b8630cc2e1e9feafcf088b0d980229b997291781
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright 1988-2000
3 @c Free Software Foundation, Inc.
4 @c
5 @c %**start of header
6 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
7 @c of @set vars. However, you can override filename with makeinfo -o.
8 @setfilename gdb.info
9 @c
10 @include gdb-cfg.texi
11 @c
12 @settitle Debugging with @value{GDBN}
13 @setchapternewpage odd
14 @c %**end of header
15
16 @iftex
17 @c @smallbook
18 @c @cropmarks
19 @end iftex
20
21 @finalout
22 @syncodeindex ky cp
23
24 @c readline appendices use @vindex, @findex and @ftable,
25 @c annotate.texi and gdbmi use @findex.
26 @syncodeindex vr cp
27 @syncodeindex fn cp
28
29 @c !!set GDB manual's edition---not the same as GDB version!
30 @set EDITION Eighth
31
32 @c !!set GDB manual's revision date
33 @set DATE March 2000
34
35 @c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
36
37 @c This is a dir.info fragment to support semi-automated addition of
38 @c manuals to an info tree.
39 @dircategory Programming & development tools.
40 @direntry
41 * Gdb: (gdb). The @sc{gnu} debugger.
42 @end direntry
43
44 @ifinfo
45 This file documents the @sc{gnu} debugger @value{GDBN}.
46
47
48 This is the @value{EDITION} Edition, @value{DATE},
49 of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
50 for @value{GDBN} Version @value{GDBVN}.
51
52 Copyright (C) 1988-2000 Free Software Foundation, Inc.
53
54 Permission is granted to make and distribute verbatim copies of
55 this manual provided the copyright notice and this permission notice
56 are preserved on all copies.
57
58 @ignore
59 Permission is granted to process this file through TeX and print the
60 results, provided the printed document carries copying permission
61 notice identical to this one except for the removal of this paragraph
62 (this paragraph not being relevant to the printed manual).
63
64 @end ignore
65 Permission is granted to copy and distribute modified versions of this
66 manual under the conditions for verbatim copying, provided also that the
67 entire resulting derived work is distributed under the terms of a
68 permission notice identical to this one.
69
70 Permission is granted to copy and distribute translations of this manual
71 into another language, under the above conditions for modified versions.
72 @end ifinfo
73
74 @titlepage
75 @title Debugging with @value{GDBN}
76 @subtitle The @sc{gnu} Source-Level Debugger
77 @sp 1
78 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
79 @subtitle @value{DATE}
80 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
81 @page
82 @tex
83 {\parskip=0pt
84 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
85 \hfill {\it Debugging with @value{GDBN}}\par
86 \hfill \TeX{}info \texinfoversion\par
87 }
88 @end tex
89
90 @vskip 0pt plus 1filll
91 Copyright @copyright{} 1988-2000 Free Software Foundation, Inc.
92 @sp 2
93 Published by the Free Software Foundation @*
94 59 Temple Place - Suite 330, @*
95 Boston, MA 02111-1307 USA @*
96 ISBN 1-882114-77-9 @*
97
98 Permission is granted to make and distribute verbatim copies of
99 this manual provided the copyright notice and this permission notice
100 are preserved on all copies.
101
102 Permission is granted to copy and distribute modified versions of this
103 manual under the conditions for verbatim copying, provided also that the
104 entire resulting derived work is distributed under the terms of a
105 permission notice identical to this one.
106
107 Permission is granted to copy and distribute translations of this manual
108 into another language, under the above conditions for modified versions.
109 @end titlepage
110 @page
111
112 @ifinfo
113 @node Top, Summary, (dir), (dir)
114
115 @top Debugging with @value{GDBN}
116
117 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
118
119 This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
120 @value{GDBVN}.
121
122 Copyright (C) 1988-2000 Free Software Foundation, Inc.
123
124 @menu
125 * Summary:: Summary of @value{GDBN}
126 * Sample Session:: A sample @value{GDBN} session
127
128 * Invocation:: Getting in and out of @value{GDBN}
129 * Commands:: @value{GDBN} commands
130 * Running:: Running programs under @value{GDBN}
131 * Stopping:: Stopping and continuing
132 * Stack:: Examining the stack
133 * Source:: Examining source files
134 * Data:: Examining data
135
136 * Languages:: Using @value{GDBN} with different languages
137
138 * Symbols:: Examining the symbol table
139 * Altering:: Altering execution
140 * GDB Files:: @value{GDBN} files
141 * Targets:: Specifying a debugging target
142 * Configurations:: Configuration-specific information
143 * Controlling GDB:: Controlling @value{GDBN}
144 * Sequences:: Canned sequences of commands
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 * Index:: Index
156 @end menu
157
158 @end ifinfo
159
160 @c the replication sucks, but this avoids a texinfo 3.12 lameness
161
162 @ifhtml
163 @node Top
164
165 @top Debugging with @value{GDBN}
166
167 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
168
169 This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
170 @value{GDBVN}.
171
172 Copyright (C) 1988-2000 Free Software Foundation, Inc.
173
174 @menu
175 * Summary:: Summary of @value{GDBN}
176 * Sample Session:: A sample @value{GDBN} session
177
178 * Invocation:: Getting in and out of @value{GDBN}
179 * Commands:: @value{GDBN} commands
180 * Running:: Running programs under @value{GDBN}
181 * Stopping:: Stopping and continuing
182 * Stack:: Examining the stack
183 * Source:: Examining source files
184 * Data:: Examining data
185
186 * Languages:: Using @value{GDBN} with different languages
187
188 * Symbols:: Examining the symbol table
189 * Altering:: Altering execution
190 * GDB Files:: @value{GDBN} files
191 * Targets:: Specifying a debugging target
192 * Configurations:: Configuration-specific information
193 * Controlling GDB:: Controlling @value{GDBN}
194 * Sequences:: Canned sequences of commands
195 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
196 * Annotations:: @value{GDBN}'s annotation interface.
197
198 * GDB Bugs:: Reporting bugs in @value{GDBN}
199 * Formatting Documentation:: How to format and print @value{GDBN} documentation
200
201 * Command Line Editing:: Command Line Editing
202 * Using History Interactively:: Using History Interactively
203 * Installing GDB:: Installing GDB
204 * Index:: Index
205 @end menu
206
207 @end ifhtml
208
209 @node Summary
210 @unnumbered Summary of @value{GDBN}
211
212 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
213 going on ``inside'' another program while it executes---or what another
214 program was doing at the moment it crashed.
215
216 @value{GDBN} can do four main kinds of things (plus other things in support of
217 these) to help you catch bugs in the act:
218
219 @itemize @bullet
220 @item
221 Start your program, specifying anything that might affect its behavior.
222
223 @item
224 Make your program stop on specified conditions.
225
226 @item
227 Examine what has happened, when your program has stopped.
228
229 @item
230 Change things in your program, so you can experiment with correcting the
231 effects of one bug and go on to learn about another.
232 @end itemize
233
234 You can use @value{GDBN} to debug programs written in C and C++.
235 For more information, see @ref{Support,,Supported languages}.
236 For more information, see @ref{C,,C and C++}.
237
238 @cindex Chill
239 @cindex Modula-2
240 Support for Modula-2 and Chill is partial. For information on Modula-2,
241 see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
242
243 @cindex Pascal
244 Debugging Pascal programs which use sets, subranges, file variables, or
245 nested functions does not currently work. @value{GDBN} does not support
246 entering expressions, printing values, or similar features using Pascal
247 syntax.
248
249 @cindex Fortran
250 @value{GDBN} can be used to debug programs written in Fortran, although
251 it may be necessary to refer to some variables with a trailing
252 underscore.
253
254 @menu
255 * Free Software:: Freely redistributable software
256 * Contributors:: Contributors to GDB
257 @end menu
258
259 @node Free Software
260 @unnumberedsec Free software
261
262 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
263 General Public License
264 (GPL). The GPL gives you the freedom to copy or adapt a licensed
265 program---but every person getting a copy also gets with it the
266 freedom to modify that copy (which means that they must get access to
267 the source code), and the freedom to distribute further copies.
268 Typical software companies use copyrights to limit your freedoms; the
269 Free Software Foundation uses the GPL to preserve these freedoms.
270
271 Fundamentally, the General Public License is a license which says that
272 you have these freedoms and that you cannot take these freedoms away
273 from anyone else.
274
275 @node Contributors
276 @unnumberedsec Contributors to @value{GDBN}
277
278 Richard Stallman was the original author of @value{GDBN}, and of many
279 other @sc{gnu} programs. Many others have contributed to its
280 development. This section attempts to credit major contributors. One
281 of the virtues of free software is that everyone is free to contribute
282 to it; with regret, we cannot actually acknowledge everyone here. The
283 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
284 blow-by-blow account.
285
286 Changes much prior to version 2.0 are lost in the mists of time.
287
288 @quotation
289 @emph{Plea:} Additions to this section are particularly welcome. If you
290 or your friends (or enemies, to be evenhanded) have been unfairly
291 omitted from this list, we would like to add your names!
292 @end quotation
293
294 So that they may not regard their many labors as thankless, we
295 particularly thank those who shepherded @value{GDBN} through major
296 releases:
297 Andrew Cagney (release 5.0);
298 Jim Blandy (release 4.18);
299 Jason Molenda (release 4.17);
300 Stan Shebs (release 4.14);
301 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
302 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
303 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
304 Jim Kingdon (releases 3.5, 3.4, and 3.3);
305 and Randy Smith (releases 3.2, 3.1, and 3.0).
306
307 Richard Stallman, assisted at various times by Peter TerMaat, Chris
308 Hanson, and Richard Mlynarik, handled releases through 2.8.
309
310 Michael Tiemann is the author of most of the @sc{gnu} C++ support in
311 @value{GDBN}, with significant additional contributions from Per
312 Bothner. James Clark wrote the @sc{gnu} C++ demangler. Early work on
313 C++ was by Peter TerMaat (who also did much general update work leading
314 to release 3.0).
315
316 @value{GDBN} 4 uses the BFD subroutine library to examine multiple
317 object-file formats; BFD was a joint project of David V.
318 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
319
320 David Johnson wrote the original COFF support; Pace Willison did
321 the original support for encapsulated COFF.
322
323 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
324
325 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
326 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
327 support.
328 Jean-Daniel Fekete contributed Sun 386i support.
329 Chris Hanson improved the HP9000 support.
330 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
331 David Johnson contributed Encore Umax support.
332 Jyrki Kuoppala contributed Altos 3068 support.
333 Jeff Law contributed HP PA and SOM support.
334 Keith Packard contributed NS32K support.
335 Doug Rabson contributed Acorn Risc Machine support.
336 Bob Rusk contributed Harris Nighthawk CX-UX support.
337 Chris Smith contributed Convex support (and Fortran debugging).
338 Jonathan Stone contributed Pyramid support.
339 Michael Tiemann contributed SPARC support.
340 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
341 Pace Willison contributed Intel 386 support.
342 Jay Vosburgh contributed Symmetry support.
343
344 Andreas Schwab contributed M68K Linux support.
345
346 Rich Schaefer and Peter Schauer helped with support of SunOS shared
347 libraries.
348
349 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
350 about several machine instruction sets.
351
352 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
353 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
354 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
355 and RDI targets, respectively.
356
357 Brian Fox is the author of the readline libraries providing
358 command-line editing and command history.
359
360 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
361 Modula-2 support, and contributed the Languages chapter of this manual.
362
363 Fred Fish wrote most of the support for Unix System Vr4.
364 He also enhanced the command-completion support to cover C++ overloaded
365 symbols.
366
367 Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
368 Super-H processors.
369
370 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
371
372 Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
373
374 Toshiba sponsored the support for the TX39 Mips processor.
375
376 Matsushita sponsored the support for the MN10200 and MN10300 processors.
377
378 Fujitsu sponsored the support for SPARClite and FR30 processors.
379
380 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
381 watchpoints.
382
383 Michael Snyder added support for tracepoints.
384
385 Stu Grossman wrote gdbserver.
386
387 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
388 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
389
390 The following people at the Hewlett-Packard Company contributed
391 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
392 (narrow mode), HP's implementation of kernel threads, HP's aC++
393 compiler, and the terminal user interface: Ben Krepp, Richard Title,
394 John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
395 Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
396 information in this manual.
397
398 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
399 development since 1991. Cygnus engineers who have worked on @value{GDBN}
400 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
401 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
402 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
403 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
404 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
405 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
406 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
407 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
408 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
409 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
410 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
411 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
412 Zuhn have made contributions both large and small.
413
414
415 @node Sample Session
416 @chapter A Sample @value{GDBN} Session
417
418 You can use this manual at your leisure to read all about @value{GDBN}.
419 However, a handful of commands are enough to get started using the
420 debugger. This chapter illustrates those commands.
421
422 @iftex
423 In this sample session, we emphasize user input like this: @b{input},
424 to make it easier to pick out from the surrounding output.
425 @end iftex
426
427 @c FIXME: this example may not be appropriate for some configs, where
428 @c FIXME...primary interest is in remote use.
429
430 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
431 processor) exhibits the following bug: sometimes, when we change its
432 quote strings from the default, the commands used to capture one macro
433 definition within another stop working. In the following short @code{m4}
434 session, we define a macro @code{foo} which expands to @code{0000}; we
435 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
436 same thing. However, when we change the open quote string to
437 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
438 procedure fails to define a new synonym @code{baz}:
439
440 @smallexample
441 $ @b{cd gnu/m4}
442 $ @b{./m4}
443 @b{define(foo,0000)}
444
445 @b{foo}
446 0000
447 @b{define(bar,defn(`foo'))}
448
449 @b{bar}
450 0000
451 @b{changequote(<QUOTE>,<UNQUOTE>)}
452
453 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
454 @b{baz}
455 @b{C-d}
456 m4: End of input: 0: fatal error: EOF in string
457 @end smallexample
458
459 @noindent
460 Let us use @value{GDBN} to try to see what is going on.
461
462 @smallexample
463 $ @b{@value{GDBP} m4}
464 @c FIXME: this falsifies the exact text played out, to permit smallbook
465 @c FIXME... format to come out better.
466 @value{GDBN} is free software and you are welcome to distribute copies
467 of it under certain conditions; type "show copying" to see
468 the conditions.
469 There is absolutely no warranty for @value{GDBN}; type "show warranty"
470 for details.
471
472 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
473 (@value{GDBP})
474 @end smallexample
475
476 @noindent
477 @value{GDBN} reads only enough symbol data to know where to find the
478 rest when needed; as a result, the first prompt comes up very quickly.
479 We now tell @value{GDBN} to use a narrower display width than usual, so
480 that examples fit in this manual.
481
482 @smallexample
483 (@value{GDBP}) @b{set width 70}
484 @end smallexample
485
486 @noindent
487 We need to see how the @code{m4} built-in @code{changequote} works.
488 Having looked at the source, we know the relevant subroutine is
489 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
490 @code{break} command.
491
492 @smallexample
493 (@value{GDBP}) @b{break m4_changequote}
494 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
495 @end smallexample
496
497 @noindent
498 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
499 control; as long as control does not reach the @code{m4_changequote}
500 subroutine, the program runs as usual:
501
502 @smallexample
503 (@value{GDBP}) @b{run}
504 Starting program: /work/Editorial/gdb/gnu/m4/m4
505 @b{define(foo,0000)}
506
507 @b{foo}
508 0000
509 @end smallexample
510
511 @noindent
512 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
513 suspends execution of @code{m4}, displaying information about the
514 context where it stops.
515
516 @smallexample
517 @b{changequote(<QUOTE>,<UNQUOTE>)}
518
519 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
520 at builtin.c:879
521 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
522 @end smallexample
523
524 @noindent
525 Now we use the command @code{n} (@code{next}) to advance execution to
526 the next line of the current function.
527
528 @smallexample
529 (@value{GDBP}) @b{n}
530 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
531 : nil,
532 @end smallexample
533
534 @noindent
535 @code{set_quotes} looks like a promising subroutine. We can go into it
536 by using the command @code{s} (@code{step}) instead of @code{next}.
537 @code{step} goes to the next line to be executed in @emph{any}
538 subroutine, so it steps into @code{set_quotes}.
539
540 @smallexample
541 (@value{GDBP}) @b{s}
542 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
543 at input.c:530
544 530 if (lquote != def_lquote)
545 @end smallexample
546
547 @noindent
548 The display that shows the subroutine where @code{m4} is now
549 suspended (and its arguments) is called a stack frame display. It
550 shows a summary of the stack. We can use the @code{backtrace}
551 command (which can also be spelled @code{bt}), to see where we are
552 in the stack as a whole: the @code{backtrace} command displays a
553 stack frame for each active subroutine.
554
555 @smallexample
556 (@value{GDBP}) @b{bt}
557 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
558 at input.c:530
559 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
560 at builtin.c:882
561 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
562 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
563 at macro.c:71
564 #4 0x79dc in expand_input () at macro.c:40
565 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
566 @end smallexample
567
568 @noindent
569 We step through a few more lines to see what happens. The first two
570 times, we can use @samp{s}; the next two times we use @code{n} to avoid
571 falling into the @code{xstrdup} subroutine.
572
573 @smallexample
574 (@value{GDBP}) @b{s}
575 0x3b5c 532 if (rquote != def_rquote)
576 (@value{GDBP}) @b{s}
577 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
578 def_lquote : xstrdup(lq);
579 (@value{GDBP}) @b{n}
580 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
581 : xstrdup(rq);
582 (@value{GDBP}) @b{n}
583 538 len_lquote = strlen(rquote);
584 @end smallexample
585
586 @noindent
587 The last line displayed looks a little odd; we can examine the variables
588 @code{lquote} and @code{rquote} to see if they are in fact the new left
589 and right quotes we specified. We use the command @code{p}
590 (@code{print}) to see their values.
591
592 @smallexample
593 (@value{GDBP}) @b{p lquote}
594 $1 = 0x35d40 "<QUOTE>"
595 (@value{GDBP}) @b{p rquote}
596 $2 = 0x35d50 "<UNQUOTE>"
597 @end smallexample
598
599 @noindent
600 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
601 To look at some context, we can display ten lines of source
602 surrounding the current line with the @code{l} (@code{list}) command.
603
604 @smallexample
605 (@value{GDBP}) @b{l}
606 533 xfree(rquote);
607 534
608 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
609 : xstrdup (lq);
610 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
611 : xstrdup (rq);
612 537
613 538 len_lquote = strlen(rquote);
614 539 len_rquote = strlen(lquote);
615 540 @}
616 541
617 542 void
618 @end smallexample
619
620 @noindent
621 Let us step past the two lines that set @code{len_lquote} and
622 @code{len_rquote}, and then examine the values of those variables.
623
624 @smallexample
625 (@value{GDBP}) @b{n}
626 539 len_rquote = strlen(lquote);
627 (@value{GDBP}) @b{n}
628 540 @}
629 (@value{GDBP}) @b{p len_lquote}
630 $3 = 9
631 (@value{GDBP}) @b{p len_rquote}
632 $4 = 7
633 @end smallexample
634
635 @noindent
636 That certainly looks wrong, assuming @code{len_lquote} and
637 @code{len_rquote} are meant to be the lengths of @code{lquote} and
638 @code{rquote} respectively. We can set them to better values using
639 the @code{p} command, since it can print the value of
640 any expression---and that expression can include subroutine calls and
641 assignments.
642
643 @smallexample
644 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
645 $5 = 7
646 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
647 $6 = 9
648 @end smallexample
649
650 @noindent
651 Is that enough to fix the problem of using the new quotes with the
652 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
653 executing with the @code{c} (@code{continue}) command, and then try the
654 example that caused trouble initially:
655
656 @smallexample
657 (@value{GDBP}) @b{c}
658 Continuing.
659
660 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
661
662 baz
663 0000
664 @end smallexample
665
666 @noindent
667 Success! The new quotes now work just as well as the default ones. The
668 problem seems to have been just the two typos defining the wrong
669 lengths. We allow @code{m4} exit by giving it an EOF as input:
670
671 @smallexample
672 @b{C-d}
673 Program exited normally.
674 @end smallexample
675
676 @noindent
677 The message @samp{Program exited normally.} is from @value{GDBN}; it
678 indicates @code{m4} has finished executing. We can end our @value{GDBN}
679 session with the @value{GDBN} @code{quit} command.
680
681 @smallexample
682 (@value{GDBP}) @b{quit}
683 @end smallexample
684
685 @node Invocation
686 @chapter Getting In and Out of @value{GDBN}
687
688 This chapter discusses how to start @value{GDBN}, and how to get out of it.
689 The essentials are:
690 @itemize @bullet
691 @item
692 type @samp{@value{GDBP}} to start @value{GDBN}.
693 @item
694 type @kbd{quit} or @kbd{C-d} to exit.
695 @end itemize
696
697 @menu
698 * Invoking GDB:: How to start @value{GDBN}
699 * Quitting GDB:: How to quit @value{GDBN}
700 * Shell Commands:: How to use shell commands inside @value{GDBN}
701 @end menu
702
703 @node Invoking GDB
704 @section Invoking @value{GDBN}
705
706 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
707 @value{GDBN} reads commands from the terminal until you tell it to exit.
708
709 You can also run @code{@value{GDBP}} with a variety of arguments and options,
710 to specify more of your debugging environment at the outset.
711
712 The command-line options described here are designed
713 to cover a variety of situations; in some environments, some of these
714 options may effectively be unavailable.
715
716 The most usual way to start @value{GDBN} is with one argument,
717 specifying an executable program:
718
719 @example
720 @value{GDBP} @var{program}
721 @end example
722
723 @noindent
724 You can also start with both an executable program and a core file
725 specified:
726
727 @example
728 @value{GDBP} @var{program} @var{core}
729 @end example
730
731 You can, instead, specify a process ID as a second argument, if you want
732 to debug a running process:
733
734 @example
735 @value{GDBP} @var{program} 1234
736 @end example
737
738 @noindent
739 would attach @value{GDBN} to process @code{1234} (unless you also have a file
740 named @file{1234}; @value{GDBN} does check for a core file first).
741
742 Taking advantage of the second command-line argument requires a fairly
743 complete operating system; when you use @value{GDBN} as a remote
744 debugger attached to a bare board, there may not be any notion of
745 ``process'', and there is often no way to get a core dump. @value{GDBN}
746 will warn you if it is unable to attach or to read core dumps.
747
748 You can run @code{@value{GDBP}} without printing the front material, which describes
749 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
750
751 @smallexample
752 @value{GDBP} -silent
753 @end smallexample
754
755 @noindent
756 You can further control how @value{GDBN} starts up by using command-line
757 options. @value{GDBN} itself can remind you of the options available.
758
759 @noindent
760 Type
761
762 @example
763 @value{GDBP} -help
764 @end example
765
766 @noindent
767 to display all available options and briefly describe their use
768 (@samp{@value{GDBP} -h} is a shorter equivalent).
769
770 All options and command line arguments you give are processed
771 in sequential order. The order makes a difference when the
772 @samp{-x} option is used.
773
774
775 @menu
776 * File Options:: Choosing files
777 * Mode Options:: Choosing modes
778 @end menu
779
780 @node File Options
781 @subsection Choosing files
782
783 When @value{GDBN} starts, it reads any arguments other than options as
784 specifying an executable file and core file (or process ID). This is
785 the same as if the arguments were specified by the @samp{-se} and
786 @samp{-c} options respectively. (@value{GDBN} reads the first argument
787 that does not have an associated option flag as equivalent to the
788 @samp{-se} option followed by that argument; and the second argument
789 that does not have an associated option flag, if any, as equivalent to
790 the @samp{-c} option followed by that argument.)
791
792 If @value{GDBN} has not been configured to included core file support,
793 such as for most embedded targets, then it will complain about a second
794 argument and ignore it.
795
796 Many options have both long and short forms; both are shown in the
797 following list. @value{GDBN} also recognizes the long forms if you truncate
798 them, so long as enough of the option is present to be unambiguous.
799 (If you prefer, you can flag option arguments with @samp{--} rather
800 than @samp{-}, though we illustrate the more usual convention.)
801
802 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
803 @c way, both those who look for -foo and --foo in the index, will find
804 @c it.
805
806 @table @code
807 @item -symbols @var{file}
808 @itemx -s @var{file}
809 @cindex @code{--symbols}
810 @cindex @code{-s}
811 Read symbol table from file @var{file}.
812
813 @item -exec @var{file}
814 @itemx -e @var{file}
815 @cindex @code{--exec}
816 @cindex @code{-e}
817 Use file @var{file} as the executable file to execute when appropriate,
818 and for examining pure data in conjunction with a core dump.
819
820 @item -se @var{file}
821 @cindex @code{--se}
822 Read symbol table from file @var{file} and use it as the executable
823 file.
824
825 @item -core @var{file}
826 @itemx -c @var{file}
827 @cindex @code{--core}
828 @cindex @code{-c}
829 Use file @var{file} as a core dump to examine.
830
831 @item -c @var{number}
832 Connect to process ID @var{number}, as with the @code{attach} command
833 (unless there is a file in core-dump format named @var{number}, in which
834 case @samp{-c} specifies that file as a core dump to read).
835
836 @item -command @var{file}
837 @itemx -x @var{file}
838 @cindex @code{--command}
839 @cindex @code{-x}
840 Execute @value{GDBN} commands from file @var{file}. @xref{Command
841 Files,, Command files}.
842
843 @item -directory @var{directory}
844 @itemx -d @var{directory}
845 @cindex @code{--directory}
846 @cindex @code{-d}
847 Add @var{directory} to the path to search for source files.
848
849 @item -m
850 @itemx -mapped
851 @cindex @code{--mapped}
852 @cindex @code{-m}
853 @emph{Warning: this option depends on operating system facilities that are not
854 supported on all systems.}@*
855 If memory-mapped files are available on your system through the @code{mmap}
856 system call, you can use this option
857 to have @value{GDBN} write the symbols from your
858 program into a reusable file in the current directory. If the program you are debugging is
859 called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
860 Future @value{GDBN} debugging sessions notice the presence of this file,
861 and can quickly map in symbol information from it, rather than reading
862 the symbol table from the executable program.
863
864 The @file{.syms} file is specific to the host machine where @value{GDBN}
865 is run. It holds an exact image of the internal @value{GDBN} symbol
866 table. It cannot be shared across multiple host platforms.
867
868 @item -r
869 @itemx -readnow
870 @cindex @code{--readnow}
871 @cindex @code{-r}
872 Read each symbol file's entire symbol table immediately, rather than
873 the default, which is to read it incrementally as it is needed.
874 This makes startup slower, but makes future operations faster.
875
876 @end table
877
878 You typically combine the @code{-mapped} and @code{-readnow} options in
879 order to build a @file{.syms} file that contains complete symbol
880 information. (@xref{Files,,Commands to specify files}, for information
881 on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
882 but build a @file{.syms} file for future use is:
883
884 @example
885 gdb -batch -nx -mapped -readnow programname
886 @end example
887
888 @node Mode Options
889 @subsection Choosing modes
890
891 You can run @value{GDBN} in various alternative modes---for example, in
892 batch mode or quiet mode.
893
894 @table @code
895 @item -nx
896 @itemx -n
897 @cindex @code{--nx}
898 @cindex @code{-n}
899 Do not execute commands found in any initialization files (normally
900 called @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally,
901 @value{GDBN} executes the commands in these files after all the command
902 options and arguments have been processed. @xref{Command Files,,Command
903 files}.
904
905 @item -quiet
906 @itemx -silent
907 @itemx -q
908 @cindex @code{--quiet}
909 @cindex @code{--silent}
910 @cindex @code{-q}
911 ``Quiet''. Do not print the introductory and copyright messages. These
912 messages are also suppressed in batch mode.
913
914 @item -batch
915 @cindex @code{--batch}
916 Run in batch mode. Exit with status @code{0} after processing all the
917 command files specified with @samp{-x} (and all commands from
918 initialization files, if not inhibited with @samp{-n}). Exit with
919 nonzero status if an error occurs in executing the @value{GDBN} commands
920 in the command files.
921
922 Batch mode may be useful for running @value{GDBN} as a filter, for
923 example to download and run a program on another computer; in order to
924 make this more useful, the message
925
926 @example
927 Program exited normally.
928 @end example
929
930 @noindent
931 (which is ordinarily issued whenever a program running under
932 @value{GDBN} control terminates) is not issued when running in batch
933 mode.
934
935 @item -nowindows
936 @itemx -nw
937 @cindex @code{--nowindows}
938 @cindex @code{-nw}
939 ``No windows''. If @value{GDBN} comes with a graphical user interface
940 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
941 interface. If no GUI is available, this option has no effect.
942
943 @item -windows
944 @itemx -w
945 @cindex @code{--windows}
946 @cindex @code{-w}
947 If @value{GDBN} includes a GUI, then this option requires it to be
948 used if possible.
949
950 @item -cd @var{directory}
951 @cindex @code{--cd}
952 Run @value{GDBN} using @var{directory} as its working directory,
953 instead of the current directory.
954
955 @item -fullname
956 @itemx -f
957 @cindex @code{--fullname}
958 @cindex @code{-f}
959 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
960 subprocess. It tells @value{GDBN} to output the full file name and line
961 number in a standard, recognizable fashion each time a stack frame is
962 displayed (which includes each time your program stops). This
963 recognizable format looks like two @samp{\032} characters, followed by
964 the file name, line number and character position separated by colons,
965 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
966 @samp{\032} characters as a signal to display the source code for the
967 frame.
968
969 @item -epoch
970 @cindex @code{--epoch}
971 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
972 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
973 routines so as to allow Epoch to display values of expressions in a
974 separate window.
975
976 @item -annotate @var{level}
977 @cindex @code{--annotate}
978 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
979 effect is identical to using @samp{set annotate @var{level}}
980 (@pxref{Annotations}).
981 Annotation level controls how much information does @value{GDBN} print
982 together with its prompt, values of expressions, source lines, and other
983 types of output. Level 0 is the normal, level 1 is for use when
984 @value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
985 maximum annotation suitable for programs that control @value{GDBN}.
986
987 @item -async
988 @cindex @code{--async}
989 Use the asynchronous event loop for the command-line interface.
990 @value{GDBN} processes all events, such as user keyboard input, via a
991 special event loop. This allows @value{GDBN} to accept and process user
992 commands in parallel with the debugged process being
993 run@footnote{@value{GDBN} built with @sc{djgpp} tools for
994 MS-DOS/MS-Windows supports this mode of operation, but the event loop is
995 suspended when the debuggee runs.}, so you don't need to wait for
996 control to return to @value{GDBN} before you type the next command.
997 (@emph{Note:} as of version 5.0, the target side of the asynchronous
998 operation is not yet in place, so @samp{-async} does not work fully
999 yet.)
1000 @c FIXME: when the target side of the event loop is done, the above NOTE
1001 @c should be removed.
1002
1003 When the standard input is connected to a terminal device, @value{GDBN}
1004 uses the asynchronous event loop by default, unless disabled by the
1005 @samp{-noasync} option.
1006
1007 @item -noasync
1008 @cindex @code{--noasync}
1009 Disable the asynchronous event loop for the command-line interface.
1010
1011 @item -baud @var{bps}
1012 @itemx -b @var{bps}
1013 @cindex @code{--baud}
1014 @cindex @code{-b}
1015 Set the line speed (baud rate or bits per second) of any serial
1016 interface used by @value{GDBN} for remote debugging.
1017
1018 @item -tty @var{device}
1019 @itemx -t @var{device}
1020 @cindex @code{--tty}
1021 @cindex @code{-t}
1022 Run using @var{device} for your program's standard input and output.
1023 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1024
1025 @c resolve the situation of these eventually
1026 @c @item -tui
1027 @c @cindex @code{--tui}
1028 @c Use a Terminal User Interface. For information, use your Web browser to
1029 @c read the file @file{TUI.html}, which is usually installed in the
1030 @c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
1031 @c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
1032 @c @value{GDBN} under @sc{gnu} Emacs}).
1033
1034 @c @item -xdb
1035 @c @cindex @code{--xdb}
1036 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1037 @c For information, see the file @file{xdb_trans.html}, which is usually
1038 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1039 @c systems.
1040
1041 @item -interpreter @var{interp}
1042 @cindex @code{--interpreter}
1043 Use the interpreter @var{interp} for interface with the controlling
1044 program or device. This option is meant to be set by programs which
1045 communicate with @value{GDBN} using it as a back end. For example,
1046 @samp{--interpreter=mi} causes @value{GDBN} to use the @dfn{gdbmi
1047 interface} (@pxref{GDB/MI, , The @sc{gdb/mi} Interface}).
1048
1049 @item -write
1050 @cindex @code{--write}
1051 Open the executable and core files for both reading and writing. This
1052 is equivalent to the @samp{set write on} command inside @value{GDBN}
1053 (@pxref{Patching}).
1054
1055 @item -statistics
1056 @cindex @code{--statistics}
1057 This option causes @value{GDBN} to print statistics about time and
1058 memory usage after it completes each command and returns to the prompt.
1059
1060 @item -version
1061 @cindex @code{--version}
1062 This option causes @value{GDBN} to print its version number and
1063 no-warranty blurb, and exit.
1064
1065 @end table
1066
1067 @node Quitting GDB
1068 @section Quitting @value{GDBN}
1069 @cindex exiting @value{GDBN}
1070 @cindex leaving @value{GDBN}
1071
1072 @table @code
1073 @kindex quit @r{[}@var{expression}@r{]}
1074 @kindex q @r{(@code{quit})}
1075 @item quit @r{[}@var{expression}@r{]}
1076 @itemx q
1077 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1078 @code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1079 do not supply @var{expression}, @value{GDBN} will terminate normally;
1080 otherwise it will terminate using the result of @var{expression} as the
1081 error code.
1082 @end table
1083
1084 @cindex interrupt
1085 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1086 terminates the action of any @value{GDBN} command that is in progress and
1087 returns to @value{GDBN} command level. It is safe to type the interrupt
1088 character at any time because @value{GDBN} does not allow it to take effect
1089 until a time when it is safe.
1090
1091 If you have been using @value{GDBN} to control an attached process or
1092 device, you can release it with the @code{detach} command
1093 (@pxref{Attach, ,Debugging an already-running process}).
1094
1095 @node Shell Commands
1096 @section Shell commands
1097
1098 If you need to execute occasional shell commands during your
1099 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1100 just use the @code{shell} command.
1101
1102 @table @code
1103 @kindex shell
1104 @cindex shell escape
1105 @item shell @var{command string}
1106 Invoke a standard shell to execute @var{command string}.
1107 If it exists, the environment variable @code{SHELL} determines which
1108 shell to run. Otherwise @value{GDBN} uses the default shell
1109 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1110 @end table
1111
1112 The utility @code{make} is often needed in development environments.
1113 You do not have to use the @code{shell} command for this purpose in
1114 @value{GDBN}:
1115
1116 @table @code
1117 @kindex make
1118 @cindex calling make
1119 @item make @var{make-args}
1120 Execute the @code{make} program with the specified
1121 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1122 @end table
1123
1124 @node Commands
1125 @chapter @value{GDBN} Commands
1126
1127 You can abbreviate a @value{GDBN} command to the first few letters of the command
1128 name, if that abbreviation is unambiguous; and you can repeat certain
1129 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1130 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1131 show you the alternatives available, if there is more than one possibility).
1132
1133 @menu
1134 * Command Syntax:: How to give commands to @value{GDBN}
1135 * Completion:: Command completion
1136 * Help:: How to ask @value{GDBN} for help
1137 @end menu
1138
1139 @node Command Syntax
1140 @section Command syntax
1141
1142 A @value{GDBN} command is a single line of input. There is no limit on
1143 how long it can be. It starts with a command name, which is followed by
1144 arguments whose meaning depends on the command name. For example, the
1145 command @code{step} accepts an argument which is the number of times to
1146 step, as in @samp{step 5}. You can also use the @code{step} command
1147 with no arguments. Some commands do not allow any arguments.
1148
1149 @cindex abbreviation
1150 @value{GDBN} command names may always be truncated if that abbreviation is
1151 unambiguous. Other possible command abbreviations are listed in the
1152 documentation for individual commands. In some cases, even ambiguous
1153 abbreviations are allowed; for example, @code{s} is specially defined as
1154 equivalent to @code{step} even though there are other commands whose
1155 names start with @code{s}. You can test abbreviations by using them as
1156 arguments to the @code{help} command.
1157
1158 @cindex repeating commands
1159 @kindex RET @r{(repeat last command)}
1160 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1161 repeat the previous command. Certain commands (for example, @code{run})
1162 will not repeat this way; these are commands whose unintentional
1163 repetition might cause trouble and which you are unlikely to want to
1164 repeat.
1165
1166 The @code{list} and @code{x} commands, when you repeat them with
1167 @key{RET}, construct new arguments rather than repeating
1168 exactly as typed. This permits easy scanning of source or memory.
1169
1170 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1171 output, in a way similar to the common utility @code{more}
1172 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
1173 @key{RET} too many in this situation, @value{GDBN} disables command
1174 repetition after any command that generates this sort of display.
1175
1176 @kindex # @r{(a comment)}
1177 @cindex comment
1178 Any text from a @kbd{#} to the end of the line is a comment; it does
1179 nothing. This is useful mainly in command files (@pxref{Command
1180 Files,,Command files}).
1181
1182 @node Completion
1183 @section Command completion
1184
1185 @cindex completion
1186 @cindex word completion
1187 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1188 only one possibility; it can also show you what the valid possibilities
1189 are for the next word in a command, at any time. This works for @value{GDBN}
1190 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1191
1192 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1193 of a word. If there is only one possibility, @value{GDBN} fills in the
1194 word, and waits for you to finish the command (or press @key{RET} to
1195 enter it). For example, if you type
1196
1197 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1198 @c complete accuracy in these examples; space introduced for clarity.
1199 @c If texinfo enhancements make it unnecessary, it would be nice to
1200 @c replace " @key" by "@key" in the following...
1201 @example
1202 (@value{GDBP}) info bre @key{TAB}
1203 @end example
1204
1205 @noindent
1206 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1207 the only @code{info} subcommand beginning with @samp{bre}:
1208
1209 @example
1210 (@value{GDBP}) info breakpoints
1211 @end example
1212
1213 @noindent
1214 You can either press @key{RET} at this point, to run the @code{info
1215 breakpoints} command, or backspace and enter something else, if
1216 @samp{breakpoints} does not look like the command you expected. (If you
1217 were sure you wanted @code{info breakpoints} in the first place, you
1218 might as well just type @key{RET} immediately after @samp{info bre},
1219 to exploit command abbreviations rather than command completion).
1220
1221 If there is more than one possibility for the next word when you press
1222 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1223 characters and try again, or just press @key{TAB} a second time;
1224 @value{GDBN} displays all the possible completions for that word. For
1225 example, you might want to set a breakpoint on a subroutine whose name
1226 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1227 just sounds the bell. Typing @key{TAB} again displays all the
1228 function names in your program that begin with those characters, for
1229 example:
1230
1231 @example
1232 (@value{GDBP}) b make_ @key{TAB}
1233 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1234 make_a_section_from_file make_environ
1235 make_abs_section make_function_type
1236 make_blockvector make_pointer_type
1237 make_cleanup make_reference_type
1238 make_command make_symbol_completion_list
1239 (@value{GDBP}) b make_
1240 @end example
1241
1242 @noindent
1243 After displaying the available possibilities, @value{GDBN} copies your
1244 partial input (@samp{b make_} in the example) so you can finish the
1245 command.
1246
1247 If you just want to see the list of alternatives in the first place, you
1248 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1249 means @kbd{@key{META} ?}. You can type this either by holding down a
1250 key designated as the @key{META} shift on your keyboard (if there is
1251 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1252
1253 @cindex quotes in commands
1254 @cindex completion of quoted strings
1255 Sometimes the string you need, while logically a ``word'', may contain
1256 parentheses or other characters that @value{GDBN} normally excludes from
1257 its notion of a word. To permit word completion to work in this
1258 situation, you may enclose words in @code{'} (single quote marks) in
1259 @value{GDBN} commands.
1260
1261 The most likely situation where you might need this is in typing the
1262 name of a C++ function. This is because C++ allows function overloading
1263 (multiple definitions of the same function, distinguished by argument
1264 type). For example, when you want to set a breakpoint you may need to
1265 distinguish whether you mean the version of @code{name} that takes an
1266 @code{int} parameter, @code{name(int)}, or the version that takes a
1267 @code{float} parameter, @code{name(float)}. To use the word-completion
1268 facilities in this situation, type a single quote @code{'} at the
1269 beginning of the function name. This alerts @value{GDBN} that it may need to
1270 consider more information than usual when you press @key{TAB} or
1271 @kbd{M-?} to request word completion:
1272
1273 @example
1274 (@value{GDBP}) b 'bubble( @kbd{M-?}
1275 bubble(double,double) bubble(int,int)
1276 (@value{GDBP}) b 'bubble(
1277 @end example
1278
1279 In some cases, @value{GDBN} can tell that completing a name requires using
1280 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1281 completing as much as it can) if you do not type the quote in the first
1282 place:
1283
1284 @example
1285 (@value{GDBP}) b bub @key{TAB}
1286 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1287 (@value{GDBP}) b 'bubble(
1288 @end example
1289
1290 @noindent
1291 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1292 you have not yet started typing the argument list when you ask for
1293 completion on an overloaded symbol.
1294
1295 For more information about overloaded functions, see @ref{C plus plus
1296 expressions, ,C++ expressions}. You can use the command @code{set
1297 overload-resolution off} to disable overload resolution;
1298 see @ref{Debugging C plus plus, ,@value{GDBN} features for C++}.
1299
1300
1301 @node Help
1302 @section Getting help
1303 @cindex online documentation
1304 @kindex help
1305
1306 You can always ask @value{GDBN} itself for information on its commands,
1307 using the command @code{help}.
1308
1309 @table @code
1310 @kindex h @r{(@code{help})}
1311 @item help
1312 @itemx h
1313 You can use @code{help} (abbreviated @code{h}) with no arguments to
1314 display a short list of named classes of commands:
1315
1316 @smallexample
1317 (@value{GDBP}) help
1318 List of classes of commands:
1319
1320 aliases -- Aliases of other commands
1321 breakpoints -- Making program stop at certain points
1322 data -- Examining data
1323 files -- Specifying and examining files
1324 internals -- Maintenance commands
1325 obscure -- Obscure features
1326 running -- Running the program
1327 stack -- Examining the stack
1328 status -- Status inquiries
1329 support -- Support facilities
1330 tracepoints -- Tracing of program execution without@*
1331 stopping the program
1332 user-defined -- User-defined commands
1333
1334 Type "help" followed by a class name for a list of
1335 commands in that class.
1336 Type "help" followed by command name for full
1337 documentation.
1338 Command name abbreviations are allowed if unambiguous.
1339 (@value{GDBP})
1340 @end smallexample
1341 @c the above line break eliminates huge line overfull...
1342
1343 @item help @var{class}
1344 Using one of the general help classes as an argument, you can get a
1345 list of the individual commands in that class. For example, here is the
1346 help display for the class @code{status}:
1347
1348 @smallexample
1349 (@value{GDBP}) help status
1350 Status inquiries.
1351
1352 List of commands:
1353
1354 @c Line break in "show" line falsifies real output, but needed
1355 @c to fit in smallbook page size.
1356 info -- Generic command for showing things
1357 about the program being debugged
1358 show -- Generic command for showing things
1359 about the debugger
1360
1361 Type "help" followed by command name for full
1362 documentation.
1363 Command name abbreviations are allowed if unambiguous.
1364 (@value{GDBP})
1365 @end smallexample
1366
1367 @item help @var{command}
1368 With a command name as @code{help} argument, @value{GDBN} displays a
1369 short paragraph on how to use that command.
1370
1371 @kindex apropos
1372 @item apropos @var{args}
1373 The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1374 commands, and their documentation, for the regular expression specified in
1375 @var{args}. It prints out all matches found. For example:
1376
1377 @smallexample
1378 apropos reload
1379 @end smallexample
1380
1381 @noindent results in:
1382
1383 @smallexample
1384 @c @group
1385 set symbol-reloading -- Set dynamic symbol table reloading
1386 multiple times in one run
1387 show symbol-reloading -- Show dynamic symbol table reloading
1388 multiple times in one run
1389 @c @end group
1390 @end smallexample
1391
1392 @kindex complete
1393 @item complete @var{args}
1394 The @code{complete @var{args}} command lists all the possible completions
1395 for the beginning of a command. Use @var{args} to specify the beginning of the
1396 command you want completed. For example:
1397
1398 @smallexample
1399 complete i
1400 @end smallexample
1401
1402 @noindent results in:
1403
1404 @smallexample
1405 @group
1406 if
1407 ignore
1408 info
1409 inspect
1410 @end group
1411 @end smallexample
1412
1413 @noindent This is intended for use by @sc{gnu} Emacs.
1414 @end table
1415
1416 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1417 and @code{show} to inquire about the state of your program, or the state
1418 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1419 manual introduces each of them in the appropriate context. The listings
1420 under @code{info} and under @code{show} in the Index point to
1421 all the sub-commands. @xref{Index}.
1422
1423 @c @group
1424 @table @code
1425 @kindex info
1426 @kindex i @r{(@code{info})}
1427 @item info
1428 This command (abbreviated @code{i}) is for describing the state of your
1429 program. For example, you can list the arguments given to your program
1430 with @code{info args}, list the registers currently in use with @code{info
1431 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1432 You can get a complete list of the @code{info} sub-commands with
1433 @w{@code{help info}}.
1434
1435 @kindex set
1436 @item set
1437 You can assign the result of an expression to an environment variable with
1438 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1439 @code{set prompt $}.
1440
1441 @kindex show
1442 @item show
1443 In contrast to @code{info}, @code{show} is for describing the state of
1444 @value{GDBN} itself.
1445 You can change most of the things you can @code{show}, by using the
1446 related command @code{set}; for example, you can control what number
1447 system is used for displays with @code{set radix}, or simply inquire
1448 which is currently in use with @code{show radix}.
1449
1450 @kindex info set
1451 To display all the settable parameters and their current
1452 values, you can use @code{show} with no arguments; you may also use
1453 @code{info set}. Both commands produce the same display.
1454 @c FIXME: "info set" violates the rule that "info" is for state of
1455 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1456 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1457 @end table
1458 @c @end group
1459
1460 Here are three miscellaneous @code{show} subcommands, all of which are
1461 exceptional in lacking corresponding @code{set} commands:
1462
1463 @table @code
1464 @kindex show version
1465 @cindex version number
1466 @item show version
1467 Show what version of @value{GDBN} is running. You should include this
1468 information in @value{GDBN} bug-reports. If multiple versions of
1469 @value{GDBN} are in use at your site, you may need to determine which
1470 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1471 commands are introduced, and old ones may wither away. Also, many
1472 system vendors ship variant versions of @value{GDBN}, and there are
1473 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1474 The version number is the same as the one announced when you start
1475 @value{GDBN}.
1476
1477 @kindex show copying
1478 @item show copying
1479 Display information about permission for copying @value{GDBN}.
1480
1481 @kindex show warranty
1482 @item show warranty
1483 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1484 if your version of @value{GDBN} comes with one.
1485
1486 @end table
1487
1488 @node Running
1489 @chapter Running Programs Under @value{GDBN}
1490
1491 When you run a program under @value{GDBN}, you must first generate
1492 debugging information when you compile it.
1493
1494 You may start @value{GDBN} with its arguments, if any, in an environment
1495 of your choice. If you are doing native debugging, you may redirect
1496 your program's input and output, debug an already running process, or
1497 kill a child process.
1498
1499 @menu
1500 * Compilation:: Compiling for debugging
1501 * Starting:: Starting your program
1502 * Arguments:: Your program's arguments
1503 * Environment:: Your program's environment
1504
1505 * Working Directory:: Your program's working directory
1506 * Input/Output:: Your program's input and output
1507 * Attach:: Debugging an already-running process
1508 * Kill Process:: Killing the child process
1509
1510 * Threads:: Debugging programs with multiple threads
1511 * Processes:: Debugging programs with multiple processes
1512 @end menu
1513
1514 @node Compilation
1515 @section Compiling for debugging
1516
1517 In order to debug a program effectively, you need to generate
1518 debugging information when you compile it. This debugging information
1519 is stored in the object file; it describes the data type of each
1520 variable or function and the correspondence between source line numbers
1521 and addresses in the executable code.
1522
1523 To request debugging information, specify the @samp{-g} option when you run
1524 the compiler.
1525
1526 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1527 options together. Using those compilers, you cannot generate optimized
1528 executables containing debugging information.
1529
1530 @value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1531 without @samp{-O}, making it possible to debug optimized code. We
1532 recommend that you @emph{always} use @samp{-g} whenever you compile a
1533 program. You may think your program is correct, but there is no sense
1534 in pushing your luck.
1535
1536 @cindex optimized code, debugging
1537 @cindex debugging optimized code
1538 When you debug a program compiled with @samp{-g -O}, remember that the
1539 optimizer is rearranging your code; the debugger shows you what is
1540 really there. Do not be too surprised when the execution path does not
1541 exactly match your source file! An extreme example: if you define a
1542 variable, but never use it, @value{GDBN} never sees that
1543 variable---because the compiler optimizes it out of existence.
1544
1545 Some things do not work as well with @samp{-g -O} as with just
1546 @samp{-g}, particularly on machines with instruction scheduling. If in
1547 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1548 please report it to us as a bug (including a test case!).
1549
1550 Older versions of the @sc{gnu} C compiler permitted a variant option
1551 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1552 format; if your @sc{gnu} C compiler has this option, do not use it.
1553
1554 @need 2000
1555 @node Starting
1556 @section Starting your program
1557 @cindex starting
1558 @cindex running
1559
1560 @table @code
1561 @kindex run
1562 @kindex r @r{(@code{run})}
1563 @item run
1564 @itemx r
1565 Use the @code{run} command to start your program under @value{GDBN}.
1566 You must first specify the program name (except on VxWorks) with an
1567 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1568 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1569 (@pxref{Files, ,Commands to specify files}).
1570
1571 @end table
1572
1573 If you are running your program in an execution environment that
1574 supports processes, @code{run} creates an inferior process and makes
1575 that process run your program. (In environments without processes,
1576 @code{run} jumps to the start of your program.)
1577
1578 The execution of a program is affected by certain information it
1579 receives from its superior. @value{GDBN} provides ways to specify this
1580 information, which you must do @emph{before} starting your program. (You
1581 can change it after starting your program, but such changes only affect
1582 your program the next time you start it.) This information may be
1583 divided into four categories:
1584
1585 @table @asis
1586 @item The @emph{arguments.}
1587 Specify the arguments to give your program as the arguments of the
1588 @code{run} command. If a shell is available on your target, the shell
1589 is used to pass the arguments, so that you may use normal conventions
1590 (such as wildcard expansion or variable substitution) in describing
1591 the arguments.
1592 In Unix systems, you can control which shell is used with the
1593 @code{SHELL} environment variable.
1594 @xref{Arguments, ,Your program's arguments}.
1595
1596 @item The @emph{environment.}
1597 Your program normally inherits its environment from @value{GDBN}, but you can
1598 use the @value{GDBN} commands @code{set environment} and @code{unset
1599 environment} to change parts of the environment that affect
1600 your program. @xref{Environment, ,Your program's environment}.
1601
1602 @item The @emph{working directory.}
1603 Your program inherits its working directory from @value{GDBN}. You can set
1604 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1605 @xref{Working Directory, ,Your program's working directory}.
1606
1607 @item The @emph{standard input and output.}
1608 Your program normally uses the same device for standard input and
1609 standard output as @value{GDBN} is using. You can redirect input and output
1610 in the @code{run} command line, or you can use the @code{tty} command to
1611 set a different device for your program.
1612 @xref{Input/Output, ,Your program's input and output}.
1613
1614 @cindex pipes
1615 @emph{Warning:} While input and output redirection work, you cannot use
1616 pipes to pass the output of the program you are debugging to another
1617 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1618 wrong program.
1619 @end table
1620
1621 When you issue the @code{run} command, your program begins to execute
1622 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1623 of how to arrange for your program to stop. Once your program has
1624 stopped, you may call functions in your program, using the @code{print}
1625 or @code{call} commands. @xref{Data, ,Examining Data}.
1626
1627 If the modification time of your symbol file has changed since the last
1628 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1629 table, and reads it again. When it does this, @value{GDBN} tries to retain
1630 your current breakpoints.
1631
1632 @node Arguments
1633 @section Your program's arguments
1634
1635 @cindex arguments (to your program)
1636 The arguments to your program can be specified by the arguments of the
1637 @code{run} command.
1638 They are passed to a shell, which expands wildcard characters and
1639 performs redirection of I/O, and thence to your program. Your
1640 @code{SHELL} environment variable (if it exists) specifies what shell
1641 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1642 the default shell (@file{/bin/sh} on Unix).
1643
1644 On non-Unix systems, the program is usually invoked directly by
1645 @value{GDBN}, which emulates I/O redirection via the appropriate system
1646 calls, and the wildcard characters are expanded by the startup code of
1647 the program, not by the shell.
1648
1649 @code{run} with no arguments uses the same arguments used by the previous
1650 @code{run}, or those set by the @code{set args} command.
1651
1652 @table @code
1653 @kindex set args
1654 @item set args
1655 Specify the arguments to be used the next time your program is run. If
1656 @code{set args} has no arguments, @code{run} executes your program
1657 with no arguments. Once you have run your program with arguments,
1658 using @code{set args} before the next @code{run} is the only way to run
1659 it again without arguments.
1660
1661 @kindex show args
1662 @item show args
1663 Show the arguments to give your program when it is started.
1664 @end table
1665
1666 @node Environment
1667 @section Your program's environment
1668
1669 @cindex environment (of your program)
1670 The @dfn{environment} consists of a set of environment variables and
1671 their values. Environment variables conventionally record such things as
1672 your user name, your home directory, your terminal type, and your search
1673 path for programs to run. Usually you set up environment variables with
1674 the shell and they are inherited by all the other programs you run. When
1675 debugging, it can be useful to try running your program with a modified
1676 environment without having to start @value{GDBN} over again.
1677
1678 @table @code
1679 @kindex path
1680 @item path @var{directory}
1681 Add @var{directory} to the front of the @code{PATH} environment variable
1682 (the search path for executables), for both @value{GDBN} and your program.
1683 You may specify several directory names, separated by whitespace or by a
1684 system-dependent separator character (@samp{:} on Unix, @samp{;} on
1685 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1686 is moved to the front, so it is searched sooner.
1687
1688 You can use the string @samp{$cwd} to refer to whatever is the current
1689 working directory at the time @value{GDBN} searches the path. If you
1690 use @samp{.} instead, it refers to the directory where you executed the
1691 @code{path} command. @value{GDBN} replaces @samp{.} in the
1692 @var{directory} argument (with the current path) before adding
1693 @var{directory} to the search path.
1694 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1695 @c document that, since repeating it would be a no-op.
1696
1697 @kindex show paths
1698 @item show paths
1699 Display the list of search paths for executables (the @code{PATH}
1700 environment variable).
1701
1702 @kindex show environment
1703 @item show environment @r{[}@var{varname}@r{]}
1704 Print the value of environment variable @var{varname} to be given to
1705 your program when it starts. If you do not supply @var{varname},
1706 print the names and values of all environment variables to be given to
1707 your program. You can abbreviate @code{environment} as @code{env}.
1708
1709 @kindex set environment
1710 @item set environment @var{varname} @r{[}=@var{value}@r{]}
1711 Set environment variable @var{varname} to @var{value}. The value
1712 changes for your program only, not for @value{GDBN} itself. @var{value} may
1713 be any string; the values of environment variables are just strings, and
1714 any interpretation is supplied by your program itself. The @var{value}
1715 parameter is optional; if it is eliminated, the variable is set to a
1716 null value.
1717 @c "any string" here does not include leading, trailing
1718 @c blanks. Gnu asks: does anyone care?
1719
1720 For example, this command:
1721
1722 @example
1723 set env USER = foo
1724 @end example
1725
1726 @noindent
1727 tells the debugged program, when subsequently run, that its user is named
1728 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1729 are not actually required.)
1730
1731 @kindex unset environment
1732 @item unset environment @var{varname}
1733 Remove variable @var{varname} from the environment to be passed to your
1734 program. This is different from @samp{set env @var{varname} =};
1735 @code{unset environment} removes the variable from the environment,
1736 rather than assigning it an empty value.
1737 @end table
1738
1739 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1740 the shell indicated
1741 by your @code{SHELL} environment variable if it exists (or
1742 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1743 that runs an initialization file---such as @file{.cshrc} for C-shell, or
1744 @file{.bashrc} for BASH---any variables you set in that file affect
1745 your program. You may wish to move setting of environment variables to
1746 files that are only run when you sign on, such as @file{.login} or
1747 @file{.profile}.
1748
1749 @node Working Directory
1750 @section Your program's working directory
1751
1752 @cindex working directory (of your program)
1753 Each time you start your program with @code{run}, it inherits its
1754 working directory from the current working directory of @value{GDBN}.
1755 The @value{GDBN} working directory is initially whatever it inherited
1756 from its parent process (typically the shell), but you can specify a new
1757 working directory in @value{GDBN} with the @code{cd} command.
1758
1759 The @value{GDBN} working directory also serves as a default for the commands
1760 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1761 specify files}.
1762
1763 @table @code
1764 @kindex cd
1765 @item cd @var{directory}
1766 Set the @value{GDBN} working directory to @var{directory}.
1767
1768 @kindex pwd
1769 @item pwd
1770 Print the @value{GDBN} working directory.
1771 @end table
1772
1773 @node Input/Output
1774 @section Your program's input and output
1775
1776 @cindex redirection
1777 @cindex i/o
1778 @cindex terminal
1779 By default, the program you run under @value{GDBN} does input and output to
1780 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
1781 to its own terminal modes to interact with you, but it records the terminal
1782 modes your program was using and switches back to them when you continue
1783 running your program.
1784
1785 @table @code
1786 @kindex info terminal
1787 @item info terminal
1788 Displays information recorded by @value{GDBN} about the terminal modes your
1789 program is using.
1790 @end table
1791
1792 You can redirect your program's input and/or output using shell
1793 redirection with the @code{run} command. For example,
1794
1795 @example
1796 run > outfile
1797 @end example
1798
1799 @noindent
1800 starts your program, diverting its output to the file @file{outfile}.
1801
1802 @kindex tty
1803 @cindex controlling terminal
1804 Another way to specify where your program should do input and output is
1805 with the @code{tty} command. This command accepts a file name as
1806 argument, and causes this file to be the default for future @code{run}
1807 commands. It also resets the controlling terminal for the child
1808 process, for future @code{run} commands. For example,
1809
1810 @example
1811 tty /dev/ttyb
1812 @end example
1813
1814 @noindent
1815 directs that processes started with subsequent @code{run} commands
1816 default to do input and output on the terminal @file{/dev/ttyb} and have
1817 that as their controlling terminal.
1818
1819 An explicit redirection in @code{run} overrides the @code{tty} command's
1820 effect on the input/output device, but not its effect on the controlling
1821 terminal.
1822
1823 When you use the @code{tty} command or redirect input in the @code{run}
1824 command, only the input @emph{for your program} is affected. The input
1825 for @value{GDBN} still comes from your terminal.
1826
1827 @node Attach
1828 @section Debugging an already-running process
1829 @kindex attach
1830 @cindex attach
1831
1832 @table @code
1833 @item attach @var{process-id}
1834 This command attaches to a running process---one that was started
1835 outside @value{GDBN}. (@code{info files} shows your active
1836 targets.) The command takes as argument a process ID. The usual way to
1837 find out the process-id of a Unix process is with the @code{ps} utility,
1838 or with the @samp{jobs -l} shell command.
1839
1840 @code{attach} does not repeat if you press @key{RET} a second time after
1841 executing the command.
1842 @end table
1843
1844 To use @code{attach}, your program must be running in an environment
1845 which supports processes; for example, @code{attach} does not work for
1846 programs on bare-board targets that lack an operating system. You must
1847 also have permission to send the process a signal.
1848
1849 When you use @code{attach}, the debugger finds the program running in
1850 the process first by looking in the current working directory, then (if
1851 the program is not found) by using the source file search path
1852 (@pxref{Source Path, ,Specifying source directories}). You can also use
1853 the @code{file} command to load the program. @xref{Files, ,Commands to
1854 Specify Files}.
1855
1856 The first thing @value{GDBN} does after arranging to debug the specified
1857 process is to stop it. You can examine and modify an attached process
1858 with all the @value{GDBN} commands that are ordinarily available when
1859 you start processes with @code{run}. You can insert breakpoints; you
1860 can step and continue; you can modify storage. If you would rather the
1861 process continue running, you may use the @code{continue} command after
1862 attaching @value{GDBN} to the process.
1863
1864 @table @code
1865 @kindex detach
1866 @item detach
1867 When you have finished debugging the attached process, you can use the
1868 @code{detach} command to release it from @value{GDBN} control. Detaching
1869 the process continues its execution. After the @code{detach} command,
1870 that process and @value{GDBN} become completely independent once more, and you
1871 are ready to @code{attach} another process or start one with @code{run}.
1872 @code{detach} does not repeat if you press @key{RET} again after
1873 executing the command.
1874 @end table
1875
1876 If you exit @value{GDBN} or use the @code{run} command while you have an
1877 attached process, you kill that process. By default, @value{GDBN} asks
1878 for confirmation if you try to do either of these things; you can
1879 control whether or not you need to confirm by using the @code{set
1880 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1881 messages}).
1882
1883 @node Kill Process
1884 @section Killing the child process
1885
1886 @table @code
1887 @kindex kill
1888 @item kill
1889 Kill the child process in which your program is running under @value{GDBN}.
1890 @end table
1891
1892 This command is useful if you wish to debug a core dump instead of a
1893 running process. @value{GDBN} ignores any core dump file while your program
1894 is running.
1895
1896 On some operating systems, a program cannot be executed outside @value{GDBN}
1897 while you have breakpoints set on it inside @value{GDBN}. You can use the
1898 @code{kill} command in this situation to permit running your program
1899 outside the debugger.
1900
1901 The @code{kill} command is also useful if you wish to recompile and
1902 relink your program, since on many systems it is impossible to modify an
1903 executable file while it is running in a process. In this case, when you
1904 next type @code{run}, @value{GDBN} notices that the file has changed, and
1905 reads the symbol table again (while trying to preserve your current
1906 breakpoint settings).
1907
1908 @node Threads
1909 @section Debugging programs with multiple threads
1910
1911 @cindex threads of execution
1912 @cindex multiple threads
1913 @cindex switching threads
1914 In some operating systems, such as HP-UX and Solaris, a single program
1915 may have more than one @dfn{thread} of execution. The precise semantics
1916 of threads differ from one operating system to another, but in general
1917 the threads of a single program are akin to multiple processes---except
1918 that they share one address space (that is, they can all examine and
1919 modify the same variables). On the other hand, each thread has its own
1920 registers and execution stack, and perhaps private memory.
1921
1922 @value{GDBN} provides these facilities for debugging multi-thread
1923 programs:
1924
1925 @itemize @bullet
1926 @item automatic notification of new threads
1927 @item @samp{thread @var{threadno}}, a command to switch among threads
1928 @item @samp{info threads}, a command to inquire about existing threads
1929 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
1930 a command to apply a command to a list of threads
1931 @item thread-specific breakpoints
1932 @end itemize
1933
1934 @quotation
1935 @emph{Warning:} These facilities are not yet available on every
1936 @value{GDBN} configuration where the operating system supports threads.
1937 If your @value{GDBN} does not support threads, these commands have no
1938 effect. For example, a system without thread support shows no output
1939 from @samp{info threads}, and always rejects the @code{thread} command,
1940 like this:
1941
1942 @smallexample
1943 (@value{GDBP}) info threads
1944 (@value{GDBP}) thread 1
1945 Thread ID 1 not known. Use the "info threads" command to
1946 see the IDs of currently known threads.
1947 @end smallexample
1948 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
1949 @c doesn't support threads"?
1950 @end quotation
1951
1952 @cindex focus of debugging
1953 @cindex current thread
1954 The @value{GDBN} thread debugging facility allows you to observe all
1955 threads while your program runs---but whenever @value{GDBN} takes
1956 control, one thread in particular is always the focus of debugging.
1957 This thread is called the @dfn{current thread}. Debugging commands show
1958 program information from the perspective of the current thread.
1959
1960 @cindex @code{New} @var{systag} message
1961 @cindex thread identifier (system)
1962 @c FIXME-implementors!! It would be more helpful if the [New...] message
1963 @c included GDB's numeric thread handle, so you could just go to that
1964 @c thread without first checking `info threads'.
1965 Whenever @value{GDBN} detects a new thread in your program, it displays
1966 the target system's identification for the thread with a message in the
1967 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1968 whose form varies depending on the particular system. For example, on
1969 LynxOS, you might see
1970
1971 @example
1972 [New process 35 thread 27]
1973 @end example
1974
1975 @noindent
1976 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1977 the @var{systag} is simply something like @samp{process 368}, with no
1978 further qualifier.
1979
1980 @c FIXME!! (1) Does the [New...] message appear even for the very first
1981 @c thread of a program, or does it only appear for the
1982 @c second---i.e., when it becomes obvious we have a multithread
1983 @c program?
1984 @c (2) *Is* there necessarily a first thread always? Or do some
1985 @c multithread systems permit starting a program with multiple
1986 @c threads ab initio?
1987
1988 @cindex thread number
1989 @cindex thread identifier (GDB)
1990 For debugging purposes, @value{GDBN} associates its own thread
1991 number---always a single integer---with each thread in your program.
1992
1993 @table @code
1994 @kindex info threads
1995 @item info threads
1996 Display a summary of all threads currently in your
1997 program. @value{GDBN} displays for each thread (in this order):
1998
1999 @enumerate
2000 @item the thread number assigned by @value{GDBN}
2001
2002 @item the target system's thread identifier (@var{systag})
2003
2004 @item the current stack frame summary for that thread
2005 @end enumerate
2006
2007 @noindent
2008 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2009 indicates the current thread.
2010
2011 For example,
2012 @end table
2013 @c end table here to get a little more width for example
2014
2015 @smallexample
2016 (@value{GDBP}) info threads
2017 3 process 35 thread 27 0x34e5 in sigpause ()
2018 2 process 35 thread 23 0x34e5 in sigpause ()
2019 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2020 at threadtest.c:68
2021 @end smallexample
2022
2023 On HP-UX systems:
2024
2025 @cindex thread number
2026 @cindex thread identifier (GDB)
2027 For debugging purposes, @value{GDBN} associates its own thread
2028 number---a small integer assigned in thread-creation order---with each
2029 thread in your program.
2030
2031 @cindex @code{New} @var{systag} message, on HP-UX
2032 @cindex thread identifier (system), on HP-UX
2033 @c FIXME-implementors!! It would be more helpful if the [New...] message
2034 @c included GDB's numeric thread handle, so you could just go to that
2035 @c thread without first checking `info threads'.
2036 Whenever @value{GDBN} detects a new thread in your program, it displays
2037 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2038 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2039 whose form varies depending on the particular system. For example, on
2040 HP-UX, you see
2041
2042 @example
2043 [New thread 2 (system thread 26594)]
2044 @end example
2045
2046 @noindent
2047 when @value{GDBN} notices a new thread.
2048
2049 @table @code
2050 @kindex info threads
2051 @item info threads
2052 Display a summary of all threads currently in your
2053 program. @value{GDBN} displays for each thread (in this order):
2054
2055 @enumerate
2056 @item the thread number assigned by @value{GDBN}
2057
2058 @item the target system's thread identifier (@var{systag})
2059
2060 @item the current stack frame summary for that thread
2061 @end enumerate
2062
2063 @noindent
2064 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2065 indicates the current thread.
2066
2067 For example,
2068 @end table
2069 @c end table here to get a little more width for example
2070
2071 @example
2072 (@value{GDBP}) info threads
2073 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2074 at quicksort.c:137
2075 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2076 from /usr/lib/libc.2
2077 1 system thread 27905 0x7b003498 in _brk () \@*
2078 from /usr/lib/libc.2
2079 @end example
2080
2081 @table @code
2082 @kindex thread @var{threadno}
2083 @item thread @var{threadno}
2084 Make thread number @var{threadno} the current thread. The command
2085 argument @var{threadno} is the internal @value{GDBN} thread number, as
2086 shown in the first field of the @samp{info threads} display.
2087 @value{GDBN} responds by displaying the system identifier of the thread
2088 you selected, and its current stack frame summary:
2089
2090 @smallexample
2091 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2092 (@value{GDBP}) thread 2
2093 [Switching to process 35 thread 23]
2094 0x34e5 in sigpause ()
2095 @end smallexample
2096
2097 @noindent
2098 As with the @samp{[New @dots{}]} message, the form of the text after
2099 @samp{Switching to} depends on your system's conventions for identifying
2100 threads.
2101
2102 @kindex thread apply
2103 @item thread apply [@var{threadno}] [@var{all}] @var{args}
2104 The @code{thread apply} command allows you to apply a command to one or
2105 more threads. Specify the numbers of the threads that you want affected
2106 with the command argument @var{threadno}. @var{threadno} is the internal
2107 @value{GDBN} thread number, as shown in the first field of the @samp{info
2108 threads} display. To apply a command to all threads, use
2109 @code{thread apply all} @var{args}.
2110 @end table
2111
2112 @cindex automatic thread selection
2113 @cindex switching threads automatically
2114 @cindex threads, automatic switching
2115 Whenever @value{GDBN} stops your program, due to a breakpoint or a
2116 signal, it automatically selects the thread where that breakpoint or
2117 signal happened. @value{GDBN} alerts you to the context switch with a
2118 message of the form @samp{[Switching to @var{systag}]} to identify the
2119 thread.
2120
2121 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2122 more information about how @value{GDBN} behaves when you stop and start
2123 programs with multiple threads.
2124
2125 @xref{Set Watchpoints,,Setting watchpoints}, for information about
2126 watchpoints in programs with multiple threads.
2127
2128 @node Processes
2129 @section Debugging programs with multiple processes
2130
2131 @cindex fork, debugging programs which call
2132 @cindex multiple processes
2133 @cindex processes, multiple
2134 On most systems, @value{GDBN} has no special support for debugging
2135 programs which create additional processes using the @code{fork}
2136 function. When a program forks, @value{GDBN} will continue to debug the
2137 parent process and the child process will run unimpeded. If you have
2138 set a breakpoint in any code which the child then executes, the child
2139 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2140 will cause it to terminate.
2141
2142 However, if you want to debug the child process there is a workaround
2143 which isn't too painful. Put a call to @code{sleep} in the code which
2144 the child process executes after the fork. It may be useful to sleep
2145 only if a certain environment variable is set, or a certain file exists,
2146 so that the delay need not occur when you don't want to run @value{GDBN}
2147 on the child. While the child is sleeping, use the @code{ps} program to
2148 get its process ID. Then tell @value{GDBN} (a new invocation of
2149 @value{GDBN} if you are also debugging the parent process) to attach to
2150 the child process (@pxref{Attach}). From that point on you can debug
2151 the child process just like any other process which you attached to.
2152
2153 On HP-UX (11.x and later only?), @value{GDBN} provides support for
2154 debugging programs that create additional processes using the
2155 @code{fork} or @code{vfork} function.
2156
2157 By default, when a program forks, @value{GDBN} will continue to debug
2158 the parent process and the child process will run unimpeded.
2159
2160 If you want to follow the child process instead of the parent process,
2161 use the command @w{@code{set follow-fork-mode}}.
2162
2163 @table @code
2164 @kindex set follow-fork-mode
2165 @item set follow-fork-mode @var{mode}
2166 Set the debugger response to a program call of @code{fork} or
2167 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2168 process. The @var{mode} can be:
2169
2170 @table @code
2171 @item parent
2172 The original process is debugged after a fork. The child process runs
2173 unimpeded. This is the default.
2174
2175 @item child
2176 The new process is debugged after a fork. The parent process runs
2177 unimpeded.
2178
2179 @item ask
2180 The debugger will ask for one of the above choices.
2181 @end table
2182
2183 @item show follow-fork-mode
2184 Display the current debugger response to a @code{fork} or @code{vfork} call.
2185 @end table
2186
2187 If you ask to debug a child process and a @code{vfork} is followed by an
2188 @code{exec}, @value{GDBN} executes the new target up to the first
2189 breakpoint in the new target. If you have a breakpoint set on
2190 @code{main} in your original program, the breakpoint will also be set on
2191 the child process's @code{main}.
2192
2193 When a child process is spawned by @code{vfork}, you cannot debug the
2194 child or parent until an @code{exec} call completes.
2195
2196 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2197 call executes, the new target restarts. To restart the parent process,
2198 use the @code{file} command with the parent executable name as its
2199 argument.
2200
2201 You can use the @code{catch} command to make @value{GDBN} stop whenever
2202 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2203 Catchpoints, ,Setting catchpoints}.
2204
2205 @node Stopping
2206 @chapter Stopping and Continuing
2207
2208 The principal purposes of using a debugger are so that you can stop your
2209 program before it terminates; or so that, if your program runs into
2210 trouble, you can investigate and find out why.
2211
2212 Inside @value{GDBN}, your program may stop for any of several reasons,
2213 such as a signal, a breakpoint, or reaching a new line after a
2214 @value{GDBN} command such as @code{step}. You may then examine and
2215 change variables, set new breakpoints or remove old ones, and then
2216 continue execution. Usually, the messages shown by @value{GDBN} provide
2217 ample explanation of the status of your program---but you can also
2218 explicitly request this information at any time.
2219
2220 @table @code
2221 @kindex info program
2222 @item info program
2223 Display information about the status of your program: whether it is
2224 running or not, what process it is, and why it stopped.
2225 @end table
2226
2227 @menu
2228 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2229 * Continuing and Stepping:: Resuming execution
2230 * Signals:: Signals
2231 * Thread Stops:: Stopping and starting multi-thread programs
2232 @end menu
2233
2234 @node Breakpoints
2235 @section Breakpoints, watchpoints, and catchpoints
2236
2237 @cindex breakpoints
2238 A @dfn{breakpoint} makes your program stop whenever a certain point in
2239 the program is reached. For each breakpoint, you can add conditions to
2240 control in finer detail whether your program stops. You can set
2241 breakpoints with the @code{break} command and its variants (@pxref{Set
2242 Breaks, ,Setting breakpoints}), to specify the place where your program
2243 should stop by line number, function name or exact address in the
2244 program.
2245
2246 In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2247 breakpoints in shared libraries before the executable is run. There is
2248 a minor limitation on HP-UX systems: you must wait until the executable
2249 is run in order to set breakpoints in shared library routines that are
2250 not called directly by the program (for example, routines that are
2251 arguments in a @code{pthread_create} call).
2252
2253 @cindex watchpoints
2254 @cindex memory tracing
2255 @cindex breakpoint on memory address
2256 @cindex breakpoint on variable modification
2257 A @dfn{watchpoint} is a special breakpoint that stops your program
2258 when the value of an expression changes. You must use a different
2259 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2260 watchpoints}), but aside from that, you can manage a watchpoint like
2261 any other breakpoint: you enable, disable, and delete both breakpoints
2262 and watchpoints using the same commands.
2263
2264 You can arrange to have values from your program displayed automatically
2265 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2266 Automatic display}.
2267
2268 @cindex catchpoints
2269 @cindex breakpoint on events
2270 A @dfn{catchpoint} is another special breakpoint that stops your program
2271 when a certain kind of event occurs, such as the throwing of a C++
2272 exception or the loading of a library. As with watchpoints, you use a
2273 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2274 catchpoints}), but aside from that, you can manage a catchpoint like any
2275 other breakpoint. (To stop when your program receives a signal, use the
2276 @code{handle} command; see @ref{Signals, ,Signals}.)
2277
2278 @cindex breakpoint numbers
2279 @cindex numbers for breakpoints
2280 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2281 catchpoint when you create it; these numbers are successive integers
2282 starting with one. In many of the commands for controlling various
2283 features of breakpoints you use the breakpoint number to say which
2284 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2285 @dfn{disabled}; if disabled, it has no effect on your program until you
2286 enable it again.
2287
2288 @cindex breakpoint ranges
2289 @cindex ranges of breakpoints
2290 Some @value{GDBN} commands accept a range of breakpoints on which to
2291 operate. A breakpoint range is either a single breakpoint number, like
2292 @samp{5}, or two such numbers, in increasing order, separated by a
2293 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2294 all breakpoint in that range are operated on.
2295
2296 @menu
2297 * Set Breaks:: Setting breakpoints
2298 * Set Watchpoints:: Setting watchpoints
2299 * Set Catchpoints:: Setting catchpoints
2300 * Delete Breaks:: Deleting breakpoints
2301 * Disabling:: Disabling breakpoints
2302 * Conditions:: Break conditions
2303 * Break Commands:: Breakpoint command lists
2304 * Breakpoint Menus:: Breakpoint menus
2305 * Error in Breakpoints:: ``Cannot insert breakpoints''
2306 @end menu
2307
2308 @node Set Breaks
2309 @subsection Setting breakpoints
2310
2311 @c FIXME LMB what does GDB do if no code on line of breakpt?
2312 @c consider in particular declaration with/without initialization.
2313 @c
2314 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2315
2316 @kindex break
2317 @kindex b @r{(@code{break})}
2318 @vindex $bpnum@r{, convenience variable}
2319 @cindex latest breakpoint
2320 Breakpoints are set with the @code{break} command (abbreviated
2321 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2322 number of the breakpoints you've set most recently; see @ref{Convenience
2323 Vars,, Convenience variables}, for a discussion of what you can do with
2324 convenience variables.
2325
2326 You have several ways to say where the breakpoint should go.
2327
2328 @table @code
2329 @item break @var{function}
2330 Set a breakpoint at entry to function @var{function}.
2331 When using source languages that permit overloading of symbols, such as
2332 C++, @var{function} may refer to more than one possible place to break.
2333 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2334
2335 @item break +@var{offset}
2336 @itemx break -@var{offset}
2337 Set a breakpoint some number of lines forward or back from the position
2338 at which execution stopped in the currently selected @dfn{stack frame}.
2339 (@xref{Frames, ,Frames}, for a description of stack frames.)
2340
2341 @item break @var{linenum}
2342 Set a breakpoint at line @var{linenum} in the current source file.
2343 The current source file is the last file whose source text was printed.
2344 The breakpoint will stop your program just before it executes any of the
2345 code on that line.
2346
2347 @item break @var{filename}:@var{linenum}
2348 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2349
2350 @item break @var{filename}:@var{function}
2351 Set a breakpoint at entry to function @var{function} found in file
2352 @var{filename}. Specifying a file name as well as a function name is
2353 superfluous except when multiple files contain similarly named
2354 functions.
2355
2356 @item break *@var{address}
2357 Set a breakpoint at address @var{address}. You can use this to set
2358 breakpoints in parts of your program which do not have debugging
2359 information or source files.
2360
2361 @item break
2362 When called without any arguments, @code{break} sets a breakpoint at
2363 the next instruction to be executed in the selected stack frame
2364 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2365 innermost, this makes your program stop as soon as control
2366 returns to that frame. This is similar to the effect of a
2367 @code{finish} command in the frame inside the selected frame---except
2368 that @code{finish} does not leave an active breakpoint. If you use
2369 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2370 the next time it reaches the current location; this may be useful
2371 inside loops.
2372
2373 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2374 least one instruction has been executed. If it did not do this, you
2375 would be unable to proceed past a breakpoint without first disabling the
2376 breakpoint. This rule applies whether or not the breakpoint already
2377 existed when your program stopped.
2378
2379 @item break @dots{} if @var{cond}
2380 Set a breakpoint with condition @var{cond}; evaluate the expression
2381 @var{cond} each time the breakpoint is reached, and stop only if the
2382 value is nonzero---that is, if @var{cond} evaluates as true.
2383 @samp{@dots{}} stands for one of the possible arguments described
2384 above (or no argument) specifying where to break. @xref{Conditions,
2385 ,Break conditions}, for more information on breakpoint conditions.
2386
2387 @kindex tbreak
2388 @item tbreak @var{args}
2389 Set a breakpoint enabled only for one stop. @var{args} are the
2390 same as for the @code{break} command, and the breakpoint is set in the same
2391 way, but the breakpoint is automatically deleted after the first time your
2392 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2393
2394 @kindex hbreak
2395 @item hbreak @var{args}
2396 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2397 @code{break} command and the breakpoint is set in the same way, but the
2398 breakpoint requires hardware support and some target hardware may not
2399 have this support. The main purpose of this is EPROM/ROM code
2400 debugging, so you can set a breakpoint at an instruction without
2401 changing the instruction. This can be used with the new trap-generation
2402 provided by SPARClite DSU and some x86-based targets. These targets
2403 will generate traps when a program accesses some data or instruction
2404 address that is assigned to the debug registers. However the hardware
2405 breakpoint registers can take a limited number of breakpoints. For
2406 example, on the DSU, only two data breakpoints can be set at a time, and
2407 @value{GDBN} will reject this command if more than two are used. Delete
2408 or disable unused hardware breakpoints before setting new ones
2409 (@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
2410
2411 @kindex thbreak
2412 @item thbreak @var{args}
2413 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2414 are the same as for the @code{hbreak} command and the breakpoint is set in
2415 the same way. However, like the @code{tbreak} command,
2416 the breakpoint is automatically deleted after the
2417 first time your program stops there. Also, like the @code{hbreak}
2418 command, the breakpoint requires hardware support and some target hardware
2419 may not have this support. @xref{Disabling, ,Disabling breakpoints}.
2420 See also @ref{Conditions, ,Break conditions}.
2421
2422 @kindex rbreak
2423 @cindex regular expression
2424 @item rbreak @var{regex}
2425 Set breakpoints on all functions matching the regular expression
2426 @var{regex}. This command sets an unconditional breakpoint on all
2427 matches, printing a list of all breakpoints it set. Once these
2428 breakpoints are set, they are treated just like the breakpoints set with
2429 the @code{break} command. You can delete them, disable them, or make
2430 them conditional the same way as any other breakpoint.
2431
2432 The syntax of the regular expression is the standard one used with tools
2433 like @file{grep}. Note that this is different from the syntax used by
2434 shells, so for instance @code{foo*} matches all functions that include
2435 an @code{fo} followed by zero or more @code{o}s. There is an implicit
2436 @code{.*} leading and trailing the regular expression you supply, so to
2437 match only functions that begin with @code{foo}, use @code{^foo}.
2438
2439 When debugging C++ programs, @code{rbreak} is useful for setting
2440 breakpoints on overloaded functions that are not members of any special
2441 classes.
2442
2443 @kindex info breakpoints
2444 @cindex @code{$_} and @code{info breakpoints}
2445 @item info breakpoints @r{[}@var{n}@r{]}
2446 @itemx info break @r{[}@var{n}@r{]}
2447 @itemx info watchpoints @r{[}@var{n}@r{]}
2448 Print a table of all breakpoints, watchpoints, and catchpoints set and
2449 not deleted, with the following columns for each breakpoint:
2450
2451 @table @emph
2452 @item Breakpoint Numbers
2453 @item Type
2454 Breakpoint, watchpoint, or catchpoint.
2455 @item Disposition
2456 Whether the breakpoint is marked to be disabled or deleted when hit.
2457 @item Enabled or Disabled
2458 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2459 that are not enabled.
2460 @item Address
2461 Where the breakpoint is in your program, as a memory address.
2462 @item What
2463 Where the breakpoint is in the source for your program, as a file and
2464 line number.
2465 @end table
2466
2467 @noindent
2468 If a breakpoint is conditional, @code{info break} shows the condition on
2469 the line following the affected breakpoint; breakpoint commands, if any,
2470 are listed after that.
2471
2472 @noindent
2473 @code{info break} with a breakpoint
2474 number @var{n} as argument lists only that breakpoint. The
2475 convenience variable @code{$_} and the default examining-address for
2476 the @code{x} command are set to the address of the last breakpoint
2477 listed (@pxref{Memory, ,Examining memory}).
2478
2479 @noindent
2480 @code{info break} displays a count of the number of times the breakpoint
2481 has been hit. This is especially useful in conjunction with the
2482 @code{ignore} command. You can ignore a large number of breakpoint
2483 hits, look at the breakpoint info to see how many times the breakpoint
2484 was hit, and then run again, ignoring one less than that number. This
2485 will get you quickly to the last hit of that breakpoint.
2486 @end table
2487
2488 @value{GDBN} allows you to set any number of breakpoints at the same place in
2489 your program. There is nothing silly or meaningless about this. When
2490 the breakpoints are conditional, this is even useful
2491 (@pxref{Conditions, ,Break conditions}).
2492
2493 @cindex negative breakpoint numbers
2494 @cindex internal @value{GDBN} breakpoints
2495 @value{GDBN} itself sometimes sets breakpoints in your program for special
2496 purposes, such as proper handling of @code{longjmp} (in C programs).
2497 These internal breakpoints are assigned negative numbers, starting with
2498 @code{-1}; @samp{info breakpoints} does not display them.
2499
2500 You can see these breakpoints with the @value{GDBN} maintenance command
2501 @samp{maint info breakpoints}.
2502
2503 @table @code
2504 @kindex maint info breakpoints
2505 @item maint info breakpoints
2506 Using the same format as @samp{info breakpoints}, display both the
2507 breakpoints you've set explicitly, and those @value{GDBN} is using for
2508 internal purposes. Internal breakpoints are shown with negative
2509 breakpoint numbers. The type column identifies what kind of breakpoint
2510 is shown:
2511
2512 @table @code
2513 @item breakpoint
2514 Normal, explicitly set breakpoint.
2515
2516 @item watchpoint
2517 Normal, explicitly set watchpoint.
2518
2519 @item longjmp
2520 Internal breakpoint, used to handle correctly stepping through
2521 @code{longjmp} calls.
2522
2523 @item longjmp resume
2524 Internal breakpoint at the target of a @code{longjmp}.
2525
2526 @item until
2527 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2528
2529 @item finish
2530 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2531
2532 @item shlib events
2533 Shared library events.
2534
2535 @end table
2536
2537 @end table
2538
2539
2540 @node Set Watchpoints
2541 @subsection Setting watchpoints
2542
2543 @cindex setting watchpoints
2544 @cindex software watchpoints
2545 @cindex hardware watchpoints
2546 You can use a watchpoint to stop execution whenever the value of an
2547 expression changes, without having to predict a particular place where
2548 this may happen.
2549
2550 Depending on your system, watchpoints may be implemented in software or
2551 hardware. @value{GDBN} does software watchpointing by single-stepping your
2552 program and testing the variable's value each time, which is hundreds of
2553 times slower than normal execution. (But this may still be worth it, to
2554 catch errors where you have no clue what part of your program is the
2555 culprit.)
2556
2557 On some systems, such as HP-UX, Linux and some other x86-based targets,
2558 @value{GDBN} includes support for
2559 hardware watchpoints, which do not slow down the running of your
2560 program.
2561
2562 @table @code
2563 @kindex watch
2564 @item watch @var{expr}
2565 Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2566 is written into by the program and its value changes.
2567
2568 @kindex rwatch
2569 @item rwatch @var{expr}
2570 Set a watchpoint that will break when watch @var{expr} is read by the program.
2571
2572 @kindex awatch
2573 @item awatch @var{expr}
2574 Set a watchpoint that will break when @var{expr} is either read or written into
2575 by the program.
2576
2577 @kindex info watchpoints
2578 @item info watchpoints
2579 This command prints a list of watchpoints, breakpoints, and catchpoints;
2580 it is the same as @code{info break}.
2581 @end table
2582
2583 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2584 watchpoints execute very quickly, and the debugger reports a change in
2585 value at the exact instruction where the change occurs. If @value{GDBN}
2586 cannot set a hardware watchpoint, it sets a software watchpoint, which
2587 executes more slowly and reports the change in value at the next
2588 statement, not the instruction, after the change occurs.
2589
2590 When you issue the @code{watch} command, @value{GDBN} reports
2591
2592 @example
2593 Hardware watchpoint @var{num}: @var{expr}
2594 @end example
2595
2596 @noindent
2597 if it was able to set a hardware watchpoint.
2598
2599 Currently, the @code{awatch} and @code{rwatch} commands can only set
2600 hardware watchpoints, because accesses to data that don't change the
2601 value of the watched expression cannot be detected without examining
2602 every instruction as it is being executed, and @value{GDBN} does not do
2603 that currently. If @value{GDBN} finds that it is unable to set a
2604 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2605 will print a message like this:
2606
2607 @smallexample
2608 Expression cannot be implemented with read/access watchpoint.
2609 @end smallexample
2610
2611 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2612 data type of the watched expression is wider than what a hardware
2613 watchpoint on the target machine can handle. For example, some systems
2614 can only watch regions that are up to 4 bytes wide; on such systems you
2615 cannot set hardware watchpoints for an expression that yields a
2616 double-precision floating-point number (which is typically 8 bytes
2617 wide). As a work-around, it might be possible to break the large region
2618 into a series of smaller ones and watch them with separate watchpoints.
2619
2620 If you set too many hardware watchpoints, @value{GDBN} might be unable
2621 to insert all of them when you resume the execution of your program.
2622 Since the precise number of active watchpoints is unknown until such
2623 time as the program is about to be resumed, @value{GDBN} might not be
2624 able to warn you about this when you set the watchpoints, and the
2625 warning will be printed only when the program is resumed:
2626
2627 @smallexample
2628 Hardware watchpoint @var{num}: Could not insert watchpoint
2629 @end smallexample
2630
2631 @noindent
2632 If this happens, delete or disable some of the watchpoints.
2633
2634 The SPARClite DSU will generate traps when a program accesses some data
2635 or instruction address that is assigned to the debug registers. For the
2636 data addresses, DSU facilitates the @code{watch} command. However the
2637 hardware breakpoint registers can only take two data watchpoints, and
2638 both watchpoints must be the same kind. For example, you can set two
2639 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2640 @strong{or} two with @code{awatch} commands, but you cannot set one
2641 watchpoint with one command and the other with a different command.
2642 @value{GDBN} will reject the command if you try to mix watchpoints.
2643 Delete or disable unused watchpoint commands before setting new ones.
2644
2645 If you call a function interactively using @code{print} or @code{call},
2646 any watchpoints you have set will be inactive until @value{GDBN} reaches another
2647 kind of breakpoint or the call completes.
2648
2649 @value{GDBN} automatically deletes watchpoints that watch local
2650 (automatic) variables, or expressions that involve such variables, when
2651 they go out of scope, that is, when the execution leaves the block in
2652 which these variables were defined. In particular, when the program
2653 being debugged terminates, @emph{all} local variables go out of scope,
2654 and so only watchpoints that watch global variables remain set. If you
2655 rerun the program, you will need to set all such watchpoints again. One
2656 way of doing that would be to set a code breakpoint at the entry to the
2657 @code{main} function and when it breaks, set all the watchpoints.
2658
2659 @quotation
2660 @cindex watchpoints and threads
2661 @cindex threads and watchpoints
2662 @emph{Warning:} In multi-thread programs, watchpoints have only limited
2663 usefulness. With the current watchpoint implementation, @value{GDBN}
2664 can only watch the value of an expression @emph{in a single thread}. If
2665 you are confident that the expression can only change due to the current
2666 thread's activity (and if you are also confident that no other thread
2667 can become current), then you can use watchpoints as usual. However,
2668 @value{GDBN} may not notice when a non-current thread's activity changes
2669 the expression.
2670
2671 @c FIXME: this is almost identical to the previous paragraph.
2672 @emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2673 have only limited usefulness. If @value{GDBN} creates a software
2674 watchpoint, it can only watch the value of an expression @emph{in a
2675 single thread}. If you are confident that the expression can only
2676 change due to the current thread's activity (and if you are also
2677 confident that no other thread can become current), then you can use
2678 software watchpoints as usual. However, @value{GDBN} may not notice
2679 when a non-current thread's activity changes the expression. (Hardware
2680 watchpoints, in contrast, watch an expression in all threads.)
2681 @end quotation
2682
2683 @node Set Catchpoints
2684 @subsection Setting catchpoints
2685 @cindex catchpoints, setting
2686 @cindex exception handlers
2687 @cindex event handling
2688
2689 You can use @dfn{catchpoints} to cause the debugger to stop for certain
2690 kinds of program events, such as C++ exceptions or the loading of a
2691 shared library. Use the @code{catch} command to set a catchpoint.
2692
2693 @table @code
2694 @kindex catch
2695 @item catch @var{event}
2696 Stop when @var{event} occurs. @var{event} can be any of the following:
2697 @table @code
2698 @item throw
2699 @kindex catch throw
2700 The throwing of a C++ exception.
2701
2702 @item catch
2703 @kindex catch catch
2704 The catching of a C++ exception.
2705
2706 @item exec
2707 @kindex catch exec
2708 A call to @code{exec}. This is currently only available for HP-UX.
2709
2710 @item fork
2711 @kindex catch fork
2712 A call to @code{fork}. This is currently only available for HP-UX.
2713
2714 @item vfork
2715 @kindex catch vfork
2716 A call to @code{vfork}. This is currently only available for HP-UX.
2717
2718 @item load
2719 @itemx load @var{libname}
2720 @kindex catch load
2721 The dynamic loading of any shared library, or the loading of the library
2722 @var{libname}. This is currently only available for HP-UX.
2723
2724 @item unload
2725 @itemx unload @var{libname}
2726 @kindex catch unload
2727 The unloading of any dynamically loaded shared library, or the unloading
2728 of the library @var{libname}. This is currently only available for HP-UX.
2729 @end table
2730
2731 @item tcatch @var{event}
2732 Set a catchpoint that is enabled only for one stop. The catchpoint is
2733 automatically deleted after the first time the event is caught.
2734
2735 @end table
2736
2737 Use the @code{info break} command to list the current catchpoints.
2738
2739 There are currently some limitations to C++ exception handling
2740 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2741
2742 @itemize @bullet
2743 @item
2744 If you call a function interactively, @value{GDBN} normally returns
2745 control to you when the function has finished executing. If the call
2746 raises an exception, however, the call may bypass the mechanism that
2747 returns control to you and cause your program either to abort or to
2748 simply continue running until it hits a breakpoint, catches a signal
2749 that @value{GDBN} is listening for, or exits. This is the case even if
2750 you set a catchpoint for the exception; catchpoints on exceptions are
2751 disabled within interactive calls.
2752
2753 @item
2754 You cannot raise an exception interactively.
2755
2756 @item
2757 You cannot install an exception handler interactively.
2758 @end itemize
2759
2760 @cindex raise exceptions
2761 Sometimes @code{catch} is not the best way to debug exception handling:
2762 if you need to know exactly where an exception is raised, it is better to
2763 stop @emph{before} the exception handler is called, since that way you
2764 can see the stack before any unwinding takes place. If you set a
2765 breakpoint in an exception handler instead, it may not be easy to find
2766 out where the exception was raised.
2767
2768 To stop just before an exception handler is called, you need some
2769 knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2770 raised by calling a library function named @code{__raise_exception}
2771 which has the following ANSI C interface:
2772
2773 @example
2774 /* @var{addr} is where the exception identifier is stored.
2775 @var{id} is the exception identifier. */
2776 void __raise_exception (void **addr, void *id);
2777 @end example
2778
2779 @noindent
2780 To make the debugger catch all exceptions before any stack
2781 unwinding takes place, set a breakpoint on @code{__raise_exception}
2782 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2783
2784 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2785 that depends on the value of @var{id}, you can stop your program when
2786 a specific exception is raised. You can use multiple conditional
2787 breakpoints to stop your program when any of a number of exceptions are
2788 raised.
2789
2790
2791 @node Delete Breaks
2792 @subsection Deleting breakpoints
2793
2794 @cindex clearing breakpoints, watchpoints, catchpoints
2795 @cindex deleting breakpoints, watchpoints, catchpoints
2796 It is often necessary to eliminate a breakpoint, watchpoint, or
2797 catchpoint once it has done its job and you no longer want your program
2798 to stop there. This is called @dfn{deleting} the breakpoint. A
2799 breakpoint that has been deleted no longer exists; it is forgotten.
2800
2801 With the @code{clear} command you can delete breakpoints according to
2802 where they are in your program. With the @code{delete} command you can
2803 delete individual breakpoints, watchpoints, or catchpoints by specifying
2804 their breakpoint numbers.
2805
2806 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2807 automatically ignores breakpoints on the first instruction to be executed
2808 when you continue execution without changing the execution address.
2809
2810 @table @code
2811 @kindex clear
2812 @item clear
2813 Delete any breakpoints at the next instruction to be executed in the
2814 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2815 the innermost frame is selected, this is a good way to delete a
2816 breakpoint where your program just stopped.
2817
2818 @item clear @var{function}
2819 @itemx clear @var{filename}:@var{function}
2820 Delete any breakpoints set at entry to the function @var{function}.
2821
2822 @item clear @var{linenum}
2823 @itemx clear @var{filename}:@var{linenum}
2824 Delete any breakpoints set at or within the code of the specified line.
2825
2826 @cindex delete breakpoints
2827 @kindex delete
2828 @kindex d @r{(@code{delete})}
2829 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2830 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2831 ranges specified as arguments. If no argument is specified, delete all
2832 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2833 confirm off}). You can abbreviate this command as @code{d}.
2834 @end table
2835
2836 @node Disabling
2837 @subsection Disabling breakpoints
2838
2839 @kindex disable breakpoints
2840 @kindex enable breakpoints
2841 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2842 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2843 it had been deleted, but remembers the information on the breakpoint so
2844 that you can @dfn{enable} it again later.
2845
2846 You disable and enable breakpoints, watchpoints, and catchpoints with
2847 the @code{enable} and @code{disable} commands, optionally specifying one
2848 or more breakpoint numbers as arguments. Use @code{info break} or
2849 @code{info watch} to print a list of breakpoints, watchpoints, and
2850 catchpoints if you do not know which numbers to use.
2851
2852 A breakpoint, watchpoint, or catchpoint can have any of four different
2853 states of enablement:
2854
2855 @itemize @bullet
2856 @item
2857 Enabled. The breakpoint stops your program. A breakpoint set
2858 with the @code{break} command starts out in this state.
2859 @item
2860 Disabled. The breakpoint has no effect on your program.
2861 @item
2862 Enabled once. The breakpoint stops your program, but then becomes
2863 disabled.
2864 @item
2865 Enabled for deletion. The breakpoint stops your program, but
2866 immediately after it does so it is deleted permanently. A breakpoint
2867 set with the @code{tbreak} command starts out in this state.
2868 @end itemize
2869
2870 You can use the following commands to enable or disable breakpoints,
2871 watchpoints, and catchpoints:
2872
2873 @table @code
2874 @kindex disable breakpoints
2875 @kindex disable
2876 @kindex dis @r{(@code{disable})}
2877 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2878 Disable the specified breakpoints---or all breakpoints, if none are
2879 listed. A disabled breakpoint has no effect but is not forgotten. All
2880 options such as ignore-counts, conditions and commands are remembered in
2881 case the breakpoint is enabled again later. You may abbreviate
2882 @code{disable} as @code{dis}.
2883
2884 @kindex enable breakpoints
2885 @kindex enable
2886 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2887 Enable the specified breakpoints (or all defined breakpoints). They
2888 become effective once again in stopping your program.
2889
2890 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
2891 Enable the specified breakpoints temporarily. @value{GDBN} disables any
2892 of these breakpoints immediately after stopping your program.
2893
2894 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
2895 Enable the specified breakpoints to work once, then die. @value{GDBN}
2896 deletes any of these breakpoints as soon as your program stops there.
2897 @end table
2898
2899 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2900 @c confusing: tbreak is also initially enabled.
2901 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2902 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2903 subsequently, they become disabled or enabled only when you use one of
2904 the commands above. (The command @code{until} can set and delete a
2905 breakpoint of its own, but it does not change the state of your other
2906 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2907 stepping}.)
2908
2909 @node Conditions
2910 @subsection Break conditions
2911 @cindex conditional breakpoints
2912 @cindex breakpoint conditions
2913
2914 @c FIXME what is scope of break condition expr? Context where wanted?
2915 @c in particular for a watchpoint?
2916 The simplest sort of breakpoint breaks every time your program reaches a
2917 specified place. You can also specify a @dfn{condition} for a
2918 breakpoint. A condition is just a Boolean expression in your
2919 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2920 a condition evaluates the expression each time your program reaches it,
2921 and your program stops only if the condition is @emph{true}.
2922
2923 This is the converse of using assertions for program validation; in that
2924 situation, you want to stop when the assertion is violated---that is,
2925 when the condition is false. In C, if you want to test an assertion expressed
2926 by the condition @var{assert}, you should set the condition
2927 @samp{! @var{assert}} on the appropriate breakpoint.
2928
2929 Conditions are also accepted for watchpoints; you may not need them,
2930 since a watchpoint is inspecting the value of an expression anyhow---but
2931 it might be simpler, say, to just set a watchpoint on a variable name,
2932 and specify a condition that tests whether the new value is an interesting
2933 one.
2934
2935 Break conditions can have side effects, and may even call functions in
2936 your program. This can be useful, for example, to activate functions
2937 that log program progress, or to use your own print functions to
2938 format special data structures. The effects are completely predictable
2939 unless there is another enabled breakpoint at the same address. (In
2940 that case, @value{GDBN} might see the other breakpoint first and stop your
2941 program without checking the condition of this one.) Note that
2942 breakpoint commands are usually more convenient and flexible than break
2943 conditions for the
2944 purpose of performing side effects when a breakpoint is reached
2945 (@pxref{Break Commands, ,Breakpoint command lists}).
2946
2947 Break conditions can be specified when a breakpoint is set, by using
2948 @samp{if} in the arguments to the @code{break} command. @xref{Set
2949 Breaks, ,Setting breakpoints}. They can also be changed at any time
2950 with the @code{condition} command.
2951
2952 You can also use the @code{if} keyword with the @code{watch} command.
2953 The @code{catch} command does not recognize the @code{if} keyword;
2954 @code{condition} is the only way to impose a further condition on a
2955 catchpoint.
2956
2957 @table @code
2958 @kindex condition
2959 @item condition @var{bnum} @var{expression}
2960 Specify @var{expression} as the break condition for breakpoint,
2961 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2962 breakpoint @var{bnum} stops your program only if the value of
2963 @var{expression} is true (nonzero, in C). When you use
2964 @code{condition}, @value{GDBN} checks @var{expression} immediately for
2965 syntactic correctness, and to determine whether symbols in it have
2966 referents in the context of your breakpoint. If @var{expression} uses
2967 symbols not referenced in the context of the breakpoint, @value{GDBN}
2968 prints an error message:
2969
2970 @example
2971 No symbol "foo" in current context.
2972 @end example
2973
2974 @noindent
2975 @value{GDBN} does
2976 not actually evaluate @var{expression} at the time the @code{condition}
2977 command (or a command that sets a breakpoint with a condition, like
2978 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
2979
2980 @item condition @var{bnum}
2981 Remove the condition from breakpoint number @var{bnum}. It becomes
2982 an ordinary unconditional breakpoint.
2983 @end table
2984
2985 @cindex ignore count (of breakpoint)
2986 A special case of a breakpoint condition is to stop only when the
2987 breakpoint has been reached a certain number of times. This is so
2988 useful that there is a special way to do it, using the @dfn{ignore
2989 count} of the breakpoint. Every breakpoint has an ignore count, which
2990 is an integer. Most of the time, the ignore count is zero, and
2991 therefore has no effect. But if your program reaches a breakpoint whose
2992 ignore count is positive, then instead of stopping, it just decrements
2993 the ignore count by one and continues. As a result, if the ignore count
2994 value is @var{n}, the breakpoint does not stop the next @var{n} times
2995 your program reaches it.
2996
2997 @table @code
2998 @kindex ignore
2999 @item ignore @var{bnum} @var{count}
3000 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3001 The next @var{count} times the breakpoint is reached, your program's
3002 execution does not stop; other than to decrement the ignore count, @value{GDBN}
3003 takes no action.
3004
3005 To make the breakpoint stop the next time it is reached, specify
3006 a count of zero.
3007
3008 When you use @code{continue} to resume execution of your program from a
3009 breakpoint, you can specify an ignore count directly as an argument to
3010 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
3011 Stepping,,Continuing and stepping}.
3012
3013 If a breakpoint has a positive ignore count and a condition, the
3014 condition is not checked. Once the ignore count reaches zero,
3015 @value{GDBN} resumes checking the condition.
3016
3017 You could achieve the effect of the ignore count with a condition such
3018 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3019 is decremented each time. @xref{Convenience Vars, ,Convenience
3020 variables}.
3021 @end table
3022
3023 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3024
3025
3026 @node Break Commands
3027 @subsection Breakpoint command lists
3028
3029 @cindex breakpoint commands
3030 You can give any breakpoint (or watchpoint or catchpoint) a series of
3031 commands to execute when your program stops due to that breakpoint. For
3032 example, you might want to print the values of certain expressions, or
3033 enable other breakpoints.
3034
3035 @table @code
3036 @kindex commands
3037 @kindex end
3038 @item commands @r{[}@var{bnum}@r{]}
3039 @itemx @dots{} @var{command-list} @dots{}
3040 @itemx end
3041 Specify a list of commands for breakpoint number @var{bnum}. The commands
3042 themselves appear on the following lines. Type a line containing just
3043 @code{end} to terminate the commands.
3044
3045 To remove all commands from a breakpoint, type @code{commands} and
3046 follow it immediately with @code{end}; that is, give no commands.
3047
3048 With no @var{bnum} argument, @code{commands} refers to the last
3049 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3050 recently encountered).
3051 @end table
3052
3053 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3054 disabled within a @var{command-list}.
3055
3056 You can use breakpoint commands to start your program up again. Simply
3057 use the @code{continue} command, or @code{step}, or any other command
3058 that resumes execution.
3059
3060 Any other commands in the command list, after a command that resumes
3061 execution, are ignored. This is because any time you resume execution
3062 (even with a simple @code{next} or @code{step}), you may encounter
3063 another breakpoint---which could have its own command list, leading to
3064 ambiguities about which list to execute.
3065
3066 @kindex silent
3067 If the first command you specify in a command list is @code{silent}, the
3068 usual message about stopping at a breakpoint is not printed. This may
3069 be desirable for breakpoints that are to print a specific message and
3070 then continue. If none of the remaining commands print anything, you
3071 see no sign that the breakpoint was reached. @code{silent} is
3072 meaningful only at the beginning of a breakpoint command list.
3073
3074 The commands @code{echo}, @code{output}, and @code{printf} allow you to
3075 print precisely controlled output, and are often useful in silent
3076 breakpoints. @xref{Output, ,Commands for controlled output}.
3077
3078 For example, here is how you could use breakpoint commands to print the
3079 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3080
3081 @example
3082 break foo if x>0
3083 commands
3084 silent
3085 printf "x is %d\n",x
3086 cont
3087 end
3088 @end example
3089
3090 One application for breakpoint commands is to compensate for one bug so
3091 you can test for another. Put a breakpoint just after the erroneous line
3092 of code, give it a condition to detect the case in which something
3093 erroneous has been done, and give it commands to assign correct values
3094 to any variables that need them. End with the @code{continue} command
3095 so that your program does not stop, and start with the @code{silent}
3096 command so that no output is produced. Here is an example:
3097
3098 @example
3099 break 403
3100 commands
3101 silent
3102 set x = y + 4
3103 cont
3104 end
3105 @end example
3106
3107 @node Breakpoint Menus
3108 @subsection Breakpoint menus
3109 @cindex overloading
3110 @cindex symbol overloading
3111
3112 Some programming languages (notably C++) permit a single function name
3113 to be defined several times, for application in different contexts.
3114 This is called @dfn{overloading}. When a function name is overloaded,
3115 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3116 a breakpoint. If you realize this is a problem, you can use
3117 something like @samp{break @var{function}(@var{types})} to specify which
3118 particular version of the function you want. Otherwise, @value{GDBN} offers
3119 you a menu of numbered choices for different possible breakpoints, and
3120 waits for your selection with the prompt @samp{>}. The first two
3121 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3122 sets a breakpoint at each definition of @var{function}, and typing
3123 @kbd{0} aborts the @code{break} command without setting any new
3124 breakpoints.
3125
3126 For example, the following session excerpt shows an attempt to set a
3127 breakpoint at the overloaded symbol @code{String::after}.
3128 We choose three particular definitions of that function name:
3129
3130 @c FIXME! This is likely to change to show arg type lists, at least
3131 @smallexample
3132 @group
3133 (@value{GDBP}) b String::after
3134 [0] cancel
3135 [1] all
3136 [2] file:String.cc; line number:867
3137 [3] file:String.cc; line number:860
3138 [4] file:String.cc; line number:875
3139 [5] file:String.cc; line number:853
3140 [6] file:String.cc; line number:846
3141 [7] file:String.cc; line number:735
3142 > 2 4 6
3143 Breakpoint 1 at 0xb26c: file String.cc, line 867.
3144 Breakpoint 2 at 0xb344: file String.cc, line 875.
3145 Breakpoint 3 at 0xafcc: file String.cc, line 846.
3146 Multiple breakpoints were set.
3147 Use the "delete" command to delete unwanted
3148 breakpoints.
3149 (@value{GDBP})
3150 @end group
3151 @end smallexample
3152
3153 @c @ifclear BARETARGET
3154 @node Error in Breakpoints
3155 @subsection ``Cannot insert breakpoints''
3156 @c
3157 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3158 @c
3159 Under some operating systems, breakpoints cannot be used in a program if
3160 any other process is running that program. In this situation,
3161 attempting to run or continue a program with a breakpoint causes
3162 @value{GDBN} to print an error message:
3163
3164 @example
3165 Cannot insert breakpoints.
3166 The same program may be running in another process.
3167 @end example
3168
3169 When this happens, you have three ways to proceed:
3170
3171 @enumerate
3172 @item
3173 Remove or disable the breakpoints, then continue.
3174
3175 @item
3176 Suspend @value{GDBN}, and copy the file containing your program to a new
3177 name. Resume @value{GDBN} and use the @code{exec-file} command to specify
3178 that @value{GDBN} should run your program under that name.
3179 Then start your program again.
3180
3181 @item
3182 Relink your program so that the text segment is nonsharable, using the
3183 linker option @samp{-N}. The operating system limitation may not apply
3184 to nonsharable executables.
3185 @end enumerate
3186 @c @end ifclear
3187
3188 A similar message can be printed if you request too many active
3189 hardware-assisted breakpoints and watchpoints:
3190
3191 @c FIXME: the precise wording of this message may change; the relevant
3192 @c source change is not committed yet (Sep 3, 1999).
3193 @smallexample
3194 Stopped; cannot insert breakpoints.
3195 You may have requested too many hardware breakpoints and watchpoints.
3196 @end smallexample
3197
3198 @noindent
3199 This message is printed when you attempt to resume the program, since
3200 only then @value{GDBN} knows exactly how many hardware breakpoints and
3201 watchpoints it needs to insert.
3202
3203 When this message is printed, you need to disable or remove some of the
3204 hardware-assisted breakpoints and watchpoints, and then continue.
3205
3206
3207 @node Continuing and Stepping
3208 @section Continuing and stepping
3209
3210 @cindex stepping
3211 @cindex continuing
3212 @cindex resuming execution
3213 @dfn{Continuing} means resuming program execution until your program
3214 completes normally. In contrast, @dfn{stepping} means executing just
3215 one more ``step'' of your program, where ``step'' may mean either one
3216 line of source code, or one machine instruction (depending on what
3217 particular command you use). Either when continuing or when stepping,
3218 your program may stop even sooner, due to a breakpoint or a signal. (If
3219 it stops due to a signal, you may want to use @code{handle}, or use
3220 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
3221
3222 @table @code
3223 @kindex continue
3224 @kindex c @r{(@code{continue})}
3225 @kindex fg @r{(resume foreground execution)}
3226 @item continue @r{[}@var{ignore-count}@r{]}
3227 @itemx c @r{[}@var{ignore-count}@r{]}
3228 @itemx fg @r{[}@var{ignore-count}@r{]}
3229 Resume program execution, at the address where your program last stopped;
3230 any breakpoints set at that address are bypassed. The optional argument
3231 @var{ignore-count} allows you to specify a further number of times to
3232 ignore a breakpoint at this location; its effect is like that of
3233 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3234
3235 The argument @var{ignore-count} is meaningful only when your program
3236 stopped due to a breakpoint. At other times, the argument to
3237 @code{continue} is ignored.
3238
3239 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3240 debugged program is deemed to be the foreground program) are provided
3241 purely for convenience, and have exactly the same behavior as
3242 @code{continue}.
3243 @end table
3244
3245 To resume execution at a different place, you can use @code{return}
3246 (@pxref{Returning, ,Returning from a function}) to go back to the
3247 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3248 different address}) to go to an arbitrary location in your program.
3249
3250 A typical technique for using stepping is to set a breakpoint
3251 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3252 beginning of the function or the section of your program where a problem
3253 is believed to lie, run your program until it stops at that breakpoint,
3254 and then step through the suspect area, examining the variables that are
3255 interesting, until you see the problem happen.
3256
3257 @table @code
3258 @kindex step
3259 @kindex s @r{(@code{step})}
3260 @item step
3261 Continue running your program until control reaches a different source
3262 line, then stop it and return control to @value{GDBN}. This command is
3263 abbreviated @code{s}.
3264
3265 @quotation
3266 @c "without debugging information" is imprecise; actually "without line
3267 @c numbers in the debugging information". (gcc -g1 has debugging info but
3268 @c not line numbers). But it seems complex to try to make that
3269 @c distinction here.
3270 @emph{Warning:} If you use the @code{step} command while control is
3271 within a function that was compiled without debugging information,
3272 execution proceeds until control reaches a function that does have
3273 debugging information. Likewise, it will not step into a function which
3274 is compiled without debugging information. To step through functions
3275 without debugging information, use the @code{stepi} command, described
3276 below.
3277 @end quotation
3278
3279 The @code{step} command only stops at the first instruction of a
3280 source line. This prevents the multiple stops that could otherwise occur in
3281 switch statements, for loops, etc. @code{step} continues to stop if a
3282 function that has debugging information is called within the line.
3283 In other words, @code{step} @emph{steps inside} any functions called
3284 within the line.
3285
3286 Also, the @code{step} command only enters a function if there is line
3287 number information for the function. Otherwise it acts like the
3288 @code{next} command. This avoids problems when using @code{cc -gl}
3289 on MIPS machines. Previously, @code{step} entered subroutines if there
3290 was any debugging information about the routine.
3291
3292 @item step @var{count}
3293 Continue running as in @code{step}, but do so @var{count} times. If a
3294 breakpoint is reached, or a signal not related to stepping occurs before
3295 @var{count} steps, stepping stops right away.
3296
3297 @kindex next
3298 @kindex n @r{(@code{next})}
3299 @item next @r{[}@var{count}@r{]}
3300 Continue to the next source line in the current (innermost) stack frame.
3301 This is similar to @code{step}, but function calls that appear within
3302 the line of code are executed without stopping. Execution stops when
3303 control reaches a different line of code at the original stack level
3304 that was executing when you gave the @code{next} command. This command
3305 is abbreviated @code{n}.
3306
3307 An argument @var{count} is a repeat count, as for @code{step}.
3308
3309
3310 @c FIX ME!! Do we delete this, or is there a way it fits in with
3311 @c the following paragraph? --- Vctoria
3312 @c
3313 @c @code{next} within a function that lacks debugging information acts like
3314 @c @code{step}, but any function calls appearing within the code of the
3315 @c function are executed without stopping.
3316
3317 The @code{next} command only stops at the first instruction of a
3318 source line. This prevents multiple stops that could otherwise occur in
3319 switch statements, for loops, etc.
3320
3321 @kindex finish
3322 @item finish
3323 Continue running until just after function in the selected stack frame
3324 returns. Print the returned value (if any).
3325
3326 Contrast this with the @code{return} command (@pxref{Returning,
3327 ,Returning from a function}).
3328
3329 @kindex until
3330 @kindex u @r{(@code{until})}
3331 @item until
3332 @itemx u
3333 Continue running until a source line past the current line, in the
3334 current stack frame, is reached. This command is used to avoid single
3335 stepping through a loop more than once. It is like the @code{next}
3336 command, except that when @code{until} encounters a jump, it
3337 automatically continues execution until the program counter is greater
3338 than the address of the jump.
3339
3340 This means that when you reach the end of a loop after single stepping
3341 though it, @code{until} makes your program continue execution until it
3342 exits the loop. In contrast, a @code{next} command at the end of a loop
3343 simply steps back to the beginning of the loop, which forces you to step
3344 through the next iteration.
3345
3346 @code{until} always stops your program if it attempts to exit the current
3347 stack frame.
3348
3349 @code{until} may produce somewhat counterintuitive results if the order
3350 of machine code does not match the order of the source lines. For
3351 example, in the following excerpt from a debugging session, the @code{f}
3352 (@code{frame}) command shows that execution is stopped at line
3353 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3354
3355 @example
3356 (@value{GDBP}) f
3357 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3358 206 expand_input();
3359 (@value{GDBP}) until
3360 195 for ( ; argc > 0; NEXTARG) @{
3361 @end example
3362
3363 This happened because, for execution efficiency, the compiler had
3364 generated code for the loop closure test at the end, rather than the
3365 start, of the loop---even though the test in a C @code{for}-loop is
3366 written before the body of the loop. The @code{until} command appeared
3367 to step back to the beginning of the loop when it advanced to this
3368 expression; however, it has not really gone to an earlier
3369 statement---not in terms of the actual machine code.
3370
3371 @code{until} with no argument works by means of single
3372 instruction stepping, and hence is slower than @code{until} with an
3373 argument.
3374
3375 @item until @var{location}
3376 @itemx u @var{location}
3377 Continue running your program until either the specified location is
3378 reached, or the current stack frame returns. @var{location} is any of
3379 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3380 ,Setting breakpoints}). This form of the command uses breakpoints,
3381 and hence is quicker than @code{until} without an argument.
3382
3383 @kindex stepi
3384 @kindex si @r{(@code{stepi})}
3385 @item stepi
3386 @itemx stepi @var{arg}
3387 @itemx si
3388 Execute one machine instruction, then stop and return to the debugger.
3389
3390 It is often useful to do @samp{display/i $pc} when stepping by machine
3391 instructions. This makes @value{GDBN} automatically display the next
3392 instruction to be executed, each time your program stops. @xref{Auto
3393 Display,, Automatic display}.
3394
3395 An argument is a repeat count, as in @code{step}.
3396
3397 @need 750
3398 @kindex nexti
3399 @kindex ni @r{(@code{nexti})}
3400 @item nexti
3401 @itemx nexti @var{arg}
3402 @itemx ni
3403 Execute one machine instruction, but if it is a function call,
3404 proceed until the function returns.
3405
3406 An argument is a repeat count, as in @code{next}.
3407 @end table
3408
3409 @node Signals
3410 @section Signals
3411 @cindex signals
3412
3413 A signal is an asynchronous event that can happen in a program. The
3414 operating system defines the possible kinds of signals, and gives each
3415 kind a name and a number. For example, in Unix @code{SIGINT} is the
3416 signal a program gets when you type an interrupt character (often @kbd{C-c});
3417 @code{SIGSEGV} is the signal a program gets from referencing a place in
3418 memory far away from all the areas in use; @code{SIGALRM} occurs when
3419 the alarm clock timer goes off (which happens only if your program has
3420 requested an alarm).
3421
3422 @cindex fatal signals
3423 Some signals, including @code{SIGALRM}, are a normal part of the
3424 functioning of your program. Others, such as @code{SIGSEGV}, indicate
3425 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
3426 program has not specified in advance some other way to handle the signal.
3427 @code{SIGINT} does not indicate an error in your program, but it is normally
3428 fatal so it can carry out the purpose of the interrupt: to kill the program.
3429
3430 @value{GDBN} has the ability to detect any occurrence of a signal in your
3431 program. You can tell @value{GDBN} in advance what to do for each kind of
3432 signal.
3433
3434 @cindex handling signals
3435 Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3436 (so as not to interfere with their role in the functioning of your program)
3437 but to stop your program immediately whenever an error signal happens.
3438 You can change these settings with the @code{handle} command.
3439
3440 @table @code
3441 @kindex info signals
3442 @item info signals
3443 @itemx info handle
3444 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3445 handle each one. You can use this to see the signal numbers of all
3446 the defined types of signals.
3447
3448 @code{info handle} is an alias for @code{info signals}.
3449
3450 @kindex handle
3451 @item handle @var{signal} @var{keywords}@dots{}
3452 Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
3453 be the number of a signal or its name (with or without the @samp{SIG} at the
3454 beginning). The @var{keywords} say what change to make.
3455 @end table
3456
3457 @c @group
3458 The keywords allowed by the @code{handle} command can be abbreviated.
3459 Their full names are:
3460
3461 @table @code
3462 @item nostop
3463 @value{GDBN} should not stop your program when this signal happens. It may
3464 still print a message telling you that the signal has come in.
3465
3466 @item stop
3467 @value{GDBN} should stop your program when this signal happens. This implies
3468 the @code{print} keyword as well.
3469
3470 @item print
3471 @value{GDBN} should print a message when this signal happens.
3472
3473 @item noprint
3474 @value{GDBN} should not mention the occurrence of the signal at all. This
3475 implies the @code{nostop} keyword as well.
3476
3477 @item pass
3478 @value{GDBN} should allow your program to see this signal; your program
3479 can handle the signal, or else it may terminate if the signal is fatal
3480 and not handled.
3481
3482 @item nopass
3483 @value{GDBN} should not allow your program to see this signal.
3484 @end table
3485 @c @end group
3486
3487 When a signal stops your program, the signal is not visible to the
3488 program until you
3489 continue. Your program sees the signal then, if @code{pass} is in
3490 effect for the signal in question @emph{at that time}. In other words,
3491 after @value{GDBN} reports a signal, you can use the @code{handle}
3492 command with @code{pass} or @code{nopass} to control whether your
3493 program sees that signal when you continue.
3494
3495 You can also use the @code{signal} command to prevent your program from
3496 seeing a signal, or cause it to see a signal it normally would not see,
3497 or to give it any signal at any time. For example, if your program stopped
3498 due to some sort of memory reference error, you might store correct
3499 values into the erroneous variables and continue, hoping to see more
3500 execution; but your program would probably terminate immediately as
3501 a result of the fatal signal once it saw the signal. To prevent this,
3502 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3503 program a signal}.
3504
3505 @node Thread Stops
3506 @section Stopping and starting multi-thread programs
3507
3508 When your program has multiple threads (@pxref{Threads,, Debugging
3509 programs with multiple threads}), you can choose whether to set
3510 breakpoints on all threads, or on a particular thread.
3511
3512 @table @code
3513 @cindex breakpoints and threads
3514 @cindex thread breakpoints
3515 @kindex break @dots{} thread @var{threadno}
3516 @item break @var{linespec} thread @var{threadno}
3517 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3518 @var{linespec} specifies source lines; there are several ways of
3519 writing them, but the effect is always to specify some source line.
3520
3521 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3522 to specify that you only want @value{GDBN} to stop the program when a
3523 particular thread reaches this breakpoint. @var{threadno} is one of the
3524 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3525 column of the @samp{info threads} display.
3526
3527 If you do not specify @samp{thread @var{threadno}} when you set a
3528 breakpoint, the breakpoint applies to @emph{all} threads of your
3529 program.
3530
3531 You can use the @code{thread} qualifier on conditional breakpoints as
3532 well; in this case, place @samp{thread @var{threadno}} before the
3533 breakpoint condition, like this:
3534
3535 @smallexample
3536 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
3537 @end smallexample
3538
3539 @end table
3540
3541 @cindex stopped threads
3542 @cindex threads, stopped
3543 Whenever your program stops under @value{GDBN} for any reason,
3544 @emph{all} threads of execution stop, not just the current thread. This
3545 allows you to examine the overall state of the program, including
3546 switching between threads, without worrying that things may change
3547 underfoot.
3548
3549 @cindex continuing threads
3550 @cindex threads, continuing
3551 Conversely, whenever you restart the program, @emph{all} threads start
3552 executing. @emph{This is true even when single-stepping} with commands
3553 like @code{step} or @code{next}.
3554
3555 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3556 Since thread scheduling is up to your debugging target's operating
3557 system (not controlled by @value{GDBN}), other threads may
3558 execute more than one statement while the current thread completes a
3559 single step. Moreover, in general other threads stop in the middle of a
3560 statement, rather than at a clean statement boundary, when the program
3561 stops.
3562
3563 You might even find your program stopped in another thread after
3564 continuing or even single-stepping. This happens whenever some other
3565 thread runs into a breakpoint, a signal, or an exception before the
3566 first thread completes whatever you requested.
3567
3568 On some OSes, you can lock the OS scheduler and thus allow only a single
3569 thread to run.
3570
3571 @table @code
3572 @item set scheduler-locking @var{mode}
3573 Set the scheduler locking mode. If it is @code{off}, then there is no
3574 locking and any thread may run at any time. If @code{on}, then only the
3575 current thread may run when the inferior is resumed. The @code{step}
3576 mode optimizes for single-stepping. It stops other threads from
3577 ``seizing the prompt'' by preempting the current thread while you are
3578 stepping. Other threads will only rarely (or never) get a chance to run
3579 when you step. They are more likely to run when you @samp{next} over a
3580 function call, and they are completely free to run when you use commands
3581 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
3582 thread hits a breakpoint during its timeslice, they will never steal the
3583 @value{GDBN} prompt away from the thread that you are debugging.
3584
3585 @item show scheduler-locking
3586 Display the current scheduler locking mode.
3587 @end table
3588
3589
3590 @node Stack
3591 @chapter Examining the Stack
3592
3593 When your program has stopped, the first thing you need to know is where it
3594 stopped and how it got there.
3595
3596 @cindex call stack
3597 Each time your program performs a function call, information about the call
3598 is generated.
3599 That information includes the location of the call in your program,
3600 the arguments of the call,
3601 and the local variables of the function being called.
3602 The information is saved in a block of data called a @dfn{stack frame}.
3603 The stack frames are allocated in a region of memory called the @dfn{call
3604 stack}.
3605
3606 When your program stops, the @value{GDBN} commands for examining the
3607 stack allow you to see all of this information.
3608
3609 @cindex selected frame
3610 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3611 @value{GDBN} commands refer implicitly to the selected frame. In
3612 particular, whenever you ask @value{GDBN} for the value of a variable in
3613 your program, the value is found in the selected frame. There are
3614 special @value{GDBN} commands to select whichever frame you are
3615 interested in. @xref{Selection, ,Selecting a frame}.
3616
3617 When your program stops, @value{GDBN} automatically selects the
3618 currently executing frame and describes it briefly, similar to the
3619 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3620
3621 @menu
3622 * Frames:: Stack frames
3623 * Backtrace:: Backtraces
3624 * Selection:: Selecting a frame
3625 * Frame Info:: Information on a frame
3626
3627 @end menu
3628
3629 @node Frames
3630 @section Stack frames
3631
3632 @cindex frame, definition
3633 @cindex stack frame
3634 The call stack is divided up into contiguous pieces called @dfn{stack
3635 frames}, or @dfn{frames} for short; each frame is the data associated
3636 with one call to one function. The frame contains the arguments given
3637 to the function, the function's local variables, and the address at
3638 which the function is executing.
3639
3640 @cindex initial frame
3641 @cindex outermost frame
3642 @cindex innermost frame
3643 When your program is started, the stack has only one frame, that of the
3644 function @code{main}. This is called the @dfn{initial} frame or the
3645 @dfn{outermost} frame. Each time a function is called, a new frame is
3646 made. Each time a function returns, the frame for that function invocation
3647 is eliminated. If a function is recursive, there can be many frames for
3648 the same function. The frame for the function in which execution is
3649 actually occurring is called the @dfn{innermost} frame. This is the most
3650 recently created of all the stack frames that still exist.
3651
3652 @cindex frame pointer
3653 Inside your program, stack frames are identified by their addresses. A
3654 stack frame consists of many bytes, each of which has its own address; each
3655 kind of computer has a convention for choosing one byte whose
3656 address serves as the address of the frame. Usually this address is kept
3657 in a register called the @dfn{frame pointer register} while execution is
3658 going on in that frame.
3659
3660 @cindex frame number
3661 @value{GDBN} assigns numbers to all existing stack frames, starting with
3662 zero for the innermost frame, one for the frame that called it,
3663 and so on upward. These numbers do not really exist in your program;
3664 they are assigned by @value{GDBN} to give you a way of designating stack
3665 frames in @value{GDBN} commands.
3666
3667 @c The -fomit-frame-pointer below perennially causes hbox overflow
3668 @c underflow problems.
3669 @cindex frameless execution
3670 Some compilers provide a way to compile functions so that they operate
3671 without stack frames. (For example, the @value{GCC} option
3672 @example
3673 @samp{-fomit-frame-pointer}
3674 @end example
3675 generates functions without a frame.)
3676 This is occasionally done with heavily used library functions to save
3677 the frame setup time. @value{GDBN} has limited facilities for dealing
3678 with these function invocations. If the innermost function invocation
3679 has no stack frame, @value{GDBN} nevertheless regards it as though
3680 it had a separate frame, which is numbered zero as usual, allowing
3681 correct tracing of the function call chain. However, @value{GDBN} has
3682 no provision for frameless functions elsewhere in the stack.
3683
3684 @table @code
3685 @kindex frame@r{, command}
3686 @cindex current stack frame
3687 @item frame @var{args}
3688 The @code{frame} command allows you to move from one stack frame to another,
3689 and to print the stack frame you select. @var{args} may be either the
3690 address of the frame or the stack frame number. Without an argument,
3691 @code{frame} prints the current stack frame.
3692
3693 @kindex select-frame
3694 @cindex selecting frame silently
3695 @item select-frame
3696 The @code{select-frame} command allows you to move from one stack frame
3697 to another without printing the frame. This is the silent version of
3698 @code{frame}.
3699 @end table
3700
3701 @node Backtrace
3702 @section Backtraces
3703
3704 @cindex backtraces
3705 @cindex tracebacks
3706 @cindex stack traces
3707 A backtrace is a summary of how your program got where it is. It shows one
3708 line per frame, for many frames, starting with the currently executing
3709 frame (frame zero), followed by its caller (frame one), and on up the
3710 stack.
3711
3712 @table @code
3713 @kindex backtrace
3714 @kindex bt @r{(@code{backtrace})}
3715 @item backtrace
3716 @itemx bt
3717 Print a backtrace of the entire stack: one line per frame for all
3718 frames in the stack.
3719
3720 You can stop the backtrace at any time by typing the system interrupt
3721 character, normally @kbd{C-c}.
3722
3723 @item backtrace @var{n}
3724 @itemx bt @var{n}
3725 Similar, but print only the innermost @var{n} frames.
3726
3727 @item backtrace -@var{n}
3728 @itemx bt -@var{n}
3729 Similar, but print only the outermost @var{n} frames.
3730 @end table
3731
3732 @kindex where
3733 @kindex info stack
3734 @kindex info s @r{(@code{info stack})}
3735 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3736 are additional aliases for @code{backtrace}.
3737
3738 Each line in the backtrace shows the frame number and the function name.
3739 The program counter value is also shown---unless you use @code{set
3740 print address off}. The backtrace also shows the source file name and
3741 line number, as well as the arguments to the function. The program
3742 counter value is omitted if it is at the beginning of the code for that
3743 line number.
3744
3745 Here is an example of a backtrace. It was made with the command
3746 @samp{bt 3}, so it shows the innermost three frames.
3747
3748 @smallexample
3749 @group
3750 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3751 at builtin.c:993
3752 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3753 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3754 at macro.c:71
3755 (More stack frames follow...)
3756 @end group
3757 @end smallexample
3758
3759 @noindent
3760 The display for frame zero does not begin with a program counter
3761 value, indicating that your program has stopped at the beginning of the
3762 code for line @code{993} of @code{builtin.c}.
3763
3764 @node Selection
3765 @section Selecting a frame
3766
3767 Most commands for examining the stack and other data in your program work on
3768 whichever stack frame is selected at the moment. Here are the commands for
3769 selecting a stack frame; all of them finish by printing a brief description
3770 of the stack frame just selected.
3771
3772 @table @code
3773 @kindex frame@r{, selecting}
3774 @kindex f @r{(@code{frame})}
3775 @item frame @var{n}
3776 @itemx f @var{n}
3777 Select frame number @var{n}. Recall that frame zero is the innermost
3778 (currently executing) frame, frame one is the frame that called the
3779 innermost one, and so on. The highest-numbered frame is the one for
3780 @code{main}.
3781
3782 @item frame @var{addr}
3783 @itemx f @var{addr}
3784 Select the frame at address @var{addr}. This is useful mainly if the
3785 chaining of stack frames has been damaged by a bug, making it
3786 impossible for @value{GDBN} to assign numbers properly to all frames. In
3787 addition, this can be useful when your program has multiple stacks and
3788 switches between them.
3789
3790 On the SPARC architecture, @code{frame} needs two addresses to
3791 select an arbitrary frame: a frame pointer and a stack pointer.
3792
3793 On the MIPS and Alpha architecture, it needs two addresses: a stack
3794 pointer and a program counter.
3795
3796 On the 29k architecture, it needs three addresses: a register stack
3797 pointer, a program counter, and a memory stack pointer.
3798 @c note to future updaters: this is conditioned on a flag
3799 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3800 @c as of 27 Jan 1994.
3801
3802 @kindex up
3803 @item up @var{n}
3804 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3805 advances toward the outermost frame, to higher frame numbers, to frames
3806 that have existed longer. @var{n} defaults to one.
3807
3808 @kindex down
3809 @kindex do @r{(@code{down})}
3810 @item down @var{n}
3811 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3812 advances toward the innermost frame, to lower frame numbers, to frames
3813 that were created more recently. @var{n} defaults to one. You may
3814 abbreviate @code{down} as @code{do}.
3815 @end table
3816
3817 All of these commands end by printing two lines of output describing the
3818 frame. The first line shows the frame number, the function name, the
3819 arguments, and the source file and line number of execution in that
3820 frame. The second line shows the text of that source line.
3821
3822 @need 1000
3823 For example:
3824
3825 @smallexample
3826 @group
3827 (@value{GDBP}) up
3828 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3829 at env.c:10
3830 10 read_input_file (argv[i]);
3831 @end group
3832 @end smallexample
3833
3834 After such a printout, the @code{list} command with no arguments
3835 prints ten lines centered on the point of execution in the frame.
3836 @xref{List, ,Printing source lines}.
3837
3838 @table @code
3839 @kindex down-silently
3840 @kindex up-silently
3841 @item up-silently @var{n}
3842 @itemx down-silently @var{n}
3843 These two commands are variants of @code{up} and @code{down},
3844 respectively; they differ in that they do their work silently, without
3845 causing display of the new frame. They are intended primarily for use
3846 in @value{GDBN} command scripts, where the output might be unnecessary and
3847 distracting.
3848 @end table
3849
3850 @node Frame Info
3851 @section Information about a frame
3852
3853 There are several other commands to print information about the selected
3854 stack frame.
3855
3856 @table @code
3857 @item frame
3858 @itemx f
3859 When used without any argument, this command does not change which
3860 frame is selected, but prints a brief description of the currently
3861 selected stack frame. It can be abbreviated @code{f}. With an
3862 argument, this command is used to select a stack frame.
3863 @xref{Selection, ,Selecting a frame}.
3864
3865 @kindex info frame
3866 @kindex info f @r{(@code{info frame})}
3867 @item info frame
3868 @itemx info f
3869 This command prints a verbose description of the selected stack frame,
3870 including:
3871
3872 @itemize @bullet
3873 @item
3874 the address of the frame
3875 @item
3876 the address of the next frame down (called by this frame)
3877 @item
3878 the address of the next frame up (caller of this frame)
3879 @item
3880 the language in which the source code corresponding to this frame is written
3881 @item
3882 the address of the frame's arguments
3883 @item
3884 the address of the frame's local variables
3885 @item
3886 the program counter saved in it (the address of execution in the caller frame)
3887 @item
3888 which registers were saved in the frame
3889 @end itemize
3890
3891 @noindent The verbose description is useful when
3892 something has gone wrong that has made the stack format fail to fit
3893 the usual conventions.
3894
3895 @item info frame @var{addr}
3896 @itemx info f @var{addr}
3897 Print a verbose description of the frame at address @var{addr}, without
3898 selecting that frame. The selected frame remains unchanged by this
3899 command. This requires the same kind of address (more than one for some
3900 architectures) that you specify in the @code{frame} command.
3901 @xref{Selection, ,Selecting a frame}.
3902
3903 @kindex info args
3904 @item info args
3905 Print the arguments of the selected frame, each on a separate line.
3906
3907 @item info locals
3908 @kindex info locals
3909 Print the local variables of the selected frame, each on a separate
3910 line. These are all variables (declared either static or automatic)
3911 accessible at the point of execution of the selected frame.
3912
3913 @kindex info catch
3914 @cindex catch exceptions, list active handlers
3915 @cindex exception handlers, how to list
3916 @item info catch
3917 Print a list of all the exception handlers that are active in the
3918 current stack frame at the current point of execution. To see other
3919 exception handlers, visit the associated frame (using the @code{up},
3920 @code{down}, or @code{frame} commands); then type @code{info catch}.
3921 @xref{Set Catchpoints, , Setting catchpoints}.
3922
3923 @end table
3924
3925
3926 @node Source
3927 @chapter Examining Source Files
3928
3929 @value{GDBN} can print parts of your program's source, since the debugging
3930 information recorded in the program tells @value{GDBN} what source files were
3931 used to build it. When your program stops, @value{GDBN} spontaneously prints
3932 the line where it stopped. Likewise, when you select a stack frame
3933 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3934 execution in that frame has stopped. You can print other portions of
3935 source files by explicit command.
3936
3937 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
3938 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
3939 @value{GDBN} under @sc{gnu} Emacs}.
3940
3941 @menu
3942 * List:: Printing source lines
3943 * Search:: Searching source files
3944 * Source Path:: Specifying source directories
3945 * Machine Code:: Source and machine code
3946 @end menu
3947
3948 @node List
3949 @section Printing source lines
3950
3951 @kindex list
3952 @kindex l @r{(@code{list})}
3953 To print lines from a source file, use the @code{list} command
3954 (abbreviated @code{l}). By default, ten lines are printed.
3955 There are several ways to specify what part of the file you want to print.
3956
3957 Here are the forms of the @code{list} command most commonly used:
3958
3959 @table @code
3960 @item list @var{linenum}
3961 Print lines centered around line number @var{linenum} in the
3962 current source file.
3963
3964 @item list @var{function}
3965 Print lines centered around the beginning of function
3966 @var{function}.
3967
3968 @item list
3969 Print more lines. If the last lines printed were printed with a
3970 @code{list} command, this prints lines following the last lines
3971 printed; however, if the last line printed was a solitary line printed
3972 as part of displaying a stack frame (@pxref{Stack, ,Examining the
3973 Stack}), this prints lines centered around that line.
3974
3975 @item list -
3976 Print lines just before the lines last printed.
3977 @end table
3978
3979 By default, @value{GDBN} prints ten source lines with any of these forms of
3980 the @code{list} command. You can change this using @code{set listsize}:
3981
3982 @table @code
3983 @kindex set listsize
3984 @item set listsize @var{count}
3985 Make the @code{list} command display @var{count} source lines (unless
3986 the @code{list} argument explicitly specifies some other number).
3987
3988 @kindex show listsize
3989 @item show listsize
3990 Display the number of lines that @code{list} prints.
3991 @end table
3992
3993 Repeating a @code{list} command with @key{RET} discards the argument,
3994 so it is equivalent to typing just @code{list}. This is more useful
3995 than listing the same lines again. An exception is made for an
3996 argument of @samp{-}; that argument is preserved in repetition so that
3997 each repetition moves up in the source file.
3998
3999 @cindex linespec
4000 In general, the @code{list} command expects you to supply zero, one or two
4001 @dfn{linespecs}. Linespecs specify source lines; there are several ways
4002 of writing them, but the effect is always to specify some source line.
4003 Here is a complete description of the possible arguments for @code{list}:
4004
4005 @table @code
4006 @item list @var{linespec}
4007 Print lines centered around the line specified by @var{linespec}.
4008
4009 @item list @var{first},@var{last}
4010 Print lines from @var{first} to @var{last}. Both arguments are
4011 linespecs.
4012
4013 @item list ,@var{last}
4014 Print lines ending with @var{last}.
4015
4016 @item list @var{first},
4017 Print lines starting with @var{first}.
4018
4019 @item list +
4020 Print lines just after the lines last printed.
4021
4022 @item list -
4023 Print lines just before the lines last printed.
4024
4025 @item list
4026 As described in the preceding table.
4027 @end table
4028
4029 Here are the ways of specifying a single source line---all the
4030 kinds of linespec.
4031
4032 @table @code
4033 @item @var{number}
4034 Specifies line @var{number} of the current source file.
4035 When a @code{list} command has two linespecs, this refers to
4036 the same source file as the first linespec.
4037
4038 @item +@var{offset}
4039 Specifies the line @var{offset} lines after the last line printed.
4040 When used as the second linespec in a @code{list} command that has
4041 two, this specifies the line @var{offset} lines down from the
4042 first linespec.
4043
4044 @item -@var{offset}
4045 Specifies the line @var{offset} lines before the last line printed.
4046
4047 @item @var{filename}:@var{number}
4048 Specifies line @var{number} in the source file @var{filename}.
4049
4050 @item @var{function}
4051 Specifies the line that begins the body of the function @var{function}.
4052 For example: in C, this is the line with the open brace.
4053
4054 @item @var{filename}:@var{function}
4055 Specifies the line of the open-brace that begins the body of the
4056 function @var{function} in the file @var{filename}. You only need the
4057 file name with a function name to avoid ambiguity when there are
4058 identically named functions in different source files.
4059
4060 @item *@var{address}
4061 Specifies the line containing the program address @var{address}.
4062 @var{address} may be any expression.
4063 @end table
4064
4065 @node Search
4066 @section Searching source files
4067 @cindex searching
4068 @kindex reverse-search
4069
4070 There are two commands for searching through the current source file for a
4071 regular expression.
4072
4073 @table @code
4074 @kindex search
4075 @kindex forward-search
4076 @item forward-search @var{regexp}
4077 @itemx search @var{regexp}
4078 The command @samp{forward-search @var{regexp}} checks each line,
4079 starting with the one following the last line listed, for a match for
4080 @var{regexp}. It lists the line that is found. You can use the
4081 synonym @samp{search @var{regexp}} or abbreviate the command name as
4082 @code{fo}.
4083
4084 @item reverse-search @var{regexp}
4085 The command @samp{reverse-search @var{regexp}} checks each line, starting
4086 with the one before the last line listed and going backward, for a match
4087 for @var{regexp}. It lists the line that is found. You can abbreviate
4088 this command as @code{rev}.
4089 @end table
4090
4091 @node Source Path
4092 @section Specifying source directories
4093
4094 @cindex source path
4095 @cindex directories for source files
4096 Executable programs sometimes do not record the directories of the source
4097 files from which they were compiled, just the names. Even when they do,
4098 the directories could be moved between the compilation and your debugging
4099 session. @value{GDBN} has a list of directories to search for source files;
4100 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4101 it tries all the directories in the list, in the order they are present
4102 in the list, until it finds a file with the desired name. Note that
4103 the executable search path is @emph{not} used for this purpose. Neither is
4104 the current working directory, unless it happens to be in the source
4105 path.
4106
4107 If @value{GDBN} cannot find a source file in the source path, and the
4108 object program records a directory, @value{GDBN} tries that directory
4109 too. If the source path is empty, and there is no record of the
4110 compilation directory, @value{GDBN} looks in the current directory as a
4111 last resort.
4112
4113 Whenever you reset or rearrange the source path, @value{GDBN} clears out
4114 any information it has cached about where source files are found and where
4115 each line is in the file.
4116
4117 @kindex directory
4118 @kindex dir
4119 When you start @value{GDBN}, its source path includes only @samp{cdir}
4120 and @samp{cwd}, in that order.
4121 To add other directories, use the @code{directory} command.
4122
4123 @table @code
4124 @item directory @var{dirname} @dots{}
4125 @item dir @var{dirname} @dots{}
4126 Add directory @var{dirname} to the front of the source path. Several
4127 directory names may be given to this command, separated by @samp{:}
4128 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4129 part of absolute file names) or
4130 whitespace. You may specify a directory that is already in the source
4131 path; this moves it forward, so @value{GDBN} searches it sooner.
4132
4133 @kindex cdir
4134 @kindex cwd
4135 @vindex $cdir@r{, convenience variable}
4136 @vindex $cwdr@r{, convenience variable}
4137 @cindex compilation directory
4138 @cindex current directory
4139 @cindex working directory
4140 @cindex directory, current
4141 @cindex directory, compilation
4142 You can use the string @samp{$cdir} to refer to the compilation
4143 directory (if one is recorded), and @samp{$cwd} to refer to the current
4144 working directory. @samp{$cwd} is not the same as @samp{.}---the former
4145 tracks the current working directory as it changes during your @value{GDBN}
4146 session, while the latter is immediately expanded to the current
4147 directory at the time you add an entry to the source path.
4148
4149 @item directory
4150 Reset the source path to empty again. This requires confirmation.
4151
4152 @c RET-repeat for @code{directory} is explicitly disabled, but since
4153 @c repeating it would be a no-op we do not say that. (thanks to RMS)
4154
4155 @item show directories
4156 @kindex show directories
4157 Print the source path: show which directories it contains.
4158 @end table
4159
4160 If your source path is cluttered with directories that are no longer of
4161 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4162 versions of source. You can correct the situation as follows:
4163
4164 @enumerate
4165 @item
4166 Use @code{directory} with no argument to reset the source path to empty.
4167
4168 @item
4169 Use @code{directory} with suitable arguments to reinstall the
4170 directories you want in the source path. You can add all the
4171 directories in one command.
4172 @end enumerate
4173
4174 @node Machine Code
4175 @section Source and machine code
4176
4177 You can use the command @code{info line} to map source lines to program
4178 addresses (and vice versa), and the command @code{disassemble} to display
4179 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
4180 mode, the @code{info line} command causes the arrow to point to the
4181 line specified. Also, @code{info line} prints addresses in symbolic form as
4182 well as hex.
4183
4184 @table @code
4185 @kindex info line
4186 @item info line @var{linespec}
4187 Print the starting and ending addresses of the compiled code for
4188 source line @var{linespec}. You can specify source lines in any of
4189 the ways understood by the @code{list} command (@pxref{List, ,Printing
4190 source lines}).
4191 @end table
4192
4193 For example, we can use @code{info line} to discover the location of
4194 the object code for the first line of function
4195 @code{m4_changequote}:
4196
4197 @c FIXME: I think this example should also show the addresses in
4198 @c symbolic form, as they usually would be displayed.
4199 @smallexample
4200 (@value{GDBP}) info line m4_changequote
4201 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4202 @end smallexample
4203
4204 @noindent
4205 We can also inquire (using @code{*@var{addr}} as the form for
4206 @var{linespec}) what source line covers a particular address:
4207 @smallexample
4208 (@value{GDBP}) info line *0x63ff
4209 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4210 @end smallexample
4211
4212 @cindex @code{$_} and @code{info line}
4213 @kindex x@r{(examine), and} info line
4214 After @code{info line}, the default address for the @code{x} command
4215 is changed to the starting address of the line, so that @samp{x/i} is
4216 sufficient to begin examining the machine code (@pxref{Memory,
4217 ,Examining memory}). Also, this address is saved as the value of the
4218 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4219 variables}).
4220
4221 @table @code
4222 @kindex disassemble
4223 @cindex assembly instructions
4224 @cindex instructions, assembly
4225 @cindex machine instructions
4226 @cindex listing machine instructions
4227 @item disassemble
4228 This specialized command dumps a range of memory as machine
4229 instructions. The default memory range is the function surrounding the
4230 program counter of the selected frame. A single argument to this
4231 command is a program counter value; @value{GDBN} dumps the function
4232 surrounding this value. Two arguments specify a range of addresses
4233 (first inclusive, second exclusive) to dump.
4234 @end table
4235
4236 The following example shows the disassembly of a range of addresses of
4237 HP PA-RISC 2.0 code:
4238
4239 @smallexample
4240 (@value{GDBP}) disas 0x32c4 0x32e4
4241 Dump of assembler code from 0x32c4 to 0x32e4:
4242 0x32c4 <main+204>: addil 0,dp
4243 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
4244 0x32cc <main+212>: ldil 0x3000,r31
4245 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
4246 0x32d4 <main+220>: ldo 0(r31),rp
4247 0x32d8 <main+224>: addil -0x800,dp
4248 0x32dc <main+228>: ldo 0x588(r1),r26
4249 0x32e0 <main+232>: ldil 0x3000,r31
4250 End of assembler dump.
4251 @end smallexample
4252
4253 Some architectures have more than one commonly-used set of instruction
4254 mnemonics or other syntax.
4255
4256 @table @code
4257 @kindex set disassembly-flavor
4258 @cindex assembly instructions
4259 @cindex instructions, assembly
4260 @cindex machine instructions
4261 @cindex listing machine instructions
4262 @cindex Intel disassembly flavor
4263 @cindex AT&T disassembly flavor
4264 @item set disassembly-flavor @var{instruction-set}
4265 Select the instruction set to use when disassembling the
4266 program via the @code{disassemble} or @code{x/i} commands.
4267
4268 Currently this command is only defined for the Intel x86 family. You
4269 can set @var{instruction-set} to either @code{intel} or @code{att}.
4270 The default is @code{att}, the AT&T flavor used by default by Unix
4271 assemblers for x86-based targets.
4272 @end table
4273
4274
4275 @node Data
4276 @chapter Examining Data
4277
4278 @cindex printing data
4279 @cindex examining data
4280 @kindex print
4281 @kindex inspect
4282 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
4283 @c document because it is nonstandard... Under Epoch it displays in a
4284 @c different window or something like that.
4285 The usual way to examine data in your program is with the @code{print}
4286 command (abbreviated @code{p}), or its synonym @code{inspect}. It
4287 evaluates and prints the value of an expression of the language your
4288 program is written in (@pxref{Languages, ,Using @value{GDBN} with
4289 Different Languages}).
4290
4291 @table @code
4292 @item print @var{expr}
4293 @itemx print /@var{f} @var{expr}
4294 @var{expr} is an expression (in the source language). By default the
4295 value of @var{expr} is printed in a format appropriate to its data type;
4296 you can choose a different format by specifying @samp{/@var{f}}, where
4297 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
4298 formats}.
4299
4300 @item print
4301 @itemx print /@var{f}
4302 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
4303 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4304 conveniently inspect the same value in an alternative format.
4305 @end table
4306
4307 A more low-level way of examining data is with the @code{x} command.
4308 It examines data in memory at a specified address and prints it in a
4309 specified format. @xref{Memory, ,Examining memory}.
4310
4311 If you are interested in information about types, or about how the
4312 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4313 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
4314 Table}.
4315
4316 @menu
4317 * Expressions:: Expressions
4318 * Variables:: Program variables
4319 * Arrays:: Artificial arrays
4320 * Output Formats:: Output formats
4321 * Memory:: Examining memory
4322 * Auto Display:: Automatic display
4323 * Print Settings:: Print settings
4324 * Value History:: Value history
4325 * Convenience Vars:: Convenience variables
4326 * Registers:: Registers
4327 * Floating Point Hardware:: Floating point hardware
4328 @end menu
4329
4330 @node Expressions
4331 @section Expressions
4332
4333 @cindex expressions
4334 @code{print} and many other @value{GDBN} commands accept an expression and
4335 compute its value. Any kind of constant, variable or operator defined
4336 by the programming language you are using is valid in an expression in
4337 @value{GDBN}. This includes conditional expressions, function calls, casts
4338 and string constants. It unfortunately does not include symbols defined
4339 by preprocessor @code{#define} commands.
4340
4341 @value{GDBN} supports array constants in expressions input by
4342 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
4343 you can use the command @code{print @{1, 2, 3@}} to build up an array in
4344 memory that is @code{malloc}ed in the target program.
4345
4346 Because C is so widespread, most of the expressions shown in examples in
4347 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4348 Languages}, for information on how to use expressions in other
4349 languages.
4350
4351 In this section, we discuss operators that you can use in @value{GDBN}
4352 expressions regardless of your programming language.
4353
4354 Casts are supported in all languages, not just in C, because it is so
4355 useful to cast a number into a pointer in order to examine a structure
4356 at that address in memory.
4357 @c FIXME: casts supported---Mod2 true?
4358
4359 @value{GDBN} supports these operators, in addition to those common
4360 to programming languages:
4361
4362 @table @code
4363 @item @@
4364 @samp{@@} is a binary operator for treating parts of memory as arrays.
4365 @xref{Arrays, ,Artificial arrays}, for more information.
4366
4367 @item ::
4368 @samp{::} allows you to specify a variable in terms of the file or
4369 function where it is defined. @xref{Variables, ,Program variables}.
4370
4371 @cindex @{@var{type}@}
4372 @cindex type casting memory
4373 @cindex memory, viewing as typed object
4374 @cindex casts, to view memory
4375 @item @{@var{type}@} @var{addr}
4376 Refers to an object of type @var{type} stored at address @var{addr} in
4377 memory. @var{addr} may be any expression whose value is an integer or
4378 pointer (but parentheses are required around binary operators, just as in
4379 a cast). This construct is allowed regardless of what kind of data is
4380 normally supposed to reside at @var{addr}.
4381 @end table
4382
4383 @node Variables
4384 @section Program variables
4385
4386 The most common kind of expression to use is the name of a variable
4387 in your program.
4388
4389 Variables in expressions are understood in the selected stack frame
4390 (@pxref{Selection, ,Selecting a frame}); they must be either:
4391
4392 @itemize @bullet
4393 @item
4394 global (or file-static)
4395 @end itemize
4396
4397 @noindent or
4398
4399 @itemize @bullet
4400 @item
4401 visible according to the scope rules of the
4402 programming language from the point of execution in that frame
4403 @end itemize
4404
4405 @noindent This means that in the function
4406
4407 @example
4408 foo (a)
4409 int a;
4410 @{
4411 bar (a);
4412 @{
4413 int b = test ();
4414 bar (b);
4415 @}
4416 @}
4417 @end example
4418
4419 @noindent
4420 you can examine and use the variable @code{a} whenever your program is
4421 executing within the function @code{foo}, but you can only use or
4422 examine the variable @code{b} while your program is executing inside
4423 the block where @code{b} is declared.
4424
4425 @cindex variable name conflict
4426 There is an exception: you can refer to a variable or function whose
4427 scope is a single source file even if the current execution point is not
4428 in this file. But it is possible to have more than one such variable or
4429 function with the same name (in different source files). If that
4430 happens, referring to that name has unpredictable effects. If you wish,
4431 you can specify a static variable in a particular function or file,
4432 using the colon-colon notation:
4433
4434 @cindex colon-colon, context for variables/functions
4435 @iftex
4436 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
4437 @cindex @code{::}, context for variables/functions
4438 @end iftex
4439 @example
4440 @var{file}::@var{variable}
4441 @var{function}::@var{variable}
4442 @end example
4443
4444 @noindent
4445 Here @var{file} or @var{function} is the name of the context for the
4446 static @var{variable}. In the case of file names, you can use quotes to
4447 make sure @value{GDBN} parses the file name as a single word---for example,
4448 to print a global value of @code{x} defined in @file{f2.c}:
4449
4450 @example
4451 (@value{GDBP}) p 'f2.c'::x
4452 @end example
4453
4454 @cindex C++ scope resolution
4455 This use of @samp{::} is very rarely in conflict with the very similar
4456 use of the same notation in C++. @value{GDBN} also supports use of the C++
4457 scope resolution operator in @value{GDBN} expressions.
4458 @c FIXME: Um, so what happens in one of those rare cases where it's in
4459 @c conflict?? --mew
4460
4461 @cindex wrong values
4462 @cindex variable values, wrong
4463 @quotation
4464 @emph{Warning:} Occasionally, a local variable may appear to have the
4465 wrong value at certain points in a function---just after entry to a new
4466 scope, and just before exit.
4467 @end quotation
4468 You may see this problem when you are stepping by machine instructions.
4469 This is because, on most machines, it takes more than one instruction to
4470 set up a stack frame (including local variable definitions); if you are
4471 stepping by machine instructions, variables may appear to have the wrong
4472 values until the stack frame is completely built. On exit, it usually
4473 also takes more than one machine instruction to destroy a stack frame;
4474 after you begin stepping through that group of instructions, local
4475 variable definitions may be gone.
4476
4477 This may also happen when the compiler does significant optimizations.
4478 To be sure of always seeing accurate values, turn off all optimization
4479 when compiling.
4480
4481 @cindex ``No symbol "foo" in current context''
4482 Another possible effect of compiler optimizations is to optimize
4483 unused variables out of existence, or assign variables to registers (as
4484 opposed to memory addresses). Depending on the support for such cases
4485 offered by the debug info format used by the compiler, @value{GDBN}
4486 might not be able to display values for such local variables. If that
4487 happens, @value{GDBN} will print a message like this:
4488
4489 @example
4490 No symbol "foo" in current context.
4491 @end example
4492
4493 To solve such problems, either recompile without optimizations, or use a
4494 different debug info format, if the compiler supports several such
4495 formats. For example, @value{NGCC}, the @sc{gnu} C/C++ compiler usually
4496 supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4497 in a format that is superior to formats such as COFF. You may be able
4498 to use DWARF-2 (@samp{-gdwarf-2}), which is also an effective form for
4499 debug info. See @ref{Debugging Options,,Options for Debugging Your
4500 Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4501 information.
4502
4503
4504 @node Arrays
4505 @section Artificial arrays
4506
4507 @cindex artificial array
4508 @kindex @@@r{, referencing memory as an array}
4509 It is often useful to print out several successive objects of the
4510 same type in memory; a section of an array, or an array of
4511 dynamically determined size for which only a pointer exists in the
4512 program.
4513
4514 You can do this by referring to a contiguous span of memory as an
4515 @dfn{artificial array}, using the binary operator @samp{@@}. The left
4516 operand of @samp{@@} should be the first element of the desired array
4517 and be an individual object. The right operand should be the desired length
4518 of the array. The result is an array value whose elements are all of
4519 the type of the left argument. The first element is actually the left
4520 argument; the second element comes from bytes of memory immediately
4521 following those that hold the first element, and so on. Here is an
4522 example. If a program says
4523
4524 @example
4525 int *array = (int *) malloc (len * sizeof (int));
4526 @end example
4527
4528 @noindent
4529 you can print the contents of @code{array} with
4530
4531 @example
4532 p *array@@len
4533 @end example
4534
4535 The left operand of @samp{@@} must reside in memory. Array values made
4536 with @samp{@@} in this way behave just like other arrays in terms of
4537 subscripting, and are coerced to pointers when used in expressions.
4538 Artificial arrays most often appear in expressions via the value history
4539 (@pxref{Value History, ,Value history}), after printing one out.
4540
4541 Another way to create an artificial array is to use a cast.
4542 This re-interprets a value as if it were an array.
4543 The value need not be in memory:
4544 @example
4545 (@value{GDBP}) p/x (short[2])0x12345678
4546 $1 = @{0x1234, 0x5678@}
4547 @end example
4548
4549 As a convenience, if you leave the array length out (as in
4550 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
4551 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4552 @example
4553 (@value{GDBP}) p/x (short[])0x12345678
4554 $2 = @{0x1234, 0x5678@}
4555 @end example
4556
4557 Sometimes the artificial array mechanism is not quite enough; in
4558 moderately complex data structures, the elements of interest may not
4559 actually be adjacent---for example, if you are interested in the values
4560 of pointers in an array. One useful work-around in this situation is
4561 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4562 variables}) as a counter in an expression that prints the first
4563 interesting value, and then repeat that expression via @key{RET}. For
4564 instance, suppose you have an array @code{dtab} of pointers to
4565 structures, and you are interested in the values of a field @code{fv}
4566 in each structure. Here is an example of what you might type:
4567
4568 @example
4569 set $i = 0
4570 p dtab[$i++]->fv
4571 @key{RET}
4572 @key{RET}
4573 @dots{}
4574 @end example
4575
4576 @node Output Formats
4577 @section Output formats
4578
4579 @cindex formatted output
4580 @cindex output formats
4581 By default, @value{GDBN} prints a value according to its data type. Sometimes
4582 this is not what you want. For example, you might want to print a number
4583 in hex, or a pointer in decimal. Or you might want to view data in memory
4584 at a certain address as a character string or as an instruction. To do
4585 these things, specify an @dfn{output format} when you print a value.
4586
4587 The simplest use of output formats is to say how to print a value
4588 already computed. This is done by starting the arguments of the
4589 @code{print} command with a slash and a format letter. The format
4590 letters supported are:
4591
4592 @table @code
4593 @item x
4594 Regard the bits of the value as an integer, and print the integer in
4595 hexadecimal.
4596
4597 @item d
4598 Print as integer in signed decimal.
4599
4600 @item u
4601 Print as integer in unsigned decimal.
4602
4603 @item o
4604 Print as integer in octal.
4605
4606 @item t
4607 Print as integer in binary. The letter @samp{t} stands for ``two''.
4608 @footnote{@samp{b} cannot be used because these format letters are also
4609 used with the @code{x} command, where @samp{b} stands for ``byte'';
4610 see @ref{Memory,,Examining memory}.}
4611
4612 @item a
4613 @cindex unknown address, locating
4614 Print as an address, both absolute in hexadecimal and as an offset from
4615 the nearest preceding symbol. You can use this format used to discover
4616 where (in what function) an unknown address is located:
4617
4618 @example
4619 (@value{GDBP}) p/a 0x54320
4620 $3 = 0x54320 <_initialize_vx+396>
4621 @end example
4622
4623 @item c
4624 Regard as an integer and print it as a character constant.
4625
4626 @item f
4627 Regard the bits of the value as a floating point number and print
4628 using typical floating point syntax.
4629 @end table
4630
4631 For example, to print the program counter in hex (@pxref{Registers}), type
4632
4633 @example
4634 p/x $pc
4635 @end example
4636
4637 @noindent
4638 Note that no space is required before the slash; this is because command
4639 names in @value{GDBN} cannot contain a slash.
4640
4641 To reprint the last value in the value history with a different format,
4642 you can use the @code{print} command with just a format and no
4643 expression. For example, @samp{p/x} reprints the last value in hex.
4644
4645 @node Memory
4646 @section Examining memory
4647
4648 You can use the command @code{x} (for ``examine'') to examine memory in
4649 any of several formats, independently of your program's data types.
4650
4651 @cindex examining memory
4652 @table @code
4653 @kindex x @r{(examine memory)}
4654 @item x/@var{nfu} @var{addr}
4655 @itemx x @var{addr}
4656 @itemx x
4657 Use the @code{x} command to examine memory.
4658 @end table
4659
4660 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4661 much memory to display and how to format it; @var{addr} is an
4662 expression giving the address where you want to start displaying memory.
4663 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4664 Several commands set convenient defaults for @var{addr}.
4665
4666 @table @r
4667 @item @var{n}, the repeat count
4668 The repeat count is a decimal integer; the default is 1. It specifies
4669 how much memory (counting by units @var{u}) to display.
4670 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4671 @c 4.1.2.
4672
4673 @item @var{f}, the display format
4674 The display format is one of the formats used by @code{print},
4675 @samp{s} (null-terminated string), or @samp{i} (machine instruction).
4676 The default is @samp{x} (hexadecimal) initially.
4677 The default changes each time you use either @code{x} or @code{print}.
4678
4679 @item @var{u}, the unit size
4680 The unit size is any of
4681
4682 @table @code
4683 @item b
4684 Bytes.
4685 @item h
4686 Halfwords (two bytes).
4687 @item w
4688 Words (four bytes). This is the initial default.
4689 @item g
4690 Giant words (eight bytes).
4691 @end table
4692
4693 Each time you specify a unit size with @code{x}, that size becomes the
4694 default unit the next time you use @code{x}. (For the @samp{s} and
4695 @samp{i} formats, the unit size is ignored and is normally not written.)
4696
4697 @item @var{addr}, starting display address
4698 @var{addr} is the address where you want @value{GDBN} to begin displaying
4699 memory. The expression need not have a pointer value (though it may);
4700 it is always interpreted as an integer address of a byte of memory.
4701 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4702 @var{addr} is usually just after the last address examined---but several
4703 other commands also set the default address: @code{info breakpoints} (to
4704 the address of the last breakpoint listed), @code{info line} (to the
4705 starting address of a line), and @code{print} (if you use it to display
4706 a value from memory).
4707 @end table
4708
4709 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4710 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4711 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4712 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4713 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
4714
4715 Since the letters indicating unit sizes are all distinct from the
4716 letters specifying output formats, you do not have to remember whether
4717 unit size or format comes first; either order works. The output
4718 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4719 (However, the count @var{n} must come first; @samp{wx4} does not work.)
4720
4721 Even though the unit size @var{u} is ignored for the formats @samp{s}
4722 and @samp{i}, you might still want to use a count @var{n}; for example,
4723 @samp{3i} specifies that you want to see three machine instructions,
4724 including any operands. The command @code{disassemble} gives an
4725 alternative way of inspecting machine instructions; see @ref{Machine
4726 Code,,Source and machine code}.
4727
4728 All the defaults for the arguments to @code{x} are designed to make it
4729 easy to continue scanning memory with minimal specifications each time
4730 you use @code{x}. For example, after you have inspected three machine
4731 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4732 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4733 the repeat count @var{n} is used again; the other arguments default as
4734 for successive uses of @code{x}.
4735
4736 @cindex @code{$_}, @code{$__}, and value history
4737 The addresses and contents printed by the @code{x} command are not saved
4738 in the value history because there is often too much of them and they
4739 would get in the way. Instead, @value{GDBN} makes these values available for
4740 subsequent use in expressions as values of the convenience variables
4741 @code{$_} and @code{$__}. After an @code{x} command, the last address
4742 examined is available for use in expressions in the convenience variable
4743 @code{$_}. The contents of that address, as examined, are available in
4744 the convenience variable @code{$__}.
4745
4746 If the @code{x} command has a repeat count, the address and contents saved
4747 are from the last memory unit printed; this is not the same as the last
4748 address printed if several units were printed on the last line of output.
4749
4750 @node Auto Display
4751 @section Automatic display
4752 @cindex automatic display
4753 @cindex display of expressions
4754
4755 If you find that you want to print the value of an expression frequently
4756 (to see how it changes), you might want to add it to the @dfn{automatic
4757 display list} so that @value{GDBN} prints its value each time your program stops.
4758 Each expression added to the list is given a number to identify it;
4759 to remove an expression from the list, you specify that number.
4760 The automatic display looks like this:
4761
4762 @example
4763 2: foo = 38
4764 3: bar[5] = (struct hack *) 0x3804
4765 @end example
4766
4767 @noindent
4768 This display shows item numbers, expressions and their current values. As with
4769 displays you request manually using @code{x} or @code{print}, you can
4770 specify the output format you prefer; in fact, @code{display} decides
4771 whether to use @code{print} or @code{x} depending on how elaborate your
4772 format specification is---it uses @code{x} if you specify a unit size,
4773 or one of the two formats (@samp{i} and @samp{s}) that are only
4774 supported by @code{x}; otherwise it uses @code{print}.
4775
4776 @table @code
4777 @kindex display
4778 @item display @var{expr}
4779 Add the expression @var{expr} to the list of expressions to display
4780 each time your program stops. @xref{Expressions, ,Expressions}.
4781
4782 @code{display} does not repeat if you press @key{RET} again after using it.
4783
4784 @item display/@var{fmt} @var{expr}
4785 For @var{fmt} specifying only a display format and not a size or
4786 count, add the expression @var{expr} to the auto-display list but
4787 arrange to display it each time in the specified format @var{fmt}.
4788 @xref{Output Formats,,Output formats}.
4789
4790 @item display/@var{fmt} @var{addr}
4791 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4792 number of units, add the expression @var{addr} as a memory address to
4793 be examined each time your program stops. Examining means in effect
4794 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4795 @end table
4796
4797 For example, @samp{display/i $pc} can be helpful, to see the machine
4798 instruction about to be executed each time execution stops (@samp{$pc}
4799 is a common name for the program counter; @pxref{Registers, ,Registers}).
4800
4801 @table @code
4802 @kindex delete display
4803 @kindex undisplay
4804 @item undisplay @var{dnums}@dots{}
4805 @itemx delete display @var{dnums}@dots{}
4806 Remove item numbers @var{dnums} from the list of expressions to display.
4807
4808 @code{undisplay} does not repeat if you press @key{RET} after using it.
4809 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4810
4811 @kindex disable display
4812 @item disable display @var{dnums}@dots{}
4813 Disable the display of item numbers @var{dnums}. A disabled display
4814 item is not printed automatically, but is not forgotten. It may be
4815 enabled again later.
4816
4817 @kindex enable display
4818 @item enable display @var{dnums}@dots{}
4819 Enable display of item numbers @var{dnums}. It becomes effective once
4820 again in auto display of its expression, until you specify otherwise.
4821
4822 @item display
4823 Display the current values of the expressions on the list, just as is
4824 done when your program stops.
4825
4826 @kindex info display
4827 @item info display
4828 Print the list of expressions previously set up to display
4829 automatically, each one with its item number, but without showing the
4830 values. This includes disabled expressions, which are marked as such.
4831 It also includes expressions which would not be displayed right now
4832 because they refer to automatic variables not currently available.
4833 @end table
4834
4835 If a display expression refers to local variables, then it does not make
4836 sense outside the lexical context for which it was set up. Such an
4837 expression is disabled when execution enters a context where one of its
4838 variables is not defined. For example, if you give the command
4839 @code{display last_char} while inside a function with an argument
4840 @code{last_char}, @value{GDBN} displays this argument while your program
4841 continues to stop inside that function. When it stops elsewhere---where
4842 there is no variable @code{last_char}---the display is disabled
4843 automatically. The next time your program stops where @code{last_char}
4844 is meaningful, you can enable the display expression once again.
4845
4846 @node Print Settings
4847 @section Print settings
4848
4849 @cindex format options
4850 @cindex print settings
4851 @value{GDBN} provides the following ways to control how arrays, structures,
4852 and symbols are printed.
4853
4854 @noindent
4855 These settings are useful for debugging programs in any language:
4856
4857 @table @code
4858 @kindex set print address
4859 @item set print address
4860 @itemx set print address on
4861 @value{GDBN} prints memory addresses showing the location of stack
4862 traces, structure values, pointer values, breakpoints, and so forth,
4863 even when it also displays the contents of those addresses. The default
4864 is @code{on}. For example, this is what a stack frame display looks like with
4865 @code{set print address on}:
4866
4867 @smallexample
4868 @group
4869 (@value{GDBP}) f
4870 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4871 at input.c:530
4872 530 if (lquote != def_lquote)
4873 @end group
4874 @end smallexample
4875
4876 @item set print address off
4877 Do not print addresses when displaying their contents. For example,
4878 this is the same stack frame displayed with @code{set print address off}:
4879
4880 @smallexample
4881 @group
4882 (@value{GDBP}) set print addr off
4883 (@value{GDBP}) f
4884 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4885 530 if (lquote != def_lquote)
4886 @end group
4887 @end smallexample
4888
4889 You can use @samp{set print address off} to eliminate all machine
4890 dependent displays from the @value{GDBN} interface. For example, with
4891 @code{print address off}, you should get the same text for backtraces on
4892 all machines---whether or not they involve pointer arguments.
4893
4894 @kindex show print address
4895 @item show print address
4896 Show whether or not addresses are to be printed.
4897 @end table
4898
4899 When @value{GDBN} prints a symbolic address, it normally prints the
4900 closest earlier symbol plus an offset. If that symbol does not uniquely
4901 identify the address (for example, it is a name whose scope is a single
4902 source file), you may need to clarify. One way to do this is with
4903 @code{info line}, for example @samp{info line *0x4537}. Alternately,
4904 you can set @value{GDBN} to print the source file and line number when
4905 it prints a symbolic address:
4906
4907 @table @code
4908 @kindex set print symbol-filename
4909 @item set print symbol-filename on
4910 Tell @value{GDBN} to print the source file name and line number of a
4911 symbol in the symbolic form of an address.
4912
4913 @item set print symbol-filename off
4914 Do not print source file name and line number of a symbol. This is the
4915 default.
4916
4917 @kindex show print symbol-filename
4918 @item show print symbol-filename
4919 Show whether or not @value{GDBN} will print the source file name and
4920 line number of a symbol in the symbolic form of an address.
4921 @end table
4922
4923 Another situation where it is helpful to show symbol filenames and line
4924 numbers is when disassembling code; @value{GDBN} shows you the line
4925 number and source file that corresponds to each instruction.
4926
4927 Also, you may wish to see the symbolic form only if the address being
4928 printed is reasonably close to the closest earlier symbol:
4929
4930 @table @code
4931 @kindex set print max-symbolic-offset
4932 @item set print max-symbolic-offset @var{max-offset}
4933 Tell @value{GDBN} to only display the symbolic form of an address if the
4934 offset between the closest earlier symbol and the address is less than
4935 @var{max-offset}. The default is 0, which tells @value{GDBN}
4936 to always print the symbolic form of an address if any symbol precedes it.
4937
4938 @kindex show print max-symbolic-offset
4939 @item show print max-symbolic-offset
4940 Ask how large the maximum offset is that @value{GDBN} prints in a
4941 symbolic address.
4942 @end table
4943
4944 @cindex wild pointer, interpreting
4945 @cindex pointer, finding referent
4946 If you have a pointer and you are not sure where it points, try
4947 @samp{set print symbol-filename on}. Then you can determine the name
4948 and source file location of the variable where it points, using
4949 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4950 For example, here @value{GDBN} shows that a variable @code{ptt} points
4951 at another variable @code{t}, defined in @file{hi2.c}:
4952
4953 @example
4954 (@value{GDBP}) set print symbol-filename on
4955 (@value{GDBP}) p/a ptt
4956 $4 = 0xe008 <t in hi2.c>
4957 @end example
4958
4959 @quotation
4960 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4961 does not show the symbol name and filename of the referent, even with
4962 the appropriate @code{set print} options turned on.
4963 @end quotation
4964
4965 Other settings control how different kinds of objects are printed:
4966
4967 @table @code
4968 @kindex set print array
4969 @item set print array
4970 @itemx set print array on
4971 Pretty print arrays. This format is more convenient to read,
4972 but uses more space. The default is off.
4973
4974 @item set print array off
4975 Return to compressed format for arrays.
4976
4977 @kindex show print array
4978 @item show print array
4979 Show whether compressed or pretty format is selected for displaying
4980 arrays.
4981
4982 @kindex set print elements
4983 @item set print elements @var{number-of-elements}
4984 Set a limit on how many elements of an array @value{GDBN} will print.
4985 If @value{GDBN} is printing a large array, it stops printing after it has
4986 printed the number of elements set by the @code{set print elements} command.
4987 This limit also applies to the display of strings.
4988 When @value{GDBN} starts, this limit is set to 200.
4989 Setting @var{number-of-elements} to zero means that the printing is unlimited.
4990
4991 @kindex show print elements
4992 @item show print elements
4993 Display the number of elements of a large array that @value{GDBN} will print.
4994 If the number is 0, then the printing is unlimited.
4995
4996 @kindex set print null-stop
4997 @item set print null-stop
4998 Cause @value{GDBN} to stop printing the characters of an array when the first
4999 @sc{null} is encountered. This is useful when large arrays actually
5000 contain only short strings.
5001 The default is off.
5002
5003 @kindex set print pretty
5004 @item set print pretty on
5005 Cause @value{GDBN} to print structures in an indented format with one member
5006 per line, like this:
5007
5008 @smallexample
5009 @group
5010 $1 = @{
5011 next = 0x0,
5012 flags = @{
5013 sweet = 1,
5014 sour = 1
5015 @},
5016 meat = 0x54 "Pork"
5017 @}
5018 @end group
5019 @end smallexample
5020
5021 @item set print pretty off
5022 Cause @value{GDBN} to print structures in a compact format, like this:
5023
5024 @smallexample
5025 @group
5026 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5027 meat = 0x54 "Pork"@}
5028 @end group
5029 @end smallexample
5030
5031 @noindent
5032 This is the default format.
5033
5034 @kindex show print pretty
5035 @item show print pretty
5036 Show which format @value{GDBN} is using to print structures.
5037
5038 @kindex set print sevenbit-strings
5039 @item set print sevenbit-strings on
5040 Print using only seven-bit characters; if this option is set,
5041 @value{GDBN} displays any eight-bit characters (in strings or
5042 character values) using the notation @code{\}@var{nnn}. This setting is
5043 best if you are working in English (@sc{ascii}) and you use the
5044 high-order bit of characters as a marker or ``meta'' bit.
5045
5046 @item set print sevenbit-strings off
5047 Print full eight-bit characters. This allows the use of more
5048 international character sets, and is the default.
5049
5050 @kindex show print sevenbit-strings
5051 @item show print sevenbit-strings
5052 Show whether or not @value{GDBN} is printing only seven-bit characters.
5053
5054 @kindex set print union
5055 @item set print union on
5056 Tell @value{GDBN} to print unions which are contained in structures. This
5057 is the default setting.
5058
5059 @item set print union off
5060 Tell @value{GDBN} not to print unions which are contained in structures.
5061
5062 @kindex show print union
5063 @item show print union
5064 Ask @value{GDBN} whether or not it will print unions which are contained in
5065 structures.
5066
5067 For example, given the declarations
5068
5069 @smallexample
5070 typedef enum @{Tree, Bug@} Species;
5071 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5072 typedef enum @{Caterpillar, Cocoon, Butterfly@}
5073 Bug_forms;
5074
5075 struct thing @{
5076 Species it;
5077 union @{
5078 Tree_forms tree;
5079 Bug_forms bug;
5080 @} form;
5081 @};
5082
5083 struct thing foo = @{Tree, @{Acorn@}@};
5084 @end smallexample
5085
5086 @noindent
5087 with @code{set print union on} in effect @samp{p foo} would print
5088
5089 @smallexample
5090 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5091 @end smallexample
5092
5093 @noindent
5094 and with @code{set print union off} in effect it would print
5095
5096 @smallexample
5097 $1 = @{it = Tree, form = @{...@}@}
5098 @end smallexample
5099 @end table
5100
5101 @need 1000
5102 @noindent
5103 These settings are of interest when debugging C++ programs:
5104
5105 @table @code
5106 @cindex demangling
5107 @kindex set print demangle
5108 @item set print demangle
5109 @itemx set print demangle on
5110 Print C++ names in their source form rather than in the encoded
5111 (``mangled'') form passed to the assembler and linker for type-safe
5112 linkage. The default is on.
5113
5114 @kindex show print demangle
5115 @item show print demangle
5116 Show whether C++ names are printed in mangled or demangled form.
5117
5118 @kindex set print asm-demangle
5119 @item set print asm-demangle
5120 @itemx set print asm-demangle on
5121 Print C++ names in their source form rather than their mangled form, even
5122 in assembler code printouts such as instruction disassemblies.
5123 The default is off.
5124
5125 @kindex show print asm-demangle
5126 @item show print asm-demangle
5127 Show whether C++ names in assembly listings are printed in mangled
5128 or demangled form.
5129
5130 @kindex set demangle-style
5131 @cindex C++ symbol decoding style
5132 @cindex symbol decoding style, C++
5133 @item set demangle-style @var{style}
5134 Choose among several encoding schemes used by different compilers to
5135 represent C++ names. The choices for @var{style} are currently:
5136
5137 @table @code
5138 @item auto
5139 Allow @value{GDBN} to choose a decoding style by inspecting your program.
5140
5141 @item gnu
5142 Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
5143 This is the default.
5144
5145 @item hp
5146 Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
5147
5148 @item lucid
5149 Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
5150
5151 @item arm
5152 Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
5153 @strong{Warning:} this setting alone is not sufficient to allow
5154 debugging @code{cfront}-generated executables. @value{GDBN} would
5155 require further enhancement to permit that.
5156
5157 @end table
5158 If you omit @var{style}, you will see a list of possible formats.
5159
5160 @kindex show demangle-style
5161 @item show demangle-style
5162 Display the encoding style currently in use for decoding C++ symbols.
5163
5164 @kindex set print object
5165 @item set print object
5166 @itemx set print object on
5167 When displaying a pointer to an object, identify the @emph{actual}
5168 (derived) type of the object rather than the @emph{declared} type, using
5169 the virtual function table.
5170
5171 @item set print object off
5172 Display only the declared type of objects, without reference to the
5173 virtual function table. This is the default setting.
5174
5175 @kindex show print object
5176 @item show print object
5177 Show whether actual, or declared, object types are displayed.
5178
5179 @kindex set print static-members
5180 @item set print static-members
5181 @itemx set print static-members on
5182 Print static members when displaying a C++ object. The default is on.
5183
5184 @item set print static-members off
5185 Do not print static members when displaying a C++ object.
5186
5187 @kindex show print static-members
5188 @item show print static-members
5189 Show whether C++ static members are printed, or not.
5190
5191 @c These don't work with HP ANSI C++ yet.
5192 @kindex set print vtbl
5193 @item set print vtbl
5194 @itemx set print vtbl on
5195 Pretty print C++ virtual function tables. The default is off.
5196 (The @code{vtbl} commands do not work on programs compiled with the HP
5197 ANSI C++ compiler (@code{aCC}).)
5198
5199 @item set print vtbl off
5200 Do not pretty print C++ virtual function tables.
5201
5202 @kindex show print vtbl
5203 @item show print vtbl
5204 Show whether C++ virtual function tables are pretty printed, or not.
5205 @end table
5206
5207 @node Value History
5208 @section Value history
5209
5210 @cindex value history
5211 Values printed by the @code{print} command are saved in the @value{GDBN}
5212 @dfn{value history}. This allows you to refer to them in other expressions.
5213 Values are kept until the symbol table is re-read or discarded
5214 (for example with the @code{file} or @code{symbol-file} commands).
5215 When the symbol table changes, the value history is discarded,
5216 since the values may contain pointers back to the types defined in the
5217 symbol table.
5218
5219 @cindex @code{$}
5220 @cindex @code{$$}
5221 @cindex history number
5222 The values printed are given @dfn{history numbers} by which you can
5223 refer to them. These are successive integers starting with one.
5224 @code{print} shows you the history number assigned to a value by
5225 printing @samp{$@var{num} = } before the value; here @var{num} is the
5226 history number.
5227
5228 To refer to any previous value, use @samp{$} followed by the value's
5229 history number. The way @code{print} labels its output is designed to
5230 remind you of this. Just @code{$} refers to the most recent value in
5231 the history, and @code{$$} refers to the value before that.
5232 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5233 is the value just prior to @code{$$}, @code{$$1} is equivalent to
5234 @code{$$}, and @code{$$0} is equivalent to @code{$}.
5235
5236 For example, suppose you have just printed a pointer to a structure and
5237 want to see the contents of the structure. It suffices to type
5238
5239 @example
5240 p *$
5241 @end example
5242
5243 If you have a chain of structures where the component @code{next} points
5244 to the next one, you can print the contents of the next one with this:
5245
5246 @example
5247 p *$.next
5248 @end example
5249
5250 @noindent
5251 You can print successive links in the chain by repeating this
5252 command---which you can do by just typing @key{RET}.
5253
5254 Note that the history records values, not expressions. If the value of
5255 @code{x} is 4 and you type these commands:
5256
5257 @example
5258 print x
5259 set x=5
5260 @end example
5261
5262 @noindent
5263 then the value recorded in the value history by the @code{print} command
5264 remains 4 even though the value of @code{x} has changed.
5265
5266 @table @code
5267 @kindex show values
5268 @item show values
5269 Print the last ten values in the value history, with their item numbers.
5270 This is like @samp{p@ $$9} repeated ten times, except that @code{show
5271 values} does not change the history.
5272
5273 @item show values @var{n}
5274 Print ten history values centered on history item number @var{n}.
5275
5276 @item show values +
5277 Print ten history values just after the values last printed. If no more
5278 values are available, @code{show values +} produces no display.
5279 @end table
5280
5281 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5282 same effect as @samp{show values +}.
5283
5284 @node Convenience Vars
5285 @section Convenience variables
5286
5287 @cindex convenience variables
5288 @value{GDBN} provides @dfn{convenience variables} that you can use within
5289 @value{GDBN} to hold on to a value and refer to it later. These variables
5290 exist entirely within @value{GDBN}; they are not part of your program, and
5291 setting a convenience variable has no direct effect on further execution
5292 of your program. That is why you can use them freely.
5293
5294 Convenience variables are prefixed with @samp{$}. Any name preceded by
5295 @samp{$} can be used for a convenience variable, unless it is one of
5296 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
5297 (Value history references, in contrast, are @emph{numbers} preceded
5298 by @samp{$}. @xref{Value History, ,Value history}.)
5299
5300 You can save a value in a convenience variable with an assignment
5301 expression, just as you would set a variable in your program.
5302 For example:
5303
5304 @example
5305 set $foo = *object_ptr
5306 @end example
5307
5308 @noindent
5309 would save in @code{$foo} the value contained in the object pointed to by
5310 @code{object_ptr}.
5311
5312 Using a convenience variable for the first time creates it, but its
5313 value is @code{void} until you assign a new value. You can alter the
5314 value with another assignment at any time.
5315
5316 Convenience variables have no fixed types. You can assign a convenience
5317 variable any type of value, including structures and arrays, even if
5318 that variable already has a value of a different type. The convenience
5319 variable, when used as an expression, has the type of its current value.
5320
5321 @table @code
5322 @kindex show convenience
5323 @item show convenience
5324 Print a list of convenience variables used so far, and their values.
5325 Abbreviated @code{show conv}.
5326 @end table
5327
5328 One of the ways to use a convenience variable is as a counter to be
5329 incremented or a pointer to be advanced. For example, to print
5330 a field from successive elements of an array of structures:
5331
5332 @example
5333 set $i = 0
5334 print bar[$i++]->contents
5335 @end example
5336
5337 @noindent
5338 Repeat that command by typing @key{RET}.
5339
5340 Some convenience variables are created automatically by @value{GDBN} and given
5341 values likely to be useful.
5342
5343 @table @code
5344 @vindex $_@r{, convenience variable}
5345 @item $_
5346 The variable @code{$_} is automatically set by the @code{x} command to
5347 the last address examined (@pxref{Memory, ,Examining memory}). Other
5348 commands which provide a default address for @code{x} to examine also
5349 set @code{$_} to that address; these commands include @code{info line}
5350 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5351 except when set by the @code{x} command, in which case it is a pointer
5352 to the type of @code{$__}.
5353
5354 @vindex $__@r{, convenience variable}
5355 @item $__
5356 The variable @code{$__} is automatically set by the @code{x} command
5357 to the value found in the last address examined. Its type is chosen
5358 to match the format in which the data was printed.
5359
5360 @item $_exitcode
5361 @vindex $_exitcode@r{, convenience variable}
5362 The variable @code{$_exitcode} is automatically set to the exit code when
5363 the program being debugged terminates.
5364 @end table
5365
5366 On HP-UX systems, if you refer to a function or variable name that
5367 begins with a dollar sign, @value{GDBN} searches for a user or system
5368 name first, before it searches for a convenience variable.
5369
5370 @node Registers
5371 @section Registers
5372
5373 @cindex registers
5374 You can refer to machine register contents, in expressions, as variables
5375 with names starting with @samp{$}. The names of registers are different
5376 for each machine; use @code{info registers} to see the names used on
5377 your machine.
5378
5379 @table @code
5380 @kindex info registers
5381 @item info registers
5382 Print the names and values of all registers except floating-point
5383 registers (in the selected stack frame).
5384
5385 @kindex info all-registers
5386 @cindex floating point registers
5387 @item info all-registers
5388 Print the names and values of all registers, including floating-point
5389 registers.
5390
5391 @item info registers @var{regname} @dots{}
5392 Print the @dfn{relativized} value of each specified register @var{regname}.
5393 As discussed in detail below, register values are normally relative to
5394 the selected stack frame. @var{regname} may be any register name valid on
5395 the machine you are using, with or without the initial @samp{$}.
5396 @end table
5397
5398 @value{GDBN} has four ``standard'' register names that are available (in
5399 expressions) on most machines---whenever they do not conflict with an
5400 architecture's canonical mnemonics for registers. The register names
5401 @code{$pc} and @code{$sp} are used for the program counter register and
5402 the stack pointer. @code{$fp} is used for a register that contains a
5403 pointer to the current stack frame, and @code{$ps} is used for a
5404 register that contains the processor status. For example,
5405 you could print the program counter in hex with
5406
5407 @example
5408 p/x $pc
5409 @end example
5410
5411 @noindent
5412 or print the instruction to be executed next with
5413
5414 @example
5415 x/i $pc
5416 @end example
5417
5418 @noindent
5419 or add four to the stack pointer@footnote{This is a way of removing
5420 one word from the stack, on machines where stacks grow downward in
5421 memory (most machines, nowadays). This assumes that the innermost
5422 stack frame is selected; setting @code{$sp} is not allowed when other
5423 stack frames are selected. To pop entire frames off the stack,
5424 regardless of machine architecture, use @code{return};
5425 see @ref{Returning, ,Returning from a function}.} with
5426
5427 @example
5428 set $sp += 4
5429 @end example
5430
5431 Whenever possible, these four standard register names are available on
5432 your machine even though the machine has different canonical mnemonics,
5433 so long as there is no conflict. The @code{info registers} command
5434 shows the canonical names. For example, on the SPARC, @code{info
5435 registers} displays the processor status register as @code{$psr} but you
5436 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5437 is an alias for the @sc{eflags} register.
5438
5439 @value{GDBN} always considers the contents of an ordinary register as an
5440 integer when the register is examined in this way. Some machines have
5441 special registers which can hold nothing but floating point; these
5442 registers are considered to have floating point values. There is no way
5443 to refer to the contents of an ordinary register as floating point value
5444 (although you can @emph{print} it as a floating point value with
5445 @samp{print/f $@var{regname}}).
5446
5447 Some registers have distinct ``raw'' and ``virtual'' data formats. This
5448 means that the data format in which the register contents are saved by
5449 the operating system is not the same one that your program normally
5450 sees. For example, the registers of the 68881 floating point
5451 coprocessor are always saved in ``extended'' (raw) format, but all C
5452 programs expect to work with ``double'' (virtual) format. In such
5453 cases, @value{GDBN} normally works with the virtual format only (the format
5454 that makes sense for your program), but the @code{info registers} command
5455 prints the data in both formats.
5456
5457 Normally, register values are relative to the selected stack frame
5458 (@pxref{Selection, ,Selecting a frame}). This means that you get the
5459 value that the register would contain if all stack frames farther in
5460 were exited and their saved registers restored. In order to see the
5461 true contents of hardware registers, you must select the innermost
5462 frame (with @samp{frame 0}).
5463
5464 However, @value{GDBN} must deduce where registers are saved, from the machine
5465 code generated by your compiler. If some registers are not saved, or if
5466 @value{GDBN} is unable to locate the saved registers, the selected stack
5467 frame makes no difference.
5468
5469 @node Floating Point Hardware
5470 @section Floating point hardware
5471 @cindex floating point
5472
5473 Depending on the configuration, @value{GDBN} may be able to give
5474 you more information about the status of the floating point hardware.
5475
5476 @table @code
5477 @kindex info float
5478 @item info float
5479 Display hardware-dependent information about the floating
5480 point unit. The exact contents and layout vary depending on the
5481 floating point chip. Currently, @samp{info float} is supported on
5482 the ARM and x86 machines.
5483 @end table
5484
5485 @node Languages
5486 @chapter Using @value{GDBN} with Different Languages
5487 @cindex languages
5488
5489 Although programming languages generally have common aspects, they are
5490 rarely expressed in the same manner. For instance, in ANSI C,
5491 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5492 Modula-2, it is accomplished by @code{p^}. Values can also be
5493 represented (and displayed) differently. Hex numbers in C appear as
5494 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
5495
5496 @cindex working language
5497 Language-specific information is built into @value{GDBN} for some languages,
5498 allowing you to express operations like the above in your program's
5499 native language, and allowing @value{GDBN} to output values in a manner
5500 consistent with the syntax of your program's native language. The
5501 language you use to build expressions is called the @dfn{working
5502 language}.
5503
5504 @menu
5505 * Setting:: Switching between source languages
5506 * Show:: Displaying the language
5507 * Checks:: Type and range checks
5508 * Support:: Supported languages
5509 @end menu
5510
5511 @node Setting
5512 @section Switching between source languages
5513
5514 There are two ways to control the working language---either have @value{GDBN}
5515 set it automatically, or select it manually yourself. You can use the
5516 @code{set language} command for either purpose. On startup, @value{GDBN}
5517 defaults to setting the language automatically. The working language is
5518 used to determine how expressions you type are interpreted, how values
5519 are printed, etc.
5520
5521 In addition to the working language, every source file that
5522 @value{GDBN} knows about has its own working language. For some object
5523 file formats, the compiler might indicate which language a particular
5524 source file is in. However, most of the time @value{GDBN} infers the
5525 language from the name of the file. The language of a source file
5526 controls whether C++ names are demangled---this way @code{backtrace} can
5527 show each frame appropriately for its own language. There is no way to
5528 set the language of a source file from within @value{GDBN}, but you can
5529 set the language associated with a filename extension. @xref{Show, ,
5530 Displaying the language}.
5531
5532 This is most commonly a problem when you use a program, such
5533 as @code{cfront} or @code{f2c}, that generates C but is written in
5534 another language. In that case, make the
5535 program use @code{#line} directives in its C output; that way
5536 @value{GDBN} will know the correct language of the source code of the original
5537 program, and will display that source code, not the generated C code.
5538
5539 @menu
5540 * Filenames:: Filename extensions and languages.
5541 * Manually:: Setting the working language manually
5542 * Automatically:: Having @value{GDBN} infer the source language
5543 @end menu
5544
5545 @node Filenames
5546 @subsection List of filename extensions and languages
5547
5548 If a source file name ends in one of the following extensions, then
5549 @value{GDBN} infers that its language is the one indicated.
5550
5551 @table @file
5552
5553 @item .c
5554 C source file
5555
5556 @item .C
5557 @itemx .cc
5558 @itemx .cp
5559 @itemx .cpp
5560 @itemx .cxx
5561 @itemx .c++
5562 C++ source file
5563
5564 @item .f
5565 @itemx .F
5566 Fortran source file
5567
5568 @item .ch
5569 @itemx .c186
5570 @itemx .c286
5571 CHILL source file
5572
5573 @item .mod
5574 Modula-2 source file
5575
5576 @item .s
5577 @itemx .S
5578 Assembler source file. This actually behaves almost like C, but
5579 @value{GDBN} does not skip over function prologues when stepping.
5580 @end table
5581
5582 In addition, you may set the language associated with a filename
5583 extension. @xref{Show, , Displaying the language}.
5584
5585 @node Manually
5586 @subsection Setting the working language
5587
5588 If you allow @value{GDBN} to set the language automatically,
5589 expressions are interpreted the same way in your debugging session and
5590 your program.
5591
5592 @kindex set language
5593 If you wish, you may set the language manually. To do this, issue the
5594 command @samp{set language @var{lang}}, where @var{lang} is the name of
5595 a language, such as
5596 @code{c} or @code{modula-2}.
5597 For a list of the supported languages, type @samp{set language}.
5598
5599 Setting the language manually prevents @value{GDBN} from updating the working
5600 language automatically. This can lead to confusion if you try
5601 to debug a program when the working language is not the same as the
5602 source language, when an expression is acceptable to both
5603 languages---but means different things. For instance, if the current
5604 source file were written in C, and @value{GDBN} was parsing Modula-2, a
5605 command such as:
5606
5607 @example
5608 print a = b + c
5609 @end example
5610
5611 @noindent
5612 might not have the effect you intended. In C, this means to add
5613 @code{b} and @code{c} and place the result in @code{a}. The result
5614 printed would be the value of @code{a}. In Modula-2, this means to compare
5615 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
5616
5617 @node Automatically
5618 @subsection Having @value{GDBN} infer the source language
5619
5620 To have @value{GDBN} set the working language automatically, use
5621 @samp{set language local} or @samp{set language auto}. @value{GDBN}
5622 then infers the working language. That is, when your program stops in a
5623 frame (usually by encountering a breakpoint), @value{GDBN} sets the
5624 working language to the language recorded for the function in that
5625 frame. If the language for a frame is unknown (that is, if the function
5626 or block corresponding to the frame was defined in a source file that
5627 does not have a recognized extension), the current working language is
5628 not changed, and @value{GDBN} issues a warning.
5629
5630 This may not seem necessary for most programs, which are written
5631 entirely in one source language. However, program modules and libraries
5632 written in one source language can be used by a main program written in
5633 a different source language. Using @samp{set language auto} in this
5634 case frees you from having to set the working language manually.
5635
5636 @node Show
5637 @section Displaying the language
5638
5639 The following commands help you find out which language is the
5640 working language, and also what language source files were written in.
5641
5642 @kindex show language
5643 @kindex info frame@r{, show the source language}
5644 @kindex info source@r{, show the source language}
5645 @table @code
5646 @item show language
5647 Display the current working language. This is the
5648 language you can use with commands such as @code{print} to
5649 build and compute expressions that may involve variables in your program.
5650
5651 @item info frame
5652 Display the source language for this frame. This language becomes the
5653 working language if you use an identifier from this frame.
5654 @xref{Frame Info, ,Information about a frame}, to identify the other
5655 information listed here.
5656
5657 @item info source
5658 Display the source language of this source file.
5659 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
5660 information listed here.
5661 @end table
5662
5663 In unusual circumstances, you may have source files with extensions
5664 not in the standard list. You can then set the extension associated
5665 with a language explicitly:
5666
5667 @kindex set extension-language
5668 @kindex info extensions
5669 @table @code
5670 @item set extension-language @var{.ext} @var{language}
5671 Set source files with extension @var{.ext} to be assumed to be in
5672 the source language @var{language}.
5673
5674 @item info extensions
5675 List all the filename extensions and the associated languages.
5676 @end table
5677
5678 @node Checks
5679 @section Type and range checking
5680
5681 @quotation
5682 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
5683 checking are included, but they do not yet have any effect. This
5684 section documents the intended facilities.
5685 @end quotation
5686 @c FIXME remove warning when type/range code added
5687
5688 Some languages are designed to guard you against making seemingly common
5689 errors through a series of compile- and run-time checks. These include
5690 checking the type of arguments to functions and operators, and making
5691 sure mathematical overflows are caught at run time. Checks such as
5692 these help to ensure a program's correctness once it has been compiled
5693 by eliminating type mismatches, and providing active checks for range
5694 errors when your program is running.
5695
5696 @value{GDBN} can check for conditions like the above if you wish.
5697 Although @value{GDBN} does not check the statements in your program, it
5698 can check expressions entered directly into @value{GDBN} for evaluation via
5699 the @code{print} command, for example. As with the working language,
5700 @value{GDBN} can also decide whether or not to check automatically based on
5701 your program's source language. @xref{Support, ,Supported languages},
5702 for the default settings of supported languages.
5703
5704 @menu
5705 * Type Checking:: An overview of type checking
5706 * Range Checking:: An overview of range checking
5707 @end menu
5708
5709 @cindex type checking
5710 @cindex checks, type
5711 @node Type Checking
5712 @subsection An overview of type checking
5713
5714 Some languages, such as Modula-2, are strongly typed, meaning that the
5715 arguments to operators and functions have to be of the correct type,
5716 otherwise an error occurs. These checks prevent type mismatch
5717 errors from ever causing any run-time problems. For example,
5718
5719 @smallexample
5720 1 + 2 @result{} 3
5721 @exdent but
5722 @error{} 1 + 2.3
5723 @end smallexample
5724
5725 The second example fails because the @code{CARDINAL} 1 is not
5726 type-compatible with the @code{REAL} 2.3.
5727
5728 For the expressions you use in @value{GDBN} commands, you can tell the
5729 @value{GDBN} type checker to skip checking;
5730 to treat any mismatches as errors and abandon the expression;
5731 or to only issue warnings when type mismatches occur,
5732 but evaluate the expression anyway. When you choose the last of
5733 these, @value{GDBN} evaluates expressions like the second example above, but
5734 also issues a warning.
5735
5736 Even if you turn type checking off, there may be other reasons
5737 related to type that prevent @value{GDBN} from evaluating an expression.
5738 For instance, @value{GDBN} does not know how to add an @code{int} and
5739 a @code{struct foo}. These particular type errors have nothing to do
5740 with the language in use, and usually arise from expressions, such as
5741 the one described above, which make little sense to evaluate anyway.
5742
5743 Each language defines to what degree it is strict about type. For
5744 instance, both Modula-2 and C require the arguments to arithmetical
5745 operators to be numbers. In C, enumerated types and pointers can be
5746 represented as numbers, so that they are valid arguments to mathematical
5747 operators. @xref{Support, ,Supported languages}, for further
5748 details on specific languages.
5749
5750 @value{GDBN} provides some additional commands for controlling the type checker:
5751
5752 @kindex set check@r{, type}
5753 @kindex set check type
5754 @kindex show check type
5755 @table @code
5756 @item set check type auto
5757 Set type checking on or off based on the current working language.
5758 @xref{Support, ,Supported languages}, for the default settings for
5759 each language.
5760
5761 @item set check type on
5762 @itemx set check type off
5763 Set type checking on or off, overriding the default setting for the
5764 current working language. Issue a warning if the setting does not
5765 match the language default. If any type mismatches occur in
5766 evaluating an expression while type checking is on, @value{GDBN} prints a
5767 message and aborts evaluation of the expression.
5768
5769 @item set check type warn
5770 Cause the type checker to issue warnings, but to always attempt to
5771 evaluate the expression. Evaluating the expression may still
5772 be impossible for other reasons. For example, @value{GDBN} cannot add
5773 numbers and structures.
5774
5775 @item show type
5776 Show the current setting of the type checker, and whether or not @value{GDBN}
5777 is setting it automatically.
5778 @end table
5779
5780 @cindex range checking
5781 @cindex checks, range
5782 @node Range Checking
5783 @subsection An overview of range checking
5784
5785 In some languages (such as Modula-2), it is an error to exceed the
5786 bounds of a type; this is enforced with run-time checks. Such range
5787 checking is meant to ensure program correctness by making sure
5788 computations do not overflow, or indices on an array element access do
5789 not exceed the bounds of the array.
5790
5791 For expressions you use in @value{GDBN} commands, you can tell
5792 @value{GDBN} to treat range errors in one of three ways: ignore them,
5793 always treat them as errors and abandon the expression, or issue
5794 warnings but evaluate the expression anyway.
5795
5796 A range error can result from numerical overflow, from exceeding an
5797 array index bound, or when you type a constant that is not a member
5798 of any type. Some languages, however, do not treat overflows as an
5799 error. In many implementations of C, mathematical overflow causes the
5800 result to ``wrap around'' to lower values---for example, if @var{m} is
5801 the largest integer value, and @var{s} is the smallest, then
5802
5803 @example
5804 @var{m} + 1 @result{} @var{s}
5805 @end example
5806
5807 This, too, is specific to individual languages, and in some cases
5808 specific to individual compilers or machines. @xref{Support, ,
5809 Supported languages}, for further details on specific languages.
5810
5811 @value{GDBN} provides some additional commands for controlling the range checker:
5812
5813 @kindex set check@r{, range}
5814 @kindex set check range
5815 @kindex show check range
5816 @table @code
5817 @item set check range auto
5818 Set range checking on or off based on the current working language.
5819 @xref{Support, ,Supported languages}, for the default settings for
5820 each language.
5821
5822 @item set check range on
5823 @itemx set check range off
5824 Set range checking on or off, overriding the default setting for the
5825 current working language. A warning is issued if the setting does not
5826 match the language default. If a range error occurs and range checking is on,
5827 then a message is printed and evaluation of the expression is aborted.
5828
5829 @item set check range warn
5830 Output messages when the @value{GDBN} range checker detects a range error,
5831 but attempt to evaluate the expression anyway. Evaluating the
5832 expression may still be impossible for other reasons, such as accessing
5833 memory that the process does not own (a typical example from many Unix
5834 systems).
5835
5836 @item show range
5837 Show the current setting of the range checker, and whether or not it is
5838 being set automatically by @value{GDBN}.
5839 @end table
5840
5841 @node Support
5842 @section Supported languages
5843
5844 @value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5845 @c This is false ...
5846 Some @value{GDBN} features may be used in expressions regardless of the
5847 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5848 and the @samp{@{type@}addr} construct (@pxref{Expressions,
5849 ,Expressions}) can be used with the constructs of any supported
5850 language.
5851
5852 The following sections detail to what degree each source language is
5853 supported by @value{GDBN}. These sections are not meant to be language
5854 tutorials or references, but serve only as a reference guide to what the
5855 @value{GDBN} expression parser accepts, and what input and output
5856 formats should look like for different languages. There are many good
5857 books written on each of these languages; please look to these for a
5858 language reference or tutorial.
5859
5860 @menu
5861 * C:: C and C++
5862 * Modula-2:: Modula-2
5863 * Chill:: Chill
5864 @end menu
5865
5866 @node C
5867 @subsection C and C++
5868
5869 @cindex C and C++
5870 @cindex expressions in C or C++
5871
5872 Since C and C++ are so closely related, many features of @value{GDBN} apply
5873 to both languages. Whenever this is the case, we discuss those languages
5874 together.
5875
5876 @cindex C@t{++}
5877 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
5878 @cindex @sc{gnu} C++
5879 The C++ debugging facilities are jointly implemented by the C++
5880 compiler and @value{GDBN}. Therefore, to debug your C++ code
5881 effectively, you must compile your C++ programs with a supported
5882 C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5883 compiler (@code{aCC}).
5884
5885 For best results when using @sc{gnu} C++, use the stabs debugging
5886 format. You can select that format explicitly with the @code{g++}
5887 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5888 @ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5889 CC, gcc.info, Using @sc{gnu} CC}, for more information.
5890
5891 @menu
5892 * C Operators:: C and C++ operators
5893 * C Constants:: C and C++ constants
5894 * C plus plus expressions:: C++ expressions
5895 * C Defaults:: Default settings for C and C++
5896 * C Checks:: C and C++ type and range checks
5897 * Debugging C:: @value{GDBN} and C
5898 * Debugging C plus plus:: @value{GDBN} features for C++
5899 @end menu
5900
5901 @node C Operators
5902 @subsubsection C and C++ operators
5903
5904 @cindex C and C++ operators
5905
5906 Operators must be defined on values of specific types. For instance,
5907 @code{+} is defined on numbers, but not on structures. Operators are
5908 often defined on groups of types.
5909
5910 For the purposes of C and C++, the following definitions hold:
5911
5912 @itemize @bullet
5913
5914 @item
5915 @emph{Integral types} include @code{int} with any of its storage-class
5916 specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
5917
5918 @item
5919 @emph{Floating-point types} include @code{float}, @code{double}, and
5920 @code{long double} (if supported by the target platform).
5921
5922 @item
5923 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
5924
5925 @item
5926 @emph{Scalar types} include all of the above.
5927
5928 @end itemize
5929
5930 @noindent
5931 The following operators are supported. They are listed here
5932 in order of increasing precedence:
5933
5934 @table @code
5935 @item ,
5936 The comma or sequencing operator. Expressions in a comma-separated list
5937 are evaluated from left to right, with the result of the entire
5938 expression being the last expression evaluated.
5939
5940 @item =
5941 Assignment. The value of an assignment expression is the value
5942 assigned. Defined on scalar types.
5943
5944 @item @var{op}=
5945 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5946 and translated to @w{@code{@var{a} = @var{a op b}}}.
5947 @w{@code{@var{op}=}} and @code{=} have the same precedence.
5948 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5949 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5950
5951 @item ?:
5952 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5953 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5954 integral type.
5955
5956 @item ||
5957 Logical @sc{or}. Defined on integral types.
5958
5959 @item &&
5960 Logical @sc{and}. Defined on integral types.
5961
5962 @item |
5963 Bitwise @sc{or}. Defined on integral types.
5964
5965 @item ^
5966 Bitwise exclusive-@sc{or}. Defined on integral types.
5967
5968 @item &
5969 Bitwise @sc{and}. Defined on integral types.
5970
5971 @item ==@r{, }!=
5972 Equality and inequality. Defined on scalar types. The value of these
5973 expressions is 0 for false and non-zero for true.
5974
5975 @item <@r{, }>@r{, }<=@r{, }>=
5976 Less than, greater than, less than or equal, greater than or equal.
5977 Defined on scalar types. The value of these expressions is 0 for false
5978 and non-zero for true.
5979
5980 @item <<@r{, }>>
5981 left shift, and right shift. Defined on integral types.
5982
5983 @item @@
5984 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5985
5986 @item +@r{, }-
5987 Addition and subtraction. Defined on integral types, floating-point types and
5988 pointer types.
5989
5990 @item *@r{, }/@r{, }%
5991 Multiplication, division, and modulus. Multiplication and division are
5992 defined on integral and floating-point types. Modulus is defined on
5993 integral types.
5994
5995 @item ++@r{, }--
5996 Increment and decrement. When appearing before a variable, the
5997 operation is performed before the variable is used in an expression;
5998 when appearing after it, the variable's value is used before the
5999 operation takes place.
6000
6001 @item *
6002 Pointer dereferencing. Defined on pointer types. Same precedence as
6003 @code{++}.
6004
6005 @item &
6006 Address operator. Defined on variables. Same precedence as @code{++}.
6007
6008 For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
6009 allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
6010 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
6011 where a C++ reference variable (declared with @samp{&@var{ref}}) is
6012 stored.
6013
6014 @item -
6015 Negative. Defined on integral and floating-point types. Same
6016 precedence as @code{++}.
6017
6018 @item !
6019 Logical negation. Defined on integral types. Same precedence as
6020 @code{++}.
6021
6022 @item ~
6023 Bitwise complement operator. Defined on integral types. Same precedence as
6024 @code{++}.
6025
6026
6027 @item .@r{, }->
6028 Structure member, and pointer-to-structure member. For convenience,
6029 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
6030 pointer based on the stored type information.
6031 Defined on @code{struct} and @code{union} data.
6032
6033 @item .*@r{, }->*
6034 Dereferences of pointers to members.
6035
6036 @item []
6037 Array indexing. @code{@var{a}[@var{i}]} is defined as
6038 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
6039
6040 @item ()
6041 Function parameter list. Same precedence as @code{->}.
6042
6043 @item ::
6044 C++ scope resolution operator. Defined on @code{struct}, @code{union},
6045 and @code{class} types.
6046
6047 @item ::
6048 Doubled colons also represent the @value{GDBN} scope operator
6049 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
6050 above.
6051 @end table
6052
6053 If an operator is redefined in the user code, @value{GDBN} usually
6054 attempts to invoke the redefined version instead of using the operator's
6055 predefined meaning.
6056
6057 @menu
6058 * C Constants::
6059 @end menu
6060
6061 @node C Constants
6062 @subsubsection C and C++ constants
6063
6064 @cindex C and C++ constants
6065
6066 @value{GDBN} allows you to express the constants of C and C++ in the
6067 following ways:
6068
6069 @itemize @bullet
6070 @item
6071 Integer constants are a sequence of digits. Octal constants are
6072 specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
6073 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
6074 @samp{l}, specifying that the constant should be treated as a
6075 @code{long} value.
6076
6077 @item
6078 Floating point constants are a sequence of digits, followed by a decimal
6079 point, followed by a sequence of digits, and optionally followed by an
6080 exponent. An exponent is of the form:
6081 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
6082 sequence of digits. The @samp{+} is optional for positive exponents.
6083 A floating-point constant may also end with a letter @samp{f} or
6084 @samp{F}, specifying that the constant should be treated as being of
6085 the @code{float} (as opposed to the default @code{double}) type; or with
6086 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
6087 constant.
6088
6089 @item
6090 Enumerated constants consist of enumerated identifiers, or their
6091 integral equivalents.
6092
6093 @item
6094 Character constants are a single character surrounded by single quotes
6095 (@code{'}), or a number---the ordinal value of the corresponding character
6096 (usually its @sc{ascii} value). Within quotes, the single character may
6097 be represented by a letter or by @dfn{escape sequences}, which are of
6098 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
6099 of the character's ordinal value; or of the form @samp{\@var{x}}, where
6100 @samp{@var{x}} is a predefined special character---for example,
6101 @samp{\n} for newline.
6102
6103 @item
6104 String constants are a sequence of character constants surrounded by
6105 double quotes (@code{"}). Any valid character constant (as described
6106 above) may appear. Double quotes within the string must be preceded by
6107 a backslash, so for instance @samp{"a\"b'c"} is a string of five
6108 characters.
6109
6110 @item
6111 Pointer constants are an integral value. You can also write pointers
6112 to constants using the C operator @samp{&}.
6113
6114 @item
6115 Array constants are comma-separated lists surrounded by braces @samp{@{}
6116 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
6117 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
6118 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
6119 @end itemize
6120
6121 @menu
6122 * C plus plus expressions::
6123 * C Defaults::
6124 * C Checks::
6125
6126 * Debugging C::
6127 @end menu
6128
6129 @node C plus plus expressions
6130 @subsubsection C++ expressions
6131
6132 @cindex expressions in C++
6133 @value{GDBN} expression handling can interpret most C++ expressions.
6134
6135 @cindex C++ support, not in @sc{coff}
6136 @cindex @sc{coff} versus C++
6137 @cindex C++ and object formats
6138 @cindex object formats and C++
6139 @cindex a.out and C++
6140 @cindex @sc{ecoff} and C++
6141 @cindex @sc{xcoff} and C++
6142 @cindex @sc{elf}/stabs and C++
6143 @cindex @sc{elf}/@sc{dwarf} and C++
6144 @c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
6145 @c periodically whether this has happened...
6146 @quotation
6147 @emph{Warning:} @value{GDBN} can only debug C++ code if you use the
6148 proper compiler. Typically, C++ debugging depends on the use of
6149 additional debugging information in the symbol table, and thus requires
6150 special support. In particular, if your compiler generates a.out, MIPS
6151 @sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
6152 symbol table, these facilities are all available. (With @sc{gnu} CC,
6153 you can use the @samp{-gstabs} option to request stabs debugging
6154 extensions explicitly.) Where the object code format is standard
6155 @sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
6156 support in @value{GDBN} does @emph{not} work.
6157 @end quotation
6158
6159 @enumerate
6160
6161 @cindex member functions
6162 @item
6163 Member function calls are allowed; you can use expressions like
6164
6165 @example
6166 count = aml->GetOriginal(x, y)
6167 @end example
6168
6169 @vindex this@r{, inside C@t{++} member functions}
6170 @cindex namespace in C++
6171 @item
6172 While a member function is active (in the selected stack frame), your
6173 expressions have the same namespace available as the member function;
6174 that is, @value{GDBN} allows implicit references to the class instance
6175 pointer @code{this} following the same rules as C++.
6176
6177 @cindex call overloaded functions
6178 @cindex overloaded functions, calling
6179 @cindex type conversions in C++
6180 @item
6181 You can call overloaded functions; @value{GDBN} resolves the function
6182 call to the right definition, with some restrictions. @value{GDBN} does not
6183 perform overload resolution involving user-defined type conversions,
6184 calls to constructors, or instantiations of templates that do not exist
6185 in the program. It also cannot handle ellipsis argument lists or
6186 default arguments.
6187
6188 It does perform integral conversions and promotions, floating-point
6189 promotions, arithmetic conversions, pointer conversions, conversions of
6190 class objects to base classes, and standard conversions such as those of
6191 functions or arrays to pointers; it requires an exact match on the
6192 number of function arguments.
6193
6194 Overload resolution is always performed, unless you have specified
6195 @code{set overload-resolution off}. @xref{Debugging C plus plus,
6196 ,@value{GDBN} features for C++}.
6197
6198 You must specify @code{set overload-resolution off} in order to use an
6199 explicit function signature to call an overloaded function, as in
6200 @smallexample
6201 p 'foo(char,int)'('x', 13)
6202 @end smallexample
6203
6204 The @value{GDBN} command-completion facility can simplify this;
6205 see @ref{Completion, ,Command completion}.
6206
6207 @cindex reference declarations
6208 @item
6209 @value{GDBN} understands variables declared as C++ references; you can use
6210 them in expressions just as you do in C++ source---they are automatically
6211 dereferenced.
6212
6213 In the parameter list shown when @value{GDBN} displays a frame, the values of
6214 reference variables are not displayed (unlike other variables); this
6215 avoids clutter, since references are often used for large structures.
6216 The @emph{address} of a reference variable is always shown, unless
6217 you have specified @samp{set print address off}.
6218
6219 @item
6220 @value{GDBN} supports the C++ name resolution operator @code{::}---your
6221 expressions can use it just as expressions in your program do. Since
6222 one scope may be defined in another, you can use @code{::} repeatedly if
6223 necessary, for example in an expression like
6224 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
6225 resolving name scope by reference to source files, in both C and C++
6226 debugging (@pxref{Variables, ,Program variables}).
6227 @end enumerate
6228
6229 In addition, when used with HP's C++ compiler, @value{GDBN} supports
6230 calling virtual functions correctly, printing out virtual bases of
6231 objects, calling functions in a base subobject, casting objects, and
6232 invoking user-defined operators.
6233
6234 @node C Defaults
6235 @subsubsection C and C++ defaults
6236
6237 @cindex C and C++ defaults
6238
6239 If you allow @value{GDBN} to set type and range checking automatically, they
6240 both default to @code{off} whenever the working language changes to
6241 C or C++. This happens regardless of whether you or @value{GDBN}
6242 selects the working language.
6243
6244 If you allow @value{GDBN} to set the language automatically, it
6245 recognizes source files whose names end with @file{.c}, @file{.C}, or
6246 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6247 these files, it sets the working language to C or C++.
6248 @xref{Automatically, ,Having @value{GDBN} infer the source language},
6249 for further details.
6250
6251 @c Type checking is (a) primarily motivated by Modula-2, and (b)
6252 @c unimplemented. If (b) changes, it might make sense to let this node
6253 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
6254
6255 @node C Checks
6256 @subsubsection C and C++ type and range checks
6257
6258 @cindex C and C++ checks
6259
6260 By default, when @value{GDBN} parses C or C++ expressions, type checking
6261 is not used. However, if you turn type checking on, @value{GDBN}
6262 considers two variables type equivalent if:
6263
6264 @itemize @bullet
6265 @item
6266 The two variables are structured and have the same structure, union, or
6267 enumerated tag.
6268
6269 @item
6270 The two variables have the same type name, or types that have been
6271 declared equivalent through @code{typedef}.
6272
6273 @ignore
6274 @c leaving this out because neither J Gilmore nor R Pesch understand it.
6275 @c FIXME--beers?
6276 @item
6277 The two @code{struct}, @code{union}, or @code{enum} variables are
6278 declared in the same declaration. (Note: this may not be true for all C
6279 compilers.)
6280 @end ignore
6281 @end itemize
6282
6283 Range checking, if turned on, is done on mathematical operations. Array
6284 indices are not checked, since they are often used to index a pointer
6285 that is not itself an array.
6286
6287 @node Debugging C
6288 @subsubsection @value{GDBN} and C
6289
6290 The @code{set print union} and @code{show print union} commands apply to
6291 the @code{union} type. When set to @samp{on}, any @code{union} that is
6292 inside a @code{struct} or @code{class} is also printed. Otherwise, it
6293 appears as @samp{@{...@}}.
6294
6295 The @code{@@} operator aids in the debugging of dynamic arrays, formed
6296 with pointers and a memory allocation function. @xref{Expressions,
6297 ,Expressions}.
6298
6299 @menu
6300 * Debugging C plus plus::
6301 @end menu
6302
6303 @node Debugging C plus plus
6304 @subsubsection @value{GDBN} features for C++
6305
6306 @cindex commands for C++
6307
6308 Some @value{GDBN} commands are particularly useful with C++, and some are
6309 designed specifically for use with C++. Here is a summary:
6310
6311 @table @code
6312 @cindex break in overloaded functions
6313 @item @r{breakpoint menus}
6314 When you want a breakpoint in a function whose name is overloaded,
6315 @value{GDBN} breakpoint menus help you specify which function definition
6316 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6317
6318 @cindex overloading in C++
6319 @item rbreak @var{regex}
6320 Setting breakpoints using regular expressions is helpful for setting
6321 breakpoints on overloaded functions that are not members of any special
6322 classes.
6323 @xref{Set Breaks, ,Setting breakpoints}.
6324
6325 @cindex C++ exception handling
6326 @item catch throw
6327 @itemx catch catch
6328 Debug C++ exception handling using these commands. @xref{Set
6329 Catchpoints, , Setting catchpoints}.
6330
6331 @cindex inheritance
6332 @item ptype @var{typename}
6333 Print inheritance relationships as well as other information for type
6334 @var{typename}.
6335 @xref{Symbols, ,Examining the Symbol Table}.
6336
6337 @cindex C++ symbol display
6338 @item set print demangle
6339 @itemx show print demangle
6340 @itemx set print asm-demangle
6341 @itemx show print asm-demangle
6342 Control whether C++ symbols display in their source form, both when
6343 displaying code as C++ source and when displaying disassemblies.
6344 @xref{Print Settings, ,Print settings}.
6345
6346 @item set print object
6347 @itemx show print object
6348 Choose whether to print derived (actual) or declared types of objects.
6349 @xref{Print Settings, ,Print settings}.
6350
6351 @item set print vtbl
6352 @itemx show print vtbl
6353 Control the format for printing virtual function tables.
6354 @xref{Print Settings, ,Print settings}.
6355 (The @code{vtbl} commands do not work on programs compiled with the HP
6356 ANSI C++ compiler (@code{aCC}).)
6357
6358 @kindex set overload-resolution
6359 @cindex overloaded functions, overload resolution
6360 @item set overload-resolution on
6361 Enable overload resolution for C++ expression evaluation. The default
6362 is on. For overloaded functions, @value{GDBN} evaluates the arguments
6363 and searches for a function whose signature matches the argument types,
6364 using the standard C++ conversion rules (see @ref{C plus plus expressions, ,C++
6365 expressions}, for details). If it cannot find a match, it emits a
6366 message.
6367
6368 @item set overload-resolution off
6369 Disable overload resolution for C++ expression evaluation. For
6370 overloaded functions that are not class member functions, @value{GDBN}
6371 chooses the first function of the specified name that it finds in the
6372 symbol table, whether or not its arguments are of the correct type. For
6373 overloaded functions that are class member functions, @value{GDBN}
6374 searches for a function whose signature @emph{exactly} matches the
6375 argument types.
6376
6377 @item @r{Overloaded symbol names}
6378 You can specify a particular definition of an overloaded symbol, using
6379 the same notation that is used to declare such symbols in C++: type
6380 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6381 also use the @value{GDBN} command-line word completion facilities to list the
6382 available choices, or to finish the type list for you.
6383 @xref{Completion,, Command completion}, for details on how to do this.
6384 @end table
6385
6386 @node Modula-2
6387 @subsection Modula-2
6388
6389 @cindex Modula-2, @value{GDBN} support
6390
6391 The extensions made to @value{GDBN} to support Modula-2 only support
6392 output from the @sc{gnu} Modula-2 compiler (which is currently being
6393 developed). Other Modula-2 compilers are not currently supported, and
6394 attempting to debug executables produced by them is most likely
6395 to give an error as @value{GDBN} reads in the executable's symbol
6396 table.
6397
6398 @cindex expressions in Modula-2
6399 @menu
6400 * M2 Operators:: Built-in operators
6401 * Built-In Func/Proc:: Built-in functions and procedures
6402 * M2 Constants:: Modula-2 constants
6403 * M2 Defaults:: Default settings for Modula-2
6404 * Deviations:: Deviations from standard Modula-2
6405 * M2 Checks:: Modula-2 type and range checks
6406 * M2 Scope:: The scope operators @code{::} and @code{.}
6407 * GDB/M2:: @value{GDBN} and Modula-2
6408 @end menu
6409
6410 @node M2 Operators
6411 @subsubsection Operators
6412 @cindex Modula-2 operators
6413
6414 Operators must be defined on values of specific types. For instance,
6415 @code{+} is defined on numbers, but not on structures. Operators are
6416 often defined on groups of types. For the purposes of Modula-2, the
6417 following definitions hold:
6418
6419 @itemize @bullet
6420
6421 @item
6422 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6423 their subranges.
6424
6425 @item
6426 @emph{Character types} consist of @code{CHAR} and its subranges.
6427
6428 @item
6429 @emph{Floating-point types} consist of @code{REAL}.
6430
6431 @item
6432 @emph{Pointer types} consist of anything declared as @code{POINTER TO
6433 @var{type}}.
6434
6435 @item
6436 @emph{Scalar types} consist of all of the above.
6437
6438 @item
6439 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
6440
6441 @item
6442 @emph{Boolean types} consist of @code{BOOLEAN}.
6443 @end itemize
6444
6445 @noindent
6446 The following operators are supported, and appear in order of
6447 increasing precedence:
6448
6449 @table @code
6450 @item ,
6451 Function argument or array index separator.
6452
6453 @item :=
6454 Assignment. The value of @var{var} @code{:=} @var{value} is
6455 @var{value}.
6456
6457 @item <@r{, }>
6458 Less than, greater than on integral, floating-point, or enumerated
6459 types.
6460
6461 @item <=@r{, }>=
6462 Less than or equal to, greater than or equal to
6463 on integral, floating-point and enumerated types, or set inclusion on
6464 set types. Same precedence as @code{<}.
6465
6466 @item =@r{, }<>@r{, }#
6467 Equality and two ways of expressing inequality, valid on scalar types.
6468 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6469 available for inequality, since @code{#} conflicts with the script
6470 comment character.
6471
6472 @item IN
6473 Set membership. Defined on set types and the types of their members.
6474 Same precedence as @code{<}.
6475
6476 @item OR
6477 Boolean disjunction. Defined on boolean types.
6478
6479 @item AND@r{, }&
6480 Boolean conjunction. Defined on boolean types.
6481
6482 @item @@
6483 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6484
6485 @item +@r{, }-
6486 Addition and subtraction on integral and floating-point types, or union
6487 and difference on set types.
6488
6489 @item *
6490 Multiplication on integral and floating-point types, or set intersection
6491 on set types.
6492
6493 @item /
6494 Division on floating-point types, or symmetric set difference on set
6495 types. Same precedence as @code{*}.
6496
6497 @item DIV@r{, }MOD
6498 Integer division and remainder. Defined on integral types. Same
6499 precedence as @code{*}.
6500
6501 @item -
6502 Negative. Defined on @code{INTEGER} and @code{REAL} data.
6503
6504 @item ^
6505 Pointer dereferencing. Defined on pointer types.
6506
6507 @item NOT
6508 Boolean negation. Defined on boolean types. Same precedence as
6509 @code{^}.
6510
6511 @item .
6512 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
6513 precedence as @code{^}.
6514
6515 @item []
6516 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6517
6518 @item ()
6519 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6520 as @code{^}.
6521
6522 @item ::@r{, }.
6523 @value{GDBN} and Modula-2 scope operators.
6524 @end table
6525
6526 @quotation
6527 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6528 treats the use of the operator @code{IN}, or the use of operators
6529 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6530 @code{<=}, and @code{>=} on sets as an error.
6531 @end quotation
6532
6533 @cindex Modula-2 built-ins
6534 @node Built-In Func/Proc
6535 @subsubsection Built-in functions and procedures
6536
6537 Modula-2 also makes available several built-in procedures and functions.
6538 In describing these, the following metavariables are used:
6539
6540 @table @var
6541
6542 @item a
6543 represents an @code{ARRAY} variable.
6544
6545 @item c
6546 represents a @code{CHAR} constant or variable.
6547
6548 @item i
6549 represents a variable or constant of integral type.
6550
6551 @item m
6552 represents an identifier that belongs to a set. Generally used in the
6553 same function with the metavariable @var{s}. The type of @var{s} should
6554 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6555
6556 @item n
6557 represents a variable or constant of integral or floating-point type.
6558
6559 @item r
6560 represents a variable or constant of floating-point type.
6561
6562 @item t
6563 represents a type.
6564
6565 @item v
6566 represents a variable.
6567
6568 @item x
6569 represents a variable or constant of one of many types. See the
6570 explanation of the function for details.
6571 @end table
6572
6573 All Modula-2 built-in procedures also return a result, described below.
6574
6575 @table @code
6576 @item ABS(@var{n})
6577 Returns the absolute value of @var{n}.
6578
6579 @item CAP(@var{c})
6580 If @var{c} is a lower case letter, it returns its upper case
6581 equivalent, otherwise it returns its argument.
6582
6583 @item CHR(@var{i})
6584 Returns the character whose ordinal value is @var{i}.
6585
6586 @item DEC(@var{v})
6587 Decrements the value in the variable @var{v} by one. Returns the new value.
6588
6589 @item DEC(@var{v},@var{i})
6590 Decrements the value in the variable @var{v} by @var{i}. Returns the
6591 new value.
6592
6593 @item EXCL(@var{m},@var{s})
6594 Removes the element @var{m} from the set @var{s}. Returns the new
6595 set.
6596
6597 @item FLOAT(@var{i})
6598 Returns the floating point equivalent of the integer @var{i}.
6599
6600 @item HIGH(@var{a})
6601 Returns the index of the last member of @var{a}.
6602
6603 @item INC(@var{v})
6604 Increments the value in the variable @var{v} by one. Returns the new value.
6605
6606 @item INC(@var{v},@var{i})
6607 Increments the value in the variable @var{v} by @var{i}. Returns the
6608 new value.
6609
6610 @item INCL(@var{m},@var{s})
6611 Adds the element @var{m} to the set @var{s} if it is not already
6612 there. Returns the new set.
6613
6614 @item MAX(@var{t})
6615 Returns the maximum value of the type @var{t}.
6616
6617 @item MIN(@var{t})
6618 Returns the minimum value of the type @var{t}.
6619
6620 @item ODD(@var{i})
6621 Returns boolean TRUE if @var{i} is an odd number.
6622
6623 @item ORD(@var{x})
6624 Returns the ordinal value of its argument. For example, the ordinal
6625 value of a character is its @sc{ascii} value (on machines supporting the
6626 @sc{ascii} character set). @var{x} must be of an ordered type, which include
6627 integral, character and enumerated types.
6628
6629 @item SIZE(@var{x})
6630 Returns the size of its argument. @var{x} can be a variable or a type.
6631
6632 @item TRUNC(@var{r})
6633 Returns the integral part of @var{r}.
6634
6635 @item VAL(@var{t},@var{i})
6636 Returns the member of the type @var{t} whose ordinal value is @var{i}.
6637 @end table
6638
6639 @quotation
6640 @emph{Warning:} Sets and their operations are not yet supported, so
6641 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6642 an error.
6643 @end quotation
6644
6645 @cindex Modula-2 constants
6646 @node M2 Constants
6647 @subsubsection Constants
6648
6649 @value{GDBN} allows you to express the constants of Modula-2 in the following
6650 ways:
6651
6652 @itemize @bullet
6653
6654 @item
6655 Integer constants are simply a sequence of digits. When used in an
6656 expression, a constant is interpreted to be type-compatible with the
6657 rest of the expression. Hexadecimal integers are specified by a
6658 trailing @samp{H}, and octal integers by a trailing @samp{B}.
6659
6660 @item
6661 Floating point constants appear as a sequence of digits, followed by a
6662 decimal point and another sequence of digits. An optional exponent can
6663 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6664 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6665 digits of the floating point constant must be valid decimal (base 10)
6666 digits.
6667
6668 @item
6669 Character constants consist of a single character enclosed by a pair of
6670 like quotes, either single (@code{'}) or double (@code{"}). They may
6671 also be expressed by their ordinal value (their @sc{ascii} value, usually)
6672 followed by a @samp{C}.
6673
6674 @item
6675 String constants consist of a sequence of characters enclosed by a
6676 pair of like quotes, either single (@code{'}) or double (@code{"}).
6677 Escape sequences in the style of C are also allowed. @xref{C
6678 Constants, ,C and C++ constants}, for a brief explanation of escape
6679 sequences.
6680
6681 @item
6682 Enumerated constants consist of an enumerated identifier.
6683
6684 @item
6685 Boolean constants consist of the identifiers @code{TRUE} and
6686 @code{FALSE}.
6687
6688 @item
6689 Pointer constants consist of integral values only.
6690
6691 @item
6692 Set constants are not yet supported.
6693 @end itemize
6694
6695 @node M2 Defaults
6696 @subsubsection Modula-2 defaults
6697 @cindex Modula-2 defaults
6698
6699 If type and range checking are set automatically by @value{GDBN}, they
6700 both default to @code{on} whenever the working language changes to
6701 Modula-2. This happens regardless of whether you or @value{GDBN}
6702 selected the working language.
6703
6704 If you allow @value{GDBN} to set the language automatically, then entering
6705 code compiled from a file whose name ends with @file{.mod} sets the
6706 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
6707 the language automatically}, for further details.
6708
6709 @node Deviations
6710 @subsubsection Deviations from standard Modula-2
6711 @cindex Modula-2, deviations from
6712
6713 A few changes have been made to make Modula-2 programs easier to debug.
6714 This is done primarily via loosening its type strictness:
6715
6716 @itemize @bullet
6717 @item
6718 Unlike in standard Modula-2, pointer constants can be formed by
6719 integers. This allows you to modify pointer variables during
6720 debugging. (In standard Modula-2, the actual address contained in a
6721 pointer variable is hidden from you; it can only be modified
6722 through direct assignment to another pointer variable or expression that
6723 returned a pointer.)
6724
6725 @item
6726 C escape sequences can be used in strings and characters to represent
6727 non-printable characters. @value{GDBN} prints out strings with these
6728 escape sequences embedded. Single non-printable characters are
6729 printed using the @samp{CHR(@var{nnn})} format.
6730
6731 @item
6732 The assignment operator (@code{:=}) returns the value of its right-hand
6733 argument.
6734
6735 @item
6736 All built-in procedures both modify @emph{and} return their argument.
6737 @end itemize
6738
6739 @node M2 Checks
6740 @subsubsection Modula-2 type and range checks
6741 @cindex Modula-2 checks
6742
6743 @quotation
6744 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6745 range checking.
6746 @end quotation
6747 @c FIXME remove warning when type/range checks added
6748
6749 @value{GDBN} considers two Modula-2 variables type equivalent if:
6750
6751 @itemize @bullet
6752 @item
6753 They are of types that have been declared equivalent via a @code{TYPE
6754 @var{t1} = @var{t2}} statement
6755
6756 @item
6757 They have been declared on the same line. (Note: This is true of the
6758 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6759 @end itemize
6760
6761 As long as type checking is enabled, any attempt to combine variables
6762 whose types are not equivalent is an error.
6763
6764 Range checking is done on all mathematical operations, assignment, array
6765 index bounds, and all built-in functions and procedures.
6766
6767 @node M2 Scope
6768 @subsubsection The scope operators @code{::} and @code{.}
6769 @cindex scope
6770 @cindex @code{.}, Modula-2 scope operator
6771 @cindex colon, doubled as scope operator
6772 @ifinfo
6773 @vindex colon-colon@r{, in Modula-2}
6774 @c Info cannot handle :: but TeX can.
6775 @end ifinfo
6776 @iftex
6777 @vindex ::@r{, in Modula-2}
6778 @end iftex
6779
6780 There are a few subtle differences between the Modula-2 scope operator
6781 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6782 similar syntax:
6783
6784 @example
6785
6786 @var{module} . @var{id}
6787 @var{scope} :: @var{id}
6788 @end example
6789
6790 @noindent
6791 where @var{scope} is the name of a module or a procedure,
6792 @var{module} the name of a module, and @var{id} is any declared
6793 identifier within your program, except another module.
6794
6795 Using the @code{::} operator makes @value{GDBN} search the scope
6796 specified by @var{scope} for the identifier @var{id}. If it is not
6797 found in the specified scope, then @value{GDBN} searches all scopes
6798 enclosing the one specified by @var{scope}.
6799
6800 Using the @code{.} operator makes @value{GDBN} search the current scope for
6801 the identifier specified by @var{id} that was imported from the
6802 definition module specified by @var{module}. With this operator, it is
6803 an error if the identifier @var{id} was not imported from definition
6804 module @var{module}, or if @var{id} is not an identifier in
6805 @var{module}.
6806
6807 @node GDB/M2
6808 @subsubsection @value{GDBN} and Modula-2
6809
6810 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6811 Five subcommands of @code{set print} and @code{show print} apply
6812 specifically to C and C++: @samp{vtbl}, @samp{demangle},
6813 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6814 apply to C++, and the last to the C @code{union} type, which has no direct
6815 analogue in Modula-2.
6816
6817 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
6818 with any language, is not useful with Modula-2. Its
6819 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6820 created in Modula-2 as they can in C or C++. However, because an
6821 address can be specified by an integral constant, the construct
6822 @samp{@{@var{type}@}@var{adrexp}} is still useful.
6823
6824 @cindex @code{#} in Modula-2
6825 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6826 interpreted as the beginning of a comment. Use @code{<>} instead.
6827
6828 @node Chill
6829 @subsection Chill
6830
6831 The extensions made to @value{GDBN} to support Chill only support output
6832 from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
6833 supported, and attempting to debug executables produced by them is most
6834 likely to give an error as @value{GDBN} reads in the executable's symbol
6835 table.
6836
6837 @c This used to say "... following Chill related topics ...", but since
6838 @c menus are not shown in the printed manual, it would look awkward.
6839 This section covers the Chill related topics and the features
6840 of @value{GDBN} which support these topics.
6841
6842 @menu
6843 * How modes are displayed:: How modes are displayed
6844 * Locations:: Locations and their accesses
6845 * Values and their Operations:: Values and their Operations
6846 * Chill type and range checks::
6847 * Chill defaults::
6848 @end menu
6849
6850 @node How modes are displayed
6851 @subsubsection How modes are displayed
6852
6853 The Chill Datatype- (Mode) support of @value{GDBN} is directly related
6854 with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
6855 slightly from the standard specification of the Chill language. The
6856 provided modes are:
6857
6858 @c FIXME: this @table's contents effectively disable @code by using @r
6859 @c on every @item. So why does it need @code?
6860 @table @code
6861 @item @r{@emph{Discrete modes:}}
6862 @itemize @bullet
6863 @item
6864 @emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6865 UINT, LONG, ULONG},
6866 @item
6867 @emph{Boolean Mode} which is predefined by @code{BOOL},
6868 @item
6869 @emph{Character Mode} which is predefined by @code{CHAR},
6870 @item
6871 @emph{Set Mode} which is displayed by the keyword @code{SET}.
6872 @smallexample
6873 (@value{GDBP}) ptype x
6874 type = SET (karli = 10, susi = 20, fritzi = 100)
6875 @end smallexample
6876 If the type is an unnumbered set the set element values are omitted.
6877 @item
6878 @emph{Range Mode} which is displayed by
6879 @smallexample
6880 @code{type = <basemode>(<lower bound> : <upper bound>)}
6881 @end smallexample
6882 where @code{<lower bound>, <upper bound>} can be of any discrete literal
6883 expression (e.g. set element names).
6884 @end itemize
6885
6886 @item @r{@emph{Powerset Mode:}}
6887 A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
6888 the member mode of the powerset. The member mode can be any discrete mode.
6889 @smallexample
6890 (@value{GDBP}) ptype x
6891 type = POWERSET SET (egon, hugo, otto)
6892 @end smallexample
6893
6894 @item @r{@emph{Reference Modes:}}
6895 @itemize @bullet
6896 @item
6897 @emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
6898 followed by the mode name to which the reference is bound.
6899 @item
6900 @emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6901 @end itemize
6902
6903 @item @r{@emph{Procedure mode}}
6904 The procedure mode is displayed by @code{type = PROC(<parameter list>)
6905 <return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
6906 list>} is a list of the parameter modes. @code{<return mode>} indicates
6907 the mode of the result of the procedure if any. The exceptionlist lists
6908 all possible exceptions which can be raised by the procedure.
6909
6910 @ignore
6911 @item @r{@emph{Instance mode}}
6912 The instance mode is represented by a structure, which has a static
6913 type, and is therefore not really of interest.
6914 @end ignore
6915
6916 @item @r{@emph{Synchronization Modes:}}
6917 @itemize @bullet
6918 @item
6919 @emph{Event Mode} which is displayed by
6920 @smallexample
6921 @code{EVENT (<event length>)}
6922 @end smallexample
6923 where @code{(<event length>)} is optional.
6924 @item
6925 @emph{Buffer Mode} which is displayed by
6926 @smallexample
6927 @code{BUFFER (<buffer length>)<buffer element mode>}
6928 @end smallexample
6929 where @code{(<buffer length>)} is optional.
6930 @end itemize
6931
6932 @item @r{@emph{Timing Modes:}}
6933 @itemize @bullet
6934 @item
6935 @emph{Duration Mode} which is predefined by @code{DURATION}
6936 @item
6937 @emph{Absolute Time Mode} which is predefined by @code{TIME}
6938 @end itemize
6939
6940 @item @r{@emph{Real Modes:}}
6941 Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6942
6943 @item @r{@emph{String Modes:}}
6944 @itemize @bullet
6945 @item
6946 @emph{Character String Mode} which is displayed by
6947 @smallexample
6948 @code{CHARS(<string length>)}
6949 @end smallexample
6950 followed by the keyword @code{VARYING} if the String Mode is a varying
6951 mode
6952 @item
6953 @emph{Bit String Mode} which is displayed by
6954 @smallexample
6955 @code{BOOLS(<string
6956 length>)}
6957 @end smallexample
6958 @end itemize
6959
6960 @item @r{@emph{Array Mode:}}
6961 The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6962 followed by the element mode (which may in turn be an array mode).
6963 @smallexample
6964 (@value{GDBP}) ptype x
6965 type = ARRAY (1:42)
6966 ARRAY (1:20)
6967 SET (karli = 10, susi = 20, fritzi = 100)
6968 @end smallexample
6969
6970 @item @r{@emph{Structure Mode}}
6971 The Structure mode is displayed by the keyword @code{STRUCT(<field
6972 list>)}. The @code{<field list>} consists of names and modes of fields
6973 of the structure. Variant structures have the keyword @code{CASE <field>
6974 OF <variant fields> ESAC} in their field list. Since the current version
6975 of the GNU Chill compiler doesn't implement tag processing (no runtime
6976 checks of variant fields, and therefore no debugging info), the output
6977 always displays all variant fields.
6978 @smallexample
6979 (@value{GDBP}) ptype str
6980 type = STRUCT (
6981 as x,
6982 bs x,
6983 CASE bs OF
6984 (karli):
6985 cs a
6986 (ott):
6987 ds x
6988 ESAC
6989 )
6990 @end smallexample
6991 @end table
6992
6993 @node Locations
6994 @subsubsection Locations and their accesses
6995
6996 A location in Chill is an object which can contain values.
6997
6998 A value of a location is generally accessed by the (declared) name of
6999 the location. The output conforms to the specification of values in
7000 Chill programs. How values are specified
7001 is the topic of the next section, @ref{Values and their Operations}.
7002
7003 The pseudo-location @code{RESULT} (or @code{result}) can be used to
7004 display or change the result of a currently-active procedure:
7005
7006 @smallexample
7007 set result := EXPR
7008 @end smallexample
7009
7010 @noindent
7011 This does the same as the Chill action @code{RESULT EXPR} (which
7012 is not available in @value{GDBN}).
7013
7014 Values of reference mode locations are printed by @code{PTR(<hex
7015 value>)} in case of a free reference mode, and by @code{(REF <reference
7016 mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
7017 represents the address where the reference points to. To access the
7018 value of the location referenced by the pointer, use the dereference
7019 operator @samp{->}.
7020
7021 Values of procedure mode locations are displayed by
7022 @smallexample
7023 @code{@{ PROC
7024 (<argument modes> ) <return mode> @} <address> <name of procedure
7025 location>}
7026 @end smallexample
7027 @code{<argument modes>} is a list of modes according to the parameter
7028 specification of the procedure and @code{<address>} shows the address of
7029 the entry point.
7030
7031 @ignore
7032 Locations of instance modes are displayed just like a structure with two
7033 fields specifying the @emph{process type} and the @emph{copy number} of
7034 the investigated instance location@footnote{This comes from the current
7035 implementation of instances. They are implemented as a structure (no
7036 na). The output should be something like @code{[<name of the process>;
7037 <instance number>]}.}. The field names are @code{__proc_type} and
7038 @code{__proc_copy}.
7039
7040 Locations of synchronization modes are displayed like a structure with
7041 the field name @code{__event_data} in case of a event mode location, and
7042 like a structure with the field @code{__buffer_data} in case of a buffer
7043 mode location (refer to previous paragraph).
7044
7045 Structure Mode locations are printed by @code{[.<field name>: <value>,
7046 ...]}. The @code{<field name>} corresponds to the structure mode
7047 definition and the layout of @code{<value>} varies depending of the mode
7048 of the field. If the investigated structure mode location is of variant
7049 structure mode, the variant parts of the structure are enclosed in curled
7050 braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
7051 on the same memory location and represent the current values of the
7052 memory location in their specific modes. Since no tag processing is done
7053 all variants are displayed. A variant field is printed by
7054 @code{(<variant name>) = .<field name>: <value>}. (who implements the
7055 stuff ???)
7056 @smallexample
7057 (@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
7058 [.cs: []], (susi) = [.ds: susi]}]
7059 @end smallexample
7060 @end ignore
7061
7062 Substructures of string mode-, array mode- or structure mode-values
7063 (e.g. array slices, fields of structure locations) are accessed using
7064 certain operations which are described in the next section, @ref{Values
7065 and their Operations}.
7066
7067 A location value may be interpreted as having a different mode using the
7068 location conversion. This mode conversion is written as @code{<mode
7069 name>(<location>)}. The user has to consider that the sizes of the modes
7070 have to be equal otherwise an error occurs. Furthermore, no range
7071 checking of the location against the destination mode is performed, and
7072 therefore the result can be quite confusing.
7073
7074 @smallexample
7075 (@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
7076 @end smallexample
7077
7078 @node Values and their Operations
7079 @subsubsection Values and their Operations
7080
7081 Values are used to alter locations, to investigate complex structures in
7082 more detail or to filter relevant information out of a large amount of
7083 data. There are several (mode dependent) operations defined which enable
7084 such investigations. These operations are not only applicable to
7085 constant values but also to locations, which can become quite useful
7086 when debugging complex structures. During parsing the command line
7087 (e.g. evaluating an expression) @value{GDBN} treats location names as
7088 the values behind these locations.
7089
7090 This section describes how values have to be specified and which
7091 operations are legal to be used with such values.
7092
7093 @table @code
7094 @item Literal Values
7095 Literal values are specified in the same manner as in @sc{gnu} Chill programs.
7096 For detailed specification refer to the @sc{gnu} Chill implementation Manual
7097 chapter 1.5.
7098 @c FIXME: if the Chill Manual is a Texinfo documents, the above should
7099 @c be converted to a @ref.
7100
7101 @ignore
7102 @itemize @bullet
7103 @item
7104 @emph{Integer Literals} are specified in the same manner as in Chill
7105 programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
7106 @item
7107 @emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
7108 @item
7109 @emph{Character Literals} are defined by @code{'<character>'}. (e.g.
7110 @code{'M'})
7111 @item
7112 @emph{Set Literals} are defined by a name which was specified in a set
7113 mode. The value delivered by a Set Literal is the set value. This is
7114 comparable to an enumeration in C/C++ language.
7115 @item
7116 @emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
7117 emptiness literal delivers either the empty reference value, the empty
7118 procedure value or the empty instance value.
7119
7120 @item
7121 @emph{Character String Literals} are defined by a sequence of characters
7122 enclosed in single- or double quotes. If a single- or double quote has
7123 to be part of the string literal it has to be stuffed (specified twice).
7124 @item
7125 @emph{Bitstring Literals} are specified in the same manner as in Chill
7126 programs (refer z200/88 chpt 5.2.4.8).
7127 @item
7128 @emph{Floating point literals} are specified in the same manner as in
7129 (gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
7130 @end itemize
7131 @end ignore
7132
7133 @item Tuple Values
7134 A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
7135 name>} can be omitted if the mode of the tuple is unambiguous. This
7136 unambiguity is derived from the context of a evaluated expression.
7137 @code{<tuple>} can be one of the following:
7138
7139 @itemize @bullet
7140 @item @emph{Powerset Tuple}
7141 @item @emph{Array Tuple}
7142 @item @emph{Structure Tuple}
7143 Powerset tuples, array tuples and structure tuples are specified in the
7144 same manner as in Chill programs refer to z200/88 chpt 5.2.5.
7145 @end itemize
7146
7147 @item String Element Value
7148 A string element value is specified by
7149 @smallexample
7150 @code{<string value>(<index>)}
7151 @end smallexample
7152 where @code{<index>} is a integer expression. It delivers a character
7153 value which is equivalent to the character indexed by @code{<index>} in
7154 the string.
7155
7156 @item String Slice Value
7157 A string slice value is specified by @code{<string value>(<slice
7158 spec>)}, where @code{<slice spec>} can be either a range of integer
7159 expressions or specified by @code{<start expr> up <size>}.
7160 @code{<size>} denotes the number of elements which the slice contains.
7161 The delivered value is a string value, which is part of the specified
7162 string.
7163
7164 @item Array Element Values
7165 An array element value is specified by @code{<array value>(<expr>)} and
7166 delivers a array element value of the mode of the specified array.
7167
7168 @item Array Slice Values
7169 An array slice is specified by @code{<array value>(<slice spec>)}, where
7170 @code{<slice spec>} can be either a range specified by expressions or by
7171 @code{<start expr> up <size>}. @code{<size>} denotes the number of
7172 arrayelements the slice contains. The delivered value is an array value
7173 which is part of the specified array.
7174
7175 @item Structure Field Values
7176 A structure field value is derived by @code{<structure value>.<field
7177 name>}, where @code{<field name>} indicates the name of a field specified
7178 in the mode definition of the structure. The mode of the delivered value
7179 corresponds to this mode definition in the structure definition.
7180
7181 @item Procedure Call Value
7182 The procedure call value is derived from the return value of the
7183 procedure@footnote{If a procedure call is used for instance in an
7184 expression, then this procedure is called with all its side
7185 effects. This can lead to confusing results if used carelessly.}.
7186
7187 Values of duration mode locations are represented by @code{ULONG} literals.
7188
7189 Values of time mode locations appear as
7190 @smallexample
7191 @code{TIME(<secs>:<nsecs>)}
7192 @end smallexample
7193
7194
7195 @ignore
7196 This is not implemented yet:
7197 @item Built-in Value
7198 @noindent
7199 The following built in functions are provided:
7200
7201 @table @code
7202 @item @code{ADDR()}
7203 @item @code{NUM()}
7204 @item @code{PRED()}
7205 @item @code{SUCC()}
7206 @item @code{ABS()}
7207 @item @code{CARD()}
7208 @item @code{MAX()}
7209 @item @code{MIN()}
7210 @item @code{SIZE()}
7211 @item @code{UPPER()}
7212 @item @code{LOWER()}
7213 @item @code{LENGTH()}
7214 @item @code{SIN()}
7215 @item @code{COS()}
7216 @item @code{TAN()}
7217 @item @code{ARCSIN()}
7218 @item @code{ARCCOS()}
7219 @item @code{ARCTAN()}
7220 @item @code{EXP()}
7221 @item @code{LN()}
7222 @item @code{LOG()}
7223 @item @code{SQRT()}
7224 @end table
7225
7226 For a detailed description refer to the GNU Chill implementation manual
7227 chapter 1.6.
7228 @end ignore
7229
7230 @item Zero-adic Operator Value
7231 The zero-adic operator value is derived from the instance value for the
7232 current active process.
7233
7234 @item Expression Values
7235 The value delivered by an expression is the result of the evaluation of
7236 the specified expression. If there are error conditions (mode
7237 incompatibility, etc.) the evaluation of expressions is aborted with a
7238 corresponding error message. Expressions may be parenthesised which
7239 causes the evaluation of this expression before any other expression
7240 which uses the result of the parenthesised expression. The following
7241 operators are supported by @value{GDBN}:
7242
7243 @table @code
7244 @item @code{OR, ORIF, XOR}
7245 @itemx @code{AND, ANDIF}
7246 @itemx @code{NOT}
7247 Logical operators defined over operands of boolean mode.
7248
7249 @item @code{=, /=}
7250 Equality and inequality operators defined over all modes.
7251
7252 @item @code{>, >=}
7253 @itemx @code{<, <=}
7254 Relational operators defined over predefined modes.
7255
7256 @item @code{+, -}
7257 @itemx @code{*, /, MOD, REM}
7258 Arithmetic operators defined over predefined modes.
7259
7260 @item @code{-}
7261 Change sign operator.
7262
7263 @item @code{//}
7264 String concatenation operator.
7265
7266 @item @code{()}
7267 String repetition operator.
7268
7269 @item @code{->}
7270 Referenced location operator which can be used either to take the
7271 address of a location (@code{->loc}), or to dereference a reference
7272 location (@code{loc->}).
7273
7274 @item @code{OR, XOR}
7275 @itemx @code{AND}
7276 @itemx @code{NOT}
7277 Powerset and bitstring operators.
7278
7279 @item @code{>, >=}
7280 @itemx @code{<, <=}
7281 Powerset inclusion operators.
7282
7283 @item @code{IN}
7284 Membership operator.
7285 @end table
7286 @end table
7287
7288 @node Chill type and range checks
7289 @subsubsection Chill type and range checks
7290
7291 @value{GDBN} considers two Chill variables mode equivalent if the sizes
7292 of the two modes are equal. This rule applies recursively to more
7293 complex datatypes which means that complex modes are treated
7294 equivalent if all element modes (which also can be complex modes like
7295 structures, arrays, etc.) have the same size.
7296
7297 Range checking is done on all mathematical operations, assignment, array
7298 index bounds and all built in procedures.
7299
7300 Strong type checks are forced using the @value{GDBN} command @code{set
7301 check strong}. This enforces strong type and range checks on all
7302 operations where Chill constructs are used (expressions, built in
7303 functions, etc.) in respect to the semantics as defined in the z.200
7304 language specification.
7305
7306 All checks can be disabled by the @value{GDBN} command @code{set check
7307 off}.
7308
7309 @ignore
7310 @c Deviations from the Chill Standard Z200/88
7311 see last paragraph ?
7312 @end ignore
7313
7314 @node Chill defaults
7315 @subsubsection Chill defaults
7316
7317 If type and range checking are set automatically by @value{GDBN}, they
7318 both default to @code{on} whenever the working language changes to
7319 Chill. This happens regardless of whether you or @value{GDBN}
7320 selected the working language.
7321
7322 If you allow @value{GDBN} to set the language automatically, then entering
7323 code compiled from a file whose name ends with @file{.ch} sets the
7324 working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
7325 the language automatically}, for further details.
7326
7327 @node Symbols
7328 @chapter Examining the Symbol Table
7329
7330 The commands described in this chapter allow you to inquire about the
7331 symbols (names of variables, functions and types) defined in your
7332 program. This information is inherent in the text of your program and
7333 does not change as your program executes. @value{GDBN} finds it in your
7334 program's symbol table, in the file indicated when you started @value{GDBN}
7335 (@pxref{File Options, ,Choosing files}), or by one of the
7336 file-management commands (@pxref{Files, ,Commands to specify files}).
7337
7338 @cindex symbol names
7339 @cindex names of symbols
7340 @cindex quoting names
7341 Occasionally, you may need to refer to symbols that contain unusual
7342 characters, which @value{GDBN} ordinarily treats as word delimiters. The
7343 most frequent case is in referring to static variables in other
7344 source files (@pxref{Variables,,Program variables}). File names
7345 are recorded in object files as debugging symbols, but @value{GDBN} would
7346 ordinarily parse a typical file name, like @file{foo.c}, as the three words
7347 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7348 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7349
7350 @example
7351 p 'foo.c'::x
7352 @end example
7353
7354 @noindent
7355 looks up the value of @code{x} in the scope of the file @file{foo.c}.
7356
7357 @table @code
7358 @kindex info address
7359 @item info address @var{symbol}
7360 Describe where the data for @var{symbol} is stored. For a register
7361 variable, this says which register it is kept in. For a non-register
7362 local variable, this prints the stack-frame offset at which the variable
7363 is always stored.
7364
7365 Note the contrast with @samp{print &@var{symbol}}, which does not work
7366 at all for a register variable, and for a stack local variable prints
7367 the exact address of the current instantiation of the variable.
7368
7369 @kindex whatis
7370 @item whatis @var{expr}
7371 Print the data type of expression @var{expr}. @var{expr} is not
7372 actually evaluated, and any side-effecting operations (such as
7373 assignments or function calls) inside it do not take place.
7374 @xref{Expressions, ,Expressions}.
7375
7376 @item whatis
7377 Print the data type of @code{$}, the last value in the value history.
7378
7379 @kindex ptype
7380 @item ptype @var{typename}
7381 Print a description of data type @var{typename}. @var{typename} may be
7382 the name of a type, or for C code it may have the form @samp{class
7383 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7384 @var{union-tag}} or @samp{enum @var{enum-tag}}.
7385
7386 @item ptype @var{expr}
7387 @itemx ptype
7388 Print a description of the type of expression @var{expr}. @code{ptype}
7389 differs from @code{whatis} by printing a detailed description, instead
7390 of just the name of the type.
7391
7392 For example, for this variable declaration:
7393
7394 @example
7395 struct complex @{double real; double imag;@} v;
7396 @end example
7397
7398 @noindent
7399 the two commands give this output:
7400
7401 @example
7402 @group
7403 (@value{GDBP}) whatis v
7404 type = struct complex
7405 (@value{GDBP}) ptype v
7406 type = struct complex @{
7407 double real;
7408 double imag;
7409 @}
7410 @end group
7411 @end example
7412
7413 @noindent
7414 As with @code{whatis}, using @code{ptype} without an argument refers to
7415 the type of @code{$}, the last value in the value history.
7416
7417 @kindex info types
7418 @item info types @var{regexp}
7419 @itemx info types
7420 Print a brief description of all types whose names match @var{regexp}
7421 (or all types in your program, if you supply no argument). Each
7422 complete typename is matched as though it were a complete line; thus,
7423 @samp{i type value} gives information on all types in your program whose
7424 names include the string @code{value}, but @samp{i type ^value$} gives
7425 information only on types whose complete name is @code{value}.
7426
7427 This command differs from @code{ptype} in two ways: first, like
7428 @code{whatis}, it does not print a detailed description; second, it
7429 lists all source files where a type is defined.
7430
7431 @kindex info source
7432 @item info source
7433 Show the name of the current source file---that is, the source file for
7434 the function containing the current point of execution---and the language
7435 it was written in.
7436
7437 @kindex info sources
7438 @item info sources
7439 Print the names of all source files in your program for which there is
7440 debugging information, organized into two lists: files whose symbols
7441 have already been read, and files whose symbols will be read when needed.
7442
7443 @kindex info functions
7444 @item info functions
7445 Print the names and data types of all defined functions.
7446
7447 @item info functions @var{regexp}
7448 Print the names and data types of all defined functions
7449 whose names contain a match for regular expression @var{regexp}.
7450 Thus, @samp{info fun step} finds all functions whose names
7451 include @code{step}; @samp{info fun ^step} finds those whose names
7452 start with @code{step}.
7453
7454 @kindex info variables
7455 @item info variables
7456 Print the names and data types of all variables that are declared
7457 outside of functions (i.e., excluding local variables).
7458
7459 @item info variables @var{regexp}
7460 Print the names and data types of all variables (except for local
7461 variables) whose names contain a match for regular expression
7462 @var{regexp}.
7463
7464 @ignore
7465 This was never implemented.
7466 @kindex info methods
7467 @item info methods
7468 @itemx info methods @var{regexp}
7469 The @code{info methods} command permits the user to examine all defined
7470 methods within C++ program, or (with the @var{regexp} argument) a
7471 specific set of methods found in the various C++ classes. Many
7472 C++ classes provide a large number of methods. Thus, the output
7473 from the @code{ptype} command can be overwhelming and hard to use. The
7474 @code{info-methods} command filters the methods, printing only those
7475 which match the regular-expression @var{regexp}.
7476 @end ignore
7477
7478 @cindex reloading symbols
7479 Some systems allow individual object files that make up your program to
7480 be replaced without stopping and restarting your program. For example,
7481 in VxWorks you can simply recompile a defective object file and keep on
7482 running. If you are running on one of these systems, you can allow
7483 @value{GDBN} to reload the symbols for automatically relinked modules:
7484
7485 @table @code
7486 @kindex set symbol-reloading
7487 @item set symbol-reloading on
7488 Replace symbol definitions for the corresponding source file when an
7489 object file with a particular name is seen again.
7490
7491 @item set symbol-reloading off
7492 Do not replace symbol definitions when encountering object files of the
7493 same name more than once. This is the default state; if you are not
7494 running on a system that permits automatic relinking of modules, you
7495 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
7496 may discard symbols when linking large programs, that may contain
7497 several modules (from different directories or libraries) with the same
7498 name.
7499
7500 @kindex show symbol-reloading
7501 @item show symbol-reloading
7502 Show the current @code{on} or @code{off} setting.
7503 @end table
7504
7505 @kindex set opaque-type-resolution
7506 @item set opaque-type-resolution on
7507 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7508 declared as a pointer to a @code{struct}, @code{class}, or
7509 @code{union}---for example, @code{struct MyType *}---that is used in one
7510 source file although the full declaration of @code{struct MyType} is in
7511 another source file. The default is on.
7512
7513 A change in the setting of this subcommand will not take effect until
7514 the next time symbols for a file are loaded.
7515
7516 @item set opaque-type-resolution off
7517 Tell @value{GDBN} not to resolve opaque types. In this case, the type
7518 is printed as follows:
7519 @smallexample
7520 @{<no data fields>@}
7521 @end smallexample
7522
7523 @kindex show opaque-type-resolution
7524 @item show opaque-type-resolution
7525 Show whether opaque types are resolved or not.
7526
7527 @kindex maint print symbols
7528 @cindex symbol dump
7529 @kindex maint print psymbols
7530 @cindex partial symbol dump
7531 @item maint print symbols @var{filename}
7532 @itemx maint print psymbols @var{filename}
7533 @itemx maint print msymbols @var{filename}
7534 Write a dump of debugging symbol data into the file @var{filename}.
7535 These commands are used to debug the @value{GDBN} symbol-reading code. Only
7536 symbols with debugging data are included. If you use @samp{maint print
7537 symbols}, @value{GDBN} includes all the symbols for which it has already
7538 collected full details: that is, @var{filename} reflects symbols for
7539 only those files whose symbols @value{GDBN} has read. You can use the
7540 command @code{info sources} to find out which files these are. If you
7541 use @samp{maint print psymbols} instead, the dump shows information about
7542 symbols that @value{GDBN} only knows partially---that is, symbols defined in
7543 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7544 @samp{maint print msymbols} dumps just the minimal symbol information
7545 required for each object file from which @value{GDBN} has read some symbols.
7546 @xref{Files, ,Commands to specify files}, for a discussion of how
7547 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
7548 @end table
7549
7550 @node Altering
7551 @chapter Altering Execution
7552
7553 Once you think you have found an error in your program, you might want to
7554 find out for certain whether correcting the apparent error would lead to
7555 correct results in the rest of the run. You can find the answer by
7556 experiment, using the @value{GDBN} features for altering execution of the
7557 program.
7558
7559 For example, you can store new values into variables or memory
7560 locations, give your program a signal, restart it at a different
7561 address, or even return prematurely from a function.
7562
7563 @menu
7564 * Assignment:: Assignment to variables
7565 * Jumping:: Continuing at a different address
7566 * Signaling:: Giving your program a signal
7567 * Returning:: Returning from a function
7568 * Calling:: Calling your program's functions
7569 * Patching:: Patching your program
7570 @end menu
7571
7572 @node Assignment
7573 @section Assignment to variables
7574
7575 @cindex assignment
7576 @cindex setting variables
7577 To alter the value of a variable, evaluate an assignment expression.
7578 @xref{Expressions, ,Expressions}. For example,
7579
7580 @example
7581 print x=4
7582 @end example
7583
7584 @noindent
7585 stores the value 4 into the variable @code{x}, and then prints the
7586 value of the assignment expression (which is 4).
7587 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7588 information on operators in supported languages.
7589
7590 @kindex set variable
7591 @cindex variables, setting
7592 If you are not interested in seeing the value of the assignment, use the
7593 @code{set} command instead of the @code{print} command. @code{set} is
7594 really the same as @code{print} except that the expression's value is
7595 not printed and is not put in the value history (@pxref{Value History,
7596 ,Value history}). The expression is evaluated only for its effects.
7597
7598 If the beginning of the argument string of the @code{set} command
7599 appears identical to a @code{set} subcommand, use the @code{set
7600 variable} command instead of just @code{set}. This command is identical
7601 to @code{set} except for its lack of subcommands. For example, if your
7602 program has a variable @code{width}, you get an error if you try to set
7603 a new value with just @samp{set width=13}, because @value{GDBN} has the
7604 command @code{set width}:
7605
7606 @example
7607 (@value{GDBP}) whatis width
7608 type = double
7609 (@value{GDBP}) p width
7610 $4 = 13
7611 (@value{GDBP}) set width=47
7612 Invalid syntax in expression.
7613 @end example
7614
7615 @noindent
7616 The invalid expression, of course, is @samp{=47}. In
7617 order to actually set the program's variable @code{width}, use
7618
7619 @example
7620 (@value{GDBP}) set var width=47
7621 @end example
7622
7623 Because the @code{set} command has many subcommands that can conflict
7624 with the names of program variables, it is a good idea to use the
7625 @code{set variable} command instead of just @code{set}. For example, if
7626 your program has a variable @code{g}, you run into problems if you try
7627 to set a new value with just @samp{set g=4}, because @value{GDBN} has
7628 the command @code{set gnutarget}, abbreviated @code{set g}:
7629
7630 @example
7631 @group
7632 (@value{GDBP}) whatis g
7633 type = double
7634 (@value{GDBP}) p g
7635 $1 = 1
7636 (@value{GDBP}) set g=4
7637 (@value{GDBP}) p g
7638 $2 = 1
7639 (@value{GDBP}) r
7640 The program being debugged has been started already.
7641 Start it from the beginning? (y or n) y
7642 Starting program: /home/smith/cc_progs/a.out
7643 "/home/smith/cc_progs/a.out": can't open to read symbols:
7644 Invalid bfd target.
7645 (@value{GDBP}) show g
7646 The current BFD target is "=4".
7647 @end group
7648 @end example
7649
7650 @noindent
7651 The program variable @code{g} did not change, and you silently set the
7652 @code{gnutarget} to an invalid value. In order to set the variable
7653 @code{g}, use
7654
7655 @example
7656 (@value{GDBP}) set var g=4
7657 @end example
7658
7659 @value{GDBN} allows more implicit conversions in assignments than C; you can
7660 freely store an integer value into a pointer variable or vice versa,
7661 and you can convert any structure to any other structure that is the
7662 same length or shorter.
7663 @comment FIXME: how do structs align/pad in these conversions?
7664 @comment /doc@cygnus.com 18dec1990
7665
7666 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7667 construct to generate a value of specified type at a specified address
7668 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7669 to memory location @code{0x83040} as an integer (which implies a certain size
7670 and representation in memory), and
7671
7672 @example
7673 set @{int@}0x83040 = 4
7674 @end example
7675
7676 @noindent
7677 stores the value 4 into that memory location.
7678
7679 @node Jumping
7680 @section Continuing at a different address
7681
7682 Ordinarily, when you continue your program, you do so at the place where
7683 it stopped, with the @code{continue} command. You can instead continue at
7684 an address of your own choosing, with the following commands:
7685
7686 @table @code
7687 @kindex jump
7688 @item jump @var{linespec}
7689 Resume execution at line @var{linespec}. Execution stops again
7690 immediately if there is a breakpoint there. @xref{List, ,Printing
7691 source lines}, for a description of the different forms of
7692 @var{linespec}. It is common practice to use the @code{tbreak} command
7693 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7694 breakpoints}.
7695
7696 The @code{jump} command does not change the current stack frame, or
7697 the stack pointer, or the contents of any memory location or any
7698 register other than the program counter. If line @var{linespec} is in
7699 a different function from the one currently executing, the results may
7700 be bizarre if the two functions expect different patterns of arguments or
7701 of local variables. For this reason, the @code{jump} command requests
7702 confirmation if the specified line is not in the function currently
7703 executing. However, even bizarre results are predictable if you are
7704 well acquainted with the machine-language code of your program.
7705
7706 @item jump *@var{address}
7707 Resume execution at the instruction at address @var{address}.
7708 @end table
7709
7710 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
7711 On many systems, you can get much the same effect as the @code{jump}
7712 command by storing a new value into the register @code{$pc}. The
7713 difference is that this does not start your program running; it only
7714 changes the address of where it @emph{will} run when you continue. For
7715 example,
7716
7717 @example
7718 set $pc = 0x485
7719 @end example
7720
7721 @noindent
7722 makes the next @code{continue} command or stepping command execute at
7723 address @code{0x485}, rather than at the address where your program stopped.
7724 @xref{Continuing and Stepping, ,Continuing and stepping}.
7725
7726 The most common occasion to use the @code{jump} command is to back
7727 up---perhaps with more breakpoints set---over a portion of a program
7728 that has already executed, in order to examine its execution in more
7729 detail.
7730
7731 @c @group
7732 @node Signaling
7733 @section Giving your program a signal
7734
7735 @table @code
7736 @kindex signal
7737 @item signal @var{signal}
7738 Resume execution where your program stopped, but immediately give it the
7739 signal @var{signal}. @var{signal} can be the name or the number of a
7740 signal. For example, on many systems @code{signal 2} and @code{signal
7741 SIGINT} are both ways of sending an interrupt signal.
7742
7743 Alternatively, if @var{signal} is zero, continue execution without
7744 giving a signal. This is useful when your program stopped on account of
7745 a signal and would ordinary see the signal when resumed with the
7746 @code{continue} command; @samp{signal 0} causes it to resume without a
7747 signal.
7748
7749 @code{signal} does not repeat when you press @key{RET} a second time
7750 after executing the command.
7751 @end table
7752 @c @end group
7753
7754 Invoking the @code{signal} command is not the same as invoking the
7755 @code{kill} utility from the shell. Sending a signal with @code{kill}
7756 causes @value{GDBN} to decide what to do with the signal depending on
7757 the signal handling tables (@pxref{Signals}). The @code{signal} command
7758 passes the signal directly to your program.
7759
7760
7761 @node Returning
7762 @section Returning from a function
7763
7764 @table @code
7765 @cindex returning from a function
7766 @kindex return
7767 @item return
7768 @itemx return @var{expression}
7769 You can cancel execution of a function call with the @code{return}
7770 command. If you give an
7771 @var{expression} argument, its value is used as the function's return
7772 value.
7773 @end table
7774
7775 When you use @code{return}, @value{GDBN} discards the selected stack frame
7776 (and all frames within it). You can think of this as making the
7777 discarded frame return prematurely. If you wish to specify a value to
7778 be returned, give that value as the argument to @code{return}.
7779
7780 This pops the selected stack frame (@pxref{Selection, ,Selecting a
7781 frame}), and any other frames inside of it, leaving its caller as the
7782 innermost remaining frame. That frame becomes selected. The
7783 specified value is stored in the registers used for returning values
7784 of functions.
7785
7786 The @code{return} command does not resume execution; it leaves the
7787 program stopped in the state that would exist if the function had just
7788 returned. In contrast, the @code{finish} command (@pxref{Continuing
7789 and Stepping, ,Continuing and stepping}) resumes execution until the
7790 selected stack frame returns naturally.
7791
7792 @node Calling
7793 @section Calling program functions
7794
7795 @cindex calling functions
7796 @kindex call
7797 @table @code
7798 @item call @var{expr}
7799 Evaluate the expression @var{expr} without displaying @code{void}
7800 returned values.
7801 @end table
7802
7803 You can use this variant of the @code{print} command if you want to
7804 execute a function from your program, but without cluttering the output
7805 with @code{void} returned values. If the result is not void, it
7806 is printed and saved in the value history.
7807
7808 For the A29K, a user-controlled variable @code{call_scratch_address},
7809 specifies the location of a scratch area to be used when @value{GDBN}
7810 calls a function in the target. This is necessary because the usual
7811 method of putting the scratch area on the stack does not work in systems
7812 that have separate instruction and data spaces.
7813
7814 @node Patching
7815 @section Patching programs
7816
7817 @cindex patching binaries
7818 @cindex writing into executables
7819 @cindex writing into corefiles
7820
7821 By default, @value{GDBN} opens the file containing your program's
7822 executable code (or the corefile) read-only. This prevents accidental
7823 alterations to machine code; but it also prevents you from intentionally
7824 patching your program's binary.
7825
7826 If you'd like to be able to patch the binary, you can specify that
7827 explicitly with the @code{set write} command. For example, you might
7828 want to turn on internal debugging flags, or even to make emergency
7829 repairs.
7830
7831 @table @code
7832 @kindex set write
7833 @item set write on
7834 @itemx set write off
7835 If you specify @samp{set write on}, @value{GDBN} opens executable and
7836 core files for both reading and writing; if you specify @samp{set write
7837 off} (the default), @value{GDBN} opens them read-only.
7838
7839 If you have already loaded a file, you must load it again (using the
7840 @code{exec-file} or @code{core-file} command) after changing @code{set
7841 write}, for your new setting to take effect.
7842
7843 @item show write
7844 @kindex show write
7845 Display whether executable files and core files are opened for writing
7846 as well as reading.
7847 @end table
7848
7849 @node GDB Files
7850 @chapter @value{GDBN} Files
7851
7852 @value{GDBN} needs to know the file name of the program to be debugged,
7853 both in order to read its symbol table and in order to start your
7854 program. To debug a core dump of a previous run, you must also tell
7855 @value{GDBN} the name of the core dump file.
7856
7857 @menu
7858 * Files:: Commands to specify files
7859 * Symbol Errors:: Errors reading symbol files
7860 @end menu
7861
7862 @node Files
7863 @section Commands to specify files
7864
7865 @cindex symbol table
7866 @cindex core dump file
7867
7868 You may want to specify executable and core dump file names. The usual
7869 way to do this is at start-up time, using the arguments to
7870 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7871 Out of @value{GDBN}}).
7872
7873 Occasionally it is necessary to change to a different file during a
7874 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7875 a file you want to use. In these situations the @value{GDBN} commands
7876 to specify new files are useful.
7877
7878 @table @code
7879 @cindex executable file
7880 @kindex file
7881 @item file @var{filename}
7882 Use @var{filename} as the program to be debugged. It is read for its
7883 symbols and for the contents of pure memory. It is also the program
7884 executed when you use the @code{run} command. If you do not specify a
7885 directory and the file is not found in the @value{GDBN} working directory,
7886 @value{GDBN} uses the environment variable @code{PATH} as a list of
7887 directories to search, just as the shell does when looking for a program
7888 to run. You can change the value of this variable, for both @value{GDBN}
7889 and your program, using the @code{path} command.
7890
7891 On systems with memory-mapped files, an auxiliary file named
7892 @file{@var{filename}.syms} may hold symbol table information for
7893 @var{filename}. If so, @value{GDBN} maps in the symbol table from
7894 @file{@var{filename}.syms}, starting up more quickly. See the
7895 descriptions of the file options @samp{-mapped} and @samp{-readnow}
7896 (available on the command line, and with the commands @code{file},
7897 @code{symbol-file}, or @code{add-symbol-file}, described below),
7898 for more information.
7899
7900 @item file
7901 @code{file} with no argument makes @value{GDBN} discard any information it
7902 has on both executable file and the symbol table.
7903
7904 @kindex exec-file
7905 @item exec-file @r{[} @var{filename} @r{]}
7906 Specify that the program to be run (but not the symbol table) is found
7907 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7908 if necessary to locate your program. Omitting @var{filename} means to
7909 discard information on the executable file.
7910
7911 @kindex symbol-file
7912 @item symbol-file @r{[} @var{filename} @r{]}
7913 Read symbol table information from file @var{filename}. @code{PATH} is
7914 searched when necessary. Use the @code{file} command to get both symbol
7915 table and program to run from the same file.
7916
7917 @code{symbol-file} with no argument clears out @value{GDBN} information on your
7918 program's symbol table.
7919
7920 The @code{symbol-file} command causes @value{GDBN} to forget the contents
7921 of its convenience variables, the value history, and all breakpoints and
7922 auto-display expressions. This is because they may contain pointers to
7923 the internal data recording symbols and data types, which are part of
7924 the old symbol table data being discarded inside @value{GDBN}.
7925
7926 @code{symbol-file} does not repeat if you press @key{RET} again after
7927 executing it once.
7928
7929 When @value{GDBN} is configured for a particular environment, it
7930 understands debugging information in whatever format is the standard
7931 generated for that environment; you may use either a @sc{gnu} compiler, or
7932 other compilers that adhere to the local conventions.
7933 Best results are usually obtained from @sc{gnu} compilers; for example,
7934 using @code{@value{GCC}} you can generate debugging information for
7935 optimized code.
7936
7937 For most kinds of object files, with the exception of old SVR3 systems
7938 using COFF, the @code{symbol-file} command does not normally read the
7939 symbol table in full right away. Instead, it scans the symbol table
7940 quickly to find which source files and which symbols are present. The
7941 details are read later, one source file at a time, as they are needed.
7942
7943 The purpose of this two-stage reading strategy is to make @value{GDBN}
7944 start up faster. For the most part, it is invisible except for
7945 occasional pauses while the symbol table details for a particular source
7946 file are being read. (The @code{set verbose} command can turn these
7947 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7948 warnings and messages}.)
7949
7950 We have not implemented the two-stage strategy for COFF yet. When the
7951 symbol table is stored in COFF format, @code{symbol-file} reads the
7952 symbol table data in full right away. Note that ``stabs-in-COFF''
7953 still does the two-stage strategy, since the debug info is actually
7954 in stabs format.
7955
7956 @kindex readnow
7957 @cindex reading symbols immediately
7958 @cindex symbols, reading immediately
7959 @kindex mapped
7960 @cindex memory-mapped symbol file
7961 @cindex saving symbol table
7962 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7963 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7964 You can override the @value{GDBN} two-stage strategy for reading symbol
7965 tables by using the @samp{-readnow} option with any of the commands that
7966 load symbol table information, if you want to be sure @value{GDBN} has the
7967 entire symbol table available.
7968
7969 If memory-mapped files are available on your system through the
7970 @code{mmap} system call, you can use another option, @samp{-mapped}, to
7971 cause @value{GDBN} to write the symbols for your program into a reusable
7972 file. Future @value{GDBN} debugging sessions map in symbol information
7973 from this auxiliary symbol file (if the program has not changed), rather
7974 than spending time reading the symbol table from the executable
7975 program. Using the @samp{-mapped} option has the same effect as
7976 starting @value{GDBN} with the @samp{-mapped} command-line option.
7977
7978 You can use both options together, to make sure the auxiliary symbol
7979 file has all the symbol information for your program.
7980
7981 The auxiliary symbol file for a program called @var{myprog} is called
7982 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7983 than the corresponding executable), @value{GDBN} always attempts to use
7984 it when you debug @var{myprog}; no special options or commands are
7985 needed.
7986
7987 The @file{.syms} file is specific to the host machine where you run
7988 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
7989 symbol table. It cannot be shared across multiple host platforms.
7990
7991 @c FIXME: for now no mention of directories, since this seems to be in
7992 @c flux. 13mar1992 status is that in theory GDB would look either in
7993 @c current dir or in same dir as myprog; but issues like competing
7994 @c GDB's, or clutter in system dirs, mean that in practice right now
7995 @c only current dir is used. FFish says maybe a special GDB hierarchy
7996 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7997 @c files.
7998
7999 @kindex core
8000 @kindex core-file
8001 @item core-file @r{[} @var{filename} @r{]}
8002 Specify the whereabouts of a core dump file to be used as the ``contents
8003 of memory''. Traditionally, core files contain only some parts of the
8004 address space of the process that generated them; @value{GDBN} can access the
8005 executable file itself for other parts.
8006
8007 @code{core-file} with no argument specifies that no core file is
8008 to be used.
8009
8010 Note that the core file is ignored when your program is actually running
8011 under @value{GDBN}. So, if you have been running your program and you
8012 wish to debug a core file instead, you must kill the subprocess in which
8013 the program is running. To do this, use the @code{kill} command
8014 (@pxref{Kill Process, ,Killing the child process}).
8015
8016 @kindex add-symbol-file
8017 @cindex dynamic linking
8018 @item add-symbol-file @var{filename} @var{address}
8019 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
8020 @itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address}
8021 The @code{add-symbol-file} command reads additional symbol table
8022 information from the file @var{filename}. You would use this command
8023 when @var{filename} has been dynamically loaded (by some other means)
8024 into the program that is running. @var{address} should be the memory
8025 address at which the file has been loaded; @value{GDBN} cannot figure
8026 this out for itself. You can additionally specify an arbitrary number
8027 of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
8028 section name and base address for that section. You can specify any
8029 @var{address} as an expression.
8030
8031 The symbol table of the file @var{filename} is added to the symbol table
8032 originally read with the @code{symbol-file} command. You can use the
8033 @code{add-symbol-file} command any number of times; the new symbol data
8034 thus read keeps adding to the old. To discard all old symbol data
8035 instead, use the @code{symbol-file} command without any arguments.
8036
8037 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
8038
8039 You can use the @samp{-mapped} and @samp{-readnow} options just as with
8040 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
8041 table information for @var{filename}.
8042
8043 @kindex add-shared-symbol-file
8044 @item add-shared-symbol-file
8045 The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
8046 operating system for the Motorola 88k. @value{GDBN} automatically looks for
8047 shared libraries, however if @value{GDBN} does not find yours, you can run
8048 @code{add-shared-symbol-file}. It takes no arguments.
8049
8050 @kindex section
8051 @item section
8052 The @code{section} command changes the base address of section SECTION of
8053 the exec file to ADDR. This can be used if the exec file does not contain
8054 section addresses, (such as in the a.out format), or when the addresses
8055 specified in the file itself are wrong. Each section must be changed
8056 separately. The @code{info files} command, described below, lists all
8057 the sections and their addresses.
8058
8059 @kindex info files
8060 @kindex info target
8061 @item info files
8062 @itemx info target
8063 @code{info files} and @code{info target} are synonymous; both print the
8064 current target (@pxref{Targets, ,Specifying a Debugging Target}),
8065 including the names of the executable and core dump files currently in
8066 use by @value{GDBN}, and the files from which symbols were loaded. The
8067 command @code{help target} lists all possible targets rather than
8068 current ones.
8069
8070 @end table
8071
8072 All file-specifying commands allow both absolute and relative file names
8073 as arguments. @value{GDBN} always converts the file name to an absolute file
8074 name and remembers it that way.
8075
8076 @cindex shared libraries
8077 @value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
8078 libraries.
8079
8080 @value{GDBN} automatically loads symbol definitions from shared libraries
8081 when you use the @code{run} command, or when you examine a core file.
8082 (Before you issue the @code{run} command, @value{GDBN} does not understand
8083 references to a function in a shared library, however---unless you are
8084 debugging a core file).
8085
8086 On HP-UX, if the program loads a library explicitly, @value{GDBN}
8087 automatically loads the symbols at the time of the @code{shl_load} call.
8088
8089 @c FIXME: some @value{GDBN} release may permit some refs to undef
8090 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
8091 @c FIXME...lib; check this from time to time when updating manual
8092
8093 @table @code
8094 @kindex info sharedlibrary
8095 @kindex info share
8096 @item info share
8097 @itemx info sharedlibrary
8098 Print the names of the shared libraries which are currently loaded.
8099
8100 @kindex sharedlibrary
8101 @kindex share
8102 @item sharedlibrary @var{regex}
8103 @itemx share @var{regex}
8104 Load shared object library symbols for files matching a
8105 Unix regular expression.
8106 As with files loaded automatically, it only loads shared libraries
8107 required by your program for a core file or after typing @code{run}. If
8108 @var{regex} is omitted all shared libraries required by your program are
8109 loaded.
8110 @end table
8111
8112 On HP-UX systems, @value{GDBN} detects the loading of a shared library
8113 and automatically reads in symbols from the newly loaded library, up to
8114 a threshold that is initially set but that you can modify if you wish.
8115
8116 Beyond that threshold, symbols from shared libraries must be explicitly
8117 loaded. To load these symbols, use the command @code{sharedlibrary
8118 @var{filename}}. The base address of the shared library is determined
8119 automatically by @value{GDBN} and need not be specified.
8120
8121 To display or set the threshold, use the commands:
8122
8123 @table @code
8124 @kindex set auto-solib-add
8125 @item set auto-solib-add @var{threshold}
8126 Set the autoloading size threshold, in megabytes. If @var{threshold} is
8127 nonzero, symbols from all shared object libraries will be loaded
8128 automatically when the inferior begins execution or when the dynamic
8129 linker informs @value{GDBN} that a new library has been loaded, until
8130 the symbol table of the program and libraries exceeds this threshold.
8131 Otherwise, symbols must be loaded manually, using the
8132 @code{sharedlibrary} command. The default threshold is 100 megabytes.
8133
8134 @kindex show auto-solib-add
8135 @item show auto-solib-add
8136 Display the current autoloading size threshold, in megabytes.
8137 @end table
8138
8139 @node Symbol Errors
8140 @section Errors reading symbol files
8141
8142 While reading a symbol file, @value{GDBN} occasionally encounters problems,
8143 such as symbol types it does not recognize, or known bugs in compiler
8144 output. By default, @value{GDBN} does not notify you of such problems, since
8145 they are relatively common and primarily of interest to people
8146 debugging compilers. If you are interested in seeing information
8147 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
8148 only one message about each such type of problem, no matter how many
8149 times the problem occurs; or you can ask @value{GDBN} to print more messages,
8150 to see how many times the problems occur, with the @code{set
8151 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
8152 messages}).
8153
8154 The messages currently printed, and their meanings, include:
8155
8156 @table @code
8157 @item inner block not inside outer block in @var{symbol}
8158
8159 The symbol information shows where symbol scopes begin and end
8160 (such as at the start of a function or a block of statements). This
8161 error indicates that an inner scope block is not fully contained
8162 in its outer scope blocks.
8163
8164 @value{GDBN} circumvents the problem by treating the inner block as if it had
8165 the same scope as the outer block. In the error message, @var{symbol}
8166 may be shown as ``@code{(don't know)}'' if the outer block is not a
8167 function.
8168
8169 @item block at @var{address} out of order
8170
8171 The symbol information for symbol scope blocks should occur in
8172 order of increasing addresses. This error indicates that it does not
8173 do so.
8174
8175 @value{GDBN} does not circumvent this problem, and has trouble
8176 locating symbols in the source file whose symbols it is reading. (You
8177 can often determine what source file is affected by specifying
8178 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
8179 messages}.)
8180
8181 @item bad block start address patched
8182
8183 The symbol information for a symbol scope block has a start address
8184 smaller than the address of the preceding source line. This is known
8185 to occur in the SunOS 4.1.1 (and earlier) C compiler.
8186
8187 @value{GDBN} circumvents the problem by treating the symbol scope block as
8188 starting on the previous source line.
8189
8190 @item bad string table offset in symbol @var{n}
8191
8192 @cindex foo
8193 Symbol number @var{n} contains a pointer into the string table which is
8194 larger than the size of the string table.
8195
8196 @value{GDBN} circumvents the problem by considering the symbol to have the
8197 name @code{foo}, which may cause other problems if many symbols end up
8198 with this name.
8199
8200 @item unknown symbol type @code{0x@var{nn}}
8201
8202 The symbol information contains new data types that @value{GDBN} does
8203 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
8204 uncomprehended information, in hexadecimal.
8205
8206 @value{GDBN} circumvents the error by ignoring this symbol information.
8207 This usually allows you to debug your program, though certain symbols
8208 are not accessible. If you encounter such a problem and feel like
8209 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
8210 on @code{complain}, then go up to the function @code{read_dbx_symtab}
8211 and examine @code{*bufp} to see the symbol.
8212
8213 @item stub type has NULL name
8214
8215 @value{GDBN} could not find the full definition for a struct or class.
8216
8217 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
8218 The symbol information for a C++ member function is missing some
8219 information that recent versions of the compiler should have output for
8220 it.
8221
8222 @item info mismatch between compiler and debugger
8223
8224 @value{GDBN} could not parse a type specification output by the compiler.
8225
8226 @end table
8227
8228 @node Targets
8229 @chapter Specifying a Debugging Target
8230
8231 @cindex debugging target
8232 @kindex target
8233
8234 A @dfn{target} is the execution environment occupied by your program.
8235
8236 Often, @value{GDBN} runs in the same host environment as your program;
8237 in that case, the debugging target is specified as a side effect when
8238 you use the @code{file} or @code{core} commands. When you need more
8239 flexibility---for example, running @value{GDBN} on a physically separate
8240 host, or controlling a standalone system over a serial port or a
8241 realtime system over a TCP/IP connection---you can use the @code{target}
8242 command to specify one of the target types configured for @value{GDBN}
8243 (@pxref{Target Commands, ,Commands for managing targets}).
8244
8245 @menu
8246 * Active Targets:: Active targets
8247 * Target Commands:: Commands for managing targets
8248 * Byte Order:: Choosing target byte order
8249 * Remote:: Remote debugging
8250 * KOD:: Kernel Object Display
8251
8252 @end menu
8253
8254 @node Active Targets
8255 @section Active targets
8256
8257 @cindex stacking targets
8258 @cindex active targets
8259 @cindex multiple targets
8260
8261 There are three classes of targets: processes, core files, and
8262 executable files. @value{GDBN} can work concurrently on up to three
8263 active targets, one in each class. This allows you to (for example)
8264 start a process and inspect its activity without abandoning your work on
8265 a core file.
8266
8267 For example, if you execute @samp{gdb a.out}, then the executable file
8268 @code{a.out} is the only active target. If you designate a core file as
8269 well---presumably from a prior run that crashed and coredumped---then
8270 @value{GDBN} has two active targets and uses them in tandem, looking
8271 first in the corefile target, then in the executable file, to satisfy
8272 requests for memory addresses. (Typically, these two classes of target
8273 are complementary, since core files contain only a program's
8274 read-write memory---variables and so on---plus machine status, while
8275 executable files contain only the program text and initialized data.)
8276
8277 When you type @code{run}, your executable file becomes an active process
8278 target as well. When a process target is active, all @value{GDBN}
8279 commands requesting memory addresses refer to that target; addresses in
8280 an active core file or executable file target are obscured while the
8281 process target is active.
8282
8283 Use the @code{core-file} and @code{exec-file} commands to select a new
8284 core file or executable target (@pxref{Files, ,Commands to specify
8285 files}). To specify as a target a process that is already running, use
8286 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8287 process}).
8288
8289 @node Target Commands
8290 @section Commands for managing targets
8291
8292 @table @code
8293 @item target @var{type} @var{parameters}
8294 Connects the @value{GDBN} host environment to a target machine or
8295 process. A target is typically a protocol for talking to debugging
8296 facilities. You use the argument @var{type} to specify the type or
8297 protocol of the target machine.
8298
8299 Further @var{parameters} are interpreted by the target protocol, but
8300 typically include things like device names or host names to connect
8301 with, process numbers, and baud rates.
8302
8303 The @code{target} command does not repeat if you press @key{RET} again
8304 after executing the command.
8305
8306 @kindex help target
8307 @item help target
8308 Displays the names of all targets available. To display targets
8309 currently selected, use either @code{info target} or @code{info files}
8310 (@pxref{Files, ,Commands to specify files}).
8311
8312 @item help target @var{name}
8313 Describe a particular target, including any parameters necessary to
8314 select it.
8315
8316 @kindex set gnutarget
8317 @item set gnutarget @var{args}
8318 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
8319 knows whether it is reading an @dfn{executable},
8320 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8321 with the @code{set gnutarget} command. Unlike most @code{target} commands,
8322 with @code{gnutarget} the @code{target} refers to a program, not a machine.
8323
8324 @quotation
8325 @emph{Warning:} To specify a file format with @code{set gnutarget},
8326 you must know the actual BFD name.
8327 @end quotation
8328
8329 @noindent
8330 @xref{Files, , Commands to specify files}.
8331
8332 @kindex show gnutarget
8333 @item show gnutarget
8334 Use the @code{show gnutarget} command to display what file format
8335 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
8336 @value{GDBN} will determine the file format for each file automatically,
8337 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8338 @end table
8339
8340 Here are some common targets (available, or not, depending on the GDB
8341 configuration):
8342
8343 @table @code
8344 @kindex target exec
8345 @item target exec @var{program}
8346 An executable file. @samp{target exec @var{program}} is the same as
8347 @samp{exec-file @var{program}}.
8348
8349 @kindex target core
8350 @item target core @var{filename}
8351 A core dump file. @samp{target core @var{filename}} is the same as
8352 @samp{core-file @var{filename}}.
8353
8354 @kindex target remote
8355 @item target remote @var{dev}
8356 Remote serial target in GDB-specific protocol. The argument @var{dev}
8357 specifies what serial device to use for the connection (e.g.
8358 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
8359 supports the @code{load} command. This is only useful if you have
8360 some other way of getting the stub to the target system, and you can put
8361 it somewhere in memory where it won't get clobbered by the download.
8362
8363 @kindex target sim
8364 @item target sim
8365 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
8366 In general,
8367 @example
8368 target sim
8369 load
8370 run
8371 @end example
8372 @noindent
8373 works; however, you cannot assume that a specific memory map, device
8374 drivers, or even basic I/O is available, although some simulators do
8375 provide these. For info about any processor-specific simulator details,
8376 see the appropriate section in @ref{Embedded Processors, ,Embedded
8377 Processors}.
8378
8379 @end table
8380
8381 Some configurations may include these targets as well:
8382
8383 @table @code
8384
8385 @kindex target nrom
8386 @item target nrom @var{dev}
8387 NetROM ROM emulator. This target only supports downloading.
8388
8389 @end table
8390
8391 Different targets are available on different configurations of @value{GDBN};
8392 your configuration may have more or fewer targets.
8393
8394 Many remote targets require you to download the executable's code
8395 once you've successfully established a connection.
8396
8397 @table @code
8398
8399 @kindex load @var{filename}
8400 @item load @var{filename}
8401 Depending on what remote debugging facilities are configured into
8402 @value{GDBN}, the @code{load} command may be available. Where it exists, it
8403 is meant to make @var{filename} (an executable) available for debugging
8404 on the remote system---by downloading, or dynamic linking, for example.
8405 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8406 the @code{add-symbol-file} command.
8407
8408 If your @value{GDBN} does not have a @code{load} command, attempting to
8409 execute it gets the error message ``@code{You can't do that when your
8410 target is @dots{}}''
8411
8412 The file is loaded at whatever address is specified in the executable.
8413 For some object file formats, you can specify the load address when you
8414 link the program; for other formats, like a.out, the object file format
8415 specifies a fixed address.
8416 @c FIXME! This would be a good place for an xref to the GNU linker doc.
8417
8418 @code{load} does not repeat if you press @key{RET} again after using it.
8419 @end table
8420
8421 @node Byte Order
8422 @section Choosing target byte order
8423
8424 @cindex choosing target byte order
8425 @cindex target byte order
8426
8427 Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8428 offer the ability to run either big-endian or little-endian byte
8429 orders. Usually the executable or symbol will include a bit to
8430 designate the endian-ness, and you will not need to worry about
8431 which to use. However, you may still find it useful to adjust
8432 @value{GDBN}'s idea of processor endian-ness manually.
8433
8434 @table @code
8435 @kindex set endian big
8436 @item set endian big
8437 Instruct @value{GDBN} to assume the target is big-endian.
8438
8439 @kindex set endian little
8440 @item set endian little
8441 Instruct @value{GDBN} to assume the target is little-endian.
8442
8443 @kindex set endian auto
8444 @item set endian auto
8445 Instruct @value{GDBN} to use the byte order associated with the
8446 executable.
8447
8448 @item show endian
8449 Display @value{GDBN}'s current idea of the target byte order.
8450
8451 @end table
8452
8453 Note that these commands merely adjust interpretation of symbolic
8454 data on the host, and that they have absolutely no effect on the
8455 target system.
8456
8457 @node Remote
8458 @section Remote debugging
8459 @cindex remote debugging
8460
8461 If you are trying to debug a program running on a machine that cannot run
8462 @value{GDBN} in the usual way, it is often useful to use remote debugging.
8463 For example, you might use remote debugging on an operating system kernel,
8464 or on a small system which does not have a general purpose operating system
8465 powerful enough to run a full-featured debugger.
8466
8467 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8468 to make this work with particular debugging targets. In addition,
8469 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
8470 but not specific to any particular target system) which you can use if you
8471 write the remote stubs---the code that runs on the remote system to
8472 communicate with @value{GDBN}.
8473
8474 Other remote targets may be available in your
8475 configuration of @value{GDBN}; use @code{help target} to list them.
8476
8477 @menu
8478 * Remote Serial:: @value{GDBN} remote serial protocol
8479 @end menu
8480
8481 @node Remote Serial
8482 @subsection The @value{GDBN} remote serial protocol
8483
8484 @cindex remote serial debugging, overview
8485 To debug a program running on another machine (the debugging
8486 @dfn{target} machine), you must first arrange for all the usual
8487 prerequisites for the program to run by itself. For example, for a C
8488 program, you need:
8489
8490 @enumerate
8491 @item
8492 A startup routine to set up the C runtime environment; these usually
8493 have a name like @file{crt0}. The startup routine may be supplied by
8494 your hardware supplier, or you may have to write your own.
8495
8496 @item
8497 A C subroutine library to support your program's
8498 subroutine calls, notably managing input and output.
8499
8500 @item
8501 A way of getting your program to the other machine---for example, a
8502 download program. These are often supplied by the hardware
8503 manufacturer, but you may have to write your own from hardware
8504 documentation.
8505 @end enumerate
8506
8507 The next step is to arrange for your program to use a serial port to
8508 communicate with the machine where @value{GDBN} is running (the @dfn{host}
8509 machine). In general terms, the scheme looks like this:
8510
8511 @table @emph
8512 @item On the host,
8513 @value{GDBN} already understands how to use this protocol; when everything
8514 else is set up, you can simply use the @samp{target remote} command
8515 (@pxref{Targets,,Specifying a Debugging Target}).
8516
8517 @item On the target,
8518 you must link with your program a few special-purpose subroutines that
8519 implement the @value{GDBN} remote serial protocol. The file containing these
8520 subroutines is called a @dfn{debugging stub}.
8521
8522 On certain remote targets, you can use an auxiliary program
8523 @code{gdbserver} instead of linking a stub into your program.
8524 @xref{Server,,Using the @code{gdbserver} program}, for details.
8525 @end table
8526
8527 The debugging stub is specific to the architecture of the remote
8528 machine; for example, use @file{sparc-stub.c} to debug programs on
8529 @sc{sparc} boards.
8530
8531 @cindex remote serial stub list
8532 These working remote stubs are distributed with @value{GDBN}:
8533
8534 @table @code
8535
8536 @item i386-stub.c
8537 @cindex @file{i386-stub.c}
8538 @cindex Intel
8539 @cindex i386
8540 For Intel 386 and compatible architectures.
8541
8542 @item m68k-stub.c
8543 @cindex @file{m68k-stub.c}
8544 @cindex Motorola 680x0
8545 @cindex m680x0
8546 For Motorola 680x0 architectures.
8547
8548 @item sh-stub.c
8549 @cindex @file{sh-stub.c}
8550 @cindex Hitachi
8551 @cindex SH
8552 For Hitachi SH architectures.
8553
8554 @item sparc-stub.c
8555 @cindex @file{sparc-stub.c}
8556 @cindex Sparc
8557 For @sc{sparc} architectures.
8558
8559 @item sparcl-stub.c
8560 @cindex @file{sparcl-stub.c}
8561 @cindex Fujitsu
8562 @cindex SparcLite
8563 For Fujitsu @sc{sparclite} architectures.
8564
8565 @end table
8566
8567 The @file{README} file in the @value{GDBN} distribution may list other
8568 recently added stubs.
8569
8570 @menu
8571 * Stub Contents:: What the stub can do for you
8572 * Bootstrapping:: What you must do for the stub
8573 * Debug Session:: Putting it all together
8574 * Protocol:: Definition of the communication protocol
8575 * Server:: Using the `gdbserver' program
8576 * NetWare:: Using the `gdbserve.nlm' program
8577 @end menu
8578
8579 @node Stub Contents
8580 @subsubsection What the stub can do for you
8581
8582 @cindex remote serial stub
8583 The debugging stub for your architecture supplies these three
8584 subroutines:
8585
8586 @table @code
8587 @item set_debug_traps
8588 @kindex set_debug_traps
8589 @cindex remote serial stub, initialization
8590 This routine arranges for @code{handle_exception} to run when your
8591 program stops. You must call this subroutine explicitly near the
8592 beginning of your program.
8593
8594 @item handle_exception
8595 @kindex handle_exception
8596 @cindex remote serial stub, main routine
8597 This is the central workhorse, but your program never calls it
8598 explicitly---the setup code arranges for @code{handle_exception} to
8599 run when a trap is triggered.
8600
8601 @code{handle_exception} takes control when your program stops during
8602 execution (for example, on a breakpoint), and mediates communications
8603 with @value{GDBN} on the host machine. This is where the communications
8604 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
8605 representative on the target machine. It begins by sending summary
8606 information on the state of your program, then continues to execute,
8607 retrieving and transmitting any information @value{GDBN} needs, until you
8608 execute a @value{GDBN} command that makes your program resume; at that point,
8609 @code{handle_exception} returns control to your own code on the target
8610 machine.
8611
8612 @item breakpoint
8613 @cindex @code{breakpoint} subroutine, remote
8614 Use this auxiliary subroutine to make your program contain a
8615 breakpoint. Depending on the particular situation, this may be the only
8616 way for @value{GDBN} to get control. For instance, if your target
8617 machine has some sort of interrupt button, you won't need to call this;
8618 pressing the interrupt button transfers control to
8619 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
8620 simply receiving characters on the serial port may also trigger a trap;
8621 again, in that situation, you don't need to call @code{breakpoint} from
8622 your own program---simply running @samp{target remote} from the host
8623 @value{GDBN} session gets control.
8624
8625 Call @code{breakpoint} if none of these is true, or if you simply want
8626 to make certain your program stops at a predetermined point for the
8627 start of your debugging session.
8628 @end table
8629
8630 @node Bootstrapping
8631 @subsubsection What you must do for the stub
8632
8633 @cindex remote stub, support routines
8634 The debugging stubs that come with @value{GDBN} are set up for a particular
8635 chip architecture, but they have no information about the rest of your
8636 debugging target machine.
8637
8638 First of all you need to tell the stub how to communicate with the
8639 serial port.
8640
8641 @table @code
8642 @item int getDebugChar()
8643 @kindex getDebugChar
8644 Write this subroutine to read a single character from the serial port.
8645 It may be identical to @code{getchar} for your target system; a
8646 different name is used to allow you to distinguish the two if you wish.
8647
8648 @item void putDebugChar(int)
8649 @kindex putDebugChar
8650 Write this subroutine to write a single character to the serial port.
8651 It may be identical to @code{putchar} for your target system; a
8652 different name is used to allow you to distinguish the two if you wish.
8653 @end table
8654
8655 @cindex control C, and remote debugging
8656 @cindex interrupting remote targets
8657 If you want @value{GDBN} to be able to stop your program while it is
8658 running, you need to use an interrupt-driven serial driver, and arrange
8659 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
8660 character). That is the character which @value{GDBN} uses to tell the
8661 remote system to stop.
8662
8663 Getting the debugging target to return the proper status to @value{GDBN}
8664 probably requires changes to the standard stub; one quick and dirty way
8665 is to just execute a breakpoint instruction (the ``dirty'' part is that
8666 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
8667
8668 Other routines you need to supply are:
8669
8670 @table @code
8671 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
8672 @kindex exceptionHandler
8673 Write this function to install @var{exception_address} in the exception
8674 handling tables. You need to do this because the stub does not have any
8675 way of knowing what the exception handling tables on your target system
8676 are like (for example, the processor's table might be in @sc{rom},
8677 containing entries which point to a table in @sc{ram}).
8678 @var{exception_number} is the exception number which should be changed;
8679 its meaning is architecture-dependent (for example, different numbers
8680 might represent divide by zero, misaligned access, etc). When this
8681 exception occurs, control should be transferred directly to
8682 @var{exception_address}, and the processor state (stack, registers,
8683 and so on) should be just as it is when a processor exception occurs. So if
8684 you want to use a jump instruction to reach @var{exception_address}, it
8685 should be a simple jump, not a jump to subroutine.
8686
8687 For the 386, @var{exception_address} should be installed as an interrupt
8688 gate so that interrupts are masked while the handler runs. The gate
8689 should be at privilege level 0 (the most privileged level). The
8690 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
8691 help from @code{exceptionHandler}.
8692
8693 @item void flush_i_cache()
8694 @kindex flush_i_cache
8695 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
8696 instruction cache, if any, on your target machine. If there is no
8697 instruction cache, this subroutine may be a no-op.
8698
8699 On target machines that have instruction caches, @value{GDBN} requires this
8700 function to make certain that the state of your program is stable.
8701 @end table
8702
8703 @noindent
8704 You must also make sure this library routine is available:
8705
8706 @table @code
8707 @item void *memset(void *, int, int)
8708 @kindex memset
8709 This is the standard library function @code{memset} that sets an area of
8710 memory to a known value. If you have one of the free versions of
8711 @code{libc.a}, @code{memset} can be found there; otherwise, you must
8712 either obtain it from your hardware manufacturer, or write your own.
8713 @end table
8714
8715 If you do not use the GNU C compiler, you may need other standard
8716 library subroutines as well; this varies from one stub to another,
8717 but in general the stubs are likely to use any of the common library
8718 subroutines which @code{@value{GCC}} generates as inline code.
8719
8720
8721 @node Debug Session
8722 @subsubsection Putting it all together
8723
8724 @cindex remote serial debugging summary
8725 In summary, when your program is ready to debug, you must follow these
8726 steps.
8727
8728 @enumerate
8729 @item
8730 Make sure you have defined the supporting low-level routines
8731 (@pxref{Bootstrapping,,What you must do for the stub}):
8732 @display
8733 @code{getDebugChar}, @code{putDebugChar},
8734 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
8735 @end display
8736
8737 @item
8738 Insert these lines near the top of your program:
8739
8740 @example
8741 set_debug_traps();
8742 breakpoint();
8743 @end example
8744
8745 @item
8746 For the 680x0 stub only, you need to provide a variable called
8747 @code{exceptionHook}. Normally you just use:
8748
8749 @example
8750 void (*exceptionHook)() = 0;
8751 @end example
8752
8753 @noindent
8754 but if before calling @code{set_debug_traps}, you set it to point to a
8755 function in your program, that function is called when
8756 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
8757 error). The function indicated by @code{exceptionHook} is called with
8758 one parameter: an @code{int} which is the exception number.
8759
8760 @item
8761 Compile and link together: your program, the @value{GDBN} debugging stub for
8762 your target architecture, and the supporting subroutines.
8763
8764 @item
8765 Make sure you have a serial connection between your target machine and
8766 the @value{GDBN} host, and identify the serial port on the host.
8767
8768 @item
8769 @c The "remote" target now provides a `load' command, so we should
8770 @c document that. FIXME.
8771 Download your program to your target machine (or get it there by
8772 whatever means the manufacturer provides), and start it.
8773
8774 @item
8775 To start remote debugging, run @value{GDBN} on the host machine, and specify
8776 as an executable file the program that is running in the remote machine.
8777 This tells @value{GDBN} how to find your program's symbols and the contents
8778 of its pure text.
8779
8780 @item
8781 @cindex serial line, @code{target remote}
8782 Establish communication using the @code{target remote} command.
8783 Its argument specifies how to communicate with the target
8784 machine---either via a devicename attached to a direct serial line, or a
8785 TCP port (usually to a terminal server which in turn has a serial line
8786 to the target). For example, to use a serial line connected to the
8787 device named @file{/dev/ttyb}:
8788
8789 @example
8790 target remote /dev/ttyb
8791 @end example
8792
8793 @cindex TCP port, @code{target remote}
8794 To use a TCP connection, use an argument of the form
8795 @code{@var{host}:port}. For example, to connect to port 2828 on a
8796 terminal server named @code{manyfarms}:
8797
8798 @example
8799 target remote manyfarms:2828
8800 @end example
8801 @end enumerate
8802
8803 Now you can use all the usual commands to examine and change data and to
8804 step and continue the remote program.
8805
8806 To resume the remote program and stop debugging it, use the @code{detach}
8807 command.
8808
8809 @cindex interrupting remote programs
8810 @cindex remote programs, interrupting
8811 Whenever @value{GDBN} is waiting for the remote program, if you type the
8812 interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
8813 program. This may or may not succeed, depending in part on the hardware
8814 and the serial drivers the remote system uses. If you type the
8815 interrupt character once again, @value{GDBN} displays this prompt:
8816
8817 @example
8818 Interrupted while waiting for the program.
8819 Give up (and stop debugging it)? (y or n)
8820 @end example
8821
8822 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
8823 (If you decide you want to try again later, you can use @samp{target
8824 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
8825 goes back to waiting.
8826
8827 @node Protocol
8828 @subsubsection Communication protocol
8829
8830 @cindex debugging stub, example
8831 @cindex remote stub, example
8832 @cindex stub example, remote debugging
8833 The stub files provided with @value{GDBN} implement the target side of the
8834 communication protocol, and the @value{GDBN} side is implemented in the
8835 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
8836 these subroutines to communicate, and ignore the details. (If you're
8837 implementing your own stub file, you can still ignore the details: start
8838 with one of the existing stub files. @file{sparc-stub.c} is the best
8839 organized, and therefore the easiest to read.)
8840
8841 However, there may be occasions when you need to know something about
8842 the protocol---for example, if there is only one serial port to your
8843 target machine, you might want your program to do something special if
8844 it recognizes a packet meant for @value{GDBN}.
8845
8846 In the examples below, @samp{<-} and @samp{->} are used to indicate
8847 transmitted and received data respectfully.
8848
8849 @cindex protocol, @value{GDBN} remote serial
8850 @cindex serial protocol, @value{GDBN} remote
8851 @cindex remote serial protocol
8852 All @value{GDBN} commands and responses (other than acknowledgments) are
8853 sent as a @var{packet}. A @var{packet} is introduced with the character
8854 @samp{$}, the actual @var{packet-data}, and the terminating character
8855 @samp{#} followed by a two-digit @var{checksum}:
8856
8857 @example
8858 @code{$}@var{packet-data}@code{#}@var{checksum}
8859 @end example
8860 @noindent
8861
8862 @cindex checksum, for @value{GDBN} remote
8863 @noindent
8864 The two-digit @var{checksum} is computed as the modulo 256 sum of all
8865 characters between the leading @samp{$} and the trailing @samp{#} (an
8866 eight bit unsigned checksum).
8867
8868 Implementors should note that prior to @value{GDBN} 5.0 the protocol
8869 specification also included an optional two-digit @var{sequence-id}:
8870
8871 @example
8872 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8873 @end example
8874
8875 @cindex sequence-id, for @value{GDBN} remote
8876 @noindent
8877 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
8878 has never output @var{sequence-id}s. Stubs that handle packets added
8879 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
8880
8881 @cindex acknowledgment, for @value{GDBN} remote
8882 When either the host or the target machine receives a packet, the first
8883 response expected is an acknowledgment: either @samp{+} (to indicate
8884 the package was received correctly) or @samp{-} (to request
8885 retransmission):
8886
8887 @example
8888 <- @code{$}@var{packet-data}@code{#}@var{checksum}
8889 -> @code{+}
8890 @end example
8891 @noindent
8892
8893 The host (@value{GDBN}) sends @var{command}s, and the target (the
8894 debugging stub incorporated in your program) sends a @var{response}. In
8895 the case of step and continue @var{command}s, the response is only sent
8896 when the operation has completed (the target has again stopped).
8897
8898 @var{packet-data} consists of a sequence of characters with the
8899 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
8900 exceptions).
8901
8902 Fields within the packet should be separated using @samp{,} @samp{;} or
8903 @samp{:}. Except where otherwise noted all numbers are represented in
8904 HEX with leading zeros suppressed.
8905
8906 Implementors should note that prior to @value{GDBN} 5.0, the character
8907 @samp{:} could not appear as the third character in a packet (as it
8908 would potentially conflict with the @var{sequence-id}).
8909
8910 Response @var{data} can be run-length encoded to save space. A @samp{*}
8911 means that the next character is an @sc{ascii} encoding giving a repeat count
8912 which stands for that many repetitions of the character preceding the
8913 @samp{*}. The encoding is @code{n+29}, yielding a printable character
8914 where @code{n >=3} (which is where rle starts to win). The printable
8915 characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
8916 value greater than 126 should not be used.
8917
8918 Some remote systems have used a different run-length encoding mechanism
8919 loosely refered to as the cisco encoding. Following the @samp{*}
8920 character are two hex digits that indicate the size of the packet.
8921
8922 So:
8923 @example
8924 "@code{0* }"
8925 @end example
8926 @noindent
8927 means the same as "0000".
8928
8929 The error response returned for some packets includes a two character
8930 error number. That number is not well defined.
8931
8932 For any @var{command} not supported by the stub, an empty response
8933 (@samp{$#00}) should be returned. That way it is possible to extend the
8934 protocol. A newer @value{GDBN} can tell if a packet is supported based
8935 on that response.
8936
8937 A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
8938 @samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8939 optional.
8940
8941 Below is a complete list of all currently defined @var{command}s and
8942 their corresponding response @var{data}:
8943 @page
8944 @multitable @columnfractions .30 .30 .40
8945 @item Packet
8946 @tab Request
8947 @tab Description
8948
8949 @item extended ops
8950 @tab @code{!}
8951 @tab
8952 Use the extended remote protocol. Sticky---only needs to be set once.
8953 The extended remote protocol supports the @samp{R} packet.
8954 @item
8955 @tab reply @samp{}
8956 @tab
8957 Stubs that support the extended remote protocol return @samp{} which,
8958 unfortunately, is identical to the response returned by stubs that do not
8959 support protocol extensions.
8960
8961 @item last signal
8962 @tab @code{?}
8963 @tab
8964 Indicate the reason the target halted. The reply is the same as for step
8965 and continue.
8966 @item
8967 @tab reply
8968 @tab see below
8969
8970
8971 @item reserved
8972 @tab @code{a}
8973 @tab Reserved for future use
8974
8975 @item set program arguments @strong{(reserved)}
8976 @tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
8977 @tab
8978 @item
8979 @tab
8980 @tab
8981 Initialized @samp{argv[]} array passed into program. @var{arglen}
8982 specifies the number of bytes in the hex encoded byte stream @var{arg}.
8983 See @file{gdbserver} for more details.
8984 @item
8985 @tab reply @code{OK}
8986 @item
8987 @tab reply @code{E}@var{NN}
8988
8989 @item set baud @strong{(deprecated)}
8990 @tab @code{b}@var{baud}
8991 @tab
8992 Change the serial line speed to @var{baud}. JTC: @emph{When does the
8993 transport layer state change? When it's received, or after the ACK is
8994 transmitted. In either case, there are problems if the command or the
8995 acknowledgment packet is dropped.} Stan: @emph{If people really wanted
8996 to add something like this, and get it working for the first time, they
8997 ought to modify ser-unix.c to send some kind of out-of-band message to a
8998 specially-setup stub and have the switch happen "in between" packets, so
8999 that from remote protocol's point of view, nothing actually
9000 happened.}
9001
9002 @item set breakpoint @strong{(deprecated)}
9003 @tab @code{B}@var{addr},@var{mode}
9004 @tab
9005 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
9006 breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
9007 @samp{z} packets.}
9008
9009 @item continue
9010 @tab @code{c}@var{addr}
9011 @tab
9012 @var{addr} is address to resume. If @var{addr} is omitted, resume at
9013 current address.
9014 @item
9015 @tab reply
9016 @tab see below
9017
9018 @item continue with signal
9019 @tab @code{C}@var{sig}@code{;}@var{addr}
9020 @tab
9021 Continue with signal @var{sig} (hex signal number). If
9022 @code{;}@var{addr} is omitted, resume at same address.
9023 @item
9024 @tab reply
9025 @tab see below
9026
9027 @item toggle debug @strong{(deprecated)}
9028 @tab @code{d}
9029 @tab
9030 toggle debug flag.
9031
9032 @item detach
9033 @tab @code{D}
9034 @tab
9035 Detach @value{GDBN} from the remote system. Sent to the remote target before
9036 @value{GDBN} disconnects.
9037 @item
9038 @tab reply @emph{no response}
9039 @tab
9040 @value{GDBN} does not check for any response after sending this packet.
9041
9042 @item reserved
9043 @tab @code{e}
9044 @tab Reserved for future use
9045
9046 @item reserved
9047 @tab @code{E}
9048 @tab Reserved for future use
9049
9050 @item reserved
9051 @tab @code{f}
9052 @tab Reserved for future use
9053
9054 @item reserved
9055 @tab @code{F}
9056 @tab Reserved for future use
9057
9058 @item read registers
9059 @tab @code{g}
9060 @tab Read general registers.
9061 @item
9062 @tab reply @var{XX...}
9063 @tab
9064 Each byte of register data is described by two hex digits. The bytes
9065 with the register are transmitted in target byte order. The size of
9066 each register and their position within the @samp{g} @var{packet} are
9067 determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
9068 @var{REGISTER_NAME} macros. The specification of several standard
9069 @code{g} packets is specified below.
9070 @item
9071 @tab @code{E}@var{NN}
9072 @tab for an error.
9073
9074 @item write regs
9075 @tab @code{G}@var{XX...}
9076 @tab
9077 See @samp{g} for a description of the @var{XX...} data.
9078 @item
9079 @tab reply @code{OK}
9080 @tab for success
9081 @item
9082 @tab reply @code{E}@var{NN}
9083 @tab for an error
9084
9085 @item reserved
9086 @tab @code{h}
9087 @tab Reserved for future use
9088
9089 @item set thread
9090 @tab @code{H}@var{c}@var{t...}
9091 @tab
9092 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
9093 @samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
9094 continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
9095 thread used in other operations. If zero, pick a thread, any thread.
9096 @item
9097 @tab reply @code{OK}
9098 @tab for success
9099 @item
9100 @tab reply @code{E}@var{NN}
9101 @tab for an error
9102
9103 @c FIXME: JTC:
9104 @c 'H': How restrictive (or permissive) is the thread model. If a
9105 @c thread is selected and stopped, are other threads allowed
9106 @c to continue to execute? As I mentioned above, I think the
9107 @c semantics of each command when a thread is selected must be
9108 @c described. For example:
9109 @c
9110 @c 'g': If the stub supports threads and a specific thread is
9111 @c selected, returns the register block from that thread;
9112 @c otherwise returns current registers.
9113 @c
9114 @c 'G' If the stub supports threads and a specific thread is
9115 @c selected, sets the registers of the register block of
9116 @c that thread; otherwise sets current registers.
9117
9118 @item cycle step @strong{(draft)}
9119 @tab @code{i}@var{addr}@code{,}@var{nnn}
9120 @tab
9121 Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
9122 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
9123 step starting at that address.
9124
9125 @item signal then cycle step @strong{(reserved)}
9126 @tab @code{I}
9127 @tab
9128 See @samp{i} and @samp{S} for likely syntax and semantics.
9129
9130 @item reserved
9131 @tab @code{j}
9132 @tab Reserved for future use
9133
9134 @item reserved
9135 @tab @code{J}
9136 @tab Reserved for future use
9137
9138 @item kill request
9139 @tab @code{k}
9140 @tab
9141 FIXME: @emph{There is no description of how operate when a specific
9142 thread context has been selected (ie. does 'k' kill only that thread?)}.
9143
9144 @item reserved
9145 @tab @code{l}
9146 @tab Reserved for future use
9147
9148 @item reserved
9149 @tab @code{L}
9150 @tab Reserved for future use
9151
9152 @item read memory
9153 @tab @code{m}@var{addr}@code{,}@var{length}
9154 @tab
9155 Read @var{length} bytes of memory starting at address @var{addr}.
9156 Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
9157 using word alligned accesses. FIXME: @emph{A word aligned memory
9158 transfer mechanism is needed.}
9159 @item
9160 @tab reply @var{XX...}
9161 @tab
9162 @var{XX...} is mem contents. Can be fewer bytes than requested if able
9163 to read only part of the data. Neither @value{GDBN} nor the stub assume that
9164 sized memory transfers are assumed using word alligned accesses. FIXME:
9165 @emph{A word aligned memory transfer mechanism is needed.}
9166 @item
9167 @tab reply @code{E}@var{NN}
9168 @tab @var{NN} is errno
9169
9170 @item write mem
9171 @tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
9172 @tab
9173 Write @var{length} bytes of memory starting at address @var{addr}.
9174 @var{XX...} is the data.
9175 @item
9176 @tab reply @code{OK}
9177 @tab for success
9178 @item
9179 @tab reply @code{E}@var{NN}
9180 @tab
9181 for an error (this includes the case where only part of the data was
9182 written).
9183
9184 @item reserved
9185 @tab @code{n}
9186 @tab Reserved for future use
9187
9188 @item reserved
9189 @tab @code{N}
9190 @tab Reserved for future use
9191
9192 @item reserved
9193 @tab @code{o}
9194 @tab Reserved for future use
9195
9196 @item reserved
9197 @tab @code{O}
9198 @tab Reserved for future use
9199
9200 @item read reg @strong{(reserved)}
9201 @tab @code{p}@var{n...}
9202 @tab
9203 See write register.
9204 @item
9205 @tab return @var{r....}
9206 @tab The hex encoded value of the register in target byte order.
9207
9208 @item write reg
9209 @tab @code{P}@var{n...}@code{=}@var{r...}
9210 @tab
9211 Write register @var{n...} with value @var{r...}, which contains two hex
9212 digits for each byte in the register (target byte order).
9213 @item
9214 @tab reply @code{OK}
9215 @tab for success
9216 @item
9217 @tab reply @code{E}@var{NN}
9218 @tab for an error
9219
9220 @item general query
9221 @tab @code{q}@var{query}
9222 @tab
9223 Request info about @var{query}. In general @value{GDBN} queries
9224 have a leading upper case letter. Custom vendor queries should use a
9225 company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
9226 optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
9227 must ensure that they match the full @var{query} name.
9228 @item
9229 @tab reply @code{XX...}
9230 @tab Hex encoded data from query. The reply can not be empty.
9231 @item
9232 @tab reply @code{E}@var{NN}
9233 @tab error reply
9234 @item
9235 @tab reply @samp{}
9236 @tab Indicating an unrecognized @var{query}.
9237
9238 @item general set
9239 @tab @code{Q}@var{var}@code{=}@var{val}
9240 @tab
9241 Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
9242 naming conventions.
9243
9244 @item reset @strong{(deprecated)}
9245 @tab @code{r}
9246 @tab
9247 Reset the entire system.
9248
9249 @item remote restart
9250 @tab @code{R}@var{XX}
9251 @tab
9252 Restart the remote server. @var{XX} while needed has no clear
9253 definition. FIXME: @emph{An example interaction explaining how this
9254 packet is used in extended-remote mode is needed}.
9255
9256 @item step
9257 @tab @code{s}@var{addr}
9258 @tab
9259 @var{addr} is address to resume. If @var{addr} is omitted, resume at
9260 same address.
9261 @item
9262 @tab reply
9263 @tab see below
9264
9265 @item step with signal
9266 @tab @code{S}@var{sig}@code{;}@var{addr}
9267 @tab
9268 Like @samp{C} but step not continue.
9269 @item
9270 @tab reply
9271 @tab see below
9272
9273 @item search
9274 @tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
9275 @tab
9276 Search backwards starting at address @var{addr} for a match with pattern
9277 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
9278 bytes. @var{addr} must be at least 3 digits.
9279
9280 @item thread alive
9281 @tab @code{T}@var{XX}
9282 @tab Find out if the thread XX is alive.
9283 @item
9284 @tab reply @code{OK}
9285 @tab thread is still alive
9286 @item
9287 @tab reply @code{E}@var{NN}
9288 @tab thread is dead
9289
9290 @item reserved
9291 @tab @code{u}
9292 @tab Reserved for future use
9293
9294 @item reserved
9295 @tab @code{U}
9296 @tab Reserved for future use
9297
9298 @item reserved
9299 @tab @code{v}
9300 @tab Reserved for future use
9301
9302 @item reserved
9303 @tab @code{V}
9304 @tab Reserved for future use
9305
9306 @item reserved
9307 @tab @code{w}
9308 @tab Reserved for future use
9309
9310 @item reserved
9311 @tab @code{W}
9312 @tab Reserved for future use
9313
9314 @item reserved
9315 @tab @code{x}
9316 @tab Reserved for future use
9317
9318 @item write mem (binary)
9319 @tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
9320 @tab
9321 @var{addr} is address, @var{length} is number of bytes, @var{XX...} is
9322 binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
9323 escaped using @code{0x7d}.
9324 @item
9325 @tab reply @code{OK}
9326 @tab for success
9327 @item
9328 @tab reply @code{E}@var{NN}
9329 @tab for an error
9330
9331 @item reserved
9332 @tab @code{y}
9333 @tab Reserved for future use
9334
9335 @item reserved
9336 @tab @code{Y}
9337 @tab Reserved for future use
9338
9339 @item remove break or watchpoint @strong{(draft)}
9340 @tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9341 @tab
9342 See @samp{Z}.
9343
9344 @item insert break or watchpoint @strong{(draft)}
9345 @tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9346 @tab
9347 @var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
9348 breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
9349 @samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
9350 bytes. For a software breakpoint, @var{length} specifies the size of
9351 the instruction to be patched. For hardware breakpoints and watchpoints
9352 @var{length} specifies the memory region to be monitored. To avoid
9353 potential problems with duplicate packets, the operations should be
9354 implemented in an idempotent way.
9355 @item
9356 @tab reply @code{E}@var{NN}
9357 @tab for an error
9358 @item
9359 @tab reply @code{OK}
9360 @tab for success
9361 @item
9362 @tab @samp{}
9363 @tab If not supported.
9364
9365 @item reserved
9366 @tab <other>
9367 @tab Reserved for future use
9368
9369 @end multitable
9370
9371 The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
9372 receive any of the below as a reply. In the case of the @samp{C},
9373 @samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
9374 when the target halts. In the below the exact meaning of @samp{signal
9375 number} is poorly defined. In general one of the UNIX signal numbering
9376 conventions is used.
9377
9378 @multitable @columnfractions .4 .6
9379
9380 @item @code{S}@var{AA}
9381 @tab @var{AA} is the signal number
9382
9383 @item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
9384 @tab
9385 @var{AA} = two hex digit signal number; @var{n...} = register number
9386 (hex), @var{r...} = target byte ordered register contents, size defined
9387 by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
9388 thread process ID, this is a hex integer; @var{n...} = other string not
9389 starting with valid hex digit. @value{GDBN} should ignore this
9390 @var{n...}, @var{r...} pair and go on to the next. This way we can
9391 extend the protocol.
9392
9393 @item @code{W}@var{AA}
9394 @tab
9395 The process exited, and @var{AA} is the exit status. This is only
9396 applicable for certains sorts of targets.
9397
9398 @item @code{X}@var{AA}
9399 @tab
9400 The process terminated with signal @var{AA}.
9401
9402 @item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
9403 @tab
9404 @var{AA} = signal number; @var{t...} = address of symbol "_start";
9405 @var{d...} = base of data section; @var{b...} = base of bss section.
9406 @emph{Note: only used by Cisco Systems targets. The difference between
9407 this reply and the "qOffsets" query is that the 'N' packet may arrive
9408 spontaneously whereas the 'qOffsets' is a query initiated by the host
9409 debugger.}
9410
9411 @item @code{O}@var{XX...}
9412 @tab
9413 @var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
9414 while the program is running and the debugger should continue to wait
9415 for 'W', 'T', etc.
9416
9417 @end multitable
9418
9419 The following set and query packets have already been defined.
9420
9421 @multitable @columnfractions .2 .2 .6
9422
9423 @item current thread
9424 @tab @code{q}@code{C}
9425 @tab Return the current thread id.
9426 @item
9427 @tab reply @code{QC}@var{pid}
9428 @tab
9429 Where @var{pid} is a HEX encoded 16 bit process id.
9430 @item
9431 @tab reply *
9432 @tab Any other reply implies the old pid.
9433
9434 @item all thread ids
9435 @tab @code{q}@code{fThreadInfo}
9436 @item
9437 @tab @code{q}@code{sThreadInfo}
9438 @tab
9439 Obtain a list of active thread ids from the target (OS). Since there
9440 may be too many active threads to fit into one reply packet, this query
9441 works iteratively: it may require more than one query/reply sequence to
9442 obtain the entire list of threads. The first query of the sequence will
9443 be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
9444 sequence will be the @code{qs}@code{ThreadInfo} query.
9445 @item
9446 @tab
9447 @tab NOTE: replaces the @code{qL} query (see below).
9448 @item
9449 @tab reply @code{m}@var{<id>}
9450 @tab A single thread id
9451 @item
9452 @tab reply @code{m}@var{<id>},@var{<id>...}
9453 @tab a comma-separated list of thread ids
9454 @item
9455 @tab reply @code{l}
9456 @tab (lower case 'el') denotes end of list.
9457 @item
9458 @tab
9459 @tab
9460 In response to each query, the target will reply with a list of one
9461 or more thread ids, in big-endian hex, separated by commas. GDB will
9462 respond to each reply with a request for more thread ids (using the
9463 @code{qs} form of the query), until the target responds with @code{l}
9464 (lower-case el, for @code{'last'}).
9465
9466 @item extra thread info
9467 @tab @code{q}@code{ThreadExtraInfo}@code{,}@var{id}
9468 @tab
9469 @item
9470 @tab
9471 @tab
9472 Where @var{<id>} is a thread-id in big-endian hex.
9473 Obtain a printable string description of a thread's attributes from
9474 the target OS. This string may contain anything that the target OS
9475 thinks is interesting for @value{GDBN} to tell the user about the thread.
9476 The string is displayed in @value{GDBN}'s @samp{info threads} display.
9477 Some examples of possible thread extra info strings are "Runnable", or
9478 "Blocked on Mutex".
9479 @item
9480 @tab reply @var{XX...}
9481 @tab
9482 Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
9483 printable string containing the extra information about the thread's
9484 attributes.
9485
9486 @item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
9487 @tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
9488 @tab
9489 @item
9490 @tab
9491 @tab
9492 Obtain thread information from RTOS. Where: @var{startflag} (one hex
9493 digit) is one to indicate the first query and zero to indicate a
9494 subsequent query; @var{threadcount} (two hex digits) is the maximum
9495 number of threads the response packet can contain; and @var{nextthread}
9496 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
9497 returned in the response as @var{argthread}.
9498 @item
9499 @tab
9500 @tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
9501 query (see above).
9502 @item
9503 @tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
9504 @tab
9505 @item
9506 @tab
9507 @tab
9508 Where: @var{count} (two hex digits) is the number of threads being
9509 returned; @var{done} (one hex digit) is zero to indicate more threads
9510 and one indicates no further threads; @var{argthreadid} (eight hex
9511 digits) is @var{nextthread} from the request packet; @var{thread...} is
9512 a sequence of thread IDs from the target. @var{threadid} (eight hex
9513 digits). See @code{remote.c:parse_threadlist_response()}.
9514
9515 @item compute CRC of memory block
9516 @tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
9517 @tab
9518 @item
9519 @tab reply @code{E}@var{NN}
9520 @tab An error (such as memory fault)
9521 @item
9522 @tab reply @code{C}@var{CRC32}
9523 @tab A 32 bit cyclic redundancy check of the specified memory region.
9524
9525 @item query sect offs
9526 @tab @code{q}@code{Offsets}
9527 @tab
9528 Get section offsets that the target used when re-locating the downloaded
9529 image. @emph{Note: while a @code{Bss} offset is included in the
9530 response, @value{GDBN} ignores this and instead applies the @code{Data}
9531 offset to the @code{Bss} section.}
9532 @item
9533 @tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
9534
9535 @item thread info request
9536 @tab @code{q}@code{P}@var{mode}@var{threadid}
9537 @tab
9538 @item
9539 @tab
9540 @tab
9541 Returns information on @var{threadid}. Where: @var{mode} is a hex
9542 encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
9543 @item
9544 @tab reply *
9545 @tab
9546 See @code{remote.c:remote_unpack_thread_info_response()}.
9547
9548 @item remote command
9549 @tab @code{q}@code{Rcmd,}@var{COMMAND}
9550 @tab
9551 @item
9552 @tab
9553 @tab
9554 @var{COMMAND} (hex encoded) is passed to the local interpreter for
9555 execution. Invalid commands should be reported using the output string.
9556 Before the final result packet, the target may also respond with a
9557 number of intermediate @code{O}@var{OUTPUT} console output
9558 packets. @emph{Implementors should note that providing access to a
9559 stubs's interpreter may have security implications}.
9560 @item
9561 @tab reply @code{OK}
9562 @tab
9563 A command response with no output.
9564 @item
9565 @tab reply @var{OUTPUT}
9566 @tab
9567 A command response with the hex encoded output string @var{OUTPUT}.
9568 @item
9569 @tab reply @code{E}@var{NN}
9570 @tab
9571 Indicate a badly formed request.
9572
9573 @item
9574 @tab reply @samp{}
9575 @tab
9576 When @samp{q}@samp{Rcmd} is not recognized.
9577
9578 @end multitable
9579
9580 The following @samp{g}/@samp{G} packets have previously been defined.
9581 In the below, some thirty-two bit registers are transferred as sixty-four
9582 bits. Those registers should be zero/sign extended (which?) to fill the
9583 space allocated. Register bytes are transfered in target byte order.
9584 The two nibbles within a register byte are transfered most-significant -
9585 least-significant.
9586
9587 @multitable @columnfractions .5 .5
9588
9589 @item MIPS32
9590 @tab
9591 All registers are transfered as thirty-two bit quantities in the order:
9592 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
9593 registers; fsr; fir; fp.
9594
9595 @item MIPS64
9596 @tab
9597 All registers are transfered as sixty-four bit quantities (including
9598 thirty-two bit registers such as @code{sr}). The ordering is the same
9599 as @code{MIPS32}.
9600
9601 @end multitable
9602
9603 Example sequence of a target being re-started. Notice how the restart
9604 does not get any direct output:
9605
9606 @example
9607 <- @code{R00}
9608 -> @code{+}
9609 @emph{target restarts}
9610 <- @code{?}
9611 -> @code{+}
9612 -> @code{T001:1234123412341234}
9613 <- @code{+}
9614 @end example
9615
9616 Example sequence of a target being stepped by a single instruction:
9617
9618 @example
9619 <- @code{G1445...}
9620 -> @code{+}
9621 <- @code{s}
9622 -> @code{+}
9623 @emph{time passes}
9624 -> @code{T001:1234123412341234}
9625 <- @code{+}
9626 <- @code{g}
9627 -> @code{+}
9628 -> @code{1455...}
9629 <- @code{+}
9630 @end example
9631
9632 @node Server
9633 @subsubsection Using the @code{gdbserver} program
9634
9635 @kindex gdbserver
9636 @cindex remote connection without stubs
9637 @code{gdbserver} is a control program for Unix-like systems, which
9638 allows you to connect your program with a remote @value{GDBN} via
9639 @code{target remote}---but without linking in the usual debugging stub.
9640
9641 @code{gdbserver} is not a complete replacement for the debugging stubs,
9642 because it requires essentially the same operating-system facilities
9643 that @value{GDBN} itself does. In fact, a system that can run
9644 @code{gdbserver} to connect to a remote @value{GDBN} could also run
9645 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9646 because it is a much smaller program than @value{GDBN} itself. It is
9647 also easier to port than all of @value{GDBN}, so you may be able to get
9648 started more quickly on a new system by using @code{gdbserver}.
9649 Finally, if you develop code for real-time systems, you may find that
9650 the tradeoffs involved in real-time operation make it more convenient to
9651 do as much development work as possible on another system, for example
9652 by cross-compiling. You can use @code{gdbserver} to make a similar
9653 choice for debugging.
9654
9655 @value{GDBN} and @code{gdbserver} communicate via either a serial line
9656 or a TCP connection, using the standard @value{GDBN} remote serial
9657 protocol.
9658
9659 @table @emph
9660 @item On the target machine,
9661 you need to have a copy of the program you want to debug.
9662 @code{gdbserver} does not need your program's symbol table, so you can
9663 strip the program if necessary to save space. @value{GDBN} on the host
9664 system does all the symbol handling.
9665
9666 To use the server, you must tell it how to communicate with @value{GDBN};
9667 the name of your program; and the arguments for your program. The
9668 syntax is:
9669
9670 @smallexample
9671 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9672 @end smallexample
9673
9674 @var{comm} is either a device name (to use a serial line) or a TCP
9675 hostname and portnumber. For example, to debug Emacs with the argument
9676 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
9677 @file{/dev/com1}:
9678
9679 @smallexample
9680 target> gdbserver /dev/com1 emacs foo.txt
9681 @end smallexample
9682
9683 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
9684 with it.
9685
9686 To use a TCP connection instead of a serial line:
9687
9688 @smallexample
9689 target> gdbserver host:2345 emacs foo.txt
9690 @end smallexample
9691
9692 The only difference from the previous example is the first argument,
9693 specifying that you are communicating with the host @value{GDBN} via
9694 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9695 expect a TCP connection from machine @samp{host} to local TCP port 2345.
9696 (Currently, the @samp{host} part is ignored.) You can choose any number
9697 you want for the port number as long as it does not conflict with any
9698 TCP ports already in use on the target system (for example, @code{23} is
9699 reserved for @code{telnet}).@footnote{If you choose a port number that
9700 conflicts with another service, @code{gdbserver} prints an error message
9701 and exits.} You must use the same port number with the host @value{GDBN}
9702 @code{target remote} command.
9703
9704 @item On the @value{GDBN} host machine,
9705 you need an unstripped copy of your program, since @value{GDBN} needs
9706 symbols and debugging information. Start up @value{GDBN} as usual,
9707 using the name of the local copy of your program as the first argument.
9708 (You may also need the @w{@samp{--baud}} option if the serial line is
9709 running at anything other than 9600@dmn{bps}.) After that, use @code{target
9710 remote} to establish communications with @code{gdbserver}. Its argument
9711 is either a device name (usually a serial device, like
9712 @file{/dev/ttyb}), or a TCP port descriptor in the form
9713 @code{@var{host}:@var{PORT}}. For example:
9714
9715 @smallexample
9716 (@value{GDBP}) target remote /dev/ttyb
9717 @end smallexample
9718
9719 @noindent
9720 communicates with the server via serial line @file{/dev/ttyb}, and
9721
9722 @smallexample
9723 (@value{GDBP}) target remote the-target:2345
9724 @end smallexample
9725
9726 @noindent
9727 communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
9728 For TCP connections, you must start up @code{gdbserver} prior to using
9729 the @code{target remote} command. Otherwise you may get an error whose
9730 text depends on the host system, but which usually looks something like
9731 @samp{Connection refused}.
9732 @end table
9733
9734 @node NetWare
9735 @subsubsection Using the @code{gdbserve.nlm} program
9736
9737 @kindex gdbserve.nlm
9738 @code{gdbserve.nlm} is a control program for NetWare systems, which
9739 allows you to connect your program with a remote @value{GDBN} via
9740 @code{target remote}.
9741
9742 @value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
9743 using the standard @value{GDBN} remote serial protocol.
9744
9745 @table @emph
9746 @item On the target machine,
9747 you need to have a copy of the program you want to debug.
9748 @code{gdbserve.nlm} does not need your program's symbol table, so you
9749 can strip the program if necessary to save space. @value{GDBN} on the
9750 host system does all the symbol handling.
9751
9752 To use the server, you must tell it how to communicate with
9753 @value{GDBN}; the name of your program; and the arguments for your
9754 program. The syntax is:
9755
9756 @smallexample
9757 load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
9758 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
9759 @end smallexample
9760
9761 @var{board} and @var{port} specify the serial line; @var{baud} specifies
9762 the baud rate used by the connection. @var{port} and @var{node} default
9763 to 0, @var{baud} defaults to 9600@dmn{bps}.
9764
9765 For example, to debug Emacs with the argument @samp{foo.txt}and
9766 communicate with @value{GDBN} over serial port number 2 or board 1
9767 using a 19200@dmn{bps} connection:
9768
9769 @smallexample
9770 load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
9771 @end smallexample
9772
9773 @item On the @value{GDBN} host machine,
9774 you need an unstripped copy of your program, since @value{GDBN} needs
9775 symbols and debugging information. Start up @value{GDBN} as usual,
9776 using the name of the local copy of your program as the first argument.
9777 (You may also need the @w{@samp{--baud}} option if the serial line is
9778 running at anything other than 9600@dmn{bps}. After that, use @code{target
9779 remote} to establish communications with @code{gdbserve.nlm}. Its
9780 argument is a device name (usually a serial device, like
9781 @file{/dev/ttyb}). For example:
9782
9783 @smallexample
9784 (@value{GDBP}) target remote /dev/ttyb
9785 @end smallexample
9786
9787 @noindent
9788 communications with the server via serial line @file{/dev/ttyb}.
9789 @end table
9790
9791 @node KOD
9792 @section Kernel Object Display
9793
9794 @cindex kernel object display
9795 @cindex kernel object
9796 @cindex KOD
9797
9798 Some targets support kernel object display. Using this facility,
9799 @value{GDBN} communicates specially with the underlying operating system
9800 and can display information about operating system-level objects such as
9801 mutexes and other synchronization objects. Exactly which objects can be
9802 displayed is determined on a per-OS basis.
9803
9804 Use the @code{set os} command to set the operating system. This tells
9805 @value{GDBN} which kernel object display module to initialize:
9806
9807 @example
9808 (@value{GDBP}) set os cisco
9809 @end example
9810
9811 If @code{set os} succeeds, @value{GDBN} will display some information
9812 about the operating system, and will create a new @code{info} command
9813 which can be used to query the target. The @code{info} command is named
9814 after the operating system:
9815
9816 @example
9817 (@value{GDBP}) info cisco
9818 List of Cisco Kernel Objects
9819 Object Description
9820 any Any and all objects
9821 @end example
9822
9823 Further subcommands can be used to query about particular objects known
9824 by the kernel.
9825
9826 There is currently no way to determine whether a given operating system
9827 is supported other than to try it.
9828
9829
9830 @node Configurations
9831 @chapter Configuration-Specific Information
9832
9833 While nearly all @value{GDBN} commands are available for all native and
9834 cross versions of the debugger, there are some exceptions. This chapter
9835 describes things that are only available in certain configurations.
9836
9837 There are three major categories of configurations: native
9838 configurations, where the host and target are the same, embedded
9839 operating system configurations, which are usually the same for several
9840 different processor architectures, and bare embedded processors, which
9841 are quite different from each other.
9842
9843 @menu
9844 * Native::
9845 * Embedded OS::
9846 * Embedded Processors::
9847 * Architectures::
9848 @end menu
9849
9850 @node Native
9851 @section Native
9852
9853 This section describes details specific to particular native
9854 configurations.
9855
9856 @menu
9857 * HP-UX:: HP-UX
9858 * SVR4 Process Information:: SVR4 process information
9859 @end menu
9860
9861 @node HP-UX
9862 @subsection HP-UX
9863
9864 On HP-UX systems, if you refer to a function or variable name that
9865 begins with a dollar sign, @value{GDBN} searches for a user or system
9866 name first, before it searches for a convenience variable.
9867
9868 @node SVR4 Process Information
9869 @subsection SVR4 process information
9870
9871 @kindex /proc
9872 @cindex process image
9873
9874 Many versions of SVR4 provide a facility called @samp{/proc} that can be
9875 used to examine the image of a running process using file-system
9876 subroutines. If @value{GDBN} is configured for an operating system with
9877 this facility, the command @code{info proc} is available to report on
9878 several kinds of information about the process running your program.
9879 @code{info proc} works only on SVR4 systems that include the
9880 @code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
9881 and Unixware, but not HP-UX or Linux, for example.
9882
9883 @table @code
9884 @kindex info proc
9885 @item info proc
9886 Summarize available information about the process.
9887
9888 @kindex info proc mappings
9889 @item info proc mappings
9890 Report on the address ranges accessible in the program, with information
9891 on whether your program may read, write, or execute each range.
9892
9893 @kindex info proc times
9894 @item info proc times
9895 Starting time, user CPU time, and system CPU time for your program and
9896 its children.
9897
9898 @kindex info proc id
9899 @item info proc id
9900 Report on the process IDs related to your program: its own process ID,
9901 the ID of its parent, the process group ID, and the session ID.
9902
9903 @kindex info proc status
9904 @item info proc status
9905 General information on the state of the process. If the process is
9906 stopped, this report includes the reason for stopping, and any signal
9907 received.
9908
9909 @item info proc all
9910 Show all the above information about the process.
9911 @end table
9912
9913 @node Embedded OS
9914 @section Embedded Operating Systems
9915
9916 This section describes configurations involving the debugging of
9917 embedded operating systems that are available for several different
9918 architectures.
9919
9920 @menu
9921 * VxWorks:: Using @value{GDBN} with VxWorks
9922 @end menu
9923
9924 @value{GDBN} includes the ability to debug programs running on
9925 various real-time operating systems.
9926
9927 @node VxWorks
9928 @subsection Using @value{GDBN} with VxWorks
9929
9930 @cindex VxWorks
9931
9932 @table @code
9933
9934 @kindex target vxworks
9935 @item target vxworks @var{machinename}
9936 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
9937 is the target system's machine name or IP address.
9938
9939 @end table
9940
9941 On VxWorks, @code{load} links @var{filename} dynamically on the
9942 current target system as well as adding its symbols in @value{GDBN}.
9943
9944 @value{GDBN} enables developers to spawn and debug tasks running on networked
9945 VxWorks targets from a Unix host. Already-running tasks spawned from
9946 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
9947 both the Unix host and on the VxWorks target. The program
9948 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
9949 installed with the name @code{vxgdb}, to distinguish it from a
9950 @value{GDBN} for debugging programs on the host itself.)
9951
9952 @table @code
9953 @item VxWorks-timeout @var{args}
9954 @kindex vxworks-timeout
9955 All VxWorks-based targets now support the option @code{vxworks-timeout}.
9956 This option is set by the user, and @var{args} represents the number of
9957 seconds @value{GDBN} waits for responses to rpc's. You might use this if
9958 your VxWorks target is a slow software simulator or is on the far side
9959 of a thin network line.
9960 @end table
9961
9962 The following information on connecting to VxWorks was current when
9963 this manual was produced; newer releases of VxWorks may use revised
9964 procedures.
9965
9966 @kindex INCLUDE_RDB
9967 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
9968 to include the remote debugging interface routines in the VxWorks
9969 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
9970 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
9971 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
9972 source debugging task @code{tRdbTask} when VxWorks is booted. For more
9973 information on configuring and remaking VxWorks, see the manufacturer's
9974 manual.
9975 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
9976
9977 Once you have included @file{rdb.a} in your VxWorks system image and set
9978 your Unix execution search path to find @value{GDBN}, you are ready to
9979 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
9980 @code{vxgdb}, depending on your installation).
9981
9982 @value{GDBN} comes up showing the prompt:
9983
9984 @example
9985 (vxgdb)
9986 @end example
9987
9988 @menu
9989 * VxWorks Connection:: Connecting to VxWorks
9990 * VxWorks Download:: VxWorks download
9991 * VxWorks Attach:: Running tasks
9992 @end menu
9993
9994 @node VxWorks Connection
9995 @subsubsection Connecting to VxWorks
9996
9997 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
9998 network. To connect to a target whose host name is ``@code{tt}'', type:
9999
10000 @example
10001 (vxgdb) target vxworks tt
10002 @end example
10003
10004 @need 750
10005 @value{GDBN} displays messages like these:
10006
10007 @smallexample
10008 Attaching remote machine across net...
10009 Connected to tt.
10010 @end smallexample
10011
10012 @need 1000
10013 @value{GDBN} then attempts to read the symbol tables of any object modules
10014 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
10015 these files by searching the directories listed in the command search
10016 path (@pxref{Environment, ,Your program's environment}); if it fails
10017 to find an object file, it displays a message such as:
10018
10019 @example
10020 prog.o: No such file or directory.
10021 @end example
10022
10023 When this happens, add the appropriate directory to the search path with
10024 the @value{GDBN} command @code{path}, and execute the @code{target}
10025 command again.
10026
10027 @node VxWorks Download
10028 @subsubsection VxWorks download
10029
10030 @cindex download to VxWorks
10031 If you have connected to the VxWorks target and you want to debug an
10032 object that has not yet been loaded, you can use the @value{GDBN}
10033 @code{load} command to download a file from Unix to VxWorks
10034 incrementally. The object file given as an argument to the @code{load}
10035 command is actually opened twice: first by the VxWorks target in order
10036 to download the code, then by @value{GDBN} in order to read the symbol
10037 table. This can lead to problems if the current working directories on
10038 the two systems differ. If both systems have NFS mounted the same
10039 filesystems, you can avoid these problems by using absolute paths.
10040 Otherwise, it is simplest to set the working directory on both systems
10041 to the directory in which the object file resides, and then to reference
10042 the file by its name, without any path. For instance, a program
10043 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
10044 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
10045 program, type this on VxWorks:
10046
10047 @example
10048 -> cd "@var{vxpath}/vw/demo/rdb"
10049 @end example
10050
10051 @noindent
10052 Then, in @value{GDBN}, type:
10053
10054 @example
10055 (vxgdb) cd @var{hostpath}/vw/demo/rdb
10056 (vxgdb) load prog.o
10057 @end example
10058
10059 @value{GDBN} displays a response similar to this:
10060
10061 @smallexample
10062 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
10063 @end smallexample
10064
10065 You can also use the @code{load} command to reload an object module
10066 after editing and recompiling the corresponding source file. Note that
10067 this makes @value{GDBN} delete all currently-defined breakpoints,
10068 auto-displays, and convenience variables, and to clear the value
10069 history. (This is necessary in order to preserve the integrity of
10070 debugger's data structures that reference the target system's symbol
10071 table.)
10072
10073 @node VxWorks Attach
10074 @subsubsection Running tasks
10075
10076 @cindex running VxWorks tasks
10077 You can also attach to an existing task using the @code{attach} command as
10078 follows:
10079
10080 @example
10081 (vxgdb) attach @var{task}
10082 @end example
10083
10084 @noindent
10085 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
10086 or suspended when you attach to it. Running tasks are suspended at
10087 the time of attachment.
10088
10089 @node Embedded Processors
10090 @section Embedded Processors
10091
10092 This section goes into details specific to particular embedded
10093 configurations.
10094
10095 @menu
10096 * A29K Embedded:: AMD A29K Embedded
10097 * ARM:: ARM
10098 * H8/300:: Hitachi H8/300
10099 * H8/500:: Hitachi H8/500
10100 * i960:: Intel i960
10101 * M32R/D:: Mitsubishi M32R/D
10102 * M68K:: Motorola M68K
10103 * M88K:: Motorola M88K
10104 * MIPS Embedded:: MIPS Embedded
10105 * PA:: HP PA Embedded
10106 * PowerPC: PowerPC
10107 * SH:: Hitachi SH
10108 * Sparclet:: Tsqware Sparclet
10109 * Sparclite:: Fujitsu Sparclite
10110 * ST2000:: Tandem ST2000
10111 * Z8000:: Zilog Z8000
10112 @end menu
10113
10114 @node A29K Embedded
10115 @subsection AMD A29K Embedded
10116
10117 @menu
10118 * A29K UDI::
10119 * A29K EB29K::
10120 * Comms (EB29K):: Communications setup
10121 * gdb-EB29K:: EB29K cross-debugging
10122 * Remote Log:: Remote log
10123 @end menu
10124
10125 @table @code
10126
10127 @kindex target adapt
10128 @item target adapt @var{dev}
10129 Adapt monitor for A29K.
10130
10131 @kindex target amd-eb
10132 @item target amd-eb @var{dev} @var{speed} @var{PROG}
10133 @cindex AMD EB29K
10134 Remote PC-resident AMD EB29K board, attached over serial lines.
10135 @var{dev} is the serial device, as for @code{target remote};
10136 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
10137 name of the program to be debugged, as it appears to DOS on the PC.
10138 @xref{A29K EB29K, ,EBMON protocol for AMD29K}.
10139
10140 @end table
10141
10142 @node A29K UDI
10143 @subsubsection A29K UDI
10144
10145 @cindex UDI
10146 @cindex AMD29K via UDI
10147
10148 @value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
10149 protocol for debugging the a29k processor family. To use this
10150 configuration with AMD targets running the MiniMON monitor, you need the
10151 program @code{MONTIP}, available from AMD at no charge. You can also
10152 use @value{GDBN} with the UDI-conformant a29k simulator program
10153 @code{ISSTIP}, also available from AMD.
10154
10155 @table @code
10156 @item target udi @var{keyword}
10157 @kindex udi
10158 Select the UDI interface to a remote a29k board or simulator, where
10159 @var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
10160 This file contains keyword entries which specify parameters used to
10161 connect to a29k targets. If the @file{udi_soc} file is not in your
10162 working directory, you must set the environment variable @samp{UDICONF}
10163 to its pathname.
10164 @end table
10165
10166 @node A29K EB29K
10167 @subsubsection EBMON protocol for AMD29K
10168
10169 @cindex EB29K board
10170 @cindex running 29K programs
10171
10172 AMD distributes a 29K development board meant to fit in a PC, together
10173 with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
10174 term, this development system is called the ``EB29K''. To use
10175 @value{GDBN} from a Unix system to run programs on the EB29K board, you
10176 must first connect a serial cable between the PC (which hosts the EB29K
10177 board) and a serial port on the Unix system. In the following, we
10178 assume you've hooked the cable between the PC's @file{COM1} port and
10179 @file{/dev/ttya} on the Unix system.
10180
10181 @node Comms (EB29K)
10182 @subsubsection Communications setup
10183
10184 The next step is to set up the PC's port, by doing something like this
10185 in DOS on the PC:
10186
10187 @example
10188 C:\> MODE com1:9600,n,8,1,none
10189 @end example
10190
10191 @noindent
10192 This example---run on an MS DOS 4.0 system---sets the PC port to 9600
10193 bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
10194 you must match the communications parameters when establishing the Unix
10195 end of the connection as well.
10196 @c FIXME: Who knows what this "no retry action" crud from the DOS manual may
10197 @c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
10198 @c
10199 @c It's optional, but it's unwise to omit it: who knows what is the
10200 @c default value set when the DOS machines boots? "No retry" means that
10201 @c the DOS serial device driver won't retry the operation if it fails;
10202 @c I understand that this is needed because the GDB serial protocol
10203 @c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
10204
10205 To give control of the PC to the Unix side of the serial line, type
10206 the following at the DOS console:
10207
10208 @example
10209 C:\> CTTY com1
10210 @end example
10211
10212 @noindent
10213 (Later, if you wish to return control to the DOS console, you can use
10214 the command @code{CTTY con}---but you must send it over the device that
10215 had control, in our example over the @file{COM1} serial line.)
10216
10217 From the Unix host, use a communications program such as @code{tip} or
10218 @code{cu} to communicate with the PC; for example,
10219
10220 @example
10221 cu -s 9600 -l /dev/ttya
10222 @end example
10223
10224 @noindent
10225 The @code{cu} options shown specify, respectively, the linespeed and the
10226 serial port to use. If you use @code{tip} instead, your command line
10227 may look something like the following:
10228
10229 @example
10230 tip -9600 /dev/ttya
10231 @end example
10232
10233 @noindent
10234 Your system may require a different name where we show
10235 @file{/dev/ttya} as the argument to @code{tip}. The communications
10236 parameters, including which port to use, are associated with the
10237 @code{tip} argument in the ``remote'' descriptions file---normally the
10238 system table @file{/etc/remote}.
10239 @c FIXME: What if anything needs doing to match the "n,8,1,none" part of
10240 @c the DOS side's comms setup? cu can support -o (odd
10241 @c parity), -e (even parity)---apparently no settings for no parity or
10242 @c for character size. Taken from stty maybe...? John points out tip
10243 @c can set these as internal variables, eg ~s parity=none; man stty
10244 @c suggests that it *might* work to stty these options with stdin or
10245 @c stdout redirected... ---doc@cygnus.com, 25feb91
10246 @c
10247 @c There's nothing to be done for the "none" part of the DOS MODE
10248 @c command. The rest of the parameters should be matched by the
10249 @c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
10250
10251 @kindex EBMON
10252 Using the @code{tip} or @code{cu} connection, change the DOS working
10253 directory to the directory containing a copy of your 29K program, then
10254 start the PC program @code{EBMON} (an EB29K control program supplied
10255 with your board by AMD). You should see an initial display from
10256 @code{EBMON} similar to the one that follows, ending with the
10257 @code{EBMON} prompt @samp{#}---
10258
10259 @example
10260 C:\> G:
10261
10262 G:\> CD \usr\joe\work29k
10263
10264 G:\USR\JOE\WORK29K> EBMON
10265 Am29000 PC Coprocessor Board Monitor, version 3.0-18
10266 Copyright 1990 Advanced Micro Devices, Inc.
10267 Written by Gibbons and Associates, Inc.
10268
10269 Enter '?' or 'H' for help
10270
10271 PC Coprocessor Type = EB29K
10272 I/O Base = 0x208
10273 Memory Base = 0xd0000
10274
10275 Data Memory Size = 2048KB
10276 Available I-RAM Range = 0x8000 to 0x1fffff
10277 Available D-RAM Range = 0x80002000 to 0x801fffff
10278
10279 PageSize = 0x400
10280 Register Stack Size = 0x800
10281 Memory Stack Size = 0x1800
10282
10283 CPU PRL = 0x3
10284 Am29027 Available = No
10285 Byte Write Available = Yes
10286
10287 # ~.
10288 @end example
10289
10290 Then exit the @code{cu} or @code{tip} program (done in the example by
10291 typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
10292 running, ready for @value{GDBN} to take over.
10293
10294 For this example, we've assumed what is probably the most convenient
10295 way to make sure the same 29K program is on both the PC and the Unix
10296 system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
10297 PC as a file system on the Unix host. If you do not have PC/NFS or
10298 something similar connecting the two systems, you must arrange some
10299 other way---perhaps floppy-disk transfer---of getting the 29K program
10300 from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
10301 serial line.
10302
10303 @node gdb-EB29K
10304 @subsubsection EB29K cross-debugging
10305
10306 Finally, @code{cd} to the directory containing an image of your 29K
10307 program on the Unix system, and start @value{GDBN}---specifying as argument the
10308 name of your 29K program:
10309
10310 @example
10311 cd /usr/joe/work29k
10312 @value{GDBP} myfoo
10313 @end example
10314
10315 @need 500
10316 Now you can use the @code{target} command:
10317
10318 @example
10319 target amd-eb /dev/ttya 9600 MYFOO
10320 @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
10321 @c emphasize that this is the name as seen by DOS (since I think DOS is
10322 @c single-minded about case of letters). ---doc@cygnus.com, 25feb91
10323 @end example
10324
10325 @noindent
10326 In this example, we've assumed your program is in a file called
10327 @file{myfoo}. Note that the filename given as the last argument to
10328 @code{target amd-eb} should be the name of the program as it appears to DOS.
10329 In our example this is simply @code{MYFOO}, but in general it can include
10330 a DOS path, and depending on your transfer mechanism may not resemble
10331 the name on the Unix side.
10332
10333 At this point, you can set any breakpoints you wish; when you are ready
10334 to see your program run on the 29K board, use the @value{GDBN} command
10335 @code{run}.
10336
10337 To stop debugging the remote program, use the @value{GDBN} @code{detach}
10338 command.
10339
10340 To return control of the PC to its console, use @code{tip} or @code{cu}
10341 once again, after your @value{GDBN} session has concluded, to attach to
10342 @code{EBMON}. You can then type the command @code{q} to shut down
10343 @code{EBMON}, returning control to the DOS command-line interpreter.
10344 Type @kbd{CTTY con} to return command input to the main DOS console,
10345 and type @kbd{~.} to leave @code{tip} or @code{cu}.
10346
10347 @node Remote Log
10348 @subsubsection Remote log
10349 @cindex @file{eb.log}, a log file for EB29K
10350 @cindex log file for EB29K
10351
10352 The @code{target amd-eb} command creates a file @file{eb.log} in the
10353 current working directory, to help debug problems with the connection.
10354 @file{eb.log} records all the output from @code{EBMON}, including echoes
10355 of the commands sent to it. Running @samp{tail -f} on this file in
10356 another window often helps to understand trouble with @code{EBMON}, or
10357 unexpected events on the PC side of the connection.
10358
10359 @node ARM
10360 @subsection ARM
10361
10362 @table @code
10363
10364 @kindex target rdi
10365 @item target rdi @var{dev}
10366 ARM Angel monitor, via RDI library interface to ADP protocol. You may
10367 use this target to communicate with both boards running the Angel
10368 monitor, or with the EmbeddedICE JTAG debug device.
10369
10370 @kindex target rdp
10371 @item target rdp @var{dev}
10372 ARM Demon monitor.
10373
10374 @end table
10375
10376 @node H8/300
10377 @subsection Hitachi H8/300
10378
10379 @table @code
10380
10381 @kindex target hms@r{, with H8/300}
10382 @item target hms @var{dev}
10383 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
10384 Use special commands @code{device} and @code{speed} to control the serial
10385 line and the communications speed used.
10386
10387 @kindex target e7000@r{, with H8/300}
10388 @item target e7000 @var{dev}
10389 E7000 emulator for Hitachi H8 and SH.
10390
10391 @kindex target sh3@r{, with H8/300}
10392 @kindex target sh3e@r{, with H8/300}
10393 @item target sh3 @var{dev}
10394 @itemx target sh3e @var{dev}
10395 Hitachi SH-3 and SH-3E target systems.
10396
10397 @end table
10398
10399 @cindex download to H8/300 or H8/500
10400 @cindex H8/300 or H8/500 download
10401 @cindex download to Hitachi SH
10402 @cindex Hitachi SH download
10403 When you select remote debugging to a Hitachi SH, H8/300, or H8/500
10404 board, the @code{load} command downloads your program to the Hitachi
10405 board and also opens it as the current executable target for
10406 @value{GDBN} on your host (like the @code{file} command).
10407
10408 @value{GDBN} needs to know these things to talk to your
10409 Hitachi SH, H8/300, or H8/500:
10410
10411 @enumerate
10412 @item
10413 that you want to use @samp{target hms}, the remote debugging interface
10414 for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
10415 emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
10416 the default when @value{GDBN} is configured specifically for the Hitachi SH,
10417 H8/300, or H8/500.)
10418
10419 @item
10420 what serial device connects your host to your Hitachi board (the first
10421 serial device available on your host is the default).
10422
10423 @item
10424 what speed to use over the serial device.
10425 @end enumerate
10426
10427 @menu
10428 * Hitachi Boards:: Connecting to Hitachi boards.
10429 * Hitachi ICE:: Using the E7000 In-Circuit Emulator.
10430 * Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
10431 @end menu
10432
10433 @node Hitachi Boards
10434 @subsubsection Connecting to Hitachi boards
10435
10436 @c only for Unix hosts
10437 @kindex device
10438 @cindex serial device, Hitachi micros
10439 Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
10440 need to explicitly set the serial device. The default @var{port} is the
10441 first available port on your host. This is only necessary on Unix
10442 hosts, where it is typically something like @file{/dev/ttya}.
10443
10444 @kindex speed
10445 @cindex serial line speed, Hitachi micros
10446 @code{@value{GDBN}} has another special command to set the communications
10447 speed: @samp{speed @var{bps}}. This command also is only used from Unix
10448 hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
10449 the DOS @code{mode} command (for instance,
10450 @w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
10451
10452 The @samp{device} and @samp{speed} commands are available only when you
10453 use a Unix host to debug your Hitachi microprocessor programs. If you
10454 use a DOS host,
10455 @value{GDBN} depends on an auxiliary terminate-and-stay-resident program
10456 called @code{asynctsr} to communicate with the development board
10457 through a PC serial port. You must also use the DOS @code{mode} command
10458 to set up the serial port on the DOS side.
10459
10460 The following sample session illustrates the steps needed to start a
10461 program under @value{GDBN} control on an H8/300. The example uses a
10462 sample H8/300 program called @file{t.x}. The procedure is the same for
10463 the Hitachi SH and the H8/500.
10464
10465 First hook up your development board. In this example, we use a
10466 board attached to serial port @code{COM2}; if you use a different serial
10467 port, substitute its name in the argument of the @code{mode} command.
10468 When you call @code{asynctsr}, the auxiliary comms program used by the
10469 debugger, you give it just the numeric part of the serial port's name;
10470 for example, @samp{asyncstr 2} below runs @code{asyncstr} on
10471 @code{COM2}.
10472
10473 @example
10474 C:\H8300\TEST> asynctsr 2
10475 C:\H8300\TEST> mode com2:9600,n,8,1,p
10476
10477 Resident portion of MODE loaded
10478
10479 COM2: 9600, n, 8, 1, p
10480
10481 @end example
10482
10483 @quotation
10484 @emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
10485 @code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
10486 disable it, or even boot without it, to use @code{asynctsr} to control
10487 your development board.
10488 @end quotation
10489
10490 @kindex target hms@r{, and serial protocol}
10491 Now that serial communications are set up, and the development board is
10492 connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
10493 the name of your program as the argument. @code{@value{GDBN}} prompts
10494 you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
10495 commands to begin your debugging session: @samp{target hms} to specify
10496 cross-debugging to the Hitachi board, and the @code{load} command to
10497 download your program to the board. @code{load} displays the names of
10498 the program's sections, and a @samp{*} for each 2K of data downloaded.
10499 (If you want to refresh @value{GDBN} data on symbols or on the
10500 executable file without downloading, use the @value{GDBN} commands
10501 @code{file} or @code{symbol-file}. These commands, and @code{load}
10502 itself, are described in @ref{Files,,Commands to specify files}.)
10503
10504 @smallexample
10505 (eg-C:\H8300\TEST) @value{GDBP} t.x
10506 @value{GDBN} is free software and you are welcome to distribute copies
10507 of it under certain conditions; type "show copying" to see
10508 the conditions.
10509 There is absolutely no warranty for @value{GDBN}; type "show warranty"
10510 for details.
10511 @value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
10512 (@value{GDBP}) target hms
10513 Connected to remote H8/300 HMS system.
10514 (@value{GDBP}) load t.x
10515 .text : 0x8000 .. 0xabde ***********
10516 .data : 0xabde .. 0xad30 *
10517 .stack : 0xf000 .. 0xf014 *
10518 @end smallexample
10519
10520 At this point, you're ready to run or debug your program. From here on,
10521 you can use all the usual @value{GDBN} commands. The @code{break} command
10522 sets breakpoints; the @code{run} command starts your program;
10523 @code{print} or @code{x} display data; the @code{continue} command
10524 resumes execution after stopping at a breakpoint. You can use the
10525 @code{help} command at any time to find out more about @value{GDBN} commands.
10526
10527 Remember, however, that @emph{operating system} facilities aren't
10528 available on your development board; for example, if your program hangs,
10529 you can't send an interrupt---but you can press the @sc{reset} switch!
10530
10531 Use the @sc{reset} button on the development board
10532 @itemize @bullet
10533 @item
10534 to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
10535 no way to pass an interrupt signal to the development board); and
10536
10537 @item
10538 to return to the @value{GDBN} command prompt after your program finishes
10539 normally. The communications protocol provides no other way for @value{GDBN}
10540 to detect program completion.
10541 @end itemize
10542
10543 In either case, @value{GDBN} sees the effect of a @sc{reset} on the
10544 development board as a ``normal exit'' of your program.
10545
10546 @node Hitachi ICE
10547 @subsubsection Using the E7000 in-circuit emulator
10548
10549 @kindex target e7000@r{, with Hitachi ICE}
10550 You can use the E7000 in-circuit emulator to develop code for either the
10551 Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
10552 e7000} command to connect @value{GDBN} to your E7000:
10553
10554 @table @code
10555 @item target e7000 @var{port} @var{speed}
10556 Use this form if your E7000 is connected to a serial port. The
10557 @var{port} argument identifies what serial port to use (for example,
10558 @samp{com2}). The third argument is the line speed in bits per second
10559 (for example, @samp{9600}).
10560
10561 @item target e7000 @var{hostname}
10562 If your E7000 is installed as a host on a TCP/IP network, you can just
10563 specify its hostname; @value{GDBN} uses @code{telnet} to connect.
10564 @end table
10565
10566 @node Hitachi Special
10567 @subsubsection Special @value{GDBN} commands for Hitachi micros
10568
10569 Some @value{GDBN} commands are available only for the H8/300:
10570
10571 @table @code
10572
10573 @kindex set machine
10574 @kindex show machine
10575 @item set machine h8300
10576 @itemx set machine h8300h
10577 Condition @value{GDBN} for one of the two variants of the H8/300
10578 architecture with @samp{set machine}. You can use @samp{show machine}
10579 to check which variant is currently in effect.
10580
10581 @end table
10582
10583 @node H8/500
10584 @subsection H8/500
10585
10586 @table @code
10587
10588 @kindex set memory @var{mod}
10589 @cindex memory models, H8/500
10590 @item set memory @var{mod}
10591 @itemx show memory
10592 Specify which H8/500 memory model (@var{mod}) you are using with
10593 @samp{set memory}; check which memory model is in effect with @samp{show
10594 memory}. The accepted values for @var{mod} are @code{small},
10595 @code{big}, @code{medium}, and @code{compact}.
10596
10597 @end table
10598
10599 @node i960
10600 @subsection Intel i960
10601
10602 @table @code
10603
10604 @kindex target mon960
10605 @item target mon960 @var{dev}
10606 MON960 monitor for Intel i960.
10607
10608 @kindex target nindy
10609 @item target nindy @var{devicename}
10610 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10611 the name of the serial device to use for the connection, e.g.
10612 @file{/dev/ttya}.
10613
10614 @end table
10615
10616 @cindex Nindy
10617 @cindex i960
10618 @dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
10619 @value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
10620 tell @value{GDBN} how to connect to the 960 in several ways:
10621
10622 @itemize @bullet
10623 @item
10624 Through command line options specifying serial port, version of the
10625 Nindy protocol, and communications speed;
10626
10627 @item
10628 By responding to a prompt on startup;
10629
10630 @item
10631 By using the @code{target} command at any point during your @value{GDBN}
10632 session. @xref{Target Commands, ,Commands for managing targets}.
10633
10634 @end itemize
10635
10636 @cindex download to Nindy-960
10637 With the Nindy interface to an Intel 960 board, @code{load}
10638 downloads @var{filename} to the 960 as well as adding its symbols in
10639 @value{GDBN}.
10640
10641 @menu
10642 * Nindy Startup:: Startup with Nindy
10643 * Nindy Options:: Options for Nindy
10644 * Nindy Reset:: Nindy reset command
10645 @end menu
10646
10647 @node Nindy Startup
10648 @subsubsection Startup with Nindy
10649
10650 If you simply start @code{@value{GDBP}} without using any command-line
10651 options, you are prompted for what serial port to use, @emph{before} you
10652 reach the ordinary @value{GDBN} prompt:
10653
10654 @example
10655 Attach /dev/ttyNN -- specify NN, or "quit" to quit:
10656 @end example
10657
10658 @noindent
10659 Respond to the prompt with whatever suffix (after @samp{/dev/tty})
10660 identifies the serial port you want to use. You can, if you choose,
10661 simply start up with no Nindy connection by responding to the prompt
10662 with an empty line. If you do this and later wish to attach to Nindy,
10663 use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
10664
10665 @node Nindy Options
10666 @subsubsection Options for Nindy
10667
10668 These are the startup options for beginning your @value{GDBN} session with a
10669 Nindy-960 board attached:
10670
10671 @table @code
10672 @item -r @var{port}
10673 Specify the serial port name of a serial interface to be used to connect
10674 to the target system. This option is only available when @value{GDBN} is
10675 configured for the Intel 960 target architecture. You may specify
10676 @var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
10677 device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
10678 suffix for a specific @code{tty} (e.g. @samp{-r a}).
10679
10680 @item -O
10681 (An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
10682 the ``old'' Nindy monitor protocol to connect to the target system.
10683 This option is only available when @value{GDBN} is configured for the Intel 960
10684 target architecture.
10685
10686 @quotation
10687 @emph{Warning:} if you specify @samp{-O}, but are actually trying to
10688 connect to a target system that expects the newer protocol, the connection
10689 fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
10690 attempts to reconnect at several different line speeds. You can abort
10691 this process with an interrupt.
10692 @end quotation
10693
10694 @item -brk
10695 Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
10696 system, in an attempt to reset it, before connecting to a Nindy target.
10697
10698 @quotation
10699 @emph{Warning:} Many target systems do not have the hardware that this
10700 requires; it only works with a few boards.
10701 @end quotation
10702 @end table
10703
10704 The standard @samp{-b} option controls the line speed used on the serial
10705 port.
10706
10707 @c @group
10708 @node Nindy Reset
10709 @subsubsection Nindy reset command
10710
10711 @table @code
10712 @item reset
10713 @kindex reset
10714 For a Nindy target, this command sends a ``break'' to the remote target
10715 system; this is only useful if the target has been equipped with a
10716 circuit to perform a hard reset (or some other interesting action) when
10717 a break is detected.
10718 @end table
10719 @c @end group
10720
10721 @node M32R/D
10722 @subsection Mitsubishi M32R/D
10723
10724 @table @code
10725
10726 @kindex target m32r
10727 @item target m32r @var{dev}
10728 Mitsubishi M32R/D ROM monitor.
10729
10730 @end table
10731
10732 @node M68K
10733 @subsection M68k
10734
10735 The Motorola m68k configuration includes ColdFire support, and
10736 target command for the following ROM monitors.
10737
10738 @table @code
10739
10740 @kindex target abug
10741 @item target abug @var{dev}
10742 ABug ROM monitor for M68K.
10743
10744 @kindex target cpu32bug
10745 @item target cpu32bug @var{dev}
10746 CPU32BUG monitor, running on a CPU32 (M68K) board.
10747
10748 @kindex target dbug
10749 @item target dbug @var{dev}
10750 dBUG ROM monitor for Motorola ColdFire.
10751
10752 @kindex target est
10753 @item target est @var{dev}
10754 EST-300 ICE monitor, running on a CPU32 (M68K) board.
10755
10756 @kindex target rom68k
10757 @item target rom68k @var{dev}
10758 ROM 68K monitor, running on an M68K IDP board.
10759
10760 @end table
10761
10762 If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
10763 instead have only a single special target command:
10764
10765 @table @code
10766
10767 @kindex target es1800
10768 @item target es1800 @var{dev}
10769 ES-1800 emulator for M68K.
10770
10771 @end table
10772
10773 [context?]
10774
10775 @table @code
10776
10777 @kindex target rombug
10778 @item target rombug @var{dev}
10779 ROMBUG ROM monitor for OS/9000.
10780
10781 @end table
10782
10783 @node M88K
10784 @subsection M88K
10785
10786 @table @code
10787
10788 @kindex target bug
10789 @item target bug @var{dev}
10790 BUG monitor, running on a MVME187 (m88k) board.
10791
10792 @end table
10793
10794 @node MIPS Embedded
10795 @subsection MIPS Embedded
10796
10797 @cindex MIPS boards
10798 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
10799 MIPS board attached to a serial line. This is available when
10800 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
10801
10802 @need 1000
10803 Use these @value{GDBN} commands to specify the connection to your target board:
10804
10805 @table @code
10806 @item target mips @var{port}
10807 @kindex target mips @var{port}
10808 To run a program on the board, start up @code{@value{GDBP}} with the
10809 name of your program as the argument. To connect to the board, use the
10810 command @samp{target mips @var{port}}, where @var{port} is the name of
10811 the serial port connected to the board. If the program has not already
10812 been downloaded to the board, you may use the @code{load} command to
10813 download it. You can then use all the usual @value{GDBN} commands.
10814
10815 For example, this sequence connects to the target board through a serial
10816 port, and loads and runs a program called @var{prog} through the
10817 debugger:
10818
10819 @example
10820 host$ @value{GDBP} @var{prog}
10821 @value{GDBN} is free software and @dots{}
10822 (@value{GDBP}) target mips /dev/ttyb
10823 (@value{GDBP}) load @var{prog}
10824 (@value{GDBP}) run
10825 @end example
10826
10827 @item target mips @var{hostname}:@var{portnumber}
10828 On some @value{GDBN} host configurations, you can specify a TCP
10829 connection (for instance, to a serial line managed by a terminal
10830 concentrator) instead of a serial port, using the syntax
10831 @samp{@var{hostname}:@var{portnumber}}.
10832
10833 @item target pmon @var{port}
10834 @kindex target pmon @var{port}
10835 PMON ROM monitor.
10836
10837 @item target ddb @var{port}
10838 @kindex target ddb @var{port}
10839 NEC's DDB variant of PMON for Vr4300.
10840
10841 @item target lsi @var{port}
10842 @kindex target lsi @var{port}
10843 LSI variant of PMON.
10844
10845 @kindex target r3900
10846 @item target r3900 @var{dev}
10847 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
10848
10849 @kindex target array
10850 @item target array @var{dev}
10851 Array Tech LSI33K RAID controller board.
10852
10853 @end table
10854
10855
10856 @noindent
10857 @value{GDBN} also supports these special commands for MIPS targets:
10858
10859 @table @code
10860 @item set processor @var{args}
10861 @itemx show processor
10862 @kindex set processor @var{args}
10863 @kindex show processor
10864 Use the @code{set processor} command to set the type of MIPS
10865 processor when you want to access processor-type-specific registers.
10866 For example, @code{set processor @var{r3041}} tells @value{GDBN}
10867 to use the CPO registers appropriate for the 3041 chip.
10868 Use the @code{show processor} command to see what MIPS processor @value{GDBN}
10869 is using. Use the @code{info reg} command to see what registers
10870 @value{GDBN} is using.
10871
10872 @item set mipsfpu double
10873 @itemx set mipsfpu single
10874 @itemx set mipsfpu none
10875 @itemx show mipsfpu
10876 @kindex set mipsfpu
10877 @kindex show mipsfpu
10878 @cindex MIPS remote floating point
10879 @cindex floating point, MIPS remote
10880 If your target board does not support the MIPS floating point
10881 coprocessor, you should use the command @samp{set mipsfpu none} (if you
10882 need this, you may wish to put the command in your @value{GDBN} init
10883 file). This tells @value{GDBN} how to find the return value of
10884 functions which return floating point values. It also allows
10885 @value{GDBN} to avoid saving the floating point registers when calling
10886 functions on the board. If you are using a floating point coprocessor
10887 with only single precision floating point support, as on the @sc{r4650}
10888 processor, use the command @samp{set mipsfpu single}. The default
10889 double precision floating point coprocessor may be selected using
10890 @samp{set mipsfpu double}.
10891
10892 In previous versions the only choices were double precision or no
10893 floating point, so @samp{set mipsfpu on} will select double precision
10894 and @samp{set mipsfpu off} will select no floating point.
10895
10896 As usual, you can inquire about the @code{mipsfpu} variable with
10897 @samp{show mipsfpu}.
10898
10899 @item set remotedebug @var{n}
10900 @itemx show remotedebug
10901 @kindex set remotedebug@r{, MIPS protocol}
10902 @kindex show remotedebug@r{, MIPS protocol}
10903 @cindex @code{remotedebug}, MIPS protocol
10904 @cindex MIPS @code{remotedebug} protocol
10905 @c FIXME! For this to be useful, you must know something about the MIPS
10906 @c FIXME...protocol. Where is it described?
10907 You can see some debugging information about communications with the board
10908 by setting the @code{remotedebug} variable. If you set it to @code{1} using
10909 @samp{set remotedebug 1}, every packet is displayed. If you set it
10910 to @code{2}, every character is displayed. You can check the current value
10911 at any time with the command @samp{show remotedebug}.
10912
10913 @item set timeout @var{seconds}
10914 @itemx set retransmit-timeout @var{seconds}
10915 @itemx show timeout
10916 @itemx show retransmit-timeout
10917 @cindex @code{timeout}, MIPS protocol
10918 @cindex @code{retransmit-timeout}, MIPS protocol
10919 @kindex set timeout
10920 @kindex show timeout
10921 @kindex set retransmit-timeout
10922 @kindex show retransmit-timeout
10923 You can control the timeout used while waiting for a packet, in the MIPS
10924 remote protocol, with the @code{set timeout @var{seconds}} command. The
10925 default is 5 seconds. Similarly, you can control the timeout used while
10926 waiting for an acknowledgement of a packet with the @code{set
10927 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
10928 You can inspect both values with @code{show timeout} and @code{show
10929 retransmit-timeout}. (These commands are @emph{only} available when
10930 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
10931
10932 The timeout set by @code{set timeout} does not apply when @value{GDBN}
10933 is waiting for your program to stop. In that case, @value{GDBN} waits
10934 forever because it has no way of knowing how long the program is going
10935 to run before stopping.
10936 @end table
10937
10938 @node PowerPC
10939 @subsection PowerPC
10940
10941 @table @code
10942
10943 @kindex target dink32
10944 @item target dink32 @var{dev}
10945 DINK32 ROM monitor.
10946
10947 @kindex target ppcbug
10948 @item target ppcbug @var{dev}
10949 @kindex target ppcbug1
10950 @item target ppcbug1 @var{dev}
10951 PPCBUG ROM monitor for PowerPC.
10952
10953 @kindex target sds
10954 @item target sds @var{dev}
10955 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
10956
10957 @end table
10958
10959 @node PA
10960 @subsection HP PA Embedded
10961
10962 @table @code
10963
10964 @kindex target op50n
10965 @item target op50n @var{dev}
10966 OP50N monitor, running on an OKI HPPA board.
10967
10968 @kindex target w89k
10969 @item target w89k @var{dev}
10970 W89K monitor, running on a Winbond HPPA board.
10971
10972 @end table
10973
10974 @node SH
10975 @subsection Hitachi SH
10976
10977 @table @code
10978
10979 @kindex target hms@r{, with Hitachi SH}
10980 @item target hms @var{dev}
10981 A Hitachi SH board attached via serial line to your host. Use special
10982 commands @code{device} and @code{speed} to control the serial line and
10983 the communications speed used.
10984
10985 @kindex target e7000@r{, with Hitachi SH}
10986 @item target e7000 @var{dev}
10987 E7000 emulator for Hitachi SH.
10988
10989 @kindex target sh3@r{, with SH}
10990 @kindex target sh3e@r{, with SH}
10991 @item target sh3 @var{dev}
10992 @item target sh3e @var{dev}
10993 Hitachi SH-3 and SH-3E target systems.
10994
10995 @end table
10996
10997 @node Sparclet
10998 @subsection Tsqware Sparclet
10999
11000 @cindex Sparclet
11001
11002 @value{GDBN} enables developers to debug tasks running on
11003 Sparclet targets from a Unix host.
11004 @value{GDBN} uses code that runs on
11005 both the Unix host and on the Sparclet target. The program
11006 @code{@value{GDBP}} is installed and executed on the Unix host.
11007
11008 @table @code
11009 @item remotetimeout @var{args}
11010 @kindex remotetimeout
11011 @value{GDBN} supports the option @code{remotetimeout}.
11012 This option is set by the user, and @var{args} represents the number of
11013 seconds @value{GDBN} waits for responses.
11014 @end table
11015
11016 @cindex compiling, on Sparclet
11017 When compiling for debugging, include the options @samp{-g} to get debug
11018 information and @samp{-Ttext} to relocate the program to where you wish to
11019 load it on the target. You may also want to add the options @samp{-n} or
11020 @samp{-N} in order to reduce the size of the sections. Example:
11021
11022 @example
11023 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
11024 @end example
11025
11026 You can use @code{objdump} to verify that the addresses are what you intended:
11027
11028 @example
11029 sparclet-aout-objdump --headers --syms prog
11030 @end example
11031
11032 @cindex running, on Sparclet
11033 Once you have set
11034 your Unix execution search path to find @value{GDBN}, you are ready to
11035 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
11036 (or @code{sparclet-aout-gdb}, depending on your installation).
11037
11038 @value{GDBN} comes up showing the prompt:
11039
11040 @example
11041 (gdbslet)
11042 @end example
11043
11044 @menu
11045 * Sparclet File:: Setting the file to debug
11046 * Sparclet Connection:: Connecting to Sparclet
11047 * Sparclet Download:: Sparclet download
11048 * Sparclet Execution:: Running and debugging
11049 @end menu
11050
11051 @node Sparclet File
11052 @subsubsection Setting file to debug
11053
11054 The @value{GDBN} command @code{file} lets you choose with program to debug.
11055
11056 @example
11057 (gdbslet) file prog
11058 @end example
11059
11060 @need 1000
11061 @value{GDBN} then attempts to read the symbol table of @file{prog}.
11062 @value{GDBN} locates
11063 the file by searching the directories listed in the command search
11064 path.
11065 If the file was compiled with debug information (option "-g"), source
11066 files will be searched as well.
11067 @value{GDBN} locates
11068 the source files by searching the directories listed in the directory search
11069 path (@pxref{Environment, ,Your program's environment}).
11070 If it fails
11071 to find a file, it displays a message such as:
11072
11073 @example
11074 prog: No such file or directory.
11075 @end example
11076
11077 When this happens, add the appropriate directories to the search paths with
11078 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
11079 @code{target} command again.
11080
11081 @node Sparclet Connection
11082 @subsubsection Connecting to Sparclet
11083
11084 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
11085 To connect to a target on serial port ``@code{ttya}'', type:
11086
11087 @example
11088 (gdbslet) target sparclet /dev/ttya
11089 Remote target sparclet connected to /dev/ttya
11090 main () at ../prog.c:3
11091 @end example
11092
11093 @need 750
11094 @value{GDBN} displays messages like these:
11095
11096 @example
11097 Connected to ttya.
11098 @end example
11099
11100 @node Sparclet Download
11101 @subsubsection Sparclet download
11102
11103 @cindex download to Sparclet
11104 Once connected to the Sparclet target,
11105 you can use the @value{GDBN}
11106 @code{load} command to download the file from the host to the target.
11107 The file name and load offset should be given as arguments to the @code{load}
11108 command.
11109 Since the file format is aout, the program must be loaded to the starting
11110 address. You can use @code{objdump} to find out what this value is. The load
11111 offset is an offset which is added to the VMA (virtual memory address)
11112 of each of the file's sections.
11113 For instance, if the program
11114 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
11115 and bss at 0x12010170, in @value{GDBN}, type:
11116
11117 @example
11118 (gdbslet) load prog 0x12010000
11119 Loading section .text, size 0xdb0 vma 0x12010000
11120 @end example
11121
11122 If the code is loaded at a different address then what the program was linked
11123 to, you may need to use the @code{section} and @code{add-symbol-file} commands
11124 to tell @value{GDBN} where to map the symbol table.
11125
11126 @node Sparclet Execution
11127 @subsubsection Running and debugging
11128
11129 @cindex running and debugging Sparclet programs
11130 You can now begin debugging the task using @value{GDBN}'s execution control
11131 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
11132 manual for the list of commands.
11133
11134 @example
11135 (gdbslet) b main
11136 Breakpoint 1 at 0x12010000: file prog.c, line 3.
11137 (gdbslet) run
11138 Starting program: prog
11139 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
11140 3 char *symarg = 0;
11141 (gdbslet) step
11142 4 char *execarg = "hello!";
11143 (gdbslet)
11144 @end example
11145
11146 @node Sparclite
11147 @subsection Fujitsu Sparclite
11148
11149 @table @code
11150
11151 @kindex target sparclite
11152 @item target sparclite @var{dev}
11153 Fujitsu sparclite boards, used only for the purpose of loading.
11154 You must use an additional command to debug the program.
11155 For example: target remote @var{dev} using @value{GDBN} standard
11156 remote protocol.
11157
11158 @end table
11159
11160 @node ST2000
11161 @subsection Tandem ST2000
11162
11163 @value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
11164 STDBUG protocol.
11165
11166 To connect your ST2000 to the host system, see the manufacturer's
11167 manual. Once the ST2000 is physically attached, you can run:
11168
11169 @example
11170 target st2000 @var{dev} @var{speed}
11171 @end example
11172
11173 @noindent
11174 to establish it as your debugging environment. @var{dev} is normally
11175 the name of a serial device, such as @file{/dev/ttya}, connected to the
11176 ST2000 via a serial line. You can instead specify @var{dev} as a TCP
11177 connection (for example, to a serial line attached via a terminal
11178 concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
11179
11180 The @code{load} and @code{attach} commands are @emph{not} defined for
11181 this target; you must load your program into the ST2000 as you normally
11182 would for standalone operation. @value{GDBN} reads debugging information
11183 (such as symbols) from a separate, debugging version of the program
11184 available on your host computer.
11185 @c FIXME!! This is terribly vague; what little content is here is
11186 @c basically hearsay.
11187
11188 @cindex ST2000 auxiliary commands
11189 These auxiliary @value{GDBN} commands are available to help you with the ST2000
11190 environment:
11191
11192 @table @code
11193 @item st2000 @var{command}
11194 @kindex st2000 @var{cmd}
11195 @cindex STDBUG commands (ST2000)
11196 @cindex commands to STDBUG (ST2000)
11197 Send a @var{command} to the STDBUG monitor. See the manufacturer's
11198 manual for available commands.
11199
11200 @item connect
11201 @cindex connect (to STDBUG)
11202 Connect the controlling terminal to the STDBUG command monitor. When
11203 you are done interacting with STDBUG, typing either of two character
11204 sequences gets you back to the @value{GDBN} command prompt:
11205 @kbd{@key{RET}~.} (Return, followed by tilde and period) or
11206 @kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
11207 @end table
11208
11209 @node Z8000
11210 @subsection Zilog Z8000
11211
11212 @cindex Z8000
11213 @cindex simulator, Z8000
11214 @cindex Zilog Z8000 simulator
11215
11216 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
11217 a Z8000 simulator.
11218
11219 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
11220 unsegmented variant of the Z8000 architecture) or the Z8001 (the
11221 segmented variant). The simulator recognizes which architecture is
11222 appropriate by inspecting the object code.
11223
11224 @table @code
11225 @item target sim @var{args}
11226 @kindex sim
11227 @kindex target sim@r{, with Z8000}
11228 Debug programs on a simulated CPU. If the simulator supports setup
11229 options, specify them via @var{args}.
11230 @end table
11231
11232 @noindent
11233 After specifying this target, you can debug programs for the simulated
11234 CPU in the same style as programs for your host computer; use the
11235 @code{file} command to load a new program image, the @code{run} command
11236 to run your program, and so on.
11237
11238 As well as making available all the usual machine registers
11239 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
11240 additional items of information as specially named registers:
11241
11242 @table @code
11243
11244 @item cycles
11245 Counts clock-ticks in the simulator.
11246
11247 @item insts
11248 Counts instructions run in the simulator.
11249
11250 @item time
11251 Execution time in 60ths of a second.
11252
11253 @end table
11254
11255 You can refer to these values in @value{GDBN} expressions with the usual
11256 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
11257 conditional breakpoint that suspends only after at least 5000
11258 simulated clock ticks.
11259
11260 @node Architectures
11261 @section Architectures
11262
11263 This section describes characteristics of architectures that affect
11264 all uses of @value{GDBN} with the architecture, both native and cross.
11265
11266 @menu
11267 * A29K::
11268 * Alpha::
11269 * MIPS::
11270 @end menu
11271
11272 @node A29K
11273 @subsection A29K
11274
11275 @table @code
11276
11277 @kindex set rstack_high_address
11278 @cindex AMD 29K register stack
11279 @cindex register stack, AMD29K
11280 @item set rstack_high_address @var{address}
11281 On AMD 29000 family processors, registers are saved in a separate
11282 @dfn{register stack}. There is no way for @value{GDBN} to determine the
11283 extent of this stack. Normally, @value{GDBN} just assumes that the
11284 stack is ``large enough''. This may result in @value{GDBN} referencing
11285 memory locations that do not exist. If necessary, you can get around
11286 this problem by specifying the ending address of the register stack with
11287 the @code{set rstack_high_address} command. The argument should be an
11288 address, which you probably want to precede with @samp{0x} to specify in
11289 hexadecimal.
11290
11291 @kindex show rstack_high_address
11292 @item show rstack_high_address
11293 Display the current limit of the register stack, on AMD 29000 family
11294 processors.
11295
11296 @end table
11297
11298 @node Alpha
11299 @subsection Alpha
11300
11301 See the following section.
11302
11303 @node MIPS
11304 @subsection MIPS
11305
11306 @cindex stack on Alpha
11307 @cindex stack on MIPS
11308 @cindex Alpha stack
11309 @cindex MIPS stack
11310 Alpha- and MIPS-based computers use an unusual stack frame, which
11311 sometimes requires @value{GDBN} to search backward in the object code to
11312 find the beginning of a function.
11313
11314 @cindex response time, MIPS debugging
11315 To improve response time (especially for embedded applications, where
11316 @value{GDBN} may be restricted to a slow serial line for this search)
11317 you may want to limit the size of this search, using one of these
11318 commands:
11319
11320 @table @code
11321 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
11322 @item set heuristic-fence-post @var{limit}
11323 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
11324 search for the beginning of a function. A value of @var{0} (the
11325 default) means there is no limit. However, except for @var{0}, the
11326 larger the limit the more bytes @code{heuristic-fence-post} must search
11327 and therefore the longer it takes to run.
11328
11329 @item show heuristic-fence-post
11330 Display the current limit.
11331 @end table
11332
11333 @noindent
11334 These commands are available @emph{only} when @value{GDBN} is configured
11335 for debugging programs on Alpha or MIPS processors.
11336
11337
11338 @node Controlling GDB
11339 @chapter Controlling @value{GDBN}
11340
11341 You can alter the way @value{GDBN} interacts with you by using the
11342 @code{set} command. For commands controlling how @value{GDBN} displays
11343 data, see @ref{Print Settings, ,Print settings}. Other settings are
11344 described here.
11345
11346 @menu
11347 * Prompt:: Prompt
11348 * Editing:: Command editing
11349 * History:: Command history
11350 * Screen Size:: Screen size
11351 * Numbers:: Numbers
11352 * Messages/Warnings:: Optional warnings and messages
11353 * Debugging Output:: Optional messages about internal happenings
11354 @end menu
11355
11356 @node Prompt
11357 @section Prompt
11358
11359 @cindex prompt
11360
11361 @value{GDBN} indicates its readiness to read a command by printing a string
11362 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
11363 can change the prompt string with the @code{set prompt} command. For
11364 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
11365 the prompt in one of the @value{GDBN} sessions so that you can always tell
11366 which one you are talking to.
11367
11368 @emph{Note:} @code{set prompt} does not add a space for you after the
11369 prompt you set. This allows you to set a prompt which ends in a space
11370 or a prompt that does not.
11371
11372 @table @code
11373 @kindex set prompt
11374 @item set prompt @var{newprompt}
11375 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
11376
11377 @kindex show prompt
11378 @item show prompt
11379 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
11380 @end table
11381
11382 @node Editing
11383 @section Command editing
11384 @cindex readline
11385 @cindex command line editing
11386
11387 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
11388 @sc{gnu} library provides consistent behavior for programs which provide a
11389 command line interface to the user. Advantages are @sc{gnu} Emacs-style
11390 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
11391 substitution, and a storage and recall of command history across
11392 debugging sessions.
11393
11394 You may control the behavior of command line editing in @value{GDBN} with the
11395 command @code{set}.
11396
11397 @table @code
11398 @kindex set editing
11399 @cindex editing
11400 @item set editing
11401 @itemx set editing on
11402 Enable command line editing (enabled by default).
11403
11404 @item set editing off
11405 Disable command line editing.
11406
11407 @kindex show editing
11408 @item show editing
11409 Show whether command line editing is enabled.
11410 @end table
11411
11412 @node History
11413 @section Command history
11414
11415 @value{GDBN} can keep track of the commands you type during your
11416 debugging sessions, so that you can be certain of precisely what
11417 happened. Use these commands to manage the @value{GDBN} command
11418 history facility.
11419
11420 @table @code
11421 @cindex history substitution
11422 @cindex history file
11423 @kindex set history filename
11424 @kindex GDBHISTFILE
11425 @item set history filename @var{fname}
11426 Set the name of the @value{GDBN} command history file to @var{fname}.
11427 This is the file where @value{GDBN} reads an initial command history
11428 list, and where it writes the command history from this session when it
11429 exits. You can access this list through history expansion or through
11430 the history command editing characters listed below. This file defaults
11431 to the value of the environment variable @code{GDBHISTFILE}, or to
11432 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
11433 is not set.
11434
11435 @cindex history save
11436 @kindex set history save
11437 @item set history save
11438 @itemx set history save on
11439 Record command history in a file, whose name may be specified with the
11440 @code{set history filename} command. By default, this option is disabled.
11441
11442 @item set history save off
11443 Stop recording command history in a file.
11444
11445 @cindex history size
11446 @kindex set history size
11447 @item set history size @var{size}
11448 Set the number of commands which @value{GDBN} keeps in its history list.
11449 This defaults to the value of the environment variable
11450 @code{HISTSIZE}, or to 256 if this variable is not set.
11451 @end table
11452
11453 @cindex history expansion
11454 History expansion assigns special meaning to the character @kbd{!}.
11455 @ifset have-readline-appendices
11456 @xref{Event Designators}.
11457 @end ifset
11458
11459 Since @kbd{!} is also the logical not operator in C, history expansion
11460 is off by default. If you decide to enable history expansion with the
11461 @code{set history expansion on} command, you may sometimes need to
11462 follow @kbd{!} (when it is used as logical not, in an expression) with
11463 a space or a tab to prevent it from being expanded. The readline
11464 history facilities do not attempt substitution on the strings
11465 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
11466
11467 The commands to control history expansion are:
11468
11469 @table @code
11470 @kindex set history expansion
11471 @item set history expansion on
11472 @itemx set history expansion
11473 Enable history expansion. History expansion is off by default.
11474
11475 @item set history expansion off
11476 Disable history expansion.
11477
11478 The readline code comes with more complete documentation of
11479 editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
11480 or @code{vi} may wish to read it.
11481 @ifset have-readline-appendices
11482 @xref{Command Line Editing}.
11483 @end ifset
11484
11485 @c @group
11486 @kindex show history
11487 @item show history
11488 @itemx show history filename
11489 @itemx show history save
11490 @itemx show history size
11491 @itemx show history expansion
11492 These commands display the state of the @value{GDBN} history parameters.
11493 @code{show history} by itself displays all four states.
11494 @c @end group
11495 @end table
11496
11497 @table @code
11498 @kindex shows
11499 @item show commands
11500 Display the last ten commands in the command history.
11501
11502 @item show commands @var{n}
11503 Print ten commands centered on command number @var{n}.
11504
11505 @item show commands +
11506 Print ten commands just after the commands last printed.
11507 @end table
11508
11509 @node Screen Size
11510 @section Screen size
11511 @cindex size of screen
11512 @cindex pauses in output
11513
11514 Certain commands to @value{GDBN} may produce large amounts of
11515 information output to the screen. To help you read all of it,
11516 @value{GDBN} pauses and asks you for input at the end of each page of
11517 output. Type @key{RET} when you want to continue the output, or @kbd{q}
11518 to discard the remaining output. Also, the screen width setting
11519 determines when to wrap lines of output. Depending on what is being
11520 printed, @value{GDBN} tries to break the line at a readable place,
11521 rather than simply letting it overflow onto the following line.
11522
11523 Normally @value{GDBN} knows the size of the screen from the terminal
11524 driver software. For example, on Unix @value{GDBN} uses the termcap data base
11525 together with the value of the @code{TERM} environment variable and the
11526 @code{stty rows} and @code{stty cols} settings. If this is not correct,
11527 you can override it with the @code{set height} and @code{set
11528 width} commands:
11529
11530 @table @code
11531 @kindex set height
11532 @kindex set width
11533 @kindex show width
11534 @kindex show height
11535 @item set height @var{lpp}
11536 @itemx show height
11537 @itemx set width @var{cpl}
11538 @itemx show width
11539 These @code{set} commands specify a screen height of @var{lpp} lines and
11540 a screen width of @var{cpl} characters. The associated @code{show}
11541 commands display the current settings.
11542
11543 If you specify a height of zero lines, @value{GDBN} does not pause during
11544 output no matter how long the output is. This is useful if output is to a
11545 file or to an editor buffer.
11546
11547 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
11548 from wrapping its output.
11549 @end table
11550
11551 @node Numbers
11552 @section Numbers
11553 @cindex number representation
11554 @cindex entering numbers
11555
11556 You can always enter numbers in octal, decimal, or hexadecimal in
11557 @value{GDBN} by the usual conventions: octal numbers begin with
11558 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
11559 begin with @samp{0x}. Numbers that begin with none of these are, by
11560 default, entered in base 10; likewise, the default display for
11561 numbers---when no particular format is specified---is base 10. You can
11562 change the default base for both input and output with the @code{set
11563 radix} command.
11564
11565 @table @code
11566 @kindex set input-radix
11567 @item set input-radix @var{base}
11568 Set the default base for numeric input. Supported choices
11569 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11570 specified either unambiguously or using the current default radix; for
11571 example, any of
11572
11573 @smallexample
11574 set radix 012
11575 set radix 10.
11576 set radix 0xa
11577 @end smallexample
11578
11579 @noindent
11580 sets the base to decimal. On the other hand, @samp{set radix 10}
11581 leaves the radix unchanged no matter what it was.
11582
11583 @kindex set output-radix
11584 @item set output-radix @var{base}
11585 Set the default base for numeric display. Supported choices
11586 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11587 specified either unambiguously or using the current default radix.
11588
11589 @kindex show input-radix
11590 @item show input-radix
11591 Display the current default base for numeric input.
11592
11593 @kindex show output-radix
11594 @item show output-radix
11595 Display the current default base for numeric display.
11596 @end table
11597
11598 @node Messages/Warnings
11599 @section Optional warnings and messages
11600
11601 By default, @value{GDBN} is silent about its inner workings. If you are
11602 running on a slow machine, you may want to use the @code{set verbose}
11603 command. This makes @value{GDBN} tell you when it does a lengthy
11604 internal operation, so you will not think it has crashed.
11605
11606 Currently, the messages controlled by @code{set verbose} are those
11607 which announce that the symbol table for a source file is being read;
11608 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
11609
11610 @table @code
11611 @kindex set verbose
11612 @item set verbose on
11613 Enables @value{GDBN} output of certain informational messages.
11614
11615 @item set verbose off
11616 Disables @value{GDBN} output of certain informational messages.
11617
11618 @kindex show verbose
11619 @item show verbose
11620 Displays whether @code{set verbose} is on or off.
11621 @end table
11622
11623 By default, if @value{GDBN} encounters bugs in the symbol table of an
11624 object file, it is silent; but if you are debugging a compiler, you may
11625 find this information useful (@pxref{Symbol Errors, ,Errors reading
11626 symbol files}).
11627
11628 @table @code
11629
11630 @kindex set complaints
11631 @item set complaints @var{limit}
11632 Permits @value{GDBN} to output @var{limit} complaints about each type of
11633 unusual symbols before becoming silent about the problem. Set
11634 @var{limit} to zero to suppress all complaints; set it to a large number
11635 to prevent complaints from being suppressed.
11636
11637 @kindex show complaints
11638 @item show complaints
11639 Displays how many symbol complaints @value{GDBN} is permitted to produce.
11640
11641 @end table
11642
11643 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
11644 lot of stupid questions to confirm certain commands. For example, if
11645 you try to run a program which is already running:
11646
11647 @example
11648 (@value{GDBP}) run
11649 The program being debugged has been started already.
11650 Start it from the beginning? (y or n)
11651 @end example
11652
11653 If you are willing to unflinchingly face the consequences of your own
11654 commands, you can disable this ``feature'':
11655
11656 @table @code
11657
11658 @kindex set confirm
11659 @cindex flinching
11660 @cindex confirmation
11661 @cindex stupid questions
11662 @item set confirm off
11663 Disables confirmation requests.
11664
11665 @item set confirm on
11666 Enables confirmation requests (the default).
11667
11668 @kindex show confirm
11669 @item show confirm
11670 Displays state of confirmation requests.
11671
11672 @end table
11673
11674 @node Debugging Output
11675 @section Optional messages about internal happenings
11676 @table @code
11677 @kindex set debug arch
11678 @item set debug arch
11679 Turns on or off display of gdbarch debugging info. The default is off
11680 @kindex show debug arch
11681 @item show debug arch
11682 Displays the current state of displaying gdbarch debugging info.
11683 @kindex set debug event
11684 @item set debug event
11685 Turns on or off display of @value{GDBN} event debugging info. The
11686 default is off.
11687 @kindex show debug event
11688 @item show debug event
11689 Displays the current state of displaying @value{GDBN} event debugging
11690 info.
11691 @kindex set debug expression
11692 @item set debug expression
11693 Turns on or off display of @value{GDBN} expression debugging info. The
11694 default is off.
11695 @kindex show debug expression
11696 @item show debug expression
11697 Displays the current state of displaying @value{GDBN} expression
11698 debugging info.
11699 @kindex set debug overload
11700 @item set debug overload
11701 Turns on or off display of @value{GDBN} C++ overload debugging
11702 info. This includes info such as ranking of functions, etc. The default
11703 is off.
11704 @kindex show debug overload
11705 @item show debug overload
11706 Displays the current state of displaying @value{GDBN} C++ overload
11707 debugging info.
11708 @kindex set debug remote
11709 @cindex packets, reporting on stdout
11710 @cindex serial connections, debugging
11711 @item set debug remote
11712 Turns on or off display of reports on all packets sent back and forth across
11713 the serial line to the remote machine. The info is printed on the
11714 @value{GDBN} standard output stream. The default is off.
11715 @kindex show debug remote
11716 @item show debug remote
11717 Displays the state of display of remote packets.
11718 @kindex set debug serial
11719 @item set debug serial
11720 Turns on or off display of @value{GDBN} serial debugging info. The
11721 default is off.
11722 @kindex show debug serial
11723 @item show debug serial
11724 Displays the current state of displaying @value{GDBN} serial debugging
11725 info.
11726 @kindex set debug target
11727 @item set debug target
11728 Turns on or off display of @value{GDBN} target debugging info. This info
11729 includes what is going on at the target level of GDB, as it happens. The
11730 default is off.
11731 @kindex show debug target
11732 @item show debug target
11733 Displays the current state of displaying @value{GDBN} target debugging
11734 info.
11735 @kindex set debug varobj
11736 @item set debug varobj
11737 Turns on or off display of @value{GDBN} variable object debugging
11738 info. The default is off.
11739 @kindex show debug varobj
11740 @item show debug varobj
11741 Displays the current state of displaying @value{GDBN} variable object
11742 debugging info.
11743 @end table
11744
11745 @node Sequences
11746 @chapter Canned Sequences of Commands
11747
11748 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
11749 command lists}), @value{GDBN} provides two ways to store sequences of
11750 commands for execution as a unit: user-defined commands and command
11751 files.
11752
11753 @menu
11754 * Define:: User-defined commands
11755 * Hooks:: User-defined command hooks
11756 * Command Files:: Command files
11757 * Output:: Commands for controlled output
11758 @end menu
11759
11760 @node Define
11761 @section User-defined commands
11762
11763 @cindex user-defined command
11764 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
11765 which you assign a new name as a command. This is done with the
11766 @code{define} command. User commands may accept up to 10 arguments
11767 separated by whitespace. Arguments are accessed within the user command
11768 via @var{$arg0@dots{}$arg9}. A trivial example:
11769
11770 @smallexample
11771 define adder
11772 print $arg0 + $arg1 + $arg2
11773 @end smallexample
11774
11775 @noindent
11776 To execute the command use:
11777
11778 @smallexample
11779 adder 1 2 3
11780 @end smallexample
11781
11782 @noindent
11783 This defines the command @code{adder}, which prints the sum of
11784 its three arguments. Note the arguments are text substitutions, so they may
11785 reference variables, use complex expressions, or even perform inferior
11786 functions calls.
11787
11788 @table @code
11789
11790 @kindex define
11791 @item define @var{commandname}
11792 Define a command named @var{commandname}. If there is already a command
11793 by that name, you are asked to confirm that you want to redefine it.
11794
11795 The definition of the command is made up of other @value{GDBN} command lines,
11796 which are given following the @code{define} command. The end of these
11797 commands is marked by a line containing @code{end}.
11798
11799 @kindex if
11800 @kindex else
11801 @item if
11802 Takes a single argument, which is an expression to evaluate.
11803 It is followed by a series of commands that are executed
11804 only if the expression is true (nonzero).
11805 There can then optionally be a line @code{else}, followed
11806 by a series of commands that are only executed if the expression
11807 was false. The end of the list is marked by a line containing @code{end}.
11808
11809 @kindex while
11810 @item while
11811 The syntax is similar to @code{if}: the command takes a single argument,
11812 which is an expression to evaluate, and must be followed by the commands to
11813 execute, one per line, terminated by an @code{end}.
11814 The commands are executed repeatedly as long as the expression
11815 evaluates to true.
11816
11817 @kindex document
11818 @item document @var{commandname}
11819 Document the user-defined command @var{commandname}, so that it can be
11820 accessed by @code{help}. The command @var{commandname} must already be
11821 defined. This command reads lines of documentation just as @code{define}
11822 reads the lines of the command definition, ending with @code{end}.
11823 After the @code{document} command is finished, @code{help} on command
11824 @var{commandname} displays the documentation you have written.
11825
11826 You may use the @code{document} command again to change the
11827 documentation of a command. Redefining the command with @code{define}
11828 does not change the documentation.
11829
11830 @kindex help user-defined
11831 @item help user-defined
11832 List all user-defined commands, with the first line of the documentation
11833 (if any) for each.
11834
11835 @kindex show user
11836 @item show user
11837 @itemx show user @var{commandname}
11838 Display the @value{GDBN} commands used to define @var{commandname} (but
11839 not its documentation). If no @var{commandname} is given, display the
11840 definitions for all user-defined commands.
11841
11842 @end table
11843
11844 When user-defined commands are executed, the
11845 commands of the definition are not printed. An error in any command
11846 stops execution of the user-defined command.
11847
11848 If used interactively, commands that would ask for confirmation proceed
11849 without asking when used inside a user-defined command. Many @value{GDBN}
11850 commands that normally print messages to say what they are doing omit the
11851 messages when used in a user-defined command.
11852
11853 @node Hooks
11854 @section User-defined command hooks
11855 @cindex command hooks
11856 @cindex hooks, for commands
11857
11858 You may define @emph{hooks}, which are a special kind of user-defined
11859 command. Whenever you run the command @samp{foo}, if the user-defined
11860 command @samp{hook-foo} exists, it is executed (with no arguments)
11861 before that command.
11862
11863 @kindex stop@r{, a pseudo-command}
11864 In addition, a pseudo-command, @samp{stop} exists. Defining
11865 (@samp{hook-stop}) makes the associated commands execute every time
11866 execution stops in your program: before breakpoint commands are run,
11867 displays are printed, or the stack frame is printed.
11868
11869 For example, to ignore @code{SIGALRM} signals while
11870 single-stepping, but treat them normally during normal execution,
11871 you could define:
11872
11873 @example
11874 define hook-stop
11875 handle SIGALRM nopass
11876 end
11877
11878 define hook-run
11879 handle SIGALRM pass
11880 end
11881
11882 define hook-continue
11883 handle SIGLARM pass
11884 end
11885 @end example
11886
11887 You can define a hook for any single-word command in @value{GDBN}, but
11888 not for command aliases; you should define a hook for the basic command
11889 name, e.g. @code{backtrace} rather than @code{bt}.
11890 @c FIXME! So how does Joe User discover whether a command is an alias
11891 @c or not?
11892 If an error occurs during the execution of your hook, execution of
11893 @value{GDBN} commands stops and @value{GDBN} issues a prompt
11894 (before the command that you actually typed had a chance to run).
11895
11896 If you try to define a hook which does not match any known command, you
11897 get a warning from the @code{define} command.
11898
11899 @node Command Files
11900 @section Command files
11901
11902 @cindex command files
11903 A command file for @value{GDBN} is a file of lines that are @value{GDBN}
11904 commands. Comments (lines starting with @kbd{#}) may also be included.
11905 An empty line in a command file does nothing; it does not mean to repeat
11906 the last command, as it would from the terminal.
11907
11908 @cindex init file
11909 @cindex @file{.gdbinit}
11910 @cindex @file{gdb.ini}
11911 When you start @value{GDBN}, it automatically executes commands from its
11912 @dfn{init files}. These are files named @file{.gdbinit} on Unix and
11913 @file{gdb.ini} on DOS/Windows. During startup, @value{GDBN} does the
11914 following:
11915
11916 @enumerate
11917 @item
11918 Reads the init file (if any) in your home directory@footnote{On
11919 DOS/Windows systems, the home directory is the one pointed to by the
11920 @code{HOME} environment variable.}.
11921
11922 @item
11923 Processes command line options and operands.
11924
11925 @item
11926 Reads the init file (if any) in the current working directory.
11927
11928 @item
11929 Reads command files specified by the @samp{-x} option.
11930 @end enumerate
11931
11932 The init file in your home directory can set options (such as @samp{set
11933 complaints}) that affect subsequent processing of command line options
11934 and operands. Init files are not executed if you use the @samp{-nx}
11935 option (@pxref{Mode Options, ,Choosing modes}).
11936
11937 @cindex init file name
11938 On some configurations of @value{GDBN}, the init file is known by a
11939 different name (these are typically environments where a specialized
11940 form of @value{GDBN} may need to coexist with other forms, hence a
11941 different name for the specialized version's init file). These are the
11942 environments with special init file names:
11943
11944 @cindex @file{.vxgdbinit}
11945 @itemize @bullet
11946 @item
11947 VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
11948
11949 @cindex @file{.os68gdbinit}
11950 @item
11951 OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
11952
11953 @cindex @file{.esgdbinit}
11954 @item
11955 ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
11956 @end itemize
11957
11958 You can also request the execution of a command file with the
11959 @code{source} command:
11960
11961 @table @code
11962 @kindex source
11963 @item source @var{filename}
11964 Execute the command file @var{filename}.
11965 @end table
11966
11967 The lines in a command file are executed sequentially. They are not
11968 printed as they are executed. An error in any command terminates execution
11969 of the command file.
11970
11971 Commands that would ask for confirmation if used interactively proceed
11972 without asking when used in a command file. Many @value{GDBN} commands that
11973 normally print messages to say what they are doing omit the messages
11974 when called from command files.
11975
11976 @node Output
11977 @section Commands for controlled output
11978
11979 During the execution of a command file or a user-defined command, normal
11980 @value{GDBN} output is suppressed; the only output that appears is what is
11981 explicitly printed by the commands in the definition. This section
11982 describes three commands useful for generating exactly the output you
11983 want.
11984
11985 @table @code
11986 @kindex echo
11987 @item echo @var{text}
11988 @c I do not consider backslash-space a standard C escape sequence
11989 @c because it is not in ANSI.
11990 Print @var{text}. Nonprinting characters can be included in
11991 @var{text} using C escape sequences, such as @samp{\n} to print a
11992 newline. @strong{No newline is printed unless you specify one.}
11993 In addition to the standard C escape sequences, a backslash followed
11994 by a space stands for a space. This is useful for displaying a
11995 string with spaces at the beginning or the end, since leading and
11996 trailing spaces are otherwise trimmed from all arguments.
11997 To print @samp{@w{ }and foo =@w{ }}, use the command
11998 @samp{echo \@w{ }and foo = \@w{ }}.
11999
12000 A backslash at the end of @var{text} can be used, as in C, to continue
12001 the command onto subsequent lines. For example,
12002
12003 @example
12004 echo This is some text\n\
12005 which is continued\n\
12006 onto several lines.\n
12007 @end example
12008
12009 produces the same output as
12010
12011 @example
12012 echo This is some text\n
12013 echo which is continued\n
12014 echo onto several lines.\n
12015 @end example
12016
12017 @kindex output
12018 @item output @var{expression}
12019 Print the value of @var{expression} and nothing but that value: no
12020 newlines, no @samp{$@var{nn} = }. The value is not entered in the
12021 value history either. @xref{Expressions, ,Expressions}, for more information
12022 on expressions.
12023
12024 @item output/@var{fmt} @var{expression}
12025 Print the value of @var{expression} in format @var{fmt}. You can use
12026 the same formats as for @code{print}. @xref{Output Formats,,Output
12027 formats}, for more information.
12028
12029 @kindex printf
12030 @item printf @var{string}, @var{expressions}@dots{}
12031 Print the values of the @var{expressions} under the control of
12032 @var{string}. The @var{expressions} are separated by commas and may be
12033 either numbers or pointers. Their values are printed as specified by
12034 @var{string}, exactly as if your program were to execute the C
12035 subroutine
12036 @c FIXME: the above implies that at least all ANSI C formats are
12037 @c supported, but it isn't true: %E and %G don't work (or so it seems).
12038 @c Either this is a bug, or the manual should document what formats are
12039 @c supported.
12040
12041 @example
12042 printf (@var{string}, @var{expressions}@dots{});
12043 @end example
12044
12045 For example, you can print two values in hex like this:
12046
12047 @smallexample
12048 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
12049 @end smallexample
12050
12051 The only backslash-escape sequences that you can use in the format
12052 string are the simple ones that consist of backslash followed by a
12053 letter.
12054 @end table
12055
12056 @node Emacs
12057 @chapter Using @value{GDBN} under @sc{gnu} Emacs
12058
12059 @cindex Emacs
12060 @cindex @sc{gnu} Emacs
12061 A special interface allows you to use @sc{gnu} Emacs to view (and
12062 edit) the source files for the program you are debugging with
12063 @value{GDBN}.
12064
12065 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
12066 executable file you want to debug as an argument. This command starts
12067 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
12068 created Emacs buffer.
12069 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
12070
12071 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
12072 things:
12073
12074 @itemize @bullet
12075 @item
12076 All ``terminal'' input and output goes through the Emacs buffer.
12077 @end itemize
12078
12079 This applies both to @value{GDBN} commands and their output, and to the input
12080 and output done by the program you are debugging.
12081
12082 This is useful because it means that you can copy the text of previous
12083 commands and input them again; you can even use parts of the output
12084 in this way.
12085
12086 All the facilities of Emacs' Shell mode are available for interacting
12087 with your program. In particular, you can send signals the usual
12088 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
12089 stop.
12090
12091 @itemize @bullet
12092 @item
12093 @value{GDBN} displays source code through Emacs.
12094 @end itemize
12095
12096 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
12097 source file for that frame and puts an arrow (@samp{=>}) at the
12098 left margin of the current line. Emacs uses a separate buffer for
12099 source display, and splits the screen to show both your @value{GDBN} session
12100 and the source.
12101
12102 Explicit @value{GDBN} @code{list} or search commands still produce output as
12103 usual, but you probably have no reason to use them from Emacs.
12104
12105 @quotation
12106 @emph{Warning:} If the directory where your program resides is not your
12107 current directory, it can be easy to confuse Emacs about the location of
12108 the source files, in which case the auxiliary display buffer does not
12109 appear to show your source. @value{GDBN} can find programs by searching your
12110 environment's @code{PATH} variable, so the @value{GDBN} input and output
12111 session proceeds normally; but Emacs does not get enough information
12112 back from @value{GDBN} to locate the source files in this situation. To
12113 avoid this problem, either start @value{GDBN} mode from the directory where
12114 your program resides, or specify an absolute file name when prompted for the
12115 @kbd{M-x gdb} argument.
12116
12117 A similar confusion can result if you use the @value{GDBN} @code{file} command to
12118 switch to debugging a program in some other location, from an existing
12119 @value{GDBN} buffer in Emacs.
12120 @end quotation
12121
12122 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
12123 you need to call @value{GDBN} by a different name (for example, if you keep
12124 several configurations around, with different names) you can set the
12125 Emacs variable @code{gdb-command-name}; for example,
12126
12127 @example
12128 (setq gdb-command-name "mygdb")
12129 @end example
12130
12131 @noindent
12132 (preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
12133 in your @file{.emacs} file) makes Emacs call the program named
12134 ``@code{mygdb}'' instead.
12135
12136 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
12137 addition to the standard Shell mode commands:
12138
12139 @table @kbd
12140 @item C-h m
12141 Describe the features of Emacs' @value{GDBN} Mode.
12142
12143 @item M-s
12144 Execute to another source line, like the @value{GDBN} @code{step} command; also
12145 update the display window to show the current file and location.
12146
12147 @item M-n
12148 Execute to next source line in this function, skipping all function
12149 calls, like the @value{GDBN} @code{next} command. Then update the display window
12150 to show the current file and location.
12151
12152 @item M-i
12153 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
12154 display window accordingly.
12155
12156 @item M-x gdb-nexti
12157 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
12158 display window accordingly.
12159
12160 @item C-c C-f
12161 Execute until exit from the selected stack frame, like the @value{GDBN}
12162 @code{finish} command.
12163
12164 @item M-c
12165 Continue execution of your program, like the @value{GDBN} @code{continue}
12166 command.
12167
12168 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
12169
12170 @item M-u
12171 Go up the number of frames indicated by the numeric argument
12172 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
12173 like the @value{GDBN} @code{up} command.
12174
12175 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
12176
12177 @item M-d
12178 Go down the number of frames indicated by the numeric argument, like the
12179 @value{GDBN} @code{down} command.
12180
12181 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
12182
12183 @item C-x &
12184 Read the number where the cursor is positioned, and insert it at the end
12185 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
12186 around an address that was displayed earlier, type @kbd{disassemble};
12187 then move the cursor to the address display, and pick up the
12188 argument for @code{disassemble} by typing @kbd{C-x &}.
12189
12190 You can customize this further by defining elements of the list
12191 @code{gdb-print-command}; once it is defined, you can format or
12192 otherwise process numbers picked up by @kbd{C-x &} before they are
12193 inserted. A numeric argument to @kbd{C-x &} indicates that you
12194 wish special formatting, and also acts as an index to pick an element of the
12195 list. If the list element is a string, the number to be inserted is
12196 formatted using the Emacs function @code{format}; otherwise the number
12197 is passed as an argument to the corresponding list element.
12198 @end table
12199
12200 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
12201 tells @value{GDBN} to set a breakpoint on the source line point is on.
12202
12203 If you accidentally delete the source-display buffer, an easy way to get
12204 it back is to type the command @code{f} in the @value{GDBN} buffer, to
12205 request a frame display; when you run under Emacs, this recreates
12206 the source buffer if necessary to show you the context of the current
12207 frame.
12208
12209 The source files displayed in Emacs are in ordinary Emacs buffers
12210 which are visiting the source files in the usual way. You can edit
12211 the files with these buffers if you wish; but keep in mind that @value{GDBN}
12212 communicates with Emacs in terms of line numbers. If you add or
12213 delete lines from the text, the line numbers that @value{GDBN} knows cease
12214 to correspond properly with the code.
12215
12216 @c The following dropped because Epoch is nonstandard. Reactivate
12217 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
12218 @ignore
12219 @kindex Emacs Epoch environment
12220 @kindex Epoch
12221 @kindex inspect
12222
12223 Version 18 of @sc{gnu} Emacs has a built-in window system
12224 called the @code{epoch}
12225 environment. Users of this environment can use a new command,
12226 @code{inspect} which performs identically to @code{print} except that
12227 each value is printed in its own window.
12228 @end ignore
12229
12230 @include annotate.texi
12231 @include gdbmi.texinfo
12232
12233 @node GDB Bugs
12234 @chapter Reporting Bugs in @value{GDBN}
12235 @cindex bugs in @value{GDBN}
12236 @cindex reporting bugs in @value{GDBN}
12237
12238 Your bug reports play an essential role in making @value{GDBN} reliable.
12239
12240 Reporting a bug may help you by bringing a solution to your problem, or it
12241 may not. But in any case the principal function of a bug report is to help
12242 the entire community by making the next version of @value{GDBN} work better. Bug
12243 reports are your contribution to the maintenance of @value{GDBN}.
12244
12245 In order for a bug report to serve its purpose, you must include the
12246 information that enables us to fix the bug.
12247
12248 @menu
12249 * Bug Criteria:: Have you found a bug?
12250 * Bug Reporting:: How to report bugs
12251 @end menu
12252
12253 @node Bug Criteria
12254 @section Have you found a bug?
12255 @cindex bug criteria
12256
12257 If you are not sure whether you have found a bug, here are some guidelines:
12258
12259 @itemize @bullet
12260 @cindex fatal signal
12261 @cindex debugger crash
12262 @cindex crash of debugger
12263 @item
12264 If the debugger gets a fatal signal, for any input whatever, that is a
12265 @value{GDBN} bug. Reliable debuggers never crash.
12266
12267 @cindex error on valid input
12268 @item
12269 If @value{GDBN} produces an error message for valid input, that is a
12270 bug. (Note that if you're cross debugging, the problem may also be
12271 somewhere in the connection to the target.)
12272
12273 @cindex invalid input
12274 @item
12275 If @value{GDBN} does not produce an error message for invalid input,
12276 that is a bug. However, you should note that your idea of
12277 ``invalid input'' might be our idea of ``an extension'' or ``support
12278 for traditional practice''.
12279
12280 @item
12281 If you are an experienced user of debugging tools, your suggestions
12282 for improvement of @value{GDBN} are welcome in any case.
12283 @end itemize
12284
12285 @node Bug Reporting
12286 @section How to report bugs
12287 @cindex bug reports
12288 @cindex @value{GDBN} bugs, reporting
12289
12290 A number of companies and individuals offer support for @sc{gnu} products.
12291 If you obtained @value{GDBN} from a support organization, we recommend you
12292 contact that organization first.
12293
12294 You can find contact information for many support companies and
12295 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
12296 distribution.
12297 @c should add a web page ref...
12298
12299 In any event, we also recommend that you send bug reports for
12300 @value{GDBN} to this addresses:
12301
12302 @example
12303 bug-gdb@@gnu.org
12304 @end example
12305
12306 @strong{Do not send bug reports to @samp{info-gdb}, or to
12307 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
12308 not want to receive bug reports. Those that do have arranged to receive
12309 @samp{bug-gdb}.
12310
12311 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
12312 serves as a repeater. The mailing list and the newsgroup carry exactly
12313 the same messages. Often people think of posting bug reports to the
12314 newsgroup instead of mailing them. This appears to work, but it has one
12315 problem which can be crucial: a newsgroup posting often lacks a mail
12316 path back to the sender. Thus, if we need to ask for more information,
12317 we may be unable to reach you. For this reason, it is better to send
12318 bug reports to the mailing list.
12319
12320 As a last resort, send bug reports on paper to:
12321
12322 @example
12323 @sc{gnu} Debugger Bugs
12324 Free Software Foundation Inc.
12325 59 Temple Place - Suite 330
12326 Boston, MA 02111-1307
12327 USA
12328 @end example
12329
12330 The fundamental principle of reporting bugs usefully is this:
12331 @strong{report all the facts}. If you are not sure whether to state a
12332 fact or leave it out, state it!
12333
12334 Often people omit facts because they think they know what causes the
12335 problem and assume that some details do not matter. Thus, you might
12336 assume that the name of the variable you use in an example does not matter.
12337 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
12338 stray memory reference which happens to fetch from the location where that
12339 name is stored in memory; perhaps, if the name were different, the contents
12340 of that location would fool the debugger into doing the right thing despite
12341 the bug. Play it safe and give a specific, complete example. That is the
12342 easiest thing for you to do, and the most helpful.
12343
12344 Keep in mind that the purpose of a bug report is to enable us to fix the
12345 bug. It may be that the bug has been reported previously, but neither
12346 you nor we can know that unless your bug report is complete and
12347 self-contained.
12348
12349 Sometimes people give a few sketchy facts and ask, ``Does this ring a
12350 bell?'' Those bug reports are useless, and we urge everyone to
12351 @emph{refuse to respond to them} except to chide the sender to report
12352 bugs properly.
12353
12354 To enable us to fix the bug, you should include all these things:
12355
12356 @itemize @bullet
12357 @item
12358 The version of @value{GDBN}. @value{GDBN} announces it if you start
12359 with no arguments; you can also print it at any time using @code{show
12360 version}.
12361
12362 Without this, we will not know whether there is any point in looking for
12363 the bug in the current version of @value{GDBN}.
12364
12365 @item
12366 The type of machine you are using, and the operating system name and
12367 version number.
12368
12369 @item
12370 What compiler (and its version) was used to compile @value{GDBN}---e.g.
12371 ``@value{GCC}--2.8.1''.
12372
12373 @item
12374 What compiler (and its version) was used to compile the program you are
12375 debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
12376 C Compiler''. For GCC, you can say @code{gcc --version} to get this
12377 information; for other compilers, see the documentation for those
12378 compilers.
12379
12380 @item
12381 The command arguments you gave the compiler to compile your example and
12382 observe the bug. For example, did you use @samp{-O}? To guarantee
12383 you will not omit something important, list them all. A copy of the
12384 Makefile (or the output from make) is sufficient.
12385
12386 If we were to try to guess the arguments, we would probably guess wrong
12387 and then we might not encounter the bug.
12388
12389 @item
12390 A complete input script, and all necessary source files, that will
12391 reproduce the bug.
12392
12393 @item
12394 A description of what behavior you observe that you believe is
12395 incorrect. For example, ``It gets a fatal signal.''
12396
12397 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
12398 will certainly notice it. But if the bug is incorrect output, we might
12399 not notice unless it is glaringly wrong. You might as well not give us
12400 a chance to make a mistake.
12401
12402 Even if the problem you experience is a fatal signal, you should still
12403 say so explicitly. Suppose something strange is going on, such as, your
12404 copy of @value{GDBN} is out of synch, or you have encountered a bug in
12405 the C library on your system. (This has happened!) Your copy might
12406 crash and ours would not. If you told us to expect a crash, then when
12407 ours fails to crash, we would know that the bug was not happening for
12408 us. If you had not told us to expect a crash, then we would not be able
12409 to draw any conclusion from our observations.
12410
12411 @item
12412 If you wish to suggest changes to the @value{GDBN} source, send us context
12413 diffs. If you even discuss something in the @value{GDBN} source, refer to
12414 it by context, not by line number.
12415
12416 The line numbers in our development sources will not match those in your
12417 sources. Your line numbers would convey no useful information to us.
12418
12419 @end itemize
12420
12421 Here are some things that are not necessary:
12422
12423 @itemize @bullet
12424 @item
12425 A description of the envelope of the bug.
12426
12427 Often people who encounter a bug spend a lot of time investigating
12428 which changes to the input file will make the bug go away and which
12429 changes will not affect it.
12430
12431 This is often time consuming and not very useful, because the way we
12432 will find the bug is by running a single example under the debugger
12433 with breakpoints, not by pure deduction from a series of examples.
12434 We recommend that you save your time for something else.
12435
12436 Of course, if you can find a simpler example to report @emph{instead}
12437 of the original one, that is a convenience for us. Errors in the
12438 output will be easier to spot, running under the debugger will take
12439 less time, and so on.
12440
12441 However, simplification is not vital; if you do not want to do this,
12442 report the bug anyway and send us the entire test case you used.
12443
12444 @item
12445 A patch for the bug.
12446
12447 A patch for the bug does help us if it is a good one. But do not omit
12448 the necessary information, such as the test case, on the assumption that
12449 a patch is all we need. We might see problems with your patch and decide
12450 to fix the problem another way, or we might not understand it at all.
12451
12452 Sometimes with a program as complicated as @value{GDBN} it is very hard to
12453 construct an example that will make the program follow a certain path
12454 through the code. If you do not send us the example, we will not be able
12455 to construct one, so we will not be able to verify that the bug is fixed.
12456
12457 And if we cannot understand what bug you are trying to fix, or why your
12458 patch should be an improvement, we will not install it. A test case will
12459 help us to understand.
12460
12461 @item
12462 A guess about what the bug is or what it depends on.
12463
12464 Such guesses are usually wrong. Even we cannot guess right about such
12465 things without first using the debugger to find the facts.
12466 @end itemize
12467
12468 @c The readline documentation is distributed with the readline code
12469 @c and consists of the two following files:
12470 @c rluser.texinfo
12471 @c inc-hist.texinfo
12472 @c Use -I with makeinfo to point to the appropriate directory,
12473 @c environment var TEXINPUTS with TeX.
12474 @include rluser.texinfo
12475 @include inc-hist.texinfo
12476
12477
12478 @node Formatting Documentation
12479 @appendix Formatting Documentation
12480
12481 @cindex @value{GDBN} reference card
12482 @cindex reference card
12483 The @value{GDBN} 4 release includes an already-formatted reference card, ready
12484 for printing with PostScript or Ghostscript, in the @file{gdb}
12485 subdirectory of the main source directory@footnote{In
12486 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
12487 release.}. If you can use PostScript or Ghostscript with your printer,
12488 you can print the reference card immediately with @file{refcard.ps}.
12489
12490 The release also includes the source for the reference card. You
12491 can format it, using @TeX{}, by typing:
12492
12493 @example
12494 make refcard.dvi
12495 @end example
12496
12497 The @value{GDBN} reference card is designed to print in @dfn{landscape}
12498 mode on US ``letter'' size paper;
12499 that is, on a sheet 11 inches wide by 8.5 inches
12500 high. You will need to specify this form of printing as an option to
12501 your @sc{dvi} output program.
12502
12503 @cindex documentation
12504
12505 All the documentation for @value{GDBN} comes as part of the machine-readable
12506 distribution. The documentation is written in Texinfo format, which is
12507 a documentation system that uses a single source file to produce both
12508 on-line information and a printed manual. You can use one of the Info
12509 formatting commands to create the on-line version of the documentation
12510 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
12511
12512 @value{GDBN} includes an already formatted copy of the on-line Info
12513 version of this manual in the @file{gdb} subdirectory. The main Info
12514 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
12515 subordinate files matching @samp{gdb.info*} in the same directory. If
12516 necessary, you can print out these files, or read them with any editor;
12517 but they are easier to read using the @code{info} subsystem in @sc{gnu}
12518 Emacs or the standalone @code{info} program, available as part of the
12519 @sc{gnu} Texinfo distribution.
12520
12521 If you want to format these Info files yourself, you need one of the
12522 Info formatting programs, such as @code{texinfo-format-buffer} or
12523 @code{makeinfo}.
12524
12525 If you have @code{makeinfo} installed, and are in the top level
12526 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
12527 version @value{GDBVN}), you can make the Info file by typing:
12528
12529 @example
12530 cd gdb
12531 make gdb.info
12532 @end example
12533
12534 If you want to typeset and print copies of this manual, you need @TeX{},
12535 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
12536 Texinfo definitions file.
12537
12538 @TeX{} is a typesetting program; it does not print files directly, but
12539 produces output files called @sc{dvi} files. To print a typeset
12540 document, you need a program to print @sc{dvi} files. If your system
12541 has @TeX{} installed, chances are it has such a program. The precise
12542 command to use depends on your system; @kbd{lpr -d} is common; another
12543 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
12544 require a file name without any extension or a @samp{.dvi} extension.
12545
12546 @TeX{} also requires a macro definitions file called
12547 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
12548 written in Texinfo format. On its own, @TeX{} cannot either read or
12549 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
12550 and is located in the @file{gdb-@var{version-number}/texinfo}
12551 directory.
12552
12553 If you have @TeX{} and a @sc{dvi} printer program installed, you can
12554 typeset and print this manual. First switch to the the @file{gdb}
12555 subdirectory of the main source directory (for example, to
12556 @file{gdb-@value{GDBVN}/gdb}) and type:
12557
12558 @example
12559 make gdb.dvi
12560 @end example
12561
12562 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
12563
12564 @node Installing GDB
12565 @appendix Installing @value{GDBN}
12566 @cindex configuring @value{GDBN}
12567 @cindex installation
12568
12569 @value{GDBN} comes with a @code{configure} script that automates the process
12570 of preparing @value{GDBN} for installation; you can then use @code{make} to
12571 build the @code{gdb} program.
12572 @iftex
12573 @c irrelevant in info file; it's as current as the code it lives with.
12574 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
12575 look at the @file{README} file in the sources; we may have improved the
12576 installation procedures since publishing this manual.}
12577 @end iftex
12578
12579 The @value{GDBN} distribution includes all the source code you need for
12580 @value{GDBN} in a single directory, whose name is usually composed by
12581 appending the version number to @samp{gdb}.
12582
12583 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
12584 @file{gdb-@value{GDBVN}} directory. That directory contains:
12585
12586 @table @code
12587 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
12588 script for configuring @value{GDBN} and all its supporting libraries
12589
12590 @item gdb-@value{GDBVN}/gdb
12591 the source specific to @value{GDBN} itself
12592
12593 @item gdb-@value{GDBVN}/bfd
12594 source for the Binary File Descriptor library
12595
12596 @item gdb-@value{GDBVN}/include
12597 @sc{gnu} include files
12598
12599 @item gdb-@value{GDBVN}/libiberty
12600 source for the @samp{-liberty} free software library
12601
12602 @item gdb-@value{GDBVN}/opcodes
12603 source for the library of opcode tables and disassemblers
12604
12605 @item gdb-@value{GDBVN}/readline
12606 source for the @sc{gnu} command-line interface
12607
12608 @item gdb-@value{GDBVN}/glob
12609 source for the @sc{gnu} filename pattern-matching subroutine
12610
12611 @item gdb-@value{GDBVN}/mmalloc
12612 source for the @sc{gnu} memory-mapped malloc package
12613 @end table
12614
12615 The simplest way to configure and build @value{GDBN} is to run @code{configure}
12616 from the @file{gdb-@var{version-number}} source directory, which in
12617 this example is the @file{gdb-@value{GDBVN}} directory.
12618
12619 First switch to the @file{gdb-@var{version-number}} source directory
12620 if you are not already in it; then run @code{configure}. Pass the
12621 identifier for the platform on which @value{GDBN} will run as an
12622 argument.
12623
12624 For example:
12625
12626 @example
12627 cd gdb-@value{GDBVN}
12628 ./configure @var{host}
12629 make
12630 @end example
12631
12632 @noindent
12633 where @var{host} is an identifier such as @samp{sun4} or
12634 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
12635 (You can often leave off @var{host}; @code{configure} tries to guess the
12636 correct value by examining your system.)
12637
12638 Running @samp{configure @var{host}} and then running @code{make} builds the
12639 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
12640 libraries, then @code{gdb} itself. The configured source files, and the
12641 binaries, are left in the corresponding source directories.
12642
12643 @need 750
12644 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
12645 system does not recognize this automatically when you run a different
12646 shell, you may need to run @code{sh} on it explicitly:
12647
12648 @example
12649 sh configure @var{host}
12650 @end example
12651
12652 If you run @code{configure} from a directory that contains source
12653 directories for multiple libraries or programs, such as the
12654 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
12655 creates configuration files for every directory level underneath (unless
12656 you tell it not to, with the @samp{--norecursion} option).
12657
12658 You can run the @code{configure} script from any of the
12659 subordinate directories in the @value{GDBN} distribution if you only want to
12660 configure that subdirectory, but be sure to specify a path to it.
12661
12662 For example, with version @value{GDBVN}, type the following to configure only
12663 the @code{bfd} subdirectory:
12664
12665 @example
12666 @group
12667 cd gdb-@value{GDBVN}/bfd
12668 ../configure @var{host}
12669 @end group
12670 @end example
12671
12672 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
12673 However, you should make sure that the shell on your path (named by
12674 the @samp{SHELL} environment variable) is publicly readable. Remember
12675 that @value{GDBN} uses the shell to start your program---some systems refuse to
12676 let @value{GDBN} debug child processes whose programs are not readable.
12677
12678 @menu
12679 * Separate Objdir:: Compiling @value{GDBN} in another directory
12680 * Config Names:: Specifying names for hosts and targets
12681 * Configure Options:: Summary of options for configure
12682 @end menu
12683
12684 @node Separate Objdir
12685 @section Compiling @value{GDBN} in another directory
12686
12687 If you want to run @value{GDBN} versions for several host or target machines,
12688 you need a different @code{gdb} compiled for each combination of
12689 host and target. @code{configure} is designed to make this easy by
12690 allowing you to generate each configuration in a separate subdirectory,
12691 rather than in the source directory. If your @code{make} program
12692 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
12693 @code{make} in each of these directories builds the @code{gdb}
12694 program specified there.
12695
12696 To build @code{gdb} in a separate directory, run @code{configure}
12697 with the @samp{--srcdir} option to specify where to find the source.
12698 (You also need to specify a path to find @code{configure}
12699 itself from your working directory. If the path to @code{configure}
12700 would be the same as the argument to @samp{--srcdir}, you can leave out
12701 the @samp{--srcdir} option; it is assumed.)
12702
12703 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
12704 separate directory for a Sun 4 like this:
12705
12706 @example
12707 @group
12708 cd gdb-@value{GDBVN}
12709 mkdir ../gdb-sun4
12710 cd ../gdb-sun4
12711 ../gdb-@value{GDBVN}/configure sun4
12712 make
12713 @end group
12714 @end example
12715
12716 When @code{configure} builds a configuration using a remote source
12717 directory, it creates a tree for the binaries with the same structure
12718 (and using the same names) as the tree under the source directory. In
12719 the example, you'd find the Sun 4 library @file{libiberty.a} in the
12720 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
12721 @file{gdb-sun4/gdb}.
12722
12723 One popular reason to build several @value{GDBN} configurations in separate
12724 directories is to configure @value{GDBN} for cross-compiling (where
12725 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
12726 programs that run on another machine---the @dfn{target}).
12727 You specify a cross-debugging target by
12728 giving the @samp{--target=@var{target}} option to @code{configure}.
12729
12730 When you run @code{make} to build a program or library, you must run
12731 it in a configured directory---whatever directory you were in when you
12732 called @code{configure} (or one of its subdirectories).
12733
12734 The @code{Makefile} that @code{configure} generates in each source
12735 directory also runs recursively. If you type @code{make} in a source
12736 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
12737 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
12738 will build all the required libraries, and then build GDB.
12739
12740 When you have multiple hosts or targets configured in separate
12741 directories, you can run @code{make} on them in parallel (for example,
12742 if they are NFS-mounted on each of the hosts); they will not interfere
12743 with each other.
12744
12745 @node Config Names
12746 @section Specifying names for hosts and targets
12747
12748 The specifications used for hosts and targets in the @code{configure}
12749 script are based on a three-part naming scheme, but some short predefined
12750 aliases are also supported. The full naming scheme encodes three pieces
12751 of information in the following pattern:
12752
12753 @example
12754 @var{architecture}-@var{vendor}-@var{os}
12755 @end example
12756
12757 For example, you can use the alias @code{sun4} as a @var{host} argument,
12758 or as the value for @var{target} in a @code{--target=@var{target}}
12759 option. The equivalent full name is @samp{sparc-sun-sunos4}.
12760
12761 The @code{configure} script accompanying @value{GDBN} does not provide
12762 any query facility to list all supported host and target names or
12763 aliases. @code{configure} calls the Bourne shell script
12764 @code{config.sub} to map abbreviations to full names; you can read the
12765 script, if you wish, or you can use it to test your guesses on
12766 abbreviations---for example:
12767
12768 @smallexample
12769 % sh config.sub i386-linux
12770 i386-pc-linux-gnu
12771 % sh config.sub alpha-linux
12772 alpha-unknown-linux-gnu
12773 % sh config.sub hp9k700
12774 hppa1.1-hp-hpux
12775 % sh config.sub sun4
12776 sparc-sun-sunos4.1.1
12777 % sh config.sub sun3
12778 m68k-sun-sunos4.1.1
12779 % sh config.sub i986v
12780 Invalid configuration `i986v': machine `i986v' not recognized
12781 @end smallexample
12782
12783 @noindent
12784 @code{config.sub} is also distributed in the @value{GDBN} source
12785 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
12786
12787 @node Configure Options
12788 @section @code{configure} options
12789
12790 Here is a summary of the @code{configure} options and arguments that
12791 are most often useful for building @value{GDBN}. @code{configure} also has
12792 several other options not listed here. @inforef{What Configure
12793 Does,,configure.info}, for a full explanation of @code{configure}.
12794
12795 @example
12796 configure @r{[}--help@r{]}
12797 @r{[}--prefix=@var{dir}@r{]}
12798 @r{[}--exec-prefix=@var{dir}@r{]}
12799 @r{[}--srcdir=@var{dirname}@r{]}
12800 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
12801 @r{[}--target=@var{target}@r{]}
12802 @var{host}
12803 @end example
12804
12805 @noindent
12806 You may introduce options with a single @samp{-} rather than
12807 @samp{--} if you prefer; but you may abbreviate option names if you use
12808 @samp{--}.
12809
12810 @table @code
12811 @item --help
12812 Display a quick summary of how to invoke @code{configure}.
12813
12814 @item --prefix=@var{dir}
12815 Configure the source to install programs and files under directory
12816 @file{@var{dir}}.
12817
12818 @item --exec-prefix=@var{dir}
12819 Configure the source to install programs under directory
12820 @file{@var{dir}}.
12821
12822 @c avoid splitting the warning from the explanation:
12823 @need 2000
12824 @item --srcdir=@var{dirname}
12825 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
12826 @code{make} that implements the @code{VPATH} feature.}@*
12827 Use this option to make configurations in directories separate from the
12828 @value{GDBN} source directories. Among other things, you can use this to
12829 build (or maintain) several configurations simultaneously, in separate
12830 directories. @code{configure} writes configuration specific files in
12831 the current directory, but arranges for them to use the source in the
12832 directory @var{dirname}. @code{configure} creates directories under
12833 the working directory in parallel to the source directories below
12834 @var{dirname}.
12835
12836 @item --norecursion
12837 Configure only the directory level where @code{configure} is executed; do not
12838 propagate configuration to subdirectories.
12839
12840 @item --target=@var{target}
12841 Configure @value{GDBN} for cross-debugging programs running on the specified
12842 @var{target}. Without this option, @value{GDBN} is configured to debug
12843 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
12844
12845 There is no convenient way to generate a list of all available targets.
12846
12847 @item @var{host} @dots{}
12848 Configure @value{GDBN} to run on the specified @var{host}.
12849
12850 There is no convenient way to generate a list of all available hosts.
12851 @end table
12852
12853 There are many other options available as well, but they are generally
12854 needed for special purposes only.
12855
12856 @node Index
12857 @unnumbered Index
12858
12859 @printindex cp
12860
12861 @tex
12862 % I think something like @colophon should be in texinfo. In the
12863 % meantime:
12864 \long\def\colophon{\hbox to0pt{}\vfill
12865 \centerline{The body of this manual is set in}
12866 \centerline{\fontname\tenrm,}
12867 \centerline{with headings in {\bf\fontname\tenbf}}
12868 \centerline{and examples in {\tt\fontname\tentt}.}
12869 \centerline{{\it\fontname\tenit\/},}
12870 \centerline{{\bf\fontname\tenbf}, and}
12871 \centerline{{\sl\fontname\tensl\/}}
12872 \centerline{are used for emphasis.}\vfill}
12873 \page\colophon
12874 % Blame: doc@cygnus.com, 1991.
12875 @end tex
12876
12877 @contents
12878 @bye
This page took 0.417425 seconds and 3 git commands to generate.