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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [doc/] [gdb.info-1] - Blame information for rev 853

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 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.1 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.1.
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.1 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.1.
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 Modula-2 is partial.  For information on Modula-2, see
142
*Note Modula-2: Modula-2.
143
 
144
   Debugging Pascal programs which use sets, subranges, file variables,
145
or nested functions does not currently work.  GDB does not support
146
entering expressions, printing values, or similar features using Pascal
147
syntax.
148
 
149
   GDB can be used to debug programs written in Fortran, although it
150
may be necessary to refer to some variables with a trailing underscore.
151
 
152
   GDB can be used to debug programs written in Objective-C, using
153
either the Apple/NeXT or the GNU Objective-C runtime.
154
 
155
* Menu:
156
 
157
* Free Software::               Freely redistributable software
158
* Contributors::                Contributors to GDB
159
 
160

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3433
File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Catchpoints,  Up: Breakpoints
3434
 
3435
5.1.4 Deleting Breakpoints
3436
--------------------------
3437
 
3438
It is often necessary to eliminate a breakpoint, watchpoint, or
3439
catchpoint once it has done its job and you no longer want your program
3440
to stop there.  This is called "deleting" the breakpoint.  A breakpoint
3441
that has been deleted no longer exists; it is forgotten.
3442
 
3443
   With the `clear' command you can delete breakpoints according to
3444
where they are in your program.  With the `delete' command you can
3445
delete individual breakpoints, watchpoints, or catchpoints by specifying
3446
their breakpoint numbers.
3447
 
3448
   It is not necessary to delete a breakpoint to proceed past it.  GDB
3449
automatically ignores breakpoints on the first instruction to be
3450
executed when you continue execution without changing the execution
3451
address.
3452
 
3453
`clear'
3454
     Delete any breakpoints at the next instruction to be executed in
3455
     the selected stack frame (*note Selecting a Frame: Selection.).
3456
     When the innermost frame is selected, this is a good way to delete
3457
     a breakpoint where your program just stopped.
3458
 
3459
`clear LOCATION'
3460
     Delete any breakpoints set at the specified LOCATION.  *Note
3461
     Specify Location::, for the various forms of LOCATION; the most
3462
     useful ones are listed below:
3463
 
3464
    `clear FUNCTION'
3465
    `clear FILENAME:FUNCTION'
3466
          Delete any breakpoints set at entry to the named FUNCTION.
3467
 
3468
    `clear LINENUM'
3469
    `clear FILENAME:LINENUM'
3470
          Delete any breakpoints set at or within the code of the
3471
          specified LINENUM of the specified FILENAME.
3472
 
3473
`delete [breakpoints] [RANGE...]'
3474
     Delete the breakpoints, watchpoints, or catchpoints of the
3475
     breakpoint ranges specified as arguments.  If no argument is
3476
     specified, delete all breakpoints (GDB asks confirmation, unless
3477
     you have `set confirm off').  You can abbreviate this command as
3478
     `d'.
3479
 
3480

3481
File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
3482
 
3483
5.1.5 Disabling Breakpoints
3484
---------------------------
3485
 
3486
Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3487
prefer to "disable" it.  This makes the breakpoint inoperative as if it
3488
had been deleted, but remembers the information on the breakpoint so
3489
that you can "enable" it again later.
3490
 
3491
   You disable and enable breakpoints, watchpoints, and catchpoints with
3492
the `enable' and `disable' commands, optionally specifying one or more
3493
breakpoint numbers as arguments.  Use `info break' or `info watch' to
3494
print a list of breakpoints, watchpoints, and catchpoints if you do not
3495
know which numbers to use.
3496
 
3497
   Disabling and enabling a breakpoint that has multiple locations
3498
affects all of its locations.
3499
 
3500
   A breakpoint, watchpoint, or catchpoint can have any of four
3501
different states of enablement:
3502
 
3503
   * Enabled.  The breakpoint stops your program.  A breakpoint set
3504
     with the `break' command starts out in this state.
3505
 
3506
   * Disabled.  The breakpoint has no effect on your program.
3507
 
3508
   * Enabled once.  The breakpoint stops your program, but then becomes
3509
     disabled.
3510
 
3511
   * Enabled for deletion.  The breakpoint stops your program, but
3512
     immediately after it does so it is deleted permanently.  A
3513
     breakpoint set with the `tbreak' command starts out in this state.
3514
 
3515
   You can use the following commands to enable or disable breakpoints,
3516
watchpoints, and catchpoints:
3517
 
3518
`disable [breakpoints] [RANGE...]'
3519
     Disable the specified breakpoints--or all breakpoints, if none are
3520
     listed.  A disabled breakpoint has no effect but is not forgotten.
3521
     All options such as ignore-counts, conditions and commands are
3522
     remembered in case the breakpoint is enabled again later.  You may
3523
     abbreviate `disable' as `dis'.
3524
 
3525
`enable [breakpoints] [RANGE...]'
3526
     Enable the specified breakpoints (or all defined breakpoints).
3527
     They become effective once again in stopping your program.
3528
 
3529
`enable [breakpoints] once RANGE...'
3530
     Enable the specified breakpoints temporarily.  GDB disables any of
3531
     these breakpoints immediately after stopping your program.
3532
 
3533
`enable [breakpoints] delete RANGE...'
3534
     Enable the specified breakpoints to work once, then die.  GDB
3535
     deletes any of these breakpoints as soon as your program stops
3536
     there.  Breakpoints set by the `tbreak' command start out in this
3537
     state.
3538
 
3539
   Except for a breakpoint set with `tbreak' (*note Setting
3540
Breakpoints: Set Breaks.), breakpoints that you set are initially
3541
enabled; subsequently, they become disabled or enabled only when you
3542
use one of the commands above.  (The command `until' can set and delete
3543
a breakpoint of its own, but it does not change the state of your other
3544
breakpoints; see *Note Continuing and Stepping: Continuing and
3545
Stepping.)
3546
 
3547

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

3650
File: gdb.info,  Node: Break Commands,  Next: Error in Breakpoints,  Prev: Conditions,  Up: Breakpoints
3651
 
3652
5.1.7 Breakpoint Command Lists
3653
------------------------------
3654
 
3655
You can give any breakpoint (or watchpoint or catchpoint) a series of
3656
commands to execute when your program stops due to that breakpoint.  For
3657
example, you might want to print the values of certain expressions, or
3658
enable other breakpoints.
3659
 
3660
`commands [BNUM]'
3661
`... COMMAND-LIST ...'
3662
`end'
3663
     Specify a list of commands for breakpoint number BNUM.  The
3664
     commands themselves appear on the following lines.  Type a line
3665
     containing just `end' to terminate the commands.
3666
 
3667
     To remove all commands from a breakpoint, type `commands' and
3668
     follow it immediately with `end'; that is, give no commands.
3669
 
3670
     With no BNUM argument, `commands' refers to the last breakpoint,
3671
     watchpoint, or catchpoint set (not to the breakpoint most recently
3672
     encountered).
3673
 
3674
   Pressing  as a means of repeating the last GDB command is
3675
disabled within a COMMAND-LIST.
3676
 
3677
   You can use breakpoint commands to start your program up again.
3678
Simply use the `continue' command, or `step', or any other command that
3679
resumes execution.
3680
 
3681
   Any other commands in the command list, after a command that resumes
3682
execution, are ignored.  This is because any time you resume execution
3683
(even with a simple `next' or `step'), you may encounter another
3684
breakpoint--which could have its own command list, leading to
3685
ambiguities about which list to execute.
3686
 
3687
   If the first command you specify in a command list is `silent', the
3688
usual message about stopping at a breakpoint is not printed.  This may
3689
be desirable for breakpoints that are to print a specific message and
3690
then continue.  If none of the remaining commands print anything, you
3691
see no sign that the breakpoint was reached.  `silent' is meaningful
3692
only at the beginning of a breakpoint command list.
3693
 
3694
   The commands `echo', `output', and `printf' allow you to print
3695
precisely controlled output, and are often useful in silent
3696
breakpoints.  *Note Commands for Controlled Output: Output.
3697
 
3698
   For example, here is how you could use breakpoint commands to print
3699
the value of `x' at entry to `foo' whenever `x' is positive.
3700
 
3701
     break foo if x>0
3702
     commands
3703
     silent
3704
     printf "x is %d\n",x
3705
     cont
3706
     end
3707
 
3708
   One application for breakpoint commands is to compensate for one bug
3709
so you can test for another.  Put a breakpoint just after the erroneous
3710
line of code, give it a condition to detect the case in which something
3711
erroneous has been done, and give it commands to assign correct values
3712
to any variables that need them.  End with the `continue' command so
3713
that your program does not stop, and start with the `silent' command so
3714
that no output is produced.  Here is an example:
3715
 
3716
     break 403
3717
     commands
3718
     silent
3719
     set x = y + 4
3720
     cont
3721
     end
3722
 
3723

3724
File: gdb.info,  Node: Error in Breakpoints,  Next: Breakpoint-related Warnings,  Prev: Break Commands,  Up: Breakpoints
3725
 
3726
5.1.8 "Cannot insert breakpoints"
3727
---------------------------------
3728
 
3729
If you request too many active hardware-assisted breakpoints and
3730
watchpoints, you will see this error message:
3731
 
3732
     Stopped; cannot insert breakpoints.
3733
     You may have requested too many hardware breakpoints and watchpoints.
3734
 
3735
This message is printed when you attempt to resume the program, since
3736
only then GDB knows exactly how many hardware breakpoints and
3737
watchpoints it needs to insert.
3738
 
3739
   When this message is printed, you need to disable or remove some of
3740
the hardware-assisted breakpoints and watchpoints, and then continue.
3741
 
3742

3743
File: gdb.info,  Node: Breakpoint-related Warnings,  Prev: Error in Breakpoints,  Up: Breakpoints
3744
 
3745
5.1.9 "Breakpoint address adjusted..."
3746
--------------------------------------
3747
 
3748
Some processor architectures place constraints on the addresses at
3749
which breakpoints may be placed.  For architectures thus constrained,
3750
GDB will attempt to adjust the breakpoint's address to comply with the
3751
constraints dictated by the architecture.
3752
 
3753
   One example of such an architecture is the Fujitsu FR-V.  The FR-V is
3754
a VLIW architecture in which a number of RISC-like instructions may be
3755
bundled together for parallel execution.  The FR-V architecture
3756
constrains the location of a breakpoint instruction within such a
3757
bundle to the instruction with the lowest address.  GDB honors this
3758
constraint by adjusting a breakpoint's address to the first in the
3759
bundle.
3760
 
3761
   It is not uncommon for optimized code to have bundles which contain
3762
instructions from different source statements, thus it may happen that
3763
a breakpoint's address will be adjusted from one source statement to
3764
another.  Since this adjustment may significantly alter GDB's
3765
breakpoint related behavior from what the user expects, a warning is
3766
printed when the breakpoint is first set and also when the breakpoint
3767
is hit.
3768
 
3769
   A warning like the one below is printed when setting a breakpoint
3770
that's been subject to address adjustment:
3771
 
3772
     warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3773
 
3774
   Such warnings are printed both for user settable and GDB's internal
3775
breakpoints.  If you see one of these warnings, you should verify that
3776
a breakpoint set at the adjusted address will have the desired affect.
3777
If not, the breakpoint in question may be removed and other breakpoints
3778
may be set which will have the desired behavior.  E.g., it may be
3779
sufficient to place the breakpoint at a later instruction.  A
3780
conditional breakpoint may also be useful in some cases to prevent the
3781
breakpoint from triggering too often.
3782
 
3783
   GDB will also issue a warning when stopping at one of these adjusted
3784
breakpoints:
3785
 
3786
     warning: Breakpoint 1 address previously adjusted from 0x00010414
3787
     to 0x00010410.
3788
 
3789
   When this warning is encountered, it may be too late to take remedial
3790
action except in cases where the breakpoint is hit earlier or more
3791
frequently than expected.
3792
 
3793

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

4005
File: gdb.info,  Node: Signals,  Next: Thread Stops,  Prev: Continuing and Stepping,  Up: Stopping
4006
 
4007
5.3 Signals
4008
===========
4009
 
4010
A signal is an asynchronous event that can happen in a program.  The
4011
operating system defines the possible kinds of signals, and gives each
4012
kind a name and a number.  For example, in Unix `SIGINT' is the signal
4013
a program gets when you type an interrupt character (often `Ctrl-c');
4014
`SIGSEGV' is the signal a program gets from referencing a place in
4015
memory far away from all the areas in use; `SIGALRM' occurs when the
4016
alarm clock timer goes off (which happens only if your program has
4017
requested an alarm).
4018
 
4019
   Some signals, including `SIGALRM', are a normal part of the
4020
functioning of your program.  Others, such as `SIGSEGV', indicate
4021
errors; these signals are "fatal" (they kill your program immediately)
4022
if the program has not specified in advance some other way to handle
4023
the signal.  `SIGINT' does not indicate an error in your program, but
4024
it is normally fatal so it can carry out the purpose of the interrupt:
4025
to kill the program.
4026
 
4027
   GDB has the ability to detect any occurrence of a signal in your
4028
program.  You can tell GDB in advance what to do for each kind of
4029
signal.
4030
 
4031
   Normally, GDB is set up to let the non-erroneous signals like
4032
`SIGALRM' be silently passed to your program (so as not to interfere
4033
with their role in the program's functioning) but to stop your program
4034
immediately whenever an error signal happens.  You can change these
4035
settings with the `handle' command.
4036
 
4037
`info signals'
4038
`info handle'
4039
     Print a table of all the kinds of signals and how GDB has been
4040
     told to handle each one.  You can use this to see the signal
4041
     numbers of all the defined types of signals.
4042
 
4043
`info signals SIG'
4044
     Similar, but print information only about the specified signal
4045
     number.
4046
 
4047
     `info handle' is an alias for `info signals'.
4048
 
4049
`handle SIGNAL [KEYWORDS...]'
4050
     Change the way GDB handles signal SIGNAL.  SIGNAL can be the
4051
     number of a signal or its name (with or without the `SIG' at the
4052
     beginning); a list of signal numbers of the form `LOW-HIGH'; or
4053
     the word `all', meaning all the known signals.  Optional arguments
4054
     KEYWORDS, described below, say what change to make.
4055
 
4056
   The keywords allowed by the `handle' command can be abbreviated.
4057
Their full names are:
4058
 
4059
`nostop'
4060
     GDB should not stop your program when this signal happens.  It may
4061
     still print a message telling you that the signal has come in.
4062
 
4063
`stop'
4064
     GDB should stop your program when this signal happens.  This
4065
     implies the `print' keyword as well.
4066
 
4067
`print'
4068
     GDB should print a message when this signal happens.
4069
 
4070
`noprint'
4071
     GDB should not mention the occurrence of the signal at all.  This
4072
     implies the `nostop' keyword as well.
4073
 
4074
`pass'
4075
`noignore'
4076
     GDB should allow your program to see this signal; your program can
4077
     handle the signal, or else it may terminate if the signal is fatal
4078
     and not handled.  `pass' and `noignore' are synonyms.
4079
 
4080
`nopass'
4081
`ignore'
4082
     GDB should not allow your program to see this signal.  `nopass'
4083
     and `ignore' are synonyms.
4084
 
4085
   When a signal stops your program, the signal is not visible to the
4086
program until you continue.  Your program sees the signal then, if
4087
`pass' is in effect for the signal in question _at that time_.  In
4088
other words, after GDB reports a signal, you can use the `handle'
4089
command with `pass' or `nopass' to control whether your program sees
4090
that signal when you continue.
4091
 
4092
   The default is set to `nostop', `noprint', `pass' for non-erroneous
4093
signals such as `SIGALRM', `SIGWINCH' and `SIGCHLD', and to `stop',
4094
`print', `pass' for the erroneous signals.
4095
 
4096
   You can also use the `signal' command to prevent your program from
4097
seeing a signal, or cause it to see a signal it normally would not see,
4098
or to give it any signal at any time.  For example, if your program
4099
stopped due to some sort of memory reference error, you might store
4100
correct values into the erroneous variables and continue, hoping to see
4101
more execution; but your program would probably terminate immediately as
4102
a result of the fatal signal once it saw the signal.  To prevent this,
4103
you can continue with `signal 0'.  *Note Giving your Program a Signal:
4104
Signaling.
4105
 
4106
   On some targets, GDB can inspect extra signal information associated
4107
with the intercepted signal, before it is actually delivered to the
4108
program being debugged.  This information is exported by the
4109
convenience variable `$_siginfo', and consists of data that is passed
4110
by the kernel to the signal handler at the time of the receipt of a
4111
signal.  The data type of the information itself is target dependent.
4112
You can see the data type using the `ptype $_siginfo' command.  On Unix
4113
systems, it typically corresponds to the standard `siginfo_t' type, as
4114
defined in the `signal.h' system header.
4115
 
4116
   Here's an example, on a GNU/Linux system, printing the stray
4117
referenced address that raised a segmentation fault.
4118
 
4119
     (gdb) continue
4120
     Program received signal SIGSEGV, Segmentation fault.
4121
     0x0000000000400766 in main ()
4122
     69        *(int *)p = 0;
4123
     (gdb) ptype $_siginfo
4124
     type = struct {
4125
         int si_signo;
4126
         int si_errno;
4127
         int si_code;
4128
         union {
4129
             int _pad[28];
4130
             struct {...} _kill;
4131
             struct {...} _timer;
4132
             struct {...} _rt;
4133
             struct {...} _sigchld;
4134
             struct {...} _sigfault;
4135
             struct {...} _sigpoll;
4136
         } _sifields;
4137
     }
4138
     (gdb) ptype $_siginfo._sifields._sigfault
4139
     type = struct {
4140
         void *si_addr;
4141
     }
