OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc1/] [gdb/] [doc/] [gdb.info-1] - Blame information for rev 341

Details | Compare with Previous | View Log

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

44
File: gdb.info,  Node: Top,  Next: Summary,  Prev: (dir),  Up: (dir)
45
 
46
Debugging with GDB
47
******************
48
 
49
This file describes GDB, the GNU symbolic debugger.
50
 
51
   This is the Ninth Edition, for GDB (GDB) Version 7.2.
52
 
53
   Copyright (C) 1988-2010 Free Software Foundation, Inc.
54
 
55
   This edition of the GDB manual is dedicated to the memory of Fred
56
Fish.  Fred was a long-standing contributor to GDB and to Free software
57
in general.  We will miss him.
58
 
59
* Menu:
60
 
61
* Summary::                     Summary of GDB
62
* Sample Session::              A sample GDB session
63
 
64
* Invocation::                  Getting in and out of GDB
65
* Commands::                    GDB commands
66
* Running::                     Running programs under GDB
67
* Stopping::                    Stopping and continuing
68
* Reverse Execution::           Running programs backward
69
* Process Record and Replay::   Recording inferior's execution and replaying it
70
* Stack::                       Examining the stack
71
* Source::                      Examining source files
72
* Data::                        Examining data
73
* Optimized Code::              Debugging optimized code
74
* Macros::                      Preprocessor Macros
75
* Tracepoints::                 Debugging remote targets non-intrusively
76
* Overlays::                    Debugging programs that use overlays
77
 
78
* Languages::                   Using GDB with different languages
79
 
80
* Symbols::                     Examining the symbol table
81
* Altering::                    Altering execution
82
* GDB Files::                   GDB files
83
* Targets::                     Specifying a debugging target
84
* Remote Debugging::            Debugging remote programs
85
* Configurations::              Configuration-specific information
86
* Controlling GDB::             Controlling GDB
87
* Extending GDB::               Extending GDB
88
* Interpreters::                Command Interpreters
89
* TUI::                         GDB Text User Interface
90
* Emacs::                       Using GDB under GNU Emacs
91
* GDB/MI::                      GDB's Machine Interface.
92
* Annotations::                 GDB's annotation interface.
93
* JIT Interface::               Using the JIT debugging interface.
94
 
95
* GDB Bugs::                    Reporting bugs in GDB
96
 
97
* Command Line Editing::        Command Line Editing
98
* Using History Interactively:: Using History Interactively
99
* Formatting Documentation::    How to format and print GDB documentation
100
* Installing GDB::              Installing GDB
101
* Maintenance Commands::        Maintenance Commands
102
* Remote Protocol::             GDB Remote Serial Protocol
103
* Agent Expressions::           The GDB Agent Expression Mechanism
104
* Target Descriptions::         How targets can describe themselves to
105
                                GDB
106
* Operating System Information:: Getting additional information from
107
                                 the operating system
108
* Trace File Format::           GDB trace file format
109
* Copying::                     GNU General Public License says
110
                                how you can copy and share GDB
111
* GNU Free Documentation License::  The license for this documentation
112
* Index::                       Index
113
 
114

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

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

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

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

652
File: gdb.info,  Node: Invocation,  Next: Commands,  Prev: Sample Session,  Up: Top
653
 
654
2 Getting In and Out of GDB
655
***************************
656
 
657
This chapter discusses how to start GDB, and how to get out of it.  The
658
essentials are:
659
   * type `gdb' to start GDB.
660
 
661
   * type `quit' or `Ctrl-d' to exit.
662
 
663
* Menu:
664
 
665
* Invoking GDB::                How to start GDB
666
* Quitting GDB::                How to quit GDB
667
* Shell Commands::              How to use shell commands inside GDB
668
* Logging Output::              How to log GDB's output to a file
669
 
670

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

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

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

988
File: gdb.info,  Node: Startup,  Prev: Mode Options,  Up: Invoking GDB
989
 
990
2.1.3 What GDB Does During Startup
991
----------------------------------
992
 
993
Here's the description of what GDB does during session startup:
994
 
995
  1. Sets up the command interpreter as specified by the command line
996
     (*note interpreter: Mode Options.).
997
 
998
  2. Reads the system-wide "init file" (if `--with-system-gdbinit' was
999
     used when building GDB; *note System-wide configuration and
1000
     settings: System-wide configuration.) and executes all the
1001
     commands in that file.
1002
 
1003
  3. Reads the init file (if any) in your home directory(1) and
1004
     executes all the commands in that file.
1005
 
1006
  4. Processes command line options and operands.
1007
 
1008
  5. Reads and executes the commands from init file (if any) in the
1009
     current working directory.  This is only done if the current
1010
     directory is different from your home directory.  Thus, you can
1011
     have more than one init file, one generic in your home directory,
1012
     and another, specific to the program you are debugging, in the
1013
     directory where you invoke GDB.
1014
 
1015
  6. Reads command files specified by the `-x' option.  *Note Command
1016
     Files::, for more details about GDB command files.
1017
 
1018
  7. Reads the command history recorded in the "history file".  *Note
1019
     Command History::, for more details about the command history and
1020
     the files where GDB records it.
1021
 
1022
   Init files use the same syntax as "command files" (*note Command
1023
Files::) and are processed by GDB in the same way.  The init file in
1024
your home directory can set options (such as `set complaints') that
1025
affect subsequent processing of command line options and operands.
1026
Init files are not executed if you use the `-nx' option (*note Choosing
1027
Modes: Mode Options.).
1028
 
1029
   To display the list of init files loaded by gdb at startup, you can
1030
use `gdb --help'.
1031
 
1032
   The GDB init files are normally called `.gdbinit'.  The DJGPP port
1033
of GDB uses the name `gdb.ini', due to the limitations of file names
1034
imposed by DOS filesystems.  The Windows ports of GDB use the standard
1035
name, but if they find a `gdb.ini' file, they warn you about that and
1036
suggest to rename the file to the standard name.
1037
 
1038
   ---------- Footnotes ----------
1039
 
1040
   (1) On DOS/Windows systems, the home directory is the one pointed to
1041
by the `HOME' environment variable.
1042
 
1043

1044
File: gdb.info,  Node: Quitting GDB,  Next: Shell Commands,  Prev: Invoking GDB,  Up: Invocation
1045
 
1046
2.2 Quitting GDB
1047
================
1048
 
1049
`quit [EXPRESSION]'
1050
`q'
1051
     To exit GDB, use the `quit' command (abbreviated `q'), or type an
1052
     end-of-file character (usually `Ctrl-d').  If you do not supply
1053
     EXPRESSION, GDB will terminate normally; otherwise it will
1054
     terminate using the result of EXPRESSION as the error code.
1055
 
1056
   An interrupt (often `Ctrl-c') does not exit from GDB, but rather
1057
terminates the action of any GDB command that is in progress and
1058
returns to GDB command level.  It is safe to type the interrupt
1059
character at any time because GDB does not allow it to take effect
1060
until a time when it is safe.
1061
 
1062
   If you have been using GDB to control an attached process or device,
1063
you can release it with the `detach' command (*note Debugging an
1064
Already-running Process: Attach.).
1065
 
1066

1067
File: gdb.info,  Node: Shell Commands,  Next: Logging Output,  Prev: Quitting GDB,  Up: Invocation
1068
 
1069
2.3 Shell Commands
1070
==================
1071
 
1072
If you need to execute occasional shell commands during your debugging
1073
session, there is no need to leave or suspend GDB; you can just use the
1074
`shell' command.
1075
 
1076
`shell COMMAND STRING'
1077
     Invoke a standard shell to execute COMMAND STRING.  If it exists,
1078
     the environment variable `SHELL' determines which shell to run.
1079
     Otherwise GDB uses the default shell (`/bin/sh' on Unix systems,
1080
     `COMMAND.COM' on MS-DOS, etc.).
1081
 
1082
   The utility `make' is often needed in development environments.  You
1083
do not have to use the `shell' command for this purpose in GDB:
1084
 
1085
`make MAKE-ARGS'
1086
     Execute the `make' program with the specified arguments.  This is
1087
     equivalent to `shell make MAKE-ARGS'.
1088
 
1089

1090
File: gdb.info,  Node: Logging Output,  Prev: Shell Commands,  Up: Invocation
1091
 
1092
2.4 Logging Output
1093
==================
1094
 
1095
You may want to save the output of GDB commands to a file.  There are
1096
several commands to control GDB's logging.
1097
 
1098
`set logging on'
1099
     Enable logging.
1100
 
1101
`set logging off'
1102
     Disable logging.
1103
 
1104
`set logging file FILE'
1105
     Change the name of the current logfile.  The default logfile is
1106
     `gdb.txt'.
1107
 
1108
`set logging overwrite [on|off]'
1109
     By default, GDB will append to the logfile.  Set `overwrite' if
1110
     you want `set logging on' to overwrite the logfile instead.
1111
 
1112
`set logging redirect [on|off]'
1113
     By default, GDB output will go to both the terminal and the
1114
     logfile.  Set `redirect' if you want output to go only to the log
1115
     file.
1116
 
1117
`show logging'
1118
     Show the current values of the logging settings.
1119
 
1120

1121
File: gdb.info,  Node: Commands,  Next: Running,  Prev: Invocation,  Up: Top
1122
 
1123
3 GDB Commands
1124
**************
1125
 
1126
You can abbreviate a GDB command to the first few letters of the command
1127
name, if that abbreviation is unambiguous; and you can repeat certain
1128
GDB commands by typing just .  You can also use the  key to
1129
get GDB to fill out the rest of a word in a command (or to show you the
1130
alternatives available, if there is more than one possibility).
1131
 
1132
* Menu:
1133
 
1134
* Command Syntax::              How to give commands to GDB
1135
* Completion::                  Command completion
1136
* Help::                        How to ask GDB for help
1137
 
1138

1139
File: gdb.info,  Node: Command Syntax,  Next: Completion,  Up: Commands
1140
 
1141
3.1 Command Syntax
1142
==================
1143
 
1144
A GDB command is a single line of input.  There is no limit on how long
1145
it can be.  It starts with a command name, which is followed by
1146
arguments whose meaning depends on the command name.  For example, the
1147
command `step' accepts an argument which is the number of times to
1148
step, as in `step 5'.  You can also use the `step' command with no
1149
arguments.  Some commands do not allow any arguments.
1150
 
1151
   GDB command names may always be truncated if that abbreviation is
1152
unambiguous.  Other possible command abbreviations are listed in the
1153
documentation for individual commands.  In some cases, even ambiguous
1154
abbreviations are allowed; for example, `s' is specially defined as
1155
equivalent to `step' even though there are other commands whose names
1156
start with `s'.  You can test abbreviations by using them as arguments
1157
to the `help' command.
1158
 
1159
   A blank line as input to GDB (typing just ) means to repeat the
1160
previous command.  Certain commands (for example, `run') will not
1161
repeat this way; these are commands whose unintentional repetition
1162
might cause trouble and which you are unlikely to want to repeat.
1163
User-defined commands can disable this feature; see *Note dont-repeat:
1164
Define.
1165
 
1166
   The `list' and `x' commands, when you repeat them with ,
1167
construct new arguments rather than repeating exactly as typed.  This
1168
permits easy scanning of source or memory.
1169
 
1170
   GDB can also use  in another way: to partition lengthy output,
1171
in a way similar to the common utility `more' (*note Screen Size:
1172
Screen Size.).  Since it is easy to press one  too many in this
1173
situation, GDB disables command repetition after any command that
1174
generates this sort of display.
1175
 
1176
   Any text from a `#' to the end of the line is a comment; it does
1177
nothing.  This is useful mainly in command files (*note Command Files:
1178
Command Files.).
1179
 
1180
   The `Ctrl-o' binding is useful for repeating a complex sequence of
1181
commands.  This command accepts the current line, like , and then
1182
fetches the next line relative to the current line from the history for
1183
editing.
1184
 
1185

1186
File: gdb.info,  Node: Completion,  Next: Help,  Prev: Command Syntax,  Up: Commands
1187
 
1188
3.2 Command Completion
1189
======================
1190
 
1191
GDB can fill in the rest of a word in a command for you, if there is
1192
only one possibility; it can also show you what the valid possibilities
1193
are for the next word in a command, at any time.  This works for GDB
1194
commands, GDB subcommands, and the names of symbols in your program.
1195
 
1196
   Press the  key whenever you want GDB to fill out the rest of a
1197
word.  If there is only one possibility, GDB fills in the word, and
1198
waits for you to finish the command (or press  to enter it).  For
1199
example, if you type
1200
 
1201
     (gdb) info bre 
1202
 
1203
GDB fills in the rest of the word `breakpoints', since that is the only
1204
`info' subcommand beginning with `bre':
1205
 
1206
     (gdb) info breakpoints
1207
 
1208
You can either press  at this point, to run the `info breakpoints'
1209
command, or backspace and enter something else, if `breakpoints' does
1210
not look like the command you expected.  (If you were sure you wanted
1211
`info breakpoints' in the first place, you might as well just type
1212
 immediately after `info bre', to exploit command abbreviations
1213
rather than command completion).
1214
 
1215
   If there is more than one possibility for the next word when you
1216
press , GDB sounds a bell.  You can either supply more characters
1217
and try again, or just press  a second time; GDB displays all the
1218
possible completions for that word.  For example, you might want to set
1219
a breakpoint on a subroutine whose name begins with `make_', but when
1220
you type `b make_' GDB just sounds the bell.  Typing  again
1221
displays all the function names in your program that begin with those
1222
characters, for example:
1223
 
1224
     (gdb) b make_ 
1225
GDB sounds bell; press  again, to see:
1226
     make_a_section_from_file     make_environ
1227
     make_abs_section             make_function_type
1228
     make_blockvector             make_pointer_type
1229
     make_cleanup                 make_reference_type
1230
     make_command                 make_symbol_completion_list
1231
     (gdb) b make_
1232
 
1233
After displaying the available possibilities, GDB copies your partial
1234
input (`b make_' in the example) so you can finish the command.
1235
 
1236
   If you just want to see the list of alternatives in the first place,
1237
you can press `M-?' rather than pressing  twice.  `M-?' means
1238
` ?'.  You can type this either by holding down a key designated
1239
as the  shift on your keyboard (if there is one) while typing
1240
`?', or as  followed by `?'.
1241
 
1242
   Sometimes the string you need, while logically a "word", may contain
1243
parentheses or other characters that GDB normally excludes from its
1244
notion of a word.  To permit word completion to work in this situation,
1245
you may enclose words in `'' (single quote marks) in GDB commands.
1246
 
1247
   The most likely situation where you might need this is in typing the
1248
name of a C++ function.  This is because C++ allows function
1249
overloading (multiple definitions of the same function, distinguished
1250
by argument type).  For example, when you want to set a breakpoint you
1251
may need to distinguish whether you mean the version of `name' that
1252
takes an `int' parameter, `name(int)', or the version that takes a
1253
`float' parameter, `name(float)'.  To use the word-completion
1254
facilities in this situation, type a single quote `'' at the beginning
1255
of the function name.  This alerts GDB that it may need to consider
1256
more information than usual when you press  or `M-?' to request
1257
word completion:
1258
 
1259
     (gdb) b 'bubble( M-?
1260
     bubble(double,double)    bubble(int,int)
1261
     (gdb) b 'bubble(
1262
 
1263
   In some cases, GDB can tell that completing a name requires using
1264
quotes.  When this happens, GDB inserts the quote for you (while
1265
completing as much as it can) if you do not type the quote in the first
1266
place:
1267
 
1268
     (gdb) b bub 
1269
GDB alters your input line to the following, and rings a bell:
1270
     (gdb) b 'bubble(
1271
 
1272
In general, GDB can tell that a quote is needed (and inserts it) if you
1273
have not yet started typing the argument list when you ask for
1274
completion on an overloaded symbol.
1275
 
1276
   For more information about overloaded functions, see *Note C++
1277
Expressions: C Plus Plus Expressions.  You can use the command `set
1278
overload-resolution off' to disable overload resolution; see *Note GDB
1279
Features for C++: Debugging C Plus Plus.
1280
 
1281
   When completing in an expression which looks up a field in a
1282
structure, GDB also tries(1) to limit completions to the field names
1283
available in the type of the left-hand-side:
1284
 
1285
     (gdb) p gdb_stdout.M-?
1286
     magic      to_delete  to_fputs   to_put     to_rewind
1287
     to_data    to_flush   to_isatty  to_read    to_write
1288
 
1289
This is because the `gdb_stdout' is a variable of the type `struct
1290
ui_file' that is defined in GDB sources as follows:
1291
 
1292
     struct ui_file
1293
     {
1294
        int *magic;
1295
        ui_file_flush_ftype *to_flush;
1296
        ui_file_write_ftype *to_write;
1297
        ui_file_fputs_ftype *to_fputs;
1298
        ui_file_read_ftype *to_read;
1299
        ui_file_delete_ftype *to_delete;
1300
        ui_file_isatty_ftype *to_isatty;
1301
        ui_file_rewind_ftype *to_rewind;
1302
        ui_file_put_ftype *to_put;
1303
        void *to_data;
1304
     }
1305
 
1306
   ---------- Footnotes ----------
1307
 
1308
   (1) The completer can be confused by certain kinds of invalid
1309
expressions.  Also, it only examines the static type of the expression,
1310
not the dynamic type.
1311
 
1312

1313
File: gdb.info,  Node: Help,  Prev: Completion,  Up: Commands
1314
 
1315
3.3 Getting Help
1316
================
1317
 
1318
You can always ask GDB itself for information on its commands, using
1319
the command `help'.
1320
 
1321
`help'
1322
`h'
1323
     You can use `help' (abbreviated `h') with no arguments to display
1324
     a short list of named classes of commands:
1325
 
1326
          (gdb) help
1327
          List of classes of commands:
1328
 
1329
          aliases -- Aliases of other commands
1330
          breakpoints -- Making program stop at certain points
1331
          data -- Examining data
1332
          files -- Specifying and examining files
1333
          internals -- Maintenance commands
1334
          obscure -- Obscure features
1335
          running -- Running the program
1336
          stack -- Examining the stack
1337
          status -- Status inquiries
1338
          support -- Support facilities
1339
          tracepoints -- Tracing of program execution without
1340
                         stopping the program
1341
          user-defined -- User-defined commands
1342
 
1343
          Type "help" followed by a class name for a list of
1344
          commands in that class.
1345
          Type "help" followed by command name for full
1346
          documentation.
1347
          Command name abbreviations are allowed if unambiguous.
1348
          (gdb)
1349
 
1350
`help CLASS'
1351
     Using one of the general help classes as an argument, you can get a
1352
     list of the individual commands in that class.  For example, here
1353
     is the help display for the class `status':
1354
 
1355
          (gdb) help status
1356
          Status inquiries.
1357
 
1358
          List of commands:
1359
 
1360
          info -- Generic command for showing things
1361
                  about the program being debugged
1362
          show -- Generic command for showing things
1363
                  about the debugger
1364
 
1365
          Type "help" followed by command name for full
1366
          documentation.
1367
          Command name abbreviations are allowed if unambiguous.
1368
          (gdb)
1369
 
1370
`help COMMAND'
1371
     With a command name as `help' argument, GDB displays a short
1372
     paragraph on how to use that command.
1373
 
1374
`apropos ARGS'
1375
     The `apropos' command searches through all of the GDB commands,
1376
     and their documentation, for the regular expression specified in
1377
     ARGS.  It prints out all matches found.  For example:
1378
 
1379
          apropos reload
1380
 
1381
     results in:
1382
 
1383
          set symbol-reloading -- Set dynamic symbol table reloading
1384
                                  multiple times in one run
1385
          show symbol-reloading -- Show dynamic symbol table reloading
1386
                                  multiple times in one run
1387
 
1388
`complete ARGS'
1389
     The `complete ARGS' command lists all the possible completions for
1390
     the beginning of a command.  Use ARGS to specify the beginning of
1391
     the command you want completed.  For example:
1392
 
1393
          complete i
1394
 
1395
     results in:
1396
 
1397
          if
1398
          ignore
1399
          info
1400
          inspect
1401
 
1402
     This is intended for use by GNU Emacs.
1403
 
1404
   In addition to `help', you can use the GDB commands `info' and
1405
`show' to inquire about the state of your program, or the state of GDB
1406
itself.  Each command supports many topics of inquiry; this manual
1407
introduces each of them in the appropriate context.  The listings under
1408
`info' and under `show' in the Index point to all the sub-commands.
1409
*Note Index::.
1410
 
1411
`info'
1412
     This command (abbreviated `i') is for describing the state of your
1413
     program.  For example, you can show the arguments passed to a
1414
     function with `info args', list the registers currently in use
1415
     with `info registers', or list the breakpoints you have set with
1416
     `info breakpoints'.  You can get a complete list of the `info'
1417
     sub-commands with `help info'.
1418
 
1419
`set'
1420
     You can assign the result of an expression to an environment
1421
     variable with `set'.  For example, you can set the GDB prompt to a
1422
     $-sign with `set prompt $'.
1423
 
1424
`show'
1425
     In contrast to `info', `show' is for describing the state of GDB
1426
     itself.  You can change most of the things you can `show', by
1427
     using the related command `set'; for example, you can control what
1428
     number system is used for displays with `set radix', or simply
1429
     inquire which is currently in use with `show radix'.
1430
 
1431
     To display all the settable parameters and their current values,
1432
     you can use `show' with no arguments; you may also use `info set'.
1433
     Both commands produce the same display.
1434
 
1435
   Here are three miscellaneous `show' subcommands, all of which are
1436
exceptional in lacking corresponding `set' commands:
1437
 
1438
`show version'
1439
     Show what version of GDB is running.  You should include this
1440
     information in GDB bug-reports.  If multiple versions of GDB are
1441
     in use at your site, you may need to determine which version of
1442
     GDB you are running; as GDB evolves, new commands are introduced,
1443
     and old ones may wither away.  Also, many system vendors ship
1444
     variant versions of GDB, and there are variant versions of GDB in
1445
     GNU/Linux distributions as well.  The version number is the same
1446
     as the one announced when you start GDB.
1447
 
1448
`show copying'
1449
`info copying'
1450
     Display information about permission for copying GDB.
1451
 
1452
`show warranty'
1453
`info warranty'
1454
     Display the GNU "NO WARRANTY" statement, or a warranty, if your
1455
     version of GDB comes with one.
1456
 
1457
 
1458

1459
File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Commands,  Up: Top
1460
 
1461
4 Running Programs Under GDB
1462
****************************
1463
 
1464
When you run a program under GDB, you must first generate debugging
1465
information when you compile it.
1466
 
1467
   You may start GDB with its arguments, if any, in an environment of
1468
your choice.  If you are doing native debugging, you may redirect your
1469
program's input and output, debug an already running process, or kill a
1470
child process.
1471
 
1472
* Menu:
1473
 
1474
* Compilation::                 Compiling for debugging
1475
* Starting::                    Starting your program
1476
* Arguments::                   Your program's arguments
1477
* Environment::                 Your program's environment
1478
 
1479
* Working Directory::           Your program's working directory
1480
* Input/Output::                Your program's input and output
1481
* Attach::                      Debugging an already-running process
1482
* Kill Process::                Killing the child process
1483
 
1484
* Inferiors and Programs::      Debugging multiple inferiors and programs
1485
* Threads::                     Debugging programs with multiple threads
1486
* Forks::                       Debugging forks
1487
* Checkpoint/Restart::          Setting a _bookmark_ to return to later
1488
 
1489

1490
File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
1491
 
1492
4.1 Compiling for Debugging
1493
===========================
1494
 
1495
In order to debug a program effectively, you need to generate debugging
1496
information when you compile it.  This debugging information is stored
1497
in the object file; it describes the data type of each variable or
1498
function and the correspondence between source line numbers and
1499
addresses in the executable code.
1500
 
1501
   To request debugging information, specify the `-g' option when you
1502
run the compiler.
1503
 
1504
   Programs that are to be shipped to your customers are compiled with
1505
optimizations, using the `-O' compiler option.  However, some compilers
1506
are unable to handle the `-g' and `-O' options together.  Using those
1507
compilers, you cannot generate optimized executables containing
1508
debugging information.
1509
 
1510
   GCC, the GNU C/C++ compiler, supports `-g' with or without `-O',
1511
making it possible to debug optimized code.  We recommend that you
1512
_always_ use `-g' whenever you compile a program.  You may think your
1513
program is correct, but there is no sense in pushing your luck.  For
1514
more information, see *Note Optimized Code::.
1515
 
1516
   Older versions of the GNU C compiler permitted a variant option
1517
`-gg' for debugging information.  GDB no longer supports this format;
1518
if your GNU C compiler has this option, do not use it.
1519
 
1520
   GDB knows about preprocessor macros and can show you their expansion
1521
(*note Macros::).  Most compilers do not include information about
1522
preprocessor macros in the debugging information if you specify the
1523
`-g' flag alone, because this information is rather large.  Version 3.1
1524
and later of GCC, the GNU C compiler, provides macro information if you
1525
specify the options `-gdwarf-2' and `-g3'; the former option requests
1526
debugging information in the Dwarf 2 format, and the latter requests
1527
"extra information".  In the future, we hope to find more compact ways
1528
to represent macro information, so that it can be included with `-g'
1529
alone.
1530
 
1531

1532
File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
1533
 
1534
4.2 Starting your Program
1535
=========================
1536
 
1537
`run'
1538
`r'
1539
     Use the `run' command to start your program under GDB.  You must
1540
     first specify the program name (except on VxWorks) with an
1541
     argument to GDB (*note Getting In and Out of GDB: Invocation.), or
1542
     by using the `file' or `exec-file' command (*note Commands to
1543
     Specify Files: Files.).
1544
 
1545
 
1546
   If you are running your program in an execution environment that
1547
supports processes, `run' creates an inferior process and makes that
1548
process run your program.  In some environments without processes,
1549
`run' jumps to the start of your program.  Other targets, like
1550
`remote', are always running.  If you get an error message like this
1551
one:
1552
 
1553
     The "remote" target does not support "run".
1554
     Try "help target" or "continue".
1555
 
1556
then use `continue' to run your program.  You may need `load' first
1557
(*note load::).
1558
 
1559
   The execution of a program is affected by certain information it
1560
receives from its superior.  GDB provides ways to specify this
1561
information, which you must do _before_ starting your program.  (You
1562
can change it after starting your program, but such changes only affect
1563
your program the next time you start it.)  This information may be
1564
divided into four categories:
1565
 
1566
The _arguments._
1567
     Specify the arguments to give your program as the arguments of the
1568
     `run' command.  If a shell is available on your target, the shell
1569
     is used to pass the arguments, so that you may use normal
1570
     conventions (such as wildcard expansion or variable substitution)
1571
     in describing the arguments.  In Unix systems, you can control
1572
     which shell is used with the `SHELL' environment variable.  *Note
1573
     Your Program's Arguments: Arguments.
1574
 
1575
The _environment._
1576
     Your program normally inherits its environment from GDB, but you
1577
     can use the GDB commands `set environment' and `unset environment'
1578
     to change parts of the environment that affect your program.
1579
     *Note Your Program's Environment: Environment.
1580
 
1581
The _working directory._
1582
     Your program inherits its working directory from GDB.  You can set
1583
     the GDB working directory with the `cd' command in GDB.  *Note
1584
     Your Program's Working Directory: Working Directory.
1585
 
1586
The _standard input and output._
1587
     Your program normally uses the same device for standard input and
1588
     standard output as GDB is using.  You can redirect input and output
1589
     in the `run' command line, or you can use the `tty' command to set
1590
     a different device for your program.  *Note Your Program's Input
1591
     and Output: Input/Output.
1592
 
1593
     _Warning:_ While input and output redirection work, you cannot use
1594
     pipes to pass the output of the program you are debugging to
1595
     another program; if you attempt this, GDB is likely to wind up
1596
     debugging the wrong program.
1597
 
1598
   When you issue the `run' command, your program begins to execute
1599
immediately.  *Note Stopping and Continuing: Stopping, for discussion
1600
of how to arrange for your program to stop.  Once your program has
1601
stopped, you may call functions in your program, using the `print' or
1602
`call' commands.  *Note Examining Data: Data.
1603
 
1604
   If the modification time of your symbol file has changed since the
1605
last time GDB read its symbols, GDB discards its symbol table, and
1606
reads it again.  When it does this, GDB tries to retain your current
1607
breakpoints.
1608
 
1609
`start'
1610
     The name of the main procedure can vary from language to language.
1611
     With C or C++, the main procedure name is always `main', but other
1612
     languages such as Ada do not require a specific name for their
1613
     main procedure.  The debugger provides a convenient way to start
1614
     the execution of the program and to stop at the beginning of the
1615
     main procedure, depending on the language used.
1616
 
1617
     The `start' command does the equivalent of setting a temporary
1618
     breakpoint at the beginning of the main procedure and then invoking
1619
     the `run' command.
1620
 
1621
     Some programs contain an "elaboration" phase where some startup
1622
     code is executed before the main procedure is called.  This
1623
     depends on the languages used to write your program.  In C++, for
1624
     instance, constructors for static and global objects are executed
1625
     before `main' is called.  It is therefore possible that the
1626
     debugger stops before reaching the main procedure.  However, the
1627
     temporary breakpoint will remain to halt execution.
1628
 
1629
     Specify the arguments to give to your program as arguments to the
1630
     `start' command.  These arguments will be given verbatim to the
1631
     underlying `run' command.  Note that the same arguments will be
1632
     reused if no argument is provided during subsequent calls to
1633
     `start' or `run'.
1634
 
1635
     It is sometimes necessary to debug the program during elaboration.
1636
     In these cases, using the `start' command would stop the
1637
     execution of your program too late, as the program would have
1638
     already completed the elaboration phase.  Under these
1639
     circumstances, insert breakpoints in your elaboration code before
1640
     running your program.
1641
 
1642
`set exec-wrapper WRAPPER'
1643
`show exec-wrapper'
1644
`unset exec-wrapper'
1645
     When `exec-wrapper' is set, the specified wrapper is used to
1646
     launch programs for debugging.  GDB starts your program with a
1647
     shell command of the form `exec WRAPPER PROGRAM'.  Quoting is
1648
     added to PROGRAM and its arguments, but not to WRAPPER, so you
1649
     should add quotes if appropriate for your shell.  The wrapper runs
1650
     until it executes your program, and then GDB takes control.
1651
 
1652
     You can use any program that eventually calls `execve' with its
1653
     arguments as a wrapper.  Several standard Unix utilities do this,
1654
     e.g. `env' and `nohup'.  Any Unix shell script ending with `exec
1655
     "$@"' will also work.
1656
 
1657
     For example, you can use `env' to pass an environment variable to
1658
     the debugged program, without setting the variable in your shell's
1659
     environment:
1660
 
1661
          (gdb) set exec-wrapper env 'LD_PRELOAD=libtest.so'
1662
          (gdb) run
1663
 
1664
     This command is available when debugging locally on most targets,
1665
     excluding DJGPP, Cygwin, MS Windows, and QNX Neutrino.
1666
 
1667
`set disable-randomization'
1668
`set disable-randomization on'
1669
     This option (enabled by default in GDB) will turn off the native
1670
     randomization of the virtual address space of the started program.
1671
     This option is useful for multiple debugging sessions to make the
1672
     execution better reproducible and memory addresses reusable across
1673
     debugging sessions.
1674
 
1675
     This feature is implemented only on GNU/Linux.  You can get the
1676
     same behavior using
1677
 
1678
          (gdb) set exec-wrapper setarch `uname -m` -R
1679
 
1680
`set disable-randomization off'
1681
     Leave the behavior of the started executable unchanged.  Some bugs
1682
     rear their ugly heads only when the program is loaded at certain
1683
     addresses.  If your bug disappears when you run the program under
1684
     GDB, that might be because GDB by default disables the address
1685
     randomization on platforms, such as GNU/Linux, which do that for
1686
     stand-alone programs.  Use `set disable-randomization off' to try
1687
     to reproduce such elusive bugs.
1688
 
1689
     The virtual address space randomization is implemented only on
1690
     GNU/Linux.  It protects the programs against some kinds of
1691
     security attacks.  In these cases the attacker needs to know the
1692
     exact location of a concrete executable code.  Randomizing its
1693
     location makes it impossible to inject jumps misusing a code at
1694
     its expected addresses.
1695
 
1696
     Prelinking shared libraries provides a startup performance
1697
     advantage but it makes addresses in these libraries predictable
1698
     for privileged processes by having just unprivileged access at the
1699
     target system.  Reading the shared library binary gives enough
1700
     information for assembling the malicious code misusing it.  Still
1701
     even a prelinked shared library can get loaded at a new random
1702
     address just requiring the regular relocation process during the
1703
     startup.  Shared libraries not already prelinked are always loaded
1704
     at a randomly chosen address.
1705
 
1706
     Position independent executables (PIE) contain position
1707
     independent code similar to the shared libraries and therefore
1708
     such executables get loaded at a randomly chosen address upon
1709
     startup.  PIE executables always load even already prelinked
1710
     shared libraries at a random address.  You can build such
1711
     executable using `gcc -fPIE -pie'.
1712
 
1713
     Heap (malloc storage), stack and custom mmap areas are always
1714
     placed randomly (as long as the randomization is enabled).
1715
 
1716
`show disable-randomization'
1717
     Show the current setting of the explicit disable of the native
1718
     randomization of the virtual address space of the started program.
1719
 
1720
 
1721

1722
File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
1723
 
1724
4.3 Your Program's Arguments
1725
============================
1726
 
1727
The arguments to your program can be specified by the arguments of the
1728
`run' command.  They are passed to a shell, which expands wildcard
1729
characters and performs redirection of I/O, and thence to your program.
1730
Your `SHELL' environment variable (if it exists) specifies what shell
1731
GDB uses.  If you do not define `SHELL', GDB uses the default shell
1732
(`/bin/sh' on Unix).
1733
 
1734
   On non-Unix systems, the program is usually invoked directly by GDB,
1735
which emulates I/O redirection via the appropriate system calls, and
1736
the wildcard characters are expanded by the startup code of the
1737
program, not by the shell.
1738
 
1739
   `run' with no arguments uses the same arguments used by the previous
1740
`run', or those set by the `set args' command.
1741
 
1742
`set args'
1743
     Specify the arguments to be used the next time your program is
1744
     run.  If `set args' has no arguments, `run' executes your program
1745
     with no arguments.  Once you have run your program with arguments,
1746
     using `set args' before the next `run' is the only way to run it
1747
     again without arguments.
1748
 
1749
`show args'
1750
     Show the arguments to give your program when it is started.
1751
 
1752

1753
File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
1754
 
1755
4.4 Your Program's Environment
1756
==============================
1757
 
1758
The "environment" consists of a set of environment variables and their
1759
values.  Environment variables conventionally record such things as
1760
your user name, your home directory, your terminal type, and your search
1761
path for programs to run.  Usually you set up environment variables with
1762
the shell and they are inherited by all the other programs you run.
1763
When debugging, it can be useful to try running your program with a
1764
modified environment without having to start GDB over again.
1765
 
1766
`path DIRECTORY'
1767
     Add DIRECTORY to the front of the `PATH' environment variable (the
1768
     search path for executables) that will be passed to your program.
1769
     The value of `PATH' used by GDB does not change.  You may specify
1770
     several directory names, separated by whitespace or by a
1771
     system-dependent separator character (`:' on Unix, `;' on MS-DOS
1772
     and MS-Windows).  If DIRECTORY is already in the path, it is moved
1773
     to the front, so it is searched sooner.
1774
 
1775
     You can use the string `$cwd' to refer to whatever is the current
1776
     working directory at the time GDB searches the path.  If you use
1777
     `.' instead, it refers to the directory where you executed the
1778
     `path' command.  GDB replaces `.' in the DIRECTORY argument (with
1779
     the current path) before adding DIRECTORY to the search path.
1780
 
1781
`show paths'
1782
     Display the list of search paths for executables (the `PATH'
1783
     environment variable).
