s/@example/@smallexample/
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
3 @c 1999, 2000, 2001, 2002
4 @c Free Software Foundation, Inc.
5 @c
6 @c %**start of header
7 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8 @c of @set vars. However, you can override filename with makeinfo -o.
9 @setfilename gdb.info
10 @c
11 @include gdb-cfg.texi
12 @c
13 @settitle Debugging with @value{GDBN}
14 @setchapternewpage odd
15 @c %**end of header
16
17 @iftex
18 @c @smallbook
19 @c @cropmarks
20 @end iftex
21
22 @finalout
23 @syncodeindex ky cp
24
25 @c readline appendices use @vindex, @findex and @ftable,
26 @c annotate.texi and gdbmi use @findex.
27 @syncodeindex vr cp
28 @syncodeindex fn cp
29
30 @c !!set GDB manual's edition---not the same as GDB version!
31 @set EDITION Ninth
32
33 @c !!set GDB manual's revision date
34 @set DATE December 2001
35
36 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
37
38 @c This is a dir.info fragment to support semi-automated addition of
39 @c manuals to an info tree.
40 @dircategory Programming & development tools.
41 @direntry
42 * Gdb: (gdb). The @sc{gnu} debugger.
43 @end direntry
44
45 @ifinfo
46 This file documents the @sc{gnu} debugger @value{GDBN}.
47
48
49 This is the @value{EDITION} Edition, @value{DATE},
50 of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
51 for @value{GDBN} Version @value{GDBVN}.
52
53 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
54 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
55
56 Permission is granted to copy, distribute and/or modify this document
57 under the terms of the GNU Free Documentation License, Version 1.1 or
58 any later version published by the Free Software Foundation; with the
59 Invariant Sections being ``Free Software'' and ``Free Software Needs
60 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
61 and with the Back-Cover Texts as in (a) below.
62
63 (a) The Free Software Foundation's Back-Cover Text is: ``You have
64 freedom to copy and modify this GNU Manual, like GNU software. Copies
65 published by the Free Software Foundation raise funds for GNU
66 development.''
67 @end ifinfo
68
69 @titlepage
70 @title Debugging with @value{GDBN}
71 @subtitle The @sc{gnu} Source-Level Debugger
72 @sp 1
73 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
74 @subtitle @value{DATE}
75 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
76 @page
77 @tex
78 {\parskip=0pt
79 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
80 \hfill {\it Debugging with @value{GDBN}}\par
81 \hfill \TeX{}info \texinfoversion\par
82 }
83 @end tex
84
85 @vskip 0pt plus 1filll
86 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
87 1996, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
88 @sp 2
89 Published by the Free Software Foundation @*
90 59 Temple Place - Suite 330, @*
91 Boston, MA 02111-1307 USA @*
92 ISBN 1-882114-77-9 @*
93
94 Permission is granted to copy, distribute and/or modify this document
95 under the terms of the GNU Free Documentation License, Version 1.1 or
96 any later version published by the Free Software Foundation; with the
97 Invariant Sections being ``Free Software'' and ``Free Software Needs
98 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
99 and with the Back-Cover Texts as in (a) below.
100
101 (a) The Free Software Foundation's Back-Cover Text is: ``You have
102 freedom to copy and modify this GNU Manual, like GNU software. Copies
103 published by the Free Software Foundation raise funds for GNU
104 development.''
105 @end titlepage
106 @page
107
108 @ifnottex
109 @node Top, Summary, (dir), (dir)
110
111 @top Debugging with @value{GDBN}
112
113 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
114
115 This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
116 @value{GDBVN}.
117
118 Copyright (C) 1988-2002 Free Software Foundation, Inc.
119
120 @menu
121 * Summary:: Summary of @value{GDBN}
122 * Sample Session:: A sample @value{GDBN} session
123
124 * Invocation:: Getting in and out of @value{GDBN}
125 * Commands:: @value{GDBN} commands
126 * Running:: Running programs under @value{GDBN}
127 * Stopping:: Stopping and continuing
128 * Stack:: Examining the stack
129 * Source:: Examining source files
130 * Data:: Examining data
131 * Tracepoints:: Debugging remote targets non-intrusively
132 * Overlays:: Debugging programs that use overlays
133
134 * Languages:: Using @value{GDBN} with different languages
135
136 * Symbols:: Examining the symbol table
137 * Altering:: Altering execution
138 * GDB Files:: @value{GDBN} files
139 * Targets:: Specifying a debugging target
140 * Remote Debugging:: Debugging remote programs
141 * Configurations:: Configuration-specific information
142 * Controlling GDB:: Controlling @value{GDBN}
143 * Sequences:: Canned sequences of commands
144 * TUI:: @value{GDBN} Text User Interface
145 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
146 * Annotations:: @value{GDBN}'s annotation interface.
147 * GDB/MI:: @value{GDBN}'s Machine Interface.
148
149 * GDB Bugs:: Reporting bugs in @value{GDBN}
150 * Formatting Documentation:: How to format and print @value{GDBN} documentation
151
152 * Command Line Editing:: Command Line Editing
153 * Using History Interactively:: Using History Interactively
154 * Installing GDB:: Installing GDB
155 * Maintenance Commands:: Maintenance Commands
156 * Remote Protocol:: GDB Remote Serial Protocol
157 * Copying:: GNU General Public License says
158 how you can copy and share GDB
159 * GNU Free Documentation License:: The license for this documentation
160 * Index:: Index
161 @end menu
162
163 @end ifnottex
164
165 @contents
166
167 @node Summary
168 @unnumbered Summary of @value{GDBN}
169
170 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
171 going on ``inside'' another program while it executes---or what another
172 program was doing at the moment it crashed.
173
174 @value{GDBN} can do four main kinds of things (plus other things in support of
175 these) to help you catch bugs in the act:
176
177 @itemize @bullet
178 @item
179 Start your program, specifying anything that might affect its behavior.
180
181 @item
182 Make your program stop on specified conditions.
183
184 @item
185 Examine what has happened, when your program has stopped.
186
187 @item
188 Change things in your program, so you can experiment with correcting the
189 effects of one bug and go on to learn about another.
190 @end itemize
191
192 You can use @value{GDBN} to debug programs written in C and C++.
193 For more information, see @ref{Support,,Supported languages}.
194 For more information, see @ref{C,,C and C++}.
195
196 @cindex Chill
197 @cindex Modula-2
198 Support for Modula-2 and Chill is partial. For information on Modula-2,
199 see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
200
201 @cindex Pascal
202 Debugging Pascal programs which use sets, subranges, file variables, or
203 nested functions does not currently work. @value{GDBN} does not support
204 entering expressions, printing values, or similar features using Pascal
205 syntax.
206
207 @cindex Fortran
208 @value{GDBN} can be used to debug programs written in Fortran, although
209 it may be necessary to refer to some variables with a trailing
210 underscore.
211
212 @menu
213 * Free Software:: Freely redistributable software
214 * Contributors:: Contributors to GDB
215 @end menu
216
217 @node Free Software
218 @unnumberedsec Free software
219
220 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
221 General Public License
222 (GPL). The GPL gives you the freedom to copy or adapt a licensed
223 program---but every person getting a copy also gets with it the
224 freedom to modify that copy (which means that they must get access to
225 the source code), and the freedom to distribute further copies.
226 Typical software companies use copyrights to limit your freedoms; the
227 Free Software Foundation uses the GPL to preserve these freedoms.
228
229 Fundamentally, the General Public License is a license which says that
230 you have these freedoms and that you cannot take these freedoms away
231 from anyone else.
232
233 @unnumberedsec Free Software Needs Free Documentation
234
235 The biggest deficiency in the free software community today is not in
236 the software---it is the lack of good free documentation that we can
237 include with the free software. Many of our most important
238 programs do not come with free reference manuals and free introductory
239 texts. Documentation is an essential part of any software package;
240 when an important free software package does not come with a free
241 manual and a free tutorial, that is a major gap. We have many such
242 gaps today.
243
244 Consider Perl, for instance. The tutorial manuals that people
245 normally use are non-free. How did this come about? Because the
246 authors of those manuals published them with restrictive terms---no
247 copying, no modification, source files not available---which exclude
248 them from the free software world.
249
250 That wasn't the first time this sort of thing happened, and it was far
251 from the last. Many times we have heard a GNU user eagerly describe a
252 manual that he is writing, his intended contribution to the community,
253 only to learn that he had ruined everything by signing a publication
254 contract to make it non-free.
255
256 Free documentation, like free software, is a matter of freedom, not
257 price. The problem with the non-free manual is not that publishers
258 charge a price for printed copies---that in itself is fine. (The Free
259 Software Foundation sells printed copies of manuals, too.) The
260 problem is the restrictions on the use of the manual. Free manuals
261 are available in source code form, and give you permission to copy and
262 modify. Non-free manuals do not allow this.
263
264 The criteria of freedom for a free manual are roughly the same as for
265 free software. Redistribution (including the normal kinds of
266 commercial redistribution) must be permitted, so that the manual can
267 accompany every copy of the program, both on-line and on paper.
268
269 Permission for modification of the technical content is crucial too.
270 When people modify the software, adding or changing features, if they
271 are conscientious they will change the manual too---so they can
272 provide accurate and clear documentation for the modified program. A
273 manual that leaves you no choice but to write a new manual to document
274 a changed version of the program is not really available to our
275 community.
276
277 Some kinds of limits on the way modification is handled are
278 acceptable. For example, requirements to preserve the original
279 author's copyright notice, the distribution terms, or the list of
280 authors, are ok. It is also no problem to require modified versions
281 to include notice that they were modified. Even entire sections that
282 may not be deleted or changed are acceptable, as long as they deal
283 with nontechnical topics (like this one). These kinds of restrictions
284 are acceptable because they don't obstruct the community's normal use
285 of the manual.
286
287 However, it must be possible to modify all the @emph{technical}
288 content of the manual, and then distribute the result in all the usual
289 media, through all the usual channels. Otherwise, the restrictions
290 obstruct the use of the manual, it is not free, and we need another
291 manual to replace it.
292
293 Please spread the word about this issue. Our community continues to
294 lose manuals to proprietary publishing. If we spread the word that
295 free software needs free reference manuals and free tutorials, perhaps
296 the next person who wants to contribute by writing documentation will
297 realize, before it is too late, that only free manuals contribute to
298 the free software community.
299
300 If you are writing documentation, please insist on publishing it under
301 the GNU Free Documentation License or another free documentation
302 license. Remember that this decision requires your approval---you
303 don't have to let the publisher decide. Some commercial publishers
304 will use a free license if you insist, but they will not propose the
305 option; it is up to you to raise the issue and say firmly that this is
306 what you want. If the publisher you are dealing with refuses, please
307 try other publishers. If you're not sure whether a proposed license
308 is free, write to @email{licensing@@gnu.org}.
309
310 You can encourage commercial publishers to sell more free, copylefted
311 manuals and tutorials by buying them, and particularly by buying
312 copies from the publishers that paid for their writing or for major
313 improvements. Meanwhile, try to avoid buying non-free documentation
314 at all. Check the distribution terms of a manual before you buy it,
315 and insist that whoever seeks your business must respect your freedom.
316 Check the history of the book, and try to reward the publishers that
317 have paid or pay the authors to work on it.
318
319 The Free Software Foundation maintains a list of free documentation
320 published by other publishers, at
321 @url{http://www.fsf.org/doc/other-free-books.html}.
322
323 @node Contributors
324 @unnumberedsec Contributors to @value{GDBN}
325
326 Richard Stallman was the original author of @value{GDBN}, and of many
327 other @sc{gnu} programs. Many others have contributed to its
328 development. This section attempts to credit major contributors. One
329 of the virtues of free software is that everyone is free to contribute
330 to it; with regret, we cannot actually acknowledge everyone here. The
331 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
332 blow-by-blow account.
333
334 Changes much prior to version 2.0 are lost in the mists of time.
335
336 @quotation
337 @emph{Plea:} Additions to this section are particularly welcome. If you
338 or your friends (or enemies, to be evenhanded) have been unfairly
339 omitted from this list, we would like to add your names!
340 @end quotation
341
342 So that they may not regard their many labors as thankless, we
343 particularly thank those who shepherded @value{GDBN} through major
344 releases:
345 Andrew Cagney (releases 5.0 and 5.1);
346 Jim Blandy (release 4.18);
347 Jason Molenda (release 4.17);
348 Stan Shebs (release 4.14);
349 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
350 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
351 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
352 Jim Kingdon (releases 3.5, 3.4, and 3.3);
353 and Randy Smith (releases 3.2, 3.1, and 3.0).
354
355 Richard Stallman, assisted at various times by Peter TerMaat, Chris
356 Hanson, and Richard Mlynarik, handled releases through 2.8.
357
358 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
359 in @value{GDBN}, with significant additional contributions from Per
360 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
361 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
362 much general update work leading to release 3.0).
363
364 @value{GDBN} uses the BFD subroutine library to examine multiple
365 object-file formats; BFD was a joint project of David V.
366 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
367
368 David Johnson wrote the original COFF support; Pace Willison did
369 the original support for encapsulated COFF.
370
371 Brent Benson of Harris Computer Systems contributed DWARF2 support.
372
373 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
374 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
375 support.
376 Jean-Daniel Fekete contributed Sun 386i support.
377 Chris Hanson improved the HP9000 support.
378 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
379 David Johnson contributed Encore Umax support.
380 Jyrki Kuoppala contributed Altos 3068 support.
381 Jeff Law contributed HP PA and SOM support.
382 Keith Packard contributed NS32K support.
383 Doug Rabson contributed Acorn Risc Machine support.
384 Bob Rusk contributed Harris Nighthawk CX-UX support.
385 Chris Smith contributed Convex support (and Fortran debugging).
386 Jonathan Stone contributed Pyramid support.
387 Michael Tiemann contributed SPARC support.
388 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
389 Pace Willison contributed Intel 386 support.
390 Jay Vosburgh contributed Symmetry support.
391
392 Andreas Schwab contributed M68K Linux support.
393
394 Rich Schaefer and Peter Schauer helped with support of SunOS shared
395 libraries.
396
397 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
398 about several machine instruction sets.
399
400 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
401 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
402 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
403 and RDI targets, respectively.
404
405 Brian Fox is the author of the readline libraries providing
406 command-line editing and command history.
407
408 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
409 Modula-2 support, and contributed the Languages chapter of this manual.
410
411 Fred Fish wrote most of the support for Unix System Vr4.
412 He also enhanced the command-completion support to cover C@t{++} overloaded
413 symbols.
414
415 Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
416 Super-H processors.
417
418 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
419
420 Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
421
422 Toshiba sponsored the support for the TX39 Mips processor.
423
424 Matsushita sponsored the support for the MN10200 and MN10300 processors.
425
426 Fujitsu sponsored the support for SPARClite and FR30 processors.
427
428 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
429 watchpoints.
430
431 Michael Snyder added support for tracepoints.
432
433 Stu Grossman wrote gdbserver.
434
435 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
436 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
437
438 The following people at the Hewlett-Packard Company contributed
439 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
440 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
441 compiler, and the terminal user interface: Ben Krepp, Richard Title,
442 John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
443 Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
444 information in this manual.
445
446 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
447 Robert Hoehne made significant contributions to the DJGPP port.
448
449 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
450 development since 1991. Cygnus engineers who have worked on @value{GDBN}
451 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
452 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
453 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
454 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
455 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
456 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
457 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
458 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
459 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
460 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
461 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
462 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
463 Zuhn have made contributions both large and small.
464
465
466 @node Sample Session
467 @chapter A Sample @value{GDBN} Session
468
469 You can use this manual at your leisure to read all about @value{GDBN}.
470 However, a handful of commands are enough to get started using the
471 debugger. This chapter illustrates those commands.
472
473 @iftex
474 In this sample session, we emphasize user input like this: @b{input},
475 to make it easier to pick out from the surrounding output.
476 @end iftex
477
478 @c FIXME: this example may not be appropriate for some configs, where
479 @c FIXME...primary interest is in remote use.
480
481 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
482 processor) exhibits the following bug: sometimes, when we change its
483 quote strings from the default, the commands used to capture one macro
484 definition within another stop working. In the following short @code{m4}
485 session, we define a macro @code{foo} which expands to @code{0000}; we
486 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
487 same thing. However, when we change the open quote string to
488 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
489 procedure fails to define a new synonym @code{baz}:
490
491 @smallexample
492 $ @b{cd gnu/m4}
493 $ @b{./m4}
494 @b{define(foo,0000)}
495
496 @b{foo}
497 0000
498 @b{define(bar,defn(`foo'))}
499
500 @b{bar}
501 0000
502 @b{changequote(<QUOTE>,<UNQUOTE>)}
503
504 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
505 @b{baz}
506 @b{C-d}
507 m4: End of input: 0: fatal error: EOF in string
508 @end smallexample
509
510 @noindent
511 Let us use @value{GDBN} to try to see what is going on.
512
513 @smallexample
514 $ @b{@value{GDBP} m4}
515 @c FIXME: this falsifies the exact text played out, to permit smallbook
516 @c FIXME... format to come out better.
517 @value{GDBN} is free software and you are welcome to distribute copies
518 of it under certain conditions; type "show copying" to see
519 the conditions.
520 There is absolutely no warranty for @value{GDBN}; type "show warranty"
521 for details.
522
523 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
524 (@value{GDBP})
525 @end smallexample
526
527 @noindent
528 @value{GDBN} reads only enough symbol data to know where to find the
529 rest when needed; as a result, the first prompt comes up very quickly.
530 We now tell @value{GDBN} to use a narrower display width than usual, so
531 that examples fit in this manual.
532
533 @smallexample
534 (@value{GDBP}) @b{set width 70}
535 @end smallexample
536
537 @noindent
538 We need to see how the @code{m4} built-in @code{changequote} works.
539 Having looked at the source, we know the relevant subroutine is
540 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
541 @code{break} command.
542
543 @smallexample
544 (@value{GDBP}) @b{break m4_changequote}
545 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
546 @end smallexample
547
548 @noindent
549 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
550 control; as long as control does not reach the @code{m4_changequote}
551 subroutine, the program runs as usual:
552
553 @smallexample
554 (@value{GDBP}) @b{run}
555 Starting program: /work/Editorial/gdb/gnu/m4/m4
556 @b{define(foo,0000)}
557
558 @b{foo}
559 0000
560 @end smallexample
561
562 @noindent
563 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
564 suspends execution of @code{m4}, displaying information about the
565 context where it stops.
566
567 @smallexample
568 @b{changequote(<QUOTE>,<UNQUOTE>)}
569
570 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
571 at builtin.c:879
572 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
573 @end smallexample
574
575 @noindent
576 Now we use the command @code{n} (@code{next}) to advance execution to
577 the next line of the current function.
578
579 @smallexample
580 (@value{GDBP}) @b{n}
581 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
582 : nil,
583 @end smallexample
584
585 @noindent
586 @code{set_quotes} looks like a promising subroutine. We can go into it
587 by using the command @code{s} (@code{step}) instead of @code{next}.
588 @code{step} goes to the next line to be executed in @emph{any}
589 subroutine, so it steps into @code{set_quotes}.
590
591 @smallexample
592 (@value{GDBP}) @b{s}
593 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
594 at input.c:530
595 530 if (lquote != def_lquote)
596 @end smallexample
597
598 @noindent
599 The display that shows the subroutine where @code{m4} is now
600 suspended (and its arguments) is called a stack frame display. It
601 shows a summary of the stack. We can use the @code{backtrace}
602 command (which can also be spelled @code{bt}), to see where we are
603 in the stack as a whole: the @code{backtrace} command displays a
604 stack frame for each active subroutine.
605
606 @smallexample
607 (@value{GDBP}) @b{bt}
608 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
609 at input.c:530
610 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
611 at builtin.c:882
612 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
613 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
614 at macro.c:71
615 #4 0x79dc in expand_input () at macro.c:40
616 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
617 @end smallexample
618
619 @noindent
620 We step through a few more lines to see what happens. The first two
621 times, we can use @samp{s}; the next two times we use @code{n} to avoid
622 falling into the @code{xstrdup} subroutine.
623
624 @smallexample
625 (@value{GDBP}) @b{s}
626 0x3b5c 532 if (rquote != def_rquote)
627 (@value{GDBP}) @b{s}
628 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
629 def_lquote : xstrdup(lq);
630 (@value{GDBP}) @b{n}
631 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
632 : xstrdup(rq);
633 (@value{GDBP}) @b{n}
634 538 len_lquote = strlen(rquote);
635 @end smallexample
636
637 @noindent
638 The last line displayed looks a little odd; we can examine the variables
639 @code{lquote} and @code{rquote} to see if they are in fact the new left
640 and right quotes we specified. We use the command @code{p}
641 (@code{print}) to see their values.
642
643 @smallexample
644 (@value{GDBP}) @b{p lquote}
645 $1 = 0x35d40 "<QUOTE>"
646 (@value{GDBP}) @b{p rquote}
647 $2 = 0x35d50 "<UNQUOTE>"
648 @end smallexample
649
650 @noindent
651 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
652 To look at some context, we can display ten lines of source
653 surrounding the current line with the @code{l} (@code{list}) command.
654
655 @smallexample
656 (@value{GDBP}) @b{l}
657 533 xfree(rquote);
658 534
659 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
660 : xstrdup (lq);
661 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
662 : xstrdup (rq);
663 537
664 538 len_lquote = strlen(rquote);
665 539 len_rquote = strlen(lquote);
666 540 @}
667 541
668 542 void
669 @end smallexample
670
671 @noindent
672 Let us step past the two lines that set @code{len_lquote} and
673 @code{len_rquote}, and then examine the values of those variables.
674
675 @smallexample
676 (@value{GDBP}) @b{n}
677 539 len_rquote = strlen(lquote);
678 (@value{GDBP}) @b{n}
679 540 @}
680 (@value{GDBP}) @b{p len_lquote}
681 $3 = 9
682 (@value{GDBP}) @b{p len_rquote}
683 $4 = 7
684 @end smallexample
685
686 @noindent
687 That certainly looks wrong, assuming @code{len_lquote} and
688 @code{len_rquote} are meant to be the lengths of @code{lquote} and
689 @code{rquote} respectively. We can set them to better values using
690 the @code{p} command, since it can print the value of
691 any expression---and that expression can include subroutine calls and
692 assignments.
693
694 @smallexample
695 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
696 $5 = 7
697 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
698 $6 = 9
699 @end smallexample
700
701 @noindent
702 Is that enough to fix the problem of using the new quotes with the
703 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
704 executing with the @code{c} (@code{continue}) command, and then try the
705 example that caused trouble initially:
706
707 @smallexample
708 (@value{GDBP}) @b{c}
709 Continuing.
710
711 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
712
713 baz
714 0000
715 @end smallexample
716
717 @noindent
718 Success! The new quotes now work just as well as the default ones. The
719 problem seems to have been just the two typos defining the wrong
720 lengths. We allow @code{m4} exit by giving it an EOF as input:
721
722 @smallexample
723 @b{C-d}
724 Program exited normally.
725 @end smallexample
726
727 @noindent
728 The message @samp{Program exited normally.} is from @value{GDBN}; it
729 indicates @code{m4} has finished executing. We can end our @value{GDBN}
730 session with the @value{GDBN} @code{quit} command.
731
732 @smallexample
733 (@value{GDBP}) @b{quit}
734 @end smallexample
735
736 @node Invocation
737 @chapter Getting In and Out of @value{GDBN}
738
739 This chapter discusses how to start @value{GDBN}, and how to get out of it.
740 The essentials are:
741 @itemize @bullet
742 @item
743 type @samp{@value{GDBP}} to start @value{GDBN}.
744 @item
745 type @kbd{quit} or @kbd{C-d} to exit.
746 @end itemize
747
748 @menu
749 * Invoking GDB:: How to start @value{GDBN}
750 * Quitting GDB:: How to quit @value{GDBN}
751 * Shell Commands:: How to use shell commands inside @value{GDBN}
752 @end menu
753
754 @node Invoking GDB
755 @section Invoking @value{GDBN}
756
757 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
758 @value{GDBN} reads commands from the terminal until you tell it to exit.
759
760 You can also run @code{@value{GDBP}} with a variety of arguments and options,
761 to specify more of your debugging environment at the outset.
762
763 The command-line options described here are designed
764 to cover a variety of situations; in some environments, some of these
765 options may effectively be unavailable.
766
767 The most usual way to start @value{GDBN} is with one argument,
768 specifying an executable program:
769
770 @smallexample
771 @value{GDBP} @var{program}
772 @end smallexample
773
774 @noindent
775 You can also start with both an executable program and a core file
776 specified:
777
778 @smallexample
779 @value{GDBP} @var{program} @var{core}
780 @end smallexample
781
782 You can, instead, specify a process ID as a second argument, if you want
783 to debug a running process:
784
785 @smallexample
786 @value{GDBP} @var{program} 1234
787 @end smallexample
788
789 @noindent
790 would attach @value{GDBN} to process @code{1234} (unless you also have a file
791 named @file{1234}; @value{GDBN} does check for a core file first).
792
793 Taking advantage of the second command-line argument requires a fairly
794 complete operating system; when you use @value{GDBN} as a remote
795 debugger attached to a bare board, there may not be any notion of
796 ``process'', and there is often no way to get a core dump. @value{GDBN}
797 will warn you if it is unable to attach or to read core dumps.
798
799 You can optionally have @code{@value{GDBP}} pass any arguments after the
800 executable file to the inferior using @code{--args}. This option stops
801 option processing.
802 @smallexample
803 gdb --args gcc -O2 -c foo.c
804 @end smallexample
805 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
806 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
807
808 You can run @code{@value{GDBP}} without printing the front material, which describes
809 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
810
811 @smallexample
812 @value{GDBP} -silent
813 @end smallexample
814
815 @noindent
816 You can further control how @value{GDBN} starts up by using command-line
817 options. @value{GDBN} itself can remind you of the options available.
818
819 @noindent
820 Type
821
822 @smallexample
823 @value{GDBP} -help
824 @end smallexample
825
826 @noindent
827 to display all available options and briefly describe their use
828 (@samp{@value{GDBP} -h} is a shorter equivalent).
829
830 All options and command line arguments you give are processed
831 in sequential order. The order makes a difference when the
832 @samp{-x} option is used.
833
834
835 @menu
836 * File Options:: Choosing files
837 * Mode Options:: Choosing modes
838 @end menu
839
840 @node File Options
841 @subsection Choosing files
842
843 When @value{GDBN} starts, it reads any arguments other than options as
844 specifying an executable file and core file (or process ID). This is
845 the same as if the arguments were specified by the @samp{-se} and
846 @samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
847 first argument that does not have an associated option flag as
848 equivalent to the @samp{-se} option followed by that argument; and the
849 second argument that does not have an associated option flag, if any, as
850 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
851 If the second argument begins with a decimal digit, @value{GDBN} will
852 first attempt to attach to it as a process, and if that fails, attempt
853 to open it as a corefile. If you have a corefile whose name begins with
854 a digit, you can prevent @value{GDBN} from treating it as a pid by
855 prefixing it with @file{./}, eg. @file{./12345}.
856
857 If @value{GDBN} has not been configured to included core file support,
858 such as for most embedded targets, then it will complain about a second
859 argument and ignore it.
860
861 Many options have both long and short forms; both are shown in the
862 following list. @value{GDBN} also recognizes the long forms if you truncate
863 them, so long as enough of the option is present to be unambiguous.
864 (If you prefer, you can flag option arguments with @samp{--} rather
865 than @samp{-}, though we illustrate the more usual convention.)
866
867 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
868 @c way, both those who look for -foo and --foo in the index, will find
869 @c it.
870
871 @table @code
872 @item -symbols @var{file}
873 @itemx -s @var{file}
874 @cindex @code{--symbols}
875 @cindex @code{-s}
876 Read symbol table from file @var{file}.
877
878 @item -exec @var{file}
879 @itemx -e @var{file}
880 @cindex @code{--exec}
881 @cindex @code{-e}
882 Use file @var{file} as the executable file to execute when appropriate,
883 and for examining pure data in conjunction with a core dump.
884
885 @item -se @var{file}
886 @cindex @code{--se}
887 Read symbol table from file @var{file} and use it as the executable
888 file.
889
890 @item -core @var{file}
891 @itemx -c @var{file}
892 @cindex @code{--core}
893 @cindex @code{-c}
894 Use file @var{file} as a core dump to examine.
895
896 @item -c @var{number}
897 @item -pid @var{number}
898 @itemx -p @var{number}
899 @cindex @code{--pid}
900 @cindex @code{-p}
901 Connect to process ID @var{number}, as with the @code{attach} command.
902 If there is no such process, @value{GDBN} will attempt to open a core
903 file named @var{number}.
904
905 @item -command @var{file}
906 @itemx -x @var{file}
907 @cindex @code{--command}
908 @cindex @code{-x}
909 Execute @value{GDBN} commands from file @var{file}. @xref{Command
910 Files,, Command files}.
911
912 @item -directory @var{directory}
913 @itemx -d @var{directory}
914 @cindex @code{--directory}
915 @cindex @code{-d}
916 Add @var{directory} to the path to search for source files.
917
918 @item -m
919 @itemx -mapped
920 @cindex @code{--mapped}
921 @cindex @code{-m}
922 @emph{Warning: this option depends on operating system facilities that are not
923 supported on all systems.}@*
924 If memory-mapped files are available on your system through the @code{mmap}
925 system call, you can use this option
926 to have @value{GDBN} write the symbols from your
927 program into a reusable file in the current directory. If the program you are debugging is
928 called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
929 Future @value{GDBN} debugging sessions notice the presence of this file,
930 and can quickly map in symbol information from it, rather than reading
931 the symbol table from the executable program.
932
933 The @file{.syms} file is specific to the host machine where @value{GDBN}
934 is run. It holds an exact image of the internal @value{GDBN} symbol
935 table. It cannot be shared across multiple host platforms.
936
937 @item -r
938 @itemx -readnow
939 @cindex @code{--readnow}
940 @cindex @code{-r}
941 Read each symbol file's entire symbol table immediately, rather than
942 the default, which is to read it incrementally as it is needed.
943 This makes startup slower, but makes future operations faster.
944
945 @end table
946
947 You typically combine the @code{-mapped} and @code{-readnow} options in
948 order to build a @file{.syms} file that contains complete symbol
949 information. (@xref{Files,,Commands to specify files}, for information
950 on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
951 but build a @file{.syms} file for future use is:
952
953 @smallexample
954 gdb -batch -nx -mapped -readnow programname
955 @end smallexample
956
957 @node Mode Options
958 @subsection Choosing modes
959
960 You can run @value{GDBN} in various alternative modes---for example, in
961 batch mode or quiet mode.
962
963 @table @code
964 @item -nx
965 @itemx -n
966 @cindex @code{--nx}
967 @cindex @code{-n}
968 Do not execute commands found in any initialization files. Normally,
969 @value{GDBN} executes the commands in these files after all the command
970 options and arguments have been processed. @xref{Command Files,,Command
971 files}.
972
973 @item -quiet
974 @itemx -silent
975 @itemx -q
976 @cindex @code{--quiet}
977 @cindex @code{--silent}
978 @cindex @code{-q}
979 ``Quiet''. Do not print the introductory and copyright messages. These
980 messages are also suppressed in batch mode.
981
982 @item -batch
983 @cindex @code{--batch}
984 Run in batch mode. Exit with status @code{0} after processing all the
985 command files specified with @samp{-x} (and all commands from
986 initialization files, if not inhibited with @samp{-n}). Exit with
987 nonzero status if an error occurs in executing the @value{GDBN} commands
988 in the command files.
989
990 Batch mode may be useful for running @value{GDBN} as a filter, for
991 example to download and run a program on another computer; in order to
992 make this more useful, the message
993
994 @smallexample
995 Program exited normally.
996 @end smallexample
997
998 @noindent
999 (which is ordinarily issued whenever a program running under
1000 @value{GDBN} control terminates) is not issued when running in batch
1001 mode.
1002
1003 @item -nowindows
1004 @itemx -nw
1005 @cindex @code{--nowindows}
1006 @cindex @code{-nw}
1007 ``No windows''. If @value{GDBN} comes with a graphical user interface
1008 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1009 interface. If no GUI is available, this option has no effect.
1010
1011 @item -windows
1012 @itemx -w
1013 @cindex @code{--windows}
1014 @cindex @code{-w}
1015 If @value{GDBN} includes a GUI, then this option requires it to be
1016 used if possible.
1017
1018 @item -cd @var{directory}
1019 @cindex @code{--cd}
1020 Run @value{GDBN} using @var{directory} as its working directory,
1021 instead of the current directory.
1022
1023 @item -fullname
1024 @itemx -f
1025 @cindex @code{--fullname}
1026 @cindex @code{-f}
1027 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1028 subprocess. It tells @value{GDBN} to output the full file name and line
1029 number in a standard, recognizable fashion each time a stack frame is
1030 displayed (which includes each time your program stops). This
1031 recognizable format looks like two @samp{\032} characters, followed by
1032 the file name, line number and character position separated by colons,
1033 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1034 @samp{\032} characters as a signal to display the source code for the
1035 frame.
1036
1037 @item -epoch
1038 @cindex @code{--epoch}
1039 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1040 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1041 routines so as to allow Epoch to display values of expressions in a
1042 separate window.
1043
1044 @item -annotate @var{level}
1045 @cindex @code{--annotate}
1046 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1047 effect is identical to using @samp{set annotate @var{level}}
1048 (@pxref{Annotations}).
1049 Annotation level controls how much information does @value{GDBN} print
1050 together with its prompt, values of expressions, source lines, and other
1051 types of output. Level 0 is the normal, level 1 is for use when
1052 @value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
1053 maximum annotation suitable for programs that control @value{GDBN}.
1054
1055 @item -async
1056 @cindex @code{--async}
1057 Use the asynchronous event loop for the command-line interface.
1058 @value{GDBN} processes all events, such as user keyboard input, via a
1059 special event loop. This allows @value{GDBN} to accept and process user
1060 commands in parallel with the debugged process being
1061 run@footnote{@value{GDBN} built with @sc{djgpp} tools for
1062 MS-DOS/MS-Windows supports this mode of operation, but the event loop is
1063 suspended when the debuggee runs.}, so you don't need to wait for
1064 control to return to @value{GDBN} before you type the next command.
1065 (@emph{Note:} as of version 5.1, the target side of the asynchronous
1066 operation is not yet in place, so @samp{-async} does not work fully
1067 yet.)
1068 @c FIXME: when the target side of the event loop is done, the above NOTE
1069 @c should be removed.
1070
1071 When the standard input is connected to a terminal device, @value{GDBN}
1072 uses the asynchronous event loop by default, unless disabled by the
1073 @samp{-noasync} option.
1074
1075 @item -noasync
1076 @cindex @code{--noasync}
1077 Disable the asynchronous event loop for the command-line interface.
1078
1079 @item --args
1080 @cindex @code{--args}
1081 Change interpretation of command line so that arguments following the
1082 executable file are passed as command line arguments to the inferior.
1083 This option stops option processing.
1084
1085 @item -baud @var{bps}
1086 @itemx -b @var{bps}
1087 @cindex @code{--baud}
1088 @cindex @code{-b}
1089 Set the line speed (baud rate or bits per second) of any serial
1090 interface used by @value{GDBN} for remote debugging.
1091
1092 @item -tty @var{device}
1093 @itemx -t @var{device}
1094 @cindex @code{--tty}
1095 @cindex @code{-t}
1096 Run using @var{device} for your program's standard input and output.
1097 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1098
1099 @c resolve the situation of these eventually
1100 @item -tui
1101 @cindex @code{--tui}
1102 Activate the Terminal User Interface when starting.
1103 The Terminal User Interface manages several text windows on the terminal,
1104 showing source, assembly, registers and @value{GDBN} command outputs
1105 (@pxref{TUI, ,@value{GDBN} Text User Interface}).
1106 Do not use this option if you run @value{GDBN} from Emacs
1107 (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
1108
1109 @c @item -xdb
1110 @c @cindex @code{--xdb}
1111 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1112 @c For information, see the file @file{xdb_trans.html}, which is usually
1113 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1114 @c systems.
1115
1116 @item -interpreter @var{interp}
1117 @cindex @code{--interpreter}
1118 Use the interpreter @var{interp} for interface with the controlling
1119 program or device. This option is meant to be set by programs which
1120 communicate with @value{GDBN} using it as a back end.
1121
1122 @samp{--interpreter=mi} (or @samp{--interpreter=mi1}) causes
1123 @value{GDBN} to use the @dfn{gdb/mi interface} (@pxref{GDB/MI, , The
1124 @sc{gdb/mi} Interface}). The older @sc{gdb/mi} interface, included in
1125 @value{GDBN} version 5.0 can be selected with @samp{--interpreter=mi0}.
1126
1127 @item -write
1128 @cindex @code{--write}
1129 Open the executable and core files for both reading and writing. This
1130 is equivalent to the @samp{set write on} command inside @value{GDBN}
1131 (@pxref{Patching}).
1132
1133 @item -statistics
1134 @cindex @code{--statistics}
1135 This option causes @value{GDBN} to print statistics about time and
1136 memory usage after it completes each command and returns to the prompt.
1137
1138 @item -version
1139 @cindex @code{--version}
1140 This option causes @value{GDBN} to print its version number and
1141 no-warranty blurb, and exit.
1142
1143 @end table
1144
1145 @node Quitting GDB
1146 @section Quitting @value{GDBN}
1147 @cindex exiting @value{GDBN}
1148 @cindex leaving @value{GDBN}
1149
1150 @table @code
1151 @kindex quit @r{[}@var{expression}@r{]}
1152 @kindex q @r{(@code{quit})}
1153 @item quit @r{[}@var{expression}@r{]}
1154 @itemx q
1155 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1156 @code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1157 do not supply @var{expression}, @value{GDBN} will terminate normally;
1158 otherwise it will terminate using the result of @var{expression} as the
1159 error code.
1160 @end table
1161
1162 @cindex interrupt
1163 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1164 terminates the action of any @value{GDBN} command that is in progress and
1165 returns to @value{GDBN} command level. It is safe to type the interrupt
1166 character at any time because @value{GDBN} does not allow it to take effect
1167 until a time when it is safe.
1168
1169 If you have been using @value{GDBN} to control an attached process or
1170 device, you can release it with the @code{detach} command
1171 (@pxref{Attach, ,Debugging an already-running process}).
1172
1173 @node Shell Commands
1174 @section Shell commands
1175
1176 If you need to execute occasional shell commands during your
1177 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1178 just use the @code{shell} command.
1179
1180 @table @code
1181 @kindex shell
1182 @cindex shell escape
1183 @item shell @var{command string}
1184 Invoke a standard shell to execute @var{command string}.
1185 If it exists, the environment variable @code{SHELL} determines which
1186 shell to run. Otherwise @value{GDBN} uses the default shell
1187 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1188 @end table
1189
1190 The utility @code{make} is often needed in development environments.
1191 You do not have to use the @code{shell} command for this purpose in
1192 @value{GDBN}:
1193
1194 @table @code
1195 @kindex make
1196 @cindex calling make
1197 @item make @var{make-args}
1198 Execute the @code{make} program with the specified
1199 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1200 @end table
1201
1202 @node Commands
1203 @chapter @value{GDBN} Commands
1204
1205 You can abbreviate a @value{GDBN} command to the first few letters of the command
1206 name, if that abbreviation is unambiguous; and you can repeat certain
1207 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1208 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1209 show you the alternatives available, if there is more than one possibility).
1210
1211 @menu
1212 * Command Syntax:: How to give commands to @value{GDBN}
1213 * Completion:: Command completion
1214 * Help:: How to ask @value{GDBN} for help
1215 @end menu
1216
1217 @node Command Syntax
1218 @section Command syntax
1219
1220 A @value{GDBN} command is a single line of input. There is no limit on
1221 how long it can be. It starts with a command name, which is followed by
1222 arguments whose meaning depends on the command name. For example, the
1223 command @code{step} accepts an argument which is the number of times to
1224 step, as in @samp{step 5}. You can also use the @code{step} command
1225 with no arguments. Some commands do not allow any arguments.
1226
1227 @cindex abbreviation
1228 @value{GDBN} command names may always be truncated if that abbreviation is
1229 unambiguous. Other possible command abbreviations are listed in the
1230 documentation for individual commands. In some cases, even ambiguous
1231 abbreviations are allowed; for example, @code{s} is specially defined as
1232 equivalent to @code{step} even though there are other commands whose
1233 names start with @code{s}. You can test abbreviations by using them as
1234 arguments to the @code{help} command.
1235
1236 @cindex repeating commands
1237 @kindex RET @r{(repeat last command)}
1238 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1239 repeat the previous command. Certain commands (for example, @code{run})
1240 will not repeat this way; these are commands whose unintentional
1241 repetition might cause trouble and which you are unlikely to want to
1242 repeat.
1243
1244 The @code{list} and @code{x} commands, when you repeat them with
1245 @key{RET}, construct new arguments rather than repeating
1246 exactly as typed. This permits easy scanning of source or memory.
1247
1248 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1249 output, in a way similar to the common utility @code{more}
1250 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
1251 @key{RET} too many in this situation, @value{GDBN} disables command
1252 repetition after any command that generates this sort of display.
1253
1254 @kindex # @r{(a comment)}
1255 @cindex comment
1256 Any text from a @kbd{#} to the end of the line is a comment; it does
1257 nothing. This is useful mainly in command files (@pxref{Command
1258 Files,,Command files}).
1259
1260 @cindex repeating command sequences
1261 @kindex C-o @r{(operate-and-get-next)}
1262 The @kbd{C-o} binding is useful for repeating a complex sequence of
1263 commands. This command accepts the current line, like @kbd{RET}, and
1264 then fetches the next line relative to the current line from the history
1265 for editing.
1266
1267 @node Completion
1268 @section Command completion
1269
1270 @cindex completion
1271 @cindex word completion
1272 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1273 only one possibility; it can also show you what the valid possibilities
1274 are for the next word in a command, at any time. This works for @value{GDBN}
1275 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1276
1277 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1278 of a word. If there is only one possibility, @value{GDBN} fills in the
1279 word, and waits for you to finish the command (or press @key{RET} to
1280 enter it). For example, if you type
1281
1282 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1283 @c complete accuracy in these examples; space introduced for clarity.
1284 @c If texinfo enhancements make it unnecessary, it would be nice to
1285 @c replace " @key" by "@key" in the following...
1286 @smallexample
1287 (@value{GDBP}) info bre @key{TAB}
1288 @end smallexample
1289
1290 @noindent
1291 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1292 the only @code{info} subcommand beginning with @samp{bre}:
1293
1294 @smallexample
1295 (@value{GDBP}) info breakpoints
1296 @end smallexample
1297
1298 @noindent
1299 You can either press @key{RET} at this point, to run the @code{info
1300 breakpoints} command, or backspace and enter something else, if
1301 @samp{breakpoints} does not look like the command you expected. (If you
1302 were sure you wanted @code{info breakpoints} in the first place, you
1303 might as well just type @key{RET} immediately after @samp{info bre},
1304 to exploit command abbreviations rather than command completion).
1305
1306 If there is more than one possibility for the next word when you press
1307 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1308 characters and try again, or just press @key{TAB} a second time;
1309 @value{GDBN} displays all the possible completions for that word. For
1310 example, you might want to set a breakpoint on a subroutine whose name
1311 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1312 just sounds the bell. Typing @key{TAB} again displays all the
1313 function names in your program that begin with those characters, for
1314 example:
1315
1316 @smallexample
1317 (@value{GDBP}) b make_ @key{TAB}
1318 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1319 make_a_section_from_file make_environ
1320 make_abs_section make_function_type
1321 make_blockvector make_pointer_type
1322 make_cleanup make_reference_type
1323 make_command make_symbol_completion_list
1324 (@value{GDBP}) b make_
1325 @end smallexample
1326
1327 @noindent
1328 After displaying the available possibilities, @value{GDBN} copies your
1329 partial input (@samp{b make_} in the example) so you can finish the
1330 command.
1331
1332 If you just want to see the list of alternatives in the first place, you
1333 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1334 means @kbd{@key{META} ?}. You can type this either by holding down a
1335 key designated as the @key{META} shift on your keyboard (if there is
1336 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1337
1338 @cindex quotes in commands
1339 @cindex completion of quoted strings
1340 Sometimes the string you need, while logically a ``word'', may contain
1341 parentheses or other characters that @value{GDBN} normally excludes from
1342 its notion of a word. To permit word completion to work in this
1343 situation, you may enclose words in @code{'} (single quote marks) in
1344 @value{GDBN} commands.
1345
1346 The most likely situation where you might need this is in typing the
1347 name of a C@t{++} function. This is because C@t{++} allows function
1348 overloading (multiple definitions of the same function, distinguished
1349 by argument type). For example, when you want to set a breakpoint you
1350 may need to distinguish whether you mean the version of @code{name}
1351 that takes an @code{int} parameter, @code{name(int)}, or the version
1352 that takes a @code{float} parameter, @code{name(float)}. To use the
1353 word-completion facilities in this situation, type a single quote
1354 @code{'} at the beginning of the function name. This alerts
1355 @value{GDBN} that it may need to consider more information than usual
1356 when you press @key{TAB} or @kbd{M-?} to request word completion:
1357
1358 @smallexample
1359 (@value{GDBP}) b 'bubble( @kbd{M-?}
1360 bubble(double,double) bubble(int,int)
1361 (@value{GDBP}) b 'bubble(
1362 @end smallexample
1363
1364 In some cases, @value{GDBN} can tell that completing a name requires using
1365 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1366 completing as much as it can) if you do not type the quote in the first
1367 place:
1368
1369 @smallexample
1370 (@value{GDBP}) b bub @key{TAB}
1371 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1372 (@value{GDBP}) b 'bubble(
1373 @end smallexample
1374
1375 @noindent
1376 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1377 you have not yet started typing the argument list when you ask for
1378 completion on an overloaded symbol.
1379
1380 For more information about overloaded functions, see @ref{C plus plus
1381 expressions, ,C@t{++} expressions}. You can use the command @code{set
1382 overload-resolution off} to disable overload resolution;
1383 see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
1384
1385
1386 @node Help
1387 @section Getting help
1388 @cindex online documentation
1389 @kindex help
1390
1391 You can always ask @value{GDBN} itself for information on its commands,
1392 using the command @code{help}.
1393
1394 @table @code
1395 @kindex h @r{(@code{help})}
1396 @item help
1397 @itemx h
1398 You can use @code{help} (abbreviated @code{h}) with no arguments to
1399 display a short list of named classes of commands:
1400
1401 @smallexample
1402 (@value{GDBP}) help
1403 List of classes of commands:
1404
1405 aliases -- Aliases of other commands
1406 breakpoints -- Making program stop at certain points
1407 data -- Examining data
1408 files -- Specifying and examining files
1409 internals -- Maintenance commands
1410 obscure -- Obscure features
1411 running -- Running the program
1412 stack -- Examining the stack
1413 status -- Status inquiries
1414 support -- Support facilities
1415 tracepoints -- Tracing of program execution without@*
1416 stopping the program
1417 user-defined -- User-defined commands
1418
1419 Type "help" followed by a class name for a list of
1420 commands in that class.
1421 Type "help" followed by command name for full
1422 documentation.
1423 Command name abbreviations are allowed if unambiguous.
1424 (@value{GDBP})
1425 @end smallexample
1426 @c the above line break eliminates huge line overfull...
1427
1428 @item help @var{class}
1429 Using one of the general help classes as an argument, you can get a
1430 list of the individual commands in that class. For example, here is the
1431 help display for the class @code{status}:
1432
1433 @smallexample
1434 (@value{GDBP}) help status
1435 Status inquiries.
1436
1437 List of commands:
1438
1439 @c Line break in "show" line falsifies real output, but needed
1440 @c to fit in smallbook page size.
1441 info -- Generic command for showing things
1442 about the program being debugged
1443 show -- Generic command for showing things
1444 about the debugger
1445
1446 Type "help" followed by command name for full
1447 documentation.
1448 Command name abbreviations are allowed if unambiguous.
1449 (@value{GDBP})
1450 @end smallexample
1451
1452 @item help @var{command}
1453 With a command name as @code{help} argument, @value{GDBN} displays a
1454 short paragraph on how to use that command.
1455
1456 @kindex apropos
1457 @item apropos @var{args}
1458 The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1459 commands, and their documentation, for the regular expression specified in
1460 @var{args}. It prints out all matches found. For example:
1461
1462 @smallexample
1463 apropos reload
1464 @end smallexample
1465
1466 @noindent
1467 results in:
1468
1469 @smallexample
1470 @c @group
1471 set symbol-reloading -- Set dynamic symbol table reloading
1472 multiple times in one run
1473 show symbol-reloading -- Show dynamic symbol table reloading
1474 multiple times in one run
1475 @c @end group
1476 @end smallexample
1477
1478 @kindex complete
1479 @item complete @var{args}
1480 The @code{complete @var{args}} command lists all the possible completions
1481 for the beginning of a command. Use @var{args} to specify the beginning of the
1482 command you want completed. For example:
1483
1484 @smallexample
1485 complete i
1486 @end smallexample
1487
1488 @noindent results in:
1489
1490 @smallexample
1491 @group
1492 if
1493 ignore
1494 info
1495 inspect
1496 @end group
1497 @end smallexample
1498
1499 @noindent This is intended for use by @sc{gnu} Emacs.
1500 @end table
1501
1502 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1503 and @code{show} to inquire about the state of your program, or the state
1504 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1505 manual introduces each of them in the appropriate context. The listings
1506 under @code{info} and under @code{show} in the Index point to
1507 all the sub-commands. @xref{Index}.
1508
1509 @c @group
1510 @table @code
1511 @kindex info
1512 @kindex i @r{(@code{info})}
1513 @item info
1514 This command (abbreviated @code{i}) is for describing the state of your
1515 program. For example, you can list the arguments given to your program
1516 with @code{info args}, list the registers currently in use with @code{info
1517 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1518 You can get a complete list of the @code{info} sub-commands with
1519 @w{@code{help info}}.
1520
1521 @kindex set
1522 @item set
1523 You can assign the result of an expression to an environment variable with
1524 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1525 @code{set prompt $}.
1526
1527 @kindex show
1528 @item show
1529 In contrast to @code{info}, @code{show} is for describing the state of
1530 @value{GDBN} itself.
1531 You can change most of the things you can @code{show}, by using the
1532 related command @code{set}; for example, you can control what number
1533 system is used for displays with @code{set radix}, or simply inquire
1534 which is currently in use with @code{show radix}.
1535
1536 @kindex info set
1537 To display all the settable parameters and their current
1538 values, you can use @code{show} with no arguments; you may also use
1539 @code{info set}. Both commands produce the same display.
1540 @c FIXME: "info set" violates the rule that "info" is for state of
1541 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1542 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1543 @end table
1544 @c @end group
1545
1546 Here are three miscellaneous @code{show} subcommands, all of which are
1547 exceptional in lacking corresponding @code{set} commands:
1548
1549 @table @code
1550 @kindex show version
1551 @cindex version number
1552 @item show version
1553 Show what version of @value{GDBN} is running. You should include this
1554 information in @value{GDBN} bug-reports. If multiple versions of
1555 @value{GDBN} are in use at your site, you may need to determine which
1556 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1557 commands are introduced, and old ones may wither away. Also, many
1558 system vendors ship variant versions of @value{GDBN}, and there are
1559 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1560 The version number is the same as the one announced when you start
1561 @value{GDBN}.
1562
1563 @kindex show copying
1564 @item show copying
1565 Display information about permission for copying @value{GDBN}.
1566
1567 @kindex show warranty
1568 @item show warranty
1569 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1570 if your version of @value{GDBN} comes with one.
1571
1572 @end table
1573
1574 @node Running
1575 @chapter Running Programs Under @value{GDBN}
1576
1577 When you run a program under @value{GDBN}, you must first generate
1578 debugging information when you compile it.
1579
1580 You may start @value{GDBN} with its arguments, if any, in an environment
1581 of your choice. If you are doing native debugging, you may redirect
1582 your program's input and output, debug an already running process, or
1583 kill a child process.
1584
1585 @menu
1586 * Compilation:: Compiling for debugging
1587 * Starting:: Starting your program
1588 * Arguments:: Your program's arguments
1589 * Environment:: Your program's environment
1590
1591 * Working Directory:: Your program's working directory
1592 * Input/Output:: Your program's input and output
1593 * Attach:: Debugging an already-running process
1594 * Kill Process:: Killing the child process
1595
1596 * Threads:: Debugging programs with multiple threads
1597 * Processes:: Debugging programs with multiple processes
1598 @end menu
1599
1600 @node Compilation
1601 @section Compiling for debugging
1602
1603 In order to debug a program effectively, you need to generate
1604 debugging information when you compile it. This debugging information
1605 is stored in the object file; it describes the data type of each
1606 variable or function and the correspondence between source line numbers
1607 and addresses in the executable code.
1608
1609 To request debugging information, specify the @samp{-g} option when you run
1610 the compiler.
1611
1612 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1613 options together. Using those compilers, you cannot generate optimized
1614 executables containing debugging information.
1615
1616 @value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1617 without @samp{-O}, making it possible to debug optimized code. We
1618 recommend that you @emph{always} use @samp{-g} whenever you compile a
1619 program. You may think your program is correct, but there is no sense
1620 in pushing your luck.
1621
1622 @cindex optimized code, debugging
1623 @cindex debugging optimized code
1624 When you debug a program compiled with @samp{-g -O}, remember that the
1625 optimizer is rearranging your code; the debugger shows you what is
1626 really there. Do not be too surprised when the execution path does not
1627 exactly match your source file! An extreme example: if you define a
1628 variable, but never use it, @value{GDBN} never sees that
1629 variable---because the compiler optimizes it out of existence.
1630
1631 Some things do not work as well with @samp{-g -O} as with just
1632 @samp{-g}, particularly on machines with instruction scheduling. If in
1633 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1634 please report it to us as a bug (including a test case!).
1635
1636 Older versions of the @sc{gnu} C compiler permitted a variant option
1637 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1638 format; if your @sc{gnu} C compiler has this option, do not use it.
1639
1640 @need 2000
1641 @node Starting
1642 @section Starting your program
1643 @cindex starting
1644 @cindex running
1645
1646 @table @code
1647 @kindex run
1648 @kindex r @r{(@code{run})}
1649 @item run
1650 @itemx r
1651 Use the @code{run} command to start your program under @value{GDBN}.
1652 You must first specify the program name (except on VxWorks) with an
1653 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1654 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1655 (@pxref{Files, ,Commands to specify files}).
1656
1657 @end table
1658
1659 If you are running your program in an execution environment that
1660 supports processes, @code{run} creates an inferior process and makes
1661 that process run your program. (In environments without processes,
1662 @code{run} jumps to the start of your program.)
1663
1664 The execution of a program is affected by certain information it
1665 receives from its superior. @value{GDBN} provides ways to specify this
1666 information, which you must do @emph{before} starting your program. (You
1667 can change it after starting your program, but such changes only affect
1668 your program the next time you start it.) This information may be
1669 divided into four categories:
1670
1671 @table @asis
1672 @item The @emph{arguments.}
1673 Specify the arguments to give your program as the arguments of the
1674 @code{run} command. If a shell is available on your target, the shell
1675 is used to pass the arguments, so that you may use normal conventions
1676 (such as wildcard expansion or variable substitution) in describing
1677 the arguments.
1678 In Unix systems, you can control which shell is used with the
1679 @code{SHELL} environment variable.
1680 @xref{Arguments, ,Your program's arguments}.
1681
1682 @item The @emph{environment.}
1683 Your program normally inherits its environment from @value{GDBN}, but you can
1684 use the @value{GDBN} commands @code{set environment} and @code{unset
1685 environment} to change parts of the environment that affect
1686 your program. @xref{Environment, ,Your program's environment}.
1687
1688 @item The @emph{working directory.}
1689 Your program inherits its working directory from @value{GDBN}. You can set
1690 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1691 @xref{Working Directory, ,Your program's working directory}.
1692
1693 @item The @emph{standard input and output.}
1694 Your program normally uses the same device for standard input and
1695 standard output as @value{GDBN} is using. You can redirect input and output
1696 in the @code{run} command line, or you can use the @code{tty} command to
1697 set a different device for your program.
1698 @xref{Input/Output, ,Your program's input and output}.
1699
1700 @cindex pipes
1701 @emph{Warning:} While input and output redirection work, you cannot use
1702 pipes to pass the output of the program you are debugging to another
1703 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1704 wrong program.
1705 @end table
1706
1707 When you issue the @code{run} command, your program begins to execute
1708 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1709 of how to arrange for your program to stop. Once your program has
1710 stopped, you may call functions in your program, using the @code{print}
1711 or @code{call} commands. @xref{Data, ,Examining Data}.
1712
1713 If the modification time of your symbol file has changed since the last
1714 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1715 table, and reads it again. When it does this, @value{GDBN} tries to retain
1716 your current breakpoints.
1717
1718 @node Arguments
1719 @section Your program's arguments
1720
1721 @cindex arguments (to your program)
1722 The arguments to your program can be specified by the arguments of the
1723 @code{run} command.
1724 They are passed to a shell, which expands wildcard characters and
1725 performs redirection of I/O, and thence to your program. Your
1726 @code{SHELL} environment variable (if it exists) specifies what shell
1727 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1728 the default shell (@file{/bin/sh} on Unix).
1729
1730 On non-Unix systems, the program is usually invoked directly by
1731 @value{GDBN}, which emulates I/O redirection via the appropriate system
1732 calls, and the wildcard characters are expanded by the startup code of
1733 the program, not by the shell.
1734
1735 @code{run} with no arguments uses the same arguments used by the previous
1736 @code{run}, or those set by the @code{set args} command.
1737
1738 @table @code
1739 @kindex set args
1740 @item set args
1741 Specify the arguments to be used the next time your program is run. If
1742 @code{set args} has no arguments, @code{run} executes your program
1743 with no arguments. Once you have run your program with arguments,
1744 using @code{set args} before the next @code{run} is the only way to run
1745 it again without arguments.
1746
1747 @kindex show args
1748 @item show args
1749 Show the arguments to give your program when it is started.
1750 @end table
1751
1752 @node Environment
1753 @section Your program's environment
1754
1755 @cindex environment (of your program)
1756 The @dfn{environment} consists of a set of environment variables and
1757 their values. Environment variables conventionally record such things as
1758 your user name, your home directory, your terminal type, and your search
1759 path for programs to run. Usually you set up environment variables with
1760 the shell and they are inherited by all the other programs you run. When
1761 debugging, it can be useful to try running your program with a modified
1762 environment without having to start @value{GDBN} over again.
1763
1764 @table @code
1765 @kindex path
1766 @item path @var{directory}
1767 Add @var{directory} to the front of the @code{PATH} environment variable
1768 (the search path for executables) that will be passed to your program.
1769 The value of @code{PATH} used by @value{GDBN} does not change.
1770 You may specify several directory names, separated by whitespace or by a
1771 system-dependent separator character (@samp{:} on Unix, @samp{;} on
1772 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1773 is moved to the front, so it is searched sooner.
1774
1775 You can use the string @samp{$cwd} to refer to whatever is the current
1776 working directory at the time @value{GDBN} searches the path. If you
1777 use @samp{.} instead, it refers to the directory where you executed the
1778 @code{path} command. @value{GDBN} replaces @samp{.} in the
1779 @var{directory} argument (with the current path) before adding
1780 @var{directory} to the search path.
1781 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1782 @c document that, since repeating it would be a no-op.
1783
1784 @kindex show paths
1785 @item show paths
1786 Display the list of search paths for executables (the @code{PATH}
1787 environment variable).
1788
1789 @kindex show environment
1790 @item show environment @r{[}@var{varname}@r{]}
1791 Print the value of environment variable @var{varname} to be given to
1792 your program when it starts. If you do not supply @var{varname},
1793 print the names and values of all environment variables to be given to
1794 your program. You can abbreviate @code{environment} as @code{env}.
1795
1796 @kindex set environment
1797 @item set environment @var{varname} @r{[}=@var{value}@r{]}
1798 Set environment variable @var{varname} to @var{value}. The value
1799 changes for your program only, not for @value{GDBN} itself. @var{value} may
1800 be any string; the values of environment variables are just strings, and
1801 any interpretation is supplied by your program itself. The @var{value}
1802 parameter is optional; if it is eliminated, the variable is set to a
1803 null value.
1804 @c "any string" here does not include leading, trailing
1805 @c blanks. Gnu asks: does anyone care?
1806
1807 For example, this command:
1808
1809 @smallexample
1810 set env USER = foo
1811 @end smallexample
1812
1813 @noindent
1814 tells the debugged program, when subsequently run, that its user is named
1815 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1816 are not actually required.)
1817
1818 @kindex unset environment
1819 @item unset environment @var{varname}
1820 Remove variable @var{varname} from the environment to be passed to your
1821 program. This is different from @samp{set env @var{varname} =};
1822 @code{unset environment} removes the variable from the environment,
1823 rather than assigning it an empty value.
1824 @end table
1825
1826 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1827 the shell indicated
1828 by your @code{SHELL} environment variable if it exists (or
1829 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1830 that runs an initialization file---such as @file{.cshrc} for C-shell, or
1831 @file{.bashrc} for BASH---any variables you set in that file affect
1832 your program. You may wish to move setting of environment variables to
1833 files that are only run when you sign on, such as @file{.login} or
1834 @file{.profile}.
1835
1836 @node Working Directory
1837 @section Your program's working directory
1838
1839 @cindex working directory (of your program)
1840 Each time you start your program with @code{run}, it inherits its
1841 working directory from the current working directory of @value{GDBN}.
1842 The @value{GDBN} working directory is initially whatever it inherited
1843 from its parent process (typically the shell), but you can specify a new
1844 working directory in @value{GDBN} with the @code{cd} command.
1845
1846 The @value{GDBN} working directory also serves as a default for the commands
1847 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1848 specify files}.
1849
1850 @table @code
1851 @kindex cd
1852 @item cd @var{directory}
1853 Set the @value{GDBN} working directory to @var{directory}.
1854
1855 @kindex pwd
1856 @item pwd
1857 Print the @value{GDBN} working directory.
1858 @end table
1859
1860 @node Input/Output
1861 @section Your program's input and output
1862
1863 @cindex redirection
1864 @cindex i/o
1865 @cindex terminal
1866 By default, the program you run under @value{GDBN} does input and output to
1867 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
1868 to its own terminal modes to interact with you, but it records the terminal
1869 modes your program was using and switches back to them when you continue
1870 running your program.
1871
1872 @table @code
1873 @kindex info terminal
1874 @item info terminal
1875 Displays information recorded by @value{GDBN} about the terminal modes your
1876 program is using.
1877 @end table
1878
1879 You can redirect your program's input and/or output using shell
1880 redirection with the @code{run} command. For example,
1881
1882 @smallexample
1883 run > outfile
1884 @end smallexample
1885
1886 @noindent
1887 starts your program, diverting its output to the file @file{outfile}.
1888
1889 @kindex tty
1890 @cindex controlling terminal
1891 Another way to specify where your program should do input and output is
1892 with the @code{tty} command. This command accepts a file name as
1893 argument, and causes this file to be the default for future @code{run}
1894 commands. It also resets the controlling terminal for the child
1895 process, for future @code{run} commands. For example,
1896
1897 @smallexample
1898 tty /dev/ttyb
1899 @end smallexample
1900
1901 @noindent
1902 directs that processes started with subsequent @code{run} commands
1903 default to do input and output on the terminal @file{/dev/ttyb} and have
1904 that as their controlling terminal.
1905
1906 An explicit redirection in @code{run} overrides the @code{tty} command's
1907 effect on the input/output device, but not its effect on the controlling
1908 terminal.
1909
1910 When you use the @code{tty} command or redirect input in the @code{run}
1911 command, only the input @emph{for your program} is affected. The input
1912 for @value{GDBN} still comes from your terminal.
1913
1914 @node Attach
1915 @section Debugging an already-running process
1916 @kindex attach
1917 @cindex attach
1918
1919 @table @code
1920 @item attach @var{process-id}
1921 This command attaches to a running process---one that was started
1922 outside @value{GDBN}. (@code{info files} shows your active
1923 targets.) The command takes as argument a process ID. The usual way to
1924 find out the process-id of a Unix process is with the @code{ps} utility,
1925 or with the @samp{jobs -l} shell command.
1926
1927 @code{attach} does not repeat if you press @key{RET} a second time after
1928 executing the command.
1929 @end table
1930
1931 To use @code{attach}, your program must be running in an environment
1932 which supports processes; for example, @code{attach} does not work for
1933 programs on bare-board targets that lack an operating system. You must
1934 also have permission to send the process a signal.
1935
1936 When you use @code{attach}, the debugger finds the program running in
1937 the process first by looking in the current working directory, then (if
1938 the program is not found) by using the source file search path
1939 (@pxref{Source Path, ,Specifying source directories}). You can also use
1940 the @code{file} command to load the program. @xref{Files, ,Commands to
1941 Specify Files}.
1942
1943 The first thing @value{GDBN} does after arranging to debug the specified
1944 process is to stop it. You can examine and modify an attached process
1945 with all the @value{GDBN} commands that are ordinarily available when
1946 you start processes with @code{run}. You can insert breakpoints; you
1947 can step and continue; you can modify storage. If you would rather the
1948 process continue running, you may use the @code{continue} command after
1949 attaching @value{GDBN} to the process.
1950
1951 @table @code
1952 @kindex detach
1953 @item detach
1954 When you have finished debugging the attached process, you can use the
1955 @code{detach} command to release it from @value{GDBN} control. Detaching
1956 the process continues its execution. After the @code{detach} command,
1957 that process and @value{GDBN} become completely independent once more, and you
1958 are ready to @code{attach} another process or start one with @code{run}.
1959 @code{detach} does not repeat if you press @key{RET} again after
1960 executing the command.
1961 @end table
1962
1963 If you exit @value{GDBN} or use the @code{run} command while you have an
1964 attached process, you kill that process. By default, @value{GDBN} asks
1965 for confirmation if you try to do either of these things; you can
1966 control whether or not you need to confirm by using the @code{set
1967 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1968 messages}).
1969
1970 @node Kill Process
1971 @section Killing the child process
1972
1973 @table @code
1974 @kindex kill
1975 @item kill
1976 Kill the child process in which your program is running under @value{GDBN}.
1977 @end table
1978
1979 This command is useful if you wish to debug a core dump instead of a
1980 running process. @value{GDBN} ignores any core dump file while your program
1981 is running.
1982
1983 On some operating systems, a program cannot be executed outside @value{GDBN}
1984 while you have breakpoints set on it inside @value{GDBN}. You can use the
1985 @code{kill} command in this situation to permit running your program
1986 outside the debugger.
1987
1988 The @code{kill} command is also useful if you wish to recompile and
1989 relink your program, since on many systems it is impossible to modify an
1990 executable file while it is running in a process. In this case, when you
1991 next type @code{run}, @value{GDBN} notices that the file has changed, and
1992 reads the symbol table again (while trying to preserve your current
1993 breakpoint settings).
1994
1995 @node Threads
1996 @section Debugging programs with multiple threads
1997
1998 @cindex threads of execution
1999 @cindex multiple threads
2000 @cindex switching threads
2001 In some operating systems, such as HP-UX and Solaris, a single program
2002 may have more than one @dfn{thread} of execution. The precise semantics
2003 of threads differ from one operating system to another, but in general
2004 the threads of a single program are akin to multiple processes---except
2005 that they share one address space (that is, they can all examine and
2006 modify the same variables). On the other hand, each thread has its own
2007 registers and execution stack, and perhaps private memory.
2008
2009 @value{GDBN} provides these facilities for debugging multi-thread
2010 programs:
2011
2012 @itemize @bullet
2013 @item automatic notification of new threads
2014 @item @samp{thread @var{threadno}}, a command to switch among threads
2015 @item @samp{info threads}, a command to inquire about existing threads
2016 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2017 a command to apply a command to a list of threads
2018 @item thread-specific breakpoints
2019 @end itemize
2020
2021 @quotation
2022 @emph{Warning:} These facilities are not yet available on every
2023 @value{GDBN} configuration where the operating system supports threads.
2024 If your @value{GDBN} does not support threads, these commands have no
2025 effect. For example, a system without thread support shows no output
2026 from @samp{info threads}, and always rejects the @code{thread} command,
2027 like this:
2028
2029 @smallexample
2030 (@value{GDBP}) info threads
2031 (@value{GDBP}) thread 1
2032 Thread ID 1 not known. Use the "info threads" command to
2033 see the IDs of currently known threads.
2034 @end smallexample
2035 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2036 @c doesn't support threads"?
2037 @end quotation
2038
2039 @cindex focus of debugging
2040 @cindex current thread
2041 The @value{GDBN} thread debugging facility allows you to observe all
2042 threads while your program runs---but whenever @value{GDBN} takes
2043 control, one thread in particular is always the focus of debugging.
2044 This thread is called the @dfn{current thread}. Debugging commands show
2045 program information from the perspective of the current thread.
2046
2047 @cindex @code{New} @var{systag} message
2048 @cindex thread identifier (system)
2049 @c FIXME-implementors!! It would be more helpful if the [New...] message
2050 @c included GDB's numeric thread handle, so you could just go to that
2051 @c thread without first checking `info threads'.
2052 Whenever @value{GDBN} detects a new thread in your program, it displays
2053 the target system's identification for the thread with a message in the
2054 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2055 whose form varies depending on the particular system. For example, on
2056 LynxOS, you might see
2057
2058 @smallexample
2059 [New process 35 thread 27]
2060 @end smallexample
2061
2062 @noindent
2063 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2064 the @var{systag} is simply something like @samp{process 368}, with no
2065 further qualifier.
2066
2067 @c FIXME!! (1) Does the [New...] message appear even for the very first
2068 @c thread of a program, or does it only appear for the
2069 @c second---i.e.@: when it becomes obvious we have a multithread
2070 @c program?
2071 @c (2) *Is* there necessarily a first thread always? Or do some
2072 @c multithread systems permit starting a program with multiple
2073 @c threads ab initio?
2074
2075 @cindex thread number
2076 @cindex thread identifier (GDB)
2077 For debugging purposes, @value{GDBN} associates its own thread
2078 number---always a single integer---with each thread in your program.
2079
2080 @table @code
2081 @kindex info threads
2082 @item info threads
2083 Display a summary of all threads currently in your
2084 program. @value{GDBN} displays for each thread (in this order):
2085
2086 @enumerate
2087 @item the thread number assigned by @value{GDBN}
2088
2089 @item the target system's thread identifier (@var{systag})
2090
2091 @item the current stack frame summary for that thread
2092 @end enumerate
2093
2094 @noindent
2095 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2096 indicates the current thread.
2097
2098 For example,
2099 @end table
2100 @c end table here to get a little more width for example
2101
2102 @smallexample
2103 (@value{GDBP}) info threads
2104 3 process 35 thread 27 0x34e5 in sigpause ()
2105 2 process 35 thread 23 0x34e5 in sigpause ()
2106 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2107 at threadtest.c:68
2108 @end smallexample
2109
2110 On HP-UX systems:
2111
2112 @cindex thread number
2113 @cindex thread identifier (GDB)
2114 For debugging purposes, @value{GDBN} associates its own thread
2115 number---a small integer assigned in thread-creation order---with each
2116 thread in your program.
2117
2118 @cindex @code{New} @var{systag} message, on HP-UX
2119 @cindex thread identifier (system), on HP-UX
2120 @c FIXME-implementors!! It would be more helpful if the [New...] message
2121 @c included GDB's numeric thread handle, so you could just go to that
2122 @c thread without first checking `info threads'.
2123 Whenever @value{GDBN} detects a new thread in your program, it displays
2124 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2125 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2126 whose form varies depending on the particular system. For example, on
2127 HP-UX, you see
2128
2129 @smallexample
2130 [New thread 2 (system thread 26594)]
2131 @end smallexample
2132
2133 @noindent
2134 when @value{GDBN} notices a new thread.
2135
2136 @table @code
2137 @kindex info threads
2138 @item info threads
2139 Display a summary of all threads currently in your
2140 program. @value{GDBN} displays for each thread (in this order):
2141
2142 @enumerate
2143 @item the thread number assigned by @value{GDBN}
2144
2145 @item the target system's thread identifier (@var{systag})
2146
2147 @item the current stack frame summary for that thread
2148 @end enumerate
2149
2150 @noindent
2151 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2152 indicates the current thread.
2153
2154 For example,
2155 @end table
2156 @c end table here to get a little more width for example
2157
2158 @smallexample
2159 (@value{GDBP}) info threads
2160 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2161 at quicksort.c:137
2162 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2163 from /usr/lib/libc.2
2164 1 system thread 27905 0x7b003498 in _brk () \@*
2165 from /usr/lib/libc.2
2166 @end smallexample
2167
2168 @table @code
2169 @kindex thread @var{threadno}
2170 @item thread @var{threadno}
2171 Make thread number @var{threadno} the current thread. The command
2172 argument @var{threadno} is the internal @value{GDBN} thread number, as
2173 shown in the first field of the @samp{info threads} display.
2174 @value{GDBN} responds by displaying the system identifier of the thread
2175 you selected, and its current stack frame summary:
2176
2177 @smallexample
2178 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2179 (@value{GDBP}) thread 2
2180 [Switching to process 35 thread 23]
2181 0x34e5 in sigpause ()
2182 @end smallexample
2183
2184 @noindent
2185 As with the @samp{[New @dots{}]} message, the form of the text after
2186 @samp{Switching to} depends on your system's conventions for identifying
2187 threads.
2188
2189 @kindex thread apply
2190 @item thread apply [@var{threadno}] [@var{all}] @var{args}
2191 The @code{thread apply} command allows you to apply a command to one or
2192 more threads. Specify the numbers of the threads that you want affected
2193 with the command argument @var{threadno}. @var{threadno} is the internal
2194 @value{GDBN} thread number, as shown in the first field of the @samp{info
2195 threads} display. To apply a command to all threads, use
2196 @code{thread apply all} @var{args}.
2197 @end table
2198
2199 @cindex automatic thread selection
2200 @cindex switching threads automatically
2201 @cindex threads, automatic switching
2202 Whenever @value{GDBN} stops your program, due to a breakpoint or a
2203 signal, it automatically selects the thread where that breakpoint or
2204 signal happened. @value{GDBN} alerts you to the context switch with a
2205 message of the form @samp{[Switching to @var{systag}]} to identify the
2206 thread.
2207
2208 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2209 more information about how @value{GDBN} behaves when you stop and start
2210 programs with multiple threads.
2211
2212 @xref{Set Watchpoints,,Setting watchpoints}, for information about
2213 watchpoints in programs with multiple threads.
2214
2215 @node Processes
2216 @section Debugging programs with multiple processes
2217
2218 @cindex fork, debugging programs which call
2219 @cindex multiple processes
2220 @cindex processes, multiple
2221 On most systems, @value{GDBN} has no special support for debugging
2222 programs which create additional processes using the @code{fork}
2223 function. When a program forks, @value{GDBN} will continue to debug the
2224 parent process and the child process will run unimpeded. If you have
2225 set a breakpoint in any code which the child then executes, the child
2226 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2227 will cause it to terminate.
2228
2229 However, if you want to debug the child process there is a workaround
2230 which isn't too painful. Put a call to @code{sleep} in the code which
2231 the child process executes after the fork. It may be useful to sleep
2232 only if a certain environment variable is set, or a certain file exists,
2233 so that the delay need not occur when you don't want to run @value{GDBN}
2234 on the child. While the child is sleeping, use the @code{ps} program to
2235 get its process ID. Then tell @value{GDBN} (a new invocation of
2236 @value{GDBN} if you are also debugging the parent process) to attach to
2237 the child process (@pxref{Attach}). From that point on you can debug
2238 the child process just like any other process which you attached to.
2239
2240 On HP-UX (11.x and later only?), @value{GDBN} provides support for
2241 debugging programs that create additional processes using the
2242 @code{fork} or @code{vfork} function.
2243
2244 By default, when a program forks, @value{GDBN} will continue to debug
2245 the parent process and the child process will run unimpeded.
2246
2247 If you want to follow the child process instead of the parent process,
2248 use the command @w{@code{set follow-fork-mode}}.
2249
2250 @table @code
2251 @kindex set follow-fork-mode
2252 @item set follow-fork-mode @var{mode}
2253 Set the debugger response to a program call of @code{fork} or
2254 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2255 process. The @var{mode} can be:
2256
2257 @table @code
2258 @item parent
2259 The original process is debugged after a fork. The child process runs
2260 unimpeded. This is the default.
2261
2262 @item child
2263 The new process is debugged after a fork. The parent process runs
2264 unimpeded.
2265
2266 @item ask
2267 The debugger will ask for one of the above choices.
2268 @end table
2269
2270 @item show follow-fork-mode
2271 Display the current debugger response to a @code{fork} or @code{vfork} call.
2272 @end table
2273
2274 If you ask to debug a child process and a @code{vfork} is followed by an
2275 @code{exec}, @value{GDBN} executes the new target up to the first
2276 breakpoint in the new target. If you have a breakpoint set on
2277 @code{main} in your original program, the breakpoint will also be set on
2278 the child process's @code{main}.
2279
2280 When a child process is spawned by @code{vfork}, you cannot debug the
2281 child or parent until an @code{exec} call completes.
2282
2283 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2284 call executes, the new target restarts. To restart the parent process,
2285 use the @code{file} command with the parent executable name as its
2286 argument.
2287
2288 You can use the @code{catch} command to make @value{GDBN} stop whenever
2289 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2290 Catchpoints, ,Setting catchpoints}.
2291
2292 @node Stopping
2293 @chapter Stopping and Continuing
2294
2295 The principal purposes of using a debugger are so that you can stop your
2296 program before it terminates; or so that, if your program runs into
2297 trouble, you can investigate and find out why.
2298
2299 Inside @value{GDBN}, your program may stop for any of several reasons,
2300 such as a signal, a breakpoint, or reaching a new line after a
2301 @value{GDBN} command such as @code{step}. You may then examine and
2302 change variables, set new breakpoints or remove old ones, and then
2303 continue execution. Usually, the messages shown by @value{GDBN} provide
2304 ample explanation of the status of your program---but you can also
2305 explicitly request this information at any time.
2306
2307 @table @code
2308 @kindex info program
2309 @item info program
2310 Display information about the status of your program: whether it is
2311 running or not, what process it is, and why it stopped.
2312 @end table
2313
2314 @menu
2315 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2316 * Continuing and Stepping:: Resuming execution
2317 * Signals:: Signals
2318 * Thread Stops:: Stopping and starting multi-thread programs
2319 @end menu
2320
2321 @node Breakpoints
2322 @section Breakpoints, watchpoints, and catchpoints
2323
2324 @cindex breakpoints
2325 A @dfn{breakpoint} makes your program stop whenever a certain point in
2326 the program is reached. For each breakpoint, you can add conditions to
2327 control in finer detail whether your program stops. You can set
2328 breakpoints with the @code{break} command and its variants (@pxref{Set
2329 Breaks, ,Setting breakpoints}), to specify the place where your program
2330 should stop by line number, function name or exact address in the
2331 program.
2332
2333 In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2334 breakpoints in shared libraries before the executable is run. There is
2335 a minor limitation on HP-UX systems: you must wait until the executable
2336 is run in order to set breakpoints in shared library routines that are
2337 not called directly by the program (for example, routines that are
2338 arguments in a @code{pthread_create} call).
2339
2340 @cindex watchpoints
2341 @cindex memory tracing
2342 @cindex breakpoint on memory address
2343 @cindex breakpoint on variable modification
2344 A @dfn{watchpoint} is a special breakpoint that stops your program
2345 when the value of an expression changes. You must use a different
2346 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2347 watchpoints}), but aside from that, you can manage a watchpoint like
2348 any other breakpoint: you enable, disable, and delete both breakpoints
2349 and watchpoints using the same commands.
2350
2351 You can arrange to have values from your program displayed automatically
2352 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2353 Automatic display}.
2354
2355 @cindex catchpoints
2356 @cindex breakpoint on events
2357 A @dfn{catchpoint} is another special breakpoint that stops your program
2358 when a certain kind of event occurs, such as the throwing of a C@t{++}
2359 exception or the loading of a library. As with watchpoints, you use a
2360 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2361 catchpoints}), but aside from that, you can manage a catchpoint like any
2362 other breakpoint. (To stop when your program receives a signal, use the
2363 @code{handle} command; see @ref{Signals, ,Signals}.)
2364
2365 @cindex breakpoint numbers
2366 @cindex numbers for breakpoints
2367 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2368 catchpoint when you create it; these numbers are successive integers
2369 starting with one. In many of the commands for controlling various
2370 features of breakpoints you use the breakpoint number to say which
2371 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2372 @dfn{disabled}; if disabled, it has no effect on your program until you
2373 enable it again.
2374
2375 @cindex breakpoint ranges
2376 @cindex ranges of breakpoints
2377 Some @value{GDBN} commands accept a range of breakpoints on which to
2378 operate. A breakpoint range is either a single breakpoint number, like
2379 @samp{5}, or two such numbers, in increasing order, separated by a
2380 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2381 all breakpoint in that range are operated on.
2382
2383 @menu
2384 * Set Breaks:: Setting breakpoints
2385 * Set Watchpoints:: Setting watchpoints
2386 * Set Catchpoints:: Setting catchpoints
2387 * Delete Breaks:: Deleting breakpoints
2388 * Disabling:: Disabling breakpoints
2389 * Conditions:: Break conditions
2390 * Break Commands:: Breakpoint command lists
2391 * Breakpoint Menus:: Breakpoint menus
2392 * Error in Breakpoints:: ``Cannot insert breakpoints''
2393 @end menu
2394
2395 @node Set Breaks
2396 @subsection Setting breakpoints
2397
2398 @c FIXME LMB what does GDB do if no code on line of breakpt?
2399 @c consider in particular declaration with/without initialization.
2400 @c
2401 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2402
2403 @kindex break
2404 @kindex b @r{(@code{break})}
2405 @vindex $bpnum@r{, convenience variable}
2406 @cindex latest breakpoint
2407 Breakpoints are set with the @code{break} command (abbreviated
2408 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2409 number of the breakpoint you've set most recently; see @ref{Convenience
2410 Vars,, Convenience variables}, for a discussion of what you can do with
2411 convenience variables.
2412
2413 You have several ways to say where the breakpoint should go.
2414
2415 @table @code
2416 @item break @var{function}
2417 Set a breakpoint at entry to function @var{function}.
2418 When using source languages that permit overloading of symbols, such as
2419 C@t{++}, @var{function} may refer to more than one possible place to break.
2420 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2421
2422 @item break +@var{offset}
2423 @itemx break -@var{offset}
2424 Set a breakpoint some number of lines forward or back from the position
2425 at which execution stopped in the currently selected @dfn{stack frame}.
2426 (@xref{Frames, ,Frames}, for a description of stack frames.)
2427
2428 @item break @var{linenum}
2429 Set a breakpoint at line @var{linenum} in the current source file.
2430 The current source file is the last file whose source text was printed.
2431 The breakpoint will stop your program just before it executes any of the
2432 code on that line.
2433
2434 @item break @var{filename}:@var{linenum}
2435 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2436
2437 @item break @var{filename}:@var{function}
2438 Set a breakpoint at entry to function @var{function} found in file
2439 @var{filename}. Specifying a file name as well as a function name is
2440 superfluous except when multiple files contain similarly named
2441 functions.
2442
2443 @item break *@var{address}
2444 Set a breakpoint at address @var{address}. You can use this to set
2445 breakpoints in parts of your program which do not have debugging
2446 information or source files.
2447
2448 @item break
2449 When called without any arguments, @code{break} sets a breakpoint at
2450 the next instruction to be executed in the selected stack frame
2451 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2452 innermost, this makes your program stop as soon as control
2453 returns to that frame. This is similar to the effect of a
2454 @code{finish} command in the frame inside the selected frame---except
2455 that @code{finish} does not leave an active breakpoint. If you use
2456 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2457 the next time it reaches the current location; this may be useful
2458 inside loops.
2459
2460 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2461 least one instruction has been executed. If it did not do this, you
2462 would be unable to proceed past a breakpoint without first disabling the
2463 breakpoint. This rule applies whether or not the breakpoint already
2464 existed when your program stopped.
2465
2466 @item break @dots{} if @var{cond}
2467 Set a breakpoint with condition @var{cond}; evaluate the expression
2468 @var{cond} each time the breakpoint is reached, and stop only if the
2469 value is nonzero---that is, if @var{cond} evaluates as true.
2470 @samp{@dots{}} stands for one of the possible arguments described
2471 above (or no argument) specifying where to break. @xref{Conditions,
2472 ,Break conditions}, for more information on breakpoint conditions.
2473
2474 @kindex tbreak
2475 @item tbreak @var{args}
2476 Set a breakpoint enabled only for one stop. @var{args} are the
2477 same as for the @code{break} command, and the breakpoint is set in the same
2478 way, but the breakpoint is automatically deleted after the first time your
2479 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2480
2481 @kindex hbreak
2482 @item hbreak @var{args}
2483 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2484 @code{break} command and the breakpoint is set in the same way, but the
2485 breakpoint requires hardware support and some target hardware may not
2486 have this support. The main purpose of this is EPROM/ROM code
2487 debugging, so you can set a breakpoint at an instruction without
2488 changing the instruction. This can be used with the new trap-generation
2489 provided by SPARClite DSU and some x86-based targets. These targets
2490 will generate traps when a program accesses some data or instruction
2491 address that is assigned to the debug registers. However the hardware
2492 breakpoint registers can take a limited number of breakpoints. For
2493 example, on the DSU, only two data breakpoints can be set at a time, and
2494 @value{GDBN} will reject this command if more than two are used. Delete
2495 or disable unused hardware breakpoints before setting new ones
2496 (@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
2497
2498 @kindex thbreak
2499 @item thbreak @var{args}
2500 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2501 are the same as for the @code{hbreak} command and the breakpoint is set in
2502 the same way. However, like the @code{tbreak} command,
2503 the breakpoint is automatically deleted after the
2504 first time your program stops there. Also, like the @code{hbreak}
2505 command, the breakpoint requires hardware support and some target hardware
2506 may not have this support. @xref{Disabling, ,Disabling breakpoints}.
2507 See also @ref{Conditions, ,Break conditions}.
2508
2509 @kindex rbreak
2510 @cindex regular expression
2511 @item rbreak @var{regex}
2512 Set breakpoints on all functions matching the regular expression
2513 @var{regex}. This command sets an unconditional breakpoint on all
2514 matches, printing a list of all breakpoints it set. Once these
2515 breakpoints are set, they are treated just like the breakpoints set with
2516 the @code{break} command. You can delete them, disable them, or make
2517 them conditional the same way as any other breakpoint.
2518
2519 The syntax of the regular expression is the standard one used with tools
2520 like @file{grep}. Note that this is different from the syntax used by
2521 shells, so for instance @code{foo*} matches all functions that include
2522 an @code{fo} followed by zero or more @code{o}s. There is an implicit
2523 @code{.*} leading and trailing the regular expression you supply, so to
2524 match only functions that begin with @code{foo}, use @code{^foo}.
2525
2526 When debugging C@t{++} programs, @code{rbreak} is useful for setting
2527 breakpoints on overloaded functions that are not members of any special
2528 classes.
2529
2530 @kindex info breakpoints
2531 @cindex @code{$_} and @code{info breakpoints}
2532 @item info breakpoints @r{[}@var{n}@r{]}
2533 @itemx info break @r{[}@var{n}@r{]}
2534 @itemx info watchpoints @r{[}@var{n}@r{]}
2535 Print a table of all breakpoints, watchpoints, and catchpoints set and
2536 not deleted, with the following columns for each breakpoint:
2537
2538 @table @emph
2539 @item Breakpoint Numbers
2540 @item Type
2541 Breakpoint, watchpoint, or catchpoint.
2542 @item Disposition
2543 Whether the breakpoint is marked to be disabled or deleted when hit.
2544 @item Enabled or Disabled
2545 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2546 that are not enabled.
2547 @item Address
2548 Where the breakpoint is in your program, as a memory address.
2549 @item What
2550 Where the breakpoint is in the source for your program, as a file and
2551 line number.
2552 @end table
2553
2554 @noindent
2555 If a breakpoint is conditional, @code{info break} shows the condition on
2556 the line following the affected breakpoint; breakpoint commands, if any,
2557 are listed after that.
2558
2559 @noindent
2560 @code{info break} with a breakpoint
2561 number @var{n} as argument lists only that breakpoint. The
2562 convenience variable @code{$_} and the default examining-address for
2563 the @code{x} command are set to the address of the last breakpoint
2564 listed (@pxref{Memory, ,Examining memory}).
2565
2566 @noindent
2567 @code{info break} displays a count of the number of times the breakpoint
2568 has been hit. This is especially useful in conjunction with the
2569 @code{ignore} command. You can ignore a large number of breakpoint
2570 hits, look at the breakpoint info to see how many times the breakpoint
2571 was hit, and then run again, ignoring one less than that number. This
2572 will get you quickly to the last hit of that breakpoint.
2573 @end table
2574
2575 @value{GDBN} allows you to set any number of breakpoints at the same place in
2576 your program. There is nothing silly or meaningless about this. When
2577 the breakpoints are conditional, this is even useful
2578 (@pxref{Conditions, ,Break conditions}).
2579
2580 @cindex negative breakpoint numbers
2581 @cindex internal @value{GDBN} breakpoints
2582 @value{GDBN} itself sometimes sets breakpoints in your program for
2583 special purposes, such as proper handling of @code{longjmp} (in C
2584 programs). These internal breakpoints are assigned negative numbers,
2585 starting with @code{-1}; @samp{info breakpoints} does not display them.
2586 You can see these breakpoints with the @value{GDBN} maintenance command
2587 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
2588
2589
2590 @node Set Watchpoints
2591 @subsection Setting watchpoints
2592
2593 @cindex setting watchpoints
2594 @cindex software watchpoints
2595 @cindex hardware watchpoints
2596 You can use a watchpoint to stop execution whenever the value of an
2597 expression changes, without having to predict a particular place where
2598 this may happen.
2599
2600 Depending on your system, watchpoints may be implemented in software or
2601 hardware. @value{GDBN} does software watchpointing by single-stepping your
2602 program and testing the variable's value each time, which is hundreds of
2603 times slower than normal execution. (But this may still be worth it, to
2604 catch errors where you have no clue what part of your program is the
2605 culprit.)
2606
2607 On some systems, such as HP-UX, Linux and some other x86-based targets,
2608 @value{GDBN} includes support for
2609 hardware watchpoints, which do not slow down the running of your
2610 program.
2611
2612 @table @code
2613 @kindex watch
2614 @item watch @var{expr}
2615 Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2616 is written into by the program and its value changes.
2617
2618 @kindex rwatch
2619 @item rwatch @var{expr}
2620 Set a watchpoint that will break when watch @var{expr} is read by the program.
2621
2622 @kindex awatch
2623 @item awatch @var{expr}
2624 Set a watchpoint that will break when @var{expr} is either read or written into
2625 by the program.
2626
2627 @kindex info watchpoints
2628 @item info watchpoints
2629 This command prints a list of watchpoints, breakpoints, and catchpoints;
2630 it is the same as @code{info break}.
2631 @end table
2632
2633 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2634 watchpoints execute very quickly, and the debugger reports a change in
2635 value at the exact instruction where the change occurs. If @value{GDBN}
2636 cannot set a hardware watchpoint, it sets a software watchpoint, which
2637 executes more slowly and reports the change in value at the next
2638 statement, not the instruction, after the change occurs.
2639
2640 When you issue the @code{watch} command, @value{GDBN} reports
2641
2642 @smallexample
2643 Hardware watchpoint @var{num}: @var{expr}
2644 @end smallexample
2645
2646 @noindent
2647 if it was able to set a hardware watchpoint.
2648
2649 Currently, the @code{awatch} and @code{rwatch} commands can only set
2650 hardware watchpoints, because accesses to data that don't change the
2651 value of the watched expression cannot be detected without examining
2652 every instruction as it is being executed, and @value{GDBN} does not do
2653 that currently. If @value{GDBN} finds that it is unable to set a
2654 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2655 will print a message like this:
2656
2657 @smallexample
2658 Expression cannot be implemented with read/access watchpoint.
2659 @end smallexample
2660
2661 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2662 data type of the watched expression is wider than what a hardware
2663 watchpoint on the target machine can handle. For example, some systems
2664 can only watch regions that are up to 4 bytes wide; on such systems you
2665 cannot set hardware watchpoints for an expression that yields a
2666 double-precision floating-point number (which is typically 8 bytes
2667 wide). As a work-around, it might be possible to break the large region
2668 into a series of smaller ones and watch them with separate watchpoints.
2669
2670 If you set too many hardware watchpoints, @value{GDBN} might be unable
2671 to insert all of them when you resume the execution of your program.
2672 Since the precise number of active watchpoints is unknown until such
2673 time as the program is about to be resumed, @value{GDBN} might not be
2674 able to warn you about this when you set the watchpoints, and the
2675 warning will be printed only when the program is resumed:
2676
2677 @smallexample
2678 Hardware watchpoint @var{num}: Could not insert watchpoint
2679 @end smallexample
2680
2681 @noindent
2682 If this happens, delete or disable some of the watchpoints.
2683
2684 The SPARClite DSU will generate traps when a program accesses some data
2685 or instruction address that is assigned to the debug registers. For the
2686 data addresses, DSU facilitates the @code{watch} command. However the
2687 hardware breakpoint registers can only take two data watchpoints, and
2688 both watchpoints must be the same kind. For example, you can set two
2689 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2690 @strong{or} two with @code{awatch} commands, but you cannot set one
2691 watchpoint with one command and the other with a different command.
2692 @value{GDBN} will reject the command if you try to mix watchpoints.
2693 Delete or disable unused watchpoint commands before setting new ones.
2694
2695 If you call a function interactively using @code{print} or @code{call},
2696 any watchpoints you have set will be inactive until @value{GDBN} reaches another
2697 kind of breakpoint or the call completes.
2698
2699 @value{GDBN} automatically deletes watchpoints that watch local
2700 (automatic) variables, or expressions that involve such variables, when
2701 they go out of scope, that is, when the execution leaves the block in
2702 which these variables were defined. In particular, when the program
2703 being debugged terminates, @emph{all} local variables go out of scope,
2704 and so only watchpoints that watch global variables remain set. If you
2705 rerun the program, you will need to set all such watchpoints again. One
2706 way of doing that would be to set a code breakpoint at the entry to the
2707 @code{main} function and when it breaks, set all the watchpoints.
2708
2709 @quotation
2710 @cindex watchpoints and threads
2711 @cindex threads and watchpoints
2712 @emph{Warning:} In multi-thread programs, watchpoints have only limited
2713 usefulness. With the current watchpoint implementation, @value{GDBN}
2714 can only watch the value of an expression @emph{in a single thread}. If
2715 you are confident that the expression can only change due to the current
2716 thread's activity (and if you are also confident that no other thread
2717 can become current), then you can use watchpoints as usual. However,
2718 @value{GDBN} may not notice when a non-current thread's activity changes
2719 the expression.
2720
2721 @c FIXME: this is almost identical to the previous paragraph.
2722 @emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2723 have only limited usefulness. If @value{GDBN} creates a software
2724 watchpoint, it can only watch the value of an expression @emph{in a
2725 single thread}. If you are confident that the expression can only
2726 change due to the current thread's activity (and if you are also
2727 confident that no other thread can become current), then you can use
2728 software watchpoints as usual. However, @value{GDBN} may not notice
2729 when a non-current thread's activity changes the expression. (Hardware
2730 watchpoints, in contrast, watch an expression in all threads.)
2731 @end quotation
2732
2733 @node Set Catchpoints
2734 @subsection Setting catchpoints
2735 @cindex catchpoints, setting
2736 @cindex exception handlers
2737 @cindex event handling
2738
2739 You can use @dfn{catchpoints} to cause the debugger to stop for certain
2740 kinds of program events, such as C@t{++} exceptions or the loading of a
2741 shared library. Use the @code{catch} command to set a catchpoint.
2742
2743 @table @code
2744 @kindex catch
2745 @item catch @var{event}
2746 Stop when @var{event} occurs. @var{event} can be any of the following:
2747 @table @code
2748 @item throw
2749 @kindex catch throw
2750 The throwing of a C@t{++} exception.
2751
2752 @item catch
2753 @kindex catch catch
2754 The catching of a C@t{++} exception.
2755
2756 @item exec
2757 @kindex catch exec
2758 A call to @code{exec}. This is currently only available for HP-UX.
2759
2760 @item fork
2761 @kindex catch fork
2762 A call to @code{fork}. This is currently only available for HP-UX.
2763
2764 @item vfork
2765 @kindex catch vfork
2766 A call to @code{vfork}. This is currently only available for HP-UX.
2767
2768 @item load
2769 @itemx load @var{libname}
2770 @kindex catch load
2771 The dynamic loading of any shared library, or the loading of the library
2772 @var{libname}. This is currently only available for HP-UX.
2773
2774 @item unload
2775 @itemx unload @var{libname}
2776 @kindex catch unload
2777 The unloading of any dynamically loaded shared library, or the unloading
2778 of the library @var{libname}. This is currently only available for HP-UX.
2779 @end table
2780
2781 @item tcatch @var{event}
2782 Set a catchpoint that is enabled only for one stop. The catchpoint is
2783 automatically deleted after the first time the event is caught.
2784
2785 @end table
2786
2787 Use the @code{info break} command to list the current catchpoints.
2788
2789 There are currently some limitations to C@t{++} exception handling
2790 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2791
2792 @itemize @bullet
2793 @item
2794 If you call a function interactively, @value{GDBN} normally returns
2795 control to you when the function has finished executing. If the call
2796 raises an exception, however, the call may bypass the mechanism that
2797 returns control to you and cause your program either to abort or to
2798 simply continue running until it hits a breakpoint, catches a signal
2799 that @value{GDBN} is listening for, or exits. This is the case even if
2800 you set a catchpoint for the exception; catchpoints on exceptions are
2801 disabled within interactive calls.
2802
2803 @item
2804 You cannot raise an exception interactively.
2805
2806 @item
2807 You cannot install an exception handler interactively.
2808 @end itemize
2809
2810 @cindex raise exceptions
2811 Sometimes @code{catch} is not the best way to debug exception handling:
2812 if you need to know exactly where an exception is raised, it is better to
2813 stop @emph{before} the exception handler is called, since that way you
2814 can see the stack before any unwinding takes place. If you set a
2815 breakpoint in an exception handler instead, it may not be easy to find
2816 out where the exception was raised.
2817
2818 To stop just before an exception handler is called, you need some
2819 knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
2820 raised by calling a library function named @code{__raise_exception}
2821 which has the following ANSI C interface:
2822
2823 @smallexample
2824 /* @var{addr} is where the exception identifier is stored.
2825 @var{id} is the exception identifier. */
2826 void __raise_exception (void **addr, void *id);
2827 @end smallexample
2828
2829 @noindent
2830 To make the debugger catch all exceptions before any stack
2831 unwinding takes place, set a breakpoint on @code{__raise_exception}
2832 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2833
2834 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2835 that depends on the value of @var{id}, you can stop your program when
2836 a specific exception is raised. You can use multiple conditional
2837 breakpoints to stop your program when any of a number of exceptions are
2838 raised.
2839
2840
2841 @node Delete Breaks
2842 @subsection Deleting breakpoints
2843
2844 @cindex clearing breakpoints, watchpoints, catchpoints
2845 @cindex deleting breakpoints, watchpoints, catchpoints
2846 It is often necessary to eliminate a breakpoint, watchpoint, or
2847 catchpoint once it has done its job and you no longer want your program
2848 to stop there. This is called @dfn{deleting} the breakpoint. A
2849 breakpoint that has been deleted no longer exists; it is forgotten.
2850
2851 With the @code{clear} command you can delete breakpoints according to
2852 where they are in your program. With the @code{delete} command you can
2853 delete individual breakpoints, watchpoints, or catchpoints by specifying
2854 their breakpoint numbers.
2855
2856 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2857 automatically ignores breakpoints on the first instruction to be executed
2858 when you continue execution without changing the execution address.
2859
2860 @table @code
2861 @kindex clear
2862 @item clear
2863 Delete any breakpoints at the next instruction to be executed in the
2864 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2865 the innermost frame is selected, this is a good way to delete a
2866 breakpoint where your program just stopped.
2867
2868 @item clear @var{function}
2869 @itemx clear @var{filename}:@var{function}
2870 Delete any breakpoints set at entry to the function @var{function}.
2871
2872 @item clear @var{linenum}
2873 @itemx clear @var{filename}:@var{linenum}
2874 Delete any breakpoints set at or within the code of the specified line.
2875
2876 @cindex delete breakpoints
2877 @kindex delete
2878 @kindex d @r{(@code{delete})}
2879 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2880 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2881 ranges specified as arguments. If no argument is specified, delete all
2882 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2883 confirm off}). You can abbreviate this command as @code{d}.
2884 @end table
2885
2886 @node Disabling
2887 @subsection Disabling breakpoints
2888
2889 @kindex disable breakpoints
2890 @kindex enable breakpoints
2891 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2892 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2893 it had been deleted, but remembers the information on the breakpoint so
2894 that you can @dfn{enable} it again later.
2895
2896 You disable and enable breakpoints, watchpoints, and catchpoints with
2897 the @code{enable} and @code{disable} commands, optionally specifying one
2898 or more breakpoint numbers as arguments. Use @code{info break} or
2899 @code{info watch} to print a list of breakpoints, watchpoints, and
2900 catchpoints if you do not know which numbers to use.
2901
2902 A breakpoint, watchpoint, or catchpoint can have any of four different
2903 states of enablement:
2904
2905 @itemize @bullet
2906 @item
2907 Enabled. The breakpoint stops your program. A breakpoint set
2908 with the @code{break} command starts out in this state.
2909 @item
2910 Disabled. The breakpoint has no effect on your program.
2911 @item
2912 Enabled once. The breakpoint stops your program, but then becomes
2913 disabled.
2914 @item
2915 Enabled for deletion. The breakpoint stops your program, but
2916 immediately after it does so it is deleted permanently. A breakpoint
2917 set with the @code{tbreak} command starts out in this state.
2918 @end itemize
2919
2920 You can use the following commands to enable or disable breakpoints,
2921 watchpoints, and catchpoints:
2922
2923 @table @code
2924 @kindex disable breakpoints
2925 @kindex disable
2926 @kindex dis @r{(@code{disable})}
2927 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2928 Disable the specified breakpoints---or all breakpoints, if none are
2929 listed. A disabled breakpoint has no effect but is not forgotten. All
2930 options such as ignore-counts, conditions and commands are remembered in
2931 case the breakpoint is enabled again later. You may abbreviate
2932 @code{disable} as @code{dis}.
2933
2934 @kindex enable breakpoints
2935 @kindex enable
2936 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2937 Enable the specified breakpoints (or all defined breakpoints). They
2938 become effective once again in stopping your program.
2939
2940 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
2941 Enable the specified breakpoints temporarily. @value{GDBN} disables any
2942 of these breakpoints immediately after stopping your program.
2943
2944 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
2945 Enable the specified breakpoints to work once, then die. @value{GDBN}
2946 deletes any of these breakpoints as soon as your program stops there.
2947 @end table
2948
2949 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2950 @c confusing: tbreak is also initially enabled.
2951 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2952 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2953 subsequently, they become disabled or enabled only when you use one of
2954 the commands above. (The command @code{until} can set and delete a
2955 breakpoint of its own, but it does not change the state of your other
2956 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2957 stepping}.)
2958
2959 @node Conditions
2960 @subsection Break conditions
2961 @cindex conditional breakpoints
2962 @cindex breakpoint conditions
2963
2964 @c FIXME what is scope of break condition expr? Context where wanted?
2965 @c in particular for a watchpoint?
2966 The simplest sort of breakpoint breaks every time your program reaches a
2967 specified place. You can also specify a @dfn{condition} for a
2968 breakpoint. A condition is just a Boolean expression in your
2969 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2970 a condition evaluates the expression each time your program reaches it,
2971 and your program stops only if the condition is @emph{true}.
2972
2973 This is the converse of using assertions for program validation; in that
2974 situation, you want to stop when the assertion is violated---that is,
2975 when the condition is false. In C, if you want to test an assertion expressed
2976 by the condition @var{assert}, you should set the condition
2977 @samp{! @var{assert}} on the appropriate breakpoint.
2978
2979 Conditions are also accepted for watchpoints; you may not need them,
2980 since a watchpoint is inspecting the value of an expression anyhow---but
2981 it might be simpler, say, to just set a watchpoint on a variable name,
2982 and specify a condition that tests whether the new value is an interesting
2983 one.
2984
2985 Break conditions can have side effects, and may even call functions in
2986 your program. This can be useful, for example, to activate functions
2987 that log program progress, or to use your own print functions to
2988 format special data structures. The effects are completely predictable
2989 unless there is another enabled breakpoint at the same address. (In
2990 that case, @value{GDBN} might see the other breakpoint first and stop your
2991 program without checking the condition of this one.) Note that
2992 breakpoint commands are usually more convenient and flexible than break
2993 conditions for the
2994 purpose of performing side effects when a breakpoint is reached
2995 (@pxref{Break Commands, ,Breakpoint command lists}).
2996
2997 Break conditions can be specified when a breakpoint is set, by using
2998 @samp{if} in the arguments to the @code{break} command. @xref{Set
2999 Breaks, ,Setting breakpoints}. They can also be changed at any time
3000 with the @code{condition} command.
3001
3002 You can also use the @code{if} keyword with the @code{watch} command.
3003 The @code{catch} command does not recognize the @code{if} keyword;
3004 @code{condition} is the only way to impose a further condition on a
3005 catchpoint.
3006
3007 @table @code
3008 @kindex condition
3009 @item condition @var{bnum} @var{expression}
3010 Specify @var{expression} as the break condition for breakpoint,
3011 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3012 breakpoint @var{bnum} stops your program only if the value of
3013 @var{expression} is true (nonzero, in C). When you use
3014 @code{condition}, @value{GDBN} checks @var{expression} immediately for
3015 syntactic correctness, and to determine whether symbols in it have
3016 referents in the context of your breakpoint. If @var{expression} uses
3017 symbols not referenced in the context of the breakpoint, @value{GDBN}
3018 prints an error message:
3019
3020 @smallexample
3021 No symbol "foo" in current context.
3022 @end smallexample
3023
3024 @noindent
3025 @value{GDBN} does
3026 not actually evaluate @var{expression} at the time the @code{condition}
3027 command (or a command that sets a breakpoint with a condition, like
3028 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
3029
3030 @item condition @var{bnum}
3031 Remove the condition from breakpoint number @var{bnum}. It becomes
3032 an ordinary unconditional breakpoint.
3033 @end table
3034
3035 @cindex ignore count (of breakpoint)
3036 A special case of a breakpoint condition is to stop only when the
3037 breakpoint has been reached a certain number of times. This is so
3038 useful that there is a special way to do it, using the @dfn{ignore
3039 count} of the breakpoint. Every breakpoint has an ignore count, which
3040 is an integer. Most of the time, the ignore count is zero, and
3041 therefore has no effect. But if your program reaches a breakpoint whose
3042 ignore count is positive, then instead of stopping, it just decrements
3043 the ignore count by one and continues. As a result, if the ignore count
3044 value is @var{n}, the breakpoint does not stop the next @var{n} times
3045 your program reaches it.
3046
3047 @table @code
3048 @kindex ignore
3049 @item ignore @var{bnum} @var{count}
3050 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3051 The next @var{count} times the breakpoint is reached, your program's
3052 execution does not stop; other than to decrement the ignore count, @value{GDBN}
3053 takes no action.
3054
3055 To make the breakpoint stop the next time it is reached, specify
3056 a count of zero.
3057
3058 When you use @code{continue} to resume execution of your program from a
3059 breakpoint, you can specify an ignore count directly as an argument to
3060 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
3061 Stepping,,Continuing and stepping}.
3062
3063 If a breakpoint has a positive ignore count and a condition, the
3064 condition is not checked. Once the ignore count reaches zero,
3065 @value{GDBN} resumes checking the condition.
3066
3067 You could achieve the effect of the ignore count with a condition such
3068 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3069 is decremented each time. @xref{Convenience Vars, ,Convenience
3070 variables}.
3071 @end table
3072
3073 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3074
3075
3076 @node Break Commands
3077 @subsection Breakpoint command lists
3078
3079 @cindex breakpoint commands
3080 You can give any breakpoint (or watchpoint or catchpoint) a series of
3081 commands to execute when your program stops due to that breakpoint. For
3082 example, you might want to print the values of certain expressions, or
3083 enable other breakpoints.
3084
3085 @table @code
3086 @kindex commands
3087 @kindex end
3088 @item commands @r{[}@var{bnum}@r{]}
3089 @itemx @dots{} @var{command-list} @dots{}
3090 @itemx end
3091 Specify a list of commands for breakpoint number @var{bnum}. The commands
3092 themselves appear on the following lines. Type a line containing just
3093 @code{end} to terminate the commands.
3094
3095 To remove all commands from a breakpoint, type @code{commands} and
3096 follow it immediately with @code{end}; that is, give no commands.
3097
3098 With no @var{bnum} argument, @code{commands} refers to the last
3099 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3100 recently encountered).
3101 @end table
3102
3103 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3104 disabled within a @var{command-list}.
3105
3106 You can use breakpoint commands to start your program up again. Simply
3107 use the @code{continue} command, or @code{step}, or any other command
3108 that resumes execution.
3109
3110 Any other commands in the command list, after a command that resumes
3111 execution, are ignored. This is because any time you resume execution
3112 (even with a simple @code{next} or @code{step}), you may encounter
3113 another breakpoint---which could have its own command list, leading to
3114 ambiguities about which list to execute.
3115
3116 @kindex silent
3117 If the first command you specify in a command list is @code{silent}, the
3118 usual message about stopping at a breakpoint is not printed. This may
3119 be desirable for breakpoints that are to print a specific message and
3120 then continue. If none of the remaining commands print anything, you
3121 see no sign that the breakpoint was reached. @code{silent} is
3122 meaningful only at the beginning of a breakpoint command list.
3123
3124 The commands @code{echo}, @code{output}, and @code{printf} allow you to
3125 print precisely controlled output, and are often useful in silent
3126 breakpoints. @xref{Output, ,Commands for controlled output}.
3127
3128 For example, here is how you could use breakpoint commands to print the
3129 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3130
3131 @smallexample
3132 break foo if x>0
3133 commands
3134 silent
3135 printf "x is %d\n",x
3136 cont
3137 end
3138 @end smallexample
3139
3140 One application for breakpoint commands is to compensate for one bug so
3141 you can test for another. Put a breakpoint just after the erroneous line
3142 of code, give it a condition to detect the case in which something
3143 erroneous has been done, and give it commands to assign correct values
3144 to any variables that need them. End with the @code{continue} command
3145 so that your program does not stop, and start with the @code{silent}
3146 command so that no output is produced. Here is an example:
3147
3148 @smallexample
3149 break 403
3150 commands
3151 silent
3152 set x = y + 4
3153 cont
3154 end
3155 @end smallexample
3156
3157 @node Breakpoint Menus
3158 @subsection Breakpoint menus
3159 @cindex overloading
3160 @cindex symbol overloading
3161
3162 Some programming languages (notably C@t{++}) permit a single function name
3163 to be defined several times, for application in different contexts.
3164 This is called @dfn{overloading}. When a function name is overloaded,
3165 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3166 a breakpoint. If you realize this is a problem, you can use
3167 something like @samp{break @var{function}(@var{types})} to specify which
3168 particular version of the function you want. Otherwise, @value{GDBN} offers
3169 you a menu of numbered choices for different possible breakpoints, and
3170 waits for your selection with the prompt @samp{>}. The first two
3171 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3172 sets a breakpoint at each definition of @var{function}, and typing
3173 @kbd{0} aborts the @code{break} command without setting any new
3174 breakpoints.
3175
3176 For example, the following session excerpt shows an attempt to set a
3177 breakpoint at the overloaded symbol @code{String::after}.
3178 We choose three particular definitions of that function name:
3179
3180 @c FIXME! This is likely to change to show arg type lists, at least
3181 @smallexample
3182 @group
3183 (@value{GDBP}) b String::after
3184 [0] cancel
3185 [1] all
3186 [2] file:String.cc; line number:867
3187 [3] file:String.cc; line number:860
3188 [4] file:String.cc; line number:875
3189 [5] file:String.cc; line number:853
3190 [6] file:String.cc; line number:846
3191 [7] file:String.cc; line number:735
3192 > 2 4 6
3193 Breakpoint 1 at 0xb26c: file String.cc, line 867.
3194 Breakpoint 2 at 0xb344: file String.cc, line 875.
3195 Breakpoint 3 at 0xafcc: file String.cc, line 846.
3196 Multiple breakpoints were set.
3197 Use the "delete" command to delete unwanted
3198 breakpoints.
3199 (@value{GDBP})
3200 @end group
3201 @end smallexample
3202
3203 @c @ifclear BARETARGET
3204 @node Error in Breakpoints
3205 @subsection ``Cannot insert breakpoints''
3206 @c
3207 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3208 @c
3209 Under some operating systems, breakpoints cannot be used in a program if
3210 any other process is running that program. In this situation,
3211 attempting to run or continue a program with a breakpoint causes
3212 @value{GDBN} to print an error message:
3213
3214 @smallexample
3215 Cannot insert breakpoints.
3216 The same program may be running in another process.
3217 @end smallexample
3218
3219 When this happens, you have three ways to proceed:
3220
3221 @enumerate
3222 @item
3223 Remove or disable the breakpoints, then continue.
3224
3225 @item
3226 Suspend @value{GDBN}, and copy the file containing your program to a new
3227 name. Resume @value{GDBN} and use the @code{exec-file} command to specify
3228 that @value{GDBN} should run your program under that name.
3229 Then start your program again.
3230
3231 @item
3232 Relink your program so that the text segment is nonsharable, using the
3233 linker option @samp{-N}. The operating system limitation may not apply
3234 to nonsharable executables.
3235 @end enumerate
3236 @c @end ifclear
3237
3238 A similar message can be printed if you request too many active
3239 hardware-assisted breakpoints and watchpoints:
3240
3241 @c FIXME: the precise wording of this message may change; the relevant
3242 @c source change is not committed yet (Sep 3, 1999).
3243 @smallexample
3244 Stopped; cannot insert breakpoints.
3245 You may have requested too many hardware breakpoints and watchpoints.
3246 @end smallexample
3247
3248 @noindent
3249 This message is printed when you attempt to resume the program, since
3250 only then @value{GDBN} knows exactly how many hardware breakpoints and
3251 watchpoints it needs to insert.
3252
3253 When this message is printed, you need to disable or remove some of the
3254 hardware-assisted breakpoints and watchpoints, and then continue.
3255
3256
3257 @node Continuing and Stepping
3258 @section Continuing and stepping
3259
3260 @cindex stepping
3261 @cindex continuing
3262 @cindex resuming execution
3263 @dfn{Continuing} means resuming program execution until your program
3264 completes normally. In contrast, @dfn{stepping} means executing just
3265 one more ``step'' of your program, where ``step'' may mean either one
3266 line of source code, or one machine instruction (depending on what
3267 particular command you use). Either when continuing or when stepping,
3268 your program may stop even sooner, due to a breakpoint or a signal. (If
3269 it stops due to a signal, you may want to use @code{handle}, or use
3270 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
3271
3272 @table @code
3273 @kindex continue
3274 @kindex c @r{(@code{continue})}
3275 @kindex fg @r{(resume foreground execution)}
3276 @item continue @r{[}@var{ignore-count}@r{]}
3277 @itemx c @r{[}@var{ignore-count}@r{]}
3278 @itemx fg @r{[}@var{ignore-count}@r{]}
3279 Resume program execution, at the address where your program last stopped;
3280 any breakpoints set at that address are bypassed. The optional argument
3281 @var{ignore-count} allows you to specify a further number of times to
3282 ignore a breakpoint at this location; its effect is like that of
3283 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3284
3285 The argument @var{ignore-count} is meaningful only when your program
3286 stopped due to a breakpoint. At other times, the argument to
3287 @code{continue} is ignored.
3288
3289 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3290 debugged program is deemed to be the foreground program) are provided
3291 purely for convenience, and have exactly the same behavior as
3292 @code{continue}.
3293 @end table
3294
3295 To resume execution at a different place, you can use @code{return}
3296 (@pxref{Returning, ,Returning from a function}) to go back to the
3297 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3298 different address}) to go to an arbitrary location in your program.
3299
3300 A typical technique for using stepping is to set a breakpoint
3301 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3302 beginning of the function or the section of your program where a problem
3303 is believed to lie, run your program until it stops at that breakpoint,
3304 and then step through the suspect area, examining the variables that are
3305 interesting, until you see the problem happen.
3306
3307 @table @code
3308 @kindex step
3309 @kindex s @r{(@code{step})}
3310 @item step
3311 Continue running your program until control reaches a different source
3312 line, then stop it and return control to @value{GDBN}. This command is
3313 abbreviated @code{s}.
3314
3315 @quotation
3316 @c "without debugging information" is imprecise; actually "without line
3317 @c numbers in the debugging information". (gcc -g1 has debugging info but
3318 @c not line numbers). But it seems complex to try to make that
3319 @c distinction here.
3320 @emph{Warning:} If you use the @code{step} command while control is
3321 within a function that was compiled without debugging information,
3322 execution proceeds until control reaches a function that does have
3323 debugging information. Likewise, it will not step into a function which
3324 is compiled without debugging information. To step through functions
3325 without debugging information, use the @code{stepi} command, described
3326 below.
3327 @end quotation
3328
3329 The @code{step} command only stops at the first instruction of a source
3330 line. This prevents the multiple stops that could otherwise occur in
3331 @code{switch} statements, @code{for} loops, etc. @code{step} continues
3332 to stop if a function that has debugging information is called within
3333 the line. In other words, @code{step} @emph{steps inside} any functions
3334 called within the line.
3335
3336 Also, the @code{step} command only enters a function if there is line
3337 number information for the function. Otherwise it acts like the
3338 @code{next} command. This avoids problems when using @code{cc -gl}
3339 on MIPS machines. Previously, @code{step} entered subroutines if there
3340 was any debugging information about the routine.
3341
3342 @item step @var{count}
3343 Continue running as in @code{step}, but do so @var{count} times. If a
3344 breakpoint is reached, or a signal not related to stepping occurs before
3345 @var{count} steps, stepping stops right away.
3346
3347 @kindex next
3348 @kindex n @r{(@code{next})}
3349 @item next @r{[}@var{count}@r{]}
3350 Continue to the next source line in the current (innermost) stack frame.
3351 This is similar to @code{step}, but function calls that appear within
3352 the line of code are executed without stopping. Execution stops when
3353 control reaches a different line of code at the original stack level
3354 that was executing when you gave the @code{next} command. This command
3355 is abbreviated @code{n}.
3356
3357 An argument @var{count} is a repeat count, as for @code{step}.
3358
3359
3360 @c FIX ME!! Do we delete this, or is there a way it fits in with
3361 @c the following paragraph? --- Vctoria
3362 @c
3363 @c @code{next} within a function that lacks debugging information acts like
3364 @c @code{step}, but any function calls appearing within the code of the
3365 @c function are executed without stopping.
3366
3367 The @code{next} command only stops at the first instruction of a
3368 source line. This prevents multiple stops that could otherwise occur in
3369 @code{switch} statements, @code{for} loops, etc.
3370
3371 @kindex set step-mode
3372 @item set step-mode
3373 @cindex functions without line info, and stepping
3374 @cindex stepping into functions with no line info
3375 @itemx set step-mode on
3376 The @code{set step-mode on} command causes the @code{step} command to
3377 stop at the first instruction of a function which contains no debug line
3378 information rather than stepping over it.
3379
3380 This is useful in cases where you may be interested in inspecting the
3381 machine instructions of a function which has no symbolic info and do not
3382 want @value{GDBN} to automatically skip over this function.
3383
3384 @item set step-mode off
3385 Causes the @code{step} command to step over any functions which contains no
3386 debug information. This is the default.
3387
3388 @kindex finish
3389 @item finish
3390 Continue running until just after function in the selected stack frame
3391 returns. Print the returned value (if any).
3392
3393 Contrast this with the @code{return} command (@pxref{Returning,
3394 ,Returning from a function}).
3395
3396 @kindex until
3397 @kindex u @r{(@code{until})}
3398 @item until
3399 @itemx u
3400 Continue running until a source line past the current line, in the
3401 current stack frame, is reached. This command is used to avoid single
3402 stepping through a loop more than once. It is like the @code{next}
3403 command, except that when @code{until} encounters a jump, it
3404 automatically continues execution until the program counter is greater
3405 than the address of the jump.
3406
3407 This means that when you reach the end of a loop after single stepping
3408 though it, @code{until} makes your program continue execution until it
3409 exits the loop. In contrast, a @code{next} command at the end of a loop
3410 simply steps back to the beginning of the loop, which forces you to step
3411 through the next iteration.
3412
3413 @code{until} always stops your program if it attempts to exit the current
3414 stack frame.
3415
3416 @code{until} may produce somewhat counterintuitive results if the order
3417 of machine code does not match the order of the source lines. For
3418 example, in the following excerpt from a debugging session, the @code{f}
3419 (@code{frame}) command shows that execution is stopped at line
3420 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3421
3422 @smallexample
3423 (@value{GDBP}) f
3424 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3425 206 expand_input();
3426 (@value{GDBP}) until
3427 195 for ( ; argc > 0; NEXTARG) @{
3428 @end smallexample
3429
3430 This happened because, for execution efficiency, the compiler had
3431 generated code for the loop closure test at the end, rather than the
3432 start, of the loop---even though the test in a C @code{for}-loop is
3433 written before the body of the loop. The @code{until} command appeared
3434 to step back to the beginning of the loop when it advanced to this
3435 expression; however, it has not really gone to an earlier
3436 statement---not in terms of the actual machine code.
3437
3438 @code{until} with no argument works by means of single
3439 instruction stepping, and hence is slower than @code{until} with an
3440 argument.
3441
3442 @item until @var{location}
3443 @itemx u @var{location}
3444 Continue running your program until either the specified location is
3445 reached, or the current stack frame returns. @var{location} is any of
3446 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3447 ,Setting breakpoints}). This form of the command uses breakpoints,
3448 and hence is quicker than @code{until} without an argument.
3449
3450 @kindex stepi
3451 @kindex si @r{(@code{stepi})}
3452 @item stepi
3453 @itemx stepi @var{arg}
3454 @itemx si
3455 Execute one machine instruction, then stop and return to the debugger.
3456
3457 It is often useful to do @samp{display/i $pc} when stepping by machine
3458 instructions. This makes @value{GDBN} automatically display the next
3459 instruction to be executed, each time your program stops. @xref{Auto
3460 Display,, Automatic display}.
3461
3462 An argument is a repeat count, as in @code{step}.
3463
3464 @need 750
3465 @kindex nexti
3466 @kindex ni @r{(@code{nexti})}
3467 @item nexti
3468 @itemx nexti @var{arg}
3469 @itemx ni
3470 Execute one machine instruction, but if it is a function call,
3471 proceed until the function returns.
3472
3473 An argument is a repeat count, as in @code{next}.
3474 @end table
3475
3476 @node Signals
3477 @section Signals
3478 @cindex signals
3479
3480 A signal is an asynchronous event that can happen in a program. The
3481 operating system defines the possible kinds of signals, and gives each
3482 kind a name and a number. For example, in Unix @code{SIGINT} is the
3483 signal a program gets when you type an interrupt character (often @kbd{C-c});
3484 @code{SIGSEGV} is the signal a program gets from referencing a place in
3485 memory far away from all the areas in use; @code{SIGALRM} occurs when
3486 the alarm clock timer goes off (which happens only if your program has
3487 requested an alarm).
3488
3489 @cindex fatal signals
3490 Some signals, including @code{SIGALRM}, are a normal part of the
3491 functioning of your program. Others, such as @code{SIGSEGV}, indicate
3492 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
3493 program has not specified in advance some other way to handle the signal.
3494 @code{SIGINT} does not indicate an error in your program, but it is normally
3495 fatal so it can carry out the purpose of the interrupt: to kill the program.
3496
3497 @value{GDBN} has the ability to detect any occurrence of a signal in your
3498 program. You can tell @value{GDBN} in advance what to do for each kind of
3499 signal.
3500
3501 @cindex handling signals
3502 Normally, @value{GDBN} is set up to let the non-erroneous signals like
3503 @code{SIGALRM} be silently passed to your program
3504 (so as not to interfere with their role in the program's functioning)
3505 but to stop your program immediately whenever an error signal happens.
3506 You can change these settings with the @code{handle} command.
3507
3508 @table @code
3509 @kindex info signals
3510 @item info signals
3511 @itemx info handle
3512 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3513 handle each one. You can use this to see the signal numbers of all
3514 the defined types of signals.
3515
3516 @code{info handle} is an alias for @code{info signals}.
3517
3518 @kindex handle
3519 @item handle @var{signal} @var{keywords}@dots{}
3520 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3521 can be the number of a signal or its name (with or without the
3522 @samp{SIG} at the beginning); a list of signal numbers of the form
3523 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3524 known signals. The @var{keywords} say what change to make.
3525 @end table
3526
3527 @c @group
3528 The keywords allowed by the @code{handle} command can be abbreviated.
3529 Their full names are:
3530
3531 @table @code
3532 @item nostop
3533 @value{GDBN} should not stop your program when this signal happens. It may
3534 still print a message telling you that the signal has come in.
3535
3536 @item stop
3537 @value{GDBN} should stop your program when this signal happens. This implies
3538 the @code{print} keyword as well.
3539
3540 @item print
3541 @value{GDBN} should print a message when this signal happens.
3542
3543 @item noprint
3544 @value{GDBN} should not mention the occurrence of the signal at all. This
3545 implies the @code{nostop} keyword as well.
3546
3547 @item pass
3548 @itemx noignore
3549 @value{GDBN} should allow your program to see this signal; your program
3550 can handle the signal, or else it may terminate if the signal is fatal
3551 and not handled. @code{pass} and @code{noignore} are synonyms.
3552
3553 @item nopass
3554 @itemx ignore
3555 @value{GDBN} should not allow your program to see this signal.
3556 @code{nopass} and @code{ignore} are synonyms.
3557 @end table
3558 @c @end group
3559
3560 When a signal stops your program, the signal is not visible to the
3561 program until you
3562 continue. Your program sees the signal then, if @code{pass} is in
3563 effect for the signal in question @emph{at that time}. In other words,
3564 after @value{GDBN} reports a signal, you can use the @code{handle}
3565 command with @code{pass} or @code{nopass} to control whether your
3566 program sees that signal when you continue.
3567
3568 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3569 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3570 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3571 erroneous signals.
3572
3573 You can also use the @code{signal} command to prevent your program from
3574 seeing a signal, or cause it to see a signal it normally would not see,
3575 or to give it any signal at any time. For example, if your program stopped
3576 due to some sort of memory reference error, you might store correct
3577 values into the erroneous variables and continue, hoping to see more
3578 execution; but your program would probably terminate immediately as
3579 a result of the fatal signal once it saw the signal. To prevent this,
3580 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3581 program a signal}.
3582
3583 @node Thread Stops
3584 @section Stopping and starting multi-thread programs
3585
3586 When your program has multiple threads (@pxref{Threads,, Debugging
3587 programs with multiple threads}), you can choose whether to set
3588 breakpoints on all threads, or on a particular thread.
3589
3590 @table @code
3591 @cindex breakpoints and threads
3592 @cindex thread breakpoints
3593 @kindex break @dots{} thread @var{threadno}
3594 @item break @var{linespec} thread @var{threadno}
3595 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3596 @var{linespec} specifies source lines; there are several ways of
3597 writing them, but the effect is always to specify some source line.
3598
3599 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3600 to specify that you only want @value{GDBN} to stop the program when a
3601 particular thread reaches this breakpoint. @var{threadno} is one of the
3602 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3603 column of the @samp{info threads} display.
3604
3605 If you do not specify @samp{thread @var{threadno}} when you set a
3606 breakpoint, the breakpoint applies to @emph{all} threads of your
3607 program.
3608
3609 You can use the @code{thread} qualifier on conditional breakpoints as
3610 well; in this case, place @samp{thread @var{threadno}} before the
3611 breakpoint condition, like this:
3612
3613 @smallexample
3614 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
3615 @end smallexample
3616
3617 @end table
3618
3619 @cindex stopped threads
3620 @cindex threads, stopped
3621 Whenever your program stops under @value{GDBN} for any reason,
3622 @emph{all} threads of execution stop, not just the current thread. This
3623 allows you to examine the overall state of the program, including
3624 switching between threads, without worrying that things may change
3625 underfoot.
3626
3627 @cindex continuing threads
3628 @cindex threads, continuing
3629 Conversely, whenever you restart the program, @emph{all} threads start
3630 executing. @emph{This is true even when single-stepping} with commands
3631 like @code{step} or @code{next}.
3632
3633 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3634 Since thread scheduling is up to your debugging target's operating
3635 system (not controlled by @value{GDBN}), other threads may
3636 execute more than one statement while the current thread completes a
3637 single step. Moreover, in general other threads stop in the middle of a
3638 statement, rather than at a clean statement boundary, when the program
3639 stops.
3640
3641 You might even find your program stopped in another thread after
3642 continuing or even single-stepping. This happens whenever some other
3643 thread runs into a breakpoint, a signal, or an exception before the
3644 first thread completes whatever you requested.
3645
3646 On some OSes, you can lock the OS scheduler and thus allow only a single
3647 thread to run.
3648
3649 @table @code
3650 @item set scheduler-locking @var{mode}
3651 Set the scheduler locking mode. If it is @code{off}, then there is no
3652 locking and any thread may run at any time. If @code{on}, then only the
3653 current thread may run when the inferior is resumed. The @code{step}
3654 mode optimizes for single-stepping. It stops other threads from
3655 ``seizing the prompt'' by preempting the current thread while you are
3656 stepping. Other threads will only rarely (or never) get a chance to run
3657 when you step. They are more likely to run when you @samp{next} over a
3658 function call, and they are completely free to run when you use commands
3659 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
3660 thread hits a breakpoint during its timeslice, they will never steal the
3661 @value{GDBN} prompt away from the thread that you are debugging.
3662
3663 @item show scheduler-locking
3664 Display the current scheduler locking mode.
3665 @end table
3666
3667
3668 @node Stack
3669 @chapter Examining the Stack
3670
3671 When your program has stopped, the first thing you need to know is where it
3672 stopped and how it got there.
3673
3674 @cindex call stack
3675 Each time your program performs a function call, information about the call
3676 is generated.
3677 That information includes the location of the call in your program,
3678 the arguments of the call,
3679 and the local variables of the function being called.
3680 The information is saved in a block of data called a @dfn{stack frame}.
3681 The stack frames are allocated in a region of memory called the @dfn{call
3682 stack}.
3683
3684 When your program stops, the @value{GDBN} commands for examining the
3685 stack allow you to see all of this information.
3686
3687 @cindex selected frame
3688 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3689 @value{GDBN} commands refer implicitly to the selected frame. In
3690 particular, whenever you ask @value{GDBN} for the value of a variable in
3691 your program, the value is found in the selected frame. There are
3692 special @value{GDBN} commands to select whichever frame you are
3693 interested in. @xref{Selection, ,Selecting a frame}.
3694
3695 When your program stops, @value{GDBN} automatically selects the
3696 currently executing frame and describes it briefly, similar to the
3697 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3698
3699 @menu
3700 * Frames:: Stack frames
3701 * Backtrace:: Backtraces
3702 * Selection:: Selecting a frame
3703 * Frame Info:: Information on a frame
3704
3705 @end menu
3706
3707 @node Frames
3708 @section Stack frames
3709
3710 @cindex frame, definition
3711 @cindex stack frame
3712 The call stack is divided up into contiguous pieces called @dfn{stack
3713 frames}, or @dfn{frames} for short; each frame is the data associated
3714 with one call to one function. The frame contains the arguments given
3715 to the function, the function's local variables, and the address at
3716 which the function is executing.
3717
3718 @cindex initial frame
3719 @cindex outermost frame
3720 @cindex innermost frame
3721 When your program is started, the stack has only one frame, that of the
3722 function @code{main}. This is called the @dfn{initial} frame or the
3723 @dfn{outermost} frame. Each time a function is called, a new frame is
3724 made. Each time a function returns, the frame for that function invocation
3725 is eliminated. If a function is recursive, there can be many frames for
3726 the same function. The frame for the function in which execution is
3727 actually occurring is called the @dfn{innermost} frame. This is the most
3728 recently created of all the stack frames that still exist.
3729
3730 @cindex frame pointer
3731 Inside your program, stack frames are identified by their addresses. A
3732 stack frame consists of many bytes, each of which has its own address; each
3733 kind of computer has a convention for choosing one byte whose
3734 address serves as the address of the frame. Usually this address is kept
3735 in a register called the @dfn{frame pointer register} while execution is
3736 going on in that frame.
3737
3738 @cindex frame number
3739 @value{GDBN} assigns numbers to all existing stack frames, starting with
3740 zero for the innermost frame, one for the frame that called it,
3741 and so on upward. These numbers do not really exist in your program;
3742 they are assigned by @value{GDBN} to give you a way of designating stack
3743 frames in @value{GDBN} commands.
3744
3745 @c The -fomit-frame-pointer below perennially causes hbox overflow
3746 @c underflow problems.
3747 @cindex frameless execution
3748 Some compilers provide a way to compile functions so that they operate
3749 without stack frames. (For example, the @value{GCC} option
3750 @smallexample
3751 @samp{-fomit-frame-pointer}
3752 @end smallexample
3753 generates functions without a frame.)
3754 This is occasionally done with heavily used library functions to save
3755 the frame setup time. @value{GDBN} has limited facilities for dealing
3756 with these function invocations. If the innermost function invocation
3757 has no stack frame, @value{GDBN} nevertheless regards it as though
3758 it had a separate frame, which is numbered zero as usual, allowing
3759 correct tracing of the function call chain. However, @value{GDBN} has
3760 no provision for frameless functions elsewhere in the stack.
3761
3762 @table @code
3763 @kindex frame@r{, command}
3764 @cindex current stack frame
3765 @item frame @var{args}
3766 The @code{frame} command allows you to move from one stack frame to another,
3767 and to print the stack frame you select. @var{args} may be either the
3768 address of the frame or the stack frame number. Without an argument,
3769 @code{frame} prints the current stack frame.
3770
3771 @kindex select-frame
3772 @cindex selecting frame silently
3773 @item select-frame
3774 The @code{select-frame} command allows you to move from one stack frame
3775 to another without printing the frame. This is the silent version of
3776 @code{frame}.
3777 @end table
3778
3779 @node Backtrace
3780 @section Backtraces
3781
3782 @cindex backtraces
3783 @cindex tracebacks
3784 @cindex stack traces
3785 A backtrace is a summary of how your program got where it is. It shows one
3786 line per frame, for many frames, starting with the currently executing
3787 frame (frame zero), followed by its caller (frame one), and on up the
3788 stack.
3789
3790 @table @code
3791 @kindex backtrace
3792 @kindex bt @r{(@code{backtrace})}
3793 @item backtrace
3794 @itemx bt
3795 Print a backtrace of the entire stack: one line per frame for all
3796 frames in the stack.
3797
3798 You can stop the backtrace at any time by typing the system interrupt
3799 character, normally @kbd{C-c}.
3800
3801 @item backtrace @var{n}
3802 @itemx bt @var{n}
3803 Similar, but print only the innermost @var{n} frames.
3804
3805 @item backtrace -@var{n}
3806 @itemx bt -@var{n}
3807 Similar, but print only the outermost @var{n} frames.
3808 @end table
3809
3810 @kindex where
3811 @kindex info stack
3812 @kindex info s @r{(@code{info stack})}
3813 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3814 are additional aliases for @code{backtrace}.
3815
3816 Each line in the backtrace shows the frame number and the function name.
3817 The program counter value is also shown---unless you use @code{set
3818 print address off}. The backtrace also shows the source file name and
3819 line number, as well as the arguments to the function. The program
3820 counter value is omitted if it is at the beginning of the code for that
3821 line number.
3822
3823 Here is an example of a backtrace. It was made with the command
3824 @samp{bt 3}, so it shows the innermost three frames.
3825
3826 @smallexample
3827 @group
3828 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3829 at builtin.c:993
3830 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3831 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3832 at macro.c:71
3833 (More stack frames follow...)
3834 @end group
3835 @end smallexample
3836
3837 @noindent
3838 The display for frame zero does not begin with a program counter
3839 value, indicating that your program has stopped at the beginning of the
3840 code for line @code{993} of @code{builtin.c}.
3841
3842 @node Selection
3843 @section Selecting a frame
3844
3845 Most commands for examining the stack and other data in your program work on
3846 whichever stack frame is selected at the moment. Here are the commands for
3847 selecting a stack frame; all of them finish by printing a brief description
3848 of the stack frame just selected.
3849
3850 @table @code
3851 @kindex frame@r{, selecting}
3852 @kindex f @r{(@code{frame})}
3853 @item frame @var{n}
3854 @itemx f @var{n}
3855 Select frame number @var{n}. Recall that frame zero is the innermost
3856 (currently executing) frame, frame one is the frame that called the
3857 innermost one, and so on. The highest-numbered frame is the one for
3858 @code{main}.
3859
3860 @item frame @var{addr}
3861 @itemx f @var{addr}
3862 Select the frame at address @var{addr}. This is useful mainly if the
3863 chaining of stack frames has been damaged by a bug, making it
3864 impossible for @value{GDBN} to assign numbers properly to all frames. In
3865 addition, this can be useful when your program has multiple stacks and
3866 switches between them.
3867
3868 On the SPARC architecture, @code{frame} needs two addresses to
3869 select an arbitrary frame: a frame pointer and a stack pointer.
3870
3871 On the MIPS and Alpha architecture, it needs two addresses: a stack
3872 pointer and a program counter.
3873
3874 On the 29k architecture, it needs three addresses: a register stack
3875 pointer, a program counter, and a memory stack pointer.
3876 @c note to future updaters: this is conditioned on a flag
3877 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3878 @c as of 27 Jan 1994.
3879
3880 @kindex up
3881 @item up @var{n}
3882 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3883 advances toward the outermost frame, to higher frame numbers, to frames
3884 that have existed longer. @var{n} defaults to one.
3885
3886 @kindex down
3887 @kindex do @r{(@code{down})}
3888 @item down @var{n}
3889 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3890 advances toward the innermost frame, to lower frame numbers, to frames
3891 that were created more recently. @var{n} defaults to one. You may
3892 abbreviate @code{down} as @code{do}.
3893 @end table
3894
3895 All of these commands end by printing two lines of output describing the
3896 frame. The first line shows the frame number, the function name, the
3897 arguments, and the source file and line number of execution in that
3898 frame. The second line shows the text of that source line.
3899
3900 @need 1000
3901 For example:
3902
3903 @smallexample
3904 @group
3905 (@value{GDBP}) up
3906 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3907 at env.c:10
3908 10 read_input_file (argv[i]);
3909 @end group
3910 @end smallexample
3911
3912 After such a printout, the @code{list} command with no arguments
3913 prints ten lines centered on the point of execution in the frame.
3914 @xref{List, ,Printing source lines}.
3915
3916 @table @code
3917 @kindex down-silently
3918 @kindex up-silently
3919 @item up-silently @var{n}
3920 @itemx down-silently @var{n}
3921 These two commands are variants of @code{up} and @code{down},
3922 respectively; they differ in that they do their work silently, without
3923 causing display of the new frame. They are intended primarily for use
3924 in @value{GDBN} command scripts, where the output might be unnecessary and
3925 distracting.
3926 @end table
3927
3928 @node Frame Info
3929 @section Information about a frame
3930
3931 There are several other commands to print information about the selected
3932 stack frame.
3933
3934 @table @code
3935 @item frame
3936 @itemx f
3937 When used without any argument, this command does not change which
3938 frame is selected, but prints a brief description of the currently
3939 selected stack frame. It can be abbreviated @code{f}. With an
3940 argument, this command is used to select a stack frame.
3941 @xref{Selection, ,Selecting a frame}.
3942
3943 @kindex info frame
3944 @kindex info f @r{(@code{info frame})}
3945 @item info frame
3946 @itemx info f
3947 This command prints a verbose description of the selected stack frame,
3948 including:
3949
3950 @itemize @bullet
3951 @item
3952 the address of the frame
3953 @item
3954 the address of the next frame down (called by this frame)
3955 @item
3956 the address of the next frame up (caller of this frame)
3957 @item
3958 the language in which the source code corresponding to this frame is written
3959 @item
3960 the address of the frame's arguments
3961 @item
3962 the address of the frame's local variables
3963 @item
3964 the program counter saved in it (the address of execution in the caller frame)
3965 @item
3966 which registers were saved in the frame
3967 @end itemize
3968
3969 @noindent The verbose description is useful when
3970 something has gone wrong that has made the stack format fail to fit
3971 the usual conventions.
3972
3973 @item info frame @var{addr}
3974 @itemx info f @var{addr}
3975 Print a verbose description of the frame at address @var{addr}, without
3976 selecting that frame. The selected frame remains unchanged by this
3977 command. This requires the same kind of address (more than one for some
3978 architectures) that you specify in the @code{frame} command.
3979 @xref{Selection, ,Selecting a frame}.
3980
3981 @kindex info args
3982 @item info args
3983 Print the arguments of the selected frame, each on a separate line.
3984
3985 @item info locals
3986 @kindex info locals
3987 Print the local variables of the selected frame, each on a separate
3988 line. These are all variables (declared either static or automatic)
3989 accessible at the point of execution of the selected frame.
3990
3991 @kindex info catch
3992 @cindex catch exceptions, list active handlers
3993 @cindex exception handlers, how to list
3994 @item info catch
3995 Print a list of all the exception handlers that are active in the
3996 current stack frame at the current point of execution. To see other
3997 exception handlers, visit the associated frame (using the @code{up},
3998 @code{down}, or @code{frame} commands); then type @code{info catch}.
3999 @xref{Set Catchpoints, , Setting catchpoints}.
4000
4001 @end table
4002
4003
4004 @node Source
4005 @chapter Examining Source Files
4006
4007 @value{GDBN} can print parts of your program's source, since the debugging
4008 information recorded in the program tells @value{GDBN} what source files were
4009 used to build it. When your program stops, @value{GDBN} spontaneously prints
4010 the line where it stopped. Likewise, when you select a stack frame
4011 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4012 execution in that frame has stopped. You can print other portions of
4013 source files by explicit command.
4014
4015 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
4016 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
4017 @value{GDBN} under @sc{gnu} Emacs}.
4018
4019 @menu
4020 * List:: Printing source lines
4021 * Search:: Searching source files
4022 * Source Path:: Specifying source directories
4023 * Machine Code:: Source and machine code
4024 @end menu
4025
4026 @node List
4027 @section Printing source lines
4028
4029 @kindex list
4030 @kindex l @r{(@code{list})}
4031 To print lines from a source file, use the @code{list} command
4032 (abbreviated @code{l}). By default, ten lines are printed.
4033 There are several ways to specify what part of the file you want to print.
4034
4035 Here are the forms of the @code{list} command most commonly used:
4036
4037 @table @code
4038 @item list @var{linenum}
4039 Print lines centered around line number @var{linenum} in the
4040 current source file.
4041
4042 @item list @var{function}
4043 Print lines centered around the beginning of function
4044 @var{function}.
4045
4046 @item list
4047 Print more lines. If the last lines printed were printed with a
4048 @code{list} command, this prints lines following the last lines
4049 printed; however, if the last line printed was a solitary line printed
4050 as part of displaying a stack frame (@pxref{Stack, ,Examining the
4051 Stack}), this prints lines centered around that line.
4052
4053 @item list -
4054 Print lines just before the lines last printed.
4055 @end table
4056
4057 By default, @value{GDBN} prints ten source lines with any of these forms of
4058 the @code{list} command. You can change this using @code{set listsize}:
4059
4060 @table @code
4061 @kindex set listsize
4062 @item set listsize @var{count}
4063 Make the @code{list} command display @var{count} source lines (unless
4064 the @code{list} argument explicitly specifies some other number).
4065
4066 @kindex show listsize
4067 @item show listsize
4068 Display the number of lines that @code{list} prints.
4069 @end table
4070
4071 Repeating a @code{list} command with @key{RET} discards the argument,
4072 so it is equivalent to typing just @code{list}. This is more useful
4073 than listing the same lines again. An exception is made for an
4074 argument of @samp{-}; that argument is preserved in repetition so that
4075 each repetition moves up in the source file.
4076
4077 @cindex linespec
4078 In general, the @code{list} command expects you to supply zero, one or two
4079 @dfn{linespecs}. Linespecs specify source lines; there are several ways
4080 of writing them, but the effect is always to specify some source line.
4081 Here is a complete description of the possible arguments for @code{list}:
4082
4083 @table @code
4084 @item list @var{linespec}
4085 Print lines centered around the line specified by @var{linespec}.
4086
4087 @item list @var{first},@var{last}
4088 Print lines from @var{first} to @var{last}. Both arguments are
4089 linespecs.
4090
4091 @item list ,@var{last}
4092 Print lines ending with @var{last}.
4093
4094 @item list @var{first},
4095 Print lines starting with @var{first}.
4096
4097 @item list +
4098 Print lines just after the lines last printed.
4099
4100 @item list -
4101 Print lines just before the lines last printed.
4102
4103 @item list
4104 As described in the preceding table.
4105 @end table
4106
4107 Here are the ways of specifying a single source line---all the
4108 kinds of linespec.
4109
4110 @table @code
4111 @item @var{number}
4112 Specifies line @var{number} of the current source file.
4113 When a @code{list} command has two linespecs, this refers to
4114 the same source file as the first linespec.
4115
4116 @item +@var{offset}
4117 Specifies the line @var{offset} lines after the last line printed.
4118 When used as the second linespec in a @code{list} command that has
4119 two, this specifies the line @var{offset} lines down from the
4120 first linespec.
4121
4122 @item -@var{offset}
4123 Specifies the line @var{offset} lines before the last line printed.
4124
4125 @item @var{filename}:@var{number}
4126 Specifies line @var{number} in the source file @var{filename}.
4127
4128 @item @var{function}
4129 Specifies the line that begins the body of the function @var{function}.
4130 For example: in C, this is the line with the open brace.
4131
4132 @item @var{filename}:@var{function}
4133 Specifies the line of the open-brace that begins the body of the
4134 function @var{function} in the file @var{filename}. You only need the
4135 file name with a function name to avoid ambiguity when there are
4136 identically named functions in different source files.
4137
4138 @item *@var{address}
4139 Specifies the line containing the program address @var{address}.
4140 @var{address} may be any expression.
4141 @end table
4142
4143 @node Search
4144 @section Searching source files
4145 @cindex searching
4146 @kindex reverse-search
4147
4148 There are two commands for searching through the current source file for a
4149 regular expression.
4150
4151 @table @code
4152 @kindex search
4153 @kindex forward-search
4154 @item forward-search @var{regexp}
4155 @itemx search @var{regexp}
4156 The command @samp{forward-search @var{regexp}} checks each line,
4157 starting with the one following the last line listed, for a match for
4158 @var{regexp}. It lists the line that is found. You can use the
4159 synonym @samp{search @var{regexp}} or abbreviate the command name as
4160 @code{fo}.
4161
4162 @item reverse-search @var{regexp}
4163 The command @samp{reverse-search @var{regexp}} checks each line, starting
4164 with the one before the last line listed and going backward, for a match
4165 for @var{regexp}. It lists the line that is found. You can abbreviate
4166 this command as @code{rev}.
4167 @end table
4168
4169 @node Source Path
4170 @section Specifying source directories
4171
4172 @cindex source path
4173 @cindex directories for source files
4174 Executable programs sometimes do not record the directories of the source
4175 files from which they were compiled, just the names. Even when they do,
4176 the directories could be moved between the compilation and your debugging
4177 session. @value{GDBN} has a list of directories to search for source files;
4178 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4179 it tries all the directories in the list, in the order they are present
4180 in the list, until it finds a file with the desired name. Note that
4181 the executable search path is @emph{not} used for this purpose. Neither is
4182 the current working directory, unless it happens to be in the source
4183 path.
4184
4185 If @value{GDBN} cannot find a source file in the source path, and the
4186 object program records a directory, @value{GDBN} tries that directory
4187 too. If the source path is empty, and there is no record of the
4188 compilation directory, @value{GDBN} looks in the current directory as a
4189 last resort.
4190
4191 Whenever you reset or rearrange the source path, @value{GDBN} clears out
4192 any information it has cached about where source files are found and where
4193 each line is in the file.
4194
4195 @kindex directory
4196 @kindex dir
4197 When you start @value{GDBN}, its source path includes only @samp{cdir}
4198 and @samp{cwd}, in that order.
4199 To add other directories, use the @code{directory} command.
4200
4201 @table @code
4202 @item directory @var{dirname} @dots{}
4203 @item dir @var{dirname} @dots{}
4204 Add directory @var{dirname} to the front of the source path. Several
4205 directory names may be given to this command, separated by @samp{:}
4206 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4207 part of absolute file names) or
4208 whitespace. You may specify a directory that is already in the source
4209 path; this moves it forward, so @value{GDBN} searches it sooner.
4210
4211 @kindex cdir
4212 @kindex cwd
4213 @vindex $cdir@r{, convenience variable}
4214 @vindex $cwdr@r{, convenience variable}
4215 @cindex compilation directory
4216 @cindex current directory
4217 @cindex working directory
4218 @cindex directory, current
4219 @cindex directory, compilation
4220 You can use the string @samp{$cdir} to refer to the compilation
4221 directory (if one is recorded), and @samp{$cwd} to refer to the current
4222 working directory. @samp{$cwd} is not the same as @samp{.}---the former
4223 tracks the current working directory as it changes during your @value{GDBN}
4224 session, while the latter is immediately expanded to the current
4225 directory at the time you add an entry to the source path.
4226
4227 @item directory
4228 Reset the source path to empty again. This requires confirmation.
4229
4230 @c RET-repeat for @code{directory} is explicitly disabled, but since
4231 @c repeating it would be a no-op we do not say that. (thanks to RMS)
4232
4233 @item show directories
4234 @kindex show directories
4235 Print the source path: show which directories it contains.
4236 @end table
4237
4238 If your source path is cluttered with directories that are no longer of
4239 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4240 versions of source. You can correct the situation as follows:
4241
4242 @enumerate
4243 @item
4244 Use @code{directory} with no argument to reset the source path to empty.
4245
4246 @item
4247 Use @code{directory} with suitable arguments to reinstall the
4248 directories you want in the source path. You can add all the
4249 directories in one command.
4250 @end enumerate
4251
4252 @node Machine Code
4253 @section Source and machine code
4254
4255 You can use the command @code{info line} to map source lines to program
4256 addresses (and vice versa), and the command @code{disassemble} to display
4257 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
4258 mode, the @code{info line} command causes the arrow to point to the
4259 line specified. Also, @code{info line} prints addresses in symbolic form as
4260 well as hex.
4261
4262 @table @code
4263 @kindex info line
4264 @item info line @var{linespec}
4265 Print the starting and ending addresses of the compiled code for
4266 source line @var{linespec}. You can specify source lines in any of
4267 the ways understood by the @code{list} command (@pxref{List, ,Printing
4268 source lines}).
4269 @end table
4270
4271 For example, we can use @code{info line} to discover the location of
4272 the object code for the first line of function
4273 @code{m4_changequote}:
4274
4275 @c FIXME: I think this example should also show the addresses in
4276 @c symbolic form, as they usually would be displayed.
4277 @smallexample
4278 (@value{GDBP}) info line m4_changequote
4279 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4280 @end smallexample
4281
4282 @noindent
4283 We can also inquire (using @code{*@var{addr}} as the form for
4284 @var{linespec}) what source line covers a particular address:
4285 @smallexample
4286 (@value{GDBP}) info line *0x63ff
4287 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4288 @end smallexample
4289
4290 @cindex @code{$_} and @code{info line}
4291 @kindex x@r{(examine), and} info line
4292 After @code{info line}, the default address for the @code{x} command
4293 is changed to the starting address of the line, so that @samp{x/i} is
4294 sufficient to begin examining the machine code (@pxref{Memory,
4295 ,Examining memory}). Also, this address is saved as the value of the
4296 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4297 variables}).
4298
4299 @table @code
4300 @kindex disassemble
4301 @cindex assembly instructions
4302 @cindex instructions, assembly
4303 @cindex machine instructions
4304 @cindex listing machine instructions
4305 @item disassemble
4306 This specialized command dumps a range of memory as machine
4307 instructions. The default memory range is the function surrounding the
4308 program counter of the selected frame. A single argument to this
4309 command is a program counter value; @value{GDBN} dumps the function
4310 surrounding this value. Two arguments specify a range of addresses
4311 (first inclusive, second exclusive) to dump.
4312 @end table
4313
4314 The following example shows the disassembly of a range of addresses of
4315 HP PA-RISC 2.0 code:
4316
4317 @smallexample
4318 (@value{GDBP}) disas 0x32c4 0x32e4
4319 Dump of assembler code from 0x32c4 to 0x32e4:
4320 0x32c4 <main+204>: addil 0,dp
4321 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
4322 0x32cc <main+212>: ldil 0x3000,r31
4323 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
4324 0x32d4 <main+220>: ldo 0(r31),rp
4325 0x32d8 <main+224>: addil -0x800,dp
4326 0x32dc <main+228>: ldo 0x588(r1),r26
4327 0x32e0 <main+232>: ldil 0x3000,r31
4328 End of assembler dump.
4329 @end smallexample
4330
4331 Some architectures have more than one commonly-used set of instruction
4332 mnemonics or other syntax.
4333
4334 @table @code
4335 @kindex set disassembly-flavor
4336 @cindex assembly instructions
4337 @cindex instructions, assembly
4338 @cindex machine instructions
4339 @cindex listing machine instructions
4340 @cindex Intel disassembly flavor
4341 @cindex AT&T disassembly flavor
4342 @item set disassembly-flavor @var{instruction-set}
4343 Select the instruction set to use when disassembling the
4344 program via the @code{disassemble} or @code{x/i} commands.
4345
4346 Currently this command is only defined for the Intel x86 family. You
4347 can set @var{instruction-set} to either @code{intel} or @code{att}.
4348 The default is @code{att}, the AT&T flavor used by default by Unix
4349 assemblers for x86-based targets.
4350 @end table
4351
4352
4353 @node Data
4354 @chapter Examining Data
4355
4356 @cindex printing data
4357 @cindex examining data
4358 @kindex print
4359 @kindex inspect
4360 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
4361 @c document because it is nonstandard... Under Epoch it displays in a
4362 @c different window or something like that.
4363 The usual way to examine data in your program is with the @code{print}
4364 command (abbreviated @code{p}), or its synonym @code{inspect}. It
4365 evaluates and prints the value of an expression of the language your
4366 program is written in (@pxref{Languages, ,Using @value{GDBN} with
4367 Different Languages}).
4368
4369 @table @code
4370 @item print @var{expr}
4371 @itemx print /@var{f} @var{expr}
4372 @var{expr} is an expression (in the source language). By default the
4373 value of @var{expr} is printed in a format appropriate to its data type;
4374 you can choose a different format by specifying @samp{/@var{f}}, where
4375 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
4376 formats}.
4377
4378 @item print
4379 @itemx print /@var{f}
4380 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
4381 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4382 conveniently inspect the same value in an alternative format.
4383 @end table
4384
4385 A more low-level way of examining data is with the @code{x} command.
4386 It examines data in memory at a specified address and prints it in a
4387 specified format. @xref{Memory, ,Examining memory}.
4388
4389 If you are interested in information about types, or about how the
4390 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4391 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
4392 Table}.
4393
4394 @menu
4395 * Expressions:: Expressions
4396 * Variables:: Program variables
4397 * Arrays:: Artificial arrays
4398 * Output Formats:: Output formats
4399 * Memory:: Examining memory
4400 * Auto Display:: Automatic display
4401 * Print Settings:: Print settings
4402 * Value History:: Value history
4403 * Convenience Vars:: Convenience variables
4404 * Registers:: Registers
4405 * Floating Point Hardware:: Floating point hardware
4406 * Memory Region Attributes:: Memory region attributes
4407 @end menu
4408
4409 @node Expressions
4410 @section Expressions
4411
4412 @cindex expressions
4413 @code{print} and many other @value{GDBN} commands accept an expression and
4414 compute its value. Any kind of constant, variable or operator defined
4415 by the programming language you are using is valid in an expression in
4416 @value{GDBN}. This includes conditional expressions, function calls, casts
4417 and string constants. It unfortunately does not include symbols defined
4418 by preprocessor @code{#define} commands.
4419
4420 @value{GDBN} supports array constants in expressions input by
4421 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
4422 you can use the command @code{print @{1, 2, 3@}} to build up an array in
4423 memory that is @code{malloc}ed in the target program.
4424
4425 Because C is so widespread, most of the expressions shown in examples in
4426 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4427 Languages}, for information on how to use expressions in other
4428 languages.
4429
4430 In this section, we discuss operators that you can use in @value{GDBN}
4431 expressions regardless of your programming language.
4432
4433 Casts are supported in all languages, not just in C, because it is so
4434 useful to cast a number into a pointer in order to examine a structure
4435 at that address in memory.
4436 @c FIXME: casts supported---Mod2 true?
4437
4438 @value{GDBN} supports these operators, in addition to those common
4439 to programming languages:
4440
4441 @table @code
4442 @item @@
4443 @samp{@@} is a binary operator for treating parts of memory as arrays.
4444 @xref{Arrays, ,Artificial arrays}, for more information.
4445
4446 @item ::
4447 @samp{::} allows you to specify a variable in terms of the file or
4448 function where it is defined. @xref{Variables, ,Program variables}.
4449
4450 @cindex @{@var{type}@}
4451 @cindex type casting memory
4452 @cindex memory, viewing as typed object
4453 @cindex casts, to view memory
4454 @item @{@var{type}@} @var{addr}
4455 Refers to an object of type @var{type} stored at address @var{addr} in
4456 memory. @var{addr} may be any expression whose value is an integer or
4457 pointer (but parentheses are required around binary operators, just as in
4458 a cast). This construct is allowed regardless of what kind of data is
4459 normally supposed to reside at @var{addr}.
4460 @end table
4461
4462 @node Variables
4463 @section Program variables
4464
4465 The most common kind of expression to use is the name of a variable
4466 in your program.
4467
4468 Variables in expressions are understood in the selected stack frame
4469 (@pxref{Selection, ,Selecting a frame}); they must be either:
4470
4471 @itemize @bullet
4472 @item
4473 global (or file-static)
4474 @end itemize
4475
4476 @noindent or
4477
4478 @itemize @bullet
4479 @item
4480 visible according to the scope rules of the
4481 programming language from the point of execution in that frame
4482 @end itemize
4483
4484 @noindent This means that in the function
4485
4486 @smallexample
4487 foo (a)
4488 int a;
4489 @{
4490 bar (a);
4491 @{
4492 int b = test ();
4493 bar (b);
4494 @}
4495 @}
4496 @end smallexample
4497
4498 @noindent
4499 you can examine and use the variable @code{a} whenever your program is
4500 executing within the function @code{foo}, but you can only use or
4501 examine the variable @code{b} while your program is executing inside
4502 the block where @code{b} is declared.
4503
4504 @cindex variable name conflict
4505 There is an exception: you can refer to a variable or function whose
4506 scope is a single source file even if the current execution point is not
4507 in this file. But it is possible to have more than one such variable or
4508 function with the same name (in different source files). If that
4509 happens, referring to that name has unpredictable effects. If you wish,
4510 you can specify a static variable in a particular function or file,
4511 using the colon-colon notation:
4512
4513 @cindex colon-colon, context for variables/functions
4514 @iftex
4515 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
4516 @cindex @code{::}, context for variables/functions
4517 @end iftex
4518 @smallexample
4519 @var{file}::@var{variable}
4520 @var{function}::@var{variable}
4521 @end smallexample
4522
4523 @noindent
4524 Here @var{file} or @var{function} is the name of the context for the
4525 static @var{variable}. In the case of file names, you can use quotes to
4526 make sure @value{GDBN} parses the file name as a single word---for example,
4527 to print a global value of @code{x} defined in @file{f2.c}:
4528
4529 @smallexample
4530 (@value{GDBP}) p 'f2.c'::x
4531 @end smallexample
4532
4533 @cindex C@t{++} scope resolution
4534 This use of @samp{::} is very rarely in conflict with the very similar
4535 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
4536 scope resolution operator in @value{GDBN} expressions.
4537 @c FIXME: Um, so what happens in one of those rare cases where it's in
4538 @c conflict?? --mew
4539
4540 @cindex wrong values
4541 @cindex variable values, wrong
4542 @quotation
4543 @emph{Warning:} Occasionally, a local variable may appear to have the
4544 wrong value at certain points in a function---just after entry to a new
4545 scope, and just before exit.
4546 @end quotation
4547 You may see this problem when you are stepping by machine instructions.
4548 This is because, on most machines, it takes more than one instruction to
4549 set up a stack frame (including local variable definitions); if you are
4550 stepping by machine instructions, variables may appear to have the wrong
4551 values until the stack frame is completely built. On exit, it usually
4552 also takes more than one machine instruction to destroy a stack frame;
4553 after you begin stepping through that group of instructions, local
4554 variable definitions may be gone.
4555
4556 This may also happen when the compiler does significant optimizations.
4557 To be sure of always seeing accurate values, turn off all optimization
4558 when compiling.
4559
4560 @cindex ``No symbol "foo" in current context''
4561 Another possible effect of compiler optimizations is to optimize
4562 unused variables out of existence, or assign variables to registers (as
4563 opposed to memory addresses). Depending on the support for such cases
4564 offered by the debug info format used by the compiler, @value{GDBN}
4565 might not be able to display values for such local variables. If that
4566 happens, @value{GDBN} will print a message like this:
4567
4568 @smallexample
4569 No symbol "foo" in current context.
4570 @end smallexample
4571
4572 To solve such problems, either recompile without optimizations, or use a
4573 different debug info format, if the compiler supports several such
4574 formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler usually
4575 supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4576 in a format that is superior to formats such as COFF. You may be able
4577 to use DWARF2 (@samp{-gdwarf-2}), which is also an effective form for
4578 debug info. See @ref{Debugging Options,,Options for Debugging Your
4579 Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4580 information.
4581
4582
4583 @node Arrays
4584 @section Artificial arrays
4585
4586 @cindex artificial array
4587 @kindex @@@r{, referencing memory as an array}
4588 It is often useful to print out several successive objects of the
4589 same type in memory; a section of an array, or an array of
4590 dynamically determined size for which only a pointer exists in the
4591 program.
4592
4593 You can do this by referring to a contiguous span of memory as an
4594 @dfn{artificial array}, using the binary operator @samp{@@}. The left
4595 operand of @samp{@@} should be the first element of the desired array
4596 and be an individual object. The right operand should be the desired length
4597 of the array. The result is an array value whose elements are all of
4598 the type of the left argument. The first element is actually the left
4599 argument; the second element comes from bytes of memory immediately
4600 following those that hold the first element, and so on. Here is an
4601 example. If a program says
4602
4603 @smallexample
4604 int *array = (int *) malloc (len * sizeof (int));
4605 @end smallexample
4606
4607 @noindent
4608 you can print the contents of @code{array} with
4609
4610 @smallexample
4611 p *array@@len
4612 @end smallexample
4613
4614 The left operand of @samp{@@} must reside in memory. Array values made
4615 with @samp{@@} in this way behave just like other arrays in terms of
4616 subscripting, and are coerced to pointers when used in expressions.
4617 Artificial arrays most often appear in expressions via the value history
4618 (@pxref{Value History, ,Value history}), after printing one out.
4619
4620 Another way to create an artificial array is to use a cast.
4621 This re-interprets a value as if it were an array.
4622 The value need not be in memory:
4623 @smallexample
4624 (@value{GDBP}) p/x (short[2])0x12345678
4625 $1 = @{0x1234, 0x5678@}
4626 @end smallexample
4627
4628 As a convenience, if you leave the array length out (as in
4629 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
4630 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4631 @smallexample
4632 (@value{GDBP}) p/x (short[])0x12345678
4633 $2 = @{0x1234, 0x5678@}
4634 @end smallexample
4635
4636 Sometimes the artificial array mechanism is not quite enough; in
4637 moderately complex data structures, the elements of interest may not
4638 actually be adjacent---for example, if you are interested in the values
4639 of pointers in an array. One useful work-around in this situation is
4640 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4641 variables}) as a counter in an expression that prints the first
4642 interesting value, and then repeat that expression via @key{RET}. For
4643 instance, suppose you have an array @code{dtab} of pointers to
4644 structures, and you are interested in the values of a field @code{fv}
4645 in each structure. Here is an example of what you might type:
4646
4647 @smallexample
4648 set $i = 0
4649 p dtab[$i++]->fv
4650 @key{RET}
4651 @key{RET}
4652 @dots{}
4653 @end smallexample
4654
4655 @node Output Formats
4656 @section Output formats
4657
4658 @cindex formatted output
4659 @cindex output formats
4660 By default, @value{GDBN} prints a value according to its data type. Sometimes
4661 this is not what you want. For example, you might want to print a number
4662 in hex, or a pointer in decimal. Or you might want to view data in memory
4663 at a certain address as a character string or as an instruction. To do
4664 these things, specify an @dfn{output format} when you print a value.
4665
4666 The simplest use of output formats is to say how to print a value
4667 already computed. This is done by starting the arguments of the
4668 @code{print} command with a slash and a format letter. The format
4669 letters supported are:
4670
4671 @table @code
4672 @item x
4673 Regard the bits of the value as an integer, and print the integer in
4674 hexadecimal.
4675
4676 @item d
4677 Print as integer in signed decimal.
4678
4679 @item u
4680 Print as integer in unsigned decimal.
4681
4682 @item o
4683 Print as integer in octal.
4684
4685 @item t
4686 Print as integer in binary. The letter @samp{t} stands for ``two''.
4687 @footnote{@samp{b} cannot be used because these format letters are also
4688 used with the @code{x} command, where @samp{b} stands for ``byte'';
4689 see @ref{Memory,,Examining memory}.}
4690
4691 @item a
4692 @cindex unknown address, locating
4693 @cindex locate address
4694 Print as an address, both absolute in hexadecimal and as an offset from
4695 the nearest preceding symbol. You can use this format used to discover
4696 where (in what function) an unknown address is located:
4697
4698 @smallexample
4699 (@value{GDBP}) p/a 0x54320
4700 $3 = 0x54320 <_initialize_vx+396>
4701 @end smallexample
4702
4703 @noindent
4704 The command @code{info symbol 0x54320} yields similar results.
4705 @xref{Symbols, info symbol}.
4706
4707 @item c
4708 Regard as an integer and print it as a character constant.
4709
4710 @item f
4711 Regard the bits of the value as a floating point number and print
4712 using typical floating point syntax.
4713 @end table
4714
4715 For example, to print the program counter in hex (@pxref{Registers}), type
4716
4717 @smallexample
4718 p/x $pc
4719 @end smallexample
4720
4721 @noindent
4722 Note that no space is required before the slash; this is because command
4723 names in @value{GDBN} cannot contain a slash.
4724
4725 To reprint the last value in the value history with a different format,
4726 you can use the @code{print} command with just a format and no
4727 expression. For example, @samp{p/x} reprints the last value in hex.
4728
4729 @node Memory
4730 @section Examining memory
4731
4732 You can use the command @code{x} (for ``examine'') to examine memory in
4733 any of several formats, independently of your program's data types.
4734
4735 @cindex examining memory
4736 @table @code
4737 @kindex x @r{(examine memory)}
4738 @item x/@var{nfu} @var{addr}
4739 @itemx x @var{addr}
4740 @itemx x
4741 Use the @code{x} command to examine memory.
4742 @end table
4743
4744 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4745 much memory to display and how to format it; @var{addr} is an
4746 expression giving the address where you want to start displaying memory.
4747 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4748 Several commands set convenient defaults for @var{addr}.
4749
4750 @table @r
4751 @item @var{n}, the repeat count
4752 The repeat count is a decimal integer; the default is 1. It specifies
4753 how much memory (counting by units @var{u}) to display.
4754 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4755 @c 4.1.2.
4756
4757 @item @var{f}, the display format
4758 The display format is one of the formats used by @code{print},
4759 @samp{s} (null-terminated string), or @samp{i} (machine instruction).
4760 The default is @samp{x} (hexadecimal) initially.
4761 The default changes each time you use either @code{x} or @code{print}.
4762
4763 @item @var{u}, the unit size
4764 The unit size is any of
4765
4766 @table @code
4767 @item b
4768 Bytes.
4769 @item h
4770 Halfwords (two bytes).
4771 @item w
4772 Words (four bytes). This is the initial default.
4773 @item g
4774 Giant words (eight bytes).
4775 @end table
4776
4777 Each time you specify a unit size with @code{x}, that size becomes the
4778 default unit the next time you use @code{x}. (For the @samp{s} and
4779 @samp{i} formats, the unit size is ignored and is normally not written.)
4780
4781 @item @var{addr}, starting display address
4782 @var{addr} is the address where you want @value{GDBN} to begin displaying
4783 memory. The expression need not have a pointer value (though it may);
4784 it is always interpreted as an integer address of a byte of memory.
4785 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4786 @var{addr} is usually just after the last address examined---but several
4787 other commands also set the default address: @code{info breakpoints} (to
4788 the address of the last breakpoint listed), @code{info line} (to the
4789 starting address of a line), and @code{print} (if you use it to display
4790 a value from memory).
4791 @end table
4792
4793 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4794 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4795 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4796 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4797 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
4798
4799 Since the letters indicating unit sizes are all distinct from the
4800 letters specifying output formats, you do not have to remember whether
4801 unit size or format comes first; either order works. The output
4802 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4803 (However, the count @var{n} must come first; @samp{wx4} does not work.)
4804
4805 Even though the unit size @var{u} is ignored for the formats @samp{s}
4806 and @samp{i}, you might still want to use a count @var{n}; for example,
4807 @samp{3i} specifies that you want to see three machine instructions,
4808 including any operands. The command @code{disassemble} gives an
4809 alternative way of inspecting machine instructions; see @ref{Machine
4810 Code,,Source and machine code}.
4811
4812 All the defaults for the arguments to @code{x} are designed to make it
4813 easy to continue scanning memory with minimal specifications each time
4814 you use @code{x}. For example, after you have inspected three machine
4815 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4816 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4817 the repeat count @var{n} is used again; the other arguments default as
4818 for successive uses of @code{x}.
4819
4820 @cindex @code{$_}, @code{$__}, and value history
4821 The addresses and contents printed by the @code{x} command are not saved
4822 in the value history because there is often too much of them and they
4823 would get in the way. Instead, @value{GDBN} makes these values available for
4824 subsequent use in expressions as values of the convenience variables
4825 @code{$_} and @code{$__}. After an @code{x} command, the last address
4826 examined is available for use in expressions in the convenience variable
4827 @code{$_}. The contents of that address, as examined, are available in
4828 the convenience variable @code{$__}.
4829
4830 If the @code{x} command has a repeat count, the address and contents saved
4831 are from the last memory unit printed; this is not the same as the last
4832 address printed if several units were printed on the last line of output.
4833
4834 @node Auto Display
4835 @section Automatic display
4836 @cindex automatic display
4837 @cindex display of expressions
4838
4839 If you find that you want to print the value of an expression frequently
4840 (to see how it changes), you might want to add it to the @dfn{automatic
4841 display list} so that @value{GDBN} prints its value each time your program stops.
4842 Each expression added to the list is given a number to identify it;
4843 to remove an expression from the list, you specify that number.
4844 The automatic display looks like this:
4845
4846 @smallexample
4847 2: foo = 38
4848 3: bar[5] = (struct hack *) 0x3804
4849 @end smallexample
4850
4851 @noindent
4852 This display shows item numbers, expressions and their current values. As with
4853 displays you request manually using @code{x} or @code{print}, you can
4854 specify the output format you prefer; in fact, @code{display} decides
4855 whether to use @code{print} or @code{x} depending on how elaborate your
4856 format specification is---it uses @code{x} if you specify a unit size,
4857 or one of the two formats (@samp{i} and @samp{s}) that are only
4858 supported by @code{x}; otherwise it uses @code{print}.
4859
4860 @table @code
4861 @kindex display
4862 @item display @var{expr}
4863 Add the expression @var{expr} to the list of expressions to display
4864 each time your program stops. @xref{Expressions, ,Expressions}.
4865
4866 @code{display} does not repeat if you press @key{RET} again after using it.
4867
4868 @item display/@var{fmt} @var{expr}
4869 For @var{fmt} specifying only a display format and not a size or
4870 count, add the expression @var{expr} to the auto-display list but
4871 arrange to display it each time in the specified format @var{fmt}.
4872 @xref{Output Formats,,Output formats}.
4873
4874 @item display/@var{fmt} @var{addr}
4875 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4876 number of units, add the expression @var{addr} as a memory address to
4877 be examined each time your program stops. Examining means in effect
4878 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4879 @end table
4880
4881 For example, @samp{display/i $pc} can be helpful, to see the machine
4882 instruction about to be executed each time execution stops (@samp{$pc}
4883 is a common name for the program counter; @pxref{Registers, ,Registers}).
4884
4885 @table @code
4886 @kindex delete display
4887 @kindex undisplay
4888 @item undisplay @var{dnums}@dots{}
4889 @itemx delete display @var{dnums}@dots{}
4890 Remove item numbers @var{dnums} from the list of expressions to display.
4891
4892 @code{undisplay} does not repeat if you press @key{RET} after using it.
4893 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4894
4895 @kindex disable display
4896 @item disable display @var{dnums}@dots{}
4897 Disable the display of item numbers @var{dnums}. A disabled display
4898 item is not printed automatically, but is not forgotten. It may be
4899 enabled again later.
4900
4901 @kindex enable display
4902 @item enable display @var{dnums}@dots{}
4903 Enable display of item numbers @var{dnums}. It becomes effective once
4904 again in auto display of its expression, until you specify otherwise.
4905
4906 @item display
4907 Display the current values of the expressions on the list, just as is
4908 done when your program stops.
4909
4910 @kindex info display
4911 @item info display
4912 Print the list of expressions previously set up to display
4913 automatically, each one with its item number, but without showing the
4914 values. This includes disabled expressions, which are marked as such.
4915 It also includes expressions which would not be displayed right now
4916 because they refer to automatic variables not currently available.
4917 @end table
4918
4919 If a display expression refers to local variables, then it does not make
4920 sense outside the lexical context for which it was set up. Such an
4921 expression is disabled when execution enters a context where one of its
4922 variables is not defined. For example, if you give the command
4923 @code{display last_char} while inside a function with an argument
4924 @code{last_char}, @value{GDBN} displays this argument while your program
4925 continues to stop inside that function. When it stops elsewhere---where
4926 there is no variable @code{last_char}---the display is disabled
4927 automatically. The next time your program stops where @code{last_char}
4928 is meaningful, you can enable the display expression once again.
4929
4930 @node Print Settings
4931 @section Print settings
4932
4933 @cindex format options
4934 @cindex print settings
4935 @value{GDBN} provides the following ways to control how arrays, structures,
4936 and symbols are printed.
4937
4938 @noindent
4939 These settings are useful for debugging programs in any language:
4940
4941 @table @code
4942 @kindex set print address
4943 @item set print address
4944 @itemx set print address on
4945 @value{GDBN} prints memory addresses showing the location of stack
4946 traces, structure values, pointer values, breakpoints, and so forth,
4947 even when it also displays the contents of those addresses. The default
4948 is @code{on}. For example, this is what a stack frame display looks like with
4949 @code{set print address on}:
4950
4951 @smallexample
4952 @group
4953 (@value{GDBP}) f
4954 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4955 at input.c:530
4956 530 if (lquote != def_lquote)
4957 @end group
4958 @end smallexample
4959
4960 @item set print address off
4961 Do not print addresses when displaying their contents. For example,
4962 this is the same stack frame displayed with @code{set print address off}:
4963
4964 @smallexample
4965 @group
4966 (@value{GDBP}) set print addr off
4967 (@value{GDBP}) f
4968 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4969 530 if (lquote != def_lquote)
4970 @end group
4971 @end smallexample
4972
4973 You can use @samp{set print address off} to eliminate all machine
4974 dependent displays from the @value{GDBN} interface. For example, with
4975 @code{print address off}, you should get the same text for backtraces on
4976 all machines---whether or not they involve pointer arguments.
4977
4978 @kindex show print address
4979 @item show print address
4980 Show whether or not addresses are to be printed.
4981 @end table
4982
4983 When @value{GDBN} prints a symbolic address, it normally prints the
4984 closest earlier symbol plus an offset. If that symbol does not uniquely
4985 identify the address (for example, it is a name whose scope is a single
4986 source file), you may need to clarify. One way to do this is with
4987 @code{info line}, for example @samp{info line *0x4537}. Alternately,
4988 you can set @value{GDBN} to print the source file and line number when
4989 it prints a symbolic address:
4990
4991 @table @code
4992 @kindex set print symbol-filename
4993 @item set print symbol-filename on
4994 Tell @value{GDBN} to print the source file name and line number of a
4995 symbol in the symbolic form of an address.
4996
4997 @item set print symbol-filename off
4998 Do not print source file name and line number of a symbol. This is the
4999 default.
5000
5001 @kindex show print symbol-filename
5002 @item show print symbol-filename
5003 Show whether or not @value{GDBN} will print the source file name and
5004 line number of a symbol in the symbolic form of an address.
5005 @end table
5006
5007 Another situation where it is helpful to show symbol filenames and line
5008 numbers is when disassembling code; @value{GDBN} shows you the line
5009 number and source file that corresponds to each instruction.
5010
5011 Also, you may wish to see the symbolic form only if the address being
5012 printed is reasonably close to the closest earlier symbol:
5013
5014 @table @code
5015 @kindex set print max-symbolic-offset
5016 @item set print max-symbolic-offset @var{max-offset}
5017 Tell @value{GDBN} to only display the symbolic form of an address if the
5018 offset between the closest earlier symbol and the address is less than
5019 @var{max-offset}. The default is 0, which tells @value{GDBN}
5020 to always print the symbolic form of an address if any symbol precedes it.
5021
5022 @kindex show print max-symbolic-offset
5023 @item show print max-symbolic-offset
5024 Ask how large the maximum offset is that @value{GDBN} prints in a
5025 symbolic address.
5026 @end table
5027
5028 @cindex wild pointer, interpreting
5029 @cindex pointer, finding referent
5030 If you have a pointer and you are not sure where it points, try
5031 @samp{set print symbol-filename on}. Then you can determine the name
5032 and source file location of the variable where it points, using
5033 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5034 For example, here @value{GDBN} shows that a variable @code{ptt} points
5035 at another variable @code{t}, defined in @file{hi2.c}:
5036
5037 @smallexample
5038 (@value{GDBP}) set print symbol-filename on
5039 (@value{GDBP}) p/a ptt
5040 $4 = 0xe008 <t in hi2.c>
5041 @end smallexample
5042
5043 @quotation
5044 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5045 does not show the symbol name and filename of the referent, even with
5046 the appropriate @code{set print} options turned on.
5047 @end quotation
5048
5049 Other settings control how different kinds of objects are printed:
5050
5051 @table @code
5052 @kindex set print array
5053 @item set print array
5054 @itemx set print array on
5055 Pretty print arrays. This format is more convenient to read,
5056 but uses more space. The default is off.
5057
5058 @item set print array off
5059 Return to compressed format for arrays.
5060
5061 @kindex show print array
5062 @item show print array
5063 Show whether compressed or pretty format is selected for displaying
5064 arrays.
5065
5066 @kindex set print elements
5067 @item set print elements @var{number-of-elements}
5068 Set a limit on how many elements of an array @value{GDBN} will print.
5069 If @value{GDBN} is printing a large array, it stops printing after it has
5070 printed the number of elements set by the @code{set print elements} command.
5071 This limit also applies to the display of strings.
5072 When @value{GDBN} starts, this limit is set to 200.
5073 Setting @var{number-of-elements} to zero means that the printing is unlimited.
5074
5075 @kindex show print elements
5076 @item show print elements
5077 Display the number of elements of a large array that @value{GDBN} will print.
5078 If the number is 0, then the printing is unlimited.
5079
5080 @kindex set print null-stop
5081 @item set print null-stop
5082 Cause @value{GDBN} to stop printing the characters of an array when the first
5083 @sc{null} is encountered. This is useful when large arrays actually
5084 contain only short strings.
5085 The default is off.
5086
5087 @kindex set print pretty
5088 @item set print pretty on
5089 Cause @value{GDBN} to print structures in an indented format with one member
5090 per line, like this:
5091
5092 @smallexample
5093 @group
5094 $1 = @{
5095 next = 0x0,
5096 flags = @{
5097 sweet = 1,
5098 sour = 1
5099 @},
5100 meat = 0x54 "Pork"
5101 @}
5102 @end group
5103 @end smallexample
5104
5105 @item set print pretty off
5106 Cause @value{GDBN} to print structures in a compact format, like this:
5107
5108 @smallexample
5109 @group
5110 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5111 meat = 0x54 "Pork"@}
5112 @end group
5113 @end smallexample
5114
5115 @noindent
5116 This is the default format.
5117
5118 @kindex show print pretty
5119 @item show print pretty
5120 Show which format @value{GDBN} is using to print structures.
5121
5122 @kindex set print sevenbit-strings
5123 @item set print sevenbit-strings on
5124 Print using only seven-bit characters; if this option is set,
5125 @value{GDBN} displays any eight-bit characters (in strings or
5126 character values) using the notation @code{\}@var{nnn}. This setting is
5127 best if you are working in English (@sc{ascii}) and you use the
5128 high-order bit of characters as a marker or ``meta'' bit.
5129
5130 @item set print sevenbit-strings off
5131 Print full eight-bit characters. This allows the use of more
5132 international character sets, and is the default.
5133
5134 @kindex show print sevenbit-strings
5135 @item show print sevenbit-strings
5136 Show whether or not @value{GDBN} is printing only seven-bit characters.
5137
5138 @kindex set print union
5139 @item set print union on
5140 Tell @value{GDBN} to print unions which are contained in structures. This
5141 is the default setting.
5142
5143 @item set print union off
5144 Tell @value{GDBN} not to print unions which are contained in structures.
5145
5146 @kindex show print union
5147 @item show print union
5148 Ask @value{GDBN} whether or not it will print unions which are contained in
5149 structures.
5150
5151 For example, given the declarations
5152
5153 @smallexample
5154 typedef enum @{Tree, Bug@} Species;
5155 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5156 typedef enum @{Caterpillar, Cocoon, Butterfly@}
5157 Bug_forms;
5158
5159 struct thing @{
5160 Species it;
5161 union @{
5162 Tree_forms tree;
5163 Bug_forms bug;
5164 @} form;
5165 @};
5166
5167 struct thing foo = @{Tree, @{Acorn@}@};
5168 @end smallexample
5169
5170 @noindent
5171 with @code{set print union on} in effect @samp{p foo} would print
5172
5173 @smallexample
5174 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5175 @end smallexample
5176
5177 @noindent
5178 and with @code{set print union off} in effect it would print
5179
5180 @smallexample
5181 $1 = @{it = Tree, form = @{...@}@}
5182 @end smallexample
5183 @end table
5184
5185 @need 1000
5186 @noindent
5187 These settings are of interest when debugging C@t{++} programs:
5188
5189 @table @code
5190 @cindex demangling
5191 @kindex set print demangle
5192 @item set print demangle
5193 @itemx set print demangle on
5194 Print C@t{++} names in their source form rather than in the encoded
5195 (``mangled'') form passed to the assembler and linker for type-safe
5196 linkage. The default is on.
5197
5198 @kindex show print demangle
5199 @item show print demangle
5200 Show whether C@t{++} names are printed in mangled or demangled form.
5201
5202 @kindex set print asm-demangle
5203 @item set print asm-demangle
5204 @itemx set print asm-demangle on
5205 Print C@t{++} names in their source form rather than their mangled form, even
5206 in assembler code printouts such as instruction disassemblies.
5207 The default is off.
5208
5209 @kindex show print asm-demangle
5210 @item show print asm-demangle
5211 Show whether C@t{++} names in assembly listings are printed in mangled
5212 or demangled form.
5213
5214 @kindex set demangle-style
5215 @cindex C@t{++} symbol decoding style
5216 @cindex symbol decoding style, C@t{++}
5217 @item set demangle-style @var{style}
5218 Choose among several encoding schemes used by different compilers to
5219 represent C@t{++} names. The choices for @var{style} are currently:
5220
5221 @table @code
5222 @item auto
5223 Allow @value{GDBN} to choose a decoding style by inspecting your program.
5224
5225 @item gnu
5226 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
5227 This is the default.
5228
5229 @item hp
5230 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
5231
5232 @item lucid
5233 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
5234
5235 @item arm
5236 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
5237 @strong{Warning:} this setting alone is not sufficient to allow
5238 debugging @code{cfront}-generated executables. @value{GDBN} would
5239 require further enhancement to permit that.
5240
5241 @end table
5242 If you omit @var{style}, you will see a list of possible formats.
5243
5244 @kindex show demangle-style
5245 @item show demangle-style
5246 Display the encoding style currently in use for decoding C@t{++} symbols.
5247
5248 @kindex set print object
5249 @item set print object
5250 @itemx set print object on
5251 When displaying a pointer to an object, identify the @emph{actual}
5252 (derived) type of the object rather than the @emph{declared} type, using
5253 the virtual function table.
5254
5255 @item set print object off
5256 Display only the declared type of objects, without reference to the
5257 virtual function table. This is the default setting.
5258
5259 @kindex show print object
5260 @item show print object
5261 Show whether actual, or declared, object types are displayed.
5262
5263 @kindex set print static-members
5264 @item set print static-members
5265 @itemx set print static-members on
5266 Print static members when displaying a C@t{++} object. The default is on.
5267
5268 @item set print static-members off
5269 Do not print static members when displaying a C@t{++} object.
5270
5271 @kindex show print static-members
5272 @item show print static-members
5273 Show whether C@t{++} static members are printed, or not.
5274
5275 @c These don't work with HP ANSI C++ yet.
5276 @kindex set print vtbl
5277 @item set print vtbl
5278 @itemx set print vtbl on
5279 Pretty print C@t{++} virtual function tables. The default is off.
5280 (The @code{vtbl} commands do not work on programs compiled with the HP
5281 ANSI C@t{++} compiler (@code{aCC}).)
5282
5283 @item set print vtbl off
5284 Do not pretty print C@t{++} virtual function tables.
5285
5286 @kindex show print vtbl
5287 @item show print vtbl
5288 Show whether C@t{++} virtual function tables are pretty printed, or not.
5289 @end table
5290
5291 @node Value History
5292 @section Value history
5293
5294 @cindex value history
5295 Values printed by the @code{print} command are saved in the @value{GDBN}
5296 @dfn{value history}. This allows you to refer to them in other expressions.
5297 Values are kept until the symbol table is re-read or discarded
5298 (for example with the @code{file} or @code{symbol-file} commands).
5299 When the symbol table changes, the value history is discarded,
5300 since the values may contain pointers back to the types defined in the
5301 symbol table.
5302
5303 @cindex @code{$}
5304 @cindex @code{$$}
5305 @cindex history number
5306 The values printed are given @dfn{history numbers} by which you can
5307 refer to them. These are successive integers starting with one.
5308 @code{print} shows you the history number assigned to a value by
5309 printing @samp{$@var{num} = } before the value; here @var{num} is the
5310 history number.
5311
5312 To refer to any previous value, use @samp{$} followed by the value's
5313 history number. The way @code{print} labels its output is designed to
5314 remind you of this. Just @code{$} refers to the most recent value in
5315 the history, and @code{$$} refers to the value before that.
5316 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5317 is the value just prior to @code{$$}, @code{$$1} is equivalent to
5318 @code{$$}, and @code{$$0} is equivalent to @code{$}.
5319
5320 For example, suppose you have just printed a pointer to a structure and
5321 want to see the contents of the structure. It suffices to type
5322
5323 @smallexample
5324 p *$
5325 @end smallexample
5326
5327 If you have a chain of structures where the component @code{next} points
5328 to the next one, you can print the contents of the next one with this:
5329
5330 @smallexample
5331 p *$.next
5332 @end smallexample
5333
5334 @noindent
5335 You can print successive links in the chain by repeating this
5336 command---which you can do by just typing @key{RET}.
5337
5338 Note that the history records values, not expressions. If the value of
5339 @code{x} is 4 and you type these commands:
5340
5341 @smallexample
5342 print x
5343 set x=5
5344 @end smallexample
5345
5346 @noindent
5347 then the value recorded in the value history by the @code{print} command
5348 remains 4 even though the value of @code{x} has changed.
5349
5350 @table @code
5351 @kindex show values
5352 @item show values
5353 Print the last ten values in the value history, with their item numbers.
5354 This is like @samp{p@ $$9} repeated ten times, except that @code{show
5355 values} does not change the history.
5356
5357 @item show values @var{n}
5358 Print ten history values centered on history item number @var{n}.
5359
5360 @item show values +
5361 Print ten history values just after the values last printed. If no more
5362 values are available, @code{show values +} produces no display.
5363 @end table
5364
5365 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5366 same effect as @samp{show values +}.
5367
5368 @node Convenience Vars
5369 @section Convenience variables
5370
5371 @cindex convenience variables
5372 @value{GDBN} provides @dfn{convenience variables} that you can use within
5373 @value{GDBN} to hold on to a value and refer to it later. These variables
5374 exist entirely within @value{GDBN}; they are not part of your program, and
5375 setting a convenience variable has no direct effect on further execution
5376 of your program. That is why you can use them freely.
5377
5378 Convenience variables are prefixed with @samp{$}. Any name preceded by
5379 @samp{$} can be used for a convenience variable, unless it is one of
5380 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
5381 (Value history references, in contrast, are @emph{numbers} preceded
5382 by @samp{$}. @xref{Value History, ,Value history}.)
5383
5384 You can save a value in a convenience variable with an assignment
5385 expression, just as you would set a variable in your program.
5386 For example:
5387
5388 @smallexample
5389 set $foo = *object_ptr
5390 @end smallexample
5391
5392 @noindent
5393 would save in @code{$foo} the value contained in the object pointed to by
5394 @code{object_ptr}.
5395
5396 Using a convenience variable for the first time creates it, but its
5397 value is @code{void} until you assign a new value. You can alter the
5398 value with another assignment at any time.
5399
5400 Convenience variables have no fixed types. You can assign a convenience
5401 variable any type of value, including structures and arrays, even if
5402 that variable already has a value of a different type. The convenience
5403 variable, when used as an expression, has the type of its current value.
5404
5405 @table @code
5406 @kindex show convenience
5407 @item show convenience
5408 Print a list of convenience variables used so far, and their values.
5409 Abbreviated @code{show conv}.
5410 @end table
5411
5412 One of the ways to use a convenience variable is as a counter to be
5413 incremented or a pointer to be advanced. For example, to print
5414 a field from successive elements of an array of structures:
5415
5416 @smallexample
5417 set $i = 0
5418 print bar[$i++]->contents
5419 @end smallexample
5420
5421 @noindent
5422 Repeat that command by typing @key{RET}.
5423
5424 Some convenience variables are created automatically by @value{GDBN} and given
5425 values likely to be useful.
5426
5427 @table @code
5428 @vindex $_@r{, convenience variable}
5429 @item $_
5430 The variable @code{$_} is automatically set by the @code{x} command to
5431 the last address examined (@pxref{Memory, ,Examining memory}). Other
5432 commands which provide a default address for @code{x} to examine also
5433 set @code{$_} to that address; these commands include @code{info line}
5434 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5435 except when set by the @code{x} command, in which case it is a pointer
5436 to the type of @code{$__}.
5437
5438 @vindex $__@r{, convenience variable}
5439 @item $__
5440 The variable @code{$__} is automatically set by the @code{x} command
5441 to the value found in the last address examined. Its type is chosen
5442 to match the format in which the data was printed.
5443
5444 @item $_exitcode
5445 @vindex $_exitcode@r{, convenience variable}
5446 The variable @code{$_exitcode} is automatically set to the exit code when
5447 the program being debugged terminates.
5448 @end table
5449
5450 On HP-UX systems, if you refer to a function or variable name that
5451 begins with a dollar sign, @value{GDBN} searches for a user or system
5452 name first, before it searches for a convenience variable.
5453
5454 @node Registers
5455 @section Registers
5456
5457 @cindex registers
5458 You can refer to machine register contents, in expressions, as variables
5459 with names starting with @samp{$}. The names of registers are different
5460 for each machine; use @code{info registers} to see the names used on
5461 your machine.
5462
5463 @table @code
5464 @kindex info registers
5465 @item info registers
5466 Print the names and values of all registers except floating-point
5467 registers (in the selected stack frame).
5468
5469 @kindex info all-registers
5470 @cindex floating point registers
5471 @item info all-registers
5472 Print the names and values of all registers, including floating-point
5473 registers.
5474
5475 @item info registers @var{regname} @dots{}
5476 Print the @dfn{relativized} value of each specified register @var{regname}.
5477 As discussed in detail below, register values are normally relative to
5478 the selected stack frame. @var{regname} may be any register name valid on
5479 the machine you are using, with or without the initial @samp{$}.
5480 @end table
5481
5482 @value{GDBN} has four ``standard'' register names that are available (in
5483 expressions) on most machines---whenever they do not conflict with an
5484 architecture's canonical mnemonics for registers. The register names
5485 @code{$pc} and @code{$sp} are used for the program counter register and
5486 the stack pointer. @code{$fp} is used for a register that contains a
5487 pointer to the current stack frame, and @code{$ps} is used for a
5488 register that contains the processor status. For example,
5489 you could print the program counter in hex with
5490
5491 @smallexample
5492 p/x $pc
5493 @end smallexample
5494
5495 @noindent
5496 or print the instruction to be executed next with
5497
5498 @smallexample
5499 x/i $pc
5500 @end smallexample
5501
5502 @noindent
5503 or add four to the stack pointer@footnote{This is a way of removing
5504 one word from the stack, on machines where stacks grow downward in
5505 memory (most machines, nowadays). This assumes that the innermost
5506 stack frame is selected; setting @code{$sp} is not allowed when other
5507 stack frames are selected. To pop entire frames off the stack,
5508 regardless of machine architecture, use @code{return};
5509 see @ref{Returning, ,Returning from a function}.} with
5510
5511 @smallexample
5512 set $sp += 4
5513 @end smallexample
5514
5515 Whenever possible, these four standard register names are available on
5516 your machine even though the machine has different canonical mnemonics,
5517 so long as there is no conflict. The @code{info registers} command
5518 shows the canonical names. For example, on the SPARC, @code{info
5519 registers} displays the processor status register as @code{$psr} but you
5520 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5521 is an alias for the @sc{eflags} register.
5522
5523 @value{GDBN} always considers the contents of an ordinary register as an
5524 integer when the register is examined in this way. Some machines have
5525 special registers which can hold nothing but floating point; these
5526 registers are considered to have floating point values. There is no way
5527 to refer to the contents of an ordinary register as floating point value
5528 (although you can @emph{print} it as a floating point value with
5529 @samp{print/f $@var{regname}}).
5530
5531 Some registers have distinct ``raw'' and ``virtual'' data formats. This
5532 means that the data format in which the register contents are saved by
5533 the operating system is not the same one that your program normally
5534 sees. For example, the registers of the 68881 floating point
5535 coprocessor are always saved in ``extended'' (raw) format, but all C
5536 programs expect to work with ``double'' (virtual) format. In such
5537 cases, @value{GDBN} normally works with the virtual format only (the format
5538 that makes sense for your program), but the @code{info registers} command
5539 prints the data in both formats.
5540
5541 Normally, register values are relative to the selected stack frame
5542 (@pxref{Selection, ,Selecting a frame}). This means that you get the
5543 value that the register would contain if all stack frames farther in
5544 were exited and their saved registers restored. In order to see the
5545 true contents of hardware registers, you must select the innermost
5546 frame (with @samp{frame 0}).
5547
5548 However, @value{GDBN} must deduce where registers are saved, from the machine
5549 code generated by your compiler. If some registers are not saved, or if
5550 @value{GDBN} is unable to locate the saved registers, the selected stack
5551 frame makes no difference.
5552
5553 @node Floating Point Hardware
5554 @section Floating point hardware
5555 @cindex floating point
5556
5557 Depending on the configuration, @value{GDBN} may be able to give
5558 you more information about the status of the floating point hardware.
5559
5560 @table @code
5561 @kindex info float
5562 @item info float
5563 Display hardware-dependent information about the floating
5564 point unit. The exact contents and layout vary depending on the
5565 floating point chip. Currently, @samp{info float} is supported on
5566 the ARM and x86 machines.
5567 @end table
5568
5569 @node Memory Region Attributes
5570 @section Memory Region Attributes
5571 @cindex memory region attributes
5572
5573 @dfn{Memory region attributes} allow you to describe special handling
5574 required by regions of your target's memory. @value{GDBN} uses attributes
5575 to determine whether to allow certain types of memory accesses; whether to
5576 use specific width accesses; and whether to cache target memory.
5577
5578 Defined memory regions can be individually enabled and disabled. When a
5579 memory region is disabled, @value{GDBN} uses the default attributes when
5580 accessing memory in that region. Similarly, if no memory regions have
5581 been defined, @value{GDBN} uses the default attributes when accessing
5582 all memory.
5583
5584 When a memory region is defined, it is given a number to identify it;
5585 to enable, disable, or remove a memory region, you specify that number.
5586
5587 @table @code
5588 @kindex mem
5589 @item mem @var{address1} @var{address2} @var{attributes}@dots{}
5590 Define memory region bounded by @var{address1} and @var{address2}
5591 with attributes @var{attributes}@dots{}.
5592
5593 @kindex delete mem
5594 @item delete mem @var{nums}@dots{}
5595 Remove memory regions @var{nums}@dots{}.
5596
5597 @kindex disable mem
5598 @item disable mem @var{nums}@dots{}
5599 Disable memory regions @var{nums}@dots{}.
5600 A disabled memory region is not forgotten.
5601 It may be enabled again later.
5602
5603 @kindex enable mem
5604 @item enable mem @var{nums}@dots{}
5605 Enable memory regions @var{nums}@dots{}.
5606
5607 @kindex info mem
5608 @item info mem
5609 Print a table of all defined memory regions, with the following columns
5610 for each region.
5611
5612 @table @emph
5613 @item Memory Region Number
5614 @item Enabled or Disabled.
5615 Enabled memory regions are marked with @samp{y}.
5616 Disabled memory regions are marked with @samp{n}.
5617
5618 @item Lo Address
5619 The address defining the inclusive lower bound of the memory region.
5620
5621 @item Hi Address
5622 The address defining the exclusive upper bound of the memory region.
5623
5624 @item Attributes
5625 The list of attributes set for this memory region.
5626 @end table
5627 @end table
5628
5629
5630 @subsection Attributes
5631
5632 @subsubsection Memory Access Mode
5633 The access mode attributes set whether @value{GDBN} may make read or
5634 write accesses to a memory region.
5635
5636 While these attributes prevent @value{GDBN} from performing invalid
5637 memory accesses, they do nothing to prevent the target system, I/O DMA,
5638 etc. from accessing memory.
5639
5640 @table @code
5641 @item ro
5642 Memory is read only.
5643 @item wo
5644 Memory is write only.
5645 @item rw
5646 Memory is read/write. This is the default.
5647 @end table
5648
5649 @subsubsection Memory Access Size
5650 The acccess size attributes tells @value{GDBN} to use specific sized
5651 accesses in the memory region. Often memory mapped device registers
5652 require specific sized accesses. If no access size attribute is
5653 specified, @value{GDBN} may use accesses of any size.
5654
5655 @table @code
5656 @item 8
5657 Use 8 bit memory accesses.
5658 @item 16
5659 Use 16 bit memory accesses.
5660 @item 32
5661 Use 32 bit memory accesses.
5662 @item 64
5663 Use 64 bit memory accesses.
5664 @end table
5665
5666 @c @subsubsection Hardware/Software Breakpoints
5667 @c The hardware/software breakpoint attributes set whether @value{GDBN}
5668 @c will use hardware or software breakpoints for the internal breakpoints
5669 @c used by the step, next, finish, until, etc. commands.
5670 @c
5671 @c @table @code
5672 @c @item hwbreak
5673 @c Always use hardware breakpoints
5674 @c @item swbreak (default)
5675 @c @end table
5676
5677 @subsubsection Data Cache
5678 The data cache attributes set whether @value{GDBN} will cache target
5679 memory. While this generally improves performance by reducing debug
5680 protocol overhead, it can lead to incorrect results because @value{GDBN}
5681 does not know about volatile variables or memory mapped device
5682 registers.
5683
5684 @table @code
5685 @item cache
5686 Enable @value{GDBN} to cache target memory.
5687 @item nocache
5688 Disable @value{GDBN} from caching target memory. This is the default.
5689 @end table
5690
5691 @c @subsubsection Memory Write Verification
5692 @c The memory write verification attributes set whether @value{GDBN}
5693 @c will re-reads data after each write to verify the write was successful.
5694 @c
5695 @c @table @code
5696 @c @item verify
5697 @c @item noverify (default)
5698 @c @end table
5699
5700 @node Tracepoints
5701 @chapter Tracepoints
5702 @c This chapter is based on the documentation written by Michael
5703 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
5704
5705 @cindex tracepoints
5706 In some applications, it is not feasible for the debugger to interrupt
5707 the program's execution long enough for the developer to learn
5708 anything helpful about its behavior. If the program's correctness
5709 depends on its real-time behavior, delays introduced by a debugger
5710 might cause the program to change its behavior drastically, or perhaps
5711 fail, even when the code itself is correct. It is useful to be able
5712 to observe the program's behavior without interrupting it.
5713
5714 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
5715 specify locations in the program, called @dfn{tracepoints}, and
5716 arbitrary expressions to evaluate when those tracepoints are reached.
5717 Later, using the @code{tfind} command, you can examine the values
5718 those expressions had when the program hit the tracepoints. The
5719 expressions may also denote objects in memory---structures or arrays,
5720 for example---whose values @value{GDBN} should record; while visiting
5721 a particular tracepoint, you may inspect those objects as if they were
5722 in memory at that moment. However, because @value{GDBN} records these
5723 values without interacting with you, it can do so quickly and
5724 unobtrusively, hopefully not disturbing the program's behavior.
5725
5726 The tracepoint facility is currently available only for remote
5727 targets. @xref{Targets}. In addition, your remote target must know how
5728 to collect trace data. This functionality is implemented in the remote
5729 stub; however, none of the stubs distributed with @value{GDBN} support
5730 tracepoints as of this writing.
5731
5732 This chapter describes the tracepoint commands and features.
5733
5734 @menu
5735 * Set Tracepoints::
5736 * Analyze Collected Data::
5737 * Tracepoint Variables::
5738 @end menu
5739
5740 @node Set Tracepoints
5741 @section Commands to Set Tracepoints
5742
5743 Before running such a @dfn{trace experiment}, an arbitrary number of
5744 tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
5745 tracepoint has a number assigned to it by @value{GDBN}. Like with
5746 breakpoints, tracepoint numbers are successive integers starting from
5747 one. Many of the commands associated with tracepoints take the
5748 tracepoint number as their argument, to identify which tracepoint to
5749 work on.
5750
5751 For each tracepoint, you can specify, in advance, some arbitrary set
5752 of data that you want the target to collect in the trace buffer when
5753 it hits that tracepoint. The collected data can include registers,
5754 local variables, or global data. Later, you can use @value{GDBN}
5755 commands to examine the values these data had at the time the
5756 tracepoint was hit.
5757
5758 This section describes commands to set tracepoints and associated
5759 conditions and actions.
5760
5761 @menu
5762 * Create and Delete Tracepoints::
5763 * Enable and Disable Tracepoints::
5764 * Tracepoint Passcounts::
5765 * Tracepoint Actions::
5766 * Listing Tracepoints::
5767 * Starting and Stopping Trace Experiment::
5768 @end menu
5769
5770 @node Create and Delete Tracepoints
5771 @subsection Create and Delete Tracepoints
5772
5773 @table @code
5774 @cindex set tracepoint
5775 @kindex trace
5776 @item trace
5777 The @code{trace} command is very similar to the @code{break} command.
5778 Its argument can be a source line, a function name, or an address in
5779 the target program. @xref{Set Breaks}. The @code{trace} command
5780 defines a tracepoint, which is a point in the target program where the
5781 debugger will briefly stop, collect some data, and then allow the
5782 program to continue. Setting a tracepoint or changing its commands
5783 doesn't take effect until the next @code{tstart} command; thus, you
5784 cannot change the tracepoint attributes once a trace experiment is
5785 running.
5786
5787 Here are some examples of using the @code{trace} command:
5788
5789 @smallexample
5790 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
5791
5792 (@value{GDBP}) @b{trace +2} // 2 lines forward
5793
5794 (@value{GDBP}) @b{trace my_function} // first source line of function
5795
5796 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
5797
5798 (@value{GDBP}) @b{trace *0x2117c4} // an address
5799 @end smallexample
5800
5801 @noindent
5802 You can abbreviate @code{trace} as @code{tr}.
5803
5804 @vindex $tpnum
5805 @cindex last tracepoint number
5806 @cindex recent tracepoint number
5807 @cindex tracepoint number
5808 The convenience variable @code{$tpnum} records the tracepoint number
5809 of the most recently set tracepoint.
5810
5811 @kindex delete tracepoint
5812 @cindex tracepoint deletion
5813 @item delete tracepoint @r{[}@var{num}@r{]}
5814 Permanently delete one or more tracepoints. With no argument, the
5815 default is to delete all tracepoints.
5816
5817 Examples:
5818
5819 @smallexample
5820 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
5821
5822 (@value{GDBP}) @b{delete trace} // remove all tracepoints
5823 @end smallexample
5824
5825 @noindent
5826 You can abbreviate this command as @code{del tr}.
5827 @end table
5828
5829 @node Enable and Disable Tracepoints
5830 @subsection Enable and Disable Tracepoints
5831
5832 @table @code
5833 @kindex disable tracepoint
5834 @item disable tracepoint @r{[}@var{num}@r{]}
5835 Disable tracepoint @var{num}, or all tracepoints if no argument
5836 @var{num} is given. A disabled tracepoint will have no effect during
5837 the next trace experiment, but it is not forgotten. You can re-enable
5838 a disabled tracepoint using the @code{enable tracepoint} command.
5839
5840 @kindex enable tracepoint
5841 @item enable tracepoint @r{[}@var{num}@r{]}
5842 Enable tracepoint @var{num}, or all tracepoints. The enabled
5843 tracepoints will become effective the next time a trace experiment is
5844 run.
5845 @end table
5846
5847 @node Tracepoint Passcounts
5848 @subsection Tracepoint Passcounts
5849
5850 @table @code
5851 @kindex passcount
5852 @cindex tracepoint pass count
5853 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
5854 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
5855 automatically stop a trace experiment. If a tracepoint's passcount is
5856 @var{n}, then the trace experiment will be automatically stopped on
5857 the @var{n}'th time that tracepoint is hit. If the tracepoint number
5858 @var{num} is not specified, the @code{passcount} command sets the
5859 passcount of the most recently defined tracepoint. If no passcount is
5860 given, the trace experiment will run until stopped explicitly by the
5861 user.
5862
5863 Examples:
5864
5865 @smallexample
5866 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
5867 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
5868
5869 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
5870 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
5871 (@value{GDBP}) @b{trace foo}
5872 (@value{GDBP}) @b{pass 3}
5873 (@value{GDBP}) @b{trace bar}
5874 (@value{GDBP}) @b{pass 2}
5875 (@value{GDBP}) @b{trace baz}
5876 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
5877 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
5878 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
5879 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
5880 @end smallexample
5881 @end table
5882
5883 @node Tracepoint Actions
5884 @subsection Tracepoint Action Lists
5885
5886 @table @code
5887 @kindex actions
5888 @cindex tracepoint actions
5889 @item actions @r{[}@var{num}@r{]}
5890 This command will prompt for a list of actions to be taken when the
5891 tracepoint is hit. If the tracepoint number @var{num} is not
5892 specified, this command sets the actions for the one that was most
5893 recently defined (so that you can define a tracepoint and then say
5894 @code{actions} without bothering about its number). You specify the
5895 actions themselves on the following lines, one action at a time, and
5896 terminate the actions list with a line containing just @code{end}. So
5897 far, the only defined actions are @code{collect} and
5898 @code{while-stepping}.
5899
5900 @cindex remove actions from a tracepoint
5901 To remove all actions from a tracepoint, type @samp{actions @var{num}}
5902 and follow it immediately with @samp{end}.
5903
5904 @smallexample
5905 (@value{GDBP}) @b{collect @var{data}} // collect some data
5906
5907 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
5908
5909 (@value{GDBP}) @b{end} // signals the end of actions.
5910 @end smallexample
5911
5912 In the following example, the action list begins with @code{collect}
5913 commands indicating the things to be collected when the tracepoint is
5914 hit. Then, in order to single-step and collect additional data
5915 following the tracepoint, a @code{while-stepping} command is used,
5916 followed by the list of things to be collected while stepping. The
5917 @code{while-stepping} command is terminated by its own separate
5918 @code{end} command. Lastly, the action list is terminated by an
5919 @code{end} command.
5920
5921 @smallexample
5922 (@value{GDBP}) @b{trace foo}
5923 (@value{GDBP}) @b{actions}
5924 Enter actions for tracepoint 1, one per line:
5925 > collect bar,baz
5926 > collect $regs
5927 > while-stepping 12
5928 > collect $fp, $sp
5929 > end
5930 end
5931 @end smallexample
5932
5933 @kindex collect @r{(tracepoints)}
5934 @item collect @var{expr1}, @var{expr2}, @dots{}
5935 Collect values of the given expressions when the tracepoint is hit.
5936 This command accepts a comma-separated list of any valid expressions.
5937 In addition to global, static, or local variables, the following
5938 special arguments are supported:
5939
5940 @table @code
5941 @item $regs
5942 collect all registers
5943
5944 @item $args
5945 collect all function arguments
5946
5947 @item $locals
5948 collect all local variables.
5949 @end table
5950
5951 You can give several consecutive @code{collect} commands, each one
5952 with a single argument, or one @code{collect} command with several
5953 arguments separated by commas: the effect is the same.
5954
5955 The command @code{info scope} (@pxref{Symbols, info scope}) is
5956 particularly useful for figuring out what data to collect.
5957
5958 @kindex while-stepping @r{(tracepoints)}
5959 @item while-stepping @var{n}
5960 Perform @var{n} single-step traces after the tracepoint, collecting
5961 new data at each step. The @code{while-stepping} command is
5962 followed by the list of what to collect while stepping (followed by
5963 its own @code{end} command):
5964
5965 @smallexample
5966 > while-stepping 12
5967 > collect $regs, myglobal
5968 > end
5969 >
5970 @end smallexample
5971
5972 @noindent
5973 You may abbreviate @code{while-stepping} as @code{ws} or
5974 @code{stepping}.
5975 @end table
5976
5977 @node Listing Tracepoints
5978 @subsection Listing Tracepoints
5979
5980 @table @code
5981 @kindex info tracepoints
5982 @cindex information about tracepoints
5983 @item info tracepoints @r{[}@var{num}@r{]}
5984 Display information about the tracepoint @var{num}. If you don't specify
5985 a tracepoint number, displays information about all the tracepoints
5986 defined so far. For each tracepoint, the following information is
5987 shown:
5988
5989 @itemize @bullet
5990 @item
5991 its number
5992 @item
5993 whether it is enabled or disabled
5994 @item
5995 its address
5996 @item
5997 its passcount as given by the @code{passcount @var{n}} command
5998 @item
5999 its step count as given by the @code{while-stepping @var{n}} command
6000 @item
6001 where in the source files is the tracepoint set
6002 @item
6003 its action list as given by the @code{actions} command
6004 @end itemize
6005
6006 @smallexample
6007 (@value{GDBP}) @b{info trace}
6008 Num Enb Address PassC StepC What
6009 1 y 0x002117c4 0 0 <gdb_asm>
6010 2 y 0x0020dc64 0 0 in g_test at g_test.c:1375
6011 3 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
6012 (@value{GDBP})
6013 @end smallexample
6014
6015 @noindent
6016 This command can be abbreviated @code{info tp}.
6017 @end table
6018
6019 @node Starting and Stopping Trace Experiment
6020 @subsection Starting and Stopping Trace Experiment
6021
6022 @table @code
6023 @kindex tstart
6024 @cindex start a new trace experiment
6025 @cindex collected data discarded
6026 @item tstart
6027 This command takes no arguments. It starts the trace experiment, and
6028 begins collecting data. This has the side effect of discarding all
6029 the data collected in the trace buffer during the previous trace
6030 experiment.
6031
6032 @kindex tstop
6033 @cindex stop a running trace experiment
6034 @item tstop
6035 This command takes no arguments. It ends the trace experiment, and
6036 stops collecting data.
6037
6038 @strong{Note:} a trace experiment and data collection may stop
6039 automatically if any tracepoint's passcount is reached
6040 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
6041
6042 @kindex tstatus
6043 @cindex status of trace data collection
6044 @cindex trace experiment, status of
6045 @item tstatus
6046 This command displays the status of the current trace data
6047 collection.
6048 @end table
6049
6050 Here is an example of the commands we described so far:
6051
6052 @smallexample
6053 (@value{GDBP}) @b{trace gdb_c_test}
6054 (@value{GDBP}) @b{actions}
6055 Enter actions for tracepoint #1, one per line.
6056 > collect $regs,$locals,$args
6057 > while-stepping 11
6058 > collect $regs
6059 > end
6060 > end
6061 (@value{GDBP}) @b{tstart}
6062 [time passes @dots{}]
6063 (@value{GDBP}) @b{tstop}
6064 @end smallexample
6065
6066
6067 @node Analyze Collected Data
6068 @section Using the collected data
6069
6070 After the tracepoint experiment ends, you use @value{GDBN} commands
6071 for examining the trace data. The basic idea is that each tracepoint
6072 collects a trace @dfn{snapshot} every time it is hit and another
6073 snapshot every time it single-steps. All these snapshots are
6074 consecutively numbered from zero and go into a buffer, and you can
6075 examine them later. The way you examine them is to @dfn{focus} on a
6076 specific trace snapshot. When the remote stub is focused on a trace
6077 snapshot, it will respond to all @value{GDBN} requests for memory and
6078 registers by reading from the buffer which belongs to that snapshot,
6079 rather than from @emph{real} memory or registers of the program being
6080 debugged. This means that @strong{all} @value{GDBN} commands
6081 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
6082 behave as if we were currently debugging the program state as it was
6083 when the tracepoint occurred. Any requests for data that are not in
6084 the buffer will fail.
6085
6086 @menu
6087 * tfind:: How to select a trace snapshot
6088 * tdump:: How to display all data for a snapshot
6089 * save-tracepoints:: How to save tracepoints for a future run
6090 @end menu
6091
6092 @node tfind
6093 @subsection @code{tfind @var{n}}
6094
6095 @kindex tfind
6096 @cindex select trace snapshot
6097 @cindex find trace snapshot
6098 The basic command for selecting a trace snapshot from the buffer is
6099 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
6100 counting from zero. If no argument @var{n} is given, the next
6101 snapshot is selected.
6102
6103 Here are the various forms of using the @code{tfind} command.
6104
6105 @table @code
6106 @item tfind start
6107 Find the first snapshot in the buffer. This is a synonym for
6108 @code{tfind 0} (since 0 is the number of the first snapshot).
6109
6110 @item tfind none
6111 Stop debugging trace snapshots, resume @emph{live} debugging.
6112
6113 @item tfind end
6114 Same as @samp{tfind none}.
6115
6116 @item tfind
6117 No argument means find the next trace snapshot.
6118
6119 @item tfind -
6120 Find the previous trace snapshot before the current one. This permits
6121 retracing earlier steps.
6122
6123 @item tfind tracepoint @var{num}
6124 Find the next snapshot associated with tracepoint @var{num}. Search
6125 proceeds forward from the last examined trace snapshot. If no
6126 argument @var{num} is given, it means find the next snapshot collected
6127 for the same tracepoint as the current snapshot.
6128
6129 @item tfind pc @var{addr}
6130 Find the next snapshot associated with the value @var{addr} of the
6131 program counter. Search proceeds forward from the last examined trace
6132 snapshot. If no argument @var{addr} is given, it means find the next
6133 snapshot with the same value of PC as the current snapshot.
6134
6135 @item tfind outside @var{addr1}, @var{addr2}
6136 Find the next snapshot whose PC is outside the given range of
6137 addresses.
6138
6139 @item tfind range @var{addr1}, @var{addr2}
6140 Find the next snapshot whose PC is between @var{addr1} and
6141 @var{addr2}. @c FIXME: Is the range inclusive or exclusive?
6142
6143 @item tfind line @r{[}@var{file}:@r{]}@var{n}
6144 Find the next snapshot associated with the source line @var{n}. If
6145 the optional argument @var{file} is given, refer to line @var{n} in
6146 that source file. Search proceeds forward from the last examined
6147 trace snapshot. If no argument @var{n} is given, it means find the
6148 next line other than the one currently being examined; thus saying
6149 @code{tfind line} repeatedly can appear to have the same effect as
6150 stepping from line to line in a @emph{live} debugging session.
6151 @end table
6152
6153 The default arguments for the @code{tfind} commands are specifically
6154 designed to make it easy to scan through the trace buffer. For
6155 instance, @code{tfind} with no argument selects the next trace
6156 snapshot, and @code{tfind -} with no argument selects the previous
6157 trace snapshot. So, by giving one @code{tfind} command, and then
6158 simply hitting @key{RET} repeatedly you can examine all the trace
6159 snapshots in order. Or, by saying @code{tfind -} and then hitting
6160 @key{RET} repeatedly you can examine the snapshots in reverse order.
6161 The @code{tfind line} command with no argument selects the snapshot
6162 for the next source line executed. The @code{tfind pc} command with
6163 no argument selects the next snapshot with the same program counter
6164 (PC) as the current frame. The @code{tfind tracepoint} command with
6165 no argument selects the next trace snapshot collected by the same
6166 tracepoint as the current one.
6167
6168 In addition to letting you scan through the trace buffer manually,
6169 these commands make it easy to construct @value{GDBN} scripts that
6170 scan through the trace buffer and print out whatever collected data
6171 you are interested in. Thus, if we want to examine the PC, FP, and SP
6172 registers from each trace frame in the buffer, we can say this:
6173
6174 @smallexample
6175 (@value{GDBP}) @b{tfind start}
6176 (@value{GDBP}) @b{while ($trace_frame != -1)}
6177 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6178 $trace_frame, $pc, $sp, $fp
6179 > tfind
6180 > end
6181
6182 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6183 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6184 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6185 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6186 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6187 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6188 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6189 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6190 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6191 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6192 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6193 @end smallexample
6194
6195 Or, if we want to examine the variable @code{X} at each source line in
6196 the buffer:
6197
6198 @smallexample
6199 (@value{GDBP}) @b{tfind start}
6200 (@value{GDBP}) @b{while ($trace_frame != -1)}
6201 > printf "Frame %d, X == %d\n", $trace_frame, X
6202 > tfind line
6203 > end
6204
6205 Frame 0, X = 1
6206 Frame 7, X = 2
6207 Frame 13, X = 255
6208 @end smallexample
6209
6210 @node tdump
6211 @subsection @code{tdump}
6212 @kindex tdump
6213 @cindex dump all data collected at tracepoint
6214 @cindex tracepoint data, display
6215
6216 This command takes no arguments. It prints all the data collected at
6217 the current trace snapshot.
6218
6219 @smallexample
6220 (@value{GDBP}) @b{trace 444}
6221 (@value{GDBP}) @b{actions}
6222 Enter actions for tracepoint #2, one per line:
6223 > collect $regs, $locals, $args, gdb_long_test
6224 > end
6225
6226 (@value{GDBP}) @b{tstart}
6227
6228 (@value{GDBP}) @b{tfind line 444}
6229 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
6230 at gdb_test.c:444
6231 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
6232
6233 (@value{GDBP}) @b{tdump}
6234 Data collected at tracepoint 2, trace frame 1:
6235 d0 0xc4aa0085 -995491707
6236 d1 0x18 24
6237 d2 0x80 128
6238 d3 0x33 51
6239 d4 0x71aea3d 119204413
6240 d5 0x22 34
6241 d6 0xe0 224
6242 d7 0x380035 3670069
6243 a0 0x19e24a 1696330
6244 a1 0x3000668 50333288
6245 a2 0x100 256
6246 a3 0x322000 3284992
6247 a4 0x3000698 50333336
6248 a5 0x1ad3cc 1758156
6249 fp 0x30bf3c 0x30bf3c
6250 sp 0x30bf34 0x30bf34
6251 ps 0x0 0
6252 pc 0x20b2c8 0x20b2c8
6253 fpcontrol 0x0 0
6254 fpstatus 0x0 0
6255 fpiaddr 0x0 0
6256 p = 0x20e5b4 "gdb-test"
6257 p1 = (void *) 0x11
6258 p2 = (void *) 0x22
6259 p3 = (void *) 0x33
6260 p4 = (void *) 0x44
6261 p5 = (void *) 0x55
6262 p6 = (void *) 0x66
6263 gdb_long_test = 17 '\021'
6264
6265 (@value{GDBP})
6266 @end smallexample
6267
6268 @node save-tracepoints
6269 @subsection @code{save-tracepoints @var{filename}}
6270 @kindex save-tracepoints
6271 @cindex save tracepoints for future sessions
6272
6273 This command saves all current tracepoint definitions together with
6274 their actions and passcounts, into a file @file{@var{filename}}
6275 suitable for use in a later debugging session. To read the saved
6276 tracepoint definitions, use the @code{source} command (@pxref{Command
6277 Files}).
6278
6279 @node Tracepoint Variables
6280 @section Convenience Variables for Tracepoints
6281 @cindex tracepoint variables
6282 @cindex convenience variables for tracepoints
6283
6284 @table @code
6285 @vindex $trace_frame
6286 @item (int) $trace_frame
6287 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
6288 snapshot is selected.
6289
6290 @vindex $tracepoint
6291 @item (int) $tracepoint
6292 The tracepoint for the current trace snapshot.
6293
6294 @vindex $trace_line
6295 @item (int) $trace_line
6296 The line number for the current trace snapshot.
6297
6298 @vindex $trace_file
6299 @item (char []) $trace_file
6300 The source file for the current trace snapshot.
6301
6302 @vindex $trace_func
6303 @item (char []) $trace_func
6304 The name of the function containing @code{$tracepoint}.
6305 @end table
6306
6307 Note: @code{$trace_file} is not suitable for use in @code{printf},
6308 use @code{output} instead.
6309
6310 Here's a simple example of using these convenience variables for
6311 stepping through all the trace snapshots and printing some of their
6312 data.
6313
6314 @smallexample
6315 (@value{GDBP}) @b{tfind start}
6316
6317 (@value{GDBP}) @b{while $trace_frame != -1}
6318 > output $trace_file
6319 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
6320 > tfind
6321 > end
6322 @end smallexample
6323
6324 @node Overlays
6325 @chapter Debugging Programs That Use Overlays
6326 @cindex overlays
6327
6328 If your program is too large to fit completely in your target system's
6329 memory, you can sometimes use @dfn{overlays} to work around this
6330 problem. @value{GDBN} provides some support for debugging programs that
6331 use overlays.
6332
6333 @menu
6334 * How Overlays Work:: A general explanation of overlays.
6335 * Overlay Commands:: Managing overlays in @value{GDBN}.
6336 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
6337 mapped by asking the inferior.
6338 * Overlay Sample Program:: A sample program using overlays.
6339 @end menu
6340
6341 @node How Overlays Work
6342 @section How Overlays Work
6343 @cindex mapped overlays
6344 @cindex unmapped overlays
6345 @cindex load address, overlay's
6346 @cindex mapped address
6347 @cindex overlay area
6348
6349 Suppose you have a computer whose instruction address space is only 64
6350 kilobytes long, but which has much more memory which can be accessed by
6351 other means: special instructions, segment registers, or memory
6352 management hardware, for example. Suppose further that you want to
6353 adapt a program which is larger than 64 kilobytes to run on this system.
6354
6355 One solution is to identify modules of your program which are relatively
6356 independent, and need not call each other directly; call these modules
6357 @dfn{overlays}. Separate the overlays from the main program, and place
6358 their machine code in the larger memory. Place your main program in
6359 instruction memory, but leave at least enough space there to hold the
6360 largest overlay as well.
6361
6362 Now, to call a function located in an overlay, you must first copy that
6363 overlay's machine code from the large memory into the space set aside
6364 for it in the instruction memory, and then jump to its entry point
6365 there.
6366
6367 @c NB: In the below the mapped area's size is greater or equal to the
6368 @c size of all overlays. This is intentional to remind the developer
6369 @c that overlays don't necessarily need to be the same size.
6370
6371 @smallexample
6372 @group
6373 Data Instruction Larger
6374 Address Space Address Space Address Space
6375 +-----------+ +-----------+ +-----------+
6376 | | | | | |
6377 +-----------+ +-----------+ +-----------+<-- overlay 1
6378 | program | | main | .----| overlay 1 | load address
6379 | variables | | program | | +-----------+
6380 | and heap | | | | | |
6381 +-----------+ | | | +-----------+<-- overlay 2
6382 | | +-----------+ | | | load address
6383 +-----------+ | | | .-| overlay 2 |
6384 | | | | | |
6385 mapped --->+-----------+ | | +-----------+
6386 address | | | | | |
6387 | overlay | <-' | | |
6388 | area | <---' +-----------+<-- overlay 3
6389 | | <---. | | load address
6390 +-----------+ `--| overlay 3 |
6391 | | | |
6392 +-----------+ | |
6393 +-----------+
6394 | |
6395 +-----------+
6396
6397 @anchor{A code overlay}A code overlay
6398 @end group
6399 @end smallexample
6400
6401 The diagram (@pxref{A code overlay}) shows a system with separate data
6402 and instruction address spaces. To map an overlay, the program copies
6403 its code from the larger address space to the instruction address space.
6404 Since the overlays shown here all use the same mapped address, only one
6405 may be mapped at a time. For a system with a single address space for
6406 data and instructions, the diagram would be similar, except that the
6407 program variables and heap would share an address space with the main
6408 program and the overlay area.
6409
6410 An overlay loaded into instruction memory and ready for use is called a
6411 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
6412 instruction memory. An overlay not present (or only partially present)
6413 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
6414 is its address in the larger memory. The mapped address is also called
6415 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
6416 called the @dfn{load memory address}, or @dfn{LMA}.
6417
6418 Unfortunately, overlays are not a completely transparent way to adapt a
6419 program to limited instruction memory. They introduce a new set of
6420 global constraints you must keep in mind as you design your program:
6421
6422 @itemize @bullet
6423
6424 @item
6425 Before calling or returning to a function in an overlay, your program
6426 must make sure that overlay is actually mapped. Otherwise, the call or
6427 return will transfer control to the right address, but in the wrong
6428 overlay, and your program will probably crash.
6429
6430 @item
6431 If the process of mapping an overlay is expensive on your system, you
6432 will need to choose your overlays carefully to minimize their effect on
6433 your program's performance.
6434
6435 @item
6436 The executable file you load onto your system must contain each
6437 overlay's instructions, appearing at the overlay's load address, not its
6438 mapped address. However, each overlay's instructions must be relocated
6439 and its symbols defined as if the overlay were at its mapped address.
6440 You can use GNU linker scripts to specify different load and relocation
6441 addresses for pieces of your program; see @ref{Overlay Description,,,
6442 ld.info, Using ld: the GNU linker}.
6443
6444 @item
6445 The procedure for loading executable files onto your system must be able
6446 to load their contents into the larger address space as well as the
6447 instruction and data spaces.
6448
6449 @end itemize
6450
6451 The overlay system described above is rather simple, and could be
6452 improved in many ways:
6453
6454 @itemize @bullet
6455
6456 @item
6457 If your system has suitable bank switch registers or memory management
6458 hardware, you could use those facilities to make an overlay's load area
6459 contents simply appear at their mapped address in instruction space.
6460 This would probably be faster than copying the overlay to its mapped
6461 area in the usual way.
6462
6463 @item
6464 If your overlays are small enough, you could set aside more than one
6465 overlay area, and have more than one overlay mapped at a time.
6466
6467 @item
6468 You can use overlays to manage data, as well as instructions. In
6469 general, data overlays are even less transparent to your design than
6470 code overlays: whereas code overlays only require care when you call or
6471 return to functions, data overlays require care every time you access
6472 the data. Also, if you change the contents of a data overlay, you
6473 must copy its contents back out to its load address before you can copy a
6474 different data overlay into the same mapped area.
6475
6476 @end itemize
6477
6478
6479 @node Overlay Commands
6480 @section Overlay Commands
6481
6482 To use @value{GDBN}'s overlay support, each overlay in your program must
6483 correspond to a separate section of the executable file. The section's
6484 virtual memory address and load memory address must be the overlay's
6485 mapped and load addresses. Identifying overlays with sections allows
6486 @value{GDBN} to determine the appropriate address of a function or
6487 variable, depending on whether the overlay is mapped or not.
6488
6489 @value{GDBN}'s overlay commands all start with the word @code{overlay};
6490 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
6491
6492 @table @code
6493 @item overlay off
6494 @kindex overlay off
6495 Disable @value{GDBN}'s overlay support. When overlay support is
6496 disabled, @value{GDBN} assumes that all functions and variables are
6497 always present at their mapped addresses. By default, @value{GDBN}'s
6498 overlay support is disabled.
6499
6500 @item overlay manual
6501 @kindex overlay manual
6502 @cindex manual overlay debugging
6503 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
6504 relies on you to tell it which overlays are mapped, and which are not,
6505 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
6506 commands described below.
6507
6508 @item overlay map-overlay @var{overlay}
6509 @itemx overlay map @var{overlay}
6510 @kindex overlay map-overlay
6511 @cindex map an overlay
6512 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
6513 be the name of the object file section containing the overlay. When an
6514 overlay is mapped, @value{GDBN} assumes it can find the overlay's
6515 functions and variables at their mapped addresses. @value{GDBN} assumes
6516 that any other overlays whose mapped ranges overlap that of
6517 @var{overlay} are now unmapped.
6518
6519 @item overlay unmap-overlay @var{overlay}
6520 @itemx overlay unmap @var{overlay}
6521 @kindex overlay unmap-overlay
6522 @cindex unmap an overlay
6523 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
6524 must be the name of the object file section containing the overlay.
6525 When an overlay is unmapped, @value{GDBN} assumes it can find the
6526 overlay's functions and variables at their load addresses.
6527
6528 @item overlay auto
6529 @kindex overlay auto
6530 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
6531 consults a data structure the overlay manager maintains in the inferior
6532 to see which overlays are mapped. For details, see @ref{Automatic
6533 Overlay Debugging}.
6534
6535 @item overlay load-target
6536 @itemx overlay load
6537 @kindex overlay load-target
6538 @cindex reloading the overlay table
6539 Re-read the overlay table from the inferior. Normally, @value{GDBN}
6540 re-reads the table @value{GDBN} automatically each time the inferior
6541 stops, so this command should only be necessary if you have changed the
6542 overlay mapping yourself using @value{GDBN}. This command is only
6543 useful when using automatic overlay debugging.
6544
6545 @item overlay list-overlays
6546 @itemx overlay list
6547 @cindex listing mapped overlays
6548 Display a list of the overlays currently mapped, along with their mapped
6549 addresses, load addresses, and sizes.
6550
6551 @end table
6552
6553 Normally, when @value{GDBN} prints a code address, it includes the name
6554 of the function the address falls in:
6555
6556 @smallexample
6557 (gdb) print main
6558 $3 = @{int ()@} 0x11a0 <main>
6559 @end smallexample
6560 @noindent
6561 When overlay debugging is enabled, @value{GDBN} recognizes code in
6562 unmapped overlays, and prints the names of unmapped functions with
6563 asterisks around them. For example, if @code{foo} is a function in an
6564 unmapped overlay, @value{GDBN} prints it this way:
6565
6566 @smallexample
6567 (gdb) overlay list
6568 No sections are mapped.
6569 (gdb) print foo
6570 $5 = @{int (int)@} 0x100000 <*foo*>
6571 @end smallexample
6572 @noindent
6573 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
6574 name normally:
6575
6576 @smallexample
6577 (gdb) overlay list
6578 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
6579 mapped at 0x1016 - 0x104a
6580 (gdb) print foo
6581 $6 = @{int (int)@} 0x1016 <foo>
6582 @end smallexample
6583
6584 When overlay debugging is enabled, @value{GDBN} can find the correct
6585 address for functions and variables in an overlay, whether or not the
6586 overlay is mapped. This allows most @value{GDBN} commands, like
6587 @code{break} and @code{disassemble}, to work normally, even on unmapped
6588 code. However, @value{GDBN}'s breakpoint support has some limitations:
6589
6590 @itemize @bullet
6591 @item
6592 @cindex breakpoints in overlays
6593 @cindex overlays, setting breakpoints in
6594 You can set breakpoints in functions in unmapped overlays, as long as
6595 @value{GDBN} can write to the overlay at its load address.
6596 @item
6597 @value{GDBN} can not set hardware or simulator-based breakpoints in
6598 unmapped overlays. However, if you set a breakpoint at the end of your
6599 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
6600 you are using manual overlay management), @value{GDBN} will re-set its
6601 breakpoints properly.
6602 @end itemize
6603
6604
6605 @node Automatic Overlay Debugging
6606 @section Automatic Overlay Debugging
6607 @cindex automatic overlay debugging
6608
6609 @value{GDBN} can automatically track which overlays are mapped and which
6610 are not, given some simple co-operation from the overlay manager in the
6611 inferior. If you enable automatic overlay debugging with the
6612 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
6613 looks in the inferior's memory for certain variables describing the
6614 current state of the overlays.
6615
6616 Here are the variables your overlay manager must define to support
6617 @value{GDBN}'s automatic overlay debugging:
6618
6619 @table @asis
6620
6621 @item @code{_ovly_table}:
6622 This variable must be an array of the following structures:
6623
6624 @smallexample
6625 struct
6626 @{
6627 /* The overlay's mapped address. */
6628 unsigned long vma;
6629
6630 /* The size of the overlay, in bytes. */
6631 unsigned long size;
6632
6633 /* The overlay's load address. */
6634 unsigned long lma;
6635
6636 /* Non-zero if the overlay is currently mapped;
6637 zero otherwise. */
6638 unsigned long mapped;
6639 @}
6640 @end smallexample
6641
6642 @item @code{_novlys}:
6643 This variable must be a four-byte signed integer, holding the total
6644 number of elements in @code{_ovly_table}.
6645
6646 @end table
6647
6648 To decide whether a particular overlay is mapped or not, @value{GDBN}
6649 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
6650 @code{lma} members equal the VMA and LMA of the overlay's section in the
6651 executable file. When @value{GDBN} finds a matching entry, it consults
6652 the entry's @code{mapped} member to determine whether the overlay is
6653 currently mapped.
6654
6655 In addition, your overlay manager may define a function called
6656 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
6657 will silently set a breakpoint there. If the overlay manager then
6658 calls this function whenever it has changed the overlay table, this
6659 will enable @value{GDBN} to accurately keep track of which overlays
6660 are in program memory, and update any breakpoints that may be set
6661 in overlays. This will allow breakpoints to work even if the
6662 overlays are kept in ROM or other non-writable memory while they
6663 are not being executed.
6664
6665 @node Overlay Sample Program
6666 @section Overlay Sample Program
6667 @cindex overlay example program
6668
6669 When linking a program which uses overlays, you must place the overlays
6670 at their load addresses, while relocating them to run at their mapped
6671 addresses. To do this, you must write a linker script (@pxref{Overlay
6672 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
6673 since linker scripts are specific to a particular host system, target
6674 architecture, and target memory layout, this manual cannot provide
6675 portable sample code demonstrating @value{GDBN}'s overlay support.
6676
6677 However, the @value{GDBN} source distribution does contain an overlaid
6678 program, with linker scripts for a few systems, as part of its test
6679 suite. The program consists of the following files from
6680 @file{gdb/testsuite/gdb.base}:
6681
6682 @table @file
6683 @item overlays.c
6684 The main program file.
6685 @item ovlymgr.c
6686 A simple overlay manager, used by @file{overlays.c}.
6687 @item foo.c
6688 @itemx bar.c
6689 @itemx baz.c
6690 @itemx grbx.c
6691 Overlay modules, loaded and used by @file{overlays.c}.
6692 @item d10v.ld
6693 @itemx m32r.ld
6694 Linker scripts for linking the test program on the @code{d10v-elf}
6695 and @code{m32r-elf} targets.
6696 @end table
6697
6698 You can build the test program using the @code{d10v-elf} GCC
6699 cross-compiler like this:
6700
6701 @smallexample
6702 $ d10v-elf-gcc -g -c overlays.c
6703 $ d10v-elf-gcc -g -c ovlymgr.c
6704 $ d10v-elf-gcc -g -c foo.c
6705 $ d10v-elf-gcc -g -c bar.c
6706 $ d10v-elf-gcc -g -c baz.c
6707 $ d10v-elf-gcc -g -c grbx.c
6708 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
6709 baz.o grbx.o -Wl,-Td10v.ld -o overlays
6710 @end smallexample
6711
6712 The build process is identical for any other architecture, except that
6713 you must substitute the appropriate compiler and linker script for the
6714 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
6715
6716
6717 @node Languages
6718 @chapter Using @value{GDBN} with Different Languages
6719 @cindex languages
6720
6721 Although programming languages generally have common aspects, they are
6722 rarely expressed in the same manner. For instance, in ANSI C,
6723 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
6724 Modula-2, it is accomplished by @code{p^}. Values can also be
6725 represented (and displayed) differently. Hex numbers in C appear as
6726 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
6727
6728 @cindex working language
6729 Language-specific information is built into @value{GDBN} for some languages,
6730 allowing you to express operations like the above in your program's
6731 native language, and allowing @value{GDBN} to output values in a manner
6732 consistent with the syntax of your program's native language. The
6733 language you use to build expressions is called the @dfn{working
6734 language}.
6735
6736 @menu
6737 * Setting:: Switching between source languages
6738 * Show:: Displaying the language
6739 * Checks:: Type and range checks
6740 * Support:: Supported languages
6741 @end menu
6742
6743 @node Setting
6744 @section Switching between source languages
6745
6746 There are two ways to control the working language---either have @value{GDBN}
6747 set it automatically, or select it manually yourself. You can use the
6748 @code{set language} command for either purpose. On startup, @value{GDBN}
6749 defaults to setting the language automatically. The working language is
6750 used to determine how expressions you type are interpreted, how values
6751 are printed, etc.
6752
6753 In addition to the working language, every source file that
6754 @value{GDBN} knows about has its own working language. For some object
6755 file formats, the compiler might indicate which language a particular
6756 source file is in. However, most of the time @value{GDBN} infers the
6757 language from the name of the file. The language of a source file
6758 controls whether C@t{++} names are demangled---this way @code{backtrace} can
6759 show each frame appropriately for its own language. There is no way to
6760 set the language of a source file from within @value{GDBN}, but you can
6761 set the language associated with a filename extension. @xref{Show, ,
6762 Displaying the language}.
6763
6764 This is most commonly a problem when you use a program, such
6765 as @code{cfront} or @code{f2c}, that generates C but is written in
6766 another language. In that case, make the
6767 program use @code{#line} directives in its C output; that way
6768 @value{GDBN} will know the correct language of the source code of the original
6769 program, and will display that source code, not the generated C code.
6770
6771 @menu
6772 * Filenames:: Filename extensions and languages.
6773 * Manually:: Setting the working language manually
6774 * Automatically:: Having @value{GDBN} infer the source language
6775 @end menu
6776
6777 @node Filenames
6778 @subsection List of filename extensions and languages
6779
6780 If a source file name ends in one of the following extensions, then
6781 @value{GDBN} infers that its language is the one indicated.
6782
6783 @table @file
6784
6785 @item .c
6786 C source file
6787
6788 @item .C
6789 @itemx .cc
6790 @itemx .cp
6791 @itemx .cpp
6792 @itemx .cxx
6793 @itemx .c++
6794 C@t{++} source file
6795
6796 @item .f
6797 @itemx .F
6798 Fortran source file
6799
6800 @item .ch
6801 @itemx .c186
6802 @itemx .c286
6803 CHILL source file
6804
6805 @item .mod
6806 Modula-2 source file
6807
6808 @item .s
6809 @itemx .S
6810 Assembler source file. This actually behaves almost like C, but
6811 @value{GDBN} does not skip over function prologues when stepping.
6812 @end table
6813
6814 In addition, you may set the language associated with a filename
6815 extension. @xref{Show, , Displaying the language}.
6816
6817 @node Manually
6818 @subsection Setting the working language
6819
6820 If you allow @value{GDBN} to set the language automatically,
6821 expressions are interpreted the same way in your debugging session and
6822 your program.
6823
6824 @kindex set language
6825 If you wish, you may set the language manually. To do this, issue the
6826 command @samp{set language @var{lang}}, where @var{lang} is the name of
6827 a language, such as
6828 @code{c} or @code{modula-2}.
6829 For a list of the supported languages, type @samp{set language}.
6830
6831 Setting the language manually prevents @value{GDBN} from updating the working
6832 language automatically. This can lead to confusion if you try
6833 to debug a program when the working language is not the same as the
6834 source language, when an expression is acceptable to both
6835 languages---but means different things. For instance, if the current
6836 source file were written in C, and @value{GDBN} was parsing Modula-2, a
6837 command such as:
6838
6839 @smallexample
6840 print a = b + c
6841 @end smallexample
6842
6843 @noindent
6844 might not have the effect you intended. In C, this means to add
6845 @code{b} and @code{c} and place the result in @code{a}. The result
6846 printed would be the value of @code{a}. In Modula-2, this means to compare
6847 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
6848
6849 @node Automatically
6850 @subsection Having @value{GDBN} infer the source language
6851
6852 To have @value{GDBN} set the working language automatically, use
6853 @samp{set language local} or @samp{set language auto}. @value{GDBN}
6854 then infers the working language. That is, when your program stops in a
6855 frame (usually by encountering a breakpoint), @value{GDBN} sets the
6856 working language to the language recorded for the function in that
6857 frame. If the language for a frame is unknown (that is, if the function
6858 or block corresponding to the frame was defined in a source file that
6859 does not have a recognized extension), the current working language is
6860 not changed, and @value{GDBN} issues a warning.
6861
6862 This may not seem necessary for most programs, which are written
6863 entirely in one source language. However, program modules and libraries
6864 written in one source language can be used by a main program written in
6865 a different source language. Using @samp{set language auto} in this
6866 case frees you from having to set the working language manually.
6867
6868 @node Show
6869 @section Displaying the language
6870
6871 The following commands help you find out which language is the
6872 working language, and also what language source files were written in.
6873
6874 @kindex show language
6875 @kindex info frame@r{, show the source language}
6876 @kindex info source@r{, show the source language}
6877 @table @code
6878 @item show language
6879 Display the current working language. This is the
6880 language you can use with commands such as @code{print} to
6881 build and compute expressions that may involve variables in your program.
6882
6883 @item info frame
6884 Display the source language for this frame. This language becomes the
6885 working language if you use an identifier from this frame.
6886 @xref{Frame Info, ,Information about a frame}, to identify the other
6887 information listed here.
6888
6889 @item info source
6890 Display the source language of this source file.
6891 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
6892 information listed here.
6893 @end table
6894
6895 In unusual circumstances, you may have source files with extensions
6896 not in the standard list. You can then set the extension associated
6897 with a language explicitly:
6898
6899 @kindex set extension-language
6900 @kindex info extensions
6901 @table @code
6902 @item set extension-language @var{.ext} @var{language}
6903 Set source files with extension @var{.ext} to be assumed to be in
6904 the source language @var{language}.
6905
6906 @item info extensions
6907 List all the filename extensions and the associated languages.
6908 @end table
6909
6910 @node Checks
6911 @section Type and range checking
6912
6913 @quotation
6914 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
6915 checking are included, but they do not yet have any effect. This
6916 section documents the intended facilities.
6917 @end quotation
6918 @c FIXME remove warning when type/range code added
6919
6920 Some languages are designed to guard you against making seemingly common
6921 errors through a series of compile- and run-time checks. These include
6922 checking the type of arguments to functions and operators, and making
6923 sure mathematical overflows are caught at run time. Checks such as
6924 these help to ensure a program's correctness once it has been compiled
6925 by eliminating type mismatches, and providing active checks for range
6926 errors when your program is running.
6927
6928 @value{GDBN} can check for conditions like the above if you wish.
6929 Although @value{GDBN} does not check the statements in your program, it
6930 can check expressions entered directly into @value{GDBN} for evaluation via
6931 the @code{print} command, for example. As with the working language,
6932 @value{GDBN} can also decide whether or not to check automatically based on
6933 your program's source language. @xref{Support, ,Supported languages},
6934 for the default settings of supported languages.
6935
6936 @menu
6937 * Type Checking:: An overview of type checking
6938 * Range Checking:: An overview of range checking
6939 @end menu
6940
6941 @cindex type checking
6942 @cindex checks, type
6943 @node Type Checking
6944 @subsection An overview of type checking
6945
6946 Some languages, such as Modula-2, are strongly typed, meaning that the
6947 arguments to operators and functions have to be of the correct type,
6948 otherwise an error occurs. These checks prevent type mismatch
6949 errors from ever causing any run-time problems. For example,
6950
6951 @smallexample
6952 1 + 2 @result{} 3
6953 @exdent but
6954 @error{} 1 + 2.3
6955 @end smallexample
6956
6957 The second example fails because the @code{CARDINAL} 1 is not
6958 type-compatible with the @code{REAL} 2.3.
6959
6960 For the expressions you use in @value{GDBN} commands, you can tell the
6961 @value{GDBN} type checker to skip checking;
6962 to treat any mismatches as errors and abandon the expression;
6963 or to only issue warnings when type mismatches occur,
6964 but evaluate the expression anyway. When you choose the last of
6965 these, @value{GDBN} evaluates expressions like the second example above, but
6966 also issues a warning.
6967
6968 Even if you turn type checking off, there may be other reasons
6969 related to type that prevent @value{GDBN} from evaluating an expression.
6970 For instance, @value{GDBN} does not know how to add an @code{int} and
6971 a @code{struct foo}. These particular type errors have nothing to do
6972 with the language in use, and usually arise from expressions, such as
6973 the one described above, which make little sense to evaluate anyway.
6974
6975 Each language defines to what degree it is strict about type. For
6976 instance, both Modula-2 and C require the arguments to arithmetical
6977 operators to be numbers. In C, enumerated types and pointers can be
6978 represented as numbers, so that they are valid arguments to mathematical
6979 operators. @xref{Support, ,Supported languages}, for further
6980 details on specific languages.
6981
6982 @value{GDBN} provides some additional commands for controlling the type checker:
6983
6984 @kindex set check@r{, type}
6985 @kindex set check type
6986 @kindex show check type
6987 @table @code
6988 @item set check type auto
6989 Set type checking on or off based on the current working language.
6990 @xref{Support, ,Supported languages}, for the default settings for
6991 each language.
6992
6993 @item set check type on
6994 @itemx set check type off
6995 Set type checking on or off, overriding the default setting for the
6996 current working language. Issue a warning if the setting does not
6997 match the language default. If any type mismatches occur in
6998 evaluating an expression while type checking is on, @value{GDBN} prints a
6999 message and aborts evaluation of the expression.
7000
7001 @item set check type warn
7002 Cause the type checker to issue warnings, but to always attempt to
7003 evaluate the expression. Evaluating the expression may still
7004 be impossible for other reasons. For example, @value{GDBN} cannot add
7005 numbers and structures.
7006
7007 @item show type
7008 Show the current setting of the type checker, and whether or not @value{GDBN}
7009 is setting it automatically.
7010 @end table
7011
7012 @cindex range checking
7013 @cindex checks, range
7014 @node Range Checking
7015 @subsection An overview of range checking
7016
7017 In some languages (such as Modula-2), it is an error to exceed the
7018 bounds of a type; this is enforced with run-time checks. Such range
7019 checking is meant to ensure program correctness by making sure
7020 computations do not overflow, or indices on an array element access do
7021 not exceed the bounds of the array.
7022
7023 For expressions you use in @value{GDBN} commands, you can tell
7024 @value{GDBN} to treat range errors in one of three ways: ignore them,
7025 always treat them as errors and abandon the expression, or issue
7026 warnings but evaluate the expression anyway.
7027
7028 A range error can result from numerical overflow, from exceeding an
7029 array index bound, or when you type a constant that is not a member
7030 of any type. Some languages, however, do not treat overflows as an
7031 error. In many implementations of C, mathematical overflow causes the
7032 result to ``wrap around'' to lower values---for example, if @var{m} is
7033 the largest integer value, and @var{s} is the smallest, then
7034
7035 @smallexample
7036 @var{m} + 1 @result{} @var{s}
7037 @end smallexample
7038
7039 This, too, is specific to individual languages, and in some cases
7040 specific to individual compilers or machines. @xref{Support, ,
7041 Supported languages}, for further details on specific languages.
7042
7043 @value{GDBN} provides some additional commands for controlling the range checker:
7044
7045 @kindex set check@r{, range}
7046 @kindex set check range
7047 @kindex show check range
7048 @table @code
7049 @item set check range auto
7050 Set range checking on or off based on the current working language.
7051 @xref{Support, ,Supported languages}, for the default settings for
7052 each language.
7053
7054 @item set check range on
7055 @itemx set check range off
7056 Set range checking on or off, overriding the default setting for the
7057 current working language. A warning is issued if the setting does not
7058 match the language default. If a range error occurs and range checking is on,
7059 then a message is printed and evaluation of the expression is aborted.
7060
7061 @item set check range warn
7062 Output messages when the @value{GDBN} range checker detects a range error,
7063 but attempt to evaluate the expression anyway. Evaluating the
7064 expression may still be impossible for other reasons, such as accessing
7065 memory that the process does not own (a typical example from many Unix
7066 systems).
7067
7068 @item show range
7069 Show the current setting of the range checker, and whether or not it is
7070 being set automatically by @value{GDBN}.
7071 @end table
7072
7073 @node Support
7074 @section Supported languages
7075
7076 @value{GDBN} supports C, C@t{++}, Fortran, Java, Chill, assembly, and Modula-2.
7077 @c This is false ...
7078 Some @value{GDBN} features may be used in expressions regardless of the
7079 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
7080 and the @samp{@{type@}addr} construct (@pxref{Expressions,
7081 ,Expressions}) can be used with the constructs of any supported
7082 language.
7083
7084 The following sections detail to what degree each source language is
7085 supported by @value{GDBN}. These sections are not meant to be language
7086 tutorials or references, but serve only as a reference guide to what the
7087 @value{GDBN} expression parser accepts, and what input and output
7088 formats should look like for different languages. There are many good
7089 books written on each of these languages; please look to these for a
7090 language reference or tutorial.
7091
7092 @menu
7093 * C:: C and C@t{++}
7094 * Modula-2:: Modula-2
7095 * Chill:: Chill
7096 @end menu
7097
7098 @node C
7099 @subsection C and C@t{++}
7100
7101 @cindex C and C@t{++}
7102 @cindex expressions in C or C@t{++}
7103
7104 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
7105 to both languages. Whenever this is the case, we discuss those languages
7106 together.
7107
7108 @cindex C@t{++}
7109 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
7110 @cindex @sc{gnu} C@t{++}
7111 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
7112 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
7113 effectively, you must compile your C@t{++} programs with a supported
7114 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
7115 compiler (@code{aCC}).
7116
7117 For best results when using @sc{gnu} C@t{++}, use the stabs debugging
7118 format. You can select that format explicitly with the @code{g++}
7119 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
7120 @ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
7121 CC, gcc.info, Using @sc{gnu} CC}, for more information.
7122
7123 @menu
7124 * C Operators:: C and C@t{++} operators
7125 * C Constants:: C and C@t{++} constants
7126 * C plus plus expressions:: C@t{++} expressions
7127 * C Defaults:: Default settings for C and C@t{++}
7128 * C Checks:: C and C@t{++} type and range checks
7129 * Debugging C:: @value{GDBN} and C
7130 * Debugging C plus plus:: @value{GDBN} features for C@t{++}
7131 @end menu
7132
7133 @node C Operators
7134 @subsubsection C and C@t{++} operators
7135
7136 @cindex C and C@t{++} operators
7137
7138 Operators must be defined on values of specific types. For instance,
7139 @code{+} is defined on numbers, but not on structures. Operators are
7140 often defined on groups of types.
7141
7142 For the purposes of C and C@t{++}, the following definitions hold:
7143
7144 @itemize @bullet
7145
7146 @item
7147 @emph{Integral types} include @code{int} with any of its storage-class
7148 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
7149
7150 @item
7151 @emph{Floating-point types} include @code{float}, @code{double}, and
7152 @code{long double} (if supported by the target platform).
7153
7154 @item
7155 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
7156
7157 @item
7158 @emph{Scalar types} include all of the above.
7159
7160 @end itemize
7161
7162 @noindent
7163 The following operators are supported. They are listed here
7164 in order of increasing precedence:
7165
7166 @table @code
7167 @item ,
7168 The comma or sequencing operator. Expressions in a comma-separated list
7169 are evaluated from left to right, with the result of the entire
7170 expression being the last expression evaluated.
7171
7172 @item =
7173 Assignment. The value of an assignment expression is the value
7174 assigned. Defined on scalar types.
7175
7176 @item @var{op}=
7177 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
7178 and translated to @w{@code{@var{a} = @var{a op b}}}.
7179 @w{@code{@var{op}=}} and @code{=} have the same precedence.
7180 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
7181 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
7182
7183 @item ?:
7184 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
7185 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
7186 integral type.
7187
7188 @item ||
7189 Logical @sc{or}. Defined on integral types.
7190
7191 @item &&
7192 Logical @sc{and}. Defined on integral types.
7193
7194 @item |
7195 Bitwise @sc{or}. Defined on integral types.
7196
7197 @item ^
7198 Bitwise exclusive-@sc{or}. Defined on integral types.
7199
7200 @item &
7201 Bitwise @sc{and}. Defined on integral types.
7202
7203 @item ==@r{, }!=
7204 Equality and inequality. Defined on scalar types. The value of these
7205 expressions is 0 for false and non-zero for true.
7206
7207 @item <@r{, }>@r{, }<=@r{, }>=
7208 Less than, greater than, less than or equal, greater than or equal.
7209 Defined on scalar types. The value of these expressions is 0 for false
7210 and non-zero for true.
7211
7212 @item <<@r{, }>>
7213 left shift, and right shift. Defined on integral types.
7214
7215 @item @@
7216 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7217
7218 @item +@r{, }-
7219 Addition and subtraction. Defined on integral types, floating-point types and
7220 pointer types.
7221
7222 @item *@r{, }/@r{, }%
7223 Multiplication, division, and modulus. Multiplication and division are
7224 defined on integral and floating-point types. Modulus is defined on
7225 integral types.
7226
7227 @item ++@r{, }--
7228 Increment and decrement. When appearing before a variable, the
7229 operation is performed before the variable is used in an expression;
7230 when appearing after it, the variable's value is used before the
7231 operation takes place.
7232
7233 @item *
7234 Pointer dereferencing. Defined on pointer types. Same precedence as
7235 @code{++}.
7236
7237 @item &
7238 Address operator. Defined on variables. Same precedence as @code{++}.
7239
7240 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
7241 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
7242 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
7243 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
7244 stored.
7245
7246 @item -
7247 Negative. Defined on integral and floating-point types. Same
7248 precedence as @code{++}.
7249
7250 @item !
7251 Logical negation. Defined on integral types. Same precedence as
7252 @code{++}.
7253
7254 @item ~
7255 Bitwise complement operator. Defined on integral types. Same precedence as
7256 @code{++}.
7257
7258
7259 @item .@r{, }->
7260 Structure member, and pointer-to-structure member. For convenience,
7261 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
7262 pointer based on the stored type information.
7263 Defined on @code{struct} and @code{union} data.
7264
7265 @item .*@r{, }->*
7266 Dereferences of pointers to members.
7267
7268 @item []
7269 Array indexing. @code{@var{a}[@var{i}]} is defined as
7270 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
7271
7272 @item ()
7273 Function parameter list. Same precedence as @code{->}.
7274
7275 @item ::
7276 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7277 and @code{class} types.
7278
7279 @item ::
7280 Doubled colons also represent the @value{GDBN} scope operator
7281 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
7282 above.
7283 @end table
7284
7285 If an operator is redefined in the user code, @value{GDBN} usually
7286 attempts to invoke the redefined version instead of using the operator's
7287 predefined meaning.
7288
7289 @menu
7290 * C Constants::
7291 @end menu
7292
7293 @node C Constants
7294 @subsubsection C and C@t{++} constants
7295
7296 @cindex C and C@t{++} constants
7297
7298 @value{GDBN} allows you to express the constants of C and C@t{++} in the
7299 following ways:
7300
7301 @itemize @bullet
7302 @item
7303 Integer constants are a sequence of digits. Octal constants are
7304 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
7305 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
7306 @samp{l}, specifying that the constant should be treated as a
7307 @code{long} value.
7308
7309 @item
7310 Floating point constants are a sequence of digits, followed by a decimal
7311 point, followed by a sequence of digits, and optionally followed by an
7312 exponent. An exponent is of the form:
7313 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
7314 sequence of digits. The @samp{+} is optional for positive exponents.
7315 A floating-point constant may also end with a letter @samp{f} or
7316 @samp{F}, specifying that the constant should be treated as being of
7317 the @code{float} (as opposed to the default @code{double}) type; or with
7318 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
7319 constant.
7320
7321 @item
7322 Enumerated constants consist of enumerated identifiers, or their
7323 integral equivalents.
7324
7325 @item
7326 Character constants are a single character surrounded by single quotes
7327 (@code{'}), or a number---the ordinal value of the corresponding character
7328 (usually its @sc{ascii} value). Within quotes, the single character may
7329 be represented by a letter or by @dfn{escape sequences}, which are of
7330 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
7331 of the character's ordinal value; or of the form @samp{\@var{x}}, where
7332 @samp{@var{x}} is a predefined special character---for example,
7333 @samp{\n} for newline.
7334
7335 @item
7336 String constants are a sequence of character constants surrounded by
7337 double quotes (@code{"}). Any valid character constant (as described
7338 above) may appear. Double quotes within the string must be preceded by
7339 a backslash, so for instance @samp{"a\"b'c"} is a string of five
7340 characters.
7341
7342 @item
7343 Pointer constants are an integral value. You can also write pointers
7344 to constants using the C operator @samp{&}.
7345
7346 @item
7347 Array constants are comma-separated lists surrounded by braces @samp{@{}
7348 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
7349 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
7350 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
7351 @end itemize
7352
7353 @menu
7354 * C plus plus expressions::
7355 * C Defaults::
7356 * C Checks::
7357
7358 * Debugging C::
7359 @end menu
7360
7361 @node C plus plus expressions
7362 @subsubsection C@t{++} expressions
7363
7364 @cindex expressions in C@t{++}
7365 @value{GDBN} expression handling can interpret most C@t{++} expressions.
7366
7367 @cindex C@t{++} support, not in @sc{coff}
7368 @cindex @sc{coff} versus C@t{++}
7369 @cindex C@t{++} and object formats
7370 @cindex object formats and C@t{++}
7371 @cindex a.out and C@t{++}
7372 @cindex @sc{ecoff} and C@t{++}
7373 @cindex @sc{xcoff} and C@t{++}
7374 @cindex @sc{elf}/stabs and C@t{++}
7375 @cindex @sc{elf}/@sc{dwarf} and C@t{++}
7376 @c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
7377 @c periodically whether this has happened...
7378 @quotation
7379 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
7380 proper compiler. Typically, C@t{++} debugging depends on the use of
7381 additional debugging information in the symbol table, and thus requires
7382 special support. In particular, if your compiler generates a.out, MIPS
7383 @sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
7384 symbol table, these facilities are all available. (With @sc{gnu} CC,
7385 you can use the @samp{-gstabs} option to request stabs debugging
7386 extensions explicitly.) Where the object code format is standard
7387 @sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C@t{++}
7388 support in @value{GDBN} does @emph{not} work.
7389 @end quotation
7390
7391 @enumerate
7392
7393 @cindex member functions
7394 @item
7395 Member function calls are allowed; you can use expressions like
7396
7397 @smallexample
7398 count = aml->GetOriginal(x, y)
7399 @end smallexample
7400
7401 @vindex this@r{, inside C@t{++} member functions}
7402 @cindex namespace in C@t{++}
7403 @item
7404 While a member function is active (in the selected stack frame), your
7405 expressions have the same namespace available as the member function;
7406 that is, @value{GDBN} allows implicit references to the class instance
7407 pointer @code{this} following the same rules as C@t{++}.
7408
7409 @cindex call overloaded functions
7410 @cindex overloaded functions, calling
7411 @cindex type conversions in C@t{++}
7412 @item
7413 You can call overloaded functions; @value{GDBN} resolves the function
7414 call to the right definition, with some restrictions. @value{GDBN} does not
7415 perform overload resolution involving user-defined type conversions,
7416 calls to constructors, or instantiations of templates that do not exist
7417 in the program. It also cannot handle ellipsis argument lists or
7418 default arguments.
7419
7420 It does perform integral conversions and promotions, floating-point
7421 promotions, arithmetic conversions, pointer conversions, conversions of
7422 class objects to base classes, and standard conversions such as those of
7423 functions or arrays to pointers; it requires an exact match on the
7424 number of function arguments.
7425
7426 Overload resolution is always performed, unless you have specified
7427 @code{set overload-resolution off}. @xref{Debugging C plus plus,
7428 ,@value{GDBN} features for C@t{++}}.
7429
7430 You must specify @code{set overload-resolution off} in order to use an
7431 explicit function signature to call an overloaded function, as in
7432 @smallexample
7433 p 'foo(char,int)'('x', 13)
7434 @end smallexample
7435
7436 The @value{GDBN} command-completion facility can simplify this;
7437 see @ref{Completion, ,Command completion}.
7438
7439 @cindex reference declarations
7440 @item
7441 @value{GDBN} understands variables declared as C@t{++} references; you can use
7442 them in expressions just as you do in C@t{++} source---they are automatically
7443 dereferenced.
7444
7445 In the parameter list shown when @value{GDBN} displays a frame, the values of
7446 reference variables are not displayed (unlike other variables); this
7447 avoids clutter, since references are often used for large structures.
7448 The @emph{address} of a reference variable is always shown, unless
7449 you have specified @samp{set print address off}.
7450
7451 @item
7452 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
7453 expressions can use it just as expressions in your program do. Since
7454 one scope may be defined in another, you can use @code{::} repeatedly if
7455 necessary, for example in an expression like
7456 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
7457 resolving name scope by reference to source files, in both C and C@t{++}
7458 debugging (@pxref{Variables, ,Program variables}).
7459 @end enumerate
7460
7461 In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
7462 calling virtual functions correctly, printing out virtual bases of
7463 objects, calling functions in a base subobject, casting objects, and
7464 invoking user-defined operators.
7465
7466 @node C Defaults
7467 @subsubsection C and C@t{++} defaults
7468
7469 @cindex C and C@t{++} defaults
7470
7471 If you allow @value{GDBN} to set type and range checking automatically, they
7472 both default to @code{off} whenever the working language changes to
7473 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
7474 selects the working language.
7475
7476 If you allow @value{GDBN} to set the language automatically, it
7477 recognizes source files whose names end with @file{.c}, @file{.C}, or
7478 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
7479 these files, it sets the working language to C or C@t{++}.
7480 @xref{Automatically, ,Having @value{GDBN} infer the source language},
7481 for further details.
7482
7483 @c Type checking is (a) primarily motivated by Modula-2, and (b)
7484 @c unimplemented. If (b) changes, it might make sense to let this node
7485 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7486
7487 @node C Checks
7488 @subsubsection C and C@t{++} type and range checks
7489
7490 @cindex C and C@t{++} checks
7491
7492 By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
7493 is not used. However, if you turn type checking on, @value{GDBN}
7494 considers two variables type equivalent if:
7495
7496 @itemize @bullet
7497 @item
7498 The two variables are structured and have the same structure, union, or
7499 enumerated tag.
7500
7501 @item
7502 The two variables have the same type name, or types that have been
7503 declared equivalent through @code{typedef}.
7504
7505 @ignore
7506 @c leaving this out because neither J Gilmore nor R Pesch understand it.
7507 @c FIXME--beers?
7508 @item
7509 The two @code{struct}, @code{union}, or @code{enum} variables are
7510 declared in the same declaration. (Note: this may not be true for all C
7511 compilers.)
7512 @end ignore
7513 @end itemize
7514
7515 Range checking, if turned on, is done on mathematical operations. Array
7516 indices are not checked, since they are often used to index a pointer
7517 that is not itself an array.
7518
7519 @node Debugging C
7520 @subsubsection @value{GDBN} and C
7521
7522 The @code{set print union} and @code{show print union} commands apply to
7523 the @code{union} type. When set to @samp{on}, any @code{union} that is
7524 inside a @code{struct} or @code{class} is also printed. Otherwise, it
7525 appears as @samp{@{...@}}.
7526
7527 The @code{@@} operator aids in the debugging of dynamic arrays, formed
7528 with pointers and a memory allocation function. @xref{Expressions,
7529 ,Expressions}.
7530
7531 @menu
7532 * Debugging C plus plus::
7533 @end menu
7534
7535 @node Debugging C plus plus
7536 @subsubsection @value{GDBN} features for C@t{++}
7537
7538 @cindex commands for C@t{++}
7539
7540 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
7541 designed specifically for use with C@t{++}. Here is a summary:
7542
7543 @table @code
7544 @cindex break in overloaded functions
7545 @item @r{breakpoint menus}
7546 When you want a breakpoint in a function whose name is overloaded,
7547 @value{GDBN} breakpoint menus help you specify which function definition
7548 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
7549
7550 @cindex overloading in C@t{++}
7551 @item rbreak @var{regex}
7552 Setting breakpoints using regular expressions is helpful for setting
7553 breakpoints on overloaded functions that are not members of any special
7554 classes.
7555 @xref{Set Breaks, ,Setting breakpoints}.
7556
7557 @cindex C@t{++} exception handling
7558 @item catch throw
7559 @itemx catch catch
7560 Debug C@t{++} exception handling using these commands. @xref{Set
7561 Catchpoints, , Setting catchpoints}.
7562
7563 @cindex inheritance
7564 @item ptype @var{typename}
7565 Print inheritance relationships as well as other information for type
7566 @var{typename}.
7567 @xref{Symbols, ,Examining the Symbol Table}.
7568
7569 @cindex C@t{++} symbol display
7570 @item set print demangle
7571 @itemx show print demangle
7572 @itemx set print asm-demangle
7573 @itemx show print asm-demangle
7574 Control whether C@t{++} symbols display in their source form, both when
7575 displaying code as C@t{++} source and when displaying disassemblies.
7576 @xref{Print Settings, ,Print settings}.
7577
7578 @item set print object
7579 @itemx show print object
7580 Choose whether to print derived (actual) or declared types of objects.
7581 @xref{Print Settings, ,Print settings}.
7582
7583 @item set print vtbl
7584 @itemx show print vtbl
7585 Control the format for printing virtual function tables.
7586 @xref{Print Settings, ,Print settings}.
7587 (The @code{vtbl} commands do not work on programs compiled with the HP
7588 ANSI C@t{++} compiler (@code{aCC}).)
7589
7590 @kindex set overload-resolution
7591 @cindex overloaded functions, overload resolution
7592 @item set overload-resolution on
7593 Enable overload resolution for C@t{++} expression evaluation. The default
7594 is on. For overloaded functions, @value{GDBN} evaluates the arguments
7595 and searches for a function whose signature matches the argument types,
7596 using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
7597 expressions}, for details). If it cannot find a match, it emits a
7598 message.
7599
7600 @item set overload-resolution off
7601 Disable overload resolution for C@t{++} expression evaluation. For
7602 overloaded functions that are not class member functions, @value{GDBN}
7603 chooses the first function of the specified name that it finds in the
7604 symbol table, whether or not its arguments are of the correct type. For
7605 overloaded functions that are class member functions, @value{GDBN}
7606 searches for a function whose signature @emph{exactly} matches the
7607 argument types.
7608
7609 @item @r{Overloaded symbol names}
7610 You can specify a particular definition of an overloaded symbol, using
7611 the same notation that is used to declare such symbols in C@t{++}: type
7612 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
7613 also use the @value{GDBN} command-line word completion facilities to list the
7614 available choices, or to finish the type list for you.
7615 @xref{Completion,, Command completion}, for details on how to do this.
7616 @end table
7617
7618 @node Modula-2
7619 @subsection Modula-2
7620
7621 @cindex Modula-2, @value{GDBN} support
7622
7623 The extensions made to @value{GDBN} to support Modula-2 only support
7624 output from the @sc{gnu} Modula-2 compiler (which is currently being
7625 developed). Other Modula-2 compilers are not currently supported, and
7626 attempting to debug executables produced by them is most likely
7627 to give an error as @value{GDBN} reads in the executable's symbol
7628 table.
7629
7630 @cindex expressions in Modula-2
7631 @menu
7632 * M2 Operators:: Built-in operators
7633 * Built-In Func/Proc:: Built-in functions and procedures
7634 * M2 Constants:: Modula-2 constants
7635 * M2 Defaults:: Default settings for Modula-2
7636 * Deviations:: Deviations from standard Modula-2
7637 * M2 Checks:: Modula-2 type and range checks
7638 * M2 Scope:: The scope operators @code{::} and @code{.}
7639 * GDB/M2:: @value{GDBN} and Modula-2
7640 @end menu
7641
7642 @node M2 Operators
7643 @subsubsection Operators
7644 @cindex Modula-2 operators
7645
7646 Operators must be defined on values of specific types. For instance,
7647 @code{+} is defined on numbers, but not on structures. Operators are
7648 often defined on groups of types. For the purposes of Modula-2, the
7649 following definitions hold:
7650
7651 @itemize @bullet
7652
7653 @item
7654 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
7655 their subranges.
7656
7657 @item
7658 @emph{Character types} consist of @code{CHAR} and its subranges.
7659
7660 @item
7661 @emph{Floating-point types} consist of @code{REAL}.
7662
7663 @item
7664 @emph{Pointer types} consist of anything declared as @code{POINTER TO
7665 @var{type}}.
7666
7667 @item
7668 @emph{Scalar types} consist of all of the above.
7669
7670 @item
7671 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
7672
7673 @item
7674 @emph{Boolean types} consist of @code{BOOLEAN}.
7675 @end itemize
7676
7677 @noindent
7678 The following operators are supported, and appear in order of
7679 increasing precedence:
7680
7681 @table @code
7682 @item ,
7683 Function argument or array index separator.
7684
7685 @item :=
7686 Assignment. The value of @var{var} @code{:=} @var{value} is
7687 @var{value}.
7688
7689 @item <@r{, }>
7690 Less than, greater than on integral, floating-point, or enumerated
7691 types.
7692
7693 @item <=@r{, }>=
7694 Less than or equal to, greater than or equal to
7695 on integral, floating-point and enumerated types, or set inclusion on
7696 set types. Same precedence as @code{<}.
7697
7698 @item =@r{, }<>@r{, }#
7699 Equality and two ways of expressing inequality, valid on scalar types.
7700 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
7701 available for inequality, since @code{#} conflicts with the script
7702 comment character.
7703
7704 @item IN
7705 Set membership. Defined on set types and the types of their members.
7706 Same precedence as @code{<}.
7707
7708 @item OR
7709 Boolean disjunction. Defined on boolean types.
7710
7711 @item AND@r{, }&
7712 Boolean conjunction. Defined on boolean types.
7713
7714 @item @@
7715 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
7716
7717 @item +@r{, }-
7718 Addition and subtraction on integral and floating-point types, or union
7719 and difference on set types.
7720
7721 @item *
7722 Multiplication on integral and floating-point types, or set intersection
7723 on set types.
7724
7725 @item /
7726 Division on floating-point types, or symmetric set difference on set
7727 types. Same precedence as @code{*}.
7728
7729 @item DIV@r{, }MOD
7730 Integer division and remainder. Defined on integral types. Same
7731 precedence as @code{*}.
7732
7733 @item -
7734 Negative. Defined on @code{INTEGER} and @code{REAL} data.
7735
7736 @item ^
7737 Pointer dereferencing. Defined on pointer types.
7738
7739 @item NOT
7740 Boolean negation. Defined on boolean types. Same precedence as
7741 @code{^}.
7742
7743 @item .
7744 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
7745 precedence as @code{^}.
7746
7747 @item []
7748 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
7749
7750 @item ()
7751 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
7752 as @code{^}.
7753
7754 @item ::@r{, }.
7755 @value{GDBN} and Modula-2 scope operators.
7756 @end table
7757
7758 @quotation
7759 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
7760 treats the use of the operator @code{IN}, or the use of operators
7761 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
7762 @code{<=}, and @code{>=} on sets as an error.
7763 @end quotation
7764
7765
7766 @node Built-In Func/Proc
7767 @subsubsection Built-in functions and procedures
7768 @cindex Modula-2 built-ins
7769
7770 Modula-2 also makes available several built-in procedures and functions.
7771 In describing these, the following metavariables are used:
7772
7773 @table @var
7774
7775 @item a
7776 represents an @code{ARRAY} variable.
7777
7778 @item c
7779 represents a @code{CHAR} constant or variable.
7780
7781 @item i
7782 represents a variable or constant of integral type.
7783
7784 @item m
7785 represents an identifier that belongs to a set. Generally used in the
7786 same function with the metavariable @var{s}. The type of @var{s} should
7787 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
7788
7789 @item n
7790 represents a variable or constant of integral or floating-point type.
7791
7792 @item r
7793 represents a variable or constant of floating-point type.
7794
7795 @item t
7796 represents a type.
7797
7798 @item v
7799 represents a variable.
7800
7801 @item x
7802 represents a variable or constant of one of many types. See the
7803 explanation of the function for details.
7804 @end table
7805
7806 All Modula-2 built-in procedures also return a result, described below.
7807
7808 @table @code
7809 @item ABS(@var{n})
7810 Returns the absolute value of @var{n}.
7811
7812 @item CAP(@var{c})
7813 If @var{c} is a lower case letter, it returns its upper case
7814 equivalent, otherwise it returns its argument.
7815
7816 @item CHR(@var{i})
7817 Returns the character whose ordinal value is @var{i}.
7818
7819 @item DEC(@var{v})
7820 Decrements the value in the variable @var{v} by one. Returns the new value.
7821
7822 @item DEC(@var{v},@var{i})
7823 Decrements the value in the variable @var{v} by @var{i}. Returns the
7824 new value.
7825
7826 @item EXCL(@var{m},@var{s})
7827 Removes the element @var{m} from the set @var{s}. Returns the new
7828 set.
7829
7830 @item FLOAT(@var{i})
7831 Returns the floating point equivalent of the integer @var{i}.
7832
7833 @item HIGH(@var{a})
7834 Returns the index of the last member of @var{a}.
7835
7836 @item INC(@var{v})
7837 Increments the value in the variable @var{v} by one. Returns the new value.
7838
7839 @item INC(@var{v},@var{i})
7840 Increments the value in the variable @var{v} by @var{i}. Returns the
7841 new value.
7842
7843 @item INCL(@var{m},@var{s})
7844 Adds the element @var{m} to the set @var{s} if it is not already
7845 there. Returns the new set.
7846
7847 @item MAX(@var{t})
7848 Returns the maximum value of the type @var{t}.
7849
7850 @item MIN(@var{t})
7851 Returns the minimum value of the type @var{t}.
7852
7853 @item ODD(@var{i})
7854 Returns boolean TRUE if @var{i} is an odd number.
7855
7856 @item ORD(@var{x})
7857 Returns the ordinal value of its argument. For example, the ordinal
7858 value of a character is its @sc{ascii} value (on machines supporting the
7859 @sc{ascii} character set). @var{x} must be of an ordered type, which include
7860 integral, character and enumerated types.
7861
7862 @item SIZE(@var{x})
7863 Returns the size of its argument. @var{x} can be a variable or a type.
7864
7865 @item TRUNC(@var{r})
7866 Returns the integral part of @var{r}.
7867
7868 @item VAL(@var{t},@var{i})
7869 Returns the member of the type @var{t} whose ordinal value is @var{i}.
7870 @end table
7871
7872 @quotation
7873 @emph{Warning:} Sets and their operations are not yet supported, so
7874 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
7875 an error.
7876 @end quotation
7877
7878 @cindex Modula-2 constants
7879 @node M2 Constants
7880 @subsubsection Constants
7881
7882 @value{GDBN} allows you to express the constants of Modula-2 in the following
7883 ways:
7884
7885 @itemize @bullet
7886
7887 @item
7888 Integer constants are simply a sequence of digits. When used in an
7889 expression, a constant is interpreted to be type-compatible with the
7890 rest of the expression. Hexadecimal integers are specified by a
7891 trailing @samp{H}, and octal integers by a trailing @samp{B}.
7892
7893 @item
7894 Floating point constants appear as a sequence of digits, followed by a
7895 decimal point and another sequence of digits. An optional exponent can
7896 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
7897 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
7898 digits of the floating point constant must be valid decimal (base 10)
7899 digits.
7900
7901 @item
7902 Character constants consist of a single character enclosed by a pair of
7903 like quotes, either single (@code{'}) or double (@code{"}). They may
7904 also be expressed by their ordinal value (their @sc{ascii} value, usually)
7905 followed by a @samp{C}.
7906
7907 @item
7908 String constants consist of a sequence of characters enclosed by a
7909 pair of like quotes, either single (@code{'}) or double (@code{"}).
7910 Escape sequences in the style of C are also allowed. @xref{C
7911 Constants, ,C and C@t{++} constants}, for a brief explanation of escape
7912 sequences.
7913
7914 @item
7915 Enumerated constants consist of an enumerated identifier.
7916
7917 @item
7918 Boolean constants consist of the identifiers @code{TRUE} and
7919 @code{FALSE}.
7920
7921 @item
7922 Pointer constants consist of integral values only.
7923
7924 @item
7925 Set constants are not yet supported.
7926 @end itemize
7927
7928 @node M2 Defaults
7929 @subsubsection Modula-2 defaults
7930 @cindex Modula-2 defaults
7931
7932 If type and range checking are set automatically by @value{GDBN}, they
7933 both default to @code{on} whenever the working language changes to
7934 Modula-2. This happens regardless of whether you or @value{GDBN}
7935 selected the working language.
7936
7937 If you allow @value{GDBN} to set the language automatically, then entering
7938 code compiled from a file whose name ends with @file{.mod} sets the
7939 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
7940 the language automatically}, for further details.
7941
7942 @node Deviations
7943 @subsubsection Deviations from standard Modula-2
7944 @cindex Modula-2, deviations from
7945
7946 A few changes have been made to make Modula-2 programs easier to debug.
7947 This is done primarily via loosening its type strictness:
7948
7949 @itemize @bullet
7950 @item
7951 Unlike in standard Modula-2, pointer constants can be formed by
7952 integers. This allows you to modify pointer variables during
7953 debugging. (In standard Modula-2, the actual address contained in a
7954 pointer variable is hidden from you; it can only be modified
7955 through direct assignment to another pointer variable or expression that
7956 returned a pointer.)
7957
7958 @item
7959 C escape sequences can be used in strings and characters to represent
7960 non-printable characters. @value{GDBN} prints out strings with these
7961 escape sequences embedded. Single non-printable characters are
7962 printed using the @samp{CHR(@var{nnn})} format.
7963
7964 @item
7965 The assignment operator (@code{:=}) returns the value of its right-hand
7966 argument.
7967
7968 @item
7969 All built-in procedures both modify @emph{and} return their argument.
7970 @end itemize
7971
7972 @node M2 Checks
7973 @subsubsection Modula-2 type and range checks
7974 @cindex Modula-2 checks
7975
7976 @quotation
7977 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
7978 range checking.
7979 @end quotation
7980 @c FIXME remove warning when type/range checks added
7981
7982 @value{GDBN} considers two Modula-2 variables type equivalent if:
7983
7984 @itemize @bullet
7985 @item
7986 They are of types that have been declared equivalent via a @code{TYPE
7987 @var{t1} = @var{t2}} statement
7988
7989 @item
7990 They have been declared on the same line. (Note: This is true of the
7991 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
7992 @end itemize
7993
7994 As long as type checking is enabled, any attempt to combine variables
7995 whose types are not equivalent is an error.
7996
7997 Range checking is done on all mathematical operations, assignment, array
7998 index bounds, and all built-in functions and procedures.
7999
8000 @node M2 Scope
8001 @subsubsection The scope operators @code{::} and @code{.}
8002 @cindex scope
8003 @cindex @code{.}, Modula-2 scope operator
8004 @cindex colon, doubled as scope operator
8005 @ifinfo
8006 @vindex colon-colon@r{, in Modula-2}
8007 @c Info cannot handle :: but TeX can.
8008 @end ifinfo
8009 @iftex
8010 @vindex ::@r{, in Modula-2}
8011 @end iftex
8012
8013 There are a few subtle differences between the Modula-2 scope operator
8014 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
8015 similar syntax:
8016
8017 @smallexample
8018
8019 @var{module} . @var{id}
8020 @var{scope} :: @var{id}
8021 @end smallexample
8022
8023 @noindent
8024 where @var{scope} is the name of a module or a procedure,
8025 @var{module} the name of a module, and @var{id} is any declared
8026 identifier within your program, except another module.
8027
8028 Using the @code{::} operator makes @value{GDBN} search the scope
8029 specified by @var{scope} for the identifier @var{id}. If it is not
8030 found in the specified scope, then @value{GDBN} searches all scopes
8031 enclosing the one specified by @var{scope}.
8032
8033 Using the @code{.} operator makes @value{GDBN} search the current scope for
8034 the identifier specified by @var{id} that was imported from the
8035 definition module specified by @var{module}. With this operator, it is
8036 an error if the identifier @var{id} was not imported from definition
8037 module @var{module}, or if @var{id} is not an identifier in
8038 @var{module}.
8039
8040 @node GDB/M2
8041 @subsubsection @value{GDBN} and Modula-2
8042
8043 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
8044 Five subcommands of @code{set print} and @code{show print} apply
8045 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
8046 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
8047 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
8048 analogue in Modula-2.
8049
8050 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
8051 with any language, is not useful with Modula-2. Its
8052 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
8053 created in Modula-2 as they can in C or C@t{++}. However, because an
8054 address can be specified by an integral constant, the construct
8055 @samp{@{@var{type}@}@var{adrexp}} is still useful.
8056
8057 @cindex @code{#} in Modula-2
8058 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
8059 interpreted as the beginning of a comment. Use @code{<>} instead.
8060
8061 @node Chill
8062 @subsection Chill
8063
8064 The extensions made to @value{GDBN} to support Chill only support output
8065 from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
8066 supported, and attempting to debug executables produced by them is most
8067 likely to give an error as @value{GDBN} reads in the executable's symbol
8068 table.
8069
8070 @c This used to say "... following Chill related topics ...", but since
8071 @c menus are not shown in the printed manual, it would look awkward.
8072 This section covers the Chill related topics and the features
8073 of @value{GDBN} which support these topics.
8074
8075 @menu
8076 * How modes are displayed:: How modes are displayed
8077 * Locations:: Locations and their accesses
8078 * Values and their Operations:: Values and their Operations
8079 * Chill type and range checks::
8080 * Chill defaults::
8081 @end menu
8082
8083 @node How modes are displayed
8084 @subsubsection How modes are displayed
8085
8086 The Chill Datatype- (Mode) support of @value{GDBN} is directly related
8087 with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
8088 slightly from the standard specification of the Chill language. The
8089 provided modes are:
8090
8091 @c FIXME: this @table's contents effectively disable @code by using @r
8092 @c on every @item. So why does it need @code?
8093 @table @code
8094 @item @r{@emph{Discrete modes:}}
8095 @itemize @bullet
8096 @item
8097 @emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
8098 UINT, LONG, ULONG},
8099 @item
8100 @emph{Boolean Mode} which is predefined by @code{BOOL},
8101 @item
8102 @emph{Character Mode} which is predefined by @code{CHAR},
8103 @item
8104 @emph{Set Mode} which is displayed by the keyword @code{SET}.
8105 @smallexample
8106 (@value{GDBP}) ptype x
8107 type = SET (karli = 10, susi = 20, fritzi = 100)
8108 @end smallexample
8109 If the type is an unnumbered set the set element values are omitted.
8110 @item
8111 @emph{Range Mode} which is displayed by
8112 @smallexample
8113 @code{type = <basemode>(<lower bound> : <upper bound>)}
8114 @end smallexample
8115 where @code{<lower bound>, <upper bound>} can be of any discrete literal
8116 expression (e.g. set element names).
8117 @end itemize
8118
8119 @item @r{@emph{Powerset Mode:}}
8120 A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
8121 the member mode of the powerset. The member mode can be any discrete mode.
8122 @smallexample
8123 (@value{GDBP}) ptype x
8124 type = POWERSET SET (egon, hugo, otto)
8125 @end smallexample
8126
8127 @item @r{@emph{Reference Modes:}}
8128 @itemize @bullet
8129 @item
8130 @emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
8131 followed by the mode name to which the reference is bound.
8132 @item
8133 @emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
8134 @end itemize
8135
8136 @item @r{@emph{Procedure mode}}
8137 The procedure mode is displayed by @code{type = PROC(<parameter list>)
8138 <return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
8139 list>} is a list of the parameter modes. @code{<return mode>} indicates
8140 the mode of the result of the procedure if any. The exceptionlist lists
8141 all possible exceptions which can be raised by the procedure.
8142
8143 @ignore
8144 @item @r{@emph{Instance mode}}
8145 The instance mode is represented by a structure, which has a static
8146 type, and is therefore not really of interest.
8147 @end ignore
8148
8149 @item @r{@emph{Synchronization Modes:}}
8150 @itemize @bullet
8151 @item
8152 @emph{Event Mode} which is displayed by
8153 @smallexample
8154 @code{EVENT (<event length>)}
8155 @end smallexample
8156 where @code{(<event length>)} is optional.
8157 @item
8158 @emph{Buffer Mode} which is displayed by
8159 @smallexample
8160 @code{BUFFER (<buffer length>)<buffer element mode>}
8161 @end smallexample
8162 where @code{(<buffer length>)} is optional.
8163 @end itemize
8164
8165 @item @r{@emph{Timing Modes:}}
8166 @itemize @bullet
8167 @item
8168 @emph{Duration Mode} which is predefined by @code{DURATION}
8169 @item
8170 @emph{Absolute Time Mode} which is predefined by @code{TIME}
8171 @end itemize
8172
8173 @item @r{@emph{Real Modes:}}
8174 Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
8175
8176 @item @r{@emph{String Modes:}}
8177 @itemize @bullet
8178 @item
8179 @emph{Character String Mode} which is displayed by
8180 @smallexample
8181 @code{CHARS(<string length>)}
8182 @end smallexample
8183 followed by the keyword @code{VARYING} if the String Mode is a varying
8184 mode
8185 @item
8186 @emph{Bit String Mode} which is displayed by
8187 @smallexample
8188 @code{BOOLS(<string
8189 length>)}
8190 @end smallexample
8191 @end itemize
8192
8193 @item @r{@emph{Array Mode:}}
8194 The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
8195 followed by the element mode (which may in turn be an array mode).
8196 @smallexample
8197 (@value{GDBP}) ptype x
8198 type = ARRAY (1:42)
8199 ARRAY (1:20)
8200 SET (karli = 10, susi = 20, fritzi = 100)
8201 @end smallexample
8202
8203 @item @r{@emph{Structure Mode}}
8204 The Structure mode is displayed by the keyword @code{STRUCT(<field
8205 list>)}. The @code{<field list>} consists of names and modes of fields
8206 of the structure. Variant structures have the keyword @code{CASE <field>
8207 OF <variant fields> ESAC} in their field list. Since the current version
8208 of the GNU Chill compiler doesn't implement tag processing (no runtime
8209 checks of variant fields, and therefore no debugging info), the output
8210 always displays all variant fields.
8211 @smallexample
8212 (@value{GDBP}) ptype str
8213 type = STRUCT (
8214 as x,
8215 bs x,
8216 CASE bs OF
8217 (karli):
8218 cs a
8219 (ott):
8220 ds x
8221 ESAC
8222 )
8223 @end smallexample
8224 @end table
8225
8226 @node Locations
8227 @subsubsection Locations and their accesses
8228
8229 A location in Chill is an object which can contain values.
8230
8231 A value of a location is generally accessed by the (declared) name of
8232 the location. The output conforms to the specification of values in
8233 Chill programs. How values are specified
8234 is the topic of the next section, @ref{Values and their Operations}.
8235
8236 The pseudo-location @code{RESULT} (or @code{result}) can be used to
8237 display or change the result of a currently-active procedure:
8238
8239 @smallexample
8240 set result := EXPR
8241 @end smallexample
8242
8243 @noindent
8244 This does the same as the Chill action @code{RESULT EXPR} (which
8245 is not available in @value{GDBN}).
8246
8247 Values of reference mode locations are printed by @code{PTR(<hex
8248 value>)} in case of a free reference mode, and by @code{(REF <reference
8249 mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
8250 represents the address where the reference points to. To access the
8251 value of the location referenced by the pointer, use the dereference
8252 operator @samp{->}.
8253
8254 Values of procedure mode locations are displayed by
8255 @smallexample
8256 @code{@{ PROC
8257 (<argument modes> ) <return mode> @} <address> <name of procedure
8258 location>}
8259 @end smallexample
8260 @code{<argument modes>} is a list of modes according to the parameter
8261 specification of the procedure and @code{<address>} shows the address of
8262 the entry point.
8263
8264 @ignore
8265 Locations of instance modes are displayed just like a structure with two
8266 fields specifying the @emph{process type} and the @emph{copy number} of
8267 the investigated instance location@footnote{This comes from the current
8268 implementation of instances. They are implemented as a structure (no
8269 na). The output should be something like @code{[<name of the process>;
8270 <instance number>]}.}. The field names are @code{__proc_type} and
8271 @code{__proc_copy}.
8272
8273 Locations of synchronization modes are displayed like a structure with
8274 the field name @code{__event_data} in case of a event mode location, and
8275 like a structure with the field @code{__buffer_data} in case of a buffer
8276 mode location (refer to previous paragraph).
8277
8278 Structure Mode locations are printed by @code{[.<field name>: <value>,
8279 ...]}. The @code{<field name>} corresponds to the structure mode
8280 definition and the layout of @code{<value>} varies depending of the mode
8281 of the field. If the investigated structure mode location is of variant
8282 structure mode, the variant parts of the structure are enclosed in curled
8283 braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
8284 on the same memory location and represent the current values of the
8285 memory location in their specific modes. Since no tag processing is done
8286 all variants are displayed. A variant field is printed by
8287 @code{(<variant name>) = .<field name>: <value>}. (who implements the
8288 stuff ???)
8289 @smallexample
8290 (@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
8291 [.cs: []], (susi) = [.ds: susi]}]
8292 @end smallexample
8293 @end ignore
8294
8295 Substructures of string mode-, array mode- or structure mode-values
8296 (e.g. array slices, fields of structure locations) are accessed using
8297 certain operations which are described in the next section, @ref{Values
8298 and their Operations}.
8299
8300 A location value may be interpreted as having a different mode using the
8301 location conversion. This mode conversion is written as @code{<mode
8302 name>(<location>)}. The user has to consider that the sizes of the modes
8303 have to be equal otherwise an error occurs. Furthermore, no range
8304 checking of the location against the destination mode is performed, and
8305 therefore the result can be quite confusing.
8306
8307 @smallexample
8308 (@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
8309 @end smallexample
8310
8311 @node Values and their Operations
8312 @subsubsection Values and their Operations
8313
8314 Values are used to alter locations, to investigate complex structures in
8315 more detail or to filter relevant information out of a large amount of
8316 data. There are several (mode dependent) operations defined which enable
8317 such investigations. These operations are not only applicable to
8318 constant values but also to locations, which can become quite useful
8319 when debugging complex structures. During parsing the command line
8320 (e.g. evaluating an expression) @value{GDBN} treats location names as
8321 the values behind these locations.
8322
8323 This section describes how values have to be specified and which
8324 operations are legal to be used with such values.
8325
8326 @table @code
8327 @item Literal Values
8328 Literal values are specified in the same manner as in @sc{gnu} Chill programs.
8329 For detailed specification refer to the @sc{gnu} Chill implementation Manual
8330 chapter 1.5.
8331 @c FIXME: if the Chill Manual is a Texinfo documents, the above should
8332 @c be converted to a @ref.
8333
8334 @ignore
8335 @itemize @bullet
8336 @item
8337 @emph{Integer Literals} are specified in the same manner as in Chill
8338 programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
8339 @item
8340 @emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
8341 @item
8342 @emph{Character Literals} are defined by @code{'<character>'}. (e.g.
8343 @code{'M'})
8344 @item
8345 @emph{Set Literals} are defined by a name which was specified in a set
8346 mode. The value delivered by a Set Literal is the set value. This is
8347 comparable to an enumeration in C/C@t{++} language.
8348 @item
8349 @emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
8350 emptiness literal delivers either the empty reference value, the empty
8351 procedure value or the empty instance value.
8352
8353 @item
8354 @emph{Character String Literals} are defined by a sequence of characters
8355 enclosed in single- or double quotes. If a single- or double quote has
8356 to be part of the string literal it has to be stuffed (specified twice).
8357 @item
8358 @emph{Bitstring Literals} are specified in the same manner as in Chill
8359 programs (refer z200/88 chpt 5.2.4.8).
8360 @item
8361 @emph{Floating point literals} are specified in the same manner as in
8362 (gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
8363 @end itemize
8364 @end ignore
8365
8366 @item Tuple Values
8367 A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
8368 name>} can be omitted if the mode of the tuple is unambiguous. This
8369 unambiguity is derived from the context of a evaluated expression.
8370 @code{<tuple>} can be one of the following:
8371
8372 @itemize @bullet
8373 @item @emph{Powerset Tuple}
8374 @item @emph{Array Tuple}
8375 @item @emph{Structure Tuple}
8376 Powerset tuples, array tuples and structure tuples are specified in the
8377 same manner as in Chill programs refer to z200/88 chpt 5.2.5.
8378 @end itemize
8379
8380 @item String Element Value
8381 A string element value is specified by
8382 @smallexample
8383 @code{<string value>(<index>)}
8384 @end smallexample
8385 where @code{<index>} is a integer expression. It delivers a character
8386 value which is equivalent to the character indexed by @code{<index>} in
8387 the string.
8388
8389 @item String Slice Value
8390 A string slice value is specified by @code{<string value>(<slice
8391 spec>)}, where @code{<slice spec>} can be either a range of integer
8392 expressions or specified by @code{<start expr> up <size>}.
8393 @code{<size>} denotes the number of elements which the slice contains.
8394 The delivered value is a string value, which is part of the specified
8395 string.
8396
8397 @item Array Element Values
8398 An array element value is specified by @code{<array value>(<expr>)} and
8399 delivers a array element value of the mode of the specified array.
8400
8401 @item Array Slice Values
8402 An array slice is specified by @code{<array value>(<slice spec>)}, where
8403 @code{<slice spec>} can be either a range specified by expressions or by
8404 @code{<start expr> up <size>}. @code{<size>} denotes the number of
8405 arrayelements the slice contains. The delivered value is an array value
8406 which is part of the specified array.
8407
8408 @item Structure Field Values
8409 A structure field value is derived by @code{<structure value>.<field
8410 name>}, where @code{<field name>} indicates the name of a field specified
8411 in the mode definition of the structure. The mode of the delivered value
8412 corresponds to this mode definition in the structure definition.
8413
8414 @item Procedure Call Value
8415 The procedure call value is derived from the return value of the
8416 procedure@footnote{If a procedure call is used for instance in an
8417 expression, then this procedure is called with all its side
8418 effects. This can lead to confusing results if used carelessly.}.
8419
8420 Values of duration mode locations are represented by @code{ULONG} literals.
8421
8422 Values of time mode locations appear as
8423 @smallexample
8424 @code{TIME(<secs>:<nsecs>)}
8425 @end smallexample
8426
8427
8428 @ignore
8429 This is not implemented yet:
8430 @item Built-in Value
8431 @noindent
8432 The following built in functions are provided:
8433
8434 @table @code
8435 @item @code{ADDR()}
8436 @item @code{NUM()}
8437 @item @code{PRED()}
8438 @item @code{SUCC()}
8439 @item @code{ABS()}
8440 @item @code{CARD()}
8441 @item @code{MAX()}
8442 @item @code{MIN()}
8443 @item @code{SIZE()}
8444 @item @code{UPPER()}
8445 @item @code{LOWER()}
8446 @item @code{LENGTH()}
8447 @item @code{SIN()}
8448 @item @code{COS()}
8449 @item @code{TAN()}
8450 @item @code{ARCSIN()}
8451 @item @code{ARCCOS()}
8452 @item @code{ARCTAN()}
8453 @item @code{EXP()}
8454 @item @code{LN()}
8455 @item @code{LOG()}
8456 @item @code{SQRT()}
8457 @end table
8458
8459 For a detailed description refer to the GNU Chill implementation manual
8460 chapter 1.6.
8461 @end ignore
8462
8463 @item Zero-adic Operator Value
8464 The zero-adic operator value is derived from the instance value for the
8465 current active process.
8466
8467 @item Expression Values
8468 The value delivered by an expression is the result of the evaluation of
8469 the specified expression. If there are error conditions (mode
8470 incompatibility, etc.) the evaluation of expressions is aborted with a
8471 corresponding error message. Expressions may be parenthesised which
8472 causes the evaluation of this expression before any other expression
8473 which uses the result of the parenthesised expression. The following
8474 operators are supported by @value{GDBN}:
8475
8476 @table @code
8477 @item @code{OR, ORIF, XOR}
8478 @itemx @code{AND, ANDIF}
8479 @itemx @code{NOT}
8480 Logical operators defined over operands of boolean mode.
8481
8482 @item @code{=, /=}
8483 Equality and inequality operators defined over all modes.
8484
8485 @item @code{>, >=}
8486 @itemx @code{<, <=}
8487 Relational operators defined over predefined modes.
8488
8489 @item @code{+, -}
8490 @itemx @code{*, /, MOD, REM}
8491 Arithmetic operators defined over predefined modes.
8492
8493 @item @code{-}
8494 Change sign operator.
8495
8496 @item @code{//}
8497 String concatenation operator.
8498
8499 @item @code{()}
8500 String repetition operator.
8501
8502 @item @code{->}
8503 Referenced location operator which can be used either to take the
8504 address of a location (@code{->loc}), or to dereference a reference
8505 location (@code{loc->}).
8506
8507 @item @code{OR, XOR}
8508 @itemx @code{AND}
8509 @itemx @code{NOT}
8510 Powerset and bitstring operators.
8511
8512 @item @code{>, >=}
8513 @itemx @code{<, <=}
8514 Powerset inclusion operators.
8515
8516 @item @code{IN}
8517 Membership operator.
8518 @end table
8519 @end table
8520
8521 @node Chill type and range checks
8522 @subsubsection Chill type and range checks
8523
8524 @value{GDBN} considers two Chill variables mode equivalent if the sizes
8525 of the two modes are equal. This rule applies recursively to more
8526 complex datatypes which means that complex modes are treated
8527 equivalent if all element modes (which also can be complex modes like
8528 structures, arrays, etc.) have the same size.
8529
8530 Range checking is done on all mathematical operations, assignment, array
8531 index bounds and all built in procedures.
8532
8533 Strong type checks are forced using the @value{GDBN} command @code{set
8534 check strong}. This enforces strong type and range checks on all
8535 operations where Chill constructs are used (expressions, built in
8536 functions, etc.) in respect to the semantics as defined in the z.200
8537 language specification.
8538
8539 All checks can be disabled by the @value{GDBN} command @code{set check
8540 off}.
8541
8542 @ignore
8543 @c Deviations from the Chill Standard Z200/88
8544 see last paragraph ?
8545 @end ignore
8546
8547 @node Chill defaults
8548 @subsubsection Chill defaults
8549
8550 If type and range checking are set automatically by @value{GDBN}, they
8551 both default to @code{on} whenever the working language changes to
8552 Chill. This happens regardless of whether you or @value{GDBN}
8553 selected the working language.
8554
8555 If you allow @value{GDBN} to set the language automatically, then entering
8556 code compiled from a file whose name ends with @file{.ch} sets the
8557 working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
8558 the language automatically}, for further details.
8559
8560 @node Symbols
8561 @chapter Examining the Symbol Table
8562
8563 The commands described in this chapter allow you to inquire about the
8564 symbols (names of variables, functions and types) defined in your
8565 program. This information is inherent in the text of your program and
8566 does not change as your program executes. @value{GDBN} finds it in your
8567 program's symbol table, in the file indicated when you started @value{GDBN}
8568 (@pxref{File Options, ,Choosing files}), or by one of the
8569 file-management commands (@pxref{Files, ,Commands to specify files}).
8570
8571 @cindex symbol names
8572 @cindex names of symbols
8573 @cindex quoting names
8574 Occasionally, you may need to refer to symbols that contain unusual
8575 characters, which @value{GDBN} ordinarily treats as word delimiters. The
8576 most frequent case is in referring to static variables in other
8577 source files (@pxref{Variables,,Program variables}). File names
8578 are recorded in object files as debugging symbols, but @value{GDBN} would
8579 ordinarily parse a typical file name, like @file{foo.c}, as the three words
8580 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
8581 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
8582
8583 @smallexample
8584 p 'foo.c'::x
8585 @end smallexample
8586
8587 @noindent
8588 looks up the value of @code{x} in the scope of the file @file{foo.c}.
8589
8590 @table @code
8591 @kindex info address
8592 @cindex address of a symbol
8593 @item info address @var{symbol}
8594 Describe where the data for @var{symbol} is stored. For a register
8595 variable, this says which register it is kept in. For a non-register
8596 local variable, this prints the stack-frame offset at which the variable
8597 is always stored.
8598
8599 Note the contrast with @samp{print &@var{symbol}}, which does not work
8600 at all for a register variable, and for a stack local variable prints
8601 the exact address of the current instantiation of the variable.
8602
8603 @kindex info symbol
8604 @cindex symbol from address
8605 @item info symbol @var{addr}
8606 Print the name of a symbol which is stored at the address @var{addr}.
8607 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
8608 nearest symbol and an offset from it:
8609
8610 @smallexample
8611 (@value{GDBP}) info symbol 0x54320
8612 _initialize_vx + 396 in section .text
8613 @end smallexample
8614
8615 @noindent
8616 This is the opposite of the @code{info address} command. You can use
8617 it to find out the name of a variable or a function given its address.
8618
8619 @kindex whatis
8620 @item whatis @var{expr}
8621 Print the data type of expression @var{expr}. @var{expr} is not
8622 actually evaluated, and any side-effecting operations (such as
8623 assignments or function calls) inside it do not take place.
8624 @xref{Expressions, ,Expressions}.
8625
8626 @item whatis
8627 Print the data type of @code{$}, the last value in the value history.
8628
8629 @kindex ptype
8630 @item ptype @var{typename}
8631 Print a description of data type @var{typename}. @var{typename} may be
8632 the name of a type, or for C code it may have the form @samp{class
8633 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
8634 @var{union-tag}} or @samp{enum @var{enum-tag}}.
8635
8636 @item ptype @var{expr}
8637 @itemx ptype
8638 Print a description of the type of expression @var{expr}. @code{ptype}
8639 differs from @code{whatis} by printing a detailed description, instead
8640 of just the name of the type.
8641
8642 For example, for this variable declaration:
8643
8644 @smallexample
8645 struct complex @{double real; double imag;@} v;
8646 @end smallexample
8647
8648 @noindent
8649 the two commands give this output:
8650
8651 @smallexample
8652 @group
8653 (@value{GDBP}) whatis v
8654 type = struct complex
8655 (@value{GDBP}) ptype v
8656 type = struct complex @{
8657 double real;
8658 double imag;
8659 @}
8660 @end group
8661 @end smallexample
8662
8663 @noindent
8664 As with @code{whatis}, using @code{ptype} without an argument refers to
8665 the type of @code{$}, the last value in the value history.
8666
8667 @kindex info types
8668 @item info types @var{regexp}
8669 @itemx info types
8670 Print a brief description of all types whose names match @var{regexp}
8671 (or all types in your program, if you supply no argument). Each
8672 complete typename is matched as though it were a complete line; thus,
8673 @samp{i type value} gives information on all types in your program whose
8674 names include the string @code{value}, but @samp{i type ^value$} gives
8675 information only on types whose complete name is @code{value}.
8676
8677 This command differs from @code{ptype} in two ways: first, like
8678 @code{whatis}, it does not print a detailed description; second, it
8679 lists all source files where a type is defined.
8680
8681 @kindex info scope
8682 @cindex local variables
8683 @item info scope @var{addr}
8684 List all the variables local to a particular scope. This command
8685 accepts a location---a function name, a source line, or an address
8686 preceded by a @samp{*}, and prints all the variables local to the
8687 scope defined by that location. For example:
8688
8689 @smallexample
8690 (@value{GDBP}) @b{info scope command_line_handler}
8691 Scope for command_line_handler:
8692 Symbol rl is an argument at stack/frame offset 8, length 4.
8693 Symbol linebuffer is in static storage at address 0x150a18, length 4.
8694 Symbol linelength is in static storage at address 0x150a1c, length 4.
8695 Symbol p is a local variable in register $esi, length 4.
8696 Symbol p1 is a local variable in register $ebx, length 4.
8697 Symbol nline is a local variable in register $edx, length 4.
8698 Symbol repeat is a local variable at frame offset -8, length 4.
8699 @end smallexample
8700
8701 @noindent
8702 This command is especially useful for determining what data to collect
8703 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
8704 collect}.
8705
8706 @kindex info source
8707 @item info source
8708 Show the name of the current source file---that is, the source file for
8709 the function containing the current point of execution---and the language
8710 it was written in.
8711
8712 @kindex info sources
8713 @item info sources
8714 Print the names of all source files in your program for which there is
8715 debugging information, organized into two lists: files whose symbols
8716 have already been read, and files whose symbols will be read when needed.
8717
8718 @kindex info functions
8719 @item info functions
8720 Print the names and data types of all defined functions.
8721
8722 @item info functions @var{regexp}
8723 Print the names and data types of all defined functions
8724 whose names contain a match for regular expression @var{regexp}.
8725 Thus, @samp{info fun step} finds all functions whose names
8726 include @code{step}; @samp{info fun ^step} finds those whose names
8727 start with @code{step}. If a function name contains characters
8728 that conflict with the regular expression language (eg.
8729 @samp{operator*()}), they may be quoted with a backslash.
8730
8731 @kindex info variables
8732 @item info variables
8733 Print the names and data types of all variables that are declared
8734 outside of functions (i.e.@: excluding local variables).
8735
8736 @item info variables @var{regexp}
8737 Print the names and data types of all variables (except for local
8738 variables) whose names contain a match for regular expression
8739 @var{regexp}.
8740
8741 @ignore
8742 This was never implemented.
8743 @kindex info methods
8744 @item info methods
8745 @itemx info methods @var{regexp}
8746 The @code{info methods} command permits the user to examine all defined
8747 methods within C@t{++} program, or (with the @var{regexp} argument) a
8748 specific set of methods found in the various C@t{++} classes. Many
8749 C@t{++} classes provide a large number of methods. Thus, the output
8750 from the @code{ptype} command can be overwhelming and hard to use. The
8751 @code{info-methods} command filters the methods, printing only those
8752 which match the regular-expression @var{regexp}.
8753 @end ignore
8754
8755 @cindex reloading symbols
8756 Some systems allow individual object files that make up your program to
8757 be replaced without stopping and restarting your program. For example,
8758 in VxWorks you can simply recompile a defective object file and keep on
8759 running. If you are running on one of these systems, you can allow
8760 @value{GDBN} to reload the symbols for automatically relinked modules:
8761
8762 @table @code
8763 @kindex set symbol-reloading
8764 @item set symbol-reloading on
8765 Replace symbol definitions for the corresponding source file when an
8766 object file with a particular name is seen again.
8767
8768 @item set symbol-reloading off
8769 Do not replace symbol definitions when encountering object files of the
8770 same name more than once. This is the default state; if you are not
8771 running on a system that permits automatic relinking of modules, you
8772 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
8773 may discard symbols when linking large programs, that may contain
8774 several modules (from different directories or libraries) with the same
8775 name.
8776
8777 @kindex show symbol-reloading
8778 @item show symbol-reloading
8779 Show the current @code{on} or @code{off} setting.
8780 @end table
8781
8782 @kindex set opaque-type-resolution
8783 @item set opaque-type-resolution on
8784 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
8785 declared as a pointer to a @code{struct}, @code{class}, or
8786 @code{union}---for example, @code{struct MyType *}---that is used in one
8787 source file although the full declaration of @code{struct MyType} is in
8788 another source file. The default is on.
8789
8790 A change in the setting of this subcommand will not take effect until
8791 the next time symbols for a file are loaded.
8792
8793 @item set opaque-type-resolution off
8794 Tell @value{GDBN} not to resolve opaque types. In this case, the type
8795 is printed as follows:
8796 @smallexample
8797 @{<no data fields>@}
8798 @end smallexample
8799
8800 @kindex show opaque-type-resolution
8801 @item show opaque-type-resolution
8802 Show whether opaque types are resolved or not.
8803
8804 @kindex maint print symbols
8805 @cindex symbol dump
8806 @kindex maint print psymbols
8807 @cindex partial symbol dump
8808 @item maint print symbols @var{filename}
8809 @itemx maint print psymbols @var{filename}
8810 @itemx maint print msymbols @var{filename}
8811 Write a dump of debugging symbol data into the file @var{filename}.
8812 These commands are used to debug the @value{GDBN} symbol-reading code. Only
8813 symbols with debugging data are included. If you use @samp{maint print
8814 symbols}, @value{GDBN} includes all the symbols for which it has already
8815 collected full details: that is, @var{filename} reflects symbols for
8816 only those files whose symbols @value{GDBN} has read. You can use the
8817 command @code{info sources} to find out which files these are. If you
8818 use @samp{maint print psymbols} instead, the dump shows information about
8819 symbols that @value{GDBN} only knows partially---that is, symbols defined in
8820 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
8821 @samp{maint print msymbols} dumps just the minimal symbol information
8822 required for each object file from which @value{GDBN} has read some symbols.
8823 @xref{Files, ,Commands to specify files}, for a discussion of how
8824 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
8825 @end table
8826
8827 @node Altering
8828 @chapter Altering Execution
8829
8830 Once you think you have found an error in your program, you might want to
8831 find out for certain whether correcting the apparent error would lead to
8832 correct results in the rest of the run. You can find the answer by
8833 experiment, using the @value{GDBN} features for altering execution of the
8834 program.
8835
8836 For example, you can store new values into variables or memory
8837 locations, give your program a signal, restart it at a different
8838 address, or even return prematurely from a function.
8839
8840 @menu
8841 * Assignment:: Assignment to variables
8842 * Jumping:: Continuing at a different address
8843 * Signaling:: Giving your program a signal
8844 * Returning:: Returning from a function
8845 * Calling:: Calling your program's functions
8846 * Patching:: Patching your program
8847 @end menu
8848
8849 @node Assignment
8850 @section Assignment to variables
8851
8852 @cindex assignment
8853 @cindex setting variables
8854 To alter the value of a variable, evaluate an assignment expression.
8855 @xref{Expressions, ,Expressions}. For example,
8856
8857 @smallexample
8858 print x=4
8859 @end smallexample
8860
8861 @noindent
8862 stores the value 4 into the variable @code{x}, and then prints the
8863 value of the assignment expression (which is 4).
8864 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
8865 information on operators in supported languages.
8866
8867 @kindex set variable
8868 @cindex variables, setting
8869 If you are not interested in seeing the value of the assignment, use the
8870 @code{set} command instead of the @code{print} command. @code{set} is
8871 really the same as @code{print} except that the expression's value is
8872 not printed and is not put in the value history (@pxref{Value History,
8873 ,Value history}). The expression is evaluated only for its effects.
8874
8875 If the beginning of the argument string of the @code{set} command
8876 appears identical to a @code{set} subcommand, use the @code{set
8877 variable} command instead of just @code{set}. This command is identical
8878 to @code{set} except for its lack of subcommands. For example, if your
8879 program has a variable @code{width}, you get an error if you try to set
8880 a new value with just @samp{set width=13}, because @value{GDBN} has the
8881 command @code{set width}:
8882
8883 @smallexample
8884 (@value{GDBP}) whatis width
8885 type = double
8886 (@value{GDBP}) p width
8887 $4 = 13
8888 (@value{GDBP}) set width=47
8889 Invalid syntax in expression.
8890 @end smallexample
8891
8892 @noindent
8893 The invalid expression, of course, is @samp{=47}. In
8894 order to actually set the program's variable @code{width}, use
8895
8896 @smallexample
8897 (@value{GDBP}) set var width=47
8898 @end smallexample
8899
8900 Because the @code{set} command has many subcommands that can conflict
8901 with the names of program variables, it is a good idea to use the
8902 @code{set variable} command instead of just @code{set}. For example, if
8903 your program has a variable @code{g}, you run into problems if you try
8904 to set a new value with just @samp{set g=4}, because @value{GDBN} has
8905 the command @code{set gnutarget}, abbreviated @code{set g}:
8906
8907 @smallexample
8908 @group
8909 (@value{GDBP}) whatis g
8910 type = double
8911 (@value{GDBP}) p g
8912 $1 = 1
8913 (@value{GDBP}) set g=4
8914 (@value{GDBP}) p g
8915 $2 = 1
8916 (@value{GDBP}) r
8917 The program being debugged has been started already.
8918 Start it from the beginning? (y or n) y
8919 Starting program: /home/smith/cc_progs/a.out
8920 "/home/smith/cc_progs/a.out": can't open to read symbols:
8921 Invalid bfd target.
8922 (@value{GDBP}) show g
8923 The current BFD target is "=4".
8924 @end group
8925 @end smallexample
8926
8927 @noindent
8928 The program variable @code{g} did not change, and you silently set the
8929 @code{gnutarget} to an invalid value. In order to set the variable
8930 @code{g}, use
8931
8932 @smallexample
8933 (@value{GDBP}) set var g=4
8934 @end smallexample
8935
8936 @value{GDBN} allows more implicit conversions in assignments than C; you can
8937 freely store an integer value into a pointer variable or vice versa,
8938 and you can convert any structure to any other structure that is the
8939 same length or shorter.
8940 @comment FIXME: how do structs align/pad in these conversions?
8941 @comment /doc@cygnus.com 18dec1990
8942
8943 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
8944 construct to generate a value of specified type at a specified address
8945 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
8946 to memory location @code{0x83040} as an integer (which implies a certain size
8947 and representation in memory), and
8948
8949 @smallexample
8950 set @{int@}0x83040 = 4
8951 @end smallexample
8952
8953 @noindent
8954 stores the value 4 into that memory location.
8955
8956 @node Jumping
8957 @section Continuing at a different address
8958
8959 Ordinarily, when you continue your program, you do so at the place where
8960 it stopped, with the @code{continue} command. You can instead continue at
8961 an address of your own choosing, with the following commands:
8962
8963 @table @code
8964 @kindex jump
8965 @item jump @var{linespec}
8966 Resume execution at line @var{linespec}. Execution stops again
8967 immediately if there is a breakpoint there. @xref{List, ,Printing
8968 source lines}, for a description of the different forms of
8969 @var{linespec}. It is common practice to use the @code{tbreak} command
8970 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
8971 breakpoints}.
8972
8973 The @code{jump} command does not change the current stack frame, or
8974 the stack pointer, or the contents of any memory location or any
8975 register other than the program counter. If line @var{linespec} is in
8976 a different function from the one currently executing, the results may
8977 be bizarre if the two functions expect different patterns of arguments or
8978 of local variables. For this reason, the @code{jump} command requests
8979 confirmation if the specified line is not in the function currently
8980 executing. However, even bizarre results are predictable if you are
8981 well acquainted with the machine-language code of your program.
8982
8983 @item jump *@var{address}
8984 Resume execution at the instruction at address @var{address}.
8985 @end table
8986
8987 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
8988 On many systems, you can get much the same effect as the @code{jump}
8989 command by storing a new value into the register @code{$pc}. The
8990 difference is that this does not start your program running; it only
8991 changes the address of where it @emph{will} run when you continue. For
8992 example,
8993
8994 @smallexample
8995 set $pc = 0x485
8996 @end smallexample
8997
8998 @noindent
8999 makes the next @code{continue} command or stepping command execute at
9000 address @code{0x485}, rather than at the address where your program stopped.
9001 @xref{Continuing and Stepping, ,Continuing and stepping}.
9002
9003 The most common occasion to use the @code{jump} command is to back
9004 up---perhaps with more breakpoints set---over a portion of a program
9005 that has already executed, in order to examine its execution in more
9006 detail.
9007
9008 @c @group
9009 @node Signaling
9010 @section Giving your program a signal
9011
9012 @table @code
9013 @kindex signal
9014 @item signal @var{signal}
9015 Resume execution where your program stopped, but immediately give it the
9016 signal @var{signal}. @var{signal} can be the name or the number of a
9017 signal. For example, on many systems @code{signal 2} and @code{signal
9018 SIGINT} are both ways of sending an interrupt signal.
9019
9020 Alternatively, if @var{signal} is zero, continue execution without
9021 giving a signal. This is useful when your program stopped on account of
9022 a signal and would ordinary see the signal when resumed with the
9023 @code{continue} command; @samp{signal 0} causes it to resume without a
9024 signal.
9025
9026 @code{signal} does not repeat when you press @key{RET} a second time
9027 after executing the command.
9028 @end table
9029 @c @end group
9030
9031 Invoking the @code{signal} command is not the same as invoking the
9032 @code{kill} utility from the shell. Sending a signal with @code{kill}
9033 causes @value{GDBN} to decide what to do with the signal depending on
9034 the signal handling tables (@pxref{Signals}). The @code{signal} command
9035 passes the signal directly to your program.
9036
9037
9038 @node Returning
9039 @section Returning from a function
9040
9041 @table @code
9042 @cindex returning from a function
9043 @kindex return
9044 @item return
9045 @itemx return @var{expression}
9046 You can cancel execution of a function call with the @code{return}
9047 command. If you give an
9048 @var{expression} argument, its value is used as the function's return
9049 value.
9050 @end table
9051
9052 When you use @code{return}, @value{GDBN} discards the selected stack frame
9053 (and all frames within it). You can think of this as making the
9054 discarded frame return prematurely. If you wish to specify a value to
9055 be returned, give that value as the argument to @code{return}.
9056
9057 This pops the selected stack frame (@pxref{Selection, ,Selecting a
9058 frame}), and any other frames inside of it, leaving its caller as the
9059 innermost remaining frame. That frame becomes selected. The
9060 specified value is stored in the registers used for returning values
9061 of functions.
9062
9063 The @code{return} command does not resume execution; it leaves the
9064 program stopped in the state that would exist if the function had just
9065 returned. In contrast, the @code{finish} command (@pxref{Continuing
9066 and Stepping, ,Continuing and stepping}) resumes execution until the
9067 selected stack frame returns naturally.
9068
9069 @node Calling
9070 @section Calling program functions
9071
9072 @cindex calling functions
9073 @kindex call
9074 @table @code
9075 @item call @var{expr}
9076 Evaluate the expression @var{expr} without displaying @code{void}
9077 returned values.
9078 @end table
9079
9080 You can use this variant of the @code{print} command if you want to
9081 execute a function from your program, but without cluttering the output
9082 with @code{void} returned values. If the result is not void, it
9083 is printed and saved in the value history.
9084
9085 @c OBSOLETE For the A29K, a user-controlled variable @code{call_scratch_address},
9086 @c OBSOLETE specifies the location of a scratch area to be used when @value{GDBN}
9087 @c OBSOLETE calls a function in the target. This is necessary because the usual
9088 @c OBSOLETE method of putting the scratch area on the stack does not work in systems
9089 @c OBSOLETE that have separate instruction and data spaces.
9090
9091 @node Patching
9092 @section Patching programs
9093
9094 @cindex patching binaries
9095 @cindex writing into executables
9096 @cindex writing into corefiles
9097
9098 By default, @value{GDBN} opens the file containing your program's
9099 executable code (or the corefile) read-only. This prevents accidental
9100 alterations to machine code; but it also prevents you from intentionally
9101 patching your program's binary.
9102
9103 If you'd like to be able to patch the binary, you can specify that
9104 explicitly with the @code{set write} command. For example, you might
9105 want to turn on internal debugging flags, or even to make emergency
9106 repairs.
9107
9108 @table @code
9109 @kindex set write
9110 @item set write on
9111 @itemx set write off
9112 If you specify @samp{set write on}, @value{GDBN} opens executable and
9113 core files for both reading and writing; if you specify @samp{set write
9114 off} (the default), @value{GDBN} opens them read-only.
9115
9116 If you have already loaded a file, you must load it again (using the
9117 @code{exec-file} or @code{core-file} command) after changing @code{set
9118 write}, for your new setting to take effect.
9119
9120 @item show write
9121 @kindex show write
9122 Display whether executable files and core files are opened for writing
9123 as well as reading.
9124 @end table
9125
9126 @node GDB Files
9127 @chapter @value{GDBN} Files
9128
9129 @value{GDBN} needs to know the file name of the program to be debugged,
9130 both in order to read its symbol table and in order to start your
9131 program. To debug a core dump of a previous run, you must also tell
9132 @value{GDBN} the name of the core dump file.
9133
9134 @menu
9135 * Files:: Commands to specify files
9136 * Symbol Errors:: Errors reading symbol files
9137 @end menu
9138
9139 @node Files
9140 @section Commands to specify files
9141
9142 @cindex symbol table
9143 @cindex core dump file
9144
9145 You may want to specify executable and core dump file names. The usual
9146 way to do this is at start-up time, using the arguments to
9147 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
9148 Out of @value{GDBN}}).
9149
9150 Occasionally it is necessary to change to a different file during a
9151 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
9152 a file you want to use. In these situations the @value{GDBN} commands
9153 to specify new files are useful.
9154
9155 @table @code
9156 @cindex executable file
9157 @kindex file
9158 @item file @var{filename}
9159 Use @var{filename} as the program to be debugged. It is read for its
9160 symbols and for the contents of pure memory. It is also the program
9161 executed when you use the @code{run} command. If you do not specify a
9162 directory and the file is not found in the @value{GDBN} working directory,
9163 @value{GDBN} uses the environment variable @code{PATH} as a list of
9164 directories to search, just as the shell does when looking for a program
9165 to run. You can change the value of this variable, for both @value{GDBN}
9166 and your program, using the @code{path} command.
9167
9168 On systems with memory-mapped files, an auxiliary file named
9169 @file{@var{filename}.syms} may hold symbol table information for
9170 @var{filename}. If so, @value{GDBN} maps in the symbol table from
9171 @file{@var{filename}.syms}, starting up more quickly. See the
9172 descriptions of the file options @samp{-mapped} and @samp{-readnow}
9173 (available on the command line, and with the commands @code{file},
9174 @code{symbol-file}, or @code{add-symbol-file}, described below),
9175 for more information.
9176
9177 @item file
9178 @code{file} with no argument makes @value{GDBN} discard any information it
9179 has on both executable file and the symbol table.
9180
9181 @kindex exec-file
9182 @item exec-file @r{[} @var{filename} @r{]}
9183 Specify that the program to be run (but not the symbol table) is found
9184 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
9185 if necessary to locate your program. Omitting @var{filename} means to
9186 discard information on the executable file.
9187
9188 @kindex symbol-file
9189 @item symbol-file @r{[} @var{filename} @r{]}
9190 Read symbol table information from file @var{filename}. @code{PATH} is
9191 searched when necessary. Use the @code{file} command to get both symbol
9192 table and program to run from the same file.
9193
9194 @code{symbol-file} with no argument clears out @value{GDBN} information on your
9195 program's symbol table.
9196
9197 The @code{symbol-file} command causes @value{GDBN} to forget the contents
9198 of its convenience variables, the value history, and all breakpoints and
9199 auto-display expressions. This is because they may contain pointers to
9200 the internal data recording symbols and data types, which are part of
9201 the old symbol table data being discarded inside @value{GDBN}.
9202
9203 @code{symbol-file} does not repeat if you press @key{RET} again after
9204 executing it once.
9205
9206 When @value{GDBN} is configured for a particular environment, it
9207 understands debugging information in whatever format is the standard
9208 generated for that environment; you may use either a @sc{gnu} compiler, or
9209 other compilers that adhere to the local conventions.
9210 Best results are usually obtained from @sc{gnu} compilers; for example,
9211 using @code{@value{GCC}} you can generate debugging information for
9212 optimized code.
9213
9214 For most kinds of object files, with the exception of old SVR3 systems
9215 using COFF, the @code{symbol-file} command does not normally read the
9216 symbol table in full right away. Instead, it scans the symbol table
9217 quickly to find which source files and which symbols are present. The
9218 details are read later, one source file at a time, as they are needed.
9219
9220 The purpose of this two-stage reading strategy is to make @value{GDBN}
9221 start up faster. For the most part, it is invisible except for
9222 occasional pauses while the symbol table details for a particular source
9223 file are being read. (The @code{set verbose} command can turn these
9224 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
9225 warnings and messages}.)
9226
9227 We have not implemented the two-stage strategy for COFF yet. When the
9228 symbol table is stored in COFF format, @code{symbol-file} reads the
9229 symbol table data in full right away. Note that ``stabs-in-COFF''
9230 still does the two-stage strategy, since the debug info is actually
9231 in stabs format.
9232
9233 @kindex readnow
9234 @cindex reading symbols immediately
9235 @cindex symbols, reading immediately
9236 @kindex mapped
9237 @cindex memory-mapped symbol file
9238 @cindex saving symbol table
9239 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9240 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9241 You can override the @value{GDBN} two-stage strategy for reading symbol
9242 tables by using the @samp{-readnow} option with any of the commands that
9243 load symbol table information, if you want to be sure @value{GDBN} has the
9244 entire symbol table available.
9245
9246 If memory-mapped files are available on your system through the
9247 @code{mmap} system call, you can use another option, @samp{-mapped}, to
9248 cause @value{GDBN} to write the symbols for your program into a reusable
9249 file. Future @value{GDBN} debugging sessions map in symbol information
9250 from this auxiliary symbol file (if the program has not changed), rather
9251 than spending time reading the symbol table from the executable
9252 program. Using the @samp{-mapped} option has the same effect as
9253 starting @value{GDBN} with the @samp{-mapped} command-line option.
9254
9255 You can use both options together, to make sure the auxiliary symbol
9256 file has all the symbol information for your program.
9257
9258 The auxiliary symbol file for a program called @var{myprog} is called
9259 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
9260 than the corresponding executable), @value{GDBN} always attempts to use
9261 it when you debug @var{myprog}; no special options or commands are
9262 needed.
9263
9264 The @file{.syms} file is specific to the host machine where you run
9265 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
9266 symbol table. It cannot be shared across multiple host platforms.
9267
9268 @c FIXME: for now no mention of directories, since this seems to be in
9269 @c flux. 13mar1992 status is that in theory GDB would look either in
9270 @c current dir or in same dir as myprog; but issues like competing
9271 @c GDB's, or clutter in system dirs, mean that in practice right now
9272 @c only current dir is used. FFish says maybe a special GDB hierarchy
9273 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
9274 @c files.
9275
9276 @kindex core
9277 @kindex core-file
9278 @item core-file @r{[} @var{filename} @r{]}
9279 Specify the whereabouts of a core dump file to be used as the ``contents
9280 of memory''. Traditionally, core files contain only some parts of the
9281 address space of the process that generated them; @value{GDBN} can access the
9282 executable file itself for other parts.
9283
9284 @code{core-file} with no argument specifies that no core file is
9285 to be used.
9286
9287 Note that the core file is ignored when your program is actually running
9288 under @value{GDBN}. So, if you have been running your program and you
9289 wish to debug a core file instead, you must kill the subprocess in which
9290 the program is running. To do this, use the @code{kill} command
9291 (@pxref{Kill Process, ,Killing the child process}).
9292
9293 @kindex add-symbol-file
9294 @cindex dynamic linking
9295 @item add-symbol-file @var{filename} @var{address}
9296 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9297 @itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
9298 The @code{add-symbol-file} command reads additional symbol table
9299 information from the file @var{filename}. You would use this command
9300 when @var{filename} has been dynamically loaded (by some other means)
9301 into the program that is running. @var{address} should be the memory
9302 address at which the file has been loaded; @value{GDBN} cannot figure
9303 this out for itself. You can additionally specify an arbitrary number
9304 of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
9305 section name and base address for that section. You can specify any
9306 @var{address} as an expression.
9307
9308 The symbol table of the file @var{filename} is added to the symbol table
9309 originally read with the @code{symbol-file} command. You can use the
9310 @code{add-symbol-file} command any number of times; the new symbol data
9311 thus read keeps adding to the old. To discard all old symbol data
9312 instead, use the @code{symbol-file} command without any arguments.
9313
9314 @cindex relocatable object files, reading symbols from
9315 @cindex object files, relocatable, reading symbols from
9316 @cindex reading symbols from relocatable object files
9317 @cindex symbols, reading from relocatable object files
9318 @cindex @file{.o} files, reading symbols from
9319 Although @var{filename} is typically a shared library file, an
9320 executable file, or some other object file which has been fully
9321 relocated for loading into a process, you can also load symbolic
9322 information from relocatable @file{.o} files, as long as:
9323
9324 @itemize @bullet
9325 @item
9326 the file's symbolic information refers only to linker symbols defined in
9327 that file, not to symbols defined by other object files,
9328 @item
9329 every section the file's symbolic information refers to has actually
9330 been loaded into the inferior, as it appears in the file, and
9331 @item
9332 you can determine the address at which every section was loaded, and
9333 provide these to the @code{add-symbol-file} command.
9334 @end itemize
9335
9336 @noindent
9337 Some embedded operating systems, like Sun Chorus and VxWorks, can load
9338 relocatable files into an already running program; such systems
9339 typically make the requirements above easy to meet. However, it's
9340 important to recognize that many native systems use complex link
9341 procedures (@code{.linkonce} section factoring and C++ constructor table
9342 assembly, for example) that make the requirements difficult to meet. In
9343 general, one cannot assume that using @code{add-symbol-file} to read a
9344 relocatable object file's symbolic information will have the same effect
9345 as linking the relocatable object file into the program in the normal
9346 way.
9347
9348 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
9349
9350 You can use the @samp{-mapped} and @samp{-readnow} options just as with
9351 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
9352 table information for @var{filename}.
9353
9354 @kindex add-shared-symbol-file
9355 @item add-shared-symbol-file
9356 The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
9357 operating system for the Motorola 88k. @value{GDBN} automatically looks for
9358 shared libraries, however if @value{GDBN} does not find yours, you can run
9359 @code{add-shared-symbol-file}. It takes no arguments.
9360
9361 @kindex section
9362 @item section
9363 The @code{section} command changes the base address of section SECTION of
9364 the exec file to ADDR. This can be used if the exec file does not contain
9365 section addresses, (such as in the a.out format), or when the addresses
9366 specified in the file itself are wrong. Each section must be changed
9367 separately. The @code{info files} command, described below, lists all
9368 the sections and their addresses.
9369
9370 @kindex info files
9371 @kindex info target
9372 @item info files
9373 @itemx info target
9374 @code{info files} and @code{info target} are synonymous; both print the
9375 current target (@pxref{Targets, ,Specifying a Debugging Target}),
9376 including the names of the executable and core dump files currently in
9377 use by @value{GDBN}, and the files from which symbols were loaded. The
9378 command @code{help target} lists all possible targets rather than
9379 current ones.
9380
9381 @kindex maint info sections
9382 @item maint info sections
9383 Another command that can give you extra information about program sections
9384 is @code{maint info sections}. In addition to the section information
9385 displayed by @code{info files}, this command displays the flags and file
9386 offset of each section in the executable and core dump files. In addition,
9387 @code{maint info sections} provides the following command options (which
9388 may be arbitrarily combined):
9389
9390 @table @code
9391 @item ALLOBJ
9392 Display sections for all loaded object files, including shared libraries.
9393 @item @var{sections}
9394 Display info only for named @var{sections}.
9395 @item @var{section-flags}
9396 Display info only for sections for which @var{section-flags} are true.
9397 The section flags that @value{GDBN} currently knows about are:
9398 @table @code
9399 @item ALLOC
9400 Section will have space allocated in the process when loaded.
9401 Set for all sections except those containing debug information.
9402 @item LOAD
9403 Section will be loaded from the file into the child process memory.
9404 Set for pre-initialized code and data, clear for @code{.bss} sections.
9405 @item RELOC
9406 Section needs to be relocated before loading.
9407 @item READONLY
9408 Section cannot be modified by the child process.
9409 @item CODE
9410 Section contains executable code only.
9411 @item DATA
9412 Section contains data only (no executable code).
9413 @item ROM
9414 Section will reside in ROM.
9415 @item CONSTRUCTOR
9416 Section contains data for constructor/destructor lists.
9417 @item HAS_CONTENTS
9418 Section is not empty.
9419 @item NEVER_LOAD
9420 An instruction to the linker to not output the section.
9421 @item COFF_SHARED_LIBRARY
9422 A notification to the linker that the section contains
9423 COFF shared library information.
9424 @item IS_COMMON
9425 Section contains common symbols.
9426 @end table
9427 @end table
9428 @kindex set trust-readonly-sections
9429 @item set trust-readonly-sections on
9430 Tell @value{GDBN} that readonly sections in your object file
9431 really are read-only (i.e.@: that their contents will not change).
9432 In that case, @value{GDBN} can fetch values from these sections
9433 out of the object file, rather than from the target program.
9434 For some targets (notably embedded ones), this can be a significant
9435 enhancement to debugging performance.
9436
9437 The default is off.
9438
9439 @item set trust-readonly-sections off
9440 Tell @value{GDBN} not to trust readonly sections. This means that
9441 the contents of the section might change while the program is running,
9442 and must therefore be fetched from the target when needed.
9443 @end table
9444
9445 All file-specifying commands allow both absolute and relative file names
9446 as arguments. @value{GDBN} always converts the file name to an absolute file
9447 name and remembers it that way.
9448
9449 @cindex shared libraries
9450 @value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
9451 libraries.
9452
9453 @value{GDBN} automatically loads symbol definitions from shared libraries
9454 when you use the @code{run} command, or when you examine a core file.
9455 (Before you issue the @code{run} command, @value{GDBN} does not understand
9456 references to a function in a shared library, however---unless you are
9457 debugging a core file).
9458
9459 On HP-UX, if the program loads a library explicitly, @value{GDBN}
9460 automatically loads the symbols at the time of the @code{shl_load} call.
9461
9462 @c FIXME: some @value{GDBN} release may permit some refs to undef
9463 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
9464 @c FIXME...lib; check this from time to time when updating manual
9465
9466 There are times, however, when you may wish to not automatically load
9467 symbol definitions from shared libraries, such as when they are
9468 particularly large or there are many of them.
9469
9470 To control the automatic loading of shared library symbols, use the
9471 commands:
9472
9473 @table @code
9474 @kindex set auto-solib-add
9475 @item set auto-solib-add @var{mode}
9476 If @var{mode} is @code{on}, symbols from all shared object libraries
9477 will be loaded automatically when the inferior begins execution, you
9478 attach to an independently started inferior, or when the dynamic linker
9479 informs @value{GDBN} that a new library has been loaded. If @var{mode}
9480 is @code{off}, symbols must be loaded manually, using the
9481 @code{sharedlibrary} command. The default value is @code{on}.
9482
9483 @kindex show auto-solib-add
9484 @item show auto-solib-add
9485 Display the current autoloading mode.
9486 @end table
9487
9488 To explicitly load shared library symbols, use the @code{sharedlibrary}
9489 command:
9490
9491 @table @code
9492 @kindex info sharedlibrary
9493 @kindex info share
9494 @item info share
9495 @itemx info sharedlibrary
9496 Print the names of the shared libraries which are currently loaded.
9497
9498 @kindex sharedlibrary
9499 @kindex share
9500 @item sharedlibrary @var{regex}
9501 @itemx share @var{regex}
9502 Load shared object library symbols for files matching a
9503 Unix regular expression.
9504 As with files loaded automatically, it only loads shared libraries
9505 required by your program for a core file or after typing @code{run}. If
9506 @var{regex} is omitted all shared libraries required by your program are
9507 loaded.
9508 @end table
9509
9510 On some systems, such as HP-UX systems, @value{GDBN} supports
9511 autoloading shared library symbols until a limiting threshold size is
9512 reached. This provides the benefit of allowing autoloading to remain on
9513 by default, but avoids autoloading excessively large shared libraries,
9514 up to a threshold that is initially set, but which you can modify if you
9515 wish.
9516
9517 Beyond that threshold, symbols from shared libraries must be explicitly
9518 loaded. To load these symbols, use the command @code{sharedlibrary
9519 @var{filename}}. The base address of the shared library is determined
9520 automatically by @value{GDBN} and need not be specified.
9521
9522 To display or set the threshold, use the commands:
9523
9524 @table @code
9525 @kindex set auto-solib-limit
9526 @item set auto-solib-limit @var{threshold}
9527 Set the autoloading size threshold, in an integral number of megabytes.
9528 If @var{threshold} is nonzero and shared library autoloading is enabled,
9529 symbols from all shared object libraries will be loaded until the total
9530 size of the loaded shared library symbols exceeds this threshold.
9531 Otherwise, symbols must be loaded manually, using the
9532 @code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
9533 Mb).
9534
9535 @kindex show auto-solib-limit
9536 @item show auto-solib-limit
9537 Display the current autoloading size threshold, in megabytes.
9538 @end table
9539
9540 @node Symbol Errors
9541 @section Errors reading symbol files
9542
9543 While reading a symbol file, @value{GDBN} occasionally encounters problems,
9544 such as symbol types it does not recognize, or known bugs in compiler
9545 output. By default, @value{GDBN} does not notify you of such problems, since
9546 they are relatively common and primarily of interest to people
9547 debugging compilers. If you are interested in seeing information
9548 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
9549 only one message about each such type of problem, no matter how many
9550 times the problem occurs; or you can ask @value{GDBN} to print more messages,
9551 to see how many times the problems occur, with the @code{set
9552 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
9553 messages}).
9554
9555 The messages currently printed, and their meanings, include:
9556
9557 @table @code
9558 @item inner block not inside outer block in @var{symbol}
9559
9560 The symbol information shows where symbol scopes begin and end
9561 (such as at the start of a function or a block of statements). This
9562 error indicates that an inner scope block is not fully contained
9563 in its outer scope blocks.
9564
9565 @value{GDBN} circumvents the problem by treating the inner block as if it had
9566 the same scope as the outer block. In the error message, @var{symbol}
9567 may be shown as ``@code{(don't know)}'' if the outer block is not a
9568 function.
9569
9570 @item block at @var{address} out of order
9571
9572 The symbol information for symbol scope blocks should occur in
9573 order of increasing addresses. This error indicates that it does not
9574 do so.
9575
9576 @value{GDBN} does not circumvent this problem, and has trouble
9577 locating symbols in the source file whose symbols it is reading. (You
9578 can often determine what source file is affected by specifying
9579 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
9580 messages}.)
9581
9582 @item bad block start address patched
9583
9584 The symbol information for a symbol scope block has a start address
9585 smaller than the address of the preceding source line. This is known
9586 to occur in the SunOS 4.1.1 (and earlier) C compiler.
9587
9588 @value{GDBN} circumvents the problem by treating the symbol scope block as
9589 starting on the previous source line.
9590
9591 @item bad string table offset in symbol @var{n}
9592
9593 @cindex foo
9594 Symbol number @var{n} contains a pointer into the string table which is
9595 larger than the size of the string table.
9596
9597 @value{GDBN} circumvents the problem by considering the symbol to have the
9598 name @code{foo}, which may cause other problems if many symbols end up
9599 with this name.
9600
9601 @item unknown symbol type @code{0x@var{nn}}
9602
9603 The symbol information contains new data types that @value{GDBN} does
9604 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
9605 uncomprehended information, in hexadecimal.
9606
9607 @value{GDBN} circumvents the error by ignoring this symbol information.
9608 This usually allows you to debug your program, though certain symbols
9609 are not accessible. If you encounter such a problem and feel like
9610 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
9611 on @code{complain}, then go up to the function @code{read_dbx_symtab}
9612 and examine @code{*bufp} to see the symbol.
9613
9614 @item stub type has NULL name
9615
9616 @value{GDBN} could not find the full definition for a struct or class.
9617
9618 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
9619 The symbol information for a C@t{++} member function is missing some
9620 information that recent versions of the compiler should have output for
9621 it.
9622
9623 @item info mismatch between compiler and debugger
9624
9625 @value{GDBN} could not parse a type specification output by the compiler.
9626
9627 @end table
9628
9629 @node Targets
9630 @chapter Specifying a Debugging Target
9631
9632 @cindex debugging target
9633 @kindex target
9634
9635 A @dfn{target} is the execution environment occupied by your program.
9636
9637 Often, @value{GDBN} runs in the same host environment as your program;
9638 in that case, the debugging target is specified as a side effect when
9639 you use the @code{file} or @code{core} commands. When you need more
9640 flexibility---for example, running @value{GDBN} on a physically separate
9641 host, or controlling a standalone system over a serial port or a
9642 realtime system over a TCP/IP connection---you can use the @code{target}
9643 command to specify one of the target types configured for @value{GDBN}
9644 (@pxref{Target Commands, ,Commands for managing targets}).
9645
9646 @menu
9647 * Active Targets:: Active targets
9648 * Target Commands:: Commands for managing targets
9649 * Byte Order:: Choosing target byte order
9650 * Remote:: Remote debugging
9651 * KOD:: Kernel Object Display
9652
9653 @end menu
9654
9655 @node Active Targets
9656 @section Active targets
9657
9658 @cindex stacking targets
9659 @cindex active targets
9660 @cindex multiple targets
9661
9662 There are three classes of targets: processes, core files, and
9663 executable files. @value{GDBN} can work concurrently on up to three
9664 active targets, one in each class. This allows you to (for example)
9665 start a process and inspect its activity without abandoning your work on
9666 a core file.
9667
9668 For example, if you execute @samp{gdb a.out}, then the executable file
9669 @code{a.out} is the only active target. If you designate a core file as
9670 well---presumably from a prior run that crashed and coredumped---then
9671 @value{GDBN} has two active targets and uses them in tandem, looking
9672 first in the corefile target, then in the executable file, to satisfy
9673 requests for memory addresses. (Typically, these two classes of target
9674 are complementary, since core files contain only a program's
9675 read-write memory---variables and so on---plus machine status, while
9676 executable files contain only the program text and initialized data.)
9677
9678 When you type @code{run}, your executable file becomes an active process
9679 target as well. When a process target is active, all @value{GDBN}
9680 commands requesting memory addresses refer to that target; addresses in
9681 an active core file or executable file target are obscured while the
9682 process target is active.
9683
9684 Use the @code{core-file} and @code{exec-file} commands to select a new
9685 core file or executable target (@pxref{Files, ,Commands to specify
9686 files}). To specify as a target a process that is already running, use
9687 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
9688 process}).
9689
9690 @node Target Commands
9691 @section Commands for managing targets
9692
9693 @table @code
9694 @item target @var{type} @var{parameters}
9695 Connects the @value{GDBN} host environment to a target machine or
9696 process. A target is typically a protocol for talking to debugging
9697 facilities. You use the argument @var{type} to specify the type or
9698 protocol of the target machine.
9699
9700 Further @var{parameters} are interpreted by the target protocol, but
9701 typically include things like device names or host names to connect
9702 with, process numbers, and baud rates.
9703
9704 The @code{target} command does not repeat if you press @key{RET} again
9705 after executing the command.
9706
9707 @kindex help target
9708 @item help target
9709 Displays the names of all targets available. To display targets
9710 currently selected, use either @code{info target} or @code{info files}
9711 (@pxref{Files, ,Commands to specify files}).
9712
9713 @item help target @var{name}
9714 Describe a particular target, including any parameters necessary to
9715 select it.
9716
9717 @kindex set gnutarget
9718 @item set gnutarget @var{args}
9719 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
9720 knows whether it is reading an @dfn{executable},
9721 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
9722 with the @code{set gnutarget} command. Unlike most @code{target} commands,
9723 with @code{gnutarget} the @code{target} refers to a program, not a machine.
9724
9725 @quotation
9726 @emph{Warning:} To specify a file format with @code{set gnutarget},
9727 you must know the actual BFD name.
9728 @end quotation
9729
9730 @noindent
9731 @xref{Files, , Commands to specify files}.
9732
9733 @kindex show gnutarget
9734 @item show gnutarget
9735 Use the @code{show gnutarget} command to display what file format
9736 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
9737 @value{GDBN} will determine the file format for each file automatically,
9738 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
9739 @end table
9740
9741 Here are some common targets (available, or not, depending on the GDB
9742 configuration):
9743
9744 @table @code
9745 @kindex target exec
9746 @item target exec @var{program}
9747 An executable file. @samp{target exec @var{program}} is the same as
9748 @samp{exec-file @var{program}}.
9749
9750 @kindex target core
9751 @item target core @var{filename}
9752 A core dump file. @samp{target core @var{filename}} is the same as
9753 @samp{core-file @var{filename}}.
9754
9755 @kindex target remote
9756 @item target remote @var{dev}
9757 Remote serial target in GDB-specific protocol. The argument @var{dev}
9758 specifies what serial device to use for the connection (e.g.
9759 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
9760 supports the @code{load} command. This is only useful if you have
9761 some other way of getting the stub to the target system, and you can put
9762 it somewhere in memory where it won't get clobbered by the download.
9763
9764 @kindex target sim
9765 @item target sim
9766 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
9767 In general,
9768 @smallexample
9769 target sim
9770 load
9771 run
9772 @end smallexample
9773 @noindent
9774 works; however, you cannot assume that a specific memory map, device
9775 drivers, or even basic I/O is available, although some simulators do
9776 provide these. For info about any processor-specific simulator details,
9777 see the appropriate section in @ref{Embedded Processors, ,Embedded
9778 Processors}.
9779
9780 @end table
9781
9782 Some configurations may include these targets as well:
9783
9784 @table @code
9785
9786 @kindex target nrom
9787 @item target nrom @var{dev}
9788 NetROM ROM emulator. This target only supports downloading.
9789
9790 @end table
9791
9792 Different targets are available on different configurations of @value{GDBN};
9793 your configuration may have more or fewer targets.
9794
9795 Many remote targets require you to download the executable's code
9796 once you've successfully established a connection.
9797
9798 @table @code
9799
9800 @kindex load @var{filename}
9801 @item load @var{filename}
9802 Depending on what remote debugging facilities are configured into
9803 @value{GDBN}, the @code{load} command may be available. Where it exists, it
9804 is meant to make @var{filename} (an executable) available for debugging
9805 on the remote system---by downloading, or dynamic linking, for example.
9806 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
9807 the @code{add-symbol-file} command.
9808
9809 If your @value{GDBN} does not have a @code{load} command, attempting to
9810 execute it gets the error message ``@code{You can't do that when your
9811 target is @dots{}}''
9812
9813 The file is loaded at whatever address is specified in the executable.
9814 For some object file formats, you can specify the load address when you
9815 link the program; for other formats, like a.out, the object file format
9816 specifies a fixed address.
9817 @c FIXME! This would be a good place for an xref to the GNU linker doc.
9818
9819 @code{load} does not repeat if you press @key{RET} again after using it.
9820 @end table
9821
9822 @node Byte Order
9823 @section Choosing target byte order
9824
9825 @cindex choosing target byte order
9826 @cindex target byte order
9827
9828 Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
9829 offer the ability to run either big-endian or little-endian byte
9830 orders. Usually the executable or symbol will include a bit to
9831 designate the endian-ness, and you will not need to worry about
9832 which to use. However, you may still find it useful to adjust
9833 @value{GDBN}'s idea of processor endian-ness manually.
9834
9835 @table @code
9836 @kindex set endian big
9837 @item set endian big
9838 Instruct @value{GDBN} to assume the target is big-endian.
9839
9840 @kindex set endian little
9841 @item set endian little
9842 Instruct @value{GDBN} to assume the target is little-endian.
9843
9844 @kindex set endian auto
9845 @item set endian auto
9846 Instruct @value{GDBN} to use the byte order associated with the
9847 executable.
9848
9849 @item show endian
9850 Display @value{GDBN}'s current idea of the target byte order.
9851
9852 @end table
9853
9854 Note that these commands merely adjust interpretation of symbolic
9855 data on the host, and that they have absolutely no effect on the
9856 target system.
9857
9858 @node Remote
9859 @section Remote debugging
9860 @cindex remote debugging
9861
9862 If you are trying to debug a program running on a machine that cannot run
9863 @value{GDBN} in the usual way, it is often useful to use remote debugging.
9864 For example, you might use remote debugging on an operating system kernel,
9865 or on a small system which does not have a general purpose operating system
9866 powerful enough to run a full-featured debugger.
9867
9868 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
9869 to make this work with particular debugging targets. In addition,
9870 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
9871 but not specific to any particular target system) which you can use if you
9872 write the remote stubs---the code that runs on the remote system to
9873 communicate with @value{GDBN}.
9874
9875 Other remote targets may be available in your
9876 configuration of @value{GDBN}; use @code{help target} to list them.
9877
9878 @node KOD
9879 @section Kernel Object Display
9880
9881 @cindex kernel object display
9882 @cindex kernel object
9883 @cindex KOD
9884
9885 Some targets support kernel object display. Using this facility,
9886 @value{GDBN} communicates specially with the underlying operating system
9887 and can display information about operating system-level objects such as
9888 mutexes and other synchronization objects. Exactly which objects can be
9889 displayed is determined on a per-OS basis.
9890
9891 Use the @code{set os} command to set the operating system. This tells
9892 @value{GDBN} which kernel object display module to initialize:
9893
9894 @smallexample
9895 (@value{GDBP}) set os cisco
9896 @end smallexample
9897
9898 If @code{set os} succeeds, @value{GDBN} will display some information
9899 about the operating system, and will create a new @code{info} command
9900 which can be used to query the target. The @code{info} command is named
9901 after the operating system:
9902
9903 @smallexample
9904 (@value{GDBP}) info cisco
9905 List of Cisco Kernel Objects
9906 Object Description
9907 any Any and all objects
9908 @end smallexample
9909
9910 Further subcommands can be used to query about particular objects known
9911 by the kernel.
9912
9913 There is currently no way to determine whether a given operating system
9914 is supported other than to try it.
9915
9916
9917 @node Remote Debugging
9918 @chapter Debugging remote programs
9919
9920 @menu
9921 * Server:: Using the gdbserver program
9922 * NetWare:: Using the gdbserve.nlm program
9923 * remote stub:: Implementing a remote stub
9924 @end menu
9925
9926 @node Server
9927 @section Using the @code{gdbserver} program
9928
9929 @kindex gdbserver
9930 @cindex remote connection without stubs
9931 @code{gdbserver} is a control program for Unix-like systems, which
9932 allows you to connect your program with a remote @value{GDBN} via
9933 @code{target remote}---but without linking in the usual debugging stub.
9934
9935 @code{gdbserver} is not a complete replacement for the debugging stubs,
9936 because it requires essentially the same operating-system facilities
9937 that @value{GDBN} itself does. In fact, a system that can run
9938 @code{gdbserver} to connect to a remote @value{GDBN} could also run
9939 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9940 because it is a much smaller program than @value{GDBN} itself. It is
9941 also easier to port than all of @value{GDBN}, so you may be able to get
9942 started more quickly on a new system by using @code{gdbserver}.
9943 Finally, if you develop code for real-time systems, you may find that
9944 the tradeoffs involved in real-time operation make it more convenient to
9945 do as much development work as possible on another system, for example
9946 by cross-compiling. You can use @code{gdbserver} to make a similar
9947 choice for debugging.
9948
9949 @value{GDBN} and @code{gdbserver} communicate via either a serial line
9950 or a TCP connection, using the standard @value{GDBN} remote serial
9951 protocol.
9952
9953 @table @emph
9954 @item On the target machine,
9955 you need to have a copy of the program you want to debug.
9956 @code{gdbserver} does not need your program's symbol table, so you can
9957 strip the program if necessary to save space. @value{GDBN} on the host
9958 system does all the symbol handling.
9959
9960 To use the server, you must tell it how to communicate with @value{GDBN};
9961 the name of your program; and the arguments for your program. The usual
9962 syntax is:
9963
9964 @smallexample
9965 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9966 @end smallexample
9967
9968 @var{comm} is either a device name (to use a serial line) or a TCP
9969 hostname and portnumber. For example, to debug Emacs with the argument
9970 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
9971 @file{/dev/com1}:
9972
9973 @smallexample
9974 target> gdbserver /dev/com1 emacs foo.txt
9975 @end smallexample
9976
9977 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
9978 with it.
9979
9980 To use a TCP connection instead of a serial line:
9981
9982 @smallexample
9983 target> gdbserver host:2345 emacs foo.txt
9984 @end smallexample
9985
9986 The only difference from the previous example is the first argument,
9987 specifying that you are communicating with the host @value{GDBN} via
9988 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9989 expect a TCP connection from machine @samp{host} to local TCP port 2345.
9990 (Currently, the @samp{host} part is ignored.) You can choose any number
9991 you want for the port number as long as it does not conflict with any
9992 TCP ports already in use on the target system (for example, @code{23} is
9993 reserved for @code{telnet}).@footnote{If you choose a port number that
9994 conflicts with another service, @code{gdbserver} prints an error message
9995 and exits.} You must use the same port number with the host @value{GDBN}
9996 @code{target remote} command.
9997
9998 On some targets, @code{gdbserver} can also attach to running programs.
9999 This is accomplished via the @code{--attach} argument. The syntax is:
10000
10001 @smallexample
10002 target> gdbserver @var{comm} --attach @var{pid}
10003 @end smallexample
10004
10005 @var{pid} is the process ID of a currently running process. It isn't necessary
10006 to point @code{gdbserver} at a binary for the running process.
10007
10008 @item On the @value{GDBN} host machine,
10009 you need an unstripped copy of your program, since @value{GDBN} needs
10010 symbols and debugging information. Start up @value{GDBN} as usual,
10011 using the name of the local copy of your program as the first argument.
10012 (You may also need the @w{@samp{--baud}} option if the serial line is
10013 running at anything other than 9600@dmn{bps}.) After that, use @code{target
10014 remote} to establish communications with @code{gdbserver}. Its argument
10015 is either a device name (usually a serial device, like
10016 @file{/dev/ttyb}), or a TCP port descriptor in the form
10017 @code{@var{host}:@var{PORT}}. For example:
10018
10019 @smallexample
10020 (@value{GDBP}) target remote /dev/ttyb
10021 @end smallexample
10022
10023 @noindent
10024 communicates with the server via serial line @file{/dev/ttyb}, and
10025
10026 @smallexample
10027 (@value{GDBP}) target remote the-target:2345
10028 @end smallexample
10029
10030 @noindent
10031 communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
10032 For TCP connections, you must start up @code{gdbserver} prior to using
10033 the @code{target remote} command. Otherwise you may get an error whose
10034 text depends on the host system, but which usually looks something like
10035 @samp{Connection refused}.
10036 @end table
10037
10038 @node NetWare
10039 @section Using the @code{gdbserve.nlm} program
10040
10041 @kindex gdbserve.nlm
10042 @code{gdbserve.nlm} is a control program for NetWare systems, which
10043 allows you to connect your program with a remote @value{GDBN} via
10044 @code{target remote}.
10045
10046 @value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
10047 using the standard @value{GDBN} remote serial protocol.
10048
10049 @table @emph
10050 @item On the target machine,
10051 you need to have a copy of the program you want to debug.
10052 @code{gdbserve.nlm} does not need your program's symbol table, so you
10053 can strip the program if necessary to save space. @value{GDBN} on the
10054 host system does all the symbol handling.
10055
10056 To use the server, you must tell it how to communicate with
10057 @value{GDBN}; the name of your program; and the arguments for your
10058 program. The syntax is:
10059
10060 @smallexample
10061 load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
10062 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
10063 @end smallexample
10064
10065 @var{board} and @var{port} specify the serial line; @var{baud} specifies
10066 the baud rate used by the connection. @var{port} and @var{node} default
10067 to 0, @var{baud} defaults to 9600@dmn{bps}.
10068
10069 For example, to debug Emacs with the argument @samp{foo.txt}and
10070 communicate with @value{GDBN} over serial port number 2 or board 1
10071 using a 19200@dmn{bps} connection:
10072
10073 @smallexample
10074 load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
10075 @end smallexample
10076
10077 @item On the @value{GDBN} host machine,
10078 you need an unstripped copy of your program, since @value{GDBN} needs
10079 symbols and debugging information. Start up @value{GDBN} as usual,
10080 using the name of the local copy of your program as the first argument.
10081 (You may also need the @w{@samp{--baud}} option if the serial line is
10082 running at anything other than 9600@dmn{bps}. After that, use @code{target
10083 remote} to establish communications with @code{gdbserve.nlm}. Its
10084 argument is a device name (usually a serial device, like
10085 @file{/dev/ttyb}). For example:
10086
10087 @smallexample
10088 (@value{GDBP}) target remote /dev/ttyb
10089 @end smallexample
10090
10091 @noindent
10092 communications with the server via serial line @file{/dev/ttyb}.
10093 @end table
10094
10095 @node remote stub
10096 @section Implementing a remote stub
10097
10098 @cindex debugging stub, example
10099 @cindex remote stub, example
10100 @cindex stub example, remote debugging
10101 The stub files provided with @value{GDBN} implement the target side of the
10102 communication protocol, and the @value{GDBN} side is implemented in the
10103 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
10104 these subroutines to communicate, and ignore the details. (If you're
10105 implementing your own stub file, you can still ignore the details: start
10106 with one of the existing stub files. @file{sparc-stub.c} is the best
10107 organized, and therefore the easiest to read.)
10108
10109 @cindex remote serial debugging, overview
10110 To debug a program running on another machine (the debugging
10111 @dfn{target} machine), you must first arrange for all the usual
10112 prerequisites for the program to run by itself. For example, for a C
10113 program, you need:
10114
10115 @enumerate
10116 @item
10117 A startup routine to set up the C runtime environment; these usually
10118 have a name like @file{crt0}. The startup routine may be supplied by
10119 your hardware supplier, or you may have to write your own.
10120
10121 @item
10122 A C subroutine library to support your program's
10123 subroutine calls, notably managing input and output.
10124
10125 @item
10126 A way of getting your program to the other machine---for example, a
10127 download program. These are often supplied by the hardware
10128 manufacturer, but you may have to write your own from hardware
10129 documentation.
10130 @end enumerate
10131
10132 The next step is to arrange for your program to use a serial port to
10133 communicate with the machine where @value{GDBN} is running (the @dfn{host}
10134 machine). In general terms, the scheme looks like this:
10135
10136 @table @emph
10137 @item On the host,
10138 @value{GDBN} already understands how to use this protocol; when everything
10139 else is set up, you can simply use the @samp{target remote} command
10140 (@pxref{Targets,,Specifying a Debugging Target}).
10141
10142 @item On the target,
10143 you must link with your program a few special-purpose subroutines that
10144 implement the @value{GDBN} remote serial protocol. The file containing these
10145 subroutines is called a @dfn{debugging stub}.
10146
10147 On certain remote targets, you can use an auxiliary program
10148 @code{gdbserver} instead of linking a stub into your program.
10149 @xref{Server,,Using the @code{gdbserver} program}, for details.
10150 @end table
10151
10152 The debugging stub is specific to the architecture of the remote
10153 machine; for example, use @file{sparc-stub.c} to debug programs on
10154 @sc{sparc} boards.
10155
10156 @cindex remote serial stub list
10157 These working remote stubs are distributed with @value{GDBN}:
10158
10159 @table @code
10160
10161 @item i386-stub.c
10162 @cindex @file{i386-stub.c}
10163 @cindex Intel
10164 @cindex i386
10165 For Intel 386 and compatible architectures.
10166
10167 @item m68k-stub.c
10168 @cindex @file{m68k-stub.c}
10169 @cindex Motorola 680x0
10170 @cindex m680x0
10171 For Motorola 680x0 architectures.
10172
10173 @item sh-stub.c
10174 @cindex @file{sh-stub.c}
10175 @cindex Hitachi
10176 @cindex SH
10177 For Hitachi SH architectures.
10178
10179 @item sparc-stub.c
10180 @cindex @file{sparc-stub.c}
10181 @cindex Sparc
10182 For @sc{sparc} architectures.
10183
10184 @item sparcl-stub.c
10185 @cindex @file{sparcl-stub.c}
10186 @cindex Fujitsu
10187 @cindex SparcLite
10188 For Fujitsu @sc{sparclite} architectures.
10189
10190 @end table
10191
10192 The @file{README} file in the @value{GDBN} distribution may list other
10193 recently added stubs.
10194
10195 @menu
10196 * Stub Contents:: What the stub can do for you
10197 * Bootstrapping:: What you must do for the stub
10198 * Debug Session:: Putting it all together
10199 @end menu
10200
10201 @node Stub Contents
10202 @subsection What the stub can do for you
10203
10204 @cindex remote serial stub
10205 The debugging stub for your architecture supplies these three
10206 subroutines:
10207
10208 @table @code
10209 @item set_debug_traps
10210 @kindex set_debug_traps
10211 @cindex remote serial stub, initialization
10212 This routine arranges for @code{handle_exception} to run when your
10213 program stops. You must call this subroutine explicitly near the
10214 beginning of your program.
10215
10216 @item handle_exception
10217 @kindex handle_exception
10218 @cindex remote serial stub, main routine
10219 This is the central workhorse, but your program never calls it
10220 explicitly---the setup code arranges for @code{handle_exception} to
10221 run when a trap is triggered.
10222
10223 @code{handle_exception} takes control when your program stops during
10224 execution (for example, on a breakpoint), and mediates communications
10225 with @value{GDBN} on the host machine. This is where the communications
10226 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
10227 representative on the target machine. It begins by sending summary
10228 information on the state of your program, then continues to execute,
10229 retrieving and transmitting any information @value{GDBN} needs, until you
10230 execute a @value{GDBN} command that makes your program resume; at that point,
10231 @code{handle_exception} returns control to your own code on the target
10232 machine.
10233
10234 @item breakpoint
10235 @cindex @code{breakpoint} subroutine, remote
10236 Use this auxiliary subroutine to make your program contain a
10237 breakpoint. Depending on the particular situation, this may be the only
10238 way for @value{GDBN} to get control. For instance, if your target
10239 machine has some sort of interrupt button, you won't need to call this;
10240 pressing the interrupt button transfers control to
10241 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
10242 simply receiving characters on the serial port may also trigger a trap;
10243 again, in that situation, you don't need to call @code{breakpoint} from
10244 your own program---simply running @samp{target remote} from the host
10245 @value{GDBN} session gets control.
10246
10247 Call @code{breakpoint} if none of these is true, or if you simply want
10248 to make certain your program stops at a predetermined point for the
10249 start of your debugging session.
10250 @end table
10251
10252 @node Bootstrapping
10253 @subsection What you must do for the stub
10254
10255 @cindex remote stub, support routines
10256 The debugging stubs that come with @value{GDBN} are set up for a particular
10257 chip architecture, but they have no information about the rest of your
10258 debugging target machine.
10259
10260 First of all you need to tell the stub how to communicate with the
10261 serial port.
10262
10263 @table @code
10264 @item int getDebugChar()
10265 @kindex getDebugChar
10266 Write this subroutine to read a single character from the serial port.
10267 It may be identical to @code{getchar} for your target system; a
10268 different name is used to allow you to distinguish the two if you wish.
10269
10270 @item void putDebugChar(int)
10271 @kindex putDebugChar
10272 Write this subroutine to write a single character to the serial port.
10273 It may be identical to @code{putchar} for your target system; a
10274 different name is used to allow you to distinguish the two if you wish.
10275 @end table
10276
10277 @cindex control C, and remote debugging
10278 @cindex interrupting remote targets
10279 If you want @value{GDBN} to be able to stop your program while it is
10280 running, you need to use an interrupt-driven serial driver, and arrange
10281 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
10282 character). That is the character which @value{GDBN} uses to tell the
10283 remote system to stop.
10284
10285 Getting the debugging target to return the proper status to @value{GDBN}
10286 probably requires changes to the standard stub; one quick and dirty way
10287 is to just execute a breakpoint instruction (the ``dirty'' part is that
10288 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
10289
10290 Other routines you need to supply are:
10291
10292 @table @code
10293 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
10294 @kindex exceptionHandler
10295 Write this function to install @var{exception_address} in the exception
10296 handling tables. You need to do this because the stub does not have any
10297 way of knowing what the exception handling tables on your target system
10298 are like (for example, the processor's table might be in @sc{rom},
10299 containing entries which point to a table in @sc{ram}).
10300 @var{exception_number} is the exception number which should be changed;
10301 its meaning is architecture-dependent (for example, different numbers
10302 might represent divide by zero, misaligned access, etc). When this
10303 exception occurs, control should be transferred directly to
10304 @var{exception_address}, and the processor state (stack, registers,
10305 and so on) should be just as it is when a processor exception occurs. So if
10306 you want to use a jump instruction to reach @var{exception_address}, it
10307 should be a simple jump, not a jump to subroutine.
10308
10309 For the 386, @var{exception_address} should be installed as an interrupt
10310 gate so that interrupts are masked while the handler runs. The gate
10311 should be at privilege level 0 (the most privileged level). The
10312 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
10313 help from @code{exceptionHandler}.
10314
10315 @item void flush_i_cache()
10316 @kindex flush_i_cache
10317 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
10318 instruction cache, if any, on your target machine. If there is no
10319 instruction cache, this subroutine may be a no-op.
10320
10321 On target machines that have instruction caches, @value{GDBN} requires this
10322 function to make certain that the state of your program is stable.
10323 @end table
10324
10325 @noindent
10326 You must also make sure this library routine is available:
10327
10328 @table @code
10329 @item void *memset(void *, int, int)
10330 @kindex memset
10331 This is the standard library function @code{memset} that sets an area of
10332 memory to a known value. If you have one of the free versions of
10333 @code{libc.a}, @code{memset} can be found there; otherwise, you must
10334 either obtain it from your hardware manufacturer, or write your own.
10335 @end table
10336
10337 If you do not use the GNU C compiler, you may need other standard
10338 library subroutines as well; this varies from one stub to another,
10339 but in general the stubs are likely to use any of the common library
10340 subroutines which @code{@value{GCC}} generates as inline code.
10341
10342
10343 @node Debug Session
10344 @subsection Putting it all together
10345
10346 @cindex remote serial debugging summary
10347 In summary, when your program is ready to debug, you must follow these
10348 steps.
10349
10350 @enumerate
10351 @item
10352 Make sure you have defined the supporting low-level routines
10353 (@pxref{Bootstrapping,,What you must do for the stub}):
10354 @display
10355 @code{getDebugChar}, @code{putDebugChar},
10356 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
10357 @end display
10358
10359 @item
10360 Insert these lines near the top of your program:
10361
10362 @smallexample
10363 set_debug_traps();
10364 breakpoint();
10365 @end smallexample
10366
10367 @item
10368 For the 680x0 stub only, you need to provide a variable called
10369 @code{exceptionHook}. Normally you just use:
10370
10371 @smallexample
10372 void (*exceptionHook)() = 0;
10373 @end smallexample
10374
10375 @noindent
10376 but if before calling @code{set_debug_traps}, you set it to point to a
10377 function in your program, that function is called when
10378 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
10379 error). The function indicated by @code{exceptionHook} is called with
10380 one parameter: an @code{int} which is the exception number.
10381
10382 @item
10383 Compile and link together: your program, the @value{GDBN} debugging stub for
10384 your target architecture, and the supporting subroutines.
10385
10386 @item
10387 Make sure you have a serial connection between your target machine and
10388 the @value{GDBN} host, and identify the serial port on the host.
10389
10390 @item
10391 @c The "remote" target now provides a `load' command, so we should
10392 @c document that. FIXME.
10393 Download your program to your target machine (or get it there by
10394 whatever means the manufacturer provides), and start it.
10395
10396 @item
10397 To start remote debugging, run @value{GDBN} on the host machine, and specify
10398 as an executable file the program that is running in the remote machine.
10399 This tells @value{GDBN} how to find your program's symbols and the contents
10400 of its pure text.
10401
10402 @item
10403 @cindex serial line, @code{target remote}
10404 Establish communication using the @code{target remote} command.
10405 Its argument specifies how to communicate with the target
10406 machine---either via a devicename attached to a direct serial line, or a
10407 TCP port (usually to a terminal server which in turn has a serial line
10408 to the target). For example, to use a serial line connected to the
10409 device named @file{/dev/ttyb}:
10410
10411 @smallexample
10412 target remote /dev/ttyb
10413 @end smallexample
10414
10415 @cindex TCP port, @code{target remote}
10416 To use a TCP connection, use an argument of the form
10417 @code{@var{host}:port}. For example, to connect to port 2828 on a
10418 terminal server named @code{manyfarms}:
10419
10420 @smallexample
10421 target remote manyfarms:2828
10422 @end smallexample
10423
10424 If your remote target is actually running on the same machine as
10425 your debugger session (e.g.@: a simulator of your target running on
10426 the same host), you can omit the hostname. For example, to connect
10427 to port 1234 on your local machine:
10428
10429 @smallexample
10430 target remote :1234
10431 @end smallexample
10432 @noindent
10433
10434 Note that the colon is still required here.
10435 @end enumerate
10436
10437 Now you can use all the usual commands to examine and change data and to
10438 step and continue the remote program.
10439
10440 To resume the remote program and stop debugging it, use the @code{detach}
10441 command.
10442
10443 @cindex interrupting remote programs
10444 @cindex remote programs, interrupting
10445 Whenever @value{GDBN} is waiting for the remote program, if you type the
10446 interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10447 program. This may or may not succeed, depending in part on the hardware
10448 and the serial drivers the remote system uses. If you type the
10449 interrupt character once again, @value{GDBN} displays this prompt:
10450
10451 @smallexample
10452 Interrupted while waiting for the program.
10453 Give up (and stop debugging it)? (y or n)
10454 @end smallexample
10455
10456 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10457 (If you decide you want to try again later, you can use @samp{target
10458 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
10459 goes back to waiting.
10460
10461
10462 @node Configurations
10463 @chapter Configuration-Specific Information
10464
10465 While nearly all @value{GDBN} commands are available for all native and
10466 cross versions of the debugger, there are some exceptions. This chapter
10467 describes things that are only available in certain configurations.
10468
10469 There are three major categories of configurations: native
10470 configurations, where the host and target are the same, embedded
10471 operating system configurations, which are usually the same for several
10472 different processor architectures, and bare embedded processors, which
10473 are quite different from each other.
10474
10475 @menu
10476 * Native::
10477 * Embedded OS::
10478 * Embedded Processors::
10479 * Architectures::
10480 @end menu
10481
10482 @node Native
10483 @section Native
10484
10485 This section describes details specific to particular native
10486 configurations.
10487
10488 @menu
10489 * HP-UX:: HP-UX
10490 * SVR4 Process Information:: SVR4 process information
10491 * DJGPP Native:: Features specific to the DJGPP port
10492 * Cygwin Native:: Features specific to the Cygwin port
10493 @end menu
10494
10495 @node HP-UX
10496 @subsection HP-UX
10497
10498 On HP-UX systems, if you refer to a function or variable name that
10499 begins with a dollar sign, @value{GDBN} searches for a user or system
10500 name first, before it searches for a convenience variable.
10501
10502 @node SVR4 Process Information
10503 @subsection SVR4 process information
10504
10505 @kindex /proc
10506 @cindex process image
10507
10508 Many versions of SVR4 provide a facility called @samp{/proc} that can be
10509 used to examine the image of a running process using file-system
10510 subroutines. If @value{GDBN} is configured for an operating system with
10511 this facility, the command @code{info proc} is available to report on
10512 several kinds of information about the process running your program.
10513 @code{info proc} works only on SVR4 systems that include the
10514 @code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
10515 and Unixware, but not HP-UX or Linux, for example.
10516
10517 @table @code
10518 @kindex info proc
10519 @item info proc
10520 Summarize available information about the process.
10521
10522 @kindex info proc mappings
10523 @item info proc mappings
10524 Report on the address ranges accessible in the program, with information
10525 on whether your program may read, write, or execute each range.
10526 @ignore
10527 @comment These sub-options of 'info proc' were not included when
10528 @comment procfs.c was re-written. Keep their descriptions around
10529 @comment against the day when someone finds the time to put them back in.
10530 @kindex info proc times
10531 @item info proc times
10532 Starting time, user CPU time, and system CPU time for your program and
10533 its children.
10534
10535 @kindex info proc id
10536 @item info proc id
10537 Report on the process IDs related to your program: its own process ID,
10538 the ID of its parent, the process group ID, and the session ID.
10539
10540 @kindex info proc status
10541 @item info proc status
10542 General information on the state of the process. If the process is
10543 stopped, this report includes the reason for stopping, and any signal
10544 received.
10545
10546 @item info proc all
10547 Show all the above information about the process.
10548 @end ignore
10549 @end table
10550
10551 @node DJGPP Native
10552 @subsection Features for Debugging @sc{djgpp} Programs
10553 @cindex @sc{djgpp} debugging
10554 @cindex native @sc{djgpp} debugging
10555 @cindex MS-DOS-specific commands
10556
10557 @sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
10558 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
10559 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
10560 top of real-mode DOS systems and their emulations.
10561
10562 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
10563 defines a few commands specific to the @sc{djgpp} port. This
10564 subsection describes those commands.
10565
10566 @table @code
10567 @kindex info dos
10568 @item info dos
10569 This is a prefix of @sc{djgpp}-specific commands which print
10570 information about the target system and important OS structures.
10571
10572 @kindex sysinfo
10573 @cindex MS-DOS system info
10574 @cindex free memory information (MS-DOS)
10575 @item info dos sysinfo
10576 This command displays assorted information about the underlying
10577 platform: the CPU type and features, the OS version and flavor, the
10578 DPMI version, and the available conventional and DPMI memory.
10579
10580 @cindex GDT
10581 @cindex LDT
10582 @cindex IDT
10583 @cindex segment descriptor tables
10584 @cindex descriptor tables display
10585 @item info dos gdt
10586 @itemx info dos ldt
10587 @itemx info dos idt
10588 These 3 commands display entries from, respectively, Global, Local,
10589 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
10590 tables are data structures which store a descriptor for each segment
10591 that is currently in use. The segment's selector is an index into a
10592 descriptor table; the table entry for that index holds the
10593 descriptor's base address and limit, and its attributes and access
10594 rights.
10595
10596 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
10597 segment (used for both data and the stack), and a DOS segment (which
10598 allows access to DOS/BIOS data structures and absolute addresses in
10599 conventional memory). However, the DPMI host will usually define
10600 additional segments in order to support the DPMI environment.
10601
10602 @cindex garbled pointers
10603 These commands allow to display entries from the descriptor tables.
10604 Without an argument, all entries from the specified table are
10605 displayed. An argument, which should be an integer expression, means
10606 display a single entry whose index is given by the argument. For
10607 example, here's a convenient way to display information about the
10608 debugged program's data segment:
10609
10610 @smallexample
10611 @exdent @code{(@value{GDBP}) info dos ldt $ds}
10612 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
10613 @end smallexample
10614
10615 @noindent
10616 This comes in handy when you want to see whether a pointer is outside
10617 the data segment's limit (i.e.@: @dfn{garbled}).
10618
10619 @cindex page tables display (MS-DOS)
10620 @item info dos pde
10621 @itemx info dos pte
10622 These two commands display entries from, respectively, the Page
10623 Directory and the Page Tables. Page Directories and Page Tables are
10624 data structures which control how virtual memory addresses are mapped
10625 into physical addresses. A Page Table includes an entry for every
10626 page of memory that is mapped into the program's address space; there
10627 may be several Page Tables, each one holding up to 4096 entries. A
10628 Page Directory has up to 4096 entries, one each for every Page Table
10629 that is currently in use.
10630
10631 Without an argument, @kbd{info dos pde} displays the entire Page
10632 Directory, and @kbd{info dos pte} displays all the entries in all of
10633 the Page Tables. An argument, an integer expression, given to the
10634 @kbd{info dos pde} command means display only that entry from the Page
10635 Directory table. An argument given to the @kbd{info dos pte} command
10636 means display entries from a single Page Table, the one pointed to by
10637 the specified entry in the Page Directory.
10638
10639 @cindex direct memory access (DMA) on MS-DOS
10640 These commands are useful when your program uses @dfn{DMA} (Direct
10641 Memory Access), which needs physical addresses to program the DMA
10642 controller.
10643
10644 These commands are supported only with some DPMI servers.
10645
10646 @cindex physical address from linear address
10647 @item info dos address-pte @var{addr}
10648 This command displays the Page Table entry for a specified linear
10649 address. The argument linear address @var{addr} should already have the
10650 appropriate segment's base address added to it, because this command
10651 accepts addresses which may belong to @emph{any} segment. For
10652 example, here's how to display the Page Table entry for the page where
10653 the variable @code{i} is stored:
10654
10655 @smallexample
10656 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
10657 @exdent @code{Page Table entry for address 0x11a00d30:}
10658 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
10659 @end smallexample
10660
10661 @noindent
10662 This says that @code{i} is stored at offset @code{0xd30} from the page
10663 whose physical base address is @code{0x02698000}, and prints all the
10664 attributes of that page.
10665
10666 Note that you must cast the addresses of variables to a @code{char *},
10667 since otherwise the value of @code{__djgpp_base_address}, the base
10668 address of all variables and functions in a @sc{djgpp} program, will
10669 be added using the rules of C pointer arithmetics: if @code{i} is
10670 declared an @code{int}, @value{GDBN} will add 4 times the value of
10671 @code{__djgpp_base_address} to the address of @code{i}.
10672
10673 Here's another example, it displays the Page Table entry for the
10674 transfer buffer:
10675
10676 @smallexample
10677 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
10678 @exdent @code{Page Table entry for address 0x29110:}
10679 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
10680 @end smallexample
10681
10682 @noindent
10683 (The @code{+ 3} offset is because the transfer buffer's address is the
10684 3rd member of the @code{_go32_info_block} structure.) The output of
10685 this command clearly shows that addresses in conventional memory are
10686 mapped 1:1, i.e.@: the physical and linear addresses are identical.
10687
10688 This command is supported only with some DPMI servers.
10689 @end table
10690
10691 @node Cygwin Native
10692 @subsection Features for Debugging MS Windows PE executables
10693 @cindex MS Windows debugging
10694 @cindex native Cygwin debugging
10695 @cindex Cygwin-specific commands
10696
10697 @value{GDBN} supports native debugging of MS Windows programs, and
10698 defines a few commands specific to the Cygwin port. This
10699 subsection describes those commands.
10700
10701 @table @code
10702 @kindex info w32
10703 @item info w32
10704 This is a prefix of MS Windows specific commands which print
10705 information about the target system and important OS structures.
10706
10707 @item info w32 selector
10708 This command displays information returned by
10709 the Win32 API @code{GetThreadSelectorEntry} function.
10710 It takes an optional argument that is evaluated to
10711 a long value to give the information about this given selector.
10712 Without argument, this command displays information
10713 about the the six segment registers.
10714
10715 @kindex info dll
10716 @item info dll
10717 This is a Cygwin specific alias of info shared.
10718
10719 @kindex dll-symbols
10720 @item dll-symbols
10721 This command loads symbols from a dll similarly to
10722 add-sym command but without the need to specify a base address.
10723
10724 @kindex set new-console
10725 @item set new-console @var{mode}
10726 If @var{mode} is @code{on} the debuggee will
10727 be started in a new console on next start.
10728 If @var{mode} is @code{off}i, the debuggee will
10729 be started in the same console as the debugger.
10730
10731 @kindex show new-console
10732 @item show new-console
10733 Displays whether a new console is used
10734 when the debuggee is started.
10735
10736 @kindex set new-group
10737 @item set new-group @var{mode}
10738 This boolean value controls whether the debuggee should
10739 start a new group or stay in the same group as the debugger.
10740 This affects the way the Windows OS handles
10741 Ctrl-C.
10742
10743 @kindex show new-group
10744 @item show new-group
10745 Displays current value of new-group boolean.
10746
10747 @kindex set debugevents
10748 @item set debugevents
10749 This boolean value adds debug output concerning events seen by the debugger.
10750
10751 @kindex set debugexec
10752 @item set debugexec
10753 This boolean value adds debug output concerning execute events
10754 seen by the debugger.
10755
10756 @kindex set debugexceptions
10757 @item set debugexceptions
10758 This boolean value adds debug ouptut concerning exception events
10759 seen by the debugger.
10760
10761 @kindex set debugmemory
10762 @item set debugmemory
10763 This boolean value adds debug ouptut concerning memory events
10764 seen by the debugger.
10765
10766 @kindex set shell
10767 @item set shell
10768 This boolean values specifies whether the debuggee is called
10769 via a shell or directly (default value is on).
10770
10771 @kindex show shell
10772 @item show shell
10773 Displays if the debuggee will be started with a shell.
10774
10775 @end table
10776
10777 @node Embedded OS
10778 @section Embedded Operating Systems
10779
10780 This section describes configurations involving the debugging of
10781 embedded operating systems that are available for several different
10782 architectures.
10783
10784 @menu
10785 * VxWorks:: Using @value{GDBN} with VxWorks
10786 @end menu
10787
10788 @value{GDBN} includes the ability to debug programs running on
10789 various real-time operating systems.
10790
10791 @node VxWorks
10792 @subsection Using @value{GDBN} with VxWorks
10793
10794 @cindex VxWorks
10795
10796 @table @code
10797
10798 @kindex target vxworks
10799 @item target vxworks @var{machinename}
10800 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
10801 is the target system's machine name or IP address.
10802
10803 @end table
10804
10805 On VxWorks, @code{load} links @var{filename} dynamically on the
10806 current target system as well as adding its symbols in @value{GDBN}.
10807
10808 @value{GDBN} enables developers to spawn and debug tasks running on networked
10809 VxWorks targets from a Unix host. Already-running tasks spawned from
10810 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
10811 both the Unix host and on the VxWorks target. The program
10812 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
10813 installed with the name @code{vxgdb}, to distinguish it from a
10814 @value{GDBN} for debugging programs on the host itself.)
10815
10816 @table @code
10817 @item VxWorks-timeout @var{args}
10818 @kindex vxworks-timeout
10819 All VxWorks-based targets now support the option @code{vxworks-timeout}.
10820 This option is set by the user, and @var{args} represents the number of
10821 seconds @value{GDBN} waits for responses to rpc's. You might use this if
10822 your VxWorks target is a slow software simulator or is on the far side
10823 of a thin network line.
10824 @end table
10825
10826 The following information on connecting to VxWorks was current when
10827 this manual was produced; newer releases of VxWorks may use revised
10828 procedures.
10829
10830 @kindex INCLUDE_RDB
10831 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
10832 to include the remote debugging interface routines in the VxWorks
10833 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
10834 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
10835 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
10836 source debugging task @code{tRdbTask} when VxWorks is booted. For more
10837 information on configuring and remaking VxWorks, see the manufacturer's
10838 manual.
10839 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
10840
10841 Once you have included @file{rdb.a} in your VxWorks system image and set
10842 your Unix execution search path to find @value{GDBN}, you are ready to
10843 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
10844 @code{vxgdb}, depending on your installation).
10845
10846 @value{GDBN} comes up showing the prompt:
10847
10848 @smallexample
10849 (vxgdb)
10850 @end smallexample
10851
10852 @menu
10853 * VxWorks Connection:: Connecting to VxWorks
10854 * VxWorks Download:: VxWorks download
10855 * VxWorks Attach:: Running tasks
10856 @end menu
10857
10858 @node VxWorks Connection
10859 @subsubsection Connecting to VxWorks
10860
10861 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
10862 network. To connect to a target whose host name is ``@code{tt}'', type:
10863
10864 @smallexample
10865 (vxgdb) target vxworks tt
10866 @end smallexample
10867
10868 @need 750
10869 @value{GDBN} displays messages like these:
10870
10871 @smallexample
10872 Attaching remote machine across net...
10873 Connected to tt.
10874 @end smallexample
10875
10876 @need 1000
10877 @value{GDBN} then attempts to read the symbol tables of any object modules
10878 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
10879 these files by searching the directories listed in the command search
10880 path (@pxref{Environment, ,Your program's environment}); if it fails
10881 to find an object file, it displays a message such as:
10882
10883 @smallexample
10884 prog.o: No such file or directory.
10885 @end smallexample
10886
10887 When this happens, add the appropriate directory to the search path with
10888 the @value{GDBN} command @code{path}, and execute the @code{target}
10889 command again.
10890
10891 @node VxWorks Download
10892 @subsubsection VxWorks download
10893
10894 @cindex download to VxWorks
10895 If you have connected to the VxWorks target and you want to debug an
10896 object that has not yet been loaded, you can use the @value{GDBN}
10897 @code{load} command to download a file from Unix to VxWorks
10898 incrementally. The object file given as an argument to the @code{load}
10899 command is actually opened twice: first by the VxWorks target in order
10900 to download the code, then by @value{GDBN} in order to read the symbol
10901 table. This can lead to problems if the current working directories on
10902 the two systems differ. If both systems have NFS mounted the same
10903 filesystems, you can avoid these problems by using absolute paths.
10904 Otherwise, it is simplest to set the working directory on both systems
10905 to the directory in which the object file resides, and then to reference
10906 the file by its name, without any path. For instance, a program
10907 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
10908 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
10909 program, type this on VxWorks:
10910
10911 @smallexample
10912 -> cd "@var{vxpath}/vw/demo/rdb"
10913 @end smallexample
10914
10915 @noindent
10916 Then, in @value{GDBN}, type:
10917
10918 @smallexample
10919 (vxgdb) cd @var{hostpath}/vw/demo/rdb
10920 (vxgdb) load prog.o
10921 @end smallexample
10922
10923 @value{GDBN} displays a response similar to this:
10924
10925 @smallexample
10926 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
10927 @end smallexample
10928
10929 You can also use the @code{load} command to reload an object module
10930 after editing and recompiling the corresponding source file. Note that
10931 this makes @value{GDBN} delete all currently-defined breakpoints,
10932 auto-displays, and convenience variables, and to clear the value
10933 history. (This is necessary in order to preserve the integrity of
10934 debugger's data structures that reference the target system's symbol
10935 table.)
10936
10937 @node VxWorks Attach
10938 @subsubsection Running tasks
10939
10940 @cindex running VxWorks tasks
10941 You can also attach to an existing task using the @code{attach} command as
10942 follows:
10943
10944 @smallexample
10945 (vxgdb) attach @var{task}
10946 @end smallexample
10947
10948 @noindent
10949 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
10950 or suspended when you attach to it. Running tasks are suspended at
10951 the time of attachment.
10952
10953 @node Embedded Processors
10954 @section Embedded Processors
10955
10956 This section goes into details specific to particular embedded
10957 configurations.
10958
10959
10960 @c OBSOLETE * A29K Embedded:: AMD A29K Embedded
10961 @menu
10962 * ARM:: ARM
10963 * H8/300:: Hitachi H8/300
10964 * H8/500:: Hitachi H8/500
10965 * i960:: Intel i960
10966 * M32R/D:: Mitsubishi M32R/D
10967 * M68K:: Motorola M68K
10968 * M88K:: Motorola M88K
10969 * MIPS Embedded:: MIPS Embedded
10970 * PA:: HP PA Embedded
10971 * PowerPC: PowerPC
10972 * SH:: Hitachi SH
10973 * Sparclet:: Tsqware Sparclet
10974 * Sparclite:: Fujitsu Sparclite
10975 * ST2000:: Tandem ST2000
10976 * Z8000:: Zilog Z8000
10977 @end menu
10978
10979 @c OBSOLETE @node A29K Embedded
10980 @c OBSOLETE @subsection AMD A29K Embedded
10981 @c OBSOLETE
10982 @c OBSOLETE @menu
10983 @c OBSOLETE * A29K UDI::
10984 @c OBSOLETE * A29K EB29K::
10985 @c OBSOLETE * Comms (EB29K):: Communications setup
10986 @c OBSOLETE * gdb-EB29K:: EB29K cross-debugging
10987 @c OBSOLETE * Remote Log:: Remote log
10988 @c OBSOLETE @end menu
10989 @c OBSOLETE
10990 @c OBSOLETE @table @code
10991 @c OBSOLETE
10992 @c OBSOLETE @kindex target adapt
10993 @c OBSOLETE @item target adapt @var{dev}
10994 @c OBSOLETE Adapt monitor for A29K.
10995 @c OBSOLETE
10996 @c OBSOLETE @kindex target amd-eb
10997 @c OBSOLETE @item target amd-eb @var{dev} @var{speed} @var{PROG}
10998 @c OBSOLETE @cindex AMD EB29K
10999 @c OBSOLETE Remote PC-resident AMD EB29K board, attached over serial lines.
11000 @c OBSOLETE @var{dev} is the serial device, as for @code{target remote};
11001 @c OBSOLETE @var{speed} allows you to specify the linespeed; and @var{PROG} is the
11002 @c OBSOLETE name of the program to be debugged, as it appears to DOS on the PC.
11003 @c OBSOLETE @xref{A29K EB29K, ,EBMON protocol for AMD29K}.
11004 @c OBSOLETE
11005 @c OBSOLETE @end table
11006 @c OBSOLETE
11007 @c OBSOLETE @node A29K UDI
11008 @c OBSOLETE @subsubsection A29K UDI
11009 @c OBSOLETE
11010 @c OBSOLETE @cindex UDI
11011 @c OBSOLETE @cindex AMD29K via UDI
11012 @c OBSOLETE
11013 @c OBSOLETE @value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
11014 @c OBSOLETE protocol for debugging the a29k processor family. To use this
11015 @c OBSOLETE configuration with AMD targets running the MiniMON monitor, you need the
11016 @c OBSOLETE program @code{MONTIP}, available from AMD at no charge. You can also
11017 @c OBSOLETE use @value{GDBN} with the UDI-conformant a29k simulator program
11018 @c OBSOLETE @code{ISSTIP}, also available from AMD.
11019 @c OBSOLETE
11020 @c OBSOLETE @table @code
11021 @c OBSOLETE @item target udi @var{keyword}
11022 @c OBSOLETE @kindex udi
11023 @c OBSOLETE Select the UDI interface to a remote a29k board or simulator, where
11024 @c OBSOLETE @var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
11025 @c OBSOLETE This file contains keyword entries which specify parameters used to
11026 @c OBSOLETE connect to a29k targets. If the @file{udi_soc} file is not in your
11027 @c OBSOLETE working directory, you must set the environment variable @samp{UDICONF}
11028 @c OBSOLETE to its pathname.
11029 @c OBSOLETE @end table
11030 @c OBSOLETE
11031 @c OBSOLETE @node A29K EB29K
11032 @c OBSOLETE @subsubsection EBMON protocol for AMD29K
11033 @c OBSOLETE
11034 @c OBSOLETE @cindex EB29K board
11035 @c OBSOLETE @cindex running 29K programs
11036 @c OBSOLETE
11037 @c OBSOLETE AMD distributes a 29K development board meant to fit in a PC, together
11038 @c OBSOLETE with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
11039 @c OBSOLETE term, this development system is called the ``EB29K''. To use
11040 @c OBSOLETE @value{GDBN} from a Unix system to run programs on the EB29K board, you
11041 @c OBSOLETE must first connect a serial cable between the PC (which hosts the EB29K
11042 @c OBSOLETE board) and a serial port on the Unix system. In the following, we
11043 @c OBSOLETE assume you've hooked the cable between the PC's @file{COM1} port and
11044 @c OBSOLETE @file{/dev/ttya} on the Unix system.
11045 @c OBSOLETE
11046 @c OBSOLETE @node Comms (EB29K)
11047 @c OBSOLETE @subsubsection Communications setup
11048 @c OBSOLETE
11049 @c OBSOLETE The next step is to set up the PC's port, by doing something like this
11050 @c OBSOLETE in DOS on the PC:
11051 @c OBSOLETE
11052 @c OBSOLETE @smallexample
11053 @c OBSOLETE C:\> MODE com1:9600,n,8,1,none
11054 @c OBSOLETE @end smallexample
11055 @c OBSOLETE
11056 @c OBSOLETE @noindent
11057 @c OBSOLETE This example---run on an MS DOS 4.0 system---sets the PC port to 9600
11058 @c OBSOLETE bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
11059 @c OBSOLETE you must match the communications parameters when establishing the Unix
11060 @c OBSOLETE end of the connection as well.
11061 @c OBSOLETE @c FIXME: Who knows what this "no retry action" crud from the DOS manual may
11062 @c OBSOLETE @c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
11063 @c OBSOLETE @c
11064 @c OBSOLETE @c It's optional, but it's unwise to omit it: who knows what is the
11065 @c OBSOLETE @c default value set when the DOS machines boots? "No retry" means that
11066 @c OBSOLETE @c the DOS serial device driver won't retry the operation if it fails;
11067 @c OBSOLETE @c I understand that this is needed because the GDB serial protocol
11068 @c OBSOLETE @c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
11069 @c OBSOLETE
11070 @c OBSOLETE To give control of the PC to the Unix side of the serial line, type
11071 @c OBSOLETE the following at the DOS console:
11072 @c OBSOLETE
11073 @c OBSOLETE @smallexample
11074 @c OBSOLETE C:\> CTTY com1
11075 @c OBSOLETE @end smallexample
11076 @c OBSOLETE
11077 @c OBSOLETE @noindent
11078 @c OBSOLETE (Later, if you wish to return control to the DOS console, you can use
11079 @c OBSOLETE the command @code{CTTY con}---but you must send it over the device that
11080 @c OBSOLETE had control, in our example over the @file{COM1} serial line.)
11081 @c OBSOLETE
11082 @c OBSOLETE From the Unix host, use a communications program such as @code{tip} or
11083 @c OBSOLETE @code{cu} to communicate with the PC; for example,
11084 @c OBSOLETE
11085 @c OBSOLETE @smallexample
11086 @c OBSOLETE cu -s 9600 -l /dev/ttya
11087 @c OBSOLETE @end smallexample
11088 @c OBSOLETE
11089 @c OBSOLETE @noindent
11090 @c OBSOLETE The @code{cu} options shown specify, respectively, the linespeed and the
11091 @c OBSOLETE serial port to use. If you use @code{tip} instead, your command line
11092 @c OBSOLETE may look something like the following:
11093 @c OBSOLETE
11094 @c OBSOLETE @smallexample
11095 @c OBSOLETE tip -9600 /dev/ttya
11096 @c OBSOLETE @end smallexample
11097 @c OBSOLETE
11098 @c OBSOLETE @noindent
11099 @c OBSOLETE Your system may require a different name where we show
11100 @c OBSOLETE @file{/dev/ttya} as the argument to @code{tip}. The communications
11101 @c OBSOLETE parameters, including which port to use, are associated with the
11102 @c OBSOLETE @code{tip} argument in the ``remote'' descriptions file---normally the
11103 @c OBSOLETE system table @file{/etc/remote}.
11104 @c OBSOLETE @c FIXME: What if anything needs doing to match the "n,8,1,none" part of
11105 @c OBSOLETE @c the DOS side's comms setup? cu can support -o (odd
11106 @c OBSOLETE @c parity), -e (even parity)---apparently no settings for no parity or
11107 @c OBSOLETE @c for character size. Taken from stty maybe...? John points out tip
11108 @c OBSOLETE @c can set these as internal variables, eg ~s parity=none; man stty
11109 @c OBSOLETE @c suggests that it *might* work to stty these options with stdin or
11110 @c OBSOLETE @c stdout redirected... ---doc@cygnus.com, 25feb91
11111 @c OBSOLETE @c
11112 @c OBSOLETE @c There's nothing to be done for the "none" part of the DOS MODE
11113 @c OBSOLETE @c command. The rest of the parameters should be matched by the
11114 @c OBSOLETE @c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
11115 @c OBSOLETE
11116 @c OBSOLETE @kindex EBMON
11117 @c OBSOLETE Using the @code{tip} or @code{cu} connection, change the DOS working
11118 @c OBSOLETE directory to the directory containing a copy of your 29K program, then
11119 @c OBSOLETE start the PC program @code{EBMON} (an EB29K control program supplied
11120 @c OBSOLETE with your board by AMD). You should see an initial display from
11121 @c OBSOLETE @code{EBMON} similar to the one that follows, ending with the
11122 @c OBSOLETE @code{EBMON} prompt @samp{#}---
11123 @c OBSOLETE
11124 @c OBSOLETE @smallexample
11125 @c OBSOLETE C:\> G:
11126 @c OBSOLETE
11127 @c OBSOLETE G:\> CD \usr\joe\work29k
11128 @c OBSOLETE
11129 @c OBSOLETE G:\USR\JOE\WORK29K> EBMON
11130 @c OBSOLETE Am29000 PC Coprocessor Board Monitor, version 3.0-18
11131 @c OBSOLETE Copyright 1990 Advanced Micro Devices, Inc.
11132 @c OBSOLETE Written by Gibbons and Associates, Inc.
11133 @c OBSOLETE
11134 @c OBSOLETE Enter '?' or 'H' for help
11135 @c OBSOLETE
11136 @c OBSOLETE PC Coprocessor Type = EB29K
11137 @c OBSOLETE I/O Base = 0x208
11138 @c OBSOLETE Memory Base = 0xd0000
11139 @c OBSOLETE
11140 @c OBSOLETE Data Memory Size = 2048KB
11141 @c OBSOLETE Available I-RAM Range = 0x8000 to 0x1fffff
11142 @c OBSOLETE Available D-RAM Range = 0x80002000 to 0x801fffff
11143 @c OBSOLETE
11144 @c OBSOLETE PageSize = 0x400
11145 @c OBSOLETE Register Stack Size = 0x800
11146 @c OBSOLETE Memory Stack Size = 0x1800
11147 @c OBSOLETE
11148 @c OBSOLETE CPU PRL = 0x3
11149 @c OBSOLETE Am29027 Available = No
11150 @c OBSOLETE Byte Write Available = Yes
11151 @c OBSOLETE
11152 @c OBSOLETE # ~.
11153 @c OBSOLETE @end smallexample
11154 @c OBSOLETE
11155 @c OBSOLETE Then exit the @code{cu} or @code{tip} program (done in the example by
11156 @c OBSOLETE typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
11157 @c OBSOLETE running, ready for @value{GDBN} to take over.
11158 @c OBSOLETE
11159 @c OBSOLETE For this example, we've assumed what is probably the most convenient
11160 @c OBSOLETE way to make sure the same 29K program is on both the PC and the Unix
11161 @c OBSOLETE system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
11162 @c OBSOLETE PC as a file system on the Unix host. If you do not have PC/NFS or
11163 @c OBSOLETE something similar connecting the two systems, you must arrange some
11164 @c OBSOLETE other way---perhaps floppy-disk transfer---of getting the 29K program
11165 @c OBSOLETE from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
11166 @c OBSOLETE serial line.
11167 @c OBSOLETE
11168 @c OBSOLETE @node gdb-EB29K
11169 @c OBSOLETE @subsubsection EB29K cross-debugging
11170 @c OBSOLETE
11171 @c OBSOLETE Finally, @code{cd} to the directory containing an image of your 29K
11172 @c OBSOLETE program on the Unix system, and start @value{GDBN}---specifying as argument the
11173 @c OBSOLETE name of your 29K program:
11174 @c OBSOLETE
11175 @c OBSOLETE @smallexample
11176 @c OBSOLETE cd /usr/joe/work29k
11177 @c OBSOLETE @value{GDBP} myfoo
11178 @c OBSOLETE @end smallexample
11179 @c OBSOLETE
11180 @c OBSOLETE @need 500
11181 @c OBSOLETE Now you can use the @code{target} command:
11182 @c OBSOLETE
11183 @c OBSOLETE @smallexample
11184 @c OBSOLETE target amd-eb /dev/ttya 9600 MYFOO
11185 @c OBSOLETE @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
11186 @c OBSOLETE @c emphasize that this is the name as seen by DOS (since I think DOS is
11187 @c OBSOLETE @c single-minded about case of letters). ---doc@cygnus.com, 25feb91
11188 @c OBSOLETE @end smallexample
11189 @c OBSOLETE
11190 @c OBSOLETE @noindent
11191 @c OBSOLETE In this example, we've assumed your program is in a file called
11192 @c OBSOLETE @file{myfoo}. Note that the filename given as the last argument to
11193 @c OBSOLETE @code{target amd-eb} should be the name of the program as it appears to DOS.
11194 @c OBSOLETE In our example this is simply @code{MYFOO}, but in general it can include
11195 @c OBSOLETE a DOS path, and depending on your transfer mechanism may not resemble
11196 @c OBSOLETE the name on the Unix side.
11197 @c OBSOLETE
11198 @c OBSOLETE At this point, you can set any breakpoints you wish; when you are ready
11199 @c OBSOLETE to see your program run on the 29K board, use the @value{GDBN} command
11200 @c OBSOLETE @code{run}.
11201 @c OBSOLETE
11202 @c OBSOLETE To stop debugging the remote program, use the @value{GDBN} @code{detach}
11203 @c OBSOLETE command.
11204 @c OBSOLETE
11205 @c OBSOLETE To return control of the PC to its console, use @code{tip} or @code{cu}
11206 @c OBSOLETE once again, after your @value{GDBN} session has concluded, to attach to
11207 @c OBSOLETE @code{EBMON}. You can then type the command @code{q} to shut down
11208 @c OBSOLETE @code{EBMON}, returning control to the DOS command-line interpreter.
11209 @c OBSOLETE Type @kbd{CTTY con} to return command input to the main DOS console,
11210 @c OBSOLETE and type @kbd{~.} to leave @code{tip} or @code{cu}.
11211 @c OBSOLETE
11212 @c OBSOLETE @node Remote Log
11213 @c OBSOLETE @subsubsection Remote log
11214 @c OBSOLETE @cindex @file{eb.log}, a log file for EB29K
11215 @c OBSOLETE @cindex log file for EB29K
11216 @c OBSOLETE
11217 @c OBSOLETE The @code{target amd-eb} command creates a file @file{eb.log} in the
11218 @c OBSOLETE current working directory, to help debug problems with the connection.
11219 @c OBSOLETE @file{eb.log} records all the output from @code{EBMON}, including echoes
11220 @c OBSOLETE of the commands sent to it. Running @samp{tail -f} on this file in
11221 @c OBSOLETE another window often helps to understand trouble with @code{EBMON}, or
11222 @c OBSOLETE unexpected events on the PC side of the connection.
11223
11224 @node ARM
11225 @subsection ARM
11226
11227 @table @code
11228
11229 @kindex target rdi
11230 @item target rdi @var{dev}
11231 ARM Angel monitor, via RDI library interface to ADP protocol. You may
11232 use this target to communicate with both boards running the Angel
11233 monitor, or with the EmbeddedICE JTAG debug device.
11234
11235 @kindex target rdp
11236 @item target rdp @var{dev}
11237 ARM Demon monitor.
11238
11239 @end table
11240
11241 @node H8/300
11242 @subsection Hitachi H8/300
11243
11244 @table @code
11245
11246 @kindex target hms@r{, with H8/300}
11247 @item target hms @var{dev}
11248 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
11249 Use special commands @code{device} and @code{speed} to control the serial
11250 line and the communications speed used.
11251
11252 @kindex target e7000@r{, with H8/300}
11253 @item target e7000 @var{dev}
11254 E7000 emulator for Hitachi H8 and SH.
11255
11256 @kindex target sh3@r{, with H8/300}
11257 @kindex target sh3e@r{, with H8/300}
11258 @item target sh3 @var{dev}
11259 @itemx target sh3e @var{dev}
11260 Hitachi SH-3 and SH-3E target systems.
11261
11262 @end table
11263
11264 @cindex download to H8/300 or H8/500
11265 @cindex H8/300 or H8/500 download
11266 @cindex download to Hitachi SH
11267 @cindex Hitachi SH download
11268 When you select remote debugging to a Hitachi SH, H8/300, or H8/500
11269 board, the @code{load} command downloads your program to the Hitachi
11270 board and also opens it as the current executable target for
11271 @value{GDBN} on your host (like the @code{file} command).
11272
11273 @value{GDBN} needs to know these things to talk to your
11274 Hitachi SH, H8/300, or H8/500:
11275
11276 @enumerate
11277 @item
11278 that you want to use @samp{target hms}, the remote debugging interface
11279 for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
11280 emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
11281 the default when @value{GDBN} is configured specifically for the Hitachi SH,
11282 H8/300, or H8/500.)
11283
11284 @item
11285 what serial device connects your host to your Hitachi board (the first
11286 serial device available on your host is the default).
11287
11288 @item
11289 what speed to use over the serial device.
11290 @end enumerate
11291
11292 @menu
11293 * Hitachi Boards:: Connecting to Hitachi boards.
11294 * Hitachi ICE:: Using the E7000 In-Circuit Emulator.
11295 * Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
11296 @end menu
11297
11298 @node Hitachi Boards
11299 @subsubsection Connecting to Hitachi boards
11300
11301 @c only for Unix hosts
11302 @kindex device
11303 @cindex serial device, Hitachi micros
11304 Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
11305 need to explicitly set the serial device. The default @var{port} is the
11306 first available port on your host. This is only necessary on Unix
11307 hosts, where it is typically something like @file{/dev/ttya}.
11308
11309 @kindex speed
11310 @cindex serial line speed, Hitachi micros
11311 @code{@value{GDBN}} has another special command to set the communications
11312 speed: @samp{speed @var{bps}}. This command also is only used from Unix
11313 hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
11314 the DOS @code{mode} command (for instance,
11315 @w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
11316
11317 The @samp{device} and @samp{speed} commands are available only when you
11318 use a Unix host to debug your Hitachi microprocessor programs. If you
11319 use a DOS host,
11320 @value{GDBN} depends on an auxiliary terminate-and-stay-resident program
11321 called @code{asynctsr} to communicate with the development board
11322 through a PC serial port. You must also use the DOS @code{mode} command
11323 to set up the serial port on the DOS side.
11324
11325 The following sample session illustrates the steps needed to start a
11326 program under @value{GDBN} control on an H8/300. The example uses a
11327 sample H8/300 program called @file{t.x}. The procedure is the same for
11328 the Hitachi SH and the H8/500.
11329
11330 First hook up your development board. In this example, we use a
11331 board attached to serial port @code{COM2}; if you use a different serial
11332 port, substitute its name in the argument of the @code{mode} command.
11333 When you call @code{asynctsr}, the auxiliary comms program used by the
11334 debugger, you give it just the numeric part of the serial port's name;
11335 for example, @samp{asyncstr 2} below runs @code{asyncstr} on
11336 @code{COM2}.
11337
11338 @smallexample
11339 C:\H8300\TEST> asynctsr 2
11340 C:\H8300\TEST> mode com2:9600,n,8,1,p
11341
11342 Resident portion of MODE loaded
11343
11344 COM2: 9600, n, 8, 1, p
11345
11346 @end smallexample
11347
11348 @quotation
11349 @emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
11350 @code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
11351 disable it, or even boot without it, to use @code{asynctsr} to control
11352 your development board.
11353 @end quotation
11354
11355 @kindex target hms@r{, and serial protocol}
11356 Now that serial communications are set up, and the development board is
11357 connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
11358 the name of your program as the argument. @code{@value{GDBN}} prompts
11359 you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
11360 commands to begin your debugging session: @samp{target hms} to specify
11361 cross-debugging to the Hitachi board, and the @code{load} command to
11362 download your program to the board. @code{load} displays the names of
11363 the program's sections, and a @samp{*} for each 2K of data downloaded.
11364 (If you want to refresh @value{GDBN} data on symbols or on the
11365 executable file without downloading, use the @value{GDBN} commands
11366 @code{file} or @code{symbol-file}. These commands, and @code{load}
11367 itself, are described in @ref{Files,,Commands to specify files}.)
11368
11369 @smallexample
11370 (eg-C:\H8300\TEST) @value{GDBP} t.x
11371 @value{GDBN} is free software and you are welcome to distribute copies
11372 of it under certain conditions; type "show copying" to see
11373 the conditions.
11374 There is absolutely no warranty for @value{GDBN}; type "show warranty"
11375 for details.
11376 @value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
11377 (@value{GDBP}) target hms
11378 Connected to remote H8/300 HMS system.
11379 (@value{GDBP}) load t.x
11380 .text : 0x8000 .. 0xabde ***********
11381 .data : 0xabde .. 0xad30 *
11382 .stack : 0xf000 .. 0xf014 *
11383 @end smallexample
11384
11385 At this point, you're ready to run or debug your program. From here on,
11386 you can use all the usual @value{GDBN} commands. The @code{break} command
11387 sets breakpoints; the @code{run} command starts your program;
11388 @code{print} or @code{x} display data; the @code{continue} command
11389 resumes execution after stopping at a breakpoint. You can use the
11390 @code{help} command at any time to find out more about @value{GDBN} commands.
11391
11392 Remember, however, that @emph{operating system} facilities aren't
11393 available on your development board; for example, if your program hangs,
11394 you can't send an interrupt---but you can press the @sc{reset} switch!
11395
11396 Use the @sc{reset} button on the development board
11397 @itemize @bullet
11398 @item
11399 to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
11400 no way to pass an interrupt signal to the development board); and
11401
11402 @item
11403 to return to the @value{GDBN} command prompt after your program finishes
11404 normally. The communications protocol provides no other way for @value{GDBN}
11405 to detect program completion.
11406 @end itemize
11407
11408 In either case, @value{GDBN} sees the effect of a @sc{reset} on the
11409 development board as a ``normal exit'' of your program.
11410
11411 @node Hitachi ICE
11412 @subsubsection Using the E7000 in-circuit emulator
11413
11414 @kindex target e7000@r{, with Hitachi ICE}
11415 You can use the E7000 in-circuit emulator to develop code for either the
11416 Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
11417 e7000} command to connect @value{GDBN} to your E7000:
11418
11419 @table @code
11420 @item target e7000 @var{port} @var{speed}
11421 Use this form if your E7000 is connected to a serial port. The
11422 @var{port} argument identifies what serial port to use (for example,
11423 @samp{com2}). The third argument is the line speed in bits per second
11424 (for example, @samp{9600}).
11425
11426 @item target e7000 @var{hostname}
11427 If your E7000 is installed as a host on a TCP/IP network, you can just
11428 specify its hostname; @value{GDBN} uses @code{telnet} to connect.
11429 @end table
11430
11431 @node Hitachi Special
11432 @subsubsection Special @value{GDBN} commands for Hitachi micros
11433
11434 Some @value{GDBN} commands are available only for the H8/300:
11435
11436 @table @code
11437
11438 @kindex set machine
11439 @kindex show machine
11440 @item set machine h8300
11441 @itemx set machine h8300h
11442 Condition @value{GDBN} for one of the two variants of the H8/300
11443 architecture with @samp{set machine}. You can use @samp{show machine}
11444 to check which variant is currently in effect.
11445
11446 @end table
11447
11448 @node H8/500
11449 @subsection H8/500
11450
11451 @table @code
11452
11453 @kindex set memory @var{mod}
11454 @cindex memory models, H8/500
11455 @item set memory @var{mod}
11456 @itemx show memory
11457 Specify which H8/500 memory model (@var{mod}) you are using with
11458 @samp{set memory}; check which memory model is in effect with @samp{show
11459 memory}. The accepted values for @var{mod} are @code{small},
11460 @code{big}, @code{medium}, and @code{compact}.
11461
11462 @end table
11463
11464 @node i960
11465 @subsection Intel i960
11466
11467 @table @code
11468
11469 @kindex target mon960
11470 @item target mon960 @var{dev}
11471 MON960 monitor for Intel i960.
11472
11473 @kindex target nindy
11474 @item target nindy @var{devicename}
11475 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
11476 the name of the serial device to use for the connection, e.g.
11477 @file{/dev/ttya}.
11478
11479 @end table
11480
11481 @cindex Nindy
11482 @cindex i960
11483 @dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
11484 @value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
11485 tell @value{GDBN} how to connect to the 960 in several ways:
11486
11487 @itemize @bullet
11488 @item
11489 Through command line options specifying serial port, version of the
11490 Nindy protocol, and communications speed;
11491
11492 @item
11493 By responding to a prompt on startup;
11494
11495 @item
11496 By using the @code{target} command at any point during your @value{GDBN}
11497 session. @xref{Target Commands, ,Commands for managing targets}.
11498
11499 @end itemize
11500
11501 @cindex download to Nindy-960
11502 With the Nindy interface to an Intel 960 board, @code{load}
11503 downloads @var{filename} to the 960 as well as adding its symbols in
11504 @value{GDBN}.
11505
11506 @menu
11507 * Nindy Startup:: Startup with Nindy
11508 * Nindy Options:: Options for Nindy
11509 * Nindy Reset:: Nindy reset command
11510 @end menu
11511
11512 @node Nindy Startup
11513 @subsubsection Startup with Nindy
11514
11515 If you simply start @code{@value{GDBP}} without using any command-line
11516 options, you are prompted for what serial port to use, @emph{before} you
11517 reach the ordinary @value{GDBN} prompt:
11518
11519 @smallexample
11520 Attach /dev/ttyNN -- specify NN, or "quit" to quit:
11521 @end smallexample
11522
11523 @noindent
11524 Respond to the prompt with whatever suffix (after @samp{/dev/tty})
11525 identifies the serial port you want to use. You can, if you choose,
11526 simply start up with no Nindy connection by responding to the prompt
11527 with an empty line. If you do this and later wish to attach to Nindy,
11528 use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
11529
11530 @node Nindy Options
11531 @subsubsection Options for Nindy
11532
11533 These are the startup options for beginning your @value{GDBN} session with a
11534 Nindy-960 board attached:
11535
11536 @table @code
11537 @item -r @var{port}
11538 Specify the serial port name of a serial interface to be used to connect
11539 to the target system. This option is only available when @value{GDBN} is
11540 configured for the Intel 960 target architecture. You may specify
11541 @var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
11542 device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
11543 suffix for a specific @code{tty} (e.g. @samp{-r a}).
11544
11545 @item -O
11546 (An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
11547 the ``old'' Nindy monitor protocol to connect to the target system.
11548 This option is only available when @value{GDBN} is configured for the Intel 960
11549 target architecture.
11550
11551 @quotation
11552 @emph{Warning:} if you specify @samp{-O}, but are actually trying to
11553 connect to a target system that expects the newer protocol, the connection
11554 fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
11555 attempts to reconnect at several different line speeds. You can abort
11556 this process with an interrupt.
11557 @end quotation
11558
11559 @item -brk
11560 Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
11561 system, in an attempt to reset it, before connecting to a Nindy target.
11562
11563 @quotation
11564 @emph{Warning:} Many target systems do not have the hardware that this
11565 requires; it only works with a few boards.
11566 @end quotation
11567 @end table
11568
11569 The standard @samp{-b} option controls the line speed used on the serial
11570 port.
11571
11572 @c @group
11573 @node Nindy Reset
11574 @subsubsection Nindy reset command
11575
11576 @table @code
11577 @item reset
11578 @kindex reset
11579 For a Nindy target, this command sends a ``break'' to the remote target
11580 system; this is only useful if the target has been equipped with a
11581 circuit to perform a hard reset (or some other interesting action) when
11582 a break is detected.
11583 @end table
11584 @c @end group
11585
11586 @node M32R/D
11587 @subsection Mitsubishi M32R/D
11588
11589 @table @code
11590
11591 @kindex target m32r
11592 @item target m32r @var{dev}
11593 Mitsubishi M32R/D ROM monitor.
11594
11595 @end table
11596
11597 @node M68K
11598 @subsection M68k
11599
11600 The Motorola m68k configuration includes ColdFire support, and
11601 target command for the following ROM monitors.
11602
11603 @table @code
11604
11605 @kindex target abug
11606 @item target abug @var{dev}
11607 ABug ROM monitor for M68K.
11608
11609 @kindex target cpu32bug
11610 @item target cpu32bug @var{dev}
11611 CPU32BUG monitor, running on a CPU32 (M68K) board.
11612
11613 @kindex target dbug
11614 @item target dbug @var{dev}
11615 dBUG ROM monitor for Motorola ColdFire.
11616
11617 @kindex target est
11618 @item target est @var{dev}
11619 EST-300 ICE monitor, running on a CPU32 (M68K) board.
11620
11621 @kindex target rom68k
11622 @item target rom68k @var{dev}
11623 ROM 68K monitor, running on an M68K IDP board.
11624
11625 @end table
11626
11627 If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
11628 instead have only a single special target command:
11629
11630 @table @code
11631
11632 @kindex target es1800
11633 @item target es1800 @var{dev}
11634 ES-1800 emulator for M68K.
11635
11636 @end table
11637
11638 [context?]
11639
11640 @table @code
11641
11642 @kindex target rombug
11643 @item target rombug @var{dev}
11644 ROMBUG ROM monitor for OS/9000.
11645
11646 @end table
11647
11648 @node M88K
11649 @subsection M88K
11650
11651 @table @code
11652
11653 @kindex target bug
11654 @item target bug @var{dev}
11655 BUG monitor, running on a MVME187 (m88k) board.
11656
11657 @end table
11658
11659 @node MIPS Embedded
11660 @subsection MIPS Embedded
11661
11662 @cindex MIPS boards
11663 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
11664 MIPS board attached to a serial line. This is available when
11665 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
11666
11667 @need 1000
11668 Use these @value{GDBN} commands to specify the connection to your target board:
11669
11670 @table @code
11671 @item target mips @var{port}
11672 @kindex target mips @var{port}
11673 To run a program on the board, start up @code{@value{GDBP}} with the
11674 name of your program as the argument. To connect to the board, use the
11675 command @samp{target mips @var{port}}, where @var{port} is the name of
11676 the serial port connected to the board. If the program has not already
11677 been downloaded to the board, you may use the @code{load} command to
11678 download it. You can then use all the usual @value{GDBN} commands.
11679
11680 For example, this sequence connects to the target board through a serial
11681 port, and loads and runs a program called @var{prog} through the
11682 debugger:
11683
11684 @smallexample
11685 host$ @value{GDBP} @var{prog}
11686 @value{GDBN} is free software and @dots{}
11687 (@value{GDBP}) target mips /dev/ttyb
11688 (@value{GDBP}) load @var{prog}
11689 (@value{GDBP}) run
11690 @end smallexample
11691
11692 @item target mips @var{hostname}:@var{portnumber}
11693 On some @value{GDBN} host configurations, you can specify a TCP
11694 connection (for instance, to a serial line managed by a terminal
11695 concentrator) instead of a serial port, using the syntax
11696 @samp{@var{hostname}:@var{portnumber}}.
11697
11698 @item target pmon @var{port}
11699 @kindex target pmon @var{port}
11700 PMON ROM monitor.
11701
11702 @item target ddb @var{port}
11703 @kindex target ddb @var{port}
11704 NEC's DDB variant of PMON for Vr4300.
11705
11706 @item target lsi @var{port}
11707 @kindex target lsi @var{port}
11708 LSI variant of PMON.
11709
11710 @kindex target r3900
11711 @item target r3900 @var{dev}
11712 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
11713
11714 @kindex target array
11715 @item target array @var{dev}
11716 Array Tech LSI33K RAID controller board.
11717
11718 @end table
11719
11720
11721 @noindent
11722 @value{GDBN} also supports these special commands for MIPS targets:
11723
11724 @table @code
11725 @item set processor @var{args}
11726 @itemx show processor
11727 @kindex set processor @var{args}
11728 @kindex show processor
11729 Use the @code{set processor} command to set the type of MIPS
11730 processor when you want to access processor-type-specific registers.
11731 For example, @code{set processor @var{r3041}} tells @value{GDBN}
11732 to use the CPU registers appropriate for the 3041 chip.
11733 Use the @code{show processor} command to see what MIPS processor @value{GDBN}
11734 is using. Use the @code{info reg} command to see what registers
11735 @value{GDBN} is using.
11736
11737 @item set mipsfpu double
11738 @itemx set mipsfpu single
11739 @itemx set mipsfpu none
11740 @itemx show mipsfpu
11741 @kindex set mipsfpu
11742 @kindex show mipsfpu
11743 @cindex MIPS remote floating point
11744 @cindex floating point, MIPS remote
11745 If your target board does not support the MIPS floating point
11746 coprocessor, you should use the command @samp{set mipsfpu none} (if you
11747 need this, you may wish to put the command in your @value{GDBN} init
11748 file). This tells @value{GDBN} how to find the return value of
11749 functions which return floating point values. It also allows
11750 @value{GDBN} to avoid saving the floating point registers when calling
11751 functions on the board. If you are using a floating point coprocessor
11752 with only single precision floating point support, as on the @sc{r4650}
11753 processor, use the command @samp{set mipsfpu single}. The default
11754 double precision floating point coprocessor may be selected using
11755 @samp{set mipsfpu double}.
11756
11757 In previous versions the only choices were double precision or no
11758 floating point, so @samp{set mipsfpu on} will select double precision
11759 and @samp{set mipsfpu off} will select no floating point.
11760
11761 As usual, you can inquire about the @code{mipsfpu} variable with
11762 @samp{show mipsfpu}.
11763
11764 @item set remotedebug @var{n}
11765 @itemx show remotedebug
11766 @kindex set remotedebug@r{, MIPS protocol}
11767 @kindex show remotedebug@r{, MIPS protocol}
11768 @cindex @code{remotedebug}, MIPS protocol
11769 @cindex MIPS @code{remotedebug} protocol
11770 @c FIXME! For this to be useful, you must know something about the MIPS
11771 @c FIXME...protocol. Where is it described?
11772 You can see some debugging information about communications with the board
11773 by setting the @code{remotedebug} variable. If you set it to @code{1} using
11774 @samp{set remotedebug 1}, every packet is displayed. If you set it
11775 to @code{2}, every character is displayed. You can check the current value
11776 at any time with the command @samp{show remotedebug}.
11777
11778 @item set timeout @var{seconds}
11779 @itemx set retransmit-timeout @var{seconds}
11780 @itemx show timeout
11781 @itemx show retransmit-timeout
11782 @cindex @code{timeout}, MIPS protocol
11783 @cindex @code{retransmit-timeout}, MIPS protocol
11784 @kindex set timeout
11785 @kindex show timeout
11786 @kindex set retransmit-timeout
11787 @kindex show retransmit-timeout
11788 You can control the timeout used while waiting for a packet, in the MIPS
11789 remote protocol, with the @code{set timeout @var{seconds}} command. The
11790 default is 5 seconds. Similarly, you can control the timeout used while
11791 waiting for an acknowledgement of a packet with the @code{set
11792 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
11793 You can inspect both values with @code{show timeout} and @code{show
11794 retransmit-timeout}. (These commands are @emph{only} available when
11795 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
11796
11797 The timeout set by @code{set timeout} does not apply when @value{GDBN}
11798 is waiting for your program to stop. In that case, @value{GDBN} waits
11799 forever because it has no way of knowing how long the program is going
11800 to run before stopping.
11801 @end table
11802
11803 @node PowerPC
11804 @subsection PowerPC
11805
11806 @table @code
11807
11808 @kindex target dink32
11809 @item target dink32 @var{dev}
11810 DINK32 ROM monitor.
11811
11812 @kindex target ppcbug
11813 @item target ppcbug @var{dev}
11814 @kindex target ppcbug1
11815 @item target ppcbug1 @var{dev}
11816 PPCBUG ROM monitor for PowerPC.
11817
11818 @kindex target sds
11819 @item target sds @var{dev}
11820 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
11821
11822 @end table
11823
11824 @node PA
11825 @subsection HP PA Embedded
11826
11827 @table @code
11828
11829 @kindex target op50n
11830 @item target op50n @var{dev}
11831 OP50N monitor, running on an OKI HPPA board.
11832
11833 @kindex target w89k
11834 @item target w89k @var{dev}
11835 W89K monitor, running on a Winbond HPPA board.
11836
11837 @end table
11838
11839 @node SH
11840 @subsection Hitachi SH
11841
11842 @table @code
11843
11844 @kindex target hms@r{, with Hitachi SH}
11845 @item target hms @var{dev}
11846 A Hitachi SH board attached via serial line to your host. Use special
11847 commands @code{device} and @code{speed} to control the serial line and
11848 the communications speed used.
11849
11850 @kindex target e7000@r{, with Hitachi SH}
11851 @item target e7000 @var{dev}
11852 E7000 emulator for Hitachi SH.
11853
11854 @kindex target sh3@r{, with SH}
11855 @kindex target sh3e@r{, with SH}
11856 @item target sh3 @var{dev}
11857 @item target sh3e @var{dev}
11858 Hitachi SH-3 and SH-3E target systems.
11859
11860 @end table
11861
11862 @node Sparclet
11863 @subsection Tsqware Sparclet
11864
11865 @cindex Sparclet
11866
11867 @value{GDBN} enables developers to debug tasks running on
11868 Sparclet targets from a Unix host.
11869 @value{GDBN} uses code that runs on
11870 both the Unix host and on the Sparclet target. The program
11871 @code{@value{GDBP}} is installed and executed on the Unix host.
11872
11873 @table @code
11874 @item remotetimeout @var{args}
11875 @kindex remotetimeout
11876 @value{GDBN} supports the option @code{remotetimeout}.
11877 This option is set by the user, and @var{args} represents the number of
11878 seconds @value{GDBN} waits for responses.
11879 @end table
11880
11881 @cindex compiling, on Sparclet
11882 When compiling for debugging, include the options @samp{-g} to get debug
11883 information and @samp{-Ttext} to relocate the program to where you wish to
11884 load it on the target. You may also want to add the options @samp{-n} or
11885 @samp{-N} in order to reduce the size of the sections. Example:
11886
11887 @smallexample
11888 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
11889 @end smallexample
11890
11891 You can use @code{objdump} to verify that the addresses are what you intended:
11892
11893 @smallexample
11894 sparclet-aout-objdump --headers --syms prog
11895 @end smallexample
11896
11897 @cindex running, on Sparclet
11898 Once you have set
11899 your Unix execution search path to find @value{GDBN}, you are ready to
11900 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
11901 (or @code{sparclet-aout-gdb}, depending on your installation).
11902
11903 @value{GDBN} comes up showing the prompt:
11904
11905 @smallexample
11906 (gdbslet)
11907 @end smallexample
11908
11909 @menu
11910 * Sparclet File:: Setting the file to debug
11911 * Sparclet Connection:: Connecting to Sparclet
11912 * Sparclet Download:: Sparclet download
11913 * Sparclet Execution:: Running and debugging
11914 @end menu
11915
11916 @node Sparclet File
11917 @subsubsection Setting file to debug
11918
11919 The @value{GDBN} command @code{file} lets you choose with program to debug.
11920
11921 @smallexample
11922 (gdbslet) file prog
11923 @end smallexample
11924
11925 @need 1000
11926 @value{GDBN} then attempts to read the symbol table of @file{prog}.
11927 @value{GDBN} locates
11928 the file by searching the directories listed in the command search
11929 path.
11930 If the file was compiled with debug information (option "-g"), source
11931 files will be searched as well.
11932 @value{GDBN} locates
11933 the source files by searching the directories listed in the directory search
11934 path (@pxref{Environment, ,Your program's environment}).
11935 If it fails
11936 to find a file, it displays a message such as:
11937
11938 @smallexample
11939 prog: No such file or directory.
11940 @end smallexample
11941
11942 When this happens, add the appropriate directories to the search paths with
11943 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
11944 @code{target} command again.
11945
11946 @node Sparclet Connection
11947 @subsubsection Connecting to Sparclet
11948
11949 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
11950 To connect to a target on serial port ``@code{ttya}'', type:
11951
11952 @smallexample
11953 (gdbslet) target sparclet /dev/ttya
11954 Remote target sparclet connected to /dev/ttya
11955 main () at ../prog.c:3
11956 @end smallexample
11957
11958 @need 750
11959 @value{GDBN} displays messages like these:
11960
11961 @smallexample
11962 Connected to ttya.
11963 @end smallexample
11964
11965 @node Sparclet Download
11966 @subsubsection Sparclet download
11967
11968 @cindex download to Sparclet
11969 Once connected to the Sparclet target,
11970 you can use the @value{GDBN}
11971 @code{load} command to download the file from the host to the target.
11972 The file name and load offset should be given as arguments to the @code{load}
11973 command.
11974 Since the file format is aout, the program must be loaded to the starting
11975 address. You can use @code{objdump} to find out what this value is. The load
11976 offset is an offset which is added to the VMA (virtual memory address)
11977 of each of the file's sections.
11978 For instance, if the program
11979 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
11980 and bss at 0x12010170, in @value{GDBN}, type:
11981
11982 @smallexample
11983 (gdbslet) load prog 0x12010000
11984 Loading section .text, size 0xdb0 vma 0x12010000
11985 @end smallexample
11986
11987 If the code is loaded at a different address then what the program was linked
11988 to, you may need to use the @code{section} and @code{add-symbol-file} commands
11989 to tell @value{GDBN} where to map the symbol table.
11990
11991 @node Sparclet Execution
11992 @subsubsection Running and debugging
11993
11994 @cindex running and debugging Sparclet programs
11995 You can now begin debugging the task using @value{GDBN}'s execution control
11996 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
11997 manual for the list of commands.
11998
11999 @smallexample
12000 (gdbslet) b main
12001 Breakpoint 1 at 0x12010000: file prog.c, line 3.
12002 (gdbslet) run
12003 Starting program: prog
12004 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
12005 3 char *symarg = 0;
12006 (gdbslet) step
12007 4 char *execarg = "hello!";
12008 (gdbslet)
12009 @end smallexample
12010
12011 @node Sparclite
12012 @subsection Fujitsu Sparclite
12013
12014 @table @code
12015
12016 @kindex target sparclite
12017 @item target sparclite @var{dev}
12018 Fujitsu sparclite boards, used only for the purpose of loading.
12019 You must use an additional command to debug the program.
12020 For example: target remote @var{dev} using @value{GDBN} standard
12021 remote protocol.
12022
12023 @end table
12024
12025 @node ST2000
12026 @subsection Tandem ST2000
12027
12028 @value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
12029 STDBUG protocol.
12030
12031 To connect your ST2000 to the host system, see the manufacturer's
12032 manual. Once the ST2000 is physically attached, you can run:
12033
12034 @smallexample
12035 target st2000 @var{dev} @var{speed}
12036 @end smallexample
12037
12038 @noindent
12039 to establish it as your debugging environment. @var{dev} is normally
12040 the name of a serial device, such as @file{/dev/ttya}, connected to the
12041 ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12042 connection (for example, to a serial line attached via a terminal
12043 concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
12044
12045 The @code{load} and @code{attach} commands are @emph{not} defined for
12046 this target; you must load your program into the ST2000 as you normally
12047 would for standalone operation. @value{GDBN} reads debugging information
12048 (such as symbols) from a separate, debugging version of the program
12049 available on your host computer.
12050 @c FIXME!! This is terribly vague; what little content is here is
12051 @c basically hearsay.
12052
12053 @cindex ST2000 auxiliary commands
12054 These auxiliary @value{GDBN} commands are available to help you with the ST2000
12055 environment:
12056
12057 @table @code
12058 @item st2000 @var{command}
12059 @kindex st2000 @var{cmd}
12060 @cindex STDBUG commands (ST2000)
12061 @cindex commands to STDBUG (ST2000)
12062 Send a @var{command} to the STDBUG monitor. See the manufacturer's
12063 manual for available commands.
12064
12065 @item connect
12066 @cindex connect (to STDBUG)
12067 Connect the controlling terminal to the STDBUG command monitor. When
12068 you are done interacting with STDBUG, typing either of two character
12069 sequences gets you back to the @value{GDBN} command prompt:
12070 @kbd{@key{RET}~.} (Return, followed by tilde and period) or
12071 @kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
12072 @end table
12073
12074 @node Z8000
12075 @subsection Zilog Z8000
12076
12077 @cindex Z8000
12078 @cindex simulator, Z8000
12079 @cindex Zilog Z8000 simulator
12080
12081 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12082 a Z8000 simulator.
12083
12084 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12085 unsegmented variant of the Z8000 architecture) or the Z8001 (the
12086 segmented variant). The simulator recognizes which architecture is
12087 appropriate by inspecting the object code.
12088
12089 @table @code
12090 @item target sim @var{args}
12091 @kindex sim
12092 @kindex target sim@r{, with Z8000}
12093 Debug programs on a simulated CPU. If the simulator supports setup
12094 options, specify them via @var{args}.
12095 @end table
12096
12097 @noindent
12098 After specifying this target, you can debug programs for the simulated
12099 CPU in the same style as programs for your host computer; use the
12100 @code{file} command to load a new program image, the @code{run} command
12101 to run your program, and so on.
12102
12103 As well as making available all the usual machine registers
12104 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12105 additional items of information as specially named registers:
12106
12107 @table @code
12108
12109 @item cycles
12110 Counts clock-ticks in the simulator.
12111
12112 @item insts
12113 Counts instructions run in the simulator.
12114
12115 @item time
12116 Execution time in 60ths of a second.
12117
12118 @end table
12119
12120 You can refer to these values in @value{GDBN} expressions with the usual
12121 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12122 conditional breakpoint that suspends only after at least 5000
12123 simulated clock ticks.
12124
12125 @node Architectures
12126 @section Architectures
12127
12128 This section describes characteristics of architectures that affect
12129 all uses of @value{GDBN} with the architecture, both native and cross.
12130
12131 @menu
12132 * A29K::
12133 * Alpha::
12134 * MIPS::
12135 @end menu
12136
12137 @node A29K
12138 @subsection A29K
12139
12140 @table @code
12141
12142 @kindex set rstack_high_address
12143 @cindex AMD 29K register stack
12144 @cindex register stack, AMD29K
12145 @item set rstack_high_address @var{address}
12146 On AMD 29000 family processors, registers are saved in a separate
12147 @dfn{register stack}. There is no way for @value{GDBN} to determine the
12148 extent of this stack. Normally, @value{GDBN} just assumes that the
12149 stack is ``large enough''. This may result in @value{GDBN} referencing
12150 memory locations that do not exist. If necessary, you can get around
12151 this problem by specifying the ending address of the register stack with
12152 the @code{set rstack_high_address} command. The argument should be an
12153 address, which you probably want to precede with @samp{0x} to specify in
12154 hexadecimal.
12155
12156 @kindex show rstack_high_address
12157 @item show rstack_high_address
12158 Display the current limit of the register stack, on AMD 29000 family
12159 processors.
12160
12161 @end table
12162
12163 @node Alpha
12164 @subsection Alpha
12165
12166 See the following section.
12167
12168 @node MIPS
12169 @subsection MIPS
12170
12171 @cindex stack on Alpha
12172 @cindex stack on MIPS
12173 @cindex Alpha stack
12174 @cindex MIPS stack
12175 Alpha- and MIPS-based computers use an unusual stack frame, which
12176 sometimes requires @value{GDBN} to search backward in the object code to
12177 find the beginning of a function.
12178
12179 @cindex response time, MIPS debugging
12180 To improve response time (especially for embedded applications, where
12181 @value{GDBN} may be restricted to a slow serial line for this search)
12182 you may want to limit the size of this search, using one of these
12183 commands:
12184
12185 @table @code
12186 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
12187 @item set heuristic-fence-post @var{limit}
12188 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12189 search for the beginning of a function. A value of @var{0} (the
12190 default) means there is no limit. However, except for @var{0}, the
12191 larger the limit the more bytes @code{heuristic-fence-post} must search
12192 and therefore the longer it takes to run.
12193
12194 @item show heuristic-fence-post
12195 Display the current limit.
12196 @end table
12197
12198 @noindent
12199 These commands are available @emph{only} when @value{GDBN} is configured
12200 for debugging programs on Alpha or MIPS processors.
12201
12202
12203 @node Controlling GDB
12204 @chapter Controlling @value{GDBN}
12205
12206 You can alter the way @value{GDBN} interacts with you by using the
12207 @code{set} command. For commands controlling how @value{GDBN} displays
12208 data, see @ref{Print Settings, ,Print settings}. Other settings are
12209 described here.
12210
12211 @menu
12212 * Prompt:: Prompt
12213 * Editing:: Command editing
12214 * History:: Command history
12215 * Screen Size:: Screen size
12216 * Numbers:: Numbers
12217 * Messages/Warnings:: Optional warnings and messages
12218 * Debugging Output:: Optional messages about internal happenings
12219 @end menu
12220
12221 @node Prompt
12222 @section Prompt
12223
12224 @cindex prompt
12225
12226 @value{GDBN} indicates its readiness to read a command by printing a string
12227 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
12228 can change the prompt string with the @code{set prompt} command. For
12229 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
12230 the prompt in one of the @value{GDBN} sessions so that you can always tell
12231 which one you are talking to.
12232
12233 @emph{Note:} @code{set prompt} does not add a space for you after the
12234 prompt you set. This allows you to set a prompt which ends in a space
12235 or a prompt that does not.
12236
12237 @table @code
12238 @kindex set prompt
12239 @item set prompt @var{newprompt}
12240 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
12241
12242 @kindex show prompt
12243 @item show prompt
12244 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
12245 @end table
12246
12247 @node Editing
12248 @section Command editing
12249 @cindex readline
12250 @cindex command line editing
12251
12252 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
12253 @sc{gnu} library provides consistent behavior for programs which provide a
12254 command line interface to the user. Advantages are @sc{gnu} Emacs-style
12255 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
12256 substitution, and a storage and recall of command history across
12257 debugging sessions.
12258
12259 You may control the behavior of command line editing in @value{GDBN} with the
12260 command @code{set}.
12261
12262 @table @code
12263 @kindex set editing
12264 @cindex editing
12265 @item set editing
12266 @itemx set editing on
12267 Enable command line editing (enabled by default).
12268
12269 @item set editing off
12270 Disable command line editing.
12271
12272 @kindex show editing
12273 @item show editing
12274 Show whether command line editing is enabled.
12275 @end table
12276
12277 @node History
12278 @section Command history
12279
12280 @value{GDBN} can keep track of the commands you type during your
12281 debugging sessions, so that you can be certain of precisely what
12282 happened. Use these commands to manage the @value{GDBN} command
12283 history facility.
12284
12285 @table @code
12286 @cindex history substitution
12287 @cindex history file
12288 @kindex set history filename
12289 @kindex GDBHISTFILE
12290 @item set history filename @var{fname}
12291 Set the name of the @value{GDBN} command history file to @var{fname}.
12292 This is the file where @value{GDBN} reads an initial command history
12293 list, and where it writes the command history from this session when it
12294 exits. You can access this list through history expansion or through
12295 the history command editing characters listed below. This file defaults
12296 to the value of the environment variable @code{GDBHISTFILE}, or to
12297 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
12298 is not set.
12299
12300 @cindex history save
12301 @kindex set history save
12302 @item set history save
12303 @itemx set history save on
12304 Record command history in a file, whose name may be specified with the
12305 @code{set history filename} command. By default, this option is disabled.
12306
12307 @item set history save off
12308 Stop recording command history in a file.
12309
12310 @cindex history size
12311 @kindex set history size
12312 @item set history size @var{size}
12313 Set the number of commands which @value{GDBN} keeps in its history list.
12314 This defaults to the value of the environment variable
12315 @code{HISTSIZE}, or to 256 if this variable is not set.
12316 @end table
12317
12318 @cindex history expansion
12319 History expansion assigns special meaning to the character @kbd{!}.
12320 @ifset have-readline-appendices
12321 @xref{Event Designators}.
12322 @end ifset
12323
12324 Since @kbd{!} is also the logical not operator in C, history expansion
12325 is off by default. If you decide to enable history expansion with the
12326 @code{set history expansion on} command, you may sometimes need to
12327 follow @kbd{!} (when it is used as logical not, in an expression) with
12328 a space or a tab to prevent it from being expanded. The readline
12329 history facilities do not attempt substitution on the strings
12330 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
12331
12332 The commands to control history expansion are:
12333
12334 @table @code
12335 @kindex set history expansion
12336 @item set history expansion on
12337 @itemx set history expansion
12338 Enable history expansion. History expansion is off by default.
12339
12340 @item set history expansion off
12341 Disable history expansion.
12342
12343 The readline code comes with more complete documentation of
12344 editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
12345 or @code{vi} may wish to read it.
12346 @ifset have-readline-appendices
12347 @xref{Command Line Editing}.
12348 @end ifset
12349
12350 @c @group
12351 @kindex show history
12352 @item show history
12353 @itemx show history filename
12354 @itemx show history save
12355 @itemx show history size
12356 @itemx show history expansion
12357 These commands display the state of the @value{GDBN} history parameters.
12358 @code{show history} by itself displays all four states.
12359 @c @end group
12360 @end table
12361
12362 @table @code
12363 @kindex shows
12364 @item show commands
12365 Display the last ten commands in the command history.
12366
12367 @item show commands @var{n}
12368 Print ten commands centered on command number @var{n}.
12369
12370 @item show commands +
12371 Print ten commands just after the commands last printed.
12372 @end table
12373
12374 @node Screen Size
12375 @section Screen size
12376 @cindex size of screen
12377 @cindex pauses in output
12378
12379 Certain commands to @value{GDBN} may produce large amounts of
12380 information output to the screen. To help you read all of it,
12381 @value{GDBN} pauses and asks you for input at the end of each page of
12382 output. Type @key{RET} when you want to continue the output, or @kbd{q}
12383 to discard the remaining output. Also, the screen width setting
12384 determines when to wrap lines of output. Depending on what is being
12385 printed, @value{GDBN} tries to break the line at a readable place,
12386 rather than simply letting it overflow onto the following line.
12387
12388 Normally @value{GDBN} knows the size of the screen from the terminal
12389 driver software. For example, on Unix @value{GDBN} uses the termcap data base
12390 together with the value of the @code{TERM} environment variable and the
12391 @code{stty rows} and @code{stty cols} settings. If this is not correct,
12392 you can override it with the @code{set height} and @code{set
12393 width} commands:
12394
12395 @table @code
12396 @kindex set height
12397 @kindex set width
12398 @kindex show width
12399 @kindex show height
12400 @item set height @var{lpp}
12401 @itemx show height
12402 @itemx set width @var{cpl}
12403 @itemx show width
12404 These @code{set} commands specify a screen height of @var{lpp} lines and
12405 a screen width of @var{cpl} characters. The associated @code{show}
12406 commands display the current settings.
12407
12408 If you specify a height of zero lines, @value{GDBN} does not pause during
12409 output no matter how long the output is. This is useful if output is to a
12410 file or to an editor buffer.
12411
12412 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
12413 from wrapping its output.
12414 @end table
12415
12416 @node Numbers
12417 @section Numbers
12418 @cindex number representation
12419 @cindex entering numbers
12420
12421 You can always enter numbers in octal, decimal, or hexadecimal in
12422 @value{GDBN} by the usual conventions: octal numbers begin with
12423 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
12424 begin with @samp{0x}. Numbers that begin with none of these are, by
12425 default, entered in base 10; likewise, the default display for
12426 numbers---when no particular format is specified---is base 10. You can
12427 change the default base for both input and output with the @code{set
12428 radix} command.
12429
12430 @table @code
12431 @kindex set input-radix
12432 @item set input-radix @var{base}
12433 Set the default base for numeric input. Supported choices
12434 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
12435 specified either unambiguously or using the current default radix; for
12436 example, any of
12437
12438 @smallexample
12439 set radix 012
12440 set radix 10.
12441 set radix 0xa
12442 @end smallexample
12443
12444 @noindent
12445 sets the base to decimal. On the other hand, @samp{set radix 10}
12446 leaves the radix unchanged no matter what it was.
12447
12448 @kindex set output-radix
12449 @item set output-radix @var{base}
12450 Set the default base for numeric display. Supported choices
12451 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
12452 specified either unambiguously or using the current default radix.
12453
12454 @kindex show input-radix
12455 @item show input-radix
12456 Display the current default base for numeric input.
12457
12458 @kindex show output-radix
12459 @item show output-radix
12460 Display the current default base for numeric display.
12461 @end table
12462
12463 @node Messages/Warnings
12464 @section Optional warnings and messages
12465
12466 By default, @value{GDBN} is silent about its inner workings. If you are
12467 running on a slow machine, you may want to use the @code{set verbose}
12468 command. This makes @value{GDBN} tell you when it does a lengthy
12469 internal operation, so you will not think it has crashed.
12470
12471 Currently, the messages controlled by @code{set verbose} are those
12472 which announce that the symbol table for a source file is being read;
12473 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
12474
12475 @table @code
12476 @kindex set verbose
12477 @item set verbose on
12478 Enables @value{GDBN} output of certain informational messages.
12479
12480 @item set verbose off
12481 Disables @value{GDBN} output of certain informational messages.
12482
12483 @kindex show verbose
12484 @item show verbose
12485 Displays whether @code{set verbose} is on or off.
12486 @end table
12487
12488 By default, if @value{GDBN} encounters bugs in the symbol table of an
12489 object file, it is silent; but if you are debugging a compiler, you may
12490 find this information useful (@pxref{Symbol Errors, ,Errors reading
12491 symbol files}).
12492
12493 @table @code
12494
12495 @kindex set complaints
12496 @item set complaints @var{limit}
12497 Permits @value{GDBN} to output @var{limit} complaints about each type of
12498 unusual symbols before becoming silent about the problem. Set
12499 @var{limit} to zero to suppress all complaints; set it to a large number
12500 to prevent complaints from being suppressed.
12501
12502 @kindex show complaints
12503 @item show complaints
12504 Displays how many symbol complaints @value{GDBN} is permitted to produce.
12505
12506 @end table
12507
12508 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
12509 lot of stupid questions to confirm certain commands. For example, if
12510 you try to run a program which is already running:
12511
12512 @smallexample
12513 (@value{GDBP}) run
12514 The program being debugged has been started already.
12515 Start it from the beginning? (y or n)
12516 @end smallexample
12517
12518 If you are willing to unflinchingly face the consequences of your own
12519 commands, you can disable this ``feature'':
12520
12521 @table @code
12522
12523 @kindex set confirm
12524 @cindex flinching
12525 @cindex confirmation
12526 @cindex stupid questions
12527 @item set confirm off
12528 Disables confirmation requests.
12529
12530 @item set confirm on
12531 Enables confirmation requests (the default).
12532
12533 @kindex show confirm
12534 @item show confirm
12535 Displays state of confirmation requests.
12536
12537 @end table
12538
12539 @node Debugging Output
12540 @section Optional messages about internal happenings
12541 @table @code
12542 @kindex set debug arch
12543 @item set debug arch
12544 Turns on or off display of gdbarch debugging info. The default is off
12545 @kindex show debug arch
12546 @item show debug arch
12547 Displays the current state of displaying gdbarch debugging info.
12548 @kindex set debug event
12549 @item set debug event
12550 Turns on or off display of @value{GDBN} event debugging info. The
12551 default is off.
12552 @kindex show debug event
12553 @item show debug event
12554 Displays the current state of displaying @value{GDBN} event debugging
12555 info.
12556 @kindex set debug expression
12557 @item set debug expression
12558 Turns on or off display of @value{GDBN} expression debugging info. The
12559 default is off.
12560 @kindex show debug expression
12561 @item show debug expression
12562 Displays the current state of displaying @value{GDBN} expression
12563 debugging info.
12564 @kindex set debug overload
12565 @item set debug overload
12566 Turns on or off display of @value{GDBN} C@t{++} overload debugging
12567 info. This includes info such as ranking of functions, etc. The default
12568 is off.
12569 @kindex show debug overload
12570 @item show debug overload
12571 Displays the current state of displaying @value{GDBN} C@t{++} overload
12572 debugging info.
12573 @kindex set debug remote
12574 @cindex packets, reporting on stdout
12575 @cindex serial connections, debugging
12576 @item set debug remote
12577 Turns on or off display of reports on all packets sent back and forth across
12578 the serial line to the remote machine. The info is printed on the
12579 @value{GDBN} standard output stream. The default is off.
12580 @kindex show debug remote
12581 @item show debug remote
12582 Displays the state of display of remote packets.
12583 @kindex set debug serial
12584 @item set debug serial
12585 Turns on or off display of @value{GDBN} serial debugging info. The
12586 default is off.
12587 @kindex show debug serial
12588 @item show debug serial
12589 Displays the current state of displaying @value{GDBN} serial debugging
12590 info.
12591 @kindex set debug target
12592 @item set debug target
12593 Turns on or off display of @value{GDBN} target debugging info. This info
12594 includes what is going on at the target level of GDB, as it happens. The
12595 default is off.
12596 @kindex show debug target
12597 @item show debug target
12598 Displays the current state of displaying @value{GDBN} target debugging
12599 info.
12600 @kindex set debug varobj
12601 @item set debug varobj
12602 Turns on or off display of @value{GDBN} variable object debugging
12603 info. The default is off.
12604 @kindex show debug varobj
12605 @item show debug varobj
12606 Displays the current state of displaying @value{GDBN} variable object
12607 debugging info.
12608 @end table
12609
12610 @node Sequences
12611 @chapter Canned Sequences of Commands
12612
12613 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
12614 command lists}), @value{GDBN} provides two ways to store sequences of
12615 commands for execution as a unit: user-defined commands and command
12616 files.
12617
12618 @menu
12619 * Define:: User-defined commands
12620 * Hooks:: User-defined command hooks
12621 * Command Files:: Command files
12622 * Output:: Commands for controlled output
12623 @end menu
12624
12625 @node Define
12626 @section User-defined commands
12627
12628 @cindex user-defined command
12629 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
12630 which you assign a new name as a command. This is done with the
12631 @code{define} command. User commands may accept up to 10 arguments
12632 separated by whitespace. Arguments are accessed within the user command
12633 via @var{$arg0@dots{}$arg9}. A trivial example:
12634
12635 @smallexample
12636 define adder
12637 print $arg0 + $arg1 + $arg2
12638 @end smallexample
12639
12640 @noindent
12641 To execute the command use:
12642
12643 @smallexample
12644 adder 1 2 3
12645 @end smallexample
12646
12647 @noindent
12648 This defines the command @code{adder}, which prints the sum of
12649 its three arguments. Note the arguments are text substitutions, so they may
12650 reference variables, use complex expressions, or even perform inferior
12651 functions calls.
12652
12653 @table @code
12654
12655 @kindex define
12656 @item define @var{commandname}
12657 Define a command named @var{commandname}. If there is already a command
12658 by that name, you are asked to confirm that you want to redefine it.
12659
12660 The definition of the command is made up of other @value{GDBN} command lines,
12661 which are given following the @code{define} command. The end of these
12662 commands is marked by a line containing @code{end}.
12663
12664 @kindex if
12665 @kindex else
12666 @item if
12667 Takes a single argument, which is an expression to evaluate.
12668 It is followed by a series of commands that are executed
12669 only if the expression is true (nonzero).
12670 There can then optionally be a line @code{else}, followed
12671 by a series of commands that are only executed if the expression
12672 was false. The end of the list is marked by a line containing @code{end}.
12673
12674 @kindex while
12675 @item while
12676 The syntax is similar to @code{if}: the command takes a single argument,
12677 which is an expression to evaluate, and must be followed by the commands to
12678 execute, one per line, terminated by an @code{end}.
12679 The commands are executed repeatedly as long as the expression
12680 evaluates to true.
12681
12682 @kindex document
12683 @item document @var{commandname}
12684 Document the user-defined command @var{commandname}, so that it can be
12685 accessed by @code{help}. The command @var{commandname} must already be
12686 defined. This command reads lines of documentation just as @code{define}
12687 reads the lines of the command definition, ending with @code{end}.
12688 After the @code{document} command is finished, @code{help} on command
12689 @var{commandname} displays the documentation you have written.
12690
12691 You may use the @code{document} command again to change the
12692 documentation of a command. Redefining the command with @code{define}
12693 does not change the documentation.
12694
12695 @kindex help user-defined
12696 @item help user-defined
12697 List all user-defined commands, with the first line of the documentation
12698 (if any) for each.
12699
12700 @kindex show user
12701 @item show user
12702 @itemx show user @var{commandname}
12703 Display the @value{GDBN} commands used to define @var{commandname} (but
12704 not its documentation). If no @var{commandname} is given, display the
12705 definitions for all user-defined commands.
12706
12707 @end table
12708
12709 When user-defined commands are executed, the
12710 commands of the definition are not printed. An error in any command
12711 stops execution of the user-defined command.
12712
12713 If used interactively, commands that would ask for confirmation proceed
12714 without asking when used inside a user-defined command. Many @value{GDBN}
12715 commands that normally print messages to say what they are doing omit the
12716 messages when used in a user-defined command.
12717
12718 @node Hooks
12719 @section User-defined command hooks
12720 @cindex command hooks
12721 @cindex hooks, for commands
12722 @cindex hooks, pre-command
12723
12724 @kindex hook
12725 @kindex hook-
12726 You may define @dfn{hooks}, which are a special kind of user-defined
12727 command. Whenever you run the command @samp{foo}, if the user-defined
12728 command @samp{hook-foo} exists, it is executed (with no arguments)
12729 before that command.
12730
12731 @cindex hooks, post-command
12732 @kindex hookpost
12733 @kindex hookpost-
12734 A hook may also be defined which is run after the command you executed.
12735 Whenever you run the command @samp{foo}, if the user-defined command
12736 @samp{hookpost-foo} exists, it is executed (with no arguments) after
12737 that command. Post-execution hooks may exist simultaneously with
12738 pre-execution hooks, for the same command.
12739
12740 It is valid for a hook to call the command which it hooks. If this
12741 occurs, the hook is not re-executed, thereby avoiding infinte recursion.
12742
12743 @c It would be nice if hookpost could be passed a parameter indicating
12744 @c if the command it hooks executed properly or not. FIXME!
12745
12746 @kindex stop@r{, a pseudo-command}
12747 In addition, a pseudo-command, @samp{stop} exists. Defining
12748 (@samp{hook-stop}) makes the associated commands execute every time
12749 execution stops in your program: before breakpoint commands are run,
12750 displays are printed, or the stack frame is printed.
12751
12752 For example, to ignore @code{SIGALRM} signals while
12753 single-stepping, but treat them normally during normal execution,
12754 you could define:
12755
12756 @smallexample
12757 define hook-stop
12758 handle SIGALRM nopass
12759 end
12760
12761 define hook-run
12762 handle SIGALRM pass
12763 end
12764
12765 define hook-continue
12766 handle SIGLARM pass
12767 end
12768 @end smallexample
12769
12770 As a further example, to hook at the begining and end of the @code{echo}
12771 command, and to add extra text to the beginning and end of the message,
12772 you could define:
12773
12774 @smallexample
12775 define hook-echo
12776 echo <<<---
12777 end
12778
12779 define hookpost-echo
12780 echo --->>>\n
12781 end
12782
12783 (@value{GDBP}) echo Hello World
12784 <<<---Hello World--->>>
12785 (@value{GDBP})
12786
12787 @end smallexample
12788
12789 You can define a hook for any single-word command in @value{GDBN}, but
12790 not for command aliases; you should define a hook for the basic command
12791 name, e.g. @code{backtrace} rather than @code{bt}.
12792 @c FIXME! So how does Joe User discover whether a command is an alias
12793 @c or not?
12794 If an error occurs during the execution of your hook, execution of
12795 @value{GDBN} commands stops and @value{GDBN} issues a prompt
12796 (before the command that you actually typed had a chance to run).
12797
12798 If you try to define a hook which does not match any known command, you
12799 get a warning from the @code{define} command.
12800
12801 @node Command Files
12802 @section Command files
12803
12804 @cindex command files
12805 A command file for @value{GDBN} is a file of lines that are @value{GDBN}
12806 commands. Comments (lines starting with @kbd{#}) may also be included.
12807 An empty line in a command file does nothing; it does not mean to repeat
12808 the last command, as it would from the terminal.
12809
12810 @cindex init file
12811 @cindex @file{.gdbinit}
12812 @cindex @file{gdb.ini}
12813 When you start @value{GDBN}, it automatically executes commands from its
12814 @dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
12815 port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
12816 limitations of file names imposed by DOS filesystems.}.
12817 During startup, @value{GDBN} does the following:
12818
12819 @enumerate
12820 @item
12821 Reads the init file (if any) in your home directory@footnote{On
12822 DOS/Windows systems, the home directory is the one pointed to by the
12823 @code{HOME} environment variable.}.
12824
12825 @item
12826 Processes command line options and operands.
12827
12828 @item
12829 Reads the init file (if any) in the current working directory.
12830
12831 @item
12832 Reads command files specified by the @samp{-x} option.
12833 @end enumerate
12834
12835 The init file in your home directory can set options (such as @samp{set
12836 complaints}) that affect subsequent processing of command line options
12837 and operands. Init files are not executed if you use the @samp{-nx}
12838 option (@pxref{Mode Options, ,Choosing modes}).
12839
12840 @cindex init file name
12841 On some configurations of @value{GDBN}, the init file is known by a
12842 different name (these are typically environments where a specialized
12843 form of @value{GDBN} may need to coexist with other forms, hence a
12844 different name for the specialized version's init file). These are the
12845 environments with special init file names:
12846
12847 @cindex @file{.vxgdbinit}
12848 @itemize @bullet
12849 @item
12850 VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
12851
12852 @cindex @file{.os68gdbinit}
12853 @item
12854 OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
12855
12856 @cindex @file{.esgdbinit}
12857 @item
12858 ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
12859 @end itemize
12860
12861 You can also request the execution of a command file with the
12862 @code{source} command:
12863
12864 @table @code
12865 @kindex source
12866 @item source @var{filename}
12867 Execute the command file @var{filename}.
12868 @end table
12869
12870 The lines in a command file are executed sequentially. They are not
12871 printed as they are executed. An error in any command terminates execution
12872 of the command file.
12873
12874 Commands that would ask for confirmation if used interactively proceed
12875 without asking when used in a command file. Many @value{GDBN} commands that
12876 normally print messages to say what they are doing omit the messages
12877 when called from command files.
12878
12879 @value{GDBN} also accepts command input from standard input. In this
12880 mode, normal output goes to standard output and error output goes to
12881 standard error. Errors in a command file supplied on standard input do
12882 not terminate execution of the command file --- execution continues with
12883 the next command.
12884
12885 @smallexample
12886 gdb < cmds > log 2>&1
12887 @end smallexample
12888
12889 (The syntax above will vary depending on the shell used.) This example
12890 will execute commands from the file @file{cmds}. All output and errors
12891 would be directed to @file{log}.
12892
12893 @node Output
12894 @section Commands for controlled output
12895
12896 During the execution of a command file or a user-defined command, normal
12897 @value{GDBN} output is suppressed; the only output that appears is what is
12898 explicitly printed by the commands in the definition. This section
12899 describes three commands useful for generating exactly the output you
12900 want.
12901
12902 @table @code
12903 @kindex echo
12904 @item echo @var{text}
12905 @c I do not consider backslash-space a standard C escape sequence
12906 @c because it is not in ANSI.
12907 Print @var{text}. Nonprinting characters can be included in
12908 @var{text} using C escape sequences, such as @samp{\n} to print a
12909 newline. @strong{No newline is printed unless you specify one.}
12910 In addition to the standard C escape sequences, a backslash followed
12911 by a space stands for a space. This is useful for displaying a
12912 string with spaces at the beginning or the end, since leading and
12913 trailing spaces are otherwise trimmed from all arguments.
12914 To print @samp{@w{ }and foo =@w{ }}, use the command
12915 @samp{echo \@w{ }and foo = \@w{ }}.
12916
12917 A backslash at the end of @var{text} can be used, as in C, to continue
12918 the command onto subsequent lines. For example,
12919
12920 @smallexample
12921 echo This is some text\n\
12922 which is continued\n\
12923 onto several lines.\n
12924 @end smallexample
12925
12926 produces the same output as
12927
12928 @smallexample
12929 echo This is some text\n
12930 echo which is continued\n
12931 echo onto several lines.\n
12932 @end smallexample
12933
12934 @kindex output
12935 @item output @var{expression}
12936 Print the value of @var{expression} and nothing but that value: no
12937 newlines, no @samp{$@var{nn} = }. The value is not entered in the
12938 value history either. @xref{Expressions, ,Expressions}, for more information
12939 on expressions.
12940
12941 @item output/@var{fmt} @var{expression}
12942 Print the value of @var{expression} in format @var{fmt}. You can use
12943 the same formats as for @code{print}. @xref{Output Formats,,Output
12944 formats}, for more information.
12945
12946 @kindex printf
12947 @item printf @var{string}, @var{expressions}@dots{}
12948 Print the values of the @var{expressions} under the control of
12949 @var{string}. The @var{expressions} are separated by commas and may be
12950 either numbers or pointers. Their values are printed as specified by
12951 @var{string}, exactly as if your program were to execute the C
12952 subroutine
12953 @c FIXME: the above implies that at least all ANSI C formats are
12954 @c supported, but it isn't true: %E and %G don't work (or so it seems).
12955 @c Either this is a bug, or the manual should document what formats are
12956 @c supported.
12957
12958 @smallexample
12959 printf (@var{string}, @var{expressions}@dots{});
12960 @end smallexample
12961
12962 For example, you can print two values in hex like this:
12963
12964 @smallexample
12965 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
12966 @end smallexample
12967
12968 The only backslash-escape sequences that you can use in the format
12969 string are the simple ones that consist of backslash followed by a
12970 letter.
12971 @end table
12972
12973 @node TUI
12974 @chapter @value{GDBN} Text User Interface
12975 @cindex TUI
12976
12977 @menu
12978 * TUI Overview:: TUI overview
12979 * TUI Keys:: TUI key bindings
12980 * TUI Commands:: TUI specific commands
12981 * TUI Configuration:: TUI configuration variables
12982 @end menu
12983
12984 The @value{GDBN} Text User Interface, TUI in short,
12985 is a terminal interface which uses the @code{curses} library
12986 to show the source file, the assembly output, the program registers
12987 and @value{GDBN} commands in separate text windows.
12988 The TUI is available only when @value{GDBN} is configured
12989 with the @code{--enable-tui} configure option (@pxref{Configure Options}).
12990
12991 @node TUI Overview
12992 @section TUI overview
12993
12994 The TUI has two display modes that can be switched while
12995 @value{GDBN} runs:
12996
12997 @itemize @bullet
12998 @item
12999 A curses (or TUI) mode in which it displays several text
13000 windows on the terminal.
13001
13002 @item
13003 A standard mode which corresponds to the @value{GDBN} configured without
13004 the TUI.
13005 @end itemize
13006
13007 In the TUI mode, @value{GDBN} can display several text window
13008 on the terminal:
13009
13010 @table @emph
13011 @item command
13012 This window is the @value{GDBN} command window with the @value{GDBN}
13013 prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13014 managed using readline but through the TUI. The @emph{command}
13015 window is always visible.
13016
13017 @item source
13018 The source window shows the source file of the program. The current
13019 line as well as active breakpoints are displayed in this window.
13020 The current program position is shown with the @samp{>} marker and
13021 active breakpoints are shown with @samp{*} markers.
13022
13023 @item assembly
13024 The assembly window shows the disassembly output of the program.
13025
13026 @item register
13027 This window shows the processor registers. It detects when
13028 a register is changed and when this is the case, registers that have
13029 changed are highlighted.
13030
13031 @end table
13032
13033 The source, assembly and register windows are attached to the thread
13034 and the frame position. They are updated when the current thread
13035 changes, when the frame changes or when the program counter changes.
13036 These three windows are arranged by the TUI according to several
13037 layouts. The layout defines which of these three windows are visible.
13038 The following layouts are available:
13039
13040 @itemize @bullet
13041 @item
13042 source
13043
13044 @item
13045 assembly
13046
13047 @item
13048 source and assembly
13049
13050 @item
13051 source and registers
13052
13053 @item
13054 assembly and registers
13055
13056 @end itemize
13057
13058 @node TUI Keys
13059 @section TUI Key Bindings
13060 @cindex TUI key bindings
13061
13062 The TUI installs several key bindings in the readline keymaps
13063 (@pxref{Command Line Editing}).
13064 They allow to leave or enter in the TUI mode or they operate
13065 directly on the TUI layout and windows. The following key bindings
13066 are installed for both TUI mode and the @value{GDBN} standard mode.
13067
13068 @table @kbd
13069 @kindex C-x C-a
13070 @item C-x C-a
13071 @kindex C-x a
13072 @itemx C-x a
13073 @kindex C-x A
13074 @itemx C-x A
13075 Enter or leave the TUI mode. When the TUI mode is left,
13076 the curses window management is left and @value{GDBN} operates using
13077 its standard mode writing on the terminal directly. When the TUI
13078 mode is entered, the control is given back to the curses windows.
13079 The screen is then refreshed.
13080
13081 @kindex C-x 1
13082 @item C-x 1
13083 Use a TUI layout with only one window. The layout will
13084 either be @samp{source} or @samp{assembly}. When the TUI mode
13085 is not active, it will switch to the TUI mode.
13086
13087 Think of this key binding as the Emacs @kbd{C-x 1} binding.
13088
13089 @kindex C-x 2
13090 @item C-x 2
13091 Use a TUI layout with at least two windows. When the current
13092 layout shows already two windows, a next layout with two windows is used.
13093 When a new layout is chosen, one window will always be common to the
13094 previous layout and the new one.
13095
13096 Think of it as the Emacs @kbd{C-x 2} binding.
13097
13098 @end table
13099
13100 The following key bindings are handled only by the TUI mode:
13101
13102 @table @key
13103 @kindex PgUp
13104 @item PgUp
13105 Scroll the active window one page up.
13106
13107 @kindex PgDn
13108 @item PgDn
13109 Scroll the active window one page down.
13110
13111 @kindex Up
13112 @item Up
13113 Scroll the active window one line up.
13114
13115 @kindex Down
13116 @item Down
13117 Scroll the active window one line down.
13118
13119 @kindex Left
13120 @item Left
13121 Scroll the active window one column left.
13122
13123 @kindex Right
13124 @item Right
13125 Scroll the active window one column right.
13126
13127 @kindex C-L
13128 @item C-L
13129 Refresh the screen.
13130
13131 @end table
13132
13133 In the TUI mode, the arrow keys are used by the active window
13134 for scrolling. This means they are not available for readline. It is
13135 necessary to use other readline key bindings such as @key{C-p}, @key{C-n},
13136 @key{C-b} and @key{C-f}.
13137
13138 @node TUI Commands
13139 @section TUI specific commands
13140 @cindex TUI commands
13141
13142 The TUI has specific commands to control the text windows.
13143 These commands are always available, that is they do not depend on
13144 the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
13145 is in the standard mode, using these commands will automatically switch
13146 in the TUI mode.
13147
13148 @table @code
13149 @item layout next
13150 @kindex layout next
13151 Display the next layout.
13152
13153 @item layout prev
13154 @kindex layout prev
13155 Display the previous layout.
13156
13157 @item layout src
13158 @kindex layout src
13159 Display the source window only.
13160
13161 @item layout asm
13162 @kindex layout asm
13163 Display the assembly window only.
13164
13165 @item layout split
13166 @kindex layout split
13167 Display the source and assembly window.
13168
13169 @item layout regs
13170 @kindex layout regs
13171 Display the register window together with the source or assembly window.
13172
13173 @item focus next | prev | src | asm | regs | split
13174 @kindex focus
13175 Set the focus to the named window.
13176 This command allows to change the active window so that scrolling keys
13177 can be affected to another window.
13178
13179 @item refresh
13180 @kindex refresh
13181 Refresh the screen. This is similar to using @key{C-L} key.
13182
13183 @item update
13184 @kindex update
13185 Update the source window and the current execution point.
13186
13187 @item winheight @var{name} +@var{count}
13188 @itemx winheight @var{name} -@var{count}
13189 @kindex winheight
13190 Change the height of the window @var{name} by @var{count}
13191 lines. Positive counts increase the height, while negative counts
13192 decrease it.
13193
13194 @end table
13195
13196 @node TUI Configuration
13197 @section TUI configuration variables
13198 @cindex TUI configuration variables
13199
13200 The TUI has several configuration variables that control the
13201 appearance of windows on the terminal.
13202
13203 @table @code
13204 @item set tui border-kind @var{kind}
13205 @kindex set tui border-kind
13206 Select the border appearance for the source, assembly and register windows.
13207 The possible values are the following:
13208 @table @code
13209 @item space
13210 Use a space character to draw the border.
13211
13212 @item ascii
13213 Use ascii characters + - and | to draw the border.
13214
13215 @item acs
13216 Use the Alternate Character Set to draw the border. The border is
13217 drawn using character line graphics if the terminal supports them.
13218
13219 @end table
13220
13221 @item set tui active-border-mode @var{mode}
13222 @kindex set tui active-border-mode
13223 Select the attributes to display the border of the active window.
13224 The possible values are @code{normal}, @code{standout}, @code{reverse},
13225 @code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
13226
13227 @item set tui border-mode @var{mode}
13228 @kindex set tui border-mode
13229 Select the attributes to display the border of other windows.
13230 The @var{mode} can be one of the following:
13231 @table @code
13232 @item normal
13233 Use normal attributes to display the border.
13234
13235 @item standout
13236 Use standout mode.
13237
13238 @item reverse
13239 Use reverse video mode.
13240
13241 @item half
13242 Use half bright mode.
13243
13244 @item half-standout
13245 Use half bright and standout mode.
13246
13247 @item bold
13248 Use extra bright or bold mode.
13249
13250 @item bold-standout
13251 Use extra bright or bold and standout mode.
13252
13253 @end table
13254
13255 @end table
13256
13257 @node Emacs
13258 @chapter Using @value{GDBN} under @sc{gnu} Emacs
13259
13260 @cindex Emacs
13261 @cindex @sc{gnu} Emacs
13262 A special interface allows you to use @sc{gnu} Emacs to view (and
13263 edit) the source files for the program you are debugging with
13264 @value{GDBN}.
13265
13266 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
13267 executable file you want to debug as an argument. This command starts
13268 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
13269 created Emacs buffer.
13270 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
13271
13272 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
13273 things:
13274
13275 @itemize @bullet
13276 @item
13277 All ``terminal'' input and output goes through the Emacs buffer.
13278 @end itemize
13279
13280 This applies both to @value{GDBN} commands and their output, and to the input
13281 and output done by the program you are debugging.
13282
13283 This is useful because it means that you can copy the text of previous
13284 commands and input them again; you can even use parts of the output
13285 in this way.
13286
13287 All the facilities of Emacs' Shell mode are available for interacting
13288 with your program. In particular, you can send signals the usual
13289 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
13290 stop.
13291
13292 @itemize @bullet
13293 @item
13294 @value{GDBN} displays source code through Emacs.
13295 @end itemize
13296
13297 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
13298 source file for that frame and puts an arrow (@samp{=>}) at the
13299 left margin of the current line. Emacs uses a separate buffer for
13300 source display, and splits the screen to show both your @value{GDBN} session
13301 and the source.
13302
13303 Explicit @value{GDBN} @code{list} or search commands still produce output as
13304 usual, but you probably have no reason to use them from Emacs.
13305
13306 @quotation
13307 @emph{Warning:} If the directory where your program resides is not your
13308 current directory, it can be easy to confuse Emacs about the location of
13309 the source files, in which case the auxiliary display buffer does not
13310 appear to show your source. @value{GDBN} can find programs by searching your
13311 environment's @code{PATH} variable, so the @value{GDBN} input and output
13312 session proceeds normally; but Emacs does not get enough information
13313 back from @value{GDBN} to locate the source files in this situation. To
13314 avoid this problem, either start @value{GDBN} mode from the directory where
13315 your program resides, or specify an absolute file name when prompted for the
13316 @kbd{M-x gdb} argument.
13317
13318 A similar confusion can result if you use the @value{GDBN} @code{file} command to
13319 switch to debugging a program in some other location, from an existing
13320 @value{GDBN} buffer in Emacs.
13321 @end quotation
13322
13323 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
13324 you need to call @value{GDBN} by a different name (for example, if you keep
13325 several configurations around, with different names) you can set the
13326 Emacs variable @code{gdb-command-name}; for example,
13327
13328 @smallexample
13329 (setq gdb-command-name "mygdb")
13330 @end smallexample
13331
13332 @noindent
13333 (preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
13334 in your @file{.emacs} file) makes Emacs call the program named
13335 ``@code{mygdb}'' instead.
13336
13337 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
13338 addition to the standard Shell mode commands:
13339
13340 @table @kbd
13341 @item C-h m
13342 Describe the features of Emacs' @value{GDBN} Mode.
13343
13344 @item M-s
13345 Execute to another source line, like the @value{GDBN} @code{step} command; also
13346 update the display window to show the current file and location.
13347
13348 @item M-n
13349 Execute to next source line in this function, skipping all function
13350 calls, like the @value{GDBN} @code{next} command. Then update the display window
13351 to show the current file and location.
13352
13353 @item M-i
13354 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
13355 display window accordingly.
13356
13357 @item M-x gdb-nexti
13358 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
13359 display window accordingly.
13360
13361 @item C-c C-f
13362 Execute until exit from the selected stack frame, like the @value{GDBN}
13363 @code{finish} command.
13364
13365 @item M-c
13366 Continue execution of your program, like the @value{GDBN} @code{continue}
13367 command.
13368
13369 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
13370
13371 @item M-u
13372 Go up the number of frames indicated by the numeric argument
13373 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
13374 like the @value{GDBN} @code{up} command.
13375
13376 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
13377
13378 @item M-d
13379 Go down the number of frames indicated by the numeric argument, like the
13380 @value{GDBN} @code{down} command.
13381
13382 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
13383
13384 @item C-x &
13385 Read the number where the cursor is positioned, and insert it at the end
13386 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
13387 around an address that was displayed earlier, type @kbd{disassemble};
13388 then move the cursor to the address display, and pick up the
13389 argument for @code{disassemble} by typing @kbd{C-x &}.
13390
13391 You can customize this further by defining elements of the list
13392 @code{gdb-print-command}; once it is defined, you can format or
13393 otherwise process numbers picked up by @kbd{C-x &} before they are
13394 inserted. A numeric argument to @kbd{C-x &} indicates that you
13395 wish special formatting, and also acts as an index to pick an element of the
13396 list. If the list element is a string, the number to be inserted is
13397 formatted using the Emacs function @code{format}; otherwise the number
13398 is passed as an argument to the corresponding list element.
13399 @end table
13400
13401 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
13402 tells @value{GDBN} to set a breakpoint on the source line point is on.
13403
13404 If you accidentally delete the source-display buffer, an easy way to get
13405 it back is to type the command @code{f} in the @value{GDBN} buffer, to
13406 request a frame display; when you run under Emacs, this recreates
13407 the source buffer if necessary to show you the context of the current
13408 frame.
13409
13410 The source files displayed in Emacs are in ordinary Emacs buffers
13411 which are visiting the source files in the usual way. You can edit
13412 the files with these buffers if you wish; but keep in mind that @value{GDBN}
13413 communicates with Emacs in terms of line numbers. If you add or
13414 delete lines from the text, the line numbers that @value{GDBN} knows cease
13415 to correspond properly with the code.
13416
13417 @c The following dropped because Epoch is nonstandard. Reactivate
13418 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
13419 @ignore
13420 @kindex Emacs Epoch environment
13421 @kindex Epoch
13422 @kindex inspect
13423
13424 Version 18 of @sc{gnu} Emacs has a built-in window system
13425 called the @code{epoch}
13426 environment. Users of this environment can use a new command,
13427 @code{inspect} which performs identically to @code{print} except that
13428 each value is printed in its own window.
13429 @end ignore
13430
13431 @include annotate.texi
13432 @include gdbmi.texinfo
13433
13434 @node GDB Bugs
13435 @chapter Reporting Bugs in @value{GDBN}
13436 @cindex bugs in @value{GDBN}
13437 @cindex reporting bugs in @value{GDBN}
13438
13439 Your bug reports play an essential role in making @value{GDBN} reliable.
13440
13441 Reporting a bug may help you by bringing a solution to your problem, or it
13442 may not. But in any case the principal function of a bug report is to help
13443 the entire community by making the next version of @value{GDBN} work better. Bug
13444 reports are your contribution to the maintenance of @value{GDBN}.
13445
13446 In order for a bug report to serve its purpose, you must include the
13447 information that enables us to fix the bug.
13448
13449 @menu
13450 * Bug Criteria:: Have you found a bug?
13451 * Bug Reporting:: How to report bugs
13452 @end menu
13453
13454 @node Bug Criteria
13455 @section Have you found a bug?
13456 @cindex bug criteria
13457
13458 If you are not sure whether you have found a bug, here are some guidelines:
13459
13460 @itemize @bullet
13461 @cindex fatal signal
13462 @cindex debugger crash
13463 @cindex crash of debugger
13464 @item
13465 If the debugger gets a fatal signal, for any input whatever, that is a
13466 @value{GDBN} bug. Reliable debuggers never crash.
13467
13468 @cindex error on valid input
13469 @item
13470 If @value{GDBN} produces an error message for valid input, that is a
13471 bug. (Note that if you're cross debugging, the problem may also be
13472 somewhere in the connection to the target.)
13473
13474 @cindex invalid input
13475 @item
13476 If @value{GDBN} does not produce an error message for invalid input,
13477 that is a bug. However, you should note that your idea of
13478 ``invalid input'' might be our idea of ``an extension'' or ``support
13479 for traditional practice''.
13480
13481 @item
13482 If you are an experienced user of debugging tools, your suggestions
13483 for improvement of @value{GDBN} are welcome in any case.
13484 @end itemize
13485
13486 @node Bug Reporting
13487 @section How to report bugs
13488 @cindex bug reports
13489 @cindex @value{GDBN} bugs, reporting
13490
13491 A number of companies and individuals offer support for @sc{gnu} products.
13492 If you obtained @value{GDBN} from a support organization, we recommend you
13493 contact that organization first.
13494
13495 You can find contact information for many support companies and
13496 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
13497 distribution.
13498 @c should add a web page ref...
13499
13500 In any event, we also recommend that you send bug reports for
13501 @value{GDBN} to this addresses:
13502
13503 @smallexample
13504 bug-gdb@@gnu.org
13505 @end smallexample
13506
13507 @strong{Do not send bug reports to @samp{info-gdb}, or to
13508 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
13509 not want to receive bug reports. Those that do have arranged to receive
13510 @samp{bug-gdb}.
13511
13512 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
13513 serves as a repeater. The mailing list and the newsgroup carry exactly
13514 the same messages. Often people think of posting bug reports to the
13515 newsgroup instead of mailing them. This appears to work, but it has one
13516 problem which can be crucial: a newsgroup posting often lacks a mail
13517 path back to the sender. Thus, if we need to ask for more information,
13518 we may be unable to reach you. For this reason, it is better to send
13519 bug reports to the mailing list.
13520
13521 As a last resort, send bug reports on paper to:
13522
13523 @smallexample
13524 @sc{gnu} Debugger Bugs
13525 Free Software Foundation Inc.
13526 59 Temple Place - Suite 330
13527 Boston, MA 02111-1307
13528 USA
13529 @end smallexample
13530
13531 The fundamental principle of reporting bugs usefully is this:
13532 @strong{report all the facts}. If you are not sure whether to state a
13533 fact or leave it out, state it!
13534
13535 Often people omit facts because they think they know what causes the
13536 problem and assume that some details do not matter. Thus, you might
13537 assume that the name of the variable you use in an example does not matter.
13538 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
13539 stray memory reference which happens to fetch from the location where that
13540 name is stored in memory; perhaps, if the name were different, the contents
13541 of that location would fool the debugger into doing the right thing despite
13542 the bug. Play it safe and give a specific, complete example. That is the
13543 easiest thing for you to do, and the most helpful.
13544
13545 Keep in mind that the purpose of a bug report is to enable us to fix the
13546 bug. It may be that the bug has been reported previously, but neither
13547 you nor we can know that unless your bug report is complete and
13548 self-contained.
13549
13550 Sometimes people give a few sketchy facts and ask, ``Does this ring a
13551 bell?'' Those bug reports are useless, and we urge everyone to
13552 @emph{refuse to respond to them} except to chide the sender to report
13553 bugs properly.
13554
13555 To enable us to fix the bug, you should include all these things:
13556
13557 @itemize @bullet
13558 @item
13559 The version of @value{GDBN}. @value{GDBN} announces it if you start
13560 with no arguments; you can also print it at any time using @code{show
13561 version}.
13562
13563 Without this, we will not know whether there is any point in looking for
13564 the bug in the current version of @value{GDBN}.
13565
13566 @item
13567 The type of machine you are using, and the operating system name and
13568 version number.
13569
13570 @item
13571 What compiler (and its version) was used to compile @value{GDBN}---e.g.
13572 ``@value{GCC}--2.8.1''.
13573
13574 @item
13575 What compiler (and its version) was used to compile the program you are
13576 debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
13577 C Compiler''. For GCC, you can say @code{gcc --version} to get this
13578 information; for other compilers, see the documentation for those
13579 compilers.
13580
13581 @item
13582 The command arguments you gave the compiler to compile your example and
13583 observe the bug. For example, did you use @samp{-O}? To guarantee
13584 you will not omit something important, list them all. A copy of the
13585 Makefile (or the output from make) is sufficient.
13586
13587 If we were to try to guess the arguments, we would probably guess wrong
13588 and then we might not encounter the bug.
13589
13590 @item
13591 A complete input script, and all necessary source files, that will
13592 reproduce the bug.
13593
13594 @item
13595 A description of what behavior you observe that you believe is
13596 incorrect. For example, ``It gets a fatal signal.''
13597
13598 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
13599 will certainly notice it. But if the bug is incorrect output, we might
13600 not notice unless it is glaringly wrong. You might as well not give us
13601 a chance to make a mistake.
13602
13603 Even if the problem you experience is a fatal signal, you should still
13604 say so explicitly. Suppose something strange is going on, such as, your
13605 copy of @value{GDBN} is out of synch, or you have encountered a bug in
13606 the C library on your system. (This has happened!) Your copy might
13607 crash and ours would not. If you told us to expect a crash, then when
13608 ours fails to crash, we would know that the bug was not happening for
13609 us. If you had not told us to expect a crash, then we would not be able
13610 to draw any conclusion from our observations.
13611
13612 @item
13613 If you wish to suggest changes to the @value{GDBN} source, send us context
13614 diffs. If you even discuss something in the @value{GDBN} source, refer to
13615 it by context, not by line number.
13616
13617 The line numbers in our development sources will not match those in your
13618 sources. Your line numbers would convey no useful information to us.
13619
13620 @end itemize
13621
13622 Here are some things that are not necessary:
13623
13624 @itemize @bullet
13625 @item
13626 A description of the envelope of the bug.
13627
13628 Often people who encounter a bug spend a lot of time investigating
13629 which changes to the input file will make the bug go away and which
13630 changes will not affect it.
13631
13632 This is often time consuming and not very useful, because the way we
13633 will find the bug is by running a single example under the debugger
13634 with breakpoints, not by pure deduction from a series of examples.
13635 We recommend that you save your time for something else.
13636
13637 Of course, if you can find a simpler example to report @emph{instead}
13638 of the original one, that is a convenience for us. Errors in the
13639 output will be easier to spot, running under the debugger will take
13640 less time, and so on.
13641
13642 However, simplification is not vital; if you do not want to do this,
13643 report the bug anyway and send us the entire test case you used.
13644
13645 @item
13646 A patch for the bug.
13647
13648 A patch for the bug does help us if it is a good one. But do not omit
13649 the necessary information, such as the test case, on the assumption that
13650 a patch is all we need. We might see problems with your patch and decide
13651 to fix the problem another way, or we might not understand it at all.
13652
13653 Sometimes with a program as complicated as @value{GDBN} it is very hard to
13654 construct an example that will make the program follow a certain path
13655 through the code. If you do not send us the example, we will not be able
13656 to construct one, so we will not be able to verify that the bug is fixed.
13657
13658 And if we cannot understand what bug you are trying to fix, or why your
13659 patch should be an improvement, we will not install it. A test case will
13660 help us to understand.
13661
13662 @item
13663 A guess about what the bug is or what it depends on.
13664
13665 Such guesses are usually wrong. Even we cannot guess right about such
13666 things without first using the debugger to find the facts.
13667 @end itemize
13668
13669 @c The readline documentation is distributed with the readline code
13670 @c and consists of the two following files:
13671 @c rluser.texinfo
13672 @c inc-hist.texinfo
13673 @c Use -I with makeinfo to point to the appropriate directory,
13674 @c environment var TEXINPUTS with TeX.
13675 @include rluser.texinfo
13676 @include inc-hist.texinfo
13677
13678
13679 @node Formatting Documentation
13680 @appendix Formatting Documentation
13681
13682 @cindex @value{GDBN} reference card
13683 @cindex reference card
13684 The @value{GDBN} 4 release includes an already-formatted reference card, ready
13685 for printing with PostScript or Ghostscript, in the @file{gdb}
13686 subdirectory of the main source directory@footnote{In
13687 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
13688 release.}. If you can use PostScript or Ghostscript with your printer,
13689 you can print the reference card immediately with @file{refcard.ps}.
13690
13691 The release also includes the source for the reference card. You
13692 can format it, using @TeX{}, by typing:
13693
13694 @smallexample
13695 make refcard.dvi
13696 @end smallexample
13697
13698 The @value{GDBN} reference card is designed to print in @dfn{landscape}
13699 mode on US ``letter'' size paper;
13700 that is, on a sheet 11 inches wide by 8.5 inches
13701 high. You will need to specify this form of printing as an option to
13702 your @sc{dvi} output program.
13703
13704 @cindex documentation
13705
13706 All the documentation for @value{GDBN} comes as part of the machine-readable
13707 distribution. The documentation is written in Texinfo format, which is
13708 a documentation system that uses a single source file to produce both
13709 on-line information and a printed manual. You can use one of the Info
13710 formatting commands to create the on-line version of the documentation
13711 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
13712
13713 @value{GDBN} includes an already formatted copy of the on-line Info
13714 version of this manual in the @file{gdb} subdirectory. The main Info
13715 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
13716 subordinate files matching @samp{gdb.info*} in the same directory. If
13717 necessary, you can print out these files, or read them with any editor;
13718 but they are easier to read using the @code{info} subsystem in @sc{gnu}
13719 Emacs or the standalone @code{info} program, available as part of the
13720 @sc{gnu} Texinfo distribution.
13721
13722 If you want to format these Info files yourself, you need one of the
13723 Info formatting programs, such as @code{texinfo-format-buffer} or
13724 @code{makeinfo}.
13725
13726 If you have @code{makeinfo} installed, and are in the top level
13727 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
13728 version @value{GDBVN}), you can make the Info file by typing:
13729
13730 @smallexample
13731 cd gdb
13732 make gdb.info
13733 @end smallexample
13734
13735 If you want to typeset and print copies of this manual, you need @TeX{},
13736 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
13737 Texinfo definitions file.
13738
13739 @TeX{} is a typesetting program; it does not print files directly, but
13740 produces output files called @sc{dvi} files. To print a typeset
13741 document, you need a program to print @sc{dvi} files. If your system
13742 has @TeX{} installed, chances are it has such a program. The precise
13743 command to use depends on your system; @kbd{lpr -d} is common; another
13744 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
13745 require a file name without any extension or a @samp{.dvi} extension.
13746
13747 @TeX{} also requires a macro definitions file called
13748 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
13749 written in Texinfo format. On its own, @TeX{} cannot either read or
13750 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
13751 and is located in the @file{gdb-@var{version-number}/texinfo}
13752 directory.
13753
13754 If you have @TeX{} and a @sc{dvi} printer program installed, you can
13755 typeset and print this manual. First switch to the the @file{gdb}
13756 subdirectory of the main source directory (for example, to
13757 @file{gdb-@value{GDBVN}/gdb}) and type:
13758
13759 @smallexample
13760 make gdb.dvi
13761 @end smallexample
13762
13763 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
13764
13765 @node Installing GDB
13766 @appendix Installing @value{GDBN}
13767 @cindex configuring @value{GDBN}
13768 @cindex installation
13769
13770 @value{GDBN} comes with a @code{configure} script that automates the process
13771 of preparing @value{GDBN} for installation; you can then use @code{make} to
13772 build the @code{gdb} program.
13773 @iftex
13774 @c irrelevant in info file; it's as current as the code it lives with.
13775 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
13776 look at the @file{README} file in the sources; we may have improved the
13777 installation procedures since publishing this manual.}
13778 @end iftex
13779
13780 The @value{GDBN} distribution includes all the source code you need for
13781 @value{GDBN} in a single directory, whose name is usually composed by
13782 appending the version number to @samp{gdb}.
13783
13784 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
13785 @file{gdb-@value{GDBVN}} directory. That directory contains:
13786
13787 @table @code
13788 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
13789 script for configuring @value{GDBN} and all its supporting libraries
13790
13791 @item gdb-@value{GDBVN}/gdb
13792 the source specific to @value{GDBN} itself
13793
13794 @item gdb-@value{GDBVN}/bfd
13795 source for the Binary File Descriptor library
13796
13797 @item gdb-@value{GDBVN}/include
13798 @sc{gnu} include files
13799
13800 @item gdb-@value{GDBVN}/libiberty
13801 source for the @samp{-liberty} free software library
13802
13803 @item gdb-@value{GDBVN}/opcodes
13804 source for the library of opcode tables and disassemblers
13805
13806 @item gdb-@value{GDBVN}/readline
13807 source for the @sc{gnu} command-line interface
13808
13809 @item gdb-@value{GDBVN}/glob
13810 source for the @sc{gnu} filename pattern-matching subroutine
13811
13812 @item gdb-@value{GDBVN}/mmalloc
13813 source for the @sc{gnu} memory-mapped malloc package
13814 @end table
13815
13816 The simplest way to configure and build @value{GDBN} is to run @code{configure}
13817 from the @file{gdb-@var{version-number}} source directory, which in
13818 this example is the @file{gdb-@value{GDBVN}} directory.
13819
13820 First switch to the @file{gdb-@var{version-number}} source directory
13821 if you are not already in it; then run @code{configure}. Pass the
13822 identifier for the platform on which @value{GDBN} will run as an
13823 argument.
13824
13825 For example:
13826
13827 @smallexample
13828 cd gdb-@value{GDBVN}
13829 ./configure @var{host}
13830 make
13831 @end smallexample
13832
13833 @noindent
13834 where @var{host} is an identifier such as @samp{sun4} or
13835 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
13836 (You can often leave off @var{host}; @code{configure} tries to guess the
13837 correct value by examining your system.)
13838
13839 Running @samp{configure @var{host}} and then running @code{make} builds the
13840 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
13841 libraries, then @code{gdb} itself. The configured source files, and the
13842 binaries, are left in the corresponding source directories.
13843
13844 @need 750
13845 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
13846 system does not recognize this automatically when you run a different
13847 shell, you may need to run @code{sh} on it explicitly:
13848
13849 @smallexample
13850 sh configure @var{host}
13851 @end smallexample
13852
13853 If you run @code{configure} from a directory that contains source
13854 directories for multiple libraries or programs, such as the
13855 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
13856 creates configuration files for every directory level underneath (unless
13857 you tell it not to, with the @samp{--norecursion} option).
13858
13859 You can run the @code{configure} script from any of the
13860 subordinate directories in the @value{GDBN} distribution if you only want to
13861 configure that subdirectory, but be sure to specify a path to it.
13862
13863 For example, with version @value{GDBVN}, type the following to configure only
13864 the @code{bfd} subdirectory:
13865
13866 @smallexample
13867 @group
13868 cd gdb-@value{GDBVN}/bfd
13869 ../configure @var{host}
13870 @end group
13871 @end smallexample
13872
13873 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
13874 However, you should make sure that the shell on your path (named by
13875 the @samp{SHELL} environment variable) is publicly readable. Remember
13876 that @value{GDBN} uses the shell to start your program---some systems refuse to
13877 let @value{GDBN} debug child processes whose programs are not readable.
13878
13879 @menu
13880 * Separate Objdir:: Compiling @value{GDBN} in another directory
13881 * Config Names:: Specifying names for hosts and targets
13882 * Configure Options:: Summary of options for configure
13883 @end menu
13884
13885 @node Separate Objdir
13886 @section Compiling @value{GDBN} in another directory
13887
13888 If you want to run @value{GDBN} versions for several host or target machines,
13889 you need a different @code{gdb} compiled for each combination of
13890 host and target. @code{configure} is designed to make this easy by
13891 allowing you to generate each configuration in a separate subdirectory,
13892 rather than in the source directory. If your @code{make} program
13893 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
13894 @code{make} in each of these directories builds the @code{gdb}
13895 program specified there.
13896
13897 To build @code{gdb} in a separate directory, run @code{configure}
13898 with the @samp{--srcdir} option to specify where to find the source.
13899 (You also need to specify a path to find @code{configure}
13900 itself from your working directory. If the path to @code{configure}
13901 would be the same as the argument to @samp{--srcdir}, you can leave out
13902 the @samp{--srcdir} option; it is assumed.)
13903
13904 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
13905 separate directory for a Sun 4 like this:
13906
13907 @smallexample
13908 @group
13909 cd gdb-@value{GDBVN}
13910 mkdir ../gdb-sun4
13911 cd ../gdb-sun4
13912 ../gdb-@value{GDBVN}/configure sun4
13913 make
13914 @end group
13915 @end smallexample
13916
13917 When @code{configure} builds a configuration using a remote source
13918 directory, it creates a tree for the binaries with the same structure
13919 (and using the same names) as the tree under the source directory. In
13920 the example, you'd find the Sun 4 library @file{libiberty.a} in the
13921 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
13922 @file{gdb-sun4/gdb}.
13923
13924 One popular reason to build several @value{GDBN} configurations in separate
13925 directories is to configure @value{GDBN} for cross-compiling (where
13926 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
13927 programs that run on another machine---the @dfn{target}).
13928 You specify a cross-debugging target by
13929 giving the @samp{--target=@var{target}} option to @code{configure}.
13930
13931 When you run @code{make} to build a program or library, you must run
13932 it in a configured directory---whatever directory you were in when you
13933 called @code{configure} (or one of its subdirectories).
13934
13935 The @code{Makefile} that @code{configure} generates in each source
13936 directory also runs recursively. If you type @code{make} in a source
13937 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
13938 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
13939 will build all the required libraries, and then build GDB.
13940
13941 When you have multiple hosts or targets configured in separate
13942 directories, you can run @code{make} on them in parallel (for example,
13943 if they are NFS-mounted on each of the hosts); they will not interfere
13944 with each other.
13945
13946 @node Config Names
13947 @section Specifying names for hosts and targets
13948
13949 The specifications used for hosts and targets in the @code{configure}
13950 script are based on a three-part naming scheme, but some short predefined
13951 aliases are also supported. The full naming scheme encodes three pieces
13952 of information in the following pattern:
13953
13954 @smallexample
13955 @var{architecture}-@var{vendor}-@var{os}
13956 @end smallexample
13957
13958 For example, you can use the alias @code{sun4} as a @var{host} argument,
13959 or as the value for @var{target} in a @code{--target=@var{target}}
13960 option. The equivalent full name is @samp{sparc-sun-sunos4}.
13961
13962 The @code{configure} script accompanying @value{GDBN} does not provide
13963 any query facility to list all supported host and target names or
13964 aliases. @code{configure} calls the Bourne shell script
13965 @code{config.sub} to map abbreviations to full names; you can read the
13966 script, if you wish, or you can use it to test your guesses on
13967 abbreviations---for example:
13968
13969 @smallexample
13970 % sh config.sub i386-linux
13971 i386-pc-linux-gnu
13972 % sh config.sub alpha-linux
13973 alpha-unknown-linux-gnu
13974 % sh config.sub hp9k700
13975 hppa1.1-hp-hpux
13976 % sh config.sub sun4
13977 sparc-sun-sunos4.1.1
13978 % sh config.sub sun3
13979 m68k-sun-sunos4.1.1
13980 % sh config.sub i986v
13981 Invalid configuration `i986v': machine `i986v' not recognized
13982 @end smallexample
13983
13984 @noindent
13985 @code{config.sub} is also distributed in the @value{GDBN} source
13986 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
13987
13988 @node Configure Options
13989 @section @code{configure} options
13990
13991 Here is a summary of the @code{configure} options and arguments that
13992 are most often useful for building @value{GDBN}. @code{configure} also has
13993 several other options not listed here. @inforef{What Configure
13994 Does,,configure.info}, for a full explanation of @code{configure}.
13995
13996 @smallexample
13997 configure @r{[}--help@r{]}
13998 @r{[}--prefix=@var{dir}@r{]}
13999 @r{[}--exec-prefix=@var{dir}@r{]}
14000 @r{[}--srcdir=@var{dirname}@r{]}
14001 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
14002 @r{[}--target=@var{target}@r{]}
14003 @var{host}
14004 @end smallexample
14005
14006 @noindent
14007 You may introduce options with a single @samp{-} rather than
14008 @samp{--} if you prefer; but you may abbreviate option names if you use
14009 @samp{--}.
14010
14011 @table @code
14012 @item --help
14013 Display a quick summary of how to invoke @code{configure}.
14014
14015 @item --prefix=@var{dir}
14016 Configure the source to install programs and files under directory
14017 @file{@var{dir}}.
14018
14019 @item --exec-prefix=@var{dir}
14020 Configure the source to install programs under directory
14021 @file{@var{dir}}.
14022
14023 @c avoid splitting the warning from the explanation:
14024 @need 2000
14025 @item --srcdir=@var{dirname}
14026 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
14027 @code{make} that implements the @code{VPATH} feature.}@*
14028 Use this option to make configurations in directories separate from the
14029 @value{GDBN} source directories. Among other things, you can use this to
14030 build (or maintain) several configurations simultaneously, in separate
14031 directories. @code{configure} writes configuration specific files in
14032 the current directory, but arranges for them to use the source in the
14033 directory @var{dirname}. @code{configure} creates directories under
14034 the working directory in parallel to the source directories below
14035 @var{dirname}.
14036
14037 @item --norecursion
14038 Configure only the directory level where @code{configure} is executed; do not
14039 propagate configuration to subdirectories.
14040
14041 @item --target=@var{target}
14042 Configure @value{GDBN} for cross-debugging programs running on the specified
14043 @var{target}. Without this option, @value{GDBN} is configured to debug
14044 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
14045
14046 There is no convenient way to generate a list of all available targets.
14047
14048 @item @var{host} @dots{}
14049 Configure @value{GDBN} to run on the specified @var{host}.
14050
14051 There is no convenient way to generate a list of all available hosts.
14052 @end table
14053
14054 There are many other options available as well, but they are generally
14055 needed for special purposes only.
14056
14057 @node Maintenance Commands
14058 @appendix Maintenance Commands
14059 @cindex maintenance commands
14060 @cindex internal commands
14061
14062 In addition to commands intended for @value{GDBN} users, @value{GDBN}
14063 includes a number of commands intended for @value{GDBN} developers.
14064 These commands are provided here for reference.
14065
14066 @table @code
14067 @kindex maint info breakpoints
14068 @item @anchor{maint info breakpoints}maint info breakpoints
14069 Using the same format as @samp{info breakpoints}, display both the
14070 breakpoints you've set explicitly, and those @value{GDBN} is using for
14071 internal purposes. Internal breakpoints are shown with negative
14072 breakpoint numbers. The type column identifies what kind of breakpoint
14073 is shown:
14074
14075 @table @code
14076 @item breakpoint
14077 Normal, explicitly set breakpoint.
14078
14079 @item watchpoint
14080 Normal, explicitly set watchpoint.
14081
14082 @item longjmp
14083 Internal breakpoint, used to handle correctly stepping through
14084 @code{longjmp} calls.
14085
14086 @item longjmp resume
14087 Internal breakpoint at the target of a @code{longjmp}.
14088
14089 @item until
14090 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
14091
14092 @item finish
14093 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
14094
14095 @item shlib events
14096 Shared library events.
14097
14098 @end table
14099
14100 @end table
14101
14102
14103 @node Remote Protocol
14104 @appendix @value{GDBN} Remote Serial Protocol
14105
14106 There may be occasions when you need to know something about the
14107 protocol---for example, if there is only one serial port to your target
14108 machine, you might want your program to do something special if it
14109 recognizes a packet meant for @value{GDBN}.
14110
14111 In the examples below, @samp{<-} and @samp{->} are used to indicate
14112 transmitted and received data respectfully.
14113
14114 @cindex protocol, @value{GDBN} remote serial
14115 @cindex serial protocol, @value{GDBN} remote
14116 @cindex remote serial protocol
14117 All @value{GDBN} commands and responses (other than acknowledgments) are
14118 sent as a @var{packet}. A @var{packet} is introduced with the character
14119 @samp{$}, the actual @var{packet-data}, and the terminating character
14120 @samp{#} followed by a two-digit @var{checksum}:
14121
14122 @smallexample
14123 @code{$}@var{packet-data}@code{#}@var{checksum}
14124 @end smallexample
14125 @noindent
14126
14127 @cindex checksum, for @value{GDBN} remote
14128 @noindent
14129 The two-digit @var{checksum} is computed as the modulo 256 sum of all
14130 characters between the leading @samp{$} and the trailing @samp{#} (an
14131 eight bit unsigned checksum).
14132
14133 Implementors should note that prior to @value{GDBN} 5.0 the protocol
14134 specification also included an optional two-digit @var{sequence-id}:
14135
14136 @smallexample
14137 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
14138 @end smallexample
14139
14140 @cindex sequence-id, for @value{GDBN} remote
14141 @noindent
14142 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
14143 has never output @var{sequence-id}s. Stubs that handle packets added
14144 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
14145
14146 @cindex acknowledgment, for @value{GDBN} remote
14147 When either the host or the target machine receives a packet, the first
14148 response expected is an acknowledgment: either @samp{+} (to indicate
14149 the package was received correctly) or @samp{-} (to request
14150 retransmission):
14151
14152 @smallexample
14153 <- @code{$}@var{packet-data}@code{#}@var{checksum}
14154 -> @code{+}
14155 @end smallexample
14156 @noindent
14157
14158 The host (@value{GDBN}) sends @var{command}s, and the target (the
14159 debugging stub incorporated in your program) sends a @var{response}. In
14160 the case of step and continue @var{command}s, the response is only sent
14161 when the operation has completed (the target has again stopped).
14162
14163 @var{packet-data} consists of a sequence of characters with the
14164 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
14165 exceptions).
14166
14167 Fields within the packet should be separated using @samp{,} @samp{;} or
14168 @samp{:}. Except where otherwise noted all numbers are represented in
14169 HEX with leading zeros suppressed.
14170
14171 Implementors should note that prior to @value{GDBN} 5.0, the character
14172 @samp{:} could not appear as the third character in a packet (as it
14173 would potentially conflict with the @var{sequence-id}).
14174
14175 Response @var{data} can be run-length encoded to save space. A @samp{*}
14176 means that the next character is an @sc{ascii} encoding giving a repeat count
14177 which stands for that many repetitions of the character preceding the
14178 @samp{*}. The encoding is @code{n+29}, yielding a printable character
14179 where @code{n >=3} (which is where rle starts to win). The printable
14180 characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
14181 value greater than 126 should not be used.
14182
14183 Some remote systems have used a different run-length encoding mechanism
14184 loosely refered to as the cisco encoding. Following the @samp{*}
14185 character are two hex digits that indicate the size of the packet.
14186
14187 So:
14188 @smallexample
14189 "@code{0* }"
14190 @end smallexample
14191 @noindent
14192 means the same as "0000".
14193
14194 The error response returned for some packets includes a two character
14195 error number. That number is not well defined.
14196
14197 For any @var{command} not supported by the stub, an empty response
14198 (@samp{$#00}) should be returned. That way it is possible to extend the
14199 protocol. A newer @value{GDBN} can tell if a packet is supported based
14200 on that response.
14201
14202 A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
14203 @samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
14204 optional.
14205
14206 Below is a complete list of all currently defined @var{command}s and
14207 their corresponding response @var{data}:
14208 @page
14209 @multitable @columnfractions .30 .30 .40
14210 @item Packet
14211 @tab Request
14212 @tab Description
14213
14214 @item extended mode
14215 @tab @code{!}
14216 @tab
14217 Enable extended mode. In extended mode, the remote server is made
14218 persistent. The @samp{R} packet is used to restart the program being
14219 debugged.
14220 @item
14221 @tab reply @samp{OK}
14222 @tab
14223 The remote target both supports and has enabled extended mode.
14224
14225 @item last signal
14226 @tab @code{?}
14227 @tab
14228 Indicate the reason the target halted. The reply is the same as for step
14229 and continue.
14230 @item
14231 @tab reply
14232 @tab see below
14233
14234
14235 @item reserved
14236 @tab @code{a}
14237 @tab Reserved for future use
14238
14239 @item set program arguments @strong{(reserved)}
14240 @tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
14241 @tab
14242 @item
14243 @tab
14244 @tab
14245 Initialized @samp{argv[]} array passed into program. @var{arglen}
14246 specifies the number of bytes in the hex encoded byte stream @var{arg}.
14247 See @file{gdbserver} for more details.
14248 @item
14249 @tab reply @code{OK}
14250 @item
14251 @tab reply @code{E}@var{NN}
14252
14253 @item set baud @strong{(deprecated)}
14254 @tab @code{b}@var{baud}
14255 @tab
14256 Change the serial line speed to @var{baud}. JTC: @emph{When does the
14257 transport layer state change? When it's received, or after the ACK is
14258 transmitted. In either case, there are problems if the command or the
14259 acknowledgment packet is dropped.} Stan: @emph{If people really wanted
14260 to add something like this, and get it working for the first time, they
14261 ought to modify ser-unix.c to send some kind of out-of-band message to a
14262 specially-setup stub and have the switch happen "in between" packets, so
14263 that from remote protocol's point of view, nothing actually
14264 happened.}
14265
14266 @item set breakpoint @strong{(deprecated)}
14267 @tab @code{B}@var{addr},@var{mode}
14268 @tab
14269 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
14270 breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
14271 @samp{z} packets.}
14272
14273 @item continue
14274 @tab @code{c}@var{addr}
14275 @tab
14276 @var{addr} is address to resume. If @var{addr} is omitted, resume at
14277 current address.
14278 @item
14279 @tab reply
14280 @tab see below
14281
14282 @item continue with signal
14283 @tab @code{C}@var{sig}@code{;}@var{addr}
14284 @tab
14285 Continue with signal @var{sig} (hex signal number). If
14286 @code{;}@var{addr} is omitted, resume at same address.
14287 @item
14288 @tab reply
14289 @tab see below
14290
14291 @item toggle debug @strong{(deprecated)}
14292 @tab @code{d}
14293 @tab
14294 toggle debug flag.
14295
14296 @item detach
14297 @tab @code{D}
14298 @tab
14299 Detach @value{GDBN} from the remote system. Sent to the remote target before
14300 @value{GDBN} disconnects.
14301 @item
14302 @tab reply @emph{no response}
14303 @tab
14304 @value{GDBN} does not check for any response after sending this packet.
14305
14306 @item reserved
14307 @tab @code{e}
14308 @tab Reserved for future use
14309
14310 @item reserved
14311 @tab @code{E}
14312 @tab Reserved for future use
14313
14314 @item reserved
14315 @tab @code{f}
14316 @tab Reserved for future use
14317
14318 @item reserved
14319 @tab @code{F}
14320 @tab Reserved for future use
14321
14322 @item read registers
14323 @tab @code{g}
14324 @tab Read general registers.
14325 @item
14326 @tab reply @var{XX...}
14327 @tab
14328 Each byte of register data is described by two hex digits. The bytes
14329 with the register are transmitted in target byte order. The size of
14330 each register and their position within the @samp{g} @var{packet} are
14331 determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
14332 @var{REGISTER_NAME} macros. The specification of several standard
14333 @code{g} packets is specified below.
14334 @item
14335 @tab @code{E}@var{NN}
14336 @tab for an error.
14337
14338 @item write regs
14339 @tab @code{G}@var{XX...}
14340 @tab
14341 See @samp{g} for a description of the @var{XX...} data.
14342 @item
14343 @tab reply @code{OK}
14344 @tab for success
14345 @item
14346 @tab reply @code{E}@var{NN}
14347 @tab for an error
14348
14349 @item reserved
14350 @tab @code{h}
14351 @tab Reserved for future use
14352
14353 @item set thread
14354 @tab @code{H}@var{c}@var{t...}
14355 @tab
14356 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
14357 @samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
14358 continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
14359 thread used in other operations. If zero, pick a thread, any thread.
14360 @item
14361 @tab reply @code{OK}
14362 @tab for success
14363 @item
14364 @tab reply @code{E}@var{NN}
14365 @tab for an error
14366
14367 @c FIXME: JTC:
14368 @c 'H': How restrictive (or permissive) is the thread model. If a
14369 @c thread is selected and stopped, are other threads allowed
14370 @c to continue to execute? As I mentioned above, I think the
14371 @c semantics of each command when a thread is selected must be
14372 @c described. For example:
14373 @c
14374 @c 'g': If the stub supports threads and a specific thread is
14375 @c selected, returns the register block from that thread;
14376 @c otherwise returns current registers.
14377 @c
14378 @c 'G' If the stub supports threads and a specific thread is
14379 @c selected, sets the registers of the register block of
14380 @c that thread; otherwise sets current registers.
14381
14382 @item cycle step @strong{(draft)}
14383 @tab @code{i}@var{addr}@code{,}@var{nnn}
14384 @tab
14385 Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
14386 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
14387 step starting at that address.
14388
14389 @item signal then cycle step @strong{(reserved)}
14390 @tab @code{I}
14391 @tab
14392 See @samp{i} and @samp{S} for likely syntax and semantics.
14393
14394 @item reserved
14395 @tab @code{j}
14396 @tab Reserved for future use
14397
14398 @item reserved
14399 @tab @code{J}
14400 @tab Reserved for future use
14401
14402 @item kill request
14403 @tab @code{k}
14404 @tab
14405 FIXME: @emph{There is no description of how to operate when a specific
14406 thread context has been selected (i.e.@: does 'k' kill only that thread?)}.
14407
14408 @item reserved
14409 @tab @code{l}
14410 @tab Reserved for future use
14411
14412 @item reserved
14413 @tab @code{L}
14414 @tab Reserved for future use
14415
14416 @item read memory
14417 @tab @code{m}@var{addr}@code{,}@var{length}
14418 @tab
14419 Read @var{length} bytes of memory starting at address @var{addr}.
14420 Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
14421 using word alligned accesses. FIXME: @emph{A word aligned memory
14422 transfer mechanism is needed.}
14423 @item
14424 @tab reply @var{XX...}
14425 @tab
14426 @var{XX...} is mem contents. Can be fewer bytes than requested if able
14427 to read only part of the data. Neither @value{GDBN} nor the stub assume that
14428 sized memory transfers are assumed using word alligned accesses. FIXME:
14429 @emph{A word aligned memory transfer mechanism is needed.}
14430 @item
14431 @tab reply @code{E}@var{NN}
14432 @tab @var{NN} is errno
14433
14434 @item write mem
14435 @tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
14436 @tab
14437 Write @var{length} bytes of memory starting at address @var{addr}.
14438 @var{XX...} is the data.
14439 @item
14440 @tab reply @code{OK}
14441 @tab for success
14442 @item
14443 @tab reply @code{E}@var{NN}
14444 @tab
14445 for an error (this includes the case where only part of the data was
14446 written).
14447
14448 @item reserved
14449 @tab @code{n}
14450 @tab Reserved for future use
14451
14452 @item reserved
14453 @tab @code{N}
14454 @tab Reserved for future use
14455
14456 @item reserved
14457 @tab @code{o}
14458 @tab Reserved for future use
14459
14460 @item reserved
14461 @tab @code{O}
14462 @tab Reserved for future use
14463
14464 @item read reg @strong{(reserved)}
14465 @tab @code{p}@var{n...}
14466 @tab
14467 See write register.
14468 @item
14469 @tab return @var{r....}
14470 @tab The hex encoded value of the register in target byte order.
14471
14472 @item write reg
14473 @tab @code{P}@var{n...}@code{=}@var{r...}
14474 @tab
14475 Write register @var{n...} with value @var{r...}, which contains two hex
14476 digits for each byte in the register (target byte order).
14477 @item
14478 @tab reply @code{OK}
14479 @tab for success
14480 @item
14481 @tab reply @code{E}@var{NN}
14482 @tab for an error
14483
14484 @item general query
14485 @tab @code{q}@var{query}
14486 @tab
14487 Request info about @var{query}. In general @value{GDBN} queries
14488 have a leading upper case letter. Custom vendor queries should use a
14489 company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
14490 optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
14491 must ensure that they match the full @var{query} name.
14492 @item
14493 @tab reply @code{XX...}
14494 @tab Hex encoded data from query. The reply can not be empty.
14495 @item
14496 @tab reply @code{E}@var{NN}
14497 @tab error reply
14498 @item
14499 @tab reply @samp{}
14500 @tab Indicating an unrecognized @var{query}.
14501
14502 @item general set
14503 @tab @code{Q}@var{var}@code{=}@var{val}
14504 @tab
14505 Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
14506 naming conventions.
14507
14508 @item reset @strong{(deprecated)}
14509 @tab @code{r}
14510 @tab
14511 Reset the entire system.
14512
14513 @item remote restart
14514 @tab @code{R}@var{XX}
14515 @tab
14516 Restart the program being debugged. @var{XX}, while needed, is ignored.
14517 This packet is only available in extended mode.
14518 @item
14519 @tab
14520 no reply
14521 @tab
14522 The @samp{R} packet has no reply.
14523
14524 @item step
14525 @tab @code{s}@var{addr}
14526 @tab
14527 @var{addr} is address to resume. If @var{addr} is omitted, resume at
14528 same address.
14529 @item
14530 @tab reply
14531 @tab see below
14532
14533 @item step with signal
14534 @tab @code{S}@var{sig}@code{;}@var{addr}
14535 @tab
14536 Like @samp{C} but step not continue.
14537 @item
14538 @tab reply
14539 @tab see below
14540
14541 @item search
14542 @tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
14543 @tab
14544 Search backwards starting at address @var{addr} for a match with pattern
14545 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
14546 bytes. @var{addr} must be at least 3 digits.
14547
14548 @item thread alive
14549 @tab @code{T}@var{XX}
14550 @tab Find out if the thread XX is alive.
14551 @item
14552 @tab reply @code{OK}
14553 @tab thread is still alive
14554 @item
14555 @tab reply @code{E}@var{NN}
14556 @tab thread is dead
14557
14558 @item reserved
14559 @tab @code{u}
14560 @tab Reserved for future use
14561
14562 @item reserved
14563 @tab @code{U}
14564 @tab Reserved for future use
14565
14566 @item reserved
14567 @tab @code{v}
14568 @tab Reserved for future use
14569
14570 @item reserved
14571 @tab @code{V}
14572 @tab Reserved for future use
14573
14574 @item reserved
14575 @tab @code{w}
14576 @tab Reserved for future use
14577
14578 @item reserved
14579 @tab @code{W}
14580 @tab Reserved for future use
14581
14582 @item reserved
14583 @tab @code{x}
14584 @tab Reserved for future use
14585
14586 @item write mem (binary)
14587 @tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
14588 @tab
14589 @var{addr} is address, @var{length} is number of bytes, @var{XX...} is
14590 binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
14591 escaped using @code{0x7d}.
14592 @item
14593 @tab reply @code{OK}
14594 @tab for success
14595 @item
14596 @tab reply @code{E}@var{NN}
14597 @tab for an error
14598
14599 @item reserved
14600 @tab @code{y}
14601 @tab Reserved for future use
14602
14603 @item reserved
14604 @tab @code{Y}
14605 @tab Reserved for future use
14606
14607 @item remove break or watchpoint @strong{(draft)}
14608 @tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
14609 @tab
14610 See @samp{Z}.
14611
14612 @item insert break or watchpoint @strong{(draft)}
14613 @tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
14614 @tab
14615 @var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
14616 breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
14617 @samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
14618 bytes. For a software breakpoint, @var{length} specifies the size of
14619 the instruction to be patched. For hardware breakpoints and watchpoints
14620 @var{length} specifies the memory region to be monitored. To avoid
14621 potential problems with duplicate packets, the operations should be
14622 implemented in an idempotent way.
14623 @item
14624 @tab reply @code{E}@var{NN}
14625 @tab for an error
14626 @item
14627 @tab reply @code{OK}
14628 @tab for success
14629 @item
14630 @tab @samp{}
14631 @tab If not supported.
14632
14633 @item reserved
14634 @tab <other>
14635 @tab Reserved for future use
14636
14637 @end multitable
14638
14639 The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
14640 receive any of the below as a reply. In the case of the @samp{C},
14641 @samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
14642 when the target halts. In the below the exact meaning of @samp{signal
14643 number} is poorly defined. In general one of the UNIX signal numbering
14644 conventions is used.
14645
14646 @multitable @columnfractions .4 .6
14647
14648 @item @code{S}@var{AA}
14649 @tab @var{AA} is the signal number
14650
14651 @item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
14652 @tab
14653 @var{AA} = two hex digit signal number; @var{n...} = register number
14654 (hex), @var{r...} = target byte ordered register contents, size defined
14655 by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
14656 thread process ID, this is a hex integer; @var{n...} = other string not
14657 starting with valid hex digit. @value{GDBN} should ignore this
14658 @var{n...}, @var{r...} pair and go on to the next. This way we can
14659 extend the protocol.
14660
14661 @item @code{W}@var{AA}
14662 @tab
14663 The process exited, and @var{AA} is the exit status. This is only
14664 applicable for certains sorts of targets.
14665
14666 @item @code{X}@var{AA}
14667 @tab
14668 The process terminated with signal @var{AA}.
14669
14670 @item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
14671 @tab
14672 @var{AA} = signal number; @var{t...} = address of symbol "_start";
14673 @var{d...} = base of data section; @var{b...} = base of bss section.
14674 @emph{Note: only used by Cisco Systems targets. The difference between
14675 this reply and the "qOffsets" query is that the 'N' packet may arrive
14676 spontaneously whereas the 'qOffsets' is a query initiated by the host
14677 debugger.}
14678
14679 @item @code{O}@var{XX...}
14680 @tab
14681 @var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
14682 while the program is running and the debugger should continue to wait
14683 for 'W', 'T', etc.
14684
14685 @end multitable
14686
14687 The following set and query packets have already been defined.
14688
14689 @multitable @columnfractions .2 .2 .6
14690
14691 @item current thread
14692 @tab @code{q}@code{C}
14693 @tab Return the current thread id.
14694 @item
14695 @tab reply @code{QC}@var{pid}
14696 @tab
14697 Where @var{pid} is a HEX encoded 16 bit process id.
14698 @item
14699 @tab reply *
14700 @tab Any other reply implies the old pid.
14701
14702 @item all thread ids
14703 @tab @code{q}@code{fThreadInfo}
14704 @item
14705 @tab @code{q}@code{sThreadInfo}
14706 @tab
14707 Obtain a list of active thread ids from the target (OS). Since there
14708 may be too many active threads to fit into one reply packet, this query
14709 works iteratively: it may require more than one query/reply sequence to
14710 obtain the entire list of threads. The first query of the sequence will
14711 be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
14712 sequence will be the @code{qs}@code{ThreadInfo} query.
14713 @item
14714 @tab
14715 @tab NOTE: replaces the @code{qL} query (see below).
14716 @item
14717 @tab reply @code{m}@var{<id>}
14718 @tab A single thread id
14719 @item
14720 @tab reply @code{m}@var{<id>},@var{<id>...}
14721 @tab a comma-separated list of thread ids
14722 @item
14723 @tab reply @code{l}
14724 @tab (lower case 'el') denotes end of list.
14725 @item
14726 @tab
14727 @tab
14728 In response to each query, the target will reply with a list of one
14729 or more thread ids, in big-endian hex, separated by commas. GDB will
14730 respond to each reply with a request for more thread ids (using the
14731 @code{qs} form of the query), until the target responds with @code{l}
14732 (lower-case el, for @code{'last'}).
14733
14734 @item extra thread info
14735 @tab @code{q}@code{ThreadExtraInfo}@code{,}@var{id}
14736 @tab
14737 @item
14738 @tab
14739 @tab
14740 Where @var{<id>} is a thread-id in big-endian hex.
14741 Obtain a printable string description of a thread's attributes from
14742 the target OS. This string may contain anything that the target OS
14743 thinks is interesting for @value{GDBN} to tell the user about the thread.
14744 The string is displayed in @value{GDBN}'s @samp{info threads} display.
14745 Some examples of possible thread extra info strings are "Runnable", or
14746 "Blocked on Mutex".
14747 @item
14748 @tab reply @var{XX...}
14749 @tab
14750 Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
14751 printable string containing the extra information about the thread's
14752 attributes.
14753
14754 @item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
14755 @tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
14756 @tab
14757 @item
14758 @tab
14759 @tab
14760 Obtain thread information from RTOS. Where: @var{startflag} (one hex
14761 digit) is one to indicate the first query and zero to indicate a
14762 subsequent query; @var{threadcount} (two hex digits) is the maximum
14763 number of threads the response packet can contain; and @var{nextthread}
14764 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
14765 returned in the response as @var{argthread}.
14766 @item
14767 @tab
14768 @tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
14769 query (see above).
14770 @item
14771 @tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
14772 @tab
14773 @item
14774 @tab
14775 @tab
14776 Where: @var{count} (two hex digits) is the number of threads being
14777 returned; @var{done} (one hex digit) is zero to indicate more threads
14778 and one indicates no further threads; @var{argthreadid} (eight hex
14779 digits) is @var{nextthread} from the request packet; @var{thread...} is
14780 a sequence of thread IDs from the target. @var{threadid} (eight hex
14781 digits). See @code{remote.c:parse_threadlist_response()}.
14782
14783 @item compute CRC of memory block
14784 @tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
14785 @tab
14786 @item
14787 @tab reply @code{E}@var{NN}
14788 @tab An error (such as memory fault)
14789 @item
14790 @tab reply @code{C}@var{CRC32}
14791 @tab A 32 bit cyclic redundancy check of the specified memory region.
14792
14793 @item query sect offs
14794 @tab @code{q}@code{Offsets}
14795 @tab
14796 Get section offsets that the target used when re-locating the downloaded
14797 image. @emph{Note: while a @code{Bss} offset is included in the
14798 response, @value{GDBN} ignores this and instead applies the @code{Data}
14799 offset to the @code{Bss} section.}
14800 @item
14801 @tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
14802
14803 @item thread info request
14804 @tab @code{q}@code{P}@var{mode}@var{threadid}
14805 @tab
14806 @item
14807 @tab
14808 @tab
14809 Returns information on @var{threadid}. Where: @var{mode} is a hex
14810 encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
14811 @item
14812 @tab reply *
14813 @tab
14814 See @code{remote.c:remote_unpack_thread_info_response()}.
14815
14816 @item remote command
14817 @tab @code{q}@code{Rcmd,}@var{COMMAND}
14818 @tab
14819 @item
14820 @tab
14821 @tab
14822 @var{COMMAND} (hex encoded) is passed to the local interpreter for
14823 execution. Invalid commands should be reported using the output string.
14824 Before the final result packet, the target may also respond with a
14825 number of intermediate @code{O}@var{OUTPUT} console output
14826 packets. @emph{Implementors should note that providing access to a
14827 stubs's interpreter may have security implications}.
14828 @item
14829 @tab reply @code{OK}
14830 @tab
14831 A command response with no output.
14832 @item
14833 @tab reply @var{OUTPUT}
14834 @tab
14835 A command response with the hex encoded output string @var{OUTPUT}.
14836 @item
14837 @tab reply @code{E}@var{NN}
14838 @tab
14839 Indicate a badly formed request.
14840
14841 @item
14842 @tab reply @samp{}
14843 @tab
14844 When @samp{q}@samp{Rcmd} is not recognized.
14845
14846 @item symbol lookup
14847 @tab @code{qSymbol::}
14848 @tab
14849 Notify the target that @value{GDBN} is prepared to serve symbol lookup
14850 requests. Accept requests from the target for the values of symbols.
14851 @item
14852 @tab
14853 @tab
14854 @item
14855 @tab reply @code{OK}
14856 @tab
14857 The target does not need to look up any (more) symbols.
14858 @item
14859 @tab reply @code{qSymbol:}@var{sym_name}
14860 @tab
14861 @sp 2
14862 @noindent
14863 The target requests the value of symbol @var{sym_name} (hex encoded).
14864 @value{GDBN} may provide the value by using the
14865 @code{qSymbol:}@var{sym_value}:@var{sym_name}
14866 message, described below.
14867
14868 @item symbol value
14869 @tab @code{qSymbol:}@var{sym_value}:@var{sym_name}
14870 @tab
14871 @sp 1
14872 @noindent
14873 Set the value of SYM_NAME to SYM_VALUE.
14874 @item
14875 @tab
14876 @tab
14877 @var{sym_name} (hex encoded) is the name of a symbol whose value
14878 the target has previously requested.
14879 @item
14880 @tab
14881 @tab
14882 @var{sym_value} (hex) is the value for symbol @var{sym_name}.
14883 If @value{GDBN} cannot supply a value for @var{sym_name}, then this
14884 field will be empty.
14885 @item
14886 @tab reply @code{OK}
14887 @tab
14888 The target does not need to look up any (more) symbols.
14889 @item
14890 @tab reply @code{qSymbol:}@var{sym_name}
14891 @tab
14892 @sp 2
14893 @noindent
14894 The target requests the value of a new symbol @var{sym_name} (hex encoded).
14895 @value{GDBN} will continue to supply the values of symbols (if available),
14896 until the target ceases to request them.
14897
14898 @end multitable
14899
14900 The following @samp{g}/@samp{G} packets have previously been defined.
14901 In the below, some thirty-two bit registers are transferred as sixty-four
14902 bits. Those registers should be zero/sign extended (which?) to fill the
14903 space allocated. Register bytes are transfered in target byte order.
14904 The two nibbles within a register byte are transfered most-significant -
14905 least-significant.
14906
14907 @multitable @columnfractions .5 .5
14908
14909 @item MIPS32
14910 @tab
14911 All registers are transfered as thirty-two bit quantities in the order:
14912 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
14913 registers; fsr; fir; fp.
14914
14915 @item MIPS64
14916 @tab
14917 All registers are transfered as sixty-four bit quantities (including
14918 thirty-two bit registers such as @code{sr}). The ordering is the same
14919 as @code{MIPS32}.
14920
14921 @end multitable
14922
14923 Example sequence of a target being re-started. Notice how the restart
14924 does not get any direct output:
14925
14926 @smallexample
14927 <- @code{R00}
14928 -> @code{+}
14929 @emph{target restarts}
14930 <- @code{?}
14931 -> @code{+}
14932 -> @code{T001:1234123412341234}
14933 <- @code{+}
14934 @end smallexample
14935
14936 Example sequence of a target being stepped by a single instruction:
14937
14938 @smallexample
14939 <- @code{G1445...}
14940 -> @code{+}
14941 <- @code{s}
14942 -> @code{+}
14943 @emph{time passes}
14944 -> @code{T001:1234123412341234}
14945 <- @code{+}
14946 <- @code{g}
14947 -> @code{+}
14948 -> @code{1455...}
14949 <- @code{+}
14950 @end smallexample
14951
14952 @include gpl.texi
14953
14954 @include fdl.texi
14955
14956 @node Index
14957 @unnumbered Index
14958
14959 @printindex cp
14960
14961 @tex
14962 % I think something like @colophon should be in texinfo. In the
14963 % meantime:
14964 \long\def\colophon{\hbox to0pt{}\vfill
14965 \centerline{The body of this manual is set in}
14966 \centerline{\fontname\tenrm,}
14967 \centerline{with headings in {\bf\fontname\tenbf}}
14968 \centerline{and examples in {\tt\fontname\tentt}.}
14969 \centerline{{\it\fontname\tenit\/},}
14970 \centerline{{\bf\fontname\tenbf}, and}
14971 \centerline{{\sl\fontname\tensl\/}}
14972 \centerline{are used for emphasis.}\vfill}
14973 \page\colophon
14974 % Blame: doc@cygnus.com, 1991.
14975 @end tex
14976
14977 @bye
This page took 0.418392 seconds and 5 git commands to generate.