4142
     (gdb) p $_siginfo._sifields._sigfault.si_addr
4143
     $1 = (void *) 0x7ffff7ff7000
4144
 
4145
   Depending on target support, `$_siginfo' may also be writable.
4146
 
4147

4148
File: gdb.info,  Node: Thread Stops,  Prev: Signals,  Up: Stopping
4149
 
4150
5.4 Stopping and Starting Multi-thread Programs
4151
===============================================
4152
 
4153
GDB supports debugging programs with multiple threads (*note Debugging
4154
Programs with Multiple Threads: Threads.).  There are two modes of
4155
controlling execution of your program within the debugger.  In the
4156
default mode, referred to as "all-stop mode", when any thread in your
4157
program stops (for example, at a breakpoint or while being stepped),
4158
all other threads in the program are also stopped by GDB.  On some
4159
targets, GDB also supports "non-stop mode", in which other threads can
4160
continue to run freely while you examine the stopped thread in the
4161
debugger.
4162
 
4163
* Menu:
4164
 
4165
* All-Stop Mode::               All threads stop when GDB takes control
4166
* Non-Stop Mode::               Other threads continue to execute
4167
* Background Execution::        Running your program asynchronously
4168
* Thread-Specific Breakpoints:: Controlling breakpoints
4169
* Interrupted System Calls::    GDB may interfere with system calls
4170
 
4171

4172
File: gdb.info,  Node: All-Stop Mode,  Next: Non-Stop Mode,  Up: Thread Stops
4173
 
4174
5.4.1 All-Stop Mode
4175
-------------------
4176
 
4177
In all-stop mode, whenever your program stops under GDB for any reason,
4178
_all_ threads of execution stop, not just the current thread.  This
4179
allows you to examine the overall state of the program, including
4180
switching between threads, without worrying that things may change
4181
underfoot.
4182
 
4183
   Conversely, whenever you restart the program, _all_ threads start
4184
executing.  _This is true even when single-stepping_ with commands like
4185
`step' or `next'.
4186
 
4187
   In particular, GDB cannot single-step all threads in lockstep.
4188
Since thread scheduling is up to your debugging target's operating
4189
system (not controlled by GDB), other threads may execute more than one
4190
statement while the current thread completes a single step.  Moreover,
4191
in general other threads stop in the middle of a statement, rather than
4192
at a clean statement boundary, when the program stops.
4193
 
4194
   You might even find your program stopped in another thread after
4195
continuing or even single-stepping.  This happens whenever some other
4196
thread runs into a breakpoint, a signal, or an exception before the
4197
first thread completes whatever you requested.
4198
 
4199
   Whenever GDB stops your program, due to a breakpoint or a signal, it
4200
automatically selects the thread where that breakpoint or signal
4201
happened.  GDB alerts you to the context switch with a message such as
4202
`[Switching to Thread N]' to identify the thread.
4203
 
4204
   On some OSes, you can modify GDB's default behavior by locking the
4205
OS scheduler to allow only a single thread to run.
4206
 
4207
`set scheduler-locking MODE'
4208
     Set the scheduler locking mode.  If it is `off', then there is no
4209
     locking and any thread may run at any time.  If `on', then only the
4210
     current thread may run when the inferior is resumed.  The `step'
4211
     mode optimizes for single-stepping; it prevents other threads from
4212
     preempting the current thread while you are stepping, so that the
4213
     focus of debugging does not change unexpectedly.  Other threads
4214
     only rarely (or never) get a chance to run when you step.  They
4215
     are more likely to run when you `next' over a function call, and
4216
     they are completely free to run when you use commands like
4217
     `continue', `until', or `finish'.  However, unless another thread
4218
     hits a breakpoint during its timeslice, GDB does not change the
4219
     current thread away from the thread that you are debugging.
4220
 
4221
`show scheduler-locking'
4222
     Display the current scheduler locking mode.
4223
 
4224
   By default, when you issue one of the execution commands such as
4225
`continue', `next' or `step', GDB allows only threads of the current
4226
inferior to run.  For example, if GDB is attached to two inferiors,
4227
each with two threads, the `continue' command resumes only the two
4228
threads of the current inferior.  This is useful, for example, when you
4229
debug a program that forks and you want to hold the parent stopped (so
4230
that, for instance, it doesn't run to exit), while you debug the child.
4231
In other situations, you may not be interested in inspecting the
4232
current state of any of the processes GDB is attached to, and you may
4233
want to resume them all until some breakpoint is hit.  In the latter
4234
case, you can instruct GDB to allow all threads of all the inferiors to
4235
run with the `set schedule-multiple' command.
4236
 
4237
`set schedule-multiple'
4238
     Set the mode for allowing threads of multiple processes to be
4239
     resumed when an execution command is issued.  When `on', all
4240
     threads of all processes are allowed to run.  When `off', only the
4241
     threads of the current process are resumed.  The default is `off'.
4242
     The `scheduler-locking' mode takes precedence when set to `on',
4243
     or while you are stepping and set to `step'.
4244
 
4245
`show schedule-multiple'
4246
     Display the current mode for resuming the execution of threads of
4247
     multiple processes.
4248
 
4249

4250
File: gdb.info,  Node: Non-Stop Mode,  Next: Background Execution,  Prev: All-Stop Mode,  Up: Thread Stops
4251
 
4252
5.4.2 Non-Stop Mode
4253
-------------------
4254
 
4255
For some multi-threaded targets, GDB supports an optional mode of
4256
operation in which you can examine stopped program threads in the
4257
debugger while other threads continue to execute freely.  This
4258
minimizes intrusion when debugging live systems, such as programs where
4259
some threads have real-time constraints or must continue to respond to
4260
external events.  This is referred to as "non-stop" mode.
4261
 
4262
   In non-stop mode, when a thread stops to report a debugging event,
4263
_only_ that thread is stopped; GDB does not stop other threads as well,
4264
in contrast to the all-stop mode behavior.  Additionally, execution
4265
commands such as `continue' and `step' apply by default only to the
4266
current thread in non-stop mode, rather than all threads as in all-stop
4267
mode.  This allows you to control threads explicitly in ways that are
4268
not possible in all-stop mode -- for example, stepping one thread while
4269
allowing others to run freely, stepping one thread while holding all
4270
others stopped, or stepping several threads independently and
4271
simultaneously.
4272
 
4273
   To enter non-stop mode, use this sequence of commands before you run
4274
or attach to your program:
4275
 
4276
     # Enable the async interface.
4277
     set target-async 1
4278
 
4279
     # If using the CLI, pagination breaks non-stop.
4280
     set pagination off
4281
 
4282
     # Finally, turn it on!
4283
     set non-stop on
4284
 
4285
   You can use these commands to manipulate the non-stop mode setting:
4286
 
4287
`set non-stop on'
4288
     Enable selection of non-stop mode.
4289
 
4290
`set non-stop off'
4291
     Disable selection of non-stop mode.
4292
 
4293
`show non-stop'
4294
     Show the current non-stop enablement setting.
4295
 
4296
   Note these commands only reflect whether non-stop mode is enabled,
4297
not whether the currently-executing program is being run in non-stop
4298
mode.  In particular, the `set non-stop' preference is only consulted
4299
when GDB starts or connects to the target program, and it is generally
4300
not possible to switch modes once debugging has started.  Furthermore,
4301
since not all targets support non-stop mode, even when you have enabled
4302
non-stop mode, GDB may still fall back to all-stop operation by default.
4303
 
4304
   In non-stop mode, all execution commands apply only to the current
4305
thread by default.  That is, `continue' only continues one thread.  To
4306
continue all threads, issue `continue -a' or `c -a'.
4307
 
4308
   You can use GDB's background execution commands (*note Background
4309
Execution::) to run some threads in the background while you continue
4310
to examine or step others from GDB.  The MI execution commands (*note
4311
GDB/MI Program Execution::) are always executed asynchronously in
4312
non-stop mode.
4313
 
4314
   Suspending execution is done with the `interrupt' command when
4315
running in the background, or `Ctrl-c' during foreground execution.  In
4316
all-stop mode, this stops the whole process; but in non-stop mode the
4317
interrupt applies only to the current thread.  To stop the whole
4318
program, use `interrupt -a'.
4319
 
4320
   Other execution commands do not currently support the `-a' option.
4321
 
4322
   In non-stop mode, when a thread stops, GDB doesn't automatically make
4323
that thread current, as it does in all-stop mode.  This is because the
4324
thread stop notifications are asynchronous with respect to GDB's
4325
command interpreter, and it would be confusing if GDB unexpectedly
4326
changed to a different thread just as you entered a command to operate
4327
on the previously current thread.
4328
 
4329

4330
File: gdb.info,  Node: Background Execution,  Next: Thread-Specific Breakpoints,  Prev: Non-Stop Mode,  Up: Thread Stops
4331
 
4332
5.4.3 Background Execution
4333
--------------------------
4334
 
4335
GDB's execution commands have two variants:  the normal foreground
4336
(synchronous) behavior, and a background (asynchronous) behavior.  In
4337
foreground execution, GDB waits for the program to report that some
4338
thread has stopped before prompting for another command.  In background
4339
execution, GDB immediately gives a command prompt so that you can issue
4340
other commands while your program runs.
4341
 
4342
   You need to explicitly enable asynchronous mode before you can use
4343
background execution commands.  You can use these commands to
4344
manipulate the asynchronous mode setting:
4345
 
4346
`set target-async on'
4347
     Enable asynchronous mode.
4348
 
4349
`set target-async off'
4350
     Disable asynchronous mode.
4351
 
4352
`show target-async'
4353
     Show the current target-async setting.
4354
 
4355
   If the target doesn't support async mode, GDB issues an error
4356
message if you attempt to use the background execution commands.
4357
 
4358
   To specify background execution, add a `&' to the command.  For
4359
example, the background form of the `continue' command is `continue&',
4360
or just `c&'.  The execution commands that accept background execution
4361
are:
4362
 
4363
`run'
4364
     *Note Starting your Program: Starting.
4365
 
4366
`attach'
4367
     *Note Debugging an Already-running Process: Attach.
4368
 
4369
`step'
4370
     *Note step: Continuing and Stepping.
4371
 
4372
`stepi'
4373
     *Note stepi: Continuing and Stepping.
4374
 
4375
`next'
4376
     *Note next: Continuing and Stepping.
4377
 
4378
`nexti'
4379
     *Note nexti: Continuing and Stepping.
4380
 
4381
`continue'
4382
     *Note continue: Continuing and Stepping.
4383
 
4384
`finish'
4385
     *Note finish: Continuing and Stepping.
4386
 
4387
`until'
4388
     *Note until: Continuing and Stepping.
4389
 
4390
 
4391
   Background execution is especially useful in conjunction with
4392
non-stop mode for debugging programs with multiple threads; see *Note
4393
Non-Stop Mode::.  However, you can also use these commands in the
4394
normal all-stop mode with the restriction that you cannot issue another
4395
execution command until the previous one finishes.  Examples of
4396
commands that are valid in all-stop mode while the program is running
4397
include `help' and `info break'.
4398
 
4399
   You can interrupt your program while it is running in the background
4400
by using the `interrupt' command.
4401
 
4402
`interrupt'
4403
`interrupt -a'
4404
     Suspend execution of the running program.  In all-stop mode,
4405
     `interrupt' stops the whole process, but in non-stop mode, it stops
4406
     only the current thread.  To stop the whole program in non-stop
4407
     mode, use `interrupt -a'.
4408
 
4409

4410
File: gdb.info,  Node: Thread-Specific Breakpoints,  Next: Interrupted System Calls,  Prev: Background Execution,  Up: Thread Stops
4411
 
4412
5.4.4 Thread-Specific Breakpoints
4413
---------------------------------
4414
 
4415
When your program has multiple threads (*note Debugging Programs with
4416
Multiple Threads: Threads.), you can choose whether to set breakpoints
4417
on all threads, or on a particular thread.
4418
 
4419
`break LINESPEC thread THREADNO'
4420
`break LINESPEC thread THREADNO if ...'
4421
     LINESPEC specifies source lines; there are several ways of writing
4422
     them (*note Specify Location::), but the effect is always to
4423
     specify some source line.
4424
 
4425
     Use the qualifier `thread THREADNO' with a breakpoint command to
4426
     specify that you only want GDB to stop the program when a
4427
     particular thread reaches this breakpoint.  THREADNO is one of the
4428
     numeric thread identifiers assigned by GDB, shown in the first
4429
     column of the `info threads' display.
4430
 
4431
     If you do not specify `thread THREADNO' when you set a breakpoint,
4432
     the breakpoint applies to _all_ threads of your program.
4433
 
4434
     You can use the `thread' qualifier on conditional breakpoints as
4435
     well; in this case, place `thread THREADNO' before or after the
4436
     breakpoint condition, like this:
4437
 
4438
          (gdb) break frik.c:13 thread 28 if bartab > lim
4439
 
4440
 
4441

4442
File: gdb.info,  Node: Interrupted System Calls,  Prev: Thread-Specific Breakpoints,  Up: Thread Stops
4443
 
4444
5.4.5 Interrupted System Calls
4445
------------------------------
4446
 
4447
There is an unfortunate side effect when using GDB to debug
4448
multi-threaded programs.  If one thread stops for a breakpoint, or for
4449
some other reason, and another thread is blocked in a system call, then
4450
the system call may return prematurely.  This is a consequence of the
4451
interaction between multiple threads and the signals that GDB uses to
4452
implement breakpoints and other events that stop execution.
4453
 
4454
   To handle this problem, your program should check the return value of
4455
each system call and react appropriately.  This is good programming
4456
style anyways.
4457
 
4458
   For example, do not write code like this:
4459
 
4460
       sleep (10);
4461
 
4462
   The call to `sleep' will return early if a different thread stops at
4463
a breakpoint or for some other reason.
4464
 
4465
   Instead, write this:
4466
 
4467
       int unslept = 10;
4468
       while (unslept > 0)
4469
         unslept = sleep (unslept);
4470
 
4471
   A system call is allowed to return early, so the system is still
4472
conforming to its specification.  But GDB does cause your
4473
multi-threaded program to behave differently than it would without GDB.
4474
 
4475
   Also, GDB uses internal breakpoints in the thread library to monitor
4476
certain events such as thread creation and thread destruction.  When
4477
such an event happens, a system call in another thread may return
4478
prematurely, even though your program does not appear to stop.
4479
 
4480

4481
File: gdb.info,  Node: Reverse Execution,  Next: Process Record and Replay,  Prev: Stopping,  Up: Top
4482
 
4483
6 Running programs backward
4484
***************************
4485
 
4486
When you are debugging a program, it is not unusual to realize that you
4487
have gone too far, and some event of interest has already happened.  If
4488
the target environment supports it, GDB can allow you to "rewind" the
4489
program by running it backward.
4490
 
4491
   A target environment that supports reverse execution should be able
4492
to "undo" the changes in machine state that have taken place as the
4493
program was executing normally.  Variables, registers etc. should
4494
revert to their previous values.  Obviously this requires a great deal
4495
of sophistication on the part of the target environment; not all target
4496
environments can support reverse execution.
4497
 
4498
   When a program is executed in reverse, the instructions that have
4499
most recently been executed are "un-executed", in reverse order.  The
4500
program counter runs backward, following the previous thread of
4501
execution in reverse.  As each instruction is "un-executed", the values
4502
of memory and/or registers that were changed by that instruction are
4503
reverted to their previous states.  After executing a piece of source
4504
code in reverse, all side effects of that code should be "undone", and
4505
all variables should be returned to their prior values(1).
4506
 
4507
   If you are debugging in a target environment that supports reverse
4508
execution, GDB provides the following commands.
4509
 
4510
`reverse-continue [IGNORE-COUNT]'
4511
`rc [IGNORE-COUNT]'
4512
     Beginning at the point where your program last stopped, start
4513
     executing in reverse.  Reverse execution will stop for breakpoints
4514
     and synchronous exceptions (signals), just like normal execution.
4515
     Behavior of asynchronous signals depends on the target environment.
4516
 
4517
`reverse-step [COUNT]'
4518
     Run the program backward until control reaches the start of a
4519
     different source line; then stop it, and return control to GDB.
4520
 
4521
     Like the `step' command, `reverse-step' will only stop at the
4522
     beginning of a source line.  It "un-executes" the previously
4523
     executed source line.  If the previous source line included calls
4524
     to debuggable functions, `reverse-step' will step (backward) into
4525
     the called function, stopping at the beginning of the _last_
4526
     statement in the called function (typically a return statement).
4527
 
4528
     Also, as with the `step' command, if non-debuggable functions are
4529
     called, `reverse-step' will run thru them backward without
4530
     stopping.
4531
 
4532
`reverse-stepi [COUNT]'
4533
     Reverse-execute one machine instruction.  Note that the instruction
4534
     to be reverse-executed is _not_ the one pointed to by the program
4535
     counter, but the instruction executed prior to that one.  For
4536
     instance, if the last instruction was a jump, `reverse-stepi' will
4537
     take you back from the destination of the jump to the jump
4538
     instruction itself.
4539
 
4540
`reverse-next [COUNT]'
4541
     Run backward to the beginning of the previous line executed in the
4542
     current (innermost) stack frame.  If the line contains function
4543
     calls, they will be "un-executed" without stopping.  Starting from
4544
     the first line of a function, `reverse-next' will take you back to
4545
     the caller of that function, _before_ the function was called,
4546
     just as the normal `next' command would take you from the last
4547
     line of a function back to its return to its caller (2).
4548
 
4549
`reverse-nexti [COUNT]'
4550
     Like `nexti', `reverse-nexti' executes a single instruction in
4551
     reverse, except that called functions are "un-executed" atomically.