1784
 
1785
`show environment [VARNAME]'
1786
     Print the value of environment variable VARNAME to be given to
1787
     your program when it starts.  If you do not supply VARNAME, print
1788
     the names and values of all environment variables to be given to
1789
     your program.  You can abbreviate `environment' as `env'.
1790
 
1791
`set environment VARNAME [=VALUE]'
1792
     Set environment variable VARNAME to VALUE.  The value changes for
1793
     your program only, not for GDB itself.  VALUE may be any string;
1794
     the values of environment variables are just strings, and any
1795
     interpretation is supplied by your program itself.  The VALUE
1796
     parameter is optional; if it is eliminated, the variable is set to
1797
     a null value.
1798
 
1799
     For example, this command:
1800
 
1801
          set env USER = foo
1802
 
1803
     tells the debugged program, when subsequently run, that its user
1804
     is named `foo'.  (The spaces around `=' are used for clarity here;
1805
     they are not actually required.)
1806
 
1807
`unset environment VARNAME'
1808
     Remove variable VARNAME from the environment to be passed to your
1809
     program.  This is different from `set env VARNAME ='; `unset
1810
     environment' removes the variable from the environment, rather
1811
     than assigning it an empty value.
1812
 
1813
   _Warning:_ On Unix systems, GDB runs your program using the shell
1814
indicated by your `SHELL' environment variable if it exists (or
1815
`/bin/sh' if not).  If your `SHELL' variable names a shell that runs an
1816
initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
1817
BASH--any variables you set in that file affect your program.  You may
1818
wish to move setting of environment variables to files that are only
1819
run when you sign on, such as `.login' or `.profile'.
1820
 
1821

1822
File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
1823
 
1824
4.5 Your Program's Working Directory
1825
====================================
1826
 
1827
Each time you start your program with `run', it inherits its working
1828
directory from the current working directory of GDB.  The GDB working
1829
directory is initially whatever it inherited from its parent process
1830
(typically the shell), but you can specify a new working directory in
1831
GDB with the `cd' command.
1832
 
1833
   The GDB working directory also serves as a default for the commands
1834
that specify files for GDB to operate on.  *Note Commands to Specify
1835
Files: Files.
1836
 
1837
`cd DIRECTORY'
1838
     Set the GDB working directory to DIRECTORY.
1839
 
1840
`pwd'
1841
     Print the GDB working directory.
1842
 
1843
   It is generally impossible to find the current working directory of
1844
the process being debugged (since a program can change its directory
1845
during its run).  If you work on a system where GDB is configured with
1846
the `/proc' support, you can use the `info proc' command (*note SVR4
1847
Process Information::) to find out the current working directory of the
1848
debuggee.
1849
 
1850

1851
File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
1852
 
1853
4.6 Your Program's Input and Output
1854
===================================
1855
 
1856
By default, the program you run under GDB does input and output to the
1857
same terminal that GDB uses.  GDB switches the terminal to its own
1858
terminal modes to interact with you, but it records the terminal modes
1859
your program was using and switches back to them when you continue
1860
running your program.
1861
 
1862
`info terminal'
1863
     Displays information recorded by GDB about the terminal modes your
1864
     program is using.
1865
 
1866
   You can redirect your program's input and/or output using shell
1867
redirection with the `run' command.  For example,
1868
 
1869
     run > outfile
1870
 
1871
starts your program, diverting its output to the file `outfile'.
1872
 
1873
   Another way to specify where your program should do input and output
1874
is with the `tty' command.  This command accepts a file name as
1875
argument, and causes this file to be the default for future `run'
1876
commands.  It also resets the controlling terminal for the child
1877
process, for future `run' commands.  For example,
1878
 
1879
     tty /dev/ttyb
1880
 
1881
directs that processes started with subsequent `run' commands default
1882
to do input and output on the terminal `/dev/ttyb' and have that as
1883
their controlling terminal.
1884
 
1885
   An explicit redirection in `run' overrides the `tty' command's
1886
effect on the input/output device, but not its effect on the controlling
1887
terminal.
1888
 
1889
   When you use the `tty' command or redirect input in the `run'
1890
command, only the input _for your program_ is affected.  The input for
1891
GDB still comes from your terminal.  `tty' is an alias for `set
1892
inferior-tty'.
1893
 
1894
   You can use the `show inferior-tty' command to tell GDB to display
1895
the name of the terminal that will be used for future runs of your
1896
program.
1897
 
1898
`set inferior-tty /dev/ttyb'
1899
     Set the tty for the program being debugged to /dev/ttyb.
1900
 
1901
`show inferior-tty'
1902
     Show the current tty for the program being debugged.
1903
 
1904

1905
File: gdb.info,  Node: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
1906
 
1907
4.7 Debugging an Already-running Process
1908
========================================
1909
 
1910
`attach PROCESS-ID'
1911
     This command attaches to a running process--one that was started
1912
     outside GDB.  (`info files' shows your active targets.)  The
1913
     command takes as argument a process ID.  The usual way to find out
1914
     the PROCESS-ID of a Unix process is with the `ps' utility, or with
1915
     the `jobs -l' shell command.
1916
 
1917
     `attach' does not repeat if you press  a second time after
1918
     executing the command.
1919
 
1920
   To use `attach', your program must be running in an environment
1921
which supports processes; for example, `attach' does not work for
1922
programs on bare-board targets that lack an operating system.  You must
1923
also have permission to send the process a signal.
1924
 
1925
   When you use `attach', the debugger finds the program running in the
1926
process first by looking in the current working directory, then (if the
1927
program is not found) by using the source file search path (*note
1928
Specifying Source Directories: Source Path.).  You can also use the
1929
`file' command to load the program.  *Note Commands to Specify Files:
1930
Files.
1931
 
1932
   The first thing GDB does after arranging to debug the specified
1933
process is to stop it.  You can examine and modify an attached process
1934
with all the GDB commands that are ordinarily available when you start
1935
processes with `run'.  You can insert breakpoints; you can step and
1936
continue; you can modify storage.  If you would rather the process
1937
continue running, you may use the `continue' command after attaching
1938
GDB to the process.
1939
 
1940
`detach'
1941
     When you have finished debugging the attached process, you can use
1942
     the `detach' command to release it from GDB control.  Detaching
1943
     the process continues its execution.  After the `detach' command,
1944
     that process and GDB become completely independent once more, and
1945
     you are ready to `attach' another process or start one with `run'.
1946
     `detach' does not repeat if you press  again after executing
1947
     the command.
1948
 
1949
   If you exit GDB while you have an attached process, you detach that
1950
process.  If you use the `run' command, you kill that process.  By
1951
default, GDB asks for confirmation if you try to do either of these
1952
things; you can control whether or not you need to confirm by using the
1953
`set confirm' command (*note Optional Warnings and Messages:
1954
Messages/Warnings.).
1955
 
1956

1957
File: gdb.info,  Node: Kill Process,  Next: Inferiors and Programs,  Prev: Attach,  Up: Running
1958
 
1959
4.8 Killing the Child Process
1960
=============================
1961
 
1962
`kill'
1963
     Kill the child process in which your program is running under GDB.
1964
 
1965
   This command is useful if you wish to debug a core dump instead of a
1966
running process.  GDB ignores any core dump file while your program is
1967
running.
1968
 
1969
   On some operating systems, a program cannot be executed outside GDB
1970
while you have breakpoints set on it inside GDB.  You can use the
1971
`kill' command in this situation to permit running your program outside
1972
the debugger.
1973
 
1974
   The `kill' command is also useful if you wish to recompile and
1975
relink your program, since on many systems it is impossible to modify an
1976
executable file while it is running in a process.  In this case, when
1977
you next type `run', GDB notices that the file has changed, and reads
1978
the symbol table again (while trying to preserve your current
1979
breakpoint settings).
1980
 
1981

1982
File: gdb.info,  Node: Inferiors and Programs,  Next: Threads,  Prev: Kill Process,  Up: Running
1983
 
1984
4.9 Debugging Multiple Inferiors and Programs
1985
=============================================
1986
 
1987
GDB lets you run and debug multiple programs in a single session.  In
1988
addition, GDB on some systems may let you run several programs
1989
simultaneously (otherwise you have to exit from one before starting
1990
another).  In the most general case, you can have multiple threads of
1991
execution in each of multiple processes, launched from multiple
1992
executables.
1993
 
1994
   GDB represents the state of each program execution with an object
1995
called an "inferior".  An inferior typically corresponds to a process,
1996
but is more general and applies also to targets that do not have
1997
processes.  Inferiors may be created before a process runs, and may be
1998
retained after a process exits.  Inferiors have unique identifiers that
1999
are different from process ids.  Usually each inferior will also have
2000
its own distinct address space, although some embedded targets may have
2001
several inferiors running in different parts of a single address space.
2002
Each inferior may in turn have multiple threads running in it.
2003
 
2004
   To find out what inferiors exist at any moment, use `info inferiors':
2005
 
2006
`info inferiors'
2007
     Print a list of all inferiors currently being managed by GDB.
2008
 
2009
     GDB displays for each inferior (in this order):
2010
 
2011
       1. the inferior number assigned by GDB
2012
 
2013
       2. the target system's inferior identifier
2014
 
2015
       3. the name of the executable the inferior is running.
2016
 
2017
 
2018
     An asterisk `*' preceding the GDB inferior number indicates the
2019
     current inferior.
2020
 
2021
     For example,
2022
 
2023
     (gdb) info inferiors
2024
       Num  Description       Executable
2025
       2    process 2307      hello
2026
     * 1    process 3401      goodbye
2027
 
2028
   To switch focus between inferiors, use the `inferior' command:
2029
 
2030
`inferior INFNO'
2031
     Make inferior number INFNO the current inferior.  The argument
2032
     INFNO is the inferior number assigned by GDB, as shown in the
2033
     first field of the `info inferiors' display.
2034
 
2035
   You can get multiple executables into a debugging session via the
2036
`add-inferior' and `clone-inferior' commands.  On some systems GDB can
2037
add inferiors to the debug session automatically by following calls to
2038
`fork' and `exec'.  To remove inferiors from the debugging session use
2039
the `remove-inferior' command.
2040
 
2041
`add-inferior [ -copies N ] [ -exec EXECUTABLE ]'
2042
     Adds N inferiors to be run using EXECUTABLE as the executable.  N
2043
     defaults to 1.  If no executable is specified, the inferiors
2044
     begins empty, with no program.  You can still assign or change the
2045
     program assigned to the inferior at any time by using the `file'
2046
     command with the executable name as its argument.
2047
 
2048
`clone-inferior [ -copies N ] [ INFNO ]'
2049
     Adds N inferiors ready to execute the same program as inferior
2050
     INFNO.  N defaults to 1.  INFNO defaults to the number of the
2051
     current inferior.  This is a convenient command when you want to
2052
     run another instance of the inferior you are debugging.
2053
 
2054
          (gdb) info inferiors
2055
            Num  Description       Executable
2056
          * 1    process 29964     helloworld
2057
          (gdb) clone-inferior
2058
          Added inferior 2.
2059
          1 inferiors added.
2060
          (gdb) info inferiors
2061
            Num  Description       Executable
2062
            2                helloworld
2063
          * 1    process 29964     helloworld
2064
 
2065
     You can now simply switch focus to inferior 2 and run it.
2066
 
2067
`remove-inferior INFNO'
2068
     Removes the inferior INFNO.  It is not possible to remove an
2069
     inferior that is running with this command.  For those, use the
2070
     `kill' or `detach' command first.
2071
 
2072
 
2073
   To quit debugging one of the running inferiors that is not the
2074
current inferior, you can either detach from it by using the
2075
`detach inferior' command (allowing it to run independently), or kill it
2076
using the `kill inferior' command:
2077
 
2078
`detach inferior INFNO'
2079
     Detach from the inferior identified by GDB inferior number INFNO.
2080
     Note that the inferior's entry still stays on the list of
2081
     inferiors shown by `info inferiors', but its Description will show
2082
     `'.
2083
 
2084
`kill inferior INFNO'
2085
     Kill the inferior identified by GDB inferior number INFNO.  Note
2086
     that the inferior's entry still stays on the list of inferiors
2087
     shown by `info inferiors', but its Description will show `'.
2088
 
2089
   After the successful completion of a command such as `detach',
2090
`detach inferior', `kill' or `kill inferior', or after a normal process
2091
exit, the inferior is still valid and listed with `info inferiors',
2092
ready to be restarted.
2093
 
2094
   To be notified when inferiors are started or exit under GDB's
2095
control use `set print inferior-events':
2096
 
2097
`set print inferior-events'
2098
`set print inferior-events on'
2099
`set print inferior-events off'
2100
     The `set print inferior-events' command allows you to enable or
2101
     disable printing of messages when GDB notices that new inferiors
2102
     have started or that inferiors have exited or have been detached.
2103
     By default, these messages will not be printed.
2104
 
2105
`show print inferior-events'
2106
     Show whether messages will be printed when GDB detects that
2107
     inferiors have started, exited or have been detached.
2108
 
2109
   Many commands will work the same with multiple programs as with a
2110
single program: e.g., `print myglobal' will simply display the value of
2111
`myglobal' in the current inferior.
2112
 
2113
   Occasionaly, when debugging GDB itself, it may be useful to get more
2114
info about the relationship of inferiors, programs, address spaces in a
2115
debug session.  You can do that with the `maint info program-spaces'
2116
command.
2117
 
2118
`maint info program-spaces'
2119
     Print a list of all program spaces currently being managed by GDB.
2120
 
2121
     GDB displays for each program space (in this order):
2122
 
2123
       1. the program space number assigned by GDB
2124
 
2125
       2. the name of the executable loaded into the program space,
2126
          with e.g., the `file' command.
2127
 
2128
 
2129
     An asterisk `*' preceding the GDB program space number indicates
2130
     the current program space.
2131
 
2132
     In addition, below each program space line, GDB prints extra
2133
     information that isn't suitable to display in tabular form.  For
2134
     example, the list of inferiors bound to the program space.
2135
 
2136
          (gdb) maint info program-spaces
2137
            Id   Executable
2138
            2    goodbye
2139
                  Bound inferiors: ID 1 (process 21561)
2140
          * 1    hello
2141
 
2142
     Here we can see that no inferior is running the program `hello',
2143
     while `process 21561' is running the program `goodbye'.  On some
2144
     targets, it is possible that multiple inferiors are bound to the
2145
     same program space.  The most common example is that of debugging
2146
     both the parent and child processes of a `vfork' call.  For
2147
     example,
2148
 
2149
          (gdb) maint info program-spaces
2150
            Id   Executable
2151
          * 1    vfork-test
2152
                  Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2153
 
2154
     Here, both inferior 2 and inferior 1 are running in the same
2155
     program space as a result of inferior 1 having executed a `vfork'
2156
     call.
2157
 
2158

2159
File: gdb.info,  Node: Threads,  Next: Forks,  Prev: Inferiors and Programs,  Up: Running
2160
 
2161
4.10 Debugging Programs with Multiple Threads
2162
=============================================
2163
 
2164
In some operating systems, such as HP-UX and Solaris, a single program
2165
may have more than one "thread" of execution.  The precise semantics of
2166
threads differ from one operating system to another, but in general the
2167
threads of a single program are akin to multiple processes--except that
2168
they share one address space (that is, they can all examine and modify
2169
the same variables).  On the other hand, each thread has its own
2170
registers and execution stack, and perhaps private memory.
2171
 
2172
   GDB provides these facilities for debugging multi-thread programs:
2173
 
2174
   * automatic notification of new threads
2175
 
2176
   * `thread THREADNO', a command to switch among threads
2177
 
2178
   * `info threads', a command to inquire about existing threads
2179
 
2180
   * `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
2181
     to a list of threads
2182
 
2183
   * thread-specific breakpoints
2184
 
2185
   * `set print thread-events', which controls printing of messages on
2186
     thread start and exit.
2187
 
2188
   * `set libthread-db-search-path PATH', which lets the user specify
2189
     which `libthread_db' to use if the default choice isn't compatible
2190
     with the program.
2191
 
2192
     _Warning:_ These facilities are not yet available on every GDB
2193
     configuration where the operating system supports threads.  If
2194
     your GDB does not support threads, these commands have no effect.
2195
     For example, a system without thread support shows no output from
2196
     `info threads', and always rejects the `thread' command, like this:
2197
 
2198
          (gdb) info threads
2199
          (gdb) thread 1
2200
          Thread ID 1 not known.  Use the "info threads" command to
2201
          see the IDs of currently known threads.
2202
 
2203
   The GDB thread debugging facility allows you to observe all threads
2204
while your program runs--but whenever GDB takes control, one thread in
2205
particular is always the focus of debugging.  This thread is called the
2206
"current thread".  Debugging commands show program information from the
2207
perspective of the current thread.
2208
 
2209
   Whenever GDB detects a new thread in your program, it displays the
2210
target system's identification for the thread with a message in the
2211
form `[New SYSTAG]'.  SYSTAG is a thread identifier whose form varies
2212
depending on the particular system.  For example, on GNU/Linux, you
2213
might see
2214
 
2215
     [New Thread 46912507313328 (LWP 25582)]
2216
 
2217
when GDB notices a new thread.  In contrast, on an SGI system, the
2218
SYSTAG is simply something like `process 368', with no further
2219
qualifier.
2220
 
2221
   For debugging purposes, GDB associates its own thread number--always
2222
a single integer--with each thread in your program.
2223
 
2224
`info threads'
2225
     Display a summary of all threads currently in your program.  GDB
2226
     displays for each thread (in this order):
2227
 
2228
       1. the thread number assigned by GDB
2229
 
2230
       2. the target system's thread identifier (SYSTAG)
2231
 
2232
       3. the current stack frame summary for that thread
2233
 
2234
     An asterisk `*' to the left of the GDB thread number indicates the
2235
     current thread.
2236
 
2237
     For example,
2238
 
2239
     (gdb) info threads
2240
       3 process 35 thread 27  0x34e5 in sigpause ()
2241
       2 process 35 thread 23  0x34e5 in sigpause ()
2242
     * 1 process 35 thread 13  main (argc=1, argv=0x7ffffff8)
2243
         at threadtest.c:68
2244
 
2245
   On HP-UX systems:
2246
 
2247
   For debugging purposes, GDB associates its own thread number--a
2248
small integer assigned in thread-creation order--with each thread in
2249
your program.
2250
 
2251
   Whenever GDB detects a new thread in your program, it displays both
2252
GDB's thread number and the target system's identification for the
2253
thread with a message in the form `[New SYSTAG]'.  SYSTAG is a thread
2254
identifier whose form varies depending on the particular system.  For
2255
example, on HP-UX, you see
2256
 
2257
     [New thread 2 (system thread 26594)]
2258
 
2259
when GDB notices a new thread.
2260
 
2261
`info threads'
2262
     Display a summary of all threads currently in your program.  GDB
2263
     displays for each thread (in this order):
2264
 
2265
       1. the thread number assigned by GDB
2266
 
2267
       2. the target system's thread identifier (SYSTAG)
2268
 
2269
       3. the current stack frame summary for that thread
2270
 
2271
     An asterisk `*' to the left of the GDB thread number indicates the
2272
     current thread.
2273
 
2274
     For example,
2275
 
2276
     (gdb) info threads
2277
         * 3 system thread 26607  worker (wptr=0x7b09c318 "@") \
2278
 
2279
     at quicksort.c:137
2280
           2 system thread 26606  0x7b0030d8 in __ksleep () \
2281
 
2282
     from /usr/lib/libc.2
2283
           1 system thread 27905  0x7b003498 in _brk () \
2284
 
2285
     from /usr/lib/libc.2
2286
 
2287
   On Solaris, you can display more information about user threads with
2288
a Solaris-specific command:
2289
 
2290
`maint info sol-threads'
2291
     Display info on Solaris user threads.
2292
 
2293
`thread THREADNO'
2294
     Make thread number THREADNO the current thread.  The command
2295
     argument THREADNO is the internal GDB thread number, as shown in
2296
     the first field of the `info threads' display.  GDB responds by
2297
     displaying the system identifier of the thread you selected, and
2298
     its current stack frame summary:
2299
 
2300
          (gdb) thread 2
2301
          [Switching to process 35 thread 23]
2302
          0x34e5 in sigpause ()
2303
 
2304
     As with the `[New ...]' message, the form of the text after
2305
     `Switching to' depends on your system's conventions for identifying
2306
     threads.
2307
 
2308
     The debugger convenience variable `$_thread' contains the number
2309
     of the current thread.  You may find this useful in writing
2310
     breakpoint conditional expressions, command scripts, and so forth.
2311
     See *Note Convenience Variables: Convenience Vars, for general
2312
     information on convenience variables.
2313
 
2314
`thread apply [THREADNO] [ALL] COMMAND'
2315
     The `thread apply' command allows you to apply the named COMMAND
2316
     to one or more threads.  Specify the numbers of the threads that
2317
     you want affected with the command argument THREADNO.  It can be a
2318
     single thread number, one of the numbers shown in the first field
2319
     of the `info threads' display; or it could be a range of thread
2320
     numbers, as in `2-4'.  To apply a command to all threads, type
2321
     `thread apply all COMMAND'.
2322
 
2323
`set print thread-events'
2324
`set print thread-events on'
2325
`set print thread-events off'
2326
     The `set print thread-events' command allows you to enable or
2327
     disable printing of messages when GDB notices that new threads have
2328
     started or that threads have exited.  By default, these messages
2329
     will be printed if detection of these events is supported by the
2330
     target.  Note that these messages cannot be disabled on all
2331
     targets.
2332
 
2333
`show print thread-events'
2334
     Show whether messages will be printed when GDB detects that threads
2335
     have started and exited.
2336
 
2337
   *Note Stopping and Starting Multi-thread Programs: Thread Stops, for
2338
more information about how GDB behaves when you stop and start programs
2339
with multiple threads.
2340
 
2341
   *Note Setting Watchpoints: Set Watchpoints, for information about
2342
watchpoints in programs with multiple threads.
2343
 
2344
`set libthread-db-search-path [PATH]'
2345
     If this variable is set, PATH is a colon-separated list of
2346
     directories GDB will use to search for `libthread_db'.  If you
2347
     omit PATH, `libthread-db-search-path' will be reset to an empty
2348
     list.
2349
 
2350
     On GNU/Linux and Solaris systems, GDB uses a "helper"
2351
     `libthread_db' library to obtain information about threads in the
2352
     inferior process.  GDB will use `libthread-db-search-path' to find
2353
     `libthread_db'.  If that fails, GDB will continue with default
2354
     system shared library directories, and finally the directory from
2355
     which `libpthread' was loaded in the inferior process.
2356
 
2357
     For any `libthread_db' library GDB finds in above directories, GDB
2358
     attempts to initialize it with the current inferior process.  If
2359
     this initialization fails (which could happen because of a version
2360
     mismatch between `libthread_db' and `libpthread'), GDB will unload
2361
     `libthread_db', and continue with the next directory.  If none of
2362
     `libthread_db' libraries initialize successfully, GDB will issue a
2363
     warning and thread debugging will be disabled.
2364
 
2365
     Setting `libthread-db-search-path' is currently implemented only
2366
     on some platforms.
2367
 
2368
`show libthread-db-search-path'
2369
     Display current libthread_db search path.
2370
 
2371

2372
File: gdb.info,  Node: Forks,  Next: Checkpoint/Restart,  Prev: Threads,  Up: Running
2373
 
2374
4.11 Debugging Forks
2375
====================
2376
 
2377
On most systems, GDB has no special support for debugging programs
2378
which create additional processes using the `fork' function.  When a
2379
program forks, GDB will continue to debug the parent process and the
2380
child process will run unimpeded.  If you have set a breakpoint in any
2381
code which the child then executes, the child will get a `SIGTRAP'
2382
signal which (unless it catches the signal) will cause it to terminate.
2383
 
2384
   However, if you want to debug the child process there is a workaround
2385
which isn't too painful.  Put a call to `sleep' in the code which the
2386
child process executes after the fork.  It may be useful to sleep only
2387
if a certain environment variable is set, or a certain file exists, so
2388
that the delay need not occur when you don't want to run GDB on the
2389
child.  While the child is sleeping, use the `ps' program to get its
2390
process ID.  Then tell GDB (a new invocation of GDB if you are also
2391
debugging the parent process) to attach to the child process (*note
2392
Attach::).  From that point on you can debug the child process just
2393
like any other process which you attached to.
2394
 
2395
   On some systems, GDB provides support for debugging programs that
2396
create additional processes using the `fork' or `vfork' functions.
2397
Currently, the only platforms with this feature are HP-UX (11.x and
2398
later only?) and GNU/Linux (kernel version 2.5.60 and later).
2399
 
2400
   By default, when a program forks, GDB will continue to debug the
2401
parent process and the child process will run unimpeded.
2402
 
2403
   If you want to follow the child process instead of the parent
2404
process, use the command `set follow-fork-mode'.
2405
 
2406
`set follow-fork-mode MODE'
2407
     Set the debugger response to a program call of `fork' or `vfork'.
2408
     A call to `fork' or `vfork' creates a new process.  The MODE
2409
     argument can be:
2410
 
2411
    `parent'
2412
          The original process is debugged after a fork.  The child
2413
          process runs unimpeded.  This is the default.
2414
 
2415
    `child'
2416
          The new process is debugged after a fork.  The parent process
2417
          runs unimpeded.
2418
 
2419
 
2420
`show follow-fork-mode'
2421
     Display the current debugger response to a `fork' or `vfork' call.
2422
 
2423
   On Linux, if you want to debug both the parent and child processes,
2424
use the command `set detach-on-fork'.
2425
 
2426
`set detach-on-fork MODE'
2427
     Tells gdb whether to detach one of the processes after a fork, or
2428
     retain debugger control over them both.
2429
 
2430
    `on'
2431
          The child process (or parent process, depending on the value
2432
          of `follow-fork-mode') will be detached and allowed to run
2433
          independently.  This is the default.
2434
 
2435
    `off'
2436
          Both processes will be held under the control of GDB.  One
2437
          process (child or parent, depending on the value of
2438
          `follow-fork-mode') is debugged as usual, while the other is
2439
          held suspended.
2440
 
2441
 
2442
`show detach-on-fork'
2443
     Show whether detach-on-fork mode is on/off.
2444
 
2445
   If you choose to set `detach-on-fork' mode off, then GDB will retain
2446
control of all forked processes (including nested forks).  You can list
2447
the forked processes under the control of GDB by using the
2448
`info inferiors' command, and switch from one fork to another by using
2449
the `inferior' command (*note Debugging Multiple Inferiors and
2450
Programs: Inferiors and Programs.).
2451
 
2452
   To quit debugging one of the forked processes, you can either detach
2453
from it by using the `detach inferior' command (allowing it to run
2454
independently), or kill it using the `kill inferior' command.  *Note
2455
Debugging Multiple Inferiors and Programs: Inferiors and Programs.
2456
 
2457
   If you ask to debug a child process and a `vfork' is followed by an
2458
`exec', GDB executes the new target up to the first breakpoint in the
2459
new target.  If you have a breakpoint set on `main' in your original
2460
program, the breakpoint will also be set on the child process's `main'.
2461
 
2462
   On some systems, when a child process is spawned by `vfork', you
2463
cannot debug the child or parent until an `exec' call completes.
2464
 
2465
   If you issue a `run' command to GDB after an `exec' call executes,
2466
the new target restarts.  To restart the parent process, use the `file'
2467
command with the parent executable name as its argument.  By default,
2468
after an `exec' call executes, GDB discards the symbols of the previous
2469
executable image.  You can change this behaviour with the
2470
`set follow-exec-mode' command.
2471
 
2472
`set follow-exec-mode MODE'
2473
     Set debugger response to a program call of `exec'.  An `exec' call
2474
     replaces the program image of a process.
2475
 
2476
     `follow-exec-mode' can be:
2477
 
2478
    `new'
2479
          GDB creates a new inferior and rebinds the process to this
2480
          new inferior.  The program the process was running before the
2481
          `exec' call can be restarted afterwards by restarting the
2482
          original inferior.
2483
 
2484
          For example:
2485
 
2486
               (gdb) info inferiors
2487
               (gdb) info inferior
2488
                 Id   Description   Executable
2489
               * 1            prog1
2490
               (gdb) run
2491
               process 12020 is executing new program: prog2
2492
               Program exited normally.
2493
               (gdb) info inferiors
2494
                 Id   Description   Executable
2495
               * 2            prog2
2496
                 1            prog1
2497
 
2498
    `same'
