* version.cc (version_string): Bump to 1.8.
[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
077e0a52
JB
11337(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
11338(@value{GDBP}) set An_Array := (1, others => 0)
11339(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
11340(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
11341(@value{GDBP}) set A_Record := (1, "Peter", True);
11342(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
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
077e0a52
JB
11364(@value{GDBP}) set A_Rec.Len := 4
11365(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
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
077e0a52
JB
11451(@value{GDBP}) set x := y + 3
11452(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
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
077e0a52
JB
11462(@value{GDBP}) break f
11463(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
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
077e0a52 11487(@value{GDBP}) print 'max(x, y)
e07c999f
PH
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
077e0a52 11520(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
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
e07c999f
PH
11759@item
11760The GNAT compiler never generates the prefix @code{Standard} for any of
11761the standard symbols defined by the Ada language. @value{GDBN} knows about
11762this: it will strip the prefix from names when you use it, and will never
11763look for a name you have so qualified among local symbols, nor match against
11764symbols in other packages or subprograms. If you have
11765defined entities anywhere in your program other than parameters and
11766local variables whose simple names match names in @code{Standard},
11767GNAT's lack of qualification here can cause confusion. When this happens,
11768you can usually resolve the confusion
11769by qualifying the problematic names with package
11770@code{Standard} explicitly.
11771@end itemize
11772
79a6e687
BW
11773@node Unsupported Languages
11774@section Unsupported Languages
4e562065
JB
11775
11776@cindex unsupported languages
11777@cindex minimal language
11778In addition to the other fully-supported programming languages,
11779@value{GDBN} also provides a pseudo-language, called @code{minimal}.
11780It does not represent a real programming language, but provides a set
11781of capabilities close to what the C or assembly languages provide.
11782This should allow most simple operations to be performed while debugging
11783an application that uses a language currently not supported by @value{GDBN}.
11784
11785If the language is set to @code{auto}, @value{GDBN} will automatically
11786select this language if the current frame corresponds to an unsupported
11787language.
11788
6d2ebf8b 11789@node Symbols
c906108c
SS
11790@chapter Examining the Symbol Table
11791
d4f3574e 11792The commands described in this chapter allow you to inquire about the
c906108c
SS
11793symbols (names of variables, functions and types) defined in your
11794program. This information is inherent in the text of your program and
11795does not change as your program executes. @value{GDBN} finds it in your
11796program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
11797(@pxref{File Options, ,Choosing Files}), or by one of the
11798file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
11799
11800@cindex symbol names
11801@cindex names of symbols
11802@cindex quoting names
11803Occasionally, you may need to refer to symbols that contain unusual
11804characters, which @value{GDBN} ordinarily treats as word delimiters. The
11805most frequent case is in referring to static variables in other
79a6e687 11806source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
11807are recorded in object files as debugging symbols, but @value{GDBN} would
11808ordinarily parse a typical file name, like @file{foo.c}, as the three words
11809@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
11810@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
11811
474c8240 11812@smallexample
c906108c 11813p 'foo.c'::x
474c8240 11814@end smallexample
c906108c
SS
11815
11816@noindent
11817looks up the value of @code{x} in the scope of the file @file{foo.c}.
11818
11819@table @code
a8f24a35
EZ
11820@cindex case-insensitive symbol names
11821@cindex case sensitivity in symbol names
11822@kindex set case-sensitive
11823@item set case-sensitive on
11824@itemx set case-sensitive off
11825@itemx set case-sensitive auto
11826Normally, when @value{GDBN} looks up symbols, it matches their names
11827with case sensitivity determined by the current source language.
11828Occasionally, you may wish to control that. The command @code{set
11829case-sensitive} lets you do that by specifying @code{on} for
11830case-sensitive matches or @code{off} for case-insensitive ones. If
11831you specify @code{auto}, case sensitivity is reset to the default
11832suitable for the source language. The default is case-sensitive
11833matches for all languages except for Fortran, for which the default is
11834case-insensitive matches.
11835
9c16f35a
EZ
11836@kindex show case-sensitive
11837@item show case-sensitive
a8f24a35
EZ
11838This command shows the current setting of case sensitivity for symbols
11839lookups.
11840
c906108c 11841@kindex info address
b37052ae 11842@cindex address of a symbol
c906108c
SS
11843@item info address @var{symbol}
11844Describe where the data for @var{symbol} is stored. For a register
11845variable, this says which register it is kept in. For a non-register
11846local variable, this prints the stack-frame offset at which the variable
11847is always stored.
11848
11849Note the contrast with @samp{print &@var{symbol}}, which does not work
11850at all for a register variable, and for a stack local variable prints
11851the exact address of the current instantiation of the variable.
11852
3d67e040 11853@kindex info symbol
b37052ae 11854@cindex symbol from address
9c16f35a 11855@cindex closest symbol and offset for an address
3d67e040
EZ
11856@item info symbol @var{addr}
11857Print the name of a symbol which is stored at the address @var{addr}.
11858If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
11859nearest symbol and an offset from it:
11860
474c8240 11861@smallexample
3d67e040
EZ
11862(@value{GDBP}) info symbol 0x54320
11863_initialize_vx + 396 in section .text
474c8240 11864@end smallexample
3d67e040
EZ
11865
11866@noindent
11867This is the opposite of the @code{info address} command. You can use
11868it to find out the name of a variable or a function given its address.
11869
c14c28ba
PP
11870For dynamically linked executables, the name of executable or shared
11871library containing the symbol is also printed:
11872
11873@smallexample
11874(@value{GDBP}) info symbol 0x400225
11875_start + 5 in section .text of /tmp/a.out
11876(@value{GDBP}) info symbol 0x2aaaac2811cf
11877__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
11878@end smallexample
11879
c906108c 11880@kindex whatis
62f3a2ba
FF
11881@item whatis [@var{arg}]
11882Print the data type of @var{arg}, which can be either an expression or
11883a data type. With no argument, print the data type of @code{$}, the
11884last value in the value history. If @var{arg} is an expression, it is
11885not actually evaluated, and any side-effecting operations (such as
11886assignments or function calls) inside it do not take place. If
11887@var{arg} is a type name, it may be the name of a type or typedef, or
11888for C code it may have the form @samp{class @var{class-name}},
11889@samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
11890@samp{enum @var{enum-tag}}.
c906108c
SS
11891@xref{Expressions, ,Expressions}.
11892
c906108c 11893@kindex ptype
62f3a2ba
FF
11894@item ptype [@var{arg}]
11895@code{ptype} accepts the same arguments as @code{whatis}, but prints a
11896detailed description of the type, instead of just the name of the type.
11897@xref{Expressions, ,Expressions}.
c906108c
SS
11898
11899For example, for this variable declaration:
11900
474c8240 11901@smallexample
c906108c 11902struct complex @{double real; double imag;@} v;
474c8240 11903@end smallexample
c906108c
SS
11904
11905@noindent
11906the two commands give this output:
11907
474c8240 11908@smallexample
c906108c
SS
11909@group
11910(@value{GDBP}) whatis v
11911type = struct complex
11912(@value{GDBP}) ptype v
11913type = struct complex @{
11914 double real;
11915 double imag;
11916@}
11917@end group
474c8240 11918@end smallexample
c906108c
SS
11919
11920@noindent
11921As with @code{whatis}, using @code{ptype} without an argument refers to
11922the type of @code{$}, the last value in the value history.
11923
ab1adacd
EZ
11924@cindex incomplete type
11925Sometimes, programs use opaque data types or incomplete specifications
11926of complex data structure. If the debug information included in the
11927program does not allow @value{GDBN} to display a full declaration of
11928the data type, it will say @samp{<incomplete type>}. For example,
11929given these declarations:
11930
11931@smallexample
11932 struct foo;
11933 struct foo *fooptr;
11934@end smallexample
11935
11936@noindent
11937but no definition for @code{struct foo} itself, @value{GDBN} will say:
11938
11939@smallexample
ddb50cd7 11940 (@value{GDBP}) ptype foo
ab1adacd
EZ
11941 $1 = <incomplete type>
11942@end smallexample
11943
11944@noindent
11945``Incomplete type'' is C terminology for data types that are not
11946completely specified.
11947
c906108c
SS
11948@kindex info types
11949@item info types @var{regexp}
11950@itemx info types
09d4efe1
EZ
11951Print a brief description of all types whose names match the regular
11952expression @var{regexp} (or all types in your program, if you supply
11953no argument). Each complete typename is matched as though it were a
11954complete line; thus, @samp{i type value} gives information on all
11955types in your program whose names include the string @code{value}, but
11956@samp{i type ^value$} gives information only on types whose complete
11957name is @code{value}.
c906108c
SS
11958
11959This command differs from @code{ptype} in two ways: first, like
11960@code{whatis}, it does not print a detailed description; second, it
11961lists all source files where a type is defined.
11962
b37052ae
EZ
11963@kindex info scope
11964@cindex local variables
09d4efe1 11965@item info scope @var{location}
b37052ae 11966List all the variables local to a particular scope. This command
09d4efe1
EZ
11967accepts a @var{location} argument---a function name, a source line, or
11968an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
11969to the scope defined by that location. (@xref{Specify Location}, for
11970details about supported forms of @var{location}.) For example:
b37052ae
EZ
11971
11972@smallexample
11973(@value{GDBP}) @b{info scope command_line_handler}
11974Scope for command_line_handler:
11975Symbol rl is an argument at stack/frame offset 8, length 4.
11976Symbol linebuffer is in static storage at address 0x150a18, length 4.
11977Symbol linelength is in static storage at address 0x150a1c, length 4.
11978Symbol p is a local variable in register $esi, length 4.
11979Symbol p1 is a local variable in register $ebx, length 4.
11980Symbol nline is a local variable in register $edx, length 4.
11981Symbol repeat is a local variable at frame offset -8, length 4.
11982@end smallexample
11983
f5c37c66
EZ
11984@noindent
11985This command is especially useful for determining what data to collect
11986during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
11987collect}.
11988
c906108c
SS
11989@kindex info source
11990@item info source
919d772c
JB
11991Show information about the current source file---that is, the source file for
11992the function containing the current point of execution:
11993@itemize @bullet
11994@item
11995the name of the source file, and the directory containing it,
11996@item
11997the directory it was compiled in,
11998@item
11999its length, in lines,
12000@item
12001which programming language it is written in,
12002@item
12003whether the executable includes debugging information for that file, and
12004if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
12005@item
12006whether the debugging information includes information about
12007preprocessor macros.
12008@end itemize
12009
c906108c
SS
12010
12011@kindex info sources
12012@item info sources
12013Print the names of all source files in your program for which there is
12014debugging information, organized into two lists: files whose symbols
12015have already been read, and files whose symbols will be read when needed.
12016
12017@kindex info functions
12018@item info functions
12019Print the names and data types of all defined functions.
12020
12021@item info functions @var{regexp}
12022Print the names and data types of all defined functions
12023whose names contain a match for regular expression @var{regexp}.
12024Thus, @samp{info fun step} finds all functions whose names
12025include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 12026start with @code{step}. If a function name contains characters
c1468174 12027that conflict with the regular expression language (e.g.@:
1c5dfdad 12028@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
12029
12030@kindex info variables
12031@item info variables
12032Print the names and data types of all variables that are declared
6ca652b0 12033outside of functions (i.e.@: excluding local variables).
c906108c
SS
12034
12035@item info variables @var{regexp}
12036Print the names and data types of all variables (except for local
12037variables) whose names contain a match for regular expression
12038@var{regexp}.
12039
b37303ee 12040@kindex info classes
721c2651 12041@cindex Objective-C, classes and selectors
b37303ee
AF
12042@item info classes
12043@itemx info classes @var{regexp}
12044Display all Objective-C classes in your program, or
12045(with the @var{regexp} argument) all those matching a particular regular
12046expression.
12047
12048@kindex info selectors
12049@item info selectors
12050@itemx info selectors @var{regexp}
12051Display all Objective-C selectors in your program, or
12052(with the @var{regexp} argument) all those matching a particular regular
12053expression.
12054
c906108c
SS
12055@ignore
12056This was never implemented.
12057@kindex info methods
12058@item info methods
12059@itemx info methods @var{regexp}
12060The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
12061methods within C@t{++} program, or (with the @var{regexp} argument) a
12062specific set of methods found in the various C@t{++} classes. Many
12063C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
12064from the @code{ptype} command can be overwhelming and hard to use. The
12065@code{info-methods} command filters the methods, printing only those
12066which match the regular-expression @var{regexp}.
12067@end ignore
12068
c906108c
SS
12069@cindex reloading symbols
12070Some systems allow individual object files that make up your program to
7a292a7a
SS
12071be replaced without stopping and restarting your program. For example,
12072in VxWorks you can simply recompile a defective object file and keep on
12073running. If you are running on one of these systems, you can allow
12074@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
12075
12076@table @code
12077@kindex set symbol-reloading
12078@item set symbol-reloading on
12079Replace symbol definitions for the corresponding source file when an
12080object file with a particular name is seen again.
12081
12082@item set symbol-reloading off
6d2ebf8b
SS
12083Do not replace symbol definitions when encountering object files of the
12084same name more than once. This is the default state; if you are not
12085running on a system that permits automatic relinking of modules, you
12086should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
12087may discard symbols when linking large programs, that may contain
12088several modules (from different directories or libraries) with the same
12089name.
c906108c
SS
12090
12091@kindex show symbol-reloading
12092@item show symbol-reloading
12093Show the current @code{on} or @code{off} setting.
12094@end table
c906108c 12095
9c16f35a 12096@cindex opaque data types
c906108c
SS
12097@kindex set opaque-type-resolution
12098@item set opaque-type-resolution on
12099Tell @value{GDBN} to resolve opaque types. An opaque type is a type
12100declared as a pointer to a @code{struct}, @code{class}, or
12101@code{union}---for example, @code{struct MyType *}---that is used in one
12102source file although the full declaration of @code{struct MyType} is in
12103another source file. The default is on.
12104
12105A change in the setting of this subcommand will not take effect until
12106the next time symbols for a file are loaded.
12107
12108@item set opaque-type-resolution off
12109Tell @value{GDBN} not to resolve opaque types. In this case, the type
12110is printed as follows:
12111@smallexample
12112@{<no data fields>@}
12113@end smallexample
12114
12115@kindex show opaque-type-resolution
12116@item show opaque-type-resolution
12117Show whether opaque types are resolved or not.
c906108c 12118
bf250677
DE
12119@kindex set print symbol-loading
12120@cindex print messages when symbols are loaded
12121@item set print symbol-loading
12122@itemx set print symbol-loading on
12123@itemx set print symbol-loading off
12124The @code{set print symbol-loading} command allows you to enable or
12125disable printing of messages when @value{GDBN} loads symbols.
12126By default, these messages will be printed, and normally this is what
12127you want. Disabling these messages is useful when debugging applications
12128with lots of shared libraries where the quantity of output can be more
12129annoying than useful.
12130
12131@kindex show print symbol-loading
12132@item show print symbol-loading
12133Show whether messages will be printed when @value{GDBN} loads symbols.
12134
c906108c
SS
12135@kindex maint print symbols
12136@cindex symbol dump
12137@kindex maint print psymbols
12138@cindex partial symbol dump
12139@item maint print symbols @var{filename}
12140@itemx maint print psymbols @var{filename}
12141@itemx maint print msymbols @var{filename}
12142Write a dump of debugging symbol data into the file @var{filename}.
12143These commands are used to debug the @value{GDBN} symbol-reading code. Only
12144symbols with debugging data are included. If you use @samp{maint print
12145symbols}, @value{GDBN} includes all the symbols for which it has already
12146collected full details: that is, @var{filename} reflects symbols for
12147only those files whose symbols @value{GDBN} has read. You can use the
12148command @code{info sources} to find out which files these are. If you
12149use @samp{maint print psymbols} instead, the dump shows information about
12150symbols that @value{GDBN} only knows partially---that is, symbols defined in
12151files that @value{GDBN} has skimmed, but not yet read completely. Finally,
12152@samp{maint print msymbols} dumps just the minimal symbol information
12153required for each object file from which @value{GDBN} has read some symbols.
79a6e687 12154@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 12155@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 12156
5e7b2f39
JB
12157@kindex maint info symtabs
12158@kindex maint info psymtabs
44ea7b70
JB
12159@cindex listing @value{GDBN}'s internal symbol tables
12160@cindex symbol tables, listing @value{GDBN}'s internal
12161@cindex full symbol tables, listing @value{GDBN}'s internal
12162@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
12163@item maint info symtabs @r{[} @var{regexp} @r{]}
12164@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
12165
12166List the @code{struct symtab} or @code{struct partial_symtab}
12167structures whose names match @var{regexp}. If @var{regexp} is not
12168given, list them all. The output includes expressions which you can
12169copy into a @value{GDBN} debugging this one to examine a particular
12170structure in more detail. For example:
12171
12172@smallexample
5e7b2f39 12173(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
12174@{ objfile /home/gnu/build/gdb/gdb
12175 ((struct objfile *) 0x82e69d0)
b383017d 12176 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
12177 ((struct partial_symtab *) 0x8474b10)
12178 readin no
12179 fullname (null)
12180 text addresses 0x814d3c8 -- 0x8158074
12181 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
12182 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
12183 dependencies (none)
12184 @}
12185@}
5e7b2f39 12186(@value{GDBP}) maint info symtabs
44ea7b70
JB
12187(@value{GDBP})
12188@end smallexample
12189@noindent
12190We see that there is one partial symbol table whose filename contains
12191the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
12192and we see that @value{GDBN} has not read in any symtabs yet at all.
12193If we set a breakpoint on a function, that will cause @value{GDBN} to
12194read the symtab for the compilation unit containing that function:
12195
12196@smallexample
12197(@value{GDBP}) break dwarf2_psymtab_to_symtab
12198Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
12199line 1574.
5e7b2f39 12200(@value{GDBP}) maint info symtabs
b383017d 12201@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 12202 ((struct objfile *) 0x82e69d0)
b383017d 12203 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
12204 ((struct symtab *) 0x86c1f38)
12205 dirname (null)
12206 fullname (null)
12207 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 12208 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
12209 debugformat DWARF 2
12210 @}
12211@}
b383017d 12212(@value{GDBP})
44ea7b70 12213@end smallexample
c906108c
SS
12214@end table
12215
44ea7b70 12216
6d2ebf8b 12217@node Altering
c906108c
SS
12218@chapter Altering Execution
12219
12220Once you think you have found an error in your program, you might want to
12221find out for certain whether correcting the apparent error would lead to
12222correct results in the rest of the run. You can find the answer by
12223experiment, using the @value{GDBN} features for altering execution of the
12224program.
12225
12226For example, you can store new values into variables or memory
7a292a7a
SS
12227locations, give your program a signal, restart it at a different
12228address, or even return prematurely from a function.
c906108c
SS
12229
12230@menu
12231* Assignment:: Assignment to variables
12232* Jumping:: Continuing at a different address
c906108c 12233* Signaling:: Giving your program a signal
c906108c
SS
12234* Returning:: Returning from a function
12235* Calling:: Calling your program's functions
12236* Patching:: Patching your program
12237@end menu
12238
6d2ebf8b 12239@node Assignment
79a6e687 12240@section Assignment to Variables
c906108c
SS
12241
12242@cindex assignment
12243@cindex setting variables
12244To alter the value of a variable, evaluate an assignment expression.
12245@xref{Expressions, ,Expressions}. For example,
12246
474c8240 12247@smallexample
c906108c 12248print x=4
474c8240 12249@end smallexample
c906108c
SS
12250
12251@noindent
12252stores the value 4 into the variable @code{x}, and then prints the
5d161b24 12253value of the assignment expression (which is 4).
c906108c
SS
12254@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
12255information on operators in supported languages.
c906108c
SS
12256
12257@kindex set variable
12258@cindex variables, setting
12259If you are not interested in seeing the value of the assignment, use the
12260@code{set} command instead of the @code{print} command. @code{set} is
12261really the same as @code{print} except that the expression's value is
12262not printed and is not put in the value history (@pxref{Value History,
79a6e687 12263,Value History}). The expression is evaluated only for its effects.
c906108c 12264
c906108c
SS
12265If the beginning of the argument string of the @code{set} command
12266appears identical to a @code{set} subcommand, use the @code{set
12267variable} command instead of just @code{set}. This command is identical
12268to @code{set} except for its lack of subcommands. For example, if your
12269program has a variable @code{width}, you get an error if you try to set
12270a new value with just @samp{set width=13}, because @value{GDBN} has the
12271command @code{set width}:
12272
474c8240 12273@smallexample
c906108c
SS
12274(@value{GDBP}) whatis width
12275type = double
12276(@value{GDBP}) p width
12277$4 = 13
12278(@value{GDBP}) set width=47
12279Invalid syntax in expression.
474c8240 12280@end smallexample
c906108c
SS
12281
12282@noindent
12283The invalid expression, of course, is @samp{=47}. In
12284order to actually set the program's variable @code{width}, use
12285
474c8240 12286@smallexample
c906108c 12287(@value{GDBP}) set var width=47
474c8240 12288@end smallexample
53a5351d 12289
c906108c
SS
12290Because the @code{set} command has many subcommands that can conflict
12291with the names of program variables, it is a good idea to use the
12292@code{set variable} command instead of just @code{set}. For example, if
12293your program has a variable @code{g}, you run into problems if you try
12294to set a new value with just @samp{set g=4}, because @value{GDBN} has
12295the command @code{set gnutarget}, abbreviated @code{set g}:
12296
474c8240 12297@smallexample
c906108c
SS
12298@group
12299(@value{GDBP}) whatis g
12300type = double
12301(@value{GDBP}) p g
12302$1 = 1
12303(@value{GDBP}) set g=4
2df3850c 12304(@value{GDBP}) p g
c906108c
SS
12305$2 = 1
12306(@value{GDBP}) r
12307The program being debugged has been started already.
12308Start it from the beginning? (y or n) y
12309Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
12310"/home/smith/cc_progs/a.out": can't open to read symbols:
12311 Invalid bfd target.
c906108c
SS
12312(@value{GDBP}) show g
12313The current BFD target is "=4".
12314@end group
474c8240 12315@end smallexample
c906108c
SS
12316
12317@noindent
12318The program variable @code{g} did not change, and you silently set the
12319@code{gnutarget} to an invalid value. In order to set the variable
12320@code{g}, use
12321
474c8240 12322@smallexample
c906108c 12323(@value{GDBP}) set var g=4
474c8240 12324@end smallexample
c906108c
SS
12325
12326@value{GDBN} allows more implicit conversions in assignments than C; you can
12327freely store an integer value into a pointer variable or vice versa,
12328and you can convert any structure to any other structure that is the
12329same length or shorter.
12330@comment FIXME: how do structs align/pad in these conversions?
12331@comment /doc@cygnus.com 18dec1990
12332
12333To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
12334construct to generate a value of specified type at a specified address
12335(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
12336to memory location @code{0x83040} as an integer (which implies a certain size
12337and representation in memory), and
12338
474c8240 12339@smallexample
c906108c 12340set @{int@}0x83040 = 4
474c8240 12341@end smallexample
c906108c
SS
12342
12343@noindent
12344stores the value 4 into that memory location.
12345
6d2ebf8b 12346@node Jumping
79a6e687 12347@section Continuing at a Different Address
c906108c
SS
12348
12349Ordinarily, when you continue your program, you do so at the place where
12350it stopped, with the @code{continue} command. You can instead continue at
12351an address of your own choosing, with the following commands:
12352
12353@table @code
12354@kindex jump
12355@item jump @var{linespec}
2a25a5ba
EZ
12356@itemx jump @var{location}
12357Resume execution at line @var{linespec} or at address given by
12358@var{location}. Execution stops again immediately if there is a
12359breakpoint there. @xref{Specify Location}, for a description of the
12360different forms of @var{linespec} and @var{location}. It is common
12361practice to use the @code{tbreak} command in conjunction with
12362@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
12363
12364The @code{jump} command does not change the current stack frame, or
12365the stack pointer, or the contents of any memory location or any
12366register other than the program counter. If line @var{linespec} is in
12367a different function from the one currently executing, the results may
12368be bizarre if the two functions expect different patterns of arguments or
12369of local variables. For this reason, the @code{jump} command requests
12370confirmation if the specified line is not in the function currently
12371executing. However, even bizarre results are predictable if you are
12372well acquainted with the machine-language code of your program.
c906108c
SS
12373@end table
12374
c906108c 12375@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
12376On many systems, you can get much the same effect as the @code{jump}
12377command by storing a new value into the register @code{$pc}. The
12378difference is that this does not start your program running; it only
12379changes the address of where it @emph{will} run when you continue. For
12380example,
c906108c 12381
474c8240 12382@smallexample
c906108c 12383set $pc = 0x485
474c8240 12384@end smallexample
c906108c
SS
12385
12386@noindent
12387makes the next @code{continue} command or stepping command execute at
12388address @code{0x485}, rather than at the address where your program stopped.
79a6e687 12389@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
12390
12391The most common occasion to use the @code{jump} command is to back
12392up---perhaps with more breakpoints set---over a portion of a program
12393that has already executed, in order to examine its execution in more
12394detail.
12395
c906108c 12396@c @group
6d2ebf8b 12397@node Signaling
79a6e687 12398@section Giving your Program a Signal
9c16f35a 12399@cindex deliver a signal to a program
c906108c
SS
12400
12401@table @code
12402@kindex signal
12403@item signal @var{signal}
12404Resume execution where your program stopped, but immediately give it the
12405signal @var{signal}. @var{signal} can be the name or the number of a
12406signal. For example, on many systems @code{signal 2} and @code{signal
12407SIGINT} are both ways of sending an interrupt signal.
12408
12409Alternatively, if @var{signal} is zero, continue execution without
12410giving a signal. This is useful when your program stopped on account of
12411a signal and would ordinary see the signal when resumed with the
12412@code{continue} command; @samp{signal 0} causes it to resume without a
12413signal.
12414
12415@code{signal} does not repeat when you press @key{RET} a second time
12416after executing the command.
12417@end table
12418@c @end group
12419
12420Invoking the @code{signal} command is not the same as invoking the
12421@code{kill} utility from the shell. Sending a signal with @code{kill}
12422causes @value{GDBN} to decide what to do with the signal depending on
12423the signal handling tables (@pxref{Signals}). The @code{signal} command
12424passes the signal directly to your program.
12425
c906108c 12426
6d2ebf8b 12427@node Returning
79a6e687 12428@section Returning from a Function
c906108c
SS
12429
12430@table @code
12431@cindex returning from a function
12432@kindex return
12433@item return
12434@itemx return @var{expression}
12435You can cancel execution of a function call with the @code{return}
12436command. If you give an
12437@var{expression} argument, its value is used as the function's return
12438value.
12439@end table
12440
12441When you use @code{return}, @value{GDBN} discards the selected stack frame
12442(and all frames within it). You can think of this as making the
12443discarded frame return prematurely. If you wish to specify a value to
12444be returned, give that value as the argument to @code{return}.
12445
12446This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 12447Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
12448innermost remaining frame. That frame becomes selected. The
12449specified value is stored in the registers used for returning values
12450of functions.
12451
12452The @code{return} command does not resume execution; it leaves the
12453program stopped in the state that would exist if the function had just
12454returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 12455and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
12456selected stack frame returns naturally.
12457
6d2ebf8b 12458@node Calling
79a6e687 12459@section Calling Program Functions
c906108c 12460
f8568604 12461@table @code
c906108c 12462@cindex calling functions
f8568604
EZ
12463@cindex inferior functions, calling
12464@item print @var{expr}
d3e8051b 12465Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
12466@var{expr} may include calls to functions in the program being
12467debugged.
12468
c906108c 12469@kindex call
c906108c
SS
12470@item call @var{expr}
12471Evaluate the expression @var{expr} without displaying @code{void}
12472returned values.
c906108c
SS
12473
12474You can use this variant of the @code{print} command if you want to
f8568604
EZ
12475execute a function from your program that does not return anything
12476(a.k.a.@: @dfn{a void function}), but without cluttering the output
12477with @code{void} returned values that @value{GDBN} will otherwise
12478print. If the result is not void, it is printed and saved in the
12479value history.
12480@end table
12481
9c16f35a
EZ
12482It is possible for the function you call via the @code{print} or
12483@code{call} command to generate a signal (e.g., if there's a bug in
12484the function, or if you passed it incorrect arguments). What happens
12485in that case is controlled by the @code{set unwindonsignal} command.
12486
12487@table @code
12488@item set unwindonsignal
12489@kindex set unwindonsignal
12490@cindex unwind stack in called functions
12491@cindex call dummy stack unwinding
12492Set unwinding of the stack if a signal is received while in a function
12493that @value{GDBN} called in the program being debugged. If set to on,
12494@value{GDBN} unwinds the stack it created for the call and restores
12495the context to what it was before the call. If set to off (the
12496default), @value{GDBN} stops in the frame where the signal was
12497received.
12498
12499@item show unwindonsignal
12500@kindex show unwindonsignal
12501Show the current setting of stack unwinding in the functions called by
12502@value{GDBN}.
12503@end table
12504
f8568604
EZ
12505@cindex weak alias functions
12506Sometimes, a function you wish to call is actually a @dfn{weak alias}
12507for another function. In such case, @value{GDBN} might not pick up
12508the type information, including the types of the function arguments,
12509which causes @value{GDBN} to call the inferior function incorrectly.
12510As a result, the called function will function erroneously and may
12511even crash. A solution to that is to use the name of the aliased
12512function instead.
c906108c 12513
6d2ebf8b 12514@node Patching
79a6e687 12515@section Patching Programs
7a292a7a 12516
c906108c
SS
12517@cindex patching binaries
12518@cindex writing into executables
c906108c 12519@cindex writing into corefiles
c906108c 12520
7a292a7a
SS
12521By default, @value{GDBN} opens the file containing your program's
12522executable code (or the corefile) read-only. This prevents accidental
12523alterations to machine code; but it also prevents you from intentionally
12524patching your program's binary.
c906108c
SS
12525
12526If you'd like to be able to patch the binary, you can specify that
12527explicitly with the @code{set write} command. For example, you might
12528want to turn on internal debugging flags, or even to make emergency
12529repairs.
12530
12531@table @code
12532@kindex set write
12533@item set write on
12534@itemx set write off
7a292a7a 12535If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 12536core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
12537off} (the default), @value{GDBN} opens them read-only.
12538
12539If you have already loaded a file, you must load it again (using the
7a292a7a
SS
12540@code{exec-file} or @code{core-file} command) after changing @code{set
12541write}, for your new setting to take effect.
c906108c
SS
12542
12543@item show write
12544@kindex show write
7a292a7a
SS
12545Display whether executable files and core files are opened for writing
12546as well as reading.
c906108c
SS
12547@end table
12548
6d2ebf8b 12549@node GDB Files
c906108c
SS
12550@chapter @value{GDBN} Files
12551
7a292a7a
SS
12552@value{GDBN} needs to know the file name of the program to be debugged,
12553both in order to read its symbol table and in order to start your
12554program. To debug a core dump of a previous run, you must also tell
12555@value{GDBN} the name of the core dump file.
c906108c
SS
12556
12557@menu
12558* Files:: Commands to specify files
5b5d99cf 12559* Separate Debug Files:: Debugging information in separate files
c906108c
SS
12560* Symbol Errors:: Errors reading symbol files
12561@end menu
12562
6d2ebf8b 12563@node Files
79a6e687 12564@section Commands to Specify Files
c906108c 12565
7a292a7a 12566@cindex symbol table
c906108c 12567@cindex core dump file
7a292a7a
SS
12568
12569You may want to specify executable and core dump file names. The usual
12570way to do this is at start-up time, using the arguments to
12571@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
12572Out of @value{GDBN}}).
c906108c
SS
12573
12574Occasionally it is necessary to change to a different file during a
397ca115
EZ
12575@value{GDBN} session. Or you may run @value{GDBN} and forget to
12576specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
12577via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
12578Program}). In these situations the @value{GDBN} commands to specify
0869d01b 12579new files are useful.
c906108c
SS
12580
12581@table @code
12582@cindex executable file
12583@kindex file
12584@item file @var{filename}
12585Use @var{filename} as the program to be debugged. It is read for its
12586symbols and for the contents of pure memory. It is also the program
12587executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
12588directory and the file is not found in the @value{GDBN} working directory,
12589@value{GDBN} uses the environment variable @code{PATH} as a list of
12590directories to search, just as the shell does when looking for a program
12591to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
12592and your program, using the @code{path} command.
12593
fc8be69e
EZ
12594@cindex unlinked object files
12595@cindex patching object files
12596You can load unlinked object @file{.o} files into @value{GDBN} using
12597the @code{file} command. You will not be able to ``run'' an object
12598file, but you can disassemble functions and inspect variables. Also,
12599if the underlying BFD functionality supports it, you could use
12600@kbd{gdb -write} to patch object files using this technique. Note
12601that @value{GDBN} can neither interpret nor modify relocations in this
12602case, so branches and some initialized variables will appear to go to
12603the wrong place. But this feature is still handy from time to time.
12604
c906108c
SS
12605@item file
12606@code{file} with no argument makes @value{GDBN} discard any information it
12607has on both executable file and the symbol table.
12608
12609@kindex exec-file
12610@item exec-file @r{[} @var{filename} @r{]}
12611Specify that the program to be run (but not the symbol table) is found
12612in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
12613if necessary to locate your program. Omitting @var{filename} means to
12614discard information on the executable file.
12615
12616@kindex symbol-file
12617@item symbol-file @r{[} @var{filename} @r{]}
12618Read symbol table information from file @var{filename}. @code{PATH} is
12619searched when necessary. Use the @code{file} command to get both symbol
12620table and program to run from the same file.
12621
12622@code{symbol-file} with no argument clears out @value{GDBN} information on your
12623program's symbol table.
12624
ae5a43e0
DJ
12625The @code{symbol-file} command causes @value{GDBN} to forget the contents of
12626some breakpoints and auto-display expressions. This is because they may
12627contain pointers to the internal data recording symbols and data types,
12628which are part of the old symbol table data being discarded inside
12629@value{GDBN}.
c906108c
SS
12630
12631@code{symbol-file} does not repeat if you press @key{RET} again after
12632executing it once.
12633
12634When @value{GDBN} is configured for a particular environment, it
12635understands debugging information in whatever format is the standard
12636generated for that environment; you may use either a @sc{gnu} compiler, or
12637other compilers that adhere to the local conventions.
c906108c 12638Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 12639using @code{@value{NGCC}} you can generate debugging information for
c906108c 12640optimized code.
c906108c
SS
12641
12642For most kinds of object files, with the exception of old SVR3 systems
12643using COFF, the @code{symbol-file} command does not normally read the
12644symbol table in full right away. Instead, it scans the symbol table
12645quickly to find which source files and which symbols are present. The
12646details are read later, one source file at a time, as they are needed.
12647
12648The purpose of this two-stage reading strategy is to make @value{GDBN}
12649start up faster. For the most part, it is invisible except for
12650occasional pauses while the symbol table details for a particular source
12651file are being read. (The @code{set verbose} command can turn these
12652pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 12653Warnings and Messages}.)
c906108c 12654
c906108c
SS
12655We have not implemented the two-stage strategy for COFF yet. When the
12656symbol table is stored in COFF format, @code{symbol-file} reads the
12657symbol table data in full right away. Note that ``stabs-in-COFF''
12658still does the two-stage strategy, since the debug info is actually
12659in stabs format.
12660
12661@kindex readnow
12662@cindex reading symbols immediately
12663@cindex symbols, reading immediately
a94ab193
EZ
12664@item symbol-file @var{filename} @r{[} -readnow @r{]}
12665@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
12666You can override the @value{GDBN} two-stage strategy for reading symbol
12667tables by using the @samp{-readnow} option with any of the commands that
12668load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 12669entire symbol table available.
c906108c 12670
c906108c
SS
12671@c FIXME: for now no mention of directories, since this seems to be in
12672@c flux. 13mar1992 status is that in theory GDB would look either in
12673@c current dir or in same dir as myprog; but issues like competing
12674@c GDB's, or clutter in system dirs, mean that in practice right now
12675@c only current dir is used. FFish says maybe a special GDB hierarchy
12676@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
12677@c files.
12678
c906108c 12679@kindex core-file
09d4efe1 12680@item core-file @r{[}@var{filename}@r{]}
4644b6e3 12681@itemx core
c906108c
SS
12682Specify the whereabouts of a core dump file to be used as the ``contents
12683of memory''. Traditionally, core files contain only some parts of the
12684address space of the process that generated them; @value{GDBN} can access the
12685executable file itself for other parts.
12686
12687@code{core-file} with no argument specifies that no core file is
12688to be used.
12689
12690Note that the core file is ignored when your program is actually running
7a292a7a
SS
12691under @value{GDBN}. So, if you have been running your program and you
12692wish to debug a core file instead, you must kill the subprocess in which
12693the program is running. To do this, use the @code{kill} command
79a6e687 12694(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 12695
c906108c
SS
12696@kindex add-symbol-file
12697@cindex dynamic linking
12698@item add-symbol-file @var{filename} @var{address}
a94ab193 12699@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 12700@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
12701The @code{add-symbol-file} command reads additional symbol table
12702information from the file @var{filename}. You would use this command
12703when @var{filename} has been dynamically loaded (by some other means)
12704into the program that is running. @var{address} should be the memory
12705address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
12706this out for itself. You can additionally specify an arbitrary number
12707of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
12708section name and base address for that section. You can specify any
12709@var{address} as an expression.
c906108c
SS
12710
12711The symbol table of the file @var{filename} is added to the symbol table
12712originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
12713@code{add-symbol-file} command any number of times; the new symbol data
12714thus read keeps adding to the old. To discard all old symbol data
12715instead, use the @code{symbol-file} command without any arguments.
c906108c 12716
17d9d558
JB
12717@cindex relocatable object files, reading symbols from
12718@cindex object files, relocatable, reading symbols from
12719@cindex reading symbols from relocatable object files
12720@cindex symbols, reading from relocatable object files
12721@cindex @file{.o} files, reading symbols from
12722Although @var{filename} is typically a shared library file, an
12723executable file, or some other object file which has been fully
12724relocated for loading into a process, you can also load symbolic
12725information from relocatable @file{.o} files, as long as:
12726
12727@itemize @bullet
12728@item
12729the file's symbolic information refers only to linker symbols defined in
12730that file, not to symbols defined by other object files,
12731@item
12732every section the file's symbolic information refers to has actually
12733been loaded into the inferior, as it appears in the file, and
12734@item
12735you can determine the address at which every section was loaded, and
12736provide these to the @code{add-symbol-file} command.
12737@end itemize
12738
12739@noindent
12740Some embedded operating systems, like Sun Chorus and VxWorks, can load
12741relocatable files into an already running program; such systems
12742typically make the requirements above easy to meet. However, it's
12743important to recognize that many native systems use complex link
49efadf5 12744procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
12745assembly, for example) that make the requirements difficult to meet. In
12746general, one cannot assume that using @code{add-symbol-file} to read a
12747relocatable object file's symbolic information will have the same effect
12748as linking the relocatable object file into the program in the normal
12749way.
12750
c906108c
SS
12751@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
12752
c45da7e6
EZ
12753@kindex add-symbol-file-from-memory
12754@cindex @code{syscall DSO}
12755@cindex load symbols from memory
12756@item add-symbol-file-from-memory @var{address}
12757Load symbols from the given @var{address} in a dynamically loaded
12758object file whose image is mapped directly into the inferior's memory.
12759For example, the Linux kernel maps a @code{syscall DSO} into each
12760process's address space; this DSO provides kernel-specific code for
12761some system calls. The argument can be any expression whose
12762evaluation yields the address of the file's shared object file header.
12763For this command to work, you must have used @code{symbol-file} or
12764@code{exec-file} commands in advance.
12765
09d4efe1
EZ
12766@kindex add-shared-symbol-files
12767@kindex assf
12768@item add-shared-symbol-files @var{library-file}
12769@itemx assf @var{library-file}
12770The @code{add-shared-symbol-files} command can currently be used only
12771in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
12772alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
12773@value{GDBN} automatically looks for shared libraries, however if
12774@value{GDBN} does not find yours, you can invoke
12775@code{add-shared-symbol-files}. It takes one argument: the shared
12776library's file name. @code{assf} is a shorthand alias for
12777@code{add-shared-symbol-files}.
c906108c 12778
c906108c 12779@kindex section
09d4efe1
EZ
12780@item section @var{section} @var{addr}
12781The @code{section} command changes the base address of the named
12782@var{section} of the exec file to @var{addr}. This can be used if the
12783exec file does not contain section addresses, (such as in the
12784@code{a.out} format), or when the addresses specified in the file
12785itself are wrong. Each section must be changed separately. The
12786@code{info files} command, described below, lists all the sections and
12787their addresses.
c906108c
SS
12788
12789@kindex info files
12790@kindex info target
12791@item info files
12792@itemx info target
7a292a7a
SS
12793@code{info files} and @code{info target} are synonymous; both print the
12794current target (@pxref{Targets, ,Specifying a Debugging Target}),
12795including the names of the executable and core dump files currently in
12796use by @value{GDBN}, and the files from which symbols were loaded. The
12797command @code{help target} lists all possible targets rather than
12798current ones.
12799
fe95c787
MS
12800@kindex maint info sections
12801@item maint info sections
12802Another command that can give you extra information about program sections
12803is @code{maint info sections}. In addition to the section information
12804displayed by @code{info files}, this command displays the flags and file
12805offset of each section in the executable and core dump files. In addition,
12806@code{maint info sections} provides the following command options (which
12807may be arbitrarily combined):
12808
12809@table @code
12810@item ALLOBJ
12811Display sections for all loaded object files, including shared libraries.
12812@item @var{sections}
6600abed 12813Display info only for named @var{sections}.
fe95c787
MS
12814@item @var{section-flags}
12815Display info only for sections for which @var{section-flags} are true.
12816The section flags that @value{GDBN} currently knows about are:
12817@table @code
12818@item ALLOC
12819Section will have space allocated in the process when loaded.
12820Set for all sections except those containing debug information.
12821@item LOAD
12822Section will be loaded from the file into the child process memory.
12823Set for pre-initialized code and data, clear for @code{.bss} sections.
12824@item RELOC
12825Section needs to be relocated before loading.
12826@item READONLY
12827Section cannot be modified by the child process.
12828@item CODE
12829Section contains executable code only.
6600abed 12830@item DATA
fe95c787
MS
12831Section contains data only (no executable code).
12832@item ROM
12833Section will reside in ROM.
12834@item CONSTRUCTOR
12835Section contains data for constructor/destructor lists.
12836@item HAS_CONTENTS
12837Section is not empty.
12838@item NEVER_LOAD
12839An instruction to the linker to not output the section.
12840@item COFF_SHARED_LIBRARY
12841A notification to the linker that the section contains
12842COFF shared library information.
12843@item IS_COMMON
12844Section contains common symbols.
12845@end table
12846@end table
6763aef9 12847@kindex set trust-readonly-sections
9c16f35a 12848@cindex read-only sections
6763aef9
MS
12849@item set trust-readonly-sections on
12850Tell @value{GDBN} that readonly sections in your object file
6ca652b0 12851really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
12852In that case, @value{GDBN} can fetch values from these sections
12853out of the object file, rather than from the target program.
12854For some targets (notably embedded ones), this can be a significant
12855enhancement to debugging performance.
12856
12857The default is off.
12858
12859@item set trust-readonly-sections off
15110bc3 12860Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
12861the contents of the section might change while the program is running,
12862and must therefore be fetched from the target when needed.
9c16f35a
EZ
12863
12864@item show trust-readonly-sections
12865Show the current setting of trusting readonly sections.
c906108c
SS
12866@end table
12867
12868All file-specifying commands allow both absolute and relative file names
12869as arguments. @value{GDBN} always converts the file name to an absolute file
12870name and remembers it that way.
12871
c906108c 12872@cindex shared libraries
9cceb671
DJ
12873@anchor{Shared Libraries}
12874@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 12875and IBM RS/6000 AIX shared libraries.
53a5351d 12876
9cceb671
DJ
12877On MS-Windows @value{GDBN} must be linked with the Expat library to support
12878shared libraries. @xref{Expat}.
12879
c906108c
SS
12880@value{GDBN} automatically loads symbol definitions from shared libraries
12881when you use the @code{run} command, or when you examine a core file.
12882(Before you issue the @code{run} command, @value{GDBN} does not understand
12883references to a function in a shared library, however---unless you are
12884debugging a core file).
53a5351d
JM
12885
12886On HP-UX, if the program loads a library explicitly, @value{GDBN}
12887automatically loads the symbols at the time of the @code{shl_load} call.
12888
c906108c
SS
12889@c FIXME: some @value{GDBN} release may permit some refs to undef
12890@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
12891@c FIXME...lib; check this from time to time when updating manual
12892
b7209cb4
FF
12893There are times, however, when you may wish to not automatically load
12894symbol definitions from shared libraries, such as when they are
12895particularly large or there are many of them.
12896
12897To control the automatic loading of shared library symbols, use the
12898commands:
12899
12900@table @code
12901@kindex set auto-solib-add
12902@item set auto-solib-add @var{mode}
12903If @var{mode} is @code{on}, symbols from all shared object libraries
12904will be loaded automatically when the inferior begins execution, you
12905attach to an independently started inferior, or when the dynamic linker
12906informs @value{GDBN} that a new library has been loaded. If @var{mode}
12907is @code{off}, symbols must be loaded manually, using the
12908@code{sharedlibrary} command. The default value is @code{on}.
12909
dcaf7c2c
EZ
12910@cindex memory used for symbol tables
12911If your program uses lots of shared libraries with debug info that
12912takes large amounts of memory, you can decrease the @value{GDBN}
12913memory footprint by preventing it from automatically loading the
12914symbols from shared libraries. To that end, type @kbd{set
12915auto-solib-add off} before running the inferior, then load each
12916library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 12917@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
12918the libraries whose symbols you want to be loaded.
12919
b7209cb4
FF
12920@kindex show auto-solib-add
12921@item show auto-solib-add
12922Display the current autoloading mode.
12923@end table
12924
c45da7e6 12925@cindex load shared library
b7209cb4
FF
12926To explicitly load shared library symbols, use the @code{sharedlibrary}
12927command:
12928
c906108c
SS
12929@table @code
12930@kindex info sharedlibrary
12931@kindex info share
12932@item info share
12933@itemx info sharedlibrary
12934Print the names of the shared libraries which are currently loaded.
12935
12936@kindex sharedlibrary
12937@kindex share
12938@item sharedlibrary @var{regex}
12939@itemx share @var{regex}
c906108c
SS
12940Load shared object library symbols for files matching a
12941Unix regular expression.
12942As with files loaded automatically, it only loads shared libraries
12943required by your program for a core file or after typing @code{run}. If
12944@var{regex} is omitted all shared libraries required by your program are
12945loaded.
c45da7e6
EZ
12946
12947@item nosharedlibrary
12948@kindex nosharedlibrary
12949@cindex unload symbols from shared libraries
12950Unload all shared object library symbols. This discards all symbols
12951that have been loaded from all shared libraries. Symbols from shared
12952libraries that were loaded by explicit user requests are not
12953discarded.
c906108c
SS
12954@end table
12955
721c2651
EZ
12956Sometimes you may wish that @value{GDBN} stops and gives you control
12957when any of shared library events happen. Use the @code{set
12958stop-on-solib-events} command for this:
12959
12960@table @code
12961@item set stop-on-solib-events
12962@kindex set stop-on-solib-events
12963This command controls whether @value{GDBN} should give you control
12964when the dynamic linker notifies it about some shared library event.
12965The most common event of interest is loading or unloading of a new
12966shared library.
12967
12968@item show stop-on-solib-events
12969@kindex show stop-on-solib-events
12970Show whether @value{GDBN} stops and gives you control when shared
12971library events happen.
12972@end table
12973
f5ebfba0 12974Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
12975configurations. @value{GDBN} needs to have access to the target's libraries;
12976this can be accomplished either by providing copies of the libraries
12977on the host system, or by asking @value{GDBN} to automatically retrieve the
12978libraries from the target. If copies of the target libraries are
12979provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
12980copies on the target can be stripped as long as the copies on the host are
12981not.
12982
59b7b46f
EZ
12983@cindex where to look for shared libraries
12984For remote debugging, you need to tell @value{GDBN} where the target
12985libraries are, so that it can load the correct copies---otherwise, it
12986may try to load the host's libraries. @value{GDBN} has two variables
12987to specify the search directories for target libraries.
f5ebfba0
DJ
12988
12989@table @code
59b7b46f 12990@cindex prefix for shared library file names
f822c95b 12991@cindex system root, alternate
f5ebfba0 12992@kindex set solib-absolute-prefix
f822c95b
DJ
12993@kindex set sysroot
12994@item set sysroot @var{path}
12995Use @var{path} as the system root for the program being debugged. Any
12996absolute shared library paths will be prefixed with @var{path}; many
12997runtime loaders store the absolute paths to the shared library in the
12998target program's memory. If you use @code{set sysroot} to find shared
12999libraries, they need to be laid out in the same way that they are on
13000the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
13001under @var{path}.
13002
f1838a98
UW
13003If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
13004retrieve the target libraries from the remote system. This is only
13005supported when using a remote target that supports the @code{remote get}
13006command (@pxref{File Transfer,,Sending files to a remote system}).
13007The part of @var{path} following the initial @file{remote:}
13008(if present) is used as system root prefix on the remote file system.
13009@footnote{If you want to specify a local system root using a directory
13010that happens to be named @file{remote:}, you need to use some equivalent
13011variant of the name like @file{./remote:}.}
13012
f822c95b
DJ
13013The @code{set solib-absolute-prefix} command is an alias for @code{set
13014sysroot}.
13015
13016@cindex default system root
59b7b46f 13017@cindex @samp{--with-sysroot}
f822c95b
DJ
13018You can set the default system root by using the configure-time
13019@samp{--with-sysroot} option. If the system root is inside
13020@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
13021@samp{--exec-prefix}), then the default system root will be updated
13022automatically if the installed @value{GDBN} is moved to a new
13023location.
13024
13025@kindex show sysroot
13026@item show sysroot
f5ebfba0
DJ
13027Display the current shared library prefix.
13028
13029@kindex set solib-search-path
13030@item set solib-search-path @var{path}
f822c95b
DJ
13031If this variable is set, @var{path} is a colon-separated list of
13032directories to search for shared libraries. @samp{solib-search-path}
13033is used after @samp{sysroot} fails to locate the library, or if the
13034path to the library is relative instead of absolute. If you want to
13035use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 13036@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 13037finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 13038it to a nonexistent directory may interfere with automatic loading
f822c95b 13039of shared library symbols.
f5ebfba0
DJ
13040
13041@kindex show solib-search-path
13042@item show solib-search-path
13043Display the current shared library search path.
13044@end table
13045
5b5d99cf
JB
13046
13047@node Separate Debug Files
13048@section Debugging Information in Separate Files
13049@cindex separate debugging information files
13050@cindex debugging information in separate files
13051@cindex @file{.debug} subdirectories
13052@cindex debugging information directory, global
13053@cindex global debugging information directory
c7e83d54
EZ
13054@cindex build ID, and separate debugging files
13055@cindex @file{.build-id} directory
5b5d99cf
JB
13056
13057@value{GDBN} allows you to put a program's debugging information in a
13058file separate from the executable itself, in a way that allows
13059@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
13060Since debugging information can be very large---sometimes larger
13061than the executable code itself---some systems distribute debugging
5b5d99cf
JB
13062information for their executables in separate files, which users can
13063install only when they need to debug a problem.
13064
c7e83d54
EZ
13065@value{GDBN} supports two ways of specifying the separate debug info
13066file:
5b5d99cf
JB
13067
13068@itemize @bullet
13069@item
c7e83d54
EZ
13070The executable contains a @dfn{debug link} that specifies the name of
13071the separate debug info file. The separate debug file's name is
13072usually @file{@var{executable}.debug}, where @var{executable} is the
13073name of the corresponding executable file without leading directories
13074(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
13075debug link specifies a CRC32 checksum for the debug file, which
13076@value{GDBN} uses to validate that the executable and the debug file
13077came from the same build.
13078
13079@item
7e27a47a 13080The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 13081also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
13082only on some operating systems, notably those which use the ELF format
13083for binary files and the @sc{gnu} Binutils.) For more details about
13084this feature, see the description of the @option{--build-id}
13085command-line option in @ref{Options, , Command Line Options, ld.info,
13086The GNU Linker}. The debug info file's name is not specified
13087explicitly by the build ID, but can be computed from the build ID, see
13088below.
d3750b24
JK
13089@end itemize
13090
c7e83d54
EZ
13091Depending on the way the debug info file is specified, @value{GDBN}
13092uses two different methods of looking for the debug file:
d3750b24
JK
13093
13094@itemize @bullet
13095@item
c7e83d54
EZ
13096For the ``debug link'' method, @value{GDBN} looks up the named file in
13097the directory of the executable file, then in a subdirectory of that
13098directory named @file{.debug}, and finally under the global debug
13099directory, in a subdirectory whose name is identical to the leading
13100directories of the executable's absolute file name.
13101
13102@item
83f83d7f 13103For the ``build ID'' method, @value{GDBN} looks in the
c7e83d54
EZ
13104@file{.build-id} subdirectory of the global debug directory for a file
13105named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
13106first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
13107are the rest of the bit string. (Real build ID strings are 32 or more
13108hex characters, not 10.)
c7e83d54
EZ
13109@end itemize
13110
13111So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
13112@file{/usr/bin/ls}, which has a debug link that specifies the
13113file @file{ls.debug}, and a build ID whose value in hex is
c7e83d54
EZ
13114@code{abcdef1234}. If the global debug directory is
13115@file{/usr/lib/debug}, then @value{GDBN} will look for the following
13116debug information files, in the indicated order:
13117
13118@itemize @minus
13119@item
13120@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 13121@item
c7e83d54 13122@file{/usr/bin/ls.debug}
5b5d99cf 13123@item
c7e83d54 13124@file{/usr/bin/.debug/ls.debug}
5b5d99cf 13125@item
c7e83d54 13126@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 13127@end itemize
5b5d99cf
JB
13128
13129You can set the global debugging info directory's name, and view the
13130name @value{GDBN} is currently using.
13131
13132@table @code
13133
13134@kindex set debug-file-directory
13135@item set debug-file-directory @var{directory}
13136Set the directory which @value{GDBN} searches for separate debugging
13137information files to @var{directory}.
13138
13139@kindex show debug-file-directory
13140@item show debug-file-directory
13141Show the directory @value{GDBN} searches for separate debugging
13142information files.
13143
13144@end table
13145
13146@cindex @code{.gnu_debuglink} sections
c7e83d54 13147@cindex debug link sections
5b5d99cf
JB
13148A debug link is a special section of the executable file named
13149@code{.gnu_debuglink}. The section must contain:
13150
13151@itemize
13152@item
13153A filename, with any leading directory components removed, followed by
13154a zero byte,
13155@item
13156zero to three bytes of padding, as needed to reach the next four-byte
13157boundary within the section, and
13158@item
13159a four-byte CRC checksum, stored in the same endianness used for the
13160executable file itself. The checksum is computed on the debugging
13161information file's full contents by the function given below, passing
13162zero as the @var{crc} argument.
13163@end itemize
13164
13165Any executable file format can carry a debug link, as long as it can
13166contain a section named @code{.gnu_debuglink} with the contents
13167described above.
13168
d3750b24 13169@cindex @code{.note.gnu.build-id} sections
c7e83d54 13170@cindex build ID sections
7e27a47a
EZ
13171The build ID is a special section in the executable file (and in other
13172ELF binary files that @value{GDBN} may consider). This section is
13173often named @code{.note.gnu.build-id}, but that name is not mandatory.
13174It contains unique identification for the built files---the ID remains
13175the same across multiple builds of the same build tree. The default
13176algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
13177content for the build ID string. The same section with an identical
13178value is present in the original built binary with symbols, in its
13179stripped variant, and in the separate debugging information file.
d3750b24 13180
5b5d99cf
JB
13181The debugging information file itself should be an ordinary
13182executable, containing a full set of linker symbols, sections, and
13183debugging information. The sections of the debugging information file
c7e83d54
EZ
13184should have the same names, addresses, and sizes as the original file,
13185but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
13186in an ordinary executable.
13187
7e27a47a 13188The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
13189@samp{objcopy} utility that can produce
13190the separated executable / debugging information file pairs using the
13191following commands:
13192
13193@smallexample
13194@kbd{objcopy --only-keep-debug foo foo.debug}
13195@kbd{strip -g foo}
c7e83d54
EZ
13196@end smallexample
13197
13198@noindent
13199These commands remove the debugging
83f83d7f
JK
13200information from the executable file @file{foo} and place it in the file
13201@file{foo.debug}. You can use the first, second or both methods to link the
13202two files:
13203
13204@itemize @bullet
13205@item
13206The debug link method needs the following additional command to also leave
13207behind a debug link in @file{foo}:
13208
13209@smallexample
13210@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
13211@end smallexample
13212
13213Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 13214a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
13215foo.debug} has the same functionality as the two @code{objcopy} commands and
13216the @code{ln -s} command above, together.
13217
13218@item
13219Build ID gets embedded into the main executable using @code{ld --build-id} or
13220the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
13221compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 13222utilities (Binutils) package since version 2.18.
83f83d7f
JK
13223@end itemize
13224
13225@noindent
d3750b24 13226
c7e83d54
EZ
13227Since there are many different ways to compute CRC's for the debug
13228link (different polynomials, reversals, byte ordering, etc.), the
13229simplest way to describe the CRC used in @code{.gnu_debuglink}
13230sections is to give the complete code for a function that computes it:
5b5d99cf 13231
4644b6e3 13232@kindex gnu_debuglink_crc32
5b5d99cf
JB
13233@smallexample
13234unsigned long
13235gnu_debuglink_crc32 (unsigned long crc,
13236 unsigned char *buf, size_t len)
13237@{
13238 static const unsigned long crc32_table[256] =
13239 @{
13240 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
13241 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
13242 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
13243 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
13244 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
13245 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
13246 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
13247 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
13248 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
13249 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
13250 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
13251 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
13252 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
13253 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
13254 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
13255 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
13256 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
13257 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
13258 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
13259 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
13260 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
13261 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
13262 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
13263 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
13264 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
13265 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
13266 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
13267 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
13268 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
13269 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
13270 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
13271 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
13272 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
13273 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
13274 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
13275 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
13276 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
13277 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
13278 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
13279 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
13280 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
13281 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
13282 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
13283 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
13284 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
13285 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
13286 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
13287 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
13288 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
13289 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
13290 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
13291 0x2d02ef8d
13292 @};
13293 unsigned char *end;
13294
13295 crc = ~crc & 0xffffffff;
13296 for (end = buf + len; buf < end; ++buf)
13297 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 13298 return ~crc & 0xffffffff;
5b5d99cf
JB
13299@}
13300@end smallexample
13301
c7e83d54
EZ
13302@noindent
13303This computation does not apply to the ``build ID'' method.
13304
5b5d99cf 13305
6d2ebf8b 13306@node Symbol Errors
79a6e687 13307@section Errors Reading Symbol Files
c906108c
SS
13308
13309While reading a symbol file, @value{GDBN} occasionally encounters problems,
13310such as symbol types it does not recognize, or known bugs in compiler
13311output. By default, @value{GDBN} does not notify you of such problems, since
13312they are relatively common and primarily of interest to people
13313debugging compilers. If you are interested in seeing information
13314about ill-constructed symbol tables, you can either ask @value{GDBN} to print
13315only one message about each such type of problem, no matter how many
13316times the problem occurs; or you can ask @value{GDBN} to print more messages,
13317to see how many times the problems occur, with the @code{set
79a6e687
BW
13318complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
13319Messages}).
c906108c
SS
13320
13321The messages currently printed, and their meanings, include:
13322
13323@table @code
13324@item inner block not inside outer block in @var{symbol}
13325
13326The symbol information shows where symbol scopes begin and end
13327(such as at the start of a function or a block of statements). This
13328error indicates that an inner scope block is not fully contained
13329in its outer scope blocks.
13330
13331@value{GDBN} circumvents the problem by treating the inner block as if it had
13332the same scope as the outer block. In the error message, @var{symbol}
13333may be shown as ``@code{(don't know)}'' if the outer block is not a
13334function.
13335
13336@item block at @var{address} out of order
13337
13338The symbol information for symbol scope blocks should occur in
13339order of increasing addresses. This error indicates that it does not
13340do so.
13341
13342@value{GDBN} does not circumvent this problem, and has trouble
13343locating symbols in the source file whose symbols it is reading. (You
13344can often determine what source file is affected by specifying
79a6e687
BW
13345@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
13346Messages}.)
c906108c
SS
13347
13348@item bad block start address patched
13349
13350The symbol information for a symbol scope block has a start address
13351smaller than the address of the preceding source line. This is known
13352to occur in the SunOS 4.1.1 (and earlier) C compiler.
13353
13354@value{GDBN} circumvents the problem by treating the symbol scope block as
13355starting on the previous source line.
13356
13357@item bad string table offset in symbol @var{n}
13358
13359@cindex foo
13360Symbol number @var{n} contains a pointer into the string table which is
13361larger than the size of the string table.
13362
13363@value{GDBN} circumvents the problem by considering the symbol to have the
13364name @code{foo}, which may cause other problems if many symbols end up
13365with this name.
13366
13367@item unknown symbol type @code{0x@var{nn}}
13368
7a292a7a
SS
13369The symbol information contains new data types that @value{GDBN} does
13370not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 13371uncomprehended information, in hexadecimal.
c906108c 13372
7a292a7a
SS
13373@value{GDBN} circumvents the error by ignoring this symbol information.
13374This usually allows you to debug your program, though certain symbols
c906108c 13375are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
13376debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
13377on @code{complain}, then go up to the function @code{read_dbx_symtab}
13378and examine @code{*bufp} to see the symbol.
c906108c
SS
13379
13380@item stub type has NULL name
c906108c 13381
7a292a7a 13382@value{GDBN} could not find the full definition for a struct or class.
c906108c 13383
7a292a7a 13384@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 13385The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
13386information that recent versions of the compiler should have output for
13387it.
c906108c
SS
13388
13389@item info mismatch between compiler and debugger
13390
13391@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 13392
c906108c
SS
13393@end table
13394
6d2ebf8b 13395@node Targets
c906108c 13396@chapter Specifying a Debugging Target
7a292a7a 13397
c906108c 13398@cindex debugging target
c906108c 13399A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
13400
13401Often, @value{GDBN} runs in the same host environment as your program;
13402in that case, the debugging target is specified as a side effect when
13403you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
13404flexibility---for example, running @value{GDBN} on a physically separate
13405host, or controlling a standalone system over a serial port or a
53a5351d
JM
13406realtime system over a TCP/IP connection---you can use the @code{target}
13407command to specify one of the target types configured for @value{GDBN}
79a6e687 13408(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 13409
a8f24a35
EZ
13410@cindex target architecture
13411It is possible to build @value{GDBN} for several different @dfn{target
13412architectures}. When @value{GDBN} is built like that, you can choose
13413one of the available architectures with the @kbd{set architecture}
13414command.
13415
13416@table @code
13417@kindex set architecture
13418@kindex show architecture
13419@item set architecture @var{arch}
13420This command sets the current target architecture to @var{arch}. The
13421value of @var{arch} can be @code{"auto"}, in addition to one of the
13422supported architectures.
13423
13424@item show architecture
13425Show the current target architecture.
9c16f35a
EZ
13426
13427@item set processor
13428@itemx processor
13429@kindex set processor
13430@kindex show processor
13431These are alias commands for, respectively, @code{set architecture}
13432and @code{show architecture}.
a8f24a35
EZ
13433@end table
13434
c906108c
SS
13435@menu
13436* Active Targets:: Active targets
13437* Target Commands:: Commands for managing targets
c906108c 13438* Byte Order:: Choosing target byte order
c906108c
SS
13439@end menu
13440
6d2ebf8b 13441@node Active Targets
79a6e687 13442@section Active Targets
7a292a7a 13443
c906108c
SS
13444@cindex stacking targets
13445@cindex active targets
13446@cindex multiple targets
13447
c906108c 13448There are three classes of targets: processes, core files, and
7a292a7a
SS
13449executable files. @value{GDBN} can work concurrently on up to three
13450active targets, one in each class. This allows you to (for example)
13451start a process and inspect its activity without abandoning your work on
13452a core file.
c906108c
SS
13453
13454For example, if you execute @samp{gdb a.out}, then the executable file
13455@code{a.out} is the only active target. If you designate a core file as
13456well---presumably from a prior run that crashed and coredumped---then
13457@value{GDBN} has two active targets and uses them in tandem, looking
13458first in the corefile target, then in the executable file, to satisfy
13459requests for memory addresses. (Typically, these two classes of target
13460are complementary, since core files contain only a program's
13461read-write memory---variables and so on---plus machine status, while
13462executable files contain only the program text and initialized data.)
c906108c
SS
13463
13464When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
13465target as well. When a process target is active, all @value{GDBN}
13466commands requesting memory addresses refer to that target; addresses in
13467an active core file or executable file target are obscured while the
13468process target is active.
c906108c 13469
7a292a7a 13470Use the @code{core-file} and @code{exec-file} commands to select a new
79a6e687
BW
13471core file or executable target (@pxref{Files, ,Commands to Specify
13472Files}). To specify as a target a process that is already running, use
13473the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
13474Process}).
c906108c 13475
6d2ebf8b 13476@node Target Commands
79a6e687 13477@section Commands for Managing Targets
c906108c
SS
13478
13479@table @code
13480@item target @var{type} @var{parameters}
7a292a7a
SS
13481Connects the @value{GDBN} host environment to a target machine or
13482process. A target is typically a protocol for talking to debugging
13483facilities. You use the argument @var{type} to specify the type or
13484protocol of the target machine.
c906108c
SS
13485
13486Further @var{parameters} are interpreted by the target protocol, but
13487typically include things like device names or host names to connect
13488with, process numbers, and baud rates.
c906108c
SS
13489
13490The @code{target} command does not repeat if you press @key{RET} again
13491after executing the command.
13492
13493@kindex help target
13494@item help target
13495Displays the names of all targets available. To display targets
13496currently selected, use either @code{info target} or @code{info files}
79a6e687 13497(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
13498
13499@item help target @var{name}
13500Describe a particular target, including any parameters necessary to
13501select it.
13502
13503@kindex set gnutarget
13504@item set gnutarget @var{args}
5d161b24 13505@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 13506knows whether it is reading an @dfn{executable},
5d161b24
DB
13507a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
13508with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
13509with @code{gnutarget} the @code{target} refers to a program, not a machine.
13510
d4f3574e 13511@quotation
c906108c
SS
13512@emph{Warning:} To specify a file format with @code{set gnutarget},
13513you must know the actual BFD name.
d4f3574e 13514@end quotation
c906108c 13515
d4f3574e 13516@noindent
79a6e687 13517@xref{Files, , Commands to Specify Files}.
c906108c 13518
5d161b24 13519@kindex show gnutarget
c906108c
SS
13520@item show gnutarget
13521Use the @code{show gnutarget} command to display what file format
13522@code{gnutarget} is set to read. If you have not set @code{gnutarget},
13523@value{GDBN} will determine the file format for each file automatically,
13524and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
13525@end table
13526
4644b6e3 13527@cindex common targets
c906108c
SS
13528Here are some common targets (available, or not, depending on the GDB
13529configuration):
c906108c
SS
13530
13531@table @code
4644b6e3 13532@kindex target
c906108c 13533@item target exec @var{program}
4644b6e3 13534@cindex executable file target
c906108c
SS
13535An executable file. @samp{target exec @var{program}} is the same as
13536@samp{exec-file @var{program}}.
13537
c906108c 13538@item target core @var{filename}
4644b6e3 13539@cindex core dump file target
c906108c
SS
13540A core dump file. @samp{target core @var{filename}} is the same as
13541@samp{core-file @var{filename}}.
c906108c 13542
1a10341b 13543@item target remote @var{medium}
4644b6e3 13544@cindex remote target
1a10341b
JB
13545A remote system connected to @value{GDBN} via a serial line or network
13546connection. This command tells @value{GDBN} to use its own remote
13547protocol over @var{medium} for debugging. @xref{Remote Debugging}.
13548
13549For example, if you have a board connected to @file{/dev/ttya} on the
13550machine running @value{GDBN}, you could say:
13551
13552@smallexample
13553target remote /dev/ttya
13554@end smallexample
13555
13556@code{target remote} supports the @code{load} command. This is only
13557useful if you have some other way of getting the stub to the target
13558system, and you can put it somewhere in memory where it won't get
13559clobbered by the download.
c906108c 13560
c906108c 13561@item target sim
4644b6e3 13562@cindex built-in simulator target
2df3850c 13563Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 13564In general,
474c8240 13565@smallexample
104c1213
JM
13566 target sim
13567 load
13568 run
474c8240 13569@end smallexample
d4f3574e 13570@noindent
104c1213 13571works; however, you cannot assume that a specific memory map, device
d4f3574e 13572drivers, or even basic I/O is available, although some simulators do
104c1213
JM
13573provide these. For info about any processor-specific simulator details,
13574see the appropriate section in @ref{Embedded Processors, ,Embedded
13575Processors}.
13576
c906108c
SS
13577@end table
13578
104c1213 13579Some configurations may include these targets as well:
c906108c
SS
13580
13581@table @code
13582
c906108c 13583@item target nrom @var{dev}
4644b6e3 13584@cindex NetROM ROM emulator target
c906108c
SS
13585NetROM ROM emulator. This target only supports downloading.
13586
c906108c
SS
13587@end table
13588
5d161b24 13589Different targets are available on different configurations of @value{GDBN};
c906108c 13590your configuration may have more or fewer targets.
c906108c 13591
721c2651
EZ
13592Many remote targets require you to download the executable's code once
13593you've successfully established a connection. You may wish to control
3d00d119
DJ
13594various aspects of this process.
13595
13596@table @code
721c2651
EZ
13597
13598@item set hash
13599@kindex set hash@r{, for remote monitors}
13600@cindex hash mark while downloading
13601This command controls whether a hash mark @samp{#} is displayed while
13602downloading a file to the remote monitor. If on, a hash mark is
13603displayed after each S-record is successfully downloaded to the
13604monitor.
13605
13606@item show hash
13607@kindex show hash@r{, for remote monitors}
13608Show the current status of displaying the hash mark.
13609
13610@item set debug monitor
13611@kindex set debug monitor
13612@cindex display remote monitor communications
13613Enable or disable display of communications messages between
13614@value{GDBN} and the remote monitor.
13615
13616@item show debug monitor
13617@kindex show debug monitor
13618Show the current status of displaying communications between
13619@value{GDBN} and the remote monitor.
a8f24a35 13620@end table
c906108c
SS
13621
13622@table @code
13623
13624@kindex load @var{filename}
13625@item load @var{filename}
8edfe269 13626@anchor{load}
c906108c
SS
13627Depending on what remote debugging facilities are configured into
13628@value{GDBN}, the @code{load} command may be available. Where it exists, it
13629is meant to make @var{filename} (an executable) available for debugging
13630on the remote system---by downloading, or dynamic linking, for example.
13631@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
13632the @code{add-symbol-file} command.
13633
13634If your @value{GDBN} does not have a @code{load} command, attempting to
13635execute it gets the error message ``@code{You can't do that when your
13636target is @dots{}}''
c906108c
SS
13637
13638The file is loaded at whatever address is specified in the executable.
13639For some object file formats, you can specify the load address when you
13640link the program; for other formats, like a.out, the object file format
13641specifies a fixed address.
13642@c FIXME! This would be a good place for an xref to the GNU linker doc.
13643
68437a39
DJ
13644Depending on the remote side capabilities, @value{GDBN} may be able to
13645load programs into flash memory.
13646
c906108c
SS
13647@code{load} does not repeat if you press @key{RET} again after using it.
13648@end table
13649
6d2ebf8b 13650@node Byte Order
79a6e687 13651@section Choosing Target Byte Order
7a292a7a 13652
c906108c
SS
13653@cindex choosing target byte order
13654@cindex target byte order
c906108c 13655
172c2a43 13656Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
13657offer the ability to run either big-endian or little-endian byte
13658orders. Usually the executable or symbol will include a bit to
13659designate the endian-ness, and you will not need to worry about
13660which to use. However, you may still find it useful to adjust
d4f3574e 13661@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
13662
13663@table @code
4644b6e3 13664@kindex set endian
c906108c
SS
13665@item set endian big
13666Instruct @value{GDBN} to assume the target is big-endian.
13667
c906108c
SS
13668@item set endian little
13669Instruct @value{GDBN} to assume the target is little-endian.
13670
c906108c
SS
13671@item set endian auto
13672Instruct @value{GDBN} to use the byte order associated with the
13673executable.
13674
13675@item show endian
13676Display @value{GDBN}'s current idea of the target byte order.
13677
13678@end table
13679
13680Note that these commands merely adjust interpretation of symbolic
13681data on the host, and that they have absolutely no effect on the
13682target system.
13683
ea35711c
DJ
13684
13685@node Remote Debugging
13686@chapter Debugging Remote Programs
c906108c
SS
13687@cindex remote debugging
13688
13689If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
13690@value{GDBN} in the usual way, it is often useful to use remote debugging.
13691For example, you might use remote debugging on an operating system kernel,
c906108c
SS
13692or on a small system which does not have a general purpose operating system
13693powerful enough to run a full-featured debugger.
13694
13695Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
13696to make this work with particular debugging targets. In addition,
5d161b24 13697@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
13698but not specific to any particular target system) which you can use if you
13699write the remote stubs---the code that runs on the remote system to
13700communicate with @value{GDBN}.
13701
13702Other remote targets may be available in your
13703configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 13704
6b2f586d 13705@menu
07f31aa6 13706* Connecting:: Connecting to a remote target
a6b151f1 13707* File Transfer:: Sending files to a remote system
6b2f586d 13708* Server:: Using the gdbserver program
79a6e687
BW
13709* Remote Configuration:: Remote configuration
13710* Remote Stub:: Implementing a remote stub
6b2f586d
AC
13711@end menu
13712
07f31aa6 13713@node Connecting
79a6e687 13714@section Connecting to a Remote Target
07f31aa6
DJ
13715
13716On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 13717your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
13718Start up @value{GDBN} as usual, using the name of the local copy of your
13719program as the first argument.
13720
86941c27
JB
13721@cindex @code{target remote}
13722@value{GDBN} can communicate with the target over a serial line, or
13723over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
13724each case, @value{GDBN} uses the same protocol for debugging your
13725program; only the medium carrying the debugging packets varies. The
13726@code{target remote} command establishes a connection to the target.
13727Its arguments indicate which medium to use:
13728
13729@table @code
13730
13731@item target remote @var{serial-device}
07f31aa6 13732@cindex serial line, @code{target remote}
86941c27
JB
13733Use @var{serial-device} to communicate with the target. For example,
13734to use a serial line connected to the device named @file{/dev/ttyb}:
13735
13736@smallexample
13737target remote /dev/ttyb
13738@end smallexample
13739
07f31aa6
DJ
13740If you're using a serial line, you may want to give @value{GDBN} the
13741@w{@samp{--baud}} option, or use the @code{set remotebaud} command
79a6e687 13742(@pxref{Remote Configuration, set remotebaud}) before the
9c16f35a 13743@code{target} command.
07f31aa6 13744
86941c27
JB
13745@item target remote @code{@var{host}:@var{port}}
13746@itemx target remote @code{tcp:@var{host}:@var{port}}
13747@cindex @acronym{TCP} port, @code{target remote}
13748Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
13749The @var{host} may be either a host name or a numeric @acronym{IP}
13750address; @var{port} must be a decimal number. The @var{host} could be
13751the target machine itself, if it is directly connected to the net, or
13752it might be a terminal server which in turn has a serial line to the
13753target.
07f31aa6 13754
86941c27
JB
13755For example, to connect to port 2828 on a terminal server named
13756@code{manyfarms}:
07f31aa6
DJ
13757
13758@smallexample
13759target remote manyfarms:2828
13760@end smallexample
13761
86941c27
JB
13762If your remote target is actually running on the same machine as your
13763debugger session (e.g.@: a simulator for your target running on the
13764same host), you can omit the hostname. For example, to connect to
13765port 1234 on your local machine:
07f31aa6
DJ
13766
13767@smallexample
13768target remote :1234
13769@end smallexample
13770@noindent
13771
13772Note that the colon is still required here.
13773
86941c27
JB
13774@item target remote @code{udp:@var{host}:@var{port}}
13775@cindex @acronym{UDP} port, @code{target remote}
13776Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
13777connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
13778
13779@smallexample
13780target remote udp:manyfarms:2828
13781@end smallexample
13782
86941c27
JB
13783When using a @acronym{UDP} connection for remote debugging, you should
13784keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
13785can silently drop packets on busy or unreliable networks, which will
13786cause havoc with your debugging session.
13787
66b8c7f6
JB
13788@item target remote | @var{command}
13789@cindex pipe, @code{target remote} to
13790Run @var{command} in the background and communicate with it using a
13791pipe. The @var{command} is a shell command, to be parsed and expanded
13792by the system's command shell, @code{/bin/sh}; it should expect remote
13793protocol packets on its standard input, and send replies on its
13794standard output. You could use this to run a stand-alone simulator
13795that speaks the remote debugging protocol, to make net connections
13796using programs like @code{ssh}, or for other similar tricks.
13797
13798If @var{command} closes its standard output (perhaps by exiting),
13799@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
13800program has already exited, this will have no effect.)
13801
86941c27 13802@end table
07f31aa6 13803
86941c27 13804Once the connection has been established, you can use all the usual
8edfe269
DJ
13805commands to examine and change data. The remote program is already
13806running; you can use @kbd{step} and @kbd{continue}, and you do not
13807need to use @kbd{run}.
07f31aa6
DJ
13808
13809@cindex interrupting remote programs
13810@cindex remote programs, interrupting
13811Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 13812interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
13813program. This may or may not succeed, depending in part on the hardware
13814and the serial drivers the remote system uses. If you type the
13815interrupt character once again, @value{GDBN} displays this prompt:
13816
13817@smallexample
13818Interrupted while waiting for the program.
13819Give up (and stop debugging it)? (y or n)
13820@end smallexample
13821
13822If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
13823(If you decide you want to try again later, you can use @samp{target
13824remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
13825goes back to waiting.
13826
13827@table @code
13828@kindex detach (remote)
13829@item detach
13830When you have finished debugging the remote program, you can use the
13831@code{detach} command to release it from @value{GDBN} control.
13832Detaching from the target normally resumes its execution, but the results
13833will depend on your particular remote stub. After the @code{detach}
13834command, @value{GDBN} is free to connect to another target.
13835
13836@kindex disconnect
13837@item disconnect
13838The @code{disconnect} command behaves like @code{detach}, except that
13839the target is generally not resumed. It will wait for @value{GDBN}
13840(this instance or another one) to connect and continue debugging. After
13841the @code{disconnect} command, @value{GDBN} is again free to connect to
13842another target.
09d4efe1
EZ
13843
13844@cindex send command to remote monitor
fad38dfa
EZ
13845@cindex extend @value{GDBN} for remote targets
13846@cindex add new commands for external monitor
09d4efe1
EZ
13847@kindex monitor
13848@item monitor @var{cmd}
fad38dfa
EZ
13849This command allows you to send arbitrary commands directly to the
13850remote monitor. Since @value{GDBN} doesn't care about the commands it
13851sends like this, this command is the way to extend @value{GDBN}---you
13852can add new commands that only the external monitor will understand
13853and implement.
07f31aa6
DJ
13854@end table
13855
a6b151f1
DJ
13856@node File Transfer
13857@section Sending files to a remote system
13858@cindex remote target, file transfer
13859@cindex file transfer
13860@cindex sending files to remote systems
13861
13862Some remote targets offer the ability to transfer files over the same
13863connection used to communicate with @value{GDBN}. This is convenient
13864for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
13865running @code{gdbserver} over a network interface. For other targets,
13866e.g.@: embedded devices with only a single serial port, this may be
13867the only way to upload or download files.
13868
13869Not all remote targets support these commands.
13870
13871@table @code
13872@kindex remote put
13873@item remote put @var{hostfile} @var{targetfile}
13874Copy file @var{hostfile} from the host system (the machine running
13875@value{GDBN}) to @var{targetfile} on the target system.
13876
13877@kindex remote get
13878@item remote get @var{targetfile} @var{hostfile}
13879Copy file @var{targetfile} from the target system to @var{hostfile}
13880on the host system.
13881
13882@kindex remote delete
13883@item remote delete @var{targetfile}
13884Delete @var{targetfile} from the target system.
13885
13886@end table
13887
6f05cf9f 13888@node Server
79a6e687 13889@section Using the @code{gdbserver} Program
6f05cf9f
AC
13890
13891@kindex gdbserver
13892@cindex remote connection without stubs
13893@code{gdbserver} is a control program for Unix-like systems, which
13894allows you to connect your program with a remote @value{GDBN} via
13895@code{target remote}---but without linking in the usual debugging stub.
13896
13897@code{gdbserver} is not a complete replacement for the debugging stubs,
13898because it requires essentially the same operating-system facilities
13899that @value{GDBN} itself does. In fact, a system that can run
13900@code{gdbserver} to connect to a remote @value{GDBN} could also run
13901@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
13902because it is a much smaller program than @value{GDBN} itself. It is
13903also easier to port than all of @value{GDBN}, so you may be able to get
13904started more quickly on a new system by using @code{gdbserver}.
13905Finally, if you develop code for real-time systems, you may find that
13906the tradeoffs involved in real-time operation make it more convenient to
13907do as much development work as possible on another system, for example
13908by cross-compiling. You can use @code{gdbserver} to make a similar
13909choice for debugging.
13910
13911@value{GDBN} and @code{gdbserver} communicate via either a serial line
13912or a TCP connection, using the standard @value{GDBN} remote serial
13913protocol.
13914
2d717e4f
DJ
13915@quotation
13916@emph{Warning:} @code{gdbserver} does not have any built-in security.
13917Do not run @code{gdbserver} connected to any public network; a
13918@value{GDBN} connection to @code{gdbserver} provides access to the
13919target system with the same privileges as the user running
13920@code{gdbserver}.
13921@end quotation
13922
13923@subsection Running @code{gdbserver}
13924@cindex arguments, to @code{gdbserver}
13925
13926Run @code{gdbserver} on the target system. You need a copy of the
13927program you want to debug, including any libraries it requires.
6f05cf9f
AC
13928@code{gdbserver} does not need your program's symbol table, so you can
13929strip the program if necessary to save space. @value{GDBN} on the host
13930system does all the symbol handling.
13931
13932To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 13933the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
13934syntax is:
13935
13936@smallexample
13937target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
13938@end smallexample
13939
13940@var{comm} is either a device name (to use a serial line) or a TCP
13941hostname and portnumber. For example, to debug Emacs with the argument
13942@samp{foo.txt} and communicate with @value{GDBN} over the serial port
13943@file{/dev/com1}:
13944
13945@smallexample
13946target> gdbserver /dev/com1 emacs foo.txt
13947@end smallexample
13948
13949@code{gdbserver} waits passively for the host @value{GDBN} to communicate
13950with it.
13951
13952To use a TCP connection instead of a serial line:
13953
13954@smallexample
13955target> gdbserver host:2345 emacs foo.txt
13956@end smallexample
13957
13958The only difference from the previous example is the first argument,
13959specifying that you are communicating with the host @value{GDBN} via
13960TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
13961expect a TCP connection from machine @samp{host} to local TCP port 2345.
13962(Currently, the @samp{host} part is ignored.) You can choose any number
13963you want for the port number as long as it does not conflict with any
13964TCP ports already in use on the target system (for example, @code{23} is
13965reserved for @code{telnet}).@footnote{If you choose a port number that
13966conflicts with another service, @code{gdbserver} prints an error message
13967and exits.} You must use the same port number with the host @value{GDBN}
13968@code{target remote} command.
13969
2d717e4f
DJ
13970@subsubsection Attaching to a Running Program
13971
56460a61
DJ
13972On some targets, @code{gdbserver} can also attach to running programs.
13973This is accomplished via the @code{--attach} argument. The syntax is:
13974
13975@smallexample
2d717e4f 13976target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
13977@end smallexample
13978
13979@var{pid} is the process ID of a currently running process. It isn't necessary
13980to point @code{gdbserver} at a binary for the running process.
13981
b1fe9455
DJ
13982@pindex pidof
13983@cindex attach to a program by name
13984You can debug processes by name instead of process ID if your target has the
13985@code{pidof} utility:
13986
13987@smallexample
2d717e4f 13988target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
13989@end smallexample
13990
f822c95b 13991In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
13992has multiple threads, most versions of @code{pidof} support the
13993@code{-s} option to only return the first process ID.
13994
2d717e4f
DJ
13995@subsubsection Multi-Process Mode for @code{gdbserver}
13996@cindex gdbserver, multiple processes
13997@cindex multiple processes with gdbserver
13998
13999When you connect to @code{gdbserver} using @code{target remote},
14000@code{gdbserver} debugs the specified program only once. When the
14001program exits, or you detach from it, @value{GDBN} closes the connection
14002and @code{gdbserver} exits.
14003
6e6c6f50 14004If you connect using @kbd{target extended-remote}, @code{gdbserver}
2d717e4f
DJ
14005enters multi-process mode. When the debugged program exits, or you
14006detach from it, @value{GDBN} stays connected to @code{gdbserver} even
14007though no program is running. The @code{run} and @code{attach}
14008commands instruct @code{gdbserver} to run or attach to a new program.
14009The @code{run} command uses @code{set remote exec-file} (@pxref{set
14010remote exec-file}) to select the program to run. Command line
14011arguments are supported, except for wildcard expansion and I/O
14012redirection (@pxref{Arguments}).
14013
14014To start @code{gdbserver} without supplying an initial command to run
14015or process ID to attach, use the @option{--multi} command line option.
6e6c6f50 14016Then you can connect using @kbd{target extended-remote} and start
2d717e4f
DJ
14017the program you want to debug.
14018
14019@code{gdbserver} does not automatically exit in multi-process mode.
14020You can terminate it by using @code{monitor exit}
14021(@pxref{Monitor Commands for gdbserver}).
14022
14023@subsubsection Other Command-Line Arguments for @code{gdbserver}
14024
14025You can include @option{--debug} on the @code{gdbserver} command line.
14026@code{gdbserver} will display extra status information about the debugging
14027process. This option is intended for @code{gdbserver} development and
14028for bug reports to the developers.
14029
ccd213ac
DJ
14030The @option{--wrapper} option specifies a wrapper to launch programs
14031for debugging. The option should be followed by the name of the
14032wrapper, then any command-line arguments to pass to the wrapper, then
14033@kbd{--} indicating the end of the wrapper arguments.
14034
14035@code{gdbserver} runs the specified wrapper program with a combined
14036command line including the wrapper arguments, then the name of the
14037program to debug, then any arguments to the program. The wrapper
14038runs until it executes your program, and then @value{GDBN} gains control.
14039
14040You can use any program that eventually calls @code{execve} with
14041its arguments as a wrapper. Several standard Unix utilities do
14042this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
14043with @code{exec "$@@"} will also work.
14044
14045For example, you can use @code{env} to pass an environment variable to
14046the debugged program, without setting the variable in @code{gdbserver}'s
14047environment:
14048
14049@smallexample
14050$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
14051@end smallexample
14052
2d717e4f
DJ
14053@subsection Connecting to @code{gdbserver}
14054
14055Run @value{GDBN} on the host system.
14056
14057First make sure you have the necessary symbol files. Load symbols for
f822c95b
DJ
14058your application using the @code{file} command before you connect. Use
14059@code{set sysroot} to locate target libraries (unless your @value{GDBN}
2d717e4f 14060was compiled with the correct sysroot using @code{--with-sysroot}).
f822c95b
DJ
14061
14062The symbol file and target libraries must exactly match the executable
14063and libraries on the target, with one exception: the files on the host
14064system should not be stripped, even if the files on the target system
14065are. Mismatched or missing files will lead to confusing results
14066during debugging. On @sc{gnu}/Linux targets, mismatched or missing
14067files may also prevent @code{gdbserver} from debugging multi-threaded
14068programs.
14069
79a6e687 14070Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
14071For TCP connections, you must start up @code{gdbserver} prior to using
14072the @code{target remote} command. Otherwise you may get an error whose
14073text depends on the host system, but which usually looks something like
2d717e4f 14074@samp{Connection refused}. Don't use the @code{load}
397ca115 14075command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 14076already on the target.
07f31aa6 14077
79a6e687 14078@subsection Monitor Commands for @code{gdbserver}
c74d0ad8 14079@cindex monitor commands, for @code{gdbserver}
2d717e4f 14080@anchor{Monitor Commands for gdbserver}
c74d0ad8
DJ
14081
14082During a @value{GDBN} session using @code{gdbserver}, you can use the
14083@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 14084Here are the available commands.
c74d0ad8
DJ
14085
14086@table @code
14087@item monitor help
14088List the available monitor commands.
14089
14090@item monitor set debug 0
14091@itemx monitor set debug 1
14092Disable or enable general debugging messages.
14093
14094@item monitor set remote-debug 0
14095@itemx monitor set remote-debug 1
14096Disable or enable specific debugging messages associated with the remote
14097protocol (@pxref{Remote Protocol}).
14098
2d717e4f
DJ
14099@item monitor exit
14100Tell gdbserver to exit immediately. This command should be followed by
14101@code{disconnect} to close the debugging session. @code{gdbserver} will
14102detach from any attached processes and kill any processes it created.
14103Use @code{monitor exit} to terminate @code{gdbserver} at the end
14104of a multi-process mode debug session.
14105
c74d0ad8
DJ
14106@end table
14107
79a6e687
BW
14108@node Remote Configuration
14109@section Remote Configuration
501eef12 14110
9c16f35a
EZ
14111@kindex set remote
14112@kindex show remote
14113This section documents the configuration options available when
14114debugging remote programs. For the options related to the File I/O
fc320d37 14115extensions of the remote protocol, see @ref{system,
9c16f35a 14116system-call-allowed}.
501eef12
AC
14117
14118@table @code
9c16f35a 14119@item set remoteaddresssize @var{bits}
d3e8051b 14120@cindex address size for remote targets
9c16f35a
EZ
14121@cindex bits in remote address
14122Set the maximum size of address in a memory packet to the specified
14123number of bits. @value{GDBN} will mask off the address bits above
14124that number, when it passes addresses to the remote target. The
14125default value is the number of bits in the target's address.
14126
14127@item show remoteaddresssize
14128Show the current value of remote address size in bits.
14129
14130@item set remotebaud @var{n}
14131@cindex baud rate for remote targets
14132Set the baud rate for the remote serial I/O to @var{n} baud. The
14133value is used to set the speed of the serial port used for debugging
14134remote targets.
14135
14136@item show remotebaud
14137Show the current speed of the remote connection.
14138
14139@item set remotebreak
14140@cindex interrupt remote programs
14141@cindex BREAK signal instead of Ctrl-C
9a6253be 14142@anchor{set remotebreak}
9c16f35a 14143If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 14144when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 14145on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
14146character instead. The default is off, since most remote systems
14147expect to see @samp{Ctrl-C} as the interrupt signal.
14148
14149@item show remotebreak
14150Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
14151interrupt the remote program.
14152
23776285
MR
14153@item set remoteflow on
14154@itemx set remoteflow off
14155@kindex set remoteflow
14156Enable or disable hardware flow control (@code{RTS}/@code{CTS})
14157on the serial port used to communicate to the remote target.
14158
14159@item show remoteflow
14160@kindex show remoteflow
14161Show the current setting of hardware flow control.
14162
9c16f35a
EZ
14163@item set remotelogbase @var{base}
14164Set the base (a.k.a.@: radix) of logging serial protocol
14165communications to @var{base}. Supported values of @var{base} are:
14166@code{ascii}, @code{octal}, and @code{hex}. The default is
14167@code{ascii}.
14168
14169@item show remotelogbase
14170Show the current setting of the radix for logging remote serial
14171protocol.
14172
14173@item set remotelogfile @var{file}
14174@cindex record serial communications on file
14175Record remote serial communications on the named @var{file}. The
14176default is not to record at all.
14177
14178@item show remotelogfile.
14179Show the current setting of the file name on which to record the
14180serial communications.
14181
14182@item set remotetimeout @var{num}
14183@cindex timeout for serial communications
14184@cindex remote timeout
14185Set the timeout limit to wait for the remote target to respond to
14186@var{num} seconds. The default is 2 seconds.
14187
14188@item show remotetimeout
14189Show the current number of seconds to wait for the remote target
14190responses.
14191
14192@cindex limit hardware breakpoints and watchpoints
14193@cindex remote target, limit break- and watchpoints
501eef12
AC
14194@anchor{set remote hardware-watchpoint-limit}
14195@anchor{set remote hardware-breakpoint-limit}
14196@item set remote hardware-watchpoint-limit @var{limit}
14197@itemx set remote hardware-breakpoint-limit @var{limit}
14198Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
14199watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f
DJ
14200
14201@item set remote exec-file @var{filename}
14202@itemx show remote exec-file
14203@anchor{set remote exec-file}
14204@cindex executable file, for remote target
14205Select the file used for @code{run} with @code{target
14206extended-remote}. This should be set to a filename valid on the
14207target system. If it is not set, the target will use a default
14208filename (e.g.@: the last program run).
84603566
SL
14209
14210@kindex set tcp
14211@kindex show tcp
14212@item set tcp auto-retry on
14213@cindex auto-retry, for remote TCP target
14214Enable auto-retry for remote TCP connections. This is useful if the remote
14215debugging agent is launched in parallel with @value{GDBN}; there is a race
14216condition because the agent may not become ready to accept the connection
14217before @value{GDBN} attempts to connect. When auto-retry is
14218enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
14219to establish the connection using the timeout specified by
14220@code{set tcp connect-timeout}.
14221
14222@item set tcp auto-retry off
14223Do not auto-retry failed TCP connections.
14224
14225@item show tcp auto-retry
14226Show the current auto-retry setting.
14227
14228@item set tcp connect-timeout @var{seconds}
14229@cindex connection timeout, for remote TCP target
14230@cindex timeout, for remote target connection
14231Set the timeout for establishing a TCP connection to the remote target to
14232@var{seconds}. The timeout affects both polling to retry failed connections
14233(enabled by @code{set tcp auto-retry on}) and waiting for connections
14234that are merely slow to complete, and represents an approximate cumulative
14235value.
14236
14237@item show tcp connect-timeout
14238Show the current connection timeout setting.
501eef12
AC
14239@end table
14240
427c3a89
DJ
14241@cindex remote packets, enabling and disabling
14242The @value{GDBN} remote protocol autodetects the packets supported by
14243your debugging stub. If you need to override the autodetection, you
14244can use these commands to enable or disable individual packets. Each
14245packet can be set to @samp{on} (the remote target supports this
14246packet), @samp{off} (the remote target does not support this packet),
14247or @samp{auto} (detect remote target support for this packet). They
14248all default to @samp{auto}. For more information about each packet,
14249see @ref{Remote Protocol}.
14250
14251During normal use, you should not have to use any of these commands.
14252If you do, that may be a bug in your remote debugging stub, or a bug
14253in @value{GDBN}. You may want to report the problem to the
14254@value{GDBN} developers.
14255
cfa9d6d9
DJ
14256For each packet @var{name}, the command to enable or disable the
14257packet is @code{set remote @var{name}-packet}. The available settings
14258are:
427c3a89 14259
cfa9d6d9 14260@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
14261@item Command Name
14262@tab Remote Packet
14263@tab Related Features
14264
cfa9d6d9 14265@item @code{fetch-register}
427c3a89
DJ
14266@tab @code{p}
14267@tab @code{info registers}
14268
cfa9d6d9 14269@item @code{set-register}
427c3a89
DJ
14270@tab @code{P}
14271@tab @code{set}
14272
cfa9d6d9 14273@item @code{binary-download}
427c3a89
DJ
14274@tab @code{X}
14275@tab @code{load}, @code{set}
14276
cfa9d6d9 14277@item @code{read-aux-vector}
427c3a89
DJ
14278@tab @code{qXfer:auxv:read}
14279@tab @code{info auxv}
14280
cfa9d6d9 14281@item @code{symbol-lookup}
427c3a89
DJ
14282@tab @code{qSymbol}
14283@tab Detecting multiple threads
14284
2d717e4f
DJ
14285@item @code{attach}
14286@tab @code{vAttach}
14287@tab @code{attach}
14288
cfa9d6d9 14289@item @code{verbose-resume}
427c3a89
DJ
14290@tab @code{vCont}
14291@tab Stepping or resuming multiple threads
14292
2d717e4f
DJ
14293@item @code{run}
14294@tab @code{vRun}
14295@tab @code{run}
14296
cfa9d6d9 14297@item @code{software-breakpoint}
427c3a89
DJ
14298@tab @code{Z0}
14299@tab @code{break}
14300
cfa9d6d9 14301@item @code{hardware-breakpoint}
427c3a89
DJ
14302@tab @code{Z1}
14303@tab @code{hbreak}
14304
cfa9d6d9 14305@item @code{write-watchpoint}
427c3a89
DJ
14306@tab @code{Z2}
14307@tab @code{watch}
14308
cfa9d6d9 14309@item @code{read-watchpoint}
427c3a89
DJ
14310@tab @code{Z3}
14311@tab @code{rwatch}
14312
cfa9d6d9 14313@item @code{access-watchpoint}
427c3a89
DJ
14314@tab @code{Z4}
14315@tab @code{awatch}
14316
cfa9d6d9
DJ
14317@item @code{target-features}
14318@tab @code{qXfer:features:read}
14319@tab @code{set architecture}
14320
14321@item @code{library-info}
14322@tab @code{qXfer:libraries:read}
14323@tab @code{info sharedlibrary}
14324
14325@item @code{memory-map}
14326@tab @code{qXfer:memory-map:read}
14327@tab @code{info mem}
14328
14329@item @code{read-spu-object}
14330@tab @code{qXfer:spu:read}
14331@tab @code{info spu}
14332
14333@item @code{write-spu-object}
14334@tab @code{qXfer:spu:write}
14335@tab @code{info spu}
14336
14337@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
14338@tab @code{qGetTLSAddr}
14339@tab Displaying @code{__thread} variables
14340
08388c79
DE
14341@item @code{search-memory}
14342@tab @code{qSearch:memory}
14343@tab @code{find}
14344
427c3a89
DJ
14345@item @code{supported-packets}
14346@tab @code{qSupported}
14347@tab Remote communications parameters
14348
cfa9d6d9 14349@item @code{pass-signals}
89be2091
DJ
14350@tab @code{QPassSignals}
14351@tab @code{handle @var{signal}}
14352
a6b151f1
DJ
14353@item @code{hostio-close-packet}
14354@tab @code{vFile:close}
14355@tab @code{remote get}, @code{remote put}
14356
14357@item @code{hostio-open-packet}
14358@tab @code{vFile:open}
14359@tab @code{remote get}, @code{remote put}
14360
14361@item @code{hostio-pread-packet}
14362@tab @code{vFile:pread}
14363@tab @code{remote get}, @code{remote put}
14364
14365@item @code{hostio-pwrite-packet}
14366@tab @code{vFile:pwrite}
14367@tab @code{remote get}, @code{remote put}
14368
14369@item @code{hostio-unlink-packet}
14370@tab @code{vFile:unlink}
14371@tab @code{remote delete}
a6f3e723
SL
14372
14373@item @code{noack-packet}
14374@tab @code{QStartNoAckMode}
14375@tab Packet acknowledgment
07e059b5
VP
14376
14377@item @code{osdata}
14378@tab @code{qXfer:osdata:read}
14379@tab @code{info os}
427c3a89
DJ
14380@end multitable
14381
79a6e687
BW
14382@node Remote Stub
14383@section Implementing a Remote Stub
7a292a7a 14384
8e04817f
AC
14385@cindex debugging stub, example
14386@cindex remote stub, example
14387@cindex stub example, remote debugging
14388The stub files provided with @value{GDBN} implement the target side of the
14389communication protocol, and the @value{GDBN} side is implemented in the
14390@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
14391these subroutines to communicate, and ignore the details. (If you're
14392implementing your own stub file, you can still ignore the details: start
14393with one of the existing stub files. @file{sparc-stub.c} is the best
14394organized, and therefore the easiest to read.)
14395
104c1213
JM
14396@cindex remote serial debugging, overview
14397To debug a program running on another machine (the debugging
14398@dfn{target} machine), you must first arrange for all the usual
14399prerequisites for the program to run by itself. For example, for a C
14400program, you need:
c906108c 14401
104c1213
JM
14402@enumerate
14403@item
14404A startup routine to set up the C runtime environment; these usually
14405have a name like @file{crt0}. The startup routine may be supplied by
14406your hardware supplier, or you may have to write your own.
96baa820 14407
5d161b24 14408@item
d4f3574e 14409A C subroutine library to support your program's
104c1213 14410subroutine calls, notably managing input and output.
96baa820 14411
104c1213
JM
14412@item
14413A way of getting your program to the other machine---for example, a
14414download program. These are often supplied by the hardware
14415manufacturer, but you may have to write your own from hardware
14416documentation.
14417@end enumerate
96baa820 14418
104c1213
JM
14419The next step is to arrange for your program to use a serial port to
14420communicate with the machine where @value{GDBN} is running (the @dfn{host}
14421machine). In general terms, the scheme looks like this:
96baa820 14422
104c1213
JM
14423@table @emph
14424@item On the host,
14425@value{GDBN} already understands how to use this protocol; when everything
14426else is set up, you can simply use the @samp{target remote} command
14427(@pxref{Targets,,Specifying a Debugging Target}).
14428
14429@item On the target,
14430you must link with your program a few special-purpose subroutines that
14431implement the @value{GDBN} remote serial protocol. The file containing these
14432subroutines is called a @dfn{debugging stub}.
14433
14434On certain remote targets, you can use an auxiliary program
14435@code{gdbserver} instead of linking a stub into your program.
79a6e687 14436@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 14437@end table
96baa820 14438
104c1213
JM
14439The debugging stub is specific to the architecture of the remote
14440machine; for example, use @file{sparc-stub.c} to debug programs on
14441@sc{sparc} boards.
96baa820 14442
104c1213
JM
14443@cindex remote serial stub list
14444These working remote stubs are distributed with @value{GDBN}:
96baa820 14445
104c1213
JM
14446@table @code
14447
14448@item i386-stub.c
41afff9a 14449@cindex @file{i386-stub.c}
104c1213
JM
14450@cindex Intel
14451@cindex i386
14452For Intel 386 and compatible architectures.
14453
14454@item m68k-stub.c
41afff9a 14455@cindex @file{m68k-stub.c}
104c1213
JM
14456@cindex Motorola 680x0
14457@cindex m680x0
14458For Motorola 680x0 architectures.
14459
14460@item sh-stub.c
41afff9a 14461@cindex @file{sh-stub.c}
172c2a43 14462@cindex Renesas
104c1213 14463@cindex SH
172c2a43 14464For Renesas SH architectures.
104c1213
JM
14465
14466@item sparc-stub.c
41afff9a 14467@cindex @file{sparc-stub.c}
104c1213
JM
14468@cindex Sparc
14469For @sc{sparc} architectures.
14470
14471@item sparcl-stub.c
41afff9a 14472@cindex @file{sparcl-stub.c}
104c1213
JM
14473@cindex Fujitsu
14474@cindex SparcLite
14475For Fujitsu @sc{sparclite} architectures.
14476
14477@end table
14478
14479The @file{README} file in the @value{GDBN} distribution may list other
14480recently added stubs.
14481
14482@menu
14483* Stub Contents:: What the stub can do for you
14484* Bootstrapping:: What you must do for the stub
14485* Debug Session:: Putting it all together
104c1213
JM
14486@end menu
14487
6d2ebf8b 14488@node Stub Contents
79a6e687 14489@subsection What the Stub Can Do for You
104c1213
JM
14490
14491@cindex remote serial stub
14492The debugging stub for your architecture supplies these three
14493subroutines:
14494
14495@table @code
14496@item set_debug_traps
4644b6e3 14497@findex set_debug_traps
104c1213
JM
14498@cindex remote serial stub, initialization
14499This routine arranges for @code{handle_exception} to run when your
14500program stops. You must call this subroutine explicitly near the
14501beginning of your program.
14502
14503@item handle_exception
4644b6e3 14504@findex handle_exception
104c1213
JM
14505@cindex remote serial stub, main routine
14506This is the central workhorse, but your program never calls it
14507explicitly---the setup code arranges for @code{handle_exception} to
14508run when a trap is triggered.
14509
14510@code{handle_exception} takes control when your program stops during
14511execution (for example, on a breakpoint), and mediates communications
14512with @value{GDBN} on the host machine. This is where the communications
14513protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 14514representative on the target machine. It begins by sending summary
104c1213
JM
14515information on the state of your program, then continues to execute,
14516retrieving and transmitting any information @value{GDBN} needs, until you
14517execute a @value{GDBN} command that makes your program resume; at that point,
14518@code{handle_exception} returns control to your own code on the target
5d161b24 14519machine.
104c1213
JM
14520
14521@item breakpoint
14522@cindex @code{breakpoint} subroutine, remote
14523Use this auxiliary subroutine to make your program contain a
14524breakpoint. Depending on the particular situation, this may be the only
14525way for @value{GDBN} to get control. For instance, if your target
14526machine has some sort of interrupt button, you won't need to call this;
14527pressing the interrupt button transfers control to
14528@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
14529simply receiving characters on the serial port may also trigger a trap;
14530again, in that situation, you don't need to call @code{breakpoint} from
14531your own program---simply running @samp{target remote} from the host
5d161b24 14532@value{GDBN} session gets control.
104c1213
JM
14533
14534Call @code{breakpoint} if none of these is true, or if you simply want
14535to make certain your program stops at a predetermined point for the
14536start of your debugging session.
14537@end table
14538
6d2ebf8b 14539@node Bootstrapping
79a6e687 14540@subsection What You Must Do for the Stub
104c1213
JM
14541
14542@cindex remote stub, support routines
14543The debugging stubs that come with @value{GDBN} are set up for a particular
14544chip architecture, but they have no information about the rest of your
14545debugging target machine.
14546
14547First of all you need to tell the stub how to communicate with the
14548serial port.
14549
14550@table @code
14551@item int getDebugChar()
4644b6e3 14552@findex getDebugChar
104c1213
JM
14553Write this subroutine to read a single character from the serial port.
14554It may be identical to @code{getchar} for your target system; a
14555different name is used to allow you to distinguish the two if you wish.
14556
14557@item void putDebugChar(int)
4644b6e3 14558@findex putDebugChar
104c1213 14559Write this subroutine to write a single character to the serial port.
5d161b24 14560It may be identical to @code{putchar} for your target system; a
104c1213
JM
14561different name is used to allow you to distinguish the two if you wish.
14562@end table
14563
14564@cindex control C, and remote debugging
14565@cindex interrupting remote targets
14566If you want @value{GDBN} to be able to stop your program while it is
14567running, you need to use an interrupt-driven serial driver, and arrange
14568for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
14569character). That is the character which @value{GDBN} uses to tell the
14570remote system to stop.
14571
14572Getting the debugging target to return the proper status to @value{GDBN}
14573probably requires changes to the standard stub; one quick and dirty way
14574is to just execute a breakpoint instruction (the ``dirty'' part is that
14575@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
14576
14577Other routines you need to supply are:
14578
14579@table @code
14580@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 14581@findex exceptionHandler
104c1213
JM
14582Write this function to install @var{exception_address} in the exception
14583handling tables. You need to do this because the stub does not have any
14584way of knowing what the exception handling tables on your target system
14585are like (for example, the processor's table might be in @sc{rom},
14586containing entries which point to a table in @sc{ram}).
14587@var{exception_number} is the exception number which should be changed;
14588its meaning is architecture-dependent (for example, different numbers
14589might represent divide by zero, misaligned access, etc). When this
14590exception occurs, control should be transferred directly to
14591@var{exception_address}, and the processor state (stack, registers,
14592and so on) should be just as it is when a processor exception occurs. So if
14593you want to use a jump instruction to reach @var{exception_address}, it
14594should be a simple jump, not a jump to subroutine.
14595
14596For the 386, @var{exception_address} should be installed as an interrupt
14597gate so that interrupts are masked while the handler runs. The gate
14598should be at privilege level 0 (the most privileged level). The
14599@sc{sparc} and 68k stubs are able to mask interrupts themselves without
14600help from @code{exceptionHandler}.
14601
14602@item void flush_i_cache()
4644b6e3 14603@findex flush_i_cache
d4f3574e 14604On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
14605instruction cache, if any, on your target machine. If there is no
14606instruction cache, this subroutine may be a no-op.
14607
14608On target machines that have instruction caches, @value{GDBN} requires this
14609function to make certain that the state of your program is stable.
14610@end table
14611
14612@noindent
14613You must also make sure this library routine is available:
14614
14615@table @code
14616@item void *memset(void *, int, int)
4644b6e3 14617@findex memset
104c1213
JM
14618This is the standard library function @code{memset} that sets an area of
14619memory to a known value. If you have one of the free versions of
14620@code{libc.a}, @code{memset} can be found there; otherwise, you must
14621either obtain it from your hardware manufacturer, or write your own.
14622@end table
14623
14624If you do not use the GNU C compiler, you may need other standard
14625library subroutines as well; this varies from one stub to another,
14626but in general the stubs are likely to use any of the common library
e22ea452 14627subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
14628
14629
6d2ebf8b 14630@node Debug Session
79a6e687 14631@subsection Putting it All Together
104c1213
JM
14632
14633@cindex remote serial debugging summary
14634In summary, when your program is ready to debug, you must follow these
14635steps.
14636
14637@enumerate
14638@item
6d2ebf8b 14639Make sure you have defined the supporting low-level routines
79a6e687 14640(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
14641@display
14642@code{getDebugChar}, @code{putDebugChar},
14643@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
14644@end display
14645
14646@item
14647Insert these lines near the top of your program:
14648
474c8240 14649@smallexample
104c1213
JM
14650set_debug_traps();
14651breakpoint();
474c8240 14652@end smallexample
104c1213
JM
14653
14654@item
14655For the 680x0 stub only, you need to provide a variable called
14656@code{exceptionHook}. Normally you just use:
14657
474c8240 14658@smallexample
104c1213 14659void (*exceptionHook)() = 0;
474c8240 14660@end smallexample
104c1213 14661
d4f3574e 14662@noindent
104c1213 14663but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 14664function in your program, that function is called when
104c1213
JM
14665@code{@value{GDBN}} continues after stopping on a trap (for example, bus
14666error). The function indicated by @code{exceptionHook} is called with
14667one parameter: an @code{int} which is the exception number.
14668
14669@item
14670Compile and link together: your program, the @value{GDBN} debugging stub for
14671your target architecture, and the supporting subroutines.
14672
14673@item
14674Make sure you have a serial connection between your target machine and
14675the @value{GDBN} host, and identify the serial port on the host.
14676
14677@item
14678@c The "remote" target now provides a `load' command, so we should
14679@c document that. FIXME.
14680Download your program to your target machine (or get it there by
14681whatever means the manufacturer provides), and start it.
14682
14683@item
07f31aa6 14684Start @value{GDBN} on the host, and connect to the target
79a6e687 14685(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 14686
104c1213
JM
14687@end enumerate
14688
8e04817f
AC
14689@node Configurations
14690@chapter Configuration-Specific Information
104c1213 14691
8e04817f
AC
14692While nearly all @value{GDBN} commands are available for all native and
14693cross versions of the debugger, there are some exceptions. This chapter
14694describes things that are only available in certain configurations.
104c1213 14695
8e04817f
AC
14696There are three major categories of configurations: native
14697configurations, where the host and target are the same, embedded
14698operating system configurations, which are usually the same for several
14699different processor architectures, and bare embedded processors, which
14700are quite different from each other.
104c1213 14701
8e04817f
AC
14702@menu
14703* Native::
14704* Embedded OS::
14705* Embedded Processors::
14706* Architectures::
14707@end menu
104c1213 14708
8e04817f
AC
14709@node Native
14710@section Native
104c1213 14711
8e04817f
AC
14712This section describes details specific to particular native
14713configurations.
6cf7e474 14714
8e04817f
AC
14715@menu
14716* HP-UX:: HP-UX
7561d450 14717* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
14718* SVR4 Process Information:: SVR4 process information
14719* DJGPP Native:: Features specific to the DJGPP port
78c47bea 14720* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 14721* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 14722* Neutrino:: Features specific to QNX Neutrino
a80b95ba 14723* Darwin:: Features specific to Darwin
8e04817f 14724@end menu
6cf7e474 14725
8e04817f
AC
14726@node HP-UX
14727@subsection HP-UX
104c1213 14728
8e04817f
AC
14729On HP-UX systems, if you refer to a function or variable name that
14730begins with a dollar sign, @value{GDBN} searches for a user or system
14731name first, before it searches for a convenience variable.
104c1213 14732
9c16f35a 14733
7561d450
MK
14734@node BSD libkvm Interface
14735@subsection BSD libkvm Interface
14736
14737@cindex libkvm
14738@cindex kernel memory image
14739@cindex kernel crash dump
14740
14741BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
14742interface that provides a uniform interface for accessing kernel virtual
14743memory images, including live systems and crash dumps. @value{GDBN}
14744uses this interface to allow you to debug live kernels and kernel crash
14745dumps on many native BSD configurations. This is implemented as a
14746special @code{kvm} debugging target. For debugging a live system, load
14747the currently running kernel into @value{GDBN} and connect to the
14748@code{kvm} target:
14749
14750@smallexample
14751(@value{GDBP}) @b{target kvm}
14752@end smallexample
14753
14754For debugging crash dumps, provide the file name of the crash dump as an
14755argument:
14756
14757@smallexample
14758(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
14759@end smallexample
14760
14761Once connected to the @code{kvm} target, the following commands are
14762available:
14763
14764@table @code
14765@kindex kvm
14766@item kvm pcb
721c2651 14767Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
14768
14769@item kvm proc
14770Set current context from proc address. This command isn't available on
14771modern FreeBSD systems.
14772@end table
14773
8e04817f 14774@node SVR4 Process Information
79a6e687 14775@subsection SVR4 Process Information
60bf7e09
EZ
14776@cindex /proc
14777@cindex examine process image
14778@cindex process info via @file{/proc}
104c1213 14779
60bf7e09
EZ
14780Many versions of SVR4 and compatible systems provide a facility called
14781@samp{/proc} that can be used to examine the image of a running
14782process using file-system subroutines. If @value{GDBN} is configured
14783for an operating system with this facility, the command @code{info
14784proc} is available to report information about the process running
14785your program, or about any process running on your system. @code{info
14786proc} works only on SVR4 systems that include the @code{procfs} code.
14787This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
14788Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 14789
8e04817f
AC
14790@table @code
14791@kindex info proc
60bf7e09 14792@cindex process ID
8e04817f 14793@item info proc
60bf7e09
EZ
14794@itemx info proc @var{process-id}
14795Summarize available information about any running process. If a
14796process ID is specified by @var{process-id}, display information about
14797that process; otherwise display information about the program being
14798debugged. The summary includes the debugged process ID, the command
14799line used to invoke it, its current working directory, and its
14800executable file's absolute file name.
14801
14802On some systems, @var{process-id} can be of the form
14803@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
14804within a process. If the optional @var{pid} part is missing, it means
14805a thread from the process being debugged (the leading @samp{/} still
14806needs to be present, or else @value{GDBN} will interpret the number as
14807a process ID rather than a thread ID).
6cf7e474 14808
8e04817f 14809@item info proc mappings
60bf7e09
EZ
14810@cindex memory address space mappings
14811Report the memory address space ranges accessible in the program, with
14812information on whether the process has read, write, or execute access
14813rights to each range. On @sc{gnu}/Linux systems, each memory range
14814includes the object file which is mapped to that range, instead of the
14815memory access rights to that range.
14816
14817@item info proc stat
14818@itemx info proc status
14819@cindex process detailed status information
14820These subcommands are specific to @sc{gnu}/Linux systems. They show
14821the process-related information, including the user ID and group ID;
14822how many threads are there in the process; its virtual memory usage;
14823the signals that are pending, blocked, and ignored; its TTY; its
14824consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 14825value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
14826(type @kbd{man 5 proc} from your shell prompt).
14827
14828@item info proc all
14829Show all the information about the process described under all of the
14830above @code{info proc} subcommands.
14831
8e04817f
AC
14832@ignore
14833@comment These sub-options of 'info proc' were not included when
14834@comment procfs.c was re-written. Keep their descriptions around
14835@comment against the day when someone finds the time to put them back in.
14836@kindex info proc times
14837@item info proc times
14838Starting time, user CPU time, and system CPU time for your program and
14839its children.
6cf7e474 14840
8e04817f
AC
14841@kindex info proc id
14842@item info proc id
14843Report on the process IDs related to your program: its own process ID,
14844the ID of its parent, the process group ID, and the session ID.
8e04817f 14845@end ignore
721c2651
EZ
14846
14847@item set procfs-trace
14848@kindex set procfs-trace
14849@cindex @code{procfs} API calls
14850This command enables and disables tracing of @code{procfs} API calls.
14851
14852@item show procfs-trace
14853@kindex show procfs-trace
14854Show the current state of @code{procfs} API call tracing.
14855
14856@item set procfs-file @var{file}
14857@kindex set procfs-file
14858Tell @value{GDBN} to write @code{procfs} API trace to the named
14859@var{file}. @value{GDBN} appends the trace info to the previous
14860contents of the file. The default is to display the trace on the
14861standard output.
14862
14863@item show procfs-file
14864@kindex show procfs-file
14865Show the file to which @code{procfs} API trace is written.
14866
14867@item proc-trace-entry
14868@itemx proc-trace-exit
14869@itemx proc-untrace-entry
14870@itemx proc-untrace-exit
14871@kindex proc-trace-entry
14872@kindex proc-trace-exit
14873@kindex proc-untrace-entry
14874@kindex proc-untrace-exit
14875These commands enable and disable tracing of entries into and exits
14876from the @code{syscall} interface.
14877
14878@item info pidlist
14879@kindex info pidlist
14880@cindex process list, QNX Neutrino
14881For QNX Neutrino only, this command displays the list of all the
14882processes and all the threads within each process.
14883
14884@item info meminfo
14885@kindex info meminfo
14886@cindex mapinfo list, QNX Neutrino
14887For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 14888@end table
104c1213 14889
8e04817f
AC
14890@node DJGPP Native
14891@subsection Features for Debugging @sc{djgpp} Programs
14892@cindex @sc{djgpp} debugging
14893@cindex native @sc{djgpp} debugging
14894@cindex MS-DOS-specific commands
104c1213 14895
514c4d71
EZ
14896@cindex DPMI
14897@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
14898MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
14899that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
14900top of real-mode DOS systems and their emulations.
104c1213 14901
8e04817f
AC
14902@value{GDBN} supports native debugging of @sc{djgpp} programs, and
14903defines a few commands specific to the @sc{djgpp} port. This
14904subsection describes those commands.
104c1213 14905
8e04817f
AC
14906@table @code
14907@kindex info dos
14908@item info dos
14909This is a prefix of @sc{djgpp}-specific commands which print
14910information about the target system and important OS structures.
f1251bdd 14911
8e04817f
AC
14912@kindex sysinfo
14913@cindex MS-DOS system info
14914@cindex free memory information (MS-DOS)
14915@item info dos sysinfo
14916This command displays assorted information about the underlying
14917platform: the CPU type and features, the OS version and flavor, the
14918DPMI version, and the available conventional and DPMI memory.
104c1213 14919
8e04817f
AC
14920@cindex GDT
14921@cindex LDT
14922@cindex IDT
14923@cindex segment descriptor tables
14924@cindex descriptor tables display
14925@item info dos gdt
14926@itemx info dos ldt
14927@itemx info dos idt
14928These 3 commands display entries from, respectively, Global, Local,
14929and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
14930tables are data structures which store a descriptor for each segment
14931that is currently in use. The segment's selector is an index into a
14932descriptor table; the table entry for that index holds the
14933descriptor's base address and limit, and its attributes and access
14934rights.
104c1213 14935
8e04817f
AC
14936A typical @sc{djgpp} program uses 3 segments: a code segment, a data
14937segment (used for both data and the stack), and a DOS segment (which
14938allows access to DOS/BIOS data structures and absolute addresses in
14939conventional memory). However, the DPMI host will usually define
14940additional segments in order to support the DPMI environment.
d4f3574e 14941
8e04817f
AC
14942@cindex garbled pointers
14943These commands allow to display entries from the descriptor tables.
14944Without an argument, all entries from the specified table are
14945displayed. An argument, which should be an integer expression, means
14946display a single entry whose index is given by the argument. For
14947example, here's a convenient way to display information about the
14948debugged program's data segment:
104c1213 14949
8e04817f
AC
14950@smallexample
14951@exdent @code{(@value{GDBP}) info dos ldt $ds}
14952@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
14953@end smallexample
104c1213 14954
8e04817f
AC
14955@noindent
14956This comes in handy when you want to see whether a pointer is outside
14957the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 14958
8e04817f
AC
14959@cindex page tables display (MS-DOS)
14960@item info dos pde
14961@itemx info dos pte
14962These two commands display entries from, respectively, the Page
14963Directory and the Page Tables. Page Directories and Page Tables are
14964data structures which control how virtual memory addresses are mapped
14965into physical addresses. A Page Table includes an entry for every
14966page of memory that is mapped into the program's address space; there
14967may be several Page Tables, each one holding up to 4096 entries. A
14968Page Directory has up to 4096 entries, one each for every Page Table
14969that is currently in use.
104c1213 14970
8e04817f
AC
14971Without an argument, @kbd{info dos pde} displays the entire Page
14972Directory, and @kbd{info dos pte} displays all the entries in all of
14973the Page Tables. An argument, an integer expression, given to the
14974@kbd{info dos pde} command means display only that entry from the Page
14975Directory table. An argument given to the @kbd{info dos pte} command
14976means display entries from a single Page Table, the one pointed to by
14977the specified entry in the Page Directory.
104c1213 14978
8e04817f
AC
14979@cindex direct memory access (DMA) on MS-DOS
14980These commands are useful when your program uses @dfn{DMA} (Direct
14981Memory Access), which needs physical addresses to program the DMA
14982controller.
104c1213 14983
8e04817f 14984These commands are supported only with some DPMI servers.
104c1213 14985
8e04817f
AC
14986@cindex physical address from linear address
14987@item info dos address-pte @var{addr}
14988This command displays the Page Table entry for a specified linear
514c4d71
EZ
14989address. The argument @var{addr} is a linear address which should
14990already have the appropriate segment's base address added to it,
14991because this command accepts addresses which may belong to @emph{any}
14992segment. For example, here's how to display the Page Table entry for
14993the page where a variable @code{i} is stored:
104c1213 14994
b383017d 14995@smallexample
8e04817f
AC
14996@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
14997@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 14998@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 14999@end smallexample
104c1213 15000
8e04817f
AC
15001@noindent
15002This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 15003whose physical base address is @code{0x02698000}, and shows all the
8e04817f 15004attributes of that page.
104c1213 15005
8e04817f
AC
15006Note that you must cast the addresses of variables to a @code{char *},
15007since otherwise the value of @code{__djgpp_base_address}, the base
15008address of all variables and functions in a @sc{djgpp} program, will
15009be added using the rules of C pointer arithmetics: if @code{i} is
15010declared an @code{int}, @value{GDBN} will add 4 times the value of
15011@code{__djgpp_base_address} to the address of @code{i}.
104c1213 15012
8e04817f
AC
15013Here's another example, it displays the Page Table entry for the
15014transfer buffer:
104c1213 15015
8e04817f
AC
15016@smallexample
15017@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
15018@exdent @code{Page Table entry for address 0x29110:}
15019@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
15020@end smallexample
104c1213 15021
8e04817f
AC
15022@noindent
15023(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
150243rd member of the @code{_go32_info_block} structure.) The output
15025clearly shows that this DPMI server maps the addresses in conventional
15026memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
15027linear (@code{0x29110}) addresses are identical.
104c1213 15028
8e04817f
AC
15029This command is supported only with some DPMI servers.
15030@end table
104c1213 15031
c45da7e6 15032@cindex DOS serial data link, remote debugging
a8f24a35
EZ
15033In addition to native debugging, the DJGPP port supports remote
15034debugging via a serial data link. The following commands are specific
15035to remote serial debugging in the DJGPP port of @value{GDBN}.
15036
15037@table @code
15038@kindex set com1base
15039@kindex set com1irq
15040@kindex set com2base
15041@kindex set com2irq
15042@kindex set com3base
15043@kindex set com3irq
15044@kindex set com4base
15045@kindex set com4irq
15046@item set com1base @var{addr}
15047This command sets the base I/O port address of the @file{COM1} serial
15048port.
15049
15050@item set com1irq @var{irq}
15051This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
15052for the @file{COM1} serial port.
15053
15054There are similar commands @samp{set com2base}, @samp{set com3irq},
15055etc.@: for setting the port address and the @code{IRQ} lines for the
15056other 3 COM ports.
15057
15058@kindex show com1base
15059@kindex show com1irq
15060@kindex show com2base
15061@kindex show com2irq
15062@kindex show com3base
15063@kindex show com3irq
15064@kindex show com4base
15065@kindex show com4irq
15066The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
15067display the current settings of the base address and the @code{IRQ}
15068lines used by the COM ports.
c45da7e6
EZ
15069
15070@item info serial
15071@kindex info serial
15072@cindex DOS serial port status
15073This command prints the status of the 4 DOS serial ports. For each
15074port, it prints whether it's active or not, its I/O base address and
15075IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
15076counts of various errors encountered so far.
a8f24a35
EZ
15077@end table
15078
15079
78c47bea 15080@node Cygwin Native
79a6e687 15081@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
15082@cindex MS Windows debugging
15083@cindex native Cygwin debugging
15084@cindex Cygwin-specific commands
15085
be448670 15086@value{GDBN} supports native debugging of MS Windows programs, including
db2e3e2e
BW
15087DLLs with and without symbolic debugging information. There are various
15088additional Cygwin-specific commands, described in this section.
15089Working with DLLs that have no debugging symbols is described in
15090@ref{Non-debug DLL Symbols}.
78c47bea
PM
15091
15092@table @code
15093@kindex info w32
15094@item info w32
db2e3e2e 15095This is a prefix of MS Windows-specific commands which print
78c47bea
PM
15096information about the target system and important OS structures.
15097
15098@item info w32 selector
15099This command displays information returned by
15100the Win32 API @code{GetThreadSelectorEntry} function.
15101It takes an optional argument that is evaluated to
15102a long value to give the information about this given selector.
15103Without argument, this command displays information
d3e8051b 15104about the six segment registers.
78c47bea
PM
15105
15106@kindex info dll
15107@item info dll
db2e3e2e 15108This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
15109
15110@kindex dll-symbols
15111@item dll-symbols
15112This command loads symbols from a dll similarly to
15113add-sym command but without the need to specify a base address.
15114
be90c084 15115@kindex set cygwin-exceptions
e16b02ee
EZ
15116@cindex debugging the Cygwin DLL
15117@cindex Cygwin DLL, debugging
be90c084 15118@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
15119If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
15120happen inside the Cygwin DLL. If @var{mode} is @code{off},
15121@value{GDBN} will delay recognition of exceptions, and may ignore some
15122exceptions which seem to be caused by internal Cygwin DLL
15123``bookkeeping''. This option is meant primarily for debugging the
15124Cygwin DLL itself; the default value is @code{off} to avoid annoying
15125@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
15126
15127@kindex show cygwin-exceptions
15128@item show cygwin-exceptions
e16b02ee
EZ
15129Displays whether @value{GDBN} will break on exceptions that happen
15130inside the Cygwin DLL itself.
be90c084 15131
b383017d 15132@kindex set new-console
78c47bea 15133@item set new-console @var{mode}
b383017d 15134If @var{mode} is @code{on} the debuggee will
78c47bea
PM
15135be started in a new console on next start.
15136If @var{mode} is @code{off}i, the debuggee will
15137be started in the same console as the debugger.
15138
15139@kindex show new-console
15140@item show new-console
15141Displays whether a new console is used
15142when the debuggee is started.
15143
15144@kindex set new-group
15145@item set new-group @var{mode}
15146This boolean value controls whether the debuggee should
15147start a new group or stay in the same group as the debugger.
15148This affects the way the Windows OS handles
c8aa23ab 15149@samp{Ctrl-C}.
78c47bea
PM
15150
15151@kindex show new-group
15152@item show new-group
15153Displays current value of new-group boolean.
15154
15155@kindex set debugevents
15156@item set debugevents
219eec71
EZ
15157This boolean value adds debug output concerning kernel events related
15158to the debuggee seen by the debugger. This includes events that
15159signal thread and process creation and exit, DLL loading and
15160unloading, console interrupts, and debugging messages produced by the
15161Windows @code{OutputDebugString} API call.
78c47bea
PM
15162
15163@kindex set debugexec
15164@item set debugexec
b383017d 15165This boolean value adds debug output concerning execute events
219eec71 15166(such as resume thread) seen by the debugger.
78c47bea
PM
15167
15168@kindex set debugexceptions
15169@item set debugexceptions
219eec71
EZ
15170This boolean value adds debug output concerning exceptions in the
15171debuggee seen by the debugger.
78c47bea
PM
15172
15173@kindex set debugmemory
15174@item set debugmemory
219eec71
EZ
15175This boolean value adds debug output concerning debuggee memory reads
15176and writes by the debugger.
78c47bea
PM
15177
15178@kindex set shell
15179@item set shell
15180This boolean values specifies whether the debuggee is called
15181via a shell or directly (default value is on).
15182
15183@kindex show shell
15184@item show shell
15185Displays if the debuggee will be started with a shell.
15186
15187@end table
15188
be448670 15189@menu
79a6e687 15190* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
15191@end menu
15192
79a6e687
BW
15193@node Non-debug DLL Symbols
15194@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
15195@cindex DLLs with no debugging symbols
15196@cindex Minimal symbols and DLLs
15197
15198Very often on windows, some of the DLLs that your program relies on do
15199not include symbolic debugging information (for example,
db2e3e2e 15200@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 15201symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 15202information contained in the DLL's export table. This section
be448670
CF
15203describes working with such symbols, known internally to @value{GDBN} as
15204``minimal symbols''.
15205
15206Note that before the debugged program has started execution, no DLLs
db2e3e2e 15207will have been loaded. The easiest way around this problem is simply to
be448670 15208start the program --- either by setting a breakpoint or letting the
db2e3e2e 15209program run once to completion. It is also possible to force
be448670 15210@value{GDBN} to load a particular DLL before starting the executable ---
12c27660 15211see the shared library information in @ref{Files}, or the
db2e3e2e 15212@code{dll-symbols} command in @ref{Cygwin Native}. Currently,
be448670
CF
15213explicitly loading symbols from a DLL with no debugging information will
15214cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
15215which may adversely affect symbol lookup performance.
15216
79a6e687 15217@subsubsection DLL Name Prefixes
be448670
CF
15218
15219In keeping with the naming conventions used by the Microsoft debugging
15220tools, DLL export symbols are made available with a prefix based on the
15221DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
15222also entered into the symbol table, so @code{CreateFileA} is often
15223sufficient. In some cases there will be name clashes within a program
15224(particularly if the executable itself includes full debugging symbols)
15225necessitating the use of the fully qualified name when referring to the
15226contents of the DLL. Use single-quotes around the name to avoid the
15227exclamation mark (``!'') being interpreted as a language operator.
15228
15229Note that the internal name of the DLL may be all upper-case, even
15230though the file name of the DLL is lower-case, or vice-versa. Since
15231symbols within @value{GDBN} are @emph{case-sensitive} this may cause
15232some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
15233@code{info variables} commands or even @code{maint print msymbols}
15234(@pxref{Symbols}). Here's an example:
be448670
CF
15235
15236@smallexample
f7dc1244 15237(@value{GDBP}) info function CreateFileA
be448670
CF
15238All functions matching regular expression "CreateFileA":
15239
15240Non-debugging symbols:
152410x77e885f4 CreateFileA
152420x77e885f4 KERNEL32!CreateFileA
15243@end smallexample
15244
15245@smallexample
f7dc1244 15246(@value{GDBP}) info function !
be448670
CF
15247All functions matching regular expression "!":
15248
15249Non-debugging symbols:
152500x6100114c cygwin1!__assert
152510x61004034 cygwin1!_dll_crt0@@0
152520x61004240 cygwin1!dll_crt0(per_process *)
15253[etc...]
15254@end smallexample
15255
79a6e687 15256@subsubsection Working with Minimal Symbols
be448670
CF
15257
15258Symbols extracted from a DLL's export table do not contain very much
15259type information. All that @value{GDBN} can do is guess whether a symbol
15260refers to a function or variable depending on the linker section that
15261contains the symbol. Also note that the actual contents of the memory
15262contained in a DLL are not available unless the program is running. This
15263means that you cannot examine the contents of a variable or disassemble
15264a function within a DLL without a running program.
15265
15266Variables are generally treated as pointers and dereferenced
15267automatically. For this reason, it is often necessary to prefix a
15268variable name with the address-of operator (``&'') and provide explicit
15269type information in the command. Here's an example of the type of
15270problem:
15271
15272@smallexample
f7dc1244 15273(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
15274$1 = 268572168
15275@end smallexample
15276
15277@smallexample
f7dc1244 15278(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
152790x10021610: "\230y\""
15280@end smallexample
15281
15282And two possible solutions:
15283
15284@smallexample
f7dc1244 15285(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
15286$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
15287@end smallexample
15288
15289@smallexample
f7dc1244 15290(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 152910x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 15292(@value{GDBP}) x/x 0x10021608
be448670 152930x10021608: 0x0022fd98
f7dc1244 15294(@value{GDBP}) x/s 0x0022fd98
be448670
CF
152950x22fd98: "/cygdrive/c/mydirectory/myprogram"
15296@end smallexample
15297
15298Setting a break point within a DLL is possible even before the program
15299starts execution. However, under these circumstances, @value{GDBN} can't
15300examine the initial instructions of the function in order to skip the
15301function's frame set-up code. You can work around this by using ``*&''
15302to set the breakpoint at a raw memory address:
15303
15304@smallexample
f7dc1244 15305(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
15306Breakpoint 1 at 0x1e04eff0
15307@end smallexample
15308
15309The author of these extensions is not entirely convinced that setting a
15310break point within a shared DLL like @file{kernel32.dll} is completely
15311safe.
15312
14d6dd68 15313@node Hurd Native
79a6e687 15314@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
15315@cindex @sc{gnu} Hurd debugging
15316
15317This subsection describes @value{GDBN} commands specific to the
15318@sc{gnu} Hurd native debugging.
15319
15320@table @code
15321@item set signals
15322@itemx set sigs
15323@kindex set signals@r{, Hurd command}
15324@kindex set sigs@r{, Hurd command}
15325This command toggles the state of inferior signal interception by
15326@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
15327affected by this command. @code{sigs} is a shorthand alias for
15328@code{signals}.
15329
15330@item show signals
15331@itemx show sigs
15332@kindex show signals@r{, Hurd command}
15333@kindex show sigs@r{, Hurd command}
15334Show the current state of intercepting inferior's signals.
15335
15336@item set signal-thread
15337@itemx set sigthread
15338@kindex set signal-thread
15339@kindex set sigthread
15340This command tells @value{GDBN} which thread is the @code{libc} signal
15341thread. That thread is run when a signal is delivered to a running
15342process. @code{set sigthread} is the shorthand alias of @code{set
15343signal-thread}.
15344
15345@item show signal-thread
15346@itemx show sigthread
15347@kindex show signal-thread
15348@kindex show sigthread
15349These two commands show which thread will run when the inferior is
15350delivered a signal.
15351
15352@item set stopped
15353@kindex set stopped@r{, Hurd command}
15354This commands tells @value{GDBN} that the inferior process is stopped,
15355as with the @code{SIGSTOP} signal. The stopped process can be
15356continued by delivering a signal to it.
15357
15358@item show stopped
15359@kindex show stopped@r{, Hurd command}
15360This command shows whether @value{GDBN} thinks the debuggee is
15361stopped.
15362
15363@item set exceptions
15364@kindex set exceptions@r{, Hurd command}
15365Use this command to turn off trapping of exceptions in the inferior.
15366When exception trapping is off, neither breakpoints nor
15367single-stepping will work. To restore the default, set exception
15368trapping on.
15369
15370@item show exceptions
15371@kindex show exceptions@r{, Hurd command}
15372Show the current state of trapping exceptions in the inferior.
15373
15374@item set task pause
15375@kindex set task@r{, Hurd commands}
15376@cindex task attributes (@sc{gnu} Hurd)
15377@cindex pause current task (@sc{gnu} Hurd)
15378This command toggles task suspension when @value{GDBN} has control.
15379Setting it to on takes effect immediately, and the task is suspended
15380whenever @value{GDBN} gets control. Setting it to off will take
15381effect the next time the inferior is continued. If this option is set
15382to off, you can use @code{set thread default pause on} or @code{set
15383thread pause on} (see below) to pause individual threads.
15384
15385@item show task pause
15386@kindex show task@r{, Hurd commands}
15387Show the current state of task suspension.
15388
15389@item set task detach-suspend-count
15390@cindex task suspend count
15391@cindex detach from task, @sc{gnu} Hurd
15392This command sets the suspend count the task will be left with when
15393@value{GDBN} detaches from it.
15394
15395@item show task detach-suspend-count
15396Show the suspend count the task will be left with when detaching.
15397
15398@item set task exception-port
15399@itemx set task excp
15400@cindex task exception port, @sc{gnu} Hurd
15401This command sets the task exception port to which @value{GDBN} will
15402forward exceptions. The argument should be the value of the @dfn{send
15403rights} of the task. @code{set task excp} is a shorthand alias.
15404
15405@item set noninvasive
15406@cindex noninvasive task options
15407This command switches @value{GDBN} to a mode that is the least
15408invasive as far as interfering with the inferior is concerned. This
15409is the same as using @code{set task pause}, @code{set exceptions}, and
15410@code{set signals} to values opposite to the defaults.
15411
15412@item info send-rights
15413@itemx info receive-rights
15414@itemx info port-rights
15415@itemx info port-sets
15416@itemx info dead-names
15417@itemx info ports
15418@itemx info psets
15419@cindex send rights, @sc{gnu} Hurd
15420@cindex receive rights, @sc{gnu} Hurd
15421@cindex port rights, @sc{gnu} Hurd
15422@cindex port sets, @sc{gnu} Hurd
15423@cindex dead names, @sc{gnu} Hurd
15424These commands display information about, respectively, send rights,
15425receive rights, port rights, port sets, and dead names of a task.
15426There are also shorthand aliases: @code{info ports} for @code{info
15427port-rights} and @code{info psets} for @code{info port-sets}.
15428
15429@item set thread pause
15430@kindex set thread@r{, Hurd command}
15431@cindex thread properties, @sc{gnu} Hurd
15432@cindex pause current thread (@sc{gnu} Hurd)
15433This command toggles current thread suspension when @value{GDBN} has
15434control. Setting it to on takes effect immediately, and the current
15435thread is suspended whenever @value{GDBN} gets control. Setting it to
15436off will take effect the next time the inferior is continued.
15437Normally, this command has no effect, since when @value{GDBN} has
15438control, the whole task is suspended. However, if you used @code{set
15439task pause off} (see above), this command comes in handy to suspend
15440only the current thread.
15441
15442@item show thread pause
15443@kindex show thread@r{, Hurd command}
15444This command shows the state of current thread suspension.
15445
15446@item set thread run
d3e8051b 15447This command sets whether the current thread is allowed to run.
14d6dd68
EZ
15448
15449@item show thread run
15450Show whether the current thread is allowed to run.
15451
15452@item set thread detach-suspend-count
15453@cindex thread suspend count, @sc{gnu} Hurd
15454@cindex detach from thread, @sc{gnu} Hurd
15455This command sets the suspend count @value{GDBN} will leave on a
15456thread when detaching. This number is relative to the suspend count
15457found by @value{GDBN} when it notices the thread; use @code{set thread
15458takeover-suspend-count} to force it to an absolute value.
15459
15460@item show thread detach-suspend-count
15461Show the suspend count @value{GDBN} will leave on the thread when
15462detaching.
15463
15464@item set thread exception-port
15465@itemx set thread excp
15466Set the thread exception port to which to forward exceptions. This
15467overrides the port set by @code{set task exception-port} (see above).
15468@code{set thread excp} is the shorthand alias.
15469
15470@item set thread takeover-suspend-count
15471Normally, @value{GDBN}'s thread suspend counts are relative to the
15472value @value{GDBN} finds when it notices each thread. This command
15473changes the suspend counts to be absolute instead.
15474
15475@item set thread default
15476@itemx show thread default
15477@cindex thread default settings, @sc{gnu} Hurd
15478Each of the above @code{set thread} commands has a @code{set thread
15479default} counterpart (e.g., @code{set thread default pause}, @code{set
15480thread default exception-port}, etc.). The @code{thread default}
15481variety of commands sets the default thread properties for all
15482threads; you can then change the properties of individual threads with
15483the non-default commands.
15484@end table
15485
15486
a64548ea
EZ
15487@node Neutrino
15488@subsection QNX Neutrino
15489@cindex QNX Neutrino
15490
15491@value{GDBN} provides the following commands specific to the QNX
15492Neutrino target:
15493
15494@table @code
15495@item set debug nto-debug
15496@kindex set debug nto-debug
15497When set to on, enables debugging messages specific to the QNX
15498Neutrino support.
15499
15500@item show debug nto-debug
15501@kindex show debug nto-debug
15502Show the current state of QNX Neutrino messages.
15503@end table
15504
a80b95ba
TG
15505@node Darwin
15506@subsection Darwin
15507@cindex Darwin
15508
15509@value{GDBN} provides the following commands specific to the Darwin target:
15510
15511@table @code
15512@item set debug darwin @var{num}
15513@kindex set debug darwin
15514When set to a non zero value, enables debugging messages specific to
15515the Darwin support. Higher values produce more verbose output.
15516
15517@item show debug darwin
15518@kindex show debug darwin
15519Show the current state of Darwin messages.
15520
15521@item set debug mach-o @var{num}
15522@kindex set debug mach-o
15523When set to a non zero value, enables debugging messages while
15524@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
15525file format used on Darwin for object and executable files.) Higher
15526values produce more verbose output. This is a command to diagnose
15527problems internal to @value{GDBN} and should not be needed in normal
15528usage.
15529
15530@item show debug mach-o
15531@kindex show debug mach-o
15532Show the current state of Mach-O file messages.
15533
15534@item set mach-exceptions on
15535@itemx set mach-exceptions off
15536@kindex set mach-exceptions
15537On Darwin, faults are first reported as a Mach exception and are then
15538mapped to a Posix signal. Use this command to turn on trapping of
15539Mach exceptions in the inferior. This might be sometimes useful to
15540better understand the cause of a fault. The default is off.
15541
15542@item show mach-exceptions
15543@kindex show mach-exceptions
15544Show the current state of exceptions trapping.
15545@end table
15546
a64548ea 15547
8e04817f
AC
15548@node Embedded OS
15549@section Embedded Operating Systems
104c1213 15550
8e04817f
AC
15551This section describes configurations involving the debugging of
15552embedded operating systems that are available for several different
15553architectures.
d4f3574e 15554
8e04817f
AC
15555@menu
15556* VxWorks:: Using @value{GDBN} with VxWorks
15557@end menu
104c1213 15558
8e04817f
AC
15559@value{GDBN} includes the ability to debug programs running on
15560various real-time operating systems.
104c1213 15561
8e04817f
AC
15562@node VxWorks
15563@subsection Using @value{GDBN} with VxWorks
104c1213 15564
8e04817f 15565@cindex VxWorks
104c1213 15566
8e04817f 15567@table @code
104c1213 15568
8e04817f
AC
15569@kindex target vxworks
15570@item target vxworks @var{machinename}
15571A VxWorks system, attached via TCP/IP. The argument @var{machinename}
15572is the target system's machine name or IP address.
104c1213 15573
8e04817f 15574@end table
104c1213 15575
8e04817f
AC
15576On VxWorks, @code{load} links @var{filename} dynamically on the
15577current target system as well as adding its symbols in @value{GDBN}.
104c1213 15578
8e04817f
AC
15579@value{GDBN} enables developers to spawn and debug tasks running on networked
15580VxWorks targets from a Unix host. Already-running tasks spawned from
15581the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
15582both the Unix host and on the VxWorks target. The program
15583@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
15584installed with the name @code{vxgdb}, to distinguish it from a
15585@value{GDBN} for debugging programs on the host itself.)
104c1213 15586
8e04817f
AC
15587@table @code
15588@item VxWorks-timeout @var{args}
15589@kindex vxworks-timeout
15590All VxWorks-based targets now support the option @code{vxworks-timeout}.
15591This option is set by the user, and @var{args} represents the number of
15592seconds @value{GDBN} waits for responses to rpc's. You might use this if
15593your VxWorks target is a slow software simulator or is on the far side
15594of a thin network line.
15595@end table
104c1213 15596
8e04817f
AC
15597The following information on connecting to VxWorks was current when
15598this manual was produced; newer releases of VxWorks may use revised
15599procedures.
104c1213 15600
4644b6e3 15601@findex INCLUDE_RDB
8e04817f
AC
15602To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
15603to include the remote debugging interface routines in the VxWorks
15604library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
15605VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
15606kernel. The resulting kernel contains @file{rdb.a}, and spawns the
15607source debugging task @code{tRdbTask} when VxWorks is booted. For more
15608information on configuring and remaking VxWorks, see the manufacturer's
15609manual.
15610@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 15611
8e04817f
AC
15612Once you have included @file{rdb.a} in your VxWorks system image and set
15613your Unix execution search path to find @value{GDBN}, you are ready to
15614run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
15615@code{vxgdb}, depending on your installation).
104c1213 15616
8e04817f 15617@value{GDBN} comes up showing the prompt:
104c1213 15618
474c8240 15619@smallexample
8e04817f 15620(vxgdb)
474c8240 15621@end smallexample
104c1213 15622
8e04817f
AC
15623@menu
15624* VxWorks Connection:: Connecting to VxWorks
15625* VxWorks Download:: VxWorks download
15626* VxWorks Attach:: Running tasks
15627@end menu
104c1213 15628
8e04817f
AC
15629@node VxWorks Connection
15630@subsubsection Connecting to VxWorks
104c1213 15631
8e04817f
AC
15632The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
15633network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 15634
474c8240 15635@smallexample
8e04817f 15636(vxgdb) target vxworks tt
474c8240 15637@end smallexample
104c1213 15638
8e04817f
AC
15639@need 750
15640@value{GDBN} displays messages like these:
104c1213 15641
8e04817f
AC
15642@smallexample
15643Attaching remote machine across net...
15644Connected to tt.
15645@end smallexample
104c1213 15646
8e04817f
AC
15647@need 1000
15648@value{GDBN} then attempts to read the symbol tables of any object modules
15649loaded into the VxWorks target since it was last booted. @value{GDBN} locates
15650these files by searching the directories listed in the command search
79a6e687 15651path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 15652to find an object file, it displays a message such as:
5d161b24 15653
474c8240 15654@smallexample
8e04817f 15655prog.o: No such file or directory.
474c8240 15656@end smallexample
104c1213 15657
8e04817f
AC
15658When this happens, add the appropriate directory to the search path with
15659the @value{GDBN} command @code{path}, and execute the @code{target}
15660command again.
104c1213 15661
8e04817f 15662@node VxWorks Download
79a6e687 15663@subsubsection VxWorks Download
104c1213 15664
8e04817f
AC
15665@cindex download to VxWorks
15666If you have connected to the VxWorks target and you want to debug an
15667object that has not yet been loaded, you can use the @value{GDBN}
15668@code{load} command to download a file from Unix to VxWorks
15669incrementally. The object file given as an argument to the @code{load}
15670command is actually opened twice: first by the VxWorks target in order
15671to download the code, then by @value{GDBN} in order to read the symbol
15672table. This can lead to problems if the current working directories on
15673the two systems differ. If both systems have NFS mounted the same
15674filesystems, you can avoid these problems by using absolute paths.
15675Otherwise, it is simplest to set the working directory on both systems
15676to the directory in which the object file resides, and then to reference
15677the file by its name, without any path. For instance, a program
15678@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
15679and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
15680program, type this on VxWorks:
104c1213 15681
474c8240 15682@smallexample
8e04817f 15683-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 15684@end smallexample
104c1213 15685
8e04817f
AC
15686@noindent
15687Then, in @value{GDBN}, type:
104c1213 15688
474c8240 15689@smallexample
8e04817f
AC
15690(vxgdb) cd @var{hostpath}/vw/demo/rdb
15691(vxgdb) load prog.o
474c8240 15692@end smallexample
104c1213 15693
8e04817f 15694@value{GDBN} displays a response similar to this:
104c1213 15695
8e04817f
AC
15696@smallexample
15697Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
15698@end smallexample
104c1213 15699
8e04817f
AC
15700You can also use the @code{load} command to reload an object module
15701after editing and recompiling the corresponding source file. Note that
15702this makes @value{GDBN} delete all currently-defined breakpoints,
15703auto-displays, and convenience variables, and to clear the value
15704history. (This is necessary in order to preserve the integrity of
15705debugger's data structures that reference the target system's symbol
15706table.)
104c1213 15707
8e04817f 15708@node VxWorks Attach
79a6e687 15709@subsubsection Running Tasks
104c1213
JM
15710
15711@cindex running VxWorks tasks
15712You can also attach to an existing task using the @code{attach} command as
15713follows:
15714
474c8240 15715@smallexample
104c1213 15716(vxgdb) attach @var{task}
474c8240 15717@end smallexample
104c1213
JM
15718
15719@noindent
15720where @var{task} is the VxWorks hexadecimal task ID. The task can be running
15721or suspended when you attach to it. Running tasks are suspended at
15722the time of attachment.
15723
6d2ebf8b 15724@node Embedded Processors
104c1213
JM
15725@section Embedded Processors
15726
15727This section goes into details specific to particular embedded
15728configurations.
15729
c45da7e6
EZ
15730@cindex send command to simulator
15731Whenever a specific embedded processor has a simulator, @value{GDBN}
15732allows to send an arbitrary command to the simulator.
15733
15734@table @code
15735@item sim @var{command}
15736@kindex sim@r{, a command}
15737Send an arbitrary @var{command} string to the simulator. Consult the
15738documentation for the specific simulator in use for information about
15739acceptable commands.
15740@end table
15741
7d86b5d5 15742
104c1213 15743@menu
c45da7e6 15744* ARM:: ARM RDI
172c2a43 15745* M32R/D:: Renesas M32R/D
104c1213 15746* M68K:: Motorola M68K
104c1213 15747* MIPS Embedded:: MIPS Embedded
a37295f9 15748* OpenRISC 1000:: OpenRisc 1000
104c1213 15749* PA:: HP PA Embedded
4acd40f3 15750* PowerPC Embedded:: PowerPC Embedded
104c1213
JM
15751* Sparclet:: Tsqware Sparclet
15752* Sparclite:: Fujitsu Sparclite
104c1213 15753* Z8000:: Zilog Z8000
a64548ea
EZ
15754* AVR:: Atmel AVR
15755* CRIS:: CRIS
15756* Super-H:: Renesas Super-H
104c1213
JM
15757@end menu
15758
6d2ebf8b 15759@node ARM
104c1213 15760@subsection ARM
c45da7e6 15761@cindex ARM RDI
104c1213
JM
15762
15763@table @code
8e04817f
AC
15764@kindex target rdi
15765@item target rdi @var{dev}
15766ARM Angel monitor, via RDI library interface to ADP protocol. You may
15767use this target to communicate with both boards running the Angel
15768monitor, or with the EmbeddedICE JTAG debug device.
15769
15770@kindex target rdp
15771@item target rdp @var{dev}
15772ARM Demon monitor.
15773
15774@end table
15775
e2f4edfd
EZ
15776@value{GDBN} provides the following ARM-specific commands:
15777
15778@table @code
15779@item set arm disassembler
15780@kindex set arm
15781This commands selects from a list of disassembly styles. The
15782@code{"std"} style is the standard style.
15783
15784@item show arm disassembler
15785@kindex show arm
15786Show the current disassembly style.
15787
15788@item set arm apcs32
15789@cindex ARM 32-bit mode
15790This command toggles ARM operation mode between 32-bit and 26-bit.
15791
15792@item show arm apcs32
15793Display the current usage of the ARM 32-bit mode.
15794
15795@item set arm fpu @var{fputype}
15796This command sets the ARM floating-point unit (FPU) type. The
15797argument @var{fputype} can be one of these:
15798
15799@table @code
15800@item auto
15801Determine the FPU type by querying the OS ABI.
15802@item softfpa
15803Software FPU, with mixed-endian doubles on little-endian ARM
15804processors.
15805@item fpa
15806GCC-compiled FPA co-processor.
15807@item softvfp
15808Software FPU with pure-endian doubles.
15809@item vfp
15810VFP co-processor.
15811@end table
15812
15813@item show arm fpu
15814Show the current type of the FPU.
15815
15816@item set arm abi
15817This command forces @value{GDBN} to use the specified ABI.
15818
15819@item show arm abi
15820Show the currently used ABI.
15821
0428b8f5
DJ
15822@item set arm fallback-mode (arm|thumb|auto)
15823@value{GDBN} uses the symbol table, when available, to determine
15824whether instructions are ARM or Thumb. This command controls
15825@value{GDBN}'s default behavior when the symbol table is not
15826available. The default is @samp{auto}, which causes @value{GDBN} to
15827use the current execution mode (from the @code{T} bit in the @code{CPSR}
15828register).
15829
15830@item show arm fallback-mode
15831Show the current fallback instruction mode.
15832
15833@item set arm force-mode (arm|thumb|auto)
15834This command overrides use of the symbol table to determine whether
15835instructions are ARM or Thumb. The default is @samp{auto}, which
15836causes @value{GDBN} to use the symbol table and then the setting
15837of @samp{set arm fallback-mode}.
15838
15839@item show arm force-mode
15840Show the current forced instruction mode.
15841
e2f4edfd
EZ
15842@item set debug arm
15843Toggle whether to display ARM-specific debugging messages from the ARM
15844target support subsystem.
15845
15846@item show debug arm
15847Show whether ARM-specific debugging messages are enabled.
15848@end table
15849
c45da7e6
EZ
15850The following commands are available when an ARM target is debugged
15851using the RDI interface:
15852
15853@table @code
15854@item rdilogfile @r{[}@var{file}@r{]}
15855@kindex rdilogfile
15856@cindex ADP (Angel Debugger Protocol) logging
15857Set the filename for the ADP (Angel Debugger Protocol) packet log.
15858With an argument, sets the log file to the specified @var{file}. With
15859no argument, show the current log file name. The default log file is
15860@file{rdi.log}.
15861
15862@item rdilogenable @r{[}@var{arg}@r{]}
15863@kindex rdilogenable
15864Control logging of ADP packets. With an argument of 1 or @code{"yes"}
15865enables logging, with an argument 0 or @code{"no"} disables it. With
15866no arguments displays the current setting. When logging is enabled,
15867ADP packets exchanged between @value{GDBN} and the RDI target device
15868are logged to a file.
15869
15870@item set rdiromatzero
15871@kindex set rdiromatzero
15872@cindex ROM at zero address, RDI
15873Tell @value{GDBN} whether the target has ROM at address 0. If on,
15874vector catching is disabled, so that zero address can be used. If off
15875(the default), vector catching is enabled. For this command to take
15876effect, it needs to be invoked prior to the @code{target rdi} command.
15877
15878@item show rdiromatzero
15879@kindex show rdiromatzero
15880Show the current setting of ROM at zero address.
15881
15882@item set rdiheartbeat
15883@kindex set rdiheartbeat
15884@cindex RDI heartbeat
15885Enable or disable RDI heartbeat packets. It is not recommended to
15886turn on this option, since it confuses ARM and EPI JTAG interface, as
15887well as the Angel monitor.
15888
15889@item show rdiheartbeat
15890@kindex show rdiheartbeat
15891Show the setting of RDI heartbeat packets.
15892@end table
15893
e2f4edfd 15894
8e04817f 15895@node M32R/D
ba04e063 15896@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
15897
15898@table @code
8e04817f
AC
15899@kindex target m32r
15900@item target m32r @var{dev}
172c2a43 15901Renesas M32R/D ROM monitor.
8e04817f 15902
fb3e19c0
KI
15903@kindex target m32rsdi
15904@item target m32rsdi @var{dev}
15905Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
15906@end table
15907
15908The following @value{GDBN} commands are specific to the M32R monitor:
15909
15910@table @code
15911@item set download-path @var{path}
15912@kindex set download-path
15913@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 15914Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
15915
15916@item show download-path
15917@kindex show download-path
15918Show the default path for downloadable @sc{srec} files.
fb3e19c0 15919
721c2651
EZ
15920@item set board-address @var{addr}
15921@kindex set board-address
15922@cindex M32-EVA target board address
15923Set the IP address for the M32R-EVA target board.
15924
15925@item show board-address
15926@kindex show board-address
15927Show the current IP address of the target board.
15928
15929@item set server-address @var{addr}
15930@kindex set server-address
15931@cindex download server address (M32R)
15932Set the IP address for the download server, which is the @value{GDBN}'s
15933host machine.
15934
15935@item show server-address
15936@kindex show server-address
15937Display the IP address of the download server.
15938
15939@item upload @r{[}@var{file}@r{]}
15940@kindex upload@r{, M32R}
15941Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
15942upload capability. If no @var{file} argument is given, the current
15943executable file is uploaded.
15944
15945@item tload @r{[}@var{file}@r{]}
15946@kindex tload@r{, M32R}
15947Test the @code{upload} command.
8e04817f
AC
15948@end table
15949
ba04e063
EZ
15950The following commands are available for M32R/SDI:
15951
15952@table @code
15953@item sdireset
15954@kindex sdireset
15955@cindex reset SDI connection, M32R
15956This command resets the SDI connection.
15957
15958@item sdistatus
15959@kindex sdistatus
15960This command shows the SDI connection status.
15961
15962@item debug_chaos
15963@kindex debug_chaos
15964@cindex M32R/Chaos debugging
15965Instructs the remote that M32R/Chaos debugging is to be used.
15966
15967@item use_debug_dma
15968@kindex use_debug_dma
15969Instructs the remote to use the DEBUG_DMA method of accessing memory.
15970
15971@item use_mon_code
15972@kindex use_mon_code
15973Instructs the remote to use the MON_CODE method of accessing memory.
15974
15975@item use_ib_break
15976@kindex use_ib_break
15977Instructs the remote to set breakpoints by IB break.
15978
15979@item use_dbt_break
15980@kindex use_dbt_break
15981Instructs the remote to set breakpoints by DBT.
15982@end table
15983
8e04817f
AC
15984@node M68K
15985@subsection M68k
15986
7ce59000
DJ
15987The Motorola m68k configuration includes ColdFire support, and a
15988target command for the following ROM monitor.
8e04817f
AC
15989
15990@table @code
15991
8e04817f
AC
15992@kindex target dbug
15993@item target dbug @var{dev}
15994dBUG ROM monitor for Motorola ColdFire.
15995
8e04817f
AC
15996@end table
15997
8e04817f
AC
15998@node MIPS Embedded
15999@subsection MIPS Embedded
16000
16001@cindex MIPS boards
16002@value{GDBN} can use the MIPS remote debugging protocol to talk to a
16003MIPS board attached to a serial line. This is available when
16004you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 16005
8e04817f
AC
16006@need 1000
16007Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 16008
8e04817f
AC
16009@table @code
16010@item target mips @var{port}
16011@kindex target mips @var{port}
16012To run a program on the board, start up @code{@value{GDBP}} with the
16013name of your program as the argument. To connect to the board, use the
16014command @samp{target mips @var{port}}, where @var{port} is the name of
16015the serial port connected to the board. If the program has not already
16016been downloaded to the board, you may use the @code{load} command to
16017download it. You can then use all the usual @value{GDBN} commands.
104c1213 16018
8e04817f
AC
16019For example, this sequence connects to the target board through a serial
16020port, and loads and runs a program called @var{prog} through the
16021debugger:
104c1213 16022
474c8240 16023@smallexample
8e04817f
AC
16024host$ @value{GDBP} @var{prog}
16025@value{GDBN} is free software and @dots{}
16026(@value{GDBP}) target mips /dev/ttyb
16027(@value{GDBP}) load @var{prog}
16028(@value{GDBP}) run
474c8240 16029@end smallexample
104c1213 16030
8e04817f
AC
16031@item target mips @var{hostname}:@var{portnumber}
16032On some @value{GDBN} host configurations, you can specify a TCP
16033connection (for instance, to a serial line managed by a terminal
16034concentrator) instead of a serial port, using the syntax
16035@samp{@var{hostname}:@var{portnumber}}.
104c1213 16036
8e04817f
AC
16037@item target pmon @var{port}
16038@kindex target pmon @var{port}
16039PMON ROM monitor.
104c1213 16040
8e04817f
AC
16041@item target ddb @var{port}
16042@kindex target ddb @var{port}
16043NEC's DDB variant of PMON for Vr4300.
104c1213 16044
8e04817f
AC
16045@item target lsi @var{port}
16046@kindex target lsi @var{port}
16047LSI variant of PMON.
104c1213 16048
8e04817f
AC
16049@kindex target r3900
16050@item target r3900 @var{dev}
16051Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 16052
8e04817f
AC
16053@kindex target array
16054@item target array @var{dev}
16055Array Tech LSI33K RAID controller board.
104c1213 16056
8e04817f 16057@end table
104c1213 16058
104c1213 16059
8e04817f
AC
16060@noindent
16061@value{GDBN} also supports these special commands for MIPS targets:
104c1213 16062
8e04817f 16063@table @code
8e04817f
AC
16064@item set mipsfpu double
16065@itemx set mipsfpu single
16066@itemx set mipsfpu none
a64548ea 16067@itemx set mipsfpu auto
8e04817f
AC
16068@itemx show mipsfpu
16069@kindex set mipsfpu
16070@kindex show mipsfpu
16071@cindex MIPS remote floating point
16072@cindex floating point, MIPS remote
16073If your target board does not support the MIPS floating point
16074coprocessor, you should use the command @samp{set mipsfpu none} (if you
16075need this, you may wish to put the command in your @value{GDBN} init
16076file). This tells @value{GDBN} how to find the return value of
16077functions which return floating point values. It also allows
16078@value{GDBN} to avoid saving the floating point registers when calling
16079functions on the board. If you are using a floating point coprocessor
16080with only single precision floating point support, as on the @sc{r4650}
16081processor, use the command @samp{set mipsfpu single}. The default
16082double precision floating point coprocessor may be selected using
16083@samp{set mipsfpu double}.
104c1213 16084
8e04817f
AC
16085In previous versions the only choices were double precision or no
16086floating point, so @samp{set mipsfpu on} will select double precision
16087and @samp{set mipsfpu off} will select no floating point.
104c1213 16088
8e04817f
AC
16089As usual, you can inquire about the @code{mipsfpu} variable with
16090@samp{show mipsfpu}.
104c1213 16091
8e04817f
AC
16092@item set timeout @var{seconds}
16093@itemx set retransmit-timeout @var{seconds}
16094@itemx show timeout
16095@itemx show retransmit-timeout
16096@cindex @code{timeout}, MIPS protocol
16097@cindex @code{retransmit-timeout}, MIPS protocol
16098@kindex set timeout
16099@kindex show timeout
16100@kindex set retransmit-timeout
16101@kindex show retransmit-timeout
16102You can control the timeout used while waiting for a packet, in the MIPS
16103remote protocol, with the @code{set timeout @var{seconds}} command. The
16104default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 16105waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
16106retransmit-timeout @var{seconds}} command. The default is 3 seconds.
16107You can inspect both values with @code{show timeout} and @code{show
16108retransmit-timeout}. (These commands are @emph{only} available when
16109@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 16110
8e04817f
AC
16111The timeout set by @code{set timeout} does not apply when @value{GDBN}
16112is waiting for your program to stop. In that case, @value{GDBN} waits
16113forever because it has no way of knowing how long the program is going
16114to run before stopping.
ba04e063
EZ
16115
16116@item set syn-garbage-limit @var{num}
16117@kindex set syn-garbage-limit@r{, MIPS remote}
16118@cindex synchronize with remote MIPS target
16119Limit the maximum number of characters @value{GDBN} should ignore when
16120it tries to synchronize with the remote target. The default is 10
16121characters. Setting the limit to -1 means there's no limit.
16122
16123@item show syn-garbage-limit
16124@kindex show syn-garbage-limit@r{, MIPS remote}
16125Show the current limit on the number of characters to ignore when
16126trying to synchronize with the remote system.
16127
16128@item set monitor-prompt @var{prompt}
16129@kindex set monitor-prompt@r{, MIPS remote}
16130@cindex remote monitor prompt
16131Tell @value{GDBN} to expect the specified @var{prompt} string from the
16132remote monitor. The default depends on the target:
16133@table @asis
16134@item pmon target
16135@samp{PMON}
16136@item ddb target
16137@samp{NEC010}
16138@item lsi target
16139@samp{PMON>}
16140@end table
16141
16142@item show monitor-prompt
16143@kindex show monitor-prompt@r{, MIPS remote}
16144Show the current strings @value{GDBN} expects as the prompt from the
16145remote monitor.
16146
16147@item set monitor-warnings
16148@kindex set monitor-warnings@r{, MIPS remote}
16149Enable or disable monitor warnings about hardware breakpoints. This
16150has effect only for the @code{lsi} target. When on, @value{GDBN} will
16151display warning messages whose codes are returned by the @code{lsi}
16152PMON monitor for breakpoint commands.
16153
16154@item show monitor-warnings
16155@kindex show monitor-warnings@r{, MIPS remote}
16156Show the current setting of printing monitor warnings.
16157
16158@item pmon @var{command}
16159@kindex pmon@r{, MIPS remote}
16160@cindex send PMON command
16161This command allows sending an arbitrary @var{command} string to the
16162monitor. The monitor must be in debug mode for this to work.
8e04817f 16163@end table
104c1213 16164
a37295f9
MM
16165@node OpenRISC 1000
16166@subsection OpenRISC 1000
16167@cindex OpenRISC 1000
16168
16169@cindex or1k boards
16170See OR1k Architecture document (@uref{www.opencores.org}) for more information
16171about platform and commands.
16172
16173@table @code
16174
16175@kindex target jtag
16176@item target jtag jtag://@var{host}:@var{port}
16177
16178Connects to remote JTAG server.
16179JTAG remote server can be either an or1ksim or JTAG server,
16180connected via parallel port to the board.
16181
16182Example: @code{target jtag jtag://localhost:9999}
16183
16184@kindex or1ksim
16185@item or1ksim @var{command}
16186If connected to @code{or1ksim} OpenRISC 1000 Architectural
16187Simulator, proprietary commands can be executed.
16188
16189@kindex info or1k spr
16190@item info or1k spr
16191Displays spr groups.
16192
16193@item info or1k spr @var{group}
16194@itemx info or1k spr @var{groupno}
16195Displays register names in selected group.
16196
16197@item info or1k spr @var{group} @var{register}
16198@itemx info or1k spr @var{register}
16199@itemx info or1k spr @var{groupno} @var{registerno}
16200@itemx info or1k spr @var{registerno}
16201Shows information about specified spr register.
16202
16203@kindex spr
16204@item spr @var{group} @var{register} @var{value}
16205@itemx spr @var{register @var{value}}
16206@itemx spr @var{groupno} @var{registerno @var{value}}
16207@itemx spr @var{registerno @var{value}}
16208Writes @var{value} to specified spr register.
16209@end table
16210
16211Some implementations of OpenRISC 1000 Architecture also have hardware trace.
16212It is very similar to @value{GDBN} trace, except it does not interfere with normal
16213program execution and is thus much faster. Hardware breakpoints/watchpoint
16214triggers can be set using:
16215@table @code
16216@item $LEA/$LDATA
16217Load effective address/data
16218@item $SEA/$SDATA
16219Store effective address/data
16220@item $AEA/$ADATA
16221Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
16222@item $FETCH
16223Fetch data
16224@end table
16225
16226When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
16227@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
16228
16229@code{htrace} commands:
16230@cindex OpenRISC 1000 htrace
16231@table @code
16232@kindex hwatch
16233@item hwatch @var{conditional}
d3e8051b 16234Set hardware watchpoint on combination of Load/Store Effective Address(es)
a37295f9
MM
16235or Data. For example:
16236
16237@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
16238
16239@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
16240
4644b6e3 16241@kindex htrace
a37295f9
MM
16242@item htrace info
16243Display information about current HW trace configuration.
16244
a37295f9
MM
16245@item htrace trigger @var{conditional}
16246Set starting criteria for HW trace.
16247
a37295f9
MM
16248@item htrace qualifier @var{conditional}
16249Set acquisition qualifier for HW trace.
16250
a37295f9
MM
16251@item htrace stop @var{conditional}
16252Set HW trace stopping criteria.
16253
f153cc92 16254@item htrace record [@var{data}]*
a37295f9
MM
16255Selects the data to be recorded, when qualifier is met and HW trace was
16256triggered.
16257
a37295f9 16258@item htrace enable
a37295f9
MM
16259@itemx htrace disable
16260Enables/disables the HW trace.
16261
f153cc92 16262@item htrace rewind [@var{filename}]
a37295f9
MM
16263Clears currently recorded trace data.
16264
16265If filename is specified, new trace file is made and any newly collected data
16266will be written there.
16267
f153cc92 16268@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
16269Prints trace buffer, using current record configuration.
16270
a37295f9
MM
16271@item htrace mode continuous
16272Set continuous trace mode.
16273
a37295f9
MM
16274@item htrace mode suspend
16275Set suspend trace mode.
16276
16277@end table
16278
4acd40f3
TJB
16279@node PowerPC Embedded
16280@subsection PowerPC Embedded
104c1213 16281
55eddb0f
DJ
16282@value{GDBN} provides the following PowerPC-specific commands:
16283
104c1213 16284@table @code
55eddb0f
DJ
16285@kindex set powerpc
16286@item set powerpc soft-float
16287@itemx show powerpc soft-float
16288Force @value{GDBN} to use (or not use) a software floating point calling
16289convention. By default, @value{GDBN} selects the calling convention based
16290on the selected architecture and the provided executable file.
16291
16292@item set powerpc vector-abi
16293@itemx show powerpc vector-abi
16294Force @value{GDBN} to use the specified calling convention for vector
16295arguments and return values. The valid options are @samp{auto};
16296@samp{generic}, to avoid vector registers even if they are present;
16297@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
16298registers. By default, @value{GDBN} selects the calling convention
16299based on the selected architecture and the provided executable file.
16300
8e04817f
AC
16301@kindex target dink32
16302@item target dink32 @var{dev}
16303DINK32 ROM monitor.
104c1213 16304
8e04817f
AC
16305@kindex target ppcbug
16306@item target ppcbug @var{dev}
16307@kindex target ppcbug1
16308@item target ppcbug1 @var{dev}
16309PPCBUG ROM monitor for PowerPC.
104c1213 16310
8e04817f
AC
16311@kindex target sds
16312@item target sds @var{dev}
16313SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 16314@end table
8e04817f 16315
c45da7e6 16316@cindex SDS protocol
d52fb0e9 16317The following commands specific to the SDS protocol are supported
55eddb0f 16318by @value{GDBN}:
c45da7e6
EZ
16319
16320@table @code
16321@item set sdstimeout @var{nsec}
16322@kindex set sdstimeout
16323Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
16324default is 2 seconds.
16325
16326@item show sdstimeout
16327@kindex show sdstimeout
16328Show the current value of the SDS timeout.
16329
16330@item sds @var{command}
16331@kindex sds@r{, a command}
16332Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
16333@end table
16334
c45da7e6 16335
8e04817f
AC
16336@node PA
16337@subsection HP PA Embedded
104c1213
JM
16338
16339@table @code
16340
8e04817f
AC
16341@kindex target op50n
16342@item target op50n @var{dev}
16343OP50N monitor, running on an OKI HPPA board.
16344
16345@kindex target w89k
16346@item target w89k @var{dev}
16347W89K monitor, running on a Winbond HPPA board.
104c1213
JM
16348
16349@end table
16350
8e04817f
AC
16351@node Sparclet
16352@subsection Tsqware Sparclet
104c1213 16353
8e04817f
AC
16354@cindex Sparclet
16355
16356@value{GDBN} enables developers to debug tasks running on
16357Sparclet targets from a Unix host.
16358@value{GDBN} uses code that runs on
16359both the Unix host and on the Sparclet target. The program
16360@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 16361
8e04817f
AC
16362@table @code
16363@item remotetimeout @var{args}
16364@kindex remotetimeout
16365@value{GDBN} supports the option @code{remotetimeout}.
16366This option is set by the user, and @var{args} represents the number of
16367seconds @value{GDBN} waits for responses.
104c1213
JM
16368@end table
16369
8e04817f
AC
16370@cindex compiling, on Sparclet
16371When compiling for debugging, include the options @samp{-g} to get debug
16372information and @samp{-Ttext} to relocate the program to where you wish to
16373load it on the target. You may also want to add the options @samp{-n} or
16374@samp{-N} in order to reduce the size of the sections. Example:
104c1213 16375
474c8240 16376@smallexample
8e04817f 16377sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 16378@end smallexample
104c1213 16379
8e04817f 16380You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 16381
474c8240 16382@smallexample
8e04817f 16383sparclet-aout-objdump --headers --syms prog
474c8240 16384@end smallexample
104c1213 16385
8e04817f
AC
16386@cindex running, on Sparclet
16387Once you have set
16388your Unix execution search path to find @value{GDBN}, you are ready to
16389run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
16390(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 16391
8e04817f
AC
16392@value{GDBN} comes up showing the prompt:
16393
474c8240 16394@smallexample
8e04817f 16395(gdbslet)
474c8240 16396@end smallexample
104c1213
JM
16397
16398@menu
8e04817f
AC
16399* Sparclet File:: Setting the file to debug
16400* Sparclet Connection:: Connecting to Sparclet
16401* Sparclet Download:: Sparclet download
16402* Sparclet Execution:: Running and debugging
104c1213
JM
16403@end menu
16404
8e04817f 16405@node Sparclet File
79a6e687 16406@subsubsection Setting File to Debug
104c1213 16407
8e04817f 16408The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 16409
474c8240 16410@smallexample
8e04817f 16411(gdbslet) file prog
474c8240 16412@end smallexample
104c1213 16413
8e04817f
AC
16414@need 1000
16415@value{GDBN} then attempts to read the symbol table of @file{prog}.
16416@value{GDBN} locates
16417the file by searching the directories listed in the command search
16418path.
12c27660 16419If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
16420files will be searched as well.
16421@value{GDBN} locates
16422the source files by searching the directories listed in the directory search
79a6e687 16423path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
16424If it fails
16425to find a file, it displays a message such as:
104c1213 16426
474c8240 16427@smallexample
8e04817f 16428prog: No such file or directory.
474c8240 16429@end smallexample
104c1213 16430
8e04817f
AC
16431When this happens, add the appropriate directories to the search paths with
16432the @value{GDBN} commands @code{path} and @code{dir}, and execute the
16433@code{target} command again.
104c1213 16434
8e04817f
AC
16435@node Sparclet Connection
16436@subsubsection Connecting to Sparclet
104c1213 16437
8e04817f
AC
16438The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
16439To connect to a target on serial port ``@code{ttya}'', type:
104c1213 16440
474c8240 16441@smallexample
8e04817f
AC
16442(gdbslet) target sparclet /dev/ttya
16443Remote target sparclet connected to /dev/ttya
16444main () at ../prog.c:3
474c8240 16445@end smallexample
104c1213 16446
8e04817f
AC
16447@need 750
16448@value{GDBN} displays messages like these:
104c1213 16449
474c8240 16450@smallexample
8e04817f 16451Connected to ttya.
474c8240 16452@end smallexample
104c1213 16453
8e04817f 16454@node Sparclet Download
79a6e687 16455@subsubsection Sparclet Download
104c1213 16456
8e04817f
AC
16457@cindex download to Sparclet
16458Once connected to the Sparclet target,
16459you can use the @value{GDBN}
16460@code{load} command to download the file from the host to the target.
16461The file name and load offset should be given as arguments to the @code{load}
16462command.
16463Since the file format is aout, the program must be loaded to the starting
16464address. You can use @code{objdump} to find out what this value is. The load
16465offset is an offset which is added to the VMA (virtual memory address)
16466of each of the file's sections.
16467For instance, if the program
16468@file{prog} was linked to text address 0x1201000, with data at 0x12010160
16469and bss at 0x12010170, in @value{GDBN}, type:
104c1213 16470
474c8240 16471@smallexample
8e04817f
AC
16472(gdbslet) load prog 0x12010000
16473Loading section .text, size 0xdb0 vma 0x12010000
474c8240 16474@end smallexample
104c1213 16475
8e04817f
AC
16476If the code is loaded at a different address then what the program was linked
16477to, you may need to use the @code{section} and @code{add-symbol-file} commands
16478to tell @value{GDBN} where to map the symbol table.
16479
16480@node Sparclet Execution
79a6e687 16481@subsubsection Running and Debugging
8e04817f
AC
16482
16483@cindex running and debugging Sparclet programs
16484You can now begin debugging the task using @value{GDBN}'s execution control
16485commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
16486manual for the list of commands.
16487
474c8240 16488@smallexample
8e04817f
AC
16489(gdbslet) b main
16490Breakpoint 1 at 0x12010000: file prog.c, line 3.
16491(gdbslet) run
16492Starting program: prog
16493Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
164943 char *symarg = 0;
16495(gdbslet) step
164964 char *execarg = "hello!";
16497(gdbslet)
474c8240 16498@end smallexample
8e04817f
AC
16499
16500@node Sparclite
16501@subsection Fujitsu Sparclite
104c1213
JM
16502
16503@table @code
16504
8e04817f
AC
16505@kindex target sparclite
16506@item target sparclite @var{dev}
16507Fujitsu sparclite boards, used only for the purpose of loading.
16508You must use an additional command to debug the program.
16509For example: target remote @var{dev} using @value{GDBN} standard
16510remote protocol.
104c1213
JM
16511
16512@end table
16513
8e04817f
AC
16514@node Z8000
16515@subsection Zilog Z8000
104c1213 16516
8e04817f
AC
16517@cindex Z8000
16518@cindex simulator, Z8000
16519@cindex Zilog Z8000 simulator
104c1213 16520
8e04817f
AC
16521When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
16522a Z8000 simulator.
16523
16524For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
16525unsegmented variant of the Z8000 architecture) or the Z8001 (the
16526segmented variant). The simulator recognizes which architecture is
16527appropriate by inspecting the object code.
104c1213 16528
8e04817f
AC
16529@table @code
16530@item target sim @var{args}
16531@kindex sim
16532@kindex target sim@r{, with Z8000}
16533Debug programs on a simulated CPU. If the simulator supports setup
16534options, specify them via @var{args}.
104c1213
JM
16535@end table
16536
8e04817f
AC
16537@noindent
16538After specifying this target, you can debug programs for the simulated
16539CPU in the same style as programs for your host computer; use the
16540@code{file} command to load a new program image, the @code{run} command
16541to run your program, and so on.
16542
16543As well as making available all the usual machine registers
16544(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
16545additional items of information as specially named registers:
104c1213
JM
16546
16547@table @code
16548
8e04817f
AC
16549@item cycles
16550Counts clock-ticks in the simulator.
104c1213 16551
8e04817f
AC
16552@item insts
16553Counts instructions run in the simulator.
104c1213 16554
8e04817f
AC
16555@item time
16556Execution time in 60ths of a second.
104c1213 16557
8e04817f 16558@end table
104c1213 16559
8e04817f
AC
16560You can refer to these values in @value{GDBN} expressions with the usual
16561conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
16562conditional breakpoint that suspends only after at least 5000
16563simulated clock ticks.
104c1213 16564
a64548ea
EZ
16565@node AVR
16566@subsection Atmel AVR
16567@cindex AVR
16568
16569When configured for debugging the Atmel AVR, @value{GDBN} supports the
16570following AVR-specific commands:
16571
16572@table @code
16573@item info io_registers
16574@kindex info io_registers@r{, AVR}
16575@cindex I/O registers (Atmel AVR)
16576This command displays information about the AVR I/O registers. For
16577each register, @value{GDBN} prints its number and value.
16578@end table
16579
16580@node CRIS
16581@subsection CRIS
16582@cindex CRIS
16583
16584When configured for debugging CRIS, @value{GDBN} provides the
16585following CRIS-specific commands:
16586
16587@table @code
16588@item set cris-version @var{ver}
16589@cindex CRIS version
e22e55c9
OF
16590Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
16591The CRIS version affects register names and sizes. This command is useful in
16592case autodetection of the CRIS version fails.
a64548ea
EZ
16593
16594@item show cris-version
16595Show the current CRIS version.
16596
16597@item set cris-dwarf2-cfi
16598@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
16599Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
16600Change to @samp{off} when using @code{gcc-cris} whose version is below
16601@code{R59}.
a64548ea
EZ
16602
16603@item show cris-dwarf2-cfi
16604Show the current state of using DWARF-2 CFI.
e22e55c9
OF
16605
16606@item set cris-mode @var{mode}
16607@cindex CRIS mode
16608Set the current CRIS mode to @var{mode}. It should only be changed when
16609debugging in guru mode, in which case it should be set to
16610@samp{guru} (the default is @samp{normal}).
16611
16612@item show cris-mode
16613Show the current CRIS mode.
a64548ea
EZ
16614@end table
16615
16616@node Super-H
16617@subsection Renesas Super-H
16618@cindex Super-H
16619
16620For the Renesas Super-H processor, @value{GDBN} provides these
16621commands:
16622
16623@table @code
16624@item regs
16625@kindex regs@r{, Super-H}
16626Show the values of all Super-H registers.
c055b101
CV
16627
16628@item set sh calling-convention @var{convention}
16629@kindex set sh calling-convention
16630Set the calling-convention used when calling functions from @value{GDBN}.
16631Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
16632With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
16633convention. If the DWARF-2 information of the called function specifies
16634that the function follows the Renesas calling convention, the function
16635is called using the Renesas calling convention. If the calling convention
16636is set to @samp{renesas}, the Renesas calling convention is always used,
16637regardless of the DWARF-2 information. This can be used to override the
16638default of @samp{gcc} if debug information is missing, or the compiler
16639does not emit the DWARF-2 calling convention entry for a function.
16640
16641@item show sh calling-convention
16642@kindex show sh calling-convention
16643Show the current calling convention setting.
16644
a64548ea
EZ
16645@end table
16646
16647
8e04817f
AC
16648@node Architectures
16649@section Architectures
104c1213 16650
8e04817f
AC
16651This section describes characteristics of architectures that affect
16652all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 16653
8e04817f 16654@menu
9c16f35a 16655* i386::
8e04817f
AC
16656* A29K::
16657* Alpha::
16658* MIPS::
a64548ea 16659* HPPA:: HP PA architecture
23d964e7 16660* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 16661* PowerPC::
8e04817f 16662@end menu
104c1213 16663
9c16f35a 16664@node i386
db2e3e2e 16665@subsection x86 Architecture-specific Issues
9c16f35a
EZ
16666
16667@table @code
16668@item set struct-convention @var{mode}
16669@kindex set struct-convention
16670@cindex struct return convention
16671@cindex struct/union returned in registers
16672Set the convention used by the inferior to return @code{struct}s and
16673@code{union}s from functions to @var{mode}. Possible values of
16674@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
16675default). @code{"default"} or @code{"pcc"} means that @code{struct}s
16676are returned on the stack, while @code{"reg"} means that a
16677@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
16678be returned in a register.
16679
16680@item show struct-convention
16681@kindex show struct-convention
16682Show the current setting of the convention to return @code{struct}s
16683from functions.
16684@end table
16685
8e04817f
AC
16686@node A29K
16687@subsection A29K
104c1213
JM
16688
16689@table @code
104c1213 16690
8e04817f
AC
16691@kindex set rstack_high_address
16692@cindex AMD 29K register stack
16693@cindex register stack, AMD29K
16694@item set rstack_high_address @var{address}
16695On AMD 29000 family processors, registers are saved in a separate
16696@dfn{register stack}. There is no way for @value{GDBN} to determine the
16697extent of this stack. Normally, @value{GDBN} just assumes that the
16698stack is ``large enough''. This may result in @value{GDBN} referencing
16699memory locations that do not exist. If necessary, you can get around
16700this problem by specifying the ending address of the register stack with
16701the @code{set rstack_high_address} command. The argument should be an
16702address, which you probably want to precede with @samp{0x} to specify in
16703hexadecimal.
104c1213 16704
8e04817f
AC
16705@kindex show rstack_high_address
16706@item show rstack_high_address
16707Display the current limit of the register stack, on AMD 29000 family
16708processors.
104c1213 16709
8e04817f 16710@end table
104c1213 16711
8e04817f
AC
16712@node Alpha
16713@subsection Alpha
104c1213 16714
8e04817f 16715See the following section.
104c1213 16716
8e04817f
AC
16717@node MIPS
16718@subsection MIPS
104c1213 16719
8e04817f
AC
16720@cindex stack on Alpha
16721@cindex stack on MIPS
16722@cindex Alpha stack
16723@cindex MIPS stack
16724Alpha- and MIPS-based computers use an unusual stack frame, which
16725sometimes requires @value{GDBN} to search backward in the object code to
16726find the beginning of a function.
104c1213 16727
8e04817f
AC
16728@cindex response time, MIPS debugging
16729To improve response time (especially for embedded applications, where
16730@value{GDBN} may be restricted to a slow serial line for this search)
16731you may want to limit the size of this search, using one of these
16732commands:
104c1213 16733
8e04817f
AC
16734@table @code
16735@cindex @code{heuristic-fence-post} (Alpha, MIPS)
16736@item set heuristic-fence-post @var{limit}
16737Restrict @value{GDBN} to examining at most @var{limit} bytes in its
16738search for the beginning of a function. A value of @var{0} (the
16739default) means there is no limit. However, except for @var{0}, the
16740larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
16741and therefore the longer it takes to run. You should only need to use
16742this command when debugging a stripped executable.
104c1213 16743
8e04817f
AC
16744@item show heuristic-fence-post
16745Display the current limit.
16746@end table
104c1213
JM
16747
16748@noindent
8e04817f
AC
16749These commands are available @emph{only} when @value{GDBN} is configured
16750for debugging programs on Alpha or MIPS processors.
104c1213 16751
a64548ea
EZ
16752Several MIPS-specific commands are available when debugging MIPS
16753programs:
16754
16755@table @code
a64548ea
EZ
16756@item set mips abi @var{arg}
16757@kindex set mips abi
16758@cindex set ABI for MIPS
16759Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
16760values of @var{arg} are:
16761
16762@table @samp
16763@item auto
16764The default ABI associated with the current binary (this is the
16765default).
16766@item o32
16767@item o64
16768@item n32
16769@item n64
16770@item eabi32
16771@item eabi64
16772@item auto
16773@end table
16774
16775@item show mips abi
16776@kindex show mips abi
16777Show the MIPS ABI used by @value{GDBN} to debug the inferior.
16778
16779@item set mipsfpu
16780@itemx show mipsfpu
16781@xref{MIPS Embedded, set mipsfpu}.
16782
16783@item set mips mask-address @var{arg}
16784@kindex set mips mask-address
16785@cindex MIPS addresses, masking
16786This command determines whether the most-significant 32 bits of 64-bit
16787MIPS addresses are masked off. The argument @var{arg} can be
16788@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
16789setting, which lets @value{GDBN} determine the correct value.
16790
16791@item show mips mask-address
16792@kindex show mips mask-address
16793Show whether the upper 32 bits of MIPS addresses are masked off or
16794not.
16795
16796@item set remote-mips64-transfers-32bit-regs
16797@kindex set remote-mips64-transfers-32bit-regs
16798This command controls compatibility with 64-bit MIPS targets that
16799transfer data in 32-bit quantities. If you have an old MIPS 64 target
16800that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
16801and 64 bits for other registers, set this option to @samp{on}.
16802
16803@item show remote-mips64-transfers-32bit-regs
16804@kindex show remote-mips64-transfers-32bit-regs
16805Show the current setting of compatibility with older MIPS 64 targets.
16806
16807@item set debug mips
16808@kindex set debug mips
16809This command turns on and off debugging messages for the MIPS-specific
16810target code in @value{GDBN}.
16811
16812@item show debug mips
16813@kindex show debug mips
16814Show the current setting of MIPS debugging messages.
16815@end table
16816
16817
16818@node HPPA
16819@subsection HPPA
16820@cindex HPPA support
16821
d3e8051b 16822When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
16823following special commands:
16824
16825@table @code
16826@item set debug hppa
16827@kindex set debug hppa
db2e3e2e 16828This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
16829messages are to be displayed.
16830
16831@item show debug hppa
16832Show whether HPPA debugging messages are displayed.
16833
16834@item maint print unwind @var{address}
16835@kindex maint print unwind@r{, HPPA}
16836This command displays the contents of the unwind table entry at the
16837given @var{address}.
16838
16839@end table
16840
104c1213 16841
23d964e7
UW
16842@node SPU
16843@subsection Cell Broadband Engine SPU architecture
16844@cindex Cell Broadband Engine
16845@cindex SPU
16846
16847When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
16848it provides the following special commands:
16849
16850@table @code
16851@item info spu event
16852@kindex info spu
16853Display SPU event facility status. Shows current event mask
16854and pending event status.
16855
16856@item info spu signal
16857Display SPU signal notification facility status. Shows pending
16858signal-control word and signal notification mode of both signal
16859notification channels.
16860
16861@item info spu mailbox
16862Display SPU mailbox facility status. Shows all pending entries,
16863in order of processing, in each of the SPU Write Outbound,
16864SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
16865
16866@item info spu dma
16867Display MFC DMA status. Shows all pending commands in the MFC
16868DMA queue. For each entry, opcode, tag, class IDs, effective
16869and local store addresses and transfer size are shown.
16870
16871@item info spu proxydma
16872Display MFC Proxy-DMA status. Shows all pending commands in the MFC
16873Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
16874and local store addresses and transfer size are shown.
16875
16876@end table
16877
4acd40f3
TJB
16878@node PowerPC
16879@subsection PowerPC
16880@cindex PowerPC architecture
16881
16882When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
16883pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
16884numbers stored in the floating point registers. These values must be stored
16885in two consecutive registers, always starting at an even register like
16886@code{f0} or @code{f2}.
16887
16888The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
16889by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
16890@code{f2} and @code{f3} for @code{$dl1} and so on.
16891
aeac0ff9 16892For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
16893wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
16894
23d964e7 16895
8e04817f
AC
16896@node Controlling GDB
16897@chapter Controlling @value{GDBN}
16898
16899You can alter the way @value{GDBN} interacts with you by using the
16900@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 16901data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
16902described here.
16903
16904@menu
16905* Prompt:: Prompt
16906* Editing:: Command editing
d620b259 16907* Command History:: Command history
8e04817f
AC
16908* Screen Size:: Screen size
16909* Numbers:: Numbers
1e698235 16910* ABI:: Configuring the current ABI
8e04817f
AC
16911* Messages/Warnings:: Optional warnings and messages
16912* Debugging Output:: Optional messages about internal happenings
16913@end menu
16914
16915@node Prompt
16916@section Prompt
104c1213 16917
8e04817f 16918@cindex prompt
104c1213 16919
8e04817f
AC
16920@value{GDBN} indicates its readiness to read a command by printing a string
16921called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
16922can change the prompt string with the @code{set prompt} command. For
16923instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
16924the prompt in one of the @value{GDBN} sessions so that you can always tell
16925which one you are talking to.
104c1213 16926
8e04817f
AC
16927@emph{Note:} @code{set prompt} does not add a space for you after the
16928prompt you set. This allows you to set a prompt which ends in a space
16929or a prompt that does not.
104c1213 16930
8e04817f
AC
16931@table @code
16932@kindex set prompt
16933@item set prompt @var{newprompt}
16934Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 16935
8e04817f
AC
16936@kindex show prompt
16937@item show prompt
16938Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
16939@end table
16940
8e04817f 16941@node Editing
79a6e687 16942@section Command Editing
8e04817f
AC
16943@cindex readline
16944@cindex command line editing
104c1213 16945
703663ab 16946@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
16947@sc{gnu} library provides consistent behavior for programs which provide a
16948command line interface to the user. Advantages are @sc{gnu} Emacs-style
16949or @dfn{vi}-style inline editing of commands, @code{csh}-like history
16950substitution, and a storage and recall of command history across
16951debugging sessions.
104c1213 16952
8e04817f
AC
16953You may control the behavior of command line editing in @value{GDBN} with the
16954command @code{set}.
104c1213 16955
8e04817f
AC
16956@table @code
16957@kindex set editing
16958@cindex editing
16959@item set editing
16960@itemx set editing on
16961Enable command line editing (enabled by default).
104c1213 16962
8e04817f
AC
16963@item set editing off
16964Disable command line editing.
104c1213 16965
8e04817f
AC
16966@kindex show editing
16967@item show editing
16968Show whether command line editing is enabled.
104c1213
JM
16969@end table
16970
703663ab
EZ
16971@xref{Command Line Editing}, for more details about the Readline
16972interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
16973encouraged to read that chapter.
16974
d620b259 16975@node Command History
79a6e687 16976@section Command History
703663ab 16977@cindex command history
8e04817f
AC
16978
16979@value{GDBN} can keep track of the commands you type during your
16980debugging sessions, so that you can be certain of precisely what
16981happened. Use these commands to manage the @value{GDBN} command
16982history facility.
104c1213 16983
703663ab
EZ
16984@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
16985package, to provide the history facility. @xref{Using History
16986Interactively}, for the detailed description of the History library.
16987
d620b259 16988To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
16989the state which is seen by users, prefix it with @samp{server }
16990(@pxref{Server Prefix}). This
d620b259
NR
16991means that this command will not affect the command history, nor will it
16992affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
16993pressed on a line by itself.
16994
16995@cindex @code{server}, command prefix
16996The server prefix does not affect the recording of values into the value
16997history; to print a value without recording it into the value history,
16998use the @code{output} command instead of the @code{print} command.
16999
703663ab
EZ
17000Here is the description of @value{GDBN} commands related to command
17001history.
17002
104c1213 17003@table @code
8e04817f
AC
17004@cindex history substitution
17005@cindex history file
17006@kindex set history filename
4644b6e3 17007@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
17008@item set history filename @var{fname}
17009Set the name of the @value{GDBN} command history file to @var{fname}.
17010This is the file where @value{GDBN} reads an initial command history
17011list, and where it writes the command history from this session when it
17012exits. You can access this list through history expansion or through
17013the history command editing characters listed below. This file defaults
17014to the value of the environment variable @code{GDBHISTFILE}, or to
17015@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
17016is not set.
104c1213 17017
9c16f35a
EZ
17018@cindex save command history
17019@kindex set history save
8e04817f
AC
17020@item set history save
17021@itemx set history save on
17022Record command history in a file, whose name may be specified with the
17023@code{set history filename} command. By default, this option is disabled.
104c1213 17024
8e04817f
AC
17025@item set history save off
17026Stop recording command history in a file.
104c1213 17027
8e04817f 17028@cindex history size
9c16f35a 17029@kindex set history size
6fc08d32 17030@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
17031@item set history size @var{size}
17032Set the number of commands which @value{GDBN} keeps in its history list.
17033This defaults to the value of the environment variable
17034@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
17035@end table
17036
8e04817f 17037History expansion assigns special meaning to the character @kbd{!}.
703663ab 17038@xref{Event Designators}, for more details.
8e04817f 17039
703663ab 17040@cindex history expansion, turn on/off
8e04817f
AC
17041Since @kbd{!} is also the logical not operator in C, history expansion
17042is off by default. If you decide to enable history expansion with the
17043@code{set history expansion on} command, you may sometimes need to
17044follow @kbd{!} (when it is used as logical not, in an expression) with
17045a space or a tab to prevent it from being expanded. The readline
17046history facilities do not attempt substitution on the strings
17047@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
17048
17049The commands to control history expansion are:
104c1213
JM
17050
17051@table @code
8e04817f
AC
17052@item set history expansion on
17053@itemx set history expansion
703663ab 17054@kindex set history expansion
8e04817f 17055Enable history expansion. History expansion is off by default.
104c1213 17056
8e04817f
AC
17057@item set history expansion off
17058Disable history expansion.
104c1213 17059
8e04817f
AC
17060@c @group
17061@kindex show history
17062@item show history
17063@itemx show history filename
17064@itemx show history save
17065@itemx show history size
17066@itemx show history expansion
17067These commands display the state of the @value{GDBN} history parameters.
17068@code{show history} by itself displays all four states.
17069@c @end group
17070@end table
17071
17072@table @code
9c16f35a
EZ
17073@kindex show commands
17074@cindex show last commands
17075@cindex display command history
8e04817f
AC
17076@item show commands
17077Display the last ten commands in the command history.
104c1213 17078
8e04817f
AC
17079@item show commands @var{n}
17080Print ten commands centered on command number @var{n}.
17081
17082@item show commands +
17083Print ten commands just after the commands last printed.
104c1213
JM
17084@end table
17085
8e04817f 17086@node Screen Size
79a6e687 17087@section Screen Size
8e04817f
AC
17088@cindex size of screen
17089@cindex pauses in output
104c1213 17090
8e04817f
AC
17091Certain commands to @value{GDBN} may produce large amounts of
17092information output to the screen. To help you read all of it,
17093@value{GDBN} pauses and asks you for input at the end of each page of
17094output. Type @key{RET} when you want to continue the output, or @kbd{q}
17095to discard the remaining output. Also, the screen width setting
17096determines when to wrap lines of output. Depending on what is being
17097printed, @value{GDBN} tries to break the line at a readable place,
17098rather than simply letting it overflow onto the following line.
17099
17100Normally @value{GDBN} knows the size of the screen from the terminal
17101driver software. For example, on Unix @value{GDBN} uses the termcap data base
17102together with the value of the @code{TERM} environment variable and the
17103@code{stty rows} and @code{stty cols} settings. If this is not correct,
17104you can override it with the @code{set height} and @code{set
17105width} commands:
17106
17107@table @code
17108@kindex set height
17109@kindex set width
17110@kindex show width
17111@kindex show height
17112@item set height @var{lpp}
17113@itemx show height
17114@itemx set width @var{cpl}
17115@itemx show width
17116These @code{set} commands specify a screen height of @var{lpp} lines and
17117a screen width of @var{cpl} characters. The associated @code{show}
17118commands display the current settings.
104c1213 17119
8e04817f
AC
17120If you specify a height of zero lines, @value{GDBN} does not pause during
17121output no matter how long the output is. This is useful if output is to a
17122file or to an editor buffer.
104c1213 17123
8e04817f
AC
17124Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
17125from wrapping its output.
9c16f35a
EZ
17126
17127@item set pagination on
17128@itemx set pagination off
17129@kindex set pagination
17130Turn the output pagination on or off; the default is on. Turning
17131pagination off is the alternative to @code{set height 0}.
17132
17133@item show pagination
17134@kindex show pagination
17135Show the current pagination mode.
104c1213
JM
17136@end table
17137
8e04817f
AC
17138@node Numbers
17139@section Numbers
17140@cindex number representation
17141@cindex entering numbers
104c1213 17142
8e04817f
AC
17143You can always enter numbers in octal, decimal, or hexadecimal in
17144@value{GDBN} by the usual conventions: octal numbers begin with
17145@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
17146begin with @samp{0x}. Numbers that neither begin with @samp{0} or
17147@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1714810; likewise, the default display for numbers---when no particular
17149format is specified---is base 10. You can change the default base for
17150both input and output with the commands described below.
104c1213 17151
8e04817f
AC
17152@table @code
17153@kindex set input-radix
17154@item set input-radix @var{base}
17155Set the default base for numeric input. Supported choices
17156for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 17157specified either unambiguously or using the current input radix; for
8e04817f 17158example, any of
104c1213 17159
8e04817f 17160@smallexample
9c16f35a
EZ
17161set input-radix 012
17162set input-radix 10.
17163set input-radix 0xa
8e04817f 17164@end smallexample
104c1213 17165
8e04817f 17166@noindent
9c16f35a 17167sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
17168leaves the input radix unchanged, no matter what it was, since
17169@samp{10}, being without any leading or trailing signs of its base, is
17170interpreted in the current radix. Thus, if the current radix is 16,
17171@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
17172change the radix.
104c1213 17173
8e04817f
AC
17174@kindex set output-radix
17175@item set output-radix @var{base}
17176Set the default base for numeric display. Supported choices
17177for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 17178specified either unambiguously or using the current input radix.
104c1213 17179
8e04817f
AC
17180@kindex show input-radix
17181@item show input-radix
17182Display the current default base for numeric input.
104c1213 17183
8e04817f
AC
17184@kindex show output-radix
17185@item show output-radix
17186Display the current default base for numeric display.
9c16f35a
EZ
17187
17188@item set radix @r{[}@var{base}@r{]}
17189@itemx show radix
17190@kindex set radix
17191@kindex show radix
17192These commands set and show the default base for both input and output
17193of numbers. @code{set radix} sets the radix of input and output to
17194the same base; without an argument, it resets the radix back to its
17195default value of 10.
17196
8e04817f 17197@end table
104c1213 17198
1e698235 17199@node ABI
79a6e687 17200@section Configuring the Current ABI
1e698235
DJ
17201
17202@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
17203application automatically. However, sometimes you need to override its
17204conclusions. Use these commands to manage @value{GDBN}'s view of the
17205current ABI.
17206
98b45e30
DJ
17207@cindex OS ABI
17208@kindex set osabi
b4e9345d 17209@kindex show osabi
98b45e30
DJ
17210
17211One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 17212system targets, either via remote debugging or native emulation.
98b45e30
DJ
17213@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
17214but you can override its conclusion using the @code{set osabi} command.
17215One example where this is useful is in debugging of binaries which use
17216an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
17217not have the same identifying marks that the standard C library for your
17218platform provides.
17219
17220@table @code
17221@item show osabi
17222Show the OS ABI currently in use.
17223
17224@item set osabi
17225With no argument, show the list of registered available OS ABI's.
17226
17227@item set osabi @var{abi}
17228Set the current OS ABI to @var{abi}.
17229@end table
17230
1e698235 17231@cindex float promotion
1e698235
DJ
17232
17233Generally, the way that an argument of type @code{float} is passed to a
17234function depends on whether the function is prototyped. For a prototyped
17235(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
17236according to the architecture's convention for @code{float}. For unprototyped
17237(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
17238@code{double} and then passed.
17239
17240Unfortunately, some forms of debug information do not reliably indicate whether
17241a function is prototyped. If @value{GDBN} calls a function that is not marked
17242as prototyped, it consults @kbd{set coerce-float-to-double}.
17243
17244@table @code
a8f24a35 17245@kindex set coerce-float-to-double
1e698235
DJ
17246@item set coerce-float-to-double
17247@itemx set coerce-float-to-double on
17248Arguments of type @code{float} will be promoted to @code{double} when passed
17249to an unprototyped function. This is the default setting.
17250
17251@item set coerce-float-to-double off
17252Arguments of type @code{float} will be passed directly to unprototyped
17253functions.
9c16f35a
EZ
17254
17255@kindex show coerce-float-to-double
17256@item show coerce-float-to-double
17257Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
17258@end table
17259
f1212245
DJ
17260@kindex set cp-abi
17261@kindex show cp-abi
17262@value{GDBN} needs to know the ABI used for your program's C@t{++}
17263objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
17264used to build your application. @value{GDBN} only fully supports
17265programs with a single C@t{++} ABI; if your program contains code using
17266multiple C@t{++} ABI's or if @value{GDBN} can not identify your
17267program's ABI correctly, you can tell @value{GDBN} which ABI to use.
17268Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
17269before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
17270``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
17271use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
17272``auto''.
17273
17274@table @code
17275@item show cp-abi
17276Show the C@t{++} ABI currently in use.
17277
17278@item set cp-abi
17279With no argument, show the list of supported C@t{++} ABI's.
17280
17281@item set cp-abi @var{abi}
17282@itemx set cp-abi auto
17283Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
17284@end table
17285
8e04817f 17286@node Messages/Warnings
79a6e687 17287@section Optional Warnings and Messages
104c1213 17288
9c16f35a
EZ
17289@cindex verbose operation
17290@cindex optional warnings
8e04817f
AC
17291By default, @value{GDBN} is silent about its inner workings. If you are
17292running on a slow machine, you may want to use the @code{set verbose}
17293command. This makes @value{GDBN} tell you when it does a lengthy
17294internal operation, so you will not think it has crashed.
104c1213 17295
8e04817f
AC
17296Currently, the messages controlled by @code{set verbose} are those
17297which announce that the symbol table for a source file is being read;
79a6e687 17298see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 17299
8e04817f
AC
17300@table @code
17301@kindex set verbose
17302@item set verbose on
17303Enables @value{GDBN} output of certain informational messages.
104c1213 17304
8e04817f
AC
17305@item set verbose off
17306Disables @value{GDBN} output of certain informational messages.
104c1213 17307
8e04817f
AC
17308@kindex show verbose
17309@item show verbose
17310Displays whether @code{set verbose} is on or off.
17311@end table
104c1213 17312
8e04817f
AC
17313By default, if @value{GDBN} encounters bugs in the symbol table of an
17314object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
17315find this information useful (@pxref{Symbol Errors, ,Errors Reading
17316Symbol Files}).
104c1213 17317
8e04817f 17318@table @code
104c1213 17319
8e04817f
AC
17320@kindex set complaints
17321@item set complaints @var{limit}
17322Permits @value{GDBN} to output @var{limit} complaints about each type of
17323unusual symbols before becoming silent about the problem. Set
17324@var{limit} to zero to suppress all complaints; set it to a large number
17325to prevent complaints from being suppressed.
104c1213 17326
8e04817f
AC
17327@kindex show complaints
17328@item show complaints
17329Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 17330
8e04817f 17331@end table
104c1213 17332
8e04817f
AC
17333By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
17334lot of stupid questions to confirm certain commands. For example, if
17335you try to run a program which is already running:
104c1213 17336
474c8240 17337@smallexample
8e04817f
AC
17338(@value{GDBP}) run
17339The program being debugged has been started already.
17340Start it from the beginning? (y or n)
474c8240 17341@end smallexample
104c1213 17342
8e04817f
AC
17343If you are willing to unflinchingly face the consequences of your own
17344commands, you can disable this ``feature'':
104c1213 17345
8e04817f 17346@table @code
104c1213 17347
8e04817f
AC
17348@kindex set confirm
17349@cindex flinching
17350@cindex confirmation
17351@cindex stupid questions
17352@item set confirm off
17353Disables confirmation requests.
104c1213 17354
8e04817f
AC
17355@item set confirm on
17356Enables confirmation requests (the default).
104c1213 17357
8e04817f
AC
17358@kindex show confirm
17359@item show confirm
17360Displays state of confirmation requests.
17361
17362@end table
104c1213 17363
16026cd7
AS
17364@cindex command tracing
17365If you need to debug user-defined commands or sourced files you may find it
17366useful to enable @dfn{command tracing}. In this mode each command will be
17367printed as it is executed, prefixed with one or more @samp{+} symbols, the
17368quantity denoting the call depth of each command.
17369
17370@table @code
17371@kindex set trace-commands
17372@cindex command scripts, debugging
17373@item set trace-commands on
17374Enable command tracing.
17375@item set trace-commands off
17376Disable command tracing.
17377@item show trace-commands
17378Display the current state of command tracing.
17379@end table
17380
8e04817f 17381@node Debugging Output
79a6e687 17382@section Optional Messages about Internal Happenings
4644b6e3
EZ
17383@cindex optional debugging messages
17384
da316a69
EZ
17385@value{GDBN} has commands that enable optional debugging messages from
17386various @value{GDBN} subsystems; normally these commands are of
17387interest to @value{GDBN} maintainers, or when reporting a bug. This
17388section documents those commands.
17389
104c1213 17390@table @code
a8f24a35
EZ
17391@kindex set exec-done-display
17392@item set exec-done-display
17393Turns on or off the notification of asynchronous commands'
17394completion. When on, @value{GDBN} will print a message when an
17395asynchronous command finishes its execution. The default is off.
17396@kindex show exec-done-display
17397@item show exec-done-display
17398Displays the current setting of asynchronous command completion
17399notification.
4644b6e3
EZ
17400@kindex set debug
17401@cindex gdbarch debugging info
a8f24a35 17402@cindex architecture debugging info
8e04817f 17403@item set debug arch
a8f24a35 17404Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 17405@kindex show debug
8e04817f
AC
17406@item show debug arch
17407Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
17408@item set debug aix-thread
17409@cindex AIX threads
17410Display debugging messages about inner workings of the AIX thread
17411module.
17412@item show debug aix-thread
17413Show the current state of AIX thread debugging info display.
d97bc12b
DE
17414@item set debug dwarf2-die
17415@cindex DWARF2 DIEs
17416Dump DWARF2 DIEs after they are read in.
17417The value is the number of nesting levels to print.
17418A value of zero turns off the display.
17419@item show debug dwarf2-die
17420Show the current state of DWARF2 DIE debugging.
237fc4c9
PA
17421@item set debug displaced
17422@cindex displaced stepping debugging info
17423Turns on or off display of @value{GDBN} debugging info for the
17424displaced stepping support. The default is off.
17425@item show debug displaced
17426Displays the current state of displaying @value{GDBN} debugging info
17427related to displaced stepping.
8e04817f 17428@item set debug event
4644b6e3 17429@cindex event debugging info
a8f24a35 17430Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 17431default is off.
8e04817f
AC
17432@item show debug event
17433Displays the current state of displaying @value{GDBN} event debugging
17434info.
8e04817f 17435@item set debug expression
4644b6e3 17436@cindex expression debugging info
721c2651
EZ
17437Turns on or off display of debugging info about @value{GDBN}
17438expression parsing. The default is off.
8e04817f 17439@item show debug expression
721c2651
EZ
17440Displays the current state of displaying debugging info about
17441@value{GDBN} expression parsing.
7453dc06 17442@item set debug frame
4644b6e3 17443@cindex frame debugging info
7453dc06
AC
17444Turns on or off display of @value{GDBN} frame debugging info. The
17445default is off.
7453dc06
AC
17446@item show debug frame
17447Displays the current state of displaying @value{GDBN} frame debugging
17448info.
30e91e0b
RC
17449@item set debug infrun
17450@cindex inferior debugging info
17451Turns on or off display of @value{GDBN} debugging info for running the inferior.
17452The default is off. @file{infrun.c} contains GDB's runtime state machine used
17453for implementing operations such as single-stepping the inferior.
17454@item show debug infrun
17455Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
17456@item set debug lin-lwp
17457@cindex @sc{gnu}/Linux LWP debug messages
17458@cindex Linux lightweight processes
721c2651 17459Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
17460@item show debug lin-lwp
17461Show the current state of Linux LWP debugging messages.
b84876c2
PA
17462@item set debug lin-lwp-async
17463@cindex @sc{gnu}/Linux LWP async debug messages
17464@cindex Linux lightweight processes
17465Turns on or off debugging messages from the Linux LWP async debug support.
17466@item show debug lin-lwp-async
17467Show the current state of Linux LWP async debugging messages.
2b4855ab 17468@item set debug observer
4644b6e3 17469@cindex observer debugging info
2b4855ab
AC
17470Turns on or off display of @value{GDBN} observer debugging. This
17471includes info such as the notification of observable events.
2b4855ab
AC
17472@item show debug observer
17473Displays the current state of observer debugging.
8e04817f 17474@item set debug overload
4644b6e3 17475@cindex C@t{++} overload debugging info
8e04817f 17476Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 17477info. This includes info such as ranking of functions, etc. The default
8e04817f 17478is off.
8e04817f
AC
17479@item show debug overload
17480Displays the current state of displaying @value{GDBN} C@t{++} overload
17481debugging info.
8e04817f
AC
17482@cindex packets, reporting on stdout
17483@cindex serial connections, debugging
605a56cb
DJ
17484@cindex debug remote protocol
17485@cindex remote protocol debugging
17486@cindex display remote packets
8e04817f
AC
17487@item set debug remote
17488Turns on or off display of reports on all packets sent back and forth across
17489the serial line to the remote machine. The info is printed on the
17490@value{GDBN} standard output stream. The default is off.
8e04817f
AC
17491@item show debug remote
17492Displays the state of display of remote packets.
8e04817f
AC
17493@item set debug serial
17494Turns on or off display of @value{GDBN} serial debugging info. The
17495default is off.
8e04817f
AC
17496@item show debug serial
17497Displays the current state of displaying @value{GDBN} serial debugging
17498info.
c45da7e6
EZ
17499@item set debug solib-frv
17500@cindex FR-V shared-library debugging
17501Turns on or off debugging messages for FR-V shared-library code.
17502@item show debug solib-frv
17503Display the current state of FR-V shared-library code debugging
17504messages.
8e04817f 17505@item set debug target
4644b6e3 17506@cindex target debugging info
8e04817f
AC
17507Turns on or off display of @value{GDBN} target debugging info. This info
17508includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
17509default is 0. Set it to 1 to track events, and to 2 to also track the
17510value of large memory transfers. Changes to this flag do not take effect
17511until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
17512@item show debug target
17513Displays the current state of displaying @value{GDBN} target debugging
17514info.
75feb17d
DJ
17515@item set debug timestamp
17516@cindex timestampping debugging info
17517Turns on or off display of timestamps with @value{GDBN} debugging info.
17518When enabled, seconds and microseconds are displayed before each debugging
17519message.
17520@item show debug timestamp
17521Displays the current state of displaying timestamps with @value{GDBN}
17522debugging info.
c45da7e6 17523@item set debugvarobj
4644b6e3 17524@cindex variable object debugging info
8e04817f
AC
17525Turns on or off display of @value{GDBN} variable object debugging
17526info. The default is off.
c45da7e6 17527@item show debugvarobj
8e04817f
AC
17528Displays the current state of displaying @value{GDBN} variable object
17529debugging info.
e776119f
DJ
17530@item set debug xml
17531@cindex XML parser debugging
17532Turns on or off debugging messages for built-in XML parsers.
17533@item show debug xml
17534Displays the current state of XML debugging messages.
8e04817f 17535@end table
104c1213 17536
d57a3c85
TJB
17537@node Extending GDB
17538@chapter Extending @value{GDBN}
17539@cindex extending GDB
17540
17541@value{GDBN} provides two mechanisms for extension. The first is based
17542on composition of @value{GDBN} commands, and the second is based on the
17543Python scripting language.
17544
17545@menu
17546* Sequences:: Canned Sequences of Commands
17547* Python:: Scripting @value{GDBN} using Python
17548@end menu
17549
8e04817f 17550@node Sequences
d57a3c85 17551@section Canned Sequences of Commands
104c1213 17552
8e04817f 17553Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 17554Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
17555commands for execution as a unit: user-defined commands and command
17556files.
104c1213 17557
8e04817f 17558@menu
fcc73fe3
EZ
17559* Define:: How to define your own commands
17560* Hooks:: Hooks for user-defined commands
17561* Command Files:: How to write scripts of commands to be stored in a file
17562* Output:: Commands for controlled output
8e04817f 17563@end menu
104c1213 17564
8e04817f 17565@node Define
d57a3c85 17566@subsection User-defined Commands
104c1213 17567
8e04817f 17568@cindex user-defined command
fcc73fe3 17569@cindex arguments, to user-defined commands
8e04817f
AC
17570A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
17571which you assign a new name as a command. This is done with the
17572@code{define} command. User commands may accept up to 10 arguments
17573separated by whitespace. Arguments are accessed within the user command
c03c782f 17574via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 17575
8e04817f
AC
17576@smallexample
17577define adder
17578 print $arg0 + $arg1 + $arg2
c03c782f 17579end
8e04817f 17580@end smallexample
104c1213
JM
17581
17582@noindent
8e04817f 17583To execute the command use:
104c1213 17584
8e04817f
AC
17585@smallexample
17586adder 1 2 3
17587@end smallexample
104c1213 17588
8e04817f
AC
17589@noindent
17590This defines the command @code{adder}, which prints the sum of
17591its three arguments. Note the arguments are text substitutions, so they may
17592reference variables, use complex expressions, or even perform inferior
17593functions calls.
104c1213 17594
fcc73fe3
EZ
17595@cindex argument count in user-defined commands
17596@cindex how many arguments (user-defined commands)
c03c782f
AS
17597In addition, @code{$argc} may be used to find out how many arguments have
17598been passed. This expands to a number in the range 0@dots{}10.
17599
17600@smallexample
17601define adder
17602 if $argc == 2
17603 print $arg0 + $arg1
17604 end
17605 if $argc == 3
17606 print $arg0 + $arg1 + $arg2
17607 end
17608end
17609@end smallexample
17610
104c1213 17611@table @code
104c1213 17612
8e04817f
AC
17613@kindex define
17614@item define @var{commandname}
17615Define a command named @var{commandname}. If there is already a command
17616by that name, you are asked to confirm that you want to redefine it.
104c1213 17617
8e04817f
AC
17618The definition of the command is made up of other @value{GDBN} command lines,
17619which are given following the @code{define} command. The end of these
17620commands is marked by a line containing @code{end}.
104c1213 17621
8e04817f 17622@kindex document
ca91424e 17623@kindex end@r{ (user-defined commands)}
8e04817f
AC
17624@item document @var{commandname}
17625Document the user-defined command @var{commandname}, so that it can be
17626accessed by @code{help}. The command @var{commandname} must already be
17627defined. This command reads lines of documentation just as @code{define}
17628reads the lines of the command definition, ending with @code{end}.
17629After the @code{document} command is finished, @code{help} on command
17630@var{commandname} displays the documentation you have written.
104c1213 17631
8e04817f
AC
17632You may use the @code{document} command again to change the
17633documentation of a command. Redefining the command with @code{define}
17634does not change the documentation.
104c1213 17635
c45da7e6
EZ
17636@kindex dont-repeat
17637@cindex don't repeat command
17638@item dont-repeat
17639Used inside a user-defined command, this tells @value{GDBN} that this
17640command should not be repeated when the user hits @key{RET}
17641(@pxref{Command Syntax, repeat last command}).
17642
8e04817f
AC
17643@kindex help user-defined
17644@item help user-defined
17645List all user-defined commands, with the first line of the documentation
17646(if any) for each.
104c1213 17647
8e04817f
AC
17648@kindex show user
17649@item show user
17650@itemx show user @var{commandname}
17651Display the @value{GDBN} commands used to define @var{commandname} (but
17652not its documentation). If no @var{commandname} is given, display the
17653definitions for all user-defined commands.
104c1213 17654
fcc73fe3 17655@cindex infinite recursion in user-defined commands
20f01a46
DH
17656@kindex show max-user-call-depth
17657@kindex set max-user-call-depth
17658@item show max-user-call-depth
5ca0cb28
DH
17659@itemx set max-user-call-depth
17660The value of @code{max-user-call-depth} controls how many recursion
3f94c067 17661levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 17662infinite recursion and aborts the command.
104c1213
JM
17663@end table
17664
fcc73fe3
EZ
17665In addition to the above commands, user-defined commands frequently
17666use control flow commands, described in @ref{Command Files}.
17667
8e04817f
AC
17668When user-defined commands are executed, the
17669commands of the definition are not printed. An error in any command
17670stops execution of the user-defined command.
104c1213 17671
8e04817f
AC
17672If used interactively, commands that would ask for confirmation proceed
17673without asking when used inside a user-defined command. Many @value{GDBN}
17674commands that normally print messages to say what they are doing omit the
17675messages when used in a user-defined command.
104c1213 17676
8e04817f 17677@node Hooks
d57a3c85 17678@subsection User-defined Command Hooks
8e04817f
AC
17679@cindex command hooks
17680@cindex hooks, for commands
17681@cindex hooks, pre-command
104c1213 17682
8e04817f 17683@kindex hook
8e04817f
AC
17684You may define @dfn{hooks}, which are a special kind of user-defined
17685command. Whenever you run the command @samp{foo}, if the user-defined
17686command @samp{hook-foo} exists, it is executed (with no arguments)
17687before that command.
104c1213 17688
8e04817f
AC
17689@cindex hooks, post-command
17690@kindex hookpost
8e04817f
AC
17691A hook may also be defined which is run after the command you executed.
17692Whenever you run the command @samp{foo}, if the user-defined command
17693@samp{hookpost-foo} exists, it is executed (with no arguments) after
17694that command. Post-execution hooks may exist simultaneously with
17695pre-execution hooks, for the same command.
104c1213 17696
8e04817f 17697It is valid for a hook to call the command which it hooks. If this
9f1c6395 17698occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 17699
8e04817f
AC
17700@c It would be nice if hookpost could be passed a parameter indicating
17701@c if the command it hooks executed properly or not. FIXME!
104c1213 17702
8e04817f
AC
17703@kindex stop@r{, a pseudo-command}
17704In addition, a pseudo-command, @samp{stop} exists. Defining
17705(@samp{hook-stop}) makes the associated commands execute every time
17706execution stops in your program: before breakpoint commands are run,
17707displays are printed, or the stack frame is printed.
104c1213 17708
8e04817f
AC
17709For example, to ignore @code{SIGALRM} signals while
17710single-stepping, but treat them normally during normal execution,
17711you could define:
104c1213 17712
474c8240 17713@smallexample
8e04817f
AC
17714define hook-stop
17715handle SIGALRM nopass
17716end
104c1213 17717
8e04817f
AC
17718define hook-run
17719handle SIGALRM pass
17720end
104c1213 17721
8e04817f 17722define hook-continue
d3e8051b 17723handle SIGALRM pass
8e04817f 17724end
474c8240 17725@end smallexample
104c1213 17726
d3e8051b 17727As a further example, to hook at the beginning and end of the @code{echo}
b383017d 17728command, and to add extra text to the beginning and end of the message,
8e04817f 17729you could define:
104c1213 17730
474c8240 17731@smallexample
8e04817f
AC
17732define hook-echo
17733echo <<<---
17734end
104c1213 17735
8e04817f
AC
17736define hookpost-echo
17737echo --->>>\n
17738end
104c1213 17739
8e04817f
AC
17740(@value{GDBP}) echo Hello World
17741<<<---Hello World--->>>
17742(@value{GDBP})
104c1213 17743
474c8240 17744@end smallexample
104c1213 17745
8e04817f
AC
17746You can define a hook for any single-word command in @value{GDBN}, but
17747not for command aliases; you should define a hook for the basic command
c1468174 17748name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
17749@c FIXME! So how does Joe User discover whether a command is an alias
17750@c or not?
17751If an error occurs during the execution of your hook, execution of
17752@value{GDBN} commands stops and @value{GDBN} issues a prompt
17753(before the command that you actually typed had a chance to run).
104c1213 17754
8e04817f
AC
17755If you try to define a hook which does not match any known command, you
17756get a warning from the @code{define} command.
c906108c 17757
8e04817f 17758@node Command Files
d57a3c85 17759@subsection Command Files
c906108c 17760
8e04817f 17761@cindex command files
fcc73fe3 17762@cindex scripting commands
6fc08d32
EZ
17763A command file for @value{GDBN} is a text file made of lines that are
17764@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
17765also be included. An empty line in a command file does nothing; it
17766does not mean to repeat the last command, as it would from the
17767terminal.
c906108c 17768
6fc08d32
EZ
17769You can request the execution of a command file with the @code{source}
17770command:
c906108c 17771
8e04817f
AC
17772@table @code
17773@kindex source
ca91424e 17774@cindex execute commands from a file
16026cd7 17775@item source [@code{-v}] @var{filename}
8e04817f 17776Execute the command file @var{filename}.
c906108c
SS
17777@end table
17778
fcc73fe3
EZ
17779The lines in a command file are generally executed sequentially,
17780unless the order of execution is changed by one of the
17781@emph{flow-control commands} described below. The commands are not
a71ec265
DH
17782printed as they are executed. An error in any command terminates
17783execution of the command file and control is returned to the console.
c906108c 17784
4b505b12
AS
17785@value{GDBN} searches for @var{filename} in the current directory and then
17786on the search path (specified with the @samp{directory} command).
17787
16026cd7
AS
17788If @code{-v}, for verbose mode, is given then @value{GDBN} displays
17789each command as it is executed. The option must be given before
17790@var{filename}, and is interpreted as part of the filename anywhere else.
17791
8e04817f
AC
17792Commands that would ask for confirmation if used interactively proceed
17793without asking when used in a command file. Many @value{GDBN} commands that
17794normally print messages to say what they are doing omit the messages
17795when called from command files.
c906108c 17796
8e04817f
AC
17797@value{GDBN} also accepts command input from standard input. In this
17798mode, normal output goes to standard output and error output goes to
17799standard error. Errors in a command file supplied on standard input do
6fc08d32 17800not terminate execution of the command file---execution continues with
8e04817f 17801the next command.
c906108c 17802
474c8240 17803@smallexample
8e04817f 17804gdb < cmds > log 2>&1
474c8240 17805@end smallexample
c906108c 17806
8e04817f
AC
17807(The syntax above will vary depending on the shell used.) This example
17808will execute commands from the file @file{cmds}. All output and errors
17809would be directed to @file{log}.
c906108c 17810
fcc73fe3
EZ
17811Since commands stored on command files tend to be more general than
17812commands typed interactively, they frequently need to deal with
17813complicated situations, such as different or unexpected values of
17814variables and symbols, changes in how the program being debugged is
17815built, etc. @value{GDBN} provides a set of flow-control commands to
17816deal with these complexities. Using these commands, you can write
17817complex scripts that loop over data structures, execute commands
17818conditionally, etc.
17819
17820@table @code
17821@kindex if
17822@kindex else
17823@item if
17824@itemx else
17825This command allows to include in your script conditionally executed
17826commands. The @code{if} command takes a single argument, which is an
17827expression to evaluate. It is followed by a series of commands that
17828are executed only if the expression is true (its value is nonzero).
17829There can then optionally be an @code{else} line, followed by a series
17830of commands that are only executed if the expression was false. The
17831end of the list is marked by a line containing @code{end}.
17832
17833@kindex while
17834@item while
17835This command allows to write loops. Its syntax is similar to
17836@code{if}: the command takes a single argument, which is an expression
17837to evaluate, and must be followed by the commands to execute, one per
17838line, terminated by an @code{end}. These commands are called the
17839@dfn{body} of the loop. The commands in the body of @code{while} are
17840executed repeatedly as long as the expression evaluates to true.
17841
17842@kindex loop_break
17843@item loop_break
17844This command exits the @code{while} loop in whose body it is included.
17845Execution of the script continues after that @code{while}s @code{end}
17846line.
17847
17848@kindex loop_continue
17849@item loop_continue
17850This command skips the execution of the rest of the body of commands
17851in the @code{while} loop in whose body it is included. Execution
17852branches to the beginning of the @code{while} loop, where it evaluates
17853the controlling expression.
ca91424e
EZ
17854
17855@kindex end@r{ (if/else/while commands)}
17856@item end
17857Terminate the block of commands that are the body of @code{if},
17858@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
17859@end table
17860
17861
8e04817f 17862@node Output
d57a3c85 17863@subsection Commands for Controlled Output
c906108c 17864
8e04817f
AC
17865During the execution of a command file or a user-defined command, normal
17866@value{GDBN} output is suppressed; the only output that appears is what is
17867explicitly printed by the commands in the definition. This section
17868describes three commands useful for generating exactly the output you
17869want.
c906108c
SS
17870
17871@table @code
8e04817f
AC
17872@kindex echo
17873@item echo @var{text}
17874@c I do not consider backslash-space a standard C escape sequence
17875@c because it is not in ANSI.
17876Print @var{text}. Nonprinting characters can be included in
17877@var{text} using C escape sequences, such as @samp{\n} to print a
17878newline. @strong{No newline is printed unless you specify one.}
17879In addition to the standard C escape sequences, a backslash followed
17880by a space stands for a space. This is useful for displaying a
17881string with spaces at the beginning or the end, since leading and
17882trailing spaces are otherwise trimmed from all arguments.
17883To print @samp{@w{ }and foo =@w{ }}, use the command
17884@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 17885
8e04817f
AC
17886A backslash at the end of @var{text} can be used, as in C, to continue
17887the command onto subsequent lines. For example,
c906108c 17888
474c8240 17889@smallexample
8e04817f
AC
17890echo This is some text\n\
17891which is continued\n\
17892onto several lines.\n
474c8240 17893@end smallexample
c906108c 17894
8e04817f 17895produces the same output as
c906108c 17896
474c8240 17897@smallexample
8e04817f
AC
17898echo This is some text\n
17899echo which is continued\n
17900echo onto several lines.\n
474c8240 17901@end smallexample
c906108c 17902
8e04817f
AC
17903@kindex output
17904@item output @var{expression}
17905Print the value of @var{expression} and nothing but that value: no
17906newlines, no @samp{$@var{nn} = }. The value is not entered in the
17907value history either. @xref{Expressions, ,Expressions}, for more information
17908on expressions.
c906108c 17909
8e04817f
AC
17910@item output/@var{fmt} @var{expression}
17911Print the value of @var{expression} in format @var{fmt}. You can use
17912the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 17913Formats}, for more information.
c906108c 17914
8e04817f 17915@kindex printf
82160952
EZ
17916@item printf @var{template}, @var{expressions}@dots{}
17917Print the values of one or more @var{expressions} under the control of
17918the string @var{template}. To print several values, make
17919@var{expressions} be a comma-separated list of individual expressions,
17920which may be either numbers or pointers. Their values are printed as
17921specified by @var{template}, exactly as a C program would do by
17922executing the code below:
c906108c 17923
474c8240 17924@smallexample
82160952 17925printf (@var{template}, @var{expressions}@dots{});
474c8240 17926@end smallexample
c906108c 17927
82160952
EZ
17928As in @code{C} @code{printf}, ordinary characters in @var{template}
17929are printed verbatim, while @dfn{conversion specification} introduced
17930by the @samp{%} character cause subsequent @var{expressions} to be
17931evaluated, their values converted and formatted according to type and
17932style information encoded in the conversion specifications, and then
17933printed.
17934
8e04817f 17935For example, you can print two values in hex like this:
c906108c 17936
8e04817f
AC
17937@smallexample
17938printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
17939@end smallexample
c906108c 17940
82160952
EZ
17941@code{printf} supports all the standard @code{C} conversion
17942specifications, including the flags and modifiers between the @samp{%}
17943character and the conversion letter, with the following exceptions:
17944
17945@itemize @bullet
17946@item
17947The argument-ordering modifiers, such as @samp{2$}, are not supported.
17948
17949@item
17950The modifier @samp{*} is not supported for specifying precision or
17951width.
17952
17953@item
17954The @samp{'} flag (for separation of digits into groups according to
17955@code{LC_NUMERIC'}) is not supported.
17956
17957@item
17958The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
17959supported.
17960
17961@item
17962The conversion letter @samp{n} (as in @samp{%n}) is not supported.
17963
17964@item
17965The conversion letters @samp{a} and @samp{A} are not supported.
17966@end itemize
17967
17968@noindent
17969Note that the @samp{ll} type modifier is supported only if the
17970underlying @code{C} implementation used to build @value{GDBN} supports
17971the @code{long long int} type, and the @samp{L} type modifier is
17972supported only if @code{long double} type is available.
17973
17974As in @code{C}, @code{printf} supports simple backslash-escape
17975sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
17976@samp{\a}, and @samp{\f}, that consist of backslash followed by a
17977single character. Octal and hexadecimal escape sequences are not
17978supported.
1a619819
LM
17979
17980Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
17981(@dfn{Decimal Floating Point}) types using the following length modifiers
17982together with a floating point specifier.
1a619819
LM
17983letters:
17984
17985@itemize @bullet
17986@item
17987@samp{H} for printing @code{Decimal32} types.
17988
17989@item
17990@samp{D} for printing @code{Decimal64} types.
17991
17992@item
17993@samp{DD} for printing @code{Decimal128} types.
17994@end itemize
17995
17996If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 17997support for the three length modifiers for DFP types, other modifiers
3b784c4f 17998such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
17999
18000In case there is no such @code{C} support, no additional modifiers will be
18001available and the value will be printed in the standard way.
18002
18003Here's an example of printing DFP types using the above conversion letters:
18004@smallexample
0aea4bf3 18005printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
18006@end smallexample
18007
c906108c
SS
18008@end table
18009
d57a3c85
TJB
18010@node Python
18011@section Scripting @value{GDBN} using Python
18012@cindex python scripting
18013@cindex scripting with python
18014
18015You can script @value{GDBN} using the @uref{http://www.python.org/,
18016Python programming language}. This feature is available only if
18017@value{GDBN} was configured using @option{--with-python}.
18018
18019@menu
18020* Python Commands:: Accessing Python from @value{GDBN}.
18021* Python API:: Accessing @value{GDBN} from Python.
18022@end menu
18023
18024@node Python Commands
18025@subsection Python Commands
18026@cindex python commands
18027@cindex commands to access python
18028
18029@value{GDBN} provides one command for accessing the Python interpreter,
18030and one related setting:
18031
18032@table @code
18033@kindex python
18034@item python @r{[}@var{code}@r{]}
18035The @code{python} command can be used to evaluate Python code.
18036
18037If given an argument, the @code{python} command will evaluate the
18038argument as a Python command. For example:
18039
18040@smallexample
18041(@value{GDBP}) python print 23
1804223
18043@end smallexample
18044
18045If you do not provide an argument to @code{python}, it will act as a
18046multi-line command, like @code{define}. In this case, the Python
18047script is made up of subsequent command lines, given after the
18048@code{python} command. This command list is terminated using a line
18049containing @code{end}. For example:
18050
18051@smallexample
18052(@value{GDBP}) python
18053Type python script
18054End with a line saying just "end".
18055>print 23
18056>end
1805723
18058@end smallexample
18059
18060@kindex maint set python print-stack
18061@item maint set python print-stack
18062By default, @value{GDBN} will print a stack trace when an error occurs
18063in a Python script. This can be controlled using @code{maint set
18064python print-stack}: if @code{on}, the default, then Python stack
18065printing is enabled; if @code{off}, then Python stack printing is
18066disabled.
18067@end table
18068
18069@node Python API
18070@subsection Python API
18071@cindex python api
18072@cindex programming in python
18073
18074@cindex python stdout
18075@cindex python pagination
18076At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
18077@code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
18078A Python program which outputs to one of these streams may have its
18079output interrupted by the user (@pxref{Screen Size}). In this
18080situation, a Python @code{KeyboardInterrupt} exception is thrown.
18081
18082@menu
18083* Basic Python:: Basic Python Functions.
18084* Exception Handling::
a08702d6 18085* Values From Inferior::
d57a3c85
TJB
18086@end menu
18087
18088@node Basic Python
18089@subsubsection Basic Python
18090
18091@cindex python functions
18092@cindex python module
18093@cindex gdb module
18094@value{GDBN} introduces a new Python module, named @code{gdb}. All
18095methods and classes added by @value{GDBN} are placed in this module.
18096@value{GDBN} automatically @code{import}s the @code{gdb} module for
18097use in all scripts evaluated by the @code{python} command.
18098
18099@findex gdb.execute
18100@defun execute command
18101Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
18102If a GDB exception happens while @var{command} runs, it is
18103translated as described in @ref{Exception Handling,,Exception Handling}.
18104If no exceptions occur, this function returns @code{None}.
18105@end defun
18106
18107@findex gdb.get_parameter
18108@defun get_parameter parameter
18109Return the value of a @value{GDBN} parameter. @var{parameter} is a
18110string naming the parameter to look up; @var{parameter} may contain
18111spaces if the parameter has a multi-part name. For example,
18112@samp{print object} is a valid parameter name.
18113
18114If the named parameter does not exist, this function throws a
18115@code{RuntimeError}. Otherwise, the parameter's value is converted to
18116a Python value of the appropriate type, and returned.
18117@end defun
18118
18119@findex gdb.write
18120@defun write string
18121Print a string to @value{GDBN}'s paginated standard output stream.
18122Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
18123call this function.
18124@end defun
18125
18126@findex gdb.flush
18127@defun flush
18128Flush @value{GDBN}'s paginated standard output stream. Flushing
18129@code{sys.stdout} or @code{sys.stderr} will automatically call this
18130function.
18131@end defun
18132
18133@node Exception Handling
18134@subsubsection Exception Handling
18135@cindex python exceptions
18136@cindex exceptions, python
18137
18138When executing the @code{python} command, Python exceptions
18139uncaught within the Python code are translated to calls to
18140@value{GDBN} error-reporting mechanism. If the command that called
18141@code{python} does not handle the error, @value{GDBN} will
18142terminate it and print an error message containing the Python
18143exception name, the associated value, and the Python call stack
18144backtrace at the point where the exception was raised. Example:
18145
18146@smallexample
18147(@value{GDBP}) python print foo
18148Traceback (most recent call last):
18149 File "<string>", line 1, in <module>
18150NameError: name 'foo' is not defined
18151@end smallexample
18152
18153@value{GDBN} errors that happen in @value{GDBN} commands invoked by Python
18154code are converted to Python @code{RuntimeError} exceptions. User
18155interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
18156prompt) is translated to a Python @code{KeyboardInterrupt}
18157exception. If you catch these exceptions in your Python code, your
18158exception handler will see @code{RuntimeError} or
18159@code{KeyboardInterrupt} as the exception type, the @value{GDBN} error
18160message as its value, and the Python call stack backtrace at the
18161Python statement closest to where the @value{GDBN} error occured as the
18162traceback.
18163
a08702d6
TJB
18164@node Values From Inferior
18165@subsubsection Values From Inferior
18166@cindex values from inferior, with Python
18167@cindex python, working with values from inferior
18168
18169@cindex @code{gdb.Value}
18170@value{GDBN} provides values it obtains from the inferior program in
18171an object of type @code{gdb.Value}. @value{GDBN} uses this object
18172for its internal bookkeeping of the inferior's values, and for
18173fetching values when necessary.
18174
18175Inferior values that are simple scalars can be used directly in
18176Python expressions that are valid for the value's data type. Here's
18177an example for an integer or floating-point value @code{some_val}:
18178
18179@smallexample
18180bar = some_val + 2
18181@end smallexample
18182
18183@noindent
18184As result of this, @code{bar} will also be a @code{gdb.Value} object
18185whose values are of the same type as those of @code{some_val}.
18186
18187Inferior values that are structures or instances of some class can
18188be accessed using the Python @dfn{dictionary syntax}. For example, if
18189@code{some_val} is a @code{gdb.Value} instance holding a structure, you
18190can access its @code{foo} element with:
18191
18192@smallexample
18193bar = some_val['foo']
18194@end smallexample
18195
18196Again, @code{bar} will also be a @code{gdb.Value} object.
18197
18198For pointer data types, @code{gdb.Value} provides a method for
18199dereferencing the pointer to obtain the object it points to.
18200
18201@defmethod Value dereference
18202This method returns a new @code{gdb.Value} object whose contents is
18203the object pointed to by the pointer. For example, if @code{foo} is
18204a C pointer to an @code{int}, declared in your C program as
18205
18206@smallexample
18207int *foo;
18208@end smallexample
18209
18210@noindent
18211then you can use the corresponding @code{gdb.Value} to access what
18212@code{foo} points to like this:
18213
18214@smallexample
18215bar = foo.dereference ()
18216@end smallexample
18217
18218The result @code{bar} will be a @code{gdb.Value} object holding the
18219value pointed to by @code{foo}.
18220@end defmethod
18221
21c294e6
AC
18222@node Interpreters
18223@chapter Command Interpreters
18224@cindex command interpreters
18225
18226@value{GDBN} supports multiple command interpreters, and some command
18227infrastructure to allow users or user interface writers to switch
18228between interpreters or run commands in other interpreters.
18229
18230@value{GDBN} currently supports two command interpreters, the console
18231interpreter (sometimes called the command-line interpreter or @sc{cli})
18232and the machine interface interpreter (or @sc{gdb/mi}). This manual
18233describes both of these interfaces in great detail.
18234
18235By default, @value{GDBN} will start with the console interpreter.
18236However, the user may choose to start @value{GDBN} with another
18237interpreter by specifying the @option{-i} or @option{--interpreter}
18238startup options. Defined interpreters include:
18239
18240@table @code
18241@item console
18242@cindex console interpreter
18243The traditional console or command-line interpreter. This is the most often
18244used interpreter with @value{GDBN}. With no interpreter specified at runtime,
18245@value{GDBN} will use this interpreter.
18246
18247@item mi
18248@cindex mi interpreter
18249The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
18250by programs wishing to use @value{GDBN} as a backend for a debugger GUI
18251or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
18252Interface}.
18253
18254@item mi2
18255@cindex mi2 interpreter
18256The current @sc{gdb/mi} interface.
18257
18258@item mi1
18259@cindex mi1 interpreter
18260The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
18261
18262@end table
18263
18264@cindex invoke another interpreter
18265The interpreter being used by @value{GDBN} may not be dynamically
18266switched at runtime. Although possible, this could lead to a very
18267precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
18268enters the command "interpreter-set console" in a console view,
18269@value{GDBN} would switch to using the console interpreter, rendering
18270the IDE inoperable!
18271
18272@kindex interpreter-exec
18273Although you may only choose a single interpreter at startup, you may execute
18274commands in any interpreter from the current interpreter using the appropriate
18275command. If you are running the console interpreter, simply use the
18276@code{interpreter-exec} command:
18277
18278@smallexample
18279interpreter-exec mi "-data-list-register-names"
18280@end smallexample
18281
18282@sc{gdb/mi} has a similar command, although it is only available in versions of
18283@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
18284
8e04817f
AC
18285@node TUI
18286@chapter @value{GDBN} Text User Interface
18287@cindex TUI
d0d5df6f 18288@cindex Text User Interface
c906108c 18289
8e04817f
AC
18290@menu
18291* TUI Overview:: TUI overview
18292* TUI Keys:: TUI key bindings
7cf36c78 18293* TUI Single Key Mode:: TUI single key mode
db2e3e2e 18294* TUI Commands:: TUI-specific commands
8e04817f
AC
18295* TUI Configuration:: TUI configuration variables
18296@end menu
c906108c 18297
46ba6afa 18298The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
18299interface which uses the @code{curses} library to show the source
18300file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
18301commands in separate text windows. The TUI mode is supported only
18302on platforms where a suitable version of the @code{curses} library
18303is available.
d0d5df6f 18304
46ba6afa
BW
18305@pindex @value{GDBTUI}
18306The TUI mode is enabled by default when you invoke @value{GDBN} as
18307either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
18308You can also switch in and out of TUI mode while @value{GDBN} runs by
18309using various TUI commands and key bindings, such as @kbd{C-x C-a}.
18310@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 18311
8e04817f 18312@node TUI Overview
79a6e687 18313@section TUI Overview
c906108c 18314
46ba6afa 18315In TUI mode, @value{GDBN} can display several text windows:
c906108c 18316
8e04817f
AC
18317@table @emph
18318@item command
18319This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
18320prompt and the @value{GDBN} output. The @value{GDBN} input is still
18321managed using readline.
c906108c 18322
8e04817f
AC
18323@item source
18324The source window shows the source file of the program. The current
46ba6afa 18325line and active breakpoints are displayed in this window.
c906108c 18326
8e04817f
AC
18327@item assembly
18328The assembly window shows the disassembly output of the program.
c906108c 18329
8e04817f 18330@item register
46ba6afa
BW
18331This window shows the processor registers. Registers are highlighted
18332when their values change.
c906108c
SS
18333@end table
18334
269c21fe 18335The source and assembly windows show the current program position
46ba6afa
BW
18336by highlighting the current line and marking it with a @samp{>} marker.
18337Breakpoints are indicated with two markers. The first marker
269c21fe
SC
18338indicates the breakpoint type:
18339
18340@table @code
18341@item B
18342Breakpoint which was hit at least once.
18343
18344@item b
18345Breakpoint which was never hit.
18346
18347@item H
18348Hardware breakpoint which was hit at least once.
18349
18350@item h
18351Hardware breakpoint which was never hit.
269c21fe
SC
18352@end table
18353
18354The second marker indicates whether the breakpoint is enabled or not:
18355
18356@table @code
18357@item +
18358Breakpoint is enabled.
18359
18360@item -
18361Breakpoint is disabled.
269c21fe
SC
18362@end table
18363
46ba6afa
BW
18364The source, assembly and register windows are updated when the current
18365thread changes, when the frame changes, or when the program counter
18366changes.
18367
18368These windows are not all visible at the same time. The command
18369window is always visible. The others can be arranged in several
18370layouts:
c906108c 18371
8e04817f
AC
18372@itemize @bullet
18373@item
46ba6afa 18374source only,
2df3850c 18375
8e04817f 18376@item
46ba6afa 18377assembly only,
8e04817f
AC
18378
18379@item
46ba6afa 18380source and assembly,
8e04817f
AC
18381
18382@item
46ba6afa 18383source and registers, or
c906108c 18384
8e04817f 18385@item
46ba6afa 18386assembly and registers.
8e04817f 18387@end itemize
c906108c 18388
46ba6afa 18389A status line above the command window shows the following information:
b7bb15bc
SC
18390
18391@table @emph
18392@item target
46ba6afa 18393Indicates the current @value{GDBN} target.
b7bb15bc
SC
18394(@pxref{Targets, ,Specifying a Debugging Target}).
18395
18396@item process
46ba6afa 18397Gives the current process or thread number.
b7bb15bc
SC
18398When no process is being debugged, this field is set to @code{No process}.
18399
18400@item function
18401Gives the current function name for the selected frame.
18402The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 18403When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
18404the string @code{??} is displayed.
18405
18406@item line
18407Indicates the current line number for the selected frame.
46ba6afa 18408When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
18409
18410@item pc
18411Indicates the current program counter address.
b7bb15bc
SC
18412@end table
18413
8e04817f
AC
18414@node TUI Keys
18415@section TUI Key Bindings
18416@cindex TUI key bindings
c906108c 18417
8e04817f 18418The TUI installs several key bindings in the readline keymaps
46ba6afa 18419(@pxref{Command Line Editing}). The following key bindings
8e04817f 18420are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 18421
8e04817f
AC
18422@table @kbd
18423@kindex C-x C-a
18424@item C-x C-a
18425@kindex C-x a
18426@itemx C-x a
18427@kindex C-x A
18428@itemx C-x A
46ba6afa
BW
18429Enter or leave the TUI mode. When leaving the TUI mode,
18430the curses window management stops and @value{GDBN} operates using
18431its standard mode, writing on the terminal directly. When reentering
18432the TUI mode, control is given back to the curses windows.
8e04817f 18433The screen is then refreshed.
c906108c 18434
8e04817f
AC
18435@kindex C-x 1
18436@item C-x 1
18437Use a TUI layout with only one window. The layout will
18438either be @samp{source} or @samp{assembly}. When the TUI mode
18439is not active, it will switch to the TUI mode.
2df3850c 18440
8e04817f 18441Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 18442
8e04817f
AC
18443@kindex C-x 2
18444@item C-x 2
18445Use a TUI layout with at least two windows. When the current
46ba6afa 18446layout already has two windows, the next layout with two windows is used.
8e04817f
AC
18447When a new layout is chosen, one window will always be common to the
18448previous layout and the new one.
c906108c 18449
8e04817f 18450Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 18451
72ffddc9
SC
18452@kindex C-x o
18453@item C-x o
18454Change the active window. The TUI associates several key bindings
46ba6afa 18455(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
18456gives the focus to the next TUI window.
18457
18458Think of it as the Emacs @kbd{C-x o} binding.
18459
7cf36c78
SC
18460@kindex C-x s
18461@item C-x s
46ba6afa
BW
18462Switch in and out of the TUI SingleKey mode that binds single
18463keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
18464@end table
18465
46ba6afa 18466The following key bindings only work in the TUI mode:
5d161b24 18467
46ba6afa 18468@table @asis
8e04817f 18469@kindex PgUp
46ba6afa 18470@item @key{PgUp}
8e04817f 18471Scroll the active window one page up.
c906108c 18472
8e04817f 18473@kindex PgDn
46ba6afa 18474@item @key{PgDn}
8e04817f 18475Scroll the active window one page down.
c906108c 18476
8e04817f 18477@kindex Up
46ba6afa 18478@item @key{Up}
8e04817f 18479Scroll the active window one line up.
c906108c 18480
8e04817f 18481@kindex Down
46ba6afa 18482@item @key{Down}
8e04817f 18483Scroll the active window one line down.
c906108c 18484
8e04817f 18485@kindex Left
46ba6afa 18486@item @key{Left}
8e04817f 18487Scroll the active window one column left.
c906108c 18488
8e04817f 18489@kindex Right
46ba6afa 18490@item @key{Right}
8e04817f 18491Scroll the active window one column right.
c906108c 18492
8e04817f 18493@kindex C-L
46ba6afa 18494@item @kbd{C-L}
8e04817f 18495Refresh the screen.
8e04817f 18496@end table
c906108c 18497
46ba6afa
BW
18498Because the arrow keys scroll the active window in the TUI mode, they
18499are not available for their normal use by readline unless the command
18500window has the focus. When another window is active, you must use
18501other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
18502and @kbd{C-f} to control the command window.
8e04817f 18503
7cf36c78
SC
18504@node TUI Single Key Mode
18505@section TUI Single Key Mode
18506@cindex TUI single key mode
18507
46ba6afa
BW
18508The TUI also provides a @dfn{SingleKey} mode, which binds several
18509frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
18510switch into this mode, where the following key bindings are used:
7cf36c78
SC
18511
18512@table @kbd
18513@kindex c @r{(SingleKey TUI key)}
18514@item c
18515continue
18516
18517@kindex d @r{(SingleKey TUI key)}
18518@item d
18519down
18520
18521@kindex f @r{(SingleKey TUI key)}
18522@item f
18523finish
18524
18525@kindex n @r{(SingleKey TUI key)}
18526@item n
18527next
18528
18529@kindex q @r{(SingleKey TUI key)}
18530@item q
46ba6afa 18531exit the SingleKey mode.
7cf36c78
SC
18532
18533@kindex r @r{(SingleKey TUI key)}
18534@item r
18535run
18536
18537@kindex s @r{(SingleKey TUI key)}
18538@item s
18539step
18540
18541@kindex u @r{(SingleKey TUI key)}
18542@item u
18543up
18544
18545@kindex v @r{(SingleKey TUI key)}
18546@item v
18547info locals
18548
18549@kindex w @r{(SingleKey TUI key)}
18550@item w
18551where
7cf36c78
SC
18552@end table
18553
18554Other keys temporarily switch to the @value{GDBN} command prompt.
18555The key that was pressed is inserted in the editing buffer so that
18556it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
18557with the TUI SingleKey mode. Once the command is entered the TUI
18558SingleKey mode is restored. The only way to permanently leave
7f9087cb 18559this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
18560
18561
8e04817f 18562@node TUI Commands
db2e3e2e 18563@section TUI-specific Commands
8e04817f
AC
18564@cindex TUI commands
18565
18566The TUI has specific commands to control the text windows.
46ba6afa
BW
18567These commands are always available, even when @value{GDBN} is not in
18568the TUI mode. When @value{GDBN} is in the standard mode, most
18569of these commands will automatically switch to the TUI mode.
c906108c
SS
18570
18571@table @code
3d757584
SC
18572@item info win
18573@kindex info win
18574List and give the size of all displayed windows.
18575
8e04817f 18576@item layout next
4644b6e3 18577@kindex layout
8e04817f 18578Display the next layout.
2df3850c 18579
8e04817f 18580@item layout prev
8e04817f 18581Display the previous layout.
c906108c 18582
8e04817f 18583@item layout src
8e04817f 18584Display the source window only.
c906108c 18585
8e04817f 18586@item layout asm
8e04817f 18587Display the assembly window only.
c906108c 18588
8e04817f 18589@item layout split
8e04817f 18590Display the source and assembly window.
c906108c 18591
8e04817f 18592@item layout regs
8e04817f
AC
18593Display the register window together with the source or assembly window.
18594
46ba6afa 18595@item focus next
8e04817f 18596@kindex focus
46ba6afa
BW
18597Make the next window active for scrolling.
18598
18599@item focus prev
18600Make the previous window active for scrolling.
18601
18602@item focus src
18603Make the source window active for scrolling.
18604
18605@item focus asm
18606Make the assembly window active for scrolling.
18607
18608@item focus regs
18609Make the register window active for scrolling.
18610
18611@item focus cmd
18612Make the command window active for scrolling.
c906108c 18613
8e04817f
AC
18614@item refresh
18615@kindex refresh
7f9087cb 18616Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 18617
6a1b180d
SC
18618@item tui reg float
18619@kindex tui reg
18620Show the floating point registers in the register window.
18621
18622@item tui reg general
18623Show the general registers in the register window.
18624
18625@item tui reg next
18626Show the next register group. The list of register groups as well as
18627their order is target specific. The predefined register groups are the
18628following: @code{general}, @code{float}, @code{system}, @code{vector},
18629@code{all}, @code{save}, @code{restore}.
18630
18631@item tui reg system
18632Show the system registers in the register window.
18633
8e04817f
AC
18634@item update
18635@kindex update
18636Update the source window and the current execution point.
c906108c 18637
8e04817f
AC
18638@item winheight @var{name} +@var{count}
18639@itemx winheight @var{name} -@var{count}
18640@kindex winheight
18641Change the height of the window @var{name} by @var{count}
18642lines. Positive counts increase the height, while negative counts
18643decrease it.
2df3850c 18644
46ba6afa
BW
18645@item tabset @var{nchars}
18646@kindex tabset
c45da7e6 18647Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
18648@end table
18649
8e04817f 18650@node TUI Configuration
79a6e687 18651@section TUI Configuration Variables
8e04817f 18652@cindex TUI configuration variables
c906108c 18653
46ba6afa 18654Several configuration variables control the appearance of TUI windows.
c906108c 18655
8e04817f
AC
18656@table @code
18657@item set tui border-kind @var{kind}
18658@kindex set tui border-kind
18659Select the border appearance for the source, assembly and register windows.
18660The possible values are the following:
18661@table @code
18662@item space
18663Use a space character to draw the border.
c906108c 18664
8e04817f 18665@item ascii
46ba6afa 18666Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 18667
8e04817f
AC
18668@item acs
18669Use the Alternate Character Set to draw the border. The border is
18670drawn using character line graphics if the terminal supports them.
8e04817f 18671@end table
c78b4128 18672
8e04817f
AC
18673@item set tui border-mode @var{mode}
18674@kindex set tui border-mode
46ba6afa
BW
18675@itemx set tui active-border-mode @var{mode}
18676@kindex set tui active-border-mode
18677Select the display attributes for the borders of the inactive windows
18678or the active window. The @var{mode} can be one of the following:
8e04817f
AC
18679@table @code
18680@item normal
18681Use normal attributes to display the border.
c906108c 18682
8e04817f
AC
18683@item standout
18684Use standout mode.
c906108c 18685
8e04817f
AC
18686@item reverse
18687Use reverse video mode.
c906108c 18688
8e04817f
AC
18689@item half
18690Use half bright mode.
c906108c 18691
8e04817f
AC
18692@item half-standout
18693Use half bright and standout mode.
c906108c 18694
8e04817f
AC
18695@item bold
18696Use extra bright or bold mode.
c78b4128 18697
8e04817f
AC
18698@item bold-standout
18699Use extra bright or bold and standout mode.
8e04817f 18700@end table
8e04817f 18701@end table
c78b4128 18702
8e04817f
AC
18703@node Emacs
18704@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 18705
8e04817f
AC
18706@cindex Emacs
18707@cindex @sc{gnu} Emacs
18708A special interface allows you to use @sc{gnu} Emacs to view (and
18709edit) the source files for the program you are debugging with
18710@value{GDBN}.
c906108c 18711
8e04817f
AC
18712To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
18713executable file you want to debug as an argument. This command starts
18714@value{GDBN} as a subprocess of Emacs, with input and output through a newly
18715created Emacs buffer.
18716@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 18717
5e252a2e 18718Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 18719things:
c906108c 18720
8e04817f
AC
18721@itemize @bullet
18722@item
5e252a2e
NR
18723All ``terminal'' input and output goes through an Emacs buffer, called
18724the GUD buffer.
c906108c 18725
8e04817f
AC
18726This applies both to @value{GDBN} commands and their output, and to the input
18727and output done by the program you are debugging.
bf0184be 18728
8e04817f
AC
18729This is useful because it means that you can copy the text of previous
18730commands and input them again; you can even use parts of the output
18731in this way.
bf0184be 18732
8e04817f
AC
18733All the facilities of Emacs' Shell mode are available for interacting
18734with your program. In particular, you can send signals the usual
18735way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
18736stop.
bf0184be
ND
18737
18738@item
8e04817f 18739@value{GDBN} displays source code through Emacs.
bf0184be 18740
8e04817f
AC
18741Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
18742source file for that frame and puts an arrow (@samp{=>}) at the
18743left margin of the current line. Emacs uses a separate buffer for
18744source display, and splits the screen to show both your @value{GDBN} session
18745and the source.
bf0184be 18746
8e04817f
AC
18747Explicit @value{GDBN} @code{list} or search commands still produce output as
18748usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
18749@end itemize
18750
18751We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
18752a graphical mode, enabled by default, which provides further buffers
18753that can control the execution and describe the state of your program.
18754@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 18755
64fabec2
AC
18756If you specify an absolute file name when prompted for the @kbd{M-x
18757gdb} argument, then Emacs sets your current working directory to where
18758your program resides. If you only specify the file name, then Emacs
18759sets your current working directory to to the directory associated
18760with the previous buffer. In this case, @value{GDBN} may find your
18761program by searching your environment's @code{PATH} variable, but on
18762some operating systems it might not find the source. So, although the
18763@value{GDBN} input and output session proceeds normally, the auxiliary
18764buffer does not display the current source and line of execution.
18765
18766The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
18767line of the GUD buffer and this serves as a default for the commands
18768that specify files for @value{GDBN} to operate on. @xref{Files,
18769,Commands to Specify Files}.
64fabec2
AC
18770
18771By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
18772need to call @value{GDBN} by a different name (for example, if you
18773keep several configurations around, with different names) you can
18774customize the Emacs variable @code{gud-gdb-command-name} to run the
18775one you want.
8e04817f 18776
5e252a2e 18777In the GUD buffer, you can use these special Emacs commands in
8e04817f 18778addition to the standard Shell mode commands:
c906108c 18779
8e04817f
AC
18780@table @kbd
18781@item C-h m
5e252a2e 18782Describe the features of Emacs' GUD Mode.
c906108c 18783
64fabec2 18784@item C-c C-s
8e04817f
AC
18785Execute to another source line, like the @value{GDBN} @code{step} command; also
18786update the display window to show the current file and location.
c906108c 18787
64fabec2 18788@item C-c C-n
8e04817f
AC
18789Execute to next source line in this function, skipping all function
18790calls, like the @value{GDBN} @code{next} command. Then update the display window
18791to show the current file and location.
c906108c 18792
64fabec2 18793@item C-c C-i
8e04817f
AC
18794Execute one instruction, like the @value{GDBN} @code{stepi} command; update
18795display window accordingly.
c906108c 18796
8e04817f
AC
18797@item C-c C-f
18798Execute until exit from the selected stack frame, like the @value{GDBN}
18799@code{finish} command.
c906108c 18800
64fabec2 18801@item C-c C-r
8e04817f
AC
18802Continue execution of your program, like the @value{GDBN} @code{continue}
18803command.
b433d00b 18804
64fabec2 18805@item C-c <
8e04817f
AC
18806Go up the number of frames indicated by the numeric argument
18807(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
18808like the @value{GDBN} @code{up} command.
b433d00b 18809
64fabec2 18810@item C-c >
8e04817f
AC
18811Go down the number of frames indicated by the numeric argument, like the
18812@value{GDBN} @code{down} command.
8e04817f 18813@end table
c906108c 18814
7f9087cb 18815In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 18816tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 18817
5e252a2e
NR
18818In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
18819separate frame which shows a backtrace when the GUD buffer is current.
18820Move point to any frame in the stack and type @key{RET} to make it
18821become the current frame and display the associated source in the
18822source buffer. Alternatively, click @kbd{Mouse-2} to make the
18823selected frame become the current one. In graphical mode, the
18824speedbar displays watch expressions.
64fabec2 18825
8e04817f
AC
18826If you accidentally delete the source-display buffer, an easy way to get
18827it back is to type the command @code{f} in the @value{GDBN} buffer, to
18828request a frame display; when you run under Emacs, this recreates
18829the source buffer if necessary to show you the context of the current
18830frame.
c906108c 18831
8e04817f
AC
18832The source files displayed in Emacs are in ordinary Emacs buffers
18833which are visiting the source files in the usual way. You can edit
18834the files with these buffers if you wish; but keep in mind that @value{GDBN}
18835communicates with Emacs in terms of line numbers. If you add or
18836delete lines from the text, the line numbers that @value{GDBN} knows cease
18837to correspond properly with the code.
b383017d 18838
5e252a2e
NR
18839A more detailed description of Emacs' interaction with @value{GDBN} is
18840given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
18841Emacs Manual}).
c906108c 18842
8e04817f
AC
18843@c The following dropped because Epoch is nonstandard. Reactivate
18844@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
18845@ignore
18846@kindex Emacs Epoch environment
18847@kindex Epoch
18848@kindex inspect
c906108c 18849
8e04817f
AC
18850Version 18 of @sc{gnu} Emacs has a built-in window system
18851called the @code{epoch}
18852environment. Users of this environment can use a new command,
18853@code{inspect} which performs identically to @code{print} except that
18854each value is printed in its own window.
18855@end ignore
c906108c 18856
922fbb7b
AC
18857
18858@node GDB/MI
18859@chapter The @sc{gdb/mi} Interface
18860
18861@unnumberedsec Function and Purpose
18862
18863@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
18864@sc{gdb/mi} is a line based machine oriented text interface to
18865@value{GDBN} and is activated by specifying using the
18866@option{--interpreter} command line option (@pxref{Mode Options}). It
18867is specifically intended to support the development of systems which
18868use the debugger as just one small component of a larger system.
922fbb7b
AC
18869
18870This chapter is a specification of the @sc{gdb/mi} interface. It is written
18871in the form of a reference manual.
18872
18873Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
18874features described below are incomplete and subject to change
18875(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
18876
18877@unnumberedsec Notation and Terminology
18878
18879@cindex notational conventions, for @sc{gdb/mi}
18880This chapter uses the following notation:
18881
18882@itemize @bullet
18883@item
18884@code{|} separates two alternatives.
18885
18886@item
18887@code{[ @var{something} ]} indicates that @var{something} is optional:
18888it may or may not be given.
18889
18890@item
18891@code{( @var{group} )*} means that @var{group} inside the parentheses
18892may repeat zero or more times.
18893
18894@item
18895@code{( @var{group} )+} means that @var{group} inside the parentheses
18896may repeat one or more times.
18897
18898@item
18899@code{"@var{string}"} means a literal @var{string}.
18900@end itemize
18901
18902@ignore
18903@heading Dependencies
18904@end ignore
18905
922fbb7b 18906@menu
c3b108f7 18907* GDB/MI General Design::
922fbb7b
AC
18908* GDB/MI Command Syntax::
18909* GDB/MI Compatibility with CLI::
af6eff6f 18910* GDB/MI Development and Front Ends::
922fbb7b 18911* GDB/MI Output Records::
ef21caaf 18912* GDB/MI Simple Examples::
922fbb7b 18913* GDB/MI Command Description Format::
ef21caaf 18914* GDB/MI Breakpoint Commands::
a2c02241
NR
18915* GDB/MI Program Context::
18916* GDB/MI Thread Commands::
18917* GDB/MI Program Execution::
18918* GDB/MI Stack Manipulation::
18919* GDB/MI Variable Objects::
922fbb7b 18920* GDB/MI Data Manipulation::
a2c02241
NR
18921* GDB/MI Tracepoint Commands::
18922* GDB/MI Symbol Query::
351ff01a 18923* GDB/MI File Commands::
922fbb7b
AC
18924@ignore
18925* GDB/MI Kod Commands::
18926* GDB/MI Memory Overlay Commands::
18927* GDB/MI Signal Handling Commands::
18928@end ignore
922fbb7b 18929* GDB/MI Target Manipulation::
a6b151f1 18930* GDB/MI File Transfer Commands::
ef21caaf 18931* GDB/MI Miscellaneous Commands::
922fbb7b
AC
18932@end menu
18933
c3b108f7
VP
18934@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18935@node GDB/MI General Design
18936@section @sc{gdb/mi} General Design
18937@cindex GDB/MI General Design
18938
18939Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
18940parts---commands sent to @value{GDBN}, responses to those commands
18941and notifications. Each command results in exactly one response,
18942indicating either successful completion of the command, or an error.
18943For the commands that do not resume the target, the response contains the
18944requested information. For the commands that resume the target, the
18945response only indicates whether the target was successfully resumed.
18946Notifications is the mechanism for reporting changes in the state of the
18947target, or in @value{GDBN} state, that cannot conveniently be associated with
18948a command and reported as part of that command response.
18949
18950The important examples of notifications are:
18951@itemize @bullet
18952
18953@item
18954Exec notifications. These are used to report changes in
18955target state---when a target is resumed, or stopped. It would not
18956be feasible to include this information in response of resuming
18957commands, because one resume commands can result in multiple events in
18958different threads. Also, quite some time may pass before any event
18959happens in the target, while a frontend needs to know whether the resuming
18960command itself was successfully executed.
18961
18962@item
18963Console output, and status notifications. Console output
18964notifications are used to report output of CLI commands, as well as
18965diagnostics for other commands. Status notifications are used to
18966report the progress of a long-running operation. Naturally, including
18967this information in command response would mean no output is produced
18968until the command is finished, which is undesirable.
18969
18970@item
18971General notifications. Commands may have various side effects on
18972the @value{GDBN} or target state beyond their official purpose. For example,
18973a command may change the selected thread. Although such changes can
18974be included in command response, using notification allows for more
18975orthogonal frontend design.
18976
18977@end itemize
18978
18979There's no guarantee that whenever an MI command reports an error,
18980@value{GDBN} or the target are in any specific state, and especially,
18981the state is not reverted to the state before the MI command was
18982processed. Therefore, whenever an MI command results in an error,
18983we recommend that the frontend refreshes all the information shown in
18984the user interface.
18985
18986@subsection Context management
18987
18988In most cases when @value{GDBN} accesses the target, this access is
18989done in context of a specific thread and frame (@pxref{Frames}).
18990Often, even when accessing global data, the target requires that a thread
18991be specified. The CLI interface maintains the selected thread and frame,
18992and supplies them to target on each command. This is convenient,
18993because a command line user would not want to specify that information
18994explicitly on each command, and because user interacts with
18995@value{GDBN} via a single terminal, so no confusion is possible as
18996to what thread and frame are the current ones.
18997
18998In the case of MI, the concept of selected thread and frame is less
18999useful. First, a frontend can easily remember this information
19000itself. Second, a graphical frontend can have more than one window,
19001each one used for debugging a different thread, and the frontend might
19002want to access additional threads for internal purposes. This
19003increases the risk that by relying on implicitly selected thread, the
19004frontend may be operating on a wrong one. Therefore, each MI command
19005should explicitly specify which thread and frame to operate on. To
19006make it possible, each MI command accepts the @samp{--thread} and
19007@samp{--frame} options, the value to each is @value{GDBN} identifier
19008for thread and frame to operate on.
19009
19010Usually, each top-level window in a frontend allows the user to select
19011a thread and a frame, and remembers the user selection for further
19012operations. However, in some cases @value{GDBN} may suggest that the
19013current thread be changed. For example, when stopping on a breakpoint
19014it is reasonable to switch to the thread where breakpoint is hit. For
19015another example, if the user issues the CLI @samp{thread} command via
19016the frontend, it is desirable to change the frontend's selected thread to the
19017one specified by user. @value{GDBN} communicates the suggestion to
19018change current thread using the @samp{=thread-selected} notification.
19019No such notification is available for the selected frame at the moment.
19020
19021Note that historically, MI shares the selected thread with CLI, so
19022frontends used the @code{-thread-select} to execute commands in the
19023right context. However, getting this to work right is cumbersome. The
19024simplest way is for frontend to emit @code{-thread-select} command
19025before every command. This doubles the number of commands that need
19026to be sent. The alternative approach is to suppress @code{-thread-select}
19027if the selected thread in @value{GDBN} is supposed to be identical to the
19028thread the frontend wants to operate on. However, getting this
19029optimization right can be tricky. In particular, if the frontend
19030sends several commands to @value{GDBN}, and one of the commands changes the
19031selected thread, then the behaviour of subsequent commands will
19032change. So, a frontend should either wait for response from such
19033problematic commands, or explicitly add @code{-thread-select} for
19034all subsequent commands. No frontend is known to do this exactly
19035right, so it is suggested to just always pass the @samp{--thread} and
19036@samp{--frame} options.
19037
19038@subsection Asynchronous command execution and non-stop mode
19039
19040On some targets, @value{GDBN} is capable of processing MI commands
19041even while the target is running. This is called @dfn{asynchronous
19042command execution} (@pxref{Background Execution}). The frontend may
19043specify a preferrence for asynchronous execution using the
19044@code{-gdb-set target-async 1} command, which should be emitted before
19045either running the executable or attaching to the target. After the
19046frontend has started the executable or attached to the target, it can
19047find if asynchronous execution is enabled using the
19048@code{-list-target-features} command.
19049
19050Even if @value{GDBN} can accept a command while target is running,
19051many commands that access the target do not work when the target is
19052running. Therefore, asynchronous command execution is most useful
19053when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
19054it is possible to examine the state of one thread, while other threads
19055are running.
19056
19057When a given thread is running, MI commands that try to access the
19058target in the context of that thread may not work, or may work only on
19059some targets. In particular, commands that try to operate on thread's
19060stack will not work, on any target. Commands that read memory, or
19061modify breakpoints, may work or not work, depending on the target. Note
19062that even commands that operate on global state, such as @code{print},
19063@code{set}, and breakpoint commands, still access the target in the
19064context of a specific thread, so frontend should try to find a
19065stopped thread and perform the operation on that thread (using the
19066@samp{--thread} option).
19067
19068Which commands will work in the context of a running thread is
19069highly target dependent. However, the two commands
19070@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
19071to find the state of a thread, will always work.
19072
19073@subsection Thread groups
19074@value{GDBN} may be used to debug several processes at the same time.
19075On some platfroms, @value{GDBN} may support debugging of several
19076hardware systems, each one having several cores with several different
19077processes running on each core. This section describes the MI
19078mechanism to support such debugging scenarios.
19079
19080The key observation is that regardless of the structure of the
19081target, MI can have a global list of threads, because most commands that
19082accept the @samp{--thread} option do not need to know what process that
19083thread belongs to. Therefore, it is not necessary to introduce
19084neither additional @samp{--process} option, nor an notion of the
19085current process in the MI interface. The only strictly new feature
19086that is required is the ability to find how the threads are grouped
19087into processes.
19088
19089To allow the user to discover such grouping, and to support arbitrary
19090hierarchy of machines/cores/processes, MI introduces the concept of a
19091@dfn{thread group}. Thread group is a collection of threads and other
19092thread groups. A thread group always has a string identifier, a type,
19093and may have additional attributes specific to the type. A new
19094command, @code{-list-thread-groups}, returns the list of top-level
19095thread groups, which correspond to processes that @value{GDBN} is
19096debugging at the moment. By passing an identifier of a thread group
19097to the @code{-list-thread-groups} command, it is possible to obtain
19098the members of specific thread group.
19099
19100To allow the user to easily discover processes, and other objects, he
19101wishes to debug, a concept of @dfn{available thread group} is
19102introduced. Available thread group is an thread group that
19103@value{GDBN} is not debugging, but that can be attached to, using the
19104@code{-target-attach} command. The list of available top-level thread
19105groups can be obtained using @samp{-list-thread-groups --available}.
19106In general, the content of a thread group may be only retrieved only
19107after attaching to that thread group.
19108
922fbb7b
AC
19109@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19110@node GDB/MI Command Syntax
19111@section @sc{gdb/mi} Command Syntax
19112
19113@menu
19114* GDB/MI Input Syntax::
19115* GDB/MI Output Syntax::
922fbb7b
AC
19116@end menu
19117
19118@node GDB/MI Input Syntax
19119@subsection @sc{gdb/mi} Input Syntax
19120
19121@cindex input syntax for @sc{gdb/mi}
19122@cindex @sc{gdb/mi}, input syntax
19123@table @code
19124@item @var{command} @expansion{}
19125@code{@var{cli-command} | @var{mi-command}}
19126
19127@item @var{cli-command} @expansion{}
19128@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
19129@var{cli-command} is any existing @value{GDBN} CLI command.
19130
19131@item @var{mi-command} @expansion{}
19132@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
19133@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
19134
19135@item @var{token} @expansion{}
19136"any sequence of digits"
19137
19138@item @var{option} @expansion{}
19139@code{"-" @var{parameter} [ " " @var{parameter} ]}
19140
19141@item @var{parameter} @expansion{}
19142@code{@var{non-blank-sequence} | @var{c-string}}
19143
19144@item @var{operation} @expansion{}
19145@emph{any of the operations described in this chapter}
19146
19147@item @var{non-blank-sequence} @expansion{}
19148@emph{anything, provided it doesn't contain special characters such as
19149"-", @var{nl}, """ and of course " "}
19150
19151@item @var{c-string} @expansion{}
19152@code{""" @var{seven-bit-iso-c-string-content} """}
19153
19154@item @var{nl} @expansion{}
19155@code{CR | CR-LF}
19156@end table
19157
19158@noindent
19159Notes:
19160
19161@itemize @bullet
19162@item
19163The CLI commands are still handled by the @sc{mi} interpreter; their
19164output is described below.
19165
19166@item
19167The @code{@var{token}}, when present, is passed back when the command
19168finishes.
19169
19170@item
19171Some @sc{mi} commands accept optional arguments as part of the parameter
19172list. Each option is identified by a leading @samp{-} (dash) and may be
19173followed by an optional argument parameter. Options occur first in the
19174parameter list and can be delimited from normal parameters using
19175@samp{--} (this is useful when some parameters begin with a dash).
19176@end itemize
19177
19178Pragmatics:
19179
19180@itemize @bullet
19181@item
19182We want easy access to the existing CLI syntax (for debugging).
19183
19184@item
19185We want it to be easy to spot a @sc{mi} operation.
19186@end itemize
19187
19188@node GDB/MI Output Syntax
19189@subsection @sc{gdb/mi} Output Syntax
19190
19191@cindex output syntax of @sc{gdb/mi}
19192@cindex @sc{gdb/mi}, output syntax
19193The output from @sc{gdb/mi} consists of zero or more out-of-band records
19194followed, optionally, by a single result record. This result record
19195is for the most recent command. The sequence of output records is
594fe323 19196terminated by @samp{(gdb)}.
922fbb7b
AC
19197
19198If an input command was prefixed with a @code{@var{token}} then the
19199corresponding output for that command will also be prefixed by that same
19200@var{token}.
19201
19202@table @code
19203@item @var{output} @expansion{}
594fe323 19204@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
19205
19206@item @var{result-record} @expansion{}
19207@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
19208
19209@item @var{out-of-band-record} @expansion{}
19210@code{@var{async-record} | @var{stream-record}}
19211
19212@item @var{async-record} @expansion{}
19213@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
19214
19215@item @var{exec-async-output} @expansion{}
19216@code{[ @var{token} ] "*" @var{async-output}}
19217
19218@item @var{status-async-output} @expansion{}
19219@code{[ @var{token} ] "+" @var{async-output}}
19220
19221@item @var{notify-async-output} @expansion{}
19222@code{[ @var{token} ] "=" @var{async-output}}
19223
19224@item @var{async-output} @expansion{}
19225@code{@var{async-class} ( "," @var{result} )* @var{nl}}
19226
19227@item @var{result-class} @expansion{}
19228@code{"done" | "running" | "connected" | "error" | "exit"}
19229
19230@item @var{async-class} @expansion{}
19231@code{"stopped" | @var{others}} (where @var{others} will be added
19232depending on the needs---this is still in development).
19233
19234@item @var{result} @expansion{}
19235@code{ @var{variable} "=" @var{value}}
19236
19237@item @var{variable} @expansion{}
19238@code{ @var{string} }
19239
19240@item @var{value} @expansion{}
19241@code{ @var{const} | @var{tuple} | @var{list} }
19242
19243@item @var{const} @expansion{}
19244@code{@var{c-string}}
19245
19246@item @var{tuple} @expansion{}
19247@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
19248
19249@item @var{list} @expansion{}
19250@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
19251@var{result} ( "," @var{result} )* "]" }
19252
19253@item @var{stream-record} @expansion{}
19254@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
19255
19256@item @var{console-stream-output} @expansion{}
19257@code{"~" @var{c-string}}
19258
19259@item @var{target-stream-output} @expansion{}
19260@code{"@@" @var{c-string}}
19261
19262@item @var{log-stream-output} @expansion{}
19263@code{"&" @var{c-string}}
19264
19265@item @var{nl} @expansion{}
19266@code{CR | CR-LF}
19267
19268@item @var{token} @expansion{}
19269@emph{any sequence of digits}.
19270@end table
19271
19272@noindent
19273Notes:
19274
19275@itemize @bullet
19276@item
19277All output sequences end in a single line containing a period.
19278
19279@item
721c02de
VP
19280The @code{@var{token}} is from the corresponding request. Note that
19281for all async output, while the token is allowed by the grammar and
19282may be output by future versions of @value{GDBN} for select async
19283output messages, it is generally omitted. Frontends should treat
19284all async output as reporting general changes in the state of the
19285target and there should be no need to associate async output to any
19286prior command.
922fbb7b
AC
19287
19288@item
19289@cindex status output in @sc{gdb/mi}
19290@var{status-async-output} contains on-going status information about the
19291progress of a slow operation. It can be discarded. All status output is
19292prefixed by @samp{+}.
19293
19294@item
19295@cindex async output in @sc{gdb/mi}
19296@var{exec-async-output} contains asynchronous state change on the target
19297(stopped, started, disappeared). All async output is prefixed by
19298@samp{*}.
19299
19300@item
19301@cindex notify output in @sc{gdb/mi}
19302@var{notify-async-output} contains supplementary information that the
19303client should handle (e.g., a new breakpoint information). All notify
19304output is prefixed by @samp{=}.
19305
19306@item
19307@cindex console output in @sc{gdb/mi}
19308@var{console-stream-output} is output that should be displayed as is in the
19309console. It is the textual response to a CLI command. All the console
19310output is prefixed by @samp{~}.
19311
19312@item
19313@cindex target output in @sc{gdb/mi}
19314@var{target-stream-output} is the output produced by the target program.
19315All the target output is prefixed by @samp{@@}.
19316
19317@item
19318@cindex log output in @sc{gdb/mi}
19319@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
19320instance messages that should be displayed as part of an error log. All
19321the log output is prefixed by @samp{&}.
19322
19323@item
19324@cindex list output in @sc{gdb/mi}
19325New @sc{gdb/mi} commands should only output @var{lists} containing
19326@var{values}.
19327
19328
19329@end itemize
19330
19331@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
19332details about the various output records.
19333
922fbb7b
AC
19334@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19335@node GDB/MI Compatibility with CLI
19336@section @sc{gdb/mi} Compatibility with CLI
19337
19338@cindex compatibility, @sc{gdb/mi} and CLI
19339@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 19340
a2c02241
NR
19341For the developers convenience CLI commands can be entered directly,
19342but there may be some unexpected behaviour. For example, commands
19343that query the user will behave as if the user replied yes, breakpoint
19344command lists are not executed and some CLI commands, such as
19345@code{if}, @code{when} and @code{define}, prompt for further input with
19346@samp{>}, which is not valid MI output.
ef21caaf
NR
19347
19348This feature may be removed at some stage in the future and it is
a2c02241
NR
19349recommended that front ends use the @code{-interpreter-exec} command
19350(@pxref{-interpreter-exec}).
922fbb7b 19351
af6eff6f
NR
19352@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19353@node GDB/MI Development and Front Ends
19354@section @sc{gdb/mi} Development and Front Ends
19355@cindex @sc{gdb/mi} development
19356
19357The application which takes the MI output and presents the state of the
19358program being debugged to the user is called a @dfn{front end}.
19359
19360Although @sc{gdb/mi} is still incomplete, it is currently being used
19361by a variety of front ends to @value{GDBN}. This makes it difficult
19362to introduce new functionality without breaking existing usage. This
19363section tries to minimize the problems by describing how the protocol
19364might change.
19365
19366Some changes in MI need not break a carefully designed front end, and
19367for these the MI version will remain unchanged. The following is a
19368list of changes that may occur within one level, so front ends should
19369parse MI output in a way that can handle them:
19370
19371@itemize @bullet
19372@item
19373New MI commands may be added.
19374
19375@item
19376New fields may be added to the output of any MI command.
19377
36ece8b3
NR
19378@item
19379The range of values for fields with specified values, e.g.,
9f708cb2 19380@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 19381
af6eff6f
NR
19382@c The format of field's content e.g type prefix, may change so parse it
19383@c at your own risk. Yes, in general?
19384
19385@c The order of fields may change? Shouldn't really matter but it might
19386@c resolve inconsistencies.
19387@end itemize
19388
19389If the changes are likely to break front ends, the MI version level
19390will be increased by one. This will allow the front end to parse the
19391output according to the MI version. Apart from mi0, new versions of
19392@value{GDBN} will not support old versions of MI and it will be the
19393responsibility of the front end to work with the new one.
19394
19395@c Starting with mi3, add a new command -mi-version that prints the MI
19396@c version?
19397
19398The best way to avoid unexpected changes in MI that might break your front
19399end is to make your project known to @value{GDBN} developers and
7a9a6b69 19400follow development on @email{gdb@@sourceware.org} and
fa0f268d 19401@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
19402@cindex mailing lists
19403
922fbb7b
AC
19404@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19405@node GDB/MI Output Records
19406@section @sc{gdb/mi} Output Records
19407
19408@menu
19409* GDB/MI Result Records::
19410* GDB/MI Stream Records::
82f68b1c 19411* GDB/MI Async Records::
c3b108f7 19412* GDB/MI Frame Information::
922fbb7b
AC
19413@end menu
19414
19415@node GDB/MI Result Records
19416@subsection @sc{gdb/mi} Result Records
19417
19418@cindex result records in @sc{gdb/mi}
19419@cindex @sc{gdb/mi}, result records
19420In addition to a number of out-of-band notifications, the response to a
19421@sc{gdb/mi} command includes one of the following result indications:
19422
19423@table @code
19424@findex ^done
19425@item "^done" [ "," @var{results} ]
19426The synchronous operation was successful, @code{@var{results}} are the return
19427values.
19428
19429@item "^running"
19430@findex ^running
19431@c Is this one correct? Should it be an out-of-band notification?
19432The asynchronous operation was successfully started. The target is
19433running.
19434
ef21caaf
NR
19435@item "^connected"
19436@findex ^connected
3f94c067 19437@value{GDBN} has connected to a remote target.
ef21caaf 19438
922fbb7b
AC
19439@item "^error" "," @var{c-string}
19440@findex ^error
19441The operation failed. The @code{@var{c-string}} contains the corresponding
19442error message.
ef21caaf
NR
19443
19444@item "^exit"
19445@findex ^exit
3f94c067 19446@value{GDBN} has terminated.
ef21caaf 19447
922fbb7b
AC
19448@end table
19449
19450@node GDB/MI Stream Records
19451@subsection @sc{gdb/mi} Stream Records
19452
19453@cindex @sc{gdb/mi}, stream records
19454@cindex stream records in @sc{gdb/mi}
19455@value{GDBN} internally maintains a number of output streams: the console, the
19456target, and the log. The output intended for each of these streams is
19457funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
19458
19459Each stream record begins with a unique @dfn{prefix character} which
19460identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
19461Syntax}). In addition to the prefix, each stream record contains a
19462@code{@var{string-output}}. This is either raw text (with an implicit new
19463line) or a quoted C string (which does not contain an implicit newline).
19464
19465@table @code
19466@item "~" @var{string-output}
19467The console output stream contains text that should be displayed in the
19468CLI console window. It contains the textual responses to CLI commands.
19469
19470@item "@@" @var{string-output}
19471The target output stream contains any textual output from the running
ef21caaf
NR
19472target. This is only present when GDB's event loop is truly
19473asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
19474
19475@item "&" @var{string-output}
19476The log stream contains debugging messages being produced by @value{GDBN}'s
19477internals.
19478@end table
19479
82f68b1c
VP
19480@node GDB/MI Async Records
19481@subsection @sc{gdb/mi} Async Records
922fbb7b 19482
82f68b1c
VP
19483@cindex async records in @sc{gdb/mi}
19484@cindex @sc{gdb/mi}, async records
19485@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 19486additional changes that have occurred. Those changes can either be a
82f68b1c 19487consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
19488target activity (e.g., target stopped).
19489
8eb41542 19490The following is the list of possible async records:
922fbb7b
AC
19491
19492@table @code
034dad6f 19493
e1ac3328
VP
19494@item *running,thread-id="@var{thread}"
19495The target is now running. The @var{thread} field tells which
19496specific thread is now running, and can be @samp{all} if all threads
19497are running. The frontend should assume that no interaction with a
19498running thread is possible after this notification is produced.
19499The frontend should not assume that this notification is output
19500only once for any command. @value{GDBN} may emit this notification
19501several times, either for different threads, because it cannot resume
19502all threads together, or even for a single thread, if the thread must
19503be stepped though some code before letting it run freely.
19504
c3b108f7 19505@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}"
82f68b1c
VP
19506The target has stopped. The @var{reason} field can have one of the
19507following values:
034dad6f
BR
19508
19509@table @code
19510@item breakpoint-hit
19511A breakpoint was reached.
19512@item watchpoint-trigger
19513A watchpoint was triggered.
19514@item read-watchpoint-trigger
19515A read watchpoint was triggered.
19516@item access-watchpoint-trigger
19517An access watchpoint was triggered.
19518@item function-finished
19519An -exec-finish or similar CLI command was accomplished.
19520@item location-reached
19521An -exec-until or similar CLI command was accomplished.
19522@item watchpoint-scope
19523A watchpoint has gone out of scope.
19524@item end-stepping-range
19525An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
19526similar CLI command was accomplished.
19527@item exited-signalled
19528The inferior exited because of a signal.
19529@item exited
19530The inferior exited.
19531@item exited-normally
19532The inferior exited normally.
19533@item signal-received
19534A signal was received by the inferior.
922fbb7b
AC
19535@end table
19536
c3b108f7
VP
19537The @var{id} field identifies the thread that directly caused the stop
19538-- for example by hitting a breakpoint. Depending on whether all-stop
19539mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
19540stop all threads, or only the thread that directly triggered the stop.
19541If all threads are stopped, the @var{stopped} field will have the
19542value of @code{"all"}. Otherwise, the value of the @var{stopped}
19543field will be a list of thread identifiers. Presently, this list will
19544always include a single thread, but frontend should be prepared to see
19545several threads in the list.
19546
19547@item =thread-group-created,id="@var{id}"
19548@itemx =thread-group-exited,id="@var{id}"
19549A thread thread group either was attached to, or has exited/detached
19550from. The @var{id} field contains the @value{GDBN} identifier of the
19551thread group.
19552
19553@item =thread-created,id="@var{id}",group-id="@var{gid}"
19554@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 19555A thread either was created, or has exited. The @var{id} field
c3b108f7
VP
19556contains the @value{GDBN} identifier of the thread. The @var{gid}
19557field identifies the thread group this thread belongs to.
66bb093b
VP
19558
19559@item =thread-selected,id="@var{id}"
19560Informs that the selected thread was changed as result of the last
19561command. This notification is not emitted as result of @code{-thread-select}
19562command but is emitted whenever an MI command that is not documented
19563to change the selected thread actually changes it. In particular,
19564invoking, directly or indirectly (via user-defined command), the CLI
19565@code{thread} command, will generate this notification.
19566
19567We suggest that in response to this notification, front ends
19568highlight the selected thread and cause subsequent commands to apply to
19569that thread.
19570
82f68b1c
VP
19571@end table
19572
c3b108f7
VP
19573@node GDB/MI Frame Information
19574@subsection @sc{gdb/mi} Frame Information
19575
19576Response from many MI commands includes an information about stack
19577frame. This information is a tuple that may have the following
19578fields:
19579
19580@table @code
19581@item level
19582The level of the stack frame. The innermost frame has the level of
19583zero. This field is always present.
19584
19585@item func
19586The name of the function corresponding to the frame. This field may
19587be absent if @value{GDBN} is unable to determine the function name.
19588
19589@item addr
19590The code address for the frame. This field is always present.
19591
19592@item file
19593The name of the source files that correspond to the frame's code
19594address. This field may be absent.
19595
19596@item line
19597The source line corresponding to the frames' code address. This field
19598may be absent.
19599
19600@item from
19601The name of the binary file (either executable or shared library) the
19602corresponds to the frame's code address. This field may be absent.
19603
19604@end table
82f68b1c 19605
922fbb7b 19606
ef21caaf
NR
19607@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19608@node GDB/MI Simple Examples
19609@section Simple Examples of @sc{gdb/mi} Interaction
19610@cindex @sc{gdb/mi}, simple examples
19611
19612This subsection presents several simple examples of interaction using
19613the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
19614following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
19615the output received from @sc{gdb/mi}.
19616
d3e8051b 19617Note the line breaks shown in the examples are here only for
ef21caaf
NR
19618readability, they don't appear in the real output.
19619
79a6e687 19620@subheading Setting a Breakpoint
ef21caaf
NR
19621
19622Setting a breakpoint generates synchronous output which contains detailed
19623information of the breakpoint.
19624
19625@smallexample
19626-> -break-insert main
19627<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
19628 enabled="y",addr="0x08048564",func="main",file="myprog.c",
19629 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
19630<- (gdb)
19631@end smallexample
19632
19633@subheading Program Execution
19634
19635Program execution generates asynchronous records and MI gives the
19636reason that execution stopped.
19637
19638@smallexample
19639-> -exec-run
19640<- ^running
19641<- (gdb)
a47ec5fe 19642<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
19643 frame=@{addr="0x08048564",func="main",
19644 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
19645 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
19646<- (gdb)
19647-> -exec-continue
19648<- ^running
19649<- (gdb)
19650<- *stopped,reason="exited-normally"
19651<- (gdb)
19652@end smallexample
19653
3f94c067 19654@subheading Quitting @value{GDBN}
ef21caaf 19655
3f94c067 19656Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
19657
19658@smallexample
19659-> (gdb)
19660<- -gdb-exit
19661<- ^exit
19662@end smallexample
19663
a2c02241 19664@subheading A Bad Command
ef21caaf
NR
19665
19666Here's what happens if you pass a non-existent command:
19667
19668@smallexample
19669-> -rubbish
19670<- ^error,msg="Undefined MI command: rubbish"
594fe323 19671<- (gdb)
ef21caaf
NR
19672@end smallexample
19673
19674
922fbb7b
AC
19675@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19676@node GDB/MI Command Description Format
19677@section @sc{gdb/mi} Command Description Format
19678
19679The remaining sections describe blocks of commands. Each block of
19680commands is laid out in a fashion similar to this section.
19681
922fbb7b
AC
19682@subheading Motivation
19683
19684The motivation for this collection of commands.
19685
19686@subheading Introduction
19687
19688A brief introduction to this collection of commands as a whole.
19689
19690@subheading Commands
19691
19692For each command in the block, the following is described:
19693
19694@subsubheading Synopsis
19695
19696@smallexample
19697 -command @var{args}@dots{}
19698@end smallexample
19699
922fbb7b
AC
19700@subsubheading Result
19701
265eeb58 19702@subsubheading @value{GDBN} Command
922fbb7b 19703
265eeb58 19704The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
19705
19706@subsubheading Example
19707
ef21caaf
NR
19708Example(s) formatted for readability. Some of the described commands have
19709not been implemented yet and these are labeled N.A.@: (not available).
19710
19711
922fbb7b 19712@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
19713@node GDB/MI Breakpoint Commands
19714@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
19715
19716@cindex breakpoint commands for @sc{gdb/mi}
19717@cindex @sc{gdb/mi}, breakpoint commands
19718This section documents @sc{gdb/mi} commands for manipulating
19719breakpoints.
19720
19721@subheading The @code{-break-after} Command
19722@findex -break-after
19723
19724@subsubheading Synopsis
19725
19726@smallexample
19727 -break-after @var{number} @var{count}
19728@end smallexample
19729
19730The breakpoint number @var{number} is not in effect until it has been
19731hit @var{count} times. To see how this is reflected in the output of
19732the @samp{-break-list} command, see the description of the
19733@samp{-break-list} command below.
19734
19735@subsubheading @value{GDBN} Command
19736
19737The corresponding @value{GDBN} command is @samp{ignore}.
19738
19739@subsubheading Example
19740
19741@smallexample
594fe323 19742(gdb)
922fbb7b 19743-break-insert main
a47ec5fe
AR
19744^done,bkpt=@{number="1",type="breakpoint",disp="keep",
19745enabled="y",addr="0x000100d0",func="main",file="hello.c",
948d5102 19746fullname="/home/foo/hello.c",line="5",times="0"@}
594fe323 19747(gdb)
922fbb7b
AC
19748-break-after 1 3
19749~
19750^done
594fe323 19751(gdb)
922fbb7b
AC
19752-break-list
19753^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19754hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19755@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19756@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19757@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19758@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19759@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19760body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
19761addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19762line="5",times="0",ignore="3"@}]@}
594fe323 19763(gdb)
922fbb7b
AC
19764@end smallexample
19765
19766@ignore
19767@subheading The @code{-break-catch} Command
19768@findex -break-catch
19769
19770@subheading The @code{-break-commands} Command
19771@findex -break-commands
19772@end ignore
19773
19774
19775@subheading The @code{-break-condition} Command
19776@findex -break-condition
19777
19778@subsubheading Synopsis
19779
19780@smallexample
19781 -break-condition @var{number} @var{expr}
19782@end smallexample
19783
19784Breakpoint @var{number} will stop the program only if the condition in
19785@var{expr} is true. The condition becomes part of the
19786@samp{-break-list} output (see the description of the @samp{-break-list}
19787command below).
19788
19789@subsubheading @value{GDBN} Command
19790
19791The corresponding @value{GDBN} command is @samp{condition}.
19792
19793@subsubheading Example
19794
19795@smallexample
594fe323 19796(gdb)
922fbb7b
AC
19797-break-condition 1 1
19798^done
594fe323 19799(gdb)
922fbb7b
AC
19800-break-list
19801^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19802hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19803@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19804@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19805@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19806@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19807@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19808body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
19809addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19810line="5",cond="1",times="0",ignore="3"@}]@}
594fe323 19811(gdb)
922fbb7b
AC
19812@end smallexample
19813
19814@subheading The @code{-break-delete} Command
19815@findex -break-delete
19816
19817@subsubheading Synopsis
19818
19819@smallexample
19820 -break-delete ( @var{breakpoint} )+
19821@end smallexample
19822
19823Delete the breakpoint(s) whose number(s) are specified in the argument
19824list. This is obviously reflected in the breakpoint list.
19825
79a6e687 19826@subsubheading @value{GDBN} Command
922fbb7b
AC
19827
19828The corresponding @value{GDBN} command is @samp{delete}.
19829
19830@subsubheading Example
19831
19832@smallexample
594fe323 19833(gdb)
922fbb7b
AC
19834-break-delete 1
19835^done
594fe323 19836(gdb)
922fbb7b
AC
19837-break-list
19838^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
19839hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19840@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19841@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19842@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19843@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19844@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19845body=[]@}
594fe323 19846(gdb)
922fbb7b
AC
19847@end smallexample
19848
19849@subheading The @code{-break-disable} Command
19850@findex -break-disable
19851
19852@subsubheading Synopsis
19853
19854@smallexample
19855 -break-disable ( @var{breakpoint} )+
19856@end smallexample
19857
19858Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
19859break list is now set to @samp{n} for the named @var{breakpoint}(s).
19860
19861@subsubheading @value{GDBN} Command
19862
19863The corresponding @value{GDBN} command is @samp{disable}.
19864
19865@subsubheading Example
19866
19867@smallexample
594fe323 19868(gdb)
922fbb7b
AC
19869-break-disable 2
19870^done
594fe323 19871(gdb)
922fbb7b
AC
19872-break-list
19873^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19874hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19875@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19876@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19877@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19878@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19879@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19880body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102
NR
19881addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19882line="5",times="0"@}]@}
594fe323 19883(gdb)
922fbb7b
AC
19884@end smallexample
19885
19886@subheading The @code{-break-enable} Command
19887@findex -break-enable
19888
19889@subsubheading Synopsis
19890
19891@smallexample
19892 -break-enable ( @var{breakpoint} )+
19893@end smallexample
19894
19895Enable (previously disabled) @var{breakpoint}(s).
19896
19897@subsubheading @value{GDBN} Command
19898
19899The corresponding @value{GDBN} command is @samp{enable}.
19900
19901@subsubheading Example
19902
19903@smallexample
594fe323 19904(gdb)
922fbb7b
AC
19905-break-enable 2
19906^done
594fe323 19907(gdb)
922fbb7b
AC
19908-break-list
19909^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
19910hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
19911@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
19912@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
19913@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
19914@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
19915@{width="40",alignment="2",col_name="what",colhdr="What"@}],
19916body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
19917addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
19918line="5",times="0"@}]@}
594fe323 19919(gdb)
922fbb7b
AC
19920@end smallexample
19921
19922@subheading The @code{-break-info} Command
19923@findex -break-info
19924
19925@subsubheading Synopsis
19926
19927@smallexample
19928 -break-info @var{breakpoint}
19929@end smallexample
19930
19931@c REDUNDANT???
19932Get information about a single breakpoint.
19933
79a6e687 19934@subsubheading @value{GDBN} Command
922fbb7b
AC
19935
19936The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
19937
19938@subsubheading Example
19939N.A.
19940
19941@subheading The @code{-break-insert} Command
19942@findex -break-insert
19943
19944@subsubheading Synopsis
19945
19946@smallexample
afe8ab22 19947 -break-insert [ -t ] [ -h ] [ -f ]
922fbb7b 19948 [ -c @var{condition} ] [ -i @var{ignore-count} ]
afe8ab22 19949 [ -p @var{thread} ] [ @var{location} ]
922fbb7b
AC
19950@end smallexample
19951
19952@noindent
afe8ab22 19953If specified, @var{location}, can be one of:
922fbb7b
AC
19954
19955@itemize @bullet
19956@item function
19957@c @item +offset
19958@c @item -offset
19959@c @item linenum
19960@item filename:linenum
19961@item filename:function
19962@item *address
19963@end itemize
19964
19965The possible optional parameters of this command are:
19966
19967@table @samp
19968@item -t
948d5102 19969Insert a temporary breakpoint.
922fbb7b
AC
19970@item -h
19971Insert a hardware breakpoint.
19972@item -c @var{condition}
19973Make the breakpoint conditional on @var{condition}.
19974@item -i @var{ignore-count}
19975Initialize the @var{ignore-count}.
afe8ab22
VP
19976@item -f
19977If @var{location} cannot be parsed (for example if it
19978refers to unknown files or functions), create a pending
19979breakpoint. Without this flag, @value{GDBN} will report
19980an error, and won't create a breakpoint, if @var{location}
19981cannot be parsed.
922fbb7b
AC
19982@end table
19983
19984@subsubheading Result
19985
19986The result is in the form:
19987
19988@smallexample
948d5102
NR
19989^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
19990enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
ef21caaf
NR
19991fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
19992times="@var{times}"@}
922fbb7b
AC
19993@end smallexample
19994
19995@noindent
948d5102
NR
19996where @var{number} is the @value{GDBN} number for this breakpoint,
19997@var{funcname} is the name of the function where the breakpoint was
19998inserted, @var{filename} is the name of the source file which contains
19999this function, @var{lineno} is the source line number within that file
20000and @var{times} the number of times that the breakpoint has been hit
20001(always 0 for -break-insert but may be greater for -break-info or -break-list
20002which use the same output).
922fbb7b
AC
20003
20004Note: this format is open to change.
20005@c An out-of-band breakpoint instead of part of the result?
20006
20007@subsubheading @value{GDBN} Command
20008
20009The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
20010@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
20011
20012@subsubheading Example
20013
20014@smallexample
594fe323 20015(gdb)
922fbb7b 20016-break-insert main
948d5102
NR
20017^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
20018fullname="/home/foo/recursive2.c,line="4",times="0"@}
594fe323 20019(gdb)
922fbb7b 20020-break-insert -t foo
948d5102
NR
20021^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
20022fullname="/home/foo/recursive2.c,line="11",times="0"@}
594fe323 20023(gdb)
922fbb7b
AC
20024-break-list
20025^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
20026hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20027@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20028@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20029@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20030@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20031@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20032body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
20033addr="0x0001072c", func="main",file="recursive2.c",
20034fullname="/home/foo/recursive2.c,"line="4",times="0"@},
922fbb7b 20035bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102
NR
20036addr="0x00010774",func="foo",file="recursive2.c",
20037fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
594fe323 20038(gdb)
922fbb7b
AC
20039-break-insert -r foo.*
20040~int foo(int, int);
948d5102
NR
20041^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
20042"fullname="/home/foo/recursive2.c",line="11",times="0"@}
594fe323 20043(gdb)
922fbb7b
AC
20044@end smallexample
20045
20046@subheading The @code{-break-list} Command
20047@findex -break-list
20048
20049@subsubheading Synopsis
20050
20051@smallexample
20052 -break-list
20053@end smallexample
20054
20055Displays the list of inserted breakpoints, showing the following fields:
20056
20057@table @samp
20058@item Number
20059number of the breakpoint
20060@item Type
20061type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
20062@item Disposition
20063should the breakpoint be deleted or disabled when it is hit: @samp{keep}
20064or @samp{nokeep}
20065@item Enabled
20066is the breakpoint enabled or no: @samp{y} or @samp{n}
20067@item Address
20068memory location at which the breakpoint is set
20069@item What
20070logical location of the breakpoint, expressed by function name, file
20071name, line number
20072@item Times
20073number of times the breakpoint has been hit
20074@end table
20075
20076If there are no breakpoints or watchpoints, the @code{BreakpointTable}
20077@code{body} field is an empty list.
20078
20079@subsubheading @value{GDBN} Command
20080
20081The corresponding @value{GDBN} command is @samp{info break}.
20082
20083@subsubheading Example
20084
20085@smallexample
594fe323 20086(gdb)
922fbb7b
AC
20087-break-list
20088^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
20089hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20090@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20091@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20092@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20093@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20094@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20095body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20096addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
20097bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
20098addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
20099line="13",times="0"@}]@}
594fe323 20100(gdb)
922fbb7b
AC
20101@end smallexample
20102
20103Here's an example of the result when there are no breakpoints:
20104
20105@smallexample
594fe323 20106(gdb)
922fbb7b
AC
20107-break-list
20108^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
20109hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20110@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20111@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20112@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20113@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20114@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20115body=[]@}
594fe323 20116(gdb)
922fbb7b
AC
20117@end smallexample
20118
20119@subheading The @code{-break-watch} Command
20120@findex -break-watch
20121
20122@subsubheading Synopsis
20123
20124@smallexample
20125 -break-watch [ -a | -r ]
20126@end smallexample
20127
20128Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 20129@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 20130read from or on a write to the memory location. With the @samp{-r}
d3e8051b 20131option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
20132trigger only when the memory location is accessed for reading. Without
20133either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 20134i.e., it will trigger when the memory location is accessed for writing.
79a6e687 20135@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
20136
20137Note that @samp{-break-list} will report a single list of watchpoints and
20138breakpoints inserted.
20139
20140@subsubheading @value{GDBN} Command
20141
20142The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
20143@samp{rwatch}.
20144
20145@subsubheading Example
20146
20147Setting a watchpoint on a variable in the @code{main} function:
20148
20149@smallexample
594fe323 20150(gdb)
922fbb7b
AC
20151-break-watch x
20152^done,wpt=@{number="2",exp="x"@}
594fe323 20153(gdb)
922fbb7b
AC
20154-exec-continue
20155^running
0869d01b
NR
20156(gdb)
20157*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 20158value=@{old="-268439212",new="55"@},
76ff342d 20159frame=@{func="main",args=[],file="recursive2.c",
948d5102 20160fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 20161(gdb)
922fbb7b
AC
20162@end smallexample
20163
20164Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
20165the program execution twice: first for the variable changing value, then
20166for the watchpoint going out of scope.
20167
20168@smallexample
594fe323 20169(gdb)
922fbb7b
AC
20170-break-watch C
20171^done,wpt=@{number="5",exp="C"@}
594fe323 20172(gdb)
922fbb7b
AC
20173-exec-continue
20174^running
0869d01b
NR
20175(gdb)
20176*stopped,reason="watchpoint-trigger",
922fbb7b
AC
20177wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
20178frame=@{func="callee4",args=[],
76ff342d
DJ
20179file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20180fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 20181(gdb)
922fbb7b
AC
20182-exec-continue
20183^running
0869d01b
NR
20184(gdb)
20185*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
20186frame=@{func="callee3",args=[@{name="strarg",
20187value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
20188file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20189fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 20190(gdb)
922fbb7b
AC
20191@end smallexample
20192
20193Listing breakpoints and watchpoints, at different points in the program
20194execution. Note that once the watchpoint goes out of scope, it is
20195deleted.
20196
20197@smallexample
594fe323 20198(gdb)
922fbb7b
AC
20199-break-watch C
20200^done,wpt=@{number="2",exp="C"@}
594fe323 20201(gdb)
922fbb7b
AC
20202-break-list
20203^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
20204hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20205@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20206@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20207@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20208@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20209@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20210body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20211addr="0x00010734",func="callee4",
948d5102
NR
20212file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20213fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
922fbb7b
AC
20214bkpt=@{number="2",type="watchpoint",disp="keep",
20215enabled="y",addr="",what="C",times="0"@}]@}
594fe323 20216(gdb)
922fbb7b
AC
20217-exec-continue
20218^running
0869d01b
NR
20219(gdb)
20220*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
20221value=@{old="-276895068",new="3"@},
20222frame=@{func="callee4",args=[],
76ff342d
DJ
20223file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20224fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 20225(gdb)
922fbb7b
AC
20226-break-list
20227^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
20228hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20229@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20230@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20231@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20232@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20233@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20234body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20235addr="0x00010734",func="callee4",
948d5102
NR
20236file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20237fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
922fbb7b
AC
20238bkpt=@{number="2",type="watchpoint",disp="keep",
20239enabled="y",addr="",what="C",times="-5"@}]@}
594fe323 20240(gdb)
922fbb7b
AC
20241-exec-continue
20242^running
20243^done,reason="watchpoint-scope",wpnum="2",
20244frame=@{func="callee3",args=[@{name="strarg",
20245value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
20246file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20247fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 20248(gdb)
922fbb7b
AC
20249-break-list
20250^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
20251hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
20252@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
20253@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
20254@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
20255@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
20256@{width="40",alignment="2",col_name="what",colhdr="What"@}],
20257body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
20258addr="0x00010734",func="callee4",
948d5102
NR
20259file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20260fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
20261times="1"@}]@}
594fe323 20262(gdb)
922fbb7b
AC
20263@end smallexample
20264
20265@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
20266@node GDB/MI Program Context
20267@section @sc{gdb/mi} Program Context
922fbb7b 20268
a2c02241
NR
20269@subheading The @code{-exec-arguments} Command
20270@findex -exec-arguments
922fbb7b 20271
922fbb7b
AC
20272
20273@subsubheading Synopsis
20274
20275@smallexample
a2c02241 20276 -exec-arguments @var{args}
922fbb7b
AC
20277@end smallexample
20278
a2c02241
NR
20279Set the inferior program arguments, to be used in the next
20280@samp{-exec-run}.
922fbb7b 20281
a2c02241 20282@subsubheading @value{GDBN} Command
922fbb7b 20283
a2c02241 20284The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 20285
a2c02241 20286@subsubheading Example
922fbb7b 20287
fbc5282e
MK
20288@smallexample
20289(gdb)
20290-exec-arguments -v word
20291^done
20292(gdb)
20293@end smallexample
922fbb7b 20294
a2c02241
NR
20295
20296@subheading The @code{-exec-show-arguments} Command
20297@findex -exec-show-arguments
20298
20299@subsubheading Synopsis
20300
20301@smallexample
20302 -exec-show-arguments
20303@end smallexample
20304
20305Print the arguments of the program.
922fbb7b
AC
20306
20307@subsubheading @value{GDBN} Command
20308
a2c02241 20309The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
20310
20311@subsubheading Example
a2c02241 20312N.A.
922fbb7b 20313
922fbb7b 20314
a2c02241
NR
20315@subheading The @code{-environment-cd} Command
20316@findex -environment-cd
922fbb7b 20317
a2c02241 20318@subsubheading Synopsis
922fbb7b
AC
20319
20320@smallexample
a2c02241 20321 -environment-cd @var{pathdir}
922fbb7b
AC
20322@end smallexample
20323
a2c02241 20324Set @value{GDBN}'s working directory.
922fbb7b 20325
a2c02241 20326@subsubheading @value{GDBN} Command
922fbb7b 20327
a2c02241
NR
20328The corresponding @value{GDBN} command is @samp{cd}.
20329
20330@subsubheading Example
922fbb7b
AC
20331
20332@smallexample
594fe323 20333(gdb)
a2c02241
NR
20334-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
20335^done
594fe323 20336(gdb)
922fbb7b
AC
20337@end smallexample
20338
20339
a2c02241
NR
20340@subheading The @code{-environment-directory} Command
20341@findex -environment-directory
922fbb7b
AC
20342
20343@subsubheading Synopsis
20344
20345@smallexample
a2c02241 20346 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
20347@end smallexample
20348
a2c02241
NR
20349Add directories @var{pathdir} to beginning of search path for source files.
20350If the @samp{-r} option is used, the search path is reset to the default
20351search path. If directories @var{pathdir} are supplied in addition to the
20352@samp{-r} option, the search path is first reset and then addition
20353occurs as normal.
20354Multiple directories may be specified, separated by blanks. Specifying
20355multiple directories in a single command
20356results in the directories added to the beginning of the
20357search path in the same order they were presented in the command.
20358If blanks are needed as
20359part of a directory name, double-quotes should be used around
20360the name. In the command output, the path will show up separated
d3e8051b 20361by the system directory-separator character. The directory-separator
a2c02241
NR
20362character must not be used
20363in any directory name.
20364If no directories are specified, the current search path is displayed.
922fbb7b
AC
20365
20366@subsubheading @value{GDBN} Command
20367
a2c02241 20368The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
20369
20370@subsubheading Example
20371
922fbb7b 20372@smallexample
594fe323 20373(gdb)
a2c02241
NR
20374-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
20375^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 20376(gdb)
a2c02241
NR
20377-environment-directory ""
20378^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 20379(gdb)
a2c02241
NR
20380-environment-directory -r /home/jjohnstn/src/gdb /usr/src
20381^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 20382(gdb)
a2c02241
NR
20383-environment-directory -r
20384^done,source-path="$cdir:$cwd"
594fe323 20385(gdb)
922fbb7b
AC
20386@end smallexample
20387
20388
a2c02241
NR
20389@subheading The @code{-environment-path} Command
20390@findex -environment-path
922fbb7b
AC
20391
20392@subsubheading Synopsis
20393
20394@smallexample
a2c02241 20395 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
20396@end smallexample
20397
a2c02241
NR
20398Add directories @var{pathdir} to beginning of search path for object files.
20399If the @samp{-r} option is used, the search path is reset to the original
20400search path that existed at gdb start-up. If directories @var{pathdir} are
20401supplied in addition to the
20402@samp{-r} option, the search path is first reset and then addition
20403occurs as normal.
20404Multiple directories may be specified, separated by blanks. Specifying
20405multiple directories in a single command
20406results in the directories added to the beginning of the
20407search path in the same order they were presented in the command.
20408If blanks are needed as
20409part of a directory name, double-quotes should be used around
20410the name. In the command output, the path will show up separated
d3e8051b 20411by the system directory-separator character. The directory-separator
a2c02241
NR
20412character must not be used
20413in any directory name.
20414If no directories are specified, the current path is displayed.
20415
922fbb7b
AC
20416
20417@subsubheading @value{GDBN} Command
20418
a2c02241 20419The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
20420
20421@subsubheading Example
20422
922fbb7b 20423@smallexample
594fe323 20424(gdb)
a2c02241
NR
20425-environment-path
20426^done,path="/usr/bin"
594fe323 20427(gdb)
a2c02241
NR
20428-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
20429^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 20430(gdb)
a2c02241
NR
20431-environment-path -r /usr/local/bin
20432^done,path="/usr/local/bin:/usr/bin"
594fe323 20433(gdb)
922fbb7b
AC
20434@end smallexample
20435
20436
a2c02241
NR
20437@subheading The @code{-environment-pwd} Command
20438@findex -environment-pwd
922fbb7b
AC
20439
20440@subsubheading Synopsis
20441
20442@smallexample
a2c02241 20443 -environment-pwd
922fbb7b
AC
20444@end smallexample
20445
a2c02241 20446Show the current working directory.
922fbb7b 20447
79a6e687 20448@subsubheading @value{GDBN} Command
922fbb7b 20449
a2c02241 20450The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
20451
20452@subsubheading Example
20453
922fbb7b 20454@smallexample
594fe323 20455(gdb)
a2c02241
NR
20456-environment-pwd
20457^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 20458(gdb)
922fbb7b
AC
20459@end smallexample
20460
a2c02241
NR
20461@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20462@node GDB/MI Thread Commands
20463@section @sc{gdb/mi} Thread Commands
20464
20465
20466@subheading The @code{-thread-info} Command
20467@findex -thread-info
922fbb7b
AC
20468
20469@subsubheading Synopsis
20470
20471@smallexample
8e8901c5 20472 -thread-info [ @var{thread-id} ]
922fbb7b
AC
20473@end smallexample
20474
8e8901c5
VP
20475Reports information about either a specific thread, if
20476the @var{thread-id} parameter is present, or about all
20477threads. When printing information about all threads,
20478also reports the current thread.
20479
79a6e687 20480@subsubheading @value{GDBN} Command
922fbb7b 20481
8e8901c5
VP
20482The @samp{info thread} command prints the same information
20483about all threads.
922fbb7b
AC
20484
20485@subsubheading Example
922fbb7b
AC
20486
20487@smallexample
8e8901c5
VP
20488-thread-info
20489^done,threads=[
20490@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
c3b108f7 20491 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
8e8901c5
VP
20492@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
20493 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
c3b108f7 20494 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}],
8e8901c5
VP
20495current-thread-id="1"
20496(gdb)
922fbb7b
AC
20497@end smallexample
20498
c3b108f7
VP
20499The @samp{state} field may have the following values:
20500
20501@table @code
20502@item stopped
20503The thread is stopped. Frame information is available for stopped
20504threads.
20505
20506@item running
20507The thread is running. There's no frame information for running
20508threads.
20509
20510@end table
20511
a2c02241
NR
20512@subheading The @code{-thread-list-ids} Command
20513@findex -thread-list-ids
922fbb7b 20514
a2c02241 20515@subsubheading Synopsis
922fbb7b 20516
a2c02241
NR
20517@smallexample
20518 -thread-list-ids
20519@end smallexample
922fbb7b 20520
a2c02241
NR
20521Produces a list of the currently known @value{GDBN} thread ids. At the
20522end of the list it also prints the total number of such threads.
922fbb7b 20523
c3b108f7
VP
20524This command is retained for historical reasons, the
20525@code{-thread-info} command should be used instead.
20526
922fbb7b
AC
20527@subsubheading @value{GDBN} Command
20528
a2c02241 20529Part of @samp{info threads} supplies the same information.
922fbb7b
AC
20530
20531@subsubheading Example
20532
a2c02241 20533No threads present, besides the main process:
922fbb7b
AC
20534
20535@smallexample
594fe323 20536(gdb)
a2c02241
NR
20537-thread-list-ids
20538^done,thread-ids=@{@},number-of-threads="0"
594fe323 20539(gdb)
922fbb7b
AC
20540@end smallexample
20541
922fbb7b 20542
a2c02241 20543Several threads:
922fbb7b
AC
20544
20545@smallexample
594fe323 20546(gdb)
a2c02241
NR
20547-thread-list-ids
20548^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20549number-of-threads="3"
594fe323 20550(gdb)
922fbb7b
AC
20551@end smallexample
20552
a2c02241
NR
20553
20554@subheading The @code{-thread-select} Command
20555@findex -thread-select
922fbb7b
AC
20556
20557@subsubheading Synopsis
20558
20559@smallexample
a2c02241 20560 -thread-select @var{threadnum}
922fbb7b
AC
20561@end smallexample
20562
a2c02241
NR
20563Make @var{threadnum} the current thread. It prints the number of the new
20564current thread, and the topmost frame for that thread.
922fbb7b 20565
c3b108f7
VP
20566This command is deprecated in favor of explicitly using the
20567@samp{--thread} option to each command.
20568
922fbb7b
AC
20569@subsubheading @value{GDBN} Command
20570
a2c02241 20571The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
20572
20573@subsubheading Example
922fbb7b
AC
20574
20575@smallexample
594fe323 20576(gdb)
a2c02241
NR
20577-exec-next
20578^running
594fe323 20579(gdb)
a2c02241
NR
20580*stopped,reason="end-stepping-range",thread-id="2",line="187",
20581file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 20582(gdb)
a2c02241
NR
20583-thread-list-ids
20584^done,
20585thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20586number-of-threads="3"
594fe323 20587(gdb)
a2c02241
NR
20588-thread-select 3
20589^done,new-thread-id="3",
20590frame=@{level="0",func="vprintf",
20591args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20592@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 20593(gdb)
922fbb7b
AC
20594@end smallexample
20595
a2c02241
NR
20596@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20597@node GDB/MI Program Execution
20598@section @sc{gdb/mi} Program Execution
922fbb7b 20599
ef21caaf 20600These are the asynchronous commands which generate the out-of-band
3f94c067 20601record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
20602asynchronously with remote targets and this interaction is mimicked in
20603other cases.
922fbb7b 20604
922fbb7b
AC
20605@subheading The @code{-exec-continue} Command
20606@findex -exec-continue
20607
20608@subsubheading Synopsis
20609
20610@smallexample
c3b108f7 20611 -exec-continue [--all|--thread-group N]
922fbb7b
AC
20612@end smallexample
20613
ef21caaf 20614Resumes the execution of the inferior program until a breakpoint is
c3b108f7
VP
20615encountered, or until the inferior exits. In all-stop mode
20616(@pxref{All-Stop Mode}), may resume only one thread, or all threads,
20617depending on the value of the @samp{scheduler-locking} variable. In
20618non-stop mode (@pxref{Non-Stop Mode}), if the @samp{--all} is not
20619specified, only the thread specified with the @samp{--thread} option
20620(or current thread, if no @samp{--thread} is provided) is resumed. If
20621@samp{--all} is specified, all threads will be resumed. The
20622@samp{--all} option is ignored in all-stop mode. If the
20623@samp{--thread-group} options is specified, then all threads in that
20624thread group are resumed.
922fbb7b
AC
20625
20626@subsubheading @value{GDBN} Command
20627
20628The corresponding @value{GDBN} corresponding is @samp{continue}.
20629
20630@subsubheading Example
20631
20632@smallexample
20633-exec-continue
20634^running
594fe323 20635(gdb)
922fbb7b 20636@@Hello world
a47ec5fe
AR
20637*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
20638func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
20639line="13"@}
594fe323 20640(gdb)
922fbb7b
AC
20641@end smallexample
20642
20643
20644@subheading The @code{-exec-finish} Command
20645@findex -exec-finish
20646
20647@subsubheading Synopsis
20648
20649@smallexample
20650 -exec-finish
20651@end smallexample
20652
ef21caaf
NR
20653Resumes the execution of the inferior program until the current
20654function is exited. Displays the results returned by the function.
922fbb7b
AC
20655
20656@subsubheading @value{GDBN} Command
20657
20658The corresponding @value{GDBN} command is @samp{finish}.
20659
20660@subsubheading Example
20661
20662Function returning @code{void}.
20663
20664@smallexample
20665-exec-finish
20666^running
594fe323 20667(gdb)
922fbb7b
AC
20668@@hello from foo
20669*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 20670file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 20671(gdb)
922fbb7b
AC
20672@end smallexample
20673
20674Function returning other than @code{void}. The name of the internal
20675@value{GDBN} variable storing the result is printed, together with the
20676value itself.
20677
20678@smallexample
20679-exec-finish
20680^running
594fe323 20681(gdb)
922fbb7b
AC
20682*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
20683args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 20684file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 20685gdb-result-var="$1",return-value="0"
594fe323 20686(gdb)
922fbb7b
AC
20687@end smallexample
20688
20689
20690@subheading The @code{-exec-interrupt} Command
20691@findex -exec-interrupt
20692
20693@subsubheading Synopsis
20694
20695@smallexample
c3b108f7 20696 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
20697@end smallexample
20698
ef21caaf
NR
20699Interrupts the background execution of the target. Note how the token
20700associated with the stop message is the one for the execution command
20701that has been interrupted. The token for the interrupt itself only
20702appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
20703interrupt a non-running program, an error message will be printed.
20704
c3b108f7
VP
20705Note that when asynchronous execution is enabled, this command is
20706asynchronous just like other execution commands. That is, first the
20707@samp{^done} response will be printed, and the target stop will be
20708reported after that using the @samp{*stopped} notification.
20709
20710In non-stop mode, only the context thread is interrupted by default.
20711All threads will be interrupted if the @samp{--all} option is
20712specified. If the @samp{--thread-group} option is specified, all
20713threads in that group will be interrupted.
20714
922fbb7b
AC
20715@subsubheading @value{GDBN} Command
20716
20717The corresponding @value{GDBN} command is @samp{interrupt}.
20718
20719@subsubheading Example
20720
20721@smallexample
594fe323 20722(gdb)
922fbb7b
AC
20723111-exec-continue
20724111^running
20725
594fe323 20726(gdb)
922fbb7b
AC
20727222-exec-interrupt
20728222^done
594fe323 20729(gdb)
922fbb7b 20730111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 20731frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 20732fullname="/home/foo/bar/try.c",line="13"@}
594fe323 20733(gdb)
922fbb7b 20734
594fe323 20735(gdb)
922fbb7b
AC
20736-exec-interrupt
20737^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 20738(gdb)
922fbb7b
AC
20739@end smallexample
20740
20741
20742@subheading The @code{-exec-next} Command
20743@findex -exec-next
20744
20745@subsubheading Synopsis
20746
20747@smallexample
20748 -exec-next
20749@end smallexample
20750
ef21caaf
NR
20751Resumes execution of the inferior program, stopping when the beginning
20752of the next source line is reached.
922fbb7b
AC
20753
20754@subsubheading @value{GDBN} Command
20755
20756The corresponding @value{GDBN} command is @samp{next}.
20757
20758@subsubheading Example
20759
20760@smallexample
20761-exec-next
20762^running
594fe323 20763(gdb)
922fbb7b 20764*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 20765(gdb)
922fbb7b
AC
20766@end smallexample
20767
20768
20769@subheading The @code{-exec-next-instruction} Command
20770@findex -exec-next-instruction
20771
20772@subsubheading Synopsis
20773
20774@smallexample
20775 -exec-next-instruction
20776@end smallexample
20777
ef21caaf
NR
20778Executes one machine instruction. If the instruction is a function
20779call, continues until the function returns. If the program stops at an
20780instruction in the middle of a source line, the address will be
20781printed as well.
922fbb7b
AC
20782
20783@subsubheading @value{GDBN} Command
20784
20785The corresponding @value{GDBN} command is @samp{nexti}.
20786
20787@subsubheading Example
20788
20789@smallexample
594fe323 20790(gdb)
922fbb7b
AC
20791-exec-next-instruction
20792^running
20793
594fe323 20794(gdb)
922fbb7b
AC
20795*stopped,reason="end-stepping-range",
20796addr="0x000100d4",line="5",file="hello.c"
594fe323 20797(gdb)
922fbb7b
AC
20798@end smallexample
20799
20800
20801@subheading The @code{-exec-return} Command
20802@findex -exec-return
20803
20804@subsubheading Synopsis
20805
20806@smallexample
20807 -exec-return
20808@end smallexample
20809
20810Makes current function return immediately. Doesn't execute the inferior.
20811Displays the new current frame.
20812
20813@subsubheading @value{GDBN} Command
20814
20815The corresponding @value{GDBN} command is @samp{return}.
20816
20817@subsubheading Example
20818
20819@smallexample
594fe323 20820(gdb)
922fbb7b
AC
20821200-break-insert callee4
20822200^done,bkpt=@{number="1",addr="0x00010734",
20823file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 20824(gdb)
922fbb7b
AC
20825000-exec-run
20826000^running
594fe323 20827(gdb)
a47ec5fe 20828000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 20829frame=@{func="callee4",args=[],
76ff342d
DJ
20830file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20831fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 20832(gdb)
922fbb7b
AC
20833205-break-delete
20834205^done
594fe323 20835(gdb)
922fbb7b
AC
20836111-exec-return
20837111^done,frame=@{level="0",func="callee3",
20838args=[@{name="strarg",
20839value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
20840file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
20841fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 20842(gdb)
922fbb7b
AC
20843@end smallexample
20844
20845
20846@subheading The @code{-exec-run} Command
20847@findex -exec-run
20848
20849@subsubheading Synopsis
20850
20851@smallexample
20852 -exec-run
20853@end smallexample
20854
ef21caaf
NR
20855Starts execution of the inferior from the beginning. The inferior
20856executes until either a breakpoint is encountered or the program
20857exits. In the latter case the output will include an exit code, if
20858the program has exited exceptionally.
922fbb7b
AC
20859
20860@subsubheading @value{GDBN} Command
20861
20862The corresponding @value{GDBN} command is @samp{run}.
20863
ef21caaf 20864@subsubheading Examples
922fbb7b
AC
20865
20866@smallexample
594fe323 20867(gdb)
922fbb7b
AC
20868-break-insert main
20869^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 20870(gdb)
922fbb7b
AC
20871-exec-run
20872^running
594fe323 20873(gdb)
a47ec5fe 20874*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 20875frame=@{func="main",args=[],file="recursive2.c",
948d5102 20876fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 20877(gdb)
922fbb7b
AC
20878@end smallexample
20879
ef21caaf
NR
20880@noindent
20881Program exited normally:
20882
20883@smallexample
594fe323 20884(gdb)
ef21caaf
NR
20885-exec-run
20886^running
594fe323 20887(gdb)
ef21caaf
NR
20888x = 55
20889*stopped,reason="exited-normally"
594fe323 20890(gdb)
ef21caaf
NR
20891@end smallexample
20892
20893@noindent
20894Program exited exceptionally:
20895
20896@smallexample
594fe323 20897(gdb)
ef21caaf
NR
20898-exec-run
20899^running
594fe323 20900(gdb)
ef21caaf
NR
20901x = 55
20902*stopped,reason="exited",exit-code="01"
594fe323 20903(gdb)
ef21caaf
NR
20904@end smallexample
20905
20906Another way the program can terminate is if it receives a signal such as
20907@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
20908
20909@smallexample
594fe323 20910(gdb)
ef21caaf
NR
20911*stopped,reason="exited-signalled",signal-name="SIGINT",
20912signal-meaning="Interrupt"
20913@end smallexample
20914
922fbb7b 20915
a2c02241
NR
20916@c @subheading -exec-signal
20917
20918
20919@subheading The @code{-exec-step} Command
20920@findex -exec-step
922fbb7b
AC
20921
20922@subsubheading Synopsis
20923
20924@smallexample
a2c02241 20925 -exec-step
922fbb7b
AC
20926@end smallexample
20927
a2c02241
NR
20928Resumes execution of the inferior program, stopping when the beginning
20929of the next source line is reached, if the next source line is not a
20930function call. If it is, stop at the first instruction of the called
20931function.
922fbb7b
AC
20932
20933@subsubheading @value{GDBN} Command
20934
a2c02241 20935The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
20936
20937@subsubheading Example
20938
20939Stepping into a function:
20940
20941@smallexample
20942-exec-step
20943^running
594fe323 20944(gdb)
922fbb7b
AC
20945*stopped,reason="end-stepping-range",
20946frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 20947@{name="b",value="0"@}],file="recursive2.c",
948d5102 20948fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 20949(gdb)
922fbb7b
AC
20950@end smallexample
20951
20952Regular stepping:
20953
20954@smallexample
20955-exec-step
20956^running
594fe323 20957(gdb)
922fbb7b 20958*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 20959(gdb)
922fbb7b
AC
20960@end smallexample
20961
20962
20963@subheading The @code{-exec-step-instruction} Command
20964@findex -exec-step-instruction
20965
20966@subsubheading Synopsis
20967
20968@smallexample
20969 -exec-step-instruction
20970@end smallexample
20971
ef21caaf
NR
20972Resumes the inferior which executes one machine instruction. The
20973output, once @value{GDBN} has stopped, will vary depending on whether
20974we have stopped in the middle of a source line or not. In the former
20975case, the address at which the program stopped will be printed as
922fbb7b
AC
20976well.
20977
20978@subsubheading @value{GDBN} Command
20979
20980The corresponding @value{GDBN} command is @samp{stepi}.
20981
20982@subsubheading Example
20983
20984@smallexample
594fe323 20985(gdb)
922fbb7b
AC
20986-exec-step-instruction
20987^running
20988
594fe323 20989(gdb)
922fbb7b 20990*stopped,reason="end-stepping-range",
76ff342d 20991frame=@{func="foo",args=[],file="try.c",
948d5102 20992fullname="/home/foo/bar/try.c",line="10"@}
594fe323 20993(gdb)
922fbb7b
AC
20994-exec-step-instruction
20995^running
20996
594fe323 20997(gdb)
922fbb7b 20998*stopped,reason="end-stepping-range",
76ff342d 20999frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 21000fullname="/home/foo/bar/try.c",line="10"@}
594fe323 21001(gdb)
922fbb7b
AC
21002@end smallexample
21003
21004
21005@subheading The @code{-exec-until} Command
21006@findex -exec-until
21007
21008@subsubheading Synopsis
21009
21010@smallexample
21011 -exec-until [ @var{location} ]
21012@end smallexample
21013
ef21caaf
NR
21014Executes the inferior until the @var{location} specified in the
21015argument is reached. If there is no argument, the inferior executes
21016until a source line greater than the current one is reached. The
21017reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
21018
21019@subsubheading @value{GDBN} Command
21020
21021The corresponding @value{GDBN} command is @samp{until}.
21022
21023@subsubheading Example
21024
21025@smallexample
594fe323 21026(gdb)
922fbb7b
AC
21027-exec-until recursive2.c:6
21028^running
594fe323 21029(gdb)
922fbb7b
AC
21030x = 55
21031*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 21032file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 21033(gdb)
922fbb7b
AC
21034@end smallexample
21035
21036@ignore
21037@subheading -file-clear
21038Is this going away????
21039@end ignore
21040
351ff01a 21041@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
21042@node GDB/MI Stack Manipulation
21043@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 21044
922fbb7b 21045
a2c02241
NR
21046@subheading The @code{-stack-info-frame} Command
21047@findex -stack-info-frame
922fbb7b
AC
21048
21049@subsubheading Synopsis
21050
21051@smallexample
a2c02241 21052 -stack-info-frame
922fbb7b
AC
21053@end smallexample
21054
a2c02241 21055Get info on the selected frame.
922fbb7b
AC
21056
21057@subsubheading @value{GDBN} Command
21058
a2c02241
NR
21059The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
21060(without arguments).
922fbb7b
AC
21061
21062@subsubheading Example
21063
21064@smallexample
594fe323 21065(gdb)
a2c02241
NR
21066-stack-info-frame
21067^done,frame=@{level="1",addr="0x0001076c",func="callee3",
21068file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21069fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 21070(gdb)
922fbb7b
AC
21071@end smallexample
21072
a2c02241
NR
21073@subheading The @code{-stack-info-depth} Command
21074@findex -stack-info-depth
922fbb7b
AC
21075
21076@subsubheading Synopsis
21077
21078@smallexample
a2c02241 21079 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
21080@end smallexample
21081
a2c02241
NR
21082Return the depth of the stack. If the integer argument @var{max-depth}
21083is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
21084
21085@subsubheading @value{GDBN} Command
21086
a2c02241 21087There's no equivalent @value{GDBN} command.
922fbb7b
AC
21088
21089@subsubheading Example
21090
a2c02241
NR
21091For a stack with frame levels 0 through 11:
21092
922fbb7b 21093@smallexample
594fe323 21094(gdb)
a2c02241
NR
21095-stack-info-depth
21096^done,depth="12"
594fe323 21097(gdb)
a2c02241
NR
21098-stack-info-depth 4
21099^done,depth="4"
594fe323 21100(gdb)
a2c02241
NR
21101-stack-info-depth 12
21102^done,depth="12"
594fe323 21103(gdb)
a2c02241
NR
21104-stack-info-depth 11
21105^done,depth="11"
594fe323 21106(gdb)
a2c02241
NR
21107-stack-info-depth 13
21108^done,depth="12"
594fe323 21109(gdb)
922fbb7b
AC
21110@end smallexample
21111
a2c02241
NR
21112@subheading The @code{-stack-list-arguments} Command
21113@findex -stack-list-arguments
922fbb7b
AC
21114
21115@subsubheading Synopsis
21116
21117@smallexample
a2c02241
NR
21118 -stack-list-arguments @var{show-values}
21119 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
21120@end smallexample
21121
a2c02241
NR
21122Display a list of the arguments for the frames between @var{low-frame}
21123and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
21124@var{high-frame} are not provided, list the arguments for the whole
21125call stack. If the two arguments are equal, show the single frame
21126at the corresponding level. It is an error if @var{low-frame} is
21127larger than the actual number of frames. On the other hand,
21128@var{high-frame} may be larger than the actual number of frames, in
21129which case only existing frames will be returned.
a2c02241
NR
21130
21131The @var{show-values} argument must have a value of 0 or 1. A value of
211320 means that only the names of the arguments are listed, a value of 1
21133means that both names and values of the arguments are printed.
922fbb7b
AC
21134
21135@subsubheading @value{GDBN} Command
21136
a2c02241
NR
21137@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
21138@samp{gdb_get_args} command which partially overlaps with the
21139functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
21140
21141@subsubheading Example
922fbb7b 21142
a2c02241 21143@smallexample
594fe323 21144(gdb)
a2c02241
NR
21145-stack-list-frames
21146^done,
21147stack=[
21148frame=@{level="0",addr="0x00010734",func="callee4",
21149file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21150fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
21151frame=@{level="1",addr="0x0001076c",func="callee3",
21152file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21153fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
21154frame=@{level="2",addr="0x0001078c",func="callee2",
21155file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21156fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
21157frame=@{level="3",addr="0x000107b4",func="callee1",
21158file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21159fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
21160frame=@{level="4",addr="0x000107e0",func="main",
21161file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
21162fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 21163(gdb)
a2c02241
NR
21164-stack-list-arguments 0
21165^done,
21166stack-args=[
21167frame=@{level="0",args=[]@},
21168frame=@{level="1",args=[name="strarg"]@},
21169frame=@{level="2",args=[name="intarg",name="strarg"]@},
21170frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
21171frame=@{level="4",args=[]@}]
594fe323 21172(gdb)
a2c02241
NR
21173-stack-list-arguments 1
21174^done,
21175stack-args=[
21176frame=@{level="0",args=[]@},
21177frame=@{level="1",
21178 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
21179frame=@{level="2",args=[
21180@{name="intarg",value="2"@},
21181@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
21182@{frame=@{level="3",args=[
21183@{name="intarg",value="2"@},
21184@{name="strarg",value="0x11940 \"A string argument.\""@},
21185@{name="fltarg",value="3.5"@}]@},
21186frame=@{level="4",args=[]@}]
594fe323 21187(gdb)
a2c02241
NR
21188-stack-list-arguments 0 2 2
21189^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 21190(gdb)
a2c02241
NR
21191-stack-list-arguments 1 2 2
21192^done,stack-args=[frame=@{level="2",
21193args=[@{name="intarg",value="2"@},
21194@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 21195(gdb)
a2c02241
NR
21196@end smallexample
21197
21198@c @subheading -stack-list-exception-handlers
922fbb7b 21199
a2c02241
NR
21200
21201@subheading The @code{-stack-list-frames} Command
21202@findex -stack-list-frames
1abaf70c
BR
21203
21204@subsubheading Synopsis
21205
21206@smallexample
a2c02241 21207 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
21208@end smallexample
21209
a2c02241
NR
21210List the frames currently on the stack. For each frame it displays the
21211following info:
21212
21213@table @samp
21214@item @var{level}
d3e8051b 21215The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
21216@item @var{addr}
21217The @code{$pc} value for that frame.
21218@item @var{func}
21219Function name.
21220@item @var{file}
21221File name of the source file where the function lives.
21222@item @var{line}
21223Line number corresponding to the @code{$pc}.
21224@end table
21225
21226If invoked without arguments, this command prints a backtrace for the
21227whole stack. If given two integer arguments, it shows the frames whose
21228levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
21229are equal, it shows the single frame at the corresponding level. It is
21230an error if @var{low-frame} is larger than the actual number of
a5451f4e 21231frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 21232actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
21233
21234@subsubheading @value{GDBN} Command
21235
a2c02241 21236The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
21237
21238@subsubheading Example
21239
a2c02241
NR
21240Full stack backtrace:
21241
1abaf70c 21242@smallexample
594fe323 21243(gdb)
a2c02241
NR
21244-stack-list-frames
21245^done,stack=
21246[frame=@{level="0",addr="0x0001076c",func="foo",
21247 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
21248frame=@{level="1",addr="0x000107a4",func="foo",
21249 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21250frame=@{level="2",addr="0x000107a4",func="foo",
21251 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21252frame=@{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"@},
21258frame=@{level="6",addr="0x000107a4",func="foo",
21259 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21260frame=@{level="7",addr="0x000107a4",func="foo",
21261 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21262frame=@{level="8",addr="0x000107a4",func="foo",
21263 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21264frame=@{level="9",addr="0x000107a4",func="foo",
21265 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21266frame=@{level="10",addr="0x000107a4",func="foo",
21267 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21268frame=@{level="11",addr="0x00010738",func="main",
21269 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 21270(gdb)
1abaf70c
BR
21271@end smallexample
21272
a2c02241 21273Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 21274
a2c02241 21275@smallexample
594fe323 21276(gdb)
a2c02241
NR
21277-stack-list-frames 3 5
21278^done,stack=
21279[frame=@{level="3",addr="0x000107a4",func="foo",
21280 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21281frame=@{level="4",addr="0x000107a4",func="foo",
21282 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
21283frame=@{level="5",addr="0x000107a4",func="foo",
21284 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 21285(gdb)
a2c02241 21286@end smallexample
922fbb7b 21287
a2c02241 21288Show a single frame:
922fbb7b
AC
21289
21290@smallexample
594fe323 21291(gdb)
a2c02241
NR
21292-stack-list-frames 3 3
21293^done,stack=
21294[frame=@{level="3",addr="0x000107a4",func="foo",
21295 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 21296(gdb)
922fbb7b
AC
21297@end smallexample
21298
922fbb7b 21299
a2c02241
NR
21300@subheading The @code{-stack-list-locals} Command
21301@findex -stack-list-locals
57c22c6c 21302
a2c02241 21303@subsubheading Synopsis
922fbb7b
AC
21304
21305@smallexample
a2c02241 21306 -stack-list-locals @var{print-values}
922fbb7b
AC
21307@end smallexample
21308
a2c02241
NR
21309Display the local variable names for the selected frame. If
21310@var{print-values} is 0 or @code{--no-values}, print only the names of
21311the variables; if it is 1 or @code{--all-values}, print also their
21312values; and if it is 2 or @code{--simple-values}, print the name,
21313type and value for simple data types and the name and type for arrays,
21314structures and unions. In this last case, a frontend can immediately
21315display the value of simple data types and create variable objects for
d3e8051b 21316other data types when the user wishes to explore their values in
a2c02241 21317more detail.
922fbb7b
AC
21318
21319@subsubheading @value{GDBN} Command
21320
a2c02241 21321@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
21322
21323@subsubheading Example
922fbb7b
AC
21324
21325@smallexample
594fe323 21326(gdb)
a2c02241
NR
21327-stack-list-locals 0
21328^done,locals=[name="A",name="B",name="C"]
594fe323 21329(gdb)
a2c02241
NR
21330-stack-list-locals --all-values
21331^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
21332 @{name="C",value="@{1, 2, 3@}"@}]
21333-stack-list-locals --simple-values
21334^done,locals=[@{name="A",type="int",value="1"@},
21335 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 21336(gdb)
922fbb7b
AC
21337@end smallexample
21338
922fbb7b 21339
a2c02241
NR
21340@subheading The @code{-stack-select-frame} Command
21341@findex -stack-select-frame
922fbb7b
AC
21342
21343@subsubheading Synopsis
21344
21345@smallexample
a2c02241 21346 -stack-select-frame @var{framenum}
922fbb7b
AC
21347@end smallexample
21348
a2c02241
NR
21349Change the selected frame. Select a different frame @var{framenum} on
21350the stack.
922fbb7b 21351
c3b108f7
VP
21352This command in deprecated in favor of passing the @samp{--frame}
21353option to every command.
21354
922fbb7b
AC
21355@subsubheading @value{GDBN} Command
21356
a2c02241
NR
21357The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
21358@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
21359
21360@subsubheading Example
21361
21362@smallexample
594fe323 21363(gdb)
a2c02241 21364-stack-select-frame 2
922fbb7b 21365^done
594fe323 21366(gdb)
922fbb7b
AC
21367@end smallexample
21368
21369@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
21370@node GDB/MI Variable Objects
21371@section @sc{gdb/mi} Variable Objects
922fbb7b 21372
a1b5960f 21373@ignore
922fbb7b 21374
a2c02241 21375@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 21376
a2c02241
NR
21377For the implementation of a variable debugger window (locals, watched
21378expressions, etc.), we are proposing the adaptation of the existing code
21379used by @code{Insight}.
922fbb7b 21380
a2c02241 21381The two main reasons for that are:
922fbb7b 21382
a2c02241
NR
21383@enumerate 1
21384@item
21385It has been proven in practice (it is already on its second generation).
922fbb7b 21386
a2c02241
NR
21387@item
21388It will shorten development time (needless to say how important it is
21389now).
21390@end enumerate
922fbb7b 21391
a2c02241
NR
21392The original interface was designed to be used by Tcl code, so it was
21393slightly changed so it could be used through @sc{gdb/mi}. This section
21394describes the @sc{gdb/mi} operations that will be available and gives some
21395hints about their use.
922fbb7b 21396
a2c02241
NR
21397@emph{Note}: In addition to the set of operations described here, we
21398expect the @sc{gui} implementation of a variable window to require, at
21399least, the following operations:
922fbb7b 21400
a2c02241
NR
21401@itemize @bullet
21402@item @code{-gdb-show} @code{output-radix}
21403@item @code{-stack-list-arguments}
21404@item @code{-stack-list-locals}
21405@item @code{-stack-select-frame}
21406@end itemize
922fbb7b 21407
a1b5960f
VP
21408@end ignore
21409
c8b2f53c 21410@subheading Introduction to Variable Objects
922fbb7b 21411
a2c02241 21412@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
21413
21414Variable objects are "object-oriented" MI interface for examining and
21415changing values of expressions. Unlike some other MI interfaces that
21416work with expressions, variable objects are specifically designed for
21417simple and efficient presentation in the frontend. A variable object
21418is identified by string name. When a variable object is created, the
21419frontend specifies the expression for that variable object. The
21420expression can be a simple variable, or it can be an arbitrary complex
21421expression, and can even involve CPU registers. After creating a
21422variable object, the frontend can invoke other variable object
21423operations---for example to obtain or change the value of a variable
21424object, or to change display format.
21425
21426Variable objects have hierarchical tree structure. Any variable object
21427that corresponds to a composite type, such as structure in C, has
21428a number of child variable objects, for example corresponding to each
21429element of a structure. A child variable object can itself have
21430children, recursively. Recursion ends when we reach
25d5ea92
VP
21431leaf variable objects, which always have built-in types. Child variable
21432objects are created only by explicit request, so if a frontend
21433is not interested in the children of a particular variable object, no
21434child will be created.
c8b2f53c
VP
21435
21436For a leaf variable object it is possible to obtain its value as a
21437string, or set the value from a string. String value can be also
21438obtained for a non-leaf variable object, but it's generally a string
21439that only indicates the type of the object, and does not list its
21440contents. Assignment to a non-leaf variable object is not allowed.
21441
21442A frontend does not need to read the values of all variable objects each time
21443the program stops. Instead, MI provides an update command that lists all
21444variable objects whose values has changed since the last update
21445operation. This considerably reduces the amount of data that must
25d5ea92
VP
21446be transferred to the frontend. As noted above, children variable
21447objects are created on demand, and only leaf variable objects have a
21448real value. As result, gdb will read target memory only for leaf
21449variables that frontend has created.
21450
21451The automatic update is not always desirable. For example, a frontend
21452might want to keep a value of some expression for future reference,
21453and never update it. For another example, fetching memory is
21454relatively slow for embedded targets, so a frontend might want
21455to disable automatic update for the variables that are either not
21456visible on the screen, or ``closed''. This is possible using so
21457called ``frozen variable objects''. Such variable objects are never
21458implicitly updated.
922fbb7b 21459
c3b108f7
VP
21460Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
21461fixed variable object, the expression is parsed when the variable
21462object is created, including associating identifiers to specific
21463variables. The meaning of expression never changes. For a floating
21464variable object the values of variables whose names appear in the
21465expressions are re-evaluated every time in the context of the current
21466frame. Consider this example:
21467
21468@smallexample
21469void do_work(...)
21470@{
21471 struct work_state state;
21472
21473 if (...)
21474 do_work(...);
21475@}
21476@end smallexample
21477
21478If a fixed variable object for the @code{state} variable is created in
21479this function, and we enter the recursive call, the the variable
21480object will report the value of @code{state} in the top-level
21481@code{do_work} invocation. On the other hand, a floating variable
21482object will report the value of @code{state} in the current frame.
21483
21484If an expression specified when creating a fixed variable object
21485refers to a local variable, the variable object becomes bound to the
21486thread and frame in which the variable object is created. When such
21487variable object is updated, @value{GDBN} makes sure that the
21488thread/frame combination the variable object is bound to still exists,
21489and re-evaluates the variable object in context of that thread/frame.
21490
a2c02241
NR
21491The following is the complete set of @sc{gdb/mi} operations defined to
21492access this functionality:
922fbb7b 21493
a2c02241
NR
21494@multitable @columnfractions .4 .6
21495@item @strong{Operation}
21496@tab @strong{Description}
922fbb7b 21497
a2c02241
NR
21498@item @code{-var-create}
21499@tab create a variable object
21500@item @code{-var-delete}
22d8a470 21501@tab delete the variable object and/or its children
a2c02241
NR
21502@item @code{-var-set-format}
21503@tab set the display format of this variable
21504@item @code{-var-show-format}
21505@tab show the display format of this variable
21506@item @code{-var-info-num-children}
21507@tab tells how many children this object has
21508@item @code{-var-list-children}
21509@tab return a list of the object's children
21510@item @code{-var-info-type}
21511@tab show the type of this variable object
21512@item @code{-var-info-expression}
02142340
VP
21513@tab print parent-relative expression that this variable object represents
21514@item @code{-var-info-path-expression}
21515@tab print full expression that this variable object represents
a2c02241
NR
21516@item @code{-var-show-attributes}
21517@tab is this variable editable? does it exist here?
21518@item @code{-var-evaluate-expression}
21519@tab get the value of this variable
21520@item @code{-var-assign}
21521@tab set the value of this variable
21522@item @code{-var-update}
21523@tab update the variable and its children
25d5ea92
VP
21524@item @code{-var-set-frozen}
21525@tab set frozeness attribute
a2c02241 21526@end multitable
922fbb7b 21527
a2c02241
NR
21528In the next subsection we describe each operation in detail and suggest
21529how it can be used.
922fbb7b 21530
a2c02241 21531@subheading Description And Use of Operations on Variable Objects
922fbb7b 21532
a2c02241
NR
21533@subheading The @code{-var-create} Command
21534@findex -var-create
ef21caaf 21535
a2c02241 21536@subsubheading Synopsis
ef21caaf 21537
a2c02241
NR
21538@smallexample
21539 -var-create @{@var{name} | "-"@}
c3b108f7 21540 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
21541@end smallexample
21542
21543This operation creates a variable object, which allows the monitoring of
21544a variable, the result of an expression, a memory cell or a CPU
21545register.
ef21caaf 21546
a2c02241
NR
21547The @var{name} parameter is the string by which the object can be
21548referenced. It must be unique. If @samp{-} is specified, the varobj
21549system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 21550unique provided that one does not specify @var{name} of that format.
a2c02241 21551The command fails if a duplicate name is found.
ef21caaf 21552
a2c02241
NR
21553The frame under which the expression should be evaluated can be
21554specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
21555frame should be used. A @samp{@@} indicates that a floating variable
21556object must be created.
922fbb7b 21557
a2c02241
NR
21558@var{expression} is any expression valid on the current language set (must not
21559begin with a @samp{*}), or one of the following:
922fbb7b 21560
a2c02241
NR
21561@itemize @bullet
21562@item
21563@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 21564
a2c02241
NR
21565@item
21566@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 21567
a2c02241
NR
21568@item
21569@samp{$@var{regname}} --- a CPU register name
21570@end itemize
922fbb7b 21571
a2c02241 21572@subsubheading Result
922fbb7b 21573
a2c02241
NR
21574This operation returns the name, number of children and the type of the
21575object created. Type is returned as a string as the ones generated by
c3b108f7
VP
21576the @value{GDBN} CLI. If a fixed variable object is bound to a
21577specific thread, the thread is is also printed:
922fbb7b
AC
21578
21579@smallexample
c3b108f7 21580 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}"
dcaaae04
NR
21581@end smallexample
21582
a2c02241
NR
21583
21584@subheading The @code{-var-delete} Command
21585@findex -var-delete
922fbb7b
AC
21586
21587@subsubheading Synopsis
21588
21589@smallexample
22d8a470 21590 -var-delete [ -c ] @var{name}
922fbb7b
AC
21591@end smallexample
21592
a2c02241 21593Deletes a previously created variable object and all of its children.
22d8a470 21594With the @samp{-c} option, just deletes the children.
922fbb7b 21595
a2c02241 21596Returns an error if the object @var{name} is not found.
922fbb7b 21597
922fbb7b 21598
a2c02241
NR
21599@subheading The @code{-var-set-format} Command
21600@findex -var-set-format
922fbb7b 21601
a2c02241 21602@subsubheading Synopsis
922fbb7b
AC
21603
21604@smallexample
a2c02241 21605 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
21606@end smallexample
21607
a2c02241
NR
21608Sets the output format for the value of the object @var{name} to be
21609@var{format-spec}.
21610
de051565 21611@anchor{-var-set-format}
a2c02241
NR
21612The syntax for the @var{format-spec} is as follows:
21613
21614@smallexample
21615 @var{format-spec} @expansion{}
21616 @{binary | decimal | hexadecimal | octal | natural@}
21617@end smallexample
21618
c8b2f53c
VP
21619The natural format is the default format choosen automatically
21620based on the variable type (like decimal for an @code{int}, hex
21621for pointers, etc.).
21622
21623For a variable with children, the format is set only on the
21624variable itself, and the children are not affected.
a2c02241
NR
21625
21626@subheading The @code{-var-show-format} Command
21627@findex -var-show-format
922fbb7b
AC
21628
21629@subsubheading Synopsis
21630
21631@smallexample
a2c02241 21632 -var-show-format @var{name}
922fbb7b
AC
21633@end smallexample
21634
a2c02241 21635Returns the format used to display the value of the object @var{name}.
922fbb7b 21636
a2c02241
NR
21637@smallexample
21638 @var{format} @expansion{}
21639 @var{format-spec}
21640@end smallexample
922fbb7b 21641
922fbb7b 21642
a2c02241
NR
21643@subheading The @code{-var-info-num-children} Command
21644@findex -var-info-num-children
21645
21646@subsubheading Synopsis
21647
21648@smallexample
21649 -var-info-num-children @var{name}
21650@end smallexample
21651
21652Returns the number of children of a variable object @var{name}:
21653
21654@smallexample
21655 numchild=@var{n}
21656@end smallexample
21657
21658
21659@subheading The @code{-var-list-children} Command
21660@findex -var-list-children
21661
21662@subsubheading Synopsis
21663
21664@smallexample
21665 -var-list-children [@var{print-values}] @var{name}
21666@end smallexample
21667@anchor{-var-list-children}
21668
21669Return a list of the children of the specified variable object and
21670create variable objects for them, if they do not already exist. With
21671a single argument or if @var{print-values} has a value for of 0 or
21672@code{--no-values}, print only the names of the variables; if
21673@var{print-values} is 1 or @code{--all-values}, also print their
21674values; and if it is 2 or @code{--simple-values} print the name and
21675value for simple data types and just the name for arrays, structures
21676and unions.
922fbb7b
AC
21677
21678@subsubheading Example
21679
21680@smallexample
594fe323 21681(gdb)
a2c02241
NR
21682 -var-list-children n
21683 ^done,numchild=@var{n},children=[@{name=@var{name},
21684 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 21685(gdb)
a2c02241
NR
21686 -var-list-children --all-values n
21687 ^done,numchild=@var{n},children=[@{name=@var{name},
21688 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
21689@end smallexample
21690
922fbb7b 21691
a2c02241
NR
21692@subheading The @code{-var-info-type} Command
21693@findex -var-info-type
922fbb7b 21694
a2c02241
NR
21695@subsubheading Synopsis
21696
21697@smallexample
21698 -var-info-type @var{name}
21699@end smallexample
21700
21701Returns the type of the specified variable @var{name}. The type is
21702returned as a string in the same format as it is output by the
21703@value{GDBN} CLI:
21704
21705@smallexample
21706 type=@var{typename}
21707@end smallexample
21708
21709
21710@subheading The @code{-var-info-expression} Command
21711@findex -var-info-expression
922fbb7b
AC
21712
21713@subsubheading Synopsis
21714
21715@smallexample
a2c02241 21716 -var-info-expression @var{name}
922fbb7b
AC
21717@end smallexample
21718
02142340
VP
21719Returns a string that is suitable for presenting this
21720variable object in user interface. The string is generally
21721not valid expression in the current language, and cannot be evaluated.
21722
21723For example, if @code{a} is an array, and variable object
21724@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 21725
a2c02241 21726@smallexample
02142340
VP
21727(gdb) -var-info-expression A.1
21728^done,lang="C",exp="1"
a2c02241 21729@end smallexample
922fbb7b 21730
a2c02241 21731@noindent
02142340
VP
21732Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
21733
21734Note that the output of the @code{-var-list-children} command also
21735includes those expressions, so the @code{-var-info-expression} command
21736is of limited use.
21737
21738@subheading The @code{-var-info-path-expression} Command
21739@findex -var-info-path-expression
21740
21741@subsubheading Synopsis
21742
21743@smallexample
21744 -var-info-path-expression @var{name}
21745@end smallexample
21746
21747Returns an expression that can be evaluated in the current
21748context and will yield the same value that a variable object has.
21749Compare this with the @code{-var-info-expression} command, which
21750result can be used only for UI presentation. Typical use of
21751the @code{-var-info-path-expression} command is creating a
21752watchpoint from a variable object.
21753
21754For example, suppose @code{C} is a C@t{++} class, derived from class
21755@code{Base}, and that the @code{Base} class has a member called
21756@code{m_size}. Assume a variable @code{c} is has the type of
21757@code{C} and a variable object @code{C} was created for variable
21758@code{c}. Then, we'll get this output:
21759@smallexample
21760(gdb) -var-info-path-expression C.Base.public.m_size
21761^done,path_expr=((Base)c).m_size)
21762@end smallexample
922fbb7b 21763
a2c02241
NR
21764@subheading The @code{-var-show-attributes} Command
21765@findex -var-show-attributes
922fbb7b 21766
a2c02241 21767@subsubheading Synopsis
922fbb7b 21768
a2c02241
NR
21769@smallexample
21770 -var-show-attributes @var{name}
21771@end smallexample
922fbb7b 21772
a2c02241 21773List attributes of the specified variable object @var{name}:
922fbb7b
AC
21774
21775@smallexample
a2c02241 21776 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
21777@end smallexample
21778
a2c02241
NR
21779@noindent
21780where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
21781
21782@subheading The @code{-var-evaluate-expression} Command
21783@findex -var-evaluate-expression
21784
21785@subsubheading Synopsis
21786
21787@smallexample
de051565 21788 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
21789@end smallexample
21790
21791Evaluates the expression that is represented by the specified variable
de051565
MK
21792object and returns its value as a string. The format of the string
21793can be specified with the @samp{-f} option. The possible values of
21794this option are the same as for @code{-var-set-format}
21795(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
21796the current display format will be used. The current display format
21797can be changed using the @code{-var-set-format} command.
a2c02241
NR
21798
21799@smallexample
21800 value=@var{value}
21801@end smallexample
21802
21803Note that one must invoke @code{-var-list-children} for a variable
21804before the value of a child variable can be evaluated.
21805
21806@subheading The @code{-var-assign} Command
21807@findex -var-assign
21808
21809@subsubheading Synopsis
21810
21811@smallexample
21812 -var-assign @var{name} @var{expression}
21813@end smallexample
21814
21815Assigns the value of @var{expression} to the variable object specified
21816by @var{name}. The object must be @samp{editable}. If the variable's
21817value is altered by the assign, the variable will show up in any
21818subsequent @code{-var-update} list.
21819
21820@subsubheading Example
922fbb7b
AC
21821
21822@smallexample
594fe323 21823(gdb)
a2c02241
NR
21824-var-assign var1 3
21825^done,value="3"
594fe323 21826(gdb)
a2c02241
NR
21827-var-update *
21828^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 21829(gdb)
922fbb7b
AC
21830@end smallexample
21831
a2c02241
NR
21832@subheading The @code{-var-update} Command
21833@findex -var-update
21834
21835@subsubheading Synopsis
21836
21837@smallexample
21838 -var-update [@var{print-values}] @{@var{name} | "*"@}
21839@end smallexample
21840
c8b2f53c
VP
21841Reevaluate the expressions corresponding to the variable object
21842@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
21843list of variable objects whose values have changed; @var{name} must
21844be a root variable object. Here, ``changed'' means that the result of
21845@code{-var-evaluate-expression} before and after the
21846@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
21847object names, all existing variable objects are updated, except
21848for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 21849@var{print-values} determines whether both names and values, or just
de051565 21850names are printed. The possible values of this option are the same
36ece8b3
NR
21851as for @code{-var-list-children} (@pxref{-var-list-children}). It is
21852recommended to use the @samp{--all-values} option, to reduce the
21853number of MI commands needed on each program stop.
c8b2f53c 21854
c3b108f7
VP
21855With the @samp{*} parameter, if a variable object is bound to a
21856currently running thread, it will not be updated, without any
21857diagnostic.
a2c02241
NR
21858
21859@subsubheading Example
922fbb7b
AC
21860
21861@smallexample
594fe323 21862(gdb)
a2c02241
NR
21863-var-assign var1 3
21864^done,value="3"
594fe323 21865(gdb)
a2c02241
NR
21866-var-update --all-values var1
21867^done,changelist=[@{name="var1",value="3",in_scope="true",
21868type_changed="false"@}]
594fe323 21869(gdb)
922fbb7b
AC
21870@end smallexample
21871
9f708cb2 21872@anchor{-var-update}
36ece8b3
NR
21873The field in_scope may take three values:
21874
21875@table @code
21876@item "true"
21877The variable object's current value is valid.
21878
21879@item "false"
21880The variable object does not currently hold a valid value but it may
21881hold one in the future if its associated expression comes back into
21882scope.
21883
21884@item "invalid"
21885The variable object no longer holds a valid value.
21886This can occur when the executable file being debugged has changed,
21887either through recompilation or by using the @value{GDBN} @code{file}
21888command. The front end should normally choose to delete these variable
21889objects.
21890@end table
21891
21892In the future new values may be added to this list so the front should
21893be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
21894
25d5ea92
VP
21895@subheading The @code{-var-set-frozen} Command
21896@findex -var-set-frozen
9f708cb2 21897@anchor{-var-set-frozen}
25d5ea92
VP
21898
21899@subsubheading Synopsis
21900
21901@smallexample
9f708cb2 21902 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
21903@end smallexample
21904
9f708cb2 21905Set the frozenness flag on the variable object @var{name}. The
25d5ea92 21906@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 21907frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 21908frozen, then neither itself, nor any of its children, are
9f708cb2 21909implicitly updated by @code{-var-update} of
25d5ea92
VP
21910a parent variable or by @code{-var-update *}. Only
21911@code{-var-update} of the variable itself will update its value and
21912values of its children. After a variable object is unfrozen, it is
21913implicitly updated by all subsequent @code{-var-update} operations.
21914Unfreezing a variable does not update it, only subsequent
21915@code{-var-update} does.
21916
21917@subsubheading Example
21918
21919@smallexample
21920(gdb)
21921-var-set-frozen V 1
21922^done
21923(gdb)
21924@end smallexample
21925
21926
a2c02241
NR
21927@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21928@node GDB/MI Data Manipulation
21929@section @sc{gdb/mi} Data Manipulation
922fbb7b 21930
a2c02241
NR
21931@cindex data manipulation, in @sc{gdb/mi}
21932@cindex @sc{gdb/mi}, data manipulation
21933This section describes the @sc{gdb/mi} commands that manipulate data:
21934examine memory and registers, evaluate expressions, etc.
21935
21936@c REMOVED FROM THE INTERFACE.
21937@c @subheading -data-assign
21938@c Change the value of a program variable. Plenty of side effects.
79a6e687 21939@c @subsubheading GDB Command
a2c02241
NR
21940@c set variable
21941@c @subsubheading Example
21942@c N.A.
21943
21944@subheading The @code{-data-disassemble} Command
21945@findex -data-disassemble
922fbb7b
AC
21946
21947@subsubheading Synopsis
21948
21949@smallexample
a2c02241
NR
21950 -data-disassemble
21951 [ -s @var{start-addr} -e @var{end-addr} ]
21952 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
21953 -- @var{mode}
922fbb7b
AC
21954@end smallexample
21955
a2c02241
NR
21956@noindent
21957Where:
21958
21959@table @samp
21960@item @var{start-addr}
21961is the beginning address (or @code{$pc})
21962@item @var{end-addr}
21963is the end address
21964@item @var{filename}
21965is the name of the file to disassemble
21966@item @var{linenum}
21967is the line number to disassemble around
21968@item @var{lines}
d3e8051b 21969is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
21970the whole function will be disassembled, in case no @var{end-addr} is
21971specified. If @var{end-addr} is specified as a non-zero value, and
21972@var{lines} is lower than the number of disassembly lines between
21973@var{start-addr} and @var{end-addr}, only @var{lines} lines are
21974displayed; if @var{lines} is higher than the number of lines between
21975@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
21976are displayed.
21977@item @var{mode}
21978is either 0 (meaning only disassembly) or 1 (meaning mixed source and
21979disassembly).
21980@end table
21981
21982@subsubheading Result
21983
21984The output for each instruction is composed of four fields:
21985
21986@itemize @bullet
21987@item Address
21988@item Func-name
21989@item Offset
21990@item Instruction
21991@end itemize
21992
21993Note that whatever included in the instruction field, is not manipulated
d3e8051b 21994directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
922fbb7b
AC
21995
21996@subsubheading @value{GDBN} Command
21997
a2c02241 21998There's no direct mapping from this command to the CLI.
922fbb7b
AC
21999
22000@subsubheading Example
22001
a2c02241
NR
22002Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
22003
922fbb7b 22004@smallexample
594fe323 22005(gdb)
a2c02241
NR
22006-data-disassemble -s $pc -e "$pc + 20" -- 0
22007^done,
22008asm_insns=[
22009@{address="0x000107c0",func-name="main",offset="4",
22010inst="mov 2, %o0"@},
22011@{address="0x000107c4",func-name="main",offset="8",
22012inst="sethi %hi(0x11800), %o2"@},
22013@{address="0x000107c8",func-name="main",offset="12",
22014inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
22015@{address="0x000107cc",func-name="main",offset="16",
22016inst="sethi %hi(0x11800), %o2"@},
22017@{address="0x000107d0",func-name="main",offset="20",
22018inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 22019(gdb)
a2c02241
NR
22020@end smallexample
22021
22022Disassemble the whole @code{main} function. Line 32 is part of
22023@code{main}.
22024
22025@smallexample
22026-data-disassemble -f basics.c -l 32 -- 0
22027^done,asm_insns=[
22028@{address="0x000107bc",func-name="main",offset="0",
22029inst="save %sp, -112, %sp"@},
22030@{address="0x000107c0",func-name="main",offset="4",
22031inst="mov 2, %o0"@},
22032@{address="0x000107c4",func-name="main",offset="8",
22033inst="sethi %hi(0x11800), %o2"@},
22034[@dots{}]
22035@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
22036@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 22037(gdb)
922fbb7b
AC
22038@end smallexample
22039
a2c02241 22040Disassemble 3 instructions from the start of @code{main}:
922fbb7b 22041
a2c02241 22042@smallexample
594fe323 22043(gdb)
a2c02241
NR
22044-data-disassemble -f basics.c -l 32 -n 3 -- 0
22045^done,asm_insns=[
22046@{address="0x000107bc",func-name="main",offset="0",
22047inst="save %sp, -112, %sp"@},
22048@{address="0x000107c0",func-name="main",offset="4",
22049inst="mov 2, %o0"@},
22050@{address="0x000107c4",func-name="main",offset="8",
22051inst="sethi %hi(0x11800), %o2"@}]
594fe323 22052(gdb)
a2c02241
NR
22053@end smallexample
22054
22055Disassemble 3 instructions from the start of @code{main} in mixed mode:
22056
22057@smallexample
594fe323 22058(gdb)
a2c02241
NR
22059-data-disassemble -f basics.c -l 32 -n 3 -- 1
22060^done,asm_insns=[
22061src_and_asm_line=@{line="31",
22062file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
22063 testsuite/gdb.mi/basics.c",line_asm_insn=[
22064@{address="0x000107bc",func-name="main",offset="0",
22065inst="save %sp, -112, %sp"@}]@},
22066src_and_asm_line=@{line="32",
22067file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
22068 testsuite/gdb.mi/basics.c",line_asm_insn=[
22069@{address="0x000107c0",func-name="main",offset="4",
22070inst="mov 2, %o0"@},
22071@{address="0x000107c4",func-name="main",offset="8",
22072inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 22073(gdb)
a2c02241
NR
22074@end smallexample
22075
22076
22077@subheading The @code{-data-evaluate-expression} Command
22078@findex -data-evaluate-expression
922fbb7b
AC
22079
22080@subsubheading Synopsis
22081
22082@smallexample
a2c02241 22083 -data-evaluate-expression @var{expr}
922fbb7b
AC
22084@end smallexample
22085
a2c02241
NR
22086Evaluate @var{expr} as an expression. The expression could contain an
22087inferior function call. The function call will execute synchronously.
22088If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
22089
22090@subsubheading @value{GDBN} Command
22091
a2c02241
NR
22092The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
22093@samp{call}. In @code{gdbtk} only, there's a corresponding
22094@samp{gdb_eval} command.
922fbb7b
AC
22095
22096@subsubheading Example
22097
a2c02241
NR
22098In the following example, the numbers that precede the commands are the
22099@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
22100Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
22101output.
22102
922fbb7b 22103@smallexample
a2c02241
NR
22104211-data-evaluate-expression A
22105211^done,value="1"
594fe323 22106(gdb)
a2c02241
NR
22107311-data-evaluate-expression &A
22108311^done,value="0xefffeb7c"
594fe323 22109(gdb)
a2c02241
NR
22110411-data-evaluate-expression A+3
22111411^done,value="4"
594fe323 22112(gdb)
a2c02241
NR
22113511-data-evaluate-expression "A + 3"
22114511^done,value="4"
594fe323 22115(gdb)
a2c02241 22116@end smallexample
922fbb7b
AC
22117
22118
a2c02241
NR
22119@subheading The @code{-data-list-changed-registers} Command
22120@findex -data-list-changed-registers
922fbb7b
AC
22121
22122@subsubheading Synopsis
22123
22124@smallexample
a2c02241 22125 -data-list-changed-registers
922fbb7b
AC
22126@end smallexample
22127
a2c02241 22128Display a list of the registers that have changed.
922fbb7b
AC
22129
22130@subsubheading @value{GDBN} Command
22131
a2c02241
NR
22132@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
22133has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
22134
22135@subsubheading Example
922fbb7b 22136
a2c02241 22137On a PPC MBX board:
922fbb7b
AC
22138
22139@smallexample
594fe323 22140(gdb)
a2c02241
NR
22141-exec-continue
22142^running
922fbb7b 22143
594fe323 22144(gdb)
a47ec5fe
AR
22145*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
22146func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
22147line="5"@}
594fe323 22148(gdb)
a2c02241
NR
22149-data-list-changed-registers
22150^done,changed-registers=["0","1","2","4","5","6","7","8","9",
22151"10","11","13","14","15","16","17","18","19","20","21","22","23",
22152"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 22153(gdb)
a2c02241 22154@end smallexample
922fbb7b
AC
22155
22156
a2c02241
NR
22157@subheading The @code{-data-list-register-names} Command
22158@findex -data-list-register-names
922fbb7b
AC
22159
22160@subsubheading Synopsis
22161
22162@smallexample
a2c02241 22163 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
22164@end smallexample
22165
a2c02241
NR
22166Show a list of register names for the current target. If no arguments
22167are given, it shows a list of the names of all the registers. If
22168integer numbers are given as arguments, it will print a list of the
22169names of the registers corresponding to the arguments. To ensure
22170consistency between a register name and its number, the output list may
22171include empty register names.
922fbb7b
AC
22172
22173@subsubheading @value{GDBN} Command
22174
a2c02241
NR
22175@value{GDBN} does not have a command which corresponds to
22176@samp{-data-list-register-names}. In @code{gdbtk} there is a
22177corresponding command @samp{gdb_regnames}.
922fbb7b
AC
22178
22179@subsubheading Example
922fbb7b 22180
a2c02241
NR
22181For the PPC MBX board:
22182@smallexample
594fe323 22183(gdb)
a2c02241
NR
22184-data-list-register-names
22185^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
22186"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
22187"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
22188"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
22189"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
22190"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
22191"", "pc","ps","cr","lr","ctr","xer"]
594fe323 22192(gdb)
a2c02241
NR
22193-data-list-register-names 1 2 3
22194^done,register-names=["r1","r2","r3"]
594fe323 22195(gdb)
a2c02241 22196@end smallexample
922fbb7b 22197
a2c02241
NR
22198@subheading The @code{-data-list-register-values} Command
22199@findex -data-list-register-values
922fbb7b
AC
22200
22201@subsubheading Synopsis
22202
22203@smallexample
a2c02241 22204 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
22205@end smallexample
22206
a2c02241
NR
22207Display the registers' contents. @var{fmt} is the format according to
22208which the registers' contents are to be returned, followed by an optional
22209list of numbers specifying the registers to display. A missing list of
22210numbers indicates that the contents of all the registers must be returned.
22211
22212Allowed formats for @var{fmt} are:
22213
22214@table @code
22215@item x
22216Hexadecimal
22217@item o
22218Octal
22219@item t
22220Binary
22221@item d
22222Decimal
22223@item r
22224Raw
22225@item N
22226Natural
22227@end table
922fbb7b
AC
22228
22229@subsubheading @value{GDBN} Command
22230
a2c02241
NR
22231The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
22232all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
22233
22234@subsubheading Example
922fbb7b 22235
a2c02241
NR
22236For a PPC MBX board (note: line breaks are for readability only, they
22237don't appear in the actual output):
22238
22239@smallexample
594fe323 22240(gdb)
a2c02241
NR
22241-data-list-register-values r 64 65
22242^done,register-values=[@{number="64",value="0xfe00a300"@},
22243@{number="65",value="0x00029002"@}]
594fe323 22244(gdb)
a2c02241
NR
22245-data-list-register-values x
22246^done,register-values=[@{number="0",value="0xfe0043c8"@},
22247@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
22248@{number="3",value="0x0"@},@{number="4",value="0xa"@},
22249@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
22250@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
22251@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
22252@{number="11",value="0x1"@},@{number="12",value="0x0"@},
22253@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
22254@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
22255@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
22256@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
22257@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
22258@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
22259@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
22260@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
22261@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
22262@{number="31",value="0x0"@},@{number="32",value="0x0"@},
22263@{number="33",value="0x0"@},@{number="34",value="0x0"@},
22264@{number="35",value="0x0"@},@{number="36",value="0x0"@},
22265@{number="37",value="0x0"@},@{number="38",value="0x0"@},
22266@{number="39",value="0x0"@},@{number="40",value="0x0"@},
22267@{number="41",value="0x0"@},@{number="42",value="0x0"@},
22268@{number="43",value="0x0"@},@{number="44",value="0x0"@},
22269@{number="45",value="0x0"@},@{number="46",value="0x0"@},
22270@{number="47",value="0x0"@},@{number="48",value="0x0"@},
22271@{number="49",value="0x0"@},@{number="50",value="0x0"@},
22272@{number="51",value="0x0"@},@{number="52",value="0x0"@},
22273@{number="53",value="0x0"@},@{number="54",value="0x0"@},
22274@{number="55",value="0x0"@},@{number="56",value="0x0"@},
22275@{number="57",value="0x0"@},@{number="58",value="0x0"@},
22276@{number="59",value="0x0"@},@{number="60",value="0x0"@},
22277@{number="61",value="0x0"@},@{number="62",value="0x0"@},
22278@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
22279@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
22280@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
22281@{number="69",value="0x20002b03"@}]
594fe323 22282(gdb)
a2c02241 22283@end smallexample
922fbb7b 22284
a2c02241
NR
22285
22286@subheading The @code{-data-read-memory} Command
22287@findex -data-read-memory
922fbb7b
AC
22288
22289@subsubheading Synopsis
22290
22291@smallexample
a2c02241
NR
22292 -data-read-memory [ -o @var{byte-offset} ]
22293 @var{address} @var{word-format} @var{word-size}
22294 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
22295@end smallexample
22296
a2c02241
NR
22297@noindent
22298where:
922fbb7b 22299
a2c02241
NR
22300@table @samp
22301@item @var{address}
22302An expression specifying the address of the first memory word to be
22303read. Complex expressions containing embedded white space should be
22304quoted using the C convention.
922fbb7b 22305
a2c02241
NR
22306@item @var{word-format}
22307The format to be used to print the memory words. The notation is the
22308same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 22309,Output Formats}).
922fbb7b 22310
a2c02241
NR
22311@item @var{word-size}
22312The size of each memory word in bytes.
922fbb7b 22313
a2c02241
NR
22314@item @var{nr-rows}
22315The number of rows in the output table.
922fbb7b 22316
a2c02241
NR
22317@item @var{nr-cols}
22318The number of columns in the output table.
922fbb7b 22319
a2c02241
NR
22320@item @var{aschar}
22321If present, indicates that each row should include an @sc{ascii} dump. The
22322value of @var{aschar} is used as a padding character when a byte is not a
22323member of the printable @sc{ascii} character set (printable @sc{ascii}
22324characters are those whose code is between 32 and 126, inclusively).
922fbb7b 22325
a2c02241
NR
22326@item @var{byte-offset}
22327An offset to add to the @var{address} before fetching memory.
22328@end table
922fbb7b 22329
a2c02241
NR
22330This command displays memory contents as a table of @var{nr-rows} by
22331@var{nr-cols} words, each word being @var{word-size} bytes. In total,
22332@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
22333(returned as @samp{total-bytes}). Should less than the requested number
22334of bytes be returned by the target, the missing words are identified
22335using @samp{N/A}. The number of bytes read from the target is returned
22336in @samp{nr-bytes} and the starting address used to read memory in
22337@samp{addr}.
22338
22339The address of the next/previous row or page is available in
22340@samp{next-row} and @samp{prev-row}, @samp{next-page} and
22341@samp{prev-page}.
922fbb7b
AC
22342
22343@subsubheading @value{GDBN} Command
22344
a2c02241
NR
22345The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
22346@samp{gdb_get_mem} memory read command.
922fbb7b
AC
22347
22348@subsubheading Example
32e7087d 22349
a2c02241
NR
22350Read six bytes of memory starting at @code{bytes+6} but then offset by
22351@code{-6} bytes. Format as three rows of two columns. One byte per
22352word. Display each word in hex.
32e7087d
JB
22353
22354@smallexample
594fe323 22355(gdb)
a2c02241
NR
223569-data-read-memory -o -6 -- bytes+6 x 1 3 2
223579^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
22358next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
22359prev-page="0x0000138a",memory=[
22360@{addr="0x00001390",data=["0x00","0x01"]@},
22361@{addr="0x00001392",data=["0x02","0x03"]@},
22362@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 22363(gdb)
32e7087d
JB
22364@end smallexample
22365
a2c02241
NR
22366Read two bytes of memory starting at address @code{shorts + 64} and
22367display as a single word formatted in decimal.
32e7087d 22368
32e7087d 22369@smallexample
594fe323 22370(gdb)
a2c02241
NR
223715-data-read-memory shorts+64 d 2 1 1
223725^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
22373next-row="0x00001512",prev-row="0x0000150e",
22374next-page="0x00001512",prev-page="0x0000150e",memory=[
22375@{addr="0x00001510",data=["128"]@}]
594fe323 22376(gdb)
32e7087d
JB
22377@end smallexample
22378
a2c02241
NR
22379Read thirty two bytes of memory starting at @code{bytes+16} and format
22380as eight rows of four columns. Include a string encoding with @samp{x}
22381used as the non-printable character.
922fbb7b
AC
22382
22383@smallexample
594fe323 22384(gdb)
a2c02241
NR
223854-data-read-memory bytes+16 x 1 8 4 x
223864^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
22387next-row="0x000013c0",prev-row="0x0000139c",
22388next-page="0x000013c0",prev-page="0x00001380",memory=[
22389@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
22390@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
22391@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
22392@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
22393@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
22394@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
22395@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
22396@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 22397(gdb)
922fbb7b
AC
22398@end smallexample
22399
a2c02241
NR
22400@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22401@node GDB/MI Tracepoint Commands
22402@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 22403
a2c02241 22404The tracepoint commands are not yet implemented.
922fbb7b 22405
a2c02241 22406@c @subheading -trace-actions
922fbb7b 22407
a2c02241 22408@c @subheading -trace-delete
922fbb7b 22409
a2c02241 22410@c @subheading -trace-disable
922fbb7b 22411
a2c02241 22412@c @subheading -trace-dump
922fbb7b 22413
a2c02241 22414@c @subheading -trace-enable
922fbb7b 22415
a2c02241 22416@c @subheading -trace-exists
922fbb7b 22417
a2c02241 22418@c @subheading -trace-find
922fbb7b 22419
a2c02241 22420@c @subheading -trace-frame-number
922fbb7b 22421
a2c02241 22422@c @subheading -trace-info
922fbb7b 22423
a2c02241 22424@c @subheading -trace-insert
922fbb7b 22425
a2c02241 22426@c @subheading -trace-list
922fbb7b 22427
a2c02241 22428@c @subheading -trace-pass-count
922fbb7b 22429
a2c02241 22430@c @subheading -trace-save
922fbb7b 22431
a2c02241 22432@c @subheading -trace-start
922fbb7b 22433
a2c02241 22434@c @subheading -trace-stop
922fbb7b 22435
922fbb7b 22436
a2c02241
NR
22437@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22438@node GDB/MI Symbol Query
22439@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
22440
22441
a2c02241
NR
22442@subheading The @code{-symbol-info-address} Command
22443@findex -symbol-info-address
922fbb7b
AC
22444
22445@subsubheading Synopsis
22446
22447@smallexample
a2c02241 22448 -symbol-info-address @var{symbol}
922fbb7b
AC
22449@end smallexample
22450
a2c02241 22451Describe where @var{symbol} is stored.
922fbb7b
AC
22452
22453@subsubheading @value{GDBN} Command
22454
a2c02241 22455The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
22456
22457@subsubheading Example
22458N.A.
22459
22460
a2c02241
NR
22461@subheading The @code{-symbol-info-file} Command
22462@findex -symbol-info-file
922fbb7b
AC
22463
22464@subsubheading Synopsis
22465
22466@smallexample
a2c02241 22467 -symbol-info-file
922fbb7b
AC
22468@end smallexample
22469
a2c02241 22470Show the file for the symbol.
922fbb7b 22471
a2c02241 22472@subsubheading @value{GDBN} Command
922fbb7b 22473
a2c02241
NR
22474There's no equivalent @value{GDBN} command. @code{gdbtk} has
22475@samp{gdb_find_file}.
922fbb7b
AC
22476
22477@subsubheading Example
22478N.A.
22479
22480
a2c02241
NR
22481@subheading The @code{-symbol-info-function} Command
22482@findex -symbol-info-function
922fbb7b
AC
22483
22484@subsubheading Synopsis
22485
22486@smallexample
a2c02241 22487 -symbol-info-function
922fbb7b
AC
22488@end smallexample
22489
a2c02241 22490Show which function the symbol lives in.
922fbb7b
AC
22491
22492@subsubheading @value{GDBN} Command
22493
a2c02241 22494@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
22495
22496@subsubheading Example
22497N.A.
22498
22499
a2c02241
NR
22500@subheading The @code{-symbol-info-line} Command
22501@findex -symbol-info-line
922fbb7b
AC
22502
22503@subsubheading Synopsis
22504
22505@smallexample
a2c02241 22506 -symbol-info-line
922fbb7b
AC
22507@end smallexample
22508
a2c02241 22509Show the core addresses of the code for a source line.
922fbb7b 22510
a2c02241 22511@subsubheading @value{GDBN} Command
922fbb7b 22512
a2c02241
NR
22513The corresponding @value{GDBN} command is @samp{info line}.
22514@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
22515
22516@subsubheading Example
a2c02241 22517N.A.
922fbb7b
AC
22518
22519
a2c02241
NR
22520@subheading The @code{-symbol-info-symbol} Command
22521@findex -symbol-info-symbol
07f31aa6
DJ
22522
22523@subsubheading Synopsis
22524
a2c02241
NR
22525@smallexample
22526 -symbol-info-symbol @var{addr}
22527@end smallexample
07f31aa6 22528
a2c02241 22529Describe what symbol is at location @var{addr}.
07f31aa6 22530
a2c02241 22531@subsubheading @value{GDBN} Command
07f31aa6 22532
a2c02241 22533The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
22534
22535@subsubheading Example
a2c02241 22536N.A.
07f31aa6
DJ
22537
22538
a2c02241
NR
22539@subheading The @code{-symbol-list-functions} Command
22540@findex -symbol-list-functions
922fbb7b
AC
22541
22542@subsubheading Synopsis
22543
22544@smallexample
a2c02241 22545 -symbol-list-functions
922fbb7b
AC
22546@end smallexample
22547
a2c02241 22548List the functions in the executable.
922fbb7b
AC
22549
22550@subsubheading @value{GDBN} Command
22551
a2c02241
NR
22552@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
22553@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
22554
22555@subsubheading Example
a2c02241 22556N.A.
922fbb7b
AC
22557
22558
a2c02241
NR
22559@subheading The @code{-symbol-list-lines} Command
22560@findex -symbol-list-lines
922fbb7b
AC
22561
22562@subsubheading Synopsis
22563
22564@smallexample
a2c02241 22565 -symbol-list-lines @var{filename}
922fbb7b
AC
22566@end smallexample
22567
a2c02241
NR
22568Print the list of lines that contain code and their associated program
22569addresses for the given source filename. The entries are sorted in
22570ascending PC order.
922fbb7b
AC
22571
22572@subsubheading @value{GDBN} Command
22573
a2c02241 22574There is no corresponding @value{GDBN} command.
922fbb7b
AC
22575
22576@subsubheading Example
a2c02241 22577@smallexample
594fe323 22578(gdb)
a2c02241
NR
22579-symbol-list-lines basics.c
22580^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 22581(gdb)
a2c02241 22582@end smallexample
922fbb7b
AC
22583
22584
a2c02241
NR
22585@subheading The @code{-symbol-list-types} Command
22586@findex -symbol-list-types
922fbb7b
AC
22587
22588@subsubheading Synopsis
22589
22590@smallexample
a2c02241 22591 -symbol-list-types
922fbb7b
AC
22592@end smallexample
22593
a2c02241 22594List all the type names.
922fbb7b
AC
22595
22596@subsubheading @value{GDBN} Command
22597
a2c02241
NR
22598The corresponding commands are @samp{info types} in @value{GDBN},
22599@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
22600
22601@subsubheading Example
22602N.A.
22603
22604
a2c02241
NR
22605@subheading The @code{-symbol-list-variables} Command
22606@findex -symbol-list-variables
922fbb7b
AC
22607
22608@subsubheading Synopsis
22609
22610@smallexample
a2c02241 22611 -symbol-list-variables
922fbb7b
AC
22612@end smallexample
22613
a2c02241 22614List all the global and static variable names.
922fbb7b
AC
22615
22616@subsubheading @value{GDBN} Command
22617
a2c02241 22618@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
22619
22620@subsubheading Example
22621N.A.
22622
22623
a2c02241
NR
22624@subheading The @code{-symbol-locate} Command
22625@findex -symbol-locate
922fbb7b
AC
22626
22627@subsubheading Synopsis
22628
22629@smallexample
a2c02241 22630 -symbol-locate
922fbb7b
AC
22631@end smallexample
22632
922fbb7b
AC
22633@subsubheading @value{GDBN} Command
22634
a2c02241 22635@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
22636
22637@subsubheading Example
22638N.A.
22639
22640
a2c02241
NR
22641@subheading The @code{-symbol-type} Command
22642@findex -symbol-type
922fbb7b
AC
22643
22644@subsubheading Synopsis
22645
22646@smallexample
a2c02241 22647 -symbol-type @var{variable}
922fbb7b
AC
22648@end smallexample
22649
a2c02241 22650Show type of @var{variable}.
922fbb7b 22651
a2c02241 22652@subsubheading @value{GDBN} Command
922fbb7b 22653
a2c02241
NR
22654The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
22655@samp{gdb_obj_variable}.
22656
22657@subsubheading Example
22658N.A.
22659
22660
22661@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22662@node GDB/MI File Commands
22663@section @sc{gdb/mi} File Commands
22664
22665This section describes the GDB/MI commands to specify executable file names
22666and to read in and obtain symbol table information.
22667
22668@subheading The @code{-file-exec-and-symbols} Command
22669@findex -file-exec-and-symbols
22670
22671@subsubheading Synopsis
922fbb7b
AC
22672
22673@smallexample
a2c02241 22674 -file-exec-and-symbols @var{file}
922fbb7b
AC
22675@end smallexample
22676
a2c02241
NR
22677Specify the executable file to be debugged. This file is the one from
22678which the symbol table is also read. If no file is specified, the
22679command clears the executable and symbol information. If breakpoints
22680are set when using this command with no arguments, @value{GDBN} will produce
22681error messages. Otherwise, no output is produced, except a completion
22682notification.
22683
922fbb7b
AC
22684@subsubheading @value{GDBN} Command
22685
a2c02241 22686The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
22687
22688@subsubheading Example
22689
22690@smallexample
594fe323 22691(gdb)
a2c02241
NR
22692-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
22693^done
594fe323 22694(gdb)
922fbb7b
AC
22695@end smallexample
22696
922fbb7b 22697
a2c02241
NR
22698@subheading The @code{-file-exec-file} Command
22699@findex -file-exec-file
922fbb7b
AC
22700
22701@subsubheading Synopsis
22702
22703@smallexample
a2c02241 22704 -file-exec-file @var{file}
922fbb7b
AC
22705@end smallexample
22706
a2c02241
NR
22707Specify the executable file to be debugged. Unlike
22708@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
22709from this file. If used without argument, @value{GDBN} clears the information
22710about the executable file. No output is produced, except a completion
22711notification.
922fbb7b 22712
a2c02241
NR
22713@subsubheading @value{GDBN} Command
22714
22715The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
22716
22717@subsubheading Example
a2c02241
NR
22718
22719@smallexample
594fe323 22720(gdb)
a2c02241
NR
22721-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
22722^done
594fe323 22723(gdb)
a2c02241 22724@end smallexample
922fbb7b
AC
22725
22726
a2c02241
NR
22727@subheading The @code{-file-list-exec-sections} Command
22728@findex -file-list-exec-sections
922fbb7b
AC
22729
22730@subsubheading Synopsis
22731
22732@smallexample
a2c02241 22733 -file-list-exec-sections
922fbb7b
AC
22734@end smallexample
22735
a2c02241
NR
22736List the sections of the current executable file.
22737
922fbb7b
AC
22738@subsubheading @value{GDBN} Command
22739
a2c02241
NR
22740The @value{GDBN} command @samp{info file} shows, among the rest, the same
22741information as this command. @code{gdbtk} has a corresponding command
22742@samp{gdb_load_info}.
922fbb7b
AC
22743
22744@subsubheading Example
22745N.A.
22746
22747
a2c02241
NR
22748@subheading The @code{-file-list-exec-source-file} Command
22749@findex -file-list-exec-source-file
922fbb7b
AC
22750
22751@subsubheading Synopsis
22752
22753@smallexample
a2c02241 22754 -file-list-exec-source-file
922fbb7b
AC
22755@end smallexample
22756
a2c02241 22757List the line number, the current source file, and the absolute path
44288b44
NR
22758to the current source file for the current executable. The macro
22759information field has a value of @samp{1} or @samp{0} depending on
22760whether or not the file includes preprocessor macro information.
922fbb7b
AC
22761
22762@subsubheading @value{GDBN} Command
22763
a2c02241 22764The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
22765
22766@subsubheading Example
22767
922fbb7b 22768@smallexample
594fe323 22769(gdb)
a2c02241 22770123-file-list-exec-source-file
44288b44 22771123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 22772(gdb)
922fbb7b
AC
22773@end smallexample
22774
22775
a2c02241
NR
22776@subheading The @code{-file-list-exec-source-files} Command
22777@findex -file-list-exec-source-files
922fbb7b
AC
22778
22779@subsubheading Synopsis
22780
22781@smallexample
a2c02241 22782 -file-list-exec-source-files
922fbb7b
AC
22783@end smallexample
22784
a2c02241
NR
22785List the source files for the current executable.
22786
3f94c067
BW
22787It will always output the filename, but only when @value{GDBN} can find
22788the absolute file name of a source file, will it output the fullname.
922fbb7b
AC
22789
22790@subsubheading @value{GDBN} Command
22791
a2c02241
NR
22792The @value{GDBN} equivalent is @samp{info sources}.
22793@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
22794
22795@subsubheading Example
922fbb7b 22796@smallexample
594fe323 22797(gdb)
a2c02241
NR
22798-file-list-exec-source-files
22799^done,files=[
22800@{file=foo.c,fullname=/home/foo.c@},
22801@{file=/home/bar.c,fullname=/home/bar.c@},
22802@{file=gdb_could_not_find_fullpath.c@}]
594fe323 22803(gdb)
922fbb7b
AC
22804@end smallexample
22805
a2c02241
NR
22806@subheading The @code{-file-list-shared-libraries} Command
22807@findex -file-list-shared-libraries
922fbb7b 22808
a2c02241 22809@subsubheading Synopsis
922fbb7b 22810
a2c02241
NR
22811@smallexample
22812 -file-list-shared-libraries
22813@end smallexample
922fbb7b 22814
a2c02241 22815List the shared libraries in the program.
922fbb7b 22816
a2c02241 22817@subsubheading @value{GDBN} Command
922fbb7b 22818
a2c02241 22819The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 22820
a2c02241
NR
22821@subsubheading Example
22822N.A.
922fbb7b
AC
22823
22824
a2c02241
NR
22825@subheading The @code{-file-list-symbol-files} Command
22826@findex -file-list-symbol-files
922fbb7b 22827
a2c02241 22828@subsubheading Synopsis
922fbb7b 22829
a2c02241
NR
22830@smallexample
22831 -file-list-symbol-files
22832@end smallexample
922fbb7b 22833
a2c02241 22834List symbol files.
922fbb7b 22835
a2c02241 22836@subsubheading @value{GDBN} Command
922fbb7b 22837
a2c02241 22838The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 22839
a2c02241
NR
22840@subsubheading Example
22841N.A.
922fbb7b 22842
922fbb7b 22843
a2c02241
NR
22844@subheading The @code{-file-symbol-file} Command
22845@findex -file-symbol-file
922fbb7b 22846
a2c02241 22847@subsubheading Synopsis
922fbb7b 22848
a2c02241
NR
22849@smallexample
22850 -file-symbol-file @var{file}
22851@end smallexample
922fbb7b 22852
a2c02241
NR
22853Read symbol table info from the specified @var{file} argument. When
22854used without arguments, clears @value{GDBN}'s symbol table info. No output is
22855produced, except for a completion notification.
922fbb7b 22856
a2c02241 22857@subsubheading @value{GDBN} Command
922fbb7b 22858
a2c02241 22859The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 22860
a2c02241 22861@subsubheading Example
922fbb7b 22862
a2c02241 22863@smallexample
594fe323 22864(gdb)
a2c02241
NR
22865-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
22866^done
594fe323 22867(gdb)
a2c02241 22868@end smallexample
922fbb7b 22869
a2c02241 22870@ignore
a2c02241
NR
22871@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22872@node GDB/MI Memory Overlay Commands
22873@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 22874
a2c02241 22875The memory overlay commands are not implemented.
922fbb7b 22876
a2c02241 22877@c @subheading -overlay-auto
922fbb7b 22878
a2c02241 22879@c @subheading -overlay-list-mapping-state
922fbb7b 22880
a2c02241 22881@c @subheading -overlay-list-overlays
922fbb7b 22882
a2c02241 22883@c @subheading -overlay-map
922fbb7b 22884
a2c02241 22885@c @subheading -overlay-off
922fbb7b 22886
a2c02241 22887@c @subheading -overlay-on
922fbb7b 22888
a2c02241 22889@c @subheading -overlay-unmap
922fbb7b 22890
a2c02241
NR
22891@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22892@node GDB/MI Signal Handling Commands
22893@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 22894
a2c02241 22895Signal handling commands are not implemented.
922fbb7b 22896
a2c02241 22897@c @subheading -signal-handle
922fbb7b 22898
a2c02241 22899@c @subheading -signal-list-handle-actions
922fbb7b 22900
a2c02241
NR
22901@c @subheading -signal-list-signal-types
22902@end ignore
922fbb7b 22903
922fbb7b 22904
a2c02241
NR
22905@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22906@node GDB/MI Target Manipulation
22907@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
22908
22909
a2c02241
NR
22910@subheading The @code{-target-attach} Command
22911@findex -target-attach
922fbb7b
AC
22912
22913@subsubheading Synopsis
22914
22915@smallexample
c3b108f7 22916 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
22917@end smallexample
22918
c3b108f7
VP
22919Attach to a process @var{pid} or a file @var{file} outside of
22920@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
22921group, the id previously returned by
22922@samp{-list-thread-groups --available} must be used.
922fbb7b 22923
79a6e687 22924@subsubheading @value{GDBN} Command
922fbb7b 22925
a2c02241 22926The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 22927
a2c02241 22928@subsubheading Example
b56e7235
VP
22929@smallexample
22930(gdb)
22931-target-attach 34
22932=thread-created,id="1"
5ae4183a 22933*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
22934^done
22935(gdb)
22936@end smallexample
a2c02241
NR
22937
22938@subheading The @code{-target-compare-sections} Command
22939@findex -target-compare-sections
922fbb7b
AC
22940
22941@subsubheading Synopsis
22942
22943@smallexample
a2c02241 22944 -target-compare-sections [ @var{section} ]
922fbb7b
AC
22945@end smallexample
22946
a2c02241
NR
22947Compare data of section @var{section} on target to the exec file.
22948Without the argument, all sections are compared.
922fbb7b 22949
a2c02241 22950@subsubheading @value{GDBN} Command
922fbb7b 22951
a2c02241 22952The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 22953
a2c02241
NR
22954@subsubheading Example
22955N.A.
22956
22957
22958@subheading The @code{-target-detach} Command
22959@findex -target-detach
922fbb7b
AC
22960
22961@subsubheading Synopsis
22962
22963@smallexample
c3b108f7 22964 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
22965@end smallexample
22966
a2c02241 22967Detach from the remote target which normally resumes its execution.
c3b108f7
VP
22968If either @var{pid} or @var{gid} is specified, detaches from either
22969the specified process, or specified thread group. There's no output.
a2c02241 22970
79a6e687 22971@subsubheading @value{GDBN} Command
a2c02241
NR
22972
22973The corresponding @value{GDBN} command is @samp{detach}.
22974
22975@subsubheading Example
922fbb7b
AC
22976
22977@smallexample
594fe323 22978(gdb)
a2c02241
NR
22979-target-detach
22980^done
594fe323 22981(gdb)
922fbb7b
AC
22982@end smallexample
22983
22984
a2c02241
NR
22985@subheading The @code{-target-disconnect} Command
22986@findex -target-disconnect
922fbb7b
AC
22987
22988@subsubheading Synopsis
22989
123dc839 22990@smallexample
a2c02241 22991 -target-disconnect
123dc839 22992@end smallexample
922fbb7b 22993
a2c02241
NR
22994Disconnect from the remote target. There's no output and the target is
22995generally not resumed.
22996
79a6e687 22997@subsubheading @value{GDBN} Command
a2c02241
NR
22998
22999The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
23000
23001@subsubheading Example
922fbb7b
AC
23002
23003@smallexample
594fe323 23004(gdb)
a2c02241
NR
23005-target-disconnect
23006^done
594fe323 23007(gdb)
922fbb7b
AC
23008@end smallexample
23009
23010
a2c02241
NR
23011@subheading The @code{-target-download} Command
23012@findex -target-download
922fbb7b
AC
23013
23014@subsubheading Synopsis
23015
23016@smallexample
a2c02241 23017 -target-download
922fbb7b
AC
23018@end smallexample
23019
a2c02241
NR
23020Loads the executable onto the remote target.
23021It prints out an update message every half second, which includes the fields:
23022
23023@table @samp
23024@item section
23025The name of the section.
23026@item section-sent
23027The size of what has been sent so far for that section.
23028@item section-size
23029The size of the section.
23030@item total-sent
23031The total size of what was sent so far (the current and the previous sections).
23032@item total-size
23033The size of the overall executable to download.
23034@end table
23035
23036@noindent
23037Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
23038@sc{gdb/mi} Output Syntax}).
23039
23040In addition, it prints the name and size of the sections, as they are
23041downloaded. These messages include the following fields:
23042
23043@table @samp
23044@item section
23045The name of the section.
23046@item section-size
23047The size of the section.
23048@item total-size
23049The size of the overall executable to download.
23050@end table
23051
23052@noindent
23053At the end, a summary is printed.
23054
23055@subsubheading @value{GDBN} Command
23056
23057The corresponding @value{GDBN} command is @samp{load}.
23058
23059@subsubheading Example
23060
23061Note: each status message appears on a single line. Here the messages
23062have been broken down so that they can fit onto a page.
922fbb7b
AC
23063
23064@smallexample
594fe323 23065(gdb)
a2c02241
NR
23066-target-download
23067+download,@{section=".text",section-size="6668",total-size="9880"@}
23068+download,@{section=".text",section-sent="512",section-size="6668",
23069total-sent="512",total-size="9880"@}
23070+download,@{section=".text",section-sent="1024",section-size="6668",
23071total-sent="1024",total-size="9880"@}
23072+download,@{section=".text",section-sent="1536",section-size="6668",
23073total-sent="1536",total-size="9880"@}
23074+download,@{section=".text",section-sent="2048",section-size="6668",
23075total-sent="2048",total-size="9880"@}
23076+download,@{section=".text",section-sent="2560",section-size="6668",
23077total-sent="2560",total-size="9880"@}
23078+download,@{section=".text",section-sent="3072",section-size="6668",
23079total-sent="3072",total-size="9880"@}
23080+download,@{section=".text",section-sent="3584",section-size="6668",
23081total-sent="3584",total-size="9880"@}
23082+download,@{section=".text",section-sent="4096",section-size="6668",
23083total-sent="4096",total-size="9880"@}
23084+download,@{section=".text",section-sent="4608",section-size="6668",
23085total-sent="4608",total-size="9880"@}
23086+download,@{section=".text",section-sent="5120",section-size="6668",
23087total-sent="5120",total-size="9880"@}
23088+download,@{section=".text",section-sent="5632",section-size="6668",
23089total-sent="5632",total-size="9880"@}
23090+download,@{section=".text",section-sent="6144",section-size="6668",
23091total-sent="6144",total-size="9880"@}
23092+download,@{section=".text",section-sent="6656",section-size="6668",
23093total-sent="6656",total-size="9880"@}
23094+download,@{section=".init",section-size="28",total-size="9880"@}
23095+download,@{section=".fini",section-size="28",total-size="9880"@}
23096+download,@{section=".data",section-size="3156",total-size="9880"@}
23097+download,@{section=".data",section-sent="512",section-size="3156",
23098total-sent="7236",total-size="9880"@}
23099+download,@{section=".data",section-sent="1024",section-size="3156",
23100total-sent="7748",total-size="9880"@}
23101+download,@{section=".data",section-sent="1536",section-size="3156",
23102total-sent="8260",total-size="9880"@}
23103+download,@{section=".data",section-sent="2048",section-size="3156",
23104total-sent="8772",total-size="9880"@}
23105+download,@{section=".data",section-sent="2560",section-size="3156",
23106total-sent="9284",total-size="9880"@}
23107+download,@{section=".data",section-sent="3072",section-size="3156",
23108total-sent="9796",total-size="9880"@}
23109^done,address="0x10004",load-size="9880",transfer-rate="6586",
23110write-rate="429"
594fe323 23111(gdb)
922fbb7b
AC
23112@end smallexample
23113
23114
a2c02241
NR
23115@subheading The @code{-target-exec-status} Command
23116@findex -target-exec-status
922fbb7b
AC
23117
23118@subsubheading Synopsis
23119
23120@smallexample
a2c02241 23121 -target-exec-status
922fbb7b
AC
23122@end smallexample
23123
a2c02241
NR
23124Provide information on the state of the target (whether it is running or
23125not, for instance).
922fbb7b 23126
a2c02241 23127@subsubheading @value{GDBN} Command
922fbb7b 23128
a2c02241
NR
23129There's no equivalent @value{GDBN} command.
23130
23131@subsubheading Example
23132N.A.
922fbb7b 23133
a2c02241
NR
23134
23135@subheading The @code{-target-list-available-targets} Command
23136@findex -target-list-available-targets
922fbb7b
AC
23137
23138@subsubheading Synopsis
23139
23140@smallexample
a2c02241 23141 -target-list-available-targets
922fbb7b
AC
23142@end smallexample
23143
a2c02241 23144List the possible targets to connect to.
922fbb7b 23145
a2c02241 23146@subsubheading @value{GDBN} Command
922fbb7b 23147
a2c02241 23148The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 23149
a2c02241
NR
23150@subsubheading Example
23151N.A.
23152
23153
23154@subheading The @code{-target-list-current-targets} Command
23155@findex -target-list-current-targets
922fbb7b
AC
23156
23157@subsubheading Synopsis
23158
23159@smallexample
a2c02241 23160 -target-list-current-targets
922fbb7b
AC
23161@end smallexample
23162
a2c02241 23163Describe the current target.
922fbb7b 23164
a2c02241 23165@subsubheading @value{GDBN} Command
922fbb7b 23166
a2c02241
NR
23167The corresponding information is printed by @samp{info file} (among
23168other things).
922fbb7b 23169
a2c02241
NR
23170@subsubheading Example
23171N.A.
23172
23173
23174@subheading The @code{-target-list-parameters} Command
23175@findex -target-list-parameters
922fbb7b
AC
23176
23177@subsubheading Synopsis
23178
23179@smallexample
a2c02241 23180 -target-list-parameters
922fbb7b
AC
23181@end smallexample
23182
a2c02241
NR
23183@c ????
23184
23185@subsubheading @value{GDBN} Command
23186
23187No equivalent.
922fbb7b
AC
23188
23189@subsubheading Example
a2c02241
NR
23190N.A.
23191
23192
23193@subheading The @code{-target-select} Command
23194@findex -target-select
23195
23196@subsubheading Synopsis
922fbb7b
AC
23197
23198@smallexample
a2c02241 23199 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
23200@end smallexample
23201
a2c02241 23202Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 23203
a2c02241
NR
23204@table @samp
23205@item @var{type}
75c99385 23206The type of target, for instance @samp{remote}, etc.
a2c02241
NR
23207@item @var{parameters}
23208Device names, host names and the like. @xref{Target Commands, ,
79a6e687 23209Commands for Managing Targets}, for more details.
a2c02241
NR
23210@end table
23211
23212The output is a connection notification, followed by the address at
23213which the target program is, in the following form:
922fbb7b
AC
23214
23215@smallexample
a2c02241
NR
23216^connected,addr="@var{address}",func="@var{function name}",
23217 args=[@var{arg list}]
922fbb7b
AC
23218@end smallexample
23219
a2c02241
NR
23220@subsubheading @value{GDBN} Command
23221
23222The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
23223
23224@subsubheading Example
922fbb7b 23225
265eeb58 23226@smallexample
594fe323 23227(gdb)
75c99385 23228-target-select remote /dev/ttya
a2c02241 23229^connected,addr="0xfe00a300",func="??",args=[]
594fe323 23230(gdb)
265eeb58 23231@end smallexample
ef21caaf 23232
a6b151f1
DJ
23233@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23234@node GDB/MI File Transfer Commands
23235@section @sc{gdb/mi} File Transfer Commands
23236
23237
23238@subheading The @code{-target-file-put} Command
23239@findex -target-file-put
23240
23241@subsubheading Synopsis
23242
23243@smallexample
23244 -target-file-put @var{hostfile} @var{targetfile}
23245@end smallexample
23246
23247Copy file @var{hostfile} from the host system (the machine running
23248@value{GDBN}) to @var{targetfile} on the target system.
23249
23250@subsubheading @value{GDBN} Command
23251
23252The corresponding @value{GDBN} command is @samp{remote put}.
23253
23254@subsubheading Example
23255
23256@smallexample
23257(gdb)
23258-target-file-put localfile remotefile
23259^done
23260(gdb)
23261@end smallexample
23262
23263
1763a388 23264@subheading The @code{-target-file-get} Command
a6b151f1
DJ
23265@findex -target-file-get
23266
23267@subsubheading Synopsis
23268
23269@smallexample
23270 -target-file-get @var{targetfile} @var{hostfile}
23271@end smallexample
23272
23273Copy file @var{targetfile} from the target system to @var{hostfile}
23274on the host system.
23275
23276@subsubheading @value{GDBN} Command
23277
23278The corresponding @value{GDBN} command is @samp{remote get}.
23279
23280@subsubheading Example
23281
23282@smallexample
23283(gdb)
23284-target-file-get remotefile localfile
23285^done
23286(gdb)
23287@end smallexample
23288
23289
23290@subheading The @code{-target-file-delete} Command
23291@findex -target-file-delete
23292
23293@subsubheading Synopsis
23294
23295@smallexample
23296 -target-file-delete @var{targetfile}
23297@end smallexample
23298
23299Delete @var{targetfile} from the target system.
23300
23301@subsubheading @value{GDBN} Command
23302
23303The corresponding @value{GDBN} command is @samp{remote delete}.
23304
23305@subsubheading Example
23306
23307@smallexample
23308(gdb)
23309-target-file-delete remotefile
23310^done
23311(gdb)
23312@end smallexample
23313
23314
ef21caaf
NR
23315@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23316@node GDB/MI Miscellaneous Commands
23317@section Miscellaneous @sc{gdb/mi} Commands
23318
23319@c @subheading -gdb-complete
23320
23321@subheading The @code{-gdb-exit} Command
23322@findex -gdb-exit
23323
23324@subsubheading Synopsis
23325
23326@smallexample
23327 -gdb-exit
23328@end smallexample
23329
23330Exit @value{GDBN} immediately.
23331
23332@subsubheading @value{GDBN} Command
23333
23334Approximately corresponds to @samp{quit}.
23335
23336@subsubheading Example
23337
23338@smallexample
594fe323 23339(gdb)
ef21caaf
NR
23340-gdb-exit
23341^exit
23342@end smallexample
23343
a2c02241
NR
23344
23345@subheading The @code{-exec-abort} Command
23346@findex -exec-abort
23347
23348@subsubheading Synopsis
23349
23350@smallexample
23351 -exec-abort
23352@end smallexample
23353
23354Kill the inferior running program.
23355
23356@subsubheading @value{GDBN} Command
23357
23358The corresponding @value{GDBN} command is @samp{kill}.
23359
23360@subsubheading Example
23361N.A.
23362
23363
ef21caaf
NR
23364@subheading The @code{-gdb-set} Command
23365@findex -gdb-set
23366
23367@subsubheading Synopsis
23368
23369@smallexample
23370 -gdb-set
23371@end smallexample
23372
23373Set an internal @value{GDBN} variable.
23374@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
23375
23376@subsubheading @value{GDBN} Command
23377
23378The corresponding @value{GDBN} command is @samp{set}.
23379
23380@subsubheading Example
23381
23382@smallexample
594fe323 23383(gdb)
ef21caaf
NR
23384-gdb-set $foo=3
23385^done
594fe323 23386(gdb)
ef21caaf
NR
23387@end smallexample
23388
23389
23390@subheading The @code{-gdb-show} Command
23391@findex -gdb-show
23392
23393@subsubheading Synopsis
23394
23395@smallexample
23396 -gdb-show
23397@end smallexample
23398
23399Show the current value of a @value{GDBN} variable.
23400
79a6e687 23401@subsubheading @value{GDBN} Command
ef21caaf
NR
23402
23403The corresponding @value{GDBN} command is @samp{show}.
23404
23405@subsubheading Example
23406
23407@smallexample
594fe323 23408(gdb)
ef21caaf
NR
23409-gdb-show annotate
23410^done,value="0"
594fe323 23411(gdb)
ef21caaf
NR
23412@end smallexample
23413
23414@c @subheading -gdb-source
23415
23416
23417@subheading The @code{-gdb-version} Command
23418@findex -gdb-version
23419
23420@subsubheading Synopsis
23421
23422@smallexample
23423 -gdb-version
23424@end smallexample
23425
23426Show version information for @value{GDBN}. Used mostly in testing.
23427
23428@subsubheading @value{GDBN} Command
23429
23430The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
23431default shows this information when you start an interactive session.
23432
23433@subsubheading Example
23434
23435@c This example modifies the actual output from GDB to avoid overfull
23436@c box in TeX.
23437@smallexample
594fe323 23438(gdb)
ef21caaf
NR
23439-gdb-version
23440~GNU gdb 5.2.1
23441~Copyright 2000 Free Software Foundation, Inc.
23442~GDB is free software, covered by the GNU General Public License, and
23443~you are welcome to change it and/or distribute copies of it under
23444~ certain conditions.
23445~Type "show copying" to see the conditions.
23446~There is absolutely no warranty for GDB. Type "show warranty" for
23447~ details.
23448~This GDB was configured as
23449 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
23450^done
594fe323 23451(gdb)
ef21caaf
NR
23452@end smallexample
23453
084344da
VP
23454@subheading The @code{-list-features} Command
23455@findex -list-features
23456
23457Returns a list of particular features of the MI protocol that
23458this version of gdb implements. A feature can be a command,
23459or a new field in an output of some command, or even an
23460important bugfix. While a frontend can sometimes detect presence
23461of a feature at runtime, it is easier to perform detection at debugger
23462startup.
23463
23464The command returns a list of strings, with each string naming an
23465available feature. Each returned string is just a name, it does not
23466have any internal structure. The list of possible feature names
23467is given below.
23468
23469Example output:
23470
23471@smallexample
23472(gdb) -list-features
23473^done,result=["feature1","feature2"]
23474@end smallexample
23475
23476The current list of features is:
23477
30e026bb
VP
23478@table @samp
23479@item frozen-varobjs
23480Indicates presence of the @code{-var-set-frozen} command, as well
23481as possible presense of the @code{frozen} field in the output
23482of @code{-varobj-create}.
23483@item pending-breakpoints
23484Indicates presence of the @option{-f} option to the @code{-break-insert} command.
23485@item thread-info
23486Indicates presence of the @code{-thread-info} command.
8b4ed427 23487
30e026bb 23488@end table
084344da 23489
c6ebd6cf
VP
23490@subheading The @code{-list-target-features} Command
23491@findex -list-target-features
23492
23493Returns a list of particular features that are supported by the
23494target. Those features affect the permitted MI commands, but
23495unlike the features reported by the @code{-list-features} command, the
23496features depend on which target GDB is using at the moment. Whenever
23497a target can change, due to commands such as @code{-target-select},
23498@code{-target-attach} or @code{-exec-run}, the list of target features
23499may change, and the frontend should obtain it again.
23500Example output:
23501
23502@smallexample
23503(gdb) -list-features
23504^done,result=["async"]
23505@end smallexample
23506
23507The current list of features is:
23508
23509@table @samp
23510@item async
23511Indicates that the target is capable of asynchronous command
23512execution, which means that @value{GDBN} will accept further commands
23513while the target is running.
23514
23515@end table
23516
c3b108f7
VP
23517@subheading The @code{-list-thread-groups} Command
23518@findex -list-thread-groups
23519
23520@subheading Synopsis
23521
23522@smallexample
23523-list-thread-groups [ --available ] [ @var{group} ]
23524@end smallexample
23525
23526When used without the @var{group} parameter, lists top-level thread
23527groups that are being debugged. When used with the @var{group}
23528parameter, the children of the specified group are listed. The
23529children can be either threads, or other groups. At present,
23530@value{GDBN} will not report both threads and groups as children at
23531the same time, but it may change in future.
23532
23533With the @samp{--available} option, instead of reporting groups that
23534are been debugged, GDB will report all thread groups available on the
23535target. Using the @samp{--available} option together with @var{group}
23536is not allowed.
23537
23538@subheading Example
23539
23540@smallexample
23541@value{GDBP}
23542-list-thread-groups
23543^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
23544-list-thread-groups 17
23545^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
23546 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
23547@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
23548 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
23549 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
23550@end smallexample
c6ebd6cf 23551
ef21caaf
NR
23552@subheading The @code{-interpreter-exec} Command
23553@findex -interpreter-exec
23554
23555@subheading Synopsis
23556
23557@smallexample
23558-interpreter-exec @var{interpreter} @var{command}
23559@end smallexample
a2c02241 23560@anchor{-interpreter-exec}
ef21caaf
NR
23561
23562Execute the specified @var{command} in the given @var{interpreter}.
23563
23564@subheading @value{GDBN} Command
23565
23566The corresponding @value{GDBN} command is @samp{interpreter-exec}.
23567
23568@subheading Example
23569
23570@smallexample
594fe323 23571(gdb)
ef21caaf
NR
23572-interpreter-exec console "break main"
23573&"During symbol reading, couldn't parse type; debugger out of date?.\n"
23574&"During symbol reading, bad structure-type format.\n"
23575~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
23576^done
594fe323 23577(gdb)
ef21caaf
NR
23578@end smallexample
23579
23580@subheading The @code{-inferior-tty-set} Command
23581@findex -inferior-tty-set
23582
23583@subheading Synopsis
23584
23585@smallexample
23586-inferior-tty-set /dev/pts/1
23587@end smallexample
23588
23589Set terminal for future runs of the program being debugged.
23590
23591@subheading @value{GDBN} Command
23592
23593The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
23594
23595@subheading Example
23596
23597@smallexample
594fe323 23598(gdb)
ef21caaf
NR
23599-inferior-tty-set /dev/pts/1
23600^done
594fe323 23601(gdb)
ef21caaf
NR
23602@end smallexample
23603
23604@subheading The @code{-inferior-tty-show} Command
23605@findex -inferior-tty-show
23606
23607@subheading Synopsis
23608
23609@smallexample
23610-inferior-tty-show
23611@end smallexample
23612
23613Show terminal for future runs of program being debugged.
23614
23615@subheading @value{GDBN} Command
23616
23617The corresponding @value{GDBN} command is @samp{show inferior-tty}.
23618
23619@subheading Example
23620
23621@smallexample
594fe323 23622(gdb)
ef21caaf
NR
23623-inferior-tty-set /dev/pts/1
23624^done
594fe323 23625(gdb)
ef21caaf
NR
23626-inferior-tty-show
23627^done,inferior_tty_terminal="/dev/pts/1"
594fe323 23628(gdb)
ef21caaf 23629@end smallexample
922fbb7b 23630
a4eefcd8
NR
23631@subheading The @code{-enable-timings} Command
23632@findex -enable-timings
23633
23634@subheading Synopsis
23635
23636@smallexample
23637-enable-timings [yes | no]
23638@end smallexample
23639
23640Toggle the printing of the wallclock, user and system times for an MI
23641command as a field in its output. This command is to help frontend
23642developers optimize the performance of their code. No argument is
23643equivalent to @samp{yes}.
23644
23645@subheading @value{GDBN} Command
23646
23647No equivalent.
23648
23649@subheading Example
23650
23651@smallexample
23652(gdb)
23653-enable-timings
23654^done
23655(gdb)
23656-break-insert main
23657^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
23658addr="0x080484ed",func="main",file="myprog.c",
23659fullname="/home/nickrob/myprog.c",line="73",times="0"@},
23660time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
23661(gdb)
23662-enable-timings no
23663^done
23664(gdb)
23665-exec-run
23666^running
23667(gdb)
a47ec5fe 23668*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
23669frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
23670@{name="argv",value="0xbfb60364"@}],file="myprog.c",
23671fullname="/home/nickrob/myprog.c",line="73"@}
23672(gdb)
23673@end smallexample
23674
922fbb7b
AC
23675@node Annotations
23676@chapter @value{GDBN} Annotations
23677
086432e2
AC
23678This chapter describes annotations in @value{GDBN}. Annotations were
23679designed to interface @value{GDBN} to graphical user interfaces or other
23680similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
23681relatively high level.
23682
d3e8051b 23683The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
23684(@pxref{GDB/MI}).
23685
922fbb7b
AC
23686@ignore
23687This is Edition @value{EDITION}, @value{DATE}.
23688@end ignore
23689
23690@menu
23691* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 23692* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
23693* Prompting:: Annotations marking @value{GDBN}'s need for input.
23694* Errors:: Annotations for error messages.
922fbb7b
AC
23695* Invalidation:: Some annotations describe things now invalid.
23696* Annotations for Running::
23697 Whether the program is running, how it stopped, etc.
23698* Source Annotations:: Annotations describing source code.
922fbb7b
AC
23699@end menu
23700
23701@node Annotations Overview
23702@section What is an Annotation?
23703@cindex annotations
23704
922fbb7b
AC
23705Annotations start with a newline character, two @samp{control-z}
23706characters, and the name of the annotation. If there is no additional
23707information associated with this annotation, the name of the annotation
23708is followed immediately by a newline. If there is additional
23709information, the name of the annotation is followed by a space, the
23710additional information, and a newline. The additional information
23711cannot contain newline characters.
23712
23713Any output not beginning with a newline and two @samp{control-z}
23714characters denotes literal output from @value{GDBN}. Currently there is
23715no need for @value{GDBN} to output a newline followed by two
23716@samp{control-z} characters, but if there was such a need, the
23717annotations could be extended with an @samp{escape} annotation which
23718means those three characters as output.
23719
086432e2
AC
23720The annotation @var{level}, which is specified using the
23721@option{--annotate} command line option (@pxref{Mode Options}), controls
23722how much information @value{GDBN} prints together with its prompt,
23723values of expressions, source lines, and other types of output. Level 0
d3e8051b 23724is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
23725subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
23726for programs that control @value{GDBN}, and level 2 annotations have
23727been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
23728Interface, annotate, GDB's Obsolete Annotations}).
23729
23730@table @code
23731@kindex set annotate
23732@item set annotate @var{level}
e09f16f9 23733The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 23734annotations to the specified @var{level}.
9c16f35a
EZ
23735
23736@item show annotate
23737@kindex show annotate
23738Show the current annotation level.
09d4efe1
EZ
23739@end table
23740
23741This chapter describes level 3 annotations.
086432e2 23742
922fbb7b
AC
23743A simple example of starting up @value{GDBN} with annotations is:
23744
23745@smallexample
086432e2
AC
23746$ @kbd{gdb --annotate=3}
23747GNU gdb 6.0
23748Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
23749GDB is free software, covered by the GNU General Public License,
23750and you are welcome to change it and/or distribute copies of it
23751under certain conditions.
23752Type "show copying" to see the conditions.
23753There is absolutely no warranty for GDB. Type "show warranty"
23754for details.
086432e2 23755This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
23756
23757^Z^Zpre-prompt
f7dc1244 23758(@value{GDBP})
922fbb7b 23759^Z^Zprompt
086432e2 23760@kbd{quit}
922fbb7b
AC
23761
23762^Z^Zpost-prompt
b383017d 23763$
922fbb7b
AC
23764@end smallexample
23765
23766Here @samp{quit} is input to @value{GDBN}; the rest is output from
23767@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
23768denotes a @samp{control-z} character) are annotations; the rest is
23769output from @value{GDBN}.
23770
9e6c4bd5
NR
23771@node Server Prefix
23772@section The Server Prefix
23773@cindex server prefix
23774
23775If you prefix a command with @samp{server } then it will not affect
23776the command history, nor will it affect @value{GDBN}'s notion of which
23777command to repeat if @key{RET} is pressed on a line by itself. This
23778means that commands can be run behind a user's back by a front-end in
23779a transparent manner.
23780
23781The server prefix does not affect the recording of values into the value
23782history; to print a value without recording it into the value history,
23783use the @code{output} command instead of the @code{print} command.
23784
922fbb7b
AC
23785@node Prompting
23786@section Annotation for @value{GDBN} Input
23787
23788@cindex annotations for prompts
23789When @value{GDBN} prompts for input, it annotates this fact so it is possible
23790to know when to send output, when the output from a given command is
23791over, etc.
23792
23793Different kinds of input each have a different @dfn{input type}. Each
23794input type has three annotations: a @code{pre-} annotation, which
23795denotes the beginning of any prompt which is being output, a plain
23796annotation, which denotes the end of the prompt, and then a @code{post-}
23797annotation which denotes the end of any echo which may (or may not) be
23798associated with the input. For example, the @code{prompt} input type
23799features the following annotations:
23800
23801@smallexample
23802^Z^Zpre-prompt
23803^Z^Zprompt
23804^Z^Zpost-prompt
23805@end smallexample
23806
23807The input types are
23808
23809@table @code
e5ac9b53
EZ
23810@findex pre-prompt annotation
23811@findex prompt annotation
23812@findex post-prompt annotation
922fbb7b
AC
23813@item prompt
23814When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
23815
e5ac9b53
EZ
23816@findex pre-commands annotation
23817@findex commands annotation
23818@findex post-commands annotation
922fbb7b
AC
23819@item commands
23820When @value{GDBN} prompts for a set of commands, like in the @code{commands}
23821command. The annotations are repeated for each command which is input.
23822
e5ac9b53
EZ
23823@findex pre-overload-choice annotation
23824@findex overload-choice annotation
23825@findex post-overload-choice annotation
922fbb7b
AC
23826@item overload-choice
23827When @value{GDBN} wants the user to select between various overloaded functions.
23828
e5ac9b53
EZ
23829@findex pre-query annotation
23830@findex query annotation
23831@findex post-query annotation
922fbb7b
AC
23832@item query
23833When @value{GDBN} wants the user to confirm a potentially dangerous operation.
23834
e5ac9b53
EZ
23835@findex pre-prompt-for-continue annotation
23836@findex prompt-for-continue annotation
23837@findex post-prompt-for-continue annotation
922fbb7b
AC
23838@item prompt-for-continue
23839When @value{GDBN} is asking the user to press return to continue. Note: Don't
23840expect this to work well; instead use @code{set height 0} to disable
23841prompting. This is because the counting of lines is buggy in the
23842presence of annotations.
23843@end table
23844
23845@node Errors
23846@section Errors
23847@cindex annotations for errors, warnings and interrupts
23848
e5ac9b53 23849@findex quit annotation
922fbb7b
AC
23850@smallexample
23851^Z^Zquit
23852@end smallexample
23853
23854This annotation occurs right before @value{GDBN} responds to an interrupt.
23855
e5ac9b53 23856@findex error annotation
922fbb7b
AC
23857@smallexample
23858^Z^Zerror
23859@end smallexample
23860
23861This annotation occurs right before @value{GDBN} responds to an error.
23862
23863Quit and error annotations indicate that any annotations which @value{GDBN} was
23864in the middle of may end abruptly. For example, if a
23865@code{value-history-begin} annotation is followed by a @code{error}, one
23866cannot expect to receive the matching @code{value-history-end}. One
23867cannot expect not to receive it either, however; an error annotation
23868does not necessarily mean that @value{GDBN} is immediately returning all the way
23869to the top level.
23870
e5ac9b53 23871@findex error-begin annotation
922fbb7b
AC
23872A quit or error annotation may be preceded by
23873
23874@smallexample
23875^Z^Zerror-begin
23876@end smallexample
23877
23878Any output between that and the quit or error annotation is the error
23879message.
23880
23881Warning messages are not yet annotated.
23882@c If we want to change that, need to fix warning(), type_error(),
23883@c range_error(), and possibly other places.
23884
922fbb7b
AC
23885@node Invalidation
23886@section Invalidation Notices
23887
23888@cindex annotations for invalidation messages
23889The following annotations say that certain pieces of state may have
23890changed.
23891
23892@table @code
e5ac9b53 23893@findex frames-invalid annotation
922fbb7b
AC
23894@item ^Z^Zframes-invalid
23895
23896The frames (for example, output from the @code{backtrace} command) may
23897have changed.
23898
e5ac9b53 23899@findex breakpoints-invalid annotation
922fbb7b
AC
23900@item ^Z^Zbreakpoints-invalid
23901
23902The breakpoints may have changed. For example, the user just added or
23903deleted a breakpoint.
23904@end table
23905
23906@node Annotations for Running
23907@section Running the Program
23908@cindex annotations for running programs
23909
e5ac9b53
EZ
23910@findex starting annotation
23911@findex stopping annotation
922fbb7b 23912When the program starts executing due to a @value{GDBN} command such as
b383017d 23913@code{step} or @code{continue},
922fbb7b
AC
23914
23915@smallexample
23916^Z^Zstarting
23917@end smallexample
23918
b383017d 23919is output. When the program stops,
922fbb7b
AC
23920
23921@smallexample
23922^Z^Zstopped
23923@end smallexample
23924
23925is output. Before the @code{stopped} annotation, a variety of
23926annotations describe how the program stopped.
23927
23928@table @code
e5ac9b53 23929@findex exited annotation
922fbb7b
AC
23930@item ^Z^Zexited @var{exit-status}
23931The program exited, and @var{exit-status} is the exit status (zero for
23932successful exit, otherwise nonzero).
23933
e5ac9b53
EZ
23934@findex signalled annotation
23935@findex signal-name annotation
23936@findex signal-name-end annotation
23937@findex signal-string annotation
23938@findex signal-string-end annotation
922fbb7b
AC
23939@item ^Z^Zsignalled
23940The program exited with a signal. After the @code{^Z^Zsignalled}, the
23941annotation continues:
23942
23943@smallexample
23944@var{intro-text}
23945^Z^Zsignal-name
23946@var{name}
23947^Z^Zsignal-name-end
23948@var{middle-text}
23949^Z^Zsignal-string
23950@var{string}
23951^Z^Zsignal-string-end
23952@var{end-text}
23953@end smallexample
23954
23955@noindent
23956where @var{name} is the name of the signal, such as @code{SIGILL} or
23957@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
23958as @code{Illegal Instruction} or @code{Segmentation fault}.
23959@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
23960user's benefit and have no particular format.
23961
e5ac9b53 23962@findex signal annotation
922fbb7b
AC
23963@item ^Z^Zsignal
23964The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
23965just saying that the program received the signal, not that it was
23966terminated with it.
23967
e5ac9b53 23968@findex breakpoint annotation
922fbb7b
AC
23969@item ^Z^Zbreakpoint @var{number}
23970The program hit breakpoint number @var{number}.
23971
e5ac9b53 23972@findex watchpoint annotation
922fbb7b
AC
23973@item ^Z^Zwatchpoint @var{number}
23974The program hit watchpoint number @var{number}.
23975@end table
23976
23977@node Source Annotations
23978@section Displaying Source
23979@cindex annotations for source display
23980
e5ac9b53 23981@findex source annotation
922fbb7b
AC
23982The following annotation is used instead of displaying source code:
23983
23984@smallexample
23985^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
23986@end smallexample
23987
23988where @var{filename} is an absolute file name indicating which source
23989file, @var{line} is the line number within that file (where 1 is the
23990first line in the file), @var{character} is the character position
23991within the file (where 0 is the first character in the file) (for most
23992debug formats this will necessarily point to the beginning of a line),
23993@var{middle} is @samp{middle} if @var{addr} is in the middle of the
23994line, or @samp{beg} if @var{addr} is at the beginning of the line, and
23995@var{addr} is the address in the target program associated with the
23996source which is being displayed. @var{addr} is in the form @samp{0x}
23997followed by one or more lowercase hex digits (note that this does not
23998depend on the language).
23999
8e04817f
AC
24000@node GDB Bugs
24001@chapter Reporting Bugs in @value{GDBN}
24002@cindex bugs in @value{GDBN}
24003@cindex reporting bugs in @value{GDBN}
c906108c 24004
8e04817f 24005Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 24006
8e04817f
AC
24007Reporting a bug may help you by bringing a solution to your problem, or it
24008may not. But in any case the principal function of a bug report is to help
24009the entire community by making the next version of @value{GDBN} work better. Bug
24010reports are your contribution to the maintenance of @value{GDBN}.
c906108c 24011
8e04817f
AC
24012In order for a bug report to serve its purpose, you must include the
24013information that enables us to fix the bug.
c4555f82
SC
24014
24015@menu
8e04817f
AC
24016* Bug Criteria:: Have you found a bug?
24017* Bug Reporting:: How to report bugs
c4555f82
SC
24018@end menu
24019
8e04817f 24020@node Bug Criteria
79a6e687 24021@section Have You Found a Bug?
8e04817f 24022@cindex bug criteria
c4555f82 24023
8e04817f 24024If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
24025
24026@itemize @bullet
8e04817f
AC
24027@cindex fatal signal
24028@cindex debugger crash
24029@cindex crash of debugger
c4555f82 24030@item
8e04817f
AC
24031If the debugger gets a fatal signal, for any input whatever, that is a
24032@value{GDBN} bug. Reliable debuggers never crash.
24033
24034@cindex error on valid input
24035@item
24036If @value{GDBN} produces an error message for valid input, that is a
24037bug. (Note that if you're cross debugging, the problem may also be
24038somewhere in the connection to the target.)
c4555f82 24039
8e04817f 24040@cindex invalid input
c4555f82 24041@item
8e04817f
AC
24042If @value{GDBN} does not produce an error message for invalid input,
24043that is a bug. However, you should note that your idea of
24044``invalid input'' might be our idea of ``an extension'' or ``support
24045for traditional practice''.
24046
24047@item
24048If you are an experienced user of debugging tools, your suggestions
24049for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
24050@end itemize
24051
8e04817f 24052@node Bug Reporting
79a6e687 24053@section How to Report Bugs
8e04817f
AC
24054@cindex bug reports
24055@cindex @value{GDBN} bugs, reporting
24056
24057A number of companies and individuals offer support for @sc{gnu} products.
24058If you obtained @value{GDBN} from a support organization, we recommend you
24059contact that organization first.
24060
24061You can find contact information for many support companies and
24062individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
24063distribution.
24064@c should add a web page ref...
24065
c16158bc
JM
24066@ifset BUGURL
24067@ifset BUGURL_DEFAULT
129188f6 24068In any event, we also recommend that you submit bug reports for
d3e8051b 24069@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
24070@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
24071page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
24072be used.
8e04817f
AC
24073
24074@strong{Do not send bug reports to @samp{info-gdb}, or to
24075@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
24076not want to receive bug reports. Those that do have arranged to receive
24077@samp{bug-gdb}.
24078
24079The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
24080serves as a repeater. The mailing list and the newsgroup carry exactly
24081the same messages. Often people think of posting bug reports to the
24082newsgroup instead of mailing them. This appears to work, but it has one
24083problem which can be crucial: a newsgroup posting often lacks a mail
24084path back to the sender. Thus, if we need to ask for more information,
24085we may be unable to reach you. For this reason, it is better to send
24086bug reports to the mailing list.
c16158bc
JM
24087@end ifset
24088@ifclear BUGURL_DEFAULT
24089In any event, we also recommend that you submit bug reports for
24090@value{GDBN} to @value{BUGURL}.
24091@end ifclear
24092@end ifset
c4555f82 24093
8e04817f
AC
24094The fundamental principle of reporting bugs usefully is this:
24095@strong{report all the facts}. If you are not sure whether to state a
24096fact or leave it out, state it!
c4555f82 24097
8e04817f
AC
24098Often people omit facts because they think they know what causes the
24099problem and assume that some details do not matter. Thus, you might
24100assume that the name of the variable you use in an example does not matter.
24101Well, probably it does not, but one cannot be sure. Perhaps the bug is a
24102stray memory reference which happens to fetch from the location where that
24103name is stored in memory; perhaps, if the name were different, the contents
24104of that location would fool the debugger into doing the right thing despite
24105the bug. Play it safe and give a specific, complete example. That is the
24106easiest thing for you to do, and the most helpful.
c4555f82 24107
8e04817f
AC
24108Keep in mind that the purpose of a bug report is to enable us to fix the
24109bug. It may be that the bug has been reported previously, but neither
24110you nor we can know that unless your bug report is complete and
24111self-contained.
c4555f82 24112
8e04817f
AC
24113Sometimes people give a few sketchy facts and ask, ``Does this ring a
24114bell?'' Those bug reports are useless, and we urge everyone to
24115@emph{refuse to respond to them} except to chide the sender to report
24116bugs properly.
24117
24118To enable us to fix the bug, you should include all these things:
c4555f82
SC
24119
24120@itemize @bullet
24121@item
8e04817f
AC
24122The version of @value{GDBN}. @value{GDBN} announces it if you start
24123with no arguments; you can also print it at any time using @code{show
24124version}.
c4555f82 24125
8e04817f
AC
24126Without this, we will not know whether there is any point in looking for
24127the bug in the current version of @value{GDBN}.
c4555f82
SC
24128
24129@item
8e04817f
AC
24130The type of machine you are using, and the operating system name and
24131version number.
c4555f82
SC
24132
24133@item
c1468174 24134What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 24135``@value{GCC}--2.8.1''.
c4555f82
SC
24136
24137@item
8e04817f 24138What compiler (and its version) was used to compile the program you are
c1468174 24139debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
24140C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
24141to get this information; for other compilers, see the documentation for
24142those compilers.
c4555f82 24143
8e04817f
AC
24144@item
24145The command arguments you gave the compiler to compile your example and
24146observe the bug. For example, did you use @samp{-O}? To guarantee
24147you will not omit something important, list them all. A copy of the
24148Makefile (or the output from make) is sufficient.
c4555f82 24149
8e04817f
AC
24150If we were to try to guess the arguments, we would probably guess wrong
24151and then we might not encounter the bug.
c4555f82 24152
8e04817f
AC
24153@item
24154A complete input script, and all necessary source files, that will
24155reproduce the bug.
c4555f82 24156
8e04817f
AC
24157@item
24158A description of what behavior you observe that you believe is
24159incorrect. For example, ``It gets a fatal signal.''
c4555f82 24160
8e04817f
AC
24161Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
24162will certainly notice it. But if the bug is incorrect output, we might
24163not notice unless it is glaringly wrong. You might as well not give us
24164a chance to make a mistake.
c4555f82 24165
8e04817f
AC
24166Even if the problem you experience is a fatal signal, you should still
24167say so explicitly. Suppose something strange is going on, such as, your
24168copy of @value{GDBN} is out of synch, or you have encountered a bug in
24169the C library on your system. (This has happened!) Your copy might
24170crash and ours would not. If you told us to expect a crash, then when
24171ours fails to crash, we would know that the bug was not happening for
24172us. If you had not told us to expect a crash, then we would not be able
24173to draw any conclusion from our observations.
c4555f82 24174
e0c07bf0
MC
24175@pindex script
24176@cindex recording a session script
24177To collect all this information, you can use a session recording program
24178such as @command{script}, which is available on many Unix systems.
24179Just run your @value{GDBN} session inside @command{script} and then
24180include the @file{typescript} file with your bug report.
24181
24182Another way to record a @value{GDBN} session is to run @value{GDBN}
24183inside Emacs and then save the entire buffer to a file.
24184
8e04817f
AC
24185@item
24186If you wish to suggest changes to the @value{GDBN} source, send us context
24187diffs. If you even discuss something in the @value{GDBN} source, refer to
24188it by context, not by line number.
c4555f82 24189
8e04817f
AC
24190The line numbers in our development sources will not match those in your
24191sources. Your line numbers would convey no useful information to us.
c4555f82 24192
8e04817f 24193@end itemize
c4555f82 24194
8e04817f 24195Here are some things that are not necessary:
c4555f82 24196
8e04817f
AC
24197@itemize @bullet
24198@item
24199A description of the envelope of the bug.
c4555f82 24200
8e04817f
AC
24201Often people who encounter a bug spend a lot of time investigating
24202which changes to the input file will make the bug go away and which
24203changes will not affect it.
c4555f82 24204
8e04817f
AC
24205This is often time consuming and not very useful, because the way we
24206will find the bug is by running a single example under the debugger
24207with breakpoints, not by pure deduction from a series of examples.
24208We recommend that you save your time for something else.
c4555f82 24209
8e04817f
AC
24210Of course, if you can find a simpler example to report @emph{instead}
24211of the original one, that is a convenience for us. Errors in the
24212output will be easier to spot, running under the debugger will take
24213less time, and so on.
c4555f82 24214
8e04817f
AC
24215However, simplification is not vital; if you do not want to do this,
24216report the bug anyway and send us the entire test case you used.
c4555f82 24217
8e04817f
AC
24218@item
24219A patch for the bug.
c4555f82 24220
8e04817f
AC
24221A patch for the bug does help us if it is a good one. But do not omit
24222the necessary information, such as the test case, on the assumption that
24223a patch is all we need. We might see problems with your patch and decide
24224to fix the problem another way, or we might not understand it at all.
c4555f82 24225
8e04817f
AC
24226Sometimes with a program as complicated as @value{GDBN} it is very hard to
24227construct an example that will make the program follow a certain path
24228through the code. If you do not send us the example, we will not be able
24229to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 24230
8e04817f
AC
24231And if we cannot understand what bug you are trying to fix, or why your
24232patch should be an improvement, we will not install it. A test case will
24233help us to understand.
c4555f82 24234
8e04817f
AC
24235@item
24236A guess about what the bug is or what it depends on.
c4555f82 24237
8e04817f
AC
24238Such guesses are usually wrong. Even we cannot guess right about such
24239things without first using the debugger to find the facts.
24240@end itemize
c4555f82 24241
8e04817f
AC
24242@c The readline documentation is distributed with the readline code
24243@c and consists of the two following files:
24244@c rluser.texinfo
24245@c inc-hist.texinfo
24246@c Use -I with makeinfo to point to the appropriate directory,
24247@c environment var TEXINPUTS with TeX.
5bdf8622 24248@include rluser.texi
8e04817f 24249@include inc-hist.texinfo
c4555f82 24250
c4555f82 24251
8e04817f
AC
24252@node Formatting Documentation
24253@appendix Formatting Documentation
c4555f82 24254
8e04817f
AC
24255@cindex @value{GDBN} reference card
24256@cindex reference card
24257The @value{GDBN} 4 release includes an already-formatted reference card, ready
24258for printing with PostScript or Ghostscript, in the @file{gdb}
24259subdirectory of the main source directory@footnote{In
24260@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
24261release.}. If you can use PostScript or Ghostscript with your printer,
24262you can print the reference card immediately with @file{refcard.ps}.
c4555f82 24263
8e04817f
AC
24264The release also includes the source for the reference card. You
24265can format it, using @TeX{}, by typing:
c4555f82 24266
474c8240 24267@smallexample
8e04817f 24268make refcard.dvi
474c8240 24269@end smallexample
c4555f82 24270
8e04817f
AC
24271The @value{GDBN} reference card is designed to print in @dfn{landscape}
24272mode on US ``letter'' size paper;
24273that is, on a sheet 11 inches wide by 8.5 inches
24274high. You will need to specify this form of printing as an option to
24275your @sc{dvi} output program.
c4555f82 24276
8e04817f 24277@cindex documentation
c4555f82 24278
8e04817f
AC
24279All the documentation for @value{GDBN} comes as part of the machine-readable
24280distribution. The documentation is written in Texinfo format, which is
24281a documentation system that uses a single source file to produce both
24282on-line information and a printed manual. You can use one of the Info
24283formatting commands to create the on-line version of the documentation
24284and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 24285
8e04817f
AC
24286@value{GDBN} includes an already formatted copy of the on-line Info
24287version of this manual in the @file{gdb} subdirectory. The main Info
24288file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
24289subordinate files matching @samp{gdb.info*} in the same directory. If
24290necessary, you can print out these files, or read them with any editor;
24291but they are easier to read using the @code{info} subsystem in @sc{gnu}
24292Emacs or the standalone @code{info} program, available as part of the
24293@sc{gnu} Texinfo distribution.
c4555f82 24294
8e04817f
AC
24295If you want to format these Info files yourself, you need one of the
24296Info formatting programs, such as @code{texinfo-format-buffer} or
24297@code{makeinfo}.
c4555f82 24298
8e04817f
AC
24299If you have @code{makeinfo} installed, and are in the top level
24300@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
24301version @value{GDBVN}), you can make the Info file by typing:
c4555f82 24302
474c8240 24303@smallexample
8e04817f
AC
24304cd gdb
24305make gdb.info
474c8240 24306@end smallexample
c4555f82 24307
8e04817f
AC
24308If you want to typeset and print copies of this manual, you need @TeX{},
24309a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
24310Texinfo definitions file.
c4555f82 24311
8e04817f
AC
24312@TeX{} is a typesetting program; it does not print files directly, but
24313produces output files called @sc{dvi} files. To print a typeset
24314document, you need a program to print @sc{dvi} files. If your system
24315has @TeX{} installed, chances are it has such a program. The precise
24316command to use depends on your system; @kbd{lpr -d} is common; another
24317(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
24318require a file name without any extension or a @samp{.dvi} extension.
c4555f82 24319
8e04817f
AC
24320@TeX{} also requires a macro definitions file called
24321@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
24322written in Texinfo format. On its own, @TeX{} cannot either read or
24323typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
24324and is located in the @file{gdb-@var{version-number}/texinfo}
24325directory.
c4555f82 24326
8e04817f 24327If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 24328typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
24329subdirectory of the main source directory (for example, to
24330@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 24331
474c8240 24332@smallexample
8e04817f 24333make gdb.dvi
474c8240 24334@end smallexample
c4555f82 24335
8e04817f 24336Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 24337
8e04817f
AC
24338@node Installing GDB
24339@appendix Installing @value{GDBN}
8e04817f 24340@cindex installation
c4555f82 24341
7fa2210b
DJ
24342@menu
24343* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 24344* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
24345* Separate Objdir:: Compiling @value{GDBN} in another directory
24346* Config Names:: Specifying names for hosts and targets
24347* Configure Options:: Summary of options for configure
24348@end menu
24349
24350@node Requirements
79a6e687 24351@section Requirements for Building @value{GDBN}
7fa2210b
DJ
24352@cindex building @value{GDBN}, requirements for
24353
24354Building @value{GDBN} requires various tools and packages to be available.
24355Other packages will be used only if they are found.
24356
79a6e687 24357@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
24358@table @asis
24359@item ISO C90 compiler
24360@value{GDBN} is written in ISO C90. It should be buildable with any
24361working C90 compiler, e.g.@: GCC.
24362
24363@end table
24364
79a6e687 24365@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
24366@table @asis
24367@item Expat
123dc839 24368@anchor{Expat}
7fa2210b
DJ
24369@value{GDBN} can use the Expat XML parsing library. This library may be
24370included with your operating system distribution; if it is not, you
24371can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 24372The @file{configure} script will search for this library in several
7fa2210b
DJ
24373standard locations; if it is installed in an unusual path, you can
24374use the @option{--with-libexpat-prefix} option to specify its location.
24375
9cceb671
DJ
24376Expat is used for:
24377
24378@itemize @bullet
24379@item
24380Remote protocol memory maps (@pxref{Memory Map Format})
24381@item
24382Target descriptions (@pxref{Target Descriptions})
24383@item
24384Remote shared library lists (@pxref{Library List Format})
24385@item
24386MS-Windows shared libraries (@pxref{Shared Libraries})
24387@end itemize
7fa2210b 24388
31fffb02
CS
24389@item zlib
24390@cindex compressed debug sections
24391@value{GDBN} will use the @samp{zlib} library, if available, to read
24392compressed debug sections. Some linkers, such as GNU gold, are capable
24393of producing binaries with compressed debug sections. If @value{GDBN}
24394is compiled with @samp{zlib}, it will be able to read the debug
24395information in such binaries.
24396
24397The @samp{zlib} library is likely included with your operating system
24398distribution; if it is not, you can get the latest version from
24399@url{http://zlib.net}.
24400
7fa2210b
DJ
24401@end table
24402
24403@node Running Configure
db2e3e2e 24404@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 24405@cindex configuring @value{GDBN}
db2e3e2e 24406@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
24407of preparing @value{GDBN} for installation; you can then use @code{make} to
24408build the @code{gdb} program.
24409@iftex
24410@c irrelevant in info file; it's as current as the code it lives with.
24411@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
24412look at the @file{README} file in the sources; we may have improved the
24413installation procedures since publishing this manual.}
24414@end iftex
c4555f82 24415
8e04817f
AC
24416The @value{GDBN} distribution includes all the source code you need for
24417@value{GDBN} in a single directory, whose name is usually composed by
24418appending the version number to @samp{gdb}.
c4555f82 24419
8e04817f
AC
24420For example, the @value{GDBN} version @value{GDBVN} distribution is in the
24421@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 24422
8e04817f
AC
24423@table @code
24424@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
24425script for configuring @value{GDBN} and all its supporting libraries
c4555f82 24426
8e04817f
AC
24427@item gdb-@value{GDBVN}/gdb
24428the source specific to @value{GDBN} itself
c4555f82 24429
8e04817f
AC
24430@item gdb-@value{GDBVN}/bfd
24431source for the Binary File Descriptor library
c906108c 24432
8e04817f
AC
24433@item gdb-@value{GDBVN}/include
24434@sc{gnu} include files
c906108c 24435
8e04817f
AC
24436@item gdb-@value{GDBVN}/libiberty
24437source for the @samp{-liberty} free software library
c906108c 24438
8e04817f
AC
24439@item gdb-@value{GDBVN}/opcodes
24440source for the library of opcode tables and disassemblers
c906108c 24441
8e04817f
AC
24442@item gdb-@value{GDBVN}/readline
24443source for the @sc{gnu} command-line interface
c906108c 24444
8e04817f
AC
24445@item gdb-@value{GDBVN}/glob
24446source for the @sc{gnu} filename pattern-matching subroutine
c906108c 24447
8e04817f
AC
24448@item gdb-@value{GDBVN}/mmalloc
24449source for the @sc{gnu} memory-mapped malloc package
24450@end table
c906108c 24451
db2e3e2e 24452The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
24453from the @file{gdb-@var{version-number}} source directory, which in
24454this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 24455
8e04817f 24456First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 24457if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
24458identifier for the platform on which @value{GDBN} will run as an
24459argument.
c906108c 24460
8e04817f 24461For example:
c906108c 24462
474c8240 24463@smallexample
8e04817f
AC
24464cd gdb-@value{GDBVN}
24465./configure @var{host}
24466make
474c8240 24467@end smallexample
c906108c 24468
8e04817f
AC
24469@noindent
24470where @var{host} is an identifier such as @samp{sun4} or
24471@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 24472(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 24473correct value by examining your system.)
c906108c 24474
8e04817f
AC
24475Running @samp{configure @var{host}} and then running @code{make} builds the
24476@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
24477libraries, then @code{gdb} itself. The configured source files, and the
24478binaries, are left in the corresponding source directories.
c906108c 24479
8e04817f 24480@need 750
db2e3e2e 24481@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
24482system does not recognize this automatically when you run a different
24483shell, you may need to run @code{sh} on it explicitly:
c906108c 24484
474c8240 24485@smallexample
8e04817f 24486sh configure @var{host}
474c8240 24487@end smallexample
c906108c 24488
db2e3e2e 24489If you run @file{configure} from a directory that contains source
8e04817f 24490directories for multiple libraries or programs, such as the
db2e3e2e
BW
24491@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
24492@file{configure}
8e04817f
AC
24493creates configuration files for every directory level underneath (unless
24494you tell it not to, with the @samp{--norecursion} option).
24495
db2e3e2e 24496You should run the @file{configure} script from the top directory in the
94e91d6d 24497source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 24498@file{configure} from one of the subdirectories, you will configure only
94e91d6d 24499that subdirectory. That is usually not what you want. In particular,
db2e3e2e 24500if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
24501of the @file{gdb-@var{version-number}} directory, you will omit the
24502configuration of @file{bfd}, @file{readline}, and other sibling
24503directories of the @file{gdb} subdirectory. This leads to build errors
24504about missing include files such as @file{bfd/bfd.h}.
c906108c 24505
8e04817f
AC
24506You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
24507However, you should make sure that the shell on your path (named by
24508the @samp{SHELL} environment variable) is publicly readable. Remember
24509that @value{GDBN} uses the shell to start your program---some systems refuse to
24510let @value{GDBN} debug child processes whose programs are not readable.
c906108c 24511
8e04817f 24512@node Separate Objdir
79a6e687 24513@section Compiling @value{GDBN} in Another Directory
c906108c 24514
8e04817f
AC
24515If you want to run @value{GDBN} versions for several host or target machines,
24516you need a different @code{gdb} compiled for each combination of
db2e3e2e 24517host and target. @file{configure} is designed to make this easy by
8e04817f
AC
24518allowing you to generate each configuration in a separate subdirectory,
24519rather than in the source directory. If your @code{make} program
24520handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
24521@code{make} in each of these directories builds the @code{gdb}
24522program specified there.
c906108c 24523
db2e3e2e 24524To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 24525with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
24526(You also need to specify a path to find @file{configure}
24527itself from your working directory. If the path to @file{configure}
8e04817f
AC
24528would be the same as the argument to @samp{--srcdir}, you can leave out
24529the @samp{--srcdir} option; it is assumed.)
c906108c 24530
8e04817f
AC
24531For example, with version @value{GDBVN}, you can build @value{GDBN} in a
24532separate directory for a Sun 4 like this:
c906108c 24533
474c8240 24534@smallexample
8e04817f
AC
24535@group
24536cd gdb-@value{GDBVN}
24537mkdir ../gdb-sun4
24538cd ../gdb-sun4
24539../gdb-@value{GDBVN}/configure sun4
24540make
24541@end group
474c8240 24542@end smallexample
c906108c 24543
db2e3e2e 24544When @file{configure} builds a configuration using a remote source
8e04817f
AC
24545directory, it creates a tree for the binaries with the same structure
24546(and using the same names) as the tree under the source directory. In
24547the example, you'd find the Sun 4 library @file{libiberty.a} in the
24548directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
24549@file{gdb-sun4/gdb}.
c906108c 24550
94e91d6d
MC
24551Make sure that your path to the @file{configure} script has just one
24552instance of @file{gdb} in it. If your path to @file{configure} looks
24553like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
24554one subdirectory of @value{GDBN}, not the whole package. This leads to
24555build errors about missing include files such as @file{bfd/bfd.h}.
24556
8e04817f
AC
24557One popular reason to build several @value{GDBN} configurations in separate
24558directories is to configure @value{GDBN} for cross-compiling (where
24559@value{GDBN} runs on one machine---the @dfn{host}---while debugging
24560programs that run on another machine---the @dfn{target}).
24561You specify a cross-debugging target by
db2e3e2e 24562giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 24563
8e04817f
AC
24564When you run @code{make} to build a program or library, you must run
24565it in a configured directory---whatever directory you were in when you
db2e3e2e 24566called @file{configure} (or one of its subdirectories).
c906108c 24567
db2e3e2e 24568The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
24569directory also runs recursively. If you type @code{make} in a source
24570directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
24571directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
24572will build all the required libraries, and then build GDB.
c906108c 24573
8e04817f
AC
24574When you have multiple hosts or targets configured in separate
24575directories, you can run @code{make} on them in parallel (for example,
24576if they are NFS-mounted on each of the hosts); they will not interfere
24577with each other.
c906108c 24578
8e04817f 24579@node Config Names
79a6e687 24580@section Specifying Names for Hosts and Targets
c906108c 24581
db2e3e2e 24582The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
24583script are based on a three-part naming scheme, but some short predefined
24584aliases are also supported. The full naming scheme encodes three pieces
24585of information in the following pattern:
c906108c 24586
474c8240 24587@smallexample
8e04817f 24588@var{architecture}-@var{vendor}-@var{os}
474c8240 24589@end smallexample
c906108c 24590
8e04817f
AC
24591For example, you can use the alias @code{sun4} as a @var{host} argument,
24592or as the value for @var{target} in a @code{--target=@var{target}}
24593option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 24594
db2e3e2e 24595The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 24596any query facility to list all supported host and target names or
db2e3e2e 24597aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
24598@code{config.sub} to map abbreviations to full names; you can read the
24599script, if you wish, or you can use it to test your guesses on
24600abbreviations---for example:
c906108c 24601
8e04817f
AC
24602@smallexample
24603% sh config.sub i386-linux
24604i386-pc-linux-gnu
24605% sh config.sub alpha-linux
24606alpha-unknown-linux-gnu
24607% sh config.sub hp9k700
24608hppa1.1-hp-hpux
24609% sh config.sub sun4
24610sparc-sun-sunos4.1.1
24611% sh config.sub sun3
24612m68k-sun-sunos4.1.1
24613% sh config.sub i986v
24614Invalid configuration `i986v': machine `i986v' not recognized
24615@end smallexample
c906108c 24616
8e04817f
AC
24617@noindent
24618@code{config.sub} is also distributed in the @value{GDBN} source
24619directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 24620
8e04817f 24621@node Configure Options
db2e3e2e 24622@section @file{configure} Options
c906108c 24623
db2e3e2e
BW
24624Here is a summary of the @file{configure} options and arguments that
24625are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 24626several other options not listed here. @inforef{What Configure
db2e3e2e 24627Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 24628
474c8240 24629@smallexample
8e04817f
AC
24630configure @r{[}--help@r{]}
24631 @r{[}--prefix=@var{dir}@r{]}
24632 @r{[}--exec-prefix=@var{dir}@r{]}
24633 @r{[}--srcdir=@var{dirname}@r{]}
24634 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
24635 @r{[}--target=@var{target}@r{]}
24636 @var{host}
474c8240 24637@end smallexample
c906108c 24638
8e04817f
AC
24639@noindent
24640You may introduce options with a single @samp{-} rather than
24641@samp{--} if you prefer; but you may abbreviate option names if you use
24642@samp{--}.
c906108c 24643
8e04817f
AC
24644@table @code
24645@item --help
db2e3e2e 24646Display a quick summary of how to invoke @file{configure}.
c906108c 24647
8e04817f
AC
24648@item --prefix=@var{dir}
24649Configure the source to install programs and files under directory
24650@file{@var{dir}}.
c906108c 24651
8e04817f
AC
24652@item --exec-prefix=@var{dir}
24653Configure the source to install programs under directory
24654@file{@var{dir}}.
c906108c 24655
8e04817f
AC
24656@c avoid splitting the warning from the explanation:
24657@need 2000
24658@item --srcdir=@var{dirname}
24659@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
24660@code{make} that implements the @code{VPATH} feature.}@*
24661Use this option to make configurations in directories separate from the
24662@value{GDBN} source directories. Among other things, you can use this to
24663build (or maintain) several configurations simultaneously, in separate
db2e3e2e 24664directories. @file{configure} writes configuration-specific files in
8e04817f 24665the current directory, but arranges for them to use the source in the
db2e3e2e 24666directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
24667the working directory in parallel to the source directories below
24668@var{dirname}.
c906108c 24669
8e04817f 24670@item --norecursion
db2e3e2e 24671Configure only the directory level where @file{configure} is executed; do not
8e04817f 24672propagate configuration to subdirectories.
c906108c 24673
8e04817f
AC
24674@item --target=@var{target}
24675Configure @value{GDBN} for cross-debugging programs running on the specified
24676@var{target}. Without this option, @value{GDBN} is configured to debug
24677programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 24678
8e04817f 24679There is no convenient way to generate a list of all available targets.
c906108c 24680
8e04817f
AC
24681@item @var{host} @dots{}
24682Configure @value{GDBN} to run on the specified @var{host}.
c906108c 24683
8e04817f
AC
24684There is no convenient way to generate a list of all available hosts.
24685@end table
c906108c 24686
8e04817f
AC
24687There are many other options available as well, but they are generally
24688needed for special purposes only.
c906108c 24689
8e04817f
AC
24690@node Maintenance Commands
24691@appendix Maintenance Commands
24692@cindex maintenance commands
24693@cindex internal commands
c906108c 24694
8e04817f 24695In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
24696includes a number of commands intended for @value{GDBN} developers,
24697that are not documented elsewhere in this manual. These commands are
da316a69
EZ
24698provided here for reference. (For commands that turn on debugging
24699messages, see @ref{Debugging Output}.)
c906108c 24700
8e04817f 24701@table @code
09d4efe1
EZ
24702@kindex maint agent
24703@item maint agent @var{expression}
24704Translate the given @var{expression} into remote agent bytecodes.
24705This command is useful for debugging the Agent Expression mechanism
24706(@pxref{Agent Expressions}).
24707
8e04817f
AC
24708@kindex maint info breakpoints
24709@item @anchor{maint info breakpoints}maint info breakpoints
24710Using the same format as @samp{info breakpoints}, display both the
24711breakpoints you've set explicitly, and those @value{GDBN} is using for
24712internal purposes. Internal breakpoints are shown with negative
24713breakpoint numbers. The type column identifies what kind of breakpoint
24714is shown:
c906108c 24715
8e04817f
AC
24716@table @code
24717@item breakpoint
24718Normal, explicitly set breakpoint.
c906108c 24719
8e04817f
AC
24720@item watchpoint
24721Normal, explicitly set watchpoint.
c906108c 24722
8e04817f
AC
24723@item longjmp
24724Internal breakpoint, used to handle correctly stepping through
24725@code{longjmp} calls.
c906108c 24726
8e04817f
AC
24727@item longjmp resume
24728Internal breakpoint at the target of a @code{longjmp}.
c906108c 24729
8e04817f
AC
24730@item until
24731Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 24732
8e04817f
AC
24733@item finish
24734Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 24735
8e04817f
AC
24736@item shlib events
24737Shared library events.
c906108c 24738
8e04817f 24739@end table
c906108c 24740
fff08868
HZ
24741@kindex set displaced-stepping
24742@kindex show displaced-stepping
237fc4c9
PA
24743@cindex displaced stepping support
24744@cindex out-of-line single-stepping
fff08868
HZ
24745@item set displaced-stepping
24746@itemx show displaced-stepping
237fc4c9 24747Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
24748if the target supports it. Displaced stepping is a way to single-step
24749over breakpoints without removing them from the inferior, by executing
24750an out-of-line copy of the instruction that was originally at the
24751breakpoint location. It is also known as out-of-line single-stepping.
24752
24753@table @code
24754@item set displaced-stepping on
24755If the target architecture supports it, @value{GDBN} will use
24756displaced stepping to step over breakpoints.
24757
24758@item set displaced-stepping off
24759@value{GDBN} will not use displaced stepping to step over breakpoints,
24760even if such is supported by the target architecture.
24761
24762@cindex non-stop mode, and @samp{set displaced-stepping}
24763@item set displaced-stepping auto
24764This is the default mode. @value{GDBN} will use displaced stepping
24765only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
24766architecture supports displaced stepping.
24767@end table
237fc4c9 24768
09d4efe1
EZ
24769@kindex maint check-symtabs
24770@item maint check-symtabs
24771Check the consistency of psymtabs and symtabs.
24772
24773@kindex maint cplus first_component
24774@item maint cplus first_component @var{name}
24775Print the first C@t{++} class/namespace component of @var{name}.
24776
24777@kindex maint cplus namespace
24778@item maint cplus namespace
24779Print the list of possible C@t{++} namespaces.
24780
24781@kindex maint demangle
24782@item maint demangle @var{name}
d3e8051b 24783Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
24784
24785@kindex maint deprecate
24786@kindex maint undeprecate
24787@cindex deprecated commands
24788@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
24789@itemx maint undeprecate @var{command}
24790Deprecate or undeprecate the named @var{command}. Deprecated commands
24791cause @value{GDBN} to issue a warning when you use them. The optional
24792argument @var{replacement} says which newer command should be used in
24793favor of the deprecated one; if it is given, @value{GDBN} will mention
24794the replacement as part of the warning.
24795
24796@kindex maint dump-me
24797@item maint dump-me
721c2651 24798@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 24799Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
24800This is supported only on systems which support aborting a program
24801with the @code{SIGQUIT} signal.
09d4efe1 24802
8d30a00d
AC
24803@kindex maint internal-error
24804@kindex maint internal-warning
09d4efe1
EZ
24805@item maint internal-error @r{[}@var{message-text}@r{]}
24806@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
24807Cause @value{GDBN} to call the internal function @code{internal_error}
24808or @code{internal_warning} and hence behave as though an internal error
24809or internal warning has been detected. In addition to reporting the
24810internal problem, these functions give the user the opportunity to
24811either quit @value{GDBN} or create a core file of the current
24812@value{GDBN} session.
24813
09d4efe1
EZ
24814These commands take an optional parameter @var{message-text} that is
24815used as the text of the error or warning message.
24816
d3e8051b 24817Here's an example of using @code{internal-error}:
09d4efe1 24818
8d30a00d 24819@smallexample
f7dc1244 24820(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
24821@dots{}/maint.c:121: internal-error: testing, 1, 2
24822A problem internal to GDB has been detected. Further
24823debugging may prove unreliable.
24824Quit this debugging session? (y or n) @kbd{n}
24825Create a core file? (y or n) @kbd{n}
f7dc1244 24826(@value{GDBP})
8d30a00d
AC
24827@end smallexample
24828
09d4efe1
EZ
24829@kindex maint packet
24830@item maint packet @var{text}
24831If @value{GDBN} is talking to an inferior via the serial protocol,
24832then this command sends the string @var{text} to the inferior, and
24833displays the response packet. @value{GDBN} supplies the initial
24834@samp{$} character, the terminating @samp{#} character, and the
24835checksum.
24836
24837@kindex maint print architecture
24838@item maint print architecture @r{[}@var{file}@r{]}
24839Print the entire architecture configuration. The optional argument
24840@var{file} names the file where the output goes.
8d30a00d 24841
81adfced
DJ
24842@kindex maint print c-tdesc
24843@item maint print c-tdesc
24844Print the current target description (@pxref{Target Descriptions}) as
24845a C source file. The created source file can be used in @value{GDBN}
24846when an XML parser is not available to parse the description.
24847
00905d52
AC
24848@kindex maint print dummy-frames
24849@item maint print dummy-frames
00905d52
AC
24850Prints the contents of @value{GDBN}'s internal dummy-frame stack.
24851
24852@smallexample
f7dc1244 24853(@value{GDBP}) @kbd{b add}
00905d52 24854@dots{}
f7dc1244 24855(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
24856Breakpoint 2, add (a=2, b=3) at @dots{}
2485758 return (a + b);
24858The program being debugged stopped while in a function called from GDB.
24859@dots{}
f7dc1244 24860(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
248610x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
24862 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
24863 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 24864(@value{GDBP})
00905d52
AC
24865@end smallexample
24866
24867Takes an optional file parameter.
24868
0680b120
AC
24869@kindex maint print registers
24870@kindex maint print raw-registers
24871@kindex maint print cooked-registers
617073a9 24872@kindex maint print register-groups
09d4efe1
EZ
24873@item maint print registers @r{[}@var{file}@r{]}
24874@itemx maint print raw-registers @r{[}@var{file}@r{]}
24875@itemx maint print cooked-registers @r{[}@var{file}@r{]}
24876@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
24877Print @value{GDBN}'s internal register data structures.
24878
617073a9
AC
24879The command @code{maint print raw-registers} includes the contents of
24880the raw register cache; the command @code{maint print cooked-registers}
24881includes the (cooked) value of all registers; and the command
24882@code{maint print register-groups} includes the groups that each
24883register is a member of. @xref{Registers,, Registers, gdbint,
24884@value{GDBN} Internals}.
0680b120 24885
09d4efe1
EZ
24886These commands take an optional parameter, a file name to which to
24887write the information.
0680b120 24888
617073a9 24889@kindex maint print reggroups
09d4efe1
EZ
24890@item maint print reggroups @r{[}@var{file}@r{]}
24891Print @value{GDBN}'s internal register group data structures. The
24892optional argument @var{file} tells to what file to write the
24893information.
617073a9 24894
09d4efe1 24895The register groups info looks like this:
617073a9
AC
24896
24897@smallexample
f7dc1244 24898(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
24899 Group Type
24900 general user
24901 float user
24902 all user
24903 vector user
24904 system user
24905 save internal
24906 restore internal
617073a9
AC
24907@end smallexample
24908
09d4efe1
EZ
24909@kindex flushregs
24910@item flushregs
24911This command forces @value{GDBN} to flush its internal register cache.
24912
24913@kindex maint print objfiles
24914@cindex info for known object files
24915@item maint print objfiles
24916Print a dump of all known object files. For each object file, this
24917command prints its name, address in memory, and all of its psymtabs
24918and symtabs.
24919
24920@kindex maint print statistics
24921@cindex bcache statistics
24922@item maint print statistics
24923This command prints, for each object file in the program, various data
24924about that object file followed by the byte cache (@dfn{bcache})
24925statistics for the object file. The objfile data includes the number
d3e8051b 24926of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
24927defined by the objfile, the number of as yet unexpanded psym tables,
24928the number of line tables and string tables, and the amount of memory
24929used by the various tables. The bcache statistics include the counts,
24930sizes, and counts of duplicates of all and unique objects, max,
24931average, and median entry size, total memory used and its overhead and
24932savings, and various measures of the hash table size and chain
24933lengths.
24934
c7ba131e
JB
24935@kindex maint print target-stack
24936@cindex target stack description
24937@item maint print target-stack
24938A @dfn{target} is an interface between the debugger and a particular
24939kind of file or process. Targets can be stacked in @dfn{strata},
24940so that more than one target can potentially respond to a request.
24941In particular, memory accesses will walk down the stack of targets
24942until they find a target that is interested in handling that particular
24943address.
24944
24945This command prints a short description of each layer that was pushed on
24946the @dfn{target stack}, starting from the top layer down to the bottom one.
24947
09d4efe1
EZ
24948@kindex maint print type
24949@cindex type chain of a data type
24950@item maint print type @var{expr}
24951Print the type chain for a type specified by @var{expr}. The argument
24952can be either a type name or a symbol. If it is a symbol, the type of
24953that symbol is described. The type chain produced by this command is
24954a recursive definition of the data type as stored in @value{GDBN}'s
24955data structures, including its flags and contained types.
24956
24957@kindex maint set dwarf2 max-cache-age
24958@kindex maint show dwarf2 max-cache-age
24959@item maint set dwarf2 max-cache-age
24960@itemx maint show dwarf2 max-cache-age
24961Control the DWARF 2 compilation unit cache.
24962
24963@cindex DWARF 2 compilation units cache
24964In object files with inter-compilation-unit references, such as those
24965produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
24966reader needs to frequently refer to previously read compilation units.
24967This setting controls how long a compilation unit will remain in the
24968cache if it is not referenced. A higher limit means that cached
24969compilation units will be stored in memory longer, and more total
24970memory will be used. Setting it to zero disables caching, which will
24971slow down @value{GDBN} startup, but reduce memory consumption.
24972
e7ba9c65
DJ
24973@kindex maint set profile
24974@kindex maint show profile
24975@cindex profiling GDB
24976@item maint set profile
24977@itemx maint show profile
24978Control profiling of @value{GDBN}.
24979
24980Profiling will be disabled until you use the @samp{maint set profile}
24981command to enable it. When you enable profiling, the system will begin
24982collecting timing and execution count data; when you disable profiling or
24983exit @value{GDBN}, the results will be written to a log file. Remember that
24984if you use profiling, @value{GDBN} will overwrite the profiling log file
24985(often called @file{gmon.out}). If you have a record of important profiling
24986data in a @file{gmon.out} file, be sure to move it to a safe location.
24987
24988Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 24989compiled with the @samp{-pg} compiler option.
e7ba9c65 24990
b84876c2
PA
24991@kindex maint set linux-async
24992@kindex maint show linux-async
24993@cindex asynchronous support
24994@item maint set linux-async
24995@itemx maint show linux-async
0606b73b
SL
24996Control the GNU/Linux native asynchronous support
24997(@pxref{Background Execution}) of @value{GDBN}.
b84876c2
PA
24998
24999GNU/Linux native asynchronous support will be disabled until you use
25000the @samp{maint set linux-async} command to enable it.
25001
75c99385
PA
25002@kindex maint set remote-async
25003@kindex maint show remote-async
25004@cindex asynchronous support
25005@item maint set remote-async
25006@itemx maint show remote-async
0606b73b
SL
25007Control the remote asynchronous support
25008(@pxref{Background Execution}) of @value{GDBN}.
75c99385
PA
25009
25010Remote asynchronous support will be disabled until you use
25011the @samp{maint set remote-async} command to enable it.
25012
09d4efe1
EZ
25013@kindex maint show-debug-regs
25014@cindex x86 hardware debug registers
25015@item maint show-debug-regs
25016Control whether to show variables that mirror the x86 hardware debug
25017registers. Use @code{ON} to enable, @code{OFF} to disable. If
3f94c067 25018enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
25019removes a hardware breakpoint or watchpoint, and when the inferior
25020triggers a hardware-assisted breakpoint or watchpoint.
25021
25022@kindex maint space
25023@cindex memory used by commands
25024@item maint space
25025Control whether to display memory usage for each command. If set to a
25026nonzero value, @value{GDBN} will display how much memory each command
25027took, following the command's own output. This can also be requested
25028by invoking @value{GDBN} with the @option{--statistics} command-line
25029switch (@pxref{Mode Options}).
25030
25031@kindex maint time
25032@cindex time of command execution
25033@item maint time
25034Control whether to display the execution time for each command. If
25035set to a nonzero value, @value{GDBN} will display how much time it
25036took to execute each command, following the command's own output.
e2b7ddea
VP
25037The time is not printed for the commands that run the target, since
25038there's no mechanism currently to compute how much time was spend
25039by @value{GDBN} and how much time was spend by the program been debugged.
25040it's not possibly currently
09d4efe1
EZ
25041This can also be requested by invoking @value{GDBN} with the
25042@option{--statistics} command-line switch (@pxref{Mode Options}).
25043
25044@kindex maint translate-address
25045@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
25046Find the symbol stored at the location specified by the address
25047@var{addr} and an optional section name @var{section}. If found,
25048@value{GDBN} prints the name of the closest symbol and an offset from
25049the symbol's location to the specified address. This is similar to
25050the @code{info address} command (@pxref{Symbols}), except that this
25051command also allows to find symbols in other sections.
ae038cb0 25052
c14c28ba
PP
25053If section was not specified, the section in which the symbol was found
25054is also printed. For dynamically linked executables, the name of
25055executable or shared library containing the symbol is printed as well.
25056
8e04817f 25057@end table
c906108c 25058
9c16f35a
EZ
25059The following command is useful for non-interactive invocations of
25060@value{GDBN}, such as in the test suite.
25061
25062@table @code
25063@item set watchdog @var{nsec}
25064@kindex set watchdog
25065@cindex watchdog timer
25066@cindex timeout for commands
25067Set the maximum number of seconds @value{GDBN} will wait for the
25068target operation to finish. If this time expires, @value{GDBN}
25069reports and error and the command is aborted.
25070
25071@item show watchdog
25072Show the current setting of the target wait timeout.
25073@end table
c906108c 25074
e0ce93ac 25075@node Remote Protocol
8e04817f 25076@appendix @value{GDBN} Remote Serial Protocol
c906108c 25077
ee2d5c50
AC
25078@menu
25079* Overview::
25080* Packets::
25081* Stop Reply Packets::
25082* General Query Packets::
25083* Register Packet Format::
9d29849a 25084* Tracepoint Packets::
a6b151f1 25085* Host I/O Packets::
9a6253be 25086* Interrupts::
8b23ecc4
SL
25087* Notification Packets::
25088* Remote Non-Stop::
a6f3e723 25089* Packet Acknowledgment::
ee2d5c50 25090* Examples::
79a6e687 25091* File-I/O Remote Protocol Extension::
cfa9d6d9 25092* Library List Format::
79a6e687 25093* Memory Map Format::
ee2d5c50
AC
25094@end menu
25095
25096@node Overview
25097@section Overview
25098
8e04817f
AC
25099There may be occasions when you need to know something about the
25100protocol---for example, if there is only one serial port to your target
25101machine, you might want your program to do something special if it
25102recognizes a packet meant for @value{GDBN}.
c906108c 25103
d2c6833e 25104In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 25105transmitted and received data, respectively.
c906108c 25106
8e04817f
AC
25107@cindex protocol, @value{GDBN} remote serial
25108@cindex serial protocol, @value{GDBN} remote
25109@cindex remote serial protocol
8b23ecc4
SL
25110All @value{GDBN} commands and responses (other than acknowledgments
25111and notifications, see @ref{Notification Packets}) are sent as a
25112@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
25113@samp{$}, the actual @var{packet-data}, and the terminating character
25114@samp{#} followed by a two-digit @var{checksum}:
c906108c 25115
474c8240 25116@smallexample
8e04817f 25117@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 25118@end smallexample
8e04817f 25119@noindent
c906108c 25120
8e04817f
AC
25121@cindex checksum, for @value{GDBN} remote
25122@noindent
25123The two-digit @var{checksum} is computed as the modulo 256 sum of all
25124characters between the leading @samp{$} and the trailing @samp{#} (an
25125eight bit unsigned checksum).
c906108c 25126
8e04817f
AC
25127Implementors should note that prior to @value{GDBN} 5.0 the protocol
25128specification also included an optional two-digit @var{sequence-id}:
c906108c 25129
474c8240 25130@smallexample
8e04817f 25131@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 25132@end smallexample
c906108c 25133
8e04817f
AC
25134@cindex sequence-id, for @value{GDBN} remote
25135@noindent
25136That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
25137has never output @var{sequence-id}s. Stubs that handle packets added
25138since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 25139
8e04817f
AC
25140When either the host or the target machine receives a packet, the first
25141response expected is an acknowledgment: either @samp{+} (to indicate
25142the package was received correctly) or @samp{-} (to request
25143retransmission):
c906108c 25144
474c8240 25145@smallexample
d2c6833e
AC
25146-> @code{$}@var{packet-data}@code{#}@var{checksum}
25147<- @code{+}
474c8240 25148@end smallexample
8e04817f 25149@noindent
53a5351d 25150
a6f3e723
SL
25151The @samp{+}/@samp{-} acknowledgments can be disabled
25152once a connection is established.
25153@xref{Packet Acknowledgment}, for details.
25154
8e04817f
AC
25155The host (@value{GDBN}) sends @var{command}s, and the target (the
25156debugging stub incorporated in your program) sends a @var{response}. In
25157the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
25158when the operation has completed, and the target has again stopped all
25159threads in all attached processes. This is the default all-stop mode
25160behavior, but the remote protocol also supports @value{GDBN}'s non-stop
25161execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 25162
8e04817f
AC
25163@var{packet-data} consists of a sequence of characters with the
25164exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
25165exceptions).
c906108c 25166
ee2d5c50 25167@cindex remote protocol, field separator
0876f84a 25168Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 25169@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 25170@sc{hex} with leading zeros suppressed.
c906108c 25171
8e04817f
AC
25172Implementors should note that prior to @value{GDBN} 5.0, the character
25173@samp{:} could not appear as the third character in a packet (as it
25174would potentially conflict with the @var{sequence-id}).
c906108c 25175
0876f84a
DJ
25176@cindex remote protocol, binary data
25177@anchor{Binary Data}
25178Binary data in most packets is encoded either as two hexadecimal
25179digits per byte of binary data. This allowed the traditional remote
25180protocol to work over connections which were only seven-bit clean.
25181Some packets designed more recently assume an eight-bit clean
25182connection, and use a more efficient encoding to send and receive
25183binary data.
25184
25185The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
25186as an escape character. Any escaped byte is transmitted as the escape
25187character followed by the original character XORed with @code{0x20}.
25188For example, the byte @code{0x7d} would be transmitted as the two
25189bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
25190@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
25191@samp{@}}) must always be escaped. Responses sent by the stub
25192must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
25193is not interpreted as the start of a run-length encoded sequence
25194(described next).
25195
1d3811f6
DJ
25196Response @var{data} can be run-length encoded to save space.
25197Run-length encoding replaces runs of identical characters with one
25198instance of the repeated character, followed by a @samp{*} and a
25199repeat count. The repeat count is itself sent encoded, to avoid
25200binary characters in @var{data}: a value of @var{n} is sent as
25201@code{@var{n}+29}. For a repeat count greater or equal to 3, this
25202produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
25203code 32) for a repeat count of 3. (This is because run-length
25204encoding starts to win for counts 3 or more.) Thus, for example,
25205@samp{0* } is a run-length encoding of ``0000'': the space character
25206after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
252073}} more times.
25208
25209The printable characters @samp{#} and @samp{$} or with a numeric value
25210greater than 126 must not be used. Runs of six repeats (@samp{#}) or
25211seven repeats (@samp{$}) can be expanded using a repeat count of only
25212five (@samp{"}). For example, @samp{00000000} can be encoded as
25213@samp{0*"00}.
c906108c 25214
8e04817f
AC
25215The error response returned for some packets includes a two character
25216error number. That number is not well defined.
c906108c 25217
f8da2bff 25218@cindex empty response, for unsupported packets
8e04817f
AC
25219For any @var{command} not supported by the stub, an empty response
25220(@samp{$#00}) should be returned. That way it is possible to extend the
25221protocol. A newer @value{GDBN} can tell if a packet is supported based
25222on that response.
c906108c 25223
b383017d
RM
25224A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
25225@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 25226optional.
c906108c 25227
ee2d5c50
AC
25228@node Packets
25229@section Packets
25230
25231The following table provides a complete list of all currently defined
25232@var{command}s and their corresponding response @var{data}.
79a6e687 25233@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 25234I/O extension of the remote protocol.
ee2d5c50 25235
b8ff78ce
JB
25236Each packet's description has a template showing the packet's overall
25237syntax, followed by an explanation of the packet's meaning. We
25238include spaces in some of the templates for clarity; these are not
25239part of the packet's syntax. No @value{GDBN} packet uses spaces to
25240separate its components. For example, a template like @samp{foo
25241@var{bar} @var{baz}} describes a packet beginning with the three ASCII
25242bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 25243@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
25244@samp{foo} and the @var{bar}, or between the @var{bar} and the
25245@var{baz}.
25246
b90a069a
SL
25247@cindex @var{thread-id}, in remote protocol
25248@anchor{thread-id syntax}
25249Several packets and replies include a @var{thread-id} field to identify
25250a thread. Normally these are positive numbers with a target-specific
25251interpretation, formatted as big-endian hex strings. A @var{thread-id}
25252can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
25253pick any thread.
25254
25255In addition, the remote protocol supports a multiprocess feature in
25256which the @var{thread-id} syntax is extended to optionally include both
25257process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
25258The @var{pid} (process) and @var{tid} (thread) components each have the
25259format described above: a positive number with target-specific
25260interpretation formatted as a big-endian hex string, literal @samp{-1}
25261to indicate all processes or threads (respectively), or @samp{0} to
25262indicate an arbitrary process or thread. Specifying just a process, as
25263@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
25264error to specify all processes but a specific thread, such as
25265@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
25266for those packets and replies explicitly documented to include a process
25267ID, rather than a @var{thread-id}.
25268
25269The multiprocess @var{thread-id} syntax extensions are only used if both
25270@value{GDBN} and the stub report support for the @samp{multiprocess}
25271feature using @samp{qSupported}. @xref{multiprocess extensions}, for
25272more information.
25273
8ffe2530
JB
25274Note that all packet forms beginning with an upper- or lower-case
25275letter, other than those described here, are reserved for future use.
25276
b8ff78ce 25277Here are the packet descriptions.
ee2d5c50 25278
b8ff78ce 25279@table @samp
ee2d5c50 25280
b8ff78ce
JB
25281@item !
25282@cindex @samp{!} packet
2d717e4f 25283@anchor{extended mode}
8e04817f
AC
25284Enable extended mode. In extended mode, the remote server is made
25285persistent. The @samp{R} packet is used to restart the program being
25286debugged.
ee2d5c50
AC
25287
25288Reply:
25289@table @samp
25290@item OK
8e04817f 25291The remote target both supports and has enabled extended mode.
ee2d5c50 25292@end table
c906108c 25293
b8ff78ce
JB
25294@item ?
25295@cindex @samp{?} packet
ee2d5c50 25296Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
25297step and continue. This packet has a special interpretation when the
25298target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 25299
ee2d5c50
AC
25300Reply:
25301@xref{Stop Reply Packets}, for the reply specifications.
25302
b8ff78ce
JB
25303@item A @var{arglen},@var{argnum},@var{arg},@dots{}
25304@cindex @samp{A} packet
25305Initialized @code{argv[]} array passed into program. @var{arglen}
25306specifies the number of bytes in the hex encoded byte stream
25307@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
25308
25309Reply:
25310@table @samp
25311@item OK
b8ff78ce
JB
25312The arguments were set.
25313@item E @var{NN}
25314An error occurred.
ee2d5c50
AC
25315@end table
25316
b8ff78ce
JB
25317@item b @var{baud}
25318@cindex @samp{b} packet
25319(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
25320Change the serial line speed to @var{baud}.
25321
25322JTC: @emph{When does the transport layer state change? When it's
25323received, or after the ACK is transmitted. In either case, there are
25324problems if the command or the acknowledgment packet is dropped.}
25325
25326Stan: @emph{If people really wanted to add something like this, and get
25327it working for the first time, they ought to modify ser-unix.c to send
25328some kind of out-of-band message to a specially-setup stub and have the
25329switch happen "in between" packets, so that from remote protocol's point
25330of view, nothing actually happened.}
25331
b8ff78ce
JB
25332@item B @var{addr},@var{mode}
25333@cindex @samp{B} packet
8e04817f 25334Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
25335breakpoint at @var{addr}.
25336
b8ff78ce 25337Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 25338(@pxref{insert breakpoint or watchpoint packet}).
c906108c 25339
bacec72f
MS
25340@item bc
25341@cindex @samp{bc} packet
25342Backward continue. Execute the target system in reverse. No parameter.
25343@xref{Reverse Execution}, for more information.
25344
25345Reply:
25346@xref{Stop Reply Packets}, for the reply specifications.
25347
25348@item bs
25349@cindex @samp{bs} packet
25350Backward single step. Execute one instruction in reverse. No parameter.
25351@xref{Reverse Execution}, for more information.
25352
25353Reply:
25354@xref{Stop Reply Packets}, for the reply specifications.
25355
4f553f88 25356@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
25357@cindex @samp{c} packet
25358Continue. @var{addr} is address to resume. If @var{addr} is omitted,
25359resume at current address.
c906108c 25360
ee2d5c50
AC
25361Reply:
25362@xref{Stop Reply Packets}, for the reply specifications.
25363
4f553f88 25364@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 25365@cindex @samp{C} packet
8e04817f 25366Continue with signal @var{sig} (hex signal number). If
b8ff78ce 25367@samp{;@var{addr}} is omitted, resume at same address.
c906108c 25368
ee2d5c50
AC
25369Reply:
25370@xref{Stop Reply Packets}, for the reply specifications.
c906108c 25371
b8ff78ce
JB
25372@item d
25373@cindex @samp{d} packet
ee2d5c50
AC
25374Toggle debug flag.
25375
b8ff78ce
JB
25376Don't use this packet; instead, define a general set packet
25377(@pxref{General Query Packets}).
ee2d5c50 25378
b8ff78ce 25379@item D
b90a069a 25380@itemx D;@var{pid}
b8ff78ce 25381@cindex @samp{D} packet
b90a069a
SL
25382The first form of the packet is used to detach @value{GDBN} from the
25383remote system. It is sent to the remote target
07f31aa6 25384before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 25385
b90a069a
SL
25386The second form, including a process ID, is used when multiprocess
25387protocol extensions are enabled (@pxref{multiprocess extensions}), to
25388detach only a specific process. The @var{pid} is specified as a
25389big-endian hex string.
25390
ee2d5c50
AC
25391Reply:
25392@table @samp
10fac096
NW
25393@item OK
25394for success
b8ff78ce 25395@item E @var{NN}
10fac096 25396for an error
ee2d5c50 25397@end table
c906108c 25398
b8ff78ce
JB
25399@item F @var{RC},@var{EE},@var{CF};@var{XX}
25400@cindex @samp{F} packet
25401A reply from @value{GDBN} to an @samp{F} packet sent by the target.
25402This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 25403Remote Protocol Extension}, for the specification.
ee2d5c50 25404
b8ff78ce 25405@item g
ee2d5c50 25406@anchor{read registers packet}
b8ff78ce 25407@cindex @samp{g} packet
ee2d5c50
AC
25408Read general registers.
25409
25410Reply:
25411@table @samp
25412@item @var{XX@dots{}}
8e04817f
AC
25413Each byte of register data is described by two hex digits. The bytes
25414with the register are transmitted in target byte order. The size of
b8ff78ce 25415each register and their position within the @samp{g} packet are
4a9bb1df
UW
25416determined by the @value{GDBN} internal gdbarch functions
25417@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce
JB
25418specification of several standard @samp{g} packets is specified below.
25419@item E @var{NN}
ee2d5c50
AC
25420for an error.
25421@end table
c906108c 25422
b8ff78ce
JB
25423@item G @var{XX@dots{}}
25424@cindex @samp{G} packet
25425Write general registers. @xref{read registers packet}, for a
25426description of the @var{XX@dots{}} data.
ee2d5c50
AC
25427
25428Reply:
25429@table @samp
25430@item OK
25431for success
b8ff78ce 25432@item E @var{NN}
ee2d5c50
AC
25433for an error
25434@end table
25435
b90a069a 25436@item H @var{c} @var{thread-id}
b8ff78ce 25437@cindex @samp{H} packet
8e04817f 25438Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
25439@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
25440should be @samp{c} for step and continue operations, @samp{g} for other
b90a069a
SL
25441operations. The thread designator @var{thread-id} has the format and
25442interpretation described in @ref{thread-id syntax}.
ee2d5c50
AC
25443
25444Reply:
25445@table @samp
25446@item OK
25447for success
b8ff78ce 25448@item E @var{NN}
ee2d5c50
AC
25449for an error
25450@end table
c906108c 25451
8e04817f
AC
25452@c FIXME: JTC:
25453@c 'H': How restrictive (or permissive) is the thread model. If a
25454@c thread is selected and stopped, are other threads allowed
25455@c to continue to execute? As I mentioned above, I think the
25456@c semantics of each command when a thread is selected must be
25457@c described. For example:
25458@c
25459@c 'g': If the stub supports threads and a specific thread is
25460@c selected, returns the register block from that thread;
25461@c otherwise returns current registers.
25462@c
25463@c 'G' If the stub supports threads and a specific thread is
25464@c selected, sets the registers of the register block of
25465@c that thread; otherwise sets current registers.
c906108c 25466
b8ff78ce 25467@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 25468@anchor{cycle step packet}
b8ff78ce
JB
25469@cindex @samp{i} packet
25470Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
25471present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
25472step starting at that address.
c906108c 25473
b8ff78ce
JB
25474@item I
25475@cindex @samp{I} packet
25476Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
25477step packet}.
ee2d5c50 25478
b8ff78ce
JB
25479@item k
25480@cindex @samp{k} packet
25481Kill request.
c906108c 25482
ac282366 25483FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
25484thread context has been selected (i.e.@: does 'k' kill only that
25485thread?)}.
c906108c 25486
b8ff78ce
JB
25487@item m @var{addr},@var{length}
25488@cindex @samp{m} packet
8e04817f 25489Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
25490Note that @var{addr} may not be aligned to any particular boundary.
25491
25492The stub need not use any particular size or alignment when gathering
25493data from memory for the response; even if @var{addr} is word-aligned
25494and @var{length} is a multiple of the word size, the stub is free to
25495use byte accesses, or not. For this reason, this packet may not be
25496suitable for accessing memory-mapped I/O devices.
c43c5473
JB
25497@cindex alignment of remote memory accesses
25498@cindex size of remote memory accesses
25499@cindex memory, alignment and size of remote accesses
c906108c 25500
ee2d5c50
AC
25501Reply:
25502@table @samp
25503@item @var{XX@dots{}}
599b237a 25504Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
25505number. The reply may contain fewer bytes than requested if the
25506server was able to read only part of the region of memory.
25507@item E @var{NN}
ee2d5c50
AC
25508@var{NN} is errno
25509@end table
25510
b8ff78ce
JB
25511@item M @var{addr},@var{length}:@var{XX@dots{}}
25512@cindex @samp{M} packet
8e04817f 25513Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 25514@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 25515hexadecimal number.
ee2d5c50
AC
25516
25517Reply:
25518@table @samp
25519@item OK
25520for success
b8ff78ce 25521@item E @var{NN}
8e04817f
AC
25522for an error (this includes the case where only part of the data was
25523written).
ee2d5c50 25524@end table
c906108c 25525
b8ff78ce
JB
25526@item p @var{n}
25527@cindex @samp{p} packet
25528Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
25529@xref{read registers packet}, for a description of how the returned
25530register value is encoded.
ee2d5c50
AC
25531
25532Reply:
25533@table @samp
2e868123
AC
25534@item @var{XX@dots{}}
25535the register's value
b8ff78ce 25536@item E @var{NN}
2e868123
AC
25537for an error
25538@item
25539Indicating an unrecognized @var{query}.
ee2d5c50
AC
25540@end table
25541
b8ff78ce 25542@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 25543@anchor{write register packet}
b8ff78ce
JB
25544@cindex @samp{P} packet
25545Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 25546number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 25547digits for each byte in the register (target byte order).
c906108c 25548
ee2d5c50
AC
25549Reply:
25550@table @samp
25551@item OK
25552for success
b8ff78ce 25553@item E @var{NN}
ee2d5c50
AC
25554for an error
25555@end table
25556
5f3bebba
JB
25557@item q @var{name} @var{params}@dots{}
25558@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 25559@cindex @samp{q} packet
b8ff78ce 25560@cindex @samp{Q} packet
5f3bebba
JB
25561General query (@samp{q}) and set (@samp{Q}). These packets are
25562described fully in @ref{General Query Packets}.
c906108c 25563
b8ff78ce
JB
25564@item r
25565@cindex @samp{r} packet
8e04817f 25566Reset the entire system.
c906108c 25567
b8ff78ce 25568Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 25569
b8ff78ce
JB
25570@item R @var{XX}
25571@cindex @samp{R} packet
8e04817f 25572Restart the program being debugged. @var{XX}, while needed, is ignored.
2d717e4f 25573This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 25574
8e04817f 25575The @samp{R} packet has no reply.
ee2d5c50 25576
4f553f88 25577@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
25578@cindex @samp{s} packet
25579Single step. @var{addr} is the address at which to resume. If
25580@var{addr} is omitted, resume at same address.
c906108c 25581
ee2d5c50
AC
25582Reply:
25583@xref{Stop Reply Packets}, for the reply specifications.
25584
4f553f88 25585@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 25586@anchor{step with signal packet}
b8ff78ce
JB
25587@cindex @samp{S} packet
25588Step with signal. This is analogous to the @samp{C} packet, but
25589requests a single-step, rather than a normal resumption of execution.
c906108c 25590
ee2d5c50
AC
25591Reply:
25592@xref{Stop Reply Packets}, for the reply specifications.
25593
b8ff78ce
JB
25594@item t @var{addr}:@var{PP},@var{MM}
25595@cindex @samp{t} packet
8e04817f 25596Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
25597@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
25598@var{addr} must be at least 3 digits.
c906108c 25599
b90a069a 25600@item T @var{thread-id}
b8ff78ce 25601@cindex @samp{T} packet
b90a069a 25602Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 25603
ee2d5c50
AC
25604Reply:
25605@table @samp
25606@item OK
25607thread is still alive
b8ff78ce 25608@item E @var{NN}
ee2d5c50
AC
25609thread is dead
25610@end table
25611
b8ff78ce
JB
25612@item v
25613Packets starting with @samp{v} are identified by a multi-letter name,
25614up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 25615
2d717e4f
DJ
25616@item vAttach;@var{pid}
25617@cindex @samp{vAttach} packet
8b23ecc4
SL
25618Attach to a new process with the specified process ID @var{pid}.
25619The process ID is a
25620hexadecimal integer identifying the process. In all-stop mode, all
25621threads in the attached process are stopped; in non-stop mode, it may be
25622attached without being stopped if that is supported by the target.
25623
25624@c In non-stop mode, on a successful vAttach, the stub should set the
25625@c current thread to a thread of the newly-attached process. After
25626@c attaching, GDB queries for the attached process's thread ID with qC.
25627@c Also note that, from a user perspective, whether or not the
25628@c target is stopped on attach in non-stop mode depends on whether you
25629@c use the foreground or background version of the attach command, not
25630@c on what vAttach does; GDB does the right thing with respect to either
25631@c stopping or restarting threads.
2d717e4f
DJ
25632
25633This packet is only available in extended mode (@pxref{extended mode}).
25634
25635Reply:
25636@table @samp
25637@item E @var{nn}
25638for an error
25639@item @r{Any stop packet}
8b23ecc4
SL
25640for success in all-stop mode (@pxref{Stop Reply Packets})
25641@item OK
25642for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
25643@end table
25644
b90a069a 25645@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce
JB
25646@cindex @samp{vCont} packet
25647Resume the inferior, specifying different actions for each thread.
b90a069a 25648If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 25649threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
25650specified then other threads should remain stopped in all-stop mode and
25651in their current state in non-stop mode.
25652Specifying multiple
86d30acc 25653default actions is an error; specifying no actions is also an error.
b90a069a
SL
25654Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
25655
25656Currently supported actions are:
86d30acc 25657
b8ff78ce 25658@table @samp
86d30acc
DJ
25659@item c
25660Continue.
b8ff78ce 25661@item C @var{sig}
8b23ecc4 25662Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
25663@item s
25664Step.
b8ff78ce 25665@item S @var{sig}
8b23ecc4
SL
25666Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
25667@item t
25668Stop.
25669@item T @var{sig}
25670Stop with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
25671@end table
25672
8b23ecc4
SL
25673The optional argument @var{addr} normally associated with the
25674@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 25675not supported in @samp{vCont}.
86d30acc 25676
8b23ecc4
SL
25677The @samp{t} and @samp{T} actions are only relevant in non-stop mode
25678(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
25679A stop reply should be generated for any affected thread not already stopped.
25680When a thread is stopped by means of a @samp{t} action,
25681the corresponding stop reply should indicate that the thread has stopped with
25682signal @samp{0}, regardless of whether the target uses some other signal
25683as an implementation detail.
25684
86d30acc
DJ
25685Reply:
25686@xref{Stop Reply Packets}, for the reply specifications.
25687
b8ff78ce
JB
25688@item vCont?
25689@cindex @samp{vCont?} packet
d3e8051b 25690Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
25691
25692Reply:
25693@table @samp
b8ff78ce
JB
25694@item vCont@r{[};@var{action}@dots{}@r{]}
25695The @samp{vCont} packet is supported. Each @var{action} is a supported
25696command in the @samp{vCont} packet.
86d30acc 25697@item
b8ff78ce 25698The @samp{vCont} packet is not supported.
86d30acc 25699@end table
ee2d5c50 25700
a6b151f1
DJ
25701@item vFile:@var{operation}:@var{parameter}@dots{}
25702@cindex @samp{vFile} packet
25703Perform a file operation on the target system. For details,
25704see @ref{Host I/O Packets}.
25705
68437a39
DJ
25706@item vFlashErase:@var{addr},@var{length}
25707@cindex @samp{vFlashErase} packet
25708Direct the stub to erase @var{length} bytes of flash starting at
25709@var{addr}. The region may enclose any number of flash blocks, but
25710its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
25711flash block size appearing in the memory map (@pxref{Memory Map
25712Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
25713together, and sends a @samp{vFlashDone} request after each group; the
25714stub is allowed to delay erase operation until the @samp{vFlashDone}
25715packet is received.
25716
b90a069a
SL
25717The stub must support @samp{vCont} if it reports support for
25718multiprocess extensions (@pxref{multiprocess extensions}). Note that in
25719this case @samp{vCont} actions can be specified to apply to all threads
25720in a process by using the @samp{p@var{pid}.-1} form of the
25721@var{thread-id}.
25722
68437a39
DJ
25723Reply:
25724@table @samp
25725@item OK
25726for success
25727@item E @var{NN}
25728for an error
25729@end table
25730
25731@item vFlashWrite:@var{addr}:@var{XX@dots{}}
25732@cindex @samp{vFlashWrite} packet
25733Direct the stub to write data to flash address @var{addr}. The data
25734is passed in binary form using the same encoding as for the @samp{X}
25735packet (@pxref{Binary Data}). The memory ranges specified by
25736@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
25737not overlap, and must appear in order of increasing addresses
25738(although @samp{vFlashErase} packets for higher addresses may already
25739have been received; the ordering is guaranteed only between
25740@samp{vFlashWrite} packets). If a packet writes to an address that was
25741neither erased by a preceding @samp{vFlashErase} packet nor by some other
25742target-specific method, the results are unpredictable.
25743
25744
25745Reply:
25746@table @samp
25747@item OK
25748for success
25749@item E.memtype
25750for vFlashWrite addressing non-flash memory
25751@item E @var{NN}
25752for an error
25753@end table
25754
25755@item vFlashDone
25756@cindex @samp{vFlashDone} packet
25757Indicate to the stub that flash programming operation is finished.
25758The stub is permitted to delay or batch the effects of a group of
25759@samp{vFlashErase} and @samp{vFlashWrite} packets until a
25760@samp{vFlashDone} packet is received. The contents of the affected
25761regions of flash memory are unpredictable until the @samp{vFlashDone}
25762request is completed.
25763
b90a069a
SL
25764@item vKill;@var{pid}
25765@cindex @samp{vKill} packet
25766Kill the process with the specified process ID. @var{pid} is a
25767hexadecimal integer identifying the process. This packet is used in
25768preference to @samp{k} when multiprocess protocol extensions are
25769supported; see @ref{multiprocess extensions}.
25770
25771Reply:
25772@table @samp
25773@item E @var{nn}
25774for an error
25775@item OK
25776for success
25777@end table
25778
2d717e4f
DJ
25779@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
25780@cindex @samp{vRun} packet
25781Run the program @var{filename}, passing it each @var{argument} on its
25782command line. The file and arguments are hex-encoded strings. If
25783@var{filename} is an empty string, the stub may use a default program
25784(e.g.@: the last program run). The program is created in the stopped
9b562ab8 25785state.
2d717e4f 25786
8b23ecc4
SL
25787@c FIXME: What about non-stop mode?
25788
2d717e4f
DJ
25789This packet is only available in extended mode (@pxref{extended mode}).
25790
25791Reply:
25792@table @samp
25793@item E @var{nn}
25794for an error
25795@item @r{Any stop packet}
25796for success (@pxref{Stop Reply Packets})
25797@end table
25798
8b23ecc4
SL
25799@item vStopped
25800@anchor{vStopped packet}
25801@cindex @samp{vStopped} packet
25802
25803In non-stop mode (@pxref{Remote Non-Stop}), acknowledge a previous stop
25804reply and prompt for the stub to report another one.
25805
25806Reply:
25807@table @samp
25808@item @r{Any stop packet}
25809if there is another unreported stop event (@pxref{Stop Reply Packets})
25810@item OK
25811if there are no unreported stop events
25812@end table
25813
b8ff78ce 25814@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 25815@anchor{X packet}
b8ff78ce
JB
25816@cindex @samp{X} packet
25817Write data to memory, where the data is transmitted in binary.
25818@var{addr} is address, @var{length} is number of bytes,
0876f84a 25819@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 25820
ee2d5c50
AC
25821Reply:
25822@table @samp
25823@item OK
25824for success
b8ff78ce 25825@item E @var{NN}
ee2d5c50
AC
25826for an error
25827@end table
25828
b8ff78ce
JB
25829@item z @var{type},@var{addr},@var{length}
25830@itemx Z @var{type},@var{addr},@var{length}
2f870471 25831@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
25832@cindex @samp{z} packet
25833@cindex @samp{Z} packets
25834Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
2f870471
AC
25835watchpoint starting at address @var{address} and covering the next
25836@var{length} bytes.
ee2d5c50 25837
2f870471
AC
25838Each breakpoint and watchpoint packet @var{type} is documented
25839separately.
25840
512217c7
AC
25841@emph{Implementation notes: A remote target shall return an empty string
25842for an unrecognized breakpoint or watchpoint packet @var{type}. A
25843remote target shall support either both or neither of a given
b8ff78ce 25844@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
25845avoid potential problems with duplicate packets, the operations should
25846be implemented in an idempotent way.}
25847
b8ff78ce
JB
25848@item z0,@var{addr},@var{length}
25849@itemx Z0,@var{addr},@var{length}
25850@cindex @samp{z0} packet
25851@cindex @samp{Z0} packet
25852Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
25853@var{addr} of size @var{length}.
2f870471
AC
25854
25855A memory breakpoint is implemented by replacing the instruction at
25856@var{addr} with a software breakpoint or trap instruction. The
b8ff78ce 25857@var{length} is used by targets that indicates the size of the
2f870471
AC
25858breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
25859@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 25860
2f870471
AC
25861@emph{Implementation note: It is possible for a target to copy or move
25862code that contains memory breakpoints (e.g., when implementing
25863overlays). The behavior of this packet, in the presence of such a
25864target, is not defined.}
c906108c 25865
ee2d5c50
AC
25866Reply:
25867@table @samp
2f870471
AC
25868@item OK
25869success
25870@item
25871not supported
b8ff78ce 25872@item E @var{NN}
ee2d5c50 25873for an error
2f870471
AC
25874@end table
25875
b8ff78ce
JB
25876@item z1,@var{addr},@var{length}
25877@itemx Z1,@var{addr},@var{length}
25878@cindex @samp{z1} packet
25879@cindex @samp{Z1} packet
25880Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
25881address @var{addr} of size @var{length}.
2f870471
AC
25882
25883A hardware breakpoint is implemented using a mechanism that is not
25884dependant on being able to modify the target's memory.
25885
25886@emph{Implementation note: A hardware breakpoint is not affected by code
25887movement.}
25888
25889Reply:
25890@table @samp
ee2d5c50 25891@item OK
2f870471
AC
25892success
25893@item
25894not supported
b8ff78ce 25895@item E @var{NN}
2f870471
AC
25896for an error
25897@end table
25898
b8ff78ce
JB
25899@item z2,@var{addr},@var{length}
25900@itemx Z2,@var{addr},@var{length}
25901@cindex @samp{z2} packet
25902@cindex @samp{Z2} packet
25903Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
2f870471
AC
25904
25905Reply:
25906@table @samp
25907@item OK
25908success
25909@item
25910not supported
b8ff78ce 25911@item E @var{NN}
2f870471
AC
25912for an error
25913@end table
25914
b8ff78ce
JB
25915@item z3,@var{addr},@var{length}
25916@itemx Z3,@var{addr},@var{length}
25917@cindex @samp{z3} packet
25918@cindex @samp{Z3} packet
25919Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
2f870471
AC
25920
25921Reply:
25922@table @samp
25923@item OK
25924success
25925@item
25926not supported
b8ff78ce 25927@item E @var{NN}
2f870471
AC
25928for an error
25929@end table
25930
b8ff78ce
JB
25931@item z4,@var{addr},@var{length}
25932@itemx Z4,@var{addr},@var{length}
25933@cindex @samp{z4} packet
25934@cindex @samp{Z4} packet
25935Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
2f870471
AC
25936
25937Reply:
25938@table @samp
25939@item OK
25940success
25941@item
25942not supported
b8ff78ce 25943@item E @var{NN}
2f870471 25944for an error
ee2d5c50
AC
25945@end table
25946
25947@end table
c906108c 25948
ee2d5c50
AC
25949@node Stop Reply Packets
25950@section Stop Reply Packets
25951@cindex stop reply packets
c906108c 25952
8b23ecc4
SL
25953The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
25954@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
25955receive any of the below as a reply. Except for @samp{?}
25956and @samp{vStopped}, that reply is only returned
b8ff78ce 25957when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
25958number} is defined by the header @file{include/gdb/signals.h} in the
25959@value{GDBN} source code.
c906108c 25960
b8ff78ce
JB
25961As in the description of request packets, we include spaces in the
25962reply templates for clarity; these are not part of the reply packet's
25963syntax. No @value{GDBN} stop reply packet uses spaces to separate its
25964components.
c906108c 25965
b8ff78ce 25966@table @samp
ee2d5c50 25967
b8ff78ce 25968@item S @var{AA}
599b237a 25969The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
25970number). This is equivalent to a @samp{T} response with no
25971@var{n}:@var{r} pairs.
c906108c 25972
b8ff78ce
JB
25973@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
25974@cindex @samp{T} packet reply
599b237a 25975The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
25976number). This is equivalent to an @samp{S} response, except that the
25977@samp{@var{n}:@var{r}} pairs can carry values of important registers
25978and other information directly in the stop reply packet, reducing
25979round-trip latency. Single-step and breakpoint traps are reported
25980this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
25981
25982@itemize @bullet
b8ff78ce 25983@item
599b237a 25984If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
25985corresponding @var{r} gives that register's value. @var{r} is a
25986series of bytes in target byte order, with each byte given by a
25987two-digit hex number.
cfa9d6d9 25988
b8ff78ce 25989@item
b90a069a
SL
25990If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
25991the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 25992
b8ff78ce 25993@item
cfa9d6d9
DJ
25994If @var{n} is a recognized @dfn{stop reason}, it describes a more
25995specific event that stopped the target. The currently defined stop
25996reasons are listed below. @var{aa} should be @samp{05}, the trap
25997signal. At most one stop reason should be present.
25998
b8ff78ce
JB
25999@item
26000Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
26001and go on to the next; this allows us to extend the protocol in the
26002future.
cfa9d6d9
DJ
26003@end itemize
26004
26005The currently defined stop reasons are:
26006
26007@table @samp
26008@item watch
26009@itemx rwatch
26010@itemx awatch
26011The packet indicates a watchpoint hit, and @var{r} is the data address, in
26012hex.
26013
26014@cindex shared library events, remote reply
26015@item library
26016The packet indicates that the loaded libraries have changed.
26017@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
26018list of loaded libraries. @var{r} is ignored.
bacec72f
MS
26019
26020@cindex replay log events, remote reply
26021@item replaylog
26022The packet indicates that the target cannot continue replaying
26023logged execution events, because it has reached the end (or the
26024beginning when executing backward) of the log. The value of @var{r}
26025will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
26026for more information.
26027
26028
cfa9d6d9 26029@end table
ee2d5c50 26030
b8ff78ce 26031@item W @var{AA}
b90a069a 26032@itemx W @var{AA} ; process:@var{pid}
8e04817f 26033The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
26034applicable to certain targets.
26035
b90a069a
SL
26036The second form of the response, including the process ID of the exited
26037process, can be used only when @value{GDBN} has reported support for
26038multiprocess protocol extensions; see @ref{multiprocess extensions}.
26039The @var{pid} is formatted as a big-endian hex string.
26040
b8ff78ce 26041@item X @var{AA}
b90a069a 26042@itemx X @var{AA} ; process:@var{pid}
8e04817f 26043The process terminated with signal @var{AA}.
c906108c 26044
b90a069a
SL
26045The second form of the response, including the process ID of the
26046terminated process, can be used only when @value{GDBN} has reported
26047support for multiprocess protocol extensions; see @ref{multiprocess
26048extensions}. The @var{pid} is formatted as a big-endian hex string.
26049
b8ff78ce
JB
26050@item O @var{XX}@dots{}
26051@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
26052written as the program's console output. This can happen at any time
26053while the program is running and the debugger should continue to wait
8b23ecc4 26054for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 26055
b8ff78ce 26056@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
26057@var{call-id} is the identifier which says which host system call should
26058be called. This is just the name of the function. Translation into the
26059correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 26060@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
26061system calls.
26062
b8ff78ce
JB
26063@samp{@var{parameter}@dots{}} is a list of parameters as defined for
26064this very system call.
0ce1b118 26065
b8ff78ce
JB
26066The target replies with this packet when it expects @value{GDBN} to
26067call a host system call on behalf of the target. @value{GDBN} replies
26068with an appropriate @samp{F} packet and keeps up waiting for the next
26069reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
26070or @samp{s} action is expected to be continued. @xref{File-I/O Remote
26071Protocol Extension}, for more details.
0ce1b118 26072
ee2d5c50
AC
26073@end table
26074
26075@node General Query Packets
26076@section General Query Packets
9c16f35a 26077@cindex remote query requests
c906108c 26078
5f3bebba
JB
26079Packets starting with @samp{q} are @dfn{general query packets};
26080packets starting with @samp{Q} are @dfn{general set packets}. General
26081query and set packets are a semi-unified form for retrieving and
26082sending information to and from the stub.
26083
26084The initial letter of a query or set packet is followed by a name
26085indicating what sort of thing the packet applies to. For example,
26086@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
26087definitions with the stub. These packet names follow some
26088conventions:
26089
26090@itemize @bullet
26091@item
26092The name must not contain commas, colons or semicolons.
26093@item
26094Most @value{GDBN} query and set packets have a leading upper case
26095letter.
26096@item
26097The names of custom vendor packets should use a company prefix, in
26098lower case, followed by a period. For example, packets designed at
26099the Acme Corporation might begin with @samp{qacme.foo} (for querying
26100foos) or @samp{Qacme.bar} (for setting bars).
26101@end itemize
26102
aa56d27a
JB
26103The name of a query or set packet should be separated from any
26104parameters by a @samp{:}; the parameters themselves should be
26105separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
26106full packet name, and check for a separator or the end of the packet,
26107in case two packet names share a common prefix. New packets should not begin
26108with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
26109packets predate these conventions, and have arguments without any terminator
26110for the packet name; we suspect they are in widespread use in places that
26111are difficult to upgrade. The @samp{qC} packet has no arguments, but some
26112existing stubs (e.g.@: RedBoot) are known to not check for the end of the
26113packet.}.
c906108c 26114
b8ff78ce
JB
26115Like the descriptions of the other packets, each description here
26116has a template showing the packet's overall syntax, followed by an
26117explanation of the packet's meaning. We include spaces in some of the
26118templates for clarity; these are not part of the packet's syntax. No
26119@value{GDBN} packet uses spaces to separate its components.
26120
5f3bebba
JB
26121Here are the currently defined query and set packets:
26122
b8ff78ce 26123@table @samp
c906108c 26124
b8ff78ce 26125@item qC
9c16f35a 26126@cindex current thread, remote request
b8ff78ce 26127@cindex @samp{qC} packet
b90a069a 26128Return the current thread ID.
ee2d5c50
AC
26129
26130Reply:
26131@table @samp
b90a069a
SL
26132@item QC @var{thread-id}
26133Where @var{thread-id} is a thread ID as documented in
26134@ref{thread-id syntax}.
b8ff78ce 26135@item @r{(anything else)}
b90a069a 26136Any other reply implies the old thread ID.
ee2d5c50
AC
26137@end table
26138
b8ff78ce 26139@item qCRC:@var{addr},@var{length}
ff2587ec 26140@cindex CRC of memory block, remote request
b8ff78ce
JB
26141@cindex @samp{qCRC} packet
26142Compute the CRC checksum of a block of memory.
ff2587ec
WZ
26143Reply:
26144@table @samp
b8ff78ce 26145@item E @var{NN}
ff2587ec 26146An error (such as memory fault)
b8ff78ce
JB
26147@item C @var{crc32}
26148The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
26149@end table
26150
b8ff78ce
JB
26151@item qfThreadInfo
26152@itemx qsThreadInfo
9c16f35a 26153@cindex list active threads, remote request
b8ff78ce
JB
26154@cindex @samp{qfThreadInfo} packet
26155@cindex @samp{qsThreadInfo} packet
b90a069a 26156Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
26157may be too many active threads to fit into one reply packet, this query
26158works iteratively: it may require more than one query/reply sequence to
26159obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
26160be the @samp{qfThreadInfo} query; subsequent queries in the
26161sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 26162
b8ff78ce 26163NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
26164
26165Reply:
26166@table @samp
b90a069a
SL
26167@item m @var{thread-id}
26168A single thread ID
26169@item m @var{thread-id},@var{thread-id}@dots{}
26170a comma-separated list of thread IDs
b8ff78ce
JB
26171@item l
26172(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
26173@end table
26174
26175In response to each query, the target will reply with a list of one or
b90a069a 26176more thread IDs, separated by commas.
e1aac25b 26177@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 26178ids (using the @samp{qs} form of the query), until the target responds
b90a069a
SL
26179with @samp{l} (lower-case el, for @dfn{last}).
26180Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
26181fields.
c906108c 26182
b8ff78ce 26183@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 26184@cindex get thread-local storage address, remote request
b8ff78ce 26185@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
26186Fetch the address associated with thread local storage specified
26187by @var{thread-id}, @var{offset}, and @var{lm}.
26188
b90a069a
SL
26189@var{thread-id} is the thread ID associated with the
26190thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
26191
26192@var{offset} is the (big endian, hex encoded) offset associated with the
26193thread local variable. (This offset is obtained from the debug
26194information associated with the variable.)
26195
db2e3e2e 26196@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
ff2587ec
WZ
26197the load module associated with the thread local storage. For example,
26198a @sc{gnu}/Linux system will pass the link map address of the shared
26199object associated with the thread local storage under consideration.
26200Other operating environments may choose to represent the load module
26201differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
26202
26203Reply:
b8ff78ce
JB
26204@table @samp
26205@item @var{XX}@dots{}
ff2587ec
WZ
26206Hex encoded (big endian) bytes representing the address of the thread
26207local storage requested.
26208
b8ff78ce
JB
26209@item E @var{nn}
26210An error occurred. @var{nn} are hex digits.
ff2587ec 26211
b8ff78ce
JB
26212@item
26213An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
26214@end table
26215
b8ff78ce 26216@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
26217Obtain thread information from RTOS. Where: @var{startflag} (one hex
26218digit) is one to indicate the first query and zero to indicate a
26219subsequent query; @var{threadcount} (two hex digits) is the maximum
26220number of threads the response packet can contain; and @var{nextthread}
26221(eight hex digits), for subsequent queries (@var{startflag} is zero), is
26222returned in the response as @var{argthread}.
ee2d5c50 26223
b8ff78ce 26224Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
26225
26226Reply:
26227@table @samp
b8ff78ce 26228@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
26229Where: @var{count} (two hex digits) is the number of threads being
26230returned; @var{done} (one hex digit) is zero to indicate more threads
26231and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 26232digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 26233is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 26234digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 26235@end table
c906108c 26236
b8ff78ce 26237@item qOffsets
9c16f35a 26238@cindex section offsets, remote request
b8ff78ce 26239@cindex @samp{qOffsets} packet
31d99776
DJ
26240Get section offsets that the target used when relocating the downloaded
26241image.
c906108c 26242
ee2d5c50
AC
26243Reply:
26244@table @samp
31d99776
DJ
26245@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
26246Relocate the @code{Text} section by @var{xxx} from its original address.
26247Relocate the @code{Data} section by @var{yyy} from its original address.
26248If the object file format provides segment information (e.g.@: @sc{elf}
26249@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
26250segments by the supplied offsets.
26251
26252@emph{Note: while a @code{Bss} offset may be included in the response,
26253@value{GDBN} ignores this and instead applies the @code{Data} offset
26254to the @code{Bss} section.}
26255
26256@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
26257Relocate the first segment of the object file, which conventionally
26258contains program code, to a starting address of @var{xxx}. If
26259@samp{DataSeg} is specified, relocate the second segment, which
26260conventionally contains modifiable data, to a starting address of
26261@var{yyy}. @value{GDBN} will report an error if the object file
26262does not contain segment information, or does not contain at least
26263as many segments as mentioned in the reply. Extra segments are
26264kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
26265@end table
26266
b90a069a 26267@item qP @var{mode} @var{thread-id}
9c16f35a 26268@cindex thread information, remote request
b8ff78ce 26269@cindex @samp{qP} packet
b90a069a
SL
26270Returns information on @var{thread-id}. Where: @var{mode} is a hex
26271encoded 32 bit mode; @var{thread-id} is a thread ID
26272(@pxref{thread-id syntax}).
ee2d5c50 26273
aa56d27a
JB
26274Don't use this packet; use the @samp{qThreadExtraInfo} query instead
26275(see below).
26276
b8ff78ce 26277Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 26278
8b23ecc4
SL
26279@item QNonStop:1
26280@item QNonStop:0
26281@cindex non-stop mode, remote request
26282@cindex @samp{QNonStop} packet
26283@anchor{QNonStop}
26284Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
26285@xref{Remote Non-Stop}, for more information.
26286
26287Reply:
26288@table @samp
26289@item OK
26290The request succeeded.
26291
26292@item E @var{nn}
26293An error occurred. @var{nn} are hex digits.
26294
26295@item
26296An empty reply indicates that @samp{QNonStop} is not supported by
26297the stub.
26298@end table
26299
26300This packet is not probed by default; the remote stub must request it,
26301by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26302Use of this packet is controlled by the @code{set non-stop} command;
26303@pxref{Non-Stop Mode}.
26304
89be2091
DJ
26305@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
26306@cindex pass signals to inferior, remote request
26307@cindex @samp{QPassSignals} packet
23181151 26308@anchor{QPassSignals}
89be2091
DJ
26309Each listed @var{signal} should be passed directly to the inferior process.
26310Signals are numbered identically to continue packets and stop replies
26311(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
26312strictly greater than the previous item. These signals do not need to stop
26313the inferior, or be reported to @value{GDBN}. All other signals should be
26314reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
26315combine; any earlier @samp{QPassSignals} list is completely replaced by the
26316new list. This packet improves performance when using @samp{handle
26317@var{signal} nostop noprint pass}.
26318
26319Reply:
26320@table @samp
26321@item OK
26322The request succeeded.
26323
26324@item E @var{nn}
26325An error occurred. @var{nn} are hex digits.
26326
26327@item
26328An empty reply indicates that @samp{QPassSignals} is not supported by
26329the stub.
26330@end table
26331
26332Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 26333command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
26334This packet is not probed by default; the remote stub must request it,
26335by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26336
b8ff78ce 26337@item qRcmd,@var{command}
ff2587ec 26338@cindex execute remote command, remote request
b8ff78ce 26339@cindex @samp{qRcmd} packet
ff2587ec 26340@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
26341execution. Invalid commands should be reported using the output
26342string. Before the final result packet, the target may also respond
26343with a number of intermediate @samp{O@var{output}} console output
26344packets. @emph{Implementors should note that providing access to a
26345stubs's interpreter may have security implications}.
fa93a9d8 26346
ff2587ec
WZ
26347Reply:
26348@table @samp
26349@item OK
26350A command response with no output.
26351@item @var{OUTPUT}
26352A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 26353@item E @var{NN}
ff2587ec 26354Indicate a badly formed request.
b8ff78ce
JB
26355@item
26356An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 26357@end table
fa93a9d8 26358
aa56d27a
JB
26359(Note that the @code{qRcmd} packet's name is separated from the
26360command by a @samp{,}, not a @samp{:}, contrary to the naming
26361conventions above. Please don't use this packet as a model for new
26362packets.)
26363
08388c79
DE
26364@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
26365@cindex searching memory, in remote debugging
26366@cindex @samp{qSearch:memory} packet
26367@anchor{qSearch memory}
26368Search @var{length} bytes at @var{address} for @var{search-pattern}.
26369@var{address} and @var{length} are encoded in hex.
26370@var{search-pattern} is a sequence of bytes, hex encoded.
26371
26372Reply:
26373@table @samp
26374@item 0
26375The pattern was not found.
26376@item 1,address
26377The pattern was found at @var{address}.
26378@item E @var{NN}
26379A badly formed request or an error was encountered while searching memory.
26380@item
26381An empty reply indicates that @samp{qSearch:memory} is not recognized.
26382@end table
26383
a6f3e723
SL
26384@item QStartNoAckMode
26385@cindex @samp{QStartNoAckMode} packet
26386@anchor{QStartNoAckMode}
26387Request that the remote stub disable the normal @samp{+}/@samp{-}
26388protocol acknowledgments (@pxref{Packet Acknowledgment}).
26389
26390Reply:
26391@table @samp
26392@item OK
26393The stub has switched to no-acknowledgment mode.
26394@value{GDBN} acknowledges this reponse,
26395but neither the stub nor @value{GDBN} shall send or expect further
26396@samp{+}/@samp{-} acknowledgments in the current connection.
26397@item
26398An empty reply indicates that the stub does not support no-acknowledgment mode.
26399@end table
26400
be2a5f71
DJ
26401@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
26402@cindex supported packets, remote query
26403@cindex features of the remote protocol
26404@cindex @samp{qSupported} packet
0876f84a 26405@anchor{qSupported}
be2a5f71
DJ
26406Tell the remote stub about features supported by @value{GDBN}, and
26407query the stub for features it supports. This packet allows
26408@value{GDBN} and the remote stub to take advantage of each others'
26409features. @samp{qSupported} also consolidates multiple feature probes
26410at startup, to improve @value{GDBN} performance---a single larger
26411packet performs better than multiple smaller probe packets on
26412high-latency links. Some features may enable behavior which must not
26413be on by default, e.g.@: because it would confuse older clients or
26414stubs. Other features may describe packets which could be
26415automatically probed for, but are not. These features must be
26416reported before @value{GDBN} will use them. This ``default
26417unsupported'' behavior is not appropriate for all packets, but it
26418helps to keep the initial connection time under control with new
26419versions of @value{GDBN} which support increasing numbers of packets.
26420
26421Reply:
26422@table @samp
26423@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
26424The stub supports or does not support each returned @var{stubfeature},
26425depending on the form of each @var{stubfeature} (see below for the
26426possible forms).
26427@item
26428An empty reply indicates that @samp{qSupported} is not recognized,
26429or that no features needed to be reported to @value{GDBN}.
26430@end table
26431
26432The allowed forms for each feature (either a @var{gdbfeature} in the
26433@samp{qSupported} packet, or a @var{stubfeature} in the response)
26434are:
26435
26436@table @samp
26437@item @var{name}=@var{value}
26438The remote protocol feature @var{name} is supported, and associated
26439with the specified @var{value}. The format of @var{value} depends
26440on the feature, but it must not include a semicolon.
26441@item @var{name}+
26442The remote protocol feature @var{name} is supported, and does not
26443need an associated value.
26444@item @var{name}-
26445The remote protocol feature @var{name} is not supported.
26446@item @var{name}?
26447The remote protocol feature @var{name} may be supported, and
26448@value{GDBN} should auto-detect support in some other way when it is
26449needed. This form will not be used for @var{gdbfeature} notifications,
26450but may be used for @var{stubfeature} responses.
26451@end table
26452
26453Whenever the stub receives a @samp{qSupported} request, the
26454supplied set of @value{GDBN} features should override any previous
26455request. This allows @value{GDBN} to put the stub in a known
26456state, even if the stub had previously been communicating with
26457a different version of @value{GDBN}.
26458
b90a069a
SL
26459The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
26460are defined:
26461
26462@table @samp
26463@item multiprocess
26464This feature indicates whether @value{GDBN} supports multiprocess
26465extensions to the remote protocol. @value{GDBN} does not use such
26466extensions unless the stub also reports that it supports them by
26467including @samp{multiprocess+} in its @samp{qSupported} reply.
26468@xref{multiprocess extensions}, for details.
26469@end table
26470
26471Stubs should ignore any unknown values for
be2a5f71
DJ
26472@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
26473packet supports receiving packets of unlimited length (earlier
b90a069a 26474versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
26475for @var{gdbfeature} may be defined in the future to let the stub take
26476advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
26477improvements in the remote protocol---the @samp{multiprocess} feature is
26478an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
26479of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
26480describes all the features it supports, and then the stub replies with
26481all the features it supports.
26482
26483Similarly, @value{GDBN} will silently ignore unrecognized stub feature
26484responses, as long as each response uses one of the standard forms.
26485
26486Some features are flags. A stub which supports a flag feature
26487should respond with a @samp{+} form response. Other features
26488require values, and the stub should respond with an @samp{=}
26489form response.
26490
26491Each feature has a default value, which @value{GDBN} will use if
26492@samp{qSupported} is not available or if the feature is not mentioned
26493in the @samp{qSupported} response. The default values are fixed; a
26494stub is free to omit any feature responses that match the defaults.
26495
26496Not all features can be probed, but for those which can, the probing
26497mechanism is useful: in some cases, a stub's internal
26498architecture may not allow the protocol layer to know some information
26499about the underlying target in advance. This is especially common in
26500stubs which may be configured for multiple targets.
26501
26502These are the currently defined stub features and their properties:
26503
cfa9d6d9 26504@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
26505@c NOTE: The first row should be @headitem, but we do not yet require
26506@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 26507@item Feature Name
be2a5f71
DJ
26508@tab Value Required
26509@tab Default
26510@tab Probe Allowed
26511
26512@item @samp{PacketSize}
26513@tab Yes
26514@tab @samp{-}
26515@tab No
26516
0876f84a
DJ
26517@item @samp{qXfer:auxv:read}
26518@tab No
26519@tab @samp{-}
26520@tab Yes
26521
23181151
DJ
26522@item @samp{qXfer:features:read}
26523@tab No
26524@tab @samp{-}
26525@tab Yes
26526
cfa9d6d9
DJ
26527@item @samp{qXfer:libraries:read}
26528@tab No
26529@tab @samp{-}
26530@tab Yes
26531
68437a39
DJ
26532@item @samp{qXfer:memory-map:read}
26533@tab No
26534@tab @samp{-}
26535@tab Yes
26536
0e7f50da
UW
26537@item @samp{qXfer:spu:read}
26538@tab No
26539@tab @samp{-}
26540@tab Yes
26541
26542@item @samp{qXfer:spu:write}
26543@tab No
26544@tab @samp{-}
26545@tab Yes
26546
8b23ecc4
SL
26547@item @samp{QNonStop}
26548@tab No
26549@tab @samp{-}
26550@tab Yes
26551
89be2091
DJ
26552@item @samp{QPassSignals}
26553@tab No
26554@tab @samp{-}
26555@tab Yes
26556
a6f3e723
SL
26557@item @samp{QStartNoAckMode}
26558@tab No
26559@tab @samp{-}
26560@tab Yes
26561
b90a069a
SL
26562@item @samp{multiprocess}
26563@tab No
26564@tab @samp{-}
26565@tab No
26566
be2a5f71
DJ
26567@end multitable
26568
26569These are the currently defined stub features, in more detail:
26570
26571@table @samp
26572@cindex packet size, remote protocol
26573@item PacketSize=@var{bytes}
26574The remote stub can accept packets up to at least @var{bytes} in
26575length. @value{GDBN} will send packets up to this size for bulk
26576transfers, and will never send larger packets. This is a limit on the
26577data characters in the packet, including the frame and checksum.
26578There is no trailing NUL byte in a remote protocol packet; if the stub
26579stores packets in a NUL-terminated format, it should allow an extra
26580byte in its buffer for the NUL. If this stub feature is not supported,
26581@value{GDBN} guesses based on the size of the @samp{g} packet response.
26582
0876f84a
DJ
26583@item qXfer:auxv:read
26584The remote stub understands the @samp{qXfer:auxv:read} packet
26585(@pxref{qXfer auxiliary vector read}).
26586
23181151
DJ
26587@item qXfer:features:read
26588The remote stub understands the @samp{qXfer:features:read} packet
26589(@pxref{qXfer target description read}).
26590
cfa9d6d9
DJ
26591@item qXfer:libraries:read
26592The remote stub understands the @samp{qXfer:libraries:read} packet
26593(@pxref{qXfer library list read}).
26594
23181151
DJ
26595@item qXfer:memory-map:read
26596The remote stub understands the @samp{qXfer:memory-map:read} packet
26597(@pxref{qXfer memory map read}).
26598
0e7f50da
UW
26599@item qXfer:spu:read
26600The remote stub understands the @samp{qXfer:spu:read} packet
26601(@pxref{qXfer spu read}).
26602
26603@item qXfer:spu:write
26604The remote stub understands the @samp{qXfer:spu:write} packet
26605(@pxref{qXfer spu write}).
26606
8b23ecc4
SL
26607@item QNonStop
26608The remote stub understands the @samp{QNonStop} packet
26609(@pxref{QNonStop}).
26610
23181151
DJ
26611@item QPassSignals
26612The remote stub understands the @samp{QPassSignals} packet
26613(@pxref{QPassSignals}).
26614
a6f3e723
SL
26615@item QStartNoAckMode
26616The remote stub understands the @samp{QStartNoAckMode} packet and
26617prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
26618
b90a069a
SL
26619@item multiprocess
26620@anchor{multiprocess extensions}
26621@cindex multiprocess extensions, in remote protocol
26622The remote stub understands the multiprocess extensions to the remote
26623protocol syntax. The multiprocess extensions affect the syntax of
26624thread IDs in both packets and replies (@pxref{thread-id syntax}), and
26625add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
26626replies. Note that reporting this feature indicates support for the
26627syntactic extensions only, not that the stub necessarily supports
26628debugging of more than one process at a time. The stub must not use
26629multiprocess extensions in packet replies unless @value{GDBN} has also
26630indicated it supports them in its @samp{qSupported} request.
26631
07e059b5
VP
26632@item qXfer:osdata:read
26633The remote stub understands the @samp{qXfer:osdata:read} packet
26634((@pxref{qXfer osdata read}).
26635
be2a5f71
DJ
26636@end table
26637
b8ff78ce 26638@item qSymbol::
ff2587ec 26639@cindex symbol lookup, remote request
b8ff78ce 26640@cindex @samp{qSymbol} packet
ff2587ec
WZ
26641Notify the target that @value{GDBN} is prepared to serve symbol lookup
26642requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
26643
26644Reply:
ff2587ec 26645@table @samp
b8ff78ce 26646@item OK
ff2587ec 26647The target does not need to look up any (more) symbols.
b8ff78ce 26648@item qSymbol:@var{sym_name}
ff2587ec
WZ
26649The target requests the value of symbol @var{sym_name} (hex encoded).
26650@value{GDBN} may provide the value by using the
b8ff78ce
JB
26651@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
26652below.
ff2587ec 26653@end table
83761cbd 26654
b8ff78ce 26655@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
26656Set the value of @var{sym_name} to @var{sym_value}.
26657
26658@var{sym_name} (hex encoded) is the name of a symbol whose value the
26659target has previously requested.
26660
26661@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
26662@value{GDBN} cannot supply a value for @var{sym_name}, then this field
26663will be empty.
26664
26665Reply:
26666@table @samp
b8ff78ce 26667@item OK
ff2587ec 26668The target does not need to look up any (more) symbols.
b8ff78ce 26669@item qSymbol:@var{sym_name}
ff2587ec
WZ
26670The target requests the value of a new symbol @var{sym_name} (hex
26671encoded). @value{GDBN} will continue to supply the values of symbols
26672(if available), until the target ceases to request them.
fa93a9d8 26673@end table
0abb7bc7 26674
9d29849a
JB
26675@item QTDP
26676@itemx QTFrame
26677@xref{Tracepoint Packets}.
26678
b90a069a 26679@item qThreadExtraInfo,@var{thread-id}
ff2587ec 26680@cindex thread attributes info, remote request
b8ff78ce
JB
26681@cindex @samp{qThreadExtraInfo} packet
26682Obtain a printable string description of a thread's attributes from
b90a069a
SL
26683the target OS. @var{thread-id} is a thread ID;
26684see @ref{thread-id syntax}. This
b8ff78ce
JB
26685string may contain anything that the target OS thinks is interesting
26686for @value{GDBN} to tell the user about the thread. The string is
26687displayed in @value{GDBN}'s @code{info threads} display. Some
26688examples of possible thread extra info strings are @samp{Runnable}, or
26689@samp{Blocked on Mutex}.
ff2587ec
WZ
26690
26691Reply:
26692@table @samp
b8ff78ce
JB
26693@item @var{XX}@dots{}
26694Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
26695comprising the printable string containing the extra information about
26696the thread's attributes.
ff2587ec 26697@end table
814e32d7 26698
aa56d27a
JB
26699(Note that the @code{qThreadExtraInfo} packet's name is separated from
26700the command by a @samp{,}, not a @samp{:}, contrary to the naming
26701conventions above. Please don't use this packet as a model for new
26702packets.)
26703
9d29849a
JB
26704@item QTStart
26705@itemx QTStop
26706@itemx QTinit
26707@itemx QTro
26708@itemx qTStatus
26709@xref{Tracepoint Packets}.
26710
0876f84a
DJ
26711@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
26712@cindex read special object, remote request
26713@cindex @samp{qXfer} packet
68437a39 26714@anchor{qXfer read}
0876f84a
DJ
26715Read uninterpreted bytes from the target's special data area
26716identified by the keyword @var{object}. Request @var{length} bytes
26717starting at @var{offset} bytes into the data. The content and
0e7f50da 26718encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
26719additional details about what data to access.
26720
26721Here are the specific requests of this form defined so far. All
26722@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
26723formats, listed below.
26724
26725@table @samp
26726@item qXfer:auxv:read::@var{offset},@var{length}
26727@anchor{qXfer auxiliary vector read}
26728Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 26729auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
26730
26731This packet is not probed by default; the remote stub must request it,
89be2091 26732by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 26733
23181151
DJ
26734@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
26735@anchor{qXfer target description read}
26736Access the @dfn{target description}. @xref{Target Descriptions}. The
26737annex specifies which XML document to access. The main description is
26738always loaded from the @samp{target.xml} annex.
26739
26740This packet is not probed by default; the remote stub must request it,
26741by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26742
cfa9d6d9
DJ
26743@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
26744@anchor{qXfer library list read}
26745Access the target's list of loaded libraries. @xref{Library List Format}.
26746The annex part of the generic @samp{qXfer} packet must be empty
26747(@pxref{qXfer read}).
26748
26749Targets which maintain a list of libraries in the program's memory do
26750not need to implement this packet; it is designed for platforms where
26751the operating system manages the list of loaded libraries.
26752
26753This packet is not probed by default; the remote stub must request it,
26754by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26755
68437a39
DJ
26756@item qXfer:memory-map:read::@var{offset},@var{length}
26757@anchor{qXfer memory map read}
79a6e687 26758Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
26759annex part of the generic @samp{qXfer} packet must be empty
26760(@pxref{qXfer read}).
26761
0e7f50da
UW
26762This packet is not probed by default; the remote stub must request it,
26763by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26764
26765@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
26766@anchor{qXfer spu read}
26767Read contents of an @code{spufs} file on the target system. The
26768annex specifies which file to read; it must be of the form
26769@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
26770in the target process, and @var{name} identifes the @code{spufs} file
26771in that context to be accessed.
26772
68437a39 26773This packet is not probed by default; the remote stub must request it,
07e059b5
VP
26774by supplying an appropriate @samp{qSupported} response
26775(@pxref{qSupported}).
26776
26777@item qXfer:osdata:read::@var{offset},@var{length}
26778@anchor{qXfer osdata read}
26779Access the target's @dfn{operating system information}.
26780@xref{Operating System Information}.
26781
68437a39
DJ
26782@end table
26783
0876f84a
DJ
26784Reply:
26785@table @samp
26786@item m @var{data}
26787Data @var{data} (@pxref{Binary Data}) has been read from the
26788target. There may be more data at a higher address (although
26789it is permitted to return @samp{m} even for the last valid
26790block of data, as long as at least one byte of data was read).
26791@var{data} may have fewer bytes than the @var{length} in the
26792request.
26793
26794@item l @var{data}
26795Data @var{data} (@pxref{Binary Data}) has been read from the target.
26796There is no more data to be read. @var{data} may have fewer bytes
26797than the @var{length} in the request.
26798
26799@item l
26800The @var{offset} in the request is at the end of the data.
26801There is no more data to be read.
26802
26803@item E00
26804The request was malformed, or @var{annex} was invalid.
26805
26806@item E @var{nn}
26807The offset was invalid, or there was an error encountered reading the data.
26808@var{nn} is a hex-encoded @code{errno} value.
26809
26810@item
26811An empty reply indicates the @var{object} string was not recognized by
26812the stub, or that the object does not support reading.
26813@end table
26814
26815@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
26816@cindex write data into object, remote request
26817Write uninterpreted bytes into the target's special data area
26818identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 26819into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 26820(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 26821is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
26822to access.
26823
0e7f50da
UW
26824Here are the specific requests of this form defined so far. All
26825@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
26826formats, listed below.
26827
26828@table @samp
26829@item qXfer:@var{spu}:write:@var{annex}:@var{offset}:@var{data}@dots{}
26830@anchor{qXfer spu write}
26831Write @var{data} to an @code{spufs} file on the target system. The
26832annex specifies which file to write; it must be of the form
26833@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
26834in the target process, and @var{name} identifes the @code{spufs} file
26835in that context to be accessed.
26836
26837This packet is not probed by default; the remote stub must request it,
26838by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
26839@end table
0876f84a
DJ
26840
26841Reply:
26842@table @samp
26843@item @var{nn}
26844@var{nn} (hex encoded) is the number of bytes written.
26845This may be fewer bytes than supplied in the request.
26846
26847@item E00
26848The request was malformed, or @var{annex} was invalid.
26849
26850@item E @var{nn}
26851The offset was invalid, or there was an error encountered writing the data.
26852@var{nn} is a hex-encoded @code{errno} value.
26853
26854@item
26855An empty reply indicates the @var{object} string was not
26856recognized by the stub, or that the object does not support writing.
26857@end table
26858
26859@item qXfer:@var{object}:@var{operation}:@dots{}
26860Requests of this form may be added in the future. When a stub does
26861not recognize the @var{object} keyword, or its support for
26862@var{object} does not recognize the @var{operation} keyword, the stub
26863must respond with an empty packet.
26864
ee2d5c50
AC
26865@end table
26866
26867@node Register Packet Format
26868@section Register Packet Format
eb12ee30 26869
b8ff78ce 26870The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
26871In the below, some thirty-two bit registers are transferred as
26872sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
26873to fill the space allocated. Register bytes are transferred in target
26874byte order. The two nibbles within a register byte are transferred
ee2d5c50 26875most-significant - least-significant.
eb12ee30 26876
ee2d5c50 26877@table @r
eb12ee30 26878
8e04817f 26879@item MIPS32
ee2d5c50 26880
599b237a 26881All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
2688232 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
26883registers; fsr; fir; fp.
eb12ee30 26884
8e04817f 26885@item MIPS64
ee2d5c50 26886
599b237a 26887All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
26888thirty-two bit registers such as @code{sr}). The ordering is the same
26889as @code{MIPS32}.
eb12ee30 26890
ee2d5c50
AC
26891@end table
26892
9d29849a
JB
26893@node Tracepoint Packets
26894@section Tracepoint Packets
26895@cindex tracepoint packets
26896@cindex packets, tracepoint
26897
26898Here we describe the packets @value{GDBN} uses to implement
26899tracepoints (@pxref{Tracepoints}).
26900
26901@table @samp
26902
26903@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
26904Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
26905is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
26906the tracepoint is disabled. @var{step} is the tracepoint's step
26907count, and @var{pass} is its pass count. If the trailing @samp{-} is
26908present, further @samp{QTDP} packets will follow to specify this
26909tracepoint's actions.
26910
26911Replies:
26912@table @samp
26913@item OK
26914The packet was understood and carried out.
26915@item
26916The packet was not recognized.
26917@end table
26918
26919@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
26920Define actions to be taken when a tracepoint is hit. @var{n} and
26921@var{addr} must be the same as in the initial @samp{QTDP} packet for
26922this tracepoint. This packet may only be sent immediately after
26923another @samp{QTDP} packet that ended with a @samp{-}. If the
26924trailing @samp{-} is present, further @samp{QTDP} packets will follow,
26925specifying more actions for this tracepoint.
26926
26927In the series of action packets for a given tracepoint, at most one
26928can have an @samp{S} before its first @var{action}. If such a packet
26929is sent, it and the following packets define ``while-stepping''
26930actions. Any prior packets define ordinary actions --- that is, those
26931taken when the tracepoint is first hit. If no action packet has an
26932@samp{S}, then all the packets in the series specify ordinary
26933tracepoint actions.
26934
26935The @samp{@var{action}@dots{}} portion of the packet is a series of
26936actions, concatenated without separators. Each action has one of the
26937following forms:
26938
26939@table @samp
26940
26941@item R @var{mask}
26942Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 26943a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
26944@var{i} should be collected. (The least significant bit is numbered
26945zero.) Note that @var{mask} may be any number of digits long; it may
26946not fit in a 32-bit word.
26947
26948@item M @var{basereg},@var{offset},@var{len}
26949Collect @var{len} bytes of memory starting at the address in register
26950number @var{basereg}, plus @var{offset}. If @var{basereg} is
26951@samp{-1}, then the range has a fixed address: @var{offset} is the
26952address of the lowest byte to collect. The @var{basereg},
599b237a 26953@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
26954values (the @samp{-1} value for @var{basereg} is a special case).
26955
26956@item X @var{len},@var{expr}
26957Evaluate @var{expr}, whose length is @var{len}, and collect memory as
26958it directs. @var{expr} is an agent expression, as described in
26959@ref{Agent Expressions}. Each byte of the expression is encoded as a
26960two-digit hex number in the packet; @var{len} is the number of bytes
26961in the expression (and thus one-half the number of hex digits in the
26962packet).
26963
26964@end table
26965
26966Any number of actions may be packed together in a single @samp{QTDP}
26967packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
26968length (400 bytes, for many stubs). There may be only one @samp{R}
26969action per tracepoint, and it must precede any @samp{M} or @samp{X}
26970actions. Any registers referred to by @samp{M} and @samp{X} actions
26971must be collected by a preceding @samp{R} action. (The
26972``while-stepping'' actions are treated as if they were attached to a
26973separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
26974
26975Replies:
26976@table @samp
26977@item OK
26978The packet was understood and carried out.
26979@item
26980The packet was not recognized.
26981@end table
26982
26983@item QTFrame:@var{n}
26984Select the @var{n}'th tracepoint frame from the buffer, and use the
26985register and memory contents recorded there to answer subsequent
26986request packets from @value{GDBN}.
26987
26988A successful reply from the stub indicates that the stub has found the
26989requested frame. The response is a series of parts, concatenated
26990without separators, describing the frame we selected. Each part has
26991one of the following forms:
26992
26993@table @samp
26994@item F @var{f}
26995The selected frame is number @var{n} in the trace frame buffer;
599b237a 26996@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
26997was no frame matching the criteria in the request packet.
26998
26999@item T @var{t}
27000The selected trace frame records a hit of tracepoint number @var{t};
599b237a 27001@var{t} is a hexadecimal number.
9d29849a
JB
27002
27003@end table
27004
27005@item QTFrame:pc:@var{addr}
27006Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
27007currently selected frame whose PC is @var{addr};
599b237a 27008@var{addr} is a hexadecimal number.
9d29849a
JB
27009
27010@item QTFrame:tdp:@var{t}
27011Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
27012currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 27013is a hexadecimal number.
9d29849a
JB
27014
27015@item QTFrame:range:@var{start}:@var{end}
27016Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
27017currently selected frame whose PC is between @var{start} (inclusive)
599b237a 27018and @var{end} (exclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
27019numbers.
27020
27021@item QTFrame:outside:@var{start}:@var{end}
27022Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
27023frame @emph{outside} the given range of addresses.
27024
27025@item QTStart
27026Begin the tracepoint experiment. Begin collecting data from tracepoint
27027hits in the trace frame buffer.
27028
27029@item QTStop
27030End the tracepoint experiment. Stop collecting trace frames.
27031
27032@item QTinit
27033Clear the table of tracepoints, and empty the trace frame buffer.
27034
27035@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
27036Establish the given ranges of memory as ``transparent''. The stub
27037will answer requests for these ranges from memory's current contents,
27038if they were not collected as part of the tracepoint hit.
27039
27040@value{GDBN} uses this to mark read-only regions of memory, like those
27041containing program code. Since these areas never change, they should
27042still have the same contents they did when the tracepoint was hit, so
27043there's no reason for the stub to refuse to provide their contents.
27044
27045@item qTStatus
27046Ask the stub if there is a trace experiment running right now.
27047
27048Replies:
27049@table @samp
27050@item T0
27051There is no trace experiment running.
27052@item T1
27053There is a trace experiment running.
27054@end table
27055
27056@end table
27057
27058
a6b151f1
DJ
27059@node Host I/O Packets
27060@section Host I/O Packets
27061@cindex Host I/O, remote protocol
27062@cindex file transfer, remote protocol
27063
27064The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
27065operations on the far side of a remote link. For example, Host I/O is
27066used to upload and download files to a remote target with its own
27067filesystem. Host I/O uses the same constant values and data structure
27068layout as the target-initiated File-I/O protocol. However, the
27069Host I/O packets are structured differently. The target-initiated
27070protocol relies on target memory to store parameters and buffers.
27071Host I/O requests are initiated by @value{GDBN}, and the
27072target's memory is not involved. @xref{File-I/O Remote Protocol
27073Extension}, for more details on the target-initiated protocol.
27074
27075The Host I/O request packets all encode a single operation along with
27076its arguments. They have this format:
27077
27078@table @samp
27079
27080@item vFile:@var{operation}: @var{parameter}@dots{}
27081@var{operation} is the name of the particular request; the target
27082should compare the entire packet name up to the second colon when checking
27083for a supported operation. The format of @var{parameter} depends on
27084the operation. Numbers are always passed in hexadecimal. Negative
27085numbers have an explicit minus sign (i.e.@: two's complement is not
27086used). Strings (e.g.@: filenames) are encoded as a series of
27087hexadecimal bytes. The last argument to a system call may be a
27088buffer of escaped binary data (@pxref{Binary Data}).
27089
27090@end table
27091
27092The valid responses to Host I/O packets are:
27093
27094@table @samp
27095
27096@item F @var{result} [, @var{errno}] [; @var{attachment}]
27097@var{result} is the integer value returned by this operation, usually
27098non-negative for success and -1 for errors. If an error has occured,
27099@var{errno} will be included in the result. @var{errno} will have a
27100value defined by the File-I/O protocol (@pxref{Errno Values}). For
27101operations which return data, @var{attachment} supplies the data as a
27102binary buffer. Binary buffers in response packets are escaped in the
27103normal way (@pxref{Binary Data}). See the individual packet
27104documentation for the interpretation of @var{result} and
27105@var{attachment}.
27106
27107@item
27108An empty response indicates that this operation is not recognized.
27109
27110@end table
27111
27112These are the supported Host I/O operations:
27113
27114@table @samp
27115@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
27116Open a file at @var{pathname} and return a file descriptor for it, or
27117return -1 if an error occurs. @var{pathname} is a string,
27118@var{flags} is an integer indicating a mask of open flags
27119(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
27120of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 27121@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
27122
27123@item vFile:close: @var{fd}
27124Close the open file corresponding to @var{fd} and return 0, or
27125-1 if an error occurs.
27126
27127@item vFile:pread: @var{fd}, @var{count}, @var{offset}
27128Read data from the open file corresponding to @var{fd}. Up to
27129@var{count} bytes will be read from the file, starting at @var{offset}
27130relative to the start of the file. The target may read fewer bytes;
27131common reasons include packet size limits and an end-of-file
27132condition. The number of bytes read is returned. Zero should only be
27133returned for a successful read at the end of the file, or if
27134@var{count} was zero.
27135
27136The data read should be returned as a binary attachment on success.
27137If zero bytes were read, the response should include an empty binary
27138attachment (i.e.@: a trailing semicolon). The return value is the
27139number of target bytes read; the binary attachment may be longer if
27140some characters were escaped.
27141
27142@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
27143Write @var{data} (a binary buffer) to the open file corresponding
27144to @var{fd}. Start the write at @var{offset} from the start of the
27145file. Unlike many @code{write} system calls, there is no
27146separate @var{count} argument; the length of @var{data} in the
27147packet is used. @samp{vFile:write} returns the number of bytes written,
27148which may be shorter than the length of @var{data}, or -1 if an
27149error occurred.
27150
27151@item vFile:unlink: @var{pathname}
27152Delete the file at @var{pathname} on the target. Return 0,
27153or -1 if an error occurs. @var{pathname} is a string.
27154
27155@end table
27156
9a6253be
KB
27157@node Interrupts
27158@section Interrupts
27159@cindex interrupts (remote protocol)
27160
27161When a program on the remote target is running, @value{GDBN} may
27162attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
27163control of which is specified via @value{GDBN}'s @samp{remotebreak}
27164setting (@pxref{set remotebreak}).
27165
27166The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
27167mechanism and may, in fact, be undefined. @value{GDBN} does not
27168currently define a @code{BREAK} mechanism for any of the network
27169interfaces except for TCP, in which case @value{GDBN} sends the
27170@code{telnet} BREAK sequence.
9a6253be
KB
27171
27172@samp{Ctrl-C}, on the other hand, is defined and implemented for all
27173transport mechanisms. It is represented by sending the single byte
27174@code{0x03} without any of the usual packet overhead described in
27175the Overview section (@pxref{Overview}). When a @code{0x03} byte is
27176transmitted as part of a packet, it is considered to be packet data
27177and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 27178(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
27179@code{0x03} as part of its packet.
27180
27181Stubs are not required to recognize these interrupt mechanisms and the
27182precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
27183implementation defined. If the target supports debugging of multiple
27184threads and/or processes, it should attempt to interrupt all
27185currently-executing threads and processes.
27186If the stub is successful at interrupting the
27187running program, it should send one of the stop
27188reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
27189of successfully stopping the program in all-stop mode, and a stop reply
27190for each stopped thread in non-stop mode.
27191Interrupts received while the
27192program is stopped are discarded.
27193
27194@node Notification Packets
27195@section Notification Packets
27196@cindex notification packets
27197@cindex packets, notification
27198
27199The @value{GDBN} remote serial protocol includes @dfn{notifications},
27200packets that require no acknowledgment. Both the GDB and the stub
27201may send notifications (although the only notifications defined at
27202present are sent by the stub). Notifications carry information
27203without incurring the round-trip latency of an acknowledgment, and so
27204are useful for low-impact communications where occasional packet loss
27205is not a problem.
27206
27207A notification packet has the form @samp{% @var{data} #
27208@var{checksum}}, where @var{data} is the content of the notification,
27209and @var{checksum} is a checksum of @var{data}, computed and formatted
27210as for ordinary @value{GDBN} packets. A notification's @var{data}
27211never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
27212receiving a notification, the recipient sends no @samp{+} or @samp{-}
27213to acknowledge the notification's receipt or to report its corruption.
27214
27215Every notification's @var{data} begins with a name, which contains no
27216colon characters, followed by a colon character.
27217
27218Recipients should silently ignore corrupted notifications and
27219notifications they do not understand. Recipients should restart
27220timeout periods on receipt of a well-formed notification, whether or
27221not they understand it.
27222
27223Senders should only send the notifications described here when this
27224protocol description specifies that they are permitted. In the
27225future, we may extend the protocol to permit existing notifications in
27226new contexts; this rule helps older senders avoid confusing newer
27227recipients.
27228
27229(Older versions of @value{GDBN} ignore bytes received until they see
27230the @samp{$} byte that begins an ordinary packet, so new stubs may
27231transmit notifications without fear of confusing older clients. There
27232are no notifications defined for @value{GDBN} to send at the moment, but we
27233assume that most older stubs would ignore them, as well.)
27234
27235The following notification packets from the stub to @value{GDBN} are
27236defined:
27237
27238@table @samp
27239@item Stop: @var{reply}
27240Report an asynchronous stop event in non-stop mode.
27241The @var{reply} has the form of a stop reply, as
27242described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
27243for information on how these notifications are acknowledged by
27244@value{GDBN}.
27245@end table
27246
27247@node Remote Non-Stop
27248@section Remote Protocol Support for Non-Stop Mode
27249
27250@value{GDBN}'s remote protocol supports non-stop debugging of
27251multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
27252supports non-stop mode, it should report that to @value{GDBN} by including
27253@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
27254
27255@value{GDBN} typically sends a @samp{QNonStop} packet only when
27256establishing a new connection with the stub. Entering non-stop mode
27257does not alter the state of any currently-running threads, but targets
27258must stop all threads in any already-attached processes when entering
27259all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
27260probe the target state after a mode change.
27261
27262In non-stop mode, when an attached process encounters an event that
27263would otherwise be reported with a stop reply, it uses the
27264asynchronous notification mechanism (@pxref{Notification Packets}) to
27265inform @value{GDBN}. In contrast to all-stop mode, where all threads
27266in all processes are stopped when a stop reply is sent, in non-stop
27267mode only the thread reporting the stop event is stopped. That is,
27268when reporting a @samp{S} or @samp{T} response to indicate completion
27269of a step operation, hitting a breakpoint, or a fault, only the
27270affected thread is stopped; any other still-running threads continue
27271to run. When reporting a @samp{W} or @samp{X} response, all running
27272threads belonging to other attached processes continue to run.
27273
27274Only one stop reply notification at a time may be pending; if
27275additional stop events occur before @value{GDBN} has acknowledged the
27276previous notification, they must be queued by the stub for later
27277synchronous transmission in response to @samp{vStopped} packets from
27278@value{GDBN}. Because the notification mechanism is unreliable,
27279the stub is permitted to resend a stop reply notification
27280if it believes @value{GDBN} may not have received it. @value{GDBN}
27281ignores additional stop reply notifications received before it has
27282finished processing a previous notification and the stub has completed
27283sending any queued stop events.
27284
27285Otherwise, @value{GDBN} must be prepared to receive a stop reply
27286notification at any time. Specifically, they may appear when
27287@value{GDBN} is not otherwise reading input from the stub, or when
27288@value{GDBN} is expecting to read a normal synchronous response or a
27289@samp{+}/@samp{-} acknowledgment to a packet it has sent.
27290Notification packets are distinct from any other communication from
27291the stub so there is no ambiguity.
27292
27293After receiving a stop reply notification, @value{GDBN} shall
27294acknowledge it by sending a @samp{vStopped} packet (@pxref{vStopped packet})
27295as a regular, synchronous request to the stub. Such acknowledgment
27296is not required to happen immediately, as @value{GDBN} is permitted to
27297send other, unrelated packets to the stub first, which the stub should
27298process normally.
27299
27300Upon receiving a @samp{vStopped} packet, if the stub has other queued
27301stop events to report to @value{GDBN}, it shall respond by sending a
27302normal stop reply response. @value{GDBN} shall then send another
27303@samp{vStopped} packet to solicit further responses; again, it is
27304permitted to send other, unrelated packets as well which the stub
27305should process normally.
27306
27307If the stub receives a @samp{vStopped} packet and there are no
27308additional stop events to report, the stub shall return an @samp{OK}
27309response. At this point, if further stop events occur, the stub shall
27310send a new stop reply notification, @value{GDBN} shall accept the
27311notification, and the process shall be repeated.
27312
27313In non-stop mode, the target shall respond to the @samp{?} packet as
27314follows. First, any incomplete stop reply notification/@samp{vStopped}
27315sequence in progress is abandoned. The target must begin a new
27316sequence reporting stop events for all stopped threads, whether or not
27317it has previously reported those events to @value{GDBN}. The first
27318stop reply is sent as a synchronous reply to the @samp{?} packet, and
27319subsequent stop replies are sent as responses to @samp{vStopped} packets
27320using the mechanism described above. The target must not send
27321asynchronous stop reply notifications until the sequence is complete.
27322If all threads are running when the target receives the @samp{?} packet,
27323or if the target is not attached to any process, it shall respond
27324@samp{OK}.
9a6253be 27325
a6f3e723
SL
27326@node Packet Acknowledgment
27327@section Packet Acknowledgment
27328
27329@cindex acknowledgment, for @value{GDBN} remote
27330@cindex packet acknowledgment, for @value{GDBN} remote
27331By default, when either the host or the target machine receives a packet,
27332the first response expected is an acknowledgment: either @samp{+} (to indicate
27333the package was received correctly) or @samp{-} (to request retransmission).
27334This mechanism allows the @value{GDBN} remote protocol to operate over
27335unreliable transport mechanisms, such as a serial line.
27336
27337In cases where the transport mechanism is itself reliable (such as a pipe or
27338TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
27339It may be desirable to disable them in that case to reduce communication
27340overhead, or for other reasons. This can be accomplished by means of the
27341@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
27342
27343When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
27344expect @samp{+}/@samp{-} protocol acknowledgments. The packet
27345and response format still includes the normal checksum, as described in
27346@ref{Overview}, but the checksum may be ignored by the receiver.
27347
27348If the stub supports @samp{QStartNoAckMode} and prefers to operate in
27349no-acknowledgment mode, it should report that to @value{GDBN}
27350by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
27351@pxref{qSupported}.
27352If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
27353disabled via the @code{set remote noack-packet off} command
27354(@pxref{Remote Configuration}),
27355@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
27356Only then may the stub actually turn off packet acknowledgments.
27357@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
27358response, which can be safely ignored by the stub.
27359
27360Note that @code{set remote noack-packet} command only affects negotiation
27361between @value{GDBN} and the stub when subsequent connections are made;
27362it does not affect the protocol acknowledgment state for any current
27363connection.
27364Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
27365new connection is established,
27366there is also no protocol request to re-enable the acknowledgments
27367for the current connection, once disabled.
27368
ee2d5c50
AC
27369@node Examples
27370@section Examples
eb12ee30 27371
8e04817f
AC
27372Example sequence of a target being re-started. Notice how the restart
27373does not get any direct output:
eb12ee30 27374
474c8240 27375@smallexample
d2c6833e
AC
27376-> @code{R00}
27377<- @code{+}
8e04817f 27378@emph{target restarts}
d2c6833e 27379-> @code{?}
8e04817f 27380<- @code{+}
d2c6833e
AC
27381<- @code{T001:1234123412341234}
27382-> @code{+}
474c8240 27383@end smallexample
eb12ee30 27384
8e04817f 27385Example sequence of a target being stepped by a single instruction:
eb12ee30 27386
474c8240 27387@smallexample
d2c6833e 27388-> @code{G1445@dots{}}
8e04817f 27389<- @code{+}
d2c6833e
AC
27390-> @code{s}
27391<- @code{+}
27392@emph{time passes}
27393<- @code{T001:1234123412341234}
8e04817f 27394-> @code{+}
d2c6833e 27395-> @code{g}
8e04817f 27396<- @code{+}
d2c6833e
AC
27397<- @code{1455@dots{}}
27398-> @code{+}
474c8240 27399@end smallexample
eb12ee30 27400
79a6e687
BW
27401@node File-I/O Remote Protocol Extension
27402@section File-I/O Remote Protocol Extension
0ce1b118
CV
27403@cindex File-I/O remote protocol extension
27404
27405@menu
27406* File-I/O Overview::
79a6e687
BW
27407* Protocol Basics::
27408* The F Request Packet::
27409* The F Reply Packet::
27410* The Ctrl-C Message::
0ce1b118 27411* Console I/O::
79a6e687 27412* List of Supported Calls::
db2e3e2e 27413* Protocol-specific Representation of Datatypes::
0ce1b118
CV
27414* Constants::
27415* File-I/O Examples::
27416@end menu
27417
27418@node File-I/O Overview
27419@subsection File-I/O Overview
27420@cindex file-i/o overview
27421
9c16f35a 27422The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 27423target to use the host's file system and console I/O to perform various
0ce1b118 27424system calls. System calls on the target system are translated into a
fc320d37
SL
27425remote protocol packet to the host system, which then performs the needed
27426actions and returns a response packet to the target system.
0ce1b118
CV
27427This simulates file system operations even on targets that lack file systems.
27428
fc320d37
SL
27429The protocol is defined to be independent of both the host and target systems.
27430It uses its own internal representation of datatypes and values. Both
0ce1b118 27431@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
27432translating the system-dependent value representations into the internal
27433protocol representations when data is transmitted.
0ce1b118 27434
fc320d37
SL
27435The communication is synchronous. A system call is possible only when
27436@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
27437or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 27438the target is stopped to allow deterministic access to the target's
fc320d37
SL
27439memory. Therefore File-I/O is not interruptible by target signals. On
27440the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 27441(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
27442
27443The target's request to perform a host system call does not finish
27444the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
27445after finishing the system call, the target returns to continuing the
27446previous activity (continue, step). No additional continue or step
27447request from @value{GDBN} is required.
27448
27449@smallexample
f7dc1244 27450(@value{GDBP}) continue
0ce1b118
CV
27451 <- target requests 'system call X'
27452 target is stopped, @value{GDBN} executes system call
3f94c067
BW
27453 -> @value{GDBN} returns result
27454 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
27455 <- target hits breakpoint and sends a Txx packet
27456@end smallexample
27457
fc320d37
SL
27458The protocol only supports I/O on the console and to regular files on
27459the host file system. Character or block special devices, pipes,
27460named pipes, sockets or any other communication method on the host
0ce1b118
CV
27461system are not supported by this protocol.
27462
8b23ecc4
SL
27463File I/O is not supported in non-stop mode.
27464
79a6e687
BW
27465@node Protocol Basics
27466@subsection Protocol Basics
0ce1b118
CV
27467@cindex protocol basics, file-i/o
27468
fc320d37
SL
27469The File-I/O protocol uses the @code{F} packet as the request as well
27470as reply packet. Since a File-I/O system call can only occur when
27471@value{GDBN} is waiting for a response from the continuing or stepping target,
27472the File-I/O request is a reply that @value{GDBN} has to expect as a result
27473of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
27474This @code{F} packet contains all information needed to allow @value{GDBN}
27475to call the appropriate host system call:
27476
27477@itemize @bullet
b383017d 27478@item
0ce1b118
CV
27479A unique identifier for the requested system call.
27480
27481@item
27482All parameters to the system call. Pointers are given as addresses
27483in the target memory address space. Pointers to strings are given as
b383017d 27484pointer/length pair. Numerical values are given as they are.
db2e3e2e 27485Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
27486
27487@end itemize
27488
fc320d37 27489At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
27490
27491@itemize @bullet
b383017d 27492@item
fc320d37
SL
27493If the parameters include pointer values to data needed as input to a
27494system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
27495standard @code{m} packet request. This additional communication has to be
27496expected by the target implementation and is handled as any other @code{m}
27497packet.
27498
27499@item
27500@value{GDBN} translates all value from protocol representation to host
27501representation as needed. Datatypes are coerced into the host types.
27502
27503@item
fc320d37 27504@value{GDBN} calls the system call.
0ce1b118
CV
27505
27506@item
27507It then coerces datatypes back to protocol representation.
27508
27509@item
fc320d37
SL
27510If the system call is expected to return data in buffer space specified
27511by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
27512target using a @code{M} or @code{X} packet. This packet has to be expected
27513by the target implementation and is handled as any other @code{M} or @code{X}
27514packet.
27515
27516@end itemize
27517
27518Eventually @value{GDBN} replies with another @code{F} packet which contains all
27519necessary information for the target to continue. This at least contains
27520
27521@itemize @bullet
27522@item
27523Return value.
27524
27525@item
27526@code{errno}, if has been changed by the system call.
27527
27528@item
27529``Ctrl-C'' flag.
27530
27531@end itemize
27532
27533After having done the needed type and value coercion, the target continues
27534the latest continue or step action.
27535
79a6e687
BW
27536@node The F Request Packet
27537@subsection The @code{F} Request Packet
0ce1b118
CV
27538@cindex file-i/o request packet
27539@cindex @code{F} request packet
27540
27541The @code{F} request packet has the following format:
27542
27543@table @samp
fc320d37 27544@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
27545
27546@var{call-id} is the identifier to indicate the host system call to be called.
27547This is just the name of the function.
27548
fc320d37
SL
27549@var{parameter@dots{}} are the parameters to the system call.
27550Parameters are hexadecimal integer values, either the actual values in case
27551of scalar datatypes, pointers to target buffer space in case of compound
27552datatypes and unspecified memory areas, or pointer/length pairs in case
27553of string parameters. These are appended to the @var{call-id} as a
27554comma-delimited list. All values are transmitted in ASCII
27555string representation, pointer/length pairs separated by a slash.
0ce1b118 27556
b383017d 27557@end table
0ce1b118 27558
fc320d37 27559
0ce1b118 27560
79a6e687
BW
27561@node The F Reply Packet
27562@subsection The @code{F} Reply Packet
0ce1b118
CV
27563@cindex file-i/o reply packet
27564@cindex @code{F} reply packet
27565
27566The @code{F} reply packet has the following format:
27567
27568@table @samp
27569
d3bdde98 27570@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
27571
27572@var{retcode} is the return code of the system call as hexadecimal value.
27573
db2e3e2e
BW
27574@var{errno} is the @code{errno} set by the call, in protocol-specific
27575representation.
0ce1b118
CV
27576This parameter can be omitted if the call was successful.
27577
fc320d37
SL
27578@var{Ctrl-C flag} is only sent if the user requested a break. In this
27579case, @var{errno} must be sent as well, even if the call was successful.
27580The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
27581
27582@smallexample
27583F0,0,C
27584@end smallexample
27585
27586@noindent
fc320d37 27587or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
27588
27589@smallexample
27590F-1,4,C
27591@end smallexample
27592
27593@noindent
db2e3e2e 27594assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
27595
27596@end table
27597
0ce1b118 27598
79a6e687
BW
27599@node The Ctrl-C Message
27600@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
27601@cindex ctrl-c message, in file-i/o protocol
27602
c8aa23ab 27603If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 27604reply packet (@pxref{The F Reply Packet}),
fc320d37 27605the target should behave as if it had
0ce1b118 27606gotten a break message. The meaning for the target is ``system call
fc320d37 27607interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 27608(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 27609packet.
fc320d37
SL
27610
27611It's important for the target to know in which
27612state the system call was interrupted. There are two possible cases:
0ce1b118
CV
27613
27614@itemize @bullet
27615@item
27616The system call hasn't been performed on the host yet.
27617
27618@item
27619The system call on the host has been finished.
27620
27621@end itemize
27622
27623These two states can be distinguished by the target by the value of the
27624returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
27625call hasn't been performed. This is equivalent to the @code{EINTR} handling
27626on POSIX systems. In any other case, the target may presume that the
fc320d37 27627system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
27628as if the break message arrived right after the system call.
27629
fc320d37 27630@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
27631yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
27632@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
27633before the user requests a break, the full action must be finished by
27634@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
27635The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
27636or the full action has been completed.
27637
27638@node Console I/O
27639@subsection Console I/O
27640@cindex console i/o as part of file-i/o
27641
d3e8051b 27642By default and if not explicitly closed by the target system, the file
0ce1b118
CV
27643descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
27644on the @value{GDBN} console is handled as any other file output operation
27645(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
27646by @value{GDBN} so that after the target read request from file descriptor
276470 all following typing is buffered until either one of the following
27648conditions is met:
27649
27650@itemize @bullet
27651@item
c8aa23ab 27652The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
27653@code{read}
27654system call is treated as finished.
27655
27656@item
7f9087cb 27657The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 27658newline.
0ce1b118
CV
27659
27660@item
c8aa23ab
EZ
27661The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
27662character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
27663
27664@end itemize
27665
fc320d37
SL
27666If the user has typed more characters than fit in the buffer given to
27667the @code{read} call, the trailing characters are buffered in @value{GDBN} until
27668either another @code{read(0, @dots{})} is requested by the target, or debugging
27669is stopped at the user's request.
0ce1b118 27670
0ce1b118 27671
79a6e687
BW
27672@node List of Supported Calls
27673@subsection List of Supported Calls
0ce1b118
CV
27674@cindex list of supported file-i/o calls
27675
27676@menu
27677* open::
27678* close::
27679* read::
27680* write::
27681* lseek::
27682* rename::
27683* unlink::
27684* stat/fstat::
27685* gettimeofday::
27686* isatty::
27687* system::
27688@end menu
27689
27690@node open
27691@unnumberedsubsubsec open
27692@cindex open, file-i/o system call
27693
fc320d37
SL
27694@table @asis
27695@item Synopsis:
0ce1b118 27696@smallexample
0ce1b118
CV
27697int open(const char *pathname, int flags);
27698int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
27699@end smallexample
27700
fc320d37
SL
27701@item Request:
27702@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
27703
0ce1b118 27704@noindent
fc320d37 27705@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
27706
27707@table @code
b383017d 27708@item O_CREAT
0ce1b118
CV
27709If the file does not exist it will be created. The host
27710rules apply as far as file ownership and time stamps
27711are concerned.
27712
b383017d 27713@item O_EXCL
fc320d37 27714When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
27715an error and open() fails.
27716
b383017d 27717@item O_TRUNC
0ce1b118 27718If the file already exists and the open mode allows
fc320d37
SL
27719writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
27720truncated to zero length.
0ce1b118 27721
b383017d 27722@item O_APPEND
0ce1b118
CV
27723The file is opened in append mode.
27724
b383017d 27725@item O_RDONLY
0ce1b118
CV
27726The file is opened for reading only.
27727
b383017d 27728@item O_WRONLY
0ce1b118
CV
27729The file is opened for writing only.
27730
b383017d 27731@item O_RDWR
0ce1b118 27732The file is opened for reading and writing.
fc320d37 27733@end table
0ce1b118
CV
27734
27735@noindent
fc320d37 27736Other bits are silently ignored.
0ce1b118 27737
0ce1b118
CV
27738
27739@noindent
fc320d37 27740@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
27741
27742@table @code
b383017d 27743@item S_IRUSR
0ce1b118
CV
27744User has read permission.
27745
b383017d 27746@item S_IWUSR
0ce1b118
CV
27747User has write permission.
27748
b383017d 27749@item S_IRGRP
0ce1b118
CV
27750Group has read permission.
27751
b383017d 27752@item S_IWGRP
0ce1b118
CV
27753Group has write permission.
27754
b383017d 27755@item S_IROTH
0ce1b118
CV
27756Others have read permission.
27757
b383017d 27758@item S_IWOTH
0ce1b118 27759Others have write permission.
fc320d37 27760@end table
0ce1b118
CV
27761
27762@noindent
fc320d37 27763Other bits are silently ignored.
0ce1b118 27764
0ce1b118 27765
fc320d37
SL
27766@item Return value:
27767@code{open} returns the new file descriptor or -1 if an error
27768occurred.
0ce1b118 27769
fc320d37 27770@item Errors:
0ce1b118
CV
27771
27772@table @code
b383017d 27773@item EEXIST
fc320d37 27774@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 27775
b383017d 27776@item EISDIR
fc320d37 27777@var{pathname} refers to a directory.
0ce1b118 27778
b383017d 27779@item EACCES
0ce1b118
CV
27780The requested access is not allowed.
27781
27782@item ENAMETOOLONG
fc320d37 27783@var{pathname} was too long.
0ce1b118 27784
b383017d 27785@item ENOENT
fc320d37 27786A directory component in @var{pathname} does not exist.
0ce1b118 27787
b383017d 27788@item ENODEV
fc320d37 27789@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 27790
b383017d 27791@item EROFS
fc320d37 27792@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
27793write access was requested.
27794
b383017d 27795@item EFAULT
fc320d37 27796@var{pathname} is an invalid pointer value.
0ce1b118 27797
b383017d 27798@item ENOSPC
0ce1b118
CV
27799No space on device to create the file.
27800
b383017d 27801@item EMFILE
0ce1b118
CV
27802The process already has the maximum number of files open.
27803
b383017d 27804@item ENFILE
0ce1b118
CV
27805The limit on the total number of files open on the system
27806has been reached.
27807
b383017d 27808@item EINTR
0ce1b118
CV
27809The call was interrupted by the user.
27810@end table
27811
fc320d37
SL
27812@end table
27813
0ce1b118
CV
27814@node close
27815@unnumberedsubsubsec close
27816@cindex close, file-i/o system call
27817
fc320d37
SL
27818@table @asis
27819@item Synopsis:
0ce1b118 27820@smallexample
0ce1b118 27821int close(int fd);
fc320d37 27822@end smallexample
0ce1b118 27823
fc320d37
SL
27824@item Request:
27825@samp{Fclose,@var{fd}}
0ce1b118 27826
fc320d37
SL
27827@item Return value:
27828@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 27829
fc320d37 27830@item Errors:
0ce1b118
CV
27831
27832@table @code
b383017d 27833@item EBADF
fc320d37 27834@var{fd} isn't a valid open file descriptor.
0ce1b118 27835
b383017d 27836@item EINTR
0ce1b118
CV
27837The call was interrupted by the user.
27838@end table
27839
fc320d37
SL
27840@end table
27841
0ce1b118
CV
27842@node read
27843@unnumberedsubsubsec read
27844@cindex read, file-i/o system call
27845
fc320d37
SL
27846@table @asis
27847@item Synopsis:
0ce1b118 27848@smallexample
0ce1b118 27849int read(int fd, void *buf, unsigned int count);
fc320d37 27850@end smallexample
0ce1b118 27851
fc320d37
SL
27852@item Request:
27853@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 27854
fc320d37 27855@item Return value:
0ce1b118
CV
27856On success, the number of bytes read is returned.
27857Zero indicates end of file. If count is zero, read
b383017d 27858returns zero as well. On error, -1 is returned.
0ce1b118 27859
fc320d37 27860@item Errors:
0ce1b118
CV
27861
27862@table @code
b383017d 27863@item EBADF
fc320d37 27864@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
27865reading.
27866
b383017d 27867@item EFAULT
fc320d37 27868@var{bufptr} is an invalid pointer value.
0ce1b118 27869
b383017d 27870@item EINTR
0ce1b118
CV
27871The call was interrupted by the user.
27872@end table
27873
fc320d37
SL
27874@end table
27875
0ce1b118
CV
27876@node write
27877@unnumberedsubsubsec write
27878@cindex write, file-i/o system call
27879
fc320d37
SL
27880@table @asis
27881@item Synopsis:
0ce1b118 27882@smallexample
0ce1b118 27883int write(int fd, const void *buf, unsigned int count);
fc320d37 27884@end smallexample
0ce1b118 27885
fc320d37
SL
27886@item Request:
27887@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 27888
fc320d37 27889@item Return value:
0ce1b118
CV
27890On success, the number of bytes written are returned.
27891Zero indicates nothing was written. On error, -1
27892is returned.
27893
fc320d37 27894@item Errors:
0ce1b118
CV
27895
27896@table @code
b383017d 27897@item EBADF
fc320d37 27898@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
27899writing.
27900
b383017d 27901@item EFAULT
fc320d37 27902@var{bufptr} is an invalid pointer value.
0ce1b118 27903
b383017d 27904@item EFBIG
0ce1b118 27905An attempt was made to write a file that exceeds the
db2e3e2e 27906host-specific maximum file size allowed.
0ce1b118 27907
b383017d 27908@item ENOSPC
0ce1b118
CV
27909No space on device to write the data.
27910
b383017d 27911@item EINTR
0ce1b118
CV
27912The call was interrupted by the user.
27913@end table
27914
fc320d37
SL
27915@end table
27916
0ce1b118
CV
27917@node lseek
27918@unnumberedsubsubsec lseek
27919@cindex lseek, file-i/o system call
27920
fc320d37
SL
27921@table @asis
27922@item Synopsis:
0ce1b118 27923@smallexample
0ce1b118 27924long lseek (int fd, long offset, int flag);
0ce1b118
CV
27925@end smallexample
27926
fc320d37
SL
27927@item Request:
27928@samp{Flseek,@var{fd},@var{offset},@var{flag}}
27929
27930@var{flag} is one of:
0ce1b118
CV
27931
27932@table @code
b383017d 27933@item SEEK_SET
fc320d37 27934The offset is set to @var{offset} bytes.
0ce1b118 27935
b383017d 27936@item SEEK_CUR
fc320d37 27937The offset is set to its current location plus @var{offset}
0ce1b118
CV
27938bytes.
27939
b383017d 27940@item SEEK_END
fc320d37 27941The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
27942bytes.
27943@end table
27944
fc320d37 27945@item Return value:
0ce1b118
CV
27946On success, the resulting unsigned offset in bytes from
27947the beginning of the file is returned. Otherwise, a
27948value of -1 is returned.
27949
fc320d37 27950@item Errors:
0ce1b118
CV
27951
27952@table @code
b383017d 27953@item EBADF
fc320d37 27954@var{fd} is not a valid open file descriptor.
0ce1b118 27955
b383017d 27956@item ESPIPE
fc320d37 27957@var{fd} is associated with the @value{GDBN} console.
0ce1b118 27958
b383017d 27959@item EINVAL
fc320d37 27960@var{flag} is not a proper value.
0ce1b118 27961
b383017d 27962@item EINTR
0ce1b118
CV
27963The call was interrupted by the user.
27964@end table
27965
fc320d37
SL
27966@end table
27967
0ce1b118
CV
27968@node rename
27969@unnumberedsubsubsec rename
27970@cindex rename, file-i/o system call
27971
fc320d37
SL
27972@table @asis
27973@item Synopsis:
0ce1b118 27974@smallexample
0ce1b118 27975int rename(const char *oldpath, const char *newpath);
fc320d37 27976@end smallexample
0ce1b118 27977
fc320d37
SL
27978@item Request:
27979@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 27980
fc320d37 27981@item Return value:
0ce1b118
CV
27982On success, zero is returned. On error, -1 is returned.
27983
fc320d37 27984@item Errors:
0ce1b118
CV
27985
27986@table @code
b383017d 27987@item EISDIR
fc320d37 27988@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
27989directory.
27990
b383017d 27991@item EEXIST
fc320d37 27992@var{newpath} is a non-empty directory.
0ce1b118 27993
b383017d 27994@item EBUSY
fc320d37 27995@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
27996process.
27997
b383017d 27998@item EINVAL
0ce1b118
CV
27999An attempt was made to make a directory a subdirectory
28000of itself.
28001
b383017d 28002@item ENOTDIR
fc320d37
SL
28003A component used as a directory in @var{oldpath} or new
28004path is not a directory. Or @var{oldpath} is a directory
28005and @var{newpath} exists but is not a directory.
0ce1b118 28006
b383017d 28007@item EFAULT
fc320d37 28008@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 28009
b383017d 28010@item EACCES
0ce1b118
CV
28011No access to the file or the path of the file.
28012
28013@item ENAMETOOLONG
b383017d 28014
fc320d37 28015@var{oldpath} or @var{newpath} was too long.
0ce1b118 28016
b383017d 28017@item ENOENT
fc320d37 28018A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 28019
b383017d 28020@item EROFS
0ce1b118
CV
28021The file is on a read-only filesystem.
28022
b383017d 28023@item ENOSPC
0ce1b118
CV
28024The device containing the file has no room for the new
28025directory entry.
28026
b383017d 28027@item EINTR
0ce1b118
CV
28028The call was interrupted by the user.
28029@end table
28030
fc320d37
SL
28031@end table
28032
0ce1b118
CV
28033@node unlink
28034@unnumberedsubsubsec unlink
28035@cindex unlink, file-i/o system call
28036
fc320d37
SL
28037@table @asis
28038@item Synopsis:
0ce1b118 28039@smallexample
0ce1b118 28040int unlink(const char *pathname);
fc320d37 28041@end smallexample
0ce1b118 28042
fc320d37
SL
28043@item Request:
28044@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 28045
fc320d37 28046@item Return value:
0ce1b118
CV
28047On success, zero is returned. On error, -1 is returned.
28048
fc320d37 28049@item Errors:
0ce1b118
CV
28050
28051@table @code
b383017d 28052@item EACCES
0ce1b118
CV
28053No access to the file or the path of the file.
28054
b383017d 28055@item EPERM
0ce1b118
CV
28056The system does not allow unlinking of directories.
28057
b383017d 28058@item EBUSY
fc320d37 28059The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
28060being used by another process.
28061
b383017d 28062@item EFAULT
fc320d37 28063@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
28064
28065@item ENAMETOOLONG
fc320d37 28066@var{pathname} was too long.
0ce1b118 28067
b383017d 28068@item ENOENT
fc320d37 28069A directory component in @var{pathname} does not exist.
0ce1b118 28070
b383017d 28071@item ENOTDIR
0ce1b118
CV
28072A component of the path is not a directory.
28073
b383017d 28074@item EROFS
0ce1b118
CV
28075The file is on a read-only filesystem.
28076
b383017d 28077@item EINTR
0ce1b118
CV
28078The call was interrupted by the user.
28079@end table
28080
fc320d37
SL
28081@end table
28082
0ce1b118
CV
28083@node stat/fstat
28084@unnumberedsubsubsec stat/fstat
28085@cindex fstat, file-i/o system call
28086@cindex stat, file-i/o system call
28087
fc320d37
SL
28088@table @asis
28089@item Synopsis:
0ce1b118 28090@smallexample
0ce1b118
CV
28091int stat(const char *pathname, struct stat *buf);
28092int fstat(int fd, struct stat *buf);
fc320d37 28093@end smallexample
0ce1b118 28094
fc320d37
SL
28095@item Request:
28096@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
28097@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 28098
fc320d37 28099@item Return value:
0ce1b118
CV
28100On success, zero is returned. On error, -1 is returned.
28101
fc320d37 28102@item Errors:
0ce1b118
CV
28103
28104@table @code
b383017d 28105@item EBADF
fc320d37 28106@var{fd} is not a valid open file.
0ce1b118 28107
b383017d 28108@item ENOENT
fc320d37 28109A directory component in @var{pathname} does not exist or the
0ce1b118
CV
28110path is an empty string.
28111
b383017d 28112@item ENOTDIR
0ce1b118
CV
28113A component of the path is not a directory.
28114
b383017d 28115@item EFAULT
fc320d37 28116@var{pathnameptr} is an invalid pointer value.
0ce1b118 28117
b383017d 28118@item EACCES
0ce1b118
CV
28119No access to the file or the path of the file.
28120
28121@item ENAMETOOLONG
fc320d37 28122@var{pathname} was too long.
0ce1b118 28123
b383017d 28124@item EINTR
0ce1b118
CV
28125The call was interrupted by the user.
28126@end table
28127
fc320d37
SL
28128@end table
28129
0ce1b118
CV
28130@node gettimeofday
28131@unnumberedsubsubsec gettimeofday
28132@cindex gettimeofday, file-i/o system call
28133
fc320d37
SL
28134@table @asis
28135@item Synopsis:
0ce1b118 28136@smallexample
0ce1b118 28137int gettimeofday(struct timeval *tv, void *tz);
fc320d37 28138@end smallexample
0ce1b118 28139
fc320d37
SL
28140@item Request:
28141@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 28142
fc320d37 28143@item Return value:
0ce1b118
CV
28144On success, 0 is returned, -1 otherwise.
28145
fc320d37 28146@item Errors:
0ce1b118
CV
28147
28148@table @code
b383017d 28149@item EINVAL
fc320d37 28150@var{tz} is a non-NULL pointer.
0ce1b118 28151
b383017d 28152@item EFAULT
fc320d37
SL
28153@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
28154@end table
28155
0ce1b118
CV
28156@end table
28157
28158@node isatty
28159@unnumberedsubsubsec isatty
28160@cindex isatty, file-i/o system call
28161
fc320d37
SL
28162@table @asis
28163@item Synopsis:
0ce1b118 28164@smallexample
0ce1b118 28165int isatty(int fd);
fc320d37 28166@end smallexample
0ce1b118 28167
fc320d37
SL
28168@item Request:
28169@samp{Fisatty,@var{fd}}
0ce1b118 28170
fc320d37
SL
28171@item Return value:
28172Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 28173
fc320d37 28174@item Errors:
0ce1b118
CV
28175
28176@table @code
b383017d 28177@item EINTR
0ce1b118
CV
28178The call was interrupted by the user.
28179@end table
28180
fc320d37
SL
28181@end table
28182
28183Note that the @code{isatty} call is treated as a special case: it returns
281841 to the target if the file descriptor is attached
28185to the @value{GDBN} console, 0 otherwise. Implementing through system calls
28186would require implementing @code{ioctl} and would be more complex than
28187needed.
28188
28189
0ce1b118
CV
28190@node system
28191@unnumberedsubsubsec system
28192@cindex system, file-i/o system call
28193
fc320d37
SL
28194@table @asis
28195@item Synopsis:
0ce1b118 28196@smallexample
0ce1b118 28197int system(const char *command);
fc320d37 28198@end smallexample
0ce1b118 28199
fc320d37
SL
28200@item Request:
28201@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 28202
fc320d37 28203@item Return value:
5600ea19
NS
28204If @var{len} is zero, the return value indicates whether a shell is
28205available. A zero return value indicates a shell is not available.
28206For non-zero @var{len}, the value returned is -1 on error and the
28207return status of the command otherwise. Only the exit status of the
28208command is returned, which is extracted from the host's @code{system}
28209return value by calling @code{WEXITSTATUS(retval)}. In case
28210@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 28211
fc320d37 28212@item Errors:
0ce1b118
CV
28213
28214@table @code
b383017d 28215@item EINTR
0ce1b118
CV
28216The call was interrupted by the user.
28217@end table
28218
fc320d37
SL
28219@end table
28220
28221@value{GDBN} takes over the full task of calling the necessary host calls
28222to perform the @code{system} call. The return value of @code{system} on
28223the host is simplified before it's returned
28224to the target. Any termination signal information from the child process
28225is discarded, and the return value consists
28226entirely of the exit status of the called command.
28227
28228Due to security concerns, the @code{system} call is by default refused
28229by @value{GDBN}. The user has to allow this call explicitly with the
28230@code{set remote system-call-allowed 1} command.
28231
28232@table @code
28233@item set remote system-call-allowed
28234@kindex set remote system-call-allowed
28235Control whether to allow the @code{system} calls in the File I/O
28236protocol for the remote target. The default is zero (disabled).
28237
28238@item show remote system-call-allowed
28239@kindex show remote system-call-allowed
28240Show whether the @code{system} calls are allowed in the File I/O
28241protocol.
28242@end table
28243
db2e3e2e
BW
28244@node Protocol-specific Representation of Datatypes
28245@subsection Protocol-specific Representation of Datatypes
28246@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
28247
28248@menu
79a6e687
BW
28249* Integral Datatypes::
28250* Pointer Values::
28251* Memory Transfer::
0ce1b118
CV
28252* struct stat::
28253* struct timeval::
28254@end menu
28255
79a6e687
BW
28256@node Integral Datatypes
28257@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
28258@cindex integral datatypes, in file-i/o protocol
28259
fc320d37
SL
28260The integral datatypes used in the system calls are @code{int},
28261@code{unsigned int}, @code{long}, @code{unsigned long},
28262@code{mode_t}, and @code{time_t}.
0ce1b118 28263
fc320d37 28264@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
28265implemented as 32 bit values in this protocol.
28266
fc320d37 28267@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 28268
0ce1b118
CV
28269@xref{Limits}, for corresponding MIN and MAX values (similar to those
28270in @file{limits.h}) to allow range checking on host and target.
28271
28272@code{time_t} datatypes are defined as seconds since the Epoch.
28273
28274All integral datatypes transferred as part of a memory read or write of a
28275structured datatype e.g.@: a @code{struct stat} have to be given in big endian
28276byte order.
28277
79a6e687
BW
28278@node Pointer Values
28279@unnumberedsubsubsec Pointer Values
0ce1b118
CV
28280@cindex pointer values, in file-i/o protocol
28281
28282Pointers to target data are transmitted as they are. An exception
28283is made for pointers to buffers for which the length isn't
28284transmitted as part of the function call, namely strings. Strings
28285are transmitted as a pointer/length pair, both as hex values, e.g.@:
28286
28287@smallexample
28288@code{1aaf/12}
28289@end smallexample
28290
28291@noindent
28292which is a pointer to data of length 18 bytes at position 0x1aaf.
28293The length is defined as the full string length in bytes, including
fc320d37
SL
28294the trailing null byte. For example, the string @code{"hello world"}
28295at address 0x123456 is transmitted as
0ce1b118
CV
28296
28297@smallexample
fc320d37 28298@code{123456/d}
0ce1b118
CV
28299@end smallexample
28300
79a6e687
BW
28301@node Memory Transfer
28302@unnumberedsubsubsec Memory Transfer
fc320d37
SL
28303@cindex memory transfer, in file-i/o protocol
28304
28305Structured data which is transferred using a memory read or write (for
db2e3e2e 28306example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
28307with all scalar multibyte datatypes being big endian. Translation to
28308this representation needs to be done both by the target before the @code{F}
28309packet is sent, and by @value{GDBN} before
28310it transfers memory to the target. Transferred pointers to structured
28311data should point to the already-coerced data at any time.
0ce1b118 28312
0ce1b118
CV
28313
28314@node struct stat
28315@unnumberedsubsubsec struct stat
28316@cindex struct stat, in file-i/o protocol
28317
fc320d37
SL
28318The buffer of type @code{struct stat} used by the target and @value{GDBN}
28319is defined as follows:
0ce1b118
CV
28320
28321@smallexample
28322struct stat @{
28323 unsigned int st_dev; /* device */
28324 unsigned int st_ino; /* inode */
28325 mode_t st_mode; /* protection */
28326 unsigned int st_nlink; /* number of hard links */
28327 unsigned int st_uid; /* user ID of owner */
28328 unsigned int st_gid; /* group ID of owner */
28329 unsigned int st_rdev; /* device type (if inode device) */
28330 unsigned long st_size; /* total size, in bytes */
28331 unsigned long st_blksize; /* blocksize for filesystem I/O */
28332 unsigned long st_blocks; /* number of blocks allocated */
28333 time_t st_atime; /* time of last access */
28334 time_t st_mtime; /* time of last modification */
28335 time_t st_ctime; /* time of last change */
28336@};
28337@end smallexample
28338
fc320d37 28339The integral datatypes conform to the definitions given in the
79a6e687 28340appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
28341structure is of size 64 bytes.
28342
28343The values of several fields have a restricted meaning and/or
28344range of values.
28345
fc320d37 28346@table @code
0ce1b118 28347
fc320d37
SL
28348@item st_dev
28349A value of 0 represents a file, 1 the console.
0ce1b118 28350
fc320d37
SL
28351@item st_ino
28352No valid meaning for the target. Transmitted unchanged.
0ce1b118 28353
fc320d37
SL
28354@item st_mode
28355Valid mode bits are described in @ref{Constants}. Any other
28356bits have currently no meaning for the target.
0ce1b118 28357
fc320d37
SL
28358@item st_uid
28359@itemx st_gid
28360@itemx st_rdev
28361No valid meaning for the target. Transmitted unchanged.
0ce1b118 28362
fc320d37
SL
28363@item st_atime
28364@itemx st_mtime
28365@itemx st_ctime
28366These values have a host and file system dependent
28367accuracy. Especially on Windows hosts, the file system may not
28368support exact timing values.
28369@end table
0ce1b118 28370
fc320d37
SL
28371The target gets a @code{struct stat} of the above representation and is
28372responsible for coercing it to the target representation before
0ce1b118
CV
28373continuing.
28374
fc320d37
SL
28375Note that due to size differences between the host, target, and protocol
28376representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
28377get truncated on the target.
28378
28379@node struct timeval
28380@unnumberedsubsubsec struct timeval
28381@cindex struct timeval, in file-i/o protocol
28382
fc320d37 28383The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
28384is defined as follows:
28385
28386@smallexample
b383017d 28387struct timeval @{
0ce1b118
CV
28388 time_t tv_sec; /* second */
28389 long tv_usec; /* microsecond */
28390@};
28391@end smallexample
28392
fc320d37 28393The integral datatypes conform to the definitions given in the
79a6e687 28394appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
28395structure is of size 8 bytes.
28396
28397@node Constants
28398@subsection Constants
28399@cindex constants, in file-i/o protocol
28400
28401The following values are used for the constants inside of the
fc320d37 28402protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
28403values before and after the call as needed.
28404
28405@menu
79a6e687
BW
28406* Open Flags::
28407* mode_t Values::
28408* Errno Values::
28409* Lseek Flags::
0ce1b118
CV
28410* Limits::
28411@end menu
28412
79a6e687
BW
28413@node Open Flags
28414@unnumberedsubsubsec Open Flags
0ce1b118
CV
28415@cindex open flags, in file-i/o protocol
28416
28417All values are given in hexadecimal representation.
28418
28419@smallexample
28420 O_RDONLY 0x0
28421 O_WRONLY 0x1
28422 O_RDWR 0x2
28423 O_APPEND 0x8
28424 O_CREAT 0x200
28425 O_TRUNC 0x400
28426 O_EXCL 0x800
28427@end smallexample
28428
79a6e687
BW
28429@node mode_t Values
28430@unnumberedsubsubsec mode_t Values
0ce1b118
CV
28431@cindex mode_t values, in file-i/o protocol
28432
28433All values are given in octal representation.
28434
28435@smallexample
28436 S_IFREG 0100000
28437 S_IFDIR 040000
28438 S_IRUSR 0400
28439 S_IWUSR 0200
28440 S_IXUSR 0100
28441 S_IRGRP 040
28442 S_IWGRP 020
28443 S_IXGRP 010
28444 S_IROTH 04
28445 S_IWOTH 02
28446 S_IXOTH 01
28447@end smallexample
28448
79a6e687
BW
28449@node Errno Values
28450@unnumberedsubsubsec Errno Values
0ce1b118
CV
28451@cindex errno values, in file-i/o protocol
28452
28453All values are given in decimal representation.
28454
28455@smallexample
28456 EPERM 1
28457 ENOENT 2
28458 EINTR 4
28459 EBADF 9
28460 EACCES 13
28461 EFAULT 14
28462 EBUSY 16
28463 EEXIST 17
28464 ENODEV 19
28465 ENOTDIR 20
28466 EISDIR 21
28467 EINVAL 22
28468 ENFILE 23
28469 EMFILE 24
28470 EFBIG 27
28471 ENOSPC 28
28472 ESPIPE 29
28473 EROFS 30
28474 ENAMETOOLONG 91
28475 EUNKNOWN 9999
28476@end smallexample
28477
fc320d37 28478 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
28479 any error value not in the list of supported error numbers.
28480
79a6e687
BW
28481@node Lseek Flags
28482@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
28483@cindex lseek flags, in file-i/o protocol
28484
28485@smallexample
28486 SEEK_SET 0
28487 SEEK_CUR 1
28488 SEEK_END 2
28489@end smallexample
28490
28491@node Limits
28492@unnumberedsubsubsec Limits
28493@cindex limits, in file-i/o protocol
28494
28495All values are given in decimal representation.
28496
28497@smallexample
28498 INT_MIN -2147483648
28499 INT_MAX 2147483647
28500 UINT_MAX 4294967295
28501 LONG_MIN -9223372036854775808
28502 LONG_MAX 9223372036854775807
28503 ULONG_MAX 18446744073709551615
28504@end smallexample
28505
28506@node File-I/O Examples
28507@subsection File-I/O Examples
28508@cindex file-i/o examples
28509
28510Example sequence of a write call, file descriptor 3, buffer is at target
28511address 0x1234, 6 bytes should be written:
28512
28513@smallexample
28514<- @code{Fwrite,3,1234,6}
28515@emph{request memory read from target}
28516-> @code{m1234,6}
28517<- XXXXXX
28518@emph{return "6 bytes written"}
28519-> @code{F6}
28520@end smallexample
28521
28522Example sequence of a read call, file descriptor 3, buffer is at target
28523address 0x1234, 6 bytes should be read:
28524
28525@smallexample
28526<- @code{Fread,3,1234,6}
28527@emph{request memory write to target}
28528-> @code{X1234,6:XXXXXX}
28529@emph{return "6 bytes read"}
28530-> @code{F6}
28531@end smallexample
28532
28533Example sequence of a read call, call fails on the host due to invalid
fc320d37 28534file descriptor (@code{EBADF}):
0ce1b118
CV
28535
28536@smallexample
28537<- @code{Fread,3,1234,6}
28538-> @code{F-1,9}
28539@end smallexample
28540
c8aa23ab 28541Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
28542host is called:
28543
28544@smallexample
28545<- @code{Fread,3,1234,6}
28546-> @code{F-1,4,C}
28547<- @code{T02}
28548@end smallexample
28549
c8aa23ab 28550Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
28551host is called:
28552
28553@smallexample
28554<- @code{Fread,3,1234,6}
28555-> @code{X1234,6:XXXXXX}
28556<- @code{T02}
28557@end smallexample
28558
cfa9d6d9
DJ
28559@node Library List Format
28560@section Library List Format
28561@cindex library list format, remote protocol
28562
28563On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
28564same process as your application to manage libraries. In this case,
28565@value{GDBN} can use the loader's symbol table and normal memory
28566operations to maintain a list of shared libraries. On other
28567platforms, the operating system manages loaded libraries.
28568@value{GDBN} can not retrieve the list of currently loaded libraries
28569through memory operations, so it uses the @samp{qXfer:libraries:read}
28570packet (@pxref{qXfer library list read}) instead. The remote stub
28571queries the target's operating system and reports which libraries
28572are loaded.
28573
28574The @samp{qXfer:libraries:read} packet returns an XML document which
28575lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
28576associated name and one or more segment or section base addresses,
28577which report where the library was loaded in memory.
28578
28579For the common case of libraries that are fully linked binaries, the
28580library should have a list of segments. If the target supports
28581dynamic linking of a relocatable object file, its library XML element
28582should instead include a list of allocated sections. The segment or
28583section bases are start addresses, not relocation offsets; they do not
28584depend on the library's link-time base addresses.
cfa9d6d9 28585
9cceb671
DJ
28586@value{GDBN} must be linked with the Expat library to support XML
28587library lists. @xref{Expat}.
28588
cfa9d6d9
DJ
28589A simple memory map, with one loaded library relocated by a single
28590offset, looks like this:
28591
28592@smallexample
28593<library-list>
28594 <library name="/lib/libc.so.6">
28595 <segment address="0x10000000"/>
28596 </library>
28597</library-list>
28598@end smallexample
28599
1fddbabb
PA
28600Another simple memory map, with one loaded library with three
28601allocated sections (.text, .data, .bss), looks like this:
28602
28603@smallexample
28604<library-list>
28605 <library name="sharedlib.o">
28606 <section address="0x10000000"/>
28607 <section address="0x20000000"/>
28608 <section address="0x30000000"/>
28609 </library>
28610</library-list>
28611@end smallexample
28612
cfa9d6d9
DJ
28613The format of a library list is described by this DTD:
28614
28615@smallexample
28616<!-- library-list: Root element with versioning -->
28617<!ELEMENT library-list (library)*>
28618<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 28619<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
28620<!ATTLIST library name CDATA #REQUIRED>
28621<!ELEMENT segment EMPTY>
28622<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
28623<!ELEMENT section EMPTY>
28624<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
28625@end smallexample
28626
1fddbabb
PA
28627In addition, segments and section descriptors cannot be mixed within a
28628single library element, and you must supply at least one segment or
28629section for each library.
28630
79a6e687
BW
28631@node Memory Map Format
28632@section Memory Map Format
68437a39
DJ
28633@cindex memory map format
28634
28635To be able to write into flash memory, @value{GDBN} needs to obtain a
28636memory map from the target. This section describes the format of the
28637memory map.
28638
28639The memory map is obtained using the @samp{qXfer:memory-map:read}
28640(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
28641lists memory regions.
28642
28643@value{GDBN} must be linked with the Expat library to support XML
28644memory maps. @xref{Expat}.
28645
28646The top-level structure of the document is shown below:
68437a39
DJ
28647
28648@smallexample
28649<?xml version="1.0"?>
28650<!DOCTYPE memory-map
28651 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
28652 "http://sourceware.org/gdb/gdb-memory-map.dtd">
28653<memory-map>
28654 region...
28655</memory-map>
28656@end smallexample
28657
28658Each region can be either:
28659
28660@itemize
28661
28662@item
28663A region of RAM starting at @var{addr} and extending for @var{length}
28664bytes from there:
28665
28666@smallexample
28667<memory type="ram" start="@var{addr}" length="@var{length}"/>
28668@end smallexample
28669
28670
28671@item
28672A region of read-only memory:
28673
28674@smallexample
28675<memory type="rom" start="@var{addr}" length="@var{length}"/>
28676@end smallexample
28677
28678
28679@item
28680A region of flash memory, with erasure blocks @var{blocksize}
28681bytes in length:
28682
28683@smallexample
28684<memory type="flash" start="@var{addr}" length="@var{length}">
28685 <property name="blocksize">@var{blocksize}</property>
28686</memory>
28687@end smallexample
28688
28689@end itemize
28690
28691Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
28692by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
28693packets to write to addresses in such ranges.
28694
28695The formal DTD for memory map format is given below:
28696
28697@smallexample
28698<!-- ................................................... -->
28699<!-- Memory Map XML DTD ................................ -->
28700<!-- File: memory-map.dtd .............................. -->
28701<!-- .................................... .............. -->
28702<!-- memory-map.dtd -->
28703<!-- memory-map: Root element with versioning -->
28704<!ELEMENT memory-map (memory | property)>
28705<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
28706<!ELEMENT memory (property)>
28707<!-- memory: Specifies a memory region,
28708 and its type, or device. -->
28709<!ATTLIST memory type CDATA #REQUIRED
28710 start CDATA #REQUIRED
28711 length CDATA #REQUIRED
28712 device CDATA #IMPLIED>
28713<!-- property: Generic attribute tag -->
28714<!ELEMENT property (#PCDATA | property)*>
28715<!ATTLIST property name CDATA #REQUIRED>
28716@end smallexample
28717
f418dd93
DJ
28718@include agentexpr.texi
28719
23181151
DJ
28720@node Target Descriptions
28721@appendix Target Descriptions
28722@cindex target descriptions
28723
28724@strong{Warning:} target descriptions are still under active development,
28725and the contents and format may change between @value{GDBN} releases.
28726The format is expected to stabilize in the future.
28727
28728One of the challenges of using @value{GDBN} to debug embedded systems
28729is that there are so many minor variants of each processor
28730architecture in use. It is common practice for vendors to start with
28731a standard processor core --- ARM, PowerPC, or MIPS, for example ---
28732and then make changes to adapt it to a particular market niche. Some
28733architectures have hundreds of variants, available from dozens of
28734vendors. This leads to a number of problems:
28735
28736@itemize @bullet
28737@item
28738With so many different customized processors, it is difficult for
28739the @value{GDBN} maintainers to keep up with the changes.
28740@item
28741Since individual variants may have short lifetimes or limited
28742audiences, it may not be worthwhile to carry information about every
28743variant in the @value{GDBN} source tree.
28744@item
28745When @value{GDBN} does support the architecture of the embedded system
28746at hand, the task of finding the correct architecture name to give the
28747@command{set architecture} command can be error-prone.
28748@end itemize
28749
28750To address these problems, the @value{GDBN} remote protocol allows a
28751target system to not only identify itself to @value{GDBN}, but to
28752actually describe its own features. This lets @value{GDBN} support
28753processor variants it has never seen before --- to the extent that the
28754descriptions are accurate, and that @value{GDBN} understands them.
28755
9cceb671
DJ
28756@value{GDBN} must be linked with the Expat library to support XML
28757target descriptions. @xref{Expat}.
123dc839 28758
23181151
DJ
28759@menu
28760* Retrieving Descriptions:: How descriptions are fetched from a target.
28761* Target Description Format:: The contents of a target description.
123dc839
DJ
28762* Predefined Target Types:: Standard types available for target
28763 descriptions.
28764* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
28765@end menu
28766
28767@node Retrieving Descriptions
28768@section Retrieving Descriptions
28769
28770Target descriptions can be read from the target automatically, or
28771specified by the user manually. The default behavior is to read the
28772description from the target. @value{GDBN} retrieves it via the remote
28773protocol using @samp{qXfer} requests (@pxref{General Query Packets,
28774qXfer}). The @var{annex} in the @samp{qXfer} packet will be
28775@samp{target.xml}. The contents of the @samp{target.xml} annex are an
28776XML document, of the form described in @ref{Target Description
28777Format}.
28778
28779Alternatively, you can specify a file to read for the target description.
28780If a file is set, the target will not be queried. The commands to
28781specify a file are:
28782
28783@table @code
28784@cindex set tdesc filename
28785@item set tdesc filename @var{path}
28786Read the target description from @var{path}.
28787
28788@cindex unset tdesc filename
28789@item unset tdesc filename
28790Do not read the XML target description from a file. @value{GDBN}
28791will use the description supplied by the current target.
28792
28793@cindex show tdesc filename
28794@item show tdesc filename
28795Show the filename to read for a target description, if any.
28796@end table
28797
28798
28799@node Target Description Format
28800@section Target Description Format
28801@cindex target descriptions, XML format
28802
28803A target description annex is an @uref{http://www.w3.org/XML/, XML}
28804document which complies with the Document Type Definition provided in
28805the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
28806means you can use generally available tools like @command{xmllint} to
28807check that your feature descriptions are well-formed and valid.
28808However, to help people unfamiliar with XML write descriptions for
28809their targets, we also describe the grammar here.
28810
123dc839
DJ
28811Target descriptions can identify the architecture of the remote target
28812and (for some architectures) provide information about custom register
28813sets. @value{GDBN} can use this information to autoconfigure for your
28814target, or to warn you if you connect to an unsupported target.
23181151
DJ
28815
28816Here is a simple target description:
28817
123dc839 28818@smallexample
1780a0ed 28819<target version="1.0">
23181151
DJ
28820 <architecture>i386:x86-64</architecture>
28821</target>
123dc839 28822@end smallexample
23181151
DJ
28823
28824@noindent
28825This minimal description only says that the target uses
28826the x86-64 architecture.
28827
123dc839
DJ
28828A target description has the following overall form, with [ ] marking
28829optional elements and @dots{} marking repeatable elements. The elements
28830are explained further below.
23181151 28831
123dc839 28832@smallexample
23181151
DJ
28833<?xml version="1.0"?>
28834<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 28835<target version="1.0">
123dc839
DJ
28836 @r{[}@var{architecture}@r{]}
28837 @r{[}@var{feature}@dots{}@r{]}
23181151 28838</target>
123dc839 28839@end smallexample
23181151
DJ
28840
28841@noindent
28842The description is generally insensitive to whitespace and line
28843breaks, under the usual common-sense rules. The XML version
28844declaration and document type declaration can generally be omitted
28845(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
28846useful for XML validation tools. The @samp{version} attribute for
28847@samp{<target>} may also be omitted, but we recommend
28848including it; if future versions of @value{GDBN} use an incompatible
28849revision of @file{gdb-target.dtd}, they will detect and report
28850the version mismatch.
23181151 28851
108546a0
DJ
28852@subsection Inclusion
28853@cindex target descriptions, inclusion
28854@cindex XInclude
28855@ifnotinfo
28856@cindex <xi:include>
28857@end ifnotinfo
28858
28859It can sometimes be valuable to split a target description up into
28860several different annexes, either for organizational purposes, or to
28861share files between different possible target descriptions. You can
28862divide a description into multiple files by replacing any element of
28863the target description with an inclusion directive of the form:
28864
123dc839 28865@smallexample
108546a0 28866<xi:include href="@var{document}"/>
123dc839 28867@end smallexample
108546a0
DJ
28868
28869@noindent
28870When @value{GDBN} encounters an element of this form, it will retrieve
28871the named XML @var{document}, and replace the inclusion directive with
28872the contents of that document. If the current description was read
28873using @samp{qXfer}, then so will be the included document;
28874@var{document} will be interpreted as the name of an annex. If the
28875current description was read from a file, @value{GDBN} will look for
28876@var{document} as a file in the same directory where it found the
28877original description.
28878
123dc839
DJ
28879@subsection Architecture
28880@cindex <architecture>
28881
28882An @samp{<architecture>} element has this form:
28883
28884@smallexample
28885 <architecture>@var{arch}</architecture>
28886@end smallexample
28887
28888@var{arch} is an architecture name from the same selection
28889accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
28890Debugging Target}).
28891
28892@subsection Features
28893@cindex <feature>
28894
28895Each @samp{<feature>} describes some logical portion of the target
28896system. Features are currently used to describe available CPU
28897registers and the types of their contents. A @samp{<feature>} element
28898has this form:
28899
28900@smallexample
28901<feature name="@var{name}">
28902 @r{[}@var{type}@dots{}@r{]}
28903 @var{reg}@dots{}
28904</feature>
28905@end smallexample
28906
28907@noindent
28908Each feature's name should be unique within the description. The name
28909of a feature does not matter unless @value{GDBN} has some special
28910knowledge of the contents of that feature; if it does, the feature
28911should have its standard name. @xref{Standard Target Features}.
28912
28913@subsection Types
28914
28915Any register's value is a collection of bits which @value{GDBN} must
28916interpret. The default interpretation is a two's complement integer,
28917but other types can be requested by name in the register description.
28918Some predefined types are provided by @value{GDBN} (@pxref{Predefined
28919Target Types}), and the description can define additional composite types.
28920
28921Each type element must have an @samp{id} attribute, which gives
28922a unique (within the containing @samp{<feature>}) name to the type.
28923Types must be defined before they are used.
28924
28925@cindex <vector>
28926Some targets offer vector registers, which can be treated as arrays
28927of scalar elements. These types are written as @samp{<vector>} elements,
28928specifying the array element type, @var{type}, and the number of elements,
28929@var{count}:
28930
28931@smallexample
28932<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
28933@end smallexample
28934
28935@cindex <union>
28936If a register's value is usefully viewed in multiple ways, define it
28937with a union type containing the useful representations. The
28938@samp{<union>} element contains one or more @samp{<field>} elements,
28939each of which has a @var{name} and a @var{type}:
28940
28941@smallexample
28942<union id="@var{id}">
28943 <field name="@var{name}" type="@var{type}"/>
28944 @dots{}
28945</union>
28946@end smallexample
28947
28948@subsection Registers
28949@cindex <reg>
28950
28951Each register is represented as an element with this form:
28952
28953@smallexample
28954<reg name="@var{name}"
28955 bitsize="@var{size}"
28956 @r{[}regnum="@var{num}"@r{]}
28957 @r{[}save-restore="@var{save-restore}"@r{]}
28958 @r{[}type="@var{type}"@r{]}
28959 @r{[}group="@var{group}"@r{]}/>
28960@end smallexample
28961
28962@noindent
28963The components are as follows:
28964
28965@table @var
28966
28967@item name
28968The register's name; it must be unique within the target description.
28969
28970@item bitsize
28971The register's size, in bits.
28972
28973@item regnum
28974The register's number. If omitted, a register's number is one greater
28975than that of the previous register (either in the current feature or in
28976a preceeding feature); the first register in the target description
28977defaults to zero. This register number is used to read or write
28978the register; e.g.@: it is used in the remote @code{p} and @code{P}
28979packets, and registers appear in the @code{g} and @code{G} packets
28980in order of increasing register number.
28981
28982@item save-restore
28983Whether the register should be preserved across inferior function
28984calls; this must be either @code{yes} or @code{no}. The default is
28985@code{yes}, which is appropriate for most registers except for
28986some system control registers; this is not related to the target's
28987ABI.
28988
28989@item type
28990The type of the register. @var{type} may be a predefined type, a type
28991defined in the current feature, or one of the special types @code{int}
28992and @code{float}. @code{int} is an integer type of the correct size
28993for @var{bitsize}, and @code{float} is a floating point type (in the
28994architecture's normal floating point format) of the correct size for
28995@var{bitsize}. The default is @code{int}.
28996
28997@item group
28998The register group to which this register belongs. @var{group} must
28999be either @code{general}, @code{float}, or @code{vector}. If no
29000@var{group} is specified, @value{GDBN} will not display the register
29001in @code{info registers}.
29002
29003@end table
29004
29005@node Predefined Target Types
29006@section Predefined Target Types
29007@cindex target descriptions, predefined types
29008
29009Type definitions in the self-description can build up composite types
29010from basic building blocks, but can not define fundamental types. Instead,
29011standard identifiers are provided by @value{GDBN} for the fundamental
29012types. The currently supported types are:
29013
29014@table @code
29015
29016@item int8
29017@itemx int16
29018@itemx int32
29019@itemx int64
7cc46491 29020@itemx int128
123dc839
DJ
29021Signed integer types holding the specified number of bits.
29022
29023@item uint8
29024@itemx uint16
29025@itemx uint32
29026@itemx uint64
7cc46491 29027@itemx uint128
123dc839
DJ
29028Unsigned integer types holding the specified number of bits.
29029
29030@item code_ptr
29031@itemx data_ptr
29032Pointers to unspecified code and data. The program counter and
29033any dedicated return address register may be marked as code
29034pointers; printing a code pointer converts it into a symbolic
29035address. The stack pointer and any dedicated address registers
29036may be marked as data pointers.
29037
6e3bbd1a
PB
29038@item ieee_single
29039Single precision IEEE floating point.
29040
29041@item ieee_double
29042Double precision IEEE floating point.
29043
123dc839
DJ
29044@item arm_fpa_ext
29045The 12-byte extended precision format used by ARM FPA registers.
29046
29047@end table
29048
29049@node Standard Target Features
29050@section Standard Target Features
29051@cindex target descriptions, standard features
29052
29053A target description must contain either no registers or all the
29054target's registers. If the description contains no registers, then
29055@value{GDBN} will assume a default register layout, selected based on
29056the architecture. If the description contains any registers, the
29057default layout will not be used; the standard registers must be
29058described in the target description, in such a way that @value{GDBN}
29059can recognize them.
29060
29061This is accomplished by giving specific names to feature elements
29062which contain standard registers. @value{GDBN} will look for features
29063with those names and verify that they contain the expected registers;
29064if any known feature is missing required registers, or if any required
29065feature is missing, @value{GDBN} will reject the target
29066description. You can add additional registers to any of the
29067standard features --- @value{GDBN} will display them just as if
29068they were added to an unrecognized feature.
29069
29070This section lists the known features and their expected contents.
29071Sample XML documents for these features are included in the
29072@value{GDBN} source tree, in the directory @file{gdb/features}.
29073
29074Names recognized by @value{GDBN} should include the name of the
29075company or organization which selected the name, and the overall
29076architecture to which the feature applies; so e.g.@: the feature
29077containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
29078
ff6f572f
DJ
29079The names of registers are not case sensitive for the purpose
29080of recognizing standard features, but @value{GDBN} will only display
29081registers using the capitalization used in the description.
29082
e9c17194
VP
29083@menu
29084* ARM Features::
1e26b4f8 29085* MIPS Features::
e9c17194 29086* M68K Features::
1e26b4f8 29087* PowerPC Features::
e9c17194
VP
29088@end menu
29089
29090
29091@node ARM Features
123dc839
DJ
29092@subsection ARM Features
29093@cindex target descriptions, ARM features
29094
29095The @samp{org.gnu.gdb.arm.core} feature is required for ARM targets.
29096It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
29097@samp{lr}, @samp{pc}, and @samp{cpsr}.
29098
29099The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
29100should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
29101
ff6f572f
DJ
29102The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
29103it should contain at least registers @samp{wR0} through @samp{wR15} and
29104@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
29105@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 29106
1e26b4f8 29107@node MIPS Features
f8b73d13
DJ
29108@subsection MIPS Features
29109@cindex target descriptions, MIPS features
29110
29111The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
29112It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
29113@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
29114on the target.
29115
29116The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
29117contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
29118registers. They may be 32-bit or 64-bit depending on the target.
29119
29120The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
29121it may be optional in a future version of @value{GDBN}. It should
29122contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
29123@samp{fir}. They may be 32-bit or 64-bit depending on the target.
29124
822b6570
DJ
29125The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
29126contain a single register, @samp{restart}, which is used by the
29127Linux kernel to control restartable syscalls.
29128
e9c17194
VP
29129@node M68K Features
29130@subsection M68K Features
29131@cindex target descriptions, M68K features
29132
29133@table @code
29134@item @samp{org.gnu.gdb.m68k.core}
29135@itemx @samp{org.gnu.gdb.coldfire.core}
29136@itemx @samp{org.gnu.gdb.fido.core}
29137One of those features must be always present.
249e1128 29138The feature that is present determines which flavor of m68k is
e9c17194
VP
29139used. The feature that is present should contain registers
29140@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
29141@samp{sp}, @samp{ps} and @samp{pc}.
29142
29143@item @samp{org.gnu.gdb.coldfire.fp}
29144This feature is optional. If present, it should contain registers
29145@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
29146@samp{fpiaddr}.
29147@end table
29148
1e26b4f8 29149@node PowerPC Features
7cc46491
DJ
29150@subsection PowerPC Features
29151@cindex target descriptions, PowerPC features
29152
29153The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
29154targets. It should contain registers @samp{r0} through @samp{r31},
29155@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
29156@samp{xer}. They may be 32-bit or 64-bit depending on the target.
29157
29158The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
29159contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
29160
29161The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
29162contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
29163and @samp{vrsave}.
29164
677c5bb1
LM
29165The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
29166contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
29167will combine these registers with the floating point registers
29168(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 29169through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
29170through @samp{vs63}, the set of vector registers for POWER7.
29171
7cc46491
DJ
29172The @samp{org.gnu.gdb.power.spe} feature is optional. It should
29173contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
29174@samp{spefscr}. SPE targets should provide 32-bit registers in
29175@samp{org.gnu.gdb.power.core} and provide the upper halves in
29176@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
29177these to present registers @samp{ev0} through @samp{ev31} to the
29178user.
29179
07e059b5
VP
29180@node Operating System Information
29181@appendix Operating System Information
29182@cindex operating system information
29183
29184@menu
29185* Process list::
29186@end menu
29187
29188Users of @value{GDBN} often wish to obtain information about the state of
29189the operating system running on the target---for example the list of
29190processes, or the list of open files. This section describes the
29191mechanism that makes it possible. This mechanism is similar to the
29192target features mechanism (@pxref{Target Descriptions}), but focuses
29193on a different aspect of target.
29194
29195Operating system information is retrived from the target via the
29196remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
29197read}). The object name in the request should be @samp{osdata}, and
29198the @var{annex} identifies the data to be fetched.
29199
29200@node Process list
29201@appendixsection Process list
29202@cindex operating system information, process list
29203
29204When requesting the process list, the @var{annex} field in the
29205@samp{qXfer} request should be @samp{processes}. The returned data is
29206an XML document. The formal syntax of this document is defined in
29207@file{gdb/features/osdata.dtd}.
29208
29209An example document is:
29210
29211@smallexample
29212<?xml version="1.0"?>
29213<!DOCTYPE target SYSTEM "osdata.dtd">
29214<osdata type="processes">
29215 <item>
29216 <column name="pid">1</column>
29217 <column name="user">root</column>
29218 <column name="command">/sbin/init</column>
29219 </item>
29220</osdata>
29221@end smallexample
29222
29223Each item should include a column whose name is @samp{pid}. The value
29224of that column should identify the process on the target. The
29225@samp{user} and @samp{command} columns are optional, and will be
29226displayed by @value{GDBN}. Target may provide additional columns,
29227which @value{GDBN} currently ignores.
29228
aab4e0ec 29229@include gpl.texi
eb12ee30 29230
2154891a 29231@raisesections
6826cf00 29232@include fdl.texi
2154891a 29233@lowersections
6826cf00 29234
6d2ebf8b 29235@node Index
c906108c
SS
29236@unnumbered Index
29237
29238@printindex cp
29239
29240@tex
29241% I think something like @colophon should be in texinfo. In the
29242% meantime:
29243\long\def\colophon{\hbox to0pt{}\vfill
29244\centerline{The body of this manual is set in}
29245\centerline{\fontname\tenrm,}
29246\centerline{with headings in {\bf\fontname\tenbf}}
29247\centerline{and examples in {\tt\fontname\tentt}.}
29248\centerline{{\it\fontname\tenit\/},}
29249\centerline{{\bf\fontname\tenbf}, and}
29250\centerline{{\sl\fontname\tensl\/}}
29251\centerline{are used for emphasis.}\vfill}
29252\page\colophon
29253% Blame: doc@cygnus.com, 1991.
29254@end tex
29255
c906108c 29256@bye
This page took 4.555719 seconds and 4 git commands to generate.