4552
     That is, if the previously executed instruction was a return from
4553
     another function, `reverse-nexti' will continue to execute in
4554
     reverse until the call to that function (from the current stack
4555
     frame) is reached.
4556
 
4557
`reverse-finish'
4558
     Just as the `finish' command takes you to the point where the
4559
     current function returns, `reverse-finish' takes you to the point
4560
     where it was called.  Instead of ending up at the end of the
4561
     current function invocation, you end up at the beginning.
4562
 
4563
`set exec-direction'
4564
     Set the direction of target execution.
4565
 
4566
`set exec-direction reverse'
4567
     GDB will perform all execution commands in reverse, until the
4568
     exec-direction mode is changed to "forward".  Affected commands
4569
     include `step, stepi, next, nexti, continue, and finish'.  The
4570
     `return' command cannot be used in reverse mode.
4571
 
4572
`set exec-direction forward'
4573
     GDB will perform all execution commands in the normal fashion.
4574
     This is the default.
4575
 
4576
   ---------- Footnotes ----------
4577
 
4578
   (1) Note that some side effects are easier to undo than others.  For
4579
instance, memory and registers are relatively easy, but device I/O is
4580
hard.  Some targets may be able undo things like device I/O, and some
4581
may not.
4582
 
4583
   The contract between GDB and the reverse executing target requires
4584
only that the target do something reasonable when GDB tells it to
4585
execute backwards, and then report the results back to GDB.  Whatever
4586
the target reports back to GDB, GDB will report back to the user.  GDB
4587
assumes that the memory and registers that the target reports are in a
4588
consistant state, but GDB accepts whatever it is given.
4589
 
4590
   (2) Unless the code is too heavily optimized.
4591
 
4592

4593
File: gdb.info,  Node: Process Record and Replay,  Next: Stack,  Prev: Reverse Execution,  Up: Top
4594
 
4595
7 Recording Inferior's Execution and Replaying It
4596
*************************************************
4597
 
4598
On some platforms, GDB provides a special "process record and replay"
4599
target that can record a log of the process execution, and replay it
4600
later with both forward and reverse execution commands.
4601
 
4602
   When this target is in use, if the execution log includes the record
4603
for the next instruction, GDB will debug in "replay mode".  In the
4604
replay mode, the inferior does not really execute code instructions.
4605
Instead, all the events that normally happen during code execution are
4606
taken from the execution log.  While code is not really executed in
4607
replay mode, the values of registers (including the program counter
4608
register) and the memory of the inferior are still changed as they
4609
normally would.  Their contents are taken from the execution log.
4610
 
4611
   If the record for the next instruction is not in the execution log,
4612
GDB will debug in "record mode".  In this mode, the inferior executes
4613
normally, and GDB records the execution log for future replay.
4614
 
4615
   The process record and replay target supports reverse execution
4616
(*note Reverse Execution::), even if the platform on which the inferior
4617
runs does not.  However, the reverse execution is limited in this case
4618
by the range of the instructions recorded in the execution log.  In
4619
other words, reverse execution on platforms that don't support it
4620
directly can only be done in the replay mode.
4621
 
4622
   When debugging in the reverse direction, GDB will work in replay
4623
mode as long as the execution log includes the record for the previous
4624
instruction; otherwise, it will work in record mode, if the platform
4625
supports reverse execution, or stop if not.
4626
 
4627
   For architecture environments that support process record and replay,
4628
GDB provides the following commands:
4629
 
4630
`target record'
4631
     This command starts the process record and replay target.  The
4632
     process record and replay target can only debug a process that is
4633
     already running.  Therefore, you need first to start the process
4634
     with the `run' or `start' commands, and then start the recording
4635
     with the `target record' command.
4636
 
4637
     Both `record' and `rec' are aliases of `target record'.
4638
 
4639
     Displaced stepping (*note displaced stepping: Maintenance
4640
     Commands.)  will be automatically disabled when process record and
4641
     replay target is started.  That's because the process record and
4642
     replay target doesn't support displaced stepping.
4643
 
4644
     If the inferior is in the non-stop mode (*note Non-Stop Mode::) or
4645
     in the asynchronous execution mode (*note Background Execution::),
4646
     the process record and replay target cannot be started because it
4647
     doesn't support these two modes.
4648
 
4649
`record stop'
4650
     Stop the process record and replay target.  When process record and
4651
     replay target stops, the entire execution log will be deleted and
4652
     the inferior will either be terminated, or will remain in its
4653
     final state.
4654
 
4655
     When you stop the process record and replay target in record mode
4656
     (at the end of the execution log), the inferior will be stopped at
4657
     the next instruction that would have been recorded.  In other
4658
     words, if you record for a while and then stop recording, the
4659
     inferior process will be left in the same state as if the
4660
     recording never happened.
4661
 
4662
     On the other hand, if the process record and replay target is
4663
     stopped while in replay mode (that is, not at the end of the
4664
     execution log, but at some earlier point), the inferior process
4665
     will become "live" at that earlier state, and it will then be
4666
     possible to continue the usual "live" debugging of the process
4667
     from that state.
4668
 
4669
     When the inferior process exits, or GDB detaches from it, process
4670
     record and replay target will automatically stop itself.
4671
 
4672
`set record insn-number-max LIMIT'
4673
     Set the limit of instructions to be recorded.  Default value is
4674
     200000.
4675
 
4676
     If LIMIT is a positive number, then GDB will start deleting
4677
     instructions from the log once the number of the record
4678
     instructions becomes greater than LIMIT.  For every new recorded
4679
     instruction, GDB will delete the earliest recorded instruction to
4680
     keep the number of recorded instructions at the limit.  (Since
4681
     deleting recorded instructions loses information, GDB lets you
4682
     control what happens when the limit is reached, by means of the
4683
     `stop-at-limit' option, described below.)
4684
 
4685
     If LIMIT is zero, GDB will never delete recorded instructions from
4686
     the execution log.  The number of recorded instructions is
4687
     unlimited in this case.
4688
 
4689
`show record insn-number-max'
4690
     Show the limit of instructions to be recorded.
4691
 
4692
`set record stop-at-limit'
4693
     Control the behavior when the number of recorded instructions
4694
     reaches the limit.  If ON (the default), GDB will stop when the
4695
     limit is reached for the first time and ask you whether you want
4696
     to stop the inferior or continue running it and recording the
4697
     execution log.  If you decide to continue recording, each new
4698
     recorded instruction will cause the oldest one to be deleted.
4699
 
4700
     If this option is OFF, GDB will automatically delete the oldest
4701
     record to make room for each new one, without asking.
4702
 
4703
`show record stop-at-limit'
4704
     Show the current setting of `stop-at-limit'.
4705
 
4706
`info record'
4707
     Show various statistics about the state of process record and its
4708
     in-memory execution log buffer, including:
4709
 
4710
        * Whether in record mode or replay mode.
4711
 
4712
        * Lowest recorded instruction number (counting from when the
4713
          current execution log started recording instructions).
4714
 
4715
        * Highest recorded instruction number.
4716
 
4717
        * Current instruction about to be replayed (if in replay mode).
4718
 
4719
        * Number of instructions contained in the execution log.
4720
 
4721
        * Maximum number of instructions that may be contained in the
4722
          execution log.
4723
 
4724
`record delete'
4725
     When record target runs in replay mode ("in the past"), delete the
4726
     subsequent execution log and begin to record a new execution log
4727
     starting from the current address.  This means you will abandon
4728
     the previously recorded "future" and begin recording a new
4729
     "future".
4730
 
4731

4732
File: gdb.info,  Node: Stack,  Next: Source,  Prev: Process Record and Replay,  Up: Top
4733
 
4734
8 Examining the Stack
4735
*********************
4736
 
4737
When your program has stopped, the first thing you need to know is
4738
where it stopped and how it got there.
4739
 
4740
   Each time your program performs a function call, information about
4741
the call is generated.  That information includes the location of the
4742
call in your program, the arguments of the call, and the local
4743
variables of the function being called.  The information is saved in a
4744
block of data called a "stack frame".  The stack frames are allocated
4745
in a region of memory called the "call stack".
4746
 
4747
   When your program stops, the GDB commands for examining the stack
4748
allow you to see all of this information.
4749
 
4750
   One of the stack frames is "selected" by GDB and many GDB commands
4751
refer implicitly to the selected frame.  In particular, whenever you
4752
ask GDB for the value of a variable in your program, the value is found
4753
in the selected frame.  There are special GDB commands to select
4754
whichever frame you are interested in.  *Note Selecting a Frame:
4755
Selection.
4756
 
4757
   When your program stops, GDB automatically selects the currently
4758
executing frame and describes it briefly, similar to the `frame'
4759
command (*note Information about a Frame: Frame Info.).
4760
 
4761
* Menu:
4762
 
4763
* Frames::                      Stack frames
4764
* Backtrace::                   Backtraces
4765
* Selection::                   Selecting a frame
4766
* Frame Info::                  Information on a frame
4767
 
4768

4769
File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
4770
 
4771
8.1 Stack Frames
4772
================
4773
 
4774
The call stack is divided up into contiguous pieces called "stack
4775
frames", or "frames" for short; each frame is the data associated with
4776
one call to one function.  The frame contains the arguments given to
4777
the function, the function's local variables, and the address at which
4778
the function is executing.
4779
 
4780
   When your program is started, the stack has only one frame, that of
4781
the function `main'.  This is called the "initial" frame or the
4782
"outermost" frame.  Each time a function is called, a new frame is
4783
made.  Each time a function returns, the frame for that function
4784
invocation is eliminated.  If a function is recursive, there can be
4785
many frames for the same function.  The frame for the function in which
4786
execution is actually occurring is called the "innermost" frame.  This
4787
is the most recently created of all the stack frames that still exist.
4788
 
4789
   Inside your program, stack frames are identified by their addresses.
4790
A stack frame consists of many bytes, each of which has its own
4791
address; each kind of computer has a convention for choosing one byte
4792
whose address serves as the address of the frame.  Usually this address
4793
is kept in a register called the "frame pointer register" (*note $fp:
4794
Registers.) while execution is going on in that frame.
4795
 
4796
   GDB assigns numbers to all existing stack frames, starting with zero
4797
for the innermost frame, one for the frame that called it, and so on
4798
upward.  These numbers do not really exist in your program; they are
4799
assigned by GDB to give you a way of designating stack frames in GDB
4800
commands.
4801
 
4802
   Some compilers provide a way to compile functions so that they
4803
operate without stack frames.  (For example, the GCC option
4804
     `-fomit-frame-pointer'
4805
   generates functions without a frame.)  This is occasionally done
4806
with heavily used library functions to save the frame setup time.  GDB
4807
has limited facilities for dealing with these function invocations.  If
4808
the innermost function invocation has no stack frame, GDB nevertheless
4809
regards it as though it had a separate frame, which is numbered zero as
4810
usual, allowing correct tracing of the function call chain.  However,
4811
GDB has no provision for frameless functions elsewhere in the stack.
4812
 
4813
`frame ARGS'
4814
     The `frame' command allows you to move from one stack frame to
4815
     another, and to print the stack frame you select.  ARGS may be
4816
     either the address of the frame or the stack frame number.
4817
     Without an argument, `frame' prints the current stack frame.
4818
 
4819
`select-frame'
4820
     The `select-frame' command allows you to move from one stack frame
4821
     to another without printing the frame.  This is the silent version
4822
     of `frame'.
4823
 
4824

4825
File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
4826
 
4827
8.2 Backtraces
4828
==============
4829
 
4830
A backtrace is a summary of how your program got where it is.  It shows
4831
one line per frame, for many frames, starting with the currently
4832
executing frame (frame zero), followed by its caller (frame one), and
4833
on up the stack.
4834
 
4835
`backtrace'
4836
`bt'
4837
     Print a backtrace of the entire stack: one line per frame for all
4838
     frames in the stack.
4839
 
4840
     You can stop the backtrace at any time by typing the system
4841
     interrupt character, normally `Ctrl-c'.
4842
 
4843
`backtrace N'
4844
`bt N'
4845
     Similar, but print only the innermost N frames.
4846
 
4847
`backtrace -N'
4848
`bt -N'
4849
     Similar, but print only the outermost N frames.
4850
 
4851
`backtrace full'
4852
`bt full'
4853
`bt full N'
4854
`bt full -N'
4855
     Print the values of the local variables also.  N specifies the
4856
     number of frames to print, as described above.
4857
 
4858
   The names `where' and `info stack' (abbreviated `info s') are
4859
additional aliases for `backtrace'.
4860
 
4861
   In a multi-threaded program, GDB by default shows the backtrace only
4862
for the current thread.  To display the backtrace for several or all of
4863
the threads, use the command `thread apply' (*note thread apply:
4864
Threads.).  For example, if you type `thread apply all backtrace', GDB
4865
will display the backtrace for all the threads; this is handy when you
4866
debug a core dump of a multi-threaded program.
4867
 
4868
   Each line in the backtrace shows the frame number and the function
4869
name.  The program counter value is also shown--unless you use `set
4870
print address off'.  The backtrace also shows the source file name and
4871
line number, as well as the arguments to the function.  The program
4872
counter value is omitted if it is at the beginning of the code for that
4873
line number.
4874
 
4875
   Here is an example of a backtrace.  It was made with the command `bt
4876
3', so it shows the innermost three frames.
4877
 
4878
     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4879
         at builtin.c:993
4880
     #1  0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
4881
     #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4882
         at macro.c:71
4883
     (More stack frames follow...)
4884
 
4885
The display for frame zero does not begin with a program counter value,
4886
indicating that your program has stopped at the beginning of the code
4887
for line `993' of `builtin.c'.
4888
 
4889
The value of parameter `data' in frame 1 has been replaced by `...'.
4890
By default, GDB prints the value of a parameter only if it is a scalar
4891
(integer, pointer, enumeration, etc).  See command `set print
4892
frame-arguments' in *Note Print Settings:: for more details on how to
4893
configure the way function parameter values are printed.
4894
 
4895
   If your program was compiled with optimizations, some compilers will
4896
optimize away arguments passed to functions if those arguments are
4897
never used after the call.  Such optimizations generate code that
4898
passes arguments through registers, but doesn't store those arguments
4899
in the stack frame.  GDB has no way of displaying such arguments in
4900
stack frames other than the innermost one.  Here's what such a
4901
backtrace might look like:
4902
 
4903
     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4904
         at builtin.c:993
4905
     #1  0x6e38 in expand_macro (sym=) at macro.c:242
4906
     #2  0x6840 in expand_token (obs=0x0, t=, td=0xf7fffb08)
4907
         at macro.c:71
4908
     (More stack frames follow...)
4909
 
4910
The values of arguments that were not saved in their stack frames are
4911
shown as `'.
4912
 
4913
   If you need to display the values of such optimized-out arguments,
4914
either deduce that from other variables whose values depend on the one
4915
you are interested in, or recompile without optimizations.
4916
 
4917
   Most programs have a standard user entry point--a place where system
4918
libraries and startup code transition into user code.  For C this is
4919
`main'(1).  When GDB finds the entry function in a backtrace it will
4920
terminate the backtrace, to avoid tracing into highly system-specific
4921
(and generally uninteresting) code.
4922
 
4923
   If you need to examine the startup code, or limit the number of
4924
levels in a backtrace, you can change this behavior:
4925
 
4926
`set backtrace past-main'
4927
`set backtrace past-main on'
4928
     Backtraces will continue past the user entry point.
4929
 
4930
`set backtrace past-main off'
4931
     Backtraces will stop when they encounter the user entry point.
4932
     This is the default.
4933
 
4934
`show backtrace past-main'
4935
     Display the current user entry point backtrace policy.
4936
 
4937
`set backtrace past-entry'
4938
`set backtrace past-entry on'
4939
     Backtraces will continue past the internal entry point of an
4940
     application.  This entry point is encoded by the linker when the
4941
     application is built, and is likely before the user entry point
4942
     `main' (or equivalent) is called.
4943
 
4944
`set backtrace past-entry off'
4945
     Backtraces will stop when they encounter the internal entry point
4946
     of an application.  This is the default.
4947
 
4948
`show backtrace past-entry'
4949
     Display the current internal entry point backtrace policy.
4950
 
4951
`set backtrace limit N'
4952
`set backtrace limit 0'
4953
     Limit the backtrace to N levels.  A value of zero means unlimited.
4954
 
4955
`show backtrace limit'
4956
     Display the current limit on backtrace levels.
4957
 
4958
   ---------- Footnotes ----------
4959
 
4960
   (1) Note that embedded programs (the so-called "free-standing"
4961
environment) are not required to have a `main' function as the entry
4962
point.  They could even have multiple entry points.
4963
 
4964

4965
File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
4966
 
4967
8.3 Selecting a Frame
4968
=====================
4969
 
4970
Most commands for examining the stack and other data in your program
4971
work on whichever stack frame is selected at the moment.  Here are the
4972
commands for selecting a stack frame; all of them finish by printing a
4973
brief description of the stack frame just selected.
4974
 
4975
`frame N'
4976
`f N'
4977
     Select frame number N.  Recall that frame zero is the innermost
4978
     (currently executing) frame, frame one is the frame that called the
4979
     innermost one, and so on.  The highest-numbered frame is the one
4980
     for `main'.
4981
 
4982
`frame ADDR'
4983
`f ADDR'
4984
     Select the frame at address ADDR.  This is useful mainly if the
4985
     chaining of stack frames has been damaged by a bug, making it
4986
     impossible for GDB to assign numbers properly to all frames.  In
4987
     addition, this can be useful when your program has multiple stacks
4988
     and switches between them.
4989
 
4990
     On the SPARC architecture, `frame' needs two addresses to select
4991
     an arbitrary frame: a frame pointer and a stack pointer.
4992
 