2499
          GDB keeps the process bound to the same inferior.  The new
2500
          executable image replaces the previous executable loaded in
2501
          the inferior.  Restarting the inferior after the `exec' call,
2502
          with e.g., the `run' command, restarts the executable the
2503
          process was running after the `exec' call.  This is the
2504
          default mode.
2505
 
2506
          For example:
2507
 
2508
               (gdb) info inferiors
2509
                 Id   Description   Executable
2510
               * 1            prog1
2511
               (gdb) run
2512
               process 12020 is executing new program: prog2
2513
               Program exited normally.
2514
               (gdb) info inferiors
2515
                 Id   Description   Executable
2516
               * 1            prog2
2517
 
2518
 
2519
   You can use the `catch' command to make GDB stop whenever a `fork',
2520
`vfork', or `exec' call is made.  *Note Setting Catchpoints: Set
2521
Catchpoints.
2522
 
2523

2524
File: gdb.info,  Node: Checkpoint/Restart,  Prev: Forks,  Up: Running
2525
 
2526
4.12 Setting a _Bookmark_ to Return to Later
2527
============================================
2528
 
2529
On certain operating systems(1), GDB is able to save a "snapshot" of a
2530
program's state, called a "checkpoint", and come back to it later.
2531
 
2532
   Returning to a checkpoint effectively undoes everything that has
2533
happened in the program since the `checkpoint' was saved.  This
2534
includes changes in memory, registers, and even (within some limits)
2535
system state.  Effectively, it is like going back in time to the moment
2536
when the checkpoint was saved.
2537
 
2538
   Thus, if you're stepping thru a program and you think you're getting
2539
close to the point where things go wrong, you can save a checkpoint.
2540
Then, if you accidentally go too far and miss the critical statement,
2541
instead of having to restart your program from the beginning, you can
2542
just go back to the checkpoint and start again from there.
2543
 
2544
   This can be especially useful if it takes a lot of time or steps to
2545
reach the point where you think the bug occurs.
2546
 
2547
   To use the `checkpoint'/`restart' method of debugging:
2548
 
2549
`checkpoint'
2550
     Save a snapshot of the debugged program's current execution state.
2551
     The `checkpoint' command takes no arguments, but each checkpoint
2552
     is assigned a small integer id, similar to a breakpoint id.
2553
 
2554
`info checkpoints'
2555
     List the checkpoints that have been saved in the current debugging
2556
     session.  For each checkpoint, the following information will be
2557
     listed:
2558
 
2559
    `Checkpoint ID'
2560
 
2561
    `Process ID'
2562
 
2563
    `Code Address'
2564
 
2565
    `Source line, or label'
2566
 
2567
`restart CHECKPOINT-ID'
2568
     Restore the program state that was saved as checkpoint number
2569
     CHECKPOINT-ID.  All program variables, registers, stack frames
2570
     etc.  will be returned to the values that they had when the
2571
     checkpoint was saved.  In essence, gdb will "wind back the clock"
2572
     to the point in time when the checkpoint was saved.
2573
 
2574
     Note that breakpoints, GDB variables, command history etc.  are
2575
     not affected by restoring a checkpoint.  In general, a checkpoint
2576
     only restores things that reside in the program being debugged,
2577
     not in the debugger.
2578
 
2579
`delete checkpoint CHECKPOINT-ID'
2580
     Delete the previously-saved checkpoint identified by CHECKPOINT-ID.
2581
 
2582
 
2583
   Returning to a previously saved checkpoint will restore the user
2584
state of the program being debugged, plus a significant subset of the
2585
system (OS) state, including file pointers.  It won't "un-write" data
2586
from a file, but it will rewind the file pointer to the previous
2587
location, so that the previously written data can be overwritten.  For
2588
files opened in read mode, the pointer will also be restored so that the
2589
previously read data can be read again.
2590
 
2591
   Of course, characters that have been sent to a printer (or other
2592
external device) cannot be "snatched back", and characters received
2593
from eg. a serial device can be removed from internal program buffers,
2594
but they cannot be "pushed back" into the serial pipeline, ready to be
2595
received again.  Similarly, the actual contents of files that have been
2596
changed cannot be restored (at this time).
2597
 
2598
   However, within those constraints, you actually can "rewind" your
2599
program to a previously saved point in time, and begin debugging it
2600
again -- and you can change the course of events so as to debug a
2601
different execution path this time.
2602
 
2603
   Finally, there is one bit of internal program state that will be
2604
different when you return to a checkpoint -- the program's process id.
2605
Each checkpoint will have a unique process id (or PID), and each will
2606
be different from the program's original PID.  If your program has
2607
saved a local copy of its process id, this could potentially pose a
2608
problem.
2609
 
2610
4.12.1 A Non-obvious Benefit of Using Checkpoints
2611
-------------------------------------------------
2612
 
2613
On some systems such as GNU/Linux, address space randomization is
2614
performed on new processes for security reasons.  This makes it
2615
difficult or impossible to set a breakpoint, or watchpoint, on an
2616
absolute address if you have to restart the program, since the absolute
2617
location of a symbol will change from one execution to the next.
2618
 
2619
   A checkpoint, however, is an _identical_ copy of a process.
2620
Therefore if you create a checkpoint at (eg.) the start of main, and
2621
simply return to that checkpoint instead of restarting the process, you
2622
can avoid the effects of address randomization and your symbols will
2623
all stay in the same place.
2624
 
2625
   ---------- Footnotes ----------
2626
 
2627
   (1) Currently, only GNU/Linux.
2628
 
2629

2630
File: gdb.info,  Node: Stopping,  Next: Reverse Execution,  Prev: Running,  Up: Top
2631
 
2632
5 Stopping and Continuing
2633
*************************
2634
 
2635
The principal purposes of using a debugger are so that you can stop your
2636
program before it terminates; or so that, if your program runs into
2637
trouble, you can investigate and find out why.
2638
 
2639
   Inside GDB, your program may stop for any of several reasons, such
2640
as a signal, a breakpoint, or reaching a new line after a GDB command
2641
such as `step'.  You may then examine and change variables, set new
2642
breakpoints or remove old ones, and then continue execution.  Usually,
2643
the messages shown by GDB provide ample explanation of the status of
2644
your program--but you can also explicitly request this information at
2645
any time.
2646
 
2647
`info program'
2648
     Display information about the status of your program: whether it is
2649
     running or not, what process it is, and why it stopped.
2650
 
2651
* Menu:
2652
 
2653
* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
2654
* Continuing and Stepping::     Resuming execution
2655
* Signals::                     Signals
2656
* Thread Stops::                Stopping and starting multi-thread programs
2657
 
2658

2659
File: gdb.info,  Node: Breakpoints,  Next: Continuing and Stepping,  Up: Stopping
2660
 
2661
5.1 Breakpoints, Watchpoints, and Catchpoints
2662
=============================================
2663
 
2664
A "breakpoint" makes your program stop whenever a certain point in the
2665
program is reached.  For each breakpoint, you can add conditions to
2666
control in finer detail whether your program stops.  You can set
2667
breakpoints with the `break' command and its variants (*note Setting
2668
Breakpoints: Set Breaks.), to specify the place where your program
2669
should stop by line number, function name or exact address in the
2670
program.
2671
 
2672
   On some systems, you can set breakpoints in shared libraries before
2673
the executable is run.  There is a minor limitation on HP-UX systems:
2674
you must wait until the executable is run in order to set breakpoints
2675
in shared library routines that are not called directly by the program
2676
(for example, routines that are arguments in a `pthread_create' call).
2677
 
2678
   A "watchpoint" is a special breakpoint that stops your program when
2679
the value of an expression changes.  The expression may be a value of a
2680
variable, or it could involve values of one or more variables combined
2681
by operators, such as `a + b'.  This is sometimes called "data
2682
breakpoints".  You must use a different command to set watchpoints
2683
(*note Setting Watchpoints: Set Watchpoints.), but aside from that, you
2684
can manage a watchpoint like any other breakpoint: you enable, disable,
2685
and delete both breakpoints and watchpoints using the same commands.
2686
 
2687
   You can arrange to have values from your program displayed
2688
automatically whenever GDB stops at a breakpoint.  *Note Automatic
2689
Display: Auto Display.
2690
 
2691
   A "catchpoint" is another special breakpoint that stops your program
2692
when a certain kind of event occurs, such as the throwing of a C++
2693
exception or the loading of a library.  As with watchpoints, you use a
2694
different command to set a catchpoint (*note Setting Catchpoints: Set
2695
Catchpoints.), but aside from that, you can manage a catchpoint like any
2696
other breakpoint.  (To stop when your program receives a signal, use the
2697
`handle' command; see *Note Signals: Signals.)
2698
 
2699
   GDB assigns a number to each breakpoint, watchpoint, or catchpoint
2700
when you create it; these numbers are successive integers starting with
2701
one.  In many of the commands for controlling various features of
2702
breakpoints you use the breakpoint number to say which breakpoint you
2703
want to change.  Each breakpoint may be "enabled" or "disabled"; if
2704
disabled, it has no effect on your program until you enable it again.
2705
 
2706
   Some GDB commands accept a range of breakpoints on which to operate.
2707
A breakpoint range is either a single breakpoint number, like `5', or
2708
two such numbers, in increasing order, separated by a hyphen, like
2709
`5-7'.  When a breakpoint range is given to a command, all breakpoints
2710
in that range are operated on.
2711
 
2712
* Menu:
2713
 
2714
* Set Breaks::                  Setting breakpoints
2715
* Set Watchpoints::             Setting watchpoints
2716
* Set Catchpoints::             Setting catchpoints
2717
* Delete Breaks::               Deleting breakpoints
2718
* Disabling::                   Disabling breakpoints
2719
* Conditions::                  Break conditions
2720
* Break Commands::              Breakpoint command lists
2721
* Save Breakpoints::            How to save breakpoints in a file
2722
* Error in Breakpoints::        ``Cannot insert breakpoints''
2723
* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
2724
 
2725

2726
File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Up: Breakpoints
2727
 
2728
5.1.1 Setting Breakpoints
2729
-------------------------
2730
 
2731
Breakpoints are set with the `break' command (abbreviated `b').  The
2732
debugger convenience variable `$bpnum' records the number of the
2733
breakpoint you've set most recently; see *Note Convenience Variables:
2734
Convenience Vars, for a discussion of what you can do with convenience
2735
variables.
2736
 
2737
`break LOCATION'
2738
     Set a breakpoint at the given LOCATION, which can specify a
2739
     function name, a line number, or an address of an instruction.
2740
     (*Note Specify Location::, for a list of all the possible ways to
2741
     specify a LOCATION.)  The breakpoint will stop your program just
2742
     before it executes any of the code in the specified LOCATION.
2743
 
2744
     When using source languages that permit overloading of symbols,
2745
     such as C++, a function name may refer to more than one possible
2746
     place to break.  *Note Ambiguous Expressions: Ambiguous
2747
     Expressions, for a discussion of that situation.
2748
 
2749
     It is also possible to insert a breakpoint that will stop the
2750
     program only if a specific thread (*note Thread-Specific
2751
     Breakpoints::) or a specific task (*note Ada Tasks::) hits that
2752
     breakpoint.
2753
 
2754
`break'
2755
     When called without any arguments, `break' sets a breakpoint at
2756
     the next instruction to be executed in the selected stack frame
2757
     (*note Examining the Stack: Stack.).  In any selected frame but the
2758
     innermost, this makes your program stop as soon as control returns
2759
     to that frame.  This is similar to the effect of a `finish'
2760
     command in the frame inside the selected frame--except that
2761
     `finish' does not leave an active breakpoint.  If you use `break'
2762
     without an argument in the innermost frame, GDB stops the next
2763
     time it reaches the current location; this may be useful inside
2764
     loops.
2765
 
2766
     GDB normally ignores breakpoints when it resumes execution, until
2767
     at least one instruction has been executed.  If it did not do
2768
     this, you would be unable to proceed past a breakpoint without
2769
     first disabling the breakpoint.  This rule applies whether or not
2770
     the breakpoint already existed when your program stopped.
2771
 
2772
`break ... if COND'
2773
     Set a breakpoint with condition COND; evaluate the expression COND
2774
     each time the breakpoint is reached, and stop only if the value is
2775
     nonzero--that is, if COND evaluates as true.  `...' stands for one
2776
     of the possible arguments described above (or no argument)
2777
     specifying where to break.  *Note Break Conditions: Conditions,
2778
     for more information on breakpoint conditions.
2779
 
2780
`tbreak ARGS'
2781
     Set a breakpoint enabled only for one stop.  ARGS are the same as
2782
     for the `break' command, and the breakpoint is set in the same
2783
     way, but the breakpoint is automatically deleted after the first
2784
     time your program stops there.  *Note Disabling Breakpoints:
2785
     Disabling.
2786
 
2787
`hbreak ARGS'
2788
     Set a hardware-assisted breakpoint.  ARGS are the same as for the
2789
     `break' command and the breakpoint is set in the same way, but the
2790
     breakpoint requires hardware support and some target hardware may
2791
     not have this support.  The main purpose of this is EPROM/ROM code
2792
     debugging, so you can set a breakpoint at an instruction without
2793
     changing the instruction.  This can be used with the new
2794
     trap-generation provided by SPARClite DSU and most x86-based
2795
     targets.  These targets will generate traps when a program
2796
     accesses some data or instruction address that is assigned to the
2797
     debug registers.  However the hardware breakpoint registers can
2798
     take a limited number of breakpoints.  For example, on the DSU,
2799
     only two data breakpoints can be set at a time, and GDB will
2800
     reject this command if more than two are used.  Delete or disable
2801
     unused hardware breakpoints before setting new ones (*note
2802
     Disabling Breakpoints: Disabling.).  *Note Break Conditions:
2803
     Conditions.  For remote targets, you can restrict the number of
2804
     hardware breakpoints GDB will use, see *Note set remote
2805
     hardware-breakpoint-limit::.
2806
 
2807
`thbreak ARGS'
2808
     Set a hardware-assisted breakpoint enabled only for one stop.  ARGS
2809
     are the same as for the `hbreak' command and the breakpoint is set
2810
     in the same way.  However, like the `tbreak' command, the
2811
     breakpoint is automatically deleted after the first time your
2812
     program stops there.  Also, like the `hbreak' command, the
2813
     breakpoint requires hardware support and some target hardware may
2814
     not have this support.  *Note Disabling Breakpoints: Disabling.
2815
     See also *Note Break Conditions: Conditions.
2816
 
2817
`rbreak REGEX'
2818
     Set breakpoints on all functions matching the regular expression
2819
     REGEX.  This command sets an unconditional breakpoint on all
2820
     matches, printing a list of all breakpoints it set.  Once these
2821
     breakpoints are set, they are treated just like the breakpoints
2822
     set with the `break' command.  You can delete them, disable them,
2823
     or make them conditional the same way as any other breakpoint.
2824
 
2825
     The syntax of the regular expression is the standard one used with
2826
     tools like `grep'.  Note that this is different from the syntax
2827
     used by shells, so for instance `foo*' matches all functions that
2828
     include an `fo' followed by zero or more `o's.  There is an
2829
     implicit `.*' leading and trailing the regular expression you
2830
     supply, so to match only functions that begin with `foo', use
2831
     `^foo'.
2832
 
2833
     When debugging C++ programs, `rbreak' is useful for setting
2834
     breakpoints on overloaded functions that are not members of any
2835
     special classes.
2836
 
2837
     The `rbreak' command can be used to set breakpoints in *all* the
2838
     functions in a program, like this:
2839
 
2840
          (gdb) rbreak .
2841
 
2842
`rbreak FILE:REGEX'
2843
     If `rbreak' is called with a filename qualification, it limits the
2844
     search for functions matching the given regular expression to the
2845
     specified FILE.  This can be used, for example, to set breakpoints
2846
     on every function in a given file:
2847
 
2848
          (gdb) rbreak file.c:.
2849
 
2850
     The colon separating the filename qualifier from the regex may
2851
     optionally be surrounded by spaces.
2852
 
2853
`info breakpoints [N]'
2854
`info break [N]'
2855
     Print a table of all breakpoints, watchpoints, and catchpoints set
2856
     and not deleted.  Optional argument N means print information only
2857
     about the specified breakpoint (or watchpoint or catchpoint).  For
2858
     each breakpoint, following columns are printed:
2859
 
2860
    _Breakpoint Numbers_
2861
 
2862
    _Type_
2863
          Breakpoint, watchpoint, or catchpoint.
2864
 
2865
    _Disposition_
2866
          Whether the breakpoint is marked to be disabled or deleted
2867
          when hit.
2868
 
2869
    _Enabled or Disabled_
2870
          Enabled breakpoints are marked with `y'.  `n' marks
2871
          breakpoints that are not enabled.
2872
 
2873
    _Address_
2874
          Where the breakpoint is in your program, as a memory address.
2875
          For a pending breakpoint whose address is not yet known,
2876
          this field will contain `'.  Such breakpoint won't
2877
          fire until a shared library that has the symbol or line
2878
          referred by breakpoint is loaded.  See below for details.  A
2879
          breakpoint with several locations will have `' in
2880
          this field--see below for details.
2881
 
2882
    _What_
2883
          Where the breakpoint is in the source for your program, as a
2884
          file and line number.  For a pending breakpoint, the original
2885
          string passed to the breakpoint command will be listed as it
2886
          cannot be resolved until the appropriate shared library is
2887
          loaded in the future.
2888
 
2889
     If a breakpoint is conditional, `info break' shows the condition on
2890
     the line following the affected breakpoint; breakpoint commands,
2891
     if any, are listed after that.  A pending breakpoint is allowed to
2892
     have a condition specified for it.  The condition is not parsed
2893
     for validity until a shared library is loaded that allows the
2894
     pending breakpoint to resolve to a valid location.
2895
 
2896
     `info break' with a breakpoint number N as argument lists only
2897
     that breakpoint.  The convenience variable `$_' and the default
2898
     examining-address for the `x' command are set to the address of
2899
     the last breakpoint listed (*note Examining Memory: Memory.).
2900
 
2901
     `info break' displays a count of the number of times the breakpoint
2902
     has been hit.  This is especially useful in conjunction with the
2903
     `ignore' command.  You can ignore a large number of breakpoint
2904
     hits, look at the breakpoint info to see how many times the
2905
     breakpoint was hit, and then run again, ignoring one less than
2906
     that number.  This will get you quickly to the last hit of that
2907
     breakpoint.
2908
 
2909
   GDB allows you to set any number of breakpoints at the same place in
2910
your program.  There is nothing silly or meaningless about this.  When
2911
the breakpoints are conditional, this is even useful (*note Break
2912
Conditions: Conditions.).
2913
 
2914
   It is possible that a breakpoint corresponds to several locations in
2915
your program.  Examples of this situation are:
2916
 
2917
   * For a C++ constructor, the GCC compiler generates several
2918
     instances of the function body, used in different cases.
2919
 
2920
   * For a C++ template function, a given line in the function can
2921
     correspond to any number of instantiations.
2922
 
2923
   * For an inlined function, a given source line can correspond to
2924
     several places where that function is inlined.
2925
 
2926
   In all those cases, GDB will insert a breakpoint at all the relevant
2927
locations(1).
2928
 
2929
   A breakpoint with multiple locations is displayed in the breakpoint
2930
table using several rows--one header row, followed by one row for each
2931
breakpoint location.  The header row has `' in the address
2932
column.  The rows for individual locations contain the actual addresses
2933
for locations, and show the functions to which those locations belong.
2934
The number column for a location is of the form
2935
BREAKPOINT-NUMBER.LOCATION-NUMBER.
2936
 
2937
   For example:
2938
 
2939
     Num     Type           Disp Enb  Address    What
2940
     1       breakpoint     keep y    
2941
             stop only if i==1
2942
             breakpoint already hit 1 time
2943
     1.1                         y    0x080486a2 in void foo() at t.cc:8
2944
     1.2                         y    0x080486ca in void foo() at t.cc:8
2945
 
2946
   Each location can be individually enabled or disabled by passing
2947
BREAKPOINT-NUMBER.LOCATION-NUMBER as argument to the `enable' and
2948
`disable' commands.  Note that you cannot delete the individual
2949
locations from the list, you can only delete the entire list of
2950
locations that belong to their parent breakpoint (with the `delete NUM'
2951
command, where NUM is the number of the parent breakpoint, 1 in the
2952
above example).  Disabling or enabling the parent breakpoint (*note
2953
Disabling::) affects all of the locations that belong to that
2954
breakpoint.
2955
 
2956
   It's quite common to have a breakpoint inside a shared library.
2957
Shared libraries can be loaded and unloaded explicitly, and possibly
2958
repeatedly, as the program is executed.  To support this use case, GDB
2959
updates breakpoint locations whenever any shared library is loaded or
2960
unloaded.  Typically, you would set a breakpoint in a shared library at
2961
the beginning of your debugging session, when the library is not
2962
loaded, and when the symbols from the library are not available.  When
2963
you try to set breakpoint, GDB will ask you if you want to set a so
2964
called "pending breakpoint"--breakpoint whose address is not yet
2965
resolved.
2966
 
2967
   After the program is run, whenever a new shared library is loaded,
2968
GDB reevaluates all the breakpoints.  When a newly loaded shared
2969
library contains the symbol or line referred to by some pending
2970
breakpoint, that breakpoint is resolved and becomes an ordinary
2971
breakpoint.  When a library is unloaded, all breakpoints that refer to
2972
its symbols or source lines become pending again.
2973
 
2974
   This logic works for breakpoints with multiple locations, too.  For
2975
example, if you have a breakpoint in a C++ template function, and a
2976
newly loaded shared library has an instantiation of that template, a
2977
new location is added to the list of locations for the breakpoint.
2978
 
2979
   Except for having unresolved address, pending breakpoints do not
2980
differ from regular breakpoints.  You can set conditions or commands,
2981
enable and disable them and perform other breakpoint operations.
2982
 
2983
   GDB provides some additional commands for controlling what happens
2984
when the `break' command cannot resolve breakpoint address
2985
specification to an address:
2986
 
2987
`set breakpoint pending auto'
2988
     This is the default behavior.  When GDB cannot find the breakpoint
2989
     location, it queries you whether a pending breakpoint should be
2990
     created.
2991
 
2992
`set breakpoint pending on'
2993
     This indicates that an unrecognized breakpoint location should
2994
     automatically result in a pending breakpoint being created.
2995
 
2996
`set breakpoint pending off'
2997
     This indicates that pending breakpoints are not to be created.  Any
2998
     unrecognized breakpoint location results in an error.  This
2999
     setting does not affect any pending breakpoints previously created.
3000
 
3001
`show breakpoint pending'
3002
     Show the current behavior setting for creating pending breakpoints.
3003
 
3004
   The settings above only affect the `break' command and its variants.
3005
Once breakpoint is set, it will be automatically updated as shared
3006
libraries are loaded and unloaded.
3007
 
3008
   For some targets, GDB can automatically decide if hardware or
3009
software breakpoints should be used, depending on whether the
3010
breakpoint address is read-only or read-write.  This applies to
3011
breakpoints set with the `break' command as well as to internal
3012
breakpoints set by commands like `next' and `finish'.  For breakpoints
3013
set with `hbreak', GDB will always use hardware breakpoints.
3014
 
3015
   You can control this automatic behaviour with the following
3016
commands::
3017
 
3018
`set breakpoint auto-hw on'
3019
     This is the default behavior.  When GDB sets a breakpoint, it will
3020
     try to use the target memory map to decide if software or hardware
3021
     breakpoint must be used.
3022
 
3023
`set breakpoint auto-hw off'
3024
     This indicates GDB should not automatically select breakpoint
3025
     type.  If the target provides a memory map, GDB will warn when
3026
     trying to set software breakpoint at a read-only address.
3027
 
3028
   GDB normally implements breakpoints by replacing the program code at
3029
the breakpoint address with a special instruction, which, when
3030
executed, given control to the debugger.  By default, the program code
3031
is so modified only when the program is resumed.  As soon as the
3032
program stops, GDB restores the original instructions.  This behaviour
3033
guards against leaving breakpoints inserted in the target should gdb
3034
abrubptly disconnect.  However, with slow remote targets, inserting and
3035
removing breakpoint can reduce the performance.  This behavior can be
3036
controlled with the following commands::
3037
 
3038
`set breakpoint always-inserted off'
3039
     All breakpoints, including newly added by the user, are inserted in
3040
     the target only when the target is resumed.  All breakpoints are
3041
     removed from the target when it stops.
3042
 
3043
`set breakpoint always-inserted on'
3044
     Causes all breakpoints to be inserted in the target at all times.
3045
     If the user adds a new breakpoint, or changes an existing
3046
     breakpoint, the breakpoints in the target are updated immediately.
3047
     A breakpoint is removed from the target only when breakpoint
3048
     itself is removed.
3049
 
3050
`set breakpoint always-inserted auto'
3051
     This is the default mode.  If GDB is controlling the inferior in
3052
     non-stop mode (*note Non-Stop Mode::), gdb behaves as if
3053
     `breakpoint always-inserted' mode is on.  If GDB is controlling
3054
     the inferior in all-stop mode, GDB behaves as if `breakpoint
3055
     always-inserted' mode is off.
3056
 
3057
   GDB itself sometimes sets breakpoints in your program for special
3058
purposes, such as proper handling of `longjmp' (in C programs).  These
3059
internal breakpoints are assigned negative numbers, starting with `-1';
3060
`info breakpoints' does not display them.  You can see these
3061
breakpoints with the GDB maintenance command `maint info breakpoints'
3062
(*note maint info breakpoints::).
3063
 
3064
   ---------- Footnotes ----------
3065
 
3066
   (1) As of this writing, multiple-location breakpoints work only if
3067
there's line number information for all the locations.  This means that
3068
they will generally not work in system libraries, unless you have debug
3069
info with line numbers for them.
3070
 
3071

3072
File: gdb.info,  Node: Set Watchpoints,  Next: Set Catchpoints,  Prev: Set Breaks,  Up: Breakpoints
3073
 
3074
5.1.2 Setting Watchpoints
3075
-------------------------
3076
 
3077
You can use a watchpoint to stop execution whenever the value of an
3078
expression changes, without having to predict a particular place where
3079
this may happen.  (This is sometimes called a "data breakpoint".)  The
3080
expression may be as simple as the value of a single variable, or as
3081
complex as many variables combined by operators.  Examples include:
3082
 
3083
   * A reference to the value of a single variable.
3084
 
3085
   * An address cast to an appropriate data type.  For example, `*(int
3086
     *)0x12345678' will watch a 4-byte region at the specified address
3087
     (assuming an `int' occupies 4 bytes).
3088
 
3089
   * An arbitrarily complex expression, such as `a*b + c/d'.  The
3090
     expression can use any operators valid in the program's native
3091
     language (*note Languages::).
3092
 
3093
   You can set a watchpoint on an expression even if the expression can
3094
not be evaluated yet.  For instance, you can set a watchpoint on
3095
`*global_ptr' before `global_ptr' is initialized.  GDB will stop when
3096
your program sets `global_ptr' and the expression produces a valid
3097
value.  If the expression becomes valid in some other way than changing
3098
a variable (e.g. if the memory pointed to by `*global_ptr' becomes
3099
readable as the result of a `malloc' call), GDB may not stop until the
3100
next time the expression changes.
3101
 
3102
   Depending on your system, watchpoints may be implemented in software
3103
or hardware.  GDB does software watchpointing by single-stepping your
3104
program and testing the variable's value each time, which is hundreds of
3105
times slower than normal execution.  (But this may still be worth it, to
3106
catch errors where you have no clue what part of your program is the
3107
culprit.)
3108
 
3109
   On some systems, such as HP-UX, PowerPC, GNU/Linux and most other
3110
x86-based targets, GDB includes support for hardware watchpoints, which
3111
do not slow down the running of your program.
3112
 
3113
`watch EXPR [thread THREADNUM]'
3114
     Set a watchpoint for an expression.  GDB will break when the
3115
     expression EXPR is written into by the program and its value
3116
     changes.  The simplest (and the most popular) use of this command
3117
     is to watch the value of a single variable:
3118
 
3119
          (gdb) watch foo
3120
 
3121
     If the command includes a `[thread THREADNUM]' clause, GDB breaks
3122
     only when the thread identified by THREADNUM changes the value of
3123
     EXPR.  If any other threads change the value of EXPR, GDB will not
3124
     break.  Note that watchpoints restricted to a single thread in
3125
     this way only work with Hardware Watchpoints.
3126
 
3127
`rwatch EXPR [thread THREADNUM]'
3128
     Set a watchpoint that will break when the value of EXPR is read by
3129
     the program.
3130
 
3131
`awatch EXPR [thread THREADNUM]'
3132
     Set a watchpoint that will break when EXPR is either read from or
3133
     written into by the program.
3134
 
3135
`info watchpoints'
3136
     This command prints a list of watchpoints, using the same format as
3137
     `info break' (*note Set Breaks::).
3138
 
3139
   If you watch for a change in a numerically entered address you need
3140
to dereference it, as the address itself is just a constant number
3141
which will never change.  GDB refuses to create a watchpoint that
3142
watches a never-changing value:
3143
 
3144
     (gdb) watch 0x600850
3145
     Cannot watch constant value 0x600850.
3146
     (gdb) watch *(int *) 0x600850
3147
     Watchpoint 1: *(int *) 6293584
3148
 
3149
   GDB sets a "hardware watchpoint" if possible.  Hardware watchpoints
3150
execute very quickly, and the debugger reports a change in value at the
3151
exact instruction where the change occurs.  If GDB cannot set a
3152
hardware watchpoint, it sets a software watchpoint, which executes more
3153
slowly and reports the change in value at the next _statement_, not the
3154
instruction, after the change occurs.
3155
 
3156
   You can force GDB to use only software watchpoints with the `set
