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

Subversion Repositories openrisc_me

[/] [openrisc/] [tags/] [gdb/] [gdb-6.8/] [gdb-6.8.openrisc-2.1/] [gdb/] [doc/] [gdb.texinfo] - Blame information for rev 33

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
\input texinfo      @c -*-texinfo-*-
2
@c Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
3
@c 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4
@c Free Software Foundation, Inc.
5
@c
6
@c %**start of header
7
@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8
@c of @set vars.  However, you can override filename with makeinfo -o.
9
@setfilename gdb.info
10
@c
11
@include gdb-cfg.texi
12
@c
13
@settitle Debugging with @value{GDBN}
14
@setchapternewpage odd
15
@c %**end of header
16
 
17
@iftex
18
@c @smallbook
19
@c @cropmarks
20
@end iftex
21
 
22
@finalout
23
@syncodeindex ky cp
24
 
25
@c readline appendices use @vindex, @findex and @ftable,
26
@c annotate.texi and gdbmi use @findex.
27
@syncodeindex vr cp
28
@syncodeindex fn cp
29
 
30
@c !!set GDB manual's edition---not the same as GDB version!
31
@c This is updated by GNU Press.
32
@set EDITION Ninth
33
 
34
@c !!set GDB edit command default editor
35
@set EDITOR /bin/ex
36
 
37
@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
38
 
39
@c This is a dir.info fragment to support semi-automated addition of
40
@c manuals to an info tree.
41
@dircategory Software development
42
@direntry
43
* Gdb: (gdb).                     The GNU debugger.
44
@end direntry
45
 
46
@ifinfo
47
This file documents the @sc{gnu} debugger @value{GDBN}.
48
 
49
 
50
This is the @value{EDITION} Edition, of @cite{Debugging with
51
@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52
Version @value{GDBVN}.
53
 
54
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
55
              1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006@*
56
              Free Software Foundation, Inc.
57
 
58
Permission is granted to copy, distribute and/or modify this document
59
under the terms of the GNU Free Documentation License, Version 1.1 or
60
any later version published by the Free Software Foundation; with the
61
Invariant Sections being ``Free Software'' and ``Free Software Needs
62
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63
and with the Back-Cover Texts as in (a) below.
64
 
65
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
66
this GNU Manual.  Buying copies from GNU Press supports the FSF in
67
developing GNU and promoting software freedom.''
68
@end ifinfo
69
 
70
@titlepage
71
@title Debugging with @value{GDBN}
72
@subtitle The @sc{gnu} Source-Level Debugger
73
@sp 1
74
@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
75
@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
76
@page
77
@tex
78
{\parskip=0pt
79
\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
80
\hfill {\it Debugging with @value{GDBN}}\par
81
\hfill \TeX{}info \texinfoversion\par
82
}
83
@end tex
84
 
85
@vskip 0pt plus 1filll
86
Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
87
1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
88
Free Software Foundation, Inc.
89
@sp 2
90
Published by the Free Software Foundation @*
91
51 Franklin Street, Fifth Floor,
92
Boston, MA 02110-1301, USA@*
93
ISBN 1-882114-77-9 @*
94
 
95
Permission is granted to copy, distribute and/or modify this document
96
under the terms of the GNU Free Documentation License, Version 1.1 or
97
any later version published by the Free Software Foundation; with the
98
Invariant Sections being ``Free Software'' and ``Free Software Needs
99
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
100
and with the Back-Cover Texts as in (a) below.
101
 
102
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
103
this GNU Manual.  Buying copies from GNU Press supports the FSF in
104
developing GNU and promoting software freedom.''
105
@page
106
This edition of the GDB manual is dedicated to the memory of Fred
107
Fish.  Fred was a long-standing contributor to GDB and to Free
108
software in general.  We will miss him.
109
@end titlepage
110
@page
111
 
112
@ifnottex
113
@node Top, Summary, (dir), (dir)
114
 
115
@top Debugging with @value{GDBN}
116
 
117
This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
118
 
119
This is the @value{EDITION} Edition, for @value{GDBN} Version
120
@value{GDBVN}.
121
 
122
Copyright (C) 1988-2006 Free Software Foundation, Inc.
123
 
124
This edition of the GDB manual is dedicated to the memory of Fred
125
Fish.  Fred was a long-standing contributor to GDB and to Free
126
software in general.  We will miss him.
127
 
128
@menu
129
* Summary::                     Summary of @value{GDBN}
130
* Sample Session::              A sample @value{GDBN} session
131
 
132
* Invocation::                  Getting in and out of @value{GDBN}
133
* Commands::                    @value{GDBN} commands
134
* Running::                     Running programs under @value{GDBN}
135
* Stopping::                    Stopping and continuing
136
* Stack::                       Examining the stack
137
* Source::                      Examining source files
138
* Data::                        Examining data
139
* Macros::                      Preprocessor Macros
140
* Tracepoints::                 Debugging remote targets non-intrusively
141
* Overlays::                    Debugging programs that use overlays
142
 
143
* Languages::                   Using @value{GDBN} with different languages
144
 
145
* Symbols::                     Examining the symbol table
146
* Altering::                    Altering execution
147
* GDB Files::                   @value{GDBN} files
148
* Targets::                     Specifying a debugging target
149
* Remote Debugging::            Debugging remote programs
150
* Configurations::              Configuration-specific information
151
* Controlling GDB::             Controlling @value{GDBN}
152
* Sequences::                   Canned sequences of commands
153
* Interpreters::                Command Interpreters
154
* TUI::                         @value{GDBN} Text User Interface
155
* Emacs::                       Using @value{GDBN} under @sc{gnu} Emacs
156
* GDB/MI::                      @value{GDBN}'s Machine Interface.
157
* Annotations::                 @value{GDBN}'s annotation interface.
158
 
159
* GDB Bugs::                    Reporting bugs in @value{GDBN}
160
 
161
* Command Line Editing::        Command Line Editing
162
* Using History Interactively:: Using History Interactively
163
* Formatting Documentation::    How to format and print @value{GDBN} documentation
164
* Installing GDB::              Installing GDB
165
* Maintenance Commands::        Maintenance Commands
166
* Remote Protocol::             GDB Remote Serial Protocol
167
* Agent Expressions::           The GDB Agent Expression Mechanism
168
* Target Descriptions::         How targets can describe themselves to
169
                                @value{GDBN}
170
* Copying::                     GNU General Public License says
171
                                how you can copy and share GDB
172
* GNU Free Documentation License::  The license for this documentation
173
* Index::                       Index
174
@end menu
175
 
176
@end ifnottex
177
 
178
@contents
179
 
180
@node Summary
181
@unnumbered Summary of @value{GDBN}
182
 
183
The purpose of a debugger such as @value{GDBN} is to allow you to see what is
184
going on ``inside'' another program while it executes---or what another
185
program was doing at the moment it crashed.
186
 
187
@value{GDBN} can do four main kinds of things (plus other things in support of
188
these) to help you catch bugs in the act:
189
 
190
@itemize @bullet
191
@item
192
Start your program, specifying anything that might affect its behavior.
193
 
194
@item
195
Make your program stop on specified conditions.
196
 
197
@item
198
Examine what has happened, when your program has stopped.
199
 
200
@item
201
Change things in your program, so you can experiment with correcting the
202
effects of one bug and go on to learn about another.
203
@end itemize
204
 
205
You can use @value{GDBN} to debug programs written in C and C@t{++}.
206
For more information, see @ref{Supported Languages,,Supported Languages}.
207
For more information, see @ref{C,,C and C++}.
208
 
209
@cindex Modula-2
210
Support for Modula-2 is partial.  For information on Modula-2, see
211
@ref{Modula-2,,Modula-2}.
212
 
213
@cindex Pascal
214
Debugging Pascal programs which use sets, subranges, file variables, or
215
nested functions does not currently work.  @value{GDBN} does not support
216
entering expressions, printing values, or similar features using Pascal
217
syntax.
218
 
219
@cindex Fortran
220
@value{GDBN} can be used to debug programs written in Fortran, although
221
it may be necessary to refer to some variables with a trailing
222
underscore.
223
 
224
@value{GDBN} can be used to debug programs written in Objective-C,
225
using either the Apple/NeXT or the GNU Objective-C runtime.
226
 
227
@menu
228
* Free Software::               Freely redistributable software
229
* Contributors::                Contributors to GDB
230
@end menu
231
 
232
@node Free Software
233
@unnumberedsec Free Software
234
 
235
@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
236
General Public License
237
(GPL).  The GPL gives you the freedom to copy or adapt a licensed
238
program---but every person getting a copy also gets with it the
239
freedom to modify that copy (which means that they must get access to
240
the source code), and the freedom to distribute further copies.
241
Typical software companies use copyrights to limit your freedoms; the
242
Free Software Foundation uses the GPL to preserve these freedoms.
243
 
244
Fundamentally, the General Public License is a license which says that
245
you have these freedoms and that you cannot take these freedoms away
246
from anyone else.
247
 
248
@unnumberedsec Free Software Needs Free Documentation
249
 
250
The biggest deficiency in the free software community today is not in
251
the software---it is the lack of good free documentation that we can
252
include with the free software.  Many of our most important
253
programs do not come with free reference manuals and free introductory
254
texts.  Documentation is an essential part of any software package;
255
when an important free software package does not come with a free
256
manual and a free tutorial, that is a major gap.  We have many such
257
gaps today.
258
 
259
Consider Perl, for instance.  The tutorial manuals that people
260
normally use are non-free.  How did this come about?  Because the
261
authors of those manuals published them with restrictive terms---no
262
copying, no modification, source files not available---which exclude
263
them from the free software world.
264
 
265
That wasn't the first time this sort of thing happened, and it was far
266
from the last.  Many times we have heard a GNU user eagerly describe a
267
manual that he is writing, his intended contribution to the community,
268
only to learn that he had ruined everything by signing a publication
269
contract to make it non-free.
270
 
271
Free documentation, like free software, is a matter of freedom, not
272
price.  The problem with the non-free manual is not that publishers
273
charge a price for printed copies---that in itself is fine.  (The Free
274
Software Foundation sells printed copies of manuals, too.)  The
275
problem is the restrictions on the use of the manual.  Free manuals
276
are available in source code form, and give you permission to copy and
277
modify.  Non-free manuals do not allow this.
278
 
279
The criteria of freedom for a free manual are roughly the same as for
280
free software.  Redistribution (including the normal kinds of
281
commercial redistribution) must be permitted, so that the manual can
282
accompany every copy of the program, both on-line and on paper.
283
 
284
Permission for modification of the technical content is crucial too.
285
When people modify the software, adding or changing features, if they
286
are conscientious they will change the manual too---so they can
287
provide accurate and clear documentation for the modified program.  A
288
manual that leaves you no choice but to write a new manual to document
289
a changed version of the program is not really available to our
290
community.
291
 
292
Some kinds of limits on the way modification is handled are
293
acceptable.  For example, requirements to preserve the original
294
author's copyright notice, the distribution terms, or the list of
295
authors, are ok.  It is also no problem to require modified versions
296
to include notice that they were modified.  Even entire sections that
297
may not be deleted or changed are acceptable, as long as they deal
298
with nontechnical topics (like this one).  These kinds of restrictions
299
are acceptable because they don't obstruct the community's normal use
300
of the manual.
301
 
302
However, it must be possible to modify all the @emph{technical}
303
content of the manual, and then distribute the result in all the usual
304
media, through all the usual channels.  Otherwise, the restrictions
305
obstruct the use of the manual, it is not free, and we need another
306
manual to replace it.
307
 
308
Please spread the word about this issue.  Our community continues to
309
lose manuals to proprietary publishing.  If we spread the word that
310
free software needs free reference manuals and free tutorials, perhaps
311
the next person who wants to contribute by writing documentation will
312
realize, before it is too late, that only free manuals contribute to
313
the free software community.
314
 
315
If you are writing documentation, please insist on publishing it under
316
the GNU Free Documentation License or another free documentation
317
license.  Remember that this decision requires your approval---you
318
don't have to let the publisher decide.  Some commercial publishers
319
will use a free license if you insist, but they will not propose the
320
option; it is up to you to raise the issue and say firmly that this is
321
what you want.  If the publisher you are dealing with refuses, please
322
try other publishers.  If you're not sure whether a proposed license
323
is free, write to @email{licensing@@gnu.org}.
324
 
325
You can encourage commercial publishers to sell more free, copylefted
326
manuals and tutorials by buying them, and particularly by buying
327
copies from the publishers that paid for their writing or for major
328
improvements.  Meanwhile, try to avoid buying non-free documentation
329
at all.  Check the distribution terms of a manual before you buy it,
330
and insist that whoever seeks your business must respect your freedom.
331
Check the history of the book, and try to reward the publishers that
332
have paid or pay the authors to work on it.
333
 
334
The Free Software Foundation maintains a list of free documentation
335
published by other publishers, at
336
@url{http://www.fsf.org/doc/other-free-books.html}.
337
 
338
@node Contributors
339
@unnumberedsec Contributors to @value{GDBN}
340
 
341
Richard Stallman was the original author of @value{GDBN}, and of many
342
other @sc{gnu} programs.  Many others have contributed to its
343
development.  This section attempts to credit major contributors.  One
344
of the virtues of free software is that everyone is free to contribute
345
to it; with regret, we cannot actually acknowledge everyone here.  The
346
file @file{ChangeLog} in the @value{GDBN} distribution approximates a
347
blow-by-blow account.
348
 
349
Changes much prior to version 2.0 are lost in the mists of time.
350
 
351
@quotation
352
@emph{Plea:} Additions to this section are particularly welcome.  If you
353
or your friends (or enemies, to be evenhanded) have been unfairly
354
omitted from this list, we would like to add your names!
355
@end quotation
356
 
357
So that they may not regard their many labors as thankless, we
358
particularly thank those who shepherded @value{GDBN} through major
359
releases:
360
Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
361
Jim Blandy (release 4.18);
362
Jason Molenda (release 4.17);
363
Stan Shebs (release 4.14);
364
Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
365
Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
366
John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
367
Jim Kingdon (releases 3.5, 3.4, and 3.3);
368
and Randy Smith (releases 3.2, 3.1, and 3.0).
369
 
370
Richard Stallman, assisted at various times by Peter TerMaat, Chris
371
Hanson, and Richard Mlynarik, handled releases through 2.8.
372
 
373
Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
374
in @value{GDBN}, with significant additional contributions from Per
375
Bothner and Daniel Berlin.  James Clark wrote the @sc{gnu} C@t{++}
376
demangler.  Early work on C@t{++} was by Peter TerMaat (who also did
377
much general update work leading to release 3.0).
378
 
379
@value{GDBN} uses the BFD subroutine library to examine multiple
380
object-file formats; BFD was a joint project of David V.
381
Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
382
 
383
David Johnson wrote the original COFF support; Pace Willison did
384
the original support for encapsulated COFF.
385
 
386
Brent Benson of Harris Computer Systems contributed DWARF 2 support.
387
 
388
Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
389
Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
390
support.
391
Jean-Daniel Fekete contributed Sun 386i support.
392
Chris Hanson improved the HP9000 support.
393
Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
394
David Johnson contributed Encore Umax support.
395
Jyrki Kuoppala contributed Altos 3068 support.
396
Jeff Law contributed HP PA and SOM support.
397
Keith Packard contributed NS32K support.
398
Doug Rabson contributed Acorn Risc Machine support.
399
Bob Rusk contributed Harris Nighthawk CX-UX support.
400
Chris Smith contributed Convex support (and Fortran debugging).
401
Jonathan Stone contributed Pyramid support.
402
Michael Tiemann contributed SPARC support.
403
Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
404
Pace Willison contributed Intel 386 support.
405
Jay Vosburgh contributed Symmetry support.
406
Marko Mlinar, Ivan Guzvinec, Johan Rydverg, Alessandro Forin, Per
407
Bothner, Chris Ziomkowski and Jeremy Bennett contributed OpenRISC 1000 support.
408
 
409
Andreas Schwab contributed M68K @sc{gnu}/Linux support.
410
 
411
Rich Schaefer and Peter Schauer helped with support of SunOS shared
412
libraries.
413
 
414
Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
415
about several machine instruction sets.
416
 
417
Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
418
remote debugging.  Intel Corporation, Wind River Systems, AMD, and ARM
419
contributed remote debugging modules for the i960, VxWorks, A29K UDI,
420
and RDI targets, respectively.
421
 
422
Brian Fox is the author of the readline libraries providing
423
command-line editing and command history.
424
 
425
Andrew Beers of SUNY Buffalo wrote the language-switching code, the
426
Modula-2 support, and contributed the Languages chapter of this manual.
427
 
428
Fred Fish wrote most of the support for Unix System Vr4.
429
He also enhanced the command-completion support to cover C@t{++} overloaded
430
symbols.
431
 
432
Hitachi America (now Renesas America), Ltd. sponsored the support for
433
H8/300, H8/500, and Super-H processors.
434
 
435
NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
436
 
437
Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
438
processors.
439
 
440
Toshiba sponsored the support for the TX39 Mips processor.
441
 
442
Matsushita sponsored the support for the MN10200 and MN10300 processors.
443
 
444
Fujitsu sponsored the support for SPARClite and FR30 processors.
445
 
446
Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
447
watchpoints.
448
 
449
Michael Snyder added support for tracepoints.
450
 
451
Stu Grossman wrote gdbserver.
452
 
453
Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
454
nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
455
 
456
The following people at the Hewlett-Packard Company contributed
457
support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
458
(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
459
compiler, and the Text User Interface (nee Terminal User Interface):
460
Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
461
Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni.  Kim Haase
462
provided HP-specific information in this manual.
463
 
464
DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
465
Robert Hoehne made significant contributions to the DJGPP port.
466
 
467
Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
468
development since 1991.  Cygnus engineers who have worked on @value{GDBN}
469
fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
470
Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
471
Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
472
Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
473
Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni.  In
474
addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
475
JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
476
Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
477
Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
478
Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
479
Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
480
Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
481
Zuhn have made contributions both large and small.
482
 
483
Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
484
Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
485
 
486
Jim Blandy added support for preprocessor macros, while working for Red
487
Hat.
488
 
489
Andrew Cagney designed @value{GDBN}'s architecture vector.  Many
490
people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
491
Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
492
Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
493
Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
494
with the migration of old architectures to this new framework.
495
 
496
Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
497
unwinder framework, this consisting of a fresh new design featuring
498
frame IDs, independent frame sniffers, and the sentinel frame.  Mark
499
Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
500
libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
501
trad unwinders.  The architecture-specific changes, each involving a
502
complete rewrite of the architecture's frame code, were carried out by
503
Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
504
Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
505
Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
506
Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
507
Weigand.
508
 
509
Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
510
Tensilica, Inc.@: contributed support for Xtensa processors.  Others
511
who have worked on the Xtensa port of @value{GDBN} in the past include
512
Steve Tjiang, John Newlin, and Scott Foehner.
513
 
514
@node Sample Session
515
@chapter A Sample @value{GDBN} Session
516
 
517
You can use this manual at your leisure to read all about @value{GDBN}.
518
However, a handful of commands are enough to get started using the
519
debugger.  This chapter illustrates those commands.
520
 
521
@iftex
522
In this sample session, we emphasize user input like this: @b{input},
523
to make it easier to pick out from the surrounding output.
524
@end iftex
525
 
526
@c FIXME: this example may not be appropriate for some configs, where
527
@c FIXME...primary interest is in remote use.
528
 
529
One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
530
processor) exhibits the following bug: sometimes, when we change its
531
quote strings from the default, the commands used to capture one macro
532
definition within another stop working.  In the following short @code{m4}
533
session, we define a macro @code{foo} which expands to @code{0000}; we
534
then use the @code{m4} built-in @code{defn} to define @code{bar} as the
535
same thing.  However, when we change the open quote string to
536
@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
537
procedure fails to define a new synonym @code{baz}:
538
 
539
@smallexample
540
$ @b{cd gnu/m4}
541
$ @b{./m4}
542
@b{define(foo,0000)}
543
 
544
@b{foo}
545
0000
546
@b{define(bar,defn(`foo'))}
547
 
548
@b{bar}
549
0000
550
@b{changequote(<QUOTE>,<UNQUOTE>)}
551
 
552
@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
553
@b{baz}
554
@b{Ctrl-d}
555
m4: End of input: 0: fatal error: EOF in string
556
@end smallexample
557
 
558
@noindent
559
Let us use @value{GDBN} to try to see what is going on.
560
 
561
@smallexample
562
$ @b{@value{GDBP} m4}
563
@c FIXME: this falsifies the exact text played out, to permit smallbook
564
@c FIXME... format to come out better.
565
@value{GDBN} is free software and you are welcome to distribute copies
566
 of it under certain conditions; type "show copying" to see
567
 the conditions.
568
There is absolutely no warranty for @value{GDBN}; type "show warranty"
569
 for details.
570
 
571
@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
572
(@value{GDBP})
573
@end smallexample
574
 
575
@noindent
576
@value{GDBN} reads only enough symbol data to know where to find the
577
rest when needed; as a result, the first prompt comes up very quickly.
578
We now tell @value{GDBN} to use a narrower display width than usual, so
579
that examples fit in this manual.
580
 
581
@smallexample
582
(@value{GDBP}) @b{set width 70}
583
@end smallexample
584
 
585
@noindent
586
We need to see how the @code{m4} built-in @code{changequote} works.
587
Having looked at the source, we know the relevant subroutine is
588
@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
589
@code{break} command.
590
 
591
@smallexample
592
(@value{GDBP}) @b{break m4_changequote}
593
Breakpoint 1 at 0x62f4: file builtin.c, line 879.
594
@end smallexample
595
 
596
@noindent
597
Using the @code{run} command, we start @code{m4} running under @value{GDBN}
598
control; as long as control does not reach the @code{m4_changequote}
599
subroutine, the program runs as usual:
600
 
601
@smallexample
602
(@value{GDBP}) @b{run}
603
Starting program: /work/Editorial/gdb/gnu/m4/m4
604
@b{define(foo,0000)}
605
 
606
@b{foo}
607
0000
608
@end smallexample
609
 
610
@noindent
611
To trigger the breakpoint, we call @code{changequote}.  @value{GDBN}
612
suspends execution of @code{m4}, displaying information about the
613
context where it stops.
614
 
615
@smallexample
616
@b{changequote(<QUOTE>,<UNQUOTE>)}
617
 
618
Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
619
    at builtin.c:879
620
879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
621
@end smallexample
622
 
623
@noindent
624
Now we use the command @code{n} (@code{next}) to advance execution to
625
the next line of the current function.
626
 
627
@smallexample
628
(@value{GDBP}) @b{n}
629
882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
630
 : nil,
631
@end smallexample
632
 
633
@noindent
634
@code{set_quotes} looks like a promising subroutine.  We can go into it
635
by using the command @code{s} (@code{step}) instead of @code{next}.
636
@code{step} goes to the next line to be executed in @emph{any}
637
subroutine, so it steps into @code{set_quotes}.
638
 
639
@smallexample
640
(@value{GDBP}) @b{s}
641
set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
642
    at input.c:530
643
530         if (lquote != def_lquote)
644
@end smallexample
645
 
646
@noindent
647
The display that shows the subroutine where @code{m4} is now
648
suspended (and its arguments) is called a stack frame display.  It
649
shows a summary of the stack.  We can use the @code{backtrace}
650
command (which can also be spelled @code{bt}), to see where we are
651
in the stack as a whole: the @code{backtrace} command displays a
652
stack frame for each active subroutine.
653
 
654
@smallexample
655
(@value{GDBP}) @b{bt}
656
#0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
657
    at input.c:530
658
#1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
659
    at builtin.c:882
660
#2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
661
#3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
662
    at macro.c:71
663
#4  0x79dc in expand_input () at macro.c:40
664
#5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
665
@end smallexample
666
 
667
@noindent
668
We step through a few more lines to see what happens.  The first two
669
times, we can use @samp{s}; the next two times we use @code{n} to avoid
670
falling into the @code{xstrdup} subroutine.
671
 
672
@smallexample
673
(@value{GDBP}) @b{s}
674
0x3b5c  532         if (rquote != def_rquote)
675
(@value{GDBP}) @b{s}
676
0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
677
def_lquote : xstrdup(lq);
678
(@value{GDBP}) @b{n}
679
536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
680
 : xstrdup(rq);
681
(@value{GDBP}) @b{n}
682
538         len_lquote = strlen(rquote);
683
@end smallexample
684
 
685
@noindent
686
The last line displayed looks a little odd; we can examine the variables
687
@code{lquote} and @code{rquote} to see if they are in fact the new left
688
and right quotes we specified.  We use the command @code{p}
689
(@code{print}) to see their values.
690
 
691
@smallexample
692
(@value{GDBP}) @b{p lquote}
693
$1 = 0x35d40 "<QUOTE>"
694
(@value{GDBP}) @b{p rquote}
695
$2 = 0x35d50 "<UNQUOTE>"
696
@end smallexample
697
 
698
@noindent
699
@code{lquote} and @code{rquote} are indeed the new left and right quotes.
700
To look at some context, we can display ten lines of source
701
surrounding the current line with the @code{l} (@code{list}) command.
702
 
703
@smallexample
704
(@value{GDBP}) @b{l}
705
533             xfree(rquote);
706
534
707
535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
708
 : xstrdup (lq);
709
536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
710
 : xstrdup (rq);
711
537
712
538         len_lquote = strlen(rquote);
713
539         len_rquote = strlen(lquote);
714
540     @}
715
541
716
542     void
717
@end smallexample
718
 
719
@noindent
720
Let us step past the two lines that set @code{len_lquote} and
721
@code{len_rquote}, and then examine the values of those variables.
722
 
723
@smallexample
724
(@value{GDBP}) @b{n}
725
539         len_rquote = strlen(lquote);
726
(@value{GDBP}) @b{n}
727
540     @}
728
(@value{GDBP}) @b{p len_lquote}
729
$3 = 9
730
(@value{GDBP}) @b{p len_rquote}
731
$4 = 7
732
@end smallexample
733
 
734
@noindent
735
That certainly looks wrong, assuming @code{len_lquote} and
736
@code{len_rquote} are meant to be the lengths of @code{lquote} and
737
@code{rquote} respectively.  We can set them to better values using
738
the @code{p} command, since it can print the value of
739
any expression---and that expression can include subroutine calls and
740
assignments.
741
 
742
@smallexample
743
(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
744
$5 = 7
745
(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
746
$6 = 9
747
@end smallexample
748
 
749
@noindent
750
Is that enough to fix the problem of using the new quotes with the
751
@code{m4} built-in @code{defn}?  We can allow @code{m4} to continue
752
executing with the @code{c} (@code{continue}) command, and then try the
753
example that caused trouble initially:
754
 
755
@smallexample
756
(@value{GDBP}) @b{c}
757
Continuing.
758
 
759
@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
760
 
761
baz
762
0000
763
@end smallexample
764
 
765
@noindent
766
Success!  The new quotes now work just as well as the default ones.  The
767
problem seems to have been just the two typos defining the wrong
768
lengths.  We allow @code{m4} exit by giving it an EOF as input:
769
 
770
@smallexample
771
@b{Ctrl-d}
772
Program exited normally.
773
@end smallexample
774
 
775
@noindent
776
The message @samp{Program exited normally.} is from @value{GDBN}; it
777
indicates @code{m4} has finished executing.  We can end our @value{GDBN}
778
session with the @value{GDBN} @code{quit} command.
779
 
780
@smallexample
781
(@value{GDBP}) @b{quit}
782
@end smallexample
783
 
784
@node Invocation
785
@chapter Getting In and Out of @value{GDBN}
786
 
787
This chapter discusses how to start @value{GDBN}, and how to get out of it.
788
The essentials are:
789
@itemize @bullet
790
@item
791
type @samp{@value{GDBP}} to start @value{GDBN}.
792
@item
793
type @kbd{quit} or @kbd{Ctrl-d} to exit.
794
@end itemize
795
 
796
@menu
797
* Invoking GDB::                How to start @value{GDBN}
798
* Quitting GDB::                How to quit @value{GDBN}
799
* Shell Commands::              How to use shell commands inside @value{GDBN}
800
* Logging Output::              How to log @value{GDBN}'s output to a file
801
@end menu
802
 
803
@node Invoking GDB
804
@section Invoking @value{GDBN}
805
 
806
Invoke @value{GDBN} by running the program @code{@value{GDBP}}.  Once started,
807
@value{GDBN} reads commands from the terminal until you tell it to exit.
808
 
809
You can also run @code{@value{GDBP}} with a variety of arguments and options,
810
to specify more of your debugging environment at the outset.
811
 
812
The command-line options described here are designed
813
to cover a variety of situations; in some environments, some of these
814
options may effectively be unavailable.
815
 
816
The most usual way to start @value{GDBN} is with one argument,
817
specifying an executable program:
818
 
819
@smallexample
820
@value{GDBP} @var{program}
821
@end smallexample
822
 
823
@noindent
824
You can also start with both an executable program and a core file
825
specified:
826
 
827
@smallexample
828
@value{GDBP} @var{program} @var{core}
829
@end smallexample
830
 
831
You can, instead, specify a process ID as a second argument, if you want
832
to debug a running process:
833
 
834
@smallexample
835
@value{GDBP} @var{program} 1234
836
@end smallexample
837
 
838
@noindent
839
would attach @value{GDBN} to process @code{1234} (unless you also have a file
840
named @file{1234}; @value{GDBN} does check for a core file first).
841
 
842
Taking advantage of the second command-line argument requires a fairly
843
complete operating system; when you use @value{GDBN} as a remote
844
debugger attached to a bare board, there may not be any notion of
845
``process'', and there is often no way to get a core dump.  @value{GDBN}
846
will warn you if it is unable to attach or to read core dumps.
847
 
848
You can optionally have @code{@value{GDBP}} pass any arguments after the
849
executable file to the inferior using @code{--args}.  This option stops
850
option processing.
851
@smallexample
852
@value{GDBP} --args gcc -O2 -c foo.c
853
@end smallexample
854
This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
855
@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
856
 
857
You can run @code{@value{GDBP}} without printing the front material, which describes
858
@value{GDBN}'s non-warranty, by specifying @code{-silent}:
859
 
860
@smallexample
861
@value{GDBP} -silent
862
@end smallexample
863
 
864
@noindent
865
You can further control how @value{GDBN} starts up by using command-line
866
options.  @value{GDBN} itself can remind you of the options available.
867
 
868
@noindent
869
Type
870
 
871
@smallexample
872
@value{GDBP} -help
873
@end smallexample
874
 
875
@noindent
876
to display all available options and briefly describe their use
877
(@samp{@value{GDBP} -h} is a shorter equivalent).
878
 
879
All options and command line arguments you give are processed
880
in sequential order.  The order makes a difference when the
881
@samp{-x} option is used.
882
 
883
 
884
@menu
885
* File Options::                Choosing files
886
* Mode Options::                Choosing modes
887
* Startup::                     What @value{GDBN} does during startup
888
@end menu
889
 
890
@node File Options
891
@subsection Choosing Files
892
 
893
When @value{GDBN} starts, it reads any arguments other than options as
894
specifying an executable file and core file (or process ID).  This is
895
the same as if the arguments were specified by the @samp{-se} and
896
@samp{-c} (or @samp{-p}) options respectively.  (@value{GDBN} reads the
897
first argument that does not have an associated option flag as
898
equivalent to the @samp{-se} option followed by that argument; and the
899
second argument that does not have an associated option flag, if any, as
900
equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
901
If the second argument begins with a decimal digit, @value{GDBN} will
902
first attempt to attach to it as a process, and if that fails, attempt
903
to open it as a corefile.  If you have a corefile whose name begins with
904
a digit, you can prevent @value{GDBN} from treating it as a pid by
905
prefixing it with @file{./}, e.g.@: @file{./12345}.
906
 
907
If @value{GDBN} has not been configured to included core file support,
908
such as for most embedded targets, then it will complain about a second
909
argument and ignore it.
910
 
911
Many options have both long and short forms; both are shown in the
912
following list.  @value{GDBN} also recognizes the long forms if you truncate
913
them, so long as enough of the option is present to be unambiguous.
914
(If you prefer, you can flag option arguments with @samp{--} rather
915
than @samp{-}, though we illustrate the more usual convention.)
916
 
917
@c NOTE: the @cindex entries here use double dashes ON PURPOSE.  This
918
@c way, both those who look for -foo and --foo in the index, will find
919
@c it.
920
 
921
@table @code
922
@item -symbols @var{file}
923
@itemx -s @var{file}
924
@cindex @code{--symbols}
925
@cindex @code{-s}
926
Read symbol table from file @var{file}.
927
 
928
@item -exec @var{file}
929
@itemx -e @var{file}
930
@cindex @code{--exec}
931
@cindex @code{-e}
932
Use file @var{file} as the executable file to execute when appropriate,
933
and for examining pure data in conjunction with a core dump.
934
 
935
@item -se @var{file}
936
@cindex @code{--se}
937
Read symbol table from file @var{file} and use it as the executable
938
file.
939
 
940
@item -core @var{file}
941
@itemx -c @var{file}
942
@cindex @code{--core}
943
@cindex @code{-c}
944
Use file @var{file} as a core dump to examine.
945
 
946
@item -pid @var{number}
947
@itemx -p @var{number}
948
@cindex @code{--pid}
949
@cindex @code{-p}
950
Connect to process ID @var{number}, as with the @code{attach} command.
951
 
952
@item -command @var{file}
953
@itemx -x @var{file}
954
@cindex @code{--command}
955
@cindex @code{-x}
956
Execute @value{GDBN} commands from file @var{file}.  @xref{Command
957
Files,, Command files}.
958
 
959
@item -eval-command @var{command}
960
@itemx -ex @var{command}
961
@cindex @code{--eval-command}
962
@cindex @code{-ex}
963
Execute a single @value{GDBN} command.
964
 
965
This option may be used multiple times to call multiple commands.  It may
966
also be interleaved with @samp{-command} as required.
967
 
968
@smallexample
969
@value{GDBP} -ex 'target sim' -ex 'load' \
970
   -x setbreakpoints -ex 'run' a.out
971
@end smallexample
972
 
973
@item -directory @var{directory}
974
@itemx -d @var{directory}
975
@cindex @code{--directory}
976
@cindex @code{-d}
977
Add @var{directory} to the path to search for source and script files.
978
 
979
@item -r
980
@itemx -readnow
981
@cindex @code{--readnow}
982
@cindex @code{-r}
983
Read each symbol file's entire symbol table immediately, rather than
984
the default, which is to read it incrementally as it is needed.
985
This makes startup slower, but makes future operations faster.
986
 
987
@end table
988
 
989
@node Mode Options
990
@subsection Choosing Modes
991
 
992
You can run @value{GDBN} in various alternative modes---for example, in
993
batch mode or quiet mode.
994
 
995
@table @code
996
@item -nx
997
@itemx -n
998
@cindex @code{--nx}
999
@cindex @code{-n}
1000
Do not execute commands found in any initialization files.  Normally,
1001
@value{GDBN} executes the commands in these files after all the command
1002
options and arguments have been processed.  @xref{Command Files,,Command
1003
Files}.
1004
 
1005
@item -quiet
1006
@itemx -silent
1007
@itemx -q
1008
@cindex @code{--quiet}
1009
@cindex @code{--silent}
1010
@cindex @code{-q}
1011
``Quiet''.  Do not print the introductory and copyright messages.  These
1012
messages are also suppressed in batch mode.
1013
 
1014
@item -batch
1015
@cindex @code{--batch}
1016
Run in batch mode.  Exit with status @code{0} after processing all the
1017
command files specified with @samp{-x} (and all commands from
1018
initialization files, if not inhibited with @samp{-n}).  Exit with
1019
nonzero status if an error occurs in executing the @value{GDBN} commands
1020
in the command files.
1021
 
1022
Batch mode may be useful for running @value{GDBN} as a filter, for
1023
example to download and run a program on another computer; in order to
1024
make this more useful, the message
1025
 
1026
@smallexample
1027
Program exited normally.
1028
@end smallexample
1029
 
1030
@noindent
1031
(which is ordinarily issued whenever a program running under
1032
@value{GDBN} control terminates) is not issued when running in batch
1033
mode.
1034
 
1035
@item -batch-silent
1036
@cindex @code{--batch-silent}
1037
Run in batch mode exactly like @samp{-batch}, but totally silently.  All
1038
@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1039
unaffected).  This is much quieter than @samp{-silent} and would be useless
1040
for an interactive session.
1041
 
1042
This is particularly useful when using targets that give @samp{Loading section}
1043
messages, for example.
1044
 
1045
Note that targets that give their output via @value{GDBN}, as opposed to
1046
writing directly to @code{stdout}, will also be made silent.
1047
 
1048
@item -return-child-result
1049
@cindex @code{--return-child-result}
1050
The return code from @value{GDBN} will be the return code from the child
1051
process (the process being debugged), with the following exceptions:
1052
 
1053
@itemize @bullet
1054
@item
1055
@value{GDBN} exits abnormally.  E.g., due to an incorrect argument or an
1056
internal error.  In this case the exit code is the same as it would have been
1057
without @samp{-return-child-result}.
1058
@item
1059
The user quits with an explicit value.  E.g., @samp{quit 1}.
1060
@item
1061
The child process never runs, or is not allowed to terminate, in which case
1062
the exit code will be -1.
1063
@end itemize
1064
 
1065
This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1066
when @value{GDBN} is being used as a remote program loader or simulator
1067
interface.
1068
 
1069
@item -nowindows
1070
@itemx -nw
1071
@cindex @code{--nowindows}
1072
@cindex @code{-nw}
1073
``No windows''.  If @value{GDBN} comes with a graphical user interface
1074
(GUI) built in, then this option tells @value{GDBN} to only use the command-line
1075
interface.  If no GUI is available, this option has no effect.
1076
 
1077
@item -windows
1078
@itemx -w
1079
@cindex @code{--windows}
1080
@cindex @code{-w}
1081
If @value{GDBN} includes a GUI, then this option requires it to be
1082
used if possible.
1083
 
1084
@item -cd @var{directory}
1085
@cindex @code{--cd}
1086
Run @value{GDBN} using @var{directory} as its working directory,
1087
instead of the current directory.
1088
 
1089
@item -fullname
1090
@itemx -f
1091
@cindex @code{--fullname}
1092
@cindex @code{-f}
1093
@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1094
subprocess.  It tells @value{GDBN} to output the full file name and line
1095
number in a standard, recognizable fashion each time a stack frame is
1096
displayed (which includes each time your program stops).  This
1097
recognizable format looks like two @samp{\032} characters, followed by
1098
the file name, line number and character position separated by colons,
1099
and a newline.  The Emacs-to-@value{GDBN} interface program uses the two
1100
@samp{\032} characters as a signal to display the source code for the
1101
frame.
1102
 
1103
@item -epoch
1104
@cindex @code{--epoch}
1105
The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1106
@value{GDBN} as a subprocess.  It tells @value{GDBN} to modify its print
1107
routines so as to allow Epoch to display values of expressions in a
1108
separate window.
1109
 
1110
@item -annotate @var{level}
1111
@cindex @code{--annotate}
1112
This option sets the @dfn{annotation level} inside @value{GDBN}.  Its
1113
effect is identical to using @samp{set annotate @var{level}}
1114
(@pxref{Annotations}).  The annotation @var{level} controls how much
1115
information @value{GDBN} prints together with its prompt, values of
1116
expressions, source lines, and other types of output.  Level 0 is the
1117
normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1118
@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1119
that control @value{GDBN}, and level 2 has been deprecated.
1120
 
1121
The annotation mechanism has largely been superseded by @sc{gdb/mi}
1122
(@pxref{GDB/MI}).
1123
 
1124
@item --args
1125
@cindex @code{--args}
1126
Change interpretation of command line so that arguments following the
1127
executable file are passed as command line arguments to the inferior.
1128
This option stops option processing.
1129
 
1130
@item -baud @var{bps}
1131
@itemx -b @var{bps}
1132
@cindex @code{--baud}
1133
@cindex @code{-b}
1134
Set the line speed (baud rate or bits per second) of any serial
1135
interface used by @value{GDBN} for remote debugging.
1136
 
1137
@item -l @var{timeout}
1138
@cindex @code{-l}
1139
Set the timeout (in seconds) of any communication used by @value{GDBN}
1140
for remote debugging.
1141
 
1142
@item -tty @var{device}
1143
@itemx -t @var{device}
1144
@cindex @code{--tty}
1145
@cindex @code{-t}
1146
Run using @var{device} for your program's standard input and output.
1147
@c FIXME: kingdon thinks there is more to -tty.  Investigate.
1148
 
1149
@c resolve the situation of these eventually
1150
@item -tui
1151
@cindex @code{--tui}
1152
Activate the @dfn{Text User Interface} when starting.  The Text User
1153
Interface manages several text windows on the terminal, showing
1154
source, assembly, registers and @value{GDBN} command outputs
1155
(@pxref{TUI, ,@value{GDBN} Text User Interface}).  Alternatively, the
1156
Text User Interface can be enabled by invoking the program
1157
@samp{@value{GDBTUI}}.  Do not use this option if you run @value{GDBN} from
1158
Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
1159
 
1160
@c @item -xdb
1161
@c @cindex @code{--xdb}
1162
@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1163
@c For information, see the file @file{xdb_trans.html}, which is usually
1164
@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1165
@c systems.
1166
 
1167
@item -interpreter @var{interp}
1168
@cindex @code{--interpreter}
1169
Use the interpreter @var{interp} for interface with the controlling
1170
program or device.  This option is meant to be set by programs which
1171
communicate with @value{GDBN} using it as a back end.
1172
@xref{Interpreters, , Command Interpreters}.
1173
 
1174
@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1175
@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1176
The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0.  The
1177
previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1178
selected with @samp{--interpreter=mi1}, is deprecated.  Earlier
1179
@sc{gdb/mi} interfaces are no longer supported.
1180
 
1181
@item -write
1182
@cindex @code{--write}
1183
Open the executable and core files for both reading and writing.  This
1184
is equivalent to the @samp{set write on} command inside @value{GDBN}
1185
(@pxref{Patching}).
1186
 
1187
@item -statistics
1188
@cindex @code{--statistics}
1189
This option causes @value{GDBN} to print statistics about time and
1190
memory usage after it completes each command and returns to the prompt.
1191
 
1192
@item -version
1193
@cindex @code{--version}
1194
This option causes @value{GDBN} to print its version number and
1195
no-warranty blurb, and exit.
1196
 
1197
@end table
1198
 
1199
@node Startup
1200
@subsection What @value{GDBN} Does During Startup
1201
@cindex @value{GDBN} startup
1202
 
1203
Here's the description of what @value{GDBN} does during session startup:
1204
 
1205
@enumerate
1206
@item
1207
Sets up the command interpreter as specified by the command line
1208
(@pxref{Mode Options, interpreter}).
1209
 
1210
@item
1211
@cindex init file
1212
Reads the @dfn{init file} (if any) in your home directory@footnote{On
1213
DOS/Windows systems, the home directory is the one pointed to by the
1214
@code{HOME} environment variable.} and executes all the commands in
1215
that file.
1216
 
1217
@item
1218
Processes command line options and operands.
1219
 
1220
@item
1221
Reads and executes the commands from init file (if any) in the current
1222
working directory.  This is only done if the current directory is
1223
different from your home directory.  Thus, you can have more than one
1224
init file, one generic in your home directory, and another, specific
1225
to the program you are debugging, in the directory where you invoke
1226
@value{GDBN}.
1227
 
1228
@item
1229
Reads command files specified by the @samp{-x} option.  @xref{Command
1230
Files}, for more details about @value{GDBN} command files.
1231
 
1232
@item
1233
Reads the command history recorded in the @dfn{history file}.
1234
@xref{Command History}, for more details about the command history and the
1235
files where @value{GDBN} records it.
1236
@end enumerate
1237
 
1238
Init files use the same syntax as @dfn{command files} (@pxref{Command
1239
Files}) and are processed by @value{GDBN} in the same way.  The init
1240
file in your home directory can set options (such as @samp{set
1241
complaints}) that affect subsequent processing of command line options
1242
and operands.  Init files are not executed if you use the @samp{-nx}
1243
option (@pxref{Mode Options, ,Choosing Modes}).
1244
 
1245
@cindex init file name
1246
@cindex @file{.gdbinit}
1247
@cindex @file{gdb.ini}
1248
The @value{GDBN} init files are normally called @file{.gdbinit}.
1249
The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1250
the limitations of file names imposed by DOS filesystems.  The Windows
1251
ports of @value{GDBN} use the standard name, but if they find a
1252
@file{gdb.ini} file, they warn you about that and suggest to rename
1253
the file to the standard name.
1254
 
1255
 
1256
@node Quitting GDB
1257
@section Quitting @value{GDBN}
1258
@cindex exiting @value{GDBN}
1259
@cindex leaving @value{GDBN}
1260
 
1261
@table @code
1262
@kindex quit @r{[}@var{expression}@r{]}
1263
@kindex q @r{(@code{quit})}
1264
@item quit @r{[}@var{expression}@r{]}
1265
@itemx q
1266
To exit @value{GDBN}, use the @code{quit} command (abbreviated
1267
@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}).  If you
1268
do not supply @var{expression}, @value{GDBN} will terminate normally;
1269
otherwise it will terminate using the result of @var{expression} as the
1270
error code.
1271
@end table
1272
 
1273
@cindex interrupt
1274
An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1275
terminates the action of any @value{GDBN} command that is in progress and
1276
returns to @value{GDBN} command level.  It is safe to type the interrupt
1277
character at any time because @value{GDBN} does not allow it to take effect
1278
until a time when it is safe.
1279
 
1280
If you have been using @value{GDBN} to control an attached process or
1281
device, you can release it with the @code{detach} command
1282
(@pxref{Attach, ,Debugging an Already-running Process}).
1283
 
1284
@node Shell Commands
1285
@section Shell Commands
1286
 
1287
If you need to execute occasional shell commands during your
1288
debugging session, there is no need to leave or suspend @value{GDBN}; you can
1289
just use the @code{shell} command.
1290
 
1291
@table @code
1292
@kindex shell
1293
@cindex shell escape
1294
@item shell @var{command string}
1295
Invoke a standard shell to execute @var{command string}.
1296
If it exists, the environment variable @code{SHELL} determines which
1297
shell to run.  Otherwise @value{GDBN} uses the default shell
1298
(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1299
@end table
1300
 
1301
The utility @code{make} is often needed in development environments.
1302
You do not have to use the @code{shell} command for this purpose in
1303
@value{GDBN}:
1304
 
1305
@table @code
1306
@kindex make
1307
@cindex calling make
1308
@item make @var{make-args}
1309
Execute the @code{make} program with the specified
1310
arguments.  This is equivalent to @samp{shell make @var{make-args}}.
1311
@end table
1312
 
1313
@node Logging Output
1314
@section Logging Output
1315
@cindex logging @value{GDBN} output
1316
@cindex save @value{GDBN} output to a file
1317
 
1318
You may want to save the output of @value{GDBN} commands to a file.
1319
There are several commands to control @value{GDBN}'s logging.
1320
 
1321
@table @code
1322
@kindex set logging
1323
@item set logging on
1324
Enable logging.
1325
@item set logging off
1326
Disable logging.
1327
@cindex logging file name
1328
@item set logging file @var{file}
1329
Change the name of the current logfile.  The default logfile is @file{gdb.txt}.
1330
@item set logging overwrite [on|off]
1331
By default, @value{GDBN} will append to the logfile.  Set @code{overwrite} if
1332
you want @code{set logging on} to overwrite the logfile instead.
1333
@item set logging redirect [on|off]
1334
By default, @value{GDBN} output will go to both the terminal and the logfile.
1335
Set @code{redirect} if you want output to go only to the log file.
1336
@kindex show logging
1337
@item show logging
1338
Show the current values of the logging settings.
1339
@end table
1340
 
1341
@node Commands
1342
@chapter @value{GDBN} Commands
1343
 
1344
You can abbreviate a @value{GDBN} command to the first few letters of the command
1345
name, if that abbreviation is unambiguous; and you can repeat certain
1346
@value{GDBN} commands by typing just @key{RET}.  You can also use the @key{TAB}
1347
key to get @value{GDBN} to fill out the rest of a word in a command (or to
1348
show you the alternatives available, if there is more than one possibility).
1349
 
1350
@menu
1351
* Command Syntax::              How to give commands to @value{GDBN}
1352
* Completion::                  Command completion
1353
* Help::                        How to ask @value{GDBN} for help
1354
@end menu
1355
 
1356
@node Command Syntax
1357
@section Command Syntax
1358
 
1359
A @value{GDBN} command is a single line of input.  There is no limit on
1360
how long it can be.  It starts with a command name, which is followed by
1361
arguments whose meaning depends on the command name.  For example, the
1362
command @code{step} accepts an argument which is the number of times to
1363
step, as in @samp{step 5}.  You can also use the @code{step} command
1364
with no arguments.  Some commands do not allow any arguments.
1365
 
1366
@cindex abbreviation
1367
@value{GDBN} command names may always be truncated if that abbreviation is
1368
unambiguous.  Other possible command abbreviations are listed in the
1369
documentation for individual commands.  In some cases, even ambiguous
1370
abbreviations are allowed; for example, @code{s} is specially defined as
1371
equivalent to @code{step} even though there are other commands whose
1372
names start with @code{s}.  You can test abbreviations by using them as
1373
arguments to the @code{help} command.
1374
 
1375
@cindex repeating commands
1376
@kindex RET @r{(repeat last command)}
1377
A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1378
repeat the previous command.  Certain commands (for example, @code{run})
1379
will not repeat this way; these are commands whose unintentional
1380
repetition might cause trouble and which you are unlikely to want to
1381
repeat.  User-defined commands can disable this feature; see
1382
@ref{Define, dont-repeat}.
1383
 
1384
The @code{list} and @code{x} commands, when you repeat them with
1385
@key{RET}, construct new arguments rather than repeating
1386
exactly as typed.  This permits easy scanning of source or memory.
1387
 
1388
@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1389
output, in a way similar to the common utility @code{more}
1390
(@pxref{Screen Size,,Screen Size}).  Since it is easy to press one
1391
@key{RET} too many in this situation, @value{GDBN} disables command
1392
repetition after any command that generates this sort of display.
1393
 
1394
@kindex # @r{(a comment)}
1395
@cindex comment
1396
Any text from a @kbd{#} to the end of the line is a comment; it does
1397
nothing.  This is useful mainly in command files (@pxref{Command
1398
Files,,Command Files}).
1399
 
1400
@cindex repeating command sequences
1401
@kindex Ctrl-o @r{(operate-and-get-next)}
1402
The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1403
commands.  This command accepts the current line, like @key{RET}, and
1404
then fetches the next line relative to the current line from the history
1405
for editing.
1406
 
1407
@node Completion
1408
@section Command Completion
1409
 
1410
@cindex completion
1411
@cindex word completion
1412
@value{GDBN} can fill in the rest of a word in a command for you, if there is
1413
only one possibility; it can also show you what the valid possibilities
1414
are for the next word in a command, at any time.  This works for @value{GDBN}
1415
commands, @value{GDBN} subcommands, and the names of symbols in your program.
1416
 
1417
Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1418
of a word.  If there is only one possibility, @value{GDBN} fills in the
1419
word, and waits for you to finish the command (or press @key{RET} to
1420
enter it).  For example, if you type
1421
 
1422
@c FIXME "@key" does not distinguish its argument sufficiently to permit
1423
@c complete accuracy in these examples; space introduced for clarity.
1424
@c If texinfo enhancements make it unnecessary, it would be nice to
1425
@c replace " @key" by "@key" in the following...
1426
@smallexample
1427
(@value{GDBP}) info bre @key{TAB}
1428
@end smallexample
1429
 
1430
@noindent
1431
@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1432
the only @code{info} subcommand beginning with @samp{bre}:
1433
 
1434
@smallexample
1435
(@value{GDBP}) info breakpoints
1436
@end smallexample
1437
 
1438
@noindent
1439
You can either press @key{RET} at this point, to run the @code{info
1440
breakpoints} command, or backspace and enter something else, if
1441
@samp{breakpoints} does not look like the command you expected.  (If you
1442
were sure you wanted @code{info breakpoints} in the first place, you
1443
might as well just type @key{RET} immediately after @samp{info bre},
1444
to exploit command abbreviations rather than command completion).
1445
 
1446
If there is more than one possibility for the next word when you press
1447
@key{TAB}, @value{GDBN} sounds a bell.  You can either supply more
1448
characters and try again, or just press @key{TAB} a second time;
1449
@value{GDBN} displays all the possible completions for that word.  For
1450
example, you might want to set a breakpoint on a subroutine whose name
1451
begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1452
just sounds the bell.  Typing @key{TAB} again displays all the
1453
function names in your program that begin with those characters, for
1454
example:
1455
 
1456
@smallexample
1457
(@value{GDBP}) b make_ @key{TAB}
1458
@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1459
make_a_section_from_file     make_environ
1460
make_abs_section             make_function_type
1461
make_blockvector             make_pointer_type
1462
make_cleanup                 make_reference_type
1463
make_command                 make_symbol_completion_list
1464
(@value{GDBP}) b make_
1465
@end smallexample
1466
 
1467
@noindent
1468
After displaying the available possibilities, @value{GDBN} copies your
1469
partial input (@samp{b make_} in the example) so you can finish the
1470
command.
1471
 
1472
If you just want to see the list of alternatives in the first place, you
1473
can press @kbd{M-?} rather than pressing @key{TAB} twice.  @kbd{M-?}
1474
means @kbd{@key{META} ?}.  You can type this either by holding down a
1475
key designated as the @key{META} shift on your keyboard (if there is
1476
one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1477
 
1478
@cindex quotes in commands
1479
@cindex completion of quoted strings
1480
Sometimes the string you need, while logically a ``word'', may contain
1481
parentheses or other characters that @value{GDBN} normally excludes from
1482
its notion of a word.  To permit word completion to work in this
1483
situation, you may enclose words in @code{'} (single quote marks) in
1484
@value{GDBN} commands.
1485
 
1486
The most likely situation where you might need this is in typing the
1487
name of a C@t{++} function.  This is because C@t{++} allows function
1488
overloading (multiple definitions of the same function, distinguished
1489
by argument type).  For example, when you want to set a breakpoint you
1490
may need to distinguish whether you mean the version of @code{name}
1491
that takes an @code{int} parameter, @code{name(int)}, or the version
1492
that takes a @code{float} parameter, @code{name(float)}.  To use the
1493
word-completion facilities in this situation, type a single quote
1494
@code{'} at the beginning of the function name.  This alerts
1495
@value{GDBN} that it may need to consider more information than usual
1496
when you press @key{TAB} or @kbd{M-?} to request word completion:
1497
 
1498
@smallexample
1499
(@value{GDBP}) b 'bubble( @kbd{M-?}
1500
bubble(double,double)    bubble(int,int)
1501
(@value{GDBP}) b 'bubble(
1502
@end smallexample
1503
 
1504
In some cases, @value{GDBN} can tell that completing a name requires using
1505
quotes.  When this happens, @value{GDBN} inserts the quote for you (while
1506
completing as much as it can) if you do not type the quote in the first
1507
place:
1508
 
1509
@smallexample
1510
(@value{GDBP}) b bub @key{TAB}
1511
@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1512
(@value{GDBP}) b 'bubble(
1513
@end smallexample
1514
 
1515
@noindent
1516
In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1517
you have not yet started typing the argument list when you ask for
1518
completion on an overloaded symbol.
1519
 
1520
For more information about overloaded functions, see @ref{C Plus Plus
1521
Expressions, ,C@t{++} Expressions}.  You can use the command @code{set
1522
overload-resolution off} to disable overload resolution;
1523
see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1524
 
1525
 
1526
@node Help
1527
@section Getting Help
1528
@cindex online documentation
1529
@kindex help
1530
 
1531
You can always ask @value{GDBN} itself for information on its commands,
1532
using the command @code{help}.
1533
 
1534
@table @code
1535
@kindex h @r{(@code{help})}
1536
@item help
1537
@itemx h
1538
You can use @code{help} (abbreviated @code{h}) with no arguments to
1539
display a short list of named classes of commands:
1540
 
1541
@smallexample
1542
(@value{GDBP}) help
1543
List of classes of commands:
1544
 
1545
aliases -- Aliases of other commands
1546
breakpoints -- Making program stop at certain points
1547
data -- Examining data
1548
files -- Specifying and examining files
1549
internals -- Maintenance commands
1550
obscure -- Obscure features
1551
running -- Running the program
1552
stack -- Examining the stack
1553
status -- Status inquiries
1554
support -- Support facilities
1555
tracepoints -- Tracing of program execution without
1556
               stopping the program
1557
user-defined -- User-defined commands
1558
 
1559
Type "help" followed by a class name for a list of
1560
commands in that class.
1561
Type "help" followed by command name for full
1562
documentation.
1563
Command name abbreviations are allowed if unambiguous.
1564
(@value{GDBP})
1565
@end smallexample
1566
@c the above line break eliminates huge line overfull...
1567
 
1568
@item help @var{class}
1569
Using one of the general help classes as an argument, you can get a
1570
list of the individual commands in that class.  For example, here is the
1571
help display for the class @code{status}:
1572
 
1573
@smallexample
1574
(@value{GDBP}) help status
1575
Status inquiries.
1576
 
1577
List of commands:
1578
 
1579
@c Line break in "show" line falsifies real output, but needed
1580
@c to fit in smallbook page size.
1581
info -- Generic command for showing things
1582
        about the program being debugged
1583
show -- Generic command for showing things
1584
        about the debugger
1585
 
1586
Type "help" followed by command name for full
1587
documentation.
1588
Command name abbreviations are allowed if unambiguous.
1589
(@value{GDBP})
1590
@end smallexample
1591
 
1592
@item help @var{command}
1593
With a command name as @code{help} argument, @value{GDBN} displays a
1594
short paragraph on how to use that command.
1595
 
1596
@kindex apropos
1597
@item apropos @var{args}
1598
The @code{apropos} command searches through all of the @value{GDBN}
1599
commands, and their documentation, for the regular expression specified in
1600
@var{args}. It prints out all matches found. For example:
1601
 
1602
@smallexample
1603
apropos reload
1604
@end smallexample
1605
 
1606
@noindent
1607
results in:
1608
 
1609
@smallexample
1610
@c @group
1611
set symbol-reloading -- Set dynamic symbol table reloading
1612
                        multiple times in one run
1613
show symbol-reloading -- Show dynamic symbol table reloading
1614
                        multiple times in one run
1615
@c @end group
1616
@end smallexample
1617
 
1618
@kindex complete
1619
@item complete @var{args}
1620
The @code{complete @var{args}} command lists all the possible completions
1621
for the beginning of a command.  Use @var{args} to specify the beginning of the
1622
command you want completed.  For example:
1623
 
1624
@smallexample
1625
complete i
1626
@end smallexample
1627
 
1628
@noindent results in:
1629
 
1630
@smallexample
1631
@group
1632
if
1633
ignore
1634
info
1635
inspect
1636
@end group
1637
@end smallexample
1638
 
1639
@noindent This is intended for use by @sc{gnu} Emacs.
1640
@end table
1641
 
1642
In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1643
and @code{show} to inquire about the state of your program, or the state
1644
of @value{GDBN} itself.  Each command supports many topics of inquiry; this
1645
manual introduces each of them in the appropriate context.  The listings
1646
under @code{info} and under @code{show} in the Index point to
1647
all the sub-commands.  @xref{Index}.
1648
 
1649
@c @group
1650
@table @code
1651
@kindex info
1652
@kindex i @r{(@code{info})}
1653
@item info
1654
This command (abbreviated @code{i}) is for describing the state of your
1655
program.  For example, you can show the arguments passed to a function
1656
with @code{info args}, list the registers currently in use with @code{info
1657
registers}, or list the breakpoints you have set with @code{info breakpoints}.
1658
You can get a complete list of the @code{info} sub-commands with
1659
@w{@code{help info}}.
1660
 
1661
@kindex set
1662
@item set
1663
You can assign the result of an expression to an environment variable with
1664
@code{set}.  For example, you can set the @value{GDBN} prompt to a $-sign with
1665
@code{set prompt $}.
1666
 
1667
@kindex show
1668
@item show
1669
In contrast to @code{info}, @code{show} is for describing the state of
1670
@value{GDBN} itself.
1671
You can change most of the things you can @code{show}, by using the
1672
related command @code{set}; for example, you can control what number
1673
system is used for displays with @code{set radix}, or simply inquire
1674
which is currently in use with @code{show radix}.
1675
 
1676
@kindex info set
1677
To display all the settable parameters and their current
1678
values, you can use @code{show} with no arguments; you may also use
1679
@code{info set}.  Both commands produce the same display.
1680
@c FIXME: "info set" violates the rule that "info" is for state of
1681
@c FIXME...program.  Ck w/ GNU: "info set" to be called something else,
1682
@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1683
@end table
1684
@c @end group
1685
 
1686
Here are three miscellaneous @code{show} subcommands, all of which are
1687
exceptional in lacking corresponding @code{set} commands:
1688
 
1689
@table @code
1690
@kindex show version
1691
@cindex @value{GDBN} version number
1692
@item show version
1693
Show what version of @value{GDBN} is running.  You should include this
1694
information in @value{GDBN} bug-reports.  If multiple versions of
1695
@value{GDBN} are in use at your site, you may need to determine which
1696
version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1697
commands are introduced, and old ones may wither away.  Also, many
1698
system vendors ship variant versions of @value{GDBN}, and there are
1699
variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1700
The version number is the same as the one announced when you start
1701
@value{GDBN}.
1702
 
1703
@kindex show copying
1704
@kindex info copying
1705
@cindex display @value{GDBN} copyright
1706
@item show copying
1707
@itemx info copying
1708
Display information about permission for copying @value{GDBN}.
1709
 
1710
@kindex show warranty
1711
@kindex info warranty
1712
@item show warranty
1713
@itemx info warranty
1714
Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1715
if your version of @value{GDBN} comes with one.
1716
 
1717
@end table
1718
 
1719
@node Running
1720
@chapter Running Programs Under @value{GDBN}
1721
 
1722
When you run a program under @value{GDBN}, you must first generate
1723
debugging information when you compile it.
1724
 
1725
You may start @value{GDBN} with its arguments, if any, in an environment
1726
of your choice.  If you are doing native debugging, you may redirect
1727
your program's input and output, debug an already running process, or
1728
kill a child process.
1729
 
1730
@menu
1731
* Compilation::                 Compiling for debugging
1732
* Starting::                    Starting your program
1733
* Arguments::                   Your program's arguments
1734
* Environment::                 Your program's environment
1735
 
1736
* Working Directory::           Your program's working directory
1737
* Input/Output::                Your program's input and output
1738
* Attach::                      Debugging an already-running process
1739
* Kill Process::                Killing the child process
1740
 
1741
* Threads::                     Debugging programs with multiple threads
1742
* Processes::                   Debugging programs with multiple processes
1743
* Checkpoint/Restart::          Setting a @emph{bookmark} to return to later
1744
@end menu
1745
 
1746
@node Compilation
1747
@section Compiling for Debugging
1748
 
1749
In order to debug a program effectively, you need to generate
1750
debugging information when you compile it.  This debugging information
1751
is stored in the object file; it describes the data type of each
1752
variable or function and the correspondence between source line numbers
1753
and addresses in the executable code.
1754
 
1755
To request debugging information, specify the @samp{-g} option when you run
1756
the compiler.
1757
 
1758
Programs that are to be shipped to your customers are compiled with
1759
optimizations, using the @samp{-O} compiler option.  However, many
1760
compilers are unable to handle the @samp{-g} and @samp{-O} options
1761
together.  Using those compilers, you cannot generate optimized
1762
executables containing debugging information.
1763
 
1764
@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1765
without @samp{-O}, making it possible to debug optimized code.  We
1766
recommend that you @emph{always} use @samp{-g} whenever you compile a
1767
program.  You may think your program is correct, but there is no sense
1768
in pushing your luck.
1769
 
1770
@cindex optimized code, debugging
1771
@cindex debugging optimized code
1772
When you debug a program compiled with @samp{-g -O}, remember that the
1773
optimizer is rearranging your code; the debugger shows you what is
1774
really there.  Do not be too surprised when the execution path does not
1775
exactly match your source file!  An extreme example: if you define a
1776
variable, but never use it, @value{GDBN} never sees that
1777
variable---because the compiler optimizes it out of existence.
1778
 
1779
Some things do not work as well with @samp{-g -O} as with just
1780
@samp{-g}, particularly on machines with instruction scheduling.  If in
1781
doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1782
please report it to us as a bug (including a test case!).
1783
@xref{Variables}, for more information about debugging optimized code.
1784
 
1785
Older versions of the @sc{gnu} C compiler permitted a variant option
1786
@w{@samp{-gg}} for debugging information.  @value{GDBN} no longer supports this
1787
format; if your @sc{gnu} C compiler has this option, do not use it.
1788
 
1789
@value{GDBN} knows about preprocessor macros and can show you their
1790
expansion (@pxref{Macros}).  Most compilers do not include information
1791
about preprocessor macros in the debugging information if you specify
1792
the @option{-g} flag alone, because this information is rather large.
1793
Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1794
provides macro information if you specify the options
1795
@option{-gdwarf-2} and @option{-g3}; the former option requests
1796
debugging information in the Dwarf 2 format, and the latter requests
1797
``extra information''.  In the future, we hope to find more compact
1798
ways to represent macro information, so that it can be included with
1799
@option{-g} alone.
1800
 
1801
@need 2000
1802
@node Starting
1803
@section Starting your Program
1804
@cindex starting
1805
@cindex running
1806
 
1807
@table @code
1808
@kindex run
1809
@kindex r @r{(@code{run})}
1810
@item run
1811
@itemx r
1812
Use the @code{run} command to start your program under @value{GDBN}.
1813
You must first specify the program name (except on VxWorks) with an
1814
argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1815
@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1816
(@pxref{Files, ,Commands to Specify Files}).
1817
 
1818
@end table
1819
 
1820
If you are running your program in an execution environment that
1821
supports processes, @code{run} creates an inferior process and makes
1822
that process run your program.  (In environments without processes,
1823
@code{run} jumps to the start of your program.)
1824
 
1825
The execution of a program is affected by certain information it
1826
receives from its superior.  @value{GDBN} provides ways to specify this
1827
information, which you must do @emph{before} starting your program.  (You
1828
can change it after starting your program, but such changes only affect
1829
your program the next time you start it.)  This information may be
1830
divided into four categories:
1831
 
1832
@table @asis
1833
@item The @emph{arguments.}
1834
Specify the arguments to give your program as the arguments of the
1835
@code{run} command.  If a shell is available on your target, the shell
1836
is used to pass the arguments, so that you may use normal conventions
1837
(such as wildcard expansion or variable substitution) in describing
1838
the arguments.
1839
In Unix systems, you can control which shell is used with the
1840
@code{SHELL} environment variable.
1841
@xref{Arguments, ,Your Program's Arguments}.
1842
 
1843
@item The @emph{environment.}
1844
Your program normally inherits its environment from @value{GDBN}, but you can
1845
use the @value{GDBN} commands @code{set environment} and @code{unset
1846
environment} to change parts of the environment that affect
1847
your program.  @xref{Environment, ,Your Program's Environment}.
1848
 
1849
@item The @emph{working directory.}
1850
Your program inherits its working directory from @value{GDBN}.  You can set
1851
the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1852
@xref{Working Directory, ,Your Program's Working Directory}.
1853
 
1854
@item The @emph{standard input and output.}
1855
Your program normally uses the same device for standard input and
1856
standard output as @value{GDBN} is using.  You can redirect input and output
1857
in the @code{run} command line, or you can use the @code{tty} command to
1858
set a different device for your program.
1859
@xref{Input/Output, ,Your Program's Input and Output}.
1860
 
1861
@cindex pipes
1862
@emph{Warning:} While input and output redirection work, you cannot use
1863
pipes to pass the output of the program you are debugging to another
1864
program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1865
wrong program.
1866
@end table
1867
 
1868
When you issue the @code{run} command, your program begins to execute
1869
immediately.  @xref{Stopping, ,Stopping and Continuing}, for discussion
1870
of how to arrange for your program to stop.  Once your program has
1871
stopped, you may call functions in your program, using the @code{print}
1872
or @code{call} commands.  @xref{Data, ,Examining Data}.
1873
 
1874
If the modification time of your symbol file has changed since the last
1875
time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1876
table, and reads it again.  When it does this, @value{GDBN} tries to retain
1877
your current breakpoints.
1878
 
1879
@table @code
1880
@kindex start
1881
@item start
1882
@cindex run to main procedure
1883
The name of the main procedure can vary from language to language.
1884
With C or C@t{++}, the main procedure name is always @code{main}, but
1885
other languages such as Ada do not require a specific name for their
1886
main procedure.  The debugger provides a convenient way to start the
1887
execution of the program and to stop at the beginning of the main
1888
procedure, depending on the language used.
1889
 
1890
The @samp{start} command does the equivalent of setting a temporary
1891
breakpoint at the beginning of the main procedure and then invoking
1892
the @samp{run} command.
1893
 
1894
@cindex elaboration phase
1895
Some programs contain an @dfn{elaboration} phase where some startup code is
1896
executed before the main procedure is called.  This depends on the
1897
languages used to write your program.  In C@t{++}, for instance,
1898
constructors for static and global objects are executed before
1899
@code{main} is called.  It is therefore possible that the debugger stops
1900
before reaching the main procedure.  However, the temporary breakpoint
1901
will remain to halt execution.
1902
 
1903
Specify the arguments to give to your program as arguments to the
1904
@samp{start} command.  These arguments will be given verbatim to the
1905
underlying @samp{run} command.  Note that the same arguments will be
1906
reused if no argument is provided during subsequent calls to
1907
@samp{start} or @samp{run}.
1908
 
1909
It is sometimes necessary to debug the program during elaboration.  In
1910
these cases, using the @code{start} command would stop the execution of
1911
your program too late, as the program would have already completed the
1912
elaboration phase.  Under these circumstances, insert breakpoints in your
1913
elaboration code before running your program.
1914
@end table
1915
 
1916
@node Arguments
1917
@section Your Program's Arguments
1918
 
1919
@cindex arguments (to your program)
1920
The arguments to your program can be specified by the arguments of the
1921
@code{run} command.
1922
They are passed to a shell, which expands wildcard characters and
1923
performs redirection of I/O, and thence to your program.  Your
1924
@code{SHELL} environment variable (if it exists) specifies what shell
1925
@value{GDBN} uses.  If you do not define @code{SHELL}, @value{GDBN} uses
1926
the default shell (@file{/bin/sh} on Unix).
1927
 
1928
On non-Unix systems, the program is usually invoked directly by
1929
@value{GDBN}, which emulates I/O redirection via the appropriate system
1930
calls, and the wildcard characters are expanded by the startup code of
1931
the program, not by the shell.
1932
 
1933
@code{run} with no arguments uses the same arguments used by the previous
1934
@code{run}, or those set by the @code{set args} command.
1935
 
1936
@table @code
1937
@kindex set args
1938
@item set args
1939
Specify the arguments to be used the next time your program is run.  If
1940
@code{set args} has no arguments, @code{run} executes your program
1941
with no arguments.  Once you have run your program with arguments,
1942
using @code{set args} before the next @code{run} is the only way to run
1943
it again without arguments.
1944
 
1945
@kindex show args
1946
@item show args
1947
Show the arguments to give your program when it is started.
1948
@end table
1949
 
1950
@node Environment
1951
@section Your Program's Environment
1952
 
1953
@cindex environment (of your program)
1954
The @dfn{environment} consists of a set of environment variables and
1955
their values.  Environment variables conventionally record such things as
1956
your user name, your home directory, your terminal type, and your search
1957
path for programs to run.  Usually you set up environment variables with
1958
the shell and they are inherited by all the other programs you run.  When
1959
debugging, it can be useful to try running your program with a modified
1960
environment without having to start @value{GDBN} over again.
1961
 
1962
@table @code
1963
@kindex path
1964
@item path @var{directory}
1965
Add @var{directory} to the front of the @code{PATH} environment variable
1966
(the search path for executables) that will be passed to your program.
1967
The value of @code{PATH} used by @value{GDBN} does not change.
1968
You may specify several directory names, separated by whitespace or by a
1969
system-dependent separator character (@samp{:} on Unix, @samp{;} on
1970
MS-DOS and MS-Windows).  If @var{directory} is already in the path, it
1971
is moved to the front, so it is searched sooner.
1972
 
1973
You can use the string @samp{$cwd} to refer to whatever is the current
1974
working directory at the time @value{GDBN} searches the path.  If you
1975
use @samp{.} instead, it refers to the directory where you executed the
1976
@code{path} command.  @value{GDBN} replaces @samp{.} in the
1977
@var{directory} argument (with the current path) before adding
1978
@var{directory} to the search path.
1979
@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1980
@c document that, since repeating it would be a no-op.
1981
 
1982
@kindex show paths
1983
@item show paths
1984
Display the list of search paths for executables (the @code{PATH}
1985
environment variable).
1986
 
1987
@kindex show environment
1988
@item show environment @r{[}@var{varname}@r{]}
1989
Print the value of environment variable @var{varname} to be given to
1990
your program when it starts.  If you do not supply @var{varname},
1991
print the names and values of all environment variables to be given to
1992
your program.  You can abbreviate @code{environment} as @code{env}.
1993
 
1994
@kindex set environment
1995
@item set environment @var{varname} @r{[}=@var{value}@r{]}
1996
Set environment variable @var{varname} to @var{value}.  The value
1997
changes for your program only, not for @value{GDBN} itself.  @var{value} may
1998
be any string; the values of environment variables are just strings, and
1999
any interpretation is supplied by your program itself.  The @var{value}
2000
parameter is optional; if it is eliminated, the variable is set to a
2001
null value.
2002
@c "any string" here does not include leading, trailing
2003
@c blanks. Gnu asks: does anyone care?
2004
 
2005
For example, this command:
2006
 
2007
@smallexample
2008
set env USER = foo
2009
@end smallexample
2010
 
2011
@noindent
2012
tells the debugged program, when subsequently run, that its user is named
2013
@samp{foo}.  (The spaces around @samp{=} are used for clarity here; they
2014
are not actually required.)
2015
 
2016
@kindex unset environment
2017
@item unset environment @var{varname}
2018
Remove variable @var{varname} from the environment to be passed to your
2019
program.  This is different from @samp{set env @var{varname} =};
2020
@code{unset environment} removes the variable from the environment,
2021
rather than assigning it an empty value.
2022
@end table
2023
 
2024
@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2025
the shell indicated
2026
by your @code{SHELL} environment variable if it exists (or
2027
@code{/bin/sh} if not).  If your @code{SHELL} variable names a shell
2028
that runs an initialization file---such as @file{.cshrc} for C-shell, or
2029
@file{.bashrc} for BASH---any variables you set in that file affect
2030
your program.  You may wish to move setting of environment variables to
2031
files that are only run when you sign on, such as @file{.login} or
2032
@file{.profile}.
2033
 
2034
@node Working Directory
2035
@section Your Program's Working Directory
2036
 
2037
@cindex working directory (of your program)
2038
Each time you start your program with @code{run}, it inherits its
2039
working directory from the current working directory of @value{GDBN}.
2040
The @value{GDBN} working directory is initially whatever it inherited
2041
from its parent process (typically the shell), but you can specify a new
2042
working directory in @value{GDBN} with the @code{cd} command.
2043
 
2044
The @value{GDBN} working directory also serves as a default for the commands
2045
that specify files for @value{GDBN} to operate on.  @xref{Files, ,Commands to
2046
Specify Files}.
2047
 
2048
@table @code
2049
@kindex cd
2050
@cindex change working directory
2051
@item cd @var{directory}
2052
Set the @value{GDBN} working directory to @var{directory}.
2053
 
2054
@kindex pwd
2055
@item pwd
2056
Print the @value{GDBN} working directory.
2057
@end table
2058
 
2059
It is generally impossible to find the current working directory of
2060
the process being debugged (since a program can change its directory
2061
during its run).  If you work on a system where @value{GDBN} is
2062
configured with the @file{/proc} support, you can use the @code{info
2063
proc} command (@pxref{SVR4 Process Information}) to find out the
2064
current working directory of the debuggee.
2065
 
2066
@node Input/Output
2067
@section Your Program's Input and Output
2068
 
2069
@cindex redirection
2070
@cindex i/o
2071
@cindex terminal
2072
By default, the program you run under @value{GDBN} does input and output to
2073
the same terminal that @value{GDBN} uses.  @value{GDBN} switches the terminal
2074
to its own terminal modes to interact with you, but it records the terminal
2075
modes your program was using and switches back to them when you continue
2076
running your program.
2077
 
2078
@table @code
2079
@kindex info terminal
2080
@item info terminal
2081
Displays information recorded by @value{GDBN} about the terminal modes your
2082
program is using.
2083
@end table
2084
 
2085
You can redirect your program's input and/or output using shell
2086
redirection with the @code{run} command.  For example,
2087
 
2088
@smallexample
2089
run > outfile
2090
@end smallexample
2091
 
2092
@noindent
2093
starts your program, diverting its output to the file @file{outfile}.
2094
 
2095
@kindex tty
2096
@cindex controlling terminal
2097
Another way to specify where your program should do input and output is
2098
with the @code{tty} command.  This command accepts a file name as
2099
argument, and causes this file to be the default for future @code{run}
2100
commands.  It also resets the controlling terminal for the child
2101
process, for future @code{run} commands.  For example,
2102
 
2103
@smallexample
2104
tty /dev/ttyb
2105
@end smallexample
2106
 
2107
@noindent
2108
directs that processes started with subsequent @code{run} commands
2109
default to do input and output on the terminal @file{/dev/ttyb} and have
2110
that as their controlling terminal.
2111
 
2112
An explicit redirection in @code{run} overrides the @code{tty} command's
2113
effect on the input/output device, but not its effect on the controlling
2114
terminal.
2115
 
2116
When you use the @code{tty} command or redirect input in the @code{run}
2117
command, only the input @emph{for your program} is affected.  The input
2118
for @value{GDBN} still comes from your terminal.  @code{tty} is an alias
2119
for @code{set inferior-tty}.
2120
 
2121
@cindex inferior tty
2122
@cindex set inferior controlling terminal
2123
You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2124
display the name of the terminal that will be used for future runs of your
2125
program.
2126
 
2127
@table @code
2128
@item set inferior-tty /dev/ttyb
2129
@kindex set inferior-tty
2130
Set the tty for the program being debugged to /dev/ttyb.
2131
 
2132
@item show inferior-tty
2133
@kindex show inferior-tty
2134
Show the current tty for the program being debugged.
2135
@end table
2136
 
2137
@node Attach
2138
@section Debugging an Already-running Process
2139
@kindex attach
2140
@cindex attach
2141
 
2142
@table @code
2143
@item attach @var{process-id}
2144
This command attaches to a running process---one that was started
2145
outside @value{GDBN}.  (@code{info files} shows your active
2146
targets.)  The command takes as argument a process ID.  The usual way to
2147
find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2148
or with the @samp{jobs -l} shell command.
2149
 
2150
@code{attach} does not repeat if you press @key{RET} a second time after
2151
executing the command.
2152
@end table
2153
 
2154
To use @code{attach}, your program must be running in an environment
2155
which supports processes; for example, @code{attach} does not work for
2156
programs on bare-board targets that lack an operating system.  You must
2157
also have permission to send the process a signal.
2158
 
2159
When you use @code{attach}, the debugger finds the program running in
2160
the process first by looking in the current working directory, then (if
2161
the program is not found) by using the source file search path
2162
(@pxref{Source Path, ,Specifying Source Directories}).  You can also use
2163
the @code{file} command to load the program.  @xref{Files, ,Commands to
2164
Specify Files}.
2165
 
2166
The first thing @value{GDBN} does after arranging to debug the specified
2167
process is to stop it.  You can examine and modify an attached process
2168
with all the @value{GDBN} commands that are ordinarily available when
2169
you start processes with @code{run}.  You can insert breakpoints; you
2170
can step and continue; you can modify storage.  If you would rather the
2171
process continue running, you may use the @code{continue} command after
2172
attaching @value{GDBN} to the process.
2173
 
2174
@table @code
2175
@kindex detach
2176
@item detach
2177
When you have finished debugging the attached process, you can use the
2178
@code{detach} command to release it from @value{GDBN} control.  Detaching
2179
the process continues its execution.  After the @code{detach} command,
2180
that process and @value{GDBN} become completely independent once more, and you
2181
are ready to @code{attach} another process or start one with @code{run}.
2182
@code{detach} does not repeat if you press @key{RET} again after
2183
executing the command.
2184
@end table
2185
 
2186
If you exit @value{GDBN} while you have an attached process, you detach
2187
that process.  If you use the @code{run} command, you kill that process.
2188
By default, @value{GDBN} asks for confirmation if you try to do either of these
2189
things; you can control whether or not you need to confirm by using the
2190
@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2191
Messages}).
2192
 
2193
@node Kill Process
2194
@section Killing the Child Process
2195
 
2196
@table @code
2197
@kindex kill
2198
@item kill
2199
Kill the child process in which your program is running under @value{GDBN}.
2200
@end table
2201
 
2202
This command is useful if you wish to debug a core dump instead of a
2203
running process.  @value{GDBN} ignores any core dump file while your program
2204
is running.
2205
 
2206
On some operating systems, a program cannot be executed outside @value{GDBN}
2207
while you have breakpoints set on it inside @value{GDBN}.  You can use the
2208
@code{kill} command in this situation to permit running your program
2209
outside the debugger.
2210
 
2211
The @code{kill} command is also useful if you wish to recompile and
2212
relink your program, since on many systems it is impossible to modify an
2213
executable file while it is running in a process.  In this case, when you
2214
next type @code{run}, @value{GDBN} notices that the file has changed, and
2215
reads the symbol table again (while trying to preserve your current
2216
breakpoint settings).
2217
 
2218
@node Threads
2219
@section Debugging Programs with Multiple Threads
2220
 
2221
@cindex threads of execution
2222
@cindex multiple threads
2223
@cindex switching threads
2224
In some operating systems, such as HP-UX and Solaris, a single program
2225
may have more than one @dfn{thread} of execution.  The precise semantics
2226
of threads differ from one operating system to another, but in general
2227
the threads of a single program are akin to multiple processes---except
2228
that they share one address space (that is, they can all examine and
2229
modify the same variables).  On the other hand, each thread has its own
2230
registers and execution stack, and perhaps private memory.
2231
 
2232
@value{GDBN} provides these facilities for debugging multi-thread
2233
programs:
2234
 
2235
@itemize @bullet
2236
@item automatic notification of new threads
2237
@item @samp{thread @var{threadno}}, a command to switch among threads
2238
@item @samp{info threads}, a command to inquire about existing threads
2239
@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2240
a command to apply a command to a list of threads
2241
@item thread-specific breakpoints
2242
@item @samp{set print thread-events}, which controls printing of
2243
messages on thread start and exit.
2244
@end itemize
2245
 
2246
@quotation
2247
@emph{Warning:} These facilities are not yet available on every
2248
@value{GDBN} configuration where the operating system supports threads.
2249
If your @value{GDBN} does not support threads, these commands have no
2250
effect.  For example, a system without thread support shows no output
2251
from @samp{info threads}, and always rejects the @code{thread} command,
2252
like this:
2253
 
2254
@smallexample
2255
(@value{GDBP}) info threads
2256
(@value{GDBP}) thread 1
2257
Thread ID 1 not known.  Use the "info threads" command to
2258
see the IDs of currently known threads.
2259
@end smallexample
2260
@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2261
@c                        doesn't support threads"?
2262
@end quotation
2263
 
2264
@cindex focus of debugging
2265
@cindex current thread
2266
The @value{GDBN} thread debugging facility allows you to observe all
2267
threads while your program runs---but whenever @value{GDBN} takes
2268
control, one thread in particular is always the focus of debugging.
2269
This thread is called the @dfn{current thread}.  Debugging commands show
2270
program information from the perspective of the current thread.
2271
 
2272
@cindex @code{New} @var{systag} message
2273
@cindex thread identifier (system)
2274
@c FIXME-implementors!! It would be more helpful if the [New...] message
2275
@c included GDB's numeric thread handle, so you could just go to that
2276
@c thread without first checking `info threads'.
2277
Whenever @value{GDBN} detects a new thread in your program, it displays
2278
the target system's identification for the thread with a message in the
2279
form @samp{[New @var{systag}]}.  @var{systag} is a thread identifier
2280
whose form varies depending on the particular system.  For example, on
2281
@sc{gnu}/Linux, you might see
2282
 
2283
@smallexample
2284
[New Thread 46912507313328 (LWP 25582)]
2285
@end smallexample
2286
 
2287
@noindent
2288
when @value{GDBN} notices a new thread.  In contrast, on an SGI system,
2289
the @var{systag} is simply something like @samp{process 368}, with no
2290
further qualifier.
2291
 
2292
@c FIXME!! (1) Does the [New...] message appear even for the very first
2293
@c         thread of a program, or does it only appear for the
2294
@c         second---i.e.@: when it becomes obvious we have a multithread
2295
@c         program?
2296
@c         (2) *Is* there necessarily a first thread always?  Or do some
2297
@c         multithread systems permit starting a program with multiple
2298
@c         threads ab initio?
2299
 
2300
@cindex thread number
2301
@cindex thread identifier (GDB)
2302
For debugging purposes, @value{GDBN} associates its own thread
2303
number---always a single integer---with each thread in your program.
2304
 
2305
@table @code
2306
@kindex info threads
2307
@item info threads
2308
Display a summary of all threads currently in your
2309
program.  @value{GDBN} displays for each thread (in this order):
2310
 
2311
@enumerate
2312
@item
2313
the thread number assigned by @value{GDBN}
2314
 
2315
@item
2316
the target system's thread identifier (@var{systag})
2317
 
2318
@item
2319
the current stack frame summary for that thread
2320
@end enumerate
2321
 
2322
@noindent
2323
An asterisk @samp{*} to the left of the @value{GDBN} thread number
2324
indicates the current thread.
2325
 
2326
For example,
2327
@end table
2328
@c end table here to get a little more width for example
2329
 
2330
@smallexample
2331
(@value{GDBP}) info threads
2332
  3 process 35 thread 27  0x34e5 in sigpause ()
2333
  2 process 35 thread 23  0x34e5 in sigpause ()
2334
* 1 process 35 thread 13  main (argc=1, argv=0x7ffffff8)
2335
    at threadtest.c:68
2336
@end smallexample
2337
 
2338
On HP-UX systems:
2339
 
2340
@cindex debugging multithreaded programs (on HP-UX)
2341
@cindex thread identifier (GDB), on HP-UX
2342
For debugging purposes, @value{GDBN} associates its own thread
2343
number---a small integer assigned in thread-creation order---with each
2344
thread in your program.
2345
 
2346
@cindex @code{New} @var{systag} message, on HP-UX
2347
@cindex thread identifier (system), on HP-UX
2348
@c FIXME-implementors!! It would be more helpful if the [New...] message
2349
@c included GDB's numeric thread handle, so you could just go to that
2350
@c thread without first checking `info threads'.
2351
Whenever @value{GDBN} detects a new thread in your program, it displays
2352
both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2353
form @samp{[New @var{systag}]}.  @var{systag} is a thread identifier
2354
whose form varies depending on the particular system.  For example, on
2355
HP-UX, you see
2356
 
2357
@smallexample
2358
[New thread 2 (system thread 26594)]
2359
@end smallexample
2360
 
2361
@noindent
2362
when @value{GDBN} notices a new thread.
2363
 
2364
@table @code
2365
@kindex info threads (HP-UX)
2366
@item info threads
2367
Display a summary of all threads currently in your
2368
program.  @value{GDBN} displays for each thread (in this order):
2369
 
2370
@enumerate
2371
@item the thread number assigned by @value{GDBN}
2372
 
2373
@item the target system's thread identifier (@var{systag})
2374
 
2375
@item the current stack frame summary for that thread
2376
@end enumerate
2377
 
2378
@noindent
2379
An asterisk @samp{*} to the left of the @value{GDBN} thread number
2380
indicates the current thread.
2381
 
2382
For example,
2383
@end table
2384
@c end table here to get a little more width for example
2385
 
2386
@smallexample
2387
(@value{GDBP}) info threads
2388
    * 3 system thread 26607  worker (wptr=0x7b09c318 "@@") \@*
2389
                               at quicksort.c:137
2390
      2 system thread 26606  0x7b0030d8 in __ksleep () \@*
2391
                               from /usr/lib/libc.2
2392
      1 system thread 27905  0x7b003498 in _brk () \@*
2393
                               from /usr/lib/libc.2
2394
@end smallexample
2395
 
2396
On Solaris, you can display more information about user threads with a
2397
Solaris-specific command:
2398
 
2399
@table @code
2400
@item maint info sol-threads
2401
@kindex maint info sol-threads
2402
@cindex thread info (Solaris)
2403
Display info on Solaris user threads.
2404
@end table
2405
 
2406
@table @code
2407
@kindex thread @var{threadno}
2408
@item thread @var{threadno}
2409
Make thread number @var{threadno} the current thread.  The command
2410
argument @var{threadno} is the internal @value{GDBN} thread number, as
2411
shown in the first field of the @samp{info threads} display.
2412
@value{GDBN} responds by displaying the system identifier of the thread
2413
you selected, and its current stack frame summary:
2414
 
2415
@smallexample
2416
@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2417
(@value{GDBP}) thread 2
2418
[Switching to process 35 thread 23]
2419
0x34e5 in sigpause ()
2420
@end smallexample
2421
 
2422
@noindent
2423
As with the @samp{[New @dots{}]} message, the form of the text after
2424
@samp{Switching to} depends on your system's conventions for identifying
2425
threads.
2426
 
2427
@kindex thread apply
2428
@cindex apply command to several threads
2429
@item thread apply [@var{threadno}] [@var{all}] @var{command}
2430
The @code{thread apply} command allows you to apply the named
2431
@var{command} to one or more threads.  Specify the numbers of the
2432
threads that you want affected with the command argument
2433
@var{threadno}.  It can be a single thread number, one of the numbers
2434
shown in the first field of the @samp{info threads} display; or it
2435
could be a range of thread numbers, as in @code{2-4}.  To apply a
2436
command to all threads, type @kbd{thread apply all @var{command}}.
2437
 
2438
@kindex set print thread-events
2439
@cindex print messages on thread start and exit
2440
@item set print thread-events
2441
@itemx set print thread-events on
2442
@itemx set print thread-events off
2443
The @code{set print thread-events} command allows you to enable or
2444
disable printing of messages when @value{GDBN} notices that new threads have
2445
started or that threads have exited.  By default, these messages will
2446
be printed if detection of these events is supported by the target.
2447
Note that these messages cannot be disabled on all targets.
2448
 
2449
@kindex show print thread-events
2450
@item show print thread-events
2451
Show whether messages will be printed when @value{GDBN} detects that threads
2452
have started and exited.
2453
@end table
2454
 
2455
@cindex automatic thread selection
2456
@cindex switching threads automatically
2457
@cindex threads, automatic switching
2458
Whenever @value{GDBN} stops your program, due to a breakpoint or a
2459
signal, it automatically selects the thread where that breakpoint or
2460
signal happened.  @value{GDBN} alerts you to the context switch with a
2461
message of the form @samp{[Switching to @var{systag}]} to identify the
2462
thread.
2463
 
2464
@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
2465
more information about how @value{GDBN} behaves when you stop and start
2466
programs with multiple threads.
2467
 
2468
@xref{Set Watchpoints,,Setting Watchpoints}, for information about
2469
watchpoints in programs with multiple threads.
2470
 
2471
@node Processes
2472
@section Debugging Programs with Multiple Processes
2473
 
2474
@cindex fork, debugging programs which call
2475
@cindex multiple processes
2476
@cindex processes, multiple
2477
On most systems, @value{GDBN} has no special support for debugging
2478
programs which create additional processes using the @code{fork}
2479
function.  When a program forks, @value{GDBN} will continue to debug the
2480
parent process and the child process will run unimpeded.  If you have
2481
set a breakpoint in any code which the child then executes, the child
2482
will get a @code{SIGTRAP} signal which (unless it catches the signal)
2483
will cause it to terminate.
2484
 
2485
However, if you want to debug the child process there is a workaround
2486
which isn't too painful.  Put a call to @code{sleep} in the code which
2487
the child process executes after the fork.  It may be useful to sleep
2488
only if a certain environment variable is set, or a certain file exists,
2489
so that the delay need not occur when you don't want to run @value{GDBN}
2490
on the child.  While the child is sleeping, use the @code{ps} program to
2491
get its process ID.  Then tell @value{GDBN} (a new invocation of
2492
@value{GDBN} if you are also debugging the parent process) to attach to
2493
the child process (@pxref{Attach}).  From that point on you can debug
2494
the child process just like any other process which you attached to.
2495
 
2496
On some systems, @value{GDBN} provides support for debugging programs that
2497
create additional processes using the @code{fork} or @code{vfork} functions.
2498
Currently, the only platforms with this feature are HP-UX (11.x and later
2499
only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
2500
 
2501
By default, when a program forks, @value{GDBN} will continue to debug
2502
the parent process and the child process will run unimpeded.
2503
 
2504
If you want to follow the child process instead of the parent process,
2505
use the command @w{@code{set follow-fork-mode}}.
2506
 
2507
@table @code
2508
@kindex set follow-fork-mode
2509
@item set follow-fork-mode @var{mode}
2510
Set the debugger response to a program call of @code{fork} or
2511
@code{vfork}.  A call to @code{fork} or @code{vfork} creates a new
2512
process.  The @var{mode} argument can be:
2513
 
2514
@table @code
2515
@item parent
2516
The original process is debugged after a fork.  The child process runs
2517
unimpeded.  This is the default.
2518
 
2519
@item child
2520
The new process is debugged after a fork.  The parent process runs
2521
unimpeded.
2522
 
2523
@end table
2524
 
2525
@kindex show follow-fork-mode
2526
@item show follow-fork-mode
2527
Display the current debugger response to a @code{fork} or @code{vfork} call.
2528
@end table
2529
 
2530
@cindex debugging multiple processes
2531
On Linux, if you want to debug both the parent and child processes, use the
2532
command @w{@code{set detach-on-fork}}.
2533
 
2534
@table @code
2535
@kindex set detach-on-fork
2536
@item set detach-on-fork @var{mode}
2537
Tells gdb whether to detach one of the processes after a fork, or
2538
retain debugger control over them both.
2539
 
2540
@table @code
2541
@item on
2542
The child process (or parent process, depending on the value of
2543
@code{follow-fork-mode}) will be detached and allowed to run
2544
independently.  This is the default.
2545
 
2546
@item off
2547
Both processes will be held under the control of @value{GDBN}.
2548
One process (child or parent, depending on the value of
2549
@code{follow-fork-mode}) is debugged as usual, while the other
2550
is held suspended.
2551
 
2552
@end table
2553
 
2554
@kindex show detach-on-fork
2555
@item show detach-on-fork
2556
Show whether detach-on-fork mode is on/off.
2557
@end table
2558
 
2559
If you choose to set @samp{detach-on-fork} mode off, then
2560
@value{GDBN} will retain control of all forked processes (including
2561
nested forks).  You can list the forked processes under the control of
2562
@value{GDBN} by using the @w{@code{info forks}} command, and switch
2563
from one fork to another by using the @w{@code{fork}} command.
2564
 
2565
@table @code
2566
@kindex info forks
2567
@item info forks
2568
Print a list of all forked processes under the control of @value{GDBN}.
2569
The listing will include a fork id, a process id, and the current
2570
position (program counter) of the process.
2571
 
2572
@kindex fork @var{fork-id}
2573
@item fork @var{fork-id}
2574
Make fork number @var{fork-id} the current process.  The argument
2575
@var{fork-id} is the internal fork number assigned by @value{GDBN},
2576
as shown in the first field of the @samp{info forks} display.
2577
 
2578
@kindex process @var{process-id}
2579
@item process @var{process-id}
2580
Make process number @var{process-id} the current process.  The
2581
argument @var{process-id} must be one that is listed in the output of
2582
@samp{info forks}.
2583
 
2584
@end table
2585
 
2586
To quit debugging one of the forked processes, you can either detach
2587
from it by using the @w{@code{detach fork}} command (allowing it to
2588
run independently), or delete (and kill) it using the
2589
@w{@code{delete fork}} command.
2590
 
2591
@table @code
2592
@kindex detach fork @var{fork-id}
2593
@item detach fork @var{fork-id}
2594
Detach from the process identified by @value{GDBN} fork number
2595
@var{fork-id}, and remove it from the fork list.  The process will be
2596
allowed to run independently.
2597
 
2598
@kindex delete fork @var{fork-id}
2599
@item delete fork @var{fork-id}
2600
Kill the process identified by @value{GDBN} fork number @var{fork-id},
2601
and remove it from the fork list.
2602
 
2603
@end table
2604
 
2605
If you ask to debug a child process and a @code{vfork} is followed by an
2606
@code{exec}, @value{GDBN} executes the new target up to the first
2607
breakpoint in the new target.  If you have a breakpoint set on
2608
@code{main} in your original program, the breakpoint will also be set on
2609
the child process's @code{main}.
2610
 
2611
When a child process is spawned by @code{vfork}, you cannot debug the
2612
child or parent until an @code{exec} call completes.
2613
 
2614
If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2615
call executes, the new target restarts.  To restart the parent process,
2616
use the @code{file} command with the parent executable name as its
2617
argument.
2618
 
2619
You can use the @code{catch} command to make @value{GDBN} stop whenever
2620
a @code{fork}, @code{vfork}, or @code{exec} call is made.  @xref{Set
2621
Catchpoints, ,Setting Catchpoints}.
2622
 
2623
@node Checkpoint/Restart
2624
@section Setting a @emph{Bookmark} to Return to Later
2625
 
2626
@cindex checkpoint
2627
@cindex restart
2628
@cindex bookmark
2629
@cindex snapshot of a process
2630
@cindex rewind program state
2631
 
2632
On certain operating systems@footnote{Currently, only
2633
@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2634
program's state, called a @dfn{checkpoint}, and come back to it
2635
later.
2636
 
2637
Returning to a checkpoint effectively undoes everything that has
2638
happened in the program since the @code{checkpoint} was saved.  This
2639
includes changes in memory, registers, and even (within some limits)
2640
system state.  Effectively, it is like going back in time to the
2641
moment when the checkpoint was saved.
2642
 
2643
Thus, if you're stepping thru a program and you think you're
2644
getting close to the point where things go wrong, you can save
2645
a checkpoint.  Then, if you accidentally go too far and miss
2646
the critical statement, instead of having to restart your program
2647
from the beginning, you can just go back to the checkpoint and
2648
start again from there.
2649
 
2650
This can be especially useful if it takes a lot of time or
2651
steps to reach the point where you think the bug occurs.
2652
 
2653
To use the @code{checkpoint}/@code{restart} method of debugging:
2654
 
2655
@table @code
2656
@kindex checkpoint
2657
@item checkpoint
2658
Save a snapshot of the debugged program's current execution state.
2659
The @code{checkpoint} command takes no arguments, but each checkpoint
2660
is assigned a small integer id, similar to a breakpoint id.
2661
 
2662
@kindex info checkpoints
2663
@item info checkpoints
2664
List the checkpoints that have been saved in the current debugging
2665
session.  For each checkpoint, the following information will be
2666
listed:
2667
 
2668
@table @code
2669
@item Checkpoint ID
2670
@item Process ID
2671
@item Code Address
2672
@item Source line, or label
2673
@end table
2674
 
2675
@kindex restart @var{checkpoint-id}
2676
@item restart @var{checkpoint-id}
2677
Restore the program state that was saved as checkpoint number
2678
@var{checkpoint-id}.  All program variables, registers, stack frames
2679
etc.@:  will be returned to the values that they had when the checkpoint
2680
was saved.  In essence, gdb will ``wind back the clock'' to the point
2681
in time when the checkpoint was saved.
2682
 
2683
Note that breakpoints, @value{GDBN} variables, command history etc.
2684
are not affected by restoring a checkpoint.  In general, a checkpoint
2685
only restores things that reside in the program being debugged, not in
2686
the debugger.
2687
 
2688
@kindex delete checkpoint @var{checkpoint-id}
2689
@item delete checkpoint @var{checkpoint-id}
2690
Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2691
 
2692
@end table
2693
 
2694
Returning to a previously saved checkpoint will restore the user state
2695
of the program being debugged, plus a significant subset of the system
2696
(OS) state, including file pointers.  It won't ``un-write'' data from
2697
a file, but it will rewind the file pointer to the previous location,
2698
so that the previously written data can be overwritten.  For files
2699
opened in read mode, the pointer will also be restored so that the
2700
previously read data can be read again.
2701
 
2702
Of course, characters that have been sent to a printer (or other
2703
external device) cannot be ``snatched back'', and characters received
2704
from eg.@: a serial device can be removed from internal program buffers,
2705
but they cannot be ``pushed back'' into the serial pipeline, ready to
2706
be received again.  Similarly, the actual contents of files that have
2707
been changed cannot be restored (at this time).
2708
 
2709
However, within those constraints, you actually can ``rewind'' your
2710
program to a previously saved point in time, and begin debugging it
2711
again --- and you can change the course of events so as to debug a
2712
different execution path this time.
2713
 
2714
@cindex checkpoints and process id
2715
Finally, there is one bit of internal program state that will be
2716
different when you return to a checkpoint --- the program's process
2717
id.  Each checkpoint will have a unique process id (or @var{pid}),
2718
and each will be different from the program's original @var{pid}.
2719
If your program has saved a local copy of its process id, this could
2720
potentially pose a problem.
2721
 
2722
@subsection A Non-obvious Benefit of Using Checkpoints
2723
 
2724
On some systems such as @sc{gnu}/Linux, address space randomization
2725
is performed on new processes for security reasons.  This makes it
2726
difficult or impossible to set a breakpoint, or watchpoint, on an
2727
absolute address if you have to restart the program, since the
2728
absolute location of a symbol will change from one execution to the
2729
next.
2730
 
2731
A checkpoint, however, is an @emph{identical} copy of a process.
2732
Therefore if you create a checkpoint at (eg.@:) the start of main,
2733
and simply return to that checkpoint instead of restarting the
2734
process, you can avoid the effects of address randomization and
2735
your symbols will all stay in the same place.
2736
 
2737
@node Stopping
2738
@chapter Stopping and Continuing
2739
 
2740
The principal purposes of using a debugger are so that you can stop your
2741
program before it terminates; or so that, if your program runs into
2742
trouble, you can investigate and find out why.
2743
 
2744
Inside @value{GDBN}, your program may stop for any of several reasons,
2745
such as a signal, a breakpoint, or reaching a new line after a
2746
@value{GDBN} command such as @code{step}.  You may then examine and
2747
change variables, set new breakpoints or remove old ones, and then
2748
continue execution.  Usually, the messages shown by @value{GDBN} provide
2749
ample explanation of the status of your program---but you can also
2750
explicitly request this information at any time.
2751
 
2752
@table @code
2753
@kindex info program
2754
@item info program
2755
Display information about the status of your program: whether it is
2756
running or not, what process it is, and why it stopped.
2757
@end table
2758
 
2759
@menu
2760
* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
2761
* Continuing and Stepping::     Resuming execution
2762
* Signals::                     Signals
2763
* Thread Stops::                Stopping and starting multi-thread programs
2764
@end menu
2765
 
2766
@node Breakpoints
2767
@section Breakpoints, Watchpoints, and Catchpoints
2768
 
2769
@cindex breakpoints
2770
A @dfn{breakpoint} makes your program stop whenever a certain point in
2771
the program is reached.  For each breakpoint, you can add conditions to
2772
control in finer detail whether your program stops.  You can set
2773
breakpoints with the @code{break} command and its variants (@pxref{Set
2774
Breaks, ,Setting Breakpoints}), to specify the place where your program
2775
should stop by line number, function name or exact address in the
2776
program.
2777
 
2778
On some systems, you can set breakpoints in shared libraries before
2779
the executable is run.  There is a minor limitation on HP-UX systems:
2780
you must wait until the executable is run in order to set breakpoints
2781
in shared library routines that are not called directly by the program
2782
(for example, routines that are arguments in a @code{pthread_create}
2783
call).
2784
 
2785
@cindex watchpoints
2786
@cindex data breakpoints
2787
@cindex memory tracing
2788
@cindex breakpoint on memory address
2789
@cindex breakpoint on variable modification
2790
A @dfn{watchpoint} is a special breakpoint that stops your program
2791
when the value of an expression changes.  The expression may be a value
2792
of a variable, or it could involve values of one or more variables
2793
combined by operators, such as @samp{a + b}.  This is sometimes called
2794
@dfn{data breakpoints}.  You must use a different command to set
2795
watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
2796
from that, you can manage a watchpoint like any other breakpoint: you
2797
enable, disable, and delete both breakpoints and watchpoints using the
2798
same commands.
2799
 
2800
You can arrange to have values from your program displayed automatically
2801
whenever @value{GDBN} stops at a breakpoint.  @xref{Auto Display,,
2802
Automatic Display}.
2803
 
2804
@cindex catchpoints
2805
@cindex breakpoint on events
2806
A @dfn{catchpoint} is another special breakpoint that stops your program
2807
when a certain kind of event occurs, such as the throwing of a C@t{++}
2808
exception or the loading of a library.  As with watchpoints, you use a
2809
different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2810
Catchpoints}), but aside from that, you can manage a catchpoint like any
2811
other breakpoint.  (To stop when your program receives a signal, use the
2812
@code{handle} command; see @ref{Signals, ,Signals}.)
2813
 
2814
@cindex breakpoint numbers
2815
@cindex numbers for breakpoints
2816
@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2817
catchpoint when you create it; these numbers are successive integers
2818
starting with one.  In many of the commands for controlling various
2819
features of breakpoints you use the breakpoint number to say which
2820
breakpoint you want to change.  Each breakpoint may be @dfn{enabled} or
2821
@dfn{disabled}; if disabled, it has no effect on your program until you
2822
enable it again.
2823
 
2824
@cindex breakpoint ranges
2825
@cindex ranges of breakpoints
2826
Some @value{GDBN} commands accept a range of breakpoints on which to
2827
operate.  A breakpoint range is either a single breakpoint number, like
2828
@samp{5}, or two such numbers, in increasing order, separated by a
2829
hyphen, like @samp{5-7}.  When a breakpoint range is given to a command,
2830
all breakpoints in that range are operated on.
2831
 
2832
@menu
2833
* Set Breaks::                  Setting breakpoints
2834
* Set Watchpoints::             Setting watchpoints
2835
* Set Catchpoints::             Setting catchpoints
2836
* Delete Breaks::               Deleting breakpoints
2837
* Disabling::                   Disabling breakpoints
2838
* Conditions::                  Break conditions
2839
* Break Commands::              Breakpoint command lists
2840
* Breakpoint Menus::            Breakpoint menus
2841
* Error in Breakpoints::        ``Cannot insert breakpoints''
2842
* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
2843
@end menu
2844
 
2845
@node Set Breaks
2846
@subsection Setting Breakpoints
2847
 
2848
@c FIXME LMB what does GDB do if no code on line of breakpt?
2849
@c       consider in particular declaration with/without initialization.
2850
@c
2851
@c FIXME 2 is there stuff on this already? break at fun start, already init?
2852
 
2853
@kindex break
2854
@kindex b @r{(@code{break})}
2855
@vindex $bpnum@r{, convenience variable}
2856
@cindex latest breakpoint
2857
Breakpoints are set with the @code{break} command (abbreviated
2858
@code{b}).  The debugger convenience variable @samp{$bpnum} records the
2859
number of the breakpoint you've set most recently; see @ref{Convenience
2860
Vars,, Convenience Variables}, for a discussion of what you can do with
2861
convenience variables.
2862
 
2863
@table @code
2864
@item break @var{location}
2865
Set a breakpoint at the given @var{location}, which can specify a
2866
function name, a line number, or an address of an instruction.
2867
(@xref{Specify Location}, for a list of all the possible ways to
2868
specify a @var{location}.)  The breakpoint will stop your program just
2869
before it executes any of the code in the specified @var{location}.
2870
 
2871
When using source languages that permit overloading of symbols, such as
2872
C@t{++}, a function name may refer to more than one possible place to break.
2873
@xref{Breakpoint Menus,,Breakpoint Menus}, for a discussion of that situation.
2874
 
2875
@item break
2876
When called without any arguments, @code{break} sets a breakpoint at
2877
the next instruction to be executed in the selected stack frame
2878
(@pxref{Stack, ,Examining the Stack}).  In any selected frame but the
2879
innermost, this makes your program stop as soon as control
2880
returns to that frame.  This is similar to the effect of a
2881
@code{finish} command in the frame inside the selected frame---except
2882
that @code{finish} does not leave an active breakpoint.  If you use
2883
@code{break} without an argument in the innermost frame, @value{GDBN} stops
2884
the next time it reaches the current location; this may be useful
2885
inside loops.
2886
 
2887
@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2888
least one instruction has been executed.  If it did not do this, you
2889
would be unable to proceed past a breakpoint without first disabling the
2890
breakpoint.  This rule applies whether or not the breakpoint already
2891
existed when your program stopped.
2892
 
2893
@item break @dots{} if @var{cond}
2894
Set a breakpoint with condition @var{cond}; evaluate the expression
2895
@var{cond} each time the breakpoint is reached, and stop only if the
2896
value is nonzero---that is, if @var{cond} evaluates as true.
2897
@samp{@dots{}} stands for one of the possible arguments described
2898
above (or no argument) specifying where to break.  @xref{Conditions,
2899
,Break Conditions}, for more information on breakpoint conditions.
2900
 
2901
@kindex tbreak
2902
@item tbreak @var{args}
2903
Set a breakpoint enabled only for one stop.  @var{args} are the
2904
same as for the @code{break} command, and the breakpoint is set in the same
2905
way, but the breakpoint is automatically deleted after the first time your
2906
program stops there.  @xref{Disabling, ,Disabling Breakpoints}.
2907
 
2908
@kindex hbreak
2909
@cindex hardware breakpoints
2910
@item hbreak @var{args}
2911
Set a hardware-assisted breakpoint.  @var{args} are the same as for the
2912
@code{break} command and the breakpoint is set in the same way, but the
2913
breakpoint requires hardware support and some target hardware may not
2914
have this support.  The main purpose of this is EPROM/ROM code
2915
debugging, so you can set a breakpoint at an instruction without
2916
changing the instruction.  This can be used with the new trap-generation
2917
provided by SPARClite DSU and most x86-based targets.  These targets
2918
will generate traps when a program accesses some data or instruction
2919
address that is assigned to the debug registers.  However the hardware
2920
breakpoint registers can take a limited number of breakpoints.  For
2921
example, on the DSU, only two data breakpoints can be set at a time, and
2922
@value{GDBN} will reject this command if more than two are used.  Delete
2923
or disable unused hardware breakpoints before setting new ones
2924
(@pxref{Disabling, ,Disabling Breakpoints}).
2925
@xref{Conditions, ,Break Conditions}.
2926
For remote targets, you can restrict the number of hardware
2927
breakpoints @value{GDBN} will use, see @ref{set remote
2928
hardware-breakpoint-limit}.
2929
 
2930
@kindex thbreak
2931
@item thbreak @var{args}
2932
Set a hardware-assisted breakpoint enabled only for one stop.  @var{args}
2933
are the same as for the @code{hbreak} command and the breakpoint is set in
2934
the same way.  However, like the @code{tbreak} command,
2935
the breakpoint is automatically deleted after the
2936
first time your program stops there.  Also, like the @code{hbreak}
2937
command, the breakpoint requires hardware support and some target hardware
2938
may not have this support.  @xref{Disabling, ,Disabling Breakpoints}.
2939
See also @ref{Conditions, ,Break Conditions}.
2940
 
2941
@kindex rbreak
2942
@cindex regular expression
2943
@cindex breakpoints in functions matching a regexp
2944
@cindex set breakpoints in many functions
2945
@item rbreak @var{regex}
2946
Set breakpoints on all functions matching the regular expression
2947
@var{regex}.  This command sets an unconditional breakpoint on all
2948
matches, printing a list of all breakpoints it set.  Once these
2949
breakpoints are set, they are treated just like the breakpoints set with
2950
the @code{break} command.  You can delete them, disable them, or make
2951
them conditional the same way as any other breakpoint.
2952
 
2953
The syntax of the regular expression is the standard one used with tools
2954
like @file{grep}.  Note that this is different from the syntax used by
2955
shells, so for instance @code{foo*} matches all functions that include
2956
an @code{fo} followed by zero or more @code{o}s.  There is an implicit
2957
@code{.*} leading and trailing the regular expression you supply, so to
2958
match only functions that begin with @code{foo}, use @code{^foo}.
2959
 
2960
@cindex non-member C@t{++} functions, set breakpoint in
2961
When debugging C@t{++} programs, @code{rbreak} is useful for setting
2962
breakpoints on overloaded functions that are not members of any special
2963
classes.
2964
 
2965
@cindex set breakpoints on all functions
2966
The @code{rbreak} command can be used to set breakpoints in
2967
@strong{all} the functions in a program, like this:
2968
 
2969
@smallexample
2970
(@value{GDBP}) rbreak .
2971
@end smallexample
2972
 
2973
@kindex info breakpoints
2974
@cindex @code{$_} and @code{info breakpoints}
2975
@item info breakpoints @r{[}@var{n}@r{]}
2976
@itemx info break @r{[}@var{n}@r{]}
2977
@itemx info watchpoints @r{[}@var{n}@r{]}
2978
Print a table of all breakpoints, watchpoints, and catchpoints set and
2979
not deleted.  Optional argument @var{n} means print information only
2980
about the specified breakpoint (or watchpoint or catchpoint).  For
2981
each breakpoint, following columns are printed:
2982
 
2983
@table @emph
2984
@item Breakpoint Numbers
2985
@item Type
2986
Breakpoint, watchpoint, or catchpoint.
2987
@item Disposition
2988
Whether the breakpoint is marked to be disabled or deleted when hit.
2989
@item Enabled or Disabled
2990
Enabled breakpoints are marked with @samp{y}.  @samp{n} marks breakpoints
2991
that are not enabled.
2992
@item Address
2993
Where the breakpoint is in your program, as a memory address.  For a
2994
pending breakpoint whose address is not yet known, this field will
2995
contain @samp{<PENDING>}.  Such breakpoint won't fire until a shared
2996
library that has the symbol or line referred by breakpoint is loaded.
2997
See below for details.  A breakpoint with several locations will
2998
have @samp{<MULTIPLE>} in this field---see below for details.
2999
@item What
3000
Where the breakpoint is in the source for your program, as a file and
3001
line number.  For a pending breakpoint, the original string passed to
3002
the breakpoint command will be listed as it cannot be resolved until
3003
the appropriate shared library is loaded in the future.
3004
@end table
3005
 
3006
@noindent
3007
If a breakpoint is conditional, @code{info break} shows the condition on
3008
the line following the affected breakpoint; breakpoint commands, if any,
3009
are listed after that.  A pending breakpoint is allowed to have a condition
3010
specified for it.  The condition is not parsed for validity until a shared
3011
library is loaded that allows the pending breakpoint to resolve to a
3012
valid location.
3013
 
3014
@noindent
3015
@code{info break} with a breakpoint
3016
number @var{n} as argument lists only that breakpoint.  The
3017
convenience variable @code{$_} and the default examining-address for
3018
the @code{x} command are set to the address of the last breakpoint
3019
listed (@pxref{Memory, ,Examining Memory}).
3020
 
3021
@noindent
3022
@code{info break} displays a count of the number of times the breakpoint
3023
has been hit.  This is especially useful in conjunction with the
3024
@code{ignore} command.  You can ignore a large number of breakpoint
3025
hits, look at the breakpoint info to see how many times the breakpoint
3026
was hit, and then run again, ignoring one less than that number.  This
3027
will get you quickly to the last hit of that breakpoint.
3028
@end table
3029
 
3030
@value{GDBN} allows you to set any number of breakpoints at the same place in
3031
your program.  There is nothing silly or meaningless about this.  When
3032
the breakpoints are conditional, this is even useful
3033
(@pxref{Conditions, ,Break Conditions}).
3034
 
3035
It is possible that a breakpoint corresponds to several locations
3036
in your program.  Examples of this situation are:
3037
 
3038
@itemize @bullet
3039
 
3040
@item
3041
For a C@t{++} constructor, the @value{NGCC} compiler generates several
3042
instances of the function body, used in different cases.
3043
 
3044
@item
3045
For a C@t{++} template function, a given line in the function can
3046
correspond to any number of instantiations.
3047
 
3048
@item
3049
For an inlined function, a given source line can correspond to
3050
several places where that function is inlined.
3051
 
3052
@end itemize
3053
 
3054
In all those cases, @value{GDBN} will insert a breakpoint at all
3055
the relevant locations.
3056
 
3057
A breakpoint with multiple locations is displayed in the breakpoint
3058
table using several rows---one header row, followed by one row for
3059
each breakpoint location.  The header row has @samp{<MULTIPLE>} in the
3060
address column.  The rows for individual locations contain the actual
3061
addresses for locations, and show the functions to which those
3062
locations belong.  The number column for a location is of the form
3063
@var{breakpoint-number}.@var{location-number}.
3064
 
3065
For example:
3066
 
3067
@smallexample
3068
Num     Type           Disp Enb  Address    What
3069
1       breakpoint     keep y    <MULTIPLE>
3070
        stop only if i==1
3071
        breakpoint already hit 1 time
3072
1.1                         y    0x080486a2 in void foo<int>() at t.cc:8
3073
1.2                         y    0x080486ca in void foo<double>() at t.cc:8
3074
@end smallexample
3075
 
3076
Each location can be individually enabled or disabled by passing
3077
@var{breakpoint-number}.@var{location-number} as argument to the
3078
@code{enable} and @code{disable} commands.  Note that you cannot
3079
delete the individual locations from the list, you can only delete the
3080
entire list of locations that belong to their parent breakpoint (with
3081
the @kbd{delete @var{num}} command, where @var{num} is the number of
3082
the parent breakpoint, 1 in the above example).  Disabling or enabling
3083
the parent breakpoint (@pxref{Disabling}) affects all of the locations
3084
that belong to that breakpoint.
3085
 
3086
@cindex pending breakpoints
3087
It's quite common to have a breakpoint inside a shared library.
3088
Shared libraries can be loaded and unloaded explicitly,
3089
and possibly repeatedly, as the program is executed.  To support
3090
this use case, @value{GDBN} updates breakpoint locations whenever
3091
any shared library is loaded or unloaded.  Typically, you would
3092
set a breakpoint in a shared library at the beginning of your
3093
debugging session, when the library is not loaded, and when the
3094
symbols from the library are not available.  When you try to set
3095
breakpoint, @value{GDBN} will ask you if you want to set
3096
a so called @dfn{pending breakpoint}---breakpoint whose address
3097
is not yet resolved.
3098
 
3099
After the program is run, whenever a new shared library is loaded,
3100
@value{GDBN} reevaluates all the breakpoints.  When a newly loaded
3101
shared library contains the symbol or line referred to by some
3102
pending breakpoint, that breakpoint is resolved and becomes an
3103
ordinary breakpoint.  When a library is unloaded, all breakpoints
3104
that refer to its symbols or source lines become pending again.
3105
 
3106
This logic works for breakpoints with multiple locations, too.  For
3107
example, if you have a breakpoint in a C@t{++} template function, and
3108
a newly loaded shared library has an instantiation of that template,
3109
a new location is added to the list of locations for the breakpoint.
3110
 
3111
Except for having unresolved address, pending breakpoints do not
3112
differ from regular breakpoints.  You can set conditions or commands,
3113
enable and disable them and perform other breakpoint operations.
3114
 
3115
@value{GDBN} provides some additional commands for controlling what
3116
happens when the @samp{break} command cannot resolve breakpoint
3117
address specification to an address:
3118
 
3119
@kindex set breakpoint pending
3120
@kindex show breakpoint pending
3121
@table @code
3122
@item set breakpoint pending auto
3123
This is the default behavior.  When @value{GDBN} cannot find the breakpoint
3124
location, it queries you whether a pending breakpoint should be created.
3125
 
3126
@item set breakpoint pending on
3127
This indicates that an unrecognized breakpoint location should automatically
3128
result in a pending breakpoint being created.
3129
 
3130
@item set breakpoint pending off
3131
This indicates that pending breakpoints are not to be created.  Any
3132
unrecognized breakpoint location results in an error.  This setting does
3133
not affect any pending breakpoints previously created.
3134
 
3135
@item show breakpoint pending
3136
Show the current behavior setting for creating pending breakpoints.
3137
@end table
3138
 
3139
The settings above only affect the @code{break} command and its
3140
variants.  Once breakpoint is set, it will be automatically updated
3141
as shared libraries are loaded and unloaded.
3142
 
3143
@cindex automatic hardware breakpoints
3144
For some targets, @value{GDBN} can automatically decide if hardware or
3145
software breakpoints should be used, depending on whether the
3146
breakpoint address is read-only or read-write.  This applies to
3147
breakpoints set with the @code{break} command as well as to internal
3148
breakpoints set by commands like @code{next} and @code{finish}.  For
3149
breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
3150
breakpoints.
3151
 
3152
You can control this automatic behaviour with the following commands::
3153
 
3154
@kindex set breakpoint auto-hw
3155
@kindex show breakpoint auto-hw
3156
@table @code
3157
@item set breakpoint auto-hw on
3158
This is the default behavior.  When @value{GDBN} sets a breakpoint, it
3159
will try to use the target memory map to decide if software or hardware
3160
breakpoint must be used.
3161
 
3162
@item set breakpoint auto-hw off
3163
This indicates @value{GDBN} should not automatically select breakpoint
3164
type.  If the target provides a memory map, @value{GDBN} will warn when
3165
trying to set software breakpoint at a read-only address.
3166
@end table
3167
 
3168
 
3169
@cindex negative breakpoint numbers
3170
@cindex internal @value{GDBN} breakpoints
3171
@value{GDBN} itself sometimes sets breakpoints in your program for
3172
special purposes, such as proper handling of @code{longjmp} (in C
3173
programs).  These internal breakpoints are assigned negative numbers,
3174
starting with @code{-1}; @samp{info breakpoints} does not display them.
3175
You can see these breakpoints with the @value{GDBN} maintenance command
3176
@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3177
 
3178
 
3179
@node Set Watchpoints
3180
@subsection Setting Watchpoints
3181
 
3182
@cindex setting watchpoints
3183
You can use a watchpoint to stop execution whenever the value of an
3184
expression changes, without having to predict a particular place where
3185
this may happen.  (This is sometimes called a @dfn{data breakpoint}.)
3186
The expression may be as simple as the value of a single variable, or
3187
as complex as many variables combined by operators.  Examples include:
3188
 
3189
@itemize @bullet
3190
@item
3191
A reference to the value of a single variable.
3192
 
3193
@item
3194
An address cast to an appropriate data type.  For example,
3195
@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3196
address (assuming an @code{int} occupies 4 bytes).
3197
 
3198
@item
3199
An arbitrarily complex expression, such as @samp{a*b + c/d}.  The
3200
expression can use any operators valid in the program's native
3201
language (@pxref{Languages}).
3202
@end itemize
3203
 
3204
@cindex software watchpoints
3205
@cindex hardware watchpoints
3206
Depending on your system, watchpoints may be implemented in software or
3207
hardware.  @value{GDBN} does software watchpointing by single-stepping your
3208
program and testing the variable's value each time, which is hundreds of
3209
times slower than normal execution.  (But this may still be worth it, to
3210
catch errors where you have no clue what part of your program is the
3211
culprit.)
3212
 
3213
On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
3214
x86-based targets, @value{GDBN} includes support for hardware
3215
watchpoints, which do not slow down the running of your program.
3216
 
3217
@table @code
3218
@kindex watch
3219
@item watch @var{expr} @r{[}thread @var{threadnum}@r{]}
3220
Set a watchpoint for an expression.  @value{GDBN} will break when the
3221
expression @var{expr} is written into by the program and its value
3222
changes.  The simplest (and the most popular) use of this command is
3223
to watch the value of a single variable:
3224
 
3225
@smallexample
3226
(@value{GDBP}) watch foo
3227
@end smallexample
3228
 
3229
If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3230
clause, @value{GDBN} breaks only when the thread identified by
3231
@var{threadnum} changes the value of @var{expr}.  If any other threads
3232
change the value of @var{expr}, @value{GDBN} will not break.  Note
3233
that watchpoints restricted to a single thread in this way only work
3234
with Hardware Watchpoints.
3235
 
3236
@kindex rwatch
3237
@item rwatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3238
Set a watchpoint that will break when the value of @var{expr} is read
3239
by the program.
3240
 
3241
@kindex awatch
3242
@item awatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3243
Set a watchpoint that will break when @var{expr} is either read from
3244
or written into by the program.
3245
 
3246
@kindex info watchpoints @r{[}@var{n}@r{]}
3247
@item info watchpoints
3248
This command prints a list of watchpoints, breakpoints, and catchpoints;
3249
it is the same as @code{info break} (@pxref{Set Breaks}).
3250
@end table
3251
 
3252
@value{GDBN} sets a @dfn{hardware watchpoint} if possible.  Hardware
3253
watchpoints execute very quickly, and the debugger reports a change in
3254
value at the exact instruction where the change occurs.  If @value{GDBN}
3255
cannot set a hardware watchpoint, it sets a software watchpoint, which
3256
executes more slowly and reports the change in value at the next
3257
@emph{statement}, not the instruction, after the change occurs.
3258
 
3259
@cindex use only software watchpoints
3260
You can force @value{GDBN} to use only software watchpoints with the
3261
@kbd{set can-use-hw-watchpoints 0} command.  With this variable set to
3262
zero, @value{GDBN} will never try to use hardware watchpoints, even if
3263
the underlying system supports them.  (Note that hardware-assisted
3264
watchpoints that were set @emph{before} setting
3265
@code{can-use-hw-watchpoints} to zero will still use the hardware
3266
mechanism of watching expression values.)
3267
 
3268
@table @code
3269
@item set can-use-hw-watchpoints
3270
@kindex set can-use-hw-watchpoints
3271
Set whether or not to use hardware watchpoints.
3272
 
3273
@item show can-use-hw-watchpoints
3274
@kindex show can-use-hw-watchpoints
3275
Show the current mode of using hardware watchpoints.
3276
@end table
3277
 
3278
For remote targets, you can restrict the number of hardware
3279
watchpoints @value{GDBN} will use, see @ref{set remote
3280
hardware-breakpoint-limit}.
3281
 
3282
When you issue the @code{watch} command, @value{GDBN} reports
3283
 
3284
@smallexample
3285
Hardware watchpoint @var{num}: @var{expr}
3286
@end smallexample
3287
 
3288
@noindent
3289
if it was able to set a hardware watchpoint.
3290
 
3291
Currently, the @code{awatch} and @code{rwatch} commands can only set
3292
hardware watchpoints, because accesses to data that don't change the
3293
value of the watched expression cannot be detected without examining
3294
every instruction as it is being executed, and @value{GDBN} does not do
3295
that currently.  If @value{GDBN} finds that it is unable to set a
3296
hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3297
will print a message like this:
3298
 
3299
@smallexample
3300
Expression cannot be implemented with read/access watchpoint.
3301
@end smallexample
3302
 
3303
Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3304
data type of the watched expression is wider than what a hardware
3305
watchpoint on the target machine can handle.  For example, some systems
3306
can only watch regions that are up to 4 bytes wide; on such systems you
3307
cannot set hardware watchpoints for an expression that yields a
3308
double-precision floating-point number (which is typically 8 bytes
3309
wide).  As a work-around, it might be possible to break the large region
3310
into a series of smaller ones and watch them with separate watchpoints.
3311
 
3312
If you set too many hardware watchpoints, @value{GDBN} might be unable
3313
to insert all of them when you resume the execution of your program.
3314
Since the precise number of active watchpoints is unknown until such
3315
time as the program is about to be resumed, @value{GDBN} might not be
3316
able to warn you about this when you set the watchpoints, and the
3317
warning will be printed only when the program is resumed:
3318
 
3319
@smallexample
3320
Hardware watchpoint @var{num}: Could not insert watchpoint
3321
@end smallexample
3322
 
3323
@noindent
3324
If this happens, delete or disable some of the watchpoints.
3325
 
3326
Watching complex expressions that reference many variables can also
3327
exhaust the resources available for hardware-assisted watchpoints.
3328
That's because @value{GDBN} needs to watch every variable in the
3329
expression with separately allocated resources.
3330
 
3331
The SPARClite DSU will generate traps when a program accesses some data
3332
or instruction address that is assigned to the debug registers.  For the
3333
data addresses, DSU facilitates the @code{watch} command.  However the
3334
hardware breakpoint registers can only take two data watchpoints, and
3335
both watchpoints must be the same kind.  For example, you can set two
3336
watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3337
@strong{or} two with @code{awatch} commands, but you cannot set one
3338
watchpoint with one command and the other with a different command.
3339
@value{GDBN} will reject the command if you try to mix watchpoints.
3340
Delete or disable unused watchpoint commands before setting new ones.
3341
 
3342
If you call a function interactively using @code{print} or @code{call},
3343
any watchpoints you have set will be inactive until @value{GDBN} reaches another
3344
kind of breakpoint or the call completes.
3345
 
3346
@value{GDBN} automatically deletes watchpoints that watch local
3347
(automatic) variables, or expressions that involve such variables, when
3348
they go out of scope, that is, when the execution leaves the block in
3349
which these variables were defined.  In particular, when the program
3350
being debugged terminates, @emph{all} local variables go out of scope,
3351
and so only watchpoints that watch global variables remain set.  If you
3352
rerun the program, you will need to set all such watchpoints again.  One
3353
way of doing that would be to set a code breakpoint at the entry to the
3354
@code{main} function and when it breaks, set all the watchpoints.
3355
 
3356
@cindex watchpoints and threads
3357
@cindex threads and watchpoints
3358
In multi-threaded programs, watchpoints will detect changes to the
3359
watched expression from every thread.
3360
 
3361
@quotation
3362
@emph{Warning:} In multi-threaded programs, software watchpoints
3363
have only limited usefulness.  If @value{GDBN} creates a software
3364
watchpoint, it can only watch the value of an expression @emph{in a
3365
single thread}.  If you are confident that the expression can only
3366
change due to the current thread's activity (and if you are also
3367
confident that no other thread can become current), then you can use
3368
software watchpoints as usual.  However, @value{GDBN} may not notice
3369
when a non-current thread's activity changes the expression.  (Hardware
3370
watchpoints, in contrast, watch an expression in all threads.)
3371
@end quotation
3372
 
3373
@xref{set remote hardware-watchpoint-limit}.
3374
 
3375
@node Set Catchpoints
3376
@subsection Setting Catchpoints
3377
@cindex catchpoints, setting
3378
@cindex exception handlers
3379
@cindex event handling
3380
 
3381
You can use @dfn{catchpoints} to cause the debugger to stop for certain
3382
kinds of program events, such as C@t{++} exceptions or the loading of a
3383
shared library.  Use the @code{catch} command to set a catchpoint.
3384
 
3385
@table @code
3386
@kindex catch
3387
@item catch @var{event}
3388
Stop when @var{event} occurs.  @var{event} can be any of the following:
3389
@table @code
3390
@item throw
3391
@cindex stop on C@t{++} exceptions
3392
The throwing of a C@t{++} exception.
3393
 
3394
@item catch
3395
The catching of a C@t{++} exception.
3396
 
3397
@item exception
3398
@cindex Ada exception catching
3399
@cindex catch Ada exceptions
3400
An Ada exception being raised.  If an exception name is specified
3401
at the end of the command (eg @code{catch exception Program_Error}),
3402
the debugger will stop only when this specific exception is raised.
3403
Otherwise, the debugger stops execution when any Ada exception is raised.
3404
 
3405
@item exception unhandled
3406
An exception that was raised but is not handled by the program.
3407
 
3408
@item assert
3409
A failed Ada assertion.
3410
 
3411
@item exec
3412
@cindex break on fork/exec
3413
A call to @code{exec}.  This is currently only available for HP-UX
3414
and @sc{gnu}/Linux.
3415
 
3416
@item fork
3417
A call to @code{fork}.  This is currently only available for HP-UX
3418
and @sc{gnu}/Linux.
3419
 
3420
@item vfork
3421
A call to @code{vfork}.  This is currently only available for HP-UX
3422
and @sc{gnu}/Linux.
3423
 
3424
@item load
3425
@itemx load @var{libname}
3426
@cindex break on load/unload of shared library
3427
The dynamic loading of any shared library, or the loading of the library
3428
@var{libname}.  This is currently only available for HP-UX.
3429
 
3430
@item unload
3431
@itemx unload @var{libname}
3432
The unloading of any dynamically loaded shared library, or the unloading
3433
of the library @var{libname}.  This is currently only available for HP-UX.
3434
@end table
3435
 
3436
@item tcatch @var{event}
3437
Set a catchpoint that is enabled only for one stop.  The catchpoint is
3438
automatically deleted after the first time the event is caught.
3439
 
3440
@end table
3441
 
3442
Use the @code{info break} command to list the current catchpoints.
3443
 
3444
There are currently some limitations to C@t{++} exception handling
3445
(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3446
 
3447
@itemize @bullet
3448
@item
3449
If you call a function interactively, @value{GDBN} normally returns
3450
control to you when the function has finished executing.  If the call
3451
raises an exception, however, the call may bypass the mechanism that
3452
returns control to you and cause your program either to abort or to
3453
simply continue running until it hits a breakpoint, catches a signal
3454
that @value{GDBN} is listening for, or exits.  This is the case even if
3455
you set a catchpoint for the exception; catchpoints on exceptions are
3456
disabled within interactive calls.
3457
 
3458
@item
3459
You cannot raise an exception interactively.
3460
 
3461
@item
3462
You cannot install an exception handler interactively.
3463
@end itemize
3464
 
3465
@cindex raise exceptions
3466
Sometimes @code{catch} is not the best way to debug exception handling:
3467
if you need to know exactly where an exception is raised, it is better to
3468
stop @emph{before} the exception handler is called, since that way you
3469
can see the stack before any unwinding takes place.  If you set a
3470
breakpoint in an exception handler instead, it may not be easy to find
3471
out where the exception was raised.
3472
 
3473
To stop just before an exception handler is called, you need some
3474
knowledge of the implementation.  In the case of @sc{gnu} C@t{++}, exceptions are
3475
raised by calling a library function named @code{__raise_exception}
3476
which has the following ANSI C interface:
3477
 
3478
@smallexample
3479
    /* @var{addr} is where the exception identifier is stored.
3480
       @var{id} is the exception identifier.  */
3481
    void __raise_exception (void **addr, void *id);
3482
@end smallexample
3483
 
3484
@noindent
3485
To make the debugger catch all exceptions before any stack
3486
unwinding takes place, set a breakpoint on @code{__raise_exception}
3487
(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
3488
 
3489
With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
3490
that depends on the value of @var{id}, you can stop your program when
3491
a specific exception is raised.  You can use multiple conditional
3492
breakpoints to stop your program when any of a number of exceptions are
3493
raised.
3494
 
3495
 
3496
@node Delete Breaks
3497
@subsection Deleting Breakpoints
3498
 
3499
@cindex clearing breakpoints, watchpoints, catchpoints
3500
@cindex deleting breakpoints, watchpoints, catchpoints
3501
It is often necessary to eliminate a breakpoint, watchpoint, or
3502
catchpoint once it has done its job and you no longer want your program
3503
to stop there.  This is called @dfn{deleting} the breakpoint.  A
3504
breakpoint that has been deleted no longer exists; it is forgotten.
3505
 
3506
With the @code{clear} command you can delete breakpoints according to
3507
where they are in your program.  With the @code{delete} command you can
3508
delete individual breakpoints, watchpoints, or catchpoints by specifying
3509
their breakpoint numbers.
3510
 
3511
It is not necessary to delete a breakpoint to proceed past it.  @value{GDBN}
3512
automatically ignores breakpoints on the first instruction to be executed
3513
when you continue execution without changing the execution address.
3514
 
3515
@table @code
3516
@kindex clear
3517
@item clear
3518
Delete any breakpoints at the next instruction to be executed in the
3519
selected stack frame (@pxref{Selection, ,Selecting a Frame}).  When
3520
the innermost frame is selected, this is a good way to delete a
3521
breakpoint where your program just stopped.
3522
 
3523
@item clear @var{location}
3524
Delete any breakpoints set at the specified @var{location}.
3525
@xref{Specify Location}, for the various forms of @var{location}; the
3526
most useful ones are listed below:
3527
 
3528
@table @code
3529
@item clear @var{function}
3530
@itemx clear @var{filename}:@var{function}
3531
Delete any breakpoints set at entry to the named @var{function}.
3532
 
3533
@item clear @var{linenum}
3534
@itemx clear @var{filename}:@var{linenum}
3535
Delete any breakpoints set at or within the code of the specified
3536
@var{linenum} of the specified @var{filename}.
3537
@end table
3538
 
3539
@cindex delete breakpoints
3540
@kindex delete
3541
@kindex d @r{(@code{delete})}
3542
@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3543
Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3544
ranges specified as arguments.  If no argument is specified, delete all
3545
breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3546
confirm off}).  You can abbreviate this command as @code{d}.
3547
@end table
3548
 
3549
@node Disabling
3550
@subsection Disabling Breakpoints
3551
 
3552
@cindex enable/disable a breakpoint
3553
Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3554
prefer to @dfn{disable} it.  This makes the breakpoint inoperative as if
3555
it had been deleted, but remembers the information on the breakpoint so
3556
that you can @dfn{enable} it again later.
3557
 
3558
You disable and enable breakpoints, watchpoints, and catchpoints with
3559
the @code{enable} and @code{disable} commands, optionally specifying one
3560
or more breakpoint numbers as arguments.  Use @code{info break} or
3561
@code{info watch} to print a list of breakpoints, watchpoints, and
3562
catchpoints if you do not know which numbers to use.
3563
 
3564
Disabling and enabling a breakpoint that has multiple locations
3565
affects all of its locations.
3566
 
3567
A breakpoint, watchpoint, or catchpoint can have any of four different
3568
states of enablement:
3569
 
3570
@itemize @bullet
3571
@item
3572
Enabled.  The breakpoint stops your program.  A breakpoint set
3573
with the @code{break} command starts out in this state.
3574
@item
3575
Disabled.  The breakpoint has no effect on your program.
3576
@item
3577
Enabled once.  The breakpoint stops your program, but then becomes
3578
disabled.
3579
@item
3580
Enabled for deletion.  The breakpoint stops your program, but
3581
immediately after it does so it is deleted permanently.  A breakpoint
3582
set with the @code{tbreak} command starts out in this state.
3583
@end itemize
3584
 
3585
You can use the following commands to enable or disable breakpoints,
3586
watchpoints, and catchpoints:
3587
 
3588
@table @code
3589
@kindex disable
3590
@kindex dis @r{(@code{disable})}
3591
@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3592
Disable the specified breakpoints---or all breakpoints, if none are
3593
listed.  A disabled breakpoint has no effect but is not forgotten.  All
3594
options such as ignore-counts, conditions and commands are remembered in
3595
case the breakpoint is enabled again later.  You may abbreviate
3596
@code{disable} as @code{dis}.
3597
 
3598
@kindex enable
3599
@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3600
Enable the specified breakpoints (or all defined breakpoints).  They
3601
become effective once again in stopping your program.
3602
 
3603
@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
3604
Enable the specified breakpoints temporarily.  @value{GDBN} disables any
3605
of these breakpoints immediately after stopping your program.
3606
 
3607
@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
3608
Enable the specified breakpoints to work once, then die.  @value{GDBN}
3609
deletes any of these breakpoints as soon as your program stops there.
3610
Breakpoints set by the @code{tbreak} command start out in this state.
3611
@end table
3612
 
3613
@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3614
@c confusing: tbreak is also initially enabled.
3615
Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3616
,Setting Breakpoints}), breakpoints that you set are initially enabled;
3617
subsequently, they become disabled or enabled only when you use one of
3618
the commands above.  (The command @code{until} can set and delete a
3619
breakpoint of its own, but it does not change the state of your other
3620
breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3621
Stepping}.)
3622
 
3623
@node Conditions
3624
@subsection Break Conditions
3625
@cindex conditional breakpoints
3626
@cindex breakpoint conditions
3627
 
3628
@c FIXME what is scope of break condition expr?  Context where wanted?
3629
@c      in particular for a watchpoint?
3630
The simplest sort of breakpoint breaks every time your program reaches a
3631
specified place.  You can also specify a @dfn{condition} for a
3632
breakpoint.  A condition is just a Boolean expression in your
3633
programming language (@pxref{Expressions, ,Expressions}).  A breakpoint with
3634
a condition evaluates the expression each time your program reaches it,
3635
and your program stops only if the condition is @emph{true}.
3636
 
3637
This is the converse of using assertions for program validation; in that
3638
situation, you want to stop when the assertion is violated---that is,
3639
when the condition is false.  In C, if you want to test an assertion expressed
3640
by the condition @var{assert}, you should set the condition
3641
@samp{! @var{assert}} on the appropriate breakpoint.
3642
 
3643
Conditions are also accepted for watchpoints; you may not need them,
3644
since a watchpoint is inspecting the value of an expression anyhow---but
3645
it might be simpler, say, to just set a watchpoint on a variable name,
3646
and specify a condition that tests whether the new value is an interesting
3647
one.
3648
 
3649
Break conditions can have side effects, and may even call functions in
3650
your program.  This can be useful, for example, to activate functions
3651
that log program progress, or to use your own print functions to
3652
format special data structures. The effects are completely predictable
3653
unless there is another enabled breakpoint at the same address.  (In
3654
that case, @value{GDBN} might see the other breakpoint first and stop your
3655
program without checking the condition of this one.)  Note that
3656
breakpoint commands are usually more convenient and flexible than break
3657
conditions for the
3658
purpose of performing side effects when a breakpoint is reached
3659
(@pxref{Break Commands, ,Breakpoint Command Lists}).
3660
 
3661
Break conditions can be specified when a breakpoint is set, by using
3662
@samp{if} in the arguments to the @code{break} command.  @xref{Set
3663
Breaks, ,Setting Breakpoints}.  They can also be changed at any time
3664
with the @code{condition} command.
3665
 
3666
You can also use the @code{if} keyword with the @code{watch} command.
3667
The @code{catch} command does not recognize the @code{if} keyword;
3668
@code{condition} is the only way to impose a further condition on a
3669
catchpoint.
3670
 
3671
@table @code
3672
@kindex condition
3673
@item condition @var{bnum} @var{expression}
3674
Specify @var{expression} as the break condition for breakpoint,
3675
watchpoint, or catchpoint number @var{bnum}.  After you set a condition,
3676
breakpoint @var{bnum} stops your program only if the value of
3677
@var{expression} is true (nonzero, in C).  When you use
3678
@code{condition}, @value{GDBN} checks @var{expression} immediately for
3679
syntactic correctness, and to determine whether symbols in it have
3680
referents in the context of your breakpoint.  If @var{expression} uses
3681
symbols not referenced in the context of the breakpoint, @value{GDBN}
3682
prints an error message:
3683
 
3684
@smallexample
3685
No symbol "foo" in current context.
3686
@end smallexample
3687
 
3688
@noindent
3689
@value{GDBN} does
3690
not actually evaluate @var{expression} at the time the @code{condition}
3691
command (or a command that sets a breakpoint with a condition, like
3692
@code{break if @dots{}}) is given, however.  @xref{Expressions, ,Expressions}.
3693
 
3694
@item condition @var{bnum}
3695
Remove the condition from breakpoint number @var{bnum}.  It becomes
3696
an ordinary unconditional breakpoint.
3697
@end table
3698
 
3699
@cindex ignore count (of breakpoint)
3700
A special case of a breakpoint condition is to stop only when the
3701
breakpoint has been reached a certain number of times.  This is so
3702
useful that there is a special way to do it, using the @dfn{ignore
3703
count} of the breakpoint.  Every breakpoint has an ignore count, which
3704
is an integer.  Most of the time, the ignore count is zero, and
3705
therefore has no effect.  But if your program reaches a breakpoint whose
3706
ignore count is positive, then instead of stopping, it just decrements
3707
the ignore count by one and continues.  As a result, if the ignore count
3708
value is @var{n}, the breakpoint does not stop the next @var{n} times
3709
your program reaches it.
3710
 
3711
@table @code
3712
@kindex ignore
3713
@item ignore @var{bnum} @var{count}
3714
Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3715
The next @var{count} times the breakpoint is reached, your program's
3716
execution does not stop; other than to decrement the ignore count, @value{GDBN}
3717
takes no action.
3718
 
3719
To make the breakpoint stop the next time it is reached, specify
3720
a count of zero.
3721
 
3722
When you use @code{continue} to resume execution of your program from a
3723
breakpoint, you can specify an ignore count directly as an argument to
3724
@code{continue}, rather than using @code{ignore}.  @xref{Continuing and
3725
Stepping,,Continuing and Stepping}.
3726
 
3727
If a breakpoint has a positive ignore count and a condition, the
3728
condition is not checked.  Once the ignore count reaches zero,
3729
@value{GDBN} resumes checking the condition.
3730
 
3731
You could achieve the effect of the ignore count with a condition such
3732
as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3733
is decremented each time.  @xref{Convenience Vars, ,Convenience
3734
Variables}.
3735
@end table
3736
 
3737
Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3738
 
3739
 
3740
@node Break Commands
3741
@subsection Breakpoint Command Lists
3742
 
3743
@cindex breakpoint commands
3744
You can give any breakpoint (or watchpoint or catchpoint) a series of
3745
commands to execute when your program stops due to that breakpoint.  For
3746
example, you might want to print the values of certain expressions, or
3747
enable other breakpoints.
3748
 
3749
@table @code
3750
@kindex commands
3751
@kindex end@r{ (breakpoint commands)}
3752
@item commands @r{[}@var{bnum}@r{]}
3753
@itemx @dots{} @var{command-list} @dots{}
3754
@itemx end
3755
Specify a list of commands for breakpoint number @var{bnum}.  The commands
3756
themselves appear on the following lines.  Type a line containing just
3757
@code{end} to terminate the commands.
3758
 
3759
To remove all commands from a breakpoint, type @code{commands} and
3760
follow it immediately with @code{end}; that is, give no commands.
3761
 
3762
With no @var{bnum} argument, @code{commands} refers to the last
3763
breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3764
recently encountered).
3765
@end table
3766
 
3767
Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3768
disabled within a @var{command-list}.
3769
 
3770
You can use breakpoint commands to start your program up again.  Simply
3771
use the @code{continue} command, or @code{step}, or any other command
3772
that resumes execution.
3773
 
3774
Any other commands in the command list, after a command that resumes
3775
execution, are ignored.  This is because any time you resume execution
3776
(even with a simple @code{next} or @code{step}), you may encounter
3777
another breakpoint---which could have its own command list, leading to
3778
ambiguities about which list to execute.
3779
 
3780
@kindex silent
3781
If the first command you specify in a command list is @code{silent}, the
3782
usual message about stopping at a breakpoint is not printed.  This may
3783
be desirable for breakpoints that are to print a specific message and
3784
then continue.  If none of the remaining commands print anything, you
3785
see no sign that the breakpoint was reached.  @code{silent} is
3786
meaningful only at the beginning of a breakpoint command list.
3787
 
3788
The commands @code{echo}, @code{output}, and @code{printf} allow you to
3789
print precisely controlled output, and are often useful in silent
3790
breakpoints.  @xref{Output, ,Commands for Controlled Output}.
3791
 
3792
For example, here is how you could use breakpoint commands to print the
3793
value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3794
 
3795
@smallexample
3796
break foo if x>0
3797
commands
3798
silent
3799
printf "x is %d\n",x
3800
cont
3801
end
3802
@end smallexample
3803
 
3804
One application for breakpoint commands is to compensate for one bug so
3805
you can test for another.  Put a breakpoint just after the erroneous line
3806
of code, give it a condition to detect the case in which something
3807
erroneous has been done, and give it commands to assign correct values
3808
to any variables that need them.  End with the @code{continue} command
3809
so that your program does not stop, and start with the @code{silent}
3810
command so that no output is produced.  Here is an example:
3811
 
3812
@smallexample
3813
break 403
3814
commands
3815
silent
3816
set x = y + 4
3817
cont
3818
end
3819
@end smallexample
3820
 
3821
@node Breakpoint Menus
3822
@subsection Breakpoint Menus
3823
@cindex overloading
3824
@cindex symbol overloading
3825
 
3826
Some programming languages (notably C@t{++} and Objective-C) permit a
3827
single function name
3828
to be defined several times, for application in different contexts.
3829
This is called @dfn{overloading}.  When a function name is overloaded,
3830
@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3831
a breakpoint.  You can use explicit signature of the function, as in
3832
@samp{break @var{function}(@var{types})}, to specify which
3833
particular version of the function you want.  Otherwise, @value{GDBN} offers
3834
you a menu of numbered choices for different possible breakpoints, and
3835
waits for your selection with the prompt @samp{>}.  The first two
3836
options are always @samp{[0] cancel} and @samp{[1] all}.  Typing @kbd{1}
3837
sets a breakpoint at each definition of @var{function}, and typing
3838
@kbd{0} aborts the @code{break} command without setting any new
3839
breakpoints.
3840
 
3841
For example, the following session excerpt shows an attempt to set a
3842
breakpoint at the overloaded symbol @code{String::after}.
3843
We choose three particular definitions of that function name:
3844
 
3845
@c FIXME! This is likely to change to show arg type lists, at least
3846
@smallexample
3847
@group
3848
(@value{GDBP}) b String::after
3849
[0] cancel
3850
[1] all
3851
[2] file:String.cc; line number:867
3852
[3] file:String.cc; line number:860
3853
[4] file:String.cc; line number:875
3854
[5] file:String.cc; line number:853
3855
[6] file:String.cc; line number:846
3856
[7] file:String.cc; line number:735
3857
> 2 4 6
3858
Breakpoint 1 at 0xb26c: file String.cc, line 867.
3859
Breakpoint 2 at 0xb344: file String.cc, line 875.
3860
Breakpoint 3 at 0xafcc: file String.cc, line 846.
3861
Multiple breakpoints were set.
3862
Use the "delete" command to delete unwanted
3863
 breakpoints.
3864
(@value{GDBP})
3865
@end group
3866
@end smallexample
3867
 
3868
@c  @ifclear BARETARGET
3869
@node Error in Breakpoints
3870
@subsection ``Cannot insert breakpoints''
3871
@c
3872
@c  FIXME!! 14/6/95  Is there a real example of this?  Let's use it.
3873
@c
3874
Under some operating systems, breakpoints cannot be used in a program if
3875
any other process is running that program.  In this situation,
3876
attempting to run or continue a program with a breakpoint causes
3877
@value{GDBN} to print an error message:
3878
 
3879
@smallexample
3880
Cannot insert breakpoints.
3881
The same program may be running in another process.
3882
@end smallexample
3883
 
3884
When this happens, you have three ways to proceed:
3885
 
3886
@enumerate
3887
@item
3888
Remove or disable the breakpoints, then continue.
3889
 
3890
@item
3891
Suspend @value{GDBN}, and copy the file containing your program to a new
3892
name.  Resume @value{GDBN} and use the @code{exec-file} command to specify
3893
that @value{GDBN} should run your program under that name.
3894
Then start your program again.
3895
 
3896
@item
3897
Relink your program so that the text segment is nonsharable, using the
3898
linker option @samp{-N}.  The operating system limitation may not apply
3899
to nonsharable executables.
3900
@end enumerate
3901
@c  @end ifclear
3902
 
3903
A similar message can be printed if you request too many active
3904
hardware-assisted breakpoints and watchpoints:
3905
 
3906
@c FIXME: the precise wording of this message may change; the relevant
3907
@c source change is not committed yet (Sep 3, 1999).
3908
@smallexample
3909
Stopped; cannot insert breakpoints.
3910
You may have requested too many hardware breakpoints and watchpoints.
3911
@end smallexample
3912
 
3913
@noindent
3914
This message is printed when you attempt to resume the program, since
3915
only then @value{GDBN} knows exactly how many hardware breakpoints and
3916
watchpoints it needs to insert.
3917
 
3918
When this message is printed, you need to disable or remove some of the
3919
hardware-assisted breakpoints and watchpoints, and then continue.
3920
 
3921
@node Breakpoint-related Warnings
3922
@subsection ``Breakpoint address adjusted...''
3923
@cindex breakpoint address adjusted
3924
 
3925
Some processor architectures place constraints on the addresses at
3926
which breakpoints may be placed.  For architectures thus constrained,
3927
@value{GDBN} will attempt to adjust the breakpoint's address to comply
3928
with the constraints dictated by the architecture.
3929
 
3930
One example of such an architecture is the Fujitsu FR-V.  The FR-V is
3931
a VLIW architecture in which a number of RISC-like instructions may be
3932
bundled together for parallel execution.  The FR-V architecture
3933
constrains the location of a breakpoint instruction within such a
3934
bundle to the instruction with the lowest address.  @value{GDBN}
3935
honors this constraint by adjusting a breakpoint's address to the
3936
first in the bundle.
3937
 
3938
It is not uncommon for optimized code to have bundles which contain
3939
instructions from different source statements, thus it may happen that
3940
a breakpoint's address will be adjusted from one source statement to
3941
another.  Since this adjustment may significantly alter @value{GDBN}'s
3942
breakpoint related behavior from what the user expects, a warning is
3943
printed when the breakpoint is first set and also when the breakpoint
3944
is hit.
3945
 
3946
A warning like the one below is printed when setting a breakpoint
3947
that's been subject to address adjustment:
3948
 
3949
@smallexample
3950
warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3951
@end smallexample
3952
 
3953
Such warnings are printed both for user settable and @value{GDBN}'s
3954
internal breakpoints.  If you see one of these warnings, you should
3955
verify that a breakpoint set at the adjusted address will have the
3956
desired affect.  If not, the breakpoint in question may be removed and
3957
other breakpoints may be set which will have the desired behavior.
3958
E.g., it may be sufficient to place the breakpoint at a later
3959
instruction.  A conditional breakpoint may also be useful in some
3960
cases to prevent the breakpoint from triggering too often.
3961
 
3962
@value{GDBN} will also issue a warning when stopping at one of these
3963
adjusted breakpoints:
3964
 
3965
@smallexample
3966
warning: Breakpoint 1 address previously adjusted from 0x00010414
3967
to 0x00010410.
3968
@end smallexample
3969
 
3970
When this warning is encountered, it may be too late to take remedial
3971
action except in cases where the breakpoint is hit earlier or more
3972
frequently than expected.
3973
 
3974
@node Continuing and Stepping
3975
@section Continuing and Stepping
3976
 
3977
@cindex stepping
3978
@cindex continuing
3979
@cindex resuming execution
3980
@dfn{Continuing} means resuming program execution until your program
3981
completes normally.  In contrast, @dfn{stepping} means executing just
3982
one more ``step'' of your program, where ``step'' may mean either one
3983
line of source code, or one machine instruction (depending on what
3984
particular command you use).  Either when continuing or when stepping,
3985
your program may stop even sooner, due to a breakpoint or a signal.  (If
3986
it stops due to a signal, you may want to use @code{handle}, or use
3987
@samp{signal 0} to resume execution.  @xref{Signals, ,Signals}.)
3988
 
3989
@table @code
3990
@kindex continue
3991
@kindex c @r{(@code{continue})}
3992
@kindex fg @r{(resume foreground execution)}
3993
@item continue @r{[}@var{ignore-count}@r{]}
3994
@itemx c @r{[}@var{ignore-count}@r{]}
3995
@itemx fg @r{[}@var{ignore-count}@r{]}
3996
Resume program execution, at the address where your program last stopped;
3997
any breakpoints set at that address are bypassed.  The optional argument
3998
@var{ignore-count} allows you to specify a further number of times to
3999
ignore a breakpoint at this location; its effect is like that of
4000
@code{ignore} (@pxref{Conditions, ,Break Conditions}).
4001
 
4002
The argument @var{ignore-count} is meaningful only when your program
4003
stopped due to a breakpoint.  At other times, the argument to
4004
@code{continue} is ignored.
4005
 
4006
The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4007
debugged program is deemed to be the foreground program) are provided
4008
purely for convenience, and have exactly the same behavior as
4009
@code{continue}.
4010
@end table
4011
 
4012
To resume execution at a different place, you can use @code{return}
4013
(@pxref{Returning, ,Returning from a Function}) to go back to the
4014
calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
4015
Different Address}) to go to an arbitrary location in your program.
4016
 
4017
A typical technique for using stepping is to set a breakpoint
4018
(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
4019
beginning of the function or the section of your program where a problem
4020
is believed to lie, run your program until it stops at that breakpoint,
4021
and then step through the suspect area, examining the variables that are
4022
interesting, until you see the problem happen.
4023
 
4024
@table @code
4025
@kindex step
4026
@kindex s @r{(@code{step})}
4027
@item step
4028
Continue running your program until control reaches a different source
4029
line, then stop it and return control to @value{GDBN}.  This command is
4030
abbreviated @code{s}.
4031
 
4032
@quotation
4033
@c "without debugging information" is imprecise; actually "without line
4034
@c numbers in the debugging information".  (gcc -g1 has debugging info but
4035
@c not line numbers).  But it seems complex to try to make that
4036
@c distinction here.
4037
@emph{Warning:} If you use the @code{step} command while control is
4038
within a function that was compiled without debugging information,
4039
execution proceeds until control reaches a function that does have
4040
debugging information.  Likewise, it will not step into a function which
4041
is compiled without debugging information.  To step through functions
4042
without debugging information, use the @code{stepi} command, described
4043
below.
4044
@end quotation
4045
 
4046
The @code{step} command only stops at the first instruction of a source
4047
line.  This prevents the multiple stops that could otherwise occur in
4048
@code{switch} statements, @code{for} loops, etc.  @code{step} continues
4049
to stop if a function that has debugging information is called within
4050
the line.  In other words, @code{step} @emph{steps inside} any functions
4051
called within the line.
4052
 
4053
Also, the @code{step} command only enters a function if there is line
4054
number information for the function.  Otherwise it acts like the
4055
@code{next} command.  This avoids problems when using @code{cc -gl}
4056
on MIPS machines.  Previously, @code{step} entered subroutines if there
4057
was any debugging information about the routine.
4058
 
4059
@item step @var{count}
4060
Continue running as in @code{step}, but do so @var{count} times.  If a
4061
breakpoint is reached, or a signal not related to stepping occurs before
4062
@var{count} steps, stepping stops right away.
4063
 
4064
@kindex next
4065
@kindex n @r{(@code{next})}
4066
@item next @r{[}@var{count}@r{]}
4067
Continue to the next source line in the current (innermost) stack frame.
4068
This is similar to @code{step}, but function calls that appear within
4069
the line of code are executed without stopping.  Execution stops when
4070
control reaches a different line of code at the original stack level
4071
that was executing when you gave the @code{next} command.  This command
4072
is abbreviated @code{n}.
4073
 
4074
An argument @var{count} is a repeat count, as for @code{step}.
4075
 
4076
 
4077
@c  FIX ME!!  Do we delete this, or is there a way it fits in with
4078
@c  the following paragraph?   ---  Vctoria
4079
@c
4080
@c  @code{next} within a function that lacks debugging information acts like
4081
@c  @code{step}, but any function calls appearing within the code of the
4082
@c  function are executed without stopping.
4083
 
4084
The @code{next} command only stops at the first instruction of a
4085
source line.  This prevents multiple stops that could otherwise occur in
4086
@code{switch} statements, @code{for} loops, etc.
4087
 
4088
@kindex set step-mode
4089
@item set step-mode
4090
@cindex functions without line info, and stepping
4091
@cindex stepping into functions with no line info
4092
@itemx set step-mode on
4093
The @code{set step-mode on} command causes the @code{step} command to
4094
stop at the first instruction of a function which contains no debug line
4095
information rather than stepping over it.
4096
 
4097
This is useful in cases where you may be interested in inspecting the
4098
machine instructions of a function which has no symbolic info and do not
4099
want @value{GDBN} to automatically skip over this function.
4100
 
4101
@item set step-mode off
4102
Causes the @code{step} command to step over any functions which contains no
4103
debug information.  This is the default.
4104
 
4105
@item show step-mode
4106
Show whether @value{GDBN} will stop in or step over functions without
4107
source line debug information.
4108
 
4109
@kindex finish
4110
@item finish
4111
Continue running until just after function in the selected stack frame
4112
returns.  Print the returned value (if any).
4113
 
4114
Contrast this with the @code{return} command (@pxref{Returning,
4115
,Returning from a Function}).
4116
 
4117
@kindex until
4118
@kindex u @r{(@code{until})}
4119
@cindex run until specified location
4120
@item until
4121
@itemx u
4122
Continue running until a source line past the current line, in the
4123
current stack frame, is reached.  This command is used to avoid single
4124
stepping through a loop more than once.  It is like the @code{next}
4125
command, except that when @code{until} encounters a jump, it
4126
automatically continues execution until the program counter is greater
4127
than the address of the jump.
4128
 
4129
This means that when you reach the end of a loop after single stepping
4130
though it, @code{until} makes your program continue execution until it
4131
exits the loop.  In contrast, a @code{next} command at the end of a loop
4132
simply steps back to the beginning of the loop, which forces you to step
4133
through the next iteration.
4134
 
4135
@code{until} always stops your program if it attempts to exit the current
4136
stack frame.
4137
 
4138
@code{until} may produce somewhat counterintuitive results if the order
4139
of machine code does not match the order of the source lines.  For
4140
example, in the following excerpt from a debugging session, the @code{f}
4141
(@code{frame}) command shows that execution is stopped at line
4142
@code{206}; yet when we use @code{until}, we get to line @code{195}:
4143
 
4144
@smallexample
4145
(@value{GDBP}) f
4146
#0  main (argc=4, argv=0xf7fffae8) at m4.c:206
4147
206                 expand_input();
4148
(@value{GDBP}) until
4149
195             for ( ; argc > 0; NEXTARG) @{
4150
@end smallexample
4151
 
4152
This happened because, for execution efficiency, the compiler had
4153
generated code for the loop closure test at the end, rather than the
4154
start, of the loop---even though the test in a C @code{for}-loop is
4155
written before the body of the loop.  The @code{until} command appeared
4156
to step back to the beginning of the loop when it advanced to this
4157
expression; however, it has not really gone to an earlier
4158
statement---not in terms of the actual machine code.
4159
 
4160
@code{until} with no argument works by means of single
4161
instruction stepping, and hence is slower than @code{until} with an
4162
argument.
4163
 
4164
@item until @var{location}
4165
@itemx u @var{location}
4166
Continue running your program until either the specified location is
4167
reached, or the current stack frame returns.  @var{location} is any of
4168
the forms described in @ref{Specify Location}.
4169
This form of the command uses temporary breakpoints, and
4170
hence is quicker than @code{until} without an argument.  The specified
4171
location is actually reached only if it is in the current frame.  This
4172
implies that @code{until} can be used to skip over recursive function
4173
invocations.  For instance in the code below, if the current location is
4174
line @code{96}, issuing @code{until 99} will execute the program up to
4175
line @code{99} in the same invocation of factorial, i.e., after the inner
4176
invocations have returned.
4177
 
4178
@smallexample
4179
94      int factorial (int value)
4180
95      @{
4181
96          if (value > 1) @{
4182
97            value *= factorial (value - 1);
4183
98          @}
4184
99          return (value);
4185
100     @}
4186
@end smallexample
4187
 
4188
 
4189
@kindex advance @var{location}
4190
@itemx advance @var{location}
4191
Continue running the program up to the given @var{location}.  An argument is
4192
required, which should be of one of the forms described in
4193
@ref{Specify Location}.
4194
Execution will also stop upon exit from the current stack
4195
frame.  This command is similar to @code{until}, but @code{advance} will
4196
not skip over recursive function calls, and the target location doesn't
4197
have to be in the same frame as the current one.
4198
 
4199
 
4200
@kindex stepi
4201
@kindex si @r{(@code{stepi})}
4202
@item stepi
4203
@itemx stepi @var{arg}
4204
@itemx si
4205
Execute one machine instruction, then stop and return to the debugger.
4206
 
4207
It is often useful to do @samp{display/i $pc} when stepping by machine
4208
instructions.  This makes @value{GDBN} automatically display the next
4209
instruction to be executed, each time your program stops.  @xref{Auto
4210
Display,, Automatic Display}.
4211
 
4212
An argument is a repeat count, as in @code{step}.
4213
 
4214
@need 750
4215
@kindex nexti
4216
@kindex ni @r{(@code{nexti})}
4217
@item nexti
4218
@itemx nexti @var{arg}
4219
@itemx ni
4220
Execute one machine instruction, but if it is a function call,
4221
proceed until the function returns.
4222
 
4223
An argument is a repeat count, as in @code{next}.
4224
@end table
4225
 
4226
@node Signals
4227
@section Signals
4228
@cindex signals
4229
 
4230
A signal is an asynchronous event that can happen in a program.  The
4231
operating system defines the possible kinds of signals, and gives each
4232
kind a name and a number.  For example, in Unix @code{SIGINT} is the
4233
signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
4234
@code{SIGSEGV} is the signal a program gets from referencing a place in
4235
memory far away from all the areas in use; @code{SIGALRM} occurs when
4236
the alarm clock timer goes off (which happens only if your program has
4237
requested an alarm).
4238
 
4239
@cindex fatal signals
4240
Some signals, including @code{SIGALRM}, are a normal part of the
4241
functioning of your program.  Others, such as @code{SIGSEGV}, indicate
4242
errors; these signals are @dfn{fatal} (they kill your program immediately) if the
4243
program has not specified in advance some other way to handle the signal.
4244
@code{SIGINT} does not indicate an error in your program, but it is normally
4245
fatal so it can carry out the purpose of the interrupt: to kill the program.
4246
 
4247
@value{GDBN} has the ability to detect any occurrence of a signal in your
4248
program.  You can tell @value{GDBN} in advance what to do for each kind of
4249
signal.
4250
 
4251
@cindex handling signals
4252
Normally, @value{GDBN} is set up to let the non-erroneous signals like
4253
@code{SIGALRM} be silently passed to your program
4254
(so as not to interfere with their role in the program's functioning)
4255
but to stop your program immediately whenever an error signal happens.
4256
You can change these settings with the @code{handle} command.
4257
 
4258
@table @code
4259
@kindex info signals
4260
@kindex info handle
4261
@item info signals
4262
@itemx info handle
4263
Print a table of all the kinds of signals and how @value{GDBN} has been told to
4264
handle each one.  You can use this to see the signal numbers of all
4265
the defined types of signals.
4266
 
4267
@item info signals @var{sig}
4268
Similar, but print information only about the specified signal number.
4269
 
4270
@code{info handle} is an alias for @code{info signals}.
4271
 
4272
@kindex handle
4273
@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
4274
Change the way @value{GDBN} handles signal @var{signal}.  @var{signal}
4275
can be the number of a signal or its name (with or without the
4276
@samp{SIG} at the beginning); a list of signal numbers of the form
4277
@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
4278
known signals.  Optional arguments @var{keywords}, described below,
4279
say what change to make.
4280
@end table
4281
 
4282
@c @group
4283
The keywords allowed by the @code{handle} command can be abbreviated.
4284
Their full names are:
4285
 
4286
@table @code
4287
@item nostop
4288
@value{GDBN} should not stop your program when this signal happens.  It may
4289
still print a message telling you that the signal has come in.
4290
 
4291
@item stop
4292
@value{GDBN} should stop your program when this signal happens.  This implies
4293
the @code{print} keyword as well.
4294
 
4295
@item print
4296
@value{GDBN} should print a message when this signal happens.
4297
 
4298
@item noprint
4299
@value{GDBN} should not mention the occurrence of the signal at all.  This
4300
implies the @code{nostop} keyword as well.
4301
 
4302
@item pass
4303
@itemx noignore
4304
@value{GDBN} should allow your program to see this signal; your program
4305
can handle the signal, or else it may terminate if the signal is fatal
4306
and not handled.  @code{pass} and @code{noignore} are synonyms.
4307
 
4308
@item nopass
4309
@itemx ignore
4310
@value{GDBN} should not allow your program to see this signal.
4311
@code{nopass} and @code{ignore} are synonyms.
4312
@end table
4313
@c @end group
4314
 
4315
When a signal stops your program, the signal is not visible to the
4316
program until you
4317
continue.  Your program sees the signal then, if @code{pass} is in
4318
effect for the signal in question @emph{at that time}.  In other words,
4319
after @value{GDBN} reports a signal, you can use the @code{handle}
4320
command with @code{pass} or @code{nopass} to control whether your
4321
program sees that signal when you continue.
4322
 
4323
The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4324
non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4325
@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4326
erroneous signals.
4327
 
4328
You can also use the @code{signal} command to prevent your program from
4329
seeing a signal, or cause it to see a signal it normally would not see,
4330
or to give it any signal at any time.  For example, if your program stopped
4331
due to some sort of memory reference error, you might store correct
4332
values into the erroneous variables and continue, hoping to see more
4333
execution; but your program would probably terminate immediately as
4334
a result of the fatal signal once it saw the signal.  To prevent this,
4335
you can continue with @samp{signal 0}.  @xref{Signaling, ,Giving your
4336
Program a Signal}.
4337
 
4338
@node Thread Stops
4339
@section Stopping and Starting Multi-thread Programs
4340
 
4341
When your program has multiple threads (@pxref{Threads,, Debugging
4342
Programs with Multiple Threads}), you can choose whether to set
4343
breakpoints on all threads, or on a particular thread.
4344
 
4345
@table @code
4346
@cindex breakpoints and threads
4347
@cindex thread breakpoints
4348
@kindex break @dots{} thread @var{threadno}
4349
@item break @var{linespec} thread @var{threadno}
4350
@itemx break @var{linespec} thread @var{threadno} if @dots{}
4351
@var{linespec} specifies source lines; there are several ways of
4352
writing them (@pxref{Specify Location}), but the effect is always to
4353
specify some source line.
4354
 
4355
Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4356
to specify that you only want @value{GDBN} to stop the program when a
4357
particular thread reaches this breakpoint.  @var{threadno} is one of the
4358
numeric thread identifiers assigned by @value{GDBN}, shown in the first
4359
column of the @samp{info threads} display.
4360
 
4361
If you do not specify @samp{thread @var{threadno}} when you set a
4362
breakpoint, the breakpoint applies to @emph{all} threads of your
4363
program.
4364
 
4365
You can use the @code{thread} qualifier on conditional breakpoints as
4366
well; in this case, place @samp{thread @var{threadno}} before the
4367
breakpoint condition, like this:
4368
 
4369
@smallexample
4370
(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
4371
@end smallexample
4372
 
4373
@end table
4374
 
4375
@cindex stopped threads
4376
@cindex threads, stopped
4377
Whenever your program stops under @value{GDBN} for any reason,
4378
@emph{all} threads of execution stop, not just the current thread.  This
4379
allows you to examine the overall state of the program, including
4380
switching between threads, without worrying that things may change
4381
underfoot.
4382
 
4383
@cindex thread breakpoints and system calls
4384
@cindex system calls and thread breakpoints
4385
@cindex premature return from system calls
4386
There is an unfortunate side effect.  If one thread stops for a
4387
breakpoint, or for some other reason, and another thread is blocked in a
4388
system call, then the system call may return prematurely.  This is a
4389
consequence of the interaction between multiple threads and the signals
4390
that @value{GDBN} uses to implement breakpoints and other events that
4391
stop execution.
4392
 
4393
To handle this problem, your program should check the return value of
4394
each system call and react appropriately.  This is good programming
4395
style anyways.
4396
 
4397
For example, do not write code like this:
4398
 
4399
@smallexample
4400
  sleep (10);
4401
@end smallexample
4402
 
4403
The call to @code{sleep} will return early if a different thread stops
4404
at a breakpoint or for some other reason.
4405
 
4406
Instead, write this:
4407
 
4408
@smallexample
4409
  int unslept = 10;
4410
  while (unslept > 0)
4411
    unslept = sleep (unslept);
4412
@end smallexample
4413
 
4414
A system call is allowed to return early, so the system is still
4415
conforming to its specification.  But @value{GDBN} does cause your
4416
multi-threaded program to behave differently than it would without
4417
@value{GDBN}.
4418
 
4419
Also, @value{GDBN} uses internal breakpoints in the thread library to
4420
monitor certain events such as thread creation and thread destruction.
4421
When such an event happens, a system call in another thread may return
4422
prematurely, even though your program does not appear to stop.
4423
 
4424
@cindex continuing threads
4425
@cindex threads, continuing
4426
Conversely, whenever you restart the program, @emph{all} threads start
4427
executing.  @emph{This is true even when single-stepping} with commands
4428
like @code{step} or @code{next}.
4429
 
4430
In particular, @value{GDBN} cannot single-step all threads in lockstep.
4431
Since thread scheduling is up to your debugging target's operating
4432
system (not controlled by @value{GDBN}), other threads may
4433
execute more than one statement while the current thread completes a
4434
single step.  Moreover, in general other threads stop in the middle of a
4435
statement, rather than at a clean statement boundary, when the program
4436
stops.
4437
 
4438
You might even find your program stopped in another thread after
4439
continuing or even single-stepping.  This happens whenever some other
4440
thread runs into a breakpoint, a signal, or an exception before the
4441
first thread completes whatever you requested.
4442
 
4443
On some OSes, you can lock the OS scheduler and thus allow only a single
4444
thread to run.
4445
 
4446
@table @code
4447
@item set scheduler-locking @var{mode}
4448
@cindex scheduler locking mode
4449
@cindex lock scheduler
4450
Set the scheduler locking mode.  If it is @code{off}, then there is no
4451
locking and any thread may run at any time.  If @code{on}, then only the
4452
current thread may run when the inferior is resumed.  The @code{step}
4453
mode optimizes for single-stepping.  It stops other threads from
4454
``seizing the prompt'' by preempting the current thread while you are
4455
stepping.  Other threads will only rarely (or never) get a chance to run
4456
when you step.  They are more likely to run when you @samp{next} over a
4457
function call, and they are completely free to run when you use commands
4458
like @samp{continue}, @samp{until}, or @samp{finish}.  However, unless another
4459
thread hits a breakpoint during its timeslice, they will never steal the
4460
@value{GDBN} prompt away from the thread that you are debugging.
4461
 
4462
@item show scheduler-locking
4463
Display the current scheduler locking mode.
4464
@end table
4465
 
4466
 
4467
@node Stack
4468
@chapter Examining the Stack
4469
 
4470
When your program has stopped, the first thing you need to know is where it
4471
stopped and how it got there.
4472
 
4473
@cindex call stack
4474
Each time your program performs a function call, information about the call
4475
is generated.
4476
That information includes the location of the call in your program,
4477
the arguments of the call,
4478
and the local variables of the function being called.
4479
The information is saved in a block of data called a @dfn{stack frame}.
4480
The stack frames are allocated in a region of memory called the @dfn{call
4481
stack}.
4482
 
4483
When your program stops, the @value{GDBN} commands for examining the
4484
stack allow you to see all of this information.
4485
 
4486
@cindex selected frame
4487
One of the stack frames is @dfn{selected} by @value{GDBN} and many
4488
@value{GDBN} commands refer implicitly to the selected frame.  In
4489
particular, whenever you ask @value{GDBN} for the value of a variable in
4490
your program, the value is found in the selected frame.  There are
4491
special @value{GDBN} commands to select whichever frame you are
4492
interested in.  @xref{Selection, ,Selecting a Frame}.
4493
 
4494
When your program stops, @value{GDBN} automatically selects the
4495
currently executing frame and describes it briefly, similar to the
4496
@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
4497
 
4498
@menu
4499
* Frames::                      Stack frames
4500
* Backtrace::                   Backtraces
4501
* Selection::                   Selecting a frame
4502
* Frame Info::                  Information on a frame
4503
 
4504
@end menu
4505
 
4506
@node Frames
4507
@section Stack Frames
4508
 
4509
@cindex frame, definition
4510
@cindex stack frame
4511
The call stack is divided up into contiguous pieces called @dfn{stack
4512
frames}, or @dfn{frames} for short; each frame is the data associated
4513
with one call to one function.  The frame contains the arguments given
4514
to the function, the function's local variables, and the address at
4515
which the function is executing.
4516
 
4517
@cindex initial frame
4518
@cindex outermost frame
4519
@cindex innermost frame
4520
When your program is started, the stack has only one frame, that of the
4521
function @code{main}.  This is called the @dfn{initial} frame or the
4522
@dfn{outermost} frame.  Each time a function is called, a new frame is
4523
made.  Each time a function returns, the frame for that function invocation
4524
is eliminated.  If a function is recursive, there can be many frames for
4525
the same function.  The frame for the function in which execution is
4526
actually occurring is called the @dfn{innermost} frame.  This is the most
4527
recently created of all the stack frames that still exist.
4528
 
4529
@cindex frame pointer
4530
Inside your program, stack frames are identified by their addresses.  A
4531
stack frame consists of many bytes, each of which has its own address; each
4532
kind of computer has a convention for choosing one byte whose
4533
address serves as the address of the frame.  Usually this address is kept
4534
in a register called the @dfn{frame pointer register}
4535
(@pxref{Registers, $fp}) while execution is going on in that frame.
4536
 
4537
@cindex frame number
4538
@value{GDBN} assigns numbers to all existing stack frames, starting with
4539
zero for the innermost frame, one for the frame that called it,
4540
and so on upward.  These numbers do not really exist in your program;
4541
they are assigned by @value{GDBN} to give you a way of designating stack
4542
frames in @value{GDBN} commands.
4543
 
4544
@c The -fomit-frame-pointer below perennially causes hbox overflow
4545
@c underflow problems.
4546
@cindex frameless execution
4547
Some compilers provide a way to compile functions so that they operate
4548
without stack frames.  (For example, the @value{NGCC} option
4549
@smallexample
4550
@samp{-fomit-frame-pointer}
4551
@end smallexample
4552
generates functions without a frame.)
4553
This is occasionally done with heavily used library functions to save
4554
the frame setup time.  @value{GDBN} has limited facilities for dealing
4555
with these function invocations.  If the innermost function invocation
4556
has no stack frame, @value{GDBN} nevertheless regards it as though
4557
it had a separate frame, which is numbered zero as usual, allowing
4558
correct tracing of the function call chain.  However, @value{GDBN} has
4559
no provision for frameless functions elsewhere in the stack.
4560
 
4561
@table @code
4562
@kindex frame@r{, command}
4563
@cindex current stack frame
4564
@item frame @var{args}
4565
The @code{frame} command allows you to move from one stack frame to another,
4566
and to print the stack frame you select.  @var{args} may be either the
4567
address of the frame or the stack frame number.  Without an argument,
4568
@code{frame} prints the current stack frame.
4569
 
4570
@kindex select-frame
4571
@cindex selecting frame silently
4572
@item select-frame
4573
The @code{select-frame} command allows you to move from one stack frame
4574
to another without printing the frame.  This is the silent version of
4575
@code{frame}.
4576
@end table
4577
 
4578
@node Backtrace
4579
@section Backtraces
4580
 
4581
@cindex traceback
4582
@cindex call stack traces
4583
A backtrace is a summary of how your program got where it is.  It shows one
4584
line per frame, for many frames, starting with the currently executing
4585
frame (frame zero), followed by its caller (frame one), and on up the
4586
stack.
4587
 
4588
@table @code
4589
@kindex backtrace
4590
@kindex bt @r{(@code{backtrace})}
4591
@item backtrace
4592
@itemx bt
4593
Print a backtrace of the entire stack: one line per frame for all
4594
frames in the stack.
4595
 
4596
You can stop the backtrace at any time by typing the system interrupt
4597
character, normally @kbd{Ctrl-c}.
4598
 
4599
@item backtrace @var{n}
4600
@itemx bt @var{n}
4601
Similar, but print only the innermost @var{n} frames.
4602
 
4603
@item backtrace -@var{n}
4604
@itemx bt -@var{n}
4605
Similar, but print only the outermost @var{n} frames.
4606
 
4607
@item backtrace full
4608
@itemx bt full
4609
@itemx bt full @var{n}
4610
@itemx bt full -@var{n}
4611
Print the values of the local variables also.  @var{n} specifies the
4612
number of frames to print, as described above.
4613
@end table
4614
 
4615
@kindex where
4616
@kindex info stack
4617
The names @code{where} and @code{info stack} (abbreviated @code{info s})
4618
are additional aliases for @code{backtrace}.
4619
 
4620
@cindex multiple threads, backtrace
4621
In a multi-threaded program, @value{GDBN} by default shows the
4622
backtrace only for the current thread.  To display the backtrace for
4623
several or all of the threads, use the command @code{thread apply}
4624
(@pxref{Threads, thread apply}).  For example, if you type @kbd{thread
4625
apply all backtrace}, @value{GDBN} will display the backtrace for all
4626
the threads; this is handy when you debug a core dump of a
4627
multi-threaded program.
4628
 
4629
Each line in the backtrace shows the frame number and the function name.
4630
The program counter value is also shown---unless you use @code{set
4631
print address off}.  The backtrace also shows the source file name and
4632
line number, as well as the arguments to the function.  The program
4633
counter value is omitted if it is at the beginning of the code for that
4634
line number.
4635
 
4636
Here is an example of a backtrace.  It was made with the command
4637
@samp{bt 3}, so it shows the innermost three frames.
4638
 
4639
@smallexample
4640
@group
4641
#0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4642
    at builtin.c:993
4643
#1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4644
#2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4645
    at macro.c:71
4646
(More stack frames follow...)
4647
@end group
4648
@end smallexample
4649
 
4650
@noindent
4651
The display for frame zero does not begin with a program counter
4652
value, indicating that your program has stopped at the beginning of the
4653
code for line @code{993} of @code{builtin.c}.
4654
 
4655
@cindex value optimized out, in backtrace
4656
@cindex function call arguments, optimized out
4657
If your program was compiled with optimizations, some compilers will
4658
optimize away arguments passed to functions if those arguments are
4659
never used after the call.  Such optimizations generate code that
4660
passes arguments through registers, but doesn't store those arguments
4661
in the stack frame.  @value{GDBN} has no way of displaying such
4662
arguments in stack frames other than the innermost one.  Here's what
4663
such a backtrace might look like:
4664
 
4665
@smallexample
4666
@group
4667
#0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4668
    at builtin.c:993
4669
#1  0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4670
#2  0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4671
    at macro.c:71
4672
(More stack frames follow...)
4673
@end group
4674
@end smallexample
4675
 
4676
@noindent
4677
The values of arguments that were not saved in their stack frames are
4678
shown as @samp{<value optimized out>}.
4679
 
4680
If you need to display the values of such optimized-out arguments,
4681
either deduce that from other variables whose values depend on the one
4682
you are interested in, or recompile without optimizations.
4683
 
4684
@cindex backtrace beyond @code{main} function
4685
@cindex program entry point
4686
@cindex startup code, and backtrace
4687
Most programs have a standard user entry point---a place where system
4688
libraries and startup code transition into user code.  For C this is
4689
@code{main}@footnote{
4690
Note that embedded programs (the so-called ``free-standing''
4691
environment) are not required to have a @code{main} function as the
4692
entry point.  They could even have multiple entry points.}.
4693
When @value{GDBN} finds the entry function in a backtrace
4694
it will terminate the backtrace, to avoid tracing into highly
4695
system-specific (and generally uninteresting) code.
4696
 
4697
If you need to examine the startup code, or limit the number of levels
4698
in a backtrace, you can change this behavior:
4699
 
4700
@table @code
4701
@item set backtrace past-main
4702
@itemx set backtrace past-main on
4703
@kindex set backtrace
4704
Backtraces will continue past the user entry point.
4705
 
4706
@item set backtrace past-main off
4707
Backtraces will stop when they encounter the user entry point.  This is the
4708
default.
4709
 
4710
@item show backtrace past-main
4711
@kindex show backtrace
4712
Display the current user entry point backtrace policy.
4713
 
4714
@item set backtrace past-entry
4715
@itemx set backtrace past-entry on
4716
Backtraces will continue past the internal entry point of an application.
4717
This entry point is encoded by the linker when the application is built,
4718
and is likely before the user entry point @code{main} (or equivalent) is called.
4719
 
4720
@item set backtrace past-entry off
4721
Backtraces will stop when they encounter the internal entry point of an
4722
application.  This is the default.
4723
 
4724
@item show backtrace past-entry
4725
Display the current internal entry point backtrace policy.
4726
 
4727
@item set backtrace limit @var{n}
4728
@itemx set backtrace limit 0
4729
@cindex backtrace limit
4730
Limit the backtrace to @var{n} levels.  A value of zero means
4731
unlimited.
4732
 
4733
@item show backtrace limit
4734
Display the current limit on backtrace levels.
4735
@end table
4736
 
4737
@node Selection
4738
@section Selecting a Frame
4739
 
4740
Most commands for examining the stack and other data in your program work on
4741
whichever stack frame is selected at the moment.  Here are the commands for
4742
selecting a stack frame; all of them finish by printing a brief description
4743
of the stack frame just selected.
4744
 
4745
@table @code
4746
@kindex frame@r{, selecting}
4747
@kindex f @r{(@code{frame})}
4748
@item frame @var{n}
4749
@itemx f @var{n}
4750
Select frame number @var{n}.  Recall that frame zero is the innermost
4751
(currently executing) frame, frame one is the frame that called the
4752
innermost one, and so on.  The highest-numbered frame is the one for
4753
@code{main}.
4754
 
4755
@item frame @var{addr}
4756
@itemx f @var{addr}
4757
Select the frame at address @var{addr}.  This is useful mainly if the
4758
chaining of stack frames has been damaged by a bug, making it
4759
impossible for @value{GDBN} to assign numbers properly to all frames.  In
4760
addition, this can be useful when your program has multiple stacks and
4761
switches between them.
4762
 
4763
On the SPARC architecture, @code{frame} needs two addresses to
4764
select an arbitrary frame: a frame pointer and a stack pointer.
4765
 
4766
On the MIPS and Alpha architecture, it needs two addresses: a stack
4767
pointer and a program counter.
4768
 
4769
On the 29k architecture, it needs three addresses: a register stack
4770
pointer, a program counter, and a memory stack pointer.
4771
 
4772
@kindex up
4773
@item up @var{n}
4774
Move @var{n} frames up the stack.  For positive numbers @var{n}, this
4775
advances toward the outermost frame, to higher frame numbers, to frames
4776
that have existed longer.  @var{n} defaults to one.
4777
 
4778
@kindex down
4779
@kindex do @r{(@code{down})}
4780
@item down @var{n}
4781
Move @var{n} frames down the stack.  For positive numbers @var{n}, this
4782
advances toward the innermost frame, to lower frame numbers, to frames
4783
that were created more recently.  @var{n} defaults to one.  You may
4784
abbreviate @code{down} as @code{do}.
4785
@end table
4786
 
4787
All of these commands end by printing two lines of output describing the
4788
frame.  The first line shows the frame number, the function name, the
4789
arguments, and the source file and line number of execution in that
4790
frame.  The second line shows the text of that source line.
4791
 
4792
@need 1000
4793
For example:
4794
 
4795
@smallexample
4796
@group
4797
(@value{GDBP}) up
4798
#1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4799
    at env.c:10
4800
10              read_input_file (argv[i]);
4801
@end group
4802
@end smallexample
4803
 
4804
After such a printout, the @code{list} command with no arguments
4805
prints ten lines centered on the point of execution in the frame.
4806
You can also edit the program at the point of execution with your favorite
4807
editing program by typing @code{edit}.
4808
@xref{List, ,Printing Source Lines},
4809
for details.
4810
 
4811
@table @code
4812
@kindex down-silently
4813
@kindex up-silently
4814
@item up-silently @var{n}
4815
@itemx down-silently @var{n}
4816
These two commands are variants of @code{up} and @code{down},
4817
respectively; they differ in that they do their work silently, without
4818
causing display of the new frame.  They are intended primarily for use
4819
in @value{GDBN} command scripts, where the output might be unnecessary and
4820
distracting.
4821
@end table
4822
 
4823
@node Frame Info
4824
@section Information About a Frame
4825
 
4826
There are several other commands to print information about the selected
4827
stack frame.
4828
 
4829
@table @code
4830
@item frame
4831
@itemx f
4832
When used without any argument, this command does not change which
4833
frame is selected, but prints a brief description of the currently
4834
selected stack frame.  It can be abbreviated @code{f}.  With an
4835
argument, this command is used to select a stack frame.
4836
@xref{Selection, ,Selecting a Frame}.
4837
 
4838
@kindex info frame
4839
@kindex info f @r{(@code{info frame})}
4840
@item info frame
4841
@itemx info f
4842
This command prints a verbose description of the selected stack frame,
4843
including:
4844
 
4845
@itemize @bullet
4846
@item
4847
the address of the frame
4848
@item
4849
the address of the next frame down (called by this frame)
4850
@item
4851
the address of the next frame up (caller of this frame)
4852
@item
4853
the language in which the source code corresponding to this frame is written
4854
@item
4855
the address of the frame's arguments
4856
@item
4857
the address of the frame's local variables
4858
@item
4859
the program counter saved in it (the address of execution in the caller frame)
4860
@item
4861
which registers were saved in the frame
4862
@end itemize
4863
 
4864
@noindent The verbose description is useful when
4865
something has gone wrong that has made the stack format fail to fit
4866
the usual conventions.
4867
 
4868
@item info frame @var{addr}
4869
@itemx info f @var{addr}
4870
Print a verbose description of the frame at address @var{addr}, without
4871
selecting that frame.  The selected frame remains unchanged by this
4872
command.  This requires the same kind of address (more than one for some
4873
architectures) that you specify in the @code{frame} command.
4874
@xref{Selection, ,Selecting a Frame}.
4875
 
4876
@kindex info args
4877
@item info args
4878
Print the arguments of the selected frame, each on a separate line.
4879
 
4880
@item info locals
4881
@kindex info locals
4882
Print the local variables of the selected frame, each on a separate
4883
line.  These are all variables (declared either static or automatic)
4884
accessible at the point of execution of the selected frame.
4885
 
4886
@kindex info catch
4887
@cindex catch exceptions, list active handlers
4888
@cindex exception handlers, how to list
4889
@item info catch
4890
Print a list of all the exception handlers that are active in the
4891
current stack frame at the current point of execution.  To see other
4892
exception handlers, visit the associated frame (using the @code{up},
4893
@code{down}, or @code{frame} commands); then type @code{info catch}.
4894
@xref{Set Catchpoints, , Setting Catchpoints}.
4895
 
4896
@end table
4897
 
4898
 
4899
@node Source
4900
@chapter Examining Source Files
4901
 
4902
@value{GDBN} can print parts of your program's source, since the debugging
4903
information recorded in the program tells @value{GDBN} what source files were
4904
used to build it.  When your program stops, @value{GDBN} spontaneously prints
4905
the line where it stopped.  Likewise, when you select a stack frame
4906
(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
4907
execution in that frame has stopped.  You can print other portions of
4908
source files by explicit command.
4909
 
4910
If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
4911
prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
4912
@value{GDBN} under @sc{gnu} Emacs}.
4913
 
4914
@menu
4915
* List::                        Printing source lines
4916
* Specify Location::            How to specify code locations
4917
* Edit::                        Editing source files
4918
* Search::                      Searching source files
4919
* Source Path::                 Specifying source directories
4920
* Machine Code::                Source and machine code
4921
@end menu
4922
 
4923
@node List
4924
@section Printing Source Lines
4925
 
4926
@kindex list
4927
@kindex l @r{(@code{list})}
4928
To print lines from a source file, use the @code{list} command
4929
(abbreviated @code{l}).  By default, ten lines are printed.
4930
There are several ways to specify what part of the file you want to
4931
print; see @ref{Specify Location}, for the full list.
4932
 
4933
Here are the forms of the @code{list} command most commonly used:
4934
 
4935
@table @code
4936
@item list @var{linenum}
4937
Print lines centered around line number @var{linenum} in the
4938
current source file.
4939
 
4940
@item list @var{function}
4941
Print lines centered around the beginning of function
4942
@var{function}.
4943
 
4944
@item list
4945
Print more lines.  If the last lines printed were printed with a
4946
@code{list} command, this prints lines following the last lines
4947
printed; however, if the last line printed was a solitary line printed
4948
as part of displaying a stack frame (@pxref{Stack, ,Examining the
4949
Stack}), this prints lines centered around that line.
4950
 
4951
@item list -
4952
Print lines just before the lines last printed.
4953
@end table
4954
 
4955
@cindex @code{list}, how many lines to display
4956
By default, @value{GDBN} prints ten source lines with any of these forms of
4957
the @code{list} command.  You can change this using @code{set listsize}:
4958
 
4959
@table @code
4960
@kindex set listsize
4961
@item set listsize @var{count}
4962
Make the @code{list} command display @var{count} source lines (unless
4963
the @code{list} argument explicitly specifies some other number).
4964
 
4965
@kindex show listsize
4966
@item show listsize
4967
Display the number of lines that @code{list} prints.
4968
@end table
4969
 
4970
Repeating a @code{list} command with @key{RET} discards the argument,
4971
so it is equivalent to typing just @code{list}.  This is more useful
4972
than listing the same lines again.  An exception is made for an
4973
argument of @samp{-}; that argument is preserved in repetition so that
4974
each repetition moves up in the source file.
4975
 
4976
In general, the @code{list} command expects you to supply zero, one or two
4977
@dfn{linespecs}.  Linespecs specify source lines; there are several ways
4978
of writing them (@pxref{Specify Location}), but the effect is always
4979
to specify some source line.
4980
 
4981
Here is a complete description of the possible arguments for @code{list}:
4982
 
4983
@table @code
4984
@item list @var{linespec}
4985
Print lines centered around the line specified by @var{linespec}.
4986
 
4987
@item list @var{first},@var{last}
4988
Print lines from @var{first} to @var{last}.  Both arguments are
4989
linespecs.  When a @code{list} command has two linespecs, and the
4990
source file of the second linespec is omitted, this refers to
4991
the same source file as the first linespec.
4992
 
4993
@item list ,@var{last}
4994
Print lines ending with @var{last}.
4995
 
4996
@item list @var{first},
4997
Print lines starting with @var{first}.
4998
 
4999
@item list +
5000
Print lines just after the lines last printed.
5001
 
5002
@item list -
5003
Print lines just before the lines last printed.
5004
 
5005
@item list
5006
As described in the preceding table.
5007
@end table
5008
 
5009
@node Specify Location
5010
@section Specifying a Location
5011
@cindex specifying location
5012
@cindex linespec
5013
 
5014
Several @value{GDBN} commands accept arguments that specify a location
5015
of your program's code.  Since @value{GDBN} is a source-level
5016
debugger, a location usually specifies some line in the source code;
5017
for that reason, locations are also known as @dfn{linespecs}.
5018
 
5019
Here are all the different ways of specifying a code location that
5020
@value{GDBN} understands:
5021
 
5022
@table @code
5023
@item @var{linenum}
5024
Specifies the line number @var{linenum} of the current source file.
5025
 
5026
@item -@var{offset}
5027
@itemx +@var{offset}
5028
Specifies the line @var{offset} lines before or after the @dfn{current
5029
line}.  For the @code{list} command, the current line is the last one
5030
printed; for the breakpoint commands, this is the line at which
5031
execution stopped in the currently selected @dfn{stack frame}
5032
(@pxref{Frames, ,Frames}, for a description of stack frames.)  When
5033
used as the second of the two linespecs in a @code{list} command,
5034
this specifies the line @var{offset} lines up or down from the first
5035
linespec.
5036
 
5037
@item @var{filename}:@var{linenum}
5038
Specifies the line @var{linenum} in the source file @var{filename}.
5039
 
5040
@item @var{function}
5041
Specifies the line that begins the body of the function @var{function}.
5042
For example, in C, this is the line with the open brace.
5043
 
5044
@item @var{filename}:@var{function}
5045
Specifies the line that begins the body of the function @var{function}
5046
in the file @var{filename}.  You only need the file name with a
5047
function name to avoid ambiguity when there are identically named
5048
functions in different source files.
5049
 
5050
@item *@var{address}
5051
Specifies the program address @var{address}.  For line-oriented
5052
commands, such as @code{list} and @code{edit}, this specifies a source
5053
line that contains @var{address}.  For @code{break} and other
5054
breakpoint oriented commands, this can be used to set breakpoints in
5055
parts of your program which do not have debugging information or
5056
source files.
5057
 
5058
Here @var{address} may be any expression valid in the current working
5059
language (@pxref{Languages, working language}) that specifies a code
5060
address.  In addition, as a convenience, @value{GDBN} extends the
5061
semantics of expressions used in locations to cover the situations
5062
that frequently happen during debugging.  Here are the various forms
5063
of @var{address}:
5064
 
5065
@table @code
5066
@item @var{expression}
5067
Any expression valid in the current working language.
5068
 
5069
@item @var{funcaddr}
5070
An address of a function or procedure derived from its name.  In C,
5071
C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
5072
simply the function's name @var{function} (and actually a special case
5073
of a valid expression).  In Pascal and Modula-2, this is
5074
@code{&@var{function}}.  In Ada, this is @code{@var{function}'Address}
5075
(although the Pascal form also works).
5076
 
5077
This form specifies the address of the function's first instruction,
5078
before the stack frame and arguments have been set up.
5079
 
5080
@item '@var{filename}'::@var{funcaddr}
5081
Like @var{funcaddr} above, but also specifies the name of the source
5082
file explicitly.  This is useful if the name of the function does not
5083
specify the function unambiguously, e.g., if there are several
5084
functions with identical names in different source files.
5085
@end table
5086
 
5087
@end table
5088
 
5089
 
5090
@node Edit
5091
@section Editing Source Files
5092
@cindex editing source files
5093
 
5094
@kindex edit
5095
@kindex e @r{(@code{edit})}
5096
To edit the lines in a source file, use the @code{edit} command.
5097
The editing program of your choice
5098
is invoked with the current line set to
5099
the active line in the program.
5100
Alternatively, there are several ways to specify what part of the file you
5101
want to print if you want to see other parts of the program:
5102
 
5103
@table @code
5104
@item edit @var{location}
5105
Edit the source file specified by @code{location}.  Editing starts at
5106
that @var{location}, e.g., at the specified source line of the
5107
specified file.  @xref{Specify Location}, for all the possible forms
5108
of the @var{location} argument; here are the forms of the @code{edit}
5109
command most commonly used:
5110
 
5111
@table @code
5112
@item edit @var{number}
5113
Edit the current source file with @var{number} as the active line number.
5114
 
5115
@item edit @var{function}
5116
Edit the file containing @var{function} at the beginning of its definition.
5117
@end table
5118
 
5119
@end table
5120
 
5121
@subsection Choosing your Editor
5122
You can customize @value{GDBN} to use any editor you want
5123
@footnote{
5124
The only restriction is that your editor (say @code{ex}), recognizes the
5125
following command-line syntax:
5126
@smallexample
5127
ex +@var{number} file
5128
@end smallexample
5129
The optional numeric value +@var{number} specifies the number of the line in
5130
the file where to start editing.}.
5131
By default, it is @file{@value{EDITOR}}, but you can change this
5132
by setting the environment variable @code{EDITOR} before using
5133
@value{GDBN}.  For example, to configure @value{GDBN} to use the
5134
@code{vi} editor, you could use these commands with the @code{sh} shell:
5135
@smallexample
5136
EDITOR=/usr/bin/vi
5137
export EDITOR
5138
gdb @dots{}
5139
@end smallexample
5140
or in the @code{csh} shell,
5141
@smallexample
5142
setenv EDITOR /usr/bin/vi
5143
gdb @dots{}
5144
@end smallexample
5145
 
5146
@node Search
5147
@section Searching Source Files
5148
@cindex searching source files
5149
 
5150
There are two commands for searching through the current source file for a
5151
regular expression.
5152
 
5153
@table @code
5154
@kindex search
5155
@kindex forward-search
5156
@item forward-search @var{regexp}
5157
@itemx search @var{regexp}
5158
The command @samp{forward-search @var{regexp}} checks each line,
5159
starting with the one following the last line listed, for a match for
5160
@var{regexp}.  It lists the line that is found.  You can use the
5161
synonym @samp{search @var{regexp}} or abbreviate the command name as
5162
@code{fo}.
5163
 
5164
@kindex reverse-search
5165
@item reverse-search @var{regexp}
5166
The command @samp{reverse-search @var{regexp}} checks each line, starting
5167
with the one before the last line listed and going backward, for a match
5168
for @var{regexp}.  It lists the line that is found.  You can abbreviate
5169
this command as @code{rev}.
5170
@end table
5171
 
5172
@node Source Path
5173
@section Specifying Source Directories
5174
 
5175
@cindex source path
5176
@cindex directories for source files
5177
Executable programs sometimes do not record the directories of the source
5178
files from which they were compiled, just the names.  Even when they do,
5179
the directories could be moved between the compilation and your debugging
5180
session.  @value{GDBN} has a list of directories to search for source files;
5181
this is called the @dfn{source path}.  Each time @value{GDBN} wants a source file,
5182
it tries all the directories in the list, in the order they are present
5183
in the list, until it finds a file with the desired name.
5184
 
5185
For example, suppose an executable references the file
5186
@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
5187
@file{/mnt/cross}.  The file is first looked up literally; if this
5188
fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
5189
fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
5190
message is printed.  @value{GDBN} does not look up the parts of the
5191
source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
5192
Likewise, the subdirectories of the source path are not searched: if
5193
the source path is @file{/mnt/cross}, and the binary refers to
5194
@file{foo.c}, @value{GDBN} would not find it under
5195
@file{/mnt/cross/usr/src/foo-1.0/lib}.
5196
 
5197
Plain file names, relative file names with leading directories, file
5198
names containing dots, etc.@: are all treated as described above; for
5199
instance, if the source path is @file{/mnt/cross}, and the source file
5200
is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
5201
@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
5202
that---@file{/mnt/cross/foo.c}.
5203
 
5204
Note that the executable search path is @emph{not} used to locate the
5205
source files.
5206
 
5207
Whenever you reset or rearrange the source path, @value{GDBN} clears out
5208
any information it has cached about where source files are found and where
5209
each line is in the file.
5210
 
5211
@kindex directory
5212
@kindex dir
5213
When you start @value{GDBN}, its source path includes only @samp{cdir}
5214
and @samp{cwd}, in that order.
5215
To add other directories, use the @code{directory} command.
5216
 
5217
The search path is used to find both program source files and @value{GDBN}
5218
script files (read using the @samp{-command} option and @samp{source} command).
5219
 
5220
In addition to the source path, @value{GDBN} provides a set of commands
5221
that manage a list of source path substitution rules.  A @dfn{substitution
5222
rule} specifies how to rewrite source directories stored in the program's
5223
debug information in case the sources were moved to a different
5224
directory between compilation and debugging.  A rule is made of
5225
two strings, the first specifying what needs to be rewritten in
5226
the path, and the second specifying how it should be rewritten.
5227
In @ref{set substitute-path}, we name these two parts @var{from} and
5228
@var{to} respectively.  @value{GDBN} does a simple string replacement
5229
of @var{from} with @var{to} at the start of the directory part of the
5230
source file name, and uses that result instead of the original file
5231
name to look up the sources.
5232
 
5233
Using the previous example, suppose the @file{foo-1.0} tree has been
5234
moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
5235
@value{GDBN} to replace @file{/usr/src} in all source path names with
5236
@file{/mnt/cross}.  The first lookup will then be
5237
@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
5238
of @file{/usr/src/foo-1.0/lib/foo.c}.  To define a source path
5239
substitution rule, use the @code{set substitute-path} command
5240
(@pxref{set substitute-path}).
5241
 
5242
To avoid unexpected substitution results, a rule is applied only if the
5243
@var{from} part of the directory name ends at a directory separator.
5244
For instance, a rule substituting  @file{/usr/source} into
5245
@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
5246
not to @file{/usr/sourceware/foo-2.0}.  And because the substitution
5247
is applied only at the beginning of the directory name, this rule will
5248
not be applied to @file{/root/usr/source/baz.c} either.
5249
 
5250
In many cases, you can achieve the same result using the @code{directory}
5251
command.  However, @code{set substitute-path} can be more efficient in
5252
the case where the sources are organized in a complex tree with multiple
5253
subdirectories.  With the @code{directory} command, you need to add each
5254
subdirectory of your project.  If you moved the entire tree while
5255
preserving its internal organization, then @code{set substitute-path}
5256
allows you to direct the debugger to all the sources with one single
5257
command.
5258
 
5259
@code{set substitute-path} is also more than just a shortcut command.
5260
The source path is only used if the file at the original location no
5261
longer exists.  On the other hand, @code{set substitute-path} modifies
5262
the debugger behavior to look at the rewritten location instead.  So, if
5263
for any reason a source file that is not relevant to your executable is
5264
located at the original location, a substitution rule is the only
5265
method available to point @value{GDBN} at the new location.
5266
 
5267
@table @code
5268
@item directory @var{dirname} @dots{}
5269
@item dir @var{dirname} @dots{}
5270
Add directory @var{dirname} to the front of the source path.  Several
5271
directory names may be given to this command, separated by @samp{:}
5272
(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5273
part of absolute file names) or
5274
whitespace.  You may specify a directory that is already in the source
5275
path; this moves it forward, so @value{GDBN} searches it sooner.
5276
 
5277
@kindex cdir
5278
@kindex cwd
5279
@vindex $cdir@r{, convenience variable}
5280
@vindex $cwd@r{, convenience variable}
5281
@cindex compilation directory
5282
@cindex current directory
5283
@cindex working directory
5284
@cindex directory, current
5285
@cindex directory, compilation
5286
You can use the string @samp{$cdir} to refer to the compilation
5287
directory (if one is recorded), and @samp{$cwd} to refer to the current
5288
working directory.  @samp{$cwd} is not the same as @samp{.}---the former
5289
tracks the current working directory as it changes during your @value{GDBN}
5290
session, while the latter is immediately expanded to the current
5291
directory at the time you add an entry to the source path.
5292
 
5293
@item directory
5294
Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems).  This requires confirmation.
5295
 
5296
@c RET-repeat for @code{directory} is explicitly disabled, but since
5297
@c repeating it would be a no-op we do not say that.  (thanks to RMS)
5298
 
5299
@item show directories
5300
@kindex show directories
5301
Print the source path: show which directories it contains.
5302
 
5303
@anchor{set substitute-path}
5304
@item set substitute-path @var{from} @var{to}
5305
@kindex set substitute-path
5306
Define a source path substitution rule, and add it at the end of the
5307
current list of existing substitution rules.  If a rule with the same
5308
@var{from} was already defined, then the old rule is also deleted.
5309
 
5310
For example, if the file @file{/foo/bar/baz.c} was moved to
5311
@file{/mnt/cross/baz.c}, then the command
5312
 
5313
@smallexample
5314
(@value{GDBP}) set substitute-path /usr/src /mnt/cross
5315
@end smallexample
5316
 
5317
@noindent
5318
will tell @value{GDBN} to replace @samp{/usr/src} with
5319
@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
5320
@file{baz.c} even though it was moved.
5321
 
5322
In the case when more than one substitution rule have been defined,
5323
the rules are evaluated one by one in the order where they have been
5324
defined.  The first one matching, if any, is selected to perform
5325
the substitution.
5326
 
5327
For instance, if we had entered the following commands:
5328
 
5329
@smallexample
5330
(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
5331
(@value{GDBP}) set substitute-path /usr/src /mnt/src
5332
@end smallexample
5333
 
5334
@noindent
5335
@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
5336
@file{/mnt/include/defs.h} by using the first rule.  However, it would
5337
use the second rule to rewrite @file{/usr/src/lib/foo.c} into
5338
@file{/mnt/src/lib/foo.c}.
5339
 
5340
 
5341
@item unset substitute-path [path]
5342
@kindex unset substitute-path
5343
If a path is specified, search the current list of substitution rules
5344
for a rule that would rewrite that path.  Delete that rule if found.
5345
A warning is emitted by the debugger if no rule could be found.
5346
 
5347
If no path is specified, then all substitution rules are deleted.
5348
 
5349
@item show substitute-path [path]
5350
@kindex show substitute-path
5351
If a path is specified, then print the source path substitution rule
5352
which would rewrite that path, if any.
5353
 
5354
If no path is specified, then print all existing source path substitution
5355
rules.
5356
 
5357
@end table
5358
 
5359
If your source path is cluttered with directories that are no longer of
5360
interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5361
versions of source.  You can correct the situation as follows:
5362
 
5363
@enumerate
5364
@item
5365
Use @code{directory} with no argument to reset the source path to its default value.
5366
 
5367
@item
5368
Use @code{directory} with suitable arguments to reinstall the
5369
directories you want in the source path.  You can add all the
5370
directories in one command.
5371
@end enumerate
5372
 
5373
@node Machine Code
5374
@section Source and Machine Code
5375
@cindex source line and its code address
5376
 
5377
You can use the command @code{info line} to map source lines to program
5378
addresses (and vice versa), and the command @code{disassemble} to display
5379
a range of addresses as machine instructions.  When run under @sc{gnu} Emacs
5380
mode, the @code{info line} command causes the arrow to point to the
5381
line specified.  Also, @code{info line} prints addresses in symbolic form as
5382
well as hex.
5383
 
5384
@table @code
5385
@kindex info line
5386
@item info line @var{linespec}
5387
Print the starting and ending addresses of the compiled code for
5388
source line @var{linespec}.  You can specify source lines in any of
5389
the ways documented in @ref{Specify Location}.
5390
@end table
5391
 
5392
For example, we can use @code{info line} to discover the location of
5393
the object code for the first line of function
5394
@code{m4_changequote}:
5395
 
5396
@c FIXME: I think this example should also show the addresses in
5397
@c symbolic form, as they usually would be displayed.
5398
@smallexample
5399
(@value{GDBP}) info line m4_changequote
5400
Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5401
@end smallexample
5402
 
5403
@noindent
5404
@cindex code address and its source line
5405
We can also inquire (using @code{*@var{addr}} as the form for
5406
@var{linespec}) what source line covers a particular address:
5407
@smallexample
5408
(@value{GDBP}) info line *0x63ff
5409
Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5410
@end smallexample
5411
 
5412
@cindex @code{$_} and @code{info line}
5413
@cindex @code{x} command, default address
5414
@kindex x@r{(examine), and} info line
5415
After @code{info line}, the default address for the @code{x} command
5416
is changed to the starting address of the line, so that @samp{x/i} is
5417
sufficient to begin examining the machine code (@pxref{Memory,
5418
,Examining Memory}).  Also, this address is saved as the value of the
5419
convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
5420
Variables}).
5421
 
5422
@table @code
5423
@kindex disassemble
5424
@cindex assembly instructions
5425
@cindex instructions, assembly
5426
@cindex machine instructions
5427
@cindex listing machine instructions
5428
@item disassemble
5429
This specialized command dumps a range of memory as machine
5430
instructions.  The default memory range is the function surrounding the
5431
program counter of the selected frame.  A single argument to this
5432
command is a program counter value; @value{GDBN} dumps the function
5433
surrounding this value.  Two arguments specify a range of addresses
5434
(first inclusive, second exclusive) to dump.
5435
@end table
5436
 
5437
The following example shows the disassembly of a range of addresses of
5438
HP PA-RISC 2.0 code:
5439
 
5440
@smallexample
5441
(@value{GDBP}) disas 0x32c4 0x32e4
5442
Dump of assembler code from 0x32c4 to 0x32e4:
5443
0x32c4 <main+204>:      addil 0,dp
5444
0x32c8 <main+208>:      ldw 0x22c(sr0,r1),r26
5445
0x32cc <main+212>:      ldil 0x3000,r31
5446
0x32d0 <main+216>:      ble 0x3f8(sr4,r31)
5447
0x32d4 <main+220>:      ldo 0(r31),rp
5448
0x32d8 <main+224>:      addil -0x800,dp
5449
0x32dc <main+228>:      ldo 0x588(r1),r26
5450
0x32e0 <main+232>:      ldil 0x3000,r31
5451
End of assembler dump.
5452
@end smallexample
5453
 
5454
Some architectures have more than one commonly-used set of instruction
5455
mnemonics or other syntax.
5456
 
5457
For programs that were dynamically linked and use shared libraries,
5458
instructions that call functions or branch to locations in the shared
5459
libraries might show a seemingly bogus location---it's actually a
5460
location of the relocation table.  On some architectures, @value{GDBN}
5461
might be able to resolve these to actual function names.
5462
 
5463
@table @code
5464
@kindex set disassembly-flavor
5465
@cindex Intel disassembly flavor
5466
@cindex AT&T disassembly flavor
5467
@item set disassembly-flavor @var{instruction-set}
5468
Select the instruction set to use when disassembling the
5469
program via the @code{disassemble} or @code{x/i} commands.
5470
 
5471
Currently this command is only defined for the Intel x86 family.  You
5472
can set @var{instruction-set} to either @code{intel} or @code{att}.
5473
The default is @code{att}, the AT&T flavor used by default by Unix
5474
assemblers for x86-based targets.
5475
 
5476
@kindex show disassembly-flavor
5477
@item show disassembly-flavor
5478
Show the current setting of the disassembly flavor.
5479
@end table
5480
 
5481
 
5482
@node Data
5483
@chapter Examining Data
5484
 
5485
@cindex printing data
5486
@cindex examining data
5487
@kindex print
5488
@kindex inspect
5489
@c "inspect" is not quite a synonym if you are using Epoch, which we do not
5490
@c document because it is nonstandard...  Under Epoch it displays in a
5491
@c different window or something like that.
5492
The usual way to examine data in your program is with the @code{print}
5493
command (abbreviated @code{p}), or its synonym @code{inspect}.  It
5494
evaluates and prints the value of an expression of the language your
5495
program is written in (@pxref{Languages, ,Using @value{GDBN} with
5496
Different Languages}).
5497
 
5498
@table @code
5499
@item print @var{expr}
5500
@itemx print /@var{f} @var{expr}
5501
@var{expr} is an expression (in the source language).  By default the
5502
value of @var{expr} is printed in a format appropriate to its data type;
5503
you can choose a different format by specifying @samp{/@var{f}}, where
5504
@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
5505
Formats}.
5506
 
5507
@item print
5508
@itemx print /@var{f}
5509
@cindex reprint the last value
5510
If you omit @var{expr}, @value{GDBN} displays the last value again (from the
5511
@dfn{value history}; @pxref{Value History, ,Value History}).  This allows you to
5512
conveniently inspect the same value in an alternative format.
5513
@end table
5514
 
5515
A more low-level way of examining data is with the @code{x} command.
5516
It examines data in memory at a specified address and prints it in a
5517
specified format.  @xref{Memory, ,Examining Memory}.
5518
 
5519
If you are interested in information about types, or about how the
5520
fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5521
command rather than @code{print}.  @xref{Symbols, ,Examining the Symbol
5522
Table}.
5523
 
5524
@menu
5525
* Expressions::                 Expressions
5526
* Variables::                   Program variables
5527
* Arrays::                      Artificial arrays
5528
* Output Formats::              Output formats
5529
* Memory::                      Examining memory
5530
* Auto Display::                Automatic display
5531
* Print Settings::              Print settings
5532
* Value History::               Value history
5533
* Convenience Vars::            Convenience variables
5534
* Registers::                   Registers
5535
* Floating Point Hardware::     Floating point hardware
5536
* Vector Unit::                 Vector Unit
5537
* OS Information::              Auxiliary data provided by operating system
5538
* Memory Region Attributes::    Memory region attributes
5539
* Dump/Restore Files::          Copy between memory and a file
5540
* Core File Generation::        Cause a program dump its core
5541
* Character Sets::              Debugging programs that use a different
5542
                                character set than GDB does
5543
* Caching Remote Data::         Data caching for remote targets
5544
@end menu
5545
 
5546
@node Expressions
5547
@section Expressions
5548
 
5549
@cindex expressions
5550
@code{print} and many other @value{GDBN} commands accept an expression and
5551
compute its value.  Any kind of constant, variable or operator defined
5552
by the programming language you are using is valid in an expression in
5553
@value{GDBN}.  This includes conditional expressions, function calls,
5554
casts, and string constants.  It also includes preprocessor macros, if
5555
you compiled your program to include this information; see
5556
@ref{Compilation}.
5557
 
5558
@cindex arrays in expressions
5559
@value{GDBN} supports array constants in expressions input by
5560
the user.  The syntax is @{@var{element}, @var{element}@dots{}@}.  For example,
5561
you can use the command @code{print @{1, 2, 3@}} to build up an array in
5562
memory that is @code{malloc}ed in the target program.
5563
 
5564
Because C is so widespread, most of the expressions shown in examples in
5565
this manual are in C.  @xref{Languages, , Using @value{GDBN} with Different
5566
Languages}, for information on how to use expressions in other
5567
languages.
5568
 
5569
In this section, we discuss operators that you can use in @value{GDBN}
5570
expressions regardless of your programming language.
5571
 
5572
@cindex casts, in expressions
5573
Casts are supported in all languages, not just in C, because it is so
5574
useful to cast a number into a pointer in order to examine a structure
5575
at that address in memory.
5576
@c FIXME: casts supported---Mod2 true?
5577
 
5578
@value{GDBN} supports these operators, in addition to those common
5579
to programming languages:
5580
 
5581
@table @code
5582
@item @@
5583
@samp{@@} is a binary operator for treating parts of memory as arrays.
5584
@xref{Arrays, ,Artificial Arrays}, for more information.
5585
 
5586
@item ::
5587
@samp{::} allows you to specify a variable in terms of the file or
5588
function where it is defined.  @xref{Variables, ,Program Variables}.
5589
 
5590
@cindex @{@var{type}@}
5591
@cindex type casting memory
5592
@cindex memory, viewing as typed object
5593
@cindex casts, to view memory
5594
@item @{@var{type}@} @var{addr}
5595
Refers to an object of type @var{type} stored at address @var{addr} in
5596
memory.  @var{addr} may be any expression whose value is an integer or
5597
pointer (but parentheses are required around binary operators, just as in
5598
a cast).  This construct is allowed regardless of what kind of data is
5599
normally supposed to reside at @var{addr}.
5600
@end table
5601
 
5602
@node Variables
5603
@section Program Variables
5604
 
5605
The most common kind of expression to use is the name of a variable
5606
in your program.
5607
 
5608
Variables in expressions are understood in the selected stack frame
5609
(@pxref{Selection, ,Selecting a Frame}); they must be either:
5610
 
5611
@itemize @bullet
5612
@item
5613
global (or file-static)
5614
@end itemize
5615
 
5616
@noindent or
5617
 
5618
@itemize @bullet
5619
@item
5620
visible according to the scope rules of the
5621
programming language from the point of execution in that frame
5622
@end itemize
5623
 
5624
@noindent This means that in the function
5625
 
5626
@smallexample
5627
foo (a)
5628
     int a;
5629
@{
5630
  bar (a);
5631
  @{
5632
    int b = test ();
5633
    bar (b);
5634
  @}
5635
@}
5636
@end smallexample
5637
 
5638
@noindent
5639
you can examine and use the variable @code{a} whenever your program is
5640
executing within the function @code{foo}, but you can only use or
5641
examine the variable @code{b} while your program is executing inside
5642
the block where @code{b} is declared.
5643
 
5644
@cindex variable name conflict
5645
There is an exception: you can refer to a variable or function whose
5646
scope is a single source file even if the current execution point is not
5647
in this file.  But it is possible to have more than one such variable or
5648
function with the same name (in different source files).  If that
5649
happens, referring to that name has unpredictable effects.  If you wish,
5650
you can specify a static variable in a particular function or file,
5651
using the colon-colon (@code{::}) notation:
5652
 
5653
@cindex colon-colon, context for variables/functions
5654
@ifnotinfo
5655
@c info cannot cope with a :: index entry, but why deprive hard copy readers?
5656
@cindex @code{::}, context for variables/functions
5657
@end ifnotinfo
5658
@smallexample
5659
@var{file}::@var{variable}
5660
@var{function}::@var{variable}
5661
@end smallexample
5662
 
5663
@noindent
5664
Here @var{file} or @var{function} is the name of the context for the
5665
static @var{variable}.  In the case of file names, you can use quotes to
5666
make sure @value{GDBN} parses the file name as a single word---for example,
5667
to print a global value of @code{x} defined in @file{f2.c}:
5668
 
5669
@smallexample
5670
(@value{GDBP}) p 'f2.c'::x
5671
@end smallexample
5672
 
5673
@cindex C@t{++} scope resolution
5674
This use of @samp{::} is very rarely in conflict with the very similar
5675
use of the same notation in C@t{++}.  @value{GDBN} also supports use of the C@t{++}
5676
scope resolution operator in @value{GDBN} expressions.
5677
@c FIXME: Um, so what happens in one of those rare cases where it's in
5678
@c conflict??  --mew
5679
 
5680
@cindex wrong values
5681
@cindex variable values, wrong
5682
@cindex function entry/exit, wrong values of variables
5683
@cindex optimized code, wrong values of variables
5684
@quotation
5685
@emph{Warning:} Occasionally, a local variable may appear to have the
5686
wrong value at certain points in a function---just after entry to a new
5687
scope, and just before exit.
5688
@end quotation
5689
You may see this problem when you are stepping by machine instructions.
5690
This is because, on most machines, it takes more than one instruction to
5691
set up a stack frame (including local variable definitions); if you are
5692
stepping by machine instructions, variables may appear to have the wrong
5693
values until the stack frame is completely built.  On exit, it usually
5694
also takes more than one machine instruction to destroy a stack frame;
5695
after you begin stepping through that group of instructions, local
5696
variable definitions may be gone.
5697
 
5698
This may also happen when the compiler does significant optimizations.
5699
To be sure of always seeing accurate values, turn off all optimization
5700
when compiling.
5701
 
5702
@cindex ``No symbol "foo" in current context''
5703
Another possible effect of compiler optimizations is to optimize
5704
unused variables out of existence, or assign variables to registers (as
5705
opposed to memory addresses).  Depending on the support for such cases
5706
offered by the debug info format used by the compiler, @value{GDBN}
5707
might not be able to display values for such local variables.  If that
5708
happens, @value{GDBN} will print a message like this:
5709
 
5710
@smallexample
5711
No symbol "foo" in current context.
5712
@end smallexample
5713
 
5714
To solve such problems, either recompile without optimizations, or use a
5715
different debug info format, if the compiler supports several such
5716
formats.  For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
5717
usually supports the @option{-gstabs+} option.  @option{-gstabs+}
5718
produces debug info in a format that is superior to formats such as
5719
COFF.  You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5720
an effective form for debug info.  @xref{Debugging Options,,Options
5721
for Debugging Your Program or GCC, gcc.info, Using the @sc{gnu}
5722
Compiler Collection (GCC)}.
5723
@xref{C, ,C and C@t{++}}, for more information about debug info formats
5724
that are best suited to C@t{++} programs.
5725
 
5726
If you ask to print an object whose contents are unknown to
5727
@value{GDBN}, e.g., because its data type is not completely specified
5728
by the debug information, @value{GDBN} will say @samp{<incomplete
5729
type>}.  @xref{Symbols, incomplete type}, for more about this.
5730
 
5731
Strings are identified as arrays of @code{char} values without specified
5732
signedness.  Arrays of either @code{signed char} or @code{unsigned char} get
5733
printed as arrays of 1 byte sized integers.  @code{-fsigned-char} or
5734
@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
5735
defines literal string type @code{"char"} as @code{char} without a sign.
5736
For program code
5737
 
5738
@smallexample
5739
char var0[] = "A";
5740
signed char var1[] = "A";
5741
@end smallexample
5742
 
5743
You get during debugging
5744
@smallexample
5745
(gdb) print var0
5746
$1 = "A"
5747
(gdb) print var1
5748
$2 = @{65 'A', 0 '\0'@}
5749
@end smallexample
5750
 
5751
@node Arrays
5752
@section Artificial Arrays
5753
 
5754
@cindex artificial array
5755
@cindex arrays
5756
@kindex @@@r{, referencing memory as an array}
5757
It is often useful to print out several successive objects of the
5758
same type in memory; a section of an array, or an array of
5759
dynamically determined size for which only a pointer exists in the
5760
program.
5761
 
5762
You can do this by referring to a contiguous span of memory as an
5763
@dfn{artificial array}, using the binary operator @samp{@@}.  The left
5764
operand of @samp{@@} should be the first element of the desired array
5765
and be an individual object.  The right operand should be the desired length
5766
of the array.  The result is an array value whose elements are all of
5767
the type of the left argument.  The first element is actually the left
5768
argument; the second element comes from bytes of memory immediately
5769
following those that hold the first element, and so on.  Here is an
5770
example.  If a program says
5771
 
5772
@smallexample
5773
int *array = (int *) malloc (len * sizeof (int));
5774
@end smallexample
5775
 
5776
@noindent
5777
you can print the contents of @code{array} with
5778
 
5779
@smallexample
5780
p *array@@len
5781
@end smallexample
5782
 
5783
The left operand of @samp{@@} must reside in memory.  Array values made
5784
with @samp{@@} in this way behave just like other arrays in terms of
5785
subscripting, and are coerced to pointers when used in expressions.
5786
Artificial arrays most often appear in expressions via the value history
5787
(@pxref{Value History, ,Value History}), after printing one out.
5788
 
5789
Another way to create an artificial array is to use a cast.
5790
This re-interprets a value as if it were an array.
5791
The value need not be in memory:
5792
@smallexample
5793
(@value{GDBP}) p/x (short[2])0x12345678
5794
$1 = @{0x1234, 0x5678@}
5795
@end smallexample
5796
 
5797
As a convenience, if you leave the array length out (as in
5798
@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
5799
the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
5800
@smallexample
5801
(@value{GDBP}) p/x (short[])0x12345678
5802
$2 = @{0x1234, 0x5678@}
5803
@end smallexample
5804
 
5805
Sometimes the artificial array mechanism is not quite enough; in
5806
moderately complex data structures, the elements of interest may not
5807
actually be adjacent---for example, if you are interested in the values
5808
of pointers in an array.  One useful work-around in this situation is
5809
to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5810
Variables}) as a counter in an expression that prints the first
5811
interesting value, and then repeat that expression via @key{RET}.  For
5812
instance, suppose you have an array @code{dtab} of pointers to
5813
structures, and you are interested in the values of a field @code{fv}
5814
in each structure.  Here is an example of what you might type:
5815
 
5816
@smallexample
5817
set $i = 0
5818
p dtab[$i++]->fv
5819
@key{RET}
5820
@key{RET}
5821
@dots{}
5822
@end smallexample
5823
 
5824
@node Output Formats
5825
@section Output Formats
5826
 
5827
@cindex formatted output
5828
@cindex output formats
5829
By default, @value{GDBN} prints a value according to its data type.  Sometimes
5830
this is not what you want.  For example, you might want to print a number
5831
in hex, or a pointer in decimal.  Or you might want to view data in memory
5832
at a certain address as a character string or as an instruction.  To do
5833
these things, specify an @dfn{output format} when you print a value.
5834
 
5835
The simplest use of output formats is to say how to print a value
5836
already computed.  This is done by starting the arguments of the
5837
@code{print} command with a slash and a format letter.  The format
5838
letters supported are:
5839
 
5840
@table @code
5841
@item x
5842
Regard the bits of the value as an integer, and print the integer in
5843
hexadecimal.
5844
 
5845
@item d
5846
Print as integer in signed decimal.
5847
 
5848
@item u
5849
Print as integer in unsigned decimal.
5850
 
5851
@item o
5852
Print as integer in octal.
5853
 
5854
@item t
5855
Print as integer in binary.  The letter @samp{t} stands for ``two''.
5856
@footnote{@samp{b} cannot be used because these format letters are also
5857
used with the @code{x} command, where @samp{b} stands for ``byte'';
5858
see @ref{Memory,,Examining Memory}.}
5859
 
5860
@item a
5861
@cindex unknown address, locating
5862
@cindex locate address
5863
Print as an address, both absolute in hexadecimal and as an offset from
5864
the nearest preceding symbol.  You can use this format used to discover
5865
where (in what function) an unknown address is located:
5866
 
5867
@smallexample
5868
(@value{GDBP}) p/a 0x54320
5869
$3 = 0x54320 <_initialize_vx+396>
5870
@end smallexample
5871
 
5872
@noindent
5873
The command @code{info symbol 0x54320} yields similar results.
5874
@xref{Symbols, info symbol}.
5875
 
5876
@item c
5877
Regard as an integer and print it as a character constant.  This
5878
prints both the numerical value and its character representation.  The
5879
character representation is replaced with the octal escape @samp{\nnn}
5880
for characters outside the 7-bit @sc{ascii} range.
5881
 
5882
Without this format, @value{GDBN} displays @code{char},
5883
@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
5884
constants.  Single-byte members of vectors are displayed as integer
5885
data.
5886
 
5887
@item f
5888
Regard the bits of the value as a floating point number and print
5889
using typical floating point syntax.
5890
 
5891
@item s
5892
@cindex printing strings
5893
@cindex printing byte arrays
5894
Regard as a string, if possible.  With this format, pointers to single-byte
5895
data are displayed as null-terminated strings and arrays of single-byte data
5896
are displayed as fixed-length strings.  Other values are displayed in their
5897
natural types.
5898
 
5899
Without this format, @value{GDBN} displays pointers to and arrays of
5900
@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
5901
strings.  Single-byte members of a vector are displayed as an integer
5902
array.
5903
@end table
5904
 
5905
For example, to print the program counter in hex (@pxref{Registers}), type
5906
 
5907
@smallexample
5908
p/x $pc
5909
@end smallexample
5910
 
5911
@noindent
5912
Note that no space is required before the slash; this is because command
5913
names in @value{GDBN} cannot contain a slash.
5914
 
5915
To reprint the last value in the value history with a different format,
5916
you can use the @code{print} command with just a format and no
5917
expression.  For example, @samp{p/x} reprints the last value in hex.
5918
 
5919
@node Memory
5920
@section Examining Memory
5921
 
5922
You can use the command @code{x} (for ``examine'') to examine memory in
5923
any of several formats, independently of your program's data types.
5924
 
5925
@cindex examining memory
5926
@table @code
5927
@kindex x @r{(examine memory)}
5928
@item x/@var{nfu} @var{addr}
5929
@itemx x @var{addr}
5930
@itemx x
5931
Use the @code{x} command to examine memory.
5932
@end table
5933
 
5934
@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5935
much memory to display and how to format it; @var{addr} is an
5936
expression giving the address where you want to start displaying memory.
5937
If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5938
Several commands set convenient defaults for @var{addr}.
5939
 
5940
@table @r
5941
@item @var{n}, the repeat count
5942
The repeat count is a decimal integer; the default is 1.  It specifies
5943
how much memory (counting by units @var{u}) to display.
5944
@c This really is **decimal**; unaffected by 'set radix' as of GDB
5945
@c 4.1.2.
5946
 
5947
@item @var{f}, the display format
5948
The display format is one of the formats used by @code{print}
5949
(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5950
@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
5951
The default is @samp{x} (hexadecimal) initially.  The default changes
5952
each time you use either @code{x} or @code{print}.
5953
 
5954
@item @var{u}, the unit size
5955
The unit size is any of
5956
 
5957
@table @code
5958
@item b
5959
Bytes.
5960
@item h
5961
Halfwords (two bytes).
5962
@item w
5963
Words (four bytes).  This is the initial default.
5964
@item g
5965
Giant words (eight bytes).
5966
@end table
5967
 
5968
Each time you specify a unit size with @code{x}, that size becomes the
5969
default unit the next time you use @code{x}.  (For the @samp{s} and
5970
@samp{i} formats, the unit size is ignored and is normally not written.)
5971
 
5972
@item @var{addr}, starting display address
5973
@var{addr} is the address where you want @value{GDBN} to begin displaying
5974
memory.  The expression need not have a pointer value (though it may);
5975
it is always interpreted as an integer address of a byte of memory.
5976
@xref{Expressions, ,Expressions}, for more information on expressions.  The default for
5977
@var{addr} is usually just after the last address examined---but several
5978
other commands also set the default address: @code{info breakpoints} (to
5979
the address of the last breakpoint listed), @code{info line} (to the
5980
starting address of a line), and @code{print} (if you use it to display
5981
a value from memory).
5982
@end table
5983
 
5984
For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5985
(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5986
starting at address @code{0x54320}.  @samp{x/4xw $sp} prints the four
5987
words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
5988
@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
5989
 
5990
Since the letters indicating unit sizes are all distinct from the
5991
letters specifying output formats, you do not have to remember whether
5992
unit size or format comes first; either order works.  The output
5993
specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5994
(However, the count @var{n} must come first; @samp{wx4} does not work.)
5995
 
5996
Even though the unit size @var{u} is ignored for the formats @samp{s}
5997
and @samp{i}, you might still want to use a count @var{n}; for example,
5998
@samp{3i} specifies that you want to see three machine instructions,
5999
including any operands.  For convenience, especially when used with
6000
the @code{display} command, the @samp{i} format also prints branch delay
6001
slot instructions, if any, beyond the count specified, which immediately
6002
follow the last instruction that is within the count.  The command
6003
@code{disassemble} gives an alternative way of inspecting machine
6004
instructions; see @ref{Machine Code,,Source and Machine Code}.
6005
 
6006
All the defaults for the arguments to @code{x} are designed to make it
6007
easy to continue scanning memory with minimal specifications each time
6008
you use @code{x}.  For example, after you have inspected three machine
6009
instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
6010
with just @samp{x/7}.  If you use @key{RET} to repeat the @code{x} command,
6011
the repeat count @var{n} is used again; the other arguments default as
6012
for successive uses of @code{x}.
6013
 
6014
@cindex @code{$_}, @code{$__}, and value history
6015
The addresses and contents printed by the @code{x} command are not saved
6016
in the value history because there is often too much of them and they
6017
would get in the way.  Instead, @value{GDBN} makes these values available for
6018
subsequent use in expressions as values of the convenience variables
6019
@code{$_} and @code{$__}.  After an @code{x} command, the last address
6020
examined is available for use in expressions in the convenience variable
6021
@code{$_}.  The contents of that address, as examined, are available in
6022
the convenience variable @code{$__}.
6023
 
6024
If the @code{x} command has a repeat count, the address and contents saved
6025
are from the last memory unit printed; this is not the same as the last
6026
address printed if several units were printed on the last line of output.
6027
 
6028
@cindex remote memory comparison
6029
@cindex verify remote memory image
6030
When you are debugging a program running on a remote target machine
6031
(@pxref{Remote Debugging}), you may wish to verify the program's image in the
6032
remote machine's memory against the executable file you downloaded to
6033
the target.  The @code{compare-sections} command is provided for such
6034
situations.
6035
 
6036
@table @code
6037
@kindex compare-sections
6038
@item compare-sections @r{[}@var{section-name}@r{]}
6039
Compare the data of a loadable section @var{section-name} in the
6040
executable file of the program being debugged with the same section in
6041
the remote machine's memory, and report any mismatches.  With no
6042
arguments, compares all loadable sections.  This command's
6043
availability depends on the target's support for the @code{"qCRC"}
6044
remote request.
6045
@end table
6046
 
6047
@node Auto Display
6048
@section Automatic Display
6049
@cindex automatic display
6050
@cindex display of expressions
6051
 
6052
If you find that you want to print the value of an expression frequently
6053
(to see how it changes), you might want to add it to the @dfn{automatic
6054
display list} so that @value{GDBN} prints its value each time your program stops.
6055
Each expression added to the list is given a number to identify it;
6056
to remove an expression from the list, you specify that number.
6057
The automatic display looks like this:
6058
 
6059
@smallexample
6060
2: foo = 38
6061
3: bar[5] = (struct hack *) 0x3804
6062
@end smallexample
6063
 
6064
@noindent
6065
This display shows item numbers, expressions and their current values.  As with
6066
displays you request manually using @code{x} or @code{print}, you can
6067
specify the output format you prefer; in fact, @code{display} decides
6068
whether to use @code{print} or @code{x} depending your format
6069
specification---it uses @code{x} if you specify either the @samp{i}
6070
or @samp{s} format, or a unit size; otherwise it uses @code{print}.
6071
 
6072
@table @code
6073
@kindex display
6074
@item display @var{expr}
6075
Add the expression @var{expr} to the list of expressions to display
6076
each time your program stops.  @xref{Expressions, ,Expressions}.
6077
 
6078
@code{display} does not repeat if you press @key{RET} again after using it.
6079
 
6080
@item display/@var{fmt} @var{expr}
6081
For @var{fmt} specifying only a display format and not a size or
6082
count, add the expression @var{expr} to the auto-display list but
6083
arrange to display it each time in the specified format @var{fmt}.
6084
@xref{Output Formats,,Output Formats}.
6085
 
6086
@item display/@var{fmt} @var{addr}
6087
For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
6088
number of units, add the expression @var{addr} as a memory address to
6089
be examined each time your program stops.  Examining means in effect
6090
doing @samp{x/@var{fmt} @var{addr}}.  @xref{Memory, ,Examining Memory}.
6091
@end table
6092
 
6093
For example, @samp{display/i $pc} can be helpful, to see the machine
6094
instruction about to be executed each time execution stops (@samp{$pc}
6095
is a common name for the program counter; @pxref{Registers, ,Registers}).
6096
 
6097
@table @code
6098
@kindex delete display
6099
@kindex undisplay
6100
@item undisplay @var{dnums}@dots{}
6101
@itemx delete display @var{dnums}@dots{}
6102
Remove item numbers @var{dnums} from the list of expressions to display.
6103
 
6104
@code{undisplay} does not repeat if you press @key{RET} after using it.
6105
(Otherwise you would just get the error @samp{No display number @dots{}}.)
6106
 
6107
@kindex disable display
6108
@item disable display @var{dnums}@dots{}
6109
Disable the display of item numbers @var{dnums}.  A disabled display
6110
item is not printed automatically, but is not forgotten.  It may be
6111
enabled again later.
6112
 
6113
@kindex enable display
6114
@item enable display @var{dnums}@dots{}
6115
Enable display of item numbers @var{dnums}.  It becomes effective once
6116
again in auto display of its expression, until you specify otherwise.
6117
 
6118
@item display
6119
Display the current values of the expressions on the list, just as is
6120
done when your program stops.
6121
 
6122
@kindex info display
6123
@item info display
6124
Print the list of expressions previously set up to display
6125
automatically, each one with its item number, but without showing the
6126
values.  This includes disabled expressions, which are marked as such.
6127
It also includes expressions which would not be displayed right now
6128
because they refer to automatic variables not currently available.
6129
@end table
6130
 
6131
@cindex display disabled out of scope
6132
If a display expression refers to local variables, then it does not make
6133
sense outside the lexical context for which it was set up.  Such an
6134
expression is disabled when execution enters a context where one of its
6135
variables is not defined.  For example, if you give the command
6136
@code{display last_char} while inside a function with an argument
6137
@code{last_char}, @value{GDBN} displays this argument while your program
6138
continues to stop inside that function.  When it stops elsewhere---where
6139
there is no variable @code{last_char}---the display is disabled
6140
automatically.  The next time your program stops where @code{last_char}
6141
is meaningful, you can enable the display expression once again.
6142
 
6143
@node Print Settings
6144
@section Print Settings
6145
 
6146
@cindex format options
6147
@cindex print settings
6148
@value{GDBN} provides the following ways to control how arrays, structures,
6149
and symbols are printed.
6150
 
6151
@noindent
6152
These settings are useful for debugging programs in any language:
6153
 
6154
@table @code
6155
@kindex set print
6156
@item set print address
6157
@itemx set print address on
6158
@cindex print/don't print memory addresses
6159
@value{GDBN} prints memory addresses showing the location of stack
6160
traces, structure values, pointer values, breakpoints, and so forth,
6161
even when it also displays the contents of those addresses.  The default
6162
is @code{on}.  For example, this is what a stack frame display looks like with
6163
@code{set print address on}:
6164
 
6165
@smallexample
6166
@group
6167
(@value{GDBP}) f
6168
#0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
6169
    at input.c:530
6170
530         if (lquote != def_lquote)
6171
@end group
6172
@end smallexample
6173
 
6174
@item set print address off
6175
Do not print addresses when displaying their contents.  For example,
6176
this is the same stack frame displayed with @code{set print address off}:
6177
 
6178
@smallexample
6179
@group
6180
(@value{GDBP}) set print addr off
6181
(@value{GDBP}) f
6182
#0  set_quotes (lq="<<", rq=">>") at input.c:530
6183
530         if (lquote != def_lquote)
6184
@end group
6185
@end smallexample
6186
 
6187
You can use @samp{set print address off} to eliminate all machine
6188
dependent displays from the @value{GDBN} interface.  For example, with
6189
@code{print address off}, you should get the same text for backtraces on
6190
all machines---whether or not they involve pointer arguments.
6191
 
6192
@kindex show print
6193
@item show print address
6194
Show whether or not addresses are to be printed.
6195
@end table
6196
 
6197
When @value{GDBN} prints a symbolic address, it normally prints the
6198
closest earlier symbol plus an offset.  If that symbol does not uniquely
6199
identify the address (for example, it is a name whose scope is a single
6200
source file), you may need to clarify.  One way to do this is with
6201
@code{info line}, for example @samp{info line *0x4537}.  Alternately,
6202
you can set @value{GDBN} to print the source file and line number when
6203
it prints a symbolic address:
6204
 
6205
@table @code
6206
@item set print symbol-filename on
6207
@cindex source file and line of a symbol
6208
@cindex symbol, source file and line
6209
Tell @value{GDBN} to print the source file name and line number of a
6210
symbol in the symbolic form of an address.
6211
 
6212
@item set print symbol-filename off
6213
Do not print source file name and line number of a symbol.  This is the
6214
default.
6215
 
6216
@item show print symbol-filename
6217
Show whether or not @value{GDBN} will print the source file name and
6218
line number of a symbol in the symbolic form of an address.
6219
@end table
6220
 
6221
Another situation where it is helpful to show symbol filenames and line
6222
numbers is when disassembling code; @value{GDBN} shows you the line
6223
number and source file that corresponds to each instruction.
6224
 
6225
Also, you may wish to see the symbolic form only if the address being
6226
printed is reasonably close to the closest earlier symbol:
6227
 
6228
@table @code
6229
@item set print max-symbolic-offset @var{max-offset}
6230
@cindex maximum value for offset of closest symbol
6231
Tell @value{GDBN} to only display the symbolic form of an address if the
6232
offset between the closest earlier symbol and the address is less than
6233
@var{max-offset}.  The default is 0, which tells @value{GDBN}
6234
to always print the symbolic form of an address if any symbol precedes it.
6235
 
6236
@item show print max-symbolic-offset
6237
Ask how large the maximum offset is that @value{GDBN} prints in a
6238
symbolic address.
6239
@end table
6240
 
6241
@cindex wild pointer, interpreting
6242
@cindex pointer, finding referent
6243
If you have a pointer and you are not sure where it points, try
6244
@samp{set print symbol-filename on}.  Then you can determine the name
6245
and source file location of the variable where it points, using
6246
@samp{p/a @var{pointer}}.  This interprets the address in symbolic form.
6247
For example, here @value{GDBN} shows that a variable @code{ptt} points
6248
at another variable @code{t}, defined in @file{hi2.c}:
6249
 
6250
@smallexample
6251
(@value{GDBP}) set print symbol-filename on
6252
(@value{GDBP}) p/a ptt
6253
$4 = 0xe008 <t in hi2.c>
6254
@end smallexample
6255
 
6256
@quotation
6257
@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
6258
does not show the symbol name and filename of the referent, even with
6259
the appropriate @code{set print} options turned on.
6260
@end quotation
6261
 
6262
Other settings control how different kinds of objects are printed:
6263
 
6264
@table @code
6265
@item set print array
6266
@itemx set print array on
6267
@cindex pretty print arrays
6268
Pretty print arrays.  This format is more convenient to read,
6269
but uses more space.  The default is off.
6270
 
6271
@item set print array off
6272
Return to compressed format for arrays.
6273
 
6274
@item show print array
6275
Show whether compressed or pretty format is selected for displaying
6276
arrays.
6277
 
6278
@cindex print array indexes
6279
@item set print array-indexes
6280
@itemx set print array-indexes on
6281
Print the index of each element when displaying arrays.  May be more
6282
convenient to locate a given element in the array or quickly find the
6283
index of a given element in that printed array.  The default is off.
6284
 
6285
@item set print array-indexes off
6286
Stop printing element indexes when displaying arrays.
6287
 
6288
@item show print array-indexes
6289
Show whether the index of each element is printed when displaying
6290
arrays.
6291
 
6292
@item set print elements @var{number-of-elements}
6293
@cindex number of array elements to print
6294
@cindex limit on number of printed array elements
6295
Set a limit on how many elements of an array @value{GDBN} will print.
6296
If @value{GDBN} is printing a large array, it stops printing after it has
6297
printed the number of elements set by the @code{set print elements} command.
6298
This limit also applies to the display of strings.
6299
When @value{GDBN} starts, this limit is set to 200.
6300
Setting  @var{number-of-elements} to zero means that the printing is unlimited.
6301
 
6302
@item show print elements
6303
Display the number of elements of a large array that @value{GDBN} will print.
6304
If the number is 0, then the printing is unlimited.
6305
 
6306
@item set print frame-arguments @var{value}
6307
@cindex printing frame argument values
6308
@cindex print all frame argument values
6309
@cindex print frame argument values for scalars only
6310
@cindex do not print frame argument values
6311
This command allows to control how the values of arguments are printed
6312
when the debugger prints a frame (@pxref{Frames}).  The possible
6313
values are:
6314
 
6315
@table @code
6316
@item all
6317
The values of all arguments are printed.  This is the default.
6318
 
6319
@item scalars
6320
Print the value of an argument only if it is a scalar.  The value of more
6321
complex arguments such as arrays, structures, unions, etc, is replaced
6322
by @code{@dots{}}.  Here is an example where only scalar arguments are shown:
6323
 
6324
@smallexample
6325
#1  0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
6326
  at frame-args.c:23
6327
@end smallexample
6328
 
6329
@item none
6330
None of the argument values are printed.  Instead, the value of each argument
6331
is replaced by @code{@dots{}}.  In this case, the example above now becomes:
6332
 
6333
@smallexample
6334
#1  0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
6335
  at frame-args.c:23
6336
@end smallexample
6337
@end table
6338
 
6339
By default, all argument values are always printed.  But this command
6340
can be useful in several cases.  For instance, it can be used to reduce
6341
the amount of information printed in each frame, making the backtrace
6342
more readable.  Also, this command can be used to improve performance
6343
when displaying Ada frames, because the computation of large arguments
6344
can sometimes be CPU-intensive, especiallly in large applications.
6345
Setting @code{print frame-arguments} to @code{scalars} or @code{none}
6346
avoids this computation, thus speeding up the display of each Ada frame.
6347
 
6348
@item show print frame-arguments
6349
Show how the value of arguments should be displayed when printing a frame.
6350
 
6351
@item set print repeats
6352
@cindex repeated array elements
6353
Set the threshold for suppressing display of repeated array
6354
elements.  When the number of consecutive identical elements of an
6355
array exceeds the threshold, @value{GDBN} prints the string
6356
@code{"<repeats @var{n} times>"}, where @var{n} is the number of
6357
identical repetitions, instead of displaying the identical elements
6358
themselves.  Setting the threshold to zero will cause all elements to
6359
be individually printed.  The default threshold is 10.
6360
 
6361
@item show print repeats
6362
Display the current threshold for printing repeated identical
6363
elements.
6364
 
6365
@item set print null-stop
6366
@cindex @sc{null} elements in arrays
6367
Cause @value{GDBN} to stop printing the characters of an array when the first
6368
@sc{null} is encountered.  This is useful when large arrays actually
6369
contain only short strings.
6370
The default is off.
6371
 
6372
@item show print null-stop
6373
Show whether @value{GDBN} stops printing an array on the first
6374
@sc{null} character.
6375
 
6376
@item set print pretty on
6377
@cindex print structures in indented form
6378
@cindex indentation in structure display
6379
Cause @value{GDBN} to print structures in an indented format with one member
6380
per line, like this:
6381
 
6382
@smallexample
6383
@group
6384
$1 = @{
6385
  next = 0x0,
6386
  flags = @{
6387
    sweet = 1,
6388
    sour = 1
6389
  @},
6390
  meat = 0x54 "Pork"
6391
@}
6392
@end group
6393
@end smallexample
6394
 
6395
@item set print pretty off
6396
Cause @value{GDBN} to print structures in a compact format, like this:
6397
 
6398
@smallexample
6399
@group
6400
$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
6401
meat = 0x54 "Pork"@}
6402
@end group
6403
@end smallexample
6404
 
6405
@noindent
6406
This is the default format.
6407
 
6408
@item show print pretty
6409
Show which format @value{GDBN} is using to print structures.
6410
 
6411
@item set print sevenbit-strings on
6412
@cindex eight-bit characters in strings
6413
@cindex octal escapes in strings
6414
Print using only seven-bit characters; if this option is set,
6415
@value{GDBN} displays any eight-bit characters (in strings or
6416
character values) using the notation @code{\}@var{nnn}.  This setting is
6417
best if you are working in English (@sc{ascii}) and you use the
6418
high-order bit of characters as a marker or ``meta'' bit.
6419
 
6420
@item set print sevenbit-strings off
6421
Print full eight-bit characters.  This allows the use of more
6422
international character sets, and is the default.
6423
 
6424
@item show print sevenbit-strings
6425
Show whether or not @value{GDBN} is printing only seven-bit characters.
6426
 
6427
@item set print union on
6428
@cindex unions in structures, printing
6429
Tell @value{GDBN} to print unions which are contained in structures
6430
and other unions.  This is the default setting.
6431
 
6432
@item set print union off
6433
Tell @value{GDBN} not to print unions which are contained in
6434
structures and other unions.  @value{GDBN} will print @code{"@{...@}"}
6435
instead.
6436
 
6437
@item show print union
6438
Ask @value{GDBN} whether or not it will print unions which are contained in
6439
structures and other unions.
6440
 
6441
For example, given the declarations
6442
 
6443
@smallexample
6444
typedef enum @{Tree, Bug@} Species;
6445
typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
6446
typedef enum @{Caterpillar, Cocoon, Butterfly@}
6447
              Bug_forms;
6448
 
6449
struct thing @{
6450
  Species it;
6451
  union @{
6452
    Tree_forms tree;
6453
    Bug_forms bug;
6454
  @} form;
6455
@};
6456
 
6457
struct thing foo = @{Tree, @{Acorn@}@};
6458
@end smallexample
6459
 
6460
@noindent
6461
with @code{set print union on} in effect @samp{p foo} would print
6462
 
6463
@smallexample
6464
$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
6465
@end smallexample
6466
 
6467
@noindent
6468
and with @code{set print union off} in effect it would print
6469
 
6470
@smallexample
6471
$1 = @{it = Tree, form = @{...@}@}
6472
@end smallexample
6473
 
6474
@noindent
6475
@code{set print union} affects programs written in C-like languages
6476
and in Pascal.
6477
@end table
6478
 
6479
@need 1000
6480
@noindent
6481
These settings are of interest when debugging C@t{++} programs:
6482
 
6483
@table @code
6484
@cindex demangling C@t{++} names
6485
@item set print demangle
6486
@itemx set print demangle on
6487
Print C@t{++} names in their source form rather than in the encoded
6488
(``mangled'') form passed to the assembler and linker for type-safe
6489
linkage.  The default is on.
6490
 
6491
@item show print demangle
6492
Show whether C@t{++} names are printed in mangled or demangled form.
6493
 
6494
@item set print asm-demangle
6495
@itemx set print asm-demangle on
6496
Print C@t{++} names in their source form rather than their mangled form, even
6497
in assembler code printouts such as instruction disassemblies.
6498
The default is off.
6499
 
6500
@item show print asm-demangle
6501
Show whether C@t{++} names in assembly listings are printed in mangled
6502
or demangled form.
6503
 
6504
@cindex C@t{++} symbol decoding style
6505
@cindex symbol decoding style, C@t{++}
6506
@kindex set demangle-style
6507
@item set demangle-style @var{style}
6508
Choose among several encoding schemes used by different compilers to
6509
represent C@t{++} names.  The choices for @var{style} are currently:
6510
 
6511
@table @code
6512
@item auto
6513
Allow @value{GDBN} to choose a decoding style by inspecting your program.
6514
 
6515
@item gnu
6516
Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
6517
This is the default.
6518
 
6519
@item hp
6520
Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
6521
 
6522
@item lucid
6523
Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
6524
 
6525
@item arm
6526
Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
6527
@strong{Warning:} this setting alone is not sufficient to allow
6528
debugging @code{cfront}-generated executables.  @value{GDBN} would
6529
require further enhancement to permit that.
6530
 
6531
@end table
6532
If you omit @var{style}, you will see a list of possible formats.
6533
 
6534
@item show demangle-style
6535
Display the encoding style currently in use for decoding C@t{++} symbols.
6536
 
6537
@item set print object
6538
@itemx set print object on
6539
@cindex derived type of an object, printing
6540
@cindex display derived types
6541
When displaying a pointer to an object, identify the @emph{actual}
6542
(derived) type of the object rather than the @emph{declared} type, using
6543
the virtual function table.
6544
 
6545
@item set print object off
6546
Display only the declared type of objects, without reference to the
6547
virtual function table.  This is the default setting.
6548
 
6549
@item show print object
6550
Show whether actual, or declared, object types are displayed.
6551
 
6552
@item set print static-members
6553
@itemx set print static-members on
6554
@cindex static members of C@t{++} objects
6555
Print static members when displaying a C@t{++} object.  The default is on.
6556
 
6557
@item set print static-members off
6558
Do not print static members when displaying a C@t{++} object.
6559
 
6560
@item show print static-members
6561
Show whether C@t{++} static members are printed or not.
6562
 
6563
@item set print pascal_static-members
6564
@itemx set print pascal_static-members on
6565
@cindex static members of Pascal objects
6566
@cindex Pascal objects, static members display
6567
Print static members when displaying a Pascal object.  The default is on.
6568
 
6569
@item set print pascal_static-members off
6570
Do not print static members when displaying a Pascal object.
6571
 
6572
@item show print pascal_static-members
6573
Show whether Pascal static members are printed or not.
6574
 
6575
@c These don't work with HP ANSI C++ yet.
6576
@item set print vtbl
6577
@itemx set print vtbl on
6578
@cindex pretty print C@t{++} virtual function tables
6579
@cindex virtual functions (C@t{++}) display
6580
@cindex VTBL display
6581
Pretty print C@t{++} virtual function tables.  The default is off.
6582
(The @code{vtbl} commands do not work on programs compiled with the HP
6583
ANSI C@t{++} compiler (@code{aCC}).)
6584
 
6585
@item set print vtbl off
6586
Do not pretty print C@t{++} virtual function tables.
6587
 
6588
@item show print vtbl
6589
Show whether C@t{++} virtual function tables are pretty printed, or not.
6590
@end table
6591
 
6592
@node Value History
6593
@section Value History
6594
 
6595
@cindex value history
6596
@cindex history of values printed by @value{GDBN}
6597
Values printed by the @code{print} command are saved in the @value{GDBN}
6598
@dfn{value history}.  This allows you to refer to them in other expressions.
6599
Values are kept until the symbol table is re-read or discarded
6600
(for example with the @code{file} or @code{symbol-file} commands).
6601
When the symbol table changes, the value history is discarded,
6602
since the values may contain pointers back to the types defined in the
6603
symbol table.
6604
 
6605
@cindex @code{$}
6606
@cindex @code{$$}
6607
@cindex history number
6608
The values printed are given @dfn{history numbers} by which you can
6609
refer to them.  These are successive integers starting with one.
6610
@code{print} shows you the history number assigned to a value by
6611
printing @samp{$@var{num} = } before the value; here @var{num} is the
6612
history number.
6613
 
6614
To refer to any previous value, use @samp{$} followed by the value's
6615
history number.  The way @code{print} labels its output is designed to
6616
remind you of this.  Just @code{$} refers to the most recent value in
6617
the history, and @code{$$} refers to the value before that.
6618
@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6619
is the value just prior to @code{$$}, @code{$$1} is equivalent to
6620
@code{$$}, and @code{$$0} is equivalent to @code{$}.
6621
 
6622
For example, suppose you have just printed a pointer to a structure and
6623
want to see the contents of the structure.  It suffices to type
6624
 
6625
@smallexample
6626
p *$
6627
@end smallexample
6628
 
6629
If you have a chain of structures where the component @code{next} points
6630
to the next one, you can print the contents of the next one with this:
6631
 
6632
@smallexample
6633
p *$.next
6634
@end smallexample
6635
 
6636
@noindent
6637
You can print successive links in the chain by repeating this
6638
command---which you can do by just typing @key{RET}.
6639
 
6640
Note that the history records values, not expressions.  If the value of
6641
@code{x} is 4 and you type these commands:
6642
 
6643
@smallexample
6644
print x
6645
set x=5
6646
@end smallexample
6647
 
6648
@noindent
6649
then the value recorded in the value history by the @code{print} command
6650
remains 4 even though the value of @code{x} has changed.
6651
 
6652
@table @code
6653
@kindex show values
6654
@item show values
6655
Print the last ten values in the value history, with their item numbers.
6656
This is like @samp{p@ $$9} repeated ten times, except that @code{show
6657
values} does not change the history.
6658
 
6659
@item show values @var{n}
6660
Print ten history values centered on history item number @var{n}.
6661
 
6662
@item show values +
6663
Print ten history values just after the values last printed.  If no more
6664
values are available, @code{show values +} produces no display.
6665
@end table
6666
 
6667
Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6668
same effect as @samp{show values +}.
6669
 
6670
@node Convenience Vars
6671
@section Convenience Variables
6672
 
6673
@cindex convenience variables
6674
@cindex user-defined variables
6675
@value{GDBN} provides @dfn{convenience variables} that you can use within
6676
@value{GDBN} to hold on to a value and refer to it later.  These variables
6677
exist entirely within @value{GDBN}; they are not part of your program, and
6678
setting a convenience variable has no direct effect on further execution
6679
of your program.  That is why you can use them freely.
6680
 
6681
Convenience variables are prefixed with @samp{$}.  Any name preceded by
6682
@samp{$} can be used for a convenience variable, unless it is one of
6683
the predefined machine-specific register names (@pxref{Registers, ,Registers}).
6684
(Value history references, in contrast, are @emph{numbers} preceded
6685
by @samp{$}.  @xref{Value History, ,Value History}.)
6686
 
6687
You can save a value in a convenience variable with an assignment
6688
expression, just as you would set a variable in your program.
6689
For example:
6690
 
6691
@smallexample
6692
set $foo = *object_ptr
6693
@end smallexample
6694
 
6695
@noindent
6696
would save in @code{$foo} the value contained in the object pointed to by
6697
@code{object_ptr}.
6698
 
6699
Using a convenience variable for the first time creates it, but its
6700
value is @code{void} until you assign a new value.  You can alter the
6701
value with another assignment at any time.
6702
 
6703
Convenience variables have no fixed types.  You can assign a convenience
6704
variable any type of value, including structures and arrays, even if
6705
that variable already has a value of a different type.  The convenience
6706
variable, when used as an expression, has the type of its current value.
6707
 
6708
@table @code
6709
@kindex show convenience
6710
@cindex show all user variables
6711
@item show convenience
6712
Print a list of convenience variables used so far, and their values.
6713
Abbreviated @code{show conv}.
6714
 
6715
@kindex init-if-undefined
6716
@cindex convenience variables, initializing
6717
@item init-if-undefined $@var{variable} = @var{expression}
6718
Set a convenience variable if it has not already been set.  This is useful
6719
for user-defined commands that keep some state.  It is similar, in concept,
6720
to using local static variables with initializers in C (except that
6721
convenience variables are global).  It can also be used to allow users to
6722
override default values used in a command script.
6723
 
6724
If the variable is already defined then the expression is not evaluated so
6725
any side-effects do not occur.
6726
@end table
6727
 
6728
One of the ways to use a convenience variable is as a counter to be
6729
incremented or a pointer to be advanced.  For example, to print
6730
a field from successive elements of an array of structures:
6731
 
6732
@smallexample
6733
set $i = 0
6734
print bar[$i++]->contents
6735
@end smallexample
6736
 
6737
@noindent
6738
Repeat that command by typing @key{RET}.
6739
 
6740
Some convenience variables are created automatically by @value{GDBN} and given
6741
values likely to be useful.
6742
 
6743
@table @code
6744
@vindex $_@r{, convenience variable}
6745
@item $_
6746
The variable @code{$_} is automatically set by the @code{x} command to
6747
the last address examined (@pxref{Memory, ,Examining Memory}).  Other
6748
commands which provide a default address for @code{x} to examine also
6749
set @code{$_} to that address; these commands include @code{info line}
6750
and @code{info breakpoint}.  The type of @code{$_} is @code{void *}
6751
except when set by the @code{x} command, in which case it is a pointer
6752
to the type of @code{$__}.
6753
 
6754
@vindex $__@r{, convenience variable}
6755
@item $__
6756
The variable @code{$__} is automatically set by the @code{x} command
6757
to the value found in the last address examined.  Its type is chosen
6758
to match the format in which the data was printed.
6759
 
6760
@item $_exitcode
6761
@vindex $_exitcode@r{, convenience variable}
6762
The variable @code{$_exitcode} is automatically set to the exit code when
6763
the program being debugged terminates.
6764
@end table
6765
 
6766
On HP-UX systems, if you refer to a function or variable name that
6767
begins with a dollar sign, @value{GDBN} searches for a user or system
6768
name first, before it searches for a convenience variable.
6769
 
6770
@node Registers
6771
@section Registers
6772
 
6773
@cindex registers
6774
You can refer to machine register contents, in expressions, as variables
6775
with names starting with @samp{$}.  The names of registers are different
6776
for each machine; use @code{info registers} to see the names used on
6777
your machine.
6778
 
6779
@table @code
6780
@kindex info registers
6781
@item info registers
6782
Print the names and values of all registers except floating-point
6783
and vector registers (in the selected stack frame).
6784
 
6785
@kindex info all-registers
6786
@cindex floating point registers
6787
@item info all-registers
6788
Print the names and values of all registers, including floating-point
6789
and vector registers (in the selected stack frame).
6790
 
6791
@item info registers @var{regname} @dots{}
6792
Print the @dfn{relativized} value of each specified register @var{regname}.
6793
As discussed in detail below, register values are normally relative to
6794
the selected stack frame.  @var{regname} may be any register name valid on
6795
the machine you are using, with or without the initial @samp{$}.
6796
@end table
6797
 
6798
@cindex stack pointer register
6799
@cindex program counter register
6800
@cindex process status register
6801
@cindex frame pointer register
6802
@cindex standard registers
6803
@value{GDBN} has four ``standard'' register names that are available (in
6804
expressions) on most machines---whenever they do not conflict with an
6805
architecture's canonical mnemonics for registers.  The register names
6806
@code{$pc} and @code{$sp} are used for the program counter register and
6807
the stack pointer.  @code{$fp} is used for a register that contains a
6808
pointer to the current stack frame, and @code{$ps} is used for a
6809
register that contains the processor status.  For example,
6810
you could print the program counter in hex with
6811
 
6812
@smallexample
6813
p/x $pc
6814
@end smallexample
6815
 
6816
@noindent
6817
or print the instruction to be executed next with
6818
 
6819
@smallexample
6820
x/i $pc
6821
@end smallexample
6822
 
6823
@noindent
6824
or add four to the stack pointer@footnote{This is a way of removing
6825
one word from the stack, on machines where stacks grow downward in
6826
memory (most machines, nowadays).  This assumes that the innermost
6827
stack frame is selected; setting @code{$sp} is not allowed when other
6828
stack frames are selected.  To pop entire frames off the stack,
6829
regardless of machine architecture, use @code{return};
6830
see @ref{Returning, ,Returning from a Function}.} with
6831
 
6832
@smallexample
6833
set $sp += 4
6834
@end smallexample
6835
 
6836
Whenever possible, these four standard register names are available on
6837
your machine even though the machine has different canonical mnemonics,
6838
so long as there is no conflict.  The @code{info registers} command
6839
shows the canonical names.  For example, on the SPARC, @code{info
6840
registers} displays the processor status register as @code{$psr} but you
6841
can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6842
is an alias for the @sc{eflags} register.
6843
 
6844
@value{GDBN} always considers the contents of an ordinary register as an
6845
integer when the register is examined in this way.  Some machines have
6846
special registers which can hold nothing but floating point; these
6847
registers are considered to have floating point values.  There is no way
6848
to refer to the contents of an ordinary register as floating point value
6849
(although you can @emph{print} it as a floating point value with
6850
@samp{print/f $@var{regname}}).
6851
 
6852
Some registers have distinct ``raw'' and ``virtual'' data formats.  This
6853
means that the data format in which the register contents are saved by
6854
the operating system is not the same one that your program normally
6855
sees.  For example, the registers of the 68881 floating point
6856
coprocessor are always saved in ``extended'' (raw) format, but all C
6857
programs expect to work with ``double'' (virtual) format.  In such
6858
cases, @value{GDBN} normally works with the virtual format only (the format
6859
that makes sense for your program), but the @code{info registers} command
6860
prints the data in both formats.
6861
 
6862
@cindex SSE registers (x86)
6863
@cindex MMX registers (x86)
6864
Some machines have special registers whose contents can be interpreted
6865
in several different ways.  For example, modern x86-based machines
6866
have SSE and MMX registers that can hold several values packed
6867
together in several different formats.  @value{GDBN} refers to such
6868
registers in @code{struct} notation:
6869
 
6870
@smallexample
6871
(@value{GDBP}) print $xmm1
6872
$1 = @{
6873
  v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
6874
  v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
6875
  v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6876
  v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
6877
  v4_int32 = @{0, 20657912, 11, 13@},
6878
  v2_int64 = @{88725056443645952, 55834574859@},
6879
  uint128 = 0x0000000d0000000b013b36f800000000
6880
@}
6881
@end smallexample
6882
 
6883
@noindent
6884
To set values of such registers, you need to tell @value{GDBN} which
6885
view of the register you wish to change, as if you were assigning
6886
value to a @code{struct} member:
6887
 
6888
@smallexample
6889
 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6890
@end smallexample
6891
 
6892
Normally, register values are relative to the selected stack frame
6893
(@pxref{Selection, ,Selecting a Frame}).  This means that you get the
6894
value that the register would contain if all stack frames farther in
6895
were exited and their saved registers restored.  In order to see the
6896
true contents of hardware registers, you must select the innermost
6897
frame (with @samp{frame 0}).
6898
 
6899
However, @value{GDBN} must deduce where registers are saved, from the machine
6900
code generated by your compiler.  If some registers are not saved, or if
6901
@value{GDBN} is unable to locate the saved registers, the selected stack
6902
frame makes no difference.
6903
 
6904
@node Floating Point Hardware
6905
@section Floating Point Hardware
6906
@cindex floating point
6907
 
6908
Depending on the configuration, @value{GDBN} may be able to give
6909
you more information about the status of the floating point hardware.
6910
 
6911
@table @code
6912
@kindex info float
6913
@item info float
6914
Display hardware-dependent information about the floating
6915
point unit.  The exact contents and layout vary depending on the
6916
floating point chip.  Currently, @samp{info float} is supported on
6917
the ARM and x86 machines.
6918
@end table
6919
 
6920
@node Vector Unit
6921
@section Vector Unit
6922
@cindex vector unit
6923
 
6924
Depending on the configuration, @value{GDBN} may be able to give you
6925
more information about the status of the vector unit.
6926
 
6927
@table @code
6928
@kindex info vector
6929
@item info vector
6930
Display information about the vector unit.  The exact contents and
6931
layout vary depending on the hardware.
6932
@end table
6933
 
6934
@node OS Information
6935
@section Operating System Auxiliary Information
6936
@cindex OS information
6937
 
6938
@value{GDBN} provides interfaces to useful OS facilities that can help
6939
you debug your program.
6940
 
6941
@cindex @code{ptrace} system call
6942
@cindex @code{struct user} contents
6943
When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6944
machines), it interfaces with the inferior via the @code{ptrace}
6945
system call.  The operating system creates a special sata structure,
6946
called @code{struct user}, for this interface.  You can use the
6947
command @code{info udot} to display the contents of this data
6948
structure.
6949
 
6950
@table @code
6951
@item info udot
6952
@kindex info udot
6953
Display the contents of the @code{struct user} maintained by the OS
6954
kernel for the program being debugged.  @value{GDBN} displays the
6955
contents of @code{struct user} as a list of hex numbers, similar to
6956
the @code{examine} command.
6957
@end table
6958
 
6959
@cindex auxiliary vector
6960
@cindex vector, auxiliary
6961
Some operating systems supply an @dfn{auxiliary vector} to programs at
6962
startup.  This is akin to the arguments and environment that you
6963
specify for a program, but contains a system-dependent variety of
6964
binary values that tell system libraries important details about the
6965
hardware, operating system, and process.  Each value's purpose is
6966
identified by an integer tag; the meanings are well-known but system-specific.
6967
Depending on the configuration and operating system facilities,
6968
@value{GDBN} may be able to show you this information.  For remote
6969
targets, this functionality may further depend on the remote stub's
6970
support of the @samp{qXfer:auxv:read} packet, see
6971
@ref{qXfer auxiliary vector read}.
6972
 
6973
@table @code
6974
@kindex info auxv
6975
@item info auxv
6976
Display the auxiliary vector of the inferior, which can be either a
6977
live process or a core dump file.  @value{GDBN} prints each tag value
6978
numerically, and also shows names and text descriptions for recognized
6979
tags.  Some values in the vector are numbers, some bit masks, and some
6980
pointers to strings or other data.  @value{GDBN} displays each value in the
6981
most appropriate form for a recognized tag, and in hexadecimal for
6982
an unrecognized tag.
6983
@end table
6984
 
6985
 
6986
@node Memory Region Attributes
6987
@section Memory Region Attributes
6988
@cindex memory region attributes
6989
 
6990
@dfn{Memory region attributes} allow you to describe special handling
6991
required by regions of your target's memory.  @value{GDBN} uses
6992
attributes to determine whether to allow certain types of memory
6993
accesses; whether to use specific width accesses; and whether to cache
6994
target memory.  By default the description of memory regions is
6995
fetched from the target (if the current target supports this), but the
6996
user can override the fetched regions.
6997
 
6998
Defined memory regions can be individually enabled and disabled.  When a
6999
memory region is disabled, @value{GDBN} uses the default attributes when
7000
accessing memory in that region.  Similarly, if no memory regions have
7001
been defined, @value{GDBN} uses the default attributes when accessing
7002
all memory.
7003
 
7004
When a memory region is defined, it is given a number to identify it;
7005
to enable, disable, or remove a memory region, you specify that number.
7006
 
7007
@table @code
7008
@kindex mem
7009
@item mem @var{lower} @var{upper} @var{attributes}@dots{}
7010
Define a memory region bounded by @var{lower} and @var{upper} with
7011
attributes @var{attributes}@dots{}, and add it to the list of regions
7012
monitored by @value{GDBN}.  Note that @var{upper} == 0 is a special
7013
case: it is treated as the target's maximum memory address.
7014
(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
7015
 
7016
@item mem auto
7017
Discard any user changes to the memory regions and use target-supplied
7018
regions, if available, or no regions if the target does not support.
7019
 
7020
@kindex delete mem
7021
@item delete mem @var{nums}@dots{}
7022
Remove memory regions @var{nums}@dots{} from the list of regions
7023
monitored by @value{GDBN}.
7024
 
7025
@kindex disable mem
7026
@item disable mem @var{nums}@dots{}
7027
Disable monitoring of memory regions @var{nums}@dots{}.
7028
A disabled memory region is not forgotten.
7029
It may be enabled again later.
7030
 
7031
@kindex enable mem
7032
@item enable mem @var{nums}@dots{}
7033
Enable monitoring of memory regions @var{nums}@dots{}.
7034
 
7035
@kindex info mem
7036
@item info mem
7037
Print a table of all defined memory regions, with the following columns
7038
for each region:
7039
 
7040
@table @emph
7041
@item Memory Region Number
7042
@item Enabled or Disabled.
7043
Enabled memory regions are marked with @samp{y}.
7044
Disabled memory regions are marked with @samp{n}.
7045
 
7046
@item Lo Address
7047
The address defining the inclusive lower bound of the memory region.
7048
 
7049
@item Hi Address
7050
The address defining the exclusive upper bound of the memory region.
7051
 
7052
@item Attributes
7053
The list of attributes set for this memory region.
7054
@end table
7055
@end table
7056
 
7057
 
7058
@subsection Attributes
7059
 
7060
@subsubsection Memory Access Mode
7061
The access mode attributes set whether @value{GDBN} may make read or
7062
write accesses to a memory region.
7063
 
7064
While these attributes prevent @value{GDBN} from performing invalid
7065
memory accesses, they do nothing to prevent the target system, I/O DMA,
7066
etc.@: from accessing memory.
7067
 
7068
@table @code
7069
@item ro
7070
Memory is read only.
7071
@item wo
7072
Memory is write only.
7073
@item rw
7074
Memory is read/write.  This is the default.
7075
@end table
7076
 
7077
@subsubsection Memory Access Size
7078
The access size attribute tells @value{GDBN} to use specific sized
7079
accesses in the memory region.  Often memory mapped device registers
7080
require specific sized accesses.  If no access size attribute is
7081
specified, @value{GDBN} may use accesses of any size.
7082
 
7083
@table @code
7084
@item 8
7085
Use 8 bit memory accesses.
7086
@item 16
7087
Use 16 bit memory accesses.
7088
@item 32
7089
Use 32 bit memory accesses.
7090
@item 64
7091
Use 64 bit memory accesses.
7092
@end table
7093
 
7094
@c @subsubsection Hardware/Software Breakpoints
7095
@c The hardware/software breakpoint attributes set whether @value{GDBN}
7096
@c will use hardware or software breakpoints for the internal breakpoints
7097
@c used by the step, next, finish, until, etc. commands.
7098
@c
7099
@c @table @code
7100
@c @item hwbreak
7101
@c Always use hardware breakpoints
7102
@c @item swbreak (default)
7103
@c @end table
7104
 
7105
@subsubsection Data Cache
7106
The data cache attributes set whether @value{GDBN} will cache target
7107
memory.  While this generally improves performance by reducing debug
7108
protocol overhead, it can lead to incorrect results because @value{GDBN}
7109
does not know about volatile variables or memory mapped device
7110
registers.
7111
 
7112
@table @code
7113
@item cache
7114
Enable @value{GDBN} to cache target memory.
7115
@item nocache
7116
Disable @value{GDBN} from caching target memory.  This is the default.
7117
@end table
7118
 
7119
@subsection Memory Access Checking
7120
@value{GDBN} can be instructed to refuse accesses to memory that is
7121
not explicitly described.  This can be useful if accessing such
7122
regions has undesired effects for a specific target, or to provide
7123
better error checking.  The following commands control this behaviour.
7124
 
7125
@table @code
7126
@kindex set mem inaccessible-by-default
7127
@item set mem inaccessible-by-default [on|off]
7128
If @code{on} is specified, make  @value{GDBN} treat memory not
7129
explicitly described by the memory ranges as non-existent and refuse accesses
7130
to such memory.  The checks are only performed if there's at least one
7131
memory range defined.  If @code{off} is specified, make @value{GDBN}
7132
treat the memory not explicitly described by the memory ranges as RAM.
7133
The default value is @code{on}.
7134
@kindex show mem inaccessible-by-default
7135
@item show mem inaccessible-by-default
7136
Show the current handling of accesses to unknown memory.
7137
@end table
7138
 
7139
 
7140
@c @subsubsection Memory Write Verification
7141
@c The memory write verification attributes set whether @value{GDBN}
7142
@c will re-reads data after each write to verify the write was successful.
7143
@c
7144
@c @table @code
7145
@c @item verify
7146
@c @item noverify (default)
7147
@c @end table
7148
 
7149
@node Dump/Restore Files
7150
@section Copy Between Memory and a File
7151
@cindex dump/restore files
7152
@cindex append data to a file
7153
@cindex dump data to a file
7154
@cindex restore data from a file
7155
 
7156
You can use the commands @code{dump}, @code{append}, and
7157
@code{restore} to copy data between target memory and a file.  The
7158
@code{dump} and @code{append} commands write data to a file, and the
7159
@code{restore} command reads data from a file back into the inferior's
7160
memory.  Files may be in binary, Motorola S-record, Intel hex, or
7161
Tektronix Hex format; however, @value{GDBN} can only append to binary
7162
files.
7163
 
7164
@table @code
7165
 
7166
@kindex dump
7167
@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7168
@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
7169
Dump the contents of memory from @var{start_addr} to @var{end_addr},
7170
or the value of @var{expr}, to @var{filename} in the given format.
7171
 
7172
The @var{format} parameter may be any one of:
7173
@table @code
7174
@item binary
7175
Raw binary form.
7176
@item ihex
7177
Intel hex format.
7178
@item srec
7179
Motorola S-record format.
7180
@item tekhex
7181
Tektronix Hex format.
7182
@end table
7183
 
7184
@value{GDBN} uses the same definitions of these formats as the
7185
@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}.  If
7186
@var{format} is omitted, @value{GDBN} dumps the data in raw binary
7187
form.
7188
 
7189
@kindex append
7190
@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7191
@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
7192
Append the contents of memory from @var{start_addr} to @var{end_addr},
7193
or the value of @var{expr}, to the file @var{filename}, in raw binary form.
7194
(@value{GDBN} can only append data to files in raw binary form.)
7195
 
7196
@kindex restore
7197
@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
7198
Restore the contents of file @var{filename} into memory.  The
7199
@code{restore} command can automatically recognize any known @sc{bfd}
7200
file format, except for raw binary.  To restore a raw binary file you
7201
must specify the optional keyword @code{binary} after the filename.
7202
 
7203
If @var{bias} is non-zero, its value will be added to the addresses
7204
contained in the file.  Binary files always start at address zero, so
7205
they will be restored at address @var{bias}.  Other bfd files have
7206
a built-in location; they will be restored at offset @var{bias}
7207
from that location.
7208
 
7209
If @var{start} and/or @var{end} are non-zero, then only data between
7210
file offset @var{start} and file offset @var{end} will be restored.
7211
These offsets are relative to the addresses in the file, before
7212
the @var{bias} argument is applied.
7213
 
7214
@end table
7215
 
7216
@node Core File Generation
7217
@section How to Produce a Core File from Your Program
7218
@cindex dump core from inferior
7219
 
7220
A @dfn{core file} or @dfn{core dump} is a file that records the memory
7221
image of a running process and its process status (register values
7222
etc.).  Its primary use is post-mortem debugging of a program that
7223
crashed while it ran outside a debugger.  A program that crashes
7224
automatically produces a core file, unless this feature is disabled by
7225
the user.  @xref{Files}, for information on invoking @value{GDBN} in
7226
the post-mortem debugging mode.
7227
 
7228
Occasionally, you may wish to produce a core file of the program you
7229
are debugging in order to preserve a snapshot of its state.
7230
@value{GDBN} has a special command for that.
7231
 
7232
@table @code
7233
@kindex gcore
7234
@kindex generate-core-file
7235
@item generate-core-file [@var{file}]
7236
@itemx gcore [@var{file}]
7237
Produce a core dump of the inferior process.  The optional argument
7238
@var{file} specifies the file name where to put the core dump.  If not
7239
specified, the file name defaults to @file{core.@var{pid}}, where
7240
@var{pid} is the inferior process ID.
7241
 
7242
Note that this command is implemented only for some systems (as of
7243
this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
7244
@end table
7245
 
7246
@node Character Sets
7247
@section Character Sets
7248
@cindex character sets
7249
@cindex charset
7250
@cindex translating between character sets
7251
@cindex host character set
7252
@cindex target character set
7253
 
7254
If the program you are debugging uses a different character set to
7255
represent characters and strings than the one @value{GDBN} uses itself,
7256
@value{GDBN} can automatically translate between the character sets for
7257
you.  The character set @value{GDBN} uses we call the @dfn{host
7258
character set}; the one the inferior program uses we call the
7259
@dfn{target character set}.
7260
 
7261
For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
7262
uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
7263
remote protocol (@pxref{Remote Debugging}) to debug a program
7264
running on an IBM mainframe, which uses the @sc{ebcdic} character set,
7265
then the host character set is Latin-1, and the target character set is
7266
@sc{ebcdic}.  If you give @value{GDBN} the command @code{set
7267
target-charset EBCDIC-US}, then @value{GDBN} translates between
7268
@sc{ebcdic} and Latin 1 as you print character or string values, or use
7269
character and string literals in expressions.
7270
 
7271
@value{GDBN} has no way to automatically recognize which character set
7272
the inferior program uses; you must tell it, using the @code{set
7273
target-charset} command, described below.
7274
 
7275
Here are the commands for controlling @value{GDBN}'s character set
7276
support:
7277
 
7278
@table @code
7279
@item set target-charset @var{charset}
7280
@kindex set target-charset
7281
Set the current target character set to @var{charset}.  We list the
7282
character set names @value{GDBN} recognizes below, but if you type
7283
@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7284
list the target character sets it supports.
7285
@end table
7286
 
7287
@table @code
7288
@item set host-charset @var{charset}
7289
@kindex set host-charset
7290
Set the current host character set to @var{charset}.
7291
 
7292
By default, @value{GDBN} uses a host character set appropriate to the
7293
system it is running on; you can override that default using the
7294
@code{set host-charset} command.
7295
 
7296
@value{GDBN} can only use certain character sets as its host character
7297
set.  We list the character set names @value{GDBN} recognizes below, and
7298
indicate which can be host character sets, but if you type
7299
@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7300
list the host character sets it supports.
7301
 
7302
@item set charset @var{charset}
7303
@kindex set charset
7304
Set the current host and target character sets to @var{charset}.  As
7305
above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
7306
@value{GDBN} will list the name of the character sets that can be used
7307
for both host and target.
7308
 
7309
 
7310
@item show charset
7311
@kindex show charset
7312
Show the names of the current host and target charsets.
7313
 
7314
@itemx show host-charset
7315
@kindex show host-charset
7316
Show the name of the current host charset.
7317
 
7318
@itemx show target-charset
7319
@kindex show target-charset
7320
Show the name of the current target charset.
7321
 
7322
@end table
7323
 
7324
@value{GDBN} currently includes support for the following character
7325
sets:
7326
 
7327
@table @code
7328
 
7329
@item ASCII
7330
@cindex ASCII character set
7331
Seven-bit U.S. @sc{ascii}.  @value{GDBN} can use this as its host
7332
character set.
7333
 
7334
@item ISO-8859-1
7335
@cindex ISO 8859-1 character set
7336
@cindex ISO Latin 1 character set
7337
The ISO Latin 1 character set.  This extends @sc{ascii} with accented
7338
characters needed for French, German, and Spanish.  @value{GDBN} can use
7339
this as its host character set.
7340
 
7341
@item EBCDIC-US
7342
@itemx IBM1047
7343
@cindex EBCDIC character set
7344
@cindex IBM1047 character set
7345
Variants of the @sc{ebcdic} character set, used on some of IBM's
7346
mainframe operating systems.  (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
7347
@value{GDBN} cannot use these as its host character set.
7348
 
7349
@end table
7350
 
7351
Note that these are all single-byte character sets.  More work inside
7352
@value{GDBN} is needed to support multi-byte or variable-width character
7353
encodings, like the UTF-8 and UCS-2 encodings of Unicode.
7354
 
7355
Here is an example of @value{GDBN}'s character set support in action.
7356
Assume that the following source code has been placed in the file
7357
@file{charset-test.c}:
7358
 
7359
@smallexample
7360
#include <stdio.h>
7361
 
7362
char ascii_hello[]
7363
  = @{72, 101, 108, 108, 111, 44, 32, 119,
7364
     111, 114, 108, 100, 33, 10, 0@};
7365
char ibm1047_hello[]
7366
  = @{200, 133, 147, 147, 150, 107, 64, 166,
7367
     150, 153, 147, 132, 90, 37, 0@};
7368
 
7369
main ()
7370
@{
7371
  printf ("Hello, world!\n");
7372
@}
7373
@end smallexample
7374
 
7375
In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
7376
containing the string @samp{Hello, world!} followed by a newline,
7377
encoded in the @sc{ascii} and @sc{ibm1047} character sets.
7378
 
7379
We compile the program, and invoke the debugger on it:
7380
 
7381
@smallexample
7382
$ gcc -g charset-test.c -o charset-test
7383
$ gdb -nw charset-test
7384
GNU gdb 2001-12-19-cvs
7385
Copyright 2001 Free Software Foundation, Inc.
7386
@dots{}
7387
(@value{GDBP})
7388
@end smallexample
7389
 
7390
We can use the @code{show charset} command to see what character sets
7391
@value{GDBN} is currently using to interpret and display characters and
7392
strings:
7393
 
7394
@smallexample
7395
(@value{GDBP}) show charset
7396
The current host and target character set is `ISO-8859-1'.
7397
(@value{GDBP})
7398
@end smallexample
7399
 
7400
For the sake of printing this manual, let's use @sc{ascii} as our
7401
initial character set:
7402
@smallexample
7403
(@value{GDBP}) set charset ASCII
7404
(@value{GDBP}) show charset
7405
The current host and target character set is `ASCII'.
7406
(@value{GDBP})
7407
@end smallexample
7408
 
7409
Let's assume that @sc{ascii} is indeed the correct character set for our
7410
host system --- in other words, let's assume that if @value{GDBN} prints
7411
characters using the @sc{ascii} character set, our terminal will display
7412
them properly.  Since our current target character set is also
7413
@sc{ascii}, the contents of @code{ascii_hello} print legibly:
7414
 
7415
@smallexample
7416
(@value{GDBP}) print ascii_hello
7417
$1 = 0x401698 "Hello, world!\n"
7418
(@value{GDBP}) print ascii_hello[0]
7419
$2 = 72 'H'
7420
(@value{GDBP})
7421
@end smallexample
7422
 
7423
@value{GDBN} uses the target character set for character and string
7424
literals you use in expressions:
7425
 
7426
@smallexample
7427
(@value{GDBP}) print '+'
7428
$3 = 43 '+'
7429
(@value{GDBP})
7430
@end smallexample
7431
 
7432
The @sc{ascii} character set uses the number 43 to encode the @samp{+}
7433
character.
7434
 
7435
@value{GDBN} relies on the user to tell it which character set the
7436
target program uses.  If we print @code{ibm1047_hello} while our target
7437
character set is still @sc{ascii}, we get jibberish:
7438
 
7439
@smallexample
7440
(@value{GDBP}) print ibm1047_hello
7441
$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
7442
(@value{GDBP}) print ibm1047_hello[0]
7443
$5 = 200 '\310'
7444
(@value{GDBP})
7445
@end smallexample
7446
 
7447
If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
7448
@value{GDBN} tells us the character sets it supports:
7449
 
7450
@smallexample
7451
(@value{GDBP}) set target-charset
7452
ASCII       EBCDIC-US   IBM1047     ISO-8859-1
7453
(@value{GDBP}) set target-charset
7454
@end smallexample
7455
 
7456
We can select @sc{ibm1047} as our target character set, and examine the
7457
program's strings again.  Now the @sc{ascii} string is wrong, but
7458
@value{GDBN} translates the contents of @code{ibm1047_hello} from the
7459
target character set, @sc{ibm1047}, to the host character set,
7460
@sc{ascii}, and they display correctly:
7461
 
7462
@smallexample
7463
(@value{GDBP}) set target-charset IBM1047
7464
(@value{GDBP}) show charset
7465
The current host character set is `ASCII'.
7466
The current target character set is `IBM1047'.
7467
(@value{GDBP}) print ascii_hello
7468
$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
7469
(@value{GDBP}) print ascii_hello[0]
7470
$7 = 72 '\110'
7471
(@value{GDBP}) print ibm1047_hello
7472
$8 = 0x4016a8 "Hello, world!\n"
7473
(@value{GDBP}) print ibm1047_hello[0]
7474
$9 = 200 'H'
7475
(@value{GDBP})
7476
@end smallexample
7477
 
7478
As above, @value{GDBN} uses the target character set for character and
7479
string literals you use in expressions:
7480
 
7481
@smallexample
7482
(@value{GDBP}) print '+'
7483
$10 = 78 '+'
7484
(@value{GDBP})
7485
@end smallexample
7486
 
7487
The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
7488
character.
7489
 
7490
@node Caching Remote Data
7491
@section Caching Data of Remote Targets
7492
@cindex caching data of remote targets
7493
 
7494
@value{GDBN} can cache data exchanged between the debugger and a
7495
remote target (@pxref{Remote Debugging}).  Such caching generally improves
7496
performance, because it reduces the overhead of the remote protocol by
7497
bundling memory reads and writes into large chunks.  Unfortunately,
7498
@value{GDBN} does not currently know anything about volatile
7499
registers, and thus data caching will produce incorrect results when
7500
volatile registers are in use.
7501
 
7502
@table @code
7503
@kindex set remotecache
7504
@item set remotecache on
7505
@itemx set remotecache off
7506
Set caching state for remote targets.  When @code{ON}, use data
7507
caching.  By default, this option is @code{OFF}.
7508
 
7509
@kindex show remotecache
7510
@item show remotecache
7511
Show the current state of data caching for remote targets.
7512
 
7513
@kindex info dcache
7514
@item info dcache
7515
Print the information about the data cache performance.  The
7516
information displayed includes: the dcache width and depth; and for
7517
each cache line, how many times it was referenced, and its data and
7518
state (dirty, bad, ok, etc.).  This command is useful for debugging
7519
the data cache operation.
7520
@end table
7521
 
7522
 
7523
@node Macros
7524
@chapter C Preprocessor Macros
7525
 
7526
Some languages, such as C and C@t{++}, provide a way to define and invoke
7527
``preprocessor macros'' which expand into strings of tokens.
7528
@value{GDBN} can evaluate expressions containing macro invocations, show
7529
the result of macro expansion, and show a macro's definition, including
7530
where it was defined.
7531
 
7532
You may need to compile your program specially to provide @value{GDBN}
7533
with information about preprocessor macros.  Most compilers do not
7534
include macros in their debugging information, even when you compile
7535
with the @option{-g} flag.  @xref{Compilation}.
7536
 
7537
A program may define a macro at one point, remove that definition later,
7538
and then provide a different definition after that.  Thus, at different
7539
points in the program, a macro may have different definitions, or have
7540
no definition at all.  If there is a current stack frame, @value{GDBN}
7541
uses the macros in scope at that frame's source code line.  Otherwise,
7542
@value{GDBN} uses the macros in scope at the current listing location;
7543
see @ref{List}.
7544
 
7545
At the moment, @value{GDBN} does not support the @code{##}
7546
token-splicing operator, the @code{#} stringification operator, or
7547
variable-arity macros.
7548
 
7549
Whenever @value{GDBN} evaluates an expression, it always expands any
7550
macro invocations present in the expression.  @value{GDBN} also provides
7551
the following commands for working with macros explicitly.
7552
 
7553
@table @code
7554
 
7555
@kindex macro expand
7556
@cindex macro expansion, showing the results of preprocessor
7557
@cindex preprocessor macro expansion, showing the results of
7558
@cindex expanding preprocessor macros
7559
@item macro expand @var{expression}
7560
@itemx macro exp @var{expression}
7561
Show the results of expanding all preprocessor macro invocations in
7562
@var{expression}.  Since @value{GDBN} simply expands macros, but does
7563
not parse the result, @var{expression} need not be a valid expression;
7564
it can be any string of tokens.
7565
 
7566
@kindex macro exp1
7567
@item macro expand-once @var{expression}
7568
@itemx macro exp1 @var{expression}
7569
@cindex expand macro once
7570
@i{(This command is not yet implemented.)}  Show the results of
7571
expanding those preprocessor macro invocations that appear explicitly in
7572
@var{expression}.  Macro invocations appearing in that expansion are
7573
left unchanged.  This command allows you to see the effect of a
7574
particular macro more clearly, without being confused by further
7575
expansions.  Since @value{GDBN} simply expands macros, but does not
7576
parse the result, @var{expression} need not be a valid expression; it
7577
can be any string of tokens.
7578
 
7579
@kindex info macro
7580
@cindex macro definition, showing
7581
@cindex definition, showing a macro's
7582
@item info macro @var{macro}
7583
Show the definition of the macro named @var{macro}, and describe the
7584
source location where that definition was established.
7585
 
7586
@kindex macro define
7587
@cindex user-defined macros
7588
@cindex defining macros interactively
7589
@cindex macros, user-defined
7590
@item macro define @var{macro} @var{replacement-list}
7591
@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
7592
@i{(This command is not yet implemented.)}  Introduce a definition for a
7593
preprocessor macro named @var{macro}, invocations of which are replaced
7594
by the tokens given in @var{replacement-list}.  The first form of this
7595
command defines an ``object-like'' macro, which takes no arguments; the
7596
second form defines a ``function-like'' macro, which takes the arguments
7597
given in @var{arglist}.
7598
 
7599
A definition introduced by this command is in scope in every expression
7600
evaluated in @value{GDBN}, until it is removed with the @command{macro
7601
undef} command, described below.  The definition overrides all
7602
definitions for @var{macro} present in the program being debugged, as
7603
well as any previous user-supplied definition.
7604
 
7605
@kindex macro undef
7606
@item macro undef @var{macro}
7607
@i{(This command is not yet implemented.)}  Remove any user-supplied
7608
definition for the macro named @var{macro}.  This command only affects
7609
definitions provided with the @command{macro define} command, described
7610
above; it cannot remove definitions present in the program being
7611
debugged.
7612
 
7613
@kindex macro list
7614
@item macro list
7615
@i{(This command is not yet implemented.)}  List all the macros
7616
defined using the @code{macro define} command.
7617
@end table
7618
 
7619
@cindex macros, example of debugging with
7620
Here is a transcript showing the above commands in action.  First, we
7621
show our source files:
7622
 
7623
@smallexample
7624
$ cat sample.c
7625
#include <stdio.h>
7626
#include "sample.h"
7627
 
7628
#define M 42
7629
#define ADD(x) (M + x)
7630
 
7631
main ()
7632
@{
7633
#define N 28
7634
  printf ("Hello, world!\n");
7635
#undef N
7636
  printf ("We're so creative.\n");
7637
#define N 1729
7638
  printf ("Goodbye, world!\n");
7639
@}
7640
$ cat sample.h
7641
#define Q <
7642
$
7643
@end smallexample
7644
 
7645
Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
7646
We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
7647
compiler includes information about preprocessor macros in the debugging
7648
information.
7649
 
7650
@smallexample
7651
$ gcc -gdwarf-2 -g3 sample.c -o sample
7652
$
7653
@end smallexample
7654
 
7655
Now, we start @value{GDBN} on our sample program:
7656
 
7657
@smallexample
7658
$ gdb -nw sample
7659
GNU gdb 2002-05-06-cvs
7660
Copyright 2002 Free Software Foundation, Inc.
7661
GDB is free software, @dots{}
7662
(@value{GDBP})
7663
@end smallexample
7664
 
7665
We can expand macros and examine their definitions, even when the
7666
program is not running.  @value{GDBN} uses the current listing position
7667
to decide which macro definitions are in scope:
7668
 
7669
@smallexample
7670
(@value{GDBP}) list main
7671
3
7672
4       #define M 42
7673
5       #define ADD(x) (M + x)
7674
6
7675
7       main ()
7676
8       @{
7677
9       #define N 28
7678
10        printf ("Hello, world!\n");
7679
11      #undef N
7680
12        printf ("We're so creative.\n");
7681
(@value{GDBP}) info macro ADD
7682
Defined at /home/jimb/gdb/macros/play/sample.c:5
7683
#define ADD(x) (M + x)
7684
(@value{GDBP}) info macro Q
7685
Defined at /home/jimb/gdb/macros/play/sample.h:1
7686
  included at /home/jimb/gdb/macros/play/sample.c:2
7687
#define Q <
7688
(@value{GDBP}) macro expand ADD(1)
7689
expands to: (42 + 1)
7690
(@value{GDBP}) macro expand-once ADD(1)
7691
expands to: once (M + 1)
7692
(@value{GDBP})
7693
@end smallexample
7694
 
7695
In the example above, note that @command{macro expand-once} expands only
7696
the macro invocation explicit in the original text --- the invocation of
7697
@code{ADD} --- but does not expand the invocation of the macro @code{M},
7698
which was introduced by @code{ADD}.
7699
 
7700
Once the program is running, @value{GDBN} uses the macro definitions in
7701
force at the source line of the current stack frame:
7702
 
7703
@smallexample
7704
(@value{GDBP}) break main
7705
Breakpoint 1 at 0x8048370: file sample.c, line 10.
7706
(@value{GDBP}) run
7707
Starting program: /home/jimb/gdb/macros/play/sample
7708
 
7709
Breakpoint 1, main () at sample.c:10
7710
10        printf ("Hello, world!\n");
7711
(@value{GDBP})
7712
@end smallexample
7713
 
7714
At line 10, the definition of the macro @code{N} at line 9 is in force:
7715
 
7716
@smallexample
7717
(@value{GDBP}) info macro N
7718
Defined at /home/jimb/gdb/macros/play/sample.c:9
7719
#define N 28
7720
(@value{GDBP}) macro expand N Q M
7721
expands to: 28 < 42
7722
(@value{GDBP}) print N Q M
7723
$1 = 1
7724
(@value{GDBP})
7725
@end smallexample
7726
 
7727
As we step over directives that remove @code{N}'s definition, and then
7728
give it a new definition, @value{GDBN} finds the definition (or lack
7729
thereof) in force at each point:
7730
 
7731
@smallexample
7732
(@value{GDBP}) next
7733
Hello, world!
7734
12        printf ("We're so creative.\n");
7735
(@value{GDBP}) info macro N
7736
The symbol `N' has no definition as a C/C++ preprocessor macro
7737
at /home/jimb/gdb/macros/play/sample.c:12
7738
(@value{GDBP}) next
7739
We're so creative.
7740
14        printf ("Goodbye, world!\n");
7741
(@value{GDBP}) info macro N
7742
Defined at /home/jimb/gdb/macros/play/sample.c:13
7743
#define N 1729
7744
(@value{GDBP}) macro expand N Q M
7745
expands to: 1729 < 42
7746
(@value{GDBP}) print N Q M
7747
$2 = 0
7748
(@value{GDBP})
7749
@end smallexample
7750
 
7751
 
7752
@node Tracepoints
7753
@chapter Tracepoints
7754
@c This chapter is based on the documentation written by Michael
7755
@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7756
 
7757
@cindex tracepoints
7758
In some applications, it is not feasible for the debugger to interrupt
7759
the program's execution long enough for the developer to learn
7760
anything helpful about its behavior.  If the program's correctness
7761
depends on its real-time behavior, delays introduced by a debugger
7762
might cause the program to change its behavior drastically, or perhaps
7763
fail, even when the code itself is correct.  It is useful to be able
7764
to observe the program's behavior without interrupting it.
7765
 
7766
Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7767
specify locations in the program, called @dfn{tracepoints}, and
7768
arbitrary expressions to evaluate when those tracepoints are reached.
7769
Later, using the @code{tfind} command, you can examine the values
7770
those expressions had when the program hit the tracepoints.  The
7771
expressions may also denote objects in memory---structures or arrays,
7772
for example---whose values @value{GDBN} should record; while visiting
7773
a particular tracepoint, you may inspect those objects as if they were
7774
in memory at that moment.  However, because @value{GDBN} records these
7775
values without interacting with you, it can do so quickly and
7776
unobtrusively, hopefully not disturbing the program's behavior.
7777
 
7778
The tracepoint facility is currently available only for remote
7779
targets.  @xref{Targets}.  In addition, your remote target must know
7780
how to collect trace data.  This functionality is implemented in the
7781
remote stub; however, none of the stubs distributed with @value{GDBN}
7782
support tracepoints as of this writing.  The format of the remote
7783
packets used to implement tracepoints are described in @ref{Tracepoint
7784
Packets}.
7785
 
7786
This chapter describes the tracepoint commands and features.
7787
 
7788
@menu
7789
* Set Tracepoints::
7790
* Analyze Collected Data::
7791
* Tracepoint Variables::
7792
@end menu
7793
 
7794
@node Set Tracepoints
7795
@section Commands to Set Tracepoints
7796
 
7797
Before running such a @dfn{trace experiment}, an arbitrary number of
7798
tracepoints can be set.  Like a breakpoint (@pxref{Set Breaks}), a
7799
tracepoint has a number assigned to it by @value{GDBN}.  Like with
7800
breakpoints, tracepoint numbers are successive integers starting from
7801
one.  Many of the commands associated with tracepoints take the
7802
tracepoint number as their argument, to identify which tracepoint to
7803
work on.
7804
 
7805
For each tracepoint, you can specify, in advance, some arbitrary set
7806
of data that you want the target to collect in the trace buffer when
7807
it hits that tracepoint.  The collected data can include registers,
7808
local variables, or global data.  Later, you can use @value{GDBN}
7809
commands to examine the values these data had at the time the
7810
tracepoint was hit.
7811
 
7812
This section describes commands to set tracepoints and associated
7813
conditions and actions.
7814
 
7815
@menu
7816
* Create and Delete Tracepoints::
7817
* Enable and Disable Tracepoints::
7818
* Tracepoint Passcounts::
7819
* Tracepoint Actions::
7820
* Listing Tracepoints::
7821
* Starting and Stopping Trace Experiments::
7822
@end menu
7823
 
7824
@node Create and Delete Tracepoints
7825
@subsection Create and Delete Tracepoints
7826
 
7827
@table @code
7828
@cindex set tracepoint
7829
@kindex trace
7830
@item trace
7831
The @code{trace} command is very similar to the @code{break} command.
7832
Its argument can be a source line, a function name, or an address in
7833
the target program.  @xref{Set Breaks}.  The @code{trace} command
7834
defines a tracepoint, which is a point in the target program where the
7835
debugger will briefly stop, collect some data, and then allow the
7836
program to continue.  Setting a tracepoint or changing its commands
7837
doesn't take effect until the next @code{tstart} command; thus, you
7838
cannot change the tracepoint attributes once a trace experiment is
7839
running.
7840
 
7841
Here are some examples of using the @code{trace} command:
7842
 
7843
@smallexample
7844
(@value{GDBP}) @b{trace foo.c:121}    // a source file and line number
7845
 
7846
(@value{GDBP}) @b{trace +2}           // 2 lines forward
7847
 
7848
(@value{GDBP}) @b{trace my_function}  // first source line of function
7849
 
7850
(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7851
 
7852
(@value{GDBP}) @b{trace *0x2117c4}    // an address
7853
@end smallexample
7854
 
7855
@noindent
7856
You can abbreviate @code{trace} as @code{tr}.
7857
 
7858
@vindex $tpnum
7859
@cindex last tracepoint number
7860
@cindex recent tracepoint number
7861
@cindex tracepoint number
7862
The convenience variable @code{$tpnum} records the tracepoint number
7863
of the most recently set tracepoint.
7864
 
7865
@kindex delete tracepoint
7866
@cindex tracepoint deletion
7867
@item delete tracepoint @r{[}@var{num}@r{]}
7868
Permanently delete one or more tracepoints.  With no argument, the
7869
default is to delete all tracepoints.
7870
 
7871
Examples:
7872
 
7873
@smallexample
7874
(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7875
 
7876
(@value{GDBP}) @b{delete trace}       // remove all tracepoints
7877
@end smallexample
7878
 
7879
@noindent
7880
You can abbreviate this command as @code{del tr}.
7881
@end table
7882
 
7883
@node Enable and Disable Tracepoints
7884
@subsection Enable and Disable Tracepoints
7885
 
7886
@table @code
7887
@kindex disable tracepoint
7888
@item disable tracepoint @r{[}@var{num}@r{]}
7889
Disable tracepoint @var{num}, or all tracepoints if no argument
7890
@var{num} is given.  A disabled tracepoint will have no effect during
7891
the next trace experiment, but it is not forgotten.  You can re-enable
7892
a disabled tracepoint using the @code{enable tracepoint} command.
7893
 
7894
@kindex enable tracepoint
7895
@item enable tracepoint @r{[}@var{num}@r{]}
7896
Enable tracepoint @var{num}, or all tracepoints.  The enabled
7897
tracepoints will become effective the next time a trace experiment is
7898
run.
7899
@end table
7900
 
7901
@node Tracepoint Passcounts
7902
@subsection Tracepoint Passcounts
7903
 
7904
@table @code
7905
@kindex passcount
7906
@cindex tracepoint pass count
7907
@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7908
Set the @dfn{passcount} of a tracepoint.  The passcount is a way to
7909
automatically stop a trace experiment.  If a tracepoint's passcount is
7910
@var{n}, then the trace experiment will be automatically stopped on
7911
the @var{n}'th time that tracepoint is hit.  If the tracepoint number
7912
@var{num} is not specified, the @code{passcount} command sets the
7913
passcount of the most recently defined tracepoint.  If no passcount is
7914
given, the trace experiment will run until stopped explicitly by the
7915
user.
7916
 
7917
Examples:
7918
 
7919
@smallexample
7920
(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
7921
@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
7922
 
7923
(@value{GDBP}) @b{passcount 12}  // Stop on the 12th execution of the
7924
@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
7925
(@value{GDBP}) @b{trace foo}
7926
(@value{GDBP}) @b{pass 3}
7927
(@value{GDBP}) @b{trace bar}
7928
(@value{GDBP}) @b{pass 2}
7929
(@value{GDBP}) @b{trace baz}
7930
(@value{GDBP}) @b{pass 1}        // Stop tracing when foo has been
7931
@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7932
@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7933
@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
7934
@end smallexample
7935
@end table
7936
 
7937
@node Tracepoint Actions
7938
@subsection Tracepoint Action Lists
7939
 
7940
@table @code
7941
@kindex actions
7942
@cindex tracepoint actions
7943
@item actions @r{[}@var{num}@r{]}
7944
This command will prompt for a list of actions to be taken when the
7945
tracepoint is hit.  If the tracepoint number @var{num} is not
7946
specified, this command sets the actions for the one that was most
7947
recently defined (so that you can define a tracepoint and then say
7948
@code{actions} without bothering about its number).  You specify the
7949
actions themselves on the following lines, one action at a time, and
7950
terminate the actions list with a line containing just @code{end}.  So
7951
far, the only defined actions are @code{collect} and
7952
@code{while-stepping}.
7953
 
7954
@cindex remove actions from a tracepoint
7955
To remove all actions from a tracepoint, type @samp{actions @var{num}}
7956
and follow it immediately with @samp{end}.
7957
 
7958
@smallexample
7959
(@value{GDBP}) @b{collect @var{data}} // collect some data
7960
 
7961
(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
7962
 
7963
(@value{GDBP}) @b{end}              // signals the end of actions.
7964
@end smallexample
7965
 
7966
In the following example, the action list begins with @code{collect}
7967
commands indicating the things to be collected when the tracepoint is
7968
hit.  Then, in order to single-step and collect additional data
7969
following the tracepoint, a @code{while-stepping} command is used,
7970
followed by the list of things to be collected while stepping.  The
7971
@code{while-stepping} command is terminated by its own separate
7972
@code{end} command.  Lastly, the action list is terminated by an
7973
@code{end} command.
7974
 
7975
@smallexample
7976
(@value{GDBP}) @b{trace foo}
7977
(@value{GDBP}) @b{actions}
7978
Enter actions for tracepoint 1, one per line:
7979
> collect bar,baz
7980
> collect $regs
7981
> while-stepping 12
7982
  > collect $fp, $sp
7983
  > end
7984
end
7985
@end smallexample
7986
 
7987
@kindex collect @r{(tracepoints)}
7988
@item collect @var{expr1}, @var{expr2}, @dots{}
7989
Collect values of the given expressions when the tracepoint is hit.
7990
This command accepts a comma-separated list of any valid expressions.
7991
In addition to global, static, or local variables, the following
7992
special arguments are supported:
7993
 
7994
@table @code
7995
@item $regs
7996
collect all registers
7997
 
7998
@item $args
7999
collect all function arguments
8000
 
8001
@item $locals
8002
collect all local variables.
8003
@end table
8004
 
8005
You can give several consecutive @code{collect} commands, each one
8006
with a single argument, or one @code{collect} command with several
8007
arguments separated by commas: the effect is the same.
8008
 
8009
The command @code{info scope} (@pxref{Symbols, info scope}) is
8010
particularly useful for figuring out what data to collect.
8011
 
8012
@kindex while-stepping @r{(tracepoints)}
8013
@item while-stepping @var{n}
8014
Perform @var{n} single-step traces after the tracepoint, collecting
8015
new data at each step.  The @code{while-stepping} command is
8016
followed by the list of what to collect while stepping (followed by
8017
its own @code{end} command):
8018
 
8019
@smallexample
8020
> while-stepping 12
8021
  > collect $regs, myglobal
8022
  > end
8023
>
8024
@end smallexample
8025
 
8026
@noindent
8027
You may abbreviate @code{while-stepping} as @code{ws} or
8028
@code{stepping}.
8029
@end table
8030
 
8031
@node Listing Tracepoints
8032
@subsection Listing Tracepoints
8033
 
8034
@table @code
8035
@kindex info tracepoints
8036
@kindex info tp
8037
@cindex information about tracepoints
8038
@item info tracepoints @r{[}@var{num}@r{]}
8039
Display information about the tracepoint @var{num}.  If you don't specify
8040
a tracepoint number, displays information about all the tracepoints
8041
defined so far.  For each tracepoint, the following information is
8042
shown:
8043
 
8044
@itemize @bullet
8045
@item
8046
its number
8047
@item
8048
whether it is enabled or disabled
8049
@item
8050
its address
8051
@item
8052
its passcount as given by the @code{passcount @var{n}} command
8053
@item
8054
its step count as given by the @code{while-stepping @var{n}} command
8055
@item
8056
where in the source files is the tracepoint set
8057
@item
8058
its action list as given by the @code{actions} command
8059
@end itemize
8060
 
8061
@smallexample
8062
(@value{GDBP}) @b{info trace}
8063
Num Enb Address    PassC StepC What
8064
1   y   0x002117c4 0     0     <gdb_asm>
8065
2   y   0x0020dc64 0     0     in g_test at g_test.c:1375
8066
3   y   0x0020b1f4 0     0     in get_data at ../foo.c:41
8067
(@value{GDBP})
8068
@end smallexample
8069
 
8070
@noindent
8071
This command can be abbreviated @code{info tp}.
8072
@end table
8073
 
8074
@node Starting and Stopping Trace Experiments
8075
@subsection Starting and Stopping Trace Experiments
8076
 
8077
@table @code
8078
@kindex tstart
8079
@cindex start a new trace experiment
8080
@cindex collected data discarded
8081
@item tstart
8082
This command takes no arguments.  It starts the trace experiment, and
8083
begins collecting data.  This has the side effect of discarding all
8084
the data collected in the trace buffer during the previous trace
8085
experiment.
8086
 
8087
@kindex tstop
8088
@cindex stop a running trace experiment
8089
@item tstop
8090
This command takes no arguments.  It ends the trace experiment, and
8091
stops collecting data.
8092
 
8093
@strong{Note}: a trace experiment and data collection may stop
8094
automatically if any tracepoint's passcount is reached
8095
(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
8096
 
8097
@kindex tstatus
8098
@cindex status of trace data collection
8099
@cindex trace experiment, status of
8100
@item tstatus
8101
This command displays the status of the current trace data
8102
collection.
8103
@end table
8104
 
8105
Here is an example of the commands we described so far:
8106
 
8107
@smallexample
8108
(@value{GDBP}) @b{trace gdb_c_test}
8109
(@value{GDBP}) @b{actions}
8110
Enter actions for tracepoint #1, one per line.
8111
> collect $regs,$locals,$args
8112
> while-stepping 11
8113
  > collect $regs
8114
  > end
8115
> end
8116
(@value{GDBP}) @b{tstart}
8117
        [time passes @dots{}]
8118
(@value{GDBP}) @b{tstop}
8119
@end smallexample
8120
 
8121
 
8122
@node Analyze Collected Data
8123
@section Using the Collected Data
8124
 
8125
After the tracepoint experiment ends, you use @value{GDBN} commands
8126
for examining the trace data.  The basic idea is that each tracepoint
8127
collects a trace @dfn{snapshot} every time it is hit and another
8128
snapshot every time it single-steps.  All these snapshots are
8129
consecutively numbered from zero and go into a buffer, and you can
8130
examine them later.  The way you examine them is to @dfn{focus} on a
8131
specific trace snapshot.  When the remote stub is focused on a trace
8132
snapshot, it will respond to all @value{GDBN} requests for memory and
8133
registers by reading from the buffer which belongs to that snapshot,
8134
rather than from @emph{real} memory or registers of the program being
8135
debugged.  This means that @strong{all} @value{GDBN} commands
8136
(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
8137
behave as if we were currently debugging the program state as it was
8138
when the tracepoint occurred.  Any requests for data that are not in
8139
the buffer will fail.
8140
 
8141
@menu
8142
* tfind::                       How to select a trace snapshot
8143
* tdump::                       How to display all data for a snapshot
8144
* save-tracepoints::            How to save tracepoints for a future run
8145
@end menu
8146
 
8147
@node tfind
8148
@subsection @code{tfind @var{n}}
8149
 
8150
@kindex tfind
8151
@cindex select trace snapshot
8152
@cindex find trace snapshot
8153
The basic command for selecting a trace snapshot from the buffer is
8154
@code{tfind @var{n}}, which finds trace snapshot number @var{n},
8155
counting from zero.  If no argument @var{n} is given, the next
8156
snapshot is selected.
8157
 
8158
Here are the various forms of using the @code{tfind} command.
8159
 
8160
@table @code
8161
@item tfind start
8162
Find the first snapshot in the buffer.  This is a synonym for
8163
@code{tfind 0} (since 0 is the number of the first snapshot).
8164
 
8165
@item tfind none
8166
Stop debugging trace snapshots, resume @emph{live} debugging.
8167
 
8168
@item tfind end
8169
Same as @samp{tfind none}.
8170
 
8171
@item tfind
8172
No argument means find the next trace snapshot.
8173
 
8174
@item tfind -
8175
Find the previous trace snapshot before the current one.  This permits
8176
retracing earlier steps.
8177
 
8178
@item tfind tracepoint @var{num}
8179
Find the next snapshot associated with tracepoint @var{num}.  Search
8180
proceeds forward from the last examined trace snapshot.  If no
8181
argument @var{num} is given, it means find the next snapshot collected
8182
for the same tracepoint as the current snapshot.
8183
 
8184
@item tfind pc @var{addr}
8185
Find the next snapshot associated with the value @var{addr} of the
8186
program counter.  Search proceeds forward from the last examined trace
8187
snapshot.  If no argument @var{addr} is given, it means find the next
8188
snapshot with the same value of PC as the current snapshot.
8189
 
8190
@item tfind outside @var{addr1}, @var{addr2}
8191
Find the next snapshot whose PC is outside the given range of
8192
addresses.
8193
 
8194
@item tfind range @var{addr1}, @var{addr2}
8195
Find the next snapshot whose PC is between @var{addr1} and
8196
@var{addr2}.  @c FIXME: Is the range inclusive or exclusive?
8197
 
8198
@item tfind line @r{[}@var{file}:@r{]}@var{n}
8199
Find the next snapshot associated with the source line @var{n}.  If
8200
the optional argument @var{file} is given, refer to line @var{n} in
8201
that source file.  Search proceeds forward from the last examined
8202
trace snapshot.  If no argument @var{n} is given, it means find the
8203
next line other than the one currently being examined; thus saying
8204
@code{tfind line} repeatedly can appear to have the same effect as
8205
stepping from line to line in a @emph{live} debugging session.
8206
@end table
8207
 
8208
The default arguments for the @code{tfind} commands are specifically
8209
designed to make it easy to scan through the trace buffer.  For
8210
instance, @code{tfind} with no argument selects the next trace
8211
snapshot, and @code{tfind -} with no argument selects the previous
8212
trace snapshot.  So, by giving one @code{tfind} command, and then
8213
simply hitting @key{RET} repeatedly you can examine all the trace
8214
snapshots in order.  Or, by saying @code{tfind -} and then hitting
8215
@key{RET} repeatedly you can examine the snapshots in reverse order.
8216
The @code{tfind line} command with no argument selects the snapshot
8217
for the next source line executed.  The @code{tfind pc} command with
8218
no argument selects the next snapshot with the same program counter
8219
(PC) as the current frame.  The @code{tfind tracepoint} command with
8220
no argument selects the next trace snapshot collected by the same
8221
tracepoint as the current one.
8222
 
8223
In addition to letting you scan through the trace buffer manually,
8224
these commands make it easy to construct @value{GDBN} scripts that
8225
scan through the trace buffer and print out whatever collected data
8226
you are interested in.  Thus, if we want to examine the PC, FP, and SP
8227
registers from each trace frame in the buffer, we can say this:
8228
 
8229
@smallexample
8230
(@value{GDBP}) @b{tfind start}
8231
(@value{GDBP}) @b{while ($trace_frame != -1)}
8232
> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
8233
          $trace_frame, $pc, $sp, $fp
8234
> tfind
8235
> end
8236
 
8237
Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
8238
Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
8239
Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
8240
Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
8241
Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
8242
Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
8243
Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
8244
Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
8245
Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
8246
Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
8247
Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
8248
@end smallexample
8249
 
8250
Or, if we want to examine the variable @code{X} at each source line in
8251
the buffer:
8252
 
8253
@smallexample
8254
(@value{GDBP}) @b{tfind start}
8255
(@value{GDBP}) @b{while ($trace_frame != -1)}
8256
> printf "Frame %d, X == %d\n", $trace_frame, X
8257
> tfind line
8258
> end
8259
 
8260
Frame 0, X = 1
8261
Frame 7, X = 2
8262
Frame 13, X = 255
8263
@end smallexample
8264
 
8265
@node tdump
8266
@subsection @code{tdump}
8267
@kindex tdump
8268
@cindex dump all data collected at tracepoint
8269
@cindex tracepoint data, display
8270
 
8271
This command takes no arguments.  It prints all the data collected at
8272
the current trace snapshot.
8273
 
8274
@smallexample
8275
(@value{GDBP}) @b{trace 444}
8276
(@value{GDBP}) @b{actions}
8277
Enter actions for tracepoint #2, one per line:
8278
> collect $regs, $locals, $args, gdb_long_test
8279
> end
8280
 
8281
(@value{GDBP}) @b{tstart}
8282
 
8283
(@value{GDBP}) @b{tfind line 444}
8284
#0  gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
8285
at gdb_test.c:444
8286
444        printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
8287
 
8288
(@value{GDBP}) @b{tdump}
8289
Data collected at tracepoint 2, trace frame 1:
8290
d0             0xc4aa0085       -995491707
8291
d1             0x18     24
8292
d2             0x80     128
8293
d3             0x33     51
8294
d4             0x71aea3d        119204413
8295
d5             0x22     34
8296
d6             0xe0     224
8297
d7             0x380035 3670069
8298
a0             0x19e24a 1696330
8299
a1             0x3000668        50333288
8300
a2             0x100    256
8301
a3             0x322000 3284992
8302
a4             0x3000698        50333336
8303
a5             0x1ad3cc 1758156
8304
fp             0x30bf3c 0x30bf3c
8305
sp             0x30bf34 0x30bf34
8306
ps             0x0      0
8307
pc             0x20b2c8 0x20b2c8
8308
fpcontrol      0x0      0
8309
fpstatus       0x0      0
8310
fpiaddr        0x0      0
8311
p = 0x20e5b4 "gdb-test"
8312
p1 = (void *) 0x11
8313
p2 = (void *) 0x22
8314
p3 = (void *) 0x33
8315
p4 = (void *) 0x44
8316
p5 = (void *) 0x55
8317
p6 = (void *) 0x66
8318
gdb_long_test = 17 '\021'
8319
 
8320
(@value{GDBP})
8321
@end smallexample
8322
 
8323
@node save-tracepoints
8324
@subsection @code{save-tracepoints @var{filename}}
8325
@kindex save-tracepoints
8326
@cindex save tracepoints for future sessions
8327
 
8328
This command saves all current tracepoint definitions together with
8329
their actions and passcounts, into a file @file{@var{filename}}
8330
suitable for use in a later debugging session.  To read the saved
8331
tracepoint definitions, use the @code{source} command (@pxref{Command
8332
Files}).
8333
 
8334
@node Tracepoint Variables
8335
@section Convenience Variables for Tracepoints
8336
@cindex tracepoint variables
8337
@cindex convenience variables for tracepoints
8338
 
8339
@table @code
8340
@vindex $trace_frame
8341
@item (int) $trace_frame
8342
The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
8343
snapshot is selected.
8344
 
8345
@vindex $tracepoint
8346
@item (int) $tracepoint
8347
The tracepoint for the current trace snapshot.
8348
 
8349
@vindex $trace_line
8350
@item (int) $trace_line
8351
The line number for the current trace snapshot.
8352
 
8353
@vindex $trace_file
8354
@item (char []) $trace_file
8355
The source file for the current trace snapshot.
8356
 
8357
@vindex $trace_func
8358
@item (char []) $trace_func
8359
The name of the function containing @code{$tracepoint}.
8360
@end table
8361
 
8362
Note: @code{$trace_file} is not suitable for use in @code{printf},
8363
use @code{output} instead.
8364
 
8365
Here's a simple example of using these convenience variables for
8366
stepping through all the trace snapshots and printing some of their
8367
data.
8368
 
8369
@smallexample
8370
(@value{GDBP}) @b{tfind start}
8371
 
8372
(@value{GDBP}) @b{while $trace_frame != -1}
8373
> output $trace_file
8374
> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
8375
> tfind
8376
> end
8377
@end smallexample
8378
 
8379
@node Overlays
8380
@chapter Debugging Programs That Use Overlays
8381
@cindex overlays
8382
 
8383
If your program is too large to fit completely in your target system's
8384
memory, you can sometimes use @dfn{overlays} to work around this
8385
problem.  @value{GDBN} provides some support for debugging programs that
8386
use overlays.
8387
 
8388
@menu
8389
* How Overlays Work::              A general explanation of overlays.
8390
* Overlay Commands::               Managing overlays in @value{GDBN}.
8391
* Automatic Overlay Debugging::    @value{GDBN} can find out which overlays are
8392
                                   mapped by asking the inferior.
8393
* Overlay Sample Program::         A sample program using overlays.
8394
@end menu
8395
 
8396
@node How Overlays Work
8397
@section How Overlays Work
8398
@cindex mapped overlays
8399
@cindex unmapped overlays
8400
@cindex load address, overlay's
8401
@cindex mapped address
8402
@cindex overlay area
8403
 
8404
Suppose you have a computer whose instruction address space is only 64
8405
kilobytes long, but which has much more memory which can be accessed by
8406
other means: special instructions, segment registers, or memory
8407
management hardware, for example.  Suppose further that you want to
8408
adapt a program which is larger than 64 kilobytes to run on this system.
8409
 
8410
One solution is to identify modules of your program which are relatively
8411
independent, and need not call each other directly; call these modules
8412
@dfn{overlays}.  Separate the overlays from the main program, and place
8413
their machine code in the larger memory.  Place your main program in
8414
instruction memory, but leave at least enough space there to hold the
8415
largest overlay as well.
8416
 
8417
Now, to call a function located in an overlay, you must first copy that
8418
overlay's machine code from the large memory into the space set aside
8419
for it in the instruction memory, and then jump to its entry point
8420
there.
8421
 
8422
@c NB:  In the below the mapped area's size is greater or equal to the
8423
@c size of all overlays.  This is intentional to remind the developer
8424
@c that overlays don't necessarily need to be the same size.
8425
 
8426
@smallexample
8427
@group
8428
    Data             Instruction            Larger
8429
Address Space       Address Space        Address Space
8430
+-----------+       +-----------+        +-----------+
8431
|           |       |           |        |           |
8432
+-----------+       +-----------+        +-----------+<-- overlay 1
8433
| program   |       |   main    |   .----| overlay 1 | load address
8434
| variables |       |  program  |   |    +-----------+
8435
| and heap  |       |           |   |    |           |
8436
+-----------+       |           |   |    +-----------+<-- overlay 2
8437
|           |       +-----------+   |    |           | load address
8438
+-----------+       |           |   |  .-| overlay 2 |
8439
                    |           |   |  | |           |
8440
         mapped --->+-----------+   |  | +-----------+
8441
         address    |           |   |  | |           |
8442
                    |  overlay  | <-'  | |           |
8443
                    |   area    |  <---' +-----------+<-- overlay 3
8444
                    |           | <---.  |           | load address
8445
                    +-----------+     `--| overlay 3 |
8446
                    |           |        |           |
8447
                    +-----------+        |           |
8448
                                         +-----------+
8449
                                         |           |
8450
                                         +-----------+
8451
 
8452
                    @anchor{A code overlay}A code overlay
8453
@end group
8454
@end smallexample
8455
 
8456
The diagram (@pxref{A code overlay}) shows a system with separate data
8457
and instruction address spaces.  To map an overlay, the program copies
8458
its code from the larger address space to the instruction address space.
8459
Since the overlays shown here all use the same mapped address, only one
8460
may be mapped at a time.  For a system with a single address space for
8461
data and instructions, the diagram would be similar, except that the
8462
program variables and heap would share an address space with the main
8463
program and the overlay area.
8464
 
8465
An overlay loaded into instruction memory and ready for use is called a
8466
@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
8467
instruction memory.  An overlay not present (or only partially present)
8468
in instruction memory is called @dfn{unmapped}; its @dfn{load address}
8469
is its address in the larger memory.  The mapped address is also called
8470
the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
8471
called the @dfn{load memory address}, or @dfn{LMA}.
8472
 
8473
Unfortunately, overlays are not a completely transparent way to adapt a
8474
program to limited instruction memory.  They introduce a new set of
8475
global constraints you must keep in mind as you design your program:
8476
 
8477
@itemize @bullet
8478
 
8479
@item
8480
Before calling or returning to a function in an overlay, your program
8481
must make sure that overlay is actually mapped.  Otherwise, the call or
8482
return will transfer control to the right address, but in the wrong
8483
overlay, and your program will probably crash.
8484
 
8485
@item
8486
If the process of mapping an overlay is expensive on your system, you
8487
will need to choose your overlays carefully to minimize their effect on
8488
your program's performance.
8489
 
8490
@item
8491
The executable file you load onto your system must contain each
8492
overlay's instructions, appearing at the overlay's load address, not its
8493
mapped address.  However, each overlay's instructions must be relocated
8494
and its symbols defined as if the overlay were at its mapped address.
8495
You can use GNU linker scripts to specify different load and relocation
8496
addresses for pieces of your program; see @ref{Overlay Description,,,
8497
ld.info, Using ld: the GNU linker}.
8498
 
8499
@item
8500
The procedure for loading executable files onto your system must be able
8501
to load their contents into the larger address space as well as the
8502
instruction and data spaces.
8503
 
8504
@end itemize
8505
 
8506
The overlay system described above is rather simple, and could be
8507
improved in many ways:
8508
 
8509
@itemize @bullet
8510
 
8511
@item
8512
If your system has suitable bank switch registers or memory management
8513
hardware, you could use those facilities to make an overlay's load area
8514
contents simply appear at their mapped address in instruction space.
8515
This would probably be faster than copying the overlay to its mapped
8516
area in the usual way.
8517
 
8518
@item
8519
If your overlays are small enough, you could set aside more than one
8520
overlay area, and have more than one overlay mapped at a time.
8521
 
8522
@item
8523
You can use overlays to manage data, as well as instructions.  In
8524
general, data overlays are even less transparent to your design than
8525
code overlays: whereas code overlays only require care when you call or
8526
return to functions, data overlays require care every time you access
8527
the data.  Also, if you change the contents of a data overlay, you
8528
must copy its contents back out to its load address before you can copy a
8529
different data overlay into the same mapped area.
8530
 
8531
@end itemize
8532
 
8533
 
8534
@node Overlay Commands
8535
@section Overlay Commands
8536
 
8537
To use @value{GDBN}'s overlay support, each overlay in your program must
8538
correspond to a separate section of the executable file.  The section's
8539
virtual memory address and load memory address must be the overlay's
8540
mapped and load addresses.  Identifying overlays with sections allows
8541
@value{GDBN} to determine the appropriate address of a function or
8542
variable, depending on whether the overlay is mapped or not.
8543
 
8544
@value{GDBN}'s overlay commands all start with the word @code{overlay};
8545
you can abbreviate this as @code{ov} or @code{ovly}.  The commands are:
8546
 
8547
@table @code
8548
@item overlay off
8549
@kindex overlay
8550
Disable @value{GDBN}'s overlay support.  When overlay support is
8551
disabled, @value{GDBN} assumes that all functions and variables are
8552
always present at their mapped addresses.  By default, @value{GDBN}'s
8553
overlay support is disabled.
8554
 
8555
@item overlay manual
8556
@cindex manual overlay debugging
8557
Enable @dfn{manual} overlay debugging.  In this mode, @value{GDBN}
8558
relies on you to tell it which overlays are mapped, and which are not,
8559
using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
8560
commands described below.
8561
 
8562
@item overlay map-overlay @var{overlay}
8563
@itemx overlay map @var{overlay}
8564
@cindex map an overlay
8565
Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
8566
be the name of the object file section containing the overlay.  When an
8567
overlay is mapped, @value{GDBN} assumes it can find the overlay's
8568
functions and variables at their mapped addresses.  @value{GDBN} assumes
8569
that any other overlays whose mapped ranges overlap that of
8570
@var{overlay} are now unmapped.
8571
 
8572
@item overlay unmap-overlay @var{overlay}
8573
@itemx overlay unmap @var{overlay}
8574
@cindex unmap an overlay
8575
Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
8576
must be the name of the object file section containing the overlay.
8577
When an overlay is unmapped, @value{GDBN} assumes it can find the
8578
overlay's functions and variables at their load addresses.
8579
 
8580
@item overlay auto
8581
Enable @dfn{automatic} overlay debugging.  In this mode, @value{GDBN}
8582
consults a data structure the overlay manager maintains in the inferior
8583
to see which overlays are mapped.  For details, see @ref{Automatic
8584
Overlay Debugging}.
8585
 
8586
@item overlay load-target
8587
@itemx overlay load
8588
@cindex reloading the overlay table
8589
Re-read the overlay table from the inferior.  Normally, @value{GDBN}
8590
re-reads the table @value{GDBN} automatically each time the inferior
8591
stops, so this command should only be necessary if you have changed the
8592
overlay mapping yourself using @value{GDBN}.  This command is only
8593
useful when using automatic overlay debugging.
8594
 
8595
@item overlay list-overlays
8596
@itemx overlay list
8597
@cindex listing mapped overlays
8598
Display a list of the overlays currently mapped, along with their mapped
8599
addresses, load addresses, and sizes.
8600
 
8601
@end table
8602
 
8603
Normally, when @value{GDBN} prints a code address, it includes the name
8604
of the function the address falls in:
8605
 
8606
@smallexample
8607
(@value{GDBP}) print main
8608
$3 = @{int ()@} 0x11a0 <main>
8609
@end smallexample
8610
@noindent
8611
When overlay debugging is enabled, @value{GDBN} recognizes code in
8612
unmapped overlays, and prints the names of unmapped functions with
8613
asterisks around them.  For example, if @code{foo} is a function in an
8614
unmapped overlay, @value{GDBN} prints it this way:
8615
 
8616
@smallexample
8617
(@value{GDBP}) overlay list
8618
No sections are mapped.
8619
(@value{GDBP}) print foo
8620
$5 = @{int (int)@} 0x100000 <*foo*>
8621
@end smallexample
8622
@noindent
8623
When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
8624
name normally:
8625
 
8626
@smallexample
8627
(@value{GDBP}) overlay list
8628
Section .ov.foo.text, loaded at 0x100000 - 0x100034,
8629
        mapped at 0x1016 - 0x104a
8630
(@value{GDBP}) print foo
8631
$6 = @{int (int)@} 0x1016 <foo>
8632
@end smallexample
8633
 
8634
When overlay debugging is enabled, @value{GDBN} can find the correct
8635
address for functions and variables in an overlay, whether or not the
8636
overlay is mapped.  This allows most @value{GDBN} commands, like
8637
@code{break} and @code{disassemble}, to work normally, even on unmapped
8638
code.  However, @value{GDBN}'s breakpoint support has some limitations:
8639
 
8640
@itemize @bullet
8641
@item
8642
@cindex breakpoints in overlays
8643
@cindex overlays, setting breakpoints in
8644
You can set breakpoints in functions in unmapped overlays, as long as
8645
@value{GDBN} can write to the overlay at its load address.
8646
@item
8647
@value{GDBN} can not set hardware or simulator-based breakpoints in
8648
unmapped overlays.  However, if you set a breakpoint at the end of your
8649
overlay manager (and tell @value{GDBN} which overlays are now mapped, if
8650
you are using manual overlay management), @value{GDBN} will re-set its
8651
breakpoints properly.
8652
@end itemize
8653
 
8654
 
8655
@node Automatic Overlay Debugging
8656
@section Automatic Overlay Debugging
8657
@cindex automatic overlay debugging
8658
 
8659
@value{GDBN} can automatically track which overlays are mapped and which
8660
are not, given some simple co-operation from the overlay manager in the
8661
inferior.  If you enable automatic overlay debugging with the
8662
@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
8663
looks in the inferior's memory for certain variables describing the
8664
current state of the overlays.
8665
 
8666
Here are the variables your overlay manager must define to support
8667
@value{GDBN}'s automatic overlay debugging:
8668
 
8669
@table @asis
8670
 
8671
@item @code{_ovly_table}:
8672
This variable must be an array of the following structures:
8673
 
8674
@smallexample
8675
struct
8676
@{
8677
  /* The overlay's mapped address.  */
8678
  unsigned long vma;
8679
 
8680
  /* The size of the overlay, in bytes.  */
8681
  unsigned long size;
8682
 
8683
  /* The overlay's load address.  */
8684
  unsigned long lma;
8685
 
8686
  /* Non-zero if the overlay is currently mapped;
8687
     zero otherwise.  */
8688
  unsigned long mapped;
8689
@}
8690
@end smallexample
8691
 
8692
@item @code{_novlys}:
8693
This variable must be a four-byte signed integer, holding the total
8694
number of elements in @code{_ovly_table}.
8695
 
8696
@end table
8697
 
8698
To decide whether a particular overlay is mapped or not, @value{GDBN}
8699
looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8700
@code{lma} members equal the VMA and LMA of the overlay's section in the
8701
executable file.  When @value{GDBN} finds a matching entry, it consults
8702
the entry's @code{mapped} member to determine whether the overlay is
8703
currently mapped.
8704
 
8705
In addition, your overlay manager may define a function called
8706
@code{_ovly_debug_event}.  If this function is defined, @value{GDBN}
8707
will silently set a breakpoint there.  If the overlay manager then
8708
calls this function whenever it has changed the overlay table, this
8709
will enable @value{GDBN} to accurately keep track of which overlays
8710
are in program memory, and update any breakpoints that may be set
8711
in overlays.  This will allow breakpoints to work even if the
8712
overlays are kept in ROM or other non-writable memory while they
8713
are not being executed.
8714
 
8715
@node Overlay Sample Program
8716
@section Overlay Sample Program
8717
@cindex overlay example program
8718
 
8719
When linking a program which uses overlays, you must place the overlays
8720
at their load addresses, while relocating them to run at their mapped
8721
addresses.  To do this, you must write a linker script (@pxref{Overlay
8722
Description,,, ld.info, Using ld: the GNU linker}).  Unfortunately,
8723
since linker scripts are specific to a particular host system, target
8724
architecture, and target memory layout, this manual cannot provide
8725
portable sample code demonstrating @value{GDBN}'s overlay support.
8726
 
8727
However, the @value{GDBN} source distribution does contain an overlaid
8728
program, with linker scripts for a few systems, as part of its test
8729
suite.  The program consists of the following files from
8730
@file{gdb/testsuite/gdb.base}:
8731
 
8732
@table @file
8733
@item overlays.c
8734
The main program file.
8735
@item ovlymgr.c
8736
A simple overlay manager, used by @file{overlays.c}.
8737
@item foo.c
8738
@itemx bar.c
8739
@itemx baz.c
8740
@itemx grbx.c
8741
Overlay modules, loaded and used by @file{overlays.c}.
8742
@item d10v.ld
8743
@itemx m32r.ld
8744
Linker scripts for linking the test program on the @code{d10v-elf}
8745
and @code{m32r-elf} targets.
8746
@end table
8747
 
8748
You can build the test program using the @code{d10v-elf} GCC
8749
cross-compiler like this:
8750
 
8751
@smallexample
8752
$ d10v-elf-gcc -g -c overlays.c
8753
$ d10v-elf-gcc -g -c ovlymgr.c
8754
$ d10v-elf-gcc -g -c foo.c
8755
$ d10v-elf-gcc -g -c bar.c
8756
$ d10v-elf-gcc -g -c baz.c
8757
$ d10v-elf-gcc -g -c grbx.c
8758
$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8759
                  baz.o grbx.o -Wl,-Td10v.ld -o overlays
8760
@end smallexample
8761
 
8762
The build process is identical for any other architecture, except that
8763
you must substitute the appropriate compiler and linker script for the
8764
target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8765
 
8766
 
8767
@node Languages
8768
@chapter Using @value{GDBN} with Different Languages
8769
@cindex languages
8770
 
8771
Although programming languages generally have common aspects, they are
8772
rarely expressed in the same manner.  For instance, in ANSI C,
8773
dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8774
Modula-2, it is accomplished by @code{p^}.  Values can also be
8775
represented (and displayed) differently.  Hex numbers in C appear as
8776
@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
8777
 
8778
@cindex working language
8779
Language-specific information is built into @value{GDBN} for some languages,
8780
allowing you to express operations like the above in your program's
8781
native language, and allowing @value{GDBN} to output values in a manner
8782
consistent with the syntax of your program's native language.  The
8783
language you use to build expressions is called the @dfn{working
8784
language}.
8785
 
8786
@menu
8787
* Setting::                     Switching between source languages
8788
* Show::                        Displaying the language
8789
* Checks::                      Type and range checks
8790
* Supported Languages::         Supported languages
8791
* Unsupported Languages::       Unsupported languages
8792
@end menu
8793
 
8794
@node Setting
8795
@section Switching Between Source Languages
8796
 
8797
There are two ways to control the working language---either have @value{GDBN}
8798
set it automatically, or select it manually yourself.  You can use the
8799
@code{set language} command for either purpose.  On startup, @value{GDBN}
8800
defaults to setting the language automatically.  The working language is
8801
used to determine how expressions you type are interpreted, how values
8802
are printed, etc.
8803
 
8804
In addition to the working language, every source file that
8805
@value{GDBN} knows about has its own working language.  For some object
8806
file formats, the compiler might indicate which language a particular
8807
source file is in.  However, most of the time @value{GDBN} infers the
8808
language from the name of the file.  The language of a source file
8809
controls whether C@t{++} names are demangled---this way @code{backtrace} can
8810
show each frame appropriately for its own language.  There is no way to
8811
set the language of a source file from within @value{GDBN}, but you can
8812
set the language associated with a filename extension.  @xref{Show, ,
8813
Displaying the Language}.
8814
 
8815
This is most commonly a problem when you use a program, such
8816
as @code{cfront} or @code{f2c}, that generates C but is written in
8817
another language.  In that case, make the
8818
program use @code{#line} directives in its C output; that way
8819
@value{GDBN} will know the correct language of the source code of the original
8820
program, and will display that source code, not the generated C code.
8821
 
8822
@menu
8823
* Filenames::                   Filename extensions and languages.
8824
* Manually::                    Setting the working language manually
8825
* Automatically::               Having @value{GDBN} infer the source language
8826
@end menu
8827
 
8828
@node Filenames
8829
@subsection List of Filename Extensions and Languages
8830
 
8831
If a source file name ends in one of the following extensions, then
8832
@value{GDBN} infers that its language is the one indicated.
8833
 
8834
@table @file
8835
@item .ada
8836
@itemx .ads
8837
@itemx .adb
8838
@itemx .a
8839
Ada source file.
8840
 
8841
@item .c
8842
C source file
8843
 
8844
@item .C
8845
@itemx .cc
8846
@itemx .cp
8847
@itemx .cpp
8848
@itemx .cxx
8849
@itemx .c++
8850
C@t{++} source file
8851
 
8852
@item .m
8853
Objective-C source file
8854
 
8855
@item .f
8856
@itemx .F
8857
Fortran source file
8858
 
8859
@item .mod
8860
Modula-2 source file
8861
 
8862
@item .s
8863
@itemx .S
8864
Assembler source file.  This actually behaves almost like C, but
8865
@value{GDBN} does not skip over function prologues when stepping.
8866
@end table
8867
 
8868
In addition, you may set the language associated with a filename
8869
extension.  @xref{Show, , Displaying the Language}.
8870
 
8871
@node Manually
8872
@subsection Setting the Working Language
8873
 
8874
If you allow @value{GDBN} to set the language automatically,
8875
expressions are interpreted the same way in your debugging session and
8876
your program.
8877
 
8878
@kindex set language
8879
If you wish, you may set the language manually.  To do this, issue the
8880
command @samp{set language @var{lang}}, where @var{lang} is the name of
8881
a language, such as
8882
@code{c} or @code{modula-2}.
8883
For a list of the supported languages, type @samp{set language}.
8884
 
8885
Setting the language manually prevents @value{GDBN} from updating the working
8886
language automatically.  This can lead to confusion if you try
8887
to debug a program when the working language is not the same as the
8888
source language, when an expression is acceptable to both
8889
languages---but means different things.  For instance, if the current
8890
source file were written in C, and @value{GDBN} was parsing Modula-2, a
8891
command such as:
8892
 
8893
@smallexample
8894
print a = b + c
8895
@end smallexample
8896
 
8897
@noindent
8898
might not have the effect you intended.  In C, this means to add
8899
@code{b} and @code{c} and place the result in @code{a}.  The result
8900
printed would be the value of @code{a}.  In Modula-2, this means to compare
8901
@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
8902
 
8903
@node Automatically
8904
@subsection Having @value{GDBN} Infer the Source Language
8905
 
8906
To have @value{GDBN} set the working language automatically, use
8907
@samp{set language local} or @samp{set language auto}.  @value{GDBN}
8908
then infers the working language.  That is, when your program stops in a
8909
frame (usually by encountering a breakpoint), @value{GDBN} sets the
8910
working language to the language recorded for the function in that
8911
frame.  If the language for a frame is unknown (that is, if the function
8912
or block corresponding to the frame was defined in a source file that
8913
does not have a recognized extension), the current working language is
8914
not changed, and @value{GDBN} issues a warning.
8915
 
8916
This may not seem necessary for most programs, which are written
8917
entirely in one source language.  However, program modules and libraries
8918
written in one source language can be used by a main program written in
8919
a different source language.  Using @samp{set language auto} in this
8920
case frees you from having to set the working language manually.
8921
 
8922
@node Show
8923
@section Displaying the Language
8924
 
8925
The following commands help you find out which language is the
8926
working language, and also what language source files were written in.
8927
 
8928
@table @code
8929
@item show language
8930
@kindex show language
8931
Display the current working language.  This is the
8932
language you can use with commands such as @code{print} to
8933
build and compute expressions that may involve variables in your program.
8934
 
8935
@item info frame
8936
@kindex info frame@r{, show the source language}
8937
Display the source language for this frame.  This language becomes the
8938
working language if you use an identifier from this frame.
8939
@xref{Frame Info, ,Information about a Frame}, to identify the other
8940
information listed here.
8941
 
8942
@item info source
8943
@kindex info source@r{, show the source language}
8944
Display the source language of this source file.
8945
@xref{Symbols, ,Examining the Symbol Table}, to identify the other
8946
information listed here.
8947
@end table
8948
 
8949
In unusual circumstances, you may have source files with extensions
8950
not in the standard list.  You can then set the extension associated
8951
with a language explicitly:
8952
 
8953
@table @code
8954
@item set extension-language @var{ext} @var{language}
8955
@kindex set extension-language
8956
Tell @value{GDBN} that source files with extension @var{ext} are to be
8957
assumed as written in the source language @var{language}.
8958
 
8959
@item info extensions
8960
@kindex info extensions
8961
List all the filename extensions and the associated languages.
8962
@end table
8963
 
8964
@node Checks
8965
@section Type and Range Checking
8966
 
8967
@quotation
8968
@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8969
checking are included, but they do not yet have any effect.  This
8970
section documents the intended facilities.
8971
@end quotation
8972
@c FIXME remove warning when type/range code added
8973
 
8974
Some languages are designed to guard you against making seemingly common
8975
errors through a series of compile- and run-time checks.  These include
8976
checking the type of arguments to functions and operators, and making
8977
sure mathematical overflows are caught at run time.  Checks such as
8978
these help to ensure a program's correctness once it has been compiled
8979
by eliminating type mismatches, and providing active checks for range
8980
errors when your program is running.
8981
 
8982
@value{GDBN} can check for conditions like the above if you wish.
8983
Although @value{GDBN} does not check the statements in your program,
8984
it can check expressions entered directly into @value{GDBN} for
8985
evaluation via the @code{print} command, for example.  As with the
8986
working language, @value{GDBN} can also decide whether or not to check
8987
automatically based on your program's source language.
8988
@xref{Supported Languages, ,Supported Languages}, for the default
8989
settings of supported languages.
8990
 
8991
@menu
8992
* Type Checking::               An overview of type checking
8993
* Range Checking::              An overview of range checking
8994
@end menu
8995
 
8996
@cindex type checking
8997
@cindex checks, type
8998
@node Type Checking
8999
@subsection An Overview of Type Checking
9000
 
9001
Some languages, such as Modula-2, are strongly typed, meaning that the
9002
arguments to operators and functions have to be of the correct type,
9003
otherwise an error occurs.  These checks prevent type mismatch
9004
errors from ever causing any run-time problems.  For example,
9005
 
9006
@smallexample
9007
1 + 2 @result{} 3
9008
@exdent but
9009
@error{} 1 + 2.3
9010
@end smallexample
9011
 
9012
The second example fails because the @code{CARDINAL} 1 is not
9013
type-compatible with the @code{REAL} 2.3.
9014
 
9015
For the expressions you use in @value{GDBN} commands, you can tell the
9016
@value{GDBN} type checker to skip checking;
9017
to treat any mismatches as errors and abandon the expression;
9018
or to only issue warnings when type mismatches occur,
9019
but evaluate the expression anyway.  When you choose the last of
9020
these, @value{GDBN} evaluates expressions like the second example above, but
9021
also issues a warning.
9022
 
9023
Even if you turn type checking off, there may be other reasons
9024
related to type that prevent @value{GDBN} from evaluating an expression.
9025
For instance, @value{GDBN} does not know how to add an @code{int} and
9026
a @code{struct foo}.  These particular type errors have nothing to do
9027
with the language in use, and usually arise from expressions, such as
9028
the one described above, which make little sense to evaluate anyway.
9029
 
9030
Each language defines to what degree it is strict about type.  For
9031
instance, both Modula-2 and C require the arguments to arithmetical
9032
operators to be numbers.  In C, enumerated types and pointers can be
9033
represented as numbers, so that they are valid arguments to mathematical
9034
operators.  @xref{Supported Languages, ,Supported Languages}, for further
9035
details on specific languages.
9036
 
9037
@value{GDBN} provides some additional commands for controlling the type checker:
9038
 
9039
@kindex set check type
9040
@kindex show check type
9041
@table @code
9042
@item set check type auto
9043
Set type checking on or off based on the current working language.
9044
@xref{Supported Languages, ,Supported Languages}, for the default settings for
9045
each language.
9046
 
9047
@item set check type on
9048
@itemx set check type off
9049
Set type checking on or off, overriding the default setting for the
9050
current working language.  Issue a warning if the setting does not
9051
match the language default.  If any type mismatches occur in
9052
evaluating an expression while type checking is on, @value{GDBN} prints a
9053
message and aborts evaluation of the expression.
9054
 
9055
@item set check type warn
9056
Cause the type checker to issue warnings, but to always attempt to
9057
evaluate the expression.  Evaluating the expression may still
9058
be impossible for other reasons.  For example, @value{GDBN} cannot add
9059
numbers and structures.
9060
 
9061
@item show type
9062
Show the current setting of the type checker, and whether or not @value{GDBN}
9063
is setting it automatically.
9064
@end table
9065
 
9066
@cindex range checking
9067
@cindex checks, range
9068
@node Range Checking
9069
@subsection An Overview of Range Checking
9070
 
9071
In some languages (such as Modula-2), it is an error to exceed the
9072
bounds of a type; this is enforced with run-time checks.  Such range
9073
checking is meant to ensure program correctness by making sure
9074
computations do not overflow, or indices on an array element access do
9075
not exceed the bounds of the array.
9076
 
9077
For expressions you use in @value{GDBN} commands, you can tell
9078
@value{GDBN} to treat range errors in one of three ways: ignore them,
9079
always treat them as errors and abandon the expression, or issue
9080
warnings but evaluate the expression anyway.
9081
 
9082
A range error can result from numerical overflow, from exceeding an
9083
array index bound, or when you type a constant that is not a member
9084
of any type.  Some languages, however, do not treat overflows as an
9085
error.  In many implementations of C, mathematical overflow causes the
9086
result to ``wrap around'' to lower values---for example, if @var{m} is
9087
the largest integer value, and @var{s} is the smallest, then
9088
 
9089
@smallexample
9090
@var{m} + 1 @result{} @var{s}
9091
@end smallexample
9092
 
9093
This, too, is specific to individual languages, and in some cases
9094
specific to individual compilers or machines.  @xref{Supported Languages, ,
9095
Supported Languages}, for further details on specific languages.
9096
 
9097
@value{GDBN} provides some additional commands for controlling the range checker:
9098
 
9099
@kindex set check range
9100
@kindex show check range
9101
@table @code
9102
@item set check range auto
9103
Set range checking on or off based on the current working language.
9104
@xref{Supported Languages, ,Supported Languages}, for the default settings for
9105
each language.
9106
 
9107
@item set check range on
9108
@itemx set check range off
9109
Set range checking on or off, overriding the default setting for the
9110
current working language.  A warning is issued if the setting does not
9111
match the language default.  If a range error occurs and range checking is on,
9112
then a message is printed and evaluation of the expression is aborted.
9113
 
9114
@item set check range warn
9115
Output messages when the @value{GDBN} range checker detects a range error,
9116
but attempt to evaluate the expression anyway.  Evaluating the
9117
expression may still be impossible for other reasons, such as accessing
9118
memory that the process does not own (a typical example from many Unix
9119
systems).
9120
 
9121
@item show range
9122
Show the current setting of the range checker, and whether or not it is
9123
being set automatically by @value{GDBN}.
9124
@end table
9125
 
9126
@node Supported Languages
9127
@section Supported Languages
9128
 
9129
@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
9130
assembly, Modula-2, and Ada.
9131
@c This is false ...
9132
Some @value{GDBN} features may be used in expressions regardless of the
9133
language you use: the @value{GDBN} @code{@@} and @code{::} operators,
9134
and the @samp{@{type@}addr} construct (@pxref{Expressions,
9135
,Expressions}) can be used with the constructs of any supported
9136
language.
9137
 
9138
The following sections detail to what degree each source language is
9139
supported by @value{GDBN}.  These sections are not meant to be language
9140
tutorials or references, but serve only as a reference guide to what the
9141
@value{GDBN} expression parser accepts, and what input and output
9142
formats should look like for different languages.  There are many good
9143
books written on each of these languages; please look to these for a
9144
language reference or tutorial.
9145
 
9146
@menu
9147
* C::                           C and C@t{++}
9148
* Objective-C::                 Objective-C
9149
* Fortran::                     Fortran
9150
* Pascal::                      Pascal
9151
* Modula-2::                    Modula-2
9152
* Ada::                         Ada
9153
@end menu
9154
 
9155
@node C
9156
@subsection C and C@t{++}
9157
 
9158
@cindex C and C@t{++}
9159
@cindex expressions in C or C@t{++}
9160
 
9161
Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
9162
to both languages.  Whenever this is the case, we discuss those languages
9163
together.
9164
 
9165
@cindex C@t{++}
9166
@cindex @code{g++}, @sc{gnu} C@t{++} compiler
9167
@cindex @sc{gnu} C@t{++}
9168
The C@t{++} debugging facilities are jointly implemented by the C@t{++}
9169
compiler and @value{GDBN}.  Therefore, to debug your C@t{++} code
9170
effectively, you must compile your C@t{++} programs with a supported
9171
C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
9172
compiler (@code{aCC}).
9173
 
9174
For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
9175
format; if it doesn't work on your system, try the stabs+ debugging
9176
format.  You can select those formats explicitly with the @code{g++}
9177
command-line options @option{-gdwarf-2} and @option{-gstabs+}.
9178
@xref{Debugging Options,,Options for Debugging Your Program or GCC,
9179
gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}.
9180
 
9181
@menu
9182
* C Operators::                 C and C@t{++} operators
9183
* C Constants::                 C and C@t{++} constants
9184
* C Plus Plus Expressions::     C@t{++} expressions
9185
* C Defaults::                  Default settings for C and C@t{++}
9186
* C Checks::                    C and C@t{++} type and range checks
9187
* Debugging C::                 @value{GDBN} and C
9188
* Debugging C Plus Plus::       @value{GDBN} features for C@t{++}
9189
* Decimal Floating Point::      Numbers in Decimal Floating Point format
9190
@end menu
9191
 
9192
@node C Operators
9193
@subsubsection C and C@t{++} Operators
9194
 
9195
@cindex C and C@t{++} operators
9196
 
9197
Operators must be defined on values of specific types.  For instance,
9198
@code{+} is defined on numbers, but not on structures.  Operators are
9199
often defined on groups of types.
9200
 
9201
For the purposes of C and C@t{++}, the following definitions hold:
9202
 
9203
@itemize @bullet
9204
 
9205
@item
9206
@emph{Integral types} include @code{int} with any of its storage-class
9207
specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
9208
 
9209
@item
9210
@emph{Floating-point types} include @code{float}, @code{double}, and
9211
@code{long double} (if supported by the target platform).
9212
 
9213
@item
9214
@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
9215
 
9216
@item
9217
@emph{Scalar types} include all of the above.
9218
 
9219
@end itemize
9220
 
9221
@noindent
9222
The following operators are supported.  They are listed here
9223
in order of increasing precedence:
9224
 
9225
@table @code
9226
@item ,
9227
The comma or sequencing operator.  Expressions in a comma-separated list
9228
are evaluated from left to right, with the result of the entire
9229
expression being the last expression evaluated.
9230
 
9231
@item =
9232
Assignment.  The value of an assignment expression is the value
9233
assigned.  Defined on scalar types.
9234
 
9235
@item @var{op}=
9236
Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
9237
and translated to @w{@code{@var{a} = @var{a op b}}}.
9238
@w{@code{@var{op}=}} and @code{=} have the same precedence.
9239
@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
9240
@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
9241
 
9242
@item ?:
9243
The ternary operator.  @code{@var{a} ? @var{b} : @var{c}} can be thought
9244
of as:  if @var{a} then @var{b} else @var{c}.  @var{a} should be of an
9245
integral type.
9246
 
9247
@item ||
9248
Logical @sc{or}.  Defined on integral types.
9249
 
9250
@item &&
9251
Logical @sc{and}.  Defined on integral types.
9252
 
9253
@item |
9254
Bitwise @sc{or}.  Defined on integral types.
9255
 
9256
@item ^
9257
Bitwise exclusive-@sc{or}.  Defined on integral types.
9258
 
9259
@item &
9260
Bitwise @sc{and}.  Defined on integral types.
9261
 
9262
@item ==@r{, }!=
9263
Equality and inequality.  Defined on scalar types.  The value of these
9264
expressions is 0 for false and non-zero for true.
9265
 
9266
@item <@r{, }>@r{, }<=@r{, }>=
9267
Less than, greater than, less than or equal, greater than or equal.
9268
Defined on scalar types.  The value of these expressions is 0 for false
9269
and non-zero for true.
9270
 
9271
@item <<@r{, }>>
9272
left shift, and right shift.  Defined on integral types.
9273
 
9274
@item @@
9275
The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9276
 
9277
@item +@r{, }-
9278
Addition and subtraction.  Defined on integral types, floating-point types and
9279
pointer types.
9280
 
9281
@item *@r{, }/@r{, }%
9282
Multiplication, division, and modulus.  Multiplication and division are
9283
defined on integral and floating-point types.  Modulus is defined on
9284
integral types.
9285
 
9286
@item ++@r{, }--
9287
Increment and decrement.  When appearing before a variable, the
9288
operation is performed before the variable is used in an expression;
9289
when appearing after it, the variable's value is used before the
9290
operation takes place.
9291
 
9292
@item *
9293
Pointer dereferencing.  Defined on pointer types.  Same precedence as
9294
@code{++}.
9295
 
9296
@item &
9297
Address operator.  Defined on variables.  Same precedence as @code{++}.
9298
 
9299
For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
9300
allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
9301
to examine the address
9302
where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
9303
stored.
9304
 
9305
@item -
9306
Negative.  Defined on integral and floating-point types.  Same
9307
precedence as @code{++}.
9308
 
9309
@item !
9310
Logical negation.  Defined on integral types.  Same precedence as
9311
@code{++}.
9312
 
9313
@item ~
9314
Bitwise complement operator.  Defined on integral types.  Same precedence as
9315
@code{++}.
9316
 
9317
 
9318
@item .@r{, }->
9319
Structure member, and pointer-to-structure member.  For convenience,
9320
@value{GDBN} regards the two as equivalent, choosing whether to dereference a
9321
pointer based on the stored type information.
9322
Defined on @code{struct} and @code{union} data.
9323
 
9324
@item .*@r{, }->*
9325
Dereferences of pointers to members.
9326
 
9327
@item []
9328
Array indexing.  @code{@var{a}[@var{i}]} is defined as
9329
@code{*(@var{a}+@var{i})}.  Same precedence as @code{->}.
9330
 
9331
@item ()
9332
Function parameter list.  Same precedence as @code{->}.
9333
 
9334
@item ::
9335
C@t{++} scope resolution operator.  Defined on @code{struct}, @code{union},
9336
and @code{class} types.
9337
 
9338
@item ::
9339
Doubled colons also represent the @value{GDBN} scope operator
9340
(@pxref{Expressions, ,Expressions}).  Same precedence as @code{::},
9341
above.
9342
@end table
9343
 
9344
If an operator is redefined in the user code, @value{GDBN} usually
9345
attempts to invoke the redefined version instead of using the operator's
9346
predefined meaning.
9347
 
9348
@node C Constants
9349
@subsubsection C and C@t{++} Constants
9350
 
9351
@cindex C and C@t{++} constants
9352
 
9353
@value{GDBN} allows you to express the constants of C and C@t{++} in the
9354
following ways:
9355
 
9356
@itemize @bullet
9357
@item
9358
Integer constants are a sequence of digits.  Octal constants are
9359
specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
9360
by a leading @samp{0x} or @samp{0X}.  Constants may also end with a letter
9361
@samp{l}, specifying that the constant should be treated as a
9362
@code{long} value.
9363
 
9364
@item
9365
Floating point constants are a sequence of digits, followed by a decimal
9366
point, followed by a sequence of digits, and optionally followed by an
9367
exponent.  An exponent is of the form:
9368
@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
9369
sequence of digits.  The @samp{+} is optional for positive exponents.
9370
A floating-point constant may also end with a letter @samp{f} or
9371
@samp{F}, specifying that the constant should be treated as being of
9372
the @code{float} (as opposed to the default @code{double}) type; or with
9373
a letter @samp{l} or @samp{L}, which specifies a @code{long double}
9374
constant.
9375
 
9376
@item
9377
Enumerated constants consist of enumerated identifiers, or their
9378
integral equivalents.
9379
 
9380
@item
9381
Character constants are a single character surrounded by single quotes
9382
(@code{'}), or a number---the ordinal value of the corresponding character
9383
(usually its @sc{ascii} value).  Within quotes, the single character may
9384
be represented by a letter or by @dfn{escape sequences}, which are of
9385
the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
9386
of the character's ordinal value; or of the form @samp{\@var{x}}, where
9387
@samp{@var{x}} is a predefined special character---for example,
9388
@samp{\n} for newline.
9389
 
9390
@item
9391
String constants are a sequence of character constants surrounded by
9392
double quotes (@code{"}).  Any valid character constant (as described
9393
above) may appear.  Double quotes within the string must be preceded by
9394
a backslash, so for instance @samp{"a\"b'c"} is a string of five
9395
characters.
9396
 
9397
@item
9398
Pointer constants are an integral value.  You can also write pointers
9399
to constants using the C operator @samp{&}.
9400
 
9401
@item
9402
Array constants are comma-separated lists surrounded by braces @samp{@{}
9403
and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
9404
integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
9405
and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
9406
@end itemize
9407
 
9408
@node C Plus Plus Expressions
9409
@subsubsection C@t{++} Expressions
9410
 
9411
@cindex expressions in C@t{++}
9412
@value{GDBN} expression handling can interpret most C@t{++} expressions.
9413
 
9414
@cindex debugging C@t{++} programs
9415
@cindex C@t{++} compilers
9416
@cindex debug formats and C@t{++}
9417
@cindex @value{NGCC} and C@t{++}
9418
@quotation
9419
@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
9420
proper compiler and the proper debug format.  Currently, @value{GDBN}
9421
works best when debugging C@t{++} code that is compiled with
9422
@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
9423
@option{-gdwarf-2} or @option{-gstabs+}.  DWARF 2 is preferred over
9424
stabs+.  Most configurations of @value{NGCC} emit either DWARF 2 or
9425
stabs+ as their default debug format, so you usually don't need to
9426
specify a debug format explicitly.  Other compilers and/or debug formats
9427
are likely to work badly or not at all when using @value{GDBN} to debug
9428
C@t{++} code.
9429
@end quotation
9430
 
9431
@enumerate
9432
 
9433
@cindex member functions
9434
@item
9435
Member function calls are allowed; you can use expressions like
9436
 
9437
@smallexample
9438
count = aml->GetOriginal(x, y)
9439
@end smallexample
9440
 
9441
@vindex this@r{, inside C@t{++} member functions}
9442
@cindex namespace in C@t{++}
9443
@item
9444
While a member function is active (in the selected stack frame), your
9445
expressions have the same namespace available as the member function;
9446
that is, @value{GDBN} allows implicit references to the class instance
9447
pointer @code{this} following the same rules as C@t{++}.
9448
 
9449
@cindex call overloaded functions
9450
@cindex overloaded functions, calling
9451
@cindex type conversions in C@t{++}
9452
@item
9453
You can call overloaded functions; @value{GDBN} resolves the function
9454
call to the right definition, with some restrictions.  @value{GDBN} does not
9455
perform overload resolution involving user-defined type conversions,
9456
calls to constructors, or instantiations of templates that do not exist
9457
in the program.  It also cannot handle ellipsis argument lists or
9458
default arguments.
9459
 
9460
It does perform integral conversions and promotions, floating-point
9461
promotions, arithmetic conversions, pointer conversions, conversions of
9462
class objects to base classes, and standard conversions such as those of
9463
functions or arrays to pointers; it requires an exact match on the
9464
number of function arguments.
9465
 
9466
Overload resolution is always performed, unless you have specified
9467
@code{set overload-resolution off}.  @xref{Debugging C Plus Plus,
9468
,@value{GDBN} Features for C@t{++}}.
9469
 
9470
You must specify @code{set overload-resolution off} in order to use an
9471
explicit function signature to call an overloaded function, as in
9472
@smallexample
9473
p 'foo(char,int)'('x', 13)
9474
@end smallexample
9475
 
9476
The @value{GDBN} command-completion facility can simplify this;
9477
see @ref{Completion, ,Command Completion}.
9478
 
9479
@cindex reference declarations
9480
@item
9481
@value{GDBN} understands variables declared as C@t{++} references; you can use
9482
them in expressions just as you do in C@t{++} source---they are automatically
9483
dereferenced.
9484
 
9485
In the parameter list shown when @value{GDBN} displays a frame, the values of
9486
reference variables are not displayed (unlike other variables); this
9487
avoids clutter, since references are often used for large structures.
9488
The @emph{address} of a reference variable is always shown, unless
9489
you have specified @samp{set print address off}.
9490
 
9491
@item
9492
@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
9493
expressions can use it just as expressions in your program do.  Since
9494
one scope may be defined in another, you can use @code{::} repeatedly if
9495
necessary, for example in an expression like
9496
@samp{@var{scope1}::@var{scope2}::@var{name}}.  @value{GDBN} also allows
9497
resolving name scope by reference to source files, in both C and C@t{++}
9498
debugging (@pxref{Variables, ,Program Variables}).
9499
@end enumerate
9500
 
9501
In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
9502
calling virtual functions correctly, printing out virtual bases of
9503
objects, calling functions in a base subobject, casting objects, and
9504
invoking user-defined operators.
9505
 
9506
@node C Defaults
9507
@subsubsection C and C@t{++} Defaults
9508
 
9509
@cindex C and C@t{++} defaults
9510
 
9511
If you allow @value{GDBN} to set type and range checking automatically, they
9512
both default to @code{off} whenever the working language changes to
9513
C or C@t{++}.  This happens regardless of whether you or @value{GDBN}
9514
selects the working language.
9515
 
9516
If you allow @value{GDBN} to set the language automatically, it
9517
recognizes source files whose names end with @file{.c}, @file{.C}, or
9518
@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
9519
these files, it sets the working language to C or C@t{++}.
9520
@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
9521
for further details.
9522
 
9523
@c Type checking is (a) primarily motivated by Modula-2, and (b)
9524
@c unimplemented.  If (b) changes, it might make sense to let this node
9525
@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
9526
 
9527
@node C Checks
9528
@subsubsection C and C@t{++} Type and Range Checks
9529
 
9530
@cindex C and C@t{++} checks
9531
 
9532
By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
9533
is not used.  However, if you turn type checking on, @value{GDBN}
9534
considers two variables type equivalent if:
9535
 
9536
@itemize @bullet
9537
@item
9538
The two variables are structured and have the same structure, union, or
9539
enumerated tag.
9540
 
9541
@item
9542
The two variables have the same type name, or types that have been
9543
declared equivalent through @code{typedef}.
9544
 
9545
@ignore
9546
@c leaving this out because neither J Gilmore nor R Pesch understand it.
9547
@c FIXME--beers?
9548
@item
9549
The two @code{struct}, @code{union}, or @code{enum} variables are
9550
declared in the same declaration.  (Note: this may not be true for all C
9551
compilers.)
9552
@end ignore
9553
@end itemize
9554
 
9555
Range checking, if turned on, is done on mathematical operations.  Array
9556
indices are not checked, since they are often used to index a pointer
9557
that is not itself an array.
9558
 
9559
@node Debugging C
9560
@subsubsection @value{GDBN} and C
9561
 
9562
The @code{set print union} and @code{show print union} commands apply to
9563
the @code{union} type.  When set to @samp{on}, any @code{union} that is
9564
inside a @code{struct} or @code{class} is also printed.  Otherwise, it
9565
appears as @samp{@{...@}}.
9566
 
9567
The @code{@@} operator aids in the debugging of dynamic arrays, formed
9568
with pointers and a memory allocation function.  @xref{Expressions,
9569
,Expressions}.
9570
 
9571
@node Debugging C Plus Plus
9572
@subsubsection @value{GDBN} Features for C@t{++}
9573
 
9574
@cindex commands for C@t{++}
9575
 
9576
Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
9577
designed specifically for use with C@t{++}.  Here is a summary:
9578
 
9579
@table @code
9580
@cindex break in overloaded functions
9581
@item @r{breakpoint menus}
9582
When you want a breakpoint in a function whose name is overloaded,
9583
@value{GDBN} breakpoint menus help you specify which function definition
9584
you want.  @xref{Breakpoint Menus,,Breakpoint Menus}.
9585
 
9586
@cindex overloading in C@t{++}
9587
@item rbreak @var{regex}
9588
Setting breakpoints using regular expressions is helpful for setting
9589
breakpoints on overloaded functions that are not members of any special
9590
classes.
9591
@xref{Set Breaks, ,Setting Breakpoints}.
9592
 
9593
@cindex C@t{++} exception handling
9594
@item catch throw
9595
@itemx catch catch
9596
Debug C@t{++} exception handling using these commands.  @xref{Set
9597
Catchpoints, , Setting Catchpoints}.
9598
 
9599
@cindex inheritance
9600
@item ptype @var{typename}
9601
Print inheritance relationships as well as other information for type
9602
@var{typename}.
9603
@xref{Symbols, ,Examining the Symbol Table}.
9604
 
9605
@cindex C@t{++} symbol display
9606
@item set print demangle
9607
@itemx show print demangle
9608
@itemx set print asm-demangle
9609
@itemx show print asm-demangle
9610
Control whether C@t{++} symbols display in their source form, both when
9611
displaying code as C@t{++} source and when displaying disassemblies.
9612
@xref{Print Settings, ,Print Settings}.
9613
 
9614
@item set print object
9615
@itemx show print object
9616
Choose whether to print derived (actual) or declared types of objects.
9617
@xref{Print Settings, ,Print Settings}.
9618
 
9619
@item set print vtbl
9620
@itemx show print vtbl
9621
Control the format for printing virtual function tables.
9622
@xref{Print Settings, ,Print Settings}.
9623
(The @code{vtbl} commands do not work on programs compiled with the HP
9624
ANSI C@t{++} compiler (@code{aCC}).)
9625
 
9626
@kindex set overload-resolution
9627
@cindex overloaded functions, overload resolution
9628
@item set overload-resolution on
9629
Enable overload resolution for C@t{++} expression evaluation.  The default
9630
is on.  For overloaded functions, @value{GDBN} evaluates the arguments
9631
and searches for a function whose signature matches the argument types,
9632
using the standard C@t{++} conversion rules (see @ref{C Plus Plus
9633
Expressions, ,C@t{++} Expressions}, for details).
9634
If it cannot find a match, it emits a message.
9635
 
9636
@item set overload-resolution off
9637
Disable overload resolution for C@t{++} expression evaluation.  For
9638
overloaded functions that are not class member functions, @value{GDBN}
9639
chooses the first function of the specified name that it finds in the
9640
symbol table, whether or not its arguments are of the correct type.  For
9641
overloaded functions that are class member functions, @value{GDBN}
9642
searches for a function whose signature @emph{exactly} matches the
9643
argument types.
9644
 
9645
@kindex show overload-resolution
9646
@item show overload-resolution
9647
Show the current setting of overload resolution.
9648
 
9649
@item @r{Overloaded symbol names}
9650
You can specify a particular definition of an overloaded symbol, using
9651
the same notation that is used to declare such symbols in C@t{++}: type
9652
@code{@var{symbol}(@var{types})} rather than just @var{symbol}.  You can
9653
also use the @value{GDBN} command-line word completion facilities to list the
9654
available choices, or to finish the type list for you.
9655
@xref{Completion,, Command Completion}, for details on how to do this.
9656
@end table
9657
 
9658
@node Decimal Floating Point
9659
@subsubsection Decimal Floating Point format
9660
@cindex decimal floating point format
9661
 
9662
@value{GDBN} can examine, set and perform computations with numbers in
9663
decimal floating point format, which in the C language correspond to the
9664
@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
9665
specified by the extension to support decimal floating-point arithmetic.
9666
 
9667
There are two encodings in use, depending on the architecture: BID (Binary
9668
Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
9669
PowerPC. @value{GDBN} will use the appropriate encoding for the configured
9670
target.
9671
 
9672
Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
9673
to manipulate decimal floating point numbers, it is not possible to convert
9674
(using a cast, for example) integers wider than 32-bit to decimal float.
9675
 
9676
In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
9677
point computations, error checking in decimal float operations ignores
9678
underflow, overflow and divide by zero exceptions.
9679
 
9680
In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
9681
to inspect @code{_Decimal128} values stored in floating point registers. See
9682
@ref{PowerPC,,PowerPC} for more details.
9683
 
9684
@node Objective-C
9685
@subsection Objective-C
9686
 
9687
@cindex Objective-C
9688
This section provides information about some commands and command
9689
options that are useful for debugging Objective-C code.  See also
9690
@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9691
few more commands specific to Objective-C support.
9692
 
9693
@menu
9694
* Method Names in Commands::
9695
* The Print Command with Objective-C::
9696
@end menu
9697
 
9698
@node Method Names in Commands
9699
@subsubsection Method Names in Commands
9700
 
9701
The following commands have been extended to accept Objective-C method
9702
names as line specifications:
9703
 
9704
@kindex clear@r{, and Objective-C}
9705
@kindex break@r{, and Objective-C}
9706
@kindex info line@r{, and Objective-C}
9707
@kindex jump@r{, and Objective-C}
9708
@kindex list@r{, and Objective-C}
9709
@itemize
9710
@item @code{clear}
9711
@item @code{break}
9712
@item @code{info line}
9713
@item @code{jump}
9714
@item @code{list}
9715
@end itemize
9716
 
9717
A fully qualified Objective-C method name is specified as
9718
 
9719
@smallexample
9720
-[@var{Class} @var{methodName}]
9721
@end smallexample
9722
 
9723
where the minus sign is used to indicate an instance method and a
9724
plus sign (not shown) is used to indicate a class method.  The class
9725
name @var{Class} and method name @var{methodName} are enclosed in
9726
brackets, similar to the way messages are specified in Objective-C
9727
source code.  For example, to set a breakpoint at the @code{create}
9728
instance method of class @code{Fruit} in the program currently being
9729
debugged, enter:
9730
 
9731
@smallexample
9732
break -[Fruit create]
9733
@end smallexample
9734
 
9735
To list ten program lines around the @code{initialize} class method,
9736
enter:
9737
 
9738
@smallexample
9739
list +[NSText initialize]
9740
@end smallexample
9741
 
9742
In the current version of @value{GDBN}, the plus or minus sign is
9743
required.  In future versions of @value{GDBN}, the plus or minus
9744
sign will be optional, but you can use it to narrow the search.  It
9745
is also possible to specify just a method name:
9746
 
9747
@smallexample
9748
break create
9749
@end smallexample
9750
 
9751
You must specify the complete method name, including any colons.  If
9752
your program's source files contain more than one @code{create} method,
9753
you'll be presented with a numbered list of classes that implement that
9754
method.  Indicate your choice by number, or type @samp{0} to exit if
9755
none apply.
9756
 
9757
As another example, to clear a breakpoint established at the
9758
@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9759
 
9760
@smallexample
9761
clear -[NSWindow makeKeyAndOrderFront:]
9762
@end smallexample
9763
 
9764
@node The Print Command with Objective-C
9765
@subsubsection The Print Command With Objective-C
9766
@cindex Objective-C, print objects
9767
@kindex print-object
9768
@kindex po @r{(@code{print-object})}
9769
 
9770
The print command has also been extended to accept methods.  For example:
9771
 
9772
@smallexample
9773
print -[@var{object} hash]
9774
@end smallexample
9775
 
9776
@cindex print an Objective-C object description
9777
@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9778
@noindent
9779
will tell @value{GDBN} to send the @code{hash} message to @var{object}
9780
and print the result.  Also, an additional command has been added,
9781
@code{print-object} or @code{po} for short, which is meant to print
9782
the description of an object.  However, this command may only work
9783
with certain Objective-C libraries that have a particular hook
9784
function, @code{_NSPrintForDebugger}, defined.
9785
 
9786
@node Fortran
9787
@subsection Fortran
9788
@cindex Fortran-specific support in @value{GDBN}
9789
 
9790
@value{GDBN} can be used to debug programs written in Fortran, but it
9791
currently supports only the features of Fortran 77 language.
9792
 
9793
@cindex trailing underscore, in Fortran symbols
9794
Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
9795
among them) append an underscore to the names of variables and
9796
functions.  When you debug programs compiled by those compilers, you
9797
will need to refer to variables and functions with a trailing
9798
underscore.
9799
 
9800
@menu
9801
* Fortran Operators::           Fortran operators and expressions
9802
* Fortran Defaults::            Default settings for Fortran
9803
* Special Fortran Commands::    Special @value{GDBN} commands for Fortran
9804
@end menu
9805
 
9806
@node Fortran Operators
9807
@subsubsection Fortran Operators and Expressions
9808
 
9809
@cindex Fortran operators and expressions
9810
 
9811
Operators must be defined on values of specific types.  For instance,
9812
@code{+} is defined on numbers, but not on characters or other non-
9813
arithmetic types.  Operators are often defined on groups of types.
9814
 
9815
@table @code
9816
@item **
9817
The exponentiation operator. It raises the first operand to the power
9818
of the second one.
9819
 
9820
@item :
9821
The range operator.  Normally used in the form of array(low:high) to
9822
represent a section of array.
9823
@end table
9824
 
9825
@node Fortran Defaults
9826
@subsubsection Fortran Defaults
9827
 
9828
@cindex Fortran Defaults
9829
 
9830
Fortran symbols are usually case-insensitive, so @value{GDBN} by
9831
default uses case-insensitive matches for Fortran symbols.  You can
9832
change that with the @samp{set case-insensitive} command, see
9833
@ref{Symbols}, for the details.
9834
 
9835
@node Special Fortran Commands
9836
@subsubsection Special Fortran Commands
9837
 
9838
@cindex Special Fortran commands
9839
 
9840
@value{GDBN} has some commands to support Fortran-specific features,
9841
such as displaying common blocks.
9842
 
9843
@table @code
9844
@cindex @code{COMMON} blocks, Fortran
9845
@kindex info common
9846
@item info common @r{[}@var{common-name}@r{]}
9847
This command prints the values contained in the Fortran @code{COMMON}
9848
block whose name is @var{common-name}.  With no argument, the names of
9849
all @code{COMMON} blocks visible at the current program location are
9850
printed.
9851
@end table
9852
 
9853
@node Pascal
9854
@subsection Pascal
9855
 
9856
@cindex Pascal support in @value{GDBN}, limitations
9857
Debugging Pascal programs which use sets, subranges, file variables, or
9858
nested functions does not currently work.  @value{GDBN} does not support
9859
entering expressions, printing values, or similar features using Pascal
9860
syntax.
9861
 
9862
The Pascal-specific command @code{set print pascal_static-members}
9863
controls whether static members of Pascal objects are displayed.
9864
@xref{Print Settings, pascal_static-members}.
9865
 
9866
@node Modula-2
9867
@subsection Modula-2
9868
 
9869
@cindex Modula-2, @value{GDBN} support
9870
 
9871
The extensions made to @value{GDBN} to support Modula-2 only support
9872
output from the @sc{gnu} Modula-2 compiler (which is currently being
9873
developed).  Other Modula-2 compilers are not currently supported, and
9874
attempting to debug executables produced by them is most likely
9875
to give an error as @value{GDBN} reads in the executable's symbol
9876
table.
9877
 
9878
@cindex expressions in Modula-2
9879
@menu
9880
* M2 Operators::                Built-in operators
9881
* Built-In Func/Proc::          Built-in functions and procedures
9882
* M2 Constants::                Modula-2 constants
9883
* M2 Types::                    Modula-2 types
9884
* M2 Defaults::                 Default settings for Modula-2
9885
* Deviations::                  Deviations from standard Modula-2
9886
* M2 Checks::                   Modula-2 type and range checks
9887
* M2 Scope::                    The scope operators @code{::} and @code{.}
9888
* GDB/M2::                      @value{GDBN} and Modula-2
9889
@end menu
9890
 
9891
@node M2 Operators
9892
@subsubsection Operators
9893
@cindex Modula-2 operators
9894
 
9895
Operators must be defined on values of specific types.  For instance,
9896
@code{+} is defined on numbers, but not on structures.  Operators are
9897
often defined on groups of types.  For the purposes of Modula-2, the
9898
following definitions hold:
9899
 
9900
@itemize @bullet
9901
 
9902
@item
9903
@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9904
their subranges.
9905
 
9906
@item
9907
@emph{Character types} consist of @code{CHAR} and its subranges.
9908
 
9909
@item
9910
@emph{Floating-point types} consist of @code{REAL}.
9911
 
9912
@item
9913
@emph{Pointer types} consist of anything declared as @code{POINTER TO
9914
@var{type}}.
9915
 
9916
@item
9917
@emph{Scalar types} consist of all of the above.
9918
 
9919
@item
9920
@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9921
 
9922
@item
9923
@emph{Boolean types} consist of @code{BOOLEAN}.
9924
@end itemize
9925
 
9926
@noindent
9927
The following operators are supported, and appear in order of
9928
increasing precedence:
9929
 
9930
@table @code
9931
@item ,
9932
Function argument or array index separator.
9933
 
9934
@item :=
9935
Assignment.  The value of @var{var} @code{:=} @var{value} is
9936
@var{value}.
9937
 
9938
@item <@r{, }>
9939
Less than, greater than on integral, floating-point, or enumerated
9940
types.
9941
 
9942
@item <=@r{, }>=
9943
Less than or equal to, greater than or equal to
9944
on integral, floating-point and enumerated types, or set inclusion on
9945
set types.  Same precedence as @code{<}.
9946
 
9947
@item =@r{, }<>@r{, }#
9948
Equality and two ways of expressing inequality, valid on scalar types.
9949
Same precedence as @code{<}.  In @value{GDBN} scripts, only @code{<>} is
9950
available for inequality, since @code{#} conflicts with the script
9951
comment character.
9952
 
9953
@item IN
9954
Set membership.  Defined on set types and the types of their members.
9955
Same precedence as @code{<}.
9956
 
9957
@item OR
9958
Boolean disjunction.  Defined on boolean types.
9959
 
9960
@item AND@r{, }&
9961
Boolean conjunction.  Defined on boolean types.
9962
 
9963
@item @@
9964
The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9965
 
9966
@item +@r{, }-
9967
Addition and subtraction on integral and floating-point types, or union
9968
and difference on set types.
9969
 
9970
@item *
9971
Multiplication on integral and floating-point types, or set intersection
9972
on set types.
9973
 
9974
@item /
9975
Division on floating-point types, or symmetric set difference on set
9976
types.  Same precedence as @code{*}.
9977
 
9978
@item DIV@r{, }MOD
9979
Integer division and remainder.  Defined on integral types.  Same
9980
precedence as @code{*}.
9981
 
9982
@item -
9983
Negative. Defined on @code{INTEGER} and @code{REAL} data.
9984
 
9985
@item ^
9986
Pointer dereferencing.  Defined on pointer types.
9987
 
9988
@item NOT
9989
Boolean negation.  Defined on boolean types.  Same precedence as
9990
@code{^}.
9991
 
9992
@item .
9993
@code{RECORD} field selector.  Defined on @code{RECORD} data.  Same
9994
precedence as @code{^}.
9995
 
9996
@item []
9997
Array indexing.  Defined on @code{ARRAY} data.  Same precedence as @code{^}.
9998
 
9999
@item ()
10000
Procedure argument list.  Defined on @code{PROCEDURE} objects.  Same precedence
10001
as @code{^}.
10002
 
10003
@item ::@r{, }.
10004
@value{GDBN} and Modula-2 scope operators.
10005
@end table
10006
 
10007
@quotation
10008
@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
10009
treats the use of the operator @code{IN}, or the use of operators
10010
@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
10011
@code{<=}, and @code{>=} on sets as an error.
10012
@end quotation
10013
 
10014
 
10015
@node Built-In Func/Proc
10016
@subsubsection Built-in Functions and Procedures
10017
@cindex Modula-2 built-ins
10018
 
10019
Modula-2 also makes available several built-in procedures and functions.
10020
In describing these, the following metavariables are used:
10021
 
10022
@table @var
10023
 
10024
@item a
10025
represents an @code{ARRAY} variable.
10026
 
10027
@item c
10028
represents a @code{CHAR} constant or variable.
10029
 
10030
@item i
10031
represents a variable or constant of integral type.
10032
 
10033
@item m
10034
represents an identifier that belongs to a set.  Generally used in the
10035
same function with the metavariable @var{s}.  The type of @var{s} should
10036
be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
10037
 
10038
@item n
10039
represents a variable or constant of integral or floating-point type.
10040
 
10041
@item r
10042
represents a variable or constant of floating-point type.
10043
 
10044
@item t
10045
represents a type.
10046
 
10047
@item v
10048
represents a variable.
10049
 
10050
@item x
10051
represents a variable or constant of one of many types.  See the
10052
explanation of the function for details.
10053
@end table
10054
 
10055
All Modula-2 built-in procedures also return a result, described below.
10056
 
10057
@table @code
10058
@item ABS(@var{n})
10059
Returns the absolute value of @var{n}.
10060
 
10061
@item CAP(@var{c})
10062
If @var{c} is a lower case letter, it returns its upper case
10063
equivalent, otherwise it returns its argument.
10064
 
10065
@item CHR(@var{i})
10066
Returns the character whose ordinal value is @var{i}.
10067
 
10068
@item DEC(@var{v})
10069
Decrements the value in the variable @var{v} by one.  Returns the new value.
10070
 
10071
@item DEC(@var{v},@var{i})
10072
Decrements the value in the variable @var{v} by @var{i}.  Returns the
10073
new value.
10074
 
10075
@item EXCL(@var{m},@var{s})
10076
Removes the element @var{m} from the set @var{s}.  Returns the new
10077
set.
10078
 
10079
@item FLOAT(@var{i})
10080
Returns the floating point equivalent of the integer @var{i}.
10081
 
10082
@item HIGH(@var{a})
10083
Returns the index of the last member of @var{a}.
10084
 
10085
@item INC(@var{v})
10086
Increments the value in the variable @var{v} by one.  Returns the new value.
10087
 
10088
@item INC(@var{v},@var{i})
10089
Increments the value in the variable @var{v} by @var{i}.  Returns the
10090
new value.
10091
 
10092
@item INCL(@var{m},@var{s})
10093
Adds the element @var{m} to the set @var{s} if it is not already
10094
there.  Returns the new set.
10095
 
10096
@item MAX(@var{t})
10097
Returns the maximum value of the type @var{t}.
10098
 
10099
@item MIN(@var{t})
10100
Returns the minimum value of the type @var{t}.
10101
 
10102
@item ODD(@var{i})
10103
Returns boolean TRUE if @var{i} is an odd number.
10104
 
10105
@item ORD(@var{x})
10106
Returns the ordinal value of its argument.  For example, the ordinal
10107
value of a character is its @sc{ascii} value (on machines supporting the
10108
@sc{ascii} character set).  @var{x} must be of an ordered type, which include
10109
integral, character and enumerated types.
10110
 
10111
@item SIZE(@var{x})
10112
Returns the size of its argument.  @var{x} can be a variable or a type.
10113
 
10114
@item TRUNC(@var{r})
10115
Returns the integral part of @var{r}.
10116
 
10117
@item TSIZE(@var{x})
10118
Returns the size of its argument.  @var{x} can be a variable or a type.
10119
 
10120
@item VAL(@var{t},@var{i})
10121
Returns the member of the type @var{t} whose ordinal value is @var{i}.
10122
@end table
10123
 
10124
@quotation
10125
@emph{Warning:}  Sets and their operations are not yet supported, so
10126
@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
10127
an error.
10128
@end quotation
10129
 
10130
@cindex Modula-2 constants
10131
@node M2 Constants
10132
@subsubsection Constants
10133
 
10134
@value{GDBN} allows you to express the constants of Modula-2 in the following
10135
ways:
10136
 
10137
@itemize @bullet
10138
 
10139
@item
10140
Integer constants are simply a sequence of digits.  When used in an
10141
expression, a constant is interpreted to be type-compatible with the
10142
rest of the expression.  Hexadecimal integers are specified by a
10143
trailing @samp{H}, and octal integers by a trailing @samp{B}.
10144
 
10145
@item
10146
Floating point constants appear as a sequence of digits, followed by a
10147
decimal point and another sequence of digits.  An optional exponent can
10148
then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
10149
@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent.  All of the
10150
digits of the floating point constant must be valid decimal (base 10)
10151
digits.
10152
 
10153
@item
10154
Character constants consist of a single character enclosed by a pair of
10155
like quotes, either single (@code{'}) or double (@code{"}).  They may
10156
also be expressed by their ordinal value (their @sc{ascii} value, usually)
10157
followed by a @samp{C}.
10158
 
10159
@item
10160
String constants consist of a sequence of characters enclosed by a
10161
pair of like quotes, either single (@code{'}) or double (@code{"}).
10162
Escape sequences in the style of C are also allowed.  @xref{C
10163
Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
10164
sequences.
10165
 
10166
@item
10167
Enumerated constants consist of an enumerated identifier.
10168
 
10169
@item
10170
Boolean constants consist of the identifiers @code{TRUE} and
10171
@code{FALSE}.
10172
 
10173
@item
10174
Pointer constants consist of integral values only.
10175
 
10176
@item
10177
Set constants are not yet supported.
10178
@end itemize
10179
 
10180
@node M2 Types
10181
@subsubsection Modula-2 Types
10182
@cindex Modula-2 types
10183
 
10184
Currently @value{GDBN} can print the following data types in Modula-2
10185
syntax: array types, record types, set types, pointer types, procedure
10186
types, enumerated types, subrange types and base types.  You can also
10187
print the contents of variables declared using these type.
10188
This section gives a number of simple source code examples together with
10189
sample @value{GDBN} sessions.
10190
 
10191
The first example contains the following section of code:
10192
 
10193
@smallexample
10194
VAR
10195
   s: SET OF CHAR ;
10196
   r: [20..40] ;
10197
@end smallexample
10198
 
10199
@noindent
10200
and you can request @value{GDBN} to interrogate the type and value of
10201
@code{r} and @code{s}.
10202
 
10203
@smallexample
10204
(@value{GDBP}) print s
10205
@{'A'..'C', 'Z'@}
10206
(@value{GDBP}) ptype s
10207
SET OF CHAR
10208
(@value{GDBP}) print r
10209
21
10210
(@value{GDBP}) ptype r
10211
[20..40]
10212
@end smallexample
10213
 
10214
@noindent
10215
Likewise if your source code declares @code{s} as:
10216
 
10217
@smallexample
10218
VAR
10219
   s: SET ['A'..'Z'] ;
10220
@end smallexample
10221
 
10222
@noindent
10223
then you may query the type of @code{s} by:
10224
 
10225
@smallexample
10226
(@value{GDBP}) ptype s
10227
type = SET ['A'..'Z']
10228
@end smallexample
10229
 
10230
@noindent
10231
Note that at present you cannot interactively manipulate set
10232
expressions using the debugger.
10233
 
10234
The following example shows how you might declare an array in Modula-2
10235
and how you can interact with @value{GDBN} to print its type and contents:
10236
 
10237
@smallexample
10238
VAR
10239
   s: ARRAY [-10..10] OF CHAR ;
10240
@end smallexample
10241
 
10242
@smallexample
10243
(@value{GDBP}) ptype s
10244
ARRAY [-10..10] OF CHAR
10245
@end smallexample
10246
 
10247
Note that the array handling is not yet complete and although the type
10248
is printed correctly, expression handling still assumes that all
10249
arrays have a lower bound of zero and not @code{-10} as in the example
10250
above.
10251
 
10252
Here are some more type related Modula-2 examples:
10253
 
10254
@smallexample
10255
TYPE
10256
   colour = (blue, red, yellow, green) ;
10257
   t = [blue..yellow] ;
10258
VAR
10259
   s: t ;
10260
BEGIN
10261
   s := blue ;
10262
@end smallexample
10263
 
10264
@noindent
10265
The @value{GDBN} interaction shows how you can query the data type
10266
and value of a variable.
10267
 
10268
@smallexample
10269
(@value{GDBP}) print s
10270
$1 = blue
10271
(@value{GDBP}) ptype t
10272
type = [blue..yellow]
10273
@end smallexample
10274
 
10275
@noindent
10276
In this example a Modula-2 array is declared and its contents
10277
displayed.  Observe that the contents are written in the same way as
10278
their @code{C} counterparts.
10279
 
10280
@smallexample
10281
VAR
10282
   s: ARRAY [1..5] OF CARDINAL ;
10283
BEGIN
10284
   s[1] := 1 ;
10285
@end smallexample
10286
 
10287
@smallexample
10288
(@value{GDBP}) print s
10289
$1 = @{1, 0, 0, 0, 0@}
10290
(@value{GDBP}) ptype s
10291
type = ARRAY [1..5] OF CARDINAL
10292
@end smallexample
10293
 
10294
The Modula-2 language interface to @value{GDBN} also understands
10295
pointer types as shown in this example:
10296
 
10297
@smallexample
10298
VAR
10299
   s: POINTER TO ARRAY [1..5] OF CARDINAL ;
10300
BEGIN
10301
   NEW(s) ;
10302
   s^[1] := 1 ;
10303
@end smallexample
10304
 
10305
@noindent
10306
and you can request that @value{GDBN} describes the type of @code{s}.
10307
 
10308
@smallexample
10309
(@value{GDBP}) ptype s
10310
type = POINTER TO ARRAY [1..5] OF CARDINAL
10311
@end smallexample
10312
 
10313
@value{GDBN} handles compound types as we can see in this example.
10314
Here we combine array types, record types, pointer types and subrange
10315
types:
10316
 
10317
@smallexample
10318
TYPE
10319
   foo = RECORD
10320
            f1: CARDINAL ;
10321
            f2: CHAR ;
10322
            f3: myarray ;
10323
         END ;
10324
 
10325
   myarray = ARRAY myrange OF CARDINAL ;
10326
   myrange = [-2..2] ;
10327
VAR
10328
   s: POINTER TO ARRAY myrange OF foo ;
10329
@end smallexample
10330
 
10331
@noindent
10332
and you can ask @value{GDBN} to describe the type of @code{s} as shown
10333
below.
10334
 
10335
@smallexample
10336
(@value{GDBP}) ptype s
10337
type = POINTER TO ARRAY [-2..2] OF foo = RECORD
10338
    f1 : CARDINAL;
10339
    f2 : CHAR;
10340
    f3 : ARRAY [-2..2] OF CARDINAL;
10341
END
10342
@end smallexample
10343
 
10344
@node M2 Defaults
10345
@subsubsection Modula-2 Defaults
10346
@cindex Modula-2 defaults
10347
 
10348
If type and range checking are set automatically by @value{GDBN}, they
10349
both default to @code{on} whenever the working language changes to
10350
Modula-2.  This happens regardless of whether you or @value{GDBN}
10351
selected the working language.
10352
 
10353
If you allow @value{GDBN} to set the language automatically, then entering
10354
code compiled from a file whose name ends with @file{.mod} sets the
10355
working language to Modula-2.  @xref{Automatically, ,Having @value{GDBN}
10356
Infer the Source Language}, for further details.
10357
 
10358
@node Deviations
10359
@subsubsection Deviations from Standard Modula-2
10360
@cindex Modula-2, deviations from
10361
 
10362
A few changes have been made to make Modula-2 programs easier to debug.
10363
This is done primarily via loosening its type strictness:
10364
 
10365
@itemize @bullet
10366
@item
10367
Unlike in standard Modula-2, pointer constants can be formed by
10368
integers.  This allows you to modify pointer variables during
10369
debugging.  (In standard Modula-2, the actual address contained in a
10370
pointer variable is hidden from you; it can only be modified
10371
through direct assignment to another pointer variable or expression that
10372
returned a pointer.)
10373
 
10374
@item
10375
C escape sequences can be used in strings and characters to represent
10376
non-printable characters.  @value{GDBN} prints out strings with these
10377
escape sequences embedded.  Single non-printable characters are
10378
printed using the @samp{CHR(@var{nnn})} format.
10379
 
10380
@item
10381
The assignment operator (@code{:=}) returns the value of its right-hand
10382
argument.
10383
 
10384
@item
10385
All built-in procedures both modify @emph{and} return their argument.
10386
@end itemize
10387
 
10388
@node M2 Checks
10389
@subsubsection Modula-2 Type and Range Checks
10390
@cindex Modula-2 checks
10391
 
10392
@quotation
10393
@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
10394
range checking.
10395
@end quotation
10396
@c FIXME remove warning when type/range checks added
10397
 
10398
@value{GDBN} considers two Modula-2 variables type equivalent if:
10399
 
10400
@itemize @bullet
10401
@item
10402
They are of types that have been declared equivalent via a @code{TYPE
10403
@var{t1} = @var{t2}} statement
10404
 
10405
@item
10406
They have been declared on the same line.  (Note:  This is true of the
10407
@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
10408
@end itemize
10409
 
10410
As long as type checking is enabled, any attempt to combine variables
10411
whose types are not equivalent is an error.
10412
 
10413
Range checking is done on all mathematical operations, assignment, array
10414
index bounds, and all built-in functions and procedures.
10415
 
10416
@node M2 Scope
10417
@subsubsection The Scope Operators @code{::} and @code{.}
10418
@cindex scope
10419
@cindex @code{.}, Modula-2 scope operator
10420
@cindex colon, doubled as scope operator
10421
@ifinfo
10422
@vindex colon-colon@r{, in Modula-2}
10423
@c Info cannot handle :: but TeX can.
10424
@end ifinfo
10425
@iftex
10426
@vindex ::@r{, in Modula-2}
10427
@end iftex
10428
 
10429
There are a few subtle differences between the Modula-2 scope operator
10430
(@code{.}) and the @value{GDBN} scope operator (@code{::}).  The two have
10431
similar syntax:
10432
 
10433
@smallexample
10434
 
10435
@var{module} . @var{id}
10436
@var{scope} :: @var{id}
10437
@end smallexample
10438
 
10439
@noindent
10440
where @var{scope} is the name of a module or a procedure,
10441
@var{module} the name of a module, and @var{id} is any declared
10442
identifier within your program, except another module.
10443
 
10444
Using the @code{::} operator makes @value{GDBN} search the scope
10445
specified by @var{scope} for the identifier @var{id}.  If it is not
10446
found in the specified scope, then @value{GDBN} searches all scopes
10447
enclosing the one specified by @var{scope}.
10448
 
10449
Using the @code{.} operator makes @value{GDBN} search the current scope for
10450
the identifier specified by @var{id} that was imported from the
10451
definition module specified by @var{module}.  With this operator, it is
10452
an error if the identifier @var{id} was not imported from definition
10453
module @var{module}, or if @var{id} is not an identifier in
10454
@var{module}.
10455
 
10456
@node GDB/M2
10457
@subsubsection @value{GDBN} and Modula-2
10458
 
10459
Some @value{GDBN} commands have little use when debugging Modula-2 programs.
10460
Five subcommands of @code{set print} and @code{show print} apply
10461
specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
10462
@samp{asm-demangle}, @samp{object}, and @samp{union}.  The first four
10463
apply to C@t{++}, and the last to the C @code{union} type, which has no direct
10464
analogue in Modula-2.
10465
 
10466
The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
10467
with any language, is not useful with Modula-2.  Its
10468
intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
10469
created in Modula-2 as they can in C or C@t{++}.  However, because an
10470
address can be specified by an integral constant, the construct
10471
@samp{@{@var{type}@}@var{adrexp}} is still useful.
10472
 
10473
@cindex @code{#} in Modula-2
10474
In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
10475
interpreted as the beginning of a comment.  Use @code{<>} instead.
10476
 
10477
@node Ada
10478
@subsection Ada
10479
@cindex Ada
10480
 
10481
The extensions made to @value{GDBN} for Ada only support
10482
output from the @sc{gnu} Ada (GNAT) compiler.
10483
Other Ada compilers are not currently supported, and
10484
attempting to debug executables produced by them is most likely
10485
to be difficult.
10486
 
10487
 
10488
@cindex expressions in Ada
10489
@menu
10490
* Ada Mode Intro::              General remarks on the Ada syntax
10491
                                   and semantics supported by Ada mode
10492
                                   in @value{GDBN}.
10493
* Omissions from Ada::          Restrictions on the Ada expression syntax.
10494
* Additions to Ada::            Extensions of the Ada expression syntax.
10495
* Stopping Before Main Program:: Debugging the program during elaboration.
10496
* Ada Glitches::                Known peculiarities of Ada mode.
10497
@end menu
10498
 
10499
@node Ada Mode Intro
10500
@subsubsection Introduction
10501
@cindex Ada mode, general
10502
 
10503
The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
10504
syntax, with some extensions.
10505
The philosophy behind the design of this subset is
10506
 
10507
@itemize @bullet
10508
@item
10509
That @value{GDBN} should provide basic literals and access to operations for
10510
arithmetic, dereferencing, field selection, indexing, and subprogram calls,
10511
leaving more sophisticated computations to subprograms written into the
10512
program (which therefore may be called from @value{GDBN}).
10513
 
10514
@item
10515
That type safety and strict adherence to Ada language restrictions
10516
are not particularly important to the @value{GDBN} user.
10517
 
10518
@item
10519
That brevity is important to the @value{GDBN} user.
10520
@end itemize
10521
 
10522
Thus, for brevity, the debugger acts as if there were
10523
implicit @code{with} and @code{use} clauses in effect for all user-written
10524
packages, making it unnecessary to fully qualify most names with
10525
their packages, regardless of context.  Where this causes ambiguity,
10526
@value{GDBN} asks the user's intent.
10527
 
10528
The debugger will start in Ada mode if it detects an Ada main program.
10529
As for other languages, it will enter Ada mode when stopped in a program that
10530
was translated from an Ada source file.
10531
 
10532
While in Ada mode, you may use `@t{--}' for comments.  This is useful
10533
mostly for documenting command files.  The standard @value{GDBN} comment
10534
(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
10535
middle (to allow based literals).
10536
 
10537
The debugger supports limited overloading.  Given a subprogram call in which
10538
the function symbol has multiple definitions, it will use the number of
10539
actual parameters and some information about their types to attempt to narrow
10540
the set of definitions.  It also makes very limited use of context, preferring
10541
procedures to functions in the context of the @code{call} command, and
10542
functions to procedures elsewhere.
10543
 
10544
@node Omissions from Ada
10545
@subsubsection Omissions from Ada
10546
@cindex Ada, omissions from
10547
 
10548
Here are the notable omissions from the subset:
10549
 
10550
@itemize @bullet
10551
@item
10552
Only a subset of the attributes are supported:
10553
 
10554
@itemize @minus
10555
@item
10556
@t{'First}, @t{'Last}, and @t{'Length}
10557
 on array objects (not on types and subtypes).
10558
 
10559
@item
10560
@t{'Min} and @t{'Max}.
10561
 
10562
@item
10563
@t{'Pos} and @t{'Val}.
10564
 
10565
@item
10566
@t{'Tag}.
10567
 
10568
@item
10569
@t{'Range} on array objects (not subtypes), but only as the right
10570
operand of the membership (@code{in}) operator.
10571
 
10572
@item
10573
@t{'Access}, @t{'Unchecked_Access}, and
10574
@t{'Unrestricted_Access} (a GNAT extension).
10575
 
10576
@item
10577
@t{'Address}.
10578
@end itemize
10579
 
10580
@item
10581
The names in
10582
@code{Characters.Latin_1} are not available and
10583
concatenation is not implemented.  Thus, escape characters in strings are
10584
not currently available.
10585
 
10586
@item
10587
Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
10588
equality of representations.  They will generally work correctly
10589
for strings and arrays whose elements have integer or enumeration types.
10590
They may not work correctly for arrays whose element
10591
types have user-defined equality, for arrays of real values
10592
(in particular, IEEE-conformant floating point, because of negative
10593
zeroes and NaNs), and for arrays whose elements contain unused bits with
10594
indeterminate values.
10595
 
10596
@item
10597
The other component-by-component array operations (@code{and}, @code{or},
10598
@code{xor}, @code{not}, and relational tests other than equality)
10599
are not implemented.
10600
 
10601
@item
10602
@cindex array aggregates (Ada)
10603
@cindex record aggregates (Ada)
10604
@cindex aggregates (Ada)
10605
There is limited support for array and record aggregates.  They are
10606
permitted only on the right sides of assignments, as in these examples:
10607
 
10608
@smallexample
10609
set An_Array := (1, 2, 3, 4, 5, 6)
10610
set An_Array := (1, others => 0)
10611
set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
10612
set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
10613
set A_Record := (1, "Peter", True);
10614
set A_Record := (Name => "Peter", Id => 1, Alive => True)
10615
@end smallexample
10616
 
10617
Changing a
10618
discriminant's value by assigning an aggregate has an
10619
undefined effect if that discriminant is used within the record.
10620
However, you can first modify discriminants by directly assigning to
10621
them (which normally would not be allowed in Ada), and then performing an
10622
aggregate assignment.  For example, given a variable @code{A_Rec}
10623
declared to have a type such as:
10624
 
10625
@smallexample
10626
type Rec (Len : Small_Integer := 0) is record
10627
    Id : Integer;
10628
    Vals : IntArray (1 .. Len);
10629
end record;
10630
@end smallexample
10631
 
10632
you can assign a value with a different size of @code{Vals} with two
10633
assignments:
10634
 
10635
@smallexample
10636
set A_Rec.Len := 4
10637
set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
10638
@end smallexample
10639
 
10640
As this example also illustrates, @value{GDBN} is very loose about the usual
10641
rules concerning aggregates.  You may leave out some of the
10642
components of an array or record aggregate (such as the @code{Len}
10643
component in the assignment to @code{A_Rec} above); they will retain their
10644
original values upon assignment.  You may freely use dynamic values as
10645
indices in component associations.  You may even use overlapping or
10646
redundant component associations, although which component values are
10647
assigned in such cases is not defined.
10648
 
10649
@item
10650
Calls to dispatching subprograms are not implemented.
10651
 
10652
@item
10653
The overloading algorithm is much more limited (i.e., less selective)
10654
than that of real Ada.  It makes only limited use of the context in
10655
which a subexpression appears to resolve its meaning, and it is much
10656
looser in its rules for allowing type matches.  As a result, some
10657
function calls will be ambiguous, and the user will be asked to choose
10658
the proper resolution.
10659
 
10660
@item
10661
The @code{new} operator is not implemented.
10662
 
10663
@item
10664
Entry calls are not implemented.
10665
 
10666
@item
10667
Aside from printing, arithmetic operations on the native VAX floating-point
10668
formats are not supported.
10669
 
10670
@item
10671
It is not possible to slice a packed array.
10672
@end itemize
10673
 
10674
@node Additions to Ada
10675
@subsubsection Additions to Ada
10676
@cindex Ada, deviations from
10677
 
10678
As it does for other languages, @value{GDBN} makes certain generic
10679
extensions to Ada (@pxref{Expressions}):
10680
 
10681
@itemize @bullet
10682
@item
10683
If the expression @var{E} is a variable residing in memory (typically
10684
a local variable or array element) and @var{N} is a positive integer,
10685
then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
10686
@var{N}-1 adjacent variables following it in memory as an array.  In
10687
Ada, this operator is generally not necessary, since its prime use is
10688
in displaying parts of an array, and slicing will usually do this in
10689
Ada.  However, there are occasional uses when debugging programs in
10690
which certain debugging information has been optimized away.
10691
 
10692
@item
10693
@code{@var{B}::@var{var}} means ``the variable named @var{var} that
10694
appears in function or file @var{B}.''  When @var{B} is a file name,
10695
you must typically surround it in single quotes.
10696
 
10697
@item
10698
The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
10699
@var{type} that appears at address @var{addr}.''
10700
 
10701
@item
10702
A name starting with @samp{$} is a convenience variable
10703
(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
10704
@end itemize
10705
 
10706
In addition, @value{GDBN} provides a few other shortcuts and outright
10707
additions specific to Ada:
10708
 
10709
@itemize @bullet
10710
@item
10711
The assignment statement is allowed as an expression, returning
10712
its right-hand operand as its value.  Thus, you may enter
10713
 
10714
@smallexample
10715
set x := y + 3
10716
print A(tmp := y + 1)
10717
@end smallexample
10718
 
10719
@item
10720
The semicolon is allowed as an ``operator,''  returning as its value
10721
the value of its right-hand operand.
10722
This allows, for example,
10723
complex conditional breaks:
10724
 
10725
@smallexample
10726
break f
10727
condition 1 (report(i); k += 1; A(k) > 100)
10728
@end smallexample
10729
 
10730
@item
10731
Rather than use catenation and symbolic character names to introduce special
10732
characters into strings, one may instead use a special bracket notation,
10733
which is also used to print strings.  A sequence of characters of the form
10734
@samp{["@var{XX}"]} within a string or character literal denotes the
10735
(single) character whose numeric encoding is @var{XX} in hexadecimal.  The
10736
sequence of characters @samp{["""]} also denotes a single quotation mark
10737
in strings.   For example,
10738
@smallexample
10739
   "One line.["0a"]Next line.["0a"]"
10740
@end smallexample
10741
@noindent
10742
contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
10743
after each period.
10744
 
10745
@item
10746
The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
10747
@t{'Max} is optional (and is ignored in any case).  For example, it is valid
10748
to write
10749
 
10750
@smallexample
10751
print 'max(x, y)
10752
@end smallexample
10753
 
10754
@item
10755
When printing arrays, @value{GDBN} uses positional notation when the
10756
array has a lower bound of 1, and uses a modified named notation otherwise.
10757
For example, a one-dimensional array of three integers with a lower bound
10758
of 3 might print as
10759
 
10760
@smallexample
10761
(3 => 10, 17, 1)
10762
@end smallexample
10763
 
10764
@noindent
10765
That is, in contrast to valid Ada, only the first component has a @code{=>}
10766
clause.
10767
 
10768
@item
10769
You may abbreviate attributes in expressions with any unique,
10770
multi-character subsequence of
10771
their names (an exact match gets preference).
10772
For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
10773
in place of  @t{a'length}.
10774
 
10775
@item
10776
@cindex quoting Ada internal identifiers
10777
Since Ada is case-insensitive, the debugger normally maps identifiers you type
10778
to lower case.  The GNAT compiler uses upper-case characters for
10779
some of its internal identifiers, which are normally of no interest to users.
10780
For the rare occasions when you actually have to look at them,
10781
enclose them in angle brackets to avoid the lower-case mapping.
10782
For example,
10783
@smallexample
10784
@value{GDBP} print <JMPBUF_SAVE>[0]
10785
@end smallexample
10786
 
10787
@item
10788
Printing an object of class-wide type or dereferencing an
10789
access-to-class-wide value will display all the components of the object's
10790
specific type (as indicated by its run-time tag).  Likewise, component
10791
selection on such a value will operate on the specific type of the
10792
object.
10793
 
10794
@end itemize
10795
 
10796
@node Stopping Before Main Program
10797
@subsubsection Stopping at the Very Beginning
10798
 
10799
@cindex breakpointing Ada elaboration code
10800
It is sometimes necessary to debug the program during elaboration, and
10801
before reaching the main procedure.
10802
As defined in the Ada Reference
10803
Manual, the elaboration code is invoked from a procedure called
10804
@code{adainit}.  To run your program up to the beginning of
10805
elaboration, simply use the following two commands:
10806
@code{tbreak adainit} and @code{run}.
10807
 
10808
@node Ada Glitches
10809
@subsubsection Known Peculiarities of Ada Mode
10810
@cindex Ada, problems
10811
 
10812
Besides the omissions listed previously (@pxref{Omissions from Ada}),
10813
we know of several problems with and limitations of Ada mode in
10814
@value{GDBN},
10815
some of which will be fixed with planned future releases of the debugger
10816
and the GNU Ada compiler.
10817
 
10818
@itemize @bullet
10819
@item
10820
Currently, the debugger
10821
has insufficient information to determine whether certain pointers represent
10822
pointers to objects or the objects themselves.
10823
Thus, the user may have to tack an extra @code{.all} after an expression
10824
to get it printed properly.
10825
 
10826
@item
10827
Static constants that the compiler chooses not to materialize as objects in
10828
storage are invisible to the debugger.
10829
 
10830
@item
10831
Named parameter associations in function argument lists are ignored (the
10832
argument lists are treated as positional).
10833
 
10834
@item
10835
Many useful library packages are currently invisible to the debugger.
10836
 
10837
@item
10838
Fixed-point arithmetic, conversions, input, and output is carried out using
10839
floating-point arithmetic, and may give results that only approximate those on
10840
the host machine.
10841
 
10842
@item
10843
The type of the @t{'Address} attribute may not be @code{System.Address}.
10844
 
10845
@item
10846
The GNAT compiler never generates the prefix @code{Standard} for any of
10847
the standard symbols defined by the Ada language.  @value{GDBN} knows about
10848
this: it will strip the prefix from names when you use it, and will never
10849
look for a name you have so qualified among local symbols, nor match against
10850
symbols in other packages or subprograms.  If you have
10851
defined entities anywhere in your program other than parameters and
10852
local variables whose simple names match names in @code{Standard},
10853
GNAT's lack of qualification here can cause confusion.  When this happens,
10854
you can usually resolve the confusion
10855
by qualifying the problematic names with package
10856
@code{Standard} explicitly.
10857
@end itemize
10858
 
10859
@node Unsupported Languages
10860
@section Unsupported Languages
10861
 
10862
@cindex unsupported languages
10863
@cindex minimal language
10864
In addition to the other fully-supported programming languages,
10865
@value{GDBN} also provides a pseudo-language, called @code{minimal}.
10866
It does not represent a real programming language, but provides a set
10867
of capabilities close to what the C or assembly languages provide.
10868
This should allow most simple operations to be performed while debugging
10869
an application that uses a language currently not supported by @value{GDBN}.
10870
 
10871
If the language is set to @code{auto}, @value{GDBN} will automatically
10872
select this language if the current frame corresponds to an unsupported
10873
language.
10874
 
10875
@node Symbols
10876
@chapter Examining the Symbol Table
10877
 
10878
The commands described in this chapter allow you to inquire about the
10879
symbols (names of variables, functions and types) defined in your
10880
program.  This information is inherent in the text of your program and
10881
does not change as your program executes.  @value{GDBN} finds it in your
10882
program's symbol table, in the file indicated when you started @value{GDBN}
10883
(@pxref{File Options, ,Choosing Files}), or by one of the
10884
file-management commands (@pxref{Files, ,Commands to Specify Files}).
10885
 
10886
@cindex symbol names
10887
@cindex names of symbols
10888
@cindex quoting names
10889
Occasionally, you may need to refer to symbols that contain unusual
10890
characters, which @value{GDBN} ordinarily treats as word delimiters.  The
10891
most frequent case is in referring to static variables in other
10892
source files (@pxref{Variables,,Program Variables}).  File names
10893
are recorded in object files as debugging symbols, but @value{GDBN} would
10894
ordinarily parse a typical file name, like @file{foo.c}, as the three words
10895
@samp{foo} @samp{.} @samp{c}.  To allow @value{GDBN} to recognize
10896
@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
10897
 
10898
@smallexample
10899
p 'foo.c'::x
10900
@end smallexample
10901
 
10902
@noindent
10903
looks up the value of @code{x} in the scope of the file @file{foo.c}.
10904
 
10905
@table @code
10906
@cindex case-insensitive symbol names
10907
@cindex case sensitivity in symbol names
10908
@kindex set case-sensitive
10909
@item set case-sensitive on
10910
@itemx set case-sensitive off
10911
@itemx set case-sensitive auto
10912
Normally, when @value{GDBN} looks up symbols, it matches their names
10913
with case sensitivity determined by the current source language.
10914
Occasionally, you may wish to control that.  The command @code{set
10915
case-sensitive} lets you do that by specifying @code{on} for
10916
case-sensitive matches or @code{off} for case-insensitive ones.  If
10917
you specify @code{auto}, case sensitivity is reset to the default
10918
suitable for the source language.  The default is case-sensitive
10919
matches for all languages except for Fortran, for which the default is
10920
case-insensitive matches.
10921
 
10922
@kindex show case-sensitive
10923
@item show case-sensitive
10924
This command shows the current setting of case sensitivity for symbols
10925
lookups.
10926
 
10927
@kindex info address
10928
@cindex address of a symbol
10929
@item info address @var{symbol}
10930
Describe where the data for @var{symbol} is stored.  For a register
10931
variable, this says which register it is kept in.  For a non-register
10932
local variable, this prints the stack-frame offset at which the variable
10933
is always stored.
10934
 
10935
Note the contrast with @samp{print &@var{symbol}}, which does not work
10936
at all for a register variable, and for a stack local variable prints
10937
the exact address of the current instantiation of the variable.
10938
 
10939
@kindex info symbol
10940
@cindex symbol from address
10941
@cindex closest symbol and offset for an address
10942
@item info symbol @var{addr}
10943
Print the name of a symbol which is stored at the address @var{addr}.
10944
If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10945
nearest symbol and an offset from it:
10946
 
10947
@smallexample
10948
(@value{GDBP}) info symbol 0x54320
10949
_initialize_vx + 396 in section .text
10950
@end smallexample
10951
 
10952
@noindent
10953
This is the opposite of the @code{info address} command.  You can use
10954
it to find out the name of a variable or a function given its address.
10955
 
10956
@kindex whatis
10957
@item whatis [@var{arg}]
10958
Print the data type of @var{arg}, which can be either an expression or
10959
a data type.  With no argument, print the data type of @code{$}, the
10960
last value in the value history.  If @var{arg} is an expression, it is
10961
not actually evaluated, and any side-effecting operations (such as
10962
assignments or function calls) inside it do not take place.  If
10963
@var{arg} is a type name, it may be the name of a type or typedef, or
10964
for C code it may have the form @samp{class @var{class-name}},
10965
@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
10966
@samp{enum @var{enum-tag}}.
10967
@xref{Expressions, ,Expressions}.
10968
 
10969
@kindex ptype
10970
@item ptype [@var{arg}]
10971
@code{ptype} accepts the same arguments as @code{whatis}, but prints a
10972
detailed description of the type, instead of just the name of the type.
10973
@xref{Expressions, ,Expressions}.
10974
 
10975
For example, for this variable declaration:
10976
 
10977
@smallexample
10978
struct complex @{double real; double imag;@} v;
10979
@end smallexample
10980
 
10981
@noindent
10982
the two commands give this output:
10983
 
10984
@smallexample
10985
@group
10986
(@value{GDBP}) whatis v
10987
type = struct complex
10988
(@value{GDBP}) ptype v
10989
type = struct complex @{
10990
    double real;
10991
    double imag;
10992
@}
10993
@end group
10994
@end smallexample
10995
 
10996
@noindent
10997
As with @code{whatis}, using @code{ptype} without an argument refers to
10998
the type of @code{$}, the last value in the value history.
10999
 
11000
@cindex incomplete type
11001
Sometimes, programs use opaque data types or incomplete specifications
11002
of complex data structure.  If the debug information included in the
11003
program does not allow @value{GDBN} to display a full declaration of
11004
the data type, it will say @samp{<incomplete type>}.  For example,
11005
given these declarations:
11006
 
11007
@smallexample
11008
    struct foo;
11009
    struct foo *fooptr;
11010
@end smallexample
11011
 
11012
@noindent
11013
but no definition for @code{struct foo} itself, @value{GDBN} will say:
11014
 
11015
@smallexample
11016
  (@value{GDBP}) ptype foo
11017
  $1 = <incomplete type>
11018
@end smallexample
11019
 
11020
@noindent
11021
``Incomplete type'' is C terminology for data types that are not
11022
completely specified.
11023
 
11024
@kindex info types
11025
@item info types @var{regexp}
11026
@itemx info types
11027
Print a brief description of all types whose names match the regular
11028
expression @var{regexp} (or all types in your program, if you supply
11029
no argument).  Each complete typename is matched as though it were a
11030
complete line; thus, @samp{i type value} gives information on all
11031
types in your program whose names include the string @code{value}, but
11032
@samp{i type ^value$} gives information only on types whose complete
11033
name is @code{value}.
11034
 
11035
This command differs from @code{ptype} in two ways: first, like
11036
@code{whatis}, it does not print a detailed description; second, it
11037
lists all source files where a type is defined.
11038
 
11039
@kindex info scope
11040
@cindex local variables
11041
@item info scope @var{location}
11042
List all the variables local to a particular scope.  This command
11043
accepts a @var{location} argument---a function name, a source line, or
11044
an address preceded by a @samp{*}, and prints all the variables local
11045
to the scope defined by that location.  (@xref{Specify Location}, for
11046
details about supported forms of @var{location}.)  For example:
11047
 
11048
@smallexample
11049
(@value{GDBP}) @b{info scope command_line_handler}
11050
Scope for command_line_handler:
11051
Symbol rl is an argument at stack/frame offset 8, length 4.
11052
Symbol linebuffer is in static storage at address 0x150a18, length 4.
11053
Symbol linelength is in static storage at address 0x150a1c, length 4.
11054
Symbol p is a local variable in register $esi, length 4.
11055
Symbol p1 is a local variable in register $ebx, length 4.
11056
Symbol nline is a local variable in register $edx, length 4.
11057
Symbol repeat is a local variable at frame offset -8, length 4.
11058
@end smallexample
11059
 
11060
@noindent
11061
This command is especially useful for determining what data to collect
11062
during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
11063
collect}.
11064
 
11065
@kindex info source
11066
@item info source
11067
Show information about the current source file---that is, the source file for
11068
the function containing the current point of execution:
11069
@itemize @bullet
11070
@item
11071
the name of the source file, and the directory containing it,
11072
@item
11073
the directory it was compiled in,
11074
@item
11075
its length, in lines,
11076
@item
11077
which programming language it is written in,
11078
@item
11079
whether the executable includes debugging information for that file, and
11080
if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
11081
@item
11082
whether the debugging information includes information about
11083
preprocessor macros.
11084
@end itemize
11085
 
11086
 
11087
@kindex info sources
11088
@item info sources
11089
Print the names of all source files in your program for which there is
11090
debugging information, organized into two lists: files whose symbols
11091
have already been read, and files whose symbols will be read when needed.
11092
 
11093
@kindex info functions
11094
@item info functions
11095
Print the names and data types of all defined functions.
11096
 
11097
@item info functions @var{regexp}
11098
Print the names and data types of all defined functions
11099
whose names contain a match for regular expression @var{regexp}.
11100
Thus, @samp{info fun step} finds all functions whose names
11101
include @code{step}; @samp{info fun ^step} finds those whose names
11102
start with @code{step}.  If a function name contains characters
11103
that conflict with the regular expression language (e.g.@:
11104
@samp{operator*()}), they may be quoted with a backslash.
11105
 
11106
@kindex info variables
11107
@item info variables
11108
Print the names and data types of all variables that are declared
11109
outside of functions (i.e.@: excluding local variables).
11110
 
11111
@item info variables @var{regexp}
11112
Print the names and data types of all variables (except for local
11113
variables) whose names contain a match for regular expression
11114
@var{regexp}.
11115
 
11116
@kindex info classes
11117
@cindex Objective-C, classes and selectors
11118
@item info classes
11119
@itemx info classes @var{regexp}
11120
Display all Objective-C classes in your program, or
11121
(with the @var{regexp} argument) all those matching a particular regular
11122
expression.
11123
 
11124
@kindex info selectors
11125
@item info selectors
11126
@itemx info selectors @var{regexp}
11127
Display all Objective-C selectors in your program, or
11128
(with the @var{regexp} argument) all those matching a particular regular
11129
expression.
11130
 
11131
@ignore
11132
This was never implemented.
11133
@kindex info methods
11134
@item info methods
11135
@itemx info methods @var{regexp}
11136
The @code{info methods} command permits the user to examine all defined
11137
methods within C@t{++} program, or (with the @var{regexp} argument) a
11138
specific set of methods found in the various C@t{++} classes.  Many
11139
C@t{++} classes provide a large number of methods.  Thus, the output
11140
from the @code{ptype} command can be overwhelming and hard to use.  The
11141
@code{info-methods} command filters the methods, printing only those
11142
which match the regular-expression @var{regexp}.
11143
@end ignore
11144
 
11145
@cindex reloading symbols
11146
Some systems allow individual object files that make up your program to
11147
be replaced without stopping and restarting your program.  For example,
11148
in VxWorks you can simply recompile a defective object file and keep on
11149
running.  If you are running on one of these systems, you can allow
11150
@value{GDBN} to reload the symbols for automatically relinked modules:
11151
 
11152
@table @code
11153
@kindex set symbol-reloading
11154
@item set symbol-reloading on
11155
Replace symbol definitions for the corresponding source file when an
11156
object file with a particular name is seen again.
11157
 
11158
@item set symbol-reloading off
11159
Do not replace symbol definitions when encountering object files of the
11160
same name more than once.  This is the default state; if you are not
11161
running on a system that permits automatic relinking of modules, you
11162
should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
11163
may discard symbols when linking large programs, that may contain
11164
several modules (from different directories or libraries) with the same
11165
name.
11166
 
11167
@kindex show symbol-reloading
11168
@item show symbol-reloading
11169
Show the current @code{on} or @code{off} setting.
11170
@end table
11171
 
11172
@cindex opaque data types
11173
@kindex set opaque-type-resolution
11174
@item set opaque-type-resolution on
11175
Tell @value{GDBN} to resolve opaque types.  An opaque type is a type
11176
declared as a pointer to a @code{struct}, @code{class}, or
11177
@code{union}---for example, @code{struct MyType *}---that is used in one
11178
source file although the full declaration of @code{struct MyType} is in
11179
another source file.  The default is on.
11180
 
11181
A change in the setting of this subcommand will not take effect until
11182
the next time symbols for a file are loaded.
11183
 
11184
@item set opaque-type-resolution off
11185
Tell @value{GDBN} not to resolve opaque types.  In this case, the type
11186
is printed as follows:
11187
@smallexample
11188
@{<no data fields>@}
11189
@end smallexample
11190
 
11191
@kindex show opaque-type-resolution
11192
@item show opaque-type-resolution
11193
Show whether opaque types are resolved or not.
11194
 
11195
@kindex maint print symbols
11196
@cindex symbol dump
11197
@kindex maint print psymbols
11198
@cindex partial symbol dump
11199
@item maint print symbols @var{filename}
11200
@itemx maint print psymbols @var{filename}
11201
@itemx maint print msymbols @var{filename}
11202
Write a dump of debugging symbol data into the file @var{filename}.
11203
These commands are used to debug the @value{GDBN} symbol-reading code.  Only
11204
symbols with debugging data are included.  If you use @samp{maint print
11205
symbols}, @value{GDBN} includes all the symbols for which it has already
11206
collected full details: that is, @var{filename} reflects symbols for
11207
only those files whose symbols @value{GDBN} has read.  You can use the
11208
command @code{info sources} to find out which files these are.  If you
11209
use @samp{maint print psymbols} instead, the dump shows information about
11210
symbols that @value{GDBN} only knows partially---that is, symbols defined in
11211
files that @value{GDBN} has skimmed, but not yet read completely.  Finally,
11212
@samp{maint print msymbols} dumps just the minimal symbol information
11213
required for each object file from which @value{GDBN} has read some symbols.
11214
@xref{Files, ,Commands to Specify Files}, for a discussion of how
11215
@value{GDBN} reads symbols (in the description of @code{symbol-file}).
11216
 
11217
@kindex maint info symtabs
11218
@kindex maint info psymtabs
11219
@cindex listing @value{GDBN}'s internal symbol tables
11220
@cindex symbol tables, listing @value{GDBN}'s internal
11221
@cindex full symbol tables, listing @value{GDBN}'s internal
11222
@cindex partial symbol tables, listing @value{GDBN}'s internal
11223
@item maint info symtabs @r{[} @var{regexp} @r{]}
11224
@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
11225
 
11226
List the @code{struct symtab} or @code{struct partial_symtab}
11227
structures whose names match @var{regexp}.  If @var{regexp} is not
11228
given, list them all.  The output includes expressions which you can
11229
copy into a @value{GDBN} debugging this one to examine a particular
11230
structure in more detail.  For example:
11231
 
11232
@smallexample
11233
(@value{GDBP}) maint info psymtabs dwarf2read
11234
@{ objfile /home/gnu/build/gdb/gdb
11235
  ((struct objfile *) 0x82e69d0)
11236
  @{ psymtab /home/gnu/src/gdb/dwarf2read.c
11237
    ((struct partial_symtab *) 0x8474b10)
11238
    readin no
11239
    fullname (null)
11240
    text addresses 0x814d3c8 -- 0x8158074
11241
    globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
11242
    statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
11243
    dependencies (none)
11244
  @}
11245
@}
11246
(@value{GDBP}) maint info symtabs
11247
(@value{GDBP})
11248
@end smallexample
11249
@noindent
11250
We see that there is one partial symbol table whose filename contains
11251
the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
11252
and we see that @value{GDBN} has not read in any symtabs yet at all.
11253
If we set a breakpoint on a function, that will cause @value{GDBN} to
11254
read the symtab for the compilation unit containing that function:
11255
 
11256
@smallexample
11257
(@value{GDBP}) break dwarf2_psymtab_to_symtab
11258
Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
11259
line 1574.
11260
(@value{GDBP}) maint info symtabs
11261
@{ objfile /home/gnu/build/gdb/gdb
11262
  ((struct objfile *) 0x82e69d0)
11263
  @{ symtab /home/gnu/src/gdb/dwarf2read.c
11264
    ((struct symtab *) 0x86c1f38)
11265
    dirname (null)
11266
    fullname (null)
11267
    blockvector ((struct blockvector *) 0x86c1bd0) (primary)
11268
    linetable ((struct linetable *) 0x8370fa0)
11269
    debugformat DWARF 2
11270
  @}
11271
@}
11272
(@value{GDBP})
11273
@end smallexample
11274
@end table
11275
 
11276
 
11277
@node Altering
11278
@chapter Altering Execution
11279
 
11280
Once you think you have found an error in your program, you might want to
11281
find out for certain whether correcting the apparent error would lead to
11282
correct results in the rest of the run.  You can find the answer by
11283
experiment, using the @value{GDBN} features for altering execution of the
11284
program.
11285
 
11286
For example, you can store new values into variables or memory
11287
locations, give your program a signal, restart it at a different
11288
address, or even return prematurely from a function.
11289
 
11290
@menu
11291
* Assignment::                  Assignment to variables
11292
* Jumping::                     Continuing at a different address
11293
* Signaling::                   Giving your program a signal
11294
* Returning::                   Returning from a function
11295
* Calling::                     Calling your program's functions
11296
* Patching::                    Patching your program
11297
@end menu
11298
 
11299
@node Assignment
11300
@section Assignment to Variables
11301
 
11302
@cindex assignment
11303
@cindex setting variables
11304
To alter the value of a variable, evaluate an assignment expression.
11305
@xref{Expressions, ,Expressions}.  For example,
11306
 
11307
@smallexample
11308
print x=4
11309
@end smallexample
11310
 
11311
@noindent
11312
stores the value 4 into the variable @code{x}, and then prints the
11313
value of the assignment expression (which is 4).
11314
@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
11315
information on operators in supported languages.
11316
 
11317
@kindex set variable
11318
@cindex variables, setting
11319
If you are not interested in seeing the value of the assignment, use the
11320
@code{set} command instead of the @code{print} command.  @code{set} is
11321
really the same as @code{print} except that the expression's value is
11322
not printed and is not put in the value history (@pxref{Value History,
11323
,Value History}).  The expression is evaluated only for its effects.
11324
 
11325
If the beginning of the argument string of the @code{set} command
11326
appears identical to a @code{set} subcommand, use the @code{set
11327
variable} command instead of just @code{set}.  This command is identical
11328
to @code{set} except for its lack of subcommands.  For example, if your
11329
program has a variable @code{width}, you get an error if you try to set
11330
a new value with just @samp{set width=13}, because @value{GDBN} has the
11331
command @code{set width}:
11332
 
11333
@smallexample
11334
(@value{GDBP}) whatis width
11335
type = double
11336
(@value{GDBP}) p width
11337
$4 = 13
11338
(@value{GDBP}) set width=47
11339
Invalid syntax in expression.
11340
@end smallexample
11341
 
11342
@noindent
11343
The invalid expression, of course, is @samp{=47}.  In
11344
order to actually set the program's variable @code{width}, use
11345
 
11346
@smallexample
11347
(@value{GDBP}) set var width=47
11348
@end smallexample
11349
 
11350
Because the @code{set} command has many subcommands that can conflict
11351
with the names of program variables, it is a good idea to use the
11352
@code{set variable} command instead of just @code{set}.  For example, if
11353
your program has a variable @code{g}, you run into problems if you try
11354
to set a new value with just @samp{set g=4}, because @value{GDBN} has
11355
the command @code{set gnutarget}, abbreviated @code{set g}:
11356
 
11357
@smallexample
11358
@group
11359
(@value{GDBP}) whatis g
11360
type = double
11361
(@value{GDBP}) p g
11362
$1 = 1
11363
(@value{GDBP}) set g=4
11364
(@value{GDBP}) p g
11365
$2 = 1
11366
(@value{GDBP}) r
11367
The program being debugged has been started already.
11368
Start it from the beginning? (y or n) y
11369
Starting program: /home/smith/cc_progs/a.out
11370
"/home/smith/cc_progs/a.out": can't open to read symbols:
11371
                                 Invalid bfd target.
11372
(@value{GDBP}) show g
11373
The current BFD target is "=4".
11374
@end group
11375
@end smallexample
11376
 
11377
@noindent
11378
The program variable @code{g} did not change, and you silently set the
11379
@code{gnutarget} to an invalid value.  In order to set the variable
11380
@code{g}, use
11381
 
11382
@smallexample
11383
(@value{GDBP}) set var g=4
11384
@end smallexample
11385
 
11386
@value{GDBN} allows more implicit conversions in assignments than C; you can
11387
freely store an integer value into a pointer variable or vice versa,
11388
and you can convert any structure to any other structure that is the
11389
same length or shorter.
11390
@comment FIXME: how do structs align/pad in these conversions?
11391
@comment        /doc@cygnus.com 18dec1990
11392
 
11393
To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
11394
construct to generate a value of specified type at a specified address
11395
(@pxref{Expressions, ,Expressions}).  For example, @code{@{int@}0x83040} refers
11396
to memory location @code{0x83040} as an integer (which implies a certain size
11397
and representation in memory), and
11398
 
11399
@smallexample
11400
set @{int@}0x83040 = 4
11401
@end smallexample
11402
 
11403
@noindent
11404
stores the value 4 into that memory location.
11405
 
11406
@node Jumping
11407
@section Continuing at a Different Address
11408
 
11409
Ordinarily, when you continue your program, you do so at the place where
11410
it stopped, with the @code{continue} command.  You can instead continue at
11411
an address of your own choosing, with the following commands:
11412
 
11413
@table @code
11414
@kindex jump
11415
@item jump @var{linespec}
11416
@itemx jump @var{location}
11417
Resume execution at line @var{linespec} or at address given by
11418
@var{location}.  Execution stops again immediately if there is a
11419
breakpoint there.  @xref{Specify Location}, for a description of the
11420
different forms of @var{linespec} and @var{location}.  It is common
11421
practice to use the @code{tbreak} command in conjunction with
11422
@code{jump}.  @xref{Set Breaks, ,Setting Breakpoints}.
11423
 
11424
The @code{jump} command does not change the current stack frame, or
11425
the stack pointer, or the contents of any memory location or any
11426
register other than the program counter.  If line @var{linespec} is in
11427
a different function from the one currently executing, the results may
11428
be bizarre if the two functions expect different patterns of arguments or
11429
of local variables.  For this reason, the @code{jump} command requests
11430
confirmation if the specified line is not in the function currently
11431
executing.  However, even bizarre results are predictable if you are
11432
well acquainted with the machine-language code of your program.
11433
@end table
11434
 
11435
@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
11436
On many systems, you can get much the same effect as the @code{jump}
11437
command by storing a new value into the register @code{$pc}.  The
11438
difference is that this does not start your program running; it only
11439
changes the address of where it @emph{will} run when you continue.  For
11440
example,
11441
 
11442
@smallexample
11443
set $pc = 0x485
11444
@end smallexample
11445
 
11446
@noindent
11447
makes the next @code{continue} command or stepping command execute at
11448
address @code{0x485}, rather than at the address where your program stopped.
11449
@xref{Continuing and Stepping, ,Continuing and Stepping}.
11450
 
11451
The most common occasion to use the @code{jump} command is to back
11452
up---perhaps with more breakpoints set---over a portion of a program
11453
that has already executed, in order to examine its execution in more
11454
detail.
11455
 
11456
@c @group
11457
@node Signaling
11458
@section Giving your Program a Signal
11459
@cindex deliver a signal to a program
11460
 
11461
@table @code
11462
@kindex signal
11463
@item signal @var{signal}
11464
Resume execution where your program stopped, but immediately give it the
11465
signal @var{signal}.  @var{signal} can be the name or the number of a
11466
signal.  For example, on many systems @code{signal 2} and @code{signal
11467
SIGINT} are both ways of sending an interrupt signal.
11468
 
11469
Alternatively, if @var{signal} is zero, continue execution without
11470
giving a signal.  This is useful when your program stopped on account of
11471
a signal and would ordinary see the signal when resumed with the
11472
@code{continue} command; @samp{signal 0} causes it to resume without a
11473
signal.
11474
 
11475
@code{signal} does not repeat when you press @key{RET} a second time
11476
after executing the command.
11477
@end table
11478
@c @end group
11479
 
11480
Invoking the @code{signal} command is not the same as invoking the
11481
@code{kill} utility from the shell.  Sending a signal with @code{kill}
11482
causes @value{GDBN} to decide what to do with the signal depending on
11483
the signal handling tables (@pxref{Signals}).  The @code{signal} command
11484
passes the signal directly to your program.
11485
 
11486
 
11487
@node Returning
11488
@section Returning from a Function
11489
 
11490
@table @code
11491
@cindex returning from a function
11492
@kindex return
11493
@item return
11494
@itemx return @var{expression}
11495
You can cancel execution of a function call with the @code{return}
11496
command.  If you give an
11497
@var{expression} argument, its value is used as the function's return
11498
value.
11499
@end table
11500
 
11501
When you use @code{return}, @value{GDBN} discards the selected stack frame
11502
(and all frames within it).  You can think of this as making the
11503
discarded frame return prematurely.  If you wish to specify a value to
11504
be returned, give that value as the argument to @code{return}.
11505
 
11506
This pops the selected stack frame (@pxref{Selection, ,Selecting a
11507
Frame}), and any other frames inside of it, leaving its caller as the
11508
innermost remaining frame.  That frame becomes selected.  The
11509
specified value is stored in the registers used for returning values
11510
of functions.
11511
 
11512
The @code{return} command does not resume execution; it leaves the
11513
program stopped in the state that would exist if the function had just
11514
returned.  In contrast, the @code{finish} command (@pxref{Continuing
11515
and Stepping, ,Continuing and Stepping}) resumes execution until the
11516
selected stack frame returns naturally.
11517
 
11518
@node Calling
11519
@section Calling Program Functions
11520
 
11521
@table @code
11522
@cindex calling functions
11523
@cindex inferior functions, calling
11524
@item print @var{expr}
11525
Evaluate the expression @var{expr} and display the resulting value.
11526
@var{expr} may include calls to functions in the program being
11527
debugged.
11528
 
11529
@kindex call
11530
@item call @var{expr}
11531
Evaluate the expression @var{expr} without displaying @code{void}
11532
returned values.
11533
 
11534
You can use this variant of the @code{print} command if you want to
11535
execute a function from your program that does not return anything
11536
(a.k.a.@: @dfn{a void function}), but without cluttering the output
11537
with @code{void} returned values that @value{GDBN} will otherwise
11538
print.  If the result is not void, it is printed and saved in the
11539
value history.
11540
@end table
11541
 
11542
It is possible for the function you call via the @code{print} or
11543
@code{call} command to generate a signal (e.g., if there's a bug in
11544
the function, or if you passed it incorrect arguments).  What happens
11545
in that case is controlled by the @code{set unwindonsignal} command.
11546
 
11547
@table @code
11548
@item set unwindonsignal
11549
@kindex set unwindonsignal
11550
@cindex unwind stack in called functions
11551
@cindex call dummy stack unwinding
11552
Set unwinding of the stack if a signal is received while in a function
11553
that @value{GDBN} called in the program being debugged.  If set to on,
11554
@value{GDBN} unwinds the stack it created for the call and restores
11555
the context to what it was before the call.  If set to off (the
11556
default), @value{GDBN} stops in the frame where the signal was
11557
received.
11558
 
11559
@item show unwindonsignal
11560
@kindex show unwindonsignal
11561
Show the current setting of stack unwinding in the functions called by
11562
@value{GDBN}.
11563
@end table
11564
 
11565
@cindex weak alias functions
11566
Sometimes, a function you wish to call is actually a @dfn{weak alias}
11567
for another function.  In such case, @value{GDBN} might not pick up
11568
the type information, including the types of the function arguments,
11569
which causes @value{GDBN} to call the inferior function incorrectly.
11570
As a result, the called function will function erroneously and may
11571
even crash.  A solution to that is to use the name of the aliased
11572
function instead.
11573
 
11574
@node Patching
11575
@section Patching Programs
11576
 
11577
@cindex patching binaries
11578
@cindex writing into executables
11579
@cindex writing into corefiles
11580
 
11581
By default, @value{GDBN} opens the file containing your program's
11582
executable code (or the corefile) read-only.  This prevents accidental
11583
alterations to machine code; but it also prevents you from intentionally
11584
patching your program's binary.
11585
 
11586
If you'd like to be able to patch the binary, you can specify that
11587
explicitly with the @code{set write} command.  For example, you might
11588
want to turn on internal debugging flags, or even to make emergency
11589
repairs.
11590
 
11591
@table @code
11592
@kindex set write
11593
@item set write on
11594
@itemx set write off
11595
If you specify @samp{set write on}, @value{GDBN} opens executable and
11596
core files for both reading and writing; if you specify @samp{set write
11597
off} (the default), @value{GDBN} opens them read-only.
11598
 
11599
If you have already loaded a file, you must load it again (using the
11600
@code{exec-file} or @code{core-file} command) after changing @code{set
11601
write}, for your new setting to take effect.
11602
 
11603
@item show write
11604
@kindex show write
11605
Display whether executable files and core files are opened for writing
11606
as well as reading.
11607
@end table
11608
 
11609
@node GDB Files
11610
@chapter @value{GDBN} Files
11611
 
11612
@value{GDBN} needs to know the file name of the program to be debugged,
11613
both in order to read its symbol table and in order to start your
11614
program.  To debug a core dump of a previous run, you must also tell
11615
@value{GDBN} the name of the core dump file.
11616
 
11617
@menu
11618
* Files::                       Commands to specify files
11619
* Separate Debug Files::        Debugging information in separate files
11620
* Symbol Errors::               Errors reading symbol files
11621
@end menu
11622
 
11623
@node Files
11624
@section Commands to Specify Files
11625
 
11626
@cindex symbol table
11627
@cindex core dump file
11628
 
11629
You may want to specify executable and core dump file names.  The usual
11630
way to do this is at start-up time, using the arguments to
11631
@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
11632
Out of @value{GDBN}}).
11633
 
11634
Occasionally it is necessary to change to a different file during a
11635
@value{GDBN} session.  Or you may run @value{GDBN} and forget to
11636
specify a file you want to use.  Or you are debugging a remote target
11637
via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
11638
Program}).  In these situations the @value{GDBN} commands to specify
11639
new files are useful.
11640
 
11641
@table @code
11642
@cindex executable file
11643
@kindex file
11644
@item file @var{filename}
11645
Use @var{filename} as the program to be debugged.  It is read for its
11646
symbols and for the contents of pure memory.  It is also the program
11647
executed when you use the @code{run} command.  If you do not specify a
11648
directory and the file is not found in the @value{GDBN} working directory,
11649
@value{GDBN} uses the environment variable @code{PATH} as a list of
11650
directories to search, just as the shell does when looking for a program
11651
to run.  You can change the value of this variable, for both @value{GDBN}
11652
and your program, using the @code{path} command.
11653
 
11654
@cindex unlinked object files
11655
@cindex patching object files
11656
You can load unlinked object @file{.o} files into @value{GDBN} using
11657
the @code{file} command.  You will not be able to ``run'' an object
11658
file, but you can disassemble functions and inspect variables.  Also,
11659
if the underlying BFD functionality supports it, you could use
11660
@kbd{gdb -write} to patch object files using this technique.  Note
11661
that @value{GDBN} can neither interpret nor modify relocations in this
11662
case, so branches and some initialized variables will appear to go to
11663
the wrong place.  But this feature is still handy from time to time.
11664
 
11665
@item file
11666
@code{file} with no argument makes @value{GDBN} discard any information it
11667
has on both executable file and the symbol table.
11668
 
11669
@kindex exec-file
11670
@item exec-file @r{[} @var{filename} @r{]}
11671
Specify that the program to be run (but not the symbol table) is found
11672
in @var{filename}.  @value{GDBN} searches the environment variable @code{PATH}
11673
if necessary to locate your program.  Omitting @var{filename} means to
11674
discard information on the executable file.
11675
 
11676
@kindex symbol-file
11677
@item symbol-file @r{[} @var{filename} @r{]}
11678
Read symbol table information from file @var{filename}.  @code{PATH} is
11679
searched when necessary.  Use the @code{file} command to get both symbol
11680
table and program to run from the same file.
11681
 
11682
@code{symbol-file} with no argument clears out @value{GDBN} information on your
11683
program's symbol table.
11684
 
11685
The @code{symbol-file} command causes @value{GDBN} to forget the contents of
11686
some breakpoints and auto-display expressions.  This is because they may
11687
contain pointers to the internal data recording symbols and data types,
11688
which are part of the old symbol table data being discarded inside
11689
@value{GDBN}.
11690
 
11691
@code{symbol-file} does not repeat if you press @key{RET} again after
11692
executing it once.
11693
 
11694
When @value{GDBN} is configured for a particular environment, it
11695
understands debugging information in whatever format is the standard
11696
generated for that environment; you may use either a @sc{gnu} compiler, or
11697
other compilers that adhere to the local conventions.
11698
Best results are usually obtained from @sc{gnu} compilers; for example,
11699
using @code{@value{NGCC}} you can generate debugging information for
11700
optimized code.
11701
 
11702
For most kinds of object files, with the exception of old SVR3 systems
11703
using COFF, the @code{symbol-file} command does not normally read the
11704
symbol table in full right away.  Instead, it scans the symbol table
11705
quickly to find which source files and which symbols are present.  The
11706
details are read later, one source file at a time, as they are needed.
11707
 
11708
The purpose of this two-stage reading strategy is to make @value{GDBN}
11709
start up faster.  For the most part, it is invisible except for
11710
occasional pauses while the symbol table details for a particular source
11711
file are being read.  (The @code{set verbose} command can turn these
11712
pauses into messages if desired.  @xref{Messages/Warnings, ,Optional
11713
Warnings and Messages}.)
11714
 
11715
We have not implemented the two-stage strategy for COFF yet.  When the
11716
symbol table is stored in COFF format, @code{symbol-file} reads the
11717
symbol table data in full right away.  Note that ``stabs-in-COFF''
11718
still does the two-stage strategy, since the debug info is actually
11719
in stabs format.
11720
 
11721
@kindex readnow
11722
@cindex reading symbols immediately
11723
@cindex symbols, reading immediately
11724
@item symbol-file @var{filename} @r{[} -readnow @r{]}
11725
@itemx file @var{filename} @r{[} -readnow @r{]}
11726
You can override the @value{GDBN} two-stage strategy for reading symbol
11727
tables by using the @samp{-readnow} option with any of the commands that
11728
load symbol table information, if you want to be sure @value{GDBN} has the
11729
entire symbol table available.
11730
 
11731
@c FIXME: for now no mention of directories, since this seems to be in
11732
@c flux.  13mar1992 status is that in theory GDB would look either in
11733
@c current dir or in same dir as myprog; but issues like competing
11734
@c GDB's, or clutter in system dirs, mean that in practice right now
11735
@c only current dir is used.  FFish says maybe a special GDB hierarchy
11736
@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
11737
@c files.
11738
 
11739
@kindex core-file
11740
@item core-file @r{[}@var{filename}@r{]}
11741
@itemx core
11742
Specify the whereabouts of a core dump file to be used as the ``contents
11743
of memory''.  Traditionally, core files contain only some parts of the
11744
address space of the process that generated them; @value{GDBN} can access the
11745
executable file itself for other parts.
11746
 
11747
@code{core-file} with no argument specifies that no core file is
11748
to be used.
11749
 
11750
Note that the core file is ignored when your program is actually running
11751
under @value{GDBN}.  So, if you have been running your program and you
11752
wish to debug a core file instead, you must kill the subprocess in which
11753
the program is running.  To do this, use the @code{kill} command
11754
(@pxref{Kill Process, ,Killing the Child Process}).
11755
 
11756
@kindex add-symbol-file
11757
@cindex dynamic linking
11758
@item add-symbol-file @var{filename} @var{address}
11759
@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
11760
@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
11761
The @code{add-symbol-file} command reads additional symbol table
11762
information from the file @var{filename}.  You would use this command
11763
when @var{filename} has been dynamically loaded (by some other means)
11764
into the program that is running.  @var{address} should be the memory
11765
address at which the file has been loaded; @value{GDBN} cannot figure
11766
this out for itself.  You can additionally specify an arbitrary number
11767
of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
11768
section name and base address for that section.  You can specify any
11769
@var{address} as an expression.
11770
 
11771
The symbol table of the file @var{filename} is added to the symbol table
11772
originally read with the @code{symbol-file} command.  You can use the
11773
@code{add-symbol-file} command any number of times; the new symbol data
11774
thus read keeps adding to the old.  To discard all old symbol data
11775
instead, use the @code{symbol-file} command without any arguments.
11776
 
11777
@cindex relocatable object files, reading symbols from
11778
@cindex object files, relocatable, reading symbols from
11779
@cindex reading symbols from relocatable object files
11780
@cindex symbols, reading from relocatable object files
11781
@cindex @file{.o} files, reading symbols from
11782
Although @var{filename} is typically a shared library file, an
11783
executable file, or some other object file which has been fully
11784
relocated for loading into a process, you can also load symbolic
11785
information from relocatable @file{.o} files, as long as:
11786
 
11787
@itemize @bullet
11788
@item
11789
the file's symbolic information refers only to linker symbols defined in
11790
that file, not to symbols defined by other object files,
11791
@item
11792
every section the file's symbolic information refers to has actually
11793
been loaded into the inferior, as it appears in the file, and
11794
@item
11795
you can determine the address at which every section was loaded, and
11796
provide these to the @code{add-symbol-file} command.
11797
@end itemize
11798
 
11799
@noindent
11800
Some embedded operating systems, like Sun Chorus and VxWorks, can load
11801
relocatable files into an already running program; such systems
11802
typically make the requirements above easy to meet.  However, it's
11803
important to recognize that many native systems use complex link
11804
procedures (@code{.linkonce} section factoring and C@t{++} constructor table
11805
assembly, for example) that make the requirements difficult to meet.  In
11806
general, one cannot assume that using @code{add-symbol-file} to read a
11807
relocatable object file's symbolic information will have the same effect
11808
as linking the relocatable object file into the program in the normal
11809
way.
11810
 
11811
@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
11812
 
11813
@kindex add-symbol-file-from-memory
11814
@cindex @code{syscall DSO}
11815
@cindex load symbols from memory
11816
@item add-symbol-file-from-memory @var{address}
11817
Load symbols from the given @var{address} in a dynamically loaded
11818
object file whose image is mapped directly into the inferior's memory.
11819
For example, the Linux kernel maps a @code{syscall DSO} into each
11820
process's address space; this DSO provides kernel-specific code for
11821
some system calls.  The argument can be any expression whose
11822
evaluation yields the address of the file's shared object file header.
11823
For this command to work, you must have used @code{symbol-file} or
11824
@code{exec-file} commands in advance.
11825
 
11826
@kindex add-shared-symbol-files
11827
@kindex assf
11828
@item add-shared-symbol-files @var{library-file}
11829
@itemx assf @var{library-file}
11830
The @code{add-shared-symbol-files} command can currently be used only
11831
in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
11832
alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
11833
@value{GDBN} automatically looks for shared libraries, however if
11834
@value{GDBN} does not find yours, you can invoke
11835
@code{add-shared-symbol-files}.  It takes one argument: the shared
11836
library's file name.  @code{assf} is a shorthand alias for
11837
@code{add-shared-symbol-files}.
11838
 
11839
@kindex section
11840
@item section @var{section} @var{addr}
11841
The @code{section} command changes the base address of the named
11842
@var{section} of the exec file to @var{addr}.  This can be used if the
11843
exec file does not contain section addresses, (such as in the
11844
@code{a.out} format), or when the addresses specified in the file
11845
itself are wrong.  Each section must be changed separately.  The
11846
@code{info files} command, described below, lists all the sections and
11847
their addresses.
11848
 
11849
@kindex info files
11850
@kindex info target
11851
@item info files
11852
@itemx info target
11853
@code{info files} and @code{info target} are synonymous; both print the
11854
current target (@pxref{Targets, ,Specifying a Debugging Target}),
11855
including the names of the executable and core dump files currently in
11856
use by @value{GDBN}, and the files from which symbols were loaded.  The
11857
command @code{help target} lists all possible targets rather than
11858
current ones.
11859
 
11860
@kindex maint info sections
11861
@item maint info sections
11862
Another command that can give you extra information about program sections
11863
is @code{maint info sections}.  In addition to the section information
11864
displayed by @code{info files}, this command displays the flags and file
11865
offset of each section in the executable and core dump files.  In addition,
11866
@code{maint info sections} provides the following command options (which
11867
may be arbitrarily combined):
11868
 
11869
@table @code
11870
@item ALLOBJ
11871
Display sections for all loaded object files, including shared libraries.
11872
@item @var{sections}
11873
Display info only for named @var{sections}.
11874
@item @var{section-flags}
11875
Display info only for sections for which @var{section-flags} are true.
11876
The section flags that @value{GDBN} currently knows about are:
11877
@table @code
11878
@item ALLOC
11879
Section will have space allocated in the process when loaded.
11880
Set for all sections except those containing debug information.
11881
@item LOAD
11882
Section will be loaded from the file into the child process memory.
11883
Set for pre-initialized code and data, clear for @code{.bss} sections.
11884
@item RELOC
11885
Section needs to be relocated before loading.
11886
@item READONLY
11887
Section cannot be modified by the child process.
11888
@item CODE
11889
Section contains executable code only.
11890
@item DATA
11891
Section contains data only (no executable code).
11892
@item ROM
11893
Section will reside in ROM.
11894
@item CONSTRUCTOR
11895
Section contains data for constructor/destructor lists.
11896
@item HAS_CONTENTS
11897
Section is not empty.
11898
@item NEVER_LOAD
11899
An instruction to the linker to not output the section.
11900
@item COFF_SHARED_LIBRARY
11901
A notification to the linker that the section contains
11902
COFF shared library information.
11903
@item IS_COMMON
11904
Section contains common symbols.
11905
@end table
11906
@end table
11907
@kindex set trust-readonly-sections
11908
@cindex read-only sections
11909
@item set trust-readonly-sections on
11910
Tell @value{GDBN} that readonly sections in your object file
11911
really are read-only (i.e.@: that their contents will not change).
11912
In that case, @value{GDBN} can fetch values from these sections
11913
out of the object file, rather than from the target program.
11914
For some targets (notably embedded ones), this can be a significant
11915
enhancement to debugging performance.
11916
 
11917
The default is off.
11918
 
11919
@item set trust-readonly-sections off
11920
Tell @value{GDBN} not to trust readonly sections.  This means that
11921
the contents of the section might change while the program is running,
11922
and must therefore be fetched from the target when needed.
11923
 
11924
@item show trust-readonly-sections
11925
Show the current setting of trusting readonly sections.
11926
@end table
11927
 
11928
All file-specifying commands allow both absolute and relative file names
11929
as arguments.  @value{GDBN} always converts the file name to an absolute file
11930
name and remembers it that way.
11931
 
11932
@cindex shared libraries
11933
@anchor{Shared Libraries}
11934
@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
11935
and IBM RS/6000 AIX shared libraries.
11936
 
11937
On MS-Windows @value{GDBN} must be linked with the Expat library to support
11938
shared libraries.  @xref{Expat}.
11939
 
11940
@value{GDBN} automatically loads symbol definitions from shared libraries
11941
when you use the @code{run} command, or when you examine a core file.
11942
(Before you issue the @code{run} command, @value{GDBN} does not understand
11943
references to a function in a shared library, however---unless you are
11944
debugging a core file).
11945
 
11946
On HP-UX, if the program loads a library explicitly, @value{GDBN}
11947
automatically loads the symbols at the time of the @code{shl_load} call.
11948
 
11949
@c FIXME: some @value{GDBN} release may permit some refs to undef
11950
@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11951
@c FIXME...lib; check this from time to time when updating manual
11952
 
11953
There are times, however, when you may wish to not automatically load
11954
symbol definitions from shared libraries, such as when they are
11955
particularly large or there are many of them.
11956
 
11957
To control the automatic loading of shared library symbols, use the
11958
commands:
11959
 
11960
@table @code
11961
@kindex set auto-solib-add
11962
@item set auto-solib-add @var{mode}
11963
If @var{mode} is @code{on}, symbols from all shared object libraries
11964
will be loaded automatically when the inferior begins execution, you
11965
attach to an independently started inferior, or when the dynamic linker
11966
informs @value{GDBN} that a new library has been loaded.  If @var{mode}
11967
is @code{off}, symbols must be loaded manually, using the
11968
@code{sharedlibrary} command.  The default value is @code{on}.
11969
 
11970
@cindex memory used for symbol tables
11971
If your program uses lots of shared libraries with debug info that
11972
takes large amounts of memory, you can decrease the @value{GDBN}
11973
memory footprint by preventing it from automatically loading the
11974
symbols from shared libraries.  To that end, type @kbd{set
11975
auto-solib-add off} before running the inferior, then load each
11976
library whose debug symbols you do need with @kbd{sharedlibrary
11977
@var{regexp}}, where @var{regexp} is a regular expression that matches
11978
the libraries whose symbols you want to be loaded.
11979
 
11980
@kindex show auto-solib-add
11981
@item show auto-solib-add
11982
Display the current autoloading mode.
11983
@end table
11984
 
11985
@cindex load shared library
11986
To explicitly load shared library symbols, use the @code{sharedlibrary}
11987
command:
11988
 
11989
@table @code
11990
@kindex info sharedlibrary
11991
@kindex info share
11992
@item info share
11993
@itemx info sharedlibrary
11994
Print the names of the shared libraries which are currently loaded.
11995
 
11996
@kindex sharedlibrary
11997
@kindex share
11998
@item sharedlibrary @var{regex}
11999
@itemx share @var{regex}
12000
Load shared object library symbols for files matching a
12001
Unix regular expression.
12002
As with files loaded automatically, it only loads shared libraries
12003
required by your program for a core file or after typing @code{run}.  If
12004
@var{regex} is omitted all shared libraries required by your program are
12005
loaded.
12006
 
12007
@item nosharedlibrary
12008
@kindex nosharedlibrary
12009
@cindex unload symbols from shared libraries
12010
Unload all shared object library symbols.  This discards all symbols
12011
that have been loaded from all shared libraries.  Symbols from shared
12012
libraries that were loaded by explicit user requests are not
12013
discarded.
12014
@end table
12015
 
12016
Sometimes you may wish that @value{GDBN} stops and gives you control
12017
when any of shared library events happen.  Use the @code{set
12018
stop-on-solib-events} command for this:
12019
 
12020
@table @code
12021
@item set stop-on-solib-events
12022
@kindex set stop-on-solib-events
12023
This command controls whether @value{GDBN} should give you control
12024
when the dynamic linker notifies it about some shared library event.
12025
The most common event of interest is loading or unloading of a new
12026
shared library.
12027
 
12028
@item show stop-on-solib-events
12029
@kindex show stop-on-solib-events
12030
Show whether @value{GDBN} stops and gives you control when shared
12031
library events happen.
12032
@end table
12033
 
12034
Shared libraries are also supported in many cross or remote debugging
12035
configurations.  A copy of the target's libraries need to be present on the
12036
host system; they need to be the same as the target libraries, although the
12037
copies on the target can be stripped as long as the copies on the host are
12038
not.
12039
 
12040
@cindex where to look for shared libraries
12041
For remote debugging, you need to tell @value{GDBN} where the target
12042
libraries are, so that it can load the correct copies---otherwise, it
12043
may try to load the host's libraries.  @value{GDBN} has two variables
12044
to specify the search directories for target libraries.
12045
 
12046
@table @code
12047
@cindex prefix for shared library file names
12048
@cindex system root, alternate
12049
@kindex set solib-absolute-prefix
12050
@kindex set sysroot
12051
@item set sysroot @var{path}
12052
Use @var{path} as the system root for the program being debugged.  Any
12053
absolute shared library paths will be prefixed with @var{path}; many
12054
runtime loaders store the absolute paths to the shared library in the
12055
target program's memory.  If you use @code{set sysroot} to find shared
12056
libraries, they need to be laid out in the same way that they are on
12057
the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
12058
under @var{path}.
12059
 
12060
The @code{set solib-absolute-prefix} command is an alias for @code{set
12061
sysroot}.
12062
 
12063
@cindex default system root
12064
@cindex @samp{--with-sysroot}
12065
You can set the default system root by using the configure-time
12066
@samp{--with-sysroot} option.  If the system root is inside
12067
@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
12068
@samp{--exec-prefix}), then the default system root will be updated
12069
automatically if the installed @value{GDBN} is moved to a new
12070
location.
12071
 
12072
@kindex show sysroot
12073
@item show sysroot
12074
Display the current shared library prefix.
12075
 
12076
@kindex set solib-search-path
12077
@item set solib-search-path @var{path}
12078
If this variable is set, @var{path} is a colon-separated list of
12079
directories to search for shared libraries.  @samp{solib-search-path}
12080
is used after @samp{sysroot} fails to locate the library, or if the
12081
path to the library is relative instead of absolute.  If you want to
12082
use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
12083
@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
12084
finding your host's libraries.  @samp{sysroot} is preferred; setting
12085
it to a nonexistent directory may interfere with automatic loading
12086
of shared library symbols.
12087
 
12088
@kindex show solib-search-path
12089
@item show solib-search-path
12090
Display the current shared library search path.
12091
@end table
12092
 
12093
 
12094
@node Separate Debug Files
12095
@section Debugging Information in Separate Files
12096
@cindex separate debugging information files
12097
@cindex debugging information in separate files
12098
@cindex @file{.debug} subdirectories
12099
@cindex debugging information directory, global
12100
@cindex global debugging information directory
12101
@cindex build ID, and separate debugging files
12102
@cindex @file{.build-id} directory
12103
 
12104
@value{GDBN} allows you to put a program's debugging information in a
12105
file separate from the executable itself, in a way that allows
12106
@value{GDBN} to find and load the debugging information automatically.
12107
Since debugging information can be very large---sometimes larger
12108
than the executable code itself---some systems distribute debugging
12109
information for their executables in separate files, which users can
12110
install only when they need to debug a problem.
12111
 
12112
@value{GDBN} supports two ways of specifying the separate debug info
12113
file:
12114
 
12115
@itemize @bullet
12116
@item
12117
The executable contains a @dfn{debug link} that specifies the name of
12118
the separate debug info file.  The separate debug file's name is
12119
usually @file{@var{executable}.debug}, where @var{executable} is the
12120
name of the corresponding executable file without leading directories
12121
(e.g., @file{ls.debug} for @file{/usr/bin/ls}).  In addition, the
12122
debug link specifies a CRC32 checksum for the debug file, which
12123
@value{GDBN} uses to validate that the executable and the debug file
12124
came from the same build.
12125
 
12126
@item
12127
The executable contains a @dfn{build ID}, a unique bit string that is
12128
also present in the corresponding debug info file.  (This is supported
12129
only on some operating systems, notably those which use the ELF format
12130
for binary files and the @sc{gnu} Binutils.)  For more details about
12131
this feature, see the description of the @option{--build-id}
12132
command-line option in @ref{Options, , Command Line Options, ld.info,
12133
The GNU Linker}.  The debug info file's name is not specified
12134
explicitly by the build ID, but can be computed from the build ID, see
12135
below.
12136
@end itemize
12137
 
12138
Depending on the way the debug info file is specified, @value{GDBN}
12139
uses two different methods of looking for the debug file:
12140
 
12141
@itemize @bullet
12142
@item
12143
For the ``debug link'' method, @value{GDBN} looks up the named file in
12144
the directory of the executable file, then in a subdirectory of that
12145
directory named @file{.debug}, and finally under the global debug
12146
directory, in a subdirectory whose name is identical to the leading
12147
directories of the executable's absolute file name.
12148
 
12149
@item
12150
For the ``build ID'' method, @value{GDBN} looks in the
12151
@file{.build-id} subdirectory of the global debug directory for a file
12152
named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
12153
first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
12154
are the rest of the bit string.  (Real build ID strings are 32 or more
12155
hex characters, not 10.)
12156
@end itemize
12157
 
12158
So, for example, suppose you ask @value{GDBN} to debug
12159
@file{/usr/bin/ls}, which has a debug link that specifies the
12160
file @file{ls.debug}, and a build ID whose value in hex is
12161
@code{abcdef1234}.  If the global debug directory is
12162
@file{/usr/lib/debug}, then @value{GDBN} will look for the following
12163
debug information files, in the indicated order:
12164
 
12165
@itemize @minus
12166
@item
12167
@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
12168
@item
12169
@file{/usr/bin/ls.debug}
12170
@item
12171
@file{/usr/bin/.debug/ls.debug}
12172
@item
12173
@file{/usr/lib/debug/usr/bin/ls.debug}.
12174
@end itemize
12175
 
12176
You can set the global debugging info directory's name, and view the
12177
name @value{GDBN} is currently using.
12178
 
12179
@table @code
12180
 
12181
@kindex set debug-file-directory
12182
@item set debug-file-directory @var{directory}
12183
Set the directory which @value{GDBN} searches for separate debugging
12184
information files to @var{directory}.
12185
 
12186
@kindex show debug-file-directory
12187
@item show debug-file-directory
12188
Show the directory @value{GDBN} searches for separate debugging
12189
information files.
12190
 
12191
@end table
12192
 
12193
@cindex @code{.gnu_debuglink} sections
12194
@cindex debug link sections
12195
A debug link is a special section of the executable file named
12196
@code{.gnu_debuglink}.  The section must contain:
12197
 
12198
@itemize
12199
@item
12200
A filename, with any leading directory components removed, followed by
12201
a zero byte,
12202
@item
12203
zero to three bytes of padding, as needed to reach the next four-byte
12204
boundary within the section, and
12205
@item
12206
a four-byte CRC checksum, stored in the same endianness used for the
12207
executable file itself.  The checksum is computed on the debugging
12208
information file's full contents by the function given below, passing
12209
zero as the @var{crc} argument.
12210
@end itemize
12211
 
12212
Any executable file format can carry a debug link, as long as it can
12213
contain a section named @code{.gnu_debuglink} with the contents
12214
described above.
12215
 
12216
@cindex @code{.note.gnu.build-id} sections
12217
@cindex build ID sections
12218
The build ID is a special section in the executable file (and in other
12219
ELF binary files that @value{GDBN} may consider).  This section is
12220
often named @code{.note.gnu.build-id}, but that name is not mandatory.
12221
It contains unique identification for the built files---the ID remains
12222
the same across multiple builds of the same build tree.  The default
12223
algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
12224
content for the build ID string.  The same section with an identical
12225
value is present in the original built binary with symbols, in its
12226
stripped variant, and in the separate debugging information file.
12227
 
12228
The debugging information file itself should be an ordinary
12229
executable, containing a full set of linker symbols, sections, and
12230
debugging information.  The sections of the debugging information file
12231
should have the same names, addresses, and sizes as the original file,
12232
but they need not contain any data---much like a @code{.bss} section
12233
in an ordinary executable.
12234
 
12235
The @sc{gnu} binary utilities (Binutils) package includes the
12236
@samp{objcopy} utility that can produce
12237
the separated executable / debugging information file pairs using the
12238
following commands:
12239
 
12240
@smallexample
12241
@kbd{objcopy --only-keep-debug foo foo.debug}
12242
@kbd{strip -g foo}
12243
@end smallexample
12244
 
12245
@noindent
12246
These commands remove the debugging
12247
information from the executable file @file{foo} and place it in the file
12248
@file{foo.debug}.  You can use the first, second or both methods to link the
12249
two files:
12250
 
12251
@itemize @bullet
12252
@item
12253
The debug link method needs the following additional command to also leave
12254
behind a debug link in @file{foo}:
12255
 
12256
@smallexample
12257
@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
12258
@end smallexample
12259
 
12260
Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
12261
a version of the @code{strip} command such that the command @kbd{strip foo -f
12262
foo.debug} has the same functionality as the two @code{objcopy} commands and
12263
the @code{ln -s} command above, together.
12264
 
12265
@item
12266
Build ID gets embedded into the main executable using @code{ld --build-id} or
12267
the @value{NGCC} counterpart @code{gcc -Wl,--build-id}.  Build ID support plus
12268
compatibility fixes for debug files separation are present in @sc{gnu} binary
12269
utilities (Binutils) package since version 2.18.
12270
@end itemize
12271
 
12272
@noindent
12273
 
12274
Since there are many different ways to compute CRC's for the debug
12275
link (different polynomials, reversals, byte ordering, etc.), the
12276
simplest way to describe the CRC used in @code{.gnu_debuglink}
12277
sections is to give the complete code for a function that computes it:
12278
 
12279
@kindex gnu_debuglink_crc32
12280
@smallexample
12281
unsigned long
12282
gnu_debuglink_crc32 (unsigned long crc,
12283
                     unsigned char *buf, size_t len)
12284
@{
12285
  static const unsigned long crc32_table[256] =
12286
    @{
12287
      0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
12288
      0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
12289
      0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
12290
      0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
12291
      0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
12292
      0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
12293
      0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
12294
      0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
12295
      0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
12296
      0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
12297
      0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
12298
      0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
12299
      0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
12300
      0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
12301
      0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
12302
      0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
12303
      0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
12304
      0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
12305
      0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
12306
      0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
12307
      0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
12308
      0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
12309
      0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
12310
      0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
12311
      0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
12312
      0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
12313
      0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
12314
      0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
12315
      0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
12316
      0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
12317
      0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
12318
      0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
12319
      0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
12320
      0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
12321
      0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
12322
      0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
12323
      0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
12324
      0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
12325
      0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
12326
      0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
12327
      0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
12328
      0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
12329
      0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
12330
      0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
12331
      0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
12332
      0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
12333
      0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
12334
      0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
12335
      0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
12336
      0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
12337
      0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
12338
      0x2d02ef8d
12339
    @};
12340
  unsigned char *end;
12341
 
12342
  crc = ~crc & 0xffffffff;
12343
  for (end = buf + len; buf < end; ++buf)
12344
    crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
12345
  return ~crc & 0xffffffff;
12346
@}
12347
@end smallexample
12348
 
12349
@noindent
12350
This computation does not apply to the ``build ID'' method.
12351
 
12352
 
12353
@node Symbol Errors
12354
@section Errors Reading Symbol Files
12355
 
12356
While reading a symbol file, @value{GDBN} occasionally encounters problems,
12357
such as symbol types it does not recognize, or known bugs in compiler
12358
output.  By default, @value{GDBN} does not notify you of such problems, since
12359
they are relatively common and primarily of interest to people
12360
debugging compilers.  If you are interested in seeing information
12361
about ill-constructed symbol tables, you can either ask @value{GDBN} to print
12362
only one message about each such type of problem, no matter how many
12363
times the problem occurs; or you can ask @value{GDBN} to print more messages,
12364
to see how many times the problems occur, with the @code{set
12365
complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
12366
Messages}).
12367
 
12368
The messages currently printed, and their meanings, include:
12369
 
12370
@table @code
12371
@item inner block not inside outer block in @var{symbol}
12372
 
12373
The symbol information shows where symbol scopes begin and end
12374
(such as at the start of a function or a block of statements).  This
12375
error indicates that an inner scope block is not fully contained
12376
in its outer scope blocks.
12377
 
12378
@value{GDBN} circumvents the problem by treating the inner block as if it had
12379
the same scope as the outer block.  In the error message, @var{symbol}
12380
may be shown as ``@code{(don't know)}'' if the outer block is not a
12381
function.
12382
 
12383
@item block at @var{address} out of order
12384
 
12385
The symbol information for symbol scope blocks should occur in
12386
order of increasing addresses.  This error indicates that it does not
12387
do so.
12388
 
12389
@value{GDBN} does not circumvent this problem, and has trouble
12390
locating symbols in the source file whose symbols it is reading.  (You
12391
can often determine what source file is affected by specifying
12392
@code{set verbose on}.  @xref{Messages/Warnings, ,Optional Warnings and
12393
Messages}.)
12394
 
12395
@item bad block start address patched
12396
 
12397
The symbol information for a symbol scope block has a start address
12398
smaller than the address of the preceding source line.  This is known
12399
to occur in the SunOS 4.1.1 (and earlier) C compiler.
12400
 
12401
@value{GDBN} circumvents the problem by treating the symbol scope block as
12402
starting on the previous source line.
12403
 
12404
@item bad string table offset in symbol @var{n}
12405
 
12406
@cindex foo
12407
Symbol number @var{n} contains a pointer into the string table which is
12408
larger than the size of the string table.
12409
 
12410
@value{GDBN} circumvents the problem by considering the symbol to have the
12411
name @code{foo}, which may cause other problems if many symbols end up
12412
with this name.
12413
 
12414
@item unknown symbol type @code{0x@var{nn}}
12415
 
12416
The symbol information contains new data types that @value{GDBN} does
12417
not yet know how to read.  @code{0x@var{nn}} is the symbol type of the
12418
uncomprehended information, in hexadecimal.
12419
 
12420
@value{GDBN} circumvents the error by ignoring this symbol information.
12421
This usually allows you to debug your program, though certain symbols
12422
are not accessible.  If you encounter such a problem and feel like
12423
debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
12424
on @code{complain}, then go up to the function @code{read_dbx_symtab}
12425
and examine @code{*bufp} to see the symbol.
12426
 
12427
@item stub type has NULL name
12428
 
12429
@value{GDBN} could not find the full definition for a struct or class.
12430
 
12431
@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
12432
The symbol information for a C@t{++} member function is missing some
12433
information that recent versions of the compiler should have output for
12434
it.
12435
 
12436
@item info mismatch between compiler and debugger
12437
 
12438
@value{GDBN} could not parse a type specification output by the compiler.
12439
 
12440
@end table
12441
 
12442
@node Targets
12443
@chapter Specifying a Debugging Target
12444
 
12445
@cindex debugging target
12446
A @dfn{target} is the execution environment occupied by your program.
12447
 
12448
Often, @value{GDBN} runs in the same host environment as your program;
12449
in that case, the debugging target is specified as a side effect when
12450
you use the @code{file} or @code{core} commands.  When you need more
12451
flexibility---for example, running @value{GDBN} on a physically separate
12452
host, or controlling a standalone system over a serial port or a
12453
realtime system over a TCP/IP connection---you can use the @code{target}
12454
command to specify one of the target types configured for @value{GDBN}
12455
(@pxref{Target Commands, ,Commands for Managing Targets}).
12456
 
12457
@cindex target architecture
12458
It is possible to build @value{GDBN} for several different @dfn{target
12459
architectures}.  When @value{GDBN} is built like that, you can choose
12460
one of the available architectures with the @kbd{set architecture}
12461
command.
12462
 
12463
@table @code
12464
@kindex set architecture
12465
@kindex show architecture
12466
@item set architecture @var{arch}
12467
This command sets the current target architecture to @var{arch}.  The
12468
value of @var{arch} can be @code{"auto"}, in addition to one of the
12469
supported architectures.
12470
 
12471
@item show architecture
12472
Show the current target architecture.
12473
 
12474
@item set processor
12475
@itemx processor
12476
@kindex set processor
12477
@kindex show processor
12478
These are alias commands for, respectively, @code{set architecture}
12479
and @code{show architecture}.
12480
@end table
12481
 
12482
@menu
12483
* Active Targets::              Active targets
12484
* Target Commands::             Commands for managing targets
12485
* Byte Order::                  Choosing target byte order
12486
@end menu
12487
 
12488
@node Active Targets
12489
@section Active Targets
12490
 
12491
@cindex stacking targets
12492
@cindex active targets
12493
@cindex multiple targets
12494
 
12495
There are three classes of targets: processes, core files, and
12496
executable files.  @value{GDBN} can work concurrently on up to three
12497
active targets, one in each class.  This allows you to (for example)
12498
start a process and inspect its activity without abandoning your work on
12499
a core file.
12500
 
12501
For example, if you execute @samp{gdb a.out}, then the executable file
12502
@code{a.out} is the only active target.  If you designate a core file as
12503
well---presumably from a prior run that crashed and coredumped---then
12504
@value{GDBN} has two active targets and uses them in tandem, looking
12505
first in the corefile target, then in the executable file, to satisfy
12506
requests for memory addresses.  (Typically, these two classes of target
12507
are complementary, since core files contain only a program's
12508
read-write memory---variables and so on---plus machine status, while
12509
executable files contain only the program text and initialized data.)
12510
 
12511
When you type @code{run}, your executable file becomes an active process
12512
target as well.  When a process target is active, all @value{GDBN}
12513
commands requesting memory addresses refer to that target; addresses in
12514
an active core file or executable file target are obscured while the
12515
process target is active.
12516
 
12517
Use the @code{core-file} and @code{exec-file} commands to select a new
12518
core file or executable target (@pxref{Files, ,Commands to Specify
12519
Files}).  To specify as a target a process that is already running, use
12520
the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
12521
Process}).
12522
 
12523
@node Target Commands
12524
@section Commands for Managing Targets
12525
 
12526
@table @code
12527
@item target @var{type} @var{parameters}
12528
Connects the @value{GDBN} host environment to a target machine or
12529
process.  A target is typically a protocol for talking to debugging
12530
facilities.  You use the argument @var{type} to specify the type or
12531
protocol of the target machine.
12532
 
12533
Further @var{parameters} are interpreted by the target protocol, but
12534
typically include things like device names or host names to connect
12535
with, process numbers, and baud rates.
12536
 
12537
The @code{target} command does not repeat if you press @key{RET} again
12538
after executing the command.
12539
 
12540
@kindex help target
12541
@item help target
12542
Displays the names of all targets available.  To display targets
12543
currently selected, use either @code{info target} or @code{info files}
12544
(@pxref{Files, ,Commands to Specify Files}).
12545
 
12546
@item help target @var{name}
12547
Describe a particular target, including any parameters necessary to
12548
select it.
12549
 
12550
@kindex set gnutarget
12551
@item set gnutarget @var{args}
12552
@value{GDBN} uses its own library BFD to read your files.  @value{GDBN}
12553
knows whether it is reading an @dfn{executable},
12554
a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
12555
with the @code{set gnutarget} command.  Unlike most @code{target} commands,
12556
with @code{gnutarget} the @code{target} refers to a program, not a machine.
12557
 
12558
@quotation
12559
@emph{Warning:} To specify a file format with @code{set gnutarget},
12560
you must know the actual BFD name.
12561
@end quotation
12562
 
12563
@noindent
12564
@xref{Files, , Commands to Specify Files}.
12565
 
12566
@kindex show gnutarget
12567
@item show gnutarget
12568
Use the @code{show gnutarget} command to display what file format
12569
@code{gnutarget} is set to read.  If you have not set @code{gnutarget},
12570
@value{GDBN} will determine the file format for each file automatically,
12571
and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
12572
@end table
12573
 
12574
@cindex common targets
12575
Here are some common targets (available, or not, depending on the GDB
12576
configuration):
12577
 
12578
@table @code
12579
@kindex target
12580
@item target exec @var{program}
12581
@cindex executable file target
12582
An executable file.  @samp{target exec @var{program}} is the same as
12583
@samp{exec-file @var{program}}.
12584
 
12585
@item target core @var{filename}
12586
@cindex core dump file target
12587
A core dump file.  @samp{target core @var{filename}} is the same as
12588
@samp{core-file @var{filename}}.
12589
 
12590
@item target remote @var{medium}
12591
@cindex remote target
12592
A remote system connected to @value{GDBN} via a serial line or network
12593
connection.  This command tells @value{GDBN} to use its own remote
12594
protocol over @var{medium} for debugging.  @xref{Remote Debugging}.
12595
 
12596
For example, if you have a board connected to @file{/dev/ttya} on the
12597
machine running @value{GDBN}, you could say:
12598
 
12599
@smallexample
12600
target remote /dev/ttya
12601
@end smallexample
12602
 
12603
@code{target remote} supports the @code{load} command.  This is only
12604
useful if you have some other way of getting the stub to the target
12605
system, and you can put it somewhere in memory where it won't get
12606
clobbered by the download.
12607
 
12608
@item target sim
12609
@cindex built-in simulator target
12610
Builtin CPU simulator.  @value{GDBN} includes simulators for most architectures.
12611
In general,
12612
@smallexample
12613
        target sim
12614
        load
12615
        run
12616
@end smallexample
12617
@noindent
12618
works; however, you cannot assume that a specific memory map, device
12619
drivers, or even basic I/O is available, although some simulators do
12620
provide these.  For info about any processor-specific simulator details,
12621
see the appropriate section in @ref{Embedded Processors, ,Embedded
12622
Processors}.
12623
 
12624
@end table
12625
 
12626
Some configurations may include these targets as well:
12627
 
12628
@table @code
12629
 
12630
@item target nrom @var{dev}
12631
@cindex NetROM ROM emulator target
12632
NetROM ROM emulator.  This target only supports downloading.
12633
 
12634
@end table
12635
 
12636
Different targets are available on different configurations of @value{GDBN};
12637
your configuration may have more or fewer targets.
12638
 
12639
Many remote targets require you to download the executable's code once
12640
you've successfully established a connection.  You may wish to control
12641
various aspects of this process.
12642
 
12643
@table @code
12644
 
12645
@item set hash
12646
@kindex set hash@r{, for remote monitors}
12647
@cindex hash mark while downloading
12648
This command controls whether a hash mark @samp{#} is displayed while
12649
downloading a file to the remote monitor.  If on, a hash mark is
12650
displayed after each S-record is successfully downloaded to the
12651
monitor.
12652
 
12653
@item show hash
12654
@kindex show hash@r{, for remote monitors}
12655
Show the current status of displaying the hash mark.
12656
 
12657
@item set debug monitor
12658
@kindex set debug monitor
12659
@cindex display remote monitor communications
12660
Enable or disable display of communications messages between
12661
@value{GDBN} and the remote monitor.
12662
 
12663
@item show debug monitor
12664
@kindex show debug monitor
12665
Show the current status of displaying communications between
12666
@value{GDBN} and the remote monitor.
12667
@end table
12668
 
12669
@table @code
12670
 
12671
@kindex load @var{filename}
12672
@item load @var{filename}
12673
Depending on what remote debugging facilities are configured into
12674
@value{GDBN}, the @code{load} command may be available.  Where it exists, it
12675
is meant to make @var{filename} (an executable) available for debugging
12676
on the remote system---by downloading, or dynamic linking, for example.
12677
@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
12678
the @code{add-symbol-file} command.
12679
 
12680
If your @value{GDBN} does not have a @code{load} command, attempting to
12681
execute it gets the error message ``@code{You can't do that when your
12682
target is @dots{}}''
12683
 
12684
The file is loaded at whatever address is specified in the executable.
12685
For some object file formats, you can specify the load address when you
12686
link the program; for other formats, like a.out, the object file format
12687
specifies a fixed address.
12688
@c FIXME! This would be a good place for an xref to the GNU linker doc.
12689
 
12690
Depending on the remote side capabilities, @value{GDBN} may be able to
12691
load programs into flash memory.
12692
 
12693
@code{load} does not repeat if you press @key{RET} again after using it.
12694
@end table
12695
 
12696
@node Byte Order
12697
@section Choosing Target Byte Order
12698
 
12699
@cindex choosing target byte order
12700
@cindex target byte order
12701
 
12702
Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
12703
offer the ability to run either big-endian or little-endian byte
12704
orders.  Usually the executable or symbol will include a bit to
12705
designate the endian-ness, and you will not need to worry about
12706
which to use.  However, you may still find it useful to adjust
12707
@value{GDBN}'s idea of processor endian-ness manually.
12708
 
12709
@table @code
12710
@kindex set endian
12711
@item set endian big
12712
Instruct @value{GDBN} to assume the target is big-endian.
12713
 
12714
@item set endian little
12715
Instruct @value{GDBN} to assume the target is little-endian.
12716
 
12717
@item set endian auto
12718
Instruct @value{GDBN} to use the byte order associated with the
12719
executable.
12720
 
12721
@item show endian
12722
Display @value{GDBN}'s current idea of the target byte order.
12723
 
12724
@end table
12725
 
12726
Note that these commands merely adjust interpretation of symbolic
12727
data on the host, and that they have absolutely no effect on the
12728
target system.
12729
 
12730
 
12731
@node Remote Debugging
12732
@chapter Debugging Remote Programs
12733
@cindex remote debugging
12734
 
12735
If you are trying to debug a program running on a machine that cannot run
12736
@value{GDBN} in the usual way, it is often useful to use remote debugging.
12737
For example, you might use remote debugging on an operating system kernel,
12738
or on a small system which does not have a general purpose operating system
12739
powerful enough to run a full-featured debugger.
12740
 
12741
Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
12742
to make this work with particular debugging targets.  In addition,
12743
@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
12744
but not specific to any particular target system) which you can use if you
12745
write the remote stubs---the code that runs on the remote system to
12746
communicate with @value{GDBN}.
12747
 
12748
Other remote targets may be available in your
12749
configuration of @value{GDBN}; use @code{help target} to list them.
12750
 
12751
@menu
12752
* Connecting::                  Connecting to a remote target
12753
* File Transfer::               Sending files to a remote system
12754
* Server::                      Using the gdbserver program
12755
* Remote Configuration::        Remote configuration
12756
* Remote Stub::                 Implementing a remote stub
12757
@end menu
12758
 
12759
@node Connecting
12760
@section Connecting to a Remote Target
12761
 
12762
On the @value{GDBN} host machine, you will need an unstripped copy of
12763
your program, since @value{GDBN} needs symbol and debugging information.
12764
Start up @value{GDBN} as usual, using the name of the local copy of your
12765
program as the first argument.
12766
 
12767
@cindex @code{target remote}
12768
@value{GDBN} can communicate with the target over a serial line, or
12769
over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}.  In
12770
each case, @value{GDBN} uses the same protocol for debugging your
12771
program; only the medium carrying the debugging packets varies.  The
12772
@code{target remote} command establishes a connection to the target.
12773
Its arguments indicate which medium to use:
12774
 
12775
@table @code
12776
 
12777
@item target remote @var{serial-device}
12778
@cindex serial line, @code{target remote}
12779
Use @var{serial-device} to communicate with the target.  For example,
12780
to use a serial line connected to the device named @file{/dev/ttyb}:
12781
 
12782
@smallexample
12783
target remote /dev/ttyb
12784
@end smallexample
12785
 
12786
If you're using a serial line, you may want to give @value{GDBN} the
12787
@w{@samp{--baud}} option, or use the @code{set remotebaud} command
12788
(@pxref{Remote Configuration, set remotebaud}) before the
12789
@code{target} command.
12790
 
12791
@item target remote @code{@var{host}:@var{port}}
12792
@itemx target remote @code{tcp:@var{host}:@var{port}}
12793
@cindex @acronym{TCP} port, @code{target remote}
12794
Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
12795
The @var{host} may be either a host name or a numeric @acronym{IP}
12796
address; @var{port} must be a decimal number.  The @var{host} could be
12797
the target machine itself, if it is directly connected to the net, or
12798
it might be a terminal server which in turn has a serial line to the
12799
target.
12800
 
12801
For example, to connect to port 2828 on a terminal server named
12802
@code{manyfarms}:
12803
 
12804
@smallexample
12805
target remote manyfarms:2828
12806
@end smallexample
12807
 
12808
If your remote target is actually running on the same machine as your
12809
debugger session (e.g.@: a simulator for your target running on the
12810
same host), you can omit the hostname.  For example, to connect to
12811
port 1234 on your local machine:
12812
 
12813
@smallexample
12814
target remote :1234
12815
@end smallexample
12816
@noindent
12817
 
12818
Note that the colon is still required here.
12819
 
12820
@item target remote @code{udp:@var{host}:@var{port}}
12821
@cindex @acronym{UDP} port, @code{target remote}
12822
Debug using @acronym{UDP} packets to @var{port} on @var{host}.  For example, to
12823
connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
12824
 
12825
@smallexample
12826
target remote udp:manyfarms:2828
12827
@end smallexample
12828
 
12829
When using a @acronym{UDP} connection for remote debugging, you should
12830
keep in mind that the `U' stands for ``Unreliable''.  @acronym{UDP}
12831
can silently drop packets on busy or unreliable networks, which will
12832
cause havoc with your debugging session.
12833
 
12834
@item target remote | @var{command}
12835
@cindex pipe, @code{target remote} to
12836
Run @var{command} in the background and communicate with it using a
12837
pipe.  The @var{command} is a shell command, to be parsed and expanded
12838
by the system's command shell, @code{/bin/sh}; it should expect remote
12839
protocol packets on its standard input, and send replies on its
12840
standard output.  You could use this to run a stand-alone simulator
12841
that speaks the remote debugging protocol, to make net connections
12842
using programs like @code{ssh}, or for other similar tricks.
12843
 
12844
If @var{command} closes its standard output (perhaps by exiting),
12845
@value{GDBN} will try to send it a @code{SIGTERM} signal.  (If the
12846
program has already exited, this will have no effect.)
12847
 
12848
@end table
12849
 
12850
Once the connection has been established, you can use all the usual
12851
commands to examine and change data and to step and continue the
12852
remote program.
12853
 
12854
@cindex interrupting remote programs
12855
@cindex remote programs, interrupting
12856
Whenever @value{GDBN} is waiting for the remote program, if you type the
12857
interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
12858
program.  This may or may not succeed, depending in part on the hardware
12859
and the serial drivers the remote system uses.  If you type the
12860
interrupt character once again, @value{GDBN} displays this prompt:
12861
 
12862
@smallexample
12863
Interrupted while waiting for the program.
12864
Give up (and stop debugging it)?  (y or n)
12865
@end smallexample
12866
 
12867
If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
12868
(If you decide you want to try again later, you can use @samp{target
12869
remote} again to connect once more.)  If you type @kbd{n}, @value{GDBN}
12870
goes back to waiting.
12871
 
12872
@table @code
12873
@kindex detach (remote)
12874
@item detach
12875
When you have finished debugging the remote program, you can use the
12876
@code{detach} command to release it from @value{GDBN} control.
12877
Detaching from the target normally resumes its execution, but the results
12878
will depend on your particular remote stub.  After the @code{detach}
12879
command, @value{GDBN} is free to connect to another target.
12880
 
12881
@kindex disconnect
12882
@item disconnect
12883
The @code{disconnect} command behaves like @code{detach}, except that
12884
the target is generally not resumed.  It will wait for @value{GDBN}
12885
(this instance or another one) to connect and continue debugging.  After
12886
the @code{disconnect} command, @value{GDBN} is again free to connect to
12887
another target.
12888
 
12889
@cindex send command to remote monitor
12890
@cindex extend @value{GDBN} for remote targets
12891
@cindex add new commands for external monitor
12892
@kindex monitor
12893
@item monitor @var{cmd}
12894
This command allows you to send arbitrary commands directly to the
12895
remote monitor.  Since @value{GDBN} doesn't care about the commands it
12896
sends like this, this command is the way to extend @value{GDBN}---you
12897
can add new commands that only the external monitor will understand
12898
and implement.
12899
@end table
12900
 
12901
@node File Transfer
12902
@section Sending files to a remote system
12903
@cindex remote target, file transfer
12904
@cindex file transfer
12905
@cindex sending files to remote systems
12906
 
12907
Some remote targets offer the ability to transfer files over the same
12908
connection used to communicate with @value{GDBN}.  This is convenient
12909
for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
12910
running @code{gdbserver} over a network interface.  For other targets,
12911
e.g.@: embedded devices with only a single serial port, this may be
12912
the only way to upload or download files.
12913
 
12914
Not all remote targets support these commands.
12915
 
12916
@table @code
12917
@kindex remote put
12918
@item remote put @var{hostfile} @var{targetfile}
12919
Copy file @var{hostfile} from the host system (the machine running
12920
@value{GDBN}) to @var{targetfile} on the target system.
12921
 
12922
@kindex remote get
12923
@item remote get @var{targetfile} @var{hostfile}
12924
Copy file @var{targetfile} from the target system to @var{hostfile}
12925
on the host system.
12926
 
12927
@kindex remote delete
12928
@item remote delete @var{targetfile}
12929
Delete @var{targetfile} from the target system.
12930
 
12931
@end table
12932
 
12933
@node Server
12934
@section Using the @code{gdbserver} Program
12935
 
12936
@kindex gdbserver
12937
@cindex remote connection without stubs
12938
@code{gdbserver} is a control program for Unix-like systems, which
12939
allows you to connect your program with a remote @value{GDBN} via
12940
@code{target remote}---but without linking in the usual debugging stub.
12941
 
12942
@code{gdbserver} is not a complete replacement for the debugging stubs,
12943
because it requires essentially the same operating-system facilities
12944
that @value{GDBN} itself does.  In fact, a system that can run
12945
@code{gdbserver} to connect to a remote @value{GDBN} could also run
12946
@value{GDBN} locally!  @code{gdbserver} is sometimes useful nevertheless,
12947
because it is a much smaller program than @value{GDBN} itself.  It is
12948
also easier to port than all of @value{GDBN}, so you may be able to get
12949
started more quickly on a new system by using @code{gdbserver}.
12950
Finally, if you develop code for real-time systems, you may find that
12951
the tradeoffs involved in real-time operation make it more convenient to
12952
do as much development work as possible on another system, for example
12953
by cross-compiling.  You can use @code{gdbserver} to make a similar
12954
choice for debugging.
12955
 
12956
@value{GDBN} and @code{gdbserver} communicate via either a serial line
12957
or a TCP connection, using the standard @value{GDBN} remote serial
12958
protocol.
12959
 
12960
@quotation
12961
@emph{Warning:} @code{gdbserver} does not have any built-in security.
12962
Do not run @code{gdbserver} connected to any public network; a
12963
@value{GDBN} connection to @code{gdbserver} provides access to the
12964
target system with the same privileges as the user running
12965
@code{gdbserver}.
12966
@end quotation
12967
 
12968
@subsection Running @code{gdbserver}
12969
@cindex arguments, to @code{gdbserver}
12970
 
12971
Run @code{gdbserver} on the target system.  You need a copy of the
12972
program you want to debug, including any libraries it requires.
12973
@code{gdbserver} does not need your program's symbol table, so you can
12974
strip the program if necessary to save space.  @value{GDBN} on the host
12975
system does all the symbol handling.
12976
 
12977
To use the server, you must tell it how to communicate with @value{GDBN};
12978
the name of your program; and the arguments for your program.  The usual
12979
syntax is:
12980
 
12981
@smallexample
12982
target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
12983
@end smallexample
12984
 
12985
@var{comm} is either a device name (to use a serial line) or a TCP
12986
hostname and portnumber.  For example, to debug Emacs with the argument
12987
@samp{foo.txt} and communicate with @value{GDBN} over the serial port
12988
@file{/dev/com1}:
12989
 
12990
@smallexample
12991
target> gdbserver /dev/com1 emacs foo.txt
12992
@end smallexample
12993
 
12994
@code{gdbserver} waits passively for the host @value{GDBN} to communicate
12995
with it.
12996
 
12997
To use a TCP connection instead of a serial line:
12998
 
12999
@smallexample
13000
target> gdbserver host:2345 emacs foo.txt
13001
@end smallexample
13002
 
13003
The only difference from the previous example is the first argument,
13004
specifying that you are communicating with the host @value{GDBN} via
13005
TCP.  The @samp{host:2345} argument means that @code{gdbserver} is to
13006
expect a TCP connection from machine @samp{host} to local TCP port 2345.
13007
(Currently, the @samp{host} part is ignored.)  You can choose any number
13008
you want for the port number as long as it does not conflict with any
13009
TCP ports already in use on the target system (for example, @code{23} is
13010
reserved for @code{telnet}).@footnote{If you choose a port number that
13011
conflicts with another service, @code{gdbserver} prints an error message
13012
and exits.}  You must use the same port number with the host @value{GDBN}
13013
@code{target remote} command.
13014
 
13015
@subsubsection Attaching to a Running Program
13016
 
13017
On some targets, @code{gdbserver} can also attach to running programs.
13018
This is accomplished via the @code{--attach} argument.  The syntax is:
13019
 
13020
@smallexample
13021
target> gdbserver --attach @var{comm} @var{pid}
13022
@end smallexample
13023
 
13024
@var{pid} is the process ID of a currently running process.  It isn't necessary
13025
to point @code{gdbserver} at a binary for the running process.
13026
 
13027
@pindex pidof
13028
@cindex attach to a program by name
13029
You can debug processes by name instead of process ID if your target has the
13030
@code{pidof} utility:
13031
 
13032
@smallexample
13033
target> gdbserver --attach @var{comm} `pidof @var{program}`
13034
@end smallexample
13035
 
13036
In case more than one copy of @var{program} is running, or @var{program}
13037
has multiple threads, most versions of @code{pidof} support the
13038
@code{-s} option to only return the first process ID.
13039
 
13040
@subsubsection Multi-Process Mode for @code{gdbserver}
13041
@cindex gdbserver, multiple processes
13042
@cindex multiple processes with gdbserver
13043
 
13044
When you connect to @code{gdbserver} using @code{target remote},
13045
@code{gdbserver} debugs the specified program only once.  When the
13046
program exits, or you detach from it, @value{GDBN} closes the connection
13047
and @code{gdbserver} exits.
13048
 
13049
If you connect using @kbd{target extended-remote}, @code{gdbserver}
13050
enters multi-process mode.  When the debugged program exits, or you
13051
detach from it, @value{GDBN} stays connected to @code{gdbserver} even
13052
though no program is running.  The @code{run} and @code{attach}
13053
commands instruct @code{gdbserver} to run or attach to a new program.
13054
The @code{run} command uses @code{set remote exec-file} (@pxref{set
13055
remote exec-file}) to select the program to run.  Command line
13056
arguments are supported, except for wildcard expansion and I/O
13057
redirection (@pxref{Arguments}).
13058
 
13059
To start @code{gdbserver} without supplying an initial command to run
13060
or process ID to attach, use the @option{--multi} command line option.
13061
Then you can connect using @kbd{target extended-remote} and start
13062
the program you want to debug.
13063
 
13064
@code{gdbserver} does not automatically exit in multi-process mode.
13065
You can terminate it by using @code{monitor exit}
13066
(@pxref{Monitor Commands for gdbserver}).
13067
 
13068
@subsubsection Other Command-Line Arguments for @code{gdbserver}
13069
 
13070
You can include @option{--debug} on the @code{gdbserver} command line.
13071
@code{gdbserver} will display extra status information about the debugging
13072
process.  This option is intended for @code{gdbserver} development and
13073
for bug reports to the developers.
13074
 
13075
@subsection Connecting to @code{gdbserver}
13076
 
13077
Run @value{GDBN} on the host system.
13078
 
13079
First make sure you have the necessary symbol files.  Load symbols for
13080
your application using the @code{file} command before you connect.  Use
13081
@code{set sysroot} to locate target libraries (unless your @value{GDBN}
13082
was compiled with the correct sysroot using @code{--with-sysroot}).
13083
 
13084
The symbol file and target libraries must exactly match the executable
13085
and libraries on the target, with one exception: the files on the host
13086
system should not be stripped, even if the files on the target system
13087
are.  Mismatched or missing files will lead to confusing results
13088
during debugging.  On @sc{gnu}/Linux targets, mismatched or missing
13089
files may also prevent @code{gdbserver} from debugging multi-threaded
13090
programs.
13091
 
13092
Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
13093
For TCP connections, you must start up @code{gdbserver} prior to using
13094
the @code{target remote} command.  Otherwise you may get an error whose
13095
text depends on the host system, but which usually looks something like
13096
@samp{Connection refused}.  Don't use the @code{load}
13097
command in @value{GDBN} when using @code{gdbserver}, since the program is
13098
already on the target.
13099
 
13100
@subsection Monitor Commands for @code{gdbserver}
13101
@cindex monitor commands, for @code{gdbserver}
13102
@anchor{Monitor Commands for gdbserver}
13103
 
13104
During a @value{GDBN} session using @code{gdbserver}, you can use the
13105
@code{monitor} command to send special requests to @code{gdbserver}.
13106
Here are the available commands.
13107
 
13108
@table @code
13109
@item monitor help
13110
List the available monitor commands.
13111
 
13112
@item monitor set debug 0
13113
@itemx monitor set debug 1
13114
Disable or enable general debugging messages.
13115
 
13116
@item monitor set remote-debug 0
13117
@itemx monitor set remote-debug 1
13118
Disable or enable specific debugging messages associated with the remote
13119
protocol (@pxref{Remote Protocol}).
13120
 
13121
@item monitor exit
13122
Tell gdbserver to exit immediately.  This command should be followed by
13123
@code{disconnect} to close the debugging session.  @code{gdbserver} will
13124
detach from any attached processes and kill any processes it created.
13125
Use @code{monitor exit} to terminate @code{gdbserver} at the end
13126
of a multi-process mode debug session.
13127
 
13128
@end table
13129
 
13130
@node Remote Configuration
13131
@section Remote Configuration
13132
 
13133
@kindex set remote
13134
@kindex show remote
13135
This section documents the configuration options available when
13136
debugging remote programs.  For the options related to the File I/O
13137
extensions of the remote protocol, see @ref{system,
13138
system-call-allowed}.
13139
 
13140
@table @code
13141
@item set remoteaddresssize @var{bits}
13142
@cindex address size for remote targets
13143
@cindex bits in remote address
13144
Set the maximum size of address in a memory packet to the specified
13145
number of bits.  @value{GDBN} will mask off the address bits above
13146
that number, when it passes addresses to the remote target.  The
13147
default value is the number of bits in the target's address.
13148
 
13149
@item show remoteaddresssize
13150
Show the current value of remote address size in bits.
13151
 
13152
@item set remotebaud @var{n}
13153
@cindex baud rate for remote targets
13154
Set the baud rate for the remote serial I/O to @var{n} baud.  The
13155
value is used to set the speed of the serial port used for debugging
13156
remote targets.
13157
 
13158
@item show remotebaud
13159
Show the current speed of the remote connection.
13160
 
13161
@item set remotebreak
13162
@cindex interrupt remote programs
13163
@cindex BREAK signal instead of Ctrl-C
13164
@anchor{set remotebreak}
13165
If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
13166
when you type @kbd{Ctrl-c} to interrupt the program running
13167
on the remote.  If set to off, @value{GDBN} sends the @samp{Ctrl-C}
13168
character instead.  The default is off, since most remote systems
13169
expect to see @samp{Ctrl-C} as the interrupt signal.
13170
 
13171
@item show remotebreak
13172
Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
13173
interrupt the remote program.
13174
 
13175
@item set remoteflow on
13176
@itemx set remoteflow off
13177
@kindex set remoteflow
13178
Enable or disable hardware flow control (@code{RTS}/@code{CTS})
13179
on the serial port used to communicate to the remote target.
13180
 
13181
@item show remoteflow
13182
@kindex show remoteflow
13183
Show the current setting of hardware flow control.
13184
 
13185
@item set remotelogbase @var{base}
13186
Set the base (a.k.a.@: radix) of logging serial protocol
13187
communications to @var{base}.  Supported values of @var{base} are:
13188
@code{ascii}, @code{octal}, and @code{hex}.  The default is
13189
@code{ascii}.
13190
 
13191
@item show remotelogbase
13192
Show the current setting of the radix for logging remote serial
13193
protocol.
13194
 
13195
@item set remotelogfile @var{file}
13196
@cindex record serial communications on file
13197
Record remote serial communications on the named @var{file}.  The
13198
default is not to record at all.
13199
 
13200
@item show remotelogfile.
13201
Show the current setting  of the file name on which to record the
13202
serial communications.
13203
 
13204
@item set remotetimeout @var{num}
13205
@cindex timeout for serial communications
13206
@cindex remote timeout
13207
Set the timeout limit to wait for the remote target to respond to
13208
@var{num} seconds.  The default is 2 seconds.
13209
 
13210
@item show remotetimeout
13211
Show the current number of seconds to wait for the remote target
13212
responses.
13213
 
13214
@cindex limit hardware breakpoints and watchpoints
13215
@cindex remote target, limit break- and watchpoints
13216
@anchor{set remote hardware-watchpoint-limit}
13217
@anchor{set remote hardware-breakpoint-limit}
13218
@item set remote hardware-watchpoint-limit @var{limit}
13219
@itemx set remote hardware-breakpoint-limit @var{limit}
13220
Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
13221
watchpoints.  A limit of -1, the default, is treated as unlimited.
13222
 
13223
@item set remote exec-file @var{filename}
13224
@itemx show remote exec-file
13225
@anchor{set remote exec-file}
13226
@cindex executable file, for remote target
13227
Select the file used for @code{run} with @code{target
13228
extended-remote}.  This should be set to a filename valid on the
13229
target system.  If it is not set, the target will use a default
13230
filename (e.g.@: the last program run).
13231
@end table
13232
 
13233
@cindex remote packets, enabling and disabling
13234
The @value{GDBN} remote protocol autodetects the packets supported by
13235
your debugging stub.  If you need to override the autodetection, you
13236
can use these commands to enable or disable individual packets.  Each
13237
packet can be set to @samp{on} (the remote target supports this
13238
packet), @samp{off} (the remote target does not support this packet),
13239
or @samp{auto} (detect remote target support for this packet).  They
13240
all default to @samp{auto}.  For more information about each packet,
13241
see @ref{Remote Protocol}.
13242
 
13243
During normal use, you should not have to use any of these commands.
13244
If you do, that may be a bug in your remote debugging stub, or a bug
13245
in @value{GDBN}.  You may want to report the problem to the
13246
@value{GDBN} developers.
13247
 
13248
For each packet @var{name}, the command to enable or disable the
13249
packet is @code{set remote @var{name}-packet}.  The available settings
13250
are:
13251
 
13252
@multitable @columnfractions 0.28 0.32 0.25
13253
@item Command Name
13254
@tab Remote Packet
13255
@tab Related Features
13256
 
13257
@item @code{fetch-register}
13258
@tab @code{p}
13259
@tab @code{info registers}
13260
 
13261
@item @code{set-register}
13262
@tab @code{P}
13263
@tab @code{set}
13264
 
13265
@item @code{binary-download}
13266
@tab @code{X}
13267
@tab @code{load}, @code{set}
13268
 
13269
@item @code{read-aux-vector}
13270
@tab @code{qXfer:auxv:read}
13271
@tab @code{info auxv}
13272
 
13273
@item @code{symbol-lookup}
13274
@tab @code{qSymbol}
13275
@tab Detecting multiple threads
13276
 
13277
@item @code{attach}
13278
@tab @code{vAttach}
13279
@tab @code{attach}
13280
 
13281
@item @code{verbose-resume}
13282
@tab @code{vCont}
13283
@tab Stepping or resuming multiple threads
13284
 
13285
@item @code{run}
13286
@tab @code{vRun}
13287
@tab @code{run}
13288
 
13289
@item @code{software-breakpoint}
13290
@tab @code{Z0}
13291
@tab @code{break}
13292
 
13293
@item @code{hardware-breakpoint}
13294
@tab @code{Z1}
13295
@tab @code{hbreak}
13296
 
13297
@item @code{write-watchpoint}
13298
@tab @code{Z2}
13299
@tab @code{watch}
13300
 
13301
@item @code{read-watchpoint}
13302
@tab @code{Z3}
13303
@tab @code{rwatch}
13304
 
13305
@item @code{access-watchpoint}
13306
@tab @code{Z4}
13307
@tab @code{awatch}
13308
 
13309
@item @code{target-features}
13310
@tab @code{qXfer:features:read}
13311
@tab @code{set architecture}
13312
 
13313
@item @code{library-info}
13314
@tab @code{qXfer:libraries:read}
13315
@tab @code{info sharedlibrary}
13316
 
13317
@item @code{memory-map}
13318
@tab @code{qXfer:memory-map:read}
13319
@tab @code{info mem}
13320
 
13321
@item @code{read-spu-object}
13322
@tab @code{qXfer:spu:read}
13323
@tab @code{info spu}
13324
 
13325
@item @code{write-spu-object}
13326
@tab @code{qXfer:spu:write}
13327
@tab @code{info spu}
13328
 
13329
@item @code{get-thread-local-@*storage-address}
13330
@tab @code{qGetTLSAddr}
13331
@tab Displaying @code{__thread} variables
13332
 
13333
@item @code{supported-packets}
13334
@tab @code{qSupported}
13335
@tab Remote communications parameters
13336
 
13337
@item @code{pass-signals}
13338
@tab @code{QPassSignals}
13339
@tab @code{handle @var{signal}}
13340
 
13341
@item @code{hostio-close-packet}
13342
@tab @code{vFile:close}
13343
@tab @code{remote get}, @code{remote put}
13344
 
13345
@item @code{hostio-open-packet}
13346
@tab @code{vFile:open}
13347
@tab @code{remote get}, @code{remote put}
13348
 
13349
@item @code{hostio-pread-packet}
13350
@tab @code{vFile:pread}
13351
@tab @code{remote get}, @code{remote put}
13352
 
13353
@item @code{hostio-pwrite-packet}
13354
@tab @code{vFile:pwrite}
13355
@tab @code{remote get}, @code{remote put}
13356
 
13357
@item @code{hostio-unlink-packet}
13358
@tab @code{vFile:unlink}
13359
@tab @code{remote delete}
13360
@end multitable
13361
 
13362
@node Remote Stub
13363
@section Implementing a Remote Stub
13364
 
13365
@cindex debugging stub, example
13366
@cindex remote stub, example
13367
@cindex stub example, remote debugging
13368
The stub files provided with @value{GDBN} implement the target side of the
13369
communication protocol, and the @value{GDBN} side is implemented in the
13370
@value{GDBN} source file @file{remote.c}.  Normally, you can simply allow
13371
these subroutines to communicate, and ignore the details.  (If you're
13372
implementing your own stub file, you can still ignore the details: start
13373
with one of the existing stub files.  @file{sparc-stub.c} is the best
13374
organized, and therefore the easiest to read.)
13375
 
13376
@cindex remote serial debugging, overview
13377
To debug a program running on another machine (the debugging
13378
@dfn{target} machine), you must first arrange for all the usual
13379
prerequisites for the program to run by itself.  For example, for a C
13380
program, you need:
13381
 
13382
@enumerate
13383
@item
13384
A startup routine to set up the C runtime environment; these usually
13385
have a name like @file{crt0}.  The startup routine may be supplied by
13386
your hardware supplier, or you may have to write your own.
13387
 
13388
@item
13389
A C subroutine library to support your program's
13390
subroutine calls, notably managing input and output.
13391
 
13392
@item
13393
A way of getting your program to the other machine---for example, a
13394
download program.  These are often supplied by the hardware
13395
manufacturer, but you may have to write your own from hardware
13396
documentation.
13397
@end enumerate
13398
 
13399
The next step is to arrange for your program to use a serial port to
13400
communicate with the machine where @value{GDBN} is running (the @dfn{host}
13401
machine).  In general terms, the scheme looks like this:
13402
 
13403
@table @emph
13404
@item On the host,
13405
@value{GDBN} already understands how to use this protocol; when everything
13406
else is set up, you can simply use the @samp{target remote} command
13407
(@pxref{Targets,,Specifying a Debugging Target}).
13408
 
13409
@item On the target,
13410
you must link with your program a few special-purpose subroutines that
13411
implement the @value{GDBN} remote serial protocol.  The file containing these
13412
subroutines is called  a @dfn{debugging stub}.
13413
 
13414
On certain remote targets, you can use an auxiliary program
13415
@code{gdbserver} instead of linking a stub into your program.
13416
@xref{Server,,Using the @code{gdbserver} Program}, for details.
13417
@end table
13418
 
13419
The debugging stub is specific to the architecture of the remote
13420
machine; for example, use @file{sparc-stub.c} to debug programs on
13421
@sc{sparc} boards.
13422
 
13423
@cindex remote serial stub list
13424
These working remote stubs are distributed with @value{GDBN}:
13425
 
13426
@table @code
13427
 
13428
@item i386-stub.c
13429
@cindex @file{i386-stub.c}
13430
@cindex Intel
13431
@cindex i386
13432
For Intel 386 and compatible architectures.
13433
 
13434
@item m68k-stub.c
13435
@cindex @file{m68k-stub.c}
13436
@cindex Motorola 680x0
13437
@cindex m680x0
13438
For Motorola 680x0 architectures.
13439
 
13440
@item sh-stub.c
13441
@cindex @file{sh-stub.c}
13442
@cindex Renesas
13443
@cindex SH
13444
For Renesas SH architectures.
13445
 
13446
@item sparc-stub.c
13447
@cindex @file{sparc-stub.c}
13448
@cindex Sparc
13449
For @sc{sparc} architectures.
13450
 
13451
@item sparcl-stub.c
13452
@cindex @file{sparcl-stub.c}
13453
@cindex Fujitsu
13454
@cindex SparcLite
13455
For Fujitsu @sc{sparclite} architectures.
13456
 
13457
@end table
13458
 
13459
The @file{README} file in the @value{GDBN} distribution may list other
13460
recently added stubs.
13461
 
13462
@menu
13463
* Stub Contents::       What the stub can do for you
13464
* Bootstrapping::       What you must do for the stub
13465
* Debug Session::       Putting it all together
13466
@end menu
13467
 
13468
@node Stub Contents
13469
@subsection What the Stub Can Do for You
13470
 
13471
@cindex remote serial stub
13472
The debugging stub for your architecture supplies these three
13473
subroutines:
13474
 
13475
@table @code
13476
@item set_debug_traps
13477
@findex set_debug_traps
13478
@cindex remote serial stub, initialization
13479
This routine arranges for @code{handle_exception} to run when your
13480
program stops.  You must call this subroutine explicitly near the
13481
beginning of your program.
13482
 
13483
@item handle_exception
13484
@findex handle_exception
13485
@cindex remote serial stub, main routine
13486
This is the central workhorse, but your program never calls it
13487
explicitly---the setup code arranges for @code{handle_exception} to
13488
run when a trap is triggered.
13489
 
13490
@code{handle_exception} takes control when your program stops during
13491
execution (for example, on a breakpoint), and mediates communications
13492
with @value{GDBN} on the host machine.  This is where the communications
13493
protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
13494
representative on the target machine.  It begins by sending summary
13495
information on the state of your program, then continues to execute,
13496
retrieving and transmitting any information @value{GDBN} needs, until you
13497
execute a @value{GDBN} command that makes your program resume; at that point,
13498
@code{handle_exception} returns control to your own code on the target
13499
machine.
13500
 
13501
@item breakpoint
13502
@cindex @code{breakpoint} subroutine, remote
13503
Use this auxiliary subroutine to make your program contain a
13504
breakpoint.  Depending on the particular situation, this may be the only
13505
way for @value{GDBN} to get control.  For instance, if your target
13506
machine has some sort of interrupt button, you won't need to call this;
13507
pressing the interrupt button transfers control to
13508
@code{handle_exception}---in effect, to @value{GDBN}.  On some machines,
13509
simply receiving characters on the serial port may also trigger a trap;
13510
again, in that situation, you don't need to call @code{breakpoint} from
13511
your own program---simply running @samp{target remote} from the host
13512
@value{GDBN} session gets control.
13513
 
13514
Call @code{breakpoint} if none of these is true, or if you simply want
13515
to make certain your program stops at a predetermined point for the
13516
start of your debugging session.
13517
@end table
13518
 
13519
@node Bootstrapping
13520
@subsection What You Must Do for the Stub
13521
 
13522
@cindex remote stub, support routines
13523
The debugging stubs that come with @value{GDBN} are set up for a particular
13524
chip architecture, but they have no information about the rest of your
13525
debugging target machine.
13526
 
13527
First of all you need to tell the stub how to communicate with the
13528
serial port.
13529
 
13530
@table @code
13531
@item int getDebugChar()
13532
@findex getDebugChar
13533
Write this subroutine to read a single character from the serial port.
13534
It may be identical to @code{getchar} for your target system; a
13535
different name is used to allow you to distinguish the two if you wish.
13536
 
13537
@item void putDebugChar(int)
13538
@findex putDebugChar
13539
Write this subroutine to write a single character to the serial port.
13540
It may be identical to @code{putchar} for your target system; a
13541
different name is used to allow you to distinguish the two if you wish.
13542
@end table
13543
 
13544
@cindex control C, and remote debugging
13545
@cindex interrupting remote targets
13546
If you want @value{GDBN} to be able to stop your program while it is
13547
running, you need to use an interrupt-driven serial driver, and arrange
13548
for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
13549
character).  That is the character which @value{GDBN} uses to tell the
13550
remote system to stop.
13551
 
13552
Getting the debugging target to return the proper status to @value{GDBN}
13553
probably requires changes to the standard stub; one quick and dirty way
13554
is to just execute a breakpoint instruction (the ``dirty'' part is that
13555
@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
13556
 
13557
Other routines you need to supply are:
13558
 
13559
@table @code
13560
@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
13561
@findex exceptionHandler
13562
Write this function to install @var{exception_address} in the exception
13563
handling tables.  You need to do this because the stub does not have any
13564
way of knowing what the exception handling tables on your target system
13565
are like (for example, the processor's table might be in @sc{rom},
13566
containing entries which point to a table in @sc{ram}).
13567
@var{exception_number} is the exception number which should be changed;
13568
its meaning is architecture-dependent (for example, different numbers
13569
might represent divide by zero, misaligned access, etc).  When this
13570
exception occurs, control should be transferred directly to
13571
@var{exception_address}, and the processor state (stack, registers,
13572
and so on) should be just as it is when a processor exception occurs.  So if
13573
you want to use a jump instruction to reach @var{exception_address}, it
13574
should be a simple jump, not a jump to subroutine.
13575
 
13576
For the 386, @var{exception_address} should be installed as an interrupt
13577
gate so that interrupts are masked while the handler runs.  The gate
13578
should be at privilege level 0 (the most privileged level).  The
13579
@sc{sparc} and 68k stubs are able to mask interrupts themselves without
13580
help from @code{exceptionHandler}.
13581
 
13582
@item void flush_i_cache()
13583
@findex flush_i_cache
13584
On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
13585
instruction cache, if any, on your target machine.  If there is no
13586
instruction cache, this subroutine may be a no-op.
13587
 
13588
On target machines that have instruction caches, @value{GDBN} requires this
13589
function to make certain that the state of your program is stable.
13590
@end table
13591
 
13592
@noindent
13593
You must also make sure this library routine is available:
13594
 
13595
@table @code
13596
@item void *memset(void *, int, int)
13597
@findex memset
13598
This is the standard library function @code{memset} that sets an area of
13599
memory to a known value.  If you have one of the free versions of
13600
@code{libc.a}, @code{memset} can be found there; otherwise, you must
13601
either obtain it from your hardware manufacturer, or write your own.
13602
@end table
13603
 
13604
If you do not use the GNU C compiler, you may need other standard
13605
library subroutines as well; this varies from one stub to another,
13606
but in general the stubs are likely to use any of the common library
13607
subroutines which @code{@value{NGCC}} generates as inline code.
13608
 
13609
 
13610
@node Debug Session
13611
@subsection Putting it All Together
13612
 
13613
@cindex remote serial debugging summary
13614
In summary, when your program is ready to debug, you must follow these
13615
steps.
13616
 
13617
@enumerate
13618
@item
13619
Make sure you have defined the supporting low-level routines
13620
(@pxref{Bootstrapping,,What You Must Do for the Stub}):
13621
@display
13622
@code{getDebugChar}, @code{putDebugChar},
13623
@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
13624
@end display
13625
 
13626
@item
13627
Insert these lines near the top of your program:
13628
 
13629
@smallexample
13630
set_debug_traps();
13631
breakpoint();
13632
@end smallexample
13633
 
13634
@item
13635
For the 680x0 stub only, you need to provide a variable called
13636
@code{exceptionHook}.  Normally you just use:
13637
 
13638
@smallexample
13639
void (*exceptionHook)() = 0;
13640
@end smallexample
13641
 
13642
@noindent
13643
but if before calling @code{set_debug_traps}, you set it to point to a
13644
function in your program, that function is called when
13645
@code{@value{GDBN}} continues after stopping on a trap (for example, bus
13646
error).  The function indicated by @code{exceptionHook} is called with
13647
one parameter: an @code{int} which is the exception number.
13648
 
13649
@item
13650
Compile and link together: your program, the @value{GDBN} debugging stub for
13651
your target architecture, and the supporting subroutines.
13652
 
13653
@item
13654
Make sure you have a serial connection between your target machine and
13655
the @value{GDBN} host, and identify the serial port on the host.
13656
 
13657
@item
13658
@c The "remote" target now provides a `load' command, so we should
13659
@c document that.  FIXME.
13660
Download your program to your target machine (or get it there by
13661
whatever means the manufacturer provides), and start it.
13662
 
13663
@item
13664
Start @value{GDBN} on the host, and connect to the target
13665
(@pxref{Connecting,,Connecting to a Remote Target}).
13666
 
13667
@end enumerate
13668
 
13669
@node Configurations
13670
@chapter Configuration-Specific Information
13671
 
13672
While nearly all @value{GDBN} commands are available for all native and
13673
cross versions of the debugger, there are some exceptions.  This chapter
13674
describes things that are only available in certain configurations.
13675
 
13676
There are three major categories of configurations: native
13677
configurations, where the host and target are the same, embedded
13678
operating system configurations, which are usually the same for several
13679
different processor architectures, and bare embedded processors, which
13680
are quite different from each other.
13681
 
13682
@menu
13683
* Native::
13684
* Embedded OS::
13685
* Embedded Processors::
13686
* Architectures::
13687
@end menu
13688
 
13689
@node Native
13690
@section Native
13691
 
13692
This section describes details specific to particular native
13693
configurations.
13694
 
13695
@menu
13696
* HP-UX::                       HP-UX
13697
* BSD libkvm Interface::        Debugging BSD kernel memory images
13698
* SVR4 Process Information::    SVR4 process information
13699
* DJGPP Native::                Features specific to the DJGPP port
13700
* Cygwin Native::               Features specific to the Cygwin port
13701
* Hurd Native::                 Features specific to @sc{gnu} Hurd
13702
* Neutrino::                    Features specific to QNX Neutrino
13703
@end menu
13704
 
13705
@node HP-UX
13706
@subsection HP-UX
13707
 
13708
On HP-UX systems, if you refer to a function or variable name that
13709
begins with a dollar sign, @value{GDBN} searches for a user or system
13710
name first, before it searches for a convenience variable.
13711
 
13712
 
13713
@node BSD libkvm Interface
13714
@subsection BSD libkvm Interface
13715
 
13716
@cindex libkvm
13717
@cindex kernel memory image
13718
@cindex kernel crash dump
13719
 
13720
BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
13721
interface that provides a uniform interface for accessing kernel virtual
13722
memory images, including live systems and crash dumps.  @value{GDBN}
13723
uses this interface to allow you to debug live kernels and kernel crash
13724
dumps on many native BSD configurations.  This is implemented as a
13725
special @code{kvm} debugging target.  For debugging a live system, load
13726
the currently running kernel into @value{GDBN} and connect to the
13727
@code{kvm} target:
13728
 
13729
@smallexample
13730
(@value{GDBP}) @b{target kvm}
13731
@end smallexample
13732
 
13733
For debugging crash dumps, provide the file name of the crash dump as an
13734
argument:
13735
 
13736
@smallexample
13737
(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
13738
@end smallexample
13739
 
13740
Once connected to the @code{kvm} target, the following commands are
13741
available:
13742
 
13743
@table @code
13744
@kindex kvm
13745
@item kvm pcb
13746
Set current context from the @dfn{Process Control Block} (PCB) address.
13747
 
13748
@item kvm proc
13749
Set current context from proc address.  This command isn't available on
13750
modern FreeBSD systems.
13751
@end table
13752
 
13753
@node SVR4 Process Information
13754
@subsection SVR4 Process Information
13755
@cindex /proc
13756
@cindex examine process image
13757
@cindex process info via @file{/proc}
13758
 
13759
Many versions of SVR4 and compatible systems provide a facility called
13760
@samp{/proc} that can be used to examine the image of a running
13761
process using file-system subroutines.  If @value{GDBN} is configured
13762
for an operating system with this facility, the command @code{info
13763
proc} is available to report information about the process running
13764
your program, or about any process running on your system.  @code{info
13765
proc} works only on SVR4 systems that include the @code{procfs} code.
13766
This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
13767
Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
13768
 
13769
@table @code
13770
@kindex info proc
13771
@cindex process ID
13772
@item info proc
13773
@itemx info proc @var{process-id}
13774
Summarize available information about any running process.  If a
13775
process ID is specified by @var{process-id}, display information about
13776
that process; otherwise display information about the program being
13777
debugged.  The summary includes the debugged process ID, the command
13778
line used to invoke it, its current working directory, and its
13779
executable file's absolute file name.
13780
 
13781
On some systems, @var{process-id} can be of the form
13782
@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
13783
within a process.  If the optional @var{pid} part is missing, it means
13784
a thread from the process being debugged (the leading @samp{/} still
13785
needs to be present, or else @value{GDBN} will interpret the number as
13786
a process ID rather than a thread ID).
13787
 
13788
@item info proc mappings
13789
@cindex memory address space mappings
13790
Report the memory address space ranges accessible in the program, with
13791
information on whether the process has read, write, or execute access
13792
rights to each range.  On @sc{gnu}/Linux systems, each memory range
13793
includes the object file which is mapped to that range, instead of the
13794
memory access rights to that range.
13795
 
13796
@item info proc stat
13797
@itemx info proc status
13798
@cindex process detailed status information
13799
These subcommands are specific to @sc{gnu}/Linux systems.  They show
13800
the process-related information, including the user ID and group ID;
13801
how many threads are there in the process; its virtual memory usage;
13802
the signals that are pending, blocked, and ignored; its TTY; its
13803
consumption of system and user time; its stack size; its @samp{nice}
13804
value; etc.  For more information, see the @samp{proc} man page
13805
(type @kbd{man 5 proc} from your shell prompt).
13806
 
13807
@item info proc all
13808
Show all the information about the process described under all of the
13809
above @code{info proc} subcommands.
13810
 
13811
@ignore
13812
@comment These sub-options of 'info proc' were not included when
13813
@comment procfs.c was re-written.  Keep their descriptions around
13814
@comment against the day when someone finds the time to put them back in.
13815
@kindex info proc times
13816
@item info proc times
13817
Starting time, user CPU time, and system CPU time for your program and
13818
its children.
13819
 
13820
@kindex info proc id
13821
@item info proc id
13822
Report on the process IDs related to your program: its own process ID,
13823
the ID of its parent, the process group ID, and the session ID.
13824
@end ignore
13825
 
13826
@item set procfs-trace
13827
@kindex set procfs-trace
13828
@cindex @code{procfs} API calls
13829
This command enables and disables tracing of @code{procfs} API calls.
13830
 
13831
@item show procfs-trace
13832
@kindex show procfs-trace
13833
Show the current state of @code{procfs} API call tracing.
13834
 
13835
@item set procfs-file @var{file}
13836
@kindex set procfs-file
13837
Tell @value{GDBN} to write @code{procfs} API trace to the named
13838
@var{file}.  @value{GDBN} appends the trace info to the previous
13839
contents of the file.  The default is to display the trace on the
13840
standard output.
13841
 
13842
@item show procfs-file
13843
@kindex show procfs-file
13844
Show the file to which @code{procfs} API trace is written.
13845
 
13846
@item proc-trace-entry
13847
@itemx proc-trace-exit
13848
@itemx proc-untrace-entry
13849
@itemx proc-untrace-exit
13850
@kindex proc-trace-entry
13851
@kindex proc-trace-exit
13852
@kindex proc-untrace-entry
13853
@kindex proc-untrace-exit
13854
These commands enable and disable tracing of entries into and exits
13855
from the @code{syscall} interface.
13856
 
13857
@item info pidlist
13858
@kindex info pidlist
13859
@cindex process list, QNX Neutrino
13860
For QNX Neutrino only, this command displays the list of all the
13861
processes and all the threads within each process.
13862
 
13863
@item info meminfo
13864
@kindex info meminfo
13865
@cindex mapinfo list, QNX Neutrino
13866
For QNX Neutrino only, this command displays the list of all mapinfos.
13867
@end table
13868
 
13869
@node DJGPP Native
13870
@subsection Features for Debugging @sc{djgpp} Programs
13871
@cindex @sc{djgpp} debugging
13872
@cindex native @sc{djgpp} debugging
13873
@cindex MS-DOS-specific commands
13874
 
13875
@cindex DPMI
13876
@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
13877
MS-Windows.  @sc{djgpp} programs are 32-bit protected-mode programs
13878
that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
13879
top of real-mode DOS systems and their emulations.
13880
 
13881
@value{GDBN} supports native debugging of @sc{djgpp} programs, and
13882
defines a few commands specific to the @sc{djgpp} port.  This
13883
subsection describes those commands.
13884
 
13885
@table @code
13886
@kindex info dos
13887
@item info dos
13888
This is a prefix of @sc{djgpp}-specific commands which print
13889
information about the target system and important OS structures.
13890
 
13891
@kindex sysinfo
13892
@cindex MS-DOS system info
13893
@cindex free memory information (MS-DOS)
13894
@item info dos sysinfo
13895
This command displays assorted information about the underlying
13896
platform: the CPU type and features, the OS version and flavor, the
13897
DPMI version, and the available conventional and DPMI memory.
13898
 
13899
@cindex GDT
13900
@cindex LDT
13901
@cindex IDT
13902
@cindex segment descriptor tables
13903
@cindex descriptor tables display
13904
@item info dos gdt
13905
@itemx info dos ldt
13906
@itemx info dos idt
13907
These 3 commands display entries from, respectively, Global, Local,
13908
and Interrupt Descriptor Tables (GDT, LDT, and IDT).  The descriptor
13909
tables are data structures which store a descriptor for each segment
13910
that is currently in use.  The segment's selector is an index into a
13911
descriptor table; the table entry for that index holds the
13912
descriptor's base address and limit, and its attributes and access
13913
rights.
13914
 
13915
A typical @sc{djgpp} program uses 3 segments: a code segment, a data
13916
segment (used for both data and the stack), and a DOS segment (which
13917
allows access to DOS/BIOS data structures and absolute addresses in
13918
conventional memory).  However, the DPMI host will usually define
13919
additional segments in order to support the DPMI environment.
13920
 
13921
@cindex garbled pointers
13922
These commands allow to display entries from the descriptor tables.
13923
Without an argument, all entries from the specified table are
13924
displayed.  An argument, which should be an integer expression, means
13925
display a single entry whose index is given by the argument.  For
13926
example, here's a convenient way to display information about the
13927
debugged program's data segment:
13928
 
13929
@smallexample
13930
@exdent @code{(@value{GDBP}) info dos ldt $ds}
13931
@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
13932
@end smallexample
13933
 
13934
@noindent
13935
This comes in handy when you want to see whether a pointer is outside
13936
the data segment's limit (i.e.@: @dfn{garbled}).
13937
 
13938
@cindex page tables display (MS-DOS)
13939
@item info dos pde
13940
@itemx info dos pte
13941
These two commands display entries from, respectively, the Page
13942
Directory and the Page Tables.  Page Directories and Page Tables are
13943
data structures which control how virtual memory addresses are mapped
13944
into physical addresses.  A Page Table includes an entry for every
13945
page of memory that is mapped into the program's address space; there
13946
may be several Page Tables, each one holding up to 4096 entries.  A
13947
Page Directory has up to 4096 entries, one each for every Page Table
13948
that is currently in use.
13949
 
13950
Without an argument, @kbd{info dos pde} displays the entire Page
13951
Directory, and @kbd{info dos pte} displays all the entries in all of
13952
the Page Tables.  An argument, an integer expression, given to the
13953
@kbd{info dos pde} command means display only that entry from the Page
13954
Directory table.  An argument given to the @kbd{info dos pte} command
13955
means display entries from a single Page Table, the one pointed to by
13956
the specified entry in the Page Directory.
13957
 
13958
@cindex direct memory access (DMA) on MS-DOS
13959
These commands are useful when your program uses @dfn{DMA} (Direct
13960
Memory Access), which needs physical addresses to program the DMA
13961
controller.
13962
 
13963
These commands are supported only with some DPMI servers.
13964
 
13965
@cindex physical address from linear address
13966
@item info dos address-pte @var{addr}
13967
This command displays the Page Table entry for a specified linear
13968
address.  The argument @var{addr} is a linear address which should
13969
already have the appropriate segment's base address added to it,
13970
because this command accepts addresses which may belong to @emph{any}
13971
segment.  For example, here's how to display the Page Table entry for
13972
the page where a variable @code{i} is stored:
13973
 
13974
@smallexample
13975
@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
13976
@exdent @code{Page Table entry for address 0x11a00d30:}
13977
@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
13978
@end smallexample
13979
 
13980
@noindent
13981
This says that @code{i} is stored at offset @code{0xd30} from the page
13982
whose physical base address is @code{0x02698000}, and shows all the
13983
attributes of that page.
13984
 
13985
Note that you must cast the addresses of variables to a @code{char *},
13986
since otherwise the value of @code{__djgpp_base_address}, the base
13987
address of all variables and functions in a @sc{djgpp} program, will
13988
be added using the rules of C pointer arithmetics: if @code{i} is
13989
declared an @code{int}, @value{GDBN} will add 4 times the value of
13990
@code{__djgpp_base_address} to the address of @code{i}.
13991
 
13992
Here's another example, it displays the Page Table entry for the
13993
transfer buffer:
13994
 
13995
@smallexample
13996
@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
13997
@exdent @code{Page Table entry for address 0x29110:}
13998
@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
13999
@end smallexample
14000
 
14001
@noindent
14002
(The @code{+ 3} offset is because the transfer buffer's address is the
14003
3rd member of the @code{_go32_info_block} structure.)  The output
14004
clearly shows that this DPMI server maps the addresses in conventional
14005
memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
14006
linear (@code{0x29110}) addresses are identical.
14007
 
14008
This command is supported only with some DPMI servers.
14009
@end table
14010
 
14011
@cindex DOS serial data link, remote debugging
14012
In addition to native debugging, the DJGPP port supports remote
14013
debugging via a serial data link.  The following commands are specific
14014
to remote serial debugging in the DJGPP port of @value{GDBN}.
14015
 
14016
@table @code
14017
@kindex set com1base
14018
@kindex set com1irq
14019
@kindex set com2base
14020
@kindex set com2irq
14021
@kindex set com3base
14022
@kindex set com3irq
14023
@kindex set com4base
14024
@kindex set com4irq
14025
@item set com1base @var{addr}
14026
This command sets the base I/O port address of the @file{COM1} serial
14027
port.
14028
 
14029
@item set com1irq @var{irq}
14030
This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
14031
for the @file{COM1} serial port.
14032
 
14033
There are similar commands @samp{set com2base}, @samp{set com3irq},
14034
etc.@: for setting the port address and the @code{IRQ} lines for the
14035
other 3 COM ports.
14036
 
14037
@kindex show com1base
14038
@kindex show com1irq
14039
@kindex show com2base
14040
@kindex show com2irq
14041
@kindex show com3base
14042
@kindex show com3irq
14043
@kindex show com4base
14044
@kindex show com4irq
14045
The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
14046
display the current settings of the base address and the @code{IRQ}
14047
lines used by the COM ports.
14048
 
14049
@item info serial
14050
@kindex info serial
14051
@cindex DOS serial port status
14052
This command prints the status of the 4 DOS serial ports.  For each
14053
port, it prints whether it's active or not, its I/O base address and
14054
IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
14055
counts of various errors encountered so far.
14056
@end table
14057
 
14058
 
14059
@node Cygwin Native
14060
@subsection Features for Debugging MS Windows PE Executables
14061
@cindex MS Windows debugging
14062
@cindex native Cygwin debugging
14063
@cindex Cygwin-specific commands
14064
 
14065
@value{GDBN} supports native debugging of MS Windows programs, including
14066
DLLs with and without symbolic debugging information.  There are various
14067
additional Cygwin-specific commands, described in this section.
14068
Working with DLLs that have no debugging symbols is described in
14069
@ref{Non-debug DLL Symbols}.
14070
 
14071
@table @code
14072
@kindex info w32
14073
@item info w32
14074
This is a prefix of MS Windows-specific commands which print
14075
information about the target system and important OS structures.
14076
 
14077
@item info w32 selector
14078
This command displays information returned by
14079
the Win32 API @code{GetThreadSelectorEntry} function.
14080
It takes an optional argument that is evaluated to
14081
a long value to give the information about this given selector.
14082
Without argument, this command displays information
14083
about the six segment registers.
14084
 
14085
@kindex info dll
14086
@item info dll
14087
This is a Cygwin-specific alias of @code{info shared}.
14088
 
14089
@kindex dll-symbols
14090
@item dll-symbols
14091
This command loads symbols from a dll similarly to
14092
add-sym command but without the need to specify a base address.
14093
 
14094
@kindex set cygwin-exceptions
14095
@cindex debugging the Cygwin DLL
14096
@cindex Cygwin DLL, debugging
14097
@item set cygwin-exceptions @var{mode}
14098
If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
14099
happen inside the Cygwin DLL.  If @var{mode} is @code{off},
14100
@value{GDBN} will delay recognition of exceptions, and may ignore some
14101
exceptions which seem to be caused by internal Cygwin DLL
14102
``bookkeeping''.  This option is meant primarily for debugging the
14103
Cygwin DLL itself; the default value is @code{off} to avoid annoying
14104
@value{GDBN} users with false @code{SIGSEGV} signals.
14105
 
14106
@kindex show cygwin-exceptions
14107
@item show cygwin-exceptions
14108
Displays whether @value{GDBN} will break on exceptions that happen
14109
inside the Cygwin DLL itself.
14110
 
14111
@kindex set new-console
14112
@item set new-console @var{mode}
14113
If @var{mode} is @code{on} the debuggee will
14114
be started in a new console on next start.
14115
If @var{mode} is @code{off}i, the debuggee will
14116
be started in the same console as the debugger.
14117
 
14118
@kindex show new-console
14119
@item show new-console
14120
Displays whether a new console is used
14121
when the debuggee is started.
14122
 
14123
@kindex set new-group
14124
@item set new-group @var{mode}
14125
This boolean value controls whether the debuggee should
14126
start a new group or stay in the same group as the debugger.
14127
This affects the way the Windows OS handles
14128
@samp{Ctrl-C}.
14129
 
14130
@kindex show new-group
14131
@item show new-group
14132
Displays current value of new-group boolean.
14133
 
14134
@kindex set debugevents
14135
@item set debugevents
14136
This boolean value adds debug output concerning kernel events related
14137
to the debuggee seen by the debugger.  This includes events that
14138
signal thread and process creation and exit, DLL loading and
14139
unloading, console interrupts, and debugging messages produced by the
14140
Windows @code{OutputDebugString} API call.
14141
 
14142
@kindex set debugexec
14143
@item set debugexec
14144
This boolean value adds debug output concerning execute events
14145
(such as resume thread) seen by the debugger.
14146
 
14147
@kindex set debugexceptions
14148
@item set debugexceptions
14149
This boolean value adds debug output concerning exceptions in the
14150
debuggee seen by the debugger.
14151
 
14152
@kindex set debugmemory
14153
@item set debugmemory
14154
This boolean value adds debug output concerning debuggee memory reads
14155
and writes by the debugger.
14156
 
14157
@kindex set shell
14158
@item set shell
14159
This boolean values specifies whether the debuggee is called
14160
via a shell or directly (default value is on).
14161
 
14162
@kindex show shell
14163
@item show shell
14164
Displays if the debuggee will be started with a shell.
14165
 
14166
@end table
14167
 
14168
@menu
14169
* Non-debug DLL Symbols::  Support for DLLs without debugging symbols
14170
@end menu
14171
 
14172
@node Non-debug DLL Symbols
14173
@subsubsection Support for DLLs without Debugging Symbols
14174
@cindex DLLs with no debugging symbols
14175
@cindex Minimal symbols and DLLs
14176
 
14177
Very often on windows, some of the DLLs that your program relies on do
14178
not include symbolic debugging information (for example,
14179
@file{kernel32.dll}).  When @value{GDBN} doesn't recognize any debugging
14180
symbols in a DLL, it relies on the minimal amount of symbolic
14181
information contained in the DLL's export table.  This section
14182
describes working with such symbols, known internally to @value{GDBN} as
14183
``minimal symbols''.
14184
 
14185
Note that before the debugged program has started execution, no DLLs
14186
will have been loaded.  The easiest way around this problem is simply to
14187
start the program --- either by setting a breakpoint or letting the
14188
program run once to completion.  It is also possible to force
14189
@value{GDBN} to load a particular DLL before starting the executable ---
14190
see the shared library information in @ref{Files}, or the
14191
@code{dll-symbols} command in @ref{Cygwin Native}.  Currently,
14192
explicitly loading symbols from a DLL with no debugging information will
14193
cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
14194
which may adversely affect symbol lookup performance.
14195
 
14196
@subsubsection DLL Name Prefixes
14197
 
14198
In keeping with the naming conventions used by the Microsoft debugging
14199
tools, DLL export symbols are made available with a prefix based on the
14200
DLL name, for instance @code{KERNEL32!CreateFileA}.  The plain name is
14201
also entered into the symbol table, so @code{CreateFileA} is often
14202
sufficient. In some cases there will be name clashes within a program
14203
(particularly if the executable itself includes full debugging symbols)
14204
necessitating the use of the fully qualified name when referring to the
14205
contents of the DLL. Use single-quotes around the name to avoid the
14206
exclamation mark (``!'')  being interpreted as a language operator.
14207
 
14208
Note that the internal name of the DLL may be all upper-case, even
14209
though the file name of the DLL is lower-case, or vice-versa. Since
14210
symbols within @value{GDBN} are @emph{case-sensitive} this may cause
14211
some confusion. If in doubt, try the @code{info functions} and
14212
@code{info variables} commands or even @code{maint print msymbols}
14213
(@pxref{Symbols}). Here's an example:
14214
 
14215
@smallexample
14216
(@value{GDBP}) info function CreateFileA
14217
All functions matching regular expression "CreateFileA":
14218
 
14219
Non-debugging symbols:
14220
0x77e885f4  CreateFileA
14221
0x77e885f4  KERNEL32!CreateFileA
14222
@end smallexample
14223
 
14224
@smallexample
14225
(@value{GDBP}) info function !
14226
All functions matching regular expression "!":
14227
 
14228
Non-debugging symbols:
14229
0x6100114c  cygwin1!__assert
14230
0x61004034  cygwin1!_dll_crt0@@0
14231
0x61004240  cygwin1!dll_crt0(per_process *)
14232
[etc...]
14233
@end smallexample
14234
 
14235
@subsubsection Working with Minimal Symbols
14236
 
14237
Symbols extracted from a DLL's export table do not contain very much
14238
type information. All that @value{GDBN} can do is guess whether a symbol
14239
refers to a function or variable depending on the linker section that
14240
contains the symbol. Also note that the actual contents of the memory
14241
contained in a DLL are not available unless the program is running. This
14242
means that you cannot examine the contents of a variable or disassemble
14243
a function within a DLL without a running program.
14244
 
14245
Variables are generally treated as pointers and dereferenced
14246
automatically. For this reason, it is often necessary to prefix a
14247
variable name with the address-of operator (``&'') and provide explicit
14248
type information in the command. Here's an example of the type of
14249
problem:
14250
 
14251
@smallexample
14252
(@value{GDBP}) print 'cygwin1!__argv'
14253
$1 = 268572168
14254
@end smallexample
14255
 
14256
@smallexample
14257
(@value{GDBP}) x 'cygwin1!__argv'
14258
0x10021610:      "\230y\""
14259
@end smallexample
14260
 
14261
And two possible solutions:
14262
 
14263
@smallexample
14264
(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
14265
$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
14266
@end smallexample
14267
 
14268
@smallexample
14269
(@value{GDBP}) x/2x &'cygwin1!__argv'
14270
0x610c0aa8 <cygwin1!__argv>:    0x10021608      0x00000000
14271
(@value{GDBP}) x/x 0x10021608
14272
0x10021608:     0x0022fd98
14273
(@value{GDBP}) x/s 0x0022fd98
14274
0x22fd98:        "/cygdrive/c/mydirectory/myprogram"
14275
@end smallexample
14276
 
14277
Setting a break point within a DLL is possible even before the program
14278
starts execution. However, under these circumstances, @value{GDBN} can't
14279
examine the initial instructions of the function in order to skip the
14280
function's frame set-up code. You can work around this by using ``*&''
14281
to set the breakpoint at a raw memory address:
14282
 
14283
@smallexample
14284
(@value{GDBP}) break *&'python22!PyOS_Readline'
14285
Breakpoint 1 at 0x1e04eff0
14286
@end smallexample
14287
 
14288
The author of these extensions is not entirely convinced that setting a
14289
break point within a shared DLL like @file{kernel32.dll} is completely
14290
safe.
14291
 
14292
@node Hurd Native
14293
@subsection Commands Specific to @sc{gnu} Hurd Systems
14294
@cindex @sc{gnu} Hurd debugging
14295
 
14296
This subsection describes @value{GDBN} commands specific to the
14297
@sc{gnu} Hurd native debugging.
14298
 
14299
@table @code
14300
@item set signals
14301
@itemx set sigs
14302
@kindex set signals@r{, Hurd command}
14303
@kindex set sigs@r{, Hurd command}
14304
This command toggles the state of inferior signal interception by
14305
@value{GDBN}.  Mach exceptions, such as breakpoint traps, are not
14306
affected by this command.  @code{sigs} is a shorthand alias for
14307
@code{signals}.
14308
 
14309
@item show signals
14310
@itemx show sigs
14311
@kindex show signals@r{, Hurd command}
14312
@kindex show sigs@r{, Hurd command}
14313
Show the current state of intercepting inferior's signals.
14314
 
14315
@item set signal-thread
14316
@itemx set sigthread
14317
@kindex set signal-thread
14318
@kindex set sigthread
14319
This command tells @value{GDBN} which thread is the @code{libc} signal
14320
thread.  That thread is run when a signal is delivered to a running
14321
process.  @code{set sigthread} is the shorthand alias of @code{set
14322
signal-thread}.
14323
 
14324
@item show signal-thread
14325
@itemx show sigthread
14326
@kindex show signal-thread
14327
@kindex show sigthread
14328
These two commands show which thread will run when the inferior is
14329
delivered a signal.
14330
 
14331
@item set stopped
14332
@kindex set stopped@r{, Hurd command}
14333
This commands tells @value{GDBN} that the inferior process is stopped,
14334
as with the @code{SIGSTOP} signal.  The stopped process can be
14335
continued by delivering a signal to it.
14336
 
14337
@item show stopped
14338
@kindex show stopped@r{, Hurd command}
14339
This command shows whether @value{GDBN} thinks the debuggee is
14340
stopped.
14341
 
14342
@item set exceptions
14343
@kindex set exceptions@r{, Hurd command}
14344
Use this command to turn off trapping of exceptions in the inferior.
14345
When exception trapping is off, neither breakpoints nor
14346
single-stepping will work.  To restore the default, set exception
14347
trapping on.
14348
 
14349
@item show exceptions
14350
@kindex show exceptions@r{, Hurd command}
14351
Show the current state of trapping exceptions in the inferior.
14352
 
14353
@item set task pause
14354
@kindex set task@r{, Hurd commands}
14355
@cindex task attributes (@sc{gnu} Hurd)
14356
@cindex pause current task (@sc{gnu} Hurd)
14357
This command toggles task suspension when @value{GDBN} has control.
14358
Setting it to on takes effect immediately, and the task is suspended
14359
whenever @value{GDBN} gets control.  Setting it to off will take
14360
effect the next time the inferior is continued.  If this option is set
14361
to off, you can use @code{set thread default pause on} or @code{set
14362
thread pause on} (see below) to pause individual threads.
14363
 
14364
@item show task pause
14365
@kindex show task@r{, Hurd commands}
14366
Show the current state of task suspension.
14367
 
14368
@item set task detach-suspend-count
14369
@cindex task suspend count
14370
@cindex detach from task, @sc{gnu} Hurd
14371
This command sets the suspend count the task will be left with when
14372
@value{GDBN} detaches from it.
14373
 
14374
@item show task detach-suspend-count
14375
Show the suspend count the task will be left with when detaching.
14376
 
14377
@item set task exception-port
14378
@itemx set task excp
14379
@cindex task exception port, @sc{gnu} Hurd
14380
This command sets the task exception port to which @value{GDBN} will
14381
forward exceptions.  The argument should be the value of the @dfn{send
14382
rights} of the task.  @code{set task excp} is a shorthand alias.
14383
 
14384
@item set noninvasive
14385
@cindex noninvasive task options
14386
This command switches @value{GDBN} to a mode that is the least
14387
invasive as far as interfering with the inferior is concerned.  This
14388
is the same as using @code{set task pause}, @code{set exceptions}, and
14389
@code{set signals} to values opposite to the defaults.
14390
 
14391
@item info send-rights
14392
@itemx info receive-rights
14393
@itemx info port-rights
14394
@itemx info port-sets
14395
@itemx info dead-names
14396
@itemx info ports
14397
@itemx info psets
14398
@cindex send rights, @sc{gnu} Hurd
14399
@cindex receive rights, @sc{gnu} Hurd
14400
@cindex port rights, @sc{gnu} Hurd
14401
@cindex port sets, @sc{gnu} Hurd
14402
@cindex dead names, @sc{gnu} Hurd
14403
These commands display information about, respectively, send rights,
14404
receive rights, port rights, port sets, and dead names of a task.
14405
There are also shorthand aliases: @code{info ports} for @code{info
14406
port-rights} and @code{info psets} for @code{info port-sets}.
14407
 
14408
@item set thread pause
14409
@kindex set thread@r{, Hurd command}
14410
@cindex thread properties, @sc{gnu} Hurd
14411
@cindex pause current thread (@sc{gnu} Hurd)
14412
This command toggles current thread suspension when @value{GDBN} has
14413
control.  Setting it to on takes effect immediately, and the current
14414
thread is suspended whenever @value{GDBN} gets control.  Setting it to
14415
off will take effect the next time the inferior is continued.
14416
Normally, this command has no effect, since when @value{GDBN} has
14417
control, the whole task is suspended.  However, if you used @code{set
14418
task pause off} (see above), this command comes in handy to suspend
14419
only the current thread.
14420
 
14421
@item show thread pause
14422
@kindex show thread@r{, Hurd command}
14423
This command shows the state of current thread suspension.
14424
 
14425
@item set thread run
14426
This command sets whether the current thread is allowed to run.
14427
 
14428
@item show thread run
14429
Show whether the current thread is allowed to run.
14430
 
14431
@item set thread detach-suspend-count
14432
@cindex thread suspend count, @sc{gnu} Hurd
14433
@cindex detach from thread, @sc{gnu} Hurd
14434
This command sets the suspend count @value{GDBN} will leave on a
14435
thread when detaching.  This number is relative to the suspend count
14436
found by @value{GDBN} when it notices the thread; use @code{set thread
14437
takeover-suspend-count} to force it to an absolute value.
14438
 
14439
@item show thread detach-suspend-count
14440
Show the suspend count @value{GDBN} will leave on the thread when
14441
detaching.
14442
 
14443
@item set thread exception-port
14444
@itemx set thread excp
14445
Set the thread exception port to which to forward exceptions.  This
14446
overrides the port set by @code{set task exception-port} (see above).
14447
@code{set thread excp} is the shorthand alias.
14448
 
14449
@item set thread takeover-suspend-count
14450
Normally, @value{GDBN}'s thread suspend counts are relative to the
14451
value @value{GDBN} finds when it notices each thread.  This command
14452
changes the suspend counts to be absolute instead.
14453
 
14454
@item set thread default
14455
@itemx show thread default
14456
@cindex thread default settings, @sc{gnu} Hurd
14457
Each of the above @code{set thread} commands has a @code{set thread
14458
default} counterpart (e.g., @code{set thread default pause}, @code{set
14459
thread default exception-port}, etc.).  The @code{thread default}
14460
variety of commands sets the default thread properties for all
14461
threads; you can then change the properties of individual threads with
14462
the non-default commands.
14463
@end table
14464
 
14465
 
14466
@node Neutrino
14467
@subsection QNX Neutrino
14468
@cindex QNX Neutrino
14469
 
14470
@value{GDBN} provides the following commands specific to the QNX
14471
Neutrino target:
14472
 
14473
@table @code
14474
@item set debug nto-debug
14475
@kindex set debug nto-debug
14476
When set to on, enables debugging messages specific to the QNX
14477
Neutrino support.
14478
 
14479
@item show debug nto-debug
14480
@kindex show debug nto-debug
14481
Show the current state of QNX Neutrino messages.
14482
@end table
14483
 
14484
 
14485
@node Embedded OS
14486
@section Embedded Operating Systems
14487
 
14488
This section describes configurations involving the debugging of
14489
embedded operating systems that are available for several different
14490
architectures.
14491
 
14492
@menu
14493
* VxWorks::                     Using @value{GDBN} with VxWorks
14494
@end menu
14495
 
14496
@value{GDBN} includes the ability to debug programs running on
14497
various real-time operating systems.
14498
 
14499
@node VxWorks
14500
@subsection Using @value{GDBN} with VxWorks
14501
 
14502
@cindex VxWorks
14503
 
14504
@table @code
14505
 
14506
@kindex target vxworks
14507
@item target vxworks @var{machinename}
14508
A VxWorks system, attached via TCP/IP.  The argument @var{machinename}
14509
is the target system's machine name or IP address.
14510
 
14511
@end table
14512
 
14513
On VxWorks, @code{load} links @var{filename} dynamically on the
14514
current target system as well as adding its symbols in @value{GDBN}.
14515
 
14516
@value{GDBN} enables developers to spawn and debug tasks running on networked
14517
VxWorks targets from a Unix host.  Already-running tasks spawned from
14518
the VxWorks shell can also be debugged.  @value{GDBN} uses code that runs on
14519
both the Unix host and on the VxWorks target.  The program
14520
@code{@value{GDBP}} is installed and executed on the Unix host.  (It may be
14521
installed with the name @code{vxgdb}, to distinguish it from a
14522
@value{GDBN} for debugging programs on the host itself.)
14523
 
14524
@table @code
14525
@item VxWorks-timeout @var{args}
14526
@kindex vxworks-timeout
14527
All VxWorks-based targets now support the option @code{vxworks-timeout}.
14528
This option is set by the user, and  @var{args} represents the number of
14529
seconds @value{GDBN} waits for responses to rpc's.  You might use this if
14530
your VxWorks target is a slow software simulator or is on the far side
14531
of a thin network line.
14532
@end table
14533
 
14534
The following information on connecting to VxWorks was current when
14535
this manual was produced; newer releases of VxWorks may use revised
14536
procedures.
14537
 
14538
@findex INCLUDE_RDB
14539
To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
14540
to include the remote debugging interface routines in the VxWorks
14541
library @file{rdb.a}.  To do this, define @code{INCLUDE_RDB} in the
14542
VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
14543
kernel.  The resulting kernel contains @file{rdb.a}, and spawns the
14544
source debugging task @code{tRdbTask} when VxWorks is booted.  For more
14545
information on configuring and remaking VxWorks, see the manufacturer's
14546
manual.
14547
@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
14548
 
14549
Once you have included @file{rdb.a} in your VxWorks system image and set
14550
your Unix execution search path to find @value{GDBN}, you are ready to
14551
run @value{GDBN}.  From your Unix host, run @code{@value{GDBP}} (or
14552
@code{vxgdb}, depending on your installation).
14553
 
14554
@value{GDBN} comes up showing the prompt:
14555
 
14556
@smallexample
14557
(vxgdb)
14558
@end smallexample
14559
 
14560
@menu
14561
* VxWorks Connection::          Connecting to VxWorks
14562
* VxWorks Download::            VxWorks download
14563
* VxWorks Attach::              Running tasks
14564
@end menu
14565
 
14566
@node VxWorks Connection
14567
@subsubsection Connecting to VxWorks
14568
 
14569
The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
14570
network.  To connect to a target whose host name is ``@code{tt}'', type:
14571
 
14572
@smallexample
14573
(vxgdb) target vxworks tt
14574
@end smallexample
14575
 
14576
@need 750
14577
@value{GDBN} displays messages like these:
14578
 
14579
@smallexample
14580
Attaching remote machine across net...
14581
Connected to tt.
14582
@end smallexample
14583
 
14584
@need 1000
14585
@value{GDBN} then attempts to read the symbol tables of any object modules
14586
loaded into the VxWorks target since it was last booted.  @value{GDBN} locates
14587
these files by searching the directories listed in the command search
14588
path (@pxref{Environment, ,Your Program's Environment}); if it fails
14589
to find an object file, it displays a message such as:
14590
 
14591
@smallexample
14592
prog.o: No such file or directory.
14593
@end smallexample
14594
 
14595
When this happens, add the appropriate directory to the search path with
14596
the @value{GDBN} command @code{path}, and execute the @code{target}
14597
command again.
14598
 
14599
@node VxWorks Download
14600
@subsubsection VxWorks Download
14601
 
14602
@cindex download to VxWorks
14603
If you have connected to the VxWorks target and you want to debug an
14604
object that has not yet been loaded, you can use the @value{GDBN}
14605
@code{load} command to download a file from Unix to VxWorks
14606
incrementally.  The object file given as an argument to the @code{load}
14607
command is actually opened twice: first by the VxWorks target in order
14608
to download the code, then by @value{GDBN} in order to read the symbol
14609
table.  This can lead to problems if the current working directories on
14610
the two systems differ.  If both systems have NFS mounted the same
14611
filesystems, you can avoid these problems by using absolute paths.
14612
Otherwise, it is simplest to set the working directory on both systems
14613
to the directory in which the object file resides, and then to reference
14614
the file by its name, without any path.  For instance, a program
14615
@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
14616
and in @file{@var{hostpath}/vw/demo/rdb} on the host.  To load this
14617
program, type this on VxWorks:
14618
 
14619
@smallexample
14620
-> cd "@var{vxpath}/vw/demo/rdb"
14621
@end smallexample
14622
 
14623
@noindent
14624
Then, in @value{GDBN}, type:
14625
 
14626
@smallexample
14627
(vxgdb) cd @var{hostpath}/vw/demo/rdb
14628
(vxgdb) load prog.o
14629
@end smallexample
14630
 
14631
@value{GDBN} displays a response similar to this:
14632
 
14633
@smallexample
14634
Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
14635
@end smallexample
14636
 
14637
You can also use the @code{load} command to reload an object module
14638
after editing and recompiling the corresponding source file.  Note that
14639
this makes @value{GDBN} delete all currently-defined breakpoints,
14640
auto-displays, and convenience variables, and to clear the value
14641
history.  (This is necessary in order to preserve the integrity of
14642
debugger's data structures that reference the target system's symbol
14643
table.)
14644
 
14645
@node VxWorks Attach
14646
@subsubsection Running Tasks
14647
 
14648
@cindex running VxWorks tasks
14649
You can also attach to an existing task using the @code{attach} command as
14650
follows:
14651
 
14652
@smallexample
14653
(vxgdb) attach @var{task}
14654
@end smallexample
14655
 
14656
@noindent
14657
where @var{task} is the VxWorks hexadecimal task ID.  The task can be running
14658
or suspended when you attach to it.  Running tasks are suspended at
14659
the time of attachment.
14660
 
14661
@node Embedded Processors
14662
@section Embedded Processors
14663
 
14664
This section goes into details specific to particular embedded
14665
configurations.
14666
 
14667
@cindex send command to simulator
14668
Whenever a specific embedded processor has a simulator, @value{GDBN}
14669
allows to send an arbitrary command to the simulator.
14670
 
14671
@table @code
14672
@item sim @var{command}
14673
@kindex sim@r{, a command}
14674
Send an arbitrary @var{command} string to the simulator.  Consult the
14675
documentation for the specific simulator in use for information about
14676
acceptable commands.
14677
@end table
14678
 
14679
 
14680
@menu
14681
* ARM::                         ARM RDI
14682
* M32R/D::                      Renesas M32R/D
14683
* M68K::                        Motorola M68K
14684
* MIPS Embedded::               MIPS Embedded
14685
* OpenRISC 1000::               OpenRisc 1000
14686
* PA::                          HP PA Embedded
14687
* PowerPC Embedded::            PowerPC Embedded
14688
* Sparclet::                    Tsqware Sparclet
14689
* Sparclite::                   Fujitsu Sparclite
14690
* Z8000::                       Zilog Z8000
14691
* AVR::                         Atmel AVR
14692
* CRIS::                        CRIS
14693
* Super-H::                     Renesas Super-H
14694
@end menu
14695
 
14696
@node ARM
14697
@subsection ARM
14698
@cindex ARM RDI
14699
 
14700
@table @code
14701
@kindex target rdi
14702
@item target rdi @var{dev}
14703
ARM Angel monitor, via RDI library interface to ADP protocol.  You may
14704
use this target to communicate with both boards running the Angel
14705
monitor, or with the EmbeddedICE JTAG debug device.
14706
 
14707
@kindex target rdp
14708
@item target rdp @var{dev}
14709
ARM Demon monitor.
14710
 
14711
@end table
14712
 
14713
@value{GDBN} provides the following ARM-specific commands:
14714
 
14715
@table @code
14716
@item set arm disassembler
14717
@kindex set arm
14718
This commands selects from a list of disassembly styles.  The
14719
@code{"std"} style is the standard style.
14720
 
14721
@item show arm disassembler
14722
@kindex show arm
14723
Show the current disassembly style.
14724
 
14725
@item set arm apcs32
14726
@cindex ARM 32-bit mode
14727
This command toggles ARM operation mode between 32-bit and 26-bit.
14728
 
14729
@item show arm apcs32
14730
Display the current usage of the ARM 32-bit mode.
14731
 
14732
@item set arm fpu @var{fputype}
14733
This command sets the ARM floating-point unit (FPU) type.  The
14734
argument @var{fputype} can be one of these:
14735
 
14736
@table @code
14737
@item auto
14738
Determine the FPU type by querying the OS ABI.
14739
@item softfpa
14740
Software FPU, with mixed-endian doubles on little-endian ARM
14741
processors.
14742
@item fpa
14743
GCC-compiled FPA co-processor.
14744
@item softvfp
14745
Software FPU with pure-endian doubles.
14746
@item vfp
14747
VFP co-processor.
14748
@end table
14749
 
14750
@item show arm fpu
14751
Show the current type of the FPU.
14752
 
14753
@item set arm abi
14754
This command forces @value{GDBN} to use the specified ABI.
14755
 
14756
@item show arm abi
14757
Show the currently used ABI.
14758
 
14759
@item set debug arm
14760
Toggle whether to display ARM-specific debugging messages from the ARM
14761
target support subsystem.
14762
 
14763
@item show debug arm
14764
Show whether ARM-specific debugging messages are enabled.
14765
@end table
14766
 
14767
The following commands are available when an ARM target is debugged
14768
using the RDI interface:
14769
 
14770
@table @code
14771
@item rdilogfile @r{[}@var{file}@r{]}
14772
@kindex rdilogfile
14773
@cindex ADP (Angel Debugger Protocol) logging
14774
Set the filename for the ADP (Angel Debugger Protocol) packet log.
14775
With an argument, sets the log file to the specified @var{file}.  With
14776
no argument, show the current log file name.  The default log file is
14777
@file{rdi.log}.
14778
 
14779
@item rdilogenable @r{[}@var{arg}@r{]}
14780
@kindex rdilogenable
14781
Control logging of ADP packets.  With an argument of 1 or @code{"yes"}
14782
enables logging, with an argument 0 or @code{"no"} disables it.  With
14783
no arguments displays the current setting.  When logging is enabled,
14784
ADP packets exchanged between @value{GDBN} and the RDI target device
14785
are logged to a file.
14786
 
14787
@item set rdiromatzero
14788
@kindex set rdiromatzero
14789
@cindex ROM at zero address, RDI
14790
Tell @value{GDBN} whether the target has ROM at address 0.  If on,
14791
vector catching is disabled, so that zero address can be used.  If off
14792
(the default), vector catching is enabled.  For this command to take
14793
effect, it needs to be invoked prior to the @code{target rdi} command.
14794
 
14795
@item show rdiromatzero
14796
@kindex show rdiromatzero
14797
Show the current setting of ROM at zero address.
14798
 
14799
@item set rdiheartbeat
14800
@kindex set rdiheartbeat
14801
@cindex RDI heartbeat
14802
Enable or disable RDI heartbeat packets.  It is not recommended to
14803
turn on this option, since it confuses ARM and EPI JTAG interface, as
14804
well as the Angel monitor.
14805
 
14806
@item show rdiheartbeat
14807
@kindex show rdiheartbeat
14808
Show the setting of RDI heartbeat packets.
14809
@end table
14810
 
14811
 
14812
@node M32R/D
14813
@subsection Renesas M32R/D and M32R/SDI
14814
 
14815
@table @code
14816
@kindex target m32r
14817
@item target m32r @var{dev}
14818
Renesas M32R/D ROM monitor.
14819
 
14820
@kindex target m32rsdi
14821
@item target m32rsdi @var{dev}
14822
Renesas M32R SDI server, connected via parallel port to the board.
14823
@end table
14824
 
14825
The following @value{GDBN} commands are specific to the M32R monitor:
14826
 
14827
@table @code
14828
@item set download-path @var{path}
14829
@kindex set download-path
14830
@cindex find downloadable @sc{srec} files (M32R)
14831
Set the default path for finding downloadable @sc{srec} files.
14832
 
14833
@item show download-path
14834
@kindex show download-path
14835
Show the default path for downloadable @sc{srec} files.
14836
 
14837
@item set board-address @var{addr}
14838
@kindex set board-address
14839
@cindex M32-EVA target board address
14840
Set the IP address for the M32R-EVA target board.
14841
 
14842
@item show board-address
14843
@kindex show board-address
14844
Show the current IP address of the target board.
14845
 
14846
@item set server-address @var{addr}
14847
@kindex set server-address
14848
@cindex download server address (M32R)
14849
Set the IP address for the download server, which is the @value{GDBN}'s
14850
host machine.
14851
 
14852
@item show server-address
14853
@kindex show server-address
14854
Display the IP address of the download server.
14855
 
14856
@item upload @r{[}@var{file}@r{]}
14857
@kindex upload@r{, M32R}
14858
Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14859
upload capability.  If no @var{file} argument is given, the current
14860
executable file is uploaded.
14861
 
14862
@item tload @r{[}@var{file}@r{]}
14863
@kindex tload@r{, M32R}
14864
Test the @code{upload} command.
14865
@end table
14866
 
14867
The following commands are available for M32R/SDI:
14868
 
14869
@table @code
14870
@item sdireset
14871
@kindex sdireset
14872
@cindex reset SDI connection, M32R
14873
This command resets the SDI connection.
14874
 
14875
@item sdistatus
14876
@kindex sdistatus
14877
This command shows the SDI connection status.
14878
 
14879
@item debug_chaos
14880
@kindex debug_chaos
14881
@cindex M32R/Chaos debugging
14882
Instructs the remote that M32R/Chaos debugging is to be used.
14883
 
14884
@item use_debug_dma
14885
@kindex use_debug_dma
14886
Instructs the remote to use the DEBUG_DMA method of accessing memory.
14887
 
14888
@item use_mon_code
14889
@kindex use_mon_code
14890
Instructs the remote to use the MON_CODE method of accessing memory.
14891
 
14892
@item use_ib_break
14893
@kindex use_ib_break
14894
Instructs the remote to set breakpoints by IB break.
14895
 
14896
@item use_dbt_break
14897
@kindex use_dbt_break
14898
Instructs the remote to set breakpoints by DBT.
14899
@end table
14900
 
14901
@node M68K
14902
@subsection M68k
14903
 
14904
The Motorola m68k configuration includes ColdFire support, and a
14905
target command for the following ROM monitor.
14906
 
14907
@table @code
14908
 
14909
@kindex target dbug
14910
@item target dbug @var{dev}
14911
dBUG ROM monitor for Motorola ColdFire.
14912
 
14913
@end table
14914
 
14915
@node MIPS Embedded
14916
@subsection MIPS Embedded
14917
 
14918
@cindex MIPS boards
14919
@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14920
MIPS board attached to a serial line.  This is available when
14921
you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
14922
 
14923
@need 1000
14924
Use these @value{GDBN} commands to specify the connection to your target board:
14925
 
14926
@table @code
14927
@item target mips @var{port}
14928
@kindex target mips @var{port}
14929
To run a program on the board, start up @code{@value{GDBP}} with the
14930
name of your program as the argument.  To connect to the board, use the
14931
command @samp{target mips @var{port}}, where @var{port} is the name of
14932
the serial port connected to the board.  If the program has not already
14933
been downloaded to the board, you may use the @code{load} command to
14934
download it.  You can then use all the usual @value{GDBN} commands.
14935
 
14936
For example, this sequence connects to the target board through a serial
14937
port, and loads and runs a program called @var{prog} through the
14938
debugger:
14939
 
14940
@smallexample
14941
host$ @value{GDBP} @var{prog}
14942
@value{GDBN} is free software and @dots{}
14943
(@value{GDBP}) target mips /dev/ttyb
14944
(@value{GDBP}) load @var{prog}
14945
(@value{GDBP}) run
14946
@end smallexample
14947
 
14948
@item target mips @var{hostname}:@var{portnumber}
14949
On some @value{GDBN} host configurations, you can specify a TCP
14950
connection (for instance, to a serial line managed by a terminal
14951
concentrator) instead of a serial port, using the syntax
14952
@samp{@var{hostname}:@var{portnumber}}.
14953
 
14954
@item target pmon @var{port}
14955
@kindex target pmon @var{port}
14956
PMON ROM monitor.
14957
 
14958
@item target ddb @var{port}
14959
@kindex target ddb @var{port}
14960
NEC's DDB variant of PMON for Vr4300.
14961
 
14962
@item target lsi @var{port}
14963
@kindex target lsi @var{port}
14964
LSI variant of PMON.
14965
 
14966
@kindex target r3900
14967
@item target r3900 @var{dev}
14968
Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
14969
 
14970
@kindex target array
14971
@item target array @var{dev}
14972
Array Tech LSI33K RAID controller board.
14973
 
14974
@end table
14975
 
14976
 
14977
@noindent
14978
@value{GDBN} also supports these special commands for MIPS targets:
14979
 
14980
@table @code
14981
@item set mipsfpu double
14982
@itemx set mipsfpu single
14983
@itemx set mipsfpu none
14984
@itemx set mipsfpu auto
14985
@itemx show mipsfpu
14986
@kindex set mipsfpu
14987
@kindex show mipsfpu
14988
@cindex MIPS remote floating point
14989
@cindex floating point, MIPS remote
14990
If your target board does not support the MIPS floating point
14991
coprocessor, you should use the command @samp{set mipsfpu none} (if you
14992
need this, you may wish to put the command in your @value{GDBN} init
14993
file).  This tells @value{GDBN} how to find the return value of
14994
functions which return floating point values.  It also allows
14995
@value{GDBN} to avoid saving the floating point registers when calling
14996
functions on the board.  If you are using a floating point coprocessor
14997
with only single precision floating point support, as on the @sc{r4650}
14998
processor, use the command @samp{set mipsfpu single}.  The default
14999
double precision floating point coprocessor may be selected using
15000
@samp{set mipsfpu double}.
15001
 
15002
In previous versions the only choices were double precision or no
15003
floating point, so @samp{set mipsfpu on} will select double precision
15004
and @samp{set mipsfpu off} will select no floating point.
15005
 
15006
As usual, you can inquire about the @code{mipsfpu} variable with
15007
@samp{show mipsfpu}.
15008
 
15009
@item set timeout @var{seconds}
15010
@itemx set retransmit-timeout @var{seconds}
15011
@itemx show timeout
15012
@itemx show retransmit-timeout
15013
@cindex @code{timeout}, MIPS protocol
15014
@cindex @code{retransmit-timeout}, MIPS protocol
15015
@kindex set timeout
15016
@kindex show timeout
15017
@kindex set retransmit-timeout
15018
@kindex show retransmit-timeout
15019
You can control the timeout used while waiting for a packet, in the MIPS
15020
remote protocol, with the @code{set timeout @var{seconds}} command.  The
15021
default is 5 seconds.  Similarly, you can control the timeout used while
15022
waiting for an acknowledgement of a packet with the @code{set
15023
retransmit-timeout @var{seconds}} command.  The default is 3 seconds.
15024
You can inspect both values with @code{show timeout} and @code{show
15025
retransmit-timeout}.  (These commands are @emph{only} available when
15026
@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
15027
 
15028
The timeout set by @code{set timeout} does not apply when @value{GDBN}
15029
is waiting for your program to stop.  In that case, @value{GDBN} waits
15030
forever because it has no way of knowing how long the program is going
15031
to run before stopping.
15032
 
15033
@item set syn-garbage-limit @var{num}
15034
@kindex set syn-garbage-limit@r{, MIPS remote}
15035
@cindex synchronize with remote MIPS target
15036
Limit the maximum number of characters @value{GDBN} should ignore when
15037
it tries to synchronize with the remote target.  The default is 10
15038
characters.  Setting the limit to -1 means there's no limit.
15039
 
15040
@item show syn-garbage-limit
15041
@kindex show syn-garbage-limit@r{, MIPS remote}
15042
Show the current limit on the number of characters to ignore when
15043
trying to synchronize with the remote system.
15044
 
15045
@item set monitor-prompt @var{prompt}
15046
@kindex set monitor-prompt@r{, MIPS remote}
15047
@cindex remote monitor prompt
15048
Tell @value{GDBN} to expect the specified @var{prompt} string from the
15049
remote monitor.  The default depends on the target:
15050
@table @asis
15051
@item pmon target
15052
@samp{PMON}
15053
@item ddb target
15054
@samp{NEC010}
15055
@item lsi target
15056
@samp{PMON>}
15057
@end table
15058
 
15059
@item show monitor-prompt
15060
@kindex show monitor-prompt@r{, MIPS remote}
15061
Show the current strings @value{GDBN} expects as the prompt from the
15062
remote monitor.
15063
 
15064
@item set monitor-warnings
15065
@kindex set monitor-warnings@r{, MIPS remote}
15066
Enable or disable monitor warnings about hardware breakpoints.  This
15067
has effect only for the @code{lsi} target.  When on, @value{GDBN} will
15068
display warning messages whose codes are returned by the @code{lsi}
15069
PMON monitor for breakpoint commands.
15070
 
15071
@item show monitor-warnings
15072
@kindex show monitor-warnings@r{, MIPS remote}
15073
Show the current setting of printing monitor warnings.
15074
 
15075
@item pmon @var{command}
15076
@kindex pmon@r{, MIPS remote}
15077
@cindex send PMON command
15078
This command allows sending an arbitrary @var{command} string to the
15079
monitor.  The monitor must be in debug mode for this to work.
15080
@end table
15081
 
15082
@node OpenRISC 1000
15083
@subsection OpenRISC 1000
15084
@cindex OpenRISC 1000
15085
 
15086
@cindex or1k boards
15087
See the OpenRISC 1000 Architecture document (@uref{www.opencores.org})
15088
for more information about this platform. A separate document
15089
@code{or1k.texinfo} provides a fuller description of the @value{GDBN}
15090
implementation with examples.
15091
 
15092
@emph{Note:} The OpenRISC 1000 architecture uses its General Purpose
15093
Register (GPR) 2 as a frame pointer register. However the @b{$fp}
15094
variable in @value{GDBN} is not currently implemented, and will return
15095
the value of the stack pointer (GPR 1) instead.
15096
 
15097
@table @code
15098
 
15099
@kindex target jtag
15100
@item  target jtag jtag://@var{host}:@var{port}
15101
@itemx target jtag @var{device}
15102
 
15103
Connect to the OpenRISC 1000 via its JTAG port. The first format uses
15104
the propietary OpenRISC 1000 remote JTAG protocol, second format is for
15105
directly connected hardware using a JP1 interface (typically via the
15106
parallel port). The remote server can be running either the
15107
architectural simulator (Or1ksim) or driving real hardware.
15108
 
15109
Example: @code{target jtag jtag://localhost:50000}@*
15110
Example: @code{target jtag /dev/lp}
15111
 
15112
@emph{Note:} This interface is now deprecated and documented here only for
15113
backwards compatibility. The OpenRISC 1000 now supports the @value{GDBN}
15114
@dfn{Remote Serial Protocol}. The recommended way to connect is using the
15115
@command{@w{target remote}} or @command{@w{target extended-remote}} commands.
15116
 
15117
@kindex target jtag_mohor
15118
@kindex target jtag_orpsoc
15119
@item  target jtag jtag_mohor://@var{host}:@var{port}
15120
@itemx target jtag jtag_orpsoc://@var{host}:@var{port}
15121
 
15122
Unfortunately there are now two different flavours of the JTAG
15123
interface used with OpenRISC 1000. The original version was created
15124
for use with the OpenRISC 1000 System-on-Chip, @b{ORPSoC}. A new
15125
(smaller and simpler) JTAG interface was developed by Igor Mohor in
15126
2004, which is used on some designs.
15127
 
15128
The default behavior of @value{GDBN} is to use the original ORPSoC
15129
version of the interface for backwards compatibility. @value{GDBN} can
15130
use the Igor Mohor version by specifying @b{jtag_mohor://} instead of
15131
@b{jtag://}. For completeness @b{jtag_orpsoc://} can be specified as a
15132
synonum for @b{jtag://}.
15133
 
15134
@emph{Note:} The recommended connection using the @value{GDBN} @dfn{Remote
15135
Serial Protocol} is independent of the JTAG implementation and will work with
15136
either.
15137
 
15138
@kindex target jtag reset
15139
@item target jtag jtag://@var{host}:@var{port} reset
15140
 
15141
By default, establishing a connection using the OpenRISC 1000 Remote JTAG
15142
Protocol @emph{does not} reset the target. This allows debugging to resume a
15143
partially complete program on connection. If a reset is required, the keyworkd
15144
@b{RESET} (case insensitive) may be added at the end of the @b{target}
15145
command.
15146
 
15147
Example: @code{target jtag jtag://localhost:50000 reset}
15148
 
15149
@emph{Note.} The proprietary remote JTAG protocol is now deprecated. Users
15150
should instead use the @value{GDBN} Remote Serial Protocol via the
15151
@command{@w{target remote}} and @command{@w{target extended-remote}} commands.
15152
 
15153
@kindex info spr
15154
@item info spr
15155
Displays Special Purpose Register (SPR) groups.
15156
 
15157
@item info spr @var{group}
15158
@itemx info spr @var{groupno}
15159
Displays values of registers in the selected SPR group.
15160
 
15161
@item  info spr @var{register}
15162
@itemx info spr @var{group} @var{register}
15163
@itemx info spr @var{group} @var{registerno}
15164
@itemx info spr @var{groupno} @var{register}
15165
@itemx info spr @var{groupno} @var{registerno}
15166
Shows information about the specified SPR register.
15167
 
15168
@kindex spr
15169
@item  spr @var{group} @var{register} @var{value}
15170
@itemx spr @var{register @var{value}}
15171
@itemx spr @var{groupno} @var{registerno @var{value}}
15172
@itemx spr @var{registerno @var{value}}
15173
Writes @var{value} to the specified SPR register.
15174
@end table
15175
 
15176
Some implementations of the OpenRISC 1000 Architecture have facilities
15177
for hardware breakpointing/watchpointing.
15178
If they exist, @value{GDBN} will use these facilities to implement
15179
@b{rwatch}, @b{awatch} and @b{hbreak} commands and to improve the
15180
performance of @b{break} and @b{watch} commands.
15181
 
15182
@node PowerPC Embedded
15183
@subsection PowerPC Embedded
15184
 
15185
@value{GDBN} provides the following PowerPC-specific commands:
15186
 
15187
@table @code
15188
@kindex set powerpc
15189
@item set powerpc soft-float
15190
@itemx show powerpc soft-float
15191
Force @value{GDBN} to use (or not use) a software floating point calling
15192
convention.  By default, @value{GDBN} selects the calling convention based
15193
on the selected architecture and the provided executable file.
15194
 
15195
@item set powerpc vector-abi
15196
@itemx show powerpc vector-abi
15197
Force @value{GDBN} to use the specified calling convention for vector
15198
arguments and return values.  The valid options are @samp{auto};
15199
@samp{generic}, to avoid vector registers even if they are present;
15200
@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
15201
registers.  By default, @value{GDBN} selects the calling convention
15202
based on the selected architecture and the provided executable file.
15203
 
15204
@kindex target dink32
15205
@item target dink32 @var{dev}
15206
DINK32 ROM monitor.
15207
 
15208
@kindex target ppcbug
15209
@item target ppcbug @var{dev}
15210
@kindex target ppcbug1
15211
@item target ppcbug1 @var{dev}
15212
PPCBUG ROM monitor for PowerPC.
15213
 
15214
@kindex target sds
15215
@item target sds @var{dev}
15216
SDS monitor, running on a PowerPC board (such as Motorola's ADS).
15217
@end table
15218
 
15219
@cindex SDS protocol
15220
The following commands specific to the SDS protocol are supported
15221
by @value{GDBN}:
15222
 
15223
@table @code
15224
@item set sdstimeout @var{nsec}
15225
@kindex set sdstimeout
15226
Set the timeout for SDS protocol reads to be @var{nsec} seconds.  The
15227
default is 2 seconds.
15228
 
15229
@item show sdstimeout
15230
@kindex show sdstimeout
15231
Show the current value of the SDS timeout.
15232
 
15233
@item sds @var{command}
15234
@kindex sds@r{, a command}
15235
Send the specified @var{command} string to the SDS monitor.
15236
@end table
15237
 
15238
 
15239
@node PA
15240
@subsection HP PA Embedded
15241
 
15242
@table @code
15243
 
15244
@kindex target op50n
15245
@item target op50n @var{dev}
15246
OP50N monitor, running on an OKI HPPA board.
15247
 
15248
@kindex target w89k
15249
@item target w89k @var{dev}
15250
W89K monitor, running on a Winbond HPPA board.
15251
 
15252
@end table
15253
 
15254
@node Sparclet
15255
@subsection Tsqware Sparclet
15256
 
15257
@cindex Sparclet
15258
 
15259
@value{GDBN} enables developers to debug tasks running on
15260
Sparclet targets from a Unix host.
15261
@value{GDBN} uses code that runs on
15262
both the Unix host and on the Sparclet target.  The program
15263
@code{@value{GDBP}} is installed and executed on the Unix host.
15264
 
15265
@table @code
15266
@item remotetimeout @var{args}
15267
@kindex remotetimeout
15268
@value{GDBN} supports the option @code{remotetimeout}.
15269
This option is set by the user, and  @var{args} represents the number of
15270
seconds @value{GDBN} waits for responses.
15271
@end table
15272
 
15273
@cindex compiling, on Sparclet
15274
When compiling for debugging, include the options @samp{-g} to get debug
15275
information and @samp{-Ttext} to relocate the program to where you wish to
15276
load it on the target.  You may also want to add the options @samp{-n} or
15277
@samp{-N} in order to reduce the size of the sections.  Example:
15278
 
15279
@smallexample
15280
sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
15281
@end smallexample
15282
 
15283
You can use @code{objdump} to verify that the addresses are what you intended:
15284
 
15285
@smallexample
15286
sparclet-aout-objdump --headers --syms prog
15287
@end smallexample
15288
 
15289
@cindex running, on Sparclet
15290
Once you have set
15291
your Unix execution search path to find @value{GDBN}, you are ready to
15292
run @value{GDBN}.  From your Unix host, run @code{@value{GDBP}}
15293
(or @code{sparclet-aout-gdb}, depending on your installation).
15294
 
15295
@value{GDBN} comes up showing the prompt:
15296
 
15297
@smallexample
15298
(gdbslet)
15299
@end smallexample
15300
 
15301
@menu
15302
* Sparclet File::                Setting the file to debug
15303
* Sparclet Connection::          Connecting to Sparclet
15304
* Sparclet Download::            Sparclet download
15305
* Sparclet Execution::           Running and debugging
15306
@end menu
15307
 
15308
@node Sparclet File
15309
@subsubsection Setting File to Debug
15310
 
15311
The @value{GDBN} command @code{file} lets you choose with program to debug.
15312
 
15313
@smallexample
15314
(gdbslet) file prog
15315
@end smallexample
15316
 
15317
@need 1000
15318
@value{GDBN} then attempts to read the symbol table of @file{prog}.
15319
@value{GDBN} locates
15320
the file by searching the directories listed in the command search
15321
path.
15322
If the file was compiled with debug information (option @samp{-g}), source
15323
files will be searched as well.
15324
@value{GDBN} locates
15325
the source files by searching the directories listed in the directory search
15326
path (@pxref{Environment, ,Your Program's Environment}).
15327
If it fails
15328
to find a file, it displays a message such as:
15329
 
15330
@smallexample
15331
prog: No such file or directory.
15332
@end smallexample
15333
 
15334
When this happens, add the appropriate directories to the search paths with
15335
the @value{GDBN} commands @code{path} and @code{dir}, and execute the
15336
@code{target} command again.
15337
 
15338
@node Sparclet Connection
15339
@subsubsection Connecting to Sparclet
15340
 
15341
The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
15342
To connect to a target on serial port ``@code{ttya}'', type:
15343
 
15344
@smallexample
15345
(gdbslet) target sparclet /dev/ttya
15346
Remote target sparclet connected to /dev/ttya
15347
main () at ../prog.c:3
15348
@end smallexample
15349
 
15350
@need 750
15351
@value{GDBN} displays messages like these:
15352
 
15353
@smallexample
15354
Connected to ttya.
15355
@end smallexample
15356
 
15357
@node Sparclet Download
15358
@subsubsection Sparclet Download
15359
 
15360
@cindex download to Sparclet
15361
Once connected to the Sparclet target,
15362
you can use the @value{GDBN}
15363
@code{load} command to download the file from the host to the target.
15364
The file name and load offset should be given as arguments to the @code{load}
15365
command.
15366
Since the file format is aout, the program must be loaded to the starting
15367
address.  You can use @code{objdump} to find out what this value is.  The load
15368
offset is an offset which is added to the VMA (virtual memory address)
15369
of each of the file's sections.
15370
For instance, if the program
15371
@file{prog} was linked to text address 0x1201000, with data at 0x12010160
15372
and bss at 0x12010170, in @value{GDBN}, type:
15373
 
15374
@smallexample
15375
(gdbslet) load prog 0x12010000
15376
Loading section .text, size 0xdb0 vma 0x12010000
15377
@end smallexample
15378
 
15379
If the code is loaded at a different address then what the program was linked
15380
to, you may need to use the @code{section} and @code{add-symbol-file} commands
15381
to tell @value{GDBN} where to map the symbol table.
15382
 
15383
@node Sparclet Execution
15384
@subsubsection Running and Debugging
15385
 
15386
@cindex running and debugging Sparclet programs
15387
You can now begin debugging the task using @value{GDBN}'s execution control
15388
commands, @code{b}, @code{step}, @code{run}, etc.  See the @value{GDBN}
15389
manual for the list of commands.
15390
 
15391
@smallexample
15392
(gdbslet) b main
15393
Breakpoint 1 at 0x12010000: file prog.c, line 3.
15394
(gdbslet) run
15395
Starting program: prog
15396
Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
15397
3        char *symarg = 0;
15398
(gdbslet) step
15399
4        char *execarg = "hello!";
15400
(gdbslet)
15401
@end smallexample
15402
 
15403
@node Sparclite
15404
@subsection Fujitsu Sparclite
15405
 
15406
@table @code
15407
 
15408
@kindex target sparclite
15409
@item target sparclite @var{dev}
15410
Fujitsu sparclite boards, used only for the purpose of loading.
15411
You must use an additional command to debug the program.
15412
For example: target remote @var{dev} using @value{GDBN} standard
15413
remote protocol.
15414
 
15415
@end table
15416
 
15417
@node Z8000
15418
@subsection Zilog Z8000
15419
 
15420
@cindex Z8000
15421
@cindex simulator, Z8000
15422
@cindex Zilog Z8000 simulator
15423
 
15424
When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
15425
a Z8000 simulator.
15426
 
15427
For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
15428
unsegmented variant of the Z8000 architecture) or the Z8001 (the
15429
segmented variant).  The simulator recognizes which architecture is
15430
appropriate by inspecting the object code.
15431
 
15432
@table @code
15433
@item target sim @var{args}
15434
@kindex sim
15435
@kindex target sim@r{, with Z8000}
15436
Debug programs on a simulated CPU.  If the simulator supports setup
15437
options, specify them via @var{args}.
15438
@end table
15439
 
15440
@noindent
15441
After specifying this target, you can debug programs for the simulated
15442
CPU in the same style as programs for your host computer; use the
15443
@code{file} command to load a new program image, the @code{run} command
15444
to run your program, and so on.
15445
 
15446
As well as making available all the usual machine registers
15447
(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
15448
additional items of information as specially named registers:
15449
 
15450
@table @code
15451
 
15452
@item cycles
15453
Counts clock-ticks in the simulator.
15454
 
15455
@item insts
15456
Counts instructions run in the simulator.
15457
 
15458
@item time
15459
Execution time in 60ths of a second.
15460
 
15461
@end table
15462
 
15463
You can refer to these values in @value{GDBN} expressions with the usual
15464
conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
15465
conditional breakpoint that suspends only after at least 5000
15466
simulated clock ticks.
15467
 
15468
@node AVR
15469
@subsection Atmel AVR
15470
@cindex AVR
15471
 
15472
When configured for debugging the Atmel AVR, @value{GDBN} supports the
15473
following AVR-specific commands:
15474
 
15475
@table @code
15476
@item info io_registers
15477
@kindex info io_registers@r{, AVR}
15478
@cindex I/O registers (Atmel AVR)
15479
This command displays information about the AVR I/O registers.  For
15480
each register, @value{GDBN} prints its number and value.
15481
@end table
15482
 
15483
@node CRIS
15484
@subsection CRIS
15485
@cindex CRIS
15486
 
15487
When configured for debugging CRIS, @value{GDBN} provides the
15488
following CRIS-specific commands:
15489
 
15490
@table @code
15491
@item set cris-version @var{ver}
15492
@cindex CRIS version
15493
Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
15494
The CRIS version affects register names and sizes.  This command is useful in
15495
case autodetection of the CRIS version fails.
15496
 
15497
@item show cris-version
15498
Show the current CRIS version.
15499
 
15500
@item set cris-dwarf2-cfi
15501
@cindex DWARF-2 CFI and CRIS
15502
Set the usage of DWARF-2 CFI for CRIS debugging.  The default is @samp{on}.
15503
Change to @samp{off} when using @code{gcc-cris} whose version is below
15504
@code{R59}.
15505
 
15506
@item show cris-dwarf2-cfi
15507
Show the current state of using DWARF-2 CFI.
15508
 
15509
@item set cris-mode @var{mode}
15510
@cindex CRIS mode
15511
Set the current CRIS mode to @var{mode}.  It should only be changed when
15512
debugging in guru mode, in which case it should be set to
15513
@samp{guru} (the default is @samp{normal}).
15514
 
15515
@item show cris-mode
15516
Show the current CRIS mode.
15517
@end table
15518
 
15519
@node Super-H
15520
@subsection Renesas Super-H
15521
@cindex Super-H
15522
 
15523
For the Renesas Super-H processor, @value{GDBN} provides these
15524
commands:
15525
 
15526
@table @code
15527
@item regs
15528
@kindex regs@r{, Super-H}
15529
Show the values of all Super-H registers.
15530
@end table
15531
 
15532
 
15533
@node Architectures
15534
@section Architectures
15535
 
15536
This section describes characteristics of architectures that affect
15537
all uses of @value{GDBN} with the architecture, both native and cross.
15538
 
15539
@menu
15540
* i386::
15541
* A29K::
15542
* Alpha::
15543
* MIPS::
15544
* HPPA::               HP PA architecture
15545
* SPU::                Cell Broadband Engine SPU architecture
15546
* PowerPC::
15547
@end menu
15548
 
15549
@node i386
15550
@subsection x86 Architecture-specific Issues
15551
 
15552
@table @code
15553
@item set struct-convention @var{mode}
15554
@kindex set struct-convention
15555
@cindex struct return convention
15556
@cindex struct/union returned in registers
15557
Set the convention used by the inferior to return @code{struct}s and
15558
@code{union}s from functions to @var{mode}.  Possible values of
15559
@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
15560
default).  @code{"default"} or @code{"pcc"} means that @code{struct}s
15561
are returned on the stack, while @code{"reg"} means that a
15562
@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
15563
be returned in a register.
15564
 
15565
@item show struct-convention
15566
@kindex show struct-convention
15567
Show the current setting of the convention to return @code{struct}s
15568
from functions.
15569
@end table
15570
 
15571
@node A29K
15572
@subsection A29K
15573
 
15574
@table @code
15575
 
15576
@kindex set rstack_high_address
15577
@cindex AMD 29K register stack
15578
@cindex register stack, AMD29K
15579
@item set rstack_high_address @var{address}
15580
On AMD 29000 family processors, registers are saved in a separate
15581
@dfn{register stack}.  There is no way for @value{GDBN} to determine the
15582
extent of this stack.  Normally, @value{GDBN} just assumes that the
15583
stack is ``large enough''.  This may result in @value{GDBN} referencing
15584
memory locations that do not exist.  If necessary, you can get around
15585
this problem by specifying the ending address of the register stack with
15586
the @code{set rstack_high_address} command.  The argument should be an
15587
address, which you probably want to precede with @samp{0x} to specify in
15588
hexadecimal.
15589
 
15590
@kindex show rstack_high_address
15591
@item show rstack_high_address
15592
Display the current limit of the register stack, on AMD 29000 family
15593
processors.
15594
 
15595
@end table
15596
 
15597
@node Alpha
15598
@subsection Alpha
15599
 
15600
See the following section.
15601
 
15602
@node MIPS
15603
@subsection MIPS
15604
 
15605
@cindex stack on Alpha
15606
@cindex stack on MIPS
15607
@cindex Alpha stack
15608
@cindex MIPS stack
15609
Alpha- and MIPS-based computers use an unusual stack frame, which
15610
sometimes requires @value{GDBN} to search backward in the object code to
15611
find the beginning of a function.
15612
 
15613
@cindex response time, MIPS debugging
15614
To improve response time (especially for embedded applications, where
15615
@value{GDBN} may be restricted to a slow serial line for this search)
15616
you may want to limit the size of this search, using one of these
15617
commands:
15618
 
15619
@table @code
15620
@cindex @code{heuristic-fence-post} (Alpha, MIPS)
15621
@item set heuristic-fence-post @var{limit}
15622
Restrict @value{GDBN} to examining at most @var{limit} bytes in its
15623
search for the beginning of a function.  A value of @var{0} (the
15624
default) means there is no limit.  However, except for @var{0}, the
15625
larger the limit the more bytes @code{heuristic-fence-post} must search
15626
and therefore the longer it takes to run.  You should only need to use
15627
this command when debugging a stripped executable.
15628
 
15629
@item show heuristic-fence-post
15630
Display the current limit.
15631
@end table
15632
 
15633
@noindent
15634
These commands are available @emph{only} when @value{GDBN} is configured
15635
for debugging programs on Alpha or MIPS processors.
15636
 
15637
Several MIPS-specific commands are available when debugging MIPS
15638
programs:
15639
 
15640
@table @code
15641
@item set mips abi @var{arg}
15642
@kindex set mips abi
15643
@cindex set ABI for MIPS
15644
Tell @value{GDBN} which MIPS ABI is used by the inferior.  Possible
15645
values of @var{arg} are:
15646
 
15647
@table @samp
15648
@item auto
15649
The default ABI associated with the current binary (this is the
15650
default).
15651
@item o32
15652
@item o64
15653
@item n32
15654
@item n64
15655
@item eabi32
15656
@item eabi64
15657
@item auto
15658
@end table
15659
 
15660
@item show mips abi
15661
@kindex show mips abi
15662
Show the MIPS ABI used by @value{GDBN} to debug the inferior.
15663
 
15664
@item set mipsfpu
15665
@itemx show mipsfpu
15666
@xref{MIPS Embedded, set mipsfpu}.
15667
 
15668
@item set mips mask-address @var{arg}
15669
@kindex set mips mask-address
15670
@cindex MIPS addresses, masking
15671
This command determines whether the most-significant 32 bits of 64-bit
15672
MIPS addresses are masked off.  The argument @var{arg} can be
15673
@samp{on}, @samp{off}, or @samp{auto}.  The latter is the default
15674
setting, which lets @value{GDBN} determine the correct value.
15675
 
15676
@item show mips mask-address
15677
@kindex show mips mask-address
15678
Show whether the upper 32 bits of MIPS addresses are masked off or
15679
not.
15680
 
15681
@item set remote-mips64-transfers-32bit-regs
15682
@kindex set remote-mips64-transfers-32bit-regs
15683
This command controls compatibility with 64-bit MIPS targets that
15684
transfer data in 32-bit quantities.  If you have an old MIPS 64 target
15685
that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
15686
and 64 bits for other registers, set this option to @samp{on}.
15687
 
15688
@item show remote-mips64-transfers-32bit-regs
15689
@kindex show remote-mips64-transfers-32bit-regs
15690
Show the current setting of compatibility with older MIPS 64 targets.
15691
 
15692
@item set debug mips
15693
@kindex set debug mips
15694
This command turns on and off debugging messages for the MIPS-specific
15695
target code in @value{GDBN}.
15696
 
15697
@item show debug mips
15698
@kindex show debug mips
15699
Show the current setting of MIPS debugging messages.
15700
@end table
15701
 
15702
 
15703
@node HPPA
15704
@subsection HPPA
15705
@cindex HPPA support
15706
 
15707
When @value{GDBN} is debugging the HP PA architecture, it provides the
15708
following special commands:
15709
 
15710
@table @code
15711
@item set debug hppa
15712
@kindex set debug hppa
15713
This command determines whether HPPA architecture-specific debugging
15714
messages are to be displayed.
15715
 
15716
@item show debug hppa
15717
Show whether HPPA debugging messages are displayed.
15718
 
15719
@item maint print unwind @var{address}
15720
@kindex maint print unwind@r{, HPPA}
15721
This command displays the contents of the unwind table entry at the
15722
given @var{address}.
15723
 
15724
@end table
15725
 
15726
 
15727
@node SPU
15728
@subsection Cell Broadband Engine SPU architecture
15729
@cindex Cell Broadband Engine
15730
@cindex SPU
15731
 
15732
When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
15733
it provides the following special commands:
15734
 
15735
@table @code
15736
@item info spu event
15737
@kindex info spu
15738
Display SPU event facility status.  Shows current event mask
15739
and pending event status.
15740
 
15741
@item info spu signal
15742
Display SPU signal notification facility status.  Shows pending
15743
signal-control word and signal notification mode of both signal
15744
notification channels.
15745
 
15746
@item info spu mailbox
15747
Display SPU mailbox facility status.  Shows all pending entries,
15748
in order of processing, in each of the SPU Write Outbound,
15749
SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
15750
 
15751
@item info spu dma
15752
Display MFC DMA status.  Shows all pending commands in the MFC
15753
DMA queue.  For each entry, opcode, tag, class IDs, effective
15754
and local store addresses and transfer size are shown.
15755
 
15756
@item info spu proxydma
15757
Display MFC Proxy-DMA status.  Shows all pending commands in the MFC
15758
Proxy-DMA queue.  For each entry, opcode, tag, class IDs, effective
15759
and local store addresses and transfer size are shown.
15760
 
15761
@end table
15762
 
15763
@node PowerPC
15764
@subsection PowerPC
15765
@cindex PowerPC architecture
15766
 
15767
When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
15768
pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
15769
numbers stored in the floating point registers. These values must be stored
15770
in two consecutive registers, always starting at an even register like
15771
@code{f0} or @code{f2}.
15772
 
15773
The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
15774
by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
15775
@code{f2} and @code{f3} for @code{$dl1} and so on.
15776
 
15777
 
15778
@node Controlling GDB
15779
@chapter Controlling @value{GDBN}
15780
 
15781
You can alter the way @value{GDBN} interacts with you by using the
15782
@code{set} command.  For commands controlling how @value{GDBN} displays
15783
data, see @ref{Print Settings, ,Print Settings}.  Other settings are
15784
described here.
15785
 
15786
@menu
15787
* Prompt::                      Prompt
15788
* Editing::                     Command editing
15789
* Command History::             Command history
15790
* Screen Size::                 Screen size
15791
* Numbers::                     Numbers
15792
* ABI::                         Configuring the current ABI
15793
* Messages/Warnings::           Optional warnings and messages
15794
* Debugging Output::            Optional messages about internal happenings
15795
@end menu
15796
 
15797
@node Prompt
15798
@section Prompt
15799
 
15800
@cindex prompt
15801
 
15802
@value{GDBN} indicates its readiness to read a command by printing a string
15803
called the @dfn{prompt}.  This string is normally @samp{(@value{GDBP})}.  You
15804
can change the prompt string with the @code{set prompt} command.  For
15805
instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15806
the prompt in one of the @value{GDBN} sessions so that you can always tell
15807
which one you are talking to.
15808
 
15809
@emph{Note:}  @code{set prompt} does not add a space for you after the
15810
prompt you set.  This allows you to set a prompt which ends in a space
15811
or a prompt that does not.
15812
 
15813
@table @code
15814
@kindex set prompt
15815
@item set prompt @var{newprompt}
15816
Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
15817
 
15818
@kindex show prompt
15819
@item show prompt
15820
Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
15821
@end table
15822
 
15823
@node Editing
15824
@section Command Editing
15825
@cindex readline
15826
@cindex command line editing
15827
 
15828
@value{GDBN} reads its input commands via the @dfn{Readline} interface.  This
15829
@sc{gnu} library provides consistent behavior for programs which provide a
15830
command line interface to the user.  Advantages are @sc{gnu} Emacs-style
15831
or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15832
substitution, and a storage and recall of command history across
15833
debugging sessions.
15834
 
15835
You may control the behavior of command line editing in @value{GDBN} with the
15836
command @code{set}.
15837
 
15838
@table @code
15839
@kindex set editing
15840
@cindex editing
15841
@item set editing
15842
@itemx set editing on
15843
Enable command line editing (enabled by default).
15844
 
15845
@item set editing off
15846
Disable command line editing.
15847
 
15848
@kindex show editing
15849
@item show editing
15850
Show whether command line editing is enabled.
15851
@end table
15852
 
15853
@xref{Command Line Editing}, for more details about the Readline
15854
interface.  Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15855
encouraged to read that chapter.
15856
 
15857
@node Command History
15858
@section Command History
15859
@cindex command history
15860
 
15861
@value{GDBN} can keep track of the commands you type during your
15862
debugging sessions, so that you can be certain of precisely what
15863
happened.  Use these commands to manage the @value{GDBN} command
15864
history facility.
15865
 
15866
@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15867
package, to provide the history facility.  @xref{Using History
15868
Interactively}, for the detailed description of the History library.
15869
 
15870
To issue a command to @value{GDBN} without affecting certain aspects of
15871
the state which is seen by users, prefix it with @samp{server }
15872
(@pxref{Server Prefix}).  This
15873
means that this command will not affect the command history, nor will it
15874
affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15875
pressed on a line by itself.
15876
 
15877
@cindex @code{server}, command prefix
15878
The server prefix does not affect the recording of values into the value
15879
history; to print a value without recording it into the value history,
15880
use the @code{output} command instead of the @code{print} command.
15881
 
15882
Here is the description of @value{GDBN} commands related to command
15883
history.
15884
 
15885
@table @code
15886
@cindex history substitution
15887
@cindex history file
15888
@kindex set history filename
15889
@cindex @env{GDBHISTFILE}, environment variable
15890
@item set history filename @var{fname}
15891
Set the name of the @value{GDBN} command history file to @var{fname}.
15892
This is the file where @value{GDBN} reads an initial command history
15893
list, and where it writes the command history from this session when it
15894
exits.  You can access this list through history expansion or through
15895
the history command editing characters listed below.  This file defaults
15896
to the value of the environment variable @code{GDBHISTFILE}, or to
15897
@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15898
is not set.
15899
 
15900
@cindex save command history
15901
@kindex set history save
15902
@item set history save
15903
@itemx set history save on
15904
Record command history in a file, whose name may be specified with the
15905
@code{set history filename} command.  By default, this option is disabled.
15906
 
15907
@item set history save off
15908
Stop recording command history in a file.
15909
 
15910
@cindex history size
15911
@kindex set history size
15912
@cindex @env{HISTSIZE}, environment variable
15913
@item set history size @var{size}
15914
Set the number of commands which @value{GDBN} keeps in its history list.
15915
This defaults to the value of the environment variable
15916
@code{HISTSIZE}, or to 256 if this variable is not set.
15917
@end table
15918
 
15919
History expansion assigns special meaning to the character @kbd{!}.
15920
@xref{Event Designators}, for more details.
15921
 
15922
@cindex history expansion, turn on/off
15923
Since @kbd{!} is also the logical not operator in C, history expansion
15924
is off by default. If you decide to enable history expansion with the
15925
@code{set history expansion on} command, you may sometimes need to
15926
follow @kbd{!} (when it is used as logical not, in an expression) with
15927
a space or a tab to prevent it from being expanded.  The readline
15928
history facilities do not attempt substitution on the strings
15929
@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15930
 
15931
The commands to control history expansion are:
15932
 
15933
@table @code
15934
@item set history expansion on
15935
@itemx set history expansion
15936
@kindex set history expansion
15937
Enable history expansion.  History expansion is off by default.
15938
 
15939
@item set history expansion off
15940
Disable history expansion.
15941
 
15942
@c @group
15943
@kindex show history
15944
@item show history
15945
@itemx show history filename
15946
@itemx show history save
15947
@itemx show history size
15948
@itemx show history expansion
15949
These commands display the state of the @value{GDBN} history parameters.
15950
@code{show history} by itself displays all four states.
15951
@c @end group
15952
@end table
15953
 
15954
@table @code
15955
@kindex show commands
15956
@cindex show last commands
15957
@cindex display command history
15958
@item show commands
15959
Display the last ten commands in the command history.
15960
 
15961
@item show commands @var{n}
15962
Print ten commands centered on command number @var{n}.
15963
 
15964
@item show commands +
15965
Print ten commands just after the commands last printed.
15966
@end table
15967
 
15968
@node Screen Size
15969
@section Screen Size
15970
@cindex size of screen
15971
@cindex pauses in output
15972
 
15973
Certain commands to @value{GDBN} may produce large amounts of
15974
information output to the screen.  To help you read all of it,
15975
@value{GDBN} pauses and asks you for input at the end of each page of
15976
output.  Type @key{RET} when you want to continue the output, or @kbd{q}
15977
to discard the remaining output.  Also, the screen width setting
15978
determines when to wrap lines of output.  Depending on what is being
15979
printed, @value{GDBN} tries to break the line at a readable place,
15980
rather than simply letting it overflow onto the following line.
15981
 
15982
Normally @value{GDBN} knows the size of the screen from the terminal
15983
driver software.  For example, on Unix @value{GDBN} uses the termcap data base
15984
together with the value of the @code{TERM} environment variable and the
15985
@code{stty rows} and @code{stty cols} settings.  If this is not correct,
15986
you can override it with the @code{set height} and @code{set
15987
width} commands:
15988
 
15989
@table @code
15990
@kindex set height
15991
@kindex set width
15992
@kindex show width
15993
@kindex show height
15994
@item set height @var{lpp}
15995
@itemx show height
15996
@itemx set width @var{cpl}
15997
@itemx show width
15998
These @code{set} commands specify a screen height of @var{lpp} lines and
15999
a screen width of @var{cpl} characters.  The associated @code{show}
16000
commands display the current settings.
16001
 
16002
If you specify a height of zero lines, @value{GDBN} does not pause during
16003
output no matter how long the output is.  This is useful if output is to a
16004
file or to an editor buffer.
16005
 
16006
Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
16007
from wrapping its output.
16008
 
16009
@item set pagination on
16010
@itemx set pagination off
16011
@kindex set pagination
16012
Turn the output pagination on or off; the default is on.  Turning
16013
pagination off is the alternative to @code{set height 0}.
16014
 
16015
@item show pagination
16016
@kindex show pagination
16017
Show the current pagination mode.
16018
@end table
16019
 
16020
@node Numbers
16021
@section Numbers
16022
@cindex number representation
16023
@cindex entering numbers
16024
 
16025
You can always enter numbers in octal, decimal, or hexadecimal in
16026
@value{GDBN} by the usual conventions: octal numbers begin with
16027
@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
16028
begin with @samp{0x}.  Numbers that neither begin with @samp{0} or
16029
@samp{0x}, nor end with a @samp{.} are, by default, entered in base
16030
10; likewise, the default display for numbers---when no particular
16031
format is specified---is base 10.  You can change the default base for
16032
both input and output with the commands described below.
16033
 
16034
@table @code
16035
@kindex set input-radix
16036
@item set input-radix @var{base}
16037
Set the default base for numeric input.  Supported choices
16038
for @var{base} are decimal 8, 10, or 16.  @var{base} must itself be
16039
specified either unambiguously or using the current input radix; for
16040
example, any of
16041
 
16042
@smallexample
16043
set input-radix 012
16044
set input-radix 10.
16045
set input-radix 0xa
16046
@end smallexample
16047
 
16048
@noindent
16049
sets the input base to decimal.  On the other hand, @samp{set input-radix 10}
16050
leaves the input radix unchanged, no matter what it was, since
16051
@samp{10}, being without any leading or trailing signs of its base, is
16052
interpreted in the current radix.  Thus, if the current radix is 16,
16053
@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
16054
change the radix.
16055
 
16056
@kindex set output-radix
16057
@item set output-radix @var{base}
16058
Set the default base for numeric display.  Supported choices
16059
for @var{base} are decimal 8, 10, or 16.  @var{base} must itself be
16060
specified either unambiguously or using the current input radix.
16061
 
16062
@kindex show input-radix
16063
@item show input-radix
16064
Display the current default base for numeric input.
16065
 
16066
@kindex show output-radix
16067
@item show output-radix
16068
Display the current default base for numeric display.
16069
 
16070
@item set radix @r{[}@var{base}@r{]}
16071
@itemx show radix
16072
@kindex set radix
16073
@kindex show radix
16074
These commands set and show the default base for both input and output
16075
of numbers.  @code{set radix} sets the radix of input and output to
16076
the same base; without an argument, it resets the radix back to its
16077
default value of 10.
16078
 
16079
@end table
16080
 
16081
@node ABI
16082
@section Configuring the Current ABI
16083
 
16084
@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
16085
application automatically.  However, sometimes you need to override its
16086
conclusions.  Use these commands to manage @value{GDBN}'s view of the
16087
current ABI.
16088
 
16089
@cindex OS ABI
16090
@kindex set osabi
16091
@kindex show osabi
16092
 
16093
One @value{GDBN} configuration can debug binaries for multiple operating
16094
system targets, either via remote debugging or native emulation.
16095
@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
16096
but you can override its conclusion using the @code{set osabi} command.
16097
One example where this is useful is in debugging of binaries which use
16098
an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
16099
not have the same identifying marks that the standard C library for your
16100
platform provides.
16101
 
16102
@table @code
16103
@item show osabi
16104
Show the OS ABI currently in use.
16105
 
16106
@item set osabi
16107
With no argument, show the list of registered available OS ABI's.
16108
 
16109
@item set osabi @var{abi}
16110
Set the current OS ABI to @var{abi}.
16111
@end table
16112
 
16113
@cindex float promotion
16114
 
16115
Generally, the way that an argument of type @code{float} is passed to a
16116
function depends on whether the function is prototyped.  For a prototyped
16117
(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
16118
according to the architecture's convention for @code{float}.  For unprototyped
16119
(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
16120
@code{double} and then passed.
16121
 
16122
Unfortunately, some forms of debug information do not reliably indicate whether
16123
a function is prototyped.  If @value{GDBN} calls a function that is not marked
16124
as prototyped, it consults @kbd{set coerce-float-to-double}.
16125
 
16126
@table @code
16127
@kindex set coerce-float-to-double
16128
@item set coerce-float-to-double
16129
@itemx set coerce-float-to-double on
16130
Arguments of type @code{float} will be promoted to @code{double} when passed
16131
to an unprototyped function.  This is the default setting.
16132
 
16133
@item set coerce-float-to-double off
16134
Arguments of type @code{float} will be passed directly to unprototyped
16135
functions.
16136
 
16137
@kindex show coerce-float-to-double
16138
@item show coerce-float-to-double
16139
Show the current setting of promoting @code{float} to @code{double}.
16140
@end table
16141
 
16142
@kindex set cp-abi
16143
@kindex show cp-abi
16144
@value{GDBN} needs to know the ABI used for your program's C@t{++}
16145
objects.  The correct C@t{++} ABI depends on which C@t{++} compiler was
16146
used to build your application.  @value{GDBN} only fully supports
16147
programs with a single C@t{++} ABI; if your program contains code using
16148
multiple C@t{++} ABI's or if @value{GDBN} can not identify your
16149
program's ABI correctly, you can tell @value{GDBN} which ABI to use.
16150
Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
16151
before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
16152
``hpaCC'' for the HP ANSI C@t{++} compiler.  Other C@t{++} compilers may
16153
use the ``gnu-v2'' or ``gnu-v3'' ABI's as well.  The default setting is
16154
``auto''.
16155
 
16156
@table @code
16157
@item show cp-abi
16158
Show the C@t{++} ABI currently in use.
16159
 
16160
@item set cp-abi
16161
With no argument, show the list of supported C@t{++} ABI's.
16162
 
16163
@item set cp-abi @var{abi}
16164
@itemx set cp-abi auto
16165
Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
16166
@end table
16167
 
16168
@node Messages/Warnings
16169
@section Optional Warnings and Messages
16170
 
16171
@cindex verbose operation
16172
@cindex optional warnings
16173
By default, @value{GDBN} is silent about its inner workings.  If you are
16174
running on a slow machine, you may want to use the @code{set verbose}
16175
command.  This makes @value{GDBN} tell you when it does a lengthy
16176
internal operation, so you will not think it has crashed.
16177
 
16178
Currently, the messages controlled by @code{set verbose} are those
16179
which announce that the symbol table for a source file is being read;
16180
see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
16181
 
16182
@table @code
16183
@kindex set verbose
16184
@item set verbose on
16185
Enables @value{GDBN} output of certain informational messages.
16186
 
16187
@item set verbose off
16188
Disables @value{GDBN} output of certain informational messages.
16189
 
16190
@kindex show verbose
16191
@item show verbose
16192
Displays whether @code{set verbose} is on or off.
16193
@end table
16194
 
16195
By default, if @value{GDBN} encounters bugs in the symbol table of an
16196
object file, it is silent; but if you are debugging a compiler, you may
16197
find this information useful (@pxref{Symbol Errors, ,Errors Reading
16198
Symbol Files}).
16199
 
16200
@table @code
16201
 
16202
@kindex set complaints
16203
@item set complaints @var{limit}
16204
Permits @value{GDBN} to output @var{limit} complaints about each type of
16205
unusual symbols before becoming silent about the problem.  Set
16206
@var{limit} to zero to suppress all complaints; set it to a large number
16207
to prevent complaints from being suppressed.
16208
 
16209
@kindex show complaints
16210
@item show complaints
16211
Displays how many symbol complaints @value{GDBN} is permitted to produce.
16212
 
16213
@end table
16214
 
16215
By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
16216
lot of stupid questions to confirm certain commands.  For example, if
16217
you try to run a program which is already running:
16218
 
16219
@smallexample
16220
(@value{GDBP}) run
16221
The program being debugged has been started already.
16222
Start it from the beginning? (y or n)
16223
@end smallexample
16224
 
16225
If you are willing to unflinchingly face the consequences of your own
16226
commands, you can disable this ``feature'':
16227
 
16228
@table @code
16229
 
16230
@kindex set confirm
16231
@cindex flinching
16232
@cindex confirmation
16233
@cindex stupid questions
16234
@item set confirm off
16235
Disables confirmation requests.
16236
 
16237
@item set confirm on
16238
Enables confirmation requests (the default).
16239
 
16240
@kindex show confirm
16241
@item show confirm
16242
Displays state of confirmation requests.
16243
 
16244
@end table
16245
 
16246
@cindex command tracing
16247
If you need to debug user-defined commands or sourced files you may find it
16248
useful to enable @dfn{command tracing}.  In this mode each command will be
16249
printed as it is executed, prefixed with one or more @samp{+} symbols, the
16250
quantity denoting the call depth of each command.
16251
 
16252
@table @code
16253
@kindex set trace-commands
16254
@cindex command scripts, debugging
16255
@item set trace-commands on
16256
Enable command tracing.
16257
@item set trace-commands off
16258
Disable command tracing.
16259
@item show trace-commands
16260
Display the current state of command tracing.
16261
@end table
16262
 
16263
@node Debugging Output
16264
@section Optional Messages about Internal Happenings
16265
@cindex optional debugging messages
16266
 
16267
@value{GDBN} has commands that enable optional debugging messages from
16268
various @value{GDBN} subsystems; normally these commands are of
16269
interest to @value{GDBN} maintainers, or when reporting a bug.  This
16270
section documents those commands.
16271
 
16272
@table @code
16273
@kindex set exec-done-display
16274
@item set exec-done-display
16275
Turns on or off the notification of asynchronous commands'
16276
completion.  When on, @value{GDBN} will print a message when an
16277
asynchronous command finishes its execution.  The default is off.
16278
@kindex show exec-done-display
16279
@item show exec-done-display
16280
Displays the current setting of asynchronous command completion
16281
notification.
16282
@kindex set debug
16283
@cindex gdbarch debugging info
16284
@cindex architecture debugging info
16285
@item set debug arch
16286
Turns on or off display of gdbarch debugging info.  The default is off
16287
@kindex show debug
16288
@item show debug arch
16289
Displays the current state of displaying gdbarch debugging info.
16290
@item set debug aix-thread
16291
@cindex AIX threads
16292
Display debugging messages about inner workings of the AIX thread
16293
module.
16294
@item show debug aix-thread
16295
Show the current state of AIX thread debugging info display.
16296
@item set debug event
16297
@cindex event debugging info
16298
Turns on or off display of @value{GDBN} event debugging info.  The
16299
default is off.
16300
@item show debug event
16301
Displays the current state of displaying @value{GDBN} event debugging
16302
info.
16303
@item set debug expression
16304
@cindex expression debugging info
16305
Turns on or off display of debugging info about @value{GDBN}
16306
expression parsing.  The default is off.
16307
@item show debug expression
16308
Displays the current state of displaying debugging info about
16309
@value{GDBN} expression parsing.
16310
@item set debug frame
16311
@cindex frame debugging info
16312
Turns on or off display of @value{GDBN} frame debugging info.  The
16313
default is off.
16314
@item show debug frame
16315
Displays the current state of displaying @value{GDBN} frame debugging
16316
info.
16317
@item set debug infrun
16318
@cindex inferior debugging info
16319
Turns on or off display of @value{GDBN} debugging info for running the inferior.
16320
The default is off.  @file{infrun.c} contains GDB's runtime state machine used
16321
for implementing operations such as single-stepping the inferior.
16322
@item show debug infrun
16323
Displays the current state of @value{GDBN} inferior debugging.
16324
@item set debug lin-lwp
16325
@cindex @sc{gnu}/Linux LWP debug messages
16326
@cindex Linux lightweight processes
16327
Turns on or off debugging messages from the Linux LWP debug support.
16328
@item show debug lin-lwp
16329
Show the current state of Linux LWP debugging messages.
16330
@item set debug observer
16331
@cindex observer debugging info
16332
Turns on or off display of @value{GDBN} observer debugging.  This
16333
includes info such as the notification of observable events.
16334
@item show debug observer
16335
Displays the current state of observer debugging.
16336
@item set debug overload
16337
@cindex C@t{++} overload debugging info
16338
Turns on or off display of @value{GDBN} C@t{++} overload debugging
16339
info. This includes info such as ranking of functions, etc.  The default
16340
is off.
16341
@item show debug overload
16342
Displays the current state of displaying @value{GDBN} C@t{++} overload
16343
debugging info.
16344
@cindex packets, reporting on stdout
16345
@cindex serial connections, debugging
16346
@cindex debug remote protocol
16347
@cindex remote protocol debugging
16348
@cindex display remote packets
16349
@item set debug remote
16350
Turns on or off display of reports on all packets sent back and forth across
16351
the serial line to the remote machine.  The info is printed on the
16352
@value{GDBN} standard output stream. The default is off.
16353
@item show debug remote
16354
Displays the state of display of remote packets.
16355
@item set debug serial
16356
Turns on or off display of @value{GDBN} serial debugging info. The
16357
default is off.
16358
@item show debug serial
16359
Displays the current state of displaying @value{GDBN} serial debugging
16360
info.
16361
@item set debug solib-frv
16362
@cindex FR-V shared-library debugging
16363
Turns on or off debugging messages for FR-V shared-library code.
16364
@item show debug solib-frv
16365
Display the current state of FR-V shared-library code debugging
16366
messages.
16367
@item set debug target
16368
@cindex target debugging info
16369
Turns on or off display of @value{GDBN} target debugging info. This info
16370
includes what is going on at the target level of GDB, as it happens. The
16371
default is 0.  Set it to 1 to track events, and to 2 to also track the
16372
value of large memory transfers.  Changes to this flag do not take effect
16373
until the next time you connect to a target or use the @code{run} command.
16374
@item show debug target
16375
Displays the current state of displaying @value{GDBN} target debugging
16376
info.
16377
@item set debugvarobj
16378
@cindex variable object debugging info
16379
Turns on or off display of @value{GDBN} variable object debugging
16380
info. The default is off.
16381
@item show debugvarobj
16382
Displays the current state of displaying @value{GDBN} variable object
16383
debugging info.
16384
@item set debug xml
16385
@cindex XML parser debugging
16386
Turns on or off debugging messages for built-in XML parsers.
16387
@item show debug xml
16388
Displays the current state of XML debugging messages.
16389
@end table
16390
 
16391
@node Sequences
16392
@chapter Canned Sequences of Commands
16393
 
16394
Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
16395
Command Lists}), @value{GDBN} provides two ways to store sequences of
16396
commands for execution as a unit: user-defined commands and command
16397
files.
16398
 
16399
@menu
16400
* Define::             How to define your own commands
16401
* Hooks::              Hooks for user-defined commands
16402
* Command Files::      How to write scripts of commands to be stored in a file
16403
* Output::             Commands for controlled output
16404
@end menu
16405
 
16406
@node Define
16407
@section User-defined Commands
16408
 
16409
@cindex user-defined command
16410
@cindex arguments, to user-defined commands
16411
A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
16412
which you assign a new name as a command.  This is done with the
16413
@code{define} command.  User commands may accept up to 10 arguments
16414
separated by whitespace.  Arguments are accessed within the user command
16415
via @code{$arg0@dots{}$arg9}.  A trivial example:
16416
 
16417
@smallexample
16418
define adder
16419
  print $arg0 + $arg1 + $arg2
16420
end
16421
@end smallexample
16422
 
16423
@noindent
16424
To execute the command use:
16425
 
16426
@smallexample
16427
adder 1 2 3
16428
@end smallexample
16429
 
16430
@noindent
16431
This defines the command @code{adder}, which prints the sum of
16432
its three arguments.  Note the arguments are text substitutions, so they may
16433
reference variables, use complex expressions, or even perform inferior
16434
functions calls.
16435
 
16436
@cindex argument count in user-defined commands
16437
@cindex how many arguments (user-defined commands)
16438
In addition, @code{$argc} may be used to find out how many arguments have
16439
been passed.  This expands to a number in the range 0@dots{}10.
16440
 
16441
@smallexample
16442
define adder
16443
  if $argc == 2
16444
    print $arg0 + $arg1
16445
  end
16446
  if $argc == 3
16447
    print $arg0 + $arg1 + $arg2
16448
  end
16449
end
16450
@end smallexample
16451
 
16452
@table @code
16453
 
16454
@kindex define
16455
@item define @var{commandname}
16456
Define a command named @var{commandname}.  If there is already a command
16457
by that name, you are asked to confirm that you want to redefine it.
16458
 
16459
The definition of the command is made up of other @value{GDBN} command lines,
16460
which are given following the @code{define} command.  The end of these
16461
commands is marked by a line containing @code{end}.
16462
 
16463
@kindex document
16464
@kindex end@r{ (user-defined commands)}
16465
@item document @var{commandname}
16466
Document the user-defined command @var{commandname}, so that it can be
16467
accessed by @code{help}.  The command @var{commandname} must already be
16468
defined.  This command reads lines of documentation just as @code{define}
16469
reads the lines of the command definition, ending with @code{end}.
16470
After the @code{document} command is finished, @code{help} on command
16471
@var{commandname} displays the documentation you have written.
16472
 
16473
You may use the @code{document} command again to change the
16474
documentation of a command.  Redefining the command with @code{define}
16475
does not change the documentation.
16476
 
16477
@kindex dont-repeat
16478
@cindex don't repeat command
16479
@item dont-repeat
16480
Used inside a user-defined command, this tells @value{GDBN} that this
16481
command should not be repeated when the user hits @key{RET}
16482
(@pxref{Command Syntax, repeat last command}).
16483
 
16484
@kindex help user-defined
16485
@item help user-defined
16486
List all user-defined commands, with the first line of the documentation
16487
(if any) for each.
16488
 
16489
@kindex show user
16490
@item show user
16491
@itemx show user @var{commandname}
16492
Display the @value{GDBN} commands used to define @var{commandname} (but
16493
not its documentation).  If no @var{commandname} is given, display the
16494
definitions for all user-defined commands.
16495
 
16496
@cindex infinite recursion in user-defined commands
16497
@kindex show max-user-call-depth
16498
@kindex set max-user-call-depth
16499
@item show max-user-call-depth
16500
@itemx set max-user-call-depth
16501
The value of @code{max-user-call-depth} controls how many recursion
16502
levels are allowed in user-defined commands before @value{GDBN} suspects an
16503
infinite recursion and aborts the command.
16504
@end table
16505
 
16506
In addition to the above commands, user-defined commands frequently
16507
use control flow commands, described in @ref{Command Files}.
16508
 
16509
When user-defined commands are executed, the
16510
commands of the definition are not printed.  An error in any command
16511
stops execution of the user-defined command.
16512
 
16513
If used interactively, commands that would ask for confirmation proceed
16514
without asking when used inside a user-defined command.  Many @value{GDBN}
16515
commands that normally print messages to say what they are doing omit the
16516
messages when used in a user-defined command.
16517
 
16518
@node Hooks
16519
@section User-defined Command Hooks
16520
@cindex command hooks
16521
@cindex hooks, for commands
16522
@cindex hooks, pre-command
16523
 
16524
@kindex hook
16525
You may define @dfn{hooks}, which are a special kind of user-defined
16526
command.  Whenever you run the command @samp{foo}, if the user-defined
16527
command @samp{hook-foo} exists, it is executed (with no arguments)
16528
before that command.
16529
 
16530
@cindex hooks, post-command
16531
@kindex hookpost
16532
A hook may also be defined which is run after the command you executed.
16533
Whenever you run the command @samp{foo}, if the user-defined command
16534
@samp{hookpost-foo} exists, it is executed (with no arguments) after
16535
that command.  Post-execution hooks may exist simultaneously with
16536
pre-execution hooks, for the same command.
16537
 
16538
It is valid for a hook to call the command which it hooks.  If this
16539
occurs, the hook is not re-executed, thereby avoiding infinite recursion.
16540
 
16541
@c It would be nice if hookpost could be passed a parameter indicating
16542
@c if the command it hooks executed properly or not.  FIXME!
16543
 
16544
@kindex stop@r{, a pseudo-command}
16545
In addition, a pseudo-command, @samp{stop} exists.  Defining
16546
(@samp{hook-stop}) makes the associated commands execute every time
16547
execution stops in your program: before breakpoint commands are run,
16548
displays are printed, or the stack frame is printed.
16549
 
16550
For example, to ignore @code{SIGALRM} signals while
16551
single-stepping, but treat them normally during normal execution,
16552
you could define:
16553
 
16554
@smallexample
16555
define hook-stop
16556
handle SIGALRM nopass
16557
end
16558
 
16559
define hook-run
16560
handle SIGALRM pass
16561
end
16562
 
16563
define hook-continue
16564
handle SIGALRM pass
16565
end
16566
@end smallexample
16567
 
16568
As a further example, to hook at the beginning and end of the @code{echo}
16569
command, and to add extra text to the beginning and end of the message,
16570
you could define:
16571
 
16572
@smallexample
16573
define hook-echo
16574
echo <<<---
16575
end
16576
 
16577
define hookpost-echo
16578
echo --->>>\n
16579
end
16580
 
16581
(@value{GDBP}) echo Hello World
16582
<<<---Hello World--->>>
16583
(@value{GDBP})
16584
 
16585
@end smallexample
16586
 
16587
You can define a hook for any single-word command in @value{GDBN}, but
16588
not for command aliases; you should define a hook for the basic command
16589
name, e.g.@:  @code{backtrace} rather than @code{bt}.
16590
@c FIXME!  So how does Joe User discover whether a command is an alias
16591
@c or not?
16592
If an error occurs during the execution of your hook, execution of
16593
@value{GDBN} commands stops and @value{GDBN} issues a prompt
16594
(before the command that you actually typed had a chance to run).
16595
 
16596
If you try to define a hook which does not match any known command, you
16597
get a warning from the @code{define} command.
16598
 
16599
@node Command Files
16600
@section Command Files
16601
 
16602
@cindex command files
16603
@cindex scripting commands
16604
A command file for @value{GDBN} is a text file made of lines that are
16605
@value{GDBN} commands.  Comments (lines starting with @kbd{#}) may
16606
also be included.  An empty line in a command file does nothing; it
16607
does not mean to repeat the last command, as it would from the
16608
terminal.
16609
 
16610
You can request the execution of a command file with the @code{source}
16611
command:
16612
 
16613
@table @code
16614
@kindex source
16615
@cindex execute commands from a file
16616
@item source [@code{-v}] @var{filename}
16617
Execute the command file @var{filename}.
16618
@end table
16619
 
16620
The lines in a command file are generally executed sequentially,
16621
unless the order of execution is changed by one of the
16622
@emph{flow-control commands} described below.  The commands are not
16623
printed as they are executed.  An error in any command terminates
16624
execution of the command file and control is returned to the console.
16625
 
16626
@value{GDBN} searches for @var{filename} in the current directory and then
16627
on the search path (specified with the @samp{directory} command).
16628
 
16629
If @code{-v}, for verbose mode, is given then @value{GDBN} displays
16630
each command as it is executed.  The option must be given before
16631
@var{filename}, and is interpreted as part of the filename anywhere else.
16632
 
16633
Commands that would ask for confirmation if used interactively proceed
16634
without asking when used in a command file.  Many @value{GDBN} commands that
16635
normally print messages to say what they are doing omit the messages
16636
when called from command files.
16637
 
16638
@value{GDBN} also accepts command input from standard input.  In this
16639
mode, normal output goes to standard output and error output goes to
16640
standard error.  Errors in a command file supplied on standard input do
16641
not terminate execution of the command file---execution continues with
16642
the next command.
16643
 
16644
@smallexample
16645
gdb < cmds > log 2>&1
16646
@end smallexample
16647
 
16648
(The syntax above will vary depending on the shell used.) This example
16649
will execute commands from the file @file{cmds}. All output and errors
16650
would be directed to @file{log}.
16651
 
16652
Since commands stored on command files tend to be more general than
16653
commands typed interactively, they frequently need to deal with
16654
complicated situations, such as different or unexpected values of
16655
variables and symbols, changes in how the program being debugged is
16656
built, etc.  @value{GDBN} provides a set of flow-control commands to
16657
deal with these complexities.  Using these commands, you can write
16658
complex scripts that loop over data structures, execute commands
16659
conditionally, etc.
16660
 
16661
@table @code
16662
@kindex if
16663
@kindex else
16664
@item if
16665
@itemx else
16666
This command allows to include in your script conditionally executed
16667
commands. The @code{if} command takes a single argument, which is an
16668
expression to evaluate.  It is followed by a series of commands that
16669
are executed only if the expression is true (its value is nonzero).
16670
There can then optionally be an @code{else} line, followed by a series
16671
of commands that are only executed if the expression was false.  The
16672
end of the list is marked by a line containing @code{end}.
16673
 
16674
@kindex while
16675
@item while
16676
This command allows to write loops.  Its syntax is similar to
16677
@code{if}: the command takes a single argument, which is an expression
16678
to evaluate, and must be followed by the commands to execute, one per
16679
line, terminated by an @code{end}.  These commands are called the
16680
@dfn{body} of the loop.  The commands in the body of @code{while} are
16681
executed repeatedly as long as the expression evaluates to true.
16682
 
16683
@kindex loop_break
16684
@item loop_break
16685
This command exits the @code{while} loop in whose body it is included.
16686
Execution of the script continues after that @code{while}s @code{end}
16687
line.
16688
 
16689
@kindex loop_continue
16690
@item loop_continue
16691
This command skips the execution of the rest of the body of commands
16692
in the @code{while} loop in whose body it is included.  Execution
16693
branches to the beginning of the @code{while} loop, where it evaluates
16694
the controlling expression.
16695
 
16696
@kindex end@r{ (if/else/while commands)}
16697
@item end
16698
Terminate the block of commands that are the body of @code{if},
16699
@code{else}, or @code{while} flow-control commands.
16700
@end table
16701
 
16702
 
16703
@node Output
16704
@section Commands for Controlled Output
16705
 
16706
During the execution of a command file or a user-defined command, normal
16707
@value{GDBN} output is suppressed; the only output that appears is what is
16708
explicitly printed by the commands in the definition.  This section
16709
describes three commands useful for generating exactly the output you
16710
want.
16711
 
16712
@table @code
16713
@kindex echo
16714
@item echo @var{text}
16715
@c I do not consider backslash-space a standard C escape sequence
16716
@c because it is not in ANSI.
16717
Print @var{text}.  Nonprinting characters can be included in
16718
@var{text} using C escape sequences, such as @samp{\n} to print a
16719
newline.  @strong{No newline is printed unless you specify one.}
16720
In addition to the standard C escape sequences, a backslash followed
16721
by a space stands for a space.  This is useful for displaying a
16722
string with spaces at the beginning or the end, since leading and
16723
trailing spaces are otherwise trimmed from all arguments.
16724
To print @samp{@w{ }and foo =@w{ }}, use the command
16725
@samp{echo \@w{ }and foo = \@w{ }}.
16726
 
16727
A backslash at the end of @var{text} can be used, as in C, to continue
16728
the command onto subsequent lines.  For example,
16729
 
16730
@smallexample
16731
echo This is some text\n\
16732
which is continued\n\
16733
onto several lines.\n
16734
@end smallexample
16735
 
16736
produces the same output as
16737
 
16738
@smallexample
16739
echo This is some text\n
16740
echo which is continued\n
16741
echo onto several lines.\n
16742
@end smallexample
16743
 
16744
@kindex output
16745
@item output @var{expression}
16746
Print the value of @var{expression} and nothing but that value: no
16747
newlines, no @samp{$@var{nn} = }.  The value is not entered in the
16748
value history either.  @xref{Expressions, ,Expressions}, for more information
16749
on expressions.
16750
 
16751
@item output/@var{fmt} @var{expression}
16752
Print the value of @var{expression} in format @var{fmt}.  You can use
16753
the same formats as for @code{print}.  @xref{Output Formats,,Output
16754
Formats}, for more information.
16755
 
16756
@kindex printf
16757
@item printf @var{template}, @var{expressions}@dots{}
16758
Print the values of one or more @var{expressions} under the control of
16759
the string @var{template}.  To print several values, make
16760
@var{expressions} be a comma-separated list of individual expressions,
16761
which may be either numbers or pointers.  Their values are printed as
16762
specified by @var{template}, exactly as a C program would do by
16763
executing the code below:
16764
 
16765
@smallexample
16766
printf (@var{template}, @var{expressions}@dots{});
16767
@end smallexample
16768
 
16769
As in @code{C} @code{printf}, ordinary characters in @var{template}
16770
are printed verbatim, while @dfn{conversion specification} introduced
16771
by the @samp{%} character cause subsequent @var{expressions} to be
16772
evaluated, their values converted and formatted according to type and
16773
style information encoded in the conversion specifications, and then
16774
printed.
16775
 
16776
For example, you can print two values in hex like this:
16777
 
16778
@smallexample
16779
printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
16780
@end smallexample
16781
 
16782
@code{printf} supports all the standard @code{C} conversion
16783
specifications, including the flags and modifiers between the @samp{%}
16784
character and the conversion letter, with the following exceptions:
16785
 
16786
@itemize @bullet
16787
@item
16788
The argument-ordering modifiers, such as @samp{2$}, are not supported.
16789
 
16790
@item
16791
The modifier @samp{*} is not supported for specifying precision or
16792
width.
16793
 
16794
@item
16795
The @samp{'} flag (for separation of digits into groups according to
16796
@code{LC_NUMERIC'}) is not supported.
16797
 
16798
@item
16799
The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
16800
supported.
16801
 
16802
@item
16803
The conversion letter @samp{n} (as in @samp{%n}) is not supported.
16804
 
16805
@item
16806
The conversion letters @samp{a} and @samp{A} are not supported.
16807
@end itemize
16808
 
16809
@noindent
16810
Note that the @samp{ll} type modifier is supported only if the
16811
underlying @code{C} implementation used to build @value{GDBN} supports
16812
the @code{long long int} type, and the @samp{L} type modifier is
16813
supported only if @code{long double} type is available.
16814
 
16815
As in @code{C}, @code{printf} supports simple backslash-escape
16816
sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
16817
@samp{\a}, and @samp{\f}, that consist of backslash followed by a
16818
single character.  Octal and hexadecimal escape sequences are not
16819
supported.
16820
 
16821
Additionally, @code{printf} supports conversion specifications for DFP
16822
(@dfn{Decimal Floating Point}) types using the following length modifiers
16823
together with a floating point specifier.
16824
letters:
16825
 
16826
@itemize @bullet
16827
@item
16828
@samp{H} for printing @code{Decimal32} types.
16829
 
16830
@item
16831
@samp{D} for printing @code{Decimal64} types.
16832
 
16833
@item
16834
@samp{DD} for printing @code{Decimal128} types.
16835
@end itemize
16836
 
16837
If the underlying @code{C} implementation used to build @value{GDBN} has
16838
support for the three length modifiers for DFP types, other modifiers
16839
such as width and precision will also be available for @value{GDBN} to use.
16840
 
16841
In case there is no such @code{C} support, no additional modifiers will be
16842
available and the value will be printed in the standard way.
16843
 
16844
Here's an example of printing DFP types using the above conversion letters:
16845
@smallexample
16846
printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
16847
@end smallexample
16848
 
16849
@end table
16850
 
16851
@node Interpreters
16852
@chapter Command Interpreters
16853
@cindex command interpreters
16854
 
16855
@value{GDBN} supports multiple command interpreters, and some command
16856
infrastructure to allow users or user interface writers to switch
16857
between interpreters or run commands in other interpreters.
16858
 
16859
@value{GDBN} currently supports two command interpreters, the console
16860
interpreter (sometimes called the command-line interpreter or @sc{cli})
16861
and the machine interface interpreter (or @sc{gdb/mi}).  This manual
16862
describes both of these interfaces in great detail.
16863
 
16864
By default, @value{GDBN} will start with the console interpreter.
16865
However, the user may choose to start @value{GDBN} with another
16866
interpreter by specifying the @option{-i} or @option{--interpreter}
16867
startup options.  Defined interpreters include:
16868
 
16869
@table @code
16870
@item console
16871
@cindex console interpreter
16872
The traditional console or command-line interpreter.  This is the most often
16873
used interpreter with @value{GDBN}. With no interpreter specified at runtime,
16874
@value{GDBN} will use this interpreter.
16875
 
16876
@item mi
16877
@cindex mi interpreter
16878
The newest @sc{gdb/mi} interface (currently @code{mi2}).  Used primarily
16879
by programs wishing to use @value{GDBN} as a backend for a debugger GUI
16880
or an IDE.  For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
16881
Interface}.
16882
 
16883
@item mi2
16884
@cindex mi2 interpreter
16885
The current @sc{gdb/mi} interface.
16886
 
16887
@item mi1
16888
@cindex mi1 interpreter
16889
The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
16890
 
16891
@end table
16892
 
16893
@cindex invoke another interpreter
16894
The interpreter being used by @value{GDBN} may not be dynamically
16895
switched at runtime.  Although possible, this could lead to a very
16896
precarious situation.  Consider an IDE using @sc{gdb/mi}.  If a user
16897
enters the command "interpreter-set console" in a console view,
16898
@value{GDBN} would switch to using the console interpreter, rendering
16899
the IDE inoperable!
16900
 
16901
@kindex interpreter-exec
16902
Although you may only choose a single interpreter at startup, you may execute
16903
commands in any interpreter from the current interpreter using the appropriate
16904
command.  If you are running the console interpreter, simply use the
16905
@code{interpreter-exec} command:
16906
 
16907
@smallexample
16908
interpreter-exec mi "-data-list-register-names"
16909
@end smallexample
16910
 
16911
@sc{gdb/mi} has a similar command, although it is only available in versions of
16912
@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16913
 
16914
@node TUI
16915
@chapter @value{GDBN} Text User Interface
16916
@cindex TUI
16917
@cindex Text User Interface
16918
 
16919
@menu
16920
* TUI Overview::                TUI overview
16921
* TUI Keys::                    TUI key bindings
16922
* TUI Single Key Mode::         TUI single key mode
16923
* TUI Commands::                TUI-specific commands
16924
* TUI Configuration::           TUI configuration variables
16925
@end menu
16926
 
16927
The @value{GDBN} Text User Interface (TUI) is a terminal
16928
interface which uses the @code{curses} library to show the source
16929
file, the assembly output, the program registers and @value{GDBN}
16930
commands in separate text windows.  The TUI mode is supported only
16931
on platforms where a suitable version of the @code{curses} library
16932
is available.
16933
 
16934
@pindex @value{GDBTUI}
16935
The TUI mode is enabled by default when you invoke @value{GDBN} as
16936
either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
16937
You can also switch in and out of TUI mode while @value{GDBN} runs by
16938
using various TUI commands and key bindings, such as @kbd{C-x C-a}.
16939
@xref{TUI Keys, ,TUI Key Bindings}.
16940
 
16941
@node TUI Overview
16942
@section TUI Overview
16943
 
16944
In TUI mode, @value{GDBN} can display several text windows:
16945
 
16946
@table @emph
16947
@item command
16948
This window is the @value{GDBN} command window with the @value{GDBN}
16949
prompt and the @value{GDBN} output.  The @value{GDBN} input is still
16950
managed using readline.
16951
 
16952
@item source
16953
The source window shows the source file of the program.  The current
16954
line and active breakpoints are displayed in this window.
16955
 
16956
@item assembly
16957
The assembly window shows the disassembly output of the program.
16958
 
16959
@item register
16960
This window shows the processor registers.  Registers are highlighted
16961
when their values change.
16962
@end table
16963
 
16964
The source and assembly windows show the current program position
16965
by highlighting the current line and marking it with a @samp{>} marker.
16966
Breakpoints are indicated with two markers.  The first marker
16967
indicates the breakpoint type:
16968
 
16969
@table @code
16970
@item B
16971
Breakpoint which was hit at least once.
16972
 
16973
@item b
16974
Breakpoint which was never hit.
16975
 
16976
@item H
16977
Hardware breakpoint which was hit at least once.
16978
 
16979
@item h
16980
Hardware breakpoint which was never hit.
16981
@end table
16982
 
16983
The second marker indicates whether the breakpoint is enabled or not:
16984
 
16985
@table @code
16986
@item +
16987
Breakpoint is enabled.
16988
 
16989
@item -
16990
Breakpoint is disabled.
16991
@end table
16992
 
16993
The source, assembly and register windows are updated when the current
16994
thread changes, when the frame changes, or when the program counter
16995
changes.
16996
 
16997
These windows are not all visible at the same time.  The command
16998
window is always visible.  The others can be arranged in several
16999
layouts:
17000
 
17001
@itemize @bullet
17002
@item
17003
source only,
17004
 
17005
@item
17006
assembly only,
17007
 
17008
@item
17009
source and assembly,
17010
 
17011
@item
17012
source and registers, or
17013
 
17014
@item
17015
assembly and registers.
17016
@end itemize
17017
 
17018
A status line above the command window shows the following information:
17019
 
17020
@table @emph
17021
@item target
17022
Indicates the current @value{GDBN} target.
17023
(@pxref{Targets, ,Specifying a Debugging Target}).
17024
 
17025
@item process
17026
Gives the current process or thread number.
17027
When no process is being debugged, this field is set to @code{No process}.
17028
 
17029
@item function
17030
Gives the current function name for the selected frame.
17031
The name is demangled if demangling is turned on (@pxref{Print Settings}).
17032
When there is no symbol corresponding to the current program counter,
17033
the string @code{??} is displayed.
17034
 
17035
@item line
17036
Indicates the current line number for the selected frame.
17037
When the current line number is not known, the string @code{??} is displayed.
17038
 
17039
@item pc
17040
Indicates the current program counter address.
17041
@end table
17042
 
17043
@node TUI Keys
17044
@section TUI Key Bindings
17045
@cindex TUI key bindings
17046
 
17047
The TUI installs several key bindings in the readline keymaps
17048
(@pxref{Command Line Editing}).  The following key bindings
17049
are installed for both TUI mode and the @value{GDBN} standard mode.
17050
 
17051
@table @kbd
17052
@kindex C-x C-a
17053
@item C-x C-a
17054
@kindex C-x a
17055
@itemx C-x a
17056
@kindex C-x A
17057
@itemx C-x A
17058
Enter or leave the TUI mode.  When leaving the TUI mode,
17059
the curses window management stops and @value{GDBN} operates using
17060
its standard mode, writing on the terminal directly.  When reentering
17061
the TUI mode, control is given back to the curses windows.
17062
The screen is then refreshed.
17063
 
17064
@kindex C-x 1
17065
@item C-x 1
17066
Use a TUI layout with only one window.  The layout will
17067
either be @samp{source} or @samp{assembly}.  When the TUI mode
17068
is not active, it will switch to the TUI mode.
17069
 
17070
Think of this key binding as the Emacs @kbd{C-x 1} binding.
17071
 
17072
@kindex C-x 2
17073
@item C-x 2
17074
Use a TUI layout with at least two windows.  When the current
17075
layout already has two windows, the next layout with two windows is used.
17076
When a new layout is chosen, one window will always be common to the
17077
previous layout and the new one.
17078
 
17079
Think of it as the Emacs @kbd{C-x 2} binding.
17080
 
17081
@kindex C-x o
17082
@item C-x o
17083
Change the active window.  The TUI associates several key bindings
17084
(like scrolling and arrow keys) with the active window.  This command
17085
gives the focus to the next TUI window.
17086
 
17087
Think of it as the Emacs @kbd{C-x o} binding.
17088
 
17089
@kindex C-x s
17090
@item C-x s
17091
Switch in and out of the TUI SingleKey mode that binds single
17092
keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
17093
@end table
17094
 
17095
The following key bindings only work in the TUI mode:
17096
 
17097
@table @asis
17098
@kindex PgUp
17099
@item @key{PgUp}
17100
Scroll the active window one page up.
17101
 
17102
@kindex PgDn
17103
@item @key{PgDn}
17104
Scroll the active window one page down.
17105
 
17106
@kindex Up
17107
@item @key{Up}
17108
Scroll the active window one line up.
17109
 
17110
@kindex Down
17111
@item @key{Down}
17112
Scroll the active window one line down.
17113
 
17114
@kindex Left
17115
@item @key{Left}
17116
Scroll the active window one column left.
17117
 
17118
@kindex Right
17119
@item @key{Right}
17120
Scroll the active window one column right.
17121
 
17122
@kindex C-L
17123
@item @kbd{C-L}
17124
Refresh the screen.
17125
@end table
17126
 
17127
Because the arrow keys scroll the active window in the TUI mode, they
17128
are not available for their normal use by readline unless the command
17129
window has the focus.  When another window is active, you must use
17130
other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
17131
and @kbd{C-f} to control the command window.
17132
 
17133
@node TUI Single Key Mode
17134
@section TUI Single Key Mode
17135
@cindex TUI single key mode
17136
 
17137
The TUI also provides a @dfn{SingleKey} mode, which binds several
17138
frequently used @value{GDBN} commands to single keys.  Type @kbd{C-x s} to
17139
switch into this mode, where the following key bindings are used:
17140
 
17141
@table @kbd
17142
@kindex c @r{(SingleKey TUI key)}
17143
@item c
17144
continue
17145
 
17146
@kindex d @r{(SingleKey TUI key)}
17147
@item d
17148
down
17149
 
17150
@kindex f @r{(SingleKey TUI key)}
17151
@item f
17152
finish
17153
 
17154
@kindex n @r{(SingleKey TUI key)}
17155
@item n
17156
next
17157
 
17158
@kindex q @r{(SingleKey TUI key)}
17159
@item q
17160
exit the SingleKey mode.
17161
 
17162
@kindex r @r{(SingleKey TUI key)}
17163
@item r
17164
run
17165
 
17166
@kindex s @r{(SingleKey TUI key)}
17167
@item s
17168
step
17169
 
17170
@kindex u @r{(SingleKey TUI key)}
17171
@item u
17172
up
17173
 
17174
@kindex v @r{(SingleKey TUI key)}
17175
@item v
17176
info locals
17177
 
17178
@kindex w @r{(SingleKey TUI key)}
17179
@item w
17180
where
17181
@end table
17182
 
17183
Other keys temporarily switch to the @value{GDBN} command prompt.
17184
The key that was pressed is inserted in the editing buffer so that
17185
it is possible to type most @value{GDBN} commands without interaction
17186
with the TUI SingleKey mode.  Once the command is entered the TUI
17187
SingleKey mode is restored.  The only way to permanently leave
17188
this mode is by typing @kbd{q} or @kbd{C-x s}.
17189
 
17190
 
17191
@node TUI Commands
17192
@section TUI-specific Commands
17193
@cindex TUI commands
17194
 
17195
The TUI has specific commands to control the text windows.
17196
These commands are always available, even when @value{GDBN} is not in
17197
the TUI mode.  When @value{GDBN} is in the standard mode, most
17198
of these commands will automatically switch to the TUI mode.
17199
 
17200
@table @code
17201
@item info win
17202
@kindex info win
17203
List and give the size of all displayed windows.
17204
 
17205
@item layout next
17206
@kindex layout
17207
Display the next layout.
17208
 
17209
@item layout prev
17210
Display the previous layout.
17211
 
17212
@item layout src
17213
Display the source window only.
17214
 
17215
@item layout asm
17216
Display the assembly window only.
17217
 
17218
@item layout split
17219
Display the source and assembly window.
17220
 
17221
@item layout regs
17222
Display the register window together with the source or assembly window.
17223
 
17224
@item focus next
17225
@kindex focus
17226
Make the next window active for scrolling.
17227
 
17228
@item focus prev
17229
Make the previous window active for scrolling.
17230
 
17231
@item focus src
17232
Make the source window active for scrolling.
17233
 
17234
@item focus asm
17235
Make the assembly window active for scrolling.
17236
 
17237
@item focus regs
17238
Make the register window active for scrolling.
17239
 
17240
@item focus cmd
17241
Make the command window active for scrolling.
17242
 
17243
@item refresh
17244
@kindex refresh
17245
Refresh the screen.  This is similar to typing @kbd{C-L}.
17246
 
17247
@item tui reg float
17248
@kindex tui reg
17249
Show the floating point registers in the register window.
17250
 
17251
@item tui reg general
17252
Show the general registers in the register window.
17253
 
17254
@item tui reg next
17255
Show the next register group.  The list of register groups as well as
17256
their order is target specific.  The predefined register groups are the
17257
following: @code{general}, @code{float}, @code{system}, @code{vector},
17258
@code{all}, @code{save}, @code{restore}.
17259
 
17260
@item tui reg system
17261
Show the system registers in the register window.
17262
 
17263
@item update
17264
@kindex update
17265
Update the source window and the current execution point.
17266
 
17267
@item winheight @var{name} +@var{count}
17268
@itemx winheight @var{name} -@var{count}
17269
@kindex winheight
17270
Change the height of the window @var{name} by @var{count}
17271
lines.  Positive counts increase the height, while negative counts
17272
decrease it.
17273
 
17274
@item tabset @var{nchars}
17275
@kindex tabset
17276
Set the width of tab stops to be @var{nchars} characters.
17277
@end table
17278
 
17279
@node TUI Configuration
17280
@section TUI Configuration Variables
17281
@cindex TUI configuration variables
17282
 
17283
Several configuration variables control the appearance of TUI windows.
17284
 
17285
@table @code
17286
@item set tui border-kind @var{kind}
17287
@kindex set tui border-kind
17288
Select the border appearance for the source, assembly and register windows.
17289
The possible values are the following:
17290
@table @code
17291
@item space
17292
Use a space character to draw the border.
17293
 
17294
@item ascii
17295
Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
17296
 
17297
@item acs
17298
Use the Alternate Character Set to draw the border.  The border is
17299
drawn using character line graphics if the terminal supports them.
17300
@end table
17301
 
17302
@item set tui border-mode @var{mode}
17303
@kindex set tui border-mode
17304
@itemx set tui active-border-mode @var{mode}
17305
@kindex set tui active-border-mode
17306
Select the display attributes for the borders of the inactive windows
17307
or the active window.  The @var{mode} can be one of the following:
17308
@table @code
17309
@item normal
17310
Use normal attributes to display the border.
17311
 
17312
@item standout
17313
Use standout mode.
17314
 
17315
@item reverse
17316
Use reverse video mode.
17317
 
17318
@item half
17319
Use half bright mode.
17320
 
17321
@item half-standout
17322
Use half bright and standout mode.
17323
 
17324
@item bold
17325
Use extra bright or bold mode.
17326
 
17327
@item bold-standout
17328
Use extra bright or bold and standout mode.
17329
@end table
17330
@end table
17331
 
17332
@node Emacs
17333
@chapter Using @value{GDBN} under @sc{gnu} Emacs
17334
 
17335
@cindex Emacs
17336
@cindex @sc{gnu} Emacs
17337
A special interface allows you to use @sc{gnu} Emacs to view (and
17338
edit) the source files for the program you are debugging with
17339
@value{GDBN}.
17340
 
17341
To use this interface, use the command @kbd{M-x gdb} in Emacs.  Give the
17342
executable file you want to debug as an argument.  This command starts
17343
@value{GDBN} as a subprocess of Emacs, with input and output through a newly
17344
created Emacs buffer.
17345
@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
17346
 
17347
Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
17348
things:
17349
 
17350
@itemize @bullet
17351
@item
17352
All ``terminal'' input and output goes through an Emacs buffer, called
17353
the GUD buffer.
17354
 
17355
This applies both to @value{GDBN} commands and their output, and to the input
17356
and output done by the program you are debugging.
17357
 
17358
This is useful because it means that you can copy the text of previous
17359
commands and input them again; you can even use parts of the output
17360
in this way.
17361
 
17362
All the facilities of Emacs' Shell mode are available for interacting
17363
with your program.  In particular, you can send signals the usual
17364
way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
17365
stop.
17366
 
17367
@item
17368
@value{GDBN} displays source code through Emacs.
17369
 
17370
Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
17371
source file for that frame and puts an arrow (@samp{=>}) at the
17372
left margin of the current line.  Emacs uses a separate buffer for
17373
source display, and splits the screen to show both your @value{GDBN} session
17374
and the source.
17375
 
17376
Explicit @value{GDBN} @code{list} or search commands still produce output as
17377
usual, but you probably have no reason to use them from Emacs.
17378
@end itemize
17379
 
17380
We call this @dfn{text command mode}.  Emacs 22.1, and later, also uses
17381
a graphical mode, enabled by default, which provides further buffers
17382
that can control the execution and describe the state of your program.
17383
@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
17384
 
17385
If you specify an absolute file name when prompted for the @kbd{M-x
17386
gdb} argument, then Emacs sets your current working directory to where
17387
your program resides.  If you only specify the file name, then Emacs
17388
sets your current working directory to to the directory associated
17389
with the previous buffer.  In this case, @value{GDBN} may find your
17390
program by searching your environment's @code{PATH} variable, but on
17391
some operating systems it might not find the source.  So, although the
17392
@value{GDBN} input and output session proceeds normally, the auxiliary
17393
buffer does not display the current source and line of execution.
17394
 
17395
The initial working directory of @value{GDBN} is printed on the top
17396
line of the GUD buffer and this serves as a default for the commands
17397
that specify files for @value{GDBN} to operate on.  @xref{Files,
17398
,Commands to Specify Files}.
17399
 
17400
By default, @kbd{M-x gdb} calls the program called @file{gdb}.  If you
17401
need to call @value{GDBN} by a different name (for example, if you
17402
keep several configurations around, with different names) you can
17403
customize the Emacs variable @code{gud-gdb-command-name} to run the
17404
one you want.
17405
 
17406
In the GUD buffer, you can use these special Emacs commands in
17407
addition to the standard Shell mode commands:
17408
 
17409
@table @kbd
17410
@item C-h m
17411
Describe the features of Emacs' GUD Mode.
17412
 
17413
@item C-c C-s
17414
Execute to another source line, like the @value{GDBN} @code{step} command; also
17415
update the display window to show the current file and location.
17416
 
17417
@item C-c C-n
17418
Execute to next source line in this function, skipping all function
17419
calls, like the @value{GDBN} @code{next} command.  Then update the display window
17420
to show the current file and location.
17421
 
17422
@item C-c C-i
17423
Execute one instruction, like the @value{GDBN} @code{stepi} command; update
17424
display window accordingly.
17425
 
17426
@item C-c C-f
17427
Execute until exit from the selected stack frame, like the @value{GDBN}
17428
@code{finish} command.
17429
 
17430
@item C-c C-r
17431
Continue execution of your program, like the @value{GDBN} @code{continue}
17432
command.
17433
 
17434
@item C-c <
17435
Go up the number of frames indicated by the numeric argument
17436
(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
17437
like the @value{GDBN} @code{up} command.
17438
 
17439
@item C-c >
17440
Go down the number of frames indicated by the numeric argument, like the
17441
@value{GDBN} @code{down} command.
17442
@end table
17443
 
17444
In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
17445
tells @value{GDBN} to set a breakpoint on the source line point is on.
17446
 
17447
In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
17448
separate frame which shows a backtrace when the GUD buffer is current.
17449
Move point to any frame in the stack and type @key{RET} to make it
17450
become the current frame and display the associated source in the
17451
source buffer.  Alternatively, click @kbd{Mouse-2} to make the
17452
selected frame become the current one.  In graphical mode, the
17453
speedbar displays watch expressions.
17454
 
17455
If you accidentally delete the source-display buffer, an easy way to get
17456
it back is to type the command @code{f} in the @value{GDBN} buffer, to
17457
request a frame display; when you run under Emacs, this recreates
17458
the source buffer if necessary to show you the context of the current
17459
frame.
17460
 
17461
The source files displayed in Emacs are in ordinary Emacs buffers
17462
which are visiting the source files in the usual way.  You can edit
17463
the files with these buffers if you wish; but keep in mind that @value{GDBN}
17464
communicates with Emacs in terms of line numbers.  If you add or
17465
delete lines from the text, the line numbers that @value{GDBN} knows cease
17466
to correspond properly with the code.
17467
 
17468
A more detailed description of Emacs' interaction with @value{GDBN} is
17469
given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
17470
Emacs Manual}).
17471
 
17472
@c The following dropped because Epoch is nonstandard.  Reactivate
17473
@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
17474
@ignore
17475
@kindex Emacs Epoch environment
17476
@kindex Epoch
17477
@kindex inspect
17478
 
17479
Version 18 of @sc{gnu} Emacs has a built-in window system
17480
called the @code{epoch}
17481
environment.  Users of this environment can use a new command,
17482
@code{inspect} which performs identically to @code{print} except that
17483
each value is printed in its own window.
17484
@end ignore
17485
 
17486
 
17487
@node GDB/MI
17488
@chapter The @sc{gdb/mi} Interface
17489
 
17490
@unnumberedsec Function and Purpose
17491
 
17492
@cindex @sc{gdb/mi}, its purpose
17493
@sc{gdb/mi} is a line based machine oriented text interface to
17494
@value{GDBN} and is activated by specifying using the
17495
@option{--interpreter} command line option (@pxref{Mode Options}).  It
17496
is specifically intended to support the development of systems which
17497
use the debugger as just one small component of a larger system.
17498
 
17499
This chapter is a specification of the @sc{gdb/mi} interface.  It is written
17500
in the form of a reference manual.
17501
 
17502
Note that @sc{gdb/mi} is still under construction, so some of the
17503
features described below are incomplete and subject to change
17504
(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
17505
 
17506
@unnumberedsec Notation and Terminology
17507
 
17508
@cindex notational conventions, for @sc{gdb/mi}
17509
This chapter uses the following notation:
17510
 
17511
@itemize @bullet
17512
@item
17513
@code{|} separates two alternatives.
17514
 
17515
@item
17516
@code{[ @var{something} ]} indicates that @var{something} is optional:
17517
it may or may not be given.
17518
 
17519
@item
17520
@code{( @var{group} )*} means that @var{group} inside the parentheses
17521
may repeat zero or more times.
17522
 
17523
@item
17524
@code{( @var{group} )+} means that @var{group} inside the parentheses
17525
may repeat one or more times.
17526
 
17527
@item
17528
@code{"@var{string}"} means a literal @var{string}.
17529
@end itemize
17530
 
17531
@ignore
17532
@heading Dependencies
17533
@end ignore
17534
 
17535
@menu
17536
* GDB/MI Command Syntax::
17537
* GDB/MI Compatibility with CLI::
17538
* GDB/MI Development and Front Ends::
17539
* GDB/MI Output Records::
17540
* GDB/MI Simple Examples::
17541
* GDB/MI Command Description Format::
17542
* GDB/MI Breakpoint Commands::
17543
* GDB/MI Program Context::
17544
* GDB/MI Thread Commands::
17545
* GDB/MI Program Execution::
17546
* GDB/MI Stack Manipulation::
17547
* GDB/MI Variable Objects::
17548
* GDB/MI Data Manipulation::
17549
* GDB/MI Tracepoint Commands::
17550
* GDB/MI Symbol Query::
17551
* GDB/MI File Commands::
17552
@ignore
17553
* GDB/MI Kod Commands::
17554
* GDB/MI Memory Overlay Commands::
17555
* GDB/MI Signal Handling Commands::
17556
@end ignore
17557
* GDB/MI Target Manipulation::
17558
* GDB/MI File Transfer Commands::
17559
* GDB/MI Miscellaneous Commands::
17560
@end menu
17561
 
17562
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17563
@node GDB/MI Command Syntax
17564
@section @sc{gdb/mi} Command Syntax
17565
 
17566
@menu
17567
* GDB/MI Input Syntax::
17568
* GDB/MI Output Syntax::
17569
@end menu
17570
 
17571
@node GDB/MI Input Syntax
17572
@subsection @sc{gdb/mi} Input Syntax
17573
 
17574
@cindex input syntax for @sc{gdb/mi}
17575
@cindex @sc{gdb/mi}, input syntax
17576
@table @code
17577
@item @var{command} @expansion{}
17578
@code{@var{cli-command} | @var{mi-command}}
17579
 
17580
@item @var{cli-command} @expansion{}
17581
@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
17582
@var{cli-command} is any existing @value{GDBN} CLI command.
17583
 
17584
@item @var{mi-command} @expansion{}
17585
@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
17586
@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
17587
 
17588
@item @var{token} @expansion{}
17589
"any sequence of digits"
17590
 
17591
@item @var{option} @expansion{}
17592
@code{"-" @var{parameter} [ " " @var{parameter} ]}
17593
 
17594
@item @var{parameter} @expansion{}
17595
@code{@var{non-blank-sequence} | @var{c-string}}
17596
 
17597
@item @var{operation} @expansion{}
17598
@emph{any of the operations described in this chapter}
17599
 
17600
@item @var{non-blank-sequence} @expansion{}
17601
@emph{anything, provided it doesn't contain special characters such as
17602
"-", @var{nl}, """ and of course " "}
17603
 
17604
@item @var{c-string} @expansion{}
17605
@code{""" @var{seven-bit-iso-c-string-content} """}
17606
 
17607
@item @var{nl} @expansion{}
17608
@code{CR | CR-LF}
17609
@end table
17610
 
17611
@noindent
17612
Notes:
17613
 
17614
@itemize @bullet
17615
@item
17616
The CLI commands are still handled by the @sc{mi} interpreter; their
17617
output is described below.
17618
 
17619
@item
17620
The @code{@var{token}}, when present, is passed back when the command
17621
finishes.
17622
 
17623
@item
17624
Some @sc{mi} commands accept optional arguments as part of the parameter
17625
list.  Each option is identified by a leading @samp{-} (dash) and may be
17626
followed by an optional argument parameter.  Options occur first in the
17627
parameter list and can be delimited from normal parameters using
17628
@samp{--} (this is useful when some parameters begin with a dash).
17629
@end itemize
17630
 
17631
Pragmatics:
17632
 
17633
@itemize @bullet
17634
@item
17635
We want easy access to the existing CLI syntax (for debugging).
17636
 
17637
@item
17638
We want it to be easy to spot a @sc{mi} operation.
17639
@end itemize
17640
 
17641
@node GDB/MI Output Syntax
17642
@subsection @sc{gdb/mi} Output Syntax
17643
 
17644
@cindex output syntax of @sc{gdb/mi}
17645
@cindex @sc{gdb/mi}, output syntax
17646
The output from @sc{gdb/mi} consists of zero or more out-of-band records
17647
followed, optionally, by a single result record.  This result record
17648
is for the most recent command.  The sequence of output records is
17649
terminated by @samp{(gdb)}.
17650
 
17651
If an input command was prefixed with a @code{@var{token}} then the
17652
corresponding output for that command will also be prefixed by that same
17653
@var{token}.
17654
 
17655
@table @code
17656
@item @var{output} @expansion{}
17657
@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
17658
 
17659
@item @var{result-record} @expansion{}
17660
@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
17661
 
17662
@item @var{out-of-band-record} @expansion{}
17663
@code{@var{async-record} | @var{stream-record}}
17664
 
17665
@item @var{async-record} @expansion{}
17666
@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
17667
 
17668
@item @var{exec-async-output} @expansion{}
17669
@code{[ @var{token} ] "*" @var{async-output}}
17670
 
17671
@item @var{status-async-output} @expansion{}
17672
@code{[ @var{token} ] "+" @var{async-output}}
17673
 
17674
@item @var{notify-async-output} @expansion{}
17675
@code{[ @var{token} ] "=" @var{async-output}}
17676
 
17677
@item @var{async-output} @expansion{}
17678
@code{@var{async-class} ( "," @var{result} )* @var{nl}}
17679
 
17680
@item @var{result-class} @expansion{}
17681
@code{"done" | "running" | "connected" | "error" | "exit"}
17682
 
17683
@item @var{async-class} @expansion{}
17684
@code{"stopped" | @var{others}} (where @var{others} will be added
17685
depending on the needs---this is still in development).
17686
 
17687
@item @var{result} @expansion{}
17688
@code{ @var{variable} "=" @var{value}}
17689
 
17690
@item @var{variable} @expansion{}
17691
@code{ @var{string} }
17692
 
17693
@item @var{value} @expansion{}
17694
@code{ @var{const} | @var{tuple} | @var{list} }
17695
 
17696
@item @var{const} @expansion{}
17697
@code{@var{c-string}}
17698
 
17699
@item @var{tuple} @expansion{}
17700
@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
17701
 
17702
@item @var{list} @expansion{}
17703
@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
17704
@var{result} ( "," @var{result} )* "]" }
17705
 
17706
@item @var{stream-record} @expansion{}
17707
@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
17708
 
17709
@item @var{console-stream-output} @expansion{}
17710
@code{"~" @var{c-string}}
17711
 
17712
@item @var{target-stream-output} @expansion{}
17713
@code{"@@" @var{c-string}}
17714
 
17715
@item @var{log-stream-output} @expansion{}
17716
@code{"&" @var{c-string}}
17717
 
17718
@item @var{nl} @expansion{}
17719
@code{CR | CR-LF}
17720
 
17721
@item @var{token} @expansion{}
17722
@emph{any sequence of digits}.
17723
@end table
17724
 
17725
@noindent
17726
Notes:
17727
 
17728
@itemize @bullet
17729
@item
17730
All output sequences end in a single line containing a period.
17731
 
17732
@item
17733
The @code{@var{token}} is from the corresponding request.  If an execution
17734
command is interrupted by the @samp{-exec-interrupt} command, the
17735
@var{token} associated with the @samp{*stopped} message is the one of the
17736
original execution command, not the one of the interrupt command.
17737
 
17738
@item
17739
@cindex status output in @sc{gdb/mi}
17740
@var{status-async-output} contains on-going status information about the
17741
progress of a slow operation.  It can be discarded.  All status output is
17742
prefixed by @samp{+}.
17743
 
17744
@item
17745
@cindex async output in @sc{gdb/mi}
17746
@var{exec-async-output} contains asynchronous state change on the target
17747
(stopped, started, disappeared).  All async output is prefixed by
17748
@samp{*}.
17749
 
17750
@item
17751
@cindex notify output in @sc{gdb/mi}
17752
@var{notify-async-output} contains supplementary information that the
17753
client should handle (e.g., a new breakpoint information).  All notify
17754
output is prefixed by @samp{=}.
17755
 
17756
@item
17757
@cindex console output in @sc{gdb/mi}
17758
@var{console-stream-output} is output that should be displayed as is in the
17759
console.  It is the textual response to a CLI command.  All the console
17760
output is prefixed by @samp{~}.
17761
 
17762
@item
17763
@cindex target output in @sc{gdb/mi}
17764
@var{target-stream-output} is the output produced by the target program.
17765
All the target output is prefixed by @samp{@@}.
17766
 
17767
@item
17768
@cindex log output in @sc{gdb/mi}
17769
@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
17770
instance messages that should be displayed as part of an error log.  All
17771
the log output is prefixed by @samp{&}.
17772
 
17773
@item
17774
@cindex list output in @sc{gdb/mi}
17775
New @sc{gdb/mi} commands should only output @var{lists} containing
17776
@var{values}.
17777
 
17778
 
17779
@end itemize
17780
 
17781
@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
17782
details about the various output records.
17783
 
17784
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17785
@node GDB/MI Compatibility with CLI
17786
@section @sc{gdb/mi} Compatibility with CLI
17787
 
17788
@cindex compatibility, @sc{gdb/mi} and CLI
17789
@cindex @sc{gdb/mi}, compatibility with CLI
17790
 
17791
For the developers convenience CLI commands can be entered directly,
17792
but there may be some unexpected behaviour.  For example, commands
17793
that query the user will behave as if the user replied yes, breakpoint
17794
command lists are not executed and some CLI commands, such as
17795
@code{if}, @code{when} and @code{define}, prompt for further input with
17796
@samp{>}, which is not valid MI output.
17797
 
17798
This feature may be removed at some stage in the future and it is
17799
recommended that front ends use the @code{-interpreter-exec} command
17800
(@pxref{-interpreter-exec}).
17801
 
17802
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17803
@node GDB/MI Development and Front Ends
17804
@section @sc{gdb/mi} Development and Front Ends
17805
@cindex @sc{gdb/mi} development
17806
 
17807
The application which takes the MI output and presents the state of the
17808
program being debugged to the user is called a @dfn{front end}.
17809
 
17810
Although @sc{gdb/mi} is still incomplete, it is currently being used
17811
by a variety of front ends to @value{GDBN}.  This makes it difficult
17812
to introduce new functionality without breaking existing usage.  This
17813
section tries to minimize the problems by describing how the protocol
17814
might change.
17815
 
17816
Some changes in MI need not break a carefully designed front end, and
17817
for these the MI version will remain unchanged.  The following is a
17818
list of changes that may occur within one level, so front ends should
17819
parse MI output in a way that can handle them:
17820
 
17821
@itemize @bullet
17822
@item
17823
New MI commands may be added.
17824
 
17825
@item
17826
New fields may be added to the output of any MI command.
17827
 
17828
@item
17829
The range of values for fields with specified values, e.g.,
17830
@code{in_scope} (@pxref{-var-update}) may be extended.
17831
 
17832
@c The format of field's content e.g type prefix, may change so parse it
17833
@c   at your own risk.  Yes, in general?
17834
 
17835
@c The order of fields may change?  Shouldn't really matter but it might
17836
@c resolve inconsistencies.
17837
@end itemize
17838
 
17839
If the changes are likely to break front ends, the MI version level
17840
will be increased by one.  This will allow the front end to parse the
17841
output according to the MI version.  Apart from mi0, new versions of
17842
@value{GDBN} will not support old versions of MI and it will be the
17843
responsibility of the front end to work with the new one.
17844
 
17845
@c Starting with mi3, add a new command -mi-version that prints the MI
17846
@c version?
17847
 
17848
The best way to avoid unexpected changes in MI that might break your front
17849
end is to make your project known to @value{GDBN} developers and
17850
follow development on @email{gdb@@sourceware.org} and
17851
@email{gdb-patches@@sourceware.org}.  There is also the mailing list
17852
@email{dmi-discuss@@lists.freestandards.org}, hosted by the Free Standards
17853
Group, which has the aim of creating a more general MI protocol
17854
called Debugger Machine Interface (DMI) that will become a standard
17855
for all debuggers, not just @value{GDBN}.
17856
@cindex mailing lists
17857
 
17858
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17859
@node GDB/MI Output Records
17860
@section @sc{gdb/mi} Output Records
17861
 
17862
@menu
17863
* GDB/MI Result Records::
17864
* GDB/MI Stream Records::
17865
* GDB/MI Out-of-band Records::
17866
@end menu
17867
 
17868
@node GDB/MI Result Records
17869
@subsection @sc{gdb/mi} Result Records
17870
 
17871
@cindex result records in @sc{gdb/mi}
17872
@cindex @sc{gdb/mi}, result records
17873
In addition to a number of out-of-band notifications, the response to a
17874
@sc{gdb/mi} command includes one of the following result indications:
17875
 
17876
@table @code
17877
@findex ^done
17878
@item "^done" [ "," @var{results} ]
17879
The synchronous operation was successful, @code{@var{results}} are the return
17880
values.
17881
 
17882
@item "^running"
17883
@findex ^running
17884
@c Is this one correct?  Should it be an out-of-band notification?
17885
The asynchronous operation was successfully started.  The target is
17886
running.
17887
 
17888
@item "^connected"
17889
@findex ^connected
17890
@value{GDBN} has connected to a remote target.
17891
 
17892
@item "^error" "," @var{c-string}
17893
@findex ^error
17894
The operation failed.  The @code{@var{c-string}} contains the corresponding
17895
error message.
17896
 
17897
@item "^exit"
17898
@findex ^exit
17899
@value{GDBN} has terminated.
17900
 
17901
@end table
17902
 
17903
@node GDB/MI Stream Records
17904
@subsection @sc{gdb/mi} Stream Records
17905
 
17906
@cindex @sc{gdb/mi}, stream records
17907
@cindex stream records in @sc{gdb/mi}
17908
@value{GDBN} internally maintains a number of output streams: the console, the
17909
target, and the log.  The output intended for each of these streams is
17910
funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17911
 
17912
Each stream record begins with a unique @dfn{prefix character} which
17913
identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17914
Syntax}).  In addition to the prefix, each stream record contains a
17915
@code{@var{string-output}}.  This is either raw text (with an implicit new
17916
line) or a quoted C string (which does not contain an implicit newline).
17917
 
17918
@table @code
17919
@item "~" @var{string-output}
17920
The console output stream contains text that should be displayed in the
17921
CLI console window.  It contains the textual responses to CLI commands.
17922
 
17923
@item "@@" @var{string-output}
17924
The target output stream contains any textual output from the running
17925
target.  This is only present when GDB's event loop is truly
17926
asynchronous, which is currently only the case for remote targets.
17927
 
17928
@item "&" @var{string-output}
17929
The log stream contains debugging messages being produced by @value{GDBN}'s
17930
internals.
17931
@end table
17932
 
17933
@node GDB/MI Out-of-band Records
17934
@subsection @sc{gdb/mi} Out-of-band Records
17935
 
17936
@cindex out-of-band records in @sc{gdb/mi}
17937
@cindex @sc{gdb/mi}, out-of-band records
17938
@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17939
additional changes that have occurred.  Those changes can either be a
17940
consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17941
target activity (e.g., target stopped).
17942
 
17943
The following is a preliminary list of possible out-of-band records.
17944
In particular, the @var{exec-async-output} records.
17945
 
17946
@table @code
17947
@item *stopped,reason="@var{reason}"
17948
@end table
17949
 
17950
@var{reason} can be one of the following:
17951
 
17952
@table @code
17953
@item breakpoint-hit
17954
A breakpoint was reached.
17955
@item watchpoint-trigger
17956
A watchpoint was triggered.
17957
@item read-watchpoint-trigger
17958
A read watchpoint was triggered.
17959
@item access-watchpoint-trigger
17960
An access watchpoint was triggered.
17961
@item function-finished
17962
An -exec-finish or similar CLI command was accomplished.
17963
@item location-reached
17964
An -exec-until or similar CLI command was accomplished.
17965
@item watchpoint-scope
17966
A watchpoint has gone out of scope.
17967
@item end-stepping-range
17968
An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17969
similar CLI command was accomplished.
17970
@item exited-signalled
17971
The inferior exited because of a signal.
17972
@item exited
17973
The inferior exited.
17974
@item exited-normally
17975
The inferior exited normally.
17976
@item signal-received
17977
A signal was received by the inferior.
17978
@end table
17979
 
17980
 
17981
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17982
@node GDB/MI Simple Examples
17983
@section Simple Examples of @sc{gdb/mi} Interaction
17984
@cindex @sc{gdb/mi}, simple examples
17985
 
17986
This subsection presents several simple examples of interaction using
17987
the @sc{gdb/mi} interface.  In these examples, @samp{->} means that the
17988
following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
17989
the output received from @sc{gdb/mi}.
17990
 
17991
Note the line breaks shown in the examples are here only for
17992
readability, they don't appear in the real output.
17993
 
17994
@subheading Setting a Breakpoint
17995
 
17996
Setting a breakpoint generates synchronous output which contains detailed
17997
information of the breakpoint.
17998
 
17999
@smallexample
18000
-> -break-insert main
18001
<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
18002
    enabled="y",addr="0x08048564",func="main",file="myprog.c",
18003
    fullname="/home/nickrob/myprog.c",line="68",times="0"@}
18004
<- (gdb)
18005
@end smallexample
18006
 
18007
@subheading Program Execution
18008
 
18009
Program execution generates asynchronous records and MI gives the
18010
reason that execution stopped.
18011
 
18012
@smallexample
18013
-> -exec-run
18014
<- ^running
18015
<- (gdb)
18016
<- *stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",
18017
   frame=@{addr="0x08048564",func="main",
18018
   args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
18019
   file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
18020
<- (gdb)
18021
-> -exec-continue
18022
<- ^running
18023
<- (gdb)
18024
<- *stopped,reason="exited-normally"
18025
<- (gdb)
18026
@end smallexample
18027
 
18028
@subheading Quitting @value{GDBN}
18029
 
18030
Quitting @value{GDBN} just prints the result class @samp{^exit}.
18031
 
18032
@smallexample
18033
-> (gdb)
18034
<- -gdb-exit
18035
<- ^exit
18036
@end smallexample
18037
 
18038
@subheading A Bad Command
18039
 
18040
Here's what happens if you pass a non-existent command:
18041
 
18042
@smallexample
18043
-> -rubbish
18044
<- ^error,msg="Undefined MI command: rubbish"
18045
<- (gdb)
18046
@end smallexample
18047
 
18048
 
18049
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18050
@node GDB/MI Command Description Format
18051
@section @sc{gdb/mi} Command Description Format
18052
 
18053
The remaining sections describe blocks of commands.  Each block of
18054
commands is laid out in a fashion similar to this section.
18055
 
18056
@subheading Motivation
18057
 
18058
The motivation for this collection of commands.
18059
 
18060
@subheading Introduction
18061
 
18062
A brief introduction to this collection of commands as a whole.
18063
 
18064
@subheading Commands
18065
 
18066
For each command in the block, the following is described:
18067
 
18068
@subsubheading Synopsis
18069
 
18070
@smallexample
18071
 -command @var{args}@dots{}
18072
@end smallexample
18073
 
18074
@subsubheading Result
18075
 
18076
@subsubheading @value{GDBN} Command
18077
 
18078
The corresponding @value{GDBN} CLI command(s), if any.
18079
 
18080
@subsubheading Example
18081
 
18082
Example(s) formatted for readability.  Some of the described commands  have
18083
not been implemented yet and these are labeled N.A.@: (not available).
18084
 
18085
 
18086
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18087
@node GDB/MI Breakpoint Commands
18088
@section @sc{gdb/mi} Breakpoint Commands
18089
 
18090
@cindex breakpoint commands for @sc{gdb/mi}
18091
@cindex @sc{gdb/mi}, breakpoint commands
18092
This section documents @sc{gdb/mi} commands for manipulating
18093
breakpoints.
18094
 
18095
@subheading The @code{-break-after} Command
18096
@findex -break-after
18097
 
18098
@subsubheading Synopsis
18099
 
18100
@smallexample
18101
 -break-after @var{number} @var{count}
18102
@end smallexample
18103
 
18104
The breakpoint number @var{number} is not in effect until it has been
18105
hit @var{count} times.  To see how this is reflected in the output of
18106
the @samp{-break-list} command, see the description of the
18107
@samp{-break-list} command below.
18108
 
18109
@subsubheading @value{GDBN} Command
18110
 
18111
The corresponding @value{GDBN} command is @samp{ignore}.
18112
 
18113
@subsubheading Example
18114
 
18115
@smallexample
18116
(gdb)
18117
-break-insert main
18118
^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",
18119
fullname="/home/foo/hello.c",line="5",times="0"@}
18120
(gdb)
18121
-break-after 1 3
18122
~
18123
^done
18124
(gdb)
18125
-break-list
18126
^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18127
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18128
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18129
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18130
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18131
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18132
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18133
body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18134
addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18135
line="5",times="0",ignore="3"@}]@}
18136
(gdb)
18137
@end smallexample
18138
 
18139
@ignore
18140
@subheading The @code{-break-catch} Command
18141
@findex -break-catch
18142
 
18143
@subheading The @code{-break-commands} Command
18144
@findex -break-commands
18145
@end ignore
18146
 
18147
 
18148
@subheading The @code{-break-condition} Command
18149
@findex -break-condition
18150
 
18151
@subsubheading Synopsis
18152
 
18153
@smallexample
18154
 -break-condition @var{number} @var{expr}
18155
@end smallexample
18156
 
18157
Breakpoint @var{number} will stop the program only if the condition in
18158
@var{expr} is true.  The condition becomes part of the
18159
@samp{-break-list} output (see the description of the @samp{-break-list}
18160
command below).
18161
 
18162
@subsubheading @value{GDBN} Command
18163
 
18164
The corresponding @value{GDBN} command is @samp{condition}.
18165
 
18166
@subsubheading Example
18167
 
18168
@smallexample
18169
(gdb)
18170
-break-condition 1 1
18171
^done
18172
(gdb)
18173
-break-list
18174
^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18175
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18176
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18177
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18178
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18179
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18180
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18181
body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18182
addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18183
line="5",cond="1",times="0",ignore="3"@}]@}
18184
(gdb)
18185
@end smallexample
18186
 
18187
@subheading The @code{-break-delete} Command
18188
@findex -break-delete
18189
 
18190
@subsubheading Synopsis
18191
 
18192
@smallexample
18193
 -break-delete ( @var{breakpoint} )+
18194
@end smallexample
18195
 
18196
Delete the breakpoint(s) whose number(s) are specified in the argument
18197
list.  This is obviously reflected in the breakpoint list.
18198
 
18199
@subsubheading @value{GDBN} Command
18200
 
18201
The corresponding @value{GDBN} command is @samp{delete}.
18202
 
18203
@subsubheading Example
18204
 
18205
@smallexample
18206
(gdb)
18207
-break-delete 1
18208
^done
18209
(gdb)
18210
-break-list
18211
^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18212
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18213
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18214
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18215
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18216
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18217
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18218
body=[]@}
18219
(gdb)
18220
@end smallexample
18221
 
18222
@subheading The @code{-break-disable} Command
18223
@findex -break-disable
18224
 
18225
@subsubheading Synopsis
18226
 
18227
@smallexample
18228
 -break-disable ( @var{breakpoint} )+
18229
@end smallexample
18230
 
18231
Disable the named @var{breakpoint}(s).  The field @samp{enabled} in the
18232
break list is now set to @samp{n} for the named @var{breakpoint}(s).
18233
 
18234
@subsubheading @value{GDBN} Command
18235
 
18236
The corresponding @value{GDBN} command is @samp{disable}.
18237
 
18238
@subsubheading Example
18239
 
18240
@smallexample
18241
(gdb)
18242
-break-disable 2
18243
^done
18244
(gdb)
18245
-break-list
18246
^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18247
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18248
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18249
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18250
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18251
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18252
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18253
body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
18254
addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18255
line="5",times="0"@}]@}
18256
(gdb)
18257
@end smallexample
18258
 
18259
@subheading The @code{-break-enable} Command
18260
@findex -break-enable
18261
 
18262
@subsubheading Synopsis
18263
 
18264
@smallexample
18265
 -break-enable ( @var{breakpoint} )+
18266
@end smallexample
18267
 
18268
Enable (previously disabled) @var{breakpoint}(s).
18269
 
18270
@subsubheading @value{GDBN} Command
18271
 
18272
The corresponding @value{GDBN} command is @samp{enable}.
18273
 
18274
@subsubheading Example
18275
 
18276
@smallexample
18277
(gdb)
18278
-break-enable 2
18279
^done
18280
(gdb)
18281
-break-list
18282
^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18283
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18284
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18285
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18286
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18287
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18288
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18289
body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
18290
addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18291
line="5",times="0"@}]@}
18292
(gdb)
18293
@end smallexample
18294
 
18295
@subheading The @code{-break-info} Command
18296
@findex -break-info
18297
 
18298
@subsubheading Synopsis
18299
 
18300
@smallexample
18301
 -break-info @var{breakpoint}
18302
@end smallexample
18303
 
18304
@c REDUNDANT???
18305
Get information about a single breakpoint.
18306
 
18307
@subsubheading @value{GDBN} Command
18308
 
18309
The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
18310
 
18311
@subsubheading Example
18312
N.A.
18313
 
18314
@subheading The @code{-break-insert} Command
18315
@findex -break-insert
18316
 
18317
@subsubheading Synopsis
18318
 
18319
@smallexample
18320
 -break-insert [ -t ] [ -h ] [ -f ]
18321
    [ -c @var{condition} ] [ -i @var{ignore-count} ]
18322
    [ -p @var{thread} ] [ @var{location} ]
18323
@end smallexample
18324
 
18325
@noindent
18326
If specified, @var{location}, can be one of:
18327
 
18328
@itemize @bullet
18329
@item function
18330
@c @item +offset
18331
@c @item -offset
18332
@c @item linenum
18333
@item filename:linenum
18334
@item filename:function
18335
@item *address
18336
@end itemize
18337
 
18338
The possible optional parameters of this command are:
18339
 
18340
@table @samp
18341
@item -t
18342
Insert a temporary breakpoint.
18343
@item -h
18344
Insert a hardware breakpoint.
18345
@item -c @var{condition}
18346
Make the breakpoint conditional on @var{condition}.
18347
@item -i @var{ignore-count}
18348
Initialize the @var{ignore-count}.
18349
@item -f
18350
If @var{location} cannot be parsed (for example if it
18351
refers to unknown files or functions), create a pending
18352
breakpoint. Without this flag, @value{GDBN} will report
18353
an error, and won't create a breakpoint, if @var{location}
18354
cannot be parsed.
18355
@end table
18356
 
18357
@subsubheading Result
18358
 
18359
The result is in the form:
18360
 
18361
@smallexample
18362
^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
18363
enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
18364
fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
18365
times="@var{times}"@}
18366
@end smallexample
18367
 
18368
@noindent
18369
where @var{number} is the @value{GDBN} number for this breakpoint,
18370
@var{funcname} is the name of the function where the breakpoint was
18371
inserted, @var{filename} is the name of the source file which contains
18372
this function, @var{lineno} is the source line number within that file
18373
and @var{times} the number of times that the breakpoint has been hit
18374
(always 0 for -break-insert but may be greater for -break-info or -break-list
18375
which use the same output).
18376
 
18377
Note: this format is open to change.
18378
@c An out-of-band breakpoint instead of part of the result?
18379
 
18380
@subsubheading @value{GDBN} Command
18381
 
18382
The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
18383
@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
18384
 
18385
@subsubheading Example
18386
 
18387
@smallexample
18388
(gdb)
18389
-break-insert main
18390
^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
18391
fullname="/home/foo/recursive2.c,line="4",times="0"@}
18392
(gdb)
18393
-break-insert -t foo
18394
^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
18395
fullname="/home/foo/recursive2.c,line="11",times="0"@}
18396
(gdb)
18397
-break-list
18398
^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18399
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18400
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18401
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18402
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18403
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18404
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18405
body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18406
addr="0x0001072c", func="main",file="recursive2.c",
18407
fullname="/home/foo/recursive2.c,"line="4",times="0"@},
18408
bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
18409
addr="0x00010774",func="foo",file="recursive2.c",
18410
fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
18411
(gdb)
18412
-break-insert -r foo.*
18413
~int foo(int, int);
18414
^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
18415
"fullname="/home/foo/recursive2.c",line="11",times="0"@}
18416
(gdb)
18417
@end smallexample
18418
 
18419
@subheading The @code{-break-list} Command
18420
@findex -break-list
18421
 
18422
@subsubheading Synopsis
18423
 
18424
@smallexample
18425
 -break-list
18426
@end smallexample
18427
 
18428
Displays the list of inserted breakpoints, showing the following fields:
18429
 
18430
@table @samp
18431
@item Number
18432
number of the breakpoint
18433
@item Type
18434
type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
18435
@item Disposition
18436
should the breakpoint be deleted or disabled when it is hit: @samp{keep}
18437
or @samp{nokeep}
18438
@item Enabled
18439
is the breakpoint enabled or no: @samp{y} or @samp{n}
18440
@item Address
18441
memory location at which the breakpoint is set
18442
@item What
18443
logical location of the breakpoint, expressed by function name, file
18444
name, line number
18445
@item Times
18446
number of times the breakpoint has been hit
18447
@end table
18448
 
18449
If there are no breakpoints or watchpoints, the @code{BreakpointTable}
18450
@code{body} field is an empty list.
18451
 
18452
@subsubheading @value{GDBN} Command
18453
 
18454
The corresponding @value{GDBN} command is @samp{info break}.
18455
 
18456
@subsubheading Example
18457
 
18458
@smallexample
18459
(gdb)
18460
-break-list
18461
^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18462
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18463
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18464
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18465
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18466
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18467
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18468
body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18469
addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
18470
bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
18471
addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
18472
line="13",times="0"@}]@}
18473
(gdb)
18474
@end smallexample
18475
 
18476
Here's an example of the result when there are no breakpoints:
18477
 
18478
@smallexample
18479
(gdb)
18480
-break-list
18481
^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18482
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18483
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18484
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18485
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18486
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18487
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18488
body=[]@}
18489
(gdb)
18490
@end smallexample
18491
 
18492
@subheading The @code{-break-watch} Command
18493
@findex -break-watch
18494
 
18495
@subsubheading Synopsis
18496
 
18497
@smallexample
18498
 -break-watch [ -a | -r ]
18499
@end smallexample
18500
 
18501
Create a watchpoint.  With the @samp{-a} option it will create an
18502
@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
18503
read from or on a write to the memory location.  With the @samp{-r}
18504
option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
18505
trigger only when the memory location is accessed for reading.  Without
18506
either of the options, the watchpoint created is a regular watchpoint,
18507
i.e., it will trigger when the memory location is accessed for writing.
18508
@xref{Set Watchpoints, , Setting Watchpoints}.
18509
 
18510
Note that @samp{-break-list} will report a single list of watchpoints and
18511
breakpoints inserted.
18512
 
18513
@subsubheading @value{GDBN} Command
18514
 
18515
The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
18516
@samp{rwatch}.
18517
 
18518
@subsubheading Example
18519
 
18520
Setting a watchpoint on a variable in the @code{main} function:
18521
 
18522
@smallexample
18523
(gdb)
18524
-break-watch x
18525
^done,wpt=@{number="2",exp="x"@}
18526
(gdb)
18527
-exec-continue
18528
^running
18529
(gdb)
18530
*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
18531
value=@{old="-268439212",new="55"@},
18532
frame=@{func="main",args=[],file="recursive2.c",
18533
fullname="/home/foo/bar/recursive2.c",line="5"@}
18534
(gdb)
18535
@end smallexample
18536
 
18537
Setting a watchpoint on a variable local to a function.  @value{GDBN} will stop
18538
the program execution twice: first for the variable changing value, then
18539
for the watchpoint going out of scope.
18540
 
18541
@smallexample
18542
(gdb)
18543
-break-watch C
18544
^done,wpt=@{number="5",exp="C"@}
18545
(gdb)
18546
-exec-continue
18547
^running
18548
(gdb)
18549
*stopped,reason="watchpoint-trigger",
18550
wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
18551
frame=@{func="callee4",args=[],
18552
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18553
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
18554
(gdb)
18555
-exec-continue
18556
^running
18557
(gdb)
18558
*stopped,reason="watchpoint-scope",wpnum="5",
18559
frame=@{func="callee3",args=[@{name="strarg",
18560
value="0x11940 \"A string argument.\""@}],
18561
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18562
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
18563
(gdb)
18564
@end smallexample
18565
 
18566
Listing breakpoints and watchpoints, at different points in the program
18567
execution.  Note that once the watchpoint goes out of scope, it is
18568
deleted.
18569
 
18570
@smallexample
18571
(gdb)
18572
-break-watch C
18573
^done,wpt=@{number="2",exp="C"@}
18574
(gdb)
18575
-break-list
18576
^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18577
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18578
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18579
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18580
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18581
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18582
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18583
body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18584
addr="0x00010734",func="callee4",
18585
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18586
fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
18587
bkpt=@{number="2",type="watchpoint",disp="keep",
18588
enabled="y",addr="",what="C",times="0"@}]@}
18589
(gdb)
18590
-exec-continue
18591
^running
18592
(gdb)
18593
*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
18594
value=@{old="-276895068",new="3"@},
18595
frame=@{func="callee4",args=[],
18596
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18597
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
18598
(gdb)
18599
-break-list
18600
^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18601
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18602
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18603
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18604
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18605
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18606
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18607
body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18608
addr="0x00010734",func="callee4",
18609
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18610
fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18611
bkpt=@{number="2",type="watchpoint",disp="keep",
18612
enabled="y",addr="",what="C",times="-5"@}]@}
18613
(gdb)
18614
-exec-continue
18615
^running
18616
^done,reason="watchpoint-scope",wpnum="2",
18617
frame=@{func="callee3",args=[@{name="strarg",
18618
value="0x11940 \"A string argument.\""@}],
18619
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18620
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
18621
(gdb)
18622
-break-list
18623
^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18624
hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18625
@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18626
@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18627
@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18628
@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18629
@{width="40",alignment="2",col_name="what",colhdr="What"@}],
18630
body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18631
addr="0x00010734",func="callee4",
18632
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18633
fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
18634
times="1"@}]@}
18635
(gdb)
18636
@end smallexample
18637
 
18638
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18639
@node GDB/MI Program Context
18640
@section @sc{gdb/mi}  Program Context
18641
 
18642
@subheading The @code{-exec-arguments} Command
18643
@findex -exec-arguments
18644
 
18645
 
18646
@subsubheading Synopsis
18647
 
18648
@smallexample
18649
 -exec-arguments @var{args}
18650
@end smallexample
18651
 
18652
Set the inferior program arguments, to be used in the next
18653
@samp{-exec-run}.
18654
 
18655
@subsubheading @value{GDBN} Command
18656
 
18657
The corresponding @value{GDBN} command is @samp{set args}.
18658
 
18659
@subsubheading Example
18660
 
18661
@c FIXME!
18662
Don't have one around.
18663
 
18664
 
18665
@subheading The @code{-exec-show-arguments} Command
18666
@findex -exec-show-arguments
18667
 
18668
@subsubheading Synopsis
18669
 
18670
@smallexample
18671
 -exec-show-arguments
18672
@end smallexample
18673
 
18674
Print the arguments of the program.
18675
 
18676
@subsubheading @value{GDBN} Command
18677
 
18678
The corresponding @value{GDBN} command is @samp{show args}.
18679
 
18680
@subsubheading Example
18681
N.A.
18682
 
18683
 
18684
@subheading The @code{-environment-cd} Command
18685
@findex -environment-cd
18686
 
18687
@subsubheading Synopsis
18688
 
18689
@smallexample
18690
 -environment-cd @var{pathdir}
18691
@end smallexample
18692
 
18693
Set @value{GDBN}'s working directory.
18694
 
18695
@subsubheading @value{GDBN} Command
18696
 
18697
The corresponding @value{GDBN} command is @samp{cd}.
18698
 
18699
@subsubheading Example
18700
 
18701
@smallexample
18702
(gdb)
18703
-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18704
^done
18705
(gdb)
18706
@end smallexample
18707
 
18708
 
18709
@subheading The @code{-environment-directory} Command
18710
@findex -environment-directory
18711
 
18712
@subsubheading Synopsis
18713
 
18714
@smallexample
18715
 -environment-directory [ -r ] [ @var{pathdir} ]+
18716
@end smallexample
18717
 
18718
Add directories @var{pathdir} to beginning of search path for source files.
18719
If the @samp{-r} option is used, the search path is reset to the default
18720
search path.  If directories @var{pathdir} are supplied in addition to the
18721
@samp{-r} option, the search path is first reset and then addition
18722
occurs as normal.
18723
Multiple directories may be specified, separated by blanks.  Specifying
18724
multiple directories in a single command
18725
results in the directories added to the beginning of the
18726
search path in the same order they were presented in the command.
18727
If blanks are needed as
18728
part of a directory name, double-quotes should be used around
18729
the name.  In the command output, the path will show up separated
18730
by the system directory-separator character.  The directory-separator
18731
character must not be used
18732
in any directory name.
18733
If no directories are specified, the current search path is displayed.
18734
 
18735
@subsubheading @value{GDBN} Command
18736
 
18737
The corresponding @value{GDBN} command is @samp{dir}.
18738
 
18739
@subsubheading Example
18740
 
18741
@smallexample
18742
(gdb)
18743
-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18744
^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18745
(gdb)
18746
-environment-directory ""
18747
^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18748
(gdb)
18749
-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18750
^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18751
(gdb)
18752
-environment-directory -r
18753
^done,source-path="$cdir:$cwd"
18754
(gdb)
18755
@end smallexample
18756
 
18757
 
18758
@subheading The @code{-environment-path} Command
18759
@findex -environment-path
18760
 
18761
@subsubheading Synopsis
18762
 
18763
@smallexample
18764
 -environment-path [ -r ] [ @var{pathdir} ]+
18765
@end smallexample
18766
 
18767
Add directories @var{pathdir} to beginning of search path for object files.
18768
If the @samp{-r} option is used, the search path is reset to the original
18769
search path that existed at gdb start-up.  If directories @var{pathdir} are
18770
supplied in addition to the
18771
@samp{-r} option, the search path is first reset and then addition
18772
occurs as normal.
18773
Multiple directories may be specified, separated by blanks.  Specifying
18774
multiple directories in a single command
18775
results in the directories added to the beginning of the
18776
search path in the same order they were presented in the command.
18777
If blanks are needed as
18778
part of a directory name, double-quotes should be used around
18779
the name.  In the command output, the path will show up separated
18780
by the system directory-separator character.  The directory-separator
18781
character must not be used
18782
in any directory name.
18783
If no directories are specified, the current path is displayed.
18784
 
18785
 
18786
@subsubheading @value{GDBN} Command
18787
 
18788
The corresponding @value{GDBN} command is @samp{path}.
18789
 
18790
@subsubheading Example
18791
 
18792
@smallexample
18793
(gdb)
18794
-environment-path
18795
^done,path="/usr/bin"
18796
(gdb)
18797
-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18798
^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18799
(gdb)
18800
-environment-path -r /usr/local/bin
18801
^done,path="/usr/local/bin:/usr/bin"
18802
(gdb)
18803
@end smallexample
18804
 
18805
 
18806
@subheading The @code{-environment-pwd} Command
18807
@findex -environment-pwd
18808
 
18809
@subsubheading Synopsis
18810
 
18811
@smallexample
18812
 -environment-pwd
18813
@end smallexample
18814
 
18815
Show the current working directory.
18816
 
18817
@subsubheading @value{GDBN} Command
18818
 
18819
The corresponding @value{GDBN} command is @samp{pwd}.
18820
 
18821
@subsubheading Example
18822
 
18823
@smallexample
18824
(gdb)
18825
-environment-pwd
18826
^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18827
(gdb)
18828
@end smallexample
18829
 
18830
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18831
@node GDB/MI Thread Commands
18832
@section @sc{gdb/mi} Thread Commands
18833
 
18834
 
18835
@subheading The @code{-thread-info} Command
18836
@findex -thread-info
18837
 
18838
@subsubheading Synopsis
18839
 
18840
@smallexample
18841
 -thread-info
18842
@end smallexample
18843
 
18844
@subsubheading @value{GDBN} Command
18845
 
18846
No equivalent.
18847
 
18848
@subsubheading Example
18849
N.A.
18850
 
18851
 
18852
@subheading The @code{-thread-list-all-threads} Command
18853
@findex -thread-list-all-threads
18854
 
18855
@subsubheading Synopsis
18856
 
18857
@smallexample
18858
 -thread-list-all-threads
18859
@end smallexample
18860
 
18861
@subsubheading @value{GDBN} Command
18862
 
18863
The equivalent @value{GDBN} command is @samp{info threads}.
18864
 
18865
@subsubheading Example
18866
N.A.
18867
 
18868
 
18869
@subheading The @code{-thread-list-ids} Command
18870
@findex -thread-list-ids
18871
 
18872
@subsubheading Synopsis
18873
 
18874
@smallexample
18875
 -thread-list-ids
18876
@end smallexample
18877
 
18878
Produces a list of the currently known @value{GDBN} thread ids.  At the
18879
end of the list it also prints the total number of such threads.
18880
 
18881
@subsubheading @value{GDBN} Command
18882
 
18883
Part of @samp{info threads} supplies the same information.
18884
 
18885
@subsubheading Example
18886
 
18887
No threads present, besides the main process:
18888
 
18889
@smallexample
18890
(gdb)
18891
-thread-list-ids
18892
^done,thread-ids=@{@},number-of-threads="0"
18893
(gdb)
18894
@end smallexample
18895
 
18896
 
18897
Several threads:
18898
 
18899
@smallexample
18900
(gdb)
18901
-thread-list-ids
18902
^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18903
number-of-threads="3"
18904
(gdb)
18905
@end smallexample
18906
 
18907
 
18908
@subheading The @code{-thread-select} Command
18909
@findex -thread-select
18910
 
18911
@subsubheading Synopsis
18912
 
18913
@smallexample
18914
 -thread-select @var{threadnum}
18915
@end smallexample
18916
 
18917
Make @var{threadnum} the current thread.  It prints the number of the new
18918
current thread, and the topmost frame for that thread.
18919
 
18920
@subsubheading @value{GDBN} Command
18921
 
18922
The corresponding @value{GDBN} command is @samp{thread}.
18923
 
18924
@subsubheading Example
18925
 
18926
@smallexample
18927
(gdb)
18928
-exec-next
18929
^running
18930
(gdb)
18931
*stopped,reason="end-stepping-range",thread-id="2",line="187",
18932
file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
18933
(gdb)
18934
-thread-list-ids
18935
^done,
18936
thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18937
number-of-threads="3"
18938
(gdb)
18939
-thread-select 3
18940
^done,new-thread-id="3",
18941
frame=@{level="0",func="vprintf",
18942
args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18943
@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
18944
(gdb)
18945
@end smallexample
18946
 
18947
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18948
@node GDB/MI Program Execution
18949
@section @sc{gdb/mi} Program Execution
18950
 
18951
These are the asynchronous commands which generate the out-of-band
18952
record @samp{*stopped}.  Currently @value{GDBN} only really executes
18953
asynchronously with remote targets and this interaction is mimicked in
18954
other cases.
18955
 
18956
@subheading The @code{-exec-continue} Command
18957
@findex -exec-continue
18958
 
18959
@subsubheading Synopsis
18960
 
18961
@smallexample
18962
 -exec-continue
18963
@end smallexample
18964
 
18965
Resumes the execution of the inferior program until a breakpoint is
18966
encountered, or until the inferior exits.
18967
 
18968
@subsubheading @value{GDBN} Command
18969
 
18970
The corresponding @value{GDBN} corresponding is @samp{continue}.
18971
 
18972
@subsubheading Example
18973
 
18974
@smallexample
18975
-exec-continue
18976
^running
18977
(gdb)
18978
@@Hello world
18979
*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
18980
file="hello.c",fullname="/home/foo/bar/hello.c",line="13"@}
18981
(gdb)
18982
@end smallexample
18983
 
18984
 
18985
@subheading The @code{-exec-finish} Command
18986
@findex -exec-finish
18987
 
18988
@subsubheading Synopsis
18989
 
18990
@smallexample
18991
 -exec-finish
18992
@end smallexample
18993
 
18994
Resumes the execution of the inferior program until the current
18995
function is exited.  Displays the results returned by the function.
18996
 
18997
@subsubheading @value{GDBN} Command
18998
 
18999
The corresponding @value{GDBN} command is @samp{finish}.
19000
 
19001
@subsubheading Example
19002
 
19003
Function returning @code{void}.
19004
 
19005
@smallexample
19006
-exec-finish
19007
^running
19008
(gdb)
19009
@@hello from foo
19010
*stopped,reason="function-finished",frame=@{func="main",args=[],
19011
file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
19012
(gdb)
19013
@end smallexample
19014
 
19015
Function returning other than @code{void}.  The name of the internal
19016
@value{GDBN} variable storing the result is printed, together with the
19017
value itself.
19018
 
19019
@smallexample
19020
-exec-finish
19021
^running
19022
(gdb)
19023
*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
19024
args=[@{name="a",value="1"],@{name="b",value="9"@}@},
19025
file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19026
gdb-result-var="$1",return-value="0"
19027
(gdb)
19028
@end smallexample
19029
 
19030
 
19031
@subheading The @code{-exec-interrupt} Command
19032
@findex -exec-interrupt
19033
 
19034
@subsubheading Synopsis
19035
 
19036
@smallexample
19037
 -exec-interrupt
19038
@end smallexample
19039
 
19040
Interrupts the background execution of the target.  Note how the token
19041
associated with the stop message is the one for the execution command
19042
that has been interrupted.  The token for the interrupt itself only
19043
appears in the @samp{^done} output.  If the user is trying to
19044
interrupt a non-running program, an error message will be printed.
19045
 
19046
@subsubheading @value{GDBN} Command
19047
 
19048
The corresponding @value{GDBN} command is @samp{interrupt}.
19049
 
19050
@subsubheading Example
19051
 
19052
@smallexample
19053
(gdb)
19054
111-exec-continue
19055
111^running
19056
 
19057
(gdb)
19058
222-exec-interrupt
19059
222^done
19060
(gdb)
19061
111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
19062
frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
19063
fullname="/home/foo/bar/try.c",line="13"@}
19064
(gdb)
19065
 
19066
(gdb)
19067
-exec-interrupt
19068
^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
19069
(gdb)
19070
@end smallexample
19071
 
19072
 
19073
@subheading The @code{-exec-next} Command
19074
@findex -exec-next
19075
 
19076
@subsubheading Synopsis
19077
 
19078
@smallexample
19079
 -exec-next
19080
@end smallexample
19081
 
19082
Resumes execution of the inferior program, stopping when the beginning
19083
of the next source line is reached.
19084
 
19085
@subsubheading @value{GDBN} Command
19086
 
19087
The corresponding @value{GDBN} command is @samp{next}.
19088
 
19089
@subsubheading Example
19090
 
19091
@smallexample
19092
-exec-next
19093
^running
19094
(gdb)
19095
*stopped,reason="end-stepping-range",line="8",file="hello.c"
19096
(gdb)
19097
@end smallexample
19098
 
19099
 
19100
@subheading The @code{-exec-next-instruction} Command
19101
@findex -exec-next-instruction
19102
 
19103
@subsubheading Synopsis
19104
 
19105
@smallexample
19106
 -exec-next-instruction
19107
@end smallexample
19108
 
19109
Executes one machine instruction.  If the instruction is a function
19110
call, continues until the function returns.  If the program stops at an
19111
instruction in the middle of a source line, the address will be
19112
printed as well.
19113
 
19114
@subsubheading @value{GDBN} Command
19115
 
19116
The corresponding @value{GDBN} command is @samp{nexti}.
19117
 
19118
@subsubheading Example
19119
 
19120
@smallexample
19121
(gdb)
19122
-exec-next-instruction
19123
^running
19124
 
19125
(gdb)
19126
*stopped,reason="end-stepping-range",
19127
addr="0x000100d4",line="5",file="hello.c"
19128
(gdb)
19129
@end smallexample
19130
 
19131
 
19132
@subheading The @code{-exec-return} Command
19133
@findex -exec-return
19134
 
19135
@subsubheading Synopsis
19136
 
19137
@smallexample
19138
 -exec-return
19139
@end smallexample
19140
 
19141
Makes current function return immediately.  Doesn't execute the inferior.
19142
Displays the new current frame.
19143
 
19144
@subsubheading @value{GDBN} Command
19145
 
19146
The corresponding @value{GDBN} command is @samp{return}.
19147
 
19148
@subsubheading Example
19149
 
19150
@smallexample
19151
(gdb)
19152
200-break-insert callee4
19153
200^done,bkpt=@{number="1",addr="0x00010734",
19154
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19155
(gdb)
19156
000-exec-run
19157
000^running
19158
(gdb)
19159
000*stopped,reason="breakpoint-hit",bkptno="1",
19160
frame=@{func="callee4",args=[],
19161
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19162
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19163
(gdb)
19164
205-break-delete
19165
205^done
19166
(gdb)
19167
111-exec-return
19168
111^done,frame=@{level="0",func="callee3",
19169
args=[@{name="strarg",
19170
value="0x11940 \"A string argument.\""@}],
19171
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19172
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
19173
(gdb)
19174
@end smallexample
19175
 
19176
 
19177
@subheading The @code{-exec-run} Command
19178
@findex -exec-run
19179
 
19180
@subsubheading Synopsis
19181
 
19182
@smallexample
19183
 -exec-run
19184
@end smallexample
19185
 
19186
Starts execution of the inferior from the beginning.  The inferior
19187
executes until either a breakpoint is encountered or the program
19188
exits.  In the latter case the output will include an exit code, if
19189
the program has exited exceptionally.
19190
 
19191
@subsubheading @value{GDBN} Command
19192
 
19193
The corresponding @value{GDBN} command is @samp{run}.
19194
 
19195
@subsubheading Examples
19196
 
19197
@smallexample
19198
(gdb)
19199
-break-insert main
19200
^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
19201
(gdb)
19202
-exec-run
19203
^running
19204
(gdb)
19205
*stopped,reason="breakpoint-hit",bkptno="1",
19206
frame=@{func="main",args=[],file="recursive2.c",
19207
fullname="/home/foo/bar/recursive2.c",line="4"@}
19208
(gdb)
19209
@end smallexample
19210
 
19211
@noindent
19212
Program exited normally:
19213
 
19214
@smallexample
19215
(gdb)
19216
-exec-run
19217
^running
19218
(gdb)
19219
x = 55
19220
*stopped,reason="exited-normally"
19221
(gdb)
19222
@end smallexample
19223
 
19224
@noindent
19225
Program exited exceptionally:
19226
 
19227
@smallexample
19228
(gdb)
19229
-exec-run
19230
^running
19231
(gdb)
19232
x = 55
19233
*stopped,reason="exited",exit-code="01"
19234
(gdb)
19235
@end smallexample
19236
 
19237
Another way the program can terminate is if it receives a signal such as
19238
@code{SIGINT}.  In this case, @sc{gdb/mi} displays this:
19239
 
19240
@smallexample
19241
(gdb)
19242
*stopped,reason="exited-signalled",signal-name="SIGINT",
19243
signal-meaning="Interrupt"
19244
@end smallexample
19245
 
19246
 
19247
@c @subheading -exec-signal
19248
 
19249
 
19250
@subheading The @code{-exec-step} Command
19251
@findex -exec-step
19252
 
19253
@subsubheading Synopsis
19254
 
19255
@smallexample
19256
 -exec-step
19257
@end smallexample
19258
 
19259
Resumes execution of the inferior program, stopping when the beginning
19260
of the next source line is reached, if the next source line is not a
19261
function call.  If it is, stop at the first instruction of the called
19262
function.
19263
 
19264
@subsubheading @value{GDBN} Command
19265
 
19266
The corresponding @value{GDBN} command is @samp{step}.
19267
 
19268
@subsubheading Example
19269
 
19270
Stepping into a function:
19271
 
19272
@smallexample
19273
-exec-step
19274
^running
19275
(gdb)
19276
*stopped,reason="end-stepping-range",
19277
frame=@{func="foo",args=[@{name="a",value="10"@},
19278
@{name="b",value="0"@}],file="recursive2.c",
19279
fullname="/home/foo/bar/recursive2.c",line="11"@}
19280
(gdb)
19281
@end smallexample
19282
 
19283
Regular stepping:
19284
 
19285
@smallexample
19286
-exec-step
19287
^running
19288
(gdb)
19289
*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
19290
(gdb)
19291
@end smallexample
19292
 
19293
 
19294
@subheading The @code{-exec-step-instruction} Command
19295
@findex -exec-step-instruction
19296
 
19297
@subsubheading Synopsis
19298
 
19299
@smallexample
19300
 -exec-step-instruction
19301
@end smallexample
19302
 
19303
Resumes the inferior which executes one machine instruction.  The
19304
output, once @value{GDBN} has stopped, will vary depending on whether
19305
we have stopped in the middle of a source line or not.  In the former
19306
case, the address at which the program stopped will be printed as
19307
well.
19308
 
19309
@subsubheading @value{GDBN} Command
19310
 
19311
The corresponding @value{GDBN} command is @samp{stepi}.
19312
 
19313
@subsubheading Example
19314
 
19315
@smallexample
19316
(gdb)
19317
-exec-step-instruction
19318
^running
19319
 
19320
(gdb)
19321
*stopped,reason="end-stepping-range",
19322
frame=@{func="foo",args=[],file="try.c",
19323
fullname="/home/foo/bar/try.c",line="10"@}
19324
(gdb)
19325
-exec-step-instruction
19326
^running
19327
 
19328
(gdb)
19329
*stopped,reason="end-stepping-range",
19330
frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
19331
fullname="/home/foo/bar/try.c",line="10"@}
19332
(gdb)
19333
@end smallexample
19334
 
19335
 
19336
@subheading The @code{-exec-until} Command
19337
@findex -exec-until
19338
 
19339
@subsubheading Synopsis
19340
 
19341
@smallexample
19342
 -exec-until [ @var{location} ]
19343
@end smallexample
19344
 
19345
Executes the inferior until the @var{location} specified in the
19346
argument is reached.  If there is no argument, the inferior executes
19347
until a source line greater than the current one is reached.  The
19348
reason for stopping in this case will be @samp{location-reached}.
19349
 
19350
@subsubheading @value{GDBN} Command
19351
 
19352
The corresponding @value{GDBN} command is @samp{until}.
19353
 
19354
@subsubheading Example
19355
 
19356
@smallexample
19357
(gdb)
19358
-exec-until recursive2.c:6
19359
^running
19360
(gdb)
19361
x = 55
19362
*stopped,reason="location-reached",frame=@{func="main",args=[],
19363
file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
19364
(gdb)
19365
@end smallexample
19366
 
19367
@ignore
19368
@subheading -file-clear
19369
Is this going away????
19370
@end ignore
19371
 
19372
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19373
@node GDB/MI Stack Manipulation
19374
@section @sc{gdb/mi} Stack Manipulation Commands
19375
 
19376
 
19377
@subheading The @code{-stack-info-frame} Command
19378
@findex -stack-info-frame
19379
 
19380
@subsubheading Synopsis
19381
 
19382
@smallexample
19383
 -stack-info-frame
19384
@end smallexample
19385
 
19386
Get info on the selected frame.
19387
 
19388
@subsubheading @value{GDBN} Command
19389
 
19390
The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19391
(without arguments).
19392
 
19393
@subsubheading Example
19394
 
19395
@smallexample
19396
(gdb)
19397
-stack-info-frame
19398
^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19399
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19400
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19401
(gdb)
19402
@end smallexample
19403
 
19404
@subheading The @code{-stack-info-depth} Command
19405
@findex -stack-info-depth
19406
 
19407
@subsubheading Synopsis
19408
 
19409
@smallexample
19410
 -stack-info-depth [ @var{max-depth} ]
19411
@end smallexample
19412
 
19413
Return the depth of the stack.  If the integer argument @var{max-depth}
19414
is specified, do not count beyond @var{max-depth} frames.
19415
 
19416
@subsubheading @value{GDBN} Command
19417
 
19418
There's no equivalent @value{GDBN} command.
19419
 
19420
@subsubheading Example
19421
 
19422
For a stack with frame levels 0 through 11:
19423
 
19424
@smallexample
19425
(gdb)
19426
-stack-info-depth
19427
^done,depth="12"
19428
(gdb)
19429
-stack-info-depth 4
19430
^done,depth="4"
19431
(gdb)
19432
-stack-info-depth 12
19433
^done,depth="12"
19434
(gdb)
19435
-stack-info-depth 11
19436
^done,depth="11"
19437
(gdb)
19438
-stack-info-depth 13
19439
^done,depth="12"
19440
(gdb)
19441
@end smallexample
19442
 
19443
@subheading The @code{-stack-list-arguments} Command
19444
@findex -stack-list-arguments
19445
 
19446
@subsubheading Synopsis
19447
 
19448
@smallexample
19449
 -stack-list-arguments @var{show-values}
19450
    [ @var{low-frame} @var{high-frame} ]
19451
@end smallexample
19452
 
19453
Display a list of the arguments for the frames between @var{low-frame}
19454
and @var{high-frame} (inclusive).  If @var{low-frame} and
19455
@var{high-frame} are not provided, list the arguments for the whole
19456
call stack.  If the two arguments are equal, show the single frame
19457
at the corresponding level.  It is an error if @var{low-frame} is
19458
larger than the actual number of frames.  On the other hand,
19459
@var{high-frame} may be larger than the actual number of frames, in
19460
which case only existing frames will be returned.
19461
 
19462
The @var{show-values} argument must have a value of 0 or 1.  A value of
19463
 
19464
means that both names and values of the arguments are printed.
19465
 
19466
@subsubheading @value{GDBN} Command
19467
 
19468
@value{GDBN} does not have an equivalent command.  @code{gdbtk} has a
19469
@samp{gdb_get_args} command which partially overlaps with the
19470
functionality of @samp{-stack-list-arguments}.
19471
 
19472
@subsubheading Example
19473
 
19474
@smallexample
19475
(gdb)
19476
-stack-list-frames
19477
^done,
19478
stack=[
19479
frame=@{level="0",addr="0x00010734",func="callee4",
19480
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19481
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
19482
frame=@{level="1",addr="0x0001076c",func="callee3",
19483
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19484
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
19485
frame=@{level="2",addr="0x0001078c",func="callee2",
19486
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19487
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
19488
frame=@{level="3",addr="0x000107b4",func="callee1",
19489
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19490
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
19491
frame=@{level="4",addr="0x000107e0",func="main",
19492
file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19493
fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
19494
(gdb)
19495
-stack-list-arguments 0
19496
^done,
19497
stack-args=[
19498
frame=@{level="0",args=[]@},
19499
frame=@{level="1",args=[name="strarg"]@},
19500
frame=@{level="2",args=[name="intarg",name="strarg"]@},
19501
frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19502
frame=@{level="4",args=[]@}]
19503
(gdb)
19504
-stack-list-arguments 1
19505
^done,
19506
stack-args=[
19507
frame=@{level="0",args=[]@},
19508
frame=@{level="1",
19509
 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19510
frame=@{level="2",args=[
19511
@{name="intarg",value="2"@},
19512
@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19513
@{frame=@{level="3",args=[
19514
@{name="intarg",value="2"@},
19515
@{name="strarg",value="0x11940 \"A string argument.\""@},
19516
@{name="fltarg",value="3.5"@}]@},
19517
frame=@{level="4",args=[]@}]
19518
(gdb)
19519
-stack-list-arguments 0 2 2
19520
^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19521
(gdb)
19522
-stack-list-arguments 1 2 2
19523
^done,stack-args=[frame=@{level="2",
19524
args=[@{name="intarg",value="2"@},
19525
@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19526
(gdb)
19527
@end smallexample
19528
 
19529
@c @subheading -stack-list-exception-handlers
19530
 
19531
 
19532
@subheading The @code{-stack-list-frames} Command
19533
@findex -stack-list-frames
19534
 
19535
@subsubheading Synopsis
19536
 
19537
@smallexample
19538
 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19539
@end smallexample
19540
 
19541
List the frames currently on the stack.  For each frame it displays the
19542
following info:
19543
 
19544
@table @samp
19545
@item @var{level}
19546
The frame number, 0 being the topmost frame, i.e., the innermost function.
19547
@item @var{addr}
19548
The @code{$pc} value for that frame.
19549
@item @var{func}
19550
Function name.
19551
@item @var{file}
19552
File name of the source file where the function lives.
19553
@item @var{line}
19554
Line number corresponding to the @code{$pc}.
19555
@end table
19556
 
19557
If invoked without arguments, this command prints a backtrace for the
19558
whole stack.  If given two integer arguments, it shows the frames whose
19559
levels are between the two arguments (inclusive).  If the two arguments
19560
are equal, it shows the single frame at the corresponding level.  It is
19561
an error if @var{low-frame} is larger than the actual number of
19562
frames.  On the other hand, @var{high-frame} may be larger than the
19563
actual number of frames, in which case only existing frames will be returned.
19564
 
19565
@subsubheading @value{GDBN} Command
19566
 
19567
The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19568
 
19569
@subsubheading Example
19570
 
19571
Full stack backtrace:
19572
 
19573
@smallexample
19574
(gdb)
19575
-stack-list-frames
19576
^done,stack=
19577
[frame=@{level="0",addr="0x0001076c",func="foo",
19578
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
19579
frame=@{level="1",addr="0x000107a4",func="foo",
19580
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19581
frame=@{level="2",addr="0x000107a4",func="foo",
19582
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19583
frame=@{level="3",addr="0x000107a4",func="foo",
19584
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19585
frame=@{level="4",addr="0x000107a4",func="foo",
19586
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19587
frame=@{level="5",addr="0x000107a4",func="foo",
19588
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19589
frame=@{level="6",addr="0x000107a4",func="foo",
19590
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19591
frame=@{level="7",addr="0x000107a4",func="foo",
19592
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19593
frame=@{level="8",addr="0x000107a4",func="foo",
19594
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19595
frame=@{level="9",addr="0x000107a4",func="foo",
19596
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19597
frame=@{level="10",addr="0x000107a4",func="foo",
19598
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19599
frame=@{level="11",addr="0x00010738",func="main",
19600
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
19601
(gdb)
19602
@end smallexample
19603
 
19604
Show frames between @var{low_frame} and @var{high_frame}:
19605
 
19606
@smallexample
19607
(gdb)
19608
-stack-list-frames 3 5
19609
^done,stack=
19610
[frame=@{level="3",addr="0x000107a4",func="foo",
19611
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19612
frame=@{level="4",addr="0x000107a4",func="foo",
19613
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19614
frame=@{level="5",addr="0x000107a4",func="foo",
19615
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
19616
(gdb)
19617
@end smallexample
19618
 
19619
Show a single frame:
19620
 
19621
@smallexample
19622
(gdb)
19623
-stack-list-frames 3 3
19624
^done,stack=
19625
[frame=@{level="3",addr="0x000107a4",func="foo",
19626
  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
19627
(gdb)
19628
@end smallexample
19629
 
19630
 
19631
@subheading The @code{-stack-list-locals} Command
19632
@findex -stack-list-locals
19633
 
19634
@subsubheading Synopsis
19635
 
19636
@smallexample
19637
 -stack-list-locals @var{print-values}
19638
@end smallexample
19639
 
19640
Display the local variable names for the selected frame.  If
19641
@var{print-values} is 0 or @code{--no-values}, print only the names of
19642
the variables; if it is 1 or @code{--all-values}, print also their
19643
values; and if it is 2 or @code{--simple-values}, print the name,
19644
type and value for simple data types and the name and type for arrays,
19645
structures and unions.  In this last case, a frontend can immediately
19646
display the value of simple data types and create variable objects for
19647
other data types when the user wishes to explore their values in
19648
more detail.
19649
 
19650
@subsubheading @value{GDBN} Command
19651
 
19652
@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19653
 
19654
@subsubheading Example
19655
 
19656
@smallexample
19657
(gdb)
19658
-stack-list-locals 0
19659
^done,locals=[name="A",name="B",name="C"]
19660
(gdb)
19661
-stack-list-locals --all-values
19662
^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
19663
  @{name="C",value="@{1, 2, 3@}"@}]
19664
-stack-list-locals --simple-values
19665
^done,locals=[@{name="A",type="int",value="1"@},
19666
  @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
19667
(gdb)
19668
@end smallexample
19669
 
19670
 
19671
@subheading The @code{-stack-select-frame} Command
19672
@findex -stack-select-frame
19673
 
19674
@subsubheading Synopsis
19675
 
19676
@smallexample
19677
 -stack-select-frame @var{framenum}
19678
@end smallexample
19679
 
19680
Change the selected frame.  Select a different frame @var{framenum} on
19681
the stack.
19682
 
19683
@subsubheading @value{GDBN} Command
19684
 
19685
The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19686
@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19687
 
19688
@subsubheading Example
19689
 
19690
@smallexample
19691
(gdb)
19692
-stack-select-frame 2
19693
^done
19694
(gdb)
19695
@end smallexample
19696
 
19697
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19698
@node GDB/MI Variable Objects
19699
@section @sc{gdb/mi} Variable Objects
19700
 
19701
@ignore
19702
 
19703
@subheading Motivation for Variable Objects in @sc{gdb/mi}
19704
 
19705
For the implementation of a variable debugger window (locals, watched
19706
expressions, etc.), we are proposing the adaptation of the existing code
19707
used by @code{Insight}.
19708
 
19709
The two main reasons for that are:
19710
 
19711
@enumerate 1
19712
@item
19713
It has been proven in practice (it is already on its second generation).
19714
 
19715
@item
19716
It will shorten development time (needless to say how important it is
19717
now).
19718
@end enumerate
19719
 
19720
The original interface was designed to be used by Tcl code, so it was
19721
slightly changed so it could be used through @sc{gdb/mi}.  This section
19722
describes the @sc{gdb/mi} operations that will be available and gives some
19723
hints about their use.
19724
 
19725
@emph{Note}: In addition to the set of operations described here, we
19726
expect the @sc{gui} implementation of a variable window to require, at
19727
least, the following operations:
19728
 
19729
@itemize @bullet
19730
@item @code{-gdb-show} @code{output-radix}
19731
@item @code{-stack-list-arguments}
19732
@item @code{-stack-list-locals}
19733
@item @code{-stack-select-frame}
19734
@end itemize
19735
 
19736
@end ignore
19737
 
19738
@subheading Introduction to Variable Objects
19739
 
19740
@cindex variable objects in @sc{gdb/mi}
19741
 
19742
Variable objects are "object-oriented" MI interface for examining and
19743
changing values of expressions.  Unlike some other MI interfaces that
19744
work with expressions, variable objects are specifically designed for
19745
simple and efficient presentation in the frontend.  A variable object
19746
is identified by string name.  When a variable object is created, the
19747
frontend specifies the expression for that variable object.  The
19748
expression can be a simple variable, or it can be an arbitrary complex
19749
expression, and can even involve CPU registers.  After creating a
19750
variable object, the frontend can invoke other variable object
19751
operations---for example to obtain or change the value of a variable
19752
object, or to change display format.
19753
 
19754
Variable objects have hierarchical tree structure.  Any variable object
19755
that corresponds to a composite type, such as structure in C, has
19756
a number of child variable objects, for example corresponding to each
19757
element of a structure.  A child variable object can itself have
19758
children, recursively.  Recursion ends when we reach
19759
leaf variable objects, which always have built-in types.  Child variable
19760
objects are created only by explicit request, so if a frontend
19761
is not interested in the children of a particular variable object, no
19762
child will be created.
19763
 
19764
For a leaf variable object it is possible to obtain its value as a
19765
string, or set the value from a string.  String value can be also
19766
obtained for a non-leaf variable object, but it's generally a string
19767
that only indicates the type of the object, and does not list its
19768
contents.  Assignment to a non-leaf variable object is not allowed.
19769
 
19770
A frontend does not need to read the values of all variable objects each time
19771
the program stops.  Instead, MI provides an update command that lists all
19772
variable objects whose values has changed since the last update
19773
operation.  This considerably reduces the amount of data that must
19774
be transferred to the frontend.  As noted above, children variable
19775
objects are created on demand, and only leaf variable objects have a
19776
real value.  As result, gdb will read target memory only for leaf
19777
variables that frontend has created.
19778
 
19779
The automatic update is not always desirable.  For example, a frontend
19780
might want to keep a value of some expression for future reference,
19781
and never update it.  For another example,  fetching memory is
19782
relatively slow for embedded targets, so a frontend might want
19783
to disable automatic update for the variables that are either not
19784
visible on the screen, or ``closed''.  This is possible using so
19785
called ``frozen variable objects''.  Such variable objects are never
19786
implicitly updated.
19787
 
19788
The following is the complete set of @sc{gdb/mi} operations defined to
19789
access this functionality:
19790
 
19791
@multitable @columnfractions .4 .6
19792
@item @strong{Operation}
19793
@tab @strong{Description}
19794
 
19795
@item @code{-var-create}
19796
@tab create a variable object
19797
@item @code{-var-delete}
19798
@tab delete the variable object and/or its children
19799
@item @code{-var-set-format}
19800
@tab set the display format of this variable
19801
@item @code{-var-show-format}
19802
@tab show the display format of this variable
19803
@item @code{-var-info-num-children}
19804
@tab tells how many children this object has
19805
@item @code{-var-list-children}
19806
@tab return a list of the object's children
19807
@item @code{-var-info-type}
19808
@tab show the type of this variable object
19809
@item @code{-var-info-expression}
19810
@tab print parent-relative expression that this variable object represents
19811
@item @code{-var-info-path-expression}
19812
@tab print full expression that this variable object represents
19813
@item @code{-var-show-attributes}
19814
@tab is this variable editable? does it exist here?
19815
@item @code{-var-evaluate-expression}
19816
@tab get the value of this variable
19817
@item @code{-var-assign}
19818
@tab set the value of this variable
19819
@item @code{-var-update}
19820
@tab update the variable and its children
19821
@item @code{-var-set-frozen}
19822
@tab set frozeness attribute
19823
@end multitable
19824
 
19825
In the next subsection we describe each operation in detail and suggest
19826
how it can be used.
19827
 
19828
@subheading Description And Use of Operations on Variable Objects
19829
 
19830
@subheading The @code{-var-create} Command
19831
@findex -var-create
19832
 
19833
@subsubheading Synopsis
19834
 
19835
@smallexample
19836
 -var-create @{@var{name} | "-"@}
19837
    @{@var{frame-addr} | "*"@} @var{expression}
19838
@end smallexample
19839
 
19840
This operation creates a variable object, which allows the monitoring of
19841
a variable, the result of an expression, a memory cell or a CPU
19842
register.
19843
 
19844
The @var{name} parameter is the string by which the object can be
19845
referenced.  It must be unique.  If @samp{-} is specified, the varobj
19846
system will generate a string ``varNNNNNN'' automatically.  It will be
19847
unique provided that one does not specify @var{name} on that format.
19848
The command fails if a duplicate name is found.
19849
 
19850
The frame under which the expression should be evaluated can be
19851
specified by @var{frame-addr}.  A @samp{*} indicates that the current
19852
frame should be used.
19853
 
19854
@var{expression} is any expression valid on the current language set (must not
19855
begin with a @samp{*}), or one of the following:
19856
 
19857
@itemize @bullet
19858
@item
19859
@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
19860
 
19861
@item
19862
@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
19863
 
19864
@item
19865
@samp{$@var{regname}} --- a CPU register name
19866
@end itemize
19867
 
19868
@subsubheading Result
19869
 
19870
This operation returns the name, number of children and the type of the
19871
object created.  Type is returned as a string as the ones generated by
19872
the @value{GDBN} CLI:
19873
 
19874
@smallexample
19875
 name="@var{name}",numchild="N",type="@var{type}"
19876
@end smallexample
19877
 
19878
 
19879
@subheading The @code{-var-delete} Command
19880
@findex -var-delete
19881
 
19882
@subsubheading Synopsis
19883
 
19884
@smallexample
19885
 -var-delete [ -c ] @var{name}
19886
@end smallexample
19887
 
19888
Deletes a previously created variable object and all of its children.
19889
With the @samp{-c} option, just deletes the children.
19890
 
19891
Returns an error if the object @var{name} is not found.
19892
 
19893
 
19894
@subheading The @code{-var-set-format} Command
19895
@findex -var-set-format
19896
 
19897
@subsubheading Synopsis
19898
 
19899
@smallexample
19900
 -var-set-format @var{name} @var{format-spec}
19901
@end smallexample
19902
 
19903
Sets the output format for the value of the object @var{name} to be
19904
@var{format-spec}.
19905
 
19906
The syntax for the @var{format-spec} is as follows:
19907
 
19908
@smallexample
19909
 @var{format-spec} @expansion{}
19910
 @{binary | decimal | hexadecimal | octal | natural@}
19911
@end smallexample
19912
 
19913
The natural format is the default format choosen automatically
19914
based on the variable type (like decimal for an @code{int}, hex
19915
for pointers, etc.).
19916
 
19917
For a variable with children, the format is set only on the
19918
variable itself, and the children are not affected.
19919
 
19920
@subheading The @code{-var-show-format} Command
19921
@findex -var-show-format
19922
 
19923
@subsubheading Synopsis
19924
 
19925
@smallexample
19926
 -var-show-format @var{name}
19927
@end smallexample
19928
 
19929
Returns the format used to display the value of the object @var{name}.
19930
 
19931
@smallexample
19932
 @var{format} @expansion{}
19933
 @var{format-spec}
19934
@end smallexample
19935
 
19936
 
19937
@subheading The @code{-var-info-num-children} Command
19938
@findex -var-info-num-children
19939
 
19940
@subsubheading Synopsis
19941
 
19942
@smallexample
19943
 -var-info-num-children @var{name}
19944
@end smallexample
19945
 
19946
Returns the number of children of a variable object @var{name}:
19947
 
19948
@smallexample
19949
 numchild=@var{n}
19950
@end smallexample
19951
 
19952
 
19953
@subheading The @code{-var-list-children} Command
19954
@findex -var-list-children
19955
 
19956
@subsubheading Synopsis
19957
 
19958
@smallexample
19959
 -var-list-children [@var{print-values}] @var{name}
19960
@end smallexample
19961
@anchor{-var-list-children}
19962
 
19963
Return a list of the children of the specified variable object and
19964
create variable objects for them, if they do not already exist.  With
19965
a single argument or if @var{print-values} has a value for of 0 or
19966
@code{--no-values}, print only the names of the variables; if
19967
@var{print-values} is 1 or @code{--all-values}, also print their
19968
values; and if it is 2 or @code{--simple-values} print the name and
19969
value for simple data types and just the name for arrays, structures
19970
and unions.
19971
 
19972
@subsubheading Example
19973
 
19974
@smallexample
19975
(gdb)
19976
 -var-list-children n
19977
 ^done,numchild=@var{n},children=[@{name=@var{name},
19978
 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
19979
(gdb)
19980
 -var-list-children --all-values n
19981
 ^done,numchild=@var{n},children=[@{name=@var{name},
19982
 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
19983
@end smallexample
19984
 
19985
 
19986
@subheading The @code{-var-info-type} Command
19987
@findex -var-info-type
19988
 
19989
@subsubheading Synopsis
19990
 
19991
@smallexample
19992
 -var-info-type @var{name}
19993
@end smallexample
19994
 
19995
Returns the type of the specified variable @var{name}.  The type is
19996
returned as a string in the same format as it is output by the
19997
@value{GDBN} CLI:
19998
 
19999
@smallexample
20000
 type=@var{typename}
20001
@end smallexample
20002
 
20003
 
20004
@subheading The @code{-var-info-expression} Command
20005
@findex -var-info-expression
20006
 
20007
@subsubheading Synopsis
20008
 
20009
@smallexample
20010
 -var-info-expression @var{name}
20011
@end smallexample
20012
 
20013
Returns a string that is suitable for presenting this
20014
variable object in user interface.  The string is generally
20015
not valid expression in the current language, and cannot be evaluated.
20016
 
20017
For example, if @code{a} is an array, and variable object
20018
@code{A} was created for @code{a}, then we'll get this output:
20019
 
20020
@smallexample
20021
(gdb) -var-info-expression A.1
20022
^done,lang="C",exp="1"
20023
@end smallexample
20024
 
20025
@noindent
20026
Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
20027
 
20028
Note that the output of the @code{-var-list-children} command also
20029
includes those expressions, so the @code{-var-info-expression} command
20030
is of limited use.
20031
 
20032
@subheading The @code{-var-info-path-expression} Command
20033
@findex -var-info-path-expression
20034
 
20035
@subsubheading Synopsis
20036
 
20037
@smallexample
20038
 -var-info-path-expression @var{name}
20039
@end smallexample
20040
 
20041
Returns an expression that can be evaluated in the current
20042
context and will yield the same value that a variable object has.
20043
Compare this with the @code{-var-info-expression} command, which
20044
result can be used only for UI presentation.  Typical use of
20045
the @code{-var-info-path-expression} command is creating a
20046
watchpoint from a variable object.
20047
 
20048
For example, suppose @code{C} is a C@t{++} class, derived from class
20049
@code{Base}, and that the @code{Base} class has a member called
20050
@code{m_size}.  Assume a variable @code{c} is has the type of
20051
@code{C} and a variable object @code{C} was created for variable
20052
@code{c}.  Then, we'll get this output:
20053
@smallexample
20054
(gdb) -var-info-path-expression C.Base.public.m_size
20055
^done,path_expr=((Base)c).m_size)
20056
@end smallexample
20057
 
20058
@subheading The @code{-var-show-attributes} Command
20059
@findex -var-show-attributes
20060
 
20061
@subsubheading Synopsis
20062
 
20063
@smallexample
20064
 -var-show-attributes @var{name}
20065
@end smallexample
20066
 
20067
List attributes of the specified variable object @var{name}:
20068
 
20069
@smallexample
20070
 status=@var{attr} [ ( ,@var{attr} )* ]
20071
@end smallexample
20072
 
20073
@noindent
20074
where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20075
 
20076
@subheading The @code{-var-evaluate-expression} Command
20077
@findex -var-evaluate-expression
20078
 
20079
@subsubheading Synopsis
20080
 
20081
@smallexample
20082
 -var-evaluate-expression @var{name}
20083
@end smallexample
20084
 
20085
Evaluates the expression that is represented by the specified variable
20086
object and returns its value as a string.  The format of the
20087
string can be changed using the @code{-var-set-format} command.
20088
 
20089
@smallexample
20090
 value=@var{value}
20091
@end smallexample
20092
 
20093
Note that one must invoke @code{-var-list-children} for a variable
20094
before the value of a child variable can be evaluated.
20095
 
20096
@subheading The @code{-var-assign} Command
20097
@findex -var-assign
20098
 
20099
@subsubheading Synopsis
20100
 
20101
@smallexample
20102
 -var-assign @var{name} @var{expression}
20103
@end smallexample
20104
 
20105
Assigns the value of @var{expression} to the variable object specified
20106
by @var{name}.  The object must be @samp{editable}.  If the variable's
20107
value is altered by the assign, the variable will show up in any
20108
subsequent @code{-var-update} list.
20109
 
20110
@subsubheading Example
20111
 
20112
@smallexample
20113
(gdb)
20114
-var-assign var1 3
20115
^done,value="3"
20116
(gdb)
20117
-var-update *
20118
^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20119
(gdb)
20120
@end smallexample
20121
 
20122
@subheading The @code{-var-update} Command
20123
@findex -var-update
20124
 
20125
@subsubheading Synopsis
20126
 
20127
@smallexample
20128
 -var-update [@var{print-values}] @{@var{name} | "*"@}
20129
@end smallexample
20130
 
20131
Reevaluate the expressions corresponding to the variable object
20132
@var{name} and all its direct and indirect children, and return the
20133
list of variable objects whose values have changed; @var{name} must
20134
be a root variable object.  Here, ``changed'' means that the result of
20135
@code{-var-evaluate-expression} before and after the
20136
@code{-var-update} is different.  If @samp{*} is used as the variable
20137
object names, all existing variable objects are updated, except
20138
for frozen ones (@pxref{-var-set-frozen}).  The option
20139
@var{print-values} determines whether both names and values, or just
20140
names are printed.  The possible values of this options are the same
20141
as for @code{-var-list-children} (@pxref{-var-list-children}).  It is
20142
recommended to use the @samp{--all-values} option, to reduce the
20143
number of MI commands needed on each program stop.
20144
 
20145
 
20146
@subsubheading Example
20147
 
20148
@smallexample
20149
(gdb)
20150
-var-assign var1 3
20151
^done,value="3"
20152
(gdb)
20153
-var-update --all-values var1
20154
^done,changelist=[@{name="var1",value="3",in_scope="true",
20155
type_changed="false"@}]
20156
(gdb)
20157
@end smallexample
20158
 
20159
@anchor{-var-update}
20160
The field in_scope may take three values:
20161
 
20162
@table @code
20163
@item "true"
20164
The variable object's current value is valid.
20165
 
20166
@item "false"
20167
The variable object does not currently hold a valid value but it may
20168
hold one in the future if its associated expression comes back into
20169
scope.
20170
 
20171
@item "invalid"
20172
The variable object no longer holds a valid value.
20173
This can occur when the executable file being debugged has changed,
20174
either through recompilation or by using the @value{GDBN} @code{file}
20175
command.  The front end should normally choose to delete these variable
20176
objects.
20177
@end table
20178
 
20179
In the future new values may be added to this list so the front should
20180
be prepared for this possibility.  @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
20181
 
20182
@subheading The @code{-var-set-frozen} Command
20183
@findex -var-set-frozen
20184
@anchor{-var-set-frozen}
20185
 
20186
@subsubheading Synopsis
20187
 
20188
@smallexample
20189
 -var-set-frozen @var{name} @var{flag}
20190
@end smallexample
20191
 
20192
Set the frozenness flag on the variable object @var{name}.  The
20193
@var{flag} parameter should be either @samp{1} to make the variable
20194
frozen or @samp{0} to make it unfrozen.  If a variable object is
20195
frozen, then neither itself, nor any of its children, are
20196
implicitly updated by @code{-var-update} of
20197
a parent variable or by @code{-var-update *}.  Only
20198
@code{-var-update} of the variable itself will update its value and
20199
values of its children.  After a variable object is unfrozen, it is
20200
implicitly updated by all subsequent @code{-var-update} operations.
20201
Unfreezing a variable does not update it, only subsequent
20202
@code{-var-update} does.
20203
 
20204
@subsubheading Example
20205
 
20206
@smallexample
20207
(gdb)
20208
-var-set-frozen V 1
20209
^done
20210
(gdb)
20211
@end smallexample
20212
 
20213
 
20214
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20215
@node GDB/MI Data Manipulation
20216
@section @sc{gdb/mi} Data Manipulation
20217
 
20218
@cindex data manipulation, in @sc{gdb/mi}
20219
@cindex @sc{gdb/mi}, data manipulation
20220
This section describes the @sc{gdb/mi} commands that manipulate data:
20221
examine memory and registers, evaluate expressions, etc.
20222
 
20223
@c REMOVED FROM THE INTERFACE.
20224
@c @subheading -data-assign
20225
@c Change the value of a program variable. Plenty of side effects.
20226
@c @subsubheading GDB Command
20227
@c set variable
20228
@c @subsubheading Example
20229
@c N.A.
20230
 
20231
@subheading The @code{-data-disassemble} Command
20232
@findex -data-disassemble
20233
 
20234
@subsubheading Synopsis
20235
 
20236
@smallexample
20237
 -data-disassemble
20238
    [ -s @var{start-addr} -e @var{end-addr} ]
20239
  | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
20240
  -- @var{mode}
20241
@end smallexample
20242
 
20243
@noindent
20244
Where:
20245
 
20246
@table @samp
20247
@item @var{start-addr}
20248
is the beginning address (or @code{$pc})
20249
@item @var{end-addr}
20250
is the end address
20251
@item @var{filename}
20252
is the name of the file to disassemble
20253
@item @var{linenum}
20254
is the line number to disassemble around
20255
@item @var{lines}
20256
is the number of disassembly lines to be produced.  If it is -1,
20257
the whole function will be disassembled, in case no @var{end-addr} is
20258
specified.  If @var{end-addr} is specified as a non-zero value, and
20259
@var{lines} is lower than the number of disassembly lines between
20260
@var{start-addr} and @var{end-addr}, only @var{lines} lines are
20261
displayed; if @var{lines} is higher than the number of lines between
20262
@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
20263
are displayed.
20264
@item @var{mode}
20265
is either 0 (meaning only disassembly) or 1 (meaning mixed source and
20266
disassembly).
20267
@end table
20268
 
20269
@subsubheading Result
20270
 
20271
The output for each instruction is composed of four fields:
20272
 
20273
@itemize @bullet
20274
@item Address
20275
@item Func-name
20276
@item Offset
20277
@item Instruction
20278
@end itemize
20279
 
20280
Note that whatever included in the instruction field, is not manipulated
20281
directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
20282
 
20283
@subsubheading @value{GDBN} Command
20284
 
20285
There's no direct mapping from this command to the CLI.
20286
 
20287
@subsubheading Example
20288
 
20289
Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
20290
 
20291
@smallexample
20292
(gdb)
20293
-data-disassemble -s $pc -e "$pc + 20" -- 0
20294
^done,
20295
asm_insns=[
20296
@{address="0x000107c0",func-name="main",offset="4",
20297
inst="mov  2, %o0"@},
20298
@{address="0x000107c4",func-name="main",offset="8",
20299
inst="sethi  %hi(0x11800), %o2"@},
20300
@{address="0x000107c8",func-name="main",offset="12",
20301
inst="or  %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
20302
@{address="0x000107cc",func-name="main",offset="16",
20303
inst="sethi  %hi(0x11800), %o2"@},
20304
@{address="0x000107d0",func-name="main",offset="20",
20305
inst="or  %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
20306
(gdb)
20307
@end smallexample
20308
 
20309
Disassemble the whole @code{main} function.  Line 32 is part of
20310
@code{main}.
20311
 
20312
@smallexample
20313
-data-disassemble -f basics.c -l 32 -- 0
20314
^done,asm_insns=[
20315
@{address="0x000107bc",func-name="main",offset="0",
20316
inst="save  %sp, -112, %sp"@},
20317
@{address="0x000107c0",func-name="main",offset="4",
20318
inst="mov   2, %o0"@},
20319
@{address="0x000107c4",func-name="main",offset="8",
20320
inst="sethi %hi(0x11800), %o2"@},
20321
[@dots{}]
20322
@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
20323
@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
20324
(gdb)
20325
@end smallexample
20326
 
20327
Disassemble 3 instructions from the start of @code{main}:
20328
 
20329
@smallexample
20330
(gdb)
20331
-data-disassemble -f basics.c -l 32 -n 3 -- 0
20332
^done,asm_insns=[
20333
@{address="0x000107bc",func-name="main",offset="0",
20334
inst="save  %sp, -112, %sp"@},
20335
@{address="0x000107c0",func-name="main",offset="4",
20336
inst="mov  2, %o0"@},
20337
@{address="0x000107c4",func-name="main",offset="8",
20338
inst="sethi  %hi(0x11800), %o2"@}]
20339
(gdb)
20340
@end smallexample
20341
 
20342
Disassemble 3 instructions from the start of @code{main} in mixed mode:
20343
 
20344
@smallexample
20345
(gdb)
20346
-data-disassemble -f basics.c -l 32 -n 3 -- 1
20347
^done,asm_insns=[
20348
src_and_asm_line=@{line="31",
20349
file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20350
  testsuite/gdb.mi/basics.c",line_asm_insn=[
20351
@{address="0x000107bc",func-name="main",offset="0",
20352
inst="save  %sp, -112, %sp"@}]@},
20353
src_and_asm_line=@{line="32",
20354
file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20355
  testsuite/gdb.mi/basics.c",line_asm_insn=[
20356
@{address="0x000107c0",func-name="main",offset="4",
20357
inst="mov  2, %o0"@},
20358
@{address="0x000107c4",func-name="main",offset="8",
20359
inst="sethi  %hi(0x11800), %o2"@}]@}]
20360
(gdb)
20361
@end smallexample
20362
 
20363
 
20364
@subheading The @code{-data-evaluate-expression} Command
20365
@findex -data-evaluate-expression
20366
 
20367
@subsubheading Synopsis
20368
 
20369
@smallexample
20370
 -data-evaluate-expression @var{expr}
20371
@end smallexample
20372
 
20373
Evaluate @var{expr} as an expression.  The expression could contain an
20374
inferior function call.  The function call will execute synchronously.
20375
If the expression contains spaces, it must be enclosed in double quotes.
20376
 
20377
@subsubheading @value{GDBN} Command
20378
 
20379
The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
20380
@samp{call}.  In @code{gdbtk} only, there's a corresponding
20381
@samp{gdb_eval} command.
20382
 
20383
@subsubheading Example
20384
 
20385
In the following example, the numbers that precede the commands are the
20386
@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
20387
Command Syntax}.  Notice how @sc{gdb/mi} returns the same tokens in its
20388
output.
20389
 
20390
@smallexample
20391
211-data-evaluate-expression A
20392
211^done,value="1"
20393
(gdb)
20394
311-data-evaluate-expression &A
20395
311^done,value="0xefffeb7c"
20396
(gdb)
20397
411-data-evaluate-expression A+3
20398
411^done,value="4"
20399
(gdb)
20400
511-data-evaluate-expression "A + 3"
20401
511^done,value="4"
20402
(gdb)
20403
@end smallexample
20404
 
20405
 
20406
@subheading The @code{-data-list-changed-registers} Command
20407
@findex -data-list-changed-registers
20408
 
20409
@subsubheading Synopsis
20410
 
20411
@smallexample
20412
 -data-list-changed-registers
20413
@end smallexample
20414
 
20415
Display a list of the registers that have changed.
20416
 
20417
@subsubheading @value{GDBN} Command
20418
 
20419
@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
20420
has the corresponding command @samp{gdb_changed_register_list}.
20421
 
20422
@subsubheading Example
20423
 
20424
On a PPC MBX board:
20425
 
20426
@smallexample
20427
(gdb)
20428
-exec-continue
20429
^running
20430
 
20431
(gdb)
20432
*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
20433
args=[],file="try.c",fullname="/home/foo/bar/try.c",line="5"@}
20434
(gdb)
20435
-data-list-changed-registers
20436
^done,changed-registers=["0","1","2","4","5","6","7","8","9",
20437
"10","11","13","14","15","16","17","18","19","20","21","22","23",
20438
"24","25","26","27","28","30","31","64","65","66","67","69"]
20439
(gdb)
20440
@end smallexample
20441
 
20442
 
20443
@subheading The @code{-data-list-register-names} Command
20444
@findex -data-list-register-names
20445
 
20446
@subsubheading Synopsis
20447
 
20448
@smallexample
20449
 -data-list-register-names [ ( @var{regno} )+ ]
20450
@end smallexample
20451
 
20452
Show a list of register names for the current target.  If no arguments
20453
are given, it shows a list of the names of all the registers.  If
20454
integer numbers are given as arguments, it will print a list of the
20455
names of the registers corresponding to the arguments.  To ensure
20456
consistency between a register name and its number, the output list may
20457
include empty register names.
20458
 
20459
@subsubheading @value{GDBN} Command
20460
 
20461
@value{GDBN} does not have a command which corresponds to
20462
@samp{-data-list-register-names}.  In @code{gdbtk} there is a
20463
corresponding command @samp{gdb_regnames}.
20464
 
20465
@subsubheading Example
20466
 
20467
For the PPC MBX board:
20468
@smallexample
20469
(gdb)
20470
-data-list-register-names
20471
^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
20472
"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
20473
"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
20474
"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
20475
"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
20476
"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
20477
"", "pc","ps","cr","lr","ctr","xer"]
20478
(gdb)
20479
-data-list-register-names 1 2 3
20480
^done,register-names=["r1","r2","r3"]
20481
(gdb)
20482
@end smallexample
20483
 
20484
@subheading The @code{-data-list-register-values} Command
20485
@findex -data-list-register-values
20486
 
20487
@subsubheading Synopsis
20488
 
20489
@smallexample
20490
 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
20491
@end smallexample
20492
 
20493
Display the registers' contents.  @var{fmt} is the format according to
20494
which the registers' contents are to be returned, followed by an optional
20495
list of numbers specifying the registers to display.  A missing list of
20496
numbers indicates that the contents of all the registers must be returned.
20497
 
20498
Allowed formats for @var{fmt} are:
20499
 
20500
@table @code
20501
@item x
20502
Hexadecimal
20503
@item o
20504
Octal
20505
@item t
20506
Binary
20507
@item d
20508
Decimal
20509
@item r
20510
Raw
20511
@item N
20512
Natural
20513
@end table
20514
 
20515
@subsubheading @value{GDBN} Command
20516
 
20517
The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
20518
all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
20519
 
20520
@subsubheading Example
20521
 
20522
For a PPC MBX board (note: line breaks are for readability only, they
20523
don't appear in the actual output):
20524
 
20525
@smallexample
20526
(gdb)
20527
-data-list-register-values r 64 65
20528
^done,register-values=[@{number="64",value="0xfe00a300"@},
20529
@{number="65",value="0x00029002"@}]
20530
(gdb)
20531
-data-list-register-values x
20532
^done,register-values=[@{number="0",value="0xfe0043c8"@},
20533
@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
20534
@{number="3",value="0x0"@},@{number="4",value="0xa"@},
20535
@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
20536
@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
20537
@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
20538
@{number="11",value="0x1"@},@{number="12",value="0x0"@},
20539
@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
20540
@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
20541
@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
20542
@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
20543
@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
20544
@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
20545
@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
20546
@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
20547
@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
20548
@{number="31",value="0x0"@},@{number="32",value="0x0"@},
20549
@{number="33",value="0x0"@},@{number="34",value="0x0"@},
20550
@{number="35",value="0x0"@},@{number="36",value="0x0"@},
20551
@{number="37",value="0x0"@},@{number="38",value="0x0"@},
20552
@{number="39",value="0x0"@},@{number="40",value="0x0"@},
20553
@{number="41",value="0x0"@},@{number="42",value="0x0"@},
20554
@{number="43",value="0x0"@},@{number="44",value="0x0"@},
20555
@{number="45",value="0x0"@},@{number="46",value="0x0"@},
20556
@{number="47",value="0x0"@},@{number="48",value="0x0"@},
20557
@{number="49",value="0x0"@},@{number="50",value="0x0"@},
20558
@{number="51",value="0x0"@},@{number="52",value="0x0"@},
20559
@{number="53",value="0x0"@},@{number="54",value="0x0"@},
20560
@{number="55",value="0x0"@},@{number="56",value="0x0"@},
20561
@{number="57",value="0x0"@},@{number="58",value="0x0"@},
20562
@{number="59",value="0x0"@},@{number="60",value="0x0"@},
20563
@{number="61",value="0x0"@},@{number="62",value="0x0"@},
20564
@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
20565
@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
20566
@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
20567
@{number="69",value="0x20002b03"@}]
20568
(gdb)
20569
@end smallexample
20570
 
20571
 
20572
@subheading The @code{-data-read-memory} Command
20573
@findex -data-read-memory
20574
 
20575
@subsubheading Synopsis
20576
 
20577
@smallexample
20578
 -data-read-memory [ -o @var{byte-offset} ]
20579
   @var{address} @var{word-format} @var{word-size}
20580
   @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
20581
@end smallexample
20582
 
20583
@noindent
20584
where:
20585
 
20586
@table @samp
20587
@item @var{address}
20588
An expression specifying the address of the first memory word to be
20589
read.  Complex expressions containing embedded white space should be
20590
quoted using the C convention.
20591
 
20592
@item @var{word-format}
20593
The format to be used to print the memory words.  The notation is the
20594
same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
20595
,Output Formats}).
20596
 
20597
@item @var{word-size}
20598
The size of each memory word in bytes.
20599
 
20600
@item @var{nr-rows}
20601
The number of rows in the output table.
20602
 
20603
@item @var{nr-cols}
20604
The number of columns in the output table.
20605
 
20606
@item @var{aschar}
20607
If present, indicates that each row should include an @sc{ascii} dump.  The
20608
value of @var{aschar} is used as a padding character when a byte is not a
20609
member of the printable @sc{ascii} character set (printable @sc{ascii}
20610
characters are those whose code is between 32 and 126, inclusively).
20611
 
20612
@item @var{byte-offset}
20613
An offset to add to the @var{address} before fetching memory.
20614
@end table
20615
 
20616
This command displays memory contents as a table of @var{nr-rows} by
20617
@var{nr-cols} words, each word being @var{word-size} bytes.  In total,
20618
@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
20619
(returned as @samp{total-bytes}).  Should less than the requested number
20620
of bytes be returned by the target, the missing words are identified
20621
using @samp{N/A}.  The number of bytes read from the target is returned
20622
in @samp{nr-bytes} and the starting address used to read memory in
20623
@samp{addr}.
20624
 
20625
The address of the next/previous row or page is available in
20626
@samp{next-row} and @samp{prev-row}, @samp{next-page} and
20627
@samp{prev-page}.
20628
 
20629
@subsubheading @value{GDBN} Command
20630
 
20631
The corresponding @value{GDBN} command is @samp{x}.  @code{gdbtk} has
20632
@samp{gdb_get_mem} memory read command.
20633
 
20634
@subsubheading Example
20635
 
20636
Read six bytes of memory starting at @code{bytes+6} but then offset by
20637
@code{-6} bytes.  Format as three rows of two columns.  One byte per
20638
word.  Display each word in hex.
20639
 
20640
@smallexample
20641
(gdb)
20642
9-data-read-memory -o -6 -- bytes+6 x 1 3 2
20643
9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
20644
next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
20645
prev-page="0x0000138a",memory=[
20646
@{addr="0x00001390",data=["0x00","0x01"]@},
20647
@{addr="0x00001392",data=["0x02","0x03"]@},
20648
@{addr="0x00001394",data=["0x04","0x05"]@}]
20649
(gdb)
20650
@end smallexample
20651
 
20652
Read two bytes of memory starting at address @code{shorts + 64} and
20653
display as a single word formatted in decimal.
20654
 
20655
@smallexample
20656
(gdb)
20657
5-data-read-memory shorts+64 d 2 1 1
20658
5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
20659
next-row="0x00001512",prev-row="0x0000150e",
20660
next-page="0x00001512",prev-page="0x0000150e",memory=[
20661
@{addr="0x00001510",data=["128"]@}]
20662
(gdb)
20663
@end smallexample
20664
 
20665
Read thirty two bytes of memory starting at @code{bytes+16} and format
20666
as eight rows of four columns.  Include a string encoding with @samp{x}
20667
used as the non-printable character.
20668
 
20669
@smallexample
20670
(gdb)
20671
4-data-read-memory bytes+16 x 1 8 4 x
20672
4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
20673
next-row="0x000013c0",prev-row="0x0000139c",
20674
next-page="0x000013c0",prev-page="0x00001380",memory=[
20675
@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
20676
@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
20677
@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
20678
@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
20679
@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
20680
@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
20681
@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
20682
@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
20683
(gdb)
20684
@end smallexample
20685
 
20686
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20687
@node GDB/MI Tracepoint Commands
20688
@section @sc{gdb/mi} Tracepoint Commands
20689
 
20690
The tracepoint commands are not yet implemented.
20691
 
20692
@c @subheading -trace-actions
20693
 
20694
@c @subheading -trace-delete
20695
 
20696
@c @subheading -trace-disable
20697
 
20698
@c @subheading -trace-dump
20699
 
20700
@c @subheading -trace-enable
20701
 
20702
@c @subheading -trace-exists
20703
 
20704
@c @subheading -trace-find
20705
 
20706
@c @subheading -trace-frame-number
20707
 
20708
@c @subheading -trace-info
20709
 
20710
@c @subheading -trace-insert
20711
 
20712
@c @subheading -trace-list
20713
 
20714
@c @subheading -trace-pass-count
20715
 
20716
@c @subheading -trace-save
20717
 
20718
@c @subheading -trace-start
20719
 
20720
@c @subheading -trace-stop
20721
 
20722
 
20723
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20724
@node GDB/MI Symbol Query
20725
@section @sc{gdb/mi} Symbol Query Commands
20726
 
20727
 
20728
@subheading The @code{-symbol-info-address} Command
20729
@findex -symbol-info-address
20730
 
20731
@subsubheading Synopsis
20732
 
20733
@smallexample
20734
 -symbol-info-address @var{symbol}
20735
@end smallexample
20736
 
20737
Describe where @var{symbol} is stored.
20738
 
20739
@subsubheading @value{GDBN} Command
20740
 
20741
The corresponding @value{GDBN} command is @samp{info address}.
20742
 
20743
@subsubheading Example
20744
N.A.
20745
 
20746
 
20747
@subheading The @code{-symbol-info-file} Command
20748
@findex -symbol-info-file
20749
 
20750
@subsubheading Synopsis
20751
 
20752
@smallexample
20753
 -symbol-info-file
20754
@end smallexample
20755
 
20756
Show the file for the symbol.
20757
 
20758
@subsubheading @value{GDBN} Command
20759
 
20760
There's no equivalent @value{GDBN} command.  @code{gdbtk} has
20761
@samp{gdb_find_file}.
20762
 
20763
@subsubheading Example
20764
N.A.
20765
 
20766
 
20767
@subheading The @code{-symbol-info-function} Command
20768
@findex -symbol-info-function
20769
 
20770
@subsubheading Synopsis
20771
 
20772
@smallexample
20773
 -symbol-info-function
20774
@end smallexample
20775
 
20776
Show which function the symbol lives in.
20777
 
20778
@subsubheading @value{GDBN} Command
20779
 
20780
@samp{gdb_get_function} in @code{gdbtk}.
20781
 
20782
@subsubheading Example
20783
N.A.
20784
 
20785
 
20786
@subheading The @code{-symbol-info-line} Command
20787
@findex -symbol-info-line
20788
 
20789
@subsubheading Synopsis
20790
 
20791
@smallexample
20792
 -symbol-info-line
20793
@end smallexample
20794
 
20795
Show the core addresses of the code for a source line.
20796
 
20797
@subsubheading @value{GDBN} Command
20798
 
20799
The corresponding @value{GDBN} command is @samp{info line}.
20800
@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
20801
 
20802
@subsubheading Example
20803
N.A.
20804
 
20805
 
20806
@subheading The @code{-symbol-info-symbol} Command
20807
@findex -symbol-info-symbol
20808
 
20809
@subsubheading Synopsis
20810
 
20811
@smallexample
20812
 -symbol-info-symbol @var{addr}
20813
@end smallexample
20814
 
20815
Describe what symbol is at location @var{addr}.
20816
 
20817
@subsubheading @value{GDBN} Command
20818
 
20819
The corresponding @value{GDBN} command is @samp{info symbol}.
20820
 
20821
@subsubheading Example
20822
N.A.
20823
 
20824
 
20825
@subheading The @code{-symbol-list-functions} Command
20826
@findex -symbol-list-functions
20827
 
20828
@subsubheading Synopsis
20829
 
20830
@smallexample
20831
 -symbol-list-functions
20832
@end smallexample
20833
 
20834
List the functions in the executable.
20835
 
20836
@subsubheading @value{GDBN} Command
20837
 
20838
@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
20839
@samp{gdb_search} in @code{gdbtk}.
20840
 
20841
@subsubheading Example
20842
N.A.
20843
 
20844
 
20845
@subheading The @code{-symbol-list-lines} Command
20846
@findex -symbol-list-lines
20847
 
20848
@subsubheading Synopsis
20849
 
20850
@smallexample
20851
 -symbol-list-lines @var{filename}
20852
@end smallexample
20853
 
20854
Print the list of lines that contain code and their associated program
20855
addresses for the given source filename.  The entries are sorted in
20856
ascending PC order.
20857
 
20858
@subsubheading @value{GDBN} Command
20859
 
20860
There is no corresponding @value{GDBN} command.
20861
 
20862
@subsubheading Example
20863
@smallexample
20864
(gdb)
20865
-symbol-list-lines basics.c
20866
^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
20867
(gdb)
20868
@end smallexample
20869
 
20870
 
20871
@subheading The @code{-symbol-list-types} Command
20872
@findex -symbol-list-types
20873
 
20874
@subsubheading Synopsis
20875
 
20876
@smallexample
20877
 -symbol-list-types
20878
@end smallexample
20879
 
20880
List all the type names.
20881
 
20882
@subsubheading @value{GDBN} Command
20883
 
20884
The corresponding commands are @samp{info types} in @value{GDBN},
20885
@samp{gdb_search} in @code{gdbtk}.
20886
 
20887
@subsubheading Example
20888
N.A.
20889
 
20890
 
20891
@subheading The @code{-symbol-list-variables} Command
20892
@findex -symbol-list-variables
20893
 
20894
@subsubheading Synopsis
20895
 
20896
@smallexample
20897
 -symbol-list-variables
20898
@end smallexample
20899
 
20900
List all the global and static variable names.
20901
 
20902
@subsubheading @value{GDBN} Command
20903
 
20904
@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
20905
 
20906
@subsubheading Example
20907
N.A.
20908
 
20909
 
20910
@subheading The @code{-symbol-locate} Command
20911
@findex -symbol-locate
20912
 
20913
@subsubheading Synopsis
20914
 
20915
@smallexample
20916
 -symbol-locate
20917
@end smallexample
20918
 
20919
@subsubheading @value{GDBN} Command
20920
 
20921
@samp{gdb_loc} in @code{gdbtk}.
20922
 
20923
@subsubheading Example
20924
N.A.
20925
 
20926
 
20927
@subheading The @code{-symbol-type} Command
20928
@findex -symbol-type
20929
 
20930
@subsubheading Synopsis
20931
 
20932
@smallexample
20933
 -symbol-type @var{variable}
20934
@end smallexample
20935
 
20936
Show type of @var{variable}.
20937
 
20938
@subsubheading @value{GDBN} Command
20939
 
20940
The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
20941
@samp{gdb_obj_variable}.
20942
 
20943
@subsubheading Example
20944
N.A.
20945
 
20946
 
20947
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20948
@node GDB/MI File Commands
20949
@section @sc{gdb/mi} File Commands
20950
 
20951
This section describes the GDB/MI commands to specify executable file names
20952
and to read in and obtain symbol table information.
20953
 
20954
@subheading The @code{-file-exec-and-symbols} Command
20955
@findex -file-exec-and-symbols
20956
 
20957
@subsubheading Synopsis
20958
 
20959
@smallexample
20960
 -file-exec-and-symbols @var{file}
20961
@end smallexample
20962
 
20963
Specify the executable file to be debugged.  This file is the one from
20964
which the symbol table is also read.  If no file is specified, the
20965
command clears the executable and symbol information.  If breakpoints
20966
are set when using this command with no arguments, @value{GDBN} will produce
20967
error messages.  Otherwise, no output is produced, except a completion
20968
notification.
20969
 
20970
@subsubheading @value{GDBN} Command
20971
 
20972
The corresponding @value{GDBN} command is @samp{file}.
20973
 
20974
@subsubheading Example
20975
 
20976
@smallexample
20977
(gdb)
20978
-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
20979
^done
20980
(gdb)
20981
@end smallexample
20982
 
20983
 
20984
@subheading The @code{-file-exec-file} Command
20985
@findex -file-exec-file
20986
 
20987
@subsubheading Synopsis
20988
 
20989
@smallexample
20990
 -file-exec-file @var{file}
20991
@end smallexample
20992
 
20993
Specify the executable file to be debugged.  Unlike
20994
@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
20995
from this file.  If used without argument, @value{GDBN} clears the information
20996
about the executable file.  No output is produced, except a completion
20997
notification.
20998
 
20999
@subsubheading @value{GDBN} Command
21000
 
21001
The corresponding @value{GDBN} command is @samp{exec-file}.
21002
 
21003
@subsubheading Example
21004
 
21005
@smallexample
21006
(gdb)
21007
-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
21008
^done
21009
(gdb)
21010
@end smallexample
21011
 
21012
 
21013
@subheading The @code{-file-list-exec-sections} Command
21014
@findex -file-list-exec-sections
21015
 
21016
@subsubheading Synopsis
21017
 
21018
@smallexample
21019
 -file-list-exec-sections
21020
@end smallexample
21021
 
21022
List the sections of the current executable file.
21023
 
21024
@subsubheading @value{GDBN} Command
21025
 
21026
The @value{GDBN} command @samp{info file} shows, among the rest, the same
21027
information as this command.  @code{gdbtk} has a corresponding command
21028
@samp{gdb_load_info}.
21029
 
21030
@subsubheading Example
21031
N.A.
21032
 
21033
 
21034
@subheading The @code{-file-list-exec-source-file} Command
21035
@findex -file-list-exec-source-file
21036
 
21037
@subsubheading Synopsis
21038
 
21039
@smallexample
21040
 -file-list-exec-source-file
21041
@end smallexample
21042
 
21043
List the line number, the current source file, and the absolute path
21044
to the current source file for the current executable.  The macro
21045
information field has a value of @samp{1} or @samp{0} depending on
21046
whether or not the file includes preprocessor macro information.
21047
 
21048
@subsubheading @value{GDBN} Command
21049
 
21050
The @value{GDBN} equivalent is @samp{info source}
21051
 
21052
@subsubheading Example
21053
 
21054
@smallexample
21055
(gdb)
21056
123-file-list-exec-source-file
21057
123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
21058
(gdb)
21059
@end smallexample
21060
 
21061
 
21062
@subheading The @code{-file-list-exec-source-files} Command
21063
@findex -file-list-exec-source-files
21064
 
21065
@subsubheading Synopsis
21066
 
21067
@smallexample
21068
 -file-list-exec-source-files
21069
@end smallexample
21070
 
21071
List the source files for the current executable.
21072
 
21073
It will always output the filename, but only when @value{GDBN} can find
21074
the absolute file name of a source file, will it output the fullname.
21075
 
21076
@subsubheading @value{GDBN} Command
21077
 
21078
The @value{GDBN} equivalent is @samp{info sources}.
21079
@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
21080
 
21081
@subsubheading Example
21082
@smallexample
21083
(gdb)
21084
-file-list-exec-source-files
21085
^done,files=[
21086
@{file=foo.c,fullname=/home/foo.c@},
21087
@{file=/home/bar.c,fullname=/home/bar.c@},
21088
@{file=gdb_could_not_find_fullpath.c@}]
21089
(gdb)
21090
@end smallexample
21091
 
21092
@subheading The @code{-file-list-shared-libraries} Command
21093
@findex -file-list-shared-libraries
21094
 
21095
@subsubheading Synopsis
21096
 
21097
@smallexample
21098
 -file-list-shared-libraries
21099
@end smallexample
21100
 
21101
List the shared libraries in the program.
21102
 
21103
@subsubheading @value{GDBN} Command
21104
 
21105
The corresponding @value{GDBN} command is @samp{info shared}.
21106
 
21107
@subsubheading Example
21108
N.A.
21109
 
21110
 
21111
@subheading The @code{-file-list-symbol-files} Command
21112
@findex -file-list-symbol-files
21113
 
21114
@subsubheading Synopsis
21115
 
21116
@smallexample
21117
 -file-list-symbol-files
21118
@end smallexample
21119
 
21120
List symbol files.
21121
 
21122
@subsubheading @value{GDBN} Command
21123
 
21124
The corresponding @value{GDBN} command is @samp{info file} (part of it).
21125
 
21126
@subsubheading Example
21127
N.A.
21128
 
21129
 
21130
@subheading The @code{-file-symbol-file} Command
21131
@findex -file-symbol-file
21132
 
21133
@subsubheading Synopsis
21134
 
21135
@smallexample
21136
 -file-symbol-file @var{file}
21137
@end smallexample
21138
 
21139
Read symbol table info from the specified @var{file} argument.  When
21140
used without arguments, clears @value{GDBN}'s symbol table info.  No output is
21141
produced, except for a completion notification.
21142
 
21143
@subsubheading @value{GDBN} Command
21144
 
21145
The corresponding @value{GDBN} command is @samp{symbol-file}.
21146
 
21147
@subsubheading Example
21148
 
21149
@smallexample
21150
(gdb)
21151
-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
21152
^done
21153
(gdb)
21154
@end smallexample
21155
 
21156
@ignore
21157
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21158
@node GDB/MI Memory Overlay Commands
21159
@section @sc{gdb/mi} Memory Overlay Commands
21160
 
21161
The memory overlay commands are not implemented.
21162
 
21163
@c @subheading -overlay-auto
21164
 
21165
@c @subheading -overlay-list-mapping-state
21166
 
21167
@c @subheading -overlay-list-overlays
21168
 
21169
@c @subheading -overlay-map
21170
 
21171
@c @subheading -overlay-off
21172
 
21173
@c @subheading -overlay-on
21174
 
21175
@c @subheading -overlay-unmap
21176
 
21177
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21178
@node GDB/MI Signal Handling Commands
21179
@section @sc{gdb/mi} Signal Handling Commands
21180
 
21181
Signal handling commands are not implemented.
21182
 
21183
@c @subheading -signal-handle
21184
 
21185
@c @subheading -signal-list-handle-actions
21186
 
21187
@c @subheading -signal-list-signal-types
21188
@end ignore
21189
 
21190
 
21191
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21192
@node GDB/MI Target Manipulation
21193
@section @sc{gdb/mi} Target Manipulation Commands
21194
 
21195
 
21196
@subheading The @code{-target-attach} Command
21197
@findex -target-attach
21198
 
21199
@subsubheading Synopsis
21200
 
21201
@smallexample
21202
 -target-attach @var{pid} | @var{file}
21203
@end smallexample
21204
 
21205
Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
21206
 
21207
@subsubheading @value{GDBN} Command
21208
 
21209
The corresponding @value{GDBN} command is @samp{attach}.
21210
 
21211
@subsubheading Example
21212
N.A.
21213
 
21214
 
21215
@subheading The @code{-target-compare-sections} Command
21216
@findex -target-compare-sections
21217
 
21218
@subsubheading Synopsis
21219
 
21220
@smallexample
21221
 -target-compare-sections [ @var{section} ]
21222
@end smallexample
21223
 
21224
Compare data of section @var{section} on target to the exec file.
21225
Without the argument, all sections are compared.
21226
 
21227
@subsubheading @value{GDBN} Command
21228
 
21229
The @value{GDBN} equivalent is @samp{compare-sections}.
21230
 
21231
@subsubheading Example
21232
N.A.
21233
 
21234
 
21235
@subheading The @code{-target-detach} Command
21236
@findex -target-detach
21237
 
21238
@subsubheading Synopsis
21239
 
21240
@smallexample
21241
 -target-detach
21242
@end smallexample
21243
 
21244
Detach from the remote target which normally resumes its execution.
21245
There's no output.
21246
 
21247
@subsubheading @value{GDBN} Command
21248
 
21249
The corresponding @value{GDBN} command is @samp{detach}.
21250
 
21251
@subsubheading Example
21252
 
21253
@smallexample
21254
(gdb)
21255
-target-detach
21256
^done
21257
(gdb)
21258
@end smallexample
21259
 
21260
 
21261
@subheading The @code{-target-disconnect} Command
21262
@findex -target-disconnect
21263
 
21264
@subsubheading Synopsis
21265
 
21266
@smallexample
21267
 -target-disconnect
21268
@end smallexample
21269
 
21270
Disconnect from the remote target.  There's no output and the target is
21271
generally not resumed.
21272
 
21273
@subsubheading @value{GDBN} Command
21274
 
21275
The corresponding @value{GDBN} command is @samp{disconnect}.
21276
 
21277
@subsubheading Example
21278
 
21279
@smallexample
21280
(gdb)
21281
-target-disconnect
21282
^done
21283
(gdb)
21284
@end smallexample
21285
 
21286
 
21287
@subheading The @code{-target-download} Command
21288
@findex -target-download
21289
 
21290
@subsubheading Synopsis
21291
 
21292
@smallexample
21293
 -target-download
21294
@end smallexample
21295
 
21296
Loads the executable onto the remote target.
21297
It prints out an update message every half second, which includes the fields:
21298
 
21299
@table @samp
21300
@item section
21301
The name of the section.
21302
@item section-sent
21303
The size of what has been sent so far for that section.
21304
@item section-size
21305
The size of the section.
21306
@item total-sent
21307
The total size of what was sent so far (the current and the previous sections).
21308
@item total-size
21309
The size of the overall executable to download.
21310
@end table
21311
 
21312
@noindent
21313
Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
21314
@sc{gdb/mi} Output Syntax}).
21315
 
21316
In addition, it prints the name and size of the sections, as they are
21317
downloaded.  These messages include the following fields:
21318
 
21319
@table @samp
21320
@item section
21321
The name of the section.
21322
@item section-size
21323
The size of the section.
21324
@item total-size
21325
The size of the overall executable to download.
21326
@end table
21327
 
21328
@noindent
21329
At the end, a summary is printed.
21330
 
21331
@subsubheading @value{GDBN} Command
21332
 
21333
The corresponding @value{GDBN} command is @samp{load}.
21334
 
21335
@subsubheading Example
21336
 
21337
Note: each status message appears on a single line.  Here the messages
21338
have been broken down so that they can fit onto a page.
21339
 
21340
@smallexample
21341
(gdb)
21342
-target-download
21343
+download,@{section=".text",section-size="6668",total-size="9880"@}
21344
+download,@{section=".text",section-sent="512",section-size="6668",
21345
total-sent="512",total-size="9880"@}
21346
+download,@{section=".text",section-sent="1024",section-size="6668",
21347
total-sent="1024",total-size="9880"@}
21348
+download,@{section=".text",section-sent="1536",section-size="6668",
21349
total-sent="1536",total-size="9880"@}
21350
+download,@{section=".text",section-sent="2048",section-size="6668",
21351
total-sent="2048",total-size="9880"@}
21352
+download,@{section=".text",section-sent="2560",section-size="6668",
21353
total-sent="2560",total-size="9880"@}
21354
+download,@{section=".text",section-sent="3072",section-size="6668",
21355
total-sent="3072",total-size="9880"@}
21356
+download,@{section=".text",section-sent="3584",section-size="6668",
21357
total-sent="3584",total-size="9880"@}
21358
+download,@{section=".text",section-sent="4096",section-size="6668",
21359
total-sent="4096",total-size="9880"@}
21360
+download,@{section=".text",section-sent="4608",section-size="6668",
21361
total-sent="4608",total-size="9880"@}
21362
+download,@{section=".text",section-sent="5120",section-size="6668",
21363
total-sent="5120",total-size="9880"@}
21364
+download,@{section=".text",section-sent="5632",section-size="6668",
21365
total-sent="5632",total-size="9880"@}
21366
+download,@{section=".text",section-sent="6144",section-size="6668",
21367
total-sent="6144",total-size="9880"@}
21368
+download,@{section=".text",section-sent="6656",section-size="6668",
21369
total-sent="6656",total-size="9880"@}
21370
+download,@{section=".init",section-size="28",total-size="9880"@}
21371
+download,@{section=".fini",section-size="28",total-size="9880"@}
21372
+download,@{section=".data",section-size="3156",total-size="9880"@}
21373
+download,@{section=".data",section-sent="512",section-size="3156",
21374
total-sent="7236",total-size="9880"@}
21375
+download,@{section=".data",section-sent="1024",section-size="3156",
21376
total-sent="7748",total-size="9880"@}
21377
+download,@{section=".data",section-sent="1536",section-size="3156",
21378
total-sent="8260",total-size="9880"@}
21379
+download,@{section=".data",section-sent="2048",section-size="3156",
21380
total-sent="8772",total-size="9880"@}
21381
+download,@{section=".data",section-sent="2560",section-size="3156",
21382
total-sent="9284",total-size="9880"@}
21383
+download,@{section=".data",section-sent="3072",section-size="3156",
21384
total-sent="9796",total-size="9880"@}
21385
^done,address="0x10004",load-size="9880",transfer-rate="6586",
21386
write-rate="429"
21387
(gdb)
21388
@end smallexample
21389
 
21390
 
21391
@subheading The @code{-target-exec-status} Command
21392
@findex -target-exec-status
21393
 
21394
@subsubheading Synopsis
21395
 
21396
@smallexample
21397
 -target-exec-status
21398
@end smallexample
21399
 
21400
Provide information on the state of the target (whether it is running or
21401
not, for instance).
21402
 
21403
@subsubheading @value{GDBN} Command
21404
 
21405
There's no equivalent @value{GDBN} command.
21406
 
21407
@subsubheading Example
21408
N.A.
21409
 
21410
 
21411
@subheading The @code{-target-list-available-targets} Command
21412
@findex -target-list-available-targets
21413
 
21414
@subsubheading Synopsis
21415
 
21416
@smallexample
21417
 -target-list-available-targets
21418
@end smallexample
21419
 
21420
List the possible targets to connect to.
21421
 
21422
@subsubheading @value{GDBN} Command
21423
 
21424
The corresponding @value{GDBN} command is @samp{help target}.
21425
 
21426
@subsubheading Example
21427
N.A.
21428
 
21429
 
21430
@subheading The @code{-target-list-current-targets} Command
21431
@findex -target-list-current-targets
21432
 
21433
@subsubheading Synopsis
21434
 
21435
@smallexample
21436
 -target-list-current-targets
21437
@end smallexample
21438
 
21439
Describe the current target.
21440
 
21441
@subsubheading @value{GDBN} Command
21442
 
21443
The corresponding information is printed by @samp{info file} (among
21444
other things).
21445
 
21446
@subsubheading Example
21447
N.A.
21448
 
21449
 
21450
@subheading The @code{-target-list-parameters} Command
21451
@findex -target-list-parameters
21452
 
21453
@subsubheading Synopsis
21454
 
21455
@smallexample
21456
 -target-list-parameters
21457
@end smallexample
21458
 
21459
@c ????
21460
 
21461
@subsubheading @value{GDBN} Command
21462
 
21463
No equivalent.
21464
 
21465
@subsubheading Example
21466
N.A.
21467
 
21468
 
21469
@subheading The @code{-target-select} Command
21470
@findex -target-select
21471
 
21472
@subsubheading Synopsis
21473
 
21474
@smallexample
21475
 -target-select @var{type} @var{parameters @dots{}}
21476
@end smallexample
21477
 
21478
Connect @value{GDBN} to the remote target.  This command takes two args:
21479
 
21480
@table @samp
21481
@item @var{type}
21482
The type of target, for instance @samp{async}, @samp{remote}, etc.
21483
@item @var{parameters}
21484
Device names, host names and the like.  @xref{Target Commands, ,
21485
Commands for Managing Targets}, for more details.
21486
@end table
21487
 
21488
The output is a connection notification, followed by the address at
21489
which the target program is, in the following form:
21490
 
21491
@smallexample
21492
^connected,addr="@var{address}",func="@var{function name}",
21493
  args=[@var{arg list}]
21494
@end smallexample
21495
 
21496
@subsubheading @value{GDBN} Command
21497
 
21498
The corresponding @value{GDBN} command is @samp{target}.
21499
 
21500
@subsubheading Example
21501
 
21502
@smallexample
21503
(gdb)
21504
-target-select async /dev/ttya
21505
^connected,addr="0xfe00a300",func="??",args=[]
21506
(gdb)
21507
@end smallexample
21508
 
21509
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21510
@node GDB/MI File Transfer Commands
21511
@section @sc{gdb/mi} File Transfer Commands
21512
 
21513
 
21514
@subheading The @code{-target-file-put} Command
21515
@findex -target-file-put
21516
 
21517
@subsubheading Synopsis
21518
 
21519
@smallexample
21520
 -target-file-put @var{hostfile} @var{targetfile}
21521
@end smallexample
21522
 
21523
Copy file @var{hostfile} from the host system (the machine running
21524
@value{GDBN}) to @var{targetfile} on the target system.
21525
 
21526
@subsubheading @value{GDBN} Command
21527
 
21528
The corresponding @value{GDBN} command is @samp{remote put}.
21529
 
21530
@subsubheading Example
21531
 
21532
@smallexample
21533
(gdb)
21534
-target-file-put localfile remotefile
21535
^done
21536
(gdb)
21537
@end smallexample
21538
 
21539
 
21540
@subheading The @code{-target-file-put} Command
21541
@findex -target-file-get
21542
 
21543
@subsubheading Synopsis
21544
 
21545
@smallexample
21546
 -target-file-get @var{targetfile} @var{hostfile}
21547
@end smallexample
21548
 
21549
Copy file @var{targetfile} from the target system to @var{hostfile}
21550
on the host system.
21551
 
21552
@subsubheading @value{GDBN} Command
21553
 
21554
The corresponding @value{GDBN} command is @samp{remote get}.
21555
 
21556
@subsubheading Example
21557
 
21558
@smallexample
21559
(gdb)
21560
-target-file-get remotefile localfile
21561
^done
21562
(gdb)
21563
@end smallexample
21564
 
21565
 
21566
@subheading The @code{-target-file-delete} Command
21567
@findex -target-file-delete
21568
 
21569
@subsubheading Synopsis
21570
 
21571
@smallexample
21572
 -target-file-delete @var{targetfile}
21573
@end smallexample
21574
 
21575
Delete @var{targetfile} from the target system.
21576
 
21577
@subsubheading @value{GDBN} Command
21578
 
21579
The corresponding @value{GDBN} command is @samp{remote delete}.
21580
 
21581
@subsubheading Example
21582
 
21583
@smallexample
21584
(gdb)
21585
-target-file-delete remotefile
21586
^done
21587
(gdb)
21588
@end smallexample
21589
 
21590
 
21591
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21592
@node GDB/MI Miscellaneous Commands
21593
@section Miscellaneous @sc{gdb/mi} Commands
21594
 
21595
@c @subheading -gdb-complete
21596
 
21597
@subheading The @code{-gdb-exit} Command
21598
@findex -gdb-exit
21599
 
21600
@subsubheading Synopsis
21601
 
21602
@smallexample
21603
 -gdb-exit
21604
@end smallexample
21605
 
21606
Exit @value{GDBN} immediately.
21607
 
21608
@subsubheading @value{GDBN} Command
21609
 
21610
Approximately corresponds to @samp{quit}.
21611
 
21612
@subsubheading Example
21613
 
21614
@smallexample
21615
(gdb)
21616
-gdb-exit
21617
^exit
21618
@end smallexample
21619
 
21620
 
21621
@subheading The @code{-exec-abort} Command
21622
@findex -exec-abort
21623
 
21624
@subsubheading Synopsis
21625
 
21626
@smallexample
21627
 -exec-abort
21628
@end smallexample
21629
 
21630
Kill the inferior running program.
21631
 
21632
@subsubheading @value{GDBN} Command
21633
 
21634
The corresponding @value{GDBN} command is @samp{kill}.
21635
 
21636
@subsubheading Example
21637
N.A.
21638
 
21639
 
21640
@subheading The @code{-gdb-set} Command
21641
@findex -gdb-set
21642
 
21643
@subsubheading Synopsis
21644
 
21645
@smallexample
21646
 -gdb-set
21647
@end smallexample
21648
 
21649
Set an internal @value{GDBN} variable.
21650
@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
21651
 
21652
@subsubheading @value{GDBN} Command
21653
 
21654
The corresponding @value{GDBN} command is @samp{set}.
21655
 
21656
@subsubheading Example
21657
 
21658
@smallexample
21659
(gdb)
21660
-gdb-set $foo=3
21661
^done
21662
(gdb)
21663
@end smallexample
21664
 
21665
 
21666
@subheading The @code{-gdb-show} Command
21667
@findex -gdb-show
21668
 
21669
@subsubheading Synopsis
21670
 
21671
@smallexample
21672
 -gdb-show
21673
@end smallexample
21674
 
21675
Show the current value of a @value{GDBN} variable.
21676
 
21677
@subsubheading @value{GDBN} Command
21678
 
21679
The corresponding @value{GDBN} command is @samp{show}.
21680
 
21681
@subsubheading Example
21682
 
21683
@smallexample
21684
(gdb)
21685
-gdb-show annotate
21686
^done,value="0"
21687
(gdb)
21688
@end smallexample
21689
 
21690
@c @subheading -gdb-source
21691
 
21692
 
21693
@subheading The @code{-gdb-version} Command
21694
@findex -gdb-version
21695
 
21696
@subsubheading Synopsis
21697
 
21698
@smallexample
21699
 -gdb-version
21700
@end smallexample
21701
 
21702
Show version information for @value{GDBN}.  Used mostly in testing.
21703
 
21704
@subsubheading @value{GDBN} Command
21705
 
21706
The @value{GDBN} equivalent is @samp{show version}.  @value{GDBN} by
21707
default shows this information when you start an interactive session.
21708
 
21709
@subsubheading Example
21710
 
21711
@c This example modifies the actual output from GDB to avoid overfull
21712
@c box in TeX.
21713
@smallexample
21714
(gdb)
21715
-gdb-version
21716
~GNU gdb 5.2.1
21717
~Copyright 2000 Free Software Foundation, Inc.
21718
~GDB is free software, covered by the GNU General Public License, and
21719
~you are welcome to change it and/or distribute copies of it under
21720
~ certain conditions.
21721
~Type "show copying" to see the conditions.
21722
~There is absolutely no warranty for GDB.  Type "show warranty" for
21723
~ details.
21724
~This GDB was configured as
21725
 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
21726
^done
21727
(gdb)
21728
@end smallexample
21729
 
21730
@subheading The @code{-list-features} Command
21731
@findex -list-features
21732
 
21733
Returns a list of particular features of the MI protocol that
21734
this version of gdb implements.  A feature can be a command,
21735
or a new field in an output of some command, or even an
21736
important bugfix.  While a frontend can sometimes detect presence
21737
of a feature at runtime, it is easier to perform detection at debugger
21738
startup.
21739
 
21740
The command returns a list of strings, with each string naming an
21741
available feature.  Each returned string is just a name, it does not
21742
have any internal structure.  The list of possible feature names
21743
is given below.
21744
 
21745
Example output:
21746
 
21747
@smallexample
21748
(gdb) -list-features
21749
^done,result=["feature1","feature2"]
21750
@end smallexample
21751
 
21752
The current list of features is:
21753
 
21754
@itemize @minus
21755
@item
21756
@samp{frozen-varobjs}---indicates presence of the
21757
@code{-var-set-frozen} command, as well as possible presense of the
21758
@code{frozen} field in the output of @code{-varobj-create}.
21759
@item
21760
@samp{pending-breakpoints}---indicates presence of the @code{-f}
21761
option to the @code{-break-insert} command.
21762
 
21763
@end itemize
21764
 
21765
@subheading The @code{-interpreter-exec} Command
21766
@findex -interpreter-exec
21767
 
21768
@subheading Synopsis
21769
 
21770
@smallexample
21771
-interpreter-exec @var{interpreter} @var{command}
21772
@end smallexample
21773
@anchor{-interpreter-exec}
21774
 
21775
Execute the specified @var{command} in the given @var{interpreter}.
21776
 
21777
@subheading @value{GDBN} Command
21778
 
21779
The corresponding @value{GDBN} command is @samp{interpreter-exec}.
21780
 
21781
@subheading Example
21782
 
21783
@smallexample
21784
(gdb)
21785
-interpreter-exec console "break main"
21786
&"During symbol reading, couldn't parse type; debugger out of date?.\n"
21787
&"During symbol reading, bad structure-type format.\n"
21788
~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
21789
^done
21790
(gdb)
21791
@end smallexample
21792
 
21793
@subheading The @code{-inferior-tty-set} Command
21794
@findex -inferior-tty-set
21795
 
21796
@subheading Synopsis
21797
 
21798
@smallexample
21799
-inferior-tty-set /dev/pts/1
21800
@end smallexample
21801
 
21802
Set terminal for future runs of the program being debugged.
21803
 
21804
@subheading @value{GDBN} Command
21805
 
21806
The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
21807
 
21808
@subheading Example
21809
 
21810
@smallexample
21811
(gdb)
21812
-inferior-tty-set /dev/pts/1
21813
^done
21814
(gdb)
21815
@end smallexample
21816
 
21817
@subheading The @code{-inferior-tty-show} Command
21818
@findex -inferior-tty-show
21819
 
21820
@subheading Synopsis
21821
 
21822
@smallexample
21823
-inferior-tty-show
21824
@end smallexample
21825
 
21826
Show terminal for future runs of program being debugged.
21827
 
21828
@subheading @value{GDBN} Command
21829
 
21830
The corresponding @value{GDBN} command is @samp{show inferior-tty}.
21831
 
21832
@subheading Example
21833
 
21834
@smallexample
21835
(gdb)
21836
-inferior-tty-set /dev/pts/1
21837
^done
21838
(gdb)
21839
-inferior-tty-show
21840
^done,inferior_tty_terminal="/dev/pts/1"
21841
(gdb)
21842
@end smallexample
21843
 
21844
@subheading The @code{-enable-timings} Command
21845
@findex -enable-timings
21846
 
21847
@subheading Synopsis
21848
 
21849
@smallexample
21850
-enable-timings [yes | no]
21851
@end smallexample
21852
 
21853
Toggle the printing of the wallclock, user and system times for an MI
21854
command as a field in its output.  This command is to help frontend
21855
developers optimize the performance of their code.  No argument is
21856
equivalent to @samp{yes}.
21857
 
21858
@subheading @value{GDBN} Command
21859
 
21860
No equivalent.
21861
 
21862
@subheading Example
21863
 
21864
@smallexample
21865
(gdb)
21866
-enable-timings
21867
^done
21868
(gdb)
21869
-break-insert main
21870
^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
21871
addr="0x080484ed",func="main",file="myprog.c",
21872
fullname="/home/nickrob/myprog.c",line="73",times="0"@},
21873
time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
21874
(gdb)
21875
-enable-timings no
21876
^done
21877
(gdb)
21878
-exec-run
21879
^running
21880
(gdb)
21881
*stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",
21882
frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
21883
@{name="argv",value="0xbfb60364"@}],file="myprog.c",
21884
fullname="/home/nickrob/myprog.c",line="73"@}
21885
(gdb)
21886
@end smallexample
21887
 
21888
@node Annotations
21889
@chapter @value{GDBN} Annotations
21890
 
21891
This chapter describes annotations in @value{GDBN}.  Annotations were
21892
designed to interface @value{GDBN} to graphical user interfaces or other
21893
similar programs which want to interact with @value{GDBN} at a
21894
relatively high level.
21895
 
21896
The annotation mechanism has largely been superseded by @sc{gdb/mi}
21897
(@pxref{GDB/MI}).
21898
 
21899
@ignore
21900
This is Edition @value{EDITION}, @value{DATE}.
21901
@end ignore
21902
 
21903
@menu
21904
* Annotations Overview::  What annotations are; the general syntax.
21905
* Server Prefix::       Issuing a command without affecting user state.
21906
* Prompting::           Annotations marking @value{GDBN}'s need for input.
21907
* Errors::              Annotations for error messages.
21908
* Invalidation::        Some annotations describe things now invalid.
21909
* Annotations for Running::
21910
                        Whether the program is running, how it stopped, etc.
21911
* Source Annotations::  Annotations describing source code.
21912
@end menu
21913
 
21914
@node Annotations Overview
21915
@section What is an Annotation?
21916
@cindex annotations
21917
 
21918
Annotations start with a newline character, two @samp{control-z}
21919
characters, and the name of the annotation.  If there is no additional
21920
information associated with this annotation, the name of the annotation
21921
is followed immediately by a newline.  If there is additional
21922
information, the name of the annotation is followed by a space, the
21923
additional information, and a newline.  The additional information
21924
cannot contain newline characters.
21925
 
21926
Any output not beginning with a newline and two @samp{control-z}
21927
characters denotes literal output from @value{GDBN}.  Currently there is
21928
no need for @value{GDBN} to output a newline followed by two
21929
@samp{control-z} characters, but if there was such a need, the
21930
annotations could be extended with an @samp{escape} annotation which
21931
means those three characters as output.
21932
 
21933
The annotation @var{level}, which is specified using the
21934
@option{--annotate} command line option (@pxref{Mode Options}), controls
21935
how much information @value{GDBN} prints together with its prompt,
21936
values of expressions, source lines, and other types of output.  Level 0
21937
is for no annotations, level 1 is for use when @value{GDBN} is run as a
21938
subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
21939
for programs that control @value{GDBN}, and level 2 annotations have
21940
been made obsolete (@pxref{Limitations, , Limitations of the Annotation
21941
Interface, annotate, GDB's Obsolete Annotations}).
21942
 
21943
@table @code
21944
@kindex set annotate
21945
@item set annotate @var{level}
21946
The @value{GDBN} command @code{set annotate} sets the level of
21947
annotations to the specified @var{level}.
21948
 
21949
@item show annotate
21950
@kindex show annotate
21951
Show the current annotation level.
21952
@end table
21953
 
21954
This chapter describes level 3 annotations.
21955
 
21956
A simple example of starting up @value{GDBN} with annotations is:
21957
 
21958
@smallexample
21959
$ @kbd{gdb --annotate=3}
21960
GNU gdb 6.0
21961
Copyright 2003 Free Software Foundation, Inc.
21962
GDB is free software, covered by the GNU General Public License,
21963
and you are welcome to change it and/or distribute copies of it
21964
under certain conditions.
21965
Type "show copying" to see the conditions.
21966
There is absolutely no warranty for GDB.  Type "show warranty"
21967
for details.
21968
This GDB was configured as "i386-pc-linux-gnu"
21969
 
21970
^Z^Zpre-prompt
21971
(@value{GDBP})
21972
^Z^Zprompt
21973
@kbd{quit}
21974
 
21975
^Z^Zpost-prompt
21976
$
21977
@end smallexample
21978
 
21979
Here @samp{quit} is input to @value{GDBN}; the rest is output from
21980
@value{GDBN}.  The three lines beginning @samp{^Z^Z} (where @samp{^Z}
21981
denotes a @samp{control-z} character) are annotations; the rest is
21982
output from @value{GDBN}.
21983
 
21984
@node Server Prefix
21985
@section The Server Prefix
21986
@cindex server prefix
21987
 
21988
If you prefix a command with @samp{server } then it will not affect
21989
the command history, nor will it affect @value{GDBN}'s notion of which
21990
command to repeat if @key{RET} is pressed on a line by itself.  This
21991
means that commands can be run behind a user's back by a front-end in
21992
a transparent manner.
21993
 
21994
The server prefix does not affect the recording of values into the value
21995
history; to print a value without recording it into the value history,
21996
use the @code{output} command instead of the @code{print} command.
21997
 
21998
@node Prompting
21999
@section Annotation for @value{GDBN} Input
22000
 
22001
@cindex annotations for prompts
22002
When @value{GDBN} prompts for input, it annotates this fact so it is possible
22003
to know when to send output, when the output from a given command is
22004
over, etc.
22005
 
22006
Different kinds of input each have a different @dfn{input type}.  Each
22007
input type has three annotations: a @code{pre-} annotation, which
22008
denotes the beginning of any prompt which is being output, a plain
22009
annotation, which denotes the end of the prompt, and then a @code{post-}
22010
annotation which denotes the end of any echo which may (or may not) be
22011
associated with the input.  For example, the @code{prompt} input type
22012
features the following annotations:
22013
 
22014
@smallexample
22015
^Z^Zpre-prompt
22016
^Z^Zprompt
22017
^Z^Zpost-prompt
22018
@end smallexample
22019
 
22020
The input types are
22021
 
22022
@table @code
22023
@findex pre-prompt annotation
22024
@findex prompt annotation
22025
@findex post-prompt annotation
22026
@item prompt
22027
When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
22028
 
22029
@findex pre-commands annotation
22030
@findex commands annotation
22031
@findex post-commands annotation
22032
@item commands
22033
When @value{GDBN} prompts for a set of commands, like in the @code{commands}
22034
command.  The annotations are repeated for each command which is input.
22035
 
22036
@findex pre-overload-choice annotation
22037
@findex overload-choice annotation
22038
@findex post-overload-choice annotation
22039
@item overload-choice
22040
When @value{GDBN} wants the user to select between various overloaded functions.
22041
 
22042
@findex pre-query annotation
22043
@findex query annotation
22044
@findex post-query annotation
22045
@item query
22046
When @value{GDBN} wants the user to confirm a potentially dangerous operation.
22047
 
22048
@findex pre-prompt-for-continue annotation
22049
@findex prompt-for-continue annotation
22050
@findex post-prompt-for-continue annotation
22051
@item prompt-for-continue
22052
When @value{GDBN} is asking the user to press return to continue.  Note: Don't
22053
expect this to work well; instead use @code{set height 0} to disable
22054
prompting.  This is because the counting of lines is buggy in the
22055
presence of annotations.
22056
@end table
22057
 
22058
@node Errors
22059
@section Errors
22060
@cindex annotations for errors, warnings and interrupts
22061
 
22062
@findex quit annotation
22063
@smallexample
22064
^Z^Zquit
22065
@end smallexample
22066
 
22067
This annotation occurs right before @value{GDBN} responds to an interrupt.
22068
 
22069
@findex error annotation
22070
@smallexample
22071
^Z^Zerror
22072
@end smallexample
22073
 
22074
This annotation occurs right before @value{GDBN} responds to an error.
22075
 
22076
Quit and error annotations indicate that any annotations which @value{GDBN} was
22077
in the middle of may end abruptly.  For example, if a
22078
@code{value-history-begin} annotation is followed by a @code{error}, one
22079
cannot expect to receive the matching @code{value-history-end}.  One
22080
cannot expect not to receive it either, however; an error annotation
22081
does not necessarily mean that @value{GDBN} is immediately returning all the way
22082
to the top level.
22083
 
22084
@findex error-begin annotation
22085
A quit or error annotation may be preceded by
22086
 
22087
@smallexample
22088
^Z^Zerror-begin
22089
@end smallexample
22090
 
22091
Any output between that and the quit or error annotation is the error
22092
message.
22093
 
22094
Warning messages are not yet annotated.
22095
@c If we want to change that, need to fix warning(), type_error(),
22096
@c range_error(), and possibly other places.
22097
 
22098
@node Invalidation
22099
@section Invalidation Notices
22100
 
22101
@cindex annotations for invalidation messages
22102
The following annotations say that certain pieces of state may have
22103
changed.
22104
 
22105
@table @code
22106
@findex frames-invalid annotation
22107
@item ^Z^Zframes-invalid
22108
 
22109
The frames (for example, output from the @code{backtrace} command) may
22110
have changed.
22111
 
22112
@findex breakpoints-invalid annotation
22113
@item ^Z^Zbreakpoints-invalid
22114
 
22115
The breakpoints may have changed.  For example, the user just added or
22116
deleted a breakpoint.
22117
@end table
22118
 
22119
@node Annotations for Running
22120
@section Running the Program
22121
@cindex annotations for running programs
22122
 
22123
@findex starting annotation
22124
@findex stopping annotation
22125
When the program starts executing due to a @value{GDBN} command such as
22126
@code{step} or @code{continue},
22127
 
22128
@smallexample
22129
^Z^Zstarting
22130
@end smallexample
22131
 
22132
is output.  When the program stops,
22133
 
22134
@smallexample
22135
^Z^Zstopped
22136
@end smallexample
22137
 
22138
is output.  Before the @code{stopped} annotation, a variety of
22139
annotations describe how the program stopped.
22140
 
22141
@table @code
22142
@findex exited annotation
22143
@item ^Z^Zexited @var{exit-status}
22144
The program exited, and @var{exit-status} is the exit status (zero for
22145
successful exit, otherwise nonzero).
22146
 
22147
@findex signalled annotation
22148
@findex signal-name annotation
22149
@findex signal-name-end annotation
22150
@findex signal-string annotation
22151
@findex signal-string-end annotation
22152
@item ^Z^Zsignalled
22153
The program exited with a signal.  After the @code{^Z^Zsignalled}, the
22154
annotation continues:
22155
 
22156
@smallexample
22157
@var{intro-text}
22158
^Z^Zsignal-name
22159
@var{name}
22160
^Z^Zsignal-name-end
22161
@var{middle-text}
22162
^Z^Zsignal-string
22163
@var{string}
22164
^Z^Zsignal-string-end
22165
@var{end-text}
22166
@end smallexample
22167
 
22168
@noindent
22169
where @var{name} is the name of the signal, such as @code{SIGILL} or
22170
@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
22171
as @code{Illegal Instruction} or @code{Segmentation fault}.
22172
@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
22173
user's benefit and have no particular format.
22174
 
22175
@findex signal annotation
22176
@item ^Z^Zsignal
22177
The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
22178
just saying that the program received the signal, not that it was
22179
terminated with it.
22180
 
22181
@findex breakpoint annotation
22182
@item ^Z^Zbreakpoint @var{number}
22183
The program hit breakpoint number @var{number}.
22184
 
22185
@findex watchpoint annotation
22186
@item ^Z^Zwatchpoint @var{number}
22187
The program hit watchpoint number @var{number}.
22188
@end table
22189
 
22190
@node Source Annotations
22191
@section Displaying Source
22192
@cindex annotations for source display
22193
 
22194
@findex source annotation
22195
The following annotation is used instead of displaying source code:
22196
 
22197
@smallexample
22198
^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
22199
@end smallexample
22200
 
22201
where @var{filename} is an absolute file name indicating which source
22202
file, @var{line} is the line number within that file (where 1 is the
22203
first line in the file), @var{character} is the character position
22204
within the file (where 0 is the first character in the file) (for most
22205
debug formats this will necessarily point to the beginning of a line),
22206
@var{middle} is @samp{middle} if @var{addr} is in the middle of the
22207
line, or @samp{beg} if @var{addr} is at the beginning of the line, and
22208
@var{addr} is the address in the target program associated with the
22209
source which is being displayed.  @var{addr} is in the form @samp{0x}
22210
followed by one or more lowercase hex digits (note that this does not
22211
depend on the language).
22212
 
22213
@node GDB Bugs
22214
@chapter Reporting Bugs in @value{GDBN}
22215
@cindex bugs in @value{GDBN}
22216
@cindex reporting bugs in @value{GDBN}
22217
 
22218
Your bug reports play an essential role in making @value{GDBN} reliable.
22219
 
22220
Reporting a bug may help you by bringing a solution to your problem, or it
22221
may not.  But in any case the principal function of a bug report is to help
22222
the entire community by making the next version of @value{GDBN} work better.  Bug
22223
reports are your contribution to the maintenance of @value{GDBN}.
22224
 
22225
In order for a bug report to serve its purpose, you must include the
22226
information that enables us to fix the bug.
22227
 
22228
@menu
22229
* Bug Criteria::                Have you found a bug?
22230
* Bug Reporting::               How to report bugs
22231
@end menu
22232
 
22233
@node Bug Criteria
22234
@section Have You Found a Bug?
22235
@cindex bug criteria
22236
 
22237
If you are not sure whether you have found a bug, here are some guidelines:
22238
 
22239
@itemize @bullet
22240
@cindex fatal signal
22241
@cindex debugger crash
22242
@cindex crash of debugger
22243
@item
22244
If the debugger gets a fatal signal, for any input whatever, that is a
22245
@value{GDBN} bug.  Reliable debuggers never crash.
22246
 
22247
@cindex error on valid input
22248
@item
22249
If @value{GDBN} produces an error message for valid input, that is a
22250
bug.  (Note that if you're cross debugging, the problem may also be
22251
somewhere in the connection to the target.)
22252
 
22253
@cindex invalid input
22254
@item
22255
If @value{GDBN} does not produce an error message for invalid input,
22256
that is a bug.  However, you should note that your idea of
22257
``invalid input'' might be our idea of ``an extension'' or ``support
22258
for traditional practice''.
22259
 
22260
@item
22261
If you are an experienced user of debugging tools, your suggestions
22262
for improvement of @value{GDBN} are welcome in any case.
22263
@end itemize
22264
 
22265
@node Bug Reporting
22266
@section How to Report Bugs
22267
@cindex bug reports
22268
@cindex @value{GDBN} bugs, reporting
22269
 
22270
A number of companies and individuals offer support for @sc{gnu} products.
22271
If you obtained @value{GDBN} from a support organization, we recommend you
22272
contact that organization first.
22273
 
22274
You can find contact information for many support companies and
22275
individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
22276
distribution.
22277
@c should add a web page ref...
22278
 
22279
In any event, we also recommend that you submit bug reports for
22280
@value{GDBN}.  The preferred method is to submit them directly using
22281
@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
22282
page}.  Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
22283
be used.
22284
 
22285
@strong{Do not send bug reports to @samp{info-gdb}, or to
22286
@samp{help-gdb}, or to any newsgroups.}  Most users of @value{GDBN} do
22287
not want to receive bug reports.  Those that do have arranged to receive
22288
@samp{bug-gdb}.
22289
 
22290
The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
22291
serves as a repeater.  The mailing list and the newsgroup carry exactly
22292
the same messages.  Often people think of posting bug reports to the
22293
newsgroup instead of mailing them.  This appears to work, but it has one
22294
problem which can be crucial: a newsgroup posting often lacks a mail
22295
path back to the sender.  Thus, if we need to ask for more information,
22296
we may be unable to reach you.  For this reason, it is better to send
22297
bug reports to the mailing list.
22298
 
22299
The fundamental principle of reporting bugs usefully is this:
22300
@strong{report all the facts}.  If you are not sure whether to state a
22301
fact or leave it out, state it!
22302
 
22303
Often people omit facts because they think they know what causes the
22304
problem and assume that some details do not matter.  Thus, you might
22305
assume that the name of the variable you use in an example does not matter.
22306
Well, probably it does not, but one cannot be sure.  Perhaps the bug is a
22307
stray memory reference which happens to fetch from the location where that
22308
name is stored in memory; perhaps, if the name were different, the contents
22309
of that location would fool the debugger into doing the right thing despite
22310
the bug.  Play it safe and give a specific, complete example.  That is the
22311
easiest thing for you to do, and the most helpful.
22312
 
22313
Keep in mind that the purpose of a bug report is to enable us to fix the
22314
bug.  It may be that the bug has been reported previously, but neither
22315
you nor we can know that unless your bug report is complete and
22316
self-contained.
22317
 
22318
Sometimes people give a few sketchy facts and ask, ``Does this ring a
22319
bell?''  Those bug reports are useless, and we urge everyone to
22320
@emph{refuse to respond to them} except to chide the sender to report
22321
bugs properly.
22322
 
22323
To enable us to fix the bug, you should include all these things:
22324
 
22325
@itemize @bullet
22326
@item
22327
The version of @value{GDBN}.  @value{GDBN} announces it if you start
22328
with no arguments; you can also print it at any time using @code{show
22329
version}.
22330
 
22331
Without this, we will not know whether there is any point in looking for
22332
the bug in the current version of @value{GDBN}.
22333
 
22334
@item
22335
The type of machine you are using, and the operating system name and
22336
version number.
22337
 
22338
@item
22339
What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
22340
``@value{GCC}--2.8.1''.
22341
 
22342
@item
22343
What compiler (and its version) was used to compile the program you are
22344
debugging---e.g.@:  ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
22345
C Compiler''.  For @value{NGCC}, you can say @kbd{@value{GCC} --version}
22346
to get this information; for other compilers, see the documentation for
22347
those compilers.
22348
 
22349
@item
22350
The command arguments you gave the compiler to compile your example and
22351
observe the bug.  For example, did you use @samp{-O}?  To guarantee
22352
you will not omit something important, list them all.  A copy of the
22353
Makefile (or the output from make) is sufficient.
22354
 
22355
If we were to try to guess the arguments, we would probably guess wrong
22356
and then we might not encounter the bug.
22357
 
22358
@item
22359
A complete input script, and all necessary source files, that will
22360
reproduce the bug.
22361
 
22362
@item
22363
A description of what behavior you observe that you believe is
22364
incorrect.  For example, ``It gets a fatal signal.''
22365
 
22366
Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
22367
will certainly notice it.  But if the bug is incorrect output, we might
22368
not notice unless it is glaringly wrong.  You might as well not give us
22369
a chance to make a mistake.
22370
 
22371
Even if the problem you experience is a fatal signal, you should still
22372
say so explicitly.  Suppose something strange is going on, such as, your
22373
copy of @value{GDBN} is out of synch, or you have encountered a bug in
22374
the C library on your system.  (This has happened!)  Your copy might
22375
crash and ours would not.  If you told us to expect a crash, then when
22376
ours fails to crash, we would know that the bug was not happening for
22377
us.  If you had not told us to expect a crash, then we would not be able
22378
to draw any conclusion from our observations.
22379
 
22380
@pindex script
22381
@cindex recording a session script
22382
To collect all this information, you can use a session recording program
22383
such as @command{script}, which is available on many Unix systems.
22384
Just run your @value{GDBN} session inside @command{script} and then
22385
include the @file{typescript} file with your bug report.
22386
 
22387
Another way to record a @value{GDBN} session is to run @value{GDBN}
22388
inside Emacs and then save the entire buffer to a file.
22389
 
22390
@item
22391
If you wish to suggest changes to the @value{GDBN} source, send us context
22392
diffs.  If you even discuss something in the @value{GDBN} source, refer to
22393
it by context, not by line number.
22394
 
22395
The line numbers in our development sources will not match those in your
22396
sources.  Your line numbers would convey no useful information to us.
22397
 
22398
@end itemize
22399
 
22400
Here are some things that are not necessary:
22401
 
22402
@itemize @bullet
22403
@item
22404
A description of the envelope of the bug.
22405
 
22406
Often people who encounter a bug spend a lot of time investigating
22407
which changes to the input file will make the bug go away and which
22408
changes will not affect it.
22409
 
22410
This is often time consuming and not very useful, because the way we
22411
will find the bug is by running a single example under the debugger
22412
with breakpoints, not by pure deduction from a series of examples.
22413
We recommend that you save your time for something else.
22414
 
22415
Of course, if you can find a simpler example to report @emph{instead}
22416
of the original one, that is a convenience for us.  Errors in the
22417
output will be easier to spot, running under the debugger will take
22418
less time, and so on.
22419
 
22420
However, simplification is not vital; if you do not want to do this,
22421
report the bug anyway and send us the entire test case you used.
22422
 
22423
@item
22424
A patch for the bug.
22425
 
22426
A patch for the bug does help us if it is a good one.  But do not omit
22427
the necessary information, such as the test case, on the assumption that
22428
a patch is all we need.  We might see problems with your patch and decide
22429
to fix the problem another way, or we might not understand it at all.
22430
 
22431
Sometimes with a program as complicated as @value{GDBN} it is very hard to
22432
construct an example that will make the program follow a certain path
22433
through the code.  If you do not send us the example, we will not be able
22434
to construct one, so we will not be able to verify that the bug is fixed.
22435
 
22436
And if we cannot understand what bug you are trying to fix, or why your
22437
patch should be an improvement, we will not install it.  A test case will
22438
help us to understand.
22439
 
22440
@item
22441
A guess about what the bug is or what it depends on.
22442
 
22443
Such guesses are usually wrong.  Even we cannot guess right about such
22444
things without first using the debugger to find the facts.
22445
@end itemize
22446
 
22447
@c The readline documentation is distributed with the readline code
22448
@c and consists of the two following files:
22449
@c     rluser.texinfo
22450
@c     inc-hist.texinfo
22451
@c Use -I with makeinfo to point to the appropriate directory,
22452
@c environment var TEXINPUTS with TeX.
22453
@include rluser.texi
22454
@include inc-hist.texinfo
22455
 
22456
 
22457
@node Formatting Documentation
22458
@appendix Formatting Documentation
22459
 
22460
@cindex @value{GDBN} reference card
22461
@cindex reference card
22462
The @value{GDBN} 4 release includes an already-formatted reference card, ready
22463
for printing with PostScript or Ghostscript, in the @file{gdb}
22464
subdirectory of the main source directory@footnote{In
22465
@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
22466
release.}.  If you can use PostScript or Ghostscript with your printer,
22467
you can print the reference card immediately with @file{refcard.ps}.
22468
 
22469
The release also includes the source for the reference card.  You
22470
can format it, using @TeX{}, by typing:
22471
 
22472
@smallexample
22473
make refcard.dvi
22474
@end smallexample
22475
 
22476
The @value{GDBN} reference card is designed to print in @dfn{landscape}
22477
mode on US ``letter'' size paper;
22478
that is, on a sheet 11 inches wide by 8.5 inches
22479
high.  You will need to specify this form of printing as an option to
22480
your @sc{dvi} output program.
22481
 
22482
@cindex documentation
22483
 
22484
All the documentation for @value{GDBN} comes as part of the machine-readable
22485
distribution.  The documentation is written in Texinfo format, which is
22486
a documentation system that uses a single source file to produce both
22487
on-line information and a printed manual.  You can use one of the Info
22488
formatting commands to create the on-line version of the documentation
22489
and @TeX{} (or @code{texi2roff}) to typeset the printed version.
22490
 
22491
@value{GDBN} includes an already formatted copy of the on-line Info
22492
version of this manual in the @file{gdb} subdirectory.  The main Info
22493
file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
22494
subordinate files matching @samp{gdb.info*} in the same directory.  If
22495
necessary, you can print out these files, or read them with any editor;
22496
but they are easier to read using the @code{info} subsystem in @sc{gnu}
22497
Emacs or the standalone @code{info} program, available as part of the
22498
@sc{gnu} Texinfo distribution.
22499
 
22500
If you want to format these Info files yourself, you need one of the
22501
Info formatting programs, such as @code{texinfo-format-buffer} or
22502
@code{makeinfo}.
22503
 
22504
If you have @code{makeinfo} installed, and are in the top level
22505
@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
22506
version @value{GDBVN}), you can make the Info file by typing:
22507
 
22508
@smallexample
22509
cd gdb
22510
make gdb.info
22511
@end smallexample
22512
 
22513
If you want to typeset and print copies of this manual, you need @TeX{},
22514
a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
22515
Texinfo definitions file.
22516
 
22517
@TeX{} is a typesetting program; it does not print files directly, but
22518
produces output files called @sc{dvi} files.  To print a typeset
22519
document, you need a program to print @sc{dvi} files.  If your system
22520
has @TeX{} installed, chances are it has such a program.  The precise
22521
command to use depends on your system; @kbd{lpr -d} is common; another
22522
(for PostScript devices) is @kbd{dvips}.  The @sc{dvi} print command may
22523
require a file name without any extension or a @samp{.dvi} extension.
22524
 
22525
@TeX{} also requires a macro definitions file called
22526
@file{texinfo.tex}.  This file tells @TeX{} how to typeset a document
22527
written in Texinfo format.  On its own, @TeX{} cannot either read or
22528
typeset a Texinfo file.  @file{texinfo.tex} is distributed with GDB
22529
and is located in the @file{gdb-@var{version-number}/texinfo}
22530
directory.
22531
 
22532
If you have @TeX{} and a @sc{dvi} printer program installed, you can
22533
typeset and print this manual.  First switch to the @file{gdb}
22534
subdirectory of the main source directory (for example, to
22535
@file{gdb-@value{GDBVN}/gdb}) and type:
22536
 
22537
@smallexample
22538
make gdb.dvi
22539
@end smallexample
22540
 
22541
Then give @file{gdb.dvi} to your @sc{dvi} printing program.
22542
 
22543
@node Installing GDB
22544
@appendix Installing @value{GDBN}
22545
@cindex installation
22546
 
22547
@menu
22548
* Requirements::                Requirements for building @value{GDBN}
22549
* Running Configure::           Invoking the @value{GDBN} @file{configure} script
22550
* Separate Objdir::             Compiling @value{GDBN} in another directory
22551
* Config Names::                Specifying names for hosts and targets
22552
* Configure Options::           Summary of options for configure
22553
@end menu
22554
 
22555
@node Requirements
22556
@section Requirements for Building @value{GDBN}
22557
@cindex building @value{GDBN}, requirements for
22558
 
22559
Building @value{GDBN} requires various tools and packages to be available.
22560
Other packages will be used only if they are found.
22561
 
22562
@heading Tools/Packages Necessary for Building @value{GDBN}
22563
@table @asis
22564
@item ISO C90 compiler
22565
@value{GDBN} is written in ISO C90.  It should be buildable with any
22566
working C90 compiler, e.g.@: GCC.
22567
 
22568
@end table
22569
 
22570
@heading Tools/Packages Optional for Building @value{GDBN}
22571
@table @asis
22572
@item Expat
22573
@anchor{Expat}
22574
@value{GDBN} can use the Expat XML parsing library.  This library may be
22575
included with your operating system distribution; if it is not, you
22576
can get the latest version from @url{http://expat.sourceforge.net}.
22577
The @file{configure} script will search for this library in several
22578
standard locations; if it is installed in an unusual path, you can
22579
use the @option{--with-libexpat-prefix} option to specify its location.
22580
 
22581
Expat is used for:
22582
 
22583
@itemize @bullet
22584
@item
22585
Remote protocol memory maps (@pxref{Memory Map Format})
22586
@item
22587
Target descriptions (@pxref{Target Descriptions})
22588
@item
22589
Remote shared library lists (@pxref{Library List Format})
22590
@item
22591
MS-Windows shared libraries (@pxref{Shared Libraries})
22592
@end itemize
22593
 
22594
@end table
22595
 
22596
@node Running Configure
22597
@section Invoking the @value{GDBN} @file{configure} Script
22598
@cindex configuring @value{GDBN}
22599
@value{GDBN} comes with a @file{configure} script that automates the process
22600
of preparing @value{GDBN} for installation; you can then use @code{make} to
22601
build the @code{gdb} program.
22602
@iftex
22603
@c irrelevant in info file; it's as current as the code it lives with.
22604
@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
22605
look at the @file{README} file in the sources; we may have improved the
22606
installation procedures since publishing this manual.}
22607
@end iftex
22608
 
22609
The @value{GDBN} distribution includes all the source code you need for
22610
@value{GDBN} in a single directory, whose name is usually composed by
22611
appending the version number to @samp{gdb}.
22612
 
22613
For example, the @value{GDBN} version @value{GDBVN} distribution is in the
22614
@file{gdb-@value{GDBVN}} directory.  That directory contains:
22615
 
22616
@table @code
22617
@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
22618
script for configuring @value{GDBN} and all its supporting libraries
22619
 
22620
@item gdb-@value{GDBVN}/gdb
22621
the source specific to @value{GDBN} itself
22622
 
22623
@item gdb-@value{GDBVN}/bfd
22624
source for the Binary File Descriptor library
22625
 
22626
@item gdb-@value{GDBVN}/include
22627
@sc{gnu} include files
22628
 
22629
@item gdb-@value{GDBVN}/libiberty
22630
source for the @samp{-liberty} free software library
22631
 
22632
@item gdb-@value{GDBVN}/opcodes
22633
source for the library of opcode tables and disassemblers
22634
 
22635
@item gdb-@value{GDBVN}/readline
22636
source for the @sc{gnu} command-line interface
22637
 
22638
@item gdb-@value{GDBVN}/glob
22639
source for the @sc{gnu} filename pattern-matching subroutine
22640
 
22641
@item gdb-@value{GDBVN}/mmalloc
22642
source for the @sc{gnu} memory-mapped malloc package
22643
@end table
22644
 
22645
The simplest way to configure and build @value{GDBN} is to run @file{configure}
22646
from the @file{gdb-@var{version-number}} source directory, which in
22647
this example is the @file{gdb-@value{GDBVN}} directory.
22648
 
22649
First switch to the @file{gdb-@var{version-number}} source directory
22650
if you are not already in it; then run @file{configure}.  Pass the
22651
identifier for the platform on which @value{GDBN} will run as an
22652
argument.
22653
 
22654
For example:
22655
 
22656
@smallexample
22657
cd gdb-@value{GDBVN}
22658
./configure @var{host}
22659
make
22660
@end smallexample
22661
 
22662
@noindent
22663
where @var{host} is an identifier such as @samp{sun4} or
22664
@samp{decstation}, that identifies the platform where @value{GDBN} will run.
22665
(You can often leave off @var{host}; @file{configure} tries to guess the
22666
correct value by examining your system.)
22667
 
22668
Running @samp{configure @var{host}} and then running @code{make} builds the
22669
@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
22670
libraries, then @code{gdb} itself.  The configured source files, and the
22671
binaries, are left in the corresponding source directories.
22672
 
22673
@need 750
22674
@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
22675
system does not recognize this automatically when you run a different
22676
shell, you may need to run @code{sh} on it explicitly:
22677
 
22678
@smallexample
22679
sh configure @var{host}
22680
@end smallexample
22681
 
22682
If you run @file{configure} from a directory that contains source
22683
directories for multiple libraries or programs, such as the
22684
@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
22685
@file{configure}
22686
creates configuration files for every directory level underneath (unless
22687
you tell it not to, with the @samp{--norecursion} option).
22688
 
22689
You should run the @file{configure} script from the top directory in the
22690
source tree, the @file{gdb-@var{version-number}} directory.  If you run
22691
@file{configure} from one of the subdirectories, you will configure only
22692
that subdirectory.  That is usually not what you want.  In particular,
22693
if you run the first @file{configure} from the @file{gdb} subdirectory
22694
of the @file{gdb-@var{version-number}} directory, you will omit the
22695
configuration of @file{bfd}, @file{readline}, and other sibling
22696
directories of the @file{gdb} subdirectory.  This leads to build errors
22697
about missing include files such as @file{bfd/bfd.h}.
22698
 
22699
You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
22700
However, you should make sure that the shell on your path (named by
22701
the @samp{SHELL} environment variable) is publicly readable.  Remember
22702
that @value{GDBN} uses the shell to start your program---some systems refuse to
22703
let @value{GDBN} debug child processes whose programs are not readable.
22704
 
22705
@node Separate Objdir
22706
@section Compiling @value{GDBN} in Another Directory
22707
 
22708
If you want to run @value{GDBN} versions for several host or target machines,
22709
you need a different @code{gdb} compiled for each combination of
22710
host and target.  @file{configure} is designed to make this easy by
22711
allowing you to generate each configuration in a separate subdirectory,
22712
rather than in the source directory.  If your @code{make} program
22713
handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
22714
@code{make} in each of these directories builds the @code{gdb}
22715
program specified there.
22716
 
22717
To build @code{gdb} in a separate directory, run @file{configure}
22718
with the @samp{--srcdir} option to specify where to find the source.
22719
(You also need to specify a path to find @file{configure}
22720
itself from your working directory.  If the path to @file{configure}
22721
would be the same as the argument to @samp{--srcdir}, you can leave out
22722
the @samp{--srcdir} option; it is assumed.)
22723
 
22724
For example, with version @value{GDBVN}, you can build @value{GDBN} in a
22725
separate directory for a Sun 4 like this:
22726
 
22727
@smallexample
22728
@group
22729
cd gdb-@value{GDBVN}
22730
mkdir ../gdb-sun4
22731
cd ../gdb-sun4
22732
../gdb-@value{GDBVN}/configure sun4
22733
make
22734
@end group
22735
@end smallexample
22736
 
22737
When @file{configure} builds a configuration using a remote source
22738
directory, it creates a tree for the binaries with the same structure
22739
(and using the same names) as the tree under the source directory.  In
22740
the example, you'd find the Sun 4 library @file{libiberty.a} in the
22741
directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
22742
@file{gdb-sun4/gdb}.
22743
 
22744
Make sure that your path to the @file{configure} script has just one
22745
instance of @file{gdb} in it.  If your path to @file{configure} looks
22746
like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
22747
one subdirectory of @value{GDBN}, not the whole package.  This leads to
22748
build errors about missing include files such as @file{bfd/bfd.h}.
22749
 
22750
One popular reason to build several @value{GDBN} configurations in separate
22751
directories is to configure @value{GDBN} for cross-compiling (where
22752
@value{GDBN} runs on one machine---the @dfn{host}---while debugging
22753
programs that run on another machine---the @dfn{target}).
22754
You specify a cross-debugging target by
22755
giving the @samp{--target=@var{target}} option to @file{configure}.
22756
 
22757
When you run @code{make} to build a program or library, you must run
22758
it in a configured directory---whatever directory you were in when you
22759
called @file{configure} (or one of its subdirectories).
22760
 
22761
The @code{Makefile} that @file{configure} generates in each source
22762
directory also runs recursively.  If you type @code{make} in a source
22763
directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
22764
directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
22765
will build all the required libraries, and then build GDB.
22766
 
22767
When you have multiple hosts or targets configured in separate
22768
directories, you can run @code{make} on them in parallel (for example,
22769
if they are NFS-mounted on each of the hosts); they will not interfere
22770
with each other.
22771
 
22772
@node Config Names
22773
@section Specifying Names for Hosts and Targets
22774
 
22775
The specifications used for hosts and targets in the @file{configure}
22776
script are based on a three-part naming scheme, but some short predefined
22777
aliases are also supported.  The full naming scheme encodes three pieces
22778
of information in the following pattern:
22779
 
22780
@smallexample
22781
@var{architecture}-@var{vendor}-@var{os}
22782
@end smallexample
22783
 
22784
For example, you can use the alias @code{sun4} as a @var{host} argument,
22785
or as the value for @var{target} in a @code{--target=@var{target}}
22786
option.  The equivalent full name is @samp{sparc-sun-sunos4}.
22787
 
22788
The @file{configure} script accompanying @value{GDBN} does not provide
22789
any query facility to list all supported host and target names or
22790
aliases.  @file{configure} calls the Bourne shell script
22791
@code{config.sub} to map abbreviations to full names; you can read the
22792
script, if you wish, or you can use it to test your guesses on
22793
abbreviations---for example:
22794
 
22795
@smallexample
22796
% sh config.sub i386-linux
22797
i386-pc-linux-gnu
22798
% sh config.sub alpha-linux
22799
alpha-unknown-linux-gnu
22800
% sh config.sub hp9k700
22801
hppa1.1-hp-hpux
22802
% sh config.sub sun4
22803
sparc-sun-sunos4.1.1
22804
% sh config.sub sun3
22805
m68k-sun-sunos4.1.1
22806
% sh config.sub i986v
22807
Invalid configuration `i986v': machine `i986v' not recognized
22808
@end smallexample
22809
 
22810
@noindent
22811
@code{config.sub} is also distributed in the @value{GDBN} source
22812
directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
22813
 
22814
@node Configure Options
22815
@section @file{configure} Options
22816
 
22817
Here is a summary of the @file{configure} options and arguments that
22818
are most often useful for building @value{GDBN}.  @file{configure} also has
22819
several other options not listed here.  @inforef{What Configure
22820
Does,,configure.info}, for a full explanation of @file{configure}.
22821
 
22822
@smallexample
22823
configure @r{[}--help@r{]}
22824
          @r{[}--prefix=@var{dir}@r{]}
22825
          @r{[}--exec-prefix=@var{dir}@r{]}
22826
          @r{[}--srcdir=@var{dirname}@r{]}
22827
          @r{[}--norecursion@r{]} @r{[}--rm@r{]}
22828
          @r{[}--target=@var{target}@r{]}
22829
          @var{host}
22830
@end smallexample
22831
 
22832
@noindent
22833
You may introduce options with a single @samp{-} rather than
22834
@samp{--} if you prefer; but you may abbreviate option names if you use
22835
@samp{--}.
22836
 
22837
@table @code
22838
@item --help
22839
Display a quick summary of how to invoke @file{configure}.
22840
 
22841
@item --prefix=@var{dir}
22842
Configure the source to install programs and files under directory
22843
@file{@var{dir}}.
22844
 
22845
@item --exec-prefix=@var{dir}
22846
Configure the source to install programs under directory
22847
@file{@var{dir}}.
22848
 
22849
@c avoid splitting the warning from the explanation:
22850
@need 2000
22851
@item --srcdir=@var{dirname}
22852
@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
22853
@code{make} that implements the @code{VPATH} feature.}@*
22854
Use this option to make configurations in directories separate from the
22855
@value{GDBN} source directories.  Among other things, you can use this to
22856
build (or maintain) several configurations simultaneously, in separate
22857
directories.  @file{configure} writes configuration-specific files in
22858
the current directory, but arranges for them to use the source in the
22859
directory @var{dirname}.  @file{configure} creates directories under
22860
the working directory in parallel to the source directories below
22861
@var{dirname}.
22862
 
22863
@item --norecursion
22864
Configure only the directory level where @file{configure} is executed; do not
22865
propagate configuration to subdirectories.
22866
 
22867
@item --target=@var{target}
22868
Configure @value{GDBN} for cross-debugging programs running on the specified
22869
@var{target}.  Without this option, @value{GDBN} is configured to debug
22870
programs that run on the same machine (@var{host}) as @value{GDBN} itself.
22871
 
22872
There is no convenient way to generate a list of all available targets.
22873
 
22874
@item @var{host} @dots{}
22875
Configure @value{GDBN} to run on the specified @var{host}.
22876
 
22877
There is no convenient way to generate a list of all available hosts.
22878
@end table
22879
 
22880
There are many other options available as well, but they are generally
22881
needed for special purposes only.
22882
 
22883
@node Maintenance Commands
22884
@appendix Maintenance Commands
22885
@cindex maintenance commands
22886
@cindex internal commands
22887
 
22888
In addition to commands intended for @value{GDBN} users, @value{GDBN}
22889
includes a number of commands intended for @value{GDBN} developers,
22890
that are not documented elsewhere in this manual.  These commands are
22891
provided here for reference.  (For commands that turn on debugging
22892
messages, see @ref{Debugging Output}.)
22893
 
22894
@table @code
22895
@kindex maint agent
22896
@item maint agent @var{expression}
22897
Translate the given @var{expression} into remote agent bytecodes.
22898
This command is useful for debugging the Agent Expression mechanism
22899
(@pxref{Agent Expressions}).
22900
 
22901
@kindex maint info breakpoints
22902
@item @anchor{maint info breakpoints}maint info breakpoints
22903
Using the same format as @samp{info breakpoints}, display both the
22904
breakpoints you've set explicitly, and those @value{GDBN} is using for
22905
internal purposes.  Internal breakpoints are shown with negative
22906
breakpoint numbers.  The type column identifies what kind of breakpoint
22907
is shown:
22908
 
22909
@table @code
22910
@item breakpoint
22911
Normal, explicitly set breakpoint.
22912
 
22913
@item watchpoint
22914
Normal, explicitly set watchpoint.
22915
 
22916
@item longjmp
22917
Internal breakpoint, used to handle correctly stepping through
22918
@code{longjmp} calls.
22919
 
22920
@item longjmp resume
22921
Internal breakpoint at the target of a @code{longjmp}.
22922
 
22923
@item until
22924
Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
22925
 
22926
@item finish
22927
Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
22928
 
22929
@item shlib events
22930
Shared library events.
22931
 
22932
@end table
22933
 
22934
@kindex maint check-symtabs
22935
@item maint check-symtabs
22936
Check the consistency of psymtabs and symtabs.
22937
 
22938
@kindex maint cplus first_component
22939
@item maint cplus first_component @var{name}
22940
Print the first C@t{++} class/namespace component of @var{name}.
22941
 
22942
@kindex maint cplus namespace
22943
@item maint cplus namespace
22944
Print the list of possible C@t{++} namespaces.
22945
 
22946
@kindex maint demangle
22947
@item maint demangle @var{name}
22948
Demangle a C@t{++} or Objective-C mangled @var{name}.
22949
 
22950
@kindex maint deprecate
22951
@kindex maint undeprecate
22952
@cindex deprecated commands
22953
@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
22954
@itemx maint undeprecate @var{command}
22955
Deprecate or undeprecate the named @var{command}.  Deprecated commands
22956
cause @value{GDBN} to issue a warning when you use them.  The optional
22957
argument @var{replacement} says which newer command should be used in
22958
favor of the deprecated one; if it is given, @value{GDBN} will mention
22959
the replacement as part of the warning.
22960
 
22961
@kindex maint dump-me
22962
@item maint dump-me
22963
@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
22964
Cause a fatal signal in the debugger and force it to dump its core.
22965
This is supported only on systems which support aborting a program
22966
with the @code{SIGQUIT} signal.
22967
 
22968
@kindex maint internal-error
22969
@kindex maint internal-warning
22970
@item maint internal-error @r{[}@var{message-text}@r{]}
22971
@itemx maint internal-warning @r{[}@var{message-text}@r{]}
22972
Cause @value{GDBN} to call the internal function @code{internal_error}
22973
or @code{internal_warning} and hence behave as though an internal error
22974
or internal warning has been detected.  In addition to reporting the
22975
internal problem, these functions give the user the opportunity to
22976
either quit @value{GDBN} or create a core file of the current
22977
@value{GDBN} session.
22978
 
22979
These commands take an optional parameter @var{message-text} that is
22980
used as the text of the error or warning message.
22981
 
22982
Here's an example of using @code{internal-error}:
22983
 
22984
@smallexample
22985
(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
22986
@dots{}/maint.c:121: internal-error: testing, 1, 2
22987
A problem internal to GDB has been detected.  Further
22988
debugging may prove unreliable.
22989
Quit this debugging session? (y or n) @kbd{n}
22990
Create a core file? (y or n) @kbd{n}
22991
(@value{GDBP})
22992
@end smallexample
22993
 
22994
@kindex maint packet
22995
@item maint packet @var{text}
22996
If @value{GDBN} is talking to an inferior via the serial protocol,
22997
then this command sends the string @var{text} to the inferior, and
22998
displays the response packet.  @value{GDBN} supplies the initial
22999
@samp{$} character, the terminating @samp{#} character, and the
23000
checksum.
23001
 
23002
@kindex maint print architecture
23003
@item maint print architecture @r{[}@var{file}@r{]}
23004
Print the entire architecture configuration.  The optional argument
23005
@var{file} names the file where the output goes.
23006
 
23007
@kindex maint print c-tdesc
23008
@item maint print c-tdesc
23009
Print the current target description (@pxref{Target Descriptions}) as
23010
a C source file.  The created source file can be used in @value{GDBN}
23011
when an XML parser is not available to parse the description.
23012
 
23013
@kindex maint print dummy-frames
23014
@item maint print dummy-frames
23015
Prints the contents of @value{GDBN}'s internal dummy-frame stack.
23016
 
23017
@smallexample
23018
(@value{GDBP}) @kbd{b add}
23019
@dots{}
23020
(@value{GDBP}) @kbd{print add(2,3)}
23021
Breakpoint 2, add (a=2, b=3) at @dots{}
23022
58        return (a + b);
23023
The program being debugged stopped while in a function called from GDB.
23024
@dots{}
23025
(@value{GDBP}) @kbd{maint print dummy-frames}
23026
0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
23027
 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
23028
 call_lo=0x01014000 call_hi=0x01014001
23029
(@value{GDBP})
23030
@end smallexample
23031
 
23032
Takes an optional file parameter.
23033
 
23034
@kindex maint print registers
23035
@kindex maint print raw-registers
23036
@kindex maint print cooked-registers
23037
@kindex maint print register-groups
23038
@item maint print registers @r{[}@var{file}@r{]}
23039
@itemx maint print raw-registers @r{[}@var{file}@r{]}
23040
@itemx maint print cooked-registers @r{[}@var{file}@r{]}
23041
@itemx maint print register-groups @r{[}@var{file}@r{]}
23042
Print @value{GDBN}'s internal register data structures.
23043
 
23044
The command @code{maint print raw-registers} includes the contents of
23045
the raw register cache; the command @code{maint print cooked-registers}
23046
includes the (cooked) value of all registers; and the command
23047
@code{maint print register-groups} includes the groups that each
23048
register is a member of.  @xref{Registers,, Registers, gdbint,
23049
@value{GDBN} Internals}.
23050
 
23051
These commands take an optional parameter, a file name to which to
23052
write the information.
23053
 
23054
@kindex maint print reggroups
23055
@item maint print reggroups @r{[}@var{file}@r{]}
23056
Print @value{GDBN}'s internal register group data structures.  The
23057
optional argument @var{file} tells to what file to write the
23058
information.
23059
 
23060
The register groups info looks like this:
23061
 
23062
@smallexample
23063
(@value{GDBP}) @kbd{maint print reggroups}
23064
 Group      Type
23065
 general    user
23066
 float      user
23067
 all        user
23068
 vector     user
23069
 system     user
23070
 save       internal
23071
 restore    internal
23072
@end smallexample
23073
 
23074
@kindex flushregs
23075
@item flushregs
23076
This command forces @value{GDBN} to flush its internal register cache.
23077
 
23078
@kindex maint print objfiles
23079
@cindex info for known object files
23080
@item maint print objfiles
23081
Print a dump of all known object files.  For each object file, this
23082
command prints its name, address in memory, and all of its psymtabs
23083
and symtabs.
23084
 
23085
@kindex maint print statistics
23086
@cindex bcache statistics
23087
@item maint print statistics
23088
This command prints, for each object file in the program, various data
23089
about that object file followed by the byte cache (@dfn{bcache})
23090
statistics for the object file.  The objfile data includes the number
23091
of minimal, partial, full, and stabs symbols, the number of types
23092
defined by the objfile, the number of as yet unexpanded psym tables,
23093
the number of line tables and string tables, and the amount of memory
23094
used by the various tables.  The bcache statistics include the counts,
23095
sizes, and counts of duplicates of all and unique objects, max,
23096
average, and median entry size, total memory used and its overhead and
23097
savings, and various measures of the hash table size and chain
23098
lengths.
23099
 
23100
@kindex maint print target-stack
23101
@cindex target stack description
23102
@item maint print target-stack
23103
A @dfn{target} is an interface between the debugger and a particular
23104
kind of file or process.  Targets can be stacked in @dfn{strata},
23105
so that more than one target can potentially respond to a request.
23106
In particular, memory accesses will walk down the stack of targets
23107
until they find a target that is interested in handling that particular
23108
address.
23109
 
23110
This command prints a short description of each layer that was pushed on
23111
the @dfn{target stack}, starting from the top layer down to the bottom one.
23112
 
23113
@kindex maint print type
23114
@cindex type chain of a data type
23115
@item maint print type @var{expr}
23116
Print the type chain for a type specified by @var{expr}.  The argument
23117
can be either a type name or a symbol.  If it is a symbol, the type of
23118
that symbol is described.  The type chain produced by this command is
23119
a recursive definition of the data type as stored in @value{GDBN}'s
23120
data structures, including its flags and contained types.
23121
 
23122
@kindex maint set dwarf2 max-cache-age
23123
@kindex maint show dwarf2 max-cache-age
23124
@item maint set dwarf2 max-cache-age
23125
@itemx maint show dwarf2 max-cache-age
23126
Control the DWARF 2 compilation unit cache.
23127
 
23128
@cindex DWARF 2 compilation units cache
23129
In object files with inter-compilation-unit references, such as those
23130
produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
23131
reader needs to frequently refer to previously read compilation units.
23132
This setting controls how long a compilation unit will remain in the
23133
cache if it is not referenced.  A higher limit means that cached
23134
compilation units will be stored in memory longer, and more total
23135
memory will be used.  Setting it to zero disables caching, which will
23136
slow down @value{GDBN} startup, but reduce memory consumption.
23137
 
23138
@kindex maint set profile
23139
@kindex maint show profile
23140
@cindex profiling GDB
23141
@item maint set profile
23142
@itemx maint show profile
23143
Control profiling of @value{GDBN}.
23144
 
23145
Profiling will be disabled until you use the @samp{maint set profile}
23146
command to enable it.  When you enable profiling, the system will begin
23147
collecting timing and execution count data; when you disable profiling or
23148
exit @value{GDBN}, the results will be written to a log file.  Remember that
23149
if you use profiling, @value{GDBN} will overwrite the profiling log file
23150
(often called @file{gmon.out}).  If you have a record of important profiling
23151
data in a @file{gmon.out} file, be sure to move it to a safe location.
23152
 
23153
Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
23154
compiled with the @samp{-pg} compiler option.
23155
 
23156
@kindex maint show-debug-regs
23157
@cindex x86 hardware debug registers
23158
@item maint show-debug-regs
23159
Control whether to show variables that mirror the x86 hardware debug
23160
registers.  Use @code{ON} to enable, @code{OFF} to disable.  If
23161
enabled, the debug registers values are shown when @value{GDBN} inserts or
23162
removes a hardware breakpoint or watchpoint, and when the inferior
23163
triggers a hardware-assisted breakpoint or watchpoint.
23164
 
23165
@kindex maint space
23166
@cindex memory used by commands
23167
@item maint space
23168
Control whether to display memory usage for each command.  If set to a
23169
nonzero value, @value{GDBN} will display how much memory each command
23170
took, following the command's own output.  This can also be requested
23171
by invoking @value{GDBN} with the @option{--statistics} command-line
23172
switch (@pxref{Mode Options}).
23173
 
23174
@kindex maint time
23175
@cindex time of command execution
23176
@item maint time
23177
Control whether to display the execution time for each command.  If
23178
set to a nonzero value, @value{GDBN} will display how much time it
23179
took to execute each command, following the command's own output.
23180
This can also be requested by invoking @value{GDBN} with the
23181
@option{--statistics} command-line switch (@pxref{Mode Options}).
23182
 
23183
@kindex maint translate-address
23184
@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
23185
Find the symbol stored at the location specified by the address
23186
@var{addr} and an optional section name @var{section}.  If found,
23187
@value{GDBN} prints the name of the closest symbol and an offset from
23188
the symbol's location to the specified address.  This is similar to
23189
the @code{info address} command (@pxref{Symbols}), except that this
23190
command also allows to find symbols in other sections.
23191
 
23192
@end table
23193
 
23194
The following command is useful for non-interactive invocations of
23195
@value{GDBN}, such as in the test suite.
23196
 
23197
@table @code
23198
@item set watchdog @var{nsec}
23199
@kindex set watchdog
23200
@cindex watchdog timer
23201
@cindex timeout for commands
23202
Set the maximum number of seconds @value{GDBN} will wait for the
23203
target operation to finish.  If this time expires, @value{GDBN}
23204
reports and error and the command is aborted.
23205
 
23206
@item show watchdog
23207
Show the current setting of the target wait timeout.
23208
@end table
23209
 
23210
@node Remote Protocol
23211
@appendix @value{GDBN} Remote Serial Protocol
23212
 
23213
@menu
23214
* Overview::
23215
* Packets::
23216
* Stop Reply Packets::
23217
* General Query Packets::
23218
* Register Packet Format::
23219
* Tracepoint Packets::
23220
* Host I/O Packets::
23221
* Interrupts::
23222
* Examples::
23223
* File-I/O Remote Protocol Extension::
23224
* Library List Format::
23225
* Memory Map Format::
23226
@end menu
23227
 
23228
@node Overview
23229
@section Overview
23230
 
23231
There may be occasions when you need to know something about the
23232
protocol---for example, if there is only one serial port to your target
23233
machine, you might want your program to do something special if it
23234
recognizes a packet meant for @value{GDBN}.
23235
 
23236
In the examples below, @samp{->} and @samp{<-} are used to indicate
23237
transmitted and received data, respectively.
23238
 
23239
@cindex protocol, @value{GDBN} remote serial
23240
@cindex serial protocol, @value{GDBN} remote
23241
@cindex remote serial protocol
23242
All @value{GDBN} commands and responses (other than acknowledgments) are
23243
sent as a @var{packet}.  A @var{packet} is introduced with the character
23244
@samp{$}, the actual @var{packet-data}, and the terminating character
23245
@samp{#} followed by a two-digit @var{checksum}:
23246
 
23247
@smallexample
23248
@code{$}@var{packet-data}@code{#}@var{checksum}
23249
@end smallexample
23250
@noindent
23251
 
23252
@cindex checksum, for @value{GDBN} remote
23253
@noindent
23254
The two-digit @var{checksum} is computed as the modulo 256 sum of all
23255
characters between the leading @samp{$} and the trailing @samp{#} (an
23256
eight bit unsigned checksum).
23257
 
23258
Implementors should note that prior to @value{GDBN} 5.0 the protocol
23259
specification also included an optional two-digit @var{sequence-id}:
23260
 
23261
@smallexample
23262
@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
23263
@end smallexample
23264
 
23265
@cindex sequence-id, for @value{GDBN} remote
23266
@noindent
23267
That @var{sequence-id} was appended to the acknowledgment.  @value{GDBN}
23268
has never output @var{sequence-id}s.  Stubs that handle packets added
23269
since @value{GDBN} 5.0 must not accept @var{sequence-id}.
23270
 
23271
@cindex acknowledgment, for @value{GDBN} remote
23272
When either the host or the target machine receives a packet, the first
23273
response expected is an acknowledgment: either @samp{+} (to indicate
23274
the package was received correctly) or @samp{-} (to request
23275
retransmission):
23276
 
23277
@smallexample
23278
-> @code{$}@var{packet-data}@code{#}@var{checksum}
23279
<- @code{+}
23280
@end smallexample
23281
@noindent
23282
 
23283
The host (@value{GDBN}) sends @var{command}s, and the target (the
23284
debugging stub incorporated in your program) sends a @var{response}.  In
23285
the case of step and continue @var{command}s, the response is only sent
23286
when the operation has completed (the target has again stopped).
23287
 
23288
@var{packet-data} consists of a sequence of characters with the
23289
exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
23290
exceptions).
23291
 
23292
@cindex remote protocol, field separator
23293
Fields within the packet should be separated using @samp{,} @samp{;} or
23294
@samp{:}.  Except where otherwise noted all numbers are represented in
23295
@sc{hex} with leading zeros suppressed.
23296
 
23297
Implementors should note that prior to @value{GDBN} 5.0, the character
23298
@samp{:} could not appear as the third character in a packet (as it
23299
would potentially conflict with the @var{sequence-id}).
23300
 
23301
@cindex remote protocol, binary data
23302
@anchor{Binary Data}
23303
Binary data in most packets is encoded either as two hexadecimal
23304
digits per byte of binary data.  This allowed the traditional remote
23305
protocol to work over connections which were only seven-bit clean.
23306
Some packets designed more recently assume an eight-bit clean
23307
connection, and use a more efficient encoding to send and receive
23308
binary data.
23309
 
23310
The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
23311
as an escape character.  Any escaped byte is transmitted as the escape
23312
character followed by the original character XORed with @code{0x20}.
23313
For example, the byte @code{0x7d} would be transmitted as the two
23314
bytes @code{0x7d 0x5d}.  The bytes @code{0x23} (@sc{ascii} @samp{#}),
23315
@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
23316
@samp{@}}) must always be escaped.  Responses sent by the stub
23317
must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
23318
is not interpreted as the start of a run-length encoded sequence
23319
(described next).
23320
 
23321
Response @var{data} can be run-length encoded to save space.
23322
Run-length encoding replaces runs of identical characters with one
23323
instance of the repeated character, followed by a @samp{*} and a
23324
repeat count.  The repeat count is itself sent encoded, to avoid
23325
binary characters in @var{data}: a value of @var{n} is sent as
23326
@code{@var{n}+29}.  For a repeat count greater or equal to 3, this
23327
produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
23328
code 32) for a repeat count of 3.  (This is because run-length
23329
encoding starts to win for counts 3 or more.)  Thus, for example,
23330
@samp{0* } is a run-length encoding of ``0000'': the space character
23331
after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
23332
3}} more times.
23333
 
23334
The printable characters @samp{#} and @samp{$} or with a numeric value
23335
greater than 126 must not be used.  Runs of six repeats (@samp{#}) or
23336
seven repeats (@samp{$}) can be expanded using a repeat count of only
23337
five (@samp{"}).  For example, @samp{00000000} can be encoded as
23338
@samp{0*"00}.
23339
 
23340
The error response returned for some packets includes a two character
23341
error number.  That number is not well defined.
23342
 
23343
@cindex empty response, for unsupported packets
23344
For any @var{command} not supported by the stub, an empty response
23345
(@samp{$#00}) should be returned.  That way it is possible to extend the
23346
protocol.  A newer @value{GDBN} can tell if a packet is supported based
23347
on that response.
23348
 
23349
A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
23350
@samp{c}, and @samp{s} @var{command}s.  All other @var{command}s are
23351
optional.
23352
 
23353
@node Packets
23354
@section Packets
23355
 
23356
The following table provides a complete list of all currently defined
23357
@var{command}s and their corresponding response @var{data}.
23358
@xref{File-I/O Remote Protocol Extension}, for details about the File
23359
I/O extension of the remote protocol.
23360
 
23361
Each packet's description has a template showing the packet's overall
23362
syntax, followed by an explanation of the packet's meaning.  We
23363
include spaces in some of the templates for clarity; these are not
23364
part of the packet's syntax.  No @value{GDBN} packet uses spaces to
23365
separate its components.  For example, a template like @samp{foo
23366
@var{bar} @var{baz}} describes a packet beginning with the three ASCII
23367
bytes @samp{foo}, followed by a @var{bar}, followed directly by a
23368
@var{baz}.  @value{GDBN} does not transmit a space character between the
23369
@samp{foo} and the @var{bar}, or between the @var{bar} and the
23370
@var{baz}.
23371
 
23372
Note that all packet forms beginning with an upper- or lower-case
23373
letter, other than those described here, are reserved for future use.
23374
 
23375
Here are the packet descriptions.
23376
 
23377
@table @samp
23378
 
23379
@item !
23380
@cindex @samp{!} packet
23381
@anchor{extended mode}
23382
Enable extended mode.  In extended mode, the remote server is made
23383
persistent.  The @samp{R} packet is used to restart the program being
23384
debugged.
23385
 
23386
Reply:
23387
@table @samp
23388
@item OK
23389
The remote target both supports and has enabled extended mode.
23390
@end table
23391
 
23392
@item ?
23393
@cindex @samp{?} packet
23394
Indicate the reason the target halted.  The reply is the same as for
23395
step and continue.
23396
 
23397
Reply:
23398
@xref{Stop Reply Packets}, for the reply specifications.
23399
 
23400
@item A @var{arglen},@var{argnum},@var{arg},@dots{}
23401
@cindex @samp{A} packet
23402
Initialized @code{argv[]} array passed into program. @var{arglen}
23403
specifies the number of bytes in the hex encoded byte stream
23404
@var{arg}.  See @code{gdbserver} for more details.
23405
 
23406
Reply:
23407
@table @samp
23408
@item OK
23409
The arguments were set.
23410
@item E @var{NN}
23411
An error occurred.
23412
@end table
23413
 
23414
@item b @var{baud}
23415
@cindex @samp{b} packet
23416
(Don't use this packet; its behavior is not well-defined.)
23417
Change the serial line speed to @var{baud}.
23418
 
23419
JTC: @emph{When does the transport layer state change?  When it's
23420
received, or after the ACK is transmitted.  In either case, there are
23421
problems if the command or the acknowledgment packet is dropped.}
23422
 
23423
Stan: @emph{If people really wanted to add something like this, and get
23424
it working for the first time, they ought to modify ser-unix.c to send
23425
some kind of out-of-band message to a specially-setup stub and have the
23426
switch happen "in between" packets, so that from remote protocol's point
23427
of view, nothing actually happened.}
23428
 
23429
@item B @var{addr},@var{mode}
23430
@cindex @samp{B} packet
23431
Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
23432
breakpoint at @var{addr}.
23433
 
23434
Don't use this packet.  Use the @samp{Z} and @samp{z} packets instead
23435
(@pxref{insert breakpoint or watchpoint packet}).
23436
 
23437
@item c @r{[}@var{addr}@r{]}
23438
@cindex @samp{c} packet
23439
Continue.  @var{addr} is address to resume.  If @var{addr} is omitted,
23440
resume at current address.
23441
 
23442
Reply:
23443
@xref{Stop Reply Packets}, for the reply specifications.
23444
 
23445
@item C @var{sig}@r{[};@var{addr}@r{]}
23446
@cindex @samp{C} packet
23447
Continue with signal @var{sig} (hex signal number).  If
23448
@samp{;@var{addr}} is omitted, resume at same address.
23449
 
23450
Reply:
23451
@xref{Stop Reply Packets}, for the reply specifications.
23452
 
23453
@item d
23454
@cindex @samp{d} packet
23455
Toggle debug flag.
23456
 
23457
Don't use this packet; instead, define a general set packet
23458
(@pxref{General Query Packets}).
23459
 
23460
@item D
23461
@cindex @samp{D} packet
23462
Detach @value{GDBN} from the remote system.  Sent to the remote target
23463
before @value{GDBN} disconnects via the @code{detach} command.
23464
 
23465
Reply:
23466
@table @samp
23467
@item OK
23468
for success
23469
@item E @var{NN}
23470
for an error
23471
@end table
23472
 
23473
@item F @var{RC},@var{EE},@var{CF};@var{XX}
23474
@cindex @samp{F} packet
23475
A reply from @value{GDBN} to an @samp{F} packet sent by the target.
23476
This is part of the File-I/O protocol extension.  @xref{File-I/O
23477
Remote Protocol Extension}, for the specification.
23478
 
23479
@item g
23480
@anchor{read registers packet}
23481
@cindex @samp{g} packet
23482
Read general registers.
23483
 
23484
Reply:
23485
@table @samp
23486
@item @var{XX@dots{}}
23487
Each byte of register data is described by two hex digits.  The bytes
23488
with the register are transmitted in target byte order.  The size of
23489
each register and their position within the @samp{g} packet are
23490
determined by the @value{GDBN} internal gdbarch functions
23491
@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.  The
23492
specification of several standard @samp{g} packets is specified below.
23493
@item E @var{NN}
23494
for an error.
23495
@end table
23496
 
23497
@item G @var{XX@dots{}}
23498
@cindex @samp{G} packet
23499
Write general registers.  @xref{read registers packet}, for a
23500
description of the @var{XX@dots{}} data.
23501
 
23502
Reply:
23503
@table @samp
23504
@item OK
23505
for success
23506
@item E @var{NN}
23507
for an error
23508
@end table
23509
 
23510
@item H @var{c} @var{t}
23511
@cindex @samp{H} packet
23512
Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
23513
@samp{G}, et.al.).  @var{c} depends on the operation to be performed: it
23514
should be @samp{c} for step and continue operations, @samp{g} for other
23515
operations.  The thread designator @var{t} may be @samp{-1}, meaning all
23516
the threads, a thread number, or @samp{0} which means pick any thread.
23517
 
23518
Reply:
23519
@table @samp
23520
@item OK
23521
for success
23522
@item E @var{NN}
23523
for an error
23524
@end table
23525
 
23526
@c FIXME: JTC:
23527
@c   'H': How restrictive (or permissive) is the thread model.  If a
23528
@c        thread is selected and stopped, are other threads allowed
23529
@c        to continue to execute?  As I mentioned above, I think the
23530
@c        semantics of each command when a thread is selected must be
23531
@c        described.  For example:
23532
@c
23533
@c        'g':    If the stub supports threads and a specific thread is
23534
@c                selected, returns the register block from that thread;
23535
@c                otherwise returns current registers.
23536
@c
23537
@c        'G'     If the stub supports threads and a specific thread is
23538
@c                selected, sets the registers of the register block of
23539
@c                that thread; otherwise sets current registers.
23540
 
23541
@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
23542
@anchor{cycle step packet}
23543
@cindex @samp{i} packet
23544
Step the remote target by a single clock cycle.  If @samp{,@var{nnn}} is
23545
present, cycle step @var{nnn} cycles.  If @var{addr} is present, cycle
23546
step starting at that address.
23547
 
23548
@item I
23549
@cindex @samp{I} packet
23550
Signal, then cycle step.  @xref{step with signal packet}.  @xref{cycle
23551
step packet}.
23552
 
23553
@item k
23554
@cindex @samp{k} packet
23555
Kill request.
23556
 
23557
FIXME: @emph{There is no description of how to operate when a specific
23558
thread context has been selected (i.e.@: does 'k' kill only that
23559
thread?)}.
23560
 
23561
@item m @var{addr},@var{length}
23562
@cindex @samp{m} packet
23563
Read @var{length} bytes of memory starting at address @var{addr}.
23564
Note that @var{addr} may not be aligned to any particular boundary.
23565
 
23566
The stub need not use any particular size or alignment when gathering
23567
data from memory for the response; even if @var{addr} is word-aligned
23568
and @var{length} is a multiple of the word size, the stub is free to
23569
use byte accesses, or not.  For this reason, this packet may not be
23570
suitable for accessing memory-mapped I/O devices.
23571
@cindex alignment of remote memory accesses
23572
@cindex size of remote memory accesses
23573
@cindex memory, alignment and size of remote accesses
23574
 
23575
Reply:
23576
@table @samp
23577
@item @var{XX@dots{}}
23578
Memory contents; each byte is transmitted as a two-digit hexadecimal
23579
number.  The reply may contain fewer bytes than requested if the
23580
server was able to read only part of the region of memory.
23581
@item E @var{NN}
23582
@var{NN} is errno
23583
@end table
23584
 
23585
@item M @var{addr},@var{length}:@var{XX@dots{}}
23586
@cindex @samp{M} packet
23587
Write @var{length} bytes of memory starting at address @var{addr}.
23588
@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
23589
hexadecimal number.
23590
 
23591
Reply:
23592
@table @samp
23593
@item OK
23594
for success
23595
@item E @var{NN}
23596
for an error (this includes the case where only part of the data was
23597
written).
23598
@end table
23599
 
23600
@item p @var{n}
23601
@cindex @samp{p} packet
23602
Read the value of register @var{n}; @var{n} is in hex.
23603
@xref{read registers packet}, for a description of how the returned
23604
register value is encoded.
23605
 
23606
Reply:
23607
@table @samp
23608
@item @var{XX@dots{}}
23609
the register's value
23610
@item E @var{NN}
23611
for an error
23612
@item
23613
Indicating an unrecognized @var{query}.
23614
@end table
23615
 
23616
@item P @var{n@dots{}}=@var{r@dots{}}
23617
@anchor{write register packet}
23618
@cindex @samp{P} packet
23619
Write register @var{n@dots{}} with value @var{r@dots{}}.  The register
23620
number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
23621
digits for each byte in the register (target byte order).
23622
 
23623
Reply:
23624
@table @samp
23625
@item OK
23626
for success
23627
@item E @var{NN}
23628
for an error
23629
@end table
23630
 
23631
@item q @var{name} @var{params}@dots{}
23632
@itemx Q @var{name} @var{params}@dots{}
23633
@cindex @samp{q} packet
23634
@cindex @samp{Q} packet
23635
General query (@samp{q}) and set (@samp{Q}).  These packets are
23636
described fully in @ref{General Query Packets}.
23637
 
23638
@item r
23639
@cindex @samp{r} packet
23640
Reset the entire system.
23641
 
23642
Don't use this packet; use the @samp{R} packet instead.
23643
 
23644
@item R @var{XX}
23645
@cindex @samp{R} packet
23646
Restart the program being debugged.  @var{XX}, while needed, is ignored.
23647
This packet is only available in extended mode (@pxref{extended mode}).
23648
 
23649
The @samp{R} packet has no reply.
23650
 
23651
@item s @r{[}@var{addr}@r{]}
23652
@cindex @samp{s} packet
23653
Single step.  @var{addr} is the address at which to resume.  If
23654
@var{addr} is omitted, resume at same address.
23655
 
23656
Reply:
23657
@xref{Stop Reply Packets}, for the reply specifications.
23658
 
23659
@item S @var{sig}@r{[};@var{addr}@r{]}
23660
@anchor{step with signal packet}
23661
@cindex @samp{S} packet
23662
Step with signal.  This is analogous to the @samp{C} packet, but
23663
requests a single-step, rather than a normal resumption of execution.
23664
 
23665
Reply:
23666
@xref{Stop Reply Packets}, for the reply specifications.
23667
 
23668
@item t @var{addr}:@var{PP},@var{MM}
23669
@cindex @samp{t} packet
23670
Search backwards starting at address @var{addr} for a match with pattern
23671
@var{PP} and mask @var{MM}.  @var{PP} and @var{MM} are 4 bytes.
23672
@var{addr} must be at least 3 digits.
23673
 
23674
@item T @var{XX}
23675
@cindex @samp{T} packet
23676
Find out if the thread XX is alive.
23677
 
23678
Reply:
23679
@table @samp
23680
@item OK
23681
thread is still alive
23682
@item E @var{NN}
23683
thread is dead
23684
@end table
23685
 
23686
@item v
23687
Packets starting with @samp{v} are identified by a multi-letter name,
23688
up to the first @samp{;} or @samp{?} (or the end of the packet).
23689
 
23690
@item vAttach;@var{pid}
23691
@cindex @samp{vAttach} packet
23692
Attach to a new process with the specified process ID.  @var{pid} is a
23693
hexadecimal integer identifying the process.  The attached process is
23694
stopped.
23695
 
23696
This packet is only available in extended mode (@pxref{extended mode}).
23697
 
23698
Reply:
23699
@table @samp
23700
@item E @var{nn}
23701
for an error
23702
@item @r{Any stop packet}
23703
for success (@pxref{Stop Reply Packets})
23704
@end table
23705
 
23706
@item vCont@r{[};@var{action}@r{[}:@var{tid}@r{]]}@dots{}
23707
@cindex @samp{vCont} packet
23708
Resume the inferior, specifying different actions for each thread.
23709
If an action is specified with no @var{tid}, then it is applied to any
23710
threads that don't have a specific action specified; if no default action is
23711
specified then other threads should remain stopped.  Specifying multiple
23712
default actions is an error; specifying no actions is also an error.
23713
Thread IDs are specified in hexadecimal.  Currently supported actions are:
23714
 
23715
@table @samp
23716
@item c
23717
Continue.
23718
@item C @var{sig}
23719
Continue with signal @var{sig}.  @var{sig} should be two hex digits.
23720
@item s
23721
Step.
23722
@item S @var{sig}
23723
Step with signal @var{sig}.  @var{sig} should be two hex digits.
23724
@end table
23725
 
23726
The optional @var{addr} argument normally associated with these packets is
23727
not supported in @samp{vCont}.
23728
 
23729
Reply:
23730
@xref{Stop Reply Packets}, for the reply specifications.
23731
 
23732
@item vCont?
23733
@cindex @samp{vCont?} packet
23734
Request a list of actions supported by the @samp{vCont} packet.
23735
 
23736
Reply:
23737
@table @samp
23738
@item vCont@r{[};@var{action}@dots{}@r{]}
23739
The @samp{vCont} packet is supported.  Each @var{action} is a supported
23740
command in the @samp{vCont} packet.
23741
@item
23742
The @samp{vCont} packet is not supported.
23743
@end table
23744
 
23745
@item vFile:@var{operation}:@var{parameter}@dots{}
23746
@cindex @samp{vFile} packet
23747
Perform a file operation on the target system.  For details,
23748
see @ref{Host I/O Packets}.
23749
 
23750
@item vFlashErase:@var{addr},@var{length}
23751
@cindex @samp{vFlashErase} packet
23752
Direct the stub to erase @var{length} bytes of flash starting at
23753
@var{addr}.  The region may enclose any number of flash blocks, but
23754
its start and end must fall on block boundaries, as indicated by the
23755
flash block size appearing in the memory map (@pxref{Memory Map
23756
Format}).  @value{GDBN} groups flash memory programming operations
23757
together, and sends a @samp{vFlashDone} request after each group; the
23758
stub is allowed to delay erase operation until the @samp{vFlashDone}
23759
packet is received.
23760
 
23761
Reply:
23762
@table @samp
23763
@item OK
23764
for success
23765
@item E @var{NN}
23766
for an error
23767
@end table
23768
 
23769
@item vFlashWrite:@var{addr}:@var{XX@dots{}}
23770
@cindex @samp{vFlashWrite} packet
23771
Direct the stub to write data to flash address @var{addr}.  The data
23772
is passed in binary form using the same encoding as for the @samp{X}
23773
packet (@pxref{Binary Data}).  The memory ranges specified by
23774
@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
23775
not overlap, and must appear in order of increasing addresses
23776
(although @samp{vFlashErase} packets for higher addresses may already
23777
have been received; the ordering is guaranteed only between
23778
@samp{vFlashWrite} packets).  If a packet writes to an address that was
23779
neither erased by a preceding @samp{vFlashErase} packet nor by some other
23780
target-specific method, the results are unpredictable.
23781
 
23782
 
23783
Reply:
23784
@table @samp
23785
@item OK
23786
for success
23787
@item E.memtype
23788
for vFlashWrite addressing non-flash memory
23789
@item E @var{NN}
23790
for an error
23791
@end table
23792
 
23793
@item vFlashDone
23794
@cindex @samp{vFlashDone} packet
23795
Indicate to the stub that flash programming operation is finished.
23796
The stub is permitted to delay or batch the effects of a group of
23797
@samp{vFlashErase} and @samp{vFlashWrite} packets until a
23798
@samp{vFlashDone} packet is received.  The contents of the affected
23799
regions of flash memory are unpredictable until the @samp{vFlashDone}
23800
request is completed.
23801
 
23802
@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
23803
@cindex @samp{vRun} packet
23804
Run the program @var{filename}, passing it each @var{argument} on its
23805
command line.  The file and arguments are hex-encoded strings.  If
23806
@var{filename} is an empty string, the stub may use a default program
23807
(e.g.@: the last program run).  The program is created in the stopped
23808
state.
23809
 
23810
This packet is only available in extended mode (@pxref{extended mode}).
23811
 
23812
Reply:
23813
@table @samp
23814
@item E @var{nn}
23815
for an error
23816
@item @r{Any stop packet}
23817
for success (@pxref{Stop Reply Packets})
23818
@end table
23819
 
23820
@item X @var{addr},@var{length}:@var{XX@dots{}}
23821
@anchor{X packet}
23822
@cindex @samp{X} packet
23823
Write data to memory, where the data is transmitted in binary.
23824
@var{addr} is address, @var{length} is number of bytes,
23825
@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
23826
 
23827
Reply:
23828
@table @samp
23829
@item OK
23830
for success
23831
@item E @var{NN}
23832
for an error
23833
@end table
23834
 
23835
@item z @var{type},@var{addr},@var{length}
23836
@itemx Z @var{type},@var{addr},@var{length}
23837
@anchor{insert breakpoint or watchpoint packet}
23838
@cindex @samp{z} packet
23839
@cindex @samp{Z} packets
23840
Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
23841
watchpoint starting at address @var{address} and covering the next
23842
@var{length} bytes.
23843
 
23844
Each breakpoint and watchpoint packet @var{type} is documented
23845
separately.
23846
 
23847
@emph{Implementation notes: A remote target shall return an empty string
23848
for an unrecognized breakpoint or watchpoint packet @var{type}.  A
23849
remote target shall support either both or neither of a given
23850
@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair.  To
23851
avoid potential problems with duplicate packets, the operations should
23852
be implemented in an idempotent way.}
23853
 
23854
@item z0,@var{addr},@var{length}
23855
@itemx Z0,@var{addr},@var{length}
23856
@cindex @samp{z0} packet
23857
@cindex @samp{Z0} packet
23858
Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
23859
@var{addr} of size @var{length}.
23860
 
23861
A memory breakpoint is implemented by replacing the instruction at
23862
@var{addr} with a software breakpoint or trap instruction.  The
23863
@var{length} is used by targets that indicates the size of the
23864
breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
23865
@sc{mips} can insert either a 2 or 4 byte breakpoint).
23866
 
23867
@emph{Implementation note: It is possible for a target to copy or move
23868
code that contains memory breakpoints (e.g., when implementing
23869
overlays).  The behavior of this packet, in the presence of such a
23870
target, is not defined.}
23871
 
23872
Reply:
23873
@table @samp
23874
@item OK
23875
success
23876
@item
23877
not supported
23878
@item E @var{NN}
23879
for an error
23880
@end table
23881
 
23882
@item z1,@var{addr},@var{length}
23883
@itemx Z1,@var{addr},@var{length}
23884
@cindex @samp{z1} packet
23885
@cindex @samp{Z1} packet
23886
Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
23887
address @var{addr} of size @var{length}.
23888
 
23889
A hardware breakpoint is implemented using a mechanism that is not
23890
dependant on being able to modify the target's memory.
23891
 
23892
@emph{Implementation note: A hardware breakpoint is not affected by code
23893
movement.}
23894
 
23895
Reply:
23896
@table @samp
23897
@item OK
23898
success
23899
@item
23900
not supported
23901
@item E @var{NN}
23902
for an error
23903
@end table
23904
 
23905
@item z2,@var{addr},@var{length}
23906
@itemx Z2,@var{addr},@var{length}
23907
@cindex @samp{z2} packet
23908
@cindex @samp{Z2} packet
23909
Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
23910
 
23911
Reply:
23912
@table @samp
23913
@item OK
23914
success
23915
@item
23916
not supported
23917
@item E @var{NN}
23918
for an error
23919
@end table
23920
 
23921
@item z3,@var{addr},@var{length}
23922
@itemx Z3,@var{addr},@var{length}
23923
@cindex @samp{z3} packet
23924
@cindex @samp{Z3} packet
23925
Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
23926
 
23927
Reply:
23928
@table @samp
23929
@item OK
23930
success
23931
@item
23932
not supported
23933
@item E @var{NN}
23934
for an error
23935
@end table
23936
 
23937
@item z4,@var{addr},@var{length}
23938
@itemx Z4,@var{addr},@var{length}
23939
@cindex @samp{z4} packet
23940
@cindex @samp{Z4} packet
23941
Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
23942
 
23943
Reply:
23944
@table @samp
23945
@item OK
23946
success
23947
@item
23948
not supported
23949
@item E @var{NN}
23950
for an error
23951
@end table
23952
 
23953
@end table
23954
 
23955
@node Stop Reply Packets
23956
@section Stop Reply Packets
23957
@cindex stop reply packets
23958
 
23959
The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
23960
receive any of the below as a reply.  In the case of the @samp{C},
23961
@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
23962
when the target halts.  In the below the exact meaning of @dfn{signal
23963
number} is defined by the header @file{include/gdb/signals.h} in the
23964
@value{GDBN} source code.
23965
 
23966
As in the description of request packets, we include spaces in the
23967
reply templates for clarity; these are not part of the reply packet's
23968
syntax.  No @value{GDBN} stop reply packet uses spaces to separate its
23969
components.
23970
 
23971
@table @samp
23972
 
23973
@item S @var{AA}
23974
The program received signal number @var{AA} (a two-digit hexadecimal
23975
number).  This is equivalent to a @samp{T} response with no
23976
@var{n}:@var{r} pairs.
23977
 
23978
@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
23979
@cindex @samp{T} packet reply
23980
The program received signal number @var{AA} (a two-digit hexadecimal
23981
number).  This is equivalent to an @samp{S} response, except that the
23982
@samp{@var{n}:@var{r}} pairs can carry values of important registers
23983
and other information directly in the stop reply packet, reducing
23984
round-trip latency.  Single-step and breakpoint traps are reported
23985
this way.  Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
23986
 
23987
@itemize @bullet
23988
@item
23989
If @var{n} is a hexadecimal number, it is a register number, and the
23990
corresponding @var{r} gives that register's value.  @var{r} is a
23991
series of bytes in target byte order, with each byte given by a
23992
two-digit hex number.
23993
 
23994
@item
23995
If @var{n} is @samp{thread}, then @var{r} is the thread process ID, in
23996
hex.
23997
 
23998
@item
23999
If @var{n} is a recognized @dfn{stop reason}, it describes a more
24000
specific event that stopped the target.  The currently defined stop
24001
reasons are listed below.  @var{aa} should be @samp{05}, the trap
24002
signal.  At most one stop reason should be present.
24003
 
24004
@item
24005
Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
24006
and go on to the next; this allows us to extend the protocol in the
24007
future.
24008
@end itemize
24009
 
24010
The currently defined stop reasons are:
24011
 
24012
@table @samp
24013
@item watch
24014
@itemx rwatch
24015
@itemx awatch
24016
The packet indicates a watchpoint hit, and @var{r} is the data address, in
24017
hex.
24018
 
24019
@cindex shared library events, remote reply
24020
@item library
24021
The packet indicates that the loaded libraries have changed.
24022
@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
24023
list of loaded libraries.  @var{r} is ignored.
24024
@end table
24025
 
24026
@item W @var{AA}
24027
The process exited, and @var{AA} is the exit status.  This is only
24028
applicable to certain targets.
24029
 
24030
@item X @var{AA}
24031
The process terminated with signal @var{AA}.
24032
 
24033
@item O @var{XX}@dots{}
24034
@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
24035
written as the program's console output.  This can happen at any time
24036
while the program is running and the debugger should continue to wait
24037
for @samp{W}, @samp{T}, etc.
24038
 
24039
@item F @var{call-id},@var{parameter}@dots{}
24040
@var{call-id} is the identifier which says which host system call should
24041
be called.  This is just the name of the function.  Translation into the
24042
correct system call is only applicable as it's defined in @value{GDBN}.
24043
@xref{File-I/O Remote Protocol Extension}, for a list of implemented
24044
system calls.
24045
 
24046
@samp{@var{parameter}@dots{}} is a list of parameters as defined for
24047
this very system call.
24048
 
24049
The target replies with this packet when it expects @value{GDBN} to
24050
call a host system call on behalf of the target.  @value{GDBN} replies
24051
with an appropriate @samp{F} packet and keeps up waiting for the next
24052
reply packet from the target.  The latest @samp{C}, @samp{c}, @samp{S}
24053
or @samp{s} action is expected to be continued.  @xref{File-I/O Remote
24054
Protocol Extension}, for more details.
24055
 
24056
@end table
24057
 
24058
@node General Query Packets
24059
@section General Query Packets
24060
@cindex remote query requests
24061
 
24062
Packets starting with @samp{q} are @dfn{general query packets};
24063
packets starting with @samp{Q} are @dfn{general set packets}.  General
24064
query and set packets are a semi-unified form for retrieving and
24065
sending information to and from the stub.
24066
 
24067
The initial letter of a query or set packet is followed by a name
24068
indicating what sort of thing the packet applies to.  For example,
24069
@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
24070
definitions with the stub.  These packet names follow some
24071
conventions:
24072
 
24073
@itemize @bullet
24074
@item
24075
The name must not contain commas, colons or semicolons.
24076
@item
24077
Most @value{GDBN} query and set packets have a leading upper case
24078
letter.
24079
@item
24080
The names of custom vendor packets should use a company prefix, in
24081
lower case, followed by a period.  For example, packets designed at
24082
the Acme Corporation might begin with @samp{qacme.foo} (for querying
24083
foos) or @samp{Qacme.bar} (for setting bars).
24084
@end itemize
24085
 
24086
The name of a query or set packet should be separated from any
24087
parameters by a @samp{:}; the parameters themselves should be
24088
separated by @samp{,} or @samp{;}.  Stubs must be careful to match the
24089
full packet name, and check for a separator or the end of the packet,
24090
in case two packet names share a common prefix.  New packets should not begin
24091
with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
24092
packets predate these conventions, and have arguments without any terminator
24093
for the packet name; we suspect they are in widespread use in places that
24094
are difficult to upgrade.  The @samp{qC} packet has no arguments, but some
24095
existing stubs (e.g.@: RedBoot) are known to not check for the end of the
24096
packet.}.
24097
 
24098
Like the descriptions of the other packets, each description here
24099
has a template showing the packet's overall syntax, followed by an
24100
explanation of the packet's meaning.  We include spaces in some of the
24101
templates for clarity; these are not part of the packet's syntax.  No
24102
@value{GDBN} packet uses spaces to separate its components.
24103
 
24104
Here are the currently defined query and set packets:
24105
 
24106
@table @samp
24107
 
24108
@item qC
24109
@cindex current thread, remote request
24110
@cindex @samp{qC} packet
24111
Return the current thread id.
24112
 
24113
Reply:
24114
@table @samp
24115
@item QC @var{pid}
24116
Where @var{pid} is an unsigned hexadecimal process id.
24117
@item @r{(anything else)}
24118
Any other reply implies the old pid.
24119
@end table
24120
 
24121
@item qCRC:@var{addr},@var{length}
24122
@cindex CRC of memory block, remote request
24123
@cindex @samp{qCRC} packet
24124
Compute the CRC checksum of a block of memory.
24125
Reply:
24126
@table @samp
24127
@item E @var{NN}
24128
An error (such as memory fault)
24129
@item C @var{crc32}
24130
The specified memory region's checksum is @var{crc32}.
24131
@end table
24132
 
24133
@item qfThreadInfo
24134
@itemx qsThreadInfo
24135
@cindex list active threads, remote request
24136
@cindex @samp{qfThreadInfo} packet
24137
@cindex @samp{qsThreadInfo} packet
24138
Obtain a list of all active thread ids from the target (OS).  Since there
24139
may be too many active threads to fit into one reply packet, this query
24140
works iteratively: it may require more than one query/reply sequence to
24141
obtain the entire list of threads.  The first query of the sequence will
24142
be the @samp{qfThreadInfo} query; subsequent queries in the
24143
sequence will be the @samp{qsThreadInfo} query.
24144
 
24145
NOTE: This packet replaces the @samp{qL} query (see below).
24146
 
24147
Reply:
24148
@table @samp
24149
@item m @var{id}
24150
A single thread id
24151
@item m @var{id},@var{id}@dots{}
24152
a comma-separated list of thread ids
24153
@item l
24154
(lower case letter @samp{L}) denotes end of list.
24155
@end table
24156
 
24157
In response to each query, the target will reply with a list of one or
24158
more thread ids, in big-endian unsigned hex, separated by commas.
24159
@value{GDBN} will respond to each reply with a request for more thread
24160
ids (using the @samp{qs} form of the query), until the target responds
24161
with @samp{l} (lower-case el, for @dfn{last}).
24162
 
24163
@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
24164
@cindex get thread-local storage address, remote request
24165
@cindex @samp{qGetTLSAddr} packet
24166
Fetch the address associated with thread local storage specified
24167
by @var{thread-id}, @var{offset}, and @var{lm}.
24168
 
24169
@var{thread-id} is the (big endian, hex encoded) thread id associated with the
24170
thread for which to fetch the TLS address.
24171
 
24172
@var{offset} is the (big endian, hex encoded) offset associated with the
24173
thread local variable.  (This offset is obtained from the debug
24174
information associated with the variable.)
24175
 
24176
@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
24177
the load module associated with the thread local storage.  For example,
24178
a @sc{gnu}/Linux system will pass the link map address of the shared
24179
object associated with the thread local storage under consideration.
24180
Other operating environments may choose to represent the load module
24181
differently, so the precise meaning of this parameter will vary.
24182
 
24183
Reply:
24184
@table @samp
24185
@item @var{XX}@dots{}
24186
Hex encoded (big endian) bytes representing the address of the thread
24187
local storage requested.
24188
 
24189
@item E @var{nn}
24190
An error occurred.  @var{nn} are hex digits.
24191
 
24192
@item
24193
An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
24194
@end table
24195
 
24196
@item qL @var{startflag} @var{threadcount} @var{nextthread}
24197
Obtain thread information from RTOS.  Where: @var{startflag} (one hex
24198
digit) is one to indicate the first query and zero to indicate a
24199
subsequent query; @var{threadcount} (two hex digits) is the maximum
24200
number of threads the response packet can contain; and @var{nextthread}
24201
(eight hex digits), for subsequent queries (@var{startflag} is zero), is
24202
returned in the response as @var{argthread}.
24203
 
24204
Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
24205
 
24206
Reply:
24207
@table @samp
24208
@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
24209
Where: @var{count} (two hex digits) is the number of threads being
24210
returned; @var{done} (one hex digit) is zero to indicate more threads
24211
and one indicates no further threads; @var{argthreadid} (eight hex
24212
digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
24213
is a sequence of thread IDs from the target.  @var{threadid} (eight hex
24214
digits).  See @code{remote.c:parse_threadlist_response()}.
24215
@end table
24216
 
24217
@item qOffsets
24218
@cindex section offsets, remote request
24219
@cindex @samp{qOffsets} packet
24220
Get section offsets that the target used when relocating the downloaded
24221
image.
24222
 
24223
Reply:
24224
@table @samp
24225
@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
24226
Relocate the @code{Text} section by @var{xxx} from its original address.
24227
Relocate the @code{Data} section by @var{yyy} from its original address.
24228
If the object file format provides segment information (e.g.@: @sc{elf}
24229
@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
24230
segments by the supplied offsets.
24231
 
24232
@emph{Note: while a @code{Bss} offset may be included in the response,
24233
@value{GDBN} ignores this and instead applies the @code{Data} offset
24234
to the @code{Bss} section.}
24235
 
24236
@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
24237
Relocate the first segment of the object file, which conventionally
24238
contains program code, to a starting address of @var{xxx}.  If
24239
@samp{DataSeg} is specified, relocate the second segment, which
24240
conventionally contains modifiable data, to a starting address of
24241
@var{yyy}.  @value{GDBN} will report an error if the object file
24242
does not contain segment information, or does not contain at least
24243
as many segments as mentioned in the reply.  Extra segments are
24244
kept at fixed offsets relative to the last relocated segment.
24245
@end table
24246
 
24247
@item qP @var{mode} @var{threadid}
24248
@cindex thread information, remote request
24249
@cindex @samp{qP} packet
24250
Returns information on @var{threadid}.  Where: @var{mode} is a hex
24251
encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
24252
 
24253
Don't use this packet; use the @samp{qThreadExtraInfo} query instead
24254
(see below).
24255
 
24256
Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
24257
 
24258
@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
24259
@cindex pass signals to inferior, remote request
24260
@cindex @samp{QPassSignals} packet
24261
@anchor{QPassSignals}
24262
Each listed @var{signal} should be passed directly to the inferior process.
24263
Signals are numbered identically to continue packets and stop replies
24264
(@pxref{Stop Reply Packets}).  Each @var{signal} list item should be
24265
strictly greater than the previous item.  These signals do not need to stop
24266
the inferior, or be reported to @value{GDBN}.  All other signals should be
24267
reported to @value{GDBN}.  Multiple @samp{QPassSignals} packets do not
24268
combine; any earlier @samp{QPassSignals} list is completely replaced by the
24269
new list.  This packet improves performance when using @samp{handle
24270
@var{signal} nostop noprint pass}.
24271
 
24272
Reply:
24273
@table @samp
24274
@item OK
24275
The request succeeded.
24276
 
24277
@item E @var{nn}
24278
An error occurred.  @var{nn} are hex digits.
24279
 
24280
@item
24281
An empty reply indicates that @samp{QPassSignals} is not supported by
24282
the stub.
24283
@end table
24284
 
24285
Use of this packet is controlled by the @code{set remote pass-signals}
24286
command (@pxref{Remote Configuration, set remote pass-signals}).
24287
This packet is not probed by default; the remote stub must request it,
24288
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24289
 
24290
@item qRcmd,@var{command}
24291
@cindex execute remote command, remote request
24292
@cindex @samp{qRcmd} packet
24293
@var{command} (hex encoded) is passed to the local interpreter for
24294
execution.  Invalid commands should be reported using the output
24295
string.  Before the final result packet, the target may also respond
24296
with a number of intermediate @samp{O@var{output}} console output
24297
packets.  @emph{Implementors should note that providing access to a
24298
stubs's interpreter may have security implications}.
24299
 
24300
Reply:
24301
@table @samp
24302
@item OK
24303
A command response with no output.
24304
@item @var{OUTPUT}
24305
A command response with the hex encoded output string @var{OUTPUT}.
24306
@item E @var{NN}
24307
Indicate a badly formed request.
24308
@item
24309
An empty reply indicates that @samp{qRcmd} is not recognized.
24310
@end table
24311
 
24312
(Note that the @code{qRcmd} packet's name is separated from the
24313
command by a @samp{,}, not a @samp{:}, contrary to the naming
24314
conventions above.  Please don't use this packet as a model for new
24315
packets.)
24316
 
24317
@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
24318
@cindex supported packets, remote query
24319
@cindex features of the remote protocol
24320
@cindex @samp{qSupported} packet
24321
@anchor{qSupported}
24322
Tell the remote stub about features supported by @value{GDBN}, and
24323
query the stub for features it supports.  This packet allows
24324
@value{GDBN} and the remote stub to take advantage of each others'
24325
features.  @samp{qSupported} also consolidates multiple feature probes
24326
at startup, to improve @value{GDBN} performance---a single larger
24327
packet performs better than multiple smaller probe packets on
24328
high-latency links.  Some features may enable behavior which must not
24329
be on by default, e.g.@: because it would confuse older clients or
24330
stubs.  Other features may describe packets which could be
24331
automatically probed for, but are not.  These features must be
24332
reported before @value{GDBN} will use them.  This ``default
24333
unsupported'' behavior is not appropriate for all packets, but it
24334
helps to keep the initial connection time under control with new
24335
versions of @value{GDBN} which support increasing numbers of packets.
24336
 
24337
Reply:
24338
@table @samp
24339
@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
24340
The stub supports or does not support each returned @var{stubfeature},
24341
depending on the form of each @var{stubfeature} (see below for the
24342
possible forms).
24343
@item
24344
An empty reply indicates that @samp{qSupported} is not recognized,
24345
or that no features needed to be reported to @value{GDBN}.
24346
@end table
24347
 
24348
The allowed forms for each feature (either a @var{gdbfeature} in the
24349
@samp{qSupported} packet, or a @var{stubfeature} in the response)
24350
are:
24351
 
24352
@table @samp
24353
@item @var{name}=@var{value}
24354
The remote protocol feature @var{name} is supported, and associated
24355
with the specified @var{value}.  The format of @var{value} depends
24356
on the feature, but it must not include a semicolon.
24357
@item @var{name}+
24358
The remote protocol feature @var{name} is supported, and does not
24359
need an associated value.
24360
@item @var{name}-
24361
The remote protocol feature @var{name} is not supported.
24362
@item @var{name}?
24363
The remote protocol feature @var{name} may be supported, and
24364
@value{GDBN} should auto-detect support in some other way when it is
24365
needed.  This form will not be used for @var{gdbfeature} notifications,
24366
but may be used for @var{stubfeature} responses.
24367
@end table
24368
 
24369
Whenever the stub receives a @samp{qSupported} request, the
24370
supplied set of @value{GDBN} features should override any previous
24371
request.  This allows @value{GDBN} to put the stub in a known
24372
state, even if the stub had previously been communicating with
24373
a different version of @value{GDBN}.
24374
 
24375
No values of @var{gdbfeature} (for the packet sent by @value{GDBN})
24376
are defined yet.  Stubs should ignore any unknown values for
24377
@var{gdbfeature}.  Any @value{GDBN} which sends a @samp{qSupported}
24378
packet supports receiving packets of unlimited length (earlier
24379
versions of @value{GDBN} may reject overly long responses).  Values
24380
for @var{gdbfeature} may be defined in the future to let the stub take
24381
advantage of new features in @value{GDBN}, e.g.@: incompatible
24382
improvements in the remote protocol---support for unlimited length
24383
responses would be a @var{gdbfeature} example, if it were not implied by
24384
the @samp{qSupported} query.  The stub's reply should be independent
24385
of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
24386
describes all the features it supports, and then the stub replies with
24387
all the features it supports.
24388
 
24389
Similarly, @value{GDBN} will silently ignore unrecognized stub feature
24390
responses, as long as each response uses one of the standard forms.
24391
 
24392
Some features are flags.  A stub which supports a flag feature
24393
should respond with a @samp{+} form response.  Other features
24394
require values, and the stub should respond with an @samp{=}
24395
form response.
24396
 
24397
Each feature has a default value, which @value{GDBN} will use if
24398
@samp{qSupported} is not available or if the feature is not mentioned
24399
in the @samp{qSupported} response.  The default values are fixed; a
24400
stub is free to omit any feature responses that match the defaults.
24401
 
24402
Not all features can be probed, but for those which can, the probing
24403
mechanism is useful: in some cases, a stub's internal
24404
architecture may not allow the protocol layer to know some information
24405
about the underlying target in advance.  This is especially common in
24406
stubs which may be configured for multiple targets.
24407
 
24408
These are the currently defined stub features and their properties:
24409
 
24410
@multitable @columnfractions 0.35 0.2 0.12 0.2
24411
@c NOTE: The first row should be @headitem, but we do not yet require
24412
@c a new enough version of Texinfo (4.7) to use @headitem.
24413
@item Feature Name
24414
@tab Value Required
24415
@tab Default
24416
@tab Probe Allowed
24417
 
24418
@item @samp{PacketSize}
24419
@tab Yes
24420
@tab @samp{-}
24421
@tab No
24422
 
24423
@item @samp{qXfer:auxv:read}
24424
@tab No
24425
@tab @samp{-}
24426
@tab Yes
24427
 
24428
@item @samp{qXfer:features:read}
24429
@tab No
24430
@tab @samp{-}
24431
@tab Yes
24432
 
24433
@item @samp{qXfer:libraries:read}
24434
@tab No
24435
@tab @samp{-}
24436
@tab Yes
24437
 
24438
@item @samp{qXfer:memory-map:read}
24439
@tab No
24440
@tab @samp{-}
24441
@tab Yes
24442
 
24443
@item @samp{qXfer:spu:read}
24444
@tab No
24445
@tab @samp{-}
24446
@tab Yes
24447
 
24448
@item @samp{qXfer:spu:write}
24449
@tab No
24450
@tab @samp{-}
24451
@tab Yes
24452
 
24453
@item @samp{QPassSignals}
24454
@tab No
24455
@tab @samp{-}
24456
@tab Yes
24457
 
24458
@end multitable
24459
 
24460
These are the currently defined stub features, in more detail:
24461
 
24462
@table @samp
24463
@cindex packet size, remote protocol
24464
@item PacketSize=@var{bytes}
24465
The remote stub can accept packets up to at least @var{bytes} in
24466
length.  @value{GDBN} will send packets up to this size for bulk
24467
transfers, and will never send larger packets.  This is a limit on the
24468
data characters in the packet, including the frame and checksum.
24469
There is no trailing NUL byte in a remote protocol packet; if the stub
24470
stores packets in a NUL-terminated format, it should allow an extra
24471
byte in its buffer for the NUL.  If this stub feature is not supported,
24472
@value{GDBN} guesses based on the size of the @samp{g} packet response.
24473
 
24474
@item qXfer:auxv:read
24475
The remote stub understands the @samp{qXfer:auxv:read} packet
24476
(@pxref{qXfer auxiliary vector read}).
24477
 
24478
@item qXfer:features:read
24479
The remote stub understands the @samp{qXfer:features:read} packet
24480
(@pxref{qXfer target description read}).
24481
 
24482
@item qXfer:libraries:read
24483
The remote stub understands the @samp{qXfer:libraries:read} packet
24484
(@pxref{qXfer library list read}).
24485
 
24486
@item qXfer:memory-map:read
24487
The remote stub understands the @samp{qXfer:memory-map:read} packet
24488
(@pxref{qXfer memory map read}).
24489
 
24490
@item qXfer:spu:read
24491
The remote stub understands the @samp{qXfer:spu:read} packet
24492
(@pxref{qXfer spu read}).
24493
 
24494
@item qXfer:spu:write
24495
The remote stub understands the @samp{qXfer:spu:write} packet
24496
(@pxref{qXfer spu write}).
24497
 
24498
@item QPassSignals
24499
The remote stub understands the @samp{QPassSignals} packet
24500
(@pxref{QPassSignals}).
24501
 
24502
@end table
24503
 
24504
@item qSymbol::
24505
@cindex symbol lookup, remote request
24506
@cindex @samp{qSymbol} packet
24507
Notify the target that @value{GDBN} is prepared to serve symbol lookup
24508
requests.  Accept requests from the target for the values of symbols.
24509
 
24510
Reply:
24511
@table @samp
24512
@item OK
24513
The target does not need to look up any (more) symbols.
24514
@item qSymbol:@var{sym_name}
24515
The target requests the value of symbol @var{sym_name} (hex encoded).
24516
@value{GDBN} may provide the value by using the
24517
@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
24518
below.
24519
@end table
24520
 
24521
@item qSymbol:@var{sym_value}:@var{sym_name}
24522
Set the value of @var{sym_name} to @var{sym_value}.
24523
 
24524
@var{sym_name} (hex encoded) is the name of a symbol whose value the
24525
target has previously requested.
24526
 
24527
@var{sym_value} (hex) is the value for symbol @var{sym_name}.  If
24528
@value{GDBN} cannot supply a value for @var{sym_name}, then this field
24529
will be empty.
24530
 
24531
Reply:
24532
@table @samp
24533
@item OK
24534
The target does not need to look up any (more) symbols.
24535
@item qSymbol:@var{sym_name}
24536
The target requests the value of a new symbol @var{sym_name} (hex
24537
encoded).  @value{GDBN} will continue to supply the values of symbols
24538
(if available), until the target ceases to request them.
24539
@end table
24540
 
24541
@item QTDP
24542
@itemx QTFrame
24543
@xref{Tracepoint Packets}.
24544
 
24545
@item qThreadExtraInfo,@var{id}
24546
@cindex thread attributes info, remote request
24547
@cindex @samp{qThreadExtraInfo} packet
24548
Obtain a printable string description of a thread's attributes from
24549
the target OS.  @var{id} is a thread-id in big-endian hex.  This
24550
string may contain anything that the target OS thinks is interesting
24551
for @value{GDBN} to tell the user about the thread.  The string is
24552
displayed in @value{GDBN}'s @code{info threads} display.  Some
24553
examples of possible thread extra info strings are @samp{Runnable}, or
24554
@samp{Blocked on Mutex}.
24555
 
24556
Reply:
24557
@table @samp
24558
@item @var{XX}@dots{}
24559
Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
24560
comprising the printable string containing the extra information about
24561
the thread's attributes.
24562
@end table
24563
 
24564
(Note that the @code{qThreadExtraInfo} packet's name is separated from
24565
the command by a @samp{,}, not a @samp{:}, contrary to the naming
24566
conventions above.  Please don't use this packet as a model for new
24567
packets.)
24568
 
24569
@item QTStart
24570
@itemx QTStop
24571
@itemx QTinit
24572
@itemx QTro
24573
@itemx qTStatus
24574
@xref{Tracepoint Packets}.
24575
 
24576
@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
24577
@cindex read special object, remote request
24578
@cindex @samp{qXfer} packet
24579
@anchor{qXfer read}
24580
Read uninterpreted bytes from the target's special data area
24581
identified by the keyword @var{object}.  Request @var{length} bytes
24582
starting at @var{offset} bytes into the data.  The content and
24583
encoding of @var{annex} is specific to @var{object}; it can supply
24584
additional details about what data to access.
24585
 
24586
Here are the specific requests of this form defined so far.  All
24587
@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
24588
formats, listed below.
24589
 
24590
@table @samp
24591
@item qXfer:auxv:read::@var{offset},@var{length}
24592
@anchor{qXfer auxiliary vector read}
24593
Access the target's @dfn{auxiliary vector}.  @xref{OS Information,
24594
auxiliary vector}.  Note @var{annex} must be empty.
24595
 
24596
This packet is not probed by default; the remote stub must request it,
24597
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24598
 
24599
@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
24600
@anchor{qXfer target description read}
24601
Access the @dfn{target description}.  @xref{Target Descriptions}.  The
24602
annex specifies which XML document to access.  The main description is
24603
always loaded from the @samp{target.xml} annex.
24604
 
24605
This packet is not probed by default; the remote stub must request it,
24606
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24607
 
24608
@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
24609
@anchor{qXfer library list read}
24610
Access the target's list of loaded libraries.  @xref{Library List Format}.
24611
The annex part of the generic @samp{qXfer} packet must be empty
24612
(@pxref{qXfer read}).
24613
 
24614
Targets which maintain a list of libraries in the program's memory do
24615
not need to implement this packet; it is designed for platforms where
24616
the operating system manages the list of loaded libraries.
24617
 
24618
This packet is not probed by default; the remote stub must request it,
24619
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24620
 
24621
@item qXfer:memory-map:read::@var{offset},@var{length}
24622
@anchor{qXfer memory map read}
24623
Access the target's @dfn{memory-map}.  @xref{Memory Map Format}.  The
24624
annex part of the generic @samp{qXfer} packet must be empty
24625
(@pxref{qXfer read}).
24626
 
24627
This packet is not probed by default; the remote stub must request it,
24628
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24629
 
24630
@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
24631
@anchor{qXfer spu read}
24632
Read contents of an @code{spufs} file on the target system.  The
24633
annex specifies which file to read; it must be of the form
24634
@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
24635
in the target process, and @var{name} identifes the @code{spufs} file
24636
in that context to be accessed.
24637
 
24638
This packet is not probed by default; the remote stub must request it,
24639
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24640
@end table
24641
 
24642
Reply:
24643
@table @samp
24644
@item m @var{data}
24645
Data @var{data} (@pxref{Binary Data}) has been read from the
24646
target.  There may be more data at a higher address (although
24647
it is permitted to return @samp{m} even for the last valid
24648
block of data, as long as at least one byte of data was read).
24649
@var{data} may have fewer bytes than the @var{length} in the
24650
request.
24651
 
24652
@item l @var{data}
24653
Data @var{data} (@pxref{Binary Data}) has been read from the target.
24654
There is no more data to be read.  @var{data} may have fewer bytes
24655
than the @var{length} in the request.
24656
 
24657
@item l
24658
The @var{offset} in the request is at the end of the data.
24659
There is no more data to be read.
24660
 
24661
@item E00
24662
The request was malformed, or @var{annex} was invalid.
24663
 
24664
@item E @var{nn}
24665
The offset was invalid, or there was an error encountered reading the data.
24666
@var{nn} is a hex-encoded @code{errno} value.
24667
 
24668
@item
24669
An empty reply indicates the @var{object} string was not recognized by
24670
the stub, or that the object does not support reading.
24671
@end table
24672
 
24673
@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
24674
@cindex write data into object, remote request
24675
Write uninterpreted bytes into the target's special data area
24676
identified by the keyword @var{object}, starting at @var{offset} bytes
24677
into the data.  @var{data}@dots{} is the binary-encoded data
24678
(@pxref{Binary Data}) to be written.  The content and encoding of @var{annex}
24679
is specific to @var{object}; it can supply additional details about what data
24680
to access.
24681
 
24682
Here are the specific requests of this form defined so far.  All
24683
@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
24684
formats, listed below.
24685
 
24686
@table @samp
24687
@item qXfer:@var{spu}:write:@var{annex}:@var{offset}:@var{data}@dots{}
24688
@anchor{qXfer spu write}
24689
Write @var{data} to an @code{spufs} file on the target system.  The
24690
annex specifies which file to write; it must be of the form
24691
@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
24692
in the target process, and @var{name} identifes the @code{spufs} file
24693
in that context to be accessed.
24694
 
24695
This packet is not probed by default; the remote stub must request it,
24696
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24697
@end table
24698
 
24699
Reply:
24700
@table @samp
24701
@item @var{nn}
24702
@var{nn} (hex encoded) is the number of bytes written.
24703
This may be fewer bytes than supplied in the request.
24704
 
24705
@item E00
24706
The request was malformed, or @var{annex} was invalid.
24707
 
24708
@item E @var{nn}
24709
The offset was invalid, or there was an error encountered writing the data.
24710
@var{nn} is a hex-encoded @code{errno} value.
24711
 
24712
@item
24713
An empty reply indicates the @var{object} string was not
24714
recognized by the stub, or that the object does not support writing.
24715
@end table
24716
 
24717
@item qXfer:@var{object}:@var{operation}:@dots{}
24718
Requests of this form may be added in the future.  When a stub does
24719
not recognize the @var{object} keyword, or its support for
24720
@var{object} does not recognize the @var{operation} keyword, the stub
24721
must respond with an empty packet.
24722
 
24723
@end table
24724
 
24725
@node Register Packet Format
24726
@section Register Packet Format
24727
 
24728
The following @code{g}/@code{G} packets have previously been defined.
24729
In the below, some thirty-two bit registers are transferred as
24730
sixty-four bits.  Those registers should be zero/sign extended (which?)
24731
to fill the space allocated.  Register bytes are transferred in target
24732
byte order.  The two nibbles within a register byte are transferred
24733
most-significant - least-significant.
24734
 
24735
@table @r
24736
 
24737
@item MIPS32
24738
 
24739
All registers are transferred as thirty-two bit quantities in the order:
24740
32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
24741
registers; fsr; fir; fp.
24742
 
24743
@item MIPS64
24744
 
24745
All registers are transferred as sixty-four bit quantities (including
24746
thirty-two bit registers such as @code{sr}).  The ordering is the same
24747
as @code{MIPS32}.
24748
 
24749
@end table
24750
 
24751
@node Tracepoint Packets
24752
@section Tracepoint Packets
24753
@cindex tracepoint packets
24754
@cindex packets, tracepoint
24755
 
24756
Here we describe the packets @value{GDBN} uses to implement
24757
tracepoints (@pxref{Tracepoints}).
24758
 
24759
@table @samp
24760
 
24761
@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
24762
Create a new tracepoint, number @var{n}, at @var{addr}.  If @var{ena}
24763
is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
24764
the tracepoint is disabled.  @var{step} is the tracepoint's step
24765
count, and @var{pass} is its pass count.  If the trailing @samp{-} is
24766
present, further @samp{QTDP} packets will follow to specify this
24767
tracepoint's actions.
24768
 
24769
Replies:
24770
@table @samp
24771
@item OK
24772
The packet was understood and carried out.
24773
@item
24774
The packet was not recognized.
24775
@end table
24776
 
24777
@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
24778
Define actions to be taken when a tracepoint is hit.  @var{n} and
24779
@var{addr} must be the same as in the initial @samp{QTDP} packet for
24780
this tracepoint.  This packet may only be sent immediately after
24781
another @samp{QTDP} packet that ended with a @samp{-}.  If the
24782
trailing @samp{-} is present, further @samp{QTDP} packets will follow,
24783
specifying more actions for this tracepoint.
24784
 
24785
In the series of action packets for a given tracepoint, at most one
24786
can have an @samp{S} before its first @var{action}.  If such a packet
24787
is sent, it and the following packets define ``while-stepping''
24788
actions.  Any prior packets define ordinary actions --- that is, those
24789
taken when the tracepoint is first hit.  If no action packet has an
24790
@samp{S}, then all the packets in the series specify ordinary
24791
tracepoint actions.
24792
 
24793
The @samp{@var{action}@dots{}} portion of the packet is a series of
24794
actions, concatenated without separators.  Each action has one of the
24795
following forms:
24796
 
24797
@table @samp
24798
 
24799
@item R @var{mask}
24800
Collect the registers whose bits are set in @var{mask}.  @var{mask} is
24801
a hexadecimal number whose @var{i}'th bit is set if register number
24802
@var{i} should be collected.  (The least significant bit is numbered
24803
zero.)  Note that @var{mask} may be any number of digits long; it may
24804
not fit in a 32-bit word.
24805
 
24806
@item M @var{basereg},@var{offset},@var{len}
24807
Collect @var{len} bytes of memory starting at the address in register
24808
number @var{basereg}, plus @var{offset}.  If @var{basereg} is
24809
@samp{-1}, then the range has a fixed address: @var{offset} is the
24810
address of the lowest byte to collect.  The @var{basereg},
24811
@var{offset}, and @var{len} parameters are all unsigned hexadecimal
24812
values (the @samp{-1} value for @var{basereg} is a special case).
24813
 
24814
@item X @var{len},@var{expr}
24815
Evaluate @var{expr}, whose length is @var{len}, and collect memory as
24816
it directs.  @var{expr} is an agent expression, as described in
24817
@ref{Agent Expressions}.  Each byte of the expression is encoded as a
24818
two-digit hex number in the packet; @var{len} is the number of bytes
24819
in the expression (and thus one-half the number of hex digits in the
24820
packet).
24821
 
24822
@end table
24823
 
24824
Any number of actions may be packed together in a single @samp{QTDP}
24825
packet, as long as the packet does not exceed the maximum packet
24826
length (400 bytes, for many stubs).  There may be only one @samp{R}
24827
action per tracepoint, and it must precede any @samp{M} or @samp{X}
24828
actions.  Any registers referred to by @samp{M} and @samp{X} actions
24829
must be collected by a preceding @samp{R} action.  (The
24830
``while-stepping'' actions are treated as if they were attached to a
24831
separate tracepoint, as far as these restrictions are concerned.)
24832
 
24833
Replies:
24834
@table @samp
24835
@item OK
24836
The packet was understood and carried out.
24837
@item
24838
The packet was not recognized.
24839
@end table
24840
 
24841
@item QTFrame:@var{n}
24842
Select the @var{n}'th tracepoint frame from the buffer, and use the
24843
register and memory contents recorded there to answer subsequent
24844
request packets from @value{GDBN}.
24845
 
24846
A successful reply from the stub indicates that the stub has found the
24847
requested frame.  The response is a series of parts, concatenated
24848
without separators, describing the frame we selected.  Each part has
24849
one of the following forms:
24850
 
24851
@table @samp
24852
@item F @var{f}
24853
The selected frame is number @var{n} in the trace frame buffer;
24854
@var{f} is a hexadecimal number.  If @var{f} is @samp{-1}, then there
24855
was no frame matching the criteria in the request packet.
24856
 
24857
@item T @var{t}
24858
The selected trace frame records a hit of tracepoint number @var{t};
24859
@var{t} is a hexadecimal number.
24860
 
24861
@end table
24862
 
24863
@item QTFrame:pc:@var{addr}
24864
Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24865
currently selected frame whose PC is @var{addr};
24866
@var{addr} is a hexadecimal number.
24867
 
24868
@item QTFrame:tdp:@var{t}
24869
Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24870
currently selected frame that is a hit of tracepoint @var{t}; @var{t}
24871
is a hexadecimal number.
24872
 
24873
@item QTFrame:range:@var{start}:@var{end}
24874
Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24875
currently selected frame whose PC is between @var{start} (inclusive)
24876
and @var{end} (exclusive); @var{start} and @var{end} are hexadecimal
24877
numbers.
24878
 
24879
@item QTFrame:outside:@var{start}:@var{end}
24880
Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
24881
frame @emph{outside} the given range of addresses.
24882
 
24883
@item QTStart
24884
Begin the tracepoint experiment.  Begin collecting data from tracepoint
24885
hits in the trace frame buffer.
24886
 
24887
@item QTStop
24888
End the tracepoint experiment.  Stop collecting trace frames.
24889
 
24890
@item QTinit
24891
Clear the table of tracepoints, and empty the trace frame buffer.
24892
 
24893
@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
24894
Establish the given ranges of memory as ``transparent''.  The stub
24895
will answer requests for these ranges from memory's current contents,
24896
if they were not collected as part of the tracepoint hit.
24897
 
24898
@value{GDBN} uses this to mark read-only regions of memory, like those
24899
containing program code.  Since these areas never change, they should
24900
still have the same contents they did when the tracepoint was hit, so
24901
there's no reason for the stub to refuse to provide their contents.
24902
 
24903
@item qTStatus
24904
Ask the stub if there is a trace experiment running right now.
24905
 
24906
Replies:
24907
@table @samp
24908
@item T0
24909
There is no trace experiment running.
24910
@item T1
24911
There is a trace experiment running.
24912
@end table
24913
 
24914
@end table
24915
 
24916
 
24917
@node Host I/O Packets
24918
@section Host I/O Packets
24919
@cindex Host I/O, remote protocol
24920
@cindex file transfer, remote protocol
24921
 
24922
The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
24923
operations on the far side of a remote link.  For example, Host I/O is
24924
used to upload and download files to a remote target with its own
24925
filesystem.  Host I/O uses the same constant values and data structure
24926
layout as the target-initiated File-I/O protocol.  However, the
24927
Host I/O packets are structured differently.  The target-initiated
24928
protocol relies on target memory to store parameters and buffers.
24929
Host I/O requests are initiated by @value{GDBN}, and the
24930
target's memory is not involved.  @xref{File-I/O Remote Protocol
24931
Extension}, for more details on the target-initiated protocol.
24932
 
24933
The Host I/O request packets all encode a single operation along with
24934
its arguments.  They have this format:
24935
 
24936
@table @samp
24937
 
24938
@item vFile:@var{operation}: @var{parameter}@dots{}
24939
@var{operation} is the name of the particular request; the target
24940
should compare the entire packet name up to the second colon when checking
24941
for a supported operation.  The format of @var{parameter} depends on
24942
the operation.  Numbers are always passed in hexadecimal.  Negative
24943
numbers have an explicit minus sign (i.e.@: two's complement is not
24944
used).  Strings (e.g.@: filenames) are encoded as a series of
24945
hexadecimal bytes.  The last argument to a system call may be a
24946
buffer of escaped binary data (@pxref{Binary Data}).
24947
 
24948
@end table
24949
 
24950
The valid responses to Host I/O packets are:
24951
 
24952
@table @samp
24953
 
24954
@item F @var{result} [, @var{errno}] [; @var{attachment}]
24955
@var{result} is the integer value returned by this operation, usually
24956
non-negative for success and -1 for errors.  If an error has occured,
24957
@var{errno} will be included in the result.  @var{errno} will have a
24958
value defined by the File-I/O protocol (@pxref{Errno Values}).  For
24959
operations which return data, @var{attachment} supplies the data as a
24960
binary buffer.  Binary buffers in response packets are escaped in the
24961
normal way (@pxref{Binary Data}).  See the individual packet
24962
documentation for the interpretation of @var{result} and
24963
@var{attachment}.
24964
 
24965
@item
24966
An empty response indicates that this operation is not recognized.
24967
 
24968
@end table
24969
 
24970
These are the supported Host I/O operations:
24971
 
24972
@table @samp
24973
@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
24974
Open a file at @var{pathname} and return a file descriptor for it, or
24975
return -1 if an error occurs.  @var{pathname} is a string,
24976
@var{flags} is an integer indicating a mask of open flags
24977
(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
24978
of mode bits to use if the file is created (@pxref{mode_t Values}).
24979
@xref{open}, for details of the open flags and mode values.
24980
 
24981
@item vFile:close: @var{fd}
24982
Close the open file corresponding to @var{fd} and return 0, or
24983
-1 if an error occurs.
24984
 
24985
@item vFile:pread: @var{fd}, @var{count}, @var{offset}
24986
Read data from the open file corresponding to @var{fd}.  Up to
24987
@var{count} bytes will be read from the file, starting at @var{offset}
24988
relative to the start of the file.  The target may read fewer bytes;
24989
common reasons include packet size limits and an end-of-file
24990
condition.  The number of bytes read is returned.  Zero should only be
24991
returned for a successful read at the end of the file, or if
24992
@var{count} was zero.
24993
 
24994
The data read should be returned as a binary attachment on success.
24995
If zero bytes were read, the response should include an empty binary
24996
attachment (i.e.@: a trailing semicolon).  The return value is the
24997
number of target bytes read; the binary attachment may be longer if
24998
some characters were escaped.
24999
 
25000
@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
25001
Write @var{data} (a binary buffer) to the open file corresponding
25002
to @var{fd}.  Start the write at @var{offset} from the start of the
25003
file.  Unlike many @code{write} system calls, there is no
25004
separate @var{count} argument; the length of @var{data} in the
25005
packet is used.  @samp{vFile:write} returns the number of bytes written,
25006
which may be shorter than the length of @var{data}, or -1 if an
25007
error occurred.
25008
 
25009
@item vFile:unlink: @var{pathname}
25010
Delete the file at @var{pathname} on the target.  Return 0,
25011
or -1 if an error occurs.  @var{pathname} is a string.
25012
 
25013
@end table
25014
 
25015
@node Interrupts
25016
@section Interrupts
25017
@cindex interrupts (remote protocol)
25018
 
25019
When a program on the remote target is running, @value{GDBN} may
25020
attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
25021
control of which is specified via @value{GDBN}'s @samp{remotebreak}
25022
setting (@pxref{set remotebreak}).
25023
 
25024
The precise meaning of @code{BREAK} is defined by the transport
25025
mechanism and may, in fact, be undefined.  @value{GDBN} does
25026
not currently define a @code{BREAK} mechanism for any of the network
25027
interfaces.
25028
 
25029
@samp{Ctrl-C}, on the other hand, is defined and implemented for all
25030
transport mechanisms.  It is represented by sending the single byte
25031
@code{0x03} without any of the usual packet overhead described in
25032
the Overview section (@pxref{Overview}).  When a @code{0x03} byte is
25033
transmitted as part of a packet, it is considered to be packet data
25034
and does @emph{not} represent an interrupt.  E.g., an @samp{X} packet
25035
(@pxref{X packet}), used for binary downloads, may include an unescaped
25036
@code{0x03} as part of its packet.
25037
 
25038
Stubs are not required to recognize these interrupt mechanisms and the
25039
precise meaning associated with receipt of the interrupt is
25040
implementation defined.  If the stub is successful at interrupting the
25041
running program, it is expected that it will send one of the Stop
25042
Reply Packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
25043
of successfully stopping the program.  Interrupts received while the
25044
program is stopped will be discarded.
25045
 
25046
@node Examples
25047
@section Examples
25048
 
25049
Example sequence of a target being re-started.  Notice how the restart
25050
does not get any direct output:
25051
 
25052
@smallexample
25053
-> @code{R00}
25054
<- @code{+}
25055
@emph{target restarts}
25056
-> @code{?}
25057
<- @code{+}
25058
<- @code{T001:1234123412341234}
25059
-> @code{+}
25060
@end smallexample
25061
 
25062
Example sequence of a target being stepped by a single instruction:
25063
 
25064
@smallexample
25065
-> @code{G1445@dots{}}
25066
<- @code{+}
25067
-> @code{s}
25068
<- @code{+}
25069
@emph{time passes}
25070
<- @code{T001:1234123412341234}
25071
-> @code{+}
25072
-> @code{g}
25073
<- @code{+}
25074
<- @code{1455@dots{}}
25075
-> @code{+}
25076
@end smallexample
25077
 
25078
@node File-I/O Remote Protocol Extension
25079
@section File-I/O Remote Protocol Extension
25080
@cindex File-I/O remote protocol extension
25081
 
25082
@menu
25083
* File-I/O Overview::
25084
* Protocol Basics::
25085
* The F Request Packet::
25086
* The F Reply Packet::
25087
* The Ctrl-C Message::
25088
* Console I/O::
25089
* List of Supported Calls::
25090
* Protocol-specific Representation of Datatypes::
25091
* Constants::
25092
* File-I/O Examples::
25093
@end menu
25094
 
25095
@node File-I/O Overview
25096
@subsection File-I/O Overview
25097
@cindex file-i/o overview
25098
 
25099
The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
25100
target to use the host's file system and console I/O to perform various
25101
system calls.  System calls on the target system are translated into a
25102
remote protocol packet to the host system, which then performs the needed
25103
actions and returns a response packet to the target system.
25104
This simulates file system operations even on targets that lack file systems.
25105
 
25106
The protocol is defined to be independent of both the host and target systems.
25107
It uses its own internal representation of datatypes and values.  Both
25108
@value{GDBN} and the target's @value{GDBN} stub are responsible for
25109
translating the system-dependent value representations into the internal
25110
protocol representations when data is transmitted.
25111
 
25112
The communication is synchronous.  A system call is possible only when
25113
@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
25114
or @samp{s} packets.  While @value{GDBN} handles the request for a system call,
25115
the target is stopped to allow deterministic access to the target's
25116
memory.  Therefore File-I/O is not interruptible by target signals.  On
25117
the other hand, it is possible to interrupt File-I/O by a user interrupt
25118
(@samp{Ctrl-C}) within @value{GDBN}.
25119
 
25120
The target's request to perform a host system call does not finish
25121
the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action.  That means,
25122
after finishing the system call, the target returns to continuing the
25123
previous activity (continue, step).  No additional continue or step
25124
request from @value{GDBN} is required.
25125
 
25126
@smallexample
25127
(@value{GDBP}) continue
25128
  <- target requests 'system call X'
25129
  target is stopped, @value{GDBN} executes system call
25130
  -> @value{GDBN} returns result
25131
  ... target continues, @value{GDBN} returns to wait for the target
25132
  <- target hits breakpoint and sends a Txx packet
25133
@end smallexample
25134
 
25135
The protocol only supports I/O on the console and to regular files on
25136
the host file system.  Character or block special devices, pipes,
25137
named pipes, sockets or any other communication method on the host
25138
system are not supported by this protocol.
25139
 
25140
@node Protocol Basics
25141
@subsection Protocol Basics
25142
@cindex protocol basics, file-i/o
25143
 
25144
The File-I/O protocol uses the @code{F} packet as the request as well
25145
as reply packet.  Since a File-I/O system call can only occur when
25146
@value{GDBN} is waiting for a response from the continuing or stepping target,
25147
the File-I/O request is a reply that @value{GDBN} has to expect as a result
25148
of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
25149
This @code{F} packet contains all information needed to allow @value{GDBN}
25150
to call the appropriate host system call:
25151
 
25152
@itemize @bullet
25153
@item
25154
A unique identifier for the requested system call.
25155
 
25156
@item
25157
All parameters to the system call.  Pointers are given as addresses
25158
in the target memory address space.  Pointers to strings are given as
25159
pointer/length pair.  Numerical values are given as they are.
25160
Numerical control flags are given in a protocol-specific representation.
25161
 
25162
@end itemize
25163
 
25164
At this point, @value{GDBN} has to perform the following actions.
25165
 
25166
@itemize @bullet
25167
@item
25168
If the parameters include pointer values to data needed as input to a
25169
system call, @value{GDBN} requests this data from the target with a
25170
standard @code{m} packet request.  This additional communication has to be
25171
expected by the target implementation and is handled as any other @code{m}
25172
packet.
25173
 
25174
@item
25175
@value{GDBN} translates all value from protocol representation to host
25176
representation as needed.  Datatypes are coerced into the host types.
25177
 
25178
@item
25179
@value{GDBN} calls the system call.
25180
 
25181
@item
25182
It then coerces datatypes back to protocol representation.
25183
 
25184
@item
25185
If the system call is expected to return data in buffer space specified
25186
by pointer parameters to the call, the data is transmitted to the
25187
target using a @code{M} or @code{X} packet.  This packet has to be expected
25188
by the target implementation and is handled as any other @code{M} or @code{X}
25189
packet.
25190
 
25191
@end itemize
25192
 
25193
Eventually @value{GDBN} replies with another @code{F} packet which contains all
25194
necessary information for the target to continue.  This at least contains
25195
 
25196
@itemize @bullet
25197
@item
25198
Return value.
25199
 
25200
@item
25201
@code{errno}, if has been changed by the system call.
25202
 
25203
@item
25204
``Ctrl-C'' flag.
25205
 
25206
@end itemize
25207
 
25208
After having done the needed type and value coercion, the target continues
25209
the latest continue or step action.
25210
 
25211
@node The F Request Packet
25212
@subsection The @code{F} Request Packet
25213
@cindex file-i/o request packet
25214
@cindex @code{F} request packet
25215
 
25216
The @code{F} request packet has the following format:
25217
 
25218
@table @samp
25219
@item F@var{call-id},@var{parameter@dots{}}
25220
 
25221
@var{call-id} is the identifier to indicate the host system call to be called.
25222
This is just the name of the function.
25223
 
25224
@var{parameter@dots{}} are the parameters to the system call.
25225
Parameters are hexadecimal integer values, either the actual values in case
25226
of scalar datatypes, pointers to target buffer space in case of compound
25227
datatypes and unspecified memory areas, or pointer/length pairs in case
25228
of string parameters.  These are appended to the @var{call-id} as a
25229
comma-delimited list.  All values are transmitted in ASCII
25230
string representation, pointer/length pairs separated by a slash.
25231
 
25232
@end table
25233
 
25234
 
25235
 
25236
@node The F Reply Packet
25237
@subsection The @code{F} Reply Packet
25238
@cindex file-i/o reply packet
25239
@cindex @code{F} reply packet
25240
 
25241
The @code{F} reply packet has the following format:
25242
 
25243
@table @samp
25244
 
25245
@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
25246
 
25247
@var{retcode} is the return code of the system call as hexadecimal value.
25248
 
25249
@var{errno} is the @code{errno} set by the call, in protocol-specific
25250
representation.
25251
This parameter can be omitted if the call was successful.
25252
 
25253
@var{Ctrl-C flag} is only sent if the user requested a break.  In this
25254
case, @var{errno} must be sent as well, even if the call was successful.
25255
The @var{Ctrl-C flag} itself consists of the character @samp{C}:
25256
 
25257
@smallexample
25258
F0,0,C
25259
@end smallexample
25260
 
25261
@noindent
25262
or, if the call was interrupted before the host call has been performed:
25263
 
25264
@smallexample
25265
F-1,4,C
25266
@end smallexample
25267
 
25268
@noindent
25269
assuming 4 is the protocol-specific representation of @code{EINTR}.
25270
 
25271
@end table
25272
 
25273
 
25274
@node The Ctrl-C Message
25275
@subsection The @samp{Ctrl-C} Message
25276
@cindex ctrl-c message, in file-i/o protocol
25277
 
25278
If the @samp{Ctrl-C} flag is set in the @value{GDBN}
25279
reply packet (@pxref{The F Reply Packet}),
25280
the target should behave as if it had
25281
gotten a break message.  The meaning for the target is ``system call
25282
interrupted by @code{SIGINT}''.  Consequentially, the target should actually stop
25283
(as with a break message) and return to @value{GDBN} with a @code{T02}
25284
packet.
25285
 
25286
It's important for the target to know in which
25287
state the system call was interrupted.  There are two possible cases:
25288
 
25289
@itemize @bullet
25290
@item
25291
The system call hasn't been performed on the host yet.
25292
 
25293
@item
25294
The system call on the host has been finished.
25295
 
25296
@end itemize
25297
 
25298
These two states can be distinguished by the target by the value of the
25299
returned @code{errno}.  If it's the protocol representation of @code{EINTR}, the system
25300
call hasn't been performed.  This is equivalent to the @code{EINTR} handling
25301
on POSIX systems.  In any other case, the target may presume that the
25302
system call has been finished --- successfully or not --- and should behave
25303
as if the break message arrived right after the system call.
25304
 
25305
@value{GDBN} must behave reliably.  If the system call has not been called
25306
yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
25307
@code{errno} in the packet.  If the system call on the host has been finished
25308
before the user requests a break, the full action must be finished by
25309
@value{GDBN}.  This requires sending @code{M} or @code{X} packets as necessary.
25310
The @code{F} packet may only be sent when either nothing has happened
25311
or the full action has been completed.
25312
 
25313
@node Console I/O
25314
@subsection Console I/O
25315
@cindex console i/o as part of file-i/o
25316
 
25317
By default and if not explicitly closed by the target system, the file
25318
descriptors 0, 1 and 2 are connected to the @value{GDBN} console.  Output
25319
on the @value{GDBN} console is handled as any other file output operation
25320
(@code{write(1, @dots{})} or @code{write(2, @dots{})}).  Console input is handled
25321
by @value{GDBN} so that after the target read request from file descriptor
25322
 
25323
conditions is met:
25324
 
25325
@itemize @bullet
25326
@item
25327
The user types @kbd{Ctrl-c}.  The behaviour is as explained above, and the
25328
@code{read}
25329
system call is treated as finished.
25330
 
25331
@item
25332
The user presses @key{RET}.  This is treated as end of input with a trailing
25333
newline.
25334
 
25335
@item
25336
The user types @kbd{Ctrl-d}.  This is treated as end of input.  No trailing
25337
character (neither newline nor @samp{Ctrl-D}) is appended to the input.
25338
 
25339
@end itemize
25340
 
25341
If the user has typed more characters than fit in the buffer given to
25342
the @code{read} call, the trailing characters are buffered in @value{GDBN} until
25343
either another @code{read(0, @dots{})} is requested by the target, or debugging
25344
is stopped at the user's request.
25345
 
25346
 
25347
@node List of Supported Calls
25348
@subsection List of Supported Calls
25349
@cindex list of supported file-i/o calls
25350
 
25351
@menu
25352
* open::
25353
* close::
25354
* read::
25355
* write::
25356
* lseek::
25357
* rename::
25358
* unlink::
25359
* stat/fstat::
25360
* gettimeofday::
25361
* isatty::
25362
* system::
25363
@end menu
25364
 
25365
@node open
25366
@unnumberedsubsubsec open
25367
@cindex open, file-i/o system call
25368
 
25369
@table @asis
25370
@item Synopsis:
25371
@smallexample
25372
int open(const char *pathname, int flags);
25373
int open(const char *pathname, int flags, mode_t mode);
25374
@end smallexample
25375
 
25376
@item Request:
25377
@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
25378
 
25379
@noindent
25380
@var{flags} is the bitwise @code{OR} of the following values:
25381
 
25382
@table @code
25383
@item O_CREAT
25384
If the file does not exist it will be created.  The host
25385
rules apply as far as file ownership and time stamps
25386
are concerned.
25387
 
25388
@item O_EXCL
25389
When used with @code{O_CREAT}, if the file already exists it is
25390
an error and open() fails.
25391
 
25392
@item O_TRUNC
25393
If the file already exists and the open mode allows
25394
writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
25395
truncated to zero length.
25396
 
25397
@item O_APPEND
25398
The file is opened in append mode.
25399
 
25400
@item O_RDONLY
25401
The file is opened for reading only.
25402
 
25403
@item O_WRONLY
25404
The file is opened for writing only.
25405
 
25406
@item O_RDWR
25407
The file is opened for reading and writing.
25408
@end table
25409
 
25410
@noindent
25411
Other bits are silently ignored.
25412
 
25413
 
25414
@noindent
25415
@var{mode} is the bitwise @code{OR} of the following values:
25416
 
25417
@table @code
25418
@item S_IRUSR
25419
User has read permission.
25420
 
25421
@item S_IWUSR
25422
User has write permission.
25423
 
25424
@item S_IRGRP
25425
Group has read permission.
25426
 
25427
@item S_IWGRP
25428
Group has write permission.
25429
 
25430
@item S_IROTH
25431
Others have read permission.
25432
 
25433
@item S_IWOTH
25434
Others have write permission.
25435
@end table
25436
 
25437
@noindent
25438
Other bits are silently ignored.
25439
 
25440
 
25441
@item Return value:
25442
@code{open} returns the new file descriptor or -1 if an error
25443
occurred.
25444
 
25445
@item Errors:
25446
 
25447
@table @code
25448
@item EEXIST
25449
@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
25450
 
25451
@item EISDIR
25452
@var{pathname} refers to a directory.
25453
 
25454
@item EACCES
25455
The requested access is not allowed.
25456
 
25457
@item ENAMETOOLONG
25458
@var{pathname} was too long.
25459
 
25460
@item ENOENT
25461
A directory component in @var{pathname} does not exist.
25462
 
25463
@item ENODEV
25464
@var{pathname} refers to a device, pipe, named pipe or socket.
25465
 
25466
@item EROFS
25467
@var{pathname} refers to a file on a read-only filesystem and
25468
write access was requested.
25469
 
25470
@item EFAULT
25471
@var{pathname} is an invalid pointer value.
25472
 
25473
@item ENOSPC
25474
No space on device to create the file.
25475
 
25476
@item EMFILE
25477
The process already has the maximum number of files open.
25478
 
25479
@item ENFILE
25480
The limit on the total number of files open on the system
25481
has been reached.
25482
 
25483
@item EINTR
25484
The call was interrupted by the user.
25485
@end table
25486
 
25487
@end table
25488
 
25489
@node close
25490
@unnumberedsubsubsec close
25491
@cindex close, file-i/o system call
25492
 
25493
@table @asis
25494
@item Synopsis:
25495
@smallexample
25496
int close(int fd);
25497
@end smallexample
25498
 
25499
@item Request:
25500
@samp{Fclose,@var{fd}}
25501
 
25502
@item Return value:
25503
@code{close} returns zero on success, or -1 if an error occurred.
25504
 
25505
@item Errors:
25506
 
25507
@table @code
25508
@item EBADF
25509
@var{fd} isn't a valid open file descriptor.
25510
 
25511
@item EINTR
25512
The call was interrupted by the user.
25513
@end table
25514
 
25515
@end table
25516
 
25517
@node read
25518
@unnumberedsubsubsec read
25519
@cindex read, file-i/o system call
25520
 
25521
@table @asis
25522
@item Synopsis:
25523
@smallexample
25524
int read(int fd, void *buf, unsigned int count);
25525
@end smallexample
25526
 
25527
@item Request:
25528
@samp{Fread,@var{fd},@var{bufptr},@var{count}}
25529
 
25530
@item Return value:
25531
On success, the number of bytes read is returned.
25532
Zero indicates end of file.  If count is zero, read
25533
returns zero as well.  On error, -1 is returned.
25534
 
25535
@item Errors:
25536
 
25537
@table @code
25538
@item EBADF
25539
@var{fd} is not a valid file descriptor or is not open for
25540
reading.
25541
 
25542
@item EFAULT
25543
@var{bufptr} is an invalid pointer value.
25544
 
25545
@item EINTR
25546
The call was interrupted by the user.
25547
@end table
25548
 
25549
@end table
25550
 
25551
@node write
25552
@unnumberedsubsubsec write
25553
@cindex write, file-i/o system call
25554
 
25555
@table @asis
25556
@item Synopsis:
25557
@smallexample
25558
int write(int fd, const void *buf, unsigned int count);
25559
@end smallexample
25560
 
25561
@item Request:
25562
@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
25563
 
25564
@item Return value:
25565
On success, the number of bytes written are returned.
25566
Zero indicates nothing was written.  On error, -1
25567
is returned.
25568
 
25569
@item Errors:
25570
 
25571
@table @code
25572
@item EBADF
25573
@var{fd} is not a valid file descriptor or is not open for
25574
writing.
25575
 
25576
@item EFAULT
25577
@var{bufptr} is an invalid pointer value.
25578
 
25579
@item EFBIG
25580
An attempt was made to write a file that exceeds the
25581
host-specific maximum file size allowed.
25582
 
25583
@item ENOSPC
25584
No space on device to write the data.
25585
 
25586
@item EINTR
25587
The call was interrupted by the user.
25588
@end table
25589
 
25590
@end table
25591
 
25592
@node lseek
25593
@unnumberedsubsubsec lseek
25594
@cindex lseek, file-i/o system call
25595
 
25596
@table @asis
25597
@item Synopsis:
25598
@smallexample
25599
long lseek (int fd, long offset, int flag);
25600
@end smallexample
25601
 
25602
@item Request:
25603
@samp{Flseek,@var{fd},@var{offset},@var{flag}}
25604
 
25605
@var{flag} is one of:
25606
 
25607
@table @code
25608
@item SEEK_SET
25609
The offset is set to @var{offset} bytes.
25610
 
25611
@item SEEK_CUR
25612
The offset is set to its current location plus @var{offset}
25613
bytes.
25614
 
25615
@item SEEK_END
25616
The offset is set to the size of the file plus @var{offset}
25617
bytes.
25618
@end table
25619
 
25620
@item Return value:
25621
On success, the resulting unsigned offset in bytes from
25622
the beginning of the file is returned.  Otherwise, a
25623
value of -1 is returned.
25624
 
25625
@item Errors:
25626
 
25627
@table @code
25628
@item EBADF
25629
@var{fd} is not a valid open file descriptor.
25630
 
25631
@item ESPIPE
25632
@var{fd} is associated with the @value{GDBN} console.
25633
 
25634
@item EINVAL
25635
@var{flag} is not a proper value.
25636
 
25637
@item EINTR
25638
The call was interrupted by the user.
25639
@end table
25640
 
25641
@end table
25642
 
25643
@node rename
25644
@unnumberedsubsubsec rename
25645
@cindex rename, file-i/o system call
25646
 
25647
@table @asis
25648
@item Synopsis:
25649
@smallexample
25650
int rename(const char *oldpath, const char *newpath);
25651
@end smallexample
25652
 
25653
@item Request:
25654
@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
25655
 
25656
@item Return value:
25657
On success, zero is returned.  On error, -1 is returned.
25658
 
25659
@item Errors:
25660
 
25661
@table @code
25662
@item EISDIR
25663
@var{newpath} is an existing directory, but @var{oldpath} is not a
25664
directory.
25665
 
25666
@item EEXIST
25667
@var{newpath} is a non-empty directory.
25668
 
25669
@item EBUSY
25670
@var{oldpath} or @var{newpath} is a directory that is in use by some
25671
process.
25672
 
25673
@item EINVAL
25674
An attempt was made to make a directory a subdirectory
25675
of itself.
25676
 
25677
@item ENOTDIR
25678
A  component used as a directory in @var{oldpath} or new
25679
path is not a directory.  Or @var{oldpath} is a directory
25680
and @var{newpath} exists but is not a directory.
25681
 
25682
@item EFAULT
25683
@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
25684
 
25685
@item EACCES
25686
No access to the file or the path of the file.
25687
 
25688
@item ENAMETOOLONG
25689
 
25690
@var{oldpath} or @var{newpath} was too long.
25691
 
25692
@item ENOENT
25693
A directory component in @var{oldpath} or @var{newpath} does not exist.
25694
 
25695
@item EROFS
25696
The file is on a read-only filesystem.
25697
 
25698
@item ENOSPC
25699
The device containing the file has no room for the new
25700
directory entry.
25701
 
25702
@item EINTR
25703
The call was interrupted by the user.
25704
@end table
25705
 
25706
@end table
25707
 
25708
@node unlink
25709
@unnumberedsubsubsec unlink
25710
@cindex unlink, file-i/o system call
25711
 
25712
@table @asis
25713
@item Synopsis:
25714
@smallexample
25715
int unlink(const char *pathname);
25716
@end smallexample
25717
 
25718
@item Request:
25719
@samp{Funlink,@var{pathnameptr}/@var{len}}
25720
 
25721
@item Return value:
25722
On success, zero is returned.  On error, -1 is returned.
25723
 
25724
@item Errors:
25725
 
25726
@table @code
25727
@item EACCES
25728
No access to the file or the path of the file.
25729
 
25730
@item EPERM
25731
The system does not allow unlinking of directories.
25732
 
25733
@item EBUSY
25734
The file @var{pathname} cannot be unlinked because it's
25735
being used by another process.
25736
 
25737
@item EFAULT
25738
@var{pathnameptr} is an invalid pointer value.
25739
 
25740
@item ENAMETOOLONG
25741
@var{pathname} was too long.
25742
 
25743
@item ENOENT
25744
A directory component in @var{pathname} does not exist.
25745
 
25746
@item ENOTDIR
25747
A component of the path is not a directory.
25748
 
25749
@item EROFS
25750
The file is on a read-only filesystem.
25751
 
25752
@item EINTR
25753
The call was interrupted by the user.
25754
@end table
25755
 
25756
@end table
25757
 
25758
@node stat/fstat
25759
@unnumberedsubsubsec stat/fstat
25760
@cindex fstat, file-i/o system call
25761
@cindex stat, file-i/o system call
25762
 
25763
@table @asis
25764
@item Synopsis:
25765
@smallexample
25766
int stat(const char *pathname, struct stat *buf);
25767
int fstat(int fd, struct stat *buf);
25768
@end smallexample
25769
 
25770
@item Request:
25771
@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
25772
@samp{Ffstat,@var{fd},@var{bufptr}}
25773
 
25774
@item Return value:
25775
On success, zero is returned.  On error, -1 is returned.
25776
 
25777
@item Errors:
25778
 
25779
@table @code
25780
@item EBADF
25781
@var{fd} is not a valid open file.
25782
 
25783
@item ENOENT
25784
A directory component in @var{pathname} does not exist or the
25785
path is an empty string.
25786
 
25787
@item ENOTDIR
25788
A component of the path is not a directory.
25789
 
25790
@item EFAULT
25791
@var{pathnameptr} is an invalid pointer value.
25792
 
25793
@item EACCES
25794
No access to the file or the path of the file.
25795
 
25796
@item ENAMETOOLONG
25797
@var{pathname} was too long.
25798
 
25799
@item EINTR
25800
The call was interrupted by the user.
25801
@end table
25802
 
25803
@end table
25804
 
25805
@node gettimeofday
25806
@unnumberedsubsubsec gettimeofday
25807
@cindex gettimeofday, file-i/o system call
25808
 
25809
@table @asis
25810
@item Synopsis:
25811
@smallexample
25812
int gettimeofday(struct timeval *tv, void *tz);
25813
@end smallexample
25814
 
25815
@item Request:
25816
@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
25817
 
25818
@item Return value:
25819
On success, 0 is returned, -1 otherwise.
25820
 
25821
@item Errors:
25822
 
25823
@table @code
25824
@item EINVAL
25825
@var{tz} is a non-NULL pointer.
25826
 
25827
@item EFAULT
25828
@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
25829
@end table
25830
 
25831
@end table
25832
 
25833
@node isatty
25834
@unnumberedsubsubsec isatty
25835
@cindex isatty, file-i/o system call
25836
 
25837
@table @asis
25838
@item Synopsis:
25839
@smallexample
25840
int isatty(int fd);
25841
@end smallexample
25842
 
25843
@item Request:
25844
@samp{Fisatty,@var{fd}}
25845
 
25846
@item Return value:
25847
Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
25848
 
25849
@item Errors:
25850
 
25851
@table @code
25852
@item EINTR
25853
The call was interrupted by the user.
25854
@end table
25855
 
25856
@end table
25857
 
25858
Note that the @code{isatty} call is treated as a special case: it returns
25859
1 to the target if the file descriptor is attached
25860
to the @value{GDBN} console, 0 otherwise.  Implementing through system calls
25861
would require implementing @code{ioctl} and would be more complex than
25862
needed.
25863
 
25864
 
25865
@node system
25866
@unnumberedsubsubsec system
25867
@cindex system, file-i/o system call
25868
 
25869
@table @asis
25870
@item Synopsis:
25871
@smallexample
25872
int system(const char *command);
25873
@end smallexample
25874
 
25875
@item Request:
25876
@samp{Fsystem,@var{commandptr}/@var{len}}
25877
 
25878
@item Return value:
25879
If @var{len} is zero, the return value indicates whether a shell is
25880
available.  A zero return value indicates a shell is not available.
25881
For non-zero @var{len}, the value returned is -1 on error and the
25882
return status of the command otherwise.  Only the exit status of the
25883
command is returned, which is extracted from the host's @code{system}
25884
return value by calling @code{WEXITSTATUS(retval)}.  In case
25885
@file{/bin/sh} could not be executed, 127 is returned.
25886
 
25887
@item Errors:
25888
 
25889
@table @code
25890
@item EINTR
25891
The call was interrupted by the user.
25892
@end table
25893
 
25894
@end table
25895
 
25896
@value{GDBN} takes over the full task of calling the necessary host calls
25897
to perform the @code{system} call.  The return value of @code{system} on
25898
the host is simplified before it's returned
25899
to the target.  Any termination signal information from the child process
25900
is discarded, and the return value consists
25901
entirely of the exit status of the called command.
25902
 
25903
Due to security concerns, the @code{system} call is by default refused
25904
by @value{GDBN}.  The user has to allow this call explicitly with the
25905
@code{set remote system-call-allowed 1} command.
25906
 
25907
@table @code
25908
@item set remote system-call-allowed
25909
@kindex set remote system-call-allowed
25910
Control whether to allow the @code{system} calls in the File I/O
25911
protocol for the remote target.  The default is zero (disabled).
25912
 
25913
@item show remote system-call-allowed
25914
@kindex show remote system-call-allowed
25915
Show whether the @code{system} calls are allowed in the File I/O
25916
protocol.
25917
@end table
25918
 
25919
@node Protocol-specific Representation of Datatypes
25920
@subsection Protocol-specific Representation of Datatypes
25921
@cindex protocol-specific representation of datatypes, in file-i/o protocol
25922
 
25923
@menu
25924
* Integral Datatypes::
25925
* Pointer Values::
25926
* Memory Transfer::
25927
* struct stat::
25928
* struct timeval::
25929
@end menu
25930
 
25931
@node Integral Datatypes
25932
@unnumberedsubsubsec Integral Datatypes
25933
@cindex integral datatypes, in file-i/o protocol
25934
 
25935
The integral datatypes used in the system calls are @code{int},
25936
@code{unsigned int}, @code{long}, @code{unsigned long},
25937
@code{mode_t}, and @code{time_t}.
25938
 
25939
@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
25940
implemented as 32 bit values in this protocol.
25941
 
25942
@code{long} and @code{unsigned long} are implemented as 64 bit types.
25943
 
25944
@xref{Limits}, for corresponding MIN and MAX values (similar to those
25945
in @file{limits.h}) to allow range checking on host and target.
25946
 
25947
@code{time_t} datatypes are defined as seconds since the Epoch.
25948
 
25949
All integral datatypes transferred as part of a memory read or write of a
25950
structured datatype e.g.@: a @code{struct stat} have to be given in big endian
25951
byte order.
25952
 
25953
@node Pointer Values
25954
@unnumberedsubsubsec Pointer Values
25955
@cindex pointer values, in file-i/o protocol
25956
 
25957
Pointers to target data are transmitted as they are.  An exception
25958
is made for pointers to buffers for which the length isn't
25959
transmitted as part of the function call, namely strings.  Strings
25960
are transmitted as a pointer/length pair, both as hex values, e.g.@:
25961
 
25962
@smallexample
25963
@code{1aaf/12}
25964
@end smallexample
25965
 
25966
@noindent
25967
which is a pointer to data of length 18 bytes at position 0x1aaf.
25968
The length is defined as the full string length in bytes, including
25969
the trailing null byte.  For example, the string @code{"hello world"}
25970
at address 0x123456 is transmitted as
25971
 
25972
@smallexample
25973
@code{123456/d}
25974
@end smallexample
25975
 
25976
@node Memory Transfer
25977
@unnumberedsubsubsec Memory Transfer
25978
@cindex memory transfer, in file-i/o protocol
25979
 
25980
Structured data which is transferred using a memory read or write (for
25981
example, a @code{struct stat}) is expected to be in a protocol-specific format
25982
with all scalar multibyte datatypes being big endian.  Translation to
25983
this representation needs to be done both by the target before the @code{F}
25984
packet is sent, and by @value{GDBN} before
25985
it transfers memory to the target.  Transferred pointers to structured
25986
data should point to the already-coerced data at any time.
25987
 
25988
 
25989
@node struct stat
25990
@unnumberedsubsubsec struct stat
25991
@cindex struct stat, in file-i/o protocol
25992
 
25993
The buffer of type @code{struct stat} used by the target and @value{GDBN}
25994
is defined as follows:
25995
 
25996
@smallexample
25997
struct stat @{
25998
    unsigned int  st_dev;      /* device */
25999
    unsigned int  st_ino;      /* inode */
26000
    mode_t        st_mode;     /* protection */
26001
    unsigned int  st_nlink;    /* number of hard links */
26002
    unsigned int  st_uid;      /* user ID of owner */
26003
    unsigned int  st_gid;      /* group ID of owner */
26004
    unsigned int  st_rdev;     /* device type (if inode device) */
26005
    unsigned long st_size;     /* total size, in bytes */
26006
    unsigned long st_blksize;  /* blocksize for filesystem I/O */
26007
    unsigned long st_blocks;   /* number of blocks allocated */
26008
    time_t        st_atime;    /* time of last access */
26009
    time_t        st_mtime;    /* time of last modification */
26010
    time_t        st_ctime;    /* time of last change */
26011
@};
26012
@end smallexample
26013
 
26014
The integral datatypes conform to the definitions given in the
26015
appropriate section (see @ref{Integral Datatypes}, for details) so this
26016
structure is of size 64 bytes.
26017
 
26018
The values of several fields have a restricted meaning and/or
26019
range of values.
26020
 
26021
@table @code
26022
 
26023
@item st_dev
26024
A value of 0 represents a file, 1 the console.
26025
 
26026
@item st_ino
26027
No valid meaning for the target.  Transmitted unchanged.
26028
 
26029
@item st_mode
26030
Valid mode bits are described in @ref{Constants}.  Any other
26031
bits have currently no meaning for the target.
26032
 
26033
@item st_uid
26034
@itemx st_gid
26035
@itemx st_rdev
26036
No valid meaning for the target.  Transmitted unchanged.
26037
 
26038
@item st_atime
26039
@itemx st_mtime
26040
@itemx st_ctime
26041
These values have a host and file system dependent
26042
accuracy.  Especially on Windows hosts, the file system may not
26043
support exact timing values.
26044
@end table
26045
 
26046
The target gets a @code{struct stat} of the above representation and is
26047
responsible for coercing it to the target representation before
26048
continuing.
26049
 
26050
Note that due to size differences between the host, target, and protocol
26051
representations of @code{struct stat} members, these members could eventually
26052
get truncated on the target.
26053
 
26054
@node struct timeval
26055
@unnumberedsubsubsec struct timeval
26056
@cindex struct timeval, in file-i/o protocol
26057
 
26058
The buffer of type @code{struct timeval} used by the File-I/O protocol
26059
is defined as follows:
26060
 
26061
@smallexample
26062
struct timeval @{
26063
    time_t tv_sec;  /* second */
26064
    long   tv_usec; /* microsecond */
26065
@};
26066
@end smallexample
26067
 
26068
The integral datatypes conform to the definitions given in the
26069
appropriate section (see @ref{Integral Datatypes}, for details) so this
26070
structure is of size 8 bytes.
26071
 
26072
@node Constants
26073
@subsection Constants
26074
@cindex constants, in file-i/o protocol
26075
 
26076
The following values are used for the constants inside of the
26077
protocol.  @value{GDBN} and target are responsible for translating these
26078
values before and after the call as needed.
26079
 
26080
@menu
26081
* Open Flags::
26082
* mode_t Values::
26083
* Errno Values::
26084
* Lseek Flags::
26085
* Limits::
26086
@end menu
26087
 
26088
@node Open Flags
26089
@unnumberedsubsubsec Open Flags
26090
@cindex open flags, in file-i/o protocol
26091
 
26092
All values are given in hexadecimal representation.
26093
 
26094
@smallexample
26095
  O_RDONLY        0x0
26096
  O_WRONLY        0x1
26097
  O_RDWR          0x2
26098
  O_APPEND        0x8
26099
  O_CREAT       0x200
26100
  O_TRUNC       0x400
26101
  O_EXCL        0x800
26102
@end smallexample
26103
 
26104
@node mode_t Values
26105
@unnumberedsubsubsec mode_t Values
26106
@cindex mode_t values, in file-i/o protocol
26107
 
26108
All values are given in octal representation.
26109
 
26110
@smallexample
26111
  S_IFREG       0100000
26112
  S_IFDIR        040000
26113
  S_IRUSR          0400
26114
  S_IWUSR          0200
26115
  S_IXUSR          0100
26116
  S_IRGRP           040
26117
  S_IWGRP           020
26118
  S_IXGRP           010
26119
  S_IROTH            04
26120
  S_IWOTH            02
26121
  S_IXOTH            01
26122
@end smallexample
26123
 
26124
@node Errno Values
26125
@unnumberedsubsubsec Errno Values
26126
@cindex errno values, in file-i/o protocol
26127
 
26128
All values are given in decimal representation.
26129
 
26130
@smallexample
26131
  EPERM           1
26132
  ENOENT          2
26133
  EINTR           4
26134
  EBADF           9
26135
  EACCES         13
26136
  EFAULT         14
26137
  EBUSY          16
26138
  EEXIST         17
26139
  ENODEV         19
26140
  ENOTDIR        20
26141
  EISDIR         21
26142
  EINVAL         22
26143
  ENFILE         23
26144
  EMFILE         24
26145
  EFBIG          27
26146
  ENOSPC         28
26147
  ESPIPE         29
26148
  EROFS          30
26149
  ENAMETOOLONG   91
26150
  EUNKNOWN       9999
26151
@end smallexample
26152
 
26153
  @code{EUNKNOWN} is used as a fallback error value if a host system returns
26154
  any error value not in the list of supported error numbers.
26155
 
26156
@node Lseek Flags
26157
@unnumberedsubsubsec Lseek Flags
26158
@cindex lseek flags, in file-i/o protocol
26159
 
26160
@smallexample
26161
  SEEK_SET      0
26162
  SEEK_CUR      1
26163
  SEEK_END      2
26164
@end smallexample
26165
 
26166
@node Limits
26167
@unnumberedsubsubsec Limits
26168
@cindex limits, in file-i/o protocol
26169
 
26170
All values are given in decimal representation.
26171
 
26172
@smallexample
26173
  INT_MIN       -2147483648
26174
  INT_MAX        2147483647
26175
  UINT_MAX       4294967295
26176
  LONG_MIN      -9223372036854775808
26177
  LONG_MAX       9223372036854775807
26178
  ULONG_MAX      18446744073709551615
26179
@end smallexample
26180
 
26181
@node File-I/O Examples
26182
@subsection File-I/O Examples
26183
@cindex file-i/o examples
26184
 
26185
Example sequence of a write call, file descriptor 3, buffer is at target
26186
address 0x1234, 6 bytes should be written:
26187
 
26188
@smallexample
26189
<- @code{Fwrite,3,1234,6}
26190
@emph{request memory read from target}
26191
-> @code{m1234,6}
26192
<- XXXXXX
26193
@emph{return "6 bytes written"}
26194
-> @code{F6}
26195
@end smallexample
26196
 
26197
Example sequence of a read call, file descriptor 3, buffer is at target
26198
address 0x1234, 6 bytes should be read:
26199
 
26200
@smallexample
26201
<- @code{Fread,3,1234,6}
26202
@emph{request memory write to target}
26203
-> @code{X1234,6:XXXXXX}
26204
@emph{return "6 bytes read"}
26205
-> @code{F6}
26206
@end smallexample
26207
 
26208
Example sequence of a read call, call fails on the host due to invalid
26209
file descriptor (@code{EBADF}):
26210
 
26211
@smallexample
26212
<- @code{Fread,3,1234,6}
26213
-> @code{F-1,9}
26214
@end smallexample
26215
 
26216
Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
26217
host is called:
26218
 
26219
@smallexample
26220
<- @code{Fread,3,1234,6}
26221
-> @code{F-1,4,C}
26222
<- @code{T02}
26223
@end smallexample
26224
 
26225
Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
26226
host is called:
26227
 
26228
@smallexample
26229
<- @code{Fread,3,1234,6}
26230
-> @code{X1234,6:XXXXXX}
26231
<- @code{T02}
26232
@end smallexample
26233
 
26234
@node Library List Format
26235
@section Library List Format
26236
@cindex library list format, remote protocol
26237
 
26238
On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
26239
same process as your application to manage libraries.  In this case,
26240
@value{GDBN} can use the loader's symbol table and normal memory
26241
operations to maintain a list of shared libraries.  On other
26242
platforms, the operating system manages loaded libraries.
26243
@value{GDBN} can not retrieve the list of currently loaded libraries
26244
through memory operations, so it uses the @samp{qXfer:libraries:read}
26245
packet (@pxref{qXfer library list read}) instead.  The remote stub
26246
queries the target's operating system and reports which libraries
26247
are loaded.
26248
 
26249
The @samp{qXfer:libraries:read} packet returns an XML document which
26250
lists loaded libraries and their offsets.  Each library has an
26251
associated name and one or more segment base addresses, which report
26252
where the library was loaded in memory.  The segment bases are start
26253
addresses, not relocation offsets; they do not depend on the library's
26254
link-time base addresses.
26255
 
26256
@value{GDBN} must be linked with the Expat library to support XML
26257
library lists.  @xref{Expat}.
26258
 
26259
A simple memory map, with one loaded library relocated by a single
26260
offset, looks like this:
26261
 
26262
@smallexample
26263
<library-list>
26264
  <library name="/lib/libc.so.6">
26265
    <segment address="0x10000000"/>
26266
  </library>
26267
</library-list>
26268
@end smallexample
26269
 
26270
The format of a library list is described by this DTD:
26271
 
26272
@smallexample
26273
<!-- library-list: Root element with versioning -->
26274
<!ELEMENT library-list  (library)*>
26275
<!ATTLIST library-list  version CDATA   #FIXED  "1.0">
26276
<!ELEMENT library       (segment)*>
26277
<!ATTLIST library       name    CDATA   #REQUIRED>
26278
<!ELEMENT segment       EMPTY>
26279
<!ATTLIST segment       address CDATA   #REQUIRED>
26280
@end smallexample
26281
 
26282
@node Memory Map Format
26283
@section Memory Map Format
26284
@cindex memory map format
26285
 
26286
To be able to write into flash memory, @value{GDBN} needs to obtain a
26287
memory map from the target.  This section describes the format of the
26288
memory map.
26289
 
26290
The memory map is obtained using the @samp{qXfer:memory-map:read}
26291
(@pxref{qXfer memory map read}) packet and is an XML document that
26292
lists memory regions.
26293
 
26294
@value{GDBN} must be linked with the Expat library to support XML
26295
memory maps.  @xref{Expat}.
26296
 
26297
The top-level structure of the document is shown below:
26298
 
26299
@smallexample
26300
<?xml version="1.0"?>
26301
<!DOCTYPE memory-map
26302
          PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
26303
                 "http://sourceware.org/gdb/gdb-memory-map.dtd">
26304
<memory-map>
26305
    region...
26306
</memory-map>
26307
@end smallexample
26308
 
26309
Each region can be either:
26310
 
26311
@itemize
26312
 
26313
@item
26314
A region of RAM starting at @var{addr} and extending for @var{length}
26315
bytes from there:
26316
 
26317
@smallexample
26318
<memory type="ram" start="@var{addr}" length="@var{length}"/>
26319
@end smallexample
26320
 
26321
 
26322
@item
26323
A region of read-only memory:
26324
 
26325
@smallexample
26326
<memory type="rom" start="@var{addr}" length="@var{length}"/>
26327
@end smallexample
26328
 
26329
 
26330
@item
26331
A region of flash memory, with erasure blocks @var{blocksize}
26332
bytes in length:
26333
 
26334
@smallexample
26335
<memory type="flash" start="@var{addr}" length="@var{length}">
26336
  <property name="blocksize">@var{blocksize}</property>
26337
</memory>
26338
@end smallexample
26339
 
26340
@end itemize
26341
 
26342
Regions must not overlap.  @value{GDBN} assumes that areas of memory not covered
26343
by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
26344
packets to write to addresses in such ranges.
26345
 
26346
The formal DTD for memory map format is given below:
26347
 
26348
@smallexample
26349
<!-- ................................................... -->
26350
<!-- Memory Map XML DTD ................................ -->
26351
<!-- File: memory-map.dtd .............................. -->
26352
<!-- .................................... .............. -->
26353
<!-- memory-map.dtd -->
26354
<!-- memory-map: Root element with versioning -->
26355
<!ELEMENT memory-map (memory | property)>
26356
<!ATTLIST memory-map    version CDATA   #FIXED  "1.0.0">
26357
<!ELEMENT memory (property)>
26358
<!-- memory: Specifies a memory region,
26359
             and its type, or device. -->
26360
<!ATTLIST memory        type    CDATA   #REQUIRED
26361
                        start   CDATA   #REQUIRED
26362
                        length  CDATA   #REQUIRED
26363
                        device  CDATA   #IMPLIED>
26364
<!-- property: Generic attribute tag -->
26365
<!ELEMENT property (#PCDATA | property)*>
26366
<!ATTLIST property      name    CDATA   #REQUIRED>
26367
@end smallexample
26368
 
26369
@include agentexpr.texi
26370
 
26371
@node Target Descriptions
26372
@appendix Target Descriptions
26373
@cindex target descriptions
26374
 
26375
@strong{Warning:} target descriptions are still under active development,
26376
and the contents and format may change between @value{GDBN} releases.
26377
The format is expected to stabilize in the future.
26378
 
26379
One of the challenges of using @value{GDBN} to debug embedded systems
26380
is that there are so many minor variants of each processor
26381
architecture in use.  It is common practice for vendors to start with
26382
a standard processor core --- ARM, PowerPC, or MIPS, for example ---
26383
and then make changes to adapt it to a particular market niche.  Some
26384
architectures have hundreds of variants, available from dozens of
26385
vendors.  This leads to a number of problems:
26386
 
26387
@itemize @bullet
26388
@item
26389
With so many different customized processors, it is difficult for
26390
the @value{GDBN} maintainers to keep up with the changes.
26391
@item
26392
Since individual variants may have short lifetimes or limited
26393
audiences, it may not be worthwhile to carry information about every
26394
variant in the @value{GDBN} source tree.
26395
@item
26396
When @value{GDBN} does support the architecture of the embedded system
26397
at hand, the task of finding the correct architecture name to give the
26398
@command{set architecture} command can be error-prone.
26399
@end itemize
26400
 
26401
To address these problems, the @value{GDBN} remote protocol allows a
26402
target system to not only identify itself to @value{GDBN}, but to
26403
actually describe its own features.  This lets @value{GDBN} support
26404
processor variants it has never seen before --- to the extent that the
26405
descriptions are accurate, and that @value{GDBN} understands them.
26406
 
26407
@value{GDBN} must be linked with the Expat library to support XML
26408
target descriptions.  @xref{Expat}.
26409
 
26410
@menu
26411
* Retrieving Descriptions::         How descriptions are fetched from a target.
26412
* Target Description Format::       The contents of a target description.
26413
* Predefined Target Types::         Standard types available for target
26414
                                    descriptions.
26415
* Standard Target Features::        Features @value{GDBN} knows about.
26416
@end menu
26417
 
26418
@node Retrieving Descriptions
26419
@section Retrieving Descriptions
26420
 
26421
Target descriptions can be read from the target automatically, or
26422
specified by the user manually.  The default behavior is to read the
26423
description from the target.  @value{GDBN} retrieves it via the remote
26424
protocol using @samp{qXfer} requests (@pxref{General Query Packets,
26425
qXfer}).  The @var{annex} in the @samp{qXfer} packet will be
26426
@samp{target.xml}.  The contents of the @samp{target.xml} annex are an
26427
XML document, of the form described in @ref{Target Description
26428
Format}.
26429
 
26430
Alternatively, you can specify a file to read for the target description.
26431
If a file is set, the target will not be queried.  The commands to
26432
specify a file are:
26433
 
26434
@table @code
26435
@cindex set tdesc filename
26436
@item set tdesc filename @var{path}
26437
Read the target description from @var{path}.
26438
 
26439
@cindex unset tdesc filename
26440
@item unset tdesc filename
26441
Do not read the XML target description from a file.  @value{GDBN}
26442
will use the description supplied by the current target.
26443
 
26444
@cindex show tdesc filename
26445
@item show tdesc filename
26446
Show the filename to read for a target description, if any.
26447
@end table
26448
 
26449
 
26450
@node Target Description Format
26451
@section Target Description Format
26452
@cindex target descriptions, XML format
26453
 
26454
A target description annex is an @uref{http://www.w3.org/XML/, XML}
26455
document which complies with the Document Type Definition provided in
26456
the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}.  This
26457
means you can use generally available tools like @command{xmllint} to
26458
check that your feature descriptions are well-formed and valid.
26459
However, to help people unfamiliar with XML write descriptions for
26460
their targets, we also describe the grammar here.
26461
 
26462
Target descriptions can identify the architecture of the remote target
26463
and (for some architectures) provide information about custom register
26464
sets.  @value{GDBN} can use this information to autoconfigure for your
26465
target, or to warn you if you connect to an unsupported target.
26466
 
26467
Here is a simple target description:
26468
 
26469
@smallexample
26470
<target version="1.0">
26471
  <architecture>i386:x86-64</architecture>
26472
</target>
26473
@end smallexample
26474
 
26475
@noindent
26476
This minimal description only says that the target uses
26477
the x86-64 architecture.
26478
 
26479
A target description has the following overall form, with [ ] marking
26480
optional elements and @dots{} marking repeatable elements.  The elements
26481
are explained further below.
26482
 
26483
@smallexample
26484
<?xml version="1.0"?>
26485
<!DOCTYPE target SYSTEM "gdb-target.dtd">
26486
<target version="1.0">
26487
  @r{[}@var{architecture}@r{]}
26488
  @r{[}@var{feature}@dots{}@r{]}
26489
</target>
26490
@end smallexample
26491
 
26492
@noindent
26493
The description is generally insensitive to whitespace and line
26494
breaks, under the usual common-sense rules.  The XML version
26495
declaration and document type declaration can generally be omitted
26496
(@value{GDBN} does not require them), but specifying them may be
26497
useful for XML validation tools.  The @samp{version} attribute for
26498
@samp{<target>} may also be omitted, but we recommend
26499
including it; if future versions of @value{GDBN} use an incompatible
26500
revision of @file{gdb-target.dtd}, they will detect and report
26501
the version mismatch.
26502
 
26503
@subsection Inclusion
26504
@cindex target descriptions, inclusion
26505
@cindex XInclude
26506
@ifnotinfo
26507
@cindex <xi:include>
26508
@end ifnotinfo
26509
 
26510
It can sometimes be valuable to split a target description up into
26511
several different annexes, either for organizational purposes, or to
26512
share files between different possible target descriptions.  You can
26513
divide a description into multiple files by replacing any element of
26514
the target description with an inclusion directive of the form:
26515
 
26516
@smallexample
26517
<xi:include href="@var{document}"/>
26518
@end smallexample
26519
 
26520
@noindent
26521
When @value{GDBN} encounters an element of this form, it will retrieve
26522
the named XML @var{document}, and replace the inclusion directive with
26523
the contents of that document.  If the current description was read
26524
using @samp{qXfer}, then so will be the included document;
26525
@var{document} will be interpreted as the name of an annex.  If the
26526
current description was read from a file, @value{GDBN} will look for
26527
@var{document} as a file in the same directory where it found the
26528
original description.
26529
 
26530
@subsection Architecture
26531
@cindex <architecture>
26532
 
26533
An @samp{<architecture>} element has this form:
26534
 
26535
@smallexample
26536
  <architecture>@var{arch}</architecture>
26537
@end smallexample
26538
 
26539
@var{arch} is an architecture name from the same selection
26540
accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
26541
Debugging Target}).
26542
 
26543
@subsection Features
26544
@cindex <feature>
26545
 
26546
Each @samp{<feature>} describes some logical portion of the target
26547
system.  Features are currently used to describe available CPU
26548
registers and the types of their contents.  A @samp{<feature>} element
26549
has this form:
26550
 
26551
@smallexample
26552
<feature name="@var{name}">
26553
  @r{[}@var{type}@dots{}@r{]}
26554
  @var{reg}@dots{}
26555
</feature>
26556
@end smallexample
26557
 
26558
@noindent
26559
Each feature's name should be unique within the description.  The name
26560
of a feature does not matter unless @value{GDBN} has some special
26561
knowledge of the contents of that feature; if it does, the feature
26562
should have its standard name.  @xref{Standard Target Features}.
26563
 
26564
@subsection Types
26565
 
26566
Any register's value is a collection of bits which @value{GDBN} must
26567
interpret.  The default interpretation is a two's complement integer,
26568
but other types can be requested by name in the register description.
26569
Some predefined types are provided by @value{GDBN} (@pxref{Predefined
26570
Target Types}), and the description can define additional composite types.
26571
 
26572
Each type element must have an @samp{id} attribute, which gives
26573
a unique (within the containing @samp{<feature>}) name to the type.
26574
Types must be defined before they are used.
26575
 
26576
@cindex <vector>
26577
Some targets offer vector registers, which can be treated as arrays
26578
of scalar elements.  These types are written as @samp{<vector>} elements,
26579
specifying the array element type, @var{type}, and the number of elements,
26580
@var{count}:
26581
 
26582
@smallexample
26583
<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
26584
@end smallexample
26585
 
26586
@cindex <union>
26587
If a register's value is usefully viewed in multiple ways, define it
26588
with a union type containing the useful representations.  The
26589
@samp{<union>} element contains one or more @samp{<field>} elements,
26590
each of which has a @var{name} and a @var{type}:
26591
 
26592
@smallexample
26593
<union id="@var{id}">
26594
  <field name="@var{name}" type="@var{type}"/>
26595
  @dots{}
26596
</union>
26597
@end smallexample
26598
 
26599
@subsection Registers
26600
@cindex <reg>
26601
 
26602
Each register is represented as an element with this form:
26603
 
26604
@smallexample
26605
<reg name="@var{name}"
26606
     bitsize="@var{size}"
26607
     @r{[}regnum="@var{num}"@r{]}
26608
     @r{[}save-restore="@var{save-restore}"@r{]}
26609
     @r{[}type="@var{type}"@r{]}
26610
     @r{[}group="@var{group}"@r{]}/>
26611
@end smallexample
26612
 
26613
@noindent
26614
The components are as follows:
26615
 
26616
@table @var
26617
 
26618
@item name
26619
The register's name; it must be unique within the target description.
26620
 
26621
@item bitsize
26622
The register's size, in bits.
26623
 
26624
@item regnum
26625
The register's number.  If omitted, a register's number is one greater
26626
than that of the previous register (either in the current feature or in
26627
a preceeding feature); the first register in the target description
26628
defaults to zero.  This register number is used to read or write
26629
the register; e.g.@: it is used in the remote @code{p} and @code{P}
26630
packets, and registers appear in the @code{g} and @code{G} packets
26631
in order of increasing register number.
26632
 
26633
@item save-restore
26634
Whether the register should be preserved across inferior function
26635
calls; this must be either @code{yes} or @code{no}.  The default is
26636
@code{yes}, which is appropriate for most registers except for
26637
some system control registers; this is not related to the target's
26638
ABI.
26639
 
26640
@item type
26641
The type of the register.  @var{type} may be a predefined type, a type
26642
defined in the current feature, or one of the special types @code{int}
26643
and @code{float}.  @code{int} is an integer type of the correct size
26644
for @var{bitsize}, and @code{float} is a floating point type (in the
26645
architecture's normal floating point format) of the correct size for
26646
@var{bitsize}.  The default is @code{int}.
26647
 
26648
@item group
26649
The register group to which this register belongs.  @var{group} must
26650
be either @code{general}, @code{float}, or @code{vector}.  If no
26651
@var{group} is specified, @value{GDBN} will not display the register
26652
in @code{info registers}.
26653
 
26654
@end table
26655
 
26656
@node Predefined Target Types
26657
@section Predefined Target Types
26658
@cindex target descriptions, predefined types
26659
 
26660
Type definitions in the self-description can build up composite types
26661
from basic building blocks, but can not define fundamental types.  Instead,
26662
standard identifiers are provided by @value{GDBN} for the fundamental
26663
types.  The currently supported types are:
26664
 
26665
@table @code
26666
 
26667
@item int8
26668
@itemx int16
26669
@itemx int32
26670
@itemx int64
26671
@itemx int128
26672
Signed integer types holding the specified number of bits.
26673
 
26674
@item uint8
26675
@itemx uint16
26676
@itemx uint32
26677
@itemx uint64
26678
@itemx uint128
26679
Unsigned integer types holding the specified number of bits.
26680
 
26681
@item code_ptr
26682
@itemx data_ptr
26683
Pointers to unspecified code and data.  The program counter and
26684
any dedicated return address register may be marked as code
26685
pointers; printing a code pointer converts it into a symbolic
26686
address.  The stack pointer and any dedicated address registers
26687
may be marked as data pointers.
26688
 
26689
@item ieee_single
26690
Single precision IEEE floating point.
26691
 
26692
@item ieee_double
26693
Double precision IEEE floating point.
26694
 
26695
@item arm_fpa_ext
26696
The 12-byte extended precision format used by ARM FPA registers.
26697
 
26698
@end table
26699
 
26700
@node Standard Target Features
26701
@section Standard Target Features
26702
@cindex target descriptions, standard features
26703
 
26704
A target description must contain either no registers or all the
26705
target's registers.  If the description contains no registers, then
26706
@value{GDBN} will assume a default register layout, selected based on
26707
the architecture.  If the description contains any registers, the
26708
default layout will not be used; the standard registers must be
26709
described in the target description, in such a way that @value{GDBN}
26710
can recognize them.
26711
 
26712
This is accomplished by giving specific names to feature elements
26713
which contain standard registers.  @value{GDBN} will look for features
26714
with those names and verify that they contain the expected registers;
26715
if any known feature is missing required registers, or if any required
26716
feature is missing, @value{GDBN} will reject the target
26717
description.  You can add additional registers to any of the
26718
standard features --- @value{GDBN} will display them just as if
26719
they were added to an unrecognized feature.
26720
 
26721
This section lists the known features and their expected contents.
26722
Sample XML documents for these features are included in the
26723
@value{GDBN} source tree, in the directory @file{gdb/features}.
26724
 
26725
Names recognized by @value{GDBN} should include the name of the
26726
company or organization which selected the name, and the overall
26727
architecture to which the feature applies; so e.g.@: the feature
26728
containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
26729
 
26730
The names of registers are not case sensitive for the purpose
26731
of recognizing standard features, but @value{GDBN} will only display
26732
registers using the capitalization used in the description.
26733
 
26734
@menu
26735
* ARM Features::
26736
* MIPS Features::
26737
* M68K Features::
26738
* PowerPC Features::
26739
@end menu
26740
 
26741
 
26742
@node ARM Features
26743
@subsection ARM Features
26744
@cindex target descriptions, ARM features
26745
 
26746
The @samp{org.gnu.gdb.arm.core} feature is required for ARM targets.
26747
It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
26748
@samp{lr}, @samp{pc}, and @samp{cpsr}.
26749
 
26750
The @samp{org.gnu.gdb.arm.fpa} feature is optional.  If present, it
26751
should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
26752
 
26753
The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional.  If present,
26754
it should contain at least registers @samp{wR0} through @samp{wR15} and
26755
@samp{wCGR0} through @samp{wCGR3}.  The @samp{wCID}, @samp{wCon},
26756
@samp{wCSSF}, and @samp{wCASF} registers are optional.
26757
 
26758
@node MIPS Features
26759
@subsection MIPS Features
26760
@cindex target descriptions, MIPS features
26761
 
26762
The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
26763
It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
26764
@samp{hi}, and @samp{pc}.  They may be 32-bit or 64-bit depending
26765
on the target.
26766
 
26767
The @samp{org.gnu.gdb.mips.cp0} feature is also required.  It should
26768
contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
26769
registers.  They may be 32-bit or 64-bit depending on the target.
26770
 
26771
The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
26772
it may be optional in a future version of @value{GDBN}.  It should
26773
contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
26774
@samp{fir}.  They may be 32-bit or 64-bit depending on the target.
26775
 
26776
The @samp{org.gnu.gdb.mips.linux} feature is optional.  It should
26777
contain a single register, @samp{restart}, which is used by the
26778
Linux kernel to control restartable syscalls.
26779
 
26780
@node M68K Features
26781
@subsection M68K Features
26782
@cindex target descriptions, M68K features
26783
 
26784
@table @code
26785
@item @samp{org.gnu.gdb.m68k.core}
26786
@itemx @samp{org.gnu.gdb.coldfire.core}
26787
@itemx @samp{org.gnu.gdb.fido.core}
26788
One of those features must be always present.
26789
The feature that is present determines which flavor of m86k is
26790
used.  The feature that is present should contain registers
26791
@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
26792
@samp{sp}, @samp{ps} and @samp{pc}.
26793
 
26794
@item @samp{org.gnu.gdb.coldfire.fp}
26795
This feature is optional.  If present, it should contain registers
26796
@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
26797
@samp{fpiaddr}.
26798
@end table
26799
 
26800
@node PowerPC Features
26801
@subsection PowerPC Features
26802
@cindex target descriptions, PowerPC features
26803
 
26804
The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
26805
targets.  It should contain registers @samp{r0} through @samp{r31},
26806
@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
26807
@samp{xer}.  They may be 32-bit or 64-bit depending on the target.
26808
 
26809
The @samp{org.gnu.gdb.power.fpu} feature is optional.  It should
26810
contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
26811
 
26812
The @samp{org.gnu.gdb.power.altivec} feature is optional.  It should
26813
contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
26814
and @samp{vrsave}.
26815
 
26816
The @samp{org.gnu.gdb.power.spe} feature is optional.  It should
26817
contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
26818
@samp{spefscr}.  SPE targets should provide 32-bit registers in
26819
@samp{org.gnu.gdb.power.core} and provide the upper halves in
26820
@samp{ev0h} through @samp{ev31h}.  @value{GDBN} will combine
26821
these to present registers @samp{ev0} through @samp{ev31} to the
26822
user.
26823
 
26824
@include gpl.texi
26825
 
26826
@raisesections
26827
@include fdl.texi
26828
@lowersections
26829
 
26830
@node Index
26831
@unnumbered Index
26832
 
26833
@printindex cp
26834
 
26835
@tex
26836
% I think something like @colophon should be in texinfo.  In the
26837
% meantime:
26838
\long\def\colophon{\hbox to0pt{}\vfill
26839
\centerline{The body of this manual is set in}
26840
\centerline{\fontname\tenrm,}
26841
\centerline{with headings in {\bf\fontname\tenbf}}
26842
\centerline{and examples in {\tt\fontname\tentt}.}
26843
\centerline{{\it\fontname\tenit\/},}
26844
\centerline{{\bf\fontname\tenbf}, and}
26845
\centerline{{\sl\fontname\tensl\/}}
26846
\centerline{are used for emphasis.}\vfill}
26847
\page\colophon
26848
% Blame: doc@cygnus.com, 1991.
26849
@end tex
26850
 
26851
@bye

powered by: WebSVN 2.1.0

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