4993
     On the MIPS and Alpha architecture, it needs two addresses: a stack
4994
     pointer and a program counter.
4995
 
4996
     On the 29k architecture, it needs three addresses: a register stack
4997
     pointer, a program counter, and a memory stack pointer.
4998
 
4999
`up N'
5000
     Move N frames up the stack.  For positive numbers N, this advances
5001
     toward the outermost frame, to higher frame numbers, to frames
5002
     that have existed longer.  N defaults to one.
5003
 
5004
`down N'
5005
     Move N frames down the stack.  For positive numbers N, this
5006
     advances toward the innermost frame, to lower frame numbers, to
5007
     frames that were created more recently.  N defaults to one.  You
5008
     may abbreviate `down' as `do'.
5009
 
5010
   All of these commands end by printing two lines of output describing
5011
the frame.  The first line shows the frame number, the function name,
5012
the arguments, and the source file and line number of execution in that
5013
frame.  The second line shows the text of that source line.
5014
 
5015
   For example:
5016
 
5017
     (gdb) up
5018
     #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
5019
         at env.c:10
5020
     10              read_input_file (argv[i]);
5021
 
5022
   After such a printout, the `list' command with no arguments prints
5023
ten lines centered on the point of execution in the frame.  You can
5024
also edit the program at the point of execution with your favorite
5025
editing program by typing `edit'.  *Note Printing Source Lines: List,
5026
for details.
5027
 
5028
`up-silently N'
5029
`down-silently N'
5030
     These two commands are variants of `up' and `down', respectively;
5031
     they differ in that they do their work silently, without causing
5032
     display of the new frame.  They are intended primarily for use in
5033
     GDB command scripts, where the output might be unnecessary and
5034
     distracting.
5035
 
5036

5037
File: gdb.info,  Node: Frame Info,  Prev: Selection,  Up: Stack
5038
 
5039
8.4 Information About a Frame
5040
=============================
5041
 
5042
There are several other commands to print information about the selected
5043
stack frame.
5044
 
5045
`frame'
5046
`f'
5047
     When used without any argument, this command does not change which
5048
     frame is selected, but prints a brief description of the currently
5049
     selected stack frame.  It can be abbreviated `f'.  With an
5050
     argument, this command is used to select a stack frame.  *Note
5051
     Selecting a Frame: Selection.
5052
 
5053
`info frame'
5054
`info f'
5055
     This command prints a verbose description of the selected stack
5056
     frame, including:
5057
 
5058
        * the address of the frame
5059
 
5060
        * the address of the next frame down (called by this frame)
5061
 
5062
        * the address of the next frame up (caller of this frame)
5063
 
5064
        * the language in which the source code corresponding to this
5065
          frame is written
5066
 
5067
        * the address of the frame's arguments
5068
 
5069
        * the address of the frame's local variables
5070
 
5071
        * the program counter saved in it (the address of execution in
5072
          the caller frame)
5073
 
5074
        * which registers were saved in the frame
5075
 
5076
     The verbose description is useful when something has gone wrong
5077
     that has made the stack format fail to fit the usual conventions.
5078
 
5079
`info frame ADDR'
5080
`info f ADDR'
5081
     Print a verbose description of the frame at address ADDR, without
5082
     selecting that frame.  The selected frame remains unchanged by this
5083
     command.  This requires the same kind of address (more than one
5084
     for some architectures) that you specify in the `frame' command.
5085
     *Note Selecting a Frame: Selection.
5086
 
5087
`info args'
5088
     Print the arguments of the selected frame, each on a separate line.
5089
 
5090
`info locals'
5091
     Print the local variables of the selected frame, each on a separate
5092
     line.  These are all variables (declared either static or
5093
     automatic) accessible at the point of execution of the selected
5094
     frame.
5095
 
5096
`info catch'
5097
     Print a list of all the exception handlers that are active in the
5098
     current stack frame at the current point of execution.  To see
5099
     other exception handlers, visit the associated frame (using the
5100
     `up', `down', or `frame' commands); then type `info catch'.  *Note
5101
     Setting Catchpoints: Set Catchpoints.
5102
 
5103
 
5104

5105
File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
5106
 
5107
9 Examining Source Files
5108
************************
5109
 
5110
GDB can print parts of your program's source, since the debugging
5111
information recorded in the program tells GDB what source files were
5112
used to build it.  When your program stops, GDB spontaneously prints
5113
the line where it stopped.  Likewise, when you select a stack frame
5114
(*note Selecting a Frame: Selection.), GDB prints the line where
5115
execution in that frame has stopped.  You can print other portions of
5116
source files by explicit command.
5117
 
5118
   If you use GDB through its GNU Emacs interface, you may prefer to
5119
use Emacs facilities to view source; see *Note Using GDB under GNU
5120
Emacs: Emacs.
5121
 
5122
* Menu:
5123
 
5124
* List::                        Printing source lines
5125
* Specify Location::            How to specify code locations
5126
* Edit::                        Editing source files
5127
* Search::                      Searching source files
5128
* Source Path::                 Specifying source directories
5129
* Machine Code::                Source and machine code
5130
 
5131

5132
File: gdb.info,  Node: List,  Next: Specify Location,  Up: Source
5133
 
5134
9.1 Printing Source Lines
5135
=========================
5136
 
5137
To print lines from a source file, use the `list' command (abbreviated
5138
`l').  By default, ten lines are printed.  There are several ways to
5139
specify what part of the file you want to print; see *Note Specify
5140
Location::, for the full list.
5141
 
5142
   Here are the forms of the `list' command most commonly used:
5143
 
5144
`list LINENUM'
5145
     Print lines centered around line number LINENUM in the current
5146
     source file.
5147
 
5148
`list FUNCTION'
5149
     Print lines centered around the beginning of function FUNCTION.
5150
 
5151
`list'
5152
     Print more lines.  If the last lines printed were printed with a
5153
     `list' command, this prints lines following the last lines
5154
     printed; however, if the last line printed was a solitary line
5155
     printed as part of displaying a stack frame (*note Examining the
5156
     Stack: Stack.), this prints lines centered around that line.
5157
 
5158
`list -'
5159
     Print lines just before the lines last printed.
5160
 
5161
   By default, GDB prints ten source lines with any of these forms of
5162
the `list' command.  You can change this using `set listsize':
5163
 
5164
`set listsize COUNT'
5165
     Make the `list' command display COUNT source lines (unless the
5166
     `list' argument explicitly specifies some other number).
5167
 
5168
`show listsize'
5169
     Display the number of lines that `list' prints.
5170
 
5171
   Repeating a `list' command with  discards the argument, so it
5172
is equivalent to typing just `list'.  This is more useful than listing
5173
the same lines again.  An exception is made for an argument of `-';
5174
that argument is preserved in repetition so that each repetition moves
5175
up in the source file.
5176
 
5177
   In general, the `list' command expects you to supply zero, one or two
5178
"linespecs".  Linespecs specify source lines; there are several ways of
5179
writing them (*note Specify Location::), but the effect is always to
5180
specify some source line.
5181
 
5182
   Here is a complete description of the possible arguments for `list':
5183
 
5184
`list LINESPEC'
5185
     Print lines centered around the line specified by LINESPEC.
5186
 
5187
`list FIRST,LAST'
5188
     Print lines from FIRST to LAST.  Both arguments are linespecs.
5189
     When a `list' command has two linespecs, and the source file of
5190
     the second linespec is omitted, this refers to the same source
5191
     file as the first linespec.
5192
 
5193
`list ,LAST'
5194
     Print lines ending with LAST.
5195
 
5196
`list FIRST,'
5197
     Print lines starting with FIRST.
5198
 
5199
`list +'
5200
     Print lines just after the lines last printed.
5201
 
5202
`list -'
5203
     Print lines just before the lines last printed.
5204
 
5205
`list'
5206
     As described in the preceding table.
5207
 
5208

5209
File: gdb.info,  Node: Specify Location,  Next: Edit,  Prev: List,  Up: Source
5210
 
5211
9.2 Specifying a Location
5212
=========================
5213
 
5214
Several GDB commands accept arguments that specify a location of your
5215
program's code.  Since GDB is a source-level debugger, a location
5216
usually specifies some line in the source code; for that reason,
5217
locations are also known as "linespecs".
5218
 
5219
   Here are all the different ways of specifying a code location that
5220
GDB understands:
5221
 
5222
`LINENUM'
5223
     Specifies the line number LINENUM of the current source file.
5224
 
5225
`-OFFSET'
5226
`+OFFSET'
5227
     Specifies the line OFFSET lines before or after the "current
5228
     line".  For the `list' command, the current line is the last one
5229
     printed; for the breakpoint commands, this is the line at which
5230
     execution stopped in the currently selected "stack frame" (*note
5231
     Frames: Frames, for a description of stack frames.)  When used as
5232
     the second of the two linespecs in a `list' command, this
5233
     specifies the line OFFSET lines up or down from the first linespec.
5234
 
5235
`FILENAME:LINENUM'
5236
     Specifies the line LINENUM in the source file FILENAME.
5237
 
5238
`FUNCTION'
5239
     Specifies the line that begins the body of the function FUNCTION.
5240
     For example, in C, this is the line with the open brace.
5241
 
5242
`FILENAME:FUNCTION'
5243
     Specifies the line that begins the body of the function FUNCTION
5244
     in the file FILENAME.  You only need the file name with a function
5245
     name to avoid ambiguity when there are identically named functions
5246
     in different source files.
5247
 
5248
`*ADDRESS'
5249
     Specifies the program address ADDRESS.  For line-oriented
5250
     commands, such as `list' and `edit', this specifies a source line
5251
     that contains ADDRESS.  For `break' and other breakpoint oriented
5252
     commands, this can be used to set breakpoints in parts of your
5253
     program which do not have debugging information or source files.
5254
 
5255
     Here ADDRESS may be any expression valid in the current working
5256
     language (*note working language: Languages.) that specifies a code
5257
     address.  In addition, as a convenience, GDB extends the semantics
5258
     of expressions used in locations to cover the situations that
5259
     frequently happen during debugging.  Here are the various forms of
5260
     ADDRESS:
5261
 
5262
    `EXPRESSION'
5263
          Any expression valid in the current working language.
5264
 
5265
    `FUNCADDR'
5266
          An address of a function or procedure derived from its name.
5267
          In C, C++, Java, Objective-C, Fortran, minimal, and assembly,
5268
          this is simply the function's name FUNCTION (and actually a
5269
          special case of a valid expression).  In Pascal and Modula-2,
5270
          this is `&FUNCTION'.  In Ada, this is `FUNCTION'Address'
5271
          (although the Pascal form also works).
5272
 
5273
          This form specifies the address of the function's first
5274
          instruction, before the stack frame and arguments have been
5275
          set up.
5276
 
5277
    `'FILENAME'::FUNCADDR'
5278
          Like FUNCADDR above, but also specifies the name of the source
5279
          file explicitly.  This is useful if the name of the function
5280
          does not specify the function unambiguously, e.g., if there
5281
          are several functions with identical names in different
5282
          source files.
5283
 
5284
 
5285

5286
File: gdb.info,  Node: Edit,  Next: Search,  Prev: Specify Location,  Up: Source
5287
 
5288
9.3 Editing Source Files
5289
========================
5290
 
5291
To edit the lines in a source file, use the `edit' command.  The
5292
editing program of your choice is invoked with the current line set to
5293
the active line in the program.  Alternatively, there are several ways
5294
to specify what part of the file you want to print if you want to see
5295
other parts of the program:
5296
 
5297
`edit LOCATION'
5298
     Edit the source file specified by `location'.  Editing starts at
5299
     that LOCATION, e.g., at the specified source line of the specified
5300
     file.  *Note Specify Location::, for all the possible forms of the
5301
     LOCATION argument; here are the forms of the `edit' command most
5302
     commonly used:
5303
 
5304
    `edit NUMBER'
5305
          Edit the current source file with NUMBER as the active line
5306
          number.
5307
 
5308
    `edit FUNCTION'
5309
          Edit the file containing FUNCTION at the beginning of its
5310
          definition.
5311
 
5312
 
5313
9.3.1 Choosing your Editor
5314
--------------------------
5315
 
5316
You can customize GDB to use any editor you want (1).  By default, it
5317
is `/bin/ex', but you can change this by setting the environment
5318
variable `EDITOR' before using GDB.  For example, to configure GDB to
5319
use the `vi' editor, you could use these commands with the `sh' shell:
5320
     EDITOR=/usr/bin/vi
5321
     export EDITOR
5322
     gdb ...
5323
   or in the `csh' shell,
5324
     setenv EDITOR /usr/bin/vi
5325
     gdb ...
5326
 
5327
   ---------- Footnotes ----------
5328
 
5329
   (1) The only restriction is that your editor (say `ex'), recognizes
5330
the following command-line syntax:
5331
     ex +NUMBER file
5332
   The optional numeric value +NUMBER specifies the number of the line
5333
in the file where to start editing.
5334
 
5335

5336
File: gdb.info,  Node: Search,  Next: Source Path,  Prev: Edit,  Up: Source
5337
 
5338
9.4 Searching Source Files
5339
==========================
5340
 
5341
There are two commands for searching through the current source file
5342
for a regular expression.
5343
 
5344
`forward-search REGEXP'
5345
`search REGEXP'
5346
     The command `forward-search REGEXP' checks each line, starting
5347
     with the one following the last line listed, for a match for
5348
     REGEXP.  It lists the line that is found.  You can use the synonym
5349
     `search REGEXP' or abbreviate the command name as `fo'.
5350
 
5351
`reverse-search REGEXP'
5352
     The command `reverse-search REGEXP' checks each line, starting
5353
     with the one before the last line listed and going backward, for a
5354
     match for REGEXP.  It lists the line that is found.  You can
5355
     abbreviate this command as `rev'.
5356
 
5357

5358
File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
5359
 
5360
9.5 Specifying Source Directories
5361
=================================
5362
 
5363
Executable programs sometimes do not record the directories of the
5364
source files from which they were compiled, just the names.  Even when
5365
they do, the directories could be moved between the compilation and
5366
your debugging session.  GDB has a list of directories to search for
5367
source files; this is called the "source path".  Each time GDB wants a
5368
source file, it tries all the directories in the list, in the order
5369
they are present in the list, until it finds a file with the desired
5370
name.
5371
 
5372
   For example, suppose an executable references the file
5373
`/usr/src/foo-1.0/lib/foo.c', and our source path is `/mnt/cross'.  The
5374
file is first looked up literally; if this fails,
5375
`/mnt/cross/usr/src/foo-1.0/lib/foo.c' is tried; if this fails,
5376
`/mnt/cross/foo.c' is opened; if this fails, an error message is
5377
printed.  GDB does not look up the parts of the source file name, such
5378
as `/mnt/cross/src/foo-1.0/lib/foo.c'.  Likewise, the subdirectories of
5379
the source path are not searched: if the source path is `/mnt/cross',
5380
and the binary refers to `foo.c', GDB would not find it under
5381
`/mnt/cross/usr/src/foo-1.0/lib'.
5382
 
5383
   Plain file names, relative file names with leading directories, file
5384
names containing dots, etc. are all treated as described above; for
5385
instance, if the source path is `/mnt/cross', and the source file is
5386
recorded as `../lib/foo.c', GDB would first try `../lib/foo.c', then
5387
`/mnt/cross/../lib/foo.c', and after that--`/mnt/cross/foo.c'.
5388
 
5389
   Note that the executable search path is _not_ used to locate the
5390
source files.
5391
 
5392
   Whenever you reset or rearrange the source path, GDB clears out any
5393
information it has cached about where source files are found and where
5394
each line is in the file.
5395
 
5396
   When you start GDB, its source path includes only `cdir' and `cwd',
5397
in that order.  To add other directories, use the `directory' command.
5398
 
5399
   The search path is used to find both program source files and GDB
5400
script files (read using the `-command' option and `source' command).
5401
 
5402
   In addition to the source path, GDB provides a set of commands that
5403
manage a list of source path substitution rules.  A "substitution rule"
5404
specifies how to rewrite source directories stored in the program's
5405
debug information in case the sources were moved to a different
5406
directory between compilation and debugging.  A rule is made of two
5407
strings, the first specifying what needs to be rewritten in the path,
5408
and the second specifying how it should be rewritten.  In *Note set
5409
substitute-path::, we name these two parts FROM and TO respectively.
5410
GDB does a simple string replacement of FROM with TO at the start of
5411
the directory part of the source file name, and uses that result
5412
instead of the original file name to look up the sources.
5413
 
5414
   Using the previous example, suppose the `foo-1.0' tree has been
5415
moved from `/usr/src' to `/mnt/cross', then you can tell GDB to replace
5416
`/usr/src' in all source path names with `/mnt/cross'.  The first
5417
lookup will then be `/mnt/cross/foo-1.0/lib/foo.c' in place of the
5418
original location of `/usr/src/foo-1.0/lib/foo.c'.  To define a source
5419
path substitution rule, use the `set substitute-path' command (*note
5420
set substitute-path::).
5421
 
5422
   To avoid unexpected substitution results, a rule is applied only if
5423
the FROM part of the directory name ends at a directory separator.  For
5424
instance, a rule substituting  `/usr/source' into `/mnt/cross' will be
5425
applied to `/usr/source/foo-1.0' but not to `/usr/sourceware/foo-2.0'.
5426
And because the substitution is applied only at the beginning of the
5427
directory name, this rule will not be applied to
5428
`/root/usr/source/baz.c' either.
5429
 
5430
   In many cases, you can achieve the same result using the `directory'
5431
command.  However, `set substitute-path' can be more efficient in the
5432
case where the sources are organized in a complex tree with multiple
5433
subdirectories.  With the `directory' command, you need to add each
5434
subdirectory of your project.  If you moved the entire tree while
5435
preserving its internal organization, then `set substitute-path' allows
5436
you to direct the debugger to all the sources with one single command.
5437
 
5438
   `set substitute-path' is also more than just a shortcut command.