3157
can-use-hw-watchpoints 0' command.  With this variable set to zero, GDB
3158
will never try to use hardware watchpoints, even if the underlying
3159
system supports them.  (Note that hardware-assisted watchpoints that
3160
were set _before_ setting `can-use-hw-watchpoints' to zero will still
3161
use the hardware mechanism of watching expression values.)
3162
 
3163
`set can-use-hw-watchpoints'
3164
     Set whether or not to use hardware watchpoints.
3165
 
3166
`show can-use-hw-watchpoints'
3167
     Show the current mode of using hardware watchpoints.
3168
 
3169
   For remote targets, you can restrict the number of hardware
3170
watchpoints GDB will use, see *Note set remote
3171
hardware-breakpoint-limit::.
3172
 
3173
   When you issue the `watch' command, GDB reports
3174
 
3175
     Hardware watchpoint NUM: EXPR
3176
 
3177
if it was able to set a hardware watchpoint.
3178
 
3179
   Currently, the `awatch' and `rwatch' commands can only set hardware
3180
watchpoints, because accesses to data that don't change the value of
3181
the watched expression cannot be detected without examining every
3182
instruction as it is being executed, and GDB does not do that
3183
currently.  If GDB finds that it is unable to set a hardware breakpoint
3184
with the `awatch' or `rwatch' command, it will print a message like
3185
this:
3186
 
3187
     Expression cannot be implemented with read/access watchpoint.
3188
 
3189
   Sometimes, GDB cannot set a hardware watchpoint because the data
3190
type of the watched expression is wider than what a hardware watchpoint
3191
on the target machine can handle.  For example, some systems can only
3192
watch regions that are up to 4 bytes wide; on such systems you cannot
3193
set hardware watchpoints for an expression that yields a
3194
double-precision floating-point number (which is typically 8 bytes
3195
wide).  As a work-around, it might be possible to break the large region
3196
into a series of smaller ones and watch them with separate watchpoints.
3197
 
3198
   If you set too many hardware watchpoints, GDB might be unable to
3199
insert all of them when you resume the execution of your program.
3200
Since the precise number of active watchpoints is unknown until such
3201
time as the program is about to be resumed, GDB might not be able to
3202
warn you about this when you set the watchpoints, and the warning will
3203
be printed only when the program is resumed:
3204
 
3205
     Hardware watchpoint NUM: Could not insert watchpoint
3206
 
3207
If this happens, delete or disable some of the watchpoints.
3208
 
3209
   Watching complex expressions that reference many variables can also
3210
exhaust the resources available for hardware-assisted watchpoints.
3211
That's because GDB needs to watch every variable in the expression with
3212
separately allocated resources.
3213
 
3214
   If you call a function interactively using `print' or `call', any
3215
watchpoints you have set will be inactive until GDB reaches another
3216
kind of breakpoint or the call completes.
3217
 
3218
   GDB automatically deletes watchpoints that watch local (automatic)
3219
variables, or expressions that involve such variables, when they go out
3220
of scope, that is, when the execution leaves the block in which these
3221
variables were defined.  In particular, when the program being debugged
3222
terminates, _all_ local variables go out of scope, and so only
3223
watchpoints that watch global variables remain set.  If you rerun the
3224
program, you will need to set all such watchpoints again.  One way of
3225
doing that would be to set a code breakpoint at the entry to the `main'
3226
function and when it breaks, set all the watchpoints.
3227
 
3228
   In multi-threaded programs, watchpoints will detect changes to the
3229
watched expression from every thread.
3230
 
3231
     _Warning:_ In multi-threaded programs, software watchpoints have
3232
     only limited usefulness.  If GDB creates a software watchpoint, it
3233
     can only watch the value of an expression _in a single thread_.
3234
     If you are confident that the expression can only change due to
3235
     the current thread's activity (and if you are also confident that
3236
     no other thread can become current), then you can use software
3237
     watchpoints as usual.  However, GDB may not notice when a
3238
     non-current thread's activity changes the expression.  (Hardware
3239
     watchpoints, in contrast, watch an expression in all threads.)
3240
 
3241
   *Note set remote hardware-watchpoint-limit::.
3242
 
3243

3244
File: gdb.info,  Node: Set Catchpoints,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
3245
 
3246
5.1.3 Setting Catchpoints
3247
-------------------------
3248
 
3249
You can use "catchpoints" to cause the debugger to stop for certain
3250
kinds of program events, such as C++ exceptions or the loading of a
3251
shared library.  Use the `catch' command to set a catchpoint.
3252
 
3253
`catch EVENT'
3254
     Stop when EVENT occurs.  EVENT can be any of the following:
3255
    `throw'
3256
          The throwing of a C++ exception.
3257
 
3258
    `catch'
3259
          The catching of a C++ exception.
3260
 
3261
    `exception'
3262
          An Ada exception being raised.  If an exception name is
3263
          specified at the end of the command (eg `catch exception
3264
          Program_Error'), the debugger will stop only when this
3265
          specific exception is raised.  Otherwise, the debugger stops
3266
          execution when any Ada exception is raised.
3267
 
3268
          When inserting an exception catchpoint on a user-defined
3269
          exception whose name is identical to one of the exceptions
3270
          defined by the language, the fully qualified name must be
3271
          used as the exception name.  Otherwise, GDB will assume that
3272
          it should stop on the pre-defined exception rather than the
3273
          user-defined one.  For instance, assuming an exception called
3274
          `Constraint_Error' is defined in package `Pck', then the
3275
          command to use to catch such exceptions is `catch exception
3276
          Pck.Constraint_Error'.
3277
 
3278
    `exception unhandled'
3279
          An exception that was raised but is not handled by the
3280
          program.
3281
 
3282
    `assert'
3283
          A failed Ada assertion.
3284
 
3285
    `exec'
3286
          A call to `exec'.  This is currently only available for HP-UX
3287
          and GNU/Linux.
3288
 
3289
    `syscall'
3290
    `syscall [NAME | NUMBER] ...'
3291
          A call to or return from a system call, a.k.a. "syscall".  A
3292
          syscall is a mechanism for application programs to request a
3293
          service from the operating system (OS) or one of the OS
3294
          system services.  GDB can catch some or all of the syscalls
3295
          issued by the debuggee, and show the related information for
3296
          each syscall.  If no argument is specified, calls to and
3297
          returns from all system calls will be caught.
3298
 
3299
          NAME can be any system call name that is valid for the
3300
          underlying OS.  Just what syscalls are valid depends on the
3301
          OS.  On GNU and Unix systems, you can find the full list of
3302
          valid syscall names on `/usr/include/asm/unistd.h'.
3303
 
3304
          Normally, GDB knows in advance which syscalls are valid for
3305
          each OS, so you can use the GDB command-line completion
3306
          facilities (*note command completion: Completion.) to list the
3307
          available choices.
3308
 
3309
          You may also specify the system call numerically.  A syscall's
3310
          number is the value passed to the OS's syscall dispatcher to
3311
          identify the requested service.  When you specify the syscall
3312
          by its name, GDB uses its database of syscalls to convert the
3313
          name into the corresponding numeric code, but using the
3314
          number directly may be useful if GDB's database does not have
3315
          the complete list of syscalls on your system (e.g., because
3316
          GDB lags behind the OS upgrades).
3317
 
3318
          The example below illustrates how this command works if you
3319
          don't provide arguments to it:
3320
 
3321
               (gdb) catch syscall
3322
               Catchpoint 1 (syscall)
3323
               (gdb) r
3324
               Starting program: /tmp/catch-syscall
3325
 
3326
               Catchpoint 1 (call to syscall 'close'), \
3327
                   0xffffe424 in __kernel_vsyscall ()
3328
               (gdb) c
3329
               Continuing.
3330
 
3331
               Catchpoint 1 (returned from syscall 'close'), \
3332
                0xffffe424 in __kernel_vsyscall ()
3333
               (gdb)
3334
 
3335
          Here is an example of catching a system call by name:
3336
 
3337
               (gdb) catch syscall chroot
3338
               Catchpoint 1 (syscall 'chroot' [61])
3339
               (gdb) r
3340
               Starting program: /tmp/catch-syscall
3341
 
3342
               Catchpoint 1 (call to syscall 'chroot'), \
3343
                           0xffffe424 in __kernel_vsyscall ()
3344
               (gdb) c
3345
               Continuing.
3346
 
3347
               Catchpoint 1 (returned from syscall 'chroot'), \
3348
                0xffffe424 in __kernel_vsyscall ()
3349
               (gdb)
3350
 
3351
          An example of specifying a system call numerically.  In the
3352
          case below, the syscall number has a corresponding entry in
3353
          the XML file, so GDB finds its name and prints it:
3354
 
3355
               (gdb) catch syscall 252
3356
               Catchpoint 1 (syscall(s) 'exit_group')
3357
               (gdb) r
3358
               Starting program: /tmp/catch-syscall
3359
 
3360
               Catchpoint 1 (call to syscall 'exit_group'), \
3361
                           0xffffe424 in __kernel_vsyscall ()
3362
               (gdb) c
3363
               Continuing.
3364
 
3365
               Program exited normally.
3366
               (gdb)
3367
 
3368
          However, there can be situations when there is no
3369
          corresponding name in XML file for that syscall number.  In
3370
          this case, GDB prints a warning message saying that it was
3371
          not able to find the syscall name, but the catchpoint will be
3372
          set anyway.  See the example below:
3373
 
3374
               (gdb) catch syscall 764
3375
               warning: The number '764' does not represent a known syscall.
3376
               Catchpoint 2 (syscall 764)
3377
               (gdb)
3378
 
3379
          If you configure GDB using the `--without-expat' option, it
3380
          will not be able to display syscall names.  Also, if your
3381
          architecture does not have an XML file describing its system
3382
          calls, you will not be able to see the syscall names.  It is
3383
          important to notice that these two features are used for
3384
          accessing the syscall name database.  In either case, you
3385
          will see a warning like this:
3386
 
3387
               (gdb) catch syscall
3388
               warning: Could not open "syscalls/i386-linux.xml"
3389
               warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
3390
               GDB will not be able to display syscall names.
3391
               Catchpoint 1 (syscall)
3392
               (gdb)
3393
 
3394
          Of course, the file name will change depending on your
3395
          architecture and system.
3396
 
3397
          Still using the example above, you can also try to catch a
3398
          syscall by its number.  In this case, you would see something
3399
          like:
3400
 
3401
               (gdb) catch syscall 252
3402
               Catchpoint 1 (syscall(s) 252)
3403
 
3404
          Again, in this case GDB would not be able to display
3405
          syscall's names.
3406
 
3407
    `fork'
3408
          A call to `fork'.  This is currently only available for HP-UX
3409
          and GNU/Linux.
3410
 
3411
    `vfork'
3412
          A call to `vfork'.  This is currently only available for HP-UX
3413
          and GNU/Linux.
3414
 
3415
 
3416
`tcatch EVENT'
3417
     Set a catchpoint that is enabled only for one stop.  The
3418
     catchpoint is automatically deleted after the first time the event
3419
     is caught.
3420
 
3421
 
3422
   Use the `info break' command to list the current catchpoints.
3423
 
3424
   There are currently some limitations to C++ exception handling
3425
(`catch throw' and `catch catch') in GDB:
3426
 
3427
   * If you call a function interactively, GDB normally returns control
3428
     to you when the function has finished executing.  If the call
3429
     raises an exception, however, the call may bypass the mechanism
3430
     that returns control to you and cause your program either to abort
3431
     or to simply continue running until it hits a breakpoint, catches
3432
     a signal that GDB is listening for, or exits.  This is the case
3433
     even if you set a catchpoint for the exception; catchpoints on
3434
     exceptions are disabled within interactive calls.
3435
 
3436
   * You cannot raise an exception interactively.
3437
 
3438
   * You cannot install an exception handler interactively.
3439
 
3440
   Sometimes `catch' is not the best way to debug exception handling:
3441
if you need to know exactly where an exception is raised, it is better
3442
to stop _before_ the exception handler is called, since that way you
3443
can see the stack before any unwinding takes place.  If you set a
3444
breakpoint in an exception handler instead, it may not be easy to find
3445
out where the exception was raised.
3446
 
3447
   To stop just before an exception handler is called, you need some
3448
knowledge of the implementation.  In the case of GNU C++, exceptions are
3449
raised by calling a library function named `__raise_exception' which
3450
has the following ANSI C interface:
3451
 
3452
         /* ADDR is where the exception identifier is stored.
3453
            ID is the exception identifier.  */
3454
         void __raise_exception (void **addr, void *id);
3455
 
3456
To make the debugger catch all exceptions before any stack unwinding
3457
takes place, set a breakpoint on `__raise_exception' (*note
3458
Breakpoints; Watchpoints; and Exceptions: Breakpoints.).
3459
 
3460
   With a conditional breakpoint (*note Break Conditions: Conditions.)
3461
that depends on the value of ID, you can stop your program when a
3462
specific exception is raised.  You can use multiple conditional
3463
breakpoints to stop your program when any of a number of exceptions are
3464
raised.
3465
 
3466

3467
File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Catchpoints,  Up: Breakpoints
3468
 
3469
5.1.4 Deleting Breakpoints
3470
--------------------------
3471
 
3472
It is often necessary to eliminate a breakpoint, watchpoint, or
3473
catchpoint once it has done its job and you no longer want your program
3474
to stop there.  This is called "deleting" the breakpoint.  A breakpoint
3475
that has been deleted no longer exists; it is forgotten.
3476
 
3477
   With the `clear' command you can delete breakpoints according to
3478
where they are in your program.  With the `delete' command you can
3479
delete individual breakpoints, watchpoints, or catchpoints by specifying
3480
their breakpoint numbers.
3481
 
3482
   It is not necessary to delete a breakpoint to proceed past it.  GDB
3483
automatically ignores breakpoints on the first instruction to be
3484
executed when you continue execution without changing the execution
3485
address.
3486
 
3487
`clear'
3488
     Delete any breakpoints at the next instruction to be executed in
3489
     the selected stack frame (*note Selecting a Frame: Selection.).
3490
     When the innermost frame is selected, this is a good way to delete
3491
     a breakpoint where your program just stopped.
3492
 
3493
`clear LOCATION'
3494
     Delete any breakpoints set at the specified LOCATION.  *Note
3495
     Specify Location::, for the various forms of LOCATION; the most
3496
     useful ones are listed below:
3497
 
3498
    `clear FUNCTION'
3499
    `clear FILENAME:FUNCTION'
3500
          Delete any breakpoints set at entry to the named FUNCTION.
3501
 
3502
    `clear LINENUM'
3503
    `clear FILENAME:LINENUM'
3504
          Delete any breakpoints set at or within the code of the
3505
          specified LINENUM of the specified FILENAME.
3506
 
3507
`delete [breakpoints] [RANGE...]'
3508
     Delete the breakpoints, watchpoints, or catchpoints of the
3509
     breakpoint ranges specified as arguments.  If no argument is
3510
     specified, delete all breakpoints (GDB asks confirmation, unless
3511
     you have `set confirm off').  You can abbreviate this command as
3512
     `d'.
3513
 
3514

3515
File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
3516
 
3517
5.1.5 Disabling Breakpoints
3518
---------------------------
3519
 
3520
Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3521
prefer to "disable" it.  This makes the breakpoint inoperative as if it
3522
had been deleted, but remembers the information on the breakpoint so
3523
that you can "enable" it again later.
3524
 
3525
   You disable and enable breakpoints, watchpoints, and catchpoints with
3526
the `enable' and `disable' commands, optionally specifying one or more
3527
breakpoint numbers as arguments.  Use `info break' to print a list of
3528
all breakpoints, watchpoints, and catchpoints if you do not know which
3529
numbers to use.
3530
 
3531
   Disabling and enabling a breakpoint that has multiple locations
3532
affects all of its locations.
3533
 
3534
   A breakpoint, watchpoint, or catchpoint can have any of four
3535
different states of enablement:
3536
 
3537
   * Enabled.  The breakpoint stops your program.  A breakpoint set
3538
     with the `break' command starts out in this state.
3539
 
3540
   * Disabled.  The breakpoint has no effect on your program.
3541
 
3542
   * Enabled once.  The breakpoint stops your program, but then becomes
3543
     disabled.
3544
 
3545
   * Enabled for deletion.  The breakpoint stops your program, but
3546
     immediately after it does so it is deleted permanently.  A
3547
     breakpoint set with the `tbreak' command starts out in this state.
3548
 
3549
   You can use the following commands to enable or disable breakpoints,
3550
watchpoints, and catchpoints:
3551
 
3552
`disable [breakpoints] [RANGE...]'
3553
     Disable the specified breakpoints--or all breakpoints, if none are
3554
     listed.  A disabled breakpoint has no effect but is not forgotten.
3555
     All options such as ignore-counts, conditions and commands are
3556
     remembered in case the breakpoint is enabled again later.  You may
3557
     abbreviate `disable' as `dis'.
3558
 
3559
`enable [breakpoints] [RANGE...]'
3560
     Enable the specified breakpoints (or all defined breakpoints).
3561
     They become effective once again in stopping your program.
3562
 
3563
`enable [breakpoints] once RANGE...'
3564
     Enable the specified breakpoints temporarily.  GDB disables any of
3565
     these breakpoints immediately after stopping your program.
3566
 
3567
`enable [breakpoints] delete RANGE...'
3568
     Enable the specified breakpoints to work once, then die.  GDB
3569
     deletes any of these breakpoints as soon as your program stops
3570
     there.  Breakpoints set by the `tbreak' command start out in this
3571
     state.
3572
 
3573
   Except for a breakpoint set with `tbreak' (*note Setting
3574
Breakpoints: Set Breaks.), breakpoints that you set are initially
3575
enabled; subsequently, they become disabled or enabled only when you
3576
use one of the commands above.  (The command `until' can set and delete
3577
a breakpoint of its own, but it does not change the state of your other
3578
breakpoints; see *Note Continuing and Stepping: Continuing and
3579
Stepping.)
3580
 
3581

3582
File: gdb.info,  Node: Conditions,  Next: Break Commands,  Prev: Disabling,  Up: Breakpoints
3583
 
3584
5.1.6 Break Conditions
3585
----------------------
3586
 
3587
The simplest sort of breakpoint breaks every time your program reaches a
3588
specified place.  You can also specify a "condition" for a breakpoint.
3589
A condition is just a Boolean expression in your programming language
3590
(*note Expressions: Expressions.).  A breakpoint with a condition
3591
evaluates the expression each time your program reaches it, and your
3592
program stops only if the condition is _true_.
3593
 
3594
   This is the converse of using assertions for program validation; in
3595
that situation, you want to stop when the assertion is violated--that
3596
is, when the condition is false.  In C, if you want to test an
3597
assertion expressed by the condition ASSERT, you should set the
3598
condition `! ASSERT' on the appropriate breakpoint.
3599
 
3600
   Conditions are also accepted for watchpoints; you may not need them,
3601
since a watchpoint is inspecting the value of an expression anyhow--but
3602
it might be simpler, say, to just set a watchpoint on a variable name,
3603
and specify a condition that tests whether the new value is an
3604
interesting one.
3605
 
3606
   Break conditions can have side effects, and may even call functions
3607
in your program.  This can be useful, for example, to activate functions
3608
that log program progress, or to use your own print functions to format
3609
special data structures.  The effects are completely predictable unless
3610
there is another enabled breakpoint at the same address.  (In that
3611
case, GDB might see the other breakpoint first and stop your program
3612
without checking the condition of this one.)  Note that breakpoint
3613
commands are usually more convenient and flexible than break conditions
3614
for the purpose of performing side effects when a breakpoint is reached
3615
(*note Breakpoint Command Lists: Break Commands.).
3616
 
3617
   Break conditions can be specified when a breakpoint is set, by using
3618
`if' in the arguments to the `break' command.  *Note Setting
3619
Breakpoints: Set Breaks.  They can also be changed at any time with the
3620
`condition' command.
3621
 
3622
   You can also use the `if' keyword with the `watch' command.  The
3623
`catch' command does not recognize the `if' keyword; `condition' is the
3624
only way to impose a further condition on a catchpoint.
3625
 
3626
`condition BNUM EXPRESSION'
3627
     Specify EXPRESSION as the break condition for breakpoint,
3628
     watchpoint, or catchpoint number BNUM.  After you set a condition,
3629
     breakpoint BNUM stops your program only if the value of EXPRESSION
3630
     is true (nonzero, in C).  When you use `condition', GDB checks
3631
     EXPRESSION immediately for syntactic correctness, and to determine
3632
     whether symbols in it have referents in the context of your
3633
     breakpoint.  If EXPRESSION uses symbols not referenced in the
3634
     context of the breakpoint, GDB prints an error message:
3635
 
3636
          No symbol "foo" in current context.
3637
 
3638
     GDB does not actually evaluate EXPRESSION at the time the
3639
     `condition' command (or a command that sets a breakpoint with a
3640
     condition, like `break if ...') is given, however.  *Note
3641
     Expressions: Expressions.
3642
 
3643
`condition BNUM'
3644
     Remove the condition from breakpoint number BNUM.  It becomes an
3645
     ordinary unconditional breakpoint.
3646
 
3647
   A special case of a breakpoint condition is to stop only when the
3648
breakpoint has been reached a certain number of times.  This is so
3649
useful that there is a special way to do it, using the "ignore count"
3650
of the breakpoint.  Every breakpoint has an ignore count, which is an
3651
integer.  Most of the time, the ignore count is zero, and therefore has
3652
no effect.  But if your program reaches a breakpoint whose ignore count
3653
is positive, then instead of stopping, it just decrements the ignore
3654
count by one and continues.  As a result, if the ignore count value is
3655
N, the breakpoint does not stop the next N times your program reaches
3656
it.
3657
 
3658
`ignore BNUM COUNT'
3659
     Set the ignore count of breakpoint number BNUM to COUNT.  The next
3660
     COUNT times the breakpoint is reached, your program's execution
3661
     does not stop; other than to decrement the ignore count, GDB takes
3662
     no action.
3663
 
3664
     To make the breakpoint stop the next time it is reached, specify a
3665
     count of zero.
3666
 
3667
     When you use `continue' to resume execution of your program from a
3668
     breakpoint, you can specify an ignore count directly as an
3669
     argument to `continue', rather than using `ignore'.  *Note
3670
     Continuing and Stepping: Continuing and Stepping.
3671
 
3672
     If a breakpoint has a positive ignore count and a condition, the
3673
     condition is not checked.  Once the ignore count reaches zero, GDB
3674
     resumes checking the condition.
3675
 
3676
     You could achieve the effect of the ignore count with a condition
3677
     such as `$foo-- <= 0' using a debugger convenience variable that
3678
     is decremented each time.  *Note Convenience Variables:
3679
     Convenience Vars.
3680
 
3681
   Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3682
 
3683

3684
File: gdb.info,  Node: Break Commands,  Next: Save Breakpoints,  Prev: Conditions,  Up: Breakpoints
3685
 
3686
5.1.7 Breakpoint Command Lists
3687
------------------------------
3688
 
3689
You can give any breakpoint (or watchpoint or catchpoint) a series of
3690
commands to execute when your program stops due to that breakpoint.  For
3691
example, you might want to print the values of certain expressions, or
3692
enable other breakpoints.
3693
 
3694
`commands [RANGE...]'
3695
`... COMMAND-LIST ...'
3696
`end'
3697
     Specify a list of commands for the given breakpoints.  The commands
3698
     themselves appear on the following lines.  Type a line containing
3699
     just `end' to terminate the commands.
3700
 
3701
     To remove all commands from a breakpoint, type `commands' and
3702
     follow it immediately with `end'; that is, give no commands.
3703
 
3704
     With no argument, `commands' refers to the last breakpoint,
3705
     watchpoint, or catchpoint set (not to the breakpoint most recently
3706
     encountered).  If the most recent breakpoints were set with a
3707
     single command, then the `commands' will apply to all the
3708
     breakpoints set by that command.  This applies to breakpoints set
3709
     by `rbreak', and also applies when a single `break' command
3710
     creates multiple breakpoints (*note Ambiguous Expressions:
3711
     Ambiguous Expressions.).
3712
 
3713
   Pressing  as a means of repeating the last GDB command is
3714
disabled within a COMMAND-LIST.
3715
 
3716
   You can use breakpoint commands to start your program up again.
3717
Simply use the `continue' command, or `step', or any other command that
3718
resumes execution.
3719
 
3720
   Any other commands in the command list, after a command that resumes
3721
execution, are ignored.  This is because any time you resume execution
3722
(even with a simple `next' or `step'), you may encounter another
3723
breakpoint--which could have its own command list, leading to
3724
ambiguities about which list to execute.
3725
 
3726
   If the first command you specify in a command list is `silent', the
3727
usual message about stopping at a breakpoint is not printed.  This may
3728
be desirable for breakpoints that are to print a specific message and
3729
then continue.  If none of the remaining commands print anything, you
3730
see no sign that the breakpoint was reached.  `silent' is meaningful
3731
only at the beginning of a breakpoint command list.
3732
 
3733
   The commands `echo', `output', and `printf' allow you to print
3734
precisely controlled output, and are often useful in silent
3735
breakpoints.  *Note Commands for Controlled Output: Output.
3736
 
3737
   For example, here is how you could use breakpoint commands to print
3738
the value of `x' at entry to `foo' whenever `x' is positive.
3739
 
3740
     break foo if x>0
3741
     commands
3742
     silent
3743
     printf "x is %d\n",x
3744
     cont
3745
     end
3746
 
3747
   One application for breakpoint commands is to compensate for one bug
3748
so you can test for another.  Put a breakpoint just after the erroneous
3749
line of code, give it a condition to detect the case in which something
3750
erroneous has been done, and give it commands to assign correct values
3751
to any variables that need them.  End with the `continue' command so
3752
that your program does not stop, and start with the `silent' command so
3753
that no output is produced.  Here is an example:
3754
 
3755
     break 403
3756
     commands
3757
     silent
3758
     set x = y + 4
3759
     cont
3760
     end
3761
 
3762

3763
File: gdb.info,  Node: Save Breakpoints,  Next: Error in Breakpoints,  Prev: Break Commands,  Up: Breakpoints
3764
 
3765
5.1.8 How to save breakpoints to a file
3766
---------------------------------------
3767
 
3768
To save breakpoint definitions to a file use the `save breakpoints'
3769
command.
3770
 
3771
`save breakpoints [FILENAME]'
3772
     This command saves all current breakpoint definitions together with
3773
     their commands and ignore counts, into a file `FILENAME' suitable
3774
     for use in a later debugging session.  This includes all types of
3775
     breakpoints (breakpoints, watchpoints, catchpoints, tracepoints).
3776
     To read the saved breakpoint definitions, use the `source' command
3777
     (*note Command Files::).  Note that watchpoints with expressions
3778
     involving local variables may fail to be recreated because it may
3779
     not be possible to access the context where the watchpoint is
3780
     valid anymore.  Because the saved breakpoint definitions are
3781
     simply a sequence of GDB commands that recreate the breakpoints,
3782
     you can edit the file in your favorite editing program, and remove
3783
     the breakpoint definitions you're not interested in, or that can
3784
     no longer be recreated.
3785
 
3786

3787
File: gdb.info,  Node: Error in Breakpoints,  Next: Breakpoint-related Warnings,  Prev: Save Breakpoints,  Up: Breakpoints
3788
 
3789
5.1.9 "Cannot insert breakpoints"
3790
---------------------------------
3791
 
3792
If you request too many active hardware-assisted breakpoints and
3793
watchpoints, you will see this error message:
3794
 
3795
     Stopped; cannot insert breakpoints.
3796
     You may have requested too many hardware breakpoints and watchpoints.
3797
 
3798
This message is printed when you attempt to resume the program, since
3799
only then GDB knows exactly how many hardware breakpoints and
3800
watchpoints it needs to insert.
3801
 
3802
   When this message is printed, you need to disable or remove some of
3803
the hardware-assisted breakpoints and watchpoints, and then continue.
3804
 
3805

3806
File: gdb.info,  Node: Breakpoint-related Warnings,  Prev: Error in Breakpoints,  Up: Breakpoints
3807
 
3808
5.1.10 "Breakpoint address adjusted..."
3809
---------------------------------------
3810
 
3811
Some processor architectures place constraints on the addresses at
3812
which breakpoints may be placed.  For architectures thus constrained,
3813
GDB will attempt to adjust the breakpoint's address to comply with the
3814
constraints dictated by the architecture.
3815
 
3816
   One example of such an architecture is the Fujitsu FR-V.  The FR-V is
3817
a VLIW architecture in which a number of RISC-like instructions may be
3818
bundled together for parallel execution.  The FR-V architecture
3819
constrains the location of a breakpoint instruction within such a
3820
bundle to the instruction with the lowest address.  GDB honors this
3821
constraint by adjusting a breakpoint's address to the first in the
3822
bundle.
3823
 
3824
   It is not uncommon for optimized code to have bundles which contain
3825
instructions from different source statements, thus it may happen that
3826
a breakpoint's address will be adjusted from one source statement to
3827
another.  Since this adjustment may significantly alter GDB's
3828
breakpoint related behavior from what the user expects, a warning is
3829
printed when the breakpoint is first set and also when the breakpoint
3830
is hit.
3831
 
3832
   A warning like the one below is printed when setting a breakpoint
3833
that's been subject to address adjustment:
3834
 
3835
     warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3836
 
3837
   Such warnings are printed both for user settable and GDB's internal
3838
breakpoints.  If you see one of these warnings, you should verify that
3839
a breakpoint set at the adjusted address will have the desired affect.
3840
If not, the breakpoint in question may be removed and other breakpoints
3841
may be set which will have the desired behavior.  E.g., it may be
3842
sufficient to place the breakpoint at a later instruction.  A
3843
conditional breakpoint may also be useful in some cases to prevent the
3844
breakpoint from triggering too often.
3845
 
3846
   GDB will also issue a warning when stopping at one of these adjusted
3847
breakpoints:
3848
 
3849
     warning: Breakpoint 1 address previously adjusted from 0x00010414
3850
     to 0x00010410.
3851
 
3852
   When this warning is encountered, it may be too late to take remedial
3853
action except in cases where the breakpoint is hit earlier or more
3854
frequently than expected.
3855
 
3856

3857
File: gdb.info,  Node: Continuing and Stepping,  Next: Signals,  Prev: Breakpoints,  Up: Stopping
3858
 
3859
5.2 Continuing and Stepping
3860
===========================
3861
 
3862
"Continuing" means resuming program execution until your program
3863
completes normally.  In contrast, "stepping" means executing just one
3864
more "step" of your program, where "step" may mean either one line of
3865
source code, or one machine instruction (depending on what particular
3866
command you use).  Either when continuing or when stepping, your
3867
program may stop even sooner, due to a breakpoint or a signal.  (If it
3868
stops due to a signal, you may want to use `handle', or use `signal 0'
3869
to resume execution.  *Note Signals: Signals.)
3870
 
3871
`continue [IGNORE-COUNT]'
3872
`c [IGNORE-COUNT]'
3873
`fg [IGNORE-COUNT]'
3874
     Resume program execution, at the address where your program last
3875
     stopped; any breakpoints set at that address are bypassed.  The
3876
     optional argument IGNORE-COUNT allows you to specify a further
3877
     number of times to ignore a breakpoint at this location; its
3878
     effect is like that of `ignore' (*note Break Conditions:
3879
     Conditions.).
3880
 
3881
     The argument IGNORE-COUNT is meaningful only when your program
3882
     stopped due to a breakpoint.  At other times, the argument to
3883
     `continue' is ignored.
3884
 
3885
     The synonyms `c' and `fg' (for "foreground", as the debugged
3886
     program is deemed to be the foreground program) are provided
3887
     purely for convenience, and have exactly the same behavior as
3888
     `continue'.
3889
 
3890
   To resume execution at a different place, you can use `return'
3891
(*note Returning from a Function: Returning.) to go back to the calling
3892
function; or `jump' (*note Continuing at a Different Address: Jumping.)
3893
to go to an arbitrary location in your program.
3894
 
3895
   A typical technique for using stepping is to set a breakpoint (*note
3896
Breakpoints; Watchpoints; and Catchpoints: Breakpoints.) at the
3897
beginning of the function or the section of your program where a problem
3898
is believed to lie, run your program until it stops at that breakpoint,
3899
and then step through the suspect area, examining the variables that are
3900
interesting, until you see the problem happen.
3901
 
3902
`step'
3903
     Continue running your program until control reaches a different
3904
     source line, then stop it and return control to GDB.  This command
3905
     is abbreviated `s'.
3906
 
3907
          _Warning:_ If you use the `step' command while control is
3908
          within a function that was compiled without debugging
3909
          information, execution proceeds until control reaches a
3910
          function that does have debugging information.  Likewise, it
3911
          will not step into a function which is compiled without
3912
          debugging information.  To step through functions without
3913
          debugging information, use the `stepi' command, described
3914
          below.
3915
 
3916
     The `step' command only stops at the first instruction of a source
3917
     line.  This prevents the multiple stops that could otherwise occur
3918
     in `switch' statements, `for' loops, etc.  `step' continues to
3919
     stop if a function that has debugging information is called within
3920
     the line.  In other words, `step' _steps inside_ any functions
3921
     called within the line.
3922
 
3923
     Also, the `step' command only enters a function if there is line
3924
     number information for the function.  Otherwise it acts like the
3925
     `next' command.  This avoids problems when using `cc -gl' on MIPS
3926
     machines.  Previously, `step' entered subroutines if there was any
3927
     debugging information about the routine.
3928
 
3929
`step COUNT'
3930
     Continue running as in `step', but do so COUNT times.  If a
3931
     breakpoint is reached, or a signal not related to stepping occurs
3932
     before COUNT steps, stepping stops right away.
3933
 
3934
`next [COUNT]'
3935
     Continue to the next source line in the current (innermost) stack
3936
     frame.  This is similar to `step', but function calls that appear
3937
     within the line of code are executed without stopping.  Execution
3938
     stops when control reaches a different line of code at the
3939
     original stack level that was executing when you gave the `next'
3940
     command.  This command is abbreviated `n'.
3941
 
3942
     An argument COUNT is a repeat count, as for `step'.
3943
 
3944
     The `next' command only stops at the first instruction of a source
3945
     line.  This prevents multiple stops that could otherwise occur in
3946
     `switch' statements, `for' loops, etc.
3947
 
3948
`set step-mode'
3949
`set step-mode on'
3950
     The `set step-mode on' command causes the `step' command to stop
3951
     at the first instruction of a function which contains no debug line
3952
     information rather than stepping over it.
3953
 
3954
     This is useful in cases where you may be interested in inspecting
3955
     the machine instructions of a function which has no symbolic info
3956
     and do not want GDB to automatically skip over this function.
3957
 
3958
`set step-mode off'
3959
     Causes the `step' command to step over any functions which
3960
     contains no debug information.  This is the default.
3961
 
3962
`show step-mode'
3963
     Show whether GDB will stop in or step over functions without
3964
     source line debug information.
3965
 
3966
`finish'
3967
     Continue running until just after function in the selected stack
3968
     frame returns.  Print the returned value (if any).  This command
3969
     can be abbreviated as `fin'.
3970
 
3971
     Contrast this with the `return' command (*note Returning from a
3972
     Function: Returning.).
