import gdb-1999-10-04 snapshot
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright 1988-1999
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
25 @syncodeindex vr cp
26
27 @c !!set GDB manual's edition---not the same as GDB version!
28 @set EDITION Seventh
29
30 @c !!set GDB manual's revision date
31 @set DATE February 1999
32
33 @c THIS MANUAL REQUIRES TEXINFO-2 macros and info-makers to format properly.
34
35 @ifinfo
36 @c This is a dir.info fragment to support semi-automated addition of
37 @c manuals to an info tree. zoo@cygnus.com is developing this facility.
38 @format
39 START-INFO-DIR-ENTRY
40 * Gdb: (gdb). The @sc{gnu} debugger.
41 END-INFO-DIR-ENTRY
42 @end format
43 @end ifinfo
44 @c
45 @c
46 @ifinfo
47 This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
50 This is the @value{EDITION} Edition, @value{DATE},
51 of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
52 for @value{GDBN} Version @value{GDBVN}.
53
54 Copyright (C) 1988-1999 Free Software Foundation, Inc.
55
56 Permission is granted to make and distribute verbatim copies of
57 this manual provided the copyright notice and this permission notice
58 are preserved on all copies.
59
60 @ignore
61 Permission is granted to process this file through TeX and print the
62 results, provided the printed document carries copying permission
63 notice identical to this one except for the removal of this paragraph
64 (this paragraph not being relevant to the printed manual).
65
66 @end ignore
67 Permission is granted to copy and distribute modified versions of this
68 manual under the conditions for verbatim copying, provided also that the
69 entire resulting derived work is distributed under the terms of a
70 permission notice identical to this one.
71
72 Permission is granted to copy and distribute translations of this manual
73 into another language, under the above conditions for modified versions.
74 @end ifinfo
75
76 @titlepage
77 @title Debugging with @value{GDBN}
78 @subtitle The @sc{gnu} Source-Level Debugger
79 @sp 1
80 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
81 @subtitle @value{DATE}
82 @author Richard M. Stallman and Roland H. Pesch
83 @page
84 @tex
85 {\parskip=0pt
86 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
87 \hfill {\it Debugging with @value{GDBN}}\par
88 \hfill \TeX{}info \texinfoversion\par
89 }
90 @end tex
91
92 @c ISBN seems to be wrong...
93
94 @vskip 0pt plus 1filll
95 Copyright @copyright{} 1988-1999 Free Software Foundation, Inc.
96 @sp 2
97 Published by the Free Software Foundation @*
98 59 Temple Place - Suite 330, @*
99 Boston, MA 02111-1307 USA @*
100 Printed copies are available for $20 each. @*
101 ISBN 1-882114-11-6 @*
102
103 Permission is granted to make and distribute verbatim copies of
104 this manual provided the copyright notice and this permission notice
105 are preserved on all copies.
106
107 Permission is granted to copy and distribute modified versions of this
108 manual under the conditions for verbatim copying, provided also that the
109 entire resulting derived work is distributed under the terms of a
110 permission notice identical to this one.
111
112 Permission is granted to copy and distribute translations of this manual
113 into another language, under the above conditions for modified versions.
114 @end titlepage
115 @page
116
117 @ifinfo
118 @node Top
119 @top Debugging with @value{GDBN}
120
121 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
122
123 This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
124 @value{GDBVN}.
125
126 Copyright (C) 1988-1999 Free Software Foundation, Inc.
127 @menu
128 * Summary:: Summary of @value{GDBN}
129 * Sample Session:: A sample @value{GDBN} session
130
131 * Invocation:: Getting in and out of @value{GDBN}
132 * Commands:: @value{GDBN} commands
133 * Running:: Running programs under @value{GDBN}
134 * Stopping:: Stopping and continuing
135 * Stack:: Examining the stack
136 * Source:: Examining source files
137 * Data:: Examining data
138
139 * Languages:: Using @value{GDBN} with different languages
140
141 * Symbols:: Examining the symbol table
142 * Altering:: Altering execution
143 * GDB Files:: @value{GDBN} files
144 * Targets:: Specifying a debugging target
145 * Configurations:: Configuration-specific information
146 * Controlling GDB:: Controlling @value{GDBN}
147 * Sequences:: Canned sequences of commands
148 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
149
150 * GDB Bugs:: Reporting bugs in @value{GDBN}
151 * Formatting Documentation:: How to format and print @value{GDBN} documentation
152
153 * Command Line Editing:: Command Line Editing
154 * Using History Interactively:: Using History Interactively
155 * Installing GDB:: Installing GDB
156 * Index:: Index
157 @end menu
158
159 @end ifinfo
160
161 @node Summary
162 @unnumbered Summary of @value{GDBN}
163
164 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
165 going on ``inside'' another program while it executes---or what another
166 program was doing at the moment it crashed.
167
168 @value{GDBN} can do four main kinds of things (plus other things in support of
169 these) to help you catch bugs in the act:
170
171 @itemize @bullet
172 @item
173 Start your program, specifying anything that might affect its behavior.
174
175 @item
176 Make your program stop on specified conditions.
177
178 @item
179 Examine what has happened, when your program has stopped.
180
181 @item
182 Change things in your program, so you can experiment with correcting the
183 effects of one bug and go on to learn about another.
184 @end itemize
185
186 You can use @value{GDBN} to debug programs written in C and C++.
187 For more information, see @ref{Support,,Supported languages}.
188 For more information, see @ref{C,,C and C++}.
189
190 @cindex Chill
191 @cindex Modula-2
192 Support for Modula-2 and Chill is partial. For information on Modula-2,
193 see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
194
195 @cindex Pascal
196 Debugging Pascal programs which use sets, subranges, file variables, or
197 nested functions does not currently work. @value{GDBN} does not support
198 entering expressions, printing values, or similar features using Pascal
199 syntax.
200
201 @cindex Fortran
202 @value{GDBN} can be used to debug programs written in Fortran, although
203 it may be necessary to refer to some variables with a trailing
204 underscore.
205
206 @menu
207 * Free Software:: Freely redistributable software
208 * Contributors:: Contributors to GDB
209 @end menu
210
211 @node Free Software
212 @unnumberedsec Free software
213
214 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
215 General Public License
216 (GPL). The GPL gives you the freedom to copy or adapt a licensed
217 program---but every person getting a copy also gets with it the
218 freedom to modify that copy (which means that they must get access to
219 the source code), and the freedom to distribute further copies.
220 Typical software companies use copyrights to limit your freedoms; the
221 Free Software Foundation uses the GPL to preserve these freedoms.
222
223 Fundamentally, the General Public License is a license which says that
224 you have these freedoms and that you cannot take these freedoms away
225 from anyone else.
226
227 @node Contributors
228 @unnumberedsec Contributors to GDB
229
230 Richard Stallman was the original author of GDB, and of many other
231 @sc{gnu} programs. Many others have contributed to its development.
232 This section attempts to credit major contributors. One of the virtues
233 of free software is that everyone is free to contribute to it; with
234 regret, we cannot actually acknowledge everyone here. The file
235 @file{ChangeLog} in the @value{GDBN} distribution approximates a
236 blow-by-blow account.
237
238 Changes much prior to version 2.0 are lost in the mists of time.
239
240 @quotation
241 @emph{Plea:} Additions to this section are particularly welcome. If you
242 or your friends (or enemies, to be evenhanded) have been unfairly
243 omitted from this list, we would like to add your names!
244 @end quotation
245
246 So that they may not regard their many labors as thankless, we
247 particularly thank those who shepherded @value{GDBN} through major
248 releases:
249 Jim Blandy (release 4.18);
250 Jason Molenda (release 4.17);
251 Stan Shebs (release 4.14);
252 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
253 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
254 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
255 Jim Kingdon (releases 3.5, 3.4, and 3.3);
256 and Randy Smith (releases 3.2, 3.1, and 3.0).
257
258 Richard Stallman, assisted at various times by Peter TerMaat, Chris
259 Hanson, and Richard Mlynarik, handled releases through 2.8.
260
261 Michael Tiemann is the author of most of the @sc{gnu} C++ support in GDB,
262 with significant additional contributions from Per Bothner. James
263 Clark wrote the @sc{gnu} C++ demangler. Early work on C++ was by Peter
264 TerMaat (who also did much general update work leading to release 3.0).
265
266 @value{GDBN} 4 uses the BFD subroutine library to examine multiple
267 object-file formats; BFD was a joint project of David V.
268 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
269
270 David Johnson wrote the original COFF support; Pace Willison did
271 the original support for encapsulated COFF.
272
273 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
274
275 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
276 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
277 support.
278 Jean-Daniel Fekete contributed Sun 386i support.
279 Chris Hanson improved the HP9000 support.
280 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
281 David Johnson contributed Encore Umax support.
282 Jyrki Kuoppala contributed Altos 3068 support.
283 Jeff Law contributed HP PA and SOM support.
284 Keith Packard contributed NS32K support.
285 Doug Rabson contributed Acorn Risc Machine support.
286 Bob Rusk contributed Harris Nighthawk CX-UX support.
287 Chris Smith contributed Convex support (and Fortran debugging).
288 Jonathan Stone contributed Pyramid support.
289 Michael Tiemann contributed SPARC support.
290 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
291 Pace Willison contributed Intel 386 support.
292 Jay Vosburgh contributed Symmetry support.
293
294 Andreas Schwab contributed M68K Linux support.
295
296 Rich Schaefer and Peter Schauer helped with support of SunOS shared
297 libraries.
298
299 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
300 about several machine instruction sets.
301
302 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
303 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
304 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
305 and RDI targets, respectively.
306
307 Brian Fox is the author of the readline libraries providing
308 command-line editing and command history.
309
310 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
311 Modula-2 support, and contributed the Languages chapter of this manual.
312
313 Fred Fish wrote most of the support for Unix System Vr4.
314 He also enhanced the command-completion support to cover C++ overloaded
315 symbols.
316
317 Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
318 Super-H processors.
319
320 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
321
322 Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
323
324 Toshiba sponsored the support for the TX39 Mips processor.
325
326 Matsushita sponsored the support for the MN10200 and MN10300 processors.
327
328 Fujitsu sponsored the support for SPARClite and FR30 processors
329
330 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
331 watchpoints.
332
333 Michael Snyder added support for tracepoints.
334
335 Stu Grossman wrote gdbserver.
336
337 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
338 nearly innumerable bug fixes and cleanups throughout GDB.
339
340 The following people at the Hewlett-Packard Company contributed
341 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
342 (narrow mode), HP's implementation of kernel threads, HP's aC++
343 compiler, and the terminal user interface: Ben Krepp, Richard Title,
344 John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
345 Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
346 information in this manual.
347
348 Cygnus Solutions has sponsored GDB maintenance and much of its
349 development since 1991. Cygnus engineers who have worked on GDB
350 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Edith Epstein,
351 Chris Faylor, Fred Fish, Martin Hunt, Jim Ingham, John Gilmore, Stu
352 Grossman, Kung Hsu, Jim Kingdon, John Metzler, Fernando Nasser, Geoffrey
353 Noer, Dawn Perchik, Rich Pixley, Zdenek Radouch, Keith Seitz, Stan
354 Shebs, David Taylor, and Elena Zannoni. In addition, Dave Brolley, Ian
355 Carmichael, Steve Chamberlain, Nick Clifton, JT Conklin, Stan Cox, DJ
356 Delorie, Ulrich Drepper, Frank Eigler, Doug Evans, Sean Fagan, David
357 Henkel-Wallace, Richard Henderson, Jeff Holcomb, Jeff Law, Jim Lemke,
358 Tom Lord, Bob Manson, Michael Meissner, Jason Merrill, Catherine Moore,
359 Drew Moseley, Ken Raeburn, Gavin Romig-Koch, Rob Savoye, Jamie Smith,
360 Mike Stump, Ian Taylor, Angela Thomas, Michael Tiemann, Tom Tromey, Ron
361 Unrau, Jim Wilson, and David Zuhn have made contributions both large
362 and small.
363
364
365 @node Sample Session
366 @chapter A Sample @value{GDBN} Session
367
368 You can use this manual at your leisure to read all about @value{GDBN}.
369 However, a handful of commands are enough to get started using the
370 debugger. This chapter illustrates those commands.
371
372 @iftex
373 In this sample session, we emphasize user input like this: @b{input},
374 to make it easier to pick out from the surrounding output.
375 @end iftex
376
377 @c FIXME: this example may not be appropriate for some configs, where
378 @c FIXME...primary interest is in remote use.
379
380 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
381 processor) exhibits the following bug: sometimes, when we change its
382 quote strings from the default, the commands used to capture one macro
383 definition within another stop working. In the following short @code{m4}
384 session, we define a macro @code{foo} which expands to @code{0000}; we
385 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
386 same thing. However, when we change the open quote string to
387 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
388 procedure fails to define a new synonym @code{baz}:
389
390 @smallexample
391 $ @b{cd gnu/m4}
392 $ @b{./m4}
393 @b{define(foo,0000)}
394
395 @b{foo}
396 0000
397 @b{define(bar,defn(`foo'))}
398
399 @b{bar}
400 0000
401 @b{changequote(<QUOTE>,<UNQUOTE>)}
402
403 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
404 @b{baz}
405 @b{C-d}
406 m4: End of input: 0: fatal error: EOF in string
407 @end smallexample
408
409 @noindent
410 Let us use @value{GDBN} to try to see what is going on.
411
412 @smallexample
413 $ @b{@value{GDBP} m4}
414 @c FIXME: this falsifies the exact text played out, to permit smallbook
415 @c FIXME... format to come out better.
416 @value{GDBN} is free software and you are welcome to distribute copies
417 of it under certain conditions; type "show copying" to see
418 the conditions.
419 There is absolutely no warranty for @value{GDBN}; type "show warranty"
420 for details.
421
422 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
423 (@value{GDBP})
424 @end smallexample
425
426 @noindent
427 @value{GDBN} reads only enough symbol data to know where to find the
428 rest when needed; as a result, the first prompt comes up very quickly.
429 We now tell @value{GDBN} to use a narrower display width than usual, so
430 that examples fit in this manual.
431
432 @smallexample
433 (@value{GDBP}) @b{set width 70}
434 @end smallexample
435
436 @noindent
437 We need to see how the @code{m4} built-in @code{changequote} works.
438 Having looked at the source, we know the relevant subroutine is
439 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
440 @code{break} command.
441
442 @smallexample
443 (@value{GDBP}) @b{break m4_changequote}
444 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
445 @end smallexample
446
447 @noindent
448 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
449 control; as long as control does not reach the @code{m4_changequote}
450 subroutine, the program runs as usual:
451
452 @smallexample
453 (@value{GDBP}) @b{run}
454 Starting program: /work/Editorial/gdb/gnu/m4/m4
455 @b{define(foo,0000)}
456
457 @b{foo}
458 0000
459 @end smallexample
460
461 @noindent
462 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
463 suspends execution of @code{m4}, displaying information about the
464 context where it stops.
465
466 @smallexample
467 @b{changequote(<QUOTE>,<UNQUOTE>)}
468
469 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
470 at builtin.c:879
471 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
472 @end smallexample
473
474 @noindent
475 Now we use the command @code{n} (@code{next}) to advance execution to
476 the next line of the current function.
477
478 @smallexample
479 (@value{GDBP}) @b{n}
480 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
481 : nil,
482 @end smallexample
483
484 @noindent
485 @code{set_quotes} looks like a promising subroutine. We can go into it
486 by using the command @code{s} (@code{step}) instead of @code{next}.
487 @code{step} goes to the next line to be executed in @emph{any}
488 subroutine, so it steps into @code{set_quotes}.
489
490 @smallexample
491 (@value{GDBP}) @b{s}
492 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
493 at input.c:530
494 530 if (lquote != def_lquote)
495 @end smallexample
496
497 @noindent
498 The display that shows the subroutine where @code{m4} is now
499 suspended (and its arguments) is called a stack frame display. It
500 shows a summary of the stack. We can use the @code{backtrace}
501 command (which can also be spelled @code{bt}), to see where we are
502 in the stack as a whole: the @code{backtrace} command displays a
503 stack frame for each active subroutine.
504
505 @smallexample
506 (@value{GDBP}) @b{bt}
507 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
508 at input.c:530
509 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
510 at builtin.c:882
511 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
512 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
513 at macro.c:71
514 #4 0x79dc in expand_input () at macro.c:40
515 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
516 @end smallexample
517
518 @noindent
519 We step through a few more lines to see what happens. The first two
520 times, we can use @samp{s}; the next two times we use @code{n} to avoid
521 falling into the @code{xstrdup} subroutine.
522
523 @smallexample
524 (@value{GDBP}) @b{s}
525 0x3b5c 532 if (rquote != def_rquote)
526 (@value{GDBP}) @b{s}
527 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
528 def_lquote : xstrdup(lq);
529 (@value{GDBP}) @b{n}
530 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
531 : xstrdup(rq);
532 (@value{GDBP}) @b{n}
533 538 len_lquote = strlen(rquote);
534 @end smallexample
535
536 @noindent
537 The last line displayed looks a little odd; we can examine the variables
538 @code{lquote} and @code{rquote} to see if they are in fact the new left
539 and right quotes we specified. We use the command @code{p}
540 (@code{print}) to see their values.
541
542 @smallexample
543 (@value{GDBP}) @b{p lquote}
544 $1 = 0x35d40 "<QUOTE>"
545 (@value{GDBP}) @b{p rquote}
546 $2 = 0x35d50 "<UNQUOTE>"
547 @end smallexample
548
549 @noindent
550 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
551 To look at some context, we can display ten lines of source
552 surrounding the current line with the @code{l} (@code{list}) command.
553
554 @smallexample
555 (@value{GDBP}) @b{l}
556 533 xfree(rquote);
557 534
558 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
559 : xstrdup (lq);
560 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
561 : xstrdup (rq);
562 537
563 538 len_lquote = strlen(rquote);
564 539 len_rquote = strlen(lquote);
565 540 @}
566 541
567 542 void
568 @end smallexample
569
570 @noindent
571 Let us step past the two lines that set @code{len_lquote} and
572 @code{len_rquote}, and then examine the values of those variables.
573
574 @smallexample
575 (@value{GDBP}) @b{n}
576 539 len_rquote = strlen(lquote);
577 (@value{GDBP}) @b{n}
578 540 @}
579 (@value{GDBP}) @b{p len_lquote}
580 $3 = 9
581 (@value{GDBP}) @b{p len_rquote}
582 $4 = 7
583 @end smallexample
584
585 @noindent
586 That certainly looks wrong, assuming @code{len_lquote} and
587 @code{len_rquote} are meant to be the lengths of @code{lquote} and
588 @code{rquote} respectively. We can set them to better values using
589 the @code{p} command, since it can print the value of
590 any expression---and that expression can include subroutine calls and
591 assignments.
592
593 @smallexample
594 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
595 $5 = 7
596 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
597 $6 = 9
598 @end smallexample
599
600 @noindent
601 Is that enough to fix the problem of using the new quotes with the
602 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
603 executing with the @code{c} (@code{continue}) command, and then try the
604 example that caused trouble initially:
605
606 @smallexample
607 (@value{GDBP}) @b{c}
608 Continuing.
609
610 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
611
612 baz
613 0000
614 @end smallexample
615
616 @noindent
617 Success! The new quotes now work just as well as the default ones. The
618 problem seems to have been just the two typos defining the wrong
619 lengths. We allow @code{m4} exit by giving it an EOF as input:
620
621 @smallexample
622 @b{C-d}
623 Program exited normally.
624 @end smallexample
625
626 @noindent
627 The message @samp{Program exited normally.} is from @value{GDBN}; it
628 indicates @code{m4} has finished executing. We can end our @value{GDBN}
629 session with the @value{GDBN} @code{quit} command.
630
631 @smallexample
632 (@value{GDBP}) @b{quit}
633 @end smallexample
634
635 @node Invocation
636 @chapter Getting In and Out of @value{GDBN}
637
638 This chapter discusses how to start @value{GDBN}, and how to get out of it.
639 The essentials are:
640 @itemize @bullet
641 @item
642 type @samp{@value{GDBP}} to start @value{GDBN}.
643 @item
644 type @kbd{quit} or @kbd{C-d} to exit.
645 @end itemize
646
647 @menu
648 * Invoking GDB:: How to start @value{GDBN}
649 * Quitting GDB:: How to quit @value{GDBN}
650 * Shell Commands:: How to use shell commands inside @value{GDBN}
651 @end menu
652
653 @node Invoking GDB
654 @section Invoking @value{GDBN}
655
656 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
657 @value{GDBN} reads commands from the terminal until you tell it to exit.
658
659 You can also run @code{@value{GDBP}} with a variety of arguments and options,
660 to specify more of your debugging environment at the outset.
661
662 The command-line options described here are designed
663 to cover a variety of situations; in some environments, some of these
664 options may effectively be unavailable.
665
666 The most usual way to start @value{GDBN} is with one argument,
667 specifying an executable program:
668
669 @example
670 @value{GDBP} @var{program}
671 @end example
672
673 @noindent
674 You can also start with both an executable program and a core file
675 specified:
676
677 @example
678 @value{GDBP} @var{program} @var{core}
679 @end example
680
681 You can, instead, specify a process ID as a second argument, if you want
682 to debug a running process:
683
684 @example
685 @value{GDBP} @var{program} 1234
686 @end example
687
688 @noindent
689 would attach @value{GDBN} to process @code{1234} (unless you also have a file
690 named @file{1234}; @value{GDBN} does check for a core file first).
691
692 Taking advantage of the second command-line argument requires a fairly
693 complete operating system; when you use @value{GDBN} as a remote debugger
694 attached to a bare board, there may not be any notion of ``process'',
695 and there is often no way to get a core dump.
696
697 You can run @code{gdb} without printing the front material, which describes
698 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
699
700 @smallexample
701 @value{GDBP} -silent
702 @end smallexample
703
704 @noindent
705 You can further control how @value{GDBN} starts up by using command-line
706 options. @value{GDBN} itself can remind you of the options available.
707
708 @noindent
709 Type
710
711 @example
712 @value{GDBP} -help
713 @end example
714
715 @noindent
716 to display all available options and briefly describe their use
717 (@samp{@value{GDBP} -h} is a shorter equivalent).
718
719 All options and command line arguments you give are processed
720 in sequential order. The order makes a difference when the
721 @samp{-x} option is used.
722
723
724 @menu
725 * File Options:: Choosing files
726 * Mode Options:: Choosing modes
727 @end menu
728
729 @node File Options
730 @subsection Choosing files
731
732 When @value{GDBN} starts
733 specifying an executable file and core file (or process ID). This is
734 the same as if the arguments were specified by the @samp{-se} and
735 @samp{-c} options respectively. (@value{GDBN} reads the first argument
736 that does not have an associated option flag as equivalent to the
737 @samp{-se} option followed by that argument; and the second argument
738 that does not have an associated option flag, if any, as equivalent to
739 the @samp{-c} option followed by that argument.)
740
741 If @value{GDBN} has not been configured to included core file support,
742 such as for most embedded targets, then it will complain about a second
743 argument and ignore it.
744
745 Many options have both long and short forms; both are shown in the
746 following list. @value{GDBN} also recognizes the long forms if you truncate
747 them, so long as enough of the option is present to be unambiguous.
748 (If you prefer, you can flag option arguments with @samp{--} rather
749 than @samp{-}, though we illustrate the more usual convention.)
750
751 @table @code
752 @item -symbols @var{file}
753 @itemx -s @var{file}
754 Read symbol table from file @var{file}.
755
756 @item -exec @var{file}
757 @itemx -e @var{file}
758 Use file @var{file} as the executable file to execute when appropriate,
759 and for examining pure data in conjunction with a core dump.
760
761 @item -se @var{file}
762 Read symbol table from file @var{file} and use it as the executable
763 file.
764
765 @item -core @var{file}
766 @itemx -c @var{file}
767 Use file @var{file} as a core dump to examine.
768
769 @item -c @var{number}
770 Connect to process ID @var{number}, as with the @code{attach} command
771 (unless there is a file in core-dump format named @var{number}, in which
772 case @samp{-c} specifies that file as a core dump to read).
773
774 @item -command @var{file}
775 @itemx -x @var{file}
776 Execute @value{GDBN} commands from file @var{file}. @xref{Command
777 Files,, Command files}.
778
779 @item -directory @var{directory}
780 @itemx -d @var{directory}
781 Add @var{directory} to the path to search for source files.
782
783 @item -m
784 @itemx -mapped
785 @emph{Warning: this option depends on operating system facilities that are not
786 supported on all systems.}@*
787 If memory-mapped files are available on your system through the @code{mmap}
788 system call, you can use this option
789 to have @value{GDBN} write the symbols from your
790 program into a reusable file in the current directory. If the program you are debugging is
791 called @file{/tmp/fred}, the mapped symbol file is @file{./fred.syms}.
792 Future @value{GDBN} debugging sessions notice the presence of this file,
793 and can quickly map in symbol information from it, rather than reading
794 the symbol table from the executable program.
795
796 The @file{.syms} file is specific to the host machine where @value{GDBN}
797 is run. It holds an exact image of the internal @value{GDBN} symbol
798 table. It cannot be shared across multiple host platforms.
799
800 @item -r
801 @itemx -readnow
802 Read each symbol file's entire symbol table immediately, rather than
803 the default, which is to read it incrementally as it is needed.
804 This makes startup slower, but makes future operations faster.
805
806 @end table
807
808 The @code{-mapped} and @code{-readnow} options are typically combined in
809 order to build a @file{.syms} file that contains complete symbol
810 information. (@xref{Files,,Commands to specify files}, for
811 information on @file{.syms} files.) A simple @value{GDBN} invocation to do
812 nothing but build a @file{.syms} file for future use is:
813
814 @example
815 gdb -batch -nx -mapped -readnow programname
816 @end example
817
818 @node Mode Options
819 @subsection Choosing modes
820
821 You can run @value{GDBN} in various alternative modes---for example, in
822 batch mode or quiet mode.
823
824 @table @code
825 @item -nx
826 @itemx -n
827 Do not execute commands from any initialization files (normally called
828 @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally, the commands in
829 these files are executed after all the command options and arguments
830 have been processed. @xref{Command Files,,Command files}.
831
832 @item -quiet
833 @itemx -q
834 ``Quiet''. Do not print the introductory and copyright messages. These
835 messages are also suppressed in batch mode.
836
837 @item -batch
838 Run in batch mode. Exit with status @code{0} after processing all the
839 command files specified with @samp{-x} (and all commands from
840 initialization files, if not inhibited with @samp{-n}). Exit with
841 nonzero status if an error occurs in executing the @value{GDBN} commands
842 in the command files.
843
844 Batch mode may be useful for running @value{GDBN} as a filter, for example to
845 download and run a program on another computer; in order to make this
846 more useful, the message
847
848 @example
849 Program exited normally.
850 @end example
851
852 @noindent
853 (which is ordinarily issued whenever a program running under @value{GDBN} control
854 terminates) is not issued when running in batch mode.
855
856 @item -cd @var{directory}
857 Run @value{GDBN} using @var{directory} as its working directory,
858 instead of the current directory.
859
860 @item -fullname
861 @itemx -f
862 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
863 subprocess. It tells @value{GDBN} to output the full file name and line
864 number in a standard, recognizable fashion each time a stack frame is
865 displayed (which includes each time your program stops). This
866 recognizable format looks like two @samp{\032} characters, followed by
867 the file name, line number and character position separated by colons,
868 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
869 @samp{\032} characters as a signal to display the source code for the
870 frame.
871
872 @item -b @var{bps}
873 Set the line speed (baud rate or bits per second) of any serial
874 interface used by @value{GDBN} for remote debugging.
875
876 @item -tty @var{device}
877 Run using @var{device} for your program's standard input and output.
878 @c FIXME: kingdon thinks there is more to -tty. Investigate.
879
880 @c resolve the situation of these eventually
881 @c @item -tui
882 @c Use a Terminal User Interface. For information, use your Web browser to
883 @c read the file @file{TUI.html}, which is usually installed in the
884 @c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
885 @c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
886 @c @value{GDBN} under @sc{gnu} Emacs}).
887
888 @c @item -xdb
889 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
890 @c For information, see the file @file{xdb_trans.html}, which is usually
891 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
892 @c systems.
893
894 @end table
895
896 @node Quitting GDB
897 @section Quitting @value{GDBN}
898 @cindex exiting @value{GDBN}
899 @cindex leaving @value{GDBN}
900
901 @table @code
902 @kindex quit @r{[}@var{expression}@r{]}
903 @kindex q
904 @item quit
905 To exit @value{GDBN}, use the @code{quit} command (abbreviated @code{q}), or
906 type an end-of-file character (usually @kbd{C-d}). If you do not supply
907 @var{expression}, @value{GDBN} will terminate normally; otherwise it will
908 terminate using the result of @var{expression} as the error code.
909 @end table
910
911 @cindex interrupt
912 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
913 terminates the action of any @value{GDBN} command that is in progress and
914 returns to @value{GDBN} command level. It is safe to type the interrupt
915 character at any time because @value{GDBN} does not allow it to take effect
916 until a time when it is safe.
917
918 If you have been using @value{GDBN} to control an attached process or
919 device, you can release it with the @code{detach} command
920 (@pxref{Attach, ,Debugging an already-running process}).
921
922 @node Shell Commands
923 @section Shell commands
924
925 If you need to execute occasional shell commands during your
926 debugging session, there is no need to leave or suspend @value{GDBN}; you can
927 just use the @code{shell} command.
928
929 @table @code
930 @kindex shell
931 @cindex shell escape
932 @item shell @var{command string}
933 Invoke a standard shell to execute @var{command string}.
934 If it exists, the environment variable @code{SHELL} determines which
935 shell to run. Otherwise @value{GDBN} uses the default shell
936 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
937 @end table
938
939 The utility @code{make} is often needed in development environments.
940 You do not have to use the @code{shell} command for this purpose in
941 @value{GDBN}:
942
943 @table @code
944 @kindex make
945 @cindex calling make
946 @item make @var{make-args}
947 Execute the @code{make} program with the specified
948 arguments. This is equivalent to @samp{shell make @var{make-args}}.
949 @end table
950
951 @node Commands
952 @chapter @value{GDBN} Commands
953
954 You can abbreviate a @value{GDBN} command to the first few letters of the command
955 name, if that abbreviation is unambiguous; and you can repeat certain
956 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
957 key to get @value{GDBN} to fill out the rest of a word in a command (or to
958 show you the alternatives available, if there is more than one possibility).
959
960 @menu
961 * Command Syntax:: How to give commands to @value{GDBN}
962 * Completion:: Command completion
963 * Help:: How to ask @value{GDBN} for help
964 @end menu
965
966 @node Command Syntax
967 @section Command syntax
968
969 A @value{GDBN} command is a single line of input. There is no limit on
970 how long it can be. It starts with a command name, which is followed by
971 arguments whose meaning depends on the command name. For example, the
972 command @code{step} accepts an argument which is the number of times to
973 step, as in @samp{step 5}. You can also use the @code{step} command
974 with no arguments. Some command names do not allow any arguments.
975
976 @cindex abbreviation
977 @value{GDBN} command names may always be truncated if that abbreviation is
978 unambiguous. Other possible command abbreviations are listed in the
979 documentation for individual commands. In some cases, even ambiguous
980 abbreviations are allowed; for example, @code{s} is specially defined as
981 equivalent to @code{step} even though there are other commands whose
982 names start with @code{s}. You can test abbreviations by using them as
983 arguments to the @code{help} command.
984
985 @cindex repeating commands
986 @kindex RET
987 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
988 repeat the previous command. Certain commands (for example, @code{run})
989 will not repeat this way; these are commands whose unintentional
990 repetition might cause trouble and which you are unlikely to want to
991 repeat.
992
993 The @code{list} and @code{x} commands, when you repeat them with
994 @key{RET}, construct new arguments rather than repeating
995 exactly as typed. This permits easy scanning of source or memory.
996
997 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
998 output, in a way similar to the common utility @code{more}
999 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
1000 @key{RET} too many in this situation, @value{GDBN} disables command
1001 repetition after any command that generates this sort of display.
1002
1003 @kindex #
1004 @cindex comment
1005 Any text from a @kbd{#} to the end of the line is a comment; it does
1006 nothing. This is useful mainly in command files (@pxref{Command
1007 Files,,Command files}).
1008
1009 @node Completion
1010 @section Command completion
1011
1012 @cindex completion
1013 @cindex word completion
1014 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1015 only one possibility; it can also show you what the valid possibilities
1016 are for the next word in a command, at any time. This works for @value{GDBN}
1017 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1018
1019 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1020 of a word. If there is only one possibility, @value{GDBN} fills in the
1021 word, and waits for you to finish the command (or press @key{RET} to
1022 enter it). For example, if you type
1023
1024 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1025 @c complete accuracy in these examples; space introduced for clarity.
1026 @c If texinfo enhancements make it unnecessary, it would be nice to
1027 @c replace " @key" by "@key" in the following...
1028 @example
1029 (@value{GDBP}) info bre @key{TAB}
1030 @end example
1031
1032 @noindent
1033 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1034 the only @code{info} subcommand beginning with @samp{bre}:
1035
1036 @example
1037 (@value{GDBP}) info breakpoints
1038 @end example
1039
1040 @noindent
1041 You can either press @key{RET} at this point, to run the @code{info
1042 breakpoints} command, or backspace and enter something else, if
1043 @samp{breakpoints} does not look like the command you expected. (If you
1044 were sure you wanted @code{info breakpoints} in the first place, you
1045 might as well just type @key{RET} immediately after @samp{info bre},
1046 to exploit command abbreviations rather than command completion).
1047
1048 If there is more than one possibility for the next word when you press
1049 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1050 characters and try again, or just press @key{TAB} a second time;
1051 @value{GDBN} displays all the possible completions for that word. For
1052 example, you might want to set a breakpoint on a subroutine whose name
1053 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1054 just sounds the bell. Typing @key{TAB} again displays all the
1055 function names in your program that begin with those characters, for
1056 example:
1057
1058 @example
1059 (@value{GDBP}) b make_ @key{TAB}
1060 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1061 make_a_section_from_file make_environ
1062 make_abs_section make_function_type
1063 make_blockvector make_pointer_type
1064 make_cleanup make_reference_type
1065 make_command make_symbol_completion_list
1066 (@value{GDBP}) b make_
1067 @end example
1068
1069 @noindent
1070 After displaying the available possibilities, @value{GDBN} copies your
1071 partial input (@samp{b make_} in the example) so you can finish the
1072 command.
1073
1074 If you just want to see the list of alternatives in the first place, you
1075 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1076 means @kbd{@key{META} ?}. You can type this either by holding down a
1077 key designated as the @key{META} shift on your keyboard (if there is
1078 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1079
1080 @cindex quotes in commands
1081 @cindex completion of quoted strings
1082 Sometimes the string you need, while logically a ``word'', may contain
1083 parentheses or other characters that @value{GDBN} normally excludes from
1084 its notion of a word. To permit word completion to work in this
1085 situation, you may enclose words in @code{'} (single quote marks) in
1086 @value{GDBN} commands.
1087
1088 The most likely situation where you might need this is in typing the
1089 name of a C++ function. This is because C++ allows function overloading
1090 (multiple definitions of the same function, distinguished by argument
1091 type). For example, when you want to set a breakpoint you may need to
1092 distinguish whether you mean the version of @code{name} that takes an
1093 @code{int} parameter, @code{name(int)}, or the version that takes a
1094 @code{float} parameter, @code{name(float)}. To use the word-completion
1095 facilities in this situation, type a single quote @code{'} at the
1096 beginning of the function name. This alerts @value{GDBN} that it may need to
1097 consider more information than usual when you press @key{TAB} or
1098 @kbd{M-?} to request word completion:
1099
1100 @example
1101 (@value{GDBP}) b 'bubble( @key{M-?}
1102 bubble(double,double) bubble(int,int)
1103 (@value{GDBP}) b 'bubble(
1104 @end example
1105
1106 In some cases, @value{GDBN} can tell that completing a name requires using
1107 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1108 completing as much as it can) if you do not type the quote in the first
1109 place:
1110
1111 @example
1112 (@value{GDBP}) b bub @key{TAB}
1113 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1114 (@value{GDBP}) b 'bubble(
1115 @end example
1116
1117 @noindent
1118 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1119 you have not yet started typing the argument list when you ask for
1120 completion on an overloaded symbol.
1121
1122 For more information about overloaded functions, see @ref{C plus plus
1123 expressions, ,C++ expressions}. You can use the command @code{set
1124 overload-resolution off} to disable overload resolution;
1125 see @ref{Debugging C plus plus, ,@value{GDBN} features for C++}.
1126
1127
1128 @node Help
1129 @section Getting help
1130 @cindex online documentation
1131 @kindex help
1132
1133 You can always ask @value{GDBN} itself for information on its commands,
1134 using the command @code{help}.
1135
1136 @table @code
1137 @kindex h
1138 @item help
1139 @itemx h
1140 You can use @code{help} (abbreviated @code{h}) with no arguments to
1141 display a short list of named classes of commands:
1142
1143 @smallexample
1144 (@value{GDBP}) help
1145 List of classes of commands:
1146
1147 running -- Running the program
1148 stack -- Examining the stack
1149 data -- Examining data
1150 breakpoints -- Making program stop at certain points
1151 files -- Specifying and examining files
1152 status -- Status inquiries
1153 support -- Support facilities
1154 user-defined -- User-defined commands
1155 aliases -- Aliases of other commands
1156 obscure -- Obscure features
1157
1158 Type "help" followed by a class name for a list of
1159 commands in that class.
1160 Type "help" followed by command name for full
1161 documentation.
1162 Command name abbreviations are allowed if unambiguous.
1163 (@value{GDBP})
1164 @end smallexample
1165
1166 @item help @var{class}
1167 Using one of the general help classes as an argument, you can get a
1168 list of the individual commands in that class. For example, here is the
1169 help display for the class @code{status}:
1170
1171 @smallexample
1172 (@value{GDBP}) help status
1173 Status inquiries.
1174
1175 List of commands:
1176
1177 @c Line break in "show" line falsifies real output, but needed
1178 @c to fit in smallbook page size.
1179 show -- Generic command for showing things set
1180 with "set"
1181 info -- Generic command for printing status
1182
1183 Type "help" followed by command name for full
1184 documentation.
1185 Command name abbreviations are allowed if unambiguous.
1186 (@value{GDBP})
1187 @end smallexample
1188
1189 @item help @var{command}
1190 With a command name as @code{help} argument, @value{GDBN} displays a
1191 short paragraph on how to use that command.
1192
1193 @kindex complete
1194 @item complete @var{args}
1195 The @code{complete @var{args}} command lists all the possible completions
1196 for the beginning of a command. Use @var{args} to specify the beginning of the
1197 command you want completed. For example:
1198
1199 @smallexample
1200 complete i
1201 @end smallexample
1202
1203 @noindent results in:
1204
1205 @smallexample
1206 @group
1207 info
1208 inspect
1209 ignore
1210 @end group
1211 @end smallexample
1212
1213 @noindent This is intended for use by @sc{gnu} Emacs.
1214 @end table
1215
1216 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1217 and @code{show} to inquire about the state of your program, or the state
1218 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1219 manual introduces each of them in the appropriate context. The listings
1220 under @code{info} and under @code{show} in the Index point to
1221 all the sub-commands. @xref{Index}.
1222
1223 @c @group
1224 @table @code
1225 @kindex info
1226 @kindex i
1227 @item info
1228 This command (abbreviated @code{i}) is for describing the state of your
1229 program. For example, you can list the arguments given to your program
1230 with @code{info args}, list the registers currently in use with @code{info
1231 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1232 You can get a complete list of the @code{info} sub-commands with
1233 @w{@code{help info}}.
1234
1235 @kindex set
1236 @item set
1237 You can assign the result of an expression to an environment variable with
1238 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1239 @code{set prompt $}.
1240
1241 @kindex show
1242 @item show
1243 In contrast to @code{info}, @code{show} is for describing the state of
1244 @value{GDBN} itself.
1245 You can change most of the things you can @code{show}, by using the
1246 related command @code{set}; for example, you can control what number
1247 system is used for displays with @code{set radix}, or simply inquire
1248 which is currently in use with @code{show radix}.
1249
1250 @kindex info set
1251 To display all the settable parameters and their current
1252 values, you can use @code{show} with no arguments; you may also use
1253 @code{info set}. Both commands produce the same display.
1254 @c FIXME: "info set" violates the rule that "info" is for state of
1255 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1256 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1257 @end table
1258 @c @end group
1259
1260 Here are three miscellaneous @code{show} subcommands, all of which are
1261 exceptional in lacking corresponding @code{set} commands:
1262
1263 @table @code
1264 @kindex show version
1265 @cindex version number
1266 @item show version
1267 Show what version of @value{GDBN} is running. You should include this
1268 information in @value{GDBN} bug-reports. If multiple versions of @value{GDBN} are in
1269 use at your site, you may occasionally want to determine which version
1270 of @value{GDBN} you are running; as @value{GDBN} evolves, new commands are introduced,
1271 and old ones may wither away. The version number is also announced
1272 when you start @value{GDBN}.
1273
1274 @kindex show copying
1275 @item show copying
1276 Display information about permission for copying @value{GDBN}.
1277
1278 @kindex show warranty
1279 @item show warranty
1280 Display the @sc{gnu} ``NO WARRANTY'' statement.
1281 @end table
1282
1283 @node Running
1284 @chapter Running Programs Under @value{GDBN}
1285
1286 When you run a program under @value{GDBN}, you must first generate
1287 debugging information when you compile it.
1288
1289 You may start @value{GDBN} with its arguments, if any, in an environment
1290 of your choice. If you are doing native debugging, you may redirect
1291 your program's input and output, debug an already running process, or
1292 kill a child process.
1293
1294 @menu
1295 * Compilation:: Compiling for debugging
1296 * Starting:: Starting your program
1297 * Arguments:: Your program's arguments
1298 * Environment:: Your program's environment
1299
1300 * Working Directory:: Your program's working directory
1301 * Input/Output:: Your program's input and output
1302 * Attach:: Debugging an already-running process
1303 * Kill Process:: Killing the child process
1304
1305 * Threads:: Debugging programs with multiple threads
1306 * Processes:: Debugging programs with multiple processes
1307 @end menu
1308
1309 @node Compilation
1310 @section Compiling for debugging
1311
1312 In order to debug a program effectively, you need to generate
1313 debugging information when you compile it. This debugging information
1314 is stored in the object file; it describes the data type of each
1315 variable or function and the correspondence between source line numbers
1316 and addresses in the executable code.
1317
1318 To request debugging information, specify the @samp{-g} option when you run
1319 the compiler.
1320
1321 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1322 options together. Using those compilers, you cannot generate optimized
1323 executables containing debugging information.
1324
1325 @value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1326 without @samp{-O}, making it possible to debug optimized code. We
1327 recommend that you @emph{always} use @samp{-g} whenever you compile a
1328 program. You may think your program is correct, but there is no sense
1329 in pushing your luck.
1330
1331 @cindex optimized code, debugging
1332 @cindex debugging optimized code
1333 When you debug a program compiled with @samp{-g -O}, remember that the
1334 optimizer is rearranging your code; the debugger shows you what is
1335 really there. Do not be too surprised when the execution path does not
1336 exactly match your source file! An extreme example: if you define a
1337 variable, but never use it, @value{GDBN} never sees that
1338 variable---because the compiler optimizes it out of existence.
1339
1340 Some things do not work as well with @samp{-g -O} as with just
1341 @samp{-g}, particularly on machines with instruction scheduling. If in
1342 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1343 please report it to us as a bug (including a test case!).
1344
1345 Older versions of the @sc{gnu} C compiler permitted a variant option
1346 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1347 format; if your @sc{gnu} C compiler has this option, do not use it.
1348
1349 @need 2000
1350 @node Starting
1351 @section Starting your program
1352 @cindex starting
1353 @cindex running
1354
1355 @table @code
1356 @kindex run
1357 @item run
1358 @itemx r
1359 Use the @code{run} command to start your program under @value{GDBN}.
1360 You must first specify the program name (except on VxWorks) with an
1361 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1362 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1363 (@pxref{Files, ,Commands to specify files}).
1364
1365 @end table
1366
1367 If you are running your program in an execution environment that
1368 supports processes, @code{run} creates an inferior process and makes
1369 that process run your program. (In environments without processes,
1370 @code{run} jumps to the start of your program.)
1371
1372 The execution of a program is affected by certain information it
1373 receives from its superior. @value{GDBN} provides ways to specify this
1374 information, which you must do @emph{before} starting your program. (You
1375 can change it after starting your program, but such changes only affect
1376 your program the next time you start it.) This information may be
1377 divided into four categories:
1378
1379 @table @asis
1380 @item The @emph{arguments.}
1381 Specify the arguments to give your program as the arguments of the
1382 @code{run} command. If a shell is available on your target, the shell
1383 is used to pass the arguments, so that you may use normal conventions
1384 (such as wildcard expansion or variable substitution) in describing
1385 the arguments.
1386 In Unix systems, you can control which shell is used with the
1387 @code{SHELL} environment variable.
1388 @xref{Arguments, ,Your program's arguments}.
1389
1390 @item The @emph{environment.}
1391 Your program normally inherits its environment from @value{GDBN}, but you can
1392 use the @value{GDBN} commands @code{set environment} and @code{unset
1393 environment} to change parts of the environment that affect
1394 your program. @xref{Environment, ,Your program's environment}.
1395
1396 @item The @emph{working directory.}
1397 Your program inherits its working directory from @value{GDBN}. You can set
1398 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1399 @xref{Working Directory, ,Your program's working directory}.
1400
1401 @item The @emph{standard input and output.}
1402 Your program normally uses the same device for standard input and
1403 standard output as @value{GDBN} is using. You can redirect input and output
1404 in the @code{run} command line, or you can use the @code{tty} command to
1405 set a different device for your program.
1406 @xref{Input/Output, ,Your program's input and output}.
1407
1408 @cindex pipes
1409 @emph{Warning:} While input and output redirection work, you cannot use
1410 pipes to pass the output of the program you are debugging to another
1411 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1412 wrong program.
1413 @end table
1414
1415 When you issue the @code{run} command, your program begins to execute
1416 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1417 of how to arrange for your program to stop. Once your program has
1418 stopped, you may call functions in your program, using the @code{print}
1419 or @code{call} commands. @xref{Data, ,Examining Data}.
1420
1421 If the modification time of your symbol file has changed since the last
1422 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1423 table, and reads it again. When it does this, @value{GDBN} tries to retain
1424 your current breakpoints.
1425
1426 @node Arguments
1427 @section Your program's arguments
1428
1429 @cindex arguments (to your program)
1430 The arguments to your program can be specified by the arguments of the
1431 @code{run} command.
1432 They are passed to a shell, which expands wildcard characters and
1433 performs redirection of I/O, and thence to your program. Your
1434 @code{SHELL} environment variable (if it exists) specifies what shell
1435 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1436 the default shell (@file{/bin/sh} on Unix).
1437
1438 On non-Unix systems, the program is usually invoked directly by
1439 @value{GDBN}, which emulates I/O redirection via the appropriate system
1440 calls, and the wildcard characters are expanded by the startup code of
1441 the program, not by the shell.
1442
1443 @code{run} with no arguments uses the same arguments used by the previous
1444 @code{run}, or those set by the @code{set args} command.
1445
1446 @kindex set args
1447 @table @code
1448 @item set args
1449 Specify the arguments to be used the next time your program is run. If
1450 @code{set args} has no arguments, @code{run} executes your program
1451 with no arguments. Once you have run your program with arguments,
1452 using @code{set args} before the next @code{run} is the only way to run
1453 it again without arguments.
1454
1455 @kindex show args
1456 @item show args
1457 Show the arguments to give your program when it is started.
1458 @end table
1459
1460 @node Environment
1461 @section Your program's environment
1462
1463 @cindex environment (of your program)
1464 The @dfn{environment} consists of a set of environment variables and
1465 their values. Environment variables conventionally record such things as
1466 your user name, your home directory, your terminal type, and your search
1467 path for programs to run. Usually you set up environment variables with
1468 the shell and they are inherited by all the other programs you run. When
1469 debugging, it can be useful to try running your program with a modified
1470 environment without having to start @value{GDBN} over again.
1471
1472 @table @code
1473 @kindex path
1474 @item path @var{directory}
1475 Add @var{directory} to the front of the @code{PATH} environment variable
1476 (the search path for executables), for both @value{GDBN} and your program.
1477 You may specify several directory names, separated by whitespace or by a
1478 system-dependent separator character (@samp{:} on Unix, @samp{;} on
1479 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1480 is moved to the front, so it is searched sooner.
1481
1482 You can use the string @samp{$cwd} to refer to whatever is the current
1483 working directory at the time @value{GDBN} searches the path. If you
1484 use @samp{.} instead, it refers to the directory where you executed the
1485 @code{path} command. @value{GDBN} replaces @samp{.} in the
1486 @var{directory} argument (with the current path) before adding
1487 @var{directory} to the search path.
1488 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1489 @c document that, since repeating it would be a no-op.
1490
1491 @kindex show paths
1492 @item show paths
1493 Display the list of search paths for executables (the @code{PATH}
1494 environment variable).
1495
1496 @kindex show environment
1497 @item show environment @r{[}@var{varname}@r{]}
1498 Print the value of environment variable @var{varname} to be given to
1499 your program when it starts. If you do not supply @var{varname},
1500 print the names and values of all environment variables to be given to
1501 your program. You can abbreviate @code{environment} as @code{env}.
1502
1503 @kindex set environment
1504 @item set environment @var{varname} @r{[}=@var{value}@r{]}
1505 Set environment variable @var{varname} to @var{value}. The value
1506 changes for your program only, not for @value{GDBN} itself. @var{value} may
1507 be any string; the values of environment variables are just strings, and
1508 any interpretation is supplied by your program itself. The @var{value}
1509 parameter is optional; if it is eliminated, the variable is set to a
1510 null value.
1511 @c "any string" here does not include leading, trailing
1512 @c blanks. Gnu asks: does anyone care?
1513
1514 For example, this command:
1515
1516 @example
1517 set env USER = foo
1518 @end example
1519
1520 @noindent
1521 tells the debugged program, when subsequently run, that its user is named
1522 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1523 are not actually required.)
1524
1525 @kindex unset environment
1526 @item unset environment @var{varname}
1527 Remove variable @var{varname} from the environment to be passed to your
1528 program. This is different from @samp{set env @var{varname} =};
1529 @code{unset environment} removes the variable from the environment,
1530 rather than assigning it an empty value.
1531 @end table
1532
1533 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1534 the shell indicated
1535 by your @code{SHELL} environment variable if it exists (or
1536 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1537 that runs an initialization file---such as @file{.cshrc} for C-shell, or
1538 @file{.bashrc} for BASH---any variables you set in that file affect
1539 your program. You may wish to move setting of environment variables to
1540 files that are only run when you sign on, such as @file{.login} or
1541 @file{.profile}.
1542
1543 @node Working Directory
1544 @section Your program's working directory
1545
1546 @cindex working directory (of your program)
1547 Each time you start your program with @code{run}, it inherits its
1548 working directory from the current working directory of @value{GDBN}.
1549 The @value{GDBN} working directory is initially whatever it inherited
1550 from its parent process (typically the shell), but you can specify a new
1551 working directory in @value{GDBN} with the @code{cd} command.
1552
1553 The @value{GDBN} working directory also serves as a default for the commands
1554 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1555 specify files}.
1556
1557 @table @code
1558 @kindex cd
1559 @item cd @var{directory}
1560 Set the @value{GDBN} working directory to @var{directory}.
1561
1562 @kindex pwd
1563 @item pwd
1564 Print the @value{GDBN} working directory.
1565 @end table
1566
1567 @node Input/Output
1568 @section Your program's input and output
1569
1570 @cindex redirection
1571 @cindex i/o
1572 @cindex terminal
1573 By default, the program you run under @value{GDBN} does input and output to
1574 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
1575 to its own terminal modes to interact with you, but it records the terminal
1576 modes your program was using and switches back to them when you continue
1577 running your program.
1578
1579 @table @code
1580 @kindex info terminal
1581 @item info terminal
1582 Displays information recorded by @value{GDBN} about the terminal modes your
1583 program is using.
1584 @end table
1585
1586 You can redirect your program's input and/or output using shell
1587 redirection with the @code{run} command. For example,
1588
1589 @example
1590 run > outfile
1591 @end example
1592
1593 @noindent
1594 starts your program, diverting its output to the file @file{outfile}.
1595
1596 @kindex tty
1597 @cindex controlling terminal
1598 Another way to specify where your program should do input and output is
1599 with the @code{tty} command. This command accepts a file name as
1600 argument, and causes this file to be the default for future @code{run}
1601 commands. It also resets the controlling terminal for the child
1602 process, for future @code{run} commands. For example,
1603
1604 @example
1605 tty /dev/ttyb
1606 @end example
1607
1608 @noindent
1609 directs that processes started with subsequent @code{run} commands
1610 default to do input and output on the terminal @file{/dev/ttyb} and have
1611 that as their controlling terminal.
1612
1613 An explicit redirection in @code{run} overrides the @code{tty} command's
1614 effect on the input/output device, but not its effect on the controlling
1615 terminal.
1616
1617 When you use the @code{tty} command or redirect input in the @code{run}
1618 command, only the input @emph{for your program} is affected. The input
1619 for @value{GDBN} still comes from your terminal.
1620
1621 @node Attach
1622 @section Debugging an already-running process
1623 @kindex attach
1624 @cindex attach
1625
1626 @table @code
1627 @item attach @var{process-id}
1628 This command attaches to a running process---one that was started
1629 outside @value{GDBN}. (@code{info files} shows your active
1630 targets.) The command takes as argument a process ID. The usual way to
1631 find out the process-id of a Unix process is with the @code{ps} utility,
1632 or with the @samp{jobs -l} shell command.
1633
1634 @code{attach} does not repeat if you press @key{RET} a second time after
1635 executing the command.
1636 @end table
1637
1638 To use @code{attach}, your program must be running in an environment
1639 which supports processes; for example, @code{attach} does not work for
1640 programs on bare-board targets that lack an operating system. You must
1641 also have permission to send the process a signal.
1642
1643 When you use @code{attach}, the debugger finds the program running in
1644 the process first by looking in the current working directory, then (if
1645 the program is not found) by using the source file search path
1646 (@pxref{Source Path, ,Specifying source directories}). You can also use
1647 the @code{file} command to load the program. @xref{Files, ,Commands to
1648 Specify Files}.
1649
1650 The first thing @value{GDBN} does after arranging to debug the specified
1651 process is to stop it. You can examine and modify an attached process
1652 with all the @value{GDBN} commands that are ordinarily available when
1653 you start processes with @code{run}. You can insert breakpoints; you
1654 can step and continue; you can modify storage. If you would rather the
1655 process continue running, you may use the @code{continue} command after
1656 attaching @value{GDBN} to the process.
1657
1658 @table @code
1659 @kindex detach
1660 @item detach
1661 When you have finished debugging the attached process, you can use the
1662 @code{detach} command to release it from @value{GDBN} control. Detaching
1663 the process continues its execution. After the @code{detach} command,
1664 that process and @value{GDBN} become completely independent once more, and you
1665 are ready to @code{attach} another process or start one with @code{run}.
1666 @code{detach} does not repeat if you press @key{RET} again after
1667 executing the command.
1668 @end table
1669
1670 If you exit @value{GDBN} or use the @code{run} command while you have an
1671 attached process, you kill that process. By default, @value{GDBN} asks
1672 for confirmation if you try to do either of these things; you can
1673 control whether or not you need to confirm by using the @code{set
1674 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1675 messages}).
1676
1677 @node Kill Process
1678 @section Killing the child process
1679
1680 @table @code
1681 @kindex kill
1682 @item kill
1683 Kill the child process in which your program is running under @value{GDBN}.
1684 @end table
1685
1686 This command is useful if you wish to debug a core dump instead of a
1687 running process. @value{GDBN} ignores any core dump file while your program
1688 is running.
1689
1690 On some operating systems, a program cannot be executed outside @value{GDBN}
1691 while you have breakpoints set on it inside @value{GDBN}. You can use the
1692 @code{kill} command in this situation to permit running your program
1693 outside the debugger.
1694
1695 The @code{kill} command is also useful if you wish to recompile and
1696 relink your program, since on many systems it is impossible to modify an
1697 executable file while it is running in a process. In this case, when you
1698 next type @code{run}, @value{GDBN} notices that the file has changed, and
1699 reads the symbol table again (while trying to preserve your current
1700 breakpoint settings).
1701
1702 @node Threads
1703 @section Debugging programs with multiple threads
1704
1705 @cindex threads of execution
1706 @cindex multiple threads
1707 @cindex switching threads
1708 In some operating systems, such as HP-UX and Solaris, a single program
1709 may have more than one @dfn{thread} of execution. The precise semantics
1710 of threads differ from one operating system to another, but in general
1711 the threads of a single program are akin to multiple processes---except
1712 that they share one address space (that is, they can all examine and
1713 modify the same variables). On the other hand, each thread has its own
1714 registers and execution stack, and perhaps private memory.
1715
1716 @value{GDBN} provides these facilities for debugging multi-thread
1717 programs:
1718
1719 @itemize @bullet
1720 @item automatic notification of new threads
1721 @item @samp{thread @var{threadno}}, a command to switch among threads
1722 @item @samp{info threads}, a command to inquire about existing threads
1723 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
1724 a command to apply a command to a list of threads
1725 @item thread-specific breakpoints
1726 @end itemize
1727
1728 @quotation
1729 @emph{Warning:} These facilities are not yet available on every
1730 @value{GDBN} configuration where the operating system supports threads.
1731 If your @value{GDBN} does not support threads, these commands have no
1732 effect. For example, a system without thread support shows no output
1733 from @samp{info threads}, and always rejects the @code{thread} command,
1734 like this:
1735
1736 @smallexample
1737 (@value{GDBP}) info threads
1738 (@value{GDBP}) thread 1
1739 Thread ID 1 not known. Use the "info threads" command to
1740 see the IDs of currently known threads.
1741 @end smallexample
1742 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
1743 @c doesn't support threads"?
1744 @end quotation
1745
1746 @cindex focus of debugging
1747 @cindex current thread
1748 The @value{GDBN} thread debugging facility allows you to observe all
1749 threads while your program runs---but whenever @value{GDBN} takes
1750 control, one thread in particular is always the focus of debugging.
1751 This thread is called the @dfn{current thread}. Debugging commands show
1752 program information from the perspective of the current thread.
1753
1754 @kindex New @var{systag}
1755 @cindex thread identifier (system)
1756 @c FIXME-implementors!! It would be more helpful if the [New...] message
1757 @c included GDB's numeric thread handle, so you could just go to that
1758 @c thread without first checking `info threads'.
1759 Whenever @value{GDBN} detects a new thread in your program, it displays
1760 the target system's identification for the thread with a message in the
1761 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1762 whose form varies depending on the particular system. For example, on
1763 LynxOS, you might see
1764
1765 @example
1766 [New process 35 thread 27]
1767 @end example
1768
1769 @noindent
1770 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1771 the @var{systag} is simply something like @samp{process 368}, with no
1772 further qualifier.
1773
1774 @c FIXME!! (1) Does the [New...] message appear even for the very first
1775 @c thread of a program, or does it only appear for the
1776 @c second---i.e., when it becomes obvious we have a multithread
1777 @c program?
1778 @c (2) *Is* there necessarily a first thread always? Or do some
1779 @c multithread systems permit starting a program with multiple
1780 @c threads ab initio?
1781
1782 @cindex thread number
1783 @cindex thread identifier (GDB)
1784 For debugging purposes, @value{GDBN} associates its own thread
1785 number---always a single integer---with each thread in your program.
1786
1787 @table @code
1788 @kindex info threads
1789 @item info threads
1790 Display a summary of all threads currently in your
1791 program. @value{GDBN} displays for each thread (in this order):
1792
1793 @enumerate
1794 @item the thread number assigned by @value{GDBN}
1795
1796 @item the target system's thread identifier (@var{systag})
1797
1798 @item the current stack frame summary for that thread
1799 @end enumerate
1800
1801 @noindent
1802 An asterisk @samp{*} to the left of the @value{GDBN} thread number
1803 indicates the current thread.
1804
1805 For example,
1806 @end table
1807 @c end table here to get a little more width for example
1808
1809 @smallexample
1810 (@value{GDBP}) info threads
1811 3 process 35 thread 27 0x34e5 in sigpause ()
1812 2 process 35 thread 23 0x34e5 in sigpause ()
1813 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
1814 at threadtest.c:68
1815 @end smallexample
1816
1817 On HP-UX systems:
1818
1819 @cindex thread number
1820 @cindex thread identifier (GDB)
1821 For debugging purposes, @value{GDBN} associates its own thread
1822 number---a small integer assigned in thread-creation order---with each
1823 thread in your program.
1824
1825 @kindex New @var{systag}
1826 @cindex thread identifier (system)
1827 @c FIXME-implementors!! It would be more helpful if the [New...] message
1828 @c included GDB's numeric thread handle, so you could just go to that
1829 @c thread without first checking `info threads'.
1830 Whenever @value{GDBN} detects a new thread in your program, it displays
1831 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
1832 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1833 whose form varies depending on the particular system. For example, on
1834 HP-UX, you see
1835
1836 @example
1837 [New thread 2 (system thread 26594)]
1838 @end example
1839
1840 @noindent
1841 when @value{GDBN} notices a new thread.
1842
1843 @table @code
1844 @kindex info threads
1845 @item info threads
1846 Display a summary of all threads currently in your
1847 program. @value{GDBN} displays for each thread (in this order):
1848
1849 @enumerate
1850 @item the thread number assigned by @value{GDBN}
1851
1852 @item the target system's thread identifier (@var{systag})
1853
1854 @item the current stack frame summary for that thread
1855 @end enumerate
1856
1857 @noindent
1858 An asterisk @samp{*} to the left of the @value{GDBN} thread number
1859 indicates the current thread.
1860
1861 For example,
1862 @end table
1863 @c end table here to get a little more width for example
1864
1865 @example
1866 (@value{GDBP}) info threads
1867 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") at quicksort.c:137
1868 2 system thread 26606 0x7b0030d8 in __ksleep () from /usr/lib/libc.2
1869 1 system thread 27905 0x7b003498 in _brk () from /usr/lib/libc.2
1870 @end example
1871
1872 @table @code
1873 @kindex thread @var{threadno}
1874 @item thread @var{threadno}
1875 Make thread number @var{threadno} the current thread. The command
1876 argument @var{threadno} is the internal @value{GDBN} thread number, as
1877 shown in the first field of the @samp{info threads} display.
1878 @value{GDBN} responds by displaying the system identifier of the thread
1879 you selected, and its current stack frame summary:
1880
1881 @smallexample
1882 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
1883 (@value{GDBP}) thread 2
1884 [Switching to process 35 thread 23]
1885 0x34e5 in sigpause ()
1886 @end smallexample
1887
1888 @noindent
1889 As with the @samp{[New @dots{}]} message, the form of the text after
1890 @samp{Switching to} depends on your system's conventions for identifying
1891 threads.
1892
1893 @kindex thread apply
1894 @item thread apply [@var{threadno}] [@var{all}] @var{args}
1895 The @code{thread apply} command allows you to apply a command to one or
1896 more threads. Specify the numbers of the threads that you want affected
1897 with the command argument @var{threadno}. @var{threadno} is the internal
1898 @value{GDBN} thread number, as shown in the first field of the @samp{info
1899 threads} display. To apply a command to all threads, use
1900 @code{thread apply all} @var{args}.
1901 @end table
1902
1903 @cindex automatic thread selection
1904 @cindex switching threads automatically
1905 @cindex threads, automatic switching
1906 Whenever @value{GDBN} stops your program, due to a breakpoint or a
1907 signal, it automatically selects the thread where that breakpoint or
1908 signal happened. @value{GDBN} alerts you to the context switch with a
1909 message of the form @samp{[Switching to @var{systag}]} to identify the
1910 thread.
1911
1912 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
1913 more information about how @value{GDBN} behaves when you stop and start
1914 programs with multiple threads.
1915
1916 @xref{Set Watchpoints,,Setting watchpoints}, for information about
1917 watchpoints in programs with multiple threads.
1918
1919 @node Processes
1920 @section Debugging programs with multiple processes
1921
1922 @cindex fork, debugging programs which call
1923 @cindex multiple processes
1924 @cindex processes, multiple
1925 On most systems, @value{GDBN} has no special support for debugging
1926 programs which create additional processes using the @code{fork}
1927 function. When a program forks, @value{GDBN} will continue to debug the
1928 parent process and the child process will run unimpeded. If you have
1929 set a breakpoint in any code which the child then executes, the child
1930 will get a @code{SIGTRAP} signal which (unless it catches the signal)
1931 will cause it to terminate.
1932
1933 However, if you want to debug the child process there is a workaround
1934 which isn't too painful. Put a call to @code{sleep} in the code which
1935 the child process executes after the fork. It may be useful to sleep
1936 only if a certain environment variable is set, or a certain file exists,
1937 so that the delay need not occur when you don't want to run @value{GDBN}
1938 on the child. While the child is sleeping, use the @code{ps} program to
1939 get its process ID. Then tell @value{GDBN} (a new invocation of
1940 @value{GDBN} if you are also debugging the parent process) to attach to
1941 the child process (@pxref{Attach}). From that point on you can debug
1942 the child process just like any other process which you attached to.
1943
1944 On HP-UX (11.x and later only?), @value{GDBN} provides support for
1945 debugging programs that create additional processes using the
1946 @code{fork} or @code{vfork} function.
1947
1948 By default, when a program forks, @value{GDBN} will continue to debug
1949 the parent process and the child process will run unimpeded.
1950
1951 If you want to follow the child process instead of the parent process,
1952 use the command @w{@code{set follow-fork-mode}}.
1953
1954 @table @code
1955 @kindex set follow-fork-mode
1956 @item set follow-fork-mode @var{mode}
1957 Set the debugger response to a program call of @code{fork} or
1958 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
1959 process. The @var{mode} can be:
1960
1961 @table @code
1962 @item parent
1963 The original process is debugged after a fork. The child process runs
1964 unimpeded.
1965
1966 @item child
1967 The new process is debugged after a fork. The parent process runs
1968 unimpeded.
1969
1970 @item ask
1971 The debugger will ask for one of the above choices.
1972 @end table
1973
1974 @item show follow-fork-mode
1975 Display the current debugger response to a fork or vfork call.
1976 @end table
1977
1978 If you ask to debug a child process and a @code{vfork} is followed by an
1979 @code{exec}, @value{GDBN} executes the new target up to the first
1980 breakpoint in the new target. If you have a breakpoint set on
1981 @code{main} in your original program, the breakpoint will also be set on
1982 the child process's @code{main}.
1983
1984 When a child process is spawned by @code{vfork}, you cannot debug the
1985 child or parent until an @code{exec} call completes.
1986
1987 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
1988 call executes, the new target restarts. To restart the parent process,
1989 use the @code{file} command with the parent executable name as its
1990 argument.
1991
1992 You can use the @code{catch} command to make @value{GDBN} stop whenever
1993 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
1994 Catchpoints, ,Setting catchpoints}.
1995
1996 @node Stopping
1997 @chapter Stopping and Continuing
1998
1999 The principal purposes of using a debugger are so that you can stop your
2000 program before it terminates; or so that, if your program runs into
2001 trouble, you can investigate and find out why.
2002
2003 Inside @value{GDBN}, your program may stop for any of several reasons,
2004 such as a signal, a breakpoint, or reaching a new line after a
2005 @value{GDBN} command such as @code{step}. You may then examine and
2006 change variables, set new breakpoints or remove old ones, and then
2007 continue execution. Usually, the messages shown by @value{GDBN} provide
2008 ample explanation of the status of your program---but you can also
2009 explicitly request this information at any time.
2010
2011 @table @code
2012 @kindex info program
2013 @item info program
2014 Display information about the status of your program: whether it is
2015 running or not, what process it is, and why it stopped.
2016 @end table
2017
2018 @menu
2019 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2020 * Continuing and Stepping:: Resuming execution
2021 * Signals:: Signals
2022 * Thread Stops:: Stopping and starting multi-thread programs
2023 @end menu
2024
2025 @node Breakpoints
2026 @section Breakpoints, watchpoints, and catchpoints
2027
2028 @cindex breakpoints
2029 A @dfn{breakpoint} makes your program stop whenever a certain point in
2030 the program is reached. For each breakpoint, you can add conditions to
2031 control in finer detail whether your program stops. You can set
2032 breakpoints with the @code{break} command and its variants (@pxref{Set
2033 Breaks, ,Setting breakpoints}), to specify the place where your program
2034 should stop by line number, function name or exact address in the
2035 program.
2036
2037 In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2038 breakpoints in shared libraries before the executable is run. There is
2039 a minor limitation on HP-UX systems: you must wait until the executable
2040 is run in order to set breakpoints in shared library routines that are
2041 not called directly by the program (for example, routines that are
2042 arguments in a @code{pthread_create} call).
2043
2044 @cindex watchpoints
2045 @cindex memory tracing
2046 @cindex breakpoint on memory address
2047 @cindex breakpoint on variable modification
2048 A @dfn{watchpoint} is a special breakpoint that stops your program
2049 when the value of an expression changes. You must use a different
2050 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2051 watchpoints}), but aside from that, you can manage a watchpoint like
2052 any other breakpoint: you enable, disable, and delete both breakpoints
2053 and watchpoints using the same commands.
2054
2055 You can arrange to have values from your program displayed automatically
2056 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2057 Automatic display}.
2058
2059 @cindex catchpoints
2060 @cindex breakpoint on events
2061 A @dfn{catchpoint} is another special breakpoint that stops your program
2062 when a certain kind of event occurs, such as the throwing of a C++
2063 exception or the loading of a library. As with watchpoints, you use a
2064 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2065 catchpoints}), but aside from that, you can manage a catchpoint like any
2066 other breakpoint. (To stop when your program receives a signal, use the
2067 @code{handle} command; see @ref{Signals, ,Signals}.)
2068
2069 @cindex breakpoint numbers
2070 @cindex numbers for breakpoints
2071 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2072 catchpoint when you create it; these numbers are successive integers
2073 starting with one. In many of the commands for controlling various
2074 features of breakpoints you use the breakpoint number to say which
2075 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2076 @dfn{disabled}; if disabled, it has no effect on your program until you
2077 enable it again.
2078
2079 @menu
2080 * Set Breaks:: Setting breakpoints
2081 * Set Watchpoints:: Setting watchpoints
2082 * Set Catchpoints:: Setting catchpoints
2083 * Delete Breaks:: Deleting breakpoints
2084 * Disabling:: Disabling breakpoints
2085 * Conditions:: Break conditions
2086 * Break Commands:: Breakpoint command lists
2087 * Breakpoint Menus:: Breakpoint menus
2088 * Error in Breakpoints:: ``Cannot insert breakpoints''
2089 @end menu
2090
2091 @node Set Breaks
2092 @subsection Setting breakpoints
2093
2094 @c FIXME LMB what does GDB do if no code on line of breakpt?
2095 @c consider in particular declaration with/without initialization.
2096 @c
2097 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2098
2099 @kindex break
2100 @kindex b
2101 @kindex $bpnum
2102 @cindex latest breakpoint
2103 Breakpoints are set with the @code{break} command (abbreviated
2104 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2105 number of the breakpoints you've set most recently; see @ref{Convenience
2106 Vars,, Convenience variables}, for a discussion of what you can do with
2107 convenience variables.
2108
2109 You have several ways to say where the breakpoint should go.
2110
2111 @table @code
2112 @item break @var{function}
2113 Set a breakpoint at entry to function @var{function}.
2114 When using source languages that permit overloading of symbols, such as
2115 C++, @var{function} may refer to more than one possible place to break.
2116 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2117
2118 @item break +@var{offset}
2119 @itemx break -@var{offset}
2120 Set a breakpoint some number of lines forward or back from the position
2121 at which execution stopped in the currently selected @dfn{stack frame}.
2122 (@xref{Frames, , Frames}, for a description of stack frames.)
2123
2124 @item break @var{linenum}
2125 Set a breakpoint at line @var{linenum} in the current source file.
2126 The current source file is the last file whose source text was printed.
2127 The breakpoint will stop your program just before it executes any of the
2128 code on that line.
2129
2130 @item break @var{filename}:@var{linenum}
2131 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2132
2133 @item break @var{filename}:@var{function}
2134 Set a breakpoint at entry to function @var{function} found in file
2135 @var{filename}. Specifying a file name as well as a function name is
2136 superfluous except when multiple files contain similarly named
2137 functions.
2138
2139 @item break *@var{address}
2140 Set a breakpoint at address @var{address}. You can use this to set
2141 breakpoints in parts of your program which do not have debugging
2142 information or source files.
2143
2144 @item break
2145 When called without any arguments, @code{break} sets a breakpoint at
2146 the next instruction to be executed in the selected stack frame
2147 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2148 innermost, this makes your program stop as soon as control
2149 returns to that frame. This is similar to the effect of a
2150 @code{finish} command in the frame inside the selected frame---except
2151 that @code{finish} does not leave an active breakpoint. If you use
2152 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2153 the next time it reaches the current location; this may be useful
2154 inside loops.
2155
2156 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2157 least one instruction has been executed. If it did not do this, you
2158 would be unable to proceed past a breakpoint without first disabling the
2159 breakpoint. This rule applies whether or not the breakpoint already
2160 existed when your program stopped.
2161
2162 @item break @dots{} if @var{cond}
2163 Set a breakpoint with condition @var{cond}; evaluate the expression
2164 @var{cond} each time the breakpoint is reached, and stop only if the
2165 value is nonzero---that is, if @var{cond} evaluates as true.
2166 @samp{@dots{}} stands for one of the possible arguments described
2167 above (or no argument) specifying where to break. @xref{Conditions,
2168 ,Break conditions}, for more information on breakpoint conditions.
2169
2170 @kindex tbreak
2171 @item tbreak @var{args}
2172 Set a breakpoint enabled only for one stop. @var{args} are the
2173 same as for the @code{break} command, and the breakpoint is set in the same
2174 way, but the breakpoint is automatically deleted after the first time your
2175 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2176
2177 @kindex hbreak
2178 @item hbreak @var{args}
2179 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2180 @code{break} command and the breakpoint is set in the same way, but the
2181 breakpoint requires hardware support and some target hardware may not
2182 have this support. The main purpose of this is EPROM/ROM code
2183 debugging, so you can set a breakpoint at an instruction without
2184 changing the instruction. This can be used with the new trap-generation
2185 provided by SPARClite DSU and some x86-based targets. These targets
2186 will generate traps when a program accesses some data or instruction
2187 address that is assigned to the debug registers. However the hardware
2188 breakpoint registers can take a limited number of breakpoints. For
2189 example, on the DSU, only two data breakpoints can be set at a time, and
2190 @value{GDBN} will reject this command if more than two are used. Delete
2191 or disable unused hardware breakpoints before setting new ones
2192 (@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
2193
2194 @kindex thbreak
2195 @item thbreak @var{args}
2196 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2197 are the same as for the @code{hbreak} command and the breakpoint is set in
2198 the same way. However, like the @code{tbreak} command,
2199 the breakpoint is automatically deleted after the
2200 first time your program stops there. Also, like the @code{hbreak}
2201 command, the breakpoint requires hardware support and some target hardware
2202 may not have this support. @xref{Disabling, ,Disabling breakpoints}.
2203 See also @ref{Conditions, ,Break conditions}.
2204
2205 @kindex rbreak
2206 @cindex regular expression
2207 @item rbreak @var{regex}
2208 @c FIXME what kind of regexp?
2209 Set breakpoints on all functions matching the regular expression
2210 @var{regex}. This command
2211 sets an unconditional breakpoint on all matches, printing a list of all
2212 breakpoints it set. Once these breakpoints are set, they are treated
2213 just like the breakpoints set with the @code{break} command. You can
2214 delete them, disable them, or make them conditional the same way as any
2215 other breakpoint.
2216
2217 When debugging C++ programs, @code{rbreak} is useful for setting
2218 breakpoints on overloaded functions that are not members of any special
2219 classes.
2220
2221 @kindex info breakpoints
2222 @cindex @code{$_} and @code{info breakpoints}
2223 @item info breakpoints @r{[}@var{n}@r{]}
2224 @itemx info break @r{[}@var{n}@r{]}
2225 @itemx info watchpoints @r{[}@var{n}@r{]}
2226 Print a table of all breakpoints, watchpoints, and catchpoints set and
2227 not deleted, with the following columns for each breakpoint:
2228
2229 @table @emph
2230 @item Breakpoint Numbers
2231 @item Type
2232 Breakpoint, watchpoint, or catchpoint.
2233 @item Disposition
2234 Whether the breakpoint is marked to be disabled or deleted when hit.
2235 @item Enabled or Disabled
2236 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2237 that are not enabled.
2238 @item Address
2239 Where the breakpoint is in your program, as a memory address
2240 @item What
2241 Where the breakpoint is in the source for your program, as a file and
2242 line number.
2243 @end table
2244
2245 @noindent
2246 If a breakpoint is conditional, @code{info break} shows the condition on
2247 the line following the affected breakpoint; breakpoint commands, if any,
2248 are listed after that.
2249
2250 @noindent
2251 @code{info break} with a breakpoint
2252 number @var{n} as argument lists only that breakpoint. The
2253 convenience variable @code{$_} and the default examining-address for
2254 the @code{x} command are set to the address of the last breakpoint
2255 listed (@pxref{Memory, ,Examining memory}).
2256
2257 @noindent
2258 @code{info break} displays a count of the number of times the breakpoint
2259 has been hit. This is especially useful in conjunction with the
2260 @code{ignore} command. You can ignore a large number of breakpoint
2261 hits, look at the breakpoint info to see how many times the breakpoint
2262 was hit, and then run again, ignoring one less than that number. This
2263 will get you quickly to the last hit of that breakpoint.
2264 @end table
2265
2266 @value{GDBN} allows you to set any number of breakpoints at the same place in
2267 your program. There is nothing silly or meaningless about this. When
2268 the breakpoints are conditional, this is even useful
2269 (@pxref{Conditions, ,Break conditions}).
2270
2271 @cindex negative breakpoint numbers
2272 @cindex internal @value{GDBN} breakpoints
2273 @value{GDBN} itself sometimes sets breakpoints in your program for special
2274 purposes, such as proper handling of @code{longjmp} (in C programs).
2275 These internal breakpoints are assigned negative numbers, starting with
2276 @code{-1}; @samp{info breakpoints} does not display them.
2277
2278 You can see these breakpoints with the @value{GDBN} maintenance command
2279 @samp{maint info breakpoints}.
2280
2281 @table @code
2282 @kindex maint info breakpoints
2283 @item maint info breakpoints
2284 Using the same format as @samp{info breakpoints}, display both the
2285 breakpoints you've set explicitly, and those @value{GDBN} is using for
2286 internal purposes. Internal breakpoints are shown with negative
2287 breakpoint numbers. The type column identifies what kind of breakpoint
2288 is shown:
2289
2290 @table @code
2291 @item breakpoint
2292 Normal, explicitly set breakpoint.
2293
2294 @item watchpoint
2295 Normal, explicitly set watchpoint.
2296
2297 @item longjmp
2298 Internal breakpoint, used to handle correctly stepping through
2299 @code{longjmp} calls.
2300
2301 @item longjmp resume
2302 Internal breakpoint at the target of a @code{longjmp}.
2303
2304 @item until
2305 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2306
2307 @item finish
2308 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2309
2310 @item shlib events
2311 Shared library events.
2312
2313 @end table
2314
2315 @end table
2316
2317
2318 @node Set Watchpoints
2319 @subsection Setting watchpoints
2320
2321 @cindex setting watchpoints
2322 @cindex software watchpoints
2323 @cindex hardware watchpoints
2324 You can use a watchpoint to stop execution whenever the value of an
2325 expression changes, without having to predict a particular place where
2326 this may happen.
2327
2328 Depending on your system, watchpoints may be implemented in software or
2329 hardware. GDB does software watchpointing by single-stepping your
2330 program and testing the variable's value each time, which is hundreds of
2331 times slower than normal execution. (But this may still be worth it, to
2332 catch errors where you have no clue what part of your program is the
2333 culprit.)
2334
2335 On some systems, such as HP-UX, Linux and some other x86-based targets,
2336 GDB includes support for
2337 hardware watchpoints, which do not slow down the running of your
2338 program.
2339
2340 @table @code
2341 @kindex watch
2342 @item watch @var{expr}
2343 Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2344 is written into by the program and its value changes.
2345
2346 @kindex rwatch
2347 @item rwatch @var{expr}
2348 Set a watchpoint that will break when watch @var{expr} is read by the program.
2349
2350 @kindex awatch
2351 @item awatch @var{expr}
2352 Set a watchpoint that will break when @var{args} is either read or written into
2353 by the program.
2354
2355 @kindex info watchpoints
2356 @item info watchpoints
2357 This command prints a list of watchpoints, breakpoints, and catchpoints;
2358 it is the same as @code{info break}.
2359 @end table
2360
2361 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2362 watchpoints execute very quickly, and the debugger reports a change in
2363 value at the exact instruction where the change occurs. If @value{GDBN}
2364 cannot set a hardware watchpoint, it sets a software watchpoint, which
2365 executes more slowly and reports the change in value at the next
2366 statement, not the instruction, after the change occurs.
2367
2368 When you issue the @code{watch} command, @value{GDBN} reports
2369
2370 @example
2371 Hardware watchpoint @var{num}: @var{expr}
2372 @end example
2373
2374 @noindent
2375 if it was able to set a hardware watchpoint.
2376
2377 Currently, the @code{awatch} and @code{rwatch} commands can only set
2378 hardware watchpoints, because accesses to data that don't change the
2379 value of the watched expression cannot be detected without examining
2380 every instruction as it is being executed, and @value{GDBN} does not do
2381 that currently. If @value{GDBN} finds that it is unable to set a
2382 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2383 will print a message like this:
2384
2385 @smallexample
2386 Expression cannot be implemented with read/access watchpoint.
2387 @end smallexample
2388
2389 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2390 data type of the watched expression is wider than what a hardware
2391 watchpoint on the target machine can handle. For example, some systems
2392 can only watch regions that are up to 4 bytes wide; on such systems you
2393 cannot set hardware watchpoints for an expression that yields a
2394 double-precision floating-point number (which is typically 8 bytes
2395 wide). As a work-around, it might be possible to break the large region
2396 into a series of smaller ones and watch them with separate watchpoints.
2397
2398 If you set too many hardware watchpoints, @value{GDBN} might be unable
2399 to insert all of them when you resume the execution of your program.
2400 Since the precise number of active watchpoints is unknown until such
2401 time as the program is about to be resumed, @value{GDBN} might not be
2402 able to warn you about this when you set the watchpoints, and the
2403 warning will be printed only when the program is resumed:
2404
2405 @smallexample
2406 Hardware watchpoint @var{num}: Could not insert watchpoint
2407 @end smallexample
2408
2409 @noindent
2410 If this happens, delete or disable some of the watchpoints.
2411
2412 The SPARClite DSU will generate traps when a program accesses some data
2413 or instruction address that is assigned to the debug registers. For the
2414 data addresses, DSU facilitates the @code{watch} command. However the
2415 hardware breakpoint registers can only take two data watchpoints, and
2416 both watchpoints must be the same kind. For example, you can set two
2417 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2418 @strong{or} two with @code{awatch} commands, but you cannot set one
2419 watchpoint with one command and the other with a different command.
2420 @value{GDBN} will reject the command if you try to mix watchpoints.
2421 Delete or disable unused watchpoint commands before setting new ones.
2422
2423 If you call a function interactively using @code{print} or @code{call},
2424 any watchpoints you have set will be inactive until GDB reaches another
2425 kind of breakpoint or the call completes.
2426
2427 @value{GDBN} automatically deletes watchpoints that watch local
2428 (automatic) variables, or expressions that involve such variables, when
2429 they go out of scope, that is, when the execution leaves the block in
2430 which these variables were defined. In particular, when the program
2431 being debugged terminates, @emph{all} local variables go out of scope,
2432 and so only watchpoints that watch global variables remain set. If you
2433 rerun the program, you will need to set all such watchpoints again. One
2434 way of doing that would be to set a code breakpoint at the entry to the
2435 @code{main} function and when it breaks, set all the watchpoints.
2436
2437 @quotation
2438 @cindex watchpoints and threads
2439 @cindex threads and watchpoints
2440 @emph{Warning:} In multi-thread programs, watchpoints have only limited
2441 usefulness. With the current watchpoint implementation, @value{GDBN}
2442 can only watch the value of an expression @emph{in a single thread}. If
2443 you are confident that the expression can only change due to the current
2444 thread's activity (and if you are also confident that no other thread
2445 can become current), then you can use watchpoints as usual. However,
2446 @value{GDBN} may not notice when a non-current thread's activity changes
2447 the expression.
2448
2449 @c FIXME: this is almost identical to the previous paragraph.
2450 @emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2451 have only limited usefulness. If @value{GDBN} creates a software
2452 watchpoint, it can only watch the value of an expression @emph{in a
2453 single thread}. If you are confident that the expression can only
2454 change due to the current thread's activity (and if you are also
2455 confident that no other thread can become current), then you can use
2456 software watchpoints as usual. However, @value{GDBN} may not notice
2457 when a non-current thread's activity changes the expression. (Hardware
2458 watchpoints, in contrast, watch an expression in all threads.)
2459 @end quotation
2460
2461 @node Set Catchpoints
2462 @subsection Setting catchpoints
2463 @cindex catchpoints, setting
2464 @cindex exception handlers
2465 @cindex event handling
2466
2467 You can use @dfn{catchpoints} to cause the debugger to stop for certain
2468 kinds of program events, such as C++ exceptions or the loading of a
2469 shared library. Use the @code{catch} command to set a catchpoint.
2470
2471 @table @code
2472 @kindex catch
2473 @item catch @var{event}
2474 Stop when @var{event} occurs. @var{event} can be any of the following:
2475 @table @code
2476 @item throw
2477 @kindex catch throw
2478 The throwing of a C++ exception.
2479
2480 @item catch
2481 @kindex catch catch
2482 The catching of a C++ exception.
2483
2484 @item exec
2485 @kindex catch exec
2486 A call to @code{exec}. This is currently only available for HP-UX.
2487
2488 @item fork
2489 @kindex catch fork
2490 A call to @code{fork}. This is currently only available for HP-UX.
2491
2492 @item vfork
2493 @kindex catch vfork
2494 A call to @code{vfork}. This is currently only available for HP-UX.
2495
2496 @item load
2497 @itemx load @var{libname}
2498 @kindex catch load
2499 The dynamic loading of any shared library, or the loading of the library
2500 @var{libname}. This is currently only available for HP-UX.
2501
2502 @item unload
2503 @itemx unload @var{libname}
2504 @kindex catch unload
2505 The unloading of any dynamically loaded shared library, or the unloading
2506 of the library @var{libname}. This is currently only available for HP-UX.
2507 @end table
2508
2509 @item tcatch @var{event}
2510 Set a catchpoint that is enabled only for one stop. The catchpoint is
2511 automatically deleted after the first time the event is caught.
2512
2513 @end table
2514
2515 Use the @code{info break} command to list the current catchpoints.
2516
2517 There are currently some limitations to C++ exception handling
2518 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2519
2520 @itemize @bullet
2521 @item
2522 If you call a function interactively, @value{GDBN} normally returns
2523 control to you when the function has finished executing. If the call
2524 raises an exception, however, the call may bypass the mechanism that
2525 returns control to you and cause your program either to abort or to
2526 simply continue running until it hits a breakpoint, catches a signal
2527 that @value{GDBN} is listening for, or exits. This is the case even if
2528 you set a catchpoint for the exception; catchpoints on exceptions are
2529 disabled within interactive calls.
2530
2531 @item
2532 You cannot raise an exception interactively.
2533
2534 @item
2535 You cannot install an exception handler interactively.
2536 @end itemize
2537
2538 @cindex raise exceptions
2539 Sometimes @code{catch} is not the best way to debug exception handling:
2540 if you need to know exactly where an exception is raised, it is better to
2541 stop @emph{before} the exception handler is called, since that way you
2542 can see the stack before any unwinding takes place. If you set a
2543 breakpoint in an exception handler instead, it may not be easy to find
2544 out where the exception was raised.
2545
2546 To stop just before an exception handler is called, you need some
2547 knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2548 raised by calling a library function named @code{__raise_exception}
2549 which has the following ANSI C interface:
2550
2551 @example
2552 /* @var{addr} is where the exception identifier is stored.
2553 @var{id} is the exception identifier. */
2554 void __raise_exception (void **addr, void *id);
2555 @end example
2556
2557 @noindent
2558 To make the debugger catch all exceptions before any stack
2559 unwinding takes place, set a breakpoint on @code{__raise_exception}
2560 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2561
2562 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2563 that depends on the value of @var{id}, you can stop your program when
2564 a specific exception is raised. You can use multiple conditional
2565 breakpoints to stop your program when any of a number of exceptions are
2566 raised.
2567
2568
2569 @node Delete Breaks
2570 @subsection Deleting breakpoints
2571
2572 @cindex clearing breakpoints, watchpoints, catchpoints
2573 @cindex deleting breakpoints, watchpoints, catchpoints
2574 It is often necessary to eliminate a breakpoint, watchpoint, or
2575 catchpoint once it has done its job and you no longer want your program
2576 to stop there. This is called @dfn{deleting} the breakpoint. A
2577 breakpoint that has been deleted no longer exists; it is forgotten.
2578
2579 With the @code{clear} command you can delete breakpoints according to
2580 where they are in your program. With the @code{delete} command you can
2581 delete individual breakpoints, watchpoints, or catchpoints by specifying
2582 their breakpoint numbers.
2583
2584 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2585 automatically ignores breakpoints on the first instruction to be executed
2586 when you continue execution without changing the execution address.
2587
2588 @table @code
2589 @kindex clear
2590 @item clear
2591 Delete any breakpoints at the next instruction to be executed in the
2592 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2593 the innermost frame is selected, this is a good way to delete a
2594 breakpoint where your program just stopped.
2595
2596 @item clear @var{function}
2597 @itemx clear @var{filename}:@var{function}
2598 Delete any breakpoints set at entry to the function @var{function}.
2599
2600 @item clear @var{linenum}
2601 @itemx clear @var{filename}:@var{linenum}
2602 Delete any breakpoints set at or within the code of the specified line.
2603
2604 @cindex delete breakpoints
2605 @kindex delete
2606 @kindex d
2607 @item delete @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2608 Delete the breakpoints, watchpoints, or catchpoints of the numbers
2609 specified as arguments. If no argument is specified, delete all
2610 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2611 confirm off}). You can abbreviate this command as @code{d}.
2612 @end table
2613
2614 @node Disabling
2615 @subsection Disabling breakpoints
2616
2617 @kindex disable breakpoints
2618 @kindex enable breakpoints
2619 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2620 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2621 it had been deleted, but remembers the information on the breakpoint so
2622 that you can @dfn{enable} it again later.
2623
2624 You disable and enable breakpoints, watchpoints, and catchpoints with
2625 the @code{enable} and @code{disable} commands, optionally specifying one
2626 or more breakpoint numbers as arguments. Use @code{info break} or
2627 @code{info watch} to print a list of breakpoints, watchpoints, and
2628 catchpoints if you do not know which numbers to use.
2629
2630 A breakpoint, watchpoint, or catchpoint can have any of four different
2631 states of enablement:
2632
2633 @itemize @bullet
2634 @item
2635 Enabled. The breakpoint stops your program. A breakpoint set
2636 with the @code{break} command starts out in this state.
2637 @item
2638 Disabled. The breakpoint has no effect on your program.
2639 @item
2640 Enabled once. The breakpoint stops your program, but then becomes
2641 disabled.
2642 @item
2643 Enabled for deletion. The breakpoint stops your program, but
2644 immediately after it does so it is deleted permanently. A breakpoint
2645 set with the @code{tbreak} command starts out in this state.
2646 @end itemize
2647
2648 You can use the following commands to enable or disable breakpoints,
2649 watchpoints, and catchpoints:
2650
2651 @table @code
2652 @kindex disable breakpoints
2653 @kindex disable
2654 @kindex dis
2655 @item disable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2656 Disable the specified breakpoints---or all breakpoints, if none are
2657 listed. A disabled breakpoint has no effect but is not forgotten. All
2658 options such as ignore-counts, conditions and commands are remembered in
2659 case the breakpoint is enabled again later. You may abbreviate
2660 @code{disable} as @code{dis}.
2661
2662 @kindex enable breakpoints
2663 @kindex enable
2664 @item enable @r{[}breakpoints@r{]} @r{[}@var{bnums}@dots{}@r{]}
2665 Enable the specified breakpoints (or all defined breakpoints). They
2666 become effective once again in stopping your program.
2667
2668 @item enable @r{[}breakpoints@r{]} once @var{bnums}@dots{}
2669 Enable the specified breakpoints temporarily. @value{GDBN} disables any
2670 of these breakpoints immediately after stopping your program.
2671
2672 @item enable @r{[}breakpoints@r{]} delete @var{bnums}@dots{}
2673 Enable the specified breakpoints to work once, then die. @value{GDBN}
2674 deletes any of these breakpoints as soon as your program stops there.
2675 @end table
2676
2677 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2678 @c confusing: tbreak is also initially enabled.
2679 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2680 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2681 subsequently, they become disabled or enabled only when you use one of
2682 the commands above. (The command @code{until} can set and delete a
2683 breakpoint of its own, but it does not change the state of your other
2684 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2685 stepping}.)
2686
2687 @node Conditions
2688 @subsection Break conditions
2689 @cindex conditional breakpoints
2690 @cindex breakpoint conditions
2691
2692 @c FIXME what is scope of break condition expr? Context where wanted?
2693 @c in particular for a watchpoint?
2694 The simplest sort of breakpoint breaks every time your program reaches a
2695 specified place. You can also specify a @dfn{condition} for a
2696 breakpoint. A condition is just a Boolean expression in your
2697 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2698 a condition evaluates the expression each time your program reaches it,
2699 and your program stops only if the condition is @emph{true}.
2700
2701 This is the converse of using assertions for program validation; in that
2702 situation, you want to stop when the assertion is violated---that is,
2703 when the condition is false. In C, if you want to test an assertion expressed
2704 by the condition @var{assert}, you should set the condition
2705 @samp{! @var{assert}} on the appropriate breakpoint.
2706
2707 Conditions are also accepted for watchpoints; you may not need them,
2708 since a watchpoint is inspecting the value of an expression anyhow---but
2709 it might be simpler, say, to just set a watchpoint on a variable name,
2710 and specify a condition that tests whether the new value is an interesting
2711 one.
2712
2713 Break conditions can have side effects, and may even call functions in
2714 your program. This can be useful, for example, to activate functions
2715 that log program progress, or to use your own print functions to
2716 format special data structures. The effects are completely predictable
2717 unless there is another enabled breakpoint at the same address. (In
2718 that case, @value{GDBN} might see the other breakpoint first and stop your
2719 program without checking the condition of this one.) Note that
2720 breakpoint commands are usually more convenient and flexible than break
2721 conditions for the
2722 purpose of performing side effects when a breakpoint is reached
2723 (@pxref{Break Commands, ,Breakpoint command lists}).
2724
2725 Break conditions can be specified when a breakpoint is set, by using
2726 @samp{if} in the arguments to the @code{break} command. @xref{Set
2727 Breaks, ,Setting breakpoints}. They can also be changed at any time
2728 with the @code{condition} command.
2729
2730 You can also use the @code{if} keyword with the @code{watch} command.
2731 The @code{catch} command does not recognize the @code{if} keyword;
2732 @code{condition} is the only way to impose a further condition on a
2733 catchpoint.
2734
2735 @table @code
2736 @kindex condition
2737 @item condition @var{bnum} @var{expression}
2738 Specify @var{expression} as the break condition for breakpoint,
2739 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2740 breakpoint @var{bnum} stops your program only if the value of
2741 @var{expression} is true (nonzero, in C). When you use
2742 @code{condition}, @value{GDBN} checks @var{expression} immediately for
2743 syntactic correctness, and to determine whether symbols in it have
2744 referents in the context of your breakpoint. If @var{expression} uses
2745 symbols not referenced in the context of the breakpoint, @value{GDBN}
2746 prints an error message:
2747
2748 @example
2749 No symbol "foo" in current context.
2750 @end example
2751
2752 @noindent
2753 @value{GDBN} does
2754 not actually evaluate @var{expression} at the time the @code{condition}
2755 command (or a command that sets a breakpoint with a condition, like
2756 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
2757
2758 @item condition @var{bnum}
2759 Remove the condition from breakpoint number @var{bnum}. It becomes
2760 an ordinary unconditional breakpoint.
2761 @end table
2762
2763 @cindex ignore count (of breakpoint)
2764 A special case of a breakpoint condition is to stop only when the
2765 breakpoint has been reached a certain number of times. This is so
2766 useful that there is a special way to do it, using the @dfn{ignore
2767 count} of the breakpoint. Every breakpoint has an ignore count, which
2768 is an integer. Most of the time, the ignore count is zero, and
2769 therefore has no effect. But if your program reaches a breakpoint whose
2770 ignore count is positive, then instead of stopping, it just decrements
2771 the ignore count by one and continues. As a result, if the ignore count
2772 value is @var{n}, the breakpoint does not stop the next @var{n} times
2773 your program reaches it.
2774
2775 @table @code
2776 @kindex ignore
2777 @item ignore @var{bnum} @var{count}
2778 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2779 The next @var{count} times the breakpoint is reached, your program's
2780 execution does not stop; other than to decrement the ignore count, @value{GDBN}
2781 takes no action.
2782
2783 To make the breakpoint stop the next time it is reached, specify
2784 a count of zero.
2785
2786 When you use @code{continue} to resume execution of your program from a
2787 breakpoint, you can specify an ignore count directly as an argument to
2788 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
2789 Stepping,,Continuing and stepping}.
2790
2791 If a breakpoint has a positive ignore count and a condition, the
2792 condition is not checked. Once the ignore count reaches zero,
2793 @value{GDBN} resumes checking the condition.
2794
2795 You could achieve the effect of the ignore count with a condition such
2796 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
2797 is decremented each time. @xref{Convenience Vars, ,Convenience
2798 variables}.
2799 @end table
2800
2801 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
2802
2803
2804 @node Break Commands
2805 @subsection Breakpoint command lists
2806
2807 @cindex breakpoint commands
2808 You can give any breakpoint (or watchpoint or catchpoint) a series of
2809 commands to execute when your program stops due to that breakpoint. For
2810 example, you might want to print the values of certain expressions, or
2811 enable other breakpoints.
2812
2813 @table @code
2814 @kindex commands
2815 @kindex end
2816 @item commands @r{[}@var{bnum}@r{]}
2817 @itemx @dots{} @var{command-list} @dots{}
2818 @itemx end
2819 Specify a list of commands for breakpoint number @var{bnum}. The commands
2820 themselves appear on the following lines. Type a line containing just
2821 @code{end} to terminate the commands.
2822
2823 To remove all commands from a breakpoint, type @code{commands} and
2824 follow it immediately with @code{end}; that is, give no commands.
2825
2826 With no @var{bnum} argument, @code{commands} refers to the last
2827 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
2828 recently encountered).
2829 @end table
2830
2831 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
2832 disabled within a @var{command-list}.
2833
2834 You can use breakpoint commands to start your program up again. Simply
2835 use the @code{continue} command, or @code{step}, or any other command
2836 that resumes execution.
2837
2838 Any other commands in the command list, after a command that resumes
2839 execution, are ignored. This is because any time you resume execution
2840 (even with a simple @code{next} or @code{step}), you may encounter
2841 another breakpoint---which could have its own command list, leading to
2842 ambiguities about which list to execute.
2843
2844 @kindex silent
2845 If the first command you specify in a command list is @code{silent}, the
2846 usual message about stopping at a breakpoint is not printed. This may
2847 be desirable for breakpoints that are to print a specific message and
2848 then continue. If none of the remaining commands print anything, you
2849 see no sign that the breakpoint was reached. @code{silent} is
2850 meaningful only at the beginning of a breakpoint command list.
2851
2852 The commands @code{echo}, @code{output}, and @code{printf} allow you to
2853 print precisely controlled output, and are often useful in silent
2854 breakpoints. @xref{Output, ,Commands for controlled output}.
2855
2856 For example, here is how you could use breakpoint commands to print the
2857 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
2858
2859 @example
2860 break foo if x>0
2861 commands
2862 silent
2863 printf "x is %d\n",x
2864 cont
2865 end
2866 @end example
2867
2868 One application for breakpoint commands is to compensate for one bug so
2869 you can test for another. Put a breakpoint just after the erroneous line
2870 of code, give it a condition to detect the case in which something
2871 erroneous has been done, and give it commands to assign correct values
2872 to any variables that need them. End with the @code{continue} command
2873 so that your program does not stop, and start with the @code{silent}
2874 command so that no output is produced. Here is an example:
2875
2876 @example
2877 break 403
2878 commands
2879 silent
2880 set x = y + 4
2881 cont
2882 end
2883 @end example
2884
2885 @node Breakpoint Menus
2886 @subsection Breakpoint menus
2887 @cindex overloading
2888 @cindex symbol overloading
2889
2890 Some programming languages (notably C++) permit a single function name
2891 to be defined several times, for application in different contexts.
2892 This is called @dfn{overloading}. When a function name is overloaded,
2893 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
2894 a breakpoint. If you realize this is a problem, you can use
2895 something like @samp{break @var{function}(@var{types})} to specify which
2896 particular version of the function you want. Otherwise, @value{GDBN} offers
2897 you a menu of numbered choices for different possible breakpoints, and
2898 waits for your selection with the prompt @samp{>}. The first two
2899 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
2900 sets a breakpoint at each definition of @var{function}, and typing
2901 @kbd{0} aborts the @code{break} command without setting any new
2902 breakpoints.
2903
2904 For example, the following session excerpt shows an attempt to set a
2905 breakpoint at the overloaded symbol @code{String::after}.
2906 We choose three particular definitions of that function name:
2907
2908 @c FIXME! This is likely to change to show arg type lists, at least
2909 @smallexample
2910 @group
2911 (@value{GDBP}) b String::after
2912 [0] cancel
2913 [1] all
2914 [2] file:String.cc; line number:867
2915 [3] file:String.cc; line number:860
2916 [4] file:String.cc; line number:875
2917 [5] file:String.cc; line number:853
2918 [6] file:String.cc; line number:846
2919 [7] file:String.cc; line number:735
2920 > 2 4 6
2921 Breakpoint 1 at 0xb26c: file String.cc, line 867.
2922 Breakpoint 2 at 0xb344: file String.cc, line 875.
2923 Breakpoint 3 at 0xafcc: file String.cc, line 846.
2924 Multiple breakpoints were set.
2925 Use the "delete" command to delete unwanted
2926 breakpoints.
2927 (@value{GDBP})
2928 @end group
2929 @end smallexample
2930
2931 @c @ifclear BARETARGET
2932 @node Error in Breakpoints
2933 @subsection ``Cannot insert breakpoints''
2934 @c
2935 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
2936 @c
2937 Under some operating systems, breakpoints cannot be used in a program if
2938 any other process is running that program. In this situation,
2939 attempting to run or continue a program with a breakpoint causes
2940 @value{GDBN} to print an error message:
2941
2942 @example
2943 Cannot insert breakpoints.
2944 The same program may be running in another process.
2945 @end example
2946
2947 When this happens, you have three ways to proceed:
2948
2949 @enumerate
2950 @item
2951 Remove or disable the breakpoints, then continue.
2952
2953 @item
2954 Suspend @value{GDBN}, and copy the file containing your program to a new
2955 name. Resume @value{GDBN} and use the @code{exec-file} command to specify
2956 that @value{GDBN} should run your program under that name.
2957 Then start your program again.
2958
2959 @item
2960 Relink your program so that the text segment is nonsharable, using the
2961 linker option @samp{-N}. The operating system limitation may not apply
2962 to nonsharable executables.
2963 @end enumerate
2964 @c @end ifclear
2965
2966 A similar message can be printed if you request too many active
2967 hardware-assisted breakpoints and watchpoints:
2968
2969 @c FIXME: the precise wording of this message may change; the relevant
2970 @c source change is not committed yet (Sep 3, 1999).
2971 @smallexample
2972 Stopped; cannot insert breakpoints.
2973 You may have requested too many hardware breakpoints and watchpoints.
2974 @end smallexample
2975
2976 @noindent
2977 This message is printed when you attempt to resume the program, since
2978 only then @value{GDBN} knows exactly how many hardware breakpoints and
2979 watchpoints it needs to insert.
2980
2981 When this message is printed, you need to disable or remove some of the
2982 hardware-assisted breakpoints and watchpoints, and then continue.
2983
2984
2985 @node Continuing and Stepping
2986 @section Continuing and stepping
2987
2988 @cindex stepping
2989 @cindex continuing
2990 @cindex resuming execution
2991 @dfn{Continuing} means resuming program execution until your program
2992 completes normally. In contrast, @dfn{stepping} means executing just
2993 one more ``step'' of your program, where ``step'' may mean either one
2994 line of source code, or one machine instruction (depending on what
2995 particular command you use). Either when continuing or when stepping,
2996 your program may stop even sooner, due to a breakpoint or a signal. (If
2997 it stops due to a signal, you may want to use @code{handle}, or use
2998 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
2999
3000 @table @code
3001 @kindex continue
3002 @kindex c
3003 @kindex fg
3004 @item continue @r{[}@var{ignore-count}@r{]}
3005 @itemx c @r{[}@var{ignore-count}@r{]}
3006 @itemx fg @r{[}@var{ignore-count}@r{]}
3007 Resume program execution, at the address where your program last stopped;
3008 any breakpoints set at that address are bypassed. The optional argument
3009 @var{ignore-count} allows you to specify a further number of times to
3010 ignore a breakpoint at this location; its effect is like that of
3011 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3012
3013 The argument @var{ignore-count} is meaningful only when your program
3014 stopped due to a breakpoint. At other times, the argument to
3015 @code{continue} is ignored.
3016
3017 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3018 debugged program is deemed to be the foreground program) are provided
3019 purely for convenience, and have exactly the same behavior as
3020 @code{continue}.
3021 @end table
3022
3023 To resume execution at a different place, you can use @code{return}
3024 (@pxref{Returning, ,Returning from a function}) to go back to the
3025 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3026 different address}) to go to an arbitrary location in your program.
3027
3028 A typical technique for using stepping is to set a breakpoint
3029 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3030 beginning of the function or the section of your program where a problem
3031 is believed to lie, run your program until it stops at that breakpoint,
3032 and then step through the suspect area, examining the variables that are
3033 interesting, until you see the problem happen.
3034
3035 @table @code
3036 @kindex step
3037 @kindex s
3038 @item step
3039 Continue running your program until control reaches a different source
3040 line, then stop it and return control to @value{GDBN}. This command is
3041 abbreviated @code{s}.
3042
3043 @quotation
3044 @c "without debugging information" is imprecise; actually "without line
3045 @c numbers in the debugging information". (gcc -g1 has debugging info but
3046 @c not line numbers). But it seems complex to try to make that
3047 @c distinction here.
3048 @emph{Warning:} If you use the @code{step} command while control is
3049 within a function that was compiled without debugging information,
3050 execution proceeds until control reaches a function that does have
3051 debugging information. Likewise, it will not step into a function which
3052 is compiled without debugging information. To step through functions
3053 without debugging information, use the @code{stepi} command, described
3054 below.
3055 @end quotation
3056
3057 The @code{step} command only stops at the first instruction of a
3058 source line. This prevents the multiple stops that could otherwise occur in
3059 switch statements, for loops, etc. @code{step} continues to stop if a
3060 function that has debugging information is called within the line.
3061 In other words, @code{step} @emph{steps inside} any functions called
3062 within the line.
3063
3064 Also, the @code{step} command only enters a function if there is line
3065 number information for the function. Otherwise it acts like the
3066 @code{next} command. This avoids problems when using @code{cc -gl}
3067 on MIPS machines. Previously, @code{step} entered subroutines if there
3068 was any debugging information about the routine.
3069
3070 @item step @var{count}
3071 Continue running as in @code{step}, but do so @var{count} times. If a
3072 breakpoint is reached, or a signal not related to stepping occurs before
3073 @var{count} steps, stepping stops right away.
3074
3075 @kindex next
3076 @kindex n
3077 @item next @r{[}@var{count}@r{]}
3078 Continue to the next source line in the current (innermost) stack frame.
3079 This is similar to @code{step}, but function calls that appear within
3080 the line of code are executed without stopping. Execution stops when
3081 control reaches a different line of code at the original stack level
3082 that was executing when you gave the @code{next} command. This command
3083 is abbreviated @code{n}.
3084
3085 An argument @var{count} is a repeat count, as for @code{step}.
3086
3087
3088 @c FIX ME!! Do we delete this, or is there a way it fits in with
3089 @c the following paragraph? --- Vctoria
3090 @c
3091 @c @code{next} within a function that lacks debugging information acts like
3092 @c @code{step}, but any function calls appearing within the code of the
3093 @c function are executed without stopping.
3094
3095 The @code{next} command only stops at the first instruction of a
3096 source line. This prevents multiple stops that could otherwise occur in
3097 switch statements, for loops, etc.
3098
3099 @kindex finish
3100 @item finish
3101 Continue running until just after function in the selected stack frame
3102 returns. Print the returned value (if any).
3103
3104 Contrast this with the @code{return} command (@pxref{Returning,
3105 ,Returning from a function}).
3106
3107 @kindex until
3108 @kindex u
3109 @item until
3110 @itemx u
3111 Continue running until a source line past the current line, in the
3112 current stack frame, is reached. This command is used to avoid single
3113 stepping through a loop more than once. It is like the @code{next}
3114 command, except that when @code{until} encounters a jump, it
3115 automatically continues execution until the program counter is greater
3116 than the address of the jump.
3117
3118 This means that when you reach the end of a loop after single stepping
3119 though it, @code{until} makes your program continue execution until it
3120 exits the loop. In contrast, a @code{next} command at the end of a loop
3121 simply steps back to the beginning of the loop, which forces you to step
3122 through the next iteration.
3123
3124 @code{until} always stops your program if it attempts to exit the current
3125 stack frame.
3126
3127 @code{until} may produce somewhat counterintuitive results if the order
3128 of machine code does not match the order of the source lines. For
3129 example, in the following excerpt from a debugging session, the @code{f}
3130 (@code{frame}) command shows that execution is stopped at line
3131 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3132
3133 @example
3134 (@value{GDBP}) f
3135 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3136 206 expand_input();
3137 (@value{GDBP}) until
3138 195 for ( ; argc > 0; NEXTARG) @{
3139 @end example
3140
3141 This happened because, for execution efficiency, the compiler had
3142 generated code for the loop closure test at the end, rather than the
3143 start, of the loop---even though the test in a C @code{for}-loop is
3144 written before the body of the loop. The @code{until} command appeared
3145 to step back to the beginning of the loop when it advanced to this
3146 expression; however, it has not really gone to an earlier
3147 statement---not in terms of the actual machine code.
3148
3149 @code{until} with no argument works by means of single
3150 instruction stepping, and hence is slower than @code{until} with an
3151 argument.
3152
3153 @item until @var{location}
3154 @itemx u @var{location}
3155 Continue running your program until either the specified location is
3156 reached, or the current stack frame returns. @var{location} is any of
3157 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3158 ,Setting breakpoints}). This form of the command uses breakpoints,
3159 and hence is quicker than @code{until} without an argument.
3160
3161 @kindex stepi
3162 @kindex si
3163 @item stepi
3164 @itemx si
3165 Execute one machine instruction, then stop and return to the debugger.
3166
3167 It is often useful to do @samp{display/i $pc} when stepping by machine
3168 instructions. This makes @value{GDBN} automatically display the next
3169 instruction to be executed, each time your program stops. @xref{Auto
3170 Display,, Automatic display}.
3171
3172 An argument is a repeat count, as in @code{step}.
3173
3174 @need 750
3175 @kindex nexti
3176 @kindex ni
3177 @item nexti
3178 @itemx ni
3179 Execute one machine instruction, but if it is a function call,
3180 proceed until the function returns.
3181
3182 An argument is a repeat count, as in @code{next}.
3183 @end table
3184
3185 @node Signals
3186 @section Signals
3187 @cindex signals
3188
3189 A signal is an asynchronous event that can happen in a program. The
3190 operating system defines the possible kinds of signals, and gives each
3191 kind a name and a number. For example, in Unix @code{SIGINT} is the
3192 signal a program gets when you type an interrupt character (often @kbd{C-c});
3193 @code{SIGSEGV} is the signal a program gets from referencing a place in
3194 memory far away from all the areas in use; @code{SIGALRM} occurs when
3195 the alarm clock timer goes off (which happens only if your program has
3196 requested an alarm).
3197
3198 @cindex fatal signals
3199 Some signals, including @code{SIGALRM}, are a normal part of the
3200 functioning of your program. Others, such as @code{SIGSEGV}, indicate
3201 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
3202 program has not specified in advance some other way to handle the signal.
3203 @code{SIGINT} does not indicate an error in your program, but it is normally
3204 fatal so it can carry out the purpose of the interrupt: to kill the program.
3205
3206 @value{GDBN} has the ability to detect any occurrence of a signal in your
3207 program. You can tell @value{GDBN} in advance what to do for each kind of
3208 signal.
3209
3210 @cindex handling signals
3211 Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3212 (so as not to interfere with their role in the functioning of your program)
3213 but to stop your program immediately whenever an error signal happens.
3214 You can change these settings with the @code{handle} command.
3215
3216 @table @code
3217 @kindex info signals
3218 @item info signals
3219 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3220 handle each one. You can use this to see the signal numbers of all
3221 the defined types of signals.
3222
3223 @code{info handle} is an alias for @code{info signals}.
3224
3225 @kindex handle
3226 @item handle @var{signal} @var{keywords}@dots{}
3227 Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
3228 be the number of a signal or its name (with or without the @samp{SIG} at the
3229 beginning). The @var{keywords} say what change to make.
3230 @end table
3231
3232 @c @group
3233 The keywords allowed by the @code{handle} command can be abbreviated.
3234 Their full names are:
3235
3236 @table @code
3237 @item nostop
3238 @value{GDBN} should not stop your program when this signal happens. It may
3239 still print a message telling you that the signal has come in.
3240
3241 @item stop
3242 @value{GDBN} should stop your program when this signal happens. This implies
3243 the @code{print} keyword as well.
3244
3245 @item print
3246 @value{GDBN} should print a message when this signal happens.
3247
3248 @item noprint
3249 @value{GDBN} should not mention the occurrence of the signal at all. This
3250 implies the @code{nostop} keyword as well.
3251
3252 @item pass
3253 @value{GDBN} should allow your program to see this signal; your program
3254 can handle the signal, or else it may terminate if the signal is fatal
3255 and not handled.
3256
3257 @item nopass
3258 @value{GDBN} should not allow your program to see this signal.
3259 @end table
3260 @c @end group
3261
3262 When a signal stops your program, the signal is not visible to the
3263 program until you
3264 continue. Your program sees the signal then, if @code{pass} is in
3265 effect for the signal in question @emph{at that time}. In other words,
3266 after @value{GDBN} reports a signal, you can use the @code{handle}
3267 command with @code{pass} or @code{nopass} to control whether your
3268 program sees that signal when you continue.
3269
3270 You can also use the @code{signal} command to prevent your program from
3271 seeing a signal, or cause it to see a signal it normally would not see,
3272 or to give it any signal at any time. For example, if your program stopped
3273 due to some sort of memory reference error, you might store correct
3274 values into the erroneous variables and continue, hoping to see more
3275 execution; but your program would probably terminate immediately as
3276 a result of the fatal signal once it saw the signal. To prevent this,
3277 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3278 program a signal}.
3279
3280 @node Thread Stops
3281 @section Stopping and starting multi-thread programs
3282
3283 When your program has multiple threads (@pxref{Threads,, Debugging
3284 programs with multiple threads}), you can choose whether to set
3285 breakpoints on all threads, or on a particular thread.
3286
3287 @table @code
3288 @cindex breakpoints and threads
3289 @cindex thread breakpoints
3290 @kindex break @dots{} thread @var{threadno}
3291 @item break @var{linespec} thread @var{threadno}
3292 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3293 @var{linespec} specifies source lines; there are several ways of
3294 writing them, but the effect is always to specify some source line.
3295
3296 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3297 to specify that you only want @value{GDBN} to stop the program when a
3298 particular thread reaches this breakpoint. @var{threadno} is one of the
3299 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3300 column of the @samp{info threads} display.
3301
3302 If you do not specify @samp{thread @var{threadno}} when you set a
3303 breakpoint, the breakpoint applies to @emph{all} threads of your
3304 program.
3305
3306 You can use the @code{thread} qualifier on conditional breakpoints as
3307 well; in this case, place @samp{thread @var{threadno}} before the
3308 breakpoint condition, like this:
3309
3310 @smallexample
3311 (gdb) break frik.c:13 thread 28 if bartab > lim
3312 @end smallexample
3313
3314 @end table
3315
3316 @cindex stopped threads
3317 @cindex threads, stopped
3318 Whenever your program stops under @value{GDBN} for any reason,
3319 @emph{all} threads of execution stop, not just the current thread. This
3320 allows you to examine the overall state of the program, including
3321 switching between threads, without worrying that things may change
3322 underfoot.
3323
3324 @cindex continuing threads
3325 @cindex threads, continuing
3326 Conversely, whenever you restart the program, @emph{all} threads start
3327 executing. @emph{This is true even when single-stepping} with commands
3328 like @code{step} or @code{next}.
3329
3330 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3331 Since thread scheduling is up to your debugging target's operating
3332 system (not controlled by @value{GDBN}), other threads may
3333 execute more than one statement while the current thread completes a
3334 single step. Moreover, in general other threads stop in the middle of a
3335 statement, rather than at a clean statement boundary, when the program
3336 stops.
3337
3338 You might even find your program stopped in another thread after
3339 continuing or even single-stepping. This happens whenever some other
3340 thread runs into a breakpoint, a signal, or an exception before the
3341 first thread completes whatever you requested.
3342
3343 On some OSes, you can lock the OS scheduler and thus allow only a single
3344 thread to run.
3345
3346 @table @code
3347 @item set scheduler-locking @var{mode}
3348 Set the scheduler locking mode. If it is @code{off}, then there is no
3349 locking and any thread may run at any time. If @code{on}, then only the
3350 current thread may run when the inferior is resumed. The @code{step}
3351 mode optimizes for single-stepping. It stops other threads from
3352 ``seizing the prompt'' by preempting the current thread while you are
3353 stepping. Other threads will only rarely (or never) get a chance to run
3354 when you step. They are more likely to run when you @samp{next} over a
3355 function call, and they are completely free to run when you use commands
3356 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
3357 thread hits a breakpoint during its timeslice, they will never steal the
3358 GDB prompt away from the thread that you are debugging.
3359
3360 @item show scheduler-locking
3361 Display the current scheduler locking mode.
3362 @end table
3363
3364
3365 @node Stack
3366 @chapter Examining the Stack
3367
3368 When your program has stopped, the first thing you need to know is where it
3369 stopped and how it got there.
3370
3371 @cindex call stack
3372 Each time your program performs a function call, information about the call
3373 is generated.
3374 That information includes the location of the call in your program,
3375 the arguments of the call,
3376 and the local variables of the function being called.
3377 The information is saved in a block of data called a @dfn{stack frame}.
3378 The stack frames are allocated in a region of memory called the @dfn{call
3379 stack}.
3380
3381 When your program stops, the @value{GDBN} commands for examining the
3382 stack allow you to see all of this information.
3383
3384 @cindex selected frame
3385 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3386 @value{GDBN} commands refer implicitly to the selected frame. In
3387 particular, whenever you ask @value{GDBN} for the value of a variable in
3388 your program, the value is found in the selected frame. There are
3389 special @value{GDBN} commands to select whichever frame you are
3390 interested in. @xref{Selection, ,Selecting a frame}.
3391
3392 When your program stops, @value{GDBN} automatically selects the
3393 currently executing frame and describes it briefly, similar to the
3394 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3395
3396 @menu
3397 * Frames:: Stack frames
3398 * Backtrace:: Backtraces
3399 * Selection:: Selecting a frame
3400 * Frame Info:: Information on a frame
3401
3402 @end menu
3403
3404 @node Frames
3405 @section Stack frames
3406
3407 @cindex frame, definition
3408 @cindex stack frame
3409 The call stack is divided up into contiguous pieces called @dfn{stack
3410 frames}, or @dfn{frames} for short; each frame is the data associated
3411 with one call to one function. The frame contains the arguments given
3412 to the function, the function's local variables, and the address at
3413 which the function is executing.
3414
3415 @cindex initial frame
3416 @cindex outermost frame
3417 @cindex innermost frame
3418 When your program is started, the stack has only one frame, that of the
3419 function @code{main}. This is called the @dfn{initial} frame or the
3420 @dfn{outermost} frame. Each time a function is called, a new frame is
3421 made. Each time a function returns, the frame for that function invocation
3422 is eliminated. If a function is recursive, there can be many frames for
3423 the same function. The frame for the function in which execution is
3424 actually occurring is called the @dfn{innermost} frame. This is the most
3425 recently created of all the stack frames that still exist.
3426
3427 @cindex frame pointer
3428 Inside your program, stack frames are identified by their addresses. A
3429 stack frame consists of many bytes, each of which has its own address; each
3430 kind of computer has a convention for choosing one byte whose
3431 address serves as the address of the frame. Usually this address is kept
3432 in a register called the @dfn{frame pointer register} while execution is
3433 going on in that frame.
3434
3435 @cindex frame number
3436 @value{GDBN} assigns numbers to all existing stack frames, starting with
3437 zero for the innermost frame, one for the frame that called it,
3438 and so on upward. These numbers do not really exist in your program;
3439 they are assigned by @value{GDBN} to give you a way of designating stack
3440 frames in @value{GDBN} commands.
3441
3442 @c below produces an acceptable overful hbox. --mew 13aug1993
3443 @cindex frameless execution
3444 Some compilers provide a way to compile functions so that they operate
3445 without stack frames. (For example, the @code{@value{GCC}} option
3446 @samp{-fomit-frame-pointer} generates functions without a frame.)
3447 This is occasionally done with heavily used library functions to save
3448 the frame setup time. @value{GDBN} has limited facilities for dealing
3449 with these function invocations. If the innermost function invocation
3450 has no stack frame, @value{GDBN} nevertheless regards it as though
3451 it had a separate frame, which is numbered zero as usual, allowing
3452 correct tracing of the function call chain. However, @value{GDBN} has
3453 no provision for frameless functions elsewhere in the stack.
3454
3455 @table @code
3456 @kindex frame@r{, command}
3457 @item frame @var{args}
3458 The @code{frame} command allows you to move from one stack frame to another,
3459 and to print the stack frame you select. @var{args} may be either the
3460 address of the frame or the stack frame number. Without an argument,
3461 @code{frame} prints the current stack frame.
3462
3463 @kindex select-frame
3464 @item select-frame
3465 The @code{select-frame} command allows you to move from one stack frame
3466 to another without printing the frame. This is the silent version of
3467 @code{frame}.
3468 @end table
3469
3470 @node Backtrace
3471 @section Backtraces
3472
3473 @cindex backtraces
3474 @cindex tracebacks
3475 @cindex stack traces
3476 A backtrace is a summary of how your program got where it is. It shows one
3477 line per frame, for many frames, starting with the currently executing
3478 frame (frame zero), followed by its caller (frame one), and on up the
3479 stack.
3480
3481 @table @code
3482 @kindex backtrace
3483 @kindex bt
3484 @item backtrace
3485 @itemx bt
3486 Print a backtrace of the entire stack: one line per frame for all
3487 frames in the stack.
3488
3489 You can stop the backtrace at any time by typing the system interrupt
3490 character, normally @kbd{C-c}.
3491
3492 @item backtrace @var{n}
3493 @itemx bt @var{n}
3494 Similar, but print only the innermost @var{n} frames.
3495
3496 @item backtrace -@var{n}
3497 @itemx bt -@var{n}
3498 Similar, but print only the outermost @var{n} frames.
3499 @end table
3500
3501 @kindex where
3502 @kindex info stack
3503 @kindex info s
3504 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3505 are additional aliases for @code{backtrace}.
3506
3507 Each line in the backtrace shows the frame number and the function name.
3508 The program counter value is also shown---unless you use @code{set
3509 print address off}. The backtrace also shows the source file name and
3510 line number, as well as the arguments to the function. The program
3511 counter value is omitted if it is at the beginning of the code for that
3512 line number.
3513
3514 Here is an example of a backtrace. It was made with the command
3515 @samp{bt 3}, so it shows the innermost three frames.
3516
3517 @smallexample
3518 @group
3519 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3520 at builtin.c:993
3521 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3522 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3523 at macro.c:71
3524 (More stack frames follow...)
3525 @end group
3526 @end smallexample
3527
3528 @noindent
3529 The display for frame zero does not begin with a program counter
3530 value, indicating that your program has stopped at the beginning of the
3531 code for line @code{993} of @code{builtin.c}.
3532
3533 @node Selection
3534 @section Selecting a frame
3535
3536 Most commands for examining the stack and other data in your program work on
3537 whichever stack frame is selected at the moment. Here are the commands for
3538 selecting a stack frame; all of them finish by printing a brief description
3539 of the stack frame just selected.
3540
3541 @table @code
3542 @kindex frame@r{, selecting}
3543 @kindex f
3544 @item frame @var{n}
3545 @itemx f @var{n}
3546 Select frame number @var{n}. Recall that frame zero is the innermost
3547 (currently executing) frame, frame one is the frame that called the
3548 innermost one, and so on. The highest-numbered frame is the one for
3549 @code{main}.
3550
3551 @item frame @var{addr}
3552 @itemx f @var{addr}
3553 Select the frame at address @var{addr}. This is useful mainly if the
3554 chaining of stack frames has been damaged by a bug, making it
3555 impossible for @value{GDBN} to assign numbers properly to all frames. In
3556 addition, this can be useful when your program has multiple stacks and
3557 switches between them.
3558
3559 On the SPARC architecture, @code{frame} needs two addresses to
3560 select an arbitrary frame: a frame pointer and a stack pointer.
3561
3562 On the MIPS and Alpha architecture, it needs two addresses: a stack
3563 pointer and a program counter.
3564
3565 On the 29k architecture, it needs three addresses: a register stack
3566 pointer, a program counter, and a memory stack pointer.
3567 @c note to future updaters: this is conditioned on a flag
3568 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3569 @c as of 27 Jan 1994.
3570
3571 @kindex up
3572 @item up @var{n}
3573 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3574 advances toward the outermost frame, to higher frame numbers, to frames
3575 that have existed longer. @var{n} defaults to one.
3576
3577 @kindex down
3578 @kindex do
3579 @item down @var{n}
3580 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3581 advances toward the innermost frame, to lower frame numbers, to frames
3582 that were created more recently. @var{n} defaults to one. You may
3583 abbreviate @code{down} as @code{do}.
3584 @end table
3585
3586 All of these commands end by printing two lines of output describing the
3587 frame. The first line shows the frame number, the function name, the
3588 arguments, and the source file and line number of execution in that
3589 frame. The second line shows the text of that source line.
3590
3591 @need 1000
3592 For example:
3593
3594 @smallexample
3595 @group
3596 (@value{GDBP}) up
3597 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3598 at env.c:10
3599 10 read_input_file (argv[i]);
3600 @end group
3601 @end smallexample
3602
3603 After such a printout, the @code{list} command with no arguments
3604 prints ten lines centered on the point of execution in the frame.
3605 @xref{List, ,Printing source lines}.
3606
3607 @table @code
3608 @kindex down-silently
3609 @kindex up-silently
3610 @item up-silently @var{n}
3611 @itemx down-silently @var{n}
3612 These two commands are variants of @code{up} and @code{down},
3613 respectively; they differ in that they do their work silently, without
3614 causing display of the new frame. They are intended primarily for use
3615 in @value{GDBN} command scripts, where the output might be unnecessary and
3616 distracting.
3617 @end table
3618
3619 @node Frame Info
3620 @section Information about a frame
3621
3622 There are several other commands to print information about the selected
3623 stack frame.
3624
3625 @table @code
3626 @item frame
3627 @itemx f
3628 When used without any argument, this command does not change which
3629 frame is selected, but prints a brief description of the currently
3630 selected stack frame. It can be abbreviated @code{f}. With an
3631 argument, this command is used to select a stack frame.
3632 @xref{Selection, ,Selecting a frame}.
3633
3634 @kindex info frame
3635 @kindex info f
3636 @item info frame
3637 @itemx info f
3638 This command prints a verbose description of the selected stack frame,
3639 including:
3640
3641 @itemize @bullet
3642 @item
3643 the address of the frame
3644 @item
3645 the address of the next frame down (called by this frame)
3646 @item
3647 the address of the next frame up (caller of this frame)
3648 @item
3649 the language in which the source code corresponding to this frame is written
3650 @item
3651 the address of the frame's arguments
3652 @item
3653 the address of the frame's local variables
3654 @item
3655 the program counter saved in it (the address of execution in the caller frame)
3656 @item
3657 which registers were saved in the frame
3658 @end itemize
3659
3660 @noindent The verbose description is useful when
3661 something has gone wrong that has made the stack format fail to fit
3662 the usual conventions.
3663
3664 @item info frame @var{addr}
3665 @itemx info f @var{addr}
3666 Print a verbose description of the frame at address @var{addr}, without
3667 selecting that frame. The selected frame remains unchanged by this
3668 command. This requires the same kind of address (more than one for some
3669 architectures) that you specify in the @code{frame} command.
3670 @xref{Selection, ,Selecting a frame}.
3671
3672 @kindex info args
3673 @item info args
3674 Print the arguments of the selected frame, each on a separate line.
3675
3676 @item info locals
3677 @kindex info locals
3678 Print the local variables of the selected frame, each on a separate
3679 line. These are all variables (declared either static or automatic)
3680 accessible at the point of execution of the selected frame.
3681
3682 @kindex info catch
3683 @cindex catch exceptions, list active handlers
3684 @cindex exception handlers, how to list
3685 @item info catch
3686 Print a list of all the exception handlers that are active in the
3687 current stack frame at the current point of execution. To see other
3688 exception handlers, visit the associated frame (using the @code{up},
3689 @code{down}, or @code{frame} commands); then type @code{info catch}.
3690 @xref{Set Catchpoints, , Setting catchpoints}.
3691
3692 @end table
3693
3694
3695 @node Source
3696 @chapter Examining Source Files
3697
3698 @value{GDBN} can print parts of your program's source, since the debugging
3699 information recorded in the program tells @value{GDBN} what source files were
3700 used to build it. When your program stops, @value{GDBN} spontaneously prints
3701 the line where it stopped. Likewise, when you select a stack frame
3702 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3703 execution in that frame has stopped. You can print other portions of
3704 source files by explicit command.
3705
3706 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
3707 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
3708 @value{GDBN} under @sc{gnu} Emacs}.
3709
3710 @menu
3711 * List:: Printing source lines
3712 * Search:: Searching source files
3713 * Source Path:: Specifying source directories
3714 * Machine Code:: Source and machine code
3715 @end menu
3716
3717 @node List
3718 @section Printing source lines
3719
3720 @kindex list
3721 @kindex l
3722 To print lines from a source file, use the @code{list} command
3723 (abbreviated @code{l}). By default, ten lines are printed.
3724 There are several ways to specify what part of the file you want to print.
3725
3726 Here are the forms of the @code{list} command most commonly used:
3727
3728 @table @code
3729 @item list @var{linenum}
3730 Print lines centered around line number @var{linenum} in the
3731 current source file.
3732
3733 @item list @var{function}
3734 Print lines centered around the beginning of function
3735 @var{function}.
3736
3737 @item list
3738 Print more lines. If the last lines printed were printed with a
3739 @code{list} command, this prints lines following the last lines
3740 printed; however, if the last line printed was a solitary line printed
3741 as part of displaying a stack frame (@pxref{Stack, ,Examining the
3742 Stack}), this prints lines centered around that line.
3743
3744 @item list -
3745 Print lines just before the lines last printed.
3746 @end table
3747
3748 By default, @value{GDBN} prints ten source lines with any of these forms of
3749 the @code{list} command. You can change this using @code{set listsize}:
3750
3751 @table @code
3752 @kindex set listsize
3753 @item set listsize @var{count}
3754 Make the @code{list} command display @var{count} source lines (unless
3755 the @code{list} argument explicitly specifies some other number).
3756
3757 @kindex show listsize
3758 @item show listsize
3759 Display the number of lines that @code{list} prints.
3760 @end table
3761
3762 Repeating a @code{list} command with @key{RET} discards the argument,
3763 so it is equivalent to typing just @code{list}. This is more useful
3764 than listing the same lines again. An exception is made for an
3765 argument of @samp{-}; that argument is preserved in repetition so that
3766 each repetition moves up in the source file.
3767
3768 @cindex linespec
3769 In general, the @code{list} command expects you to supply zero, one or two
3770 @dfn{linespecs}. Linespecs specify source lines; there are several ways
3771 of writing them, but the effect is always to specify some source line.
3772 Here is a complete description of the possible arguments for @code{list}:
3773
3774 @table @code
3775 @item list @var{linespec}
3776 Print lines centered around the line specified by @var{linespec}.
3777
3778 @item list @var{first},@var{last}
3779 Print lines from @var{first} to @var{last}. Both arguments are
3780 linespecs.
3781
3782 @item list ,@var{last}
3783 Print lines ending with @var{last}.
3784
3785 @item list @var{first},
3786 Print lines starting with @var{first}.
3787
3788 @item list +
3789 Print lines just after the lines last printed.
3790
3791 @item list -
3792 Print lines just before the lines last printed.
3793
3794 @item list
3795 As described in the preceding table.
3796 @end table
3797
3798 Here are the ways of specifying a single source line---all the
3799 kinds of linespec.
3800
3801 @table @code
3802 @item @var{number}
3803 Specifies line @var{number} of the current source file.
3804 When a @code{list} command has two linespecs, this refers to
3805 the same source file as the first linespec.
3806
3807 @item +@var{offset}
3808 Specifies the line @var{offset} lines after the last line printed.
3809 When used as the second linespec in a @code{list} command that has
3810 two, this specifies the line @var{offset} lines down from the
3811 first linespec.
3812
3813 @item -@var{offset}
3814 Specifies the line @var{offset} lines before the last line printed.
3815
3816 @item @var{filename}:@var{number}
3817 Specifies line @var{number} in the source file @var{filename}.
3818
3819 @item @var{function}
3820 Specifies the line that begins the body of the function @var{function}.
3821 For example: in C, this is the line with the open brace.
3822
3823 @item @var{filename}:@var{function}
3824 Specifies the line of the open-brace that begins the body of the
3825 function @var{function} in the file @var{filename}. You only need the
3826 file name with a function name to avoid ambiguity when there are
3827 identically named functions in different source files.
3828
3829 @item *@var{address}
3830 Specifies the line containing the program address @var{address}.
3831 @var{address} may be any expression.
3832 @end table
3833
3834 @node Search
3835 @section Searching source files
3836 @cindex searching
3837 @kindex reverse-search
3838
3839 There are two commands for searching through the current source file for a
3840 regular expression.
3841
3842 @table @code
3843 @kindex search
3844 @kindex forward-search
3845 @item forward-search @var{regexp}
3846 @itemx search @var{regexp}
3847 The command @samp{forward-search @var{regexp}} checks each line,
3848 starting with the one following the last line listed, for a match for
3849 @var{regexp}. It lists the line that is found. You can use the
3850 synonym @samp{search @var{regexp}} or abbreviate the command name as
3851 @code{fo}.
3852
3853 @item reverse-search @var{regexp}
3854 The command @samp{reverse-search @var{regexp}} checks each line, starting
3855 with the one before the last line listed and going backward, for a match
3856 for @var{regexp}. It lists the line that is found. You can abbreviate
3857 this command as @code{rev}.
3858 @end table
3859
3860 @node Source Path
3861 @section Specifying source directories
3862
3863 @cindex source path
3864 @cindex directories for source files
3865 Executable programs sometimes do not record the directories of the source
3866 files from which they were compiled, just the names. Even when they do,
3867 the directories could be moved between the compilation and your debugging
3868 session. @value{GDBN} has a list of directories to search for source files;
3869 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
3870 it tries all the directories in the list, in the order they are present
3871 in the list, until it finds a file with the desired name. Note that
3872 the executable search path is @emph{not} used for this purpose. Neither is
3873 the current working directory, unless it happens to be in the source
3874 path.
3875
3876 If @value{GDBN} cannot find a source file in the source path, and the
3877 object program records a directory, @value{GDBN} tries that directory
3878 too. If the source path is empty, and there is no record of the
3879 compilation directory, @value{GDBN} looks in the current directory as a
3880 last resort.
3881
3882 Whenever you reset or rearrange the source path, @value{GDBN} clears out
3883 any information it has cached about where source files are found and where
3884 each line is in the file.
3885
3886 @kindex directory
3887 @kindex dir
3888 When you start @value{GDBN}, its source path includes only @samp{cdir}
3889 and @samp{cwd}, in that order.
3890 To add other directories, use the @code{directory} command.
3891
3892 @table @code
3893 @item directory @var{dirname} @dots{}
3894 @item dir @var{dirname} @dots{}
3895 Add directory @var{dirname} to the front of the source path. Several
3896 directory names may be given to this command, separated by @samp{:}
3897 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
3898 part of absolute file names) or
3899 whitespace. You may specify a directory that is already in the source
3900 path; this moves it forward, so @value{GDBN} searches it sooner.
3901
3902 @kindex cdir
3903 @kindex cwd
3904 @kindex $cdir
3905 @kindex $cwd
3906 @cindex compilation directory
3907 @cindex current directory
3908 @cindex working directory
3909 @cindex directory, current
3910 @cindex directory, compilation
3911 You can use the string @samp{$cdir} to refer to the compilation
3912 directory (if one is recorded), and @samp{$cwd} to refer to the current
3913 working directory. @samp{$cwd} is not the same as @samp{.}---the former
3914 tracks the current working directory as it changes during your @value{GDBN}
3915 session, while the latter is immediately expanded to the current
3916 directory at the time you add an entry to the source path.
3917
3918 @item directory
3919 Reset the source path to empty again. This requires confirmation.
3920
3921 @c RET-repeat for @code{directory} is explicitly disabled, but since
3922 @c repeating it would be a no-op we do not say that. (thanks to RMS)
3923
3924 @item show directories
3925 @kindex show directories
3926 Print the source path: show which directories it contains.
3927 @end table
3928
3929 If your source path is cluttered with directories that are no longer of
3930 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
3931 versions of source. You can correct the situation as follows:
3932
3933 @enumerate
3934 @item
3935 Use @code{directory} with no argument to reset the source path to empty.
3936
3937 @item
3938 Use @code{directory} with suitable arguments to reinstall the
3939 directories you want in the source path. You can add all the
3940 directories in one command.
3941 @end enumerate
3942
3943 @node Machine Code
3944 @section Source and machine code
3945
3946 You can use the command @code{info line} to map source lines to program
3947 addresses (and vice versa), and the command @code{disassemble} to display
3948 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
3949 mode, the @code{info line} command causes the arrow to point to the
3950 line specified. Also, @code{info line} prints addresses in symbolic form as
3951 well as hex.
3952
3953 @table @code
3954 @kindex info line
3955 @item info line @var{linespec}
3956 Print the starting and ending addresses of the compiled code for
3957 source line @var{linespec}. You can specify source lines in any of
3958 the ways understood by the @code{list} command (@pxref{List, ,Printing
3959 source lines}).
3960 @end table
3961
3962 For example, we can use @code{info line} to discover the location of
3963 the object code for the first line of function
3964 @code{m4_changequote}:
3965
3966 @c FIXME: I think this example should also show the addresses in
3967 @c symbolic form, as they usually would be displayed.
3968 @smallexample
3969 (@value{GDBP}) info line m4_changecom
3970 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3971 @end smallexample
3972
3973 @noindent
3974 We can also inquire (using @code{*@var{addr}} as the form for
3975 @var{linespec}) what source line covers a particular address:
3976 @smallexample
3977 (@value{GDBP}) info line *0x63ff
3978 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
3979 @end smallexample
3980
3981 @cindex @code{$_} and @code{info line}
3982 @kindex x@r{, and }@code{info line}
3983 After @code{info line}, the default address for the @code{x} command
3984 is changed to the starting address of the line, so that @samp{x/i} is
3985 sufficient to begin examining the machine code (@pxref{Memory,
3986 ,Examining memory}). Also, this address is saved as the value of the
3987 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
3988 variables}).
3989
3990 @table @code
3991 @kindex disassemble
3992 @cindex assembly instructions
3993 @cindex instructions, assembly
3994 @cindex machine instructions
3995 @cindex listing machine instructions
3996 @item disassemble
3997 This specialized command dumps a range of memory as machine
3998 instructions. The default memory range is the function surrounding the
3999 program counter of the selected frame. A single argument to this
4000 command is a program counter value; @value{GDBN} dumps the function
4001 surrounding this value. Two arguments specify a range of addresses
4002 (first inclusive, second exclusive) to dump.
4003 @end table
4004
4005 The following example shows the disassembly of a range of addresses of
4006 HP PA-RISC 2.0 code:
4007
4008 @smallexample
4009 (@value{GDBP}) disas 0x32c4 0x32e4
4010 Dump of assembler code from 0x32c4 to 0x32e4:
4011 0x32c4 <main+204>: addil 0,dp
4012 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
4013 0x32cc <main+212>: ldil 0x3000,r31
4014 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
4015 0x32d4 <main+220>: ldo 0(r31),rp
4016 0x32d8 <main+224>: addil -0x800,dp
4017 0x32dc <main+228>: ldo 0x588(r1),r26
4018 0x32e0 <main+232>: ldil 0x3000,r31
4019 End of assembler dump.
4020 @end smallexample
4021
4022 Some architectures have more than one commonly-used set of instruction
4023 mnemonics or other syntax.
4024
4025 @table @code
4026 @kindex set disassembly-flavor
4027 @cindex assembly instructions
4028 @cindex instructions, assembly
4029 @cindex machine instructions
4030 @cindex listing machine instructions
4031 @cindex Intel disassembly flavor
4032 @cindex AT&T disassembly flavor
4033 @item set disassembly-flavor @var{instruction-set}
4034 Select the instruction set to use when disassembling the
4035 program via the @code{disassemble} or @code{x/i} commands.
4036
4037 Currently this command is only defined for the Intel x86 family. You
4038 can set @var{instruction-set} to either @code{intel} or @code{att}.
4039 The default is @code{att}, the AT&T flavor used by default by Unix
4040 assemblers for x86-based targets.
4041 @end table
4042
4043
4044 @node Data
4045 @chapter Examining Data
4046
4047 @cindex printing data
4048 @cindex examining data
4049 @kindex print
4050 @kindex inspect
4051 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
4052 @c document because it is nonstandard... Under Epoch it displays in a
4053 @c different window or something like that.
4054 The usual way to examine data in your program is with the @code{print}
4055 command (abbreviated @code{p}), or its synonym @code{inspect}. It
4056 evaluates and prints the value of an expression of the language your
4057 program is written in (@pxref{Languages, ,Using @value{GDBN} with
4058 Different Languages}).
4059
4060 @table @code
4061 @item print @var{expr}
4062 @itemx print /@var{f} @var{expr}
4063 @var{expr} is an expression (in the source language). By default the
4064 value of @var{expr} is printed in a format appropriate to its data type;
4065 you can choose a different format by specifying @samp{/@var{f}}, where
4066 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
4067 formats}.
4068
4069 @item print
4070 @itemx print /@var{f}
4071 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
4072 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4073 conveniently inspect the same value in an alternative format.
4074 @end table
4075
4076 A more low-level way of examining data is with the @code{x} command.
4077 It examines data in memory at a specified address and prints it in a
4078 specified format. @xref{Memory, ,Examining memory}.
4079
4080 If you are interested in information about types, or about how the
4081 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4082 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
4083 Table}.
4084
4085 @menu
4086 * Expressions:: Expressions
4087 * Variables:: Program variables
4088 * Arrays:: Artificial arrays
4089 * Output Formats:: Output formats
4090 * Memory:: Examining memory
4091 * Auto Display:: Automatic display
4092 * Print Settings:: Print settings
4093 * Value History:: Value history
4094 * Convenience Vars:: Convenience variables
4095 * Registers:: Registers
4096 * Floating Point Hardware:: Floating point hardware
4097 @end menu
4098
4099 @node Expressions
4100 @section Expressions
4101
4102 @cindex expressions
4103 @code{print} and many other @value{GDBN} commands accept an expression and
4104 compute its value. Any kind of constant, variable or operator defined
4105 by the programming language you are using is valid in an expression in
4106 @value{GDBN}. This includes conditional expressions, function calls, casts
4107 and string constants. It unfortunately does not include symbols defined
4108 by preprocessor @code{#define} commands.
4109
4110 @value{GDBN} supports array constants in expressions input by
4111 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
4112 you can use the command @code{print @{1, 2, 3@}} to build up an array in
4113 memory that is @code{malloc}ed in the target program.
4114
4115 Because C is so widespread, most of the expressions shown in examples in
4116 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4117 Languages}, for information on how to use expressions in other
4118 languages.
4119
4120 In this section, we discuss operators that you can use in @value{GDBN}
4121 expressions regardless of your programming language.
4122
4123 Casts are supported in all languages, not just in C, because it is so
4124 useful to cast a number into a pointer in order to examine a structure
4125 at that address in memory.
4126 @c FIXME: casts supported---Mod2 true?
4127
4128 @value{GDBN} supports these operators, in addition to those common
4129 to programming languages:
4130
4131 @table @code
4132 @item @@
4133 @samp{@@} is a binary operator for treating parts of memory as arrays.
4134 @xref{Arrays, ,Artificial arrays}, for more information.
4135
4136 @item ::
4137 @samp{::} allows you to specify a variable in terms of the file or
4138 function where it is defined. @xref{Variables, ,Program variables}.
4139
4140 @cindex @{@var{type}@}
4141 @cindex type casting memory
4142 @cindex memory, viewing as typed object
4143 @cindex casts, to view memory
4144 @item @{@var{type}@} @var{addr}
4145 Refers to an object of type @var{type} stored at address @var{addr} in
4146 memory. @var{addr} may be any expression whose value is an integer or
4147 pointer (but parentheses are required around binary operators, just as in
4148 a cast). This construct is allowed regardless of what kind of data is
4149 normally supposed to reside at @var{addr}.
4150 @end table
4151
4152 @node Variables
4153 @section Program variables
4154
4155 The most common kind of expression to use is the name of a variable
4156 in your program.
4157
4158 Variables in expressions are understood in the selected stack frame
4159 (@pxref{Selection, ,Selecting a frame}); they must be either:
4160
4161 @itemize @bullet
4162 @item
4163 global (or file-static)
4164 @end itemize
4165
4166 @noindent or
4167
4168 @itemize @bullet
4169 @item
4170 visible according to the scope rules of the
4171 programming language from the point of execution in that frame
4172 @end itemize
4173
4174 @noindent This means that in the function
4175
4176 @example
4177 foo (a)
4178 int a;
4179 @{
4180 bar (a);
4181 @{
4182 int b = test ();
4183 bar (b);
4184 @}
4185 @}
4186 @end example
4187
4188 @noindent
4189 you can examine and use the variable @code{a} whenever your program is
4190 executing within the function @code{foo}, but you can only use or
4191 examine the variable @code{b} while your program is executing inside
4192 the block where @code{b} is declared.
4193
4194 @cindex variable name conflict
4195 There is an exception: you can refer to a variable or function whose
4196 scope is a single source file even if the current execution point is not
4197 in this file. But it is possible to have more than one such variable or
4198 function with the same name (in different source files). If that
4199 happens, referring to that name has unpredictable effects. If you wish,
4200 you can specify a static variable in a particular function or file,
4201 using the colon-colon notation:
4202
4203 @cindex colon-colon, context for variables/functions
4204 @iftex
4205 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
4206 @kindex ::
4207 @end iftex
4208 @example
4209 @var{file}::@var{variable}
4210 @var{function}::@var{variable}
4211 @end example
4212
4213 @noindent
4214 Here @var{file} or @var{function} is the name of the context for the
4215 static @var{variable}. In the case of file names, you can use quotes to
4216 make sure @value{GDBN} parses the file name as a single word---for example,
4217 to print a global value of @code{x} defined in @file{f2.c}:
4218
4219 @example
4220 (@value{GDBP}) p 'f2.c'::x
4221 @end example
4222
4223 @cindex C++ scope resolution
4224 This use of @samp{::} is very rarely in conflict with the very similar
4225 use of the same notation in C++. @value{GDBN} also supports use of the C++
4226 scope resolution operator in @value{GDBN} expressions.
4227 @c FIXME: Um, so what happens in one of those rare cases where it's in
4228 @c conflict?? --mew
4229
4230 @cindex wrong values
4231 @cindex variable values, wrong
4232 @quotation
4233 @emph{Warning:} Occasionally, a local variable may appear to have the
4234 wrong value at certain points in a function---just after entry to a new
4235 scope, and just before exit.
4236 @end quotation
4237 You may see this problem when you are stepping by machine instructions.
4238 This is because, on most machines, it takes more than one instruction to
4239 set up a stack frame (including local variable definitions); if you are
4240 stepping by machine instructions, variables may appear to have the wrong
4241 values until the stack frame is completely built. On exit, it usually
4242 also takes more than one machine instruction to destroy a stack frame;
4243 after you begin stepping through that group of instructions, local
4244 variable definitions may be gone.
4245
4246 This may also happen when the compiler does significant optimizations.
4247 To be sure of always seeing accurate values, turn off all optimization
4248 when compiling.
4249
4250 @cindex ``No symbol "foo" in current context''
4251 Another possible effect of compiler optimizations is to optimize
4252 unused variables out of existence, or assign variables to registers (as
4253 opposed to memory addresses). Depending on the support for such cases
4254 offered by the debug info format used by the compiler, @value{GDBN}
4255 might not be able to display values for such local variables. If that
4256 happens, @value{GDBN} will print a message like this:
4257
4258 @example
4259 No symbol "foo" in current context.
4260 @end example
4261
4262 To solve such problems, either recompile without optimizations, or use a
4263 different debug info format, if the compiler supports several such
4264 formats. For example, @value{NGCC}, the @sc{gnu} C/C++ compiler usually
4265 supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4266 in a format that is superior to formats such as COFF. You may be able
4267 to use DWARF-2 (@samp{-gdwarf-2}), which is also an effective form for
4268 debug info. See @ref{Debugging Options,,Options for Debugging Your
4269 Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4270 information.
4271
4272
4273 @node Arrays
4274 @section Artificial arrays
4275
4276 @cindex artificial array
4277 @kindex @@
4278 It is often useful to print out several successive objects of the
4279 same type in memory; a section of an array, or an array of
4280 dynamically determined size for which only a pointer exists in the
4281 program.
4282
4283 You can do this by referring to a contiguous span of memory as an
4284 @dfn{artificial array}, using the binary operator @samp{@@}. The left
4285 operand of @samp{@@} should be the first element of the desired array
4286 and be an individual object. The right operand should be the desired length
4287 of the array. The result is an array value whose elements are all of
4288 the type of the left argument. The first element is actually the left
4289 argument; the second element comes from bytes of memory immediately
4290 following those that hold the first element, and so on. Here is an
4291 example. If a program says
4292
4293 @example
4294 int *array = (int *) malloc (len * sizeof (int));
4295 @end example
4296
4297 @noindent
4298 you can print the contents of @code{array} with
4299
4300 @example
4301 p *array@@len
4302 @end example
4303
4304 The left operand of @samp{@@} must reside in memory. Array values made
4305 with @samp{@@} in this way behave just like other arrays in terms of
4306 subscripting, and are coerced to pointers when used in expressions.
4307 Artificial arrays most often appear in expressions via the value history
4308 (@pxref{Value History, ,Value history}), after printing one out.
4309
4310 Another way to create an artificial array is to use a cast.
4311 This re-interprets a value as if it were an array.
4312 The value need not be in memory:
4313 @example
4314 (@value{GDBP}) p/x (short[2])0x12345678
4315 $1 = @{0x1234, 0x5678@}
4316 @end example
4317
4318 As a convenience, if you leave the array length out (as in
4319 @samp{(@var{type}[])@var{value}}) gdb calculates the size to fill
4320 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4321 @example
4322 (@value{GDBP}) p/x (short[])0x12345678
4323 $2 = @{0x1234, 0x5678@}
4324 @end example
4325
4326 Sometimes the artificial array mechanism is not quite enough; in
4327 moderately complex data structures, the elements of interest may not
4328 actually be adjacent---for example, if you are interested in the values
4329 of pointers in an array. One useful work-around in this situation is
4330 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4331 variables}) as a counter in an expression that prints the first
4332 interesting value, and then repeat that expression via @key{RET}. For
4333 instance, suppose you have an array @code{dtab} of pointers to
4334 structures, and you are interested in the values of a field @code{fv}
4335 in each structure. Here is an example of what you might type:
4336
4337 @example
4338 set $i = 0
4339 p dtab[$i++]->fv
4340 @key{RET}
4341 @key{RET}
4342 @dots{}
4343 @end example
4344
4345 @node Output Formats
4346 @section Output formats
4347
4348 @cindex formatted output
4349 @cindex output formats
4350 By default, @value{GDBN} prints a value according to its data type. Sometimes
4351 this is not what you want. For example, you might want to print a number
4352 in hex, or a pointer in decimal. Or you might want to view data in memory
4353 at a certain address as a character string or as an instruction. To do
4354 these things, specify an @dfn{output format} when you print a value.
4355
4356 The simplest use of output formats is to say how to print a value
4357 already computed. This is done by starting the arguments of the
4358 @code{print} command with a slash and a format letter. The format
4359 letters supported are:
4360
4361 @table @code
4362 @item x
4363 Regard the bits of the value as an integer, and print the integer in
4364 hexadecimal.
4365
4366 @item d
4367 Print as integer in signed decimal.
4368
4369 @item u
4370 Print as integer in unsigned decimal.
4371
4372 @item o
4373 Print as integer in octal.
4374
4375 @item t
4376 Print as integer in binary. The letter @samp{t} stands for ``two''.
4377 @footnote{@samp{b} cannot be used because these format letters are also
4378 used with the @code{x} command, where @samp{b} stands for ``byte'';
4379 see @ref{Memory,,Examining memory}.}
4380
4381 @item a
4382 @cindex unknown address, locating
4383 Print as an address, both absolute in hexadecimal and as an offset from
4384 the nearest preceding symbol. You can use this format used to discover
4385 where (in what function) an unknown address is located:
4386
4387 @example
4388 (@value{GDBP}) p/a 0x54320
4389 $3 = 0x54320 <_initialize_vx+396>
4390 @end example
4391
4392 @item c
4393 Regard as an integer and print it as a character constant.
4394
4395 @item f
4396 Regard the bits of the value as a floating point number and print
4397 using typical floating point syntax.
4398 @end table
4399
4400 For example, to print the program counter in hex (@pxref{Registers}), type
4401
4402 @example
4403 p/x $pc
4404 @end example
4405
4406 @noindent
4407 Note that no space is required before the slash; this is because command
4408 names in @value{GDBN} cannot contain a slash.
4409
4410 To reprint the last value in the value history with a different format,
4411 you can use the @code{print} command with just a format and no
4412 expression. For example, @samp{p/x} reprints the last value in hex.
4413
4414 @node Memory
4415 @section Examining memory
4416
4417 You can use the command @code{x} (for ``examine'') to examine memory in
4418 any of several formats, independently of your program's data types.
4419
4420 @cindex examining memory
4421 @table @code
4422 @kindex x
4423 @item x/@var{nfu} @var{addr}
4424 @itemx x @var{addr}
4425 @itemx x
4426 Use the @code{x} command to examine memory.
4427 @end table
4428
4429 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4430 much memory to display and how to format it; @var{addr} is an
4431 expression giving the address where you want to start displaying memory.
4432 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4433 Several commands set convenient defaults for @var{addr}.
4434
4435 @table @r
4436 @item @var{n}, the repeat count
4437 The repeat count is a decimal integer; the default is 1. It specifies
4438 how much memory (counting by units @var{u}) to display.
4439 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4440 @c 4.1.2.
4441
4442 @item @var{f}, the display format
4443 The display format is one of the formats used by @code{print},
4444 @samp{s} (null-terminated string), or @samp{i} (machine instruction).
4445 The default is @samp{x} (hexadecimal) initially.
4446 The default changes each time you use either @code{x} or @code{print}.
4447
4448 @item @var{u}, the unit size
4449 The unit size is any of
4450
4451 @table @code
4452 @item b
4453 Bytes.
4454 @item h
4455 Halfwords (two bytes).
4456 @item w
4457 Words (four bytes). This is the initial default.
4458 @item g
4459 Giant words (eight bytes).
4460 @end table
4461
4462 Each time you specify a unit size with @code{x}, that size becomes the
4463 default unit the next time you use @code{x}. (For the @samp{s} and
4464 @samp{i} formats, the unit size is ignored and is normally not written.)
4465
4466 @item @var{addr}, starting display address
4467 @var{addr} is the address where you want @value{GDBN} to begin displaying
4468 memory. The expression need not have a pointer value (though it may);
4469 it is always interpreted as an integer address of a byte of memory.
4470 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4471 @var{addr} is usually just after the last address examined---but several
4472 other commands also set the default address: @code{info breakpoints} (to
4473 the address of the last breakpoint listed), @code{info line} (to the
4474 starting address of a line), and @code{print} (if you use it to display
4475 a value from memory).
4476 @end table
4477
4478 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4479 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4480 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4481 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4482 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
4483
4484 Since the letters indicating unit sizes are all distinct from the
4485 letters specifying output formats, you do not have to remember whether
4486 unit size or format comes first; either order works. The output
4487 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4488 (However, the count @var{n} must come first; @samp{wx4} does not work.)
4489
4490 Even though the unit size @var{u} is ignored for the formats @samp{s}
4491 and @samp{i}, you might still want to use a count @var{n}; for example,
4492 @samp{3i} specifies that you want to see three machine instructions,
4493 including any operands. The command @code{disassemble} gives an
4494 alternative way of inspecting machine instructions; see @ref{Machine
4495 Code,,Source and machine code}.
4496
4497 All the defaults for the arguments to @code{x} are designed to make it
4498 easy to continue scanning memory with minimal specifications each time
4499 you use @code{x}. For example, after you have inspected three machine
4500 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4501 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4502 the repeat count @var{n} is used again; the other arguments default as
4503 for successive uses of @code{x}.
4504
4505 @cindex @code{$_}, @code{$__}, and value history
4506 The addresses and contents printed by the @code{x} command are not saved
4507 in the value history because there is often too much of them and they
4508 would get in the way. Instead, @value{GDBN} makes these values available for
4509 subsequent use in expressions as values of the convenience variables
4510 @code{$_} and @code{$__}. After an @code{x} command, the last address
4511 examined is available for use in expressions in the convenience variable
4512 @code{$_}. The contents of that address, as examined, are available in
4513 the convenience variable @code{$__}.
4514
4515 If the @code{x} command has a repeat count, the address and contents saved
4516 are from the last memory unit printed; this is not the same as the last
4517 address printed if several units were printed on the last line of output.
4518
4519 @node Auto Display
4520 @section Automatic display
4521 @cindex automatic display
4522 @cindex display of expressions
4523
4524 If you find that you want to print the value of an expression frequently
4525 (to see how it changes), you might want to add it to the @dfn{automatic
4526 display list} so that @value{GDBN} prints its value each time your program stops.
4527 Each expression added to the list is given a number to identify it;
4528 to remove an expression from the list, you specify that number.
4529 The automatic display looks like this:
4530
4531 @example
4532 2: foo = 38
4533 3: bar[5] = (struct hack *) 0x3804
4534 @end example
4535
4536 @noindent
4537 This display shows item numbers, expressions and their current values. As with
4538 displays you request manually using @code{x} or @code{print}, you can
4539 specify the output format you prefer; in fact, @code{display} decides
4540 whether to use @code{print} or @code{x} depending on how elaborate your
4541 format specification is---it uses @code{x} if you specify a unit size,
4542 or one of the two formats (@samp{i} and @samp{s}) that are only
4543 supported by @code{x}; otherwise it uses @code{print}.
4544
4545 @table @code
4546 @kindex display
4547 @item display @var{expr}
4548 Add the expression @var{expr} to the list of expressions to display
4549 each time your program stops. @xref{Expressions, ,Expressions}.
4550
4551 @code{display} does not repeat if you press @key{RET} again after using it.
4552
4553 @item display/@var{fmt} @var{expr}
4554 For @var{fmt} specifying only a display format and not a size or
4555 count, add the expression @var{expr} to the auto-display list but
4556 arrange to display it each time in the specified format @var{fmt}.
4557 @xref{Output Formats,,Output formats}.
4558
4559 @item display/@var{fmt} @var{addr}
4560 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4561 number of units, add the expression @var{addr} as a memory address to
4562 be examined each time your program stops. Examining means in effect
4563 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4564 @end table
4565
4566 For example, @samp{display/i $pc} can be helpful, to see the machine
4567 instruction about to be executed each time execution stops (@samp{$pc}
4568 is a common name for the program counter; @pxref{Registers, ,Registers}).
4569
4570 @table @code
4571 @kindex delete display
4572 @kindex undisplay
4573 @item undisplay @var{dnums}@dots{}
4574 @itemx delete display @var{dnums}@dots{}
4575 Remove item numbers @var{dnums} from the list of expressions to display.
4576
4577 @code{undisplay} does not repeat if you press @key{RET} after using it.
4578 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4579
4580 @kindex disable display
4581 @item disable display @var{dnums}@dots{}
4582 Disable the display of item numbers @var{dnums}. A disabled display
4583 item is not printed automatically, but is not forgotten. It may be
4584 enabled again later.
4585
4586 @kindex enable display
4587 @item enable display @var{dnums}@dots{}
4588 Enable display of item numbers @var{dnums}. It becomes effective once
4589 again in auto display of its expression, until you specify otherwise.
4590
4591 @item display
4592 Display the current values of the expressions on the list, just as is
4593 done when your program stops.
4594
4595 @kindex info display
4596 @item info display
4597 Print the list of expressions previously set up to display
4598 automatically, each one with its item number, but without showing the
4599 values. This includes disabled expressions, which are marked as such.
4600 It also includes expressions which would not be displayed right now
4601 because they refer to automatic variables not currently available.
4602 @end table
4603
4604 If a display expression refers to local variables, then it does not make
4605 sense outside the lexical context for which it was set up. Such an
4606 expression is disabled when execution enters a context where one of its
4607 variables is not defined. For example, if you give the command
4608 @code{display last_char} while inside a function with an argument
4609 @code{last_char}, @value{GDBN} displays this argument while your program
4610 continues to stop inside that function. When it stops elsewhere---where
4611 there is no variable @code{last_char}---the display is disabled
4612 automatically. The next time your program stops where @code{last_char}
4613 is meaningful, you can enable the display expression once again.
4614
4615 @node Print Settings
4616 @section Print settings
4617
4618 @cindex format options
4619 @cindex print settings
4620 @value{GDBN} provides the following ways to control how arrays, structures,
4621 and symbols are printed.
4622
4623 @noindent
4624 These settings are useful for debugging programs in any language:
4625
4626 @table @code
4627 @kindex set print address
4628 @item set print address
4629 @itemx set print address on
4630 @value{GDBN} prints memory addresses showing the location of stack
4631 traces, structure values, pointer values, breakpoints, and so forth,
4632 even when it also displays the contents of those addresses. The default
4633 is @code{on}. For example, this is what a stack frame display looks like with
4634 @code{set print address on}:
4635
4636 @smallexample
4637 @group
4638 (@value{GDBP}) f
4639 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4640 at input.c:530
4641 530 if (lquote != def_lquote)
4642 @end group
4643 @end smallexample
4644
4645 @item set print address off
4646 Do not print addresses when displaying their contents. For example,
4647 this is the same stack frame displayed with @code{set print address off}:
4648
4649 @smallexample
4650 @group
4651 (@value{GDBP}) set print addr off
4652 (@value{GDBP}) f
4653 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4654 530 if (lquote != def_lquote)
4655 @end group
4656 @end smallexample
4657
4658 You can use @samp{set print address off} to eliminate all machine
4659 dependent displays from the @value{GDBN} interface. For example, with
4660 @code{print address off}, you should get the same text for backtraces on
4661 all machines---whether or not they involve pointer arguments.
4662
4663 @kindex show print address
4664 @item show print address
4665 Show whether or not addresses are to be printed.
4666 @end table
4667
4668 When @value{GDBN} prints a symbolic address, it normally prints the
4669 closest earlier symbol plus an offset. If that symbol does not uniquely
4670 identify the address (for example, it is a name whose scope is a single
4671 source file), you may need to clarify. One way to do this is with
4672 @code{info line}, for example @samp{info line *0x4537}. Alternately,
4673 you can set @value{GDBN} to print the source file and line number when
4674 it prints a symbolic address:
4675
4676 @table @code
4677 @kindex set print symbol-filename
4678 @item set print symbol-filename on
4679 Tell @value{GDBN} to print the source file name and line number of a
4680 symbol in the symbolic form of an address.
4681
4682 @item set print symbol-filename off
4683 Do not print source file name and line number of a symbol. This is the
4684 default.
4685
4686 @kindex show print symbol-filename
4687 @item show print symbol-filename
4688 Show whether or not @value{GDBN} will print the source file name and
4689 line number of a symbol in the symbolic form of an address.
4690 @end table
4691
4692 Another situation where it is helpful to show symbol filenames and line
4693 numbers is when disassembling code; @value{GDBN} shows you the line
4694 number and source file that corresponds to each instruction.
4695
4696 Also, you may wish to see the symbolic form only if the address being
4697 printed is reasonably close to the closest earlier symbol:
4698
4699 @table @code
4700 @kindex set print max-symbolic-offset
4701 @item set print max-symbolic-offset @var{max-offset}
4702 Tell @value{GDBN} to only display the symbolic form of an address if the
4703 offset between the closest earlier symbol and the address is less than
4704 @var{max-offset}. The default is 0, which tells @value{GDBN}
4705 to always print the symbolic form of an address if any symbol precedes it.
4706
4707 @kindex show print max-symbolic-offset
4708 @item show print max-symbolic-offset
4709 Ask how large the maximum offset is that @value{GDBN} prints in a
4710 symbolic address.
4711 @end table
4712
4713 @cindex wild pointer, interpreting
4714 @cindex pointer, finding referent
4715 If you have a pointer and you are not sure where it points, try
4716 @samp{set print symbol-filename on}. Then you can determine the name
4717 and source file location of the variable where it points, using
4718 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4719 For example, here @value{GDBN} shows that a variable @code{ptt} points
4720 at another variable @code{t}, defined in @file{hi2.c}:
4721
4722 @example
4723 (@value{GDBP}) set print symbol-filename on
4724 (@value{GDBP}) p/a ptt
4725 $4 = 0xe008 <t in hi2.c>
4726 @end example
4727
4728 @quotation
4729 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4730 does not show the symbol name and filename of the referent, even with
4731 the appropriate @code{set print} options turned on.
4732 @end quotation
4733
4734 Other settings control how different kinds of objects are printed:
4735
4736 @table @code
4737 @kindex set print array
4738 @item set print array
4739 @itemx set print array on
4740 Pretty print arrays. This format is more convenient to read,
4741 but uses more space. The default is off.
4742
4743 @item set print array off
4744 Return to compressed format for arrays.
4745
4746 @kindex show print array
4747 @item show print array
4748 Show whether compressed or pretty format is selected for displaying
4749 arrays.
4750
4751 @kindex set print elements
4752 @item set print elements @var{number-of-elements}
4753 Set a limit on how many elements of an array @value{GDBN} will print.
4754 If @value{GDBN} is printing a large array, it stops printing after it has
4755 printed the number of elements set by the @code{set print elements} command.
4756 This limit also applies to the display of strings.
4757 When @value{GDBN} starts, this limit is set to 200.
4758 Setting @var{number-of-elements} to zero means that the printing is unlimited.
4759
4760 @kindex show print elements
4761 @item show print elements
4762 Display the number of elements of a large array that @value{GDBN} will print.
4763 If the number is 0, then the printing is unlimited.
4764
4765 @kindex set print null-stop
4766 @item set print null-stop
4767 Cause @value{GDBN} to stop printing the characters of an array when the first
4768 @sc{null} is encountered. This is useful when large arrays actually
4769 contain only short strings.
4770 The default is off.
4771
4772 @kindex set print pretty
4773 @item set print pretty on
4774 Cause @value{GDBN} to print structures in an indented format with one member
4775 per line, like this:
4776
4777 @smallexample
4778 @group
4779 $1 = @{
4780 next = 0x0,
4781 flags = @{
4782 sweet = 1,
4783 sour = 1
4784 @},
4785 meat = 0x54 "Pork"
4786 @}
4787 @end group
4788 @end smallexample
4789
4790 @item set print pretty off
4791 Cause @value{GDBN} to print structures in a compact format, like this:
4792
4793 @smallexample
4794 @group
4795 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
4796 meat = 0x54 "Pork"@}
4797 @end group
4798 @end smallexample
4799
4800 @noindent
4801 This is the default format.
4802
4803 @kindex show print pretty
4804 @item show print pretty
4805 Show which format @value{GDBN} is using to print structures.
4806
4807 @kindex set print sevenbit-strings
4808 @item set print sevenbit-strings on
4809 Print using only seven-bit characters; if this option is set,
4810 @value{GDBN} displays any eight-bit characters (in strings or
4811 character values) using the notation @code{\}@var{nnn}. This setting is
4812 best if you are working in English (@sc{ascii}) and you use the
4813 high-order bit of characters as a marker or ``meta'' bit.
4814
4815 @item set print sevenbit-strings off
4816 Print full eight-bit characters. This allows the use of more
4817 international character sets, and is the default.
4818
4819 @kindex show print sevenbit-strings
4820 @item show print sevenbit-strings
4821 Show whether or not @value{GDBN} is printing only seven-bit characters.
4822
4823 @kindex set print union
4824 @item set print union on
4825 Tell @value{GDBN} to print unions which are contained in structures. This
4826 is the default setting.
4827
4828 @item set print union off
4829 Tell @value{GDBN} not to print unions which are contained in structures.
4830
4831 @kindex show print union
4832 @item show print union
4833 Ask @value{GDBN} whether or not it will print unions which are contained in
4834 structures.
4835
4836 For example, given the declarations
4837
4838 @smallexample
4839 typedef enum @{Tree, Bug@} Species;
4840 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
4841 typedef enum @{Caterpillar, Cocoon, Butterfly@}
4842 Bug_forms;
4843
4844 struct thing @{
4845 Species it;
4846 union @{
4847 Tree_forms tree;
4848 Bug_forms bug;
4849 @} form;
4850 @};
4851
4852 struct thing foo = @{Tree, @{Acorn@}@};
4853 @end smallexample
4854
4855 @noindent
4856 with @code{set print union on} in effect @samp{p foo} would print
4857
4858 @smallexample
4859 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
4860 @end smallexample
4861
4862 @noindent
4863 and with @code{set print union off} in effect it would print
4864
4865 @smallexample
4866 $1 = @{it = Tree, form = @{...@}@}
4867 @end smallexample
4868 @end table
4869
4870 @need 1000
4871 @noindent
4872 These settings are of interest when debugging C++ programs:
4873
4874 @table @code
4875 @cindex demangling
4876 @kindex set print demangle
4877 @item set print demangle
4878 @itemx set print demangle on
4879 Print C++ names in their source form rather than in the encoded
4880 (``mangled'') form passed to the assembler and linker for type-safe
4881 linkage. The default is on.
4882
4883 @kindex show print demangle
4884 @item show print demangle
4885 Show whether C++ names are printed in mangled or demangled form.
4886
4887 @kindex set print asm-demangle
4888 @item set print asm-demangle
4889 @itemx set print asm-demangle on
4890 Print C++ names in their source form rather than their mangled form, even
4891 in assembler code printouts such as instruction disassemblies.
4892 The default is off.
4893
4894 @kindex show print asm-demangle
4895 @item show print asm-demangle
4896 Show whether C++ names in assembly listings are printed in mangled
4897 or demangled form.
4898
4899 @kindex set demangle-style
4900 @cindex C++ symbol decoding style
4901 @cindex symbol decoding style, C++
4902 @item set demangle-style @var{style}
4903 Choose among several encoding schemes used by different compilers to
4904 represent C++ names. The choices for @var{style} are currently:
4905
4906 @table @code
4907 @item auto
4908 Allow @value{GDBN} to choose a decoding style by inspecting your program.
4909
4910 @item gnu
4911 Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
4912 This is the default.
4913
4914 @item hp
4915 Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
4916
4917 @item lucid
4918 Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
4919
4920 @item arm
4921 Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
4922 @strong{Warning:} this setting alone is not sufficient to allow
4923 debugging @code{cfront}-generated executables. @value{GDBN} would
4924 require further enhancement to permit that.
4925
4926 @end table
4927 If you omit @var{style}, you will see a list of possible formats.
4928
4929 @kindex show demangle-style
4930 @item show demangle-style
4931 Display the encoding style currently in use for decoding C++ symbols.
4932
4933 @kindex set print object
4934 @item set print object
4935 @itemx set print object on
4936 When displaying a pointer to an object, identify the @emph{actual}
4937 (derived) type of the object rather than the @emph{declared} type, using
4938 the virtual function table.
4939
4940 @item set print object off
4941 Display only the declared type of objects, without reference to the
4942 virtual function table. This is the default setting.
4943
4944 @kindex show print object
4945 @item show print object
4946 Show whether actual, or declared, object types are displayed.
4947
4948 @kindex set print static-members
4949 @item set print static-members
4950 @itemx set print static-members on
4951 Print static members when displaying a C++ object. The default is on.
4952
4953 @item set print static-members off
4954 Do not print static members when displaying a C++ object.
4955
4956 @kindex show print static-members
4957 @item show print static-members
4958 Show whether C++ static members are printed, or not.
4959
4960 @c These don't work with HP ANSI C++ yet.
4961 @kindex set print vtbl
4962 @item set print vtbl
4963 @itemx set print vtbl on
4964 Pretty print C++ virtual function tables. The default is off.
4965 (The @code{vtbl} commands do not work on programs compiled with the HP
4966 ANSI C++ compiler (@code{aCC}).)
4967
4968 @item set print vtbl off
4969 Do not pretty print C++ virtual function tables.
4970
4971 @kindex show print vtbl
4972 @item show print vtbl
4973 Show whether C++ virtual function tables are pretty printed, or not.
4974 @end table
4975
4976 @node Value History
4977 @section Value history
4978
4979 @cindex value history
4980 Values printed by the @code{print} command are saved in the @value{GDBN}
4981 @dfn{value history}. This allows you to refer to them in other expressions.
4982 Values are kept until the symbol table is re-read or discarded
4983 (for example with the @code{file} or @code{symbol-file} commands).
4984 When the symbol table changes, the value history is discarded,
4985 since the values may contain pointers back to the types defined in the
4986 symbol table.
4987
4988 @cindex @code{$}
4989 @cindex @code{$$}
4990 @cindex history number
4991 The values printed are given @dfn{history numbers} by which you can
4992 refer to them. These are successive integers starting with one.
4993 @code{print} shows you the history number assigned to a value by
4994 printing @samp{$@var{num} = } before the value; here @var{num} is the
4995 history number.
4996
4997 To refer to any previous value, use @samp{$} followed by the value's
4998 history number. The way @code{print} labels its output is designed to
4999 remind you of this. Just @code{$} refers to the most recent value in
5000 the history, and @code{$$} refers to the value before that.
5001 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5002 is the value just prior to @code{$$}, @code{$$1} is equivalent to
5003 @code{$$}, and @code{$$0} is equivalent to @code{$}.
5004
5005 For example, suppose you have just printed a pointer to a structure and
5006 want to see the contents of the structure. It suffices to type
5007
5008 @example
5009 p *$
5010 @end example
5011
5012 If you have a chain of structures where the component @code{next} points
5013 to the next one, you can print the contents of the next one with this:
5014
5015 @example
5016 p *$.next
5017 @end example
5018
5019 @noindent
5020 You can print successive links in the chain by repeating this
5021 command---which you can do by just typing @key{RET}.
5022
5023 Note that the history records values, not expressions. If the value of
5024 @code{x} is 4 and you type these commands:
5025
5026 @example
5027 print x
5028 set x=5
5029 @end example
5030
5031 @noindent
5032 then the value recorded in the value history by the @code{print} command
5033 remains 4 even though the value of @code{x} has changed.
5034
5035 @table @code
5036 @kindex show values
5037 @item show values
5038 Print the last ten values in the value history, with their item numbers.
5039 This is like @samp{p@ $$9} repeated ten times, except that @code{show
5040 values} does not change the history.
5041
5042 @item show values @var{n}
5043 Print ten history values centered on history item number @var{n}.
5044
5045 @item show values +
5046 Print ten history values just after the values last printed. If no more
5047 values are available, @code{show values +} produces no display.
5048 @end table
5049
5050 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5051 same effect as @samp{show values +}.
5052
5053 @node Convenience Vars
5054 @section Convenience variables
5055
5056 @cindex convenience variables
5057 @value{GDBN} provides @dfn{convenience variables} that you can use within
5058 @value{GDBN} to hold on to a value and refer to it later. These variables
5059 exist entirely within @value{GDBN}; they are not part of your program, and
5060 setting a convenience variable has no direct effect on further execution
5061 of your program. That is why you can use them freely.
5062
5063 Convenience variables are prefixed with @samp{$}. Any name preceded by
5064 @samp{$} can be used for a convenience variable, unless it is one of
5065 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
5066 (Value history references, in contrast, are @emph{numbers} preceded
5067 by @samp{$}. @xref{Value History, ,Value history}.)
5068
5069 You can save a value in a convenience variable with an assignment
5070 expression, just as you would set a variable in your program.
5071 For example:
5072
5073 @example
5074 set $foo = *object_ptr
5075 @end example
5076
5077 @noindent
5078 would save in @code{$foo} the value contained in the object pointed to by
5079 @code{object_ptr}.
5080
5081 Using a convenience variable for the first time creates it, but its
5082 value is @code{void} until you assign a new value. You can alter the
5083 value with another assignment at any time.
5084
5085 Convenience variables have no fixed types. You can assign a convenience
5086 variable any type of value, including structures and arrays, even if
5087 that variable already has a value of a different type. The convenience
5088 variable, when used as an expression, has the type of its current value.
5089
5090 @table @code
5091 @kindex show convenience
5092 @item show convenience
5093 Print a list of convenience variables used so far, and their values.
5094 Abbreviated @code{show conv}.
5095 @end table
5096
5097 One of the ways to use a convenience variable is as a counter to be
5098 incremented or a pointer to be advanced. For example, to print
5099 a field from successive elements of an array of structures:
5100
5101 @example
5102 set $i = 0
5103 print bar[$i++]->contents
5104 @end example
5105
5106 @noindent
5107 Repeat that command by typing @key{RET}.
5108
5109 Some convenience variables are created automatically by @value{GDBN} and given
5110 values likely to be useful.
5111
5112 @table @code
5113 @kindex $_
5114 @item $_
5115 The variable @code{$_} is automatically set by the @code{x} command to
5116 the last address examined (@pxref{Memory, ,Examining memory}). Other
5117 commands which provide a default address for @code{x} to examine also
5118 set @code{$_} to that address; these commands include @code{info line}
5119 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5120 except when set by the @code{x} command, in which case it is a pointer
5121 to the type of @code{$__}.
5122
5123 @kindex $__
5124 @item $__
5125 The variable @code{$__} is automatically set by the @code{x} command
5126 to the value found in the last address examined. Its type is chosen
5127 to match the format in which the data was printed.
5128
5129 @item $_exitcode
5130 @kindex $_exitcode
5131 The variable @code{$_exitcode} is automatically set to the exit code when
5132 the program being debugged terminates.
5133 @end table
5134
5135 On HP-UX systems, if you refer to a function or variable name that
5136 begins with a dollar sign, @value{GDBN} searches for a user or system
5137 name first, before it searches for a convenience variable.
5138
5139 @node Registers
5140 @section Registers
5141
5142 @cindex registers
5143 You can refer to machine register contents, in expressions, as variables
5144 with names starting with @samp{$}. The names of registers are different
5145 for each machine; use @code{info registers} to see the names used on
5146 your machine.
5147
5148 @table @code
5149 @kindex info registers
5150 @item info registers
5151 Print the names and values of all registers except floating-point
5152 registers (in the selected stack frame).
5153
5154 @kindex info all-registers
5155 @cindex floating point registers
5156 @item info all-registers
5157 Print the names and values of all registers, including floating-point
5158 registers.
5159
5160 @item info registers @var{regname} @dots{}
5161 Print the @dfn{relativized} value of each specified register @var{regname}.
5162 As discussed in detail below, register values are normally relative to
5163 the selected stack frame. @var{regname} may be any register name valid on
5164 the machine you are using, with or without the initial @samp{$}.
5165 @end table
5166
5167 @value{GDBN} has four ``standard'' register names that are available (in
5168 expressions) on most machines---whenever they do not conflict with an
5169 architecture's canonical mnemonics for registers. The register names
5170 @code{$pc} and @code{$sp} are used for the program counter register and
5171 the stack pointer. @code{$fp} is used for a register that contains a
5172 pointer to the current stack frame, and @code{$ps} is used for a
5173 register that contains the processor status. For example,
5174 you could print the program counter in hex with
5175
5176 @example
5177 p/x $pc
5178 @end example
5179
5180 @noindent
5181 or print the instruction to be executed next with
5182
5183 @example
5184 x/i $pc
5185 @end example
5186
5187 @noindent
5188 or add four to the stack pointer@footnote{This is a way of removing
5189 one word from the stack, on machines where stacks grow downward in
5190 memory (most machines, nowadays). This assumes that the innermost
5191 stack frame is selected; setting @code{$sp} is not allowed when other
5192 stack frames are selected. To pop entire frames off the stack,
5193 regardless of machine architecture, use @code{return};
5194 see @ref{Returning, ,Returning from a function}.} with
5195
5196 @example
5197 set $sp += 4
5198 @end example
5199
5200 Whenever possible, these four standard register names are available on
5201 your machine even though the machine has different canonical mnemonics,
5202 so long as there is no conflict. The @code{info registers} command
5203 shows the canonical names. For example, on the SPARC, @code{info
5204 registers} displays the processor status register as @code{$psr} but you
5205 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5206 is an alias for the @sc{eflags} register.
5207
5208 @value{GDBN} always considers the contents of an ordinary register as an
5209 integer when the register is examined in this way. Some machines have
5210 special registers which can hold nothing but floating point; these
5211 registers are considered to have floating point values. There is no way
5212 to refer to the contents of an ordinary register as floating point value
5213 (although you can @emph{print} it as a floating point value with
5214 @samp{print/f $@var{regname}}).
5215
5216 Some registers have distinct ``raw'' and ``virtual'' data formats. This
5217 means that the data format in which the register contents are saved by
5218 the operating system is not the same one that your program normally
5219 sees. For example, the registers of the 68881 floating point
5220 coprocessor are always saved in ``extended'' (raw) format, but all C
5221 programs expect to work with ``double'' (virtual) format. In such
5222 cases, @value{GDBN} normally works with the virtual format only (the format
5223 that makes sense for your program), but the @code{info registers} command
5224 prints the data in both formats.
5225
5226 Normally, register values are relative to the selected stack frame
5227 (@pxref{Selection, ,Selecting a frame}). This means that you get the
5228 value that the register would contain if all stack frames farther in
5229 were exited and their saved registers restored. In order to see the
5230 true contents of hardware registers, you must select the innermost
5231 frame (with @samp{frame 0}).
5232
5233 However, @value{GDBN} must deduce where registers are saved, from the machine
5234 code generated by your compiler. If some registers are not saved, or if
5235 @value{GDBN} is unable to locate the saved registers, the selected stack
5236 frame makes no difference.
5237
5238 @node Floating Point Hardware
5239 @section Floating point hardware
5240 @cindex floating point
5241
5242 Depending on the configuration, @value{GDBN} may be able to give
5243 you more information about the status of the floating point hardware.
5244
5245 @table @code
5246 @kindex info float
5247 @item info float
5248 Display hardware-dependent information about the floating
5249 point unit. The exact contents and layout vary depending on the
5250 floating point chip. Currently, @samp{info float} is supported on
5251 the ARM and x86 machines.
5252 @end table
5253
5254 @node Languages
5255 @chapter Using @value{GDBN} with Different Languages
5256 @cindex languages
5257
5258 Although programming languages generally have common aspects, they are
5259 rarely expressed in the same manner. For instance, in ANSI C,
5260 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5261 Modula-2, it is accomplished by @code{p^}. Values can also be
5262 represented (and displayed) differently. Hex numbers in C appear as
5263 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
5264
5265 @cindex working language
5266 Language-specific information is built into @value{GDBN} for some languages,
5267 allowing you to express operations like the above in your program's
5268 native language, and allowing @value{GDBN} to output values in a manner
5269 consistent with the syntax of your program's native language. The
5270 language you use to build expressions is called the @dfn{working
5271 language}.
5272
5273 @menu
5274 * Setting:: Switching between source languages
5275 * Show:: Displaying the language
5276 * Checks:: Type and range checks
5277 * Support:: Supported languages
5278 @end menu
5279
5280 @node Setting
5281 @section Switching between source languages
5282
5283 There are two ways to control the working language---either have @value{GDBN}
5284 set it automatically, or select it manually yourself. You can use the
5285 @code{set language} command for either purpose. On startup, @value{GDBN}
5286 defaults to setting the language automatically. The working language is
5287 used to determine how expressions you type are interpreted, how values
5288 are printed, etc.
5289
5290 In addition to the working language, every source file that
5291 @value{GDBN} knows about has its own working language. For some object
5292 file formats, the compiler might indicate which language a particular
5293 source file is in. However, most of the time @value{GDBN} infers the
5294 language from the name of the file. The language of a source file
5295 controls whether C++ names are demangled---this way @code{backtrace} can
5296 show each frame appropriately for its own language. There is no way to
5297 set the language of a source file from within @value{GDBN}, but you can
5298 set the language associated with a filename extension. @xref{Show, ,
5299 Displaying the language}.
5300
5301 This is most commonly a problem when you use a program, such
5302 as @code{cfront} or @code{f2c}, that generates C but is written in
5303 another language. In that case, make the
5304 program use @code{#line} directives in its C output; that way
5305 @value{GDBN} will know the correct language of the source code of the original
5306 program, and will display that source code, not the generated C code.
5307
5308 @menu
5309 * Filenames:: Filename extensions and languages.
5310 * Manually:: Setting the working language manually
5311 * Automatically:: Having @value{GDBN} infer the source language
5312 @end menu
5313
5314 @node Filenames
5315 @subsection List of filename extensions and languages
5316
5317 If a source file name ends in one of the following extensions, then
5318 @value{GDBN} infers that its language is the one indicated.
5319
5320 @table @file
5321
5322 @item .c
5323 C source file
5324
5325 @item .C
5326 @itemx .cc
5327 @itemx .cp
5328 @itemx .cpp
5329 @itemx .cxx
5330 @itemx .c++
5331 C++ source file
5332
5333 @item .f
5334 @itemx .F
5335 Fortran source file
5336
5337 @item .ch
5338 @itemx .c186
5339 @itemx .c286
5340 CHILL source file.
5341
5342 @item .mod
5343 Modula-2 source file
5344
5345 @item .s
5346 @itemx .S
5347 Assembler source file. This actually behaves almost like C, but
5348 @value{GDBN} does not skip over function prologues when stepping.
5349 @end table
5350
5351 In addition, you may set the language associated with a filename
5352 extension. @xref{Show, , Displaying the language}.
5353
5354 @node Manually
5355 @subsection Setting the working language
5356
5357 If you allow @value{GDBN} to set the language automatically,
5358 expressions are interpreted the same way in your debugging session and
5359 your program.
5360
5361 @kindex set language
5362 If you wish, you may set the language manually. To do this, issue the
5363 command @samp{set language @var{lang}}, where @var{lang} is the name of
5364 a language, such as
5365 @code{c} or @code{modula-2}.
5366 For a list of the supported languages, type @samp{set language}.
5367
5368 Setting the language manually prevents @value{GDBN} from updating the working
5369 language automatically. This can lead to confusion if you try
5370 to debug a program when the working language is not the same as the
5371 source language, when an expression is acceptable to both
5372 languages---but means different things. For instance, if the current
5373 source file were written in C, and @value{GDBN} was parsing Modula-2, a
5374 command such as:
5375
5376 @example
5377 print a = b + c
5378 @end example
5379
5380 @noindent
5381 might not have the effect you intended. In C, this means to add
5382 @code{b} and @code{c} and place the result in @code{a}. The result
5383 printed would be the value of @code{a}. In Modula-2, this means to compare
5384 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
5385
5386 @node Automatically
5387 @subsection Having @value{GDBN} infer the source language
5388
5389 To have @value{GDBN} set the working language automatically, use
5390 @samp{set language local} or @samp{set language auto}. @value{GDBN}
5391 then infers the working language. That is, when your program stops in a
5392 frame (usually by encountering a breakpoint), @value{GDBN} sets the
5393 working language to the language recorded for the function in that
5394 frame. If the language for a frame is unknown (that is, if the function
5395 or block corresponding to the frame was defined in a source file that
5396 does not have a recognized extension), the current working language is
5397 not changed, and @value{GDBN} issues a warning.
5398
5399 This may not seem necessary for most programs, which are written
5400 entirely in one source language. However, program modules and libraries
5401 written in one source language can be used by a main program written in
5402 a different source language. Using @samp{set language auto} in this
5403 case frees you from having to set the working language manually.
5404
5405 @node Show
5406 @section Displaying the language
5407
5408 The following commands help you find out which language is the
5409 working language, and also what language source files were written in.
5410
5411 @kindex show language
5412 @kindex info frame@r{, show the source language}
5413 @kindex info source@r{, show the source language}
5414 @table @code
5415 @item show language
5416 Display the current working language. This is the
5417 language you can use with commands such as @code{print} to
5418 build and compute expressions that may involve variables in your program.
5419
5420 @item info frame
5421 Display the source language for this frame. This language becomes the
5422 working language if you use an identifier from this frame.
5423 @xref{Frame Info, ,Information about a frame}, to identify the other
5424 information listed here.
5425
5426 @item info source
5427 Display the source language of this source file.
5428 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
5429 information listed here.
5430 @end table
5431
5432 In unusual circumstances, you may have source files with extensions
5433 not in the standard list. You can then set the extension associated
5434 with a language explicitly:
5435
5436 @kindex set extension-language
5437 @kindex info extensions
5438 @table @code
5439 @item set extension-language @var{.ext} @var{language}
5440 Set source files with extension @var{.ext} to be assumed to be in
5441 the source language @var{language}.
5442
5443 @item info extensions
5444 List all the filename extensions and the associated languages.
5445 @end table
5446
5447 @node Checks
5448 @section Type and range checking
5449
5450 @quotation
5451 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
5452 checking are included, but they do not yet have any effect. This
5453 section documents the intended facilities.
5454 @end quotation
5455 @c FIXME remove warning when type/range code added
5456
5457 Some languages are designed to guard you against making seemingly common
5458 errors through a series of compile- and run-time checks. These include
5459 checking the type of arguments to functions and operators, and making
5460 sure mathematical overflows are caught at run time. Checks such as
5461 these help to ensure a program's correctness once it has been compiled
5462 by eliminating type mismatches, and providing active checks for range
5463 errors when your program is running.
5464
5465 @value{GDBN} can check for conditions like the above if you wish.
5466 Although @value{GDBN} does not check the statements in your program, it
5467 can check expressions entered directly into @value{GDBN} for evaluation via
5468 the @code{print} command, for example. As with the working language,
5469 @value{GDBN} can also decide whether or not to check automatically based on
5470 your program's source language. @xref{Support, ,Supported languages},
5471 for the default settings of supported languages.
5472
5473 @menu
5474 * Type Checking:: An overview of type checking
5475 * Range Checking:: An overview of range checking
5476 @end menu
5477
5478 @cindex type checking
5479 @cindex checks, type
5480 @node Type Checking
5481 @subsection An overview of type checking
5482
5483 Some languages, such as Modula-2, are strongly typed, meaning that the
5484 arguments to operators and functions have to be of the correct type,
5485 otherwise an error occurs. These checks prevent type mismatch
5486 errors from ever causing any run-time problems. For example,
5487
5488 @smallexample
5489 1 + 2 @result{} 3
5490 @exdent but
5491 @error{} 1 + 2.3
5492 @end smallexample
5493
5494 The second example fails because the @code{CARDINAL} 1 is not
5495 type-compatible with the @code{REAL} 2.3.
5496
5497 For the expressions you use in @value{GDBN} commands, you can tell the
5498 @value{GDBN} type checker to skip checking;
5499 to treat any mismatches as errors and abandon the expression;
5500 or to only issue warnings when type mismatches occur,
5501 but evaluate the expression anyway. When you choose the last of
5502 these, @value{GDBN} evaluates expressions like the second example above, but
5503 also issues a warning.
5504
5505 Even if you turn type checking off, there may be other reasons
5506 related to type that prevent @value{GDBN} from evaluating an expression.
5507 For instance, @value{GDBN} does not know how to add an @code{int} and
5508 a @code{struct foo}. These particular type errors have nothing to do
5509 with the language in use, and usually arise from expressions, such as
5510 the one described above, which make little sense to evaluate anyway.
5511
5512 Each language defines to what degree it is strict about type. For
5513 instance, both Modula-2 and C require the arguments to arithmetical
5514 operators to be numbers. In C, enumerated types and pointers can be
5515 represented as numbers, so that they are valid arguments to mathematical
5516 operators. @xref{Support, ,Supported languages}, for further
5517 details on specific languages.
5518
5519 @value{GDBN} provides some additional commands for controlling the type checker:
5520
5521 @kindex set check@r{, type}
5522 @kindex set check type
5523 @kindex show check type
5524 @table @code
5525 @item set check type auto
5526 Set type checking on or off based on the current working language.
5527 @xref{Support, ,Supported languages}, for the default settings for
5528 each language.
5529
5530 @item set check type on
5531 @itemx set check type off
5532 Set type checking on or off, overriding the default setting for the
5533 current working language. Issue a warning if the setting does not
5534 match the language default. If any type mismatches occur in
5535 evaluating an expression while type checking is on, @value{GDBN} prints a
5536 message and aborts evaluation of the expression.
5537
5538 @item set check type warn
5539 Cause the type checker to issue warnings, but to always attempt to
5540 evaluate the expression. Evaluating the expression may still
5541 be impossible for other reasons. For example, @value{GDBN} cannot add
5542 numbers and structures.
5543
5544 @item show type
5545 Show the current setting of the type checker, and whether or not @value{GDBN}
5546 is setting it automatically.
5547 @end table
5548
5549 @cindex range checking
5550 @cindex checks, range
5551 @node Range Checking
5552 @subsection An overview of range checking
5553
5554 In some languages (such as Modula-2), it is an error to exceed the
5555 bounds of a type; this is enforced with run-time checks. Such range
5556 checking is meant to ensure program correctness by making sure
5557 computations do not overflow, or indices on an array element access do
5558 not exceed the bounds of the array.
5559
5560 For expressions you use in @value{GDBN} commands, you can tell
5561 @value{GDBN} to treat range errors in one of three ways: ignore them,
5562 always treat them as errors and abandon the expression, or issue
5563 warnings but evaluate the expression anyway.
5564
5565 A range error can result from numerical overflow, from exceeding an
5566 array index bound, or when you type a constant that is not a member
5567 of any type. Some languages, however, do not treat overflows as an
5568 error. In many implementations of C, mathematical overflow causes the
5569 result to ``wrap around'' to lower values---for example, if @var{m} is
5570 the largest integer value, and @var{s} is the smallest, then
5571
5572 @example
5573 @var{m} + 1 @result{} @var{s}
5574 @end example
5575
5576 This, too, is specific to individual languages, and in some cases
5577 specific to individual compilers or machines. @xref{Support, ,
5578 Supported languages}, for further details on specific languages.
5579
5580 @value{GDBN} provides some additional commands for controlling the range checker:
5581
5582 @kindex set check@r{, range}
5583 @kindex set check range
5584 @kindex show check range
5585 @table @code
5586 @item set check range auto
5587 Set range checking on or off based on the current working language.
5588 @xref{Support, ,Supported languages}, for the default settings for
5589 each language.
5590
5591 @item set check range on
5592 @itemx set check range off
5593 Set range checking on or off, overriding the default setting for the
5594 current working language. A warning is issued if the setting does not
5595 match the language default. If a range error occurs, then a message
5596 is printed and evaluation of the expression is aborted.
5597
5598 @item set check range warn
5599 Output messages when the @value{GDBN} range checker detects a range error,
5600 but attempt to evaluate the expression anyway. Evaluating the
5601 expression may still be impossible for other reasons, such as accessing
5602 memory that the process does not own (a typical example from many Unix
5603 systems).
5604
5605 @item show range
5606 Show the current setting of the range checker, and whether or not it is
5607 being set automatically by @value{GDBN}.
5608 @end table
5609
5610 @node Support
5611 @section Supported languages
5612
5613 @value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5614 @c This is false ...
5615 Some @value{GDBN} features may be used in expressions regardless of the
5616 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5617 and the @samp{@{type@}addr} construct (@pxref{Expressions,
5618 ,Expressions}) can be used with the constructs of any supported
5619 language.
5620
5621 The following sections detail to what degree each source language is
5622 supported by @value{GDBN}. These sections are not meant to be language
5623 tutorials or references, but serve only as a reference guide to what the
5624 @value{GDBN} expression parser accepts, and what input and output
5625 formats should look like for different languages. There are many good
5626 books written on each of these languages; please look to these for a
5627 language reference or tutorial.
5628
5629 @menu
5630 * C:: C and C++
5631 * Modula-2:: Modula-2
5632 * Chill:: Chill
5633 @end menu
5634
5635 @node C
5636 @subsection C and C++
5637
5638 @cindex C and C++
5639 @cindex expressions in C or C++
5640
5641 Since C and C++ are so closely related, many features of @value{GDBN} apply
5642 to both languages. Whenever this is the case, we discuss those languages
5643 together.
5644
5645 @cindex C++
5646 @kindex g++
5647 @cindex @sc{gnu} C++
5648 The C++ debugging facilities are jointly implemented by the C++
5649 compiler and @value{GDBN}. Therefore, to debug your C++ code
5650 effectively, you must compile your C++ programs with a supported
5651 C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5652 compiler (@code{aCC}).
5653
5654 For best results when using @sc{gnu} C++, use the stabs debugging
5655 format. You can select that format explicitly with the @code{g++}
5656 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5657 @ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5658 CC, gcc.info, Using @sc{gnu} CC}, for more information.
5659
5660 @menu
5661 * C Operators:: C and C++ operators
5662 * C Constants:: C and C++ constants
5663 * C plus plus expressions:: C++ expressions
5664 * C Defaults:: Default settings for C and C++
5665 * C Checks:: C and C++ type and range checks
5666 * Debugging C:: @value{GDBN} and C
5667 * Debugging C plus plus:: @value{GDBN} features for C++
5668 @end menu
5669
5670 @node C Operators
5671 @subsubsection C and C++ operators
5672
5673 @cindex C and C++ operators
5674
5675 Operators must be defined on values of specific types. For instance,
5676 @code{+} is defined on numbers, but not on structures. Operators are
5677 often defined on groups of types.
5678
5679 For the purposes of C and C++, the following definitions hold:
5680
5681 @itemize @bullet
5682
5683 @item
5684 @emph{Integral types} include @code{int} with any of its storage-class
5685 specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
5686
5687 @item
5688 @emph{Floating-point types} include @code{float}, @code{double}, and
5689 @code{long double} (if supported by the target platform).
5690
5691 @item
5692 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
5693
5694 @item
5695 @emph{Scalar types} include all of the above.
5696
5697 @end itemize
5698
5699 @noindent
5700 The following operators are supported. They are listed here
5701 in order of increasing precedence:
5702
5703 @table @code
5704 @item ,
5705 The comma or sequencing operator. Expressions in a comma-separated list
5706 are evaluated from left to right, with the result of the entire
5707 expression being the last expression evaluated.
5708
5709 @item =
5710 Assignment. The value of an assignment expression is the value
5711 assigned. Defined on scalar types.
5712
5713 @item @var{op}=
5714 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5715 and translated to @w{@code{@var{a} = @var{a op b}}}.
5716 @w{@code{@var{op}=}} and @code{=} have the same precedence.
5717 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5718 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5719
5720 @item ?:
5721 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5722 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5723 integral type.
5724
5725 @item ||
5726 Logical @sc{or}. Defined on integral types.
5727
5728 @item &&
5729 Logical @sc{and}. Defined on integral types.
5730
5731 @item |
5732 Bitwise @sc{or}. Defined on integral types.
5733
5734 @item ^
5735 Bitwise exclusive-@sc{or}. Defined on integral types.
5736
5737 @item &
5738 Bitwise @sc{and}. Defined on integral types.
5739
5740 @item ==@r{, }!=
5741 Equality and inequality. Defined on scalar types. The value of these
5742 expressions is 0 for false and non-zero for true.
5743
5744 @item <@r{, }>@r{, }<=@r{, }>=
5745 Less than, greater than, less than or equal, greater than or equal.
5746 Defined on scalar types. The value of these expressions is 0 for false
5747 and non-zero for true.
5748
5749 @item <<@r{, }>>
5750 left shift, and right shift. Defined on integral types.
5751
5752 @item @@
5753 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5754
5755 @item +@r{, }-
5756 Addition and subtraction. Defined on integral types, floating-point types and
5757 pointer types.
5758
5759 @item *@r{, }/@r{, }%
5760 Multiplication, division, and modulus. Multiplication and division are
5761 defined on integral and floating-point types. Modulus is defined on
5762 integral types.
5763
5764 @item ++@r{, }--
5765 Increment and decrement. When appearing before a variable, the
5766 operation is performed before the variable is used in an expression;
5767 when appearing after it, the variable's value is used before the
5768 operation takes place.
5769
5770 @item *
5771 Pointer dereferencing. Defined on pointer types. Same precedence as
5772 @code{++}.
5773
5774 @item &
5775 Address operator. Defined on variables. Same precedence as @code{++}.
5776
5777 For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
5778 allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
5779 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
5780 where a C++ reference variable (declared with @samp{&@var{ref}}) is
5781 stored.
5782
5783 @item -
5784 Negative. Defined on integral and floating-point types. Same
5785 precedence as @code{++}.
5786
5787 @item !
5788 Logical negation. Defined on integral types. Same precedence as
5789 @code{++}.
5790
5791 @item ~
5792 Bitwise complement operator. Defined on integral types. Same precedence as
5793 @code{++}.
5794
5795
5796 @item .@r{, }->
5797 Structure member, and pointer-to-structure member. For convenience,
5798 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
5799 pointer based on the stored type information.
5800 Defined on @code{struct} and @code{union} data.
5801
5802 @item .*@r{, }->*
5803 Dereferences of pointers to members.
5804
5805 @item []
5806 Array indexing. @code{@var{a}[@var{i}]} is defined as
5807 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
5808
5809 @item ()
5810 Function parameter list. Same precedence as @code{->}.
5811
5812 @item ::
5813 C++ scope resolution operator. Defined on @code{struct}, @code{union},
5814 and @code{class} types.
5815
5816 @item ::
5817 Doubled colons also represent the @value{GDBN} scope operator
5818 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
5819 above.
5820 @end table
5821
5822 If an operator is redefined in the user code, @value{GDBN} usually
5823 attempts to invoke the redefined version instead of using the operator's
5824 predefined meaning.
5825
5826 @menu
5827 * C Constants::
5828 @end menu
5829
5830 @node C Constants
5831 @subsubsection C and C++ constants
5832
5833 @cindex C and C++ constants
5834
5835 @value{GDBN} allows you to express the constants of C and C++ in the
5836 following ways:
5837
5838 @itemize @bullet
5839 @item
5840 Integer constants are a sequence of digits. Octal constants are
5841 specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
5842 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
5843 @samp{l}, specifying that the constant should be treated as a
5844 @code{long} value.
5845
5846 @item
5847 Floating point constants are a sequence of digits, followed by a decimal
5848 point, followed by a sequence of digits, and optionally followed by an
5849 exponent. An exponent is of the form:
5850 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
5851 sequence of digits. The @samp{+} is optional for positive exponents.
5852 A floating-point constant may also end with a letter @samp{f} or
5853 @samp{F}, specifying that the constant should be treated as being of
5854 the @code{float} (as opposed to the default @code{double}) type; or with
5855 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
5856 constant.
5857
5858 @item
5859 Enumerated constants consist of enumerated identifiers, or their
5860 integral equivalents.
5861
5862 @item
5863 Character constants are a single character surrounded by single quotes
5864 (@code{'}), or a number---the ordinal value of the corresponding character
5865 (usually its @sc{ascii} value). Within quotes, the single character may
5866 be represented by a letter or by @dfn{escape sequences}, which are of
5867 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
5868 of the character's ordinal value; or of the form @samp{\@var{x}}, where
5869 @samp{@var{x}} is a predefined special character---for example,
5870 @samp{\n} for newline.
5871
5872 @item
5873 String constants are a sequence of character constants surrounded
5874 by double quotes (@code{"}).
5875
5876 @item
5877 Pointer constants are an integral value. You can also write pointers
5878 to constants using the C operator @samp{&}.
5879
5880 @item
5881 Array constants are comma-separated lists surrounded by braces @samp{@{}
5882 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
5883 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
5884 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
5885 @end itemize
5886
5887 @menu
5888 * C plus plus expressions::
5889 * C Defaults::
5890 * C Checks::
5891
5892 * Debugging C::
5893 @end menu
5894
5895 @node C plus plus expressions
5896 @subsubsection C++ expressions
5897
5898 @cindex expressions in C++
5899 @value{GDBN} expression handling can interpret most C++ expressions.
5900
5901 @cindex C++ support, not in @sc{coff}
5902 @cindex @sc{coff} versus C++
5903 @cindex C++ and object formats
5904 @cindex object formats and C++
5905 @cindex a.out and C++
5906 @cindex @sc{ecoff} and C++
5907 @cindex @sc{xcoff} and C++
5908 @cindex @sc{elf}/stabs and C++
5909 @cindex @sc{elf}/@sc{dwarf} and C++
5910 @c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
5911 @c periodically whether this has happened...
5912 @quotation
5913 @emph{Warning:} @value{GDBN} can only debug C++ code if you use the
5914 proper compiler. Typically, C++ debugging depends on the use of
5915 additional debugging information in the symbol table, and thus requires
5916 special support. In particular, if your compiler generates a.out, MIPS
5917 @sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
5918 symbol table, these facilities are all available. (With @sc{gnu} CC,
5919 you can use the @samp{-gstabs} option to request stabs debugging
5920 extensions explicitly.) Where the object code format is standard
5921 @sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
5922 support in @value{GDBN} does @emph{not} work.
5923 @end quotation
5924
5925 @enumerate
5926
5927 @cindex member functions
5928 @item
5929 Member function calls are allowed; you can use expressions like
5930
5931 @example
5932 count = aml->GetOriginal(x, y)
5933 @end example
5934
5935 @kindex this
5936 @cindex namespace in C++
5937 @item
5938 While a member function is active (in the selected stack frame), your
5939 expressions have the same namespace available as the member function;
5940 that is, @value{GDBN} allows implicit references to the class instance
5941 pointer @code{this} following the same rules as C++.
5942
5943 @cindex call overloaded functions
5944 @cindex overloaded functions, calling
5945 @cindex type conversions in C++
5946 @item
5947 You can call overloaded functions; @value{GDBN} resolves the function
5948 call to the right definition, with some restrictions. @value{GDBN} does not
5949 perform overload resolution involving user-defined type conversions,
5950 calls to constructors, or instantiations of templates that do not exist
5951 in the program. It also cannot handle ellipsis argument lists or
5952 default arguments.
5953
5954 It does perform integral conversions and promotions, floating-point
5955 promotions, arithmetic conversions, pointer conversions, conversions of
5956 class objects to base classes, and standard conversions such as those of
5957 functions or arrays to pointers; it requires an exact match on the
5958 number of function arguments.
5959
5960 Overload resolution is always performed, unless you have specified
5961 @code{set overload-resolution off}. @xref{Debugging C plus plus,
5962 ,@value{GDBN} features for C++}.
5963
5964 You must specify @code{set overload-resolution off} in order to use an
5965 explicit function signature to call an overloaded function, as in
5966 @smallexample
5967 p 'foo(char,int)'('x', 13)
5968 @end smallexample
5969
5970 The @value{GDBN} command-completion facility can simplify this;
5971 see @ref{Completion, ,Command completion}.
5972
5973 @cindex reference declarations
5974 @item
5975 @value{GDBN} understands variables declared as C++ references; you can use
5976 them in expressions just as you do in C++ source---they are automatically
5977 dereferenced.
5978
5979 In the parameter list shown when @value{GDBN} displays a frame, the values of
5980 reference variables are not displayed (unlike other variables); this
5981 avoids clutter, since references are often used for large structures.
5982 The @emph{address} of a reference variable is always shown, unless
5983 you have specified @samp{set print address off}.
5984
5985 @item
5986 @value{GDBN} supports the C++ name resolution operator @code{::}---your
5987 expressions can use it just as expressions in your program do. Since
5988 one scope may be defined in another, you can use @code{::} repeatedly if
5989 necessary, for example in an expression like
5990 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
5991 resolving name scope by reference to source files, in both C and C++
5992 debugging (@pxref{Variables, ,Program variables}).
5993 @end enumerate
5994
5995 In addition, when used with HP's C++ compiler, @value{GDBN} supports
5996 calling virtual functions correctly, printing out virtual bases of
5997 objects, calling functions in a base subobject, casting objects, and
5998 invoking user-defined operators.
5999
6000 @node C Defaults
6001 @subsubsection C and C++ defaults
6002
6003 @cindex C and C++ defaults
6004
6005 If you allow @value{GDBN} to set type and range checking automatically, they
6006 both default to @code{off} whenever the working language changes to
6007 C or C++. This happens regardless of whether you or @value{GDBN}
6008 selects the working language.
6009
6010 If you allow @value{GDBN} to set the language automatically, it
6011 recognizes source files whose names end with @file{.c}, @file{.C}, or
6012 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6013 these files, it sets the working language to C or C++.
6014 @xref{Automatically, ,Having @value{GDBN} infer the source language},
6015 for further details.
6016
6017 @c Type checking is (a) primarily motivated by Modula-2, and (b)
6018 @c unimplemented. If (b) changes, it might make sense to let this node
6019 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
6020
6021 @node C Checks
6022 @subsubsection C and C++ type and range checks
6023
6024 @cindex C and C++ checks
6025
6026 By default, when @value{GDBN} parses C or C++ expressions, type checking
6027 is not used. However, if you turn type checking on, @value{GDBN}
6028 considers two variables type equivalent if:
6029
6030 @itemize @bullet
6031 @item
6032 The two variables are structured and have the same structure, union, or
6033 enumerated tag.
6034
6035 @item
6036 The two variables have the same type name, or types that have been
6037 declared equivalent through @code{typedef}.
6038
6039 @ignore
6040 @c leaving this out because neither J Gilmore nor R Pesch understand it.
6041 @c FIXME--beers?
6042 @item
6043 The two @code{struct}, @code{union}, or @code{enum} variables are
6044 declared in the same declaration. (Note: this may not be true for all C
6045 compilers.)
6046 @end ignore
6047 @end itemize
6048
6049 Range checking, if turned on, is done on mathematical operations. Array
6050 indices are not checked, since they are often used to index a pointer
6051 that is not itself an array.
6052
6053 @node Debugging C
6054 @subsubsection @value{GDBN} and C
6055
6056 The @code{set print union} and @code{show print union} commands apply to
6057 the @code{union} type. When set to @samp{on}, any @code{union} that is
6058 inside a @code{struct} or @code{class} is also printed. Otherwise, it
6059 appears as @samp{@{...@}}.
6060
6061 The @code{@@} operator aids in the debugging of dynamic arrays, formed
6062 with pointers and a memory allocation function. @xref{Expressions,
6063 ,Expressions}.
6064
6065 @menu
6066 * Debugging C plus plus::
6067 @end menu
6068
6069 @node Debugging C plus plus
6070 @subsubsection @value{GDBN} features for C++
6071
6072 @cindex commands for C++
6073
6074 Some @value{GDBN} commands are particularly useful with C++, and some are
6075 designed specifically for use with C++. Here is a summary:
6076
6077 @table @code
6078 @cindex break in overloaded functions
6079 @item @r{breakpoint menus}
6080 When you want a breakpoint in a function whose name is overloaded,
6081 @value{GDBN} breakpoint menus help you specify which function definition
6082 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6083
6084 @cindex overloading in C++
6085 @item rbreak @var{regex}
6086 Setting breakpoints using regular expressions is helpful for setting
6087 breakpoints on overloaded functions that are not members of any special
6088 classes.
6089 @xref{Set Breaks, ,Setting breakpoints}.
6090
6091 @cindex C++ exception handling
6092 @item catch throw
6093 @itemx catch catch
6094 Debug C++ exception handling using these commands. @xref{Set
6095 Catchpoints, , Setting catchpoints}.
6096
6097 @cindex inheritance
6098 @item ptype @var{typename}
6099 Print inheritance relationships as well as other information for type
6100 @var{typename}.
6101 @xref{Symbols, ,Examining the Symbol Table}.
6102
6103 @cindex C++ symbol display
6104 @item set print demangle
6105 @itemx show print demangle
6106 @itemx set print asm-demangle
6107 @itemx show print asm-demangle
6108 Control whether C++ symbols display in their source form, both when
6109 displaying code as C++ source and when displaying disassemblies.
6110 @xref{Print Settings, ,Print settings}.
6111
6112 @item set print object
6113 @itemx show print object
6114 Choose whether to print derived (actual) or declared types of objects.
6115 @xref{Print Settings, ,Print settings}.
6116
6117 @item set print vtbl
6118 @itemx show print vtbl
6119 Control the format for printing virtual function tables.
6120 @xref{Print Settings, ,Print settings}.
6121 (The @code{vtbl} commands do not work on programs compiled with the HP
6122 ANSI C++ compiler (@code{aCC}).)
6123
6124 @kindex set overload-resolution
6125 @cindex overloaded functions, overload resolution
6126 @item set overload-resolution on
6127 Enable overload resolution for C++ expression evaluation. The default
6128 is on. For overloaded functions, @value{GDBN} evaluates the arguments
6129 and searches for a function whose signature matches the argument types,
6130 using the standard C++ conversion rules (see @ref{C plus plus expressions, ,C++
6131 expressions}, for details). If it cannot find a match, it emits a
6132 message.
6133
6134 @item set overload-resolution off
6135 Disable overload resolution for C++ expression evaluation. For
6136 overloaded functions that are not class member functions, @value{GDBN}
6137 chooses the first function of the specified name that it finds in the
6138 symbol table, whether or not its arguments are of the correct type. For
6139 overloaded functions that are class member functions, @value{GDBN}
6140 searches for a function whose signature @emph{exactly} matches the
6141 argument types.
6142
6143 @item @r{Overloaded symbol names}
6144 You can specify a particular definition of an overloaded symbol, using
6145 the same notation that is used to declare such symbols in C++: type
6146 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6147 also use the @value{GDBN} command-line word completion facilities to list the
6148 available choices, or to finish the type list for you.
6149 @xref{Completion,, Command completion}, for details on how to do this.
6150 @end table
6151
6152 @node Modula-2
6153 @subsection Modula-2
6154
6155 @cindex Modula-2, @value{GDBN} support
6156
6157 The extensions made to @value{GDBN} to support Modula-2 only support
6158 output from the @sc{gnu} Modula-2 compiler (which is currently being
6159 developed). Other Modula-2 compilers are not currently supported, and
6160 attempting to debug executables produced by them is most likely
6161 to give an error as @value{GDBN} reads in the executable's symbol
6162 table.
6163
6164 @cindex expressions in Modula-2
6165 @menu
6166 * M2 Operators:: Built-in operators
6167 * Built-In Func/Proc:: Built-in functions and procedures
6168 * M2 Constants:: Modula-2 constants
6169 * M2 Defaults:: Default settings for Modula-2
6170 * Deviations:: Deviations from standard Modula-2
6171 * M2 Checks:: Modula-2 type and range checks
6172 * M2 Scope:: The scope operators @code{::} and @code{.}
6173 * GDB/M2:: @value{GDBN} and Modula-2
6174 @end menu
6175
6176 @node M2 Operators
6177 @subsubsection Operators
6178 @cindex Modula-2 operators
6179
6180 Operators must be defined on values of specific types. For instance,
6181 @code{+} is defined on numbers, but not on structures. Operators are
6182 often defined on groups of types. For the purposes of Modula-2, the
6183 following definitions hold:
6184
6185 @itemize @bullet
6186
6187 @item
6188 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6189 their subranges.
6190
6191 @item
6192 @emph{Character types} consist of @code{CHAR} and its subranges.
6193
6194 @item
6195 @emph{Floating-point types} consist of @code{REAL}.
6196
6197 @item
6198 @emph{Pointer types} consist of anything declared as @code{POINTER TO
6199 @var{type}}.
6200
6201 @item
6202 @emph{Scalar types} consist of all of the above.
6203
6204 @item
6205 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
6206
6207 @item
6208 @emph{Boolean types} consist of @code{BOOLEAN}.
6209 @end itemize
6210
6211 @noindent
6212 The following operators are supported, and appear in order of
6213 increasing precedence:
6214
6215 @table @code
6216 @item ,
6217 Function argument or array index separator.
6218
6219 @item :=
6220 Assignment. The value of @var{var} @code{:=} @var{value} is
6221 @var{value}.
6222
6223 @item <@r{, }>
6224 Less than, greater than on integral, floating-point, or enumerated
6225 types.
6226
6227 @item <=@r{, }>=
6228 Less than, greater than, less than or equal to, greater than or equal to
6229 on integral, floating-point and enumerated types, or set inclusion on
6230 set types. Same precedence as @code{<}.
6231
6232 @item =@r{, }<>@r{, }#
6233 Equality and two ways of expressing inequality, valid on scalar types.
6234 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6235 available for inequality, since @code{#} conflicts with the script
6236 comment character.
6237
6238 @item IN
6239 Set membership. Defined on set types and the types of their members.
6240 Same precedence as @code{<}.
6241
6242 @item OR
6243 Boolean disjunction. Defined on boolean types.
6244
6245 @item AND@r{, }&
6246 Boolean conjunction. Defined on boolean types.
6247
6248 @item @@
6249 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6250
6251 @item +@r{, }-
6252 Addition and subtraction on integral and floating-point types, or union
6253 and difference on set types.
6254
6255 @item *
6256 Multiplication on integral and floating-point types, or set intersection
6257 on set types.
6258
6259 @item /
6260 Division on floating-point types, or symmetric set difference on set
6261 types. Same precedence as @code{*}.
6262
6263 @item DIV@r{, }MOD
6264 Integer division and remainder. Defined on integral types. Same
6265 precedence as @code{*}.
6266
6267 @item -
6268 Negative. Defined on @code{INTEGER} and @code{REAL} data.
6269
6270 @item ^
6271 Pointer dereferencing. Defined on pointer types.
6272
6273 @item NOT
6274 Boolean negation. Defined on boolean types. Same precedence as
6275 @code{^}.
6276
6277 @item .
6278 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
6279 precedence as @code{^}.
6280
6281 @item []
6282 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6283
6284 @item ()
6285 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6286 as @code{^}.
6287
6288 @item ::@r{, }.
6289 @value{GDBN} and Modula-2 scope operators.
6290 @end table
6291
6292 @quotation
6293 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6294 treats the use of the operator @code{IN}, or the use of operators
6295 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6296 @code{<=}, and @code{>=} on sets as an error.
6297 @end quotation
6298
6299 @cindex Modula-2 built-ins
6300 @node Built-In Func/Proc
6301 @subsubsection Built-in functions and procedures
6302
6303 Modula-2 also makes available several built-in procedures and functions.
6304 In describing these, the following metavariables are used:
6305
6306 @table @var
6307
6308 @item a
6309 represents an @code{ARRAY} variable.
6310
6311 @item c
6312 represents a @code{CHAR} constant or variable.
6313
6314 @item i
6315 represents a variable or constant of integral type.
6316
6317 @item m
6318 represents an identifier that belongs to a set. Generally used in the
6319 same function with the metavariable @var{s}. The type of @var{s} should
6320 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6321
6322 @item n
6323 represents a variable or constant of integral or floating-point type.
6324
6325 @item r
6326 represents a variable or constant of floating-point type.
6327
6328 @item t
6329 represents a type.
6330
6331 @item v
6332 represents a variable.
6333
6334 @item x
6335 represents a variable or constant of one of many types. See the
6336 explanation of the function for details.
6337 @end table
6338
6339 All Modula-2 built-in procedures also return a result, described below.
6340
6341 @table @code
6342 @item ABS(@var{n})
6343 Returns the absolute value of @var{n}.
6344
6345 @item CAP(@var{c})
6346 If @var{c} is a lower case letter, it returns its upper case
6347 equivalent, otherwise it returns its argument
6348
6349 @item CHR(@var{i})
6350 Returns the character whose ordinal value is @var{i}.
6351
6352 @item DEC(@var{v})
6353 Decrements the value in the variable @var{v}. Returns the new value.
6354
6355 @item DEC(@var{v},@var{i})
6356 Decrements the value in the variable @var{v} by @var{i}. Returns the
6357 new value.
6358
6359 @item EXCL(@var{m},@var{s})
6360 Removes the element @var{m} from the set @var{s}. Returns the new
6361 set.
6362
6363 @item FLOAT(@var{i})
6364 Returns the floating point equivalent of the integer @var{i}.
6365
6366 @item HIGH(@var{a})
6367 Returns the index of the last member of @var{a}.
6368
6369 @item INC(@var{v})
6370 Increments the value in the variable @var{v}. Returns the new value.
6371
6372 @item INC(@var{v},@var{i})
6373 Increments the value in the variable @var{v} by @var{i}. Returns the
6374 new value.
6375
6376 @item INCL(@var{m},@var{s})
6377 Adds the element @var{m} to the set @var{s} if it is not already
6378 there. Returns the new set.
6379
6380 @item MAX(@var{t})
6381 Returns the maximum value of the type @var{t}.
6382
6383 @item MIN(@var{t})
6384 Returns the minimum value of the type @var{t}.
6385
6386 @item ODD(@var{i})
6387 Returns boolean TRUE if @var{i} is an odd number.
6388
6389 @item ORD(@var{x})
6390 Returns the ordinal value of its argument. For example, the ordinal
6391 value of a character is its ASCII value (on machines supporting the
6392 ASCII character set). @var{x} must be of an ordered type, which include
6393 integral, character and enumerated types.
6394
6395 @item SIZE(@var{x})
6396 Returns the size of its argument. @var{x} can be a variable or a type.
6397
6398 @item TRUNC(@var{r})
6399 Returns the integral part of @var{r}.
6400
6401 @item VAL(@var{t},@var{i})
6402 Returns the member of the type @var{t} whose ordinal value is @var{i}.
6403 @end table
6404
6405 @quotation
6406 @emph{Warning:} Sets and their operations are not yet supported, so
6407 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6408 an error.
6409 @end quotation
6410
6411 @cindex Modula-2 constants
6412 @node M2 Constants
6413 @subsubsection Constants
6414
6415 @value{GDBN} allows you to express the constants of Modula-2 in the following
6416 ways:
6417
6418 @itemize @bullet
6419
6420 @item
6421 Integer constants are simply a sequence of digits. When used in an
6422 expression, a constant is interpreted to be type-compatible with the
6423 rest of the expression. Hexadecimal integers are specified by a
6424 trailing @samp{H}, and octal integers by a trailing @samp{B}.
6425
6426 @item
6427 Floating point constants appear as a sequence of digits, followed by a
6428 decimal point and another sequence of digits. An optional exponent can
6429 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6430 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6431 digits of the floating point constant must be valid decimal (base 10)
6432 digits.
6433
6434 @item
6435 Character constants consist of a single character enclosed by a pair of
6436 like quotes, either single (@code{'}) or double (@code{"}). They may
6437 also be expressed by their ordinal value (their ASCII value, usually)
6438 followed by a @samp{C}.
6439
6440 @item
6441 String constants consist of a sequence of characters enclosed by a
6442 pair of like quotes, either single (@code{'}) or double (@code{"}).
6443 Escape sequences in the style of C are also allowed. @xref{C
6444 Constants, ,C and C++ constants}, for a brief explanation of escape
6445 sequences.
6446
6447 @item
6448 Enumerated constants consist of an enumerated identifier.
6449
6450 @item
6451 Boolean constants consist of the identifiers @code{TRUE} and
6452 @code{FALSE}.
6453
6454 @item
6455 Pointer constants consist of integral values only.
6456
6457 @item
6458 Set constants are not yet supported.
6459 @end itemize
6460
6461 @node M2 Defaults
6462 @subsubsection Modula-2 defaults
6463 @cindex Modula-2 defaults
6464
6465 If type and range checking are set automatically by @value{GDBN}, they
6466 both default to @code{on} whenever the working language changes to
6467 Modula-2. This happens regardless of whether you or @value{GDBN}
6468 selected the working language.
6469
6470 If you allow @value{GDBN} to set the language automatically, then entering
6471 code compiled from a file whose name ends with @file{.mod} sets the
6472 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
6473 the language automatically}, for further details.
6474
6475 @node Deviations
6476 @subsubsection Deviations from standard Modula-2
6477 @cindex Modula-2, deviations from
6478
6479 A few changes have been made to make Modula-2 programs easier to debug.
6480 This is done primarily via loosening its type strictness:
6481
6482 @itemize @bullet
6483 @item
6484 Unlike in standard Modula-2, pointer constants can be formed by
6485 integers. This allows you to modify pointer variables during
6486 debugging. (In standard Modula-2, the actual address contained in a
6487 pointer variable is hidden from you; it can only be modified
6488 through direct assignment to another pointer variable or expression that
6489 returned a pointer.)
6490
6491 @item
6492 C escape sequences can be used in strings and characters to represent
6493 non-printable characters. @value{GDBN} prints out strings with these
6494 escape sequences embedded. Single non-printable characters are
6495 printed using the @samp{CHR(@var{nnn})} format.
6496
6497 @item
6498 The assignment operator (@code{:=}) returns the value of its right-hand
6499 argument.
6500
6501 @item
6502 All built-in procedures both modify @emph{and} return their argument.
6503 @end itemize
6504
6505 @node M2 Checks
6506 @subsubsection Modula-2 type and range checks
6507 @cindex Modula-2 checks
6508
6509 @quotation
6510 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6511 range checking.
6512 @end quotation
6513 @c FIXME remove warning when type/range checks added
6514
6515 @value{GDBN} considers two Modula-2 variables type equivalent if:
6516
6517 @itemize @bullet
6518 @item
6519 They are of types that have been declared equivalent via a @code{TYPE
6520 @var{t1} = @var{t2}} statement
6521
6522 @item
6523 They have been declared on the same line. (Note: This is true of the
6524 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6525 @end itemize
6526
6527 As long as type checking is enabled, any attempt to combine variables
6528 whose types are not equivalent is an error.
6529
6530 Range checking is done on all mathematical operations, assignment, array
6531 index bounds, and all built-in functions and procedures.
6532
6533 @node M2 Scope
6534 @subsubsection The scope operators @code{::} and @code{.}
6535 @cindex scope
6536 @kindex .
6537 @cindex colon, doubled as scope operator
6538 @ifinfo
6539 @kindex colon-colon@r{, in Modula-2}
6540 @c Info cannot handle :: but TeX can.
6541 @end ifinfo
6542 @iftex
6543 @kindex ::
6544 @end iftex
6545
6546 There are a few subtle differences between the Modula-2 scope operator
6547 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6548 similar syntax:
6549
6550 @example
6551
6552 @var{module} . @var{id}
6553 @var{scope} :: @var{id}
6554 @end example
6555
6556 @noindent
6557 where @var{scope} is the name of a module or a procedure,
6558 @var{module} the name of a module, and @var{id} is any declared
6559 identifier within your program, except another module.
6560
6561 Using the @code{::} operator makes @value{GDBN} search the scope
6562 specified by @var{scope} for the identifier @var{id}. If it is not
6563 found in the specified scope, then @value{GDBN} searches all scopes
6564 enclosing the one specified by @var{scope}.
6565
6566 Using the @code{.} operator makes @value{GDBN} search the current scope for
6567 the identifier specified by @var{id} that was imported from the
6568 definition module specified by @var{module}. With this operator, it is
6569 an error if the identifier @var{id} was not imported from definition
6570 module @var{module}, or if @var{id} is not an identifier in
6571 @var{module}.
6572
6573 @node GDB/M2
6574 @subsubsection @value{GDBN} and Modula-2
6575
6576 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6577 Five subcommands of @code{set print} and @code{show print} apply
6578 specifically to C and C++: @samp{vtbl}, @samp{demangle},
6579 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6580 apply to C++, and the last to the C @code{union} type, which has no direct
6581 analogue in Modula-2.
6582
6583 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
6584 with any language, is not useful with Modula-2. Its
6585 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6586 created in Modula-2 as they can in C or C++. However, because an
6587 address can be specified by an integral constant, the construct
6588 @samp{@{@var{type}@}@var{adrexp}} is still useful.
6589
6590 @cindex @code{#} in Modula-2
6591 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6592 interpreted as the beginning of a comment. Use @code{<>} instead.
6593
6594 @node Chill
6595 @subsection Chill
6596
6597 The extensions made to @value{GDBN} to support Chill only support output
6598 from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
6599 supported, and attempting to debug executables produced by them is most
6600 likely to give an error as @value{GDBN} reads in the executable's symbol
6601 table.
6602
6603 @c This used to say "... following Chill related topics ...", but since
6604 @c menus are not shown in the printed manual, it would look awkward.
6605 This section covers the Chill related topics and the features
6606 of @value{GDBN} which support these topics.
6607
6608 @menu
6609 * How modes are displayed:: How modes are displayed
6610 * Locations:: Locations and their accesses
6611 * Values and their Operations:: Values and their Operations
6612 * Chill type and range checks::
6613 * Chill defaults::
6614 @end menu
6615
6616 @node How modes are displayed
6617 @subsubsection How modes are displayed
6618
6619 The Chill Datatype- (Mode) support of @value{GDBN} is directly related
6620 with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
6621 slightly from the standard specification of the Chill language. The
6622 provided modes are:
6623
6624 @c FIXME: this @table's contents effectively disable @code by using @r
6625 @c on every @item. So why does it need @code?
6626 @table @code
6627 @item @r{@emph{Discrete modes:}}
6628 @itemize @bullet
6629 @item
6630 @emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6631 UINT, LONG, ULONG},
6632 @item
6633 @emph{Boolean Mode} which is predefined by @code{BOOL},
6634 @item
6635 @emph{Character Mode} which is predefined by @code{CHAR},
6636 @item
6637 @emph{Set Mode} which is displayed by the keyword @code{SET}.
6638 @smallexample
6639 (@value{GDBP}) ptype x
6640 type = SET (karli = 10, susi = 20, fritzi = 100)
6641 @end smallexample
6642 If the type is an unnumbered set the set element values are omitted.
6643 @item
6644 @emph{Range Mode} which is displayed by @code{type = <basemode>
6645 (<lower bound> : <upper bound>)}, where @code{<lower bound>, <upper
6646 bound>} can be of any discrete literal expression (e.g. set element
6647 names).
6648 @end itemize
6649
6650 @item @r{@emph{Powerset Mode:}}
6651 A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
6652 the member mode of the powerset. The member mode can be any discrete mode.
6653 @smallexample
6654 (@value{GDBP}) ptype x
6655 type = POWERSET SET (egon, hugo, otto)
6656 @end smallexample
6657
6658 @item @r{@emph{Reference Modes:}}
6659 @itemize @bullet
6660 @item
6661 @emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
6662 followed by the mode name to which the reference is bound.
6663 @item
6664 @emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6665 @end itemize
6666
6667 @item @r{@emph{Procedure mode}}
6668 The procedure mode is displayed by @code{type = PROC(<parameter list>)
6669 <return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
6670 list>} is a list of the parameter modes. @code{<return mode>} indicates
6671 the mode of the result of the procedure if any. The exceptionlist lists
6672 all possible exceptions which can be raised by the procedure.
6673
6674 @ignore
6675 @item @r{@emph{Instance mode}}
6676 The instance mode is represented by a structure, which has a static
6677 type, and is therefore not really of interest.
6678 @end ignore
6679
6680 @item @r{@emph{Synchronization Modes:}}
6681 @itemize @bullet
6682 @item
6683 @emph{Event Mode} which is displayed by @code{EVENT (<event length>)},
6684 where @code{(<event length>)} is optional.
6685 @item
6686 @emph{Buffer Mode} which is displayed by @code{BUFFER (<buffer length>)
6687 <buffer element mode>}, where @code{(<buffer length>)} is optional.
6688 @end itemize
6689
6690 @item @r{@emph{Timing Modes:}}
6691 @itemize @bullet
6692 @item
6693 @emph{Duration Mode} which is predefined by @code{DURATION}
6694 @item
6695 @emph{Absolute Time Mode} which is predefined by @code{TIME}
6696 @end itemize
6697
6698 @item @r{@emph{Real Modes:}}
6699 Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6700
6701 @item @r{@emph{String Modes:}}
6702 @itemize @bullet
6703 @item
6704 @emph{Character String Mode} which is displayed by @code{CHARS(<string
6705 length>)}, followed by the keyword @code{VARYING} if the String Mode is
6706 a varying mode
6707 @item
6708 @emph{Bit String Mode} which is displayed by @code{BOOLS(<string
6709 length>)}.
6710 @end itemize
6711
6712 @item @r{@emph{Array Mode:}}
6713 The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6714 followed by the element mode (which may in turn be an array mode).
6715 @smallexample
6716 (@value{GDBP}) ptype x
6717 type = ARRAY (1:42)
6718 ARRAY (1:20)
6719 SET (karli = 10, susi = 20, fritzi = 100)
6720 @end smallexample
6721
6722 @item @r{@emph{Structure Mode}}
6723 The Structure mode is displayed by the keyword @code{STRUCT(<field
6724 list>)}. The @code{<field list>} consists of names and modes of fields
6725 of the structure. Variant structures have the keyword @code{CASE <field>
6726 OF <variant fields> ESAC} in their field list. Since the current version
6727 of the GNU Chill compiler doesn't implement tag processing (no runtime
6728 checks of variant fields, and therefore no debugging info), the output
6729 always displays all variant fields.
6730 @smallexample
6731 (@value{GDBP}) ptype str
6732 type = STRUCT (
6733 as x,
6734 bs x,
6735 CASE bs OF
6736 (karli):
6737 cs a
6738 (ott):
6739 ds x
6740 ESAC
6741 )
6742 @end smallexample
6743 @end table
6744
6745 @node Locations
6746 @subsubsection Locations and their accesses
6747
6748 A location in Chill is an object which can contain values.
6749
6750 A value of a location is generally accessed by the (declared) name of
6751 the location. The output conforms to the specification of values in
6752 Chill programs. How values are specified
6753 is the topic of the next section, @ref{Values and their Operations}.
6754
6755 The pseudo-location @code{RESULT} (or @code{result}) can be used to
6756 display or change the result of a currently-active procedure:
6757
6758 @smallexample
6759 set result := EXPR
6760 @end smallexample
6761
6762 @noindent
6763 This does the same as the Chill action @code{RESULT EXPR} (which
6764 is not available in gdb).
6765
6766 Values of reference mode locations are printed by @code{PTR(<hex
6767 value>)} in case of a free reference mode, and by @code{(REF <reference
6768 mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
6769 represents the address where the reference points to. To access the
6770 value of the location referenced by the pointer, use the dereference
6771 operator @samp{->}.
6772
6773 Values of procedure mode locations are displayed by @code{@{ PROC
6774 (<argument modes> ) <return mode> @} <address> <name of procedure
6775 location>}. @code{<argument modes>} is a list of modes according to the
6776 parameter specification of the procedure and @code{<address>} shows the
6777 address of the entry point.
6778
6779 @ignore
6780 Locations of instance modes are displayed just like a structure with two
6781 fields specifying the @emph{process type} and the @emph{copy number} of
6782 the investigated instance location@footnote{This comes from the current
6783 implementation of instances. They are implemented as a structure (no
6784 na). The output should be something like @code{[<name of the process>;
6785 <instance number>]}.}. The field names are @code{__proc_type} and
6786 @code{__proc_copy}.
6787
6788 Locations of synchronization modes are displayed like a structure with
6789 the field name @code{__event_data} in case of a event mode location, and
6790 like a structure with the field @code{__buffer_data} in case of a buffer
6791 mode location (refer to previous paragraph).
6792
6793 Structure Mode locations are printed by @code{[.<field name>: <value>,
6794 ...]}. The @code{<field name>} corresponds to the structure mode
6795 definition and the layout of @code{<value>} varies depending of the mode
6796 of the field. If the investigated structure mode location is of variant
6797 structure mode, the variant parts of the structure are enclosed in curled
6798 braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
6799 on the same memory location and represent the current values of the
6800 memory location in their specific modes. Since no tag processing is done
6801 all variants are displayed. A variant field is printed by
6802 @code{(<variant name>) = .<field name>: <value>}. (who implements the
6803 stuff ???)
6804 @smallexample
6805 (@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
6806 [.cs: []], (susi) = [.ds: susi]}]
6807 @end smallexample
6808 @end ignore
6809
6810 Substructures of string mode-, array mode- or structure mode-values
6811 (e.g. array slices, fields of structure locations) are accessed using
6812 certain operations which are described in the next section, @ref{Values
6813 and their Operations}.
6814
6815 A location value may be interpreted as having a different mode using the
6816 location conversion. This mode conversion is written as @code{<mode
6817 name>(<location>)}. The user has to consider that the sizes of the modes
6818 have to be equal otherwise an error occurs. Furthermore, no range
6819 checking of the location against the destination mode is performed, and
6820 therefore the result can be quite confusing.
6821
6822 @smallexample
6823 (@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
6824 @end smallexample
6825
6826 @node Values and their Operations
6827 @subsubsection Values and their Operations
6828
6829 Values are used to alter locations, to investigate complex structures in
6830 more detail or to filter relevant information out of a large amount of
6831 data. There are several (mode dependent) operations defined which enable
6832 such investigations. These operations are not only applicable to
6833 constant values but also to locations, which can become quite useful
6834 when debugging complex structures. During parsing the command line
6835 (e.g. evaluating an expression) @value{GDBN} treats location names as
6836 the values behind these locations.
6837
6838 This section describes how values have to be specified and which
6839 operations are legal to be used with such values.
6840
6841 @table @code
6842 @item Literal Values
6843 Literal values are specified in the same manner as in @sc{gnu} Chill programs.
6844 For detailed specification refer to the @sc{gnu} Chill implementation Manual
6845 chapter 1.5.
6846 @c FIXME: if the Chill Manual is a Texinfo documents, the above should
6847 @c be converted to a @ref.
6848
6849 @ignore
6850 @itemize @bullet
6851 @item
6852 @emph{Integer Literals} are specified in the same manner as in Chill
6853 programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
6854 @item
6855 @emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
6856 @item
6857 @emph{Character Literals} are defined by @code{'<character>'}. (e.g.
6858 @code{'M'})
6859 @item
6860 @emph{Set Literals} are defined by a name which was specified in a set
6861 mode. The value delivered by a Set Literal is the set value. This is
6862 comparable to an enumeration in C/C++ language.
6863 @item
6864 @emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
6865 emptiness literal delivers either the empty reference value, the empty
6866 procedure value or the empty instance value.
6867
6868 @item
6869 @emph{Character String Literals} are defined by a sequence of characters
6870 enclosed in single- or double quotes. If a single- or double quote has
6871 to be part of the string literal it has to be stuffed (specified twice).
6872 @item
6873 @emph{Bitstring Literals} are specified in the same manner as in Chill
6874 programs (refer z200/88 chpt 5.2.4.8).
6875 @item
6876 @emph{Floating point literals} are specified in the same manner as in
6877 (gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
6878 @end itemize
6879 @end ignore
6880
6881 @item Tuple Values
6882 A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
6883 name>} can be omitted if the mode of the tuple is unambiguous. This
6884 unambiguity is derived from the context of a evaluated expression.
6885 @code{<tuple>} can be one of the following:
6886
6887 @itemize @bullet
6888 @item @emph{Powerset Tuple}
6889 @item @emph{Array Tuple}
6890 @item @emph{Structure Tuple}
6891 Powerset tuples, array tuples and structure tuples are specified in the
6892 same manner as in Chill programs refer to z200/88 chpt 5.2.5.
6893 @end itemize
6894
6895 @item String Element Value
6896 A string element value is specified by @code{<string value>(<index>)},
6897 where @code{<index>} is a integer expression. It delivers a character
6898 value which is equivalent to the character indexed by @code{<index>} in
6899 the string.
6900
6901 @item String Slice Value
6902 A string slice value is specified by @code{<string value>(<slice
6903 spec>)}, where @code{<slice spec>} can be either a range of integer
6904 expressions or specified by @code{<start expr> up <size>}.
6905 @code{<size>} denotes the number of elements which the slice contains.
6906 The delivered value is a string value, which is part of the specified
6907 string.
6908
6909 @item Array Element Values
6910 An array element value is specified by @code{<array value>(<expr>)} and
6911 delivers a array element value of the mode of the specified array.
6912
6913 @item Array Slice Values
6914 An array slice is specified by @code{<array value>(<slice spec>)}, where
6915 @code{<slice spec>} can be either a range specified by expressions or by
6916 @code{<start expr> up <size>}. @code{<size>} denotes the number of
6917 arrayelements the slice contains. The delivered value is an array value
6918 which is part of the specified array.
6919
6920 @item Structure Field Values
6921 A structure field value is derived by @code{<structure value>.<field
6922 name>}, where @code{<field name>} indicates the name of a field specified
6923 in the mode definition of the structure. The mode of the delivered value
6924 corresponds to this mode definition in the structure definition.
6925
6926 @item Procedure Call Value
6927 The procedure call value is derived from the return value of the
6928 procedure@footnote{If a procedure call is used for instance in an
6929 expression, then this procedure is called with all its side
6930 effects. This can lead to confusing results if used carelessly.}.
6931
6932 Values of duration mode locations are represented by @code{ULONG} literals.
6933
6934 Values of time mode locations are represented by @code{TIME(<secs>:<nsecs>)}.
6935
6936 @ignore
6937 This is not implemented yet:
6938 @item Built-in Value
6939 @noindent
6940 The following built in functions are provided:
6941
6942 @table @code
6943 @item @code{ADDR()}
6944 @item @code{NUM()}
6945 @item @code{PRED()}
6946 @item @code{SUCC()}
6947 @item @code{ABS()}
6948 @item @code{CARD()}
6949 @item @code{MAX()}
6950 @item @code{MIN()}
6951 @item @code{SIZE()}
6952 @item @code{UPPER()}
6953 @item @code{LOWER()}
6954 @item @code{LENGTH()}
6955 @item @code{SIN()}
6956 @item @code{COS()}
6957 @item @code{TAN()}
6958 @item @code{ARCSIN()}
6959 @item @code{ARCCOS()}
6960 @item @code{ARCTAN()}
6961 @item @code{EXP()}
6962 @item @code{LN()}
6963 @item @code{LOG()}
6964 @item @code{SQRT()}
6965 @end table
6966
6967 For a detailed description refer to the GNU Chill implementation manual
6968 chapter 1.6.
6969 @end ignore
6970
6971 @item Zero-adic Operator Value
6972 The zero-adic operator value is derived from the instance value for the
6973 current active process.
6974
6975 @item Expression Values
6976 The value delivered by an expression is the result of the evaluation of
6977 the specified expression. If there are error conditions (mode
6978 incompatibility, etc.) the evaluation of expressions is aborted with a
6979 corresponding error message. Expressions may be parenthesised which
6980 causes the evaluation of this expression before any other expression
6981 which uses the result of the parenthesised expression. The following
6982 operators are supported by @value{GDBN}:
6983
6984 @table @code
6985 @item @code{OR, ORIF, XOR}
6986 @itemx @code{AND, ANDIF}
6987 @itemx @code{NOT}
6988 Logical operators defined over operands of boolean mode.
6989
6990 @item @code{=, /=}
6991 Equality and inequality operators defined over all modes.
6992
6993 @item @code{>, >=}
6994 @itemx @code{<, <=}
6995 Relational operators defined over predefined modes.
6996
6997 @item @code{+, -}
6998 @itemx @code{*, /, MOD, REM}
6999 Arithmetic operators defined over predefined modes.
7000
7001 @item @code{-}
7002 Change sign operator.
7003
7004 @item @code{//}
7005 String concatenation operator.
7006
7007 @item @code{()}
7008 String repetition operator.
7009
7010 @item @code{->}
7011 Referenced location operator which can be used either to take the
7012 address of a location (@code{->loc}), or to dereference a reference
7013 location (@code{loc->}).
7014
7015 @item @code{OR, XOR}
7016 @itemx @code{AND}
7017 @itemx @code{NOT}
7018 Powerset and bitstring operators.
7019
7020 @item @code{>, >=}
7021 @itemx @code{<, <=}
7022 Powerset inclusion operators.
7023
7024 @item @code{IN}
7025 Membership operator.
7026 @end table
7027 @end table
7028
7029 @node Chill type and range checks
7030 @subsubsection Chill type and range checks
7031
7032 @value{GDBN} considers two Chill variables mode equivalent if the sizes
7033 of the two modes are equal. This rule applies recursively to more
7034 complex datatypes which means that complex modes are treated
7035 equivalent if all element modes (which also can be complex modes like
7036 structures, arrays, etc.) have the same size.
7037
7038 Range checking is done on all mathematical operations, assignment, array
7039 index bounds and all built in procedures.
7040
7041 Strong type checks are forced using the @value{GDBN} command @code{set
7042 check strong}. This enforces strong type and range checks on all
7043 operations where Chill constructs are used (expressions, built in
7044 functions, etc.) in respect to the semantics as defined in the z.200
7045 language specification.
7046
7047 All checks can be disabled by the @value{GDBN} command @code{set check
7048 off}.
7049
7050 @ignore
7051 @c Deviations from the Chill Standard Z200/88
7052 see last paragraph ?
7053 @end ignore
7054
7055 @node Chill defaults
7056 @subsubsection Chill defaults
7057
7058 If type and range checking are set automatically by @value{GDBN}, they
7059 both default to @code{on} whenever the working language changes to
7060 Chill. This happens regardless of whether you or @value{GDBN}
7061 selected the working language.
7062
7063 If you allow @value{GDBN} to set the language automatically, then entering
7064 code compiled from a file whose name ends with @file{.ch} sets the
7065 working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
7066 the language automatically}, for further details.
7067
7068 @node Symbols
7069 @chapter Examining the Symbol Table
7070
7071 The commands described in this chapter allow you to inquire about the
7072 symbols (names of variables, functions and types) defined in your
7073 program. This information is inherent in the text of your program and
7074 does not change as your program executes. @value{GDBN} finds it in your
7075 program's symbol table, in the file indicated when you started @value{GDBN}
7076 (@pxref{File Options, ,Choosing files}), or by one of the
7077 file-management commands (@pxref{Files, ,Commands to specify files}).
7078
7079 @cindex symbol names
7080 @cindex names of symbols
7081 @cindex quoting names
7082 Occasionally, you may need to refer to symbols that contain unusual
7083 characters, which @value{GDBN} ordinarily treats as word delimiters. The
7084 most frequent case is in referring to static variables in other
7085 source files (@pxref{Variables,,Program variables}). File names
7086 are recorded in object files as debugging symbols, but @value{GDBN} would
7087 ordinarily parse a typical file name, like @file{foo.c}, as the three words
7088 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7089 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7090
7091 @example
7092 p 'foo.c'::x
7093 @end example
7094
7095 @noindent
7096 looks up the value of @code{x} in the scope of the file @file{foo.c}.
7097
7098 @table @code
7099 @kindex info address
7100 @item info address @var{symbol}
7101 Describe where the data for @var{symbol} is stored. For a register
7102 variable, this says which register it is kept in. For a non-register
7103 local variable, this prints the stack-frame offset at which the variable
7104 is always stored.
7105
7106 Note the contrast with @samp{print &@var{symbol}}, which does not work
7107 at all for a register variable, and for a stack local variable prints
7108 the exact address of the current instantiation of the variable.
7109
7110 @kindex whatis
7111 @item whatis @var{expr}
7112 Print the data type of expression @var{expr}. @var{expr} is not
7113 actually evaluated, and any side-effecting operations (such as
7114 assignments or function calls) inside it do not take place.
7115 @xref{Expressions, ,Expressions}.
7116
7117 @item whatis
7118 Print the data type of @code{$}, the last value in the value history.
7119
7120 @kindex ptype
7121 @item ptype @var{typename}
7122 Print a description of data type @var{typename}. @var{typename} may be
7123 the name of a type, or for C code it may have the form @samp{class
7124 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7125 @var{union-tag}} or @samp{enum @var{enum-tag}}.
7126
7127 @item ptype @var{expr}
7128 @itemx ptype
7129 Print a description of the type of expression @var{expr}. @code{ptype}
7130 differs from @code{whatis} by printing a detailed description, instead
7131 of just the name of the type.
7132
7133 For example, for this variable declaration:
7134
7135 @example
7136 struct complex @{double real; double imag;@} v;
7137 @end example
7138
7139 @noindent
7140 the two commands give this output:
7141
7142 @example
7143 @group
7144 (@value{GDBP}) whatis v
7145 type = struct complex
7146 (@value{GDBP}) ptype v
7147 type = struct complex @{
7148 double real;
7149 double imag;
7150 @}
7151 @end group
7152 @end example
7153
7154 @noindent
7155 As with @code{whatis}, using @code{ptype} without an argument refers to
7156 the type of @code{$}, the last value in the value history.
7157
7158 @kindex info types
7159 @item info types @var{regexp}
7160 @itemx info types
7161 Print a brief description of all types whose names match @var{regexp}
7162 (or all types in your program, if you supply no argument). Each
7163 complete typename is matched as though it were a complete line; thus,
7164 @samp{i type value} gives information on all types in your program whose
7165 names include the string @code{value}, but @samp{i type ^value$} gives
7166 information only on types whose complete name is @code{value}.
7167
7168 This command differs from @code{ptype} in two ways: first, like
7169 @code{whatis}, it does not print a detailed description; second, it
7170 lists all source files where a type is defined.
7171
7172 @kindex info source
7173 @item info source
7174 Show the name of the current source file---that is, the source file for
7175 the function containing the current point of execution---and the language
7176 it was written in.
7177
7178 @kindex info sources
7179 @item info sources
7180 Print the names of all source files in your program for which there is
7181 debugging information, organized into two lists: files whose symbols
7182 have already been read, and files whose symbols will be read when needed.
7183
7184 @kindex info functions
7185 @item info functions
7186 Print the names and data types of all defined functions.
7187
7188 @item info functions @var{regexp}
7189 Print the names and data types of all defined functions
7190 whose names contain a match for regular expression @var{regexp}.
7191 Thus, @samp{info fun step} finds all functions whose names
7192 include @code{step}; @samp{info fun ^step} finds those whose names
7193 start with @code{step}.
7194
7195 @kindex info variables
7196 @item info variables
7197 Print the names and data types of all variables that are declared
7198 outside of functions (i.e., excluding local variables).
7199
7200 @item info variables @var{regexp}
7201 Print the names and data types of all variables (except for local
7202 variables) whose names contain a match for regular expression
7203 @var{regexp}.
7204
7205 @ignore
7206 This was never implemented.
7207 @kindex info methods
7208 @item info methods
7209 @itemx info methods @var{regexp}
7210 The @code{info methods} command permits the user to examine all defined
7211 methods within C++ program, or (with the @var{regexp} argument) a
7212 specific set of methods found in the various C++ classes. Many
7213 C++ classes provide a large number of methods. Thus, the output
7214 from the @code{ptype} command can be overwhelming and hard to use. The
7215 @code{info-methods} command filters the methods, printing only those
7216 which match the regular-expression @var{regexp}.
7217 @end ignore
7218
7219 @cindex reloading symbols
7220 Some systems allow individual object files that make up your program to
7221 be replaced without stopping and restarting your program. For example,
7222 in VxWorks you can simply recompile a defective object file and keep on
7223 running. If you are running on one of these systems, you can allow
7224 @value{GDBN} to reload the symbols for automatically relinked modules:
7225
7226 @table @code
7227 @kindex set symbol-reloading
7228 @item set symbol-reloading on
7229 Replace symbol definitions for the corresponding source file when an
7230 object file with a particular name is seen again.
7231
7232 @item set symbol-reloading off
7233 Do not replace symbol definitions when re-encountering object files of
7234 the same name. This is the default state; if you are not running on a
7235 system that permits automatically relinking modules, you should leave
7236 @code{symbol-reloading} off, since otherwise @value{GDBN} may discard symbols
7237 when linking large programs, that may contain several modules (from
7238 different directories or libraries) with the same name.
7239
7240 @kindex show symbol-reloading
7241 @item show symbol-reloading
7242 Show the current @code{on} or @code{off} setting.
7243 @end table
7244
7245 @kindex set opaque-type-resolution
7246 @item set opaque-type-resolution on
7247 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7248 declared as a pointer to a @code{struct}, @code{class}, or
7249 @code{union}---for example, @code{struct MyType *}---that is used in one
7250 source file although the full declaration of @code{struct MyType} is in
7251 another source file. The default is on.
7252
7253 A change in the setting of this subcommand will not take effect until
7254 the next time symbols for a file are loaded.
7255
7256 @item set opaque-type-resolution off
7257 Tell @value{GDBN} not to resolve opaque types. In this case, the type
7258 is printed as follows:
7259 @smallexample
7260 @{<no data fields>@}
7261 @end smallexample
7262
7263 @kindex show opaque-type-resolution
7264 @item show opaque-type-resolution
7265 Show whether opaque types are resolved or not.
7266
7267 @kindex maint print symbols
7268 @cindex symbol dump
7269 @kindex maint print psymbols
7270 @cindex partial symbol dump
7271 @item maint print symbols @var{filename}
7272 @itemx maint print psymbols @var{filename}
7273 @itemx maint print msymbols @var{filename}
7274 Write a dump of debugging symbol data into the file @var{filename}.
7275 These commands are used to debug the @value{GDBN} symbol-reading code. Only
7276 symbols with debugging data are included. If you use @samp{maint print
7277 symbols}, @value{GDBN} includes all the symbols for which it has already
7278 collected full details: that is, @var{filename} reflects symbols for
7279 only those files whose symbols @value{GDBN} has read. You can use the
7280 command @code{info sources} to find out which files these are. If you
7281 use @samp{maint print psymbols} instead, the dump shows information about
7282 symbols that @value{GDBN} only knows partially---that is, symbols defined in
7283 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7284 @samp{maint print msymbols} dumps just the minimal symbol information
7285 required for each object file from which @value{GDBN} has read some symbols.
7286 @xref{Files, ,Commands to specify files}, for a discussion of how
7287 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
7288 @end table
7289
7290 @node Altering
7291 @chapter Altering Execution
7292
7293 Once you think you have found an error in your program, you might want to
7294 find out for certain whether correcting the apparent error would lead to
7295 correct results in the rest of the run. You can find the answer by
7296 experiment, using the @value{GDBN} features for altering execution of the
7297 program.
7298
7299 For example, you can store new values into variables or memory
7300 locations, give your program a signal, restart it at a different
7301 address, or even return prematurely from a function.
7302
7303 @menu
7304 * Assignment:: Assignment to variables
7305 * Jumping:: Continuing at a different address
7306 * Signaling:: Giving your program a signal
7307 * Returning:: Returning from a function
7308 * Calling:: Calling your program's functions
7309 * Patching:: Patching your program
7310 @end menu
7311
7312 @node Assignment
7313 @section Assignment to variables
7314
7315 @cindex assignment
7316 @cindex setting variables
7317 To alter the value of a variable, evaluate an assignment expression.
7318 @xref{Expressions, ,Expressions}. For example,
7319
7320 @example
7321 print x=4
7322 @end example
7323
7324 @noindent
7325 stores the value 4 into the variable @code{x}, and then prints the
7326 value of the assignment expression (which is 4).
7327 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7328 information on operators in supported languages.
7329
7330 @kindex set variable
7331 @cindex variables, setting
7332 If you are not interested in seeing the value of the assignment, use the
7333 @code{set} command instead of the @code{print} command. @code{set} is
7334 really the same as @code{print} except that the expression's value is
7335 not printed and is not put in the value history (@pxref{Value History,
7336 ,Value history}). The expression is evaluated only for its effects.
7337
7338 If the beginning of the argument string of the @code{set} command
7339 appears identical to a @code{set} subcommand, use the @code{set
7340 variable} command instead of just @code{set}. This command is identical
7341 to @code{set} except for its lack of subcommands. For example, if your
7342 program has a variable @code{width}, you get an error if you try to set
7343 a new value with just @samp{set width=13}, because @value{GDBN} has the
7344 command @code{set width}:
7345
7346 @example
7347 (@value{GDBP}) whatis width
7348 type = double
7349 (@value{GDBP}) p width
7350 $4 = 13
7351 (@value{GDBP}) set width=47
7352 Invalid syntax in expression.
7353 @end example
7354
7355 @noindent
7356 The invalid expression, of course, is @samp{=47}. In
7357 order to actually set the program's variable @code{width}, use
7358
7359 @example
7360 (@value{GDBP}) set var width=47
7361 @end example
7362
7363 Because the @code{set} command has many subcommands that can conflict
7364 with the names of program variables, it is a good idea to use the
7365 @code{set variable} command instead of just @code{set}. For example, if
7366 your program has a variable @code{g}, you run into problems if you try
7367 to set a new value with just @samp{set g=4}, because @value{GDBN} has
7368 the command @code{set gnutarget}, abbreviated @code{set g}:
7369
7370 @example
7371 @group
7372 (@value{GDBP}) whatis g
7373 type = double
7374 (@value{GDBP}) p g
7375 $1 = 1
7376 (@value{GDBP}) set g=4
7377 (gdb) p g
7378 $2 = 1
7379 (@value{GDBP}) r
7380 The program being debugged has been started already.
7381 Start it from the beginning? (y or n) y
7382 Starting program: /home/smith/cc_progs/a.out
7383 "/home/smith/cc_progs/a.out": can't open to read symbols: Invalid bfd target.
7384 (@value{GDBP}) show g
7385 The current BFD target is "=4".
7386 @end group
7387 @end example
7388
7389 @noindent
7390 The program variable @code{g} did not change, and you silently set the
7391 @code{gnutarget} to an invalid value. In order to set the variable
7392 @code{g}, use
7393
7394 @example
7395 (@value{GDBP}) set var g=4
7396 @end example
7397
7398 @value{GDBN} allows more implicit conversions in assignments than C; you can
7399 freely store an integer value into a pointer variable or vice versa,
7400 and you can convert any structure to any other structure that is the
7401 same length or shorter.
7402 @comment FIXME: how do structs align/pad in these conversions?
7403 @comment /doc@cygnus.com 18dec1990
7404
7405 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7406 construct to generate a value of specified type at a specified address
7407 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7408 to memory location @code{0x83040} as an integer (which implies a certain size
7409 and representation in memory), and
7410
7411 @example
7412 set @{int@}0x83040 = 4
7413 @end example
7414
7415 @noindent
7416 stores the value 4 into that memory location.
7417
7418 @node Jumping
7419 @section Continuing at a different address
7420
7421 Ordinarily, when you continue your program, you do so at the place where
7422 it stopped, with the @code{continue} command. You can instead continue at
7423 an address of your own choosing, with the following commands:
7424
7425 @table @code
7426 @kindex jump
7427 @item jump @var{linespec}
7428 Resume execution at line @var{linespec}. Execution stops again
7429 immediately if there is a breakpoint there. @xref{List, ,Printing
7430 source lines}, for a description of the different forms of
7431 @var{linespec}. It is common practice to use the @code{tbreak} command
7432 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7433 breakpoints}.
7434
7435 The @code{jump} command does not change the current stack frame, or
7436 the stack pointer, or the contents of any memory location or any
7437 register other than the program counter. If line @var{linespec} is in
7438 a different function from the one currently executing, the results may
7439 be bizarre if the two functions expect different patterns of arguments or
7440 of local variables. For this reason, the @code{jump} command requests
7441 confirmation if the specified line is not in the function currently
7442 executing. However, even bizarre results are predictable if you are
7443 well acquainted with the machine-language code of your program.
7444
7445 @item jump *@var{address}
7446 Resume execution at the instruction at address @var{address}.
7447 @end table
7448
7449 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
7450 On many systems, you can get much the same effect as the @code{jump}
7451 command by storing a new value into the register @code{$pc}. The
7452 difference is that this does not start your program running; it only
7453 changes the address of where it @emph{will} run when you continue. For
7454 example,
7455
7456 @example
7457 set $pc = 0x485
7458 @end example
7459
7460 @noindent
7461 makes the next @code{continue} command or stepping command execute at
7462 address @code{0x485}, rather than at the address where your program stopped.
7463 @xref{Continuing and Stepping, ,Continuing and stepping}.
7464
7465 The most common occasion to use the @code{jump} command is to back
7466 up---perhaps with more breakpoints set---over a portion of a program
7467 that has already executed, in order to examine its execution in more
7468 detail.
7469
7470 @c @group
7471 @node Signaling
7472 @section Giving your program a signal
7473
7474 @table @code
7475 @kindex signal
7476 @item signal @var{signal}
7477 Resume execution where your program stopped, but immediately give it the
7478 signal @var{signal}. @var{signal} can be the name or the number of a
7479 signal. For example, on many systems @code{signal 2} and @code{signal
7480 SIGINT} are both ways of sending an interrupt signal.
7481
7482 Alternatively, if @var{signal} is zero, continue execution without
7483 giving a signal. This is useful when your program stopped on account of
7484 a signal and would ordinary see the signal when resumed with the
7485 @code{continue} command; @samp{signal 0} causes it to resume without a
7486 signal.
7487
7488 @code{signal} does not repeat when you press @key{RET} a second time
7489 after executing the command.
7490 @end table
7491 @c @end group
7492
7493 Invoking the @code{signal} command is not the same as invoking the
7494 @code{kill} utility from the shell. Sending a signal with @code{kill}
7495 causes @value{GDBN} to decide what to do with the signal depending on
7496 the signal handling tables (@pxref{Signals}). The @code{signal} command
7497 passes the signal directly to your program.
7498
7499
7500 @node Returning
7501 @section Returning from a function
7502
7503 @table @code
7504 @cindex returning from a function
7505 @kindex return
7506 @item return
7507 @itemx return @var{expression}
7508 You can cancel execution of a function call with the @code{return}
7509 command. If you give an
7510 @var{expression} argument, its value is used as the function's return
7511 value.
7512 @end table
7513
7514 When you use @code{return}, @value{GDBN} discards the selected stack frame
7515 (and all frames within it). You can think of this as making the
7516 discarded frame return prematurely. If you wish to specify a value to
7517 be returned, give that value as the argument to @code{return}.
7518
7519 This pops the selected stack frame (@pxref{Selection, ,Selecting a
7520 frame}), and any other frames inside of it, leaving its caller as the
7521 innermost remaining frame. That frame becomes selected. The
7522 specified value is stored in the registers used for returning values
7523 of functions.
7524
7525 The @code{return} command does not resume execution; it leaves the
7526 program stopped in the state that would exist if the function had just
7527 returned. In contrast, the @code{finish} command (@pxref{Continuing
7528 and Stepping, ,Continuing and stepping}) resumes execution until the
7529 selected stack frame returns naturally.
7530
7531 @node Calling
7532 @section Calling program functions
7533
7534 @cindex calling functions
7535 @kindex call
7536 @table @code
7537 @item call @var{expr}
7538 Evaluate the expression @var{expr} without displaying @code{void}
7539 returned values.
7540 @end table
7541
7542 You can use this variant of the @code{print} command if you want to
7543 execute a function from your program, but without cluttering the output
7544 with @code{void} returned values. If the result is not void, it
7545 is printed and saved in the value history.
7546
7547 For the A29K, a user-controlled variable @code{call_scratch_address},
7548 specifies the location of a scratch area to be used when @value{GDBN}
7549 calls a function in the target. This is necessary because the usual
7550 method of putting the scratch area on the stack does not work in systems
7551 that have separate instruction and data spaces.
7552
7553 @node Patching
7554 @section Patching programs
7555
7556 @cindex patching binaries
7557 @cindex writing into executables
7558 @cindex writing into corefiles
7559
7560 By default, @value{GDBN} opens the file containing your program's
7561 executable code (or the corefile) read-only. This prevents accidental
7562 alterations to machine code; but it also prevents you from intentionally
7563 patching your program's binary.
7564
7565 If you'd like to be able to patch the binary, you can specify that
7566 explicitly with the @code{set write} command. For example, you might
7567 want to turn on internal debugging flags, or even to make emergency
7568 repairs.
7569
7570 @table @code
7571 @kindex set write
7572 @item set write on
7573 @itemx set write off
7574 If you specify @samp{set write on}, @value{GDBN} opens executable and
7575 core files for both reading and writing; if you specify @samp{set write
7576 off} (the default), @value{GDBN} opens them read-only.
7577
7578 If you have already loaded a file, you must load it again (using the
7579 @code{exec-file} or @code{core-file} command) after changing @code{set
7580 write}, for your new setting to take effect.
7581
7582 @item show write
7583 @kindex show write
7584 Display whether executable files and core files are opened for writing
7585 as well as reading.
7586 @end table
7587
7588 @node GDB Files
7589 @chapter @value{GDBN} Files
7590
7591 @value{GDBN} needs to know the file name of the program to be debugged,
7592 both in order to read its symbol table and in order to start your
7593 program. To debug a core dump of a previous run, you must also tell
7594 @value{GDBN} the name of the core dump file.
7595
7596 @menu
7597 * Files:: Commands to specify files
7598 * Symbol Errors:: Errors reading symbol files
7599 @end menu
7600
7601 @node Files
7602 @section Commands to specify files
7603
7604 @cindex symbol table
7605 @cindex core dump file
7606
7607 You may want to specify executable and core dump file names. The usual
7608 way to do this is at start-up time, using the arguments to
7609 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7610 Out of @value{GDBN}}).
7611
7612 Occasionally it is necessary to change to a different file during a
7613 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7614 a file you want to use. In these situations the @value{GDBN} commands
7615 to specify new files are useful.
7616
7617 @table @code
7618 @cindex executable file
7619 @kindex file
7620 @item file @var{filename}
7621 Use @var{filename} as the program to be debugged. It is read for its
7622 symbols and for the contents of pure memory. It is also the program
7623 executed when you use the @code{run} command. If you do not specify a
7624 directory and the file is not found in the @value{GDBN} working directory,
7625 @value{GDBN} uses the environment variable @code{PATH} as a list of
7626 directories to search, just as the shell does when looking for a program
7627 to run. You can change the value of this variable, for both @value{GDBN}
7628 and your program, using the @code{path} command.
7629
7630 On systems with memory-mapped files, an auxiliary file
7631 @file{@var{filename}.syms} may hold symbol table information for
7632 @var{filename}. If so, @value{GDBN} maps in the symbol table from
7633 @file{@var{filename}.syms}, starting up more quickly. See the
7634 descriptions of the file options @samp{-mapped} and @samp{-readnow}
7635 (available on the command line, and with the commands @code{file},
7636 @code{symbol-file}, or @code{add-symbol-file}, described below),
7637 for more information.
7638
7639 @item file
7640 @code{file} with no argument makes @value{GDBN} discard any information it
7641 has on both executable file and the symbol table.
7642
7643 @kindex exec-file
7644 @item exec-file @r{[} @var{filename} @r{]}
7645 Specify that the program to be run (but not the symbol table) is found
7646 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7647 if necessary to locate your program. Omitting @var{filename} means to
7648 discard information on the executable file.
7649
7650 @kindex symbol-file
7651 @item symbol-file @r{[} @var{filename} @r{]}
7652 Read symbol table information from file @var{filename}. @code{PATH} is
7653 searched when necessary. Use the @code{file} command to get both symbol
7654 table and program to run from the same file.
7655
7656 @code{symbol-file} with no argument clears out @value{GDBN} information on your
7657 program's symbol table.
7658
7659 The @code{symbol-file} command causes @value{GDBN} to forget the contents
7660 of its convenience variables, the value history, and all breakpoints and
7661 auto-display expressions. This is because they may contain pointers to
7662 the internal data recording symbols and data types, which are part of
7663 the old symbol table data being discarded inside @value{GDBN}.
7664
7665 @code{symbol-file} does not repeat if you press @key{RET} again after
7666 executing it once.
7667
7668 When @value{GDBN} is configured for a particular environment, it
7669 understands debugging information in whatever format is the standard
7670 generated for that environment; you may use either a @sc{gnu} compiler, or
7671 other compilers that adhere to the local conventions.
7672 Best results are usually obtained from @sc{gnu} compilers; for example,
7673 using @code{@value{GCC}} you can generate debugging information for
7674 optimized code.
7675
7676 For most kinds of object files, with the exception of old SVR3 systems
7677 using COFF, the @code{symbol-file} command does not normally read the
7678 symbol table in full right away. Instead, it scans the symbol table
7679 quickly to find which source files and which symbols are present. The
7680 details are read later, one source file at a time, as they are needed.
7681
7682 The purpose of this two-stage reading strategy is to make @value{GDBN}
7683 start up faster. For the most part, it is invisible except for
7684 occasional pauses while the symbol table details for a particular source
7685 file are being read. (The @code{set verbose} command can turn these
7686 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7687 warnings and messages}.)
7688
7689 We have not implemented the two-stage strategy for COFF yet. When the
7690 symbol table is stored in COFF format, @code{symbol-file} reads the
7691 symbol table data in full right away. Note that ``stabs-in-COFF''
7692 still does the two-stage strategy, since the debug info is actually
7693 in stabs format.
7694
7695 @kindex readnow
7696 @cindex reading symbols immediately
7697 @cindex symbols, reading immediately
7698 @kindex mapped
7699 @cindex memory-mapped symbol file
7700 @cindex saving symbol table
7701 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7702 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7703 You can override the @value{GDBN} two-stage strategy for reading symbol
7704 tables by using the @samp{-readnow} option with any of the commands that
7705 load symbol table information, if you want to be sure @value{GDBN} has the
7706 entire symbol table available.
7707
7708 If memory-mapped files are available on your system through the
7709 @code{mmap} system call, you can use another option, @samp{-mapped}, to
7710 cause @value{GDBN} to write the symbols for your program into a reusable
7711 file. Future @value{GDBN} debugging sessions map in symbol information
7712 from this auxiliary symbol file (if the program has not changed), rather
7713 than spending time reading the symbol table from the executable
7714 program. Using the @samp{-mapped} option has the same effect as
7715 starting @value{GDBN} with the @samp{-mapped} command-line option.
7716
7717 You can use both options together, to make sure the auxiliary symbol
7718 file has all the symbol information for your program.
7719
7720 The auxiliary symbol file for a program called @var{myprog} is called
7721 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7722 than the corresponding executable), @value{GDBN} always attempts to use
7723 it when you debug @var{myprog}; no special options or commands are
7724 needed.
7725
7726 The @file{.syms} file is specific to the host machine where you run
7727 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
7728 symbol table. It cannot be shared across multiple host platforms.
7729
7730 @c FIXME: for now no mention of directories, since this seems to be in
7731 @c flux. 13mar1992 status is that in theory GDB would look either in
7732 @c current dir or in same dir as myprog; but issues like competing
7733 @c GDB's, or clutter in system dirs, mean that in practice right now
7734 @c only current dir is used. FFish says maybe a special GDB hierarchy
7735 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7736 @c files.
7737
7738 @kindex core
7739 @kindex core-file
7740 @item core-file @r{[} @var{filename} @r{]}
7741 Specify the whereabouts of a core dump file to be used as the ``contents
7742 of memory''. Traditionally, core files contain only some parts of the
7743 address space of the process that generated them; @value{GDBN} can access the
7744 executable file itself for other parts.
7745
7746 @code{core-file} with no argument specifies that no core file is
7747 to be used.
7748
7749 Note that the core file is ignored when your program is actually running
7750 under @value{GDBN}. So, if you have been running your program and you
7751 wish to debug a core file instead, you must kill the subprocess in which
7752 the program is running. To do this, use the @code{kill} command
7753 (@pxref{Kill Process, ,Killing the child process}).
7754
7755 @kindex add-symbol-file
7756 @cindex dynamic linking
7757 @item add-symbol-file @var{filename} @var{address}
7758 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7759 @itemx add-symbol-file @var{filename} @var{address} @var{data_address} @var{bss_address}
7760 @itemx add-symbol-file @var{filename} @r{-T}@var{section} @var{address}
7761 The @code{add-symbol-file} command reads additional symbol table information
7762 from the file @var{filename}. You would use this command when @var{filename}
7763 has been dynamically loaded (by some other means) into the program that
7764 is running. @var{address} should be the memory address at which the
7765 file has been loaded; @value{GDBN} cannot figure this out for itself.
7766 You can specify up to three addresses, in which case they are taken to be
7767 the addresses of the text, data, and bss segments respectively.
7768 For complicated cases, you can specify an arbitrary number of @r{-T}@var{section} @var{address}
7769 pairs, to give an explicit section name and base address for that section.
7770 You can specify any @var{address} as an expression.
7771
7772 The symbol table of the file @var{filename} is added to the symbol table
7773 originally read with the @code{symbol-file} command. You can use the
7774 @code{add-symbol-file} command any number of times; the new symbol data thus
7775 read keeps adding to the old. To discard all old symbol data instead,
7776 use the @code{symbol-file} command.
7777
7778 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
7779
7780 You can use the @samp{-mapped} and @samp{-readnow} options just as with
7781 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
7782 table information for @var{filename}.
7783
7784 @kindex add-shared-symbol-file
7785 @item add-shared-symbol-file
7786 The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
7787 operating system for the Motorola 88k. @value{GDBN} automatically looks for
7788 shared libraries, however if @value{GDBN} does not find yours, you can run
7789 @code{add-shared-symbol-file}. It takes no arguments.
7790
7791 @kindex section
7792 @item section
7793 The @code{section} command changes the base address of section SECTION of
7794 the exec file to ADDR. This can be used if the exec file does not contain
7795 section addresses, (such as in the a.out format), or when the addresses
7796 specified in the file itself are wrong. Each section must be changed
7797 separately. The @code{info files} command, described below, lists all
7798 the sections and their addresses.
7799
7800 @kindex info files
7801 @kindex info target
7802 @item info files
7803 @itemx info target
7804 @code{info files} and @code{info target} are synonymous; both print the
7805 current target (@pxref{Targets, ,Specifying a Debugging Target}),
7806 including the names of the executable and core dump files currently in
7807 use by @value{GDBN}, and the files from which symbols were loaded. The
7808 command @code{help target} lists all possible targets rather than
7809 current ones.
7810
7811 @end table
7812
7813 All file-specifying commands allow both absolute and relative file names
7814 as arguments. @value{GDBN} always converts the file name to an absolute file
7815 name and remembers it that way.
7816
7817 @cindex shared libraries
7818 @value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
7819 libraries.
7820
7821 @value{GDBN} automatically loads symbol definitions from shared libraries
7822 when you use the @code{run} command, or when you examine a core file.
7823 (Before you issue the @code{run} command, @value{GDBN} does not understand
7824 references to a function in a shared library, however---unless you are
7825 debugging a core file).
7826
7827 On HP-UX, if the program loads a library explicitly, @value{GDBN}
7828 automatically loads the symbols at the time of the @code{shl_load} call.
7829
7830 @c FIXME: some @value{GDBN} release may permit some refs to undef
7831 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
7832 @c FIXME...lib; check this from time to time when updating manual
7833
7834 @table @code
7835 @kindex info sharedlibrary
7836 @kindex info share
7837 @item info share
7838 @itemx info sharedlibrary
7839 Print the names of the shared libraries which are currently loaded.
7840
7841 @kindex sharedlibrary
7842 @kindex share
7843 @item sharedlibrary @var{regex}
7844 @itemx share @var{regex}
7845 Load shared object library symbols for files matching a
7846 Unix regular expression.
7847 As with files loaded automatically, it only loads shared libraries
7848 required by your program for a core file or after typing @code{run}. If
7849 @var{regex} is omitted all shared libraries required by your program are
7850 loaded.
7851 @end table
7852
7853 On HP-UX systems, @value{GDBN} detects the loading of a shared library
7854 and automatically reads in symbols from the newly loaded library, up to
7855 a threshold that is initially set but that you can modify if you wish.
7856
7857 Beyond that threshold, symbols from shared libraries must be explicitly
7858 loaded. To load these symbols, use the command @code{sharedlibrary
7859 @var{filename}}. The base address of the shared library is determined
7860 automatically by @value{GDBN} and need not be specified.
7861
7862 To display or set the threshold, use the commands:
7863
7864 @table @code
7865 @kindex set auto-solib-add
7866 @item set auto-solib-add @var{threshold}
7867 Set the autoloading size threshold, in megabytes. If @var{threshold} is
7868 nonzero, symbols from all shared object libraries will be loaded
7869 automatically when the inferior begins execution or when the dynamic
7870 linker informs @value{GDBN} that a new library has been loaded, until
7871 the symbol table of the program and libraries exceeds this threshold.
7872 Otherwise, symbols must be loaded manually, using the
7873 @code{sharedlibrary} command. The default threshold is 100 megabytes.
7874
7875 @kindex show auto-solib-add
7876 @item show auto-solib-add
7877 Display the current autoloading size threshold, in megabytes.
7878 @end table
7879
7880 @node Symbol Errors
7881 @section Errors reading symbol files
7882
7883 While reading a symbol file, @value{GDBN} occasionally encounters problems,
7884 such as symbol types it does not recognize, or known bugs in compiler
7885 output. By default, @value{GDBN} does not notify you of such problems, since
7886 they are relatively common and primarily of interest to people
7887 debugging compilers. If you are interested in seeing information
7888 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
7889 only one message about each such type of problem, no matter how many
7890 times the problem occurs; or you can ask @value{GDBN} to print more messages,
7891 to see how many times the problems occur, with the @code{set
7892 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
7893 messages}).
7894
7895 The messages currently printed, and their meanings, include:
7896
7897 @table @code
7898 @item inner block not inside outer block in @var{symbol}
7899
7900 The symbol information shows where symbol scopes begin and end
7901 (such as at the start of a function or a block of statements). This
7902 error indicates that an inner scope block is not fully contained
7903 in its outer scope blocks.
7904
7905 @value{GDBN} circumvents the problem by treating the inner block as if it had
7906 the same scope as the outer block. In the error message, @var{symbol}
7907 may be shown as ``@code{(don't know)}'' if the outer block is not a
7908 function.
7909
7910 @item block at @var{address} out of order
7911
7912 The symbol information for symbol scope blocks should occur in
7913 order of increasing addresses. This error indicates that it does not
7914 do so.
7915
7916 @value{GDBN} does not circumvent this problem, and has trouble
7917 locating symbols in the source file whose symbols it is reading. (You
7918 can often determine what source file is affected by specifying
7919 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
7920 messages}.)
7921
7922 @item bad block start address patched
7923
7924 The symbol information for a symbol scope block has a start address
7925 smaller than the address of the preceding source line. This is known
7926 to occur in the SunOS 4.1.1 (and earlier) C compiler.
7927
7928 @value{GDBN} circumvents the problem by treating the symbol scope block as
7929 starting on the previous source line.
7930
7931 @item bad string table offset in symbol @var{n}
7932
7933 @cindex foo
7934 Symbol number @var{n} contains a pointer into the string table which is
7935 larger than the size of the string table.
7936
7937 @value{GDBN} circumvents the problem by considering the symbol to have the
7938 name @code{foo}, which may cause other problems if many symbols end up
7939 with this name.
7940
7941 @item unknown symbol type @code{0x@var{nn}}
7942
7943 The symbol information contains new data types that @value{GDBN} does
7944 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
7945 uncomprehended information, in hexadecimal.
7946
7947 @value{GDBN} circumvents the error by ignoring this symbol information.
7948 This usually allows you to debug your program, though certain symbols
7949 are not accessible. If you encounter such a problem and feel like
7950 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
7951 on @code{complain}, then go up to the function @code{read_dbx_symtab}
7952 and examine @code{*bufp} to see the symbol.
7953
7954 @item stub type has NULL name
7955
7956 @value{GDBN} could not find the full definition for a struct or class.
7957
7958 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
7959 The symbol information for a C++ member function is missing some
7960 information that recent versions of the compiler should have output for
7961 it.
7962
7963 @item info mismatch between compiler and debugger
7964
7965 @value{GDBN} could not parse a type specification output by the compiler.
7966
7967 @end table
7968
7969 @node Targets
7970 @chapter Specifying a Debugging Target
7971
7972 @cindex debugging target
7973 @kindex target
7974
7975 A @dfn{target} is the execution environment occupied by your program.
7976
7977 Often, @value{GDBN} runs in the same host environment as your program;
7978 in that case, the debugging target is specified as a side effect when
7979 you use the @code{file} or @code{core} commands. When you need more
7980 flexibility---for example, running @value{GDBN} on a physically separate
7981 host, or controlling a standalone system over a serial port or a
7982 realtime system over a TCP/IP connection---you can use the @code{target}
7983 command to specify one of the target types configured for @value{GDBN}
7984 (@pxref{Target Commands, ,Commands for managing targets}).
7985
7986 @menu
7987 * Active Targets:: Active targets
7988 * Target Commands:: Commands for managing targets
7989 * Byte Order:: Choosing target byte order
7990 * Remote:: Remote debugging
7991 * KOD:: Kernel Object Display
7992
7993 @end menu
7994
7995 @node Active Targets
7996 @section Active targets
7997
7998 @cindex stacking targets
7999 @cindex active targets
8000 @cindex multiple targets
8001
8002 There are three classes of targets: processes, core files, and
8003 executable files. @value{GDBN} can work concurrently on up to three
8004 active targets, one in each class. This allows you to (for example)
8005 start a process and inspect its activity without abandoning your work on
8006 a core file.
8007
8008 For example, if you execute @samp{gdb a.out}, then the executable file
8009 @code{a.out} is the only active target. If you designate a core file as
8010 well---presumably from a prior run that crashed and coredumped---then
8011 @value{GDBN} has two active targets and uses them in tandem, looking
8012 first in the corefile target, then in the executable file, to satisfy
8013 requests for memory addresses. (Typically, these two classes of target
8014 are complementary, since core files contain only a program's
8015 read-write memory---variables and so on---plus machine status, while
8016 executable files contain only the program text and initialized data.)
8017
8018 When you type @code{run}, your executable file becomes an active process
8019 target as well. When a process target is active, all @value{GDBN}
8020 commands requesting memory addresses refer to that target; addresses in
8021 an active core file or executable file target are obscured while the
8022 process target is active.
8023
8024 Use the @code{core-file} and @code{exec-file} commands to select a new
8025 core file or executable target (@pxref{Files, ,Commands to specify
8026 files}). To specify as a target a process that is already running, use
8027 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8028 process}).
8029
8030 @node Target Commands
8031 @section Commands for managing targets
8032
8033 @table @code
8034 @item target @var{type} @var{parameters}
8035 Connects the @value{GDBN} host environment to a target machine or
8036 process. A target is typically a protocol for talking to debugging
8037 facilities. You use the argument @var{type} to specify the type or
8038 protocol of the target machine.
8039
8040 Further @var{parameters} are interpreted by the target protocol, but
8041 typically include things like device names or host names to connect
8042 with, process numbers, and baud rates.
8043
8044 The @code{target} command does not repeat if you press @key{RET} again
8045 after executing the command.
8046
8047 @kindex help target
8048 @item help target
8049 Displays the names of all targets available. To display targets
8050 currently selected, use either @code{info target} or @code{info files}
8051 (@pxref{Files, ,Commands to specify files}).
8052
8053 @item help target @var{name}
8054 Describe a particular target, including any parameters necessary to
8055 select it.
8056
8057 @kindex set gnutarget
8058 @item set gnutarget @var{args}
8059 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
8060 knows whether it is reading an @dfn{executable},
8061 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8062 with the @code{set gnutarget} command. Unlike most @code{target} commands,
8063 with @code{gnutarget} the @code{target} refers to a program, not a machine.
8064
8065 @quotation
8066 @emph{Warning:} To specify a file format with @code{set gnutarget},
8067 you must know the actual BFD name.
8068 @end quotation
8069
8070 @noindent
8071 @xref{Files, , Commands to specify files}.
8072
8073 @kindex show gnutarget
8074 @item show gnutarget
8075 Use the @code{show gnutarget} command to display what file format
8076 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
8077 @value{GDBN} will determine the file format for each file automatically,
8078 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8079 @end table
8080
8081 Here are some common targets (available, or not, depending on the GDB
8082 configuration):
8083
8084 @table @code
8085 @kindex target exec
8086 @item target exec @var{program}
8087 An executable file. @samp{target exec @var{program}} is the same as
8088 @samp{exec-file @var{program}}.
8089
8090 @kindex target core
8091 @item target core @var{filename}
8092 A core dump file. @samp{target core @var{filename}} is the same as
8093 @samp{core-file @var{filename}}.
8094
8095 @kindex target remote
8096 @item target remote @var{dev}
8097 Remote serial target in GDB-specific protocol. The argument @var{dev}
8098 specifies what serial device to use for the connection (e.g.
8099 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
8100 supports the @code{load} command. This is only useful if you have
8101 some other way of getting the stub to the target system, and you can put
8102 it somewhere in memory where it won't get clobbered by the download.
8103
8104 @kindex target sim
8105 @item target sim
8106 Builtin CPU simulator. GDB includes simulators for most architectures.
8107 In general,
8108 @example
8109 target sim
8110 load
8111 run
8112 @end example
8113 @noindent
8114 works; however, you cannot assume that a specific memory map, device
8115 drivers, or even basic I/O is available, although some simulators do
8116 provide these. For info about any processor-specific simulator details,
8117 see the appropriate section in @ref{Embedded Processors, ,Embedded
8118 Processors}.
8119
8120 @end table
8121
8122 Some configurations may include these targets as well:
8123
8124 @table @code
8125
8126 @kindex target nrom
8127 @item target nrom @var{dev}
8128 NetROM ROM emulator. This target only supports downloading.
8129
8130 @end table
8131
8132 Different targets are available on different configurations of @value{GDBN};
8133 your configuration may have more or fewer targets.
8134
8135 Many remote targets require you to download the executable's code
8136 once you've successfully established a connection.
8137
8138 @table @code
8139
8140 @kindex load @var{filename}
8141 @item load @var{filename}
8142 Depending on what remote debugging facilities are configured into
8143 @value{GDBN}, the @code{load} command may be available. Where it exists, it
8144 is meant to make @var{filename} (an executable) available for debugging
8145 on the remote system---by downloading, or dynamic linking, for example.
8146 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8147 the @code{add-symbol-file} command.
8148
8149 If your @value{GDBN} does not have a @code{load} command, attempting to
8150 execute it gets the error message ``@code{You can't do that when your
8151 target is @dots{}}''
8152
8153 The file is loaded at whatever address is specified in the executable.
8154 For some object file formats, you can specify the load address when you
8155 link the program; for other formats, like a.out, the object file format
8156 specifies a fixed address.
8157 @c FIXME! This would be a good place for an xref to the GNU linker doc.
8158
8159 @code{load} does not repeat if you press @key{RET} again after using it.
8160 @end table
8161
8162 @node Byte Order
8163 @section Choosing target byte order
8164
8165 @cindex choosing target byte order
8166 @cindex target byte order
8167 @kindex set endian big
8168 @kindex set endian little
8169 @kindex set endian auto
8170 @kindex show endian
8171
8172 Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8173 offer the ability to run either big-endian or little-endian byte
8174 orders. Usually the executable or symbol will include a bit to
8175 designate the endian-ness, and you will not need to worry about
8176 which to use. However, you may still find it useful to adjust
8177 @value{GDBN}'s idea of processor endian-ness manually.
8178
8179 @table @code
8180 @kindex set endian big
8181 @item set endian big
8182 Instruct @value{GDBN} to assume the target is big-endian.
8183
8184 @kindex set endian little
8185 @item set endian little
8186 Instruct @value{GDBN} to assume the target is little-endian.
8187
8188 @kindex set endian auto
8189 @item set endian auto
8190 Instruct @value{GDBN} to use the byte order associated with the
8191 executable.
8192
8193 @item show endian
8194 Display @value{GDBN}'s current idea of the target byte order.
8195
8196 @end table
8197
8198 Note that these commands merely adjust interpretation of symbolic
8199 data on the host, and that they have absolutely no effect on the
8200 target system.
8201
8202 @node Remote
8203 @section Remote debugging
8204 @cindex remote debugging
8205
8206 If you are trying to debug a program running on a machine that cannot run
8207 @value{GDBN} in the usual way, it is often useful to use remote debugging.
8208 For example, you might use remote debugging on an operating system kernel,
8209 or on a small system which does not have a general purpose operating system
8210 powerful enough to run a full-featured debugger.
8211
8212 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8213 to make this work with particular debugging targets. In addition,
8214 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
8215 but not specific to any particular target system) which you can use if you
8216 write the remote stubs---the code that runs on the remote system to
8217 communicate with @value{GDBN}.
8218
8219 Other remote targets may be available in your
8220 configuration of @value{GDBN}; use @code{help target} to list them.
8221
8222 @menu
8223 * Remote Serial:: @value{GDBN} remote serial protocol
8224 @end menu
8225
8226 @node Remote Serial
8227 @subsection The @value{GDBN} remote serial protocol
8228
8229 @cindex remote serial debugging, overview
8230 To debug a program running on another machine (the debugging
8231 @dfn{target} machine), you must first arrange for all the usual
8232 prerequisites for the program to run by itself. For example, for a C
8233 program, you need:
8234
8235 @enumerate
8236 @item
8237 A startup routine to set up the C runtime environment; these usually
8238 have a name like @file{crt0}. The startup routine may be supplied by
8239 your hardware supplier, or you may have to write your own.
8240
8241 @item
8242 A C subroutine library to support your program's
8243 subroutine calls, notably managing input and output.
8244
8245 @item
8246 A way of getting your program to the other machine---for example, a
8247 download program. These are often supplied by the hardware
8248 manufacturer, but you may have to write your own from hardware
8249 documentation.
8250 @end enumerate
8251
8252 The next step is to arrange for your program to use a serial port to
8253 communicate with the machine where @value{GDBN} is running (the @dfn{host}
8254 machine). In general terms, the scheme looks like this:
8255
8256 @table @emph
8257 @item On the host,
8258 @value{GDBN} already understands how to use this protocol; when everything
8259 else is set up, you can simply use the @samp{target remote} command
8260 (@pxref{Targets,,Specifying a Debugging Target}).
8261
8262 @item On the target,
8263 you must link with your program a few special-purpose subroutines that
8264 implement the @value{GDBN} remote serial protocol. The file containing these
8265 subroutines is called a @dfn{debugging stub}.
8266
8267 On certain remote targets, you can use an auxiliary program
8268 @code{gdbserver} instead of linking a stub into your program.
8269 @xref{Server,,Using the @code{gdbserver} program}, for details.
8270 @end table
8271
8272 The debugging stub is specific to the architecture of the remote
8273 machine; for example, use @file{sparc-stub.c} to debug programs on
8274 @sc{sparc} boards.
8275
8276 @cindex remote serial stub list
8277 These working remote stubs are distributed with @value{GDBN}:
8278
8279 @table @code
8280
8281 @item i386-stub.c
8282 @kindex i386-stub.c
8283 @cindex Intel
8284 @cindex i386
8285 For Intel 386 and compatible architectures.
8286
8287 @item m68k-stub.c
8288 @kindex m68k-stub.c
8289 @cindex Motorola 680x0
8290 @cindex m680x0
8291 For Motorola 680x0 architectures.
8292
8293 @item sh-stub.c
8294 @kindex sh-stub.c
8295 @cindex Hitachi
8296 @cindex SH
8297 For Hitachi SH architectures.
8298
8299 @item sparc-stub.c
8300 @kindex sparc-stub.c
8301 @cindex Sparc
8302 For @sc{sparc} architectures.
8303
8304 @item sparcl-stub.c
8305 @kindex sparcl-stub.c
8306 @cindex Fujitsu
8307 @cindex SparcLite
8308 For Fujitsu @sc{sparclite} architectures.
8309
8310 @end table
8311
8312 The @file{README} file in the @value{GDBN} distribution may list other
8313 recently added stubs.
8314
8315 @menu
8316 * Stub Contents:: What the stub can do for you
8317 * Bootstrapping:: What you must do for the stub
8318 * Debug Session:: Putting it all together
8319 * Protocol:: Definition of the communication protocol
8320 * Server:: Using the `gdbserver' program
8321 * NetWare:: Using the `gdbserve.nlm' program
8322 @end menu
8323
8324 @node Stub Contents
8325 @subsubsection What the stub can do for you
8326
8327 @cindex remote serial stub
8328 The debugging stub for your architecture supplies these three
8329 subroutines:
8330
8331 @table @code
8332 @item set_debug_traps
8333 @kindex set_debug_traps
8334 @cindex remote serial stub, initialization
8335 This routine arranges for @code{handle_exception} to run when your
8336 program stops. You must call this subroutine explicitly near the
8337 beginning of your program.
8338
8339 @item handle_exception
8340 @kindex handle_exception
8341 @cindex remote serial stub, main routine
8342 This is the central workhorse, but your program never calls it
8343 explicitly---the setup code arranges for @code{handle_exception} to
8344 run when a trap is triggered.
8345
8346 @code{handle_exception} takes control when your program stops during
8347 execution (for example, on a breakpoint), and mediates communications
8348 with @value{GDBN} on the host machine. This is where the communications
8349 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
8350 representative on the target machine. It begins by sending summary
8351 information on the state of your program, then continues to execute,
8352 retrieving and transmitting any information @value{GDBN} needs, until you
8353 execute a @value{GDBN} command that makes your program resume; at that point,
8354 @code{handle_exception} returns control to your own code on the target
8355 machine.
8356
8357 @item breakpoint
8358 @cindex @code{breakpoint} subroutine, remote
8359 Use this auxiliary subroutine to make your program contain a
8360 breakpoint. Depending on the particular situation, this may be the only
8361 way for @value{GDBN} to get control. For instance, if your target
8362 machine has some sort of interrupt button, you won't need to call this;
8363 pressing the interrupt button transfers control to
8364 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
8365 simply receiving characters on the serial port may also trigger a trap;
8366 again, in that situation, you don't need to call @code{breakpoint} from
8367 your own program---simply running @samp{target remote} from the host
8368 @value{GDBN} session gets control.
8369
8370 Call @code{breakpoint} if none of these is true, or if you simply want
8371 to make certain your program stops at a predetermined point for the
8372 start of your debugging session.
8373 @end table
8374
8375 @node Bootstrapping
8376 @subsubsection What you must do for the stub
8377
8378 @cindex remote stub, support routines
8379 The debugging stubs that come with @value{GDBN} are set up for a particular
8380 chip architecture, but they have no information about the rest of your
8381 debugging target machine.
8382
8383 First of all you need to tell the stub how to communicate with the
8384 serial port.
8385
8386 @table @code
8387 @item int getDebugChar()
8388 @kindex getDebugChar
8389 Write this subroutine to read a single character from the serial port.
8390 It may be identical to @code{getchar} for your target system; a
8391 different name is used to allow you to distinguish the two if you wish.
8392
8393 @item void putDebugChar(int)
8394 @kindex putDebugChar
8395 Write this subroutine to write a single character to the serial port.
8396 It may be identical to @code{putchar} for your target system; a
8397 different name is used to allow you to distinguish the two if you wish.
8398 @end table
8399
8400 @cindex control C, and remote debugging
8401 @cindex interrupting remote targets
8402 If you want @value{GDBN} to be able to stop your program while it is
8403 running, you need to use an interrupt-driven serial driver, and arrange
8404 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
8405 character). That is the character which @value{GDBN} uses to tell the
8406 remote system to stop.
8407
8408 Getting the debugging target to return the proper status to @value{GDBN}
8409 probably requires changes to the standard stub; one quick and dirty way
8410 is to just execute a breakpoint instruction (the ``dirty'' part is that
8411 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
8412
8413 Other routines you need to supply are:
8414
8415 @table @code
8416 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
8417 @kindex exceptionHandler
8418 Write this function to install @var{exception_address} in the exception
8419 handling tables. You need to do this because the stub does not have any
8420 way of knowing what the exception handling tables on your target system
8421 are like (for example, the processor's table might be in @sc{rom},
8422 containing entries which point to a table in @sc{ram}).
8423 @var{exception_number} is the exception number which should be changed;
8424 its meaning is architecture-dependent (for example, different numbers
8425 might represent divide by zero, misaligned access, etc). When this
8426 exception occurs, control should be transferred directly to
8427 @var{exception_address}, and the processor state (stack, registers,
8428 and so on) should be just as it is when a processor exception occurs. So if
8429 you want to use a jump instruction to reach @var{exception_address}, it
8430 should be a simple jump, not a jump to subroutine.
8431
8432 For the 386, @var{exception_address} should be installed as an interrupt
8433 gate so that interrupts are masked while the handler runs. The gate
8434 should be at privilege level 0 (the most privileged level). The
8435 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
8436 help from @code{exceptionHandler}.
8437
8438 @item void flush_i_cache()
8439 @kindex flush_i_cache
8440 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
8441 instruction cache, if any, on your target machine. If there is no
8442 instruction cache, this subroutine may be a no-op.
8443
8444 On target machines that have instruction caches, @value{GDBN} requires this
8445 function to make certain that the state of your program is stable.
8446 @end table
8447
8448 @noindent
8449 You must also make sure this library routine is available:
8450
8451 @table @code
8452 @item void *memset(void *, int, int)
8453 @kindex memset
8454 This is the standard library function @code{memset} that sets an area of
8455 memory to a known value. If you have one of the free versions of
8456 @code{libc.a}, @code{memset} can be found there; otherwise, you must
8457 either obtain it from your hardware manufacturer, or write your own.
8458 @end table
8459
8460 If you do not use the GNU C compiler, you may need other standard
8461 library subroutines as well; this varies from one stub to another,
8462 but in general the stubs are likely to use any of the common library
8463 subroutines which @code{@value{GCC}} generates as inline code.
8464
8465
8466 @node Debug Session
8467 @subsubsection Putting it all together
8468
8469 @cindex remote serial debugging summary
8470 In summary, when your program is ready to debug, you must follow these
8471 steps.
8472
8473 @enumerate
8474 @item
8475 Make sure you have the supporting low-level routines
8476 (@pxref{Bootstrapping,,What you must do for the stub}):
8477 @display
8478 @code{getDebugChar}, @code{putDebugChar},
8479 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
8480 @end display
8481
8482 @item
8483 Insert these lines near the top of your program:
8484
8485 @example
8486 set_debug_traps();
8487 breakpoint();
8488 @end example
8489
8490 @item
8491 For the 680x0 stub only, you need to provide a variable called
8492 @code{exceptionHook}. Normally you just use:
8493
8494 @example
8495 void (*exceptionHook)() = 0;
8496 @end example
8497
8498 @noindent
8499 but if before calling @code{set_debug_traps}, you set it to point to a
8500 function in your program; that function is called when
8501 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
8502 error). The function indicated by @code{exceptionHook} is called with
8503 one parameter: an @code{int} which is the exception number.
8504
8505 @item
8506 Compile and link together: your program, the @value{GDBN} debugging stub for
8507 your target architecture, and the supporting subroutines.
8508
8509 @item
8510 Make sure you have a serial connection between your target machine and
8511 the @value{GDBN} host, and identify the serial port on the host.
8512
8513 @item
8514 @c The "remote" target now provides a `load' command, so we should
8515 @c document that. FIXME.
8516 Download your program to your target machine (or get it there by
8517 whatever means the manufacturer provides), and start it.
8518
8519 @item
8520 To start remote debugging, run @value{GDBN} on the host machine, and specify
8521 as an executable file the program that is running in the remote machine.
8522 This tells @value{GDBN} how to find your program's symbols and the contents
8523 of its pure text.
8524
8525 @item
8526 @cindex serial line, @code{target remote}
8527 Establish communication using the @code{target remote} command.
8528 Its argument specifies how to communicate with the target
8529 machine---either via a devicename attached to a direct serial line, or a
8530 TCP port (usually to a terminal server which in turn has a serial line
8531 to the target). For example, to use a serial line connected to the
8532 device named @file{/dev/ttyb}:
8533
8534 @example
8535 target remote /dev/ttyb
8536 @end example
8537
8538 @cindex TCP port, @code{target remote}
8539 To use a TCP connection, use an argument of the form
8540 @code{@var{host}:port}. For example, to connect to port 2828 on a
8541 terminal server named @code{manyfarms}:
8542
8543 @example
8544 target remote manyfarms:2828
8545 @end example
8546 @end enumerate
8547
8548 Now you can use all the usual commands to examine and change data and to
8549 step and continue the remote program.
8550
8551 To resume the remote program and stop debugging it, use the @code{detach}
8552 command.
8553
8554 @cindex interrupting remote programs
8555 @cindex remote programs, interrupting
8556 Whenever @value{GDBN} is waiting for the remote program, if you type the
8557 interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
8558 program. This may or may not succeed, depending in part on the hardware
8559 and the serial drivers the remote system uses. If you type the
8560 interrupt character once again, @value{GDBN} displays this prompt:
8561
8562 @example
8563 Interrupted while waiting for the program.
8564 Give up (and stop debugging it)? (y or n)
8565 @end example
8566
8567 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
8568 (If you decide you want to try again later, you can use @samp{target
8569 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
8570 goes back to waiting.
8571
8572 @node Protocol
8573 @subsubsection Communication protocol
8574
8575 @cindex debugging stub, example
8576 @cindex remote stub, example
8577 @cindex stub example, remote debugging
8578 The stub files provided with @value{GDBN} implement the target side of the
8579 communication protocol, and the @value{GDBN} side is implemented in the
8580 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
8581 these subroutines to communicate, and ignore the details. (If you're
8582 implementing your own stub file, you can still ignore the details: start
8583 with one of the existing stub files. @file{sparc-stub.c} is the best
8584 organized, and therefore the easiest to read.)
8585
8586 However, there may be occasions when you need to know something about
8587 the protocol---for example, if there is only one serial port to your
8588 target machine, you might want your program to do something special if
8589 it recognizes a packet meant for @value{GDBN}.
8590
8591 In the examples below, @samp{<-} and @samp{->} are used to indicate
8592 transmitted and received data respectfully.
8593
8594 @cindex protocol, @value{GDBN} remote serial
8595 @cindex serial protocol, @value{GDBN} remote
8596 @cindex remote serial protocol
8597 All @value{GDBN} commands and responses (other than acknowledgments)
8598 are sent as a @var{packet}. A @var{packet} is introduced with the
8599 character @samp{$}, this is followed by an optional two-digit
8600 @var{sequence-id} and the character @samp{:}, the actual
8601 @var{packet-data}, and the terminating character @samp{#} followed by a
8602 two-digit @var{checksum}:
8603
8604 @example
8605 @code{$}@var{packet-data}@code{#}@var{checksum}
8606 @end example
8607 @noindent
8608 or, with the optional @var{sequence-id}:
8609 @example
8610 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8611 @end example
8612
8613 @cindex checksum, for @value{GDBN} remote
8614 @noindent
8615 The two-digit @var{checksum} is computed as the modulo 256 sum of all
8616 characters between the leading @samp{$} and the trailing @samp{#} (that
8617 consisting of both the optional @var{sequence-id}@code{:} and the actual
8618 @var{packet-data}) (an eight bit unsigned checksum).
8619
8620 @cindex sequence-id, for @value{GDBN} remote
8621 @noindent
8622 The two-digit @var{sequence-id}, when present, is returned with the
8623 acknowledgment. Beyond that its meaning is poorly defined.
8624 @value{GDBN} is not known to output @var{sequence-id}s.
8625
8626 When either the host or the target machine receives a packet, the first
8627 response expected is an acknowledgment: either @samp{+} (to indicate
8628 the package was received correctly) or @samp{-} (to request
8629 retransmission):
8630
8631 @example
8632 <- @code{$}@var{packet-data}@code{#}@var{checksum}
8633 -> @code{+}
8634 @end example
8635 @noindent
8636 If the received packet included a @var{sequence-id} than that is
8637 appended to a positive acknowledgment:
8638
8639 @example
8640 <- @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8641 -> @code{+}@var{sequence-id}
8642 @end example
8643
8644 The host (@value{GDBN}) sends @var{command}s, and the target (the
8645 debugging stub incorporated in your program) sends a @var{response}. In
8646 the case of step and continue @var{command}s, the response is only sent
8647 when the operation has completed (the target has again stopped).
8648
8649 @var{packet-data} consists of a sequence of characters with the
8650 exception of @samp{#} and @samp{$} (see @samp{X} packet for an
8651 exception). @samp{:} can not appear as the third character in a packet.
8652 Fields within the packet should be separated using @samp{,} and @samp{;}
8653 (unfortunately some packets chose to use @samp{:}). Except where
8654 otherwise noted all numbers are represented in HEX with leading zeros
8655 suppressed.
8656
8657 Response @var{data} can be run-length encoded to save space. A @samp{*}
8658 means that the next character is an ASCII encoding giving a repeat count
8659 which stands for that many repetitions of the character preceding the
8660 @samp{*}. The encoding is @code{n+29}, yielding a printable character
8661 where @code{n >=3} (which is where rle starts to win). The printable
8662 characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
8663 value greater than 126 should not be used.
8664
8665 Some remote systems have used a different run-length encoding mechanism
8666 loosely refered to as the cisco encoding. Following the @samp{*}
8667 character are two hex digits that indicate the size of the packet.
8668
8669 So:
8670 @example
8671 "@code{0* }"
8672 @end example
8673 @noindent
8674 means the same as "0000".
8675
8676 The error response, returned for some packets includes a two character
8677 error number. That number is not well defined.
8678
8679 For any @var{command} not supported by the stub, an empty response
8680 (@samp{$#00}) should be returned. That way it is possible to extend the
8681 protocol. A newer @value{GDBN} can tell if a packet is supported based
8682 on that response.
8683
8684 Below is a complete list of all currently defined @var{command}s and
8685 their corresponding response @var{data}:
8686
8687 @multitable @columnfractions .30 .30 .40
8688 @item Packet
8689 @tab Request
8690 @tab Description
8691
8692 @item extended ops @emph{(optional)}
8693 @tab @code{!}
8694 @tab
8695 Use the extended remote protocol. Sticky---only needs to be set once.
8696 The extended remote protocol support the @samp{R} packet.
8697 @item
8698 @tab reply @samp{}
8699 @tab
8700 Stubs that support the extended remote protocol return @samp{} which,
8701 unfortunately, is identical to the response returned by stubs that do not
8702 support protocol extensions.
8703
8704 @item last signal
8705 @tab @code{?}
8706 @tab
8707 Indicate the reason the target halted. The reply is the same as for step
8708 and continue.
8709 @item
8710 @tab reply
8711 @tab see below
8712
8713
8714 @item reserved
8715 @tab @code{a}
8716 @tab Reserved for future use
8717
8718 @item set program arguments @strong{(reserved)} @emph{(optional)}
8719 @tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
8720 @tab
8721 Initialized @samp{argv[]} array passed into program. @var{arglen}
8722 specifies the number of bytes in the hex encoded byte stream @var{arg}.
8723 See @file{gdbserver} for more details.
8724 @item
8725 @tab reply @code{OK}
8726 @item
8727 @tab reply @code{E}@var{NN}
8728
8729 @item set baud @strong{(deprecated)}
8730 @tab @code{b}@var{baud}
8731 @tab
8732 Change the serial line speed to @var{baud}. JTC: @emph{When does the
8733 transport layer state change? When it's received, or after the ACK is
8734 transmitted. In either case, there are problems if the command or the
8735 acknowledgment packet is dropped.} Stan: @emph{If people really wanted
8736 to add something like this, and get it working for the first time, they
8737 ought to modify ser-unix.c to send some kind of out-of-band message to a
8738 specially-setup stub and have the switch happen "in between" packets, so
8739 that from remote protocol's point of view, nothing actually
8740 happened.}
8741
8742 @item set breakpoint @strong{(deprecated)}
8743 @tab @code{B}@var{addr},@var{mode}
8744 @tab
8745 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
8746 breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
8747 @samp{z} packets.}
8748
8749 @item continue
8750 @tab @code{c}@var{addr}
8751 @tab
8752 @var{addr} is address to resume. If @var{addr} is omitted, resume at
8753 current address.
8754 @item
8755 @tab reply
8756 @tab see below
8757
8758 @item continue with signal @emph{(optional)}
8759 @tab @code{C}@var{sig}@code{;}@var{addr}
8760 @tab
8761 Continue with signal @var{sig} (hex signal number). If
8762 @code{;}@var{addr} is omitted, resume at same address.
8763 @item
8764 @tab reply
8765 @tab see below
8766
8767 @item toggle debug @emph{(deprecated)}
8768 @tab @code{d}
8769 @tab
8770 toggle debug flag.
8771
8772 @item detach @emph{(optional)}
8773 @tab @code{D}
8774 @tab
8775 Detach GDB from the remote system. Sent to the remote target before
8776 GDB disconnects.
8777 @item
8778 @tab reply @emph{no response}
8779 @tab
8780 GDB does not check for any response after sending this packet
8781
8782 @item reserved
8783 @tab @code{e}
8784 @tab Reserved for future use
8785
8786 @item reserved
8787 @tab @code{E}
8788 @tab Reserved for future use
8789
8790 @item reserved
8791 @tab @code{f}
8792 @tab Reserved for future use
8793
8794 @item reserved
8795 @tab @code{F}
8796 @tab Reserved for future use
8797
8798 @item read registers
8799 @tab @code{g}
8800 @tab Read general registers.
8801 @item
8802 @tab reply @var{XX...}
8803 @tab
8804 Each byte of register data is described by two hex digits. The bytes
8805 with the register are transmitted in target byte order. The size of
8806 each register and their position within the @samp{g} @var{packet} are
8807 determined by the GDB internal macros @var{REGISTER_RAW_SIZE} and
8808 @var{REGISTER_NAME} macros. The specification of several standard
8809 @code{g} packets is specified below.
8810 @item
8811 @tab @code{E}@var{NN}
8812 @tab for an error.
8813
8814 @item write regs
8815 @tab @code{G}@var{XX...}
8816 @tab
8817 See @samp{g} for a description of the @var{XX...} data.
8818 @item
8819 @tab reply @code{OK}
8820 @tab for success
8821 @item
8822 @tab reply @code{E}@var{NN}
8823 @tab for an error
8824
8825 @item reserved
8826 @tab @code{h}
8827 @tab Reserved for future use
8828
8829 @item set thread @emph{(optional)}
8830 @tab @code{H}@var{c}@var{t...}
8831 @tab
8832 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
8833 @samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
8834 continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
8835 thread used in other operations. If zero, pick a thread, any thread.
8836 @item
8837 @tab reply @code{OK}
8838 @tab for success
8839 @item
8840 @tab reply @code{E}@var{NN}
8841 @tab for an error
8842
8843 @c FIXME: JTC:
8844 @c 'H': How restrictive (or permissive) is the thread model. If a
8845 @c thread is selected and stopped, are other threads allowed
8846 @c to continue to execute? As I mentioned above, I think the
8847 @c semantics of each command when a thread is selected must be
8848 @c described. For example:
8849 @c
8850 @c 'g': If the stub supports threads and a specific thread is
8851 @c selected, returns the register block from that thread;
8852 @c otherwise returns current registers.
8853 @c
8854 @c 'G' If the stub supports threads and a specific thread is
8855 @c selected, sets the registers of the register block of
8856 @c that thread; otherwise sets current registers.
8857
8858 @item cycle step @strong{(draft)} @emph{(optional)}
8859 @tab @code{i}@var{addr}@code{,}@var{nnn}
8860 @tab
8861 Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
8862 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
8863 step starting at that address.
8864
8865 @item signal then cycle step @strong{(reserved)} @emph{(optional)}
8866 @tab @code{I}
8867 @tab
8868 See @samp{i} and @samp{S} for likely syntax and semantics.
8869
8870 @item reserved
8871 @tab @code{j}
8872 @tab Reserved for future use
8873
8874 @item reserved
8875 @tab @code{J}
8876 @tab Reserved for future use
8877
8878 @item kill request @emph{(optional)}
8879 @tab @code{k}
8880 @tab
8881 FIXME: @emph{There is no description of how operate when a specific
8882 thread context has been selected (ie. does 'k' kill only that thread?)}.
8883
8884 @item reserved
8885 @tab @code{l}
8886 @tab Reserved for future use
8887
8888 @item reserved
8889 @tab @code{L}
8890 @tab Reserved for future use
8891
8892 @item read memory
8893 @tab @code{m}@var{addr}@code{,}@var{length}
8894 @tab
8895 Read @var{length} bytes of memory starting at address @var{addr}.
8896 Neither GDB nor the stub assume that sized memory transfers are assumed
8897 using word alligned accesses. FIXME: @emph{A word aligned memory
8898 transfer mechanism is needed.}
8899 @item
8900 @tab reply @var{XX...}
8901 @tab
8902 @var{XX...} is mem contents. Can be fewer bytes than requested if able
8903 to read only part of the data. Neither GDB nor the stub assume that
8904 sized memory transfers are assumed using word alligned accesses. FIXME:
8905 @emph{A word aligned memory transfer mechanism is needed.}
8906 @item
8907 @tab reply @code{E}@var{NN}
8908 @tab @var{NN} is errno
8909
8910 @item write mem
8911 @tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
8912 @tab
8913 Write @var{length} bytes of memory starting at address @var{addr}.
8914 @var{XX...} is the data.
8915 @item
8916 @tab reply @code{OK}
8917 @tab for success
8918 @item
8919 @tab reply @code{E}@var{NN}
8920 @tab
8921 for an error (this includes the case where only part of the data was
8922 written).
8923
8924 @item reserved
8925 @tab @code{n}
8926 @tab Reserved for future use
8927
8928 @item reserved
8929 @tab @code{N}
8930 @tab Reserved for future use
8931
8932 @item reserved
8933 @tab @code{o}
8934 @tab Reserved for future use
8935
8936 @item reserved
8937 @tab @code{O}
8938 @tab Reserved for future use
8939
8940 @item read reg @strong{(reserved)}
8941 @tab @code{p}@var{n...}
8942 @tab
8943 See write register.
8944 @item
8945 @tab return @var{r....}
8946 @tab The hex encoded value of the register in target byte order.
8947
8948 @item write reg @emph{(optional)}
8949 @tab @code{P}@var{n...}@code{=}@var{r...}
8950 @tab
8951 Write register @var{n...} with value @var{r...}, which contains two hex
8952 digits for each byte in the register (target byte order).
8953 @item
8954 @tab reply @code{OK}
8955 @tab for success
8956 @item
8957 @tab reply @code{E}@var{NN}
8958 @tab for an error
8959
8960 @item general query @emph{(optional)}
8961 @tab @code{q}@var{query}
8962 @tab
8963 Request info about @var{query}. In general @value{GDBN} @var{query}'s
8964 have a leading upper case letter. Custom vendor queries should use a
8965 company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
8966 optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
8967 must ensure that they match the full @var{query} name.
8968 @item
8969 @tab reply @code{XX...}
8970 @tab Hex encoded data from query. The reply can not be empty.
8971 @item
8972 @tab reply @code{E}@var{NN}
8973 @tab error reply
8974 @item
8975 @tab reply @samp{}
8976 @tab Indicating an unrecognized @var{query}.
8977
8978 @item general set @emph{(optional)}
8979 @tab @code{Q}@var{var}@code{=}@var{val}
8980 @tab
8981 Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
8982 naming conventions.
8983
8984 @item reset @emph{(deprecated)}
8985 @tab @code{r}
8986 @tab
8987 Reset the entire system.
8988
8989 @item remote restart @emph{(optional)}
8990 @tab @code{R}@var{XX}
8991 @tab
8992 Restart the remote server. @var{XX} while needed has no clear
8993 definition. FIXME: @emph{An example interaction explaining how this
8994 packet is used in extended-remote mode is needed}.
8995
8996 @item step @emph{(optional)}
8997 @tab @code{s}@var{addr}
8998 @tab
8999 @var{addr} is address to resume. If @var{addr} is omitted, resume at
9000 same address.
9001 @item
9002 @tab reply
9003 @tab see below
9004
9005 @item step with signal @emph{(optional)}
9006 @tab @code{S}@var{sig}@code{;}@var{addr}
9007 @tab
9008 Like @samp{C} but step not continue.
9009 @item
9010 @tab reply
9011 @tab see below
9012
9013 @item search @emph{(optional)}
9014 @tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
9015 @tab
9016 Search backwards starting at address @var{addr} for a match with pattern
9017 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
9018 bytes. @var{addr} must be at least 3 digits.
9019
9020 @item thread alive @emph{(optional)}
9021 @tab @code{T}@var{XX}
9022 @tab Find out if the thread XX is alive.
9023 @item
9024 @tab reply @code{OK}
9025 @tab thread is still alive
9026 @item
9027 @tab reply @code{E}@var{NN}
9028 @tab thread is dead
9029
9030 @item reserved
9031 @tab @code{u}
9032 @tab Reserved for future use
9033
9034 @item reserved
9035 @tab @code{U}
9036 @tab Reserved for future use
9037
9038 @item reserved
9039 @tab @code{v}
9040 @tab Reserved for future use
9041
9042 @item reserved
9043 @tab @code{V}
9044 @tab Reserved for future use
9045
9046 @item reserved
9047 @tab @code{w}
9048 @tab Reserved for future use
9049
9050 @item reserved
9051 @tab @code{W}
9052 @tab Reserved for future use
9053
9054 @item reserved
9055 @tab @code{x}
9056 @tab Reserved for future use
9057
9058 @item write mem (binary) @emph{(optional)}
9059 @tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
9060 @tab
9061 @var{addr} is address, @var{length} is number of bytes, @var{XX...} is
9062 binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
9063 escaped using @code{0x7d}.
9064 @item
9065 @tab reply @code{OK}
9066 @tab for success
9067 @item
9068 @tab reply @code{E}@var{NN}
9069 @tab for an error
9070
9071 @item reserved
9072 @tab @code{y}
9073 @tab Reserved for future use
9074
9075 @item reserved
9076 @tab @code{Y}
9077 @tab Reserved for future use
9078
9079 @item remove break or watchpoint @strong{(draft)} @emph{(optional)}
9080 @tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9081 @tab
9082 See @samp{Z}.
9083
9084 @item insert break or watchpoint @strong{(draft)} @emph{(optional)}
9085 @tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9086 @tab
9087 @var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
9088 breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
9089 @samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
9090 bytes. For a software breakpoint, @var{length} specifies the size of
9091 the instruction to be patched. For hardware breakpoints and watchpoints
9092 @var{length} specifies the memory region to be monitored. To avoid
9093 potential problems with duplicate packets, the operations should be
9094 implemented in an ident-potentent way.
9095 @item
9096 @tab reply @code{E}@var{NN}
9097 @tab for an error
9098 @item
9099 @tab reply @code{OK}
9100 @tab for success
9101 @item
9102 @tab @samp{}
9103 @tab If not supported.
9104
9105 @item reserved
9106 @tab <other>
9107 @tab Reserved for future use
9108
9109 @end multitable
9110
9111 The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
9112 receive any of the below as a reply. In the case of the @samp{C},
9113 @samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
9114 when the target halts. In the below the exact meaning of @samp{signal
9115 number} is poorly defined. In general one of the UNIX signal numbering
9116 conventions is used.
9117
9118 @multitable @columnfractions .4 .6
9119
9120 @item @code{S}@var{AA}
9121 @tab @var{AA} is the signal number
9122
9123 @item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
9124 @tab
9125 @var{AA} = two hex digit signal number; @var{n...} = register number
9126 (hex), @var{r...} = target byte ordered register contents, size defined
9127 by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
9128 thread process ID, this is a hex integer; @var{n...} = other string not
9129 starting with valid hex digit. @value{GDBN} should ignore this
9130 @var{n...}, @var{r...} pair and go on to the next. This way we can
9131 extend the protocol.
9132
9133 @item @code{W}@var{AA}
9134 @tab
9135 The process exited, and @var{AA} is the exit status. This is only
9136 applicable for certains sorts of targets.
9137
9138 @item @code{X}@var{AA}
9139 @tab
9140 The process terminated with signal @var{AA}.
9141
9142 @item @code{N}@var{AA}@code{;}@var{tttttttt}@code{;}@var{dddddddd}@code{;}@var{bbbbbbbb} @strong{(obsolete)}
9143 @tab
9144 @var{AA} = signal number; @var{tttttttt} = address of symbol "_start";
9145 @var{dddddddd} = base of data section; @var{bbbbbbbb} = base of bss
9146 section. @emph{Note: only used by Cisco Systems targets. The difference
9147 between this reply and the "qOffsets" query is that the 'N' packet may
9148 arrive spontaneously whereas the 'qOffsets' is a query initiated by the
9149 host debugger.}
9150
9151 @item @code{O}@var{XX...}
9152 @tab
9153 @var{XX...} is hex encoding of ASCII data. This can happen at any time
9154 while the program is running and the debugger should continue to wait
9155 for 'W', 'T', etc.
9156
9157 @end multitable
9158
9159 The following set and query packets have already been defined.
9160
9161 @multitable @columnfractions .2 .2 .6
9162
9163 @item current thread
9164 @tab @code{q}@code{C}
9165 @tab Return the current thread id.
9166 @item
9167 @tab reply @code{QC}@var{pid}
9168 @tab
9169 Where @var{pid} is a HEX encoded 16 bit process id.
9170 @item
9171 @tab reply *
9172 @tab Any other reply implies the old pid.
9173
9174 @item compute CRC of memory block
9175 @tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
9176 @tab
9177 @item
9178 @tab reply @code{E}@var{NN}
9179 @tab An error (such as memory fault)
9180 @item
9181 @tab reply @code{C}@var{CRC32}
9182 @tab A 32 bit cyclic redundancy check of the specified memory region.
9183
9184 @item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
9185 @tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
9186 @tab
9187 Obtain thread information from RTOS. Where: @var{startflag} (one hex
9188 digit) is one to indicate the first query and zero to indicate a
9189 subsequent query; @var{threadcount} (two hex digits) is the maximum
9190 number of threads the response packet can contain; and @var{nextthread}
9191 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
9192 returned in the response as @var{argthread}.
9193 @item
9194 @tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
9195 @tab
9196 Where: @var{count} (two hex digits) is the number of threads being
9197 returned; @var{done} (one hex digit) is zero to indicate more threads
9198 and one indicates no further threads; @var{argthreadid} (eight hex
9199 digits) is @var{nextthread} from the request packet; @var{thread...} is
9200 a sequence of thread IDs from the target. @var{threadid} (eight hex
9201 digits). See @code{remote.c:parse_threadlist_response()}.
9202
9203 @item query sect offs
9204 @tab @code{q}@code{Offsets}
9205 @tab Get section offsets.
9206 @item
9207 @tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
9208
9209 @item thread info request
9210 @tab @code{q}@code{P}@var{mode}@var{threadid}
9211 @tab
9212 Returns information on @var{threadid}. Where: @var{mode} is a hex
9213 encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
9214 @item
9215 @tab reply *
9216 @tab
9217 See @code{remote.c:remote_unpack_thread_info_response()}.
9218
9219 @item remote command
9220 @tab @code{q}@code{Rcmd,}@var{COMMAND}
9221 @tab
9222 @var{COMMAND} (hex encoded) is passed to the local interpreter for
9223 execution. Invalid commands should be reported using the output string.
9224 Before the final result packet, the target may also respond with a
9225 number of intermediate @code{O}@var{OUTPUT} console output
9226 packets. @emph{Implementors should note that providing access to a
9227 stubs's interpreter may have security implications}.
9228 @item
9229 @tab reply @code{OK}
9230 @tab
9231 A command response with no output.
9232 @item
9233 @tab reply @var{OUTPUT}
9234 @tab
9235 A command response with the hex encoded output string @var{OUTPUT}.
9236 @item
9237 @tab reply @code{E}@var{NN}
9238 @tab
9239 Indicate a badly formed request.
9240
9241 @item
9242 @tab reply @samp{}
9243 @tab
9244 When @samp{q}@samp{Rcmd} is not recognized.
9245
9246 @end multitable
9247
9248 The following @samp{g}/@samp{G} packets have previously been defined.
9249 In the below, some thirty-two bit registers are transferred as sixty-four
9250 bits. Those registers should be zero/sign extended (which?) to fill the
9251 space allocated. Register bytes are transfered in target byte order.
9252 The two nibbles within a register byte are transfered most-significant -
9253 least-significant.
9254
9255 @multitable @columnfractions .5 .5
9256
9257 @item MIPS32
9258 @tab
9259 All registers are transfered as thirty-two bit quantities in the order:
9260 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
9261 registers; fsr; fir; fp.
9262
9263 @item MIPS64
9264 @tab
9265 All registers are transfered as sixty-four bit quantities (including
9266 thirty-two bit registers such as @code{sr}). The ordering is the same
9267 as @code{MIPS32}.
9268
9269 @end multitable
9270
9271 Example sequence of a target being re-started. Notice how the restart
9272 does not get any direct output:
9273
9274 @example
9275 <- @code{R00}
9276 -> @code{+}
9277 @emph{target restarts}
9278 <- @code{?}
9279 -> @code{+}
9280 -> @code{T001:1234123412341234}
9281 <- @code{+}
9282 @end example
9283
9284 Example sequence of a target being stepped by a single instruction:
9285
9286 @example
9287 <- @code{G1445...}
9288 -> @code{+}
9289 <- @code{s}
9290 -> @code{+}
9291 @emph{time passes}
9292 -> @code{T001:1234123412341234}
9293 <- @code{+}
9294 <- @code{g}
9295 -> @code{+}
9296 -> @code{1455...}
9297 <- @code{+}
9298 @end example
9299
9300 @kindex set remotedebug@r{, serial protocol}
9301 @kindex show remotedebug@r{, serial protocol}
9302 @cindex packets, reporting on stdout
9303 @cindex serial connections, debugging
9304 If you have trouble with the serial connection, you can use the command
9305 @code{set remotedebug}. This makes @value{GDBN} report on all packets sent
9306 back and forth across the serial line to the remote machine. The
9307 packet-debugging information is printed on the @value{GDBN} standard output
9308 stream. @code{set remotedebug off} turns it off, and @code{show
9309 remotedebug} shows you its current state.
9310
9311 @node Server
9312 @subsubsection Using the @code{gdbserver} program
9313
9314 @kindex gdbserver
9315 @cindex remote connection without stubs
9316 @code{gdbserver} is a control program for Unix-like systems, which
9317 allows you to connect your program with a remote @value{GDBN} via
9318 @code{target remote}---but without linking in the usual debugging stub.
9319
9320 @code{gdbserver} is not a complete replacement for the debugging stubs,
9321 because it requires essentially the same operating-system facilities
9322 that @value{GDBN} itself does. In fact, a system that can run
9323 @code{gdbserver} to connect to a remote @value{GDBN} could also run
9324 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9325 because it is a much smaller program than @value{GDBN} itself. It is
9326 also easier to port than all of @value{GDBN}, so you may be able to get
9327 started more quickly on a new system by using @code{gdbserver}.
9328 Finally, if you develop code for real-time systems, you may find that
9329 the tradeoffs involved in real-time operation make it more convenient to
9330 do as much development work as possible on another system, for example
9331 by cross-compiling. You can use @code{gdbserver} to make a similar
9332 choice for debugging.
9333
9334 @value{GDBN} and @code{gdbserver} communicate via either a serial line
9335 or a TCP connection, using the standard @value{GDBN} remote serial
9336 protocol.
9337
9338 @table @emph
9339 @item On the target machine,
9340 you need to have a copy of the program you want to debug.
9341 @code{gdbserver} does not need your program's symbol table, so you can
9342 strip the program if necessary to save space. @value{GDBN} on the host
9343 system does all the symbol handling.
9344
9345 To use the server, you must tell it how to communicate with @value{GDBN};
9346 the name of your program; and the arguments for your program. The
9347 syntax is:
9348
9349 @smallexample
9350 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9351 @end smallexample
9352
9353 @var{comm} is either a device name (to use a serial line) or a TCP
9354 hostname and portnumber. For example, to debug Emacs with the argument
9355 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
9356 @file{/dev/com1}:
9357
9358 @smallexample
9359 target> gdbserver /dev/com1 emacs foo.txt
9360 @end smallexample
9361
9362 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
9363 with it.
9364
9365 To use a TCP connection instead of a serial line:
9366
9367 @smallexample
9368 target> gdbserver host:2345 emacs foo.txt
9369 @end smallexample
9370
9371 The only difference from the previous example is the first argument,
9372 specifying that you are communicating with the host @value{GDBN} via
9373 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9374 expect a TCP connection from machine @samp{host} to local TCP port 2345.
9375 (Currently, the @samp{host} part is ignored.) You can choose any number
9376 you want for the port number as long as it does not conflict with any
9377 TCP ports already in use on the target system (for example, @code{23} is
9378 reserved for @code{telnet}).@footnote{If you choose a port number that
9379 conflicts with another service, @code{gdbserver} prints an error message
9380 and exits.} You must use the same port number with the host @value{GDBN}
9381 @code{target remote} command.
9382
9383 @item On the @value{GDBN} host machine,
9384 you need an unstripped copy of your program, since @value{GDBN} needs
9385 symbols and debugging information. Start up @value{GDBN} as usual,
9386 using the name of the local copy of your program as the first argument.
9387 (You may also need the @w{@samp{--baud}} option if the serial line is
9388 running at anything other than 9600@dmn{bps}.) After that, use @code{target
9389 remote} to establish communications with @code{gdbserver}. Its argument
9390 is either a device name (usually a serial device, like
9391 @file{/dev/ttyb}), or a TCP port descriptor in the form
9392 @code{@var{host}:@var{PORT}}. For example:
9393
9394 @smallexample
9395 (@value{GDBP}) target remote /dev/ttyb
9396 @end smallexample
9397
9398 @noindent
9399 communicates with the server via serial line @file{/dev/ttyb}, and
9400
9401 @smallexample
9402 (@value{GDBP}) target remote the-target:2345
9403 @end smallexample
9404
9405 @noindent
9406 communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
9407 For TCP connections, you must start up @code{gdbserver} prior to using
9408 the @code{target remote} command. Otherwise you may get an error whose
9409 text depends on the host system, but which usually looks something like
9410 @samp{Connection refused}.
9411 @end table
9412
9413 @node NetWare
9414 @subsubsection Using the @code{gdbserve.nlm} program
9415
9416 @kindex gdbserve.nlm
9417 @code{gdbserve.nlm} is a control program for NetWare systems, which
9418 allows you to connect your program with a remote @value{GDBN} via
9419 @code{target remote}.
9420
9421 @value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
9422 using the standard @value{GDBN} remote serial protocol.
9423
9424 @table @emph
9425 @item On the target machine,
9426 you need to have a copy of the program you want to debug.
9427 @code{gdbserve.nlm} does not need your program's symbol table, so you
9428 can strip the program if necessary to save space. @value{GDBN} on the
9429 host system does all the symbol handling.
9430
9431 To use the server, you must tell it how to communicate with
9432 @value{GDBN}; the name of your program; and the arguments for your
9433 program. The syntax is:
9434
9435 @smallexample
9436 load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
9437 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
9438 @end smallexample
9439
9440 @var{board} and @var{port} specify the serial line; @var{baud} specifies
9441 the baud rate used by the connection. @var{port} and @var{node} default
9442 to 0, @var{baud} defaults to 9600@dmn{bps}.
9443
9444 For example, to debug Emacs with the argument @samp{foo.txt}and
9445 communicate with @value{GDBN} over serial port number 2 or board 1
9446 using a 19200@dmn{bps} connection:
9447
9448 @smallexample
9449 load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
9450 @end smallexample
9451
9452 @item On the @value{GDBN} host machine,
9453 you need an unstripped copy of your program, since @value{GDBN} needs
9454 symbols and debugging information. Start up @value{GDBN} as usual,
9455 using the name of the local copy of your program as the first argument.
9456 (You may also need the @w{@samp{--baud}} option if the serial line is
9457 running at anything other than 9600@dmn{bps}. After that, use @code{target
9458 remote} to establish communications with @code{gdbserve.nlm}. Its
9459 argument is a device name (usually a serial device, like
9460 @file{/dev/ttyb}). For example:
9461
9462 @smallexample
9463 (@value{GDBP}) target remote /dev/ttyb
9464 @end smallexample
9465
9466 @noindent
9467 communications with the server via serial line @file{/dev/ttyb}.
9468 @end table
9469
9470 @node KOD
9471 @section Kernel Object Display
9472
9473 @cindex kernel object display
9474 @cindex kernel object
9475 @cindex KOD
9476
9477 Some targets support kernel object display. Using this facility,
9478 @value{GDBN} communicates specially with the underlying operating system
9479 and can display information about operating system-level objects such as
9480 mutexes and other synchronization objects. Exactly which objects can be
9481 displayed is determined on a per-OS basis.
9482
9483 Use the @code{set os} command to set the operating system. This tells
9484 @value{GDBN} which kernel object display module to initialize:
9485
9486 @example
9487 (gdb) set os cisco
9488 @end example
9489
9490 If @code{set os} succeeds, @value{GDBN} will display some information
9491 about the operating system, and will create a new @code{info} command
9492 which can be used to query the target. The @code{info} command is named
9493 after the operating system:
9494
9495 @example
9496 (gdb) info cisco
9497 List of Cisco Kernel Objects
9498 Object Description
9499 any Any and all objects
9500 @end example
9501
9502 Further subcommands can be used to query about particular objects known
9503 by the kernel.
9504
9505 There is currently no way to determine whether a given operating system
9506 is supported other than to try it.
9507
9508
9509 @node Configurations
9510 @chapter Configuration-Specific Information
9511
9512 While nearly all @value{GDBN} commands are available for all native and
9513 cross versions of the debugger, there are some exceptions. This chapter
9514 describes things that are only available in certain configurations.
9515
9516 There are three major categories of configurations: native
9517 configurations, where the host and target are the same, embedded
9518 operating system configurations, which are usually the same for several
9519 different processor architectures, and bare embedded processors, which
9520 are quite different from each other.
9521
9522 @menu
9523 * Native::
9524 * Embedded OS::
9525 * Embedded Processors::
9526 * Architectures::
9527 @end menu
9528
9529 @node Native
9530 @section Native
9531
9532 This section describes details specific to particular native
9533 configurations.
9534
9535 @menu
9536 * HP-UX:: HP-UX
9537 * SVR4 Process Information:: SVR4 process information
9538 @end menu
9539
9540 @node HP-UX
9541 @subsection HP-UX
9542
9543 On HP-UX systems, if you refer to a function or variable name that
9544 begins with a dollar sign, @value{GDBN} searches for a user or system
9545 name first, before it searches for a convenience variable.
9546
9547 @node SVR4 Process Information
9548 @subsection SVR4 process information
9549
9550 @kindex /proc
9551 @cindex process image
9552
9553 Many versions of SVR4 provide a facility called @samp{/proc} that can be
9554 used to examine the image of a running process using file-system
9555 subroutines. If @value{GDBN} is configured for an operating system with
9556 this facility, the command @code{info proc} is available to report on
9557 several kinds of information about the process running your program.
9558 @code{info proc} works only on SVR4 systems that include the
9559 @code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
9560 and Unixware, but not HP-UX or Linux, for example.
9561
9562 @table @code
9563 @kindex info proc
9564 @item info proc
9565 Summarize available information about the process.
9566
9567 @kindex info proc mappings
9568 @item info proc mappings
9569 Report on the address ranges accessible in the program, with information
9570 on whether your program may read, write, or execute each range.
9571
9572 @kindex info proc times
9573 @item info proc times
9574 Starting time, user CPU time, and system CPU time for your program and
9575 its children.
9576
9577 @kindex info proc id
9578 @item info proc id
9579 Report on the process IDs related to your program: its own process ID,
9580 the ID of its parent, the process group ID, and the session ID.
9581
9582 @kindex info proc status
9583 @item info proc status
9584 General information on the state of the process. If the process is
9585 stopped, this report includes the reason for stopping, and any signal
9586 received.
9587
9588 @item info proc all
9589 Show all the above information about the process.
9590 @end table
9591
9592 @node Embedded OS
9593 @section Embedded Operating Systems
9594
9595 This section describes configurations involving the debugging of
9596 embedded operating systems that are available for several different
9597 architectures.
9598
9599 @menu
9600 * VxWorks:: Using @value{GDBN} with VxWorks
9601 @end menu
9602
9603 @value{GDBN} includes the ability to debug programs running on
9604 various real-time operating systems.
9605
9606 @node VxWorks
9607 @subsection Using @value{GDBN} with VxWorks
9608
9609 @cindex VxWorks
9610
9611 @table @code
9612
9613 @kindex target vxworks
9614 @item target vxworks @var{machinename}
9615 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
9616 is the target system's machine name or IP address.
9617
9618 @end table
9619
9620 On VxWorks, @code{load} links @var{filename} dynamically on the
9621 current target system as well as adding its symbols in @value{GDBN}.
9622
9623 @value{GDBN} enables developers to spawn and debug tasks running on networked
9624 VxWorks targets from a Unix host. Already-running tasks spawned from
9625 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
9626 both the Unix host and on the VxWorks target. The program
9627 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
9628 installed with the name @code{vxgdb}, to distinguish it from a
9629 @value{GDB} for debugging programs on the host itself.)
9630
9631 @table @code
9632 @item VxWorks-timeout @var{args}
9633 @kindex vxworks-timeout
9634 All VxWorks-based targets now support the option @code{vxworks-timeout}.
9635 This option is set by the user, and @var{args} represents the number of
9636 seconds @value{GDBN} waits for responses to rpc's. You might use this if
9637 your VxWorks target is a slow software simulator or is on the far side
9638 of a thin network line.
9639 @end table
9640
9641 The following information on connecting to VxWorks was current when
9642 this manual was produced; newer releases of VxWorks may use revised
9643 procedures.
9644
9645 @kindex INCLUDE_RDB
9646 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
9647 to include the remote debugging interface routines in the VxWorks
9648 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
9649 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
9650 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
9651 source debugging task @code{tRdbTask} when VxWorks is booted. For more
9652 information on configuring and remaking VxWorks, see the manufacturer's
9653 manual.
9654 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
9655
9656 Once you have included @file{rdb.a} in your VxWorks system image and set
9657 your Unix execution search path to find @value{GDBN}, you are ready to
9658 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or @code{vxgdb},
9659 depending on your installation).
9660
9661 @value{GDBN} comes up showing the prompt:
9662
9663 @example
9664 (vxgdb)
9665 @end example
9666
9667 @menu
9668 * VxWorks Connection:: Connecting to VxWorks
9669 * VxWorks Download:: VxWorks download
9670 * VxWorks Attach:: Running tasks
9671 @end menu
9672
9673 @node VxWorks Connection
9674 @subsubsection Connecting to VxWorks
9675
9676 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
9677 network. To connect to a target whose host name is ``@code{tt}'', type:
9678
9679 @example
9680 (vxgdb) target vxworks tt
9681 @end example
9682
9683 @need 750
9684 @value{GDBN} displays messages like these:
9685
9686 @smallexample
9687 Attaching remote machine across net...
9688 Connected to tt.
9689 @end smallexample
9690
9691 @need 1000
9692 @value{GDBN} then attempts to read the symbol tables of any object modules
9693 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
9694 these files by searching the directories listed in the command search
9695 path (@pxref{Environment, ,Your program's environment}); if it fails
9696 to find an object file, it displays a message such as:
9697
9698 @example
9699 prog.o: No such file or directory.
9700 @end example
9701
9702 When this happens, add the appropriate directory to the search path with
9703 the @value{GDBN} command @code{path}, and execute the @code{target}
9704 command again.
9705
9706 @node VxWorks Download
9707 @subsubsection VxWorks download
9708
9709 @cindex download to VxWorks
9710 If you have connected to the VxWorks target and you want to debug an
9711 object that has not yet been loaded, you can use the @value{GDBN}
9712 @code{load} command to download a file from Unix to VxWorks
9713 incrementally. The object file given as an argument to the @code{load}
9714 command is actually opened twice: first by the VxWorks target in order
9715 to download the code, then by @value{GDBN} in order to read the symbol
9716 table. This can lead to problems if the current working directories on
9717 the two systems differ. If both systems have NFS mounted the same
9718 filesystems, you can avoid these problems by using absolute paths.
9719 Otherwise, it is simplest to set the working directory on both systems
9720 to the directory in which the object file resides, and then to reference
9721 the file by its name, without any path. For instance, a program
9722 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
9723 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
9724 program, type this on VxWorks:
9725
9726 @example
9727 -> cd "@var{vxpath}/vw/demo/rdb"
9728 @end example
9729
9730 @noindent
9731 Then, in @value{GDBN}, type:
9732
9733 @example
9734 (vxgdb) cd @var{hostpath}/vw/demo/rdb
9735 (vxgdb) load prog.o
9736 @end example
9737
9738 @value{GDBN} displays a response similar to this:
9739
9740 @smallexample
9741 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
9742 @end smallexample
9743
9744 You can also use the @code{load} command to reload an object module
9745 after editing and recompiling the corresponding source file. Note that
9746 this makes @value{GDBN} delete all currently-defined breakpoints,
9747 auto-displays, and convenience variables, and to clear the value
9748 history. (This is necessary in order to preserve the integrity of
9749 debugger's data structures that reference the target system's symbol
9750 table.)
9751
9752 @node VxWorks Attach
9753 @subsubsection Running tasks
9754
9755 @cindex running VxWorks tasks
9756 You can also attach to an existing task using the @code{attach} command as
9757 follows:
9758
9759 @example
9760 (vxgdb) attach @var{task}
9761 @end example
9762
9763 @noindent
9764 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
9765 or suspended when you attach to it. Running tasks are suspended at
9766 the time of attachment.
9767
9768 @node Embedded Processors
9769 @section Embedded Processors
9770
9771 This section goes into details specific to particular embedded
9772 configurations.
9773
9774 @menu
9775 * A29K Embedded:: AMD A29K Embedded
9776 * ARM:: ARM
9777 * H8/300:: Hitachi H8/300
9778 * H8/500:: Hitachi H8/500
9779 * i960:: Intel i960
9780 * M32R/D:: Mitsubishi M32R/D
9781 * M68K:: Motorola M68K
9782 * M88K:: Motorola M88K
9783 * MIPS Embedded:: MIPS Embedded
9784 * PA:: HP PA Embedded
9785 * PowerPC: PowerPC
9786 * SH:: Hitachi SH
9787 * Sparclet:: Tsqware Sparclet
9788 * Sparclite:: Fujitsu Sparclite
9789 * ST2000:: Tandem ST2000
9790 * Z8000:: Zilog Z8000
9791 @end menu
9792
9793 @node A29K Embedded
9794 @subsection AMD A29K Embedded
9795
9796 @menu
9797 * A29K UDI::
9798 * A29K EB29K::
9799 * Comms (EB29K):: Communications setup
9800 * gdb-EB29K:: EB29K cross-debugging
9801 * Remote Log:: Remote log
9802 @end menu
9803
9804 @table @code
9805
9806 @kindex target adapt
9807 @item target adapt @var{dev}
9808 Adapt monitor for A29K.
9809
9810 @kindex target amd-eb
9811 @item target amd-eb @var{dev} @var{speed} @var{PROG}
9812 @cindex AMD EB29K
9813 Remote PC-resident AMD EB29K board, attached over serial lines.
9814 @var{dev} is the serial device, as for @code{target remote};
9815 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
9816 name of the program to be debugged, as it appears to DOS on the PC.
9817 @xref{A29K EB29K, ,EBMON protocol for AMD29K}.
9818
9819 @end table
9820
9821 @node A29K UDI
9822 @subsubsection A29K UDI
9823
9824 @cindex UDI
9825 @cindex AMD29K via UDI
9826
9827 @value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
9828 protocol for debugging the a29k processor family. To use this
9829 configuration with AMD targets running the MiniMON monitor, you need the
9830 program @code{MONTIP}, available from AMD at no charge. You can also
9831 use @value{GDBN} with the UDI-conformant a29k simulator program
9832 @code{ISSTIP}, also available from AMD.
9833
9834 @table @code
9835 @item target udi @var{keyword}
9836 @kindex udi
9837 Select the UDI interface to a remote a29k board or simulator, where
9838 @var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
9839 This file contains keyword entries which specify parameters used to
9840 connect to a29k targets. If the @file{udi_soc} file is not in your
9841 working directory, you must set the environment variable @samp{UDICONF}
9842 to its pathname.
9843 @end table
9844
9845 @node A29K EB29K
9846 @subsubsection EBMON protocol for AMD29K
9847
9848 @cindex EB29K board
9849 @cindex running 29K programs
9850
9851 AMD distributes a 29K development board meant to fit in a PC, together
9852 with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
9853 term, this development system is called the ``EB29K''. To use
9854 @value{GDBN} from a Unix system to run programs on the EB29K board, you
9855 must first connect a serial cable between the PC (which hosts the EB29K
9856 board) and a serial port on the Unix system. In the following, we
9857 assume you've hooked the cable between the PC's @file{COM1} port and
9858 @file{/dev/ttya} on the Unix system.
9859
9860 @node Comms (EB29K)
9861 @subsubsection Communications setup
9862
9863 The next step is to set up the PC's port, by doing something like this
9864 in DOS on the PC:
9865
9866 @example
9867 C:\> MODE com1:9600,n,8,1,none
9868 @end example
9869
9870 @noindent
9871 This example---run on an MS DOS 4.0 system---sets the PC port to 9600
9872 bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
9873 you must match the communications parameters when establishing the Unix
9874 end of the connection as well.
9875 @c FIXME: Who knows what this "no retry action" crud from the DOS manual may
9876 @c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
9877 @c
9878 @c It's optional, but it's unwise to omit it: who knows what is the
9879 @c default value set when the DOS machines boots? "No retry" means that
9880 @c the DOS serial device driver won't retry the operation if it fails;
9881 @c I understand that this is needed because the GDB serial protocol
9882 @c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
9883
9884 To give control of the PC to the Unix side of the serial line, type
9885 the following at the DOS console:
9886
9887 @example
9888 C:\> CTTY com1
9889 @end example
9890
9891 @noindent
9892 (Later, if you wish to return control to the DOS console, you can use
9893 the command @code{CTTY con}---but you must send it over the device that
9894 had control, in our example over the @file{COM1} serial line).
9895
9896 From the Unix host, use a communications program such as @code{tip} or
9897 @code{cu} to communicate with the PC; for example,
9898
9899 @example
9900 cu -s 9600 -l /dev/ttya
9901 @end example
9902
9903 @noindent
9904 The @code{cu} options shown specify, respectively, the linespeed and the
9905 serial port to use. If you use @code{tip} instead, your command line
9906 may look something like the following:
9907
9908 @example
9909 tip -9600 /dev/ttya
9910 @end example
9911
9912 @noindent
9913 Your system may require a different name where we show
9914 @file{/dev/ttya} as the argument to @code{tip}. The communications
9915 parameters, including which port to use, are associated with the
9916 @code{tip} argument in the ``remote'' descriptions file---normally the
9917 system table @file{/etc/remote}.
9918 @c FIXME: What if anything needs doing to match the "n,8,1,none" part of
9919 @c the DOS side's comms setup? cu can support -o (odd
9920 @c parity), -e (even parity)---apparently no settings for no parity or
9921 @c for character size. Taken from stty maybe...? John points out tip
9922 @c can set these as internal variables, eg ~s parity=none; man stty
9923 @c suggests that it *might* work to stty these options with stdin or
9924 @c stdout redirected... ---doc@cygnus.com, 25feb91
9925 @c
9926 @c There's nothing to be done for the "none" part of the DOS MODE
9927 @c command. The rest of the parameters should be matched by the
9928 @c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
9929
9930 @kindex EBMON
9931 Using the @code{tip} or @code{cu} connection, change the DOS working
9932 directory to the directory containing a copy of your 29K program, then
9933 start the PC program @code{EBMON} (an EB29K control program supplied
9934 with your board by AMD). You should see an initial display from
9935 @code{EBMON} similar to the one that follows, ending with the
9936 @code{EBMON} prompt @samp{#}---
9937
9938 @example
9939 C:\> G:
9940
9941 G:\> CD \usr\joe\work29k
9942
9943 G:\USR\JOE\WORK29K> EBMON
9944 Am29000 PC Coprocessor Board Monitor, version 3.0-18
9945 Copyright 1990 Advanced Micro Devices, Inc.
9946 Written by Gibbons and Associates, Inc.
9947
9948 Enter '?' or 'H' for help
9949
9950 PC Coprocessor Type = EB29K
9951 I/O Base = 0x208
9952 Memory Base = 0xd0000
9953
9954 Data Memory Size = 2048KB
9955 Available I-RAM Range = 0x8000 to 0x1fffff
9956 Available D-RAM Range = 0x80002000 to 0x801fffff
9957
9958 PageSize = 0x400
9959 Register Stack Size = 0x800
9960 Memory Stack Size = 0x1800
9961
9962 CPU PRL = 0x3
9963 Am29027 Available = No
9964 Byte Write Available = Yes
9965
9966 # ~.
9967 @end example
9968
9969 Then exit the @code{cu} or @code{tip} program (done in the example by
9970 typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
9971 running, ready for @value{GDBN} to take over.
9972
9973 For this example, we've assumed what is probably the most convenient
9974 way to make sure the same 29K program is on both the PC and the Unix
9975 system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
9976 PC as a file system on the Unix host. If you do not have PC/NFS or
9977 something similar connecting the two systems, you must arrange some
9978 other way---perhaps floppy-disk transfer---of getting the 29K program
9979 from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
9980 serial line.
9981
9982 @node gdb-EB29K
9983 @subsubsection EB29K cross-debugging
9984
9985 Finally, @code{cd} to the directory containing an image of your 29K
9986 program on the Unix system, and start @value{GDBN}---specifying as argument the
9987 name of your 29K program:
9988
9989 @example
9990 cd /usr/joe/work29k
9991 @value{GDBP} myfoo
9992 @end example
9993
9994 @need 500
9995 Now you can use the @code{target} command:
9996
9997 @example
9998 target amd-eb /dev/ttya 9600 MYFOO
9999 @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
10000 @c emphasize that this is the name as seen by DOS (since I think DOS is
10001 @c single-minded about case of letters). ---doc@cygnus.com, 25feb91
10002 @end example
10003
10004 @noindent
10005 In this example, we've assumed your program is in a file called
10006 @file{myfoo}. Note that the filename given as the last argument to
10007 @code{target amd-eb} should be the name of the program as it appears to DOS.
10008 In our example this is simply @code{MYFOO}, but in general it can include
10009 a DOS path, and depending on your transfer mechanism may not resemble
10010 the name on the Unix side.
10011
10012 At this point, you can set any breakpoints you wish; when you are ready
10013 to see your program run on the 29K board, use the @value{GDBN} command
10014 @code{run}.
10015
10016 To stop debugging the remote program, use the @value{GDBN} @code{detach}
10017 command.
10018
10019 To return control of the PC to its console, use @code{tip} or @code{cu}
10020 once again, after your @value{GDBN} session has concluded, to attach to
10021 @code{EBMON}. You can then type the command @code{q} to shut down
10022 @code{EBMON}, returning control to the DOS command-line interpreter.
10023 Type @kbd{CTTY con} to return command input to the main DOS console,
10024 and type @kbd{~.} to leave @code{tip} or @code{cu}.
10025
10026 @node Remote Log
10027 @subsubsection Remote log
10028 @kindex eb.log
10029 @cindex log file for EB29K
10030
10031 The @code{target amd-eb} command creates a file @file{eb.log} in the
10032 current working directory, to help debug problems with the connection.
10033 @file{eb.log} records all the output from @code{EBMON}, including echoes
10034 of the commands sent to it. Running @samp{tail -f} on this file in
10035 another window often helps to understand trouble with @code{EBMON}, or
10036 unexpected events on the PC side of the connection.
10037
10038 @node ARM
10039 @subsection ARM
10040
10041 @table @code
10042
10043 @kindex target rdi
10044 @item target rdi @var{dev}
10045 ARM Angel monitor, via RDI library interface to ADP protocol. You may
10046 use this target to communicate with both boards running the Angel
10047 monitor, or with the EmbeddedICE JTAG debug device.
10048
10049 @kindex target rdp
10050 @item target rdp @var{dev}
10051 ARM Demon monitor.
10052
10053 @end table
10054
10055 @node H8/300
10056 @subsection Hitachi H8/300
10057
10058 @table @code
10059
10060 @kindex target hms@r{, with H8/300}
10061 @item target hms @var{dev}
10062 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
10063 Use special commands @code{device} and @code{speed} to control the serial
10064 line and the communications speed used.
10065
10066 @kindex target e7000@r{, with H8/300}
10067 @item target e7000 @var{dev}
10068 E7000 emulator for Hitachi H8 and SH.
10069
10070 @kindex target sh3@r{, with H8/300}
10071 @kindex target sh3e@r{, with H8/300}
10072 @item target sh3 @var{dev}
10073 @item target sh3e @var{dev}
10074 Hitachi SH-3 and SH-3E target systems.
10075
10076 @end table
10077
10078 @cindex download to H8/300 or H8/500
10079 @cindex H8/300 or H8/500 download
10080 @cindex download to Hitachi SH
10081 @cindex Hitachi SH download
10082 When you select remote debugging to a Hitachi SH, H8/300, or H8/500
10083 board, the @code{load} command downloads your program to the Hitachi
10084 board and also opens it as the current executable target for
10085 @value{GDBN} on your host (like the @code{file} command).
10086
10087 @value{GDBN} needs to know these things to talk to your
10088 Hitachi SH, H8/300, or H8/500:
10089
10090 @enumerate
10091 @item
10092 that you want to use @samp{target hms}, the remote debugging interface
10093 for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
10094 emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
10095 the default when GDB is configured specifically for the Hitachi SH,
10096 H8/300, or H8/500.)
10097
10098 @item
10099 what serial device connects your host to your Hitachi board (the first
10100 serial device available on your host is the default).
10101
10102 @item
10103 what speed to use over the serial device.
10104 @end enumerate
10105
10106 @menu
10107 * Hitachi Boards:: Connecting to Hitachi boards.
10108 * Hitachi ICE:: Using the E7000 In-Circuit Emulator.
10109 * Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
10110 @end menu
10111
10112 @node Hitachi Boards
10113 @subsubsection Connecting to Hitachi boards
10114
10115 @c only for Unix hosts
10116 @kindex device
10117 @cindex serial device, Hitachi micros
10118 Use the special @code{@value{GDBP}} command @samp{device @var{port}} if you
10119 need to explicitly set the serial device. The default @var{port} is the
10120 first available port on your host. This is only necessary on Unix
10121 hosts, where it is typically something like @file{/dev/ttya}.
10122
10123 @kindex speed
10124 @cindex serial line speed, Hitachi micros
10125 @code{@value{GDBP}} has another special command to set the communications
10126 speed: @samp{speed @var{bps}}. This command also is only used from Unix
10127 hosts; on DOS hosts, set the line speed as usual from outside GDB with
10128 the DOS @code{mode} command (for instance,
10129 @w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
10130
10131 The @samp{device} and @samp{speed} commands are available only when you
10132 use a Unix host to debug your Hitachi microprocessor programs. If you
10133 use a DOS host,
10134 @value{GDBN} depends on an auxiliary terminate-and-stay-resident program
10135 called @code{asynctsr} to communicate with the development board
10136 through a PC serial port. You must also use the DOS @code{mode} command
10137 to set up the serial port on the DOS side.
10138
10139 The following sample session illustrates the steps needed to start a
10140 program under @value{GDBN} control on an H8/300. The example uses a
10141 sample H8/300 program called @file{t.x}. The procedure is the same for
10142 the Hitachi SH and the H8/500.
10143
10144 First hook up your development board. In this example, we use a
10145 board attached to serial port @code{COM2}; if you use a different serial
10146 port, substitute its name in the argument of the @code{mode} command.
10147 When you call @code{asynctsr}, the auxiliary comms program used by the
10148 debugger, you give it just the numeric part of the serial port's name;
10149 for example, @samp{asyncstr 2} below runs @code{asyncstr} on
10150 @code{COM2}.
10151
10152 @example
10153 C:\H8300\TEST> asynctsr 2
10154 C:\H8300\TEST> mode com2:9600,n,8,1,p
10155
10156 Resident portion of MODE loaded
10157
10158 COM2: 9600, n, 8, 1, p
10159
10160 @end example
10161
10162 @quotation
10163 @emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
10164 @code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
10165 disable it, or even boot without it, to use @code{asynctsr} to control
10166 your development board.
10167 @end quotation
10168
10169 @kindex target hms@r{, and serial protocol}
10170 Now that serial communications are set up, and the development board is
10171 connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
10172 the name of your program as the argument. @code{@value{GDBP}} prompts
10173 you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
10174 commands to begin your debugging session: @samp{target hms} to specify
10175 cross-debugging to the Hitachi board, and the @code{load} command to
10176 download your program to the board. @code{load} displays the names of
10177 the program's sections, and a @samp{*} for each 2K of data downloaded.
10178 (If you want to refresh @value{GDBN} data on symbols or on the
10179 executable file without downloading, use the @value{GDBN} commands
10180 @code{file} or @code{symbol-file}. These commands, and @code{load}
10181 itself, are described in @ref{Files,,Commands to specify files}.)
10182
10183 @smallexample
10184 (eg-C:\H8300\TEST) @value{GDBP} t.x
10185 GDB is free software and you are welcome to distribute copies
10186 of it under certain conditions; type "show copying" to see
10187 the conditions.
10188 There is absolutely no warranty for GDB; type "show warranty"
10189 for details.
10190 GDB @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
10191 (gdb) target hms
10192 Connected to remote H8/300 HMS system.
10193 (gdb) load t.x
10194 .text : 0x8000 .. 0xabde ***********
10195 .data : 0xabde .. 0xad30 *
10196 .stack : 0xf000 .. 0xf014 *
10197 @end smallexample
10198
10199 At this point, you're ready to run or debug your program. From here on,
10200 you can use all the usual @value{GDBN} commands. The @code{break} command
10201 sets breakpoints; the @code{run} command starts your program;
10202 @code{print} or @code{x} display data; the @code{continue} command
10203 resumes execution after stopping at a breakpoint. You can use the
10204 @code{help} command at any time to find out more about @value{GDBN} commands.
10205
10206 Remember, however, that @emph{operating system} facilities aren't
10207 available on your development board; for example, if your program hangs,
10208 you can't send an interrupt---but you can press the @sc{reset} switch!
10209
10210 Use the @sc{reset} button on the development board
10211 @itemize @bullet
10212 @item
10213 to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
10214 no way to pass an interrupt signal to the development board); and
10215
10216 @item
10217 to return to the @value{GDBN} command prompt after your program finishes
10218 normally. The communications protocol provides no other way for @value{GDBN}
10219 to detect program completion.
10220 @end itemize
10221
10222 In either case, @value{GDBN} sees the effect of a @sc{reset} on the
10223 development board as a ``normal exit'' of your program.
10224
10225 @node Hitachi ICE
10226 @subsubsection Using the E7000 in-circuit emulator
10227
10228 @kindex target e7000@r{, with Hitachi ICE}
10229 You can use the E7000 in-circuit emulator to develop code for either the
10230 Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
10231 e7000} command to connect @value{GDBN} to your E7000:
10232
10233 @table @code
10234 @item target e7000 @var{port} @var{speed}
10235 Use this form if your E7000 is connected to a serial port. The
10236 @var{port} argument identifies what serial port to use (for example,
10237 @samp{com2}). The third argument is the line speed in bits per second
10238 (for example, @samp{9600}).
10239
10240 @item target e7000 @var{hostname}
10241 If your E7000 is installed as a host on a TCP/IP network, you can just
10242 specify its hostname; @value{GDBN} uses @code{telnet} to connect.
10243 @end table
10244
10245 @node Hitachi Special
10246 @subsubsection Special @value{GDBN} commands for Hitachi micros
10247
10248 Some @value{GDBN} commands are available only for the H8/300:
10249
10250 @table @code
10251
10252 @kindex set machine
10253 @kindex show machine
10254 @item set machine h8300
10255 @itemx set machine h8300h
10256 Condition @value{GDBN} for one of the two variants of the H8/300
10257 architecture with @samp{set machine}. You can use @samp{show machine}
10258 to check which variant is currently in effect.
10259
10260 @end table
10261
10262 @node H8/500
10263 @subsection H8/500
10264
10265 @table @code
10266
10267 @kindex set memory @var{mod}
10268 @cindex memory models, H8/500
10269 @item set memory @var{mod}
10270 @itemx show memory
10271 Specify which H8/500 memory model (@var{mod}) you are using with
10272 @samp{set memory}; check which memory model is in effect with @samp{show
10273 memory}. The accepted values for @var{mod} are @code{small},
10274 @code{big}, @code{medium}, and @code{compact}.
10275
10276 @end table
10277
10278 @node i960
10279 @subsection Intel i960
10280
10281 @table @code
10282
10283 @kindex target mon960
10284 @item target mon960 @var{dev}
10285 MON960 monitor for Intel i960.
10286
10287 @item target nindy @var{devicename}
10288 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10289 the name of the serial device to use for the connection, e.g.
10290 @file{/dev/ttya}.
10291
10292 @end table
10293
10294 @cindex Nindy
10295 @cindex i960
10296 @dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
10297 @value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
10298 tell @value{GDBN} how to connect to the 960 in several ways:
10299
10300 @itemize @bullet
10301 @item
10302 Through command line options specifying serial port, version of the
10303 Nindy protocol, and communications speed;
10304
10305 @item
10306 By responding to a prompt on startup;
10307
10308 @item
10309 By using the @code{target} command at any point during your @value{GDBN}
10310 session. @xref{Target Commands, ,Commands for managing targets}.
10311
10312 @kindex target nindy
10313 @item target nindy @var{devicename}
10314 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10315 the name of the serial device to use for the connection, e.g.
10316 @file{/dev/ttya}.
10317
10318 @end itemize
10319
10320 @cindex download to Nindy-960
10321 With the Nindy interface to an Intel 960 board, @code{load}
10322 downloads @var{filename} to the 960 as well as adding its symbols in
10323 @value{GDBN}.
10324
10325 @menu
10326 * Nindy Startup:: Startup with Nindy
10327 * Nindy Options:: Options for Nindy
10328 * Nindy Reset:: Nindy reset command
10329 @end menu
10330
10331 @node Nindy Startup
10332 @subsubsection Startup with Nindy
10333
10334 If you simply start @code{@value{GDBP}} without using any command-line
10335 options, you are prompted for what serial port to use, @emph{before} you
10336 reach the ordinary @value{GDBN} prompt:
10337
10338 @example
10339 Attach /dev/ttyNN -- specify NN, or "quit" to quit:
10340 @end example
10341
10342 @noindent
10343 Respond to the prompt with whatever suffix (after @samp{/dev/tty})
10344 identifies the serial port you want to use. You can, if you choose,
10345 simply start up with no Nindy connection by responding to the prompt
10346 with an empty line. If you do this and later wish to attach to Nindy,
10347 use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
10348
10349 @node Nindy Options
10350 @subsubsection Options for Nindy
10351
10352 These are the startup options for beginning your @value{GDBN} session with a
10353 Nindy-960 board attached:
10354
10355 @table @code
10356 @item -r @var{port}
10357 Specify the serial port name of a serial interface to be used to connect
10358 to the target system. This option is only available when @value{GDBN} is
10359 configured for the Intel 960 target architecture. You may specify
10360 @var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
10361 device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
10362 suffix for a specific @code{tty} (e.g. @samp{-r a}).
10363
10364 @item -O
10365 (An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
10366 the ``old'' Nindy monitor protocol to connect to the target system.
10367 This option is only available when @value{GDBN} is configured for the Intel 960
10368 target architecture.
10369
10370 @quotation
10371 @emph{Warning:} if you specify @samp{-O}, but are actually trying to
10372 connect to a target system that expects the newer protocol, the connection
10373 fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
10374 attempts to reconnect at several different line speeds. You can abort
10375 this process with an interrupt.
10376 @end quotation
10377
10378 @item -brk
10379 Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
10380 system, in an attempt to reset it, before connecting to a Nindy target.
10381
10382 @quotation
10383 @emph{Warning:} Many target systems do not have the hardware that this
10384 requires; it only works with a few boards.
10385 @end quotation
10386 @end table
10387
10388 The standard @samp{-b} option controls the line speed used on the serial
10389 port.
10390
10391 @c @group
10392 @node Nindy Reset
10393 @subsubsection Nindy reset command
10394
10395 @table @code
10396 @item reset
10397 @kindex reset
10398 For a Nindy target, this command sends a ``break'' to the remote target
10399 system; this is only useful if the target has been equipped with a
10400 circuit to perform a hard reset (or some other interesting action) when
10401 a break is detected.
10402 @end table
10403 @c @end group
10404
10405 @node M32R/D
10406 @subsection Mitsubishi M32R/D
10407
10408 @table @code
10409
10410 @kindex target m32r
10411 @item target m32r @var{dev}
10412 Mitsubishi M32R/D ROM monitor.
10413
10414 @end table
10415
10416 @node M68K
10417 @subsection M68k
10418
10419 The Motorola m68k configuration includes ColdFire support, and
10420 target command for the following ROM monitors.
10421
10422 @table @code
10423
10424 @kindex target abug
10425 @item target abug @var{dev}
10426 ABug ROM monitor for M68K.
10427
10428 @kindex target cpu32bug
10429 @item target cpu32bug @var{dev}
10430 CPU32BUG monitor, running on a CPU32 (M68K) board.
10431
10432 @kindex target dbug
10433 @item target dbug @var{dev}
10434 dBUG ROM monitor for Motorola ColdFire.
10435
10436 @kindex target est
10437 @item target est @var{dev}
10438 EST-300 ICE monitor, running on a CPU32 (M68K) board.
10439
10440 @kindex target rom68k
10441 @item target rom68k @var{dev}
10442 ROM 68K monitor, running on an M68K IDP board.
10443
10444 @end table
10445
10446 If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
10447 instead have only a single special target command:
10448
10449 @table @code
10450
10451 @kindex target es1800
10452 @item target es1800 @var{dev}
10453 ES-1800 emulator for M68K.
10454
10455 @end table
10456
10457 [context?]
10458
10459 @table @code
10460
10461 @kindex target rombug
10462 @item target rombug @var{dev}
10463 ROMBUG ROM monitor for OS/9000.
10464
10465 @end table
10466
10467 @node M88K
10468 @subsection M88K
10469
10470 @table @code
10471
10472 @kindex target bug
10473 @item target bug @var{dev}
10474 BUG monitor, running on a MVME187 (m88k) board.
10475
10476 @end table
10477
10478 @node MIPS Embedded
10479 @subsection MIPS Embedded
10480
10481 @cindex MIPS boards
10482 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
10483 MIPS board attached to a serial line. This is available when
10484 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
10485
10486 @need 1000
10487 Use these @value{GDBN} commands to specify the connection to your target board:
10488
10489 @table @code
10490 @item target mips @var{port}
10491 @kindex target mips @var{port}
10492 To run a program on the board, start up @code{@value{GDBP}} with the
10493 name of your program as the argument. To connect to the board, use the
10494 command @samp{target mips @var{port}}, where @var{port} is the name of
10495 the serial port connected to the board. If the program has not already
10496 been downloaded to the board, you may use the @code{load} command to
10497 download it. You can then use all the usual @value{GDBN} commands.
10498
10499 For example, this sequence connects to the target board through a serial
10500 port, and loads and runs a program called @var{prog} through the
10501 debugger:
10502
10503 @example
10504 host$ @value{GDBP} @var{prog}
10505 GDB is free software and @dots{}
10506 (gdb) target mips /dev/ttyb
10507 (gdb) load @var{prog}
10508 (gdb) run
10509 @end example
10510
10511 @item target mips @var{hostname}:@var{portnumber}
10512 On some @value{GDBN} host configurations, you can specify a TCP
10513 connection (for instance, to a serial line managed by a terminal
10514 concentrator) instead of a serial port, using the syntax
10515 @samp{@var{hostname}:@var{portnumber}}.
10516
10517 @item target pmon @var{port}
10518 @kindex target pmon @var{port}
10519 PMON ROM monitor.
10520
10521 @item target ddb @var{port}
10522 @kindex target ddb @var{port}
10523 NEC's DDB variant of PMON for Vr4300.
10524
10525 @item target lsi @var{port}
10526 @kindex target lsi @var{port}
10527 LSI variant of PMON.
10528
10529 @kindex target r3900
10530 @item target r3900 @var{dev}
10531 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
10532
10533 @kindex target array
10534 @item target array @var{dev}
10535 Array Tech LSI33K RAID controller board.
10536
10537 @end table
10538
10539
10540 @noindent
10541 @value{GDBN} also supports these special commands for MIPS targets:
10542
10543 @table @code
10544 @item set processor @var{args}
10545 @itemx show processor
10546 @kindex set processor @var{args}
10547 @kindex show processor
10548 Use the @code{set processor} command to set the type of MIPS
10549 processor when you want to access processor-type-specific registers.
10550 For example, @code{set processor @var{r3041}} tells @value{GDBN}
10551 to use the CPO registers appropriate for the 3041 chip.
10552 Use the @code{show processor} command to see what MIPS processor @value{GDBN}
10553 is using. Use the @code{info reg} command to see what registers
10554 @value{GDBN} is using.
10555
10556 @item set mipsfpu double
10557 @itemx set mipsfpu single
10558 @itemx set mipsfpu none
10559 @itemx show mipsfpu
10560 @kindex set mipsfpu
10561 @kindex show mipsfpu
10562 @cindex MIPS remote floating point
10563 @cindex floating point, MIPS remote
10564 If your target board does not support the MIPS floating point
10565 coprocessor, you should use the command @samp{set mipsfpu none} (if you
10566 need this, you may wish to put the command in your @value{GDBINIT}
10567 file). This tells @value{GDBN} how to find the return value of
10568 functions which return floating point values. It also allows
10569 @value{GDBN} to avoid saving the floating point registers when calling
10570 functions on the board. If you are using a floating point coprocessor
10571 with only single precision floating point support, as on the @sc{r4650}
10572 processor, use the command @samp{set mipsfpu single}. The default
10573 double precision floating point coprocessor may be selected using
10574 @samp{set mipsfpu double}.
10575
10576 In previous versions the only choices were double precision or no
10577 floating point, so @samp{set mipsfpu on} will select double precision
10578 and @samp{set mipsfpu off} will select no floating point.
10579
10580 As usual, you can inquire about the @code{mipsfpu} variable with
10581 @samp{show mipsfpu}.
10582
10583 @item set remotedebug @var{n}
10584 @itemx show remotedebug
10585 @kindex set remotedebug@r{, MIPS protocol}
10586 @kindex show remotedebug@r{, MIPS protocol}
10587 @cindex @code{remotedebug}, MIPS protocol
10588 @cindex MIPS @code{remotedebug} protocol
10589 @c FIXME! For this to be useful, you must know something about the MIPS
10590 @c FIXME...protocol. Where is it described?
10591 You can see some debugging information about communications with the board
10592 by setting the @code{remotedebug} variable. If you set it to @code{1} using
10593 @samp{set remotedebug 1}, every packet is displayed. If you set it
10594 to @code{2}, every character is displayed. You can check the current value
10595 at any time with the command @samp{show remotedebug}.
10596
10597 @item set timeout @var{seconds}
10598 @itemx set retransmit-timeout @var{seconds}
10599 @itemx show timeout
10600 @itemx show retransmit-timeout
10601 @cindex @code{timeout}, MIPS protocol
10602 @cindex @code{retransmit-timeout}, MIPS protocol
10603 @kindex set timeout
10604 @kindex show timeout
10605 @kindex set retransmit-timeout
10606 @kindex show retransmit-timeout
10607 You can control the timeout used while waiting for a packet, in the MIPS
10608 remote protocol, with the @code{set timeout @var{seconds}} command. The
10609 default is 5 seconds. Similarly, you can control the timeout used while
10610 waiting for an acknowledgement of a packet with the @code{set
10611 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
10612 You can inspect both values with @code{show timeout} and @code{show
10613 retransmit-timeout}. (These commands are @emph{only} available when
10614 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
10615
10616 The timeout set by @code{set timeout} does not apply when @value{GDBN}
10617 is waiting for your program to stop. In that case, @value{GDBN} waits
10618 forever because it has no way of knowing how long the program is going
10619 to run before stopping.
10620 @end table
10621
10622 @node PowerPC
10623 @subsection PowerPC
10624
10625 @table @code
10626
10627 @kindex target dink32
10628 @item target dink32 @var{dev}
10629 DINK32 ROM monitor.
10630
10631 @kindex target ppcbug
10632 @item target ppcbug @var{dev}
10633 @kindex target ppcbug1
10634 @item target ppcbug1 @var{dev}
10635 PPCBUG ROM monitor for PowerPC.
10636
10637 @kindex target sds
10638 @item target sds @var{dev}
10639 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
10640
10641 @end table
10642
10643 @node PA
10644 @subsection HP PA Embedded
10645
10646 @table @code
10647
10648 @kindex target op50n
10649 @item target op50n @var{dev}
10650 OP50N monitor, running on an OKI HPPA board.
10651
10652 @kindex target w89k
10653 @item target w89k @var{dev}
10654 W89K monitor, running on a Winbond HPPA board.
10655
10656 @end table
10657
10658 @node SH
10659 @subsection Hitachi SH
10660
10661 @table @code
10662
10663 @kindex target hms@r{, with Hitachi SH}
10664 @item target hms @var{dev}
10665 A Hitachi SH board attached via serial line to your host. Use special
10666 commands @code{device} and @code{speed} to control the serial line and
10667 the communications speed used.
10668
10669 @kindex target e7000@r{, with Hitachi SH}
10670 @item target e7000 @var{dev}
10671 E7000 emulator for Hitachi SH.
10672
10673 @kindex target sh3@r{, with SH}
10674 @kindex target sh3e@r{, with SH}
10675 @item target sh3 @var{dev}
10676 @item target sh3e @var{dev}
10677 Hitachi SH-3 and SH-3E target systems.
10678
10679 @end table
10680
10681 @node Sparclet
10682 @subsection Tsqware Sparclet
10683
10684 @cindex Sparclet
10685
10686 @value{GDBN} enables developers to debug tasks running on
10687 Sparclet targets from a Unix host.
10688 @value{GDBN} uses code that runs on
10689 both the Unix host and on the Sparclet target. The program
10690 @code{@value{GDBP}} is installed and executed on the Unix host.
10691
10692 @table @code
10693 @item timeout @var{args}
10694 @kindex remotetimeout
10695 @value{GDBN} supports the option @code{remotetimeout}.
10696 This option is set by the user, and @var{args} represents the number of
10697 seconds @value{GDBN} waits for responses.
10698 @end table
10699
10700 @kindex Compiling
10701 When compiling for debugging, include the options @samp{-g} to get debug
10702 information and @samp{-Ttext} to relocate the program to where you wish to
10703 load it on the target. You may also want to add the options @samp{-n} or
10704 @samp{-N} in order to reduce the size of the sections. Example:
10705
10706 @example
10707 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
10708 @end example
10709
10710 You can use @code{objdump} to verify that the addresses are what you intended:
10711
10712 @example
10713 sparclet-aout-objdump --headers --syms prog
10714 @end example
10715
10716 @kindex Running
10717 Once you have set
10718 your Unix execution search path to find @value{GDBN}, you are ready to
10719 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
10720 (or @code{sparclet-aout-gdb}, depending on your installation).
10721
10722 @value{GDBN} comes up showing the prompt:
10723
10724 @example
10725 (gdbslet)
10726 @end example
10727
10728 @menu
10729 * Sparclet File:: Setting the file to debug
10730 * Sparclet Connection:: Connecting to Sparclet
10731 * Sparclet Download:: Sparclet download
10732 * Sparclet Execution:: Running and debugging
10733 @end menu
10734
10735 @node Sparclet File
10736 @subsubsection Setting file to debug
10737
10738 The @value{GDBN} command @code{file} lets you choose with program to debug.
10739
10740 @example
10741 (gdbslet) file prog
10742 @end example
10743
10744 @need 1000
10745 @value{GDBN} then attempts to read the symbol table of @file{prog}.
10746 @value{GDBN} locates
10747 the file by searching the directories listed in the command search
10748 path.
10749 If the file was compiled with debug information (option "-g"), source
10750 files will be searched as well.
10751 @value{GDBN} locates
10752 the source files by searching the directories listed in the directory search
10753 path (@pxref{Environment, ,Your program's environment}).
10754 If it fails
10755 to find a file, it displays a message such as:
10756
10757 @example
10758 prog: No such file or directory.
10759 @end example
10760
10761 When this happens, add the appropriate directories to the search paths with
10762 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
10763 @code{target} command again.
10764
10765 @node Sparclet Connection
10766 @subsubsection Connecting to Sparclet
10767
10768 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
10769 To connect to a target on serial port ``@code{ttya}'', type:
10770
10771 @example
10772 (gdbslet) target sparclet /dev/ttya
10773 Remote target sparclet connected to /dev/ttya
10774 main () at ../prog.c:3
10775 @end example
10776
10777 @need 750
10778 @value{GDBN} displays messages like these:
10779
10780 @example
10781 Connected to ttya.
10782 @end example
10783
10784 @node Sparclet Download
10785 @subsubsection Sparclet download
10786
10787 @cindex download to Sparclet
10788 Once connected to the Sparclet target,
10789 you can use the @value{GDBN}
10790 @code{load} command to download the file from the host to the target.
10791 The file name and load offset should be given as arguments to the @code{load}
10792 command.
10793 Since the file format is aout, the program must be loaded to the starting
10794 address. You can use @code{objdump} to find out what this value is. The load
10795 offset is an offset which is added to the VMA (virtual memory address)
10796 of each of the file's sections.
10797 For instance, if the program
10798 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
10799 and bss at 0x12010170, in @value{GDBN}, type:
10800
10801 @example
10802 (gdbslet) load prog 0x12010000
10803 Loading section .text, size 0xdb0 vma 0x12010000
10804 @end example
10805
10806 If the code is loaded at a different address then what the program was linked
10807 to, you may need to use the @code{section} and @code{add-symbol-file} commands
10808 to tell @value{GDBN} where to map the symbol table.
10809
10810 @node Sparclet Execution
10811 @subsubsection Running and debugging
10812
10813 @cindex running and debugging Sparclet programs
10814 You can now begin debugging the task using @value{GDBN}'s execution control
10815 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
10816 manual for the list of commands.
10817
10818 @example
10819 (gdbslet) b main
10820 Breakpoint 1 at 0x12010000: file prog.c, line 3.
10821 (gdbslet) run
10822 Starting program: prog
10823 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
10824 3 char *symarg = 0;
10825 (gdbslet) step
10826 4 char *execarg = "hello!";
10827 (gdbslet)
10828 @end example
10829
10830 @node Sparclite
10831 @subsection Fujitsu Sparclite
10832
10833 @table @code
10834
10835 @kindex target sparclite
10836 @item target sparclite @var{dev}
10837 Fujitsu sparclite boards, used only for the purpose of loading.
10838 You must use an additional command to debug the program.
10839 For example: target remote @var{dev} using @value{GDBN} standard
10840 remote protocol.
10841
10842 @end table
10843
10844 @node ST2000
10845 @subsection Tandem ST2000
10846
10847 GDB may be used with a Tandem ST2000 phone switch, running Tandem's
10848 STDBUG protocol.
10849
10850 To connect your ST2000 to the host system, see the manufacturer's
10851 manual. Once the ST2000 is physically attached, you can run:
10852
10853 @example
10854 target st2000 @var{dev} @var{speed}
10855 @end example
10856
10857 @noindent
10858 to establish it as your debugging environment. @var{dev} is normally
10859 the name of a serial device, such as @file{/dev/ttya}, connected to the
10860 ST2000 via a serial line. You can instead specify @var{dev} as a TCP
10861 connection (for example, to a serial line attached via a terminal
10862 concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
10863
10864 The @code{load} and @code{attach} commands are @emph{not} defined for
10865 this target; you must load your program into the ST2000 as you normally
10866 would for standalone operation. @value{GDBN} reads debugging information
10867 (such as symbols) from a separate, debugging version of the program
10868 available on your host computer.
10869 @c FIXME!! This is terribly vague; what little content is here is
10870 @c basically hearsay.
10871
10872 @cindex ST2000 auxiliary commands
10873 These auxiliary @value{GDBN} commands are available to help you with the ST2000
10874 environment:
10875
10876 @table @code
10877 @item st2000 @var{command}
10878 @kindex st2000 @var{cmd}
10879 @cindex STDBUG commands (ST2000)
10880 @cindex commands to STDBUG (ST2000)
10881 Send a @var{command} to the STDBUG monitor. See the manufacturer's
10882 manual for available commands.
10883
10884 @item connect
10885 @cindex connect (to STDBUG)
10886 Connect the controlling terminal to the STDBUG command monitor. When
10887 you are done interacting with STDBUG, typing either of two character
10888 sequences gets you back to the @value{GDBN} command prompt:
10889 @kbd{@key{RET}~.} (Return, followed by tilde and period) or
10890 @kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
10891 @end table
10892
10893 @node Z8000
10894 @subsection Zilog Z8000
10895
10896 @cindex Z8000
10897 @cindex simulator, Z8000
10898 @cindex Zilog Z8000 simulator
10899
10900 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
10901 a Z8000 simulator.
10902
10903 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
10904 unsegmented variant of the Z8000 architecture) or the Z8001 (the
10905 segmented variant). The simulator recognizes which architecture is
10906 appropriate by inspecting the object code.
10907
10908 @table @code
10909 @item target sim @var{args}
10910 @kindex sim
10911 @kindex target sim@r{, with Z8000}
10912 Debug programs on a simulated CPU. If the simulator supports setup
10913 options, specify them via @var{args}.
10914 @end table
10915
10916 @noindent
10917 After specifying this target, you can debug programs for the simulated
10918 CPU in the same style as programs for your host computer; use the
10919 @code{file} command to load a new program image, the @code{run} command
10920 to run your program, and so on.
10921
10922 As well as making available all the usual machine registers
10923 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
10924 additional items of information as specially named registers:
10925
10926 @table @code
10927
10928 @item cycles
10929 Counts clock-ticks in the simulator.
10930
10931 @item insts
10932 Counts instructions run in the simulator.
10933
10934 @item time
10935 Execution time in 60ths of a second.
10936
10937 @end table
10938
10939 You can refer to these values in @value{GDBN} expressions with the usual
10940 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
10941 conditional breakpoint that suspends only after at least 5000
10942 simulated clock ticks.
10943
10944 @node Architectures
10945 @section Architectures
10946
10947 This section describes characteristics of architectures that affect
10948 all uses of GDB with this architecture, both native and cross.
10949
10950 @menu
10951 * A29K::
10952 * Alpha::
10953 * MIPS::
10954 @end menu
10955
10956 @node A29K
10957 @subsection A29K
10958
10959 @table @code
10960
10961 @kindex set rstack_high_address
10962 @cindex AMD 29K register stack
10963 @cindex register stack, AMD29K
10964 @item set rstack_high_address @var{address}
10965 On AMD 29000 family processors, registers are saved in a separate
10966 @dfn{register stack}. There is no way for @value{GDBN} to determine the
10967 extent of this stack. Normally, @value{GDBN} just assumes that the
10968 stack is ``large enough''. This may result in @value{GDBN} referencing
10969 memory locations that do not exist. If necessary, you can get around
10970 this problem by specifying the ending address of the register stack with
10971 the @code{set rstack_high_address} command. The argument should be an
10972 address, which you probably want to precede with @samp{0x} to specify in
10973 hexadecimal.
10974
10975 @kindex show rstack_high_address
10976 @item show rstack_high_address
10977 Display the current limit of the register stack, on AMD 29000 family
10978 processors.
10979
10980 @end table
10981
10982 @node Alpha
10983 @subsection Alpha
10984
10985 See the following section.
10986
10987 @node MIPS
10988 @subsection MIPS
10989
10990 @cindex stack on Alpha
10991 @cindex stack on MIPS
10992 @cindex Alpha stack
10993 @cindex MIPS stack
10994 Alpha- and MIPS-based computers use an unusual stack frame, which
10995 sometimes requires @value{GDBN} to search backward in the object code to
10996 find the beginning of a function.
10997
10998 @cindex response time, MIPS debugging
10999 To improve response time (especially for embedded applications, where
11000 @value{GDBN} may be restricted to a slow serial line for this search)
11001 you may want to limit the size of this search, using one of these
11002 commands:
11003
11004 @table @code
11005 @cindex @code{heuristic-fence-post} (Alpha,MIPS)
11006 @item set heuristic-fence-post @var{limit}
11007 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
11008 search for the beginning of a function. A value of @var{0} (the
11009 default) means there is no limit. However, except for @var{0}, the
11010 larger the limit the more bytes @code{heuristic-fence-post} must search
11011 and therefore the longer it takes to run.
11012
11013 @item show heuristic-fence-post
11014 Display the current limit.
11015 @end table
11016
11017 @noindent
11018 These commands are available @emph{only} when @value{GDBN} is configured
11019 for debugging programs on Alpha or MIPS processors.
11020
11021
11022 @node Controlling GDB
11023 @chapter Controlling @value{GDBN}
11024
11025 You can alter the way @value{GDBN} interacts with you by using the
11026 @code{set} command. For commands controlling how @value{GDBN} displays
11027 data, see @ref{Print Settings, ,Print settings}. Other settings are
11028 described here.
11029
11030 @menu
11031 * Prompt:: Prompt
11032 * Editing:: Command editing
11033 * History:: Command history
11034 * Screen Size:: Screen size
11035 * Numbers:: Numbers
11036 * Messages/Warnings:: Optional warnings and messages
11037 @end menu
11038
11039 @node Prompt
11040 @section Prompt
11041
11042 @cindex prompt
11043
11044 @value{GDBN} indicates its readiness to read a command by printing a string
11045 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
11046 can change the prompt string with the @code{set prompt} command. For
11047 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
11048 the prompt in one of the @value{GDBN} sessions so that you can always tell
11049 which one you are talking to.
11050
11051 @emph{Note:} @code{set prompt} does not add a space for you after the
11052 prompt you set. This allows you to set a prompt which ends in a space
11053 or a prompt that does not.
11054
11055 @table @code
11056 @kindex set prompt
11057 @item set prompt @var{newprompt}
11058 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
11059
11060 @kindex show prompt
11061 @item show prompt
11062 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
11063 @end table
11064
11065 @node Editing
11066 @section Command editing
11067 @cindex readline
11068 @cindex command line editing
11069
11070 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
11071 @sc{gnu} library provides consistent behavior for programs which provide a
11072 command line interface to the user. Advantages are @sc{gnu} Emacs-style
11073 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
11074 substitution, and a storage and recall of command history across
11075 debugging sessions.
11076
11077 You may control the behavior of command line editing in @value{GDBN} with the
11078 command @code{set}.
11079
11080 @table @code
11081 @kindex set editing
11082 @cindex editing
11083 @item set editing
11084 @itemx set editing on
11085 Enable command line editing (enabled by default).
11086
11087 @item set editing off
11088 Disable command line editing.
11089
11090 @kindex show editing
11091 @item show editing
11092 Show whether command line editing is enabled.
11093 @end table
11094
11095 @node History
11096 @section Command history
11097
11098 @value{GDBN} can keep track of the commands you type during your
11099 debugging sessions, so that you can be certain of precisely what
11100 happened. Use these commands to manage the @value{GDBN} command
11101 history facility.
11102
11103 @table @code
11104 @cindex history substitution
11105 @cindex history file
11106 @kindex set history filename
11107 @kindex GDBHISTFILE
11108 @item set history filename @var{fname}
11109 Set the name of the @value{GDBN} command history file to @var{fname}.
11110 This is the file where @value{GDBN} reads an initial command history
11111 list, and where it writes the command history from this session when it
11112 exits. You can access this list through history expansion or through
11113 the history command editing characters listed below. This file defaults
11114 to the value of the environment variable @code{GDBHISTFILE}, or to
11115 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
11116 is not set.
11117
11118 @cindex history save
11119 @kindex set history save
11120 @item set history save
11121 @itemx set history save on
11122 Record command history in a file, whose name may be specified with the
11123 @code{set history filename} command. By default, this option is disabled.
11124
11125 @item set history save off
11126 Stop recording command history in a file.
11127
11128 @cindex history size
11129 @kindex set history size
11130 @item set history size @var{size}
11131 Set the number of commands which @value{GDBN} keeps in its history list.
11132 This defaults to the value of the environment variable
11133 @code{HISTSIZE}, or to 256 if this variable is not set.
11134 @end table
11135
11136 @cindex history expansion
11137 History expansion assigns special meaning to the character @kbd{!}.
11138 @ifset have-readline-appendices
11139 @xref{Event Designators}.
11140 @end ifset
11141
11142 Since @kbd{!} is also the logical not operator in C, history expansion
11143 is off by default. If you decide to enable history expansion with the
11144 @code{set history expansion on} command, you may sometimes need to
11145 follow @kbd{!} (when it is used as logical not, in an expression) with
11146 a space or a tab to prevent it from being expanded. The readline
11147 history facilities do not attempt substitution on the strings
11148 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
11149
11150 The commands to control history expansion are:
11151
11152 @table @code
11153 @kindex set history expansion
11154 @item set history expansion on
11155 @itemx set history expansion
11156 Enable history expansion. History expansion is off by default.
11157
11158 @item set history expansion off
11159 Disable history expansion.
11160
11161 The readline code comes with more complete documentation of
11162 editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
11163 or @code{vi} may wish to read it.
11164 @ifset have-readline-appendices
11165 @xref{Command Line Editing}.
11166 @end ifset
11167
11168 @c @group
11169 @kindex show history
11170 @item show history
11171 @itemx show history filename
11172 @itemx show history save
11173 @itemx show history size
11174 @itemx show history expansion
11175 These commands display the state of the @value{GDBN} history parameters.
11176 @code{show history} by itself displays all four states.
11177 @c @end group
11178 @end table
11179
11180 @table @code
11181 @kindex show commands
11182 @item show commands
11183 Display the last ten commands in the command history.
11184
11185 @item show commands @var{n}
11186 Print ten commands centered on command number @var{n}.
11187
11188 @item show commands +
11189 Print ten commands just after the commands last printed.
11190 @end table
11191
11192 @node Screen Size
11193 @section Screen size
11194 @cindex size of screen
11195 @cindex pauses in output
11196
11197 Certain commands to @value{GDBN} may produce large amounts of
11198 information output to the screen. To help you read all of it,
11199 @value{GDBN} pauses and asks you for input at the end of each page of
11200 output. Type @key{RET} when you want to continue the output, or @kbd{q}
11201 to discard the remaining output. Also, the screen width setting
11202 determines when to wrap lines of output. Depending on what is being
11203 printed, @value{GDBN} tries to break the line at a readable place,
11204 rather than simply letting it overflow onto the following line.
11205
11206 Normally @value{GDBN} knows the size of the screen from the terminal
11207 driver software. For example, on Unix @value{GDBN} uses the termcap data base
11208 together with the value of the @code{TERM} environment variable and the
11209 @code{stty rows} and @code{stty cols} settings. If this is not correct,
11210 you can override it with the @code{set height} and @code{set
11211 width} commands:
11212
11213 @table @code
11214 @kindex set height
11215 @kindex set width
11216 @kindex show width
11217 @kindex show height
11218 @item set height @var{lpp}
11219 @itemx show height
11220 @itemx set width @var{cpl}
11221 @itemx show width
11222 These @code{set} commands specify a screen height of @var{lpp} lines and
11223 a screen width of @var{cpl} characters. The associated @code{show}
11224 commands display the current settings.
11225
11226 If you specify a height of zero lines, @value{GDBN} does not pause during
11227 output no matter how long the output is. This is useful if output is to a
11228 file or to an editor buffer.
11229
11230 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
11231 from wrapping its output.
11232 @end table
11233
11234 @node Numbers
11235 @section Numbers
11236 @cindex number representation
11237 @cindex entering numbers
11238
11239 You can always enter numbers in octal, decimal, or hexadecimal in @value{GDBN} by
11240 the usual conventions: octal numbers begin with @samp{0}, decimal
11241 numbers end with @samp{.}, and hexadecimal numbers begin with @samp{0x}.
11242 Numbers that begin with none of these are, by default, entered in base
11243 10; likewise, the default display for numbers---when no particular
11244 format is specified---is base 10. You can change the default base for
11245 both input and output with the @code{set radix} command.
11246
11247 @table @code
11248 @kindex set input-radix
11249 @item set input-radix @var{base}
11250 Set the default base for numeric input. Supported choices
11251 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11252 specified either unambiguously or using the current default radix; for
11253 example, any of
11254
11255 @smallexample
11256 set radix 012
11257 set radix 10.
11258 set radix 0xa
11259 @end smallexample
11260
11261 @noindent
11262 sets the base to decimal. On the other hand, @samp{set radix 10}
11263 leaves the radix unchanged no matter what it was.
11264
11265 @kindex set output-radix
11266 @item set output-radix @var{base}
11267 Set the default base for numeric display. Supported choices
11268 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11269 specified either unambiguously or using the current default radix.
11270
11271 @kindex show input-radix
11272 @item show input-radix
11273 Display the current default base for numeric input.
11274
11275 @kindex show output-radix
11276 @item show output-radix
11277 Display the current default base for numeric display.
11278 @end table
11279
11280 @node Messages/Warnings
11281 @section Optional warnings and messages
11282
11283 By default, @value{GDBN} is silent about its inner workings. If you are running
11284 on a slow machine, you may want to use the @code{set verbose} command.
11285 This makes @value{GDBN} tell you when it does a lengthy internal operation, so
11286 you will not think it has crashed.
11287
11288 Currently, the messages controlled by @code{set verbose} are those
11289 which announce that the symbol table for a source file is being read;
11290 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
11291
11292 @table @code
11293 @kindex set verbose
11294 @item set verbose on
11295 Enables @value{GDBN} output of certain informational messages.
11296
11297 @item set verbose off
11298 Disables @value{GDBN} output of certain informational messages.
11299
11300 @kindex show verbose
11301 @item show verbose
11302 Displays whether @code{set verbose} is on or off.
11303 @end table
11304
11305 By default, if @value{GDBN} encounters bugs in the symbol table of an object
11306 file, it is silent; but if you are debugging a compiler, you may find
11307 this information useful (@pxref{Symbol Errors, ,Errors reading symbol files}).
11308
11309 @table @code
11310 @kindex set complaints
11311 @item set complaints @var{limit}
11312 Permits @value{GDBN} to output @var{limit} complaints about each type of unusual
11313 symbols before becoming silent about the problem. Set @var{limit} to
11314 zero to suppress all complaints; set it to a large number to prevent
11315 complaints from being suppressed.
11316
11317 @kindex show complaints
11318 @item show complaints
11319 Displays how many symbol complaints @value{GDBN} is permitted to produce.
11320 @end table
11321
11322 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
11323 lot of stupid questions to confirm certain commands. For example, if
11324 you try to run a program which is already running:
11325
11326 @example
11327 (@value{GDBP}) run
11328 The program being debugged has been started already.
11329 Start it from the beginning? (y or n)
11330 @end example
11331
11332 If you are willing to unflinchingly face the consequences of your own
11333 commands, you can disable this ``feature'':
11334
11335 @table @code
11336 @kindex set confirm
11337 @cindex flinching
11338 @cindex confirmation
11339 @cindex stupid questions
11340 @item set confirm off
11341 Disables confirmation requests.
11342
11343 @item set confirm on
11344 Enables confirmation requests (the default).
11345
11346 @kindex show confirm
11347 @item show confirm
11348 Displays state of confirmation requests.
11349 @end table
11350
11351 @node Sequences
11352 @chapter Canned Sequences of Commands
11353
11354 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
11355 command lists}), @value{GDBN} provides two ways to store sequences of commands
11356 for execution as a unit: user-defined commands and command files.
11357
11358 @menu
11359 * Define:: User-defined commands
11360 * Hooks:: User-defined command hooks
11361 * Command Files:: Command files
11362 * Output:: Commands for controlled output
11363 @end menu
11364
11365 @node Define
11366 @section User-defined commands
11367
11368 @cindex user-defined command
11369 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to which
11370 you assign a new name as a command. This is done with the @code{define}
11371 command. User commands may accept up to 10 arguments separated by whitespace.
11372 Arguments are accessed within the user command via @var{$arg0@dots{}$arg9}.
11373 A trivial example:
11374
11375 @smallexample
11376 define adder
11377 print $arg0 + $arg1 + $arg2
11378 @end smallexample
11379
11380 @noindent
11381 To execute the command use:
11382
11383 @smallexample
11384 adder 1 2 3
11385 @end smallexample
11386
11387 @noindent
11388 This defines the command @code{adder}, which prints the sum of
11389 its three arguments. Note the arguments are text substitutions, so they may
11390 reference variables, use complex expressions, or even perform inferior
11391 functions calls.
11392
11393 @table @code
11394 @kindex define
11395 @item define @var{commandname}
11396 Define a command named @var{commandname}. If there is already a command
11397 by that name, you are asked to confirm that you want to redefine it.
11398
11399 The definition of the command is made up of other @value{GDBN} command lines,
11400 which are given following the @code{define} command. The end of these
11401 commands is marked by a line containing @code{end}.
11402
11403 @kindex if
11404 @kindex else
11405 @item if
11406 Takes a single argument, which is an expression to evaluate.
11407 It is followed by a series of commands that are executed
11408 only if the expression is true (nonzero).
11409 There can then optionally be a line @code{else}, followed
11410 by a series of commands that are only executed if the expression
11411 was false. The end of the list is marked by a line containing @code{end}.
11412
11413 @kindex while
11414 @item while
11415 The syntax is similar to @code{if}: the command takes a single argument,
11416 which is an expression to evaluate, and must be followed by the commands to
11417 execute, one per line, terminated by an @code{end}.
11418 The commands are executed repeatedly as long as the expression
11419 evaluates to true.
11420
11421 @kindex document
11422 @item document @var{commandname}
11423 Document the user-defined command @var{commandname}, so that it can be
11424 accessed by @code{help}. The command @var{commandname} must already be
11425 defined. This command reads lines of documentation just as @code{define}
11426 reads the lines of the command definition, ending with @code{end}.
11427 After the @code{document} command is finished, @code{help} on command
11428 @var{commandname} displays the documentation you have written.
11429
11430 You may use the @code{document} command again to change the
11431 documentation of a command. Redefining the command with @code{define}
11432 does not change the documentation.
11433
11434 @kindex help user-defined
11435 @item help user-defined
11436 List all user-defined commands, with the first line of the documentation
11437 (if any) for each.
11438
11439 @kindex show user
11440 @item show user
11441 @itemx show user @var{commandname}
11442 Display the @value{GDBN} commands used to define @var{commandname} (but not its
11443 documentation). If no @var{commandname} is given, display the
11444 definitions for all user-defined commands.
11445 @end table
11446
11447 When user-defined commands are executed, the
11448 commands of the definition are not printed. An error in any command
11449 stops execution of the user-defined command.
11450
11451 If used interactively, commands that would ask for confirmation proceed
11452 without asking when used inside a user-defined command. Many @value{GDBN}
11453 commands that normally print messages to say what they are doing omit the
11454 messages when used in a user-defined command.
11455
11456 @node Hooks
11457 @section User-defined command hooks
11458 @cindex command hooks
11459 @cindex hooks, for commands
11460
11461 You may define @emph{hooks}, which are a special kind of user-defined
11462 command. Whenever you run the command @samp{foo}, if the user-defined
11463 command @samp{hook-foo} exists, it is executed (with no arguments)
11464 before that command.
11465
11466 @kindex stop@r{, a pseudo-command}
11467 In addition, a pseudo-command, @samp{stop} exists. Defining
11468 (@samp{hook-stop}) makes the associated commands execute every time
11469 execution stops in your program: before breakpoint commands are run,
11470 displays are printed, or the stack frame is printed.
11471
11472 For example, to ignore @code{SIGALRM} signals while
11473 single-stepping, but treat them normally during normal execution,
11474 you could define:
11475
11476 @example
11477 define hook-stop
11478 handle SIGALRM nopass
11479 end
11480
11481 define hook-run
11482 handle SIGALRM pass
11483 end
11484
11485 define hook-continue
11486 handle SIGLARM pass
11487 end
11488 @end example
11489
11490 You can define a hook for any single-word command in @value{GDBN}, but
11491 not for command aliases; you should define a hook for the basic command
11492 name, e.g. @code{backtrace} rather than @code{bt}.
11493 @c FIXME! So how does Joe User discover whether a command is an alias
11494 @c or not?
11495 If an error occurs during the execution of your hook, execution of
11496 @value{GDBN} commands stops and @value{GDBN} issues a prompt
11497 (before the command that you actually typed had a chance to run).
11498
11499 If you try to define a hook which does not match any known command, you
11500 get a warning from the @code{define} command.
11501
11502 @node Command Files
11503 @section Command files
11504
11505 @cindex command files
11506 A command file for @value{GDBN} is a file of lines that are @value{GDBN}
11507 commands. Comments (lines starting with @kbd{#}) may also be included.
11508 An empty line in a command file does nothing; it does not mean to repeat
11509 the last command, as it would from the terminal.
11510
11511 @cindex init file
11512 @cindex @file{.gdbinit}
11513 @cindex @file{gdb.ini}
11514 When you start @value{GDBN}, it automatically executes commands from its
11515 @dfn{init files}. These are files named @file{.gdbinit} on Unix, or
11516 @file{gdb.ini} on DOS/Windows. @value{GDBN} reads the init file (if
11517 any) in your home directory@footnote{On DOS/Windows systems, the home
11518 directory is the one pointed to by the @code{HOME} environment variable.},
11519 then processes command line options and
11520 operands, and then reads the init file (if any) in the current working
11521 directory. This is so the init file in your home directory can set
11522 options (such as @code{set complaints}) which affect the processing of
11523 the command line options and operands. The init files are not executed
11524 if you use the @samp{-nx} option; @pxref{Mode Options, ,Choosing modes}.
11525
11526 @cindex init file name
11527 On some configurations of @value{GDBN}, the init file is known by a
11528 different name (these are typically environments where a specialized
11529 form of @value{GDBN} may need to coexist with other forms, hence a
11530 different name for the specialized version's init file). These are the
11531 environments with special init file names:
11532
11533 @kindex .vxgdbinit
11534 @itemize @bullet
11535 @item
11536 VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
11537
11538 @kindex .os68gdbinit
11539 @item
11540 OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
11541
11542 @kindex .esgdbinit
11543 @item
11544 ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
11545 @end itemize
11546
11547 You can also request the execution of a command file with the
11548 @code{source} command:
11549
11550 @table @code
11551 @kindex source
11552 @item source @var{filename}
11553 Execute the command file @var{filename}.
11554 @end table
11555
11556 The lines in a command file are executed sequentially. They are not
11557 printed as they are executed. An error in any command terminates execution
11558 of the command file.
11559
11560 Commands that would ask for confirmation if used interactively proceed
11561 without asking when used in a command file. Many @value{GDBN} commands that
11562 normally print messages to say what they are doing omit the messages
11563 when called from command files.
11564
11565 @node Output
11566 @section Commands for controlled output
11567
11568 During the execution of a command file or a user-defined command, normal
11569 @value{GDBN} output is suppressed; the only output that appears is what is
11570 explicitly printed by the commands in the definition. This section
11571 describes three commands useful for generating exactly the output you
11572 want.
11573
11574 @table @code
11575 @kindex echo
11576 @item echo @var{text}
11577 @c I do not consider backslash-space a standard C escape sequence
11578 @c because it is not in ANSI.
11579 Print @var{text}. Nonprinting characters can be included in
11580 @var{text} using C escape sequences, such as @samp{\n} to print a
11581 newline. @strong{No newline is printed unless you specify one.}
11582 In addition to the standard C escape sequences, a backslash followed
11583 by a space stands for a space. This is useful for displaying a
11584 string with spaces at the beginning or the end, since leading and
11585 trailing spaces are otherwise trimmed from all arguments.
11586 To print @samp{@w{ }and foo =@w{ }}, use the command
11587 @samp{echo \@w{ }and foo = \@w{ }}.
11588
11589 A backslash at the end of @var{text} can be used, as in C, to continue
11590 the command onto subsequent lines. For example,
11591
11592 @example
11593 echo This is some text\n\
11594 which is continued\n\
11595 onto several lines.\n
11596 @end example
11597
11598 produces the same output as
11599
11600 @example
11601 echo This is some text\n
11602 echo which is continued\n
11603 echo onto several lines.\n
11604 @end example
11605
11606 @kindex output
11607 @item output @var{expression}
11608 Print the value of @var{expression} and nothing but that value: no
11609 newlines, no @samp{$@var{nn} = }. The value is not entered in the
11610 value history either. @xref{Expressions, ,Expressions}, for more information
11611 on expressions.
11612
11613 @item output/@var{fmt} @var{expression}
11614 Print the value of @var{expression} in format @var{fmt}. You can use
11615 the same formats as for @code{print}. @xref{Output Formats,,Output
11616 formats}, for more information.
11617
11618 @kindex printf
11619 @item printf @var{string}, @var{expressions}@dots{}
11620 Print the values of the @var{expressions} under the control of
11621 @var{string}. The @var{expressions} are separated by commas and may be
11622 either numbers or pointers. Their values are printed as specified by
11623 @var{string}, exactly as if your program were to execute the C
11624 subroutine
11625 @c FIXME: the above implies that at least all ANSI C formats are
11626 @c supported, but it isn't true: %E and %G don't work (or so it seems).
11627 @c Either this is a bug, or the manual should document what formats are
11628 @c supported.
11629
11630 @example
11631 printf (@var{string}, @var{expressions}@dots{});
11632 @end example
11633
11634 For example, you can print two values in hex like this:
11635
11636 @smallexample
11637 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
11638 @end smallexample
11639
11640 The only backslash-escape sequences that you can use in the format
11641 string are the simple ones that consist of backslash followed by a
11642 letter.
11643 @end table
11644
11645 @node Emacs
11646 @chapter Using @value{GDBN} under @sc{gnu} Emacs
11647
11648 @cindex Emacs
11649 @cindex @sc{gnu} Emacs
11650 A special interface allows you to use @sc{gnu} Emacs to view (and
11651 edit) the source files for the program you are debugging with
11652 @value{GDBN}.
11653
11654 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
11655 executable file you want to debug as an argument. This command starts
11656 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
11657 created Emacs buffer.
11658 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
11659
11660 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
11661 things:
11662
11663 @itemize @bullet
11664 @item
11665 All ``terminal'' input and output goes through the Emacs buffer.
11666 @end itemize
11667
11668 This applies both to @value{GDBN} commands and their output, and to the input
11669 and output done by the program you are debugging.
11670
11671 This is useful because it means that you can copy the text of previous
11672 commands and input them again; you can even use parts of the output
11673 in this way.
11674
11675 All the facilities of Emacs' Shell mode are available for interacting
11676 with your program. In particular, you can send signals the usual
11677 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
11678 stop.
11679
11680 @itemize @bullet
11681 @item
11682 @value{GDBN} displays source code through Emacs.
11683 @end itemize
11684
11685 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
11686 source file for that frame and puts an arrow (@samp{=>}) at the
11687 left margin of the current line. Emacs uses a separate buffer for
11688 source display, and splits the screen to show both your @value{GDBN} session
11689 and the source.
11690
11691 Explicit @value{GDBN} @code{list} or search commands still produce output as
11692 usual, but you probably have no reason to use them from Emacs.
11693
11694 @quotation
11695 @emph{Warning:} If the directory where your program resides is not your
11696 current directory, it can be easy to confuse Emacs about the location of
11697 the source files, in which case the auxiliary display buffer does not
11698 appear to show your source. @value{GDBN} can find programs by searching your
11699 environment's @code{PATH} variable, so the @value{GDBN} input and output
11700 session proceeds normally; but Emacs does not get enough information
11701 back from @value{GDBN} to locate the source files in this situation. To
11702 avoid this problem, either start @value{GDBN} mode from the directory where
11703 your program resides, or specify an absolute file name when prompted for the
11704 @kbd{M-x gdb} argument.
11705
11706 A similar confusion can result if you use the @value{GDBN} @code{file} command to
11707 switch to debugging a program in some other location, from an existing
11708 @value{GDBN} buffer in Emacs.
11709 @end quotation
11710
11711 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
11712 you need to call @value{GDBN} by a different name (for example, if you keep
11713 several configurations around, with different names) you can set the
11714 Emacs variable @code{gdb-command-name}; for example,
11715
11716 @example
11717 (setq gdb-command-name "mygdb")
11718 @end example
11719
11720 @noindent
11721 (preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
11722 in your @file{.emacs} file) makes Emacs call the program named
11723 ``@code{mygdb}'' instead.
11724
11725 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
11726 addition to the standard Shell mode commands:
11727
11728 @table @kbd
11729 @item C-h m
11730 Describe the features of Emacs' @value{GDBN} Mode.
11731
11732 @item M-s
11733 Execute to another source line, like the @value{GDBN} @code{step} command; also
11734 update the display window to show the current file and location.
11735
11736 @item M-n
11737 Execute to next source line in this function, skipping all function
11738 calls, like the @value{GDBN} @code{next} command. Then update the display window
11739 to show the current file and location.
11740
11741 @item M-i
11742 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
11743 display window accordingly.
11744
11745 @item M-x gdb-nexti
11746 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
11747 display window accordingly.
11748
11749 @item C-c C-f
11750 Execute until exit from the selected stack frame, like the @value{GDBN}
11751 @code{finish} command.
11752
11753 @item M-c
11754 Continue execution of your program, like the @value{GDBN} @code{continue}
11755 command.
11756
11757 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
11758
11759 @item M-u
11760 Go up the number of frames indicated by the numeric argument
11761 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
11762 like the @value{GDBN} @code{up} command.
11763
11764 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
11765
11766 @item M-d
11767 Go down the number of frames indicated by the numeric argument, like the
11768 @value{GDBN} @code{down} command.
11769
11770 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
11771
11772 @item C-x &
11773 Read the number where the cursor is positioned, and insert it at the end
11774 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
11775 around an address that was displayed earlier, type @kbd{disassemble};
11776 then move the cursor to the address display, and pick up the
11777 argument for @code{disassemble} by typing @kbd{C-x &}.
11778
11779 You can customize this further by defining elements of the list
11780 @code{gdb-print-command}; once it is defined, you can format or
11781 otherwise process numbers picked up by @kbd{C-x &} before they are
11782 inserted. A numeric argument to @kbd{C-x &} indicates that you
11783 wish special formatting, and also acts as an index to pick an element of the
11784 list. If the list element is a string, the number to be inserted is
11785 formatted using the Emacs function @code{format}; otherwise the number
11786 is passed as an argument to the corresponding list element.
11787 @end table
11788
11789 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
11790 tells @value{GDBN} to set a breakpoint on the source line point is on.
11791
11792 If you accidentally delete the source-display buffer, an easy way to get
11793 it back is to type the command @code{f} in the @value{GDBN} buffer, to
11794 request a frame display; when you run under Emacs, this recreates
11795 the source buffer if necessary to show you the context of the current
11796 frame.
11797
11798 The source files displayed in Emacs are in ordinary Emacs buffers
11799 which are visiting the source files in the usual way. You can edit
11800 the files with these buffers if you wish; but keep in mind that @value{GDBN}
11801 communicates with Emacs in terms of line numbers. If you add or
11802 delete lines from the text, the line numbers that @value{GDBN} knows cease
11803 to correspond properly with the code.
11804
11805 @c The following dropped because Epoch is nonstandard. Reactivate
11806 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
11807 @ignore
11808 @kindex Emacs Epoch environment
11809 @kindex Epoch
11810 @kindex inspect
11811
11812 Version 18 of @sc{gnu} Emacs has a built-in window system
11813 called the @code{epoch}
11814 environment. Users of this environment can use a new command,
11815 @code{inspect} which performs identically to @code{print} except that
11816 each value is printed in its own window.
11817 @end ignore
11818
11819 @node GDB Bugs
11820 @chapter Reporting Bugs in @value{GDBN}
11821 @cindex bugs in @value{GDBN}
11822 @cindex reporting bugs in @value{GDBN}
11823
11824 Your bug reports play an essential role in making @value{GDBN} reliable.
11825
11826 Reporting a bug may help you by bringing a solution to your problem, or it
11827 may not. But in any case the principal function of a bug report is to help
11828 the entire community by making the next version of @value{GDBN} work better. Bug
11829 reports are your contribution to the maintenance of @value{GDBN}.
11830
11831 In order for a bug report to serve its purpose, you must include the
11832 information that enables us to fix the bug.
11833
11834 @menu
11835 * Bug Criteria:: Have you found a bug?
11836 * Bug Reporting:: How to report bugs
11837 @end menu
11838
11839 @node Bug Criteria
11840 @section Have you found a bug?
11841 @cindex bug criteria
11842
11843 If you are not sure whether you have found a bug, here are some guidelines:
11844
11845 @itemize @bullet
11846 @cindex fatal signal
11847 @cindex debugger crash
11848 @cindex crash of debugger
11849 @item
11850 If the debugger gets a fatal signal, for any input whatever, that is a
11851 @value{GDBN} bug. Reliable debuggers never crash.
11852
11853 @cindex error on valid input
11854 @item
11855 If @value{GDBN} produces an error message for valid input, that is a
11856 bug. (Note that if you're cross debugging, the problem may also be
11857 somewhere in the connection to the target.)
11858
11859 @cindex invalid input
11860 @item
11861 If @value{GDBN} does not produce an error message for invalid input,
11862 that is a bug. However, you should note that your idea of
11863 ``invalid input'' might be our idea of ``an extension'' or ``support
11864 for traditional practice''.
11865
11866 @item
11867 If you are an experienced user of debugging tools, your suggestions
11868 for improvement of @value{GDBN} are welcome in any case.
11869 @end itemize
11870
11871 @node Bug Reporting
11872 @section How to report bugs
11873 @cindex bug reports
11874 @cindex @value{GDBN} bugs, reporting
11875
11876 A number of companies and individuals offer support for @sc{gnu} products.
11877 If you obtained @value{GDBN} from a support organization, we recommend you
11878 contact that organization first.
11879
11880 You can find contact information for many support companies and
11881 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
11882 distribution.
11883 @c should add a web page ref...
11884
11885 In any event, we also recommend that you send bug reports for
11886 @value{GDBN} to this addresses:
11887
11888 @example
11889 bug-gdb@@gnu.org
11890 @end example
11891
11892 @strong{Do not send bug reports to @samp{info-gdb}, or to
11893 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
11894 not want to receive bug reports. Those that do have arranged to receive
11895 @samp{bug-gdb}.
11896
11897 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
11898 serves as a repeater. The mailing list and the newsgroup carry exactly
11899 the same messages. Often people think of posting bug reports to the
11900 newsgroup instead of mailing them. This appears to work, but it has one
11901 problem which can be crucial: a newsgroup posting often lacks a mail
11902 path back to the sender. Thus, if we need to ask for more information,
11903 we may be unable to reach you. For this reason, it is better to send
11904 bug reports to the mailing list.
11905
11906 As a last resort, send bug reports on paper to:
11907
11908 @example
11909 @sc{gnu} Debugger Bugs
11910 Free Software Foundation Inc.
11911 59 Temple Place - Suite 330
11912 Boston, MA 02111-1307
11913 USA
11914 @end example
11915
11916 The fundamental principle of reporting bugs usefully is this:
11917 @strong{report all the facts}. If you are not sure whether to state a
11918 fact or leave it out, state it!
11919
11920 Often people omit facts because they think they know what causes the
11921 problem and assume that some details do not matter. Thus, you might
11922 assume that the name of the variable you use in an example does not matter.
11923 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
11924 stray memory reference which happens to fetch from the location where that
11925 name is stored in memory; perhaps, if the name were different, the contents
11926 of that location would fool the debugger into doing the right thing despite
11927 the bug. Play it safe and give a specific, complete example. That is the
11928 easiest thing for you to do, and the most helpful.
11929
11930 Keep in mind that the purpose of a bug report is to enable us to fix the
11931 bug. It may be that the bug has been reported previously, but neither
11932 you nor we can know that unless your bug report is complete and
11933 self-contained.
11934
11935 Sometimes people give a few sketchy facts and ask, ``Does this ring a
11936 bell?'' Those bug reports are useless, and we urge everyone to
11937 @emph{refuse to respond to them} except to chide the sender to report
11938 bugs properly.
11939
11940 To enable us to fix the bug, you should include all these things:
11941
11942 @itemize @bullet
11943 @item
11944 The version of @value{GDBN}. @value{GDBN} announces it if you start
11945 with no arguments; you can also print it at any time using @code{show
11946 version}.
11947
11948 Without this, we will not know whether there is any point in looking for
11949 the bug in the current version of @value{GDBN}.
11950
11951 @item
11952 The type of machine you are using, and the operating system name and
11953 version number.
11954
11955 @item
11956 What compiler (and its version) was used to compile @value{GDBN}---e.g.
11957 ``@value{GCC}--2.8.1''.
11958
11959 @item
11960 What compiler (and its version) was used to compile the program you are
11961 debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
11962 C Compiler''. For GCC, you can say @code{gcc --version} to get this
11963 information; for other compilers, see the documentation for those
11964 compilers.
11965
11966 @item
11967 The command arguments you gave the compiler to compile your example and
11968 observe the bug. For example, did you use @samp{-O}? To guarantee
11969 you will not omit something important, list them all. A copy of the
11970 Makefile (or the output from make) is sufficient.
11971
11972 If we were to try to guess the arguments, we would probably guess wrong
11973 and then we might not encounter the bug.
11974
11975 @item
11976 A complete input script, and all necessary source files, that will
11977 reproduce the bug.
11978
11979 @item
11980 A description of what behavior you observe that you believe is
11981 incorrect. For example, ``It gets a fatal signal.''
11982
11983 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
11984 will certainly notice it. But if the bug is incorrect output, we might
11985 not notice unless it is glaringly wrong. You might as well not give us
11986 a chance to make a mistake.
11987
11988 Even if the problem you experience is a fatal signal, you should still
11989 say so explicitly. Suppose something strange is going on, such as, your
11990 copy of @value{GDBN} is out of synch, or you have encountered a bug in
11991 the C library on your system. (This has happened!) Your copy might
11992 crash and ours would not. If you told us to expect a crash, then when
11993 ours fails to crash, we would know that the bug was not happening for
11994 us. If you had not told us to expect a crash, then we would not be able
11995 to draw any conclusion from our observations.
11996
11997 @item
11998 If you wish to suggest changes to the @value{GDBN} source, send us context
11999 diffs. If you even discuss something in the @value{GDBN} source, refer to
12000 it by context, not by line number.
12001
12002 The line numbers in our development sources will not match those in your
12003 sources. Your line numbers would convey no useful information to us.
12004
12005 @end itemize
12006
12007 Here are some things that are not necessary:
12008
12009 @itemize @bullet
12010 @item
12011 A description of the envelope of the bug.
12012
12013 Often people who encounter a bug spend a lot of time investigating
12014 which changes to the input file will make the bug go away and which
12015 changes will not affect it.
12016
12017 This is often time consuming and not very useful, because the way we
12018 will find the bug is by running a single example under the debugger
12019 with breakpoints, not by pure deduction from a series of examples.
12020 We recommend that you save your time for something else.
12021
12022 Of course, if you can find a simpler example to report @emph{instead}
12023 of the original one, that is a convenience for us. Errors in the
12024 output will be easier to spot, running under the debugger will take
12025 less time, and so on.
12026
12027 However, simplification is not vital; if you do not want to do this,
12028 report the bug anyway and send us the entire test case you used.
12029
12030 @item
12031 A patch for the bug.
12032
12033 A patch for the bug does help us if it is a good one. But do not omit
12034 the necessary information, such as the test case, on the assumption that
12035 a patch is all we need. We might see problems with your patch and decide
12036 to fix the problem another way, or we might not understand it at all.
12037
12038 Sometimes with a program as complicated as @value{GDBN} it is very hard to
12039 construct an example that will make the program follow a certain path
12040 through the code. If you do not send us the example, we will not be able
12041 to construct one, so we will not be able to verify that the bug is fixed.
12042
12043 And if we cannot understand what bug you are trying to fix, or why your
12044 patch should be an improvement, we will not install it. A test case will
12045 help us to understand.
12046
12047 @item
12048 A guess about what the bug is or what it depends on.
12049
12050 Such guesses are usually wrong. Even we cannot guess right about such
12051 things without first using the debugger to find the facts.
12052 @end itemize
12053
12054 @c The readline documentation is distributed with the readline code
12055 @c and consists of the two following files:
12056 @c rluser.texinfo
12057 @c inc-hist.texinfo
12058 @c Use -I with makeinfo to point to the appropriate directory,
12059 @c environment var TEXINPUTS with TeX.
12060 @include rluser.texinfo
12061 @include inc-hist.texinfo
12062
12063
12064 @node Formatting Documentation
12065 @appendix Formatting Documentation
12066
12067 @cindex @value{GDBN} reference card
12068 @cindex reference card
12069 The @value{GDBN} 4 release includes an already-formatted reference card, ready
12070 for printing with PostScript or Ghostscript, in the @file{gdb}
12071 subdirectory of the main source directory@footnote{In
12072 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
12073 release.}. If you can use PostScript or Ghostscript with your printer,
12074 you can print the reference card immediately with @file{refcard.ps}.
12075
12076 The release also includes the source for the reference card. You
12077 can format it, using @TeX{}, by typing:
12078
12079 @example
12080 make refcard.dvi
12081 @end example
12082
12083 The @value{GDBN} reference card is designed to print in @dfn{landscape}
12084 mode on US ``letter'' size paper;
12085 that is, on a sheet 11 inches wide by 8.5 inches
12086 high. You will need to specify this form of printing as an option to
12087 your @sc{dvi} output program.
12088
12089 @cindex documentation
12090
12091 All the documentation for @value{GDBN} comes as part of the machine-readable
12092 distribution. The documentation is written in Texinfo format, which is
12093 a documentation system that uses a single source file to produce both
12094 on-line information and a printed manual. You can use one of the Info
12095 formatting commands to create the on-line version of the documentation
12096 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
12097
12098 @value{GDBN} includes an already formatted copy of the on-line Info
12099 version of this manual in the @file{gdb} subdirectory. The main Info
12100 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
12101 subordinate files matching @samp{gdb.info*} in the same directory. If
12102 necessary, you can print out these files, or read them with any editor;
12103 but they are easier to read using the @code{info} subsystem in @sc{gnu}
12104 Emacs or the standalone @code{info} program, available as part of the
12105 @sc{gnu} Texinfo distribution.
12106
12107 If you want to format these Info files yourself, you need one of the
12108 Info formatting programs, such as @code{texinfo-format-buffer} or
12109 @code{makeinfo}.
12110
12111 If you have @code{makeinfo} installed, and are in the top level
12112 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
12113 version @value{GDBVN}), you can make the Info file by typing:
12114
12115 @example
12116 cd gdb
12117 make gdb.info
12118 @end example
12119
12120 If you want to typeset and print copies of this manual, you need @TeX{},
12121 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
12122 Texinfo definitions file.
12123
12124 @TeX{} is a typesetting program; it does not print files directly, but
12125 produces output files called @sc{dvi} files. To print a typeset
12126 document, you need a program to print @sc{dvi} files. If your system
12127 has @TeX{} installed, chances are it has such a program. The precise
12128 command to use depends on your system; @kbd{lpr -d} is common; another
12129 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
12130 require a file name without any extension or a @samp{.dvi} extension.
12131
12132 @TeX{} also requires a macro definitions file called
12133 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
12134 written in Texinfo format. On its own, @TeX{} cannot either read or
12135 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
12136 and is located in the @file{gdb-@var{version-number}/texinfo}
12137 directory.
12138
12139 If you have @TeX{} and a @sc{dvi} printer program installed, you can
12140 typeset and print this manual. First switch to the the @file{gdb}
12141 subdirectory of the main source directory (for example, to
12142 @file{gdb-@value{GDBVN}/gdb}) and type:
12143
12144 @example
12145 make gdb.dvi
12146 @end example
12147
12148 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
12149
12150 @node Installing GDB
12151 @appendix Installing @value{GDBN}
12152 @cindex configuring @value{GDBN}
12153 @cindex installation
12154
12155 @value{GDBN} comes with a @code{configure} script that automates the process
12156 of preparing @value{GDBN} for installation; you can then use @code{make} to
12157 build the @code{gdb} program.
12158 @iftex
12159 @c irrelevant in info file; it's as current as the code it lives with.
12160 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
12161 look at the @file{README} file in the sources; we may have improved the
12162 installation procedures since publishing this manual.}
12163 @end iftex
12164
12165 The @value{GDBN} distribution includes all the source code you need for
12166 @value{GDBN} in a single directory, whose name is usually composed by
12167 appending the version number to @samp{gdb}.
12168
12169 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
12170 @file{gdb-@value{GDBVN}} directory. That directory contains:
12171
12172 @table @code
12173 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
12174 script for configuring @value{GDBN} and all its supporting libraries
12175
12176 @item gdb-@value{GDBVN}/gdb
12177 the source specific to @value{GDBN} itself
12178
12179 @item gdb-@value{GDBVN}/bfd
12180 source for the Binary File Descriptor library
12181
12182 @item gdb-@value{GDBVN}/include
12183 @sc{gnu} include files
12184
12185 @item gdb-@value{GDBVN}/libiberty
12186 source for the @samp{-liberty} free software library
12187
12188 @item gdb-@value{GDBVN}/opcodes
12189 source for the library of opcode tables and disassemblers
12190
12191 @item gdb-@value{GDBVN}/readline
12192 source for the @sc{gnu} command-line interface
12193
12194 @item gdb-@value{GDBVN}/glob
12195 source for the @sc{gnu} filename pattern-matching subroutine
12196
12197 @item gdb-@value{GDBVN}/mmalloc
12198 source for the @sc{gnu} memory-mapped malloc package
12199 @end table
12200
12201 The simplest way to configure and build @value{GDBN} is to run @code{configure}
12202 from the @file{gdb-@var{version-number}} source directory, which in
12203 this example is the @file{gdb-@value{GDBVN}} directory.
12204
12205 First switch to the @file{gdb-@var{version-number}} source directory
12206 if you are not already in it; then run @code{configure}. Pass the
12207 identifier for the platform on which @value{GDBN} will run as an
12208 argument.
12209
12210 For example:
12211
12212 @example
12213 cd gdb-@value{GDBVN}
12214 ./configure @var{host}
12215 make
12216 @end example
12217
12218 @noindent
12219 where @var{host} is an identifier such as @samp{sun4} or
12220 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
12221 (You can often leave off @var{host}; @code{configure} tries to guess the
12222 correct value by examining your system.)
12223
12224 Running @samp{configure @var{host}} and then running @code{make} builds the
12225 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
12226 libraries, then @code{gdb} itself. The configured source files, and the
12227 binaries, are left in the corresponding source directories.
12228
12229 @need 750
12230 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
12231 system does not recognize this automatically when you run a different
12232 shell, you may need to run @code{sh} on it explicitly:
12233
12234 @example
12235 sh configure @var{host}
12236 @end example
12237
12238 If you run @code{configure} from a directory that contains source
12239 directories for multiple libraries or programs, such as the
12240 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
12241 creates configuration files for every directory level underneath (unless
12242 you tell it not to, with the @samp{--norecursion} option).
12243
12244 You can run the @code{configure} script from any of the
12245 subordinate directories in the @value{GDBN} distribution if you only want to
12246 configure that subdirectory, but be sure to specify a path to it.
12247
12248 For example, with version @value{GDBVN}, type the following to configure only
12249 the @code{bfd} subdirectory:
12250
12251 @example
12252 @group
12253 cd gdb-@value{GDBVN}/bfd
12254 ../configure @var{host}
12255 @end group
12256 @end example
12257
12258 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
12259 However, you should make sure that the shell on your path (named by
12260 the @samp{SHELL} environment variable) is publicly readable. Remember
12261 that @value{GDBN} uses the shell to start your program---some systems refuse to
12262 let @value{GDBN} debug child processes whose programs are not readable.
12263
12264 @menu
12265 * Separate Objdir:: Compiling @value{GDBN} in another directory
12266 * Config Names:: Specifying names for hosts and targets
12267 * Configure Options:: Summary of options for configure
12268 @end menu
12269
12270 @node Separate Objdir
12271 @section Compiling @value{GDBN} in another directory
12272
12273 If you want to run @value{GDBN} versions for several host or target machines,
12274 you need a different @code{gdb} compiled for each combination of
12275 host and target. @code{configure} is designed to make this easy by
12276 allowing you to generate each configuration in a separate subdirectory,
12277 rather than in the source directory. If your @code{make} program
12278 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
12279 @code{make} in each of these directories builds the @code{gdb}
12280 program specified there.
12281
12282 To build @code{gdb} in a separate directory, run @code{configure}
12283 with the @samp{--srcdir} option to specify where to find the source.
12284 (You also need to specify a path to find @code{configure}
12285 itself from your working directory. If the path to @code{configure}
12286 would be the same as the argument to @samp{--srcdir}, you can leave out
12287 the @samp{--srcdir} option; it is assumed.)
12288
12289 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
12290 separate directory for a Sun 4 like this:
12291
12292 @example
12293 @group
12294 cd gdb-@value{GDBVN}
12295 mkdir ../gdb-sun4
12296 cd ../gdb-sun4
12297 ../gdb-@value{GDBVN}/configure sun4
12298 make
12299 @end group
12300 @end example
12301
12302 When @code{configure} builds a configuration using a remote source
12303 directory, it creates a tree for the binaries with the same structure
12304 (and using the same names) as the tree under the source directory. In
12305 the example, you'd find the Sun 4 library @file{libiberty.a} in the
12306 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
12307 @file{gdb-sun4/gdb}.
12308
12309 One popular reason to build several @value{GDBN} configurations in separate
12310 directories is to configure @value{GDBN} for cross-compiling (where
12311 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
12312 programs that run on another machine---the @dfn{target}).
12313 You specify a cross-debugging target by
12314 giving the @samp{--target=@var{target}} option to @code{configure}.
12315
12316 When you run @code{make} to build a program or library, you must run
12317 it in a configured directory---whatever directory you were in when you
12318 called @code{configure} (or one of its subdirectories).
12319
12320 The @code{Makefile} that @code{configure} generates in each source
12321 directory also runs recursively. If you type @code{make} in a source
12322 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
12323 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
12324 will build all the required libraries, and then build GDB.
12325
12326 When you have multiple hosts or targets configured in separate
12327 directories, you can run @code{make} on them in parallel (for example,
12328 if they are NFS-mounted on each of the hosts); they will not interfere
12329 with each other.
12330
12331 @node Config Names
12332 @section Specifying names for hosts and targets
12333
12334 The specifications used for hosts and targets in the @code{configure}
12335 script are based on a three-part naming scheme, but some short predefined
12336 aliases are also supported. The full naming scheme encodes three pieces
12337 of information in the following pattern:
12338
12339 @example
12340 @var{architecture}-@var{vendor}-@var{os}
12341 @end example
12342
12343 For example, you can use the alias @code{sun4} as a @var{host} argument,
12344 or as the value for @var{target} in a @code{--target=@var{target}}
12345 option. The equivalent full name is @samp{sparc-sun-sunos4}.
12346
12347 The @code{configure} script accompanying @value{GDBN} does not provide
12348 any query facility to list all supported host and target names or
12349 aliases. @code{configure} calls the Bourne shell script
12350 @code{config.sub} to map abbreviations to full names; you can read the
12351 script, if you wish, or you can use it to test your guesses on
12352 abbreviations---for example:
12353
12354 @smallexample
12355 % sh config.sub i386-linux
12356 i386-pc-linux-gnu
12357 % sh config.sub alpha-linux
12358 alpha-unknown-linux-gnu
12359 % sh config.sub hp9k700
12360 hppa1.1-hp-hpux
12361 % sh config.sub sun4
12362 sparc-sun-sunos4.1.1
12363 % sh config.sub sun3
12364 m68k-sun-sunos4.1.1
12365 % sh config.sub i986v
12366 Invalid configuration `i986v': machine `i986v' not recognized
12367 @end smallexample
12368
12369 @noindent
12370 @code{config.sub} is also distributed in the @value{GDBN} source
12371 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
12372
12373 @node Configure Options
12374 @section @code{configure} options
12375
12376 Here is a summary of the @code{configure} options and arguments that
12377 are most often useful for building @value{GDBN}. @code{configure} also has
12378 several other options not listed here. @inforef{What Configure
12379 Does,,configure.info}, for a full explanation of @code{configure}.
12380
12381 @example
12382 configure @r{[}--help@r{]}
12383 @r{[}--prefix=@var{dir}@r{]}
12384 @r{[}--exec-prefix=@var{dir}@r{]}
12385 @r{[}--srcdir=@var{dirname}@r{]}
12386 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
12387 @r{[}--target=@var{target}@r{]}
12388 @var{host}
12389 @end example
12390
12391 @noindent
12392 You may introduce options with a single @samp{-} rather than
12393 @samp{--} if you prefer; but you may abbreviate option names if you use
12394 @samp{--}.
12395
12396 @table @code
12397 @item --help
12398 Display a quick summary of how to invoke @code{configure}.
12399
12400 @item --prefix=@var{dir}
12401 Configure the source to install programs and files under directory
12402 @file{@var{dir}}.
12403
12404 @item --exec-prefix=@var{dir}
12405 Configure the source to install programs under directory
12406 @file{@var{dir}}.
12407
12408 @c avoid splitting the warning from the explanation:
12409 @need 2000
12410 @item --srcdir=@var{dirname}
12411 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
12412 @code{make} that implements the @code{VPATH} feature.}@*
12413 Use this option to make configurations in directories separate from the
12414 @value{GDBN} source directories. Among other things, you can use this to
12415 build (or maintain) several configurations simultaneously, in separate
12416 directories. @code{configure} writes configuration specific files in
12417 the current directory, but arranges for them to use the source in the
12418 directory @var{dirname}. @code{configure} creates directories under
12419 the working directory in parallel to the source directories below
12420 @var{dirname}.
12421
12422 @item --norecursion
12423 Configure only the directory level where @code{configure} is executed; do not
12424 propagate configuration to subdirectories.
12425
12426 @item --target=@var{target}
12427 Configure @value{GDBN} for cross-debugging programs running on the specified
12428 @var{target}. Without this option, @value{GDBN} is configured to debug
12429 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
12430
12431 There is no convenient way to generate a list of all available targets.
12432
12433 @item @var{host} @dots{}
12434 Configure @value{GDBN} to run on the specified @var{host}.
12435
12436 There is no convenient way to generate a list of all available hosts.
12437 @end table
12438
12439 There are many other options available as well, but they are generally
12440 needed for special purposes only.
12441
12442 @node Index
12443 @unnumbered Index
12444
12445 @printindex cp
12446
12447 @tex
12448 % I think something like @colophon should be in texinfo. In the
12449 % meantime:
12450 \long\def\colophon{\hbox to0pt{}\vfill
12451 \centerline{The body of this manual is set in}
12452 \centerline{\fontname\tenrm,}
12453 \centerline{with headings in {\bf\fontname\tenbf}}
12454 \centerline{and examples in {\tt\fontname\tentt}.}
12455 \centerline{{\it\fontname\tenit\/},}
12456 \centerline{{\bf\fontname\tenbf}, and}
12457 \centerline{{\sl\fontname\tensl\/}}
12458 \centerline{are used for emphasis.}\vfill}
12459 \page\colophon
12460 % Blame: doc@cygnus.com, 1991.
12461 @end tex
12462
12463 @contents
12464 @bye
This page took 0.296481 seconds and 4 git commands to generate.