5439
The source path is only used if the file at the original location no
5440
longer exists.  On the other hand, `set substitute-path' modifies the
5441
debugger behavior to look at the rewritten location instead.  So, if
5442
for any reason a source file that is not relevant to your executable is
5443
located at the original location, a substitution rule is the only
5444
method available to point GDB at the new location.
5445
 
5446
   You can configure a default source path substitution rule by
5447
configuring GDB with the `--with-relocated-sources=DIR' option.  The DIR
5448
should be the name of a directory under GDB's configured prefix (set
5449
with `--prefix' or `--exec-prefix'), and directory names in debug
5450
information under DIR will be adjusted automatically if the installed
5451
GDB is moved to a new location.  This is useful if GDB, libraries or
5452
executables with debug information and corresponding source code are
5453
being moved together.
5454
 
5455
`directory DIRNAME ...'
5456
 
5457
`dir DIRNAME ...'
5458
     Add directory DIRNAME to the front of the source path.  Several
5459
     directory names may be given to this command, separated by `:'
5460
     (`;' on MS-DOS and MS-Windows, where `:' usually appears as part
5461
     of absolute file names) or whitespace.  You may specify a
5462
     directory that is already in the source path; this moves it
5463
     forward, so GDB searches it sooner.
5464
 
5465
     You can use the string `$cdir' to refer to the compilation
5466
     directory (if one is recorded), and `$cwd' to refer to the current
5467
     working directory.  `$cwd' is not the same as `.'--the former
5468
     tracks the current working directory as it changes during your GDB
5469
     session, while the latter is immediately expanded to the current
5470
     directory at the time you add an entry to the source path.
5471
 
5472
`directory'
5473
     Reset the source path to its default value (`$cdir:$cwd' on Unix
5474
     systems).  This requires confirmation.
5475
 
5476
`show directories'
5477
     Print the source path: show which directories it contains.
5478
 
5479
`set substitute-path FROM TO'
5480
     Define a source path substitution rule, and add it at the end of
5481
     the current list of existing substitution rules.  If a rule with
5482
     the same FROM was already defined, then the old rule is also
5483
     deleted.
5484
 
5485
     For example, if the file `/foo/bar/baz.c' was moved to
5486
     `/mnt/cross/baz.c', then the command
5487
 
5488
          (gdb) set substitute-path /usr/src /mnt/cross
5489
 
5490
     will tell GDB to replace `/usr/src' with `/mnt/cross', which will
5491
     allow GDB to find the file `baz.c' even though it was moved.
5492
 
5493
     In the case when more than one substitution rule have been defined,
5494
     the rules are evaluated one by one in the order where they have
5495
     been defined.  The first one matching, if any, is selected to
5496
     perform the substitution.
5497
 
5498
     For instance, if we had entered the following commands:
5499
 
5500
          (gdb) set substitute-path /usr/src/include /mnt/include
5501
          (gdb) set substitute-path /usr/src /mnt/src
5502
 
5503
     GDB would then rewrite `/usr/src/include/defs.h' into
5504
     `/mnt/include/defs.h' by using the first rule.  However, it would
5505
     use the second rule to rewrite `/usr/src/lib/foo.c' into
5506
     `/mnt/src/lib/foo.c'.
5507
 
5508
`unset substitute-path [path]'
5509
     If a path is specified, search the current list of substitution
5510
     rules for a rule that would rewrite that path.  Delete that rule
5511
     if found.  A warning is emitted by the debugger if no rule could
5512
     be found.
5513
 
5514
     If no path is specified, then all substitution rules are deleted.
5515
 
5516
`show substitute-path [path]'
5517
     If a path is specified, then print the source path substitution
5518
     rule which would rewrite that path, if any.
5519
 
5520
     If no path is specified, then print all existing source path
5521
     substitution rules.
5522
 
5523
 
5524
   If your source path is cluttered with directories that are no longer
5525
of interest, GDB may sometimes cause confusion by finding the wrong
5526
versions of source.  You can correct the situation as follows:
5527
 
5528
  1. Use `directory' with no argument to reset the source path to its
5529
     default value.
5530
 
5531
  2. Use `directory' with suitable arguments to reinstall the
5532
     directories you want in the source path.  You can add all the
5533
     directories in one command.
5534
 
5535

5536
File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
5537
 
5538
9.6 Source and Machine Code
5539
===========================
5540
 
5541
You can use the command `info line' to map source lines to program
5542
addresses (and vice versa), and the command `disassemble' to display a
5543
range of addresses as machine instructions.  You can use the command
5544
`set disassemble-next-line' to set whether to disassemble next source
5545
line when execution stops.  When run under GNU Emacs mode, the `info
5546
line' command causes the arrow to point to the line specified.  Also,
5547
`info line' prints addresses in symbolic form as well as hex.
5548
 
5549
`info line LINESPEC'
5550
     Print the starting and ending addresses of the compiled code for
5551
     source line LINESPEC.  You can specify source lines in any of the
5552
     ways documented in *Note Specify Location::.
5553
 
5554
   For example, we can use `info line' to discover the location of the
5555
object code for the first line of function `m4_changequote':
5556
 
5557
     (gdb) info line m4_changequote
5558
     Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5559
 
5560
We can also inquire (using `*ADDR' as the form for LINESPEC) what
5561
source line covers a particular address:
5562
     (gdb) info line *0x63ff
5563
     Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5564
 
5565
   After `info line', the default address for the `x' command is
5566
changed to the starting address of the line, so that `x/i' is
5567
sufficient to begin examining the machine code (*note Examining Memory:
5568
Memory.).  Also, this address is saved as the value of the convenience
5569
variable `$_' (*note Convenience Variables: Convenience Vars.).
5570
 
5571
`disassemble'
5572
`disassemble /m'
5573
`disassemble /r'
5574
     This specialized command dumps a range of memory as machine
5575
     instructions.  It can also print mixed source+disassembly by
5576
     specifying the `/m' modifier and print the raw instructions in hex
5577
     as well as in symbolic form by specifying the `/r'.  The default
5578
     memory range is the function surrounding the program counter of
5579
     the selected frame.  A single argument to this command is a
5580
     program counter value; GDB dumps the function surrounding this
5581
     value.  When two arguments are given, they should be separated by
5582
     a comma, possibly surrounded by whitespace.  The arguments specify
5583
     a range of addresses (first inclusive, second exclusive) to dump.
5584
     In that case, the name of the function is also printed (since
5585
     there could be several functions in the given range).
5586
 
5587
     The argument(s) can be any expression yielding a numeric value,
5588
     such as `0x32c4', `&main+10' or `$pc - 8'.
5589
 
5590
     If the range of memory being disassembled contains current program
5591
     counter, the instruction at that location is shown with a `=>'
5592
     marker.
5593
 
5594
   The following example shows the disassembly of a range of addresses
5595
of HP PA-RISC 2.0 code:
5596
 
5597
     (gdb) disas 0x32c4, 0x32e4
5598
     Dump of assembler code from 0x32c4 to 0x32e4:
5599
        0x32c4 :      addil 0,dp
5600
        0x32c8 :      ldw 0x22c(sr0,r1),r26
5601
        0x32cc :      ldil 0x3000,r31
5602
        0x32d0 :      ble 0x3f8(sr4,r31)
5603
        0x32d4 :      ldo 0(r31),rp
5604
        0x32d8 :      addil -0x800,dp
5605
        0x32dc :      ldo 0x588(r1),r26
5606
        0x32e0 :      ldil 0x3000,r31
5607
     End of assembler dump.
5608
 
5609
   Here is an example showing mixed source+assembly for Intel x86, when
5610
the program is stopped just after function prologue:
5611
 
5612
     (gdb) disas /m main
5613
     Dump of assembler code for function main:
5614
     5       {
5615
        0x08048330 <+0>:    push   %ebp
5616
        0x08048331 <+1>:    mov    %esp,%ebp
5617
        0x08048333 <+3>:    sub    $0x8,%esp
5618
        0x08048336 <+6>:    and    $0xfffffff0,%esp
5619
        0x08048339 <+9>:    sub    $0x10,%esp
5620
 
5621
     6         printf ("Hello.\n");
5622
     => 0x0804833c <+12>:   movl   $0x8048440,(%esp)
5623
        0x08048343 <+19>:   call   0x8048284 
5624
 
5625
     7         return 0;
5626
     8       }
5627
        0x08048348 <+24>:   mov    $0x0,%eax
5628
        0x0804834d <+29>:   leave
5629
        0x0804834e <+30>:   ret
5630
 
5631
     End of assembler dump.
5632
 
5633
   Some architectures have more than one commonly-used set of
5634
instruction mnemonics or other syntax.
5635
 
5636
   For programs that were dynamically linked and use shared libraries,
5637
instructions that call functions or branch to locations in the shared
5638
libraries might show a seemingly bogus location--it's actually a
5639
location of the relocation table.  On some architectures, GDB might be
5640
able to resolve these to actual function names.
5641
 
5642
`set disassembly-flavor INSTRUCTION-SET'
5643
     Select the instruction set to use when disassembling the program
5644
     via the `disassemble' or `x/i' commands.
5645
 
5646
     Currently this command is only defined for the Intel x86 family.
5647
     You can set INSTRUCTION-SET to either `intel' or `att'.  The
5648
     default is `att', the AT&T flavor used by default by Unix
5649
     assemblers for x86-based targets.
5650
 
5651
`show disassembly-flavor'
5652
     Show the current setting of the disassembly flavor.
5653
 
5654
`set disassemble-next-line'
5655
`show disassemble-next-line'
5656
     Control whether or not GDB will disassemble the next source line
5657
     or instruction when execution stops.  If ON, GDB will display
5658
     disassembly of the next source line when execution of the program
5659
     being debugged stops.  This is _in addition_ to displaying the
5660
     source line itself, which GDB always does if possible.  If the
5661
     next source line cannot be displayed for some reason (e.g., if GDB
5662
     cannot find the source file, or there's no line info in the debug
5663
     info), GDB will display disassembly of the next _instruction_
5664
     instead of showing the next source line.  If AUTO, GDB will
5665
     display disassembly of next instruction only if the source line
5666
     cannot be displayed.  This setting causes GDB to display some
5667
     feedback when you step through a function with no line info or
5668
     whose source file is unavailable.  The default is OFF, which means
5669
     never display the disassembly of the next line or instruction.
5670
 
5671

5672
File: gdb.info,  Node: Data,  Next: Optimized Code,  Prev: Source,  Up: Top
5673
 
5674
10 Examining Data
5675
*****************
5676
 
5677
The usual way to examine data in your program is with the `print'
5678
command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
5679
prints the value of an expression of the language your program is
5680
written in (*note Using GDB with Different Languages: Languages.).
5681
 
5682
`print EXPR'
5683
`print /F EXPR'
5684
     EXPR is an expression (in the source language).  By default the
5685
     value of EXPR is printed in a format appropriate to its data type;
5686
     you can choose a different format by specifying `/F', where F is a
5687
     letter specifying the format; see *Note Output Formats: Output
5688
     Formats.
5689
 
5690
`print'
5691
`print /F'
5692
     If you omit EXPR, GDB displays the last value again (from the
5693
     "value history"; *note Value History: Value History.).  This
5694
     allows you to conveniently inspect the same value in an
5695
     alternative format.
5696
 
5697
   A more low-level way of examining data is with the `x' command.  It
5698
examines data in memory at a specified address and prints it in a
5699
specified format.  *Note Examining Memory: Memory.
5700
 
5701
   If you are interested in information about types, or about how the
5702
fields of a struct or a class are declared, use the `ptype EXP' command
5703
rather than `print'.  *Note Examining the Symbol Table: Symbols.
5704
 
5705
* Menu:
5706
 
5707
* Expressions::                 Expressions
5708
* Ambiguous Expressions::       Ambiguous Expressions
5709
* Variables::                   Program variables
5710
* Arrays::                      Artificial arrays
5711
* Output Formats::              Output formats
5712
* Memory::                      Examining memory
5713
* Auto Display::                Automatic display
5714
* Print Settings::              Print settings
5715
* Value History::               Value history
5716
* Convenience Vars::            Convenience variables
5717
* Registers::                   Registers
5718
* Floating Point Hardware::     Floating point hardware
5719
* Vector Unit::                 Vector Unit
5720
* OS Information::              Auxiliary data provided by operating system
5721
* Memory Region Attributes::    Memory region attributes
5722
* Dump/Restore Files::          Copy between memory and a file
5723
* Core File Generation::        Cause a program dump its core
5724
* Character Sets::              Debugging programs that use a different
5725
                                character set than GDB does
5726
* Caching Remote Data::         Data caching for remote targets
5727
* Searching Memory::            Searching memory for a sequence of bytes
5728
 
5729

5730
File: gdb.info,  Node: Expressions,  Next: Ambiguous Expressions,  Up: Data
5731
 
5732
10.1 Expressions
5733
================
5734
 
5735
`print' and many other GDB commands accept an expression and compute
5736
its value.  Any kind of constant, variable or operator defined by the
5737
programming language you are using is valid in an expression in GDB.
5738
This includes conditional expressions, function calls, casts, and
5739
string constants.  It also includes preprocessor macros, if you
5740
compiled your program to include this information; see *Note
5741
Compilation::.
5742
 
5743
   GDB supports array constants in expressions input by the user.  The
5744
syntax is {ELEMENT, ELEMENT...}.  For example, you can use the command
5745
`print {1, 2, 3}' to create an array of three integers.  If you pass an
5746
array to a function or assign it to a program variable, GDB copies the
5747
array to memory that is `malloc'ed in the target program.
5748
 
5749
   Because C is so widespread, most of the expressions shown in
5750
examples in this manual are in C.  *Note Using GDB with Different
5751
Languages: Languages, for information on how to use expressions in other
5752
languages.
5753
 
5754
   In this section, we discuss operators that you can use in GDB
5755
expressions regardless of your programming language.
5756
 
5757
   Casts are supported in all languages, not just in C, because it is so
5758
useful to cast a number into a pointer in order to examine a structure
5759
at that address in memory.
5760
 
5761
   GDB supports these operators, in addition to those common to
5762
programming languages:
5763
 
5764
`@'
5765
     `@' is a binary operator for treating parts of memory as arrays.
5766
     *Note Artificial Arrays: Arrays, for more information.
5767
 
5768
`::'
5769
     `::' allows you to specify a variable in terms of the file or
5770
     function where it is defined.  *Note Program Variables: Variables.
5771
 
5772
`{TYPE} ADDR'
5773
     Refers to an object of type TYPE stored at address ADDR in memory.
5774
     ADDR may be any expression whose value is an integer or pointer
5775
     (but parentheses are required around binary operators, just as in
5776
     a cast).  This construct is allowed regardless of what kind of
5777
     data is normally supposed to reside at ADDR.
5778
 
5779

5780
File: gdb.info,  Node: Ambiguous Expressions,  Next: Variables,  Prev: Expressions,  Up: Data
5781
 
5782
10.2 Ambiguous Expressions
5783
==========================
5784
 
5785
Expressions can sometimes contain some ambiguous elements.  For
5786
instance, some programming languages (notably Ada, C++ and Objective-C)
5787
permit a single function name to be defined several times, for
5788
application in different contexts.  This is called "overloading".
5789
Another example involving Ada is generics.  A "generic package" is
5790
similar to C++ templates and is typically instantiated several times,
5791
resulting in the same function name being defined in different contexts.
5792
 
5793
   In some cases and depending on the language, it is possible to adjust
5794
the expression to remove the ambiguity.  For instance in C++, you can
5795
specify the signature of the function you want to break on, as in
5796
`break FUNCTION(TYPES)'.  In Ada, using the fully qualified name of
5797
your function often makes the expression unambiguous as well.
5798
 
5799
   When an ambiguity that needs to be resolved is detected, the debugger
5800
has the capability to display a menu of numbered choices for each
5801
possibility, and then waits for the selection with the prompt `>'.  The
5802
first option is always `[0] cancel', and typing `0 ' aborts the
5803
current command.  If the command in which the expression was used
5804
allows more than one choice to be selected, the next option in the menu
5805
is `[1] all', and typing `1 ' selects all possible choices.
5806
 
5807
   For example, the following session excerpt shows an attempt to set a
5808
breakpoint at the overloaded symbol `String::after'.  We choose three
5809
particular definitions of that function name:
5810
 
5811
     (gdb) b String::after
5812
     [0] cancel
5813
     [1] all
5814
     [2] file:String.cc; line number:867
5815
     [3] file:String.cc; line number:860
5816
     [4] file:String.cc; line number:875
5817
     [5] file:String.cc; line number:853
5818
     [6] file:String.cc; line number:846
5819
     [7] file:String.cc; line number:735
5820
     > 2 4 6
5821
     Breakpoint 1 at 0xb26c: file String.cc, line 867.
5822
     Breakpoint 2 at 0xb344: file String.cc, line 875.
5823
     Breakpoint 3 at 0xafcc: file String.cc, line 846.
5824
     Multiple breakpoints were set.
5825
     Use the "delete" command to delete unwanted
5826
      breakpoints.
5827
     (gdb)
5828
 
5829
`set multiple-symbols MODE'
5830
     This option allows you to adjust the debugger behavior when an
5831
     expression is ambiguous.
5832
 
5833
     By default, MODE is set to `all'.  If the command with which the
5834
     expression is used allows more than one choice, then GDB
5835
     automatically selects all possible choices.  For instance,
5836
     inserting a breakpoint on a function using an ambiguous name
5837
     results in a breakpoint inserted on each possible match.  However,
5838
     if a unique choice must be made, then GDB uses the menu to help
5839
     you disambiguate the expression.  For instance, printing the
5840
     address of an overloaded function will result in the use of the
5841
     menu.
5842
 
5843
     When MODE is set to `ask', the debugger always uses the menu when