3973
 
3974
`until'
3975
`u'
3976
     Continue running until a source line past the current line, in the
3977
     current stack frame, is reached.  This command is used to avoid
3978
     single stepping through a loop more than once.  It is like the
3979
     `next' command, except that when `until' encounters a jump, it
3980
     automatically continues execution until the program counter is
3981
     greater than the address of the jump.
3982
 
3983
     This means that when you reach the end of a loop after single
3984
     stepping though it, `until' makes your program continue execution
3985
     until it exits the loop.  In contrast, a `next' command at the end
3986
     of a loop simply steps back to the beginning of the loop, which
3987
     forces you to step through the next iteration.
3988
 
3989
     `until' always stops your program if it attempts to exit the
3990
     current stack frame.
3991
 
3992
     `until' may produce somewhat counterintuitive results if the order
3993
     of machine code does not match the order of the source lines.  For
3994
     example, in the following excerpt from a debugging session, the `f'
3995
     (`frame') command shows that execution is stopped at line `206';
3996
     yet when we use `until', we get to line `195':
3997
 
3998
          (gdb) f
3999
          #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
4000
          206                 expand_input();
4001
          (gdb) until
4002
          195             for ( ; argc > 0; NEXTARG) {
4003
 
4004
     This happened because, for execution efficiency, the compiler had
4005
     generated code for the loop closure test at the end, rather than
4006
     the start, of the loop--even though the test in a C `for'-loop is
4007
     written before the body of the loop.  The `until' command appeared
4008
     to step back to the beginning of the loop when it advanced to this
4009
     expression; however, it has not really gone to an earlier
4010
     statement--not in terms of the actual machine code.
4011
 
4012
     `until' with no argument works by means of single instruction
4013
     stepping, and hence is slower than `until' with an argument.
4014
 
4015
`until LOCATION'
4016
`u LOCATION'
4017
     Continue running your program until either the specified location
4018
     is reached, or the current stack frame returns.  LOCATION is any of
4019
     the forms described in *Note Specify Location::.  This form of the
4020
     command uses temporary breakpoints, and hence is quicker than
4021
     `until' without an argument.  The specified location is actually
4022
     reached only if it is in the current frame.  This implies that
4023
     `until' can be used to skip over recursive function invocations.
4024
     For instance in the code below, if the current location is line
4025
     `96', issuing `until 99' will execute the program up to line `99'
4026
     in the same invocation of factorial, i.e., after the inner
4027
     invocations have returned.
4028
 
4029
          94    int factorial (int value)
4030
          95    {
4031
          96        if (value > 1) {
4032
          97            value *= factorial (value - 1);
4033
          98        }
4034
          99        return (value);
4035
          100     }
4036
 
4037
`advance LOCATION'
4038
     Continue running the program up to the given LOCATION.  An
4039
     argument is required, which should be of one of the forms
4040
     described in *Note Specify Location::.  Execution will also stop
4041
     upon exit from the current stack frame.  This command is similar
4042
     to `until', but `advance' will not skip over recursive function
4043
     calls, and the target location doesn't have to be in the same
4044
     frame as the current one.
4045
 
4046
`stepi'
4047
`stepi ARG'
4048
`si'
4049
     Execute one machine instruction, then stop and return to the
4050
     debugger.
4051
 
4052
     It is often useful to do `display/i $pc' when stepping by machine
4053
     instructions.  This makes GDB automatically display the next
4054
     instruction to be executed, each time your program stops.  *Note
4055
     Automatic Display: Auto Display.
4056
 
4057
     An argument is a repeat count, as in `step'.
4058
 
4059
`nexti'
4060
`nexti ARG'
4061
`ni'
4062
     Execute one machine instruction, but if it is a function call,
4063
     proceed until the function returns.
4064
 
4065
     An argument is a repeat count, as in `next'.
4066
 
4067

4068
File: gdb.info,  Node: Signals,  Next: Thread Stops,  Prev: Continuing and Stepping,  Up: Stopping
4069
 
4070
5.3 Signals
4071
===========
4072
 
4073
A signal is an asynchronous event that can happen in a program.  The
4074
operating system defines the possible kinds of signals, and gives each
4075
kind a name and a number.  For example, in Unix `SIGINT' is the signal
4076
a program gets when you type an interrupt character (often `Ctrl-c');
4077
`SIGSEGV' is the signal a program gets from referencing a place in
4078
memory far away from all the areas in use; `SIGALRM' occurs when the
4079
alarm clock timer goes off (which happens only if your program has
4080
requested an alarm).
4081
 
4082
   Some signals, including `SIGALRM', are a normal part of the
4083
functioning of your program.  Others, such as `SIGSEGV', indicate
4084
errors; these signals are "fatal" (they kill your program immediately)
4085
if the program has not specified in advance some other way to handle
4086
the signal.  `SIGINT' does not indicate an error in your program, but
4087
it is normally fatal so it can carry out the purpose of the interrupt:
4088
to kill the program.
4089
 
4090
   GDB has the ability to detect any occurrence of a signal in your
4091
program.  You can tell GDB in advance what to do for each kind of
4092
signal.
4093
 
4094
   Normally, GDB is set up to let the non-erroneous signals like
4095
`SIGALRM' be silently passed to your program (so as not to interfere
4096
with their role in the program's functioning) but to stop your program
4097
immediately whenever an error signal happens.  You can change these
4098
settings with the `handle' command.
4099
 
4100
`info signals'
4101
`info handle'
4102
     Print a table of all the kinds of signals and how GDB has been
4103
     told to handle each one.  You can use this to see the signal
4104
     numbers of all the defined types of signals.
4105
 
4106
`info signals SIG'
4107
     Similar, but print information only about the specified signal
4108
     number.
4109
 
4110
     `info handle' is an alias for `info signals'.
4111
 
4112
`handle SIGNAL [KEYWORDS...]'
4113
     Change the way GDB handles signal SIGNAL.  SIGNAL can be the
4114
     number of a signal or its name (with or without the `SIG' at the
4115
     beginning); a list of signal numbers of the form `LOW-HIGH'; or
4116
     the word `all', meaning all the known signals.  Optional arguments
4117
     KEYWORDS, described below, say what change to make.
4118
 
4119
   The keywords allowed by the `handle' command can be abbreviated.
4120
Their full names are:
4121
 
4122
`nostop'
4123
     GDB should not stop your program when this signal happens.  It may
4124
     still print a message telling you that the signal has come in.
4125
 
4126
`stop'
4127
     GDB should stop your program when this signal happens.  This
4128
     implies the `print' keyword as well.
4129
 
4130
`print'
4131
     GDB should print a message when this signal happens.
4132
 
4133
`noprint'
4134
     GDB should not mention the occurrence of the signal at all.  This
4135
     implies the `nostop' keyword as well.
4136
 
4137
`pass'
4138
`noignore'
4139
     GDB should allow your program to see this signal; your program can
4140
     handle the signal, or else it may terminate if the signal is fatal
4141
     and not handled.  `pass' and `noignore' are synonyms.
4142
 
4143
`nopass'
4144
`ignore'
4145
     GDB should not allow your program to see this signal.  `nopass'
4146
     and `ignore' are synonyms.
4147
 
4148
   When a signal stops your program, the signal is not visible to the
4149
program until you continue.  Your program sees the signal then, if
4150
`pass' is in effect for the signal in question _at that time_.  In
4151
other words, after GDB reports a signal, you can use the `handle'
4152
command with `pass' or `nopass' to control whether your program sees
4153
that signal when you continue.
4154
 
4155
   The default is set to `nostop', `noprint', `pass' for non-erroneous
4156
signals such as `SIGALRM', `SIGWINCH' and `SIGCHLD', and to `stop',
4157
`print', `pass' for the erroneous signals.
4158
 
4159
   You can also use the `signal' command to prevent your program from
4160
seeing a signal, or cause it to see a signal it normally would not see,
4161
or to give it any signal at any time.  For example, if your program
4162
stopped due to some sort of memory reference error, you might store
4163
correct values into the erroneous variables and continue, hoping to see
4164
more execution; but your program would probably terminate immediately as
4165
a result of the fatal signal once it saw the signal.  To prevent this,
4166
you can continue with `signal 0'.  *Note Giving your Program a Signal:
4167
Signaling.
4168
 
4169
   On some targets, GDB can inspect extra signal information associated
4170
with the intercepted signal, before it is actually delivered to the
4171
program being debugged.  This information is exported by the
4172
convenience variable `$_siginfo', and consists of data that is passed
4173
by the kernel to the signal handler at the time of the receipt of a
4174
signal.  The data type of the information itself is target dependent.
4175
You can see the data type using the `ptype $_siginfo' command.  On Unix
4176
systems, it typically corresponds to the standard `siginfo_t' type, as
4177
defined in the `signal.h' system header.
4178
 
4179
   Here's an example, on a GNU/Linux system, printing the stray
4180
referenced address that raised a segmentation fault.
4181
 
4182
     (gdb) continue
4183
     Program received signal SIGSEGV, Segmentation fault.
4184
     0x0000000000400766 in main ()
4185
     69        *(int *)p = 0;
4186
     (gdb) ptype $_siginfo
4187
     type = struct {
4188
         int si_signo;
4189
         int si_errno;
4190
         int si_code;
4191
         union {
4192
             int _pad[28];
4193
             struct {...} _kill;
4194
             struct {...} _timer;
4195
             struct {...} _rt;
4196
             struct {...} _sigchld;
4197
             struct {...} _sigfault;
4198
             struct {...} _sigpoll;
4199
         } _sifields;
4200
     }
4201
     (gdb) ptype $_siginfo._sifields._sigfault
4202
     type = struct {
4203
         void *si_addr;
4204
     }
4205
     (gdb) p $_siginfo._sifields._sigfault.si_addr
4206
     $1 = (void *) 0x7ffff7ff7000
4207
 
4208
   Depending on target support, `$_siginfo' may also be writable.
4209
 
4210

4211
File: gdb.info,  Node: Thread Stops,  Prev: Signals,  Up: Stopping
4212
 
4213
5.4 Stopping and Starting Multi-thread Programs
4214
===============================================
4215
 
4216
GDB supports debugging programs with multiple threads (*note Debugging
4217
Programs with Multiple Threads: Threads.).  There are two modes of
4218
controlling execution of your program within the debugger.  In the
4219
default mode, referred to as "all-stop mode", when any thread in your
4220
program stops (for example, at a breakpoint or while being stepped),
4221
all other threads in the program are also stopped by GDB.  On some
4222
targets, GDB also supports "non-stop mode", in which other threads can
4223
continue to run freely while you examine the stopped thread in the
4224
debugger.
4225
 
4226
* Menu:
4227
 
4228
* All-Stop Mode::               All threads stop when GDB takes control
4229
* Non-Stop Mode::               Other threads continue to execute
4230
* Background Execution::        Running your program asynchronously
4231
* Thread-Specific Breakpoints:: Controlling breakpoints
4232
* Interrupted System Calls::    GDB may interfere with system calls
4233
* Observer Mode::               GDB does not alter program behavior
4234
 
4235

4236
File: gdb.info,  Node: All-Stop Mode,  Next: Non-Stop Mode,  Up: Thread Stops
4237
 
4238
5.4.1 All-Stop Mode
4239
-------------------
4240
 
4241
In all-stop mode, whenever your program stops under GDB for any reason,
4242
_all_ threads of execution stop, not just the current thread.  This
4243
allows you to examine the overall state of the program, including
4244
switching between threads, without worrying that things may change
4245
underfoot.
4246
 
4247
   Conversely, whenever you restart the program, _all_ threads start
4248
executing.  _This is true even when single-stepping_ with commands like
4249
`step' or `next'.
4250
 
4251
   In particular, GDB cannot single-step all threads in lockstep.
4252
Since thread scheduling is up to your debugging target's operating
4253
system (not controlled by GDB), other threads may execute more than one
4254
statement while the current thread completes a single step.  Moreover,
4255
in general other threads stop in the middle of a statement, rather than
4256
at a clean statement boundary, when the program stops.
4257
 
4258
   You might even find your program stopped in another thread after
4259
continuing or even single-stepping.  This happens whenever some other
4260
thread runs into a breakpoint, a signal, or an exception before the
4261
first thread completes whatever you requested.
4262
 
4263
   Whenever GDB stops your program, due to a breakpoint or a signal, it
4264
automatically selects the thread where that breakpoint or signal
4265
happened.  GDB alerts you to the context switch with a message such as
4266
`[Switching to Thread N]' to identify the thread.
4267
 
4268
   On some OSes, you can modify GDB's default behavior by locking the
4269
OS scheduler to allow only a single thread to run.
4270
 
4271
`set scheduler-locking MODE'
4272
     Set the scheduler locking mode.  If it is `off', then there is no
4273
     locking and any thread may run at any time.  If `on', then only the
4274
     current thread may run when the inferior is resumed.  The `step'
4275
     mode optimizes for single-stepping; it prevents other threads from
4276
     preempting the current thread while you are stepping, so that the
4277
     focus of debugging does not change unexpectedly.  Other threads
4278
     only rarely (or never) get a chance to run when you step.  They
4279
     are more likely to run when you `next' over a function call, and
4280
     they are completely free to run when you use commands like
4281
     `continue', `until', or `finish'.  However, unless another thread
4282
     hits a breakpoint during its timeslice, GDB does not change the
4283
     current thread away from the thread that you are debugging.
4284
 
4285
`show scheduler-locking'
4286
     Display the current scheduler locking mode.
4287
 
4288
   By default, when you issue one of the execution commands such as
4289
`continue', `next' or `step', GDB allows only threads of the current
4290
inferior to run.  For example, if GDB is attached to two inferiors,
4291
each with two threads, the `continue' command resumes only the two
4292
threads of the current inferior.  This is useful, for example, when you
4293
debug a program that forks and you want to hold the parent stopped (so
4294
that, for instance, it doesn't run to exit), while you debug the child.
4295
In other situations, you may not be interested in inspecting the
4296
current state of any of the processes GDB is attached to, and you may
4297
want to resume them all until some breakpoint is hit.  In the latter
4298
case, you can instruct GDB to allow all threads of all the inferiors to
4299
run with the `set schedule-multiple' command.
4300
 
4301
`set schedule-multiple'
4302
     Set the mode for allowing threads of multiple processes to be
4303
     resumed when an execution command is issued.  When `on', all
4304
     threads of all processes are allowed to run.  When `off', only the
4305
     threads of the current process are resumed.  The default is `off'.
4306
     The `scheduler-locking' mode takes precedence when set to `on',
4307
     or while you are stepping and set to `step'.
4308
 
4309
`show schedule-multiple'
4310
     Display the current mode for resuming the execution of threads of
4311
     multiple processes.
4312
 
4313

4314
File: gdb.info,  Node: Non-Stop Mode,  Next: Background Execution,  Prev: All-Stop Mode,  Up: Thread Stops
4315
 
4316
5.4.2 Non-Stop Mode
4317
-------------------
4318
 
4319
For some multi-threaded targets, GDB supports an optional mode of
4320
operation in which you can examine stopped program threads in the
4321
debugger while other threads continue to execute freely.  This
4322
minimizes intrusion when debugging live systems, such as programs where
4323
some threads have real-time constraints or must continue to respond to
4324
external events.  This is referred to as "non-stop" mode.
4325
 
4326
   In non-stop mode, when a thread stops to report a debugging event,
4327
_only_ that thread is stopped; GDB does not stop other threads as well,
4328
in contrast to the all-stop mode behavior.  Additionally, execution
4329
commands such as `continue' and `step' apply by default only to the
4330
current thread in non-stop mode, rather than all threads as in all-stop
4331
mode.  This allows you to control threads explicitly in ways that are
4332
not possible in all-stop mode -- for example, stepping one thread while
4333
allowing others to run freely, stepping one thread while holding all
4334
others stopped, or stepping several threads independently and
4335
simultaneously.
4336
 
4337
   To enter non-stop mode, use this sequence of commands before you run
4338
or attach to your program:
4339
 
4340
     # Enable the async interface.
4341
     set target-async 1
4342
 
4343
     # If using the CLI, pagination breaks non-stop.
4344
     set pagination off
4345
 
4346
     # Finally, turn it on!
4347
     set non-stop on
4348
 
4349
   You can use these commands to manipulate the non-stop mode setting:
4350
 
4351
`set non-stop on'
4352
     Enable selection of non-stop mode.
4353
 
4354
`set non-stop off'
4355
     Disable selection of non-stop mode.
4356
 
4357
`show non-stop'
4358
     Show the current non-stop enablement setting.
4359
 
4360
   Note these commands only reflect whether non-stop mode is enabled,
4361
not whether the currently-executing program is being run in non-stop
4362
mode.  In particular, the `set non-stop' preference is only consulted
4363
when GDB starts or connects to the target program, and it is generally
4364
not possible to switch modes once debugging has started.  Furthermore,
4365
since not all targets support non-stop mode, even when you have enabled
4366
non-stop mode, GDB may still fall back to all-stop operation by default.
4367
 
4368
   In non-stop mode, all execution commands apply only to the current
4369
thread by default.  That is, `continue' only continues one thread.  To
4370
continue all threads, issue `continue -a' or `c -a'.
4371
 
4372
   You can use GDB's background execution commands (*note Background
4373
Execution::) to run some threads in the background while you continue
4374
to examine or step others from GDB.  The MI execution commands (*note
4375
GDB/MI Program Execution::) are always executed asynchronously in
4376
non-stop mode.
4377
 
4378
   Suspending execution is done with the `interrupt' command when
4379
running in the background, or `Ctrl-c' during foreground execution.  In
4380
all-stop mode, this stops the whole process; but in non-stop mode the
4381
interrupt applies only to the current thread.  To stop the whole
4382
program, use `interrupt -a'.
4383
 
4384
   Other execution commands do not currently support the `-a' option.
4385
 
4386
   In non-stop mode, when a thread stops, GDB doesn't automatically make
4387
that thread current, as it does in all-stop mode.  This is because the
4388
thread stop notifications are asynchronous with respect to GDB's
4389
command interpreter, and it would be confusing if GDB unexpectedly
4390
changed to a different thread just as you entered a command to operate
4391
on the previously current thread.
4392
 
4393

4394
File: gdb.info,  Node: Background Execution,  Next: Thread-Specific Breakpoints,  Prev: Non-Stop Mode,  Up: Thread Stops
4395
 
4396
5.4.3 Background Execution
4397
--------------------------
4398
 
4399
GDB's execution commands have two variants:  the normal foreground
4400
(synchronous) behavior, and a background (asynchronous) behavior.  In
4401
foreground execution, GDB waits for the program to report that some
4402
thread has stopped before prompting for another command.  In background
4403
execution, GDB immediately gives a command prompt so that you can issue
4404
other commands while your program runs.
4405
 
4406
   You need to explicitly enable asynchronous mode before you can use
4407
background execution commands.  You can use these commands to
4408
manipulate the asynchronous mode setting:
4409
 
4410
`set target-async on'
4411
     Enable asynchronous mode.
4412
 
4413
`set target-async off'
4414
     Disable asynchronous mode.
4415
 
4416
`show target-async'
4417
     Show the current target-async setting.
4418
 
4419
   If the target doesn't support async mode, GDB issues an error
4420
message if you attempt to use the background execution commands.
4421
 
4422
   To specify background execution, add a `&' to the command.  For
4423
example, the background form of the `continue' command is `continue&',
4424
or just `c&'.  The execution commands that accept background execution
4425
are:
4426
 
4427
`run'
4428
     *Note Starting your Program: Starting.
4429
 
4430
`attach'
4431
     *Note Debugging an Already-running Process: Attach.
4432
 
4433
`step'
4434
     *Note step: Continuing and Stepping.
4435
 
4436
`stepi'
4437
     *Note stepi: Continuing and Stepping.
4438
 
4439
`next'
4440
     *Note next: Continuing and Stepping.
4441
 
4442
`nexti'
4443
     *Note nexti: Continuing and Stepping.
4444
 
4445
`continue'
4446
     *Note continue: Continuing and Stepping.
4447
 
4448
`finish'
4449
     *Note finish: Continuing and Stepping.
4450
 
4451
`until'
4452
     *Note until: Continuing and Stepping.
4453
 
4454
 
4455
   Background execution is especially useful in conjunction with
4456
non-stop mode for debugging programs with multiple threads; see *Note
4457
Non-Stop Mode::.  However, you can also use these commands in the
4458
normal all-stop mode with the restriction that you cannot issue another
4459
execution command until the previous one finishes.  Examples of
4460
commands that are valid in all-stop mode while the program is running
4461
include `help' and `info break'.
4462
 
4463
   You can interrupt your program while it is running in the background
4464
by using the `interrupt' command.
4465
 
4466
`interrupt'
4467
`interrupt -a'
4468
     Suspend execution of the running program.  In all-stop mode,
4469
     `interrupt' stops the whole process, but in non-stop mode, it stops
4470
     only the current thread.  To stop the whole program in non-stop
4471
     mode, use `interrupt -a'.
4472
 
4473

4474
File: gdb.info,  Node: Thread-Specific Breakpoints,  Next: Interrupted System Calls,  Prev: Background Execution,  Up: Thread Stops
4475
 
4476
5.4.4 Thread-Specific Breakpoints
4477
---------------------------------
4478
 
4479
When your program has multiple threads (*note Debugging Programs with
4480
Multiple Threads: Threads.), you can choose whether to set breakpoints
4481
on all threads, or on a particular thread.
4482
 
4483
`break LINESPEC thread THREADNO'
4484
`break LINESPEC thread THREADNO if ...'
4485
     LINESPEC specifies source lines; there are several ways of writing
4486
     them (*note Specify Location::), but the effect is always to
4487
     specify some source line.
4488
 
4489
     Use the qualifier `thread THREADNO' with a breakpoint command to
4490
     specify that you only want GDB to stop the program when a
4491
     particular thread reaches this breakpoint.  THREADNO is one of the
4492
     numeric thread identifiers assigned by GDB, shown in the first
4493
     column of the `info threads' display.
4494
 
4495
     If you do not specify `thread THREADNO' when you set a breakpoint,
4496
     the breakpoint applies to _all_ threads of your program.
4497
 
4498
     You can use the `thread' qualifier on conditional breakpoints as
4499
     well; in this case, place `thread THREADNO' before or after the
4500
     breakpoint condition, like this:
4501
 
4502
          (gdb) break frik.c:13 thread 28 if bartab > lim
4503
 
4504
 
4505

4506
File: gdb.info,  Node: Interrupted System Calls,  Next: Observer Mode,  Prev: Thread-Specific Breakpoints,  Up: Thread Stops
4507
 
4508
5.4.5 Interrupted System Calls
4509
------------------------------
4510
 
4511
There is an unfortunate side effect when using GDB to debug
4512
multi-threaded programs.  If one thread stops for a breakpoint, or for
4513
some other reason, and another thread is blocked in a system call, then
4514
the system call may return prematurely.  This is a consequence of the
4515
interaction between multiple threads and the signals that GDB uses to
4516
implement breakpoints and other events that stop execution.
4517
 
4518
   To handle this problem, your program should check the return value of
4519
each system call and react appropriately.  This is good programming
4520
style anyways.
4521
 
4522
   For example, do not write code like this:
4523
 
4524
       sleep (10);
4525
 
4526
   The call to `sleep' will return early if a different thread stops at
4527
a breakpoint or for some other reason.
4528
 
4529
   Instead, write this:
4530
 
4531
       int unslept = 10;
4532
       while (unslept > 0)
4533
         unslept = sleep (unslept);
4534
 
4535
   A system call is allowed to return early, so the system is still
4536
conforming to its specification.  But GDB does cause your
4537
multi-threaded program to behave differently than it would without GDB.
4538
 
4539
   Also, GDB uses internal breakpoints in the thread library to monitor
4540
certain events such as thread creation and thread destruction.  When
4541
such an event happens, a system call in another thread may return
4542
prematurely, even though your program does not appear to stop.
4543
 
4544

4545
File: gdb.info,  Node: Observer Mode,  Prev: Interrupted System Calls,  Up: Thread Stops
4546
 
4547
5.4.6 Observer Mode
4548
-------------------
4549
 
4550
If you want to build on non-stop mode and observe program behavior
4551
without any chance of disruption by GDB, you can set variables to
4552
disable all of the debugger's attempts to modify state, whether by
4553
writing memory, inserting breakpoints, etc.  These operate at a low
4554
level, intercepting operations from all commands.
4555
 
4556
   When all of these are set to `off', then GDB is said to be "observer
4557
mode".  As a convenience, the variable `observer' can be set to disable
4558
these, plus enable non-stop mode.
4559
 
4560
   Note that GDB will not prevent you from making nonsensical
4561
combinations of these settings. For instance, if you have enabled
4562
`may-insert-breakpoints' but disabled `may-write-memory', then
4563
breakpoints that work by writing trap instructions into the code stream
4564
will still not be able to be placed.
4565
 
4566
`set observer on'
4567
`set observer off'
4568
     When set to `on', this disables all the permission variables below
4569
     (except for `insert-fast-tracepoints'), plus enables non-stop
4570
     debugging.  Setting this to `off' switches back to normal
4571
     debugging, though remaining in non-stop mode.
4572
 
4573
`show observer'
4574
     Show whether observer mode is on or off.
4575
 
4576
`set may-write-registers on'
4577
`set may-write-registers off'
4578
     This controls whether GDB will attempt to alter the values of
4579
     registers, such as with assignment expressions in `print', or the
4580
     `jump' command.  It defaults to `on'.
4581
 
4582
`show may-write-registers'
4583
     Show the current permission to write registers.
4584
 
4585
`set may-write-memory on'
4586
`set may-write-memory off'
4587
     This controls whether GDB will attempt to alter the contents of
4588
     memory, such as with assignment expressions in `print'.  It
4589
     defaults to `on'.
4590
 
4591
`show may-write-memory'
4592
     Show the current permission to write memory.
4593
 
4594
`set may-insert-breakpoints on'
4595
`set may-insert-breakpoints off'
4596
     This controls whether GDB will attempt to insert breakpoints.
4597
     This affects all breakpoints, including internal breakpoints
4598
     defined by GDB.  It defaults to `on'.
4599
 
4600
`show may-insert-breakpoints'
4601
     Show the current permission to insert breakpoints.
4602
 
4603
`set may-insert-tracepoints on'
4604
`set may-insert-tracepoints off'
4605
     This controls whether GDB will attempt to insert (regular)
4606
     tracepoints at the beginning of a tracing experiment.  It affects
4607
     only non-fast tracepoints, fast tracepoints being under the
4608
     control of `may-insert-fast-tracepoints'.  It defaults to `on'.
4609
 
4610
`show may-insert-tracepoints'
4611
     Show the current permission to insert tracepoints.
4612
 
4613
`set may-insert-fast-tracepoints on'
4614
`set may-insert-fast-tracepoints off'
4615
     This controls whether GDB will attempt to insert fast tracepoints
4616
     at the beginning of a tracing experiment.  It affects only fast
4617
     tracepoints, regular (non-fast) tracepoints being under the
4618
     control of `may-insert-tracepoints'.  It defaults to `on'.
4619
 
4620
`show may-insert-fast-tracepoints'
4621
     Show the current permission to insert fast tracepoints.
4622
 
4623
`set may-interrupt on'
4624
`set may-interrupt off'
4625
     This controls whether GDB will attempt to interrupt or stop
4626
     program execution.  When this variable is `off', the `interrupt'
4627
     command will have no effect, nor will `Ctrl-c'. It defaults to
4628
     `on'.
4629
 
4630
`show may-interrupt'
4631
     Show the current permission to interrupt or stop the program.
4632
 
4633
 
4634

4635
File: gdb.info,  Node: Reverse Execution,  Next: Process Record and Replay,  Prev: Stopping,  Up: Top
4636
 
4637
6 Running programs backward
4638
***************************
4639
 
4640
When you are debugging a program, it is not unusual to realize that you
4641
have gone too far, and some event of interest has already happened.  If
4642
the target environment supports it, GDB can allow you to "rewind" the
4643
program by running it backward.
4644
 
4645
   A target environment that supports reverse execution should be able
4646
to "undo" the changes in machine state that have taken place as the
4647
program was executing normally.  Variables, registers etc. should
4648
revert to their previous values.  Obviously this requires a great deal
4649
of sophistication on the part of the target environment; not all target
4650
environments can support reverse execution.
4651
 
4652
   When a program is executed in reverse, the instructions that have
4653
most recently been executed are "un-executed", in reverse order.  The
4654
program counter runs backward, following the previous thread of
4655
execution in reverse.  As each instruction is "un-executed", the values
4656
of memory and/or registers that were changed by that instruction are
4657
reverted to their previous states.  After executing a piece of source
4658
code in reverse, all side effects of that code should be "undone", and
4659
all variables should be returned to their prior values(1).
4660
 
4661
   If you are debugging in a target environment that supports reverse
4662
execution, GDB provides the following commands.
4663
 
4664
`reverse-continue [IGNORE-COUNT]'
4665
`rc [IGNORE-COUNT]'
4666
     Beginning at the point where your program last stopped, start
4667
     executing in reverse.  Reverse execution will stop for breakpoints
4668
     and synchronous exceptions (signals), just like normal execution.
4669
     Behavior of asynchronous signals depends on the target environment.
4670
 
4671
`reverse-step [COUNT]'
4672
     Run the program backward until control reaches the start of a
4673
     different source line; then stop it, and return control to GDB.
4674
 
4675
     Like the `step' command, `reverse-step' will only stop at the
4676
     beginning of a source line.  It "un-executes" the previously
4677
     executed source line.  If the previous source line included calls
4678
     to debuggable functions, `reverse-step' will step (backward) into
4679
     the called function, stopping at the beginning of the _last_
4680
     statement in the called function (typically a return statement).
4681
 
4682
     Also, as with the `step' command, if non-debuggable functions are
4683
     called, `reverse-step' will run thru them backward without
4684
     stopping.
4685
 
4686
`reverse-stepi [COUNT]'
4687
     Reverse-execute one machine instruction.  Note that the instruction
4688
     to be reverse-executed is _not_ the one pointed to by the program
4689
     counter, but the instruction executed prior to that one.  For
4690
     instance, if the last instruction was a jump, `reverse-stepi' will
4691
     take you back from the destination of the jump to the jump
4692
     instruction itself.
4693
 
4694
`reverse-next [COUNT]'
4695
     Run backward to the beginning of the previous line executed in the
4696
     current (innermost) stack frame.  If the line contains function
4697
     calls, they will be "un-executed" without stopping.  Starting from
4698
     the first line of a function, `reverse-next' will take you back to
4699
     the caller of that function, _before_ the function was called,
4700
     just as the normal `next' command would take you from the last
4701
     line of a function back to its return to its caller (2).
4702
 
4703
`reverse-nexti [COUNT]'
4704
     Like `nexti', `reverse-nexti' executes a single instruction in
4705
     reverse, except that called functions are "un-executed" atomically.
4706
     That is, if the previously executed instruction was a return from
4707
     another function, `reverse-nexti' will continue to execute in
4708
     reverse until the call to that function (from the current stack
4709
     frame) is reached.
4710
 
4711
`reverse-finish'
4712
     Just as the `finish' command takes you to the point where the
4713
     current function returns, `reverse-finish' takes you to the point
4714
     where it was called.  Instead of ending up at the end of the
4715
     current function invocation, you end up at the beginning.
4716
 
4717
`set exec-direction'
4718
     Set the direction of target execution.
4719
 
4720
`set exec-direction reverse'
4721
     GDB will perform all execution commands in reverse, until the
4722
     exec-direction mode is changed to "forward".  Affected commands
4723
     include `step, stepi, next, nexti, continue, and finish'.  The
4724
     `return' command cannot be used in reverse mode.
4725
 
4726
`set exec-direction forward'
4727
     GDB will perform all execution commands in the normal fashion.
4728
     This is the default.
4729
 
4730
   ---------- Footnotes ----------
4731
 
4732
   (1) Note that some side effects are easier to undo than others.  For
4733
instance, memory and registers are relatively easy, but device I/O is
4734
hard.  Some targets may be able undo things like device I/O, and some
4735
may not.
4736
 
4737
   The contract between GDB and the reverse executing target requires
4738
only that the target do something reasonable when GDB tells it to
4739
execute backwards, and then report the results back to GDB.  Whatever
4740
the target reports back to GDB, GDB will report back to the user.  GDB
4741
assumes that the memory and registers that the target reports are in a
4742
consistant state, but GDB accepts whatever it is given.
4743
 
4744
   (2) Unless the code is too heavily optimized.
4745
 
4746

4747
File: gdb.info,  Node: Process Record and Replay,  Next: Stack,  Prev: Reverse Execution,  Up: Top
4748
 
4749
7 Recording Inferior's Execution and Replaying It
4750
*************************************************
4751
 
4752
On some platforms, GDB provides a special "process record and replay"
4753
target that can record a log of the process execution, and replay it
4754
later with both forward and reverse execution commands.
4755
 
4756
   When this target is in use, if the execution log includes the record
4757
for the next instruction, GDB will debug in "replay mode".  In the
4758
replay mode, the inferior does not really execute code instructions.
4759
Instead, all the events that normally happen during code execution are
4760
taken from the execution log.  While code is not really executed in
4761
replay mode, the values of registers (including the program counter
4762
register) and the memory of the inferior are still changed as they
4763
normally would.  Their contents are taken from the execution log.
4764
 
4765
   If the record for the next instruction is not in the execution log,
4766
GDB will debug in "record mode".  In this mode, the inferior executes
4767
normally, and GDB records the execution log for future replay.
4768
 
4769
   The process record and replay target supports reverse execution
4770
(*note Reverse Execution::), even if the platform on which the inferior
4771
runs does not.  However, the reverse execution is limited in this case
4772
by the range of the instructions recorded in the execution log.  In
4773
other words, reverse execution on platforms that don't support it
4774
directly can only be done in the replay mode.
4775
 
4776
   When debugging in the reverse direction, GDB will work in replay
4777
mode as long as the execution log includes the record for the previous
4778
instruction; otherwise, it will work in record mode, if the platform
4779
supports reverse execution, or stop if not.
4780
 
4781
   For architecture environments that support process record and replay,
4782
GDB provides the following commands:
4783
 
4784
`target record'
4785
     This command starts the process record and replay target.  The
4786
     process record and replay target can only debug a process that is
4787
     already running.  Therefore, you need first to start the process
4788
     with the `run' or `start' commands, and then start the recording
4789
     with the `target record' command.
4790
 
4791
     Both `record' and `rec' are aliases of `target record'.
4792
 
4793
     Displaced stepping (*note displaced stepping: Maintenance
4794
     Commands.)  will be automatically disabled when process record and
4795
     replay target is started.  That's because the process record and
4796
     replay target doesn't support displaced stepping.
4797
 
4798
     If the inferior is in the non-stop mode (*note Non-Stop Mode::) or
4799
     in the asynchronous execution mode (*note Background Execution::),
4800
     the process record and replay target cannot be started because it
4801
     doesn't support these two modes.
4802
 
4803
`record stop'
4804
     Stop the process record and replay target.  When process record and
4805
     replay target stops, the entire execution log will be deleted and
4806
     the inferior will either be terminated, or will remain in its
4807
     final state.
4808
 
4809
     When you stop the process record and replay target in record mode
4810
     (at the end of the execution log), the inferior will be stopped at
4811
     the next instruction that would have been recorded.  In other
4812
     words, if you record for a while and then stop recording, the
4813
     inferior process will be left in the same state as if the
4814
     recording never happened.
4815
 
4816
     On the other hand, if the process record and replay target is
4817
     stopped while in replay mode (that is, not at the end of the
4818
     execution log, but at some earlier point), the inferior process
4819
     will become "live" at that earlier state, and it will then be
4820
     possible to continue the usual "live" debugging of the process
4821
     from that state.
4822
 
4823
     When the inferior process exits, or GDB detaches from it, process
4824
     record and replay target will automatically stop itself.
4825
 
4826
`record save FILENAME'
4827
     Save the execution log to a file `FILENAME'.  Default filename is
4828
     `gdb_record.PROCESS_ID', where PROCESS_ID is the process ID of the
4829
     inferior.
4830
 
4831
`record restore FILENAME'
4832
     Restore the execution log from a file `FILENAME'.  File must have
4833
     been created with `record save'.
4834
 
4835
`set record insn-number-max LIMIT'
4836
     Set the limit of instructions to be recorded.  Default value is
4837
     200000.
4838
 
4839
     If LIMIT is a positive number, then GDB will start deleting
4840
     instructions from the log once the number of the record
4841
     instructions becomes greater than LIMIT.  For every new recorded
4842
     instruction, GDB will delete the earliest recorded instruction to
4843
     keep the number of recorded instructions at the limit.  (Since
4844
     deleting recorded instructions loses information, GDB lets you
4845
     control what happens when the limit is reached, by means of the
4846
     `stop-at-limit' option, described below.)
4847
 
4848
     If LIMIT is zero, GDB will never delete recorded instructions from
4849
     the execution log.  The number of recorded instructions is
4850
     unlimited in this case.
4851
 
4852
`show record insn-number-max'
4853
     Show the limit of instructions to be recorded.
4854
 
4855
`set record stop-at-limit'
4856
     Control the behavior when the number of recorded instructions
4857
     reaches the limit.  If ON (the default), GDB will stop when the
4858
     limit is reached for the first time and ask you whether you want
4859
     to stop the inferior or continue running it and recording the
4860
     execution log.  If you decide to continue recording, each new
4861
     recorded instruction will cause the oldest one to be deleted.
4862
 
4863
     If this option is OFF, GDB will automatically delete the oldest
4864
     record to make room for each new one, without asking.
4865
 
4866
`show record stop-at-limit'
4867
     Show the current setting of `stop-at-limit'.
4868
 
4869
`set record memory-query'
4870
     Control the behavior when GDB is unable to record memory changes
4871
     caused by an instruction.  If ON, GDB will query whether to stop
4872
     the inferior in that case.
4873
 
4874
     If this option is OFF (the default), GDB will automatically ignore
4875
     the effect of such instructions on memory.  Later, when GDB
4876
     replays this execution log, it will mark the log of this
4877
     instruction as not accessible, and it will not affect the replay
4878
     results.
4879
 
4880
`show record memory-query'
4881
     Show the current setting of `memory-query'.
4882
 
4883
`info record'
4884
     Show various statistics about the state of process record and its
4885
     in-memory execution log buffer, including:
4886
 
4887
        * Whether in record mode or replay mode.
4888
 
4889
        * Lowest recorded instruction number (counting from when the
4890
          current execution log started recording instructions).
4891
 
4892
        * Highest recorded instruction number.
4893
 
4894
        * Current instruction about to be replayed (if in replay mode).
4895
 
4896
        * Number of instructions contained in the execution log.
4897
 
4898
        * Maximum number of instructions that may be contained in the
4899
          execution log.
4900
 
4901
`record delete'
4902
     When record target runs in replay mode ("in the past"), delete the
4903
     subsequent execution log and begin to record a new execution log
4904
     starting from the current address.  This means you will abandon
4905
     the previously recorded "future" and begin recording a new
4906
     "future".
4907
 
4908

4909
File: gdb.info,  Node: Stack,  Next: Source,  Prev: Process Record and Replay,  Up: Top
4910
 
4911
8 Examining the Stack
4912
*********************
4913
 
4914
When your program has stopped, the first thing you need to know is
4915
where it stopped and how it got there.
4916
 
4917
   Each time your program performs a function call, information about
4918
the call is generated.  That information includes the location of the
4919
call in your program, the arguments of the call, and the local
4920
variables of the function being called.  The information is saved in a
4921
block of data called a "stack frame".  The stack frames are allocated
4922
in a region of memory called the "call stack".
4923
 
4924
   When your program stops, the GDB commands for examining the stack
4925
allow you to see all of this information.
4926
 
4927
   One of the stack frames is "selected" by GDB and many GDB commands
4928
refer implicitly to the selected frame.  In particular, whenever you
4929
ask GDB for the value of a variable in your program, the value is found
4930
in the selected frame.  There are special GDB commands to select
4931
whichever frame you are interested in.  *Note Selecting a Frame:
4932
Selection.
4933
 
4934
   When your program stops, GDB automatically selects the currently
4935
executing frame and describes it briefly, similar to the `frame'
4936
command (*note Information about a Frame: Frame Info.).
4937
 
4938
* Menu:
4939
 
4940
* Frames::                      Stack frames
4941
* Backtrace::                   Backtraces
4942
* Selection::                   Selecting a frame
4943
* Frame Info::                  Information on a frame
4944
 
4945

4946
File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
4947
 
4948
8.1 Stack Frames
4949
================
4950
 
4951
The call stack is divided up into contiguous pieces called "stack
4952
frames", or "frames" for short; each frame is the data associated with
4953
one call to one function.  The frame contains the arguments given to
4954
the function, the function's local variables, and the address at which
4955
the function is executing.
4956
 
4957
   When your program is started, the stack has only one frame, that of
4958
the function `main'.  This is called the "initial" frame or the
4959
"outermost" frame.  Each time a function is called, a new frame is
4960
made.  Each time a function returns, the frame for that function
4961
invocation is eliminated.  If a function is recursive, there can be
4962
many frames for the same function.  The frame for the function in which
4963
execution is actually occurring is called the "innermost" frame.  This
4964
is the most recently created of all the stack frames that still exist.
4965
 
4966
   Inside your program, stack frames are identified by their addresses.
4967
A stack frame consists of many bytes, each of which has its own
4968
address; each kind of computer has a convention for choosing one byte
4969
whose address serves as the address of the frame.  Usually this address
4970
is kept in a register called the "frame pointer register" (*note $fp:
4971
Registers.) while execution is going on in that frame.
4972
 
4973
   GDB assigns numbers to all existing stack frames, starting with zero
4974
for the innermost frame, one for the frame that called it, and so on
4975
upward.  These numbers do not really exist in your program; they are
4976
assigned by GDB to give you a way of designating stack frames in GDB
4977
commands.
4978
 
4979
   Some compilers provide a way to compile functions so that they
4980
operate without stack frames.  (For example, the GCC option
4981
     `-fomit-frame-pointer'
4982
   generates functions without a frame.)  This is occasionally done
