MI non-stop and multiprocess docs.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
c02a867d 2@c Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
d7d9f01e 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
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
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
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
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The GNU debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
c16158bc
JM
52@ifset VERSION_PACKAGE
53@value{VERSION_PACKAGE}
54@end ifset
9fe8321b 55Version @value{GDBVN}.
c906108c 56
8a037dd7 57Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
b620eb07 58 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006@*
7d51c7de 59 Free Software Foundation, Inc.
c906108c 60
e9c75b65
EZ
61Permission is granted to copy, distribute and/or modify this document
62under the terms of the GNU Free Documentation License, Version 1.1 or
63any later version published by the Free Software Foundation; with the
959acfd1
EZ
64Invariant Sections being ``Free Software'' and ``Free Software Needs
65Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
66and with the Back-Cover Texts as in (a) below.
c906108c 67
b8533aec
DJ
68(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
69this GNU Manual. Buying copies from GNU Press supports the FSF in
70developing GNU and promoting software freedom.''
c906108c
SS
71@end ifinfo
72
73@titlepage
74@title Debugging with @value{GDBN}
75@subtitle The @sc{gnu} Source-Level Debugger
c906108c 76@sp 1
c906108c 77@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
78@ifset VERSION_PACKAGE
79@sp 1
80@subtitle @value{VERSION_PACKAGE}
81@end ifset
9e9c5ae7 82@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 83@page
c906108c
SS
84@tex
85{\parskip=0pt
c16158bc 86\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
87\hfill {\it Debugging with @value{GDBN}}\par
88\hfill \TeX{}info \texinfoversion\par
89}
90@end tex
53a5351d 91
c906108c 92@vskip 0pt plus 1filll
8a037dd7 93Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
b620eb07 941996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
7d51c7de 95Free Software Foundation, Inc.
c906108c 96@sp 2
c906108c 97Published by the Free Software Foundation @*
c02a867d
EZ
9851 Franklin Street, Fifth Floor,
99Boston, MA 02110-1301, USA@*
6d2ebf8b 100ISBN 1-882114-77-9 @*
e9c75b65
EZ
101
102Permission is granted to copy, distribute and/or modify this document
103under the terms of the GNU Free Documentation License, Version 1.1 or
104any later version published by the Free Software Foundation; with the
959acfd1
EZ
105Invariant Sections being ``Free Software'' and ``Free Software Needs
106Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
107and with the Back-Cover Texts as in (a) below.
e9c75b65 108
b8533aec
DJ
109(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
110this GNU Manual. Buying copies from GNU Press supports the FSF in
111developing GNU and promoting software freedom.''
3fb6a982
JB
112@page
113This edition of the GDB manual is dedicated to the memory of Fred
114Fish. Fred was a long-standing contributor to GDB and to Free
115software in general. We will miss him.
c906108c
SS
116@end titlepage
117@page
118
6c0e9fb3 119@ifnottex
6d2ebf8b
SS
120@node Top, Summary, (dir), (dir)
121
c906108c
SS
122@top Debugging with @value{GDBN}
123
124This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
125
c16158bc
JM
126This is the @value{EDITION} Edition, for @value{GDBN}
127@ifset VERSION_PACKAGE
128@value{VERSION_PACKAGE}
129@end ifset
130Version @value{GDBVN}.
c906108c 131
b620eb07 132Copyright (C) 1988-2006 Free Software Foundation, Inc.
6d2ebf8b 133
3fb6a982
JB
134This edition of the GDB manual is dedicated to the memory of Fred
135Fish. Fred was a long-standing contributor to GDB and to Free
136software in general. We will miss him.
137
6d2ebf8b
SS
138@menu
139* Summary:: Summary of @value{GDBN}
140* Sample Session:: A sample @value{GDBN} session
141
142* Invocation:: Getting in and out of @value{GDBN}
143* Commands:: @value{GDBN} commands
144* Running:: Running programs under @value{GDBN}
145* Stopping:: Stopping and continuing
bacec72f 146* Reverse Execution:: Running programs backward
6d2ebf8b
SS
147* Stack:: Examining the stack
148* Source:: Examining source files
149* Data:: Examining data
e2e0bcd1 150* Macros:: Preprocessor Macros
b37052ae 151* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 152* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
153
154* Languages:: Using @value{GDBN} with different languages
155
156* Symbols:: Examining the symbol table
157* Altering:: Altering execution
158* GDB Files:: @value{GDBN} files
159* Targets:: Specifying a debugging target
6b2f586d 160* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
161* Configurations:: Configuration-specific information
162* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 163* Extending GDB:: Extending @value{GDBN}
21c294e6 164* Interpreters:: Command Interpreters
c8f4133a 165* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 166* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 167* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 168* Annotations:: @value{GDBN}'s annotation interface.
6d2ebf8b
SS
169
170* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b
SS
171
172* Command Line Editing:: Command Line Editing
173* Using History Interactively:: Using History Interactively
0869d01b 174* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 175* Installing GDB:: Installing GDB
eb12ee30 176* Maintenance Commands:: Maintenance Commands
e0ce93ac 177* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 178* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
179* Target Descriptions:: How targets can describe themselves to
180 @value{GDBN}
07e059b5
VP
181* Operating System Information:: Getting additional information from
182 the operating system
aab4e0ec
AC
183* Copying:: GNU General Public License says
184 how you can copy and share GDB
6826cf00 185* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
186* Index:: Index
187@end menu
188
6c0e9fb3 189@end ifnottex
c906108c 190
449f3b6c 191@contents
449f3b6c 192
6d2ebf8b 193@node Summary
c906108c
SS
194@unnumbered Summary of @value{GDBN}
195
196The purpose of a debugger such as @value{GDBN} is to allow you to see what is
197going on ``inside'' another program while it executes---or what another
198program was doing at the moment it crashed.
199
200@value{GDBN} can do four main kinds of things (plus other things in support of
201these) to help you catch bugs in the act:
202
203@itemize @bullet
204@item
205Start your program, specifying anything that might affect its behavior.
206
207@item
208Make your program stop on specified conditions.
209
210@item
211Examine what has happened, when your program has stopped.
212
213@item
214Change things in your program, so you can experiment with correcting the
215effects of one bug and go on to learn about another.
216@end itemize
217
49efadf5 218You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 219For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
220For more information, see @ref{C,,C and C++}.
221
cce74817 222@cindex Modula-2
e632838e
AC
223Support for Modula-2 is partial. For information on Modula-2, see
224@ref{Modula-2,,Modula-2}.
c906108c 225
cce74817
JM
226@cindex Pascal
227Debugging Pascal programs which use sets, subranges, file variables, or
228nested functions does not currently work. @value{GDBN} does not support
229entering expressions, printing values, or similar features using Pascal
230syntax.
c906108c 231
c906108c
SS
232@cindex Fortran
233@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 234it may be necessary to refer to some variables with a trailing
cce74817 235underscore.
c906108c 236
b37303ee
AF
237@value{GDBN} can be used to debug programs written in Objective-C,
238using either the Apple/NeXT or the GNU Objective-C runtime.
239
c906108c
SS
240@menu
241* Free Software:: Freely redistributable software
242* Contributors:: Contributors to GDB
243@end menu
244
6d2ebf8b 245@node Free Software
79a6e687 246@unnumberedsec Free Software
c906108c 247
5d161b24 248@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
249General Public License
250(GPL). The GPL gives you the freedom to copy or adapt a licensed
251program---but every person getting a copy also gets with it the
252freedom to modify that copy (which means that they must get access to
253the source code), and the freedom to distribute further copies.
254Typical software companies use copyrights to limit your freedoms; the
255Free Software Foundation uses the GPL to preserve these freedoms.
256
257Fundamentally, the General Public License is a license which says that
258you have these freedoms and that you cannot take these freedoms away
259from anyone else.
260
2666264b 261@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
262
263The biggest deficiency in the free software community today is not in
264the software---it is the lack of good free documentation that we can
265include with the free software. Many of our most important
266programs do not come with free reference manuals and free introductory
267texts. Documentation is an essential part of any software package;
268when an important free software package does not come with a free
269manual and a free tutorial, that is a major gap. We have many such
270gaps today.
271
272Consider Perl, for instance. The tutorial manuals that people
273normally use are non-free. How did this come about? Because the
274authors of those manuals published them with restrictive terms---no
275copying, no modification, source files not available---which exclude
276them from the free software world.
277
278That wasn't the first time this sort of thing happened, and it was far
279from the last. Many times we have heard a GNU user eagerly describe a
280manual that he is writing, his intended contribution to the community,
281only to learn that he had ruined everything by signing a publication
282contract to make it non-free.
283
284Free documentation, like free software, is a matter of freedom, not
285price. The problem with the non-free manual is not that publishers
286charge a price for printed copies---that in itself is fine. (The Free
287Software Foundation sells printed copies of manuals, too.) The
288problem is the restrictions on the use of the manual. Free manuals
289are available in source code form, and give you permission to copy and
290modify. Non-free manuals do not allow this.
291
292The criteria of freedom for a free manual are roughly the same as for
293free software. Redistribution (including the normal kinds of
294commercial redistribution) must be permitted, so that the manual can
295accompany every copy of the program, both on-line and on paper.
296
297Permission for modification of the technical content is crucial too.
298When people modify the software, adding or changing features, if they
299are conscientious they will change the manual too---so they can
300provide accurate and clear documentation for the modified program. A
301manual that leaves you no choice but to write a new manual to document
302a changed version of the program is not really available to our
303community.
304
305Some kinds of limits on the way modification is handled are
306acceptable. For example, requirements to preserve the original
307author's copyright notice, the distribution terms, or the list of
308authors, are ok. It is also no problem to require modified versions
309to include notice that they were modified. Even entire sections that
310may not be deleted or changed are acceptable, as long as they deal
311with nontechnical topics (like this one). These kinds of restrictions
312are acceptable because they don't obstruct the community's normal use
313of the manual.
314
315However, it must be possible to modify all the @emph{technical}
316content of the manual, and then distribute the result in all the usual
317media, through all the usual channels. Otherwise, the restrictions
318obstruct the use of the manual, it is not free, and we need another
319manual to replace it.
320
321Please spread the word about this issue. Our community continues to
322lose manuals to proprietary publishing. If we spread the word that
323free software needs free reference manuals and free tutorials, perhaps
324the next person who wants to contribute by writing documentation will
325realize, before it is too late, that only free manuals contribute to
326the free software community.
327
328If you are writing documentation, please insist on publishing it under
329the GNU Free Documentation License or another free documentation
330license. Remember that this decision requires your approval---you
331don't have to let the publisher decide. Some commercial publishers
332will use a free license if you insist, but they will not propose the
333option; it is up to you to raise the issue and say firmly that this is
334what you want. If the publisher you are dealing with refuses, please
335try other publishers. If you're not sure whether a proposed license
42584a72 336is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
337
338You can encourage commercial publishers to sell more free, copylefted
339manuals and tutorials by buying them, and particularly by buying
340copies from the publishers that paid for their writing or for major
341improvements. Meanwhile, try to avoid buying non-free documentation
342at all. Check the distribution terms of a manual before you buy it,
343and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
344Check the history of the book, and try to reward the publishers that
345have paid or pay the authors to work on it.
959acfd1
EZ
346
347The Free Software Foundation maintains a list of free documentation
348published by other publishers, at
349@url{http://www.fsf.org/doc/other-free-books.html}.
350
6d2ebf8b 351@node Contributors
96a2c332
SS
352@unnumberedsec Contributors to @value{GDBN}
353
354Richard Stallman was the original author of @value{GDBN}, and of many
355other @sc{gnu} programs. Many others have contributed to its
356development. This section attempts to credit major contributors. One
357of the virtues of free software is that everyone is free to contribute
358to it; with regret, we cannot actually acknowledge everyone here. The
359file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
360blow-by-blow account.
361
362Changes much prior to version 2.0 are lost in the mists of time.
363
364@quotation
365@emph{Plea:} Additions to this section are particularly welcome. If you
366or your friends (or enemies, to be evenhanded) have been unfairly
367omitted from this list, we would like to add your names!
368@end quotation
369
370So that they may not regard their many labors as thankless, we
371particularly thank those who shepherded @value{GDBN} through major
372releases:
7ba3cf9c 373Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
374Jim Blandy (release 4.18);
375Jason Molenda (release 4.17);
376Stan Shebs (release 4.14);
377Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
378Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
379John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
380Jim Kingdon (releases 3.5, 3.4, and 3.3);
381and Randy Smith (releases 3.2, 3.1, and 3.0).
382
383Richard Stallman, assisted at various times by Peter TerMaat, Chris
384Hanson, and Richard Mlynarik, handled releases through 2.8.
385
b37052ae
EZ
386Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
387in @value{GDBN}, with significant additional contributions from Per
388Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
389demangler. Early work on C@t{++} was by Peter TerMaat (who also did
390much general update work leading to release 3.0).
c906108c 391
b37052ae 392@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
393object-file formats; BFD was a joint project of David V.
394Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
395
396David Johnson wrote the original COFF support; Pace Willison did
397the original support for encapsulated COFF.
398
0179ffac 399Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
400
401Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
402Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
403support.
404Jean-Daniel Fekete contributed Sun 386i support.
405Chris Hanson improved the HP9000 support.
406Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
407David Johnson contributed Encore Umax support.
408Jyrki Kuoppala contributed Altos 3068 support.
409Jeff Law contributed HP PA and SOM support.
410Keith Packard contributed NS32K support.
411Doug Rabson contributed Acorn Risc Machine support.
412Bob Rusk contributed Harris Nighthawk CX-UX support.
413Chris Smith contributed Convex support (and Fortran debugging).
414Jonathan Stone contributed Pyramid support.
415Michael Tiemann contributed SPARC support.
416Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
417Pace Willison contributed Intel 386 support.
418Jay Vosburgh contributed Symmetry support.
a37295f9 419Marko Mlinar contributed OpenRISC 1000 support.
c906108c 420
1104b9e7 421Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
422
423Rich Schaefer and Peter Schauer helped with support of SunOS shared
424libraries.
425
426Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
427about several machine instruction sets.
428
429Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
430remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
431contributed remote debugging modules for the i960, VxWorks, A29K UDI,
432and RDI targets, respectively.
433
434Brian Fox is the author of the readline libraries providing
435command-line editing and command history.
436
7a292a7a
SS
437Andrew Beers of SUNY Buffalo wrote the language-switching code, the
438Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 439
5d161b24 440Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 441He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 442symbols.
c906108c 443
f24c5e49
KI
444Hitachi America (now Renesas America), Ltd. sponsored the support for
445H8/300, H8/500, and Super-H processors.
c906108c
SS
446
447NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
448
f24c5e49
KI
449Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
450processors.
c906108c
SS
451
452Toshiba sponsored the support for the TX39 Mips processor.
453
454Matsushita sponsored the support for the MN10200 and MN10300 processors.
455
96a2c332 456Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
457
458Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
459watchpoints.
460
461Michael Snyder added support for tracepoints.
462
463Stu Grossman wrote gdbserver.
464
465Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 466nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
467
468The following people at the Hewlett-Packard Company contributed
469support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 470(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
471compiler, and the Text User Interface (nee Terminal User Interface):
472Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
473Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
474provided HP-specific information in this manual.
c906108c 475
b37052ae
EZ
476DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
477Robert Hoehne made significant contributions to the DJGPP port.
478
96a2c332
SS
479Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
480development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
481fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
482Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
483Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
484Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
485Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
486addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
487JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
488Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
489Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
490Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
491Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
492Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
493Zuhn have made contributions both large and small.
c906108c 494
ffed4509
AC
495Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
496Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
497
e2e0bcd1
JB
498Jim Blandy added support for preprocessor macros, while working for Red
499Hat.
c906108c 500
a9967aef
AC
501Andrew Cagney designed @value{GDBN}'s architecture vector. Many
502people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
503Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
504Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
505Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
506with the migration of old architectures to this new framework.
507
c5e30d01
AC
508Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
509unwinder framework, this consisting of a fresh new design featuring
510frame IDs, independent frame sniffers, and the sentinel frame. Mark
511Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
512libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 513trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
514complete rewrite of the architecture's frame code, were carried out by
515Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
516Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
517Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
518Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
519Weigand.
520
ca3bf3bd
DJ
521Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
522Tensilica, Inc.@: contributed support for Xtensa processors. Others
523who have worked on the Xtensa port of @value{GDBN} in the past include
524Steve Tjiang, John Newlin, and Scott Foehner.
525
6d2ebf8b 526@node Sample Session
c906108c
SS
527@chapter A Sample @value{GDBN} Session
528
529You can use this manual at your leisure to read all about @value{GDBN}.
530However, a handful of commands are enough to get started using the
531debugger. This chapter illustrates those commands.
532
533@iftex
534In this sample session, we emphasize user input like this: @b{input},
535to make it easier to pick out from the surrounding output.
536@end iftex
537
538@c FIXME: this example may not be appropriate for some configs, where
539@c FIXME...primary interest is in remote use.
540
541One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
542processor) exhibits the following bug: sometimes, when we change its
543quote strings from the default, the commands used to capture one macro
544definition within another stop working. In the following short @code{m4}
545session, we define a macro @code{foo} which expands to @code{0000}; we
546then use the @code{m4} built-in @code{defn} to define @code{bar} as the
547same thing. However, when we change the open quote string to
548@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
549procedure fails to define a new synonym @code{baz}:
550
551@smallexample
552$ @b{cd gnu/m4}
553$ @b{./m4}
554@b{define(foo,0000)}
555
556@b{foo}
5570000
558@b{define(bar,defn(`foo'))}
559
560@b{bar}
5610000
562@b{changequote(<QUOTE>,<UNQUOTE>)}
563
564@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
565@b{baz}
c8aa23ab 566@b{Ctrl-d}
c906108c
SS
567m4: End of input: 0: fatal error: EOF in string
568@end smallexample
569
570@noindent
571Let us use @value{GDBN} to try to see what is going on.
572
c906108c
SS
573@smallexample
574$ @b{@value{GDBP} m4}
575@c FIXME: this falsifies the exact text played out, to permit smallbook
576@c FIXME... format to come out better.
577@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 578 of it under certain conditions; type "show copying" to see
c906108c 579 the conditions.
5d161b24 580There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
581 for details.
582
583@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
584(@value{GDBP})
585@end smallexample
c906108c
SS
586
587@noindent
588@value{GDBN} reads only enough symbol data to know where to find the
589rest when needed; as a result, the first prompt comes up very quickly.
590We now tell @value{GDBN} to use a narrower display width than usual, so
591that examples fit in this manual.
592
593@smallexample
594(@value{GDBP}) @b{set width 70}
595@end smallexample
596
597@noindent
598We need to see how the @code{m4} built-in @code{changequote} works.
599Having looked at the source, we know the relevant subroutine is
600@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
601@code{break} command.
602
603@smallexample
604(@value{GDBP}) @b{break m4_changequote}
605Breakpoint 1 at 0x62f4: file builtin.c, line 879.
606@end smallexample
607
608@noindent
609Using the @code{run} command, we start @code{m4} running under @value{GDBN}
610control; as long as control does not reach the @code{m4_changequote}
611subroutine, the program runs as usual:
612
613@smallexample
614(@value{GDBP}) @b{run}
615Starting program: /work/Editorial/gdb/gnu/m4/m4
616@b{define(foo,0000)}
617
618@b{foo}
6190000
620@end smallexample
621
622@noindent
623To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
624suspends execution of @code{m4}, displaying information about the
625context where it stops.
626
627@smallexample
628@b{changequote(<QUOTE>,<UNQUOTE>)}
629
5d161b24 630Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
631 at builtin.c:879
632879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
633@end smallexample
634
635@noindent
636Now we use the command @code{n} (@code{next}) to advance execution to
637the next line of the current function.
638
639@smallexample
640(@value{GDBP}) @b{n}
641882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
642 : nil,
643@end smallexample
644
645@noindent
646@code{set_quotes} looks like a promising subroutine. We can go into it
647by using the command @code{s} (@code{step}) instead of @code{next}.
648@code{step} goes to the next line to be executed in @emph{any}
649subroutine, so it steps into @code{set_quotes}.
650
651@smallexample
652(@value{GDBP}) @b{s}
653set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
654 at input.c:530
655530 if (lquote != def_lquote)
656@end smallexample
657
658@noindent
659The display that shows the subroutine where @code{m4} is now
660suspended (and its arguments) is called a stack frame display. It
661shows a summary of the stack. We can use the @code{backtrace}
662command (which can also be spelled @code{bt}), to see where we are
663in the stack as a whole: the @code{backtrace} command displays a
664stack frame for each active subroutine.
665
666@smallexample
667(@value{GDBP}) @b{bt}
668#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
669 at input.c:530
5d161b24 670#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
671 at builtin.c:882
672#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
673#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
674 at macro.c:71
675#4 0x79dc in expand_input () at macro.c:40
676#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
677@end smallexample
678
679@noindent
680We step through a few more lines to see what happens. The first two
681times, we can use @samp{s}; the next two times we use @code{n} to avoid
682falling into the @code{xstrdup} subroutine.
683
684@smallexample
685(@value{GDBP}) @b{s}
6860x3b5c 532 if (rquote != def_rquote)
687(@value{GDBP}) @b{s}
6880x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
689def_lquote : xstrdup(lq);
690(@value{GDBP}) @b{n}
691536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
692 : xstrdup(rq);
693(@value{GDBP}) @b{n}
694538 len_lquote = strlen(rquote);
695@end smallexample
696
697@noindent
698The last line displayed looks a little odd; we can examine the variables
699@code{lquote} and @code{rquote} to see if they are in fact the new left
700and right quotes we specified. We use the command @code{p}
701(@code{print}) to see their values.
702
703@smallexample
704(@value{GDBP}) @b{p lquote}
705$1 = 0x35d40 "<QUOTE>"
706(@value{GDBP}) @b{p rquote}
707$2 = 0x35d50 "<UNQUOTE>"
708@end smallexample
709
710@noindent
711@code{lquote} and @code{rquote} are indeed the new left and right quotes.
712To look at some context, we can display ten lines of source
713surrounding the current line with the @code{l} (@code{list}) command.
714
715@smallexample
716(@value{GDBP}) @b{l}
717533 xfree(rquote);
718534
719535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
720 : xstrdup (lq);
721536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
722 : xstrdup (rq);
723537
724538 len_lquote = strlen(rquote);
725539 len_rquote = strlen(lquote);
726540 @}
727541
728542 void
729@end smallexample
730
731@noindent
732Let us step past the two lines that set @code{len_lquote} and
733@code{len_rquote}, and then examine the values of those variables.
734
735@smallexample
736(@value{GDBP}) @b{n}
737539 len_rquote = strlen(lquote);
738(@value{GDBP}) @b{n}
739540 @}
740(@value{GDBP}) @b{p len_lquote}
741$3 = 9
742(@value{GDBP}) @b{p len_rquote}
743$4 = 7
744@end smallexample
745
746@noindent
747That certainly looks wrong, assuming @code{len_lquote} and
748@code{len_rquote} are meant to be the lengths of @code{lquote} and
749@code{rquote} respectively. We can set them to better values using
750the @code{p} command, since it can print the value of
751any expression---and that expression can include subroutine calls and
752assignments.
753
754@smallexample
755(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
756$5 = 7
757(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
758$6 = 9
759@end smallexample
760
761@noindent
762Is that enough to fix the problem of using the new quotes with the
763@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
764executing with the @code{c} (@code{continue}) command, and then try the
765example that caused trouble initially:
766
767@smallexample
768(@value{GDBP}) @b{c}
769Continuing.
770
771@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
772
773baz
7740000
775@end smallexample
776
777@noindent
778Success! The new quotes now work just as well as the default ones. The
779problem seems to have been just the two typos defining the wrong
780lengths. We allow @code{m4} exit by giving it an EOF as input:
781
782@smallexample
c8aa23ab 783@b{Ctrl-d}
c906108c
SS
784Program exited normally.
785@end smallexample
786
787@noindent
788The message @samp{Program exited normally.} is from @value{GDBN}; it
789indicates @code{m4} has finished executing. We can end our @value{GDBN}
790session with the @value{GDBN} @code{quit} command.
791
792@smallexample
793(@value{GDBP}) @b{quit}
794@end smallexample
c906108c 795
6d2ebf8b 796@node Invocation
c906108c
SS
797@chapter Getting In and Out of @value{GDBN}
798
799This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 800The essentials are:
c906108c 801@itemize @bullet
5d161b24 802@item
53a5351d 803type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 804@item
c8aa23ab 805type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
806@end itemize
807
808@menu
809* Invoking GDB:: How to start @value{GDBN}
810* Quitting GDB:: How to quit @value{GDBN}
811* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 812* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
813@end menu
814
6d2ebf8b 815@node Invoking GDB
c906108c
SS
816@section Invoking @value{GDBN}
817
c906108c
SS
818Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
819@value{GDBN} reads commands from the terminal until you tell it to exit.
820
821You can also run @code{@value{GDBP}} with a variety of arguments and options,
822to specify more of your debugging environment at the outset.
823
c906108c
SS
824The command-line options described here are designed
825to cover a variety of situations; in some environments, some of these
5d161b24 826options may effectively be unavailable.
c906108c
SS
827
828The most usual way to start @value{GDBN} is with one argument,
829specifying an executable program:
830
474c8240 831@smallexample
c906108c 832@value{GDBP} @var{program}
474c8240 833@end smallexample
c906108c 834
c906108c
SS
835@noindent
836You can also start with both an executable program and a core file
837specified:
838
474c8240 839@smallexample
c906108c 840@value{GDBP} @var{program} @var{core}
474c8240 841@end smallexample
c906108c
SS
842
843You can, instead, specify a process ID as a second argument, if you want
844to debug a running process:
845
474c8240 846@smallexample
c906108c 847@value{GDBP} @var{program} 1234
474c8240 848@end smallexample
c906108c
SS
849
850@noindent
851would attach @value{GDBN} to process @code{1234} (unless you also have a file
852named @file{1234}; @value{GDBN} does check for a core file first).
853
c906108c 854Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
855complete operating system; when you use @value{GDBN} as a remote
856debugger attached to a bare board, there may not be any notion of
857``process'', and there is often no way to get a core dump. @value{GDBN}
858will warn you if it is unable to attach or to read core dumps.
c906108c 859
aa26fa3a
TT
860You can optionally have @code{@value{GDBP}} pass any arguments after the
861executable file to the inferior using @code{--args}. This option stops
862option processing.
474c8240 863@smallexample
3f94c067 864@value{GDBP} --args gcc -O2 -c foo.c
474c8240 865@end smallexample
aa26fa3a
TT
866This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
867@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
868
96a2c332 869You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
870@value{GDBN}'s non-warranty, by specifying @code{-silent}:
871
872@smallexample
873@value{GDBP} -silent
874@end smallexample
875
876@noindent
877You can further control how @value{GDBN} starts up by using command-line
878options. @value{GDBN} itself can remind you of the options available.
879
880@noindent
881Type
882
474c8240 883@smallexample
c906108c 884@value{GDBP} -help
474c8240 885@end smallexample
c906108c
SS
886
887@noindent
888to display all available options and briefly describe their use
889(@samp{@value{GDBP} -h} is a shorter equivalent).
890
891All options and command line arguments you give are processed
892in sequential order. The order makes a difference when the
893@samp{-x} option is used.
894
895
896@menu
c906108c
SS
897* File Options:: Choosing files
898* Mode Options:: Choosing modes
6fc08d32 899* Startup:: What @value{GDBN} does during startup
c906108c
SS
900@end menu
901
6d2ebf8b 902@node File Options
79a6e687 903@subsection Choosing Files
c906108c 904
2df3850c 905When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
906specifying an executable file and core file (or process ID). This is
907the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 908@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
909first argument that does not have an associated option flag as
910equivalent to the @samp{-se} option followed by that argument; and the
911second argument that does not have an associated option flag, if any, as
912equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
913If the second argument begins with a decimal digit, @value{GDBN} will
914first attempt to attach to it as a process, and if that fails, attempt
915to open it as a corefile. If you have a corefile whose name begins with
b383017d 916a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 917prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
918
919If @value{GDBN} has not been configured to included core file support,
920such as for most embedded targets, then it will complain about a second
921argument and ignore it.
c906108c
SS
922
923Many options have both long and short forms; both are shown in the
924following list. @value{GDBN} also recognizes the long forms if you truncate
925them, so long as enough of the option is present to be unambiguous.
926(If you prefer, you can flag option arguments with @samp{--} rather
927than @samp{-}, though we illustrate the more usual convention.)
928
d700128c
EZ
929@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
930@c way, both those who look for -foo and --foo in the index, will find
931@c it.
932
c906108c
SS
933@table @code
934@item -symbols @var{file}
935@itemx -s @var{file}
d700128c
EZ
936@cindex @code{--symbols}
937@cindex @code{-s}
c906108c
SS
938Read symbol table from file @var{file}.
939
940@item -exec @var{file}
941@itemx -e @var{file}
d700128c
EZ
942@cindex @code{--exec}
943@cindex @code{-e}
7a292a7a
SS
944Use file @var{file} as the executable file to execute when appropriate,
945and for examining pure data in conjunction with a core dump.
c906108c
SS
946
947@item -se @var{file}
d700128c 948@cindex @code{--se}
c906108c
SS
949Read symbol table from file @var{file} and use it as the executable
950file.
951
c906108c
SS
952@item -core @var{file}
953@itemx -c @var{file}
d700128c
EZ
954@cindex @code{--core}
955@cindex @code{-c}
b383017d 956Use file @var{file} as a core dump to examine.
c906108c 957
19837790
MS
958@item -pid @var{number}
959@itemx -p @var{number}
960@cindex @code{--pid}
961@cindex @code{-p}
962Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
963
964@item -command @var{file}
965@itemx -x @var{file}
d700128c
EZ
966@cindex @code{--command}
967@cindex @code{-x}
c906108c
SS
968Execute @value{GDBN} commands from file @var{file}. @xref{Command
969Files,, Command files}.
970
8a5a3c82
AS
971@item -eval-command @var{command}
972@itemx -ex @var{command}
973@cindex @code{--eval-command}
974@cindex @code{-ex}
975Execute a single @value{GDBN} command.
976
977This option may be used multiple times to call multiple commands. It may
978also be interleaved with @samp{-command} as required.
979
980@smallexample
981@value{GDBP} -ex 'target sim' -ex 'load' \
982 -x setbreakpoints -ex 'run' a.out
983@end smallexample
984
c906108c
SS
985@item -directory @var{directory}
986@itemx -d @var{directory}
d700128c
EZ
987@cindex @code{--directory}
988@cindex @code{-d}
4b505b12 989Add @var{directory} to the path to search for source and script files.
c906108c 990
c906108c
SS
991@item -r
992@itemx -readnow
d700128c
EZ
993@cindex @code{--readnow}
994@cindex @code{-r}
c906108c
SS
995Read each symbol file's entire symbol table immediately, rather than
996the default, which is to read it incrementally as it is needed.
997This makes startup slower, but makes future operations faster.
53a5351d 998
c906108c
SS
999@end table
1000
6d2ebf8b 1001@node Mode Options
79a6e687 1002@subsection Choosing Modes
c906108c
SS
1003
1004You can run @value{GDBN} in various alternative modes---for example, in
1005batch mode or quiet mode.
1006
1007@table @code
1008@item -nx
1009@itemx -n
d700128c
EZ
1010@cindex @code{--nx}
1011@cindex @code{-n}
96565e91 1012Do not execute commands found in any initialization files. Normally,
2df3850c
JM
1013@value{GDBN} executes the commands in these files after all the command
1014options and arguments have been processed. @xref{Command Files,,Command
79a6e687 1015Files}.
c906108c
SS
1016
1017@item -quiet
d700128c 1018@itemx -silent
c906108c 1019@itemx -q
d700128c
EZ
1020@cindex @code{--quiet}
1021@cindex @code{--silent}
1022@cindex @code{-q}
c906108c
SS
1023``Quiet''. Do not print the introductory and copyright messages. These
1024messages are also suppressed in batch mode.
1025
1026@item -batch
d700128c 1027@cindex @code{--batch}
c906108c
SS
1028Run in batch mode. Exit with status @code{0} after processing all the
1029command files specified with @samp{-x} (and all commands from
1030initialization files, if not inhibited with @samp{-n}). Exit with
1031nonzero status if an error occurs in executing the @value{GDBN} commands
1032in the command files.
1033
2df3850c
JM
1034Batch mode may be useful for running @value{GDBN} as a filter, for
1035example to download and run a program on another computer; in order to
1036make this more useful, the message
c906108c 1037
474c8240 1038@smallexample
c906108c 1039Program exited normally.
474c8240 1040@end smallexample
c906108c
SS
1041
1042@noindent
2df3850c
JM
1043(which is ordinarily issued whenever a program running under
1044@value{GDBN} control terminates) is not issued when running in batch
1045mode.
1046
1a088d06
AS
1047@item -batch-silent
1048@cindex @code{--batch-silent}
1049Run in batch mode exactly like @samp{-batch}, but totally silently. All
1050@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1051unaffected). This is much quieter than @samp{-silent} and would be useless
1052for an interactive session.
1053
1054This is particularly useful when using targets that give @samp{Loading section}
1055messages, for example.
1056
1057Note that targets that give their output via @value{GDBN}, as opposed to
1058writing directly to @code{stdout}, will also be made silent.
1059
4b0ad762
AS
1060@item -return-child-result
1061@cindex @code{--return-child-result}
1062The return code from @value{GDBN} will be the return code from the child
1063process (the process being debugged), with the following exceptions:
1064
1065@itemize @bullet
1066@item
1067@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1068internal error. In this case the exit code is the same as it would have been
1069without @samp{-return-child-result}.
1070@item
1071The user quits with an explicit value. E.g., @samp{quit 1}.
1072@item
1073The child process never runs, or is not allowed to terminate, in which case
1074the exit code will be -1.
1075@end itemize
1076
1077This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1078when @value{GDBN} is being used as a remote program loader or simulator
1079interface.
1080
2df3850c
JM
1081@item -nowindows
1082@itemx -nw
d700128c
EZ
1083@cindex @code{--nowindows}
1084@cindex @code{-nw}
2df3850c 1085``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1086(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1087interface. If no GUI is available, this option has no effect.
1088
1089@item -windows
1090@itemx -w
d700128c
EZ
1091@cindex @code{--windows}
1092@cindex @code{-w}
2df3850c
JM
1093If @value{GDBN} includes a GUI, then this option requires it to be
1094used if possible.
c906108c
SS
1095
1096@item -cd @var{directory}
d700128c 1097@cindex @code{--cd}
c906108c
SS
1098Run @value{GDBN} using @var{directory} as its working directory,
1099instead of the current directory.
1100
c906108c
SS
1101@item -fullname
1102@itemx -f
d700128c
EZ
1103@cindex @code{--fullname}
1104@cindex @code{-f}
7a292a7a
SS
1105@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1106subprocess. It tells @value{GDBN} to output the full file name and line
1107number in a standard, recognizable fashion each time a stack frame is
1108displayed (which includes each time your program stops). This
1109recognizable format looks like two @samp{\032} characters, followed by
1110the file name, line number and character position separated by colons,
1111and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1112@samp{\032} characters as a signal to display the source code for the
1113frame.
c906108c 1114
d700128c
EZ
1115@item -epoch
1116@cindex @code{--epoch}
1117The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1118@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1119routines so as to allow Epoch to display values of expressions in a
1120separate window.
1121
1122@item -annotate @var{level}
1123@cindex @code{--annotate}
1124This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1125effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1126(@pxref{Annotations}). The annotation @var{level} controls how much
1127information @value{GDBN} prints together with its prompt, values of
1128expressions, source lines, and other types of output. Level 0 is the
1129normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1130@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1131that control @value{GDBN}, and level 2 has been deprecated.
1132
265eeb58 1133The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1134(@pxref{GDB/MI}).
d700128c 1135
aa26fa3a
TT
1136@item --args
1137@cindex @code{--args}
1138Change interpretation of command line so that arguments following the
1139executable file are passed as command line arguments to the inferior.
1140This option stops option processing.
1141
2df3850c
JM
1142@item -baud @var{bps}
1143@itemx -b @var{bps}
d700128c
EZ
1144@cindex @code{--baud}
1145@cindex @code{-b}
c906108c
SS
1146Set the line speed (baud rate or bits per second) of any serial
1147interface used by @value{GDBN} for remote debugging.
c906108c 1148
f47b1503
AS
1149@item -l @var{timeout}
1150@cindex @code{-l}
1151Set the timeout (in seconds) of any communication used by @value{GDBN}
1152for remote debugging.
1153
c906108c 1154@item -tty @var{device}
d700128c
EZ
1155@itemx -t @var{device}
1156@cindex @code{--tty}
1157@cindex @code{-t}
c906108c
SS
1158Run using @var{device} for your program's standard input and output.
1159@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1160
53a5351d 1161@c resolve the situation of these eventually
c4555f82
SC
1162@item -tui
1163@cindex @code{--tui}
d0d5df6f
AC
1164Activate the @dfn{Text User Interface} when starting. The Text User
1165Interface manages several text windows on the terminal, showing
1166source, assembly, registers and @value{GDBN} command outputs
1167(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1168Text User Interface can be enabled by invoking the program
46ba6afa 1169@samp{@value{GDBTUI}}. Do not use this option if you run @value{GDBN} from
d0d5df6f 1170Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1171
1172@c @item -xdb
d700128c 1173@c @cindex @code{--xdb}
53a5351d
JM
1174@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1175@c For information, see the file @file{xdb_trans.html}, which is usually
1176@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1177@c systems.
1178
d700128c
EZ
1179@item -interpreter @var{interp}
1180@cindex @code{--interpreter}
1181Use the interpreter @var{interp} for interface with the controlling
1182program or device. This option is meant to be set by programs which
94bbb2c0 1183communicate with @value{GDBN} using it as a back end.
21c294e6 1184@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1185
da0f9dcd 1186@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1187@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1188The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1189previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1190selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1191@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1192
1193@item -write
1194@cindex @code{--write}
1195Open the executable and core files for both reading and writing. This
1196is equivalent to the @samp{set write on} command inside @value{GDBN}
1197(@pxref{Patching}).
1198
1199@item -statistics
1200@cindex @code{--statistics}
1201This option causes @value{GDBN} to print statistics about time and
1202memory usage after it completes each command and returns to the prompt.
1203
1204@item -version
1205@cindex @code{--version}
1206This option causes @value{GDBN} to print its version number and
1207no-warranty blurb, and exit.
1208
c906108c
SS
1209@end table
1210
6fc08d32 1211@node Startup
79a6e687 1212@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1213@cindex @value{GDBN} startup
1214
1215Here's the description of what @value{GDBN} does during session startup:
1216
1217@enumerate
1218@item
1219Sets up the command interpreter as specified by the command line
1220(@pxref{Mode Options, interpreter}).
1221
1222@item
1223@cindex init file
1224Reads the @dfn{init file} (if any) in your home directory@footnote{On
1225DOS/Windows systems, the home directory is the one pointed to by the
1226@code{HOME} environment variable.} and executes all the commands in
1227that file.
1228
1229@item
1230Processes command line options and operands.
1231
1232@item
1233Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1234working directory. This is only done if the current directory is
1235different from your home directory. Thus, you can have more than one
1236init file, one generic in your home directory, and another, specific
1237to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1238@value{GDBN}.
1239
1240@item
1241Reads command files specified by the @samp{-x} option. @xref{Command
1242Files}, for more details about @value{GDBN} command files.
1243
1244@item
1245Reads the command history recorded in the @dfn{history file}.
d620b259 1246@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1247files where @value{GDBN} records it.
1248@end enumerate
1249
1250Init files use the same syntax as @dfn{command files} (@pxref{Command
1251Files}) and are processed by @value{GDBN} in the same way. The init
1252file in your home directory can set options (such as @samp{set
1253complaints}) that affect subsequent processing of command line options
1254and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1255option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32
EZ
1256
1257@cindex init file name
1258@cindex @file{.gdbinit}
119b882a 1259@cindex @file{gdb.ini}
8807d78b 1260The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1261The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1262the limitations of file names imposed by DOS filesystems. The Windows
1263ports of @value{GDBN} use the standard name, but if they find a
1264@file{gdb.ini} file, they warn you about that and suggest to rename
1265the file to the standard name.
1266
6fc08d32 1267
6d2ebf8b 1268@node Quitting GDB
c906108c
SS
1269@section Quitting @value{GDBN}
1270@cindex exiting @value{GDBN}
1271@cindex leaving @value{GDBN}
1272
1273@table @code
1274@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1275@kindex q @r{(@code{quit})}
96a2c332
SS
1276@item quit @r{[}@var{expression}@r{]}
1277@itemx q
1278To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1279@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1280do not supply @var{expression}, @value{GDBN} will terminate normally;
1281otherwise it will terminate using the result of @var{expression} as the
1282error code.
c906108c
SS
1283@end table
1284
1285@cindex interrupt
c8aa23ab 1286An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1287terminates the action of any @value{GDBN} command that is in progress and
1288returns to @value{GDBN} command level. It is safe to type the interrupt
1289character at any time because @value{GDBN} does not allow it to take effect
1290until a time when it is safe.
1291
c906108c
SS
1292If you have been using @value{GDBN} to control an attached process or
1293device, you can release it with the @code{detach} command
79a6e687 1294(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1295
6d2ebf8b 1296@node Shell Commands
79a6e687 1297@section Shell Commands
c906108c
SS
1298
1299If you need to execute occasional shell commands during your
1300debugging session, there is no need to leave or suspend @value{GDBN}; you can
1301just use the @code{shell} command.
1302
1303@table @code
1304@kindex shell
1305@cindex shell escape
1306@item shell @var{command string}
1307Invoke a standard shell to execute @var{command string}.
c906108c 1308If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1309shell to run. Otherwise @value{GDBN} uses the default shell
1310(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1311@end table
1312
1313The utility @code{make} is often needed in development environments.
1314You do not have to use the @code{shell} command for this purpose in
1315@value{GDBN}:
1316
1317@table @code
1318@kindex make
1319@cindex calling make
1320@item make @var{make-args}
1321Execute the @code{make} program with the specified
1322arguments. This is equivalent to @samp{shell make @var{make-args}}.
1323@end table
1324
79a6e687
BW
1325@node Logging Output
1326@section Logging Output
0fac0b41 1327@cindex logging @value{GDBN} output
9c16f35a 1328@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1329
1330You may want to save the output of @value{GDBN} commands to a file.
1331There are several commands to control @value{GDBN}'s logging.
1332
1333@table @code
1334@kindex set logging
1335@item set logging on
1336Enable logging.
1337@item set logging off
1338Disable logging.
9c16f35a 1339@cindex logging file name
0fac0b41
DJ
1340@item set logging file @var{file}
1341Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1342@item set logging overwrite [on|off]
1343By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1344you want @code{set logging on} to overwrite the logfile instead.
1345@item set logging redirect [on|off]
1346By default, @value{GDBN} output will go to both the terminal and the logfile.
1347Set @code{redirect} if you want output to go only to the log file.
1348@kindex show logging
1349@item show logging
1350Show the current values of the logging settings.
1351@end table
1352
6d2ebf8b 1353@node Commands
c906108c
SS
1354@chapter @value{GDBN} Commands
1355
1356You can abbreviate a @value{GDBN} command to the first few letters of the command
1357name, if that abbreviation is unambiguous; and you can repeat certain
1358@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1359key to get @value{GDBN} to fill out the rest of a word in a command (or to
1360show you the alternatives available, if there is more than one possibility).
1361
1362@menu
1363* Command Syntax:: How to give commands to @value{GDBN}
1364* Completion:: Command completion
1365* Help:: How to ask @value{GDBN} for help
1366@end menu
1367
6d2ebf8b 1368@node Command Syntax
79a6e687 1369@section Command Syntax
c906108c
SS
1370
1371A @value{GDBN} command is a single line of input. There is no limit on
1372how long it can be. It starts with a command name, which is followed by
1373arguments whose meaning depends on the command name. For example, the
1374command @code{step} accepts an argument which is the number of times to
1375step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1376with no arguments. Some commands do not allow any arguments.
c906108c
SS
1377
1378@cindex abbreviation
1379@value{GDBN} command names may always be truncated if that abbreviation is
1380unambiguous. Other possible command abbreviations are listed in the
1381documentation for individual commands. In some cases, even ambiguous
1382abbreviations are allowed; for example, @code{s} is specially defined as
1383equivalent to @code{step} even though there are other commands whose
1384names start with @code{s}. You can test abbreviations by using them as
1385arguments to the @code{help} command.
1386
1387@cindex repeating commands
41afff9a 1388@kindex RET @r{(repeat last command)}
c906108c 1389A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1390repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1391will not repeat this way; these are commands whose unintentional
1392repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1393repeat. User-defined commands can disable this feature; see
1394@ref{Define, dont-repeat}.
c906108c
SS
1395
1396The @code{list} and @code{x} commands, when you repeat them with
1397@key{RET}, construct new arguments rather than repeating
1398exactly as typed. This permits easy scanning of source or memory.
1399
1400@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1401output, in a way similar to the common utility @code{more}
79a6e687 1402(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1403@key{RET} too many in this situation, @value{GDBN} disables command
1404repetition after any command that generates this sort of display.
1405
41afff9a 1406@kindex # @r{(a comment)}
c906108c
SS
1407@cindex comment
1408Any text from a @kbd{#} to the end of the line is a comment; it does
1409nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1410Files,,Command Files}).
c906108c 1411
88118b3a 1412@cindex repeating command sequences
c8aa23ab
EZ
1413@kindex Ctrl-o @r{(operate-and-get-next)}
1414The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1415commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1416then fetches the next line relative to the current line from the history
1417for editing.
1418
6d2ebf8b 1419@node Completion
79a6e687 1420@section Command Completion
c906108c
SS
1421
1422@cindex completion
1423@cindex word completion
1424@value{GDBN} can fill in the rest of a word in a command for you, if there is
1425only one possibility; it can also show you what the valid possibilities
1426are for the next word in a command, at any time. This works for @value{GDBN}
1427commands, @value{GDBN} subcommands, and the names of symbols in your program.
1428
1429Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1430of a word. If there is only one possibility, @value{GDBN} fills in the
1431word, and waits for you to finish the command (or press @key{RET} to
1432enter it). For example, if you type
1433
1434@c FIXME "@key" does not distinguish its argument sufficiently to permit
1435@c complete accuracy in these examples; space introduced for clarity.
1436@c If texinfo enhancements make it unnecessary, it would be nice to
1437@c replace " @key" by "@key" in the following...
474c8240 1438@smallexample
c906108c 1439(@value{GDBP}) info bre @key{TAB}
474c8240 1440@end smallexample
c906108c
SS
1441
1442@noindent
1443@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1444the only @code{info} subcommand beginning with @samp{bre}:
1445
474c8240 1446@smallexample
c906108c 1447(@value{GDBP}) info breakpoints
474c8240 1448@end smallexample
c906108c
SS
1449
1450@noindent
1451You can either press @key{RET} at this point, to run the @code{info
1452breakpoints} command, or backspace and enter something else, if
1453@samp{breakpoints} does not look like the command you expected. (If you
1454were sure you wanted @code{info breakpoints} in the first place, you
1455might as well just type @key{RET} immediately after @samp{info bre},
1456to exploit command abbreviations rather than command completion).
1457
1458If there is more than one possibility for the next word when you press
1459@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1460characters and try again, or just press @key{TAB} a second time;
1461@value{GDBN} displays all the possible completions for that word. For
1462example, you might want to set a breakpoint on a subroutine whose name
1463begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1464just sounds the bell. Typing @key{TAB} again displays all the
1465function names in your program that begin with those characters, for
1466example:
1467
474c8240 1468@smallexample
c906108c
SS
1469(@value{GDBP}) b make_ @key{TAB}
1470@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1471make_a_section_from_file make_environ
1472make_abs_section make_function_type
1473make_blockvector make_pointer_type
1474make_cleanup make_reference_type
c906108c
SS
1475make_command make_symbol_completion_list
1476(@value{GDBP}) b make_
474c8240 1477@end smallexample
c906108c
SS
1478
1479@noindent
1480After displaying the available possibilities, @value{GDBN} copies your
1481partial input (@samp{b make_} in the example) so you can finish the
1482command.
1483
1484If you just want to see the list of alternatives in the first place, you
b37052ae 1485can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1486means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1487key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1488one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1489
1490@cindex quotes in commands
1491@cindex completion of quoted strings
1492Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1493parentheses or other characters that @value{GDBN} normally excludes from
1494its notion of a word. To permit word completion to work in this
1495situation, you may enclose words in @code{'} (single quote marks) in
1496@value{GDBN} commands.
c906108c 1497
c906108c 1498The most likely situation where you might need this is in typing the
b37052ae
EZ
1499name of a C@t{++} function. This is because C@t{++} allows function
1500overloading (multiple definitions of the same function, distinguished
1501by argument type). For example, when you want to set a breakpoint you
1502may need to distinguish whether you mean the version of @code{name}
1503that takes an @code{int} parameter, @code{name(int)}, or the version
1504that takes a @code{float} parameter, @code{name(float)}. To use the
1505word-completion facilities in this situation, type a single quote
1506@code{'} at the beginning of the function name. This alerts
1507@value{GDBN} that it may need to consider more information than usual
1508when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1509
474c8240 1510@smallexample
96a2c332 1511(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1512bubble(double,double) bubble(int,int)
1513(@value{GDBP}) b 'bubble(
474c8240 1514@end smallexample
c906108c
SS
1515
1516In some cases, @value{GDBN} can tell that completing a name requires using
1517quotes. When this happens, @value{GDBN} inserts the quote for you (while
1518completing as much as it can) if you do not type the quote in the first
1519place:
1520
474c8240 1521@smallexample
c906108c
SS
1522(@value{GDBP}) b bub @key{TAB}
1523@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1524(@value{GDBP}) b 'bubble(
474c8240 1525@end smallexample
c906108c
SS
1526
1527@noindent
1528In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1529you have not yet started typing the argument list when you ask for
1530completion on an overloaded symbol.
1531
79a6e687
BW
1532For more information about overloaded functions, see @ref{C Plus Plus
1533Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1534overload-resolution off} to disable overload resolution;
79a6e687 1535see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1536
65d12d83
TT
1537@cindex completion of structure field names
1538@cindex structure field name completion
1539@cindex completion of union field names
1540@cindex union field name completion
1541When completing in an expression which looks up a field in a
1542structure, @value{GDBN} also tries@footnote{The completer can be
1543confused by certain kinds of invalid expressions. Also, it only
1544examines the static type of the expression, not the dynamic type.} to
1545limit completions to the field names available in the type of the
1546left-hand-side:
1547
1548@smallexample
1549(@value{GDBP}) p gdb_stdout.@kbd{M-?}
1550magic to_delete to_fputs to_put to_rewind
1551to_data to_flush to_isatty to_read to_write
1552@end smallexample
1553
1554@noindent
1555This is because the @code{gdb_stdout} is a variable of the type
1556@code{struct ui_file} that is defined in @value{GDBN} sources as
1557follows:
1558
1559@smallexample
1560struct ui_file
1561@{
1562 int *magic;
1563 ui_file_flush_ftype *to_flush;
1564 ui_file_write_ftype *to_write;
1565 ui_file_fputs_ftype *to_fputs;
1566 ui_file_read_ftype *to_read;
1567 ui_file_delete_ftype *to_delete;
1568 ui_file_isatty_ftype *to_isatty;
1569 ui_file_rewind_ftype *to_rewind;
1570 ui_file_put_ftype *to_put;
1571 void *to_data;
1572@}
1573@end smallexample
1574
c906108c 1575
6d2ebf8b 1576@node Help
79a6e687 1577@section Getting Help
c906108c
SS
1578@cindex online documentation
1579@kindex help
1580
5d161b24 1581You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1582using the command @code{help}.
1583
1584@table @code
41afff9a 1585@kindex h @r{(@code{help})}
c906108c
SS
1586@item help
1587@itemx h
1588You can use @code{help} (abbreviated @code{h}) with no arguments to
1589display a short list of named classes of commands:
1590
1591@smallexample
1592(@value{GDBP}) help
1593List of classes of commands:
1594
2df3850c 1595aliases -- Aliases of other commands
c906108c 1596breakpoints -- Making program stop at certain points
2df3850c 1597data -- Examining data
c906108c 1598files -- Specifying and examining files
2df3850c
JM
1599internals -- Maintenance commands
1600obscure -- Obscure features
1601running -- Running the program
1602stack -- Examining the stack
c906108c
SS
1603status -- Status inquiries
1604support -- Support facilities
12c27660 1605tracepoints -- Tracing of program execution without
96a2c332 1606 stopping the program
c906108c 1607user-defined -- User-defined commands
c906108c 1608
5d161b24 1609Type "help" followed by a class name for a list of
c906108c 1610commands in that class.
5d161b24 1611Type "help" followed by command name for full
c906108c
SS
1612documentation.
1613Command name abbreviations are allowed if unambiguous.
1614(@value{GDBP})
1615@end smallexample
96a2c332 1616@c the above line break eliminates huge line overfull...
c906108c
SS
1617
1618@item help @var{class}
1619Using one of the general help classes as an argument, you can get a
1620list of the individual commands in that class. For example, here is the
1621help display for the class @code{status}:
1622
1623@smallexample
1624(@value{GDBP}) help status
1625Status inquiries.
1626
1627List of commands:
1628
1629@c Line break in "show" line falsifies real output, but needed
1630@c to fit in smallbook page size.
2df3850c 1631info -- Generic command for showing things
12c27660 1632 about the program being debugged
2df3850c 1633show -- Generic command for showing things
12c27660 1634 about the debugger
c906108c 1635
5d161b24 1636Type "help" followed by command name for full
c906108c
SS
1637documentation.
1638Command name abbreviations are allowed if unambiguous.
1639(@value{GDBP})
1640@end smallexample
1641
1642@item help @var{command}
1643With a command name as @code{help} argument, @value{GDBN} displays a
1644short paragraph on how to use that command.
1645
6837a0a2
DB
1646@kindex apropos
1647@item apropos @var{args}
09d4efe1 1648The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1649commands, and their documentation, for the regular expression specified in
1650@var{args}. It prints out all matches found. For example:
1651
1652@smallexample
1653apropos reload
1654@end smallexample
1655
b37052ae
EZ
1656@noindent
1657results in:
6837a0a2
DB
1658
1659@smallexample
6d2ebf8b
SS
1660@c @group
1661set symbol-reloading -- Set dynamic symbol table reloading
12c27660 1662 multiple times in one run
6d2ebf8b 1663show symbol-reloading -- Show dynamic symbol table reloading
12c27660 1664 multiple times in one run
6d2ebf8b 1665@c @end group
6837a0a2
DB
1666@end smallexample
1667
c906108c
SS
1668@kindex complete
1669@item complete @var{args}
1670The @code{complete @var{args}} command lists all the possible completions
1671for the beginning of a command. Use @var{args} to specify the beginning of the
1672command you want completed. For example:
1673
1674@smallexample
1675complete i
1676@end smallexample
1677
1678@noindent results in:
1679
1680@smallexample
1681@group
2df3850c
JM
1682if
1683ignore
c906108c
SS
1684info
1685inspect
c906108c
SS
1686@end group
1687@end smallexample
1688
1689@noindent This is intended for use by @sc{gnu} Emacs.
1690@end table
1691
1692In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1693and @code{show} to inquire about the state of your program, or the state
1694of @value{GDBN} itself. Each command supports many topics of inquiry; this
1695manual introduces each of them in the appropriate context. The listings
1696under @code{info} and under @code{show} in the Index point to
1697all the sub-commands. @xref{Index}.
1698
1699@c @group
1700@table @code
1701@kindex info
41afff9a 1702@kindex i @r{(@code{info})}
c906108c
SS
1703@item info
1704This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1705program. For example, you can show the arguments passed to a function
c906108c
SS
1706with @code{info args}, list the registers currently in use with @code{info
1707registers}, or list the breakpoints you have set with @code{info breakpoints}.
1708You can get a complete list of the @code{info} sub-commands with
1709@w{@code{help info}}.
1710
1711@kindex set
1712@item set
5d161b24 1713You can assign the result of an expression to an environment variable with
c906108c
SS
1714@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1715@code{set prompt $}.
1716
1717@kindex show
1718@item show
5d161b24 1719In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1720@value{GDBN} itself.
1721You can change most of the things you can @code{show}, by using the
1722related command @code{set}; for example, you can control what number
1723system is used for displays with @code{set radix}, or simply inquire
1724which is currently in use with @code{show radix}.
1725
1726@kindex info set
1727To display all the settable parameters and their current
1728values, you can use @code{show} with no arguments; you may also use
1729@code{info set}. Both commands produce the same display.
1730@c FIXME: "info set" violates the rule that "info" is for state of
1731@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1732@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1733@end table
1734@c @end group
1735
1736Here are three miscellaneous @code{show} subcommands, all of which are
1737exceptional in lacking corresponding @code{set} commands:
1738
1739@table @code
1740@kindex show version
9c16f35a 1741@cindex @value{GDBN} version number
c906108c
SS
1742@item show version
1743Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1744information in @value{GDBN} bug-reports. If multiple versions of
1745@value{GDBN} are in use at your site, you may need to determine which
1746version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1747commands are introduced, and old ones may wither away. Also, many
1748system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1749variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1750The version number is the same as the one announced when you start
1751@value{GDBN}.
c906108c
SS
1752
1753@kindex show copying
09d4efe1 1754@kindex info copying
9c16f35a 1755@cindex display @value{GDBN} copyright
c906108c 1756@item show copying
09d4efe1 1757@itemx info copying
c906108c
SS
1758Display information about permission for copying @value{GDBN}.
1759
1760@kindex show warranty
09d4efe1 1761@kindex info warranty
c906108c 1762@item show warranty
09d4efe1 1763@itemx info warranty
2df3850c 1764Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1765if your version of @value{GDBN} comes with one.
2df3850c 1766
c906108c
SS
1767@end table
1768
6d2ebf8b 1769@node Running
c906108c
SS
1770@chapter Running Programs Under @value{GDBN}
1771
1772When you run a program under @value{GDBN}, you must first generate
1773debugging information when you compile it.
7a292a7a
SS
1774
1775You may start @value{GDBN} with its arguments, if any, in an environment
1776of your choice. If you are doing native debugging, you may redirect
1777your program's input and output, debug an already running process, or
1778kill a child process.
c906108c
SS
1779
1780@menu
1781* Compilation:: Compiling for debugging
1782* Starting:: Starting your program
c906108c
SS
1783* Arguments:: Your program's arguments
1784* Environment:: Your program's environment
c906108c
SS
1785
1786* Working Directory:: Your program's working directory
1787* Input/Output:: Your program's input and output
1788* Attach:: Debugging an already-running process
1789* Kill Process:: Killing the child process
c906108c 1790
b77209e0 1791* Inferiors:: Debugging multiple inferiors
c906108c
SS
1792* Threads:: Debugging programs with multiple threads
1793* Processes:: Debugging programs with multiple processes
5c95884b 1794* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1795@end menu
1796
6d2ebf8b 1797@node Compilation
79a6e687 1798@section Compiling for Debugging
c906108c
SS
1799
1800In order to debug a program effectively, you need to generate
1801debugging information when you compile it. This debugging information
1802is stored in the object file; it describes the data type of each
1803variable or function and the correspondence between source line numbers
1804and addresses in the executable code.
1805
1806To request debugging information, specify the @samp{-g} option when you run
1807the compiler.
1808
514c4d71
EZ
1809Programs that are to be shipped to your customers are compiled with
1810optimizations, using the @samp{-O} compiler option. However, many
1811compilers are unable to handle the @samp{-g} and @samp{-O} options
1812together. Using those compilers, you cannot generate optimized
c906108c
SS
1813executables containing debugging information.
1814
514c4d71 1815@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1816without @samp{-O}, making it possible to debug optimized code. We
1817recommend that you @emph{always} use @samp{-g} whenever you compile a
1818program. You may think your program is correct, but there is no sense
1819in pushing your luck.
c906108c
SS
1820
1821@cindex optimized code, debugging
1822@cindex debugging optimized code
1823When you debug a program compiled with @samp{-g -O}, remember that the
1824optimizer is rearranging your code; the debugger shows you what is
1825really there. Do not be too surprised when the execution path does not
1826exactly match your source file! An extreme example: if you define a
1827variable, but never use it, @value{GDBN} never sees that
1828variable---because the compiler optimizes it out of existence.
1829
1830Some things do not work as well with @samp{-g -O} as with just
1831@samp{-g}, particularly on machines with instruction scheduling. If in
1832doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1833please report it to us as a bug (including a test case!).
15387254 1834@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1835
1836Older versions of the @sc{gnu} C compiler permitted a variant option
1837@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1838format; if your @sc{gnu} C compiler has this option, do not use it.
1839
514c4d71
EZ
1840@value{GDBN} knows about preprocessor macros and can show you their
1841expansion (@pxref{Macros}). Most compilers do not include information
1842about preprocessor macros in the debugging information if you specify
1843the @option{-g} flag alone, because this information is rather large.
1844Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1845provides macro information if you specify the options
1846@option{-gdwarf-2} and @option{-g3}; the former option requests
1847debugging information in the Dwarf 2 format, and the latter requests
1848``extra information''. In the future, we hope to find more compact
1849ways to represent macro information, so that it can be included with
1850@option{-g} alone.
1851
c906108c 1852@need 2000
6d2ebf8b 1853@node Starting
79a6e687 1854@section Starting your Program
c906108c
SS
1855@cindex starting
1856@cindex running
1857
1858@table @code
1859@kindex run
41afff9a 1860@kindex r @r{(@code{run})}
c906108c
SS
1861@item run
1862@itemx r
7a292a7a
SS
1863Use the @code{run} command to start your program under @value{GDBN}.
1864You must first specify the program name (except on VxWorks) with an
1865argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1866@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
79a6e687 1867(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
1868
1869@end table
1870
c906108c
SS
1871If you are running your program in an execution environment that
1872supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
1873that process run your program. In some environments without processes,
1874@code{run} jumps to the start of your program. Other targets,
1875like @samp{remote}, are always running. If you get an error
1876message like this one:
1877
1878@smallexample
1879The "remote" target does not support "run".
1880Try "help target" or "continue".
1881@end smallexample
1882
1883@noindent
1884then use @code{continue} to run your program. You may need @code{load}
1885first (@pxref{load}).
c906108c
SS
1886
1887The execution of a program is affected by certain information it
1888receives from its superior. @value{GDBN} provides ways to specify this
1889information, which you must do @emph{before} starting your program. (You
1890can change it after starting your program, but such changes only affect
1891your program the next time you start it.) This information may be
1892divided into four categories:
1893
1894@table @asis
1895@item The @emph{arguments.}
1896Specify the arguments to give your program as the arguments of the
1897@code{run} command. If a shell is available on your target, the shell
1898is used to pass the arguments, so that you may use normal conventions
1899(such as wildcard expansion or variable substitution) in describing
1900the arguments.
1901In Unix systems, you can control which shell is used with the
1902@code{SHELL} environment variable.
79a6e687 1903@xref{Arguments, ,Your Program's Arguments}.
c906108c
SS
1904
1905@item The @emph{environment.}
1906Your program normally inherits its environment from @value{GDBN}, but you can
1907use the @value{GDBN} commands @code{set environment} and @code{unset
1908environment} to change parts of the environment that affect
79a6e687 1909your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
1910
1911@item The @emph{working directory.}
1912Your program inherits its working directory from @value{GDBN}. You can set
1913the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 1914@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
1915
1916@item The @emph{standard input and output.}
1917Your program normally uses the same device for standard input and
1918standard output as @value{GDBN} is using. You can redirect input and output
1919in the @code{run} command line, or you can use the @code{tty} command to
1920set a different device for your program.
79a6e687 1921@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
1922
1923@cindex pipes
1924@emph{Warning:} While input and output redirection work, you cannot use
1925pipes to pass the output of the program you are debugging to another
1926program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1927wrong program.
1928@end table
c906108c
SS
1929
1930When you issue the @code{run} command, your program begins to execute
79a6e687 1931immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
1932of how to arrange for your program to stop. Once your program has
1933stopped, you may call functions in your program, using the @code{print}
1934or @code{call} commands. @xref{Data, ,Examining Data}.
1935
1936If the modification time of your symbol file has changed since the last
1937time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1938table, and reads it again. When it does this, @value{GDBN} tries to retain
1939your current breakpoints.
1940
4e8b0763
JB
1941@table @code
1942@kindex start
1943@item start
1944@cindex run to main procedure
1945The name of the main procedure can vary from language to language.
1946With C or C@t{++}, the main procedure name is always @code{main}, but
1947other languages such as Ada do not require a specific name for their
1948main procedure. The debugger provides a convenient way to start the
1949execution of the program and to stop at the beginning of the main
1950procedure, depending on the language used.
1951
1952The @samp{start} command does the equivalent of setting a temporary
1953breakpoint at the beginning of the main procedure and then invoking
1954the @samp{run} command.
1955
f018e82f
EZ
1956@cindex elaboration phase
1957Some programs contain an @dfn{elaboration} phase where some startup code is
1958executed before the main procedure is called. This depends on the
1959languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1960constructors for static and global objects are executed before
1961@code{main} is called. It is therefore possible that the debugger stops
1962before reaching the main procedure. However, the temporary breakpoint
1963will remain to halt execution.
1964
1965Specify the arguments to give to your program as arguments to the
1966@samp{start} command. These arguments will be given verbatim to the
1967underlying @samp{run} command. Note that the same arguments will be
1968reused if no argument is provided during subsequent calls to
1969@samp{start} or @samp{run}.
1970
1971It is sometimes necessary to debug the program during elaboration. In
1972these cases, using the @code{start} command would stop the execution of
1973your program too late, as the program would have already completed the
1974elaboration phase. Under these circumstances, insert breakpoints in your
1975elaboration code before running your program.
ccd213ac
DJ
1976
1977@kindex set exec-wrapper
1978@item set exec-wrapper @var{wrapper}
1979@itemx show exec-wrapper
1980@itemx unset exec-wrapper
1981When @samp{exec-wrapper} is set, the specified wrapper is used to
1982launch programs for debugging. @value{GDBN} starts your program
1983with a shell command of the form @kbd{exec @var{wrapper}
1984@var{program}}. Quoting is added to @var{program} and its
1985arguments, but not to @var{wrapper}, so you should add quotes if
1986appropriate for your shell. The wrapper runs until it executes
1987your program, and then @value{GDBN} takes control.
1988
1989You can use any program that eventually calls @code{execve} with
1990its arguments as a wrapper. Several standard Unix utilities do
1991this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
1992with @code{exec "$@@"} will also work.
1993
1994For example, you can use @code{env} to pass an environment variable to
1995the debugged program, without setting the variable in your shell's
1996environment:
1997
1998@smallexample
1999(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2000(@value{GDBP}) run
2001@end smallexample
2002
2003This command is available when debugging locally on most targets, excluding
2004@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2005
10568435
JK
2006@kindex set disable-randomization
2007@item set disable-randomization
2008@itemx set disable-randomization on
2009This option (enabled by default in @value{GDBN}) will turn off the native
2010randomization of the virtual address space of the started program. This option
2011is useful for multiple debugging sessions to make the execution better
2012reproducible and memory addresses reusable across debugging sessions.
2013
2014This feature is implemented only on @sc{gnu}/Linux. You can get the same
2015behavior using
2016
2017@smallexample
2018(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2019@end smallexample
2020
2021@item set disable-randomization off
2022Leave the behavior of the started executable unchanged. Some bugs rear their
2023ugly heads only when the program is loaded at certain addresses. If your bug
2024disappears when you run the program under @value{GDBN}, that might be because
2025@value{GDBN} by default disables the address randomization on platforms, such
2026as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2027disable-randomization off} to try to reproduce such elusive bugs.
2028
2029The virtual address space randomization is implemented only on @sc{gnu}/Linux.
2030It protects the programs against some kinds of security attacks. In these
2031cases the attacker needs to know the exact location of a concrete executable
2032code. Randomizing its location makes it impossible to inject jumps misusing
2033a code at its expected addresses.
2034
2035Prelinking shared libraries provides a startup performance advantage but it
2036makes addresses in these libraries predictable for privileged processes by
2037having just unprivileged access at the target system. Reading the shared
2038library binary gives enough information for assembling the malicious code
2039misusing it. Still even a prelinked shared library can get loaded at a new
2040random address just requiring the regular relocation process during the
2041startup. Shared libraries not already prelinked are always loaded at
2042a randomly chosen address.
2043
2044Position independent executables (PIE) contain position independent code
2045similar to the shared libraries and therefore such executables get loaded at
2046a randomly chosen address upon startup. PIE executables always load even
2047already prelinked shared libraries at a random address. You can build such
2048executable using @command{gcc -fPIE -pie}.
2049
2050Heap (malloc storage), stack and custom mmap areas are always placed randomly
2051(as long as the randomization is enabled).
2052
2053@item show disable-randomization
2054Show the current setting of the explicit disable of the native randomization of
2055the virtual address space of the started program.
2056
4e8b0763
JB
2057@end table
2058
6d2ebf8b 2059@node Arguments
79a6e687 2060@section Your Program's Arguments
c906108c
SS
2061
2062@cindex arguments (to your program)
2063The arguments to your program can be specified by the arguments of the
5d161b24 2064@code{run} command.
c906108c
SS
2065They are passed to a shell, which expands wildcard characters and
2066performs redirection of I/O, and thence to your program. Your
2067@code{SHELL} environment variable (if it exists) specifies what shell
2068@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2069the default shell (@file{/bin/sh} on Unix).
2070
2071On non-Unix systems, the program is usually invoked directly by
2072@value{GDBN}, which emulates I/O redirection via the appropriate system
2073calls, and the wildcard characters are expanded by the startup code of
2074the program, not by the shell.
c906108c
SS
2075
2076@code{run} with no arguments uses the same arguments used by the previous
2077@code{run}, or those set by the @code{set args} command.
2078
c906108c 2079@table @code
41afff9a 2080@kindex set args
c906108c
SS
2081@item set args
2082Specify the arguments to be used the next time your program is run. If
2083@code{set args} has no arguments, @code{run} executes your program
2084with no arguments. Once you have run your program with arguments,
2085using @code{set args} before the next @code{run} is the only way to run
2086it again without arguments.
2087
2088@kindex show args
2089@item show args
2090Show the arguments to give your program when it is started.
2091@end table
2092
6d2ebf8b 2093@node Environment
79a6e687 2094@section Your Program's Environment
c906108c
SS
2095
2096@cindex environment (of your program)
2097The @dfn{environment} consists of a set of environment variables and
2098their values. Environment variables conventionally record such things as
2099your user name, your home directory, your terminal type, and your search
2100path for programs to run. Usually you set up environment variables with
2101the shell and they are inherited by all the other programs you run. When
2102debugging, it can be useful to try running your program with a modified
2103environment without having to start @value{GDBN} over again.
2104
2105@table @code
2106@kindex path
2107@item path @var{directory}
2108Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2109(the search path for executables) that will be passed to your program.
2110The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2111You may specify several directory names, separated by whitespace or by a
2112system-dependent separator character (@samp{:} on Unix, @samp{;} on
2113MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2114is moved to the front, so it is searched sooner.
c906108c
SS
2115
2116You can use the string @samp{$cwd} to refer to whatever is the current
2117working directory at the time @value{GDBN} searches the path. If you
2118use @samp{.} instead, it refers to the directory where you executed the
2119@code{path} command. @value{GDBN} replaces @samp{.} in the
2120@var{directory} argument (with the current path) before adding
2121@var{directory} to the search path.
2122@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2123@c document that, since repeating it would be a no-op.
2124
2125@kindex show paths
2126@item show paths
2127Display the list of search paths for executables (the @code{PATH}
2128environment variable).
2129
2130@kindex show environment
2131@item show environment @r{[}@var{varname}@r{]}
2132Print the value of environment variable @var{varname} to be given to
2133your program when it starts. If you do not supply @var{varname},
2134print the names and values of all environment variables to be given to
2135your program. You can abbreviate @code{environment} as @code{env}.
2136
2137@kindex set environment
53a5351d 2138@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
2139Set environment variable @var{varname} to @var{value}. The value
2140changes for your program only, not for @value{GDBN} itself. @var{value} may
2141be any string; the values of environment variables are just strings, and
2142any interpretation is supplied by your program itself. The @var{value}
2143parameter is optional; if it is eliminated, the variable is set to a
2144null value.
2145@c "any string" here does not include leading, trailing
2146@c blanks. Gnu asks: does anyone care?
2147
2148For example, this command:
2149
474c8240 2150@smallexample
c906108c 2151set env USER = foo
474c8240 2152@end smallexample
c906108c
SS
2153
2154@noindent
d4f3574e 2155tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2156@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2157are not actually required.)
2158
2159@kindex unset environment
2160@item unset environment @var{varname}
2161Remove variable @var{varname} from the environment to be passed to your
2162program. This is different from @samp{set env @var{varname} =};
2163@code{unset environment} removes the variable from the environment,
2164rather than assigning it an empty value.
2165@end table
2166
d4f3574e
SS
2167@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2168the shell indicated
c906108c
SS
2169by your @code{SHELL} environment variable if it exists (or
2170@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2171that runs an initialization file---such as @file{.cshrc} for C-shell, or
2172@file{.bashrc} for BASH---any variables you set in that file affect
2173your program. You may wish to move setting of environment variables to
2174files that are only run when you sign on, such as @file{.login} or
2175@file{.profile}.
2176
6d2ebf8b 2177@node Working Directory
79a6e687 2178@section Your Program's Working Directory
c906108c
SS
2179
2180@cindex working directory (of your program)
2181Each time you start your program with @code{run}, it inherits its
2182working directory from the current working directory of @value{GDBN}.
2183The @value{GDBN} working directory is initially whatever it inherited
2184from its parent process (typically the shell), but you can specify a new
2185working directory in @value{GDBN} with the @code{cd} command.
2186
2187The @value{GDBN} working directory also serves as a default for the commands
2188that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2189Specify Files}.
c906108c
SS
2190
2191@table @code
2192@kindex cd
721c2651 2193@cindex change working directory
c906108c
SS
2194@item cd @var{directory}
2195Set the @value{GDBN} working directory to @var{directory}.
2196
2197@kindex pwd
2198@item pwd
2199Print the @value{GDBN} working directory.
2200@end table
2201
60bf7e09
EZ
2202It is generally impossible to find the current working directory of
2203the process being debugged (since a program can change its directory
2204during its run). If you work on a system where @value{GDBN} is
2205configured with the @file{/proc} support, you can use the @code{info
2206proc} command (@pxref{SVR4 Process Information}) to find out the
2207current working directory of the debuggee.
2208
6d2ebf8b 2209@node Input/Output
79a6e687 2210@section Your Program's Input and Output
c906108c
SS
2211
2212@cindex redirection
2213@cindex i/o
2214@cindex terminal
2215By default, the program you run under @value{GDBN} does input and output to
5d161b24 2216the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2217to its own terminal modes to interact with you, but it records the terminal
2218modes your program was using and switches back to them when you continue
2219running your program.
2220
2221@table @code
2222@kindex info terminal
2223@item info terminal
2224Displays information recorded by @value{GDBN} about the terminal modes your
2225program is using.
2226@end table
2227
2228You can redirect your program's input and/or output using shell
2229redirection with the @code{run} command. For example,
2230
474c8240 2231@smallexample
c906108c 2232run > outfile
474c8240 2233@end smallexample
c906108c
SS
2234
2235@noindent
2236starts your program, diverting its output to the file @file{outfile}.
2237
2238@kindex tty
2239@cindex controlling terminal
2240Another way to specify where your program should do input and output is
2241with the @code{tty} command. This command accepts a file name as
2242argument, and causes this file to be the default for future @code{run}
2243commands. It also resets the controlling terminal for the child
2244process, for future @code{run} commands. For example,
2245
474c8240 2246@smallexample
c906108c 2247tty /dev/ttyb
474c8240 2248@end smallexample
c906108c
SS
2249
2250@noindent
2251directs that processes started with subsequent @code{run} commands
2252default to do input and output on the terminal @file{/dev/ttyb} and have
2253that as their controlling terminal.
2254
2255An explicit redirection in @code{run} overrides the @code{tty} command's
2256effect on the input/output device, but not its effect on the controlling
2257terminal.
2258
2259When you use the @code{tty} command or redirect input in the @code{run}
2260command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2261for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2262for @code{set inferior-tty}.
2263
2264@cindex inferior tty
2265@cindex set inferior controlling terminal
2266You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2267display the name of the terminal that will be used for future runs of your
2268program.
2269
2270@table @code
2271@item set inferior-tty /dev/ttyb
2272@kindex set inferior-tty
2273Set the tty for the program being debugged to /dev/ttyb.
2274
2275@item show inferior-tty
2276@kindex show inferior-tty
2277Show the current tty for the program being debugged.
2278@end table
c906108c 2279
6d2ebf8b 2280@node Attach
79a6e687 2281@section Debugging an Already-running Process
c906108c
SS
2282@kindex attach
2283@cindex attach
2284
2285@table @code
2286@item attach @var{process-id}
2287This command attaches to a running process---one that was started
2288outside @value{GDBN}. (@code{info files} shows your active
2289targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2290find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2291or with the @samp{jobs -l} shell command.
2292
2293@code{attach} does not repeat if you press @key{RET} a second time after
2294executing the command.
2295@end table
2296
2297To use @code{attach}, your program must be running in an environment
2298which supports processes; for example, @code{attach} does not work for
2299programs on bare-board targets that lack an operating system. You must
2300also have permission to send the process a signal.
2301
2302When you use @code{attach}, the debugger finds the program running in
2303the process first by looking in the current working directory, then (if
2304the program is not found) by using the source file search path
79a6e687 2305(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2306the @code{file} command to load the program. @xref{Files, ,Commands to
2307Specify Files}.
2308
2309The first thing @value{GDBN} does after arranging to debug the specified
2310process is to stop it. You can examine and modify an attached process
53a5351d
JM
2311with all the @value{GDBN} commands that are ordinarily available when
2312you start processes with @code{run}. You can insert breakpoints; you
2313can step and continue; you can modify storage. If you would rather the
2314process continue running, you may use the @code{continue} command after
c906108c
SS
2315attaching @value{GDBN} to the process.
2316
2317@table @code
2318@kindex detach
2319@item detach
2320When you have finished debugging the attached process, you can use the
2321@code{detach} command to release it from @value{GDBN} control. Detaching
2322the process continues its execution. After the @code{detach} command,
2323that process and @value{GDBN} become completely independent once more, and you
2324are ready to @code{attach} another process or start one with @code{run}.
2325@code{detach} does not repeat if you press @key{RET} again after
2326executing the command.
2327@end table
2328
159fcc13
JK
2329If you exit @value{GDBN} while you have an attached process, you detach
2330that process. If you use the @code{run} command, you kill that process.
2331By default, @value{GDBN} asks for confirmation if you try to do either of these
2332things; you can control whether or not you need to confirm by using the
2333@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2334Messages}).
c906108c 2335
6d2ebf8b 2336@node Kill Process
79a6e687 2337@section Killing the Child Process
c906108c
SS
2338
2339@table @code
2340@kindex kill
2341@item kill
2342Kill the child process in which your program is running under @value{GDBN}.
2343@end table
2344
2345This command is useful if you wish to debug a core dump instead of a
2346running process. @value{GDBN} ignores any core dump file while your program
2347is running.
2348
2349On some operating systems, a program cannot be executed outside @value{GDBN}
2350while you have breakpoints set on it inside @value{GDBN}. You can use the
2351@code{kill} command in this situation to permit running your program
2352outside the debugger.
2353
2354The @code{kill} command is also useful if you wish to recompile and
2355relink your program, since on many systems it is impossible to modify an
2356executable file while it is running in a process. In this case, when you
2357next type @code{run}, @value{GDBN} notices that the file has changed, and
2358reads the symbol table again (while trying to preserve your current
2359breakpoint settings).
2360
b77209e0
PA
2361@node Inferiors
2362@section Debugging Multiple Inferiors
2363
2364Some @value{GDBN} targets are able to run multiple processes created
2365from a single executable. This can happen, for instance, with an
2366embedded system reporting back several processes via the remote
2367protocol.
2368
2369@cindex inferior
2370@value{GDBN} represents the state of each program execution with an
2371object called an @dfn{inferior}. An inferior typically corresponds to
2372a process, but is more general and applies also to targets that do not
2373have processes. Inferiors may be created before a process runs, and
2374may (in future) be retained after a process exits. Each run of an
2375executable creates a new inferior, as does each attachment to an
2376existing process. Inferiors have unique identifiers that are
2377different from process ids, and may optionally be named as well.
2378Usually each inferior will also have its own distinct address space,
2379although some embedded targets may have several inferiors running in
2380different parts of a single space.
2381
2382Each inferior may in turn have multiple threads running in it.
2383
2384To find out what inferiors exist at any moment, use @code{info inferiors}:
2385
2386@table @code
2387@kindex info inferiors
2388@item info inferiors
2389Print a list of all inferiors currently being managed by @value{GDBN}.
2390
2391@kindex set print inferior-events
2392@cindex print messages on inferior start and exit
2393@item set print inferior-events
2394@itemx set print inferior-events on
2395@itemx set print inferior-events off
2396The @code{set print inferior-events} command allows you to enable or
2397disable printing of messages when @value{GDBN} notices that new
2398inferiors have started or that inferiors have exited or have been
2399detached. By default, these messages will not be printed.
2400
2401@kindex show print inferior-events
2402@item show print inferior-events
2403Show whether messages will be printed when @value{GDBN} detects that
2404inferiors have started, exited or have been detached.
2405@end table
2406
6d2ebf8b 2407@node Threads
79a6e687 2408@section Debugging Programs with Multiple Threads
c906108c
SS
2409
2410@cindex threads of execution
2411@cindex multiple threads
2412@cindex switching threads
2413In some operating systems, such as HP-UX and Solaris, a single program
2414may have more than one @dfn{thread} of execution. The precise semantics
2415of threads differ from one operating system to another, but in general
2416the threads of a single program are akin to multiple processes---except
2417that they share one address space (that is, they can all examine and
2418modify the same variables). On the other hand, each thread has its own
2419registers and execution stack, and perhaps private memory.
2420
2421@value{GDBN} provides these facilities for debugging multi-thread
2422programs:
2423
2424@itemize @bullet
2425@item automatic notification of new threads
2426@item @samp{thread @var{threadno}}, a command to switch among threads
2427@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2428@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2429a command to apply a command to a list of threads
2430@item thread-specific breakpoints
93815fbf
VP
2431@item @samp{set print thread-events}, which controls printing of
2432messages on thread start and exit.
c906108c
SS
2433@end itemize
2434
c906108c
SS
2435@quotation
2436@emph{Warning:} These facilities are not yet available on every
2437@value{GDBN} configuration where the operating system supports threads.
2438If your @value{GDBN} does not support threads, these commands have no
2439effect. For example, a system without thread support shows no output
2440from @samp{info threads}, and always rejects the @code{thread} command,
2441like this:
2442
2443@smallexample
2444(@value{GDBP}) info threads
2445(@value{GDBP}) thread 1
2446Thread ID 1 not known. Use the "info threads" command to
2447see the IDs of currently known threads.
2448@end smallexample
2449@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2450@c doesn't support threads"?
2451@end quotation
c906108c
SS
2452
2453@cindex focus of debugging
2454@cindex current thread
2455The @value{GDBN} thread debugging facility allows you to observe all
2456threads while your program runs---but whenever @value{GDBN} takes
2457control, one thread in particular is always the focus of debugging.
2458This thread is called the @dfn{current thread}. Debugging commands show
2459program information from the perspective of the current thread.
2460
41afff9a 2461@cindex @code{New} @var{systag} message
c906108c
SS
2462@cindex thread identifier (system)
2463@c FIXME-implementors!! It would be more helpful if the [New...] message
2464@c included GDB's numeric thread handle, so you could just go to that
2465@c thread without first checking `info threads'.
2466Whenever @value{GDBN} detects a new thread in your program, it displays
2467the target system's identification for the thread with a message in the
2468form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2469whose form varies depending on the particular system. For example, on
8807d78b 2470@sc{gnu}/Linux, you might see
c906108c 2471
474c8240 2472@smallexample
8807d78b 2473[New Thread 46912507313328 (LWP 25582)]
474c8240 2474@end smallexample
c906108c
SS
2475
2476@noindent
2477when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2478the @var{systag} is simply something like @samp{process 368}, with no
2479further qualifier.
2480
2481@c FIXME!! (1) Does the [New...] message appear even for the very first
2482@c thread of a program, or does it only appear for the
6ca652b0 2483@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2484@c program?
2485@c (2) *Is* there necessarily a first thread always? Or do some
2486@c multithread systems permit starting a program with multiple
5d161b24 2487@c threads ab initio?
c906108c
SS
2488
2489@cindex thread number
2490@cindex thread identifier (GDB)
2491For debugging purposes, @value{GDBN} associates its own thread
2492number---always a single integer---with each thread in your program.
2493
2494@table @code
2495@kindex info threads
2496@item info threads
2497Display a summary of all threads currently in your
2498program. @value{GDBN} displays for each thread (in this order):
2499
2500@enumerate
09d4efe1
EZ
2501@item
2502the thread number assigned by @value{GDBN}
c906108c 2503
09d4efe1
EZ
2504@item
2505the target system's thread identifier (@var{systag})
c906108c 2506
09d4efe1
EZ
2507@item
2508the current stack frame summary for that thread
c906108c
SS
2509@end enumerate
2510
2511@noindent
2512An asterisk @samp{*} to the left of the @value{GDBN} thread number
2513indicates the current thread.
2514
5d161b24 2515For example,
c906108c
SS
2516@end table
2517@c end table here to get a little more width for example
2518
2519@smallexample
2520(@value{GDBP}) info threads
2521 3 process 35 thread 27 0x34e5 in sigpause ()
2522 2 process 35 thread 23 0x34e5 in sigpause ()
2523* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2524 at threadtest.c:68
2525@end smallexample
53a5351d
JM
2526
2527On HP-UX systems:
c906108c 2528
4644b6e3
EZ
2529@cindex debugging multithreaded programs (on HP-UX)
2530@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2531For debugging purposes, @value{GDBN} associates its own thread
2532number---a small integer assigned in thread-creation order---with each
2533thread in your program.
2534
41afff9a
EZ
2535@cindex @code{New} @var{systag} message, on HP-UX
2536@cindex thread identifier (system), on HP-UX
c906108c
SS
2537@c FIXME-implementors!! It would be more helpful if the [New...] message
2538@c included GDB's numeric thread handle, so you could just go to that
2539@c thread without first checking `info threads'.
2540Whenever @value{GDBN} detects a new thread in your program, it displays
2541both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2542form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2543whose form varies depending on the particular system. For example, on
2544HP-UX, you see
2545
474c8240 2546@smallexample
c906108c 2547[New thread 2 (system thread 26594)]
474c8240 2548@end smallexample
c906108c
SS
2549
2550@noindent
5d161b24 2551when @value{GDBN} notices a new thread.
c906108c
SS
2552
2553@table @code
4644b6e3 2554@kindex info threads (HP-UX)
c906108c
SS
2555@item info threads
2556Display a summary of all threads currently in your
2557program. @value{GDBN} displays for each thread (in this order):
2558
2559@enumerate
2560@item the thread number assigned by @value{GDBN}
2561
2562@item the target system's thread identifier (@var{systag})
2563
2564@item the current stack frame summary for that thread
2565@end enumerate
2566
2567@noindent
2568An asterisk @samp{*} to the left of the @value{GDBN} thread number
2569indicates the current thread.
2570
5d161b24 2571For example,
c906108c
SS
2572@end table
2573@c end table here to get a little more width for example
2574
474c8240 2575@smallexample
c906108c 2576(@value{GDBP}) info threads
6d2ebf8b
SS
2577 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2578 at quicksort.c:137
2579 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2580 from /usr/lib/libc.2
2581 1 system thread 27905 0x7b003498 in _brk () \@*
2582 from /usr/lib/libc.2
474c8240 2583@end smallexample
c906108c 2584
c45da7e6
EZ
2585On Solaris, you can display more information about user threads with a
2586Solaris-specific command:
2587
2588@table @code
2589@item maint info sol-threads
2590@kindex maint info sol-threads
2591@cindex thread info (Solaris)
2592Display info on Solaris user threads.
2593@end table
2594
c906108c
SS
2595@table @code
2596@kindex thread @var{threadno}
2597@item thread @var{threadno}
2598Make thread number @var{threadno} the current thread. The command
2599argument @var{threadno} is the internal @value{GDBN} thread number, as
2600shown in the first field of the @samp{info threads} display.
2601@value{GDBN} responds by displaying the system identifier of the thread
2602you selected, and its current stack frame summary:
2603
2604@smallexample
2605@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2606(@value{GDBP}) thread 2
c906108c 2607[Switching to process 35 thread 23]
c906108c
SS
26080x34e5 in sigpause ()
2609@end smallexample
2610
2611@noindent
2612As with the @samp{[New @dots{}]} message, the form of the text after
2613@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2614threads.
c906108c 2615
9c16f35a 2616@kindex thread apply
638ac427 2617@cindex apply command to several threads
839c27b7
EZ
2618@item thread apply [@var{threadno}] [@var{all}] @var{command}
2619The @code{thread apply} command allows you to apply the named
2620@var{command} to one or more threads. Specify the numbers of the
2621threads that you want affected with the command argument
2622@var{threadno}. It can be a single thread number, one of the numbers
2623shown in the first field of the @samp{info threads} display; or it
2624could be a range of thread numbers, as in @code{2-4}. To apply a
2625command to all threads, type @kbd{thread apply all @var{command}}.
93815fbf
VP
2626
2627@kindex set print thread-events
2628@cindex print messages on thread start and exit
2629@item set print thread-events
2630@itemx set print thread-events on
2631@itemx set print thread-events off
2632The @code{set print thread-events} command allows you to enable or
2633disable printing of messages when @value{GDBN} notices that new threads have
2634started or that threads have exited. By default, these messages will
2635be printed if detection of these events is supported by the target.
2636Note that these messages cannot be disabled on all targets.
2637
2638@kindex show print thread-events
2639@item show print thread-events
2640Show whether messages will be printed when @value{GDBN} detects that threads
2641have started and exited.
c906108c
SS
2642@end table
2643
79a6e687 2644@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
2645more information about how @value{GDBN} behaves when you stop and start
2646programs with multiple threads.
2647
79a6e687 2648@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 2649watchpoints in programs with multiple threads.
c906108c 2650
6d2ebf8b 2651@node Processes
79a6e687 2652@section Debugging Programs with Multiple Processes
c906108c
SS
2653
2654@cindex fork, debugging programs which call
2655@cindex multiple processes
2656@cindex processes, multiple
53a5351d
JM
2657On most systems, @value{GDBN} has no special support for debugging
2658programs which create additional processes using the @code{fork}
2659function. When a program forks, @value{GDBN} will continue to debug the
2660parent process and the child process will run unimpeded. If you have
2661set a breakpoint in any code which the child then executes, the child
2662will get a @code{SIGTRAP} signal which (unless it catches the signal)
2663will cause it to terminate.
c906108c
SS
2664
2665However, if you want to debug the child process there is a workaround
2666which isn't too painful. Put a call to @code{sleep} in the code which
2667the child process executes after the fork. It may be useful to sleep
2668only if a certain environment variable is set, or a certain file exists,
2669so that the delay need not occur when you don't want to run @value{GDBN}
2670on the child. While the child is sleeping, use the @code{ps} program to
2671get its process ID. Then tell @value{GDBN} (a new invocation of
2672@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2673the child process (@pxref{Attach}). From that point on you can debug
c906108c 2674the child process just like any other process which you attached to.
c906108c 2675
b51970ac
DJ
2676On some systems, @value{GDBN} provides support for debugging programs that
2677create additional processes using the @code{fork} or @code{vfork} functions.
2678Currently, the only platforms with this feature are HP-UX (11.x and later
a6b151f1 2679only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
c906108c
SS
2680
2681By default, when a program forks, @value{GDBN} will continue to debug
2682the parent process and the child process will run unimpeded.
2683
2684If you want to follow the child process instead of the parent process,
2685use the command @w{@code{set follow-fork-mode}}.
2686
2687@table @code
2688@kindex set follow-fork-mode
2689@item set follow-fork-mode @var{mode}
2690Set the debugger response to a program call of @code{fork} or
2691@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2692process. The @var{mode} argument can be:
c906108c
SS
2693
2694@table @code
2695@item parent
2696The original process is debugged after a fork. The child process runs
2df3850c 2697unimpeded. This is the default.
c906108c
SS
2698
2699@item child
2700The new process is debugged after a fork. The parent process runs
2701unimpeded.
2702
c906108c
SS
2703@end table
2704
9c16f35a 2705@kindex show follow-fork-mode
c906108c 2706@item show follow-fork-mode
2df3850c 2707Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2708@end table
2709
5c95884b
MS
2710@cindex debugging multiple processes
2711On Linux, if you want to debug both the parent and child processes, use the
2712command @w{@code{set detach-on-fork}}.
2713
2714@table @code
2715@kindex set detach-on-fork
2716@item set detach-on-fork @var{mode}
2717Tells gdb whether to detach one of the processes after a fork, or
2718retain debugger control over them both.
2719
2720@table @code
2721@item on
2722The child process (or parent process, depending on the value of
2723@code{follow-fork-mode}) will be detached and allowed to run
2724independently. This is the default.
2725
2726@item off
2727Both processes will be held under the control of @value{GDBN}.
2728One process (child or parent, depending on the value of
2729@code{follow-fork-mode}) is debugged as usual, while the other
2730is held suspended.
2731
2732@end table
2733
11310833
NR
2734@kindex show detach-on-fork
2735@item show detach-on-fork
2736Show whether detach-on-fork mode is on/off.
5c95884b
MS
2737@end table
2738
11310833 2739If you choose to set @samp{detach-on-fork} mode off, then
5c95884b
MS
2740@value{GDBN} will retain control of all forked processes (including
2741nested forks). You can list the forked processes under the control of
2742@value{GDBN} by using the @w{@code{info forks}} command, and switch
2743from one fork to another by using the @w{@code{fork}} command.
2744
2745@table @code
2746@kindex info forks
2747@item info forks
2748Print a list of all forked processes under the control of @value{GDBN}.
2749The listing will include a fork id, a process id, and the current
2750position (program counter) of the process.
2751
5c95884b
MS
2752@kindex fork @var{fork-id}
2753@item fork @var{fork-id}
2754Make fork number @var{fork-id} the current process. The argument
2755@var{fork-id} is the internal fork number assigned by @value{GDBN},
2756as shown in the first field of the @samp{info forks} display.
2757
11310833
NR
2758@kindex process @var{process-id}
2759@item process @var{process-id}
2760Make process number @var{process-id} the current process. The
2761argument @var{process-id} must be one that is listed in the output of
2762@samp{info forks}.
2763
5c95884b
MS
2764@end table
2765
2766To quit debugging one of the forked processes, you can either detach
f73adfeb 2767from it by using the @w{@code{detach fork}} command (allowing it to
5c95884b 2768run independently), or delete (and kill) it using the
b8db102d 2769@w{@code{delete fork}} command.
5c95884b
MS
2770
2771@table @code
f73adfeb
AS
2772@kindex detach fork @var{fork-id}
2773@item detach fork @var{fork-id}
5c95884b
MS
2774Detach from the process identified by @value{GDBN} fork number
2775@var{fork-id}, and remove it from the fork list. The process will be
2776allowed to run independently.
2777
b8db102d
MS
2778@kindex delete fork @var{fork-id}
2779@item delete fork @var{fork-id}
5c95884b
MS
2780Kill the process identified by @value{GDBN} fork number @var{fork-id},
2781and remove it from the fork list.
2782
2783@end table
2784
c906108c
SS
2785If you ask to debug a child process and a @code{vfork} is followed by an
2786@code{exec}, @value{GDBN} executes the new target up to the first
2787breakpoint in the new target. If you have a breakpoint set on
2788@code{main} in your original program, the breakpoint will also be set on
2789the child process's @code{main}.
2790
2791When a child process is spawned by @code{vfork}, you cannot debug the
2792child or parent until an @code{exec} call completes.
2793
2794If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2795call executes, the new target restarts. To restart the parent process,
2796use the @code{file} command with the parent executable name as its
2797argument.
2798
2799You can use the @code{catch} command to make @value{GDBN} stop whenever
2800a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 2801Catchpoints, ,Setting Catchpoints}.
c906108c 2802
5c95884b 2803@node Checkpoint/Restart
79a6e687 2804@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
2805
2806@cindex checkpoint
2807@cindex restart
2808@cindex bookmark
2809@cindex snapshot of a process
2810@cindex rewind program state
2811
2812On certain operating systems@footnote{Currently, only
2813@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2814program's state, called a @dfn{checkpoint}, and come back to it
2815later.
2816
2817Returning to a checkpoint effectively undoes everything that has
2818happened in the program since the @code{checkpoint} was saved. This
2819includes changes in memory, registers, and even (within some limits)
2820system state. Effectively, it is like going back in time to the
2821moment when the checkpoint was saved.
2822
2823Thus, if you're stepping thru a program and you think you're
2824getting close to the point where things go wrong, you can save
2825a checkpoint. Then, if you accidentally go too far and miss
2826the critical statement, instead of having to restart your program
2827from the beginning, you can just go back to the checkpoint and
2828start again from there.
2829
2830This can be especially useful if it takes a lot of time or
2831steps to reach the point where you think the bug occurs.
2832
2833To use the @code{checkpoint}/@code{restart} method of debugging:
2834
2835@table @code
2836@kindex checkpoint
2837@item checkpoint
2838Save a snapshot of the debugged program's current execution state.
2839The @code{checkpoint} command takes no arguments, but each checkpoint
2840is assigned a small integer id, similar to a breakpoint id.
2841
2842@kindex info checkpoints
2843@item info checkpoints
2844List the checkpoints that have been saved in the current debugging
2845session. For each checkpoint, the following information will be
2846listed:
2847
2848@table @code
2849@item Checkpoint ID
2850@item Process ID
2851@item Code Address
2852@item Source line, or label
2853@end table
2854
2855@kindex restart @var{checkpoint-id}
2856@item restart @var{checkpoint-id}
2857Restore the program state that was saved as checkpoint number
2858@var{checkpoint-id}. All program variables, registers, stack frames
2859etc.@: will be returned to the values that they had when the checkpoint
2860was saved. In essence, gdb will ``wind back the clock'' to the point
2861in time when the checkpoint was saved.
2862
2863Note that breakpoints, @value{GDBN} variables, command history etc.
2864are not affected by restoring a checkpoint. In general, a checkpoint
2865only restores things that reside in the program being debugged, not in
2866the debugger.
2867
b8db102d
MS
2868@kindex delete checkpoint @var{checkpoint-id}
2869@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
2870Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2871
2872@end table
2873
2874Returning to a previously saved checkpoint will restore the user state
2875of the program being debugged, plus a significant subset of the system
2876(OS) state, including file pointers. It won't ``un-write'' data from
2877a file, but it will rewind the file pointer to the previous location,
2878so that the previously written data can be overwritten. For files
2879opened in read mode, the pointer will also be restored so that the
2880previously read data can be read again.
2881
2882Of course, characters that have been sent to a printer (or other
2883external device) cannot be ``snatched back'', and characters received
2884from eg.@: a serial device can be removed from internal program buffers,
2885but they cannot be ``pushed back'' into the serial pipeline, ready to
2886be received again. Similarly, the actual contents of files that have
2887been changed cannot be restored (at this time).
2888
2889However, within those constraints, you actually can ``rewind'' your
2890program to a previously saved point in time, and begin debugging it
2891again --- and you can change the course of events so as to debug a
2892different execution path this time.
2893
2894@cindex checkpoints and process id
2895Finally, there is one bit of internal program state that will be
2896different when you return to a checkpoint --- the program's process
2897id. Each checkpoint will have a unique process id (or @var{pid}),
2898and each will be different from the program's original @var{pid}.
2899If your program has saved a local copy of its process id, this could
2900potentially pose a problem.
2901
79a6e687 2902@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
2903
2904On some systems such as @sc{gnu}/Linux, address space randomization
2905is performed on new processes for security reasons. This makes it
2906difficult or impossible to set a breakpoint, or watchpoint, on an
2907absolute address if you have to restart the program, since the
2908absolute location of a symbol will change from one execution to the
2909next.
2910
2911A checkpoint, however, is an @emph{identical} copy of a process.
2912Therefore if you create a checkpoint at (eg.@:) the start of main,
2913and simply return to that checkpoint instead of restarting the
2914process, you can avoid the effects of address randomization and
2915your symbols will all stay in the same place.
2916
6d2ebf8b 2917@node Stopping
c906108c
SS
2918@chapter Stopping and Continuing
2919
2920The principal purposes of using a debugger are so that you can stop your
2921program before it terminates; or so that, if your program runs into
2922trouble, you can investigate and find out why.
2923
7a292a7a
SS
2924Inside @value{GDBN}, your program may stop for any of several reasons,
2925such as a signal, a breakpoint, or reaching a new line after a
2926@value{GDBN} command such as @code{step}. You may then examine and
2927change variables, set new breakpoints or remove old ones, and then
2928continue execution. Usually, the messages shown by @value{GDBN} provide
2929ample explanation of the status of your program---but you can also
2930explicitly request this information at any time.
c906108c
SS
2931
2932@table @code
2933@kindex info program
2934@item info program
2935Display information about the status of your program: whether it is
7a292a7a 2936running or not, what process it is, and why it stopped.
c906108c
SS
2937@end table
2938
2939@menu
2940* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2941* Continuing and Stepping:: Resuming execution
c906108c 2942* Signals:: Signals
c906108c 2943* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2944@end menu
2945
6d2ebf8b 2946@node Breakpoints
79a6e687 2947@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
2948
2949@cindex breakpoints
2950A @dfn{breakpoint} makes your program stop whenever a certain point in
2951the program is reached. For each breakpoint, you can add conditions to
2952control in finer detail whether your program stops. You can set
2953breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 2954Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
2955should stop by line number, function name or exact address in the
2956program.
2957
09d4efe1
EZ
2958On some systems, you can set breakpoints in shared libraries before
2959the executable is run. There is a minor limitation on HP-UX systems:
2960you must wait until the executable is run in order to set breakpoints
2961in shared library routines that are not called directly by the program
2962(for example, routines that are arguments in a @code{pthread_create}
2963call).
c906108c
SS
2964
2965@cindex watchpoints
fd60e0df 2966@cindex data breakpoints
c906108c
SS
2967@cindex memory tracing
2968@cindex breakpoint on memory address
2969@cindex breakpoint on variable modification
2970A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 2971when the value of an expression changes. The expression may be a value
0ced0c34 2972of a variable, or it could involve values of one or more variables
fd60e0df
EZ
2973combined by operators, such as @samp{a + b}. This is sometimes called
2974@dfn{data breakpoints}. You must use a different command to set
79a6e687 2975watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
2976from that, you can manage a watchpoint like any other breakpoint: you
2977enable, disable, and delete both breakpoints and watchpoints using the
2978same commands.
c906108c
SS
2979
2980You can arrange to have values from your program displayed automatically
2981whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 2982Automatic Display}.
c906108c
SS
2983
2984@cindex catchpoints
2985@cindex breakpoint on events
2986A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2987when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2988exception or the loading of a library. As with watchpoints, you use a
2989different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 2990Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 2991other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2992@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2993
2994@cindex breakpoint numbers
2995@cindex numbers for breakpoints
2996@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2997catchpoint when you create it; these numbers are successive integers
2998starting with one. In many of the commands for controlling various
2999features of breakpoints you use the breakpoint number to say which
3000breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3001@dfn{disabled}; if disabled, it has no effect on your program until you
3002enable it again.
3003
c5394b80
JM
3004@cindex breakpoint ranges
3005@cindex ranges of breakpoints
3006Some @value{GDBN} commands accept a range of breakpoints on which to
3007operate. A breakpoint range is either a single breakpoint number, like
3008@samp{5}, or two such numbers, in increasing order, separated by a
3009hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 3010all breakpoints in that range are operated on.
c5394b80 3011
c906108c
SS
3012@menu
3013* Set Breaks:: Setting breakpoints
3014* Set Watchpoints:: Setting watchpoints
3015* Set Catchpoints:: Setting catchpoints
3016* Delete Breaks:: Deleting breakpoints
3017* Disabling:: Disabling breakpoints
3018* Conditions:: Break conditions
3019* Break Commands:: Breakpoint command lists
d4f3574e 3020* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3021* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3022@end menu
3023
6d2ebf8b 3024@node Set Breaks
79a6e687 3025@subsection Setting Breakpoints
c906108c 3026
5d161b24 3027@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3028@c consider in particular declaration with/without initialization.
3029@c
3030@c FIXME 2 is there stuff on this already? break at fun start, already init?
3031
3032@kindex break
41afff9a
EZ
3033@kindex b @r{(@code{break})}
3034@vindex $bpnum@r{, convenience variable}
c906108c
SS
3035@cindex latest breakpoint
3036Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3037@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3038number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3039Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3040convenience variables.
3041
c906108c 3042@table @code
2a25a5ba
EZ
3043@item break @var{location}
3044Set a breakpoint at the given @var{location}, which can specify a
3045function name, a line number, or an address of an instruction.
3046(@xref{Specify Location}, for a list of all the possible ways to
3047specify a @var{location}.) The breakpoint will stop your program just
3048before it executes any of the code in the specified @var{location}.
3049
c906108c 3050When using source languages that permit overloading of symbols, such as
2a25a5ba 3051C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3052@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3053that situation.
c906108c 3054
c906108c
SS
3055@item break
3056When called without any arguments, @code{break} sets a breakpoint at
3057the next instruction to be executed in the selected stack frame
3058(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3059innermost, this makes your program stop as soon as control
3060returns to that frame. This is similar to the effect of a
3061@code{finish} command in the frame inside the selected frame---except
3062that @code{finish} does not leave an active breakpoint. If you use
3063@code{break} without an argument in the innermost frame, @value{GDBN} stops
3064the next time it reaches the current location; this may be useful
3065inside loops.
3066
3067@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3068least one instruction has been executed. If it did not do this, you
3069would be unable to proceed past a breakpoint without first disabling the
3070breakpoint. This rule applies whether or not the breakpoint already
3071existed when your program stopped.
3072
3073@item break @dots{} if @var{cond}
3074Set a breakpoint with condition @var{cond}; evaluate the expression
3075@var{cond} each time the breakpoint is reached, and stop only if the
3076value is nonzero---that is, if @var{cond} evaluates as true.
3077@samp{@dots{}} stands for one of the possible arguments described
3078above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3079,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3080
3081@kindex tbreak
3082@item tbreak @var{args}
3083Set a breakpoint enabled only for one stop. @var{args} are the
3084same as for the @code{break} command, and the breakpoint is set in the same
3085way, but the breakpoint is automatically deleted after the first time your
79a6e687 3086program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3087
c906108c 3088@kindex hbreak
ba04e063 3089@cindex hardware breakpoints
c906108c 3090@item hbreak @var{args}
d4f3574e
SS
3091Set a hardware-assisted breakpoint. @var{args} are the same as for the
3092@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3093breakpoint requires hardware support and some target hardware may not
3094have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3095debugging, so you can set a breakpoint at an instruction without
3096changing the instruction. This can be used with the new trap-generation
09d4efe1 3097provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3098will generate traps when a program accesses some data or instruction
3099address that is assigned to the debug registers. However the hardware
3100breakpoint registers can take a limited number of breakpoints. For
3101example, on the DSU, only two data breakpoints can be set at a time, and
3102@value{GDBN} will reject this command if more than two are used. Delete
3103or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3104(@pxref{Disabling, ,Disabling Breakpoints}).
3105@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3106For remote targets, you can restrict the number of hardware
3107breakpoints @value{GDBN} will use, see @ref{set remote
3108hardware-breakpoint-limit}.
501eef12 3109
c906108c
SS
3110@kindex thbreak
3111@item thbreak @var{args}
3112Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3113are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3114the same way. However, like the @code{tbreak} command,
c906108c
SS
3115the breakpoint is automatically deleted after the
3116first time your program stops there. Also, like the @code{hbreak}
5d161b24 3117command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3118may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3119See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3120
3121@kindex rbreak
3122@cindex regular expression
c45da7e6
EZ
3123@cindex breakpoints in functions matching a regexp
3124@cindex set breakpoints in many functions
c906108c 3125@item rbreak @var{regex}
c906108c 3126Set breakpoints on all functions matching the regular expression
11cf8741
JM
3127@var{regex}. This command sets an unconditional breakpoint on all
3128matches, printing a list of all breakpoints it set. Once these
3129breakpoints are set, they are treated just like the breakpoints set with
3130the @code{break} command. You can delete them, disable them, or make
3131them conditional the same way as any other breakpoint.
3132
3133The syntax of the regular expression is the standard one used with tools
3134like @file{grep}. Note that this is different from the syntax used by
3135shells, so for instance @code{foo*} matches all functions that include
3136an @code{fo} followed by zero or more @code{o}s. There is an implicit
3137@code{.*} leading and trailing the regular expression you supply, so to
3138match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3139
f7dc1244 3140@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3141When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3142breakpoints on overloaded functions that are not members of any special
3143classes.
c906108c 3144
f7dc1244
EZ
3145@cindex set breakpoints on all functions
3146The @code{rbreak} command can be used to set breakpoints in
3147@strong{all} the functions in a program, like this:
3148
3149@smallexample
3150(@value{GDBP}) rbreak .
3151@end smallexample
3152
c906108c
SS
3153@kindex info breakpoints
3154@cindex @code{$_} and @code{info breakpoints}
3155@item info breakpoints @r{[}@var{n}@r{]}
3156@itemx info break @r{[}@var{n}@r{]}
3157@itemx info watchpoints @r{[}@var{n}@r{]}
3158Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734
EZ
3159not deleted. Optional argument @var{n} means print information only
3160about the specified breakpoint (or watchpoint or catchpoint). For
3161each breakpoint, following columns are printed:
c906108c
SS
3162
3163@table @emph
3164@item Breakpoint Numbers
3165@item Type
3166Breakpoint, watchpoint, or catchpoint.
3167@item Disposition
3168Whether the breakpoint is marked to be disabled or deleted when hit.
3169@item Enabled or Disabled
3170Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3171that are not enabled.
c906108c 3172@item Address
fe6fbf8b 3173Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3174pending breakpoint whose address is not yet known, this field will
3175contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3176library that has the symbol or line referred by breakpoint is loaded.
3177See below for details. A breakpoint with several locations will
3b784c4f 3178have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3179@item What
3180Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3181line number. For a pending breakpoint, the original string passed to
3182the breakpoint command will be listed as it cannot be resolved until
3183the appropriate shared library is loaded in the future.
c906108c
SS
3184@end table
3185
3186@noindent
3187If a breakpoint is conditional, @code{info break} shows the condition on
3188the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
3189are listed after that. A pending breakpoint is allowed to have a condition
3190specified for it. The condition is not parsed for validity until a shared
3191library is loaded that allows the pending breakpoint to resolve to a
3192valid location.
c906108c
SS
3193
3194@noindent
3195@code{info break} with a breakpoint
3196number @var{n} as argument lists only that breakpoint. The
3197convenience variable @code{$_} and the default examining-address for
3198the @code{x} command are set to the address of the last breakpoint
79a6e687 3199listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3200
3201@noindent
3202@code{info break} displays a count of the number of times the breakpoint
3203has been hit. This is especially useful in conjunction with the
3204@code{ignore} command. You can ignore a large number of breakpoint
3205hits, look at the breakpoint info to see how many times the breakpoint
3206was hit, and then run again, ignoring one less than that number. This
3207will get you quickly to the last hit of that breakpoint.
3208@end table
3209
3210@value{GDBN} allows you to set any number of breakpoints at the same place in
3211your program. There is nothing silly or meaningless about this. When
3212the breakpoints are conditional, this is even useful
79a6e687 3213(@pxref{Conditions, ,Break Conditions}).
c906108c 3214
2e9132cc
EZ
3215@cindex multiple locations, breakpoints
3216@cindex breakpoints, multiple locations
fcda367b 3217It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3218in your program. Examples of this situation are:
3219
3220@itemize @bullet
fe6fbf8b
VP
3221@item
3222For a C@t{++} constructor, the @value{NGCC} compiler generates several
3223instances of the function body, used in different cases.
3224
3225@item
3226For a C@t{++} template function, a given line in the function can
3227correspond to any number of instantiations.
3228
3229@item
3230For an inlined function, a given source line can correspond to
3231several places where that function is inlined.
fe6fbf8b
VP
3232@end itemize
3233
3234In all those cases, @value{GDBN} will insert a breakpoint at all
2e9132cc
EZ
3235the relevant locations@footnote{
3236As of this writing, multiple-location breakpoints work only if there's
3237line number information for all the locations. This means that they
3238will generally not work in system libraries, unless you have debug
3239info with line numbers for them.}.
fe6fbf8b 3240
3b784c4f
EZ
3241A breakpoint with multiple locations is displayed in the breakpoint
3242table using several rows---one header row, followed by one row for
3243each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3244address column. The rows for individual locations contain the actual
3245addresses for locations, and show the functions to which those
3246locations belong. The number column for a location is of the form
fe6fbf8b
VP
3247@var{breakpoint-number}.@var{location-number}.
3248
3249For example:
3b784c4f 3250
fe6fbf8b
VP
3251@smallexample
3252Num Type Disp Enb Address What
32531 breakpoint keep y <MULTIPLE>
3254 stop only if i==1
3255 breakpoint already hit 1 time
32561.1 y 0x080486a2 in void foo<int>() at t.cc:8
32571.2 y 0x080486ca in void foo<double>() at t.cc:8
3258@end smallexample
3259
3260Each location can be individually enabled or disabled by passing
3261@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3262@code{enable} and @code{disable} commands. Note that you cannot
3263delete the individual locations from the list, you can only delete the
16bfc218 3264entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3265the @kbd{delete @var{num}} command, where @var{num} is the number of
3266the parent breakpoint, 1 in the above example). Disabling or enabling
3267the parent breakpoint (@pxref{Disabling}) affects all of the locations
3268that belong to that breakpoint.
fe6fbf8b 3269
2650777c 3270@cindex pending breakpoints
fe6fbf8b 3271It's quite common to have a breakpoint inside a shared library.
3b784c4f 3272Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3273and possibly repeatedly, as the program is executed. To support
3274this use case, @value{GDBN} updates breakpoint locations whenever
3275any shared library is loaded or unloaded. Typically, you would
fcda367b 3276set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3277debugging session, when the library is not loaded, and when the
3278symbols from the library are not available. When you try to set
3279breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3280a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3281is not yet resolved.
3282
3283After the program is run, whenever a new shared library is loaded,
3284@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3285shared library contains the symbol or line referred to by some
3286pending breakpoint, that breakpoint is resolved and becomes an
3287ordinary breakpoint. When a library is unloaded, all breakpoints
3288that refer to its symbols or source lines become pending again.
3289
3290This logic works for breakpoints with multiple locations, too. For
3291example, if you have a breakpoint in a C@t{++} template function, and
3292a newly loaded shared library has an instantiation of that template,
3293a new location is added to the list of locations for the breakpoint.
3294
3295Except for having unresolved address, pending breakpoints do not
3296differ from regular breakpoints. You can set conditions or commands,
3297enable and disable them and perform other breakpoint operations.
3298
3299@value{GDBN} provides some additional commands for controlling what
3300happens when the @samp{break} command cannot resolve breakpoint
3301address specification to an address:
dd79a6cf
JJ
3302
3303@kindex set breakpoint pending
3304@kindex show breakpoint pending
3305@table @code
3306@item set breakpoint pending auto
3307This is the default behavior. When @value{GDBN} cannot find the breakpoint
3308location, it queries you whether a pending breakpoint should be created.
3309
3310@item set breakpoint pending on
3311This indicates that an unrecognized breakpoint location should automatically
3312result in a pending breakpoint being created.
3313
3314@item set breakpoint pending off
3315This indicates that pending breakpoints are not to be created. Any
3316unrecognized breakpoint location results in an error. This setting does
3317not affect any pending breakpoints previously created.
3318
3319@item show breakpoint pending
3320Show the current behavior setting for creating pending breakpoints.
3321@end table
2650777c 3322
fe6fbf8b
VP
3323The settings above only affect the @code{break} command and its
3324variants. Once breakpoint is set, it will be automatically updated
3325as shared libraries are loaded and unloaded.
2650777c 3326
765dc015
VP
3327@cindex automatic hardware breakpoints
3328For some targets, @value{GDBN} can automatically decide if hardware or
3329software breakpoints should be used, depending on whether the
3330breakpoint address is read-only or read-write. This applies to
3331breakpoints set with the @code{break} command as well as to internal
3332breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3333breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3334breakpoints.
3335
3336You can control this automatic behaviour with the following commands::
3337
3338@kindex set breakpoint auto-hw
3339@kindex show breakpoint auto-hw
3340@table @code
3341@item set breakpoint auto-hw on
3342This is the default behavior. When @value{GDBN} sets a breakpoint, it
3343will try to use the target memory map to decide if software or hardware
3344breakpoint must be used.
3345
3346@item set breakpoint auto-hw off
3347This indicates @value{GDBN} should not automatically select breakpoint
3348type. If the target provides a memory map, @value{GDBN} will warn when
3349trying to set software breakpoint at a read-only address.
3350@end table
3351
74960c60
VP
3352@value{GDBN} normally implements breakpoints by replacing the program code
3353at the breakpoint address with a special instruction, which, when
3354executed, given control to the debugger. By default, the program
3355code is so modified only when the program is resumed. As soon as
3356the program stops, @value{GDBN} restores the original instructions. This
3357behaviour guards against leaving breakpoints inserted in the
3358target should gdb abrubptly disconnect. However, with slow remote
3359targets, inserting and removing breakpoint can reduce the performance.
3360This behavior can be controlled with the following commands::
3361
3362@kindex set breakpoint always-inserted
3363@kindex show breakpoint always-inserted
3364@table @code
3365@item set breakpoint always-inserted off
33e5cbd6
PA
3366All breakpoints, including newly added by the user, are inserted in
3367the target only when the target is resumed. All breakpoints are
3368removed from the target when it stops.
74960c60
VP
3369
3370@item set breakpoint always-inserted on
3371Causes all breakpoints to be inserted in the target at all times. If
3372the user adds a new breakpoint, or changes an existing breakpoint, the
3373breakpoints in the target are updated immediately. A breakpoint is
3374removed from the target only when breakpoint itself is removed.
33e5cbd6
PA
3375
3376@cindex non-stop mode, and @code{breakpoint always-inserted}
3377@item set breakpoint always-inserted auto
3378This is the default mode. If @value{GDBN} is controlling the inferior
3379in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3380@code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3381controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3382@code{breakpoint always-inserted} mode is off.
74960c60 3383@end table
765dc015 3384
c906108c
SS
3385@cindex negative breakpoint numbers
3386@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3387@value{GDBN} itself sometimes sets breakpoints in your program for
3388special purposes, such as proper handling of @code{longjmp} (in C
3389programs). These internal breakpoints are assigned negative numbers,
3390starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3391You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3392@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3393
3394
6d2ebf8b 3395@node Set Watchpoints
79a6e687 3396@subsection Setting Watchpoints
c906108c
SS
3397
3398@cindex setting watchpoints
c906108c
SS
3399You can use a watchpoint to stop execution whenever the value of an
3400expression changes, without having to predict a particular place where
fd60e0df
EZ
3401this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3402The expression may be as simple as the value of a single variable, or
3403as complex as many variables combined by operators. Examples include:
3404
3405@itemize @bullet
3406@item
3407A reference to the value of a single variable.
3408
3409@item
3410An address cast to an appropriate data type. For example,
3411@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3412address (assuming an @code{int} occupies 4 bytes).
3413
3414@item
3415An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3416expression can use any operators valid in the program's native
3417language (@pxref{Languages}).
3418@end itemize
c906108c 3419
fa4727a6
DJ
3420You can set a watchpoint on an expression even if the expression can
3421not be evaluated yet. For instance, you can set a watchpoint on
3422@samp{*global_ptr} before @samp{global_ptr} is initialized.
3423@value{GDBN} will stop when your program sets @samp{global_ptr} and
3424the expression produces a valid value. If the expression becomes
3425valid in some other way than changing a variable (e.g.@: if the memory
3426pointed to by @samp{*global_ptr} becomes readable as the result of a
3427@code{malloc} call), @value{GDBN} may not stop until the next time
3428the expression changes.
3429
82f2d802
EZ
3430@cindex software watchpoints
3431@cindex hardware watchpoints
c906108c 3432Depending on your system, watchpoints may be implemented in software or
2df3850c 3433hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3434program and testing the variable's value each time, which is hundreds of
3435times slower than normal execution. (But this may still be worth it, to
3436catch errors where you have no clue what part of your program is the
3437culprit.)
3438
37e4754d 3439On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
82f2d802
EZ
3440x86-based targets, @value{GDBN} includes support for hardware
3441watchpoints, which do not slow down the running of your program.
c906108c
SS
3442
3443@table @code
3444@kindex watch
d8b2a693 3445@item watch @var{expr} @r{[}thread @var{threadnum}@r{]}
fd60e0df
EZ
3446Set a watchpoint for an expression. @value{GDBN} will break when the
3447expression @var{expr} is written into by the program and its value
3448changes. The simplest (and the most popular) use of this command is
3449to watch the value of a single variable:
3450
3451@smallexample
3452(@value{GDBP}) watch foo
3453@end smallexample
c906108c 3454
d8b2a693
JB
3455If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3456clause, @value{GDBN} breaks only when the thread identified by
3457@var{threadnum} changes the value of @var{expr}. If any other threads
3458change the value of @var{expr}, @value{GDBN} will not break. Note
3459that watchpoints restricted to a single thread in this way only work
3460with Hardware Watchpoints.
3461
c906108c 3462@kindex rwatch
d8b2a693 3463@item rwatch @var{expr} @r{[}thread @var{threadnum}@r{]}
09d4efe1
EZ
3464Set a watchpoint that will break when the value of @var{expr} is read
3465by the program.
c906108c
SS
3466
3467@kindex awatch
d8b2a693 3468@item awatch @var{expr} @r{[}thread @var{threadnum}@r{]}
09d4efe1
EZ
3469Set a watchpoint that will break when @var{expr} is either read from
3470or written into by the program.
c906108c 3471
45ac1734 3472@kindex info watchpoints @r{[}@var{n}@r{]}
c906108c
SS
3473@item info watchpoints
3474This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 3475it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
3476@end table
3477
3478@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3479watchpoints execute very quickly, and the debugger reports a change in
3480value at the exact instruction where the change occurs. If @value{GDBN}
3481cannot set a hardware watchpoint, it sets a software watchpoint, which
3482executes more slowly and reports the change in value at the next
82f2d802
EZ
3483@emph{statement}, not the instruction, after the change occurs.
3484
82f2d802
EZ
3485@cindex use only software watchpoints
3486You can force @value{GDBN} to use only software watchpoints with the
3487@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3488zero, @value{GDBN} will never try to use hardware watchpoints, even if
3489the underlying system supports them. (Note that hardware-assisted
3490watchpoints that were set @emph{before} setting
3491@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 3492mechanism of watching expression values.)
c906108c 3493
9c16f35a
EZ
3494@table @code
3495@item set can-use-hw-watchpoints
3496@kindex set can-use-hw-watchpoints
3497Set whether or not to use hardware watchpoints.
3498
3499@item show can-use-hw-watchpoints
3500@kindex show can-use-hw-watchpoints
3501Show the current mode of using hardware watchpoints.
3502@end table
3503
3504For remote targets, you can restrict the number of hardware
3505watchpoints @value{GDBN} will use, see @ref{set remote
3506hardware-breakpoint-limit}.
3507
c906108c
SS
3508When you issue the @code{watch} command, @value{GDBN} reports
3509
474c8240 3510@smallexample
c906108c 3511Hardware watchpoint @var{num}: @var{expr}
474c8240 3512@end smallexample
c906108c
SS
3513
3514@noindent
3515if it was able to set a hardware watchpoint.
3516
7be570e7
JM
3517Currently, the @code{awatch} and @code{rwatch} commands can only set
3518hardware watchpoints, because accesses to data that don't change the
3519value of the watched expression cannot be detected without examining
3520every instruction as it is being executed, and @value{GDBN} does not do
3521that currently. If @value{GDBN} finds that it is unable to set a
3522hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3523will print a message like this:
3524
3525@smallexample
3526Expression cannot be implemented with read/access watchpoint.
3527@end smallexample
3528
3529Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3530data type of the watched expression is wider than what a hardware
3531watchpoint on the target machine can handle. For example, some systems
3532can only watch regions that are up to 4 bytes wide; on such systems you
3533cannot set hardware watchpoints for an expression that yields a
3534double-precision floating-point number (which is typically 8 bytes
3535wide). As a work-around, it might be possible to break the large region
3536into a series of smaller ones and watch them with separate watchpoints.
3537
3538If you set too many hardware watchpoints, @value{GDBN} might be unable
3539to insert all of them when you resume the execution of your program.
3540Since the precise number of active watchpoints is unknown until such
3541time as the program is about to be resumed, @value{GDBN} might not be
3542able to warn you about this when you set the watchpoints, and the
3543warning will be printed only when the program is resumed:
3544
3545@smallexample
3546Hardware watchpoint @var{num}: Could not insert watchpoint
3547@end smallexample
3548
3549@noindent
3550If this happens, delete or disable some of the watchpoints.
3551
fd60e0df
EZ
3552Watching complex expressions that reference many variables can also
3553exhaust the resources available for hardware-assisted watchpoints.
3554That's because @value{GDBN} needs to watch every variable in the
3555expression with separately allocated resources.
3556
c906108c 3557If you call a function interactively using @code{print} or @code{call},
2df3850c 3558any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3559kind of breakpoint or the call completes.
3560
7be570e7
JM
3561@value{GDBN} automatically deletes watchpoints that watch local
3562(automatic) variables, or expressions that involve such variables, when
3563they go out of scope, that is, when the execution leaves the block in
3564which these variables were defined. In particular, when the program
3565being debugged terminates, @emph{all} local variables go out of scope,
3566and so only watchpoints that watch global variables remain set. If you
3567rerun the program, you will need to set all such watchpoints again. One
3568way of doing that would be to set a code breakpoint at the entry to the
3569@code{main} function and when it breaks, set all the watchpoints.
3570
c906108c
SS
3571@cindex watchpoints and threads
3572@cindex threads and watchpoints
d983da9c
DJ
3573In multi-threaded programs, watchpoints will detect changes to the
3574watched expression from every thread.
3575
3576@quotation
3577@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
3578have only limited usefulness. If @value{GDBN} creates a software
3579watchpoint, it can only watch the value of an expression @emph{in a
3580single thread}. If you are confident that the expression can only
3581change due to the current thread's activity (and if you are also
3582confident that no other thread can become current), then you can use
3583software watchpoints as usual. However, @value{GDBN} may not notice
3584when a non-current thread's activity changes the expression. (Hardware
3585watchpoints, in contrast, watch an expression in all threads.)
c906108c 3586@end quotation
c906108c 3587
501eef12
AC
3588@xref{set remote hardware-watchpoint-limit}.
3589
6d2ebf8b 3590@node Set Catchpoints
79a6e687 3591@subsection Setting Catchpoints
d4f3574e 3592@cindex catchpoints, setting
c906108c
SS
3593@cindex exception handlers
3594@cindex event handling
3595
3596You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3597kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3598shared library. Use the @code{catch} command to set a catchpoint.
3599
3600@table @code
3601@kindex catch
3602@item catch @var{event}
3603Stop when @var{event} occurs. @var{event} can be any of the following:
3604@table @code
3605@item throw
4644b6e3 3606@cindex stop on C@t{++} exceptions
b37052ae 3607The throwing of a C@t{++} exception.
c906108c
SS
3608
3609@item catch
b37052ae 3610The catching of a C@t{++} exception.
c906108c 3611
8936fcda
JB
3612@item exception
3613@cindex Ada exception catching
3614@cindex catch Ada exceptions
3615An Ada exception being raised. If an exception name is specified
3616at the end of the command (eg @code{catch exception Program_Error}),
3617the debugger will stop only when this specific exception is raised.
3618Otherwise, the debugger stops execution when any Ada exception is raised.
3619
87f67dba
JB
3620When inserting an exception catchpoint on a user-defined exception whose
3621name is identical to one of the exceptions defined by the language, the
3622fully qualified name must be used as the exception name. Otherwise,
3623@value{GDBN} will assume that it should stop on the pre-defined exception
3624rather than the user-defined one. For instance, assuming an exception
3625called @code{Constraint_Error} is defined in package @code{Pck}, then
3626the command to use to catch such exceptions is @kbd{catch exception
3627Pck.Constraint_Error}.
3628
8936fcda
JB
3629@item exception unhandled
3630An exception that was raised but is not handled by the program.
3631
3632@item assert
3633A failed Ada assertion.
3634
c906108c 3635@item exec
4644b6e3 3636@cindex break on fork/exec
5ee187d7
DJ
3637A call to @code{exec}. This is currently only available for HP-UX
3638and @sc{gnu}/Linux.
c906108c
SS
3639
3640@item fork
5ee187d7
DJ
3641A call to @code{fork}. This is currently only available for HP-UX
3642and @sc{gnu}/Linux.
c906108c
SS
3643
3644@item vfork
5ee187d7
DJ
3645A call to @code{vfork}. This is currently only available for HP-UX
3646and @sc{gnu}/Linux.
c906108c 3647
c906108c
SS
3648@end table
3649
3650@item tcatch @var{event}
3651Set a catchpoint that is enabled only for one stop. The catchpoint is
3652automatically deleted after the first time the event is caught.
3653
3654@end table
3655
3656Use the @code{info break} command to list the current catchpoints.
3657
b37052ae 3658There are currently some limitations to C@t{++} exception handling
c906108c
SS
3659(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3660
3661@itemize @bullet
3662@item
3663If you call a function interactively, @value{GDBN} normally returns
3664control to you when the function has finished executing. If the call
3665raises an exception, however, the call may bypass the mechanism that
3666returns control to you and cause your program either to abort or to
3667simply continue running until it hits a breakpoint, catches a signal
3668that @value{GDBN} is listening for, or exits. This is the case even if
3669you set a catchpoint for the exception; catchpoints on exceptions are
3670disabled within interactive calls.
3671
3672@item
3673You cannot raise an exception interactively.
3674
3675@item
3676You cannot install an exception handler interactively.
3677@end itemize
3678
3679@cindex raise exceptions
3680Sometimes @code{catch} is not the best way to debug exception handling:
3681if you need to know exactly where an exception is raised, it is better to
3682stop @emph{before} the exception handler is called, since that way you
3683can see the stack before any unwinding takes place. If you set a
3684breakpoint in an exception handler instead, it may not be easy to find
3685out where the exception was raised.
3686
3687To stop just before an exception handler is called, you need some
b37052ae 3688knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3689raised by calling a library function named @code{__raise_exception}
3690which has the following ANSI C interface:
3691
474c8240 3692@smallexample
c906108c 3693 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3694 @var{id} is the exception identifier. */
3695 void __raise_exception (void **addr, void *id);
474c8240 3696@end smallexample
c906108c
SS
3697
3698@noindent
3699To make the debugger catch all exceptions before any stack
3700unwinding takes place, set a breakpoint on @code{__raise_exception}
79a6e687 3701(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
c906108c 3702
79a6e687 3703With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
c906108c
SS
3704that depends on the value of @var{id}, you can stop your program when
3705a specific exception is raised. You can use multiple conditional
3706breakpoints to stop your program when any of a number of exceptions are
3707raised.
3708
3709
6d2ebf8b 3710@node Delete Breaks
79a6e687 3711@subsection Deleting Breakpoints
c906108c
SS
3712
3713@cindex clearing breakpoints, watchpoints, catchpoints
3714@cindex deleting breakpoints, watchpoints, catchpoints
3715It is often necessary to eliminate a breakpoint, watchpoint, or
3716catchpoint once it has done its job and you no longer want your program
3717to stop there. This is called @dfn{deleting} the breakpoint. A
3718breakpoint that has been deleted no longer exists; it is forgotten.
3719
3720With the @code{clear} command you can delete breakpoints according to
3721where they are in your program. With the @code{delete} command you can
3722delete individual breakpoints, watchpoints, or catchpoints by specifying
3723their breakpoint numbers.
3724
3725It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3726automatically ignores breakpoints on the first instruction to be executed
3727when you continue execution without changing the execution address.
3728
3729@table @code
3730@kindex clear
3731@item clear
3732Delete any breakpoints at the next instruction to be executed in the
79a6e687 3733selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
3734the innermost frame is selected, this is a good way to delete a
3735breakpoint where your program just stopped.
3736
2a25a5ba
EZ
3737@item clear @var{location}
3738Delete any breakpoints set at the specified @var{location}.
3739@xref{Specify Location}, for the various forms of @var{location}; the
3740most useful ones are listed below:
3741
3742@table @code
c906108c
SS
3743@item clear @var{function}
3744@itemx clear @var{filename}:@var{function}
09d4efe1 3745Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3746
3747@item clear @var{linenum}
3748@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3749Delete any breakpoints set at or within the code of the specified
3750@var{linenum} of the specified @var{filename}.
2a25a5ba 3751@end table
c906108c
SS
3752
3753@cindex delete breakpoints
3754@kindex delete
41afff9a 3755@kindex d @r{(@code{delete})}
c5394b80
JM
3756@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3757Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3758ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3759breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3760confirm off}). You can abbreviate this command as @code{d}.
3761@end table
3762
6d2ebf8b 3763@node Disabling
79a6e687 3764@subsection Disabling Breakpoints
c906108c 3765
4644b6e3 3766@cindex enable/disable a breakpoint
c906108c
SS
3767Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3768prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3769it had been deleted, but remembers the information on the breakpoint so
3770that you can @dfn{enable} it again later.
3771
3772You disable and enable breakpoints, watchpoints, and catchpoints with
3773the @code{enable} and @code{disable} commands, optionally specifying one
3774or more breakpoint numbers as arguments. Use @code{info break} or
3775@code{info watch} to print a list of breakpoints, watchpoints, and
3776catchpoints if you do not know which numbers to use.
3777
3b784c4f
EZ
3778Disabling and enabling a breakpoint that has multiple locations
3779affects all of its locations.
3780
c906108c
SS
3781A breakpoint, watchpoint, or catchpoint can have any of four different
3782states of enablement:
3783
3784@itemize @bullet
3785@item
3786Enabled. The breakpoint stops your program. A breakpoint set
3787with the @code{break} command starts out in this state.
3788@item
3789Disabled. The breakpoint has no effect on your program.
3790@item
3791Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3792disabled.
c906108c
SS
3793@item
3794Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3795immediately after it does so it is deleted permanently. A breakpoint
3796set with the @code{tbreak} command starts out in this state.
c906108c
SS
3797@end itemize
3798
3799You can use the following commands to enable or disable breakpoints,
3800watchpoints, and catchpoints:
3801
3802@table @code
c906108c 3803@kindex disable
41afff9a 3804@kindex dis @r{(@code{disable})}
c5394b80 3805@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3806Disable the specified breakpoints---or all breakpoints, if none are
3807listed. A disabled breakpoint has no effect but is not forgotten. All
3808options such as ignore-counts, conditions and commands are remembered in
3809case the breakpoint is enabled again later. You may abbreviate
3810@code{disable} as @code{dis}.
3811
c906108c 3812@kindex enable
c5394b80 3813@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3814Enable the specified breakpoints (or all defined breakpoints). They
3815become effective once again in stopping your program.
3816
c5394b80 3817@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3818Enable the specified breakpoints temporarily. @value{GDBN} disables any
3819of these breakpoints immediately after stopping your program.
3820
c5394b80 3821@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3822Enable the specified breakpoints to work once, then die. @value{GDBN}
3823deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3824Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3825@end table
3826
d4f3574e
SS
3827@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3828@c confusing: tbreak is also initially enabled.
c906108c 3829Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 3830,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
3831subsequently, they become disabled or enabled only when you use one of
3832the commands above. (The command @code{until} can set and delete a
3833breakpoint of its own, but it does not change the state of your other
3834breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 3835Stepping}.)
c906108c 3836
6d2ebf8b 3837@node Conditions
79a6e687 3838@subsection Break Conditions
c906108c
SS
3839@cindex conditional breakpoints
3840@cindex breakpoint conditions
3841
3842@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3843@c in particular for a watchpoint?
c906108c
SS
3844The simplest sort of breakpoint breaks every time your program reaches a
3845specified place. You can also specify a @dfn{condition} for a
3846breakpoint. A condition is just a Boolean expression in your
3847programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3848a condition evaluates the expression each time your program reaches it,
3849and your program stops only if the condition is @emph{true}.
3850
3851This is the converse of using assertions for program validation; in that
3852situation, you want to stop when the assertion is violated---that is,
3853when the condition is false. In C, if you want to test an assertion expressed
3854by the condition @var{assert}, you should set the condition
3855@samp{! @var{assert}} on the appropriate breakpoint.
3856
3857Conditions are also accepted for watchpoints; you may not need them,
3858since a watchpoint is inspecting the value of an expression anyhow---but
3859it might be simpler, say, to just set a watchpoint on a variable name,
3860and specify a condition that tests whether the new value is an interesting
3861one.
3862
3863Break conditions can have side effects, and may even call functions in
3864your program. This can be useful, for example, to activate functions
3865that log program progress, or to use your own print functions to
3866format special data structures. The effects are completely predictable
3867unless there is another enabled breakpoint at the same address. (In
3868that case, @value{GDBN} might see the other breakpoint first and stop your
3869program without checking the condition of this one.) Note that
d4f3574e
SS
3870breakpoint commands are usually more convenient and flexible than break
3871conditions for the
c906108c 3872purpose of performing side effects when a breakpoint is reached
79a6e687 3873(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c
SS
3874
3875Break conditions can be specified when a breakpoint is set, by using
3876@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 3877Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 3878with the @code{condition} command.
53a5351d 3879
c906108c
SS
3880You can also use the @code{if} keyword with the @code{watch} command.
3881The @code{catch} command does not recognize the @code{if} keyword;
3882@code{condition} is the only way to impose a further condition on a
3883catchpoint.
c906108c
SS
3884
3885@table @code
3886@kindex condition
3887@item condition @var{bnum} @var{expression}
3888Specify @var{expression} as the break condition for breakpoint,
3889watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3890breakpoint @var{bnum} stops your program only if the value of
3891@var{expression} is true (nonzero, in C). When you use
3892@code{condition}, @value{GDBN} checks @var{expression} immediately for
3893syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3894referents in the context of your breakpoint. If @var{expression} uses
3895symbols not referenced in the context of the breakpoint, @value{GDBN}
3896prints an error message:
3897
474c8240 3898@smallexample
d4f3574e 3899No symbol "foo" in current context.
474c8240 3900@end smallexample
d4f3574e
SS
3901
3902@noindent
c906108c
SS
3903@value{GDBN} does
3904not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3905command (or a command that sets a breakpoint with a condition, like
3906@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3907
3908@item condition @var{bnum}
3909Remove the condition from breakpoint number @var{bnum}. It becomes
3910an ordinary unconditional breakpoint.
3911@end table
3912
3913@cindex ignore count (of breakpoint)
3914A special case of a breakpoint condition is to stop only when the
3915breakpoint has been reached a certain number of times. This is so
3916useful that there is a special way to do it, using the @dfn{ignore
3917count} of the breakpoint. Every breakpoint has an ignore count, which
3918is an integer. Most of the time, the ignore count is zero, and
3919therefore has no effect. But if your program reaches a breakpoint whose
3920ignore count is positive, then instead of stopping, it just decrements
3921the ignore count by one and continues. As a result, if the ignore count
3922value is @var{n}, the breakpoint does not stop the next @var{n} times
3923your program reaches it.
3924
3925@table @code
3926@kindex ignore
3927@item ignore @var{bnum} @var{count}
3928Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3929The next @var{count} times the breakpoint is reached, your program's
3930execution does not stop; other than to decrement the ignore count, @value{GDBN}
3931takes no action.
3932
3933To make the breakpoint stop the next time it is reached, specify
3934a count of zero.
3935
3936When you use @code{continue} to resume execution of your program from a
3937breakpoint, you can specify an ignore count directly as an argument to
3938@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 3939Stepping,,Continuing and Stepping}.
c906108c
SS
3940
3941If a breakpoint has a positive ignore count and a condition, the
3942condition is not checked. Once the ignore count reaches zero,
3943@value{GDBN} resumes checking the condition.
3944
3945You could achieve the effect of the ignore count with a condition such
3946as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3947is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 3948Variables}.
c906108c
SS
3949@end table
3950
3951Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3952
3953
6d2ebf8b 3954@node Break Commands
79a6e687 3955@subsection Breakpoint Command Lists
c906108c
SS
3956
3957@cindex breakpoint commands
3958You can give any breakpoint (or watchpoint or catchpoint) a series of
3959commands to execute when your program stops due to that breakpoint. For
3960example, you might want to print the values of certain expressions, or
3961enable other breakpoints.
3962
3963@table @code
3964@kindex commands
ca91424e 3965@kindex end@r{ (breakpoint commands)}
c906108c
SS
3966@item commands @r{[}@var{bnum}@r{]}
3967@itemx @dots{} @var{command-list} @dots{}
3968@itemx end
3969Specify a list of commands for breakpoint number @var{bnum}. The commands
3970themselves appear on the following lines. Type a line containing just
3971@code{end} to terminate the commands.
3972
3973To remove all commands from a breakpoint, type @code{commands} and
3974follow it immediately with @code{end}; that is, give no commands.
3975
3976With no @var{bnum} argument, @code{commands} refers to the last
3977breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3978recently encountered).
3979@end table
3980
3981Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3982disabled within a @var{command-list}.
3983
3984You can use breakpoint commands to start your program up again. Simply
3985use the @code{continue} command, or @code{step}, or any other command
3986that resumes execution.
3987
3988Any other commands in the command list, after a command that resumes
3989execution, are ignored. This is because any time you resume execution
3990(even with a simple @code{next} or @code{step}), you may encounter
3991another breakpoint---which could have its own command list, leading to
3992ambiguities about which list to execute.
3993
3994@kindex silent
3995If the first command you specify in a command list is @code{silent}, the
3996usual message about stopping at a breakpoint is not printed. This may
3997be desirable for breakpoints that are to print a specific message and
3998then continue. If none of the remaining commands print anything, you
3999see no sign that the breakpoint was reached. @code{silent} is
4000meaningful only at the beginning of a breakpoint command list.
4001
4002The commands @code{echo}, @code{output}, and @code{printf} allow you to
4003print precisely controlled output, and are often useful in silent
79a6e687 4004breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
4005
4006For example, here is how you could use breakpoint commands to print the
4007value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4008
474c8240 4009@smallexample
c906108c
SS
4010break foo if x>0
4011commands
4012silent
4013printf "x is %d\n",x
4014cont
4015end
474c8240 4016@end smallexample
c906108c
SS
4017
4018One application for breakpoint commands is to compensate for one bug so
4019you can test for another. Put a breakpoint just after the erroneous line
4020of code, give it a condition to detect the case in which something
4021erroneous has been done, and give it commands to assign correct values
4022to any variables that need them. End with the @code{continue} command
4023so that your program does not stop, and start with the @code{silent}
4024command so that no output is produced. Here is an example:
4025
474c8240 4026@smallexample
c906108c
SS
4027break 403
4028commands
4029silent
4030set x = y + 4
4031cont
4032end
474c8240 4033@end smallexample
c906108c 4034
c906108c 4035@c @ifclear BARETARGET
6d2ebf8b 4036@node Error in Breakpoints
d4f3574e 4037@subsection ``Cannot insert breakpoints''
c906108c
SS
4038@c
4039@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
4040@c
d4f3574e
SS
4041Under some operating systems, breakpoints cannot be used in a program if
4042any other process is running that program. In this situation,
5d161b24 4043attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
4044@value{GDBN} to print an error message:
4045
474c8240 4046@smallexample
d4f3574e
SS
4047Cannot insert breakpoints.
4048The same program may be running in another process.
474c8240 4049@end smallexample
d4f3574e
SS
4050
4051When this happens, you have three ways to proceed:
4052
4053@enumerate
4054@item
4055Remove or disable the breakpoints, then continue.
4056
4057@item
5d161b24 4058Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 4059name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 4060that @value{GDBN} should run your program under that name.
d4f3574e
SS
4061Then start your program again.
4062
4063@item
4064Relink your program so that the text segment is nonsharable, using the
4065linker option @samp{-N}. The operating system limitation may not apply
4066to nonsharable executables.
4067@end enumerate
c906108c
SS
4068@c @end ifclear
4069
d4f3574e
SS
4070A similar message can be printed if you request too many active
4071hardware-assisted breakpoints and watchpoints:
4072
4073@c FIXME: the precise wording of this message may change; the relevant
4074@c source change is not committed yet (Sep 3, 1999).
4075@smallexample
4076Stopped; cannot insert breakpoints.
4077You may have requested too many hardware breakpoints and watchpoints.
4078@end smallexample
4079
4080@noindent
4081This message is printed when you attempt to resume the program, since
4082only then @value{GDBN} knows exactly how many hardware breakpoints and
4083watchpoints it needs to insert.
4084
4085When this message is printed, you need to disable or remove some of the
4086hardware-assisted breakpoints and watchpoints, and then continue.
4087
79a6e687 4088@node Breakpoint-related Warnings
1485d690
KB
4089@subsection ``Breakpoint address adjusted...''
4090@cindex breakpoint address adjusted
4091
4092Some processor architectures place constraints on the addresses at
4093which breakpoints may be placed. For architectures thus constrained,
4094@value{GDBN} will attempt to adjust the breakpoint's address to comply
4095with the constraints dictated by the architecture.
4096
4097One example of such an architecture is the Fujitsu FR-V. The FR-V is
4098a VLIW architecture in which a number of RISC-like instructions may be
4099bundled together for parallel execution. The FR-V architecture
4100constrains the location of a breakpoint instruction within such a
4101bundle to the instruction with the lowest address. @value{GDBN}
4102honors this constraint by adjusting a breakpoint's address to the
4103first in the bundle.
4104
4105It is not uncommon for optimized code to have bundles which contain
4106instructions from different source statements, thus it may happen that
4107a breakpoint's address will be adjusted from one source statement to
4108another. Since this adjustment may significantly alter @value{GDBN}'s
4109breakpoint related behavior from what the user expects, a warning is
4110printed when the breakpoint is first set and also when the breakpoint
4111is hit.
4112
4113A warning like the one below is printed when setting a breakpoint
4114that's been subject to address adjustment:
4115
4116@smallexample
4117warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4118@end smallexample
4119
4120Such warnings are printed both for user settable and @value{GDBN}'s
4121internal breakpoints. If you see one of these warnings, you should
4122verify that a breakpoint set at the adjusted address will have the
4123desired affect. If not, the breakpoint in question may be removed and
b383017d 4124other breakpoints may be set which will have the desired behavior.
1485d690
KB
4125E.g., it may be sufficient to place the breakpoint at a later
4126instruction. A conditional breakpoint may also be useful in some
4127cases to prevent the breakpoint from triggering too often.
4128
4129@value{GDBN} will also issue a warning when stopping at one of these
4130adjusted breakpoints:
4131
4132@smallexample
4133warning: Breakpoint 1 address previously adjusted from 0x00010414
4134to 0x00010410.
4135@end smallexample
4136
4137When this warning is encountered, it may be too late to take remedial
4138action except in cases where the breakpoint is hit earlier or more
4139frequently than expected.
d4f3574e 4140
6d2ebf8b 4141@node Continuing and Stepping
79a6e687 4142@section Continuing and Stepping
c906108c
SS
4143
4144@cindex stepping
4145@cindex continuing
4146@cindex resuming execution
4147@dfn{Continuing} means resuming program execution until your program
4148completes normally. In contrast, @dfn{stepping} means executing just
4149one more ``step'' of your program, where ``step'' may mean either one
4150line of source code, or one machine instruction (depending on what
7a292a7a
SS
4151particular command you use). Either when continuing or when stepping,
4152your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
4153it stops due to a signal, you may want to use @code{handle}, or use
4154@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
4155
4156@table @code
4157@kindex continue
41afff9a
EZ
4158@kindex c @r{(@code{continue})}
4159@kindex fg @r{(resume foreground execution)}
c906108c
SS
4160@item continue @r{[}@var{ignore-count}@r{]}
4161@itemx c @r{[}@var{ignore-count}@r{]}
4162@itemx fg @r{[}@var{ignore-count}@r{]}
4163Resume program execution, at the address where your program last stopped;
4164any breakpoints set at that address are bypassed. The optional argument
4165@var{ignore-count} allows you to specify a further number of times to
4166ignore a breakpoint at this location; its effect is like that of
79a6e687 4167@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
4168
4169The argument @var{ignore-count} is meaningful only when your program
4170stopped due to a breakpoint. At other times, the argument to
4171@code{continue} is ignored.
4172
d4f3574e
SS
4173The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4174debugged program is deemed to be the foreground program) are provided
4175purely for convenience, and have exactly the same behavior as
4176@code{continue}.
c906108c
SS
4177@end table
4178
4179To resume execution at a different place, you can use @code{return}
79a6e687 4180(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 4181calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 4182Different Address}) to go to an arbitrary location in your program.
c906108c
SS
4183
4184A typical technique for using stepping is to set a breakpoint
79a6e687 4185(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
4186beginning of the function or the section of your program where a problem
4187is believed to lie, run your program until it stops at that breakpoint,
4188and then step through the suspect area, examining the variables that are
4189interesting, until you see the problem happen.
4190
4191@table @code
4192@kindex step
41afff9a 4193@kindex s @r{(@code{step})}
c906108c
SS
4194@item step
4195Continue running your program until control reaches a different source
4196line, then stop it and return control to @value{GDBN}. This command is
4197abbreviated @code{s}.
4198
4199@quotation
4200@c "without debugging information" is imprecise; actually "without line
4201@c numbers in the debugging information". (gcc -g1 has debugging info but
4202@c not line numbers). But it seems complex to try to make that
4203@c distinction here.
4204@emph{Warning:} If you use the @code{step} command while control is
4205within a function that was compiled without debugging information,
4206execution proceeds until control reaches a function that does have
4207debugging information. Likewise, it will not step into a function which
4208is compiled without debugging information. To step through functions
4209without debugging information, use the @code{stepi} command, described
4210below.
4211@end quotation
4212
4a92d011
EZ
4213The @code{step} command only stops at the first instruction of a source
4214line. This prevents the multiple stops that could otherwise occur in
4215@code{switch} statements, @code{for} loops, etc. @code{step} continues
4216to stop if a function that has debugging information is called within
4217the line. In other words, @code{step} @emph{steps inside} any functions
4218called within the line.
c906108c 4219
d4f3574e
SS
4220Also, the @code{step} command only enters a function if there is line
4221number information for the function. Otherwise it acts like the
5d161b24 4222@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 4223on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 4224was any debugging information about the routine.
c906108c
SS
4225
4226@item step @var{count}
4227Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
4228breakpoint is reached, or a signal not related to stepping occurs before
4229@var{count} steps, stepping stops right away.
c906108c
SS
4230
4231@kindex next
41afff9a 4232@kindex n @r{(@code{next})}
c906108c
SS
4233@item next @r{[}@var{count}@r{]}
4234Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
4235This is similar to @code{step}, but function calls that appear within
4236the line of code are executed without stopping. Execution stops when
4237control reaches a different line of code at the original stack level
4238that was executing when you gave the @code{next} command. This command
4239is abbreviated @code{n}.
c906108c
SS
4240
4241An argument @var{count} is a repeat count, as for @code{step}.
4242
4243
4244@c FIX ME!! Do we delete this, or is there a way it fits in with
4245@c the following paragraph? --- Vctoria
4246@c
4247@c @code{next} within a function that lacks debugging information acts like
4248@c @code{step}, but any function calls appearing within the code of the
4249@c function are executed without stopping.
4250
d4f3574e
SS
4251The @code{next} command only stops at the first instruction of a
4252source line. This prevents multiple stops that could otherwise occur in
4a92d011 4253@code{switch} statements, @code{for} loops, etc.
c906108c 4254
b90a5f51
CF
4255@kindex set step-mode
4256@item set step-mode
4257@cindex functions without line info, and stepping
4258@cindex stepping into functions with no line info
4259@itemx set step-mode on
4a92d011 4260The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
4261stop at the first instruction of a function which contains no debug line
4262information rather than stepping over it.
4263
4a92d011
EZ
4264This is useful in cases where you may be interested in inspecting the
4265machine instructions of a function which has no symbolic info and do not
4266want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
4267
4268@item set step-mode off
4a92d011 4269Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
4270debug information. This is the default.
4271
9c16f35a
EZ
4272@item show step-mode
4273Show whether @value{GDBN} will stop in or step over functions without
4274source line debug information.
4275
c906108c 4276@kindex finish
8dfa32fc 4277@kindex fin @r{(@code{finish})}
c906108c
SS
4278@item finish
4279Continue running until just after function in the selected stack frame
8dfa32fc
JB
4280returns. Print the returned value (if any). This command can be
4281abbreviated as @code{fin}.
c906108c
SS
4282
4283Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 4284,Returning from a Function}).
c906108c
SS
4285
4286@kindex until
41afff9a 4287@kindex u @r{(@code{until})}
09d4efe1 4288@cindex run until specified location
c906108c
SS
4289@item until
4290@itemx u
4291Continue running until a source line past the current line, in the
4292current stack frame, is reached. This command is used to avoid single
4293stepping through a loop more than once. It is like the @code{next}
4294command, except that when @code{until} encounters a jump, it
4295automatically continues execution until the program counter is greater
4296than the address of the jump.
4297
4298This means that when you reach the end of a loop after single stepping
4299though it, @code{until} makes your program continue execution until it
4300exits the loop. In contrast, a @code{next} command at the end of a loop
4301simply steps back to the beginning of the loop, which forces you to step
4302through the next iteration.
4303
4304@code{until} always stops your program if it attempts to exit the current
4305stack frame.
4306
4307@code{until} may produce somewhat counterintuitive results if the order
4308of machine code does not match the order of the source lines. For
4309example, in the following excerpt from a debugging session, the @code{f}
4310(@code{frame}) command shows that execution is stopped at line
4311@code{206}; yet when we use @code{until}, we get to line @code{195}:
4312
474c8240 4313@smallexample
c906108c
SS
4314(@value{GDBP}) f
4315#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4316206 expand_input();
4317(@value{GDBP}) until
4318195 for ( ; argc > 0; NEXTARG) @{
474c8240 4319@end smallexample
c906108c
SS
4320
4321This happened because, for execution efficiency, the compiler had
4322generated code for the loop closure test at the end, rather than the
4323start, of the loop---even though the test in a C @code{for}-loop is
4324written before the body of the loop. The @code{until} command appeared
4325to step back to the beginning of the loop when it advanced to this
4326expression; however, it has not really gone to an earlier
4327statement---not in terms of the actual machine code.
4328
4329@code{until} with no argument works by means of single
4330instruction stepping, and hence is slower than @code{until} with an
4331argument.
4332
4333@item until @var{location}
4334@itemx u @var{location}
4335Continue running your program until either the specified location is
4336reached, or the current stack frame returns. @var{location} is any of
2a25a5ba
EZ
4337the forms described in @ref{Specify Location}.
4338This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
4339hence is quicker than @code{until} without an argument. The specified
4340location is actually reached only if it is in the current frame. This
4341implies that @code{until} can be used to skip over recursive function
4342invocations. For instance in the code below, if the current location is
4343line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 4344line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
4345invocations have returned.
4346
4347@smallexample
434894 int factorial (int value)
434995 @{
435096 if (value > 1) @{
435197 value *= factorial (value - 1);
435298 @}
435399 return (value);
4354100 @}
4355@end smallexample
4356
4357
4358@kindex advance @var{location}
4359@itemx advance @var{location}
09d4efe1 4360Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
4361required, which should be of one of the forms described in
4362@ref{Specify Location}.
4363Execution will also stop upon exit from the current stack
c60eb6f1
EZ
4364frame. This command is similar to @code{until}, but @code{advance} will
4365not skip over recursive function calls, and the target location doesn't
4366have to be in the same frame as the current one.
4367
c906108c
SS
4368
4369@kindex stepi
41afff9a 4370@kindex si @r{(@code{stepi})}
c906108c 4371@item stepi
96a2c332 4372@itemx stepi @var{arg}
c906108c
SS
4373@itemx si
4374Execute one machine instruction, then stop and return to the debugger.
4375
4376It is often useful to do @samp{display/i $pc} when stepping by machine
4377instructions. This makes @value{GDBN} automatically display the next
4378instruction to be executed, each time your program stops. @xref{Auto
79a6e687 4379Display,, Automatic Display}.
c906108c
SS
4380
4381An argument is a repeat count, as in @code{step}.
4382
4383@need 750
4384@kindex nexti
41afff9a 4385@kindex ni @r{(@code{nexti})}
c906108c 4386@item nexti
96a2c332 4387@itemx nexti @var{arg}
c906108c
SS
4388@itemx ni
4389Execute one machine instruction, but if it is a function call,
4390proceed until the function returns.
4391
4392An argument is a repeat count, as in @code{next}.
4393@end table
4394
6d2ebf8b 4395@node Signals
c906108c
SS
4396@section Signals
4397@cindex signals
4398
4399A signal is an asynchronous event that can happen in a program. The
4400operating system defines the possible kinds of signals, and gives each
4401kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 4402signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
4403@code{SIGSEGV} is the signal a program gets from referencing a place in
4404memory far away from all the areas in use; @code{SIGALRM} occurs when
4405the alarm clock timer goes off (which happens only if your program has
4406requested an alarm).
4407
4408@cindex fatal signals
4409Some signals, including @code{SIGALRM}, are a normal part of the
4410functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 4411errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
4412program has not specified in advance some other way to handle the signal.
4413@code{SIGINT} does not indicate an error in your program, but it is normally
4414fatal so it can carry out the purpose of the interrupt: to kill the program.
4415
4416@value{GDBN} has the ability to detect any occurrence of a signal in your
4417program. You can tell @value{GDBN} in advance what to do for each kind of
4418signal.
4419
4420@cindex handling signals
24f93129
EZ
4421Normally, @value{GDBN} is set up to let the non-erroneous signals like
4422@code{SIGALRM} be silently passed to your program
4423(so as not to interfere with their role in the program's functioning)
c906108c
SS
4424but to stop your program immediately whenever an error signal happens.
4425You can change these settings with the @code{handle} command.
4426
4427@table @code
4428@kindex info signals
09d4efe1 4429@kindex info handle
c906108c 4430@item info signals
96a2c332 4431@itemx info handle
c906108c
SS
4432Print a table of all the kinds of signals and how @value{GDBN} has been told to
4433handle each one. You can use this to see the signal numbers of all
4434the defined types of signals.
4435
45ac1734
EZ
4436@item info signals @var{sig}
4437Similar, but print information only about the specified signal number.
4438
d4f3574e 4439@code{info handle} is an alias for @code{info signals}.
c906108c
SS
4440
4441@kindex handle
45ac1734 4442@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
4443Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4444can be the number of a signal or its name (with or without the
24f93129 4445@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 4446@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
4447known signals. Optional arguments @var{keywords}, described below,
4448say what change to make.
c906108c
SS
4449@end table
4450
4451@c @group
4452The keywords allowed by the @code{handle} command can be abbreviated.
4453Their full names are:
4454
4455@table @code
4456@item nostop
4457@value{GDBN} should not stop your program when this signal happens. It may
4458still print a message telling you that the signal has come in.
4459
4460@item stop
4461@value{GDBN} should stop your program when this signal happens. This implies
4462the @code{print} keyword as well.
4463
4464@item print
4465@value{GDBN} should print a message when this signal happens.
4466
4467@item noprint
4468@value{GDBN} should not mention the occurrence of the signal at all. This
4469implies the @code{nostop} keyword as well.
4470
4471@item pass
5ece1a18 4472@itemx noignore
c906108c
SS
4473@value{GDBN} should allow your program to see this signal; your program
4474can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 4475and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
4476
4477@item nopass
5ece1a18 4478@itemx ignore
c906108c 4479@value{GDBN} should not allow your program to see this signal.
5ece1a18 4480@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
4481@end table
4482@c @end group
4483
d4f3574e
SS
4484When a signal stops your program, the signal is not visible to the
4485program until you
c906108c
SS
4486continue. Your program sees the signal then, if @code{pass} is in
4487effect for the signal in question @emph{at that time}. In other words,
4488after @value{GDBN} reports a signal, you can use the @code{handle}
4489command with @code{pass} or @code{nopass} to control whether your
4490program sees that signal when you continue.
4491
24f93129
EZ
4492The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4493non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4494@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4495erroneous signals.
4496
c906108c
SS
4497You can also use the @code{signal} command to prevent your program from
4498seeing a signal, or cause it to see a signal it normally would not see,
4499or to give it any signal at any time. For example, if your program stopped
4500due to some sort of memory reference error, you might store correct
4501values into the erroneous variables and continue, hoping to see more
4502execution; but your program would probably terminate immediately as
4503a result of the fatal signal once it saw the signal. To prevent this,
4504you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 4505Program a Signal}.
c906108c 4506
6d2ebf8b 4507@node Thread Stops
79a6e687 4508@section Stopping and Starting Multi-thread Programs
c906108c 4509
0606b73b
SL
4510@cindex stopped threads
4511@cindex threads, stopped
4512
4513@cindex continuing threads
4514@cindex threads, continuing
4515
4516@value{GDBN} supports debugging programs with multiple threads
4517(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
4518are two modes of controlling execution of your program within the
4519debugger. In the default mode, referred to as @dfn{all-stop mode},
4520when any thread in your program stops (for example, at a breakpoint
4521or while being stepped), all other threads in the program are also stopped by
4522@value{GDBN}. On some targets, @value{GDBN} also supports
4523@dfn{non-stop mode}, in which other threads can continue to run freely while
4524you examine the stopped thread in the debugger.
4525
4526@menu
4527* All-Stop Mode:: All threads stop when GDB takes control
4528* Non-Stop Mode:: Other threads continue to execute
4529* Background Execution:: Running your program asynchronously
4530* Thread-Specific Breakpoints:: Controlling breakpoints
4531* Interrupted System Calls:: GDB may interfere with system calls
4532@end menu
4533
4534@node All-Stop Mode
4535@subsection All-Stop Mode
4536
4537@cindex all-stop mode
4538
4539In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
4540@emph{all} threads of execution stop, not just the current thread. This
4541allows you to examine the overall state of the program, including
4542switching between threads, without worrying that things may change
4543underfoot.
4544
4545Conversely, whenever you restart the program, @emph{all} threads start
4546executing. @emph{This is true even when single-stepping} with commands
4547like @code{step} or @code{next}.
4548
4549In particular, @value{GDBN} cannot single-step all threads in lockstep.
4550Since thread scheduling is up to your debugging target's operating
4551system (not controlled by @value{GDBN}), other threads may
4552execute more than one statement while the current thread completes a
4553single step. Moreover, in general other threads stop in the middle of a
4554statement, rather than at a clean statement boundary, when the program
4555stops.
4556
4557You might even find your program stopped in another thread after
4558continuing or even single-stepping. This happens whenever some other
4559thread runs into a breakpoint, a signal, or an exception before the
4560first thread completes whatever you requested.
4561
4562@cindex automatic thread selection
4563@cindex switching threads automatically
4564@cindex threads, automatic switching
4565Whenever @value{GDBN} stops your program, due to a breakpoint or a
4566signal, it automatically selects the thread where that breakpoint or
4567signal happened. @value{GDBN} alerts you to the context switch with a
4568message such as @samp{[Switching to Thread @var{n}]} to identify the
4569thread.
4570
4571On some OSes, you can modify @value{GDBN}'s default behavior by
4572locking the OS scheduler to allow only a single thread to run.
4573
4574@table @code
4575@item set scheduler-locking @var{mode}
4576@cindex scheduler locking mode
4577@cindex lock scheduler
4578Set the scheduler locking mode. If it is @code{off}, then there is no
4579locking and any thread may run at any time. If @code{on}, then only the
4580current thread may run when the inferior is resumed. The @code{step}
4581mode optimizes for single-stepping; it prevents other threads
4582from preempting the current thread while you are stepping, so that
4583the focus of debugging does not change unexpectedly.
4584Other threads only rarely (or never) get a chance to run
4585when you step. They are more likely to run when you @samp{next} over a
4586function call, and they are completely free to run when you use commands
4587like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
4588thread hits a breakpoint during its timeslice, @value{GDBN} does not change
4589the current thread away from the thread that you are debugging.
4590
4591@item show scheduler-locking
4592Display the current scheduler locking mode.
4593@end table
4594
4595@node Non-Stop Mode
4596@subsection Non-Stop Mode
4597
4598@cindex non-stop mode
4599
4600@c This section is really only a place-holder, and needs to be expanded
4601@c with more details.
4602
4603For some multi-threaded targets, @value{GDBN} supports an optional
4604mode of operation in which you can examine stopped program threads in
4605the debugger while other threads continue to execute freely. This
4606minimizes intrusion when debugging live systems, such as programs
4607where some threads have real-time constraints or must continue to
4608respond to external events. This is referred to as @dfn{non-stop} mode.
4609
4610In non-stop mode, when a thread stops to report a debugging event,
4611@emph{only} that thread is stopped; @value{GDBN} does not stop other
4612threads as well, in contrast to the all-stop mode behavior. Additionally,
4613execution commands such as @code{continue} and @code{step} apply by default
4614only to the current thread in non-stop mode, rather than all threads as
4615in all-stop mode. This allows you to control threads explicitly in
4616ways that are not possible in all-stop mode --- for example, stepping
4617one thread while allowing others to run freely, stepping
4618one thread while holding all others stopped, or stepping several threads
4619independently and simultaneously.
4620
4621To enter non-stop mode, use this sequence of commands before you run
4622or attach to your program:
4623
0606b73b
SL
4624@smallexample
4625# Enable the async interface.
c6ebd6cf 4626set target-async 1
0606b73b 4627
0606b73b
SL
4628# If using the CLI, pagination breaks non-stop.
4629set pagination off
4630
4631# Finally, turn it on!
4632set non-stop on
4633@end smallexample
4634
4635You can use these commands to manipulate the non-stop mode setting:
4636
4637@table @code
4638@kindex set non-stop
4639@item set non-stop on
4640Enable selection of non-stop mode.
4641@item set non-stop off
4642Disable selection of non-stop mode.
4643@kindex show non-stop
4644@item show non-stop
4645Show the current non-stop enablement setting.
4646@end table
4647
4648Note these commands only reflect whether non-stop mode is enabled,
4649not whether the currently-executing program is being run in non-stop mode.
4650In particular, the @code{set non-stop} preference is only consulted when
4651@value{GDBN} starts or connects to the target program, and it is generally
4652not possible to switch modes once debugging has started. Furthermore,
4653since not all targets support non-stop mode, even when you have enabled
4654non-stop mode, @value{GDBN} may still fall back to all-stop operation by
4655default.
4656
4657In non-stop mode, all execution commands apply only to the current thread
4658by default. That is, @code{continue} only continues one thread.
4659To continue all threads, issue @code{continue -a} or @code{c -a}.
4660
4661You can use @value{GDBN}'s background execution commands
4662(@pxref{Background Execution}) to run some threads in the background
4663while you continue to examine or step others from @value{GDBN}.
4664The MI execution commands (@pxref{GDB/MI Program Execution}) are
4665always executed asynchronously in non-stop mode.
4666
4667Suspending execution is done with the @code{interrupt} command when
4668running in the background, or @kbd{Ctrl-c} during foreground execution.
4669In all-stop mode, this stops the whole process;
4670but in non-stop mode the interrupt applies only to the current thread.
4671To stop the whole program, use @code{interrupt -a}.
4672
4673Other execution commands do not currently support the @code{-a} option.
4674
4675In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
4676that thread current, as it does in all-stop mode. This is because the
4677thread stop notifications are asynchronous with respect to @value{GDBN}'s
4678command interpreter, and it would be confusing if @value{GDBN} unexpectedly
4679changed to a different thread just as you entered a command to operate on the
4680previously current thread.
4681
4682@node Background Execution
4683@subsection Background Execution
4684
4685@cindex foreground execution
4686@cindex background execution
4687@cindex asynchronous execution
4688@cindex execution, foreground, background and asynchronous
4689
4690@value{GDBN}'s execution commands have two variants: the normal
4691foreground (synchronous) behavior, and a background
4692(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
4693the program to report that some thread has stopped before prompting for
4694another command. In background execution, @value{GDBN} immediately gives
4695a command prompt so that you can issue other commands while your program runs.
4696
4697To specify background execution, add a @code{&} to the command. For example,
4698the background form of the @code{continue} command is @code{continue&}, or
4699just @code{c&}. The execution commands that accept background execution
4700are:
4701
4702@table @code
4703@kindex run&
4704@item run
4705@xref{Starting, , Starting your Program}.
4706
4707@item attach
4708@kindex attach&
4709@xref{Attach, , Debugging an Already-running Process}.
4710
4711@item step
4712@kindex step&
4713@xref{Continuing and Stepping, step}.
4714
4715@item stepi
4716@kindex stepi&
4717@xref{Continuing and Stepping, stepi}.
4718
4719@item next
4720@kindex next&
4721@xref{Continuing and Stepping, next}.
4722
4723@item continue
4724@kindex continue&
4725@xref{Continuing and Stepping, continue}.
4726
4727@item finish
4728@kindex finish&
4729@xref{Continuing and Stepping, finish}.
4730
4731@item until
4732@kindex until&
4733@xref{Continuing and Stepping, until}.
4734
4735@end table
4736
4737Background execution is especially useful in conjunction with non-stop
4738mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
4739However, you can also use these commands in the normal all-stop mode with
4740the restriction that you cannot issue another execution command until the
4741previous one finishes. Examples of commands that are valid in all-stop
4742mode while the program is running include @code{help} and @code{info break}.
4743
4744You can interrupt your program while it is running in the background by
4745using the @code{interrupt} command.
4746
4747@table @code
4748@kindex interrupt
4749@item interrupt
4750@itemx interrupt -a
4751
4752Suspend execution of the running program. In all-stop mode,
4753@code{interrupt} stops the whole process, but in non-stop mode, it stops
4754only the current thread. To stop the whole program in non-stop mode,
4755use @code{interrupt -a}.
4756@end table
4757
4758You may need to explicitly enable async mode before you can use background
c6ebd6cf 4759execution commands, with the @code{set target-async 1} command. If the
0606b73b
SL
4760target doesn't support async mode, @value{GDBN} issues an error message
4761if you attempt to use the background execution commands.
4762
4763@node Thread-Specific Breakpoints
4764@subsection Thread-Specific Breakpoints
4765
c906108c 4766When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 4767Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
4768breakpoints on all threads, or on a particular thread.
4769
4770@table @code
4771@cindex breakpoints and threads
4772@cindex thread breakpoints
4773@kindex break @dots{} thread @var{threadno}
4774@item break @var{linespec} thread @var{threadno}
4775@itemx break @var{linespec} thread @var{threadno} if @dots{}
4776@var{linespec} specifies source lines; there are several ways of
2a25a5ba
EZ
4777writing them (@pxref{Specify Location}), but the effect is always to
4778specify some source line.
c906108c
SS
4779
4780Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4781to specify that you only want @value{GDBN} to stop the program when a
4782particular thread reaches this breakpoint. @var{threadno} is one of the
4783numeric thread identifiers assigned by @value{GDBN}, shown in the first
4784column of the @samp{info threads} display.
4785
4786If you do not specify @samp{thread @var{threadno}} when you set a
4787breakpoint, the breakpoint applies to @emph{all} threads of your
4788program.
4789
4790You can use the @code{thread} qualifier on conditional breakpoints as
4791well; in this case, place @samp{thread @var{threadno}} before the
4792breakpoint condition, like this:
4793
4794@smallexample
2df3850c 4795(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4796@end smallexample
4797
4798@end table
4799
0606b73b
SL
4800@node Interrupted System Calls
4801@subsection Interrupted System Calls
c906108c 4802
36d86913
MC
4803@cindex thread breakpoints and system calls
4804@cindex system calls and thread breakpoints
4805@cindex premature return from system calls
0606b73b
SL
4806There is an unfortunate side effect when using @value{GDBN} to debug
4807multi-threaded programs. If one thread stops for a
36d86913
MC
4808breakpoint, or for some other reason, and another thread is blocked in a
4809system call, then the system call may return prematurely. This is a
4810consequence of the interaction between multiple threads and the signals
4811that @value{GDBN} uses to implement breakpoints and other events that
4812stop execution.
4813
4814To handle this problem, your program should check the return value of
4815each system call and react appropriately. This is good programming
4816style anyways.
4817
4818For example, do not write code like this:
4819
4820@smallexample
4821 sleep (10);
4822@end smallexample
4823
4824The call to @code{sleep} will return early if a different thread stops
4825at a breakpoint or for some other reason.
4826
4827Instead, write this:
4828
4829@smallexample
4830 int unslept = 10;
4831 while (unslept > 0)
4832 unslept = sleep (unslept);
4833@end smallexample
4834
4835A system call is allowed to return early, so the system is still
4836conforming to its specification. But @value{GDBN} does cause your
4837multi-threaded program to behave differently than it would without
4838@value{GDBN}.
4839
4840Also, @value{GDBN} uses internal breakpoints in the thread library to
4841monitor certain events such as thread creation and thread destruction.
4842When such an event happens, a system call in another thread may return
4843prematurely, even though your program does not appear to stop.
4844
c906108c 4845
bacec72f
MS
4846@node Reverse Execution
4847@chapter Running programs backward
4848@cindex reverse execution
4849@cindex running programs backward
4850
4851When you are debugging a program, it is not unusual to realize that
4852you have gone too far, and some event of interest has already happened.
4853If the target environment supports it, @value{GDBN} can allow you to
4854``rewind'' the program by running it backward.
4855
4856A target environment that supports reverse execution should be able
4857to ``undo'' the changes in machine state that have taken place as the
4858program was executing normally. Variables, registers etc.@: should
4859revert to their previous values. Obviously this requires a great
4860deal of sophistication on the part of the target environment; not
4861all target environments can support reverse execution.
4862
4863When a program is executed in reverse, the instructions that
4864have most recently been executed are ``un-executed'', in reverse
4865order. The program counter runs backward, following the previous
4866thread of execution in reverse. As each instruction is ``un-executed'',
4867the values of memory and/or registers that were changed by that
4868instruction are reverted to their previous states. After executing
4869a piece of source code in reverse, all side effects of that code
4870should be ``undone'', and all variables should be returned to their
4871prior values@footnote{
4872Note that some side effects are easier to undo than others. For instance,
4873memory and registers are relatively easy, but device I/O is hard. Some
4874targets may be able undo things like device I/O, and some may not.
4875
4876The contract between @value{GDBN} and the reverse executing target
4877requires only that the target do something reasonable when
4878@value{GDBN} tells it to execute backwards, and then report the
4879results back to @value{GDBN}. Whatever the target reports back to
4880@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
4881assumes that the memory and registers that the target reports are in a
4882consistant state, but @value{GDBN} accepts whatever it is given.
4883}.
4884
4885If you are debugging in a target environment that supports
4886reverse execution, @value{GDBN} provides the following commands.
4887
4888@table @code
4889@kindex reverse-continue
4890@kindex rc @r{(@code{reverse-continue})}
4891@item reverse-continue @r{[}@var{ignore-count}@r{]}
4892@itemx rc @r{[}@var{ignore-count}@r{]}
4893Beginning at the point where your program last stopped, start executing
4894in reverse. Reverse execution will stop for breakpoints and synchronous
4895exceptions (signals), just like normal execution. Behavior of
4896asynchronous signals depends on the target environment.
4897
4898@kindex reverse-step
4899@kindex rs @r{(@code{step})}
4900@item reverse-step @r{[}@var{count}@r{]}
4901Run the program backward until control reaches the start of a
4902different source line; then stop it, and return control to @value{GDBN}.
4903
4904Like the @code{step} command, @code{reverse-step} will only stop
4905at the beginning of a source line. It ``un-executes'' the previously
4906executed source line. If the previous source line included calls to
4907debuggable functions, @code{reverse-step} will step (backward) into
4908the called function, stopping at the beginning of the @emph{last}
4909statement in the called function (typically a return statement).
4910
4911Also, as with the @code{step} command, if non-debuggable functions are
4912called, @code{reverse-step} will run thru them backward without stopping.
4913
4914@kindex reverse-stepi
4915@kindex rsi @r{(@code{reverse-stepi})}
4916@item reverse-stepi @r{[}@var{count}@r{]}
4917Reverse-execute one machine instruction. Note that the instruction
4918to be reverse-executed is @emph{not} the one pointed to by the program
4919counter, but the instruction executed prior to that one. For instance,
4920if the last instruction was a jump, @code{reverse-stepi} will take you
4921back from the destination of the jump to the jump instruction itself.
4922
4923@kindex reverse-next
4924@kindex rn @r{(@code{reverse-next})}
4925@item reverse-next @r{[}@var{count}@r{]}
4926Run backward to the beginning of the previous line executed in
4927the current (innermost) stack frame. If the line contains function
4928calls, they will be ``un-executed'' without stopping. Starting from
4929the first line of a function, @code{reverse-next} will take you back
4930to the caller of that function, @emph{before} the function was called,
4931just as the normal @code{next} command would take you from the last
4932line of a function back to its return to its caller
4933@footnote{Unles the code is too heavily optimized.}.
4934
4935@kindex reverse-nexti
4936@kindex rni @r{(@code{reverse-nexti})}
4937@item reverse-nexti @r{[}@var{count}@r{]}
4938Like @code{nexti}, @code{reverse-nexti} executes a single instruction
4939in reverse, except that called functions are ``un-executed'' atomically.
4940That is, if the previously executed instruction was a return from
4941another instruction, @code{reverse-nexti} will continue to execute
4942in reverse until the call to that function (from the current stack
4943frame) is reached.
4944
4945@kindex reverse-finish
4946@item reverse-finish
4947Just as the @code{finish} command takes you to the point where the
4948current function returns, @code{reverse-finish} takes you to the point
4949where it was called. Instead of ending up at the end of the current
4950function invocation, you end up at the beginning.
4951
4952@kindex set exec-direction
4953@item set exec-direction
4954Set the direction of target execution.
4955@itemx set exec-direction reverse
4956@cindex execute forward or backward in time
4957@value{GDBN} will perform all execution commands in reverse, until the
4958exec-direction mode is changed to ``forward''. Affected commands include
4959@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
4960command cannot be used in reverse mode.
4961@item set exec-direction forward
4962@value{GDBN} will perform all execution commands in the normal fashion.
4963This is the default.
4964@end table
4965
c906108c 4966
6d2ebf8b 4967@node Stack
c906108c
SS
4968@chapter Examining the Stack
4969
4970When your program has stopped, the first thing you need to know is where it
4971stopped and how it got there.
4972
4973@cindex call stack
5d161b24
DB
4974Each time your program performs a function call, information about the call
4975is generated.
4976That information includes the location of the call in your program,
4977the arguments of the call,
c906108c 4978and the local variables of the function being called.
5d161b24 4979The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4980The stack frames are allocated in a region of memory called the @dfn{call
4981stack}.
4982
4983When your program stops, the @value{GDBN} commands for examining the
4984stack allow you to see all of this information.
4985
4986@cindex selected frame
4987One of the stack frames is @dfn{selected} by @value{GDBN} and many
4988@value{GDBN} commands refer implicitly to the selected frame. In
4989particular, whenever you ask @value{GDBN} for the value of a variable in
4990your program, the value is found in the selected frame. There are
4991special @value{GDBN} commands to select whichever frame you are
79a6e687 4992interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
4993
4994When your program stops, @value{GDBN} automatically selects the
5d161b24 4995currently executing frame and describes it briefly, similar to the
79a6e687 4996@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
4997
4998@menu
4999* Frames:: Stack frames
5000* Backtrace:: Backtraces
5001* Selection:: Selecting a frame
5002* Frame Info:: Information on a frame
c906108c
SS
5003
5004@end menu
5005
6d2ebf8b 5006@node Frames
79a6e687 5007@section Stack Frames
c906108c 5008
d4f3574e 5009@cindex frame, definition
c906108c
SS
5010@cindex stack frame
5011The call stack is divided up into contiguous pieces called @dfn{stack
5012frames}, or @dfn{frames} for short; each frame is the data associated
5013with one call to one function. The frame contains the arguments given
5014to the function, the function's local variables, and the address at
5015which the function is executing.
5016
5017@cindex initial frame
5018@cindex outermost frame
5019@cindex innermost frame
5020When your program is started, the stack has only one frame, that of the
5021function @code{main}. This is called the @dfn{initial} frame or the
5022@dfn{outermost} frame. Each time a function is called, a new frame is
5023made. Each time a function returns, the frame for that function invocation
5024is eliminated. If a function is recursive, there can be many frames for
5025the same function. The frame for the function in which execution is
5026actually occurring is called the @dfn{innermost} frame. This is the most
5027recently created of all the stack frames that still exist.
5028
5029@cindex frame pointer
5030Inside your program, stack frames are identified by their addresses. A
5031stack frame consists of many bytes, each of which has its own address; each
5032kind of computer has a convention for choosing one byte whose
5033address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
5034in a register called the @dfn{frame pointer register}
5035(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
5036
5037@cindex frame number
5038@value{GDBN} assigns numbers to all existing stack frames, starting with
5039zero for the innermost frame, one for the frame that called it,
5040and so on upward. These numbers do not really exist in your program;
5041they are assigned by @value{GDBN} to give you a way of designating stack
5042frames in @value{GDBN} commands.
5043
6d2ebf8b
SS
5044@c The -fomit-frame-pointer below perennially causes hbox overflow
5045@c underflow problems.
c906108c
SS
5046@cindex frameless execution
5047Some compilers provide a way to compile functions so that they operate
e22ea452 5048without stack frames. (For example, the @value{NGCC} option
474c8240 5049@smallexample
6d2ebf8b 5050@samp{-fomit-frame-pointer}
474c8240 5051@end smallexample
6d2ebf8b 5052generates functions without a frame.)
c906108c
SS
5053This is occasionally done with heavily used library functions to save
5054the frame setup time. @value{GDBN} has limited facilities for dealing
5055with these function invocations. If the innermost function invocation
5056has no stack frame, @value{GDBN} nevertheless regards it as though
5057it had a separate frame, which is numbered zero as usual, allowing
5058correct tracing of the function call chain. However, @value{GDBN} has
5059no provision for frameless functions elsewhere in the stack.
5060
5061@table @code
d4f3574e 5062@kindex frame@r{, command}
41afff9a 5063@cindex current stack frame
c906108c 5064@item frame @var{args}
5d161b24 5065The @code{frame} command allows you to move from one stack frame to another,
c906108c 5066and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
5067address of the frame or the stack frame number. Without an argument,
5068@code{frame} prints the current stack frame.
c906108c
SS
5069
5070@kindex select-frame
41afff9a 5071@cindex selecting frame silently
c906108c
SS
5072@item select-frame
5073The @code{select-frame} command allows you to move from one stack frame
5074to another without printing the frame. This is the silent version of
5075@code{frame}.
5076@end table
5077
6d2ebf8b 5078@node Backtrace
c906108c
SS
5079@section Backtraces
5080
09d4efe1
EZ
5081@cindex traceback
5082@cindex call stack traces
c906108c
SS
5083A backtrace is a summary of how your program got where it is. It shows one
5084line per frame, for many frames, starting with the currently executing
5085frame (frame zero), followed by its caller (frame one), and on up the
5086stack.
5087
5088@table @code
5089@kindex backtrace
41afff9a 5090@kindex bt @r{(@code{backtrace})}
c906108c
SS
5091@item backtrace
5092@itemx bt
5093Print a backtrace of the entire stack: one line per frame for all
5094frames in the stack.
5095
5096You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 5097character, normally @kbd{Ctrl-c}.
c906108c
SS
5098
5099@item backtrace @var{n}
5100@itemx bt @var{n}
5101Similar, but print only the innermost @var{n} frames.
5102
5103@item backtrace -@var{n}
5104@itemx bt -@var{n}
5105Similar, but print only the outermost @var{n} frames.
0f061b69
NR
5106
5107@item backtrace full
0f061b69 5108@itemx bt full
dd74f6ae
NR
5109@itemx bt full @var{n}
5110@itemx bt full -@var{n}
e7109c7e 5111Print the values of the local variables also. @var{n} specifies the
286ba84d 5112number of frames to print, as described above.
c906108c
SS
5113@end table
5114
5115@kindex where
5116@kindex info stack
c906108c
SS
5117The names @code{where} and @code{info stack} (abbreviated @code{info s})
5118are additional aliases for @code{backtrace}.
5119
839c27b7
EZ
5120@cindex multiple threads, backtrace
5121In a multi-threaded program, @value{GDBN} by default shows the
5122backtrace only for the current thread. To display the backtrace for
5123several or all of the threads, use the command @code{thread apply}
5124(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
5125apply all backtrace}, @value{GDBN} will display the backtrace for all
5126the threads; this is handy when you debug a core dump of a
5127multi-threaded program.
5128
c906108c
SS
5129Each line in the backtrace shows the frame number and the function name.
5130The program counter value is also shown---unless you use @code{set
5131print address off}. The backtrace also shows the source file name and
5132line number, as well as the arguments to the function. The program
5133counter value is omitted if it is at the beginning of the code for that
5134line number.
5135
5136Here is an example of a backtrace. It was made with the command
5137@samp{bt 3}, so it shows the innermost three frames.
5138
5139@smallexample
5140@group
5d161b24 5141#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
5142 at builtin.c:993
5143#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
5144#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
5145 at macro.c:71
5146(More stack frames follow...)
5147@end group
5148@end smallexample
5149
5150@noindent
5151The display for frame zero does not begin with a program counter
5152value, indicating that your program has stopped at the beginning of the
5153code for line @code{993} of @code{builtin.c}.
5154
18999be5
EZ
5155@cindex value optimized out, in backtrace
5156@cindex function call arguments, optimized out
5157If your program was compiled with optimizations, some compilers will
5158optimize away arguments passed to functions if those arguments are
5159never used after the call. Such optimizations generate code that
5160passes arguments through registers, but doesn't store those arguments
5161in the stack frame. @value{GDBN} has no way of displaying such
5162arguments in stack frames other than the innermost one. Here's what
5163such a backtrace might look like:
5164
5165@smallexample
5166@group
5167#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5168 at builtin.c:993
5169#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
5170#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
5171 at macro.c:71
5172(More stack frames follow...)
5173@end group
5174@end smallexample
5175
5176@noindent
5177The values of arguments that were not saved in their stack frames are
5178shown as @samp{<value optimized out>}.
5179
5180If you need to display the values of such optimized-out arguments,
5181either deduce that from other variables whose values depend on the one
5182you are interested in, or recompile without optimizations.
5183
a8f24a35
EZ
5184@cindex backtrace beyond @code{main} function
5185@cindex program entry point
5186@cindex startup code, and backtrace
25d29d70
AC
5187Most programs have a standard user entry point---a place where system
5188libraries and startup code transition into user code. For C this is
d416eeec
EZ
5189@code{main}@footnote{
5190Note that embedded programs (the so-called ``free-standing''
5191environment) are not required to have a @code{main} function as the
5192entry point. They could even have multiple entry points.}.
5193When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
5194it will terminate the backtrace, to avoid tracing into highly
5195system-specific (and generally uninteresting) code.
5196
5197If you need to examine the startup code, or limit the number of levels
5198in a backtrace, you can change this behavior:
95f90d25
DJ
5199
5200@table @code
25d29d70
AC
5201@item set backtrace past-main
5202@itemx set backtrace past-main on
4644b6e3 5203@kindex set backtrace
25d29d70
AC
5204Backtraces will continue past the user entry point.
5205
5206@item set backtrace past-main off
95f90d25
DJ
5207Backtraces will stop when they encounter the user entry point. This is the
5208default.
5209
25d29d70 5210@item show backtrace past-main
4644b6e3 5211@kindex show backtrace
25d29d70
AC
5212Display the current user entry point backtrace policy.
5213
2315ffec
RC
5214@item set backtrace past-entry
5215@itemx set backtrace past-entry on
a8f24a35 5216Backtraces will continue past the internal entry point of an application.
2315ffec
RC
5217This entry point is encoded by the linker when the application is built,
5218and is likely before the user entry point @code{main} (or equivalent) is called.
5219
5220@item set backtrace past-entry off
d3e8051b 5221Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
5222application. This is the default.
5223
5224@item show backtrace past-entry
5225Display the current internal entry point backtrace policy.
5226
25d29d70
AC
5227@item set backtrace limit @var{n}
5228@itemx set backtrace limit 0
5229@cindex backtrace limit
5230Limit the backtrace to @var{n} levels. A value of zero means
5231unlimited.
95f90d25 5232
25d29d70
AC
5233@item show backtrace limit
5234Display the current limit on backtrace levels.
95f90d25
DJ
5235@end table
5236
6d2ebf8b 5237@node Selection
79a6e687 5238@section Selecting a Frame
c906108c
SS
5239
5240Most commands for examining the stack and other data in your program work on
5241whichever stack frame is selected at the moment. Here are the commands for
5242selecting a stack frame; all of them finish by printing a brief description
5243of the stack frame just selected.
5244
5245@table @code
d4f3574e 5246@kindex frame@r{, selecting}
41afff9a 5247@kindex f @r{(@code{frame})}
c906108c
SS
5248@item frame @var{n}
5249@itemx f @var{n}
5250Select frame number @var{n}. Recall that frame zero is the innermost
5251(currently executing) frame, frame one is the frame that called the
5252innermost one, and so on. The highest-numbered frame is the one for
5253@code{main}.
5254
5255@item frame @var{addr}
5256@itemx f @var{addr}
5257Select the frame at address @var{addr}. This is useful mainly if the
5258chaining of stack frames has been damaged by a bug, making it
5259impossible for @value{GDBN} to assign numbers properly to all frames. In
5260addition, this can be useful when your program has multiple stacks and
5261switches between them.
5262
c906108c
SS
5263On the SPARC architecture, @code{frame} needs two addresses to
5264select an arbitrary frame: a frame pointer and a stack pointer.
5265
5266On the MIPS and Alpha architecture, it needs two addresses: a stack
5267pointer and a program counter.
5268
5269On the 29k architecture, it needs three addresses: a register stack
5270pointer, a program counter, and a memory stack pointer.
c906108c
SS
5271
5272@kindex up
5273@item up @var{n}
5274Move @var{n} frames up the stack. For positive numbers @var{n}, this
5275advances toward the outermost frame, to higher frame numbers, to frames
5276that have existed longer. @var{n} defaults to one.
5277
5278@kindex down
41afff9a 5279@kindex do @r{(@code{down})}
c906108c
SS
5280@item down @var{n}
5281Move @var{n} frames down the stack. For positive numbers @var{n}, this
5282advances toward the innermost frame, to lower frame numbers, to frames
5283that were created more recently. @var{n} defaults to one. You may
5284abbreviate @code{down} as @code{do}.
5285@end table
5286
5287All of these commands end by printing two lines of output describing the
5288frame. The first line shows the frame number, the function name, the
5289arguments, and the source file and line number of execution in that
5d161b24 5290frame. The second line shows the text of that source line.
c906108c
SS
5291
5292@need 1000
5293For example:
5294
5295@smallexample
5296@group
5297(@value{GDBP}) up
5298#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
5299 at env.c:10
530010 read_input_file (argv[i]);
5301@end group
5302@end smallexample
5303
5304After such a printout, the @code{list} command with no arguments
5305prints ten lines centered on the point of execution in the frame.
87885426
FN
5306You can also edit the program at the point of execution with your favorite
5307editing program by typing @code{edit}.
79a6e687 5308@xref{List, ,Printing Source Lines},
87885426 5309for details.
c906108c
SS
5310
5311@table @code
5312@kindex down-silently
5313@kindex up-silently
5314@item up-silently @var{n}
5315@itemx down-silently @var{n}
5316These two commands are variants of @code{up} and @code{down},
5317respectively; they differ in that they do their work silently, without
5318causing display of the new frame. They are intended primarily for use
5319in @value{GDBN} command scripts, where the output might be unnecessary and
5320distracting.
5321@end table
5322
6d2ebf8b 5323@node Frame Info
79a6e687 5324@section Information About a Frame
c906108c
SS
5325
5326There are several other commands to print information about the selected
5327stack frame.
5328
5329@table @code
5330@item frame
5331@itemx f
5332When used without any argument, this command does not change which
5333frame is selected, but prints a brief description of the currently
5334selected stack frame. It can be abbreviated @code{f}. With an
5335argument, this command is used to select a stack frame.
79a6e687 5336@xref{Selection, ,Selecting a Frame}.
c906108c
SS
5337
5338@kindex info frame
41afff9a 5339@kindex info f @r{(@code{info frame})}
c906108c
SS
5340@item info frame
5341@itemx info f
5342This command prints a verbose description of the selected stack frame,
5343including:
5344
5345@itemize @bullet
5d161b24
DB
5346@item
5347the address of the frame
c906108c
SS
5348@item
5349the address of the next frame down (called by this frame)
5350@item
5351the address of the next frame up (caller of this frame)
5352@item
5353the language in which the source code corresponding to this frame is written
5354@item
5355the address of the frame's arguments
5356@item
d4f3574e
SS
5357the address of the frame's local variables
5358@item
c906108c
SS
5359the program counter saved in it (the address of execution in the caller frame)
5360@item
5361which registers were saved in the frame
5362@end itemize
5363
5364@noindent The verbose description is useful when
5365something has gone wrong that has made the stack format fail to fit
5366the usual conventions.
5367
5368@item info frame @var{addr}
5369@itemx info f @var{addr}
5370Print a verbose description of the frame at address @var{addr}, without
5371selecting that frame. The selected frame remains unchanged by this
5372command. This requires the same kind of address (more than one for some
5373architectures) that you specify in the @code{frame} command.
79a6e687 5374@xref{Selection, ,Selecting a Frame}.
c906108c
SS
5375
5376@kindex info args
5377@item info args
5378Print the arguments of the selected frame, each on a separate line.
5379
5380@item info locals
5381@kindex info locals
5382Print the local variables of the selected frame, each on a separate
5383line. These are all variables (declared either static or automatic)
5384accessible at the point of execution of the selected frame.
5385
c906108c 5386@kindex info catch
d4f3574e
SS
5387@cindex catch exceptions, list active handlers
5388@cindex exception handlers, how to list
c906108c
SS
5389@item info catch
5390Print a list of all the exception handlers that are active in the
5391current stack frame at the current point of execution. To see other
5392exception handlers, visit the associated frame (using the @code{up},
5393@code{down}, or @code{frame} commands); then type @code{info catch}.
79a6e687 5394@xref{Set Catchpoints, , Setting Catchpoints}.
53a5351d 5395
c906108c
SS
5396@end table
5397
c906108c 5398
6d2ebf8b 5399@node Source
c906108c
SS
5400@chapter Examining Source Files
5401
5402@value{GDBN} can print parts of your program's source, since the debugging
5403information recorded in the program tells @value{GDBN} what source files were
5404used to build it. When your program stops, @value{GDBN} spontaneously prints
5405the line where it stopped. Likewise, when you select a stack frame
79a6e687 5406(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
5407execution in that frame has stopped. You can print other portions of
5408source files by explicit command.
5409
7a292a7a 5410If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 5411prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 5412@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
5413
5414@menu
5415* List:: Printing source lines
2a25a5ba 5416* Specify Location:: How to specify code locations
87885426 5417* Edit:: Editing source files
c906108c 5418* Search:: Searching source files
c906108c
SS
5419* Source Path:: Specifying source directories
5420* Machine Code:: Source and machine code
5421@end menu
5422
6d2ebf8b 5423@node List
79a6e687 5424@section Printing Source Lines
c906108c
SS
5425
5426@kindex list
41afff9a 5427@kindex l @r{(@code{list})}
c906108c 5428To print lines from a source file, use the @code{list} command
5d161b24 5429(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
5430There are several ways to specify what part of the file you want to
5431print; see @ref{Specify Location}, for the full list.
c906108c
SS
5432
5433Here are the forms of the @code{list} command most commonly used:
5434
5435@table @code
5436@item list @var{linenum}
5437Print lines centered around line number @var{linenum} in the
5438current source file.
5439
5440@item list @var{function}
5441Print lines centered around the beginning of function
5442@var{function}.
5443
5444@item list
5445Print more lines. If the last lines printed were printed with a
5446@code{list} command, this prints lines following the last lines
5447printed; however, if the last line printed was a solitary line printed
5448as part of displaying a stack frame (@pxref{Stack, ,Examining the
5449Stack}), this prints lines centered around that line.
5450
5451@item list -
5452Print lines just before the lines last printed.
5453@end table
5454
9c16f35a 5455@cindex @code{list}, how many lines to display
c906108c
SS
5456By default, @value{GDBN} prints ten source lines with any of these forms of
5457the @code{list} command. You can change this using @code{set listsize}:
5458
5459@table @code
5460@kindex set listsize
5461@item set listsize @var{count}
5462Make the @code{list} command display @var{count} source lines (unless
5463the @code{list} argument explicitly specifies some other number).
5464
5465@kindex show listsize
5466@item show listsize
5467Display the number of lines that @code{list} prints.
5468@end table
5469
5470Repeating a @code{list} command with @key{RET} discards the argument,
5471so it is equivalent to typing just @code{list}. This is more useful
5472than listing the same lines again. An exception is made for an
5473argument of @samp{-}; that argument is preserved in repetition so that
5474each repetition moves up in the source file.
5475
c906108c
SS
5476In general, the @code{list} command expects you to supply zero, one or two
5477@dfn{linespecs}. Linespecs specify source lines; there are several ways
2a25a5ba
EZ
5478of writing them (@pxref{Specify Location}), but the effect is always
5479to specify some source line.
5480
c906108c
SS
5481Here is a complete description of the possible arguments for @code{list}:
5482
5483@table @code
5484@item list @var{linespec}
5485Print lines centered around the line specified by @var{linespec}.
5486
5487@item list @var{first},@var{last}
5488Print lines from @var{first} to @var{last}. Both arguments are
2a25a5ba
EZ
5489linespecs. When a @code{list} command has two linespecs, and the
5490source file of the second linespec is omitted, this refers to
5491the same source file as the first linespec.
c906108c
SS
5492
5493@item list ,@var{last}
5494Print lines ending with @var{last}.
5495
5496@item list @var{first},
5497Print lines starting with @var{first}.
5498
5499@item list +
5500Print lines just after the lines last printed.
5501
5502@item list -
5503Print lines just before the lines last printed.
5504
5505@item list
5506As described in the preceding table.
5507@end table
5508
2a25a5ba
EZ
5509@node Specify Location
5510@section Specifying a Location
5511@cindex specifying location
5512@cindex linespec
c906108c 5513
2a25a5ba
EZ
5514Several @value{GDBN} commands accept arguments that specify a location
5515of your program's code. Since @value{GDBN} is a source-level
5516debugger, a location usually specifies some line in the source code;
5517for that reason, locations are also known as @dfn{linespecs}.
c906108c 5518
2a25a5ba
EZ
5519Here are all the different ways of specifying a code location that
5520@value{GDBN} understands:
c906108c 5521
2a25a5ba
EZ
5522@table @code
5523@item @var{linenum}
5524Specifies the line number @var{linenum} of the current source file.
c906108c 5525
2a25a5ba
EZ
5526@item -@var{offset}
5527@itemx +@var{offset}
5528Specifies the line @var{offset} lines before or after the @dfn{current
5529line}. For the @code{list} command, the current line is the last one
5530printed; for the breakpoint commands, this is the line at which
5531execution stopped in the currently selected @dfn{stack frame}
5532(@pxref{Frames, ,Frames}, for a description of stack frames.) When
5533used as the second of the two linespecs in a @code{list} command,
5534this specifies the line @var{offset} lines up or down from the first
5535linespec.
5536
5537@item @var{filename}:@var{linenum}
5538Specifies the line @var{linenum} in the source file @var{filename}.
c906108c
SS
5539
5540@item @var{function}
5541Specifies the line that begins the body of the function @var{function}.
2a25a5ba 5542For example, in C, this is the line with the open brace.
c906108c
SS
5543
5544@item @var{filename}:@var{function}
2a25a5ba
EZ
5545Specifies the line that begins the body of the function @var{function}
5546in the file @var{filename}. You only need the file name with a
5547function name to avoid ambiguity when there are identically named
5548functions in different source files.
c906108c
SS
5549
5550@item *@var{address}
2a25a5ba
EZ
5551Specifies the program address @var{address}. For line-oriented
5552commands, such as @code{list} and @code{edit}, this specifies a source
5553line that contains @var{address}. For @code{break} and other
5554breakpoint oriented commands, this can be used to set breakpoints in
5555parts of your program which do not have debugging information or
5556source files.
5557
5558Here @var{address} may be any expression valid in the current working
5559language (@pxref{Languages, working language}) that specifies a code
5fa54e5d
EZ
5560address. In addition, as a convenience, @value{GDBN} extends the
5561semantics of expressions used in locations to cover the situations
5562that frequently happen during debugging. Here are the various forms
5563of @var{address}:
2a25a5ba
EZ
5564
5565@table @code
5566@item @var{expression}
5567Any expression valid in the current working language.
5568
5569@item @var{funcaddr}
5570An address of a function or procedure derived from its name. In C,
5571C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
5572simply the function's name @var{function} (and actually a special case
5573of a valid expression). In Pascal and Modula-2, this is
5574@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
5575(although the Pascal form also works).
5576
5577This form specifies the address of the function's first instruction,
5578before the stack frame and arguments have been set up.
5579
5580@item '@var{filename}'::@var{funcaddr}
5581Like @var{funcaddr} above, but also specifies the name of the source
5582file explicitly. This is useful if the name of the function does not
5583specify the function unambiguously, e.g., if there are several
5584functions with identical names in different source files.
c906108c
SS
5585@end table
5586
2a25a5ba
EZ
5587@end table
5588
5589
87885426 5590@node Edit
79a6e687 5591@section Editing Source Files
87885426
FN
5592@cindex editing source files
5593
5594@kindex edit
5595@kindex e @r{(@code{edit})}
5596To edit the lines in a source file, use the @code{edit} command.
5597The editing program of your choice
5598is invoked with the current line set to
5599the active line in the program.
5600Alternatively, there are several ways to specify what part of the file you
2a25a5ba 5601want to print if you want to see other parts of the program:
87885426
FN
5602
5603@table @code
2a25a5ba
EZ
5604@item edit @var{location}
5605Edit the source file specified by @code{location}. Editing starts at
5606that @var{location}, e.g., at the specified source line of the
5607specified file. @xref{Specify Location}, for all the possible forms
5608of the @var{location} argument; here are the forms of the @code{edit}
5609command most commonly used:
87885426 5610
2a25a5ba 5611@table @code
87885426
FN
5612@item edit @var{number}
5613Edit the current source file with @var{number} as the active line number.
5614
5615@item edit @var{function}
5616Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 5617@end table
87885426 5618
87885426
FN
5619@end table
5620
79a6e687 5621@subsection Choosing your Editor
87885426
FN
5622You can customize @value{GDBN} to use any editor you want
5623@footnote{
5624The only restriction is that your editor (say @code{ex}), recognizes the
5625following command-line syntax:
10998722 5626@smallexample
87885426 5627ex +@var{number} file
10998722 5628@end smallexample
15387254
EZ
5629The optional numeric value +@var{number} specifies the number of the line in
5630the file where to start editing.}.
5631By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
5632by setting the environment variable @code{EDITOR} before using
5633@value{GDBN}. For example, to configure @value{GDBN} to use the
5634@code{vi} editor, you could use these commands with the @code{sh} shell:
5635@smallexample
87885426
FN
5636EDITOR=/usr/bin/vi
5637export EDITOR
15387254 5638gdb @dots{}
10998722 5639@end smallexample
87885426 5640or in the @code{csh} shell,
10998722 5641@smallexample
87885426 5642setenv EDITOR /usr/bin/vi
15387254 5643gdb @dots{}
10998722 5644@end smallexample
87885426 5645
6d2ebf8b 5646@node Search
79a6e687 5647@section Searching Source Files
15387254 5648@cindex searching source files
c906108c
SS
5649
5650There are two commands for searching through the current source file for a
5651regular expression.
5652
5653@table @code
5654@kindex search
5655@kindex forward-search
5656@item forward-search @var{regexp}
5657@itemx search @var{regexp}
5658The command @samp{forward-search @var{regexp}} checks each line,
5659starting with the one following the last line listed, for a match for
5d161b24 5660@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
5661synonym @samp{search @var{regexp}} or abbreviate the command name as
5662@code{fo}.
5663
09d4efe1 5664@kindex reverse-search
c906108c
SS
5665@item reverse-search @var{regexp}
5666The command @samp{reverse-search @var{regexp}} checks each line, starting
5667with the one before the last line listed and going backward, for a match
5668for @var{regexp}. It lists the line that is found. You can abbreviate
5669this command as @code{rev}.
5670@end table
c906108c 5671
6d2ebf8b 5672@node Source Path
79a6e687 5673@section Specifying Source Directories
c906108c
SS
5674
5675@cindex source path
5676@cindex directories for source files
5677Executable programs sometimes do not record the directories of the source
5678files from which they were compiled, just the names. Even when they do,
5679the directories could be moved between the compilation and your debugging
5680session. @value{GDBN} has a list of directories to search for source files;
5681this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
5682it tries all the directories in the list, in the order they are present
0b66e38c
EZ
5683in the list, until it finds a file with the desired name.
5684
5685For example, suppose an executable references the file
5686@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
5687@file{/mnt/cross}. The file is first looked up literally; if this
5688fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
5689fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
5690message is printed. @value{GDBN} does not look up the parts of the
5691source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
5692Likewise, the subdirectories of the source path are not searched: if
5693the source path is @file{/mnt/cross}, and the binary refers to
5694@file{foo.c}, @value{GDBN} would not find it under
5695@file{/mnt/cross/usr/src/foo-1.0/lib}.
5696
5697Plain file names, relative file names with leading directories, file
5698names containing dots, etc.@: are all treated as described above; for
5699instance, if the source path is @file{/mnt/cross}, and the source file
5700is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
5701@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
5702that---@file{/mnt/cross/foo.c}.
5703
5704Note that the executable search path is @emph{not} used to locate the
cd852561 5705source files.
c906108c
SS
5706
5707Whenever you reset or rearrange the source path, @value{GDBN} clears out
5708any information it has cached about where source files are found and where
5709each line is in the file.
5710
5711@kindex directory
5712@kindex dir
d4f3574e
SS
5713When you start @value{GDBN}, its source path includes only @samp{cdir}
5714and @samp{cwd}, in that order.
c906108c
SS
5715To add other directories, use the @code{directory} command.
5716
4b505b12
AS
5717The search path is used to find both program source files and @value{GDBN}
5718script files (read using the @samp{-command} option and @samp{source} command).
5719
30daae6c
JB
5720In addition to the source path, @value{GDBN} provides a set of commands
5721that manage a list of source path substitution rules. A @dfn{substitution
5722rule} specifies how to rewrite source directories stored in the program's
5723debug information in case the sources were moved to a different
5724directory between compilation and debugging. A rule is made of
5725two strings, the first specifying what needs to be rewritten in
5726the path, and the second specifying how it should be rewritten.
5727In @ref{set substitute-path}, we name these two parts @var{from} and
5728@var{to} respectively. @value{GDBN} does a simple string replacement
5729of @var{from} with @var{to} at the start of the directory part of the
5730source file name, and uses that result instead of the original file
5731name to look up the sources.
5732
5733Using the previous example, suppose the @file{foo-1.0} tree has been
5734moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 5735@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
5736@file{/mnt/cross}. The first lookup will then be
5737@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
5738of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
5739substitution rule, use the @code{set substitute-path} command
5740(@pxref{set substitute-path}).
5741
5742To avoid unexpected substitution results, a rule is applied only if the
5743@var{from} part of the directory name ends at a directory separator.
5744For instance, a rule substituting @file{/usr/source} into
5745@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
5746not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 5747is applied only at the beginning of the directory name, this rule will
30daae6c
JB
5748not be applied to @file{/root/usr/source/baz.c} either.
5749
5750In many cases, you can achieve the same result using the @code{directory}
5751command. However, @code{set substitute-path} can be more efficient in
5752the case where the sources are organized in a complex tree with multiple
5753subdirectories. With the @code{directory} command, you need to add each
5754subdirectory of your project. If you moved the entire tree while
5755preserving its internal organization, then @code{set substitute-path}
5756allows you to direct the debugger to all the sources with one single
5757command.
5758
5759@code{set substitute-path} is also more than just a shortcut command.
5760The source path is only used if the file at the original location no
5761longer exists. On the other hand, @code{set substitute-path} modifies
5762the debugger behavior to look at the rewritten location instead. So, if
5763for any reason a source file that is not relevant to your executable is
5764located at the original location, a substitution rule is the only
3f94c067 5765method available to point @value{GDBN} at the new location.
30daae6c 5766
c906108c
SS
5767@table @code
5768@item directory @var{dirname} @dots{}
5769@item dir @var{dirname} @dots{}
5770Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
5771directory names may be given to this command, separated by @samp{:}
5772(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5773part of absolute file names) or
c906108c
SS
5774whitespace. You may specify a directory that is already in the source
5775path; this moves it forward, so @value{GDBN} searches it sooner.
5776
5777@kindex cdir
5778@kindex cwd
41afff9a 5779@vindex $cdir@r{, convenience variable}
d3e8051b 5780@vindex $cwd@r{, convenience variable}
c906108c
SS
5781@cindex compilation directory
5782@cindex current directory
5783@cindex working directory
5784@cindex directory, current
5785@cindex directory, compilation
5786You can use the string @samp{$cdir} to refer to the compilation
5787directory (if one is recorded), and @samp{$cwd} to refer to the current
5788working directory. @samp{$cwd} is not the same as @samp{.}---the former
5789tracks the current working directory as it changes during your @value{GDBN}
5790session, while the latter is immediately expanded to the current
5791directory at the time you add an entry to the source path.
5792
5793@item directory
cd852561 5794Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
5795
5796@c RET-repeat for @code{directory} is explicitly disabled, but since
5797@c repeating it would be a no-op we do not say that. (thanks to RMS)
5798
5799@item show directories
5800@kindex show directories
5801Print the source path: show which directories it contains.
30daae6c
JB
5802
5803@anchor{set substitute-path}
5804@item set substitute-path @var{from} @var{to}
5805@kindex set substitute-path
5806Define a source path substitution rule, and add it at the end of the
5807current list of existing substitution rules. If a rule with the same
5808@var{from} was already defined, then the old rule is also deleted.
5809
5810For example, if the file @file{/foo/bar/baz.c} was moved to
5811@file{/mnt/cross/baz.c}, then the command
5812
5813@smallexample
5814(@value{GDBP}) set substitute-path /usr/src /mnt/cross
5815@end smallexample
5816
5817@noindent
5818will tell @value{GDBN} to replace @samp{/usr/src} with
5819@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
5820@file{baz.c} even though it was moved.
5821
5822In the case when more than one substitution rule have been defined,
5823the rules are evaluated one by one in the order where they have been
5824defined. The first one matching, if any, is selected to perform
5825the substitution.
5826
5827For instance, if we had entered the following commands:
5828
5829@smallexample
5830(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
5831(@value{GDBP}) set substitute-path /usr/src /mnt/src
5832@end smallexample
5833
5834@noindent
5835@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
5836@file{/mnt/include/defs.h} by using the first rule. However, it would
5837use the second rule to rewrite @file{/usr/src/lib/foo.c} into
5838@file{/mnt/src/lib/foo.c}.
5839
5840
5841@item unset substitute-path [path]
5842@kindex unset substitute-path
5843If a path is specified, search the current list of substitution rules
5844for a rule that would rewrite that path. Delete that rule if found.
5845A warning is emitted by the debugger if no rule could be found.
5846
5847If no path is specified, then all substitution rules are deleted.
5848
5849@item show substitute-path [path]
5850@kindex show substitute-path
5851If a path is specified, then print the source path substitution rule
5852which would rewrite that path, if any.
5853
5854If no path is specified, then print all existing source path substitution
5855rules.
5856
c906108c
SS
5857@end table
5858
5859If your source path is cluttered with directories that are no longer of
5860interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5861versions of source. You can correct the situation as follows:
5862
5863@enumerate
5864@item
cd852561 5865Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
5866
5867@item
5868Use @code{directory} with suitable arguments to reinstall the
5869directories you want in the source path. You can add all the
5870directories in one command.
5871@end enumerate
5872
6d2ebf8b 5873@node Machine Code
79a6e687 5874@section Source and Machine Code
15387254 5875@cindex source line and its code address
c906108c
SS
5876
5877You can use the command @code{info line} to map source lines to program
5878addresses (and vice versa), and the command @code{disassemble} to display
5879a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 5880mode, the @code{info line} command causes the arrow to point to the
5d161b24 5881line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
5882well as hex.
5883
5884@table @code
5885@kindex info line
5886@item info line @var{linespec}
5887Print the starting and ending addresses of the compiled code for
5888source line @var{linespec}. You can specify source lines in any of
2a25a5ba 5889the ways documented in @ref{Specify Location}.
c906108c
SS
5890@end table
5891
5892For example, we can use @code{info line} to discover the location of
5893the object code for the first line of function
5894@code{m4_changequote}:
5895
d4f3574e
SS
5896@c FIXME: I think this example should also show the addresses in
5897@c symbolic form, as they usually would be displayed.
c906108c 5898@smallexample
96a2c332 5899(@value{GDBP}) info line m4_changequote
c906108c
SS
5900Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5901@end smallexample
5902
5903@noindent
15387254 5904@cindex code address and its source line
c906108c
SS
5905We can also inquire (using @code{*@var{addr}} as the form for
5906@var{linespec}) what source line covers a particular address:
5907@smallexample
5908(@value{GDBP}) info line *0x63ff
5909Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5910@end smallexample
5911
5912@cindex @code{$_} and @code{info line}
15387254 5913@cindex @code{x} command, default address
41afff9a 5914@kindex x@r{(examine), and} info line
c906108c
SS
5915After @code{info line}, the default address for the @code{x} command
5916is changed to the starting address of the line, so that @samp{x/i} is
5917sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 5918,Examining Memory}). Also, this address is saved as the value of the
c906108c 5919convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 5920Variables}).
c906108c
SS
5921
5922@table @code
5923@kindex disassemble
5924@cindex assembly instructions
5925@cindex instructions, assembly
5926@cindex machine instructions
5927@cindex listing machine instructions
5928@item disassemble
d14508fe 5929@itemx disassemble /m
c906108c 5930This specialized command dumps a range of memory as machine
d14508fe
DE
5931instructions. It can also print mixed source+disassembly by specifying
5932the @code{/m} modifier.
5933The default memory range is the function surrounding the
c906108c
SS
5934program counter of the selected frame. A single argument to this
5935command is a program counter value; @value{GDBN} dumps the function
5936surrounding this value. Two arguments specify a range of addresses
5937(first inclusive, second exclusive) to dump.
5938@end table
5939
c906108c
SS
5940The following example shows the disassembly of a range of addresses of
5941HP PA-RISC 2.0 code:
5942
5943@smallexample
5944(@value{GDBP}) disas 0x32c4 0x32e4
5945Dump of assembler code from 0x32c4 to 0x32e4:
59460x32c4 <main+204>: addil 0,dp
59470x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
59480x32cc <main+212>: ldil 0x3000,r31
59490x32d0 <main+216>: ble 0x3f8(sr4,r31)
59500x32d4 <main+220>: ldo 0(r31),rp
59510x32d8 <main+224>: addil -0x800,dp
59520x32dc <main+228>: ldo 0x588(r1),r26
59530x32e0 <main+232>: ldil 0x3000,r31
5954End of assembler dump.
5955@end smallexample
c906108c 5956
d14508fe
DE
5957Here is an example showing mixed source+assembly for Intel x86:
5958
5959@smallexample
5960(@value{GDBP}) disas /m main
5961Dump of assembler code for function main:
59625 @{
59630x08048330 <main+0>: push %ebp
59640x08048331 <main+1>: mov %esp,%ebp
59650x08048333 <main+3>: sub $0x8,%esp
59660x08048336 <main+6>: and $0xfffffff0,%esp
59670x08048339 <main+9>: sub $0x10,%esp
5968
59696 printf ("Hello.\n");
59700x0804833c <main+12>: movl $0x8048440,(%esp)
59710x08048343 <main+19>: call 0x8048284 <puts@@plt>
5972
59737 return 0;
59748 @}
59750x08048348 <main+24>: mov $0x0,%eax
59760x0804834d <main+29>: leave
59770x0804834e <main+30>: ret
5978
5979End of assembler dump.
5980@end smallexample
5981
c906108c
SS
5982Some architectures have more than one commonly-used set of instruction
5983mnemonics or other syntax.
5984
76d17f34
EZ
5985For programs that were dynamically linked and use shared libraries,
5986instructions that call functions or branch to locations in the shared
5987libraries might show a seemingly bogus location---it's actually a
5988location of the relocation table. On some architectures, @value{GDBN}
5989might be able to resolve these to actual function names.
5990
c906108c 5991@table @code
d4f3574e 5992@kindex set disassembly-flavor
d4f3574e
SS
5993@cindex Intel disassembly flavor
5994@cindex AT&T disassembly flavor
5995@item set disassembly-flavor @var{instruction-set}
c906108c
SS
5996Select the instruction set to use when disassembling the
5997program via the @code{disassemble} or @code{x/i} commands.
5998
5999Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
6000can set @var{instruction-set} to either @code{intel} or @code{att}.
6001The default is @code{att}, the AT&T flavor used by default by Unix
6002assemblers for x86-based targets.
9c16f35a
EZ
6003
6004@kindex show disassembly-flavor
6005@item show disassembly-flavor
6006Show the current setting of the disassembly flavor.
c906108c
SS
6007@end table
6008
6009
6d2ebf8b 6010@node Data
c906108c
SS
6011@chapter Examining Data
6012
6013@cindex printing data
6014@cindex examining data
6015@kindex print
6016@kindex inspect
6017@c "inspect" is not quite a synonym if you are using Epoch, which we do not
6018@c document because it is nonstandard... Under Epoch it displays in a
6019@c different window or something like that.
6020The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
6021command (abbreviated @code{p}), or its synonym @code{inspect}. It
6022evaluates and prints the value of an expression of the language your
6023program is written in (@pxref{Languages, ,Using @value{GDBN} with
6024Different Languages}).
c906108c
SS
6025
6026@table @code
d4f3574e
SS
6027@item print @var{expr}
6028@itemx print /@var{f} @var{expr}
6029@var{expr} is an expression (in the source language). By default the
6030value of @var{expr} is printed in a format appropriate to its data type;
c906108c 6031you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 6032@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 6033Formats}.
c906108c
SS
6034
6035@item print
6036@itemx print /@var{f}
15387254 6037@cindex reprint the last value
d4f3574e 6038If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 6039@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
6040conveniently inspect the same value in an alternative format.
6041@end table
6042
6043A more low-level way of examining data is with the @code{x} command.
6044It examines data in memory at a specified address and prints it in a
79a6e687 6045specified format. @xref{Memory, ,Examining Memory}.
c906108c 6046
7a292a7a 6047If you are interested in information about types, or about how the
d4f3574e
SS
6048fields of a struct or a class are declared, use the @code{ptype @var{exp}}
6049command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 6050Table}.
c906108c
SS
6051
6052@menu
6053* Expressions:: Expressions
6ba66d6a 6054* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
6055* Variables:: Program variables
6056* Arrays:: Artificial arrays
6057* Output Formats:: Output formats
6058* Memory:: Examining memory
6059* Auto Display:: Automatic display
6060* Print Settings:: Print settings
6061* Value History:: Value history
6062* Convenience Vars:: Convenience variables
6063* Registers:: Registers
c906108c 6064* Floating Point Hardware:: Floating point hardware
53c69bd7 6065* Vector Unit:: Vector Unit
721c2651 6066* OS Information:: Auxiliary data provided by operating system
29e57380 6067* Memory Region Attributes:: Memory region attributes
16d9dec6 6068* Dump/Restore Files:: Copy between memory and a file
384ee23f 6069* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
6070* Character Sets:: Debugging programs that use a different
6071 character set than GDB does
09d4efe1 6072* Caching Remote Data:: Data caching for remote targets
08388c79 6073* Searching Memory:: Searching memory for a sequence of bytes
c906108c
SS
6074@end menu
6075
6d2ebf8b 6076@node Expressions
c906108c
SS
6077@section Expressions
6078
6079@cindex expressions
6080@code{print} and many other @value{GDBN} commands accept an expression and
6081compute its value. Any kind of constant, variable or operator defined
6082by the programming language you are using is valid in an expression in
e2e0bcd1
JB
6083@value{GDBN}. This includes conditional expressions, function calls,
6084casts, and string constants. It also includes preprocessor macros, if
6085you compiled your program to include this information; see
6086@ref{Compilation}.
c906108c 6087
15387254 6088@cindex arrays in expressions
d4f3574e
SS
6089@value{GDBN} supports array constants in expressions input by
6090the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
6091you can use the command @code{print @{1, 2, 3@}} to create an array
6092of three integers. If you pass an array to a function or assign it
6093to a program variable, @value{GDBN} copies the array to memory that
6094is @code{malloc}ed in the target program.
c906108c 6095
c906108c
SS
6096Because C is so widespread, most of the expressions shown in examples in
6097this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
6098Languages}, for information on how to use expressions in other
6099languages.
6100
6101In this section, we discuss operators that you can use in @value{GDBN}
6102expressions regardless of your programming language.
6103
15387254 6104@cindex casts, in expressions
c906108c
SS
6105Casts are supported in all languages, not just in C, because it is so
6106useful to cast a number into a pointer in order to examine a structure
6107at that address in memory.
6108@c FIXME: casts supported---Mod2 true?
c906108c
SS
6109
6110@value{GDBN} supports these operators, in addition to those common
6111to programming languages:
6112
6113@table @code
6114@item @@
6115@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 6116@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
6117
6118@item ::
6119@samp{::} allows you to specify a variable in terms of the file or
79a6e687 6120function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
6121
6122@cindex @{@var{type}@}
6123@cindex type casting memory
6124@cindex memory, viewing as typed object
6125@cindex casts, to view memory
6126@item @{@var{type}@} @var{addr}
6127Refers to an object of type @var{type} stored at address @var{addr} in
6128memory. @var{addr} may be any expression whose value is an integer or
6129pointer (but parentheses are required around binary operators, just as in
6130a cast). This construct is allowed regardless of what kind of data is
6131normally supposed to reside at @var{addr}.
6132@end table
6133
6ba66d6a
JB
6134@node Ambiguous Expressions
6135@section Ambiguous Expressions
6136@cindex ambiguous expressions
6137
6138Expressions can sometimes contain some ambiguous elements. For instance,
6139some programming languages (notably Ada, C@t{++} and Objective-C) permit
6140a single function name to be defined several times, for application in
6141different contexts. This is called @dfn{overloading}. Another example
6142involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
6143templates and is typically instantiated several times, resulting in
6144the same function name being defined in different contexts.
6145
6146In some cases and depending on the language, it is possible to adjust
6147the expression to remove the ambiguity. For instance in C@t{++}, you
6148can specify the signature of the function you want to break on, as in
6149@kbd{break @var{function}(@var{types})}. In Ada, using the fully
6150qualified name of your function often makes the expression unambiguous
6151as well.
6152
6153When an ambiguity that needs to be resolved is detected, the debugger
6154has the capability to display a menu of numbered choices for each
6155possibility, and then waits for the selection with the prompt @samp{>}.
6156The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
6157aborts the current command. If the command in which the expression was
6158used allows more than one choice to be selected, the next option in the
6159menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
6160choices.
6161
6162For example, the following session excerpt shows an attempt to set a
6163breakpoint at the overloaded symbol @code{String::after}.
6164We choose three particular definitions of that function name:
6165
6166@c FIXME! This is likely to change to show arg type lists, at least
6167@smallexample
6168@group
6169(@value{GDBP}) b String::after
6170[0] cancel
6171[1] all
6172[2] file:String.cc; line number:867
6173[3] file:String.cc; line number:860
6174[4] file:String.cc; line number:875
6175[5] file:String.cc; line number:853
6176[6] file:String.cc; line number:846
6177[7] file:String.cc; line number:735
6178> 2 4 6
6179Breakpoint 1 at 0xb26c: file String.cc, line 867.
6180Breakpoint 2 at 0xb344: file String.cc, line 875.
6181Breakpoint 3 at 0xafcc: file String.cc, line 846.
6182Multiple breakpoints were set.
6183Use the "delete" command to delete unwanted
6184 breakpoints.
6185(@value{GDBP})
6186@end group
6187@end smallexample
6188
6189@table @code
6190@kindex set multiple-symbols
6191@item set multiple-symbols @var{mode}
6192@cindex multiple-symbols menu
6193
6194This option allows you to adjust the debugger behavior when an expression
6195is ambiguous.
6196
6197By default, @var{mode} is set to @code{all}. If the command with which
6198the expression is used allows more than one choice, then @value{GDBN}
6199automatically selects all possible choices. For instance, inserting
6200a breakpoint on a function using an ambiguous name results in a breakpoint
6201inserted on each possible match. However, if a unique choice must be made,
6202then @value{GDBN} uses the menu to help you disambiguate the expression.
6203For instance, printing the address of an overloaded function will result
6204in the use of the menu.
6205
6206When @var{mode} is set to @code{ask}, the debugger always uses the menu
6207when an ambiguity is detected.
6208
6209Finally, when @var{mode} is set to @code{cancel}, the debugger reports
6210an error due to the ambiguity and the command is aborted.
6211
6212@kindex show multiple-symbols
6213@item show multiple-symbols
6214Show the current value of the @code{multiple-symbols} setting.
6215@end table
6216
6d2ebf8b 6217@node Variables
79a6e687 6218@section Program Variables
c906108c
SS
6219
6220The most common kind of expression to use is the name of a variable
6221in your program.
6222
6223Variables in expressions are understood in the selected stack frame
79a6e687 6224(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
6225
6226@itemize @bullet
6227@item
6228global (or file-static)
6229@end itemize
6230
5d161b24 6231@noindent or
c906108c
SS
6232
6233@itemize @bullet
6234@item
6235visible according to the scope rules of the
6236programming language from the point of execution in that frame
5d161b24 6237@end itemize
c906108c
SS
6238
6239@noindent This means that in the function
6240
474c8240 6241@smallexample
c906108c
SS
6242foo (a)
6243 int a;
6244@{
6245 bar (a);
6246 @{
6247 int b = test ();
6248 bar (b);
6249 @}
6250@}
474c8240 6251@end smallexample
c906108c
SS
6252
6253@noindent
6254you can examine and use the variable @code{a} whenever your program is
6255executing within the function @code{foo}, but you can only use or
6256examine the variable @code{b} while your program is executing inside
6257the block where @code{b} is declared.
6258
6259@cindex variable name conflict
6260There is an exception: you can refer to a variable or function whose
6261scope is a single source file even if the current execution point is not
6262in this file. But it is possible to have more than one such variable or
6263function with the same name (in different source files). If that
6264happens, referring to that name has unpredictable effects. If you wish,
6265you can specify a static variable in a particular function or file,
15387254 6266using the colon-colon (@code{::}) notation:
c906108c 6267
d4f3574e 6268@cindex colon-colon, context for variables/functions
12c27660 6269@ifnotinfo
c906108c 6270@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 6271@cindex @code{::}, context for variables/functions
12c27660 6272@end ifnotinfo
474c8240 6273@smallexample
c906108c
SS
6274@var{file}::@var{variable}
6275@var{function}::@var{variable}
474c8240 6276@end smallexample
c906108c
SS
6277
6278@noindent
6279Here @var{file} or @var{function} is the name of the context for the
6280static @var{variable}. In the case of file names, you can use quotes to
6281make sure @value{GDBN} parses the file name as a single word---for example,
6282to print a global value of @code{x} defined in @file{f2.c}:
6283
474c8240 6284@smallexample
c906108c 6285(@value{GDBP}) p 'f2.c'::x
474c8240 6286@end smallexample
c906108c 6287
b37052ae 6288@cindex C@t{++} scope resolution
c906108c 6289This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 6290use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
6291scope resolution operator in @value{GDBN} expressions.
6292@c FIXME: Um, so what happens in one of those rare cases where it's in
6293@c conflict?? --mew
c906108c
SS
6294
6295@cindex wrong values
6296@cindex variable values, wrong
15387254
EZ
6297@cindex function entry/exit, wrong values of variables
6298@cindex optimized code, wrong values of variables
c906108c
SS
6299@quotation
6300@emph{Warning:} Occasionally, a local variable may appear to have the
6301wrong value at certain points in a function---just after entry to a new
6302scope, and just before exit.
6303@end quotation
6304You may see this problem when you are stepping by machine instructions.
6305This is because, on most machines, it takes more than one instruction to
6306set up a stack frame (including local variable definitions); if you are
6307stepping by machine instructions, variables may appear to have the wrong
6308values until the stack frame is completely built. On exit, it usually
6309also takes more than one machine instruction to destroy a stack frame;
6310after you begin stepping through that group of instructions, local
6311variable definitions may be gone.
6312
6313This may also happen when the compiler does significant optimizations.
6314To be sure of always seeing accurate values, turn off all optimization
6315when compiling.
6316
d4f3574e
SS
6317@cindex ``No symbol "foo" in current context''
6318Another possible effect of compiler optimizations is to optimize
6319unused variables out of existence, or assign variables to registers (as
6320opposed to memory addresses). Depending on the support for such cases
6321offered by the debug info format used by the compiler, @value{GDBN}
6322might not be able to display values for such local variables. If that
6323happens, @value{GDBN} will print a message like this:
6324
474c8240 6325@smallexample
d4f3574e 6326No symbol "foo" in current context.
474c8240 6327@end smallexample
d4f3574e
SS
6328
6329To solve such problems, either recompile without optimizations, or use a
6330different debug info format, if the compiler supports several such
15387254 6331formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
6332usually supports the @option{-gstabs+} option. @option{-gstabs+}
6333produces debug info in a format that is superior to formats such as
6334COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
6335an effective form for debug info. @xref{Debugging Options,,Options
ce9341a1
BW
6336for Debugging Your Program or GCC, gcc.info, Using the @sc{gnu}
6337Compiler Collection (GCC)}.
79a6e687 6338@xref{C, ,C and C@t{++}}, for more information about debug info formats
15387254 6339that are best suited to C@t{++} programs.
d4f3574e 6340
ab1adacd
EZ
6341If you ask to print an object whose contents are unknown to
6342@value{GDBN}, e.g., because its data type is not completely specified
6343by the debug information, @value{GDBN} will say @samp{<incomplete
6344type>}. @xref{Symbols, incomplete type}, for more about this.
6345
3a60f64e
JK
6346Strings are identified as arrays of @code{char} values without specified
6347signedness. Arrays of either @code{signed char} or @code{unsigned char} get
6348printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
6349@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
6350defines literal string type @code{"char"} as @code{char} without a sign.
6351For program code
6352
6353@smallexample
6354char var0[] = "A";
6355signed char var1[] = "A";
6356@end smallexample
6357
6358You get during debugging
6359@smallexample
6360(gdb) print var0
6361$1 = "A"
6362(gdb) print var1
6363$2 = @{65 'A', 0 '\0'@}
6364@end smallexample
6365
6d2ebf8b 6366@node Arrays
79a6e687 6367@section Artificial Arrays
c906108c
SS
6368
6369@cindex artificial array
15387254 6370@cindex arrays
41afff9a 6371@kindex @@@r{, referencing memory as an array}
c906108c
SS
6372It is often useful to print out several successive objects of the
6373same type in memory; a section of an array, or an array of
6374dynamically determined size for which only a pointer exists in the
6375program.
6376
6377You can do this by referring to a contiguous span of memory as an
6378@dfn{artificial array}, using the binary operator @samp{@@}. The left
6379operand of @samp{@@} should be the first element of the desired array
6380and be an individual object. The right operand should be the desired length
6381of the array. The result is an array value whose elements are all of
6382the type of the left argument. The first element is actually the left
6383argument; the second element comes from bytes of memory immediately
6384following those that hold the first element, and so on. Here is an
6385example. If a program says
6386
474c8240 6387@smallexample
c906108c 6388int *array = (int *) malloc (len * sizeof (int));
474c8240 6389@end smallexample
c906108c
SS
6390
6391@noindent
6392you can print the contents of @code{array} with
6393
474c8240 6394@smallexample
c906108c 6395p *array@@len
474c8240 6396@end smallexample
c906108c
SS
6397
6398The left operand of @samp{@@} must reside in memory. Array values made
6399with @samp{@@} in this way behave just like other arrays in terms of
6400subscripting, and are coerced to pointers when used in expressions.
6401Artificial arrays most often appear in expressions via the value history
79a6e687 6402(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
6403
6404Another way to create an artificial array is to use a cast.
6405This re-interprets a value as if it were an array.
6406The value need not be in memory:
474c8240 6407@smallexample
c906108c
SS
6408(@value{GDBP}) p/x (short[2])0x12345678
6409$1 = @{0x1234, 0x5678@}
474c8240 6410@end smallexample
c906108c
SS
6411
6412As a convenience, if you leave the array length out (as in
c3f6f71d 6413@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 6414the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 6415@smallexample
c906108c
SS
6416(@value{GDBP}) p/x (short[])0x12345678
6417$2 = @{0x1234, 0x5678@}
474c8240 6418@end smallexample
c906108c
SS
6419
6420Sometimes the artificial array mechanism is not quite enough; in
6421moderately complex data structures, the elements of interest may not
6422actually be adjacent---for example, if you are interested in the values
6423of pointers in an array. One useful work-around in this situation is
6424to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 6425Variables}) as a counter in an expression that prints the first
c906108c
SS
6426interesting value, and then repeat that expression via @key{RET}. For
6427instance, suppose you have an array @code{dtab} of pointers to
6428structures, and you are interested in the values of a field @code{fv}
6429in each structure. Here is an example of what you might type:
6430
474c8240 6431@smallexample
c906108c
SS
6432set $i = 0
6433p dtab[$i++]->fv
6434@key{RET}
6435@key{RET}
6436@dots{}
474c8240 6437@end smallexample
c906108c 6438
6d2ebf8b 6439@node Output Formats
79a6e687 6440@section Output Formats
c906108c
SS
6441
6442@cindex formatted output
6443@cindex output formats
6444By default, @value{GDBN} prints a value according to its data type. Sometimes
6445this is not what you want. For example, you might want to print a number
6446in hex, or a pointer in decimal. Or you might want to view data in memory
6447at a certain address as a character string or as an instruction. To do
6448these things, specify an @dfn{output format} when you print a value.
6449
6450The simplest use of output formats is to say how to print a value
6451already computed. This is done by starting the arguments of the
6452@code{print} command with a slash and a format letter. The format
6453letters supported are:
6454
6455@table @code
6456@item x
6457Regard the bits of the value as an integer, and print the integer in
6458hexadecimal.
6459
6460@item d
6461Print as integer in signed decimal.
6462
6463@item u
6464Print as integer in unsigned decimal.
6465
6466@item o
6467Print as integer in octal.
6468
6469@item t
6470Print as integer in binary. The letter @samp{t} stands for ``two''.
6471@footnote{@samp{b} cannot be used because these format letters are also
6472used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 6473see @ref{Memory,,Examining Memory}.}
c906108c
SS
6474
6475@item a
6476@cindex unknown address, locating
3d67e040 6477@cindex locate address
c906108c
SS
6478Print as an address, both absolute in hexadecimal and as an offset from
6479the nearest preceding symbol. You can use this format used to discover
6480where (in what function) an unknown address is located:
6481
474c8240 6482@smallexample
c906108c
SS
6483(@value{GDBP}) p/a 0x54320
6484$3 = 0x54320 <_initialize_vx+396>
474c8240 6485@end smallexample
c906108c 6486
3d67e040
EZ
6487@noindent
6488The command @code{info symbol 0x54320} yields similar results.
6489@xref{Symbols, info symbol}.
6490
c906108c 6491@item c
51274035
EZ
6492Regard as an integer and print it as a character constant. This
6493prints both the numerical value and its character representation. The
6494character representation is replaced with the octal escape @samp{\nnn}
6495for characters outside the 7-bit @sc{ascii} range.
c906108c 6496
ea37ba09
DJ
6497Without this format, @value{GDBN} displays @code{char},
6498@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
6499constants. Single-byte members of vectors are displayed as integer
6500data.
6501
c906108c
SS
6502@item f
6503Regard the bits of the value as a floating point number and print
6504using typical floating point syntax.
ea37ba09
DJ
6505
6506@item s
6507@cindex printing strings
6508@cindex printing byte arrays
6509Regard as a string, if possible. With this format, pointers to single-byte
6510data are displayed as null-terminated strings and arrays of single-byte data
6511are displayed as fixed-length strings. Other values are displayed in their
6512natural types.
6513
6514Without this format, @value{GDBN} displays pointers to and arrays of
6515@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
6516strings. Single-byte members of a vector are displayed as an integer
6517array.
c906108c
SS
6518@end table
6519
6520For example, to print the program counter in hex (@pxref{Registers}), type
6521
474c8240 6522@smallexample
c906108c 6523p/x $pc
474c8240 6524@end smallexample
c906108c
SS
6525
6526@noindent
6527Note that no space is required before the slash; this is because command
6528names in @value{GDBN} cannot contain a slash.
6529
6530To reprint the last value in the value history with a different format,
6531you can use the @code{print} command with just a format and no
6532expression. For example, @samp{p/x} reprints the last value in hex.
6533
6d2ebf8b 6534@node Memory
79a6e687 6535@section Examining Memory
c906108c
SS
6536
6537You can use the command @code{x} (for ``examine'') to examine memory in
6538any of several formats, independently of your program's data types.
6539
6540@cindex examining memory
6541@table @code
41afff9a 6542@kindex x @r{(examine memory)}
c906108c
SS
6543@item x/@var{nfu} @var{addr}
6544@itemx x @var{addr}
6545@itemx x
6546Use the @code{x} command to examine memory.
6547@end table
6548
6549@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
6550much memory to display and how to format it; @var{addr} is an
6551expression giving the address where you want to start displaying memory.
6552If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
6553Several commands set convenient defaults for @var{addr}.
6554
6555@table @r
6556@item @var{n}, the repeat count
6557The repeat count is a decimal integer; the default is 1. It specifies
6558how much memory (counting by units @var{u}) to display.
6559@c This really is **decimal**; unaffected by 'set radix' as of GDB
6560@c 4.1.2.
6561
6562@item @var{f}, the display format
51274035
EZ
6563The display format is one of the formats used by @code{print}
6564(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
6565@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
6566The default is @samp{x} (hexadecimal) initially. The default changes
6567each time you use either @code{x} or @code{print}.
c906108c
SS
6568
6569@item @var{u}, the unit size
6570The unit size is any of
6571
6572@table @code
6573@item b
6574Bytes.
6575@item h
6576Halfwords (two bytes).
6577@item w
6578Words (four bytes). This is the initial default.
6579@item g
6580Giant words (eight bytes).
6581@end table
6582
6583Each time you specify a unit size with @code{x}, that size becomes the
6584default unit the next time you use @code{x}. (For the @samp{s} and
6585@samp{i} formats, the unit size is ignored and is normally not written.)
6586
6587@item @var{addr}, starting display address
6588@var{addr} is the address where you want @value{GDBN} to begin displaying
6589memory. The expression need not have a pointer value (though it may);
6590it is always interpreted as an integer address of a byte of memory.
6591@xref{Expressions, ,Expressions}, for more information on expressions. The default for
6592@var{addr} is usually just after the last address examined---but several
6593other commands also set the default address: @code{info breakpoints} (to
6594the address of the last breakpoint listed), @code{info line} (to the
6595starting address of a line), and @code{print} (if you use it to display
6596a value from memory).
6597@end table
6598
6599For example, @samp{x/3uh 0x54320} is a request to display three halfwords
6600(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
6601starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
6602words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 6603@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
6604
6605Since the letters indicating unit sizes are all distinct from the
6606letters specifying output formats, you do not have to remember whether
6607unit size or format comes first; either order works. The output
6608specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
6609(However, the count @var{n} must come first; @samp{wx4} does not work.)
6610
6611Even though the unit size @var{u} is ignored for the formats @samp{s}
6612and @samp{i}, you might still want to use a count @var{n}; for example,
6613@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
6614including any operands. For convenience, especially when used with
6615the @code{display} command, the @samp{i} format also prints branch delay
6616slot instructions, if any, beyond the count specified, which immediately
6617follow the last instruction that is within the count. The command
6618@code{disassemble} gives an alternative way of inspecting machine
6619instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
6620
6621All the defaults for the arguments to @code{x} are designed to make it
6622easy to continue scanning memory with minimal specifications each time
6623you use @code{x}. For example, after you have inspected three machine
6624instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
6625with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
6626the repeat count @var{n} is used again; the other arguments default as
6627for successive uses of @code{x}.
6628
6629@cindex @code{$_}, @code{$__}, and value history
6630The addresses and contents printed by the @code{x} command are not saved
6631in the value history because there is often too much of them and they
6632would get in the way. Instead, @value{GDBN} makes these values available for
6633subsequent use in expressions as values of the convenience variables
6634@code{$_} and @code{$__}. After an @code{x} command, the last address
6635examined is available for use in expressions in the convenience variable
6636@code{$_}. The contents of that address, as examined, are available in
6637the convenience variable @code{$__}.
6638
6639If the @code{x} command has a repeat count, the address and contents saved
6640are from the last memory unit printed; this is not the same as the last
6641address printed if several units were printed on the last line of output.
6642
09d4efe1
EZ
6643@cindex remote memory comparison
6644@cindex verify remote memory image
6645When you are debugging a program running on a remote target machine
ea35711c 6646(@pxref{Remote Debugging}), you may wish to verify the program's image in the
09d4efe1
EZ
6647remote machine's memory against the executable file you downloaded to
6648the target. The @code{compare-sections} command is provided for such
6649situations.
6650
6651@table @code
6652@kindex compare-sections
6653@item compare-sections @r{[}@var{section-name}@r{]}
6654Compare the data of a loadable section @var{section-name} in the
6655executable file of the program being debugged with the same section in
6656the remote machine's memory, and report any mismatches. With no
6657arguments, compares all loadable sections. This command's
6658availability depends on the target's support for the @code{"qCRC"}
6659remote request.
6660@end table
6661
6d2ebf8b 6662@node Auto Display
79a6e687 6663@section Automatic Display
c906108c
SS
6664@cindex automatic display
6665@cindex display of expressions
6666
6667If you find that you want to print the value of an expression frequently
6668(to see how it changes), you might want to add it to the @dfn{automatic
6669display list} so that @value{GDBN} prints its value each time your program stops.
6670Each expression added to the list is given a number to identify it;
6671to remove an expression from the list, you specify that number.
6672The automatic display looks like this:
6673
474c8240 6674@smallexample
c906108c
SS
66752: foo = 38
66763: bar[5] = (struct hack *) 0x3804
474c8240 6677@end smallexample
c906108c
SS
6678
6679@noindent
6680This display shows item numbers, expressions and their current values. As with
6681displays you request manually using @code{x} or @code{print}, you can
6682specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
6683whether to use @code{print} or @code{x} depending your format
6684specification---it uses @code{x} if you specify either the @samp{i}
6685or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
6686
6687@table @code
6688@kindex display
d4f3574e
SS
6689@item display @var{expr}
6690Add the expression @var{expr} to the list of expressions to display
c906108c
SS
6691each time your program stops. @xref{Expressions, ,Expressions}.
6692
6693@code{display} does not repeat if you press @key{RET} again after using it.
6694
d4f3574e 6695@item display/@var{fmt} @var{expr}
c906108c 6696For @var{fmt} specifying only a display format and not a size or
d4f3574e 6697count, add the expression @var{expr} to the auto-display list but
c906108c 6698arrange to display it each time in the specified format @var{fmt}.
79a6e687 6699@xref{Output Formats,,Output Formats}.
c906108c
SS
6700
6701@item display/@var{fmt} @var{addr}
6702For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
6703number of units, add the expression @var{addr} as a memory address to
6704be examined each time your program stops. Examining means in effect
79a6e687 6705doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
6706@end table
6707
6708For example, @samp{display/i $pc} can be helpful, to see the machine
6709instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 6710is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
6711
6712@table @code
6713@kindex delete display
6714@kindex undisplay
6715@item undisplay @var{dnums}@dots{}
6716@itemx delete display @var{dnums}@dots{}
6717Remove item numbers @var{dnums} from the list of expressions to display.
6718
6719@code{undisplay} does not repeat if you press @key{RET} after using it.
6720(Otherwise you would just get the error @samp{No display number @dots{}}.)
6721
6722@kindex disable display
6723@item disable display @var{dnums}@dots{}
6724Disable the display of item numbers @var{dnums}. A disabled display
6725item is not printed automatically, but is not forgotten. It may be
6726enabled again later.
6727
6728@kindex enable display
6729@item enable display @var{dnums}@dots{}
6730Enable display of item numbers @var{dnums}. It becomes effective once
6731again in auto display of its expression, until you specify otherwise.
6732
6733@item display
6734Display the current values of the expressions on the list, just as is
6735done when your program stops.
6736
6737@kindex info display
6738@item info display
6739Print the list of expressions previously set up to display
6740automatically, each one with its item number, but without showing the
6741values. This includes disabled expressions, which are marked as such.
6742It also includes expressions which would not be displayed right now
6743because they refer to automatic variables not currently available.
6744@end table
6745
15387254 6746@cindex display disabled out of scope
c906108c
SS
6747If a display expression refers to local variables, then it does not make
6748sense outside the lexical context for which it was set up. Such an
6749expression is disabled when execution enters a context where one of its
6750variables is not defined. For example, if you give the command
6751@code{display last_char} while inside a function with an argument
6752@code{last_char}, @value{GDBN} displays this argument while your program
6753continues to stop inside that function. When it stops elsewhere---where
6754there is no variable @code{last_char}---the display is disabled
6755automatically. The next time your program stops where @code{last_char}
6756is meaningful, you can enable the display expression once again.
6757
6d2ebf8b 6758@node Print Settings
79a6e687 6759@section Print Settings
c906108c
SS
6760
6761@cindex format options
6762@cindex print settings
6763@value{GDBN} provides the following ways to control how arrays, structures,
6764and symbols are printed.
6765
6766@noindent
6767These settings are useful for debugging programs in any language:
6768
6769@table @code
4644b6e3 6770@kindex set print
c906108c
SS
6771@item set print address
6772@itemx set print address on
4644b6e3 6773@cindex print/don't print memory addresses
c906108c
SS
6774@value{GDBN} prints memory addresses showing the location of stack
6775traces, structure values, pointer values, breakpoints, and so forth,
6776even when it also displays the contents of those addresses. The default
6777is @code{on}. For example, this is what a stack frame display looks like with
6778@code{set print address on}:
6779
6780@smallexample
6781@group
6782(@value{GDBP}) f
6783#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
6784 at input.c:530
6785530 if (lquote != def_lquote)
6786@end group
6787@end smallexample
6788
6789@item set print address off
6790Do not print addresses when displaying their contents. For example,
6791this is the same stack frame displayed with @code{set print address off}:
6792
6793@smallexample
6794@group
6795(@value{GDBP}) set print addr off
6796(@value{GDBP}) f
6797#0 set_quotes (lq="<<", rq=">>") at input.c:530
6798530 if (lquote != def_lquote)
6799@end group
6800@end smallexample
6801
6802You can use @samp{set print address off} to eliminate all machine
6803dependent displays from the @value{GDBN} interface. For example, with
6804@code{print address off}, you should get the same text for backtraces on
6805all machines---whether or not they involve pointer arguments.
6806
4644b6e3 6807@kindex show print
c906108c
SS
6808@item show print address
6809Show whether or not addresses are to be printed.
6810@end table
6811
6812When @value{GDBN} prints a symbolic address, it normally prints the
6813closest earlier symbol plus an offset. If that symbol does not uniquely
6814identify the address (for example, it is a name whose scope is a single
6815source file), you may need to clarify. One way to do this is with
6816@code{info line}, for example @samp{info line *0x4537}. Alternately,
6817you can set @value{GDBN} to print the source file and line number when
6818it prints a symbolic address:
6819
6820@table @code
c906108c 6821@item set print symbol-filename on
9c16f35a
EZ
6822@cindex source file and line of a symbol
6823@cindex symbol, source file and line
c906108c
SS
6824Tell @value{GDBN} to print the source file name and line number of a
6825symbol in the symbolic form of an address.
6826
6827@item set print symbol-filename off
6828Do not print source file name and line number of a symbol. This is the
6829default.
6830
c906108c
SS
6831@item show print symbol-filename
6832Show whether or not @value{GDBN} will print the source file name and
6833line number of a symbol in the symbolic form of an address.
6834@end table
6835
6836Another situation where it is helpful to show symbol filenames and line
6837numbers is when disassembling code; @value{GDBN} shows you the line
6838number and source file that corresponds to each instruction.
6839
6840Also, you may wish to see the symbolic form only if the address being
6841printed is reasonably close to the closest earlier symbol:
6842
6843@table @code
c906108c 6844@item set print max-symbolic-offset @var{max-offset}
4644b6e3 6845@cindex maximum value for offset of closest symbol
c906108c
SS
6846Tell @value{GDBN} to only display the symbolic form of an address if the
6847offset between the closest earlier symbol and the address is less than
5d161b24 6848@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
6849to always print the symbolic form of an address if any symbol precedes it.
6850
c906108c
SS
6851@item show print max-symbolic-offset
6852Ask how large the maximum offset is that @value{GDBN} prints in a
6853symbolic address.
6854@end table
6855
6856@cindex wild pointer, interpreting
6857@cindex pointer, finding referent
6858If you have a pointer and you are not sure where it points, try
6859@samp{set print symbol-filename on}. Then you can determine the name
6860and source file location of the variable where it points, using
6861@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
6862For example, here @value{GDBN} shows that a variable @code{ptt} points
6863at another variable @code{t}, defined in @file{hi2.c}:
6864
474c8240 6865@smallexample
c906108c
SS
6866(@value{GDBP}) set print symbol-filename on
6867(@value{GDBP}) p/a ptt
6868$4 = 0xe008 <t in hi2.c>
474c8240 6869@end smallexample
c906108c
SS
6870
6871@quotation
6872@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
6873does not show the symbol name and filename of the referent, even with
6874the appropriate @code{set print} options turned on.
6875@end quotation
6876
6877Other settings control how different kinds of objects are printed:
6878
6879@table @code
c906108c
SS
6880@item set print array
6881@itemx set print array on
4644b6e3 6882@cindex pretty print arrays
c906108c
SS
6883Pretty print arrays. This format is more convenient to read,
6884but uses more space. The default is off.
6885
6886@item set print array off
6887Return to compressed format for arrays.
6888
c906108c
SS
6889@item show print array
6890Show whether compressed or pretty format is selected for displaying
6891arrays.
6892
3c9c013a
JB
6893@cindex print array indexes
6894@item set print array-indexes
6895@itemx set print array-indexes on
6896Print the index of each element when displaying arrays. May be more
6897convenient to locate a given element in the array or quickly find the
6898index of a given element in that printed array. The default is off.
6899
6900@item set print array-indexes off
6901Stop printing element indexes when displaying arrays.
6902
6903@item show print array-indexes
6904Show whether the index of each element is printed when displaying
6905arrays.
6906
c906108c 6907@item set print elements @var{number-of-elements}
4644b6e3 6908@cindex number of array elements to print
9c16f35a 6909@cindex limit on number of printed array elements
c906108c
SS
6910Set a limit on how many elements of an array @value{GDBN} will print.
6911If @value{GDBN} is printing a large array, it stops printing after it has
6912printed the number of elements set by the @code{set print elements} command.
6913This limit also applies to the display of strings.
d4f3574e 6914When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
6915Setting @var{number-of-elements} to zero means that the printing is unlimited.
6916
c906108c
SS
6917@item show print elements
6918Display the number of elements of a large array that @value{GDBN} will print.
6919If the number is 0, then the printing is unlimited.
6920
b4740add
JB
6921@item set print frame-arguments @var{value}
6922@cindex printing frame argument values
6923@cindex print all frame argument values
6924@cindex print frame argument values for scalars only
6925@cindex do not print frame argument values
6926This command allows to control how the values of arguments are printed
6927when the debugger prints a frame (@pxref{Frames}). The possible
6928values are:
6929
6930@table @code
6931@item all
6932The values of all arguments are printed. This is the default.
6933
6934@item scalars
6935Print the value of an argument only if it is a scalar. The value of more
6936complex arguments such as arrays, structures, unions, etc, is replaced
6937by @code{@dots{}}. Here is an example where only scalar arguments are shown:
6938
6939@smallexample
6940#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
6941 at frame-args.c:23
6942@end smallexample
6943
6944@item none
6945None of the argument values are printed. Instead, the value of each argument
6946is replaced by @code{@dots{}}. In this case, the example above now becomes:
6947
6948@smallexample
6949#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
6950 at frame-args.c:23
6951@end smallexample
6952@end table
6953
6954By default, all argument values are always printed. But this command
6955can be useful in several cases. For instance, it can be used to reduce
6956the amount of information printed in each frame, making the backtrace
6957more readable. Also, this command can be used to improve performance
6958when displaying Ada frames, because the computation of large arguments
6959can sometimes be CPU-intensive, especiallly in large applications.
6960Setting @code{print frame-arguments} to @code{scalars} or @code{none}
6961avoids this computation, thus speeding up the display of each Ada frame.
6962
6963@item show print frame-arguments
6964Show how the value of arguments should be displayed when printing a frame.
6965
9c16f35a
EZ
6966@item set print repeats
6967@cindex repeated array elements
6968Set the threshold for suppressing display of repeated array
d3e8051b 6969elements. When the number of consecutive identical elements of an
9c16f35a
EZ
6970array exceeds the threshold, @value{GDBN} prints the string
6971@code{"<repeats @var{n} times>"}, where @var{n} is the number of
6972identical repetitions, instead of displaying the identical elements
6973themselves. Setting the threshold to zero will cause all elements to
6974be individually printed. The default threshold is 10.
6975
6976@item show print repeats
6977Display the current threshold for printing repeated identical
6978elements.
6979
c906108c 6980@item set print null-stop
4644b6e3 6981@cindex @sc{null} elements in arrays
c906108c 6982Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 6983@sc{null} is encountered. This is useful when large arrays actually
c906108c 6984contain only short strings.
d4f3574e 6985The default is off.
c906108c 6986
9c16f35a
EZ
6987@item show print null-stop
6988Show whether @value{GDBN} stops printing an array on the first
6989@sc{null} character.
6990
c906108c 6991@item set print pretty on
9c16f35a
EZ
6992@cindex print structures in indented form
6993@cindex indentation in structure display
5d161b24 6994Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
6995per line, like this:
6996
6997@smallexample
6998@group
6999$1 = @{
7000 next = 0x0,
7001 flags = @{
7002 sweet = 1,
7003 sour = 1
7004 @},
7005 meat = 0x54 "Pork"
7006@}
7007@end group
7008@end smallexample
7009
7010@item set print pretty off
7011Cause @value{GDBN} to print structures in a compact format, like this:
7012
7013@smallexample
7014@group
7015$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
7016meat = 0x54 "Pork"@}
7017@end group
7018@end smallexample
7019
7020@noindent
7021This is the default format.
7022
c906108c
SS
7023@item show print pretty
7024Show which format @value{GDBN} is using to print structures.
7025
c906108c 7026@item set print sevenbit-strings on
4644b6e3
EZ
7027@cindex eight-bit characters in strings
7028@cindex octal escapes in strings
c906108c
SS
7029Print using only seven-bit characters; if this option is set,
7030@value{GDBN} displays any eight-bit characters (in strings or
7031character values) using the notation @code{\}@var{nnn}. This setting is
7032best if you are working in English (@sc{ascii}) and you use the
7033high-order bit of characters as a marker or ``meta'' bit.
7034
7035@item set print sevenbit-strings off
7036Print full eight-bit characters. This allows the use of more
7037international character sets, and is the default.
7038
c906108c
SS
7039@item show print sevenbit-strings
7040Show whether or not @value{GDBN} is printing only seven-bit characters.
7041
c906108c 7042@item set print union on
4644b6e3 7043@cindex unions in structures, printing
9c16f35a
EZ
7044Tell @value{GDBN} to print unions which are contained in structures
7045and other unions. This is the default setting.
c906108c
SS
7046
7047@item set print union off
9c16f35a
EZ
7048Tell @value{GDBN} not to print unions which are contained in
7049structures and other unions. @value{GDBN} will print @code{"@{...@}"}
7050instead.
c906108c 7051
c906108c
SS
7052@item show print union
7053Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 7054structures and other unions.
c906108c
SS
7055
7056For example, given the declarations
7057
7058@smallexample
7059typedef enum @{Tree, Bug@} Species;
7060typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 7061typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
7062 Bug_forms;
7063
7064struct thing @{
7065 Species it;
7066 union @{
7067 Tree_forms tree;
7068 Bug_forms bug;
7069 @} form;
7070@};
7071
7072struct thing foo = @{Tree, @{Acorn@}@};
7073@end smallexample
7074
7075@noindent
7076with @code{set print union on} in effect @samp{p foo} would print
7077
7078@smallexample
7079$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
7080@end smallexample
7081
7082@noindent
7083and with @code{set print union off} in effect it would print
7084
7085@smallexample
7086$1 = @{it = Tree, form = @{...@}@}
7087@end smallexample
9c16f35a
EZ
7088
7089@noindent
7090@code{set print union} affects programs written in C-like languages
7091and in Pascal.
c906108c
SS
7092@end table
7093
c906108c
SS
7094@need 1000
7095@noindent
b37052ae 7096These settings are of interest when debugging C@t{++} programs:
c906108c
SS
7097
7098@table @code
4644b6e3 7099@cindex demangling C@t{++} names
c906108c
SS
7100@item set print demangle
7101@itemx set print demangle on
b37052ae 7102Print C@t{++} names in their source form rather than in the encoded
c906108c 7103(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 7104linkage. The default is on.
c906108c 7105
c906108c 7106@item show print demangle
b37052ae 7107Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 7108
c906108c
SS
7109@item set print asm-demangle
7110@itemx set print asm-demangle on
b37052ae 7111Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
7112in assembler code printouts such as instruction disassemblies.
7113The default is off.
7114
c906108c 7115@item show print asm-demangle
b37052ae 7116Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
7117or demangled form.
7118
b37052ae
EZ
7119@cindex C@t{++} symbol decoding style
7120@cindex symbol decoding style, C@t{++}
a8f24a35 7121@kindex set demangle-style
c906108c
SS
7122@item set demangle-style @var{style}
7123Choose among several encoding schemes used by different compilers to
b37052ae 7124represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
7125
7126@table @code
7127@item auto
7128Allow @value{GDBN} to choose a decoding style by inspecting your program.
7129
7130@item gnu
b37052ae 7131Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 7132This is the default.
c906108c
SS
7133
7134@item hp
b37052ae 7135Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
7136
7137@item lucid
b37052ae 7138Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
7139
7140@item arm
b37052ae 7141Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
7142@strong{Warning:} this setting alone is not sufficient to allow
7143debugging @code{cfront}-generated executables. @value{GDBN} would
7144require further enhancement to permit that.
7145
7146@end table
7147If you omit @var{style}, you will see a list of possible formats.
7148
c906108c 7149@item show demangle-style
b37052ae 7150Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 7151
c906108c
SS
7152@item set print object
7153@itemx set print object on
4644b6e3 7154@cindex derived type of an object, printing
9c16f35a 7155@cindex display derived types
c906108c
SS
7156When displaying a pointer to an object, identify the @emph{actual}
7157(derived) type of the object rather than the @emph{declared} type, using
7158the virtual function table.
7159
7160@item set print object off
7161Display only the declared type of objects, without reference to the
7162virtual function table. This is the default setting.
7163
c906108c
SS
7164@item show print object
7165Show whether actual, or declared, object types are displayed.
7166
c906108c
SS
7167@item set print static-members
7168@itemx set print static-members on
4644b6e3 7169@cindex static members of C@t{++} objects
b37052ae 7170Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
7171
7172@item set print static-members off
b37052ae 7173Do not print static members when displaying a C@t{++} object.
c906108c 7174
c906108c 7175@item show print static-members
9c16f35a
EZ
7176Show whether C@t{++} static members are printed or not.
7177
7178@item set print pascal_static-members
7179@itemx set print pascal_static-members on
d3e8051b
EZ
7180@cindex static members of Pascal objects
7181@cindex Pascal objects, static members display
9c16f35a
EZ
7182Print static members when displaying a Pascal object. The default is on.
7183
7184@item set print pascal_static-members off
7185Do not print static members when displaying a Pascal object.
7186
7187@item show print pascal_static-members
7188Show whether Pascal static members are printed or not.
c906108c
SS
7189
7190@c These don't work with HP ANSI C++ yet.
c906108c
SS
7191@item set print vtbl
7192@itemx set print vtbl on
4644b6e3 7193@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
7194@cindex virtual functions (C@t{++}) display
7195@cindex VTBL display
b37052ae 7196Pretty print C@t{++} virtual function tables. The default is off.
c906108c 7197(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 7198ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
7199
7200@item set print vtbl off
b37052ae 7201Do not pretty print C@t{++} virtual function tables.
c906108c 7202
c906108c 7203@item show print vtbl
b37052ae 7204Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 7205@end table
c906108c 7206
6d2ebf8b 7207@node Value History
79a6e687 7208@section Value History
c906108c
SS
7209
7210@cindex value history
9c16f35a 7211@cindex history of values printed by @value{GDBN}
5d161b24
DB
7212Values printed by the @code{print} command are saved in the @value{GDBN}
7213@dfn{value history}. This allows you to refer to them in other expressions.
7214Values are kept until the symbol table is re-read or discarded
7215(for example with the @code{file} or @code{symbol-file} commands).
7216When the symbol table changes, the value history is discarded,
7217since the values may contain pointers back to the types defined in the
c906108c
SS
7218symbol table.
7219
7220@cindex @code{$}
7221@cindex @code{$$}
7222@cindex history number
7223The values printed are given @dfn{history numbers} by which you can
7224refer to them. These are successive integers starting with one.
7225@code{print} shows you the history number assigned to a value by
7226printing @samp{$@var{num} = } before the value; here @var{num} is the
7227history number.
7228
7229To refer to any previous value, use @samp{$} followed by the value's
7230history number. The way @code{print} labels its output is designed to
7231remind you of this. Just @code{$} refers to the most recent value in
7232the history, and @code{$$} refers to the value before that.
7233@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
7234is the value just prior to @code{$$}, @code{$$1} is equivalent to
7235@code{$$}, and @code{$$0} is equivalent to @code{$}.
7236
7237For example, suppose you have just printed a pointer to a structure and
7238want to see the contents of the structure. It suffices to type
7239
474c8240 7240@smallexample
c906108c 7241p *$
474c8240 7242@end smallexample
c906108c
SS
7243
7244If you have a chain of structures where the component @code{next} points
7245to the next one, you can print the contents of the next one with this:
7246
474c8240 7247@smallexample
c906108c 7248p *$.next
474c8240 7249@end smallexample
c906108c
SS
7250
7251@noindent
7252You can print successive links in the chain by repeating this
7253command---which you can do by just typing @key{RET}.
7254
7255Note that the history records values, not expressions. If the value of
7256@code{x} is 4 and you type these commands:
7257
474c8240 7258@smallexample
c906108c
SS
7259print x
7260set x=5
474c8240 7261@end smallexample
c906108c
SS
7262
7263@noindent
7264then the value recorded in the value history by the @code{print} command
7265remains 4 even though the value of @code{x} has changed.
7266
7267@table @code
7268@kindex show values
7269@item show values
7270Print the last ten values in the value history, with their item numbers.
7271This is like @samp{p@ $$9} repeated ten times, except that @code{show
7272values} does not change the history.
7273
7274@item show values @var{n}
7275Print ten history values centered on history item number @var{n}.
7276
7277@item show values +
7278Print ten history values just after the values last printed. If no more
7279values are available, @code{show values +} produces no display.
7280@end table
7281
7282Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
7283same effect as @samp{show values +}.
7284
6d2ebf8b 7285@node Convenience Vars
79a6e687 7286@section Convenience Variables
c906108c
SS
7287
7288@cindex convenience variables
9c16f35a 7289@cindex user-defined variables
c906108c
SS
7290@value{GDBN} provides @dfn{convenience variables} that you can use within
7291@value{GDBN} to hold on to a value and refer to it later. These variables
7292exist entirely within @value{GDBN}; they are not part of your program, and
7293setting a convenience variable has no direct effect on further execution
7294of your program. That is why you can use them freely.
7295
7296Convenience variables are prefixed with @samp{$}. Any name preceded by
7297@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 7298the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 7299(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 7300by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
7301
7302You can save a value in a convenience variable with an assignment
7303expression, just as you would set a variable in your program.
7304For example:
7305
474c8240 7306@smallexample
c906108c 7307set $foo = *object_ptr
474c8240 7308@end smallexample
c906108c
SS
7309
7310@noindent
7311would save in @code{$foo} the value contained in the object pointed to by
7312@code{object_ptr}.
7313
7314Using a convenience variable for the first time creates it, but its
7315value is @code{void} until you assign a new value. You can alter the
7316value with another assignment at any time.
7317
7318Convenience variables have no fixed types. You can assign a convenience
7319variable any type of value, including structures and arrays, even if
7320that variable already has a value of a different type. The convenience
7321variable, when used as an expression, has the type of its current value.
7322
7323@table @code
7324@kindex show convenience
9c16f35a 7325@cindex show all user variables
c906108c
SS
7326@item show convenience
7327Print a list of convenience variables used so far, and their values.
d4f3574e 7328Abbreviated @code{show conv}.
53e5f3cf
AS
7329
7330@kindex init-if-undefined
7331@cindex convenience variables, initializing
7332@item init-if-undefined $@var{variable} = @var{expression}
7333Set a convenience variable if it has not already been set. This is useful
7334for user-defined commands that keep some state. It is similar, in concept,
7335to using local static variables with initializers in C (except that
7336convenience variables are global). It can also be used to allow users to
7337override default values used in a command script.
7338
7339If the variable is already defined then the expression is not evaluated so
7340any side-effects do not occur.
c906108c
SS
7341@end table
7342
7343One of the ways to use a convenience variable is as a counter to be
7344incremented or a pointer to be advanced. For example, to print
7345a field from successive elements of an array of structures:
7346
474c8240 7347@smallexample
c906108c
SS
7348set $i = 0
7349print bar[$i++]->contents
474c8240 7350@end smallexample
c906108c 7351
d4f3574e
SS
7352@noindent
7353Repeat that command by typing @key{RET}.
c906108c
SS
7354
7355Some convenience variables are created automatically by @value{GDBN} and given
7356values likely to be useful.
7357
7358@table @code
41afff9a 7359@vindex $_@r{, convenience variable}
c906108c
SS
7360@item $_
7361The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 7362the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
7363commands which provide a default address for @code{x} to examine also
7364set @code{$_} to that address; these commands include @code{info line}
7365and @code{info breakpoint}. The type of @code{$_} is @code{void *}
7366except when set by the @code{x} command, in which case it is a pointer
7367to the type of @code{$__}.
7368
41afff9a 7369@vindex $__@r{, convenience variable}
c906108c
SS
7370@item $__
7371The variable @code{$__} is automatically set by the @code{x} command
7372to the value found in the last address examined. Its type is chosen
7373to match the format in which the data was printed.
7374
7375@item $_exitcode
41afff9a 7376@vindex $_exitcode@r{, convenience variable}
c906108c
SS
7377The variable @code{$_exitcode} is automatically set to the exit code when
7378the program being debugged terminates.
7379@end table
7380
53a5351d
JM
7381On HP-UX systems, if you refer to a function or variable name that
7382begins with a dollar sign, @value{GDBN} searches for a user or system
7383name first, before it searches for a convenience variable.
c906108c 7384
6d2ebf8b 7385@node Registers
c906108c
SS
7386@section Registers
7387
7388@cindex registers
7389You can refer to machine register contents, in expressions, as variables
7390with names starting with @samp{$}. The names of registers are different
7391for each machine; use @code{info registers} to see the names used on
7392your machine.
7393
7394@table @code
7395@kindex info registers
7396@item info registers
7397Print the names and values of all registers except floating-point
c85508ee 7398and vector registers (in the selected stack frame).
c906108c
SS
7399
7400@kindex info all-registers
7401@cindex floating point registers
7402@item info all-registers
7403Print the names and values of all registers, including floating-point
c85508ee 7404and vector registers (in the selected stack frame).
c906108c
SS
7405
7406@item info registers @var{regname} @dots{}
7407Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
7408As discussed in detail below, register values are normally relative to
7409the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
7410the machine you are using, with or without the initial @samp{$}.
7411@end table
7412
e09f16f9
EZ
7413@cindex stack pointer register
7414@cindex program counter register
7415@cindex process status register
7416@cindex frame pointer register
7417@cindex standard registers
c906108c
SS
7418@value{GDBN} has four ``standard'' register names that are available (in
7419expressions) on most machines---whenever they do not conflict with an
7420architecture's canonical mnemonics for registers. The register names
7421@code{$pc} and @code{$sp} are used for the program counter register and
7422the stack pointer. @code{$fp} is used for a register that contains a
7423pointer to the current stack frame, and @code{$ps} is used for a
7424register that contains the processor status. For example,
7425you could print the program counter in hex with
7426
474c8240 7427@smallexample
c906108c 7428p/x $pc
474c8240 7429@end smallexample
c906108c
SS
7430
7431@noindent
7432or print the instruction to be executed next with
7433
474c8240 7434@smallexample
c906108c 7435x/i $pc
474c8240 7436@end smallexample
c906108c
SS
7437
7438@noindent
7439or add four to the stack pointer@footnote{This is a way of removing
7440one word from the stack, on machines where stacks grow downward in
7441memory (most machines, nowadays). This assumes that the innermost
7442stack frame is selected; setting @code{$sp} is not allowed when other
7443stack frames are selected. To pop entire frames off the stack,
7444regardless of machine architecture, use @code{return};
79a6e687 7445see @ref{Returning, ,Returning from a Function}.} with
c906108c 7446
474c8240 7447@smallexample
c906108c 7448set $sp += 4
474c8240 7449@end smallexample
c906108c
SS
7450
7451Whenever possible, these four standard register names are available on
7452your machine even though the machine has different canonical mnemonics,
7453so long as there is no conflict. The @code{info registers} command
7454shows the canonical names. For example, on the SPARC, @code{info
7455registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
7456can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
7457is an alias for the @sc{eflags} register.
c906108c
SS
7458
7459@value{GDBN} always considers the contents of an ordinary register as an
7460integer when the register is examined in this way. Some machines have
7461special registers which can hold nothing but floating point; these
7462registers are considered to have floating point values. There is no way
7463to refer to the contents of an ordinary register as floating point value
7464(although you can @emph{print} it as a floating point value with
7465@samp{print/f $@var{regname}}).
7466
7467Some registers have distinct ``raw'' and ``virtual'' data formats. This
7468means that the data format in which the register contents are saved by
7469the operating system is not the same one that your program normally
7470sees. For example, the registers of the 68881 floating point
7471coprocessor are always saved in ``extended'' (raw) format, but all C
7472programs expect to work with ``double'' (virtual) format. In such
5d161b24 7473cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
7474that makes sense for your program), but the @code{info registers} command
7475prints the data in both formats.
7476
36b80e65
EZ
7477@cindex SSE registers (x86)
7478@cindex MMX registers (x86)
7479Some machines have special registers whose contents can be interpreted
7480in several different ways. For example, modern x86-based machines
7481have SSE and MMX registers that can hold several values packed
7482together in several different formats. @value{GDBN} refers to such
7483registers in @code{struct} notation:
7484
7485@smallexample
7486(@value{GDBP}) print $xmm1
7487$1 = @{
7488 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
7489 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
7490 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
7491 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
7492 v4_int32 = @{0, 20657912, 11, 13@},
7493 v2_int64 = @{88725056443645952, 55834574859@},
7494 uint128 = 0x0000000d0000000b013b36f800000000
7495@}
7496@end smallexample
7497
7498@noindent
7499To set values of such registers, you need to tell @value{GDBN} which
7500view of the register you wish to change, as if you were assigning
7501value to a @code{struct} member:
7502
7503@smallexample
7504 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
7505@end smallexample
7506
c906108c 7507Normally, register values are relative to the selected stack frame
79a6e687 7508(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
7509value that the register would contain if all stack frames farther in
7510were exited and their saved registers restored. In order to see the
7511true contents of hardware registers, you must select the innermost
7512frame (with @samp{frame 0}).
7513
7514However, @value{GDBN} must deduce where registers are saved, from the machine
7515code generated by your compiler. If some registers are not saved, or if
7516@value{GDBN} is unable to locate the saved registers, the selected stack
7517frame makes no difference.
7518
6d2ebf8b 7519@node Floating Point Hardware
79a6e687 7520@section Floating Point Hardware
c906108c
SS
7521@cindex floating point
7522
7523Depending on the configuration, @value{GDBN} may be able to give
7524you more information about the status of the floating point hardware.
7525
7526@table @code
7527@kindex info float
7528@item info float
7529Display hardware-dependent information about the floating
7530point unit. The exact contents and layout vary depending on the
7531floating point chip. Currently, @samp{info float} is supported on
7532the ARM and x86 machines.
7533@end table
c906108c 7534
e76f1f2e
AC
7535@node Vector Unit
7536@section Vector Unit
7537@cindex vector unit
7538
7539Depending on the configuration, @value{GDBN} may be able to give you
7540more information about the status of the vector unit.
7541
7542@table @code
7543@kindex info vector
7544@item info vector
7545Display information about the vector unit. The exact contents and
7546layout vary depending on the hardware.
7547@end table
7548
721c2651 7549@node OS Information
79a6e687 7550@section Operating System Auxiliary Information
721c2651
EZ
7551@cindex OS information
7552
7553@value{GDBN} provides interfaces to useful OS facilities that can help
7554you debug your program.
7555
7556@cindex @code{ptrace} system call
7557@cindex @code{struct user} contents
7558When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
7559machines), it interfaces with the inferior via the @code{ptrace}
7560system call. The operating system creates a special sata structure,
7561called @code{struct user}, for this interface. You can use the
7562command @code{info udot} to display the contents of this data
7563structure.
7564
7565@table @code
7566@item info udot
7567@kindex info udot
7568Display the contents of the @code{struct user} maintained by the OS
7569kernel for the program being debugged. @value{GDBN} displays the
7570contents of @code{struct user} as a list of hex numbers, similar to
7571the @code{examine} command.
7572@end table
7573
b383017d
RM
7574@cindex auxiliary vector
7575@cindex vector, auxiliary
b383017d
RM
7576Some operating systems supply an @dfn{auxiliary vector} to programs at
7577startup. This is akin to the arguments and environment that you
7578specify for a program, but contains a system-dependent variety of
7579binary values that tell system libraries important details about the
7580hardware, operating system, and process. Each value's purpose is
7581identified by an integer tag; the meanings are well-known but system-specific.
7582Depending on the configuration and operating system facilities,
9c16f35a
EZ
7583@value{GDBN} may be able to show you this information. For remote
7584targets, this functionality may further depend on the remote stub's
427c3a89
DJ
7585support of the @samp{qXfer:auxv:read} packet, see
7586@ref{qXfer auxiliary vector read}.
b383017d
RM
7587
7588@table @code
7589@kindex info auxv
7590@item info auxv
7591Display the auxiliary vector of the inferior, which can be either a
e4937fc1 7592live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
7593numerically, and also shows names and text descriptions for recognized
7594tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 7595pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
7596most appropriate form for a recognized tag, and in hexadecimal for
7597an unrecognized tag.
7598@end table
7599
07e059b5
VP
7600On some targets, @value{GDBN} can access operating-system-specific information
7601and display it to user, without interpretation. For remote targets,
7602this functionality depends on the remote stub's support of the
7603@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
7604
7605@table @code
7606@kindex info os processes
7607@item info os processes
7608Display the list of processes on the target. For each process,
7609@value{GDBN} prints the process identifier, the name of the user, and
7610the command corresponding to the process.
7611@end table
721c2651 7612
29e57380 7613@node Memory Region Attributes
79a6e687 7614@section Memory Region Attributes
29e57380
C
7615@cindex memory region attributes
7616
b383017d 7617@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
7618required by regions of your target's memory. @value{GDBN} uses
7619attributes to determine whether to allow certain types of memory
7620accesses; whether to use specific width accesses; and whether to cache
7621target memory. By default the description of memory regions is
7622fetched from the target (if the current target supports this), but the
7623user can override the fetched regions.
29e57380
C
7624
7625Defined memory regions can be individually enabled and disabled. When a
7626memory region is disabled, @value{GDBN} uses the default attributes when
7627accessing memory in that region. Similarly, if no memory regions have
7628been defined, @value{GDBN} uses the default attributes when accessing
7629all memory.
7630
b383017d 7631When a memory region is defined, it is given a number to identify it;
29e57380
C
7632to enable, disable, or remove a memory region, you specify that number.
7633
7634@table @code
7635@kindex mem
bfac230e 7636@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
7637Define a memory region bounded by @var{lower} and @var{upper} with
7638attributes @var{attributes}@dots{}, and add it to the list of regions
7639monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 7640case: it is treated as the target's maximum memory address.
bfac230e 7641(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 7642
fd79ecee
DJ
7643@item mem auto
7644Discard any user changes to the memory regions and use target-supplied
7645regions, if available, or no regions if the target does not support.
7646
29e57380
C
7647@kindex delete mem
7648@item delete mem @var{nums}@dots{}
09d4efe1
EZ
7649Remove memory regions @var{nums}@dots{} from the list of regions
7650monitored by @value{GDBN}.
29e57380
C
7651
7652@kindex disable mem
7653@item disable mem @var{nums}@dots{}
09d4efe1 7654Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 7655A disabled memory region is not forgotten.
29e57380
C
7656It may be enabled again later.
7657
7658@kindex enable mem
7659@item enable mem @var{nums}@dots{}
09d4efe1 7660Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
7661
7662@kindex info mem
7663@item info mem
7664Print a table of all defined memory regions, with the following columns
09d4efe1 7665for each region:
29e57380
C
7666
7667@table @emph
7668@item Memory Region Number
7669@item Enabled or Disabled.
b383017d 7670Enabled memory regions are marked with @samp{y}.
29e57380
C
7671Disabled memory regions are marked with @samp{n}.
7672
7673@item Lo Address
7674The address defining the inclusive lower bound of the memory region.
7675
7676@item Hi Address
7677The address defining the exclusive upper bound of the memory region.
7678
7679@item Attributes
7680The list of attributes set for this memory region.
7681@end table
7682@end table
7683
7684
7685@subsection Attributes
7686
b383017d 7687@subsubsection Memory Access Mode
29e57380
C
7688The access mode attributes set whether @value{GDBN} may make read or
7689write accesses to a memory region.
7690
7691While these attributes prevent @value{GDBN} from performing invalid
7692memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 7693etc.@: from accessing memory.
29e57380
C
7694
7695@table @code
7696@item ro
7697Memory is read only.
7698@item wo
7699Memory is write only.
7700@item rw
6ca652b0 7701Memory is read/write. This is the default.
29e57380
C
7702@end table
7703
7704@subsubsection Memory Access Size
d3e8051b 7705The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
7706accesses in the memory region. Often memory mapped device registers
7707require specific sized accesses. If no access size attribute is
7708specified, @value{GDBN} may use accesses of any size.
7709
7710@table @code
7711@item 8
7712Use 8 bit memory accesses.
7713@item 16
7714Use 16 bit memory accesses.
7715@item 32
7716Use 32 bit memory accesses.
7717@item 64
7718Use 64 bit memory accesses.
7719@end table
7720
7721@c @subsubsection Hardware/Software Breakpoints
7722@c The hardware/software breakpoint attributes set whether @value{GDBN}
7723@c will use hardware or software breakpoints for the internal breakpoints
7724@c used by the step, next, finish, until, etc. commands.
7725@c
7726@c @table @code
7727@c @item hwbreak
b383017d 7728@c Always use hardware breakpoints
29e57380
C
7729@c @item swbreak (default)
7730@c @end table
7731
7732@subsubsection Data Cache
7733The data cache attributes set whether @value{GDBN} will cache target
7734memory. While this generally improves performance by reducing debug
7735protocol overhead, it can lead to incorrect results because @value{GDBN}
7736does not know about volatile variables or memory mapped device
7737registers.
7738
7739@table @code
7740@item cache
b383017d 7741Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
7742@item nocache
7743Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
7744@end table
7745
4b5752d0
VP
7746@subsection Memory Access Checking
7747@value{GDBN} can be instructed to refuse accesses to memory that is
7748not explicitly described. This can be useful if accessing such
7749regions has undesired effects for a specific target, or to provide
7750better error checking. The following commands control this behaviour.
7751
7752@table @code
7753@kindex set mem inaccessible-by-default
7754@item set mem inaccessible-by-default [on|off]
7755If @code{on} is specified, make @value{GDBN} treat memory not
7756explicitly described by the memory ranges as non-existent and refuse accesses
7757to such memory. The checks are only performed if there's at least one
7758memory range defined. If @code{off} is specified, make @value{GDBN}
7759treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 7760The default value is @code{on}.
4b5752d0
VP
7761@kindex show mem inaccessible-by-default
7762@item show mem inaccessible-by-default
7763Show the current handling of accesses to unknown memory.
7764@end table
7765
7766
29e57380 7767@c @subsubsection Memory Write Verification
b383017d 7768@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
7769@c will re-reads data after each write to verify the write was successful.
7770@c
7771@c @table @code
7772@c @item verify
7773@c @item noverify (default)
7774@c @end table
7775
16d9dec6 7776@node Dump/Restore Files
79a6e687 7777@section Copy Between Memory and a File
16d9dec6
MS
7778@cindex dump/restore files
7779@cindex append data to a file
7780@cindex dump data to a file
7781@cindex restore data from a file
16d9dec6 7782
df5215a6
JB
7783You can use the commands @code{dump}, @code{append}, and
7784@code{restore} to copy data between target memory and a file. The
7785@code{dump} and @code{append} commands write data to a file, and the
7786@code{restore} command reads data from a file back into the inferior's
7787memory. Files may be in binary, Motorola S-record, Intel hex, or
7788Tektronix Hex format; however, @value{GDBN} can only append to binary
7789files.
7790
7791@table @code
7792
7793@kindex dump
7794@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7795@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
7796Dump the contents of memory from @var{start_addr} to @var{end_addr},
7797or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 7798
df5215a6 7799The @var{format} parameter may be any one of:
16d9dec6 7800@table @code
df5215a6
JB
7801@item binary
7802Raw binary form.
7803@item ihex
7804Intel hex format.
7805@item srec
7806Motorola S-record format.
7807@item tekhex
7808Tektronix Hex format.
7809@end table
7810
7811@value{GDBN} uses the same definitions of these formats as the
7812@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
7813@var{format} is omitted, @value{GDBN} dumps the data in raw binary
7814form.
7815
7816@kindex append
7817@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7818@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
7819Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 7820or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
7821(@value{GDBN} can only append data to files in raw binary form.)
7822
7823@kindex restore
7824@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
7825Restore the contents of file @var{filename} into memory. The
7826@code{restore} command can automatically recognize any known @sc{bfd}
7827file format, except for raw binary. To restore a raw binary file you
7828must specify the optional keyword @code{binary} after the filename.
16d9dec6 7829
b383017d 7830If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
7831contained in the file. Binary files always start at address zero, so
7832they will be restored at address @var{bias}. Other bfd files have
7833a built-in location; they will be restored at offset @var{bias}
7834from that location.
7835
7836If @var{start} and/or @var{end} are non-zero, then only data between
7837file offset @var{start} and file offset @var{end} will be restored.
b383017d 7838These offsets are relative to the addresses in the file, before
16d9dec6
MS
7839the @var{bias} argument is applied.
7840
7841@end table
7842
384ee23f
EZ
7843@node Core File Generation
7844@section How to Produce a Core File from Your Program
7845@cindex dump core from inferior
7846
7847A @dfn{core file} or @dfn{core dump} is a file that records the memory
7848image of a running process and its process status (register values
7849etc.). Its primary use is post-mortem debugging of a program that
7850crashed while it ran outside a debugger. A program that crashes
7851automatically produces a core file, unless this feature is disabled by
7852the user. @xref{Files}, for information on invoking @value{GDBN} in
7853the post-mortem debugging mode.
7854
7855Occasionally, you may wish to produce a core file of the program you
7856are debugging in order to preserve a snapshot of its state.
7857@value{GDBN} has a special command for that.
7858
7859@table @code
7860@kindex gcore
7861@kindex generate-core-file
7862@item generate-core-file [@var{file}]
7863@itemx gcore [@var{file}]
7864Produce a core dump of the inferior process. The optional argument
7865@var{file} specifies the file name where to put the core dump. If not
7866specified, the file name defaults to @file{core.@var{pid}}, where
7867@var{pid} is the inferior process ID.
7868
7869Note that this command is implemented only for some systems (as of
7870this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
7871@end table
7872
a0eb71c5
KB
7873@node Character Sets
7874@section Character Sets
7875@cindex character sets
7876@cindex charset
7877@cindex translating between character sets
7878@cindex host character set
7879@cindex target character set
7880
7881If the program you are debugging uses a different character set to
7882represent characters and strings than the one @value{GDBN} uses itself,
7883@value{GDBN} can automatically translate between the character sets for
7884you. The character set @value{GDBN} uses we call the @dfn{host
7885character set}; the one the inferior program uses we call the
7886@dfn{target character set}.
7887
7888For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
7889uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 7890remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
7891running on an IBM mainframe, which uses the @sc{ebcdic} character set,
7892then the host character set is Latin-1, and the target character set is
7893@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 7894target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
7895@sc{ebcdic} and Latin 1 as you print character or string values, or use
7896character and string literals in expressions.
7897
7898@value{GDBN} has no way to automatically recognize which character set
7899the inferior program uses; you must tell it, using the @code{set
7900target-charset} command, described below.
7901
7902Here are the commands for controlling @value{GDBN}'s character set
7903support:
7904
7905@table @code
7906@item set target-charset @var{charset}
7907@kindex set target-charset
7908Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
7909character set names @value{GDBN} recognizes below, but if you type
7910@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7911list the target character sets it supports.
a0eb71c5
KB
7912@end table
7913
7914@table @code
7915@item set host-charset @var{charset}
7916@kindex set host-charset
7917Set the current host character set to @var{charset}.
7918
7919By default, @value{GDBN} uses a host character set appropriate to the
7920system it is running on; you can override that default using the
7921@code{set host-charset} command.
7922
7923@value{GDBN} can only use certain character sets as its host character
7924set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
7925indicate which can be host character sets, but if you type
7926@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7927list the host character sets it supports.
a0eb71c5
KB
7928
7929@item set charset @var{charset}
7930@kindex set charset
e33d66ec
EZ
7931Set the current host and target character sets to @var{charset}. As
7932above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
7933@value{GDBN} will list the name of the character sets that can be used
7934for both host and target.
7935
a0eb71c5
KB
7936
7937@item show charset
a0eb71c5 7938@kindex show charset
b383017d 7939Show the names of the current host and target charsets.
e33d66ec
EZ
7940
7941@itemx show host-charset
a0eb71c5 7942@kindex show host-charset
b383017d 7943Show the name of the current host charset.
e33d66ec
EZ
7944
7945@itemx show target-charset
a0eb71c5 7946@kindex show target-charset
b383017d 7947Show the name of the current target charset.
a0eb71c5
KB
7948
7949@end table
7950
7951@value{GDBN} currently includes support for the following character
7952sets:
7953
7954@table @code
7955
7956@item ASCII
7957@cindex ASCII character set
7958Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
7959character set.
7960
7961@item ISO-8859-1
7962@cindex ISO 8859-1 character set
7963@cindex ISO Latin 1 character set
e33d66ec 7964The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
7965characters needed for French, German, and Spanish. @value{GDBN} can use
7966this as its host character set.
7967
7968@item EBCDIC-US
7969@itemx IBM1047
7970@cindex EBCDIC character set
7971@cindex IBM1047 character set
7972Variants of the @sc{ebcdic} character set, used on some of IBM's
7973mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
7974@value{GDBN} cannot use these as its host character set.
7975
7976@end table
7977
7978Note that these are all single-byte character sets. More work inside
3f94c067 7979@value{GDBN} is needed to support multi-byte or variable-width character
a0eb71c5
KB
7980encodings, like the UTF-8 and UCS-2 encodings of Unicode.
7981
7982Here is an example of @value{GDBN}'s character set support in action.
7983Assume that the following source code has been placed in the file
7984@file{charset-test.c}:
7985
7986@smallexample
7987#include <stdio.h>
7988
7989char ascii_hello[]
7990 = @{72, 101, 108, 108, 111, 44, 32, 119,
7991 111, 114, 108, 100, 33, 10, 0@};
7992char ibm1047_hello[]
7993 = @{200, 133, 147, 147, 150, 107, 64, 166,
7994 150, 153, 147, 132, 90, 37, 0@};
7995
7996main ()
7997@{
7998 printf ("Hello, world!\n");
7999@}
10998722 8000@end smallexample
a0eb71c5
KB
8001
8002In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
8003containing the string @samp{Hello, world!} followed by a newline,
8004encoded in the @sc{ascii} and @sc{ibm1047} character sets.
8005
8006We compile the program, and invoke the debugger on it:
8007
8008@smallexample
8009$ gcc -g charset-test.c -o charset-test
8010$ gdb -nw charset-test
8011GNU gdb 2001-12-19-cvs
8012Copyright 2001 Free Software Foundation, Inc.
8013@dots{}
f7dc1244 8014(@value{GDBP})
10998722 8015@end smallexample
a0eb71c5
KB
8016
8017We can use the @code{show charset} command to see what character sets
8018@value{GDBN} is currently using to interpret and display characters and
8019strings:
8020
8021@smallexample
f7dc1244 8022(@value{GDBP}) show charset
e33d66ec 8023The current host and target character set is `ISO-8859-1'.
f7dc1244 8024(@value{GDBP})
10998722 8025@end smallexample
a0eb71c5
KB
8026
8027For the sake of printing this manual, let's use @sc{ascii} as our
8028initial character set:
8029@smallexample
f7dc1244
EZ
8030(@value{GDBP}) set charset ASCII
8031(@value{GDBP}) show charset
e33d66ec 8032The current host and target character set is `ASCII'.
f7dc1244 8033(@value{GDBP})
10998722 8034@end smallexample
a0eb71c5
KB
8035
8036Let's assume that @sc{ascii} is indeed the correct character set for our
8037host system --- in other words, let's assume that if @value{GDBN} prints
8038characters using the @sc{ascii} character set, our terminal will display
8039them properly. Since our current target character set is also
8040@sc{ascii}, the contents of @code{ascii_hello} print legibly:
8041
8042@smallexample
f7dc1244 8043(@value{GDBP}) print ascii_hello
a0eb71c5 8044$1 = 0x401698 "Hello, world!\n"
f7dc1244 8045(@value{GDBP}) print ascii_hello[0]
a0eb71c5 8046$2 = 72 'H'
f7dc1244 8047(@value{GDBP})
10998722 8048@end smallexample
a0eb71c5
KB
8049
8050@value{GDBN} uses the target character set for character and string
8051literals you use in expressions:
8052
8053@smallexample
f7dc1244 8054(@value{GDBP}) print '+'
a0eb71c5 8055$3 = 43 '+'
f7dc1244 8056(@value{GDBP})
10998722 8057@end smallexample
a0eb71c5
KB
8058
8059The @sc{ascii} character set uses the number 43 to encode the @samp{+}
8060character.
8061
8062@value{GDBN} relies on the user to tell it which character set the
8063target program uses. If we print @code{ibm1047_hello} while our target
8064character set is still @sc{ascii}, we get jibberish:
8065
8066@smallexample
f7dc1244 8067(@value{GDBP}) print ibm1047_hello
a0eb71c5 8068$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 8069(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 8070$5 = 200 '\310'
f7dc1244 8071(@value{GDBP})
10998722 8072@end smallexample
a0eb71c5 8073
e33d66ec 8074If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
8075@value{GDBN} tells us the character sets it supports:
8076
8077@smallexample
f7dc1244 8078(@value{GDBP}) set target-charset
b383017d 8079ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 8080(@value{GDBP}) set target-charset
10998722 8081@end smallexample
a0eb71c5
KB
8082
8083We can select @sc{ibm1047} as our target character set, and examine the
8084program's strings again. Now the @sc{ascii} string is wrong, but
8085@value{GDBN} translates the contents of @code{ibm1047_hello} from the
8086target character set, @sc{ibm1047}, to the host character set,
8087@sc{ascii}, and they display correctly:
8088
8089@smallexample
f7dc1244
EZ
8090(@value{GDBP}) set target-charset IBM1047
8091(@value{GDBP}) show charset
e33d66ec
EZ
8092The current host character set is `ASCII'.
8093The current target character set is `IBM1047'.
f7dc1244 8094(@value{GDBP}) print ascii_hello
a0eb71c5 8095$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 8096(@value{GDBP}) print ascii_hello[0]
a0eb71c5 8097$7 = 72 '\110'
f7dc1244 8098(@value{GDBP}) print ibm1047_hello
a0eb71c5 8099$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 8100(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 8101$9 = 200 'H'
f7dc1244 8102(@value{GDBP})
10998722 8103@end smallexample
a0eb71c5
KB
8104
8105As above, @value{GDBN} uses the target character set for character and
8106string literals you use in expressions:
8107
8108@smallexample
f7dc1244 8109(@value{GDBP}) print '+'
a0eb71c5 8110$10 = 78 '+'
f7dc1244 8111(@value{GDBP})
10998722 8112@end smallexample
a0eb71c5 8113
e33d66ec 8114The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
8115character.
8116
09d4efe1
EZ
8117@node Caching Remote Data
8118@section Caching Data of Remote Targets
8119@cindex caching data of remote targets
8120
8121@value{GDBN} can cache data exchanged between the debugger and a
ea35711c 8122remote target (@pxref{Remote Debugging}). Such caching generally improves
09d4efe1
EZ
8123performance, because it reduces the overhead of the remote protocol by
8124bundling memory reads and writes into large chunks. Unfortunately,
8125@value{GDBN} does not currently know anything about volatile
8126registers, and thus data caching will produce incorrect results when
8127volatile registers are in use.
8128
8129@table @code
8130@kindex set remotecache
8131@item set remotecache on
8132@itemx set remotecache off
8133Set caching state for remote targets. When @code{ON}, use data
8134caching. By default, this option is @code{OFF}.
8135
8136@kindex show remotecache
8137@item show remotecache
8138Show the current state of data caching for remote targets.
8139
8140@kindex info dcache
8141@item info dcache
8142Print the information about the data cache performance. The
8143information displayed includes: the dcache width and depth; and for
8144each cache line, how many times it was referenced, and its data and
07128da0 8145state (invalid, dirty, valid). This command is useful for debugging
09d4efe1
EZ
8146the data cache operation.
8147@end table
8148
08388c79
DE
8149@node Searching Memory
8150@section Search Memory
8151@cindex searching memory
8152
8153Memory can be searched for a particular sequence of bytes with the
8154@code{find} command.
8155
8156@table @code
8157@kindex find
8158@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
8159@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
8160Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
8161etc. The search begins at address @var{start_addr} and continues for either
8162@var{len} bytes or through to @var{end_addr} inclusive.
8163@end table
8164
8165@var{s} and @var{n} are optional parameters.
8166They may be specified in either order, apart or together.
8167
8168@table @r
8169@item @var{s}, search query size
8170The size of each search query value.
8171
8172@table @code
8173@item b
8174bytes
8175@item h
8176halfwords (two bytes)
8177@item w
8178words (four bytes)
8179@item g
8180giant words (eight bytes)
8181@end table
8182
8183All values are interpreted in the current language.
8184This means, for example, that if the current source language is C/C@t{++}
8185then searching for the string ``hello'' includes the trailing '\0'.
8186
8187If the value size is not specified, it is taken from the
8188value's type in the current language.
8189This is useful when one wants to specify the search
8190pattern as a mixture of types.
8191Note that this means, for example, that in the case of C-like languages
8192a search for an untyped 0x42 will search for @samp{(int) 0x42}
8193which is typically four bytes.
8194
8195@item @var{n}, maximum number of finds
8196The maximum number of matches to print. The default is to print all finds.
8197@end table
8198
8199You can use strings as search values. Quote them with double-quotes
8200 (@code{"}).
8201The string value is copied into the search pattern byte by byte,
8202regardless of the endianness of the target and the size specification.
8203
8204The address of each match found is printed as well as a count of the
8205number of matches found.
8206
8207The address of the last value found is stored in convenience variable
8208@samp{$_}.
8209A count of the number of matches is stored in @samp{$numfound}.
8210
8211For example, if stopped at the @code{printf} in this function:
8212
8213@smallexample
8214void
8215hello ()
8216@{
8217 static char hello[] = "hello-hello";
8218 static struct @{ char c; short s; int i; @}
8219 __attribute__ ((packed)) mixed
8220 = @{ 'c', 0x1234, 0x87654321 @};
8221 printf ("%s\n", hello);
8222@}
8223@end smallexample
8224
8225@noindent
8226you get during debugging:
8227
8228@smallexample
8229(gdb) find &hello[0], +sizeof(hello), "hello"
82300x804956d <hello.1620+6>
82311 pattern found
8232(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
82330x8049567 <hello.1620>
82340x804956d <hello.1620+6>
82352 patterns found
8236(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
82370x8049567 <hello.1620>
82381 pattern found
8239(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
82400x8049560 <mixed.1625>
82411 pattern found
8242(gdb) print $numfound
8243$1 = 1
8244(gdb) print $_
8245$2 = (void *) 0x8049560
8246@end smallexample
a0eb71c5 8247
e2e0bcd1
JB
8248@node Macros
8249@chapter C Preprocessor Macros
8250
49efadf5 8251Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
8252``preprocessor macros'' which expand into strings of tokens.
8253@value{GDBN} can evaluate expressions containing macro invocations, show
8254the result of macro expansion, and show a macro's definition, including
8255where it was defined.
8256
8257You may need to compile your program specially to provide @value{GDBN}
8258with information about preprocessor macros. Most compilers do not
8259include macros in their debugging information, even when you compile
8260with the @option{-g} flag. @xref{Compilation}.
8261
8262A program may define a macro at one point, remove that definition later,
8263and then provide a different definition after that. Thus, at different
8264points in the program, a macro may have different definitions, or have
8265no definition at all. If there is a current stack frame, @value{GDBN}
8266uses the macros in scope at that frame's source code line. Otherwise,
8267@value{GDBN} uses the macros in scope at the current listing location;
8268see @ref{List}.
8269
e2e0bcd1
JB
8270Whenever @value{GDBN} evaluates an expression, it always expands any
8271macro invocations present in the expression. @value{GDBN} also provides
8272the following commands for working with macros explicitly.
8273
8274@table @code
8275
8276@kindex macro expand
8277@cindex macro expansion, showing the results of preprocessor
8278@cindex preprocessor macro expansion, showing the results of
8279@cindex expanding preprocessor macros
8280@item macro expand @var{expression}
8281@itemx macro exp @var{expression}
8282Show the results of expanding all preprocessor macro invocations in
8283@var{expression}. Since @value{GDBN} simply expands macros, but does
8284not parse the result, @var{expression} need not be a valid expression;
8285it can be any string of tokens.
8286
09d4efe1 8287@kindex macro exp1
e2e0bcd1
JB
8288@item macro expand-once @var{expression}
8289@itemx macro exp1 @var{expression}
4644b6e3 8290@cindex expand macro once
e2e0bcd1
JB
8291@i{(This command is not yet implemented.)} Show the results of
8292expanding those preprocessor macro invocations that appear explicitly in
8293@var{expression}. Macro invocations appearing in that expansion are
8294left unchanged. This command allows you to see the effect of a
8295particular macro more clearly, without being confused by further
8296expansions. Since @value{GDBN} simply expands macros, but does not
8297parse the result, @var{expression} need not be a valid expression; it
8298can be any string of tokens.
8299
475b0867 8300@kindex info macro
e2e0bcd1
JB
8301@cindex macro definition, showing
8302@cindex definition, showing a macro's
475b0867 8303@item info macro @var{macro}
e2e0bcd1
JB
8304Show the definition of the macro named @var{macro}, and describe the
8305source location where that definition was established.
8306
8307@kindex macro define
8308@cindex user-defined macros
8309@cindex defining macros interactively
8310@cindex macros, user-defined
8311@item macro define @var{macro} @var{replacement-list}
8312@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
8313Introduce a definition for a preprocessor macro named @var{macro},
8314invocations of which are replaced by the tokens given in
8315@var{replacement-list}. The first form of this command defines an
8316``object-like'' macro, which takes no arguments; the second form
8317defines a ``function-like'' macro, which takes the arguments given in
8318@var{arglist}.
8319
8320A definition introduced by this command is in scope in every
8321expression evaluated in @value{GDBN}, until it is removed with the
8322@code{macro undef} command, described below. The definition overrides
8323all definitions for @var{macro} present in the program being debugged,
8324as well as any previous user-supplied definition.
e2e0bcd1
JB
8325
8326@kindex macro undef
8327@item macro undef @var{macro}
d7d9f01e
TT
8328Remove any user-supplied definition for the macro named @var{macro}.
8329This command only affects definitions provided with the @code{macro
8330define} command, described above; it cannot remove definitions present
8331in the program being debugged.
e2e0bcd1 8332
09d4efe1
EZ
8333@kindex macro list
8334@item macro list
d7d9f01e 8335List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
8336@end table
8337
8338@cindex macros, example of debugging with
8339Here is a transcript showing the above commands in action. First, we
8340show our source files:
8341
8342@smallexample
8343$ cat sample.c
8344#include <stdio.h>
8345#include "sample.h"
8346
8347#define M 42
8348#define ADD(x) (M + x)
8349
8350main ()
8351@{
8352#define N 28
8353 printf ("Hello, world!\n");
8354#undef N
8355 printf ("We're so creative.\n");
8356#define N 1729
8357 printf ("Goodbye, world!\n");
8358@}
8359$ cat sample.h
8360#define Q <
8361$
8362@end smallexample
8363
8364Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
8365We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
8366compiler includes information about preprocessor macros in the debugging
8367information.
8368
8369@smallexample
8370$ gcc -gdwarf-2 -g3 sample.c -o sample
8371$
8372@end smallexample
8373
8374Now, we start @value{GDBN} on our sample program:
8375
8376@smallexample
8377$ gdb -nw sample
8378GNU gdb 2002-05-06-cvs
8379Copyright 2002 Free Software Foundation, Inc.
8380GDB is free software, @dots{}
f7dc1244 8381(@value{GDBP})
e2e0bcd1
JB
8382@end smallexample
8383
8384We can expand macros and examine their definitions, even when the
8385program is not running. @value{GDBN} uses the current listing position
8386to decide which macro definitions are in scope:
8387
8388@smallexample
f7dc1244 8389(@value{GDBP}) list main
e2e0bcd1
JB
83903
83914 #define M 42
83925 #define ADD(x) (M + x)
83936
83947 main ()
83958 @{
83969 #define N 28
839710 printf ("Hello, world!\n");
839811 #undef N
839912 printf ("We're so creative.\n");
f7dc1244 8400(@value{GDBP}) info macro ADD
e2e0bcd1
JB
8401Defined at /home/jimb/gdb/macros/play/sample.c:5
8402#define ADD(x) (M + x)
f7dc1244 8403(@value{GDBP}) info macro Q
e2e0bcd1
JB
8404Defined at /home/jimb/gdb/macros/play/sample.h:1
8405 included at /home/jimb/gdb/macros/play/sample.c:2
8406#define Q <
f7dc1244 8407(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 8408expands to: (42 + 1)
f7dc1244 8409(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 8410expands to: once (M + 1)
f7dc1244 8411(@value{GDBP})
e2e0bcd1
JB
8412@end smallexample
8413
d7d9f01e 8414In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
8415the macro invocation explicit in the original text --- the invocation of
8416@code{ADD} --- but does not expand the invocation of the macro @code{M},
8417which was introduced by @code{ADD}.
8418
3f94c067
BW
8419Once the program is running, @value{GDBN} uses the macro definitions in
8420force at the source line of the current stack frame:
e2e0bcd1
JB
8421
8422@smallexample
f7dc1244 8423(@value{GDBP}) break main
e2e0bcd1 8424Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 8425(@value{GDBP}) run
b383017d 8426Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
8427
8428Breakpoint 1, main () at sample.c:10
842910 printf ("Hello, world!\n");
f7dc1244 8430(@value{GDBP})
e2e0bcd1
JB
8431@end smallexample
8432
8433At line 10, the definition of the macro @code{N} at line 9 is in force:
8434
8435@smallexample
f7dc1244 8436(@value{GDBP}) info macro N
e2e0bcd1
JB
8437Defined at /home/jimb/gdb/macros/play/sample.c:9
8438#define N 28
f7dc1244 8439(@value{GDBP}) macro expand N Q M
e2e0bcd1 8440expands to: 28 < 42
f7dc1244 8441(@value{GDBP}) print N Q M
e2e0bcd1 8442$1 = 1
f7dc1244 8443(@value{GDBP})
e2e0bcd1
JB
8444@end smallexample
8445
8446As we step over directives that remove @code{N}'s definition, and then
8447give it a new definition, @value{GDBN} finds the definition (or lack
8448thereof) in force at each point:
8449
8450@smallexample
f7dc1244 8451(@value{GDBP}) next
e2e0bcd1
JB
8452Hello, world!
845312 printf ("We're so creative.\n");
f7dc1244 8454(@value{GDBP}) info macro N
e2e0bcd1
JB
8455The symbol `N' has no definition as a C/C++ preprocessor macro
8456at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 8457(@value{GDBP}) next
e2e0bcd1
JB
8458We're so creative.
845914 printf ("Goodbye, world!\n");
f7dc1244 8460(@value{GDBP}) info macro N
e2e0bcd1
JB
8461Defined at /home/jimb/gdb/macros/play/sample.c:13
8462#define N 1729
f7dc1244 8463(@value{GDBP}) macro expand N Q M
e2e0bcd1 8464expands to: 1729 < 42
f7dc1244 8465(@value{GDBP}) print N Q M
e2e0bcd1 8466$2 = 0
f7dc1244 8467(@value{GDBP})
e2e0bcd1
JB
8468@end smallexample
8469
8470
b37052ae
EZ
8471@node Tracepoints
8472@chapter Tracepoints
8473@c This chapter is based on the documentation written by Michael
8474@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
8475
8476@cindex tracepoints
8477In some applications, it is not feasible for the debugger to interrupt
8478the program's execution long enough for the developer to learn
8479anything helpful about its behavior. If the program's correctness
8480depends on its real-time behavior, delays introduced by a debugger
8481might cause the program to change its behavior drastically, or perhaps
8482fail, even when the code itself is correct. It is useful to be able
8483to observe the program's behavior without interrupting it.
8484
8485Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
8486specify locations in the program, called @dfn{tracepoints}, and
8487arbitrary expressions to evaluate when those tracepoints are reached.
8488Later, using the @code{tfind} command, you can examine the values
8489those expressions had when the program hit the tracepoints. The
8490expressions may also denote objects in memory---structures or arrays,
8491for example---whose values @value{GDBN} should record; while visiting
8492a particular tracepoint, you may inspect those objects as if they were
8493in memory at that moment. However, because @value{GDBN} records these
8494values without interacting with you, it can do so quickly and
8495unobtrusively, hopefully not disturbing the program's behavior.
8496
8497The tracepoint facility is currently available only for remote
9d29849a
JB
8498targets. @xref{Targets}. In addition, your remote target must know
8499how to collect trace data. This functionality is implemented in the
8500remote stub; however, none of the stubs distributed with @value{GDBN}
8501support tracepoints as of this writing. The format of the remote
8502packets used to implement tracepoints are described in @ref{Tracepoint
8503Packets}.
b37052ae
EZ
8504
8505This chapter describes the tracepoint commands and features.
8506
8507@menu
b383017d
RM
8508* Set Tracepoints::
8509* Analyze Collected Data::
8510* Tracepoint Variables::
b37052ae
EZ
8511@end menu
8512
8513@node Set Tracepoints
8514@section Commands to Set Tracepoints
8515
8516Before running such a @dfn{trace experiment}, an arbitrary number of
8517tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
8518tracepoint has a number assigned to it by @value{GDBN}. Like with
8519breakpoints, tracepoint numbers are successive integers starting from
8520one. Many of the commands associated with tracepoints take the
8521tracepoint number as their argument, to identify which tracepoint to
8522work on.
8523
8524For each tracepoint, you can specify, in advance, some arbitrary set
8525of data that you want the target to collect in the trace buffer when
8526it hits that tracepoint. The collected data can include registers,
8527local variables, or global data. Later, you can use @value{GDBN}
8528commands to examine the values these data had at the time the
8529tracepoint was hit.
8530
8531This section describes commands to set tracepoints and associated
8532conditions and actions.
8533
8534@menu
b383017d
RM
8535* Create and Delete Tracepoints::
8536* Enable and Disable Tracepoints::
8537* Tracepoint Passcounts::
8538* Tracepoint Actions::
8539* Listing Tracepoints::
79a6e687 8540* Starting and Stopping Trace Experiments::
b37052ae
EZ
8541@end menu
8542
8543@node Create and Delete Tracepoints
8544@subsection Create and Delete Tracepoints
8545
8546@table @code
8547@cindex set tracepoint
8548@kindex trace
8549@item trace
8550The @code{trace} command is very similar to the @code{break} command.
8551Its argument can be a source line, a function name, or an address in
8552the target program. @xref{Set Breaks}. The @code{trace} command
8553defines a tracepoint, which is a point in the target program where the
8554debugger will briefly stop, collect some data, and then allow the
8555program to continue. Setting a tracepoint or changing its commands
8556doesn't take effect until the next @code{tstart} command; thus, you
8557cannot change the tracepoint attributes once a trace experiment is
8558running.
8559
8560Here are some examples of using the @code{trace} command:
8561
8562@smallexample
8563(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
8564
8565(@value{GDBP}) @b{trace +2} // 2 lines forward
8566
8567(@value{GDBP}) @b{trace my_function} // first source line of function
8568
8569(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
8570
8571(@value{GDBP}) @b{trace *0x2117c4} // an address
8572@end smallexample
8573
8574@noindent
8575You can abbreviate @code{trace} as @code{tr}.
8576
8577@vindex $tpnum
8578@cindex last tracepoint number
8579@cindex recent tracepoint number
8580@cindex tracepoint number
8581The convenience variable @code{$tpnum} records the tracepoint number
8582of the most recently set tracepoint.
8583
8584@kindex delete tracepoint
8585@cindex tracepoint deletion
8586@item delete tracepoint @r{[}@var{num}@r{]}
8587Permanently delete one or more tracepoints. With no argument, the
8588default is to delete all tracepoints.
8589
8590Examples:
8591
8592@smallexample
8593(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
8594
8595(@value{GDBP}) @b{delete trace} // remove all tracepoints
8596@end smallexample
8597
8598@noindent
8599You can abbreviate this command as @code{del tr}.
8600@end table
8601
8602@node Enable and Disable Tracepoints
8603@subsection Enable and Disable Tracepoints
8604
8605@table @code
8606@kindex disable tracepoint
8607@item disable tracepoint @r{[}@var{num}@r{]}
8608Disable tracepoint @var{num}, or all tracepoints if no argument
8609@var{num} is given. A disabled tracepoint will have no effect during
8610the next trace experiment, but it is not forgotten. You can re-enable
8611a disabled tracepoint using the @code{enable tracepoint} command.
8612
8613@kindex enable tracepoint
8614@item enable tracepoint @r{[}@var{num}@r{]}
8615Enable tracepoint @var{num}, or all tracepoints. The enabled
8616tracepoints will become effective the next time a trace experiment is
8617run.
8618@end table
8619
8620@node Tracepoint Passcounts
8621@subsection Tracepoint Passcounts
8622
8623@table @code
8624@kindex passcount
8625@cindex tracepoint pass count
8626@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
8627Set the @dfn{passcount} of a tracepoint. The passcount is a way to
8628automatically stop a trace experiment. If a tracepoint's passcount is
8629@var{n}, then the trace experiment will be automatically stopped on
8630the @var{n}'th time that tracepoint is hit. If the tracepoint number
8631@var{num} is not specified, the @code{passcount} command sets the
8632passcount of the most recently defined tracepoint. If no passcount is
8633given, the trace experiment will run until stopped explicitly by the
8634user.
8635
8636Examples:
8637
8638@smallexample
b383017d 8639(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 8640@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
8641
8642(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 8643@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
8644(@value{GDBP}) @b{trace foo}
8645(@value{GDBP}) @b{pass 3}
8646(@value{GDBP}) @b{trace bar}
8647(@value{GDBP}) @b{pass 2}
8648(@value{GDBP}) @b{trace baz}
8649(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
8650@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
8651@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
8652@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
8653@end smallexample
8654@end table
8655
8656@node Tracepoint Actions
8657@subsection Tracepoint Action Lists
8658
8659@table @code
8660@kindex actions
8661@cindex tracepoint actions
8662@item actions @r{[}@var{num}@r{]}
8663This command will prompt for a list of actions to be taken when the
8664tracepoint is hit. If the tracepoint number @var{num} is not
8665specified, this command sets the actions for the one that was most
8666recently defined (so that you can define a tracepoint and then say
8667@code{actions} without bothering about its number). You specify the
8668actions themselves on the following lines, one action at a time, and
8669terminate the actions list with a line containing just @code{end}. So
8670far, the only defined actions are @code{collect} and
8671@code{while-stepping}.
8672
8673@cindex remove actions from a tracepoint
8674To remove all actions from a tracepoint, type @samp{actions @var{num}}
8675and follow it immediately with @samp{end}.
8676
8677@smallexample
8678(@value{GDBP}) @b{collect @var{data}} // collect some data
8679
6826cf00 8680(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 8681
6826cf00 8682(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
8683@end smallexample
8684
8685In the following example, the action list begins with @code{collect}
8686commands indicating the things to be collected when the tracepoint is
8687hit. Then, in order to single-step and collect additional data
8688following the tracepoint, a @code{while-stepping} command is used,
8689followed by the list of things to be collected while stepping. The
8690@code{while-stepping} command is terminated by its own separate
8691@code{end} command. Lastly, the action list is terminated by an
8692@code{end} command.
8693
8694@smallexample
8695(@value{GDBP}) @b{trace foo}
8696(@value{GDBP}) @b{actions}
8697Enter actions for tracepoint 1, one per line:
8698> collect bar,baz
8699> collect $regs
8700> while-stepping 12
8701 > collect $fp, $sp
8702 > end
8703end
8704@end smallexample
8705
8706@kindex collect @r{(tracepoints)}
8707@item collect @var{expr1}, @var{expr2}, @dots{}
8708Collect values of the given expressions when the tracepoint is hit.
8709This command accepts a comma-separated list of any valid expressions.
8710In addition to global, static, or local variables, the following
8711special arguments are supported:
8712
8713@table @code
8714@item $regs
8715collect all registers
8716
8717@item $args
8718collect all function arguments
8719
8720@item $locals
8721collect all local variables.
8722@end table
8723
8724You can give several consecutive @code{collect} commands, each one
8725with a single argument, or one @code{collect} command with several
8726arguments separated by commas: the effect is the same.
8727
f5c37c66
EZ
8728The command @code{info scope} (@pxref{Symbols, info scope}) is
8729particularly useful for figuring out what data to collect.
8730
b37052ae
EZ
8731@kindex while-stepping @r{(tracepoints)}
8732@item while-stepping @var{n}
8733Perform @var{n} single-step traces after the tracepoint, collecting
8734new data at each step. The @code{while-stepping} command is
8735followed by the list of what to collect while stepping (followed by
8736its own @code{end} command):
8737
8738@smallexample
8739> while-stepping 12
8740 > collect $regs, myglobal
8741 > end
8742>
8743@end smallexample
8744
8745@noindent
8746You may abbreviate @code{while-stepping} as @code{ws} or
8747@code{stepping}.
8748@end table
8749
8750@node Listing Tracepoints
8751@subsection Listing Tracepoints
8752
8753@table @code
8754@kindex info tracepoints
09d4efe1 8755@kindex info tp
b37052ae
EZ
8756@cindex information about tracepoints
8757@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 8758Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 8759a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
8760defined so far. For each tracepoint, the following information is
8761shown:
8762
8763@itemize @bullet
8764@item
8765its number
8766@item
8767whether it is enabled or disabled
8768@item
8769its address
8770@item
8771its passcount as given by the @code{passcount @var{n}} command
8772@item
8773its step count as given by the @code{while-stepping @var{n}} command
8774@item
8775where in the source files is the tracepoint set
8776@item
8777its action list as given by the @code{actions} command
8778@end itemize
8779
8780@smallexample
8781(@value{GDBP}) @b{info trace}
8782Num Enb Address PassC StepC What
87831 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
87842 y 0x0020dc64 0 0 in g_test at g_test.c:1375
87853 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
8786(@value{GDBP})
8787@end smallexample
8788
8789@noindent
8790This command can be abbreviated @code{info tp}.
8791@end table
8792
79a6e687
BW
8793@node Starting and Stopping Trace Experiments
8794@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
8795
8796@table @code
8797@kindex tstart
8798@cindex start a new trace experiment
8799@cindex collected data discarded
8800@item tstart
8801This command takes no arguments. It starts the trace experiment, and
8802begins collecting data. This has the side effect of discarding all
8803the data collected in the trace buffer during the previous trace
8804experiment.
8805
8806@kindex tstop
8807@cindex stop a running trace experiment
8808@item tstop
8809This command takes no arguments. It ends the trace experiment, and
8810stops collecting data.
8811
68c71a2e 8812@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
8813automatically if any tracepoint's passcount is reached
8814(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
8815
8816@kindex tstatus
8817@cindex status of trace data collection
8818@cindex trace experiment, status of
8819@item tstatus
8820This command displays the status of the current trace data
8821collection.
8822@end table
8823
8824Here is an example of the commands we described so far:
8825
8826@smallexample
8827(@value{GDBP}) @b{trace gdb_c_test}
8828(@value{GDBP}) @b{actions}
8829Enter actions for tracepoint #1, one per line.
8830> collect $regs,$locals,$args
8831> while-stepping 11
8832 > collect $regs
8833 > end
8834> end
8835(@value{GDBP}) @b{tstart}
8836 [time passes @dots{}]
8837(@value{GDBP}) @b{tstop}
8838@end smallexample
8839
8840
8841@node Analyze Collected Data
79a6e687 8842@section Using the Collected Data
b37052ae
EZ
8843
8844After the tracepoint experiment ends, you use @value{GDBN} commands
8845for examining the trace data. The basic idea is that each tracepoint
8846collects a trace @dfn{snapshot} every time it is hit and another
8847snapshot every time it single-steps. All these snapshots are
8848consecutively numbered from zero and go into a buffer, and you can
8849examine them later. The way you examine them is to @dfn{focus} on a
8850specific trace snapshot. When the remote stub is focused on a trace
8851snapshot, it will respond to all @value{GDBN} requests for memory and
8852registers by reading from the buffer which belongs to that snapshot,
8853rather than from @emph{real} memory or registers of the program being
8854debugged. This means that @strong{all} @value{GDBN} commands
8855(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
8856behave as if we were currently debugging the program state as it was
8857when the tracepoint occurred. Any requests for data that are not in
8858the buffer will fail.
8859
8860@menu
8861* tfind:: How to select a trace snapshot
8862* tdump:: How to display all data for a snapshot
8863* save-tracepoints:: How to save tracepoints for a future run
8864@end menu
8865
8866@node tfind
8867@subsection @code{tfind @var{n}}
8868
8869@kindex tfind
8870@cindex select trace snapshot
8871@cindex find trace snapshot
8872The basic command for selecting a trace snapshot from the buffer is
8873@code{tfind @var{n}}, which finds trace snapshot number @var{n},
8874counting from zero. If no argument @var{n} is given, the next
8875snapshot is selected.
8876
8877Here are the various forms of using the @code{tfind} command.
8878
8879@table @code
8880@item tfind start
8881Find the first snapshot in the buffer. This is a synonym for
8882@code{tfind 0} (since 0 is the number of the first snapshot).
8883
8884@item tfind none
8885Stop debugging trace snapshots, resume @emph{live} debugging.
8886
8887@item tfind end
8888Same as @samp{tfind none}.
8889
8890@item tfind
8891No argument means find the next trace snapshot.
8892
8893@item tfind -
8894Find the previous trace snapshot before the current one. This permits
8895retracing earlier steps.
8896
8897@item tfind tracepoint @var{num}
8898Find the next snapshot associated with tracepoint @var{num}. Search
8899proceeds forward from the last examined trace snapshot. If no
8900argument @var{num} is given, it means find the next snapshot collected
8901for the same tracepoint as the current snapshot.
8902
8903@item tfind pc @var{addr}
8904Find the next snapshot associated with the value @var{addr} of the
8905program counter. Search proceeds forward from the last examined trace
8906snapshot. If no argument @var{addr} is given, it means find the next
8907snapshot with the same value of PC as the current snapshot.
8908
8909@item tfind outside @var{addr1}, @var{addr2}
8910Find the next snapshot whose PC is outside the given range of
8911addresses.
8912
8913@item tfind range @var{addr1}, @var{addr2}
8914Find the next snapshot whose PC is between @var{addr1} and
8915@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
8916
8917@item tfind line @r{[}@var{file}:@r{]}@var{n}
8918Find the next snapshot associated with the source line @var{n}. If
8919the optional argument @var{file} is given, refer to line @var{n} in
8920that source file. Search proceeds forward from the last examined
8921trace snapshot. If no argument @var{n} is given, it means find the
8922next line other than the one currently being examined; thus saying
8923@code{tfind line} repeatedly can appear to have the same effect as
8924stepping from line to line in a @emph{live} debugging session.
8925@end table
8926
8927The default arguments for the @code{tfind} commands are specifically
8928designed to make it easy to scan through the trace buffer. For
8929instance, @code{tfind} with no argument selects the next trace
8930snapshot, and @code{tfind -} with no argument selects the previous
8931trace snapshot. So, by giving one @code{tfind} command, and then
8932simply hitting @key{RET} repeatedly you can examine all the trace
8933snapshots in order. Or, by saying @code{tfind -} and then hitting
8934@key{RET} repeatedly you can examine the snapshots in reverse order.
8935The @code{tfind line} command with no argument selects the snapshot
8936for the next source line executed. The @code{tfind pc} command with
8937no argument selects the next snapshot with the same program counter
8938(PC) as the current frame. The @code{tfind tracepoint} command with
8939no argument selects the next trace snapshot collected by the same
8940tracepoint as the current one.
8941
8942In addition to letting you scan through the trace buffer manually,
8943these commands make it easy to construct @value{GDBN} scripts that
8944scan through the trace buffer and print out whatever collected data
8945you are interested in. Thus, if we want to examine the PC, FP, and SP
8946registers from each trace frame in the buffer, we can say this:
8947
8948@smallexample
8949(@value{GDBP}) @b{tfind start}
8950(@value{GDBP}) @b{while ($trace_frame != -1)}
8951> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
8952 $trace_frame, $pc, $sp, $fp
8953> tfind
8954> end
8955
8956Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
8957Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
8958Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
8959Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
8960Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
8961Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
8962Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
8963Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
8964Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
8965Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
8966Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
8967@end smallexample
8968
8969Or, if we want to examine the variable @code{X} at each source line in
8970the buffer:
8971
8972@smallexample
8973(@value{GDBP}) @b{tfind start}
8974(@value{GDBP}) @b{while ($trace_frame != -1)}
8975> printf "Frame %d, X == %d\n", $trace_frame, X
8976> tfind line
8977> end
8978
8979Frame 0, X = 1
8980Frame 7, X = 2
8981Frame 13, X = 255
8982@end smallexample
8983
8984@node tdump
8985@subsection @code{tdump}
8986@kindex tdump
8987@cindex dump all data collected at tracepoint
8988@cindex tracepoint data, display
8989
8990This command takes no arguments. It prints all the data collected at
8991the current trace snapshot.
8992
8993@smallexample
8994(@value{GDBP}) @b{trace 444}
8995(@value{GDBP}) @b{actions}
8996Enter actions for tracepoint #2, one per line:
8997> collect $regs, $locals, $args, gdb_long_test
8998> end
8999
9000(@value{GDBP}) @b{tstart}
9001
9002(@value{GDBP}) @b{tfind line 444}
9003#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
9004at gdb_test.c:444
9005444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
9006
9007(@value{GDBP}) @b{tdump}
9008Data collected at tracepoint 2, trace frame 1:
9009d0 0xc4aa0085 -995491707
9010d1 0x18 24
9011d2 0x80 128
9012d3 0x33 51
9013d4 0x71aea3d 119204413
9014d5 0x22 34
9015d6 0xe0 224
9016d7 0x380035 3670069
9017a0 0x19e24a 1696330
9018a1 0x3000668 50333288
9019a2 0x100 256
9020a3 0x322000 3284992
9021a4 0x3000698 50333336
9022a5 0x1ad3cc 1758156
9023fp 0x30bf3c 0x30bf3c
9024sp 0x30bf34 0x30bf34
9025ps 0x0 0
9026pc 0x20b2c8 0x20b2c8
9027fpcontrol 0x0 0
9028fpstatus 0x0 0
9029fpiaddr 0x0 0
9030p = 0x20e5b4 "gdb-test"
9031p1 = (void *) 0x11
9032p2 = (void *) 0x22
9033p3 = (void *) 0x33
9034p4 = (void *) 0x44
9035p5 = (void *) 0x55
9036p6 = (void *) 0x66
9037gdb_long_test = 17 '\021'
9038
9039(@value{GDBP})
9040@end smallexample
9041
9042@node save-tracepoints
9043@subsection @code{save-tracepoints @var{filename}}
9044@kindex save-tracepoints
9045@cindex save tracepoints for future sessions
9046
9047This command saves all current tracepoint definitions together with
9048their actions and passcounts, into a file @file{@var{filename}}
9049suitable for use in a later debugging session. To read the saved
9050tracepoint definitions, use the @code{source} command (@pxref{Command
9051Files}).
9052
9053@node Tracepoint Variables
9054@section Convenience Variables for Tracepoints
9055@cindex tracepoint variables
9056@cindex convenience variables for tracepoints
9057
9058@table @code
9059@vindex $trace_frame
9060@item (int) $trace_frame
9061The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
9062snapshot is selected.
9063
9064@vindex $tracepoint
9065@item (int) $tracepoint
9066The tracepoint for the current trace snapshot.
9067
9068@vindex $trace_line
9069@item (int) $trace_line
9070The line number for the current trace snapshot.
9071
9072@vindex $trace_file
9073@item (char []) $trace_file
9074The source file for the current trace snapshot.
9075
9076@vindex $trace_func
9077@item (char []) $trace_func
9078The name of the function containing @code{$tracepoint}.
9079@end table
9080
9081Note: @code{$trace_file} is not suitable for use in @code{printf},
9082use @code{output} instead.
9083
9084Here's a simple example of using these convenience variables for
9085stepping through all the trace snapshots and printing some of their
9086data.
9087
9088@smallexample
9089(@value{GDBP}) @b{tfind start}
9090
9091(@value{GDBP}) @b{while $trace_frame != -1}
9092> output $trace_file
9093> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
9094> tfind
9095> end
9096@end smallexample
9097
df0cd8c5
JB
9098@node Overlays
9099@chapter Debugging Programs That Use Overlays
9100@cindex overlays
9101
9102If your program is too large to fit completely in your target system's
9103memory, you can sometimes use @dfn{overlays} to work around this
9104problem. @value{GDBN} provides some support for debugging programs that
9105use overlays.
9106
9107@menu
9108* How Overlays Work:: A general explanation of overlays.
9109* Overlay Commands:: Managing overlays in @value{GDBN}.
9110* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
9111 mapped by asking the inferior.
9112* Overlay Sample Program:: A sample program using overlays.
9113@end menu
9114
9115@node How Overlays Work
9116@section How Overlays Work
9117@cindex mapped overlays
9118@cindex unmapped overlays
9119@cindex load address, overlay's
9120@cindex mapped address
9121@cindex overlay area
9122
9123Suppose you have a computer whose instruction address space is only 64
9124kilobytes long, but which has much more memory which can be accessed by
9125other means: special instructions, segment registers, or memory
9126management hardware, for example. Suppose further that you want to
9127adapt a program which is larger than 64 kilobytes to run on this system.
9128
9129One solution is to identify modules of your program which are relatively
9130independent, and need not call each other directly; call these modules
9131@dfn{overlays}. Separate the overlays from the main program, and place
9132their machine code in the larger memory. Place your main program in
9133instruction memory, but leave at least enough space there to hold the
9134largest overlay as well.
9135
9136Now, to call a function located in an overlay, you must first copy that
9137overlay's machine code from the large memory into the space set aside
9138for it in the instruction memory, and then jump to its entry point
9139there.
9140
c928edc0
AC
9141@c NB: In the below the mapped area's size is greater or equal to the
9142@c size of all overlays. This is intentional to remind the developer
9143@c that overlays don't necessarily need to be the same size.
9144
474c8240 9145@smallexample
df0cd8c5 9146@group
c928edc0
AC
9147 Data Instruction Larger
9148Address Space Address Space Address Space
9149+-----------+ +-----------+ +-----------+
9150| | | | | |
9151+-----------+ +-----------+ +-----------+<-- overlay 1
9152| program | | main | .----| overlay 1 | load address
9153| variables | | program | | +-----------+
9154| and heap | | | | | |
9155+-----------+ | | | +-----------+<-- overlay 2
9156| | +-----------+ | | | load address
9157+-----------+ | | | .-| overlay 2 |
9158 | | | | | |
9159 mapped --->+-----------+ | | +-----------+
9160 address | | | | | |
9161 | overlay | <-' | | |
9162 | area | <---' +-----------+<-- overlay 3
9163 | | <---. | | load address
9164 +-----------+ `--| overlay 3 |
9165 | | | |
9166 +-----------+ | |
9167 +-----------+
9168 | |
9169 +-----------+
9170
9171 @anchor{A code overlay}A code overlay
df0cd8c5 9172@end group
474c8240 9173@end smallexample
df0cd8c5 9174
c928edc0
AC
9175The diagram (@pxref{A code overlay}) shows a system with separate data
9176and instruction address spaces. To map an overlay, the program copies
9177its code from the larger address space to the instruction address space.
9178Since the overlays shown here all use the same mapped address, only one
9179may be mapped at a time. For a system with a single address space for
9180data and instructions, the diagram would be similar, except that the
9181program variables and heap would share an address space with the main
9182program and the overlay area.
df0cd8c5
JB
9183
9184An overlay loaded into instruction memory and ready for use is called a
9185@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
9186instruction memory. An overlay not present (or only partially present)
9187in instruction memory is called @dfn{unmapped}; its @dfn{load address}
9188is its address in the larger memory. The mapped address is also called
9189the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
9190called the @dfn{load memory address}, or @dfn{LMA}.
9191
9192Unfortunately, overlays are not a completely transparent way to adapt a
9193program to limited instruction memory. They introduce a new set of
9194global constraints you must keep in mind as you design your program:
9195
9196@itemize @bullet
9197
9198@item
9199Before calling or returning to a function in an overlay, your program
9200must make sure that overlay is actually mapped. Otherwise, the call or
9201return will transfer control to the right address, but in the wrong
9202overlay, and your program will probably crash.
9203
9204@item
9205If the process of mapping an overlay is expensive on your system, you
9206will need to choose your overlays carefully to minimize their effect on
9207your program's performance.
9208
9209@item
9210The executable file you load onto your system must contain each
9211overlay's instructions, appearing at the overlay's load address, not its
9212mapped address. However, each overlay's instructions must be relocated
9213and its symbols defined as if the overlay were at its mapped address.
9214You can use GNU linker scripts to specify different load and relocation
9215addresses for pieces of your program; see @ref{Overlay Description,,,
9216ld.info, Using ld: the GNU linker}.
9217
9218@item
9219The procedure for loading executable files onto your system must be able
9220to load their contents into the larger address space as well as the
9221instruction and data spaces.
9222
9223@end itemize
9224
9225The overlay system described above is rather simple, and could be
9226improved in many ways:
9227
9228@itemize @bullet
9229
9230@item
9231If your system has suitable bank switch registers or memory management
9232hardware, you could use those facilities to make an overlay's load area
9233contents simply appear at their mapped address in instruction space.
9234This would probably be faster than copying the overlay to its mapped
9235area in the usual way.
9236
9237@item
9238If your overlays are small enough, you could set aside more than one
9239overlay area, and have more than one overlay mapped at a time.
9240
9241@item
9242You can use overlays to manage data, as well as instructions. In
9243general, data overlays are even less transparent to your design than
9244code overlays: whereas code overlays only require care when you call or
9245return to functions, data overlays require care every time you access
9246the data. Also, if you change the contents of a data overlay, you
9247must copy its contents back out to its load address before you can copy a
9248different data overlay into the same mapped area.
9249
9250@end itemize
9251
9252
9253@node Overlay Commands
9254@section Overlay Commands
9255
9256To use @value{GDBN}'s overlay support, each overlay in your program must
9257correspond to a separate section of the executable file. The section's
9258virtual memory address and load memory address must be the overlay's
9259mapped and load addresses. Identifying overlays with sections allows
9260@value{GDBN} to determine the appropriate address of a function or
9261variable, depending on whether the overlay is mapped or not.
9262
9263@value{GDBN}'s overlay commands all start with the word @code{overlay};
9264you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
9265
9266@table @code
9267@item overlay off
4644b6e3 9268@kindex overlay
df0cd8c5
JB
9269Disable @value{GDBN}'s overlay support. When overlay support is
9270disabled, @value{GDBN} assumes that all functions and variables are
9271always present at their mapped addresses. By default, @value{GDBN}'s
9272overlay support is disabled.
9273
9274@item overlay manual
df0cd8c5
JB
9275@cindex manual overlay debugging
9276Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
9277relies on you to tell it which overlays are mapped, and which are not,
9278using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
9279commands described below.
9280
9281@item overlay map-overlay @var{overlay}
9282@itemx overlay map @var{overlay}
df0cd8c5
JB
9283@cindex map an overlay
9284Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
9285be the name of the object file section containing the overlay. When an
9286overlay is mapped, @value{GDBN} assumes it can find the overlay's
9287functions and variables at their mapped addresses. @value{GDBN} assumes
9288that any other overlays whose mapped ranges overlap that of
9289@var{overlay} are now unmapped.
9290
9291@item overlay unmap-overlay @var{overlay}
9292@itemx overlay unmap @var{overlay}
df0cd8c5
JB
9293@cindex unmap an overlay
9294Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
9295must be the name of the object file section containing the overlay.
9296When an overlay is unmapped, @value{GDBN} assumes it can find the
9297overlay's functions and variables at their load addresses.
9298
9299@item overlay auto
df0cd8c5
JB
9300Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
9301consults a data structure the overlay manager maintains in the inferior
9302to see which overlays are mapped. For details, see @ref{Automatic
9303Overlay Debugging}.
9304
9305@item overlay load-target
9306@itemx overlay load
df0cd8c5
JB
9307@cindex reloading the overlay table
9308Re-read the overlay table from the inferior. Normally, @value{GDBN}
9309re-reads the table @value{GDBN} automatically each time the inferior
9310stops, so this command should only be necessary if you have changed the
9311overlay mapping yourself using @value{GDBN}. This command is only
9312useful when using automatic overlay debugging.
9313
9314@item overlay list-overlays
9315@itemx overlay list
9316@cindex listing mapped overlays
9317Display a list of the overlays currently mapped, along with their mapped
9318addresses, load addresses, and sizes.
9319
9320@end table
9321
9322Normally, when @value{GDBN} prints a code address, it includes the name
9323of the function the address falls in:
9324
474c8240 9325@smallexample
f7dc1244 9326(@value{GDBP}) print main
df0cd8c5 9327$3 = @{int ()@} 0x11a0 <main>
474c8240 9328@end smallexample
df0cd8c5
JB
9329@noindent
9330When overlay debugging is enabled, @value{GDBN} recognizes code in
9331unmapped overlays, and prints the names of unmapped functions with
9332asterisks around them. For example, if @code{foo} is a function in an
9333unmapped overlay, @value{GDBN} prints it this way:
9334
474c8240 9335@smallexample
f7dc1244 9336(@value{GDBP}) overlay list
df0cd8c5 9337No sections are mapped.
f7dc1244 9338(@value{GDBP}) print foo
df0cd8c5 9339$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 9340@end smallexample
df0cd8c5
JB
9341@noindent
9342When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
9343name normally:
9344
474c8240 9345@smallexample
f7dc1244 9346(@value{GDBP}) overlay list
b383017d 9347Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 9348 mapped at 0x1016 - 0x104a
f7dc1244 9349(@value{GDBP}) print foo
df0cd8c5 9350$6 = @{int (int)@} 0x1016 <foo>
474c8240 9351@end smallexample
df0cd8c5
JB
9352
9353When overlay debugging is enabled, @value{GDBN} can find the correct
9354address for functions and variables in an overlay, whether or not the
9355overlay is mapped. This allows most @value{GDBN} commands, like
9356@code{break} and @code{disassemble}, to work normally, even on unmapped
9357code. However, @value{GDBN}'s breakpoint support has some limitations:
9358
9359@itemize @bullet
9360@item
9361@cindex breakpoints in overlays
9362@cindex overlays, setting breakpoints in
9363You can set breakpoints in functions in unmapped overlays, as long as
9364@value{GDBN} can write to the overlay at its load address.
9365@item
9366@value{GDBN} can not set hardware or simulator-based breakpoints in
9367unmapped overlays. However, if you set a breakpoint at the end of your
9368overlay manager (and tell @value{GDBN} which overlays are now mapped, if
9369you are using manual overlay management), @value{GDBN} will re-set its
9370breakpoints properly.
9371@end itemize
9372
9373
9374@node Automatic Overlay Debugging
9375@section Automatic Overlay Debugging
9376@cindex automatic overlay debugging
9377
9378@value{GDBN} can automatically track which overlays are mapped and which
9379are not, given some simple co-operation from the overlay manager in the
9380inferior. If you enable automatic overlay debugging with the
9381@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
9382looks in the inferior's memory for certain variables describing the
9383current state of the overlays.
9384
9385Here are the variables your overlay manager must define to support
9386@value{GDBN}'s automatic overlay debugging:
9387
9388@table @asis
9389
9390@item @code{_ovly_table}:
9391This variable must be an array of the following structures:
9392
474c8240 9393@smallexample
df0cd8c5
JB
9394struct
9395@{
9396 /* The overlay's mapped address. */
9397 unsigned long vma;
9398
9399 /* The size of the overlay, in bytes. */
9400 unsigned long size;
9401
9402 /* The overlay's load address. */
9403 unsigned long lma;
9404
9405 /* Non-zero if the overlay is currently mapped;
9406 zero otherwise. */
9407 unsigned long mapped;
9408@}
474c8240 9409@end smallexample
df0cd8c5
JB
9410
9411@item @code{_novlys}:
9412This variable must be a four-byte signed integer, holding the total
9413number of elements in @code{_ovly_table}.
9414
9415@end table
9416
9417To decide whether a particular overlay is mapped or not, @value{GDBN}
9418looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
9419@code{lma} members equal the VMA and LMA of the overlay's section in the
9420executable file. When @value{GDBN} finds a matching entry, it consults
9421the entry's @code{mapped} member to determine whether the overlay is
9422currently mapped.
9423
81d46470 9424In addition, your overlay manager may define a function called
def71bfa 9425@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
9426will silently set a breakpoint there. If the overlay manager then
9427calls this function whenever it has changed the overlay table, this
9428will enable @value{GDBN} to accurately keep track of which overlays
9429are in program memory, and update any breakpoints that may be set
b383017d 9430in overlays. This will allow breakpoints to work even if the
81d46470
MS
9431overlays are kept in ROM or other non-writable memory while they
9432are not being executed.
df0cd8c5
JB
9433
9434@node Overlay Sample Program
9435@section Overlay Sample Program
9436@cindex overlay example program
9437
9438When linking a program which uses overlays, you must place the overlays
9439at their load addresses, while relocating them to run at their mapped
9440addresses. To do this, you must write a linker script (@pxref{Overlay
9441Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
9442since linker scripts are specific to a particular host system, target
9443architecture, and target memory layout, this manual cannot provide
9444portable sample code demonstrating @value{GDBN}'s overlay support.
9445
9446However, the @value{GDBN} source distribution does contain an overlaid
9447program, with linker scripts for a few systems, as part of its test
9448suite. The program consists of the following files from
9449@file{gdb/testsuite/gdb.base}:
9450
9451@table @file
9452@item overlays.c
9453The main program file.
9454@item ovlymgr.c
9455A simple overlay manager, used by @file{overlays.c}.
9456@item foo.c
9457@itemx bar.c
9458@itemx baz.c
9459@itemx grbx.c
9460Overlay modules, loaded and used by @file{overlays.c}.
9461@item d10v.ld
9462@itemx m32r.ld
9463Linker scripts for linking the test program on the @code{d10v-elf}
9464and @code{m32r-elf} targets.
9465@end table
9466
9467You can build the test program using the @code{d10v-elf} GCC
9468cross-compiler like this:
9469
474c8240 9470@smallexample
df0cd8c5
JB
9471$ d10v-elf-gcc -g -c overlays.c
9472$ d10v-elf-gcc -g -c ovlymgr.c
9473$ d10v-elf-gcc -g -c foo.c
9474$ d10v-elf-gcc -g -c bar.c
9475$ d10v-elf-gcc -g -c baz.c
9476$ d10v-elf-gcc -g -c grbx.c
9477$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
9478 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 9479@end smallexample
df0cd8c5
JB
9480
9481The build process is identical for any other architecture, except that
9482you must substitute the appropriate compiler and linker script for the
9483target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
9484
9485
6d2ebf8b 9486@node Languages
c906108c
SS
9487@chapter Using @value{GDBN} with Different Languages
9488@cindex languages
9489
c906108c
SS
9490Although programming languages generally have common aspects, they are
9491rarely expressed in the same manner. For instance, in ANSI C,
9492dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
9493Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 9494represented (and displayed) differently. Hex numbers in C appear as
c906108c 9495@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
9496
9497@cindex working language
9498Language-specific information is built into @value{GDBN} for some languages,
9499allowing you to express operations like the above in your program's
9500native language, and allowing @value{GDBN} to output values in a manner
9501consistent with the syntax of your program's native language. The
9502language you use to build expressions is called the @dfn{working
9503language}.
9504
9505@menu
9506* Setting:: Switching between source languages
9507* Show:: Displaying the language
c906108c 9508* Checks:: Type and range checks
79a6e687
BW
9509* Supported Languages:: Supported languages
9510* Unsupported Languages:: Unsupported languages
c906108c
SS
9511@end menu
9512
6d2ebf8b 9513@node Setting
79a6e687 9514@section Switching Between Source Languages
c906108c
SS
9515
9516There are two ways to control the working language---either have @value{GDBN}
9517set it automatically, or select it manually yourself. You can use the
9518@code{set language} command for either purpose. On startup, @value{GDBN}
9519defaults to setting the language automatically. The working language is
9520used to determine how expressions you type are interpreted, how values
9521are printed, etc.
9522
9523In addition to the working language, every source file that
9524@value{GDBN} knows about has its own working language. For some object
9525file formats, the compiler might indicate which language a particular
9526source file is in. However, most of the time @value{GDBN} infers the
9527language from the name of the file. The language of a source file
b37052ae 9528controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 9529show each frame appropriately for its own language. There is no way to
d4f3574e
SS
9530set the language of a source file from within @value{GDBN}, but you can
9531set the language associated with a filename extension. @xref{Show, ,
79a6e687 9532Displaying the Language}.
c906108c
SS
9533
9534This is most commonly a problem when you use a program, such
5d161b24 9535as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
9536another language. In that case, make the
9537program use @code{#line} directives in its C output; that way
9538@value{GDBN} will know the correct language of the source code of the original
9539program, and will display that source code, not the generated C code.
9540
9541@menu
9542* Filenames:: Filename extensions and languages.
9543* Manually:: Setting the working language manually
9544* Automatically:: Having @value{GDBN} infer the source language
9545@end menu
9546
6d2ebf8b 9547@node Filenames
79a6e687 9548@subsection List of Filename Extensions and Languages
c906108c
SS
9549
9550If a source file name ends in one of the following extensions, then
9551@value{GDBN} infers that its language is the one indicated.
9552
9553@table @file
e07c999f
PH
9554@item .ada
9555@itemx .ads
9556@itemx .adb
9557@itemx .a
9558Ada source file.
c906108c
SS
9559
9560@item .c
9561C source file
9562
9563@item .C
9564@itemx .cc
9565@itemx .cp
9566@itemx .cpp
9567@itemx .cxx
9568@itemx .c++
b37052ae 9569C@t{++} source file
c906108c 9570
b37303ee
AF
9571@item .m
9572Objective-C source file
9573
c906108c
SS
9574@item .f
9575@itemx .F
9576Fortran source file
9577
c906108c
SS
9578@item .mod
9579Modula-2 source file
c906108c
SS
9580
9581@item .s
9582@itemx .S
9583Assembler source file. This actually behaves almost like C, but
9584@value{GDBN} does not skip over function prologues when stepping.
9585@end table
9586
9587In addition, you may set the language associated with a filename
79a6e687 9588extension. @xref{Show, , Displaying the Language}.
c906108c 9589
6d2ebf8b 9590@node Manually
79a6e687 9591@subsection Setting the Working Language
c906108c
SS
9592
9593If you allow @value{GDBN} to set the language automatically,
9594expressions are interpreted the same way in your debugging session and
9595your program.
9596
9597@kindex set language
9598If you wish, you may set the language manually. To do this, issue the
9599command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 9600a language, such as
c906108c 9601@code{c} or @code{modula-2}.
c906108c
SS
9602For a list of the supported languages, type @samp{set language}.
9603
c906108c
SS
9604Setting the language manually prevents @value{GDBN} from updating the working
9605language automatically. This can lead to confusion if you try
9606to debug a program when the working language is not the same as the
9607source language, when an expression is acceptable to both
9608languages---but means different things. For instance, if the current
9609source file were written in C, and @value{GDBN} was parsing Modula-2, a
9610command such as:
9611
474c8240 9612@smallexample
c906108c 9613print a = b + c
474c8240 9614@end smallexample
c906108c
SS
9615
9616@noindent
9617might not have the effect you intended. In C, this means to add
9618@code{b} and @code{c} and place the result in @code{a}. The result
9619printed would be the value of @code{a}. In Modula-2, this means to compare
9620@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 9621
6d2ebf8b 9622@node Automatically
79a6e687 9623@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
9624
9625To have @value{GDBN} set the working language automatically, use
9626@samp{set language local} or @samp{set language auto}. @value{GDBN}
9627then infers the working language. That is, when your program stops in a
9628frame (usually by encountering a breakpoint), @value{GDBN} sets the
9629working language to the language recorded for the function in that
9630frame. If the language for a frame is unknown (that is, if the function
9631or block corresponding to the frame was defined in a source file that
9632does not have a recognized extension), the current working language is
9633not changed, and @value{GDBN} issues a warning.
9634
9635This may not seem necessary for most programs, which are written
9636entirely in one source language. However, program modules and libraries
9637written in one source language can be used by a main program written in
9638a different source language. Using @samp{set language auto} in this
9639case frees you from having to set the working language manually.
9640
6d2ebf8b 9641@node Show
79a6e687 9642@section Displaying the Language
c906108c
SS
9643
9644The following commands help you find out which language is the
9645working language, and also what language source files were written in.
9646
c906108c
SS
9647@table @code
9648@item show language
9c16f35a 9649@kindex show language
c906108c
SS
9650Display the current working language. This is the
9651language you can use with commands such as @code{print} to
9652build and compute expressions that may involve variables in your program.
9653
9654@item info frame
4644b6e3 9655@kindex info frame@r{, show the source language}
5d161b24 9656Display the source language for this frame. This language becomes the
c906108c 9657working language if you use an identifier from this frame.
79a6e687 9658@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
9659information listed here.
9660
9661@item info source
4644b6e3 9662@kindex info source@r{, show the source language}
c906108c 9663Display the source language of this source file.
5d161b24 9664@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
9665information listed here.
9666@end table
9667
9668In unusual circumstances, you may have source files with extensions
9669not in the standard list. You can then set the extension associated
9670with a language explicitly:
9671
c906108c 9672@table @code
09d4efe1 9673@item set extension-language @var{ext} @var{language}
9c16f35a 9674@kindex set extension-language
09d4efe1
EZ
9675Tell @value{GDBN} that source files with extension @var{ext} are to be
9676assumed as written in the source language @var{language}.
c906108c
SS
9677
9678@item info extensions
9c16f35a 9679@kindex info extensions
c906108c
SS
9680List all the filename extensions and the associated languages.
9681@end table
9682
6d2ebf8b 9683@node Checks
79a6e687 9684@section Type and Range Checking
c906108c
SS
9685
9686@quotation
9687@emph{Warning:} In this release, the @value{GDBN} commands for type and range
9688checking are included, but they do not yet have any effect. This
9689section documents the intended facilities.
9690@end quotation
9691@c FIXME remove warning when type/range code added
9692
9693Some languages are designed to guard you against making seemingly common
9694errors through a series of compile- and run-time checks. These include
9695checking the type of arguments to functions and operators, and making
9696sure mathematical overflows are caught at run time. Checks such as
9697these help to ensure a program's correctness once it has been compiled
9698by eliminating type mismatches, and providing active checks for range
9699errors when your program is running.
9700
9701@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
9702Although @value{GDBN} does not check the statements in your program,
9703it can check expressions entered directly into @value{GDBN} for
9704evaluation via the @code{print} command, for example. As with the
9705working language, @value{GDBN} can also decide whether or not to check
9706automatically based on your program's source language.
79a6e687 9707@xref{Supported Languages, ,Supported Languages}, for the default
9c16f35a 9708settings of supported languages.
c906108c
SS
9709
9710@menu
9711* Type Checking:: An overview of type checking
9712* Range Checking:: An overview of range checking
9713@end menu
9714
9715@cindex type checking
9716@cindex checks, type
6d2ebf8b 9717@node Type Checking
79a6e687 9718@subsection An Overview of Type Checking
c906108c
SS
9719
9720Some languages, such as Modula-2, are strongly typed, meaning that the
9721arguments to operators and functions have to be of the correct type,
9722otherwise an error occurs. These checks prevent type mismatch
9723errors from ever causing any run-time problems. For example,
9724
9725@smallexample
97261 + 2 @result{} 3
9727@exdent but
9728@error{} 1 + 2.3
9729@end smallexample
9730
9731The second example fails because the @code{CARDINAL} 1 is not
9732type-compatible with the @code{REAL} 2.3.
9733
5d161b24
DB
9734For the expressions you use in @value{GDBN} commands, you can tell the
9735@value{GDBN} type checker to skip checking;
9736to treat any mismatches as errors and abandon the expression;
9737or to only issue warnings when type mismatches occur,
c906108c
SS
9738but evaluate the expression anyway. When you choose the last of
9739these, @value{GDBN} evaluates expressions like the second example above, but
9740also issues a warning.
9741
5d161b24
DB
9742Even if you turn type checking off, there may be other reasons
9743related to type that prevent @value{GDBN} from evaluating an expression.
9744For instance, @value{GDBN} does not know how to add an @code{int} and
9745a @code{struct foo}. These particular type errors have nothing to do
9746with the language in use, and usually arise from expressions, such as
c906108c
SS
9747the one described above, which make little sense to evaluate anyway.
9748
9749Each language defines to what degree it is strict about type. For
9750instance, both Modula-2 and C require the arguments to arithmetical
9751operators to be numbers. In C, enumerated types and pointers can be
9752represented as numbers, so that they are valid arguments to mathematical
79a6e687 9753operators. @xref{Supported Languages, ,Supported Languages}, for further
c906108c
SS
9754details on specific languages.
9755
9756@value{GDBN} provides some additional commands for controlling the type checker:
9757
c906108c
SS
9758@kindex set check type
9759@kindex show check type
9760@table @code
9761@item set check type auto
9762Set type checking on or off based on the current working language.
79a6e687 9763@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
9764each language.
9765
9766@item set check type on
9767@itemx set check type off
9768Set type checking on or off, overriding the default setting for the
9769current working language. Issue a warning if the setting does not
9770match the language default. If any type mismatches occur in
d4f3574e 9771evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
9772message and aborts evaluation of the expression.
9773
9774@item set check type warn
9775Cause the type checker to issue warnings, but to always attempt to
9776evaluate the expression. Evaluating the expression may still
9777be impossible for other reasons. For example, @value{GDBN} cannot add
9778numbers and structures.
9779
9780@item show type
5d161b24 9781Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
9782is setting it automatically.
9783@end table
9784
9785@cindex range checking
9786@cindex checks, range
6d2ebf8b 9787@node Range Checking
79a6e687 9788@subsection An Overview of Range Checking
c906108c
SS
9789
9790In some languages (such as Modula-2), it is an error to exceed the
9791bounds of a type; this is enforced with run-time checks. Such range
9792checking is meant to ensure program correctness by making sure
9793computations do not overflow, or indices on an array element access do
9794not exceed the bounds of the array.
9795
9796For expressions you use in @value{GDBN} commands, you can tell
9797@value{GDBN} to treat range errors in one of three ways: ignore them,
9798always treat them as errors and abandon the expression, or issue
9799warnings but evaluate the expression anyway.
9800
9801A range error can result from numerical overflow, from exceeding an
9802array index bound, or when you type a constant that is not a member
9803of any type. Some languages, however, do not treat overflows as an
9804error. In many implementations of C, mathematical overflow causes the
9805result to ``wrap around'' to lower values---for example, if @var{m} is
9806the largest integer value, and @var{s} is the smallest, then
9807
474c8240 9808@smallexample
c906108c 9809@var{m} + 1 @result{} @var{s}
474c8240 9810@end smallexample
c906108c
SS
9811
9812This, too, is specific to individual languages, and in some cases
79a6e687
BW
9813specific to individual compilers or machines. @xref{Supported Languages, ,
9814Supported Languages}, for further details on specific languages.
c906108c
SS
9815
9816@value{GDBN} provides some additional commands for controlling the range checker:
9817
c906108c
SS
9818@kindex set check range
9819@kindex show check range
9820@table @code
9821@item set check range auto
9822Set range checking on or off based on the current working language.
79a6e687 9823@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
9824each language.
9825
9826@item set check range on
9827@itemx set check range off
9828Set range checking on or off, overriding the default setting for the
9829current working language. A warning is issued if the setting does not
c3f6f71d
JM
9830match the language default. If a range error occurs and range checking is on,
9831then a message is printed and evaluation of the expression is aborted.
c906108c
SS
9832
9833@item set check range warn
9834Output messages when the @value{GDBN} range checker detects a range error,
9835but attempt to evaluate the expression anyway. Evaluating the
9836expression may still be impossible for other reasons, such as accessing
9837memory that the process does not own (a typical example from many Unix
9838systems).
9839
9840@item show range
9841Show the current setting of the range checker, and whether or not it is
9842being set automatically by @value{GDBN}.
9843@end table
c906108c 9844
79a6e687
BW
9845@node Supported Languages
9846@section Supported Languages
c906108c 9847
9c16f35a
EZ
9848@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
9849assembly, Modula-2, and Ada.
cce74817 9850@c This is false ...
c906108c
SS
9851Some @value{GDBN} features may be used in expressions regardless of the
9852language you use: the @value{GDBN} @code{@@} and @code{::} operators,
9853and the @samp{@{type@}addr} construct (@pxref{Expressions,
9854,Expressions}) can be used with the constructs of any supported
9855language.
9856
9857The following sections detail to what degree each source language is
9858supported by @value{GDBN}. These sections are not meant to be language
9859tutorials or references, but serve only as a reference guide to what the
9860@value{GDBN} expression parser accepts, and what input and output
9861formats should look like for different languages. There are many good
9862books written on each of these languages; please look to these for a
9863language reference or tutorial.
9864
c906108c 9865@menu
b37303ee 9866* C:: C and C@t{++}
b383017d 9867* Objective-C:: Objective-C
09d4efe1 9868* Fortran:: Fortran
9c16f35a 9869* Pascal:: Pascal
b37303ee 9870* Modula-2:: Modula-2
e07c999f 9871* Ada:: Ada
c906108c
SS
9872@end menu
9873
6d2ebf8b 9874@node C
b37052ae 9875@subsection C and C@t{++}
7a292a7a 9876
b37052ae
EZ
9877@cindex C and C@t{++}
9878@cindex expressions in C or C@t{++}
c906108c 9879
b37052ae 9880Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
9881to both languages. Whenever this is the case, we discuss those languages
9882together.
9883
41afff9a
EZ
9884@cindex C@t{++}
9885@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
9886@cindex @sc{gnu} C@t{++}
9887The C@t{++} debugging facilities are jointly implemented by the C@t{++}
9888compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
9889effectively, you must compile your C@t{++} programs with a supported
9890C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
9891compiler (@code{aCC}).
9892
0179ffac
DC
9893For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
9894format; if it doesn't work on your system, try the stabs+ debugging
9895format. You can select those formats explicitly with the @code{g++}
9896command-line options @option{-gdwarf-2} and @option{-gstabs+}.
ce9341a1
BW
9897@xref{Debugging Options,,Options for Debugging Your Program or GCC,
9898gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}.
c906108c 9899
c906108c 9900@menu
b37052ae
EZ
9901* C Operators:: C and C@t{++} operators
9902* C Constants:: C and C@t{++} constants
79a6e687 9903* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
9904* C Defaults:: Default settings for C and C@t{++}
9905* C Checks:: C and C@t{++} type and range checks
c906108c 9906* Debugging C:: @value{GDBN} and C
79a6e687 9907* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 9908* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 9909@end menu
c906108c 9910
6d2ebf8b 9911@node C Operators
79a6e687 9912@subsubsection C and C@t{++} Operators
7a292a7a 9913
b37052ae 9914@cindex C and C@t{++} operators
c906108c
SS
9915
9916Operators must be defined on values of specific types. For instance,
9917@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 9918often defined on groups of types.
c906108c 9919
b37052ae 9920For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
9921
9922@itemize @bullet
53a5351d 9923
c906108c 9924@item
c906108c 9925@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 9926specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
9927
9928@item
d4f3574e
SS
9929@emph{Floating-point types} include @code{float}, @code{double}, and
9930@code{long double} (if supported by the target platform).
c906108c
SS
9931
9932@item
53a5351d 9933@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
9934
9935@item
9936@emph{Scalar types} include all of the above.
53a5351d 9937
c906108c
SS
9938@end itemize
9939
9940@noindent
9941The following operators are supported. They are listed here
9942in order of increasing precedence:
9943
9944@table @code
9945@item ,
9946The comma or sequencing operator. Expressions in a comma-separated list
9947are evaluated from left to right, with the result of the entire
9948expression being the last expression evaluated.
9949
9950@item =
9951Assignment. The value of an assignment expression is the value
9952assigned. Defined on scalar types.
9953
9954@item @var{op}=
9955Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
9956and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 9957@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
9958@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
9959@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
9960
9961@item ?:
9962The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
9963of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
9964integral type.
9965
9966@item ||
9967Logical @sc{or}. Defined on integral types.
9968
9969@item &&
9970Logical @sc{and}. Defined on integral types.
9971
9972@item |
9973Bitwise @sc{or}. Defined on integral types.
9974
9975@item ^
9976Bitwise exclusive-@sc{or}. Defined on integral types.
9977
9978@item &
9979Bitwise @sc{and}. Defined on integral types.
9980
9981@item ==@r{, }!=
9982Equality and inequality. Defined on scalar types. The value of these
9983expressions is 0 for false and non-zero for true.
9984
9985@item <@r{, }>@r{, }<=@r{, }>=
9986Less than, greater than, less than or equal, greater than or equal.
9987Defined on scalar types. The value of these expressions is 0 for false
9988and non-zero for true.
9989
9990@item <<@r{, }>>
9991left shift, and right shift. Defined on integral types.
9992
9993@item @@
9994The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9995
9996@item +@r{, }-
9997Addition and subtraction. Defined on integral types, floating-point types and
9998pointer types.
9999
10000@item *@r{, }/@r{, }%
10001Multiplication, division, and modulus. Multiplication and division are
10002defined on integral and floating-point types. Modulus is defined on
10003integral types.
10004
10005@item ++@r{, }--
10006Increment and decrement. When appearing before a variable, the
10007operation is performed before the variable is used in an expression;
10008when appearing after it, the variable's value is used before the
10009operation takes place.
10010
10011@item *
10012Pointer dereferencing. Defined on pointer types. Same precedence as
10013@code{++}.
10014
10015@item &
10016Address operator. Defined on variables. Same precedence as @code{++}.
10017
b37052ae
EZ
10018For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
10019allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 10020to examine the address
b37052ae 10021where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 10022stored.
c906108c
SS
10023
10024@item -
10025Negative. Defined on integral and floating-point types. Same
10026precedence as @code{++}.
10027
10028@item !
10029Logical negation. Defined on integral types. Same precedence as
10030@code{++}.
10031
10032@item ~
10033Bitwise complement operator. Defined on integral types. Same precedence as
10034@code{++}.
10035
10036
10037@item .@r{, }->
10038Structure member, and pointer-to-structure member. For convenience,
10039@value{GDBN} regards the two as equivalent, choosing whether to dereference a
10040pointer based on the stored type information.
10041Defined on @code{struct} and @code{union} data.
10042
c906108c
SS
10043@item .*@r{, }->*
10044Dereferences of pointers to members.
c906108c
SS
10045
10046@item []
10047Array indexing. @code{@var{a}[@var{i}]} is defined as
10048@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
10049
10050@item ()
10051Function parameter list. Same precedence as @code{->}.
10052
c906108c 10053@item ::
b37052ae 10054C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 10055and @code{class} types.
c906108c
SS
10056
10057@item ::
7a292a7a
SS
10058Doubled colons also represent the @value{GDBN} scope operator
10059(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
10060above.
c906108c
SS
10061@end table
10062
c906108c
SS
10063If an operator is redefined in the user code, @value{GDBN} usually
10064attempts to invoke the redefined version instead of using the operator's
10065predefined meaning.
c906108c 10066
6d2ebf8b 10067@node C Constants
79a6e687 10068@subsubsection C and C@t{++} Constants
c906108c 10069
b37052ae 10070@cindex C and C@t{++} constants
c906108c 10071
b37052ae 10072@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 10073following ways:
c906108c
SS
10074
10075@itemize @bullet
10076@item
10077Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
10078specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
10079by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
10080@samp{l}, specifying that the constant should be treated as a
10081@code{long} value.
10082
10083@item
10084Floating point constants are a sequence of digits, followed by a decimal
10085point, followed by a sequence of digits, and optionally followed by an
10086exponent. An exponent is of the form:
10087@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
10088sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
10089A floating-point constant may also end with a letter @samp{f} or
10090@samp{F}, specifying that the constant should be treated as being of
10091the @code{float} (as opposed to the default @code{double}) type; or with
10092a letter @samp{l} or @samp{L}, which specifies a @code{long double}
10093constant.
c906108c
SS
10094
10095@item
10096Enumerated constants consist of enumerated identifiers, or their
10097integral equivalents.
10098
10099@item
10100Character constants are a single character surrounded by single quotes
10101(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 10102(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
10103be represented by a letter or by @dfn{escape sequences}, which are of
10104the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
10105of the character's ordinal value; or of the form @samp{\@var{x}}, where
10106@samp{@var{x}} is a predefined special character---for example,
10107@samp{\n} for newline.
10108
10109@item
96a2c332
SS
10110String constants are a sequence of character constants surrounded by
10111double quotes (@code{"}). Any valid character constant (as described
10112above) may appear. Double quotes within the string must be preceded by
10113a backslash, so for instance @samp{"a\"b'c"} is a string of five
10114characters.
c906108c
SS
10115
10116@item
10117Pointer constants are an integral value. You can also write pointers
10118to constants using the C operator @samp{&}.
10119
10120@item
10121Array constants are comma-separated lists surrounded by braces @samp{@{}
10122and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
10123integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
10124and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
10125@end itemize
10126
79a6e687
BW
10127@node C Plus Plus Expressions
10128@subsubsection C@t{++} Expressions
b37052ae
EZ
10129
10130@cindex expressions in C@t{++}
10131@value{GDBN} expression handling can interpret most C@t{++} expressions.
10132
0179ffac
DC
10133@cindex debugging C@t{++} programs
10134@cindex C@t{++} compilers
10135@cindex debug formats and C@t{++}
10136@cindex @value{NGCC} and C@t{++}
c906108c 10137@quotation
b37052ae 10138@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
10139proper compiler and the proper debug format. Currently, @value{GDBN}
10140works best when debugging C@t{++} code that is compiled with
10141@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
10142@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
10143stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
10144stabs+ as their default debug format, so you usually don't need to
10145specify a debug format explicitly. Other compilers and/or debug formats
10146are likely to work badly or not at all when using @value{GDBN} to debug
10147C@t{++} code.
c906108c 10148@end quotation
c906108c
SS
10149
10150@enumerate
10151
10152@cindex member functions
10153@item
10154Member function calls are allowed; you can use expressions like
10155
474c8240 10156@smallexample
c906108c 10157count = aml->GetOriginal(x, y)
474c8240 10158@end smallexample
c906108c 10159
41afff9a 10160@vindex this@r{, inside C@t{++} member functions}
b37052ae 10161@cindex namespace in C@t{++}
c906108c
SS
10162@item
10163While a member function is active (in the selected stack frame), your
10164expressions have the same namespace available as the member function;
10165that is, @value{GDBN} allows implicit references to the class instance
b37052ae 10166pointer @code{this} following the same rules as C@t{++}.
c906108c 10167
c906108c 10168@cindex call overloaded functions
d4f3574e 10169@cindex overloaded functions, calling
b37052ae 10170@cindex type conversions in C@t{++}
c906108c
SS
10171@item
10172You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 10173call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
10174perform overload resolution involving user-defined type conversions,
10175calls to constructors, or instantiations of templates that do not exist
10176in the program. It also cannot handle ellipsis argument lists or
10177default arguments.
10178
10179It does perform integral conversions and promotions, floating-point
10180promotions, arithmetic conversions, pointer conversions, conversions of
10181class objects to base classes, and standard conversions such as those of
10182functions or arrays to pointers; it requires an exact match on the
10183number of function arguments.
10184
10185Overload resolution is always performed, unless you have specified
79a6e687
BW
10186@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
10187,@value{GDBN} Features for C@t{++}}.
c906108c 10188
d4f3574e 10189You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
10190explicit function signature to call an overloaded function, as in
10191@smallexample
10192p 'foo(char,int)'('x', 13)
10193@end smallexample
d4f3574e 10194
c906108c 10195The @value{GDBN} command-completion facility can simplify this;
79a6e687 10196see @ref{Completion, ,Command Completion}.
c906108c 10197
c906108c
SS
10198@cindex reference declarations
10199@item
b37052ae
EZ
10200@value{GDBN} understands variables declared as C@t{++} references; you can use
10201them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
10202dereferenced.
10203
10204In the parameter list shown when @value{GDBN} displays a frame, the values of
10205reference variables are not displayed (unlike other variables); this
10206avoids clutter, since references are often used for large structures.
10207The @emph{address} of a reference variable is always shown, unless
10208you have specified @samp{set print address off}.
10209
10210@item
b37052ae 10211@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
10212expressions can use it just as expressions in your program do. Since
10213one scope may be defined in another, you can use @code{::} repeatedly if
10214necessary, for example in an expression like
10215@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 10216resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 10217debugging (@pxref{Variables, ,Program Variables}).
c906108c
SS
10218@end enumerate
10219
b37052ae 10220In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
10221calling virtual functions correctly, printing out virtual bases of
10222objects, calling functions in a base subobject, casting objects, and
10223invoking user-defined operators.
c906108c 10224
6d2ebf8b 10225@node C Defaults
79a6e687 10226@subsubsection C and C@t{++} Defaults
7a292a7a 10227
b37052ae 10228@cindex C and C@t{++} defaults
c906108c 10229
c906108c
SS
10230If you allow @value{GDBN} to set type and range checking automatically, they
10231both default to @code{off} whenever the working language changes to
b37052ae 10232C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 10233selects the working language.
c906108c
SS
10234
10235If you allow @value{GDBN} to set the language automatically, it
10236recognizes source files whose names end with @file{.c}, @file{.C}, or
10237@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 10238these files, it sets the working language to C or C@t{++}.
79a6e687 10239@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
10240for further details.
10241
c906108c
SS
10242@c Type checking is (a) primarily motivated by Modula-2, and (b)
10243@c unimplemented. If (b) changes, it might make sense to let this node
10244@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 10245
6d2ebf8b 10246@node C Checks
79a6e687 10247@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 10248
b37052ae 10249@cindex C and C@t{++} checks
c906108c 10250
b37052ae 10251By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
10252is not used. However, if you turn type checking on, @value{GDBN}
10253considers two variables type equivalent if:
10254
10255@itemize @bullet
10256@item
10257The two variables are structured and have the same structure, union, or
10258enumerated tag.
10259
10260@item
10261The two variables have the same type name, or types that have been
10262declared equivalent through @code{typedef}.
10263
10264@ignore
10265@c leaving this out because neither J Gilmore nor R Pesch understand it.
10266@c FIXME--beers?
10267@item
10268The two @code{struct}, @code{union}, or @code{enum} variables are
10269declared in the same declaration. (Note: this may not be true for all C
10270compilers.)
10271@end ignore
10272@end itemize
10273
10274Range checking, if turned on, is done on mathematical operations. Array
10275indices are not checked, since they are often used to index a pointer
10276that is not itself an array.
c906108c 10277
6d2ebf8b 10278@node Debugging C
c906108c 10279@subsubsection @value{GDBN} and C
c906108c
SS
10280
10281The @code{set print union} and @code{show print union} commands apply to
10282the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
10283inside a @code{struct} or @code{class} is also printed. Otherwise, it
10284appears as @samp{@{...@}}.
c906108c
SS
10285
10286The @code{@@} operator aids in the debugging of dynamic arrays, formed
10287with pointers and a memory allocation function. @xref{Expressions,
10288,Expressions}.
10289
79a6e687
BW
10290@node Debugging C Plus Plus
10291@subsubsection @value{GDBN} Features for C@t{++}
c906108c 10292
b37052ae 10293@cindex commands for C@t{++}
7a292a7a 10294
b37052ae
EZ
10295Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
10296designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
10297
10298@table @code
10299@cindex break in overloaded functions
10300@item @r{breakpoint menus}
10301When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
10302@value{GDBN} has the capability to display a menu of possible breakpoint
10303locations to help you specify which function definition you want.
10304@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 10305
b37052ae 10306@cindex overloading in C@t{++}
c906108c
SS
10307@item rbreak @var{regex}
10308Setting breakpoints using regular expressions is helpful for setting
10309breakpoints on overloaded functions that are not members of any special
10310classes.
79a6e687 10311@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 10312
b37052ae 10313@cindex C@t{++} exception handling
c906108c
SS
10314@item catch throw
10315@itemx catch catch
b37052ae 10316Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 10317Catchpoints, , Setting Catchpoints}.
c906108c
SS
10318
10319@cindex inheritance
10320@item ptype @var{typename}
10321Print inheritance relationships as well as other information for type
10322@var{typename}.
10323@xref{Symbols, ,Examining the Symbol Table}.
10324
b37052ae 10325@cindex C@t{++} symbol display
c906108c
SS
10326@item set print demangle
10327@itemx show print demangle
10328@itemx set print asm-demangle
10329@itemx show print asm-demangle
b37052ae
EZ
10330Control whether C@t{++} symbols display in their source form, both when
10331displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 10332@xref{Print Settings, ,Print Settings}.
c906108c
SS
10333
10334@item set print object
10335@itemx show print object
10336Choose whether to print derived (actual) or declared types of objects.
79a6e687 10337@xref{Print Settings, ,Print Settings}.
c906108c
SS
10338
10339@item set print vtbl
10340@itemx show print vtbl
10341Control the format for printing virtual function tables.
79a6e687 10342@xref{Print Settings, ,Print Settings}.
c906108c 10343(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 10344ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
10345
10346@kindex set overload-resolution
d4f3574e 10347@cindex overloaded functions, overload resolution
c906108c 10348@item set overload-resolution on
b37052ae 10349Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
10350is on. For overloaded functions, @value{GDBN} evaluates the arguments
10351and searches for a function whose signature matches the argument types,
79a6e687
BW
10352using the standard C@t{++} conversion rules (see @ref{C Plus Plus
10353Expressions, ,C@t{++} Expressions}, for details).
10354If it cannot find a match, it emits a message.
c906108c
SS
10355
10356@item set overload-resolution off
b37052ae 10357Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
10358overloaded functions that are not class member functions, @value{GDBN}
10359chooses the first function of the specified name that it finds in the
10360symbol table, whether or not its arguments are of the correct type. For
10361overloaded functions that are class member functions, @value{GDBN}
10362searches for a function whose signature @emph{exactly} matches the
10363argument types.
c906108c 10364
9c16f35a
EZ
10365@kindex show overload-resolution
10366@item show overload-resolution
10367Show the current setting of overload resolution.
10368
c906108c
SS
10369@item @r{Overloaded symbol names}
10370You can specify a particular definition of an overloaded symbol, using
b37052ae 10371the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
10372@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
10373also use the @value{GDBN} command-line word completion facilities to list the
10374available choices, or to finish the type list for you.
79a6e687 10375@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 10376@end table
c906108c 10377
febe4383
TJB
10378@node Decimal Floating Point
10379@subsubsection Decimal Floating Point format
10380@cindex decimal floating point format
10381
10382@value{GDBN} can examine, set and perform computations with numbers in
10383decimal floating point format, which in the C language correspond to the
10384@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
10385specified by the extension to support decimal floating-point arithmetic.
10386
10387There are two encodings in use, depending on the architecture: BID (Binary
10388Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
10389PowerPC. @value{GDBN} will use the appropriate encoding for the configured
10390target.
10391
10392Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
10393to manipulate decimal floating point numbers, it is not possible to convert
10394(using a cast, for example) integers wider than 32-bit to decimal float.
10395
10396In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
10397point computations, error checking in decimal float operations ignores
10398underflow, overflow and divide by zero exceptions.
10399
4acd40f3
TJB
10400In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
10401to inspect @code{_Decimal128} values stored in floating point registers. See
10402@ref{PowerPC,,PowerPC} for more details.
10403
b37303ee
AF
10404@node Objective-C
10405@subsection Objective-C
10406
10407@cindex Objective-C
10408This section provides information about some commands and command
721c2651
EZ
10409options that are useful for debugging Objective-C code. See also
10410@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
10411few more commands specific to Objective-C support.
b37303ee
AF
10412
10413@menu
b383017d
RM
10414* Method Names in Commands::
10415* The Print Command with Objective-C::
b37303ee
AF
10416@end menu
10417
c8f4133a 10418@node Method Names in Commands
b37303ee
AF
10419@subsubsection Method Names in Commands
10420
10421The following commands have been extended to accept Objective-C method
10422names as line specifications:
10423
10424@kindex clear@r{, and Objective-C}
10425@kindex break@r{, and Objective-C}
10426@kindex info line@r{, and Objective-C}
10427@kindex jump@r{, and Objective-C}
10428@kindex list@r{, and Objective-C}
10429@itemize
10430@item @code{clear}
10431@item @code{break}
10432@item @code{info line}
10433@item @code{jump}
10434@item @code{list}
10435@end itemize
10436
10437A fully qualified Objective-C method name is specified as
10438
10439@smallexample
10440-[@var{Class} @var{methodName}]
10441@end smallexample
10442
c552b3bb
JM
10443where the minus sign is used to indicate an instance method and a
10444plus sign (not shown) is used to indicate a class method. The class
10445name @var{Class} and method name @var{methodName} are enclosed in
10446brackets, similar to the way messages are specified in Objective-C
10447source code. For example, to set a breakpoint at the @code{create}
10448instance method of class @code{Fruit} in the program currently being
10449debugged, enter:
b37303ee
AF
10450
10451@smallexample
10452break -[Fruit create]
10453@end smallexample
10454
10455To list ten program lines around the @code{initialize} class method,
10456enter:
10457
10458@smallexample
10459list +[NSText initialize]
10460@end smallexample
10461
c552b3bb
JM
10462In the current version of @value{GDBN}, the plus or minus sign is
10463required. In future versions of @value{GDBN}, the plus or minus
10464sign will be optional, but you can use it to narrow the search. It
10465is also possible to specify just a method name:
b37303ee
AF
10466
10467@smallexample
10468break create
10469@end smallexample
10470
10471You must specify the complete method name, including any colons. If
10472your program's source files contain more than one @code{create} method,
10473you'll be presented with a numbered list of classes that implement that
10474method. Indicate your choice by number, or type @samp{0} to exit if
10475none apply.
10476
10477As another example, to clear a breakpoint established at the
10478@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
10479
10480@smallexample
10481clear -[NSWindow makeKeyAndOrderFront:]
10482@end smallexample
10483
10484@node The Print Command with Objective-C
10485@subsubsection The Print Command With Objective-C
721c2651 10486@cindex Objective-C, print objects
c552b3bb
JM
10487@kindex print-object
10488@kindex po @r{(@code{print-object})}
b37303ee 10489
c552b3bb 10490The print command has also been extended to accept methods. For example:
b37303ee
AF
10491
10492@smallexample
c552b3bb 10493print -[@var{object} hash]
b37303ee
AF
10494@end smallexample
10495
10496@cindex print an Objective-C object description
c552b3bb
JM
10497@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
10498@noindent
10499will tell @value{GDBN} to send the @code{hash} message to @var{object}
10500and print the result. Also, an additional command has been added,
10501@code{print-object} or @code{po} for short, which is meant to print
10502the description of an object. However, this command may only work
10503with certain Objective-C libraries that have a particular hook
10504function, @code{_NSPrintForDebugger}, defined.
b37303ee 10505
09d4efe1
EZ
10506@node Fortran
10507@subsection Fortran
10508@cindex Fortran-specific support in @value{GDBN}
10509
814e32d7
WZ
10510@value{GDBN} can be used to debug programs written in Fortran, but it
10511currently supports only the features of Fortran 77 language.
10512
10513@cindex trailing underscore, in Fortran symbols
10514Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
10515among them) append an underscore to the names of variables and
10516functions. When you debug programs compiled by those compilers, you
10517will need to refer to variables and functions with a trailing
10518underscore.
10519
10520@menu
10521* Fortran Operators:: Fortran operators and expressions
10522* Fortran Defaults:: Default settings for Fortran
79a6e687 10523* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
10524@end menu
10525
10526@node Fortran Operators
79a6e687 10527@subsubsection Fortran Operators and Expressions
814e32d7
WZ
10528
10529@cindex Fortran operators and expressions
10530
10531Operators must be defined on values of specific types. For instance,
10532@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 10533arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
10534
10535@table @code
10536@item **
10537The exponentiation operator. It raises the first operand to the power
10538of the second one.
10539
10540@item :
10541The range operator. Normally used in the form of array(low:high) to
10542represent a section of array.
68837c9d
MD
10543
10544@item %
10545The access component operator. Normally used to access elements in derived
10546types. Also suitable for unions. As unions aren't part of regular Fortran,
10547this can only happen when accessing a register that uses a gdbarch-defined
10548union type.
814e32d7
WZ
10549@end table
10550
10551@node Fortran Defaults
10552@subsubsection Fortran Defaults
10553
10554@cindex Fortran Defaults
10555
10556Fortran symbols are usually case-insensitive, so @value{GDBN} by
10557default uses case-insensitive matches for Fortran symbols. You can
10558change that with the @samp{set case-insensitive} command, see
10559@ref{Symbols}, for the details.
10560
79a6e687
BW
10561@node Special Fortran Commands
10562@subsubsection Special Fortran Commands
814e32d7
WZ
10563
10564@cindex Special Fortran commands
10565
db2e3e2e
BW
10566@value{GDBN} has some commands to support Fortran-specific features,
10567such as displaying common blocks.
814e32d7 10568
09d4efe1
EZ
10569@table @code
10570@cindex @code{COMMON} blocks, Fortran
10571@kindex info common
10572@item info common @r{[}@var{common-name}@r{]}
10573This command prints the values contained in the Fortran @code{COMMON}
10574block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 10575all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
10576printed.
10577@end table
10578
9c16f35a
EZ
10579@node Pascal
10580@subsection Pascal
10581
10582@cindex Pascal support in @value{GDBN}, limitations
10583Debugging Pascal programs which use sets, subranges, file variables, or
10584nested functions does not currently work. @value{GDBN} does not support
10585entering expressions, printing values, or similar features using Pascal
10586syntax.
10587
10588The Pascal-specific command @code{set print pascal_static-members}
10589controls whether static members of Pascal objects are displayed.
10590@xref{Print Settings, pascal_static-members}.
10591
09d4efe1 10592@node Modula-2
c906108c 10593@subsection Modula-2
7a292a7a 10594
d4f3574e 10595@cindex Modula-2, @value{GDBN} support
c906108c
SS
10596
10597The extensions made to @value{GDBN} to support Modula-2 only support
10598output from the @sc{gnu} Modula-2 compiler (which is currently being
10599developed). Other Modula-2 compilers are not currently supported, and
10600attempting to debug executables produced by them is most likely
10601to give an error as @value{GDBN} reads in the executable's symbol
10602table.
10603
10604@cindex expressions in Modula-2
10605@menu
10606* M2 Operators:: Built-in operators
10607* Built-In Func/Proc:: Built-in functions and procedures
10608* M2 Constants:: Modula-2 constants
72019c9c 10609* M2 Types:: Modula-2 types
c906108c
SS
10610* M2 Defaults:: Default settings for Modula-2
10611* Deviations:: Deviations from standard Modula-2
10612* M2 Checks:: Modula-2 type and range checks
10613* M2 Scope:: The scope operators @code{::} and @code{.}
10614* GDB/M2:: @value{GDBN} and Modula-2
10615@end menu
10616
6d2ebf8b 10617@node M2 Operators
c906108c
SS
10618@subsubsection Operators
10619@cindex Modula-2 operators
10620
10621Operators must be defined on values of specific types. For instance,
10622@code{+} is defined on numbers, but not on structures. Operators are
10623often defined on groups of types. For the purposes of Modula-2, the
10624following definitions hold:
10625
10626@itemize @bullet
10627
10628@item
10629@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
10630their subranges.
10631
10632@item
10633@emph{Character types} consist of @code{CHAR} and its subranges.
10634
10635@item
10636@emph{Floating-point types} consist of @code{REAL}.
10637
10638@item
10639@emph{Pointer types} consist of anything declared as @code{POINTER TO
10640@var{type}}.
10641
10642@item
10643@emph{Scalar types} consist of all of the above.
10644
10645@item
10646@emph{Set types} consist of @code{SET} and @code{BITSET} types.
10647
10648@item
10649@emph{Boolean types} consist of @code{BOOLEAN}.
10650@end itemize
10651
10652@noindent
10653The following operators are supported, and appear in order of
10654increasing precedence:
10655
10656@table @code
10657@item ,
10658Function argument or array index separator.
10659
10660@item :=
10661Assignment. The value of @var{var} @code{:=} @var{value} is
10662@var{value}.
10663
10664@item <@r{, }>
10665Less than, greater than on integral, floating-point, or enumerated
10666types.
10667
10668@item <=@r{, }>=
96a2c332 10669Less than or equal to, greater than or equal to
c906108c
SS
10670on integral, floating-point and enumerated types, or set inclusion on
10671set types. Same precedence as @code{<}.
10672
10673@item =@r{, }<>@r{, }#
10674Equality and two ways of expressing inequality, valid on scalar types.
10675Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
10676available for inequality, since @code{#} conflicts with the script
10677comment character.
10678
10679@item IN
10680Set membership. Defined on set types and the types of their members.
10681Same precedence as @code{<}.
10682
10683@item OR
10684Boolean disjunction. Defined on boolean types.
10685
10686@item AND@r{, }&
d4f3574e 10687Boolean conjunction. Defined on boolean types.
c906108c
SS
10688
10689@item @@
10690The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
10691
10692@item +@r{, }-
10693Addition and subtraction on integral and floating-point types, or union
10694and difference on set types.
10695
10696@item *
10697Multiplication on integral and floating-point types, or set intersection
10698on set types.
10699
10700@item /
10701Division on floating-point types, or symmetric set difference on set
10702types. Same precedence as @code{*}.
10703
10704@item DIV@r{, }MOD
10705Integer division and remainder. Defined on integral types. Same
10706precedence as @code{*}.
10707
10708@item -
10709Negative. Defined on @code{INTEGER} and @code{REAL} data.
10710
10711@item ^
10712Pointer dereferencing. Defined on pointer types.
10713
10714@item NOT
10715Boolean negation. Defined on boolean types. Same precedence as
10716@code{^}.
10717
10718@item .
10719@code{RECORD} field selector. Defined on @code{RECORD} data. Same
10720precedence as @code{^}.
10721
10722@item []
10723Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
10724
10725@item ()
10726Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
10727as @code{^}.
10728
10729@item ::@r{, }.
10730@value{GDBN} and Modula-2 scope operators.
10731@end table
10732
10733@quotation
72019c9c 10734@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
10735treats the use of the operator @code{IN}, or the use of operators
10736@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
10737@code{<=}, and @code{>=} on sets as an error.
10738@end quotation
10739
cb51c4e0 10740
6d2ebf8b 10741@node Built-In Func/Proc
79a6e687 10742@subsubsection Built-in Functions and Procedures
cb51c4e0 10743@cindex Modula-2 built-ins
c906108c
SS
10744
10745Modula-2 also makes available several built-in procedures and functions.
10746In describing these, the following metavariables are used:
10747
10748@table @var
10749
10750@item a
10751represents an @code{ARRAY} variable.
10752
10753@item c
10754represents a @code{CHAR} constant or variable.
10755
10756@item i
10757represents a variable or constant of integral type.
10758
10759@item m
10760represents an identifier that belongs to a set. Generally used in the
10761same function with the metavariable @var{s}. The type of @var{s} should
10762be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
10763
10764@item n
10765represents a variable or constant of integral or floating-point type.
10766
10767@item r
10768represents a variable or constant of floating-point type.
10769
10770@item t
10771represents a type.
10772
10773@item v
10774represents a variable.
10775
10776@item x
10777represents a variable or constant of one of many types. See the
10778explanation of the function for details.
10779@end table
10780
10781All Modula-2 built-in procedures also return a result, described below.
10782
10783@table @code
10784@item ABS(@var{n})
10785Returns the absolute value of @var{n}.
10786
10787@item CAP(@var{c})
10788If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 10789equivalent, otherwise it returns its argument.
c906108c
SS
10790
10791@item CHR(@var{i})
10792Returns the character whose ordinal value is @var{i}.
10793
10794@item DEC(@var{v})
c3f6f71d 10795Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
10796
10797@item DEC(@var{v},@var{i})
10798Decrements the value in the variable @var{v} by @var{i}. Returns the
10799new value.
10800
10801@item EXCL(@var{m},@var{s})
10802Removes the element @var{m} from the set @var{s}. Returns the new
10803set.
10804
10805@item FLOAT(@var{i})
10806Returns the floating point equivalent of the integer @var{i}.
10807
10808@item HIGH(@var{a})
10809Returns the index of the last member of @var{a}.
10810
10811@item INC(@var{v})
c3f6f71d 10812Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
10813
10814@item INC(@var{v},@var{i})
10815Increments the value in the variable @var{v} by @var{i}. Returns the
10816new value.
10817
10818@item INCL(@var{m},@var{s})
10819Adds the element @var{m} to the set @var{s} if it is not already
10820there. Returns the new set.
10821
10822@item MAX(@var{t})
10823Returns the maximum value of the type @var{t}.
10824
10825@item MIN(@var{t})
10826Returns the minimum value of the type @var{t}.
10827
10828@item ODD(@var{i})
10829Returns boolean TRUE if @var{i} is an odd number.
10830
10831@item ORD(@var{x})
10832Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
10833value of a character is its @sc{ascii} value (on machines supporting the
10834@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
10835integral, character and enumerated types.
10836
10837@item SIZE(@var{x})
10838Returns the size of its argument. @var{x} can be a variable or a type.
10839
10840@item TRUNC(@var{r})
10841Returns the integral part of @var{r}.
10842
844781a1
GM
10843@item TSIZE(@var{x})
10844Returns the size of its argument. @var{x} can be a variable or a type.
10845
c906108c
SS
10846@item VAL(@var{t},@var{i})
10847Returns the member of the type @var{t} whose ordinal value is @var{i}.
10848@end table
10849
10850@quotation
10851@emph{Warning:} Sets and their operations are not yet supported, so
10852@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
10853an error.
10854@end quotation
10855
10856@cindex Modula-2 constants
6d2ebf8b 10857@node M2 Constants
c906108c
SS
10858@subsubsection Constants
10859
10860@value{GDBN} allows you to express the constants of Modula-2 in the following
10861ways:
10862
10863@itemize @bullet
10864
10865@item
10866Integer constants are simply a sequence of digits. When used in an
10867expression, a constant is interpreted to be type-compatible with the
10868rest of the expression. Hexadecimal integers are specified by a
10869trailing @samp{H}, and octal integers by a trailing @samp{B}.
10870
10871@item
10872Floating point constants appear as a sequence of digits, followed by a
10873decimal point and another sequence of digits. An optional exponent can
10874then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
10875@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
10876digits of the floating point constant must be valid decimal (base 10)
10877digits.
10878
10879@item
10880Character constants consist of a single character enclosed by a pair of
10881like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 10882also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
10883followed by a @samp{C}.
10884
10885@item
10886String constants consist of a sequence of characters enclosed by a
10887pair of like quotes, either single (@code{'}) or double (@code{"}).
10888Escape sequences in the style of C are also allowed. @xref{C
79a6e687 10889Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
10890sequences.
10891
10892@item
10893Enumerated constants consist of an enumerated identifier.
10894
10895@item
10896Boolean constants consist of the identifiers @code{TRUE} and
10897@code{FALSE}.
10898
10899@item
10900Pointer constants consist of integral values only.
10901
10902@item
10903Set constants are not yet supported.
10904@end itemize
10905
72019c9c
GM
10906@node M2 Types
10907@subsubsection Modula-2 Types
10908@cindex Modula-2 types
10909
10910Currently @value{GDBN} can print the following data types in Modula-2
10911syntax: array types, record types, set types, pointer types, procedure
10912types, enumerated types, subrange types and base types. You can also
10913print the contents of variables declared using these type.
10914This section gives a number of simple source code examples together with
10915sample @value{GDBN} sessions.
10916
10917The first example contains the following section of code:
10918
10919@smallexample
10920VAR
10921 s: SET OF CHAR ;
10922 r: [20..40] ;
10923@end smallexample
10924
10925@noindent
10926and you can request @value{GDBN} to interrogate the type and value of
10927@code{r} and @code{s}.
10928
10929@smallexample
10930(@value{GDBP}) print s
10931@{'A'..'C', 'Z'@}
10932(@value{GDBP}) ptype s
10933SET OF CHAR
10934(@value{GDBP}) print r
1093521
10936(@value{GDBP}) ptype r
10937[20..40]
10938@end smallexample
10939
10940@noindent
10941Likewise if your source code declares @code{s} as:
10942
10943@smallexample
10944VAR
10945 s: SET ['A'..'Z'] ;
10946@end smallexample
10947
10948@noindent
10949then you may query the type of @code{s} by:
10950
10951@smallexample
10952(@value{GDBP}) ptype s
10953type = SET ['A'..'Z']
10954@end smallexample
10955
10956@noindent
10957Note that at present you cannot interactively manipulate set
10958expressions using the debugger.
10959
10960The following example shows how you might declare an array in Modula-2
10961and how you can interact with @value{GDBN} to print its type and contents:
10962
10963@smallexample
10964VAR
10965 s: ARRAY [-10..10] OF CHAR ;
10966@end smallexample
10967
10968@smallexample
10969(@value{GDBP}) ptype s
10970ARRAY [-10..10] OF CHAR
10971@end smallexample
10972
10973Note that the array handling is not yet complete and although the type
10974is printed correctly, expression handling still assumes that all
10975arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 10976above.
72019c9c
GM
10977
10978Here are some more type related Modula-2 examples:
10979
10980@smallexample
10981TYPE
10982 colour = (blue, red, yellow, green) ;
10983 t = [blue..yellow] ;
10984VAR
10985 s: t ;
10986BEGIN
10987 s := blue ;
10988@end smallexample
10989
10990@noindent
10991The @value{GDBN} interaction shows how you can query the data type
10992and value of a variable.
10993
10994@smallexample
10995(@value{GDBP}) print s
10996$1 = blue
10997(@value{GDBP}) ptype t
10998type = [blue..yellow]
10999@end smallexample
11000
11001@noindent
11002In this example a Modula-2 array is declared and its contents
11003displayed. Observe that the contents are written in the same way as
11004their @code{C} counterparts.
11005
11006@smallexample
11007VAR
11008 s: ARRAY [1..5] OF CARDINAL ;
11009BEGIN
11010 s[1] := 1 ;
11011@end smallexample
11012
11013@smallexample
11014(@value{GDBP}) print s
11015$1 = @{1, 0, 0, 0, 0@}
11016(@value{GDBP}) ptype s
11017type = ARRAY [1..5] OF CARDINAL
11018@end smallexample
11019
11020The Modula-2 language interface to @value{GDBN} also understands
11021pointer types as shown in this example:
11022
11023@smallexample
11024VAR
11025 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
11026BEGIN
11027 NEW(s) ;
11028 s^[1] := 1 ;
11029@end smallexample
11030
11031@noindent
11032and you can request that @value{GDBN} describes the type of @code{s}.
11033
11034@smallexample
11035(@value{GDBP}) ptype s
11036type = POINTER TO ARRAY [1..5] OF CARDINAL
11037@end smallexample
11038
11039@value{GDBN} handles compound types as we can see in this example.
11040Here we combine array types, record types, pointer types and subrange
11041types:
11042
11043@smallexample
11044TYPE
11045 foo = RECORD
11046 f1: CARDINAL ;
11047 f2: CHAR ;
11048 f3: myarray ;
11049 END ;
11050
11051 myarray = ARRAY myrange OF CARDINAL ;
11052 myrange = [-2..2] ;
11053VAR
11054 s: POINTER TO ARRAY myrange OF foo ;
11055@end smallexample
11056
11057@noindent
11058and you can ask @value{GDBN} to describe the type of @code{s} as shown
11059below.
11060
11061@smallexample
11062(@value{GDBP}) ptype s
11063type = POINTER TO ARRAY [-2..2] OF foo = RECORD
11064 f1 : CARDINAL;
11065 f2 : CHAR;
11066 f3 : ARRAY [-2..2] OF CARDINAL;
11067END
11068@end smallexample
11069
6d2ebf8b 11070@node M2 Defaults
79a6e687 11071@subsubsection Modula-2 Defaults
c906108c
SS
11072@cindex Modula-2 defaults
11073
11074If type and range checking are set automatically by @value{GDBN}, they
11075both default to @code{on} whenever the working language changes to
d4f3574e 11076Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
11077selected the working language.
11078
11079If you allow @value{GDBN} to set the language automatically, then entering
11080code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
11081working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
11082Infer the Source Language}, for further details.
c906108c 11083
6d2ebf8b 11084@node Deviations
79a6e687 11085@subsubsection Deviations from Standard Modula-2
c906108c
SS
11086@cindex Modula-2, deviations from
11087
11088A few changes have been made to make Modula-2 programs easier to debug.
11089This is done primarily via loosening its type strictness:
11090
11091@itemize @bullet
11092@item
11093Unlike in standard Modula-2, pointer constants can be formed by
11094integers. This allows you to modify pointer variables during
11095debugging. (In standard Modula-2, the actual address contained in a
11096pointer variable is hidden from you; it can only be modified
11097through direct assignment to another pointer variable or expression that
11098returned a pointer.)
11099
11100@item
11101C escape sequences can be used in strings and characters to represent
11102non-printable characters. @value{GDBN} prints out strings with these
11103escape sequences embedded. Single non-printable characters are
11104printed using the @samp{CHR(@var{nnn})} format.
11105
11106@item
11107The assignment operator (@code{:=}) returns the value of its right-hand
11108argument.
11109
11110@item
11111All built-in procedures both modify @emph{and} return their argument.
11112@end itemize
11113
6d2ebf8b 11114@node M2 Checks
79a6e687 11115@subsubsection Modula-2 Type and Range Checks
c906108c
SS
11116@cindex Modula-2 checks
11117
11118@quotation
11119@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
11120range checking.
11121@end quotation
11122@c FIXME remove warning when type/range checks added
11123
11124@value{GDBN} considers two Modula-2 variables type equivalent if:
11125
11126@itemize @bullet
11127@item
11128They are of types that have been declared equivalent via a @code{TYPE
11129@var{t1} = @var{t2}} statement
11130
11131@item
11132They have been declared on the same line. (Note: This is true of the
11133@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
11134@end itemize
11135
11136As long as type checking is enabled, any attempt to combine variables
11137whose types are not equivalent is an error.
11138
11139Range checking is done on all mathematical operations, assignment, array
11140index bounds, and all built-in functions and procedures.
11141
6d2ebf8b 11142@node M2 Scope
79a6e687 11143@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 11144@cindex scope
41afff9a 11145@cindex @code{.}, Modula-2 scope operator
c906108c
SS
11146@cindex colon, doubled as scope operator
11147@ifinfo
41afff9a 11148@vindex colon-colon@r{, in Modula-2}
c906108c
SS
11149@c Info cannot handle :: but TeX can.
11150@end ifinfo
11151@iftex
41afff9a 11152@vindex ::@r{, in Modula-2}
c906108c
SS
11153@end iftex
11154
11155There are a few subtle differences between the Modula-2 scope operator
11156(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
11157similar syntax:
11158
474c8240 11159@smallexample
c906108c
SS
11160
11161@var{module} . @var{id}
11162@var{scope} :: @var{id}
474c8240 11163@end smallexample
c906108c
SS
11164
11165@noindent
11166where @var{scope} is the name of a module or a procedure,
11167@var{module} the name of a module, and @var{id} is any declared
11168identifier within your program, except another module.
11169
11170Using the @code{::} operator makes @value{GDBN} search the scope
11171specified by @var{scope} for the identifier @var{id}. If it is not
11172found in the specified scope, then @value{GDBN} searches all scopes
11173enclosing the one specified by @var{scope}.
11174
11175Using the @code{.} operator makes @value{GDBN} search the current scope for
11176the identifier specified by @var{id} that was imported from the
11177definition module specified by @var{module}. With this operator, it is
11178an error if the identifier @var{id} was not imported from definition
11179module @var{module}, or if @var{id} is not an identifier in
11180@var{module}.
11181
6d2ebf8b 11182@node GDB/M2
c906108c
SS
11183@subsubsection @value{GDBN} and Modula-2
11184
11185Some @value{GDBN} commands have little use when debugging Modula-2 programs.
11186Five subcommands of @code{set print} and @code{show print} apply
b37052ae 11187specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 11188@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 11189apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
11190analogue in Modula-2.
11191
11192The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 11193with any language, is not useful with Modula-2. Its
c906108c 11194intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 11195created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 11196address can be specified by an integral constant, the construct
d4f3574e 11197@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
11198
11199@cindex @code{#} in Modula-2
11200In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
11201interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 11202
e07c999f
PH
11203@node Ada
11204@subsection Ada
11205@cindex Ada
11206
11207The extensions made to @value{GDBN} for Ada only support
11208output from the @sc{gnu} Ada (GNAT) compiler.
11209Other Ada compilers are not currently supported, and
11210attempting to debug executables produced by them is most likely
11211to be difficult.
11212
11213
11214@cindex expressions in Ada
11215@menu
11216* Ada Mode Intro:: General remarks on the Ada syntax
11217 and semantics supported by Ada mode
11218 in @value{GDBN}.
11219* Omissions from Ada:: Restrictions on the Ada expression syntax.
11220* Additions to Ada:: Extensions of the Ada expression syntax.
11221* Stopping Before Main Program:: Debugging the program during elaboration.
20924a55
JB
11222* Ada Tasks:: Listing and setting breakpoints in tasks.
11223* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
e07c999f
PH
11224* Ada Glitches:: Known peculiarities of Ada mode.
11225@end menu
11226
11227@node Ada Mode Intro
11228@subsubsection Introduction
11229@cindex Ada mode, general
11230
11231The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
11232syntax, with some extensions.
11233The philosophy behind the design of this subset is
11234
11235@itemize @bullet
11236@item
11237That @value{GDBN} should provide basic literals and access to operations for
11238arithmetic, dereferencing, field selection, indexing, and subprogram calls,
11239leaving more sophisticated computations to subprograms written into the
11240program (which therefore may be called from @value{GDBN}).
11241
11242@item
11243That type safety and strict adherence to Ada language restrictions
11244are not particularly important to the @value{GDBN} user.
11245
11246@item
11247That brevity is important to the @value{GDBN} user.
11248@end itemize
11249
f3a2dd1a
JB
11250Thus, for brevity, the debugger acts as if all names declared in
11251user-written packages are directly visible, even if they are not visible
11252according to Ada rules, thus making it unnecessary to fully qualify most
11253names with their packages, regardless of context. Where this causes
11254ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
11255
11256The debugger will start in Ada mode if it detects an Ada main program.
11257As for other languages, it will enter Ada mode when stopped in a program that
11258was translated from an Ada source file.
11259
11260While in Ada mode, you may use `@t{--}' for comments. This is useful
11261mostly for documenting command files. The standard @value{GDBN} comment
11262(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
11263middle (to allow based literals).
11264
11265The debugger supports limited overloading. Given a subprogram call in which
11266the function symbol has multiple definitions, it will use the number of
11267actual parameters and some information about their types to attempt to narrow
11268the set of definitions. It also makes very limited use of context, preferring
11269procedures to functions in the context of the @code{call} command, and
11270functions to procedures elsewhere.
11271
11272@node Omissions from Ada
11273@subsubsection Omissions from Ada
11274@cindex Ada, omissions from
11275
11276Here are the notable omissions from the subset:
11277
11278@itemize @bullet
11279@item
11280Only a subset of the attributes are supported:
11281
11282@itemize @minus
11283@item
11284@t{'First}, @t{'Last}, and @t{'Length}
11285 on array objects (not on types and subtypes).
11286
11287@item
11288@t{'Min} and @t{'Max}.
11289
11290@item
11291@t{'Pos} and @t{'Val}.
11292
11293@item
11294@t{'Tag}.
11295
11296@item
11297@t{'Range} on array objects (not subtypes), but only as the right
11298operand of the membership (@code{in}) operator.
11299
11300@item
11301@t{'Access}, @t{'Unchecked_Access}, and
11302@t{'Unrestricted_Access} (a GNAT extension).
11303
11304@item
11305@t{'Address}.
11306@end itemize
11307
11308@item
11309The names in
11310@code{Characters.Latin_1} are not available and
11311concatenation is not implemented. Thus, escape characters in strings are
11312not currently available.
11313
11314@item
11315Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
11316equality of representations. They will generally work correctly
11317for strings and arrays whose elements have integer or enumeration types.
11318They may not work correctly for arrays whose element
11319types have user-defined equality, for arrays of real values
11320(in particular, IEEE-conformant floating point, because of negative
11321zeroes and NaNs), and for arrays whose elements contain unused bits with
11322indeterminate values.
11323
11324@item
11325The other component-by-component array operations (@code{and}, @code{or},
11326@code{xor}, @code{not}, and relational tests other than equality)
11327are not implemented.
11328
11329@item
860701dc
PH
11330@cindex array aggregates (Ada)
11331@cindex record aggregates (Ada)
11332@cindex aggregates (Ada)
11333There is limited support for array and record aggregates. They are
11334permitted only on the right sides of assignments, as in these examples:
11335
11336@smallexample
11337set An_Array := (1, 2, 3, 4, 5, 6)
11338set An_Array := (1, others => 0)
11339set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
11340set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
11341set A_Record := (1, "Peter", True);
11342set A_Record := (Name => "Peter", Id => 1, Alive => True)
11343@end smallexample
11344
11345Changing a
11346discriminant's value by assigning an aggregate has an
11347undefined effect if that discriminant is used within the record.
11348However, you can first modify discriminants by directly assigning to
11349them (which normally would not be allowed in Ada), and then performing an
11350aggregate assignment. For example, given a variable @code{A_Rec}
11351declared to have a type such as:
11352
11353@smallexample
11354type Rec (Len : Small_Integer := 0) is record
11355 Id : Integer;
11356 Vals : IntArray (1 .. Len);
11357end record;
11358@end smallexample
11359
11360you can assign a value with a different size of @code{Vals} with two
11361assignments:
11362
11363@smallexample
11364set A_Rec.Len := 4
11365set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
11366@end smallexample
11367
11368As this example also illustrates, @value{GDBN} is very loose about the usual
11369rules concerning aggregates. You may leave out some of the
11370components of an array or record aggregate (such as the @code{Len}
11371component in the assignment to @code{A_Rec} above); they will retain their
11372original values upon assignment. You may freely use dynamic values as
11373indices in component associations. You may even use overlapping or
11374redundant component associations, although which component values are
11375assigned in such cases is not defined.
e07c999f
PH
11376
11377@item
11378Calls to dispatching subprograms are not implemented.
11379
11380@item
11381The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
11382than that of real Ada. It makes only limited use of the context in
11383which a subexpression appears to resolve its meaning, and it is much
11384looser in its rules for allowing type matches. As a result, some
11385function calls will be ambiguous, and the user will be asked to choose
11386the proper resolution.
e07c999f
PH
11387
11388@item
11389The @code{new} operator is not implemented.
11390
11391@item
11392Entry calls are not implemented.
11393
11394@item
11395Aside from printing, arithmetic operations on the native VAX floating-point
11396formats are not supported.
11397
11398@item
11399It is not possible to slice a packed array.
158c7665
PH
11400
11401@item
11402The names @code{True} and @code{False}, when not part of a qualified name,
11403are interpreted as if implicitly prefixed by @code{Standard}, regardless of
11404context.
11405Should your program
11406redefine these names in a package or procedure (at best a dubious practice),
11407you will have to use fully qualified names to access their new definitions.
e07c999f
PH
11408@end itemize
11409
11410@node Additions to Ada
11411@subsubsection Additions to Ada
11412@cindex Ada, deviations from
11413
11414As it does for other languages, @value{GDBN} makes certain generic
11415extensions to Ada (@pxref{Expressions}):
11416
11417@itemize @bullet
11418@item
ae21e955
BW
11419If the expression @var{E} is a variable residing in memory (typically
11420a local variable or array element) and @var{N} is a positive integer,
11421then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
11422@var{N}-1 adjacent variables following it in memory as an array. In
11423Ada, this operator is generally not necessary, since its prime use is
11424in displaying parts of an array, and slicing will usually do this in
11425Ada. However, there are occasional uses when debugging programs in
11426which certain debugging information has been optimized away.
e07c999f
PH
11427
11428@item
ae21e955
BW
11429@code{@var{B}::@var{var}} means ``the variable named @var{var} that
11430appears in function or file @var{B}.'' When @var{B} is a file name,
11431you must typically surround it in single quotes.
e07c999f
PH
11432
11433@item
11434The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
11435@var{type} that appears at address @var{addr}.''
11436
11437@item
11438A name starting with @samp{$} is a convenience variable
11439(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
11440@end itemize
11441
ae21e955
BW
11442In addition, @value{GDBN} provides a few other shortcuts and outright
11443additions specific to Ada:
e07c999f
PH
11444
11445@itemize @bullet
11446@item
11447The assignment statement is allowed as an expression, returning
11448its right-hand operand as its value. Thus, you may enter
11449
11450@smallexample
11451set x := y + 3
11452print A(tmp := y + 1)
11453@end smallexample
11454
11455@item
11456The semicolon is allowed as an ``operator,'' returning as its value
11457the value of its right-hand operand.
11458This allows, for example,
11459complex conditional breaks:
11460
11461@smallexample
11462break f
11463condition 1 (report(i); k += 1; A(k) > 100)
11464@end smallexample
11465
11466@item
11467Rather than use catenation and symbolic character names to introduce special
11468characters into strings, one may instead use a special bracket notation,
11469which is also used to print strings. A sequence of characters of the form
11470@samp{["@var{XX}"]} within a string or character literal denotes the
11471(single) character whose numeric encoding is @var{XX} in hexadecimal. The
11472sequence of characters @samp{["""]} also denotes a single quotation mark
11473in strings. For example,
11474@smallexample
11475 "One line.["0a"]Next line.["0a"]"
11476@end smallexample
11477@noindent
ae21e955
BW
11478contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
11479after each period.
e07c999f
PH
11480
11481@item
11482The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
11483@t{'Max} is optional (and is ignored in any case). For example, it is valid
11484to write
11485
11486@smallexample
11487print 'max(x, y)
11488@end smallexample
11489
11490@item
11491When printing arrays, @value{GDBN} uses positional notation when the
11492array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
11493For example, a one-dimensional array of three integers with a lower bound
11494of 3 might print as
e07c999f
PH
11495
11496@smallexample
11497(3 => 10, 17, 1)
11498@end smallexample
11499
11500@noindent
11501That is, in contrast to valid Ada, only the first component has a @code{=>}
11502clause.
11503
11504@item
11505You may abbreviate attributes in expressions with any unique,
11506multi-character subsequence of
11507their names (an exact match gets preference).
11508For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
11509in place of @t{a'length}.
11510
11511@item
11512@cindex quoting Ada internal identifiers
11513Since Ada is case-insensitive, the debugger normally maps identifiers you type
11514to lower case. The GNAT compiler uses upper-case characters for
11515some of its internal identifiers, which are normally of no interest to users.
11516For the rare occasions when you actually have to look at them,
11517enclose them in angle brackets to avoid the lower-case mapping.
11518For example,
11519@smallexample
11520@value{GDBP} print <JMPBUF_SAVE>[0]
11521@end smallexample
11522
11523@item
11524Printing an object of class-wide type or dereferencing an
11525access-to-class-wide value will display all the components of the object's
11526specific type (as indicated by its run-time tag). Likewise, component
11527selection on such a value will operate on the specific type of the
11528object.
11529
11530@end itemize
11531
11532@node Stopping Before Main Program
11533@subsubsection Stopping at the Very Beginning
11534
11535@cindex breakpointing Ada elaboration code
11536It is sometimes necessary to debug the program during elaboration, and
11537before reaching the main procedure.
11538As defined in the Ada Reference
11539Manual, the elaboration code is invoked from a procedure called
11540@code{adainit}. To run your program up to the beginning of
11541elaboration, simply use the following two commands:
11542@code{tbreak adainit} and @code{run}.
11543
20924a55
JB
11544@node Ada Tasks
11545@subsubsection Extensions for Ada Tasks
11546@cindex Ada, tasking
11547
11548Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
11549@value{GDBN} provides the following task-related commands:
11550
11551@table @code
11552@kindex info tasks
11553@item info tasks
11554This command shows a list of current Ada tasks, as in the following example:
11555
11556
11557@smallexample
11558@iftex
11559@leftskip=0.5cm
11560@end iftex
11561(@value{GDBP}) info tasks
11562 ID TID P-ID Pri State Name
11563 1 8088000 0 15 Child Activation Wait main_task
11564 2 80a4000 1 15 Accept Statement b
11565 3 809a800 1 15 Child Activation Wait a
11566* 4 80ae800 3 15 Running c
11567
11568@end smallexample
11569
11570@noindent
11571In this listing, the asterisk before the last task indicates it to be the
11572task currently being inspected.
11573
11574@table @asis
11575@item ID
11576Represents @value{GDBN}'s internal task number.
11577
11578@item TID
11579The Ada task ID.
11580
11581@item P-ID
11582The parent's task ID (@value{GDBN}'s internal task number).
11583
11584@item Pri
11585The base priority of the task.
11586
11587@item State
11588Current state of the task.
11589
11590@table @code
11591@item Unactivated
11592The task has been created but has not been activated. It cannot be
11593executing.
11594
11595@item Running
11596The task currently running.
11597
11598@item Runnable
11599The task is not blocked for any reason known to Ada. (It may be waiting
11600for a mutex, though.) It is conceptually "executing" in normal mode.
11601
11602@item Terminated
11603The task is terminated, in the sense of ARM 9.3 (5). Any dependents
11604that were waiting on terminate alternatives have been awakened and have
11605terminated themselves.
11606
11607@item Child Activation Wait
11608The task is waiting for created tasks to complete activation.
11609
11610@item Accept Statement
11611The task is waiting on an accept or selective wait statement.
11612
11613@item Waiting on entry call
11614The task is waiting on an entry call.
11615
11616@item Async Select Wait
11617The task is waiting to start the abortable part of an asynchronous
11618select statement.
11619
11620@item Delay Sleep
11621The task is waiting on a select statement with only a delay
11622alternative open.
11623
11624@item Child Termination Wait
11625The task is sleeping having completed a master within itself, and is
11626waiting for the tasks dependent on that master to become terminated or
11627waiting on a terminate Phase.
11628
11629@item Wait Child in Term Alt
11630The task is sleeping waiting for tasks on terminate alternatives to
11631finish terminating.
11632
11633@item Accepting RV with @var{taskno}
11634The task is accepting a rendez-vous with the task @var{taskno}.
11635@end table
11636
11637@item Name
11638Name of the task in the program.
11639
11640@end table
11641
11642@kindex info task @var{taskno}
11643@item info task @var{taskno}
11644This command shows detailled informations on the specified task, as in
11645the following example:
11646@smallexample
11647@iftex
11648@leftskip=0.5cm
11649@end iftex
11650(@value{GDBP}) info tasks
11651 ID TID P-ID Pri State Name
11652 1 8077880 0 15 Child Activation Wait main_task
11653* 2 807c468 1 15 Running task_1
11654(@value{GDBP}) info task 2
11655Ada Task: 0x807c468
11656Name: task_1
11657Thread: 0x807f378
11658Parent: 1 (main_task)
11659Base Priority: 15
11660State: Runnable
11661@end smallexample
11662
11663@item task
11664@kindex task@r{ (Ada)}
11665@cindex current Ada task ID
11666This command prints the ID of the current task.
11667
11668@smallexample
11669@iftex
11670@leftskip=0.5cm
11671@end iftex
11672(@value{GDBP}) info tasks
11673 ID TID P-ID Pri State Name
11674 1 8077870 0 15 Child Activation Wait main_task
11675* 2 807c458 1 15 Running t
11676(@value{GDBP}) task
11677[Current task is 2]
11678@end smallexample
11679
11680@item task @var{taskno}
11681@cindex Ada task switching
11682This command is like the @code{thread @var{threadno}}
11683command (@pxref{Threads}). It switches the context of debugging
11684from the current task to the given task.
11685
11686@smallexample
11687@iftex
11688@leftskip=0.5cm
11689@end iftex
11690(@value{GDBP}) info tasks
11691 ID TID P-ID Pri State Name
11692 1 8077870 0 15 Child Activation Wait main_task
11693* 2 807c458 1 15 Running t
11694(@value{GDBP}) task 1
11695[Switching to task 1]
11696#0 0x8067726 in pthread_cond_wait ()
11697(@value{GDBP}) bt
11698#0 0x8067726 in pthread_cond_wait ()
11699#1 0x8056714 in system.os_interface.pthread_cond_wait ()
11700#2 0x805cb63 in system.task_primitives.operations.sleep ()
11701#3 0x806153e in system.tasking.stages.activate_tasks ()
11702#4 0x804aacc in un () at un.adb:5
11703@end smallexample
11704
11705@end table
11706
11707@node Ada Tasks and Core Files
11708@subsubsection Tasking Support when Debugging Core Files
11709@cindex Ada tasking and core file debugging
11710
11711When inspecting a core file, as opposed to debugging a live program,
11712tasking support may be limited or even unavailable, depending on
11713the platform being used.
11714For instance, on x86-linux, the list of tasks is available, but task
11715switching is not supported. On Tru64, however, task switching will work
11716as usual.
11717
11718On certain platforms, including Tru64, the debugger needs to perform some
11719memory writes in order to provide Ada tasking support. When inspecting
11720a core file, this means that the core file must be opened with read-write
11721privileges, using the command @samp{"set write on"} (@pxref{Patching}).
11722Under these circumstances, you should make a backup copy of the core
11723file before inspecting it with @value{GDBN}.
11724
e07c999f
PH
11725@node Ada Glitches
11726@subsubsection Known Peculiarities of Ada Mode
11727@cindex Ada, problems
11728
11729Besides the omissions listed previously (@pxref{Omissions from Ada}),
11730we know of several problems with and limitations of Ada mode in
11731@value{GDBN},
11732some of which will be fixed with planned future releases of the debugger
11733and the GNU Ada compiler.
11734
11735@itemize @bullet
11736@item
11737Currently, the debugger
11738has insufficient information to determine whether certain pointers represent
11739pointers to objects or the objects themselves.
11740Thus, the user may have to tack an extra @code{.all} after an expression
11741to get it printed properly.
11742
11743@item
11744Static constants that the compiler chooses not to materialize as objects in
11745storage are invisible to the debugger.
11746
11747@item
11748Named parameter associations in function argument lists are ignored (the
11749argument lists are treated as positional).
11750
11751@item
11752Many useful library packages are currently invisible to the debugger.
11753
11754@item
11755Fixed-point arithmetic, conversions, input, and output is carried out using
11756floating-point arithmetic, and may give results that only approximate those on
11757the host machine.
11758
11759@item
11760The type of the @t{'Address} attribute may not be @code{System.Address}.
11761
11762@item
11763The GNAT compiler never generates the prefix @code{Standard} for any of
11764the standard symbols defined by the Ada language. @value{GDBN} knows about
11765this: it will strip the prefix from names when you use it, and will never
11766look for a name you have so qualified among local symbols, nor match against
11767symbols in other packages or subprograms. If you have
11768defined entities anywhere in your program other than parameters and
11769local variables whose simple names match names in @code{Standard},
11770GNAT's lack of qualification here can cause confusion. When this happens,
11771you can usually resolve the confusion
11772by qualifying the problematic names with package
11773@code{Standard} explicitly.
11774@end itemize
11775
79a6e687
BW
11776@node Unsupported Languages
11777@section Unsupported Languages
4e562065
JB
11778
11779@cindex unsupported languages
11780@cindex minimal language
11781In addition to the other fully-supported programming languages,
11782@value{GDBN} also provides a pseudo-language, called @code{minimal}.
11783It does not represent a real programming language, but provides a set
11784of capabilities close to what the C or assembly languages provide.
11785This should allow most simple operations to be performed while debugging
11786an application that uses a language currently not supported by @value{GDBN}.
11787
11788If the language is set to @code{auto}, @value{GDBN} will automatically
11789select this language if the current frame corresponds to an unsupported
11790language.
11791
6d2ebf8b 11792@node Symbols
c906108c
SS
11793@chapter Examining the Symbol Table
11794
d4f3574e 11795The commands described in this chapter allow you to inquire about the
c906108c
SS
11796symbols (names of variables, functions and types) defined in your
11797program. This information is inherent in the text of your program and
11798does not change as your program executes. @value{GDBN} finds it in your
11799program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
11800(@pxref{File Options, ,Choosing Files}), or by one of the
11801file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
11802
11803@cindex symbol names
11804@cindex names of symbols
11805@cindex quoting names
11806Occasionally, you may need to refer to symbols that contain unusual
11807characters, which @value{GDBN} ordinarily treats as word delimiters. The
11808most frequent case is in referring to static variables in other
79a6e687 11809source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
11810are recorded in object files as debugging symbols, but @value{GDBN} would
11811ordinarily parse a typical file name, like @file{foo.c}, as the three words
11812@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
11813@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
11814
474c8240 11815@smallexample
c906108c 11816p 'foo.c'::x
474c8240 11817@end smallexample
c906108c
SS
11818
11819@noindent
11820looks up the value of @code{x} in the scope of the file @file{foo.c}.
11821
11822@table @code
a8f24a35
EZ
11823@cindex case-insensitive symbol names
11824@cindex case sensitivity in symbol names
11825@kindex set case-sensitive
11826@item set case-sensitive on
11827@itemx set case-sensitive off
11828@itemx set case-sensitive auto
11829Normally, when @value{GDBN} looks up symbols, it matches their names
11830with case sensitivity determined by the current source language.
11831Occasionally, you may wish to control that. The command @code{set
11832case-sensitive} lets you do that by specifying @code{on} for
11833case-sensitive matches or @code{off} for case-insensitive ones. If
11834you specify @code{auto}, case sensitivity is reset to the default
11835suitable for the source language. The default is case-sensitive
11836matches for all languages except for Fortran, for which the default is
11837case-insensitive matches.
11838
9c16f35a
EZ
11839@kindex show case-sensitive
11840@item show case-sensitive
a8f24a35
EZ
11841This command shows the current setting of case sensitivity for symbols
11842lookups.
11843
c906108c 11844@kindex info address
b37052ae 11845@cindex address of a symbol
c906108c
SS
11846@item info address @var{symbol}
11847Describe where the data for @var{symbol} is stored. For a register
11848variable, this says which register it is kept in. For a non-register
11849local variable, this prints the stack-frame offset at which the variable
11850is always stored.
11851
11852Note the contrast with @samp{print &@var{symbol}}, which does not work
11853at all for a register variable, and for a stack local variable prints
11854the exact address of the current instantiation of the variable.
11855
3d67e040 11856@kindex info symbol
b37052ae 11857@cindex symbol from address
9c16f35a 11858@cindex closest symbol and offset for an address
3d67e040
EZ
11859@item info symbol @var{addr}
11860Print the name of a symbol which is stored at the address @var{addr}.
11861If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
11862nearest symbol and an offset from it:
11863
474c8240 11864@smallexample
3d67e040
EZ
11865(@value{GDBP}) info symbol 0x54320
11866_initialize_vx + 396 in section .text
474c8240 11867@end smallexample
3d67e040
EZ
11868
11869@noindent
11870This is the opposite of the @code{info address} command. You can use
11871it to find out the name of a variable or a function given its address.
11872
c14c28ba
PP
11873For dynamically linked executables, the name of executable or shared
11874library containing the symbol is also printed:
11875
11876@smallexample
11877(@value{GDBP}) info symbol 0x400225
11878_start + 5 in section .text of /tmp/a.out
11879(@value{GDBP}) info symbol 0x2aaaac2811cf
11880__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
11881@end smallexample
11882
c906108c 11883@kindex whatis
62f3a2ba
FF
11884@item whatis [@var{arg}]
11885Print the data type of @var{arg}, which can be either an expression or
11886a data type. With no argument, print the data type of @code{$}, the
11887last value in the value history. If @var{arg} is an expression, it is
11888not actually evaluated, and any side-effecting operations (such as
11889assignments or function calls) inside it do not take place. If
11890@var{arg} is a type name, it may be the name of a type or typedef, or
11891for C code it may have the form @samp{class @var{class-name}},
11892@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
11893@samp{enum @var{enum-tag}}.
c906108c
SS
11894@xref{Expressions, ,Expressions}.
11895
c906108c 11896@kindex ptype
62f3a2ba
FF
11897@item ptype [@var{arg}]
11898@code{ptype} accepts the same arguments as @code{whatis}, but prints a
11899detailed description of the type, instead of just the name of the type.
11900@xref{Expressions, ,Expressions}.
c906108c
SS
11901
11902For example, for this variable declaration:
11903
474c8240 11904@smallexample
c906108c 11905struct complex @{double real; double imag;@} v;
474c8240 11906@end smallexample
c906108c
SS
11907
11908@noindent
11909the two commands give this output:
11910
474c8240 11911@smallexample
c906108c
SS
11912@group
11913(@value{GDBP}) whatis v
11914type = struct complex
11915(@value{GDBP}) ptype v
11916type = struct complex @{
11917 double real;
11918 double imag;
11919@}
11920@end group
474c8240 11921@end smallexample
c906108c
SS
11922
11923@noindent
11924As with @code{whatis}, using @code{ptype} without an argument refers to
11925the type of @code{$}, the last value in the value history.
11926
ab1adacd
EZ
11927@cindex incomplete type
11928Sometimes, programs use opaque data types or incomplete specifications
11929of complex data structure. If the debug information included in the
11930program does not allow @value{GDBN} to display a full declaration of
11931the data type, it will say @samp{<incomplete type>}. For example,
11932given these declarations:
11933
11934@smallexample
11935 struct foo;
11936 struct foo *fooptr;
11937@end smallexample
11938
11939@noindent
11940but no definition for @code{struct foo} itself, @value{GDBN} will say:
11941
11942@smallexample
ddb50cd7 11943 (@value{GDBP}) ptype foo
ab1adacd
EZ
11944 $1 = <incomplete type>
11945@end smallexample
11946
11947@noindent
11948``Incomplete type'' is C terminology for data types that are not
11949completely specified.
11950
c906108c
SS
11951@kindex info types
11952@item info types @var{regexp}
11953@itemx info types
09d4efe1
EZ
11954Print a brief description of all types whose names match the regular
11955expression @var{regexp} (or all types in your program, if you supply
11956no argument). Each complete typename is matched as though it were a
11957complete line; thus, @samp{i type value} gives information on all
11958types in your program whose names include the string @code{value}, but
11959@samp{i type ^value$} gives information only on types whose complete
11960name is @code{value}.
c906108c
SS
11961
11962This command differs from @code{ptype} in two ways: first, like
11963@code{whatis}, it does not print a detailed description; second, it
11964lists all source files where a type is defined.
11965
b37052ae
EZ
11966@kindex info scope
11967@cindex local variables
09d4efe1 11968@item info scope @var{location}
b37052ae 11969List all the variables local to a particular scope. This command
09d4efe1
EZ
11970accepts a @var{location} argument---a function name, a source line, or
11971an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
11972to the scope defined by that location. (@xref{Specify Location}, for
11973details about supported forms of @var{location}.) For example:
b37052ae
EZ
11974
11975@smallexample
11976(@value{GDBP}) @b{info scope command_line_handler}
11977Scope for command_line_handler:
11978Symbol rl is an argument at stack/frame offset 8, length 4.
11979Symbol linebuffer is in static storage at address 0x150a18, length 4.
11980Symbol linelength is in static storage at address 0x150a1c, length 4.
11981Symbol p is a local variable in register $esi, length 4.
11982Symbol p1 is a local variable in register $ebx, length 4.
11983Symbol nline is a local variable in register $edx, length 4.
11984Symbol repeat is a local variable at frame offset -8, length 4.
11985@end smallexample
11986
f5c37c66
EZ
11987@noindent
11988This command is especially useful for determining what data to collect
11989during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
11990collect}.
11991
c906108c
SS
11992@kindex info source
11993@item info source
919d772c
JB
11994Show information about the current source file---that is, the source file for
11995the function containing the current point of execution:
11996@itemize @bullet
11997@item
11998the name of the source file, and the directory containing it,
11999@item
12000the directory it was compiled in,
12001@item
12002its length, in lines,
12003@item
12004which programming language it is written in,
12005@item
12006whether the executable includes debugging information for that file, and
12007if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
12008@item
12009whether the debugging information includes information about
12010preprocessor macros.
12011@end itemize
12012
c906108c
SS
12013
12014@kindex info sources
12015@item info sources
12016Print the names of all source files in your program for which there is
12017debugging information, organized into two lists: files whose symbols
12018have already been read, and files whose symbols will be read when needed.
12019
12020@kindex info functions
12021@item info functions
12022Print the names and data types of all defined functions.
12023
12024@item info functions @var{regexp}
12025Print the names and data types of all defined functions
12026whose names contain a match for regular expression @var{regexp}.
12027Thus, @samp{info fun step} finds all functions whose names
12028include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 12029start with @code{step}. If a function name contains characters
c1468174 12030that conflict with the regular expression language (e.g.@:
1c5dfdad 12031@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
12032
12033@kindex info variables
12034@item info variables
12035Print the names and data types of all variables that are declared
6ca652b0 12036outside of functions (i.e.@: excluding local variables).
c906108c
SS
12037
12038@item info variables @var{regexp}
12039Print the names and data types of all variables (except for local
12040variables) whose names contain a match for regular expression
12041@var{regexp}.
12042
b37303ee 12043@kindex info classes
721c2651 12044@cindex Objective-C, classes and selectors
b37303ee
AF
12045@item info classes
12046@itemx info classes @var{regexp}
12047Display all Objective-C classes in your program, or
12048(with the @var{regexp} argument) all those matching a particular regular
12049expression.
12050
12051@kindex info selectors
12052@item info selectors
12053@itemx info selectors @var{regexp}
12054Display all Objective-C selectors in your program, or
12055(with the @var{regexp} argument) all those matching a particular regular
12056expression.
12057
c906108c
SS
12058@ignore
12059This was never implemented.
12060@kindex info methods
12061@item info methods
12062@itemx info methods @var{regexp}
12063The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
12064methods within C@t{++} program, or (with the @var{regexp} argument) a
12065specific set of methods found in the various C@t{++} classes. Many
12066C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
12067from the @code{ptype} command can be overwhelming and hard to use. The
12068@code{info-methods} command filters the methods, printing only those
12069which match the regular-expression @var{regexp}.
12070@end ignore
12071
c906108c
SS
12072@cindex reloading symbols
12073Some systems allow individual object files that make up your program to
7a292a7a
SS
12074be replaced without stopping and restarting your program. For example,
12075in VxWorks you can simply recompile a defective object file and keep on
12076running. If you are running on one of these systems, you can allow
12077@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
12078
12079@table @code
12080@kindex set symbol-reloading
12081@item set symbol-reloading on
12082Replace symbol definitions for the corresponding source file when an
12083object file with a particular name is seen again.
12084
12085@item set symbol-reloading off
6d2ebf8b
SS
12086Do not replace symbol definitions when encountering object files of the
12087same name more than once. This is the default state; if you are not
12088running on a system that permits automatic relinking of modules, you
12089should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
12090may discard symbols when linking large programs, that may contain
12091several modules (from different directories or libraries) with the same
12092name.
c906108c
SS
12093
12094@kindex show symbol-reloading
12095@item show symbol-reloading
12096Show the current @code{on} or @code{off} setting.
12097@end table
c906108c 12098
9c16f35a 12099@cindex opaque data types
c906108c
SS
12100@kindex set opaque-type-resolution
12101@item set opaque-type-resolution on
12102Tell @value{GDBN} to resolve opaque types. An opaque type is a type
12103declared as a pointer to a @code{struct}, @code{class}, or
12104@code{union}---for example, @code{struct MyType *}---that is used in one
12105source file although the full declaration of @code{struct MyType} is in
12106another source file. The default is on.
12107
12108A change in the setting of this subcommand will not take effect until
12109the next time symbols for a file are loaded.
12110
12111@item set opaque-type-resolution off
12112Tell @value{GDBN} not to resolve opaque types. In this case, the type
12113is printed as follows:
12114@smallexample
12115@{<no data fields>@}
12116@end smallexample
12117
12118@kindex show opaque-type-resolution
12119@item show opaque-type-resolution
12120Show whether opaque types are resolved or not.
c906108c 12121
bf250677
DE
12122@kindex set print symbol-loading
12123@cindex print messages when symbols are loaded
12124@item set print symbol-loading
12125@itemx set print symbol-loading on
12126@itemx set print symbol-loading off
12127The @code{set print symbol-loading} command allows you to enable or
12128disable printing of messages when @value{GDBN} loads symbols.
12129By default, these messages will be printed, and normally this is what
12130you want. Disabling these messages is useful when debugging applications
12131with lots of shared libraries where the quantity of output can be more
12132annoying than useful.
12133
12134@kindex show print symbol-loading
12135@item show print symbol-loading
12136Show whether messages will be printed when @value{GDBN} loads symbols.
12137
c906108c
SS
12138@kindex maint print symbols
12139@cindex symbol dump
12140@kindex maint print psymbols
12141@cindex partial symbol dump
12142@item maint print symbols @var{filename}
12143@itemx maint print psymbols @var{filename}
12144@itemx maint print msymbols @var{filename}
12145Write a dump of debugging symbol data into the file @var{filename}.
12146These commands are used to debug the @value{GDBN} symbol-reading code. Only
12147symbols with debugging data are included. If you use @samp{maint print
12148symbols}, @value{GDBN} includes all the symbols for which it has already
12149collected full details: that is, @var{filename} reflects symbols for
12150only those files whose symbols @value{GDBN} has read. You can use the
12151command @code{info sources} to find out which files these are. If you
12152use @samp{maint print psymbols} instead, the dump shows information about
12153symbols that @value{GDBN} only knows partially---that is, symbols defined in
12154files that @value{GDBN} has skimmed, but not yet read completely. Finally,
12155@samp{maint print msymbols} dumps just the minimal symbol information
12156required for each object file from which @value{GDBN} has read some symbols.
79a6e687 12157@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 12158@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 12159
5e7b2f39
JB
12160@kindex maint info symtabs
12161@kindex maint info psymtabs
44ea7b70
JB
12162@cindex listing @value{GDBN}'s internal symbol tables
12163@cindex symbol tables, listing @value{GDBN}'s internal
12164@cindex full symbol tables, listing @value{GDBN}'s internal
12165@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
12166@item maint info symtabs @r{[} @var{regexp} @r{]}
12167@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
12168
12169List the @code{struct symtab} or @code{struct partial_symtab}
12170structures whose names match @var{regexp}. If @var{regexp} is not
12171given, list them all. The output includes expressions which you can
12172copy into a @value{GDBN} debugging this one to examine a particular
12173structure in more detail. For example:
12174
12175@smallexample
5e7b2f39 12176(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
12177@{ objfile /home/gnu/build/gdb/gdb
12178 ((struct objfile *) 0x82e69d0)
b383017d 12179 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
12180 ((struct partial_symtab *) 0x8474b10)
12181 readin no
12182 fullname (null)
12183 text addresses 0x814d3c8 -- 0x8158074
12184 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
12185 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
12186 dependencies (none)
12187 @}
12188@}
5e7b2f39 12189(@value{GDBP}) maint info symtabs
44ea7b70
JB
12190(@value{GDBP})
12191@end smallexample
12192@noindent
12193We see that there is one partial symbol table whose filename contains
12194the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
12195and we see that @value{GDBN} has not read in any symtabs yet at all.
12196If we set a breakpoint on a function, that will cause @value{GDBN} to
12197read the symtab for the compilation unit containing that function:
12198
12199@smallexample
12200(@value{GDBP}) break dwarf2_psymtab_to_symtab
12201Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
12202line 1574.
5e7b2f39 12203(@value{GDBP}) maint info symtabs
b383017d 12204@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 12205 ((struct objfile *) 0x82e69d0)
b383017d 12206 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
12207 ((struct symtab *) 0x86c1f38)
12208 dirname (null)
12209 fullname (null)
12210 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 12211 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
12212 debugformat DWARF 2
12213 @}
12214@}
b383017d 12215(@value{GDBP})
44ea7b70 12216@end smallexample
c906108c
SS
12217@end table
12218
44ea7b70 12219
6d2ebf8b 12220@node Altering
c906108c
SS
12221@chapter Altering Execution
12222
12223Once you think you have found an error in your program, you might want to
12224find out for certain whether correcting the apparent error would lead to
12225correct results in the rest of the run. You can find the answer by
12226experiment, using the @value{GDBN} features for altering execution of the
12227program.
12228
12229For example, you can store new values into variables or memory
7a292a7a
SS
12230locations, give your program a signal, restart it at a different
12231address, or even return prematurely from a function.
c906108c
SS
12232
12233@menu
12234* Assignment:: Assignment to variables
12235* Jumping:: Continuing at a different address
c906108c 12236* Signaling:: Giving your program a signal
c906108c
SS
12237* Returning:: Returning from a function
12238* Calling:: Calling your program's functions
12239* Patching:: Patching your program
12240@end menu
12241
6d2ebf8b 12242@node Assignment
79a6e687 12243@section Assignment to Variables
c906108c
SS
12244
12245@cindex assignment
12246@cindex setting variables
12247To alter the value of a variable, evaluate an assignment expression.
12248@xref{Expressions, ,Expressions}. For example,
12249
474c8240 12250@smallexample
c906108c 12251print x=4
474c8240 12252@end smallexample
c906108c
SS
12253
12254@noindent
12255stores the value 4 into the variable @code{x}, and then prints the
5d161b24 12256value of the assignment expression (which is 4).
c906108c
SS
12257@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
12258information on operators in supported languages.
c906108c
SS
12259
12260@kindex set variable
12261@cindex variables, setting
12262If you are not interested in seeing the value of the assignment, use the
12263@code{set} command instead of the @code{print} command. @code{set} is
12264really the same as @code{print} except that the expression's value is
12265not printed and is not put in the value history (@pxref{Value History,
79a6e687 12266,Value History}). The expression is evaluated only for its effects.
c906108c 12267
c906108c
SS
12268If the beginning of the argument string of the @code{set} command
12269appears identical to a @code{set} subcommand, use the @code{set
12270variable} command instead of just @code{set}. This command is identical
12271to @code{set} except for its lack of subcommands. For example, if your
12272program has a variable @code{width}, you get an error if you try to set
12273a new value with just @samp{set width=13}, because @value{GDBN} has the
12274command @code{set width}:
12275
474c8240 12276@smallexample
c906108c
SS
12277(@value{GDBP}) whatis width
12278type = double
12279(@value{GDBP}) p width
12280$4 = 13
12281(@value{GDBP}) set width=47
12282Invalid syntax in expression.
474c8240 12283@end smallexample
c906108c
SS
12284
12285@noindent
12286The invalid expression, of course, is @samp{=47}. In
12287order to actually set the program's variable @code{width}, use
12288
474c8240 12289@smallexample
c906108c 12290(@value{GDBP}) set var width=47
474c8240 12291@end smallexample
53a5351d 12292
c906108c
SS
12293Because the @code{set} command has many subcommands that can conflict
12294with the names of program variables, it is a good idea to use the
12295@code{set variable} command instead of just @code{set}. For example, if
12296your program has a variable @code{g}, you run into problems if you try
12297to set a new value with just @samp{set g=4}, because @value{GDBN} has
12298the command @code{set gnutarget}, abbreviated @code{set g}:
12299
474c8240 12300@smallexample
c906108c
SS
12301@group
12302(@value{GDBP}) whatis g
12303type = double
12304(@value{GDBP}) p g
12305$1 = 1
12306(@value{GDBP}) set g=4
2df3850c 12307(@value{GDBP}) p g
c906108c
SS
12308$2 = 1
12309(@value{GDBP}) r
12310The program being debugged has been started already.
12311Start it from the beginning? (y or n) y
12312Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
12313"/home/smith/cc_progs/a.out": can't open to read symbols:
12314 Invalid bfd target.
c906108c
SS
12315(@value{GDBP}) show g
12316The current BFD target is "=4".
12317@end group
474c8240 12318@end smallexample
c906108c
SS
12319
12320@noindent
12321The program variable @code{g} did not change, and you silently set the
12322@code{gnutarget} to an invalid value. In order to set the variable
12323@code{g}, use
12324
474c8240 12325@smallexample
c906108c 12326(@value{GDBP}) set var g=4
474c8240 12327@end smallexample
c906108c
SS
12328
12329@value{GDBN} allows more implicit conversions in assignments than C; you can
12330freely store an integer value into a pointer variable or vice versa,
12331and you can convert any structure to any other structure that is the
12332same length or shorter.
12333@comment FIXME: how do structs align/pad in these conversions?
12334@comment /doc@cygnus.com 18dec1990
12335
12336To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
12337construct to generate a value of specified type at a specified address
12338(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
12339to memory location @code{0x83040} as an integer (which implies a certain size
12340and representation in memory), and
12341
474c8240 12342@smallexample
c906108c 12343set @{int@}0x83040 = 4
474c8240 12344@end smallexample
c906108c
SS
12345
12346@noindent
12347stores the value 4 into that memory location.
12348
6d2ebf8b 12349@node Jumping
79a6e687 12350@section Continuing at a Different Address
c906108c
SS
12351
12352Ordinarily, when you continue your program, you do so at the place where
12353it stopped, with the @code{continue} command. You can instead continue at
12354an address of your own choosing, with the following commands:
12355
12356@table @code
12357@kindex jump
12358@item jump @var{linespec}
2a25a5ba
EZ
12359@itemx jump @var{location}
12360Resume execution at line @var{linespec} or at address given by
12361@var{location}. Execution stops again immediately if there is a
12362breakpoint there. @xref{Specify Location}, for a description of the
12363different forms of @var{linespec} and @var{location}. It is common
12364practice to use the @code{tbreak} command in conjunction with
12365@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
12366
12367The @code{jump} command does not change the current stack frame, or
12368the stack pointer, or the contents of any memory location or any
12369register other than the program counter. If line @var{linespec} is in
12370a different function from the one currently executing, the results may
12371be bizarre if the two functions expect different patterns of arguments or
12372of local variables. For this reason, the @code{jump} command requests
12373confirmation if the specified line is not in the function currently
12374executing. However, even bizarre results are predictable if you are
12375well acquainted with the machine-language code of your program.
c906108c
SS
12376@end table
12377
c906108c 12378@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
12379On many systems, you can get much the same effect as the @code{jump}
12380command by storing a new value into the register @code{$pc}. The
12381difference is that this does not start your program running; it only
12382changes the address of where it @emph{will} run when you continue. For
12383example,
c906108c 12384
474c8240 12385@smallexample
c906108c 12386set $pc = 0x485
474c8240 12387@end smallexample
c906108c
SS
12388
12389@noindent
12390makes the next @code{continue} command or stepping command execute at
12391address @code{0x485}, rather than at the address where your program stopped.
79a6e687 12392@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
12393
12394The most common occasion to use the @code{jump} command is to back
12395up---perhaps with more breakpoints set---over a portion of a program
12396that has already executed, in order to examine its execution in more
12397detail.
12398
c906108c 12399@c @group
6d2ebf8b 12400@node Signaling
79a6e687 12401@section Giving your Program a Signal
9c16f35a 12402@cindex deliver a signal to a program
c906108c
SS
12403
12404@table @code
12405@kindex signal
12406@item signal @var{signal}
12407Resume execution where your program stopped, but immediately give it the
12408signal @var{signal}. @var{signal} can be the name or the number of a
12409signal. For example, on many systems @code{signal 2} and @code{signal
12410SIGINT} are both ways of sending an interrupt signal.
12411
12412Alternatively, if @var{signal} is zero, continue execution without
12413giving a signal. This is useful when your program stopped on account of
12414a signal and would ordinary see the signal when resumed with the
12415@code{continue} command; @samp{signal 0} causes it to resume without a
12416signal.
12417
12418@code{signal} does not repeat when you press @key{RET} a second time
12419after executing the command.
12420@end table
12421@c @end group
12422
12423Invoking the @code{signal} command is not the same as invoking the
12424@code{kill} utility from the shell. Sending a signal with @code{kill}
12425causes @value{GDBN} to decide what to do with the signal depending on
12426the signal handling tables (@pxref{Signals}). The @code{signal} command
12427passes the signal directly to your program.
12428
c906108c 12429
6d2ebf8b 12430@node Returning
79a6e687 12431@section Returning from a Function
c906108c
SS
12432
12433@table @code
12434@cindex returning from a function
12435@kindex return
12436@item return
12437@itemx return @var{expression}
12438You can cancel execution of a function call with the @code{return}
12439command. If you give an
12440@var{expression} argument, its value is used as the function's return
12441value.
12442@end table
12443
12444When you use @code{return}, @value{GDBN} discards the selected stack frame
12445(and all frames within it). You can think of this as making the
12446discarded frame return prematurely. If you wish to specify a value to
12447be returned, give that value as the argument to @code{return}.
12448
12449This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 12450Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
12451innermost remaining frame. That frame becomes selected. The
12452specified value is stored in the registers used for returning values
12453of functions.
12454
12455The @code{return} command does not resume execution; it leaves the
12456program stopped in the state that would exist if the function had just
12457returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 12458and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
12459selected stack frame returns naturally.
12460
6d2ebf8b 12461@node Calling
79a6e687 12462@section Calling Program Functions
c906108c 12463
f8568604 12464@table @code
c906108c 12465@cindex calling functions
f8568604
EZ
12466@cindex inferior functions, calling
12467@item print @var{expr}
d3e8051b 12468Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
12469@var{expr} may include calls to functions in the program being
12470debugged.
12471
c906108c 12472@kindex call
c906108c
SS
12473@item call @var{expr}
12474Evaluate the expression @var{expr} without displaying @code{void}
12475returned values.
c906108c
SS
12476
12477You can use this variant of the @code{print} command if you want to
f8568604
EZ
12478execute a function from your program that does not return anything
12479(a.k.a.@: @dfn{a void function}), but without cluttering the output
12480with @code{void} returned values that @value{GDBN} will otherwise
12481print. If the result is not void, it is printed and saved in the
12482value history.
12483@end table
12484
9c16f35a
EZ
12485It is possible for the function you call via the @code{print} or
12486@code{call} command to generate a signal (e.g., if there's a bug in
12487the function, or if you passed it incorrect arguments). What happens
12488in that case is controlled by the @code{set unwindonsignal} command.
12489
12490@table @code
12491@item set unwindonsignal
12492@kindex set unwindonsignal
12493@cindex unwind stack in called functions
12494@cindex call dummy stack unwinding
12495Set unwinding of the stack if a signal is received while in a function
12496that @value{GDBN} called in the program being debugged. If set to on,
12497@value{GDBN} unwinds the stack it created for the call and restores
12498the context to what it was before the call. If set to off (the
12499default), @value{GDBN} stops in the frame where the signal was
12500received.
12501
12502@item show unwindonsignal
12503@kindex show unwindonsignal
12504Show the current setting of stack unwinding in the functions called by
12505@value{GDBN}.
12506@end table
12507
f8568604
EZ
12508@cindex weak alias functions
12509Sometimes, a function you wish to call is actually a @dfn{weak alias}
12510for another function. In such case, @value{GDBN} might not pick up
12511the type information, including the types of the function arguments,
12512which causes @value{GDBN} to call the inferior function incorrectly.
12513As a result, the called function will function erroneously and may
12514even crash. A solution to that is to use the name of the aliased
12515function instead.
c906108c 12516
6d2ebf8b 12517@node Patching
79a6e687 12518@section Patching Programs
7a292a7a 12519
c906108c
SS
12520@cindex patching binaries
12521@cindex writing into executables
c906108c 12522@cindex writing into corefiles
c906108c 12523
7a292a7a
SS
12524By default, @value{GDBN} opens the file containing your program's
12525executable code (or the corefile) read-only. This prevents accidental
12526alterations to machine code; but it also prevents you from intentionally
12527patching your program's binary.
c906108c
SS
12528
12529If you'd like to be able to patch the binary, you can specify that
12530explicitly with the @code{set write} command. For example, you might
12531want to turn on internal debugging flags, or even to make emergency
12532repairs.
12533
12534@table @code
12535@kindex set write
12536@item set write on
12537@itemx set write off
7a292a7a 12538If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 12539core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
12540off} (the default), @value{GDBN} opens them read-only.
12541
12542If you have already loaded a file, you must load it again (using the
7a292a7a
SS
12543@code{exec-file} or @code{core-file} command) after changing @code{set
12544write}, for your new setting to take effect.
c906108c
SS
12545
12546@item show write
12547@kindex show write
7a292a7a
SS
12548Display whether executable files and core files are opened for writing
12549as well as reading.
c906108c
SS
12550@end table
12551
6d2ebf8b 12552@node GDB Files
c906108c
SS
12553@chapter @value{GDBN} Files
12554
7a292a7a
SS
12555@value{GDBN} needs to know the file name of the program to be debugged,
12556both in order to read its symbol table and in order to start your
12557program. To debug a core dump of a previous run, you must also tell
12558@value{GDBN} the name of the core dump file.
c906108c
SS
12559
12560@menu
12561* Files:: Commands to specify files
5b5d99cf 12562* Separate Debug Files:: Debugging information in separate files
c906108c
SS
12563* Symbol Errors:: Errors reading symbol files
12564@end menu
12565
6d2ebf8b 12566@node Files
79a6e687 12567@section Commands to Specify Files
c906108c 12568
7a292a7a 12569@cindex symbol table
c906108c 12570@cindex core dump file
7a292a7a
SS
12571
12572You may want to specify executable and core dump file names. The usual
12573way to do this is at start-up time, using the arguments to
12574@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
12575Out of @value{GDBN}}).
c906108c
SS
12576
12577Occasionally it is necessary to change to a different file during a
397ca115
EZ
12578@value{GDBN} session. Or you may run @value{GDBN} and forget to
12579specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
12580via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
12581Program}). In these situations the @value{GDBN} commands to specify
0869d01b 12582new files are useful.
c906108c
SS
12583
12584@table @code
12585@cindex executable file
12586@kindex file
12587@item file @var{filename}
12588Use @var{filename} as the program to be debugged. It is read for its
12589symbols and for the contents of pure memory. It is also the program
12590executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
12591directory and the file is not found in the @value{GDBN} working directory,
12592@value{GDBN} uses the environment variable @code{PATH} as a list of
12593directories to search, just as the shell does when looking for a program
12594to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
12595and your program, using the @code{path} command.
12596
fc8be69e
EZ
12597@cindex unlinked object files
12598@cindex patching object files
12599You can load unlinked object @file{.o} files into @value{GDBN} using
12600the @code{file} command. You will not be able to ``run'' an object
12601file, but you can disassemble functions and inspect variables. Also,
12602if the underlying BFD functionality supports it, you could use
12603@kbd{gdb -write} to patch object files using this technique. Note
12604that @value{GDBN} can neither interpret nor modify relocations in this
12605case, so branches and some initialized variables will appear to go to
12606the wrong place. But this feature is still handy from time to time.
12607
c906108c
SS
12608@item file
12609@code{file} with no argument makes @value{GDBN} discard any information it
12610has on both executable file and the symbol table.
12611
12612@kindex exec-file
12613@item exec-file @r{[} @var{filename} @r{]}
12614Specify that the program to be run (but not the symbol table) is found
12615in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
12616if necessary to locate your program. Omitting @var{filename} means to
12617discard information on the executable file.
12618
12619@kindex symbol-file
12620@item symbol-file @r{[} @var{filename} @r{]}
12621Read symbol table information from file @var{filename}. @code{PATH} is
12622searched when necessary. Use the @code{file} command to get both symbol
12623table and program to run from the same file.
12624
12625@code{symbol-file} with no argument clears out @value{GDBN} information on your
12626program's symbol table.
12627
ae5a43e0
DJ
12628The @code{symbol-file} command causes @value{GDBN} to forget the contents of
12629some breakpoints and auto-display expressions. This is because they may
12630contain pointers to the internal data recording symbols and data types,
12631which are part of the old symbol table data being discarded inside
12632@value{GDBN}.
c906108c
SS
12633
12634@code{symbol-file} does not repeat if you press @key{RET} again after
12635executing it once.
12636
12637When @value{GDBN} is configured for a particular environment, it
12638understands debugging information in whatever format is the standard
12639generated for that environment; you may use either a @sc{gnu} compiler, or
12640other compilers that adhere to the local conventions.
c906108c 12641Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 12642using @code{@value{NGCC}} you can generate debugging information for
c906108c 12643optimized code.
c906108c
SS
12644
12645For most kinds of object files, with the exception of old SVR3 systems
12646using COFF, the @code{symbol-file} command does not normally read the
12647symbol table in full right away. Instead, it scans the symbol table
12648quickly to find which source files and which symbols are present. The
12649details are read later, one source file at a time, as they are needed.
12650
12651The purpose of this two-stage reading strategy is to make @value{GDBN}
12652start up faster. For the most part, it is invisible except for
12653occasional pauses while the symbol table details for a particular source
12654file are being read. (The @code{set verbose} command can turn these
12655pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 12656Warnings and Messages}.)
c906108c 12657
c906108c
SS
12658We have not implemented the two-stage strategy for COFF yet. When the
12659symbol table is stored in COFF format, @code{symbol-file} reads the
12660symbol table data in full right away. Note that ``stabs-in-COFF''
12661still does the two-stage strategy, since the debug info is actually
12662in stabs format.
12663
12664@kindex readnow
12665@cindex reading symbols immediately
12666@cindex symbols, reading immediately
a94ab193
EZ
12667@item symbol-file @var{filename} @r{[} -readnow @r{]}
12668@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
12669You can override the @value{GDBN} two-stage strategy for reading symbol
12670tables by using the @samp{-readnow} option with any of the commands that
12671load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 12672entire symbol table available.
c906108c 12673
c906108c
SS
12674@c FIXME: for now no mention of directories, since this seems to be in
12675@c flux. 13mar1992 status is that in theory GDB would look either in
12676@c current dir or in same dir as myprog; but issues like competing
12677@c GDB's, or clutter in system dirs, mean that in practice right now
12678@c only current dir is used. FFish says maybe a special GDB hierarchy
12679@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
12680@c files.
12681
c906108c 12682@kindex core-file
09d4efe1 12683@item core-file @r{[}@var{filename}@r{]}
4644b6e3 12684@itemx core
c906108c
SS
12685Specify the whereabouts of a core dump file to be used as the ``contents
12686of memory''. Traditionally, core files contain only some parts of the
12687address space of the process that generated them; @value{GDBN} can access the
12688executable file itself for other parts.
12689
12690@code{core-file} with no argument specifies that no core file is
12691to be used.
12692
12693Note that the core file is ignored when your program is actually running
7a292a7a
SS
12694under @value{GDBN}. So, if you have been running your program and you
12695wish to debug a core file instead, you must kill the subprocess in which
12696the program is running. To do this, use the @code{kill} command
79a6e687 12697(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 12698
c906108c
SS
12699@kindex add-symbol-file
12700@cindex dynamic linking
12701@item add-symbol-file @var{filename} @var{address}
a94ab193 12702@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 12703@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
12704The @code{add-symbol-file} command reads additional symbol table
12705information from the file @var{filename}. You would use this command
12706when @var{filename} has been dynamically loaded (by some other means)
12707into the program that is running. @var{address} should be the memory
12708address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
12709this out for itself. You can additionally specify an arbitrary number
12710of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
12711section name and base address for that section. You can specify any
12712@var{address} as an expression.
c906108c
SS
12713
12714The symbol table of the file @var{filename} is added to the symbol table
12715originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
12716@code{add-symbol-file} command any number of times; the new symbol data
12717thus read keeps adding to the old. To discard all old symbol data
12718instead, use the @code{symbol-file} command without any arguments.
c906108c 12719
17d9d558
JB
12720@cindex relocatable object files, reading symbols from
12721@cindex object files, relocatable, reading symbols from
12722@cindex reading symbols from relocatable object files
12723@cindex symbols, reading from relocatable object files
12724@cindex @file{.o} files, reading symbols from
12725Although @var{filename} is typically a shared library file, an
12726executable file, or some other object file which has been fully
12727relocated for loading into a process, you can also load symbolic
12728information from relocatable @file{.o} files, as long as:
12729
12730@itemize @bullet
12731@item
12732the file's symbolic information refers only to linker symbols defined in
12733that file, not to symbols defined by other object files,
12734@item
12735every section the file's symbolic information refers to has actually
12736been loaded into the inferior, as it appears in the file, and
12737@item
12738you can determine the address at which every section was loaded, and
12739provide these to the @code{add-symbol-file} command.
12740@end itemize
12741
12742@noindent
12743Some embedded operating systems, like Sun Chorus and VxWorks, can load
12744relocatable files into an already running program; such systems
12745typically make the requirements above easy to meet. However, it's
12746important to recognize that many native systems use complex link
49efadf5 12747procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
12748assembly, for example) that make the requirements difficult to meet. In
12749general, one cannot assume that using @code{add-symbol-file} to read a
12750relocatable object file's symbolic information will have the same effect
12751as linking the relocatable object file into the program in the normal
12752way.
12753
c906108c
SS
12754@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
12755
c45da7e6
EZ
12756@kindex add-symbol-file-from-memory
12757@cindex @code{syscall DSO}
12758@cindex load symbols from memory
12759@item add-symbol-file-from-memory @var{address}
12760Load symbols from the given @var{address} in a dynamically loaded
12761object file whose image is mapped directly into the inferior's memory.
12762For example, the Linux kernel maps a @code{syscall DSO} into each
12763process's address space; this DSO provides kernel-specific code for
12764some system calls. The argument can be any expression whose
12765evaluation yields the address of the file's shared object file header.
12766For this command to work, you must have used @code{symbol-file} or
12767@code{exec-file} commands in advance.
12768
09d4efe1
EZ
12769@kindex add-shared-symbol-files
12770@kindex assf
12771@item add-shared-symbol-files @var{library-file}
12772@itemx assf @var{library-file}
12773The @code{add-shared-symbol-files} command can currently be used only
12774in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
12775alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
12776@value{GDBN} automatically looks for shared libraries, however if
12777@value{GDBN} does not find yours, you can invoke
12778@code{add-shared-symbol-files}. It takes one argument: the shared
12779library's file name. @code{assf} is a shorthand alias for
12780@code{add-shared-symbol-files}.
c906108c 12781
c906108c 12782@kindex section
09d4efe1
EZ
12783@item section @var{section} @var{addr}
12784The @code{section} command changes the base address of the named
12785@var{section} of the exec file to @var{addr}. This can be used if the
12786exec file does not contain section addresses, (such as in the
12787@code{a.out} format), or when the addresses specified in the file
12788itself are wrong. Each section must be changed separately. The
12789@code{info files} command, described below, lists all the sections and
12790their addresses.
c906108c
SS
12791
12792@kindex info files
12793@kindex info target
12794@item info files
12795@itemx info target
7a292a7a
SS
12796@code{info files} and @code{info target} are synonymous; both print the
12797current target (@pxref{Targets, ,Specifying a Debugging Target}),
12798including the names of the executable and core dump files currently in
12799use by @value{GDBN}, and the files from which symbols were loaded. The
12800command @code{help target} lists all possible targets rather than
12801current ones.
12802
fe95c787
MS
12803@kindex maint info sections
12804@item maint info sections
12805Another command that can give you extra information about program sections
12806is @code{maint info sections}. In addition to the section information
12807displayed by @code{info files}, this command displays the flags and file
12808offset of each section in the executable and core dump files. In addition,
12809@code{maint info sections} provides the following command options (which
12810may be arbitrarily combined):
12811
12812@table @code
12813@item ALLOBJ
12814Display sections for all loaded object files, including shared libraries.
12815@item @var{sections}
6600abed 12816Display info only for named @var{sections}.
fe95c787
MS
12817@item @var{section-flags}
12818Display info only for sections for which @var{section-flags} are true.
12819The section flags that @value{GDBN} currently knows about are:
12820@table @code
12821@item ALLOC
12822Section will have space allocated in the process when loaded.
12823Set for all sections except those containing debug information.
12824@item LOAD
12825Section will be loaded from the file into the child process memory.
12826Set for pre-initialized code and data, clear for @code{.bss} sections.
12827@item RELOC
12828Section needs to be relocated before loading.
12829@item READONLY
12830Section cannot be modified by the child process.
12831@item CODE
12832Section contains executable code only.
6600abed 12833@item DATA
fe95c787
MS
12834Section contains data only (no executable code).
12835@item ROM
12836Section will reside in ROM.
12837@item CONSTRUCTOR
12838Section contains data for constructor/destructor lists.
12839@item HAS_CONTENTS
12840Section is not empty.
12841@item NEVER_LOAD
12842An instruction to the linker to not output the section.
12843@item COFF_SHARED_LIBRARY
12844A notification to the linker that the section contains
12845COFF shared library information.
12846@item IS_COMMON
12847Section contains common symbols.
12848@end table
12849@end table
6763aef9 12850@kindex set trust-readonly-sections
9c16f35a 12851@cindex read-only sections
6763aef9
MS
12852@item set trust-readonly-sections on
12853Tell @value{GDBN} that readonly sections in your object file
6ca652b0 12854really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
12855In that case, @value{GDBN} can fetch values from these sections
12856out of the object file, rather than from the target program.
12857For some targets (notably embedded ones), this can be a significant
12858enhancement to debugging performance.
12859
12860The default is off.
12861
12862@item set trust-readonly-sections off
15110bc3 12863Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
12864the contents of the section might change while the program is running,
12865and must therefore be fetched from the target when needed.
9c16f35a
EZ
12866
12867@item show trust-readonly-sections
12868Show the current setting of trusting readonly sections.
c906108c
SS
12869@end table
12870
12871All file-specifying commands allow both absolute and relative file names
12872as arguments. @value{GDBN} always converts the file name to an absolute file
12873name and remembers it that way.
12874
c906108c 12875@cindex shared libraries
9cceb671
DJ
12876@anchor{Shared Libraries}
12877@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 12878and IBM RS/6000 AIX shared libraries.
53a5351d 12879
9cceb671
DJ
12880On MS-Windows @value{GDBN} must be linked with the Expat library to support
12881shared libraries. @xref{Expat}.
12882
c906108c
SS
12883@value{GDBN} automatically loads symbol definitions from shared libraries
12884when you use the @code{run} command, or when you examine a core file.
12885(Before you issue the @code{run} command, @value{GDBN} does not understand
12886references to a function in a shared library, however---unless you are
12887debugging a core file).
53a5351d
JM
12888
12889On HP-UX, if the program loads a library explicitly, @value{GDBN}
12890automatically loads the symbols at the time of the @code{shl_load} call.
12891
c906108c
SS
12892@c FIXME: some @value{GDBN} release may permit some refs to undef
12893@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
12894@c FIXME...lib; check this from time to time when updating manual
12895
b7209cb4
FF
12896There are times, however, when you may wish to not automatically load
12897symbol definitions from shared libraries, such as when they are
12898particularly large or there are many of them.
12899
12900To control the automatic loading of shared library symbols, use the
12901commands:
12902
12903@table @code
12904@kindex set auto-solib-add
12905@item set auto-solib-add @var{mode}
12906If @var{mode} is @code{on}, symbols from all shared object libraries
12907will be loaded automatically when the inferior begins execution, you
12908attach to an independently started inferior, or when the dynamic linker
12909informs @value{GDBN} that a new library has been loaded. If @var{mode}
12910is @code{off}, symbols must be loaded manually, using the
12911@code{sharedlibrary} command. The default value is @code{on}.
12912
dcaf7c2c
EZ
12913@cindex memory used for symbol tables
12914If your program uses lots of shared libraries with debug info that
12915takes large amounts of memory, you can decrease the @value{GDBN}
12916memory footprint by preventing it from automatically loading the
12917symbols from shared libraries. To that end, type @kbd{set
12918auto-solib-add off} before running the inferior, then load each
12919library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 12920@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
12921the libraries whose symbols you want to be loaded.
12922
b7209cb4
FF
12923@kindex show auto-solib-add
12924@item show auto-solib-add
12925Display the current autoloading mode.
12926@end table
12927
c45da7e6 12928@cindex load shared library
b7209cb4
FF
12929To explicitly load shared library symbols, use the @code{sharedlibrary}
12930command:
12931
c906108c
SS
12932@table @code
12933@kindex info sharedlibrary
12934@kindex info share
12935@item info share
12936@itemx info sharedlibrary
12937Print the names of the shared libraries which are currently loaded.
12938
12939@kindex sharedlibrary
12940@kindex share
12941@item sharedlibrary @var{regex}
12942@itemx share @var{regex}
c906108c
SS
12943Load shared object library symbols for files matching a
12944Unix regular expression.
12945As with files loaded automatically, it only loads shared libraries
12946required by your program for a core file or after typing @code{run}. If
12947@var{regex} is omitted all shared libraries required by your program are
12948loaded.
c45da7e6
EZ
12949
12950@item nosharedlibrary
12951@kindex nosharedlibrary
12952@cindex unload symbols from shared libraries
12953Unload all shared object library symbols. This discards all symbols
12954that have been loaded from all shared libraries. Symbols from shared
12955libraries that were loaded by explicit user requests are not
12956discarded.
c906108c
SS
12957@end table
12958
721c2651
EZ
12959Sometimes you may wish that @value{GDBN} stops and gives you control
12960when any of shared library events happen. Use the @code{set
12961stop-on-solib-events} command for this:
12962
12963@table @code
12964@item set stop-on-solib-events
12965@kindex set stop-on-solib-events
12966This command controls whether @value{GDBN} should give you control
12967when the dynamic linker notifies it about some shared library event.
12968The most common event of interest is loading or unloading of a new
12969shared library.
12970
12971@item show stop-on-solib-events
12972@kindex show stop-on-solib-events
12973Show whether @value{GDBN} stops and gives you control when shared
12974library events happen.
12975@end table
12976
f5ebfba0 12977Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
12978configurations. @value{GDBN} needs to have access to the target's libraries;
12979this can be accomplished either by providing copies of the libraries
12980on the host system, or by asking @value{GDBN} to automatically retrieve the
12981libraries from the target. If copies of the target libraries are
12982provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
12983copies on the target can be stripped as long as the copies on the host are
12984not.
12985
59b7b46f
EZ
12986@cindex where to look for shared libraries
12987For remote debugging, you need to tell @value{GDBN} where the target
12988libraries are, so that it can load the correct copies---otherwise, it
12989may try to load the host's libraries. @value{GDBN} has two variables
12990to specify the search directories for target libraries.
f5ebfba0
DJ
12991
12992@table @code
59b7b46f 12993@cindex prefix for shared library file names
f822c95b 12994@cindex system root, alternate
f5ebfba0 12995@kindex set solib-absolute-prefix
f822c95b
DJ
12996@kindex set sysroot
12997@item set sysroot @var{path}
12998Use @var{path} as the system root for the program being debugged. Any
12999absolute shared library paths will be prefixed with @var{path}; many
13000runtime loaders store the absolute paths to the shared library in the
13001target program's memory. If you use @code{set sysroot} to find shared
13002libraries, they need to be laid out in the same way that they are on
13003the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
13004under @var{path}.
13005
f1838a98
UW
13006If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
13007retrieve the target libraries from the remote system. This is only
13008supported when using a remote target that supports the @code{remote get}
13009command (@pxref{File Transfer,,Sending files to a remote system}).
13010The part of @var{path} following the initial @file{remote:}
13011(if present) is used as system root prefix on the remote file system.
13012@footnote{If you want to specify a local system root using a directory
13013that happens to be named @file{remote:}, you need to use some equivalent
13014variant of the name like @file{./remote:}.}
13015
f822c95b
DJ
13016The @code{set solib-absolute-prefix} command is an alias for @code{set
13017sysroot}.
13018
13019@cindex default system root
59b7b46f 13020@cindex @samp{--with-sysroot}
f822c95b
DJ
13021You can set the default system root by using the configure-time
13022@samp{--with-sysroot} option. If the system root is inside
13023@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
13024@samp{--exec-prefix}), then the default system root will be updated
13025automatically if the installed @value{GDBN} is moved to a new
13026location.
13027
13028@kindex show sysroot
13029@item show sysroot
f5ebfba0
DJ
13030Display the current shared library prefix.
13031
13032@kindex set solib-search-path
13033@item set solib-search-path @var{path}
f822c95b
DJ
13034If this variable is set, @var{path} is a colon-separated list of
13035directories to search for shared libraries. @samp{solib-search-path}
13036is used after @samp{sysroot} fails to locate the library, or if the
13037path to the library is relative instead of absolute. If you want to
13038use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 13039@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 13040finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 13041it to a nonexistent directory may interfere with automatic loading
f822c95b 13042of shared library symbols.
f5ebfba0
DJ
13043
13044@kindex show solib-search-path
13045@item show solib-search-path
13046Display the current shared library search path.
13047@end table
13048
5b5d99cf
JB
13049
13050@node Separate Debug Files
13051@section Debugging Information in Separate Files
13052@cindex separate debugging information files
13053@cindex debugging information in separate files
13054@cindex @file{.debug} subdirectories
13055@cindex debugging information directory, global
13056@cindex global debugging information directory
c7e83d54
EZ
13057@cindex build ID, and separate debugging files
13058@cindex @file{.build-id} directory
5b5d99cf
JB
13059
13060@value{GDBN} allows you to put a program's debugging information in a
13061file separate from the executable itself, in a way that allows
13062@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
13063Since debugging information can be very large---sometimes larger
13064than the executable code itself---some systems distribute debugging
5b5d99cf
JB
13065information for their executables in separate files, which users can
13066install only when they need to debug a problem.
13067
c7e83d54
EZ
13068@value{GDBN} supports two ways of specifying the separate debug info
13069file:
5b5d99cf
JB
13070
13071@itemize @bullet
13072@item
c7e83d54
EZ
13073The executable contains a @dfn{debug link} that specifies the name of
13074the separate debug info file. The separate debug file's name is
13075usually @file{@var{executable}.debug}, where @var{executable} is the
13076name of the corresponding executable file without leading directories
13077(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
13078debug link specifies a CRC32 checksum for the debug file, which
13079@value{GDBN} uses to validate that the executable and the debug file
13080came from the same build.
13081
13082@item
7e27a47a 13083The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 13084also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
13085only on some operating systems, notably those which use the ELF format
13086for binary files and the @sc{gnu} Binutils.) For more details about
13087this feature, see the description of the @option{--build-id}
13088command-line option in @ref{Options, , Command Line Options, ld.info,
13089The GNU Linker}. The debug info file's name is not specified
13090explicitly by the build ID, but can be computed from the build ID, see
13091below.
d3750b24
JK
13092@end itemize
13093
c7e83d54
EZ
13094Depending on the way the debug info file is specified, @value{GDBN}
13095uses two different methods of looking for the debug file:
d3750b24
JK
13096
13097@itemize @bullet
13098@item
c7e83d54
EZ
13099For the ``debug link'' method, @value{GDBN} looks up the named file in
13100the directory of the executable file, then in a subdirectory of that
13101directory named @file{.debug}, and finally under the global debug
13102directory, in a subdirectory whose name is identical to the leading
13103directories of the executable's absolute file name.
13104
13105@item
83f83d7f 13106For the ``build ID'' method, @value{GDBN} looks in the
c7e83d54
EZ
13107@file{.build-id} subdirectory of the global debug directory for a file
13108named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
13109first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
13110are the rest of the bit string. (Real build ID strings are 32 or more
13111hex characters, not 10.)
c7e83d54
EZ
13112@end itemize
13113
13114So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
13115@file{/usr/bin/ls}, which has a debug link that specifies the
13116file @file{ls.debug}, and a build ID whose value in hex is
c7e83d54
EZ
13117@code{abcdef1234}. If the global debug directory is
13118@file{/usr/lib/debug}, then @value{GDBN} will look for the following
13119debug information files, in the indicated order:
13120
13121@itemize @minus
13122@item
13123@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 13124@item
c7e83d54 13125@file{/usr/bin/ls.debug}
5b5d99cf 13126@item
c7e83d54 13127@file{/usr/bin/.debug/ls.debug}
5b5d99cf 13128@item
c7e83d54 13129@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 13130@end itemize
5b5d99cf
JB
13131
13132You can set the global debugging info directory's name, and view the
13133name @value{GDBN} is currently using.
13134
13135@table @code
13136
13137@kindex set debug-file-directory
13138@item set debug-file-directory @var{directory}
13139Set the directory which @value{GDBN} searches for separate debugging
13140information files to @var{directory}.
13141
13142@kindex show debug-file-directory
13143@item show debug-file-directory
13144Show the directory @value{GDBN} searches for separate debugging
13145information files.
13146
13147@end table
13148
13149@cindex @code{.gnu_debuglink} sections
c7e83d54 13150@cindex debug link sections
5b5d99cf
JB
13151A debug link is a special section of the executable file named
13152@code{.gnu_debuglink}. The section must contain:
13153
13154@itemize
13155@item
13156A filename, with any leading directory components removed, followed by
13157a zero byte,
13158@item
13159zero to three bytes of padding, as needed to reach the next four-byte
13160boundary within the section, and
13161@item
13162a four-byte CRC checksum, stored in the same endianness used for the
13163executable file itself. The checksum is computed on the debugging
13164information file's full contents by the function given below, passing
13165zero as the @var{crc} argument.
13166@end itemize
13167
13168Any executable file format can carry a debug link, as long as it can
13169contain a section named @code{.gnu_debuglink} with the contents
13170described above.
13171
d3750b24 13172@cindex @code{.note.gnu.build-id} sections
c7e83d54 13173@cindex build ID sections
7e27a47a
EZ
13174The build ID is a special section in the executable file (and in other
13175ELF binary files that @value{GDBN} may consider). This section is
13176often named @code{.note.gnu.build-id}, but that name is not mandatory.
13177It contains unique identification for the built files---the ID remains
13178the same across multiple builds of the same build tree. The default
13179algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
13180content for the build ID string. The same section with an identical
13181value is present in the original built binary with symbols, in its
13182stripped variant, and in the separate debugging information file.
d3750b24 13183
5b5d99cf
JB
13184The debugging information file itself should be an ordinary
13185executable, containing a full set of linker symbols, sections, and
13186debugging information. The sections of the debugging information file
c7e83d54
EZ
13187should have the same names, addresses, and sizes as the original file,
13188but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
13189in an ordinary executable.
13190
7e27a47a 13191The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
13192@samp{objcopy} utility that can produce
13193the separated executable / debugging information file pairs using the
13194following commands:
13195
13196@smallexample
13197@kbd{objcopy --only-keep-debug foo foo.debug}
13198@kbd{strip -g foo}
c7e83d54
EZ
13199@end smallexample
13200
13201@noindent
13202These commands remove the debugging
83f83d7f
JK
13203information from the executable file @file{foo} and place it in the file
13204@file{foo.debug}. You can use the first, second or both methods to link the
13205two files:
13206
13207@itemize @bullet
13208@item
13209The debug link method needs the following additional command to also leave
13210behind a debug link in @file{foo}:
13211
13212@smallexample
13213@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
13214@end smallexample
13215
13216Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 13217a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
13218foo.debug} has the same functionality as the two @code{objcopy} commands and
13219the @code{ln -s} command above, together.
13220
13221@item
13222Build ID gets embedded into the main executable using @code{ld --build-id} or
13223the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
13224compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 13225utilities (Binutils) package since version 2.18.
83f83d7f
JK
13226@end itemize
13227
13228@noindent
d3750b24 13229
c7e83d54
EZ
13230Since there are many different ways to compute CRC's for the debug
13231link (different polynomials, reversals, byte ordering, etc.), the
13232simplest way to describe the CRC used in @code{.gnu_debuglink}
13233sections is to give the complete code for a function that computes it:
5b5d99cf 13234
4644b6e3 13235@kindex gnu_debuglink_crc32
5b5d99cf
JB
13236@smallexample
13237unsigned long
13238gnu_debuglink_crc32 (unsigned long crc,
13239 unsigned char *buf, size_t len)
13240@{
13241 static const unsigned long crc32_table[256] =
13242 @{
13243 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
13244 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
13245 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
13246 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
13247 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
13248 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
13249 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
13250 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
13251 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
13252 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
13253 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
13254 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
13255 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
13256 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
13257 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
13258 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
13259 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
13260 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
13261 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
13262 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
13263 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
13264 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
13265 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
13266 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
13267 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
13268 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
13269 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
13270 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
13271 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
13272 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
13273 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
13274 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
13275 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
13276 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
13277 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
13278 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
13279 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
13280 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
13281 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
13282 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
13283 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
13284 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
13285 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
13286 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
13287 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
13288 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
13289 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
13290 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
13291 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
13292 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
13293 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
13294 0x2d02ef8d
13295 @};
13296 unsigned char *end;
13297
13298 crc = ~crc & 0xffffffff;
13299 for (end = buf + len; buf < end; ++buf)
13300 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 13301 return ~crc & 0xffffffff;
5b5d99cf
JB
13302@}
13303@end smallexample
13304
c7e83d54
EZ
13305@noindent
13306This computation does not apply to the ``build ID'' method.
13307
5b5d99cf 13308
6d2ebf8b 13309@node Symbol Errors
79a6e687 13310@section Errors Reading Symbol Files
c906108c
SS
13311
13312While reading a symbol file, @value{GDBN} occasionally encounters problems,
13313such as symbol types it does not recognize, or known bugs in compiler
13314output. By default, @value{GDBN} does not notify you of such problems, since
13315they are relatively common and primarily of interest to people
13316debugging compilers. If you are interested in seeing information
13317about ill-constructed symbol tables, you can either ask @value{GDBN} to print
13318only one message about each such type of problem, no matter how many
13319times the problem occurs; or you can ask @value{GDBN} to print more messages,
13320to see how many times the problems occur, with the @code{set
79a6e687
BW
13321complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
13322Messages}).
c906108c
SS
13323
13324The messages currently printed, and their meanings, include:
13325
13326@table @code
13327@item inner block not inside outer block in @var{symbol}
13328
13329The symbol information shows where symbol scopes begin and end
13330(such as at the start of a function or a block of statements). This
13331error indicates that an inner scope block is not fully contained
13332in its outer scope blocks.
13333
13334@value{GDBN} circumvents the problem by treating the inner block as if it had
13335the same scope as the outer block. In the error message, @var{symbol}
13336may be shown as ``@code{(don't know)}'' if the outer block is not a
13337function.
13338
13339@item block at @var{address} out of order
13340
13341The symbol information for symbol scope blocks should occur in
13342order of increasing addresses. This error indicates that it does not
13343do so.
13344
13345@value{GDBN} does not circumvent this problem, and has trouble
13346locating symbols in the source file whose symbols it is reading. (You
13347can often determine what source file is affected by specifying
79a6e687
BW
13348@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
13349Messages}.)
c906108c
SS
13350
13351@item bad block start address patched
13352
13353The symbol information for a symbol scope block has a start address
13354smaller than the address of the preceding source line. This is known
13355to occur in the SunOS 4.1.1 (and earlier) C compiler.
13356
13357@value{GDBN} circumvents the problem by treating the symbol scope block as
13358starting on the previous source line.
13359
13360@item bad string table offset in symbol @var{n}
13361
13362@cindex foo
13363Symbol number @var{n} contains a pointer into the string table which is
13364larger than the size of the string table.
13365
13366@value{GDBN} circumvents the problem by considering the symbol to have the
13367name @code{foo}, which may cause other problems if many symbols end up
13368with this name.
13369
13370@item unknown symbol type @code{0x@var{nn}}
13371
7a292a7a
SS
13372The symbol information contains new data types that @value{GDBN} does
13373not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 13374uncomprehended information, in hexadecimal.
c906108c 13375
7a292a7a
SS
13376@value{GDBN} circumvents the error by ignoring this symbol information.
13377This usually allows you to debug your program, though certain symbols
c906108c 13378are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
13379debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
13380on @code{complain}, then go up to the function @code{read_dbx_symtab}
13381and examine @code{*bufp} to see the symbol.
c906108c
SS
13382
13383@item stub type has NULL name
c906108c 13384
7a292a7a 13385@value{GDBN} could not find the full definition for a struct or class.
c906108c 13386
7a292a7a 13387@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 13388The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
13389information that recent versions of the compiler should have output for
13390it.
c906108c
SS
13391
13392@item info mismatch between compiler and debugger
13393
13394@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 13395
c906108c
SS
13396@end table
13397
6d2ebf8b 13398@node Targets
c906108c 13399@chapter Specifying a Debugging Target
7a292a7a 13400
c906108c 13401@cindex debugging target
c906108c 13402A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
13403
13404Often, @value{GDBN} runs in the same host environment as your program;
13405in that case, the debugging target is specified as a side effect when
13406you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
13407flexibility---for example, running @value{GDBN} on a physically separate
13408host, or controlling a standalone system over a serial port or a
53a5351d
JM
13409realtime system over a TCP/IP connection---you can use the @code{target}
13410command to specify one of the target types configured for @value{GDBN}
79a6e687 13411(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 13412
a8f24a35
EZ
13413@cindex target architecture
13414It is possible to build @value{GDBN} for several different @dfn{target
13415architectures}. When @value{GDBN} is built like that, you can choose
13416one of the available architectures with the @kbd{set architecture}
13417command.
13418
13419@table @code
13420@kindex set architecture
13421@kindex show architecture
13422@item set architecture @var{arch}
13423This command sets the current target architecture to @var{arch}. The
13424value of @var{arch} can be @code{"auto"}, in addition to one of the
13425supported architectures.
13426
13427@item show architecture
13428Show the current target architecture.
9c16f35a
EZ
13429
13430@item set processor
13431@itemx processor
13432@kindex set processor
13433@kindex show processor
13434These are alias commands for, respectively, @code{set architecture}
13435and @code{show architecture}.
a8f24a35
EZ
13436@end table
13437
c906108c
SS
13438@menu
13439* Active Targets:: Active targets
13440* Target Commands:: Commands for managing targets
c906108c 13441* Byte Order:: Choosing target byte order
c906108c
SS
13442@end menu
13443
6d2ebf8b 13444@node Active Targets
79a6e687 13445@section Active Targets
7a292a7a 13446
c906108c
SS
13447@cindex stacking targets
13448@cindex active targets
13449@cindex multiple targets
13450
c906108c 13451There are three classes of targets: processes, core files, and
7a292a7a
SS
13452executable files. @value{GDBN} can work concurrently on up to three
13453active targets, one in each class. This allows you to (for example)
13454start a process and inspect its activity without abandoning your work on
13455a core file.
c906108c
SS
13456
13457For example, if you execute @samp{gdb a.out}, then the executable file
13458@code{a.out} is the only active target. If you designate a core file as
13459well---presumably from a prior run that crashed and coredumped---then
13460@value{GDBN} has two active targets and uses them in tandem, looking
13461first in the corefile target, then in the executable file, to satisfy
13462requests for memory addresses. (Typically, these two classes of target
13463are complementary, since core files contain only a program's
13464read-write memory---variables and so on---plus machine status, while
13465executable files contain only the program text and initialized data.)
c906108c
SS
13466
13467When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
13468target as well. When a process target is active, all @value{GDBN}
13469commands requesting memory addresses refer to that target; addresses in
13470an active core file or executable file target are obscured while the
13471process target is active.
c906108c 13472
7a292a7a 13473Use the @code{core-file} and @code{exec-file} commands to select a new
79a6e687
BW
13474core file or executable target (@pxref{Files, ,Commands to Specify
13475Files}). To specify as a target a process that is already running, use
13476the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
13477Process}).
c906108c 13478
6d2ebf8b 13479@node Target Commands
79a6e687 13480@section Commands for Managing Targets
c906108c
SS
13481
13482@table @code
13483@item target @var{type} @var{parameters}
7a292a7a
SS
13484Connects the @value{GDBN} host environment to a target machine or
13485process. A target is typically a protocol for talking to debugging
13486facilities. You use the argument @var{type} to specify the type or
13487protocol of the target machine.
c906108c
SS
13488
13489Further @var{parameters} are interpreted by the target protocol, but
13490typically include things like device names or host names to connect
13491with, process numbers, and baud rates.
c906108c
SS
13492
13493The @code{target} command does not repeat if you press @key{RET} again
13494after executing the command.
13495
13496@kindex help target
13497@item help target
13498Displays the names of all targets available. To display targets
13499currently selected, use either @code{info target} or @code{info files}
79a6e687 13500(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
13501
13502@item help target @var{name}
13503Describe a particular target, including any parameters necessary to
13504select it.
13505
13506@kindex set gnutarget
13507@item set gnutarget @var{args}
5d161b24 13508@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 13509knows whether it is reading an @dfn{executable},
5d161b24
DB
13510a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
13511with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
13512with @code{gnutarget} the @code{target} refers to a program, not a machine.
13513
d4f3574e 13514@quotation
c906108c
SS
13515@emph{Warning:} To specify a file format with @code{set gnutarget},
13516you must know the actual BFD name.
d4f3574e 13517@end quotation
c906108c 13518
d4f3574e 13519@noindent
79a6e687 13520@xref{Files, , Commands to Specify Files}.
c906108c 13521
5d161b24 13522@kindex show gnutarget
c906108c
SS
13523@item show gnutarget
13524Use the @code{show gnutarget} command to display what file format
13525@code{gnutarget} is set to read. If you have not set @code{gnutarget},
13526@value{GDBN} will determine the file format for each file automatically,
13527and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
13528@end table
13529
4644b6e3 13530@cindex common targets
c906108c
SS
13531Here are some common targets (available, or not, depending on the GDB
13532configuration):
c906108c
SS
13533
13534@table @code
4644b6e3 13535@kindex target
c906108c 13536@item target exec @var{program}
4644b6e3 13537@cindex executable file target
c906108c
SS
13538An executable file. @samp{target exec @var{program}} is the same as
13539@samp{exec-file @var{program}}.
13540
c906108c 13541@item target core @var{filename}
4644b6e3 13542@cindex core dump file target
c906108c
SS
13543A core dump file. @samp{target core @var{filename}} is the same as
13544@samp{core-file @var{filename}}.
c906108c 13545
1a10341b 13546@item target remote @var{medium}
4644b6e3 13547@cindex remote target
1a10341b
JB
13548A remote system connected to @value{GDBN} via a serial line or network
13549connection. This command tells @value{GDBN} to use its own remote
13550protocol over @var{medium} for debugging. @xref{Remote Debugging}.
13551
13552For example, if you have a board connected to @file{/dev/ttya} on the
13553machine running @value{GDBN}, you could say:
13554
13555@smallexample
13556target remote /dev/ttya
13557@end smallexample
13558
13559@code{target remote} supports the @code{load} command. This is only
13560useful if you have some other way of getting the stub to the target
13561system, and you can put it somewhere in memory where it won't get
13562clobbered by the download.
c906108c 13563
c906108c 13564@item target sim
4644b6e3 13565@cindex built-in simulator target
2df3850c 13566Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 13567In general,
474c8240 13568@smallexample
104c1213
JM
13569 target sim
13570 load
13571 run
474c8240 13572@end smallexample
d4f3574e 13573@noindent
104c1213 13574works; however, you cannot assume that a specific memory map, device
d4f3574e 13575drivers, or even basic I/O is available, although some simulators do
104c1213
JM
13576provide these. For info about any processor-specific simulator details,
13577see the appropriate section in @ref{Embedded Processors, ,Embedded
13578Processors}.
13579
c906108c
SS
13580@end table
13581
104c1213 13582Some configurations may include these targets as well:
c906108c
SS
13583
13584@table @code
13585
c906108c 13586@item target nrom @var{dev}
4644b6e3 13587@cindex NetROM ROM emulator target
c906108c
SS
13588NetROM ROM emulator. This target only supports downloading.
13589
c906108c
SS
13590@end table
13591
5d161b24 13592Different targets are available on different configurations of @value{GDBN};
c906108c 13593your configuration may have more or fewer targets.
c906108c 13594
721c2651
EZ
13595Many remote targets require you to download the executable's code once
13596you've successfully established a connection. You may wish to control
3d00d119
DJ
13597various aspects of this process.
13598
13599@table @code
721c2651
EZ
13600
13601@item set hash
13602@kindex set hash@r{, for remote monitors}
13603@cindex hash mark while downloading
13604This command controls whether a hash mark @samp{#} is displayed while
13605downloading a file to the remote monitor. If on, a hash mark is
13606displayed after each S-record is successfully downloaded to the
13607monitor.
13608
13609@item show hash
13610@kindex show hash@r{, for remote monitors}
13611Show the current status of displaying the hash mark.
13612
13613@item set debug monitor
13614@kindex set debug monitor
13615@cindex display remote monitor communications
13616Enable or disable display of communications messages between
13617@value{GDBN} and the remote monitor.
13618
13619@item show debug monitor
13620@kindex show debug monitor
13621Show the current status of displaying communications between
13622@value{GDBN} and the remote monitor.
a8f24a35 13623@end table
c906108c
SS
13624
13625@table @code
13626
13627@kindex load @var{filename}
13628@item load @var{filename}
8edfe269 13629@anchor{load}
c906108c
SS
13630Depending on what remote debugging facilities are configured into
13631@value{GDBN}, the @code{load} command may be available. Where it exists, it
13632is meant to make @var{filename} (an executable) available for debugging
13633on the remote system---by downloading, or dynamic linking, for example.
13634@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
13635the @code{add-symbol-file} command.
13636
13637If your @value{GDBN} does not have a @code{load} command, attempting to
13638execute it gets the error message ``@code{You can't do that when your
13639target is @dots{}}''
c906108c
SS
13640
13641The file is loaded at whatever address is specified in the executable.
13642For some object file formats, you can specify the load address when you
13643link the program; for other formats, like a.out, the object file format
13644specifies a fixed address.
13645@c FIXME! This would be a good place for an xref to the GNU linker doc.
13646
68437a39
DJ
13647Depending on the remote side capabilities, @value{GDBN} may be able to
13648load programs into flash memory.
13649
c906108c
SS
13650@code{load} does not repeat if you press @key{RET} again after using it.
13651@end table
13652
6d2ebf8b 13653@node Byte Order
79a6e687 13654@section Choosing Target Byte Order
7a292a7a 13655
c906108c
SS
13656@cindex choosing target byte order
13657@cindex target byte order
c906108c 13658
172c2a43 13659Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
13660offer the ability to run either big-endian or little-endian byte
13661orders. Usually the executable or symbol will include a bit to
13662designate the endian-ness, and you will not need to worry about
13663which to use. However, you may still find it useful to adjust
d4f3574e 13664@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
13665
13666@table @code
4644b6e3 13667@kindex set endian
c906108c
SS
13668@item set endian big
13669Instruct @value{GDBN} to assume the target is big-endian.
13670
c906108c
SS
13671@item set endian little
13672Instruct @value{GDBN} to assume the target is little-endian.
13673
c906108c
SS
13674@item set endian auto
13675Instruct @value{GDBN} to use the byte order associated with the
13676executable.
13677
13678@item show endian
13679Display @value{GDBN}'s current idea of the target byte order.
13680
13681@end table
13682
13683Note that these commands merely adjust interpretation of symbolic
13684data on the host, and that they have absolutely no effect on the
13685target system.
13686
ea35711c
DJ
13687
13688@node Remote Debugging
13689@chapter Debugging Remote Programs
c906108c
SS
13690@cindex remote debugging
13691
13692If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
13693@value{GDBN} in the usual way, it is often useful to use remote debugging.
13694For example, you might use remote debugging on an operating system kernel,
c906108c
SS
13695or on a small system which does not have a general purpose operating system
13696powerful enough to run a full-featured debugger.
13697
13698Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
13699to make this work with particular debugging targets. In addition,
5d161b24 13700@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
13701but not specific to any particular target system) which you can use if you
13702write the remote stubs---the code that runs on the remote system to
13703communicate with @value{GDBN}.
13704
13705Other remote targets may be available in your
13706configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 13707
6b2f586d 13708@menu
07f31aa6 13709* Connecting:: Connecting to a remote target
a6b151f1 13710* File Transfer:: Sending files to a remote system
6b2f586d 13711* Server:: Using the gdbserver program
79a6e687
BW
13712* Remote Configuration:: Remote configuration
13713* Remote Stub:: Implementing a remote stub
6b2f586d
AC
13714@end menu
13715
07f31aa6 13716@node Connecting
79a6e687 13717@section Connecting to a Remote Target
07f31aa6
DJ
13718
13719On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 13720your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
13721Start up @value{GDBN} as usual, using the name of the local copy of your
13722program as the first argument.
13723
86941c27
JB
13724@cindex @code{target remote}
13725@value{GDBN} can communicate with the target over a serial line, or
13726over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
13727each case, @value{GDBN} uses the same protocol for debugging your
13728program; only the medium carrying the debugging packets varies. The
13729@code{target remote} command establishes a connection to the target.
13730Its arguments indicate which medium to use:
13731
13732@table @code
13733
13734@item target remote @var{serial-device}
07f31aa6 13735@cindex serial line, @code{target remote}
86941c27
JB
13736Use @var{serial-device} to communicate with the target. For example,
13737to use a serial line connected to the device named @file{/dev/ttyb}:
13738
13739@smallexample
13740target remote /dev/ttyb
13741@end smallexample
13742
07f31aa6
DJ
13743If you're using a serial line, you may want to give @value{GDBN} the
13744@w{@samp{--baud}} option, or use the @code{set remotebaud} command
79a6e687 13745(@pxref{Remote Configuration, set remotebaud}) before the
9c16f35a 13746@code{target} command.
07f31aa6 13747
86941c27
JB
13748@item target remote @code{@var{host}:@var{port}}
13749@itemx target remote @code{tcp:@var{host}:@var{port}}
13750@cindex @acronym{TCP} port, @code{target remote}
13751Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
13752The @var{host} may be either a host name or a numeric @acronym{IP}
13753address; @var{port} must be a decimal number. The @var{host} could be
13754the target machine itself, if it is directly connected to the net, or
13755it might be a terminal server which in turn has a serial line to the
13756target.
07f31aa6 13757
86941c27
JB
13758For example, to connect to port 2828 on a terminal server named
13759@code{manyfarms}:
07f31aa6
DJ
13760
13761@smallexample
13762target remote manyfarms:2828
13763@end smallexample
13764
86941c27
JB
13765If your remote target is actually running on the same machine as your
13766debugger session (e.g.@: a simulator for your target running on the
13767same host), you can omit the hostname. For example, to connect to
13768port 1234 on your local machine:
07f31aa6
DJ
13769
13770@smallexample
13771target remote :1234
13772@end smallexample
13773@noindent
13774
13775Note that the colon is still required here.
13776
86941c27
JB
13777@item target remote @code{udp:@var{host}:@var{port}}
13778@cindex @acronym{UDP} port, @code{target remote}
13779Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
13780connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
13781
13782@smallexample
13783target remote udp:manyfarms:2828
13784@end smallexample
13785
86941c27
JB
13786When using a @acronym{UDP} connection for remote debugging, you should
13787keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
13788can silently drop packets on busy or unreliable networks, which will
13789cause havoc with your debugging session.
13790
66b8c7f6
JB
13791@item target remote | @var{command}
13792@cindex pipe, @code{target remote} to
13793Run @var{command} in the background and communicate with it using a
13794pipe. The @var{command} is a shell command, to be parsed and expanded
13795by the system's command shell, @code{/bin/sh}; it should expect remote
13796protocol packets on its standard input, and send replies on its
13797standard output. You could use this to run a stand-alone simulator
13798that speaks the remote debugging protocol, to make net connections
13799using programs like @code{ssh}, or for other similar tricks.
13800
13801If @var{command} closes its standard output (perhaps by exiting),
13802@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
13803program has already exited, this will have no effect.)
13804
86941c27 13805@end table
07f31aa6 13806
86941c27 13807Once the connection has been established, you can use all the usual
8edfe269
DJ
13808commands to examine and change data. The remote program is already
13809running; you can use @kbd{step} and @kbd{continue}, and you do not
13810need to use @kbd{run}.
07f31aa6
DJ
13811
13812@cindex interrupting remote programs
13813@cindex remote programs, interrupting
13814Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 13815interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
13816program. This may or may not succeed, depending in part on the hardware
13817and the serial drivers the remote system uses. If you type the
13818interrupt character once again, @value{GDBN} displays this prompt:
13819
13820@smallexample
13821Interrupted while waiting for the program.
13822Give up (and stop debugging it)? (y or n)
13823@end smallexample
13824
13825If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
13826(If you decide you want to try again later, you can use @samp{target
13827remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
13828goes back to waiting.
13829
13830@table @code
13831@kindex detach (remote)
13832@item detach
13833When you have finished debugging the remote program, you can use the
13834@code{detach} command to release it from @value{GDBN} control.
13835Detaching from the target normally resumes its execution, but the results
13836will depend on your particular remote stub. After the @code{detach}
13837command, @value{GDBN} is free to connect to another target.
13838
13839@kindex disconnect
13840@item disconnect
13841The @code{disconnect} command behaves like @code{detach}, except that
13842the target is generally not resumed. It will wait for @value{GDBN}
13843(this instance or another one) to connect and continue debugging. After
13844the @code{disconnect} command, @value{GDBN} is again free to connect to
13845another target.
09d4efe1
EZ
13846
13847@cindex send command to remote monitor
fad38dfa
EZ
13848@cindex extend @value{GDBN} for remote targets
13849@cindex add new commands for external monitor
09d4efe1
EZ
13850@kindex monitor
13851@item monitor @var{cmd}
fad38dfa
EZ
13852This command allows you to send arbitrary commands directly to the
13853remote monitor. Since @value{GDBN} doesn't care about the commands it
13854sends like this, this command is the way to extend @value{GDBN}---you
13855can add new commands that only the external monitor will understand
13856and implement.
07f31aa6
DJ
13857@end table
13858
a6b151f1
DJ
13859@node File Transfer
13860@section Sending files to a remote system
13861@cindex remote target, file transfer
13862@cindex file transfer
13863@cindex sending files to remote systems
13864
13865Some remote targets offer the ability to transfer files over the same
13866connection used to communicate with @value{GDBN}. This is convenient
13867for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
13868running @code{gdbserver} over a network interface. For other targets,
13869e.g.@: embedded devices with only a single serial port, this may be
13870the only way to upload or download files.
13871
13872Not all remote targets support these commands.
13873
13874@table @code
13875@kindex remote put
13876@item remote put @var{hostfile} @var{targetfile}
13877Copy file @var{hostfile} from the host system (the machine running
13878@value{GDBN}) to @var{targetfile} on the target system.
13879
13880@kindex remote get
13881@item remote get @var{targetfile} @var{hostfile}
13882Copy file @var{targetfile} from the target system to @var{hostfile}
13883on the host system.
13884
13885@kindex remote delete
13886@item remote delete @var{targetfile}
13887Delete @var{targetfile} from the target system.
13888
13889@end table
13890
6f05cf9f 13891@node Server
79a6e687 13892@section Using the @code{gdbserver} Program
6f05cf9f
AC
13893
13894@kindex gdbserver
13895@cindex remote connection without stubs
13896@code{gdbserver} is a control program for Unix-like systems, which
13897allows you to connect your program with a remote @value{GDBN} via
13898@code{target remote}---but without linking in the usual debugging stub.
13899
13900@code{gdbserver} is not a complete replacement for the debugging stubs,
13901because it requires essentially the same operating-system facilities
13902that @value{GDBN} itself does. In fact, a system that can run
13903@code{gdbserver} to connect to a remote @value{GDBN} could also run
13904@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
13905because it is a much smaller program than @value{GDBN} itself. It is
13906also easier to port than all of @value{GDBN}, so you may be able to get
13907started more quickly on a new system by using @code{gdbserver}.
13908Finally, if you develop code for real-time systems, you may find that
13909the tradeoffs involved in real-time operation make it more convenient to
13910do as much development work as possible on another system, for example
13911by cross-compiling. You can use @code{gdbserver} to make a similar
13912choice for debugging.
13913
13914@value{GDBN} and @code{gdbserver} communicate via either a serial line
13915or a TCP connection, using the standard @value{GDBN} remote serial
13916protocol.
13917
2d717e4f
DJ
13918@quotation
13919@emph{Warning:} @code{gdbserver} does not have any built-in security.
13920Do not run @code{gdbserver} connected to any public network; a
13921@value{GDBN} connection to @code{gdbserver} provides access to the
13922target system with the same privileges as the user running
13923@code{gdbserver}.
13924@end quotation
13925
13926@subsection Running @code{gdbserver}
13927@cindex arguments, to @code{gdbserver}
13928
13929Run @code{gdbserver} on the target system. You need a copy of the
13930program you want to debug, including any libraries it requires.
6f05cf9f
AC
13931@code{gdbserver} does not need your program's symbol table, so you can
13932strip the program if necessary to save space. @value{GDBN} on the host
13933system does all the symbol handling.
13934
13935To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 13936the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
13937syntax is:
13938
13939@smallexample
13940target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
13941@end smallexample
13942
13943@var{comm} is either a device name (to use a serial line) or a TCP
13944hostname and portnumber. For example, to debug Emacs with the argument
13945@samp{foo.txt} and communicate with @value{GDBN} over the serial port
13946@file{/dev/com1}:
13947
13948@smallexample
13949target> gdbserver /dev/com1 emacs foo.txt
13950@end smallexample
13951
13952@code{gdbserver} waits passively for the host @value{GDBN} to communicate
13953with it.
13954
13955To use a TCP connection instead of a serial line:
13956
13957@smallexample
13958target> gdbserver host:2345 emacs foo.txt
13959@end smallexample
13960
13961The only difference from the previous example is the first argument,
13962specifying that you are communicating with the host @value{GDBN} via
13963TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
13964expect a TCP connection from machine @samp{host} to local TCP port 2345.
13965(Currently, the @samp{host} part is ignored.) You can choose any number
13966you want for the port number as long as it does not conflict with any
13967TCP ports already in use on the target system (for example, @code{23} is
13968reserved for @code{telnet}).@footnote{If you choose a port number that
13969conflicts with another service, @code{gdbserver} prints an error message
13970and exits.} You must use the same port number with the host @value{GDBN}
13971@code{target remote} command.
13972
2d717e4f
DJ
13973@subsubsection Attaching to a Running Program
13974
56460a61
DJ
13975On some targets, @code{gdbserver} can also attach to running programs.
13976This is accomplished via the @code{--attach} argument. The syntax is:
13977
13978@smallexample
2d717e4f 13979target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
13980@end smallexample
13981
13982@var{pid} is the process ID of a currently running process. It isn't necessary
13983to point @code{gdbserver} at a binary for the running process.
13984
b1fe9455
DJ
13985@pindex pidof
13986@cindex attach to a program by name
13987You can debug processes by name instead of process ID if your target has the
13988@code{pidof} utility:
13989
13990@smallexample
2d717e4f 13991target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
13992@end smallexample
13993
f822c95b 13994In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
13995has multiple threads, most versions of @code{pidof} support the
13996@code{-s} option to only return the first process ID.
13997
2d717e4f
DJ
13998@subsubsection Multi-Process Mode for @code{gdbserver}
13999@cindex gdbserver, multiple processes
14000@cindex multiple processes with gdbserver
14001
14002When you connect to @code{gdbserver} using @code{target remote},
14003@code{gdbserver} debugs the specified program only once. When the
14004program exits, or you detach from it, @value{GDBN} closes the connection
14005and @code{gdbserver} exits.
14006
6e6c6f50 14007If you connect using @kbd{target extended-remote}, @code{gdbserver}
2d717e4f
DJ
14008enters multi-process mode. When the debugged program exits, or you
14009detach from it, @value{GDBN} stays connected to @code{gdbserver} even
14010though no program is running. The @code{run} and @code{attach}
14011commands instruct @code{gdbserver} to run or attach to a new program.
14012The @code{run} command uses @code{set remote exec-file} (@pxref{set
14013remote exec-file}) to select the program to run. Command line
14014arguments are supported, except for wildcard expansion and I/O
14015redirection (@pxref{Arguments}).
14016
14017To start @code{gdbserver} without supplying an initial command to run
14018or process ID to attach, use the @option{--multi} command line option.
6e6c6f50 14019Then you can connect using @kbd{target extended-remote} and start
2d717e4f
DJ
14020the program you want to debug.
14021
14022@code{gdbserver} does not automatically exit in multi-process mode.
14023You can terminate it by using @code{monitor exit}
14024(@pxref{Monitor Commands for gdbserver}).
14025
14026@subsubsection Other Command-Line Arguments for @code{gdbserver}
14027
14028You can include @option{--debug} on the @code{gdbserver} command line.
14029@code{gdbserver} will display extra status information about the debugging
14030process. This option is intended for @code{gdbserver} development and
14031for bug reports to the developers.
14032
ccd213ac
DJ
14033The @option{--wrapper} option specifies a wrapper to launch programs
14034for debugging. The option should be followed by the name of the
14035wrapper, then any command-line arguments to pass to the wrapper, then
14036@kbd{--} indicating the end of the wrapper arguments.
14037
14038@code{gdbserver} runs the specified wrapper program with a combined
14039command line including the wrapper arguments, then the name of the
14040program to debug, then any arguments to the program. The wrapper
14041runs until it executes your program, and then @value{GDBN} gains control.
14042
14043You can use any program that eventually calls @code{execve} with
14044its arguments as a wrapper. Several standard Unix utilities do
14045this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
14046with @code{exec "$@@"} will also work.
14047
14048For example, you can use @code{env} to pass an environment variable to
14049the debugged program, without setting the variable in @code{gdbserver}'s
14050environment:
14051
14052@smallexample
14053$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
14054@end smallexample
14055
2d717e4f
DJ
14056@subsection Connecting to @code{gdbserver}
14057
14058Run @value{GDBN} on the host system.
14059
14060First make sure you have the necessary symbol files. Load symbols for
f822c95b
DJ
14061your application using the @code{file} command before you connect. Use
14062@code{set sysroot} to locate target libraries (unless your @value{GDBN}
2d717e4f 14063was compiled with the correct sysroot using @code{--with-sysroot}).
f822c95b
DJ
14064
14065The symbol file and target libraries must exactly match the executable
14066and libraries on the target, with one exception: the files on the host
14067system should not be stripped, even if the files on the target system
14068are. Mismatched or missing files will lead to confusing results
14069during debugging. On @sc{gnu}/Linux targets, mismatched or missing
14070files may also prevent @code{gdbserver} from debugging multi-threaded
14071programs.
14072
79a6e687 14073Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
14074For TCP connections, you must start up @code{gdbserver} prior to using
14075the @code{target remote} command. Otherwise you may get an error whose
14076text depends on the host system, but which usually looks something like
2d717e4f 14077@samp{Connection refused}. Don't use the @code{load}
397ca115 14078command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 14079already on the target.
07f31aa6 14080
79a6e687 14081@subsection Monitor Commands for @code{gdbserver}
c74d0ad8 14082@cindex monitor commands, for @code{gdbserver}
2d717e4f 14083@anchor{Monitor Commands for gdbserver}
c74d0ad8
DJ
14084
14085During a @value{GDBN} session using @code{gdbserver}, you can use the
14086@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 14087Here are the available commands.
c74d0ad8
DJ
14088
14089@table @code
14090@item monitor help
14091List the available monitor commands.
14092
14093@item monitor set debug 0
14094@itemx monitor set debug 1
14095Disable or enable general debugging messages.
14096
14097@item monitor set remote-debug 0
14098@itemx monitor set remote-debug 1
14099Disable or enable specific debugging messages associated with the remote
14100protocol (@pxref{Remote Protocol}).
14101
2d717e4f
DJ
14102@item monitor exit
14103Tell gdbserver to exit immediately. This command should be followed by
14104@code{disconnect} to close the debugging session. @code{gdbserver} will
14105detach from any attached processes and kill any processes it created.
14106Use @code{monitor exit} to terminate @code{gdbserver} at the end
14107of a multi-process mode debug session.
14108
c74d0ad8
DJ
14109@end table
14110
79a6e687
BW
14111@node Remote Configuration
14112@section Remote Configuration
501eef12 14113
9c16f35a
EZ
14114@kindex set remote
14115@kindex show remote
14116This section documents the configuration options available when
14117debugging remote programs. For the options related to the File I/O
fc320d37 14118extensions of the remote protocol, see @ref{system,
9c16f35a 14119system-call-allowed}.
501eef12
AC
14120
14121@table @code
9c16f35a 14122@item set remoteaddresssize @var{bits}
d3e8051b 14123@cindex address size for remote targets
9c16f35a
EZ
14124@cindex bits in remote address
14125Set the maximum size of address in a memory packet to the specified
14126number of bits. @value{GDBN} will mask off the address bits above
14127that number, when it passes addresses to the remote target. The
14128default value is the number of bits in the target's address.
14129
14130@item show remoteaddresssize
14131Show the current value of remote address size in bits.
14132
14133@item set remotebaud @var{n}
14134@cindex baud rate for remote targets
14135Set the baud rate for the remote serial I/O to @var{n} baud. The
14136value is used to set the speed of the serial port used for debugging
14137remote targets.
14138
14139@item show remotebaud
14140Show the current speed of the remote connection.
14141
14142@item set remotebreak
14143@cindex interrupt remote programs
14144@cindex BREAK signal instead of Ctrl-C
9a6253be 14145@anchor{set remotebreak}
9c16f35a 14146If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 14147when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 14148on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
14149character instead. The default is off, since most remote systems
14150expect to see @samp{Ctrl-C} as the interrupt signal.
14151
14152@item show remotebreak
14153Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
14154interrupt the remote program.
14155
23776285
MR
14156@item set remoteflow on
14157@itemx set remoteflow off
14158@kindex set remoteflow
14159Enable or disable hardware flow control (@code{RTS}/@code{CTS})
14160on the serial port used to communicate to the remote target.
14161
14162@item show remoteflow
14163@kindex show remoteflow
14164Show the current setting of hardware flow control.
14165
9c16f35a
EZ
14166@item set remotelogbase @var{base}
14167Set the base (a.k.a.@: radix) of logging serial protocol
14168communications to @var{base}. Supported values of @var{base} are:
14169@code{ascii}, @code{octal}, and @code{hex}. The default is
14170@code{ascii}.
14171
14172@item show remotelogbase
14173Show the current setting of the radix for logging remote serial
14174protocol.
14175
14176@item set remotelogfile @var{file}
14177@cindex record serial communications on file
14178Record remote serial communications on the named @var{file}. The
14179default is not to record at all.
14180
14181@item show remotelogfile.
14182Show the current setting of the file name on which to record the
14183serial communications.
14184
14185@item set remotetimeout @var{num}
14186@cindex timeout for serial communications
14187@cindex remote timeout
14188Set the timeout limit to wait for the remote target to respond to
14189@var{num} seconds. The default is 2 seconds.
14190
14191@item show remotetimeout
14192Show the current number of seconds to wait for the remote target
14193responses.
14194
14195@cindex limit hardware breakpoints and watchpoints
14196@cindex remote target, limit break- and watchpoints
501eef12
AC
14197@anchor{set remote hardware-watchpoint-limit}
14198@anchor{set remote hardware-breakpoint-limit}
14199@item set remote hardware-watchpoint-limit @var{limit}
14200@itemx set remote hardware-breakpoint-limit @var{limit}
14201Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
14202watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f
DJ
14203
14204@item set remote exec-file @var{filename}
14205@itemx show remote exec-file
14206@anchor{set remote exec-file}
14207@cindex executable file, for remote target
14208Select the file used for @code{run} with @code{target
14209extended-remote}. This should be set to a filename valid on the
14210target system. If it is not set, the target will use a default
14211filename (e.g.@: the last program run).
501eef12
AC
14212@end table
14213
427c3a89
DJ
14214@cindex remote packets, enabling and disabling
14215The @value{GDBN} remote protocol autodetects the packets supported by
14216your debugging stub. If you need to override the autodetection, you
14217can use these commands to enable or disable individual packets. Each
14218packet can be set to @samp{on} (the remote target supports this
14219packet), @samp{off} (the remote target does not support this packet),
14220or @samp{auto} (detect remote target support for this packet). They
14221all default to @samp{auto}. For more information about each packet,
14222see @ref{Remote Protocol}.
14223
14224During normal use, you should not have to use any of these commands.
14225If you do, that may be a bug in your remote debugging stub, or a bug
14226in @value{GDBN}. You may want to report the problem to the
14227@value{GDBN} developers.
14228
cfa9d6d9
DJ
14229For each packet @var{name}, the command to enable or disable the
14230packet is @code{set remote @var{name}-packet}. The available settings
14231are:
427c3a89 14232
cfa9d6d9 14233@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
14234@item Command Name
14235@tab Remote Packet
14236@tab Related Features
14237
cfa9d6d9 14238@item @code{fetch-register}
427c3a89
DJ
14239@tab @code{p}
14240@tab @code{info registers}
14241
cfa9d6d9 14242@item @code{set-register}
427c3a89
DJ
14243@tab @code{P}
14244@tab @code{set}
14245
cfa9d6d9 14246@item @code{binary-download}
427c3a89
DJ
14247@tab @code{X}
14248@tab @code{load}, @code{set}
14249
cfa9d6d9 14250@item @code{read-aux-vector}
427c3a89
DJ
14251@tab @code{qXfer:auxv:read}
14252@tab @code{info auxv}
14253
cfa9d6d9 14254@item @code{symbol-lookup}
427c3a89
DJ
14255@tab @code{qSymbol}
14256@tab Detecting multiple threads
14257
2d717e4f
DJ
14258@item @code{attach}
14259@tab @code{vAttach}
14260@tab @code{attach}
14261
cfa9d6d9 14262@item @code{verbose-resume}
427c3a89
DJ
14263@tab @code{vCont}
14264@tab Stepping or resuming multiple threads
14265
2d717e4f
DJ
14266@item @code{run}
14267@tab @code{vRun}
14268@tab @code{run}
14269
cfa9d6d9 14270@item @code{software-breakpoint}
427c3a89
DJ
14271@tab @code{Z0}
14272@tab @code{break}
14273
cfa9d6d9 14274@item @code{hardware-breakpoint}
427c3a89
DJ
14275@tab @code{Z1}
14276@tab @code{hbreak}
14277
cfa9d6d9 14278@item @code{write-watchpoint}
427c3a89
DJ
14279@tab @code{Z2}
14280@tab @code{watch}
14281
cfa9d6d9 14282@item @code{read-watchpoint}
427c3a89
DJ
14283@tab @code{Z3}
14284@tab @code{rwatch}
14285
cfa9d6d9 14286@item @code{access-watchpoint}
427c3a89
DJ
14287@tab @code{Z4}
14288@tab @code{awatch}
14289
cfa9d6d9
DJ
14290@item @code{target-features}
14291@tab @code{qXfer:features:read}
14292@tab @code{set architecture}
14293
14294@item @code{library-info}
14295@tab @code{qXfer:libraries:read}
14296@tab @code{info sharedlibrary}
14297
14298@item @code{memory-map}
14299@tab @code{qXfer:memory-map:read}
14300@tab @code{info mem}
14301
14302@item @code{read-spu-object}
14303@tab @code{qXfer:spu:read}
14304@tab @code{info spu}
14305
14306@item @code{write-spu-object}
14307@tab @code{qXfer:spu:write}
14308@tab @code{info spu}
14309
14310@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
14311@tab @code{qGetTLSAddr}
14312@tab Displaying @code{__thread} variables
14313
08388c79
DE
14314@item @code{search-memory}
14315@tab @code{qSearch:memory}
14316@tab @code{find}
14317
427c3a89
DJ
14318@item @code{supported-packets}
14319@tab @code{qSupported}
14320@tab Remote communications parameters
14321
cfa9d6d9 14322@item @code{pass-signals}
89be2091
DJ
14323@tab @code{QPassSignals}
14324@tab @code{handle @var{signal}}
14325
a6b151f1
DJ
14326@item @code{hostio-close-packet}
14327@tab @code{vFile:close}
14328@tab @code{remote get}, @code{remote put}
14329
14330@item @code{hostio-open-packet}
14331@tab @code{vFile:open}
14332@tab @code{remote get}, @code{remote put}
14333
14334@item @code{hostio-pread-packet}
14335@tab @code{vFile:pread}
14336@tab @code{remote get}, @code{remote put}
14337
14338@item @code{hostio-pwrite-packet}
14339@tab @code{vFile:pwrite}
14340@tab @code{remote get}, @code{remote put}
14341
14342@item @code{hostio-unlink-packet}
14343@tab @code{vFile:unlink}
14344@tab @code{remote delete}
a6f3e723
SL
14345
14346@item @code{noack-packet}
14347@tab @code{QStartNoAckMode}
14348@tab Packet acknowledgment
07e059b5
VP
14349
14350@item @code{osdata}
14351@tab @code{qXfer:osdata:read}
14352@tab @code{info os}
427c3a89
DJ
14353@end multitable
14354
79a6e687
BW
14355@node Remote Stub
14356@section Implementing a Remote Stub
7a292a7a 14357
8e04817f
AC
14358@cindex debugging stub, example
14359@cindex remote stub, example
14360@cindex stub example, remote debugging
14361The stub files provided with @value{GDBN} implement the target side of the
14362communication protocol, and the @value{GDBN} side is implemented in the
14363@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
14364these subroutines to communicate, and ignore the details. (If you're
14365implementing your own stub file, you can still ignore the details: start
14366with one of the existing stub files. @file{sparc-stub.c} is the best
14367organized, and therefore the easiest to read.)
14368
104c1213
JM
14369@cindex remote serial debugging, overview
14370To debug a program running on another machine (the debugging
14371@dfn{target} machine), you must first arrange for all the usual
14372prerequisites for the program to run by itself. For example, for a C
14373program, you need:
c906108c 14374
104c1213
JM
14375@enumerate
14376@item
14377A startup routine to set up the C runtime environment; these usually
14378have a name like @file{crt0}. The startup routine may be supplied by
14379your hardware supplier, or you may have to write your own.
96baa820 14380
5d161b24 14381@item
d4f3574e 14382A C subroutine library to support your program's
104c1213 14383subroutine calls, notably managing input and output.
96baa820 14384
104c1213
JM
14385@item
14386A way of getting your program to the other machine---for example, a
14387download program. These are often supplied by the hardware
14388manufacturer, but you may have to write your own from hardware
14389documentation.
14390@end enumerate
96baa820 14391
104c1213
JM
14392The next step is to arrange for your program to use a serial port to
14393communicate with the machine where @value{GDBN} is running (the @dfn{host}
14394machine). In general terms, the scheme looks like this:
96baa820 14395
104c1213
JM
14396@table @emph
14397@item On the host,
14398@value{GDBN} already understands how to use this protocol; when everything
14399else is set up, you can simply use the @samp{target remote} command
14400(@pxref{Targets,,Specifying a Debugging Target}).
14401
14402@item On the target,
14403you must link with your program a few special-purpose subroutines that
14404implement the @value{GDBN} remote serial protocol. The file containing these
14405subroutines is called a @dfn{debugging stub}.
14406
14407On certain remote targets, you can use an auxiliary program
14408@code{gdbserver} instead of linking a stub into your program.
79a6e687 14409@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 14410@end table
96baa820 14411
104c1213
JM
14412The debugging stub is specific to the architecture of the remote
14413machine; for example, use @file{sparc-stub.c} to debug programs on
14414@sc{sparc} boards.
96baa820 14415
104c1213
JM
14416@cindex remote serial stub list
14417These working remote stubs are distributed with @value{GDBN}:
96baa820 14418
104c1213
JM
14419@table @code
14420
14421@item i386-stub.c
41afff9a 14422@cindex @file{i386-stub.c}
104c1213
JM
14423@cindex Intel
14424@cindex i386
14425For Intel 386 and compatible architectures.
14426
14427@item m68k-stub.c
41afff9a 14428@cindex @file{m68k-stub.c}
104c1213
JM
14429@cindex Motorola 680x0
14430@cindex m680x0
14431For Motorola 680x0 architectures.
14432
14433@item sh-stub.c
41afff9a 14434@cindex @file{sh-stub.c}
172c2a43 14435@cindex Renesas
104c1213 14436@cindex SH
172c2a43 14437For Renesas SH architectures.
104c1213
JM
14438
14439@item sparc-stub.c
41afff9a 14440@cindex @file{sparc-stub.c}
104c1213
JM
14441@cindex Sparc
14442For @sc{sparc} architectures.
14443
14444@item sparcl-stub.c
41afff9a 14445@cindex @file{sparcl-stub.c}
104c1213
JM
14446@cindex Fujitsu
14447@cindex SparcLite
14448For Fujitsu @sc{sparclite} architectures.
14449
14450@end table
14451
14452The @file{README} file in the @value{GDBN} distribution may list other
14453recently added stubs.
14454
14455@menu
14456* Stub Contents:: What the stub can do for you
14457* Bootstrapping:: What you must do for the stub
14458* Debug Session:: Putting it all together
104c1213
JM
14459@end menu
14460
6d2ebf8b 14461@node Stub Contents
79a6e687 14462@subsection What the Stub Can Do for You
104c1213
JM
14463
14464@cindex remote serial stub
14465The debugging stub for your architecture supplies these three
14466subroutines:
14467
14468@table @code
14469@item set_debug_traps
4644b6e3 14470@findex set_debug_traps
104c1213
JM
14471@cindex remote serial stub, initialization
14472This routine arranges for @code{handle_exception} to run when your
14473program stops. You must call this subroutine explicitly near the
14474beginning of your program.
14475
14476@item handle_exception
4644b6e3 14477@findex handle_exception
104c1213
JM
14478@cindex remote serial stub, main routine
14479This is the central workhorse, but your program never calls it
14480explicitly---the setup code arranges for @code{handle_exception} to
14481run when a trap is triggered.
14482
14483@code{handle_exception} takes control when your program stops during
14484execution (for example, on a breakpoint), and mediates communications
14485with @value{GDBN} on the host machine. This is where the communications
14486protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 14487representative on the target machine. It begins by sending summary
104c1213
JM
14488information on the state of your program, then continues to execute,
14489retrieving and transmitting any information @value{GDBN} needs, until you
14490execute a @value{GDBN} command that makes your program resume; at that point,
14491@code{handle_exception} returns control to your own code on the target
5d161b24 14492machine.
104c1213
JM
14493
14494@item breakpoint
14495@cindex @code{breakpoint} subroutine, remote
14496Use this auxiliary subroutine to make your program contain a
14497breakpoint. Depending on the particular situation, this may be the only
14498way for @value{GDBN} to get control. For instance, if your target
14499machine has some sort of interrupt button, you won't need to call this;
14500pressing the interrupt button transfers control to
14501@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
14502simply receiving characters on the serial port may also trigger a trap;
14503again, in that situation, you don't need to call @code{breakpoint} from
14504your own program---simply running @samp{target remote} from the host
5d161b24 14505@value{GDBN} session gets control.
104c1213
JM
14506
14507Call @code{breakpoint} if none of these is true, or if you simply want
14508to make certain your program stops at a predetermined point for the
14509start of your debugging session.
14510@end table
14511
6d2ebf8b 14512@node Bootstrapping
79a6e687 14513@subsection What You Must Do for the Stub
104c1213
JM
14514
14515@cindex remote stub, support routines
14516The debugging stubs that come with @value{GDBN} are set up for a particular
14517chip architecture, but they have no information about the rest of your
14518debugging target machine.
14519
14520First of all you need to tell the stub how to communicate with the
14521serial port.
14522
14523@table @code
14524@item int getDebugChar()
4644b6e3 14525@findex getDebugChar
104c1213
JM
14526Write this subroutine to read a single character from the serial port.
14527It may be identical to @code{getchar} for your target system; a
14528different name is used to allow you to distinguish the two if you wish.
14529
14530@item void putDebugChar(int)
4644b6e3 14531@findex putDebugChar
104c1213 14532Write this subroutine to write a single character to the serial port.
5d161b24 14533It may be identical to @code{putchar} for your target system; a
104c1213
JM
14534different name is used to allow you to distinguish the two if you wish.
14535@end table
14536
14537@cindex control C, and remote debugging
14538@cindex interrupting remote targets
14539If you want @value{GDBN} to be able to stop your program while it is
14540running, you need to use an interrupt-driven serial driver, and arrange
14541for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
14542character). That is the character which @value{GDBN} uses to tell the
14543remote system to stop.
14544
14545Getting the debugging target to return the proper status to @value{GDBN}
14546probably requires changes to the standard stub; one quick and dirty way
14547is to just execute a breakpoint instruction (the ``dirty'' part is that
14548@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
14549
14550Other routines you need to supply are:
14551
14552@table @code
14553@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 14554@findex exceptionHandler
104c1213
JM
14555Write this function to install @var{exception_address} in the exception
14556handling tables. You need to do this because the stub does not have any
14557way of knowing what the exception handling tables on your target system
14558are like (for example, the processor's table might be in @sc{rom},
14559containing entries which point to a table in @sc{ram}).
14560@var{exception_number} is the exception number which should be changed;
14561its meaning is architecture-dependent (for example, different numbers
14562might represent divide by zero, misaligned access, etc). When this
14563exception occurs, control should be transferred directly to
14564@var{exception_address}, and the processor state (stack, registers,
14565and so on) should be just as it is when a processor exception occurs. So if
14566you want to use a jump instruction to reach @var{exception_address}, it
14567should be a simple jump, not a jump to subroutine.
14568
14569For the 386, @var{exception_address} should be installed as an interrupt
14570gate so that interrupts are masked while the handler runs. The gate
14571should be at privilege level 0 (the most privileged level). The
14572@sc{sparc} and 68k stubs are able to mask interrupts themselves without
14573help from @code{exceptionHandler}.
14574
14575@item void flush_i_cache()
4644b6e3 14576@findex flush_i_cache
d4f3574e 14577On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
14578instruction cache, if any, on your target machine. If there is no
14579instruction cache, this subroutine may be a no-op.
14580
14581On target machines that have instruction caches, @value{GDBN} requires this
14582function to make certain that the state of your program is stable.
14583@end table
14584
14585@noindent
14586You must also make sure this library routine is available:
14587
14588@table @code
14589@item void *memset(void *, int, int)
4644b6e3 14590@findex memset
104c1213
JM
14591This is the standard library function @code{memset} that sets an area of
14592memory to a known value. If you have one of the free versions of
14593@code{libc.a}, @code{memset} can be found there; otherwise, you must
14594either obtain it from your hardware manufacturer, or write your own.
14595@end table
14596
14597If you do not use the GNU C compiler, you may need other standard
14598library subroutines as well; this varies from one stub to another,
14599but in general the stubs are likely to use any of the common library
e22ea452 14600subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
14601
14602
6d2ebf8b 14603@node Debug Session
79a6e687 14604@subsection Putting it All Together
104c1213
JM
14605
14606@cindex remote serial debugging summary
14607In summary, when your program is ready to debug, you must follow these
14608steps.
14609
14610@enumerate
14611@item
6d2ebf8b 14612Make sure you have defined the supporting low-level routines
79a6e687 14613(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
14614@display
14615@code{getDebugChar}, @code{putDebugChar},
14616@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
14617@end display
14618
14619@item
14620Insert these lines near the top of your program:
14621
474c8240 14622@smallexample
104c1213
JM
14623set_debug_traps();
14624breakpoint();
474c8240 14625@end smallexample
104c1213
JM
14626
14627@item
14628For the 680x0 stub only, you need to provide a variable called
14629@code{exceptionHook}. Normally you just use:
14630
474c8240 14631@smallexample
104c1213 14632void (*exceptionHook)() = 0;
474c8240 14633@end smallexample
104c1213 14634
d4f3574e 14635@noindent
104c1213 14636but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 14637function in your program, that function is called when
104c1213
JM
14638@code{@value{GDBN}} continues after stopping on a trap (for example, bus
14639error). The function indicated by @code{exceptionHook} is called with
14640one parameter: an @code{int} which is the exception number.
14641
14642@item
14643Compile and link together: your program, the @value{GDBN} debugging stub for
14644your target architecture, and the supporting subroutines.
14645
14646@item
14647Make sure you have a serial connection between your target machine and
14648the @value{GDBN} host, and identify the serial port on the host.
14649
14650@item
14651@c The "remote" target now provides a `load' command, so we should
14652@c document that. FIXME.
14653Download your program to your target machine (or get it there by
14654whatever means the manufacturer provides), and start it.
14655
14656@item
07f31aa6 14657Start @value{GDBN} on the host, and connect to the target
79a6e687 14658(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 14659
104c1213
JM
14660@end enumerate
14661
8e04817f
AC
14662@node Configurations
14663@chapter Configuration-Specific Information
104c1213 14664
8e04817f
AC
14665While nearly all @value{GDBN} commands are available for all native and
14666cross versions of the debugger, there are some exceptions. This chapter
14667describes things that are only available in certain configurations.
104c1213 14668
8e04817f
AC
14669There are three major categories of configurations: native
14670configurations, where the host and target are the same, embedded
14671operating system configurations, which are usually the same for several
14672different processor architectures, and bare embedded processors, which
14673are quite different from each other.
104c1213 14674
8e04817f
AC
14675@menu
14676* Native::
14677* Embedded OS::
14678* Embedded Processors::
14679* Architectures::
14680@end menu
104c1213 14681
8e04817f
AC
14682@node Native
14683@section Native
104c1213 14684
8e04817f
AC
14685This section describes details specific to particular native
14686configurations.
6cf7e474 14687
8e04817f
AC
14688@menu
14689* HP-UX:: HP-UX
7561d450 14690* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
14691* SVR4 Process Information:: SVR4 process information
14692* DJGPP Native:: Features specific to the DJGPP port
78c47bea 14693* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 14694* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 14695* Neutrino:: Features specific to QNX Neutrino
a80b95ba 14696* Darwin:: Features specific to Darwin
8e04817f 14697@end menu
6cf7e474 14698
8e04817f
AC
14699@node HP-UX
14700@subsection HP-UX
104c1213 14701
8e04817f
AC
14702On HP-UX systems, if you refer to a function or variable name that
14703begins with a dollar sign, @value{GDBN} searches for a user or system
14704name first, before it searches for a convenience variable.
104c1213 14705
9c16f35a 14706
7561d450
MK
14707@node BSD libkvm Interface
14708@subsection BSD libkvm Interface
14709
14710@cindex libkvm
14711@cindex kernel memory image
14712@cindex kernel crash dump
14713
14714BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
14715interface that provides a uniform interface for accessing kernel virtual
14716memory images, including live systems and crash dumps. @value{GDBN}
14717uses this interface to allow you to debug live kernels and kernel crash
14718dumps on many native BSD configurations. This is implemented as a
14719special @code{kvm} debugging target. For debugging a live system, load
14720the currently running kernel into @value{GDBN} and connect to the
14721@code{kvm} target:
14722
14723@smallexample
14724(@value{GDBP}) @b{target kvm}
14725@end smallexample
14726
14727For debugging crash dumps, provide the file name of the crash dump as an
14728argument:
14729
14730@smallexample
14731(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
14732@end smallexample
14733
14734Once connected to the @code{kvm} target, the following commands are
14735available:
14736
14737@table @code
14738@kindex kvm
14739@item kvm pcb
721c2651 14740Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
14741
14742@item kvm proc
14743Set current context from proc address. This command isn't available on
14744modern FreeBSD systems.
14745@end table
14746
8e04817f 14747@node SVR4 Process Information
79a6e687 14748@subsection SVR4 Process Information
60bf7e09
EZ
14749@cindex /proc
14750@cindex examine process image
14751@cindex process info via @file{/proc}
104c1213 14752
60bf7e09
EZ
14753Many versions of SVR4 and compatible systems provide a facility called
14754@samp{/proc} that can be used to examine the image of a running
14755process using file-system subroutines. If @value{GDBN} is configured
14756for an operating system with this facility, the command @code{info
14757proc} is available to report information about the process running
14758your program, or about any process running on your system. @code{info
14759proc} works only on SVR4 systems that include the @code{procfs} code.
14760This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
14761Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 14762
8e04817f
AC
14763@table @code
14764@kindex info proc
60bf7e09 14765@cindex process ID
8e04817f 14766@item info proc
60bf7e09
EZ
14767@itemx info proc @var{process-id}
14768Summarize available information about any running process. If a
14769process ID is specified by @var{process-id}, display information about
14770that process; otherwise display information about the program being
14771debugged. The summary includes the debugged process ID, the command
14772line used to invoke it, its current working directory, and its
14773executable file's absolute file name.
14774
14775On some systems, @var{process-id} can be of the form
14776@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
14777within a process. If the optional @var{pid} part is missing, it means
14778a thread from the process being debugged (the leading @samp{/} still
14779needs to be present, or else @value{GDBN} will interpret the number as
14780a process ID rather than a thread ID).
6cf7e474 14781
8e04817f 14782@item info proc mappings
60bf7e09
EZ
14783@cindex memory address space mappings
14784Report the memory address space ranges accessible in the program, with
14785information on whether the process has read, write, or execute access
14786rights to each range. On @sc{gnu}/Linux systems, each memory range
14787includes the object file which is mapped to that range, instead of the
14788memory access rights to that range.
14789
14790@item info proc stat
14791@itemx info proc status
14792@cindex process detailed status information
14793These subcommands are specific to @sc{gnu}/Linux systems. They show
14794the process-related information, including the user ID and group ID;
14795how many threads are there in the process; its virtual memory usage;
14796the signals that are pending, blocked, and ignored; its TTY; its
14797consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 14798value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
14799(type @kbd{man 5 proc} from your shell prompt).
14800
14801@item info proc all
14802Show all the information about the process described under all of the
14803above @code{info proc} subcommands.
14804
8e04817f
AC
14805@ignore
14806@comment These sub-options of 'info proc' were not included when
14807@comment procfs.c was re-written. Keep their descriptions around
14808@comment against the day when someone finds the time to put them back in.
14809@kindex info proc times
14810@item info proc times
14811Starting time, user CPU time, and system CPU time for your program and
14812its children.
6cf7e474 14813
8e04817f
AC
14814@kindex info proc id
14815@item info proc id
14816Report on the process IDs related to your program: its own process ID,
14817the ID of its parent, the process group ID, and the session ID.
8e04817f 14818@end ignore
721c2651
EZ
14819
14820@item set procfs-trace
14821@kindex set procfs-trace
14822@cindex @code{procfs} API calls
14823This command enables and disables tracing of @code{procfs} API calls.
14824
14825@item show procfs-trace
14826@kindex show procfs-trace
14827Show the current state of @code{procfs} API call tracing.
14828
14829@item set procfs-file @var{file}
14830@kindex set procfs-file
14831Tell @value{GDBN} to write @code{procfs} API trace to the named
14832@var{file}. @value{GDBN} appends the trace info to the previous
14833contents of the file. The default is to display the trace on the
14834standard output.
14835
14836@item show procfs-file
14837@kindex show procfs-file
14838Show the file to which @code{procfs} API trace is written.
14839
14840@item proc-trace-entry
14841@itemx proc-trace-exit
14842@itemx proc-untrace-entry
14843@itemx proc-untrace-exit
14844@kindex proc-trace-entry
14845@kindex proc-trace-exit
14846@kindex proc-untrace-entry
14847@kindex proc-untrace-exit
14848These commands enable and disable tracing of entries into and exits
14849from the @code{syscall} interface.
14850
14851@item info pidlist
14852@kindex info pidlist
14853@cindex process list, QNX Neutrino
14854For QNX Neutrino only, this command displays the list of all the
14855processes and all the threads within each process.
14856
14857@item info meminfo
14858@kindex info meminfo
14859@cindex mapinfo list, QNX Neutrino
14860For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 14861@end table
104c1213 14862
8e04817f
AC
14863@node DJGPP Native
14864@subsection Features for Debugging @sc{djgpp} Programs
14865@cindex @sc{djgpp} debugging
14866@cindex native @sc{djgpp} debugging
14867@cindex MS-DOS-specific commands
104c1213 14868
514c4d71
EZ
14869@cindex DPMI
14870@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
14871MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
14872that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
14873top of real-mode DOS systems and their emulations.
104c1213 14874
8e04817f
AC
14875@value{GDBN} supports native debugging of @sc{djgpp} programs, and
14876defines a few commands specific to the @sc{djgpp} port. This
14877subsection describes those commands.
104c1213 14878
8e04817f
AC
14879@table @code
14880@kindex info dos
14881@item info dos
14882This is a prefix of @sc{djgpp}-specific commands which print
14883information about the target system and important OS structures.
f1251bdd 14884
8e04817f
AC
14885@kindex sysinfo
14886@cindex MS-DOS system info
14887@cindex free memory information (MS-DOS)
14888@item info dos sysinfo
14889This command displays assorted information about the underlying
14890platform: the CPU type and features, the OS version and flavor, the
14891DPMI version, and the available conventional and DPMI memory.
104c1213 14892
8e04817f
AC
14893@cindex GDT
14894@cindex LDT
14895@cindex IDT
14896@cindex segment descriptor tables
14897@cindex descriptor tables display
14898@item info dos gdt
14899@itemx info dos ldt
14900@itemx info dos idt
14901These 3 commands display entries from, respectively, Global, Local,
14902and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
14903tables are data structures which store a descriptor for each segment
14904that is currently in use. The segment's selector is an index into a
14905descriptor table; the table entry for that index holds the
14906descriptor's base address and limit, and its attributes and access
14907rights.
104c1213 14908
8e04817f
AC
14909A typical @sc{djgpp} program uses 3 segments: a code segment, a data
14910segment (used for both data and the stack), and a DOS segment (which
14911allows access to DOS/BIOS data structures and absolute addresses in
14912conventional memory). However, the DPMI host will usually define
14913additional segments in order to support the DPMI environment.
d4f3574e 14914
8e04817f
AC
14915@cindex garbled pointers
14916These commands allow to display entries from the descriptor tables.
14917Without an argument, all entries from the specified table are
14918displayed. An argument, which should be an integer expression, means
14919display a single entry whose index is given by the argument. For
14920example, here's a convenient way to display information about the
14921debugged program's data segment:
104c1213 14922
8e04817f
AC
14923@smallexample
14924@exdent @code{(@value{GDBP}) info dos ldt $ds}
14925@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
14926@end smallexample
104c1213 14927
8e04817f
AC
14928@noindent
14929This comes in handy when you want to see whether a pointer is outside
14930the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 14931
8e04817f
AC
14932@cindex page tables display (MS-DOS)
14933@item info dos pde
14934@itemx info dos pte
14935These two commands display entries from, respectively, the Page
14936Directory and the Page Tables. Page Directories and Page Tables are
14937data structures which control how virtual memory addresses are mapped
14938into physical addresses. A Page Table includes an entry for every
14939page of memory that is mapped into the program's address space; there
14940may be several Page Tables, each one holding up to 4096 entries. A
14941Page Directory has up to 4096 entries, one each for every Page Table
14942that is currently in use.
104c1213 14943
8e04817f
AC
14944Without an argument, @kbd{info dos pde} displays the entire Page
14945Directory, and @kbd{info dos pte} displays all the entries in all of
14946the Page Tables. An argument, an integer expression, given to the
14947@kbd{info dos pde} command means display only that entry from the Page
14948Directory table. An argument given to the @kbd{info dos pte} command
14949means display entries from a single Page Table, the one pointed to by
14950the specified entry in the Page Directory.
104c1213 14951
8e04817f
AC
14952@cindex direct memory access (DMA) on MS-DOS
14953These commands are useful when your program uses @dfn{DMA} (Direct
14954Memory Access), which needs physical addresses to program the DMA
14955controller.
104c1213 14956
8e04817f 14957These commands are supported only with some DPMI servers.
104c1213 14958
8e04817f
AC
14959@cindex physical address from linear address
14960@item info dos address-pte @var{addr}
14961This command displays the Page Table entry for a specified linear
514c4d71
EZ
14962address. The argument @var{addr} is a linear address which should
14963already have the appropriate segment's base address added to it,
14964because this command accepts addresses which may belong to @emph{any}
14965segment. For example, here's how to display the Page Table entry for
14966the page where a variable @code{i} is stored:
104c1213 14967
b383017d 14968@smallexample
8e04817f
AC
14969@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
14970@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 14971@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 14972@end smallexample
104c1213 14973
8e04817f
AC
14974@noindent
14975This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 14976whose physical base address is @code{0x02698000}, and shows all the
8e04817f 14977attributes of that page.
104c1213 14978
8e04817f
AC
14979Note that you must cast the addresses of variables to a @code{char *},
14980since otherwise the value of @code{__djgpp_base_address}, the base
14981address of all variables and functions in a @sc{djgpp} program, will
14982be added using the rules of C pointer arithmetics: if @code{i} is
14983declared an @code{int}, @value{GDBN} will add 4 times the value of
14984@code{__djgpp_base_address} to the address of @code{i}.
104c1213 14985
8e04817f
AC
14986Here's another example, it displays the Page Table entry for the
14987transfer buffer:
104c1213 14988
8e04817f
AC
14989@smallexample
14990@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
14991@exdent @code{Page Table entry for address 0x29110:}
14992@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
14993@end smallexample
104c1213 14994
8e04817f
AC
14995@noindent
14996(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
149973rd member of the @code{_go32_info_block} structure.) The output
14998clearly shows that this DPMI server maps the addresses in conventional
14999memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
15000linear (@code{0x29110}) addresses are identical.
104c1213 15001
8e04817f
AC
15002This command is supported only with some DPMI servers.
15003@end table
104c1213 15004
c45da7e6 15005@cindex DOS serial data link, remote debugging
a8f24a35
EZ
15006In addition to native debugging, the DJGPP port supports remote
15007debugging via a serial data link. The following commands are specific
15008to remote serial debugging in the DJGPP port of @value{GDBN}.
15009
15010@table @code
15011@kindex set com1base
15012@kindex set com1irq
15013@kindex set com2base
15014@kindex set com2irq
15015@kindex set com3base
15016@kindex set com3irq
15017@kindex set com4base
15018@kindex set com4irq
15019@item set com1base @var{addr}
15020This command sets the base I/O port address of the @file{COM1} serial
15021port.
15022
15023@item set com1irq @var{irq}
15024This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
15025for the @file{COM1} serial port.
15026
15027There are similar commands @samp{set com2base}, @samp{set com3irq},
15028etc.@: for setting the port address and the @code{IRQ} lines for the
15029other 3 COM ports.
15030
15031@kindex show com1base
15032@kindex show com1irq
15033@kindex show com2base
15034@kindex show com2irq
15035@kindex show com3base
15036@kindex show com3irq
15037@kindex show com4base
15038@kindex show com4irq
15039The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
15040display the current settings of the base address and the @code{IRQ}
15041lines used by the COM ports.
c45da7e6
EZ
15042
15043@item info serial
15044@kindex info serial
15045@cindex DOS serial port status
15046This command prints the status of the 4 DOS serial ports. For each
15047port, it prints whether it's active or not, its I/O base address and
15048IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
15049counts of various errors encountered so far.
a8f24a35
EZ
15050@end table
15051
15052
78c47bea 15053@node Cygwin Native
79a6e687 15054@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
15055@cindex MS Windows debugging
15056@cindex native Cygwin debugging
15057@cindex Cygwin-specific commands
15058
be448670 15059@value{GDBN} supports native debugging of MS Windows programs, including
db2e3e2e
BW
15060DLLs with and without symbolic debugging information. There are various
15061additional Cygwin-specific commands, described in this section.
15062Working with DLLs that have no debugging symbols is described in
15063@ref{Non-debug DLL Symbols}.
78c47bea
PM
15064
15065@table @code
15066@kindex info w32
15067@item info w32
db2e3e2e 15068This is a prefix of MS Windows-specific commands which print
78c47bea
PM
15069information about the target system and important OS structures.
15070
15071@item info w32 selector
15072This command displays information returned by
15073the Win32 API @code{GetThreadSelectorEntry} function.
15074It takes an optional argument that is evaluated to
15075a long value to give the information about this given selector.
15076Without argument, this command displays information
d3e8051b 15077about the six segment registers.
78c47bea
PM
15078
15079@kindex info dll
15080@item info dll
db2e3e2e 15081This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
15082
15083@kindex dll-symbols
15084@item dll-symbols
15085This command loads symbols from a dll similarly to
15086add-sym command but without the need to specify a base address.
15087
be90c084 15088@kindex set cygwin-exceptions
e16b02ee
EZ
15089@cindex debugging the Cygwin DLL
15090@cindex Cygwin DLL, debugging
be90c084 15091@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
15092If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
15093happen inside the Cygwin DLL. If @var{mode} is @code{off},
15094@value{GDBN} will delay recognition of exceptions, and may ignore some
15095exceptions which seem to be caused by internal Cygwin DLL
15096``bookkeeping''. This option is meant primarily for debugging the
15097Cygwin DLL itself; the default value is @code{off} to avoid annoying
15098@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
15099
15100@kindex show cygwin-exceptions
15101@item show cygwin-exceptions
e16b02ee
EZ
15102Displays whether @value{GDBN} will break on exceptions that happen
15103inside the Cygwin DLL itself.
be90c084 15104
b383017d 15105@kindex set new-console
78c47bea 15106@item set new-console @var{mode}
b383017d 15107If @var{mode} is @code{on} the debuggee will
78c47bea
PM
15108be started in a new console on next start.
15109If @var{mode} is @code{off}i, the debuggee will
15110be started in the same console as the debugger.
15111
15112@kindex show new-console
15113@item show new-console
15114Displays whether a new console is used
15115when the debuggee is started.
15116
15117@kindex set new-group
15118@item set new-group @var{mode}
15119This boolean value controls whether the debuggee should
15120start a new group or stay in the same group as the debugger.
15121This affects the way the Windows OS handles
c8aa23ab 15122@samp{Ctrl-C}.
78c47bea
PM
15123
15124@kindex show new-group
15125@item show new-group
15126Displays current value of new-group boolean.
15127
15128@kindex set debugevents
15129@item set debugevents
219eec71
EZ
15130This boolean value adds debug output concerning kernel events related
15131to the debuggee seen by the debugger. This includes events that
15132signal thread and process creation and exit, DLL loading and
15133unloading, console interrupts, and debugging messages produced by the
15134Windows @code{OutputDebugString} API call.
78c47bea
PM
15135
15136@kindex set debugexec
15137@item set debugexec
b383017d 15138This boolean value adds debug output concerning execute events
219eec71 15139(such as resume thread) seen by the debugger.
78c47bea
PM
15140
15141@kindex set debugexceptions
15142@item set debugexceptions
219eec71
EZ
15143This boolean value adds debug output concerning exceptions in the
15144debuggee seen by the debugger.
78c47bea
PM
15145
15146@kindex set debugmemory
15147@item set debugmemory
219eec71
EZ
15148This boolean value adds debug output concerning debuggee memory reads
15149and writes by the debugger.
78c47bea
PM
15150
15151@kindex set shell
15152@item set shell
15153This boolean values specifies whether the debuggee is called
15154via a shell or directly (default value is on).
15155
15156@kindex show shell
15157@item show shell
15158Displays if the debuggee will be started with a shell.
15159
15160@end table
15161
be448670 15162@menu
79a6e687 15163* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
15164@end menu
15165
79a6e687
BW
15166@node Non-debug DLL Symbols
15167@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
15168@cindex DLLs with no debugging symbols
15169@cindex Minimal symbols and DLLs
15170
15171Very often on windows, some of the DLLs that your program relies on do
15172not include symbolic debugging information (for example,
db2e3e2e 15173@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 15174symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 15175information contained in the DLL's export table. This section
be448670
CF
15176describes working with such symbols, known internally to @value{GDBN} as
15177``minimal symbols''.
15178
15179Note that before the debugged program has started execution, no DLLs
db2e3e2e 15180will have been loaded. The easiest way around this problem is simply to
be448670 15181start the program --- either by setting a breakpoint or letting the
db2e3e2e 15182program run once to completion. It is also possible to force
be448670 15183@value{GDBN} to load a particular DLL before starting the executable ---
12c27660 15184see the shared library information in @ref{Files}, or the
db2e3e2e 15185@code{dll-symbols} command in @ref{Cygwin Native}. Currently,
be448670
CF
15186explicitly loading symbols from a DLL with no debugging information will
15187cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
15188which may adversely affect symbol lookup performance.
15189
79a6e687 15190@subsubsection DLL Name Prefixes
be448670
CF
15191
15192In keeping with the naming conventions used by the Microsoft debugging
15193tools, DLL export symbols are made available with a prefix based on the
15194DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
15195also entered into the symbol table, so @code{CreateFileA} is often
15196sufficient. In some cases there will be name clashes within a program
15197(particularly if the executable itself includes full debugging symbols)
15198necessitating the use of the fully qualified name when referring to the
15199contents of the DLL. Use single-quotes around the name to avoid the
15200exclamation mark (``!'') being interpreted as a language operator.
15201
15202Note that the internal name of the DLL may be all upper-case, even
15203though the file name of the DLL is lower-case, or vice-versa. Since
15204symbols within @value{GDBN} are @emph{case-sensitive} this may cause
15205some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
15206@code{info variables} commands or even @code{maint print msymbols}
15207(@pxref{Symbols}). Here's an example:
be448670
CF
15208
15209@smallexample
f7dc1244 15210(@value{GDBP}) info function CreateFileA
be448670
CF
15211All functions matching regular expression "CreateFileA":
15212
15213Non-debugging symbols:
152140x77e885f4 CreateFileA
152150x77e885f4 KERNEL32!CreateFileA
15216@end smallexample
15217
15218@smallexample
f7dc1244 15219(@value{GDBP}) info function !
be448670
CF
15220All functions matching regular expression "!":
15221
15222Non-debugging symbols:
152230x6100114c cygwin1!__assert
152240x61004034 cygwin1!_dll_crt0@@0
152250x61004240 cygwin1!dll_crt0(per_process *)
15226[etc...]
15227@end smallexample
15228
79a6e687 15229@subsubsection Working with Minimal Symbols
be448670
CF
15230
15231Symbols extracted from a DLL's export table do not contain very much
15232type information. All that @value{GDBN} can do is guess whether a symbol
15233refers to a function or variable depending on the linker section that
15234contains the symbol. Also note that the actual contents of the memory
15235contained in a DLL are not available unless the program is running. This
15236means that you cannot examine the contents of a variable or disassemble
15237a function within a DLL without a running program.
15238
15239Variables are generally treated as pointers and dereferenced
15240automatically. For this reason, it is often necessary to prefix a
15241variable name with the address-of operator (``&'') and provide explicit
15242type information in the command. Here's an example of the type of
15243problem:
15244
15245@smallexample
f7dc1244 15246(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
15247$1 = 268572168
15248@end smallexample
15249
15250@smallexample
f7dc1244 15251(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
152520x10021610: "\230y\""
15253@end smallexample
15254
15255And two possible solutions:
15256
15257@smallexample
f7dc1244 15258(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
15259$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
15260@end smallexample
15261
15262@smallexample
f7dc1244 15263(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 152640x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 15265(@value{GDBP}) x/x 0x10021608
be448670 152660x10021608: 0x0022fd98
f7dc1244 15267(@value{GDBP}) x/s 0x0022fd98
be448670
CF
152680x22fd98: "/cygdrive/c/mydirectory/myprogram"
15269@end smallexample
15270
15271Setting a break point within a DLL is possible even before the program
15272starts execution. However, under these circumstances, @value{GDBN} can't
15273examine the initial instructions of the function in order to skip the
15274function's frame set-up code. You can work around this by using ``*&''
15275to set the breakpoint at a raw memory address:
15276
15277@smallexample
f7dc1244 15278(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
15279Breakpoint 1 at 0x1e04eff0
15280@end smallexample
15281
15282The author of these extensions is not entirely convinced that setting a
15283break point within a shared DLL like @file{kernel32.dll} is completely
15284safe.
15285
14d6dd68 15286@node Hurd Native
79a6e687 15287@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
15288@cindex @sc{gnu} Hurd debugging
15289
15290This subsection describes @value{GDBN} commands specific to the
15291@sc{gnu} Hurd native debugging.
15292
15293@table @code
15294@item set signals
15295@itemx set sigs
15296@kindex set signals@r{, Hurd command}
15297@kindex set sigs@r{, Hurd command}
15298This command toggles the state of inferior signal interception by
15299@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
15300affected by this command. @code{sigs} is a shorthand alias for
15301@code{signals}.
15302
15303@item show signals
15304@itemx show sigs
15305@kindex show signals@r{, Hurd command}
15306@kindex show sigs@r{, Hurd command}
15307Show the current state of intercepting inferior's signals.
15308
15309@item set signal-thread
15310@itemx set sigthread
15311@kindex set signal-thread
15312@kindex set sigthread
15313This command tells @value{GDBN} which thread is the @code{libc} signal
15314thread. That thread is run when a signal is delivered to a running
15315process. @code{set sigthread} is the shorthand alias of @code{set
15316signal-thread}.
15317
15318@item show signal-thread
15319@itemx show sigthread
15320@kindex show signal-thread
15321@kindex show sigthread
15322These two commands show which thread will run when the inferior is
15323delivered a signal.
15324
15325@item set stopped
15326@kindex set stopped@r{, Hurd command}
15327This commands tells @value{GDBN} that the inferior process is stopped,
15328as with the @code{SIGSTOP} signal. The stopped process can be
15329continued by delivering a signal to it.
15330
15331@item show stopped
15332@kindex show stopped@r{, Hurd command}
15333This command shows whether @value{GDBN} thinks the debuggee is
15334stopped.
15335
15336@item set exceptions
15337@kindex set exceptions@r{, Hurd command}
15338Use this command to turn off trapping of exceptions in the inferior.
15339When exception trapping is off, neither breakpoints nor
15340single-stepping will work. To restore the default, set exception
15341trapping on.
15342
15343@item show exceptions
15344@kindex show exceptions@r{, Hurd command}
15345Show the current state of trapping exceptions in the inferior.
15346
15347@item set task pause
15348@kindex set task@r{, Hurd commands}
15349@cindex task attributes (@sc{gnu} Hurd)
15350@cindex pause current task (@sc{gnu} Hurd)
15351This command toggles task suspension when @value{GDBN} has control.
15352Setting it to on takes effect immediately, and the task is suspended
15353whenever @value{GDBN} gets control. Setting it to off will take
15354effect the next time the inferior is continued. If this option is set
15355to off, you can use @code{set thread default pause on} or @code{set
15356thread pause on} (see below) to pause individual threads.
15357
15358@item show task pause
15359@kindex show task@r{, Hurd commands}
15360Show the current state of task suspension.
15361
15362@item set task detach-suspend-count
15363@cindex task suspend count
15364@cindex detach from task, @sc{gnu} Hurd
15365This command sets the suspend count the task will be left with when
15366@value{GDBN} detaches from it.
15367
15368@item show task detach-suspend-count
15369Show the suspend count the task will be left with when detaching.
15370
15371@item set task exception-port
15372@itemx set task excp
15373@cindex task exception port, @sc{gnu} Hurd
15374This command sets the task exception port to which @value{GDBN} will
15375forward exceptions. The argument should be the value of the @dfn{send
15376rights} of the task. @code{set task excp} is a shorthand alias.
15377
15378@item set noninvasive
15379@cindex noninvasive task options
15380This command switches @value{GDBN} to a mode that is the least
15381invasive as far as interfering with the inferior is concerned. This
15382is the same as using @code{set task pause}, @code{set exceptions}, and
15383@code{set signals} to values opposite to the defaults.
15384
15385@item info send-rights
15386@itemx info receive-rights
15387@itemx info port-rights
15388@itemx info port-sets
15389@itemx info dead-names
15390@itemx info ports
15391@itemx info psets
15392@cindex send rights, @sc{gnu} Hurd
15393@cindex receive rights, @sc{gnu} Hurd
15394@cindex port rights, @sc{gnu} Hurd
15395@cindex port sets, @sc{gnu} Hurd
15396@cindex dead names, @sc{gnu} Hurd
15397These commands display information about, respectively, send rights,
15398receive rights, port rights, port sets, and dead names of a task.
15399There are also shorthand aliases: @code{info ports} for @code{info
15400port-rights} and @code{info psets} for @code{info port-sets}.
15401
15402@item set thread pause
15403@kindex set thread@r{, Hurd command}
15404@cindex thread properties, @sc{gnu} Hurd
15405@cindex pause current thread (@sc{gnu} Hurd)
15406This command toggles current thread suspension when @value{GDBN} has
15407control. Setting it to on takes effect immediately, and the current
15408thread is suspended whenever @value{GDBN} gets control. Setting it to
15409off will take effect the next time the inferior is continued.
15410Normally, this command has no effect, since when @value{GDBN} has
15411control, the whole task is suspended. However, if you used @code{set
15412task pause off} (see above), this command comes in handy to suspend
15413only the current thread.
15414
15415@item show thread pause
15416@kindex show thread@r{, Hurd command}
15417This command shows the state of current thread suspension.
15418
15419@item set thread run
d3e8051b 15420This command sets whether the current thread is allowed to run.
14d6dd68
EZ
15421
15422@item show thread run
15423Show whether the current thread is allowed to run.
15424
15425@item set thread detach-suspend-count
15426@cindex thread suspend count, @sc{gnu} Hurd
15427@cindex detach from thread, @sc{gnu} Hurd
15428This command sets the suspend count @value{GDBN} will leave on a
15429thread when detaching. This number is relative to the suspend count
15430found by @value{GDBN} when it notices the thread; use @code{set thread
15431takeover-suspend-count} to force it to an absolute value.
15432
15433@item show thread detach-suspend-count
15434Show the suspend count @value{GDBN} will leave on the thread when
15435detaching.
15436
15437@item set thread exception-port
15438@itemx set thread excp
15439Set the thread exception port to which to forward exceptions. This
15440overrides the port set by @code{set task exception-port} (see above).
15441@code{set thread excp} is the shorthand alias.
15442
15443@item set thread takeover-suspend-count
15444Normally, @value{GDBN}'s thread suspend counts are relative to the
15445value @value{GDBN} finds when it notices each thread. This command
15446changes the suspend counts to be absolute instead.
15447
15448@item set thread default
15449@itemx show thread default
15450@cindex thread default settings, @sc{gnu} Hurd
15451Each of the above @code{set thread} commands has a @code{set thread
15452default} counterpart (e.g., @code{set thread default pause}, @code{set
15453thread default exception-port}, etc.). The @code{thread default}
15454variety of commands sets the default thread properties for all
15455threads; you can then change the properties of individual threads with
15456the non-default commands.
15457@end table
15458
15459
a64548ea
EZ
15460@node Neutrino
15461@subsection QNX Neutrino
15462@cindex QNX Neutrino
15463
15464@value{GDBN} provides the following commands specific to the QNX
15465Neutrino target:
15466
15467@table @code
15468@item set debug nto-debug
15469@kindex set debug nto-debug
15470When set to on, enables debugging messages specific to the QNX
15471Neutrino support.
15472
15473@item show debug nto-debug
15474@kindex show debug nto-debug
15475Show the current state of QNX Neutrino messages.
15476@end table
15477
a80b95ba
TG
15478@node Darwin
15479@subsection Darwin
15480@cindex Darwin
15481
15482@value{GDBN} provides the following commands specific to the Darwin target:
15483
15484@table @code
15485@item set debug darwin @var{num}
15486@kindex set debug darwin
15487When set to a non zero value, enables debugging messages specific to
15488the Darwin support. Higher values produce more verbose output.
15489
15490@item show debug darwin
15491@kindex show debug darwin
15492Show the current state of Darwin messages.
15493
15494@item set debug mach-o @var{num}
15495@kindex set debug mach-o
15496When set to a non zero value, enables debugging messages while
15497@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
15498file format used on Darwin for object and executable files.) Higher
15499values produce more verbose output. This is a command to diagnose
15500problems internal to @value{GDBN} and should not be needed in normal
15501usage.
15502
15503@item show debug mach-o
15504@kindex show debug mach-o
15505Show the current state of Mach-O file messages.
15506
15507@item set mach-exceptions on
15508@itemx set mach-exceptions off
15509@kindex set mach-exceptions
15510On Darwin, faults are first reported as a Mach exception and are then
15511mapped to a Posix signal. Use this command to turn on trapping of
15512Mach exceptions in the inferior. This might be sometimes useful to
15513better understand the cause of a fault. The default is off.
15514
15515@item show mach-exceptions
15516@kindex show mach-exceptions
15517Show the current state of exceptions trapping.
15518@end table
15519
a64548ea 15520
8e04817f
AC
15521@node Embedded OS
15522@section Embedded Operating Systems
104c1213 15523
8e04817f
AC
15524This section describes configurations involving the debugging of
15525embedded operating systems that are available for several different
15526architectures.
d4f3574e 15527
8e04817f
AC
15528@menu
15529* VxWorks:: Using @value{GDBN} with VxWorks
15530@end menu
104c1213 15531
8e04817f
AC
15532@value{GDBN} includes the ability to debug programs running on
15533various real-time operating systems.
104c1213 15534
8e04817f
AC
15535@node VxWorks
15536@subsection Using @value{GDBN} with VxWorks
104c1213 15537
8e04817f 15538@cindex VxWorks
104c1213 15539
8e04817f 15540@table @code
104c1213 15541
8e04817f
AC
15542@kindex target vxworks
15543@item target vxworks @var{machinename}
15544A VxWorks system, attached via TCP/IP. The argument @var{machinename}
15545is the target system's machine name or IP address.
104c1213 15546
8e04817f 15547@end table
104c1213 15548
8e04817f
AC
15549On VxWorks, @code{load} links @var{filename} dynamically on the
15550current target system as well as adding its symbols in @value{GDBN}.
104c1213 15551
8e04817f
AC
15552@value{GDBN} enables developers to spawn and debug tasks running on networked
15553VxWorks targets from a Unix host. Already-running tasks spawned from
15554the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
15555both the Unix host and on the VxWorks target. The program
15556@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
15557installed with the name @code{vxgdb}, to distinguish it from a
15558@value{GDBN} for debugging programs on the host itself.)
104c1213 15559
8e04817f
AC
15560@table @code
15561@item VxWorks-timeout @var{args}
15562@kindex vxworks-timeout
15563All VxWorks-based targets now support the option @code{vxworks-timeout}.
15564This option is set by the user, and @var{args} represents the number of
15565seconds @value{GDBN} waits for responses to rpc's. You might use this if
15566your VxWorks target is a slow software simulator or is on the far side
15567of a thin network line.
15568@end table
104c1213 15569
8e04817f
AC
15570The following information on connecting to VxWorks was current when
15571this manual was produced; newer releases of VxWorks may use revised
15572procedures.
104c1213 15573
4644b6e3 15574@findex INCLUDE_RDB
8e04817f
AC
15575To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
15576to include the remote debugging interface routines in the VxWorks
15577library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
15578VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
15579kernel. The resulting kernel contains @file{rdb.a}, and spawns the
15580source debugging task @code{tRdbTask} when VxWorks is booted. For more
15581information on configuring and remaking VxWorks, see the manufacturer's
15582manual.
15583@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 15584
8e04817f
AC
15585Once you have included @file{rdb.a} in your VxWorks system image and set
15586your Unix execution search path to find @value{GDBN}, you are ready to
15587run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
15588@code{vxgdb}, depending on your installation).
104c1213 15589
8e04817f 15590@value{GDBN} comes up showing the prompt:
104c1213 15591
474c8240 15592@smallexample
8e04817f 15593(vxgdb)
474c8240 15594@end smallexample
104c1213 15595
8e04817f
AC
15596@menu
15597* VxWorks Connection:: Connecting to VxWorks
15598* VxWorks Download:: VxWorks download
15599* VxWorks Attach:: Running tasks
15600@end menu
104c1213 15601
8e04817f
AC
15602@node VxWorks Connection
15603@subsubsection Connecting to VxWorks
104c1213 15604
8e04817f
AC
15605The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
15606network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 15607
474c8240 15608@smallexample
8e04817f 15609(vxgdb) target vxworks tt
474c8240 15610@end smallexample
104c1213 15611
8e04817f
AC
15612@need 750
15613@value{GDBN} displays messages like these:
104c1213 15614
8e04817f
AC
15615@smallexample
15616Attaching remote machine across net...
15617Connected to tt.
15618@end smallexample
104c1213 15619
8e04817f
AC
15620@need 1000
15621@value{GDBN} then attempts to read the symbol tables of any object modules
15622loaded into the VxWorks target since it was last booted. @value{GDBN} locates
15623these files by searching the directories listed in the command search
79a6e687 15624path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 15625to find an object file, it displays a message such as:
5d161b24 15626
474c8240 15627@smallexample
8e04817f 15628prog.o: No such file or directory.
474c8240 15629@end smallexample
104c1213 15630
8e04817f
AC
15631When this happens, add the appropriate directory to the search path with
15632the @value{GDBN} command @code{path}, and execute the @code{target}
15633command again.
104c1213 15634
8e04817f 15635@node VxWorks Download
79a6e687 15636@subsubsection VxWorks Download
104c1213 15637
8e04817f
AC
15638@cindex download to VxWorks
15639If you have connected to the VxWorks target and you want to debug an
15640object that has not yet been loaded, you can use the @value{GDBN}
15641@code{load} command to download a file from Unix to VxWorks
15642incrementally. The object file given as an argument to the @code{load}
15643command is actually opened twice: first by the VxWorks target in order
15644to download the code, then by @value{GDBN} in order to read the symbol
15645table. This can lead to problems if the current working directories on
15646the two systems differ. If both systems have NFS mounted the same
15647filesystems, you can avoid these problems by using absolute paths.
15648Otherwise, it is simplest to set the working directory on both systems
15649to the directory in which the object file resides, and then to reference
15650the file by its name, without any path. For instance, a program
15651@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
15652and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
15653program, type this on VxWorks:
104c1213 15654
474c8240 15655@smallexample
8e04817f 15656-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 15657@end smallexample
104c1213 15658
8e04817f
AC
15659@noindent
15660Then, in @value{GDBN}, type:
104c1213 15661
474c8240 15662@smallexample
8e04817f
AC
15663(vxgdb) cd @var{hostpath}/vw/demo/rdb
15664(vxgdb) load prog.o
474c8240 15665@end smallexample
104c1213 15666
8e04817f 15667@value{GDBN} displays a response similar to this:
104c1213 15668
8e04817f
AC
15669@smallexample
15670Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
15671@end smallexample
104c1213 15672
8e04817f
AC
15673You can also use the @code{load} command to reload an object module
15674after editing and recompiling the corresponding source file. Note that
15675this makes @value{GDBN} delete all currently-defined breakpoints,
15676auto-displays, and convenience variables, and to clear the value
15677history. (This is necessary in order to preserve the integrity of
15678debugger's data structures that reference the target system's symbol
15679table.)
104c1213 15680
8e04817f 15681@node VxWorks Attach
79a6e687 15682@subsubsection Running Tasks
104c1213
JM
15683
15684@cindex running VxWorks tasks
15685You can also attach to an existing task using the @code{attach} command as
15686follows:
15687
474c8240 15688@smallexample
104c1213 15689(vxgdb) attach @var{task}
474c8240 15690@end smallexample
104c1213
JM
15691
15692@noindent
15693where @var{task} is the VxWorks hexadecimal task ID. The task can be running
15694or suspended when you attach to it. Running tasks are suspended at
15695the time of attachment.
15696
6d2ebf8b 15697@node Embedded Processors
104c1213
JM
15698@section Embedded Processors
15699
15700This section goes into details specific to particular embedded
15701configurations.
15702
c45da7e6
EZ
15703@cindex send command to simulator
15704Whenever a specific embedded processor has a simulator, @value{GDBN}
15705allows to send an arbitrary command to the simulator.
15706
15707@table @code
15708@item sim @var{command}
15709@kindex sim@r{, a command}
15710Send an arbitrary @var{command} string to the simulator. Consult the
15711documentation for the specific simulator in use for information about
15712acceptable commands.
15713@end table
15714
7d86b5d5 15715
104c1213 15716@menu
c45da7e6 15717* ARM:: ARM RDI
172c2a43 15718* M32R/D:: Renesas M32R/D
104c1213 15719* M68K:: Motorola M68K
104c1213 15720* MIPS Embedded:: MIPS Embedded
a37295f9 15721* OpenRISC 1000:: OpenRisc 1000
104c1213 15722* PA:: HP PA Embedded
4acd40f3 15723* PowerPC Embedded:: PowerPC Embedded
104c1213
JM
15724* Sparclet:: Tsqware Sparclet
15725* Sparclite:: Fujitsu Sparclite
104c1213 15726* Z8000:: Zilog Z8000
a64548ea
EZ
15727* AVR:: Atmel AVR
15728* CRIS:: CRIS
15729* Super-H:: Renesas Super-H
104c1213
JM
15730@end menu
15731
6d2ebf8b 15732@node ARM
104c1213 15733@subsection ARM
c45da7e6 15734@cindex ARM RDI
104c1213
JM
15735
15736@table @code
8e04817f
AC
15737@kindex target rdi
15738@item target rdi @var{dev}
15739ARM Angel monitor, via RDI library interface to ADP protocol. You may
15740use this target to communicate with both boards running the Angel
15741monitor, or with the EmbeddedICE JTAG debug device.
15742
15743@kindex target rdp
15744@item target rdp @var{dev}
15745ARM Demon monitor.
15746
15747@end table
15748
e2f4edfd
EZ
15749@value{GDBN} provides the following ARM-specific commands:
15750
15751@table @code
15752@item set arm disassembler
15753@kindex set arm
15754This commands selects from a list of disassembly styles. The
15755@code{"std"} style is the standard style.
15756
15757@item show arm disassembler
15758@kindex show arm
15759Show the current disassembly style.
15760
15761@item set arm apcs32
15762@cindex ARM 32-bit mode
15763This command toggles ARM operation mode between 32-bit and 26-bit.
15764
15765@item show arm apcs32
15766Display the current usage of the ARM 32-bit mode.
15767
15768@item set arm fpu @var{fputype}
15769This command sets the ARM floating-point unit (FPU) type. The
15770argument @var{fputype} can be one of these:
15771
15772@table @code
15773@item auto
15774Determine the FPU type by querying the OS ABI.
15775@item softfpa
15776Software FPU, with mixed-endian doubles on little-endian ARM
15777processors.
15778@item fpa
15779GCC-compiled FPA co-processor.
15780@item softvfp
15781Software FPU with pure-endian doubles.
15782@item vfp
15783VFP co-processor.
15784@end table
15785
15786@item show arm fpu
15787Show the current type of the FPU.
15788
15789@item set arm abi
15790This command forces @value{GDBN} to use the specified ABI.
15791
15792@item show arm abi
15793Show the currently used ABI.
15794
0428b8f5
DJ
15795@item set arm fallback-mode (arm|thumb|auto)
15796@value{GDBN} uses the symbol table, when available, to determine
15797whether instructions are ARM or Thumb. This command controls
15798@value{GDBN}'s default behavior when the symbol table is not
15799available. The default is @samp{auto}, which causes @value{GDBN} to
15800use the current execution mode (from the @code{T} bit in the @code{CPSR}
15801register).
15802
15803@item show arm fallback-mode
15804Show the current fallback instruction mode.
15805
15806@item set arm force-mode (arm|thumb|auto)
15807This command overrides use of the symbol table to determine whether
15808instructions are ARM or Thumb. The default is @samp{auto}, which
15809causes @value{GDBN} to use the symbol table and then the setting
15810of @samp{set arm fallback-mode}.
15811
15812@item show arm force-mode
15813Show the current forced instruction mode.
15814
e2f4edfd
EZ
15815@item set debug arm
15816Toggle whether to display ARM-specific debugging messages from the ARM
15817target support subsystem.
15818
15819@item show debug arm
15820Show whether ARM-specific debugging messages are enabled.
15821@end table
15822
c45da7e6
EZ
15823The following commands are available when an ARM target is debugged
15824using the RDI interface:
15825
15826@table @code
15827@item rdilogfile @r{[}@var{file}@r{]}
15828@kindex rdilogfile
15829@cindex ADP (Angel Debugger Protocol) logging
15830Set the filename for the ADP (Angel Debugger Protocol) packet log.
15831With an argument, sets the log file to the specified @var{file}. With
15832no argument, show the current log file name. The default log file is
15833@file{rdi.log}.
15834
15835@item rdilogenable @r{[}@var{arg}@r{]}
15836@kindex rdilogenable
15837Control logging of ADP packets. With an argument of 1 or @code{"yes"}
15838enables logging, with an argument 0 or @code{"no"} disables it. With
15839no arguments displays the current setting. When logging is enabled,
15840ADP packets exchanged between @value{GDBN} and the RDI target device
15841are logged to a file.
15842
15843@item set rdiromatzero
15844@kindex set rdiromatzero
15845@cindex ROM at zero address, RDI
15846Tell @value{GDBN} whether the target has ROM at address 0. If on,
15847vector catching is disabled, so that zero address can be used. If off
15848(the default), vector catching is enabled. For this command to take
15849effect, it needs to be invoked prior to the @code{target rdi} command.
15850
15851@item show rdiromatzero
15852@kindex show rdiromatzero
15853Show the current setting of ROM at zero address.
15854
15855@item set rdiheartbeat
15856@kindex set rdiheartbeat
15857@cindex RDI heartbeat
15858Enable or disable RDI heartbeat packets. It is not recommended to
15859turn on this option, since it confuses ARM and EPI JTAG interface, as
15860well as the Angel monitor.
15861
15862@item show rdiheartbeat
15863@kindex show rdiheartbeat
15864Show the setting of RDI heartbeat packets.
15865@end table
15866
e2f4edfd 15867
8e04817f 15868@node M32R/D
ba04e063 15869@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
15870
15871@table @code
8e04817f
AC
15872@kindex target m32r
15873@item target m32r @var{dev}
172c2a43 15874Renesas M32R/D ROM monitor.
8e04817f 15875
fb3e19c0
KI
15876@kindex target m32rsdi
15877@item target m32rsdi @var{dev}
15878Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
15879@end table
15880
15881The following @value{GDBN} commands are specific to the M32R monitor:
15882
15883@table @code
15884@item set download-path @var{path}
15885@kindex set download-path
15886@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 15887Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
15888
15889@item show download-path
15890@kindex show download-path
15891Show the default path for downloadable @sc{srec} files.
fb3e19c0 15892
721c2651
EZ
15893@item set board-address @var{addr}
15894@kindex set board-address
15895@cindex M32-EVA target board address
15896Set the IP address for the M32R-EVA target board.
15897
15898@item show board-address
15899@kindex show board-address
15900Show the current IP address of the target board.
15901
15902@item set server-address @var{addr}
15903@kindex set server-address
15904@cindex download server address (M32R)
15905Set the IP address for the download server, which is the @value{GDBN}'s
15906host machine.
15907
15908@item show server-address
15909@kindex show server-address
15910Display the IP address of the download server.
15911
15912@item upload @r{[}@var{file}@r{]}
15913@kindex upload@r{, M32R}
15914Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
15915upload capability. If no @var{file} argument is given, the current
15916executable file is uploaded.
15917
15918@item tload @r{[}@var{file}@r{]}
15919@kindex tload@r{, M32R}
15920Test the @code{upload} command.
8e04817f
AC
15921@end table
15922
ba04e063
EZ
15923The following commands are available for M32R/SDI:
15924
15925@table @code
15926@item sdireset
15927@kindex sdireset
15928@cindex reset SDI connection, M32R
15929This command resets the SDI connection.
15930
15931@item sdistatus
15932@kindex sdistatus
15933This command shows the SDI connection status.
15934
15935@item debug_chaos
15936@kindex debug_chaos
15937@cindex M32R/Chaos debugging
15938Instructs the remote that M32R/Chaos debugging is to be used.
15939
15940@item use_debug_dma
15941@kindex use_debug_dma
15942Instructs the remote to use the DEBUG_DMA method of accessing memory.
15943
15944@item use_mon_code
15945@kindex use_mon_code
15946Instructs the remote to use the MON_CODE method of accessing memory.
15947
15948@item use_ib_break
15949@kindex use_ib_break
15950Instructs the remote to set breakpoints by IB break.
15951
15952@item use_dbt_break
15953@kindex use_dbt_break
15954Instructs the remote to set breakpoints by DBT.
15955@end table
15956
8e04817f
AC
15957@node M68K
15958@subsection M68k
15959
7ce59000
DJ
15960The Motorola m68k configuration includes ColdFire support, and a
15961target command for the following ROM monitor.
8e04817f
AC
15962
15963@table @code
15964
8e04817f
AC
15965@kindex target dbug
15966@item target dbug @var{dev}
15967dBUG ROM monitor for Motorola ColdFire.
15968
8e04817f
AC
15969@end table
15970
8e04817f
AC
15971@node MIPS Embedded
15972@subsection MIPS Embedded
15973
15974@cindex MIPS boards
15975@value{GDBN} can use the MIPS remote debugging protocol to talk to a
15976MIPS board attached to a serial line. This is available when
15977you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 15978
8e04817f
AC
15979@need 1000
15980Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 15981
8e04817f
AC
15982@table @code
15983@item target mips @var{port}
15984@kindex target mips @var{port}
15985To run a program on the board, start up @code{@value{GDBP}} with the
15986name of your program as the argument. To connect to the board, use the
15987command @samp{target mips @var{port}}, where @var{port} is the name of
15988the serial port connected to the board. If the program has not already
15989been downloaded to the board, you may use the @code{load} command to
15990download it. You can then use all the usual @value{GDBN} commands.
104c1213 15991
8e04817f
AC
15992For example, this sequence connects to the target board through a serial
15993port, and loads and runs a program called @var{prog} through the
15994debugger:
104c1213 15995
474c8240 15996@smallexample
8e04817f
AC
15997host$ @value{GDBP} @var{prog}
15998@value{GDBN} is free software and @dots{}
15999(@value{GDBP}) target mips /dev/ttyb
16000(@value{GDBP}) load @var{prog}
16001(@value{GDBP}) run
474c8240 16002@end smallexample
104c1213 16003
8e04817f
AC
16004@item target mips @var{hostname}:@var{portnumber}
16005On some @value{GDBN} host configurations, you can specify a TCP
16006connection (for instance, to a serial line managed by a terminal
16007concentrator) instead of a serial port, using the syntax
16008@samp{@var{hostname}:@var{portnumber}}.
104c1213 16009
8e04817f
AC
16010@item target pmon @var{port}
16011@kindex target pmon @var{port}
16012PMON ROM monitor.
104c1213 16013
8e04817f
AC
16014@item target ddb @var{port}
16015@kindex target ddb @var{port}
16016NEC's DDB variant of PMON for Vr4300.
104c1213 16017
8e04817f
AC
16018@item target lsi @var{port}
16019@kindex target lsi @var{port}
16020LSI variant of PMON.
104c1213 16021
8e04817f
AC
16022@kindex target r3900
16023@item target r3900 @var{dev}
16024Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 16025
8e04817f
AC
16026@kindex target array
16027@item target array @var{dev}
16028Array Tech LSI33K RAID controller board.
104c1213 16029
8e04817f 16030@end table
104c1213 16031
104c1213 16032
8e04817f
AC
16033@noindent
16034@value{GDBN} also supports these special commands for MIPS targets:
104c1213 16035
8e04817f 16036@table @code
8e04817f
AC
16037@item set mipsfpu double
16038@itemx set mipsfpu single
16039@itemx set mipsfpu none
a64548ea 16040@itemx set mipsfpu auto
8e04817f
AC
16041@itemx show mipsfpu
16042@kindex set mipsfpu
16043@kindex show mipsfpu
16044@cindex MIPS remote floating point
16045@cindex floating point, MIPS remote
16046If your target board does not support the MIPS floating point
16047coprocessor, you should use the command @samp{set mipsfpu none} (if you
16048need this, you may wish to put the command in your @value{GDBN} init
16049file). This tells @value{GDBN} how to find the return value of
16050functions which return floating point values. It also allows
16051@value{GDBN} to avoid saving the floating point registers when calling
16052functions on the board. If you are using a floating point coprocessor
16053with only single precision floating point support, as on the @sc{r4650}
16054processor, use the command @samp{set mipsfpu single}. The default
16055double precision floating point coprocessor may be selected using
16056@samp{set mipsfpu double}.
104c1213 16057
8e04817f
AC
16058In previous versions the only choices were double precision or no
16059floating point, so @samp{set mipsfpu on} will select double precision
16060and @samp{set mipsfpu off} will select no floating point.
104c1213 16061
8e04817f
AC
16062As usual, you can inquire about the @code{mipsfpu} variable with
16063@samp{show mipsfpu}.
104c1213 16064
8e04817f
AC
16065@item set timeout @var{seconds}
16066@itemx set retransmit-timeout @var{seconds}
16067@itemx show timeout
16068@itemx show retransmit-timeout
16069@cindex @code{timeout}, MIPS protocol
16070@cindex @code{retransmit-timeout}, MIPS protocol
16071@kindex set timeout
16072@kindex show timeout
16073@kindex set retransmit-timeout
16074@kindex show retransmit-timeout
16075You can control the timeout used while waiting for a packet, in the MIPS
16076remote protocol, with the @code{set timeout @var{seconds}} command. The
16077default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 16078waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
16079retransmit-timeout @var{seconds}} command. The default is 3 seconds.
16080You can inspect both values with @code{show timeout} and @code{show
16081retransmit-timeout}. (These commands are @emph{only} available when
16082@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 16083
8e04817f
AC
16084The timeout set by @code{set timeout} does not apply when @value{GDBN}
16085is waiting for your program to stop. In that case, @value{GDBN} waits
16086forever because it has no way of knowing how long the program is going
16087to run before stopping.
ba04e063
EZ
16088
16089@item set syn-garbage-limit @var{num}
16090@kindex set syn-garbage-limit@r{, MIPS remote}
16091@cindex synchronize with remote MIPS target
16092Limit the maximum number of characters @value{GDBN} should ignore when
16093it tries to synchronize with the remote target. The default is 10
16094characters. Setting the limit to -1 means there's no limit.
16095
16096@item show syn-garbage-limit
16097@kindex show syn-garbage-limit@r{, MIPS remote}
16098Show the current limit on the number of characters to ignore when
16099trying to synchronize with the remote system.
16100
16101@item set monitor-prompt @var{prompt}
16102@kindex set monitor-prompt@r{, MIPS remote}
16103@cindex remote monitor prompt
16104Tell @value{GDBN} to expect the specified @var{prompt} string from the
16105remote monitor. The default depends on the target:
16106@table @asis
16107@item pmon target
16108@samp{PMON}
16109@item ddb target
16110@samp{NEC010}
16111@item lsi target
16112@samp{PMON>}
16113@end table
16114
16115@item show monitor-prompt
16116@kindex show monitor-prompt@r{, MIPS remote}
16117Show the current strings @value{GDBN} expects as the prompt from the
16118remote monitor.
16119
16120@item set monitor-warnings
16121@kindex set monitor-warnings@r{, MIPS remote}
16122Enable or disable monitor warnings about hardware breakpoints. This
16123has effect only for the @code{lsi} target. When on, @value{GDBN} will
16124display warning messages whose codes are returned by the @code{lsi}
16125PMON monitor for breakpoint commands.
16126
16127@item show monitor-warnings
16128@kindex show monitor-warnings@r{, MIPS remote}
16129Show the current setting of printing monitor warnings.
16130
16131@item pmon @var{command}
16132@kindex pmon@r{, MIPS remote}
16133@cindex send PMON command
16134This command allows sending an arbitrary @var{command} string to the
16135monitor. The monitor must be in debug mode for this to work.
8e04817f 16136@end table
104c1213 16137
a37295f9
MM
16138@node OpenRISC 1000
16139@subsection OpenRISC 1000
16140@cindex OpenRISC 1000
16141
16142@cindex or1k boards
16143See OR1k Architecture document (@uref{www.opencores.org}) for more information
16144about platform and commands.
16145
16146@table @code
16147
16148@kindex target jtag
16149@item target jtag jtag://@var{host}:@var{port}
16150
16151Connects to remote JTAG server.
16152JTAG remote server can be either an or1ksim or JTAG server,
16153connected via parallel port to the board.
16154
16155Example: @code{target jtag jtag://localhost:9999}
16156
16157@kindex or1ksim
16158@item or1ksim @var{command}
16159If connected to @code{or1ksim} OpenRISC 1000 Architectural
16160Simulator, proprietary commands can be executed.
16161
16162@kindex info or1k spr
16163@item info or1k spr
16164Displays spr groups.
16165
16166@item info or1k spr @var{group}
16167@itemx info or1k spr @var{groupno}
16168Displays register names in selected group.
16169
16170@item info or1k spr @var{group} @var{register}
16171@itemx info or1k spr @var{register}
16172@itemx info or1k spr @var{groupno} @var{registerno}
16173@itemx info or1k spr @var{registerno}
16174Shows information about specified spr register.
16175
16176@kindex spr
16177@item spr @var{group} @var{register} @var{value}
16178@itemx spr @var{register @var{value}}
16179@itemx spr @var{groupno} @var{registerno @var{value}}
16180@itemx spr @var{registerno @var{value}}
16181Writes @var{value} to specified spr register.
16182@end table
16183
16184Some implementations of OpenRISC 1000 Architecture also have hardware trace.
16185It is very similar to @value{GDBN} trace, except it does not interfere with normal
16186program execution and is thus much faster. Hardware breakpoints/watchpoint
16187triggers can be set using:
16188@table @code
16189@item $LEA/$LDATA
16190Load effective address/data
16191@item $SEA/$SDATA
16192Store effective address/data
16193@item $AEA/$ADATA
16194Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
16195@item $FETCH
16196Fetch data
16197@end table
16198
16199When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
16200@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
16201
16202@code{htrace} commands:
16203@cindex OpenRISC 1000 htrace
16204@table @code
16205@kindex hwatch
16206@item hwatch @var{conditional}
d3e8051b 16207Set hardware watchpoint on combination of Load/Store Effective Address(es)
a37295f9
MM
16208or Data. For example:
16209
16210@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
16211
16212@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
16213
4644b6e3 16214@kindex htrace
a37295f9
MM
16215@item htrace info
16216Display information about current HW trace configuration.
16217
a37295f9
MM
16218@item htrace trigger @var{conditional}
16219Set starting criteria for HW trace.
16220
a37295f9
MM
16221@item htrace qualifier @var{conditional}
16222Set acquisition qualifier for HW trace.
16223
a37295f9
MM
16224@item htrace stop @var{conditional}
16225Set HW trace stopping criteria.
16226
f153cc92 16227@item htrace record [@var{data}]*
a37295f9
MM
16228Selects the data to be recorded, when qualifier is met and HW trace was
16229triggered.
16230
a37295f9 16231@item htrace enable
a37295f9
MM
16232@itemx htrace disable
16233Enables/disables the HW trace.
16234
f153cc92 16235@item htrace rewind [@var{filename}]
a37295f9
MM
16236Clears currently recorded trace data.
16237
16238If filename is specified, new trace file is made and any newly collected data
16239will be written there.
16240
f153cc92 16241@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
16242Prints trace buffer, using current record configuration.
16243
a37295f9
MM
16244@item htrace mode continuous
16245Set continuous trace mode.
16246
a37295f9
MM
16247@item htrace mode suspend
16248Set suspend trace mode.
16249
16250@end table
16251
4acd40f3
TJB
16252@node PowerPC Embedded
16253@subsection PowerPC Embedded
104c1213 16254
55eddb0f
DJ
16255@value{GDBN} provides the following PowerPC-specific commands:
16256
104c1213 16257@table @code
55eddb0f
DJ
16258@kindex set powerpc
16259@item set powerpc soft-float
16260@itemx show powerpc soft-float
16261Force @value{GDBN} to use (or not use) a software floating point calling
16262convention. By default, @value{GDBN} selects the calling convention based
16263on the selected architecture and the provided executable file.
16264
16265@item set powerpc vector-abi
16266@itemx show powerpc vector-abi
16267Force @value{GDBN} to use the specified calling convention for vector
16268arguments and return values. The valid options are @samp{auto};
16269@samp{generic}, to avoid vector registers even if they are present;
16270@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
16271registers. By default, @value{GDBN} selects the calling convention
16272based on the selected architecture and the provided executable file.
16273
8e04817f
AC
16274@kindex target dink32
16275@item target dink32 @var{dev}
16276DINK32 ROM monitor.
104c1213 16277
8e04817f
AC
16278@kindex target ppcbug
16279@item target ppcbug @var{dev}
16280@kindex target ppcbug1
16281@item target ppcbug1 @var{dev}
16282PPCBUG ROM monitor for PowerPC.
104c1213 16283
8e04817f
AC
16284@kindex target sds
16285@item target sds @var{dev}
16286SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 16287@end table
8e04817f 16288
c45da7e6 16289@cindex SDS protocol
d52fb0e9 16290The following commands specific to the SDS protocol are supported
55eddb0f 16291by @value{GDBN}:
c45da7e6
EZ
16292
16293@table @code
16294@item set sdstimeout @var{nsec}
16295@kindex set sdstimeout
16296Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
16297default is 2 seconds.
16298
16299@item show sdstimeout
16300@kindex show sdstimeout
16301Show the current value of the SDS timeout.
16302
16303@item sds @var{command}
16304@kindex sds@r{, a command}
16305Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
16306@end table
16307
c45da7e6 16308
8e04817f
AC
16309@node PA
16310@subsection HP PA Embedded
104c1213
JM
16311
16312@table @code
16313
8e04817f
AC
16314@kindex target op50n
16315@item target op50n @var{dev}
16316OP50N monitor, running on an OKI HPPA board.
16317
16318@kindex target w89k
16319@item target w89k @var{dev}
16320W89K monitor, running on a Winbond HPPA board.
104c1213
JM
16321
16322@end table
16323
8e04817f
AC
16324@node Sparclet
16325@subsection Tsqware Sparclet
104c1213 16326
8e04817f
AC
16327@cindex Sparclet
16328
16329@value{GDBN} enables developers to debug tasks running on
16330Sparclet targets from a Unix host.
16331@value{GDBN} uses code that runs on
16332both the Unix host and on the Sparclet target. The program
16333@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 16334
8e04817f
AC
16335@table @code
16336@item remotetimeout @var{args}
16337@kindex remotetimeout
16338@value{GDBN} supports the option @code{remotetimeout}.
16339This option is set by the user, and @var{args} represents the number of
16340seconds @value{GDBN} waits for responses.
104c1213
JM
16341@end table
16342
8e04817f
AC
16343@cindex compiling, on Sparclet
16344When compiling for debugging, include the options @samp{-g} to get debug
16345information and @samp{-Ttext} to relocate the program to where you wish to
16346load it on the target. You may also want to add the options @samp{-n} or
16347@samp{-N} in order to reduce the size of the sections. Example:
104c1213 16348
474c8240 16349@smallexample
8e04817f 16350sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 16351@end smallexample
104c1213 16352
8e04817f 16353You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 16354
474c8240 16355@smallexample
8e04817f 16356sparclet-aout-objdump --headers --syms prog
474c8240 16357@end smallexample
104c1213 16358
8e04817f
AC
16359@cindex running, on Sparclet
16360Once you have set
16361your Unix execution search path to find @value{GDBN}, you are ready to
16362run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
16363(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 16364
8e04817f
AC
16365@value{GDBN} comes up showing the prompt:
16366
474c8240 16367@smallexample
8e04817f 16368(gdbslet)
474c8240 16369@end smallexample
104c1213
JM
16370
16371@menu
8e04817f
AC
16372* Sparclet File:: Setting the file to debug
16373* Sparclet Connection:: Connecting to Sparclet
16374* Sparclet Download:: Sparclet download
16375* Sparclet Execution:: Running and debugging
104c1213
JM
16376@end menu
16377
8e04817f 16378@node Sparclet File
79a6e687 16379@subsubsection Setting File to Debug
104c1213 16380
8e04817f 16381The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 16382
474c8240 16383@smallexample
8e04817f 16384(gdbslet) file prog
474c8240 16385@end smallexample
104c1213 16386
8e04817f
AC
16387@need 1000
16388@value{GDBN} then attempts to read the symbol table of @file{prog}.
16389@value{GDBN} locates
16390the file by searching the directories listed in the command search
16391path.
12c27660 16392If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
16393files will be searched as well.
16394@value{GDBN} locates
16395the source files by searching the directories listed in the directory search
79a6e687 16396path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
16397If it fails
16398to find a file, it displays a message such as:
104c1213 16399
474c8240 16400@smallexample
8e04817f 16401prog: No such file or directory.
474c8240 16402@end smallexample
104c1213 16403
8e04817f
AC
16404When this happens, add the appropriate directories to the search paths with
16405the @value{GDBN} commands @code{path} and @code{dir}, and execute the
16406@code{target} command again.
104c1213 16407
8e04817f
AC
16408@node Sparclet Connection
16409@subsubsection Connecting to Sparclet
104c1213 16410
8e04817f
AC
16411The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
16412To connect to a target on serial port ``@code{ttya}'', type:
104c1213 16413
474c8240 16414@smallexample
8e04817f
AC
16415(gdbslet) target sparclet /dev/ttya
16416Remote target sparclet connected to /dev/ttya
16417main () at ../prog.c:3
474c8240 16418@end smallexample
104c1213 16419
8e04817f
AC
16420@need 750
16421@value{GDBN} displays messages like these:
104c1213 16422
474c8240 16423@smallexample
8e04817f 16424Connected to ttya.
474c8240 16425@end smallexample
104c1213 16426
8e04817f 16427@node Sparclet Download
79a6e687 16428@subsubsection Sparclet Download
104c1213 16429
8e04817f
AC
16430@cindex download to Sparclet
16431Once connected to the Sparclet target,
16432you can use the @value{GDBN}
16433@code{load} command to download the file from the host to the target.
16434The file name and load offset should be given as arguments to the @code{load}
16435command.
16436Since the file format is aout, the program must be loaded to the starting
16437address. You can use @code{objdump} to find out what this value is. The load
16438offset is an offset which is added to the VMA (virtual memory address)
16439of each of the file's sections.
16440For instance, if the program
16441@file{prog} was linked to text address 0x1201000, with data at 0x12010160
16442and bss at 0x12010170, in @value{GDBN}, type:
104c1213 16443
474c8240 16444@smallexample
8e04817f
AC
16445(gdbslet) load prog 0x12010000
16446Loading section .text, size 0xdb0 vma 0x12010000
474c8240 16447@end smallexample
104c1213 16448
8e04817f
AC
16449If the code is loaded at a different address then what the program was linked
16450to, you may need to use the @code{section} and @code{add-symbol-file} commands
16451to tell @value{GDBN} where to map the symbol table.
16452
16453@node Sparclet Execution
79a6e687 16454@subsubsection Running and Debugging
8e04817f
AC
16455
16456@cindex running and debugging Sparclet programs
16457You can now begin debugging the task using @value{GDBN}'s execution control
16458commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
16459manual for the list of commands.
16460
474c8240 16461@smallexample
8e04817f
AC
16462(gdbslet) b main
16463Breakpoint 1 at 0x12010000: file prog.c, line 3.
16464(gdbslet) run
16465Starting program: prog
16466Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
164673 char *symarg = 0;
16468(gdbslet) step
164694 char *execarg = "hello!";
16470(gdbslet)
474c8240 16471@end smallexample
8e04817f
AC
16472
16473@node Sparclite
16474@subsection Fujitsu Sparclite
104c1213
JM
16475
16476@table @code
16477
8e04817f
AC
16478@kindex target sparclite
16479@item target sparclite @var{dev}
16480Fujitsu sparclite boards, used only for the purpose of loading.
16481You must use an additional command to debug the program.
16482For example: target remote @var{dev} using @value{GDBN} standard
16483remote protocol.
104c1213
JM
16484
16485@end table
16486
8e04817f
AC
16487@node Z8000
16488@subsection Zilog Z8000
104c1213 16489
8e04817f
AC
16490@cindex Z8000
16491@cindex simulator, Z8000
16492@cindex Zilog Z8000 simulator
104c1213 16493
8e04817f
AC
16494When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
16495a Z8000 simulator.
16496
16497For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
16498unsegmented variant of the Z8000 architecture) or the Z8001 (the
16499segmented variant). The simulator recognizes which architecture is
16500appropriate by inspecting the object code.
104c1213 16501
8e04817f
AC
16502@table @code
16503@item target sim @var{args}
16504@kindex sim
16505@kindex target sim@r{, with Z8000}
16506Debug programs on a simulated CPU. If the simulator supports setup
16507options, specify them via @var{args}.
104c1213
JM
16508@end table
16509
8e04817f
AC
16510@noindent
16511After specifying this target, you can debug programs for the simulated
16512CPU in the same style as programs for your host computer; use the
16513@code{file} command to load a new program image, the @code{run} command
16514to run your program, and so on.
16515
16516As well as making available all the usual machine registers
16517(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
16518additional items of information as specially named registers:
104c1213
JM
16519
16520@table @code
16521
8e04817f
AC
16522@item cycles
16523Counts clock-ticks in the simulator.
104c1213 16524
8e04817f
AC
16525@item insts
16526Counts instructions run in the simulator.
104c1213 16527
8e04817f
AC
16528@item time
16529Execution time in 60ths of a second.
104c1213 16530
8e04817f 16531@end table
104c1213 16532
8e04817f
AC
16533You can refer to these values in @value{GDBN} expressions with the usual
16534conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
16535conditional breakpoint that suspends only after at least 5000
16536simulated clock ticks.
104c1213 16537
a64548ea
EZ
16538@node AVR
16539@subsection Atmel AVR
16540@cindex AVR
16541
16542When configured for debugging the Atmel AVR, @value{GDBN} supports the
16543following AVR-specific commands:
16544
16545@table @code
16546@item info io_registers
16547@kindex info io_registers@r{, AVR}
16548@cindex I/O registers (Atmel AVR)
16549This command displays information about the AVR I/O registers. For
16550each register, @value{GDBN} prints its number and value.
16551@end table
16552
16553@node CRIS
16554@subsection CRIS
16555@cindex CRIS
16556
16557When configured for debugging CRIS, @value{GDBN} provides the
16558following CRIS-specific commands:
16559
16560@table @code
16561@item set cris-version @var{ver}
16562@cindex CRIS version
e22e55c9
OF
16563Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
16564The CRIS version affects register names and sizes. This command is useful in
16565case autodetection of the CRIS version fails.
a64548ea
EZ
16566
16567@item show cris-version
16568Show the current CRIS version.
16569
16570@item set cris-dwarf2-cfi
16571@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
16572Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
16573Change to @samp{off} when using @code{gcc-cris} whose version is below
16574@code{R59}.
a64548ea
EZ
16575
16576@item show cris-dwarf2-cfi
16577Show the current state of using DWARF-2 CFI.
e22e55c9
OF
16578
16579@item set cris-mode @var{mode}
16580@cindex CRIS mode
16581Set the current CRIS mode to @var{mode}. It should only be changed when
16582debugging in guru mode, in which case it should be set to
16583@samp{guru} (the default is @samp{normal}).
16584
16585@item show cris-mode
16586Show the current CRIS mode.
a64548ea
EZ
16587@end table
16588
16589@node Super-H
16590@subsection Renesas Super-H
16591@cindex Super-H
16592
16593For the Renesas Super-H processor, @value{GDBN} provides these
16594commands:
16595
16596@table @code
16597@item regs
16598@kindex regs@r{, Super-H}
16599Show the values of all Super-H registers.
c055b101
CV
16600
16601@item set sh calling-convention @var{convention}
16602@kindex set sh calling-convention
16603Set the calling-convention used when calling functions from @value{GDBN}.
16604Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
16605With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
16606convention. If the DWARF-2 information of the called function specifies
16607that the function follows the Renesas calling convention, the function
16608is called using the Renesas calling convention. If the calling convention
16609is set to @samp{renesas}, the Renesas calling convention is always used,
16610regardless of the DWARF-2 information. This can be used to override the
16611default of @samp{gcc} if debug information is missing, or the compiler
16612does not emit the DWARF-2 calling convention entry for a function.
16613
16614@item show sh calling-convention
16615@kindex show sh calling-convention
16616Show the current calling convention setting.
16617
a64548ea
EZ
16618@end table
16619
16620
8e04817f
AC
16621@node Architectures
16622@section Architectures
104c1213 16623
8e04817f
AC
16624This section describes characteristics of architectures that affect
16625all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 16626
8e04817f 16627@menu
9c16f35a 16628* i386::
8e04817f
AC
16629* A29K::
16630* Alpha::
16631* MIPS::
a64548ea 16632* HPPA:: HP PA architecture
23d964e7 16633* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 16634* PowerPC::
8e04817f 16635@end menu
104c1213 16636
9c16f35a 16637@node i386
db2e3e2e 16638@subsection x86 Architecture-specific Issues
9c16f35a
EZ
16639
16640@table @code
16641@item set struct-convention @var{mode}
16642@kindex set struct-convention
16643@cindex struct return convention
16644@cindex struct/union returned in registers
16645Set the convention used by the inferior to return @code{struct}s and
16646@code{union}s from functions to @var{mode}. Possible values of
16647@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
16648default). @code{"default"} or @code{"pcc"} means that @code{struct}s
16649are returned on the stack, while @code{"reg"} means that a
16650@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
16651be returned in a register.
16652
16653@item show struct-convention
16654@kindex show struct-convention
16655Show the current setting of the convention to return @code{struct}s
16656from functions.
16657@end table
16658
8e04817f
AC
16659@node A29K
16660@subsection A29K
104c1213
JM
16661
16662@table @code
104c1213 16663
8e04817f
AC
16664@kindex set rstack_high_address
16665@cindex AMD 29K register stack
16666@cindex register stack, AMD29K
16667@item set rstack_high_address @var{address}
16668On AMD 29000 family processors, registers are saved in a separate
16669@dfn{register stack}. There is no way for @value{GDBN} to determine the
16670extent of this stack. Normally, @value{GDBN} just assumes that the
16671stack is ``large enough''. This may result in @value{GDBN} referencing
16672memory locations that do not exist. If necessary, you can get around
16673this problem by specifying the ending address of the register stack with
16674the @code{set rstack_high_address} command. The argument should be an
16675address, which you probably want to precede with @samp{0x} to specify in
16676hexadecimal.
104c1213 16677
8e04817f
AC
16678@kindex show rstack_high_address
16679@item show rstack_high_address
16680Display the current limit of the register stack, on AMD 29000 family
16681processors.
104c1213 16682
8e04817f 16683@end table
104c1213 16684
8e04817f
AC
16685@node Alpha
16686@subsection Alpha
104c1213 16687
8e04817f 16688See the following section.
104c1213 16689
8e04817f
AC
16690@node MIPS
16691@subsection MIPS
104c1213 16692
8e04817f
AC
16693@cindex stack on Alpha
16694@cindex stack on MIPS
16695@cindex Alpha stack
16696@cindex MIPS stack
16697Alpha- and MIPS-based computers use an unusual stack frame, which
16698sometimes requires @value{GDBN} to search backward in the object code to
16699find the beginning of a function.
104c1213 16700
8e04817f
AC
16701@cindex response time, MIPS debugging
16702To improve response time (especially for embedded applications, where
16703@value{GDBN} may be restricted to a slow serial line for this search)
16704you may want to limit the size of this search, using one of these
16705commands:
104c1213 16706
8e04817f
AC
16707@table @code
16708@cindex @code{heuristic-fence-post} (Alpha, MIPS)
16709@item set heuristic-fence-post @var{limit}
16710Restrict @value{GDBN} to examining at most @var{limit} bytes in its
16711search for the beginning of a function. A value of @var{0} (the
16712default) means there is no limit. However, except for @var{0}, the
16713larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
16714and therefore the longer it takes to run. You should only need to use
16715this command when debugging a stripped executable.
104c1213 16716
8e04817f
AC
16717@item show heuristic-fence-post
16718Display the current limit.
16719@end table
104c1213
JM
16720
16721@noindent
8e04817f
AC
16722These commands are available @emph{only} when @value{GDBN} is configured
16723for debugging programs on Alpha or MIPS processors.
104c1213 16724
a64548ea
EZ
16725Several MIPS-specific commands are available when debugging MIPS
16726programs:
16727
16728@table @code
a64548ea
EZ
16729@item set mips abi @var{arg}
16730@kindex set mips abi
16731@cindex set ABI for MIPS
16732Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
16733values of @var{arg} are:
16734
16735@table @samp
16736@item auto
16737The default ABI associated with the current binary (this is the
16738default).
16739@item o32
16740@item o64
16741@item n32
16742@item n64
16743@item eabi32
16744@item eabi64
16745@item auto
16746@end table
16747
16748@item show mips abi
16749@kindex show mips abi
16750Show the MIPS ABI used by @value{GDBN} to debug the inferior.
16751
16752@item set mipsfpu
16753@itemx show mipsfpu
16754@xref{MIPS Embedded, set mipsfpu}.
16755
16756@item set mips mask-address @var{arg}
16757@kindex set mips mask-address
16758@cindex MIPS addresses, masking
16759This command determines whether the most-significant 32 bits of 64-bit
16760MIPS addresses are masked off. The argument @var{arg} can be
16761@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
16762setting, which lets @value{GDBN} determine the correct value.
16763
16764@item show mips mask-address
16765@kindex show mips mask-address
16766Show whether the upper 32 bits of MIPS addresses are masked off or
16767not.
16768
16769@item set remote-mips64-transfers-32bit-regs
16770@kindex set remote-mips64-transfers-32bit-regs
16771This command controls compatibility with 64-bit MIPS targets that
16772transfer data in 32-bit quantities. If you have an old MIPS 64 target
16773that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
16774and 64 bits for other registers, set this option to @samp{on}.
16775
16776@item show remote-mips64-transfers-32bit-regs
16777@kindex show remote-mips64-transfers-32bit-regs
16778Show the current setting of compatibility with older MIPS 64 targets.
16779
16780@item set debug mips
16781@kindex set debug mips
16782This command turns on and off debugging messages for the MIPS-specific
16783target code in @value{GDBN}.
16784
16785@item show debug mips
16786@kindex show debug mips
16787Show the current setting of MIPS debugging messages.
16788@end table
16789
16790
16791@node HPPA
16792@subsection HPPA
16793@cindex HPPA support
16794
d3e8051b 16795When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
16796following special commands:
16797
16798@table @code
16799@item set debug hppa
16800@kindex set debug hppa
db2e3e2e 16801This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
16802messages are to be displayed.
16803
16804@item show debug hppa
16805Show whether HPPA debugging messages are displayed.
16806
16807@item maint print unwind @var{address}
16808@kindex maint print unwind@r{, HPPA}
16809This command displays the contents of the unwind table entry at the
16810given @var{address}.
16811
16812@end table
16813
104c1213 16814
23d964e7
UW
16815@node SPU
16816@subsection Cell Broadband Engine SPU architecture
16817@cindex Cell Broadband Engine
16818@cindex SPU
16819
16820When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
16821it provides the following special commands:
16822
16823@table @code
16824@item info spu event
16825@kindex info spu
16826Display SPU event facility status. Shows current event mask
16827and pending event status.
16828
16829@item info spu signal
16830Display SPU signal notification facility status. Shows pending
16831signal-control word and signal notification mode of both signal
16832notification channels.
16833
16834@item info spu mailbox
16835Display SPU mailbox facility status. Shows all pending entries,
16836in order of processing, in each of the SPU Write Outbound,
16837SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
16838
16839@item info spu dma
16840Display MFC DMA status. Shows all pending commands in the MFC
16841DMA queue. For each entry, opcode, tag, class IDs, effective
16842and local store addresses and transfer size are shown.
16843
16844@item info spu proxydma
16845Display MFC Proxy-DMA status. Shows all pending commands in the MFC
16846Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
16847and local store addresses and transfer size are shown.
16848
16849@end table
16850
4acd40f3
TJB
16851@node PowerPC
16852@subsection PowerPC
16853@cindex PowerPC architecture
16854
16855When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
16856pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
16857numbers stored in the floating point registers. These values must be stored
16858in two consecutive registers, always starting at an even register like
16859@code{f0} or @code{f2}.
16860
16861The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
16862by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
16863@code{f2} and @code{f3} for @code{$dl1} and so on.
16864
aeac0ff9 16865For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
16866wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
16867
23d964e7 16868
8e04817f
AC
16869@node Controlling GDB
16870@chapter Controlling @value{GDBN}
16871
16872You can alter the way @value{GDBN} interacts with you by using the
16873@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 16874data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
16875described here.
16876
16877@menu
16878* Prompt:: Prompt
16879* Editing:: Command editing
d620b259 16880* Command History:: Command history
8e04817f
AC
16881* Screen Size:: Screen size
16882* Numbers:: Numbers
1e698235 16883* ABI:: Configuring the current ABI
8e04817f
AC
16884* Messages/Warnings:: Optional warnings and messages
16885* Debugging Output:: Optional messages about internal happenings
16886@end menu
16887
16888@node Prompt
16889@section Prompt
104c1213 16890
8e04817f 16891@cindex prompt
104c1213 16892
8e04817f
AC
16893@value{GDBN} indicates its readiness to read a command by printing a string
16894called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
16895can change the prompt string with the @code{set prompt} command. For
16896instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
16897the prompt in one of the @value{GDBN} sessions so that you can always tell
16898which one you are talking to.
104c1213 16899
8e04817f
AC
16900@emph{Note:} @code{set prompt} does not add a space for you after the
16901prompt you set. This allows you to set a prompt which ends in a space
16902or a prompt that does not.
104c1213 16903
8e04817f
AC
16904@table @code
16905@kindex set prompt
16906@item set prompt @var{newprompt}
16907Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 16908
8e04817f
AC
16909@kindex show prompt
16910@item show prompt
16911Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
16912@end table
16913
8e04817f 16914@node Editing
79a6e687 16915@section Command Editing
8e04817f
AC
16916@cindex readline
16917@cindex command line editing
104c1213 16918
703663ab 16919@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
16920@sc{gnu} library provides consistent behavior for programs which provide a
16921command line interface to the user. Advantages are @sc{gnu} Emacs-style
16922or @dfn{vi}-style inline editing of commands, @code{csh}-like history
16923substitution, and a storage and recall of command history across
16924debugging sessions.
104c1213 16925
8e04817f
AC
16926You may control the behavior of command line editing in @value{GDBN} with the
16927command @code{set}.
104c1213 16928
8e04817f
AC
16929@table @code
16930@kindex set editing
16931@cindex editing
16932@item set editing
16933@itemx set editing on
16934Enable command line editing (enabled by default).
104c1213 16935
8e04817f
AC
16936@item set editing off
16937Disable command line editing.
104c1213 16938
8e04817f
AC
16939@kindex show editing
16940@item show editing
16941Show whether command line editing is enabled.
104c1213
JM
16942@end table
16943
703663ab
EZ
16944@xref{Command Line Editing}, for more details about the Readline
16945interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
16946encouraged to read that chapter.
16947
d620b259 16948@node Command History
79a6e687 16949@section Command History
703663ab 16950@cindex command history
8e04817f
AC
16951
16952@value{GDBN} can keep track of the commands you type during your
16953debugging sessions, so that you can be certain of precisely what
16954happened. Use these commands to manage the @value{GDBN} command
16955history facility.
104c1213 16956
703663ab
EZ
16957@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
16958package, to provide the history facility. @xref{Using History
16959Interactively}, for the detailed description of the History library.
16960
d620b259 16961To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
16962the state which is seen by users, prefix it with @samp{server }
16963(@pxref{Server Prefix}). This
d620b259
NR
16964means that this command will not affect the command history, nor will it
16965affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
16966pressed on a line by itself.
16967
16968@cindex @code{server}, command prefix
16969The server prefix does not affect the recording of values into the value
16970history; to print a value without recording it into the value history,
16971use the @code{output} command instead of the @code{print} command.
16972
703663ab
EZ
16973Here is the description of @value{GDBN} commands related to command
16974history.
16975
104c1213 16976@table @code
8e04817f
AC
16977@cindex history substitution
16978@cindex history file
16979@kindex set history filename
4644b6e3 16980@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
16981@item set history filename @var{fname}
16982Set the name of the @value{GDBN} command history file to @var{fname}.
16983This is the file where @value{GDBN} reads an initial command history
16984list, and where it writes the command history from this session when it
16985exits. You can access this list through history expansion or through
16986the history command editing characters listed below. This file defaults
16987to the value of the environment variable @code{GDBHISTFILE}, or to
16988@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
16989is not set.
104c1213 16990
9c16f35a
EZ
16991@cindex save command history
16992@kindex set history save
8e04817f
AC
16993@item set history save
16994@itemx set history save on
16995Record command history in a file, whose name may be specified with the
16996@code{set history filename} command. By default, this option is disabled.
104c1213 16997
8e04817f
AC
16998@item set history save off
16999Stop recording command history in a file.
104c1213 17000
8e04817f 17001@cindex history size
9c16f35a 17002@kindex set history size
6fc08d32 17003@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
17004@item set history size @var{size}
17005Set the number of commands which @value{GDBN} keeps in its history list.
17006This defaults to the value of the environment variable
17007@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
17008@end table
17009
8e04817f 17010History expansion assigns special meaning to the character @kbd{!}.
703663ab 17011@xref{Event Designators}, for more details.
8e04817f 17012
703663ab 17013@cindex history expansion, turn on/off
8e04817f
AC
17014Since @kbd{!} is also the logical not operator in C, history expansion
17015is off by default. If you decide to enable history expansion with the
17016@code{set history expansion on} command, you may sometimes need to
17017follow @kbd{!} (when it is used as logical not, in an expression) with
17018a space or a tab to prevent it from being expanded. The readline
17019history facilities do not attempt substitution on the strings
17020@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
17021
17022The commands to control history expansion are:
104c1213
JM
17023
17024@table @code
8e04817f
AC
17025@item set history expansion on
17026@itemx set history expansion
703663ab 17027@kindex set history expansion
8e04817f 17028Enable history expansion. History expansion is off by default.
104c1213 17029
8e04817f
AC
17030@item set history expansion off
17031Disable history expansion.
104c1213 17032
8e04817f
AC
17033@c @group
17034@kindex show history
17035@item show history
17036@itemx show history filename
17037@itemx show history save
17038@itemx show history size
17039@itemx show history expansion
17040These commands display the state of the @value{GDBN} history parameters.
17041@code{show history} by itself displays all four states.
17042@c @end group
17043@end table
17044
17045@table @code
9c16f35a
EZ
17046@kindex show commands
17047@cindex show last commands
17048@cindex display command history
8e04817f
AC
17049@item show commands
17050Display the last ten commands in the command history.
104c1213 17051
8e04817f
AC
17052@item show commands @var{n}
17053Print ten commands centered on command number @var{n}.
17054
17055@item show commands +
17056Print ten commands just after the commands last printed.
104c1213
JM
17057@end table
17058
8e04817f 17059@node Screen Size
79a6e687 17060@section Screen Size
8e04817f
AC
17061@cindex size of screen
17062@cindex pauses in output
104c1213 17063
8e04817f
AC
17064Certain commands to @value{GDBN} may produce large amounts of
17065information output to the screen. To help you read all of it,
17066@value{GDBN} pauses and asks you for input at the end of each page of
17067output. Type @key{RET} when you want to continue the output, or @kbd{q}
17068to discard the remaining output. Also, the screen width setting
17069determines when to wrap lines of output. Depending on what is being
17070printed, @value{GDBN} tries to break the line at a readable place,
17071rather than simply letting it overflow onto the following line.
17072
17073Normally @value{GDBN} knows the size of the screen from the terminal
17074driver software. For example, on Unix @value{GDBN} uses the termcap data base
17075together with the value of the @code{TERM} environment variable and the
17076@code{stty rows} and @code{stty cols} settings. If this is not correct,
17077you can override it with the @code{set height} and @code{set
17078width} commands:
17079
17080@table @code
17081@kindex set height
17082@kindex set width
17083@kindex show width
17084@kindex show height
17085@item set height @var{lpp}
17086@itemx show height
17087@itemx set width @var{cpl}
17088@itemx show width
17089These @code{set} commands specify a screen height of @var{lpp} lines and
17090a screen width of @var{cpl} characters. The associated @code{show}
17091commands display the current settings.
104c1213 17092
8e04817f
AC
17093If you specify a height of zero lines, @value{GDBN} does not pause during
17094output no matter how long the output is. This is useful if output is to a
17095file or to an editor buffer.
104c1213 17096
8e04817f
AC
17097Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
17098from wrapping its output.
9c16f35a
EZ
17099
17100@item set pagination on
17101@itemx set pagination off
17102@kindex set pagination
17103Turn the output pagination on or off; the default is on. Turning
17104pagination off is the alternative to @code{set height 0}.
17105
17106@item show pagination
17107@kindex show pagination
17108Show the current pagination mode.
104c1213
JM
17109@end table
17110
8e04817f
AC
17111@node Numbers
17112@section Numbers
17113@cindex number representation
17114@cindex entering numbers
104c1213 17115
8e04817f
AC
17116You can always enter numbers in octal, decimal, or hexadecimal in
17117@value{GDBN} by the usual conventions: octal numbers begin with
17118@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
17119begin with @samp{0x}. Numbers that neither begin with @samp{0} or
17120@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1712110; likewise, the default display for numbers---when no particular
17122format is specified---is base 10. You can change the default base for
17123both input and output with the commands described below.
104c1213 17124
8e04817f
AC
17125@table @code
17126@kindex set input-radix
17127@item set input-radix @var{base}
17128Set the default base for numeric input. Supported choices
17129for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 17130specified either unambiguously or using the current input radix; for
8e04817f 17131example, any of
104c1213 17132
8e04817f 17133@smallexample
9c16f35a
EZ
17134set input-radix 012
17135set input-radix 10.
17136set input-radix 0xa
8e04817f 17137@end smallexample
104c1213 17138
8e04817f 17139@noindent
9c16f35a 17140sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
17141leaves the input radix unchanged, no matter what it was, since
17142@samp{10}, being without any leading or trailing signs of its base, is
17143interpreted in the current radix. Thus, if the current radix is 16,
17144@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
17145change the radix.
104c1213 17146
8e04817f
AC
17147@kindex set output-radix
17148@item set output-radix @var{base}
17149Set the default base for numeric display. Supported choices
17150for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 17151specified either unambiguously or using the current input radix.
104c1213 17152
8e04817f
AC
17153@kindex show input-radix
17154@item show input-radix
17155Display the current default base for numeric input.
104c1213 17156
8e04817f
AC
17157@kindex show output-radix
17158@item show output-radix
17159Display the current default base for numeric display.
9c16f35a
EZ
17160
17161@item set radix @r{[}@var{base}@r{]}
17162@itemx show radix
17163@kindex set radix
17164@kindex show radix
17165These commands set and show the default base for both input and output
17166of numbers. @code{set radix} sets the radix of input and output to
17167the same base; without an argument, it resets the radix back to its
17168default value of 10.
17169
8e04817f 17170@end table
104c1213 17171
1e698235 17172@node ABI
79a6e687 17173@section Configuring the Current ABI
1e698235
DJ
17174
17175@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
17176application automatically. However, sometimes you need to override its
17177conclusions. Use these commands to manage @value{GDBN}'s view of the
17178current ABI.
17179
98b45e30
DJ
17180@cindex OS ABI
17181@kindex set osabi
b4e9345d 17182@kindex show osabi
98b45e30
DJ
17183
17184One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 17185system targets, either via remote debugging or native emulation.
98b45e30
DJ
17186@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
17187but you can override its conclusion using the @code{set osabi} command.
17188One example where this is useful is in debugging of binaries which use
17189an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
17190not have the same identifying marks that the standard C library for your
17191platform provides.
17192
17193@table @code
17194@item show osabi
17195Show the OS ABI currently in use.
17196
17197@item set osabi
17198With no argument, show the list of registered available OS ABI's.
17199
17200@item set osabi @var{abi}
17201Set the current OS ABI to @var{abi}.
17202@end table
17203
1e698235 17204@cindex float promotion
1e698235
DJ
17205
17206Generally, the way that an argument of type @code{float} is passed to a
17207function depends on whether the function is prototyped. For a prototyped
17208(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
17209according to the architecture's convention for @code{float}. For unprototyped
17210(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
17211@code{double} and then passed.
17212
17213Unfortunately, some forms of debug information do not reliably indicate whether
17214a function is prototyped. If @value{GDBN} calls a function that is not marked
17215as prototyped, it consults @kbd{set coerce-float-to-double}.
17216
17217@table @code
a8f24a35 17218@kindex set coerce-float-to-double
1e698235
DJ
17219@item set coerce-float-to-double
17220@itemx set coerce-float-to-double on
17221Arguments of type @code{float} will be promoted to @code{double} when passed
17222to an unprototyped function. This is the default setting.
17223
17224@item set coerce-float-to-double off
17225Arguments of type @code{float} will be passed directly to unprototyped
17226functions.
9c16f35a
EZ
17227
17228@kindex show coerce-float-to-double
17229@item show coerce-float-to-double
17230Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
17231@end table
17232
f1212245
DJ
17233@kindex set cp-abi
17234@kindex show cp-abi
17235@value{GDBN} needs to know the ABI used for your program's C@t{++}
17236objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
17237used to build your application. @value{GDBN} only fully supports
17238programs with a single C@t{++} ABI; if your program contains code using
17239multiple C@t{++} ABI's or if @value{GDBN} can not identify your
17240program's ABI correctly, you can tell @value{GDBN} which ABI to use.
17241Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
17242before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
17243``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
17244use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
17245``auto''.
17246
17247@table @code
17248@item show cp-abi
17249Show the C@t{++} ABI currently in use.
17250
17251@item set cp-abi
17252With no argument, show the list of supported C@t{++} ABI's.
17253
17254@item set cp-abi @var{abi}
17255@itemx set cp-abi auto
17256Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
17257@end table
17258
8e04817f 17259@node Messages/Warnings
79a6e687 17260@section Optional Warnings and Messages
104c1213 17261
9c16f35a
EZ
17262@cindex verbose operation
17263@cindex optional warnings
8e04817f
AC
17264By default, @value{GDBN} is silent about its inner workings. If you are
17265running on a slow machine, you may want to use the @code{set verbose}
17266command. This makes @value{GDBN} tell you when it does a lengthy
17267internal operation, so you will not think it has crashed.
104c1213 17268
8e04817f
AC
17269Currently, the messages controlled by @code{set verbose} are those
17270which announce that the symbol table for a source file is being read;
79a6e687 17271see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 17272
8e04817f
AC
17273@table @code
17274@kindex set verbose
17275@item set verbose on
17276Enables @value{GDBN} output of certain informational messages.
104c1213 17277
8e04817f
AC
17278@item set verbose off
17279Disables @value{GDBN} output of certain informational messages.
104c1213 17280
8e04817f
AC
17281@kindex show verbose
17282@item show verbose
17283Displays whether @code{set verbose} is on or off.
17284@end table
104c1213 17285
8e04817f
AC
17286By default, if @value{GDBN} encounters bugs in the symbol table of an
17287object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
17288find this information useful (@pxref{Symbol Errors, ,Errors Reading
17289Symbol Files}).
104c1213 17290
8e04817f 17291@table @code
104c1213 17292
8e04817f
AC
17293@kindex set complaints
17294@item set complaints @var{limit}
17295Permits @value{GDBN} to output @var{limit} complaints about each type of
17296unusual symbols before becoming silent about the problem. Set
17297@var{limit} to zero to suppress all complaints; set it to a large number
17298to prevent complaints from being suppressed.
104c1213 17299
8e04817f
AC
17300@kindex show complaints
17301@item show complaints
17302Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 17303
8e04817f 17304@end table
104c1213 17305
8e04817f
AC
17306By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
17307lot of stupid questions to confirm certain commands. For example, if
17308you try to run a program which is already running:
104c1213 17309
474c8240 17310@smallexample
8e04817f
AC
17311(@value{GDBP}) run
17312The program being debugged has been started already.
17313Start it from the beginning? (y or n)
474c8240 17314@end smallexample
104c1213 17315
8e04817f
AC
17316If you are willing to unflinchingly face the consequences of your own
17317commands, you can disable this ``feature'':
104c1213 17318
8e04817f 17319@table @code
104c1213 17320
8e04817f
AC
17321@kindex set confirm
17322@cindex flinching
17323@cindex confirmation
17324@cindex stupid questions
17325@item set confirm off
17326Disables confirmation requests.
104c1213 17327
8e04817f
AC
17328@item set confirm on
17329Enables confirmation requests (the default).
104c1213 17330
8e04817f
AC
17331@kindex show confirm
17332@item show confirm
17333Displays state of confirmation requests.
17334
17335@end table
104c1213 17336
16026cd7
AS
17337@cindex command tracing
17338If you need to debug user-defined commands or sourced files you may find it
17339useful to enable @dfn{command tracing}. In this mode each command will be
17340printed as it is executed, prefixed with one or more @samp{+} symbols, the
17341quantity denoting the call depth of each command.
17342
17343@table @code
17344@kindex set trace-commands
17345@cindex command scripts, debugging
17346@item set trace-commands on
17347Enable command tracing.
17348@item set trace-commands off
17349Disable command tracing.
17350@item show trace-commands
17351Display the current state of command tracing.
17352@end table
17353
8e04817f 17354@node Debugging Output
79a6e687 17355@section Optional Messages about Internal Happenings
4644b6e3
EZ
17356@cindex optional debugging messages
17357
da316a69
EZ
17358@value{GDBN} has commands that enable optional debugging messages from
17359various @value{GDBN} subsystems; normally these commands are of
17360interest to @value{GDBN} maintainers, or when reporting a bug. This
17361section documents those commands.
17362
104c1213 17363@table @code
a8f24a35
EZ
17364@kindex set exec-done-display
17365@item set exec-done-display
17366Turns on or off the notification of asynchronous commands'
17367completion. When on, @value{GDBN} will print a message when an
17368asynchronous command finishes its execution. The default is off.
17369@kindex show exec-done-display
17370@item show exec-done-display
17371Displays the current setting of asynchronous command completion
17372notification.
4644b6e3
EZ
17373@kindex set debug
17374@cindex gdbarch debugging info
a8f24a35 17375@cindex architecture debugging info
8e04817f 17376@item set debug arch
a8f24a35 17377Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 17378@kindex show debug
8e04817f
AC
17379@item show debug arch
17380Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
17381@item set debug aix-thread
17382@cindex AIX threads
17383Display debugging messages about inner workings of the AIX thread
17384module.
17385@item show debug aix-thread
17386Show the current state of AIX thread debugging info display.
d97bc12b
DE
17387@item set debug dwarf2-die
17388@cindex DWARF2 DIEs
17389Dump DWARF2 DIEs after they are read in.
17390The value is the number of nesting levels to print.
17391A value of zero turns off the display.
17392@item show debug dwarf2-die
17393Show the current state of DWARF2 DIE debugging.
237fc4c9
PA
17394@item set debug displaced
17395@cindex displaced stepping debugging info
17396Turns on or off display of @value{GDBN} debugging info for the
17397displaced stepping support. The default is off.
17398@item show debug displaced
17399Displays the current state of displaying @value{GDBN} debugging info
17400related to displaced stepping.
8e04817f 17401@item set debug event
4644b6e3 17402@cindex event debugging info
a8f24a35 17403Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 17404default is off.
8e04817f
AC
17405@item show debug event
17406Displays the current state of displaying @value{GDBN} event debugging
17407info.
8e04817f 17408@item set debug expression
4644b6e3 17409@cindex expression debugging info
721c2651
EZ
17410Turns on or off display of debugging info about @value{GDBN}
17411expression parsing. The default is off.
8e04817f 17412@item show debug expression
721c2651
EZ
17413Displays the current state of displaying debugging info about
17414@value{GDBN} expression parsing.
7453dc06 17415@item set debug frame
4644b6e3 17416@cindex frame debugging info
7453dc06
AC
17417Turns on or off display of @value{GDBN} frame debugging info. The
17418default is off.
7453dc06
AC
17419@item show debug frame
17420Displays the current state of displaying @value{GDBN} frame debugging
17421info.
30e91e0b
RC
17422@item set debug infrun
17423@cindex inferior debugging info
17424Turns on or off display of @value{GDBN} debugging info for running the inferior.
17425The default is off. @file{infrun.c} contains GDB's runtime state machine used
17426for implementing operations such as single-stepping the inferior.
17427@item show debug infrun
17428Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
17429@item set debug lin-lwp
17430@cindex @sc{gnu}/Linux LWP debug messages
17431@cindex Linux lightweight processes
721c2651 17432Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
17433@item show debug lin-lwp
17434Show the current state of Linux LWP debugging messages.
b84876c2
PA
17435@item set debug lin-lwp-async
17436@cindex @sc{gnu}/Linux LWP async debug messages
17437@cindex Linux lightweight processes
17438Turns on or off debugging messages from the Linux LWP async debug support.
17439@item show debug lin-lwp-async
17440Show the current state of Linux LWP async debugging messages.
2b4855ab 17441@item set debug observer
4644b6e3 17442@cindex observer debugging info
2b4855ab
AC
17443Turns on or off display of @value{GDBN} observer debugging. This
17444includes info such as the notification of observable events.
2b4855ab
AC
17445@item show debug observer
17446Displays the current state of observer debugging.
8e04817f 17447@item set debug overload
4644b6e3 17448@cindex C@t{++} overload debugging info
8e04817f 17449Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 17450info. This includes info such as ranking of functions, etc. The default
8e04817f 17451is off.
8e04817f
AC
17452@item show debug overload
17453Displays the current state of displaying @value{GDBN} C@t{++} overload
17454debugging info.
8e04817f
AC
17455@cindex packets, reporting on stdout
17456@cindex serial connections, debugging
605a56cb
DJ
17457@cindex debug remote protocol
17458@cindex remote protocol debugging
17459@cindex display remote packets
8e04817f
AC
17460@item set debug remote
17461Turns on or off display of reports on all packets sent back and forth across
17462the serial line to the remote machine. The info is printed on the
17463@value{GDBN} standard output stream. The default is off.
8e04817f
AC
17464@item show debug remote
17465Displays the state of display of remote packets.
8e04817f
AC
17466@item set debug serial
17467Turns on or off display of @value{GDBN} serial debugging info. The
17468default is off.
8e04817f
AC
17469@item show debug serial
17470Displays the current state of displaying @value{GDBN} serial debugging
17471info.
c45da7e6
EZ
17472@item set debug solib-frv
17473@cindex FR-V shared-library debugging
17474Turns on or off debugging messages for FR-V shared-library code.
17475@item show debug solib-frv
17476Display the current state of FR-V shared-library code debugging
17477messages.
8e04817f 17478@item set debug target
4644b6e3 17479@cindex target debugging info
8e04817f
AC
17480Turns on or off display of @value{GDBN} target debugging info. This info
17481includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
17482default is 0. Set it to 1 to track events, and to 2 to also track the
17483value of large memory transfers. Changes to this flag do not take effect
17484until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
17485@item show debug target
17486Displays the current state of displaying @value{GDBN} target debugging
17487info.
75feb17d
DJ
17488@item set debug timestamp
17489@cindex timestampping debugging info
17490Turns on or off display of timestamps with @value{GDBN} debugging info.
17491When enabled, seconds and microseconds are displayed before each debugging
17492message.
17493@item show debug timestamp
17494Displays the current state of displaying timestamps with @value{GDBN}
17495debugging info.
c45da7e6 17496@item set debugvarobj
4644b6e3 17497@cindex variable object debugging info
8e04817f
AC
17498Turns on or off display of @value{GDBN} variable object debugging
17499info. The default is off.
c45da7e6 17500@item show debugvarobj
8e04817f
AC
17501Displays the current state of displaying @value{GDBN} variable object
17502debugging info.
e776119f
DJ
17503@item set debug xml
17504@cindex XML parser debugging
17505Turns on or off debugging messages for built-in XML parsers.
17506@item show debug xml
17507Displays the current state of XML debugging messages.
8e04817f 17508@end table
104c1213 17509
d57a3c85
TJB
17510@node Extending GDB
17511@chapter Extending @value{GDBN}
17512@cindex extending GDB
17513
17514@value{GDBN} provides two mechanisms for extension. The first is based
17515on composition of @value{GDBN} commands, and the second is based on the
17516Python scripting language.
17517
17518@menu
17519* Sequences:: Canned Sequences of Commands
17520* Python:: Scripting @value{GDBN} using Python
17521@end menu
17522
8e04817f 17523@node Sequences
d57a3c85 17524@section Canned Sequences of Commands
104c1213 17525
8e04817f 17526Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 17527Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
17528commands for execution as a unit: user-defined commands and command
17529files.
104c1213 17530
8e04817f 17531@menu
fcc73fe3
EZ
17532* Define:: How to define your own commands
17533* Hooks:: Hooks for user-defined commands
17534* Command Files:: How to write scripts of commands to be stored in a file
17535* Output:: Commands for controlled output
8e04817f 17536@end menu
104c1213 17537
8e04817f 17538@node Define
d57a3c85 17539@subsection User-defined Commands
104c1213 17540
8e04817f 17541@cindex user-defined command
fcc73fe3 17542@cindex arguments, to user-defined commands
8e04817f
AC
17543A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
17544which you assign a new name as a command. This is done with the
17545@code{define} command. User commands may accept up to 10 arguments
17546separated by whitespace. Arguments are accessed within the user command
c03c782f 17547via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 17548
8e04817f
AC
17549@smallexample
17550define adder
17551 print $arg0 + $arg1 + $arg2
c03c782f 17552end
8e04817f 17553@end smallexample
104c1213
JM
17554
17555@noindent
8e04817f 17556To execute the command use:
104c1213 17557
8e04817f
AC
17558@smallexample
17559adder 1 2 3
17560@end smallexample
104c1213 17561
8e04817f
AC
17562@noindent
17563This defines the command @code{adder}, which prints the sum of
17564its three arguments. Note the arguments are text substitutions, so they may
17565reference variables, use complex expressions, or even perform inferior
17566functions calls.
104c1213 17567
fcc73fe3
EZ
17568@cindex argument count in user-defined commands
17569@cindex how many arguments (user-defined commands)
c03c782f
AS
17570In addition, @code{$argc} may be used to find out how many arguments have
17571been passed. This expands to a number in the range 0@dots{}10.
17572
17573@smallexample
17574define adder
17575 if $argc == 2
17576 print $arg0 + $arg1
17577 end
17578 if $argc == 3
17579 print $arg0 + $arg1 + $arg2
17580 end
17581end
17582@end smallexample
17583
104c1213 17584@table @code
104c1213 17585
8e04817f
AC
17586@kindex define
17587@item define @var{commandname}
17588Define a command named @var{commandname}. If there is already a command
17589by that name, you are asked to confirm that you want to redefine it.
104c1213 17590
8e04817f
AC
17591The definition of the command is made up of other @value{GDBN} command lines,
17592which are given following the @code{define} command. The end of these
17593commands is marked by a line containing @code{end}.
104c1213 17594
8e04817f 17595@kindex document
ca91424e 17596@kindex end@r{ (user-defined commands)}
8e04817f
AC
17597@item document @var{commandname}
17598Document the user-defined command @var{commandname}, so that it can be
17599accessed by @code{help}. The command @var{commandname} must already be
17600defined. This command reads lines of documentation just as @code{define}
17601reads the lines of the command definition, ending with @code{end}.
17602After the @code{document} command is finished, @code{help} on command
17603@var{commandname} displays the documentation you have written.
104c1213 17604
8e04817f
AC
17605You may use the @code{document} command again to change the
17606documentation of a command. Redefining the command with @code{define}
17607does not change the documentation.
104c1213 17608
c45da7e6
EZ
17609@kindex dont-repeat
17610@cindex don't repeat command
17611@item dont-repeat
17612Used inside a user-defined command, this tells @value{GDBN} that this
17613command should not be repeated when the user hits @key{RET}
17614(@pxref{Command Syntax, repeat last command}).
17615
8e04817f
AC
17616@kindex help user-defined
17617@item help user-defined
17618List all user-defined commands, with the first line of the documentation
17619(if any) for each.
104c1213 17620
8e04817f
AC
17621@kindex show user
17622@item show user
17623@itemx show user @var{commandname}
17624Display the @value{GDBN} commands used to define @var{commandname} (but
17625not its documentation). If no @var{commandname} is given, display the
17626definitions for all user-defined commands.
104c1213 17627
fcc73fe3 17628@cindex infinite recursion in user-defined commands
20f01a46
DH
17629@kindex show max-user-call-depth
17630@kindex set max-user-call-depth
17631@item show max-user-call-depth
5ca0cb28
DH
17632@itemx set max-user-call-depth
17633The value of @code{max-user-call-depth} controls how many recursion
3f94c067 17634levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 17635infinite recursion and aborts the command.
104c1213
JM
17636@end table
17637
fcc73fe3
EZ
17638In addition to the above commands, user-defined commands frequently
17639use control flow commands, described in @ref{Command Files}.
17640
8e04817f
AC
17641When user-defined commands are executed, the
17642commands of the definition are not printed. An error in any command
17643stops execution of the user-defined command.
104c1213 17644
8e04817f
AC
17645If used interactively, commands that would ask for confirmation proceed
17646without asking when used inside a user-defined command. Many @value{GDBN}
17647commands that normally print messages to say what they are doing omit the
17648messages when used in a user-defined command.
104c1213 17649
8e04817f 17650@node Hooks
d57a3c85 17651@subsection User-defined Command Hooks
8e04817f
AC
17652@cindex command hooks
17653@cindex hooks, for commands
17654@cindex hooks, pre-command
104c1213 17655
8e04817f 17656@kindex hook
8e04817f
AC
17657You may define @dfn{hooks}, which are a special kind of user-defined
17658command. Whenever you run the command @samp{foo}, if the user-defined
17659command @samp{hook-foo} exists, it is executed (with no arguments)
17660before that command.
104c1213 17661
8e04817f
AC
17662@cindex hooks, post-command
17663@kindex hookpost
8e04817f
AC
17664A hook may also be defined which is run after the command you executed.
17665Whenever you run the command @samp{foo}, if the user-defined command
17666@samp{hookpost-foo} exists, it is executed (with no arguments) after
17667that command. Post-execution hooks may exist simultaneously with
17668pre-execution hooks, for the same command.
104c1213 17669
8e04817f 17670It is valid for a hook to call the command which it hooks. If this
9f1c6395 17671occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 17672
8e04817f
AC
17673@c It would be nice if hookpost could be passed a parameter indicating
17674@c if the command it hooks executed properly or not. FIXME!
104c1213 17675
8e04817f
AC
17676@kindex stop@r{, a pseudo-command}
17677In addition, a pseudo-command, @samp{stop} exists. Defining
17678(@samp{hook-stop}) makes the associated commands execute every time
17679execution stops in your program: before breakpoint commands are run,
17680displays are printed, or the stack frame is printed.
104c1213 17681
8e04817f
AC
17682For example, to ignore @code{SIGALRM} signals while
17683single-stepping, but treat them normally during normal execution,
17684you could define:
104c1213 17685
474c8240 17686@smallexample
8e04817f
AC
17687define hook-stop
17688handle SIGALRM nopass
17689end
104c1213 17690
8e04817f
AC
17691define hook-run
17692handle SIGALRM pass
17693end
104c1213 17694
8e04817f 17695define hook-continue
d3e8051b 17696handle SIGALRM pass
8e04817f 17697end
474c8240 17698@end smallexample
104c1213 17699
d3e8051b 17700As a further example, to hook at the beginning and end of the @code{echo}
b383017d 17701command, and to add extra text to the beginning and end of the message,
8e04817f 17702you could define:
104c1213 17703
474c8240 17704@smallexample
8e04817f
AC
17705define hook-echo
17706echo <<<---
17707end
104c1213 17708
8e04817f
AC
17709define hookpost-echo
17710echo --->>>\n
17711end
104c1213 17712
8e04817f
AC
17713(@value{GDBP}) echo Hello World
17714<<<---Hello World--->>>
17715(@value{GDBP})
104c1213 17716
474c8240 17717@end smallexample
104c1213 17718
8e04817f
AC
17719You can define a hook for any single-word command in @value{GDBN}, but
17720not for command aliases; you should define a hook for the basic command
c1468174 17721name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
17722@c FIXME! So how does Joe User discover whether a command is an alias
17723@c or not?
17724If an error occurs during the execution of your hook, execution of
17725@value{GDBN} commands stops and @value{GDBN} issues a prompt
17726(before the command that you actually typed had a chance to run).
104c1213 17727
8e04817f
AC
17728If you try to define a hook which does not match any known command, you
17729get a warning from the @code{define} command.
c906108c 17730
8e04817f 17731@node Command Files
d57a3c85 17732@subsection Command Files
c906108c 17733
8e04817f 17734@cindex command files
fcc73fe3 17735@cindex scripting commands
6fc08d32
EZ
17736A command file for @value{GDBN} is a text file made of lines that are
17737@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
17738also be included. An empty line in a command file does nothing; it
17739does not mean to repeat the last command, as it would from the
17740terminal.
c906108c 17741
6fc08d32
EZ
17742You can request the execution of a command file with the @code{source}
17743command:
c906108c 17744
8e04817f
AC
17745@table @code
17746@kindex source
ca91424e 17747@cindex execute commands from a file
16026cd7 17748@item source [@code{-v}] @var{filename}
8e04817f 17749Execute the command file @var{filename}.
c906108c
SS
17750@end table
17751
fcc73fe3
EZ
17752The lines in a command file are generally executed sequentially,
17753unless the order of execution is changed by one of the
17754@emph{flow-control commands} described below. The commands are not
a71ec265
DH
17755printed as they are executed. An error in any command terminates
17756execution of the command file and control is returned to the console.
c906108c 17757
4b505b12
AS
17758@value{GDBN} searches for @var{filename} in the current directory and then
17759on the search path (specified with the @samp{directory} command).
17760
16026cd7
AS
17761If @code{-v}, for verbose mode, is given then @value{GDBN} displays
17762each command as it is executed. The option must be given before
17763@var{filename}, and is interpreted as part of the filename anywhere else.
17764
8e04817f
AC
17765Commands that would ask for confirmation if used interactively proceed
17766without asking when used in a command file. Many @value{GDBN} commands that
17767normally print messages to say what they are doing omit the messages
17768when called from command files.
c906108c 17769
8e04817f
AC
17770@value{GDBN} also accepts command input from standard input. In this
17771mode, normal output goes to standard output and error output goes to
17772standard error. Errors in a command file supplied on standard input do
6fc08d32 17773not terminate execution of the command file---execution continues with
8e04817f 17774the next command.
c906108c 17775
474c8240 17776@smallexample
8e04817f 17777gdb < cmds > log 2>&1
474c8240 17778@end smallexample
c906108c 17779
8e04817f
AC
17780(The syntax above will vary depending on the shell used.) This example
17781will execute commands from the file @file{cmds}. All output and errors
17782would be directed to @file{log}.
c906108c 17783
fcc73fe3
EZ
17784Since commands stored on command files tend to be more general than
17785commands typed interactively, they frequently need to deal with
17786complicated situations, such as different or unexpected values of
17787variables and symbols, changes in how the program being debugged is
17788built, etc. @value{GDBN} provides a set of flow-control commands to
17789deal with these complexities. Using these commands, you can write
17790complex scripts that loop over data structures, execute commands
17791conditionally, etc.
17792
17793@table @code
17794@kindex if
17795@kindex else
17796@item if
17797@itemx else
17798This command allows to include in your script conditionally executed
17799commands. The @code{if} command takes a single argument, which is an
17800expression to evaluate. It is followed by a series of commands that
17801are executed only if the expression is true (its value is nonzero).
17802There can then optionally be an @code{else} line, followed by a series
17803of commands that are only executed if the expression was false. The
17804end of the list is marked by a line containing @code{end}.
17805
17806@kindex while
17807@item while
17808This command allows to write loops. Its syntax is similar to
17809@code{if}: the command takes a single argument, which is an expression
17810to evaluate, and must be followed by the commands to execute, one per
17811line, terminated by an @code{end}. These commands are called the
17812@dfn{body} of the loop. The commands in the body of @code{while} are
17813executed repeatedly as long as the expression evaluates to true.
17814
17815@kindex loop_break
17816@item loop_break
17817This command exits the @code{while} loop in whose body it is included.
17818Execution of the script continues after that @code{while}s @code{end}
17819line.
17820
17821@kindex loop_continue
17822@item loop_continue
17823This command skips the execution of the rest of the body of commands
17824in the @code{while} loop in whose body it is included. Execution
17825branches to the beginning of the @code{while} loop, where it evaluates
17826the controlling expression.
ca91424e
EZ
17827
17828@kindex end@r{ (if/else/while commands)}
17829@item end
17830Terminate the block of commands that are the body of @code{if},
17831@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
17832@end table
17833
17834
8e04817f 17835@node Output
d57a3c85 17836@subsection Commands for Controlled Output
c906108c 17837
8e04817f
AC
17838During the execution of a command file or a user-defined command, normal
17839@value{GDBN} output is suppressed; the only output that appears is what is
17840explicitly printed by the commands in the definition. This section
17841describes three commands useful for generating exactly the output you
17842want.
c906108c
SS
17843
17844@table @code
8e04817f
AC
17845@kindex echo
17846@item echo @var{text}
17847@c I do not consider backslash-space a standard C escape sequence
17848@c because it is not in ANSI.
17849Print @var{text}. Nonprinting characters can be included in
17850@var{text} using C escape sequences, such as @samp{\n} to print a
17851newline. @strong{No newline is printed unless you specify one.}
17852In addition to the standard C escape sequences, a backslash followed
17853by a space stands for a space. This is useful for displaying a
17854string with spaces at the beginning or the end, since leading and
17855trailing spaces are otherwise trimmed from all arguments.
17856To print @samp{@w{ }and foo =@w{ }}, use the command
17857@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 17858
8e04817f
AC
17859A backslash at the end of @var{text} can be used, as in C, to continue
17860the command onto subsequent lines. For example,
c906108c 17861
474c8240 17862@smallexample
8e04817f
AC
17863echo This is some text\n\
17864which is continued\n\
17865onto several lines.\n
474c8240 17866@end smallexample
c906108c 17867
8e04817f 17868produces the same output as
c906108c 17869
474c8240 17870@smallexample
8e04817f
AC
17871echo This is some text\n
17872echo which is continued\n
17873echo onto several lines.\n
474c8240 17874@end smallexample
c906108c 17875
8e04817f
AC
17876@kindex output
17877@item output @var{expression}
17878Print the value of @var{expression} and nothing but that value: no
17879newlines, no @samp{$@var{nn} = }. The value is not entered in the
17880value history either. @xref{Expressions, ,Expressions}, for more information
17881on expressions.
c906108c 17882
8e04817f
AC
17883@item output/@var{fmt} @var{expression}
17884Print the value of @var{expression} in format @var{fmt}. You can use
17885the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 17886Formats}, for more information.
c906108c 17887
8e04817f 17888@kindex printf
82160952
EZ
17889@item printf @var{template}, @var{expressions}@dots{}
17890Print the values of one or more @var{expressions} under the control of
17891the string @var{template}. To print several values, make
17892@var{expressions} be a comma-separated list of individual expressions,
17893which may be either numbers or pointers. Their values are printed as
17894specified by @var{template}, exactly as a C program would do by
17895executing the code below:
c906108c 17896
474c8240 17897@smallexample
82160952 17898printf (@var{template}, @var{expressions}@dots{});
474c8240 17899@end smallexample
c906108c 17900
82160952
EZ
17901As in @code{C} @code{printf}, ordinary characters in @var{template}
17902are printed verbatim, while @dfn{conversion specification} introduced
17903by the @samp{%} character cause subsequent @var{expressions} to be
17904evaluated, their values converted and formatted according to type and
17905style information encoded in the conversion specifications, and then
17906printed.
17907
8e04817f 17908For example, you can print two values in hex like this:
c906108c 17909
8e04817f
AC
17910@smallexample
17911printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
17912@end smallexample
c906108c 17913
82160952
EZ
17914@code{printf} supports all the standard @code{C} conversion
17915specifications, including the flags and modifiers between the @samp{%}
17916character and the conversion letter, with the following exceptions:
17917
17918@itemize @bullet
17919@item
17920The argument-ordering modifiers, such as @samp{2$}, are not supported.
17921
17922@item
17923The modifier @samp{*} is not supported for specifying precision or
17924width.
17925
17926@item
17927The @samp{'} flag (for separation of digits into groups according to
17928@code{LC_NUMERIC'}) is not supported.
17929
17930@item
17931The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
17932supported.
17933
17934@item
17935The conversion letter @samp{n} (as in @samp{%n}) is not supported.
17936
17937@item
17938The conversion letters @samp{a} and @samp{A} are not supported.
17939@end itemize
17940
17941@noindent
17942Note that the @samp{ll} type modifier is supported only if the
17943underlying @code{C} implementation used to build @value{GDBN} supports
17944the @code{long long int} type, and the @samp{L} type modifier is
17945supported only if @code{long double} type is available.
17946
17947As in @code{C}, @code{printf} supports simple backslash-escape
17948sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
17949@samp{\a}, and @samp{\f}, that consist of backslash followed by a
17950single character. Octal and hexadecimal escape sequences are not
17951supported.
1a619819
LM
17952
17953Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
17954(@dfn{Decimal Floating Point}) types using the following length modifiers
17955together with a floating point specifier.
1a619819
LM
17956letters:
17957
17958@itemize @bullet
17959@item
17960@samp{H} for printing @code{Decimal32} types.
17961
17962@item
17963@samp{D} for printing @code{Decimal64} types.
17964
17965@item
17966@samp{DD} for printing @code{Decimal128} types.
17967@end itemize
17968
17969If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 17970support for the three length modifiers for DFP types, other modifiers
3b784c4f 17971such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
17972
17973In case there is no such @code{C} support, no additional modifiers will be
17974available and the value will be printed in the standard way.
17975
17976Here's an example of printing DFP types using the above conversion letters:
17977@smallexample
0aea4bf3 17978printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
17979@end smallexample
17980
c906108c
SS
17981@end table
17982
d57a3c85
TJB
17983@node Python
17984@section Scripting @value{GDBN} using Python
17985@cindex python scripting
17986@cindex scripting with python
17987
17988You can script @value{GDBN} using the @uref{http://www.python.org/,
17989Python programming language}. This feature is available only if
17990@value{GDBN} was configured using @option{--with-python}.
17991
17992@menu
17993* Python Commands:: Accessing Python from @value{GDBN}.
17994* Python API:: Accessing @value{GDBN} from Python.
17995@end menu
17996
17997@node Python Commands
17998@subsection Python Commands
17999@cindex python commands
18000@cindex commands to access python
18001
18002@value{GDBN} provides one command for accessing the Python interpreter,
18003and one related setting:
18004
18005@table @code
18006@kindex python
18007@item python @r{[}@var{code}@r{]}
18008The @code{python} command can be used to evaluate Python code.
18009
18010If given an argument, the @code{python} command will evaluate the
18011argument as a Python command. For example:
18012
18013@smallexample
18014(@value{GDBP}) python print 23
1801523
18016@end smallexample
18017
18018If you do not provide an argument to @code{python}, it will act as a
18019multi-line command, like @code{define}. In this case, the Python
18020script is made up of subsequent command lines, given after the
18021@code{python} command. This command list is terminated using a line
18022containing @code{end}. For example:
18023
18024@smallexample
18025(@value{GDBP}) python
18026Type python script
18027End with a line saying just "end".
18028>print 23
18029>end
1803023
18031@end smallexample
18032
18033@kindex maint set python print-stack
18034@item maint set python print-stack
18035By default, @value{GDBN} will print a stack trace when an error occurs
18036in a Python script. This can be controlled using @code{maint set
18037python print-stack}: if @code{on}, the default, then Python stack
18038printing is enabled; if @code{off}, then Python stack printing is
18039disabled.
18040@end table
18041
18042@node Python API
18043@subsection Python API
18044@cindex python api
18045@cindex programming in python
18046
18047@cindex python stdout
18048@cindex python pagination
18049At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
18050@code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
18051A Python program which outputs to one of these streams may have its
18052output interrupted by the user (@pxref{Screen Size}). In this
18053situation, a Python @code{KeyboardInterrupt} exception is thrown.
18054
18055@menu
18056* Basic Python:: Basic Python Functions.
18057* Exception Handling::
a08702d6 18058* Values From Inferior::
d57a3c85
TJB
18059@end menu
18060
18061@node Basic Python
18062@subsubsection Basic Python
18063
18064@cindex python functions
18065@cindex python module
18066@cindex gdb module
18067@value{GDBN} introduces a new Python module, named @code{gdb}. All
18068methods and classes added by @value{GDBN} are placed in this module.
18069@value{GDBN} automatically @code{import}s the @code{gdb} module for
18070use in all scripts evaluated by the @code{python} command.
18071
18072@findex gdb.execute
18073@defun execute command
18074Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
18075If a GDB exception happens while @var{command} runs, it is
18076translated as described in @ref{Exception Handling,,Exception Handling}.
18077If no exceptions occur, this function returns @code{None}.
18078@end defun
18079
18080@findex gdb.get_parameter
18081@defun get_parameter parameter
18082Return the value of a @value{GDBN} parameter. @var{parameter} is a
18083string naming the parameter to look up; @var{parameter} may contain
18084spaces if the parameter has a multi-part name. For example,
18085@samp{print object} is a valid parameter name.
18086
18087If the named parameter does not exist, this function throws a
18088@code{RuntimeError}. Otherwise, the parameter's value is converted to
18089a Python value of the appropriate type, and returned.
18090@end defun
18091
18092@findex gdb.write
18093@defun write string
18094Print a string to @value{GDBN}'s paginated standard output stream.
18095Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
18096call this function.
18097@end defun
18098
18099@findex gdb.flush
18100@defun flush
18101Flush @value{GDBN}'s paginated standard output stream. Flushing
18102@code{sys.stdout} or @code{sys.stderr} will automatically call this
18103function.
18104@end defun
18105
18106@node Exception Handling
18107@subsubsection Exception Handling
18108@cindex python exceptions
18109@cindex exceptions, python
18110
18111When executing the @code{python} command, Python exceptions
18112uncaught within the Python code are translated to calls to
18113@value{GDBN} error-reporting mechanism. If the command that called
18114@code{python} does not handle the error, @value{GDBN} will
18115terminate it and print an error message containing the Python
18116exception name, the associated value, and the Python call stack
18117backtrace at the point where the exception was raised. Example:
18118
18119@smallexample
18120(@value{GDBP}) python print foo
18121Traceback (most recent call last):
18122 File "<string>", line 1, in <module>
18123NameError: name 'foo' is not defined
18124@end smallexample
18125
18126@value{GDBN} errors that happen in @value{GDBN} commands invoked by Python
18127code are converted to Python @code{RuntimeError} exceptions. User
18128interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
18129prompt) is translated to a Python @code{KeyboardInterrupt}
18130exception. If you catch these exceptions in your Python code, your
18131exception handler will see @code{RuntimeError} or
18132@code{KeyboardInterrupt} as the exception type, the @value{GDBN} error
18133message as its value, and the Python call stack backtrace at the
18134Python statement closest to where the @value{GDBN} error occured as the
18135traceback.
18136
a08702d6
TJB
18137@node Values From Inferior
18138@subsubsection Values From Inferior
18139@cindex values from inferior, with Python
18140@cindex python, working with values from inferior
18141
18142@cindex @code{gdb.Value}
18143@value{GDBN} provides values it obtains from the inferior program in
18144an object of type @code{gdb.Value}. @value{GDBN} uses this object
18145for its internal bookkeeping of the inferior's values, and for
18146fetching values when necessary.
18147
18148Inferior values that are simple scalars can be used directly in
18149Python expressions that are valid for the value's data type. Here's
18150an example for an integer or floating-point value @code{some_val}:
18151
18152@smallexample
18153bar = some_val + 2
18154@end smallexample
18155
18156@noindent
18157As result of this, @code{bar} will also be a @code{gdb.Value} object
18158whose values are of the same type as those of @code{some_val}.
18159
18160Inferior values that are structures or instances of some class can
18161be accessed using the Python @dfn{dictionary syntax}. For example, if
18162@code{some_val} is a @code{gdb.Value} instance holding a structure, you
18163can access its @code{foo} element with:
18164
18165@smallexample
18166bar = some_val['foo']
18167@end smallexample
18168
18169Again, @code{bar} will also be a @code{gdb.Value} object.
18170
18171For pointer data types, @code{gdb.Value} provides a method for
18172dereferencing the pointer to obtain the object it points to.
18173
18174@defmethod Value dereference
18175This method returns a new @code{gdb.Value} object whose contents is
18176the object pointed to by the pointer. For example, if @code{foo} is
18177a C pointer to an @code{int}, declared in your C program as
18178
18179@smallexample
18180int *foo;
18181@end smallexample
18182
18183@noindent
18184then you can use the corresponding @code{gdb.Value} to access what
18185@code{foo} points to like this:
18186
18187@smallexample
18188bar = foo.dereference ()
18189@end smallexample
18190
18191The result @code{bar} will be a @code{gdb.Value} object holding the
18192value pointed to by @code{foo}.
18193@end defmethod
18194
21c294e6
AC
18195@node Interpreters
18196@chapter Command Interpreters
18197@cindex command interpreters
18198
18199@value{GDBN} supports multiple command interpreters, and some command
18200infrastructure to allow users or user interface writers to switch
18201between interpreters or run commands in other interpreters.
18202
18203@value{GDBN} currently supports two command interpreters, the console
18204interpreter (sometimes called the command-line interpreter or @sc{cli})
18205and the machine interface interpreter (or @sc{gdb/mi}). This manual
18206describes both of these interfaces in great detail.
18207
18208By default, @value{GDBN} will start with the console interpreter.
18209However, the user may choose to start @value{GDBN} with another
18210interpreter by specifying the @option{-i} or @option{--interpreter}
18211startup options. Defined interpreters include:
18212
18213@table @code
18214@item console
18215@cindex console interpreter
18216The traditional console or command-line interpreter. This is the most often
18217used interpreter with @value{GDBN}. With no interpreter specified at runtime,
18218@value{GDBN} will use this interpreter.
18219
18220@item mi
18221@cindex mi interpreter
18222The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
18223by programs wishing to use @value{GDBN} as a backend for a debugger GUI
18224or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
18225Interface}.
18226
18227@item mi2
18228@cindex mi2 interpreter
18229The current @sc{gdb/mi} interface.
18230
18231@item mi1
18232@cindex mi1 interpreter
18233The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
18234
18235@end table
18236
18237@cindex invoke another interpreter
18238The interpreter being used by @value{GDBN} may not be dynamically
18239switched at runtime. Although possible, this could lead to a very
18240precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
18241enters the command "interpreter-set console" in a console view,
18242@value{GDBN} would switch to using the console interpreter, rendering
18243the IDE inoperable!
18244
18245@kindex interpreter-exec
18246Although you may only choose a single interpreter at startup, you may execute
18247commands in any interpreter from the current interpreter using the appropriate
18248command. If you are running the console interpreter, simply use the
18249@code{interpreter-exec} command:
18250
18251@smallexample
18252interpreter-exec mi "-data-list-register-names"
18253@end smallexample
18254
18255@sc{gdb/mi} has a similar command, although it is only available in versions of
18256@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
18257
8e04817f
AC
18258@node TUI
18259@chapter @value{GDBN} Text User Interface
18260@cindex TUI
d0d5df6f 18261@cindex Text User Interface
c906108c 18262
8e04817f
AC
18263@menu
18264* TUI Overview:: TUI overview
18265* TUI Keys:: TUI key bindings
7cf36c78 18266* TUI Single Key Mode:: TUI single key mode
db2e3e2e 18267* TUI Commands:: TUI-specific commands
8e04817f
AC
18268* TUI Configuration:: TUI configuration variables
18269@end menu
c906108c 18270
46ba6afa 18271The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
18272interface which uses the @code{curses} library to show the source
18273file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
18274commands in separate text windows. The TUI mode is supported only
18275on platforms where a suitable version of the @code{curses} library
18276is available.
d0d5df6f 18277
46ba6afa
BW
18278@pindex @value{GDBTUI}
18279The TUI mode is enabled by default when you invoke @value{GDBN} as
18280either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
18281You can also switch in and out of TUI mode while @value{GDBN} runs by
18282using various TUI commands and key bindings, such as @kbd{C-x C-a}.
18283@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 18284
8e04817f 18285@node TUI Overview
79a6e687 18286@section TUI Overview
c906108c 18287
46ba6afa 18288In TUI mode, @value{GDBN} can display several text windows:
c906108c 18289
8e04817f
AC
18290@table @emph
18291@item command
18292This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
18293prompt and the @value{GDBN} output. The @value{GDBN} input is still
18294managed using readline.
c906108c 18295
8e04817f
AC
18296@item source
18297The source window shows the source file of the program. The current
46ba6afa 18298line and active breakpoints are displayed in this window.
c906108c 18299
8e04817f
AC
18300@item assembly
18301The assembly window shows the disassembly output of the program.
c906108c 18302
8e04817f 18303@item register
46ba6afa
BW
18304This window shows the processor registers. Registers are highlighted
18305when their values change.
c906108c
SS
18306@end table
18307
269c21fe 18308The source and assembly windows show the current program position
46ba6afa
BW
18309by highlighting the current line and marking it with a @samp{>} marker.
18310Breakpoints are indicated with two markers. The first marker
269c21fe
SC
18311indicates the breakpoint type:
18312
18313@table @code
18314@item B
18315Breakpoint which was hit at least once.
18316
18317@item b
18318Breakpoint which was never hit.
18319
18320@item H
18321Hardware breakpoint which was hit at least once.
18322
18323@item h
18324Hardware breakpoint which was never hit.
269c21fe
SC
18325@end table
18326
18327The second marker indicates whether the breakpoint is enabled or not:
18328
18329@table @code
18330@item +
18331Breakpoint is enabled.
18332
18333@item -
18334Breakpoint is disabled.
269c21fe
SC
18335@end table
18336
46ba6afa
BW
18337The source, assembly and register windows are updated when the current
18338thread changes, when the frame changes, or when the program counter
18339changes.
18340
18341These windows are not all visible at the same time. The command
18342window is always visible. The others can be arranged in several
18343layouts:
c906108c 18344
8e04817f
AC
18345@itemize @bullet
18346@item
46ba6afa 18347source only,
2df3850c 18348
8e04817f 18349@item
46ba6afa 18350assembly only,
8e04817f
AC
18351
18352@item
46ba6afa 18353source and assembly,
8e04817f
AC
18354
18355@item
46ba6afa 18356source and registers, or
c906108c 18357
8e04817f 18358@item
46ba6afa 18359assembly and registers.
8e04817f 18360@end itemize
c906108c 18361
46ba6afa 18362A status line above the command window shows the following information:
b7bb15bc
SC
18363
18364@table @emph
18365@item target
46ba6afa 18366Indicates the current @value{GDBN} target.
b7bb15bc
SC
18367(@pxref{Targets, ,Specifying a Debugging Target}).
18368
18369@item process
46ba6afa 18370Gives the current process or thread number.
b7bb15bc
SC
18371When no process is being debugged, this field is set to @code{No process}.
18372
18373@item function
18374Gives the current function name for the selected frame.
18375The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 18376When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
18377the string @code{??} is displayed.
18378
18379@item line
18380Indicates the current line number for the selected frame.
46ba6afa 18381When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
18382
18383@item pc
18384Indicates the current program counter address.
b7bb15bc
SC
18385@end table
18386
8e04817f
AC
18387@node TUI Keys
18388@section TUI Key Bindings
18389@cindex TUI key bindings
c906108c 18390
8e04817f 18391The TUI installs several key bindings in the readline keymaps
46ba6afa 18392(@pxref{Command Line Editing}). The following key bindings
8e04817f 18393are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 18394
8e04817f
AC
18395@table @kbd
18396@kindex C-x C-a
18397@item C-x C-a
18398@kindex C-x a
18399@itemx C-x a
18400@kindex C-x A
18401@itemx C-x A
46ba6afa
BW
18402Enter or leave the TUI mode. When leaving the TUI mode,
18403the curses window management stops and @value{GDBN} operates using
18404its standard mode, writing on the terminal directly. When reentering
18405the TUI mode, control is given back to the curses windows.
8e04817f 18406The screen is then refreshed.
c906108c 18407
8e04817f
AC
18408@kindex C-x 1
18409@item C-x 1
18410Use a TUI layout with only one window. The layout will
18411either be @samp{source} or @samp{assembly}. When the TUI mode
18412is not active, it will switch to the TUI mode.
2df3850c 18413
8e04817f 18414Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 18415
8e04817f
AC
18416@kindex C-x 2
18417@item C-x 2
18418Use a TUI layout with at least two windows. When the current
46ba6afa 18419layout already has two windows, the next layout with two windows is used.
8e04817f
AC
18420When a new layout is chosen, one window will always be common to the
18421previous layout and the new one.
c906108c 18422
8e04817f 18423Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 18424
72ffddc9
SC
18425@kindex C-x o
18426@item C-x o
18427Change the active window. The TUI associates several key bindings
46ba6afa 18428(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
18429gives the focus to the next TUI window.
18430
18431Think of it as the Emacs @kbd{C-x o} binding.
18432
7cf36c78
SC
18433@kindex C-x s
18434@item C-x s
46ba6afa
BW
18435Switch in and out of the TUI SingleKey mode that binds single
18436keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
18437@end table
18438
46ba6afa 18439The following key bindings only work in the TUI mode:
5d161b24 18440
46ba6afa 18441@table @asis
8e04817f 18442@kindex PgUp
46ba6afa 18443@item @key{PgUp}
8e04817f 18444Scroll the active window one page up.
c906108c 18445
8e04817f 18446@kindex PgDn
46ba6afa 18447@item @key{PgDn}
8e04817f 18448Scroll the active window one page down.
c906108c 18449
8e04817f 18450@kindex Up
46ba6afa 18451@item @key{Up}
8e04817f 18452Scroll the active window one line up.
c906108c 18453
8e04817f 18454@kindex Down
46ba6afa 18455@item @key{Down}
8e04817f 18456Scroll the active window one line down.
c906108c 18457
8e04817f 18458@kindex Left
46ba6afa 18459@item @key{Left}
8e04817f 18460Scroll the active window one column left.
c906108c 18461
8e04817f 18462@kindex Right
46ba6afa 18463@item @key{Right}
8e04817f 18464Scroll the active window one column right.
c906108c 18465
8e04817f 18466@kindex C-L
46ba6afa 18467@item @kbd{C-L}
8e04817f 18468Refresh the screen.
8e04817f 18469@end table
c906108c 18470
46ba6afa
BW
18471Because the arrow keys scroll the active window in the TUI mode, they
18472are not available for their normal use by readline unless the command
18473window has the focus. When another window is active, you must use
18474other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
18475and @kbd{C-f} to control the command window.
8e04817f 18476
7cf36c78
SC
18477@node TUI Single Key Mode
18478@section TUI Single Key Mode
18479@cindex TUI single key mode
18480
46ba6afa
BW
18481The TUI also provides a @dfn{SingleKey} mode, which binds several
18482frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
18483switch into this mode, where the following key bindings are used:
7cf36c78
SC
18484
18485@table @kbd
18486@kindex c @r{(SingleKey TUI key)}
18487@item c
18488continue
18489
18490@kindex d @r{(SingleKey TUI key)}
18491@item d
18492down
18493
18494@kindex f @r{(SingleKey TUI key)}
18495@item f
18496finish
18497
18498@kindex n @r{(SingleKey TUI key)}
18499@item n
18500next
18501
18502@kindex q @r{(SingleKey TUI key)}
18503@item q
46ba6afa 18504exit the SingleKey mode.
7cf36c78
SC
18505
18506@kindex r @r{(SingleKey TUI key)}
18507@item r
18508run
18509
18510@kindex s @r{(SingleKey TUI key)}
18511@item s
18512step
18513
18514@kindex u @r{(SingleKey TUI key)}
18515@item u
18516up
18517
18518@kindex v @r{(SingleKey TUI key)}
18519@item v
18520info locals
18521
18522@kindex w @r{(SingleKey TUI key)}
18523@item w
18524where
7cf36c78
SC
18525@end table
18526
18527Other keys temporarily switch to the @value{GDBN} command prompt.
18528The key that was pressed is inserted in the editing buffer so that
18529it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
18530with the TUI SingleKey mode. Once the command is entered the TUI
18531SingleKey mode is restored. The only way to permanently leave
7f9087cb 18532this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
18533
18534
8e04817f 18535@node TUI Commands
db2e3e2e 18536@section TUI-specific Commands
8e04817f
AC
18537@cindex TUI commands
18538
18539The TUI has specific commands to control the text windows.
46ba6afa
BW
18540These commands are always available, even when @value{GDBN} is not in
18541the TUI mode. When @value{GDBN} is in the standard mode, most
18542of these commands will automatically switch to the TUI mode.
c906108c
SS
18543
18544@table @code
3d757584
SC
18545@item info win
18546@kindex info win
18547List and give the size of all displayed windows.
18548
8e04817f 18549@item layout next
4644b6e3 18550@kindex layout
8e04817f 18551Display the next layout.
2df3850c 18552
8e04817f 18553@item layout prev
8e04817f 18554Display the previous layout.
c906108c 18555
8e04817f 18556@item layout src
8e04817f 18557Display the source window only.
c906108c 18558
8e04817f 18559@item layout asm
8e04817f 18560Display the assembly window only.
c906108c 18561
8e04817f 18562@item layout split
8e04817f 18563Display the source and assembly window.
c906108c 18564
8e04817f 18565@item layout regs
8e04817f
AC
18566Display the register window together with the source or assembly window.
18567
46ba6afa 18568@item focus next
8e04817f 18569@kindex focus
46ba6afa
BW
18570Make the next window active for scrolling.
18571
18572@item focus prev
18573Make the previous window active for scrolling.
18574
18575@item focus src
18576Make the source window active for scrolling.
18577
18578@item focus asm
18579Make the assembly window active for scrolling.
18580
18581@item focus regs
18582Make the register window active for scrolling.
18583
18584@item focus cmd
18585Make the command window active for scrolling.
c906108c 18586
8e04817f
AC
18587@item refresh
18588@kindex refresh
7f9087cb 18589Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 18590
6a1b180d
SC
18591@item tui reg float
18592@kindex tui reg
18593Show the floating point registers in the register window.
18594
18595@item tui reg general
18596Show the general registers in the register window.
18597
18598@item tui reg next
18599Show the next register group. The list of register groups as well as
18600their order is target specific. The predefined register groups are the
18601following: @code{general}, @code{float}, @code{system}, @code{vector},
18602@code{all}, @code{save}, @code{restore}.
18603
18604@item tui reg system
18605Show the system registers in the register window.
18606
8e04817f
AC
18607@item update
18608@kindex update
18609Update the source window and the current execution point.
c906108c 18610
8e04817f
AC
18611@item winheight @var{name} +@var{count}
18612@itemx winheight @var{name} -@var{count}
18613@kindex winheight
18614Change the height of the window @var{name} by @var{count}
18615lines. Positive counts increase the height, while negative counts
18616decrease it.
2df3850c 18617
46ba6afa
BW
18618@item tabset @var{nchars}
18619@kindex tabset
c45da7e6 18620Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
18621@end table
18622
8e04817f 18623@node TUI Configuration
79a6e687 18624@section TUI Configuration Variables
8e04817f 18625@cindex TUI configuration variables
c906108c 18626
46ba6afa 18627Several configuration variables control the appearance of TUI windows.
c906108c 18628
8e04817f
AC
18629@table @code
18630@item set tui border-kind @var{kind}
18631@kindex set tui border-kind
18632Select the border appearance for the source, assembly and register windows.
18633The possible values are the following:
18634@table @code
18635@item space
18636Use a space character to draw the border.
c906108c 18637
8e04817f 18638@item ascii
46ba6afa 18639Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 18640
8e04817f
AC
18641@item acs
18642Use the Alternate Character Set to draw the border. The border is
18643drawn using character line graphics if the terminal supports them.
8e04817f 18644@end table
c78b4128 18645
8e04817f
AC
18646@item set tui border-mode @var{mode}
18647@kindex set tui border-mode
46ba6afa
BW
18648@itemx set tui active-border-mode @var{mode}
18649@kindex set tui active-border-mode
18650Select the display attributes for the borders of the inactive windows
18651or the active window. The @var{mode} can be one of the following:
8e04817f
AC
18652@table @code
18653@item normal
18654Use normal attributes to display the border.
c906108c 18655
8e04817f
AC
18656@item standout
18657Use standout mode.
c906108c 18658
8e04817f
AC
18659@item reverse
18660Use reverse video mode.
c906108c 18661
8e04817f
AC
18662@item half
18663Use half bright mode.
c906108c 18664
8e04817f
AC
18665@item half-standout
18666Use half bright and standout mode.
c906108c 18667
8e04817f
AC
18668@item bold
18669Use extra bright or bold mode.
c78b4128 18670
8e04817f
AC
18671@item bold-standout
18672Use extra bright or bold and standout mode.
8e04817f 18673@end table
8e04817f 18674@end table
c78b4128 18675
8e04817f
AC
18676@node Emacs
18677@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 18678
8e04817f
AC
18679@cindex Emacs
18680@cindex @sc{gnu} Emacs
18681A special interface allows you to use @sc{gnu} Emacs to view (and
18682edit) the source files for the program you are debugging with
18683@value{GDBN}.
c906108c 18684
8e04817f
AC
18685To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
18686executable file you want to debug as an argument. This command starts
18687@value{GDBN} as a subprocess of Emacs, with input and output through a newly
18688created Emacs buffer.
18689@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 18690
5e252a2e 18691Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 18692things:
c906108c 18693
8e04817f
AC
18694@itemize @bullet
18695@item
5e252a2e
NR
18696All ``terminal'' input and output goes through an Emacs buffer, called
18697the GUD buffer.
c906108c 18698
8e04817f
AC
18699This applies both to @value{GDBN} commands and their output, and to the input
18700and output done by the program you are debugging.
bf0184be 18701
8e04817f
AC
18702This is useful because it means that you can copy the text of previous
18703commands and input them again; you can even use parts of the output
18704in this way.
bf0184be 18705
8e04817f
AC
18706All the facilities of Emacs' Shell mode are available for interacting
18707with your program. In particular, you can send signals the usual
18708way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
18709stop.
bf0184be
ND
18710
18711@item
8e04817f 18712@value{GDBN} displays source code through Emacs.
bf0184be 18713
8e04817f
AC
18714Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
18715source file for that frame and puts an arrow (@samp{=>}) at the
18716left margin of the current line. Emacs uses a separate buffer for
18717source display, and splits the screen to show both your @value{GDBN} session
18718and the source.
bf0184be 18719
8e04817f
AC
18720Explicit @value{GDBN} @code{list} or search commands still produce output as
18721usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
18722@end itemize
18723
18724We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
18725a graphical mode, enabled by default, which provides further buffers
18726that can control the execution and describe the state of your program.
18727@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 18728
64fabec2
AC
18729If you specify an absolute file name when prompted for the @kbd{M-x
18730gdb} argument, then Emacs sets your current working directory to where
18731your program resides. If you only specify the file name, then Emacs
18732sets your current working directory to to the directory associated
18733with the previous buffer. In this case, @value{GDBN} may find your
18734program by searching your environment's @code{PATH} variable, but on
18735some operating systems it might not find the source. So, although the
18736@value{GDBN} input and output session proceeds normally, the auxiliary
18737buffer does not display the current source and line of execution.
18738
18739The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
18740line of the GUD buffer and this serves as a default for the commands
18741that specify files for @value{GDBN} to operate on. @xref{Files,
18742,Commands to Specify Files}.
64fabec2
AC
18743
18744By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
18745need to call @value{GDBN} by a different name (for example, if you
18746keep several configurations around, with different names) you can
18747customize the Emacs variable @code{gud-gdb-command-name} to run the
18748one you want.
8e04817f 18749
5e252a2e 18750In the GUD buffer, you can use these special Emacs commands in
8e04817f 18751addition to the standard Shell mode commands:
c906108c 18752
8e04817f
AC
18753@table @kbd
18754@item C-h m
5e252a2e 18755Describe the features of Emacs' GUD Mode.
c906108c 18756
64fabec2 18757@item C-c C-s
8e04817f
AC
18758Execute to another source line, like the @value{GDBN} @code{step} command; also
18759update the display window to show the current file and location.
c906108c 18760
64fabec2 18761@item C-c C-n
8e04817f
AC
18762Execute to next source line in this function, skipping all function
18763calls, like the @value{GDBN} @code{next} command. Then update the display window
18764to show the current file and location.
c906108c 18765
64fabec2 18766@item C-c C-i
8e04817f
AC
18767Execute one instruction, like the @value{GDBN} @code{stepi} command; update
18768display window accordingly.
c906108c 18769
8e04817f
AC
18770@item C-c C-f
18771Execute until exit from the selected stack frame, like the @value{GDBN}
18772@code{finish} command.
c906108c 18773
64fabec2 18774@item C-c C-r
8e04817f
AC
18775Continue execution of your program, like the @value{GDBN} @code{continue}
18776command.
b433d00b 18777
64fabec2 18778@item C-c <
8e04817f
AC
18779Go up the number of frames indicated by the numeric argument
18780(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
18781like the @value{GDBN} @code{up} command.
b433d00b 18782
64fabec2 18783@item C-c >
8e04817f
AC
18784Go down the number of frames indicated by the numeric argument, like the
18785@value{GDBN} @code{down} command.
8e04817f 18786@end table
c906108c 18787
7f9087cb 18788In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 18789tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 18790
5e252a2e
NR
18791In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
18792separate frame which shows a backtrace when the GUD buffer is current.
18793Move point to any frame in the stack and type @key{RET} to make it
18794become the current frame and display the associated source in the
18795source buffer. Alternatively, click @kbd{Mouse-2} to make the
18796selected frame become the current one. In graphical mode, the
18797speedbar displays watch expressions.
64fabec2 18798
8e04817f
AC
18799If you accidentally delete the source-display buffer, an easy way to get
18800it back is to type the command @code{f} in the @value{GDBN} buffer, to
18801request a frame display; when you run under Emacs, this recreates
18802the source buffer if necessary to show you the context of the current
18803frame.
c906108c 18804
8e04817f
AC
18805The source files displayed in Emacs are in ordinary Emacs buffers
18806which are visiting the source files in the usual way. You can edit
18807the files with these buffers if you wish; but keep in mind that @value{GDBN}
18808communicates with Emacs in terms of line numbers. If you add or
18809delete lines from the text, the line numbers that @value{GDBN} knows cease
18810to correspond properly with the code.
b383017d 18811
5e252a2e
NR
18812A more detailed description of Emacs' interaction with @value{GDBN} is
18813given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
18814Emacs Manual}).
c906108c 18815
8e04817f
AC
18816@c The following dropped because Epoch is nonstandard. Reactivate
18817@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
18818@ignore
18819@kindex Emacs Epoch environment
18820@kindex Epoch
18821@kindex inspect
c906108c 18822
8e04817f
AC
18823Version 18 of @sc{gnu} Emacs has a built-in window system
18824called the @code{epoch}
18825environment. Users of this environment can use a new command,
18826@code{inspect} which performs identically to @code{print} except that
18827each value is printed in its own window.
18828@end ignore
c906108c 18829
922fbb7b
AC
18830
18831@node GDB/MI
18832@chapter The @sc{gdb/mi} Interface
18833
18834@unnumberedsec Function and Purpose
18835
18836@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
18837@sc{gdb/mi} is a line based machine oriented text interface to
18838@value{GDBN} and is activated by specifying using the
18839@option{--interpreter} command line option (@pxref{Mode Options}). It
18840is specifically intended to support the development of systems which
18841use the debugger as just one small component of a larger system.
922fbb7b
AC
18842
18843This chapter is a specification of the @sc{gdb/mi} interface. It is written
18844in the form of a reference manual.
18845
18846Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
18847features described below are incomplete and subject to change
18848(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
18849
18850@unnumberedsec Notation and Terminology
18851
18852@cindex notational conventions, for @sc{gdb/mi}
18853This chapter uses the following notation:
18854
18855@itemize @bullet
18856@item
18857@code{|} separates two alternatives.
18858
18859@item
18860@code{[ @var{something} ]} indicates that @var{something} is optional:
18861it may or may not be given.
18862
18863@item
18864@code{( @var{group} )*} means that @var{group} inside the parentheses
18865may repeat zero or more times.
18866
18867@item
18868@code{( @var{group} )+} means that @var{group} inside the parentheses
18869may repeat one or more times.
18870
18871@item
18872@code{"@var{string}"} means a literal @var{string}.
18873@end itemize
18874
18875@ignore
18876@heading Dependencies
18877@end ignore
18878
922fbb7b 18879@menu
c3b108f7 18880* GDB/MI General Design::
922fbb7b
AC
18881* GDB/MI Command Syntax::
18882* GDB/MI Compatibility with CLI::
af6eff6f 18883* GDB/MI Development and Front Ends::
922fbb7b 18884* GDB/MI Output Records::
ef21caaf 18885* GDB/MI Simple Examples::
922fbb7b 18886* GDB/MI Command Description Format::
ef21caaf 18887* GDB/MI Breakpoint Commands::
a2c02241
NR
18888* GDB/MI Program Context::
18889* GDB/MI Thread Commands::
18890* GDB/MI Program Execution::
18891* GDB/MI Stack Manipulation::
18892* GDB/MI Variable Objects::
922fbb7b 18893* GDB/MI Data Manipulation::
a2c02241
NR
18894* GDB/MI Tracepoint Commands::
18895* GDB/MI Symbol Query::
351ff01a 18896* GDB/MI File Commands::
922fbb7b
AC
18897@ignore
18898* GDB/MI Kod Commands::
18899* GDB/MI Memory Overlay Commands::
18900* GDB/MI Signal Handling Commands::
18901@end ignore
922fbb7b 18902* GDB/MI Target Manipulation::
a6b151f1 18903* GDB/MI File Transfer Commands::
ef21caaf 18904* GDB/MI Miscellaneous Commands::
922fbb7b
AC
18905@end menu
18906
c3b108f7
VP
18907@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18908@node GDB/MI General Design
18909@section @sc{gdb/mi} General Design
18910@cindex GDB/MI General Design
18911
18912Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
18913parts---commands sent to @value{GDBN}, responses to those commands
18914and notifications. Each command results in exactly one response,
18915indicating either successful completion of the command, or an error.
18916For the commands that do not resume the target, the response contains the
18917requested information. For the commands that resume the target, the
18918response only indicates whether the target was successfully resumed.
18919Notifications is the mechanism for reporting changes in the state of the
18920target, or in @value{GDBN} state, that cannot conveniently be associated with
18921a command and reported as part of that command response.
18922
18923The important examples of notifications are:
18924@itemize @bullet
18925
18926@item
18927Exec notifications. These are used to report changes in
18928target state---when a target is resumed, or stopped. It would not
18929be feasible to include this information in response of resuming
18930commands, because one resume commands can result in multiple events in
18931different threads. Also, quite some time may pass before any event
18932happens in the target, while a frontend needs to know whether the resuming
18933command itself was successfully executed.
18934
18935@item
18936Console output, and status notifications. Console output
18937notifications are used to report output of CLI commands, as well as
18938diagnostics for other commands. Status notifications are used to
18939report the progress of a long-running operation. Naturally, including
18940this information in command response would mean no output is produced
18941until the command is finished, which is undesirable.
18942
18943@item
18944General notifications. Commands may have various side effects on
18945the @value{GDBN} or target state beyond their official purpose. For example,
18946a command may change the selected thread. Although such changes can
18947be included in command response, using notification allows for more
18948orthogonal frontend design.
18949
18950@end itemize
18951
18952There's no guarantee that whenever an MI command reports an error,
18953@value{GDBN} or the target are in any specific state, and especially,
18954the state is not reverted to the state before the MI command was
18955processed. Therefore, whenever an MI command results in an error,
18956we recommend that the frontend refreshes all the information shown in
18957the user interface.
18958
18959@subsection Context management
18960
18961In most cases when @value{GDBN} accesses the target, this access is
18962done in context of a specific thread and frame (@pxref{Frames}).
18963Often, even when accessing global data, the target requires that a thread
18964be specified. The CLI interface maintains the selected thread and frame,
18965and supplies them to target on each command. This is convenient,
18966because a command line user would not want to specify that information
18967explicitly on each command, and because user interacts with
18968@value{GDBN} via a single terminal, so no confusion is possible as
18969to what thread and frame are the current ones.
18970
18971In the case of MI, the concept of selected thread and frame is less
18972useful. First, a frontend can easily remember this information
18973itself. Second, a graphical frontend can have more than one window,
18974each one used for debugging a different thread, and the frontend might
18975want to access additional threads for internal purposes. This
18976increases the risk that by relying on implicitly selected thread, the
18977frontend may be operating on a wrong one. Therefore, each MI command
18978should explicitly specify which thread and frame to operate on. To
18979make it possible, each MI command accepts the @samp{--thread} and
18980@samp{--frame} options, the value to each is @value{GDBN} identifier
18981for thread and frame to operate on.
18982
18983Usually, each top-level window in a frontend allows the user to select
18984a thread and a frame, and remembers the user selection for further
18985operations. However, in some cases @value{GDBN} may suggest that the
18986current thread be changed. For example, when stopping on a breakpoint
18987it is reasonable to switch to the thread where breakpoint is hit. For
18988another example, if the user issues the CLI @samp{thread} command via
18989the frontend, it is desirable to change the frontend's selected thread to the
18990one specified by user. @value{GDBN} communicates the suggestion to
18991change current thread using the @samp{=thread-selected} notification.
18992No such notification is available for the selected frame at the moment.
18993
18994Note that historically, MI shares the selected thread with CLI, so
18995frontends used the @code{-thread-select} to execute commands in the
18996right context. However, getting this to work right is cumbersome. The
18997simplest way is for frontend to emit @code{-thread-select} command
18998before every command. This doubles the number of commands that need
18999to be sent. The alternative approach is to suppress @code{-thread-select}
19000if the selected thread in @value{GDBN} is supposed to be identical to the
19001thread the frontend wants to operate on. However, getting this
19002optimization right can be tricky. In particular, if the frontend
19003sends several commands to @value{GDBN}, and one of the commands changes the
19004selected thread, then the behaviour of subsequent commands will
19005change. So, a frontend should either wait for response from such
19006problematic commands, or explicitly add @code{-thread-select} for
19007all subsequent commands. No frontend is known to do this exactly
19008right, so it is suggested to just always pass the @samp{--thread} and
19009@samp{--frame} options.
19010
19011@subsection Asynchronous command execution and non-stop mode
19012
19013On some targets, @value{GDBN} is capable of processing MI commands
19014even while the target is running. This is called @dfn{asynchronous
19015command execution} (@pxref{Background Execution}). The frontend may
19016specify a preferrence for asynchronous execution using the
19017@code{-gdb-set target-async 1} command, which should be emitted before
19018either running the executable or attaching to the target. After the
19019frontend has started the executable or attached to the target, it can
19020find if asynchronous execution is enabled using the
19021@code{-list-target-features} command.
19022
19023Even if @value{GDBN} can accept a command while target is running,
19024many commands that access the target do not work when the target is
19025running. Therefore, asynchronous command execution is most useful
19026when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
19027it is possible to examine the state of one thread, while other threads
19028are running.
19029
19030When a given thread is running, MI commands that try to access the
19031target in the context of that thread may not work, or may work only on
19032some targets. In particular, commands that try to operate on thread's
19033stack will not work, on any target. Commands that read memory, or
19034modify breakpoints, may work or not work, depending on the target. Note
19035that even commands that operate on global state, such as @code{print},
19036@code{set}, and breakpoint commands, still access the target in the
19037context of a specific thread, so frontend should try to find a
19038stopped thread and perform the operation on that thread (using the
19039@samp{--thread} option).
19040
19041Which commands will work in the context of a running thread is
19042highly target dependent. However, the two commands
19043@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
19044to find the state of a thread, will always work.
19045
19046@subsection Thread groups
19047@value{GDBN} may be used to debug several processes at the same time.
19048On some platfroms, @value{GDBN} may support debugging of several
19049hardware systems, each one having several cores with several different
19050processes running on each core. This section describes the MI
19051mechanism to support such debugging scenarios.
19052
19053The key observation is that regardless of the structure of the
19054target, MI can have a global list of threads, because most commands that
19055accept the @samp{--thread} option do not need to know what process that
19056thread belongs to. Therefore, it is not necessary to introduce
19057neither additional @samp{--process} option, nor an notion of the
19058current process in the MI interface. The only strictly new feature
19059that is required is the ability to find how the threads are grouped
19060into processes.
19061
19062To allow the user to discover such grouping, and to support arbitrary
19063hierarchy of machines/cores/processes, MI introduces the concept of a
19064@dfn{thread group}. Thread group is a collection of threads and other
19065thread groups. A thread group always has a string identifier, a type,
19066and may have additional attributes specific to the type. A new
19067command, @code{-list-thread-groups}, returns the list of top-level
19068thread groups, which correspond to processes that @value{GDBN} is
19069debugging at the moment. By passing an identifier of a thread group
19070to the @code{-list-thread-groups} command, it is possible to obtain
19071the members of specific thread group.
19072
19073To allow the user to easily discover processes, and other objects, he
19074wishes to debug, a concept of @dfn{available thread group} is
19075introduced. Available thread group is an thread group that
19076@value{GDBN} is not debugging, but that can be attached to, using the
19077@code{-target-attach} command. The list of available top-level thread
19078groups can be obtained using @samp{-list-thread-groups --available}.
19079In general, the content of a thread group may be only retrieved only
19080after attaching to that thread group.
19081
922fbb7b
AC
19082@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19083@node GDB/MI Command Syntax
19084@section @sc{gdb/mi} Command Syntax
19085
19086@menu
19087* GDB/MI Input Syntax::
19088* GDB/MI Output Syntax::
922fbb7b
AC
19089@end menu
19090
19091@node GDB/MI Input Syntax
19092@subsection @sc{gdb/mi} Input Syntax
19093
19094@cindex input syntax for @sc{gdb/mi}
19095@cindex @sc{gdb/mi}, input syntax
19096@table @code
19097@item @var{command} @expansion{}
19098@code{@var{cli-command} | @var{mi-command}}
19099
19100@item @var{cli-command} @expansion{}
19101@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
19102@var{cli-command} is any existing @value{GDBN} CLI command.
19103
19104@item @var{mi-command} @expansion{}
19105@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
19106@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
19107
19108@item @var{token} @expansion{}
19109"any sequence of digits"
19110
19111@item @var{option} @expansion{}
19112@code{"-" @var{parameter} [ " " @var{parameter} ]}
19113
19114@item @var{parameter} @expansion{}
19115@code{@var{non-blank-sequence} | @var{c-string}}
19116
19117@item @var{operation} @expansion{}
19118@emph{any of the operations described in this chapter}
19119
19120@item @var{non-blank-sequence} @expansion{}
19121@emph{anything, provided it doesn't contain special characters such as
19122"-", @var{nl}, """ and of course " "}
19123
19124@item @var{c-string} @expansion{}
19125@code{""" @var{seven-bit-iso-c-string-content} """}
19126
19127@item @var{nl} @expansion{}
19128@code{CR | CR-LF}
19129@end table
19130
19131@noindent
19132Notes:
19133
19134@itemize @bullet
19135@item
19136The CLI commands are still handled by the @sc{mi} interpreter; their
19137output is described below.
19138
19139@item
19140The @code{@var{token}}, when present, is passed back when the command
19141finishes.
19142
19143@item
19144Some @sc{mi} commands accept optional arguments as part of the parameter
19145list. Each option is identified by a leading @samp{-} (dash) and may be
19146followed by an optional argument parameter. Options occur first in the
19147parameter list and can be delimited from normal parameters using
19148@samp{--} (this is useful when some parameters begin with a dash).
19149@end itemize
19150
19151Pragmatics:
19152
19153@itemize @bullet
19154@item
19155We want easy access to the existing CLI syntax (for debugging).
19156
19157@item
19158We want it to be easy to spot a @sc{mi} operation.
19159@end itemize
19160
19161@node GDB/MI Output Syntax
19162@subsection @sc{gdb/mi} Output Syntax
19163
19164@cindex output syntax of @sc{gdb/mi}
19165@cindex @sc{gdb/mi}, output syntax
19166The output from @sc{gdb/mi} consists of zero or more out-of-band records
19167followed, optionally, by a single result record. This result record
19168is for the most recent command. The sequence of output records is
594fe323 19169terminated by @samp{(gdb)}.
922fbb7b
AC
19170
19171If an input command was prefixed with a @code{@var{token}} then the
19172corresponding output for that command will also be prefixed by that same
19173@var{token}.
19174
19175@table @code
19176@item @var{output} @expansion{}
594fe323 19177@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
19178
19179@item @var{result-record} @expansion{}
19180@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
19181
19182@item @var{out-of-band-record} @expansion{}
19183@code{@var{async-record} | @var{stream-record}}
19184
19185@item @var{async-record} @expansion{}
19186@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
19187
19188@item @var{exec-async-output} @expansion{}
19189@code{[ @var{token} ] "*" @var{async-output}}
19190
19191@item @var{status-async-output} @expansion{}
19192@code{[ @var{token} ] "+" @var{async-output}}
19193
19194@item @var{notify-async-output} @expansion{}
19195@code{[ @var{token} ] "=" @var{async-output}}
19196
19197@item @var{async-output} @expansion{}
19198@code{@var{async-class} ( "," @var{result} )* @var{nl}}
19199
19200@item @var{result-class} @expansion{}
19201@code{"done" | "running" | "connected" | "error" | "exit"}
19202
19203@item @var{async-class} @expansion{}
19204@code{"stopped" | @var{others}} (where @var{others} will be added
19205depending on the needs---this is still in development).
19206
19207@item @var{result} @expansion{}
19208@code{ @var{variable} "=" @var{value}}
19209
19210@item @var{variable} @expansion{}
19211@code{ @var{string} }
19212
19213@item @var{value} @expansion{}
19214@code{ @var{const} | @var{tuple} | @var{list} }
19215
19216@item @var{const} @expansion{}
19217@code{@var{c-string}}
19218
19219@item @var{tuple} @expansion{}
19220@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
19221
19222@item @var{list} @expansion{}
19223@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
19224@var{result} ( "," @var{result} )* "]" }
19225
19226@item @var{stream-record} @expansion{}
19227@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
19228
19229@item @var{console-stream-output} @expansion{}
19230@code{"~" @var{c-string}}
19231
19232@item @var{target-stream-output} @expansion{}
19233@code{"@@" @var{c-string}}
19234
19235@item @var{log-stream-output} @expansion{}
19236@code{"&" @var{c-string}}
19237
19238@item @var{nl} @expansion{}
19239@code{CR | CR-LF}
19240
19241@item @var{token} @expansion{}
19242@emph{any sequence of digits}.
19243@end table
19244
19245@noindent
19246Notes:
19247
19248@itemize @bullet
19249@item
19250All output sequences end in a single line containing a period.
19251
19252@item
721c02de
VP
19253The @code{@var{token}} is from the corresponding request. Note that
19254for all async output, while the token is allowed by the grammar and
19255may be output by future versions of @value{GDBN} for select async
19256output messages, it is generally omitted. Frontends should treat
19257all async output as reporting general changes in the state of the
19258target and there should be no need to associate async output to any
19259prior command.
922fbb7b
AC
19260
19261@item
19262@cindex status output in @sc{gdb/mi}
19263@var{status-async-output} contains on-going status information about the
19264progress of a slow operation. It can be discarded. All status output is
19265prefixed by @samp{+}.
19266
19267@item
19268@cindex async output in @sc{gdb/mi}
19269@var{exec-async-output} contains asynchronous state change on the target
19270(stopped, started, disappeared). All async output is prefixed by
19271@samp{*}.
19272
19273@item
19274@cindex notify output in @sc{gdb/mi}
19275@var{notify-async-output} contains supplementary information that the
19276client should handle (e.g., a new breakpoint information). All notify
19277output is prefixed by @samp{=}.
19278
19279@item
19280@cindex console output in @sc{gdb/mi}
19281@var{console-stream-output} is output that should be displayed as is in the
19282console. It is the textual response to a CLI command. All the console
19283output is prefixed by @samp{~}.
19284
19285@item
19286@cindex target output in @sc{gdb/mi}
19287@var{target-stream-output} is the output produced by the target program.
19288All the target output is prefixed by @samp{@@}.
19289
19290@item
19291@cindex log output in @sc{gdb/mi}
19292@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
19293instance messages that should be displayed as part of an error log. All
19294the log output is prefixed by @samp{&}.
19295
19296@item
19297@cindex list output in @sc{gdb/mi}
19298New @sc{gdb/mi} commands should only output @var{lists} containing
19299@var{values}.
19300
19301
19302@end itemize
19303
19304@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
19305details about the various output records.
19306
922fbb7b
AC
19307@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19308@node GDB/MI Compatibility with CLI
19309@section @sc{gdb/mi} Compatibility with CLI
19310
19311@cindex compatibility, @sc{gdb/mi} and CLI
19312@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 19313
a2c02241
NR
19314For the developers convenience CLI commands can be entered directly,
19315but there may be some unexpected behaviour. For example, commands
19316that query the user will behave as if the user replied yes, breakpoint
19317command lists are not executed and some CLI commands, such as
19318@code{if}, @code{when} and @code{define}, prompt for further input with
19319@samp{>}, which is not valid MI output.
ef21caaf
NR
19320
19321This feature may be removed at some stage in the future and it is
a2c02241
NR
19322recommended that front ends use the @code{-interpreter-exec} command
19323(@pxref{-interpreter-exec}).
922fbb7b 19324
af6eff6f
NR
19325@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19326@node GDB/MI Development and Front Ends
19327@section @sc{gdb/mi} Development and Front Ends
19328@cindex @sc{gdb/mi} development
19329
19330The application which takes the MI output and presents the state of the
19331program being debugged to the user is called a @dfn{front end}.
19332
19333Although @sc{gdb/mi} is still incomplete, it is currently being used
19334by a variety of front ends to @value{GDBN}. This makes it difficult
19335to introduce new functionality without breaking existing usage. This
19336section tries to minimize the problems by describing how the protocol
19337might change.
19338
19339Some changes in MI need not break a carefully designed front end, and
19340for these the MI version will remain unchanged. The following is a
19341list of changes that may occur within one level, so front ends should
19342parse MI output in a way that can handle them:
19343
19344@itemize @bullet
19345@item
19346New MI commands may be added.
19347
19348@item
19349New fields may be added to the output of any MI command.
19350
36ece8b3
NR
19351@item
19352The range of values for fields with specified values, e.g.,
9f708cb2 19353@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 19354
af6eff6f
NR
19355@c The format of field's content e.g type prefix, may change so parse it
19356@c at your own risk. Yes, in general?
19357
19358@c The order of fields may change? Shouldn't really matter but it might
19359@c resolve inconsistencies.
19360@end itemize
19361
19362If the changes are likely to break front ends, the MI version level
19363will be increased by one. This will allow the front end to parse the
19364output according to the MI version. Apart from mi0, new versions of
19365@value{GDBN} will not support old versions of MI and it will be the
19366responsibility of the front end to work with the new one.
19367
19368@c Starting with mi3, add a new command -mi-version that prints the MI
19369@c version?
19370
19371The best way to avoid unexpected changes in MI that might break your front
19372end is to make your project known to @value{GDBN} developers and
7a9a6b69 19373follow development on @email{gdb@@sourceware.org} and
fa0f268d 19374@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
19375@cindex mailing lists
19376
922fbb7b
AC
19377@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19378@node GDB/MI Output Records
19379@section @sc{gdb/mi} Output Records
19380
19381@menu
19382* GDB/MI Result Records::
19383* GDB/MI Stream Records::
82f68b1c 19384* GDB/MI Async Records::
c3b108f7 19385* GDB/MI Frame Information::
922fbb7b
AC
19386@end menu
19387
19388@node GDB/MI Result Records
19389@subsection @sc{gdb/mi} Result Records
19390
19391@cindex result records in @sc{gdb/mi}
19392@cindex @sc{gdb/mi}, result records
19393In addition to a number of out-of-band notifications, the response to a
19394@sc{gdb/mi} command includes one of the following result indications:
19395
19396@table @code
19397@findex ^done
19398@item "^done" [ "," @var{results} ]
19399The synchronous operation was successful, @code{@var{results}} are the return
19400values.
19401
19402@item "^running"
19403@findex ^running
19404@c Is this one correct? Should it be an out-of-band notification?
19405The asynchronous operation was successfully started. The target is
19406running.
19407
ef21caaf
NR
19408@item "^connected"
19409@findex ^connected
3f94c067 19410@value{GDBN} has connected to a remote target.
ef21caaf 19411
922fbb7b
AC
19412@item "^error" "," @var{c-string}
19413@findex ^error
19414The operation failed. The @code{@var{c-string}} contains the corresponding
19415error message.
ef21caaf
NR
19416
19417@item "^exit"
19418@findex ^exit
3f94c067 19419@value{GDBN} has terminated.
ef21caaf 19420
922fbb7b
AC
19421@end table
19422
19423@node GDB/MI Stream Records
19424@subsection @sc{gdb/mi} Stream Records
19425
19426@cindex @sc{gdb/mi}, stream records
19427@cindex stream records in @sc{gdb/mi}
19428@value{GDBN} internally maintains a number of output streams: the console, the
19429target, and the log. The output intended for each of these streams is
19430funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
19431
19432Each stream record begins with a unique @dfn{prefix character} which
19433identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
19434Syntax}). In addition to the prefix, each stream record contains a
19435@code{@var{string-output}}. This is either raw text (with an implicit new
19436line) or a quoted C string (which does not contain an implicit newline).
19437
19438@table @code
19439@item "~" @var{string-output}
19440The console output stream contains text that should be displayed in the
19441CLI console window. It contains the textual responses to CLI commands.
19442
19443@item "@@" @var{string-output}
19444The target output stream contains any textual output from the running
ef21caaf
NR
19445target. This is only present when GDB's event loop is truly
19446asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
19447
19448@item "&" @var{string-output}
19449The log stream contains debugging messages being produced by @value{GDBN}'s
19450internals.
19451@end table
19452
82f68b1c
VP
19453@node GDB/MI Async Records
19454@subsection @sc{gdb/mi} Async Records
922fbb7b 19455
82f68b1c
VP
19456@cindex async records in @sc{gdb/mi}
19457@cindex @sc{gdb/mi}, async records
19458@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 19459additional changes that have occurred. Those changes can either be a
82f68b1c 19460consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
19461target activity (e.g., target stopped).
19462
8eb41542 19463The following is the list of possible async records:
922fbb7b
AC
19464
19465@table @code
034dad6f 19466
e1ac3328
VP
19467@item *running,thread-id="@var{thread}"
19468The target is now running. The @var{thread} field tells which
19469specific thread is now running, and can be @samp{all} if all threads
19470are running. The frontend should assume that no interaction with a
19471running thread is possible after this notification is produced.
19472The frontend should not assume that this notification is output
19473only once for any command. @value{GDBN} may emit this notification
19474several times, either for different threads, because it cannot resume
19475all threads together, or even for a single thread, if the thread must
19476be stepped though some code before letting it run freely.
19477
c3b108f7 19478@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}"
82f68b1c
VP
19479The target has stopped. The @var{reason} field can have one of the
19480following values:
034dad6f
BR
19481
19482@table @code
19483@item breakpoint-hit
19484A breakpoint was reached.
19485@item watchpoint-trigger
19486A watchpoint was triggered.
19487@item read-watchpoint-trigger
19488A read watchpoint was triggered.
19489@item access-watchpoint-trigger
19490An access watchpoint was triggered.
19491@item function-finished
19492An -exec-finish or similar CLI command was accomplished.
19493@item location-reached
19494An -exec-until or similar CLI command was accomplished.
19495@item watchpoint-scope
19496A watchpoint has gone out of scope.
19497@item end-stepping-range
19498An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
19499similar CLI command was accomplished.
19500@item exited-signalled
19501The inferior exited because of a signal.
19502@item exited
19503The inferior exited.
19504@item exited-normally
19505The inferior exited normally.
19506@item signal-received
19507A signal was received by the inferior.
922fbb7b
AC
19508@end table
19509
c3b108f7
VP
19510The @var{id} field identifies the thread that directly caused the stop
19511-- for example by hitting a breakpoint. Depending on whether all-stop
19512mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
19513stop all threads, or only the thread that directly triggered the stop.
19514If all threads are stopped, the @var{stopped} field will have the
19515value of @code{"all"}. Otherwise, the value of the @var{stopped}
19516field will be a list of thread identifiers. Presently, this list will
19517always include a single thread, but frontend should be prepared to see
19518several threads in the list.
19519
19520@item =thread-group-created,id="@var{id}"
19521@itemx =thread-group-exited,id="@var{id}"
19522A thread thread group either was attached to, or has exited/detached
19523from. The @var{id} field contains the @value{GDBN} identifier of the
19524thread group.
19525
19526@item =thread-created,id="@var{id}",group-id="@var{gid}"
19527@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 19528A thread either was created, or has exited. The @var{id} field
c3b108f7
VP
19529contains the @value{GDBN} identifier of the thread. The @var{gid}
19530field identifies the thread group this thread belongs to.
66bb093b
VP
19531
19532@item =thread-selected,id="@var{id}"
19533Informs that the selected thread was changed as result of the last
19534command. This notification is not emitted as result of @code{-thread-select}
19535command but is emitted whenever an MI command that is not documented
19536to change the selected thread actually changes it. In particular,
19537invoking, directly or indirectly (via user-defined command), the CLI
19538@code{thread} command, will generate this notification.
19539
19540We suggest that in response to this notification, front ends
19541highlight the selected thread and cause subsequent commands to apply to
19542that thread.
19543
82f68b1c
VP
19544@end table
19545
c3b108f7
VP
19546@node GDB/MI Frame Information
19547@subsection @sc{gdb/mi} Frame Information
19548
19549Response from many MI commands includes an information about stack
19550frame. This information is a tuple that may have the following
19551fields:
19552
19553@table @code
19554@item level
19555The level of the stack frame. The innermost frame has the level of
19556zero. This field is always present.
19557
19558@item func
19559The name of the function corresponding to the frame. This field may
19560be absent if @value{GDBN} is unable to determine the function name.
19561
19562@item addr
19563The code address for the frame. This field is always present.
19564
19565@item file
19566The name of the source files that correspond to the frame's code
19567address. This field may be absent.
19568
19569@item line
19570The source line corresponding to the frames' code address. This field
19571may be absent.
19572
19573@item from
19574The name of the binary file (either executable or shared library) the
19575corresponds to the frame's code address. This field may be absent.
19576
19577@end table
82f68b1c 19578
922fbb7b 19579
ef21caaf
NR
19580@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19581@node GDB/MI Simple Examples
19582@section Simple Examples of @sc{gdb/mi} Interaction
19583@cindex @sc{gdb/mi}, simple examples
19584
19585This subsection presents several simple examples of interaction using
19586the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
19587following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
19588the output received from @sc{gdb/mi}.
19589
d3e8051b 19590Note the line breaks shown in the examples are here only for
ef21caaf
NR
19591readability, they don't appear in the real output.
19592
79a6e687 19593@subheading Setting a Breakpoint
ef21caaf
NR
19594
19595Setting a breakpoint generates synchronous output which contains detailed
19596information of the breakpoint.
19597
19598@smallexample
19599-> -break-insert main
19600<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
19601 enabled="y",addr="0x08048564",func="main",file="myprog.c",
19602 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
19603<- (gdb)
19604@end smallexample
19605
19606@subheading Program Execution
19607
19608Program execution generates asynchronous records and MI gives the
19609reason that execution stopped.
19610
19611@smallexample
19612-> -exec-run
19613<- ^running
19614<- (gdb)
a47ec5fe 19615<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
19616 frame=@{addr="0x08048564",func="main",
19617 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
19618 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
19619<- (gdb)
19620-> -exec-continue
19621<- ^running
19622<- (gdb)
19623<- *stopped,reason="exited-normally"
19624<- (gdb)
19625@end smallexample
19626
3f94c067 19627@subheading Quitting @value{GDBN}
ef21caaf 19628
3f94c067 19629Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
19630
19631@smallexample
19632-> (gdb)
19633<- -gdb-exit
19634<- ^exit
19635@end smallexample
19636
a2c02241 19637@subheading A Bad Command
ef21caaf
NR
19638
19639Here's what happens if you pass a non-existent command:
19640
19641@smallexample
19642-> -rubbish
19643<- ^error,msg="Undefined MI command: rubbish"
594fe323 19644<- (gdb)
ef21caaf
NR
19645@end smallexample
19646
19647
922fbb7b
AC
19648@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19649@node GDB/MI Command Description Format
19650@section @sc{gdb/mi} Command Description Format
19651
19652The remaining sections describe blocks of commands. Each block of
19653commands is laid out in a fashion similar to this section.
19654
922fbb7b
AC
19655@subheading Motivation
19656
19657The motivation for this collection of commands.
19658
19659@subheading Introduction
19660
19661A brief introduction to this collection of commands as a whole.
19662
19663@subheading Commands
19664
19665For each command in the block, the following is described:
19666
19667@subsubheading Synopsis
19668
19669@smallexample
19670 -command @var{args}@dots{}
19671@end smallexample
19672
922fbb7b
AC
19673@subsubheading Result
19674
265eeb58 19675@subsubheading @value{GDBN} Command
922fbb7b 19676
265eeb58 19677The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
19678
19679@subsubheading Example
19680
ef21caaf
NR
19681Example(s) formatted for readability. Some of the described commands have
19682not been implemented yet and these are labeled N.A.@: (not available).
19683
19684
922fbb7b 19685@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
19686@node GDB/MI Breakpoint Commands
19687@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
19688
19689@cindex breakpoint commands for @sc{gdb/mi}
19690@cindex @sc{gdb/mi}, breakpoint commands
19691This section documents @sc{gdb/mi} commands for manipulating
19692breakpoints.
19693
19694@subheading The @code{-break-after} Command
19695@findex -break-after
19696
19697@subsubheading Synopsis
19698
19699@smallexample
19700 -break-after @var{number} @var{count}
19701@end smallexample
19702
19703The breakpoint number @var{number} is not in effect until it has been
19704hit @var{count} times. To see how this is reflected in the output of
19705the @samp{-break-list} command, see the description of the
19706@samp{-break-list} command below.
19707
19708@subsubheading @value{GDBN} Command
19709
19710The corresponding @value{GDBN} command is @samp{ignore}.
19711
19712@subsubheading Example
19713
19714@smallexample
594fe323 19715(gdb)
922fbb7b 19716-break-insert main
a47ec5fe
AR
19717^done,bkpt=@{number="1",type="breakpoint",disp="keep",
19718enabled="y",addr="0x000100d0",func="main",file="hello.c",
948d5102 19719fullname="/home/foo/hello.c",line="5",times="0"@}
594fe323 19720(gdb)
922fbb7b
AC
19721-break-after 1 3
19722~
19723^done
594fe323 19724(gdb)
922fbb7b
AC
19725-break-list
19726^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19727hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19728@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19729@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19730@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19731@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19732@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19733body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
19734addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19735line="5",times="0",ignore="3"@}]@}
594fe323 19736(gdb)
922fbb7b
AC
19737@end smallexample
19738
19739@ignore
19740@subheading The @code{-break-catch} Command
19741@findex -break-catch
19742
19743@subheading The @code{-break-commands} Command
19744@findex -break-commands
19745@end ignore
19746
19747
19748@subheading The @code{-break-condition} Command
19749@findex -break-condition
19750
19751@subsubheading Synopsis
19752
19753@smallexample
19754 -break-condition @var{number} @var{expr}
19755@end smallexample
19756
19757Breakpoint @var{number} will stop the program only if the condition in
19758@var{expr} is true. The condition becomes part of the
19759@samp{-break-list} output (see the description of the @samp{-break-list}
19760command below).
19761
19762@subsubheading @value{GDBN} Command
19763
19764The corresponding @value{GDBN} command is @samp{condition}.
19765
19766@subsubheading Example
19767
19768@smallexample
594fe323 19769(gdb)
922fbb7b
AC
19770-break-condition 1 1
19771^done
594fe323 19772(gdb)
922fbb7b
AC
19773-break-list
19774^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19775hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19776@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19777@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19778@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19779@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19780@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19781body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
19782addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19783line="5",cond="1",times="0",ignore="3"@}]@}
594fe323 19784(gdb)
922fbb7b
AC
19785@end smallexample
19786
19787@subheading The @code{-break-delete} Command
19788@findex -break-delete
19789
19790@subsubheading Synopsis
19791
19792@smallexample
19793 -break-delete ( @var{breakpoint} )+
19794@end smallexample
19795
19796Delete the breakpoint(s) whose number(s) are specified in the argument
19797list. This is obviously reflected in the breakpoint list.
19798
79a6e687 19799@subsubheading @value{GDBN} Command
922fbb7b
AC
19800
19801The corresponding @value{GDBN} command is @samp{delete}.
19802
19803@subsubheading Example
19804
19805@smallexample
594fe323 19806(gdb)
922fbb7b
AC
19807-break-delete 1
19808^done
594fe323 19809(gdb)
922fbb7b
AC
19810-break-list
19811^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
19812hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19813@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19814@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19815@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19816@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19817@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19818body=[]@}
594fe323 19819(gdb)
922fbb7b
AC
19820@end smallexample
19821
19822@subheading The @code{-break-disable} Command
19823@findex -break-disable
19824
19825@subsubheading Synopsis
19826
19827@smallexample
19828 -break-disable ( @var{breakpoint} )+
19829@end smallexample
19830
19831Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
19832break list is now set to @samp{n} for the named @var{breakpoint}(s).
19833
19834@subsubheading @value{GDBN} Command
19835
19836The corresponding @value{GDBN} command is @samp{disable}.
19837
19838@subsubheading Example
19839
19840@smallexample
594fe323 19841(gdb)
922fbb7b
AC
19842-break-disable 2
19843^done
594fe323 19844(gdb)
922fbb7b
AC
19845-break-list
19846^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19847hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19848@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19849@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19850@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19851@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19852@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19853body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102
NR
19854addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19855line="5",times="0"@}]@}
594fe323 19856(gdb)
922fbb7b
AC
19857@end smallexample
19858
19859@subheading The @code{-break-enable} Command
19860@findex -break-enable
19861
19862@subsubheading Synopsis
19863
19864@smallexample
19865 -break-enable ( @var{breakpoint} )+
19866@end smallexample
19867
19868Enable (previously disabled) @var{breakpoint}(s).
19869
19870@subsubheading @value{GDBN} Command
19871
19872The corresponding @value{GDBN} command is @samp{enable}.
19873
19874@subsubheading Example
19875
19876@smallexample
594fe323 19877(gdb)
922fbb7b
AC
19878-break-enable 2
19879^done
594fe323 19880(gdb)
922fbb7b
AC
19881-break-list
19882^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19883hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19884@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19885@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19886@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19887@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19888@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19889body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
19890addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19891line="5",times="0"@}]@}
594fe323 19892(gdb)
922fbb7b
AC
19893@end smallexample
19894
19895@subheading The @code{-break-info} Command
19896@findex -break-info
19897
19898@subsubheading Synopsis
19899
19900@smallexample
19901 -break-info @var{breakpoint}
19902@end smallexample
19903
19904@c REDUNDANT???
19905Get information about a single breakpoint.
19906
79a6e687 19907@subsubheading @value{GDBN} Command
922fbb7b
AC
19908
19909The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
19910
19911@subsubheading Example
19912N.A.
19913
19914@subheading The @code{-break-insert} Command
19915@findex -break-insert
19916
19917@subsubheading Synopsis
19918
19919@smallexample
afe8ab22 19920 -break-insert [ -t ] [ -h ] [ -f ]
922fbb7b 19921 [ -c @var{condition} ] [ -i @var{ignore-count} ]
afe8ab22 19922 [ -p @var{thread} ] [ @var{location} ]
922fbb7b
AC
19923@end smallexample
19924
19925@noindent
afe8ab22 19926If specified, @var{location}, can be one of:
922fbb7b
AC
19927
19928@itemize @bullet
19929@item function
19930@c @item +offset
19931@c @item -offset
19932@c @item linenum
19933@item filename:linenum
19934@item filename:function
19935@item *address
19936@end itemize
19937
19938The possible optional parameters of this command are:
19939
19940@table @samp
19941@item -t
948d5102 19942Insert a temporary breakpoint.
922fbb7b
AC
19943@item -h
19944Insert a hardware breakpoint.
19945@item -c @var{condition}
19946Make the breakpoint conditional on @var{condition}.
19947@item -i @var{ignore-count}
19948Initialize the @var{ignore-count}.
afe8ab22
VP
19949@item -f
19950If @var{location} cannot be parsed (for example if it
19951refers to unknown files or functions), create a pending
19952breakpoint. Without this flag, @value{GDBN} will report
19953an error, and won't create a breakpoint, if @var{location}
19954cannot be parsed.
922fbb7b
AC
19955@end table
19956
19957@subsubheading Result
19958
19959The result is in the form:
19960
19961@smallexample
948d5102
NR
19962^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
19963enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
ef21caaf
NR
19964fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
19965times="@var{times}"@}
922fbb7b
AC
19966@end smallexample
19967
19968@noindent
948d5102
NR
19969where @var{number} is the @value{GDBN} number for this breakpoint,
19970@var{funcname} is the name of the function where the breakpoint was
19971inserted, @var{filename} is the name of the source file which contains
19972this function, @var{lineno} is the source line number within that file
19973and @var{times} the number of times that the breakpoint has been hit
19974(always 0 for -break-insert but may be greater for -break-info or -break-list
19975which use the same output).
922fbb7b
AC
19976
19977Note: this format is open to change.
19978@c An out-of-band breakpoint instead of part of the result?
19979
19980@subsubheading @value{GDBN} Command
19981
19982The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
19983@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
19984
19985@subsubheading Example
19986
19987@smallexample
594fe323 19988(gdb)
922fbb7b 19989-break-insert main
948d5102
NR
19990^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
19991fullname="/home/foo/recursive2.c,line="4",times="0"@}
594fe323 19992(gdb)
922fbb7b 19993-break-insert -t foo
948d5102
NR
19994^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
19995fullname="/home/foo/recursive2.c,line="11",times="0"@}
594fe323 19996(gdb)
922fbb7b
AC
19997-break-list
19998^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
19999hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20000@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20001@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20002@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20003@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20004@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20005body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
20006addr="0x0001072c", func="main",file="recursive2.c",
20007fullname="/home/foo/recursive2.c,"line="4",times="0"@},
922fbb7b 20008bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102
NR
20009addr="0x00010774",func="foo",file="recursive2.c",
20010fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
594fe323 20011(gdb)
922fbb7b
AC
20012-break-insert -r foo.*
20013~int foo(int, int);
948d5102
NR
20014^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
20015"fullname="/home/foo/recursive2.c",line="11",times="0"@}
594fe323 20016(gdb)
922fbb7b
AC
20017@end smallexample
20018
20019@subheading The @code{-break-list} Command
20020@findex -break-list
20021
20022@subsubheading Synopsis
20023
20024@smallexample
20025 -break-list
20026@end smallexample
20027
20028Displays the list of inserted breakpoints, showing the following fields:
20029
20030@table @samp
20031@item Number
20032number of the breakpoint
20033@item Type
20034type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
20035@item Disposition
20036should the breakpoint be deleted or disabled when it is hit: @samp{keep}
20037or @samp{nokeep}
20038@item Enabled
20039is the breakpoint enabled or no: @samp{y} or @samp{n}
20040@item Address
20041memory location at which the breakpoint is set
20042@item What
20043logical location of the breakpoint, expressed by function name, file
20044name, line number
20045@item Times
20046number of times the breakpoint has been hit
20047@end table
20048
20049If there are no breakpoints or watchpoints, the @code{BreakpointTable}
20050@code{body} field is an empty list.
20051
20052@subsubheading @value{GDBN} Command
20053
20054The corresponding @value{GDBN} command is @samp{info break}.
20055
20056@subsubheading Example
20057
20058@smallexample
594fe323 20059(gdb)
922fbb7b
AC
20060-break-list
20061^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
20062hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20063@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20064@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20065@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20066@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20067@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20068body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20069addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
20070bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
20071addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
20072line="13",times="0"@}]@}
594fe323 20073(gdb)
922fbb7b
AC
20074@end smallexample
20075
20076Here's an example of the result when there are no breakpoints:
20077
20078@smallexample
594fe323 20079(gdb)
922fbb7b
AC
20080-break-list
20081^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
20082hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20083@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20084@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20085@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20086@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20087@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20088body=[]@}
594fe323 20089(gdb)
922fbb7b
AC
20090@end smallexample
20091
20092@subheading The @code{-break-watch} Command
20093@findex -break-watch
20094
20095@subsubheading Synopsis
20096
20097@smallexample
20098 -break-watch [ -a | -r ]
20099@end smallexample
20100
20101Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 20102@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 20103read from or on a write to the memory location. With the @samp{-r}
d3e8051b 20104option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
20105trigger only when the memory location is accessed for reading. Without
20106either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 20107i.e., it will trigger when the memory location is accessed for writing.
79a6e687 20108@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
20109
20110Note that @samp{-break-list} will report a single list of watchpoints and
20111breakpoints inserted.
20112
20113@subsubheading @value{GDBN} Command
20114
20115The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
20116@samp{rwatch}.
20117
20118@subsubheading Example
20119
20120Setting a watchpoint on a variable in the @code{main} function:
20121
20122@smallexample
594fe323 20123(gdb)
922fbb7b
AC
20124-break-watch x
20125^done,wpt=@{number="2",exp="x"@}
594fe323 20126(gdb)
922fbb7b
AC
20127-exec-continue
20128^running
0869d01b
NR
20129(gdb)
20130*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 20131value=@{old="-268439212",new="55"@},
76ff342d 20132frame=@{func="main",args=[],file="recursive2.c",
948d5102 20133fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 20134(gdb)
922fbb7b
AC
20135@end smallexample
20136
20137Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
20138the program execution twice: first for the variable changing value, then
20139for the watchpoint going out of scope.
20140
20141@smallexample
594fe323 20142(gdb)
922fbb7b
AC
20143-break-watch C
20144^done,wpt=@{number="5",exp="C"@}
594fe323 20145(gdb)
922fbb7b
AC
20146-exec-continue
20147^running
0869d01b
NR
20148(gdb)
20149*stopped,reason="watchpoint-trigger",
922fbb7b
AC
20150wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
20151frame=@{func="callee4",args=[],
76ff342d
DJ
20152file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20153fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 20154(gdb)
922fbb7b
AC
20155-exec-continue
20156^running
0869d01b
NR
20157(gdb)
20158*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
20159frame=@{func="callee3",args=[@{name="strarg",
20160value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
20161file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20162fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 20163(gdb)
922fbb7b
AC
20164@end smallexample
20165
20166Listing breakpoints and watchpoints, at different points in the program
20167execution. Note that once the watchpoint goes out of scope, it is
20168deleted.
20169
20170@smallexample
594fe323 20171(gdb)
922fbb7b
AC
20172-break-watch C
20173^done,wpt=@{number="2",exp="C"@}
594fe323 20174(gdb)
922fbb7b
AC
20175-break-list
20176^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
20177hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20178@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20179@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20180@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20181@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20182@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20183body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20184addr="0x00010734",func="callee4",
948d5102
NR
20185file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20186fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
922fbb7b
AC
20187bkpt=@{number="2",type="watchpoint",disp="keep",
20188enabled="y",addr="",what="C",times="0"@}]@}
594fe323 20189(gdb)
922fbb7b
AC
20190-exec-continue
20191^running
0869d01b
NR
20192(gdb)
20193*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
20194value=@{old="-276895068",new="3"@},
20195frame=@{func="callee4",args=[],
76ff342d
DJ
20196file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20197fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 20198(gdb)
922fbb7b
AC
20199-break-list
20200^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
20201hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20202@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20203@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20204@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20205@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20206@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20207body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20208addr="0x00010734",func="callee4",
948d5102
NR
20209file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20210fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
922fbb7b
AC
20211bkpt=@{number="2",type="watchpoint",disp="keep",
20212enabled="y",addr="",what="C",times="-5"@}]@}
594fe323 20213(gdb)
922fbb7b
AC
20214-exec-continue
20215^running
20216^done,reason="watchpoint-scope",wpnum="2",
20217frame=@{func="callee3",args=[@{name="strarg",
20218value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
20219file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20220fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 20221(gdb)
922fbb7b
AC
20222-break-list
20223^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
20224hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20225@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20226@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20227@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20228@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20229@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20230body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20231addr="0x00010734",func="callee4",
948d5102
NR
20232file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20233fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
20234times="1"@}]@}
594fe323 20235(gdb)
922fbb7b
AC
20236@end smallexample
20237
20238@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
20239@node GDB/MI Program Context
20240@section @sc{gdb/mi} Program Context
922fbb7b 20241
a2c02241
NR
20242@subheading The @code{-exec-arguments} Command
20243@findex -exec-arguments
922fbb7b 20244
922fbb7b
AC
20245
20246@subsubheading Synopsis
20247
20248@smallexample
a2c02241 20249 -exec-arguments @var{args}
922fbb7b
AC
20250@end smallexample
20251
a2c02241
NR
20252Set the inferior program arguments, to be used in the next
20253@samp{-exec-run}.
922fbb7b 20254
a2c02241 20255@subsubheading @value{GDBN} Command
922fbb7b 20256
a2c02241 20257The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 20258
a2c02241 20259@subsubheading Example
922fbb7b 20260
fbc5282e
MK
20261@smallexample
20262(gdb)
20263-exec-arguments -v word
20264^done
20265(gdb)
20266@end smallexample
922fbb7b 20267
a2c02241
NR
20268
20269@subheading The @code{-exec-show-arguments} Command
20270@findex -exec-show-arguments
20271
20272@subsubheading Synopsis
20273
20274@smallexample
20275 -exec-show-arguments
20276@end smallexample
20277
20278Print the arguments of the program.
922fbb7b
AC
20279
20280@subsubheading @value{GDBN} Command
20281
a2c02241 20282The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
20283
20284@subsubheading Example
a2c02241 20285N.A.
922fbb7b 20286
922fbb7b 20287
a2c02241
NR
20288@subheading The @code{-environment-cd} Command
20289@findex -environment-cd
922fbb7b 20290
a2c02241 20291@subsubheading Synopsis
922fbb7b
AC
20292
20293@smallexample
a2c02241 20294 -environment-cd @var{pathdir}
922fbb7b
AC
20295@end smallexample
20296
a2c02241 20297Set @value{GDBN}'s working directory.
922fbb7b 20298
a2c02241 20299@subsubheading @value{GDBN} Command
922fbb7b 20300
a2c02241
NR
20301The corresponding @value{GDBN} command is @samp{cd}.
20302
20303@subsubheading Example
922fbb7b
AC
20304
20305@smallexample
594fe323 20306(gdb)
a2c02241
NR
20307-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
20308^done
594fe323 20309(gdb)
922fbb7b
AC
20310@end smallexample
20311
20312
a2c02241
NR
20313@subheading The @code{-environment-directory} Command
20314@findex -environment-directory
922fbb7b
AC
20315
20316@subsubheading Synopsis
20317
20318@smallexample
a2c02241 20319 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
20320@end smallexample
20321
a2c02241
NR
20322Add directories @var{pathdir} to beginning of search path for source files.
20323If the @samp{-r} option is used, the search path is reset to the default
20324search path. If directories @var{pathdir} are supplied in addition to the
20325@samp{-r} option, the search path is first reset and then addition
20326occurs as normal.
20327Multiple directories may be specified, separated by blanks. Specifying
20328multiple directories in a single command
20329results in the directories added to the beginning of the
20330search path in the same order they were presented in the command.
20331If blanks are needed as
20332part of a directory name, double-quotes should be used around
20333the name. In the command output, the path will show up separated
d3e8051b 20334by the system directory-separator character. The directory-separator
a2c02241
NR
20335character must not be used
20336in any directory name.
20337If no directories are specified, the current search path is displayed.
922fbb7b
AC
20338
20339@subsubheading @value{GDBN} Command
20340
a2c02241 20341The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
20342
20343@subsubheading Example
20344
922fbb7b 20345@smallexample
594fe323 20346(gdb)
a2c02241
NR
20347-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
20348^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 20349(gdb)
a2c02241
NR
20350-environment-directory ""
20351^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 20352(gdb)
a2c02241
NR
20353-environment-directory -r /home/jjohnstn/src/gdb /usr/src
20354^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 20355(gdb)
a2c02241
NR
20356-environment-directory -r
20357^done,source-path="$cdir:$cwd"
594fe323 20358(gdb)
922fbb7b
AC
20359@end smallexample
20360
20361
a2c02241
NR
20362@subheading The @code{-environment-path} Command
20363@findex -environment-path
922fbb7b
AC
20364
20365@subsubheading Synopsis
20366
20367@smallexample
a2c02241 20368 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
20369@end smallexample
20370
a2c02241
NR
20371Add directories @var{pathdir} to beginning of search path for object files.
20372If the @samp{-r} option is used, the search path is reset to the original
20373search path that existed at gdb start-up. If directories @var{pathdir} are
20374supplied in addition to the
20375@samp{-r} option, the search path is first reset and then addition
20376occurs as normal.
20377Multiple directories may be specified, separated by blanks. Specifying
20378multiple directories in a single command
20379results in the directories added to the beginning of the
20380search path in the same order they were presented in the command.
20381If blanks are needed as
20382part of a directory name, double-quotes should be used around
20383the name. In the command output, the path will show up separated
d3e8051b 20384by the system directory-separator character. The directory-separator
a2c02241
NR
20385character must not be used
20386in any directory name.
20387If no directories are specified, the current path is displayed.
20388
922fbb7b
AC
20389
20390@subsubheading @value{GDBN} Command
20391
a2c02241 20392The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
20393
20394@subsubheading Example
20395
922fbb7b 20396@smallexample
594fe323 20397(gdb)
a2c02241
NR
20398-environment-path
20399^done,path="/usr/bin"
594fe323 20400(gdb)
a2c02241
NR
20401-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
20402^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 20403(gdb)
a2c02241
NR
20404-environment-path -r /usr/local/bin
20405^done,path="/usr/local/bin:/usr/bin"
594fe323 20406(gdb)
922fbb7b
AC
20407@end smallexample
20408
20409
a2c02241
NR
20410@subheading The @code{-environment-pwd} Command
20411@findex -environment-pwd
922fbb7b
AC
20412
20413@subsubheading Synopsis
20414
20415@smallexample
a2c02241 20416 -environment-pwd
922fbb7b
AC
20417@end smallexample
20418
a2c02241 20419Show the current working directory.
922fbb7b 20420
79a6e687 20421@subsubheading @value{GDBN} Command
922fbb7b 20422
a2c02241 20423The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
20424
20425@subsubheading Example
20426
922fbb7b 20427@smallexample
594fe323 20428(gdb)
a2c02241
NR
20429-environment-pwd
20430^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 20431(gdb)
922fbb7b
AC
20432@end smallexample
20433
a2c02241
NR
20434@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20435@node GDB/MI Thread Commands
20436@section @sc{gdb/mi} Thread Commands
20437
20438
20439@subheading The @code{-thread-info} Command
20440@findex -thread-info
922fbb7b
AC
20441
20442@subsubheading Synopsis
20443
20444@smallexample
8e8901c5 20445 -thread-info [ @var{thread-id} ]
922fbb7b
AC
20446@end smallexample
20447
8e8901c5
VP
20448Reports information about either a specific thread, if
20449the @var{thread-id} parameter is present, or about all
20450threads. When printing information about all threads,
20451also reports the current thread.
20452
79a6e687 20453@subsubheading @value{GDBN} Command
922fbb7b 20454
8e8901c5
VP
20455The @samp{info thread} command prints the same information
20456about all threads.
922fbb7b
AC
20457
20458@subsubheading Example
922fbb7b
AC
20459
20460@smallexample
8e8901c5
VP
20461-thread-info
20462^done,threads=[
20463@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
c3b108f7 20464 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
8e8901c5
VP
20465@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
20466 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
c3b108f7 20467 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}],
8e8901c5
VP
20468current-thread-id="1"
20469(gdb)
922fbb7b
AC
20470@end smallexample
20471
c3b108f7
VP
20472The @samp{state} field may have the following values:
20473
20474@table @code
20475@item stopped
20476The thread is stopped. Frame information is available for stopped
20477threads.
20478
20479@item running
20480The thread is running. There's no frame information for running
20481threads.
20482
20483@end table
20484
a2c02241
NR
20485@subheading The @code{-thread-list-ids} Command
20486@findex -thread-list-ids
922fbb7b 20487
a2c02241 20488@subsubheading Synopsis
922fbb7b 20489
a2c02241
NR
20490@smallexample
20491 -thread-list-ids
20492@end smallexample
922fbb7b 20493
a2c02241
NR
20494Produces a list of the currently known @value{GDBN} thread ids. At the
20495end of the list it also prints the total number of such threads.
922fbb7b 20496
c3b108f7
VP
20497This command is retained for historical reasons, the
20498@code{-thread-info} command should be used instead.
20499
922fbb7b
AC
20500@subsubheading @value{GDBN} Command
20501
a2c02241 20502Part of @samp{info threads} supplies the same information.
922fbb7b
AC
20503
20504@subsubheading Example
20505
a2c02241 20506No threads present, besides the main process:
922fbb7b
AC
20507
20508@smallexample
594fe323 20509(gdb)
a2c02241
NR
20510-thread-list-ids
20511^done,thread-ids=@{@},number-of-threads="0"
594fe323 20512(gdb)
922fbb7b
AC
20513@end smallexample
20514
922fbb7b 20515
a2c02241 20516Several threads:
922fbb7b
AC
20517
20518@smallexample
594fe323 20519(gdb)
a2c02241
NR
20520-thread-list-ids
20521^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20522number-of-threads="3"
594fe323 20523(gdb)
922fbb7b
AC
20524@end smallexample
20525
a2c02241
NR
20526
20527@subheading The @code{-thread-select} Command
20528@findex -thread-select
922fbb7b
AC
20529
20530@subsubheading Synopsis
20531
20532@smallexample
a2c02241 20533 -thread-select @var{threadnum}
922fbb7b
AC
20534@end smallexample
20535
a2c02241
NR
20536Make @var{threadnum} the current thread. It prints the number of the new
20537current thread, and the topmost frame for that thread.
922fbb7b 20538
c3b108f7
VP
20539This command is deprecated in favor of explicitly using the
20540@samp{--thread} option to each command.
20541
922fbb7b
AC
20542@subsubheading @value{GDBN} Command
20543
a2c02241 20544The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
20545
20546@subsubheading Example
922fbb7b
AC
20547
20548@smallexample
594fe323 20549(gdb)
a2c02241
NR
20550-exec-next
20551^running
594fe323 20552(gdb)
a2c02241
NR
20553*stopped,reason="end-stepping-range",thread-id="2",line="187",
20554file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 20555(gdb)
a2c02241
NR
20556-thread-list-ids
20557^done,
20558thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20559number-of-threads="3"
594fe323 20560(gdb)
a2c02241
NR
20561-thread-select 3
20562^done,new-thread-id="3",
20563frame=@{level="0",func="vprintf",
20564args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20565@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 20566(gdb)
922fbb7b
AC
20567@end smallexample
20568
a2c02241
NR
20569@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20570@node GDB/MI Program Execution
20571@section @sc{gdb/mi} Program Execution
922fbb7b 20572
ef21caaf 20573These are the asynchronous commands which generate the out-of-band
3f94c067 20574record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
20575asynchronously with remote targets and this interaction is mimicked in
20576other cases.
922fbb7b 20577
922fbb7b
AC
20578@subheading The @code{-exec-continue} Command
20579@findex -exec-continue
20580
20581@subsubheading Synopsis
20582
20583@smallexample
c3b108f7 20584 -exec-continue [--all|--thread-group N]
922fbb7b
AC
20585@end smallexample
20586
ef21caaf 20587Resumes the execution of the inferior program until a breakpoint is
c3b108f7
VP
20588encountered, or until the inferior exits. In all-stop mode
20589(@pxref{All-Stop Mode}), may resume only one thread, or all threads,
20590depending on the value of the @samp{scheduler-locking} variable. In
20591non-stop mode (@pxref{Non-Stop Mode}), if the @samp{--all} is not
20592specified, only the thread specified with the @samp{--thread} option
20593(or current thread, if no @samp{--thread} is provided) is resumed. If
20594@samp{--all} is specified, all threads will be resumed. The
20595@samp{--all} option is ignored in all-stop mode. If the
20596@samp{--thread-group} options is specified, then all threads in that
20597thread group are resumed.
922fbb7b
AC
20598
20599@subsubheading @value{GDBN} Command
20600
20601The corresponding @value{GDBN} corresponding is @samp{continue}.
20602
20603@subsubheading Example
20604
20605@smallexample
20606-exec-continue
20607^running
594fe323 20608(gdb)
922fbb7b 20609@@Hello world
a47ec5fe
AR
20610*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
20611func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
20612line="13"@}
594fe323 20613(gdb)
922fbb7b
AC
20614@end smallexample
20615
20616
20617@subheading The @code{-exec-finish} Command
20618@findex -exec-finish
20619
20620@subsubheading Synopsis
20621
20622@smallexample
20623 -exec-finish
20624@end smallexample
20625
ef21caaf
NR
20626Resumes the execution of the inferior program until the current
20627function is exited. Displays the results returned by the function.
922fbb7b
AC
20628
20629@subsubheading @value{GDBN} Command
20630
20631The corresponding @value{GDBN} command is @samp{finish}.
20632
20633@subsubheading Example
20634
20635Function returning @code{void}.
20636
20637@smallexample
20638-exec-finish
20639^running
594fe323 20640(gdb)
922fbb7b
AC
20641@@hello from foo
20642*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 20643file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 20644(gdb)
922fbb7b
AC
20645@end smallexample
20646
20647Function returning other than @code{void}. The name of the internal
20648@value{GDBN} variable storing the result is printed, together with the
20649value itself.
20650
20651@smallexample
20652-exec-finish
20653^running
594fe323 20654(gdb)
922fbb7b
AC
20655*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
20656args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 20657file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 20658gdb-result-var="$1",return-value="0"
594fe323 20659(gdb)
922fbb7b
AC
20660@end smallexample
20661
20662
20663@subheading The @code{-exec-interrupt} Command
20664@findex -exec-interrupt
20665
20666@subsubheading Synopsis
20667
20668@smallexample
c3b108f7 20669 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
20670@end smallexample
20671
ef21caaf
NR
20672Interrupts the background execution of the target. Note how the token
20673associated with the stop message is the one for the execution command
20674that has been interrupted. The token for the interrupt itself only
20675appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
20676interrupt a non-running program, an error message will be printed.
20677
c3b108f7
VP
20678Note that when asynchronous execution is enabled, this command is
20679asynchronous just like other execution commands. That is, first the
20680@samp{^done} response will be printed, and the target stop will be
20681reported after that using the @samp{*stopped} notification.
20682
20683In non-stop mode, only the context thread is interrupted by default.
20684All threads will be interrupted if the @samp{--all} option is
20685specified. If the @samp{--thread-group} option is specified, all
20686threads in that group will be interrupted.
20687
922fbb7b
AC
20688@subsubheading @value{GDBN} Command
20689
20690The corresponding @value{GDBN} command is @samp{interrupt}.
20691
20692@subsubheading Example
20693
20694@smallexample
594fe323 20695(gdb)
922fbb7b
AC
20696111-exec-continue
20697111^running
20698
594fe323 20699(gdb)
922fbb7b
AC
20700222-exec-interrupt
20701222^done
594fe323 20702(gdb)
922fbb7b 20703111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 20704frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 20705fullname="/home/foo/bar/try.c",line="13"@}
594fe323 20706(gdb)
922fbb7b 20707
594fe323 20708(gdb)
922fbb7b
AC
20709-exec-interrupt
20710^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 20711(gdb)
922fbb7b
AC
20712@end smallexample
20713
20714
20715@subheading The @code{-exec-next} Command
20716@findex -exec-next
20717
20718@subsubheading Synopsis
20719
20720@smallexample
20721 -exec-next
20722@end smallexample
20723
ef21caaf
NR
20724Resumes execution of the inferior program, stopping when the beginning
20725of the next source line is reached.
922fbb7b
AC
20726
20727@subsubheading @value{GDBN} Command
20728
20729The corresponding @value{GDBN} command is @samp{next}.
20730
20731@subsubheading Example
20732
20733@smallexample
20734-exec-next
20735^running
594fe323 20736(gdb)
922fbb7b 20737*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 20738(gdb)
922fbb7b
AC
20739@end smallexample
20740
20741
20742@subheading The @code{-exec-next-instruction} Command
20743@findex -exec-next-instruction
20744
20745@subsubheading Synopsis
20746
20747@smallexample
20748 -exec-next-instruction
20749@end smallexample
20750
ef21caaf
NR
20751Executes one machine instruction. If the instruction is a function
20752call, continues until the function returns. If the program stops at an
20753instruction in the middle of a source line, the address will be
20754printed as well.
922fbb7b
AC
20755
20756@subsubheading @value{GDBN} Command
20757
20758The corresponding @value{GDBN} command is @samp{nexti}.
20759
20760@subsubheading Example
20761
20762@smallexample
594fe323 20763(gdb)
922fbb7b
AC
20764-exec-next-instruction
20765^running
20766
594fe323 20767(gdb)
922fbb7b
AC
20768*stopped,reason="end-stepping-range",
20769addr="0x000100d4",line="5",file="hello.c"
594fe323 20770(gdb)
922fbb7b
AC
20771@end smallexample
20772
20773
20774@subheading The @code{-exec-return} Command
20775@findex -exec-return
20776
20777@subsubheading Synopsis
20778
20779@smallexample
20780 -exec-return
20781@end smallexample
20782
20783Makes current function return immediately. Doesn't execute the inferior.
20784Displays the new current frame.
20785
20786@subsubheading @value{GDBN} Command
20787
20788The corresponding @value{GDBN} command is @samp{return}.
20789
20790@subsubheading Example
20791
20792@smallexample
594fe323 20793(gdb)
922fbb7b
AC
20794200-break-insert callee4
20795200^done,bkpt=@{number="1",addr="0x00010734",
20796file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 20797(gdb)
922fbb7b
AC
20798000-exec-run
20799000^running
594fe323 20800(gdb)
a47ec5fe 20801000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 20802frame=@{func="callee4",args=[],
76ff342d
DJ
20803file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20804fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 20805(gdb)
922fbb7b
AC
20806205-break-delete
20807205^done
594fe323 20808(gdb)
922fbb7b
AC
20809111-exec-return
20810111^done,frame=@{level="0",func="callee3",
20811args=[@{name="strarg",
20812value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
20813file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20814fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 20815(gdb)
922fbb7b
AC
20816@end smallexample
20817
20818
20819@subheading The @code{-exec-run} Command
20820@findex -exec-run
20821
20822@subsubheading Synopsis
20823
20824@smallexample
20825 -exec-run
20826@end smallexample
20827
ef21caaf
NR
20828Starts execution of the inferior from the beginning. The inferior
20829executes until either a breakpoint is encountered or the program
20830exits. In the latter case the output will include an exit code, if
20831the program has exited exceptionally.
922fbb7b
AC
20832
20833@subsubheading @value{GDBN} Command
20834
20835The corresponding @value{GDBN} command is @samp{run}.
20836
ef21caaf 20837@subsubheading Examples
922fbb7b
AC
20838
20839@smallexample
594fe323 20840(gdb)
922fbb7b
AC
20841-break-insert main
20842^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 20843(gdb)
922fbb7b
AC
20844-exec-run
20845^running
594fe323 20846(gdb)
a47ec5fe 20847*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 20848frame=@{func="main",args=[],file="recursive2.c",
948d5102 20849fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 20850(gdb)
922fbb7b
AC
20851@end smallexample
20852
ef21caaf
NR
20853@noindent
20854Program exited normally:
20855
20856@smallexample
594fe323 20857(gdb)
ef21caaf
NR
20858-exec-run
20859^running
594fe323 20860(gdb)
ef21caaf
NR
20861x = 55
20862*stopped,reason="exited-normally"
594fe323 20863(gdb)
ef21caaf
NR
20864@end smallexample
20865
20866@noindent
20867Program exited exceptionally:
20868
20869@smallexample
594fe323 20870(gdb)
ef21caaf
NR
20871-exec-run
20872^running
594fe323 20873(gdb)
ef21caaf
NR
20874x = 55
20875*stopped,reason="exited",exit-code="01"
594fe323 20876(gdb)
ef21caaf
NR
20877@end smallexample
20878
20879Another way the program can terminate is if it receives a signal such as
20880@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
20881
20882@smallexample
594fe323 20883(gdb)
ef21caaf
NR
20884*stopped,reason="exited-signalled",signal-name="SIGINT",
20885signal-meaning="Interrupt"
20886@end smallexample
20887
922fbb7b 20888
a2c02241
NR
20889@c @subheading -exec-signal
20890
20891
20892@subheading The @code{-exec-step} Command
20893@findex -exec-step
922fbb7b
AC
20894
20895@subsubheading Synopsis
20896
20897@smallexample
a2c02241 20898 -exec-step
922fbb7b
AC
20899@end smallexample
20900
a2c02241
NR
20901Resumes execution of the inferior program, stopping when the beginning
20902of the next source line is reached, if the next source line is not a
20903function call. If it is, stop at the first instruction of the called
20904function.
922fbb7b
AC
20905
20906@subsubheading @value{GDBN} Command
20907
a2c02241 20908The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
20909
20910@subsubheading Example
20911
20912Stepping into a function:
20913
20914@smallexample
20915-exec-step
20916^running
594fe323 20917(gdb)
922fbb7b
AC
20918*stopped,reason="end-stepping-range",
20919frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 20920@{name="b",value="0"@}],file="recursive2.c",
948d5102 20921fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 20922(gdb)
922fbb7b
AC
20923@end smallexample
20924
20925Regular stepping:
20926
20927@smallexample
20928-exec-step
20929^running
594fe323 20930(gdb)
922fbb7b 20931*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 20932(gdb)
922fbb7b
AC
20933@end smallexample
20934
20935
20936@subheading The @code{-exec-step-instruction} Command
20937@findex -exec-step-instruction
20938
20939@subsubheading Synopsis
20940
20941@smallexample
20942 -exec-step-instruction
20943@end smallexample
20944
ef21caaf
NR
20945Resumes the inferior which executes one machine instruction. The
20946output, once @value{GDBN} has stopped, will vary depending on whether
20947we have stopped in the middle of a source line or not. In the former
20948case, the address at which the program stopped will be printed as
922fbb7b
AC
20949well.
20950
20951@subsubheading @value{GDBN} Command
20952
20953The corresponding @value{GDBN} command is @samp{stepi}.
20954
20955@subsubheading Example
20956
20957@smallexample
594fe323 20958(gdb)
922fbb7b
AC
20959-exec-step-instruction
20960^running
20961
594fe323 20962(gdb)
922fbb7b 20963*stopped,reason="end-stepping-range",
76ff342d 20964frame=@{func="foo",args=[],file="try.c",
948d5102 20965fullname="/home/foo/bar/try.c",line="10"@}
594fe323 20966(gdb)
922fbb7b
AC
20967-exec-step-instruction
20968^running
20969
594fe323 20970(gdb)
922fbb7b 20971*stopped,reason="end-stepping-range",
76ff342d 20972frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 20973fullname="/home/foo/bar/try.c",line="10"@}
594fe323 20974(gdb)
922fbb7b
AC
20975@end smallexample
20976
20977
20978@subheading The @code{-exec-until} Command
20979@findex -exec-until
20980
20981@subsubheading Synopsis
20982
20983@smallexample
20984 -exec-until [ @var{location} ]
20985@end smallexample
20986
ef21caaf
NR
20987Executes the inferior until the @var{location} specified in the
20988argument is reached. If there is no argument, the inferior executes
20989until a source line greater than the current one is reached. The
20990reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
20991
20992@subsubheading @value{GDBN} Command
20993
20994The corresponding @value{GDBN} command is @samp{until}.
20995
20996@subsubheading Example
20997
20998@smallexample
594fe323 20999(gdb)
922fbb7b
AC
21000-exec-until recursive2.c:6
21001^running
594fe323 21002(gdb)
922fbb7b
AC
21003x = 55
21004*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 21005file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 21006(gdb)
922fbb7b
AC
21007@end smallexample
21008
21009@ignore
21010@subheading -file-clear
21011Is this going away????
21012@end ignore
21013
351ff01a 21014@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
21015@node GDB/MI Stack Manipulation
21016@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 21017
922fbb7b 21018
a2c02241
NR
21019@subheading The @code{-stack-info-frame} Command
21020@findex -stack-info-frame
922fbb7b
AC
21021
21022@subsubheading Synopsis
21023
21024@smallexample
a2c02241 21025 -stack-info-frame
922fbb7b
AC
21026@end smallexample
21027
a2c02241 21028Get info on the selected frame.
922fbb7b
AC
21029
21030@subsubheading @value{GDBN} Command
21031
a2c02241
NR
21032The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
21033(without arguments).
922fbb7b
AC
21034
21035@subsubheading Example
21036
21037@smallexample
594fe323 21038(gdb)
a2c02241
NR
21039-stack-info-frame
21040^done,frame=@{level="1",addr="0x0001076c",func="callee3",
21041file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21042fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 21043(gdb)
922fbb7b
AC
21044@end smallexample
21045
a2c02241
NR
21046@subheading The @code{-stack-info-depth} Command
21047@findex -stack-info-depth
922fbb7b
AC
21048
21049@subsubheading Synopsis
21050
21051@smallexample
a2c02241 21052 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
21053@end smallexample
21054
a2c02241
NR
21055Return the depth of the stack. If the integer argument @var{max-depth}
21056is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
21057
21058@subsubheading @value{GDBN} Command
21059
a2c02241 21060There's no equivalent @value{GDBN} command.
922fbb7b
AC
21061
21062@subsubheading Example
21063
a2c02241
NR
21064For a stack with frame levels 0 through 11:
21065
922fbb7b 21066@smallexample
594fe323 21067(gdb)
a2c02241
NR
21068-stack-info-depth
21069^done,depth="12"
594fe323 21070(gdb)
a2c02241
NR
21071-stack-info-depth 4
21072^done,depth="4"
594fe323 21073(gdb)
a2c02241
NR
21074-stack-info-depth 12
21075^done,depth="12"
594fe323 21076(gdb)
a2c02241
NR
21077-stack-info-depth 11
21078^done,depth="11"
594fe323 21079(gdb)
a2c02241
NR
21080-stack-info-depth 13
21081^done,depth="12"
594fe323 21082(gdb)
922fbb7b
AC
21083@end smallexample
21084
a2c02241
NR
21085@subheading The @code{-stack-list-arguments} Command
21086@findex -stack-list-arguments
922fbb7b
AC
21087
21088@subsubheading Synopsis
21089
21090@smallexample
a2c02241
NR
21091 -stack-list-arguments @var{show-values}
21092 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
21093@end smallexample
21094
a2c02241
NR
21095Display a list of the arguments for the frames between @var{low-frame}
21096and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
21097@var{high-frame} are not provided, list the arguments for the whole
21098call stack. If the two arguments are equal, show the single frame
21099at the corresponding level. It is an error if @var{low-frame} is
21100larger than the actual number of frames. On the other hand,
21101@var{high-frame} may be larger than the actual number of frames, in
21102which case only existing frames will be returned.
a2c02241
NR
21103
21104The @var{show-values} argument must have a value of 0 or 1. A value of
211050 means that only the names of the arguments are listed, a value of 1
21106means that both names and values of the arguments are printed.
922fbb7b
AC
21107
21108@subsubheading @value{GDBN} Command
21109
a2c02241
NR
21110@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
21111@samp{gdb_get_args} command which partially overlaps with the
21112functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
21113
21114@subsubheading Example
922fbb7b 21115
a2c02241 21116@smallexample
594fe323 21117(gdb)
a2c02241
NR
21118-stack-list-frames
21119^done,
21120stack=[
21121frame=@{level="0",addr="0x00010734",func="callee4",
21122file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21123fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
21124frame=@{level="1",addr="0x0001076c",func="callee3",
21125file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21126fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
21127frame=@{level="2",addr="0x0001078c",func="callee2",
21128file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21129fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
21130frame=@{level="3",addr="0x000107b4",func="callee1",
21131file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21132fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
21133frame=@{level="4",addr="0x000107e0",func="main",
21134file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21135fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 21136(gdb)
a2c02241
NR
21137-stack-list-arguments 0
21138^done,
21139stack-args=[
21140frame=@{level="0",args=[]@},
21141frame=@{level="1",args=[name="strarg"]@},
21142frame=@{level="2",args=[name="intarg",name="strarg"]@},
21143frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
21144frame=@{level="4",args=[]@}]
594fe323 21145(gdb)
a2c02241
NR
21146-stack-list-arguments 1
21147^done,
21148stack-args=[
21149frame=@{level="0",args=[]@},
21150frame=@{level="1",
21151 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
21152frame=@{level="2",args=[
21153@{name="intarg",value="2"@},
21154@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
21155@{frame=@{level="3",args=[
21156@{name="intarg",value="2"@},
21157@{name="strarg",value="0x11940 \"A string argument.\""@},
21158@{name="fltarg",value="3.5"@}]@},
21159frame=@{level="4",args=[]@}]
594fe323 21160(gdb)
a2c02241
NR
21161-stack-list-arguments 0 2 2
21162^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 21163(gdb)
a2c02241
NR
21164-stack-list-arguments 1 2 2
21165^done,stack-args=[frame=@{level="2",
21166args=[@{name="intarg",value="2"@},
21167@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 21168(gdb)
a2c02241
NR
21169@end smallexample
21170
21171@c @subheading -stack-list-exception-handlers
922fbb7b 21172
a2c02241
NR
21173
21174@subheading The @code{-stack-list-frames} Command
21175@findex -stack-list-frames
1abaf70c
BR
21176
21177@subsubheading Synopsis
21178
21179@smallexample
a2c02241 21180 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
21181@end smallexample
21182
a2c02241
NR
21183List the frames currently on the stack. For each frame it displays the
21184following info:
21185
21186@table @samp
21187@item @var{level}
d3e8051b 21188The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
21189@item @var{addr}
21190The @code{$pc} value for that frame.
21191@item @var{func}
21192Function name.
21193@item @var{file}
21194File name of the source file where the function lives.
21195@item @var{line}
21196Line number corresponding to the @code{$pc}.
21197@end table
21198
21199If invoked without arguments, this command prints a backtrace for the
21200whole stack. If given two integer arguments, it shows the frames whose
21201levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
21202are equal, it shows the single frame at the corresponding level. It is
21203an error if @var{low-frame} is larger than the actual number of
a5451f4e 21204frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 21205actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
21206
21207@subsubheading @value{GDBN} Command
21208
a2c02241 21209The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
21210
21211@subsubheading Example
21212
a2c02241
NR
21213Full stack backtrace:
21214
1abaf70c 21215@smallexample
594fe323 21216(gdb)
a2c02241
NR
21217-stack-list-frames
21218^done,stack=
21219[frame=@{level="0",addr="0x0001076c",func="foo",
21220 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
21221frame=@{level="1",addr="0x000107a4",func="foo",
21222 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21223frame=@{level="2",addr="0x000107a4",func="foo",
21224 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21225frame=@{level="3",addr="0x000107a4",func="foo",
21226 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21227frame=@{level="4",addr="0x000107a4",func="foo",
21228 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21229frame=@{level="5",addr="0x000107a4",func="foo",
21230 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21231frame=@{level="6",addr="0x000107a4",func="foo",
21232 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21233frame=@{level="7",addr="0x000107a4",func="foo",
21234 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21235frame=@{level="8",addr="0x000107a4",func="foo",
21236 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21237frame=@{level="9",addr="0x000107a4",func="foo",
21238 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21239frame=@{level="10",addr="0x000107a4",func="foo",
21240 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21241frame=@{level="11",addr="0x00010738",func="main",
21242 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 21243(gdb)
1abaf70c
BR
21244@end smallexample
21245
a2c02241 21246Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 21247
a2c02241 21248@smallexample
594fe323 21249(gdb)
a2c02241
NR
21250-stack-list-frames 3 5
21251^done,stack=
21252[frame=@{level="3",addr="0x000107a4",func="foo",
21253 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21254frame=@{level="4",addr="0x000107a4",func="foo",
21255 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21256frame=@{level="5",addr="0x000107a4",func="foo",
21257 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 21258(gdb)
a2c02241 21259@end smallexample
922fbb7b 21260
a2c02241 21261Show a single frame:
922fbb7b
AC
21262
21263@smallexample
594fe323 21264(gdb)
a2c02241
NR
21265-stack-list-frames 3 3
21266^done,stack=
21267[frame=@{level="3",addr="0x000107a4",func="foo",
21268 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 21269(gdb)
922fbb7b
AC
21270@end smallexample
21271
922fbb7b 21272
a2c02241
NR
21273@subheading The @code{-stack-list-locals} Command
21274@findex -stack-list-locals
57c22c6c 21275
a2c02241 21276@subsubheading Synopsis
922fbb7b
AC
21277
21278@smallexample
a2c02241 21279 -stack-list-locals @var{print-values}
922fbb7b
AC
21280@end smallexample
21281
a2c02241
NR
21282Display the local variable names for the selected frame. If
21283@var{print-values} is 0 or @code{--no-values}, print only the names of
21284the variables; if it is 1 or @code{--all-values}, print also their
21285values; and if it is 2 or @code{--simple-values}, print the name,
21286type and value for simple data types and the name and type for arrays,
21287structures and unions. In this last case, a frontend can immediately
21288display the value of simple data types and create variable objects for
d3e8051b 21289other data types when the user wishes to explore their values in
a2c02241 21290more detail.
922fbb7b
AC
21291
21292@subsubheading @value{GDBN} Command
21293
a2c02241 21294@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
21295
21296@subsubheading Example
922fbb7b
AC
21297
21298@smallexample
594fe323 21299(gdb)
a2c02241
NR
21300-stack-list-locals 0
21301^done,locals=[name="A",name="B",name="C"]
594fe323 21302(gdb)
a2c02241
NR
21303-stack-list-locals --all-values
21304^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
21305 @{name="C",value="@{1, 2, 3@}"@}]
21306-stack-list-locals --simple-values
21307^done,locals=[@{name="A",type="int",value="1"@},
21308 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 21309(gdb)
922fbb7b
AC
21310@end smallexample
21311
922fbb7b 21312
a2c02241
NR
21313@subheading The @code{-stack-select-frame} Command
21314@findex -stack-select-frame
922fbb7b
AC
21315
21316@subsubheading Synopsis
21317
21318@smallexample
a2c02241 21319 -stack-select-frame @var{framenum}
922fbb7b
AC
21320@end smallexample
21321
a2c02241
NR
21322Change the selected frame. Select a different frame @var{framenum} on
21323the stack.
922fbb7b 21324
c3b108f7
VP
21325This command in deprecated in favor of passing the @samp{--frame}
21326option to every command.
21327
922fbb7b
AC
21328@subsubheading @value{GDBN} Command
21329
a2c02241
NR
21330The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
21331@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
21332
21333@subsubheading Example
21334
21335@smallexample
594fe323 21336(gdb)
a2c02241 21337-stack-select-frame 2
922fbb7b 21338^done
594fe323 21339(gdb)
922fbb7b
AC
21340@end smallexample
21341
21342@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
21343@node GDB/MI Variable Objects
21344@section @sc{gdb/mi} Variable Objects
922fbb7b 21345
a1b5960f 21346@ignore
922fbb7b 21347
a2c02241 21348@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 21349
a2c02241
NR
21350For the implementation of a variable debugger window (locals, watched
21351expressions, etc.), we are proposing the adaptation of the existing code
21352used by @code{Insight}.
922fbb7b 21353
a2c02241 21354The two main reasons for that are:
922fbb7b 21355
a2c02241
NR
21356@enumerate 1
21357@item
21358It has been proven in practice (it is already on its second generation).
922fbb7b 21359
a2c02241
NR
21360@item
21361It will shorten development time (needless to say how important it is
21362now).
21363@end enumerate
922fbb7b 21364
a2c02241
NR
21365The original interface was designed to be used by Tcl code, so it was
21366slightly changed so it could be used through @sc{gdb/mi}. This section
21367describes the @sc{gdb/mi} operations that will be available and gives some
21368hints about their use.
922fbb7b 21369
a2c02241
NR
21370@emph{Note}: In addition to the set of operations described here, we
21371expect the @sc{gui} implementation of a variable window to require, at
21372least, the following operations:
922fbb7b 21373
a2c02241
NR
21374@itemize @bullet
21375@item @code{-gdb-show} @code{output-radix}
21376@item @code{-stack-list-arguments}
21377@item @code{-stack-list-locals}
21378@item @code{-stack-select-frame}
21379@end itemize
922fbb7b 21380
a1b5960f
VP
21381@end ignore
21382
c8b2f53c 21383@subheading Introduction to Variable Objects
922fbb7b 21384
a2c02241 21385@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
21386
21387Variable objects are "object-oriented" MI interface for examining and
21388changing values of expressions. Unlike some other MI interfaces that
21389work with expressions, variable objects are specifically designed for
21390simple and efficient presentation in the frontend. A variable object
21391is identified by string name. When a variable object is created, the
21392frontend specifies the expression for that variable object. The
21393expression can be a simple variable, or it can be an arbitrary complex
21394expression, and can even involve CPU registers. After creating a
21395variable object, the frontend can invoke other variable object
21396operations---for example to obtain or change the value of a variable
21397object, or to change display format.
21398
21399Variable objects have hierarchical tree structure. Any variable object
21400that corresponds to a composite type, such as structure in C, has
21401a number of child variable objects, for example corresponding to each
21402element of a structure. A child variable object can itself have
21403children, recursively. Recursion ends when we reach
25d5ea92
VP
21404leaf variable objects, which always have built-in types. Child variable
21405objects are created only by explicit request, so if a frontend
21406is not interested in the children of a particular variable object, no
21407child will be created.
c8b2f53c
VP
21408
21409For a leaf variable object it is possible to obtain its value as a
21410string, or set the value from a string. String value can be also
21411obtained for a non-leaf variable object, but it's generally a string
21412that only indicates the type of the object, and does not list its
21413contents. Assignment to a non-leaf variable object is not allowed.
21414
21415A frontend does not need to read the values of all variable objects each time
21416the program stops. Instead, MI provides an update command that lists all
21417variable objects whose values has changed since the last update
21418operation. This considerably reduces the amount of data that must
25d5ea92
VP
21419be transferred to the frontend. As noted above, children variable
21420objects are created on demand, and only leaf variable objects have a
21421real value. As result, gdb will read target memory only for leaf
21422variables that frontend has created.
21423
21424The automatic update is not always desirable. For example, a frontend
21425might want to keep a value of some expression for future reference,
21426and never update it. For another example, fetching memory is
21427relatively slow for embedded targets, so a frontend might want
21428to disable automatic update for the variables that are either not
21429visible on the screen, or ``closed''. This is possible using so
21430called ``frozen variable objects''. Such variable objects are never
21431implicitly updated.
922fbb7b 21432
c3b108f7
VP
21433Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
21434fixed variable object, the expression is parsed when the variable
21435object is created, including associating identifiers to specific
21436variables. The meaning of expression never changes. For a floating
21437variable object the values of variables whose names appear in the
21438expressions are re-evaluated every time in the context of the current
21439frame. Consider this example:
21440
21441@smallexample
21442void do_work(...)
21443@{
21444 struct work_state state;
21445
21446 if (...)
21447 do_work(...);
21448@}
21449@end smallexample
21450
21451If a fixed variable object for the @code{state} variable is created in
21452this function, and we enter the recursive call, the the variable
21453object will report the value of @code{state} in the top-level
21454@code{do_work} invocation. On the other hand, a floating variable
21455object will report the value of @code{state} in the current frame.
21456
21457If an expression specified when creating a fixed variable object
21458refers to a local variable, the variable object becomes bound to the
21459thread and frame in which the variable object is created. When such
21460variable object is updated, @value{GDBN} makes sure that the
21461thread/frame combination the variable object is bound to still exists,
21462and re-evaluates the variable object in context of that thread/frame.
21463
a2c02241
NR
21464The following is the complete set of @sc{gdb/mi} operations defined to
21465access this functionality:
922fbb7b 21466
a2c02241
NR
21467@multitable @columnfractions .4 .6
21468@item @strong{Operation}
21469@tab @strong{Description}
922fbb7b 21470
a2c02241
NR
21471@item @code{-var-create}
21472@tab create a variable object
21473@item @code{-var-delete}
22d8a470 21474@tab delete the variable object and/or its children
a2c02241
NR
21475@item @code{-var-set-format}
21476@tab set the display format of this variable
21477@item @code{-var-show-format}
21478@tab show the display format of this variable
21479@item @code{-var-info-num-children}
21480@tab tells how many children this object has
21481@item @code{-var-list-children}
21482@tab return a list of the object's children
21483@item @code{-var-info-type}
21484@tab show the type of this variable object
21485@item @code{-var-info-expression}
02142340
VP
21486@tab print parent-relative expression that this variable object represents
21487@item @code{-var-info-path-expression}
21488@tab print full expression that this variable object represents
a2c02241
NR
21489@item @code{-var-show-attributes}
21490@tab is this variable editable? does it exist here?
21491@item @code{-var-evaluate-expression}
21492@tab get the value of this variable
21493@item @code{-var-assign}
21494@tab set the value of this variable
21495@item @code{-var-update}
21496@tab update the variable and its children
25d5ea92
VP
21497@item @code{-var-set-frozen}
21498@tab set frozeness attribute
a2c02241 21499@end multitable
922fbb7b 21500
a2c02241
NR
21501In the next subsection we describe each operation in detail and suggest
21502how it can be used.
922fbb7b 21503
a2c02241 21504@subheading Description And Use of Operations on Variable Objects
922fbb7b 21505
a2c02241
NR
21506@subheading The @code{-var-create} Command
21507@findex -var-create
ef21caaf 21508
a2c02241 21509@subsubheading Synopsis
ef21caaf 21510
a2c02241
NR
21511@smallexample
21512 -var-create @{@var{name} | "-"@}
c3b108f7 21513 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
21514@end smallexample
21515
21516This operation creates a variable object, which allows the monitoring of
21517a variable, the result of an expression, a memory cell or a CPU
21518register.
ef21caaf 21519
a2c02241
NR
21520The @var{name} parameter is the string by which the object can be
21521referenced. It must be unique. If @samp{-} is specified, the varobj
21522system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 21523unique provided that one does not specify @var{name} of that format.
a2c02241 21524The command fails if a duplicate name is found.
ef21caaf 21525
a2c02241
NR
21526The frame under which the expression should be evaluated can be
21527specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
21528frame should be used. A @samp{@@} indicates that a floating variable
21529object must be created.
922fbb7b 21530
a2c02241
NR
21531@var{expression} is any expression valid on the current language set (must not
21532begin with a @samp{*}), or one of the following:
922fbb7b 21533
a2c02241
NR
21534@itemize @bullet
21535@item
21536@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 21537
a2c02241
NR
21538@item
21539@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 21540
a2c02241
NR
21541@item
21542@samp{$@var{regname}} --- a CPU register name
21543@end itemize
922fbb7b 21544
a2c02241 21545@subsubheading Result
922fbb7b 21546
a2c02241
NR
21547This operation returns the name, number of children and the type of the
21548object created. Type is returned as a string as the ones generated by
c3b108f7
VP
21549the @value{GDBN} CLI. If a fixed variable object is bound to a
21550specific thread, the thread is is also printed:
922fbb7b
AC
21551
21552@smallexample
c3b108f7 21553 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}"
dcaaae04
NR
21554@end smallexample
21555
a2c02241
NR
21556
21557@subheading The @code{-var-delete} Command
21558@findex -var-delete
922fbb7b
AC
21559
21560@subsubheading Synopsis
21561
21562@smallexample
22d8a470 21563 -var-delete [ -c ] @var{name}
922fbb7b
AC
21564@end smallexample
21565
a2c02241 21566Deletes a previously created variable object and all of its children.
22d8a470 21567With the @samp{-c} option, just deletes the children.
922fbb7b 21568
a2c02241 21569Returns an error if the object @var{name} is not found.
922fbb7b 21570
922fbb7b 21571
a2c02241
NR
21572@subheading The @code{-var-set-format} Command
21573@findex -var-set-format
922fbb7b 21574
a2c02241 21575@subsubheading Synopsis
922fbb7b
AC
21576
21577@smallexample
a2c02241 21578 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
21579@end smallexample
21580
a2c02241
NR
21581Sets the output format for the value of the object @var{name} to be
21582@var{format-spec}.
21583
de051565 21584@anchor{-var-set-format}
a2c02241
NR
21585The syntax for the @var{format-spec} is as follows:
21586
21587@smallexample
21588 @var{format-spec} @expansion{}
21589 @{binary | decimal | hexadecimal | octal | natural@}
21590@end smallexample
21591
c8b2f53c
VP
21592The natural format is the default format choosen automatically
21593based on the variable type (like decimal for an @code{int}, hex
21594for pointers, etc.).
21595
21596For a variable with children, the format is set only on the
21597variable itself, and the children are not affected.
a2c02241
NR
21598
21599@subheading The @code{-var-show-format} Command
21600@findex -var-show-format
922fbb7b
AC
21601
21602@subsubheading Synopsis
21603
21604@smallexample
a2c02241 21605 -var-show-format @var{name}
922fbb7b
AC
21606@end smallexample
21607
a2c02241 21608Returns the format used to display the value of the object @var{name}.
922fbb7b 21609
a2c02241
NR
21610@smallexample
21611 @var{format} @expansion{}
21612 @var{format-spec}
21613@end smallexample
922fbb7b 21614
922fbb7b 21615
a2c02241
NR
21616@subheading The @code{-var-info-num-children} Command
21617@findex -var-info-num-children
21618
21619@subsubheading Synopsis
21620
21621@smallexample
21622 -var-info-num-children @var{name}
21623@end smallexample
21624
21625Returns the number of children of a variable object @var{name}:
21626
21627@smallexample
21628 numchild=@var{n}
21629@end smallexample
21630
21631
21632@subheading The @code{-var-list-children} Command
21633@findex -var-list-children
21634
21635@subsubheading Synopsis
21636
21637@smallexample
21638 -var-list-children [@var{print-values}] @var{name}
21639@end smallexample
21640@anchor{-var-list-children}
21641
21642Return a list of the children of the specified variable object and
21643create variable objects for them, if they do not already exist. With
21644a single argument or if @var{print-values} has a value for of 0 or
21645@code{--no-values}, print only the names of the variables; if
21646@var{print-values} is 1 or @code{--all-values}, also print their
21647values; and if it is 2 or @code{--simple-values} print the name and
21648value for simple data types and just the name for arrays, structures
21649and unions.
922fbb7b
AC
21650
21651@subsubheading Example
21652
21653@smallexample
594fe323 21654(gdb)
a2c02241
NR
21655 -var-list-children n
21656 ^done,numchild=@var{n},children=[@{name=@var{name},
21657 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 21658(gdb)
a2c02241
NR
21659 -var-list-children --all-values n
21660 ^done,numchild=@var{n},children=[@{name=@var{name},
21661 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
21662@end smallexample
21663
922fbb7b 21664
a2c02241
NR
21665@subheading The @code{-var-info-type} Command
21666@findex -var-info-type
922fbb7b 21667
a2c02241
NR
21668@subsubheading Synopsis
21669
21670@smallexample
21671 -var-info-type @var{name}
21672@end smallexample
21673
21674Returns the type of the specified variable @var{name}. The type is
21675returned as a string in the same format as it is output by the
21676@value{GDBN} CLI:
21677
21678@smallexample
21679 type=@var{typename}
21680@end smallexample
21681
21682
21683@subheading The @code{-var-info-expression} Command
21684@findex -var-info-expression
922fbb7b
AC
21685
21686@subsubheading Synopsis
21687
21688@smallexample
a2c02241 21689 -var-info-expression @var{name}
922fbb7b
AC
21690@end smallexample
21691
02142340
VP
21692Returns a string that is suitable for presenting this
21693variable object in user interface. The string is generally
21694not valid expression in the current language, and cannot be evaluated.
21695
21696For example, if @code{a} is an array, and variable object
21697@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 21698
a2c02241 21699@smallexample
02142340
VP
21700(gdb) -var-info-expression A.1
21701^done,lang="C",exp="1"
a2c02241 21702@end smallexample
922fbb7b 21703
a2c02241 21704@noindent
02142340
VP
21705Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
21706
21707Note that the output of the @code{-var-list-children} command also
21708includes those expressions, so the @code{-var-info-expression} command
21709is of limited use.
21710
21711@subheading The @code{-var-info-path-expression} Command
21712@findex -var-info-path-expression
21713
21714@subsubheading Synopsis
21715
21716@smallexample
21717 -var-info-path-expression @var{name}
21718@end smallexample
21719
21720Returns an expression that can be evaluated in the current
21721context and will yield the same value that a variable object has.
21722Compare this with the @code{-var-info-expression} command, which
21723result can be used only for UI presentation. Typical use of
21724the @code{-var-info-path-expression} command is creating a
21725watchpoint from a variable object.
21726
21727For example, suppose @code{C} is a C@t{++} class, derived from class
21728@code{Base}, and that the @code{Base} class has a member called
21729@code{m_size}. Assume a variable @code{c} is has the type of
21730@code{C} and a variable object @code{C} was created for variable
21731@code{c}. Then, we'll get this output:
21732@smallexample
21733(gdb) -var-info-path-expression C.Base.public.m_size
21734^done,path_expr=((Base)c).m_size)
21735@end smallexample
922fbb7b 21736
a2c02241
NR
21737@subheading The @code{-var-show-attributes} Command
21738@findex -var-show-attributes
922fbb7b 21739
a2c02241 21740@subsubheading Synopsis
922fbb7b 21741
a2c02241
NR
21742@smallexample
21743 -var-show-attributes @var{name}
21744@end smallexample
922fbb7b 21745
a2c02241 21746List attributes of the specified variable object @var{name}:
922fbb7b
AC
21747
21748@smallexample
a2c02241 21749 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
21750@end smallexample
21751
a2c02241
NR
21752@noindent
21753where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
21754
21755@subheading The @code{-var-evaluate-expression} Command
21756@findex -var-evaluate-expression
21757
21758@subsubheading Synopsis
21759
21760@smallexample
de051565 21761 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
21762@end smallexample
21763
21764Evaluates the expression that is represented by the specified variable
de051565
MK
21765object and returns its value as a string. The format of the string
21766can be specified with the @samp{-f} option. The possible values of
21767this option are the same as for @code{-var-set-format}
21768(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
21769the current display format will be used. The current display format
21770can be changed using the @code{-var-set-format} command.
a2c02241
NR
21771
21772@smallexample
21773 value=@var{value}
21774@end smallexample
21775
21776Note that one must invoke @code{-var-list-children} for a variable
21777before the value of a child variable can be evaluated.
21778
21779@subheading The @code{-var-assign} Command
21780@findex -var-assign
21781
21782@subsubheading Synopsis
21783
21784@smallexample
21785 -var-assign @var{name} @var{expression}
21786@end smallexample
21787
21788Assigns the value of @var{expression} to the variable object specified
21789by @var{name}. The object must be @samp{editable}. If the variable's
21790value is altered by the assign, the variable will show up in any
21791subsequent @code{-var-update} list.
21792
21793@subsubheading Example
922fbb7b
AC
21794
21795@smallexample
594fe323 21796(gdb)
a2c02241
NR
21797-var-assign var1 3
21798^done,value="3"
594fe323 21799(gdb)
a2c02241
NR
21800-var-update *
21801^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 21802(gdb)
922fbb7b
AC
21803@end smallexample
21804
a2c02241
NR
21805@subheading The @code{-var-update} Command
21806@findex -var-update
21807
21808@subsubheading Synopsis
21809
21810@smallexample
21811 -var-update [@var{print-values}] @{@var{name} | "*"@}
21812@end smallexample
21813
c8b2f53c
VP
21814Reevaluate the expressions corresponding to the variable object
21815@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
21816list of variable objects whose values have changed; @var{name} must
21817be a root variable object. Here, ``changed'' means that the result of
21818@code{-var-evaluate-expression} before and after the
21819@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
21820object names, all existing variable objects are updated, except
21821for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 21822@var{print-values} determines whether both names and values, or just
de051565 21823names are printed. The possible values of this option are the same
36ece8b3
NR
21824as for @code{-var-list-children} (@pxref{-var-list-children}). It is
21825recommended to use the @samp{--all-values} option, to reduce the
21826number of MI commands needed on each program stop.
c8b2f53c 21827
c3b108f7
VP
21828With the @samp{*} parameter, if a variable object is bound to a
21829currently running thread, it will not be updated, without any
21830diagnostic.
a2c02241
NR
21831
21832@subsubheading Example
922fbb7b
AC
21833
21834@smallexample
594fe323 21835(gdb)
a2c02241
NR
21836-var-assign var1 3
21837^done,value="3"
594fe323 21838(gdb)
a2c02241
NR
21839-var-update --all-values var1
21840^done,changelist=[@{name="var1",value="3",in_scope="true",
21841type_changed="false"@}]
594fe323 21842(gdb)
922fbb7b
AC
21843@end smallexample
21844
9f708cb2 21845@anchor{-var-update}
36ece8b3
NR
21846The field in_scope may take three values:
21847
21848@table @code
21849@item "true"
21850The variable object's current value is valid.
21851
21852@item "false"
21853The variable object does not currently hold a valid value but it may
21854hold one in the future if its associated expression comes back into
21855scope.
21856
21857@item "invalid"
21858The variable object no longer holds a valid value.
21859This can occur when the executable file being debugged has changed,
21860either through recompilation or by using the @value{GDBN} @code{file}
21861command. The front end should normally choose to delete these variable
21862objects.
21863@end table
21864
21865In the future new values may be added to this list so the front should
21866be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
21867
25d5ea92
VP
21868@subheading The @code{-var-set-frozen} Command
21869@findex -var-set-frozen
9f708cb2 21870@anchor{-var-set-frozen}
25d5ea92
VP
21871
21872@subsubheading Synopsis
21873
21874@smallexample
9f708cb2 21875 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
21876@end smallexample
21877
9f708cb2 21878Set the frozenness flag on the variable object @var{name}. The
25d5ea92 21879@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 21880frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 21881frozen, then neither itself, nor any of its children, are
9f708cb2 21882implicitly updated by @code{-var-update} of
25d5ea92
VP
21883a parent variable or by @code{-var-update *}. Only
21884@code{-var-update} of the variable itself will update its value and
21885values of its children. After a variable object is unfrozen, it is
21886implicitly updated by all subsequent @code{-var-update} operations.
21887Unfreezing a variable does not update it, only subsequent
21888@code{-var-update} does.
21889
21890@subsubheading Example
21891
21892@smallexample
21893(gdb)
21894-var-set-frozen V 1
21895^done
21896(gdb)
21897@end smallexample
21898
21899
a2c02241
NR
21900@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21901@node GDB/MI Data Manipulation
21902@section @sc{gdb/mi} Data Manipulation
922fbb7b 21903
a2c02241
NR
21904@cindex data manipulation, in @sc{gdb/mi}
21905@cindex @sc{gdb/mi}, data manipulation
21906This section describes the @sc{gdb/mi} commands that manipulate data:
21907examine memory and registers, evaluate expressions, etc.
21908
21909@c REMOVED FROM THE INTERFACE.
21910@c @subheading -data-assign
21911@c Change the value of a program variable. Plenty of side effects.
79a6e687 21912@c @subsubheading GDB Command
a2c02241
NR
21913@c set variable
21914@c @subsubheading Example
21915@c N.A.
21916
21917@subheading The @code{-data-disassemble} Command
21918@findex -data-disassemble
922fbb7b
AC
21919
21920@subsubheading Synopsis
21921
21922@smallexample
a2c02241
NR
21923 -data-disassemble
21924 [ -s @var{start-addr} -e @var{end-addr} ]
21925 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
21926 -- @var{mode}
922fbb7b
AC
21927@end smallexample
21928
a2c02241
NR
21929@noindent
21930Where:
21931
21932@table @samp
21933@item @var{start-addr}
21934is the beginning address (or @code{$pc})
21935@item @var{end-addr}
21936is the end address
21937@item @var{filename}
21938is the name of the file to disassemble
21939@item @var{linenum}
21940is the line number to disassemble around
21941@item @var{lines}
d3e8051b 21942is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
21943the whole function will be disassembled, in case no @var{end-addr} is
21944specified. If @var{end-addr} is specified as a non-zero value, and
21945@var{lines} is lower than the number of disassembly lines between
21946@var{start-addr} and @var{end-addr}, only @var{lines} lines are
21947displayed; if @var{lines} is higher than the number of lines between
21948@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
21949are displayed.
21950@item @var{mode}
21951is either 0 (meaning only disassembly) or 1 (meaning mixed source and
21952disassembly).
21953@end table
21954
21955@subsubheading Result
21956
21957The output for each instruction is composed of four fields:
21958
21959@itemize @bullet
21960@item Address
21961@item Func-name
21962@item Offset
21963@item Instruction
21964@end itemize
21965
21966Note that whatever included in the instruction field, is not manipulated
d3e8051b 21967directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
922fbb7b
AC
21968
21969@subsubheading @value{GDBN} Command
21970
a2c02241 21971There's no direct mapping from this command to the CLI.
922fbb7b
AC
21972
21973@subsubheading Example
21974
a2c02241
NR
21975Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
21976
922fbb7b 21977@smallexample
594fe323 21978(gdb)
a2c02241
NR
21979-data-disassemble -s $pc -e "$pc + 20" -- 0
21980^done,
21981asm_insns=[
21982@{address="0x000107c0",func-name="main",offset="4",
21983inst="mov 2, %o0"@},
21984@{address="0x000107c4",func-name="main",offset="8",
21985inst="sethi %hi(0x11800), %o2"@},
21986@{address="0x000107c8",func-name="main",offset="12",
21987inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
21988@{address="0x000107cc",func-name="main",offset="16",
21989inst="sethi %hi(0x11800), %o2"@},
21990@{address="0x000107d0",func-name="main",offset="20",
21991inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 21992(gdb)
a2c02241
NR
21993@end smallexample
21994
21995Disassemble the whole @code{main} function. Line 32 is part of
21996@code{main}.
21997
21998@smallexample
21999-data-disassemble -f basics.c -l 32 -- 0
22000^done,asm_insns=[
22001@{address="0x000107bc",func-name="main",offset="0",
22002inst="save %sp, -112, %sp"@},
22003@{address="0x000107c0",func-name="main",offset="4",
22004inst="mov 2, %o0"@},
22005@{address="0x000107c4",func-name="main",offset="8",
22006inst="sethi %hi(0x11800), %o2"@},
22007[@dots{}]
22008@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
22009@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 22010(gdb)
922fbb7b
AC
22011@end smallexample
22012
a2c02241 22013Disassemble 3 instructions from the start of @code{main}:
922fbb7b 22014
a2c02241 22015@smallexample
594fe323 22016(gdb)
a2c02241
NR
22017-data-disassemble -f basics.c -l 32 -n 3 -- 0
22018^done,asm_insns=[
22019@{address="0x000107bc",func-name="main",offset="0",
22020inst="save %sp, -112, %sp"@},
22021@{address="0x000107c0",func-name="main",offset="4",
22022inst="mov 2, %o0"@},
22023@{address="0x000107c4",func-name="main",offset="8",
22024inst="sethi %hi(0x11800), %o2"@}]
594fe323 22025(gdb)
a2c02241
NR
22026@end smallexample
22027
22028Disassemble 3 instructions from the start of @code{main} in mixed mode:
22029
22030@smallexample
594fe323 22031(gdb)
a2c02241
NR
22032-data-disassemble -f basics.c -l 32 -n 3 -- 1
22033^done,asm_insns=[
22034src_and_asm_line=@{line="31",
22035file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
22036 testsuite/gdb.mi/basics.c",line_asm_insn=[
22037@{address="0x000107bc",func-name="main",offset="0",
22038inst="save %sp, -112, %sp"@}]@},
22039src_and_asm_line=@{line="32",
22040file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
22041 testsuite/gdb.mi/basics.c",line_asm_insn=[
22042@{address="0x000107c0",func-name="main",offset="4",
22043inst="mov 2, %o0"@},
22044@{address="0x000107c4",func-name="main",offset="8",
22045inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 22046(gdb)
a2c02241
NR
22047@end smallexample
22048
22049
22050@subheading The @code{-data-evaluate-expression} Command
22051@findex -data-evaluate-expression
922fbb7b
AC
22052
22053@subsubheading Synopsis
22054
22055@smallexample
a2c02241 22056 -data-evaluate-expression @var{expr}
922fbb7b
AC
22057@end smallexample
22058
a2c02241
NR
22059Evaluate @var{expr} as an expression. The expression could contain an
22060inferior function call. The function call will execute synchronously.
22061If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
22062
22063@subsubheading @value{GDBN} Command
22064
a2c02241
NR
22065The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
22066@samp{call}. In @code{gdbtk} only, there's a corresponding
22067@samp{gdb_eval} command.
922fbb7b
AC
22068
22069@subsubheading Example
22070
a2c02241
NR
22071In the following example, the numbers that precede the commands are the
22072@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
22073Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
22074output.
22075
922fbb7b 22076@smallexample
a2c02241
NR
22077211-data-evaluate-expression A
22078211^done,value="1"
594fe323 22079(gdb)
a2c02241
NR
22080311-data-evaluate-expression &A
22081311^done,value="0xefffeb7c"
594fe323 22082(gdb)
a2c02241
NR
22083411-data-evaluate-expression A+3
22084411^done,value="4"
594fe323 22085(gdb)
a2c02241
NR
22086511-data-evaluate-expression "A + 3"
22087511^done,value="4"
594fe323 22088(gdb)
a2c02241 22089@end smallexample
922fbb7b
AC
22090
22091
a2c02241
NR
22092@subheading The @code{-data-list-changed-registers} Command
22093@findex -data-list-changed-registers
922fbb7b
AC
22094
22095@subsubheading Synopsis
22096
22097@smallexample
a2c02241 22098 -data-list-changed-registers
922fbb7b
AC
22099@end smallexample
22100
a2c02241 22101Display a list of the registers that have changed.
922fbb7b
AC
22102
22103@subsubheading @value{GDBN} Command
22104
a2c02241
NR
22105@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
22106has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
22107
22108@subsubheading Example
922fbb7b 22109
a2c02241 22110On a PPC MBX board:
922fbb7b
AC
22111
22112@smallexample
594fe323 22113(gdb)
a2c02241
NR
22114-exec-continue
22115^running
922fbb7b 22116
594fe323 22117(gdb)
a47ec5fe
AR
22118*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
22119func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
22120line="5"@}
594fe323 22121(gdb)
a2c02241
NR
22122-data-list-changed-registers
22123^done,changed-registers=["0","1","2","4","5","6","7","8","9",
22124"10","11","13","14","15","16","17","18","19","20","21","22","23",
22125"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 22126(gdb)
a2c02241 22127@end smallexample
922fbb7b
AC
22128
22129
a2c02241
NR
22130@subheading The @code{-data-list-register-names} Command
22131@findex -data-list-register-names
922fbb7b
AC
22132
22133@subsubheading Synopsis
22134
22135@smallexample
a2c02241 22136 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
22137@end smallexample
22138
a2c02241
NR
22139Show a list of register names for the current target. If no arguments
22140are given, it shows a list of the names of all the registers. If
22141integer numbers are given as arguments, it will print a list of the
22142names of the registers corresponding to the arguments. To ensure
22143consistency between a register name and its number, the output list may
22144include empty register names.
922fbb7b
AC
22145
22146@subsubheading @value{GDBN} Command
22147
a2c02241
NR
22148@value{GDBN} does not have a command which corresponds to
22149@samp{-data-list-register-names}. In @code{gdbtk} there is a
22150corresponding command @samp{gdb_regnames}.
922fbb7b
AC
22151
22152@subsubheading Example
922fbb7b 22153
a2c02241
NR
22154For the PPC MBX board:
22155@smallexample
594fe323 22156(gdb)
a2c02241
NR
22157-data-list-register-names
22158^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
22159"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
22160"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
22161"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
22162"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
22163"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
22164"", "pc","ps","cr","lr","ctr","xer"]
594fe323 22165(gdb)
a2c02241
NR
22166-data-list-register-names 1 2 3
22167^done,register-names=["r1","r2","r3"]
594fe323 22168(gdb)
a2c02241 22169@end smallexample
922fbb7b 22170
a2c02241
NR
22171@subheading The @code{-data-list-register-values} Command
22172@findex -data-list-register-values
922fbb7b
AC
22173
22174@subsubheading Synopsis
22175
22176@smallexample
a2c02241 22177 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
22178@end smallexample
22179
a2c02241
NR
22180Display the registers' contents. @var{fmt} is the format according to
22181which the registers' contents are to be returned, followed by an optional
22182list of numbers specifying the registers to display. A missing list of
22183numbers indicates that the contents of all the registers must be returned.
22184
22185Allowed formats for @var{fmt} are:
22186
22187@table @code
22188@item x
22189Hexadecimal
22190@item o
22191Octal
22192@item t
22193Binary
22194@item d
22195Decimal
22196@item r
22197Raw
22198@item N
22199Natural
22200@end table
922fbb7b
AC
22201
22202@subsubheading @value{GDBN} Command
22203
a2c02241
NR
22204The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
22205all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
22206
22207@subsubheading Example
922fbb7b 22208
a2c02241
NR
22209For a PPC MBX board (note: line breaks are for readability only, they
22210don't appear in the actual output):
22211
22212@smallexample
594fe323 22213(gdb)
a2c02241
NR
22214-data-list-register-values r 64 65
22215^done,register-values=[@{number="64",value="0xfe00a300"@},
22216@{number="65",value="0x00029002"@}]
594fe323 22217(gdb)
a2c02241
NR
22218-data-list-register-values x
22219^done,register-values=[@{number="0",value="0xfe0043c8"@},
22220@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
22221@{number="3",value="0x0"@},@{number="4",value="0xa"@},
22222@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
22223@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
22224@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
22225@{number="11",value="0x1"@},@{number="12",value="0x0"@},
22226@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
22227@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
22228@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
22229@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
22230@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
22231@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
22232@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
22233@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
22234@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
22235@{number="31",value="0x0"@},@{number="32",value="0x0"@},
22236@{number="33",value="0x0"@},@{number="34",value="0x0"@},
22237@{number="35",value="0x0"@},@{number="36",value="0x0"@},
22238@{number="37",value="0x0"@},@{number="38",value="0x0"@},
22239@{number="39",value="0x0"@},@{number="40",value="0x0"@},
22240@{number="41",value="0x0"@},@{number="42",value="0x0"@},
22241@{number="43",value="0x0"@},@{number="44",value="0x0"@},
22242@{number="45",value="0x0"@},@{number="46",value="0x0"@},
22243@{number="47",value="0x0"@},@{number="48",value="0x0"@},
22244@{number="49",value="0x0"@},@{number="50",value="0x0"@},
22245@{number="51",value="0x0"@},@{number="52",value="0x0"@},
22246@{number="53",value="0x0"@},@{number="54",value="0x0"@},
22247@{number="55",value="0x0"@},@{number="56",value="0x0"@},
22248@{number="57",value="0x0"@},@{number="58",value="0x0"@},
22249@{number="59",value="0x0"@},@{number="60",value="0x0"@},
22250@{number="61",value="0x0"@},@{number="62",value="0x0"@},
22251@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
22252@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
22253@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
22254@{number="69",value="0x20002b03"@}]
594fe323 22255(gdb)
a2c02241 22256@end smallexample
922fbb7b 22257
a2c02241
NR
22258
22259@subheading The @code{-data-read-memory} Command
22260@findex -data-read-memory
922fbb7b
AC
22261
22262@subsubheading Synopsis
22263
22264@smallexample
a2c02241
NR
22265 -data-read-memory [ -o @var{byte-offset} ]
22266 @var{address} @var{word-format} @var{word-size}
22267 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
22268@end smallexample
22269
a2c02241
NR
22270@noindent
22271where:
922fbb7b 22272
a2c02241
NR
22273@table @samp
22274@item @var{address}
22275An expression specifying the address of the first memory word to be
22276read. Complex expressions containing embedded white space should be
22277quoted using the C convention.
922fbb7b 22278
a2c02241
NR
22279@item @var{word-format}
22280The format to be used to print the memory words. The notation is the
22281same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 22282,Output Formats}).
922fbb7b 22283
a2c02241
NR
22284@item @var{word-size}
22285The size of each memory word in bytes.
922fbb7b 22286
a2c02241
NR
22287@item @var{nr-rows}
22288The number of rows in the output table.
922fbb7b 22289
a2c02241
NR
22290@item @var{nr-cols}
22291The number of columns in the output table.
922fbb7b 22292
a2c02241
NR
22293@item @var{aschar}
22294If present, indicates that each row should include an @sc{ascii} dump. The
22295value of @var{aschar} is used as a padding character when a byte is not a
22296member of the printable @sc{ascii} character set (printable @sc{ascii}
22297characters are those whose code is between 32 and 126, inclusively).
922fbb7b 22298
a2c02241
NR
22299@item @var{byte-offset}
22300An offset to add to the @var{address} before fetching memory.
22301@end table
922fbb7b 22302
a2c02241
NR
22303This command displays memory contents as a table of @var{nr-rows} by
22304@var{nr-cols} words, each word being @var{word-size} bytes. In total,
22305@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
22306(returned as @samp{total-bytes}). Should less than the requested number
22307of bytes be returned by the target, the missing words are identified
22308using @samp{N/A}. The number of bytes read from the target is returned
22309in @samp{nr-bytes} and the starting address used to read memory in
22310@samp{addr}.
22311
22312The address of the next/previous row or page is available in
22313@samp{next-row} and @samp{prev-row}, @samp{next-page} and
22314@samp{prev-page}.
922fbb7b
AC
22315
22316@subsubheading @value{GDBN} Command
22317
a2c02241
NR
22318The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
22319@samp{gdb_get_mem} memory read command.
922fbb7b
AC
22320
22321@subsubheading Example
32e7087d 22322
a2c02241
NR
22323Read six bytes of memory starting at @code{bytes+6} but then offset by
22324@code{-6} bytes. Format as three rows of two columns. One byte per
22325word. Display each word in hex.
32e7087d
JB
22326
22327@smallexample
594fe323 22328(gdb)
a2c02241
NR
223299-data-read-memory -o -6 -- bytes+6 x 1 3 2
223309^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
22331next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
22332prev-page="0x0000138a",memory=[
22333@{addr="0x00001390",data=["0x00","0x01"]@},
22334@{addr="0x00001392",data=["0x02","0x03"]@},
22335@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 22336(gdb)
32e7087d
JB
22337@end smallexample
22338
a2c02241
NR
22339Read two bytes of memory starting at address @code{shorts + 64} and
22340display as a single word formatted in decimal.
32e7087d 22341
32e7087d 22342@smallexample
594fe323 22343(gdb)
a2c02241
NR
223445-data-read-memory shorts+64 d 2 1 1
223455^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
22346next-row="0x00001512",prev-row="0x0000150e",
22347next-page="0x00001512",prev-page="0x0000150e",memory=[
22348@{addr="0x00001510",data=["128"]@}]
594fe323 22349(gdb)
32e7087d
JB
22350@end smallexample
22351
a2c02241
NR
22352Read thirty two bytes of memory starting at @code{bytes+16} and format
22353as eight rows of four columns. Include a string encoding with @samp{x}
22354used as the non-printable character.
922fbb7b
AC
22355
22356@smallexample
594fe323 22357(gdb)
a2c02241
NR
223584-data-read-memory bytes+16 x 1 8 4 x
223594^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
22360next-row="0x000013c0",prev-row="0x0000139c",
22361next-page="0x000013c0",prev-page="0x00001380",memory=[
22362@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
22363@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
22364@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
22365@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
22366@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
22367@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
22368@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
22369@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 22370(gdb)
922fbb7b
AC
22371@end smallexample
22372
a2c02241
NR
22373@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22374@node GDB/MI Tracepoint Commands
22375@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 22376
a2c02241 22377The tracepoint commands are not yet implemented.
922fbb7b 22378
a2c02241 22379@c @subheading -trace-actions
922fbb7b 22380
a2c02241 22381@c @subheading -trace-delete
922fbb7b 22382
a2c02241 22383@c @subheading -trace-disable
922fbb7b 22384
a2c02241 22385@c @subheading -trace-dump
922fbb7b 22386
a2c02241 22387@c @subheading -trace-enable
922fbb7b 22388
a2c02241 22389@c @subheading -trace-exists
922fbb7b 22390
a2c02241 22391@c @subheading -trace-find
922fbb7b 22392
a2c02241 22393@c @subheading -trace-frame-number
922fbb7b 22394
a2c02241 22395@c @subheading -trace-info
922fbb7b 22396
a2c02241 22397@c @subheading -trace-insert
922fbb7b 22398
a2c02241 22399@c @subheading -trace-list
922fbb7b 22400
a2c02241 22401@c @subheading -trace-pass-count
922fbb7b 22402
a2c02241 22403@c @subheading -trace-save
922fbb7b 22404
a2c02241 22405@c @subheading -trace-start
922fbb7b 22406
a2c02241 22407@c @subheading -trace-stop
922fbb7b 22408
922fbb7b 22409
a2c02241
NR
22410@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22411@node GDB/MI Symbol Query
22412@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
22413
22414
a2c02241
NR
22415@subheading The @code{-symbol-info-address} Command
22416@findex -symbol-info-address
922fbb7b
AC
22417
22418@subsubheading Synopsis
22419
22420@smallexample
a2c02241 22421 -symbol-info-address @var{symbol}
922fbb7b
AC
22422@end smallexample
22423
a2c02241 22424Describe where @var{symbol} is stored.
922fbb7b
AC
22425
22426@subsubheading @value{GDBN} Command
22427
a2c02241 22428The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
22429
22430@subsubheading Example
22431N.A.
22432
22433
a2c02241
NR
22434@subheading The @code{-symbol-info-file} Command
22435@findex -symbol-info-file
922fbb7b
AC
22436
22437@subsubheading Synopsis
22438
22439@smallexample
a2c02241 22440 -symbol-info-file
922fbb7b
AC
22441@end smallexample
22442
a2c02241 22443Show the file for the symbol.
922fbb7b 22444
a2c02241 22445@subsubheading @value{GDBN} Command
922fbb7b 22446
a2c02241
NR
22447There's no equivalent @value{GDBN} command. @code{gdbtk} has
22448@samp{gdb_find_file}.
922fbb7b
AC
22449
22450@subsubheading Example
22451N.A.
22452
22453
a2c02241
NR
22454@subheading The @code{-symbol-info-function} Command
22455@findex -symbol-info-function
922fbb7b
AC
22456
22457@subsubheading Synopsis
22458
22459@smallexample
a2c02241 22460 -symbol-info-function
922fbb7b
AC
22461@end smallexample
22462
a2c02241 22463Show which function the symbol lives in.
922fbb7b
AC
22464
22465@subsubheading @value{GDBN} Command
22466
a2c02241 22467@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
22468
22469@subsubheading Example
22470N.A.
22471
22472
a2c02241
NR
22473@subheading The @code{-symbol-info-line} Command
22474@findex -symbol-info-line
922fbb7b
AC
22475
22476@subsubheading Synopsis
22477
22478@smallexample
a2c02241 22479 -symbol-info-line
922fbb7b
AC
22480@end smallexample
22481
a2c02241 22482Show the core addresses of the code for a source line.
922fbb7b 22483
a2c02241 22484@subsubheading @value{GDBN} Command
922fbb7b 22485
a2c02241
NR
22486The corresponding @value{GDBN} command is @samp{info line}.
22487@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
22488
22489@subsubheading Example
a2c02241 22490N.A.
922fbb7b
AC
22491
22492
a2c02241
NR
22493@subheading The @code{-symbol-info-symbol} Command
22494@findex -symbol-info-symbol
07f31aa6
DJ
22495
22496@subsubheading Synopsis
22497
a2c02241
NR
22498@smallexample
22499 -symbol-info-symbol @var{addr}
22500@end smallexample
07f31aa6 22501
a2c02241 22502Describe what symbol is at location @var{addr}.
07f31aa6 22503
a2c02241 22504@subsubheading @value{GDBN} Command
07f31aa6 22505
a2c02241 22506The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
22507
22508@subsubheading Example
a2c02241 22509N.A.
07f31aa6
DJ
22510
22511
a2c02241
NR
22512@subheading The @code{-symbol-list-functions} Command
22513@findex -symbol-list-functions
922fbb7b
AC
22514
22515@subsubheading Synopsis
22516
22517@smallexample
a2c02241 22518 -symbol-list-functions
922fbb7b
AC
22519@end smallexample
22520
a2c02241 22521List the functions in the executable.
922fbb7b
AC
22522
22523@subsubheading @value{GDBN} Command
22524
a2c02241
NR
22525@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
22526@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
22527
22528@subsubheading Example
a2c02241 22529N.A.
922fbb7b
AC
22530
22531
a2c02241
NR
22532@subheading The @code{-symbol-list-lines} Command
22533@findex -symbol-list-lines
922fbb7b
AC
22534
22535@subsubheading Synopsis
22536
22537@smallexample
a2c02241 22538 -symbol-list-lines @var{filename}
922fbb7b
AC
22539@end smallexample
22540
a2c02241
NR
22541Print the list of lines that contain code and their associated program
22542addresses for the given source filename. The entries are sorted in
22543ascending PC order.
922fbb7b
AC
22544
22545@subsubheading @value{GDBN} Command
22546
a2c02241 22547There is no corresponding @value{GDBN} command.
922fbb7b
AC
22548
22549@subsubheading Example
a2c02241 22550@smallexample
594fe323 22551(gdb)
a2c02241
NR
22552-symbol-list-lines basics.c
22553^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 22554(gdb)
a2c02241 22555@end smallexample
922fbb7b
AC
22556
22557
a2c02241
NR
22558@subheading The @code{-symbol-list-types} Command
22559@findex -symbol-list-types
922fbb7b
AC
22560
22561@subsubheading Synopsis
22562
22563@smallexample
a2c02241 22564 -symbol-list-types
922fbb7b
AC
22565@end smallexample
22566
a2c02241 22567List all the type names.
922fbb7b
AC
22568
22569@subsubheading @value{GDBN} Command
22570
a2c02241
NR
22571The corresponding commands are @samp{info types} in @value{GDBN},
22572@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
22573
22574@subsubheading Example
22575N.A.
22576
22577
a2c02241
NR
22578@subheading The @code{-symbol-list-variables} Command
22579@findex -symbol-list-variables
922fbb7b
AC
22580
22581@subsubheading Synopsis
22582
22583@smallexample
a2c02241 22584 -symbol-list-variables
922fbb7b
AC
22585@end smallexample
22586
a2c02241 22587List all the global and static variable names.
922fbb7b
AC
22588
22589@subsubheading @value{GDBN} Command
22590
a2c02241 22591@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
22592
22593@subsubheading Example
22594N.A.
22595
22596
a2c02241
NR
22597@subheading The @code{-symbol-locate} Command
22598@findex -symbol-locate
922fbb7b
AC
22599
22600@subsubheading Synopsis
22601
22602@smallexample
a2c02241 22603 -symbol-locate
922fbb7b
AC
22604@end smallexample
22605
922fbb7b
AC
22606@subsubheading @value{GDBN} Command
22607
a2c02241 22608@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
22609
22610@subsubheading Example
22611N.A.
22612
22613
a2c02241
NR
22614@subheading The @code{-symbol-type} Command
22615@findex -symbol-type
922fbb7b
AC
22616
22617@subsubheading Synopsis
22618
22619@smallexample
a2c02241 22620 -symbol-type @var{variable}
922fbb7b
AC
22621@end smallexample
22622
a2c02241 22623Show type of @var{variable}.
922fbb7b 22624
a2c02241 22625@subsubheading @value{GDBN} Command
922fbb7b 22626
a2c02241
NR
22627The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
22628@samp{gdb_obj_variable}.
22629
22630@subsubheading Example
22631N.A.
22632
22633
22634@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22635@node GDB/MI File Commands
22636@section @sc{gdb/mi} File Commands
22637
22638This section describes the GDB/MI commands to specify executable file names
22639and to read in and obtain symbol table information.
22640
22641@subheading The @code{-file-exec-and-symbols} Command
22642@findex -file-exec-and-symbols
22643
22644@subsubheading Synopsis
922fbb7b
AC
22645
22646@smallexample
a2c02241 22647 -file-exec-and-symbols @var{file}
922fbb7b
AC
22648@end smallexample
22649
a2c02241
NR
22650Specify the executable file to be debugged. This file is the one from
22651which the symbol table is also read. If no file is specified, the
22652command clears the executable and symbol information. If breakpoints
22653are set when using this command with no arguments, @value{GDBN} will produce
22654error messages. Otherwise, no output is produced, except a completion
22655notification.
22656
922fbb7b
AC
22657@subsubheading @value{GDBN} Command
22658
a2c02241 22659The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
22660
22661@subsubheading Example
22662
22663@smallexample
594fe323 22664(gdb)
a2c02241
NR
22665-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
22666^done
594fe323 22667(gdb)
922fbb7b
AC
22668@end smallexample
22669
922fbb7b 22670
a2c02241
NR
22671@subheading The @code{-file-exec-file} Command
22672@findex -file-exec-file
922fbb7b
AC
22673
22674@subsubheading Synopsis
22675
22676@smallexample
a2c02241 22677 -file-exec-file @var{file}
922fbb7b
AC
22678@end smallexample
22679
a2c02241
NR
22680Specify the executable file to be debugged. Unlike
22681@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
22682from this file. If used without argument, @value{GDBN} clears the information
22683about the executable file. No output is produced, except a completion
22684notification.
922fbb7b 22685
a2c02241
NR
22686@subsubheading @value{GDBN} Command
22687
22688The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
22689
22690@subsubheading Example
a2c02241
NR
22691
22692@smallexample
594fe323 22693(gdb)
a2c02241
NR
22694-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
22695^done
594fe323 22696(gdb)
a2c02241 22697@end smallexample
922fbb7b
AC
22698
22699
a2c02241
NR
22700@subheading The @code{-file-list-exec-sections} Command
22701@findex -file-list-exec-sections
922fbb7b
AC
22702
22703@subsubheading Synopsis
22704
22705@smallexample
a2c02241 22706 -file-list-exec-sections
922fbb7b
AC
22707@end smallexample
22708
a2c02241
NR
22709List the sections of the current executable file.
22710
922fbb7b
AC
22711@subsubheading @value{GDBN} Command
22712
a2c02241
NR
22713The @value{GDBN} command @samp{info file} shows, among the rest, the same
22714information as this command. @code{gdbtk} has a corresponding command
22715@samp{gdb_load_info}.
922fbb7b
AC
22716
22717@subsubheading Example
22718N.A.
22719
22720
a2c02241
NR
22721@subheading The @code{-file-list-exec-source-file} Command
22722@findex -file-list-exec-source-file
922fbb7b
AC
22723
22724@subsubheading Synopsis
22725
22726@smallexample
a2c02241 22727 -file-list-exec-source-file
922fbb7b
AC
22728@end smallexample
22729
a2c02241 22730List the line number, the current source file, and the absolute path
44288b44
NR
22731to the current source file for the current executable. The macro
22732information field has a value of @samp{1} or @samp{0} depending on
22733whether or not the file includes preprocessor macro information.
922fbb7b
AC
22734
22735@subsubheading @value{GDBN} Command
22736
a2c02241 22737The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
22738
22739@subsubheading Example
22740
922fbb7b 22741@smallexample
594fe323 22742(gdb)
a2c02241 22743123-file-list-exec-source-file
44288b44 22744123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 22745(gdb)
922fbb7b
AC
22746@end smallexample
22747
22748
a2c02241
NR
22749@subheading The @code{-file-list-exec-source-files} Command
22750@findex -file-list-exec-source-files
922fbb7b
AC
22751
22752@subsubheading Synopsis
22753
22754@smallexample
a2c02241 22755 -file-list-exec-source-files
922fbb7b
AC
22756@end smallexample
22757
a2c02241
NR
22758List the source files for the current executable.
22759
3f94c067
BW
22760It will always output the filename, but only when @value{GDBN} can find
22761the absolute file name of a source file, will it output the fullname.
922fbb7b
AC
22762
22763@subsubheading @value{GDBN} Command
22764
a2c02241
NR
22765The @value{GDBN} equivalent is @samp{info sources}.
22766@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
22767
22768@subsubheading Example
922fbb7b 22769@smallexample
594fe323 22770(gdb)
a2c02241
NR
22771-file-list-exec-source-files
22772^done,files=[
22773@{file=foo.c,fullname=/home/foo.c@},
22774@{file=/home/bar.c,fullname=/home/bar.c@},
22775@{file=gdb_could_not_find_fullpath.c@}]
594fe323 22776(gdb)
922fbb7b
AC
22777@end smallexample
22778
a2c02241
NR
22779@subheading The @code{-file-list-shared-libraries} Command
22780@findex -file-list-shared-libraries
922fbb7b 22781
a2c02241 22782@subsubheading Synopsis
922fbb7b 22783
a2c02241
NR
22784@smallexample
22785 -file-list-shared-libraries
22786@end smallexample
922fbb7b 22787
a2c02241 22788List the shared libraries in the program.
922fbb7b 22789
a2c02241 22790@subsubheading @value{GDBN} Command
922fbb7b 22791
a2c02241 22792The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 22793
a2c02241
NR
22794@subsubheading Example
22795N.A.
922fbb7b
AC
22796
22797
a2c02241
NR
22798@subheading The @code{-file-list-symbol-files} Command
22799@findex -file-list-symbol-files
922fbb7b 22800
a2c02241 22801@subsubheading Synopsis
922fbb7b 22802
a2c02241
NR
22803@smallexample
22804 -file-list-symbol-files
22805@end smallexample
922fbb7b 22806
a2c02241 22807List symbol files.
922fbb7b 22808
a2c02241 22809@subsubheading @value{GDBN} Command
922fbb7b 22810
a2c02241 22811The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 22812
a2c02241
NR
22813@subsubheading Example
22814N.A.
922fbb7b 22815
922fbb7b 22816
a2c02241
NR
22817@subheading The @code{-file-symbol-file} Command
22818@findex -file-symbol-file
922fbb7b 22819
a2c02241 22820@subsubheading Synopsis
922fbb7b 22821
a2c02241
NR
22822@smallexample
22823 -file-symbol-file @var{file}
22824@end smallexample
922fbb7b 22825
a2c02241
NR
22826Read symbol table info from the specified @var{file} argument. When
22827used without arguments, clears @value{GDBN}'s symbol table info. No output is
22828produced, except for a completion notification.
922fbb7b 22829
a2c02241 22830@subsubheading @value{GDBN} Command
922fbb7b 22831
a2c02241 22832The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 22833
a2c02241 22834@subsubheading Example
922fbb7b 22835
a2c02241 22836@smallexample
594fe323 22837(gdb)
a2c02241
NR
22838-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
22839^done
594fe323 22840(gdb)
a2c02241 22841@end smallexample
922fbb7b 22842
a2c02241 22843@ignore
a2c02241
NR
22844@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22845@node GDB/MI Memory Overlay Commands
22846@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 22847
a2c02241 22848The memory overlay commands are not implemented.
922fbb7b 22849
a2c02241 22850@c @subheading -overlay-auto
922fbb7b 22851
a2c02241 22852@c @subheading -overlay-list-mapping-state
922fbb7b 22853
a2c02241 22854@c @subheading -overlay-list-overlays
922fbb7b 22855
a2c02241 22856@c @subheading -overlay-map
922fbb7b 22857
a2c02241 22858@c @subheading -overlay-off
922fbb7b 22859
a2c02241 22860@c @subheading -overlay-on
922fbb7b 22861
a2c02241 22862@c @subheading -overlay-unmap
922fbb7b 22863
a2c02241
NR
22864@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22865@node GDB/MI Signal Handling Commands
22866@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 22867
a2c02241 22868Signal handling commands are not implemented.
922fbb7b 22869
a2c02241 22870@c @subheading -signal-handle
922fbb7b 22871
a2c02241 22872@c @subheading -signal-list-handle-actions
922fbb7b 22873
a2c02241
NR
22874@c @subheading -signal-list-signal-types
22875@end ignore
922fbb7b 22876
922fbb7b 22877
a2c02241
NR
22878@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22879@node GDB/MI Target Manipulation
22880@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
22881
22882
a2c02241
NR
22883@subheading The @code{-target-attach} Command
22884@findex -target-attach
922fbb7b
AC
22885
22886@subsubheading Synopsis
22887
22888@smallexample
c3b108f7 22889 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
22890@end smallexample
22891
c3b108f7
VP
22892Attach to a process @var{pid} or a file @var{file} outside of
22893@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
22894group, the id previously returned by
22895@samp{-list-thread-groups --available} must be used.
922fbb7b 22896
79a6e687 22897@subsubheading @value{GDBN} Command
922fbb7b 22898
a2c02241 22899The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 22900
a2c02241 22901@subsubheading Example
b56e7235
VP
22902@smallexample
22903(gdb)
22904-target-attach 34
22905=thread-created,id="1"
5ae4183a 22906*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
22907^done
22908(gdb)
22909@end smallexample
a2c02241
NR
22910
22911@subheading The @code{-target-compare-sections} Command
22912@findex -target-compare-sections
922fbb7b
AC
22913
22914@subsubheading Synopsis
22915
22916@smallexample
a2c02241 22917 -target-compare-sections [ @var{section} ]
922fbb7b
AC
22918@end smallexample
22919
a2c02241
NR
22920Compare data of section @var{section} on target to the exec file.
22921Without the argument, all sections are compared.
922fbb7b 22922
a2c02241 22923@subsubheading @value{GDBN} Command
922fbb7b 22924
a2c02241 22925The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 22926
a2c02241
NR
22927@subsubheading Example
22928N.A.
22929
22930
22931@subheading The @code{-target-detach} Command
22932@findex -target-detach
922fbb7b
AC
22933
22934@subsubheading Synopsis
22935
22936@smallexample
c3b108f7 22937 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
22938@end smallexample
22939
a2c02241 22940Detach from the remote target which normally resumes its execution.
c3b108f7
VP
22941If either @var{pid} or @var{gid} is specified, detaches from either
22942the specified process, or specified thread group. There's no output.
a2c02241 22943
79a6e687 22944@subsubheading @value{GDBN} Command
a2c02241
NR
22945
22946The corresponding @value{GDBN} command is @samp{detach}.
22947
22948@subsubheading Example
922fbb7b
AC
22949
22950@smallexample
594fe323 22951(gdb)
a2c02241
NR
22952-target-detach
22953^done
594fe323 22954(gdb)
922fbb7b
AC
22955@end smallexample
22956
22957
a2c02241
NR
22958@subheading The @code{-target-disconnect} Command
22959@findex -target-disconnect
922fbb7b
AC
22960
22961@subsubheading Synopsis
22962
123dc839 22963@smallexample
a2c02241 22964 -target-disconnect
123dc839 22965@end smallexample
922fbb7b 22966
a2c02241
NR
22967Disconnect from the remote target. There's no output and the target is
22968generally not resumed.
22969
79a6e687 22970@subsubheading @value{GDBN} Command
a2c02241
NR
22971
22972The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
22973
22974@subsubheading Example
922fbb7b
AC
22975
22976@smallexample
594fe323 22977(gdb)
a2c02241
NR
22978-target-disconnect
22979^done
594fe323 22980(gdb)
922fbb7b
AC
22981@end smallexample
22982
22983
a2c02241
NR
22984@subheading The @code{-target-download} Command
22985@findex -target-download
922fbb7b
AC
22986
22987@subsubheading Synopsis
22988
22989@smallexample
a2c02241 22990 -target-download
922fbb7b
AC
22991@end smallexample
22992
a2c02241
NR
22993Loads the executable onto the remote target.
22994It prints out an update message every half second, which includes the fields:
22995
22996@table @samp
22997@item section
22998The name of the section.
22999@item section-sent
23000The size of what has been sent so far for that section.
23001@item section-size
23002The size of the section.
23003@item total-sent
23004The total size of what was sent so far (the current and the previous sections).
23005@item total-size
23006The size of the overall executable to download.
23007@end table
23008
23009@noindent
23010Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
23011@sc{gdb/mi} Output Syntax}).
23012
23013In addition, it prints the name and size of the sections, as they are
23014downloaded. These messages include the following fields:
23015
23016@table @samp
23017@item section
23018The name of the section.
23019@item section-size
23020The size of the section.
23021@item total-size
23022The size of the overall executable to download.
23023@end table
23024
23025@noindent
23026At the end, a summary is printed.
23027
23028@subsubheading @value{GDBN} Command
23029
23030The corresponding @value{GDBN} command is @samp{load}.
23031
23032@subsubheading Example
23033
23034Note: each status message appears on a single line. Here the messages
23035have been broken down so that they can fit onto a page.
922fbb7b
AC
23036
23037@smallexample
594fe323 23038(gdb)
a2c02241
NR
23039-target-download
23040+download,@{section=".text",section-size="6668",total-size="9880"@}
23041+download,@{section=".text",section-sent="512",section-size="6668",
23042total-sent="512",total-size="9880"@}
23043+download,@{section=".text",section-sent="1024",section-size="6668",
23044total-sent="1024",total-size="9880"@}
23045+download,@{section=".text",section-sent="1536",section-size="6668",
23046total-sent="1536",total-size="9880"@}
23047+download,@{section=".text",section-sent="2048",section-size="6668",
23048total-sent="2048",total-size="9880"@}
23049+download,@{section=".text",section-sent="2560",section-size="6668",
23050total-sent="2560",total-size="9880"@}
23051+download,@{section=".text",section-sent="3072",section-size="6668",
23052total-sent="3072",total-size="9880"@}
23053+download,@{section=".text",section-sent="3584",section-size="6668",
23054total-sent="3584",total-size="9880"@}
23055+download,@{section=".text",section-sent="4096",section-size="6668",
23056total-sent="4096",total-size="9880"@}
23057+download,@{section=".text",section-sent="4608",section-size="6668",
23058total-sent="4608",total-size="9880"@}
23059+download,@{section=".text",section-sent="5120",section-size="6668",
23060total-sent="5120",total-size="9880"@}
23061+download,@{section=".text",section-sent="5632",section-size="6668",
23062total-sent="5632",total-size="9880"@}
23063+download,@{section=".text",section-sent="6144",section-size="6668",
23064total-sent="6144",total-size="9880"@}
23065+download,@{section=".text",section-sent="6656",section-size="6668",
23066total-sent="6656",total-size="9880"@}
23067+download,@{section=".init",section-size="28",total-size="9880"@}
23068+download,@{section=".fini",section-size="28",total-size="9880"@}
23069+download,@{section=".data",section-size="3156",total-size="9880"@}
23070+download,@{section=".data",section-sent="512",section-size="3156",
23071total-sent="7236",total-size="9880"@}
23072+download,@{section=".data",section-sent="1024",section-size="3156",
23073total-sent="7748",total-size="9880"@}
23074+download,@{section=".data",section-sent="1536",section-size="3156",
23075total-sent="8260",total-size="9880"@}
23076+download,@{section=".data",section-sent="2048",section-size="3156",
23077total-sent="8772",total-size="9880"@}
23078+download,@{section=".data",section-sent="2560",section-size="3156",
23079total-sent="9284",total-size="9880"@}
23080+download,@{section=".data",section-sent="3072",section-size="3156",
23081total-sent="9796",total-size="9880"@}
23082^done,address="0x10004",load-size="9880",transfer-rate="6586",
23083write-rate="429"
594fe323 23084(gdb)
922fbb7b
AC
23085@end smallexample
23086
23087
a2c02241
NR
23088@subheading The @code{-target-exec-status} Command
23089@findex -target-exec-status
922fbb7b
AC
23090
23091@subsubheading Synopsis
23092
23093@smallexample
a2c02241 23094 -target-exec-status
922fbb7b
AC
23095@end smallexample
23096
a2c02241
NR
23097Provide information on the state of the target (whether it is running or
23098not, for instance).
922fbb7b 23099
a2c02241 23100@subsubheading @value{GDBN} Command
922fbb7b 23101
a2c02241
NR
23102There's no equivalent @value{GDBN} command.
23103
23104@subsubheading Example
23105N.A.
922fbb7b 23106
a2c02241
NR
23107
23108@subheading The @code{-target-list-available-targets} Command
23109@findex -target-list-available-targets
922fbb7b
AC
23110
23111@subsubheading Synopsis
23112
23113@smallexample
a2c02241 23114 -target-list-available-targets
922fbb7b
AC
23115@end smallexample
23116
a2c02241 23117List the possible targets to connect to.
922fbb7b 23118
a2c02241 23119@subsubheading @value{GDBN} Command
922fbb7b 23120
a2c02241 23121The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 23122
a2c02241
NR
23123@subsubheading Example
23124N.A.
23125
23126
23127@subheading The @code{-target-list-current-targets} Command
23128@findex -target-list-current-targets
922fbb7b
AC
23129
23130@subsubheading Synopsis
23131
23132@smallexample
a2c02241 23133 -target-list-current-targets
922fbb7b
AC
23134@end smallexample
23135
a2c02241 23136Describe the current target.
922fbb7b 23137
a2c02241 23138@subsubheading @value{GDBN} Command
922fbb7b 23139
a2c02241
NR
23140The corresponding information is printed by @samp{info file} (among
23141other things).
922fbb7b 23142
a2c02241
NR
23143@subsubheading Example
23144N.A.
23145
23146
23147@subheading The @code{-target-list-parameters} Command
23148@findex -target-list-parameters
922fbb7b
AC
23149
23150@subsubheading Synopsis
23151
23152@smallexample
a2c02241 23153 -target-list-parameters
922fbb7b
AC
23154@end smallexample
23155
a2c02241
NR
23156@c ????
23157
23158@subsubheading @value{GDBN} Command
23159
23160No equivalent.
922fbb7b
AC
23161
23162@subsubheading Example
a2c02241
NR
23163N.A.
23164
23165
23166@subheading The @code{-target-select} Command
23167@findex -target-select
23168
23169@subsubheading Synopsis
922fbb7b
AC
23170
23171@smallexample
a2c02241 23172 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
23173@end smallexample
23174
a2c02241 23175Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 23176
a2c02241
NR
23177@table @samp
23178@item @var{type}
75c99385 23179The type of target, for instance @samp{remote}, etc.
a2c02241
NR
23180@item @var{parameters}
23181Device names, host names and the like. @xref{Target Commands, ,
79a6e687 23182Commands for Managing Targets}, for more details.
a2c02241
NR
23183@end table
23184
23185The output is a connection notification, followed by the address at
23186which the target program is, in the following form:
922fbb7b
AC
23187
23188@smallexample
a2c02241
NR
23189^connected,addr="@var{address}",func="@var{function name}",
23190 args=[@var{arg list}]
922fbb7b
AC
23191@end smallexample
23192
a2c02241
NR
23193@subsubheading @value{GDBN} Command
23194
23195The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
23196
23197@subsubheading Example
922fbb7b 23198
265eeb58 23199@smallexample
594fe323 23200(gdb)
75c99385 23201-target-select remote /dev/ttya
a2c02241 23202^connected,addr="0xfe00a300",func="??",args=[]
594fe323 23203(gdb)
265eeb58 23204@end smallexample
ef21caaf 23205
a6b151f1
DJ
23206@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23207@node GDB/MI File Transfer Commands
23208@section @sc{gdb/mi} File Transfer Commands
23209
23210
23211@subheading The @code{-target-file-put} Command
23212@findex -target-file-put
23213
23214@subsubheading Synopsis
23215
23216@smallexample
23217 -target-file-put @var{hostfile} @var{targetfile}
23218@end smallexample
23219
23220Copy file @var{hostfile} from the host system (the machine running
23221@value{GDBN}) to @var{targetfile} on the target system.
23222
23223@subsubheading @value{GDBN} Command
23224
23225The corresponding @value{GDBN} command is @samp{remote put}.
23226
23227@subsubheading Example
23228
23229@smallexample
23230(gdb)
23231-target-file-put localfile remotefile
23232^done
23233(gdb)
23234@end smallexample
23235
23236
1763a388 23237@subheading The @code{-target-file-get} Command
a6b151f1
DJ
23238@findex -target-file-get
23239
23240@subsubheading Synopsis
23241
23242@smallexample
23243 -target-file-get @var{targetfile} @var{hostfile}
23244@end smallexample
23245
23246Copy file @var{targetfile} from the target system to @var{hostfile}
23247on the host system.
23248
23249@subsubheading @value{GDBN} Command
23250
23251The corresponding @value{GDBN} command is @samp{remote get}.
23252
23253@subsubheading Example
23254
23255@smallexample
23256(gdb)
23257-target-file-get remotefile localfile
23258^done
23259(gdb)
23260@end smallexample
23261
23262
23263@subheading The @code{-target-file-delete} Command
23264@findex -target-file-delete
23265
23266@subsubheading Synopsis
23267
23268@smallexample
23269 -target-file-delete @var{targetfile}
23270@end smallexample
23271
23272Delete @var{targetfile} from the target system.
23273
23274@subsubheading @value{GDBN} Command
23275
23276The corresponding @value{GDBN} command is @samp{remote delete}.
23277
23278@subsubheading Example
23279
23280@smallexample
23281(gdb)
23282-target-file-delete remotefile
23283^done
23284(gdb)
23285@end smallexample
23286
23287
ef21caaf
NR
23288@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23289@node GDB/MI Miscellaneous Commands
23290@section Miscellaneous @sc{gdb/mi} Commands
23291
23292@c @subheading -gdb-complete
23293
23294@subheading The @code{-gdb-exit} Command
23295@findex -gdb-exit
23296
23297@subsubheading Synopsis
23298
23299@smallexample
23300 -gdb-exit
23301@end smallexample
23302
23303Exit @value{GDBN} immediately.
23304
23305@subsubheading @value{GDBN} Command
23306
23307Approximately corresponds to @samp{quit}.
23308
23309@subsubheading Example
23310
23311@smallexample
594fe323 23312(gdb)
ef21caaf
NR
23313-gdb-exit
23314^exit
23315@end smallexample
23316
a2c02241
NR
23317
23318@subheading The @code{-exec-abort} Command
23319@findex -exec-abort
23320
23321@subsubheading Synopsis
23322
23323@smallexample
23324 -exec-abort
23325@end smallexample
23326
23327Kill the inferior running program.
23328
23329@subsubheading @value{GDBN} Command
23330
23331The corresponding @value{GDBN} command is @samp{kill}.
23332
23333@subsubheading Example
23334N.A.
23335
23336
ef21caaf
NR
23337@subheading The @code{-gdb-set} Command
23338@findex -gdb-set
23339
23340@subsubheading Synopsis
23341
23342@smallexample
23343 -gdb-set
23344@end smallexample
23345
23346Set an internal @value{GDBN} variable.
23347@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
23348
23349@subsubheading @value{GDBN} Command
23350
23351The corresponding @value{GDBN} command is @samp{set}.
23352
23353@subsubheading Example
23354
23355@smallexample
594fe323 23356(gdb)
ef21caaf
NR
23357-gdb-set $foo=3
23358^done
594fe323 23359(gdb)
ef21caaf
NR
23360@end smallexample
23361
23362
23363@subheading The @code{-gdb-show} Command
23364@findex -gdb-show
23365
23366@subsubheading Synopsis
23367
23368@smallexample
23369 -gdb-show
23370@end smallexample
23371
23372Show the current value of a @value{GDBN} variable.
23373
79a6e687 23374@subsubheading @value{GDBN} Command
ef21caaf
NR
23375
23376The corresponding @value{GDBN} command is @samp{show}.
23377
23378@subsubheading Example
23379
23380@smallexample
594fe323 23381(gdb)
ef21caaf
NR
23382-gdb-show annotate
23383^done,value="0"
594fe323 23384(gdb)
ef21caaf
NR
23385@end smallexample
23386
23387@c @subheading -gdb-source
23388
23389
23390@subheading The @code{-gdb-version} Command
23391@findex -gdb-version
23392
23393@subsubheading Synopsis
23394
23395@smallexample
23396 -gdb-version
23397@end smallexample
23398
23399Show version information for @value{GDBN}. Used mostly in testing.
23400
23401@subsubheading @value{GDBN} Command
23402
23403The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
23404default shows this information when you start an interactive session.
23405
23406@subsubheading Example
23407
23408@c This example modifies the actual output from GDB to avoid overfull
23409@c box in TeX.
23410@smallexample
594fe323 23411(gdb)
ef21caaf
NR
23412-gdb-version
23413~GNU gdb 5.2.1
23414~Copyright 2000 Free Software Foundation, Inc.
23415~GDB is free software, covered by the GNU General Public License, and
23416~you are welcome to change it and/or distribute copies of it under
23417~ certain conditions.
23418~Type "show copying" to see the conditions.
23419~There is absolutely no warranty for GDB. Type "show warranty" for
23420~ details.
23421~This GDB was configured as
23422 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
23423^done
594fe323 23424(gdb)
ef21caaf
NR
23425@end smallexample
23426
084344da
VP
23427@subheading The @code{-list-features} Command
23428@findex -list-features
23429
23430Returns a list of particular features of the MI protocol that
23431this version of gdb implements. A feature can be a command,
23432or a new field in an output of some command, or even an
23433important bugfix. While a frontend can sometimes detect presence
23434of a feature at runtime, it is easier to perform detection at debugger
23435startup.
23436
23437The command returns a list of strings, with each string naming an
23438available feature. Each returned string is just a name, it does not
23439have any internal structure. The list of possible feature names
23440is given below.
23441
23442Example output:
23443
23444@smallexample
23445(gdb) -list-features
23446^done,result=["feature1","feature2"]
23447@end smallexample
23448
23449The current list of features is:
23450
30e026bb
VP
23451@table @samp
23452@item frozen-varobjs
23453Indicates presence of the @code{-var-set-frozen} command, as well
23454as possible presense of the @code{frozen} field in the output
23455of @code{-varobj-create}.
23456@item pending-breakpoints
23457Indicates presence of the @option{-f} option to the @code{-break-insert} command.
23458@item thread-info
23459Indicates presence of the @code{-thread-info} command.
8b4ed427 23460
30e026bb 23461@end table
084344da 23462
c6ebd6cf
VP
23463@subheading The @code{-list-target-features} Command
23464@findex -list-target-features
23465
23466Returns a list of particular features that are supported by the
23467target. Those features affect the permitted MI commands, but
23468unlike the features reported by the @code{-list-features} command, the
23469features depend on which target GDB is using at the moment. Whenever
23470a target can change, due to commands such as @code{-target-select},
23471@code{-target-attach} or @code{-exec-run}, the list of target features
23472may change, and the frontend should obtain it again.
23473Example output:
23474
23475@smallexample
23476(gdb) -list-features
23477^done,result=["async"]
23478@end smallexample
23479
23480The current list of features is:
23481
23482@table @samp
23483@item async
23484Indicates that the target is capable of asynchronous command
23485execution, which means that @value{GDBN} will accept further commands
23486while the target is running.
23487
23488@end table
23489
c3b108f7
VP
23490@subheading The @code{-list-thread-groups} Command
23491@findex -list-thread-groups
23492
23493@subheading Synopsis
23494
23495@smallexample
23496-list-thread-groups [ --available ] [ @var{group} ]
23497@end smallexample
23498
23499When used without the @var{group} parameter, lists top-level thread
23500groups that are being debugged. When used with the @var{group}
23501parameter, the children of the specified group are listed. The
23502children can be either threads, or other groups. At present,
23503@value{GDBN} will not report both threads and groups as children at
23504the same time, but it may change in future.
23505
23506With the @samp{--available} option, instead of reporting groups that
23507are been debugged, GDB will report all thread groups available on the
23508target. Using the @samp{--available} option together with @var{group}
23509is not allowed.
23510
23511@subheading Example
23512
23513@smallexample
23514@value{GDBP}
23515-list-thread-groups
23516^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
23517-list-thread-groups 17
23518^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
23519 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
23520@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
23521 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
23522 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
23523@end smallexample
c6ebd6cf 23524
ef21caaf
NR
23525@subheading The @code{-interpreter-exec} Command
23526@findex -interpreter-exec
23527
23528@subheading Synopsis
23529
23530@smallexample
23531-interpreter-exec @var{interpreter} @var{command}
23532@end smallexample
a2c02241 23533@anchor{-interpreter-exec}
ef21caaf
NR
23534
23535Execute the specified @var{command} in the given @var{interpreter}.
23536
23537@subheading @value{GDBN} Command
23538
23539The corresponding @value{GDBN} command is @samp{interpreter-exec}.
23540
23541@subheading Example
23542
23543@smallexample
594fe323 23544(gdb)
ef21caaf
NR
23545-interpreter-exec console "break main"
23546&"During symbol reading, couldn't parse type; debugger out of date?.\n"
23547&"During symbol reading, bad structure-type format.\n"
23548~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
23549^done
594fe323 23550(gdb)
ef21caaf
NR
23551@end smallexample
23552
23553@subheading The @code{-inferior-tty-set} Command
23554@findex -inferior-tty-set
23555
23556@subheading Synopsis
23557
23558@smallexample
23559-inferior-tty-set /dev/pts/1
23560@end smallexample
23561
23562Set terminal for future runs of the program being debugged.
23563
23564@subheading @value{GDBN} Command
23565
23566The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
23567
23568@subheading Example
23569
23570@smallexample
594fe323 23571(gdb)
ef21caaf
NR
23572-inferior-tty-set /dev/pts/1
23573^done
594fe323 23574(gdb)
ef21caaf
NR
23575@end smallexample
23576
23577@subheading The @code{-inferior-tty-show} Command
23578@findex -inferior-tty-show
23579
23580@subheading Synopsis
23581
23582@smallexample
23583-inferior-tty-show
23584@end smallexample
23585
23586Show terminal for future runs of program being debugged.
23587
23588@subheading @value{GDBN} Command
23589
23590The corresponding @value{GDBN} command is @samp{show inferior-tty}.
23591
23592@subheading Example
23593
23594@smallexample
594fe323 23595(gdb)
ef21caaf
NR
23596-inferior-tty-set /dev/pts/1
23597^done
594fe323 23598(gdb)
ef21caaf
NR
23599-inferior-tty-show
23600^done,inferior_tty_terminal="/dev/pts/1"
594fe323 23601(gdb)
ef21caaf 23602@end smallexample
922fbb7b 23603
a4eefcd8
NR
23604@subheading The @code{-enable-timings} Command
23605@findex -enable-timings
23606
23607@subheading Synopsis
23608
23609@smallexample
23610-enable-timings [yes | no]
23611@end smallexample
23612
23613Toggle the printing of the wallclock, user and system times for an MI
23614command as a field in its output. This command is to help frontend
23615developers optimize the performance of their code. No argument is
23616equivalent to @samp{yes}.
23617
23618@subheading @value{GDBN} Command
23619
23620No equivalent.
23621
23622@subheading Example
23623
23624@smallexample
23625(gdb)
23626-enable-timings
23627^done
23628(gdb)
23629-break-insert main
23630^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
23631addr="0x080484ed",func="main",file="myprog.c",
23632fullname="/home/nickrob/myprog.c",line="73",times="0"@},
23633time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
23634(gdb)
23635-enable-timings no
23636^done
23637(gdb)
23638-exec-run
23639^running
23640(gdb)
a47ec5fe 23641*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
23642frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
23643@{name="argv",value="0xbfb60364"@}],file="myprog.c",
23644fullname="/home/nickrob/myprog.c",line="73"@}
23645(gdb)
23646@end smallexample
23647
922fbb7b
AC
23648@node Annotations
23649@chapter @value{GDBN} Annotations
23650
086432e2
AC
23651This chapter describes annotations in @value{GDBN}. Annotations were
23652designed to interface @value{GDBN} to graphical user interfaces or other
23653similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
23654relatively high level.
23655
d3e8051b 23656The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
23657(@pxref{GDB/MI}).
23658
922fbb7b
AC
23659@ignore
23660This is Edition @value{EDITION}, @value{DATE}.
23661@end ignore
23662
23663@menu
23664* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 23665* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
23666* Prompting:: Annotations marking @value{GDBN}'s need for input.
23667* Errors:: Annotations for error messages.
922fbb7b
AC
23668* Invalidation:: Some annotations describe things now invalid.
23669* Annotations for Running::
23670 Whether the program is running, how it stopped, etc.
23671* Source Annotations:: Annotations describing source code.
922fbb7b
AC
23672@end menu
23673
23674@node Annotations Overview
23675@section What is an Annotation?
23676@cindex annotations
23677
922fbb7b
AC
23678Annotations start with a newline character, two @samp{control-z}
23679characters, and the name of the annotation. If there is no additional
23680information associated with this annotation, the name of the annotation
23681is followed immediately by a newline. If there is additional
23682information, the name of the annotation is followed by a space, the
23683additional information, and a newline. The additional information
23684cannot contain newline characters.
23685
23686Any output not beginning with a newline and two @samp{control-z}
23687characters denotes literal output from @value{GDBN}. Currently there is
23688no need for @value{GDBN} to output a newline followed by two
23689@samp{control-z} characters, but if there was such a need, the
23690annotations could be extended with an @samp{escape} annotation which
23691means those three characters as output.
23692
086432e2
AC
23693The annotation @var{level}, which is specified using the
23694@option{--annotate} command line option (@pxref{Mode Options}), controls
23695how much information @value{GDBN} prints together with its prompt,
23696values of expressions, source lines, and other types of output. Level 0
d3e8051b 23697is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
23698subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
23699for programs that control @value{GDBN}, and level 2 annotations have
23700been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
23701Interface, annotate, GDB's Obsolete Annotations}).
23702
23703@table @code
23704@kindex set annotate
23705@item set annotate @var{level}
e09f16f9 23706The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 23707annotations to the specified @var{level}.
9c16f35a
EZ
23708
23709@item show annotate
23710@kindex show annotate
23711Show the current annotation level.
09d4efe1
EZ
23712@end table
23713
23714This chapter describes level 3 annotations.
086432e2 23715
922fbb7b
AC
23716A simple example of starting up @value{GDBN} with annotations is:
23717
23718@smallexample
086432e2
AC
23719$ @kbd{gdb --annotate=3}
23720GNU gdb 6.0
23721Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
23722GDB is free software, covered by the GNU General Public License,
23723and you are welcome to change it and/or distribute copies of it
23724under certain conditions.
23725Type "show copying" to see the conditions.
23726There is absolutely no warranty for GDB. Type "show warranty"
23727for details.
086432e2 23728This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
23729
23730^Z^Zpre-prompt
f7dc1244 23731(@value{GDBP})
922fbb7b 23732^Z^Zprompt
086432e2 23733@kbd{quit}
922fbb7b
AC
23734
23735^Z^Zpost-prompt
b383017d 23736$
922fbb7b
AC
23737@end smallexample
23738
23739Here @samp{quit} is input to @value{GDBN}; the rest is output from
23740@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
23741denotes a @samp{control-z} character) are annotations; the rest is
23742output from @value{GDBN}.
23743
9e6c4bd5
NR
23744@node Server Prefix
23745@section The Server Prefix
23746@cindex server prefix
23747
23748If you prefix a command with @samp{server } then it will not affect
23749the command history, nor will it affect @value{GDBN}'s notion of which
23750command to repeat if @key{RET} is pressed on a line by itself. This
23751means that commands can be run behind a user's back by a front-end in
23752a transparent manner.
23753
23754The server prefix does not affect the recording of values into the value
23755history; to print a value without recording it into the value history,
23756use the @code{output} command instead of the @code{print} command.
23757
922fbb7b
AC
23758@node Prompting
23759@section Annotation for @value{GDBN} Input
23760
23761@cindex annotations for prompts
23762When @value{GDBN} prompts for input, it annotates this fact so it is possible
23763to know when to send output, when the output from a given command is
23764over, etc.
23765
23766Different kinds of input each have a different @dfn{input type}. Each
23767input type has three annotations: a @code{pre-} annotation, which
23768denotes the beginning of any prompt which is being output, a plain
23769annotation, which denotes the end of the prompt, and then a @code{post-}
23770annotation which denotes the end of any echo which may (or may not) be
23771associated with the input. For example, the @code{prompt} input type
23772features the following annotations:
23773
23774@smallexample
23775^Z^Zpre-prompt
23776^Z^Zprompt
23777^Z^Zpost-prompt
23778@end smallexample
23779
23780The input types are
23781
23782@table @code
e5ac9b53
EZ
23783@findex pre-prompt annotation
23784@findex prompt annotation
23785@findex post-prompt annotation
922fbb7b
AC
23786@item prompt
23787When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
23788
e5ac9b53
EZ
23789@findex pre-commands annotation
23790@findex commands annotation
23791@findex post-commands annotation
922fbb7b
AC
23792@item commands
23793When @value{GDBN} prompts for a set of commands, like in the @code{commands}
23794command. The annotations are repeated for each command which is input.
23795
e5ac9b53
EZ
23796@findex pre-overload-choice annotation
23797@findex overload-choice annotation
23798@findex post-overload-choice annotation
922fbb7b
AC
23799@item overload-choice
23800When @value{GDBN} wants the user to select between various overloaded functions.
23801
e5ac9b53
EZ
23802@findex pre-query annotation
23803@findex query annotation
23804@findex post-query annotation
922fbb7b
AC
23805@item query
23806When @value{GDBN} wants the user to confirm a potentially dangerous operation.
23807
e5ac9b53
EZ
23808@findex pre-prompt-for-continue annotation
23809@findex prompt-for-continue annotation
23810@findex post-prompt-for-continue annotation
922fbb7b
AC
23811@item prompt-for-continue
23812When @value{GDBN} is asking the user to press return to continue. Note: Don't
23813expect this to work well; instead use @code{set height 0} to disable
23814prompting. This is because the counting of lines is buggy in the
23815presence of annotations.
23816@end table
23817
23818@node Errors
23819@section Errors
23820@cindex annotations for errors, warnings and interrupts
23821
e5ac9b53 23822@findex quit annotation
922fbb7b
AC
23823@smallexample
23824^Z^Zquit
23825@end smallexample
23826
23827This annotation occurs right before @value{GDBN} responds to an interrupt.
23828
e5ac9b53 23829@findex error annotation
922fbb7b
AC
23830@smallexample
23831^Z^Zerror
23832@end smallexample
23833
23834This annotation occurs right before @value{GDBN} responds to an error.
23835
23836Quit and error annotations indicate that any annotations which @value{GDBN} was
23837in the middle of may end abruptly. For example, if a
23838@code{value-history-begin} annotation is followed by a @code{error}, one
23839cannot expect to receive the matching @code{value-history-end}. One
23840cannot expect not to receive it either, however; an error annotation
23841does not necessarily mean that @value{GDBN} is immediately returning all the way
23842to the top level.
23843
e5ac9b53 23844@findex error-begin annotation
922fbb7b
AC
23845A quit or error annotation may be preceded by
23846
23847@smallexample
23848^Z^Zerror-begin
23849@end smallexample
23850
23851Any output between that and the quit or error annotation is the error
23852message.
23853
23854Warning messages are not yet annotated.
23855@c If we want to change that, need to fix warning(), type_error(),
23856@c range_error(), and possibly other places.
23857
922fbb7b
AC
23858@node Invalidation
23859@section Invalidation Notices
23860
23861@cindex annotations for invalidation messages
23862The following annotations say that certain pieces of state may have
23863changed.
23864
23865@table @code
e5ac9b53 23866@findex frames-invalid annotation
922fbb7b
AC
23867@item ^Z^Zframes-invalid
23868
23869The frames (for example, output from the @code{backtrace} command) may
23870have changed.
23871
e5ac9b53 23872@findex breakpoints-invalid annotation
922fbb7b
AC
23873@item ^Z^Zbreakpoints-invalid
23874
23875The breakpoints may have changed. For example, the user just added or
23876deleted a breakpoint.
23877@end table
23878
23879@node Annotations for Running
23880@section Running the Program
23881@cindex annotations for running programs
23882
e5ac9b53
EZ
23883@findex starting annotation
23884@findex stopping annotation
922fbb7b 23885When the program starts executing due to a @value{GDBN} command such as
b383017d 23886@code{step} or @code{continue},
922fbb7b
AC
23887
23888@smallexample
23889^Z^Zstarting
23890@end smallexample
23891
b383017d 23892is output. When the program stops,
922fbb7b
AC
23893
23894@smallexample
23895^Z^Zstopped
23896@end smallexample
23897
23898is output. Before the @code{stopped} annotation, a variety of
23899annotations describe how the program stopped.
23900
23901@table @code
e5ac9b53 23902@findex exited annotation
922fbb7b
AC
23903@item ^Z^Zexited @var{exit-status}
23904The program exited, and @var{exit-status} is the exit status (zero for
23905successful exit, otherwise nonzero).
23906
e5ac9b53
EZ
23907@findex signalled annotation
23908@findex signal-name annotation
23909@findex signal-name-end annotation
23910@findex signal-string annotation
23911@findex signal-string-end annotation
922fbb7b
AC
23912@item ^Z^Zsignalled
23913The program exited with a signal. After the @code{^Z^Zsignalled}, the
23914annotation continues:
23915
23916@smallexample
23917@var{intro-text}
23918^Z^Zsignal-name
23919@var{name}
23920^Z^Zsignal-name-end
23921@var{middle-text}
23922^Z^Zsignal-string
23923@var{string}
23924^Z^Zsignal-string-end
23925@var{end-text}
23926@end smallexample
23927
23928@noindent
23929where @var{name} is the name of the signal, such as @code{SIGILL} or
23930@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
23931as @code{Illegal Instruction} or @code{Segmentation fault}.
23932@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
23933user's benefit and have no particular format.
23934
e5ac9b53 23935@findex signal annotation
922fbb7b
AC
23936@item ^Z^Zsignal
23937The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
23938just saying that the program received the signal, not that it was
23939terminated with it.
23940
e5ac9b53 23941@findex breakpoint annotation
922fbb7b
AC
23942@item ^Z^Zbreakpoint @var{number}
23943The program hit breakpoint number @var{number}.
23944
e5ac9b53 23945@findex watchpoint annotation
922fbb7b
AC
23946@item ^Z^Zwatchpoint @var{number}
23947The program hit watchpoint number @var{number}.
23948@end table
23949
23950@node Source Annotations
23951@section Displaying Source
23952@cindex annotations for source display
23953
e5ac9b53 23954@findex source annotation
922fbb7b
AC
23955The following annotation is used instead of displaying source code:
23956
23957@smallexample
23958^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
23959@end smallexample
23960
23961where @var{filename} is an absolute file name indicating which source
23962file, @var{line} is the line number within that file (where 1 is the
23963first line in the file), @var{character} is the character position
23964within the file (where 0 is the first character in the file) (for most
23965debug formats this will necessarily point to the beginning of a line),
23966@var{middle} is @samp{middle} if @var{addr} is in the middle of the
23967line, or @samp{beg} if @var{addr} is at the beginning of the line, and
23968@var{addr} is the address in the target program associated with the
23969source which is being displayed. @var{addr} is in the form @samp{0x}
23970followed by one or more lowercase hex digits (note that this does not
23971depend on the language).
23972
8e04817f
AC
23973@node GDB Bugs
23974@chapter Reporting Bugs in @value{GDBN}
23975@cindex bugs in @value{GDBN}
23976@cindex reporting bugs in @value{GDBN}
c906108c 23977
8e04817f 23978Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 23979
8e04817f
AC
23980Reporting a bug may help you by bringing a solution to your problem, or it
23981may not. But in any case the principal function of a bug report is to help
23982the entire community by making the next version of @value{GDBN} work better. Bug
23983reports are your contribution to the maintenance of @value{GDBN}.
c906108c 23984
8e04817f
AC
23985In order for a bug report to serve its purpose, you must include the
23986information that enables us to fix the bug.
c4555f82
SC
23987
23988@menu
8e04817f
AC
23989* Bug Criteria:: Have you found a bug?
23990* Bug Reporting:: How to report bugs
c4555f82
SC
23991@end menu
23992
8e04817f 23993@node Bug Criteria
79a6e687 23994@section Have You Found a Bug?
8e04817f 23995@cindex bug criteria
c4555f82 23996
8e04817f 23997If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
23998
23999@itemize @bullet
8e04817f
AC
24000@cindex fatal signal
24001@cindex debugger crash
24002@cindex crash of debugger
c4555f82 24003@item
8e04817f
AC
24004If the debugger gets a fatal signal, for any input whatever, that is a
24005@value{GDBN} bug. Reliable debuggers never crash.
24006
24007@cindex error on valid input
24008@item
24009If @value{GDBN} produces an error message for valid input, that is a
24010bug. (Note that if you're cross debugging, the problem may also be
24011somewhere in the connection to the target.)
c4555f82 24012
8e04817f 24013@cindex invalid input
c4555f82 24014@item
8e04817f
AC
24015If @value{GDBN} does not produce an error message for invalid input,
24016that is a bug. However, you should note that your idea of
24017``invalid input'' might be our idea of ``an extension'' or ``support
24018for traditional practice''.
24019
24020@item
24021If you are an experienced user of debugging tools, your suggestions
24022for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
24023@end itemize
24024
8e04817f 24025@node Bug Reporting
79a6e687 24026@section How to Report Bugs
8e04817f
AC
24027@cindex bug reports
24028@cindex @value{GDBN} bugs, reporting
24029
24030A number of companies and individuals offer support for @sc{gnu} products.
24031If you obtained @value{GDBN} from a support organization, we recommend you
24032contact that organization first.
24033
24034You can find contact information for many support companies and
24035individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
24036distribution.
24037@c should add a web page ref...
24038
c16158bc
JM
24039@ifset BUGURL
24040@ifset BUGURL_DEFAULT
129188f6 24041In any event, we also recommend that you submit bug reports for
d3e8051b 24042@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
24043@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
24044page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
24045be used.
8e04817f
AC
24046
24047@strong{Do not send bug reports to @samp{info-gdb}, or to
24048@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
24049not want to receive bug reports. Those that do have arranged to receive
24050@samp{bug-gdb}.
24051
24052The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
24053serves as a repeater. The mailing list and the newsgroup carry exactly
24054the same messages. Often people think of posting bug reports to the
24055newsgroup instead of mailing them. This appears to work, but it has one
24056problem which can be crucial: a newsgroup posting often lacks a mail
24057path back to the sender. Thus, if we need to ask for more information,
24058we may be unable to reach you. For this reason, it is better to send
24059bug reports to the mailing list.
c16158bc
JM
24060@end ifset
24061@ifclear BUGURL_DEFAULT
24062In any event, we also recommend that you submit bug reports for
24063@value{GDBN} to @value{BUGURL}.
24064@end ifclear
24065@end ifset
c4555f82 24066
8e04817f
AC
24067The fundamental principle of reporting bugs usefully is this:
24068@strong{report all the facts}. If you are not sure whether to state a
24069fact or leave it out, state it!
c4555f82 24070
8e04817f
AC
24071Often people omit facts because they think they know what causes the
24072problem and assume that some details do not matter. Thus, you might
24073assume that the name of the variable you use in an example does not matter.
24074Well, probably it does not, but one cannot be sure. Perhaps the bug is a
24075stray memory reference which happens to fetch from the location where that
24076name is stored in memory; perhaps, if the name were different, the contents
24077of that location would fool the debugger into doing the right thing despite
24078the bug. Play it safe and give a specific, complete example. That is the
24079easiest thing for you to do, and the most helpful.
c4555f82 24080
8e04817f
AC
24081Keep in mind that the purpose of a bug report is to enable us to fix the
24082bug. It may be that the bug has been reported previously, but neither
24083you nor we can know that unless your bug report is complete and
24084self-contained.
c4555f82 24085
8e04817f
AC
24086Sometimes people give a few sketchy facts and ask, ``Does this ring a
24087bell?'' Those bug reports are useless, and we urge everyone to
24088@emph{refuse to respond to them} except to chide the sender to report
24089bugs properly.
24090
24091To enable us to fix the bug, you should include all these things:
c4555f82
SC
24092
24093@itemize @bullet
24094@item
8e04817f
AC
24095The version of @value{GDBN}. @value{GDBN} announces it if you start
24096with no arguments; you can also print it at any time using @code{show
24097version}.
c4555f82 24098
8e04817f
AC
24099Without this, we will not know whether there is any point in looking for
24100the bug in the current version of @value{GDBN}.
c4555f82
SC
24101
24102@item
8e04817f
AC
24103The type of machine you are using, and the operating system name and
24104version number.
c4555f82
SC
24105
24106@item
c1468174 24107What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 24108``@value{GCC}--2.8.1''.
c4555f82
SC
24109
24110@item
8e04817f 24111What compiler (and its version) was used to compile the program you are
c1468174 24112debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
24113C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
24114to get this information; for other compilers, see the documentation for
24115those compilers.
c4555f82 24116
8e04817f
AC
24117@item
24118The command arguments you gave the compiler to compile your example and
24119observe the bug. For example, did you use @samp{-O}? To guarantee
24120you will not omit something important, list them all. A copy of the
24121Makefile (or the output from make) is sufficient.
c4555f82 24122
8e04817f
AC
24123If we were to try to guess the arguments, we would probably guess wrong
24124and then we might not encounter the bug.
c4555f82 24125
8e04817f
AC
24126@item
24127A complete input script, and all necessary source files, that will
24128reproduce the bug.
c4555f82 24129
8e04817f
AC
24130@item
24131A description of what behavior you observe that you believe is
24132incorrect. For example, ``It gets a fatal signal.''
c4555f82 24133
8e04817f
AC
24134Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
24135will certainly notice it. But if the bug is incorrect output, we might
24136not notice unless it is glaringly wrong. You might as well not give us
24137a chance to make a mistake.
c4555f82 24138
8e04817f
AC
24139Even if the problem you experience is a fatal signal, you should still
24140say so explicitly. Suppose something strange is going on, such as, your
24141copy of @value{GDBN} is out of synch, or you have encountered a bug in
24142the C library on your system. (This has happened!) Your copy might
24143crash and ours would not. If you told us to expect a crash, then when
24144ours fails to crash, we would know that the bug was not happening for
24145us. If you had not told us to expect a crash, then we would not be able
24146to draw any conclusion from our observations.
c4555f82 24147
e0c07bf0
MC
24148@pindex script
24149@cindex recording a session script
24150To collect all this information, you can use a session recording program
24151such as @command{script}, which is available on many Unix systems.
24152Just run your @value{GDBN} session inside @command{script} and then
24153include the @file{typescript} file with your bug report.
24154
24155Another way to record a @value{GDBN} session is to run @value{GDBN}
24156inside Emacs and then save the entire buffer to a file.
24157
8e04817f
AC
24158@item
24159If you wish to suggest changes to the @value{GDBN} source, send us context
24160diffs. If you even discuss something in the @value{GDBN} source, refer to
24161it by context, not by line number.
c4555f82 24162
8e04817f
AC
24163The line numbers in our development sources will not match those in your
24164sources. Your line numbers would convey no useful information to us.
c4555f82 24165
8e04817f 24166@end itemize
c4555f82 24167
8e04817f 24168Here are some things that are not necessary:
c4555f82 24169
8e04817f
AC
24170@itemize @bullet
24171@item
24172A description of the envelope of the bug.
c4555f82 24173
8e04817f
AC
24174Often people who encounter a bug spend a lot of time investigating
24175which changes to the input file will make the bug go away and which
24176changes will not affect it.
c4555f82 24177
8e04817f
AC
24178This is often time consuming and not very useful, because the way we
24179will find the bug is by running a single example under the debugger
24180with breakpoints, not by pure deduction from a series of examples.
24181We recommend that you save your time for something else.
c4555f82 24182
8e04817f
AC
24183Of course, if you can find a simpler example to report @emph{instead}
24184of the original one, that is a convenience for us. Errors in the
24185output will be easier to spot, running under the debugger will take
24186less time, and so on.
c4555f82 24187
8e04817f
AC
24188However, simplification is not vital; if you do not want to do this,
24189report the bug anyway and send us the entire test case you used.
c4555f82 24190
8e04817f
AC
24191@item
24192A patch for the bug.
c4555f82 24193
8e04817f
AC
24194A patch for the bug does help us if it is a good one. But do not omit
24195the necessary information, such as the test case, on the assumption that
24196a patch is all we need. We might see problems with your patch and decide
24197to fix the problem another way, or we might not understand it at all.
c4555f82 24198
8e04817f
AC
24199Sometimes with a program as complicated as @value{GDBN} it is very hard to
24200construct an example that will make the program follow a certain path
24201through the code. If you do not send us the example, we will not be able
24202to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 24203
8e04817f
AC
24204And if we cannot understand what bug you are trying to fix, or why your
24205patch should be an improvement, we will not install it. A test case will
24206help us to understand.
c4555f82 24207
8e04817f
AC
24208@item
24209A guess about what the bug is or what it depends on.
c4555f82 24210
8e04817f
AC
24211Such guesses are usually wrong. Even we cannot guess right about such
24212things without first using the debugger to find the facts.
24213@end itemize
c4555f82 24214
8e04817f
AC
24215@c The readline documentation is distributed with the readline code
24216@c and consists of the two following files:
24217@c rluser.texinfo
24218@c inc-hist.texinfo
24219@c Use -I with makeinfo to point to the appropriate directory,
24220@c environment var TEXINPUTS with TeX.
5bdf8622 24221@include rluser.texi
8e04817f 24222@include inc-hist.texinfo
c4555f82 24223
c4555f82 24224
8e04817f
AC
24225@node Formatting Documentation
24226@appendix Formatting Documentation
c4555f82 24227
8e04817f
AC
24228@cindex @value{GDBN} reference card
24229@cindex reference card
24230The @value{GDBN} 4 release includes an already-formatted reference card, ready
24231for printing with PostScript or Ghostscript, in the @file{gdb}
24232subdirectory of the main source directory@footnote{In
24233@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
24234release.}. If you can use PostScript or Ghostscript with your printer,
24235you can print the reference card immediately with @file{refcard.ps}.
c4555f82 24236
8e04817f
AC
24237The release also includes the source for the reference card. You
24238can format it, using @TeX{}, by typing:
c4555f82 24239
474c8240 24240@smallexample
8e04817f 24241make refcard.dvi
474c8240 24242@end smallexample
c4555f82 24243
8e04817f
AC
24244The @value{GDBN} reference card is designed to print in @dfn{landscape}
24245mode on US ``letter'' size paper;
24246that is, on a sheet 11 inches wide by 8.5 inches
24247high. You will need to specify this form of printing as an option to
24248your @sc{dvi} output program.
c4555f82 24249
8e04817f 24250@cindex documentation
c4555f82 24251
8e04817f
AC
24252All the documentation for @value{GDBN} comes as part of the machine-readable
24253distribution. The documentation is written in Texinfo format, which is
24254a documentation system that uses a single source file to produce both
24255on-line information and a printed manual. You can use one of the Info
24256formatting commands to create the on-line version of the documentation
24257and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 24258
8e04817f
AC
24259@value{GDBN} includes an already formatted copy of the on-line Info
24260version of this manual in the @file{gdb} subdirectory. The main Info
24261file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
24262subordinate files matching @samp{gdb.info*} in the same directory. If
24263necessary, you can print out these files, or read them with any editor;
24264but they are easier to read using the @code{info} subsystem in @sc{gnu}
24265Emacs or the standalone @code{info} program, available as part of the
24266@sc{gnu} Texinfo distribution.
c4555f82 24267
8e04817f
AC
24268If you want to format these Info files yourself, you need one of the
24269Info formatting programs, such as @code{texinfo-format-buffer} or
24270@code{makeinfo}.
c4555f82 24271
8e04817f
AC
24272If you have @code{makeinfo} installed, and are in the top level
24273@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
24274version @value{GDBVN}), you can make the Info file by typing:
c4555f82 24275
474c8240 24276@smallexample
8e04817f
AC
24277cd gdb
24278make gdb.info
474c8240 24279@end smallexample
c4555f82 24280
8e04817f
AC
24281If you want to typeset and print copies of this manual, you need @TeX{},
24282a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
24283Texinfo definitions file.
c4555f82 24284
8e04817f
AC
24285@TeX{} is a typesetting program; it does not print files directly, but
24286produces output files called @sc{dvi} files. To print a typeset
24287document, you need a program to print @sc{dvi} files. If your system
24288has @TeX{} installed, chances are it has such a program. The precise
24289command to use depends on your system; @kbd{lpr -d} is common; another
24290(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
24291require a file name without any extension or a @samp{.dvi} extension.
c4555f82 24292
8e04817f
AC
24293@TeX{} also requires a macro definitions file called
24294@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
24295written in Texinfo format. On its own, @TeX{} cannot either read or
24296typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
24297and is located in the @file{gdb-@var{version-number}/texinfo}
24298directory.
c4555f82 24299
8e04817f 24300If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 24301typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
24302subdirectory of the main source directory (for example, to
24303@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 24304
474c8240 24305@smallexample
8e04817f 24306make gdb.dvi
474c8240 24307@end smallexample
c4555f82 24308
8e04817f 24309Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 24310
8e04817f
AC
24311@node Installing GDB
24312@appendix Installing @value{GDBN}
8e04817f 24313@cindex installation
c4555f82 24314
7fa2210b
DJ
24315@menu
24316* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 24317* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
24318* Separate Objdir:: Compiling @value{GDBN} in another directory
24319* Config Names:: Specifying names for hosts and targets
24320* Configure Options:: Summary of options for configure
24321@end menu
24322
24323@node Requirements
79a6e687 24324@section Requirements for Building @value{GDBN}
7fa2210b
DJ
24325@cindex building @value{GDBN}, requirements for
24326
24327Building @value{GDBN} requires various tools and packages to be available.
24328Other packages will be used only if they are found.
24329
79a6e687 24330@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
24331@table @asis
24332@item ISO C90 compiler
24333@value{GDBN} is written in ISO C90. It should be buildable with any
24334working C90 compiler, e.g.@: GCC.
24335
24336@end table
24337
79a6e687 24338@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
24339@table @asis
24340@item Expat
123dc839 24341@anchor{Expat}
7fa2210b
DJ
24342@value{GDBN} can use the Expat XML parsing library. This library may be
24343included with your operating system distribution; if it is not, you
24344can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 24345The @file{configure} script will search for this library in several
7fa2210b
DJ
24346standard locations; if it is installed in an unusual path, you can
24347use the @option{--with-libexpat-prefix} option to specify its location.
24348
9cceb671
DJ
24349Expat is used for:
24350
24351@itemize @bullet
24352@item
24353Remote protocol memory maps (@pxref{Memory Map Format})
24354@item
24355Target descriptions (@pxref{Target Descriptions})
24356@item
24357Remote shared library lists (@pxref{Library List Format})
24358@item
24359MS-Windows shared libraries (@pxref{Shared Libraries})
24360@end itemize
7fa2210b 24361
31fffb02
CS
24362@item zlib
24363@cindex compressed debug sections
24364@value{GDBN} will use the @samp{zlib} library, if available, to read
24365compressed debug sections. Some linkers, such as GNU gold, are capable
24366of producing binaries with compressed debug sections. If @value{GDBN}
24367is compiled with @samp{zlib}, it will be able to read the debug
24368information in such binaries.
24369
24370The @samp{zlib} library is likely included with your operating system
24371distribution; if it is not, you can get the latest version from
24372@url{http://zlib.net}.
24373
7fa2210b
DJ
24374@end table
24375
24376@node Running Configure
db2e3e2e 24377@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 24378@cindex configuring @value{GDBN}
db2e3e2e 24379@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
24380of preparing @value{GDBN} for installation; you can then use @code{make} to
24381build the @code{gdb} program.
24382@iftex
24383@c irrelevant in info file; it's as current as the code it lives with.
24384@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
24385look at the @file{README} file in the sources; we may have improved the
24386installation procedures since publishing this manual.}
24387@end iftex
c4555f82 24388
8e04817f
AC
24389The @value{GDBN} distribution includes all the source code you need for
24390@value{GDBN} in a single directory, whose name is usually composed by
24391appending the version number to @samp{gdb}.
c4555f82 24392
8e04817f
AC
24393For example, the @value{GDBN} version @value{GDBVN} distribution is in the
24394@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 24395
8e04817f
AC
24396@table @code
24397@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
24398script for configuring @value{GDBN} and all its supporting libraries
c4555f82 24399
8e04817f
AC
24400@item gdb-@value{GDBVN}/gdb
24401the source specific to @value{GDBN} itself
c4555f82 24402
8e04817f
AC
24403@item gdb-@value{GDBVN}/bfd
24404source for the Binary File Descriptor library
c906108c 24405
8e04817f
AC
24406@item gdb-@value{GDBVN}/include
24407@sc{gnu} include files
c906108c 24408
8e04817f
AC
24409@item gdb-@value{GDBVN}/libiberty
24410source for the @samp{-liberty} free software library
c906108c 24411
8e04817f
AC
24412@item gdb-@value{GDBVN}/opcodes
24413source for the library of opcode tables and disassemblers
c906108c 24414
8e04817f
AC
24415@item gdb-@value{GDBVN}/readline
24416source for the @sc{gnu} command-line interface
c906108c 24417
8e04817f
AC
24418@item gdb-@value{GDBVN}/glob
24419source for the @sc{gnu} filename pattern-matching subroutine
c906108c 24420
8e04817f
AC
24421@item gdb-@value{GDBVN}/mmalloc
24422source for the @sc{gnu} memory-mapped malloc package
24423@end table
c906108c 24424
db2e3e2e 24425The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
24426from the @file{gdb-@var{version-number}} source directory, which in
24427this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 24428
8e04817f 24429First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 24430if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
24431identifier for the platform on which @value{GDBN} will run as an
24432argument.
c906108c 24433
8e04817f 24434For example:
c906108c 24435
474c8240 24436@smallexample
8e04817f
AC
24437cd gdb-@value{GDBVN}
24438./configure @var{host}
24439make
474c8240 24440@end smallexample
c906108c 24441
8e04817f
AC
24442@noindent
24443where @var{host} is an identifier such as @samp{sun4} or
24444@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 24445(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 24446correct value by examining your system.)
c906108c 24447
8e04817f
AC
24448Running @samp{configure @var{host}} and then running @code{make} builds the
24449@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
24450libraries, then @code{gdb} itself. The configured source files, and the
24451binaries, are left in the corresponding source directories.
c906108c 24452
8e04817f 24453@need 750
db2e3e2e 24454@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
24455system does not recognize this automatically when you run a different
24456shell, you may need to run @code{sh} on it explicitly:
c906108c 24457
474c8240 24458@smallexample
8e04817f 24459sh configure @var{host}
474c8240 24460@end smallexample
c906108c 24461
db2e3e2e 24462If you run @file{configure} from a directory that contains source
8e04817f 24463directories for multiple libraries or programs, such as the
db2e3e2e
BW
24464@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
24465@file{configure}
8e04817f
AC
24466creates configuration files for every directory level underneath (unless
24467you tell it not to, with the @samp{--norecursion} option).
24468
db2e3e2e 24469You should run the @file{configure} script from the top directory in the
94e91d6d 24470source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 24471@file{configure} from one of the subdirectories, you will configure only
94e91d6d 24472that subdirectory. That is usually not what you want. In particular,
db2e3e2e 24473if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
24474of the @file{gdb-@var{version-number}} directory, you will omit the
24475configuration of @file{bfd}, @file{readline}, and other sibling
24476directories of the @file{gdb} subdirectory. This leads to build errors
24477about missing include files such as @file{bfd/bfd.h}.
c906108c 24478
8e04817f
AC
24479You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
24480However, you should make sure that the shell on your path (named by
24481the @samp{SHELL} environment variable) is publicly readable. Remember
24482that @value{GDBN} uses the shell to start your program---some systems refuse to
24483let @value{GDBN} debug child processes whose programs are not readable.
c906108c 24484
8e04817f 24485@node Separate Objdir
79a6e687 24486@section Compiling @value{GDBN} in Another Directory
c906108c 24487
8e04817f
AC
24488If you want to run @value{GDBN} versions for several host or target machines,
24489you need a different @code{gdb} compiled for each combination of
db2e3e2e 24490host and target. @file{configure} is designed to make this easy by
8e04817f
AC
24491allowing you to generate each configuration in a separate subdirectory,
24492rather than in the source directory. If your @code{make} program
24493handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
24494@code{make} in each of these directories builds the @code{gdb}
24495program specified there.
c906108c 24496
db2e3e2e 24497To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 24498with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
24499(You also need to specify a path to find @file{configure}
24500itself from your working directory. If the path to @file{configure}
8e04817f
AC
24501would be the same as the argument to @samp{--srcdir}, you can leave out
24502the @samp{--srcdir} option; it is assumed.)
c906108c 24503
8e04817f
AC
24504For example, with version @value{GDBVN}, you can build @value{GDBN} in a
24505separate directory for a Sun 4 like this:
c906108c 24506
474c8240 24507@smallexample
8e04817f
AC
24508@group
24509cd gdb-@value{GDBVN}
24510mkdir ../gdb-sun4
24511cd ../gdb-sun4
24512../gdb-@value{GDBVN}/configure sun4
24513make
24514@end group
474c8240 24515@end smallexample
c906108c 24516
db2e3e2e 24517When @file{configure} builds a configuration using a remote source
8e04817f
AC
24518directory, it creates a tree for the binaries with the same structure
24519(and using the same names) as the tree under the source directory. In
24520the example, you'd find the Sun 4 library @file{libiberty.a} in the
24521directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
24522@file{gdb-sun4/gdb}.
c906108c 24523
94e91d6d
MC
24524Make sure that your path to the @file{configure} script has just one
24525instance of @file{gdb} in it. If your path to @file{configure} looks
24526like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
24527one subdirectory of @value{GDBN}, not the whole package. This leads to
24528build errors about missing include files such as @file{bfd/bfd.h}.
24529
8e04817f
AC
24530One popular reason to build several @value{GDBN} configurations in separate
24531directories is to configure @value{GDBN} for cross-compiling (where
24532@value{GDBN} runs on one machine---the @dfn{host}---while debugging
24533programs that run on another machine---the @dfn{target}).
24534You specify a cross-debugging target by
db2e3e2e 24535giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 24536
8e04817f
AC
24537When you run @code{make} to build a program or library, you must run
24538it in a configured directory---whatever directory you were in when you
db2e3e2e 24539called @file{configure} (or one of its subdirectories).
c906108c 24540
db2e3e2e 24541The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
24542directory also runs recursively. If you type @code{make} in a source
24543directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
24544directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
24545will build all the required libraries, and then build GDB.
c906108c 24546
8e04817f
AC
24547When you have multiple hosts or targets configured in separate
24548directories, you can run @code{make} on them in parallel (for example,
24549if they are NFS-mounted on each of the hosts); they will not interfere
24550with each other.
c906108c 24551
8e04817f 24552@node Config Names
79a6e687 24553@section Specifying Names for Hosts and Targets
c906108c 24554
db2e3e2e 24555The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
24556script are based on a three-part naming scheme, but some short predefined
24557aliases are also supported. The full naming scheme encodes three pieces
24558of information in the following pattern:
c906108c 24559
474c8240 24560@smallexample
8e04817f 24561@var{architecture}-@var{vendor}-@var{os}
474c8240 24562@end smallexample
c906108c 24563
8e04817f
AC
24564For example, you can use the alias @code{sun4} as a @var{host} argument,
24565or as the value for @var{target} in a @code{--target=@var{target}}
24566option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 24567
db2e3e2e 24568The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 24569any query facility to list all supported host and target names or
db2e3e2e 24570aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
24571@code{config.sub} to map abbreviations to full names; you can read the
24572script, if you wish, or you can use it to test your guesses on
24573abbreviations---for example:
c906108c 24574
8e04817f
AC
24575@smallexample
24576% sh config.sub i386-linux
24577i386-pc-linux-gnu
24578% sh config.sub alpha-linux
24579alpha-unknown-linux-gnu
24580% sh config.sub hp9k700
24581hppa1.1-hp-hpux
24582% sh config.sub sun4
24583sparc-sun-sunos4.1.1
24584% sh config.sub sun3
24585m68k-sun-sunos4.1.1
24586% sh config.sub i986v
24587Invalid configuration `i986v': machine `i986v' not recognized
24588@end smallexample
c906108c 24589
8e04817f
AC
24590@noindent
24591@code{config.sub} is also distributed in the @value{GDBN} source
24592directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 24593
8e04817f 24594@node Configure Options
db2e3e2e 24595@section @file{configure} Options
c906108c 24596
db2e3e2e
BW
24597Here is a summary of the @file{configure} options and arguments that
24598are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 24599several other options not listed here. @inforef{What Configure
db2e3e2e 24600Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 24601
474c8240 24602@smallexample
8e04817f
AC
24603configure @r{[}--help@r{]}
24604 @r{[}--prefix=@var{dir}@r{]}
24605 @r{[}--exec-prefix=@var{dir}@r{]}
24606 @r{[}--srcdir=@var{dirname}@r{]}
24607 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
24608 @r{[}--target=@var{target}@r{]}
24609 @var{host}
474c8240 24610@end smallexample
c906108c 24611
8e04817f
AC
24612@noindent
24613You may introduce options with a single @samp{-} rather than
24614@samp{--} if you prefer; but you may abbreviate option names if you use
24615@samp{--}.
c906108c 24616
8e04817f
AC
24617@table @code
24618@item --help
db2e3e2e 24619Display a quick summary of how to invoke @file{configure}.
c906108c 24620
8e04817f
AC
24621@item --prefix=@var{dir}
24622Configure the source to install programs and files under directory
24623@file{@var{dir}}.
c906108c 24624
8e04817f
AC
24625@item --exec-prefix=@var{dir}
24626Configure the source to install programs under directory
24627@file{@var{dir}}.
c906108c 24628
8e04817f
AC
24629@c avoid splitting the warning from the explanation:
24630@need 2000
24631@item --srcdir=@var{dirname}
24632@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
24633@code{make} that implements the @code{VPATH} feature.}@*
24634Use this option to make configurations in directories separate from the
24635@value{GDBN} source directories. Among other things, you can use this to
24636build (or maintain) several configurations simultaneously, in separate
db2e3e2e 24637directories. @file{configure} writes configuration-specific files in
8e04817f 24638the current directory, but arranges for them to use the source in the
db2e3e2e 24639directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
24640the working directory in parallel to the source directories below
24641@var{dirname}.
c906108c 24642
8e04817f 24643@item --norecursion
db2e3e2e 24644Configure only the directory level where @file{configure} is executed; do not
8e04817f 24645propagate configuration to subdirectories.
c906108c 24646
8e04817f
AC
24647@item --target=@var{target}
24648Configure @value{GDBN} for cross-debugging programs running on the specified
24649@var{target}. Without this option, @value{GDBN} is configured to debug
24650programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 24651
8e04817f 24652There is no convenient way to generate a list of all available targets.
c906108c 24653
8e04817f
AC
24654@item @var{host} @dots{}
24655Configure @value{GDBN} to run on the specified @var{host}.
c906108c 24656
8e04817f
AC
24657There is no convenient way to generate a list of all available hosts.
24658@end table
c906108c 24659
8e04817f
AC
24660There are many other options available as well, but they are generally
24661needed for special purposes only.
c906108c 24662
8e04817f
AC
24663@node Maintenance Commands
24664@appendix Maintenance Commands
24665@cindex maintenance commands
24666@cindex internal commands
c906108c 24667
8e04817f 24668In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
24669includes a number of commands intended for @value{GDBN} developers,
24670that are not documented elsewhere in this manual. These commands are
da316a69
EZ
24671provided here for reference. (For commands that turn on debugging
24672messages, see @ref{Debugging Output}.)
c906108c 24673
8e04817f 24674@table @code
09d4efe1
EZ
24675@kindex maint agent
24676@item maint agent @var{expression}
24677Translate the given @var{expression} into remote agent bytecodes.
24678This command is useful for debugging the Agent Expression mechanism
24679(@pxref{Agent Expressions}).
24680
8e04817f
AC
24681@kindex maint info breakpoints
24682@item @anchor{maint info breakpoints}maint info breakpoints
24683Using the same format as @samp{info breakpoints}, display both the
24684breakpoints you've set explicitly, and those @value{GDBN} is using for
24685internal purposes. Internal breakpoints are shown with negative
24686breakpoint numbers. The type column identifies what kind of breakpoint
24687is shown:
c906108c 24688
8e04817f
AC
24689@table @code
24690@item breakpoint
24691Normal, explicitly set breakpoint.
c906108c 24692
8e04817f
AC
24693@item watchpoint
24694Normal, explicitly set watchpoint.
c906108c 24695
8e04817f
AC
24696@item longjmp
24697Internal breakpoint, used to handle correctly stepping through
24698@code{longjmp} calls.
c906108c 24699
8e04817f
AC
24700@item longjmp resume
24701Internal breakpoint at the target of a @code{longjmp}.
c906108c 24702
8e04817f
AC
24703@item until
24704Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 24705
8e04817f
AC
24706@item finish
24707Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 24708
8e04817f
AC
24709@item shlib events
24710Shared library events.
c906108c 24711
8e04817f 24712@end table
c906108c 24713
fff08868
HZ
24714@kindex set displaced-stepping
24715@kindex show displaced-stepping
237fc4c9
PA
24716@cindex displaced stepping support
24717@cindex out-of-line single-stepping
fff08868
HZ
24718@item set displaced-stepping
24719@itemx show displaced-stepping
237fc4c9 24720Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
24721if the target supports it. Displaced stepping is a way to single-step
24722over breakpoints without removing them from the inferior, by executing
24723an out-of-line copy of the instruction that was originally at the
24724breakpoint location. It is also known as out-of-line single-stepping.
24725
24726@table @code
24727@item set displaced-stepping on
24728If the target architecture supports it, @value{GDBN} will use
24729displaced stepping to step over breakpoints.
24730
24731@item set displaced-stepping off
24732@value{GDBN} will not use displaced stepping to step over breakpoints,
24733even if such is supported by the target architecture.
24734
24735@cindex non-stop mode, and @samp{set displaced-stepping}
24736@item set displaced-stepping auto
24737This is the default mode. @value{GDBN} will use displaced stepping
24738only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
24739architecture supports displaced stepping.
24740@end table
237fc4c9 24741
09d4efe1
EZ
24742@kindex maint check-symtabs
24743@item maint check-symtabs
24744Check the consistency of psymtabs and symtabs.
24745
24746@kindex maint cplus first_component
24747@item maint cplus first_component @var{name}
24748Print the first C@t{++} class/namespace component of @var{name}.
24749
24750@kindex maint cplus namespace
24751@item maint cplus namespace
24752Print the list of possible C@t{++} namespaces.
24753
24754@kindex maint demangle
24755@item maint demangle @var{name}
d3e8051b 24756Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
24757
24758@kindex maint deprecate
24759@kindex maint undeprecate
24760@cindex deprecated commands
24761@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
24762@itemx maint undeprecate @var{command}
24763Deprecate or undeprecate the named @var{command}. Deprecated commands
24764cause @value{GDBN} to issue a warning when you use them. The optional
24765argument @var{replacement} says which newer command should be used in
24766favor of the deprecated one; if it is given, @value{GDBN} will mention
24767the replacement as part of the warning.
24768
24769@kindex maint dump-me
24770@item maint dump-me
721c2651 24771@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 24772Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
24773This is supported only on systems which support aborting a program
24774with the @code{SIGQUIT} signal.
09d4efe1 24775
8d30a00d
AC
24776@kindex maint internal-error
24777@kindex maint internal-warning
09d4efe1
EZ
24778@item maint internal-error @r{[}@var{message-text}@r{]}
24779@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
24780Cause @value{GDBN} to call the internal function @code{internal_error}
24781or @code{internal_warning} and hence behave as though an internal error
24782or internal warning has been detected. In addition to reporting the
24783internal problem, these functions give the user the opportunity to
24784either quit @value{GDBN} or create a core file of the current
24785@value{GDBN} session.
24786
09d4efe1
EZ
24787These commands take an optional parameter @var{message-text} that is
24788used as the text of the error or warning message.
24789
d3e8051b 24790Here's an example of using @code{internal-error}:
09d4efe1 24791
8d30a00d 24792@smallexample
f7dc1244 24793(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
24794@dots{}/maint.c:121: internal-error: testing, 1, 2
24795A problem internal to GDB has been detected. Further
24796debugging may prove unreliable.
24797Quit this debugging session? (y or n) @kbd{n}
24798Create a core file? (y or n) @kbd{n}
f7dc1244 24799(@value{GDBP})
8d30a00d
AC
24800@end smallexample
24801
09d4efe1
EZ
24802@kindex maint packet
24803@item maint packet @var{text}
24804If @value{GDBN} is talking to an inferior via the serial protocol,
24805then this command sends the string @var{text} to the inferior, and
24806displays the response packet. @value{GDBN} supplies the initial
24807@samp{$} character, the terminating @samp{#} character, and the
24808checksum.
24809
24810@kindex maint print architecture
24811@item maint print architecture @r{[}@var{file}@r{]}
24812Print the entire architecture configuration. The optional argument
24813@var{file} names the file where the output goes.
8d30a00d 24814
81adfced
DJ
24815@kindex maint print c-tdesc
24816@item maint print c-tdesc
24817Print the current target description (@pxref{Target Descriptions}) as
24818a C source file. The created source file can be used in @value{GDBN}
24819when an XML parser is not available to parse the description.
24820
00905d52
AC
24821@kindex maint print dummy-frames
24822@item maint print dummy-frames
00905d52
AC
24823Prints the contents of @value{GDBN}'s internal dummy-frame stack.
24824
24825@smallexample
f7dc1244 24826(@value{GDBP}) @kbd{b add}
00905d52 24827@dots{}
f7dc1244 24828(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
24829Breakpoint 2, add (a=2, b=3) at @dots{}
2483058 return (a + b);
24831The program being debugged stopped while in a function called from GDB.
24832@dots{}
f7dc1244 24833(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
248340x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
24835 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
24836 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 24837(@value{GDBP})
00905d52
AC
24838@end smallexample
24839
24840Takes an optional file parameter.
24841
0680b120
AC
24842@kindex maint print registers
24843@kindex maint print raw-registers
24844@kindex maint print cooked-registers
617073a9 24845@kindex maint print register-groups
09d4efe1
EZ
24846@item maint print registers @r{[}@var{file}@r{]}
24847@itemx maint print raw-registers @r{[}@var{file}@r{]}
24848@itemx maint print cooked-registers @r{[}@var{file}@r{]}
24849@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
24850Print @value{GDBN}'s internal register data structures.
24851
617073a9
AC
24852The command @code{maint print raw-registers} includes the contents of
24853the raw register cache; the command @code{maint print cooked-registers}
24854includes the (cooked) value of all registers; and the command
24855@code{maint print register-groups} includes the groups that each
24856register is a member of. @xref{Registers,, Registers, gdbint,
24857@value{GDBN} Internals}.
0680b120 24858
09d4efe1
EZ
24859These commands take an optional parameter, a file name to which to
24860write the information.
0680b120 24861
617073a9 24862@kindex maint print reggroups
09d4efe1
EZ
24863@item maint print reggroups @r{[}@var{file}@r{]}
24864Print @value{GDBN}'s internal register group data structures. The
24865optional argument @var{file} tells to what file to write the
24866information.
617073a9 24867
09d4efe1 24868The register groups info looks like this:
617073a9
AC
24869
24870@smallexample
f7dc1244 24871(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
24872 Group Type
24873 general user
24874 float user
24875 all user
24876 vector user
24877 system user
24878 save internal
24879 restore internal
617073a9
AC
24880@end smallexample
24881
09d4efe1
EZ
24882@kindex flushregs
24883@item flushregs
24884This command forces @value{GDBN} to flush its internal register cache.
24885
24886@kindex maint print objfiles
24887@cindex info for known object files
24888@item maint print objfiles
24889Print a dump of all known object files. For each object file, this
24890command prints its name, address in memory, and all of its psymtabs
24891and symtabs.
24892
24893@kindex maint print statistics
24894@cindex bcache statistics
24895@item maint print statistics
24896This command prints, for each object file in the program, various data
24897about that object file followed by the byte cache (@dfn{bcache})
24898statistics for the object file. The objfile data includes the number
d3e8051b 24899of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
24900defined by the objfile, the number of as yet unexpanded psym tables,
24901the number of line tables and string tables, and the amount of memory
24902used by the various tables. The bcache statistics include the counts,
24903sizes, and counts of duplicates of all and unique objects, max,
24904average, and median entry size, total memory used and its overhead and
24905savings, and various measures of the hash table size and chain
24906lengths.
24907
c7ba131e
JB
24908@kindex maint print target-stack
24909@cindex target stack description
24910@item maint print target-stack
24911A @dfn{target} is an interface between the debugger and a particular
24912kind of file or process. Targets can be stacked in @dfn{strata},
24913so that more than one target can potentially respond to a request.
24914In particular, memory accesses will walk down the stack of targets
24915until they find a target that is interested in handling that particular
24916address.
24917
24918This command prints a short description of each layer that was pushed on
24919the @dfn{target stack}, starting from the top layer down to the bottom one.
24920
09d4efe1
EZ
24921@kindex maint print type
24922@cindex type chain of a data type
24923@item maint print type @var{expr}
24924Print the type chain for a type specified by @var{expr}. The argument
24925can be either a type name or a symbol. If it is a symbol, the type of
24926that symbol is described. The type chain produced by this command is
24927a recursive definition of the data type as stored in @value{GDBN}'s
24928data structures, including its flags and contained types.
24929
24930@kindex maint set dwarf2 max-cache-age
24931@kindex maint show dwarf2 max-cache-age
24932@item maint set dwarf2 max-cache-age
24933@itemx maint show dwarf2 max-cache-age
24934Control the DWARF 2 compilation unit cache.
24935
24936@cindex DWARF 2 compilation units cache
24937In object files with inter-compilation-unit references, such as those
24938produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
24939reader needs to frequently refer to previously read compilation units.
24940This setting controls how long a compilation unit will remain in the
24941cache if it is not referenced. A higher limit means that cached
24942compilation units will be stored in memory longer, and more total
24943memory will be used. Setting it to zero disables caching, which will
24944slow down @value{GDBN} startup, but reduce memory consumption.
24945
e7ba9c65
DJ
24946@kindex maint set profile
24947@kindex maint show profile
24948@cindex profiling GDB
24949@item maint set profile
24950@itemx maint show profile
24951Control profiling of @value{GDBN}.
24952
24953Profiling will be disabled until you use the @samp{maint set profile}
24954command to enable it. When you enable profiling, the system will begin
24955collecting timing and execution count data; when you disable profiling or
24956exit @value{GDBN}, the results will be written to a log file. Remember that
24957if you use profiling, @value{GDBN} will overwrite the profiling log file
24958(often called @file{gmon.out}). If you have a record of important profiling
24959data in a @file{gmon.out} file, be sure to move it to a safe location.
24960
24961Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 24962compiled with the @samp{-pg} compiler option.
e7ba9c65 24963
b84876c2
PA
24964@kindex maint set linux-async
24965@kindex maint show linux-async
24966@cindex asynchronous support
24967@item maint set linux-async
24968@itemx maint show linux-async
0606b73b
SL
24969Control the GNU/Linux native asynchronous support
24970(@pxref{Background Execution}) of @value{GDBN}.
b84876c2
PA
24971
24972GNU/Linux native asynchronous support will be disabled until you use
24973the @samp{maint set linux-async} command to enable it.
24974
75c99385
PA
24975@kindex maint set remote-async
24976@kindex maint show remote-async
24977@cindex asynchronous support
24978@item maint set remote-async
24979@itemx maint show remote-async
0606b73b
SL
24980Control the remote asynchronous support
24981(@pxref{Background Execution}) of @value{GDBN}.
75c99385
PA
24982
24983Remote asynchronous support will be disabled until you use
24984the @samp{maint set remote-async} command to enable it.
24985
09d4efe1
EZ
24986@kindex maint show-debug-regs
24987@cindex x86 hardware debug registers
24988@item maint show-debug-regs
24989Control whether to show variables that mirror the x86 hardware debug
24990registers. Use @code{ON} to enable, @code{OFF} to disable. If
3f94c067 24991enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
24992removes a hardware breakpoint or watchpoint, and when the inferior
24993triggers a hardware-assisted breakpoint or watchpoint.
24994
24995@kindex maint space
24996@cindex memory used by commands
24997@item maint space
24998Control whether to display memory usage for each command. If set to a
24999nonzero value, @value{GDBN} will display how much memory each command
25000took, following the command's own output. This can also be requested
25001by invoking @value{GDBN} with the @option{--statistics} command-line
25002switch (@pxref{Mode Options}).
25003
25004@kindex maint time
25005@cindex time of command execution
25006@item maint time
25007Control whether to display the execution time for each command. If
25008set to a nonzero value, @value{GDBN} will display how much time it
25009took to execute each command, following the command's own output.
e2b7ddea
VP
25010The time is not printed for the commands that run the target, since
25011there's no mechanism currently to compute how much time was spend
25012by @value{GDBN} and how much time was spend by the program been debugged.
25013it's not possibly currently
09d4efe1
EZ
25014This can also be requested by invoking @value{GDBN} with the
25015@option{--statistics} command-line switch (@pxref{Mode Options}).
25016
25017@kindex maint translate-address
25018@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
25019Find the symbol stored at the location specified by the address
25020@var{addr} and an optional section name @var{section}. If found,
25021@value{GDBN} prints the name of the closest symbol and an offset from
25022the symbol's location to the specified address. This is similar to
25023the @code{info address} command (@pxref{Symbols}), except that this
25024command also allows to find symbols in other sections.
ae038cb0 25025
c14c28ba
PP
25026If section was not specified, the section in which the symbol was found
25027is also printed. For dynamically linked executables, the name of
25028executable or shared library containing the symbol is printed as well.
25029
8e04817f 25030@end table
c906108c 25031
9c16f35a
EZ
25032The following command is useful for non-interactive invocations of
25033@value{GDBN}, such as in the test suite.
25034
25035@table @code
25036@item set watchdog @var{nsec}
25037@kindex set watchdog
25038@cindex watchdog timer
25039@cindex timeout for commands
25040Set the maximum number of seconds @value{GDBN} will wait for the
25041target operation to finish. If this time expires, @value{GDBN}
25042reports and error and the command is aborted.
25043
25044@item show watchdog
25045Show the current setting of the target wait timeout.
25046@end table
c906108c 25047
e0ce93ac 25048@node Remote Protocol
8e04817f 25049@appendix @value{GDBN} Remote Serial Protocol
c906108c 25050
ee2d5c50
AC
25051@menu
25052* Overview::
25053* Packets::
25054* Stop Reply Packets::
25055* General Query Packets::
25056* Register Packet Format::
9d29849a 25057* Tracepoint Packets::
a6b151f1 25058* Host I/O Packets::
9a6253be 25059* Interrupts::
8b23ecc4
SL
25060* Notification Packets::
25061* Remote Non-Stop::
a6f3e723 25062* Packet Acknowledgment::
ee2d5c50 25063* Examples::
79a6e687 25064* File-I/O Remote Protocol Extension::
cfa9d6d9 25065* Library List Format::
79a6e687 25066* Memory Map Format::
ee2d5c50
AC
25067@end menu
25068
25069@node Overview
25070@section Overview
25071
8e04817f
AC
25072There may be occasions when you need to know something about the
25073protocol---for example, if there is only one serial port to your target
25074machine, you might want your program to do something special if it
25075recognizes a packet meant for @value{GDBN}.
c906108c 25076
d2c6833e 25077In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 25078transmitted and received data, respectively.
c906108c 25079
8e04817f
AC
25080@cindex protocol, @value{GDBN} remote serial
25081@cindex serial protocol, @value{GDBN} remote
25082@cindex remote serial protocol
8b23ecc4
SL
25083All @value{GDBN} commands and responses (other than acknowledgments
25084and notifications, see @ref{Notification Packets}) are sent as a
25085@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
25086@samp{$}, the actual @var{packet-data}, and the terminating character
25087@samp{#} followed by a two-digit @var{checksum}:
c906108c 25088
474c8240 25089@smallexample
8e04817f 25090@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 25091@end smallexample
8e04817f 25092@noindent
c906108c 25093
8e04817f
AC
25094@cindex checksum, for @value{GDBN} remote
25095@noindent
25096The two-digit @var{checksum} is computed as the modulo 256 sum of all
25097characters between the leading @samp{$} and the trailing @samp{#} (an
25098eight bit unsigned checksum).
c906108c 25099
8e04817f
AC
25100Implementors should note that prior to @value{GDBN} 5.0 the protocol
25101specification also included an optional two-digit @var{sequence-id}:
c906108c 25102
474c8240 25103@smallexample
8e04817f 25104@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 25105@end smallexample
c906108c 25106
8e04817f
AC
25107@cindex sequence-id, for @value{GDBN} remote
25108@noindent
25109That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
25110has never output @var{sequence-id}s. Stubs that handle packets added
25111since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 25112
8e04817f
AC
25113When either the host or the target machine receives a packet, the first
25114response expected is an acknowledgment: either @samp{+} (to indicate
25115the package was received correctly) or @samp{-} (to request
25116retransmission):
c906108c 25117
474c8240 25118@smallexample
d2c6833e
AC
25119-> @code{$}@var{packet-data}@code{#}@var{checksum}
25120<- @code{+}
474c8240 25121@end smallexample
8e04817f 25122@noindent
53a5351d 25123
a6f3e723
SL
25124The @samp{+}/@samp{-} acknowledgments can be disabled
25125once a connection is established.
25126@xref{Packet Acknowledgment}, for details.
25127
8e04817f
AC
25128The host (@value{GDBN}) sends @var{command}s, and the target (the
25129debugging stub incorporated in your program) sends a @var{response}. In
25130the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
25131when the operation has completed, and the target has again stopped all
25132threads in all attached processes. This is the default all-stop mode
25133behavior, but the remote protocol also supports @value{GDBN}'s non-stop
25134execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 25135
8e04817f
AC
25136@var{packet-data} consists of a sequence of characters with the
25137exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
25138exceptions).
c906108c 25139
ee2d5c50 25140@cindex remote protocol, field separator
0876f84a 25141Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 25142@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 25143@sc{hex} with leading zeros suppressed.
c906108c 25144
8e04817f
AC
25145Implementors should note that prior to @value{GDBN} 5.0, the character
25146@samp{:} could not appear as the third character in a packet (as it
25147would potentially conflict with the @var{sequence-id}).
c906108c 25148
0876f84a
DJ
25149@cindex remote protocol, binary data
25150@anchor{Binary Data}
25151Binary data in most packets is encoded either as two hexadecimal
25152digits per byte of binary data. This allowed the traditional remote
25153protocol to work over connections which were only seven-bit clean.
25154Some packets designed more recently assume an eight-bit clean
25155connection, and use a more efficient encoding to send and receive
25156binary data.
25157
25158The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
25159as an escape character. Any escaped byte is transmitted as the escape
25160character followed by the original character XORed with @code{0x20}.
25161For example, the byte @code{0x7d} would be transmitted as the two
25162bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
25163@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
25164@samp{@}}) must always be escaped. Responses sent by the stub
25165must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
25166is not interpreted as the start of a run-length encoded sequence
25167(described next).
25168
1d3811f6
DJ
25169Response @var{data} can be run-length encoded to save space.
25170Run-length encoding replaces runs of identical characters with one
25171instance of the repeated character, followed by a @samp{*} and a
25172repeat count. The repeat count is itself sent encoded, to avoid
25173binary characters in @var{data}: a value of @var{n} is sent as
25174@code{@var{n}+29}. For a repeat count greater or equal to 3, this
25175produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
25176code 32) for a repeat count of 3. (This is because run-length
25177encoding starts to win for counts 3 or more.) Thus, for example,
25178@samp{0* } is a run-length encoding of ``0000'': the space character
25179after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
251803}} more times.
25181
25182The printable characters @samp{#} and @samp{$} or with a numeric value
25183greater than 126 must not be used. Runs of six repeats (@samp{#}) or
25184seven repeats (@samp{$}) can be expanded using a repeat count of only
25185five (@samp{"}). For example, @samp{00000000} can be encoded as
25186@samp{0*"00}.
c906108c 25187
8e04817f
AC
25188The error response returned for some packets includes a two character
25189error number. That number is not well defined.
c906108c 25190
f8da2bff 25191@cindex empty response, for unsupported packets
8e04817f
AC
25192For any @var{command} not supported by the stub, an empty response
25193(@samp{$#00}) should be returned. That way it is possible to extend the
25194protocol. A newer @value{GDBN} can tell if a packet is supported based
25195on that response.
c906108c 25196
b383017d
RM
25197A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
25198@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 25199optional.
c906108c 25200
ee2d5c50
AC
25201@node Packets
25202@section Packets
25203
25204The following table provides a complete list of all currently defined
25205@var{command}s and their corresponding response @var{data}.
79a6e687 25206@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 25207I/O extension of the remote protocol.
ee2d5c50 25208
b8ff78ce
JB
25209Each packet's description has a template showing the packet's overall
25210syntax, followed by an explanation of the packet's meaning. We
25211include spaces in some of the templates for clarity; these are not
25212part of the packet's syntax. No @value{GDBN} packet uses spaces to
25213separate its components. For example, a template like @samp{foo
25214@var{bar} @var{baz}} describes a packet beginning with the three ASCII
25215bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 25216@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
25217@samp{foo} and the @var{bar}, or between the @var{bar} and the
25218@var{baz}.
25219
b90a069a
SL
25220@cindex @var{thread-id}, in remote protocol
25221@anchor{thread-id syntax}
25222Several packets and replies include a @var{thread-id} field to identify
25223a thread. Normally these are positive numbers with a target-specific
25224interpretation, formatted as big-endian hex strings. A @var{thread-id}
25225can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
25226pick any thread.
25227
25228In addition, the remote protocol supports a multiprocess feature in
25229which the @var{thread-id} syntax is extended to optionally include both
25230process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
25231The @var{pid} (process) and @var{tid} (thread) components each have the
25232format described above: a positive number with target-specific
25233interpretation formatted as a big-endian hex string, literal @samp{-1}
25234to indicate all processes or threads (respectively), or @samp{0} to
25235indicate an arbitrary process or thread. Specifying just a process, as
25236@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
25237error to specify all processes but a specific thread, such as
25238@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
25239for those packets and replies explicitly documented to include a process
25240ID, rather than a @var{thread-id}.
25241
25242The multiprocess @var{thread-id} syntax extensions are only used if both
25243@value{GDBN} and the stub report support for the @samp{multiprocess}
25244feature using @samp{qSupported}. @xref{multiprocess extensions}, for
25245more information.
25246
8ffe2530
JB
25247Note that all packet forms beginning with an upper- or lower-case
25248letter, other than those described here, are reserved for future use.
25249
b8ff78ce 25250Here are the packet descriptions.
ee2d5c50 25251
b8ff78ce 25252@table @samp
ee2d5c50 25253
b8ff78ce
JB
25254@item !
25255@cindex @samp{!} packet
2d717e4f 25256@anchor{extended mode}
8e04817f
AC
25257Enable extended mode. In extended mode, the remote server is made
25258persistent. The @samp{R} packet is used to restart the program being
25259debugged.
ee2d5c50
AC
25260
25261Reply:
25262@table @samp
25263@item OK
8e04817f 25264The remote target both supports and has enabled extended mode.
ee2d5c50 25265@end table
c906108c 25266
b8ff78ce
JB
25267@item ?
25268@cindex @samp{?} packet
ee2d5c50 25269Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
25270step and continue. This packet has a special interpretation when the
25271target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 25272
ee2d5c50
AC
25273Reply:
25274@xref{Stop Reply Packets}, for the reply specifications.
25275
b8ff78ce
JB
25276@item A @var{arglen},@var{argnum},@var{arg},@dots{}
25277@cindex @samp{A} packet
25278Initialized @code{argv[]} array passed into program. @var{arglen}
25279specifies the number of bytes in the hex encoded byte stream
25280@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
25281
25282Reply:
25283@table @samp
25284@item OK
b8ff78ce
JB
25285The arguments were set.
25286@item E @var{NN}
25287An error occurred.
ee2d5c50
AC
25288@end table
25289
b8ff78ce
JB
25290@item b @var{baud}
25291@cindex @samp{b} packet
25292(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
25293Change the serial line speed to @var{baud}.
25294
25295JTC: @emph{When does the transport layer state change? When it's
25296received, or after the ACK is transmitted. In either case, there are
25297problems if the command or the acknowledgment packet is dropped.}
25298
25299Stan: @emph{If people really wanted to add something like this, and get
25300it working for the first time, they ought to modify ser-unix.c to send
25301some kind of out-of-band message to a specially-setup stub and have the
25302switch happen "in between" packets, so that from remote protocol's point
25303of view, nothing actually happened.}
25304
b8ff78ce
JB
25305@item B @var{addr},@var{mode}
25306@cindex @samp{B} packet
8e04817f 25307Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
25308breakpoint at @var{addr}.
25309
b8ff78ce 25310Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 25311(@pxref{insert breakpoint or watchpoint packet}).
c906108c 25312
bacec72f
MS
25313@item bc
25314@cindex @samp{bc} packet
25315Backward continue. Execute the target system in reverse. No parameter.
25316@xref{Reverse Execution}, for more information.
25317
25318Reply:
25319@xref{Stop Reply Packets}, for the reply specifications.
25320
25321@item bs
25322@cindex @samp{bs} packet
25323Backward single step. Execute one instruction in reverse. No parameter.
25324@xref{Reverse Execution}, for more information.
25325
25326Reply:
25327@xref{Stop Reply Packets}, for the reply specifications.
25328
4f553f88 25329@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
25330@cindex @samp{c} packet
25331Continue. @var{addr} is address to resume. If @var{addr} is omitted,
25332resume at current address.
c906108c 25333
ee2d5c50
AC
25334Reply:
25335@xref{Stop Reply Packets}, for the reply specifications.
25336
4f553f88 25337@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 25338@cindex @samp{C} packet
8e04817f 25339Continue with signal @var{sig} (hex signal number). If
b8ff78ce 25340@samp{;@var{addr}} is omitted, resume at same address.
c906108c 25341
ee2d5c50
AC
25342Reply:
25343@xref{Stop Reply Packets}, for the reply specifications.
c906108c 25344
b8ff78ce
JB
25345@item d
25346@cindex @samp{d} packet
ee2d5c50
AC
25347Toggle debug flag.
25348
b8ff78ce
JB
25349Don't use this packet; instead, define a general set packet
25350(@pxref{General Query Packets}).
ee2d5c50 25351
b8ff78ce 25352@item D
b90a069a 25353@itemx D;@var{pid}
b8ff78ce 25354@cindex @samp{D} packet
b90a069a
SL
25355The first form of the packet is used to detach @value{GDBN} from the
25356remote system. It is sent to the remote target
07f31aa6 25357before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 25358
b90a069a
SL
25359The second form, including a process ID, is used when multiprocess
25360protocol extensions are enabled (@pxref{multiprocess extensions}), to
25361detach only a specific process. The @var{pid} is specified as a
25362big-endian hex string.
25363
ee2d5c50
AC
25364Reply:
25365@table @samp
10fac096
NW
25366@item OK
25367for success
b8ff78ce 25368@item E @var{NN}
10fac096 25369for an error
ee2d5c50 25370@end table
c906108c 25371
b8ff78ce
JB
25372@item F @var{RC},@var{EE},@var{CF};@var{XX}
25373@cindex @samp{F} packet
25374A reply from @value{GDBN} to an @samp{F} packet sent by the target.
25375This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 25376Remote Protocol Extension}, for the specification.
ee2d5c50 25377
b8ff78ce 25378@item g
ee2d5c50 25379@anchor{read registers packet}
b8ff78ce 25380@cindex @samp{g} packet
ee2d5c50
AC
25381Read general registers.
25382
25383Reply:
25384@table @samp
25385@item @var{XX@dots{}}
8e04817f
AC
25386Each byte of register data is described by two hex digits. The bytes
25387with the register are transmitted in target byte order. The size of
b8ff78ce 25388each register and their position within the @samp{g} packet are
4a9bb1df
UW
25389determined by the @value{GDBN} internal gdbarch functions
25390@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce
JB
25391specification of several standard @samp{g} packets is specified below.
25392@item E @var{NN}
ee2d5c50
AC
25393for an error.
25394@end table
c906108c 25395
b8ff78ce
JB
25396@item G @var{XX@dots{}}
25397@cindex @samp{G} packet
25398Write general registers. @xref{read registers packet}, for a
25399description of the @var{XX@dots{}} data.
ee2d5c50
AC
25400
25401Reply:
25402@table @samp
25403@item OK
25404for success
b8ff78ce 25405@item E @var{NN}
ee2d5c50
AC
25406for an error
25407@end table
25408
b90a069a 25409@item H @var{c} @var{thread-id}
b8ff78ce 25410@cindex @samp{H} packet
8e04817f 25411Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
25412@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
25413should be @samp{c} for step and continue operations, @samp{g} for other
b90a069a
SL
25414operations. The thread designator @var{thread-id} has the format and
25415interpretation described in @ref{thread-id syntax}.
ee2d5c50
AC
25416
25417Reply:
25418@table @samp
25419@item OK
25420for success
b8ff78ce 25421@item E @var{NN}
ee2d5c50
AC
25422for an error
25423@end table
c906108c 25424
8e04817f
AC
25425@c FIXME: JTC:
25426@c 'H': How restrictive (or permissive) is the thread model. If a
25427@c thread is selected and stopped, are other threads allowed
25428@c to continue to execute? As I mentioned above, I think the
25429@c semantics of each command when a thread is selected must be
25430@c described. For example:
25431@c
25432@c 'g': If the stub supports threads and a specific thread is
25433@c selected, returns the register block from that thread;
25434@c otherwise returns current registers.
25435@c
25436@c 'G' If the stub supports threads and a specific thread is
25437@c selected, sets the registers of the register block of
25438@c that thread; otherwise sets current registers.
c906108c 25439
b8ff78ce 25440@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 25441@anchor{cycle step packet}
b8ff78ce
JB
25442@cindex @samp{i} packet
25443Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
25444present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
25445step starting at that address.
c906108c 25446
b8ff78ce
JB
25447@item I
25448@cindex @samp{I} packet
25449Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
25450step packet}.
ee2d5c50 25451
b8ff78ce
JB
25452@item k
25453@cindex @samp{k} packet
25454Kill request.
c906108c 25455
ac282366 25456FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
25457thread context has been selected (i.e.@: does 'k' kill only that
25458thread?)}.
c906108c 25459
b8ff78ce
JB
25460@item m @var{addr},@var{length}
25461@cindex @samp{m} packet
8e04817f 25462Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
25463Note that @var{addr} may not be aligned to any particular boundary.
25464
25465The stub need not use any particular size or alignment when gathering
25466data from memory for the response; even if @var{addr} is word-aligned
25467and @var{length} is a multiple of the word size, the stub is free to
25468use byte accesses, or not. For this reason, this packet may not be
25469suitable for accessing memory-mapped I/O devices.
c43c5473
JB
25470@cindex alignment of remote memory accesses
25471@cindex size of remote memory accesses
25472@cindex memory, alignment and size of remote accesses
c906108c 25473
ee2d5c50
AC
25474Reply:
25475@table @samp
25476@item @var{XX@dots{}}
599b237a 25477Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
25478number. The reply may contain fewer bytes than requested if the
25479server was able to read only part of the region of memory.
25480@item E @var{NN}
ee2d5c50
AC
25481@var{NN} is errno
25482@end table
25483
b8ff78ce
JB
25484@item M @var{addr},@var{length}:@var{XX@dots{}}
25485@cindex @samp{M} packet
8e04817f 25486Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 25487@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 25488hexadecimal number.
ee2d5c50
AC
25489
25490Reply:
25491@table @samp
25492@item OK
25493for success
b8ff78ce 25494@item E @var{NN}
8e04817f
AC
25495for an error (this includes the case where only part of the data was
25496written).
ee2d5c50 25497@end table
c906108c 25498
b8ff78ce
JB
25499@item p @var{n}
25500@cindex @samp{p} packet
25501Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
25502@xref{read registers packet}, for a description of how the returned
25503register value is encoded.
ee2d5c50
AC
25504
25505Reply:
25506@table @samp
2e868123
AC
25507@item @var{XX@dots{}}
25508the register's value
b8ff78ce 25509@item E @var{NN}
2e868123
AC
25510for an error
25511@item
25512Indicating an unrecognized @var{query}.
ee2d5c50
AC
25513@end table
25514
b8ff78ce 25515@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 25516@anchor{write register packet}
b8ff78ce
JB
25517@cindex @samp{P} packet
25518Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 25519number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 25520digits for each byte in the register (target byte order).
c906108c 25521
ee2d5c50
AC
25522Reply:
25523@table @samp
25524@item OK
25525for success
b8ff78ce 25526@item E @var{NN}
ee2d5c50
AC
25527for an error
25528@end table
25529
5f3bebba
JB
25530@item q @var{name} @var{params}@dots{}
25531@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 25532@cindex @samp{q} packet
b8ff78ce 25533@cindex @samp{Q} packet
5f3bebba
JB
25534General query (@samp{q}) and set (@samp{Q}). These packets are
25535described fully in @ref{General Query Packets}.
c906108c 25536
b8ff78ce
JB
25537@item r
25538@cindex @samp{r} packet
8e04817f 25539Reset the entire system.
c906108c 25540
b8ff78ce 25541Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 25542
b8ff78ce
JB
25543@item R @var{XX}
25544@cindex @samp{R} packet
8e04817f 25545Restart the program being debugged. @var{XX}, while needed, is ignored.
2d717e4f 25546This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 25547
8e04817f 25548The @samp{R} packet has no reply.
ee2d5c50 25549
4f553f88 25550@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
25551@cindex @samp{s} packet
25552Single step. @var{addr} is the address at which to resume. If
25553@var{addr} is omitted, resume at same address.
c906108c 25554
ee2d5c50
AC
25555Reply:
25556@xref{Stop Reply Packets}, for the reply specifications.
25557
4f553f88 25558@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 25559@anchor{step with signal packet}
b8ff78ce
JB
25560@cindex @samp{S} packet
25561Step with signal. This is analogous to the @samp{C} packet, but
25562requests a single-step, rather than a normal resumption of execution.
c906108c 25563
ee2d5c50
AC
25564Reply:
25565@xref{Stop Reply Packets}, for the reply specifications.
25566
b8ff78ce
JB
25567@item t @var{addr}:@var{PP},@var{MM}
25568@cindex @samp{t} packet
8e04817f 25569Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
25570@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
25571@var{addr} must be at least 3 digits.
c906108c 25572
b90a069a 25573@item T @var{thread-id}
b8ff78ce 25574@cindex @samp{T} packet
b90a069a 25575Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 25576
ee2d5c50
AC
25577Reply:
25578@table @samp
25579@item OK
25580thread is still alive
b8ff78ce 25581@item E @var{NN}
ee2d5c50
AC
25582thread is dead
25583@end table
25584
b8ff78ce
JB
25585@item v
25586Packets starting with @samp{v} are identified by a multi-letter name,
25587up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 25588
2d717e4f
DJ
25589@item vAttach;@var{pid}
25590@cindex @samp{vAttach} packet
8b23ecc4
SL
25591Attach to a new process with the specified process ID @var{pid}.
25592The process ID is a
25593hexadecimal integer identifying the process. In all-stop mode, all
25594threads in the attached process are stopped; in non-stop mode, it may be
25595attached without being stopped if that is supported by the target.
25596
25597@c In non-stop mode, on a successful vAttach, the stub should set the
25598@c current thread to a thread of the newly-attached process. After
25599@c attaching, GDB queries for the attached process's thread ID with qC.
25600@c Also note that, from a user perspective, whether or not the
25601@c target is stopped on attach in non-stop mode depends on whether you
25602@c use the foreground or background version of the attach command, not
25603@c on what vAttach does; GDB does the right thing with respect to either
25604@c stopping or restarting threads.
2d717e4f
DJ
25605
25606This packet is only available in extended mode (@pxref{extended mode}).
25607
25608Reply:
25609@table @samp
25610@item E @var{nn}
25611for an error
25612@item @r{Any stop packet}
8b23ecc4
SL
25613for success in all-stop mode (@pxref{Stop Reply Packets})
25614@item OK
25615for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
25616@end table
25617
b90a069a 25618@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce
JB
25619@cindex @samp{vCont} packet
25620Resume the inferior, specifying different actions for each thread.
b90a069a 25621If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 25622threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
25623specified then other threads should remain stopped in all-stop mode and
25624in their current state in non-stop mode.
25625Specifying multiple
86d30acc 25626default actions is an error; specifying no actions is also an error.
b90a069a
SL
25627Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
25628
25629Currently supported actions are:
86d30acc 25630
b8ff78ce 25631@table @samp
86d30acc
DJ
25632@item c
25633Continue.
b8ff78ce 25634@item C @var{sig}
8b23ecc4 25635Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
25636@item s
25637Step.
b8ff78ce 25638@item S @var{sig}
8b23ecc4
SL
25639Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
25640@item t
25641Stop.
25642@item T @var{sig}
25643Stop with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
25644@end table
25645
8b23ecc4
SL
25646The optional argument @var{addr} normally associated with the
25647@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 25648not supported in @samp{vCont}.
86d30acc 25649
8b23ecc4
SL
25650The @samp{t} and @samp{T} actions are only relevant in non-stop mode
25651(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
25652A stop reply should be generated for any affected thread not already stopped.
25653When a thread is stopped by means of a @samp{t} action,
25654the corresponding stop reply should indicate that the thread has stopped with
25655signal @samp{0}, regardless of whether the target uses some other signal
25656as an implementation detail.
25657
86d30acc
DJ
25658Reply:
25659@xref{Stop Reply Packets}, for the reply specifications.
25660
b8ff78ce
JB
25661@item vCont?
25662@cindex @samp{vCont?} packet
d3e8051b 25663Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
25664
25665Reply:
25666@table @samp
b8ff78ce
JB
25667@item vCont@r{[};@var{action}@dots{}@r{]}
25668The @samp{vCont} packet is supported. Each @var{action} is a supported
25669command in the @samp{vCont} packet.
86d30acc 25670@item
b8ff78ce 25671The @samp{vCont} packet is not supported.
86d30acc 25672@end table
ee2d5c50 25673
a6b151f1
DJ
25674@item vFile:@var{operation}:@var{parameter}@dots{}
25675@cindex @samp{vFile} packet
25676Perform a file operation on the target system. For details,
25677see @ref{Host I/O Packets}.
25678
68437a39
DJ
25679@item vFlashErase:@var{addr},@var{length}
25680@cindex @samp{vFlashErase} packet
25681Direct the stub to erase @var{length} bytes of flash starting at
25682@var{addr}. The region may enclose any number of flash blocks, but
25683its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
25684flash block size appearing in the memory map (@pxref{Memory Map
25685Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
25686together, and sends a @samp{vFlashDone} request after each group; the
25687stub is allowed to delay erase operation until the @samp{vFlashDone}
25688packet is received.
25689
b90a069a
SL
25690The stub must support @samp{vCont} if it reports support for
25691multiprocess extensions (@pxref{multiprocess extensions}). Note that in
25692this case @samp{vCont} actions can be specified to apply to all threads
25693in a process by using the @samp{p@var{pid}.-1} form of the
25694@var{thread-id}.
25695
68437a39
DJ
25696Reply:
25697@table @samp
25698@item OK
25699for success
25700@item E @var{NN}
25701for an error
25702@end table
25703
25704@item vFlashWrite:@var{addr}:@var{XX@dots{}}
25705@cindex @samp{vFlashWrite} packet
25706Direct the stub to write data to flash address @var{addr}. The data
25707is passed in binary form using the same encoding as for the @samp{X}
25708packet (@pxref{Binary Data}). The memory ranges specified by
25709@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
25710not overlap, and must appear in order of increasing addresses
25711(although @samp{vFlashErase} packets for higher addresses may already
25712have been received; the ordering is guaranteed only between
25713@samp{vFlashWrite} packets). If a packet writes to an address that was
25714neither erased by a preceding @samp{vFlashErase} packet nor by some other
25715target-specific method, the results are unpredictable.
25716
25717
25718Reply:
25719@table @samp
25720@item OK
25721for success
25722@item E.memtype
25723for vFlashWrite addressing non-flash memory
25724@item E @var{NN}
25725for an error
25726@end table
25727
25728@item vFlashDone
25729@cindex @samp{vFlashDone} packet
25730Indicate to the stub that flash programming operation is finished.
25731The stub is permitted to delay or batch the effects of a group of
25732@samp{vFlashErase} and @samp{vFlashWrite} packets until a
25733@samp{vFlashDone} packet is received. The contents of the affected
25734regions of flash memory are unpredictable until the @samp{vFlashDone}
25735request is completed.
25736
b90a069a
SL
25737@item vKill;@var{pid}
25738@cindex @samp{vKill} packet
25739Kill the process with the specified process ID. @var{pid} is a
25740hexadecimal integer identifying the process. This packet is used in
25741preference to @samp{k} when multiprocess protocol extensions are
25742supported; see @ref{multiprocess extensions}.
25743
25744Reply:
25745@table @samp
25746@item E @var{nn}
25747for an error
25748@item OK
25749for success
25750@end table
25751
2d717e4f
DJ
25752@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
25753@cindex @samp{vRun} packet
25754Run the program @var{filename}, passing it each @var{argument} on its
25755command line. The file and arguments are hex-encoded strings. If
25756@var{filename} is an empty string, the stub may use a default program
25757(e.g.@: the last program run). The program is created in the stopped
9b562ab8 25758state.
2d717e4f 25759
8b23ecc4
SL
25760@c FIXME: What about non-stop mode?
25761
2d717e4f
DJ
25762This packet is only available in extended mode (@pxref{extended mode}).
25763
25764Reply:
25765@table @samp
25766@item E @var{nn}
25767for an error
25768@item @r{Any stop packet}
25769for success (@pxref{Stop Reply Packets})
25770@end table
25771
8b23ecc4
SL
25772@item vStopped
25773@anchor{vStopped packet}
25774@cindex @samp{vStopped} packet
25775
25776In non-stop mode (@pxref{Remote Non-Stop}), acknowledge a previous stop
25777reply and prompt for the stub to report another one.
25778
25779Reply:
25780@table @samp
25781@item @r{Any stop packet}
25782if there is another unreported stop event (@pxref{Stop Reply Packets})
25783@item OK
25784if there are no unreported stop events
25785@end table
25786
b8ff78ce 25787@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 25788@anchor{X packet}
b8ff78ce
JB
25789@cindex @samp{X} packet
25790Write data to memory, where the data is transmitted in binary.
25791@var{addr} is address, @var{length} is number of bytes,
0876f84a 25792@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 25793
ee2d5c50
AC
25794Reply:
25795@table @samp
25796@item OK
25797for success
b8ff78ce 25798@item E @var{NN}
ee2d5c50
AC
25799for an error
25800@end table
25801
b8ff78ce
JB
25802@item z @var{type},@var{addr},@var{length}
25803@itemx Z @var{type},@var{addr},@var{length}
2f870471 25804@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
25805@cindex @samp{z} packet
25806@cindex @samp{Z} packets
25807Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
2f870471
AC
25808watchpoint starting at address @var{address} and covering the next
25809@var{length} bytes.
ee2d5c50 25810
2f870471
AC
25811Each breakpoint and watchpoint packet @var{type} is documented
25812separately.
25813
512217c7
AC
25814@emph{Implementation notes: A remote target shall return an empty string
25815for an unrecognized breakpoint or watchpoint packet @var{type}. A
25816remote target shall support either both or neither of a given
b8ff78ce 25817@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
25818avoid potential problems with duplicate packets, the operations should
25819be implemented in an idempotent way.}
25820
b8ff78ce
JB
25821@item z0,@var{addr},@var{length}
25822@itemx Z0,@var{addr},@var{length}
25823@cindex @samp{z0} packet
25824@cindex @samp{Z0} packet
25825Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
25826@var{addr} of size @var{length}.
2f870471
AC
25827
25828A memory breakpoint is implemented by replacing the instruction at
25829@var{addr} with a software breakpoint or trap instruction. The
b8ff78ce 25830@var{length} is used by targets that indicates the size of the
2f870471
AC
25831breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
25832@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 25833
2f870471
AC
25834@emph{Implementation note: It is possible for a target to copy or move
25835code that contains memory breakpoints (e.g., when implementing
25836overlays). The behavior of this packet, in the presence of such a
25837target, is not defined.}
c906108c 25838
ee2d5c50
AC
25839Reply:
25840@table @samp
2f870471
AC
25841@item OK
25842success
25843@item
25844not supported
b8ff78ce 25845@item E @var{NN}
ee2d5c50 25846for an error
2f870471
AC
25847@end table
25848
b8ff78ce
JB
25849@item z1,@var{addr},@var{length}
25850@itemx Z1,@var{addr},@var{length}
25851@cindex @samp{z1} packet
25852@cindex @samp{Z1} packet
25853Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
25854address @var{addr} of size @var{length}.
2f870471
AC
25855
25856A hardware breakpoint is implemented using a mechanism that is not
25857dependant on being able to modify the target's memory.
25858
25859@emph{Implementation note: A hardware breakpoint is not affected by code
25860movement.}
25861
25862Reply:
25863@table @samp
ee2d5c50 25864@item OK
2f870471
AC
25865success
25866@item
25867not supported
b8ff78ce 25868@item E @var{NN}
2f870471
AC
25869for an error
25870@end table
25871
b8ff78ce
JB
25872@item z2,@var{addr},@var{length}
25873@itemx Z2,@var{addr},@var{length}
25874@cindex @samp{z2} packet
25875@cindex @samp{Z2} packet
25876Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
2f870471
AC
25877
25878Reply:
25879@table @samp
25880@item OK
25881success
25882@item
25883not supported
b8ff78ce 25884@item E @var{NN}
2f870471
AC
25885for an error
25886@end table
25887
b8ff78ce
JB
25888@item z3,@var{addr},@var{length}
25889@itemx Z3,@var{addr},@var{length}
25890@cindex @samp{z3} packet
25891@cindex @samp{Z3} packet
25892Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
2f870471
AC
25893
25894Reply:
25895@table @samp
25896@item OK
25897success
25898@item
25899not supported
b8ff78ce 25900@item E @var{NN}
2f870471
AC
25901for an error
25902@end table
25903
b8ff78ce
JB
25904@item z4,@var{addr},@var{length}
25905@itemx Z4,@var{addr},@var{length}
25906@cindex @samp{z4} packet
25907@cindex @samp{Z4} packet
25908Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
2f870471
AC
25909
25910Reply:
25911@table @samp
25912@item OK
25913success
25914@item
25915not supported
b8ff78ce 25916@item E @var{NN}
2f870471 25917for an error
ee2d5c50
AC
25918@end table
25919
25920@end table
c906108c 25921
ee2d5c50
AC
25922@node Stop Reply Packets
25923@section Stop Reply Packets
25924@cindex stop reply packets
c906108c 25925
8b23ecc4
SL
25926The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
25927@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
25928receive any of the below as a reply. Except for @samp{?}
25929and @samp{vStopped}, that reply is only returned
b8ff78ce 25930when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
25931number} is defined by the header @file{include/gdb/signals.h} in the
25932@value{GDBN} source code.
c906108c 25933
b8ff78ce
JB
25934As in the description of request packets, we include spaces in the
25935reply templates for clarity; these are not part of the reply packet's
25936syntax. No @value{GDBN} stop reply packet uses spaces to separate its
25937components.
c906108c 25938
b8ff78ce 25939@table @samp
ee2d5c50 25940
b8ff78ce 25941@item S @var{AA}
599b237a 25942The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
25943number). This is equivalent to a @samp{T} response with no
25944@var{n}:@var{r} pairs.
c906108c 25945
b8ff78ce
JB
25946@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
25947@cindex @samp{T} packet reply
599b237a 25948The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
25949number). This is equivalent to an @samp{S} response, except that the
25950@samp{@var{n}:@var{r}} pairs can carry values of important registers
25951and other information directly in the stop reply packet, reducing
25952round-trip latency. Single-step and breakpoint traps are reported
25953this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
25954
25955@itemize @bullet
b8ff78ce 25956@item
599b237a 25957If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
25958corresponding @var{r} gives that register's value. @var{r} is a
25959series of bytes in target byte order, with each byte given by a
25960two-digit hex number.
cfa9d6d9 25961
b8ff78ce 25962@item
b90a069a
SL
25963If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
25964the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 25965
b8ff78ce 25966@item
cfa9d6d9
DJ
25967If @var{n} is a recognized @dfn{stop reason}, it describes a more
25968specific event that stopped the target. The currently defined stop
25969reasons are listed below. @var{aa} should be @samp{05}, the trap
25970signal. At most one stop reason should be present.
25971
b8ff78ce
JB
25972@item
25973Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
25974and go on to the next; this allows us to extend the protocol in the
25975future.
cfa9d6d9
DJ
25976@end itemize
25977
25978The currently defined stop reasons are:
25979
25980@table @samp
25981@item watch
25982@itemx rwatch
25983@itemx awatch
25984The packet indicates a watchpoint hit, and @var{r} is the data address, in
25985hex.
25986
25987@cindex shared library events, remote reply
25988@item library
25989The packet indicates that the loaded libraries have changed.
25990@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
25991list of loaded libraries. @var{r} is ignored.
bacec72f
MS
25992
25993@cindex replay log events, remote reply
25994@item replaylog
25995The packet indicates that the target cannot continue replaying
25996logged execution events, because it has reached the end (or the
25997beginning when executing backward) of the log. The value of @var{r}
25998will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
25999for more information.
26000
26001
cfa9d6d9 26002@end table
ee2d5c50 26003
b8ff78ce 26004@item W @var{AA}
b90a069a 26005@itemx W @var{AA} ; process:@var{pid}
8e04817f 26006The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
26007applicable to certain targets.
26008
b90a069a
SL
26009The second form of the response, including the process ID of the exited
26010process, can be used only when @value{GDBN} has reported support for
26011multiprocess protocol extensions; see @ref{multiprocess extensions}.
26012The @var{pid} is formatted as a big-endian hex string.
26013
b8ff78ce 26014@item X @var{AA}
b90a069a 26015@itemx X @var{AA} ; process:@var{pid}
8e04817f 26016The process terminated with signal @var{AA}.
c906108c 26017
b90a069a
SL
26018The second form of the response, including the process ID of the
26019terminated process, can be used only when @value{GDBN} has reported
26020support for multiprocess protocol extensions; see @ref{multiprocess
26021extensions}. The @var{pid} is formatted as a big-endian hex string.
26022
b8ff78ce
JB
26023@item O @var{XX}@dots{}
26024@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
26025written as the program's console output. This can happen at any time
26026while the program is running and the debugger should continue to wait
8b23ecc4 26027for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 26028
b8ff78ce 26029@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
26030@var{call-id} is the identifier which says which host system call should
26031be called. This is just the name of the function. Translation into the
26032correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 26033@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
26034system calls.
26035
b8ff78ce
JB
26036@samp{@var{parameter}@dots{}} is a list of parameters as defined for
26037this very system call.
0ce1b118 26038
b8ff78ce
JB
26039The target replies with this packet when it expects @value{GDBN} to
26040call a host system call on behalf of the target. @value{GDBN} replies
26041with an appropriate @samp{F} packet and keeps up waiting for the next
26042reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
26043or @samp{s} action is expected to be continued. @xref{File-I/O Remote
26044Protocol Extension}, for more details.
0ce1b118 26045
ee2d5c50
AC
26046@end table
26047
26048@node General Query Packets
26049@section General Query Packets
9c16f35a 26050@cindex remote query requests
c906108c 26051
5f3bebba
JB
26052Packets starting with @samp{q} are @dfn{general query packets};
26053packets starting with @samp{Q} are @dfn{general set packets}. General
26054query and set packets are a semi-unified form for retrieving and
26055sending information to and from the stub.
26056
26057The initial letter of a query or set packet is followed by a name
26058indicating what sort of thing the packet applies to. For example,
26059@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
26060definitions with the stub. These packet names follow some
26061conventions:
26062
26063@itemize @bullet
26064@item
26065The name must not contain commas, colons or semicolons.
26066@item
26067Most @value{GDBN} query and set packets have a leading upper case
26068letter.
26069@item
26070The names of custom vendor packets should use a company prefix, in
26071lower case, followed by a period. For example, packets designed at
26072the Acme Corporation might begin with @samp{qacme.foo} (for querying
26073foos) or @samp{Qacme.bar} (for setting bars).
26074@end itemize
26075
aa56d27a
JB
26076The name of a query or set packet should be separated from any
26077parameters by a @samp{:}; the parameters themselves should be
26078separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
26079full packet name, and check for a separator or the end of the packet,
26080in case two packet names share a common prefix. New packets should not begin
26081with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
26082packets predate these conventions, and have arguments without any terminator
26083for the packet name; we suspect they are in widespread use in places that
26084are difficult to upgrade. The @samp{qC} packet has no arguments, but some
26085existing stubs (e.g.@: RedBoot) are known to not check for the end of the
26086packet.}.
c906108c 26087
b8ff78ce
JB
26088Like the descriptions of the other packets, each description here
26089has a template showing the packet's overall syntax, followed by an
26090explanation of the packet's meaning. We include spaces in some of the
26091templates for clarity; these are not part of the packet's syntax. No
26092@value{GDBN} packet uses spaces to separate its components.
26093
5f3bebba
JB
26094Here are the currently defined query and set packets:
26095
b8ff78ce 26096@table @samp
c906108c 26097
b8ff78ce 26098@item qC
9c16f35a 26099@cindex current thread, remote request
b8ff78ce 26100@cindex @samp{qC} packet
b90a069a 26101Return the current thread ID.
ee2d5c50
AC
26102
26103Reply:
26104@table @samp
b90a069a
SL
26105@item QC @var{thread-id}
26106Where @var{thread-id} is a thread ID as documented in
26107@ref{thread-id syntax}.
b8ff78ce 26108@item @r{(anything else)}
b90a069a 26109Any other reply implies the old thread ID.
ee2d5c50
AC
26110@end table
26111
b8ff78ce 26112@item qCRC:@var{addr},@var{length}
ff2587ec 26113@cindex CRC of memory block, remote request
b8ff78ce
JB
26114@cindex @samp{qCRC} packet
26115Compute the CRC checksum of a block of memory.
ff2587ec
WZ
26116Reply:
26117@table @samp
b8ff78ce 26118@item E @var{NN}
ff2587ec 26119An error (such as memory fault)
b8ff78ce
JB
26120@item C @var{crc32}
26121The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
26122@end table
26123
b8ff78ce
JB
26124@item qfThreadInfo
26125@itemx qsThreadInfo
9c16f35a 26126@cindex list active threads, remote request
b8ff78ce
JB
26127@cindex @samp{qfThreadInfo} packet
26128@cindex @samp{qsThreadInfo} packet
b90a069a 26129Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
26130may be too many active threads to fit into one reply packet, this query
26131works iteratively: it may require more than one query/reply sequence to
26132obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
26133be the @samp{qfThreadInfo} query; subsequent queries in the
26134sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 26135
b8ff78ce 26136NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
26137
26138Reply:
26139@table @samp
b90a069a
SL
26140@item m @var{thread-id}
26141A single thread ID
26142@item m @var{thread-id},@var{thread-id}@dots{}
26143a comma-separated list of thread IDs
b8ff78ce
JB
26144@item l
26145(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
26146@end table
26147
26148In response to each query, the target will reply with a list of one or
b90a069a 26149more thread IDs, separated by commas.
e1aac25b 26150@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 26151ids (using the @samp{qs} form of the query), until the target responds
b90a069a
SL
26152with @samp{l} (lower-case el, for @dfn{last}).
26153Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
26154fields.
c906108c 26155
b8ff78ce 26156@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 26157@cindex get thread-local storage address, remote request
b8ff78ce 26158@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
26159Fetch the address associated with thread local storage specified
26160by @var{thread-id}, @var{offset}, and @var{lm}.
26161
b90a069a
SL
26162@var{thread-id} is the thread ID associated with the
26163thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
26164
26165@var{offset} is the (big endian, hex encoded) offset associated with the
26166thread local variable. (This offset is obtained from the debug
26167information associated with the variable.)
26168
db2e3e2e 26169@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
ff2587ec
WZ
26170the load module associated with the thread local storage. For example,
26171a @sc{gnu}/Linux system will pass the link map address of the shared
26172object associated with the thread local storage under consideration.
26173Other operating environments may choose to represent the load module
26174differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
26175
26176Reply:
b8ff78ce
JB
26177@table @samp
26178@item @var{XX}@dots{}
ff2587ec
WZ
26179Hex encoded (big endian) bytes representing the address of the thread
26180local storage requested.
26181
b8ff78ce
JB
26182@item E @var{nn}
26183An error occurred. @var{nn} are hex digits.
ff2587ec 26184
b8ff78ce
JB
26185@item
26186An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
26187@end table
26188
b8ff78ce 26189@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
26190Obtain thread information from RTOS. Where: @var{startflag} (one hex
26191digit) is one to indicate the first query and zero to indicate a
26192subsequent query; @var{threadcount} (two hex digits) is the maximum
26193number of threads the response packet can contain; and @var{nextthread}
26194(eight hex digits), for subsequent queries (@var{startflag} is zero), is
26195returned in the response as @var{argthread}.
ee2d5c50 26196
b8ff78ce 26197Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
26198
26199Reply:
26200@table @samp
b8ff78ce 26201@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
26202Where: @var{count} (two hex digits) is the number of threads being
26203returned; @var{done} (one hex digit) is zero to indicate more threads
26204and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 26205digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 26206is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 26207digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 26208@end table
c906108c 26209
b8ff78ce 26210@item qOffsets
9c16f35a 26211@cindex section offsets, remote request
b8ff78ce 26212@cindex @samp{qOffsets} packet
31d99776
DJ
26213Get section offsets that the target used when relocating the downloaded
26214image.
c906108c 26215
ee2d5c50
AC
26216Reply:
26217@table @samp
31d99776
DJ
26218@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
26219Relocate the @code{Text} section by @var{xxx} from its original address.
26220Relocate the @code{Data} section by @var{yyy} from its original address.
26221If the object file format provides segment information (e.g.@: @sc{elf}
26222@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
26223segments by the supplied offsets.
26224
26225@emph{Note: while a @code{Bss} offset may be included in the response,
26226@value{GDBN} ignores this and instead applies the @code{Data} offset
26227to the @code{Bss} section.}
26228
26229@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
26230Relocate the first segment of the object file, which conventionally
26231contains program code, to a starting address of @var{xxx}. If
26232@samp{DataSeg} is specified, relocate the second segment, which
26233conventionally contains modifiable data, to a starting address of
26234@var{yyy}. @value{GDBN} will report an error if the object file
26235does not contain segment information, or does not contain at least
26236as many segments as mentioned in the reply. Extra segments are
26237kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
26238@end table
26239
b90a069a 26240@item qP @var{mode} @var{thread-id}
9c16f35a 26241@cindex thread information, remote request
b8ff78ce 26242@cindex @samp{qP} packet
b90a069a
SL
26243Returns information on @var{thread-id}. Where: @var{mode} is a hex
26244encoded 32 bit mode; @var{thread-id} is a thread ID
26245(@pxref{thread-id syntax}).
ee2d5c50 26246
aa56d27a
JB
26247Don't use this packet; use the @samp{qThreadExtraInfo} query instead
26248(see below).
26249
b8ff78ce 26250Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 26251
8b23ecc4
SL
26252@item QNonStop:1
26253@item QNonStop:0
26254@cindex non-stop mode, remote request
26255@cindex @samp{QNonStop} packet
26256@anchor{QNonStop}
26257Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
26258@xref{Remote Non-Stop}, for more information.
26259
26260Reply:
26261@table @samp
26262@item OK
26263The request succeeded.
26264
26265@item E @var{nn}
26266An error occurred. @var{nn} are hex digits.
26267
26268@item
26269An empty reply indicates that @samp{QNonStop} is not supported by
26270the stub.
26271@end table
26272
26273This packet is not probed by default; the remote stub must request it,
26274by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26275Use of this packet is controlled by the @code{set non-stop} command;
26276@pxref{Non-Stop Mode}.
26277
89be2091
DJ
26278@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
26279@cindex pass signals to inferior, remote request
26280@cindex @samp{QPassSignals} packet
23181151 26281@anchor{QPassSignals}
89be2091
DJ
26282Each listed @var{signal} should be passed directly to the inferior process.
26283Signals are numbered identically to continue packets and stop replies
26284(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
26285strictly greater than the previous item. These signals do not need to stop
26286the inferior, or be reported to @value{GDBN}. All other signals should be
26287reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
26288combine; any earlier @samp{QPassSignals} list is completely replaced by the
26289new list. This packet improves performance when using @samp{handle
26290@var{signal} nostop noprint pass}.
26291
26292Reply:
26293@table @samp
26294@item OK
26295The request succeeded.
26296
26297@item E @var{nn}
26298An error occurred. @var{nn} are hex digits.
26299
26300@item
26301An empty reply indicates that @samp{QPassSignals} is not supported by
26302the stub.
26303@end table
26304
26305Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 26306command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
26307This packet is not probed by default; the remote stub must request it,
26308by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26309
b8ff78ce 26310@item qRcmd,@var{command}
ff2587ec 26311@cindex execute remote command, remote request
b8ff78ce 26312@cindex @samp{qRcmd} packet
ff2587ec 26313@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
26314execution. Invalid commands should be reported using the output
26315string. Before the final result packet, the target may also respond
26316with a number of intermediate @samp{O@var{output}} console output
26317packets. @emph{Implementors should note that providing access to a
26318stubs's interpreter may have security implications}.
fa93a9d8 26319
ff2587ec
WZ
26320Reply:
26321@table @samp
26322@item OK
26323A command response with no output.
26324@item @var{OUTPUT}
26325A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 26326@item E @var{NN}
ff2587ec 26327Indicate a badly formed request.
b8ff78ce
JB
26328@item
26329An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 26330@end table
fa93a9d8 26331
aa56d27a
JB
26332(Note that the @code{qRcmd} packet's name is separated from the
26333command by a @samp{,}, not a @samp{:}, contrary to the naming
26334conventions above. Please don't use this packet as a model for new
26335packets.)
26336
08388c79
DE
26337@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
26338@cindex searching memory, in remote debugging
26339@cindex @samp{qSearch:memory} packet
26340@anchor{qSearch memory}
26341Search @var{length} bytes at @var{address} for @var{search-pattern}.
26342@var{address} and @var{length} are encoded in hex.
26343@var{search-pattern} is a sequence of bytes, hex encoded.
26344
26345Reply:
26346@table @samp
26347@item 0
26348The pattern was not found.
26349@item 1,address
26350The pattern was found at @var{address}.
26351@item E @var{NN}
26352A badly formed request or an error was encountered while searching memory.
26353@item
26354An empty reply indicates that @samp{qSearch:memory} is not recognized.
26355@end table
26356
a6f3e723
SL
26357@item QStartNoAckMode
26358@cindex @samp{QStartNoAckMode} packet
26359@anchor{QStartNoAckMode}
26360Request that the remote stub disable the normal @samp{+}/@samp{-}
26361protocol acknowledgments (@pxref{Packet Acknowledgment}).
26362
26363Reply:
26364@table @samp
26365@item OK
26366The stub has switched to no-acknowledgment mode.
26367@value{GDBN} acknowledges this reponse,
26368but neither the stub nor @value{GDBN} shall send or expect further
26369@samp{+}/@samp{-} acknowledgments in the current connection.
26370@item
26371An empty reply indicates that the stub does not support no-acknowledgment mode.
26372@end table
26373
be2a5f71
DJ
26374@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
26375@cindex supported packets, remote query
26376@cindex features of the remote protocol
26377@cindex @samp{qSupported} packet
0876f84a 26378@anchor{qSupported}
be2a5f71
DJ
26379Tell the remote stub about features supported by @value{GDBN}, and
26380query the stub for features it supports. This packet allows
26381@value{GDBN} and the remote stub to take advantage of each others'
26382features. @samp{qSupported} also consolidates multiple feature probes
26383at startup, to improve @value{GDBN} performance---a single larger
26384packet performs better than multiple smaller probe packets on
26385high-latency links. Some features may enable behavior which must not
26386be on by default, e.g.@: because it would confuse older clients or
26387stubs. Other features may describe packets which could be
26388automatically probed for, but are not. These features must be
26389reported before @value{GDBN} will use them. This ``default
26390unsupported'' behavior is not appropriate for all packets, but it
26391helps to keep the initial connection time under control with new
26392versions of @value{GDBN} which support increasing numbers of packets.
26393
26394Reply:
26395@table @samp
26396@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
26397The stub supports or does not support each returned @var{stubfeature},
26398depending on the form of each @var{stubfeature} (see below for the
26399possible forms).
26400@item
26401An empty reply indicates that @samp{qSupported} is not recognized,
26402or that no features needed to be reported to @value{GDBN}.
26403@end table
26404
26405The allowed forms for each feature (either a @var{gdbfeature} in the
26406@samp{qSupported} packet, or a @var{stubfeature} in the response)
26407are:
26408
26409@table @samp
26410@item @var{name}=@var{value}
26411The remote protocol feature @var{name} is supported, and associated
26412with the specified @var{value}. The format of @var{value} depends
26413on the feature, but it must not include a semicolon.
26414@item @var{name}+
26415The remote protocol feature @var{name} is supported, and does not
26416need an associated value.
26417@item @var{name}-
26418The remote protocol feature @var{name} is not supported.
26419@item @var{name}?
26420The remote protocol feature @var{name} may be supported, and
26421@value{GDBN} should auto-detect support in some other way when it is
26422needed. This form will not be used for @var{gdbfeature} notifications,
26423but may be used for @var{stubfeature} responses.
26424@end table
26425
26426Whenever the stub receives a @samp{qSupported} request, the
26427supplied set of @value{GDBN} features should override any previous
26428request. This allows @value{GDBN} to put the stub in a known
26429state, even if the stub had previously been communicating with
26430a different version of @value{GDBN}.
26431
b90a069a
SL
26432The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
26433are defined:
26434
26435@table @samp
26436@item multiprocess
26437This feature indicates whether @value{GDBN} supports multiprocess
26438extensions to the remote protocol. @value{GDBN} does not use such
26439extensions unless the stub also reports that it supports them by
26440including @samp{multiprocess+} in its @samp{qSupported} reply.
26441@xref{multiprocess extensions}, for details.
26442@end table
26443
26444Stubs should ignore any unknown values for
be2a5f71
DJ
26445@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
26446packet supports receiving packets of unlimited length (earlier
b90a069a 26447versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
26448for @var{gdbfeature} may be defined in the future to let the stub take
26449advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
26450improvements in the remote protocol---the @samp{multiprocess} feature is
26451an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
26452of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
26453describes all the features it supports, and then the stub replies with
26454all the features it supports.
26455
26456Similarly, @value{GDBN} will silently ignore unrecognized stub feature
26457responses, as long as each response uses one of the standard forms.
26458
26459Some features are flags. A stub which supports a flag feature
26460should respond with a @samp{+} form response. Other features
26461require values, and the stub should respond with an @samp{=}
26462form response.
26463
26464Each feature has a default value, which @value{GDBN} will use if
26465@samp{qSupported} is not available or if the feature is not mentioned
26466in the @samp{qSupported} response. The default values are fixed; a
26467stub is free to omit any feature responses that match the defaults.
26468
26469Not all features can be probed, but for those which can, the probing
26470mechanism is useful: in some cases, a stub's internal
26471architecture may not allow the protocol layer to know some information
26472about the underlying target in advance. This is especially common in
26473stubs which may be configured for multiple targets.
26474
26475These are the currently defined stub features and their properties:
26476
cfa9d6d9 26477@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
26478@c NOTE: The first row should be @headitem, but we do not yet require
26479@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 26480@item Feature Name
be2a5f71
DJ
26481@tab Value Required
26482@tab Default
26483@tab Probe Allowed
26484
26485@item @samp{PacketSize}
26486@tab Yes
26487@tab @samp{-}
26488@tab No
26489
0876f84a
DJ
26490@item @samp{qXfer:auxv:read}
26491@tab No
26492@tab @samp{-}
26493@tab Yes
26494
23181151
DJ
26495@item @samp{qXfer:features:read}
26496@tab No
26497@tab @samp{-}
26498@tab Yes
26499
cfa9d6d9
DJ
26500@item @samp{qXfer:libraries:read}
26501@tab No
26502@tab @samp{-}
26503@tab Yes
26504
68437a39
DJ
26505@item @samp{qXfer:memory-map:read}
26506@tab No
26507@tab @samp{-}
26508@tab Yes
26509
0e7f50da
UW
26510@item @samp{qXfer:spu:read}
26511@tab No
26512@tab @samp{-}
26513@tab Yes
26514
26515@item @samp{qXfer:spu:write}
26516@tab No
26517@tab @samp{-}
26518@tab Yes
26519
8b23ecc4
SL
26520@item @samp{QNonStop}
26521@tab No
26522@tab @samp{-}
26523@tab Yes
26524
89be2091
DJ
26525@item @samp{QPassSignals}
26526@tab No
26527@tab @samp{-}
26528@tab Yes
26529
a6f3e723
SL
26530@item @samp{QStartNoAckMode}
26531@tab No
26532@tab @samp{-}
26533@tab Yes
26534
b90a069a
SL
26535@item @samp{multiprocess}
26536@tab No
26537@tab @samp{-}
26538@tab No
26539
be2a5f71
DJ
26540@end multitable
26541
26542These are the currently defined stub features, in more detail:
26543
26544@table @samp
26545@cindex packet size, remote protocol
26546@item PacketSize=@var{bytes}
26547The remote stub can accept packets up to at least @var{bytes} in
26548length. @value{GDBN} will send packets up to this size for bulk
26549transfers, and will never send larger packets. This is a limit on the
26550data characters in the packet, including the frame and checksum.
26551There is no trailing NUL byte in a remote protocol packet; if the stub
26552stores packets in a NUL-terminated format, it should allow an extra
26553byte in its buffer for the NUL. If this stub feature is not supported,
26554@value{GDBN} guesses based on the size of the @samp{g} packet response.
26555
0876f84a
DJ
26556@item qXfer:auxv:read
26557The remote stub understands the @samp{qXfer:auxv:read} packet
26558(@pxref{qXfer auxiliary vector read}).
26559
23181151
DJ
26560@item qXfer:features:read
26561The remote stub understands the @samp{qXfer:features:read} packet
26562(@pxref{qXfer target description read}).
26563
cfa9d6d9
DJ
26564@item qXfer:libraries:read
26565The remote stub understands the @samp{qXfer:libraries:read} packet
26566(@pxref{qXfer library list read}).
26567
23181151
DJ
26568@item qXfer:memory-map:read
26569The remote stub understands the @samp{qXfer:memory-map:read} packet
26570(@pxref{qXfer memory map read}).
26571
0e7f50da
UW
26572@item qXfer:spu:read
26573The remote stub understands the @samp{qXfer:spu:read} packet
26574(@pxref{qXfer spu read}).
26575
26576@item qXfer:spu:write
26577The remote stub understands the @samp{qXfer:spu:write} packet
26578(@pxref{qXfer spu write}).
26579
8b23ecc4
SL
26580@item QNonStop
26581The remote stub understands the @samp{QNonStop} packet
26582(@pxref{QNonStop}).
26583
23181151
DJ
26584@item QPassSignals
26585The remote stub understands the @samp{QPassSignals} packet
26586(@pxref{QPassSignals}).
26587
a6f3e723
SL
26588@item QStartNoAckMode
26589The remote stub understands the @samp{QStartNoAckMode} packet and
26590prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
26591
b90a069a
SL
26592@item multiprocess
26593@anchor{multiprocess extensions}
26594@cindex multiprocess extensions, in remote protocol
26595The remote stub understands the multiprocess extensions to the remote
26596protocol syntax. The multiprocess extensions affect the syntax of
26597thread IDs in both packets and replies (@pxref{thread-id syntax}), and
26598add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
26599replies. Note that reporting this feature indicates support for the
26600syntactic extensions only, not that the stub necessarily supports
26601debugging of more than one process at a time. The stub must not use
26602multiprocess extensions in packet replies unless @value{GDBN} has also
26603indicated it supports them in its @samp{qSupported} request.
26604
07e059b5
VP
26605@item qXfer:osdata:read
26606The remote stub understands the @samp{qXfer:osdata:read} packet
26607((@pxref{qXfer osdata read}).
26608
be2a5f71
DJ
26609@end table
26610
b8ff78ce 26611@item qSymbol::
ff2587ec 26612@cindex symbol lookup, remote request
b8ff78ce 26613@cindex @samp{qSymbol} packet
ff2587ec
WZ
26614Notify the target that @value{GDBN} is prepared to serve symbol lookup
26615requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
26616
26617Reply:
ff2587ec 26618@table @samp
b8ff78ce 26619@item OK
ff2587ec 26620The target does not need to look up any (more) symbols.
b8ff78ce 26621@item qSymbol:@var{sym_name}
ff2587ec
WZ
26622The target requests the value of symbol @var{sym_name} (hex encoded).
26623@value{GDBN} may provide the value by using the
b8ff78ce
JB
26624@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
26625below.
ff2587ec 26626@end table
83761cbd 26627
b8ff78ce 26628@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
26629Set the value of @var{sym_name} to @var{sym_value}.
26630
26631@var{sym_name} (hex encoded) is the name of a symbol whose value the
26632target has previously requested.
26633
26634@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
26635@value{GDBN} cannot supply a value for @var{sym_name}, then this field
26636will be empty.
26637
26638Reply:
26639@table @samp
b8ff78ce 26640@item OK
ff2587ec 26641The target does not need to look up any (more) symbols.
b8ff78ce 26642@item qSymbol:@var{sym_name}
ff2587ec
WZ
26643The target requests the value of a new symbol @var{sym_name} (hex
26644encoded). @value{GDBN} will continue to supply the values of symbols
26645(if available), until the target ceases to request them.
fa93a9d8 26646@end table
0abb7bc7 26647
9d29849a
JB
26648@item QTDP
26649@itemx QTFrame
26650@xref{Tracepoint Packets}.
26651
b90a069a 26652@item qThreadExtraInfo,@var{thread-id}
ff2587ec 26653@cindex thread attributes info, remote request
b8ff78ce
JB
26654@cindex @samp{qThreadExtraInfo} packet
26655Obtain a printable string description of a thread's attributes from
b90a069a
SL
26656the target OS. @var{thread-id} is a thread ID;
26657see @ref{thread-id syntax}. This
b8ff78ce
JB
26658string may contain anything that the target OS thinks is interesting
26659for @value{GDBN} to tell the user about the thread. The string is
26660displayed in @value{GDBN}'s @code{info threads} display. Some
26661examples of possible thread extra info strings are @samp{Runnable}, or
26662@samp{Blocked on Mutex}.
ff2587ec
WZ
26663
26664Reply:
26665@table @samp
b8ff78ce
JB
26666@item @var{XX}@dots{}
26667Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
26668comprising the printable string containing the extra information about
26669the thread's attributes.
ff2587ec 26670@end table
814e32d7 26671
aa56d27a
JB
26672(Note that the @code{qThreadExtraInfo} packet's name is separated from
26673the command by a @samp{,}, not a @samp{:}, contrary to the naming
26674conventions above. Please don't use this packet as a model for new
26675packets.)
26676
9d29849a
JB
26677@item QTStart
26678@itemx QTStop
26679@itemx QTinit
26680@itemx QTro
26681@itemx qTStatus
26682@xref{Tracepoint Packets}.
26683
0876f84a
DJ
26684@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
26685@cindex read special object, remote request
26686@cindex @samp{qXfer} packet
68437a39 26687@anchor{qXfer read}
0876f84a
DJ
26688Read uninterpreted bytes from the target's special data area
26689identified by the keyword @var{object}. Request @var{length} bytes
26690starting at @var{offset} bytes into the data. The content and
0e7f50da 26691encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
26692additional details about what data to access.
26693
26694Here are the specific requests of this form defined so far. All
26695@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
26696formats, listed below.
26697
26698@table @samp
26699@item qXfer:auxv:read::@var{offset},@var{length}
26700@anchor{qXfer auxiliary vector read}
26701Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 26702auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
26703
26704This packet is not probed by default; the remote stub must request it,
89be2091 26705by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 26706
23181151
DJ
26707@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
26708@anchor{qXfer target description read}
26709Access the @dfn{target description}. @xref{Target Descriptions}. The
26710annex specifies which XML document to access. The main description is
26711always loaded from the @samp{target.xml} annex.
26712
26713This packet is not probed by default; the remote stub must request it,
26714by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26715
cfa9d6d9
DJ
26716@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
26717@anchor{qXfer library list read}
26718Access the target's list of loaded libraries. @xref{Library List Format}.
26719The annex part of the generic @samp{qXfer} packet must be empty
26720(@pxref{qXfer read}).
26721
26722Targets which maintain a list of libraries in the program's memory do
26723not need to implement this packet; it is designed for platforms where
26724the operating system manages the list of loaded libraries.
26725
26726This packet is not probed by default; the remote stub must request it,
26727by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26728
68437a39
DJ
26729@item qXfer:memory-map:read::@var{offset},@var{length}
26730@anchor{qXfer memory map read}
79a6e687 26731Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
26732annex part of the generic @samp{qXfer} packet must be empty
26733(@pxref{qXfer read}).
26734
0e7f50da
UW
26735This packet is not probed by default; the remote stub must request it,
26736by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26737
26738@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
26739@anchor{qXfer spu read}
26740Read contents of an @code{spufs} file on the target system. The
26741annex specifies which file to read; it must be of the form
26742@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
26743in the target process, and @var{name} identifes the @code{spufs} file
26744in that context to be accessed.
26745
68437a39 26746This packet is not probed by default; the remote stub must request it,
07e059b5
VP
26747by supplying an appropriate @samp{qSupported} response
26748(@pxref{qSupported}).
26749
26750@item qXfer:osdata:read::@var{offset},@var{length}
26751@anchor{qXfer osdata read}
26752Access the target's @dfn{operating system information}.
26753@xref{Operating System Information}.
26754
68437a39
DJ
26755@end table
26756
0876f84a
DJ
26757Reply:
26758@table @samp
26759@item m @var{data}
26760Data @var{data} (@pxref{Binary Data}) has been read from the
26761target. There may be more data at a higher address (although
26762it is permitted to return @samp{m} even for the last valid
26763block of data, as long as at least one byte of data was read).
26764@var{data} may have fewer bytes than the @var{length} in the
26765request.
26766
26767@item l @var{data}
26768Data @var{data} (@pxref{Binary Data}) has been read from the target.
26769There is no more data to be read. @var{data} may have fewer bytes
26770than the @var{length} in the request.
26771
26772@item l
26773The @var{offset} in the request is at the end of the data.
26774There is no more data to be read.
26775
26776@item E00
26777The request was malformed, or @var{annex} was invalid.
26778
26779@item E @var{nn}
26780The offset was invalid, or there was an error encountered reading the data.
26781@var{nn} is a hex-encoded @code{errno} value.
26782
26783@item
26784An empty reply indicates the @var{object} string was not recognized by
26785the stub, or that the object does not support reading.
26786@end table
26787
26788@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
26789@cindex write data into object, remote request
26790Write uninterpreted bytes into the target's special data area
26791identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 26792into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 26793(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 26794is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
26795to access.
26796
0e7f50da
UW
26797Here are the specific requests of this form defined so far. All
26798@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
26799formats, listed below.
26800
26801@table @samp
26802@item qXfer:@var{spu}:write:@var{annex}:@var{offset}:@var{data}@dots{}
26803@anchor{qXfer spu write}
26804Write @var{data} to an @code{spufs} file on the target system. The
26805annex specifies which file to write; it must be of the form
26806@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
26807in the target process, and @var{name} identifes the @code{spufs} file
26808in that context to be accessed.
26809
26810This packet is not probed by default; the remote stub must request it,
26811by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26812@end table
0876f84a
DJ
26813
26814Reply:
26815@table @samp
26816@item @var{nn}
26817@var{nn} (hex encoded) is the number of bytes written.
26818This may be fewer bytes than supplied in the request.
26819
26820@item E00
26821The request was malformed, or @var{annex} was invalid.
26822
26823@item E @var{nn}
26824The offset was invalid, or there was an error encountered writing the data.
26825@var{nn} is a hex-encoded @code{errno} value.
26826
26827@item
26828An empty reply indicates the @var{object} string was not
26829recognized by the stub, or that the object does not support writing.
26830@end table
26831
26832@item qXfer:@var{object}:@var{operation}:@dots{}
26833Requests of this form may be added in the future. When a stub does
26834not recognize the @var{object} keyword, or its support for
26835@var{object} does not recognize the @var{operation} keyword, the stub
26836must respond with an empty packet.
26837
ee2d5c50
AC
26838@end table
26839
26840@node Register Packet Format
26841@section Register Packet Format
eb12ee30 26842
b8ff78ce 26843The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
26844In the below, some thirty-two bit registers are transferred as
26845sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
26846to fill the space allocated. Register bytes are transferred in target
26847byte order. The two nibbles within a register byte are transferred
ee2d5c50 26848most-significant - least-significant.
eb12ee30 26849
ee2d5c50 26850@table @r
eb12ee30 26851
8e04817f 26852@item MIPS32
ee2d5c50 26853
599b237a 26854All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
2685532 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
26856registers; fsr; fir; fp.
eb12ee30 26857
8e04817f 26858@item MIPS64
ee2d5c50 26859
599b237a 26860All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
26861thirty-two bit registers such as @code{sr}). The ordering is the same
26862as @code{MIPS32}.
eb12ee30 26863
ee2d5c50
AC
26864@end table
26865
9d29849a
JB
26866@node Tracepoint Packets
26867@section Tracepoint Packets
26868@cindex tracepoint packets
26869@cindex packets, tracepoint
26870
26871Here we describe the packets @value{GDBN} uses to implement
26872tracepoints (@pxref{Tracepoints}).
26873
26874@table @samp
26875
26876@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
26877Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
26878is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
26879the tracepoint is disabled. @var{step} is the tracepoint's step
26880count, and @var{pass} is its pass count. If the trailing @samp{-} is
26881present, further @samp{QTDP} packets will follow to specify this
26882tracepoint's actions.
26883
26884Replies:
26885@table @samp
26886@item OK
26887The packet was understood and carried out.
26888@item
26889The packet was not recognized.
26890@end table
26891
26892@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
26893Define actions to be taken when a tracepoint is hit. @var{n} and
26894@var{addr} must be the same as in the initial @samp{QTDP} packet for
26895this tracepoint. This packet may only be sent immediately after
26896another @samp{QTDP} packet that ended with a @samp{-}. If the
26897trailing @samp{-} is present, further @samp{QTDP} packets will follow,
26898specifying more actions for this tracepoint.
26899
26900In the series of action packets for a given tracepoint, at most one
26901can have an @samp{S} before its first @var{action}. If such a packet
26902is sent, it and the following packets define ``while-stepping''
26903actions. Any prior packets define ordinary actions --- that is, those
26904taken when the tracepoint is first hit. If no action packet has an
26905@samp{S}, then all the packets in the series specify ordinary
26906tracepoint actions.
26907
26908The @samp{@var{action}@dots{}} portion of the packet is a series of
26909actions, concatenated without separators. Each action has one of the
26910following forms:
26911
26912@table @samp
26913
26914@item R @var{mask}
26915Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 26916a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
26917@var{i} should be collected. (The least significant bit is numbered
26918zero.) Note that @var{mask} may be any number of digits long; it may
26919not fit in a 32-bit word.
26920
26921@item M @var{basereg},@var{offset},@var{len}
26922Collect @var{len} bytes of memory starting at the address in register
26923number @var{basereg}, plus @var{offset}. If @var{basereg} is
26924@samp{-1}, then the range has a fixed address: @var{offset} is the
26925address of the lowest byte to collect. The @var{basereg},
599b237a 26926@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
26927values (the @samp{-1} value for @var{basereg} is a special case).
26928
26929@item X @var{len},@var{expr}
26930Evaluate @var{expr}, whose length is @var{len}, and collect memory as
26931it directs. @var{expr} is an agent expression, as described in
26932@ref{Agent Expressions}. Each byte of the expression is encoded as a
26933two-digit hex number in the packet; @var{len} is the number of bytes
26934in the expression (and thus one-half the number of hex digits in the
26935packet).
26936
26937@end table
26938
26939Any number of actions may be packed together in a single @samp{QTDP}
26940packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
26941length (400 bytes, for many stubs). There may be only one @samp{R}
26942action per tracepoint, and it must precede any @samp{M} or @samp{X}
26943actions. Any registers referred to by @samp{M} and @samp{X} actions
26944must be collected by a preceding @samp{R} action. (The
26945``while-stepping'' actions are treated as if they were attached to a
26946separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
26947
26948Replies:
26949@table @samp
26950@item OK
26951The packet was understood and carried out.
26952@item
26953The packet was not recognized.
26954@end table
26955
26956@item QTFrame:@var{n}
26957Select the @var{n}'th tracepoint frame from the buffer, and use the
26958register and memory contents recorded there to answer subsequent
26959request packets from @value{GDBN}.
26960
26961A successful reply from the stub indicates that the stub has found the
26962requested frame. The response is a series of parts, concatenated
26963without separators, describing the frame we selected. Each part has
26964one of the following forms:
26965
26966@table @samp
26967@item F @var{f}
26968The selected frame is number @var{n} in the trace frame buffer;
599b237a 26969@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
26970was no frame matching the criteria in the request packet.
26971
26972@item T @var{t}
26973The selected trace frame records a hit of tracepoint number @var{t};
599b237a 26974@var{t} is a hexadecimal number.
9d29849a
JB
26975
26976@end table
26977
26978@item QTFrame:pc:@var{addr}
26979Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
26980currently selected frame whose PC is @var{addr};
599b237a 26981@var{addr} is a hexadecimal number.
9d29849a
JB
26982
26983@item QTFrame:tdp:@var{t}
26984Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
26985currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 26986is a hexadecimal number.
9d29849a
JB
26987
26988@item QTFrame:range:@var{start}:@var{end}
26989Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
26990currently selected frame whose PC is between @var{start} (inclusive)
599b237a 26991and @var{end} (exclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
26992numbers.
26993
26994@item QTFrame:outside:@var{start}:@var{end}
26995Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
26996frame @emph{outside} the given range of addresses.
26997
26998@item QTStart
26999Begin the tracepoint experiment. Begin collecting data from tracepoint
27000hits in the trace frame buffer.
27001
27002@item QTStop
27003End the tracepoint experiment. Stop collecting trace frames.
27004
27005@item QTinit
27006Clear the table of tracepoints, and empty the trace frame buffer.
27007
27008@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
27009Establish the given ranges of memory as ``transparent''. The stub
27010will answer requests for these ranges from memory's current contents,
27011if they were not collected as part of the tracepoint hit.
27012
27013@value{GDBN} uses this to mark read-only regions of memory, like those
27014containing program code. Since these areas never change, they should
27015still have the same contents they did when the tracepoint was hit, so
27016there's no reason for the stub to refuse to provide their contents.
27017
27018@item qTStatus
27019Ask the stub if there is a trace experiment running right now.
27020
27021Replies:
27022@table @samp
27023@item T0
27024There is no trace experiment running.
27025@item T1
27026There is a trace experiment running.
27027@end table
27028
27029@end table
27030
27031
a6b151f1
DJ
27032@node Host I/O Packets
27033@section Host I/O Packets
27034@cindex Host I/O, remote protocol
27035@cindex file transfer, remote protocol
27036
27037The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
27038operations on the far side of a remote link. For example, Host I/O is
27039used to upload and download files to a remote target with its own
27040filesystem. Host I/O uses the same constant values and data structure
27041layout as the target-initiated File-I/O protocol. However, the
27042Host I/O packets are structured differently. The target-initiated
27043protocol relies on target memory to store parameters and buffers.
27044Host I/O requests are initiated by @value{GDBN}, and the
27045target's memory is not involved. @xref{File-I/O Remote Protocol
27046Extension}, for more details on the target-initiated protocol.
27047
27048The Host I/O request packets all encode a single operation along with
27049its arguments. They have this format:
27050
27051@table @samp
27052
27053@item vFile:@var{operation}: @var{parameter}@dots{}
27054@var{operation} is the name of the particular request; the target
27055should compare the entire packet name up to the second colon when checking
27056for a supported operation. The format of @var{parameter} depends on
27057the operation. Numbers are always passed in hexadecimal. Negative
27058numbers have an explicit minus sign (i.e.@: two's complement is not
27059used). Strings (e.g.@: filenames) are encoded as a series of
27060hexadecimal bytes. The last argument to a system call may be a
27061buffer of escaped binary data (@pxref{Binary Data}).
27062
27063@end table
27064
27065The valid responses to Host I/O packets are:
27066
27067@table @samp
27068
27069@item F @var{result} [, @var{errno}] [; @var{attachment}]
27070@var{result} is the integer value returned by this operation, usually
27071non-negative for success and -1 for errors. If an error has occured,
27072@var{errno} will be included in the result. @var{errno} will have a
27073value defined by the File-I/O protocol (@pxref{Errno Values}). For
27074operations which return data, @var{attachment} supplies the data as a
27075binary buffer. Binary buffers in response packets are escaped in the
27076normal way (@pxref{Binary Data}). See the individual packet
27077documentation for the interpretation of @var{result} and
27078@var{attachment}.
27079
27080@item
27081An empty response indicates that this operation is not recognized.
27082
27083@end table
27084
27085These are the supported Host I/O operations:
27086
27087@table @samp
27088@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
27089Open a file at @var{pathname} and return a file descriptor for it, or
27090return -1 if an error occurs. @var{pathname} is a string,
27091@var{flags} is an integer indicating a mask of open flags
27092(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
27093of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 27094@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
27095
27096@item vFile:close: @var{fd}
27097Close the open file corresponding to @var{fd} and return 0, or
27098-1 if an error occurs.
27099
27100@item vFile:pread: @var{fd}, @var{count}, @var{offset}
27101Read data from the open file corresponding to @var{fd}. Up to
27102@var{count} bytes will be read from the file, starting at @var{offset}
27103relative to the start of the file. The target may read fewer bytes;
27104common reasons include packet size limits and an end-of-file
27105condition. The number of bytes read is returned. Zero should only be
27106returned for a successful read at the end of the file, or if
27107@var{count} was zero.
27108
27109The data read should be returned as a binary attachment on success.
27110If zero bytes were read, the response should include an empty binary
27111attachment (i.e.@: a trailing semicolon). The return value is the
27112number of target bytes read; the binary attachment may be longer if
27113some characters were escaped.
27114
27115@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
27116Write @var{data} (a binary buffer) to the open file corresponding
27117to @var{fd}. Start the write at @var{offset} from the start of the
27118file. Unlike many @code{write} system calls, there is no
27119separate @var{count} argument; the length of @var{data} in the
27120packet is used. @samp{vFile:write} returns the number of bytes written,
27121which may be shorter than the length of @var{data}, or -1 if an
27122error occurred.
27123
27124@item vFile:unlink: @var{pathname}
27125Delete the file at @var{pathname} on the target. Return 0,
27126or -1 if an error occurs. @var{pathname} is a string.
27127
27128@end table
27129
9a6253be
KB
27130@node Interrupts
27131@section Interrupts
27132@cindex interrupts (remote protocol)
27133
27134When a program on the remote target is running, @value{GDBN} may
27135attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
27136control of which is specified via @value{GDBN}'s @samp{remotebreak}
27137setting (@pxref{set remotebreak}).
27138
27139The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
27140mechanism and may, in fact, be undefined. @value{GDBN} does not
27141currently define a @code{BREAK} mechanism for any of the network
27142interfaces except for TCP, in which case @value{GDBN} sends the
27143@code{telnet} BREAK sequence.
9a6253be
KB
27144
27145@samp{Ctrl-C}, on the other hand, is defined and implemented for all
27146transport mechanisms. It is represented by sending the single byte
27147@code{0x03} without any of the usual packet overhead described in
27148the Overview section (@pxref{Overview}). When a @code{0x03} byte is
27149transmitted as part of a packet, it is considered to be packet data
27150and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 27151(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
27152@code{0x03} as part of its packet.
27153
27154Stubs are not required to recognize these interrupt mechanisms and the
27155precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
27156implementation defined. If the target supports debugging of multiple
27157threads and/or processes, it should attempt to interrupt all
27158currently-executing threads and processes.
27159If the stub is successful at interrupting the
27160running program, it should send one of the stop
27161reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
27162of successfully stopping the program in all-stop mode, and a stop reply
27163for each stopped thread in non-stop mode.
27164Interrupts received while the
27165program is stopped are discarded.
27166
27167@node Notification Packets
27168@section Notification Packets
27169@cindex notification packets
27170@cindex packets, notification
27171
27172The @value{GDBN} remote serial protocol includes @dfn{notifications},
27173packets that require no acknowledgment. Both the GDB and the stub
27174may send notifications (although the only notifications defined at
27175present are sent by the stub). Notifications carry information
27176without incurring the round-trip latency of an acknowledgment, and so
27177are useful for low-impact communications where occasional packet loss
27178is not a problem.
27179
27180A notification packet has the form @samp{% @var{data} #
27181@var{checksum}}, where @var{data} is the content of the notification,
27182and @var{checksum} is a checksum of @var{data}, computed and formatted
27183as for ordinary @value{GDBN} packets. A notification's @var{data}
27184never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
27185receiving a notification, the recipient sends no @samp{+} or @samp{-}
27186to acknowledge the notification's receipt or to report its corruption.
27187
27188Every notification's @var{data} begins with a name, which contains no
27189colon characters, followed by a colon character.
27190
27191Recipients should silently ignore corrupted notifications and
27192notifications they do not understand. Recipients should restart
27193timeout periods on receipt of a well-formed notification, whether or
27194not they understand it.
27195
27196Senders should only send the notifications described here when this
27197protocol description specifies that they are permitted. In the
27198future, we may extend the protocol to permit existing notifications in
27199new contexts; this rule helps older senders avoid confusing newer
27200recipients.
27201
27202(Older versions of @value{GDBN} ignore bytes received until they see
27203the @samp{$} byte that begins an ordinary packet, so new stubs may
27204transmit notifications without fear of confusing older clients. There
27205are no notifications defined for @value{GDBN} to send at the moment, but we
27206assume that most older stubs would ignore them, as well.)
27207
27208The following notification packets from the stub to @value{GDBN} are
27209defined:
27210
27211@table @samp
27212@item Stop: @var{reply}
27213Report an asynchronous stop event in non-stop mode.
27214The @var{reply} has the form of a stop reply, as
27215described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
27216for information on how these notifications are acknowledged by
27217@value{GDBN}.
27218@end table
27219
27220@node Remote Non-Stop
27221@section Remote Protocol Support for Non-Stop Mode
27222
27223@value{GDBN}'s remote protocol supports non-stop debugging of
27224multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
27225supports non-stop mode, it should report that to @value{GDBN} by including
27226@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
27227
27228@value{GDBN} typically sends a @samp{QNonStop} packet only when
27229establishing a new connection with the stub. Entering non-stop mode
27230does not alter the state of any currently-running threads, but targets
27231must stop all threads in any already-attached processes when entering
27232all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
27233probe the target state after a mode change.
27234
27235In non-stop mode, when an attached process encounters an event that
27236would otherwise be reported with a stop reply, it uses the
27237asynchronous notification mechanism (@pxref{Notification Packets}) to
27238inform @value{GDBN}. In contrast to all-stop mode, where all threads
27239in all processes are stopped when a stop reply is sent, in non-stop
27240mode only the thread reporting the stop event is stopped. That is,
27241when reporting a @samp{S} or @samp{T} response to indicate completion
27242of a step operation, hitting a breakpoint, or a fault, only the
27243affected thread is stopped; any other still-running threads continue
27244to run. When reporting a @samp{W} or @samp{X} response, all running
27245threads belonging to other attached processes continue to run.
27246
27247Only one stop reply notification at a time may be pending; if
27248additional stop events occur before @value{GDBN} has acknowledged the
27249previous notification, they must be queued by the stub for later
27250synchronous transmission in response to @samp{vStopped} packets from
27251@value{GDBN}. Because the notification mechanism is unreliable,
27252the stub is permitted to resend a stop reply notification
27253if it believes @value{GDBN} may not have received it. @value{GDBN}
27254ignores additional stop reply notifications received before it has
27255finished processing a previous notification and the stub has completed
27256sending any queued stop events.
27257
27258Otherwise, @value{GDBN} must be prepared to receive a stop reply
27259notification at any time. Specifically, they may appear when
27260@value{GDBN} is not otherwise reading input from the stub, or when
27261@value{GDBN} is expecting to read a normal synchronous response or a
27262@samp{+}/@samp{-} acknowledgment to a packet it has sent.
27263Notification packets are distinct from any other communication from
27264the stub so there is no ambiguity.
27265
27266After receiving a stop reply notification, @value{GDBN} shall
27267acknowledge it by sending a @samp{vStopped} packet (@pxref{vStopped packet})
27268as a regular, synchronous request to the stub. Such acknowledgment
27269is not required to happen immediately, as @value{GDBN} is permitted to
27270send other, unrelated packets to the stub first, which the stub should
27271process normally.
27272
27273Upon receiving a @samp{vStopped} packet, if the stub has other queued
27274stop events to report to @value{GDBN}, it shall respond by sending a
27275normal stop reply response. @value{GDBN} shall then send another
27276@samp{vStopped} packet to solicit further responses; again, it is
27277permitted to send other, unrelated packets as well which the stub
27278should process normally.
27279
27280If the stub receives a @samp{vStopped} packet and there are no
27281additional stop events to report, the stub shall return an @samp{OK}
27282response. At this point, if further stop events occur, the stub shall
27283send a new stop reply notification, @value{GDBN} shall accept the
27284notification, and the process shall be repeated.
27285
27286In non-stop mode, the target shall respond to the @samp{?} packet as
27287follows. First, any incomplete stop reply notification/@samp{vStopped}
27288sequence in progress is abandoned. The target must begin a new
27289sequence reporting stop events for all stopped threads, whether or not
27290it has previously reported those events to @value{GDBN}. The first
27291stop reply is sent as a synchronous reply to the @samp{?} packet, and
27292subsequent stop replies are sent as responses to @samp{vStopped} packets
27293using the mechanism described above. The target must not send
27294asynchronous stop reply notifications until the sequence is complete.
27295If all threads are running when the target receives the @samp{?} packet,
27296or if the target is not attached to any process, it shall respond
27297@samp{OK}.
9a6253be 27298
a6f3e723
SL
27299@node Packet Acknowledgment
27300@section Packet Acknowledgment
27301
27302@cindex acknowledgment, for @value{GDBN} remote
27303@cindex packet acknowledgment, for @value{GDBN} remote
27304By default, when either the host or the target machine receives a packet,
27305the first response expected is an acknowledgment: either @samp{+} (to indicate
27306the package was received correctly) or @samp{-} (to request retransmission).
27307This mechanism allows the @value{GDBN} remote protocol to operate over
27308unreliable transport mechanisms, such as a serial line.
27309
27310In cases where the transport mechanism is itself reliable (such as a pipe or
27311TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
27312It may be desirable to disable them in that case to reduce communication
27313overhead, or for other reasons. This can be accomplished by means of the
27314@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
27315
27316When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
27317expect @samp{+}/@samp{-} protocol acknowledgments. The packet
27318and response format still includes the normal checksum, as described in
27319@ref{Overview}, but the checksum may be ignored by the receiver.
27320
27321If the stub supports @samp{QStartNoAckMode} and prefers to operate in
27322no-acknowledgment mode, it should report that to @value{GDBN}
27323by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
27324@pxref{qSupported}.
27325If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
27326disabled via the @code{set remote noack-packet off} command
27327(@pxref{Remote Configuration}),
27328@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
27329Only then may the stub actually turn off packet acknowledgments.
27330@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
27331response, which can be safely ignored by the stub.
27332
27333Note that @code{set remote noack-packet} command only affects negotiation
27334between @value{GDBN} and the stub when subsequent connections are made;
27335it does not affect the protocol acknowledgment state for any current
27336connection.
27337Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
27338new connection is established,
27339there is also no protocol request to re-enable the acknowledgments
27340for the current connection, once disabled.
27341
ee2d5c50
AC
27342@node Examples
27343@section Examples
eb12ee30 27344
8e04817f
AC
27345Example sequence of a target being re-started. Notice how the restart
27346does not get any direct output:
eb12ee30 27347
474c8240 27348@smallexample
d2c6833e
AC
27349-> @code{R00}
27350<- @code{+}
8e04817f 27351@emph{target restarts}
d2c6833e 27352-> @code{?}
8e04817f 27353<- @code{+}
d2c6833e
AC
27354<- @code{T001:1234123412341234}
27355-> @code{+}
474c8240 27356@end smallexample
eb12ee30 27357
8e04817f 27358Example sequence of a target being stepped by a single instruction:
eb12ee30 27359
474c8240 27360@smallexample
d2c6833e 27361-> @code{G1445@dots{}}
8e04817f 27362<- @code{+}
d2c6833e
AC
27363-> @code{s}
27364<- @code{+}
27365@emph{time passes}
27366<- @code{T001:1234123412341234}
8e04817f 27367-> @code{+}
d2c6833e 27368-> @code{g}
8e04817f 27369<- @code{+}
d2c6833e
AC
27370<- @code{1455@dots{}}
27371-> @code{+}
474c8240 27372@end smallexample
eb12ee30 27373
79a6e687
BW
27374@node File-I/O Remote Protocol Extension
27375@section File-I/O Remote Protocol Extension
0ce1b118
CV
27376@cindex File-I/O remote protocol extension
27377
27378@menu
27379* File-I/O Overview::
79a6e687
BW
27380* Protocol Basics::
27381* The F Request Packet::
27382* The F Reply Packet::
27383* The Ctrl-C Message::
0ce1b118 27384* Console I/O::
79a6e687 27385* List of Supported Calls::
db2e3e2e 27386* Protocol-specific Representation of Datatypes::
0ce1b118
CV
27387* Constants::
27388* File-I/O Examples::
27389@end menu
27390
27391@node File-I/O Overview
27392@subsection File-I/O Overview
27393@cindex file-i/o overview
27394
9c16f35a 27395The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 27396target to use the host's file system and console I/O to perform various
0ce1b118 27397system calls. System calls on the target system are translated into a
fc320d37
SL
27398remote protocol packet to the host system, which then performs the needed
27399actions and returns a response packet to the target system.
0ce1b118
CV
27400This simulates file system operations even on targets that lack file systems.
27401
fc320d37
SL
27402The protocol is defined to be independent of both the host and target systems.
27403It uses its own internal representation of datatypes and values. Both
0ce1b118 27404@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
27405translating the system-dependent value representations into the internal
27406protocol representations when data is transmitted.
0ce1b118 27407
fc320d37
SL
27408The communication is synchronous. A system call is possible only when
27409@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
27410or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 27411the target is stopped to allow deterministic access to the target's
fc320d37
SL
27412memory. Therefore File-I/O is not interruptible by target signals. On
27413the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 27414(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
27415
27416The target's request to perform a host system call does not finish
27417the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
27418after finishing the system call, the target returns to continuing the
27419previous activity (continue, step). No additional continue or step
27420request from @value{GDBN} is required.
27421
27422@smallexample
f7dc1244 27423(@value{GDBP}) continue
0ce1b118
CV
27424 <- target requests 'system call X'
27425 target is stopped, @value{GDBN} executes system call
3f94c067
BW
27426 -> @value{GDBN} returns result
27427 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
27428 <- target hits breakpoint and sends a Txx packet
27429@end smallexample
27430
fc320d37
SL
27431The protocol only supports I/O on the console and to regular files on
27432the host file system. Character or block special devices, pipes,
27433named pipes, sockets or any other communication method on the host
0ce1b118
CV
27434system are not supported by this protocol.
27435
8b23ecc4
SL
27436File I/O is not supported in non-stop mode.
27437
79a6e687
BW
27438@node Protocol Basics
27439@subsection Protocol Basics
0ce1b118
CV
27440@cindex protocol basics, file-i/o
27441
fc320d37
SL
27442The File-I/O protocol uses the @code{F} packet as the request as well
27443as reply packet. Since a File-I/O system call can only occur when
27444@value{GDBN} is waiting for a response from the continuing or stepping target,
27445the File-I/O request is a reply that @value{GDBN} has to expect as a result
27446of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
27447This @code{F} packet contains all information needed to allow @value{GDBN}
27448to call the appropriate host system call:
27449
27450@itemize @bullet
b383017d 27451@item
0ce1b118
CV
27452A unique identifier for the requested system call.
27453
27454@item
27455All parameters to the system call. Pointers are given as addresses
27456in the target memory address space. Pointers to strings are given as
b383017d 27457pointer/length pair. Numerical values are given as they are.
db2e3e2e 27458Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
27459
27460@end itemize
27461
fc320d37 27462At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
27463
27464@itemize @bullet
b383017d 27465@item
fc320d37
SL
27466If the parameters include pointer values to data needed as input to a
27467system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
27468standard @code{m} packet request. This additional communication has to be
27469expected by the target implementation and is handled as any other @code{m}
27470packet.
27471
27472@item
27473@value{GDBN} translates all value from protocol representation to host
27474representation as needed. Datatypes are coerced into the host types.
27475
27476@item
fc320d37 27477@value{GDBN} calls the system call.
0ce1b118
CV
27478
27479@item
27480It then coerces datatypes back to protocol representation.
27481
27482@item
fc320d37
SL
27483If the system call is expected to return data in buffer space specified
27484by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
27485target using a @code{M} or @code{X} packet. This packet has to be expected
27486by the target implementation and is handled as any other @code{M} or @code{X}
27487packet.
27488
27489@end itemize
27490
27491Eventually @value{GDBN} replies with another @code{F} packet which contains all
27492necessary information for the target to continue. This at least contains
27493
27494@itemize @bullet
27495@item
27496Return value.
27497
27498@item
27499@code{errno}, if has been changed by the system call.
27500
27501@item
27502``Ctrl-C'' flag.
27503
27504@end itemize
27505
27506After having done the needed type and value coercion, the target continues
27507the latest continue or step action.
27508
79a6e687
BW
27509@node The F Request Packet
27510@subsection The @code{F} Request Packet
0ce1b118
CV
27511@cindex file-i/o request packet
27512@cindex @code{F} request packet
27513
27514The @code{F} request packet has the following format:
27515
27516@table @samp
fc320d37 27517@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
27518
27519@var{call-id} is the identifier to indicate the host system call to be called.
27520This is just the name of the function.
27521
fc320d37
SL
27522@var{parameter@dots{}} are the parameters to the system call.
27523Parameters are hexadecimal integer values, either the actual values in case
27524of scalar datatypes, pointers to target buffer space in case of compound
27525datatypes and unspecified memory areas, or pointer/length pairs in case
27526of string parameters. These are appended to the @var{call-id} as a
27527comma-delimited list. All values are transmitted in ASCII
27528string representation, pointer/length pairs separated by a slash.
0ce1b118 27529
b383017d 27530@end table
0ce1b118 27531
fc320d37 27532
0ce1b118 27533
79a6e687
BW
27534@node The F Reply Packet
27535@subsection The @code{F} Reply Packet
0ce1b118
CV
27536@cindex file-i/o reply packet
27537@cindex @code{F} reply packet
27538
27539The @code{F} reply packet has the following format:
27540
27541@table @samp
27542
d3bdde98 27543@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
27544
27545@var{retcode} is the return code of the system call as hexadecimal value.
27546
db2e3e2e
BW
27547@var{errno} is the @code{errno} set by the call, in protocol-specific
27548representation.
0ce1b118
CV
27549This parameter can be omitted if the call was successful.
27550
fc320d37
SL
27551@var{Ctrl-C flag} is only sent if the user requested a break. In this
27552case, @var{errno} must be sent as well, even if the call was successful.
27553The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
27554
27555@smallexample
27556F0,0,C
27557@end smallexample
27558
27559@noindent
fc320d37 27560or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
27561
27562@smallexample
27563F-1,4,C
27564@end smallexample
27565
27566@noindent
db2e3e2e 27567assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
27568
27569@end table
27570
0ce1b118 27571
79a6e687
BW
27572@node The Ctrl-C Message
27573@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
27574@cindex ctrl-c message, in file-i/o protocol
27575
c8aa23ab 27576If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 27577reply packet (@pxref{The F Reply Packet}),
fc320d37 27578the target should behave as if it had
0ce1b118 27579gotten a break message. The meaning for the target is ``system call
fc320d37 27580interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 27581(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 27582packet.
fc320d37
SL
27583
27584It's important for the target to know in which
27585state the system call was interrupted. There are two possible cases:
0ce1b118
CV
27586
27587@itemize @bullet
27588@item
27589The system call hasn't been performed on the host yet.
27590
27591@item
27592The system call on the host has been finished.
27593
27594@end itemize
27595
27596These two states can be distinguished by the target by the value of the
27597returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
27598call hasn't been performed. This is equivalent to the @code{EINTR} handling
27599on POSIX systems. In any other case, the target may presume that the
fc320d37 27600system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
27601as if the break message arrived right after the system call.
27602
fc320d37 27603@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
27604yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
27605@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
27606before the user requests a break, the full action must be finished by
27607@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
27608The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
27609or the full action has been completed.
27610
27611@node Console I/O
27612@subsection Console I/O
27613@cindex console i/o as part of file-i/o
27614
d3e8051b 27615By default and if not explicitly closed by the target system, the file
0ce1b118
CV
27616descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
27617on the @value{GDBN} console is handled as any other file output operation
27618(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
27619by @value{GDBN} so that after the target read request from file descriptor
276200 all following typing is buffered until either one of the following
27621conditions is met:
27622
27623@itemize @bullet
27624@item
c8aa23ab 27625The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
27626@code{read}
27627system call is treated as finished.
27628
27629@item
7f9087cb 27630The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 27631newline.
0ce1b118
CV
27632
27633@item
c8aa23ab
EZ
27634The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
27635character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
27636
27637@end itemize
27638
fc320d37
SL
27639If the user has typed more characters than fit in the buffer given to
27640the @code{read} call, the trailing characters are buffered in @value{GDBN} until
27641either another @code{read(0, @dots{})} is requested by the target, or debugging
27642is stopped at the user's request.
0ce1b118 27643
0ce1b118 27644
79a6e687
BW
27645@node List of Supported Calls
27646@subsection List of Supported Calls
0ce1b118
CV
27647@cindex list of supported file-i/o calls
27648
27649@menu
27650* open::
27651* close::
27652* read::
27653* write::
27654* lseek::
27655* rename::
27656* unlink::
27657* stat/fstat::
27658* gettimeofday::
27659* isatty::
27660* system::
27661@end menu
27662
27663@node open
27664@unnumberedsubsubsec open
27665@cindex open, file-i/o system call
27666
fc320d37
SL
27667@table @asis
27668@item Synopsis:
0ce1b118 27669@smallexample
0ce1b118
CV
27670int open(const char *pathname, int flags);
27671int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
27672@end smallexample
27673
fc320d37
SL
27674@item Request:
27675@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
27676
0ce1b118 27677@noindent
fc320d37 27678@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
27679
27680@table @code
b383017d 27681@item O_CREAT
0ce1b118
CV
27682If the file does not exist it will be created. The host
27683rules apply as far as file ownership and time stamps
27684are concerned.
27685
b383017d 27686@item O_EXCL
fc320d37 27687When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
27688an error and open() fails.
27689
b383017d 27690@item O_TRUNC
0ce1b118 27691If the file already exists and the open mode allows
fc320d37
SL
27692writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
27693truncated to zero length.
0ce1b118 27694
b383017d 27695@item O_APPEND
0ce1b118
CV
27696The file is opened in append mode.
27697
b383017d 27698@item O_RDONLY
0ce1b118
CV
27699The file is opened for reading only.
27700
b383017d 27701@item O_WRONLY
0ce1b118
CV
27702The file is opened for writing only.
27703
b383017d 27704@item O_RDWR
0ce1b118 27705The file is opened for reading and writing.
fc320d37 27706@end table
0ce1b118
CV
27707
27708@noindent
fc320d37 27709Other bits are silently ignored.
0ce1b118 27710
0ce1b118
CV
27711
27712@noindent
fc320d37 27713@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
27714
27715@table @code
b383017d 27716@item S_IRUSR
0ce1b118
CV
27717User has read permission.
27718
b383017d 27719@item S_IWUSR
0ce1b118
CV
27720User has write permission.
27721
b383017d 27722@item S_IRGRP
0ce1b118
CV
27723Group has read permission.
27724
b383017d 27725@item S_IWGRP
0ce1b118
CV
27726Group has write permission.
27727
b383017d 27728@item S_IROTH
0ce1b118
CV
27729Others have read permission.
27730
b383017d 27731@item S_IWOTH
0ce1b118 27732Others have write permission.
fc320d37 27733@end table
0ce1b118
CV
27734
27735@noindent
fc320d37 27736Other bits are silently ignored.
0ce1b118 27737
0ce1b118 27738
fc320d37
SL
27739@item Return value:
27740@code{open} returns the new file descriptor or -1 if an error
27741occurred.
0ce1b118 27742
fc320d37 27743@item Errors:
0ce1b118
CV
27744
27745@table @code
b383017d 27746@item EEXIST
fc320d37 27747@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 27748
b383017d 27749@item EISDIR
fc320d37 27750@var{pathname} refers to a directory.
0ce1b118 27751
b383017d 27752@item EACCES
0ce1b118
CV
27753The requested access is not allowed.
27754
27755@item ENAMETOOLONG
fc320d37 27756@var{pathname} was too long.
0ce1b118 27757
b383017d 27758@item ENOENT
fc320d37 27759A directory component in @var{pathname} does not exist.
0ce1b118 27760
b383017d 27761@item ENODEV
fc320d37 27762@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 27763
b383017d 27764@item EROFS
fc320d37 27765@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
27766write access was requested.
27767
b383017d 27768@item EFAULT
fc320d37 27769@var{pathname} is an invalid pointer value.
0ce1b118 27770
b383017d 27771@item ENOSPC
0ce1b118
CV
27772No space on device to create the file.
27773
b383017d 27774@item EMFILE
0ce1b118
CV
27775The process already has the maximum number of files open.
27776
b383017d 27777@item ENFILE
0ce1b118
CV
27778The limit on the total number of files open on the system
27779has been reached.
27780
b383017d 27781@item EINTR
0ce1b118
CV
27782The call was interrupted by the user.
27783@end table
27784
fc320d37
SL
27785@end table
27786
0ce1b118
CV
27787@node close
27788@unnumberedsubsubsec close
27789@cindex close, file-i/o system call
27790
fc320d37
SL
27791@table @asis
27792@item Synopsis:
0ce1b118 27793@smallexample
0ce1b118 27794int close(int fd);
fc320d37 27795@end smallexample
0ce1b118 27796
fc320d37
SL
27797@item Request:
27798@samp{Fclose,@var{fd}}
0ce1b118 27799
fc320d37
SL
27800@item Return value:
27801@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 27802
fc320d37 27803@item Errors:
0ce1b118
CV
27804
27805@table @code
b383017d 27806@item EBADF
fc320d37 27807@var{fd} isn't a valid open file descriptor.
0ce1b118 27808
b383017d 27809@item EINTR
0ce1b118
CV
27810The call was interrupted by the user.
27811@end table
27812
fc320d37
SL
27813@end table
27814
0ce1b118
CV
27815@node read
27816@unnumberedsubsubsec read
27817@cindex read, file-i/o system call
27818
fc320d37
SL
27819@table @asis
27820@item Synopsis:
0ce1b118 27821@smallexample
0ce1b118 27822int read(int fd, void *buf, unsigned int count);
fc320d37 27823@end smallexample
0ce1b118 27824
fc320d37
SL
27825@item Request:
27826@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 27827
fc320d37 27828@item Return value:
0ce1b118
CV
27829On success, the number of bytes read is returned.
27830Zero indicates end of file. If count is zero, read
b383017d 27831returns zero as well. On error, -1 is returned.
0ce1b118 27832
fc320d37 27833@item Errors:
0ce1b118
CV
27834
27835@table @code
b383017d 27836@item EBADF
fc320d37 27837@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
27838reading.
27839
b383017d 27840@item EFAULT
fc320d37 27841@var{bufptr} is an invalid pointer value.
0ce1b118 27842
b383017d 27843@item EINTR
0ce1b118
CV
27844The call was interrupted by the user.
27845@end table
27846
fc320d37
SL
27847@end table
27848
0ce1b118
CV
27849@node write
27850@unnumberedsubsubsec write
27851@cindex write, file-i/o system call
27852
fc320d37
SL
27853@table @asis
27854@item Synopsis:
0ce1b118 27855@smallexample
0ce1b118 27856int write(int fd, const void *buf, unsigned int count);
fc320d37 27857@end smallexample
0ce1b118 27858
fc320d37
SL
27859@item Request:
27860@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 27861
fc320d37 27862@item Return value:
0ce1b118
CV
27863On success, the number of bytes written are returned.
27864Zero indicates nothing was written. On error, -1
27865is returned.
27866
fc320d37 27867@item Errors:
0ce1b118
CV
27868
27869@table @code
b383017d 27870@item EBADF
fc320d37 27871@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
27872writing.
27873
b383017d 27874@item EFAULT
fc320d37 27875@var{bufptr} is an invalid pointer value.
0ce1b118 27876
b383017d 27877@item EFBIG
0ce1b118 27878An attempt was made to write a file that exceeds the
db2e3e2e 27879host-specific maximum file size allowed.
0ce1b118 27880
b383017d 27881@item ENOSPC
0ce1b118
CV
27882No space on device to write the data.
27883
b383017d 27884@item EINTR
0ce1b118
CV
27885The call was interrupted by the user.
27886@end table
27887
fc320d37
SL
27888@end table
27889
0ce1b118
CV
27890@node lseek
27891@unnumberedsubsubsec lseek
27892@cindex lseek, file-i/o system call
27893
fc320d37
SL
27894@table @asis
27895@item Synopsis:
0ce1b118 27896@smallexample
0ce1b118 27897long lseek (int fd, long offset, int flag);
0ce1b118
CV
27898@end smallexample
27899
fc320d37
SL
27900@item Request:
27901@samp{Flseek,@var{fd},@var{offset},@var{flag}}
27902
27903@var{flag} is one of:
0ce1b118
CV
27904
27905@table @code
b383017d 27906@item SEEK_SET
fc320d37 27907The offset is set to @var{offset} bytes.
0ce1b118 27908
b383017d 27909@item SEEK_CUR
fc320d37 27910The offset is set to its current location plus @var{offset}
0ce1b118
CV
27911bytes.
27912
b383017d 27913@item SEEK_END
fc320d37 27914The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
27915bytes.
27916@end table
27917
fc320d37 27918@item Return value:
0ce1b118
CV
27919On success, the resulting unsigned offset in bytes from
27920the beginning of the file is returned. Otherwise, a
27921value of -1 is returned.
27922
fc320d37 27923@item Errors:
0ce1b118
CV
27924
27925@table @code
b383017d 27926@item EBADF
fc320d37 27927@var{fd} is not a valid open file descriptor.
0ce1b118 27928
b383017d 27929@item ESPIPE
fc320d37 27930@var{fd} is associated with the @value{GDBN} console.
0ce1b118 27931
b383017d 27932@item EINVAL
fc320d37 27933@var{flag} is not a proper value.
0ce1b118 27934
b383017d 27935@item EINTR
0ce1b118
CV
27936The call was interrupted by the user.
27937@end table
27938
fc320d37
SL
27939@end table
27940
0ce1b118
CV
27941@node rename
27942@unnumberedsubsubsec rename
27943@cindex rename, file-i/o system call
27944
fc320d37
SL
27945@table @asis
27946@item Synopsis:
0ce1b118 27947@smallexample
0ce1b118 27948int rename(const char *oldpath, const char *newpath);
fc320d37 27949@end smallexample
0ce1b118 27950
fc320d37
SL
27951@item Request:
27952@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 27953
fc320d37 27954@item Return value:
0ce1b118
CV
27955On success, zero is returned. On error, -1 is returned.
27956
fc320d37 27957@item Errors:
0ce1b118
CV
27958
27959@table @code
b383017d 27960@item EISDIR
fc320d37 27961@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
27962directory.
27963
b383017d 27964@item EEXIST
fc320d37 27965@var{newpath} is a non-empty directory.
0ce1b118 27966
b383017d 27967@item EBUSY
fc320d37 27968@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
27969process.
27970
b383017d 27971@item EINVAL
0ce1b118
CV
27972An attempt was made to make a directory a subdirectory
27973of itself.
27974
b383017d 27975@item ENOTDIR
fc320d37
SL
27976A component used as a directory in @var{oldpath} or new
27977path is not a directory. Or @var{oldpath} is a directory
27978and @var{newpath} exists but is not a directory.
0ce1b118 27979
b383017d 27980@item EFAULT
fc320d37 27981@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 27982
b383017d 27983@item EACCES
0ce1b118
CV
27984No access to the file or the path of the file.
27985
27986@item ENAMETOOLONG
b383017d 27987
fc320d37 27988@var{oldpath} or @var{newpath} was too long.
0ce1b118 27989
b383017d 27990@item ENOENT
fc320d37 27991A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 27992
b383017d 27993@item EROFS
0ce1b118
CV
27994The file is on a read-only filesystem.
27995
b383017d 27996@item ENOSPC
0ce1b118
CV
27997The device containing the file has no room for the new
27998directory entry.
27999
b383017d 28000@item EINTR
0ce1b118
CV
28001The call was interrupted by the user.
28002@end table
28003
fc320d37
SL
28004@end table
28005
0ce1b118
CV
28006@node unlink
28007@unnumberedsubsubsec unlink
28008@cindex unlink, file-i/o system call
28009
fc320d37
SL
28010@table @asis
28011@item Synopsis:
0ce1b118 28012@smallexample
0ce1b118 28013int unlink(const char *pathname);
fc320d37 28014@end smallexample
0ce1b118 28015
fc320d37
SL
28016@item Request:
28017@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 28018
fc320d37 28019@item Return value:
0ce1b118
CV
28020On success, zero is returned. On error, -1 is returned.
28021
fc320d37 28022@item Errors:
0ce1b118
CV
28023
28024@table @code
b383017d 28025@item EACCES
0ce1b118
CV
28026No access to the file or the path of the file.
28027
b383017d 28028@item EPERM
0ce1b118
CV
28029The system does not allow unlinking of directories.
28030
b383017d 28031@item EBUSY
fc320d37 28032The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
28033being used by another process.
28034
b383017d 28035@item EFAULT
fc320d37 28036@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
28037
28038@item ENAMETOOLONG
fc320d37 28039@var{pathname} was too long.
0ce1b118 28040
b383017d 28041@item ENOENT
fc320d37 28042A directory component in @var{pathname} does not exist.
0ce1b118 28043
b383017d 28044@item ENOTDIR
0ce1b118
CV
28045A component of the path is not a directory.
28046
b383017d 28047@item EROFS
0ce1b118
CV
28048The file is on a read-only filesystem.
28049
b383017d 28050@item EINTR
0ce1b118
CV
28051The call was interrupted by the user.
28052@end table
28053
fc320d37
SL
28054@end table
28055
0ce1b118
CV
28056@node stat/fstat
28057@unnumberedsubsubsec stat/fstat
28058@cindex fstat, file-i/o system call
28059@cindex stat, file-i/o system call
28060
fc320d37
SL
28061@table @asis
28062@item Synopsis:
0ce1b118 28063@smallexample
0ce1b118
CV
28064int stat(const char *pathname, struct stat *buf);
28065int fstat(int fd, struct stat *buf);
fc320d37 28066@end smallexample
0ce1b118 28067
fc320d37
SL
28068@item Request:
28069@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
28070@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 28071
fc320d37 28072@item Return value:
0ce1b118
CV
28073On success, zero is returned. On error, -1 is returned.
28074
fc320d37 28075@item Errors:
0ce1b118
CV
28076
28077@table @code
b383017d 28078@item EBADF
fc320d37 28079@var{fd} is not a valid open file.
0ce1b118 28080
b383017d 28081@item ENOENT
fc320d37 28082A directory component in @var{pathname} does not exist or the
0ce1b118
CV
28083path is an empty string.
28084
b383017d 28085@item ENOTDIR
0ce1b118
CV
28086A component of the path is not a directory.
28087
b383017d 28088@item EFAULT
fc320d37 28089@var{pathnameptr} is an invalid pointer value.
0ce1b118 28090
b383017d 28091@item EACCES
0ce1b118
CV
28092No access to the file or the path of the file.
28093
28094@item ENAMETOOLONG
fc320d37 28095@var{pathname} was too long.
0ce1b118 28096
b383017d 28097@item EINTR
0ce1b118
CV
28098The call was interrupted by the user.
28099@end table
28100
fc320d37
SL
28101@end table
28102
0ce1b118
CV
28103@node gettimeofday
28104@unnumberedsubsubsec gettimeofday
28105@cindex gettimeofday, file-i/o system call
28106
fc320d37
SL
28107@table @asis
28108@item Synopsis:
0ce1b118 28109@smallexample
0ce1b118 28110int gettimeofday(struct timeval *tv, void *tz);
fc320d37 28111@end smallexample
0ce1b118 28112
fc320d37
SL
28113@item Request:
28114@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 28115
fc320d37 28116@item Return value:
0ce1b118
CV
28117On success, 0 is returned, -1 otherwise.
28118
fc320d37 28119@item Errors:
0ce1b118
CV
28120
28121@table @code
b383017d 28122@item EINVAL
fc320d37 28123@var{tz} is a non-NULL pointer.
0ce1b118 28124
b383017d 28125@item EFAULT
fc320d37
SL
28126@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
28127@end table
28128
0ce1b118
CV
28129@end table
28130
28131@node isatty
28132@unnumberedsubsubsec isatty
28133@cindex isatty, file-i/o system call
28134
fc320d37
SL
28135@table @asis
28136@item Synopsis:
0ce1b118 28137@smallexample
0ce1b118 28138int isatty(int fd);
fc320d37 28139@end smallexample
0ce1b118 28140
fc320d37
SL
28141@item Request:
28142@samp{Fisatty,@var{fd}}
0ce1b118 28143
fc320d37
SL
28144@item Return value:
28145Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 28146
fc320d37 28147@item Errors:
0ce1b118
CV
28148
28149@table @code
b383017d 28150@item EINTR
0ce1b118
CV
28151The call was interrupted by the user.
28152@end table
28153
fc320d37
SL
28154@end table
28155
28156Note that the @code{isatty} call is treated as a special case: it returns
281571 to the target if the file descriptor is attached
28158to the @value{GDBN} console, 0 otherwise. Implementing through system calls
28159would require implementing @code{ioctl} and would be more complex than
28160needed.
28161
28162
0ce1b118
CV
28163@node system
28164@unnumberedsubsubsec system
28165@cindex system, file-i/o system call
28166
fc320d37
SL
28167@table @asis
28168@item Synopsis:
0ce1b118 28169@smallexample
0ce1b118 28170int system(const char *command);
fc320d37 28171@end smallexample
0ce1b118 28172
fc320d37
SL
28173@item Request:
28174@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 28175
fc320d37 28176@item Return value:
5600ea19
NS
28177If @var{len} is zero, the return value indicates whether a shell is
28178available. A zero return value indicates a shell is not available.
28179For non-zero @var{len}, the value returned is -1 on error and the
28180return status of the command otherwise. Only the exit status of the
28181command is returned, which is extracted from the host's @code{system}
28182return value by calling @code{WEXITSTATUS(retval)}. In case
28183@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 28184
fc320d37 28185@item Errors:
0ce1b118
CV
28186
28187@table @code
b383017d 28188@item EINTR
0ce1b118
CV
28189The call was interrupted by the user.
28190@end table
28191
fc320d37
SL
28192@end table
28193
28194@value{GDBN} takes over the full task of calling the necessary host calls
28195to perform the @code{system} call. The return value of @code{system} on
28196the host is simplified before it's returned
28197to the target. Any termination signal information from the child process
28198is discarded, and the return value consists
28199entirely of the exit status of the called command.
28200
28201Due to security concerns, the @code{system} call is by default refused
28202by @value{GDBN}. The user has to allow this call explicitly with the
28203@code{set remote system-call-allowed 1} command.
28204
28205@table @code
28206@item set remote system-call-allowed
28207@kindex set remote system-call-allowed
28208Control whether to allow the @code{system} calls in the File I/O
28209protocol for the remote target. The default is zero (disabled).
28210
28211@item show remote system-call-allowed
28212@kindex show remote system-call-allowed
28213Show whether the @code{system} calls are allowed in the File I/O
28214protocol.
28215@end table
28216
db2e3e2e
BW
28217@node Protocol-specific Representation of Datatypes
28218@subsection Protocol-specific Representation of Datatypes
28219@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
28220
28221@menu
79a6e687
BW
28222* Integral Datatypes::
28223* Pointer Values::
28224* Memory Transfer::
0ce1b118
CV
28225* struct stat::
28226* struct timeval::
28227@end menu
28228
79a6e687
BW
28229@node Integral Datatypes
28230@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
28231@cindex integral datatypes, in file-i/o protocol
28232
fc320d37
SL
28233The integral datatypes used in the system calls are @code{int},
28234@code{unsigned int}, @code{long}, @code{unsigned long},
28235@code{mode_t}, and @code{time_t}.
0ce1b118 28236
fc320d37 28237@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
28238implemented as 32 bit values in this protocol.
28239
fc320d37 28240@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 28241
0ce1b118
CV
28242@xref{Limits}, for corresponding MIN and MAX values (similar to those
28243in @file{limits.h}) to allow range checking on host and target.
28244
28245@code{time_t} datatypes are defined as seconds since the Epoch.
28246
28247All integral datatypes transferred as part of a memory read or write of a
28248structured datatype e.g.@: a @code{struct stat} have to be given in big endian
28249byte order.
28250
79a6e687
BW
28251@node Pointer Values
28252@unnumberedsubsubsec Pointer Values
0ce1b118
CV
28253@cindex pointer values, in file-i/o protocol
28254
28255Pointers to target data are transmitted as they are. An exception
28256is made for pointers to buffers for which the length isn't
28257transmitted as part of the function call, namely strings. Strings
28258are transmitted as a pointer/length pair, both as hex values, e.g.@:
28259
28260@smallexample
28261@code{1aaf/12}
28262@end smallexample
28263
28264@noindent
28265which is a pointer to data of length 18 bytes at position 0x1aaf.
28266The length is defined as the full string length in bytes, including
fc320d37
SL
28267the trailing null byte. For example, the string @code{"hello world"}
28268at address 0x123456 is transmitted as
0ce1b118
CV
28269
28270@smallexample
fc320d37 28271@code{123456/d}
0ce1b118
CV
28272@end smallexample
28273
79a6e687
BW
28274@node Memory Transfer
28275@unnumberedsubsubsec Memory Transfer
fc320d37
SL
28276@cindex memory transfer, in file-i/o protocol
28277
28278Structured data which is transferred using a memory read or write (for
db2e3e2e 28279example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
28280with all scalar multibyte datatypes being big endian. Translation to
28281this representation needs to be done both by the target before the @code{F}
28282packet is sent, and by @value{GDBN} before
28283it transfers memory to the target. Transferred pointers to structured
28284data should point to the already-coerced data at any time.
0ce1b118 28285
0ce1b118
CV
28286
28287@node struct stat
28288@unnumberedsubsubsec struct stat
28289@cindex struct stat, in file-i/o protocol
28290
fc320d37
SL
28291The buffer of type @code{struct stat} used by the target and @value{GDBN}
28292is defined as follows:
0ce1b118
CV
28293
28294@smallexample
28295struct stat @{
28296 unsigned int st_dev; /* device */
28297 unsigned int st_ino; /* inode */
28298 mode_t st_mode; /* protection */
28299 unsigned int st_nlink; /* number of hard links */
28300 unsigned int st_uid; /* user ID of owner */
28301 unsigned int st_gid; /* group ID of owner */
28302 unsigned int st_rdev; /* device type (if inode device) */
28303 unsigned long st_size; /* total size, in bytes */
28304 unsigned long st_blksize; /* blocksize for filesystem I/O */
28305 unsigned long st_blocks; /* number of blocks allocated */
28306 time_t st_atime; /* time of last access */
28307 time_t st_mtime; /* time of last modification */
28308 time_t st_ctime; /* time of last change */
28309@};
28310@end smallexample
28311
fc320d37 28312The integral datatypes conform to the definitions given in the
79a6e687 28313appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
28314structure is of size 64 bytes.
28315
28316The values of several fields have a restricted meaning and/or
28317range of values.
28318
fc320d37 28319@table @code
0ce1b118 28320
fc320d37
SL
28321@item st_dev
28322A value of 0 represents a file, 1 the console.
0ce1b118 28323
fc320d37
SL
28324@item st_ino
28325No valid meaning for the target. Transmitted unchanged.
0ce1b118 28326
fc320d37
SL
28327@item st_mode
28328Valid mode bits are described in @ref{Constants}. Any other
28329bits have currently no meaning for the target.
0ce1b118 28330
fc320d37
SL
28331@item st_uid
28332@itemx st_gid
28333@itemx st_rdev
28334No valid meaning for the target. Transmitted unchanged.
0ce1b118 28335
fc320d37
SL
28336@item st_atime
28337@itemx st_mtime
28338@itemx st_ctime
28339These values have a host and file system dependent
28340accuracy. Especially on Windows hosts, the file system may not
28341support exact timing values.
28342@end table
0ce1b118 28343
fc320d37
SL
28344The target gets a @code{struct stat} of the above representation and is
28345responsible for coercing it to the target representation before
0ce1b118
CV
28346continuing.
28347
fc320d37
SL
28348Note that due to size differences between the host, target, and protocol
28349representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
28350get truncated on the target.
28351
28352@node struct timeval
28353@unnumberedsubsubsec struct timeval
28354@cindex struct timeval, in file-i/o protocol
28355
fc320d37 28356The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
28357is defined as follows:
28358
28359@smallexample
b383017d 28360struct timeval @{
0ce1b118
CV
28361 time_t tv_sec; /* second */
28362 long tv_usec; /* microsecond */
28363@};
28364@end smallexample
28365
fc320d37 28366The integral datatypes conform to the definitions given in the
79a6e687 28367appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
28368structure is of size 8 bytes.
28369
28370@node Constants
28371@subsection Constants
28372@cindex constants, in file-i/o protocol
28373
28374The following values are used for the constants inside of the
fc320d37 28375protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
28376values before and after the call as needed.
28377
28378@menu
79a6e687
BW
28379* Open Flags::
28380* mode_t Values::
28381* Errno Values::
28382* Lseek Flags::
0ce1b118
CV
28383* Limits::
28384@end menu
28385
79a6e687
BW
28386@node Open Flags
28387@unnumberedsubsubsec Open Flags
0ce1b118
CV
28388@cindex open flags, in file-i/o protocol
28389
28390All values are given in hexadecimal representation.
28391
28392@smallexample
28393 O_RDONLY 0x0
28394 O_WRONLY 0x1
28395 O_RDWR 0x2
28396 O_APPEND 0x8
28397 O_CREAT 0x200
28398 O_TRUNC 0x400
28399 O_EXCL 0x800
28400@end smallexample
28401
79a6e687
BW
28402@node mode_t Values
28403@unnumberedsubsubsec mode_t Values
0ce1b118
CV
28404@cindex mode_t values, in file-i/o protocol
28405
28406All values are given in octal representation.
28407
28408@smallexample
28409 S_IFREG 0100000
28410 S_IFDIR 040000
28411 S_IRUSR 0400
28412 S_IWUSR 0200
28413 S_IXUSR 0100
28414 S_IRGRP 040
28415 S_IWGRP 020
28416 S_IXGRP 010
28417 S_IROTH 04
28418 S_IWOTH 02
28419 S_IXOTH 01
28420@end smallexample
28421
79a6e687
BW
28422@node Errno Values
28423@unnumberedsubsubsec Errno Values
0ce1b118
CV
28424@cindex errno values, in file-i/o protocol
28425
28426All values are given in decimal representation.
28427
28428@smallexample
28429 EPERM 1
28430 ENOENT 2
28431 EINTR 4
28432 EBADF 9
28433 EACCES 13
28434 EFAULT 14
28435 EBUSY 16
28436 EEXIST 17
28437 ENODEV 19
28438 ENOTDIR 20
28439 EISDIR 21
28440 EINVAL 22
28441 ENFILE 23
28442 EMFILE 24
28443 EFBIG 27
28444 ENOSPC 28
28445 ESPIPE 29
28446 EROFS 30
28447 ENAMETOOLONG 91
28448 EUNKNOWN 9999
28449@end smallexample
28450
fc320d37 28451 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
28452 any error value not in the list of supported error numbers.
28453
79a6e687
BW
28454@node Lseek Flags
28455@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
28456@cindex lseek flags, in file-i/o protocol
28457
28458@smallexample
28459 SEEK_SET 0
28460 SEEK_CUR 1
28461 SEEK_END 2
28462@end smallexample
28463
28464@node Limits
28465@unnumberedsubsubsec Limits
28466@cindex limits, in file-i/o protocol
28467
28468All values are given in decimal representation.
28469
28470@smallexample
28471 INT_MIN -2147483648
28472 INT_MAX 2147483647
28473 UINT_MAX 4294967295
28474 LONG_MIN -9223372036854775808
28475 LONG_MAX 9223372036854775807
28476 ULONG_MAX 18446744073709551615
28477@end smallexample
28478
28479@node File-I/O Examples
28480@subsection File-I/O Examples
28481@cindex file-i/o examples
28482
28483Example sequence of a write call, file descriptor 3, buffer is at target
28484address 0x1234, 6 bytes should be written:
28485
28486@smallexample
28487<- @code{Fwrite,3,1234,6}
28488@emph{request memory read from target}
28489-> @code{m1234,6}
28490<- XXXXXX
28491@emph{return "6 bytes written"}
28492-> @code{F6}
28493@end smallexample
28494
28495Example sequence of a read call, file descriptor 3, buffer is at target
28496address 0x1234, 6 bytes should be read:
28497
28498@smallexample
28499<- @code{Fread,3,1234,6}
28500@emph{request memory write to target}
28501-> @code{X1234,6:XXXXXX}
28502@emph{return "6 bytes read"}
28503-> @code{F6}
28504@end smallexample
28505
28506Example sequence of a read call, call fails on the host due to invalid
fc320d37 28507file descriptor (@code{EBADF}):
0ce1b118
CV
28508
28509@smallexample
28510<- @code{Fread,3,1234,6}
28511-> @code{F-1,9}
28512@end smallexample
28513
c8aa23ab 28514Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
28515host is called:
28516
28517@smallexample
28518<- @code{Fread,3,1234,6}
28519-> @code{F-1,4,C}
28520<- @code{T02}
28521@end smallexample
28522
c8aa23ab 28523Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
28524host is called:
28525
28526@smallexample
28527<- @code{Fread,3,1234,6}
28528-> @code{X1234,6:XXXXXX}
28529<- @code{T02}
28530@end smallexample
28531
cfa9d6d9
DJ
28532@node Library List Format
28533@section Library List Format
28534@cindex library list format, remote protocol
28535
28536On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
28537same process as your application to manage libraries. In this case,
28538@value{GDBN} can use the loader's symbol table and normal memory
28539operations to maintain a list of shared libraries. On other
28540platforms, the operating system manages loaded libraries.
28541@value{GDBN} can not retrieve the list of currently loaded libraries
28542through memory operations, so it uses the @samp{qXfer:libraries:read}
28543packet (@pxref{qXfer library list read}) instead. The remote stub
28544queries the target's operating system and reports which libraries
28545are loaded.
28546
28547The @samp{qXfer:libraries:read} packet returns an XML document which
28548lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
28549associated name and one or more segment or section base addresses,
28550which report where the library was loaded in memory.
28551
28552For the common case of libraries that are fully linked binaries, the
28553library should have a list of segments. If the target supports
28554dynamic linking of a relocatable object file, its library XML element
28555should instead include a list of allocated sections. The segment or
28556section bases are start addresses, not relocation offsets; they do not
28557depend on the library's link-time base addresses.
cfa9d6d9 28558
9cceb671
DJ
28559@value{GDBN} must be linked with the Expat library to support XML
28560library lists. @xref{Expat}.
28561
cfa9d6d9
DJ
28562A simple memory map, with one loaded library relocated by a single
28563offset, looks like this:
28564
28565@smallexample
28566<library-list>
28567 <library name="/lib/libc.so.6">
28568 <segment address="0x10000000"/>
28569 </library>
28570</library-list>
28571@end smallexample
28572
1fddbabb
PA
28573Another simple memory map, with one loaded library with three
28574allocated sections (.text, .data, .bss), looks like this:
28575
28576@smallexample
28577<library-list>
28578 <library name="sharedlib.o">
28579 <section address="0x10000000"/>
28580 <section address="0x20000000"/>
28581 <section address="0x30000000"/>
28582 </library>
28583</library-list>
28584@end smallexample
28585
cfa9d6d9
DJ
28586The format of a library list is described by this DTD:
28587
28588@smallexample
28589<!-- library-list: Root element with versioning -->
28590<!ELEMENT library-list (library)*>
28591<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 28592<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
28593<!ATTLIST library name CDATA #REQUIRED>
28594<!ELEMENT segment EMPTY>
28595<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
28596<!ELEMENT section EMPTY>
28597<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
28598@end smallexample
28599
1fddbabb
PA
28600In addition, segments and section descriptors cannot be mixed within a
28601single library element, and you must supply at least one segment or
28602section for each library.
28603
79a6e687
BW
28604@node Memory Map Format
28605@section Memory Map Format
68437a39
DJ
28606@cindex memory map format
28607
28608To be able to write into flash memory, @value{GDBN} needs to obtain a
28609memory map from the target. This section describes the format of the
28610memory map.
28611
28612The memory map is obtained using the @samp{qXfer:memory-map:read}
28613(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
28614lists memory regions.
28615
28616@value{GDBN} must be linked with the Expat library to support XML
28617memory maps. @xref{Expat}.
28618
28619The top-level structure of the document is shown below:
68437a39
DJ
28620
28621@smallexample
28622<?xml version="1.0"?>
28623<!DOCTYPE memory-map
28624 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
28625 "http://sourceware.org/gdb/gdb-memory-map.dtd">
28626<memory-map>
28627 region...
28628</memory-map>
28629@end smallexample
28630
28631Each region can be either:
28632
28633@itemize
28634
28635@item
28636A region of RAM starting at @var{addr} and extending for @var{length}
28637bytes from there:
28638
28639@smallexample
28640<memory type="ram" start="@var{addr}" length="@var{length}"/>
28641@end smallexample
28642
28643
28644@item
28645A region of read-only memory:
28646
28647@smallexample
28648<memory type="rom" start="@var{addr}" length="@var{length}"/>
28649@end smallexample
28650
28651
28652@item
28653A region of flash memory, with erasure blocks @var{blocksize}
28654bytes in length:
28655
28656@smallexample
28657<memory type="flash" start="@var{addr}" length="@var{length}">
28658 <property name="blocksize">@var{blocksize}</property>
28659</memory>
28660@end smallexample
28661
28662@end itemize
28663
28664Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
28665by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
28666packets to write to addresses in such ranges.
28667
28668The formal DTD for memory map format is given below:
28669
28670@smallexample
28671<!-- ................................................... -->
28672<!-- Memory Map XML DTD ................................ -->
28673<!-- File: memory-map.dtd .............................. -->
28674<!-- .................................... .............. -->
28675<!-- memory-map.dtd -->
28676<!-- memory-map: Root element with versioning -->
28677<!ELEMENT memory-map (memory | property)>
28678<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
28679<!ELEMENT memory (property)>
28680<!-- memory: Specifies a memory region,
28681 and its type, or device. -->
28682<!ATTLIST memory type CDATA #REQUIRED
28683 start CDATA #REQUIRED
28684 length CDATA #REQUIRED
28685 device CDATA #IMPLIED>
28686<!-- property: Generic attribute tag -->
28687<!ELEMENT property (#PCDATA | property)*>
28688<!ATTLIST property name CDATA #REQUIRED>
28689@end smallexample
28690
f418dd93
DJ
28691@include agentexpr.texi
28692
23181151
DJ
28693@node Target Descriptions
28694@appendix Target Descriptions
28695@cindex target descriptions
28696
28697@strong{Warning:} target descriptions are still under active development,
28698and the contents and format may change between @value{GDBN} releases.
28699The format is expected to stabilize in the future.
28700
28701One of the challenges of using @value{GDBN} to debug embedded systems
28702is that there are so many minor variants of each processor
28703architecture in use. It is common practice for vendors to start with
28704a standard processor core --- ARM, PowerPC, or MIPS, for example ---
28705and then make changes to adapt it to a particular market niche. Some
28706architectures have hundreds of variants, available from dozens of
28707vendors. This leads to a number of problems:
28708
28709@itemize @bullet
28710@item
28711With so many different customized processors, it is difficult for
28712the @value{GDBN} maintainers to keep up with the changes.
28713@item
28714Since individual variants may have short lifetimes or limited
28715audiences, it may not be worthwhile to carry information about every
28716variant in the @value{GDBN} source tree.
28717@item
28718When @value{GDBN} does support the architecture of the embedded system
28719at hand, the task of finding the correct architecture name to give the
28720@command{set architecture} command can be error-prone.
28721@end itemize
28722
28723To address these problems, the @value{GDBN} remote protocol allows a
28724target system to not only identify itself to @value{GDBN}, but to
28725actually describe its own features. This lets @value{GDBN} support
28726processor variants it has never seen before --- to the extent that the
28727descriptions are accurate, and that @value{GDBN} understands them.
28728
9cceb671
DJ
28729@value{GDBN} must be linked with the Expat library to support XML
28730target descriptions. @xref{Expat}.
123dc839 28731
23181151
DJ
28732@menu
28733* Retrieving Descriptions:: How descriptions are fetched from a target.
28734* Target Description Format:: The contents of a target description.
123dc839
DJ
28735* Predefined Target Types:: Standard types available for target
28736 descriptions.
28737* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
28738@end menu
28739
28740@node Retrieving Descriptions
28741@section Retrieving Descriptions
28742
28743Target descriptions can be read from the target automatically, or
28744specified by the user manually. The default behavior is to read the
28745description from the target. @value{GDBN} retrieves it via the remote
28746protocol using @samp{qXfer} requests (@pxref{General Query Packets,
28747qXfer}). The @var{annex} in the @samp{qXfer} packet will be
28748@samp{target.xml}. The contents of the @samp{target.xml} annex are an
28749XML document, of the form described in @ref{Target Description
28750Format}.
28751
28752Alternatively, you can specify a file to read for the target description.
28753If a file is set, the target will not be queried. The commands to
28754specify a file are:
28755
28756@table @code
28757@cindex set tdesc filename
28758@item set tdesc filename @var{path}
28759Read the target description from @var{path}.
28760
28761@cindex unset tdesc filename
28762@item unset tdesc filename
28763Do not read the XML target description from a file. @value{GDBN}
28764will use the description supplied by the current target.
28765
28766@cindex show tdesc filename
28767@item show tdesc filename
28768Show the filename to read for a target description, if any.
28769@end table
28770
28771
28772@node Target Description Format
28773@section Target Description Format
28774@cindex target descriptions, XML format
28775
28776A target description annex is an @uref{http://www.w3.org/XML/, XML}
28777document which complies with the Document Type Definition provided in
28778the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
28779means you can use generally available tools like @command{xmllint} to
28780check that your feature descriptions are well-formed and valid.
28781However, to help people unfamiliar with XML write descriptions for
28782their targets, we also describe the grammar here.
28783
123dc839
DJ
28784Target descriptions can identify the architecture of the remote target
28785and (for some architectures) provide information about custom register
28786sets. @value{GDBN} can use this information to autoconfigure for your
28787target, or to warn you if you connect to an unsupported target.
23181151
DJ
28788
28789Here is a simple target description:
28790
123dc839 28791@smallexample
1780a0ed 28792<target version="1.0">
23181151
DJ
28793 <architecture>i386:x86-64</architecture>
28794</target>
123dc839 28795@end smallexample
23181151
DJ
28796
28797@noindent
28798This minimal description only says that the target uses
28799the x86-64 architecture.
28800
123dc839
DJ
28801A target description has the following overall form, with [ ] marking
28802optional elements and @dots{} marking repeatable elements. The elements
28803are explained further below.
23181151 28804
123dc839 28805@smallexample
23181151
DJ
28806<?xml version="1.0"?>
28807<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 28808<target version="1.0">
123dc839
DJ
28809 @r{[}@var{architecture}@r{]}
28810 @r{[}@var{feature}@dots{}@r{]}
23181151 28811</target>
123dc839 28812@end smallexample
23181151
DJ
28813
28814@noindent
28815The description is generally insensitive to whitespace and line
28816breaks, under the usual common-sense rules. The XML version
28817declaration and document type declaration can generally be omitted
28818(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
28819useful for XML validation tools. The @samp{version} attribute for
28820@samp{<target>} may also be omitted, but we recommend
28821including it; if future versions of @value{GDBN} use an incompatible
28822revision of @file{gdb-target.dtd}, they will detect and report
28823the version mismatch.
23181151 28824
108546a0
DJ
28825@subsection Inclusion
28826@cindex target descriptions, inclusion
28827@cindex XInclude
28828@ifnotinfo
28829@cindex <xi:include>
28830@end ifnotinfo
28831
28832It can sometimes be valuable to split a target description up into
28833several different annexes, either for organizational purposes, or to
28834share files between different possible target descriptions. You can
28835divide a description into multiple files by replacing any element of
28836the target description with an inclusion directive of the form:
28837
123dc839 28838@smallexample
108546a0 28839<xi:include href="@var{document}"/>
123dc839 28840@end smallexample
108546a0
DJ
28841
28842@noindent
28843When @value{GDBN} encounters an element of this form, it will retrieve
28844the named XML @var{document}, and replace the inclusion directive with
28845the contents of that document. If the current description was read
28846using @samp{qXfer}, then so will be the included document;
28847@var{document} will be interpreted as the name of an annex. If the
28848current description was read from a file, @value{GDBN} will look for
28849@var{document} as a file in the same directory where it found the
28850original description.
28851
123dc839
DJ
28852@subsection Architecture
28853@cindex <architecture>
28854
28855An @samp{<architecture>} element has this form:
28856
28857@smallexample
28858 <architecture>@var{arch}</architecture>
28859@end smallexample
28860
28861@var{arch} is an architecture name from the same selection
28862accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
28863Debugging Target}).
28864
28865@subsection Features
28866@cindex <feature>
28867
28868Each @samp{<feature>} describes some logical portion of the target
28869system. Features are currently used to describe available CPU
28870registers and the types of their contents. A @samp{<feature>} element
28871has this form:
28872
28873@smallexample
28874<feature name="@var{name}">
28875 @r{[}@var{type}@dots{}@r{]}
28876 @var{reg}@dots{}
28877</feature>
28878@end smallexample
28879
28880@noindent
28881Each feature's name should be unique within the description. The name
28882of a feature does not matter unless @value{GDBN} has some special
28883knowledge of the contents of that feature; if it does, the feature
28884should have its standard name. @xref{Standard Target Features}.
28885
28886@subsection Types
28887
28888Any register's value is a collection of bits which @value{GDBN} must
28889interpret. The default interpretation is a two's complement integer,
28890but other types can be requested by name in the register description.
28891Some predefined types are provided by @value{GDBN} (@pxref{Predefined
28892Target Types}), and the description can define additional composite types.
28893
28894Each type element must have an @samp{id} attribute, which gives
28895a unique (within the containing @samp{<feature>}) name to the type.
28896Types must be defined before they are used.
28897
28898@cindex <vector>
28899Some targets offer vector registers, which can be treated as arrays
28900of scalar elements. These types are written as @samp{<vector>} elements,
28901specifying the array element type, @var{type}, and the number of elements,
28902@var{count}:
28903
28904@smallexample
28905<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
28906@end smallexample
28907
28908@cindex <union>
28909If a register's value is usefully viewed in multiple ways, define it
28910with a union type containing the useful representations. The
28911@samp{<union>} element contains one or more @samp{<field>} elements,
28912each of which has a @var{name} and a @var{type}:
28913
28914@smallexample
28915<union id="@var{id}">
28916 <field name="@var{name}" type="@var{type}"/>
28917 @dots{}
28918</union>
28919@end smallexample
28920
28921@subsection Registers
28922@cindex <reg>
28923
28924Each register is represented as an element with this form:
28925
28926@smallexample
28927<reg name="@var{name}"
28928 bitsize="@var{size}"
28929 @r{[}regnum="@var{num}"@r{]}
28930 @r{[}save-restore="@var{save-restore}"@r{]}
28931 @r{[}type="@var{type}"@r{]}
28932 @r{[}group="@var{group}"@r{]}/>
28933@end smallexample
28934
28935@noindent
28936The components are as follows:
28937
28938@table @var
28939
28940@item name
28941The register's name; it must be unique within the target description.
28942
28943@item bitsize
28944The register's size, in bits.
28945
28946@item regnum
28947The register's number. If omitted, a register's number is one greater
28948than that of the previous register (either in the current feature or in
28949a preceeding feature); the first register in the target description
28950defaults to zero. This register number is used to read or write
28951the register; e.g.@: it is used in the remote @code{p} and @code{P}
28952packets, and registers appear in the @code{g} and @code{G} packets
28953in order of increasing register number.
28954
28955@item save-restore
28956Whether the register should be preserved across inferior function
28957calls; this must be either @code{yes} or @code{no}. The default is
28958@code{yes}, which is appropriate for most registers except for
28959some system control registers; this is not related to the target's
28960ABI.
28961
28962@item type
28963The type of the register. @var{type} may be a predefined type, a type
28964defined in the current feature, or one of the special types @code{int}
28965and @code{float}. @code{int} is an integer type of the correct size
28966for @var{bitsize}, and @code{float} is a floating point type (in the
28967architecture's normal floating point format) of the correct size for
28968@var{bitsize}. The default is @code{int}.
28969
28970@item group
28971The register group to which this register belongs. @var{group} must
28972be either @code{general}, @code{float}, or @code{vector}. If no
28973@var{group} is specified, @value{GDBN} will not display the register
28974in @code{info registers}.
28975
28976@end table
28977
28978@node Predefined Target Types
28979@section Predefined Target Types
28980@cindex target descriptions, predefined types
28981
28982Type definitions in the self-description can build up composite types
28983from basic building blocks, but can not define fundamental types. Instead,
28984standard identifiers are provided by @value{GDBN} for the fundamental
28985types. The currently supported types are:
28986
28987@table @code
28988
28989@item int8
28990@itemx int16
28991@itemx int32
28992@itemx int64
7cc46491 28993@itemx int128
123dc839
DJ
28994Signed integer types holding the specified number of bits.
28995
28996@item uint8
28997@itemx uint16
28998@itemx uint32
28999@itemx uint64
7cc46491 29000@itemx uint128
123dc839
DJ
29001Unsigned integer types holding the specified number of bits.
29002
29003@item code_ptr
29004@itemx data_ptr
29005Pointers to unspecified code and data. The program counter and
29006any dedicated return address register may be marked as code
29007pointers; printing a code pointer converts it into a symbolic
29008address. The stack pointer and any dedicated address registers
29009may be marked as data pointers.
29010
6e3bbd1a
PB
29011@item ieee_single
29012Single precision IEEE floating point.
29013
29014@item ieee_double
29015Double precision IEEE floating point.
29016
123dc839
DJ
29017@item arm_fpa_ext
29018The 12-byte extended precision format used by ARM FPA registers.
29019
29020@end table
29021
29022@node Standard Target Features
29023@section Standard Target Features
29024@cindex target descriptions, standard features
29025
29026A target description must contain either no registers or all the
29027target's registers. If the description contains no registers, then
29028@value{GDBN} will assume a default register layout, selected based on
29029the architecture. If the description contains any registers, the
29030default layout will not be used; the standard registers must be
29031described in the target description, in such a way that @value{GDBN}
29032can recognize them.
29033
29034This is accomplished by giving specific names to feature elements
29035which contain standard registers. @value{GDBN} will look for features
29036with those names and verify that they contain the expected registers;
29037if any known feature is missing required registers, or if any required
29038feature is missing, @value{GDBN} will reject the target
29039description. You can add additional registers to any of the
29040standard features --- @value{GDBN} will display them just as if
29041they were added to an unrecognized feature.
29042
29043This section lists the known features and their expected contents.
29044Sample XML documents for these features are included in the
29045@value{GDBN} source tree, in the directory @file{gdb/features}.
29046
29047Names recognized by @value{GDBN} should include the name of the
29048company or organization which selected the name, and the overall
29049architecture to which the feature applies; so e.g.@: the feature
29050containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
29051
ff6f572f
DJ
29052The names of registers are not case sensitive for the purpose
29053of recognizing standard features, but @value{GDBN} will only display
29054registers using the capitalization used in the description.
29055
e9c17194
VP
29056@menu
29057* ARM Features::
1e26b4f8 29058* MIPS Features::
e9c17194 29059* M68K Features::
1e26b4f8 29060* PowerPC Features::
e9c17194
VP
29061@end menu
29062
29063
29064@node ARM Features
123dc839
DJ
29065@subsection ARM Features
29066@cindex target descriptions, ARM features
29067
29068The @samp{org.gnu.gdb.arm.core} feature is required for ARM targets.
29069It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
29070@samp{lr}, @samp{pc}, and @samp{cpsr}.
29071
29072The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
29073should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
29074
ff6f572f
DJ
29075The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
29076it should contain at least registers @samp{wR0} through @samp{wR15} and
29077@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
29078@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 29079
1e26b4f8 29080@node MIPS Features
f8b73d13
DJ
29081@subsection MIPS Features
29082@cindex target descriptions, MIPS features
29083
29084The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
29085It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
29086@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
29087on the target.
29088
29089The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
29090contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
29091registers. They may be 32-bit or 64-bit depending on the target.
29092
29093The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
29094it may be optional in a future version of @value{GDBN}. It should
29095contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
29096@samp{fir}. They may be 32-bit or 64-bit depending on the target.
29097
822b6570
DJ
29098The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
29099contain a single register, @samp{restart}, which is used by the
29100Linux kernel to control restartable syscalls.
29101
e9c17194
VP
29102@node M68K Features
29103@subsection M68K Features
29104@cindex target descriptions, M68K features
29105
29106@table @code
29107@item @samp{org.gnu.gdb.m68k.core}
29108@itemx @samp{org.gnu.gdb.coldfire.core}
29109@itemx @samp{org.gnu.gdb.fido.core}
29110One of those features must be always present.
249e1128 29111The feature that is present determines which flavor of m68k is
e9c17194
VP
29112used. The feature that is present should contain registers
29113@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
29114@samp{sp}, @samp{ps} and @samp{pc}.
29115
29116@item @samp{org.gnu.gdb.coldfire.fp}
29117This feature is optional. If present, it should contain registers
29118@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
29119@samp{fpiaddr}.
29120@end table
29121
1e26b4f8 29122@node PowerPC Features
7cc46491
DJ
29123@subsection PowerPC Features
29124@cindex target descriptions, PowerPC features
29125
29126The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
29127targets. It should contain registers @samp{r0} through @samp{r31},
29128@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
29129@samp{xer}. They may be 32-bit or 64-bit depending on the target.
29130
29131The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
29132contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
29133
29134The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
29135contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
29136and @samp{vrsave}.
29137
677c5bb1
LM
29138The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
29139contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
29140will combine these registers with the floating point registers
29141(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 29142through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
29143through @samp{vs63}, the set of vector registers for POWER7.
29144
7cc46491
DJ
29145The @samp{org.gnu.gdb.power.spe} feature is optional. It should
29146contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
29147@samp{spefscr}. SPE targets should provide 32-bit registers in
29148@samp{org.gnu.gdb.power.core} and provide the upper halves in
29149@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
29150these to present registers @samp{ev0} through @samp{ev31} to the
29151user.
29152
07e059b5
VP
29153@node Operating System Information
29154@appendix Operating System Information
29155@cindex operating system information
29156
29157@menu
29158* Process list::
29159@end menu
29160
29161Users of @value{GDBN} often wish to obtain information about the state of
29162the operating system running on the target---for example the list of
29163processes, or the list of open files. This section describes the
29164mechanism that makes it possible. This mechanism is similar to the
29165target features mechanism (@pxref{Target Descriptions}), but focuses
29166on a different aspect of target.
29167
29168Operating system information is retrived from the target via the
29169remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
29170read}). The object name in the request should be @samp{osdata}, and
29171the @var{annex} identifies the data to be fetched.
29172
29173@node Process list
29174@appendixsection Process list
29175@cindex operating system information, process list
29176
29177When requesting the process list, the @var{annex} field in the
29178@samp{qXfer} request should be @samp{processes}. The returned data is
29179an XML document. The formal syntax of this document is defined in
29180@file{gdb/features/osdata.dtd}.
29181
29182An example document is:
29183
29184@smallexample
29185<?xml version="1.0"?>
29186<!DOCTYPE target SYSTEM "osdata.dtd">
29187<osdata type="processes">
29188 <item>
29189 <column name="pid">1</column>
29190 <column name="user">root</column>
29191 <column name="command">/sbin/init</column>
29192 </item>
29193</osdata>
29194@end smallexample
29195
29196Each item should include a column whose name is @samp{pid}. The value
29197of that column should identify the process on the target. The
29198@samp{user} and @samp{command} columns are optional, and will be
29199displayed by @value{GDBN}. Target may provide additional columns,
29200which @value{GDBN} currently ignores.
29201
aab4e0ec 29202@include gpl.texi
eb12ee30 29203
2154891a 29204@raisesections
6826cf00 29205@include fdl.texi
2154891a 29206@lowersections
6826cf00 29207
6d2ebf8b 29208@node Index
c906108c
SS
29209@unnumbered Index
29210
29211@printindex cp
29212
29213@tex
29214% I think something like @colophon should be in texinfo. In the
29215% meantime:
29216\long\def\colophon{\hbox to0pt{}\vfill
29217\centerline{The body of this manual is set in}
29218\centerline{\fontname\tenrm,}
29219\centerline{with headings in {\bf\fontname\tenbf}}
29220\centerline{and examples in {\tt\fontname\tentt}.}
29221\centerline{{\it\fontname\tenit\/},}
29222\centerline{{\bf\fontname\tenbf}, and}
29223\centerline{{\sl\fontname\tensl\/}}
29224\centerline{are used for emphasis.}\vfill}
29225\page\colophon
29226% Blame: doc@cygnus.com, 1991.
29227@end tex
29228
c906108c 29229@bye
This page took 3.069858 seconds and 4 git commands to generate.