5844
     an ambiguity is detected.
5845
 
5846
     Finally, when MODE is set to `cancel', the debugger reports an
5847
     error due to the ambiguity and the command is aborted.
5848
 
5849
`show multiple-symbols'
5850
     Show the current value of the `multiple-symbols' setting.
5851
 
5852

5853
File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Ambiguous Expressions,  Up: Data
5854
 
5855
10.3 Program Variables
5856
======================
5857
 
5858
The most common kind of expression to use is the name of a variable in
5859
your program.
5860
 
5861
   Variables in expressions are understood in the selected stack frame
5862
(*note Selecting a Frame: Selection.); they must be either:
5863
 
5864
   * global (or file-static)
5865
 
5866
or
5867
 
5868
   * visible according to the scope rules of the programming language
5869
     from the point of execution in that frame
5870
 
5871
This means that in the function
5872
 
5873
     foo (a)
5874
          int a;
5875
     {
5876
       bar (a);
5877
       {
5878
         int b = test ();
5879
         bar (b);
5880
       }
5881
     }
5882
 
5883
you can examine and use the variable `a' whenever your program is
5884
executing within the function `foo', but you can only use or examine
5885
the variable `b' while your program is executing inside the block where
5886
`b' is declared.
5887
 
5888
   There is an exception: you can refer to a variable or function whose
5889
scope is a single source file even if the current execution point is not
5890
in this file.  But it is possible to have more than one such variable or
5891
function with the same name (in different source files).  If that
5892
happens, referring to that name has unpredictable effects.  If you wish,
5893
you can specify a static variable in a particular function or file,
5894
using the colon-colon (`::') notation:
5895
 
5896
     FILE::VARIABLE
5897
     FUNCTION::VARIABLE
5898
 
5899
Here FILE or FUNCTION is the name of the context for the static
5900
VARIABLE.  In the case of file names, you can use quotes to make sure
5901
GDB parses the file name as a single word--for example, to print a
5902
global value of `x' defined in `f2.c':
5903
 
5904
     (gdb) p 'f2.c'::x
5905
 
5906
   This use of `::' is very rarely in conflict with the very similar
5907
use of the same notation in C++.  GDB also supports use of the C++
5908
scope resolution operator in GDB expressions.
5909
 
5910
     _Warning:_ Occasionally, a local variable may appear to have the
5911
     wrong value at certain points in a function--just after entry to a
5912
     new scope, and just before exit.
5913
   You may see this problem when you are stepping by machine
5914
instructions.  This is because, on most machines, it takes more than
5915
one instruction to set up a stack frame (including local variable
5916
definitions); if you are stepping by machine instructions, variables
5917
may appear to have the wrong values until the stack frame is completely
5918
built.  On exit, it usually also takes more than one machine
5919
instruction to destroy a stack frame; after you begin stepping through
5920
that group of instructions, local variable definitions may be gone.
5921
 
5922
   This may also happen when the compiler does significant
5923
optimizations.  To be sure of always seeing accurate values, turn off
5924
all optimization when compiling.
5925
 
5926
   Another possible effect of compiler optimizations is to optimize
5927
unused variables out of existence, or assign variables to registers (as
5928
opposed to memory addresses).  Depending on the support for such cases
5929
offered by the debug info format used by the compiler, GDB might not be
5930
able to display values for such local variables.  If that happens, GDB
5931
will print a message like this:
5932
 
5933
     No symbol "foo" in current context.
5934
 
5935
   To solve such problems, either recompile without optimizations, or
5936
use a different debug info format, if the compiler supports several such
5937
formats.  For example, GCC, the GNU C/C++ compiler, usually supports
5938
the `-gstabs+' option.  `-gstabs+' produces debug info in a format that
5939
is superior to formats such as COFF.  You may be able to use DWARF 2
5940
(`-gdwarf-2'), which is also an effective form for debug info.  *Note
5941
Options for Debugging Your Program or GCC: (gcc.info)Debugging Options.
5942
*Note C and C++: C, for more information about debug info formats that
5943
are best suited to C++ programs.
5944
 
5945
   If you ask to print an object whose contents are unknown to GDB,
5946
e.g., because its data type is not completely specified by the debug
5947
information, GDB will say `'.  *Note incomplete type:
5948
Symbols, for more about this.
5949
 
5950
   Strings are identified as arrays of `char' values without specified
5951
signedness.  Arrays of either `signed char' or `unsigned char' get
5952
printed as arrays of 1 byte sized integers.  `-fsigned-char' or
5953
`-funsigned-char' GCC options have no effect as GDB defines literal
5954
string type `"char"' as `char' without a sign.  For program code
5955
 
5956
     char var0[] = "A";
5957
     signed char var1[] = "A";
5958
 
5959
   You get during debugging
5960
     (gdb) print var0
5961
     $1 = "A"
5962
     (gdb) print var1
5963
     $2 = {65 'A', 0 '\0'}
5964
 
5965

5966
File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
5967
 
5968
10.4 Artificial Arrays
5969
======================
5970
 
5971
It is often useful to print out several successive objects of the same
5972
type in memory; a section of an array, or an array of dynamically
5973
determined size for which only a pointer exists in the program.
5974
 
5975
   You can do this by referring to a contiguous span of memory as an
5976
"artificial array", using the binary operator `@'.  The left operand of
5977
`@' should be the first element of the desired array and be an
5978
individual object.  The right operand should be the desired length of
5979
the array.  The result is an array value whose elements are all of the
5980
type of the left argument.  The first element is actually the left
5981
argument; the second element comes from bytes of memory immediately
5982
following those that hold the first element, and so on.  Here is an
5983
example.  If a program says
5984
 
5985
     int *array = (int *) malloc (len * sizeof (int));
5986
 
5987
you can print the contents of `array' with
5988
 
5989
     p *array@len
5990
 
5991
   The left operand of `@' must reside in memory.  Array values made
5992
with `@' in this way behave just like other arrays in terms of
5993
subscripting, and are coerced to pointers when used in expressions.
5994
Artificial arrays most often appear in expressions via the value history
5995
(*note Value History: Value History.), after printing one out.
5996
 
5997
   Another way to create an artificial array is to use a cast.  This
5998
re-interprets a value as if it were an array.  The value need not be in
5999
memory:
6000
     (gdb) p/x (short[2])0x12345678
6001
     $1 = {0x1234, 0x5678}
6002
 
6003
   As a convenience, if you leave the array length out (as in
6004
`(TYPE[])VALUE') GDB calculates the size to fill the value (as
6005
`sizeof(VALUE)/sizeof(TYPE)':
6006
     (gdb) p/x (short[])0x12345678
6007
     $2 = {0x1234, 0x5678}
6008
 
6009
   Sometimes the artificial array mechanism is not quite enough; in
6010
moderately complex data structures, the elements of interest may not
6011
actually be adjacent--for example, if you are interested in the values
6012
of pointers in an array.  One useful work-around in this situation is
6013
to use a convenience variable (*note Convenience Variables: Convenience
6014
Vars.) as a counter in an expression that prints the first interesting
6015
value, and then repeat that expression via .  For instance,
6016
suppose you have an array `dtab' of pointers to structures, and you are
6017
interested in the values of a field `fv' in each structure.  Here is an
6018
example of what you might type:
6019
 
6020
     set $i = 0
6021
     p dtab[$i++]->fv
6022
     
6023
     
6024
     ...
6025
 
6026

6027
File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
6028
 
6029
10.5 Output Formats
6030
===================
6031
 
6032
By default, GDB prints a value according to its data type.  Sometimes
6033
this is not what you want.  For example, you might want to print a
6034
number in hex, or a pointer in decimal.  Or you might want to view data
6035
in memory at a certain address as a character string or as an
6036
instruction.  To do these things, specify an "output format" when you
6037
print a value.
6038
 
6039
   The simplest use of output formats is to say how to print a value
6040
already computed.  This is done by starting the arguments of the
6041
`print' command with a slash and a format letter.  The format letters
6042
supported are:
6043
 
6044
`x'
6045
     Regard the bits of the value as an integer, and print the integer
6046
     in hexadecimal.
6047
 
6048
`d'
6049
     Print as integer in signed decimal.
6050
 
6051
`u'
6052
     Print as integer in unsigned decimal.
6053
 
6054
`o'
6055
     Print as integer in octal.
6056
 
6057
`t'
6058
     Print as integer in binary.  The letter `t' stands for "two".  (1)
6059
 
6060
`a'
6061
     Print as an address, both absolute in hexadecimal and as an offset
6062
     from the nearest preceding symbol.  You can use this format used
6063
     to discover where (in what function) an unknown address is located:
6064
 
6065
          (gdb) p/a 0x54320
6066
          $3 = 0x54320 <_initialize_vx+396>
6067
 
6068
     The command `info symbol 0x54320' yields similar results.  *Note
6069
     info symbol: Symbols.
6070
 
6071
`c'
6072
     Regard as an integer and print it as a character constant.  This
6073
     prints both the numerical value and its character representation.
6074
     The character representation is replaced with the octal escape
6075
     `\nnn' for characters outside the 7-bit ASCII range.
6076
 
6077
     Without this format, GDB displays `char', `unsigned char', and
6078
     `signed char' data as character constants.  Single-byte members of
6079
     vectors are displayed as integer data.
6080
 
6081
`f'
6082
     Regard the bits of the value as a floating point number and print
6083
     using typical floating point syntax.
6084
 
6085
`s'
6086
     Regard as a string, if possible.  With this format, pointers to
6087
     single-byte data are displayed as null-terminated strings and
6088
     arrays of single-byte data are displayed as fixed-length strings.
6089
     Other values are displayed in their natural types.
6090
 
6091
     Without this format, GDB displays pointers to and arrays of
6092
     `char', `unsigned char', and `signed char' as strings.
6093
     Single-byte members of a vector are displayed as an integer array.
6094
 
6095
`r'
6096
     Print using the `raw' formatting.  By default, GDB will use a
6097
     type-specific pretty-printer.  The `r' format bypasses any
6098
     pretty-printer which might exist for the value's type.
6099
 
6100
   For example, to print the program counter in hex (*note
6101
Registers::), type
6102
 
6103
     p/x $pc
6104
 
6105
Note that no space is required before the slash; this is because command
6106
names in GDB cannot contain a slash.
6107
 
6108
   To reprint the last value in the value history with a different
6109
format, you can use the `print' command with just a format and no
6110
expression.  For example, `p/x' reprints the last value in hex.
6111
 
6112
   ---------- Footnotes ----------
6113
 
6114
   (1) `b' cannot be used because these format letters are also used
6115
with the `x' command, where `b' stands for "byte"; see *Note Examining
6116
Memory: Memory.
6117
 
6118

6119
File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output Formats,  Up: Data
6120
 
6121
10.6 Examining Memory
6122
=====================
6123
 
6124
You can use the command `x' (for "examine") to examine memory in any of
6125
several formats, independently of your program's data types.
6126
 
6127
`x/NFU ADDR'
6128
`x ADDR'
6129
`x'
6130
     Use the `x' command to examine memory.
6131
 
6132
   N, F, and U are all optional parameters that specify how much memory
6133
to display and how to format it; ADDR is an expression giving the
6134
address where you want to start displaying memory.  If you use defaults
6135
for NFU, you need not type the slash `/'.  Several commands set
6136
convenient defaults for ADDR.
6137
 
6138
N, the repeat count
6139
     The repeat count is a decimal integer; the default is 1.  It
6140
     specifies how much memory (counting by units U) to display.
6141
 
6142
F, the display format
6143
     The display format is one of the formats used by `print' (`x',
6144
     `d', `u', `o', `t', `a', `c', `f', `s'), and in addition `i' (for
6145
     machine instructions).  The default is `x' (hexadecimal)
6146
     initially.  The default changes each time you use either `x' or
6147
     `print'.
6148
 
6149
U, the unit size
6150
     The unit size is any of
6151
 
6152
    `b'
6153
          Bytes.
6154
 
6155
    `h'
6156
          Halfwords (two bytes).
6157
 
6158
    `w'
6159
          Words (four bytes).  This is the initial default.
6160
 
6161
    `g'
6162
          Giant words (eight bytes).
6163
 
6164
     Each time you specify a unit size with `x', that size becomes the
6165
     default unit the next time you use `x'.  (For the `s' and `i'
6166
     formats, the unit size is ignored and is normally not written.)
6167
 
6168
ADDR, starting display address
6169
     ADDR is the address where you want GDB to begin displaying memory.
6170
     The expression need not have a pointer value (though it may); it
6171
     is always interpreted as an integer address of a byte of memory.
6172
     *Note Expressions: Expressions, for more information on
6173
     expressions.  The default for ADDR is usually just after the last
6174
     address examined--but several other commands also set the default
6175
     address: `info breakpoints' (to the address of the last breakpoint
6176
     listed), `info line' (to the starting address of a line), and
6177
     `print' (if you use it to display a value from memory).
6178
 
6179
   For example, `x/3uh 0x54320' is a request to display three halfwords