4983
with heavily used library functions to save the frame setup time.  GDB
4984
has limited facilities for dealing with these function invocations.  If
4985
the innermost function invocation has no stack frame, GDB nevertheless
4986
regards it as though it had a separate frame, which is numbered zero as
4987
usual, allowing correct tracing of the function call chain.  However,
4988
GDB has no provision for frameless functions elsewhere in the stack.
4989
 
4990
`frame ARGS'
4991
     The `frame' command allows you to move from one stack frame to
4992
     another, and to print the stack frame you select.  ARGS may be
4993
     either the address of the frame or the stack frame number.
4994
     Without an argument, `frame' prints the current stack frame.
4995
 
4996
`select-frame'
4997
     The `select-frame' command allows you to move from one stack frame
4998
     to another without printing the frame.  This is the silent version
4999
     of `frame'.
5000
 
5001

5002
File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
5003
 
5004
8.2 Backtraces
5005
==============
5006
 
5007
A backtrace is a summary of how your program got where it is.  It shows
5008
one line per frame, for many frames, starting with the currently
5009
executing frame (frame zero), followed by its caller (frame one), and
5010
on up the stack.
5011
 
5012
`backtrace'
5013
`bt'
5014
     Print a backtrace of the entire stack: one line per frame for all
5015
     frames in the stack.
5016
 
5017
     You can stop the backtrace at any time by typing the system
5018
     interrupt character, normally `Ctrl-c'.
5019
 
5020
`backtrace N'
5021
`bt N'
5022
     Similar, but print only the innermost N frames.
5023
 
5024
`backtrace -N'
5025
`bt -N'
5026
     Similar, but print only the outermost N frames.
5027
 
5028
`backtrace full'
5029
`bt full'
5030
`bt full N'
5031
`bt full -N'
5032
     Print the values of the local variables also.  N specifies the
5033
     number of frames to print, as described above.
5034
 
5035
   The names `where' and `info stack' (abbreviated `info s') are
5036
additional aliases for `backtrace'.
5037
 
5038
   In a multi-threaded program, GDB by default shows the backtrace only
5039
for the current thread.  To display the backtrace for several or all of
5040
the threads, use the command `thread apply' (*note thread apply:
5041
Threads.).  For example, if you type `thread apply all backtrace', GDB
5042
will display the backtrace for all the threads; this is handy when you
5043
debug a core dump of a multi-threaded program.
5044
 
5045
   Each line in the backtrace shows the frame number and the function
5046
name.  The program counter value is also shown--unless you use `set
5047
print address off'.  The backtrace also shows the source file name and
5048
line number, as well as the arguments to the function.  The program
5049
counter value is omitted if it is at the beginning of the code for that
5050
line number.
5051
 
5052
   Here is an example of a backtrace.  It was made with the command `bt
5053
3', so it shows the innermost three frames.
5054
 
5055
     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5056
         at builtin.c:993
5057
     #1  0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
5058
     #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
5059
         at macro.c:71
5060
     (More stack frames follow...)
5061
 
5062
The display for frame zero does not begin with a program counter value,
5063
indicating that your program has stopped at the beginning of the code
5064
for line `993' of `builtin.c'.
5065
 
5066
The value of parameter `data' in frame 1 has been replaced by `...'.
5067
By default, GDB prints the value of a parameter only if it is a scalar
5068
(integer, pointer, enumeration, etc).  See command `set print
5069
frame-arguments' in *Note Print Settings:: for more details on how to
5070
configure the way function parameter values are printed.
5071
 
5072
   If your program was compiled with optimizations, some compilers will
5073
optimize away arguments passed to functions if those arguments are
5074
never used after the call.  Such optimizations generate code that
5075
passes arguments through registers, but doesn't store those arguments
5076
in the stack frame.  GDB has no way of displaying such arguments in
5077
stack frames other than the innermost one.  Here's what such a
5078
backtrace might look like:
5079
 
5080
     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5081
         at builtin.c:993
5082
     #1  0x6e38 in expand_macro (sym=) at macro.c:242
5083
     #2  0x6840 in expand_token (obs=0x0, t=, td=0xf7fffb08)
5084
         at macro.c:71
5085
     (More stack frames follow...)
5086
 
5087
The values of arguments that were not saved in their stack frames are
5088
shown as `'.
5089
 
5090
   If you need to display the values of such optimized-out arguments,
5091
either deduce that from other variables whose values depend on the one
5092
you are interested in, or recompile without optimizations.
5093
 
5094
   Most programs have a standard user entry point--a place where system
5095
libraries and startup code transition into user code.  For C this is
5096
`main'(1).  When GDB finds the entry function in a backtrace it will
5097
terminate the backtrace, to avoid tracing into highly system-specific
5098
(and generally uninteresting) code.
5099
 
5100
   If you need to examine the startup code, or limit the number of
5101
levels in a backtrace, you can change this behavior:
5102
 
5103
`set backtrace past-main'
5104
`set backtrace past-main on'
5105
     Backtraces will continue past the user entry point.
5106
 
5107
`set backtrace past-main off'
5108
     Backtraces will stop when they encounter the user entry point.
5109
     This is the default.
5110
 
5111
`show backtrace past-main'
5112
     Display the current user entry point backtrace policy.
5113
 
5114
`set backtrace past-entry'
5115
`set backtrace past-entry on'
5116
     Backtraces will continue past the internal entry point of an
5117
     application.  This entry point is encoded by the linker when the
5118
     application is built, and is likely before the user entry point
5119
     `main' (or equivalent) is called.
5120
 
5121
`set backtrace past-entry off'
5122
     Backtraces will stop when they encounter the internal entry point
5123
     of an application.  This is the default.
5124
 
5125
`show backtrace past-entry'
5126
     Display the current internal entry point backtrace policy.
5127
 
5128
`set backtrace limit N'
5129
`set backtrace limit 0'
5130
     Limit the backtrace to N levels.  A value of zero means unlimited.
5131
 
5132
`show backtrace limit'
5133
     Display the current limit on backtrace levels.
5134
 
5135
   ---------- Footnotes ----------
5136
 
5137
   (1) Note that embedded programs (the so-called "free-standing"
5138
environment) are not required to have a `main' function as the entry
5139
point.  They could even have multiple entry points.
5140
 
5141

5142
File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
5143
 
5144
8.3 Selecting a Frame
5145
=====================
5146
 
5147
Most commands for examining the stack and other data in your program
5148
work on whichever stack frame is selected at the moment.  Here are the
5149
commands for selecting a stack frame; all of them finish by printing a
5150
brief description of the stack frame just selected.
5151
 
5152
`frame N'
5153
`f N'
5154
     Select frame number N.  Recall that frame zero is the innermost
5155
     (currently executing) frame, frame one is the frame that called the
5156
     innermost one, and so on.  The highest-numbered frame is the one
5157
     for `main'.
5158
 
5159
`frame ADDR'
5160
`f ADDR'
5161
     Select the frame at address ADDR.  This is useful mainly if the
5162
     chaining of stack frames has been damaged by a bug, making it
5163
     impossible for GDB to assign numbers properly to all frames.  In
5164
     addition, this can be useful when your program has multiple stacks
5165
     and switches between them.
5166
 
5167
     On the SPARC architecture, `frame' needs two addresses to select
5168
     an arbitrary frame: a frame pointer and a stack pointer.
5169
 
5170
     On the MIPS and Alpha architecture, it needs two addresses: a stack
5171
     pointer and a program counter.
5172
 
5173
     On the 29k architecture, it needs three addresses: a register stack
5174
     pointer, a program counter, and a memory stack pointer.
5175
 
5176
`up N'
5177
     Move N frames up the stack.  For positive numbers N, this advances
5178
     toward the outermost frame, to higher frame numbers, to frames
5179
     that have existed longer.  N defaults to one.
5180
 
5181
`down N'
5182
     Move N frames down the stack.  For positive numbers N, this
5183
     advances toward the innermost frame, to lower frame numbers, to
5184
     frames that were created more recently.  N defaults to one.  You
5185
     may abbreviate `down' as `do'.
5186
 
5187
   All of these commands end by printing two lines of output describing
5188
the frame.  The first line shows the frame number, the function name,
5189
the arguments, and the source file and line number of execution in that
5190
frame.  The second line shows the text of that source line.
5191
 
5192
   For example:
5193
 
5194
     (gdb) up
5195
     #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
5196
         at env.c:10
5197
     10              read_input_file (argv[i]);
5198
 
5199
   After such a printout, the `list' command with no arguments prints
5200
ten lines centered on the point of execution in the frame.  You can
5201
also edit the program at the point of execution with your favorite
5202
editing program by typing `edit'.  *Note Printing Source Lines: List,
5203
for details.
5204
 
5205
`up-silently N'
5206
`down-silently N'
5207
     These two commands are variants of `up' and `down', respectively;
5208
     they differ in that they do their work silently, without causing
5209
     display of the new frame.  They are intended primarily for use in
5210
     GDB command scripts, where the output might be unnecessary and
5211
     distracting.
5212
 
5213

5214
File: gdb.info,  Node: Frame Info,  Prev: Selection,  Up: Stack
5215
 
5216
8.4 Information About a Frame
5217
=============================
5218
 
5219
There are several other commands to print information about the selected
5220
stack frame.
5221
 
5222
`frame'
5223
`f'
5224
     When used without any argument, this command does not change which
5225
     frame is selected, but prints a brief description of the currently
5226
     selected stack frame.  It can be abbreviated `f'.  With an
5227
     argument, this command is used to select a stack frame.  *Note
5228
     Selecting a Frame: Selection.
5229
 
5230
`info frame'
5231
`info f'
5232
     This command prints a verbose description of the selected stack
5233
     frame, including:
5234
 
5235
        * the address of the frame
5236
 
5237
        * the address of the next frame down (called by this frame)
5238
 
5239
        * the address of the next frame up (caller of this frame)
5240
 
5241
        * the language in which the source code corresponding to this
5242
          frame is written
5243
 
5244
        * the address of the frame's arguments
5245
 
5246
        * the address of the frame's local variables
5247
 
5248
        * the program counter saved in it (the address of execution in
5249
          the caller frame)
5250
 
5251
        * which registers were saved in the frame
5252
 
5253
     The verbose description is useful when something has gone wrong
5254
     that has made the stack format fail to fit the usual conventions.
5255
 
5256
`info frame ADDR'
5257
`info f ADDR'
5258
     Print a verbose description of the frame at address ADDR, without
5259
     selecting that frame.  The selected frame remains unchanged by this
5260
     command.  This requires the same kind of address (more than one
5261
     for some architectures) that you specify in the `frame' command.
5262
     *Note Selecting a Frame: Selection.
5263
 
5264
`info args'
5265
     Print the arguments of the selected frame, each on a separate line.
5266
 
5267
`info locals'
5268
     Print the local variables of the selected frame, each on a separate
5269
     line.  These are all variables (declared either static or
5270
     automatic) accessible at the point of execution of the selected
5271
     frame.
5272
 
5273
`info catch'
5274
     Print a list of all the exception handlers that are active in the
5275
     current stack frame at the current point of execution.  To see
5276
     other exception handlers, visit the associated frame (using the
5277
     `up', `down', or `frame' commands); then type `info catch'.  *Note
5278
     Setting Catchpoints: Set Catchpoints.
5279
 
5280
 
5281

5282
File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
5283
 
5284
9 Examining Source Files
5285
************************
5286
 
5287
GDB can print parts of your program's source, since the debugging
5288
information recorded in the program tells GDB what source files were
5289
used to build it.  When your program stops, GDB spontaneously prints
5290
the line where it stopped.  Likewise, when you select a stack frame
5291
(*note Selecting a Frame: Selection.), GDB prints the line where
5292
execution in that frame has stopped.  You can print other portions of
5293
source files by explicit command.
5294
 
5295
   If you use GDB through its GNU Emacs interface, you may prefer to
5296
use Emacs facilities to view source; see *Note Using GDB under GNU
5297
Emacs: Emacs.
5298
 
5299
* Menu:
5300
 
5301
* List::                        Printing source lines
5302
* Specify Location::            How to specify code locations
5303
* Edit::                        Editing source files
5304
* Search::                      Searching source files
5305
* Source Path::                 Specifying source directories
5306
* Machine Code::                Source and machine code
5307
 
5308

5309
File: gdb.info,  Node: List,  Next: Specify Location,  Up: Source
5310
 
5311
9.1 Printing Source Lines
5312
=========================
5313
 
5314
To print lines from a source file, use the `list' command (abbreviated
5315
`l').  By default, ten lines are printed.  There are several ways to
5316
specify what part of the file you want to print; see *Note Specify
5317
Location::, for the full list.
5318
 
5319
   Here are the forms of the `list' command most commonly used:
5320
 
5321
`list LINENUM'
5322
     Print lines centered around line number LINENUM in the current
5323
     source file.
5324
 
5325
`list FUNCTION'
5326
     Print lines centered around the beginning of function FUNCTION.
5327
 
5328
`list'
5329
     Print more lines.  If the last lines printed were printed with a
5330
     `list' command, this prints lines following the last lines
5331
     printed; however, if the last line printed was a solitary line
5332
     printed as part of displaying a stack frame (*note Examining the
5333
     Stack: Stack.), this prints lines centered around that line.
5334
 
5335
`list -'
5336
     Print lines just before the lines last printed.
5337
 
5338
   By default, GDB prints ten source lines with any of these forms of
5339
the `list' command.  You can change this using `set listsize':
5340
 
5341
`set listsize COUNT'
5342
     Make the `list' command display COUNT source lines (unless the
5343
     `list' argument explicitly specifies some other number).
5344
 
5345
`show listsize'
5346
     Display the number of lines that `list' prints.
5347
 
5348
   Repeating a `list' command with  discards the argument, so it
5349
is equivalent to typing just `list'.  This is more useful than listing
5350
the same lines again.  An exception is made for an argument of `-';
5351
that argument is preserved in repetition so that each repetition moves
5352
up in the source file.
5353
 
5354
   In general, the `list' command expects you to supply zero, one or two
5355
"linespecs".  Linespecs specify source lines; there are several ways of
5356
writing them (*note Specify Location::), but the effect is always to
5357
specify some source line.
5358
 
5359
   Here is a complete description of the possible arguments for `list':
5360
 
5361
`list LINESPEC'
5362
     Print lines centered around the line specified by LINESPEC.
5363
 
5364
`list FIRST,LAST'
5365
     Print lines from FIRST to LAST.  Both arguments are linespecs.
5366
     When a `list' command has two linespecs, and the source file of
5367
     the second linespec is omitted, this refers to the same source
5368
     file as the first linespec.
5369
 
5370
`list ,LAST'
5371
     Print lines ending with LAST.
5372
 
5373
`list FIRST,'
5374
     Print lines starting with FIRST.
5375
 
5376
`list +'
5377
     Print lines just after the lines last printed.
5378
 
5379
`list -'
5380
     Print lines just before the lines last printed.
5381
 
5382
`list'
5383
     As described in the preceding table.
5384
 
5385

5386
File: gdb.info,  Node: Specify Location,  Next: Edit,  Prev: List,  Up: Source
5387
 
5388
9.2 Specifying a Location
5389
=========================
5390
 
5391
Several GDB commands accept arguments that specify a location of your
5392
program's code.  Since GDB is a source-level debugger, a location
5393
usually specifies some line in the source code; for that reason,
5394
locations are also known as "linespecs".
5395
 
5396
   Here are all the different ways of specifying a code location that
5397
GDB understands:
5398
 
5399
`LINENUM'
5400
     Specifies the line number LINENUM of the current source file.
5401
 
5402
`-OFFSET'
5403
`+OFFSET'
5404
     Specifies the line OFFSET lines before or after the "current
5405
     line".  For the `list' command, the current line is the last one
5406
     printed; for the breakpoint commands, this is the line at which
5407
     execution stopped in the currently selected "stack frame" (*note
5408
     Frames: Frames, for a description of stack frames.)  When used as
5409
     the second of the two linespecs in a `list' command, this
5410
     specifies the line OFFSET lines up or down from the first linespec.
5411
 
5412
`FILENAME:LINENUM'
5413
     Specifies the line LINENUM in the source file FILENAME.
5414
 
5415
`FUNCTION'
5416
     Specifies the line that begins the body of the function FUNCTION.
5417
     For example, in C, this is the line with the open brace.
5418
 
5419
`FILENAME:FUNCTION'
5420
     Specifies the line that begins the body of the function FUNCTION
5421
     in the file FILENAME.  You only need the file name with a function
5422
     name to avoid ambiguity when there are identically named functions
5423
     in different source files.
5424
 
5425
`*ADDRESS'
5426
     Specifies the program address ADDRESS.  For line-oriented
5427
     commands, such as `list' and `edit', this specifies a source line
5428
     that contains ADDRESS.  For `break' and other breakpoint oriented
5429
     commands, this can be used to set breakpoints in parts of your
5430
     program which do not have debugging information or source files.
5431
 
5432
     Here ADDRESS may be any expression valid in the current working
5433
     language (*note working language: Languages.) that specifies a code
5434
     address.  In addition, as a convenience, GDB extends the semantics
5435
     of expressions used in locations to cover the situations that
5436
     frequently happen during debugging.  Here are the various forms of
5437
     ADDRESS:
5438
 
5439
    `EXPRESSION'
5440
          Any expression valid in the current working language.
5441
 
5442
    `FUNCADDR'
5443
          An address of a function or procedure derived from its name.
5444
          In C, C++, Java, Objective-C, Fortran, minimal, and assembly,
5445
          this is simply the function's name FUNCTION (and actually a
5446
          special case of a valid expression).  In Pascal and Modula-2,
5447
          this is `&FUNCTION'.  In Ada, this is `FUNCTION'Address'
5448
          (although the Pascal form also works).
5449
 
5450
          This form specifies the address of the function's first
5451
          instruction, before the stack frame and arguments have been
5452
          set up.
5453
 
5454
    `'FILENAME'::FUNCADDR'
5455
          Like FUNCADDR above, but also specifies the name of the source
5456
          file explicitly.  This is useful if the name of the function
5457
          does not specify the function unambiguously, e.g., if there
5458
          are several functions with identical names in different
5459
          source files.
5460
 
5461
 
5462

5463
File: gdb.info,  Node: Edit,  Next: Search,  Prev: Specify Location,  Up: Source
5464
 
5465
9.3 Editing Source Files
5466
========================
5467
 
5468
To edit the lines in a source file, use the `edit' command.  The
5469
editing program of your choice is invoked with the current line set to
5470
the active line in the program.  Alternatively, there are several ways
5471
to specify what part of the file you want to print if you want to see
5472
other parts of the program:
5473
 
5474
`edit LOCATION'
5475
     Edit the source file specified by `location'.  Editing starts at
5476
     that LOCATION, e.g., at the specified source line of the specified
5477
     file.  *Note Specify Location::, for all the possible forms of the
5478
     LOCATION argument; here are the forms of the `edit' command most
5479
     commonly used:
5480
 
5481
    `edit NUMBER'
5482
          Edit the current source file with NUMBER as the active line
5483
          number.
5484
 
5485
    `edit FUNCTION'
5486
          Edit the file containing FUNCTION at the beginning of its
5487
          definition.
5488
 
5489
 
5490
9.3.1 Choosing your Editor
5491
--------------------------
5492
 
5493
You can customize GDB to use any editor you want (1).  By default, it
5494
is `/bin/ex', but you can change this by setting the environment
5495
variable `EDITOR' before using GDB.  For example, to configure GDB to
5496
use the `vi' editor, you could use these commands with the `sh' shell:
5497
     EDITOR=/usr/bin/vi
5498
     export EDITOR
5499
     gdb ...
5500
   or in the `csh' shell,
5501
     setenv EDITOR /usr/bin/vi
5502
     gdb ...
5503
 
5504
   ---------- Footnotes ----------
5505
 
5506
   (1) The only restriction is that your editor (say `ex'), recognizes
5507
the following command-line syntax:
5508
     ex +NUMBER file
5509
   The optional numeric value +NUMBER specifies the number of the line
5510
in the file where to start editing.
5511
 
5512

5513
File: gdb.info,  Node: Search,  Next: Source Path,  Prev: Edit,  Up: Source
5514
 
5515
9.4 Searching Source Files
5516
==========================
5517
 
5518
There are two commands for searching through the current source file
5519
for a regular expression.
5520
 
5521
`forward-search REGEXP'
5522
`search REGEXP'
5523
     The command `forward-search REGEXP' checks each line, starting
5524
     with the one following the last line listed, for a match for
5525
     REGEXP.  It lists the line that is found.  You can use the synonym
5526
     `search REGEXP' or abbreviate the command name as `fo'.
5527
 
5528
`reverse-search REGEXP'
5529
     The command `reverse-search REGEXP' checks each line, starting
5530
     with the one before the last line listed and going backward, for a
5531
     match for REGEXP.  It lists the line that is found.  You can
5532
     abbreviate this command as `rev'.
5533
 
5534

5535
File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
5536
 
5537
9.5 Specifying Source Directories
5538
=================================
5539
 
5540
Executable programs sometimes do not record the directories of the
5541
source files from which they were compiled, just the names.  Even when
5542
they do, the directories could be moved between the compilation and
5543
your debugging session.  GDB has a list of directories to search for
5544
source files; this is called the "source path".  Each time GDB wants a
5545
source file, it tries all the directories in the list, in the order
5546
they are present in the list, until it finds a file with the desired
5547
name.
5548
 
5549
   For example, suppose an executable references the file
5550
`/usr/src/foo-1.0/lib/foo.c', and our source path is `/mnt/cross'.  The
5551
file is first looked up literally; if this fails,
5552
`/mnt/cross/usr/src/foo-1.0/lib/foo.c' is tried; if this fails,
5553
`/mnt/cross/foo.c' is opened; if this fails, an error message is
5554
printed.  GDB does not look up the parts of the source file name, such
5555
as `/mnt/cross/src/foo-1.0/lib/foo.c'.  Likewise, the subdirectories of
5556
the source path are not searched: if the source path is `/mnt/cross',
5557
and the binary refers to `foo.c', GDB would not find it under
5558
`/mnt/cross/usr/src/foo-1.0/lib'.
5559
 
5560
   Plain file names, relative file names with leading directories, file
5561
names containing dots, etc. are all treated as described above; for
5562
instance, if the source path is `/mnt/cross', and the source file is
5563
recorded as `../lib/foo.c', GDB would first try `../lib/foo.c', then
5564
`/mnt/cross/../lib/foo.c', and after that--`/mnt/cross/foo.c'.
5565
 
5566
   Note that the executable search path is _not_ used to locate the
5567
source files.
5568
 
5569
   Whenever you reset or rearrange the source path, GDB clears out any
5570
information it has cached about where source files are found and where
5571
each line is in the file.
5572
 
5573
   When you start GDB, its source path includes only `cdir' and `cwd',
5574
in that order.  To add other directories, use the `directory' command.
5575
 
5576
   The search path is used to find both program source files and GDB
5577
script files (read using the `-command' option and `source' command).
5578
 
5579
   In addition to the source path, GDB provides a set of commands that
5580
manage a list of source path substitution rules.  A "substitution rule"
5581
specifies how to rewrite source directories stored in the program's
5582
debug information in case the sources were moved to a different
5583
directory between compilation and debugging.  A rule is made of two
5584
strings, the first specifying what needs to be rewritten in the path,
5585
and the second specifying how it should be rewritten.  In *Note set
5586
substitute-path::, we name these two parts FROM and TO respectively.
5587
GDB does a simple string replacement of FROM with TO at the start of
5588
the directory part of the source file name, and uses that result
5589
instead of the original file name to look up the sources.
5590
 
5591
   Using the previous example, suppose the `foo-1.0' tree has been
5592
moved from `/usr/src' to `/mnt/cross', then you can tell GDB to replace
5593
`/usr/src' in all source path names with `/mnt/cross'.  The first
5594
lookup will then be `/mnt/cross/foo-1.0/lib/foo.c' in place of the
5595
original location of `/usr/src/foo-1.0/lib/foo.c'.  To define a source
5596
path substitution rule, use the `set substitute-path' command (*note
5597
set substitute-path::).
5598
 
5599
   To avoid unexpected substitution results, a rule is applied only if
5600
the FROM part of the directory name ends at a directory separator.  For
5601
instance, a rule substituting  `/usr/source' into `/mnt/cross' will be
5602
applied to `/usr/source/foo-1.0' but not to `/usr/sourceware/foo-2.0'.
5603
And because the substitution is applied only at the beginning of the
5604
directory name, this rule will not be applied to
5605
`/root/usr/source/baz.c' either.
5606
 
5607
   In many cases, you can achieve the same result using the `directory'
5608
command.  However, `set substitute-path' can be more efficient in the
5609
case where the sources are organized in a complex tree with multiple
5610
subdirectories.  With the `directory' command, you need to add each
5611
subdirectory of your project.  If you moved the entire tree while
5612
preserving its internal organization, then `set substitute-path' allows
5613
you to direct the debugger to all the sources with one single command.
5614
 
5615
   `set substitute-path' is also more than just a shortcut command.
5616
The source path is only used if the file at the original location no
5617
longer exists.  On the other hand, `set substitute-path' modifies the
5618
debugger behavior to look at the rewritten location instead.  So, if
5619
for any reason a source file that is not relevant to your executable is
5620
located at the original location, a substitution rule is the only
5621
method available to point GDB at the new location.
5622
 
5623
   You can configure a default source path substitution rule by
5624
configuring GDB with the `--with-relocated-sources=DIR' option.  The DIR
5625
should be the name of a directory under GDB's configured prefix (set
5626
with `--prefix' or `--exec-prefix'), and directory names in debug
5627
information under DIR will be adjusted automatically if the installed
5628
GDB is moved to a new location.  This is useful if GDB, libraries or
5629
executables with debug information and corresponding source code are
5630
being moved together.
5631
 
5632
`directory DIRNAME ...'
5633
 
5634
`dir DIRNAME ...'
5635
     Add directory DIRNAME to the front of the source path.  Several
5636
     directory names may be given to this command, separated by `:'
5637
     (`;' on MS-DOS and MS-Windows, where `:' usually appears as part
5638
     of absolute file names) or whitespace.  You may specify a
5639
     directory that is already in the source path; this moves it
5640
     forward, so GDB searches it sooner.
5641
 
5642
     You can use the string `$cdir' to refer to the compilation
5643
     directory (if one is recorded), and `$cwd' to refer to the current
5644
     working directory.  `$cwd' is not the same as `.'--the former
5645
     tracks the current working directory as it changes during your GDB
5646
     session, while the latter is immediately expanded to the current
5647
     directory at the time you add an entry to the source path.
5648
 
5649
`directory'
5650
     Reset the source path to its default value (`$cdir:$cwd' on Unix
5651
     systems).  This requires confirmation.
5652
 
5653
`show directories'
5654
     Print the source path: show which directories it contains.
5655
 
5656
`set substitute-path FROM TO'
5657
     Define a source path substitution rule, and add it at the end of
5658
     the current list of existing substitution rules.  If a rule with
5659
     the same FROM was already defined, then the old rule is also
5660
     deleted.
5661
 
5662
     For example, if the file `/foo/bar/baz.c' was moved to
5663
     `/mnt/cross/baz.c', then the command
5664
 
5665
          (gdb) set substitute-path /usr/src /mnt/cross
5666
 
5667
     will tell GDB to replace `/usr/src' with `/mnt/cross', which will
5668
     allow GDB to find the file `baz.c' even though it was moved.
5669
 
5670
     In the case when more than one substitution rule have been defined,
5671
     the rules are evaluated one by one in the order where they have
5672
     been defined.  The first one matching, if any, is selected to
5673
     perform the substitution.
5674
 
5675
     For instance, if we had entered the following commands:
5676
 
5677
          (gdb) set substitute-path /usr/src/include /mnt/include
5678
          (gdb) set substitute-path /usr/src /mnt/src
5679
 
5680
     GDB would then rewrite `/usr/src/include/defs.h' into
5681
     `/mnt/include/defs.h' by using the first rule.  However, it would
5682
     use the second rule to rewrite `/usr/src/lib/foo.c' into
5683
     `/mnt/src/lib/foo.c'.
5684
 
5685
`unset substitute-path [path]'
5686
     If a path is specified, search the current list of substitution
5687
     rules for a rule that would rewrite that path.  Delete that rule
5688
     if found.  A warning is emitted by the debugger if no rule could
5689
     be found.
5690
 
5691
     If no path is specified, then all substitution rules are deleted.
5692
 
5693
`show substitute-path [path]'
5694
     If a path is specified, then print the source path substitution
5695
     rule which would rewrite that path, if any.
5696
 
5697
     If no path is specified, then print all existing source path
5698
     substitution rules.
5699
 
5700
 
5701
   If your source path is cluttered with directories that are no longer
5702
of interest, GDB may sometimes cause confusion by finding the wrong
5703
versions of source.  You can correct the situation as follows:
5704
 
5705
  1. Use `directory' with no argument to reset the source path to its
5706
     default value.
5707
 
5708
  2. Use `directory' with suitable arguments to reinstall the
5709
     directories you want in the source path.  You can add all the
5710
     directories in one command.
5711
 
5712

5713
File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
5714
 
5715
9.6 Source and Machine Code
5716
===========================
5717
 
5718
You can use the command `info line' to map source lines to program
5719
addresses (and vice versa), and the command `disassemble' to display a
5720
range of addresses as machine instructions.  You can use the command
5721
`set disassemble-next-line' to set whether to disassemble next source
5722
line when execution stops.  When run under GNU Emacs mode, the `info
5723
line' command causes the arrow to point to the line specified.  Also,
5724
`info line' prints addresses in symbolic form as well as hex.
5725
 
5726
`info line LINESPEC'
5727
     Print the starting and ending addresses of the compiled code for
5728
     source line LINESPEC.  You can specify source lines in any of the
5729
     ways documented in *Note Specify Location::.
5730
 
5731
   For example, we can use `info line' to discover the location of the
5732
object code for the first line of function `m4_changequote':
5733
 
5734
     (gdb) info line m4_changequote
5735
     Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5736
 
5737
We can also inquire (using `*ADDR' as the form for LINESPEC) what
5738
source line covers a particular address:
5739
     (gdb) info line *0x63ff
5740
     Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5741
 
5742
   After `info line', the default address for the `x' command is
5743
changed to the starting address of the line, so that `x/i' is
5744
sufficient to begin examining the machine code (*note Examining Memory:
5745
Memory.).  Also, this address is saved as the value of the convenience
5746
variable `$_' (*note Convenience Variables: Convenience Vars.).
5747
 
5748
`disassemble'
5749
`disassemble /m'
5750
`disassemble /r'
5751
     This specialized command dumps a range of memory as machine
5752
     instructions.  It can also print mixed source+disassembly by
5753
     specifying the `/m' modifier and print the raw instructions in hex
5754
     as well as in symbolic form by specifying the `/r'.  The default
5755
     memory range is the function surrounding the program counter of
5756
     the selected frame.  A single argument to this command is a
5757
     program counter value; GDB dumps the function surrounding this
5758
     value.  When two arguments are given, they should be separated by
5759
     a comma, possibly surrounded by whitespace.  The arguments specify
5760
     a range of addresses to dump, in one of two forms:
5761
 
5762
    `START,END'
5763
          the addresses from START (inclusive) to END (exclusive)
5764
 
5765
    `START,+LENGTH'
5766
          the addresses from START (inclusive) to `START+LENGTH'
5767
          (exclusive).
5768
 
5769
     When 2 arguments are specified, the name of the function is also
5770
     printed (since there could be several functions in the given
5771
     range).
5772
 
5773
     The argument(s) can be any expression yielding a numeric value,
5774
     such as `0x32c4', `&main+10' or `$pc - 8'.
5775
 
5776
     If the range of memory being disassembled contains current program
5777
     counter, the instruction at that location is shown with a `=>'
5778
     marker.
5779
 
5780
   The following example shows the disassembly of a range of addresses
5781
of HP PA-RISC 2.0 code:
5782
 
5783
     (gdb) disas 0x32c4, 0x32e4
5784
     Dump of assembler code from 0x32c4 to 0x32e4:
5785
        0x32c4 :      addil 0,dp
5786
        0x32c8 :      ldw 0x22c(sr0,r1),r26
5787
        0x32cc :      ldil 0x3000,r31
5788
        0x32d0 :      ble 0x3f8(sr4,r31)
5789
        0x32d4 :      ldo 0(r31),rp
5790
        0x32d8 :      addil -0x800,dp
5791
        0x32dc :      ldo 0x588(r1),r26
5792
        0x32e0 :      ldil 0x3000,r31
5793
     End of assembler dump.
5794
 
5795
   Here is an example showing mixed source+assembly for Intel x86, when
5796
the program is stopped just after function prologue:
5797
 
5798
     (gdb) disas /m main
5799
     Dump of assembler code for function main:
5800
     5       {
5801
        0x08048330 <+0>:    push   %ebp
5802
        0x08048331 <+1>:    mov    %esp,%ebp
5803
        0x08048333 <+3>:    sub    $0x8,%esp
5804
        0x08048336 <+6>:    and    $0xfffffff0,%esp
5805
        0x08048339 <+9>:    sub    $0x10,%esp
5806
 
5807
     6         printf ("Hello.\n");
5808
     => 0x0804833c <+12>:   movl   $0x8048440,(%esp)
5809
        0x08048343 <+19>:   call   0x8048284 
5810
 
5811
     7         return 0;
5812
     8       }
5813
        0x08048348 <+24>:   mov    $0x0,%eax
5814
        0x0804834d <+29>:   leave
5815
        0x0804834e <+30>:   ret
5816
 
5817
     End of assembler dump.
5818
 
5819
   Here is another example showing raw instructions in hex for AMD
5820
x86-64,
5821
 
5822
     (gdb) disas /r 0x400281,+10
5823
     Dump of assembler code from 0x400281 to 0x40028b:
5824
        0x0000000000400281:  38 36  cmp    %dh,(%rsi)
5825
        0x0000000000400283:  2d 36 34 2e 73 sub    $0x732e3436,%eax
5826
        0x0000000000400288:  6f     outsl  %ds:(%rsi),(%dx)
5827
        0x0000000000400289:  2e 32 00       xor    %cs:(%rax),%al
5828
     End of assembler dump.
5829
 
5830
   Some architectures have more than one commonly-used set of
5831
instruction mnemonics or other syntax.
5832
 
5833
   For programs that were dynamically linked and use shared libraries,
5834
instructions that call functions or branch to locations in the shared
5835
libraries might show a seemingly bogus location--it's actually a
5836
location of the relocation table.  On some architectures, GDB might be
5837
able to resolve these to actual function names.
5838
 
5839
`set disassembly-flavor INSTRUCTION-SET'
5840
     Select the instruction set to use when disassembling the program
5841
     via the `disassemble' or `x/i' commands.
5842
 
5843
     Currently this command is only defined for the Intel x86 family.
5844
     You can set INSTRUCTION-SET to either `intel' or `att'.  The
5845
     default is `att', the AT&T flavor used by default by Unix
5846
     assemblers for x86-based targets.
5847
 
5848
`show disassembly-flavor'
5849
     Show the current setting of the disassembly flavor.
5850
 
5851
`set disassemble-next-line'
5852
`show disassemble-next-line'
5853
     Control whether or not GDB will disassemble the next source line
5854
     or instruction when execution stops.  If ON, GDB will display
5855
     disassembly of the next source line when execution of the program
5856
     being debugged stops.  This is _in addition_ to displaying the
5857
     source line itself, which GDB always does if possible.  If the
5858
     next source line cannot be displayed for some reason (e.g., if GDB
5859
     cannot find the source file, or there's no line info in the debug
5860
     info), GDB will display disassembly of the next _instruction_
5861
     instead of showing the next source line.  If AUTO, GDB will
5862
     display disassembly of next instruction only if the source line
5863
     cannot be displayed.  This setting causes GDB to display some
5864
     feedback when you step through a function with no line info or
5865
     whose source file is unavailable.  The default is OFF, which means
5866
     never display the disassembly of the next line or instruction.
5867
 
5868

5869
File: gdb.info,  Node: Data,  Next: Optimized Code,  Prev: Source,  Up: Top
5870
 
5871
10 Examining Data
5872
*****************
5873
 
5874
The usual way to examine data in your program is with the `print'
5875
command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
5876
prints the value of an expression of the language your program is
5877
written in (*note Using GDB with Different Languages: Languages.).  It
5878
may also print the expression using a Python-based pretty-printer
5879
(*note Pretty Printing::).
5880
 
5881
`print EXPR'
5882
`print /F EXPR'
5883
     EXPR is an expression (in the source language).  By default the
5884
     value of EXPR is printed in a format appropriate to its data type;
5885
     you can choose a different format by specifying `/F', where F is a
5886
     letter specifying the format; see *Note Output Formats: Output
5887
     Formats.
5888
 
5889
`print'
5890
`print /F'
5891
     If you omit EXPR, GDB displays the last value again (from the
5892
     "value history"; *note Value History: Value History.).  This
5893
     allows you to conveniently inspect the same value in an
5894
     alternative format.
5895
 
5896
   A more low-level way of examining data is with the `x' command.  It
5897
examines data in memory at a specified address and prints it in a
5898
specified format.  *Note Examining Memory: Memory.
5899
 
5900
   If you are interested in information about types, or about how the
5901
fields of a struct or a class are declared, use the `ptype EXP' command
5902
rather than `print'.  *Note Examining the Symbol Table: Symbols.
5903
 
5904
* Menu:
5905
 
5906
* Expressions::                 Expressions
5907
* Ambiguous Expressions::       Ambiguous Expressions
5908
* Variables::                   Program variables
5909
* Arrays::                      Artificial arrays
5910
* Output Formats::              Output formats
5911
* Memory::                      Examining memory
5912
* Auto Display::                Automatic display
5913
* Print Settings::              Print settings
5914
* Pretty Printing::             Python pretty printing
5915
* Value History::               Value history
5916
* Convenience Vars::            Convenience variables
5917
* Registers::                   Registers
5918
* Floating Point Hardware::     Floating point hardware
5919
* Vector Unit::                 Vector Unit
5920
* OS Information::              Auxiliary data provided by operating system
5921
* Memory Region Attributes::    Memory region attributes
5922
* Dump/Restore Files::          Copy between memory and a file
5923
* Core File Generation::        Cause a program dump its core
5924
* Character Sets::              Debugging programs that use a different
5925
                                character set than GDB does
5926
* Caching Remote Data::         Data caching for remote targets
5927
* Searching Memory::            Searching memory for a sequence of bytes
5928
 
5929

5930
File: gdb.info,  Node: Expressions,  Next: Ambiguous Expressions,  Up: Data
5931
 
5932
10.1 Expressions
5933
================
5934
 
5935
`print' and many other GDB commands accept an expression and compute
5936
its value.  Any kind of constant, variable or operator defined by the
5937
programming language you are using is valid in an expression in GDB.
5938
This includes conditional expressions, function calls, casts, and
5939
string constants.  It also includes preprocessor macros, if you
5940
compiled your program to include this information; see *Note
5941
Compilation::.
5942
 
5943
   GDB supports array constants in expressions input by the user.  The
5944
syntax is {ELEMENT, ELEMENT...}.  For example, you can use the command
5945
`print {1, 2, 3}' to create an array of three integers.  If you pass an
5946
array to a function or assign it to a program variable, GDB copies the
5947
array to memory that is `malloc'ed in the target program.
5948
 
5949
   Because C is so widespread, most of the expressions shown in
5950
examples in this manual are in C.  *Note Using GDB with Different
5951
Languages: Languages, for information on how to use expressions in other
5952
languages.
5953
 
5954
   In this section, we discuss operators that you can use in GDB
5955
expressions regardless of your programming language.
5956
 
5957
   Casts are supported in all languages, not just in C, because it is so
5958
useful to cast a number into a pointer in order to examine a structure
5959
at that address in memory.
5960
 
5961
   GDB supports these operators, in addition to those common to
5962
programming languages:
5963
 
5964
`@'
5965
     `@' is a binary operator for treating parts of memory as arrays.
5966
     *Note Artificial Arrays: Arrays, for more information.
5967
 
5968
`::'
5969
     `::' allows you to specify a variable in terms of the file or
5970
     function where it is defined.  *Note Program Variables: Variables.
5971
 
5972
`{TYPE} ADDR'
5973
     Refers to an object of type TYPE stored at address ADDR in memory.
5974
     ADDR may be any expression whose value is an integer or pointer
5975
     (but parentheses are required around binary operators, just as in
5976
     a cast).  This construct is allowed regardless of what kind of
5977
     data is normally supposed to reside at ADDR.
5978
 
5979

5980
File: gdb.info,  Node: Ambiguous Expressions,  Next: Variables,  Prev: Expressions,  Up: Data
5981
 
5982
10.2 Ambiguous Expressions
5983
==========================
5984
 
5985
Expressions can sometimes contain some ambiguous elements.  For
5986
instance, some programming languages (notably Ada, C++ and Objective-C)
5987
permit a single function name to be defined several times, for
5988
application in different contexts.  This is called "overloading".
5989
Another example involving Ada is generics.  A "generic package" is
5990
similar to C++ templates and is typically instantiated several times,
5991
resulting in the same function name being defined in different contexts.
5992
 
5993
   In some cases and depending on the language, it is possible to adjust
5994
the expression to remove the ambiguity.  For instance in C++, you can
5995
specify the signature of the function you want to break on, as in
5996
`break FUNCTION(TYPES)'.  In Ada, using the fully qualified name of
5997
your function often makes the expression unambiguous as well.
5998
 
5999
   When an ambiguity that needs to be resolved is detected, the debugger
6000
has the capability to display a menu of numbered choices for each
6001
possibility, and then waits for the selection with the prompt `>'.  The
6002
first option is always `[0] cancel', and typing `0 ' aborts the
6003
current command.  If the command in which the expression was used
6004
allows more than one choice to be selected, the next option in the menu
6005
is `[1] all', and typing `1 ' selects all possible choices.
6006
 
6007
   For example, the following session excerpt shows an attempt to set a
6008
breakpoint at the overloaded symbol `String::after'.  We choose three
6009
particular definitions of that function name:
6010
 
6011
     (gdb) b String::after
6012
     [0] cancel
6013
     [1] all
6014
     [2] file:String.cc; line number:867
6015
     [3] file:String.cc; line number:860
6016
     [4] file:String.cc; line number:875
6017
     [5] file:String.cc; line number:853
6018
     [6] file:String.cc; line number:846
6019
     [7] file:String.cc; line number:735
6020
     > 2 4 6
6021
     Breakpoint 1 at 0xb26c: file String.cc, line 867.
6022
     Breakpoint 2 at 0xb344: file String.cc, line 875.
6023
     Breakpoint 3 at 0xafcc: file String.cc, line 846.
6024
     Multiple breakpoints were set.
6025
     Use the "delete" command to delete unwanted
6026
      breakpoints.
6027
     (gdb)
6028
 
6029
`set multiple-symbols MODE'
6030
     This option allows you to adjust the debugger behavior when an
6031
     expression is ambiguous.
6032
 
6033
     By default, MODE is set to `all'.  If the command with which the
6034
     expression is used allows more than one choice, then GDB
6035
     automatically selects all possible choices.  For instance,
6036
     inserting a breakpoint on a function using an ambiguous name
6037
     results in a breakpoint inserted on each possible match.  However,
6038
     if a unique choice must be made, then GDB uses the menu to help
6039
     you disambiguate the expression.  For instance, printing the
6040
     address of an overloaded function will result in the use of the
6041
     menu.
6042
 
6043
     When MODE is set to `ask', the debugger always uses the menu when
6044
     an ambiguity is detected.
6045
 
6046
     Finally, when MODE is set to `cancel', the debugger reports an
6047
     error due to the ambiguity and the command is aborted.
6048
 
6049
`show multiple-symbols'
6050
     Show the current value of the `multiple-symbols' setting.
6051
 
6052

6053
File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Ambiguous Expressions,  Up: Data
6054
 
6055
10.3 Program Variables
6056
======================
6057
 
6058
The most common kind of expression to use is the name of a variable in
6059
your program.
6060
 
6061
   Variables in expressions are understood in the selected stack frame
6062
(*note Selecting a Frame: Selection.); they must be either:
6063
 
6064
   * global (or file-static)
6065
 
6066
or
6067
 
6068
   * visible according to the scope rules of the programming language
6069
     from the point of execution in that frame
6070
 
6071
This means that in the function
6072
 
6073
     foo (a)
6074
          int a;
6075
     {
6076
       bar (a);
6077
       {
6078
         int b = test ();
6079
         bar (b);
6080
       }
6081
     }
6082
 
6083
you can examine and use the variable `a' whenever your program is
6084
executing within the function `foo', but you can only use or examine
6085
the variable `b' while your program is executing inside the block where
6086
`b' is declared.
6087
 
6088
   There is an exception: you can refer to a variable or function whose
6089
scope is a single source file even if the current execution point is not
6090
in this file.  But it is possible to have more than one such variable or
6091
function with the same name (in different source files).  If that
6092
happens, referring to that name has unpredictable effects.  If you wish,
6093
you can specify a static variable in a particular function or file,
6094
using the colon-colon (`::') notation:
6095
 
6096
     FILE::VARIABLE
6097
     FUNCTION::VARIABLE
6098
 
6099
Here FILE or FUNCTION is the name of the context for the static
6100
VARIABLE.  In the case of file names, you can use quotes to make sure
6101
GDB parses the file name as a single word--for example, to print a
6102
global value of `x' defined in `f2.c':
6103
 
6104
     (gdb) p 'f2.c'::x
6105
 