6180
(`h') of memory, formatted as unsigned decimal integers (`u'), starting
6181
at address `0x54320'.  `x/4xw $sp' prints the four words (`w') of
6182
memory above the stack pointer (here, `$sp'; *note Registers:
6183
Registers.) in hexadecimal (`x').
6184
 
6185
   Since the letters indicating unit sizes are all distinct from the
6186
letters specifying output formats, you do not have to remember whether
6187
unit size or format comes first; either order works.  The output
6188
specifications `4xw' and `4wx' mean exactly the same thing.  (However,
6189
the count N must come first; `wx4' does not work.)
6190
 
6191
   Even though the unit size U is ignored for the formats `s' and `i',
6192
you might still want to use a count N; for example, `3i' specifies that
6193
you want to see three machine instructions, including any operands.
6194
For convenience, especially when used with the `display' command, the
6195
`i' format also prints branch delay slot instructions, if any, beyond
6196
the count specified, which immediately follow the last instruction that
6197
is within the count.  The command `disassemble' gives an alternative
6198
way of inspecting machine instructions; see *Note Source and Machine
6199
Code: Machine Code.
6200
 
6201
   All the defaults for the arguments to `x' are designed to make it
6202
easy to continue scanning memory with minimal specifications each time
6203
you use `x'.  For example, after you have inspected three machine
6204
instructions with `x/3i ADDR', you can inspect the next seven with just
6205
`x/7'.  If you use  to repeat the `x' command, the repeat count N
6206
is used again; the other arguments default as for successive uses of
6207
`x'.
6208
 
6209
   When examining machine instructions, the instruction at current
6210
program counter is shown with a `=>' marker. For example:
6211
 
6212
     (gdb) x/5i $pc-6
6213
        0x804837f : mov    %esp,%ebp
6214
        0x8048381 : push   %ecx
6215
        0x8048382 : sub    $0x4,%esp
6216
     => 0x8048385 : movl   $0x8048460,(%esp)
6217
        0x804838c : call   0x80482d4 
6218
 
6219
   The addresses and contents printed by the `x' command are not saved
6220
in the value history because there is often too much of them and they
6221
would get in the way.  Instead, GDB makes these values available for
6222
subsequent use in expressions as values of the convenience variables
6223
`$_' and `$__'.  After an `x' command, the last address examined is
6224
available for use in expressions in the convenience variable `$_'.  The
6225
contents of that address, as examined, are available in the convenience
6226
variable `$__'.
6227
 
6228
   If the `x' command has a repeat count, the address and contents saved
6229
are from the last memory unit printed; this is not the same as the last
6230
address printed if several units were printed on the last line of
6231
output.
6232
 
6233
   When you are debugging a program running on a remote target machine
6234
(*note Remote Debugging::), you may wish to verify the program's image
6235
in the remote machine's memory against the executable file you
6236
downloaded to the target.  The `compare-sections' command is provided
6237
for such situations.
6238
 
6239
`compare-sections [SECTION-NAME]'
6240
     Compare the data of a loadable section SECTION-NAME in the
6241
     executable file of the program being debugged with the same
6242
     section in the remote machine's memory, and report any mismatches.
6243
     With no arguments, compares all loadable sections.  This command's
6244
     availability depends on the target's support for the `"qCRC"'
6245
     remote request.
6246
 
6247

6248
File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
6249
 
6250
10.7 Automatic Display
6251
======================
6252
 
6253
If you find that you want to print the value of an expression frequently
6254
(to see how it changes), you might want to add it to the "automatic
6255
display list" so that GDB prints its value each time your program stops.
6256
Each expression added to the list is given a number to identify it; to
6257
remove an expression from the list, you specify that number.  The
6258
automatic display looks like this:
6259
 
6260
     2: foo = 38
6261
     3: bar[5] = (struct hack *) 0x3804
6262
 
6263
This display shows item numbers, expressions and their current values.
6264
As with displays you request manually using `x' or `print', you can
6265
specify the output format you prefer; in fact, `display' decides
6266
whether to use `print' or `x' depending your format specification--it
6267
uses `x' if you specify either the `i' or `s' format, or a unit size;
6268
otherwise it uses `print'.
6269
 
6270
`display EXPR'
6271
     Add the expression EXPR to the list of expressions to display each
6272
     time your program stops.  *Note Expressions: Expressions.
6273
 
6274
     `display' does not repeat if you press  again after using it.
6275
 
6276
`display/FMT EXPR'
6277
     For FMT specifying only a display format and not a size or count,
6278
     add the expression EXPR to the auto-display list but arrange to
6279
     display it each time in the specified format FMT.  *Note Output
6280
     Formats: Output Formats.
6281
 
6282
`display/FMT ADDR'
6283
     For FMT `i' or `s', or including a unit-size or a number of units,
6284
     add the expression ADDR as a memory address to be examined each
6285
     time your program stops.  Examining means in effect doing `x/FMT
6286
     ADDR'.  *Note Examining Memory: Memory.
6287
 
6288
   For example, `display/i $pc' can be helpful, to see the machine
6289
instruction about to be executed each time execution stops (`$pc' is a
6290
common name for the program counter; *note Registers: Registers.).
6291
 
6292
`undisplay DNUMS...'
6293
`delete display DNUMS...'
6294
     Remove item numbers DNUMS from the list of expressions to display.
6295
 
6296
     `undisplay' does not repeat if you press  after using it.
6297
     (Otherwise you would just get the error `No display number ...'.)
6298
 
6299
`disable display DNUMS...'
6300
     Disable the display of item numbers DNUMS.  A disabled display
6301
     item is not printed automatically, but is not forgotten.  It may be
6302
     enabled again later.
6303
 
6304
`enable display DNUMS...'
6305
     Enable display of item numbers DNUMS.  It becomes effective once
6306
     again in auto display of its expression, until you specify
6307
     otherwise.
6308
 
6309
`display'
6310
     Display the current values of the expressions on the list, just as
6311
     is done when your program stops.
6312
 
6313
`info display'
6314
     Print the list of expressions previously set up to display
6315
     automatically, each one with its item number, but without showing
6316
     the values.  This includes disabled expressions, which are marked
6317
     as such.  It also includes expressions which would not be
6318
     displayed right now because they refer to automatic variables not
6319
     currently available.
6320
 
6321
   If a display expression refers to local variables, then it does not
6322
make sense outside the lexical context for which it was set up.  Such an
6323
expression is disabled when execution enters a context where one of its
6324
variables is not defined.  For example, if you give the command
6325
`display last_char' while inside a function with an argument
6326
`last_char', GDB displays this argument while your program continues to
6327
stop inside that function.  When it stops elsewhere--where there is no
6328
variable `last_char'--the display is disabled automatically.  The next
6329
time your program stops where `last_char' is meaningful, you can enable
6330
the display expression once again.
6331
 
6332

6333
File: gdb.info,  Node: Print Settings,  Next: Value History,  Prev: Auto Display,  Up: Data
6334
 
6335
10.8 Print Settings
6336
===================
6337
 
6338
GDB provides the following ways to control how arrays, structures, and
6339
symbols are printed.
6340
 
6341
These settings are useful for debugging programs in any language:
6342
 
6343
`set print address'
6344
`set print address on'
6345
     GDB prints memory addresses showing the location of stack traces,
6346
     structure values, pointer values, breakpoints, and so forth, even
6347
     when it also displays the contents of those addresses.  The default
6348
     is `on'.  For example, this is what a stack frame display looks
6349
     like with `set print address on':
6350
 
6351
          (gdb) f
6352
          #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
6353
              at input.c:530
6354
          530         if (lquote != def_lquote)
6355
 
6356
`set print address off'
6357
     Do not print addresses when displaying their contents.  For
6358
     example, this is the same stack frame displayed with `set print
6359
     address off':
6360
 
6361
          (gdb) set print addr off
6362
          (gdb) f
6363
          #0  set_quotes (lq="<<", rq=">>") at input.c:530
6364
          530         if (lquote != def_lquote)
6365
 
6366
     You can use `set print address off' to eliminate all machine
6367
     dependent displays from the GDB interface.  For example, with
6368
     `print address off', you should get the same text for backtraces on
6369
     all machines--whether or not they involve pointer arguments.
6370
 
6371
`show print address'
6372
     Show whether or not addresses are to be printed.
6373
 
6374
   When GDB prints a symbolic address, it normally prints the closest
6375
earlier symbol plus an offset.  If that symbol does not uniquely
6376
identify the address (for example, it is a name whose scope is a single
6377
source file), you may need to clarify.  One way to do this is with
6378
`info line', for example `info line *0x4537'.  Alternately, you can set
6379
GDB to print the source file and line number when it prints a symbolic
6380
address:
6381
 
6382
`set print symbol-filename on'
6383
     Tell GDB to print the source file name and line number of a symbol
6384
     in the symbolic form of an address.
6385
 
6386
`set print symbol-filename off'
6387
     Do not print source file name and line number of a symbol.  This
6388
     is the default.
6389
 
6390
`show print symbol-filename'
6391
     Show whether or not GDB will print the source file name and line
6392
     number of a symbol in the symbolic form of an address.
6393
 
6394
   Another situation where it is helpful to show symbol filenames and
6395
line numbers is when disassembling code; GDB shows you the line number
6396
and source file that corresponds to each instruction.
6397
 
6398
   Also, you may wish to see the symbolic form only if the address being
6399
printed is reasonably close to the closest earlier symbol:
6400
 
6401
`set print max-symbolic-offset MAX-OFFSET'
6402
     Tell GDB to only display the symbolic form of an address if the
6403
     offset between the closest earlier symbol and the address is less
6404
     than MAX-OFFSET.  The default is 0, which tells GDB to always
6405
     print the symbolic form of an address if any symbol precedes it.
6406
 
6407
`show print max-symbolic-offset'
6408
     Ask how large the maximum offset is that GDB prints in a symbolic
6409
     address.
6410
 
6411
   If you have a pointer and you are not sure where it points, try `set
6412
print symbol-filename on'.  Then you can determine the name and source
6413
file location of the variable where it points, using `p/a POINTER'.
6414
This interprets the address in symbolic form.  For example, here GDB
6415
shows that a variable `ptt' points at another variable `t', defined in
6416
`hi2.c':
6417
 
6418
     (gdb) set print symbol-filename on
6419
     (gdb) p/a ptt
6420
     $4 = 0xe008 
6421
 
6422
     _Warning:_ For pointers that point to a local variable, `p/a' does
6423
     not show the symbol name and filename of the referent, even with
6424
     the appropriate `set print' options turned on.
6425
 
6426
   Other settings control how different kinds of objects are printed:
6427
 
6428
`set print array'
6429
`set print array on'
6430
     Pretty print arrays.  This format is more convenient to read, but
6431
     uses more space.  The default is off.
6432
 
6433
`set print array off'
6434
     Return to compressed format for arrays.
6435
 
6436
`show print array'
6437
     Show whether compressed or pretty format is selected for displaying
6438
     arrays.
6439
 
6440
`set print array-indexes'
6441
`set print array-indexes on'
6442
     Print the index of each element when displaying arrays.  May be
6443
     more convenient to locate a given element in the array or quickly
6444
     find the index of a given element in that printed array.  The
6445
     default is off.
6446
 
6447
`set print array-indexes off'
6448
     Stop printing element indexes when displaying arrays.
6449
 
6450
`show print array-indexes'
6451
     Show whether the index of each element is printed when displaying
6452
     arrays.
6453
 
6454
`set print elements NUMBER-OF-ELEMENTS'
6455
     Set a limit on how many elements of an array GDB will print.  If
6456
     GDB is printing a large array, it stops printing after it has
6457
     printed the number of elements set by the `set print elements'
6458
     command.  This limit also applies to the display of strings.  When
6459
     GDB starts, this limit is set to 200.  Setting  NUMBER-OF-ELEMENTS
6460
     to zero means that the printing is unlimited.
6461
 
6462
`show print elements'
6463
     Display the number of elements of a large array that GDB will
6464
     print.  If the number is 0, then the printing is unlimited.
6465
 
6466
`set print frame-arguments VALUE'
6467
     This command allows to control how the values of arguments are
6468
     printed when the debugger prints a frame (*note Frames::).  The
6469
     possible values are:
6470
 
6471
    `all'
6472
          The values of all arguments are printed.
6473
 
6474
    `scalars'
6475
          Print the value of an argument only if it is a scalar.  The
6476
          value of more complex arguments such as arrays, structures,
6477
          unions, etc, is replaced by `...'.  This is the default.
6478
          Here is an example where only scalar arguments are shown:
6479
 
6480
               #1  0x08048361 in call_me (i=3, s=..., ss=0xbf8d508c, u=..., e=green)
6481
                 at frame-args.c:23
6482
 
6483
    `none'
6484
          None of the argument values are printed.  Instead, the value
6485
          of each argument is replaced by `...'.  In this case, the
6486
          example above now becomes:
6487
 
6488
               #1  0x08048361 in call_me (i=..., s=..., ss=..., u=..., e=...)
6489
                 at frame-args.c:23
6490
 
6491
     By default, only scalar arguments are printed.  This command can
6492
     be used to configure the debugger to print the value of all
6493
     arguments, regardless of their type.  However, it is often
6494
     advantageous to not print the value of more complex parameters.
6495
     For instance, it reduces the amount of information printed in each
6496
     frame, making the backtrace more readable.  Also, it improves
6497
     performance when displaying Ada frames, because the computation of
6498
     large arguments can sometimes be CPU-intensive, especially in
6499
     large applications.  Setting `print frame-arguments' to `scalars'
6500
     (the default) or `none' avoids this computation, thus speeding up
6501
     the display of each Ada frame.
6502
 
6503
`show print frame-arguments'
6504
     Show how the value of arguments should be displayed when printing
6505
     a frame.
6506
 
6507
`set print repeats'
6508
     Set the threshold for suppressing display of repeated array
6509
     elements.  When the number of consecutive identical elements of an
6510
     array exceeds the threshold, GDB prints the string `"
6511
     times>"', where N is the number of identical repetitions, instead
6512
     of displaying the identical elements themselves.  Setting the
6513
     threshold to zero will cause all elements to be individually
6514
     printed.  The default threshold is 10.
6515
 
6516
`show print repeats'
6517
     Display the current threshold for printing repeated identical
6518
     elements.
6519
 
6520
`set print null-stop'
6521
     Cause GDB to stop printing the characters of an array when the
6522
     first NULL is encountered.  This is useful when large arrays
6523
     actually contain only short strings.  The default is off.
6524
 
6525
`show print null-stop'
6526
     Show whether GDB stops printing an array on the first NULL
6527
     character.
6528
 
6529
`set print pretty on'
6530
     Cause GDB to print structures in an indented format with one member
6531
     per line, like this:
6532
 
6533
          $1 = {
6534
            next = 0x0,
6535
            flags = {
6536
              sweet = 1,
6537
              sour = 1
6538
            },
6539
            meat = 0x54 "Pork"
6540
          }
6541
 
6542
`set print pretty off'
6543
     Cause GDB to print structures in a compact format, like this:
6544
 
6545
          $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
6546
          meat = 0x54 "Pork"}
6547
 
6548
     This is the default format.
6549
 
6550
`show print pretty'
6551
     Show which format GDB is using to print structures.
6552
 
6553
`set print sevenbit-strings on'
6554
     Print using only seven-bit characters; if this option is set, GDB
6555
     displays any eight-bit characters (in strings or character values)
6556
     using the notation `\'NNN.  This setting is best if you are
6557
     working in English (ASCII) and you use the high-order bit of
6558
     characters as a marker or "meta" bit.
6559
 
6560
`set print sevenbit-strings off'
6561
     Print full eight-bit characters.  This allows the use of more
6562
     international character sets, and is the default.
6563
 
6564
`show print sevenbit-strings'
6565
     Show whether or not GDB is printing only seven-bit characters.
6566
 
6567
`set print union on'
6568
     Tell GDB to print unions which are contained in structures and
6569
     other unions.  This is the default setting.
6570
 
6571
`set print union off'
6572
     Tell GDB not to print unions which are contained in structures and
6573
     other unions.  GDB will print `"{...}"' instead.
6574
 
6575
`show print union'
6576
     Ask GDB whether or not it will print unions which are contained in
6577
     structures and other unions.
6578
 
6579
     For example, given the declarations
6580
 
6581
          typedef enum {Tree, Bug} Species;
6582
          typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
6583
          typedef enum {Caterpillar, Cocoon, Butterfly}
6584
                        Bug_forms;
6585
 
6586
          struct thing {
6587
            Species it;
6588
            union {
6589
              Tree_forms tree;
6590
              Bug_forms bug;
6591
            } form;
6592
          };
6593
 
6594
          struct thing foo = {Tree, {Acorn}};
6595
 
6596
     with `set print union on' in effect `p foo' would print
6597
 
6598
          $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
6599
 
6600
     and with `set print union off' in effect it would print
6601
 
6602
          $1 = {it = Tree, form = {...}}
6603
 
6604
     `set print union' affects programs written in C-like languages and
6605
     in Pascal.
6606
 
6607
These settings are of interest when debugging C++ programs:
6608
 
6609
`set print demangle'
6610
`set print demangle on'
6611
     Print C++ names in their source form rather than in the encoded
6612
     ("mangled") form passed to the assembler and linker for type-safe
6613
     linkage.  The default is on.
6614
 
6615
`show print demangle'
6616
     Show whether C++ names are printed in mangled or demangled form.
6617
 
6618
`set print asm-demangle'
6619
`set print asm-demangle on'
6620
     Print C++ names in their source form rather than their mangled
6621
     form, even in assembler code printouts such as instruction
6622
     disassemblies.  The default is off.
6623
 
6624
`show print asm-demangle'
6625
     Show whether C++ names in assembly listings are printed in mangled
6626
     or demangled form.
6627
 
6628
`set demangle-style STYLE'
6629
     Choose among several encoding schemes used by different compilers
6630
     to represent C++ names.  The choices for STYLE are currently:
6631
 
6632
    `auto'
6633
          Allow GDB to choose a decoding style by inspecting your
6634
          program.
6635
 
6636
    `gnu'
6637
          Decode based on the GNU C++ compiler (`g++') encoding
6638
          algorithm.  This is the default.
6639
 
6640
    `hp'
6641
          Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
6642
 
6643
    `lucid'
6644
          Decode based on the Lucid C++ compiler (`lcc') encoding
6645
          algorithm.
6646
 
6647
    `arm'
6648
          Decode using the algorithm in the `C++ Annotated Reference
6649
          Manual'.  *Warning:* this setting alone is not sufficient to
6650
          allow debugging `cfront'-generated executables.  GDB would
6651
          require further enhancement to permit that.
6652
 
6653
     If you omit STYLE, you will see a list of possible formats.
6654
 
6655
`show demangle-style'
6656
     Display the encoding style currently in use for decoding C++
6657
     symbols.
6658
 
6659
`set print object'
6660
`set print object on'
6661
     When displaying a pointer to an object, identify the _actual_
6662
     (derived) type of the object rather than the _declared_ type, using
6663
     the virtual function table.
6664
 
6665
`set print object off'
6666
     Display only the declared type of objects, without reference to the
6667
     virtual function table.  This is the default setting.
6668
 
6669
`show print object'
6670
     Show whether actual, or declared, object types are displayed.
6671
 
6672
`set print static-members'
6673
`set print static-members on'
6674
     Print static members when displaying a C++ object.  The default is
6675
     on.
6676
 
6677
`set print static-members off'
6678
     Do not print static members when displaying a C++ object.
6679
 
6680
`show print static-members'
6681
     Show whether C++ static members are printed or not.
6682
 
6683
`set print pascal_static-members'
6684
`set print pascal_static-members on'
6685
     Print static members when displaying a Pascal object.  The default
6686
     is on.
6687
 
6688
`set print pascal_static-members off'
6689
     Do not print static members when displaying a Pascal object.
6690
 
6691
`show print pascal_static-members'
6692
     Show whether Pascal static members are printed or not.
6693
 
6694
`set print vtbl'
6695
`set print vtbl on'
6696
     Pretty print C++ virtual function tables.  The default is off.
6697
     (The `vtbl' commands do not work on programs compiled with the HP
6698
     ANSI C++ compiler (`aCC').)
6699
 
6700
`set print vtbl off'
6701
     Do not pretty print C++ virtual function tables.
6702
 
6703
`show print vtbl'
6704
     Show whether C++ virtual function tables are pretty printed, or
6705
     not.
6706
 
6707

6708
File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Print Settings,  Up: Data
6709
 
6710
10.9 Value History
6711
==================
6712
 
6713
Values printed by the `print' command are saved in the GDB "value
6714
history".  This allows you to refer to them in other expressions.
6715
Values are kept until the symbol table is re-read or discarded (for
6716
example with the `file' or `symbol-file' commands).  When the symbol
6717
table changes, the value history is discarded, since the values may
6718
contain pointers back to the types defined in the symbol table.
6719
 
6720
   The values printed are given "history numbers" by which you can
6721
refer to them.  These are successive integers starting with one.
6722
`print' shows you the history number assigned to a value by printing
6723
`$NUM = ' before the value; here NUM is the history number.
6724
 
6725
   To refer to any previous value, use `$' followed by the value's
6726
history number.  The way `print' labels its output is designed to
6727
remind you of this.  Just `$' refers to the most recent value in the
6728
history, and `$$' refers to the value before that.  `$$N' refers to the
6729
Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
6730
equivalent to `$$', and `$$0' is equivalent to `$'.
6731
 
6732
   For example, suppose you have just printed a pointer to a structure
6733
and want to see the contents of the structure.  It suffices to type
6734
 
6735
     p *$
6736
 
6737
   If you have a chain of structures where the component `next' points
6738
to the next one, you can print the contents of the next one with this:
6739
 
6740
     p *$.next
6741
 
6742
You can print successive links in the chain by repeating this
6743
command--which you can do by just typing .
6744
 
6745
   Note that the history records values, not expressions.  If the value
6746
of `x' is 4 and you type these commands:
6747
 
6748
     print x
6749
     set x=5
6750
 
6751
then the value recorded in the value history by the `print' command
6752
remains 4 even though the value of `x' has changed.
6753
 
6754
`show values'
6755
     Print the last ten values in the value history, with their item
6756
     numbers.  This is like `p $$9' repeated ten times, except that
6757
     `show values' does not change the history.
6758
 
6759
`show values N'
6760
     Print ten history values centered on history item number N.
6761
 
6762
`show values +'
6763
     Print ten history values just after the values last printed.  If
6764
     no more values are available, `show values +' produces no display.
6765
 
6766
   Pressing  to repeat `show values N' has exactly the same effect
6767
as `show values +'.
6768
 
6769

6770
File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
6771
 
6772
10.10 Convenience Variables
6773
===========================
6774
 
6775
GDB provides "convenience variables" that you can use within GDB to
6776
hold on to a value and refer to it later.  These variables exist
6777
entirely within GDB; they are not part of your program, and setting a
6778
convenience variable has no direct effect on further execution of your
6779
program.  That is why you can use them freely.
6780
 
6781
   Convenience variables are prefixed with `$'.  Any name preceded by
6782
`$' can be used for a convenience variable, unless it is one of the
6783
predefined machine-specific register names (*note Registers:
6784
Registers.).  (Value history references, in contrast, are _numbers_
6785
preceded by `$'.  *Note Value History: Value History.)
6786
 
6787
   You can save a value in a convenience variable with an assignment
6788
expression, just as you would set a variable in your program.  For
6789
example:
6790
 
6791
     set $foo = *object_ptr
6792
 
6793
would save in `$foo' the value contained in the object pointed to by
6794
`object_ptr'.
6795
 
6796
   Using a convenience variable for the first time creates it, but its
6797
value is `void' until you assign a new value.  You can alter the value
6798
with another assignment at any time.
6799
 
6800
   Convenience variables have no fixed types.  You can assign a
6801
convenience variable any type of value, including structures and
6802
arrays, even if that variable already has a value of a different type.
6803
The convenience variable, when used as an expression, has the type of
6804
its current value.
6805
 
6806
`show convenience'
6807
     Print a list of convenience variables used so far, and their
6808
     values.  Abbreviated `show conv'.
6809
 
6810
`init-if-undefined $VARIABLE = EXPRESSION'
6811
     Set a convenience variable if it has not already been set.  This
6812
     is useful for user-defined commands that keep some state.  It is
6813
     similar, in concept, to using local static variables with
6814
     initializers in C (except that convenience variables are global).
6815
     It can also be used to allow users to override default values used
6816
     in a command script.
6817
 
6818
     If the variable is already defined then the expression is not
6819
     evaluated so any side-effects do not occur.
6820
 
6821
   One of the ways to use a convenience variable is as a counter to be
6822
incremented or a pointer to be advanced.  For example, to print a field
6823
from successive elements of an array of structures:
6824
 
6825
     set $i = 0
6826
     print bar[$i++]->contents
6827
 
6828
Repeat that command by typing .
6829
 
6830
   Some convenience variables are created automatically by GDB and given
6831
values likely to be useful.
6832
 
6833
`$_'
6834
     The variable `$_' is automatically set by the `x' command to the
6835
     last address examined (*note Examining Memory: Memory.).  Other
6836
     commands which provide a default address for `x' to examine also
6837
     set `$_' to that address; these commands include `info line' and
6838
     `info breakpoint'.  The type of `$_' is `void *' except when set
6839
     by the `x' command, in which case it is a pointer to the type of
6840
     `$__'.
6841
 
6842
`$__'
6843
     The variable `$__' is automatically set by the `x' command to the
6844
     value found in the last address examined.  Its type is chosen to
6845
     match the format in which the data was printed.
6846
 
6847
`$_exitcode'
6848
     The variable `$_exitcode' is automatically set to the exit code
6849
     when the program being debugged terminates.
6850
 
6851
`$_siginfo'
6852
     The variable `$_siginfo' contains extra signal information (*note
6853
     extra signal information::).  Note that `$_siginfo' could be
6854
     empty, if the application has not yet received any signals.  For
6855
     example, it will be empty before you execute the `run' command.
6856
 
6857
   On HP-UX systems, if you refer to a function or variable name that
6858
begins with a dollar sign, GDB searches for a user or system name
6859
first, before it searches for a convenience variable.
6860
 
6861
   GDB also supplies some "convenience functions".  These have a syntax
6862
similar to convenience variables.  A convenience function can be used
6863
in an expression just like an ordinary function; however, a convenience
6864
function is implemented internally to GDB.
6865
 
6866
`help function'
6867
     Print a list of all convenience functions.
6868
 
6869

6870
File: gdb.info,  Node: Registers,  Next: Floating Point Hardware,  Prev: Convenience Vars,  Up: Data
6871
 
6872
10.11 Registers
6873
===============
6874
 
6875
You can refer to machine register contents, in expressions, as variables
6876
with names starting with `$'.  The names of registers are different for
6877
each machine; use `info registers' to see the names used on your
6878
machine.
6879
 
6880
`info registers'
6881
     Print the names and values of all registers except floating-point
6882
     and vector registers (in the selected stack frame).
6883
 
6884
`info all-registers'
6885
     Print the names and values of all registers, including
6886
     floating-point and vector registers (in the selected stack frame).
6887
 
6888
`info registers REGNAME ...'
6889
     Print the "relativized" value of each specified register REGNAME.
6890
     As discussed in detail below, register values are normally
6891
     relative to the selected stack frame.  REGNAME may be any register
6892
     name valid on the machine you are using, with or without the
6893
     initial `$'.
6894
 
6895
   GDB has four "standard" register names that are available (in
6896
expressions) on most machines--whenever they do not conflict with an
6897
architecture's canonical mnemonics for registers.  The register names
6898
`$pc' and `$sp' are used for the program counter register and the stack
6899
pointer.  `$fp' is used for a register that contains a pointer to the
6900
current stack frame, and `$ps' is used for a register that contains the
6901
processor status.  For example, you could print the program counter in
6902
hex with
6903
 
6904
     p/x $pc
6905
 
6906
or print the instruction to be executed next with
6907
 
6908
     x/i $pc
6909
 
6910
or add four to the stack pointer(1) with
6911
 
6912
     set $sp += 4
6913
 
6914
   Whenever possible, these four standard register names are available
6915
on your machine even though the machine has different canonical
6916
mnemonics, so long as there is no conflict.  The `info registers'
6917
command shows the canonical names.  For example, on the SPARC, `info
6918
registers' displays the processor status register as `$psr' but you can
6919
also refer to it as `$ps'; and on x86-based machines `$ps' is an alias
6920
for the EFLAGS register.
6921
 
6922
   GDB always considers the contents of an ordinary register as an
6923
integer when the register is examined in this way.  Some machines have
6924
special registers which can hold nothing but floating point; these
6925
registers are considered to have floating point values.  There is no way
6926
to refer to the contents of an ordinary register as floating point value
6927
(although you can _print_ it as a floating point value with `print/f
6928
$REGNAME').
6929
 
6930
   Some registers have distinct "raw" and "virtual" data formats.  This
6931
means that the data format in which the register contents are saved by
6932
the operating system is not the same one that your program normally
6933
sees.  For example, the registers of the 68881 floating point
6934
coprocessor are always saved in "extended" (raw) format, but all C
6935
programs expect to work with "double" (virtual) format.  In such cases,
6936
GDB normally works with the virtual format only (the format that makes
6937
sense for your program), but the `info registers' command prints the
6938
data in both formats.
6939
 
6940
   Some machines have special registers whose contents can be
6941
interpreted in several different ways.  For example, modern x86-based
6942
machines have SSE and MMX registers that can hold several values packed
6943
together in several different formats.  GDB refers to such registers in
6944
`struct' notation:
6945
 
6946
     (gdb) print $xmm1
6947
     $1 = {
6948
       v4_float = {0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044},
6949
       v2_double = {9.92129282474342e-303, 2.7585945287983262e-313},
6950
       v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6951
       v8_int16 = {0, 0, 14072, 315, 11, 0, 13, 0},
6952
       v4_int32 = {0, 20657912, 11, 13},
6953
       v2_int64 = {88725056443645952, 55834574859},
6954
       uint128 = 0x0000000d0000000b013b36f800000000
6955
     }
6956
 
6957
To set values of such registers, you need to tell GDB which view of the
6958
register you wish to change, as if you were assigning value to a
6959
`struct' member:
6960
 
6961
      (gdb) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6962
 
6963
   Normally, register values are relative to the selected stack frame
6964
(*note Selecting a Frame: Selection.).  This means that you get the
6965
value that the register would contain if all stack frames farther in
6966
were exited and their saved registers restored.  In order to see the
6967
true contents of hardware registers, you must select the innermost
6968
frame (with `frame 0').
6969
 
6970
   However, GDB must deduce where registers are saved, from the machine
6971
code generated by your compiler.  If some registers are not saved, or if
6972
GDB is unable to locate the saved registers, the selected stack frame
6973
makes no difference.
6974
 
6975
   ---------- Footnotes ----------
6976
 
6977
   (1) This is a way of removing one word from the stack, on machines
6978
where stacks grow downward in memory (most machines, nowadays).  This
6979
assumes that the innermost stack frame is selected; setting `$sp' is
6980
not allowed when other stack frames are selected.  To pop entire frames
6981
off the stack, regardless of machine architecture, use `return'; see
6982
*Note Returning from a Function: Returning.
6983
 
6984

6985
File: gdb.info,  Node: Floating Point Hardware,  Next: Vector Unit,  Prev: Registers,  Up: Data
6986
 
6987
10.12 Floating Point Hardware
6988
=============================
6989
 
6990
Depending on the configuration, GDB may be able to give you more
6991
information about the status of the floating point hardware.
6992
 
6993
`info float'
6994
     Display hardware-dependent information about the floating point
6995
     unit.  The exact contents and layout vary depending on the
6996
     floating point chip.  Currently, `info float' is supported on the
6997
     ARM and x86 machines.
6998
 
6999

7000
File: gdb.info,  Node: Vector Unit,  Next: OS Information,  Prev: Floating Point Hardware,  Up: Data
7001
 
7002
10.13 Vector Unit
7003
=================
7004
 
7005
Depending on the configuration, GDB may be able to give you more
7006
information about the status of the vector unit.
7007
 
7008
`info vector'
7009
     Display information about the vector unit.  The exact contents and
7010
     layout vary depending on the hardware.
7011
 
7012

7013
File: gdb.info,  Node: OS Information,  Next: Memory Region Attributes,  Prev: Vector Unit,  Up: Data
7014
 
7015
10.14 Operating System Auxiliary Information
7016
============================================
7017
 
7018
GDB provides interfaces to useful OS facilities that can help you debug
7019
your program.
7020
 
7021
   When GDB runs on a "Posix system" (such as GNU or Unix machines), it
7022
interfaces with the inferior via the `ptrace' system call.  The
7023
operating system creates a special sata structure, called `struct
7024
user', for this interface.  You can use the command `info udot' to
7025
display the contents of this data structure.
7026
 
7027
`info udot'
7028
     Display the contents of the `struct user' maintained by the OS
7029
     kernel for the program being debugged.  GDB displays the contents
7030
     of `struct user' as a list of hex numbers, similar to the
7031
     `examine' command.
7032
 
7033
   Some operating systems supply an "auxiliary vector" to programs at
7034
startup.  This is akin to the arguments and environment that you
7035
specify for a program, but contains a system-dependent variety of
7036
binary values that tell system libraries important details about the
7037
hardware, operating system, and process.  Each value's purpose is
7038
identified by an integer tag; the meanings are well-known but
7039
system-specific.  Depending on the configuration and operating system
7040
facilities, GDB may be able to show you this information.  For remote
7041
targets, this functionality may further depend on the remote stub's
7042
support of the `qXfer:auxv:read' packet, see *Note qXfer auxiliary
7043
vector read::.
7044
 
7045
`info auxv'
7046
     Display the auxiliary vector of the inferior, which can be either a
7047
     live process or a core dump file.  GDB prints each tag value
7048
     numerically, and also shows names and text descriptions for
7049
     recognized tags.  Some values in the vector are numbers, some bit
7050
     masks, and some pointers to strings or other data.  GDB displays
7051
     each value in the most appropriate form for a recognized tag, and
7052
     in hexadecimal for an unrecognized tag.
7053
 
7054
   On some targets, GDB can access operating-system-specific information
7055
and display it to user, without interpretation.  For remote targets,
7056
this functionality depends on the remote stub's support of the
7057
`qXfer:osdata:read' packet, see *Note qXfer osdata read::.
7058
 
7059
`info os processes'
7060
     Display the list of processes on the target.  For each process,
7061
     GDB prints the process identifier, the name of the user, and the
7062
     command corresponding to the process.
7063
 
7064

7065
File: gdb.info,  Node: Memory Region Attributes,  Next: Dump/Restore Files,  Prev: OS Information,  Up: Data
7066
 
7067
10.15 Memory Region Attributes
7068
==============================
7069
 
7070
"Memory region attributes" allow you to describe special handling
7071
required by regions of your target's memory.  GDB uses attributes to
7072
determine whether to allow certain types of memory accesses; whether to
7073
use specific width accesses; and whether to cache target memory.  By
7074
default the description of memory regions is fetched from the target
7075
(if the current target supports this), but the user can override the
7076
fetched regions.
7077
 
7078
   Defined memory regions can be individually enabled and disabled.
7079
When a memory region is disabled, GDB uses the default attributes when
7080
accessing memory in that region.  Similarly, if no memory regions have
7081
been defined, GDB uses the default attributes when accessing all memory.
7082
 
7083
   When a memory region is defined, it is given a number to identify it;
7084
to enable, disable, or remove a memory region, you specify that number.
7085
 
7086
`mem LOWER UPPER ATTRIBUTES...'
7087
     Define a memory region bounded by LOWER and UPPER with attributes
7088
     ATTRIBUTES..., and add it to the list of regions monitored by GDB.
7089
     Note that UPPER == 0 is a special case: it is treated as the
7090
     target's maximum memory address.  (0xffff on 16 bit targets,
7091
     0xffffffff on 32 bit targets, etc.)
7092
 
7093
`mem auto'
7094
     Discard any user changes to the memory regions and use
7095
     target-supplied regions, if available, or no regions if the target
7096
     does not support.
7097
 
7098
`delete mem NUMS...'
7099
     Remove memory regions NUMS... from the list of regions monitored
7100
     by GDB.
7101
 
7102
`disable mem NUMS...'
7103
     Disable monitoring of memory regions NUMS....  A disabled memory
7104
     region is not forgotten.  It may be enabled again later.
7105
 
7106
`enable mem NUMS...'
7107
     Enable monitoring of memory regions NUMS....
7108
 
7109
`info mem'
7110
     Print a table of all defined memory regions, with the following
7111
     columns for each region:
7112
 
7113
    _Memory Region Number_
7114
 
7115
    _Enabled or Disabled._
7116
          Enabled memory regions are marked with `y'.  Disabled memory
7117
          regions are marked with `n'.
7118
 
7119
    _Lo Address_
7120
          The address defining the inclusive lower bound of the memory
7121
          region.
7122
 
7123
    _Hi Address_
7124
          The address defining the exclusive upper bound of the memory
7125
          region.
7126
 
7127
    _Attributes_
7128
          The list of attributes set for this memory region.
7129
 
7130
10.15.1 Attributes
7131
------------------
7132
 
7133
10.15.1.1 Memory Access Mode
7134
............................
7135
 
7136
The access mode attributes set whether GDB may make read or write
7137
accesses to a memory region.
7138
 
7139
   While these attributes prevent GDB from performing invalid memory
7140
accesses, they do nothing to prevent the target system, I/O DMA, etc.
7141
from accessing memory.
7142
 
7143
`ro'
7144
     Memory is read only.
7145
 
7146
`wo'
7147
     Memory is write only.
7148
 
7149
`rw'
7150
     Memory is read/write.  This is the default.
7151
 
7152
10.15.1.2 Memory Access Size
7153
............................
7154
 
7155
The access size attribute tells GDB to use specific sized accesses in
7156
the memory region.  Often memory mapped device registers require
7157
specific sized accesses.  If no access size attribute is specified, GDB
7158
may use accesses of any size.
7159
 
7160
`8'
7161
     Use 8 bit memory accesses.
7162
 
7163
`16'
7164
     Use 16 bit memory accesses.
7165
 
7166
`32'
7167
     Use 32 bit memory accesses.
7168
 
7169
`64'
7170
     Use 64 bit memory accesses.
7171
 
7172
10.15.1.3 Data Cache
7173
....................
7174
 
7175
The data cache attributes set whether GDB will cache target memory.
7176
While this generally improves performance by reducing debug protocol
7177
overhead, it can lead to incorrect results because GDB does not know
7178
about volatile variables or memory mapped device registers.
7179
 
7180
`cache'
7181
     Enable GDB to cache target memory.
7182
 
7183
`nocache'
7184
     Disable GDB from caching target memory.  This is the default.
7185
 
7186
10.15.2 Memory Access Checking
7187
------------------------------
7188
 
7189
GDB can be instructed to refuse accesses to memory that is not
7190
explicitly described.  This can be useful if accessing such regions has
7191
undesired effects for a specific target, or to provide better error
7192
checking.  The following commands control this behaviour.
7193
 
7194
`set mem inaccessible-by-default [on|off]'
7195
     If `on' is specified, make  GDB treat memory not explicitly
7196
     described by the memory ranges as non-existent and refuse accesses
7197
     to such memory.  The checks are only performed if there's at least
7198
     one memory range defined.  If `off' is specified, make GDB treat
7199
     the memory not explicitly described by the memory ranges as RAM.
7200
     The default value is `on'.
7201
 
7202
`show mem inaccessible-by-default'
7203
     Show the current handling of accesses to unknown memory.
7204
 

powered by: WebSVN 2.1.0

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