6106
   This use of `::' is very rarely in conflict with the very similar
6107
use of the same notation in C++.  GDB also supports use of the C++
6108
scope resolution operator in GDB expressions.
6109
 
6110
     _Warning:_ Occasionally, a local variable may appear to have the
6111
     wrong value at certain points in a function--just after entry to a
6112
     new scope, and just before exit.
6113
   You may see this problem when you are stepping by machine
6114
instructions.  This is because, on most machines, it takes more than
6115
one instruction to set up a stack frame (including local variable
6116
definitions); if you are stepping by machine instructions, variables
6117
may appear to have the wrong values until the stack frame is completely
6118
built.  On exit, it usually also takes more than one machine
6119
instruction to destroy a stack frame; after you begin stepping through
6120
that group of instructions, local variable definitions may be gone.
6121
 
6122
   This may also happen when the compiler does significant
6123
optimizations.  To be sure of always seeing accurate values, turn off
6124
all optimization when compiling.
6125
 
6126
   Another possible effect of compiler optimizations is to optimize
6127
unused variables out of existence, or assign variables to registers (as
6128
opposed to memory addresses).  Depending on the support for such cases
6129
offered by the debug info format used by the compiler, GDB might not be
6130
able to display values for such local variables.  If that happens, GDB
6131
will print a message like this:
6132
 
6133
     No symbol "foo" in current context.
6134
 
6135
   To solve such problems, either recompile without optimizations, or
6136
use a different debug info format, if the compiler supports several such
6137
formats.  For example, GCC, the GNU C/C++ compiler, usually supports
6138
the `-gstabs+' option.  `-gstabs+' produces debug info in a format that
6139
is superior to formats such as COFF.  You may be able to use DWARF 2
6140
(`-gdwarf-2'), which is also an effective form for debug info.  *Note
6141
Options for Debugging Your Program or GCC: (gcc.info)Debugging Options.
6142
*Note C and C++: C, for more information about debug info formats that
6143
are best suited to C++ programs.
6144
 
6145
   If you ask to print an object whose contents are unknown to GDB,
6146
e.g., because its data type is not completely specified by the debug
6147
information, GDB will say `'.  *Note incomplete type:
6148
Symbols, for more about this.
6149
 
6150
   Strings are identified as arrays of `char' values without specified
6151
signedness.  Arrays of either `signed char' or `unsigned char' get
6152
printed as arrays of 1 byte sized integers.  `-fsigned-char' or
6153
`-funsigned-char' GCC options have no effect as GDB defines literal
6154
string type `"char"' as `char' without a sign.  For program code
6155
 
6156
     char var0[] = "A";
6157
     signed char var1[] = "A";
6158
 
6159
   You get during debugging
6160
     (gdb) print var0
6161
     $1 = "A"
6162
     (gdb) print var1
6163
     $2 = {65 'A', 0 '\0'}
6164
 
6165

6166
File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
6167
 
6168
10.4 Artificial Arrays
6169
======================
6170
 
6171
It is often useful to print out several successive objects of the same
6172
type in memory; a section of an array, or an array of dynamically
6173
determined size for which only a pointer exists in the program.
6174
 
6175
   You can do this by referring to a contiguous span of memory as an
6176
"artificial array", using the binary operator `@'.  The left operand of
6177
`@' should be the first element of the desired array and be an
6178
individual object.  The right operand should be the desired length of
6179
the array.  The result is an array value whose elements are all of the
6180
type of the left argument.  The first element is actually the left
6181
argument; the second element comes from bytes of memory immediately
6182
following those that hold the first element, and so on.  Here is an
6183
example.  If a program says
6184
 
6185
     int *array = (int *) malloc (len * sizeof (int));
6186
 
6187
you can print the contents of `array' with
6188
 
6189
     p *array@len
6190
 
6191
   The left operand of `@' must reside in memory.  Array values made
6192
with `@' in this way behave just like other arrays in terms of
6193
subscripting, and are coerced to pointers when used in expressions.
6194
Artificial arrays most often appear in expressions via the value history
6195
(*note Value History: Value History.), after printing one out.
6196
 
6197
   Another way to create an artificial array is to use a cast.  This
6198
re-interprets a value as if it were an array.  The value need not be in
6199
memory:
6200
     (gdb) p/x (short[2])0x12345678
6201
     $1 = {0x1234, 0x5678}
6202
 
6203
   As a convenience, if you leave the array length out (as in
6204
`(TYPE[])VALUE') GDB calculates the size to fill the value (as
6205
`sizeof(VALUE)/sizeof(TYPE)':
6206
     (gdb) p/x (short[])0x12345678
6207
     $2 = {0x1234, 0x5678}
6208
 
6209
   Sometimes the artificial array mechanism is not quite enough; in
6210
moderately complex data structures, the elements of interest may not
6211
actually be adjacent--for example, if you are interested in the values
6212
of pointers in an array.  One useful work-around in this situation is
6213
to use a convenience variable (*note Convenience Variables: Convenience
6214
Vars.) as a counter in an expression that prints the first interesting
6215
value, and then repeat that expression via .  For instance,
6216
suppose you have an array `dtab' of pointers to structures, and you are
6217
interested in the values of a field `fv' in each structure.  Here is an
6218
example of what you might type:
6219
 
6220
     set $i = 0
6221
     p dtab[$i++]->fv
6222
     
6223
     
6224
     ...
6225
 
6226

6227
File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
6228
 
6229
10.5 Output Formats
6230
===================
6231
 
6232
By default, GDB prints a value according to its data type.  Sometimes
6233
this is not what you want.  For example, you might want to print a
6234
number in hex, or a pointer in decimal.  Or you might want to view data
6235
in memory at a certain address as a character string or as an
6236
instruction.  To do these things, specify an "output format" when you
6237
print a value.
6238
 
6239
   The simplest use of output formats is to say how to print a value
6240
already computed.  This is done by starting the arguments of the
6241
`print' command with a slash and a format letter.  The format letters
6242
supported are:
6243
 
6244
`x'
6245
     Regard the bits of the value as an integer, and print the integer
6246
     in hexadecimal.
6247
 
6248
`d'
6249
     Print as integer in signed decimal.
6250
 
6251
`u'
6252
     Print as integer in unsigned decimal.
6253
 
6254
`o'
6255
     Print as integer in octal.
6256
 
6257
`t'
6258
     Print as integer in binary.  The letter `t' stands for "two".  (1)
6259
 
6260
`a'
6261
     Print as an address, both absolute in hexadecimal and as an offset
6262
     from the nearest preceding symbol.  You can use this format used
6263
     to discover where (in what function) an unknown address is located:
6264
 
6265
          (gdb) p/a 0x54320
6266
          $3 = 0x54320 <_initialize_vx+396>
6267
 
6268
     The command `info symbol 0x54320' yields similar results.  *Note
6269
     info symbol: Symbols.
6270
 
6271
`c'
6272
     Regard as an integer and print it as a character constant.  This
6273
     prints both the numerical value and its character representation.
6274
     The character representation is replaced with the octal escape
6275
     `\nnn' for characters outside the 7-bit ASCII range.
6276
 
6277
     Without this format, GDB displays `char', `unsigned char', and
6278
     `signed char' data as character constants.  Single-byte members of
6279
     vectors are displayed as integer data.
6280
 
6281
`f'
6282
     Regard the bits of the value as a floating point number and print
6283
     using typical floating point syntax.
6284
 
6285
`s'
6286
     Regard as a string, if possible.  With this format, pointers to
6287
     single-byte data are displayed as null-terminated strings and
6288
     arrays of single-byte data are displayed as fixed-length strings.
6289
     Other values are displayed in their natural types.
6290
 
6291
     Without this format, GDB displays pointers to and arrays of
6292
     `char', `unsigned char', and `signed char' as strings.
6293
     Single-byte members of a vector are displayed as an integer array.
6294
 
6295
`r'
6296
     Print using the `raw' formatting.  By default, GDB will use a
6297
     Python-based pretty-printer, if one is available (*note Pretty
6298
     Printing::).  This typically results in a higher-level display of
6299
     the value's contents.  The `r' format bypasses any Python
6300
     pretty-printer which might exist.
6301
 
6302
   For example, to print the program counter in hex (*note
6303
Registers::), type
6304
 
6305
     p/x $pc
6306
 
6307
Note that no space is required before the slash; this is because command
6308
names in GDB cannot contain a slash.
6309
 
6310
   To reprint the last value in the value history with a different
6311
format, you can use the `print' command with just a format and no
6312
expression.  For example, `p/x' reprints the last value in hex.
6313
 
6314
   ---------- Footnotes ----------
6315
 
6316
   (1) `b' cannot be used because these format letters are also used
6317
with the `x' command, where `b' stands for "byte"; see *Note Examining
6318
Memory: Memory.
6319
 
6320

6321
File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output Formats,  Up: Data
6322
 
6323
10.6 Examining Memory
6324
=====================
6325
 
6326
You can use the command `x' (for "examine") to examine memory in any of
6327
several formats, independently of your program's data types.
6328
 
6329
`x/NFU ADDR'
6330
`x ADDR'
6331
`x'
6332
     Use the `x' command to examine memory.
6333
 
6334
   N, F, and U are all optional parameters that specify how much memory
6335
to display and how to format it; ADDR is an expression giving the
6336
address where you want to start displaying memory.  If you use defaults
6337
for NFU, you need not type the slash `/'.  Several commands set
6338
convenient defaults for ADDR.
6339
 
6340
N, the repeat count
6341
     The repeat count is a decimal integer; the default is 1.  It
6342
     specifies how much memory (counting by units U) to display.
6343
 
6344
F, the display format
6345
     The display format is one of the formats used by `print' (`x',
6346
     `d', `u', `o', `t', `a', `c', `f', `s'), and in addition `i' (for
6347
     machine instructions).  The default is `x' (hexadecimal)
6348
     initially.  The default changes each time you use either `x' or
6349
     `print'.
6350
 
6351
U, the unit size
6352
     The unit size is any of
6353
 
6354
    `b'
6355
          Bytes.
6356
 
6357
    `h'
6358
          Halfwords (two bytes).
6359
 
6360
    `w'
6361
          Words (four bytes).  This is the initial default.
6362
 
6363
    `g'
6364
          Giant words (eight bytes).
6365
 
6366
     Each time you specify a unit size with `x', that size becomes the
6367
     default unit the next time you use `x'.  For the `i' format, the
6368
     unit size is ignored and is normally not written.  For the `s'
6369
     format, the unit size defaults to `b', unless it is explicitly
6370
     given.  Use `x /hs' to display 16-bit char strings and `x /ws' to
6371
     display 32-bit strings.  The next use of `x /s' will again display
6372
     8-bit strings.  Note that the results depend on the programming
6373
     language of the current compilation unit.  If the language is C,
6374
     the `s' modifier will use the UTF-16 encoding while `w' will use
6375
     UTF-32.  The encoding is set by the programming language and cannot
6376
     be altered.
6377
 
6378
ADDR, starting display address
6379
     ADDR is the address where you want GDB to begin displaying memory.
6380
     The expression need not have a pointer value (though it may); it
6381
     is always interpreted as an integer address of a byte of memory.
6382
     *Note Expressions: Expressions, for more information on
6383
     expressions.  The default for ADDR is usually just after the last
6384
     address examined--but several other commands also set the default
6385
     address: `info breakpoints' (to the address of the last breakpoint
6386
     listed), `info line' (to the starting address of a line), and
6387
     `print' (if you use it to display a value from memory).
6388
 
6389
   For example, `x/3uh 0x54320' is a request to display three halfwords
6390
(`h') of memory, formatted as unsigned decimal integers (`u'), starting
6391
at address `0x54320'.  `x/4xw $sp' prints the four words (`w') of
6392
memory above the stack pointer (here, `$sp'; *note Registers:
6393
Registers.) in hexadecimal (`x').
6394
 
6395
   Since the letters indicating unit sizes are all distinct from the
6396
letters specifying output formats, you do not have to remember whether
6397
unit size or format comes first; either order works.  The output
6398
specifications `4xw' and `4wx' mean exactly the same thing.  (However,
6399
the count N must come first; `wx4' does not work.)
6400
 
6401
   Even though the unit size U is ignored for the formats `s' and `i',
6402
you might still want to use a count N; for example, `3i' specifies that
6403
you want to see three machine instructions, including any operands.
6404
For convenience, especially when used with the `display' command, the
6405
`i' format also prints branch delay slot instructions, if any, beyond
6406
the count specified, which immediately follow the last instruction that
6407
is within the count.  The command `disassemble' gives an alternative
6408
way of inspecting machine instructions; see *Note Source and Machine
6409
Code: Machine Code.
6410
 
6411
   All the defaults for the arguments to `x' are designed to make it
6412
easy to continue scanning memory with minimal specifications each time
6413
you use `x'.  For example, after you have inspected three machine
6414
instructions with `x/3i ADDR', you can inspect the next seven with just
6415
`x/7'.  If you use  to repeat the `x' command, the repeat count N
6416
is used again; the other arguments default as for successive uses of
6417
`x'.
6418
 
6419
   When examining machine instructions, the instruction at current
6420
program counter is shown with a `=>' marker. For example:
6421
 
6422
     (gdb) x/5i $pc-6
6423
        0x804837f : mov    %esp,%ebp
6424
        0x8048381 : push   %ecx
6425
        0x8048382 : sub    $0x4,%esp
6426
     => 0x8048385 : movl   $0x8048460,(%esp)
6427
        0x804838c : call   0x80482d4 
6428
 
6429
   The addresses and contents printed by the `x' command are not saved
6430
in the value history because there is often too much of them and they
6431
would get in the way.  Instead, GDB makes these values available for
6432
subsequent use in expressions as values of the convenience variables
6433
`$_' and `$__'.  After an `x' command, the last address examined is
6434
available for use in expressions in the convenience variable `$_'.  The
6435
contents of that address, as examined, are available in the convenience
6436
variable `$__'.
6437
 
6438
   If the `x' command has a repeat count, the address and contents saved
6439
are from the last memory unit printed; this is not the same as the last
6440
address printed if several units were printed on the last line of
6441
output.
6442
 
6443
   When you are debugging a program running on a remote target machine
6444
(*note Remote Debugging::), you may wish to verify the program's image
6445
in the remote machine's memory against the executable file you
6446
downloaded to the target.  The `compare-sections' command is provided
6447
for such situations.
6448
 
6449
`compare-sections [SECTION-NAME]'
6450
     Compare the data of a loadable section SECTION-NAME in the
6451
     executable file of the program being debugged with the same
6452
     section in the remote machine's memory, and report any mismatches.
6453
     With no arguments, compares all loadable sections.  This command's
6454
     availability depends on the target's support for the `"qCRC"'
6455
     remote request.
6456
 
6457

6458
File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
6459
 
6460
10.7 Automatic Display
6461
======================
6462
 
6463
If you find that you want to print the value of an expression frequently
6464
(to see how it changes), you might want to add it to the "automatic
6465
display list" so that GDB prints its value each time your program stops.
6466
Each expression added to the list is given a number to identify it; to
6467
remove an expression from the list, you specify that number.  The
6468
automatic display looks like this:
6469
 
6470
     2: foo = 38
6471
     3: bar[5] = (struct hack *) 0x3804
6472
 
6473
This display shows item numbers, expressions and their current values.
6474
As with displays you request manually using `x' or `print', you can
6475
specify the output format you prefer; in fact, `display' decides
6476
whether to use `print' or `x' depending your format specification--it
6477
uses `x' if you specify either the `i' or `s' format, or a unit size;
6478
otherwise it uses `print'.
6479
 
6480
`display EXPR'
6481
     Add the expression EXPR to the list of expressions to display each
6482
     time your program stops.  *Note Expressions: Expressions.
6483
 
6484
     `display' does not repeat if you press  again after using it.
6485
 
6486
`display/FMT EXPR'
6487
     For FMT specifying only a display format and not a size or count,
6488
     add the expression EXPR to the auto-display list but arrange to
6489
     display it each time in the specified format FMT.  *Note Output
6490
     Formats: Output Formats.
6491
 
6492
`display/FMT ADDR'
6493
     For FMT `i' or `s', or including a unit-size or a number of units,
6494
     add the expression ADDR as a memory address to be examined each
6495
     time your program stops.  Examining means in effect doing `x/FMT
6496
     ADDR'.  *Note Examining Memory: Memory.
6497
 
6498
   For example, `display/i $pc' can be helpful, to see the machine
6499
instruction about to be executed each time execution stops (`$pc' is a
6500
common name for the program counter; *note Registers: Registers.).
6501
 
6502
`undisplay DNUMS...'
6503
`delete display DNUMS...'
6504
     Remove item numbers DNUMS from the list of expressions to display.
6505
 
6506
     `undisplay' does not repeat if you press  after using it.
6507
     (Otherwise you would just get the error `No display number ...'.)
6508
 
6509
`disable display DNUMS...'
6510
     Disable the display of item numbers DNUMS.  A disabled display
6511
     item is not printed automatically, but is not forgotten.  It may be
6512
     enabled again later.
6513
 
6514
`enable display DNUMS...'
6515
     Enable display of item numbers DNUMS.  It becomes effective once
6516
     again in auto display of its expression, until you specify
6517
     otherwise.
6518
 
6519
`display'
6520
     Display the current values of the expressions on the list, just as
6521
     is done when your program stops.
6522
 
6523
`info display'
6524
     Print the list of expressions previously set up to display
6525
     automatically, each one with its item number, but without showing
6526
     the values.  This includes disabled expressions, which are marked
6527
     as such.  It also includes expressions which would not be
6528
     displayed right now because they refer to automatic variables not
6529
     currently available.
6530
 
6531
   If a display expression refers to local variables, then it does not
6532
make sense outside the lexical context for which it was set up.  Such an
6533
expression is disabled when execution enters a context where one of its
6534
variables is not defined.  For example, if you give the command
6535
`display last_char' while inside a function with an argument
6536
`last_char', GDB displays this argument while your program continues to
6537
stop inside that function.  When it stops elsewhere--where there is no
6538
variable `last_char'--the display is disabled automatically.  The next
6539
time your program stops where `last_char' is meaningful, you can enable
6540
the display expression once again.
6541
 
6542

6543
File: gdb.info,  Node: Print Settings,  Next: Pretty Printing,  Prev: Auto Display,  Up: Data
6544
 
6545
10.8 Print Settings
6546
===================
6547
 
6548
GDB provides the following ways to control how arrays, structures, and
6549
symbols are printed.
6550
 
6551
These settings are useful for debugging programs in any language:
6552
 
6553
`set print address'
6554
`set print address on'
6555
     GDB prints memory addresses showing the location of stack traces,
6556
     structure values, pointer values, breakpoints, and so forth, even
6557
     when it also displays the contents of those addresses.  The default
6558
     is `on'.  For example, this is what a stack frame display looks
6559
     like with `set print address on':
6560
 
6561
          (gdb) f
6562
          #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
6563
              at input.c:530
6564
          530         if (lquote != def_lquote)
6565
 
6566
`set print address off'
6567
     Do not print addresses when displaying their contents.  For
6568
     example, this is the same stack frame displayed with `set print
6569
     address off':
6570
 
6571
          (gdb) set print addr off
6572
          (gdb) f
6573
          #0  set_quotes (lq="<<", rq=">>") at input.c:530
6574
          530         if (lquote != def_lquote)
6575
 
6576
     You can use `set print address off' to eliminate all machine
6577
     dependent displays from the GDB interface.  For example, with
6578
     `print address off', you should get the same text for backtraces on
6579
     all machines--whether or not they involve pointer arguments.
6580
 
6581
`show print address'
6582
     Show whether or not addresses are to be printed.
6583
 
6584
   When GDB prints a symbolic address, it normally prints the closest
6585
earlier symbol plus an offset.  If that symbol does not uniquely
6586
identify the address (for example, it is a name whose scope is a single
6587
source file), you may need to clarify.  One way to do this is with
6588
`info line', for example `info line *0x4537'.  Alternately, you can set
6589
GDB to print the source file and line number when it prints a symbolic
6590
address:
6591
 
6592
`set print symbol-filename on'
6593
     Tell GDB to print the source file name and line number of a symbol
6594
     in the symbolic form of an address.
6595
 
6596
`set print symbol-filename off'
6597
     Do not print source file name and line number of a symbol.  This
6598
     is the default.
6599
 
6600
`show print symbol-filename'
6601
     Show whether or not GDB will print the source file name and line
6602
     number of a symbol in the symbolic form of an address.
6603
 
6604
   Another situation where it is helpful to show symbol filenames and
6605
line numbers is when disassembling code; GDB shows you the line number
6606
and source file that corresponds to each instruction.
6607
 
6608
   Also, you may wish to see the symbolic form only if the address being
6609
printed is reasonably close to the closest earlier symbol:
6610
 
6611
`set print max-symbolic-offset MAX-OFFSET'
6612
     Tell GDB to only display the symbolic form of an address if the
6613
     offset between the closest earlier symbol and the address is less
6614
     than MAX-OFFSET.  The default is 0, which tells GDB to always
6615
     print the symbolic form of an address if any symbol precedes it.
6616
 
6617
`show print max-symbolic-offset'
6618
     Ask how large the maximum offset is that GDB prints in a symbolic
6619
     address.
6620
 
6621
   If you have a pointer and you are not sure where it points, try `set
6622
print symbol-filename on'.  Then you can determine the name and source
6623
file location of the variable where it points, using `p/a POINTER'.
6624
This interprets the address in symbolic form.  For example, here GDB
6625
shows that a variable `ptt' points at another variable `t', defined in
6626
`hi2.c':
6627
 
6628
     (gdb) set print symbol-filename on
6629
     (gdb) p/a ptt
6630
     $4 = 0xe008 
6631
 
6632
     _Warning:_ For pointers that point to a local variable, `p/a' does
6633
     not show the symbol name and filename of the referent, even with
6634
     the appropriate `set print' options turned on.
6635
 
6636
   Other settings control how different kinds of objects are printed:
6637
 
6638
`set print array'
6639
`set print array on'
6640
     Pretty print arrays.  This format is more convenient to read, but
6641
     uses more space.  The default is off.
6642
 
6643
`set print array off'
6644
     Return to compressed format for arrays.
6645
 
6646
`show print array'
6647
     Show whether compressed or pretty format is selected for displaying
6648
     arrays.
6649
 
6650
`set print array-indexes'
6651
`set print array-indexes on'
6652
     Print the index of each element when displaying arrays.  May be
6653
     more convenient to locate a given element in the array or quickly
6654
     find the index of a given element in that printed array.  The
6655
     default is off.
6656
 
6657
`set print array-indexes off'
6658
     Stop printing element indexes when displaying arrays.
6659
 
6660
`show print array-indexes'
6661
     Show whether the index of each element is printed when displaying
6662
     arrays.
6663
 
6664
`set print elements NUMBER-OF-ELEMENTS'
6665
     Set a limit on how many elements of an array GDB will print.  If
6666
     GDB is printing a large array, it stops printing after it has
6667
     printed the number of elements set by the `set print elements'
6668
     command.  This limit also applies to the display of strings.  When
6669
     GDB starts, this limit is set to 200.  Setting  NUMBER-OF-ELEMENTS
6670
     to zero means that the printing is unlimited.
6671
 
6672
`show print elements'
6673
     Display the number of elements of a large array that GDB will
6674
     print.  If the number is 0, then the printing is unlimited.
6675
 
6676
`set print frame-arguments VALUE'
6677
     This command allows to control how the values of arguments are
6678
     printed when the debugger prints a frame (*note Frames::).  The
6679
     possible values are:
6680
 
6681
    `all'
6682
          The values of all arguments are printed.
6683
 
6684
    `scalars'
6685
          Print the value of an argument only if it is a scalar.  The
6686
          value of more complex arguments such as arrays, structures,
6687
          unions, etc, is replaced by `...'.  This is the default.
6688
          Here is an example where only scalar arguments are shown:
6689
 
6690
               #1  0x08048361 in call_me (i=3, s=..., ss=0xbf8d508c, u=..., e=green)
6691
                 at frame-args.c:23
6692
 
6693
    `none'
6694
          None of the argument values are printed.  Instead, the value
6695
          of each argument is replaced by `...'.  In this case, the
6696
          example above now becomes:
6697
 
6698
               #1  0x08048361 in call_me (i=..., s=..., ss=..., u=..., e=...)
6699
                 at frame-args.c:23
6700
 
6701
     By default, only scalar arguments are printed.  This command can
6702
     be used to configure the debugger to print the value of all
6703
     arguments, regardless of their type.  However, it is often
6704
     advantageous to not print the value of more complex parameters.
6705
     For instance, it reduces the amount of information printed in each
6706
     frame, making the backtrace more readable.  Also, it improves
6707
     performance when displaying Ada frames, because the computation of
6708
     large arguments can sometimes be CPU-intensive, especially in
6709
     large applications.  Setting `print frame-arguments' to `scalars'
6710
     (the default) or `none' avoids this computation, thus speeding up
6711
     the display of each Ada frame.
6712
 
6713
`show print frame-arguments'
6714
     Show how the value of arguments should be displayed when printing
6715
     a frame.
6716
 
6717
`set print repeats'
6718
     Set the threshold for suppressing display of repeated array
6719
     elements.  When the number of consecutive identical elements of an
6720
     array exceeds the threshold, GDB prints the string `"
6721
     times>"', where N is the number of identical repetitions, instead
6722
     of displaying the identical elements themselves.  Setting the
6723
     threshold to zero will cause all elements to be individually
6724
     printed.  The default threshold is 10.
6725
 
6726
`show print repeats'
6727
     Display the current threshold for printing repeated identical
6728
     elements.
6729
 
6730
`set print null-stop'
6731
     Cause GDB to stop printing the characters of an array when the
6732
     first NULL is encountered.  This is useful when large arrays
6733
     actually contain only short strings.  The default is off.
6734
 
6735
`show print null-stop'
6736
     Show whether GDB stops printing an array on the first NULL
6737
     character.
6738
 
6739
`set print pretty on'
6740
     Cause GDB to print structures in an indented format with one member
6741
     per line, like this:
6742
 
6743
          $1 = {
6744
            next = 0x0,
6745
            flags = {
6746
              sweet = 1,
6747
              sour = 1
6748
            },
6749
            meat = 0x54 "Pork"
6750
          }
6751
 
6752
`set print pretty off'
6753
     Cause GDB to print structures in a compact format, like this:
6754
 
6755
          $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
6756
          meat = 0x54 "Pork"}
6757
 
6758
     This is the default format.
6759
 
6760
`show print pretty'
6761
     Show which format GDB is using to print structures.
6762
 
6763
`set print sevenbit-strings on'
6764
     Print using only seven-bit characters; if this option is set, GDB
6765
     displays any eight-bit characters (in strings or character values)
6766
     using the notation `\'NNN.  This setting is best if you are
6767
     working in English (ASCII) and you use the high-order bit of
6768
     characters as a marker or "meta" bit.
6769
 
6770
`set print sevenbit-strings off'
6771
     Print full eight-bit characters.  This allows the use of more
6772
     international character sets, and is the default.
6773
 
6774
`show print sevenbit-strings'
6775
     Show whether or not GDB is printing only seven-bit characters.
6776
 
6777
`set print union on'
6778
     Tell GDB to print unions which are contained in structures and
6779
     other unions.  This is the default setting.
6780
 
6781
`set print union off'
6782
     Tell GDB not to print unions which are contained in structures and
6783
     other unions.  GDB will print `"{...}"' instead.
6784
 
6785
`show print union'
6786
     Ask GDB whether or not it will print unions which are contained in
6787
     structures and other unions.
6788
 
6789
     For example, given the declarations
6790
 
6791
          typedef enum {Tree, Bug} Species;
6792
          typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
6793
          typedef enum {Caterpillar, Cocoon, Butterfly}
6794
                        Bug_forms;
6795
 
6796
          struct thing {
6797
            Species it;
6798
            union {
6799
              Tree_forms tree;
6800
              Bug_forms bug;
6801
            } form;
6802
          };
6803
 
6804
          struct thing foo = {Tree, {Acorn}};
6805
 
6806
     with `set print union on' in effect `p foo' would print
6807
 
6808
          $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
6809
 
6810
     and with `set print union off' in effect it would print
6811
 
6812
          $1 = {it = Tree, form = {...}}
6813
 
6814
     `set print union' affects programs written in C-like languages and
6815
     in Pascal.
6816
 
6817
These settings are of interest when debugging C++ programs:
6818
 
6819
`set print demangle'
6820
`set print demangle on'
6821
     Print C++ names in their source form rather than in the encoded
6822
     ("mangled") form passed to the assembler and linker for type-safe
6823
     linkage.  The default is on.
6824
 
6825
`show print demangle'
6826
     Show whether C++ names are printed in mangled or demangled form.
6827
 
6828
`set print asm-demangle'
6829
`set print asm-demangle on'
6830
     Print C++ names in their source form rather than their mangled
6831
     form, even in assembler code printouts such as instruction
6832
     disassemblies.  The default is off.
6833
 
6834
`show print asm-demangle'
6835
     Show whether C++ names in assembly listings are printed in mangled
6836
     or demangled form.
6837
 
6838
`set demangle-style STYLE'
6839
     Choose among several encoding schemes used by different compilers
6840
     to represent C++ names.  The choices for STYLE are currently:
6841
 
6842
    `auto'
6843
          Allow GDB to choose a decoding style by inspecting your
6844
          program.
6845
 
6846
    `gnu'
6847
          Decode based on the GNU C++ compiler (`g++') encoding
6848
          algorithm.  This is the default.
6849
 
6850
    `hp'
6851
          Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
6852
 
6853
    `lucid'
6854
          Decode based on the Lucid C++ compiler (`lcc') encoding
6855
          algorithm.
6856
 
6857
    `arm'
6858
          Decode using the algorithm in the `C++ Annotated Reference
6859
          Manual'.  *Warning:* this setting alone is not sufficient to
6860
          allow debugging `cfront'-generated executables.  GDB would
6861
          require further enhancement to permit that.
6862
 
6863
     If you omit STYLE, you will see a list of possible formats.
6864
 
6865
`show demangle-style'
6866
     Display the encoding style currently in use for decoding C++
6867
     symbols.
6868
 
6869
`set print object'
6870
`set print object on'
6871
     When displaying a pointer to an object, identify the _actual_
6872
     (derived) type of the object rather than the _declared_ type, using
6873
     the virtual function table.
6874
 
6875
`set print object off'
6876
     Display only the declared type of objects, without reference to the
6877
     virtual function table.  This is the default setting.
6878
 
6879
`show print object'
6880
     Show whether actual, or declared, object types are displayed.
6881
 
6882
`set print static-members'
6883
`set print static-members on'
6884
     Print static members when displaying a C++ object.  The default is
6885
     on.
6886
 
6887
`set print static-members off'
6888
     Do not print static members when displaying a C++ object.
6889
 
6890
`show print static-members'
6891
     Show whether C++ static members are printed or not.
6892
 
6893
`set print pascal_static-members'
6894
`set print pascal_static-members on'
6895
     Print static members when displaying a Pascal object.  The default
6896
     is on.
6897
 
6898
`set print pascal_static-members off'
6899
     Do not print static members when displaying a Pascal object.
6900
 
6901
`show print pascal_static-members'
6902
     Show whether Pascal static members are printed or not.
6903
 
6904
`set print vtbl'
6905
`set print vtbl on'
6906
     Pretty print C++ virtual function tables.  The default is off.
6907
     (The `vtbl' commands do not work on programs compiled with the HP
6908
     ANSI C++ compiler (`aCC').)
6909
 
6910
`set print vtbl off'
6911
     Do not pretty print C++ virtual function tables.
6912
 
6913
`show print vtbl'
6914
     Show whether C++ virtual function tables are pretty printed, or
6915
     not.
6916
 
6917

6918
File: gdb.info,  Node: Pretty Printing,  Next: Value History,  Prev: Print Settings,  Up: Data
6919
 
6920
10.9 Pretty Printing
6921
====================
6922
 
6923
GDB provides a mechanism to allow pretty-printing of values using
6924
Python code.  It greatly simplifies the display of complex objects.
6925
This mechanism works for both MI and the CLI.
6926
 
6927
   For example, here is how a C++ `std::string' looks without a
6928
pretty-printer:
6929
 
6930
     (gdb) print s
6931
     $1 = {
6932
       static npos = 4294967295,
6933
       _M_dataplus = {
6934
         > = {
6935
           <__gnu_cxx::new_allocator> = {
6936
             }, 
6937
           },
6938
         members of std::basic_string,
6939
           std::allocator >::_Alloc_hider:
6940
         _M_p = 0x804a014 "abcd"
6941
       }
6942
     }
6943
 
6944
   With a pretty-printer for `std::string' only the contents are
6945
printed:
6946
 
6947
     (gdb) print s
6948
     $2 = "abcd"
6949
 
6950
   For implementing pretty printers for new types you should read the
6951
Python API details (*note Pretty Printing API::).
6952
 
6953

6954
File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Pretty Printing,  Up: Data
6955
 
6956
10.10 Value History
6957
===================
6958
 
6959
Values printed by the `print' command are saved in the GDB "value
6960
history".  This allows you to refer to them in other expressions.
6961
Values are kept until the symbol table is re-read or discarded (for
6962
example with the `file' or `symbol-file' commands).  When the symbol
6963
table changes, the value history is discarded, since the values may
6964
contain pointers back to the types defined in the symbol table.
6965
 
6966
   The values printed are given "history numbers" by which you can
6967
refer to them.  These are successive integers starting with one.
6968
`print' shows you the history number assigned to a value by printing
6969
`$NUM = ' before the value; here NUM is the history number.
6970
 
6971
   To refer to any previous value, use `$' followed by the value's
6972
history number.  The way `print' labels its output is designed to
6973
remind you of this.  Just `$' refers to the most recent value in the
6974
history, and `$$' refers to the value before that.  `$$N' refers to the
6975
Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
6976
equivalent to `$$', and `$$0' is equivalent to `$'.
6977
 
6978
   For example, suppose you have just printed a pointer to a structure
6979
and want to see the contents of the structure.  It suffices to type
6980
 
6981
     p *$
6982
 
6983
   If you have a chain of structures where the component `next' points
6984
to the next one, you can print the contents of the next one with this:
6985
 
6986
     p *$.next
6987
 
6988
You can print successive links in the chain by repeating this
6989
command--which you can do by just typing .
6990
 
6991
   Note that the history records values, not expressions.  If the value
6992
of `x' is 4 and you type these commands:
6993
 
6994
     print x
6995
     set x=5
6996
 
6997
then the value recorded in the value history by the `print' command
6998
remains 4 even though the value of `x' has changed.
6999
 
7000
`show values'
7001
     Print the last ten values in the value history, with their item
7002
     numbers.  This is like `p $$9' repeated ten times, except that
7003
     `show values' does not change the history.
7004
 
7005
`show values N'
7006
     Print ten history values centered on history item number N.
7007
 
7008
`show values +'
7009
     Print ten history values just after the values last printed.  If
7010
     no more values are available, `show values +' produces no display.
7011
 
7012
   Pressing  to repeat `show values N' has exactly the same effect
7013
as `show values +'.
7014
 
7015

7016
File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
7017
 
7018
10.11 Convenience Variables
7019
===========================
7020
 
7021
GDB provides "convenience variables" that you can use within GDB to
7022
hold on to a value and refer to it later.  These variables exist
7023
entirely within GDB; they are not part of your program, and setting a
7024
convenience variable has no direct effect on further execution of your
7025
program.  That is why you can use them freely.
7026
 
7027
   Convenience variables are prefixed with `$'.  Any name preceded by
7028
`$' can be used for a convenience variable, unless it is one of the
7029
predefined machine-specific register names (*note Registers:
7030
Registers.).  (Value history references, in contrast, are _numbers_
7031
preceded by `$'.  *Note Value History: Value History.)
7032
 
7033
   You can save a value in a convenience variable with an assignment
7034
expression, just as you would set a variable in your program.  For
7035
example:
7036
 
7037
     set $foo = *object_ptr
7038
 
7039
would save in `$foo' the value contained in the object pointed to by
7040
`object_ptr'.
7041
 
7042
   Using a convenience variable for the first time creates it, but its
7043
value is `void' until you assign a new value.  You can alter the value
7044
with another assignment at any time.
7045
 
7046
   Convenience variables have no fixed types.  You can assign a
7047
convenience variable any type of value, including structures and
7048
arrays, even if that variable already has a value of a different type.
7049
The convenience variable, when used as an expression, has the type of
7050
its current value.
7051
 
7052
`show convenience'
7053
     Print a list of convenience variables used so far, and their
7054
     values.  Abbreviated `show conv'.
7055
 
7056
`init-if-undefined $VARIABLE = EXPRESSION'
7057
     Set a convenience variable if it has not already been set.  This
7058
     is useful for user-defined commands that keep some state.  It is
7059
     similar, in concept, to using local static variables with
7060
     initializers in C (except that convenience variables are global).
7061
     It can also be used to allow users to override default values used
7062
     in a command script.
7063
 
7064
     If the variable is already defined then the expression is not
7065
     evaluated so any side-effects do not occur.
7066
 
7067
   One of the ways to use a convenience variable is as a counter to be
7068
incremented or a pointer to be advanced.  For example, to print a field
7069
from successive elements of an array of structures:
7070
 
7071
     set $i = 0
7072
     print bar[$i++]->contents
7073
 
7074
Repeat that command by typing .
7075
 
7076
   Some convenience variables are created automatically by GDB and given
7077
values likely to be useful.
7078
 
7079
`$_'
7080
     The variable `$_' is automatically set by the `x' command to the
7081
     last address examined (*note Examining Memory: Memory.).  Other
7082
     commands which provide a default address for `x' to examine also
7083
     set `$_' to that address; these commands include `info line' and
7084
     `info breakpoint'.  The type of `$_' is `void *' except when set
7085
     by the `x' command, in which case it is a pointer to the type of
7086
     `$__'.
7087
 
7088
`$__'
7089
     The variable `$__' is automatically set by the `x' command to the
7090
     value found in the last address examined.  Its type is chosen to
7091
     match the format in which the data was printed.
7092
 
7093
`$_exitcode'
7094
     The variable `$_exitcode' is automatically set to the exit code
7095
     when the program being debugged terminates.
7096
 
7097
`$_sdata'
7098
     The variable `$_sdata' contains extra collected static tracepoint
7099
     data.  *Note Tracepoint Action Lists: Tracepoint Actions.  Note
7100
     that `$_sdata' could be empty, if not inspecting a trace buffer, or
7101
     if extra static tracepoint data has not been collected.
7102
 
7103
`$_siginfo'
7104
     The variable `$_siginfo' contains extra signal information (*note
7105
     extra signal information::).  Note that `$_siginfo' could be
7106
     empty, if the application has not yet received any signals.  For
7107
     example, it will be empty before you execute the `run' command.
7108
 
7109
`$_tlb'
7110
     The variable `$_tlb' is automatically set when debugging
7111
     applications running on MS-Windows in native mode or connected to
7112
     gdbserver that supports the `qGetTIBAddr' request.  *Note General
7113
     Query Packets::.  This variable contains the address of the thread
7114
     information block.
7115
 
7116
 
7117
   On HP-UX systems, if you refer to a function or variable name that
7118
begins with a dollar sign, GDB searches for a user or system name
7119
first, before it searches for a convenience variable.
7120
 
7121
   GDB also supplies some "convenience functions".  These have a syntax
7122
similar to convenience variables.  A convenience function can be used
7123
in an expression just like an ordinary function; however, a convenience
7124
function is implemented internally to GDB.
7125
 
7126
`help function'
7127
     Print a list of all convenience functions.
7128
 

powered by: WebSVN 2.1.0

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