be4a8c906db56bedd5b37c944c39ebc5d3b877a9
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright 1988-2000
3 @c Free Software Foundation, Inc.
4 @c
5 @c %**start of header
6 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
7 @c of @set vars. However, you can override filename with makeinfo -o.
8 @setfilename gdb.info
9 @c
10 @include gdb-cfg.texi
11 @c
12 @settitle Debugging with @value{GDBN}
13 @setchapternewpage odd
14 @c %**end of header
15
16 @iftex
17 @c @smallbook
18 @c @cropmarks
19 @end iftex
20
21 @finalout
22 @syncodeindex ky cp
23
24 @c readline appendices use @vindex
25 @syncodeindex vr cp
26
27 @c !!set GDB manual's edition---not the same as GDB version!
28 @set EDITION Eighth
29
30 @c !!set GDB manual's revision date
31 @set DATE March 2000
32
33 @c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
34
35 @c This is a dir.info fragment to support semi-automated addition of
36 @c manuals to an info tree.
37 @dircategory Programming & development tools.
38 @direntry
39 * Gdb: (gdb). The @sc{gnu} debugger.
40 @end direntry
41
42 @ifinfo
43 This file documents the @sc{gnu} debugger @value{GDBN}.
44
45
46 This is the @value{EDITION} Edition, @value{DATE},
47 of @cite{Debugging with @value{GDBN}: the @sc{gnu} Source-Level Debugger}
48 for @value{GDBN} Version @value{GDBVN}.
49
50 Copyright (C) 1988-2000 Free Software Foundation, Inc.
51
52 Permission is granted to make and distribute verbatim copies of
53 this manual provided the copyright notice and this permission notice
54 are preserved on all copies.
55
56 @ignore
57 Permission is granted to process this file through TeX and print the
58 results, provided the printed document carries copying permission
59 notice identical to this one except for the removal of this paragraph
60 (this paragraph not being relevant to the printed manual).
61
62 @end ignore
63 Permission is granted to copy and distribute modified versions of this
64 manual under the conditions for verbatim copying, provided also that the
65 entire resulting derived work is distributed under the terms of a
66 permission notice identical to this one.
67
68 Permission is granted to copy and distribute translations of this manual
69 into another language, under the above conditions for modified versions.
70 @end ifinfo
71
72 @titlepage
73 @title Debugging with @value{GDBN}
74 @subtitle The @sc{gnu} Source-Level Debugger
75 @sp 1
76 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
77 @subtitle @value{DATE}
78 @author Richard M. Stallman and Roland H. Pesch
79 @page
80 @tex
81 {\parskip=0pt
82 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
83 \hfill {\it Debugging with @value{GDBN}}\par
84 \hfill \TeX{}info \texinfoversion\par
85 }
86 @end tex
87
88 @vskip 0pt plus 1filll
89 Copyright @copyright{} 1988-2000 Free Software Foundation, Inc.
90 @sp 2
91 Published by the Free Software Foundation @*
92 59 Temple Place - Suite 330, @*
93 Boston, MA 02111-1307 USA @*
94 ISBN 1-882114-77-9 @*
95
96 Permission is granted to make and distribute verbatim copies of
97 this manual provided the copyright notice and this permission notice
98 are preserved on all copies.
99
100 Permission is granted to copy and distribute modified versions of this
101 manual under the conditions for verbatim copying, provided also that the
102 entire resulting derived work is distributed under the terms of a
103 permission notice identical to this one.
104
105 Permission is granted to copy and distribute translations of this manual
106 into another language, under the above conditions for modified versions.
107 @end titlepage
108 @page
109
110 @ifinfo
111 @node Top, Summary, (dir), (dir)
112
113 @top Debugging with @value{GDBN}
114
115 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
117 This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
118 @value{GDBVN}.
119
120 Copyright (C) 1988-2000 Free Software Foundation, Inc.
121
122 @menu
123 * Summary:: Summary of @value{GDBN}
124 * Sample Session:: A sample @value{GDBN} session
125
126 * Invocation:: Getting in and out of @value{GDBN}
127 * Commands:: @value{GDBN} commands
128 * Running:: Running programs under @value{GDBN}
129 * Stopping:: Stopping and continuing
130 * Stack:: Examining the stack
131 * Source:: Examining source files
132 * Data:: Examining data
133
134 * Languages:: Using @value{GDBN} with different languages
135
136 * Symbols:: Examining the symbol table
137 * Altering:: Altering execution
138 * GDB Files:: @value{GDBN} files
139 * Targets:: Specifying a debugging target
140 * Configurations:: Configuration-specific information
141 * Controlling GDB:: Controlling @value{GDBN}
142 * Sequences:: Canned sequences of commands
143 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
144 * Annotations:: @value{GDBN}'s annotation interface.
145
146 * GDB Bugs:: Reporting bugs in @value{GDBN}
147 * Formatting Documentation:: How to format and print @value{GDBN} documentation
148
149 * Command Line Editing:: Command Line Editing
150 * Using History Interactively:: Using History Interactively
151 * Installing GDB:: Installing GDB
152 * Index:: Index
153 @end menu
154
155 @end ifinfo
156
157 @c the replication sucks, but this avoids a texinfo 3.12 lameness
158
159 @ifhtml
160 @node Top
161
162 @top Debugging with @value{GDBN}
163
164 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
165
166 This is the @value{EDITION} Edition, @value{DATE}, for @value{GDBN} Version
167 @value{GDBVN}.
168
169 Copyright (C) 1988-2000 Free Software Foundation, Inc.
170
171 @menu
172 * Summary:: Summary of @value{GDBN}
173 * Sample Session:: A sample @value{GDBN} session
174
175 * Invocation:: Getting in and out of @value{GDBN}
176 * Commands:: @value{GDBN} commands
177 * Running:: Running programs under @value{GDBN}
178 * Stopping:: Stopping and continuing
179 * Stack:: Examining the stack
180 * Source:: Examining source files
181 * Data:: Examining data
182
183 * Languages:: Using @value{GDBN} with different languages
184
185 * Symbols:: Examining the symbol table
186 * Altering:: Altering execution
187 * GDB Files:: @value{GDBN} files
188 * Targets:: Specifying a debugging target
189 * Configurations:: Configuration-specific information
190 * Controlling GDB:: Controlling @value{GDBN}
191 * Sequences:: Canned sequences of commands
192 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
193 * Annotations:: @value{GDBN}'s annotation interface.
194
195 * GDB Bugs:: Reporting bugs in @value{GDBN}
196 * Formatting Documentation:: How to format and print @value{GDBN} documentation
197
198 * Command Line Editing:: Command Line Editing
199 * Using History Interactively:: Using History Interactively
200 * Installing GDB:: Installing GDB
201 * Index:: Index
202 @end menu
203
204 @end ifhtml
205
206 @node Summary
207 @unnumbered Summary of @value{GDBN}
208
209 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
210 going on ``inside'' another program while it executes---or what another
211 program was doing at the moment it crashed.
212
213 @value{GDBN} can do four main kinds of things (plus other things in support of
214 these) to help you catch bugs in the act:
215
216 @itemize @bullet
217 @item
218 Start your program, specifying anything that might affect its behavior.
219
220 @item
221 Make your program stop on specified conditions.
222
223 @item
224 Examine what has happened, when your program has stopped.
225
226 @item
227 Change things in your program, so you can experiment with correcting the
228 effects of one bug and go on to learn about another.
229 @end itemize
230
231 You can use @value{GDBN} to debug programs written in C and C++.
232 For more information, see @ref{Support,,Supported languages}.
233 For more information, see @ref{C,,C and C++}.
234
235 @cindex Chill
236 @cindex Modula-2
237 Support for Modula-2 and Chill is partial. For information on Modula-2,
238 see @ref{Modula-2,,Modula-2}. For information on Chill, see @ref{Chill}.
239
240 @cindex Pascal
241 Debugging Pascal programs which use sets, subranges, file variables, or
242 nested functions does not currently work. @value{GDBN} does not support
243 entering expressions, printing values, or similar features using Pascal
244 syntax.
245
246 @cindex Fortran
247 @value{GDBN} can be used to debug programs written in Fortran, although
248 it may be necessary to refer to some variables with a trailing
249 underscore.
250
251 @menu
252 * Free Software:: Freely redistributable software
253 * Contributors:: Contributors to GDB
254 @end menu
255
256 @node Free Software
257 @unnumberedsec Free software
258
259 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
260 General Public License
261 (GPL). The GPL gives you the freedom to copy or adapt a licensed
262 program---but every person getting a copy also gets with it the
263 freedom to modify that copy (which means that they must get access to
264 the source code), and the freedom to distribute further copies.
265 Typical software companies use copyrights to limit your freedoms; the
266 Free Software Foundation uses the GPL to preserve these freedoms.
267
268 Fundamentally, the General Public License is a license which says that
269 you have these freedoms and that you cannot take these freedoms away
270 from anyone else.
271
272 @node Contributors
273 @unnumberedsec Contributors to @value{GDBN}
274
275 Richard Stallman was the original author of @value{GDBN}, and of many
276 other @sc{gnu} programs. Many others have contributed to its
277 development. This section attempts to credit major contributors. One
278 of the virtues of free software is that everyone is free to contribute
279 to it; with regret, we cannot actually acknowledge everyone here. The
280 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
281 blow-by-blow account.
282
283 Changes much prior to version 2.0 are lost in the mists of time.
284
285 @quotation
286 @emph{Plea:} Additions to this section are particularly welcome. If you
287 or your friends (or enemies, to be evenhanded) have been unfairly
288 omitted from this list, we would like to add your names!
289 @end quotation
290
291 So that they may not regard their many labors as thankless, we
292 particularly thank those who shepherded @value{GDBN} through major
293 releases:
294 Jim Blandy (release 4.18);
295 Jason Molenda (release 4.17);
296 Stan Shebs (release 4.14);
297 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
298 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
299 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
300 Jim Kingdon (releases 3.5, 3.4, and 3.3);
301 and Randy Smith (releases 3.2, 3.1, and 3.0).
302
303 Richard Stallman, assisted at various times by Peter TerMaat, Chris
304 Hanson, and Richard Mlynarik, handled releases through 2.8.
305
306 Michael Tiemann is the author of most of the @sc{gnu} C++ support in
307 @value{GDBN}, with significant additional contributions from Per
308 Bothner. James Clark wrote the @sc{gnu} C++ demangler. Early work on
309 C++ was by Peter TerMaat (who also did much general update work leading
310 to release 3.0).
311
312 @value{GDBN} 4 uses the BFD subroutine library to examine multiple
313 object-file formats; BFD was a joint project of David V.
314 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
315
316 David Johnson wrote the original COFF support; Pace Willison did
317 the original support for encapsulated COFF.
318
319 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
320
321 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
322 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
323 support.
324 Jean-Daniel Fekete contributed Sun 386i support.
325 Chris Hanson improved the HP9000 support.
326 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
327 David Johnson contributed Encore Umax support.
328 Jyrki Kuoppala contributed Altos 3068 support.
329 Jeff Law contributed HP PA and SOM support.
330 Keith Packard contributed NS32K support.
331 Doug Rabson contributed Acorn Risc Machine support.
332 Bob Rusk contributed Harris Nighthawk CX-UX support.
333 Chris Smith contributed Convex support (and Fortran debugging).
334 Jonathan Stone contributed Pyramid support.
335 Michael Tiemann contributed SPARC support.
336 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
337 Pace Willison contributed Intel 386 support.
338 Jay Vosburgh contributed Symmetry support.
339
340 Andreas Schwab contributed M68K Linux support.
341
342 Rich Schaefer and Peter Schauer helped with support of SunOS shared
343 libraries.
344
345 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
346 about several machine instruction sets.
347
348 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
349 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
350 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
351 and RDI targets, respectively.
352
353 Brian Fox is the author of the readline libraries providing
354 command-line editing and command history.
355
356 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
357 Modula-2 support, and contributed the Languages chapter of this manual.
358
359 Fred Fish wrote most of the support for Unix System Vr4.
360 He also enhanced the command-completion support to cover C++ overloaded
361 symbols.
362
363 Hitachi America, Ltd. sponsored the support for H8/300, H8/500, and
364 Super-H processors.
365
366 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
367
368 Mitsubishi sponsored the support for D10V, D30V, and M32R/D processors.
369
370 Toshiba sponsored the support for the TX39 Mips processor.
371
372 Matsushita sponsored the support for the MN10200 and MN10300 processors.
373
374 Fujitsu sponsored the support for SPARClite and FR30 processors.
375
376 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
377 watchpoints.
378
379 Michael Snyder added support for tracepoints.
380
381 Stu Grossman wrote gdbserver.
382
383 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
384 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
385
386 The following people at the Hewlett-Packard Company contributed
387 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
388 (narrow mode), HP's implementation of kernel threads, HP's aC++
389 compiler, and the terminal user interface: Ben Krepp, Richard Title,
390 John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
391 Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
392 information in this manual.
393
394 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
395 development since 1991. Cygnus engineers who have worked on @value{GDBN}
396 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
397 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
398 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
399 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
400 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
401 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
402 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
403 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
404 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
405 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
406 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
407 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
408 Zuhn have made contributions both large and small.
409
410
411 @node Sample Session
412 @chapter A Sample @value{GDBN} Session
413
414 You can use this manual at your leisure to read all about @value{GDBN}.
415 However, a handful of commands are enough to get started using the
416 debugger. This chapter illustrates those commands.
417
418 @iftex
419 In this sample session, we emphasize user input like this: @b{input},
420 to make it easier to pick out from the surrounding output.
421 @end iftex
422
423 @c FIXME: this example may not be appropriate for some configs, where
424 @c FIXME...primary interest is in remote use.
425
426 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
427 processor) exhibits the following bug: sometimes, when we change its
428 quote strings from the default, the commands used to capture one macro
429 definition within another stop working. In the following short @code{m4}
430 session, we define a macro @code{foo} which expands to @code{0000}; we
431 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
432 same thing. However, when we change the open quote string to
433 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
434 procedure fails to define a new synonym @code{baz}:
435
436 @smallexample
437 $ @b{cd gnu/m4}
438 $ @b{./m4}
439 @b{define(foo,0000)}
440
441 @b{foo}
442 0000
443 @b{define(bar,defn(`foo'))}
444
445 @b{bar}
446 0000
447 @b{changequote(<QUOTE>,<UNQUOTE>)}
448
449 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
450 @b{baz}
451 @b{C-d}
452 m4: End of input: 0: fatal error: EOF in string
453 @end smallexample
454
455 @noindent
456 Let us use @value{GDBN} to try to see what is going on.
457
458 @smallexample
459 $ @b{@value{GDBP} m4}
460 @c FIXME: this falsifies the exact text played out, to permit smallbook
461 @c FIXME... format to come out better.
462 @value{GDBN} is free software and you are welcome to distribute copies
463 of it under certain conditions; type "show copying" to see
464 the conditions.
465 There is absolutely no warranty for @value{GDBN}; type "show warranty"
466 for details.
467
468 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
469 (@value{GDBP})
470 @end smallexample
471
472 @noindent
473 @value{GDBN} reads only enough symbol data to know where to find the
474 rest when needed; as a result, the first prompt comes up very quickly.
475 We now tell @value{GDBN} to use a narrower display width than usual, so
476 that examples fit in this manual.
477
478 @smallexample
479 (@value{GDBP}) @b{set width 70}
480 @end smallexample
481
482 @noindent
483 We need to see how the @code{m4} built-in @code{changequote} works.
484 Having looked at the source, we know the relevant subroutine is
485 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
486 @code{break} command.
487
488 @smallexample
489 (@value{GDBP}) @b{break m4_changequote}
490 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
491 @end smallexample
492
493 @noindent
494 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
495 control; as long as control does not reach the @code{m4_changequote}
496 subroutine, the program runs as usual:
497
498 @smallexample
499 (@value{GDBP}) @b{run}
500 Starting program: /work/Editorial/gdb/gnu/m4/m4
501 @b{define(foo,0000)}
502
503 @b{foo}
504 0000
505 @end smallexample
506
507 @noindent
508 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
509 suspends execution of @code{m4}, displaying information about the
510 context where it stops.
511
512 @smallexample
513 @b{changequote(<QUOTE>,<UNQUOTE>)}
514
515 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
516 at builtin.c:879
517 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
518 @end smallexample
519
520 @noindent
521 Now we use the command @code{n} (@code{next}) to advance execution to
522 the next line of the current function.
523
524 @smallexample
525 (@value{GDBP}) @b{n}
526 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
527 : nil,
528 @end smallexample
529
530 @noindent
531 @code{set_quotes} looks like a promising subroutine. We can go into it
532 by using the command @code{s} (@code{step}) instead of @code{next}.
533 @code{step} goes to the next line to be executed in @emph{any}
534 subroutine, so it steps into @code{set_quotes}.
535
536 @smallexample
537 (@value{GDBP}) @b{s}
538 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
539 at input.c:530
540 530 if (lquote != def_lquote)
541 @end smallexample
542
543 @noindent
544 The display that shows the subroutine where @code{m4} is now
545 suspended (and its arguments) is called a stack frame display. It
546 shows a summary of the stack. We can use the @code{backtrace}
547 command (which can also be spelled @code{bt}), to see where we are
548 in the stack as a whole: the @code{backtrace} command displays a
549 stack frame for each active subroutine.
550
551 @smallexample
552 (@value{GDBP}) @b{bt}
553 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
554 at input.c:530
555 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
556 at builtin.c:882
557 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
558 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
559 at macro.c:71
560 #4 0x79dc in expand_input () at macro.c:40
561 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
562 @end smallexample
563
564 @noindent
565 We step through a few more lines to see what happens. The first two
566 times, we can use @samp{s}; the next two times we use @code{n} to avoid
567 falling into the @code{xstrdup} subroutine.
568
569 @smallexample
570 (@value{GDBP}) @b{s}
571 0x3b5c 532 if (rquote != def_rquote)
572 (@value{GDBP}) @b{s}
573 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
574 def_lquote : xstrdup(lq);
575 (@value{GDBP}) @b{n}
576 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
577 : xstrdup(rq);
578 (@value{GDBP}) @b{n}
579 538 len_lquote = strlen(rquote);
580 @end smallexample
581
582 @noindent
583 The last line displayed looks a little odd; we can examine the variables
584 @code{lquote} and @code{rquote} to see if they are in fact the new left
585 and right quotes we specified. We use the command @code{p}
586 (@code{print}) to see their values.
587
588 @smallexample
589 (@value{GDBP}) @b{p lquote}
590 $1 = 0x35d40 "<QUOTE>"
591 (@value{GDBP}) @b{p rquote}
592 $2 = 0x35d50 "<UNQUOTE>"
593 @end smallexample
594
595 @noindent
596 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
597 To look at some context, we can display ten lines of source
598 surrounding the current line with the @code{l} (@code{list}) command.
599
600 @smallexample
601 (@value{GDBP}) @b{l}
602 533 xfree(rquote);
603 534
604 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
605 : xstrdup (lq);
606 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
607 : xstrdup (rq);
608 537
609 538 len_lquote = strlen(rquote);
610 539 len_rquote = strlen(lquote);
611 540 @}
612 541
613 542 void
614 @end smallexample
615
616 @noindent
617 Let us step past the two lines that set @code{len_lquote} and
618 @code{len_rquote}, and then examine the values of those variables.
619
620 @smallexample
621 (@value{GDBP}) @b{n}
622 539 len_rquote = strlen(lquote);
623 (@value{GDBP}) @b{n}
624 540 @}
625 (@value{GDBP}) @b{p len_lquote}
626 $3 = 9
627 (@value{GDBP}) @b{p len_rquote}
628 $4 = 7
629 @end smallexample
630
631 @noindent
632 That certainly looks wrong, assuming @code{len_lquote} and
633 @code{len_rquote} are meant to be the lengths of @code{lquote} and
634 @code{rquote} respectively. We can set them to better values using
635 the @code{p} command, since it can print the value of
636 any expression---and that expression can include subroutine calls and
637 assignments.
638
639 @smallexample
640 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
641 $5 = 7
642 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
643 $6 = 9
644 @end smallexample
645
646 @noindent
647 Is that enough to fix the problem of using the new quotes with the
648 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
649 executing with the @code{c} (@code{continue}) command, and then try the
650 example that caused trouble initially:
651
652 @smallexample
653 (@value{GDBP}) @b{c}
654 Continuing.
655
656 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
657
658 baz
659 0000
660 @end smallexample
661
662 @noindent
663 Success! The new quotes now work just as well as the default ones. The
664 problem seems to have been just the two typos defining the wrong
665 lengths. We allow @code{m4} exit by giving it an EOF as input:
666
667 @smallexample
668 @b{C-d}
669 Program exited normally.
670 @end smallexample
671
672 @noindent
673 The message @samp{Program exited normally.} is from @value{GDBN}; it
674 indicates @code{m4} has finished executing. We can end our @value{GDBN}
675 session with the @value{GDBN} @code{quit} command.
676
677 @smallexample
678 (@value{GDBP}) @b{quit}
679 @end smallexample
680
681 @node Invocation
682 @chapter Getting In and Out of @value{GDBN}
683
684 This chapter discusses how to start @value{GDBN}, and how to get out of it.
685 The essentials are:
686 @itemize @bullet
687 @item
688 type @samp{@value{GDBP}} to start @value{GDBN}.
689 @item
690 type @kbd{quit} or @kbd{C-d} to exit.
691 @end itemize
692
693 @menu
694 * Invoking GDB:: How to start @value{GDBN}
695 * Quitting GDB:: How to quit @value{GDBN}
696 * Shell Commands:: How to use shell commands inside @value{GDBN}
697 @end menu
698
699 @node Invoking GDB
700 @section Invoking @value{GDBN}
701
702 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
703 @value{GDBN} reads commands from the terminal until you tell it to exit.
704
705 You can also run @code{@value{GDBP}} with a variety of arguments and options,
706 to specify more of your debugging environment at the outset.
707
708 The command-line options described here are designed
709 to cover a variety of situations; in some environments, some of these
710 options may effectively be unavailable.
711
712 The most usual way to start @value{GDBN} is with one argument,
713 specifying an executable program:
714
715 @example
716 @value{GDBP} @var{program}
717 @end example
718
719 @noindent
720 You can also start with both an executable program and a core file
721 specified:
722
723 @example
724 @value{GDBP} @var{program} @var{core}
725 @end example
726
727 You can, instead, specify a process ID as a second argument, if you want
728 to debug a running process:
729
730 @example
731 @value{GDBP} @var{program} 1234
732 @end example
733
734 @noindent
735 would attach @value{GDBN} to process @code{1234} (unless you also have a file
736 named @file{1234}; @value{GDBN} does check for a core file first).
737
738 Taking advantage of the second command-line argument requires a fairly
739 complete operating system; when you use @value{GDBN} as a remote
740 debugger attached to a bare board, there may not be any notion of
741 ``process'', and there is often no way to get a core dump. @value{GDBN}
742 will warn you if it is unable to attach or to read core dumps.
743
744 You can run @code{@value{GDBP}} without printing the front material, which describes
745 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
746
747 @smallexample
748 @value{GDBP} -silent
749 @end smallexample
750
751 @noindent
752 You can further control how @value{GDBN} starts up by using command-line
753 options. @value{GDBN} itself can remind you of the options available.
754
755 @noindent
756 Type
757
758 @example
759 @value{GDBP} -help
760 @end example
761
762 @noindent
763 to display all available options and briefly describe their use
764 (@samp{@value{GDBP} -h} is a shorter equivalent).
765
766 All options and command line arguments you give are processed
767 in sequential order. The order makes a difference when the
768 @samp{-x} option is used.
769
770
771 @menu
772 * File Options:: Choosing files
773 * Mode Options:: Choosing modes
774 @end menu
775
776 @node File Options
777 @subsection Choosing files
778
779 When @value{GDBN} starts, it reads any arguments other than options as
780 specifying an executable file and core file (or process ID). This is
781 the same as if the arguments were specified by the @samp{-se} and
782 @samp{-c} options respectively. (@value{GDBN} reads the first argument
783 that does not have an associated option flag as equivalent to the
784 @samp{-se} option followed by that argument; and the second argument
785 that does not have an associated option flag, if any, as equivalent to
786 the @samp{-c} option followed by that argument.)
787
788 If @value{GDBN} has not been configured to included core file support,
789 such as for most embedded targets, then it will complain about a second
790 argument and ignore it.
791
792 Many options have both long and short forms; both are shown in the
793 following list. @value{GDBN} also recognizes the long forms if you truncate
794 them, so long as enough of the option is present to be unambiguous.
795 (If you prefer, you can flag option arguments with @samp{--} rather
796 than @samp{-}, though we illustrate the more usual convention.)
797
798 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
799 @c way, both those who look for -foo and --foo in the index, will find
800 @c it.
801
802 @table @code
803 @item -symbols @var{file}
804 @itemx -s @var{file}
805 @cindex @code{--symbols}
806 @cindex @code{-s}
807 Read symbol table from file @var{file}.
808
809 @item -exec @var{file}
810 @itemx -e @var{file}
811 @cindex @code{--exec}
812 @cindex @code{-e}
813 Use file @var{file} as the executable file to execute when appropriate,
814 and for examining pure data in conjunction with a core dump.
815
816 @item -se @var{file}
817 @cindex @code{--se}
818 Read symbol table from file @var{file} and use it as the executable
819 file.
820
821 @item -core @var{file}
822 @itemx -c @var{file}
823 @cindex @code{--core}
824 @cindex @code{-c}
825 Use file @var{file} as a core dump to examine.
826
827 @item -c @var{number}
828 Connect to process ID @var{number}, as with the @code{attach} command
829 (unless there is a file in core-dump format named @var{number}, in which
830 case @samp{-c} specifies that file as a core dump to read).
831
832 @item -command @var{file}
833 @itemx -x @var{file}
834 @cindex @code{--command}
835 @cindex @code{-x}
836 Execute @value{GDBN} commands from file @var{file}. @xref{Command
837 Files,, Command files}.
838
839 @item -directory @var{directory}
840 @itemx -d @var{directory}
841 @cindex @code{--directory}
842 @cindex @code{-d}
843 Add @var{directory} to the path to search for source files.
844
845 @item -m
846 @itemx -mapped
847 @cindex @code{--mapped}
848 @cindex @code{-m}
849 @emph{Warning: this option depends on operating system facilities that are not
850 supported on all systems.}@*
851 If memory-mapped files are available on your system through the @code{mmap}
852 system call, you can use this option
853 to have @value{GDBN} write the symbols from your
854 program into a reusable file in the current directory. If the program you are debugging is
855 called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
856 Future @value{GDBN} debugging sessions notice the presence of this file,
857 and can quickly map in symbol information from it, rather than reading
858 the symbol table from the executable program.
859
860 The @file{.syms} file is specific to the host machine where @value{GDBN}
861 is run. It holds an exact image of the internal @value{GDBN} symbol
862 table. It cannot be shared across multiple host platforms.
863
864 @item -r
865 @itemx -readnow
866 @cindex @code{--readnow}
867 @cindex @code{-r}
868 Read each symbol file's entire symbol table immediately, rather than
869 the default, which is to read it incrementally as it is needed.
870 This makes startup slower, but makes future operations faster.
871
872 @end table
873
874 You typically combine the @code{-mapped} and @code{-readnow} options in
875 order to build a @file{.syms} file that contains complete symbol
876 information. (@xref{Files,,Commands to specify files}, for information
877 on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
878 but build a @file{.syms} file for future use is:
879
880 @example
881 gdb -batch -nx -mapped -readnow programname
882 @end example
883
884 @node Mode Options
885 @subsection Choosing modes
886
887 You can run @value{GDBN} in various alternative modes---for example, in
888 batch mode or quiet mode.
889
890 @table @code
891 @item -nx
892 @itemx -n
893 @cindex @code{--nx}
894 @cindex @code{-n}
895 Do not execute commands found in any initialization files (normally
896 called @file{.gdbinit}, or @file{gdb.ini} on PCs). Normally,
897 @value{GDBN} executes the commands in these files after all the command
898 options and arguments have been processed. @xref{Command Files,,Command
899 files}.
900
901 @item -quiet
902 @itemx -silent
903 @itemx -q
904 @cindex @code{--quiet}
905 @cindex @code{--silent}
906 @cindex @code{-q}
907 ``Quiet''. Do not print the introductory and copyright messages. These
908 messages are also suppressed in batch mode.
909
910 @item -batch
911 @cindex @code{--batch}
912 Run in batch mode. Exit with status @code{0} after processing all the
913 command files specified with @samp{-x} (and all commands from
914 initialization files, if not inhibited with @samp{-n}). Exit with
915 nonzero status if an error occurs in executing the @value{GDBN} commands
916 in the command files.
917
918 Batch mode may be useful for running @value{GDBN} as a filter, for
919 example to download and run a program on another computer; in order to
920 make this more useful, the message
921
922 @example
923 Program exited normally.
924 @end example
925
926 @noindent
927 (which is ordinarily issued whenever a program running under
928 @value{GDBN} control terminates) is not issued when running in batch
929 mode.
930
931 @item -nowindows
932 @itemx -nw
933 @cindex @code{--nowindows}
934 @cindex @code{-nw}
935 ``No windows''. If @value{GDBN} comes with a graphical user interface
936 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
937 interface. If no GUI is available, this option has no effect.
938
939 @item -windows
940 @itemx -w
941 @cindex @code{--windows}
942 @cindex @code{-w}
943 If @value{GDBN} includes a GUI, then this option requires it to be
944 used if possible.
945
946 @item -cd @var{directory}
947 @cindex @code{--cd}
948 Run @value{GDBN} using @var{directory} as its working directory,
949 instead of the current directory.
950
951 @item -fullname
952 @itemx -f
953 @cindex @code{--fullname}
954 @cindex @code{-f}
955 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
956 subprocess. It tells @value{GDBN} to output the full file name and line
957 number in a standard, recognizable fashion each time a stack frame is
958 displayed (which includes each time your program stops). This
959 recognizable format looks like two @samp{\032} characters, followed by
960 the file name, line number and character position separated by colons,
961 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
962 @samp{\032} characters as a signal to display the source code for the
963 frame.
964
965 @item -epoch
966 @cindex @code{--epoch}
967 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
968 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
969 routines so as to allow Epoch to display values of expressions in a
970 separate window.
971
972 @item -annotate @var{level}
973 @cindex @code{--annotate}
974 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
975 effect is identical to using @samp{set annotate @var{level}}
976 (@pxref{Annotations}).
977 Annotation level controls how much information does @value{GDBN} print
978 together with its prompt, values of expressions, source lines, and other
979 types of output. Level 0 is the normal, level 1 is for use when
980 @value{GDBN} is run as a subprocess of @sc{gnu} Emacs, level 2 is the
981 maximum annotation suitable for programs that control @value{GDBN}.
982
983 @item -async
984 @cindex @code{--async}
985 Use the asynchronous event loop for the command-line interface.
986 @value{GDBN} processes all events, such as user keyboard input, via a
987 special event loop. This allows @value{GDBN} to accept and process user
988 commands in parallel with the debugged process being
989 run@footnote{@value{GDBN} built with @sc{djgpp} tools for
990 MS-DOS/MS-Windows supports this mode of operation, but the event loop is
991 suspended when the debuggee runs.}, so you don't need to wait for
992 control to return to @value{GDBN} before you type the next command.
993 (@emph{Note:} as of version 5.0, the target side of the asynchronous
994 operation is not yet in place, so @samp{-async} does not work fully
995 yet.)
996 @c FIXME: when the target side of the event loop is done, the above NOTE
997 @c should be removed.
998
999 When the standard input is connected to a terminal device, @value{GDBN}
1000 uses the asynchronous event loop by default, unless disabled by the
1001 @samp{-noasync} option.
1002
1003 @item -noasync
1004 @cindex @code{--noasync}
1005 Disable the asynchronous event loop for the command-line interface.
1006
1007 @item -baud @var{bps}
1008 @itemx -b @var{bps}
1009 @cindex @code{--baud}
1010 @cindex @code{-b}
1011 Set the line speed (baud rate or bits per second) of any serial
1012 interface used by @value{GDBN} for remote debugging.
1013
1014 @item -tty @var{device}
1015 @itemx -t @var{device}
1016 @cindex @code{--tty}
1017 @cindex @code{-t}
1018 Run using @var{device} for your program's standard input and output.
1019 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1020
1021 @c resolve the situation of these eventually
1022 @c @item -tui
1023 @c @cindex @code{--tui}
1024 @c Use a Terminal User Interface. For information, use your Web browser to
1025 @c read the file @file{TUI.html}, which is usually installed in the
1026 @c directory @code{/opt/langtools/wdb/doc} on HP-UX systems. Do not use
1027 @c this option if you run @value{GDBN} from Emacs (see @pxref{Emacs, ,Using
1028 @c @value{GDBN} under @sc{gnu} Emacs}).
1029
1030 @c @item -xdb
1031 @c @cindex @code{--xdb}
1032 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1033 @c For information, see the file @file{xdb_trans.html}, which is usually
1034 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1035 @c systems.
1036
1037 @item -interpreter @var{interp}
1038 @cindex @code{--interpreter}
1039 Use the interpreter @var{interp} for interface with the controlling
1040 program or device. This option is meant to be set by programs which
1041 communicate with @value{GDBN} using it as a back end. For example,
1042 @samp{--interpreter=mi} causes @value{GDBN} to use the @dfn{gdbmi
1043 interface}.
1044 @c FIXME: There should be an @xref here to the GDB/MI docs, but
1045 @c gdbmi.texi doesn't have a single node to reference!
1046
1047 @item -write
1048 @cindex @code{--write}
1049 Open the executable and core files for both reading and writing. This
1050 is equivalent to the @samp{set write on} command inside @value{GDBN}
1051 (@pxref{Patching}).
1052
1053 @item -statistics
1054 @cindex @code{--statistics}
1055 This option causes @value{GDBN} to print statistics about time and
1056 memory usage after it completes each command and returns to the prompt.
1057
1058 @item -version
1059 @cindex @code{--version}
1060 This option causes @value{GDBN} to print its version number and
1061 no-warranty blurb, and exit.
1062
1063 @end table
1064
1065 @node Quitting GDB
1066 @section Quitting @value{GDBN}
1067 @cindex exiting @value{GDBN}
1068 @cindex leaving @value{GDBN}
1069
1070 @table @code
1071 @kindex quit @r{[}@var{expression}@r{]}
1072 @kindex q
1073 @item quit @r{[}@var{expression}@r{]}
1074 @itemx q
1075 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1076 @code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1077 do not supply @var{expression}, @value{GDBN} will terminate normally;
1078 otherwise it will terminate using the result of @var{expression} as the
1079 error code.
1080 @end table
1081
1082 @cindex interrupt
1083 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1084 terminates the action of any @value{GDBN} command that is in progress and
1085 returns to @value{GDBN} command level. It is safe to type the interrupt
1086 character at any time because @value{GDBN} does not allow it to take effect
1087 until a time when it is safe.
1088
1089 If you have been using @value{GDBN} to control an attached process or
1090 device, you can release it with the @code{detach} command
1091 (@pxref{Attach, ,Debugging an already-running process}).
1092
1093 @node Shell Commands
1094 @section Shell commands
1095
1096 If you need to execute occasional shell commands during your
1097 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1098 just use the @code{shell} command.
1099
1100 @table @code
1101 @kindex shell
1102 @cindex shell escape
1103 @item shell @var{command string}
1104 Invoke a standard shell to execute @var{command string}.
1105 If it exists, the environment variable @code{SHELL} determines which
1106 shell to run. Otherwise @value{GDBN} uses the default shell
1107 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1108 @end table
1109
1110 The utility @code{make} is often needed in development environments.
1111 You do not have to use the @code{shell} command for this purpose in
1112 @value{GDBN}:
1113
1114 @table @code
1115 @kindex make
1116 @cindex calling make
1117 @item make @var{make-args}
1118 Execute the @code{make} program with the specified
1119 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1120 @end table
1121
1122 @node Commands
1123 @chapter @value{GDBN} Commands
1124
1125 You can abbreviate a @value{GDBN} command to the first few letters of the command
1126 name, if that abbreviation is unambiguous; and you can repeat certain
1127 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1128 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1129 show you the alternatives available, if there is more than one possibility).
1130
1131 @menu
1132 * Command Syntax:: How to give commands to @value{GDBN}
1133 * Completion:: Command completion
1134 * Help:: How to ask @value{GDBN} for help
1135 @end menu
1136
1137 @node Command Syntax
1138 @section Command syntax
1139
1140 A @value{GDBN} command is a single line of input. There is no limit on
1141 how long it can be. It starts with a command name, which is followed by
1142 arguments whose meaning depends on the command name. For example, the
1143 command @code{step} accepts an argument which is the number of times to
1144 step, as in @samp{step 5}. You can also use the @code{step} command
1145 with no arguments. Some commands do not allow any arguments.
1146
1147 @cindex abbreviation
1148 @value{GDBN} command names may always be truncated if that abbreviation is
1149 unambiguous. Other possible command abbreviations are listed in the
1150 documentation for individual commands. In some cases, even ambiguous
1151 abbreviations are allowed; for example, @code{s} is specially defined as
1152 equivalent to @code{step} even though there are other commands whose
1153 names start with @code{s}. You can test abbreviations by using them as
1154 arguments to the @code{help} command.
1155
1156 @cindex repeating commands
1157 @kindex RET
1158 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1159 repeat the previous command. Certain commands (for example, @code{run})
1160 will not repeat this way; these are commands whose unintentional
1161 repetition might cause trouble and which you are unlikely to want to
1162 repeat.
1163
1164 The @code{list} and @code{x} commands, when you repeat them with
1165 @key{RET}, construct new arguments rather than repeating
1166 exactly as typed. This permits easy scanning of source or memory.
1167
1168 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1169 output, in a way similar to the common utility @code{more}
1170 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
1171 @key{RET} too many in this situation, @value{GDBN} disables command
1172 repetition after any command that generates this sort of display.
1173
1174 @kindex #
1175 @cindex comment
1176 Any text from a @kbd{#} to the end of the line is a comment; it does
1177 nothing. This is useful mainly in command files (@pxref{Command
1178 Files,,Command files}).
1179
1180 @node Completion
1181 @section Command completion
1182
1183 @cindex completion
1184 @cindex word completion
1185 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1186 only one possibility; it can also show you what the valid possibilities
1187 are for the next word in a command, at any time. This works for @value{GDBN}
1188 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1189
1190 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1191 of a word. If there is only one possibility, @value{GDBN} fills in the
1192 word, and waits for you to finish the command (or press @key{RET} to
1193 enter it). For example, if you type
1194
1195 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1196 @c complete accuracy in these examples; space introduced for clarity.
1197 @c If texinfo enhancements make it unnecessary, it would be nice to
1198 @c replace " @key" by "@key" in the following...
1199 @example
1200 (@value{GDBP}) info bre @key{TAB}
1201 @end example
1202
1203 @noindent
1204 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1205 the only @code{info} subcommand beginning with @samp{bre}:
1206
1207 @example
1208 (@value{GDBP}) info breakpoints
1209 @end example
1210
1211 @noindent
1212 You can either press @key{RET} at this point, to run the @code{info
1213 breakpoints} command, or backspace and enter something else, if
1214 @samp{breakpoints} does not look like the command you expected. (If you
1215 were sure you wanted @code{info breakpoints} in the first place, you
1216 might as well just type @key{RET} immediately after @samp{info bre},
1217 to exploit command abbreviations rather than command completion).
1218
1219 If there is more than one possibility for the next word when you press
1220 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1221 characters and try again, or just press @key{TAB} a second time;
1222 @value{GDBN} displays all the possible completions for that word. For
1223 example, you might want to set a breakpoint on a subroutine whose name
1224 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1225 just sounds the bell. Typing @key{TAB} again displays all the
1226 function names in your program that begin with those characters, for
1227 example:
1228
1229 @example
1230 (@value{GDBP}) b make_ @key{TAB}
1231 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1232 make_a_section_from_file make_environ
1233 make_abs_section make_function_type
1234 make_blockvector make_pointer_type
1235 make_cleanup make_reference_type
1236 make_command make_symbol_completion_list
1237 (@value{GDBP}) b make_
1238 @end example
1239
1240 @noindent
1241 After displaying the available possibilities, @value{GDBN} copies your
1242 partial input (@samp{b make_} in the example) so you can finish the
1243 command.
1244
1245 If you just want to see the list of alternatives in the first place, you
1246 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1247 means @kbd{@key{META} ?}. You can type this either by holding down a
1248 key designated as the @key{META} shift on your keyboard (if there is
1249 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1250
1251 @cindex quotes in commands
1252 @cindex completion of quoted strings
1253 Sometimes the string you need, while logically a ``word'', may contain
1254 parentheses or other characters that @value{GDBN} normally excludes from
1255 its notion of a word. To permit word completion to work in this
1256 situation, you may enclose words in @code{'} (single quote marks) in
1257 @value{GDBN} commands.
1258
1259 The most likely situation where you might need this is in typing the
1260 name of a C++ function. This is because C++ allows function overloading
1261 (multiple definitions of the same function, distinguished by argument
1262 type). For example, when you want to set a breakpoint you may need to
1263 distinguish whether you mean the version of @code{name} that takes an
1264 @code{int} parameter, @code{name(int)}, or the version that takes a
1265 @code{float} parameter, @code{name(float)}. To use the word-completion
1266 facilities in this situation, type a single quote @code{'} at the
1267 beginning of the function name. This alerts @value{GDBN} that it may need to
1268 consider more information than usual when you press @key{TAB} or
1269 @kbd{M-?} to request word completion:
1270
1271 @example
1272 (@value{GDBP}) b 'bubble( @kbd{M-?}
1273 bubble(double,double) bubble(int,int)
1274 (@value{GDBP}) b 'bubble(
1275 @end example
1276
1277 In some cases, @value{GDBN} can tell that completing a name requires using
1278 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1279 completing as much as it can) if you do not type the quote in the first
1280 place:
1281
1282 @example
1283 (@value{GDBP}) b bub @key{TAB}
1284 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1285 (@value{GDBP}) b 'bubble(
1286 @end example
1287
1288 @noindent
1289 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1290 you have not yet started typing the argument list when you ask for
1291 completion on an overloaded symbol.
1292
1293 For more information about overloaded functions, see @ref{C plus plus
1294 expressions, ,C++ expressions}. You can use the command @code{set
1295 overload-resolution off} to disable overload resolution;
1296 see @ref{Debugging C plus plus, ,@value{GDBN} features for C++}.
1297
1298
1299 @node Help
1300 @section Getting help
1301 @cindex online documentation
1302 @kindex help
1303
1304 You can always ask @value{GDBN} itself for information on its commands,
1305 using the command @code{help}.
1306
1307 @table @code
1308 @kindex h
1309 @item help
1310 @itemx h
1311 You can use @code{help} (abbreviated @code{h}) with no arguments to
1312 display a short list of named classes of commands:
1313
1314 @smallexample
1315 (@value{GDBP}) help
1316 List of classes of commands:
1317
1318 aliases -- Aliases of other commands
1319 breakpoints -- Making program stop at certain points
1320 data -- Examining data
1321 files -- Specifying and examining files
1322 internals -- Maintenance commands
1323 obscure -- Obscure features
1324 running -- Running the program
1325 stack -- Examining the stack
1326 status -- Status inquiries
1327 support -- Support facilities
1328 tracepoints -- Tracing of program execution without@*
1329 stopping the program
1330 user-defined -- User-defined commands
1331
1332 Type "help" followed by a class name for a list of
1333 commands in that class.
1334 Type "help" followed by command name for full
1335 documentation.
1336 Command name abbreviations are allowed if unambiguous.
1337 (@value{GDBP})
1338 @end smallexample
1339 @c the above line break eliminates huge line overfull...
1340
1341 @item help @var{class}
1342 Using one of the general help classes as an argument, you can get a
1343 list of the individual commands in that class. For example, here is the
1344 help display for the class @code{status}:
1345
1346 @smallexample
1347 (@value{GDBP}) help status
1348 Status inquiries.
1349
1350 List of commands:
1351
1352 @c Line break in "show" line falsifies real output, but needed
1353 @c to fit in smallbook page size.
1354 info -- Generic command for showing things
1355 about the program being debugged
1356 show -- Generic command for showing things
1357 about the debugger
1358
1359 Type "help" followed by command name for full
1360 documentation.
1361 Command name abbreviations are allowed if unambiguous.
1362 (@value{GDBP})
1363 @end smallexample
1364
1365 @item help @var{command}
1366 With a command name as @code{help} argument, @value{GDBN} displays a
1367 short paragraph on how to use that command.
1368
1369 @kindex apropos
1370 @item apropos @var{args}
1371 The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1372 commands, and their documentation, for the regular expression specified in
1373 @var{args}. It prints out all matches found. For example:
1374
1375 @smallexample
1376 apropos reload
1377 @end smallexample
1378
1379 @noindent results in:
1380
1381 @smallexample
1382 @c @group
1383 set symbol-reloading -- Set dynamic symbol table reloading
1384 multiple times in one run
1385 show symbol-reloading -- Show dynamic symbol table reloading
1386 multiple times in one run
1387 @c @end group
1388 @end smallexample
1389
1390 @kindex complete
1391 @item complete @var{args}
1392 The @code{complete @var{args}} command lists all the possible completions
1393 for the beginning of a command. Use @var{args} to specify the beginning of the
1394 command you want completed. For example:
1395
1396 @smallexample
1397 complete i
1398 @end smallexample
1399
1400 @noindent results in:
1401
1402 @smallexample
1403 @group
1404 if
1405 ignore
1406 info
1407 inspect
1408 @end group
1409 @end smallexample
1410
1411 @noindent This is intended for use by @sc{gnu} Emacs.
1412 @end table
1413
1414 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1415 and @code{show} to inquire about the state of your program, or the state
1416 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1417 manual introduces each of them in the appropriate context. The listings
1418 under @code{info} and under @code{show} in the Index point to
1419 all the sub-commands. @xref{Index}.
1420
1421 @c @group
1422 @table @code
1423 @kindex info
1424 @kindex i
1425 @item info
1426 This command (abbreviated @code{i}) is for describing the state of your
1427 program. For example, you can list the arguments given to your program
1428 with @code{info args}, list the registers currently in use with @code{info
1429 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1430 You can get a complete list of the @code{info} sub-commands with
1431 @w{@code{help info}}.
1432
1433 @kindex set
1434 @item set
1435 You can assign the result of an expression to an environment variable with
1436 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1437 @code{set prompt $}.
1438
1439 @kindex show
1440 @item show
1441 In contrast to @code{info}, @code{show} is for describing the state of
1442 @value{GDBN} itself.
1443 You can change most of the things you can @code{show}, by using the
1444 related command @code{set}; for example, you can control what number
1445 system is used for displays with @code{set radix}, or simply inquire
1446 which is currently in use with @code{show radix}.
1447
1448 @kindex info set
1449 To display all the settable parameters and their current
1450 values, you can use @code{show} with no arguments; you may also use
1451 @code{info set}. Both commands produce the same display.
1452 @c FIXME: "info set" violates the rule that "info" is for state of
1453 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1454 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1455 @end table
1456 @c @end group
1457
1458 Here are three miscellaneous @code{show} subcommands, all of which are
1459 exceptional in lacking corresponding @code{set} commands:
1460
1461 @table @code
1462 @kindex show version
1463 @cindex version number
1464 @item show version
1465 Show what version of @value{GDBN} is running. You should include this
1466 information in @value{GDBN} bug-reports. If multiple versions of
1467 @value{GDBN} are in use at your site, you may need to determine which
1468 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1469 commands are introduced, and old ones may wither away. Also, many
1470 system vendors ship variant versions of @value{GDBN}, and there are
1471 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1472 The version number is the same as the one announced when you start
1473 @value{GDBN}.
1474
1475 @kindex show copying
1476 @item show copying
1477 Display information about permission for copying @value{GDBN}.
1478
1479 @kindex show warranty
1480 @item show warranty
1481 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1482 if your version of @value{GDBN} comes with one.
1483
1484 @end table
1485
1486 @node Running
1487 @chapter Running Programs Under @value{GDBN}
1488
1489 When you run a program under @value{GDBN}, you must first generate
1490 debugging information when you compile it.
1491
1492 You may start @value{GDBN} with its arguments, if any, in an environment
1493 of your choice. If you are doing native debugging, you may redirect
1494 your program's input and output, debug an already running process, or
1495 kill a child process.
1496
1497 @menu
1498 * Compilation:: Compiling for debugging
1499 * Starting:: Starting your program
1500 * Arguments:: Your program's arguments
1501 * Environment:: Your program's environment
1502
1503 * Working Directory:: Your program's working directory
1504 * Input/Output:: Your program's input and output
1505 * Attach:: Debugging an already-running process
1506 * Kill Process:: Killing the child process
1507
1508 * Threads:: Debugging programs with multiple threads
1509 * Processes:: Debugging programs with multiple processes
1510 @end menu
1511
1512 @node Compilation
1513 @section Compiling for debugging
1514
1515 In order to debug a program effectively, you need to generate
1516 debugging information when you compile it. This debugging information
1517 is stored in the object file; it describes the data type of each
1518 variable or function and the correspondence between source line numbers
1519 and addresses in the executable code.
1520
1521 To request debugging information, specify the @samp{-g} option when you run
1522 the compiler.
1523
1524 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1525 options together. Using those compilers, you cannot generate optimized
1526 executables containing debugging information.
1527
1528 @value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1529 without @samp{-O}, making it possible to debug optimized code. We
1530 recommend that you @emph{always} use @samp{-g} whenever you compile a
1531 program. You may think your program is correct, but there is no sense
1532 in pushing your luck.
1533
1534 @cindex optimized code, debugging
1535 @cindex debugging optimized code
1536 When you debug a program compiled with @samp{-g -O}, remember that the
1537 optimizer is rearranging your code; the debugger shows you what is
1538 really there. Do not be too surprised when the execution path does not
1539 exactly match your source file! An extreme example: if you define a
1540 variable, but never use it, @value{GDBN} never sees that
1541 variable---because the compiler optimizes it out of existence.
1542
1543 Some things do not work as well with @samp{-g -O} as with just
1544 @samp{-g}, particularly on machines with instruction scheduling. If in
1545 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1546 please report it to us as a bug (including a test case!).
1547
1548 Older versions of the @sc{gnu} C compiler permitted a variant option
1549 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1550 format; if your @sc{gnu} C compiler has this option, do not use it.
1551
1552 @need 2000
1553 @node Starting
1554 @section Starting your program
1555 @cindex starting
1556 @cindex running
1557
1558 @table @code
1559 @kindex run
1560 @item run
1561 @itemx r
1562 Use the @code{run} command to start your program under @value{GDBN}.
1563 You must first specify the program name (except on VxWorks) with an
1564 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1565 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1566 (@pxref{Files, ,Commands to specify files}).
1567
1568 @end table
1569
1570 If you are running your program in an execution environment that
1571 supports processes, @code{run} creates an inferior process and makes
1572 that process run your program. (In environments without processes,
1573 @code{run} jumps to the start of your program.)
1574
1575 The execution of a program is affected by certain information it
1576 receives from its superior. @value{GDBN} provides ways to specify this
1577 information, which you must do @emph{before} starting your program. (You
1578 can change it after starting your program, but such changes only affect
1579 your program the next time you start it.) This information may be
1580 divided into four categories:
1581
1582 @table @asis
1583 @item The @emph{arguments.}
1584 Specify the arguments to give your program as the arguments of the
1585 @code{run} command. If a shell is available on your target, the shell
1586 is used to pass the arguments, so that you may use normal conventions
1587 (such as wildcard expansion or variable substitution) in describing
1588 the arguments.
1589 In Unix systems, you can control which shell is used with the
1590 @code{SHELL} environment variable.
1591 @xref{Arguments, ,Your program's arguments}.
1592
1593 @item The @emph{environment.}
1594 Your program normally inherits its environment from @value{GDBN}, but you can
1595 use the @value{GDBN} commands @code{set environment} and @code{unset
1596 environment} to change parts of the environment that affect
1597 your program. @xref{Environment, ,Your program's environment}.
1598
1599 @item The @emph{working directory.}
1600 Your program inherits its working directory from @value{GDBN}. You can set
1601 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1602 @xref{Working Directory, ,Your program's working directory}.
1603
1604 @item The @emph{standard input and output.}
1605 Your program normally uses the same device for standard input and
1606 standard output as @value{GDBN} is using. You can redirect input and output
1607 in the @code{run} command line, or you can use the @code{tty} command to
1608 set a different device for your program.
1609 @xref{Input/Output, ,Your program's input and output}.
1610
1611 @cindex pipes
1612 @emph{Warning:} While input and output redirection work, you cannot use
1613 pipes to pass the output of the program you are debugging to another
1614 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1615 wrong program.
1616 @end table
1617
1618 When you issue the @code{run} command, your program begins to execute
1619 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1620 of how to arrange for your program to stop. Once your program has
1621 stopped, you may call functions in your program, using the @code{print}
1622 or @code{call} commands. @xref{Data, ,Examining Data}.
1623
1624 If the modification time of your symbol file has changed since the last
1625 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1626 table, and reads it again. When it does this, @value{GDBN} tries to retain
1627 your current breakpoints.
1628
1629 @node Arguments
1630 @section Your program's arguments
1631
1632 @cindex arguments (to your program)
1633 The arguments to your program can be specified by the arguments of the
1634 @code{run} command.
1635 They are passed to a shell, which expands wildcard characters and
1636 performs redirection of I/O, and thence to your program. Your
1637 @code{SHELL} environment variable (if it exists) specifies what shell
1638 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1639 the default shell (@file{/bin/sh} on Unix).
1640
1641 On non-Unix systems, the program is usually invoked directly by
1642 @value{GDBN}, which emulates I/O redirection via the appropriate system
1643 calls, and the wildcard characters are expanded by the startup code of
1644 the program, not by the shell.
1645
1646 @code{run} with no arguments uses the same arguments used by the previous
1647 @code{run}, or those set by the @code{set args} command.
1648
1649 @kindex set args
1650 @table @code
1651 @item set args
1652 Specify the arguments to be used the next time your program is run. If
1653 @code{set args} has no arguments, @code{run} executes your program
1654 with no arguments. Once you have run your program with arguments,
1655 using @code{set args} before the next @code{run} is the only way to run
1656 it again without arguments.
1657
1658 @kindex show args
1659 @item show args
1660 Show the arguments to give your program when it is started.
1661 @end table
1662
1663 @node Environment
1664 @section Your program's environment
1665
1666 @cindex environment (of your program)
1667 The @dfn{environment} consists of a set of environment variables and
1668 their values. Environment variables conventionally record such things as
1669 your user name, your home directory, your terminal type, and your search
1670 path for programs to run. Usually you set up environment variables with
1671 the shell and they are inherited by all the other programs you run. When
1672 debugging, it can be useful to try running your program with a modified
1673 environment without having to start @value{GDBN} over again.
1674
1675 @table @code
1676 @kindex path
1677 @item path @var{directory}
1678 Add @var{directory} to the front of the @code{PATH} environment variable
1679 (the search path for executables), for both @value{GDBN} and your program.
1680 You may specify several directory names, separated by whitespace or by a
1681 system-dependent separator character (@samp{:} on Unix, @samp{;} on
1682 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1683 is moved to the front, so it is searched sooner.
1684
1685 You can use the string @samp{$cwd} to refer to whatever is the current
1686 working directory at the time @value{GDBN} searches the path. If you
1687 use @samp{.} instead, it refers to the directory where you executed the
1688 @code{path} command. @value{GDBN} replaces @samp{.} in the
1689 @var{directory} argument (with the current path) before adding
1690 @var{directory} to the search path.
1691 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1692 @c document that, since repeating it would be a no-op.
1693
1694 @kindex show paths
1695 @item show paths
1696 Display the list of search paths for executables (the @code{PATH}
1697 environment variable).
1698
1699 @kindex show environment
1700 @item show environment @r{[}@var{varname}@r{]}
1701 Print the value of environment variable @var{varname} to be given to
1702 your program when it starts. If you do not supply @var{varname},
1703 print the names and values of all environment variables to be given to
1704 your program. You can abbreviate @code{environment} as @code{env}.
1705
1706 @kindex set environment
1707 @item set environment @var{varname} @r{[}=@var{value}@r{]}
1708 Set environment variable @var{varname} to @var{value}. The value
1709 changes for your program only, not for @value{GDBN} itself. @var{value} may
1710 be any string; the values of environment variables are just strings, and
1711 any interpretation is supplied by your program itself. The @var{value}
1712 parameter is optional; if it is eliminated, the variable is set to a
1713 null value.
1714 @c "any string" here does not include leading, trailing
1715 @c blanks. Gnu asks: does anyone care?
1716
1717 For example, this command:
1718
1719 @example
1720 set env USER = foo
1721 @end example
1722
1723 @noindent
1724 tells the debugged program, when subsequently run, that its user is named
1725 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1726 are not actually required.)
1727
1728 @kindex unset environment
1729 @item unset environment @var{varname}
1730 Remove variable @var{varname} from the environment to be passed to your
1731 program. This is different from @samp{set env @var{varname} =};
1732 @code{unset environment} removes the variable from the environment,
1733 rather than assigning it an empty value.
1734 @end table
1735
1736 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1737 the shell indicated
1738 by your @code{SHELL} environment variable if it exists (or
1739 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1740 that runs an initialization file---such as @file{.cshrc} for C-shell, or
1741 @file{.bashrc} for BASH---any variables you set in that file affect
1742 your program. You may wish to move setting of environment variables to
1743 files that are only run when you sign on, such as @file{.login} or
1744 @file{.profile}.
1745
1746 @node Working Directory
1747 @section Your program's working directory
1748
1749 @cindex working directory (of your program)
1750 Each time you start your program with @code{run}, it inherits its
1751 working directory from the current working directory of @value{GDBN}.
1752 The @value{GDBN} working directory is initially whatever it inherited
1753 from its parent process (typically the shell), but you can specify a new
1754 working directory in @value{GDBN} with the @code{cd} command.
1755
1756 The @value{GDBN} working directory also serves as a default for the commands
1757 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1758 specify files}.
1759
1760 @table @code
1761 @kindex cd
1762 @item cd @var{directory}
1763 Set the @value{GDBN} working directory to @var{directory}.
1764
1765 @kindex pwd
1766 @item pwd
1767 Print the @value{GDBN} working directory.
1768 @end table
1769
1770 @node Input/Output
1771 @section Your program's input and output
1772
1773 @cindex redirection
1774 @cindex i/o
1775 @cindex terminal
1776 By default, the program you run under @value{GDBN} does input and output to
1777 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
1778 to its own terminal modes to interact with you, but it records the terminal
1779 modes your program was using and switches back to them when you continue
1780 running your program.
1781
1782 @table @code
1783 @kindex info terminal
1784 @item info terminal
1785 Displays information recorded by @value{GDBN} about the terminal modes your
1786 program is using.
1787 @end table
1788
1789 You can redirect your program's input and/or output using shell
1790 redirection with the @code{run} command. For example,
1791
1792 @example
1793 run > outfile
1794 @end example
1795
1796 @noindent
1797 starts your program, diverting its output to the file @file{outfile}.
1798
1799 @kindex tty
1800 @cindex controlling terminal
1801 Another way to specify where your program should do input and output is
1802 with the @code{tty} command. This command accepts a file name as
1803 argument, and causes this file to be the default for future @code{run}
1804 commands. It also resets the controlling terminal for the child
1805 process, for future @code{run} commands. For example,
1806
1807 @example
1808 tty /dev/ttyb
1809 @end example
1810
1811 @noindent
1812 directs that processes started with subsequent @code{run} commands
1813 default to do input and output on the terminal @file{/dev/ttyb} and have
1814 that as their controlling terminal.
1815
1816 An explicit redirection in @code{run} overrides the @code{tty} command's
1817 effect on the input/output device, but not its effect on the controlling
1818 terminal.
1819
1820 When you use the @code{tty} command or redirect input in the @code{run}
1821 command, only the input @emph{for your program} is affected. The input
1822 for @value{GDBN} still comes from your terminal.
1823
1824 @node Attach
1825 @section Debugging an already-running process
1826 @kindex attach
1827 @cindex attach
1828
1829 @table @code
1830 @item attach @var{process-id}
1831 This command attaches to a running process---one that was started
1832 outside @value{GDBN}. (@code{info files} shows your active
1833 targets.) The command takes as argument a process ID. The usual way to
1834 find out the process-id of a Unix process is with the @code{ps} utility,
1835 or with the @samp{jobs -l} shell command.
1836
1837 @code{attach} does not repeat if you press @key{RET} a second time after
1838 executing the command.
1839 @end table
1840
1841 To use @code{attach}, your program must be running in an environment
1842 which supports processes; for example, @code{attach} does not work for
1843 programs on bare-board targets that lack an operating system. You must
1844 also have permission to send the process a signal.
1845
1846 When you use @code{attach}, the debugger finds the program running in
1847 the process first by looking in the current working directory, then (if
1848 the program is not found) by using the source file search path
1849 (@pxref{Source Path, ,Specifying source directories}). You can also use
1850 the @code{file} command to load the program. @xref{Files, ,Commands to
1851 Specify Files}.
1852
1853 The first thing @value{GDBN} does after arranging to debug the specified
1854 process is to stop it. You can examine and modify an attached process
1855 with all the @value{GDBN} commands that are ordinarily available when
1856 you start processes with @code{run}. You can insert breakpoints; you
1857 can step and continue; you can modify storage. If you would rather the
1858 process continue running, you may use the @code{continue} command after
1859 attaching @value{GDBN} to the process.
1860
1861 @table @code
1862 @kindex detach
1863 @item detach
1864 When you have finished debugging the attached process, you can use the
1865 @code{detach} command to release it from @value{GDBN} control. Detaching
1866 the process continues its execution. After the @code{detach} command,
1867 that process and @value{GDBN} become completely independent once more, and you
1868 are ready to @code{attach} another process or start one with @code{run}.
1869 @code{detach} does not repeat if you press @key{RET} again after
1870 executing the command.
1871 @end table
1872
1873 If you exit @value{GDBN} or use the @code{run} command while you have an
1874 attached process, you kill that process. By default, @value{GDBN} asks
1875 for confirmation if you try to do either of these things; you can
1876 control whether or not you need to confirm by using the @code{set
1877 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
1878 messages}).
1879
1880 @node Kill Process
1881 @section Killing the child process
1882
1883 @table @code
1884 @kindex kill
1885 @item kill
1886 Kill the child process in which your program is running under @value{GDBN}.
1887 @end table
1888
1889 This command is useful if you wish to debug a core dump instead of a
1890 running process. @value{GDBN} ignores any core dump file while your program
1891 is running.
1892
1893 On some operating systems, a program cannot be executed outside @value{GDBN}
1894 while you have breakpoints set on it inside @value{GDBN}. You can use the
1895 @code{kill} command in this situation to permit running your program
1896 outside the debugger.
1897
1898 The @code{kill} command is also useful if you wish to recompile and
1899 relink your program, since on many systems it is impossible to modify an
1900 executable file while it is running in a process. In this case, when you
1901 next type @code{run}, @value{GDBN} notices that the file has changed, and
1902 reads the symbol table again (while trying to preserve your current
1903 breakpoint settings).
1904
1905 @node Threads
1906 @section Debugging programs with multiple threads
1907
1908 @cindex threads of execution
1909 @cindex multiple threads
1910 @cindex switching threads
1911 In some operating systems, such as HP-UX and Solaris, a single program
1912 may have more than one @dfn{thread} of execution. The precise semantics
1913 of threads differ from one operating system to another, but in general
1914 the threads of a single program are akin to multiple processes---except
1915 that they share one address space (that is, they can all examine and
1916 modify the same variables). On the other hand, each thread has its own
1917 registers and execution stack, and perhaps private memory.
1918
1919 @value{GDBN} provides these facilities for debugging multi-thread
1920 programs:
1921
1922 @itemize @bullet
1923 @item automatic notification of new threads
1924 @item @samp{thread @var{threadno}}, a command to switch among threads
1925 @item @samp{info threads}, a command to inquire about existing threads
1926 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
1927 a command to apply a command to a list of threads
1928 @item thread-specific breakpoints
1929 @end itemize
1930
1931 @quotation
1932 @emph{Warning:} These facilities are not yet available on every
1933 @value{GDBN} configuration where the operating system supports threads.
1934 If your @value{GDBN} does not support threads, these commands have no
1935 effect. For example, a system without thread support shows no output
1936 from @samp{info threads}, and always rejects the @code{thread} command,
1937 like this:
1938
1939 @smallexample
1940 (@value{GDBP}) info threads
1941 (@value{GDBP}) thread 1
1942 Thread ID 1 not known. Use the "info threads" command to
1943 see the IDs of currently known threads.
1944 @end smallexample
1945 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
1946 @c doesn't support threads"?
1947 @end quotation
1948
1949 @cindex focus of debugging
1950 @cindex current thread
1951 The @value{GDBN} thread debugging facility allows you to observe all
1952 threads while your program runs---but whenever @value{GDBN} takes
1953 control, one thread in particular is always the focus of debugging.
1954 This thread is called the @dfn{current thread}. Debugging commands show
1955 program information from the perspective of the current thread.
1956
1957 @kindex New @var{systag}
1958 @cindex thread identifier (system)
1959 @c FIXME-implementors!! It would be more helpful if the [New...] message
1960 @c included GDB's numeric thread handle, so you could just go to that
1961 @c thread without first checking `info threads'.
1962 Whenever @value{GDBN} detects a new thread in your program, it displays
1963 the target system's identification for the thread with a message in the
1964 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
1965 whose form varies depending on the particular system. For example, on
1966 LynxOS, you might see
1967
1968 @example
1969 [New process 35 thread 27]
1970 @end example
1971
1972 @noindent
1973 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
1974 the @var{systag} is simply something like @samp{process 368}, with no
1975 further qualifier.
1976
1977 @c FIXME!! (1) Does the [New...] message appear even for the very first
1978 @c thread of a program, or does it only appear for the
1979 @c second---i.e., when it becomes obvious we have a multithread
1980 @c program?
1981 @c (2) *Is* there necessarily a first thread always? Or do some
1982 @c multithread systems permit starting a program with multiple
1983 @c threads ab initio?
1984
1985 @cindex thread number
1986 @cindex thread identifier (GDB)
1987 For debugging purposes, @value{GDBN} associates its own thread
1988 number---always a single integer---with each thread in your program.
1989
1990 @table @code
1991 @kindex info threads
1992 @item info threads
1993 Display a summary of all threads currently in your
1994 program. @value{GDBN} displays for each thread (in this order):
1995
1996 @enumerate
1997 @item the thread number assigned by @value{GDBN}
1998
1999 @item the target system's thread identifier (@var{systag})
2000
2001 @item the current stack frame summary for that thread
2002 @end enumerate
2003
2004 @noindent
2005 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2006 indicates the current thread.
2007
2008 For example,
2009 @end table
2010 @c end table here to get a little more width for example
2011
2012 @smallexample
2013 (@value{GDBP}) info threads
2014 3 process 35 thread 27 0x34e5 in sigpause ()
2015 2 process 35 thread 23 0x34e5 in sigpause ()
2016 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2017 at threadtest.c:68
2018 @end smallexample
2019
2020 On HP-UX systems:
2021
2022 @cindex thread number
2023 @cindex thread identifier (GDB)
2024 For debugging purposes, @value{GDBN} associates its own thread
2025 number---a small integer assigned in thread-creation order---with each
2026 thread in your program.
2027
2028 @kindex New @var{systag}
2029 @cindex thread identifier (system)
2030 @c FIXME-implementors!! It would be more helpful if the [New...] message
2031 @c included GDB's numeric thread handle, so you could just go to that
2032 @c thread without first checking `info threads'.
2033 Whenever @value{GDBN} detects a new thread in your program, it displays
2034 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2035 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2036 whose form varies depending on the particular system. For example, on
2037 HP-UX, you see
2038
2039 @example
2040 [New thread 2 (system thread 26594)]
2041 @end example
2042
2043 @noindent
2044 when @value{GDBN} notices a new thread.
2045
2046 @table @code
2047 @kindex info threads
2048 @item info threads
2049 Display a summary of all threads currently in your
2050 program. @value{GDBN} displays for each thread (in this order):
2051
2052 @enumerate
2053 @item the thread number assigned by @value{GDBN}
2054
2055 @item the target system's thread identifier (@var{systag})
2056
2057 @item the current stack frame summary for that thread
2058 @end enumerate
2059
2060 @noindent
2061 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2062 indicates the current thread.
2063
2064 For example,
2065 @end table
2066 @c end table here to get a little more width for example
2067
2068 @example
2069 (@value{GDBP}) info threads
2070 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2071 at quicksort.c:137
2072 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2073 from /usr/lib/libc.2
2074 1 system thread 27905 0x7b003498 in _brk () \@*
2075 from /usr/lib/libc.2
2076 @end example
2077
2078 @table @code
2079 @kindex thread @var{threadno}
2080 @item thread @var{threadno}
2081 Make thread number @var{threadno} the current thread. The command
2082 argument @var{threadno} is the internal @value{GDBN} thread number, as
2083 shown in the first field of the @samp{info threads} display.
2084 @value{GDBN} responds by displaying the system identifier of the thread
2085 you selected, and its current stack frame summary:
2086
2087 @smallexample
2088 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2089 (@value{GDBP}) thread 2
2090 [Switching to process 35 thread 23]
2091 0x34e5 in sigpause ()
2092 @end smallexample
2093
2094 @noindent
2095 As with the @samp{[New @dots{}]} message, the form of the text after
2096 @samp{Switching to} depends on your system's conventions for identifying
2097 threads.
2098
2099 @kindex thread apply
2100 @item thread apply [@var{threadno}] [@var{all}] @var{args}
2101 The @code{thread apply} command allows you to apply a command to one or
2102 more threads. Specify the numbers of the threads that you want affected
2103 with the command argument @var{threadno}. @var{threadno} is the internal
2104 @value{GDBN} thread number, as shown in the first field of the @samp{info
2105 threads} display. To apply a command to all threads, use
2106 @code{thread apply all} @var{args}.
2107 @end table
2108
2109 @cindex automatic thread selection
2110 @cindex switching threads automatically
2111 @cindex threads, automatic switching
2112 Whenever @value{GDBN} stops your program, due to a breakpoint or a
2113 signal, it automatically selects the thread where that breakpoint or
2114 signal happened. @value{GDBN} alerts you to the context switch with a
2115 message of the form @samp{[Switching to @var{systag}]} to identify the
2116 thread.
2117
2118 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2119 more information about how @value{GDBN} behaves when you stop and start
2120 programs with multiple threads.
2121
2122 @xref{Set Watchpoints,,Setting watchpoints}, for information about
2123 watchpoints in programs with multiple threads.
2124
2125 @node Processes
2126 @section Debugging programs with multiple processes
2127
2128 @cindex fork, debugging programs which call
2129 @cindex multiple processes
2130 @cindex processes, multiple
2131 On most systems, @value{GDBN} has no special support for debugging
2132 programs which create additional processes using the @code{fork}
2133 function. When a program forks, @value{GDBN} will continue to debug the
2134 parent process and the child process will run unimpeded. If you have
2135 set a breakpoint in any code which the child then executes, the child
2136 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2137 will cause it to terminate.
2138
2139 However, if you want to debug the child process there is a workaround
2140 which isn't too painful. Put a call to @code{sleep} in the code which
2141 the child process executes after the fork. It may be useful to sleep
2142 only if a certain environment variable is set, or a certain file exists,
2143 so that the delay need not occur when you don't want to run @value{GDBN}
2144 on the child. While the child is sleeping, use the @code{ps} program to
2145 get its process ID. Then tell @value{GDBN} (a new invocation of
2146 @value{GDBN} if you are also debugging the parent process) to attach to
2147 the child process (@pxref{Attach}). From that point on you can debug
2148 the child process just like any other process which you attached to.
2149
2150 On HP-UX (11.x and later only?), @value{GDBN} provides support for
2151 debugging programs that create additional processes using the
2152 @code{fork} or @code{vfork} function.
2153
2154 By default, when a program forks, @value{GDBN} will continue to debug
2155 the parent process and the child process will run unimpeded.
2156
2157 If you want to follow the child process instead of the parent process,
2158 use the command @w{@code{set follow-fork-mode}}.
2159
2160 @table @code
2161 @kindex set follow-fork-mode
2162 @item set follow-fork-mode @var{mode}
2163 Set the debugger response to a program call of @code{fork} or
2164 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2165 process. The @var{mode} can be:
2166
2167 @table @code
2168 @item parent
2169 The original process is debugged after a fork. The child process runs
2170 unimpeded. This is the default.
2171
2172 @item child
2173 The new process is debugged after a fork. The parent process runs
2174 unimpeded.
2175
2176 @item ask
2177 The debugger will ask for one of the above choices.
2178 @end table
2179
2180 @item show follow-fork-mode
2181 Display the current debugger response to a @code{fork} or @code{vfork} call.
2182 @end table
2183
2184 If you ask to debug a child process and a @code{vfork} is followed by an
2185 @code{exec}, @value{GDBN} executes the new target up to the first
2186 breakpoint in the new target. If you have a breakpoint set on
2187 @code{main} in your original program, the breakpoint will also be set on
2188 the child process's @code{main}.
2189
2190 When a child process is spawned by @code{vfork}, you cannot debug the
2191 child or parent until an @code{exec} call completes.
2192
2193 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2194 call executes, the new target restarts. To restart the parent process,
2195 use the @code{file} command with the parent executable name as its
2196 argument.
2197
2198 You can use the @code{catch} command to make @value{GDBN} stop whenever
2199 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2200 Catchpoints, ,Setting catchpoints}.
2201
2202 @node Stopping
2203 @chapter Stopping and Continuing
2204
2205 The principal purposes of using a debugger are so that you can stop your
2206 program before it terminates; or so that, if your program runs into
2207 trouble, you can investigate and find out why.
2208
2209 Inside @value{GDBN}, your program may stop for any of several reasons,
2210 such as a signal, a breakpoint, or reaching a new line after a
2211 @value{GDBN} command such as @code{step}. You may then examine and
2212 change variables, set new breakpoints or remove old ones, and then
2213 continue execution. Usually, the messages shown by @value{GDBN} provide
2214 ample explanation of the status of your program---but you can also
2215 explicitly request this information at any time.
2216
2217 @table @code
2218 @kindex info program
2219 @item info program
2220 Display information about the status of your program: whether it is
2221 running or not, what process it is, and why it stopped.
2222 @end table
2223
2224 @menu
2225 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2226 * Continuing and Stepping:: Resuming execution
2227 * Signals:: Signals
2228 * Thread Stops:: Stopping and starting multi-thread programs
2229 @end menu
2230
2231 @node Breakpoints
2232 @section Breakpoints, watchpoints, and catchpoints
2233
2234 @cindex breakpoints
2235 A @dfn{breakpoint} makes your program stop whenever a certain point in
2236 the program is reached. For each breakpoint, you can add conditions to
2237 control in finer detail whether your program stops. You can set
2238 breakpoints with the @code{break} command and its variants (@pxref{Set
2239 Breaks, ,Setting breakpoints}), to specify the place where your program
2240 should stop by line number, function name or exact address in the
2241 program.
2242
2243 In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2244 breakpoints in shared libraries before the executable is run. There is
2245 a minor limitation on HP-UX systems: you must wait until the executable
2246 is run in order to set breakpoints in shared library routines that are
2247 not called directly by the program (for example, routines that are
2248 arguments in a @code{pthread_create} call).
2249
2250 @cindex watchpoints
2251 @cindex memory tracing
2252 @cindex breakpoint on memory address
2253 @cindex breakpoint on variable modification
2254 A @dfn{watchpoint} is a special breakpoint that stops your program
2255 when the value of an expression changes. You must use a different
2256 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2257 watchpoints}), but aside from that, you can manage a watchpoint like
2258 any other breakpoint: you enable, disable, and delete both breakpoints
2259 and watchpoints using the same commands.
2260
2261 You can arrange to have values from your program displayed automatically
2262 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2263 Automatic display}.
2264
2265 @cindex catchpoints
2266 @cindex breakpoint on events
2267 A @dfn{catchpoint} is another special breakpoint that stops your program
2268 when a certain kind of event occurs, such as the throwing of a C++
2269 exception or the loading of a library. As with watchpoints, you use a
2270 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2271 catchpoints}), but aside from that, you can manage a catchpoint like any
2272 other breakpoint. (To stop when your program receives a signal, use the
2273 @code{handle} command; see @ref{Signals, ,Signals}.)
2274
2275 @cindex breakpoint numbers
2276 @cindex numbers for breakpoints
2277 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2278 catchpoint when you create it; these numbers are successive integers
2279 starting with one. In many of the commands for controlling various
2280 features of breakpoints you use the breakpoint number to say which
2281 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2282 @dfn{disabled}; if disabled, it has no effect on your program until you
2283 enable it again.
2284
2285 @cindex breakpoint ranges
2286 @cindex ranges of breakpoints
2287 Some @value{GDBN} commands accept a range of breakpoints on which to
2288 operate. A breakpoint range is either a single breakpoint number, like
2289 @samp{5}, or two such numbers, in increasing order, separated by a
2290 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2291 all breakpoint in that range are operated on.
2292
2293 @menu
2294 * Set Breaks:: Setting breakpoints
2295 * Set Watchpoints:: Setting watchpoints
2296 * Set Catchpoints:: Setting catchpoints
2297 * Delete Breaks:: Deleting breakpoints
2298 * Disabling:: Disabling breakpoints
2299 * Conditions:: Break conditions
2300 * Break Commands:: Breakpoint command lists
2301 * Breakpoint Menus:: Breakpoint menus
2302 * Error in Breakpoints:: ``Cannot insert breakpoints''
2303 @end menu
2304
2305 @node Set Breaks
2306 @subsection Setting breakpoints
2307
2308 @c FIXME LMB what does GDB do if no code on line of breakpt?
2309 @c consider in particular declaration with/without initialization.
2310 @c
2311 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2312
2313 @kindex break
2314 @kindex b
2315 @kindex $bpnum
2316 @cindex latest breakpoint
2317 Breakpoints are set with the @code{break} command (abbreviated
2318 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2319 number of the breakpoints you've set most recently; see @ref{Convenience
2320 Vars,, Convenience variables}, for a discussion of what you can do with
2321 convenience variables.
2322
2323 You have several ways to say where the breakpoint should go.
2324
2325 @table @code
2326 @item break @var{function}
2327 Set a breakpoint at entry to function @var{function}.
2328 When using source languages that permit overloading of symbols, such as
2329 C++, @var{function} may refer to more than one possible place to break.
2330 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2331
2332 @item break +@var{offset}
2333 @itemx break -@var{offset}
2334 Set a breakpoint some number of lines forward or back from the position
2335 at which execution stopped in the currently selected @dfn{stack frame}.
2336 (@xref{Frames, ,Frames}, for a description of stack frames.)
2337
2338 @item break @var{linenum}
2339 Set a breakpoint at line @var{linenum} in the current source file.
2340 The current source file is the last file whose source text was printed.
2341 The breakpoint will stop your program just before it executes any of the
2342 code on that line.
2343
2344 @item break @var{filename}:@var{linenum}
2345 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2346
2347 @item break @var{filename}:@var{function}
2348 Set a breakpoint at entry to function @var{function} found in file
2349 @var{filename}. Specifying a file name as well as a function name is
2350 superfluous except when multiple files contain similarly named
2351 functions.
2352
2353 @item break *@var{address}
2354 Set a breakpoint at address @var{address}. You can use this to set
2355 breakpoints in parts of your program which do not have debugging
2356 information or source files.
2357
2358 @item break
2359 When called without any arguments, @code{break} sets a breakpoint at
2360 the next instruction to be executed in the selected stack frame
2361 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2362 innermost, this makes your program stop as soon as control
2363 returns to that frame. This is similar to the effect of a
2364 @code{finish} command in the frame inside the selected frame---except
2365 that @code{finish} does not leave an active breakpoint. If you use
2366 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2367 the next time it reaches the current location; this may be useful
2368 inside loops.
2369
2370 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2371 least one instruction has been executed. If it did not do this, you
2372 would be unable to proceed past a breakpoint without first disabling the
2373 breakpoint. This rule applies whether or not the breakpoint already
2374 existed when your program stopped.
2375
2376 @item break @dots{} if @var{cond}
2377 Set a breakpoint with condition @var{cond}; evaluate the expression
2378 @var{cond} each time the breakpoint is reached, and stop only if the
2379 value is nonzero---that is, if @var{cond} evaluates as true.
2380 @samp{@dots{}} stands for one of the possible arguments described
2381 above (or no argument) specifying where to break. @xref{Conditions,
2382 ,Break conditions}, for more information on breakpoint conditions.
2383
2384 @kindex tbreak
2385 @item tbreak @var{args}
2386 Set a breakpoint enabled only for one stop. @var{args} are the
2387 same as for the @code{break} command, and the breakpoint is set in the same
2388 way, but the breakpoint is automatically deleted after the first time your
2389 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2390
2391 @kindex hbreak
2392 @item hbreak @var{args}
2393 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2394 @code{break} command and the breakpoint is set in the same way, but the
2395 breakpoint requires hardware support and some target hardware may not
2396 have this support. The main purpose of this is EPROM/ROM code
2397 debugging, so you can set a breakpoint at an instruction without
2398 changing the instruction. This can be used with the new trap-generation
2399 provided by SPARClite DSU and some x86-based targets. These targets
2400 will generate traps when a program accesses some data or instruction
2401 address that is assigned to the debug registers. However the hardware
2402 breakpoint registers can take a limited number of breakpoints. For
2403 example, on the DSU, only two data breakpoints can be set at a time, and
2404 @value{GDBN} will reject this command if more than two are used. Delete
2405 or disable unused hardware breakpoints before setting new ones
2406 (@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
2407
2408 @kindex thbreak
2409 @item thbreak @var{args}
2410 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2411 are the same as for the @code{hbreak} command and the breakpoint is set in
2412 the same way. However, like the @code{tbreak} command,
2413 the breakpoint is automatically deleted after the
2414 first time your program stops there. Also, like the @code{hbreak}
2415 command, the breakpoint requires hardware support and some target hardware
2416 may not have this support. @xref{Disabling, ,Disabling breakpoints}.
2417 See also @ref{Conditions, ,Break conditions}.
2418
2419 @kindex rbreak
2420 @cindex regular expression
2421 @item rbreak @var{regex}
2422 Set breakpoints on all functions matching the regular expression
2423 @var{regex}. This command sets an unconditional breakpoint on all
2424 matches, printing a list of all breakpoints it set. Once these
2425 breakpoints are set, they are treated just like the breakpoints set with
2426 the @code{break} command. You can delete them, disable them, or make
2427 them conditional the same way as any other breakpoint.
2428
2429 The syntax of the regular expression is the standard one used with tools
2430 like @file{grep}. Note that this is different from the syntax used by
2431 shells, so for instance @code{foo*} matches all functions that include
2432 an @code{fo} followed by zero or more @code{o}s. There is an implicit
2433 @code{.*} leading and trailing the regular expression you supply, so to
2434 match only functions that begin with @code{foo}, use @code{^foo}.
2435
2436 When debugging C++ programs, @code{rbreak} is useful for setting
2437 breakpoints on overloaded functions that are not members of any special
2438 classes.
2439
2440 @kindex info breakpoints
2441 @cindex @code{$_} and @code{info breakpoints}
2442 @item info breakpoints @r{[}@var{n}@r{]}
2443 @itemx info break @r{[}@var{n}@r{]}
2444 @itemx info watchpoints @r{[}@var{n}@r{]}
2445 Print a table of all breakpoints, watchpoints, and catchpoints set and
2446 not deleted, with the following columns for each breakpoint:
2447
2448 @table @emph
2449 @item Breakpoint Numbers
2450 @item Type
2451 Breakpoint, watchpoint, or catchpoint.
2452 @item Disposition
2453 Whether the breakpoint is marked to be disabled or deleted when hit.
2454 @item Enabled or Disabled
2455 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2456 that are not enabled.
2457 @item Address
2458 Where the breakpoint is in your program, as a memory address.
2459 @item What
2460 Where the breakpoint is in the source for your program, as a file and
2461 line number.
2462 @end table
2463
2464 @noindent
2465 If a breakpoint is conditional, @code{info break} shows the condition on
2466 the line following the affected breakpoint; breakpoint commands, if any,
2467 are listed after that.
2468
2469 @noindent
2470 @code{info break} with a breakpoint
2471 number @var{n} as argument lists only that breakpoint. The
2472 convenience variable @code{$_} and the default examining-address for
2473 the @code{x} command are set to the address of the last breakpoint
2474 listed (@pxref{Memory, ,Examining memory}).
2475
2476 @noindent
2477 @code{info break} displays a count of the number of times the breakpoint
2478 has been hit. This is especially useful in conjunction with the
2479 @code{ignore} command. You can ignore a large number of breakpoint
2480 hits, look at the breakpoint info to see how many times the breakpoint
2481 was hit, and then run again, ignoring one less than that number. This
2482 will get you quickly to the last hit of that breakpoint.
2483 @end table
2484
2485 @value{GDBN} allows you to set any number of breakpoints at the same place in
2486 your program. There is nothing silly or meaningless about this. When
2487 the breakpoints are conditional, this is even useful
2488 (@pxref{Conditions, ,Break conditions}).
2489
2490 @cindex negative breakpoint numbers
2491 @cindex internal @value{GDBN} breakpoints
2492 @value{GDBN} itself sometimes sets breakpoints in your program for special
2493 purposes, such as proper handling of @code{longjmp} (in C programs).
2494 These internal breakpoints are assigned negative numbers, starting with
2495 @code{-1}; @samp{info breakpoints} does not display them.
2496
2497 You can see these breakpoints with the @value{GDBN} maintenance command
2498 @samp{maint info breakpoints}.
2499
2500 @table @code
2501 @kindex maint info breakpoints
2502 @item maint info breakpoints
2503 Using the same format as @samp{info breakpoints}, display both the
2504 breakpoints you've set explicitly, and those @value{GDBN} is using for
2505 internal purposes. Internal breakpoints are shown with negative
2506 breakpoint numbers. The type column identifies what kind of breakpoint
2507 is shown:
2508
2509 @table @code
2510 @item breakpoint
2511 Normal, explicitly set breakpoint.
2512
2513 @item watchpoint
2514 Normal, explicitly set watchpoint.
2515
2516 @item longjmp
2517 Internal breakpoint, used to handle correctly stepping through
2518 @code{longjmp} calls.
2519
2520 @item longjmp resume
2521 Internal breakpoint at the target of a @code{longjmp}.
2522
2523 @item until
2524 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
2525
2526 @item finish
2527 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
2528
2529 @item shlib events
2530 Shared library events.
2531
2532 @end table
2533
2534 @end table
2535
2536
2537 @node Set Watchpoints
2538 @subsection Setting watchpoints
2539
2540 @cindex setting watchpoints
2541 @cindex software watchpoints
2542 @cindex hardware watchpoints
2543 You can use a watchpoint to stop execution whenever the value of an
2544 expression changes, without having to predict a particular place where
2545 this may happen.
2546
2547 Depending on your system, watchpoints may be implemented in software or
2548 hardware. @value{GDBN} does software watchpointing by single-stepping your
2549 program and testing the variable's value each time, which is hundreds of
2550 times slower than normal execution. (But this may still be worth it, to
2551 catch errors where you have no clue what part of your program is the
2552 culprit.)
2553
2554 On some systems, such as HP-UX, Linux and some other x86-based targets,
2555 @value{GDBN} includes support for
2556 hardware watchpoints, which do not slow down the running of your
2557 program.
2558
2559 @table @code
2560 @kindex watch
2561 @item watch @var{expr}
2562 Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2563 is written into by the program and its value changes.
2564
2565 @kindex rwatch
2566 @item rwatch @var{expr}
2567 Set a watchpoint that will break when watch @var{expr} is read by the program.
2568
2569 @kindex awatch
2570 @item awatch @var{expr}
2571 Set a watchpoint that will break when @var{expr} is either read or written into
2572 by the program.
2573
2574 @kindex info watchpoints
2575 @item info watchpoints
2576 This command prints a list of watchpoints, breakpoints, and catchpoints;
2577 it is the same as @code{info break}.
2578 @end table
2579
2580 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2581 watchpoints execute very quickly, and the debugger reports a change in
2582 value at the exact instruction where the change occurs. If @value{GDBN}
2583 cannot set a hardware watchpoint, it sets a software watchpoint, which
2584 executes more slowly and reports the change in value at the next
2585 statement, not the instruction, after the change occurs.
2586
2587 When you issue the @code{watch} command, @value{GDBN} reports
2588
2589 @example
2590 Hardware watchpoint @var{num}: @var{expr}
2591 @end example
2592
2593 @noindent
2594 if it was able to set a hardware watchpoint.
2595
2596 Currently, the @code{awatch} and @code{rwatch} commands can only set
2597 hardware watchpoints, because accesses to data that don't change the
2598 value of the watched expression cannot be detected without examining
2599 every instruction as it is being executed, and @value{GDBN} does not do
2600 that currently. If @value{GDBN} finds that it is unable to set a
2601 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2602 will print a message like this:
2603
2604 @smallexample
2605 Expression cannot be implemented with read/access watchpoint.
2606 @end smallexample
2607
2608 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2609 data type of the watched expression is wider than what a hardware
2610 watchpoint on the target machine can handle. For example, some systems
2611 can only watch regions that are up to 4 bytes wide; on such systems you
2612 cannot set hardware watchpoints for an expression that yields a
2613 double-precision floating-point number (which is typically 8 bytes
2614 wide). As a work-around, it might be possible to break the large region
2615 into a series of smaller ones and watch them with separate watchpoints.
2616
2617 If you set too many hardware watchpoints, @value{GDBN} might be unable
2618 to insert all of them when you resume the execution of your program.
2619 Since the precise number of active watchpoints is unknown until such
2620 time as the program is about to be resumed, @value{GDBN} might not be
2621 able to warn you about this when you set the watchpoints, and the
2622 warning will be printed only when the program is resumed:
2623
2624 @smallexample
2625 Hardware watchpoint @var{num}: Could not insert watchpoint
2626 @end smallexample
2627
2628 @noindent
2629 If this happens, delete or disable some of the watchpoints.
2630
2631 The SPARClite DSU will generate traps when a program accesses some data
2632 or instruction address that is assigned to the debug registers. For the
2633 data addresses, DSU facilitates the @code{watch} command. However the
2634 hardware breakpoint registers can only take two data watchpoints, and
2635 both watchpoints must be the same kind. For example, you can set two
2636 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2637 @strong{or} two with @code{awatch} commands, but you cannot set one
2638 watchpoint with one command and the other with a different command.
2639 @value{GDBN} will reject the command if you try to mix watchpoints.
2640 Delete or disable unused watchpoint commands before setting new ones.
2641
2642 If you call a function interactively using @code{print} or @code{call},
2643 any watchpoints you have set will be inactive until @value{GDBN} reaches another
2644 kind of breakpoint or the call completes.
2645
2646 @value{GDBN} automatically deletes watchpoints that watch local
2647 (automatic) variables, or expressions that involve such variables, when
2648 they go out of scope, that is, when the execution leaves the block in
2649 which these variables were defined. In particular, when the program
2650 being debugged terminates, @emph{all} local variables go out of scope,
2651 and so only watchpoints that watch global variables remain set. If you
2652 rerun the program, you will need to set all such watchpoints again. One
2653 way of doing that would be to set a code breakpoint at the entry to the
2654 @code{main} function and when it breaks, set all the watchpoints.
2655
2656 @quotation
2657 @cindex watchpoints and threads
2658 @cindex threads and watchpoints
2659 @emph{Warning:} In multi-thread programs, watchpoints have only limited
2660 usefulness. With the current watchpoint implementation, @value{GDBN}
2661 can only watch the value of an expression @emph{in a single thread}. If
2662 you are confident that the expression can only change due to the current
2663 thread's activity (and if you are also confident that no other thread
2664 can become current), then you can use watchpoints as usual. However,
2665 @value{GDBN} may not notice when a non-current thread's activity changes
2666 the expression.
2667
2668 @c FIXME: this is almost identical to the previous paragraph.
2669 @emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2670 have only limited usefulness. If @value{GDBN} creates a software
2671 watchpoint, it can only watch the value of an expression @emph{in a
2672 single thread}. If you are confident that the expression can only
2673 change due to the current thread's activity (and if you are also
2674 confident that no other thread can become current), then you can use
2675 software watchpoints as usual. However, @value{GDBN} may not notice
2676 when a non-current thread's activity changes the expression. (Hardware
2677 watchpoints, in contrast, watch an expression in all threads.)
2678 @end quotation
2679
2680 @node Set Catchpoints
2681 @subsection Setting catchpoints
2682 @cindex catchpoints, setting
2683 @cindex exception handlers
2684 @cindex event handling
2685
2686 You can use @dfn{catchpoints} to cause the debugger to stop for certain
2687 kinds of program events, such as C++ exceptions or the loading of a
2688 shared library. Use the @code{catch} command to set a catchpoint.
2689
2690 @table @code
2691 @kindex catch
2692 @item catch @var{event}
2693 Stop when @var{event} occurs. @var{event} can be any of the following:
2694 @table @code
2695 @item throw
2696 @kindex catch throw
2697 The throwing of a C++ exception.
2698
2699 @item catch
2700 @kindex catch catch
2701 The catching of a C++ exception.
2702
2703 @item exec
2704 @kindex catch exec
2705 A call to @code{exec}. This is currently only available for HP-UX.
2706
2707 @item fork
2708 @kindex catch fork
2709 A call to @code{fork}. This is currently only available for HP-UX.
2710
2711 @item vfork
2712 @kindex catch vfork
2713 A call to @code{vfork}. This is currently only available for HP-UX.
2714
2715 @item load
2716 @itemx load @var{libname}
2717 @kindex catch load
2718 The dynamic loading of any shared library, or the loading of the library
2719 @var{libname}. This is currently only available for HP-UX.
2720
2721 @item unload
2722 @itemx unload @var{libname}
2723 @kindex catch unload
2724 The unloading of any dynamically loaded shared library, or the unloading
2725 of the library @var{libname}. This is currently only available for HP-UX.
2726 @end table
2727
2728 @item tcatch @var{event}
2729 Set a catchpoint that is enabled only for one stop. The catchpoint is
2730 automatically deleted after the first time the event is caught.
2731
2732 @end table
2733
2734 Use the @code{info break} command to list the current catchpoints.
2735
2736 There are currently some limitations to C++ exception handling
2737 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2738
2739 @itemize @bullet
2740 @item
2741 If you call a function interactively, @value{GDBN} normally returns
2742 control to you when the function has finished executing. If the call
2743 raises an exception, however, the call may bypass the mechanism that
2744 returns control to you and cause your program either to abort or to
2745 simply continue running until it hits a breakpoint, catches a signal
2746 that @value{GDBN} is listening for, or exits. This is the case even if
2747 you set a catchpoint for the exception; catchpoints on exceptions are
2748 disabled within interactive calls.
2749
2750 @item
2751 You cannot raise an exception interactively.
2752
2753 @item
2754 You cannot install an exception handler interactively.
2755 @end itemize
2756
2757 @cindex raise exceptions
2758 Sometimes @code{catch} is not the best way to debug exception handling:
2759 if you need to know exactly where an exception is raised, it is better to
2760 stop @emph{before} the exception handler is called, since that way you
2761 can see the stack before any unwinding takes place. If you set a
2762 breakpoint in an exception handler instead, it may not be easy to find
2763 out where the exception was raised.
2764
2765 To stop just before an exception handler is called, you need some
2766 knowledge of the implementation. In the case of @sc{gnu} C++, exceptions are
2767 raised by calling a library function named @code{__raise_exception}
2768 which has the following ANSI C interface:
2769
2770 @example
2771 /* @var{addr} is where the exception identifier is stored.
2772 @var{id} is the exception identifier. */
2773 void __raise_exception (void **addr, void *id);
2774 @end example
2775
2776 @noindent
2777 To make the debugger catch all exceptions before any stack
2778 unwinding takes place, set a breakpoint on @code{__raise_exception}
2779 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2780
2781 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2782 that depends on the value of @var{id}, you can stop your program when
2783 a specific exception is raised. You can use multiple conditional
2784 breakpoints to stop your program when any of a number of exceptions are
2785 raised.
2786
2787
2788 @node Delete Breaks
2789 @subsection Deleting breakpoints
2790
2791 @cindex clearing breakpoints, watchpoints, catchpoints
2792 @cindex deleting breakpoints, watchpoints, catchpoints
2793 It is often necessary to eliminate a breakpoint, watchpoint, or
2794 catchpoint once it has done its job and you no longer want your program
2795 to stop there. This is called @dfn{deleting} the breakpoint. A
2796 breakpoint that has been deleted no longer exists; it is forgotten.
2797
2798 With the @code{clear} command you can delete breakpoints according to
2799 where they are in your program. With the @code{delete} command you can
2800 delete individual breakpoints, watchpoints, or catchpoints by specifying
2801 their breakpoint numbers.
2802
2803 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2804 automatically ignores breakpoints on the first instruction to be executed
2805 when you continue execution without changing the execution address.
2806
2807 @table @code
2808 @kindex clear
2809 @item clear
2810 Delete any breakpoints at the next instruction to be executed in the
2811 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2812 the innermost frame is selected, this is a good way to delete a
2813 breakpoint where your program just stopped.
2814
2815 @item clear @var{function}
2816 @itemx clear @var{filename}:@var{function}
2817 Delete any breakpoints set at entry to the function @var{function}.
2818
2819 @item clear @var{linenum}
2820 @itemx clear @var{filename}:@var{linenum}
2821 Delete any breakpoints set at or within the code of the specified line.
2822
2823 @cindex delete breakpoints
2824 @kindex delete
2825 @kindex d
2826 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2827 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2828 ranges specified as arguments. If no argument is specified, delete all
2829 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2830 confirm off}). You can abbreviate this command as @code{d}.
2831 @end table
2832
2833 @node Disabling
2834 @subsection Disabling breakpoints
2835
2836 @kindex disable breakpoints
2837 @kindex enable breakpoints
2838 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2839 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2840 it had been deleted, but remembers the information on the breakpoint so
2841 that you can @dfn{enable} it again later.
2842
2843 You disable and enable breakpoints, watchpoints, and catchpoints with
2844 the @code{enable} and @code{disable} commands, optionally specifying one
2845 or more breakpoint numbers as arguments. Use @code{info break} or
2846 @code{info watch} to print a list of breakpoints, watchpoints, and
2847 catchpoints if you do not know which numbers to use.
2848
2849 A breakpoint, watchpoint, or catchpoint can have any of four different
2850 states of enablement:
2851
2852 @itemize @bullet
2853 @item
2854 Enabled. The breakpoint stops your program. A breakpoint set
2855 with the @code{break} command starts out in this state.
2856 @item
2857 Disabled. The breakpoint has no effect on your program.
2858 @item
2859 Enabled once. The breakpoint stops your program, but then becomes
2860 disabled.
2861 @item
2862 Enabled for deletion. The breakpoint stops your program, but
2863 immediately after it does so it is deleted permanently. A breakpoint
2864 set with the @code{tbreak} command starts out in this state.
2865 @end itemize
2866
2867 You can use the following commands to enable or disable breakpoints,
2868 watchpoints, and catchpoints:
2869
2870 @table @code
2871 @kindex disable breakpoints
2872 @kindex disable
2873 @kindex dis
2874 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2875 Disable the specified breakpoints---or all breakpoints, if none are
2876 listed. A disabled breakpoint has no effect but is not forgotten. All
2877 options such as ignore-counts, conditions and commands are remembered in
2878 case the breakpoint is enabled again later. You may abbreviate
2879 @code{disable} as @code{dis}.
2880
2881 @kindex enable breakpoints
2882 @kindex enable
2883 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2884 Enable the specified breakpoints (or all defined breakpoints). They
2885 become effective once again in stopping your program.
2886
2887 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
2888 Enable the specified breakpoints temporarily. @value{GDBN} disables any
2889 of these breakpoints immediately after stopping your program.
2890
2891 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
2892 Enable the specified breakpoints to work once, then die. @value{GDBN}
2893 deletes any of these breakpoints as soon as your program stops there.
2894 @end table
2895
2896 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
2897 @c confusing: tbreak is also initially enabled.
2898 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
2899 ,Setting breakpoints}), breakpoints that you set are initially enabled;
2900 subsequently, they become disabled or enabled only when you use one of
2901 the commands above. (The command @code{until} can set and delete a
2902 breakpoint of its own, but it does not change the state of your other
2903 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
2904 stepping}.)
2905
2906 @node Conditions
2907 @subsection Break conditions
2908 @cindex conditional breakpoints
2909 @cindex breakpoint conditions
2910
2911 @c FIXME what is scope of break condition expr? Context where wanted?
2912 @c in particular for a watchpoint?
2913 The simplest sort of breakpoint breaks every time your program reaches a
2914 specified place. You can also specify a @dfn{condition} for a
2915 breakpoint. A condition is just a Boolean expression in your
2916 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
2917 a condition evaluates the expression each time your program reaches it,
2918 and your program stops only if the condition is @emph{true}.
2919
2920 This is the converse of using assertions for program validation; in that
2921 situation, you want to stop when the assertion is violated---that is,
2922 when the condition is false. In C, if you want to test an assertion expressed
2923 by the condition @var{assert}, you should set the condition
2924 @samp{! @var{assert}} on the appropriate breakpoint.
2925
2926 Conditions are also accepted for watchpoints; you may not need them,
2927 since a watchpoint is inspecting the value of an expression anyhow---but
2928 it might be simpler, say, to just set a watchpoint on a variable name,
2929 and specify a condition that tests whether the new value is an interesting
2930 one.
2931
2932 Break conditions can have side effects, and may even call functions in
2933 your program. This can be useful, for example, to activate functions
2934 that log program progress, or to use your own print functions to
2935 format special data structures. The effects are completely predictable
2936 unless there is another enabled breakpoint at the same address. (In
2937 that case, @value{GDBN} might see the other breakpoint first and stop your
2938 program without checking the condition of this one.) Note that
2939 breakpoint commands are usually more convenient and flexible than break
2940 conditions for the
2941 purpose of performing side effects when a breakpoint is reached
2942 (@pxref{Break Commands, ,Breakpoint command lists}).
2943
2944 Break conditions can be specified when a breakpoint is set, by using
2945 @samp{if} in the arguments to the @code{break} command. @xref{Set
2946 Breaks, ,Setting breakpoints}. They can also be changed at any time
2947 with the @code{condition} command.
2948
2949 You can also use the @code{if} keyword with the @code{watch} command.
2950 The @code{catch} command does not recognize the @code{if} keyword;
2951 @code{condition} is the only way to impose a further condition on a
2952 catchpoint.
2953
2954 @table @code
2955 @kindex condition
2956 @item condition @var{bnum} @var{expression}
2957 Specify @var{expression} as the break condition for breakpoint,
2958 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
2959 breakpoint @var{bnum} stops your program only if the value of
2960 @var{expression} is true (nonzero, in C). When you use
2961 @code{condition}, @value{GDBN} checks @var{expression} immediately for
2962 syntactic correctness, and to determine whether symbols in it have
2963 referents in the context of your breakpoint. If @var{expression} uses
2964 symbols not referenced in the context of the breakpoint, @value{GDBN}
2965 prints an error message:
2966
2967 @example
2968 No symbol "foo" in current context.
2969 @end example
2970
2971 @noindent
2972 @value{GDBN} does
2973 not actually evaluate @var{expression} at the time the @code{condition}
2974 command (or a command that sets a breakpoint with a condition, like
2975 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
2976
2977 @item condition @var{bnum}
2978 Remove the condition from breakpoint number @var{bnum}. It becomes
2979 an ordinary unconditional breakpoint.
2980 @end table
2981
2982 @cindex ignore count (of breakpoint)
2983 A special case of a breakpoint condition is to stop only when the
2984 breakpoint has been reached a certain number of times. This is so
2985 useful that there is a special way to do it, using the @dfn{ignore
2986 count} of the breakpoint. Every breakpoint has an ignore count, which
2987 is an integer. Most of the time, the ignore count is zero, and
2988 therefore has no effect. But if your program reaches a breakpoint whose
2989 ignore count is positive, then instead of stopping, it just decrements
2990 the ignore count by one and continues. As a result, if the ignore count
2991 value is @var{n}, the breakpoint does not stop the next @var{n} times
2992 your program reaches it.
2993
2994 @table @code
2995 @kindex ignore
2996 @item ignore @var{bnum} @var{count}
2997 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
2998 The next @var{count} times the breakpoint is reached, your program's
2999 execution does not stop; other than to decrement the ignore count, @value{GDBN}
3000 takes no action.
3001
3002 To make the breakpoint stop the next time it is reached, specify
3003 a count of zero.
3004
3005 When you use @code{continue} to resume execution of your program from a
3006 breakpoint, you can specify an ignore count directly as an argument to
3007 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
3008 Stepping,,Continuing and stepping}.
3009
3010 If a breakpoint has a positive ignore count and a condition, the
3011 condition is not checked. Once the ignore count reaches zero,
3012 @value{GDBN} resumes checking the condition.
3013
3014 You could achieve the effect of the ignore count with a condition such
3015 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3016 is decremented each time. @xref{Convenience Vars, ,Convenience
3017 variables}.
3018 @end table
3019
3020 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3021
3022
3023 @node Break Commands
3024 @subsection Breakpoint command lists
3025
3026 @cindex breakpoint commands
3027 You can give any breakpoint (or watchpoint or catchpoint) a series of
3028 commands to execute when your program stops due to that breakpoint. For
3029 example, you might want to print the values of certain expressions, or
3030 enable other breakpoints.
3031
3032 @table @code
3033 @kindex commands
3034 @kindex end
3035 @item commands @r{[}@var{bnum}@r{]}
3036 @itemx @dots{} @var{command-list} @dots{}
3037 @itemx end
3038 Specify a list of commands for breakpoint number @var{bnum}. The commands
3039 themselves appear on the following lines. Type a line containing just
3040 @code{end} to terminate the commands.
3041
3042 To remove all commands from a breakpoint, type @code{commands} and
3043 follow it immediately with @code{end}; that is, give no commands.
3044
3045 With no @var{bnum} argument, @code{commands} refers to the last
3046 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3047 recently encountered).
3048 @end table
3049
3050 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3051 disabled within a @var{command-list}.
3052
3053 You can use breakpoint commands to start your program up again. Simply
3054 use the @code{continue} command, or @code{step}, or any other command
3055 that resumes execution.
3056
3057 Any other commands in the command list, after a command that resumes
3058 execution, are ignored. This is because any time you resume execution
3059 (even with a simple @code{next} or @code{step}), you may encounter
3060 another breakpoint---which could have its own command list, leading to
3061 ambiguities about which list to execute.
3062
3063 @kindex silent
3064 If the first command you specify in a command list is @code{silent}, the
3065 usual message about stopping at a breakpoint is not printed. This may
3066 be desirable for breakpoints that are to print a specific message and
3067 then continue. If none of the remaining commands print anything, you
3068 see no sign that the breakpoint was reached. @code{silent} is
3069 meaningful only at the beginning of a breakpoint command list.
3070
3071 The commands @code{echo}, @code{output}, and @code{printf} allow you to
3072 print precisely controlled output, and are often useful in silent
3073 breakpoints. @xref{Output, ,Commands for controlled output}.
3074
3075 For example, here is how you could use breakpoint commands to print the
3076 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3077
3078 @example
3079 break foo if x>0
3080 commands
3081 silent
3082 printf "x is %d\n",x
3083 cont
3084 end
3085 @end example
3086
3087 One application for breakpoint commands is to compensate for one bug so
3088 you can test for another. Put a breakpoint just after the erroneous line
3089 of code, give it a condition to detect the case in which something
3090 erroneous has been done, and give it commands to assign correct values
3091 to any variables that need them. End with the @code{continue} command
3092 so that your program does not stop, and start with the @code{silent}
3093 command so that no output is produced. Here is an example:
3094
3095 @example
3096 break 403
3097 commands
3098 silent
3099 set x = y + 4
3100 cont
3101 end
3102 @end example
3103
3104 @node Breakpoint Menus
3105 @subsection Breakpoint menus
3106 @cindex overloading
3107 @cindex symbol overloading
3108
3109 Some programming languages (notably C++) permit a single function name
3110 to be defined several times, for application in different contexts.
3111 This is called @dfn{overloading}. When a function name is overloaded,
3112 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3113 a breakpoint. If you realize this is a problem, you can use
3114 something like @samp{break @var{function}(@var{types})} to specify which
3115 particular version of the function you want. Otherwise, @value{GDBN} offers
3116 you a menu of numbered choices for different possible breakpoints, and
3117 waits for your selection with the prompt @samp{>}. The first two
3118 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3119 sets a breakpoint at each definition of @var{function}, and typing
3120 @kbd{0} aborts the @code{break} command without setting any new
3121 breakpoints.
3122
3123 For example, the following session excerpt shows an attempt to set a
3124 breakpoint at the overloaded symbol @code{String::after}.
3125 We choose three particular definitions of that function name:
3126
3127 @c FIXME! This is likely to change to show arg type lists, at least
3128 @smallexample
3129 @group
3130 (@value{GDBP}) b String::after
3131 [0] cancel
3132 [1] all
3133 [2] file:String.cc; line number:867
3134 [3] file:String.cc; line number:860
3135 [4] file:String.cc; line number:875
3136 [5] file:String.cc; line number:853
3137 [6] file:String.cc; line number:846
3138 [7] file:String.cc; line number:735
3139 > 2 4 6
3140 Breakpoint 1 at 0xb26c: file String.cc, line 867.
3141 Breakpoint 2 at 0xb344: file String.cc, line 875.
3142 Breakpoint 3 at 0xafcc: file String.cc, line 846.
3143 Multiple breakpoints were set.
3144 Use the "delete" command to delete unwanted
3145 breakpoints.
3146 (@value{GDBP})
3147 @end group
3148 @end smallexample
3149
3150 @c @ifclear BARETARGET
3151 @node Error in Breakpoints
3152 @subsection ``Cannot insert breakpoints''
3153 @c
3154 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3155 @c
3156 Under some operating systems, breakpoints cannot be used in a program if
3157 any other process is running that program. In this situation,
3158 attempting to run or continue a program with a breakpoint causes
3159 @value{GDBN} to print an error message:
3160
3161 @example
3162 Cannot insert breakpoints.
3163 The same program may be running in another process.
3164 @end example
3165
3166 When this happens, you have three ways to proceed:
3167
3168 @enumerate
3169 @item
3170 Remove or disable the breakpoints, then continue.
3171
3172 @item
3173 Suspend @value{GDBN}, and copy the file containing your program to a new
3174 name. Resume @value{GDBN} and use the @code{exec-file} command to specify
3175 that @value{GDBN} should run your program under that name.
3176 Then start your program again.
3177
3178 @item
3179 Relink your program so that the text segment is nonsharable, using the
3180 linker option @samp{-N}. The operating system limitation may not apply
3181 to nonsharable executables.
3182 @end enumerate
3183 @c @end ifclear
3184
3185 A similar message can be printed if you request too many active
3186 hardware-assisted breakpoints and watchpoints:
3187
3188 @c FIXME: the precise wording of this message may change; the relevant
3189 @c source change is not committed yet (Sep 3, 1999).
3190 @smallexample
3191 Stopped; cannot insert breakpoints.
3192 You may have requested too many hardware breakpoints and watchpoints.
3193 @end smallexample
3194
3195 @noindent
3196 This message is printed when you attempt to resume the program, since
3197 only then @value{GDBN} knows exactly how many hardware breakpoints and
3198 watchpoints it needs to insert.
3199
3200 When this message is printed, you need to disable or remove some of the
3201 hardware-assisted breakpoints and watchpoints, and then continue.
3202
3203
3204 @node Continuing and Stepping
3205 @section Continuing and stepping
3206
3207 @cindex stepping
3208 @cindex continuing
3209 @cindex resuming execution
3210 @dfn{Continuing} means resuming program execution until your program
3211 completes normally. In contrast, @dfn{stepping} means executing just
3212 one more ``step'' of your program, where ``step'' may mean either one
3213 line of source code, or one machine instruction (depending on what
3214 particular command you use). Either when continuing or when stepping,
3215 your program may stop even sooner, due to a breakpoint or a signal. (If
3216 it stops due to a signal, you may want to use @code{handle}, or use
3217 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
3218
3219 @table @code
3220 @kindex continue
3221 @kindex c
3222 @kindex fg
3223 @item continue @r{[}@var{ignore-count}@r{]}
3224 @itemx c @r{[}@var{ignore-count}@r{]}
3225 @itemx fg @r{[}@var{ignore-count}@r{]}
3226 Resume program execution, at the address where your program last stopped;
3227 any breakpoints set at that address are bypassed. The optional argument
3228 @var{ignore-count} allows you to specify a further number of times to
3229 ignore a breakpoint at this location; its effect is like that of
3230 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3231
3232 The argument @var{ignore-count} is meaningful only when your program
3233 stopped due to a breakpoint. At other times, the argument to
3234 @code{continue} is ignored.
3235
3236 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3237 debugged program is deemed to be the foreground program) are provided
3238 purely for convenience, and have exactly the same behavior as
3239 @code{continue}.
3240 @end table
3241
3242 To resume execution at a different place, you can use @code{return}
3243 (@pxref{Returning, ,Returning from a function}) to go back to the
3244 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3245 different address}) to go to an arbitrary location in your program.
3246
3247 A typical technique for using stepping is to set a breakpoint
3248 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3249 beginning of the function or the section of your program where a problem
3250 is believed to lie, run your program until it stops at that breakpoint,
3251 and then step through the suspect area, examining the variables that are
3252 interesting, until you see the problem happen.
3253
3254 @table @code
3255 @kindex step
3256 @kindex s
3257 @item step
3258 Continue running your program until control reaches a different source
3259 line, then stop it and return control to @value{GDBN}. This command is
3260 abbreviated @code{s}.
3261
3262 @quotation
3263 @c "without debugging information" is imprecise; actually "without line
3264 @c numbers in the debugging information". (gcc -g1 has debugging info but
3265 @c not line numbers). But it seems complex to try to make that
3266 @c distinction here.
3267 @emph{Warning:} If you use the @code{step} command while control is
3268 within a function that was compiled without debugging information,
3269 execution proceeds until control reaches a function that does have
3270 debugging information. Likewise, it will not step into a function which
3271 is compiled without debugging information. To step through functions
3272 without debugging information, use the @code{stepi} command, described
3273 below.
3274 @end quotation
3275
3276 The @code{step} command only stops at the first instruction of a
3277 source line. This prevents the multiple stops that could otherwise occur in
3278 switch statements, for loops, etc. @code{step} continues to stop if a
3279 function that has debugging information is called within the line.
3280 In other words, @code{step} @emph{steps inside} any functions called
3281 within the line.
3282
3283 Also, the @code{step} command only enters a function if there is line
3284 number information for the function. Otherwise it acts like the
3285 @code{next} command. This avoids problems when using @code{cc -gl}
3286 on MIPS machines. Previously, @code{step} entered subroutines if there
3287 was any debugging information about the routine.
3288
3289 @item step @var{count}
3290 Continue running as in @code{step}, but do so @var{count} times. If a
3291 breakpoint is reached, or a signal not related to stepping occurs before
3292 @var{count} steps, stepping stops right away.
3293
3294 @kindex next
3295 @kindex n
3296 @item next @r{[}@var{count}@r{]}
3297 Continue to the next source line in the current (innermost) stack frame.
3298 This is similar to @code{step}, but function calls that appear within
3299 the line of code are executed without stopping. Execution stops when
3300 control reaches a different line of code at the original stack level
3301 that was executing when you gave the @code{next} command. This command
3302 is abbreviated @code{n}.
3303
3304 An argument @var{count} is a repeat count, as for @code{step}.
3305
3306
3307 @c FIX ME!! Do we delete this, or is there a way it fits in with
3308 @c the following paragraph? --- Vctoria
3309 @c
3310 @c @code{next} within a function that lacks debugging information acts like
3311 @c @code{step}, but any function calls appearing within the code of the
3312 @c function are executed without stopping.
3313
3314 The @code{next} command only stops at the first instruction of a
3315 source line. This prevents multiple stops that could otherwise occur in
3316 switch statements, for loops, etc.
3317
3318 @kindex finish
3319 @item finish
3320 Continue running until just after function in the selected stack frame
3321 returns. Print the returned value (if any).
3322
3323 Contrast this with the @code{return} command (@pxref{Returning,
3324 ,Returning from a function}).
3325
3326 @kindex until
3327 @kindex u
3328 @item until
3329 @itemx u
3330 Continue running until a source line past the current line, in the
3331 current stack frame, is reached. This command is used to avoid single
3332 stepping through a loop more than once. It is like the @code{next}
3333 command, except that when @code{until} encounters a jump, it
3334 automatically continues execution until the program counter is greater
3335 than the address of the jump.
3336
3337 This means that when you reach the end of a loop after single stepping
3338 though it, @code{until} makes your program continue execution until it
3339 exits the loop. In contrast, a @code{next} command at the end of a loop
3340 simply steps back to the beginning of the loop, which forces you to step
3341 through the next iteration.
3342
3343 @code{until} always stops your program if it attempts to exit the current
3344 stack frame.
3345
3346 @code{until} may produce somewhat counterintuitive results if the order
3347 of machine code does not match the order of the source lines. For
3348 example, in the following excerpt from a debugging session, the @code{f}
3349 (@code{frame}) command shows that execution is stopped at line
3350 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3351
3352 @example
3353 (@value{GDBP}) f
3354 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3355 206 expand_input();
3356 (@value{GDBP}) until
3357 195 for ( ; argc > 0; NEXTARG) @{
3358 @end example
3359
3360 This happened because, for execution efficiency, the compiler had
3361 generated code for the loop closure test at the end, rather than the
3362 start, of the loop---even though the test in a C @code{for}-loop is
3363 written before the body of the loop. The @code{until} command appeared
3364 to step back to the beginning of the loop when it advanced to this
3365 expression; however, it has not really gone to an earlier
3366 statement---not in terms of the actual machine code.
3367
3368 @code{until} with no argument works by means of single
3369 instruction stepping, and hence is slower than @code{until} with an
3370 argument.
3371
3372 @item until @var{location}
3373 @itemx u @var{location}
3374 Continue running your program until either the specified location is
3375 reached, or the current stack frame returns. @var{location} is any of
3376 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3377 ,Setting breakpoints}). This form of the command uses breakpoints,
3378 and hence is quicker than @code{until} without an argument.
3379
3380 @kindex stepi
3381 @kindex si
3382 @item stepi
3383 @itemx stepi @var{arg}
3384 @itemx si
3385 Execute one machine instruction, then stop and return to the debugger.
3386
3387 It is often useful to do @samp{display/i $pc} when stepping by machine
3388 instructions. This makes @value{GDBN} automatically display the next
3389 instruction to be executed, each time your program stops. @xref{Auto
3390 Display,, Automatic display}.
3391
3392 An argument is a repeat count, as in @code{step}.
3393
3394 @need 750
3395 @kindex nexti
3396 @kindex ni
3397 @item nexti
3398 @itemx nexti @var{arg}
3399 @itemx ni
3400 Execute one machine instruction, but if it is a function call,
3401 proceed until the function returns.
3402
3403 An argument is a repeat count, as in @code{next}.
3404 @end table
3405
3406 @node Signals
3407 @section Signals
3408 @cindex signals
3409
3410 A signal is an asynchronous event that can happen in a program. The
3411 operating system defines the possible kinds of signals, and gives each
3412 kind a name and a number. For example, in Unix @code{SIGINT} is the
3413 signal a program gets when you type an interrupt character (often @kbd{C-c});
3414 @code{SIGSEGV} is the signal a program gets from referencing a place in
3415 memory far away from all the areas in use; @code{SIGALRM} occurs when
3416 the alarm clock timer goes off (which happens only if your program has
3417 requested an alarm).
3418
3419 @cindex fatal signals
3420 Some signals, including @code{SIGALRM}, are a normal part of the
3421 functioning of your program. Others, such as @code{SIGSEGV}, indicate
3422 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
3423 program has not specified in advance some other way to handle the signal.
3424 @code{SIGINT} does not indicate an error in your program, but it is normally
3425 fatal so it can carry out the purpose of the interrupt: to kill the program.
3426
3427 @value{GDBN} has the ability to detect any occurrence of a signal in your
3428 program. You can tell @value{GDBN} in advance what to do for each kind of
3429 signal.
3430
3431 @cindex handling signals
3432 Normally, @value{GDBN} is set up to ignore non-erroneous signals like @code{SIGALRM}
3433 (so as not to interfere with their role in the functioning of your program)
3434 but to stop your program immediately whenever an error signal happens.
3435 You can change these settings with the @code{handle} command.
3436
3437 @table @code
3438 @kindex info signals
3439 @item info signals
3440 @itemx info handle
3441 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3442 handle each one. You can use this to see the signal numbers of all
3443 the defined types of signals.
3444
3445 @code{info handle} is an alias for @code{info signals}.
3446
3447 @kindex handle
3448 @item handle @var{signal} @var{keywords}@dots{}
3449 Change the way @value{GDBN} handles signal @var{signal}. @var{signal} can
3450 be the number of a signal or its name (with or without the @samp{SIG} at the
3451 beginning). The @var{keywords} say what change to make.
3452 @end table
3453
3454 @c @group
3455 The keywords allowed by the @code{handle} command can be abbreviated.
3456 Their full names are:
3457
3458 @table @code
3459 @item nostop
3460 @value{GDBN} should not stop your program when this signal happens. It may
3461 still print a message telling you that the signal has come in.
3462
3463 @item stop
3464 @value{GDBN} should stop your program when this signal happens. This implies
3465 the @code{print} keyword as well.
3466
3467 @item print
3468 @value{GDBN} should print a message when this signal happens.
3469
3470 @item noprint
3471 @value{GDBN} should not mention the occurrence of the signal at all. This
3472 implies the @code{nostop} keyword as well.
3473
3474 @item pass
3475 @value{GDBN} should allow your program to see this signal; your program
3476 can handle the signal, or else it may terminate if the signal is fatal
3477 and not handled.
3478
3479 @item nopass
3480 @value{GDBN} should not allow your program to see this signal.
3481 @end table
3482 @c @end group
3483
3484 When a signal stops your program, the signal is not visible to the
3485 program until you
3486 continue. Your program sees the signal then, if @code{pass} is in
3487 effect for the signal in question @emph{at that time}. In other words,
3488 after @value{GDBN} reports a signal, you can use the @code{handle}
3489 command with @code{pass} or @code{nopass} to control whether your
3490 program sees that signal when you continue.
3491
3492 You can also use the @code{signal} command to prevent your program from
3493 seeing a signal, or cause it to see a signal it normally would not see,
3494 or to give it any signal at any time. For example, if your program stopped
3495 due to some sort of memory reference error, you might store correct
3496 values into the erroneous variables and continue, hoping to see more
3497 execution; but your program would probably terminate immediately as
3498 a result of the fatal signal once it saw the signal. To prevent this,
3499 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3500 program a signal}.
3501
3502 @node Thread Stops
3503 @section Stopping and starting multi-thread programs
3504
3505 When your program has multiple threads (@pxref{Threads,, Debugging
3506 programs with multiple threads}), you can choose whether to set
3507 breakpoints on all threads, or on a particular thread.
3508
3509 @table @code
3510 @cindex breakpoints and threads
3511 @cindex thread breakpoints
3512 @kindex break @dots{} thread @var{threadno}
3513 @item break @var{linespec} thread @var{threadno}
3514 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3515 @var{linespec} specifies source lines; there are several ways of
3516 writing them, but the effect is always to specify some source line.
3517
3518 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3519 to specify that you only want @value{GDBN} to stop the program when a
3520 particular thread reaches this breakpoint. @var{threadno} is one of the
3521 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3522 column of the @samp{info threads} display.
3523
3524 If you do not specify @samp{thread @var{threadno}} when you set a
3525 breakpoint, the breakpoint applies to @emph{all} threads of your
3526 program.
3527
3528 You can use the @code{thread} qualifier on conditional breakpoints as
3529 well; in this case, place @samp{thread @var{threadno}} before the
3530 breakpoint condition, like this:
3531
3532 @smallexample
3533 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
3534 @end smallexample
3535
3536 @end table
3537
3538 @cindex stopped threads
3539 @cindex threads, stopped
3540 Whenever your program stops under @value{GDBN} for any reason,
3541 @emph{all} threads of execution stop, not just the current thread. This
3542 allows you to examine the overall state of the program, including
3543 switching between threads, without worrying that things may change
3544 underfoot.
3545
3546 @cindex continuing threads
3547 @cindex threads, continuing
3548 Conversely, whenever you restart the program, @emph{all} threads start
3549 executing. @emph{This is true even when single-stepping} with commands
3550 like @code{step} or @code{next}.
3551
3552 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3553 Since thread scheduling is up to your debugging target's operating
3554 system (not controlled by @value{GDBN}), other threads may
3555 execute more than one statement while the current thread completes a
3556 single step. Moreover, in general other threads stop in the middle of a
3557 statement, rather than at a clean statement boundary, when the program
3558 stops.
3559
3560 You might even find your program stopped in another thread after
3561 continuing or even single-stepping. This happens whenever some other
3562 thread runs into a breakpoint, a signal, or an exception before the
3563 first thread completes whatever you requested.
3564
3565 On some OSes, you can lock the OS scheduler and thus allow only a single
3566 thread to run.
3567
3568 @table @code
3569 @item set scheduler-locking @var{mode}
3570 Set the scheduler locking mode. If it is @code{off}, then there is no
3571 locking and any thread may run at any time. If @code{on}, then only the
3572 current thread may run when the inferior is resumed. The @code{step}
3573 mode optimizes for single-stepping. It stops other threads from
3574 ``seizing the prompt'' by preempting the current thread while you are
3575 stepping. Other threads will only rarely (or never) get a chance to run
3576 when you step. They are more likely to run when you @samp{next} over a
3577 function call, and they are completely free to run when you use commands
3578 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
3579 thread hits a breakpoint during its timeslice, they will never steal the
3580 @value{GDBN} prompt away from the thread that you are debugging.
3581
3582 @item show scheduler-locking
3583 Display the current scheduler locking mode.
3584 @end table
3585
3586
3587 @node Stack
3588 @chapter Examining the Stack
3589
3590 When your program has stopped, the first thing you need to know is where it
3591 stopped and how it got there.
3592
3593 @cindex call stack
3594 Each time your program performs a function call, information about the call
3595 is generated.
3596 That information includes the location of the call in your program,
3597 the arguments of the call,
3598 and the local variables of the function being called.
3599 The information is saved in a block of data called a @dfn{stack frame}.
3600 The stack frames are allocated in a region of memory called the @dfn{call
3601 stack}.
3602
3603 When your program stops, the @value{GDBN} commands for examining the
3604 stack allow you to see all of this information.
3605
3606 @cindex selected frame
3607 One of the stack frames is @dfn{selected} by @value{GDBN} and many
3608 @value{GDBN} commands refer implicitly to the selected frame. In
3609 particular, whenever you ask @value{GDBN} for the value of a variable in
3610 your program, the value is found in the selected frame. There are
3611 special @value{GDBN} commands to select whichever frame you are
3612 interested in. @xref{Selection, ,Selecting a frame}.
3613
3614 When your program stops, @value{GDBN} automatically selects the
3615 currently executing frame and describes it briefly, similar to the
3616 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3617
3618 @menu
3619 * Frames:: Stack frames
3620 * Backtrace:: Backtraces
3621 * Selection:: Selecting a frame
3622 * Frame Info:: Information on a frame
3623
3624 @end menu
3625
3626 @node Frames
3627 @section Stack frames
3628
3629 @cindex frame, definition
3630 @cindex stack frame
3631 The call stack is divided up into contiguous pieces called @dfn{stack
3632 frames}, or @dfn{frames} for short; each frame is the data associated
3633 with one call to one function. The frame contains the arguments given
3634 to the function, the function's local variables, and the address at
3635 which the function is executing.
3636
3637 @cindex initial frame
3638 @cindex outermost frame
3639 @cindex innermost frame
3640 When your program is started, the stack has only one frame, that of the
3641 function @code{main}. This is called the @dfn{initial} frame or the
3642 @dfn{outermost} frame. Each time a function is called, a new frame is
3643 made. Each time a function returns, the frame for that function invocation
3644 is eliminated. If a function is recursive, there can be many frames for
3645 the same function. The frame for the function in which execution is
3646 actually occurring is called the @dfn{innermost} frame. This is the most
3647 recently created of all the stack frames that still exist.
3648
3649 @cindex frame pointer
3650 Inside your program, stack frames are identified by their addresses. A
3651 stack frame consists of many bytes, each of which has its own address; each
3652 kind of computer has a convention for choosing one byte whose
3653 address serves as the address of the frame. Usually this address is kept
3654 in a register called the @dfn{frame pointer register} while execution is
3655 going on in that frame.
3656
3657 @cindex frame number
3658 @value{GDBN} assigns numbers to all existing stack frames, starting with
3659 zero for the innermost frame, one for the frame that called it,
3660 and so on upward. These numbers do not really exist in your program;
3661 they are assigned by @value{GDBN} to give you a way of designating stack
3662 frames in @value{GDBN} commands.
3663
3664 @c The -fomit-frame-pointer below perennially causes hbox overflow
3665 @c underflow problems.
3666 @cindex frameless execution
3667 Some compilers provide a way to compile functions so that they operate
3668 without stack frames. (For example, the @value{GCC} option
3669 @example
3670 @samp{-fomit-frame-pointer}
3671 @end example
3672 generates functions without a frame.)
3673 This is occasionally done with heavily used library functions to save
3674 the frame setup time. @value{GDBN} has limited facilities for dealing
3675 with these function invocations. If the innermost function invocation
3676 has no stack frame, @value{GDBN} nevertheless regards it as though
3677 it had a separate frame, which is numbered zero as usual, allowing
3678 correct tracing of the function call chain. However, @value{GDBN} has
3679 no provision for frameless functions elsewhere in the stack.
3680
3681 @table @code
3682 @kindex frame@r{, command}
3683 @item frame @var{args}
3684 The @code{frame} command allows you to move from one stack frame to another,
3685 and to print the stack frame you select. @var{args} may be either the
3686 address of the frame or the stack frame number. Without an argument,
3687 @code{frame} prints the current stack frame.
3688
3689 @kindex select-frame
3690 @item select-frame
3691 The @code{select-frame} command allows you to move from one stack frame
3692 to another without printing the frame. This is the silent version of
3693 @code{frame}.
3694 @end table
3695
3696 @node Backtrace
3697 @section Backtraces
3698
3699 @cindex backtraces
3700 @cindex tracebacks
3701 @cindex stack traces
3702 A backtrace is a summary of how your program got where it is. It shows one
3703 line per frame, for many frames, starting with the currently executing
3704 frame (frame zero), followed by its caller (frame one), and on up the
3705 stack.
3706
3707 @table @code
3708 @kindex backtrace
3709 @kindex bt
3710 @item backtrace
3711 @itemx bt
3712 Print a backtrace of the entire stack: one line per frame for all
3713 frames in the stack.
3714
3715 You can stop the backtrace at any time by typing the system interrupt
3716 character, normally @kbd{C-c}.
3717
3718 @item backtrace @var{n}
3719 @itemx bt @var{n}
3720 Similar, but print only the innermost @var{n} frames.
3721
3722 @item backtrace -@var{n}
3723 @itemx bt -@var{n}
3724 Similar, but print only the outermost @var{n} frames.
3725 @end table
3726
3727 @kindex where
3728 @kindex info stack
3729 @kindex info s
3730 The names @code{where} and @code{info stack} (abbreviated @code{info s})
3731 are additional aliases for @code{backtrace}.
3732
3733 Each line in the backtrace shows the frame number and the function name.
3734 The program counter value is also shown---unless you use @code{set
3735 print address off}. The backtrace also shows the source file name and
3736 line number, as well as the arguments to the function. The program
3737 counter value is omitted if it is at the beginning of the code for that
3738 line number.
3739
3740 Here is an example of a backtrace. It was made with the command
3741 @samp{bt 3}, so it shows the innermost three frames.
3742
3743 @smallexample
3744 @group
3745 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3746 at builtin.c:993
3747 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3748 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3749 at macro.c:71
3750 (More stack frames follow...)
3751 @end group
3752 @end smallexample
3753
3754 @noindent
3755 The display for frame zero does not begin with a program counter
3756 value, indicating that your program has stopped at the beginning of the
3757 code for line @code{993} of @code{builtin.c}.
3758
3759 @node Selection
3760 @section Selecting a frame
3761
3762 Most commands for examining the stack and other data in your program work on
3763 whichever stack frame is selected at the moment. Here are the commands for
3764 selecting a stack frame; all of them finish by printing a brief description
3765 of the stack frame just selected.
3766
3767 @table @code
3768 @kindex frame@r{, selecting}
3769 @kindex f
3770 @item frame @var{n}
3771 @itemx f @var{n}
3772 Select frame number @var{n}. Recall that frame zero is the innermost
3773 (currently executing) frame, frame one is the frame that called the
3774 innermost one, and so on. The highest-numbered frame is the one for
3775 @code{main}.
3776
3777 @item frame @var{addr}
3778 @itemx f @var{addr}
3779 Select the frame at address @var{addr}. This is useful mainly if the
3780 chaining of stack frames has been damaged by a bug, making it
3781 impossible for @value{GDBN} to assign numbers properly to all frames. In
3782 addition, this can be useful when your program has multiple stacks and
3783 switches between them.
3784
3785 On the SPARC architecture, @code{frame} needs two addresses to
3786 select an arbitrary frame: a frame pointer and a stack pointer.
3787
3788 On the MIPS and Alpha architecture, it needs two addresses: a stack
3789 pointer and a program counter.
3790
3791 On the 29k architecture, it needs three addresses: a register stack
3792 pointer, a program counter, and a memory stack pointer.
3793 @c note to future updaters: this is conditioned on a flag
3794 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
3795 @c as of 27 Jan 1994.
3796
3797 @kindex up
3798 @item up @var{n}
3799 Move @var{n} frames up the stack. For positive numbers @var{n}, this
3800 advances toward the outermost frame, to higher frame numbers, to frames
3801 that have existed longer. @var{n} defaults to one.
3802
3803 @kindex down
3804 @kindex do
3805 @item down @var{n}
3806 Move @var{n} frames down the stack. For positive numbers @var{n}, this
3807 advances toward the innermost frame, to lower frame numbers, to frames
3808 that were created more recently. @var{n} defaults to one. You may
3809 abbreviate @code{down} as @code{do}.
3810 @end table
3811
3812 All of these commands end by printing two lines of output describing the
3813 frame. The first line shows the frame number, the function name, the
3814 arguments, and the source file and line number of execution in that
3815 frame. The second line shows the text of that source line.
3816
3817 @need 1000
3818 For example:
3819
3820 @smallexample
3821 @group
3822 (@value{GDBP}) up
3823 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3824 at env.c:10
3825 10 read_input_file (argv[i]);
3826 @end group
3827 @end smallexample
3828
3829 After such a printout, the @code{list} command with no arguments
3830 prints ten lines centered on the point of execution in the frame.
3831 @xref{List, ,Printing source lines}.
3832
3833 @table @code
3834 @kindex down-silently
3835 @kindex up-silently
3836 @item up-silently @var{n}
3837 @itemx down-silently @var{n}
3838 These two commands are variants of @code{up} and @code{down},
3839 respectively; they differ in that they do their work silently, without
3840 causing display of the new frame. They are intended primarily for use
3841 in @value{GDBN} command scripts, where the output might be unnecessary and
3842 distracting.
3843 @end table
3844
3845 @node Frame Info
3846 @section Information about a frame
3847
3848 There are several other commands to print information about the selected
3849 stack frame.
3850
3851 @table @code
3852 @item frame
3853 @itemx f
3854 When used without any argument, this command does not change which
3855 frame is selected, but prints a brief description of the currently
3856 selected stack frame. It can be abbreviated @code{f}. With an
3857 argument, this command is used to select a stack frame.
3858 @xref{Selection, ,Selecting a frame}.
3859
3860 @kindex info frame
3861 @kindex info f
3862 @item info frame
3863 @itemx info f
3864 This command prints a verbose description of the selected stack frame,
3865 including:
3866
3867 @itemize @bullet
3868 @item
3869 the address of the frame
3870 @item
3871 the address of the next frame down (called by this frame)
3872 @item
3873 the address of the next frame up (caller of this frame)
3874 @item
3875 the language in which the source code corresponding to this frame is written
3876 @item
3877 the address of the frame's arguments
3878 @item
3879 the address of the frame's local variables
3880 @item
3881 the program counter saved in it (the address of execution in the caller frame)
3882 @item
3883 which registers were saved in the frame
3884 @end itemize
3885
3886 @noindent The verbose description is useful when
3887 something has gone wrong that has made the stack format fail to fit
3888 the usual conventions.
3889
3890 @item info frame @var{addr}
3891 @itemx info f @var{addr}
3892 Print a verbose description of the frame at address @var{addr}, without
3893 selecting that frame. The selected frame remains unchanged by this
3894 command. This requires the same kind of address (more than one for some
3895 architectures) that you specify in the @code{frame} command.
3896 @xref{Selection, ,Selecting a frame}.
3897
3898 @kindex info args
3899 @item info args
3900 Print the arguments of the selected frame, each on a separate line.
3901
3902 @item info locals
3903 @kindex info locals
3904 Print the local variables of the selected frame, each on a separate
3905 line. These are all variables (declared either static or automatic)
3906 accessible at the point of execution of the selected frame.
3907
3908 @kindex info catch
3909 @cindex catch exceptions, list active handlers
3910 @cindex exception handlers, how to list
3911 @item info catch
3912 Print a list of all the exception handlers that are active in the
3913 current stack frame at the current point of execution. To see other
3914 exception handlers, visit the associated frame (using the @code{up},
3915 @code{down}, or @code{frame} commands); then type @code{info catch}.
3916 @xref{Set Catchpoints, , Setting catchpoints}.
3917
3918 @end table
3919
3920
3921 @node Source
3922 @chapter Examining Source Files
3923
3924 @value{GDBN} can print parts of your program's source, since the debugging
3925 information recorded in the program tells @value{GDBN} what source files were
3926 used to build it. When your program stops, @value{GDBN} spontaneously prints
3927 the line where it stopped. Likewise, when you select a stack frame
3928 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
3929 execution in that frame has stopped. You can print other portions of
3930 source files by explicit command.
3931
3932 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
3933 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
3934 @value{GDBN} under @sc{gnu} Emacs}.
3935
3936 @menu
3937 * List:: Printing source lines
3938 * Search:: Searching source files
3939 * Source Path:: Specifying source directories
3940 * Machine Code:: Source and machine code
3941 @end menu
3942
3943 @node List
3944 @section Printing source lines
3945
3946 @kindex list
3947 @kindex l
3948 To print lines from a source file, use the @code{list} command
3949 (abbreviated @code{l}). By default, ten lines are printed.
3950 There are several ways to specify what part of the file you want to print.
3951
3952 Here are the forms of the @code{list} command most commonly used:
3953
3954 @table @code
3955 @item list @var{linenum}
3956 Print lines centered around line number @var{linenum} in the
3957 current source file.
3958
3959 @item list @var{function}
3960 Print lines centered around the beginning of function
3961 @var{function}.
3962
3963 @item list
3964 Print more lines. If the last lines printed were printed with a
3965 @code{list} command, this prints lines following the last lines
3966 printed; however, if the last line printed was a solitary line printed
3967 as part of displaying a stack frame (@pxref{Stack, ,Examining the
3968 Stack}), this prints lines centered around that line.
3969
3970 @item list -
3971 Print lines just before the lines last printed.
3972 @end table
3973
3974 By default, @value{GDBN} prints ten source lines with any of these forms of
3975 the @code{list} command. You can change this using @code{set listsize}:
3976
3977 @table @code
3978 @kindex set listsize
3979 @item set listsize @var{count}
3980 Make the @code{list} command display @var{count} source lines (unless
3981 the @code{list} argument explicitly specifies some other number).
3982
3983 @kindex show listsize
3984 @item show listsize
3985 Display the number of lines that @code{list} prints.
3986 @end table
3987
3988 Repeating a @code{list} command with @key{RET} discards the argument,
3989 so it is equivalent to typing just @code{list}. This is more useful
3990 than listing the same lines again. An exception is made for an
3991 argument of @samp{-}; that argument is preserved in repetition so that
3992 each repetition moves up in the source file.
3993
3994 @cindex linespec
3995 In general, the @code{list} command expects you to supply zero, one or two
3996 @dfn{linespecs}. Linespecs specify source lines; there are several ways
3997 of writing them, but the effect is always to specify some source line.
3998 Here is a complete description of the possible arguments for @code{list}:
3999
4000 @table @code
4001 @item list @var{linespec}
4002 Print lines centered around the line specified by @var{linespec}.
4003
4004 @item list @var{first},@var{last}
4005 Print lines from @var{first} to @var{last}. Both arguments are
4006 linespecs.
4007
4008 @item list ,@var{last}
4009 Print lines ending with @var{last}.
4010
4011 @item list @var{first},
4012 Print lines starting with @var{first}.
4013
4014 @item list +
4015 Print lines just after the lines last printed.
4016
4017 @item list -
4018 Print lines just before the lines last printed.
4019
4020 @item list
4021 As described in the preceding table.
4022 @end table
4023
4024 Here are the ways of specifying a single source line---all the
4025 kinds of linespec.
4026
4027 @table @code
4028 @item @var{number}
4029 Specifies line @var{number} of the current source file.
4030 When a @code{list} command has two linespecs, this refers to
4031 the same source file as the first linespec.
4032
4033 @item +@var{offset}
4034 Specifies the line @var{offset} lines after the last line printed.
4035 When used as the second linespec in a @code{list} command that has
4036 two, this specifies the line @var{offset} lines down from the
4037 first linespec.
4038
4039 @item -@var{offset}
4040 Specifies the line @var{offset} lines before the last line printed.
4041
4042 @item @var{filename}:@var{number}
4043 Specifies line @var{number} in the source file @var{filename}.
4044
4045 @item @var{function}
4046 Specifies the line that begins the body of the function @var{function}.
4047 For example: in C, this is the line with the open brace.
4048
4049 @item @var{filename}:@var{function}
4050 Specifies the line of the open-brace that begins the body of the
4051 function @var{function} in the file @var{filename}. You only need the
4052 file name with a function name to avoid ambiguity when there are
4053 identically named functions in different source files.
4054
4055 @item *@var{address}
4056 Specifies the line containing the program address @var{address}.
4057 @var{address} may be any expression.
4058 @end table
4059
4060 @node Search
4061 @section Searching source files
4062 @cindex searching
4063 @kindex reverse-search
4064
4065 There are two commands for searching through the current source file for a
4066 regular expression.
4067
4068 @table @code
4069 @kindex search
4070 @kindex forward-search
4071 @item forward-search @var{regexp}
4072 @itemx search @var{regexp}
4073 The command @samp{forward-search @var{regexp}} checks each line,
4074 starting with the one following the last line listed, for a match for
4075 @var{regexp}. It lists the line that is found. You can use the
4076 synonym @samp{search @var{regexp}} or abbreviate the command name as
4077 @code{fo}.
4078
4079 @item reverse-search @var{regexp}
4080 The command @samp{reverse-search @var{regexp}} checks each line, starting
4081 with the one before the last line listed and going backward, for a match
4082 for @var{regexp}. It lists the line that is found. You can abbreviate
4083 this command as @code{rev}.
4084 @end table
4085
4086 @node Source Path
4087 @section Specifying source directories
4088
4089 @cindex source path
4090 @cindex directories for source files
4091 Executable programs sometimes do not record the directories of the source
4092 files from which they were compiled, just the names. Even when they do,
4093 the directories could be moved between the compilation and your debugging
4094 session. @value{GDBN} has a list of directories to search for source files;
4095 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4096 it tries all the directories in the list, in the order they are present
4097 in the list, until it finds a file with the desired name. Note that
4098 the executable search path is @emph{not} used for this purpose. Neither is
4099 the current working directory, unless it happens to be in the source
4100 path.
4101
4102 If @value{GDBN} cannot find a source file in the source path, and the
4103 object program records a directory, @value{GDBN} tries that directory
4104 too. If the source path is empty, and there is no record of the
4105 compilation directory, @value{GDBN} looks in the current directory as a
4106 last resort.
4107
4108 Whenever you reset or rearrange the source path, @value{GDBN} clears out
4109 any information it has cached about where source files are found and where
4110 each line is in the file.
4111
4112 @kindex directory
4113 @kindex dir
4114 When you start @value{GDBN}, its source path includes only @samp{cdir}
4115 and @samp{cwd}, in that order.
4116 To add other directories, use the @code{directory} command.
4117
4118 @table @code
4119 @item directory @var{dirname} @dots{}
4120 @item dir @var{dirname} @dots{}
4121 Add directory @var{dirname} to the front of the source path. Several
4122 directory names may be given to this command, separated by @samp{:}
4123 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4124 part of absolute file names) or
4125 whitespace. You may specify a directory that is already in the source
4126 path; this moves it forward, so @value{GDBN} searches it sooner.
4127
4128 @kindex cdir
4129 @kindex cwd
4130 @kindex $cdir
4131 @kindex $cwd
4132 @cindex compilation directory
4133 @cindex current directory
4134 @cindex working directory
4135 @cindex directory, current
4136 @cindex directory, compilation
4137 You can use the string @samp{$cdir} to refer to the compilation
4138 directory (if one is recorded), and @samp{$cwd} to refer to the current
4139 working directory. @samp{$cwd} is not the same as @samp{.}---the former
4140 tracks the current working directory as it changes during your @value{GDBN}
4141 session, while the latter is immediately expanded to the current
4142 directory at the time you add an entry to the source path.
4143
4144 @item directory
4145 Reset the source path to empty again. This requires confirmation.
4146
4147 @c RET-repeat for @code{directory} is explicitly disabled, but since
4148 @c repeating it would be a no-op we do not say that. (thanks to RMS)
4149
4150 @item show directories
4151 @kindex show directories
4152 Print the source path: show which directories it contains.
4153 @end table
4154
4155 If your source path is cluttered with directories that are no longer of
4156 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4157 versions of source. You can correct the situation as follows:
4158
4159 @enumerate
4160 @item
4161 Use @code{directory} with no argument to reset the source path to empty.
4162
4163 @item
4164 Use @code{directory} with suitable arguments to reinstall the
4165 directories you want in the source path. You can add all the
4166 directories in one command.
4167 @end enumerate
4168
4169 @node Machine Code
4170 @section Source and machine code
4171
4172 You can use the command @code{info line} to map source lines to program
4173 addresses (and vice versa), and the command @code{disassemble} to display
4174 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
4175 mode, the @code{info line} command causes the arrow to point to the
4176 line specified. Also, @code{info line} prints addresses in symbolic form as
4177 well as hex.
4178
4179 @table @code
4180 @kindex info line
4181 @item info line @var{linespec}
4182 Print the starting and ending addresses of the compiled code for
4183 source line @var{linespec}. You can specify source lines in any of
4184 the ways understood by the @code{list} command (@pxref{List, ,Printing
4185 source lines}).
4186 @end table
4187
4188 For example, we can use @code{info line} to discover the location of
4189 the object code for the first line of function
4190 @code{m4_changequote}:
4191
4192 @c FIXME: I think this example should also show the addresses in
4193 @c symbolic form, as they usually would be displayed.
4194 @smallexample
4195 (@value{GDBP}) info line m4_changequote
4196 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4197 @end smallexample
4198
4199 @noindent
4200 We can also inquire (using @code{*@var{addr}} as the form for
4201 @var{linespec}) what source line covers a particular address:
4202 @smallexample
4203 (@value{GDBP}) info line *0x63ff
4204 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4205 @end smallexample
4206
4207 @cindex @code{$_} and @code{info line}
4208 @kindex x@r{, and }@code{info line}
4209 After @code{info line}, the default address for the @code{x} command
4210 is changed to the starting address of the line, so that @samp{x/i} is
4211 sufficient to begin examining the machine code (@pxref{Memory,
4212 ,Examining memory}). Also, this address is saved as the value of the
4213 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4214 variables}).
4215
4216 @table @code
4217 @kindex disassemble
4218 @cindex assembly instructions
4219 @cindex instructions, assembly
4220 @cindex machine instructions
4221 @cindex listing machine instructions
4222 @item disassemble
4223 This specialized command dumps a range of memory as machine
4224 instructions. The default memory range is the function surrounding the
4225 program counter of the selected frame. A single argument to this
4226 command is a program counter value; @value{GDBN} dumps the function
4227 surrounding this value. Two arguments specify a range of addresses
4228 (first inclusive, second exclusive) to dump.
4229 @end table
4230
4231 The following example shows the disassembly of a range of addresses of
4232 HP PA-RISC 2.0 code:
4233
4234 @smallexample
4235 (@value{GDBP}) disas 0x32c4 0x32e4
4236 Dump of assembler code from 0x32c4 to 0x32e4:
4237 0x32c4 <main+204>: addil 0,dp
4238 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
4239 0x32cc <main+212>: ldil 0x3000,r31
4240 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
4241 0x32d4 <main+220>: ldo 0(r31),rp
4242 0x32d8 <main+224>: addil -0x800,dp
4243 0x32dc <main+228>: ldo 0x588(r1),r26
4244 0x32e0 <main+232>: ldil 0x3000,r31
4245 End of assembler dump.
4246 @end smallexample
4247
4248 Some architectures have more than one commonly-used set of instruction
4249 mnemonics or other syntax.
4250
4251 @table @code
4252 @kindex set disassembly-flavor
4253 @cindex assembly instructions
4254 @cindex instructions, assembly
4255 @cindex machine instructions
4256 @cindex listing machine instructions
4257 @cindex Intel disassembly flavor
4258 @cindex AT&T disassembly flavor
4259 @item set disassembly-flavor @var{instruction-set}
4260 Select the instruction set to use when disassembling the
4261 program via the @code{disassemble} or @code{x/i} commands.
4262
4263 Currently this command is only defined for the Intel x86 family. You
4264 can set @var{instruction-set} to either @code{intel} or @code{att}.
4265 The default is @code{att}, the AT&T flavor used by default by Unix
4266 assemblers for x86-based targets.
4267 @end table
4268
4269
4270 @node Data
4271 @chapter Examining Data
4272
4273 @cindex printing data
4274 @cindex examining data
4275 @kindex print
4276 @kindex inspect
4277 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
4278 @c document because it is nonstandard... Under Epoch it displays in a
4279 @c different window or something like that.
4280 The usual way to examine data in your program is with the @code{print}
4281 command (abbreviated @code{p}), or its synonym @code{inspect}. It
4282 evaluates and prints the value of an expression of the language your
4283 program is written in (@pxref{Languages, ,Using @value{GDBN} with
4284 Different Languages}).
4285
4286 @table @code
4287 @item print @var{expr}
4288 @itemx print /@var{f} @var{expr}
4289 @var{expr} is an expression (in the source language). By default the
4290 value of @var{expr} is printed in a format appropriate to its data type;
4291 you can choose a different format by specifying @samp{/@var{f}}, where
4292 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
4293 formats}.
4294
4295 @item print
4296 @itemx print /@var{f}
4297 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
4298 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4299 conveniently inspect the same value in an alternative format.
4300 @end table
4301
4302 A more low-level way of examining data is with the @code{x} command.
4303 It examines data in memory at a specified address and prints it in a
4304 specified format. @xref{Memory, ,Examining memory}.
4305
4306 If you are interested in information about types, or about how the
4307 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4308 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
4309 Table}.
4310
4311 @menu
4312 * Expressions:: Expressions
4313 * Variables:: Program variables
4314 * Arrays:: Artificial arrays
4315 * Output Formats:: Output formats
4316 * Memory:: Examining memory
4317 * Auto Display:: Automatic display
4318 * Print Settings:: Print settings
4319 * Value History:: Value history
4320 * Convenience Vars:: Convenience variables
4321 * Registers:: Registers
4322 * Floating Point Hardware:: Floating point hardware
4323 @end menu
4324
4325 @node Expressions
4326 @section Expressions
4327
4328 @cindex expressions
4329 @code{print} and many other @value{GDBN} commands accept an expression and
4330 compute its value. Any kind of constant, variable or operator defined
4331 by the programming language you are using is valid in an expression in
4332 @value{GDBN}. This includes conditional expressions, function calls, casts
4333 and string constants. It unfortunately does not include symbols defined
4334 by preprocessor @code{#define} commands.
4335
4336 @value{GDBN} supports array constants in expressions input by
4337 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
4338 you can use the command @code{print @{1, 2, 3@}} to build up an array in
4339 memory that is @code{malloc}ed in the target program.
4340
4341 Because C is so widespread, most of the expressions shown in examples in
4342 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4343 Languages}, for information on how to use expressions in other
4344 languages.
4345
4346 In this section, we discuss operators that you can use in @value{GDBN}
4347 expressions regardless of your programming language.
4348
4349 Casts are supported in all languages, not just in C, because it is so
4350 useful to cast a number into a pointer in order to examine a structure
4351 at that address in memory.
4352 @c FIXME: casts supported---Mod2 true?
4353
4354 @value{GDBN} supports these operators, in addition to those common
4355 to programming languages:
4356
4357 @table @code
4358 @item @@
4359 @samp{@@} is a binary operator for treating parts of memory as arrays.
4360 @xref{Arrays, ,Artificial arrays}, for more information.
4361
4362 @item ::
4363 @samp{::} allows you to specify a variable in terms of the file or
4364 function where it is defined. @xref{Variables, ,Program variables}.
4365
4366 @cindex @{@var{type}@}
4367 @cindex type casting memory
4368 @cindex memory, viewing as typed object
4369 @cindex casts, to view memory
4370 @item @{@var{type}@} @var{addr}
4371 Refers to an object of type @var{type} stored at address @var{addr} in
4372 memory. @var{addr} may be any expression whose value is an integer or
4373 pointer (but parentheses are required around binary operators, just as in
4374 a cast). This construct is allowed regardless of what kind of data is
4375 normally supposed to reside at @var{addr}.
4376 @end table
4377
4378 @node Variables
4379 @section Program variables
4380
4381 The most common kind of expression to use is the name of a variable
4382 in your program.
4383
4384 Variables in expressions are understood in the selected stack frame
4385 (@pxref{Selection, ,Selecting a frame}); they must be either:
4386
4387 @itemize @bullet
4388 @item
4389 global (or file-static)
4390 @end itemize
4391
4392 @noindent or
4393
4394 @itemize @bullet
4395 @item
4396 visible according to the scope rules of the
4397 programming language from the point of execution in that frame
4398 @end itemize
4399
4400 @noindent This means that in the function
4401
4402 @example
4403 foo (a)
4404 int a;
4405 @{
4406 bar (a);
4407 @{
4408 int b = test ();
4409 bar (b);
4410 @}
4411 @}
4412 @end example
4413
4414 @noindent
4415 you can examine and use the variable @code{a} whenever your program is
4416 executing within the function @code{foo}, but you can only use or
4417 examine the variable @code{b} while your program is executing inside
4418 the block where @code{b} is declared.
4419
4420 @cindex variable name conflict
4421 There is an exception: you can refer to a variable or function whose
4422 scope is a single source file even if the current execution point is not
4423 in this file. But it is possible to have more than one such variable or
4424 function with the same name (in different source files). If that
4425 happens, referring to that name has unpredictable effects. If you wish,
4426 you can specify a static variable in a particular function or file,
4427 using the colon-colon notation:
4428
4429 @cindex colon-colon, context for variables/functions
4430 @iftex
4431 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
4432 @kindex ::
4433 @end iftex
4434 @example
4435 @var{file}::@var{variable}
4436 @var{function}::@var{variable}
4437 @end example
4438
4439 @noindent
4440 Here @var{file} or @var{function} is the name of the context for the
4441 static @var{variable}. In the case of file names, you can use quotes to
4442 make sure @value{GDBN} parses the file name as a single word---for example,
4443 to print a global value of @code{x} defined in @file{f2.c}:
4444
4445 @example
4446 (@value{GDBP}) p 'f2.c'::x
4447 @end example
4448
4449 @cindex C++ scope resolution
4450 This use of @samp{::} is very rarely in conflict with the very similar
4451 use of the same notation in C++. @value{GDBN} also supports use of the C++
4452 scope resolution operator in @value{GDBN} expressions.
4453 @c FIXME: Um, so what happens in one of those rare cases where it's in
4454 @c conflict?? --mew
4455
4456 @cindex wrong values
4457 @cindex variable values, wrong
4458 @quotation
4459 @emph{Warning:} Occasionally, a local variable may appear to have the
4460 wrong value at certain points in a function---just after entry to a new
4461 scope, and just before exit.
4462 @end quotation
4463 You may see this problem when you are stepping by machine instructions.
4464 This is because, on most machines, it takes more than one instruction to
4465 set up a stack frame (including local variable definitions); if you are
4466 stepping by machine instructions, variables may appear to have the wrong
4467 values until the stack frame is completely built. On exit, it usually
4468 also takes more than one machine instruction to destroy a stack frame;
4469 after you begin stepping through that group of instructions, local
4470 variable definitions may be gone.
4471
4472 This may also happen when the compiler does significant optimizations.
4473 To be sure of always seeing accurate values, turn off all optimization
4474 when compiling.
4475
4476 @cindex ``No symbol "foo" in current context''
4477 Another possible effect of compiler optimizations is to optimize
4478 unused variables out of existence, or assign variables to registers (as
4479 opposed to memory addresses). Depending on the support for such cases
4480 offered by the debug info format used by the compiler, @value{GDBN}
4481 might not be able to display values for such local variables. If that
4482 happens, @value{GDBN} will print a message like this:
4483
4484 @example
4485 No symbol "foo" in current context.
4486 @end example
4487
4488 To solve such problems, either recompile without optimizations, or use a
4489 different debug info format, if the compiler supports several such
4490 formats. For example, @value{NGCC}, the @sc{gnu} C/C++ compiler usually
4491 supports the @samp{-gstabs} option. @samp{-gstabs} produces debug info
4492 in a format that is superior to formats such as COFF. You may be able
4493 to use DWARF-2 (@samp{-gdwarf-2}), which is also an effective form for
4494 debug info. See @ref{Debugging Options,,Options for Debugging Your
4495 Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}, for more
4496 information.
4497
4498
4499 @node Arrays
4500 @section Artificial arrays
4501
4502 @cindex artificial array
4503 @kindex @@
4504 It is often useful to print out several successive objects of the
4505 same type in memory; a section of an array, or an array of
4506 dynamically determined size for which only a pointer exists in the
4507 program.
4508
4509 You can do this by referring to a contiguous span of memory as an
4510 @dfn{artificial array}, using the binary operator @samp{@@}. The left
4511 operand of @samp{@@} should be the first element of the desired array
4512 and be an individual object. The right operand should be the desired length
4513 of the array. The result is an array value whose elements are all of
4514 the type of the left argument. The first element is actually the left
4515 argument; the second element comes from bytes of memory immediately
4516 following those that hold the first element, and so on. Here is an
4517 example. If a program says
4518
4519 @example
4520 int *array = (int *) malloc (len * sizeof (int));
4521 @end example
4522
4523 @noindent
4524 you can print the contents of @code{array} with
4525
4526 @example
4527 p *array@@len
4528 @end example
4529
4530 The left operand of @samp{@@} must reside in memory. Array values made
4531 with @samp{@@} in this way behave just like other arrays in terms of
4532 subscripting, and are coerced to pointers when used in expressions.
4533 Artificial arrays most often appear in expressions via the value history
4534 (@pxref{Value History, ,Value history}), after printing one out.
4535
4536 Another way to create an artificial array is to use a cast.
4537 This re-interprets a value as if it were an array.
4538 The value need not be in memory:
4539 @example
4540 (@value{GDBP}) p/x (short[2])0x12345678
4541 $1 = @{0x1234, 0x5678@}
4542 @end example
4543
4544 As a convenience, if you leave the array length out (as in
4545 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
4546 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
4547 @example
4548 (@value{GDBP}) p/x (short[])0x12345678
4549 $2 = @{0x1234, 0x5678@}
4550 @end example
4551
4552 Sometimes the artificial array mechanism is not quite enough; in
4553 moderately complex data structures, the elements of interest may not
4554 actually be adjacent---for example, if you are interested in the values
4555 of pointers in an array. One useful work-around in this situation is
4556 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4557 variables}) as a counter in an expression that prints the first
4558 interesting value, and then repeat that expression via @key{RET}. For
4559 instance, suppose you have an array @code{dtab} of pointers to
4560 structures, and you are interested in the values of a field @code{fv}
4561 in each structure. Here is an example of what you might type:
4562
4563 @example
4564 set $i = 0
4565 p dtab[$i++]->fv
4566 @key{RET}
4567 @key{RET}
4568 @dots{}
4569 @end example
4570
4571 @node Output Formats
4572 @section Output formats
4573
4574 @cindex formatted output
4575 @cindex output formats
4576 By default, @value{GDBN} prints a value according to its data type. Sometimes
4577 this is not what you want. For example, you might want to print a number
4578 in hex, or a pointer in decimal. Or you might want to view data in memory
4579 at a certain address as a character string or as an instruction. To do
4580 these things, specify an @dfn{output format} when you print a value.
4581
4582 The simplest use of output formats is to say how to print a value
4583 already computed. This is done by starting the arguments of the
4584 @code{print} command with a slash and a format letter. The format
4585 letters supported are:
4586
4587 @table @code
4588 @item x
4589 Regard the bits of the value as an integer, and print the integer in
4590 hexadecimal.
4591
4592 @item d
4593 Print as integer in signed decimal.
4594
4595 @item u
4596 Print as integer in unsigned decimal.
4597
4598 @item o
4599 Print as integer in octal.
4600
4601 @item t
4602 Print as integer in binary. The letter @samp{t} stands for ``two''.
4603 @footnote{@samp{b} cannot be used because these format letters are also
4604 used with the @code{x} command, where @samp{b} stands for ``byte'';
4605 see @ref{Memory,,Examining memory}.}
4606
4607 @item a
4608 @cindex unknown address, locating
4609 Print as an address, both absolute in hexadecimal and as an offset from
4610 the nearest preceding symbol. You can use this format used to discover
4611 where (in what function) an unknown address is located:
4612
4613 @example
4614 (@value{GDBP}) p/a 0x54320
4615 $3 = 0x54320 <_initialize_vx+396>
4616 @end example
4617
4618 @item c
4619 Regard as an integer and print it as a character constant.
4620
4621 @item f
4622 Regard the bits of the value as a floating point number and print
4623 using typical floating point syntax.
4624 @end table
4625
4626 For example, to print the program counter in hex (@pxref{Registers}), type
4627
4628 @example
4629 p/x $pc
4630 @end example
4631
4632 @noindent
4633 Note that no space is required before the slash; this is because command
4634 names in @value{GDBN} cannot contain a slash.
4635
4636 To reprint the last value in the value history with a different format,
4637 you can use the @code{print} command with just a format and no
4638 expression. For example, @samp{p/x} reprints the last value in hex.
4639
4640 @node Memory
4641 @section Examining memory
4642
4643 You can use the command @code{x} (for ``examine'') to examine memory in
4644 any of several formats, independently of your program's data types.
4645
4646 @cindex examining memory
4647 @table @code
4648 @kindex x
4649 @item x/@var{nfu} @var{addr}
4650 @itemx x @var{addr}
4651 @itemx x
4652 Use the @code{x} command to examine memory.
4653 @end table
4654
4655 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
4656 much memory to display and how to format it; @var{addr} is an
4657 expression giving the address where you want to start displaying memory.
4658 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
4659 Several commands set convenient defaults for @var{addr}.
4660
4661 @table @r
4662 @item @var{n}, the repeat count
4663 The repeat count is a decimal integer; the default is 1. It specifies
4664 how much memory (counting by units @var{u}) to display.
4665 @c This really is **decimal**; unaffected by 'set radix' as of GDB
4666 @c 4.1.2.
4667
4668 @item @var{f}, the display format
4669 The display format is one of the formats used by @code{print},
4670 @samp{s} (null-terminated string), or @samp{i} (machine instruction).
4671 The default is @samp{x} (hexadecimal) initially.
4672 The default changes each time you use either @code{x} or @code{print}.
4673
4674 @item @var{u}, the unit size
4675 The unit size is any of
4676
4677 @table @code
4678 @item b
4679 Bytes.
4680 @item h
4681 Halfwords (two bytes).
4682 @item w
4683 Words (four bytes). This is the initial default.
4684 @item g
4685 Giant words (eight bytes).
4686 @end table
4687
4688 Each time you specify a unit size with @code{x}, that size becomes the
4689 default unit the next time you use @code{x}. (For the @samp{s} and
4690 @samp{i} formats, the unit size is ignored and is normally not written.)
4691
4692 @item @var{addr}, starting display address
4693 @var{addr} is the address where you want @value{GDBN} to begin displaying
4694 memory. The expression need not have a pointer value (though it may);
4695 it is always interpreted as an integer address of a byte of memory.
4696 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
4697 @var{addr} is usually just after the last address examined---but several
4698 other commands also set the default address: @code{info breakpoints} (to
4699 the address of the last breakpoint listed), @code{info line} (to the
4700 starting address of a line), and @code{print} (if you use it to display
4701 a value from memory).
4702 @end table
4703
4704 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
4705 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
4706 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
4707 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
4708 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
4709
4710 Since the letters indicating unit sizes are all distinct from the
4711 letters specifying output formats, you do not have to remember whether
4712 unit size or format comes first; either order works. The output
4713 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
4714 (However, the count @var{n} must come first; @samp{wx4} does not work.)
4715
4716 Even though the unit size @var{u} is ignored for the formats @samp{s}
4717 and @samp{i}, you might still want to use a count @var{n}; for example,
4718 @samp{3i} specifies that you want to see three machine instructions,
4719 including any operands. The command @code{disassemble} gives an
4720 alternative way of inspecting machine instructions; see @ref{Machine
4721 Code,,Source and machine code}.
4722
4723 All the defaults for the arguments to @code{x} are designed to make it
4724 easy to continue scanning memory with minimal specifications each time
4725 you use @code{x}. For example, after you have inspected three machine
4726 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
4727 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
4728 the repeat count @var{n} is used again; the other arguments default as
4729 for successive uses of @code{x}.
4730
4731 @cindex @code{$_}, @code{$__}, and value history
4732 The addresses and contents printed by the @code{x} command are not saved
4733 in the value history because there is often too much of them and they
4734 would get in the way. Instead, @value{GDBN} makes these values available for
4735 subsequent use in expressions as values of the convenience variables
4736 @code{$_} and @code{$__}. After an @code{x} command, the last address
4737 examined is available for use in expressions in the convenience variable
4738 @code{$_}. The contents of that address, as examined, are available in
4739 the convenience variable @code{$__}.
4740
4741 If the @code{x} command has a repeat count, the address and contents saved
4742 are from the last memory unit printed; this is not the same as the last
4743 address printed if several units were printed on the last line of output.
4744
4745 @node Auto Display
4746 @section Automatic display
4747 @cindex automatic display
4748 @cindex display of expressions
4749
4750 If you find that you want to print the value of an expression frequently
4751 (to see how it changes), you might want to add it to the @dfn{automatic
4752 display list} so that @value{GDBN} prints its value each time your program stops.
4753 Each expression added to the list is given a number to identify it;
4754 to remove an expression from the list, you specify that number.
4755 The automatic display looks like this:
4756
4757 @example
4758 2: foo = 38
4759 3: bar[5] = (struct hack *) 0x3804
4760 @end example
4761
4762 @noindent
4763 This display shows item numbers, expressions and their current values. As with
4764 displays you request manually using @code{x} or @code{print}, you can
4765 specify the output format you prefer; in fact, @code{display} decides
4766 whether to use @code{print} or @code{x} depending on how elaborate your
4767 format specification is---it uses @code{x} if you specify a unit size,
4768 or one of the two formats (@samp{i} and @samp{s}) that are only
4769 supported by @code{x}; otherwise it uses @code{print}.
4770
4771 @table @code
4772 @kindex display
4773 @item display @var{expr}
4774 Add the expression @var{expr} to the list of expressions to display
4775 each time your program stops. @xref{Expressions, ,Expressions}.
4776
4777 @code{display} does not repeat if you press @key{RET} again after using it.
4778
4779 @item display/@var{fmt} @var{expr}
4780 For @var{fmt} specifying only a display format and not a size or
4781 count, add the expression @var{expr} to the auto-display list but
4782 arrange to display it each time in the specified format @var{fmt}.
4783 @xref{Output Formats,,Output formats}.
4784
4785 @item display/@var{fmt} @var{addr}
4786 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
4787 number of units, add the expression @var{addr} as a memory address to
4788 be examined each time your program stops. Examining means in effect
4789 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
4790 @end table
4791
4792 For example, @samp{display/i $pc} can be helpful, to see the machine
4793 instruction about to be executed each time execution stops (@samp{$pc}
4794 is a common name for the program counter; @pxref{Registers, ,Registers}).
4795
4796 @table @code
4797 @kindex delete display
4798 @kindex undisplay
4799 @item undisplay @var{dnums}@dots{}
4800 @itemx delete display @var{dnums}@dots{}
4801 Remove item numbers @var{dnums} from the list of expressions to display.
4802
4803 @code{undisplay} does not repeat if you press @key{RET} after using it.
4804 (Otherwise you would just get the error @samp{No display number @dots{}}.)
4805
4806 @kindex disable display
4807 @item disable display @var{dnums}@dots{}
4808 Disable the display of item numbers @var{dnums}. A disabled display
4809 item is not printed automatically, but is not forgotten. It may be
4810 enabled again later.
4811
4812 @kindex enable display
4813 @item enable display @var{dnums}@dots{}
4814 Enable display of item numbers @var{dnums}. It becomes effective once
4815 again in auto display of its expression, until you specify otherwise.
4816
4817 @item display
4818 Display the current values of the expressions on the list, just as is
4819 done when your program stops.
4820
4821 @kindex info display
4822 @item info display
4823 Print the list of expressions previously set up to display
4824 automatically, each one with its item number, but without showing the
4825 values. This includes disabled expressions, which are marked as such.
4826 It also includes expressions which would not be displayed right now
4827 because they refer to automatic variables not currently available.
4828 @end table
4829
4830 If a display expression refers to local variables, then it does not make
4831 sense outside the lexical context for which it was set up. Such an
4832 expression is disabled when execution enters a context where one of its
4833 variables is not defined. For example, if you give the command
4834 @code{display last_char} while inside a function with an argument
4835 @code{last_char}, @value{GDBN} displays this argument while your program
4836 continues to stop inside that function. When it stops elsewhere---where
4837 there is no variable @code{last_char}---the display is disabled
4838 automatically. The next time your program stops where @code{last_char}
4839 is meaningful, you can enable the display expression once again.
4840
4841 @node Print Settings
4842 @section Print settings
4843
4844 @cindex format options
4845 @cindex print settings
4846 @value{GDBN} provides the following ways to control how arrays, structures,
4847 and symbols are printed.
4848
4849 @noindent
4850 These settings are useful for debugging programs in any language:
4851
4852 @table @code
4853 @kindex set print address
4854 @item set print address
4855 @itemx set print address on
4856 @value{GDBN} prints memory addresses showing the location of stack
4857 traces, structure values, pointer values, breakpoints, and so forth,
4858 even when it also displays the contents of those addresses. The default
4859 is @code{on}. For example, this is what a stack frame display looks like with
4860 @code{set print address on}:
4861
4862 @smallexample
4863 @group
4864 (@value{GDBP}) f
4865 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4866 at input.c:530
4867 530 if (lquote != def_lquote)
4868 @end group
4869 @end smallexample
4870
4871 @item set print address off
4872 Do not print addresses when displaying their contents. For example,
4873 this is the same stack frame displayed with @code{set print address off}:
4874
4875 @smallexample
4876 @group
4877 (@value{GDBP}) set print addr off
4878 (@value{GDBP}) f
4879 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4880 530 if (lquote != def_lquote)
4881 @end group
4882 @end smallexample
4883
4884 You can use @samp{set print address off} to eliminate all machine
4885 dependent displays from the @value{GDBN} interface. For example, with
4886 @code{print address off}, you should get the same text for backtraces on
4887 all machines---whether or not they involve pointer arguments.
4888
4889 @kindex show print address
4890 @item show print address
4891 Show whether or not addresses are to be printed.
4892 @end table
4893
4894 When @value{GDBN} prints a symbolic address, it normally prints the
4895 closest earlier symbol plus an offset. If that symbol does not uniquely
4896 identify the address (for example, it is a name whose scope is a single
4897 source file), you may need to clarify. One way to do this is with
4898 @code{info line}, for example @samp{info line *0x4537}. Alternately,
4899 you can set @value{GDBN} to print the source file and line number when
4900 it prints a symbolic address:
4901
4902 @table @code
4903 @kindex set print symbol-filename
4904 @item set print symbol-filename on
4905 Tell @value{GDBN} to print the source file name and line number of a
4906 symbol in the symbolic form of an address.
4907
4908 @item set print symbol-filename off
4909 Do not print source file name and line number of a symbol. This is the
4910 default.
4911
4912 @kindex show print symbol-filename
4913 @item show print symbol-filename
4914 Show whether or not @value{GDBN} will print the source file name and
4915 line number of a symbol in the symbolic form of an address.
4916 @end table
4917
4918 Another situation where it is helpful to show symbol filenames and line
4919 numbers is when disassembling code; @value{GDBN} shows you the line
4920 number and source file that corresponds to each instruction.
4921
4922 Also, you may wish to see the symbolic form only if the address being
4923 printed is reasonably close to the closest earlier symbol:
4924
4925 @table @code
4926 @kindex set print max-symbolic-offset
4927 @item set print max-symbolic-offset @var{max-offset}
4928 Tell @value{GDBN} to only display the symbolic form of an address if the
4929 offset between the closest earlier symbol and the address is less than
4930 @var{max-offset}. The default is 0, which tells @value{GDBN}
4931 to always print the symbolic form of an address if any symbol precedes it.
4932
4933 @kindex show print max-symbolic-offset
4934 @item show print max-symbolic-offset
4935 Ask how large the maximum offset is that @value{GDBN} prints in a
4936 symbolic address.
4937 @end table
4938
4939 @cindex wild pointer, interpreting
4940 @cindex pointer, finding referent
4941 If you have a pointer and you are not sure where it points, try
4942 @samp{set print symbol-filename on}. Then you can determine the name
4943 and source file location of the variable where it points, using
4944 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
4945 For example, here @value{GDBN} shows that a variable @code{ptt} points
4946 at another variable @code{t}, defined in @file{hi2.c}:
4947
4948 @example
4949 (@value{GDBP}) set print symbol-filename on
4950 (@value{GDBP}) p/a ptt
4951 $4 = 0xe008 <t in hi2.c>
4952 @end example
4953
4954 @quotation
4955 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
4956 does not show the symbol name and filename of the referent, even with
4957 the appropriate @code{set print} options turned on.
4958 @end quotation
4959
4960 Other settings control how different kinds of objects are printed:
4961
4962 @table @code
4963 @kindex set print array
4964 @item set print array
4965 @itemx set print array on
4966 Pretty print arrays. This format is more convenient to read,
4967 but uses more space. The default is off.
4968
4969 @item set print array off
4970 Return to compressed format for arrays.
4971
4972 @kindex show print array
4973 @item show print array
4974 Show whether compressed or pretty format is selected for displaying
4975 arrays.
4976
4977 @kindex set print elements
4978 @item set print elements @var{number-of-elements}
4979 Set a limit on how many elements of an array @value{GDBN} will print.
4980 If @value{GDBN} is printing a large array, it stops printing after it has
4981 printed the number of elements set by the @code{set print elements} command.
4982 This limit also applies to the display of strings.
4983 When @value{GDBN} starts, this limit is set to 200.
4984 Setting @var{number-of-elements} to zero means that the printing is unlimited.
4985
4986 @kindex show print elements
4987 @item show print elements
4988 Display the number of elements of a large array that @value{GDBN} will print.
4989 If the number is 0, then the printing is unlimited.
4990
4991 @kindex set print null-stop
4992 @item set print null-stop
4993 Cause @value{GDBN} to stop printing the characters of an array when the first
4994 @sc{null} is encountered. This is useful when large arrays actually
4995 contain only short strings.
4996 The default is off.
4997
4998 @kindex set print pretty
4999 @item set print pretty on
5000 Cause @value{GDBN} to print structures in an indented format with one member
5001 per line, like this:
5002
5003 @smallexample
5004 @group
5005 $1 = @{
5006 next = 0x0,
5007 flags = @{
5008 sweet = 1,
5009 sour = 1
5010 @},
5011 meat = 0x54 "Pork"
5012 @}
5013 @end group
5014 @end smallexample
5015
5016 @item set print pretty off
5017 Cause @value{GDBN} to print structures in a compact format, like this:
5018
5019 @smallexample
5020 @group
5021 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5022 meat = 0x54 "Pork"@}
5023 @end group
5024 @end smallexample
5025
5026 @noindent
5027 This is the default format.
5028
5029 @kindex show print pretty
5030 @item show print pretty
5031 Show which format @value{GDBN} is using to print structures.
5032
5033 @kindex set print sevenbit-strings
5034 @item set print sevenbit-strings on
5035 Print using only seven-bit characters; if this option is set,
5036 @value{GDBN} displays any eight-bit characters (in strings or
5037 character values) using the notation @code{\}@var{nnn}. This setting is
5038 best if you are working in English (@sc{ascii}) and you use the
5039 high-order bit of characters as a marker or ``meta'' bit.
5040
5041 @item set print sevenbit-strings off
5042 Print full eight-bit characters. This allows the use of more
5043 international character sets, and is the default.
5044
5045 @kindex show print sevenbit-strings
5046 @item show print sevenbit-strings
5047 Show whether or not @value{GDBN} is printing only seven-bit characters.
5048
5049 @kindex set print union
5050 @item set print union on
5051 Tell @value{GDBN} to print unions which are contained in structures. This
5052 is the default setting.
5053
5054 @item set print union off
5055 Tell @value{GDBN} not to print unions which are contained in structures.
5056
5057 @kindex show print union
5058 @item show print union
5059 Ask @value{GDBN} whether or not it will print unions which are contained in
5060 structures.
5061
5062 For example, given the declarations
5063
5064 @smallexample
5065 typedef enum @{Tree, Bug@} Species;
5066 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5067 typedef enum @{Caterpillar, Cocoon, Butterfly@}
5068 Bug_forms;
5069
5070 struct thing @{
5071 Species it;
5072 union @{
5073 Tree_forms tree;
5074 Bug_forms bug;
5075 @} form;
5076 @};
5077
5078 struct thing foo = @{Tree, @{Acorn@}@};
5079 @end smallexample
5080
5081 @noindent
5082 with @code{set print union on} in effect @samp{p foo} would print
5083
5084 @smallexample
5085 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5086 @end smallexample
5087
5088 @noindent
5089 and with @code{set print union off} in effect it would print
5090
5091 @smallexample
5092 $1 = @{it = Tree, form = @{...@}@}
5093 @end smallexample
5094 @end table
5095
5096 @need 1000
5097 @noindent
5098 These settings are of interest when debugging C++ programs:
5099
5100 @table @code
5101 @cindex demangling
5102 @kindex set print demangle
5103 @item set print demangle
5104 @itemx set print demangle on
5105 Print C++ names in their source form rather than in the encoded
5106 (``mangled'') form passed to the assembler and linker for type-safe
5107 linkage. The default is on.
5108
5109 @kindex show print demangle
5110 @item show print demangle
5111 Show whether C++ names are printed in mangled or demangled form.
5112
5113 @kindex set print asm-demangle
5114 @item set print asm-demangle
5115 @itemx set print asm-demangle on
5116 Print C++ names in their source form rather than their mangled form, even
5117 in assembler code printouts such as instruction disassemblies.
5118 The default is off.
5119
5120 @kindex show print asm-demangle
5121 @item show print asm-demangle
5122 Show whether C++ names in assembly listings are printed in mangled
5123 or demangled form.
5124
5125 @kindex set demangle-style
5126 @cindex C++ symbol decoding style
5127 @cindex symbol decoding style, C++
5128 @item set demangle-style @var{style}
5129 Choose among several encoding schemes used by different compilers to
5130 represent C++ names. The choices for @var{style} are currently:
5131
5132 @table @code
5133 @item auto
5134 Allow @value{GDBN} to choose a decoding style by inspecting your program.
5135
5136 @item gnu
5137 Decode based on the @sc{gnu} C++ compiler (@code{g++}) encoding algorithm.
5138 This is the default.
5139
5140 @item hp
5141 Decode based on the HP ANSI C++ (@code{aCC}) encoding algorithm.
5142
5143 @item lucid
5144 Decode based on the Lucid C++ compiler (@code{lcc}) encoding algorithm.
5145
5146 @item arm
5147 Decode using the algorithm in the @cite{C++ Annotated Reference Manual}.
5148 @strong{Warning:} this setting alone is not sufficient to allow
5149 debugging @code{cfront}-generated executables. @value{GDBN} would
5150 require further enhancement to permit that.
5151
5152 @end table
5153 If you omit @var{style}, you will see a list of possible formats.
5154
5155 @kindex show demangle-style
5156 @item show demangle-style
5157 Display the encoding style currently in use for decoding C++ symbols.
5158
5159 @kindex set print object
5160 @item set print object
5161 @itemx set print object on
5162 When displaying a pointer to an object, identify the @emph{actual}
5163 (derived) type of the object rather than the @emph{declared} type, using
5164 the virtual function table.
5165
5166 @item set print object off
5167 Display only the declared type of objects, without reference to the
5168 virtual function table. This is the default setting.
5169
5170 @kindex show print object
5171 @item show print object
5172 Show whether actual, or declared, object types are displayed.
5173
5174 @kindex set print static-members
5175 @item set print static-members
5176 @itemx set print static-members on
5177 Print static members when displaying a C++ object. The default is on.
5178
5179 @item set print static-members off
5180 Do not print static members when displaying a C++ object.
5181
5182 @kindex show print static-members
5183 @item show print static-members
5184 Show whether C++ static members are printed, or not.
5185
5186 @c These don't work with HP ANSI C++ yet.
5187 @kindex set print vtbl
5188 @item set print vtbl
5189 @itemx set print vtbl on
5190 Pretty print C++ virtual function tables. The default is off.
5191 (The @code{vtbl} commands do not work on programs compiled with the HP
5192 ANSI C++ compiler (@code{aCC}).)
5193
5194 @item set print vtbl off
5195 Do not pretty print C++ virtual function tables.
5196
5197 @kindex show print vtbl
5198 @item show print vtbl
5199 Show whether C++ virtual function tables are pretty printed, or not.
5200 @end table
5201
5202 @node Value History
5203 @section Value history
5204
5205 @cindex value history
5206 Values printed by the @code{print} command are saved in the @value{GDBN}
5207 @dfn{value history}. This allows you to refer to them in other expressions.
5208 Values are kept until the symbol table is re-read or discarded
5209 (for example with the @code{file} or @code{symbol-file} commands).
5210 When the symbol table changes, the value history is discarded,
5211 since the values may contain pointers back to the types defined in the
5212 symbol table.
5213
5214 @cindex @code{$}
5215 @cindex @code{$$}
5216 @cindex history number
5217 The values printed are given @dfn{history numbers} by which you can
5218 refer to them. These are successive integers starting with one.
5219 @code{print} shows you the history number assigned to a value by
5220 printing @samp{$@var{num} = } before the value; here @var{num} is the
5221 history number.
5222
5223 To refer to any previous value, use @samp{$} followed by the value's
5224 history number. The way @code{print} labels its output is designed to
5225 remind you of this. Just @code{$} refers to the most recent value in
5226 the history, and @code{$$} refers to the value before that.
5227 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5228 is the value just prior to @code{$$}, @code{$$1} is equivalent to
5229 @code{$$}, and @code{$$0} is equivalent to @code{$}.
5230
5231 For example, suppose you have just printed a pointer to a structure and
5232 want to see the contents of the structure. It suffices to type
5233
5234 @example
5235 p *$
5236 @end example
5237
5238 If you have a chain of structures where the component @code{next} points
5239 to the next one, you can print the contents of the next one with this:
5240
5241 @example
5242 p *$.next
5243 @end example
5244
5245 @noindent
5246 You can print successive links in the chain by repeating this
5247 command---which you can do by just typing @key{RET}.
5248
5249 Note that the history records values, not expressions. If the value of
5250 @code{x} is 4 and you type these commands:
5251
5252 @example
5253 print x
5254 set x=5
5255 @end example
5256
5257 @noindent
5258 then the value recorded in the value history by the @code{print} command
5259 remains 4 even though the value of @code{x} has changed.
5260
5261 @table @code
5262 @kindex show values
5263 @item show values
5264 Print the last ten values in the value history, with their item numbers.
5265 This is like @samp{p@ $$9} repeated ten times, except that @code{show
5266 values} does not change the history.
5267
5268 @item show values @var{n}
5269 Print ten history values centered on history item number @var{n}.
5270
5271 @item show values +
5272 Print ten history values just after the values last printed. If no more
5273 values are available, @code{show values +} produces no display.
5274 @end table
5275
5276 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5277 same effect as @samp{show values +}.
5278
5279 @node Convenience Vars
5280 @section Convenience variables
5281
5282 @cindex convenience variables
5283 @value{GDBN} provides @dfn{convenience variables} that you can use within
5284 @value{GDBN} to hold on to a value and refer to it later. These variables
5285 exist entirely within @value{GDBN}; they are not part of your program, and
5286 setting a convenience variable has no direct effect on further execution
5287 of your program. That is why you can use them freely.
5288
5289 Convenience variables are prefixed with @samp{$}. Any name preceded by
5290 @samp{$} can be used for a convenience variable, unless it is one of
5291 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
5292 (Value history references, in contrast, are @emph{numbers} preceded
5293 by @samp{$}. @xref{Value History, ,Value history}.)
5294
5295 You can save a value in a convenience variable with an assignment
5296 expression, just as you would set a variable in your program.
5297 For example:
5298
5299 @example
5300 set $foo = *object_ptr
5301 @end example
5302
5303 @noindent
5304 would save in @code{$foo} the value contained in the object pointed to by
5305 @code{object_ptr}.
5306
5307 Using a convenience variable for the first time creates it, but its
5308 value is @code{void} until you assign a new value. You can alter the
5309 value with another assignment at any time.
5310
5311 Convenience variables have no fixed types. You can assign a convenience
5312 variable any type of value, including structures and arrays, even if
5313 that variable already has a value of a different type. The convenience
5314 variable, when used as an expression, has the type of its current value.
5315
5316 @table @code
5317 @kindex show convenience
5318 @item show convenience
5319 Print a list of convenience variables used so far, and their values.
5320 Abbreviated @code{show conv}.
5321 @end table
5322
5323 One of the ways to use a convenience variable is as a counter to be
5324 incremented or a pointer to be advanced. For example, to print
5325 a field from successive elements of an array of structures:
5326
5327 @example
5328 set $i = 0
5329 print bar[$i++]->contents
5330 @end example
5331
5332 @noindent
5333 Repeat that command by typing @key{RET}.
5334
5335 Some convenience variables are created automatically by @value{GDBN} and given
5336 values likely to be useful.
5337
5338 @table @code
5339 @kindex $_
5340 @item $_
5341 The variable @code{$_} is automatically set by the @code{x} command to
5342 the last address examined (@pxref{Memory, ,Examining memory}). Other
5343 commands which provide a default address for @code{x} to examine also
5344 set @code{$_} to that address; these commands include @code{info line}
5345 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5346 except when set by the @code{x} command, in which case it is a pointer
5347 to the type of @code{$__}.
5348
5349 @kindex $__
5350 @item $__
5351 The variable @code{$__} is automatically set by the @code{x} command
5352 to the value found in the last address examined. Its type is chosen
5353 to match the format in which the data was printed.
5354
5355 @item $_exitcode
5356 @kindex $_exitcode
5357 The variable @code{$_exitcode} is automatically set to the exit code when
5358 the program being debugged terminates.
5359 @end table
5360
5361 On HP-UX systems, if you refer to a function or variable name that
5362 begins with a dollar sign, @value{GDBN} searches for a user or system
5363 name first, before it searches for a convenience variable.
5364
5365 @node Registers
5366 @section Registers
5367
5368 @cindex registers
5369 You can refer to machine register contents, in expressions, as variables
5370 with names starting with @samp{$}. The names of registers are different
5371 for each machine; use @code{info registers} to see the names used on
5372 your machine.
5373
5374 @table @code
5375 @kindex info registers
5376 @item info registers
5377 Print the names and values of all registers except floating-point
5378 registers (in the selected stack frame).
5379
5380 @kindex info all-registers
5381 @cindex floating point registers
5382 @item info all-registers
5383 Print the names and values of all registers, including floating-point
5384 registers.
5385
5386 @item info registers @var{regname} @dots{}
5387 Print the @dfn{relativized} value of each specified register @var{regname}.
5388 As discussed in detail below, register values are normally relative to
5389 the selected stack frame. @var{regname} may be any register name valid on
5390 the machine you are using, with or without the initial @samp{$}.
5391 @end table
5392
5393 @value{GDBN} has four ``standard'' register names that are available (in
5394 expressions) on most machines---whenever they do not conflict with an
5395 architecture's canonical mnemonics for registers. The register names
5396 @code{$pc} and @code{$sp} are used for the program counter register and
5397 the stack pointer. @code{$fp} is used for a register that contains a
5398 pointer to the current stack frame, and @code{$ps} is used for a
5399 register that contains the processor status. For example,
5400 you could print the program counter in hex with
5401
5402 @example
5403 p/x $pc
5404 @end example
5405
5406 @noindent
5407 or print the instruction to be executed next with
5408
5409 @example
5410 x/i $pc
5411 @end example
5412
5413 @noindent
5414 or add four to the stack pointer@footnote{This is a way of removing
5415 one word from the stack, on machines where stacks grow downward in
5416 memory (most machines, nowadays). This assumes that the innermost
5417 stack frame is selected; setting @code{$sp} is not allowed when other
5418 stack frames are selected. To pop entire frames off the stack,
5419 regardless of machine architecture, use @code{return};
5420 see @ref{Returning, ,Returning from a function}.} with
5421
5422 @example
5423 set $sp += 4
5424 @end example
5425
5426 Whenever possible, these four standard register names are available on
5427 your machine even though the machine has different canonical mnemonics,
5428 so long as there is no conflict. The @code{info registers} command
5429 shows the canonical names. For example, on the SPARC, @code{info
5430 registers} displays the processor status register as @code{$psr} but you
5431 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5432 is an alias for the @sc{eflags} register.
5433
5434 @value{GDBN} always considers the contents of an ordinary register as an
5435 integer when the register is examined in this way. Some machines have
5436 special registers which can hold nothing but floating point; these
5437 registers are considered to have floating point values. There is no way
5438 to refer to the contents of an ordinary register as floating point value
5439 (although you can @emph{print} it as a floating point value with
5440 @samp{print/f $@var{regname}}).
5441
5442 Some registers have distinct ``raw'' and ``virtual'' data formats. This
5443 means that the data format in which the register contents are saved by
5444 the operating system is not the same one that your program normally
5445 sees. For example, the registers of the 68881 floating point
5446 coprocessor are always saved in ``extended'' (raw) format, but all C
5447 programs expect to work with ``double'' (virtual) format. In such
5448 cases, @value{GDBN} normally works with the virtual format only (the format
5449 that makes sense for your program), but the @code{info registers} command
5450 prints the data in both formats.
5451
5452 Normally, register values are relative to the selected stack frame
5453 (@pxref{Selection, ,Selecting a frame}). This means that you get the
5454 value that the register would contain if all stack frames farther in
5455 were exited and their saved registers restored. In order to see the
5456 true contents of hardware registers, you must select the innermost
5457 frame (with @samp{frame 0}).
5458
5459 However, @value{GDBN} must deduce where registers are saved, from the machine
5460 code generated by your compiler. If some registers are not saved, or if
5461 @value{GDBN} is unable to locate the saved registers, the selected stack
5462 frame makes no difference.
5463
5464 @node Floating Point Hardware
5465 @section Floating point hardware
5466 @cindex floating point
5467
5468 Depending on the configuration, @value{GDBN} may be able to give
5469 you more information about the status of the floating point hardware.
5470
5471 @table @code
5472 @kindex info float
5473 @item info float
5474 Display hardware-dependent information about the floating
5475 point unit. The exact contents and layout vary depending on the
5476 floating point chip. Currently, @samp{info float} is supported on
5477 the ARM and x86 machines.
5478 @end table
5479
5480 @node Languages
5481 @chapter Using @value{GDBN} with Different Languages
5482 @cindex languages
5483
5484 Although programming languages generally have common aspects, they are
5485 rarely expressed in the same manner. For instance, in ANSI C,
5486 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
5487 Modula-2, it is accomplished by @code{p^}. Values can also be
5488 represented (and displayed) differently. Hex numbers in C appear as
5489 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
5490
5491 @cindex working language
5492 Language-specific information is built into @value{GDBN} for some languages,
5493 allowing you to express operations like the above in your program's
5494 native language, and allowing @value{GDBN} to output values in a manner
5495 consistent with the syntax of your program's native language. The
5496 language you use to build expressions is called the @dfn{working
5497 language}.
5498
5499 @menu
5500 * Setting:: Switching between source languages
5501 * Show:: Displaying the language
5502 * Checks:: Type and range checks
5503 * Support:: Supported languages
5504 @end menu
5505
5506 @node Setting
5507 @section Switching between source languages
5508
5509 There are two ways to control the working language---either have @value{GDBN}
5510 set it automatically, or select it manually yourself. You can use the
5511 @code{set language} command for either purpose. On startup, @value{GDBN}
5512 defaults to setting the language automatically. The working language is
5513 used to determine how expressions you type are interpreted, how values
5514 are printed, etc.
5515
5516 In addition to the working language, every source file that
5517 @value{GDBN} knows about has its own working language. For some object
5518 file formats, the compiler might indicate which language a particular
5519 source file is in. However, most of the time @value{GDBN} infers the
5520 language from the name of the file. The language of a source file
5521 controls whether C++ names are demangled---this way @code{backtrace} can
5522 show each frame appropriately for its own language. There is no way to
5523 set the language of a source file from within @value{GDBN}, but you can
5524 set the language associated with a filename extension. @xref{Show, ,
5525 Displaying the language}.
5526
5527 This is most commonly a problem when you use a program, such
5528 as @code{cfront} or @code{f2c}, that generates C but is written in
5529 another language. In that case, make the
5530 program use @code{#line} directives in its C output; that way
5531 @value{GDBN} will know the correct language of the source code of the original
5532 program, and will display that source code, not the generated C code.
5533
5534 @menu
5535 * Filenames:: Filename extensions and languages.
5536 * Manually:: Setting the working language manually
5537 * Automatically:: Having @value{GDBN} infer the source language
5538 @end menu
5539
5540 @node Filenames
5541 @subsection List of filename extensions and languages
5542
5543 If a source file name ends in one of the following extensions, then
5544 @value{GDBN} infers that its language is the one indicated.
5545
5546 @table @file
5547
5548 @item .c
5549 C source file
5550
5551 @item .C
5552 @itemx .cc
5553 @itemx .cp
5554 @itemx .cpp
5555 @itemx .cxx
5556 @itemx .c++
5557 C++ source file
5558
5559 @item .f
5560 @itemx .F
5561 Fortran source file
5562
5563 @item .ch
5564 @itemx .c186
5565 @itemx .c286
5566 CHILL source file
5567
5568 @item .mod
5569 Modula-2 source file
5570
5571 @item .s
5572 @itemx .S
5573 Assembler source file. This actually behaves almost like C, but
5574 @value{GDBN} does not skip over function prologues when stepping.
5575 @end table
5576
5577 In addition, you may set the language associated with a filename
5578 extension. @xref{Show, , Displaying the language}.
5579
5580 @node Manually
5581 @subsection Setting the working language
5582
5583 If you allow @value{GDBN} to set the language automatically,
5584 expressions are interpreted the same way in your debugging session and
5585 your program.
5586
5587 @kindex set language
5588 If you wish, you may set the language manually. To do this, issue the
5589 command @samp{set language @var{lang}}, where @var{lang} is the name of
5590 a language, such as
5591 @code{c} or @code{modula-2}.
5592 For a list of the supported languages, type @samp{set language}.
5593
5594 Setting the language manually prevents @value{GDBN} from updating the working
5595 language automatically. This can lead to confusion if you try
5596 to debug a program when the working language is not the same as the
5597 source language, when an expression is acceptable to both
5598 languages---but means different things. For instance, if the current
5599 source file were written in C, and @value{GDBN} was parsing Modula-2, a
5600 command such as:
5601
5602 @example
5603 print a = b + c
5604 @end example
5605
5606 @noindent
5607 might not have the effect you intended. In C, this means to add
5608 @code{b} and @code{c} and place the result in @code{a}. The result
5609 printed would be the value of @code{a}. In Modula-2, this means to compare
5610 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
5611
5612 @node Automatically
5613 @subsection Having @value{GDBN} infer the source language
5614
5615 To have @value{GDBN} set the working language automatically, use
5616 @samp{set language local} or @samp{set language auto}. @value{GDBN}
5617 then infers the working language. That is, when your program stops in a
5618 frame (usually by encountering a breakpoint), @value{GDBN} sets the
5619 working language to the language recorded for the function in that
5620 frame. If the language for a frame is unknown (that is, if the function
5621 or block corresponding to the frame was defined in a source file that
5622 does not have a recognized extension), the current working language is
5623 not changed, and @value{GDBN} issues a warning.
5624
5625 This may not seem necessary for most programs, which are written
5626 entirely in one source language. However, program modules and libraries
5627 written in one source language can be used by a main program written in
5628 a different source language. Using @samp{set language auto} in this
5629 case frees you from having to set the working language manually.
5630
5631 @node Show
5632 @section Displaying the language
5633
5634 The following commands help you find out which language is the
5635 working language, and also what language source files were written in.
5636
5637 @kindex show language
5638 @kindex info frame@r{, show the source language}
5639 @kindex info source@r{, show the source language}
5640 @table @code
5641 @item show language
5642 Display the current working language. This is the
5643 language you can use with commands such as @code{print} to
5644 build and compute expressions that may involve variables in your program.
5645
5646 @item info frame
5647 Display the source language for this frame. This language becomes the
5648 working language if you use an identifier from this frame.
5649 @xref{Frame Info, ,Information about a frame}, to identify the other
5650 information listed here.
5651
5652 @item info source
5653 Display the source language of this source file.
5654 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
5655 information listed here.
5656 @end table
5657
5658 In unusual circumstances, you may have source files with extensions
5659 not in the standard list. You can then set the extension associated
5660 with a language explicitly:
5661
5662 @kindex set extension-language
5663 @kindex info extensions
5664 @table @code
5665 @item set extension-language @var{.ext} @var{language}
5666 Set source files with extension @var{.ext} to be assumed to be in
5667 the source language @var{language}.
5668
5669 @item info extensions
5670 List all the filename extensions and the associated languages.
5671 @end table
5672
5673 @node Checks
5674 @section Type and range checking
5675
5676 @quotation
5677 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
5678 checking are included, but they do not yet have any effect. This
5679 section documents the intended facilities.
5680 @end quotation
5681 @c FIXME remove warning when type/range code added
5682
5683 Some languages are designed to guard you against making seemingly common
5684 errors through a series of compile- and run-time checks. These include
5685 checking the type of arguments to functions and operators, and making
5686 sure mathematical overflows are caught at run time. Checks such as
5687 these help to ensure a program's correctness once it has been compiled
5688 by eliminating type mismatches, and providing active checks for range
5689 errors when your program is running.
5690
5691 @value{GDBN} can check for conditions like the above if you wish.
5692 Although @value{GDBN} does not check the statements in your program, it
5693 can check expressions entered directly into @value{GDBN} for evaluation via
5694 the @code{print} command, for example. As with the working language,
5695 @value{GDBN} can also decide whether or not to check automatically based on
5696 your program's source language. @xref{Support, ,Supported languages},
5697 for the default settings of supported languages.
5698
5699 @menu
5700 * Type Checking:: An overview of type checking
5701 * Range Checking:: An overview of range checking
5702 @end menu
5703
5704 @cindex type checking
5705 @cindex checks, type
5706 @node Type Checking
5707 @subsection An overview of type checking
5708
5709 Some languages, such as Modula-2, are strongly typed, meaning that the
5710 arguments to operators and functions have to be of the correct type,
5711 otherwise an error occurs. These checks prevent type mismatch
5712 errors from ever causing any run-time problems. For example,
5713
5714 @smallexample
5715 1 + 2 @result{} 3
5716 @exdent but
5717 @error{} 1 + 2.3
5718 @end smallexample
5719
5720 The second example fails because the @code{CARDINAL} 1 is not
5721 type-compatible with the @code{REAL} 2.3.
5722
5723 For the expressions you use in @value{GDBN} commands, you can tell the
5724 @value{GDBN} type checker to skip checking;
5725 to treat any mismatches as errors and abandon the expression;
5726 or to only issue warnings when type mismatches occur,
5727 but evaluate the expression anyway. When you choose the last of
5728 these, @value{GDBN} evaluates expressions like the second example above, but
5729 also issues a warning.
5730
5731 Even if you turn type checking off, there may be other reasons
5732 related to type that prevent @value{GDBN} from evaluating an expression.
5733 For instance, @value{GDBN} does not know how to add an @code{int} and
5734 a @code{struct foo}. These particular type errors have nothing to do
5735 with the language in use, and usually arise from expressions, such as
5736 the one described above, which make little sense to evaluate anyway.
5737
5738 Each language defines to what degree it is strict about type. For
5739 instance, both Modula-2 and C require the arguments to arithmetical
5740 operators to be numbers. In C, enumerated types and pointers can be
5741 represented as numbers, so that they are valid arguments to mathematical
5742 operators. @xref{Support, ,Supported languages}, for further
5743 details on specific languages.
5744
5745 @value{GDBN} provides some additional commands for controlling the type checker:
5746
5747 @kindex set check@r{, type}
5748 @kindex set check type
5749 @kindex show check type
5750 @table @code
5751 @item set check type auto
5752 Set type checking on or off based on the current working language.
5753 @xref{Support, ,Supported languages}, for the default settings for
5754 each language.
5755
5756 @item set check type on
5757 @itemx set check type off
5758 Set type checking on or off, overriding the default setting for the
5759 current working language. Issue a warning if the setting does not
5760 match the language default. If any type mismatches occur in
5761 evaluating an expression while type checking is on, @value{GDBN} prints a
5762 message and aborts evaluation of the expression.
5763
5764 @item set check type warn
5765 Cause the type checker to issue warnings, but to always attempt to
5766 evaluate the expression. Evaluating the expression may still
5767 be impossible for other reasons. For example, @value{GDBN} cannot add
5768 numbers and structures.
5769
5770 @item show type
5771 Show the current setting of the type checker, and whether or not @value{GDBN}
5772 is setting it automatically.
5773 @end table
5774
5775 @cindex range checking
5776 @cindex checks, range
5777 @node Range Checking
5778 @subsection An overview of range checking
5779
5780 In some languages (such as Modula-2), it is an error to exceed the
5781 bounds of a type; this is enforced with run-time checks. Such range
5782 checking is meant to ensure program correctness by making sure
5783 computations do not overflow, or indices on an array element access do
5784 not exceed the bounds of the array.
5785
5786 For expressions you use in @value{GDBN} commands, you can tell
5787 @value{GDBN} to treat range errors in one of three ways: ignore them,
5788 always treat them as errors and abandon the expression, or issue
5789 warnings but evaluate the expression anyway.
5790
5791 A range error can result from numerical overflow, from exceeding an
5792 array index bound, or when you type a constant that is not a member
5793 of any type. Some languages, however, do not treat overflows as an
5794 error. In many implementations of C, mathematical overflow causes the
5795 result to ``wrap around'' to lower values---for example, if @var{m} is
5796 the largest integer value, and @var{s} is the smallest, then
5797
5798 @example
5799 @var{m} + 1 @result{} @var{s}
5800 @end example
5801
5802 This, too, is specific to individual languages, and in some cases
5803 specific to individual compilers or machines. @xref{Support, ,
5804 Supported languages}, for further details on specific languages.
5805
5806 @value{GDBN} provides some additional commands for controlling the range checker:
5807
5808 @kindex set check@r{, range}
5809 @kindex set check range
5810 @kindex show check range
5811 @table @code
5812 @item set check range auto
5813 Set range checking on or off based on the current working language.
5814 @xref{Support, ,Supported languages}, for the default settings for
5815 each language.
5816
5817 @item set check range on
5818 @itemx set check range off
5819 Set range checking on or off, overriding the default setting for the
5820 current working language. A warning is issued if the setting does not
5821 match the language default. If a range error occurs and range checking is on,
5822 then a message is printed and evaluation of the expression is aborted.
5823
5824 @item set check range warn
5825 Output messages when the @value{GDBN} range checker detects a range error,
5826 but attempt to evaluate the expression anyway. Evaluating the
5827 expression may still be impossible for other reasons, such as accessing
5828 memory that the process does not own (a typical example from many Unix
5829 systems).
5830
5831 @item show range
5832 Show the current setting of the range checker, and whether or not it is
5833 being set automatically by @value{GDBN}.
5834 @end table
5835
5836 @node Support
5837 @section Supported languages
5838
5839 @value{GDBN} supports C, C++, Fortran, Java, Chill, assembly, and Modula-2.
5840 @c This is false ...
5841 Some @value{GDBN} features may be used in expressions regardless of the
5842 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
5843 and the @samp{@{type@}addr} construct (@pxref{Expressions,
5844 ,Expressions}) can be used with the constructs of any supported
5845 language.
5846
5847 The following sections detail to what degree each source language is
5848 supported by @value{GDBN}. These sections are not meant to be language
5849 tutorials or references, but serve only as a reference guide to what the
5850 @value{GDBN} expression parser accepts, and what input and output
5851 formats should look like for different languages. There are many good
5852 books written on each of these languages; please look to these for a
5853 language reference or tutorial.
5854
5855 @menu
5856 * C:: C and C++
5857 * Modula-2:: Modula-2
5858 * Chill:: Chill
5859 @end menu
5860
5861 @node C
5862 @subsection C and C++
5863
5864 @cindex C and C++
5865 @cindex expressions in C or C++
5866
5867 Since C and C++ are so closely related, many features of @value{GDBN} apply
5868 to both languages. Whenever this is the case, we discuss those languages
5869 together.
5870
5871 @cindex C++
5872 @kindex g++
5873 @cindex @sc{gnu} C++
5874 The C++ debugging facilities are jointly implemented by the C++
5875 compiler and @value{GDBN}. Therefore, to debug your C++ code
5876 effectively, you must compile your C++ programs with a supported
5877 C++ compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C++
5878 compiler (@code{aCC}).
5879
5880 For best results when using @sc{gnu} C++, use the stabs debugging
5881 format. You can select that format explicitly with the @code{g++}
5882 command-line options @samp{-gstabs} or @samp{-gstabs+}. See
5883 @ref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
5884 CC, gcc.info, Using @sc{gnu} CC}, for more information.
5885
5886 @menu
5887 * C Operators:: C and C++ operators
5888 * C Constants:: C and C++ constants
5889 * C plus plus expressions:: C++ expressions
5890 * C Defaults:: Default settings for C and C++
5891 * C Checks:: C and C++ type and range checks
5892 * Debugging C:: @value{GDBN} and C
5893 * Debugging C plus plus:: @value{GDBN} features for C++
5894 @end menu
5895
5896 @node C Operators
5897 @subsubsection C and C++ operators
5898
5899 @cindex C and C++ operators
5900
5901 Operators must be defined on values of specific types. For instance,
5902 @code{+} is defined on numbers, but not on structures. Operators are
5903 often defined on groups of types.
5904
5905 For the purposes of C and C++, the following definitions hold:
5906
5907 @itemize @bullet
5908
5909 @item
5910 @emph{Integral types} include @code{int} with any of its storage-class
5911 specifiers; @code{char}; @code{enum}; and, for C++, @code{bool}.
5912
5913 @item
5914 @emph{Floating-point types} include @code{float}, @code{double}, and
5915 @code{long double} (if supported by the target platform).
5916
5917 @item
5918 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
5919
5920 @item
5921 @emph{Scalar types} include all of the above.
5922
5923 @end itemize
5924
5925 @noindent
5926 The following operators are supported. They are listed here
5927 in order of increasing precedence:
5928
5929 @table @code
5930 @item ,
5931 The comma or sequencing operator. Expressions in a comma-separated list
5932 are evaluated from left to right, with the result of the entire
5933 expression being the last expression evaluated.
5934
5935 @item =
5936 Assignment. The value of an assignment expression is the value
5937 assigned. Defined on scalar types.
5938
5939 @item @var{op}=
5940 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
5941 and translated to @w{@code{@var{a} = @var{a op b}}}.
5942 @w{@code{@var{op}=}} and @code{=} have the same precedence.
5943 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
5944 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
5945
5946 @item ?:
5947 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
5948 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
5949 integral type.
5950
5951 @item ||
5952 Logical @sc{or}. Defined on integral types.
5953
5954 @item &&
5955 Logical @sc{and}. Defined on integral types.
5956
5957 @item |
5958 Bitwise @sc{or}. Defined on integral types.
5959
5960 @item ^
5961 Bitwise exclusive-@sc{or}. Defined on integral types.
5962
5963 @item &
5964 Bitwise @sc{and}. Defined on integral types.
5965
5966 @item ==@r{, }!=
5967 Equality and inequality. Defined on scalar types. The value of these
5968 expressions is 0 for false and non-zero for true.
5969
5970 @item <@r{, }>@r{, }<=@r{, }>=
5971 Less than, greater than, less than or equal, greater than or equal.
5972 Defined on scalar types. The value of these expressions is 0 for false
5973 and non-zero for true.
5974
5975 @item <<@r{, }>>
5976 left shift, and right shift. Defined on integral types.
5977
5978 @item @@
5979 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
5980
5981 @item +@r{, }-
5982 Addition and subtraction. Defined on integral types, floating-point types and
5983 pointer types.
5984
5985 @item *@r{, }/@r{, }%
5986 Multiplication, division, and modulus. Multiplication and division are
5987 defined on integral and floating-point types. Modulus is defined on
5988 integral types.
5989
5990 @item ++@r{, }--
5991 Increment and decrement. When appearing before a variable, the
5992 operation is performed before the variable is used in an expression;
5993 when appearing after it, the variable's value is used before the
5994 operation takes place.
5995
5996 @item *
5997 Pointer dereferencing. Defined on pointer types. Same precedence as
5998 @code{++}.
5999
6000 @item &
6001 Address operator. Defined on variables. Same precedence as @code{++}.
6002
6003 For debugging C++, @value{GDBN} implements a use of @samp{&} beyond what is
6004 allowed in the C++ language itself: you can use @samp{&(&@var{ref})}
6005 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
6006 where a C++ reference variable (declared with @samp{&@var{ref}}) is
6007 stored.
6008
6009 @item -
6010 Negative. Defined on integral and floating-point types. Same
6011 precedence as @code{++}.
6012
6013 @item !
6014 Logical negation. Defined on integral types. Same precedence as
6015 @code{++}.
6016
6017 @item ~
6018 Bitwise complement operator. Defined on integral types. Same precedence as
6019 @code{++}.
6020
6021
6022 @item .@r{, }->
6023 Structure member, and pointer-to-structure member. For convenience,
6024 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
6025 pointer based on the stored type information.
6026 Defined on @code{struct} and @code{union} data.
6027
6028 @item .*@r{, }->*
6029 Dereferences of pointers to members.
6030
6031 @item []
6032 Array indexing. @code{@var{a}[@var{i}]} is defined as
6033 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
6034
6035 @item ()
6036 Function parameter list. Same precedence as @code{->}.
6037
6038 @item ::
6039 C++ scope resolution operator. Defined on @code{struct}, @code{union},
6040 and @code{class} types.
6041
6042 @item ::
6043 Doubled colons also represent the @value{GDBN} scope operator
6044 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
6045 above.
6046 @end table
6047
6048 If an operator is redefined in the user code, @value{GDBN} usually
6049 attempts to invoke the redefined version instead of using the operator's
6050 predefined meaning.
6051
6052 @menu
6053 * C Constants::
6054 @end menu
6055
6056 @node C Constants
6057 @subsubsection C and C++ constants
6058
6059 @cindex C and C++ constants
6060
6061 @value{GDBN} allows you to express the constants of C and C++ in the
6062 following ways:
6063
6064 @itemize @bullet
6065 @item
6066 Integer constants are a sequence of digits. Octal constants are
6067 specified by a leading @samp{0} (i.e. zero), and hexadecimal constants by
6068 a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
6069 @samp{l}, specifying that the constant should be treated as a
6070 @code{long} value.
6071
6072 @item
6073 Floating point constants are a sequence of digits, followed by a decimal
6074 point, followed by a sequence of digits, and optionally followed by an
6075 exponent. An exponent is of the form:
6076 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
6077 sequence of digits. The @samp{+} is optional for positive exponents.
6078 A floating-point constant may also end with a letter @samp{f} or
6079 @samp{F}, specifying that the constant should be treated as being of
6080 the @code{float} (as opposed to the default @code{double}) type; or with
6081 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
6082 constant.
6083
6084 @item
6085 Enumerated constants consist of enumerated identifiers, or their
6086 integral equivalents.
6087
6088 @item
6089 Character constants are a single character surrounded by single quotes
6090 (@code{'}), or a number---the ordinal value of the corresponding character
6091 (usually its @sc{ascii} value). Within quotes, the single character may
6092 be represented by a letter or by @dfn{escape sequences}, which are of
6093 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
6094 of the character's ordinal value; or of the form @samp{\@var{x}}, where
6095 @samp{@var{x}} is a predefined special character---for example,
6096 @samp{\n} for newline.
6097
6098 @item
6099 String constants are a sequence of character constants surrounded by
6100 double quotes (@code{"}). Any valid character constant (as described
6101 above) may appear. Double quotes within the string must be preceded by
6102 a backslash, so for instance @samp{"a\"b'c"} is a string of five
6103 characters.
6104
6105 @item
6106 Pointer constants are an integral value. You can also write pointers
6107 to constants using the C operator @samp{&}.
6108
6109 @item
6110 Array constants are comma-separated lists surrounded by braces @samp{@{}
6111 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
6112 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
6113 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
6114 @end itemize
6115
6116 @menu
6117 * C plus plus expressions::
6118 * C Defaults::
6119 * C Checks::
6120
6121 * Debugging C::
6122 @end menu
6123
6124 @node C plus plus expressions
6125 @subsubsection C++ expressions
6126
6127 @cindex expressions in C++
6128 @value{GDBN} expression handling can interpret most C++ expressions.
6129
6130 @cindex C++ support, not in @sc{coff}
6131 @cindex @sc{coff} versus C++
6132 @cindex C++ and object formats
6133 @cindex object formats and C++
6134 @cindex a.out and C++
6135 @cindex @sc{ecoff} and C++
6136 @cindex @sc{xcoff} and C++
6137 @cindex @sc{elf}/stabs and C++
6138 @cindex @sc{elf}/@sc{dwarf} and C++
6139 @c FIXME!! GDB may eventually be able to debug C++ using DWARF; check
6140 @c periodically whether this has happened...
6141 @quotation
6142 @emph{Warning:} @value{GDBN} can only debug C++ code if you use the
6143 proper compiler. Typically, C++ debugging depends on the use of
6144 additional debugging information in the symbol table, and thus requires
6145 special support. In particular, if your compiler generates a.out, MIPS
6146 @sc{ecoff}, RS/6000 @sc{xcoff}, or @sc{elf} with stabs extensions to the
6147 symbol table, these facilities are all available. (With @sc{gnu} CC,
6148 you can use the @samp{-gstabs} option to request stabs debugging
6149 extensions explicitly.) Where the object code format is standard
6150 @sc{coff} or @sc{dwarf} in @sc{elf}, on the other hand, most of the C++
6151 support in @value{GDBN} does @emph{not} work.
6152 @end quotation
6153
6154 @enumerate
6155
6156 @cindex member functions
6157 @item
6158 Member function calls are allowed; you can use expressions like
6159
6160 @example
6161 count = aml->GetOriginal(x, y)
6162 @end example
6163
6164 @kindex this
6165 @cindex namespace in C++
6166 @item
6167 While a member function is active (in the selected stack frame), your
6168 expressions have the same namespace available as the member function;
6169 that is, @value{GDBN} allows implicit references to the class instance
6170 pointer @code{this} following the same rules as C++.
6171
6172 @cindex call overloaded functions
6173 @cindex overloaded functions, calling
6174 @cindex type conversions in C++
6175 @item
6176 You can call overloaded functions; @value{GDBN} resolves the function
6177 call to the right definition, with some restrictions. @value{GDBN} does not
6178 perform overload resolution involving user-defined type conversions,
6179 calls to constructors, or instantiations of templates that do not exist
6180 in the program. It also cannot handle ellipsis argument lists or
6181 default arguments.
6182
6183 It does perform integral conversions and promotions, floating-point
6184 promotions, arithmetic conversions, pointer conversions, conversions of
6185 class objects to base classes, and standard conversions such as those of
6186 functions or arrays to pointers; it requires an exact match on the
6187 number of function arguments.
6188
6189 Overload resolution is always performed, unless you have specified
6190 @code{set overload-resolution off}. @xref{Debugging C plus plus,
6191 ,@value{GDBN} features for C++}.
6192
6193 You must specify @code{set overload-resolution off} in order to use an
6194 explicit function signature to call an overloaded function, as in
6195 @smallexample
6196 p 'foo(char,int)'('x', 13)
6197 @end smallexample
6198
6199 The @value{GDBN} command-completion facility can simplify this;
6200 see @ref{Completion, ,Command completion}.
6201
6202 @cindex reference declarations
6203 @item
6204 @value{GDBN} understands variables declared as C++ references; you can use
6205 them in expressions just as you do in C++ source---they are automatically
6206 dereferenced.
6207
6208 In the parameter list shown when @value{GDBN} displays a frame, the values of
6209 reference variables are not displayed (unlike other variables); this
6210 avoids clutter, since references are often used for large structures.
6211 The @emph{address} of a reference variable is always shown, unless
6212 you have specified @samp{set print address off}.
6213
6214 @item
6215 @value{GDBN} supports the C++ name resolution operator @code{::}---your
6216 expressions can use it just as expressions in your program do. Since
6217 one scope may be defined in another, you can use @code{::} repeatedly if
6218 necessary, for example in an expression like
6219 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
6220 resolving name scope by reference to source files, in both C and C++
6221 debugging (@pxref{Variables, ,Program variables}).
6222 @end enumerate
6223
6224 In addition, when used with HP's C++ compiler, @value{GDBN} supports
6225 calling virtual functions correctly, printing out virtual bases of
6226 objects, calling functions in a base subobject, casting objects, and
6227 invoking user-defined operators.
6228
6229 @node C Defaults
6230 @subsubsection C and C++ defaults
6231
6232 @cindex C and C++ defaults
6233
6234 If you allow @value{GDBN} to set type and range checking automatically, they
6235 both default to @code{off} whenever the working language changes to
6236 C or C++. This happens regardless of whether you or @value{GDBN}
6237 selects the working language.
6238
6239 If you allow @value{GDBN} to set the language automatically, it
6240 recognizes source files whose names end with @file{.c}, @file{.C}, or
6241 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
6242 these files, it sets the working language to C or C++.
6243 @xref{Automatically, ,Having @value{GDBN} infer the source language},
6244 for further details.
6245
6246 @c Type checking is (a) primarily motivated by Modula-2, and (b)
6247 @c unimplemented. If (b) changes, it might make sense to let this node
6248 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
6249
6250 @node C Checks
6251 @subsubsection C and C++ type and range checks
6252
6253 @cindex C and C++ checks
6254
6255 By default, when @value{GDBN} parses C or C++ expressions, type checking
6256 is not used. However, if you turn type checking on, @value{GDBN}
6257 considers two variables type equivalent if:
6258
6259 @itemize @bullet
6260 @item
6261 The two variables are structured and have the same structure, union, or
6262 enumerated tag.
6263
6264 @item
6265 The two variables have the same type name, or types that have been
6266 declared equivalent through @code{typedef}.
6267
6268 @ignore
6269 @c leaving this out because neither J Gilmore nor R Pesch understand it.
6270 @c FIXME--beers?
6271 @item
6272 The two @code{struct}, @code{union}, or @code{enum} variables are
6273 declared in the same declaration. (Note: this may not be true for all C
6274 compilers.)
6275 @end ignore
6276 @end itemize
6277
6278 Range checking, if turned on, is done on mathematical operations. Array
6279 indices are not checked, since they are often used to index a pointer
6280 that is not itself an array.
6281
6282 @node Debugging C
6283 @subsubsection @value{GDBN} and C
6284
6285 The @code{set print union} and @code{show print union} commands apply to
6286 the @code{union} type. When set to @samp{on}, any @code{union} that is
6287 inside a @code{struct} or @code{class} is also printed. Otherwise, it
6288 appears as @samp{@{...@}}.
6289
6290 The @code{@@} operator aids in the debugging of dynamic arrays, formed
6291 with pointers and a memory allocation function. @xref{Expressions,
6292 ,Expressions}.
6293
6294 @menu
6295 * Debugging C plus plus::
6296 @end menu
6297
6298 @node Debugging C plus plus
6299 @subsubsection @value{GDBN} features for C++
6300
6301 @cindex commands for C++
6302
6303 Some @value{GDBN} commands are particularly useful with C++, and some are
6304 designed specifically for use with C++. Here is a summary:
6305
6306 @table @code
6307 @cindex break in overloaded functions
6308 @item @r{breakpoint menus}
6309 When you want a breakpoint in a function whose name is overloaded,
6310 @value{GDBN} breakpoint menus help you specify which function definition
6311 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
6312
6313 @cindex overloading in C++
6314 @item rbreak @var{regex}
6315 Setting breakpoints using regular expressions is helpful for setting
6316 breakpoints on overloaded functions that are not members of any special
6317 classes.
6318 @xref{Set Breaks, ,Setting breakpoints}.
6319
6320 @cindex C++ exception handling
6321 @item catch throw
6322 @itemx catch catch
6323 Debug C++ exception handling using these commands. @xref{Set
6324 Catchpoints, , Setting catchpoints}.
6325
6326 @cindex inheritance
6327 @item ptype @var{typename}
6328 Print inheritance relationships as well as other information for type
6329 @var{typename}.
6330 @xref{Symbols, ,Examining the Symbol Table}.
6331
6332 @cindex C++ symbol display
6333 @item set print demangle
6334 @itemx show print demangle
6335 @itemx set print asm-demangle
6336 @itemx show print asm-demangle
6337 Control whether C++ symbols display in their source form, both when
6338 displaying code as C++ source and when displaying disassemblies.
6339 @xref{Print Settings, ,Print settings}.
6340
6341 @item set print object
6342 @itemx show print object
6343 Choose whether to print derived (actual) or declared types of objects.
6344 @xref{Print Settings, ,Print settings}.
6345
6346 @item set print vtbl
6347 @itemx show print vtbl
6348 Control the format for printing virtual function tables.
6349 @xref{Print Settings, ,Print settings}.
6350 (The @code{vtbl} commands do not work on programs compiled with the HP
6351 ANSI C++ compiler (@code{aCC}).)
6352
6353 @kindex set overload-resolution
6354 @cindex overloaded functions, overload resolution
6355 @item set overload-resolution on
6356 Enable overload resolution for C++ expression evaluation. The default
6357 is on. For overloaded functions, @value{GDBN} evaluates the arguments
6358 and searches for a function whose signature matches the argument types,
6359 using the standard C++ conversion rules (see @ref{C plus plus expressions, ,C++
6360 expressions}, for details). If it cannot find a match, it emits a
6361 message.
6362
6363 @item set overload-resolution off
6364 Disable overload resolution for C++ expression evaluation. For
6365 overloaded functions that are not class member functions, @value{GDBN}
6366 chooses the first function of the specified name that it finds in the
6367 symbol table, whether or not its arguments are of the correct type. For
6368 overloaded functions that are class member functions, @value{GDBN}
6369 searches for a function whose signature @emph{exactly} matches the
6370 argument types.
6371
6372 @item @r{Overloaded symbol names}
6373 You can specify a particular definition of an overloaded symbol, using
6374 the same notation that is used to declare such symbols in C++: type
6375 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
6376 also use the @value{GDBN} command-line word completion facilities to list the
6377 available choices, or to finish the type list for you.
6378 @xref{Completion,, Command completion}, for details on how to do this.
6379 @end table
6380
6381 @node Modula-2
6382 @subsection Modula-2
6383
6384 @cindex Modula-2, @value{GDBN} support
6385
6386 The extensions made to @value{GDBN} to support Modula-2 only support
6387 output from the @sc{gnu} Modula-2 compiler (which is currently being
6388 developed). Other Modula-2 compilers are not currently supported, and
6389 attempting to debug executables produced by them is most likely
6390 to give an error as @value{GDBN} reads in the executable's symbol
6391 table.
6392
6393 @cindex expressions in Modula-2
6394 @menu
6395 * M2 Operators:: Built-in operators
6396 * Built-In Func/Proc:: Built-in functions and procedures
6397 * M2 Constants:: Modula-2 constants
6398 * M2 Defaults:: Default settings for Modula-2
6399 * Deviations:: Deviations from standard Modula-2
6400 * M2 Checks:: Modula-2 type and range checks
6401 * M2 Scope:: The scope operators @code{::} and @code{.}
6402 * GDB/M2:: @value{GDBN} and Modula-2
6403 @end menu
6404
6405 @node M2 Operators
6406 @subsubsection Operators
6407 @cindex Modula-2 operators
6408
6409 Operators must be defined on values of specific types. For instance,
6410 @code{+} is defined on numbers, but not on structures. Operators are
6411 often defined on groups of types. For the purposes of Modula-2, the
6412 following definitions hold:
6413
6414 @itemize @bullet
6415
6416 @item
6417 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
6418 their subranges.
6419
6420 @item
6421 @emph{Character types} consist of @code{CHAR} and its subranges.
6422
6423 @item
6424 @emph{Floating-point types} consist of @code{REAL}.
6425
6426 @item
6427 @emph{Pointer types} consist of anything declared as @code{POINTER TO
6428 @var{type}}.
6429
6430 @item
6431 @emph{Scalar types} consist of all of the above.
6432
6433 @item
6434 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
6435
6436 @item
6437 @emph{Boolean types} consist of @code{BOOLEAN}.
6438 @end itemize
6439
6440 @noindent
6441 The following operators are supported, and appear in order of
6442 increasing precedence:
6443
6444 @table @code
6445 @item ,
6446 Function argument or array index separator.
6447
6448 @item :=
6449 Assignment. The value of @var{var} @code{:=} @var{value} is
6450 @var{value}.
6451
6452 @item <@r{, }>
6453 Less than, greater than on integral, floating-point, or enumerated
6454 types.
6455
6456 @item <=@r{, }>=
6457 Less than or equal to, greater than or equal to
6458 on integral, floating-point and enumerated types, or set inclusion on
6459 set types. Same precedence as @code{<}.
6460
6461 @item =@r{, }<>@r{, }#
6462 Equality and two ways of expressing inequality, valid on scalar types.
6463 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
6464 available for inequality, since @code{#} conflicts with the script
6465 comment character.
6466
6467 @item IN
6468 Set membership. Defined on set types and the types of their members.
6469 Same precedence as @code{<}.
6470
6471 @item OR
6472 Boolean disjunction. Defined on boolean types.
6473
6474 @item AND@r{, }&
6475 Boolean conjunction. Defined on boolean types.
6476
6477 @item @@
6478 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
6479
6480 @item +@r{, }-
6481 Addition and subtraction on integral and floating-point types, or union
6482 and difference on set types.
6483
6484 @item *
6485 Multiplication on integral and floating-point types, or set intersection
6486 on set types.
6487
6488 @item /
6489 Division on floating-point types, or symmetric set difference on set
6490 types. Same precedence as @code{*}.
6491
6492 @item DIV@r{, }MOD
6493 Integer division and remainder. Defined on integral types. Same
6494 precedence as @code{*}.
6495
6496 @item -
6497 Negative. Defined on @code{INTEGER} and @code{REAL} data.
6498
6499 @item ^
6500 Pointer dereferencing. Defined on pointer types.
6501
6502 @item NOT
6503 Boolean negation. Defined on boolean types. Same precedence as
6504 @code{^}.
6505
6506 @item .
6507 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
6508 precedence as @code{^}.
6509
6510 @item []
6511 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
6512
6513 @item ()
6514 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
6515 as @code{^}.
6516
6517 @item ::@r{, }.
6518 @value{GDBN} and Modula-2 scope operators.
6519 @end table
6520
6521 @quotation
6522 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
6523 treats the use of the operator @code{IN}, or the use of operators
6524 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
6525 @code{<=}, and @code{>=} on sets as an error.
6526 @end quotation
6527
6528 @cindex Modula-2 built-ins
6529 @node Built-In Func/Proc
6530 @subsubsection Built-in functions and procedures
6531
6532 Modula-2 also makes available several built-in procedures and functions.
6533 In describing these, the following metavariables are used:
6534
6535 @table @var
6536
6537 @item a
6538 represents an @code{ARRAY} variable.
6539
6540 @item c
6541 represents a @code{CHAR} constant or variable.
6542
6543 @item i
6544 represents a variable or constant of integral type.
6545
6546 @item m
6547 represents an identifier that belongs to a set. Generally used in the
6548 same function with the metavariable @var{s}. The type of @var{s} should
6549 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
6550
6551 @item n
6552 represents a variable or constant of integral or floating-point type.
6553
6554 @item r
6555 represents a variable or constant of floating-point type.
6556
6557 @item t
6558 represents a type.
6559
6560 @item v
6561 represents a variable.
6562
6563 @item x
6564 represents a variable or constant of one of many types. See the
6565 explanation of the function for details.
6566 @end table
6567
6568 All Modula-2 built-in procedures also return a result, described below.
6569
6570 @table @code
6571 @item ABS(@var{n})
6572 Returns the absolute value of @var{n}.
6573
6574 @item CAP(@var{c})
6575 If @var{c} is a lower case letter, it returns its upper case
6576 equivalent, otherwise it returns its argument.
6577
6578 @item CHR(@var{i})
6579 Returns the character whose ordinal value is @var{i}.
6580
6581 @item DEC(@var{v})
6582 Decrements the value in the variable @var{v} by one. Returns the new value.
6583
6584 @item DEC(@var{v},@var{i})
6585 Decrements the value in the variable @var{v} by @var{i}. Returns the
6586 new value.
6587
6588 @item EXCL(@var{m},@var{s})
6589 Removes the element @var{m} from the set @var{s}. Returns the new
6590 set.
6591
6592 @item FLOAT(@var{i})
6593 Returns the floating point equivalent of the integer @var{i}.
6594
6595 @item HIGH(@var{a})
6596 Returns the index of the last member of @var{a}.
6597
6598 @item INC(@var{v})
6599 Increments the value in the variable @var{v} by one. Returns the new value.
6600
6601 @item INC(@var{v},@var{i})
6602 Increments the value in the variable @var{v} by @var{i}. Returns the
6603 new value.
6604
6605 @item INCL(@var{m},@var{s})
6606 Adds the element @var{m} to the set @var{s} if it is not already
6607 there. Returns the new set.
6608
6609 @item MAX(@var{t})
6610 Returns the maximum value of the type @var{t}.
6611
6612 @item MIN(@var{t})
6613 Returns the minimum value of the type @var{t}.
6614
6615 @item ODD(@var{i})
6616 Returns boolean TRUE if @var{i} is an odd number.
6617
6618 @item ORD(@var{x})
6619 Returns the ordinal value of its argument. For example, the ordinal
6620 value of a character is its @sc{ascii} value (on machines supporting the
6621 @sc{ascii} character set). @var{x} must be of an ordered type, which include
6622 integral, character and enumerated types.
6623
6624 @item SIZE(@var{x})
6625 Returns the size of its argument. @var{x} can be a variable or a type.
6626
6627 @item TRUNC(@var{r})
6628 Returns the integral part of @var{r}.
6629
6630 @item VAL(@var{t},@var{i})
6631 Returns the member of the type @var{t} whose ordinal value is @var{i}.
6632 @end table
6633
6634 @quotation
6635 @emph{Warning:} Sets and their operations are not yet supported, so
6636 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
6637 an error.
6638 @end quotation
6639
6640 @cindex Modula-2 constants
6641 @node M2 Constants
6642 @subsubsection Constants
6643
6644 @value{GDBN} allows you to express the constants of Modula-2 in the following
6645 ways:
6646
6647 @itemize @bullet
6648
6649 @item
6650 Integer constants are simply a sequence of digits. When used in an
6651 expression, a constant is interpreted to be type-compatible with the
6652 rest of the expression. Hexadecimal integers are specified by a
6653 trailing @samp{H}, and octal integers by a trailing @samp{B}.
6654
6655 @item
6656 Floating point constants appear as a sequence of digits, followed by a
6657 decimal point and another sequence of digits. An optional exponent can
6658 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
6659 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
6660 digits of the floating point constant must be valid decimal (base 10)
6661 digits.
6662
6663 @item
6664 Character constants consist of a single character enclosed by a pair of
6665 like quotes, either single (@code{'}) or double (@code{"}). They may
6666 also be expressed by their ordinal value (their @sc{ascii} value, usually)
6667 followed by a @samp{C}.
6668
6669 @item
6670 String constants consist of a sequence of characters enclosed by a
6671 pair of like quotes, either single (@code{'}) or double (@code{"}).
6672 Escape sequences in the style of C are also allowed. @xref{C
6673 Constants, ,C and C++ constants}, for a brief explanation of escape
6674 sequences.
6675
6676 @item
6677 Enumerated constants consist of an enumerated identifier.
6678
6679 @item
6680 Boolean constants consist of the identifiers @code{TRUE} and
6681 @code{FALSE}.
6682
6683 @item
6684 Pointer constants consist of integral values only.
6685
6686 @item
6687 Set constants are not yet supported.
6688 @end itemize
6689
6690 @node M2 Defaults
6691 @subsubsection Modula-2 defaults
6692 @cindex Modula-2 defaults
6693
6694 If type and range checking are set automatically by @value{GDBN}, they
6695 both default to @code{on} whenever the working language changes to
6696 Modula-2. This happens regardless of whether you or @value{GDBN}
6697 selected the working language.
6698
6699 If you allow @value{GDBN} to set the language automatically, then entering
6700 code compiled from a file whose name ends with @file{.mod} sets the
6701 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
6702 the language automatically}, for further details.
6703
6704 @node Deviations
6705 @subsubsection Deviations from standard Modula-2
6706 @cindex Modula-2, deviations from
6707
6708 A few changes have been made to make Modula-2 programs easier to debug.
6709 This is done primarily via loosening its type strictness:
6710
6711 @itemize @bullet
6712 @item
6713 Unlike in standard Modula-2, pointer constants can be formed by
6714 integers. This allows you to modify pointer variables during
6715 debugging. (In standard Modula-2, the actual address contained in a
6716 pointer variable is hidden from you; it can only be modified
6717 through direct assignment to another pointer variable or expression that
6718 returned a pointer.)
6719
6720 @item
6721 C escape sequences can be used in strings and characters to represent
6722 non-printable characters. @value{GDBN} prints out strings with these
6723 escape sequences embedded. Single non-printable characters are
6724 printed using the @samp{CHR(@var{nnn})} format.
6725
6726 @item
6727 The assignment operator (@code{:=}) returns the value of its right-hand
6728 argument.
6729
6730 @item
6731 All built-in procedures both modify @emph{and} return their argument.
6732 @end itemize
6733
6734 @node M2 Checks
6735 @subsubsection Modula-2 type and range checks
6736 @cindex Modula-2 checks
6737
6738 @quotation
6739 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
6740 range checking.
6741 @end quotation
6742 @c FIXME remove warning when type/range checks added
6743
6744 @value{GDBN} considers two Modula-2 variables type equivalent if:
6745
6746 @itemize @bullet
6747 @item
6748 They are of types that have been declared equivalent via a @code{TYPE
6749 @var{t1} = @var{t2}} statement
6750
6751 @item
6752 They have been declared on the same line. (Note: This is true of the
6753 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
6754 @end itemize
6755
6756 As long as type checking is enabled, any attempt to combine variables
6757 whose types are not equivalent is an error.
6758
6759 Range checking is done on all mathematical operations, assignment, array
6760 index bounds, and all built-in functions and procedures.
6761
6762 @node M2 Scope
6763 @subsubsection The scope operators @code{::} and @code{.}
6764 @cindex scope
6765 @kindex .
6766 @cindex colon, doubled as scope operator
6767 @ifinfo
6768 @kindex colon-colon@r{, in Modula-2}
6769 @c Info cannot handle :: but TeX can.
6770 @end ifinfo
6771 @iftex
6772 @kindex ::
6773 @end iftex
6774
6775 There are a few subtle differences between the Modula-2 scope operator
6776 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
6777 similar syntax:
6778
6779 @example
6780
6781 @var{module} . @var{id}
6782 @var{scope} :: @var{id}
6783 @end example
6784
6785 @noindent
6786 where @var{scope} is the name of a module or a procedure,
6787 @var{module} the name of a module, and @var{id} is any declared
6788 identifier within your program, except another module.
6789
6790 Using the @code{::} operator makes @value{GDBN} search the scope
6791 specified by @var{scope} for the identifier @var{id}. If it is not
6792 found in the specified scope, then @value{GDBN} searches all scopes
6793 enclosing the one specified by @var{scope}.
6794
6795 Using the @code{.} operator makes @value{GDBN} search the current scope for
6796 the identifier specified by @var{id} that was imported from the
6797 definition module specified by @var{module}. With this operator, it is
6798 an error if the identifier @var{id} was not imported from definition
6799 module @var{module}, or if @var{id} is not an identifier in
6800 @var{module}.
6801
6802 @node GDB/M2
6803 @subsubsection @value{GDBN} and Modula-2
6804
6805 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
6806 Five subcommands of @code{set print} and @code{show print} apply
6807 specifically to C and C++: @samp{vtbl}, @samp{demangle},
6808 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
6809 apply to C++, and the last to the C @code{union} type, which has no direct
6810 analogue in Modula-2.
6811
6812 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
6813 with any language, is not useful with Modula-2. Its
6814 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
6815 created in Modula-2 as they can in C or C++. However, because an
6816 address can be specified by an integral constant, the construct
6817 @samp{@{@var{type}@}@var{adrexp}} is still useful.
6818
6819 @cindex @code{#} in Modula-2
6820 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
6821 interpreted as the beginning of a comment. Use @code{<>} instead.
6822
6823 @node Chill
6824 @subsection Chill
6825
6826 The extensions made to @value{GDBN} to support Chill only support output
6827 from the @sc{gnu} Chill compiler. Other Chill compilers are not currently
6828 supported, and attempting to debug executables produced by them is most
6829 likely to give an error as @value{GDBN} reads in the executable's symbol
6830 table.
6831
6832 @c This used to say "... following Chill related topics ...", but since
6833 @c menus are not shown in the printed manual, it would look awkward.
6834 This section covers the Chill related topics and the features
6835 of @value{GDBN} which support these topics.
6836
6837 @menu
6838 * How modes are displayed:: How modes are displayed
6839 * Locations:: Locations and their accesses
6840 * Values and their Operations:: Values and their Operations
6841 * Chill type and range checks::
6842 * Chill defaults::
6843 @end menu
6844
6845 @node How modes are displayed
6846 @subsubsection How modes are displayed
6847
6848 The Chill Datatype- (Mode) support of @value{GDBN} is directly related
6849 with the functionality of the @sc{gnu} Chill compiler, and therefore deviates
6850 slightly from the standard specification of the Chill language. The
6851 provided modes are:
6852
6853 @c FIXME: this @table's contents effectively disable @code by using @r
6854 @c on every @item. So why does it need @code?
6855 @table @code
6856 @item @r{@emph{Discrete modes:}}
6857 @itemize @bullet
6858 @item
6859 @emph{Integer Modes} which are predefined by @code{BYTE, UBYTE, INT,
6860 UINT, LONG, ULONG},
6861 @item
6862 @emph{Boolean Mode} which is predefined by @code{BOOL},
6863 @item
6864 @emph{Character Mode} which is predefined by @code{CHAR},
6865 @item
6866 @emph{Set Mode} which is displayed by the keyword @code{SET}.
6867 @smallexample
6868 (@value{GDBP}) ptype x
6869 type = SET (karli = 10, susi = 20, fritzi = 100)
6870 @end smallexample
6871 If the type is an unnumbered set the set element values are omitted.
6872 @item
6873 @emph{Range Mode} which is displayed by
6874 @smallexample
6875 @code{type = <basemode>(<lower bound> : <upper bound>)}
6876 @end smallexample
6877 where @code{<lower bound>, <upper bound>} can be of any discrete literal
6878 expression (e.g. set element names).
6879 @end itemize
6880
6881 @item @r{@emph{Powerset Mode:}}
6882 A Powerset Mode is displayed by the keyword @code{POWERSET} followed by
6883 the member mode of the powerset. The member mode can be any discrete mode.
6884 @smallexample
6885 (@value{GDBP}) ptype x
6886 type = POWERSET SET (egon, hugo, otto)
6887 @end smallexample
6888
6889 @item @r{@emph{Reference Modes:}}
6890 @itemize @bullet
6891 @item
6892 @emph{Bound Reference Mode} which is displayed by the keyword @code{REF}
6893 followed by the mode name to which the reference is bound.
6894 @item
6895 @emph{Free Reference Mode} which is displayed by the keyword @code{PTR}.
6896 @end itemize
6897
6898 @item @r{@emph{Procedure mode}}
6899 The procedure mode is displayed by @code{type = PROC(<parameter list>)
6900 <return mode> EXCEPTIONS (<exception list>)}. The @code{<parameter
6901 list>} is a list of the parameter modes. @code{<return mode>} indicates
6902 the mode of the result of the procedure if any. The exceptionlist lists
6903 all possible exceptions which can be raised by the procedure.
6904
6905 @ignore
6906 @item @r{@emph{Instance mode}}
6907 The instance mode is represented by a structure, which has a static
6908 type, and is therefore not really of interest.
6909 @end ignore
6910
6911 @item @r{@emph{Synchronization Modes:}}
6912 @itemize @bullet
6913 @item
6914 @emph{Event Mode} which is displayed by
6915 @smallexample
6916 @code{EVENT (<event length>)}
6917 @end smallexample
6918 where @code{(<event length>)} is optional.
6919 @item
6920 @emph{Buffer Mode} which is displayed by
6921 @smallexample
6922 @code{BUFFER (<buffer length>)<buffer element mode>}
6923 @end smallexample
6924 where @code{(<buffer length>)} is optional.
6925 @end itemize
6926
6927 @item @r{@emph{Timing Modes:}}
6928 @itemize @bullet
6929 @item
6930 @emph{Duration Mode} which is predefined by @code{DURATION}
6931 @item
6932 @emph{Absolute Time Mode} which is predefined by @code{TIME}
6933 @end itemize
6934
6935 @item @r{@emph{Real Modes:}}
6936 Real Modes are predefined with @code{REAL} and @code{LONG_REAL}.
6937
6938 @item @r{@emph{String Modes:}}
6939 @itemize @bullet
6940 @item
6941 @emph{Character String Mode} which is displayed by
6942 @smallexample
6943 @code{CHARS(<string length>)}
6944 @end smallexample
6945 followed by the keyword @code{VARYING} if the String Mode is a varying
6946 mode
6947 @item
6948 @emph{Bit String Mode} which is displayed by
6949 @smallexample
6950 @code{BOOLS(<string
6951 length>)}
6952 @end smallexample
6953 @end itemize
6954
6955 @item @r{@emph{Array Mode:}}
6956 The Array Mode is displayed by the keyword @code{ARRAY(<range>)}
6957 followed by the element mode (which may in turn be an array mode).
6958 @smallexample
6959 (@value{GDBP}) ptype x
6960 type = ARRAY (1:42)
6961 ARRAY (1:20)
6962 SET (karli = 10, susi = 20, fritzi = 100)
6963 @end smallexample
6964
6965 @item @r{@emph{Structure Mode}}
6966 The Structure mode is displayed by the keyword @code{STRUCT(<field
6967 list>)}. The @code{<field list>} consists of names and modes of fields
6968 of the structure. Variant structures have the keyword @code{CASE <field>
6969 OF <variant fields> ESAC} in their field list. Since the current version
6970 of the GNU Chill compiler doesn't implement tag processing (no runtime
6971 checks of variant fields, and therefore no debugging info), the output
6972 always displays all variant fields.
6973 @smallexample
6974 (@value{GDBP}) ptype str
6975 type = STRUCT (
6976 as x,
6977 bs x,
6978 CASE bs OF
6979 (karli):
6980 cs a
6981 (ott):
6982 ds x
6983 ESAC
6984 )
6985 @end smallexample
6986 @end table
6987
6988 @node Locations
6989 @subsubsection Locations and their accesses
6990
6991 A location in Chill is an object which can contain values.
6992
6993 A value of a location is generally accessed by the (declared) name of
6994 the location. The output conforms to the specification of values in
6995 Chill programs. How values are specified
6996 is the topic of the next section, @ref{Values and their Operations}.
6997
6998 The pseudo-location @code{RESULT} (or @code{result}) can be used to
6999 display or change the result of a currently-active procedure:
7000
7001 @smallexample
7002 set result := EXPR
7003 @end smallexample
7004
7005 @noindent
7006 This does the same as the Chill action @code{RESULT EXPR} (which
7007 is not available in @value{GDBN}).
7008
7009 Values of reference mode locations are printed by @code{PTR(<hex
7010 value>)} in case of a free reference mode, and by @code{(REF <reference
7011 mode>) (<hex-value>)} in case of a bound reference. @code{<hex value>}
7012 represents the address where the reference points to. To access the
7013 value of the location referenced by the pointer, use the dereference
7014 operator @samp{->}.
7015
7016 Values of procedure mode locations are displayed by
7017 @smallexample
7018 @code{@{ PROC
7019 (<argument modes> ) <return mode> @} <address> <name of procedure
7020 location>}
7021 @end smallexample
7022 @code{<argument modes>} is a list of modes according to the parameter
7023 specification of the procedure and @code{<address>} shows the address of
7024 the entry point.
7025
7026 @ignore
7027 Locations of instance modes are displayed just like a structure with two
7028 fields specifying the @emph{process type} and the @emph{copy number} of
7029 the investigated instance location@footnote{This comes from the current
7030 implementation of instances. They are implemented as a structure (no
7031 na). The output should be something like @code{[<name of the process>;
7032 <instance number>]}.}. The field names are @code{__proc_type} and
7033 @code{__proc_copy}.
7034
7035 Locations of synchronization modes are displayed like a structure with
7036 the field name @code{__event_data} in case of a event mode location, and
7037 like a structure with the field @code{__buffer_data} in case of a buffer
7038 mode location (refer to previous paragraph).
7039
7040 Structure Mode locations are printed by @code{[.<field name>: <value>,
7041 ...]}. The @code{<field name>} corresponds to the structure mode
7042 definition and the layout of @code{<value>} varies depending of the mode
7043 of the field. If the investigated structure mode location is of variant
7044 structure mode, the variant parts of the structure are enclosed in curled
7045 braces (@samp{@{@}}). Fields enclosed by @samp{@{,@}} are residing
7046 on the same memory location and represent the current values of the
7047 memory location in their specific modes. Since no tag processing is done
7048 all variants are displayed. A variant field is printed by
7049 @code{(<variant name>) = .<field name>: <value>}. (who implements the
7050 stuff ???)
7051 @smallexample
7052 (@value{GDBP}) print str1 $4 = [.as: 0, .bs: karli, .<TAG>: { (karli) =
7053 [.cs: []], (susi) = [.ds: susi]}]
7054 @end smallexample
7055 @end ignore
7056
7057 Substructures of string mode-, array mode- or structure mode-values
7058 (e.g. array slices, fields of structure locations) are accessed using
7059 certain operations which are described in the next section, @ref{Values
7060 and their Operations}.
7061
7062 A location value may be interpreted as having a different mode using the
7063 location conversion. This mode conversion is written as @code{<mode
7064 name>(<location>)}. The user has to consider that the sizes of the modes
7065 have to be equal otherwise an error occurs. Furthermore, no range
7066 checking of the location against the destination mode is performed, and
7067 therefore the result can be quite confusing.
7068
7069 @smallexample
7070 (@value{GDBP}) print int (s(3 up 4)) XXX TO be filled in !! XXX
7071 @end smallexample
7072
7073 @node Values and their Operations
7074 @subsubsection Values and their Operations
7075
7076 Values are used to alter locations, to investigate complex structures in
7077 more detail or to filter relevant information out of a large amount of
7078 data. There are several (mode dependent) operations defined which enable
7079 such investigations. These operations are not only applicable to
7080 constant values but also to locations, which can become quite useful
7081 when debugging complex structures. During parsing the command line
7082 (e.g. evaluating an expression) @value{GDBN} treats location names as
7083 the values behind these locations.
7084
7085 This section describes how values have to be specified and which
7086 operations are legal to be used with such values.
7087
7088 @table @code
7089 @item Literal Values
7090 Literal values are specified in the same manner as in @sc{gnu} Chill programs.
7091 For detailed specification refer to the @sc{gnu} Chill implementation Manual
7092 chapter 1.5.
7093 @c FIXME: if the Chill Manual is a Texinfo documents, the above should
7094 @c be converted to a @ref.
7095
7096 @ignore
7097 @itemize @bullet
7098 @item
7099 @emph{Integer Literals} are specified in the same manner as in Chill
7100 programs (refer to the Chill Standard z200/88 chpt 5.2.4.2)
7101 @item
7102 @emph{Boolean Literals} are defined by @code{TRUE} and @code{FALSE}.
7103 @item
7104 @emph{Character Literals} are defined by @code{'<character>'}. (e.g.
7105 @code{'M'})
7106 @item
7107 @emph{Set Literals} are defined by a name which was specified in a set
7108 mode. The value delivered by a Set Literal is the set value. This is
7109 comparable to an enumeration in C/C++ language.
7110 @item
7111 @emph{Emptiness Literal} is predefined by @code{NULL}. The value of the
7112 emptiness literal delivers either the empty reference value, the empty
7113 procedure value or the empty instance value.
7114
7115 @item
7116 @emph{Character String Literals} are defined by a sequence of characters
7117 enclosed in single- or double quotes. If a single- or double quote has
7118 to be part of the string literal it has to be stuffed (specified twice).
7119 @item
7120 @emph{Bitstring Literals} are specified in the same manner as in Chill
7121 programs (refer z200/88 chpt 5.2.4.8).
7122 @item
7123 @emph{Floating point literals} are specified in the same manner as in
7124 (gnu-)Chill programs (refer @sc{gnu} Chill implementation Manual chapter 1.5).
7125 @end itemize
7126 @end ignore
7127
7128 @item Tuple Values
7129 A tuple is specified by @code{<mode name>[<tuple>]}, where @code{<mode
7130 name>} can be omitted if the mode of the tuple is unambiguous. This
7131 unambiguity is derived from the context of a evaluated expression.
7132 @code{<tuple>} can be one of the following:
7133
7134 @itemize @bullet
7135 @item @emph{Powerset Tuple}
7136 @item @emph{Array Tuple}
7137 @item @emph{Structure Tuple}
7138 Powerset tuples, array tuples and structure tuples are specified in the
7139 same manner as in Chill programs refer to z200/88 chpt 5.2.5.
7140 @end itemize
7141
7142 @item String Element Value
7143 A string element value is specified by
7144 @smallexample
7145 @code{<string value>(<index>)}
7146 @end smallexample
7147 where @code{<index>} is a integer expression. It delivers a character
7148 value which is equivalent to the character indexed by @code{<index>} in
7149 the string.
7150
7151 @item String Slice Value
7152 A string slice value is specified by @code{<string value>(<slice
7153 spec>)}, where @code{<slice spec>} can be either a range of integer
7154 expressions or specified by @code{<start expr> up <size>}.
7155 @code{<size>} denotes the number of elements which the slice contains.
7156 The delivered value is a string value, which is part of the specified
7157 string.
7158
7159 @item Array Element Values
7160 An array element value is specified by @code{<array value>(<expr>)} and
7161 delivers a array element value of the mode of the specified array.
7162
7163 @item Array Slice Values
7164 An array slice is specified by @code{<array value>(<slice spec>)}, where
7165 @code{<slice spec>} can be either a range specified by expressions or by
7166 @code{<start expr> up <size>}. @code{<size>} denotes the number of
7167 arrayelements the slice contains. The delivered value is an array value
7168 which is part of the specified array.
7169
7170 @item Structure Field Values
7171 A structure field value is derived by @code{<structure value>.<field
7172 name>}, where @code{<field name>} indicates the name of a field specified
7173 in the mode definition of the structure. The mode of the delivered value
7174 corresponds to this mode definition in the structure definition.
7175
7176 @item Procedure Call Value
7177 The procedure call value is derived from the return value of the
7178 procedure@footnote{If a procedure call is used for instance in an
7179 expression, then this procedure is called with all its side
7180 effects. This can lead to confusing results if used carelessly.}.
7181
7182 Values of duration mode locations are represented by @code{ULONG} literals.
7183
7184 Values of time mode locations appear as
7185 @smallexample
7186 @code{TIME(<secs>:<nsecs>)}
7187 @end smallexample
7188
7189
7190 @ignore
7191 This is not implemented yet:
7192 @item Built-in Value
7193 @noindent
7194 The following built in functions are provided:
7195
7196 @table @code
7197 @item @code{ADDR()}
7198 @item @code{NUM()}
7199 @item @code{PRED()}
7200 @item @code{SUCC()}
7201 @item @code{ABS()}
7202 @item @code{CARD()}
7203 @item @code{MAX()}
7204 @item @code{MIN()}
7205 @item @code{SIZE()}
7206 @item @code{UPPER()}
7207 @item @code{LOWER()}
7208 @item @code{LENGTH()}
7209 @item @code{SIN()}
7210 @item @code{COS()}
7211 @item @code{TAN()}
7212 @item @code{ARCSIN()}
7213 @item @code{ARCCOS()}
7214 @item @code{ARCTAN()}
7215 @item @code{EXP()}
7216 @item @code{LN()}
7217 @item @code{LOG()}
7218 @item @code{SQRT()}
7219 @end table
7220
7221 For a detailed description refer to the GNU Chill implementation manual
7222 chapter 1.6.
7223 @end ignore
7224
7225 @item Zero-adic Operator Value
7226 The zero-adic operator value is derived from the instance value for the
7227 current active process.
7228
7229 @item Expression Values
7230 The value delivered by an expression is the result of the evaluation of
7231 the specified expression. If there are error conditions (mode
7232 incompatibility, etc.) the evaluation of expressions is aborted with a
7233 corresponding error message. Expressions may be parenthesised which
7234 causes the evaluation of this expression before any other expression
7235 which uses the result of the parenthesised expression. The following
7236 operators are supported by @value{GDBN}:
7237
7238 @table @code
7239 @item @code{OR, ORIF, XOR}
7240 @itemx @code{AND, ANDIF}
7241 @itemx @code{NOT}
7242 Logical operators defined over operands of boolean mode.
7243
7244 @item @code{=, /=}
7245 Equality and inequality operators defined over all modes.
7246
7247 @item @code{>, >=}
7248 @itemx @code{<, <=}
7249 Relational operators defined over predefined modes.
7250
7251 @item @code{+, -}
7252 @itemx @code{*, /, MOD, REM}
7253 Arithmetic operators defined over predefined modes.
7254
7255 @item @code{-}
7256 Change sign operator.
7257
7258 @item @code{//}
7259 String concatenation operator.
7260
7261 @item @code{()}
7262 String repetition operator.
7263
7264 @item @code{->}
7265 Referenced location operator which can be used either to take the
7266 address of a location (@code{->loc}), or to dereference a reference
7267 location (@code{loc->}).
7268
7269 @item @code{OR, XOR}
7270 @itemx @code{AND}
7271 @itemx @code{NOT}
7272 Powerset and bitstring operators.
7273
7274 @item @code{>, >=}
7275 @itemx @code{<, <=}
7276 Powerset inclusion operators.
7277
7278 @item @code{IN}
7279 Membership operator.
7280 @end table
7281 @end table
7282
7283 @node Chill type and range checks
7284 @subsubsection Chill type and range checks
7285
7286 @value{GDBN} considers two Chill variables mode equivalent if the sizes
7287 of the two modes are equal. This rule applies recursively to more
7288 complex datatypes which means that complex modes are treated
7289 equivalent if all element modes (which also can be complex modes like
7290 structures, arrays, etc.) have the same size.
7291
7292 Range checking is done on all mathematical operations, assignment, array
7293 index bounds and all built in procedures.
7294
7295 Strong type checks are forced using the @value{GDBN} command @code{set
7296 check strong}. This enforces strong type and range checks on all
7297 operations where Chill constructs are used (expressions, built in
7298 functions, etc.) in respect to the semantics as defined in the z.200
7299 language specification.
7300
7301 All checks can be disabled by the @value{GDBN} command @code{set check
7302 off}.
7303
7304 @ignore
7305 @c Deviations from the Chill Standard Z200/88
7306 see last paragraph ?
7307 @end ignore
7308
7309 @node Chill defaults
7310 @subsubsection Chill defaults
7311
7312 If type and range checking are set automatically by @value{GDBN}, they
7313 both default to @code{on} whenever the working language changes to
7314 Chill. This happens regardless of whether you or @value{GDBN}
7315 selected the working language.
7316
7317 If you allow @value{GDBN} to set the language automatically, then entering
7318 code compiled from a file whose name ends with @file{.ch} sets the
7319 working language to Chill. @xref{Automatically, ,Having @value{GDBN} set
7320 the language automatically}, for further details.
7321
7322 @node Symbols
7323 @chapter Examining the Symbol Table
7324
7325 The commands described in this chapter allow you to inquire about the
7326 symbols (names of variables, functions and types) defined in your
7327 program. This information is inherent in the text of your program and
7328 does not change as your program executes. @value{GDBN} finds it in your
7329 program's symbol table, in the file indicated when you started @value{GDBN}
7330 (@pxref{File Options, ,Choosing files}), or by one of the
7331 file-management commands (@pxref{Files, ,Commands to specify files}).
7332
7333 @cindex symbol names
7334 @cindex names of symbols
7335 @cindex quoting names
7336 Occasionally, you may need to refer to symbols that contain unusual
7337 characters, which @value{GDBN} ordinarily treats as word delimiters. The
7338 most frequent case is in referring to static variables in other
7339 source files (@pxref{Variables,,Program variables}). File names
7340 are recorded in object files as debugging symbols, but @value{GDBN} would
7341 ordinarily parse a typical file name, like @file{foo.c}, as the three words
7342 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
7343 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
7344
7345 @example
7346 p 'foo.c'::x
7347 @end example
7348
7349 @noindent
7350 looks up the value of @code{x} in the scope of the file @file{foo.c}.
7351
7352 @table @code
7353 @kindex info address
7354 @item info address @var{symbol}
7355 Describe where the data for @var{symbol} is stored. For a register
7356 variable, this says which register it is kept in. For a non-register
7357 local variable, this prints the stack-frame offset at which the variable
7358 is always stored.
7359
7360 Note the contrast with @samp{print &@var{symbol}}, which does not work
7361 at all for a register variable, and for a stack local variable prints
7362 the exact address of the current instantiation of the variable.
7363
7364 @kindex whatis
7365 @item whatis @var{expr}
7366 Print the data type of expression @var{expr}. @var{expr} is not
7367 actually evaluated, and any side-effecting operations (such as
7368 assignments or function calls) inside it do not take place.
7369 @xref{Expressions, ,Expressions}.
7370
7371 @item whatis
7372 Print the data type of @code{$}, the last value in the value history.
7373
7374 @kindex ptype
7375 @item ptype @var{typename}
7376 Print a description of data type @var{typename}. @var{typename} may be
7377 the name of a type, or for C code it may have the form @samp{class
7378 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
7379 @var{union-tag}} or @samp{enum @var{enum-tag}}.
7380
7381 @item ptype @var{expr}
7382 @itemx ptype
7383 Print a description of the type of expression @var{expr}. @code{ptype}
7384 differs from @code{whatis} by printing a detailed description, instead
7385 of just the name of the type.
7386
7387 For example, for this variable declaration:
7388
7389 @example
7390 struct complex @{double real; double imag;@} v;
7391 @end example
7392
7393 @noindent
7394 the two commands give this output:
7395
7396 @example
7397 @group
7398 (@value{GDBP}) whatis v
7399 type = struct complex
7400 (@value{GDBP}) ptype v
7401 type = struct complex @{
7402 double real;
7403 double imag;
7404 @}
7405 @end group
7406 @end example
7407
7408 @noindent
7409 As with @code{whatis}, using @code{ptype} without an argument refers to
7410 the type of @code{$}, the last value in the value history.
7411
7412 @kindex info types
7413 @item info types @var{regexp}
7414 @itemx info types
7415 Print a brief description of all types whose names match @var{regexp}
7416 (or all types in your program, if you supply no argument). Each
7417 complete typename is matched as though it were a complete line; thus,
7418 @samp{i type value} gives information on all types in your program whose
7419 names include the string @code{value}, but @samp{i type ^value$} gives
7420 information only on types whose complete name is @code{value}.
7421
7422 This command differs from @code{ptype} in two ways: first, like
7423 @code{whatis}, it does not print a detailed description; second, it
7424 lists all source files where a type is defined.
7425
7426 @kindex info source
7427 @item info source
7428 Show the name of the current source file---that is, the source file for
7429 the function containing the current point of execution---and the language
7430 it was written in.
7431
7432 @kindex info sources
7433 @item info sources
7434 Print the names of all source files in your program for which there is
7435 debugging information, organized into two lists: files whose symbols
7436 have already been read, and files whose symbols will be read when needed.
7437
7438 @kindex info functions
7439 @item info functions
7440 Print the names and data types of all defined functions.
7441
7442 @item info functions @var{regexp}
7443 Print the names and data types of all defined functions
7444 whose names contain a match for regular expression @var{regexp}.
7445 Thus, @samp{info fun step} finds all functions whose names
7446 include @code{step}; @samp{info fun ^step} finds those whose names
7447 start with @code{step}.
7448
7449 @kindex info variables
7450 @item info variables
7451 Print the names and data types of all variables that are declared
7452 outside of functions (i.e., excluding local variables).
7453
7454 @item info variables @var{regexp}
7455 Print the names and data types of all variables (except for local
7456 variables) whose names contain a match for regular expression
7457 @var{regexp}.
7458
7459 @ignore
7460 This was never implemented.
7461 @kindex info methods
7462 @item info methods
7463 @itemx info methods @var{regexp}
7464 The @code{info methods} command permits the user to examine all defined
7465 methods within C++ program, or (with the @var{regexp} argument) a
7466 specific set of methods found in the various C++ classes. Many
7467 C++ classes provide a large number of methods. Thus, the output
7468 from the @code{ptype} command can be overwhelming and hard to use. The
7469 @code{info-methods} command filters the methods, printing only those
7470 which match the regular-expression @var{regexp}.
7471 @end ignore
7472
7473 @cindex reloading symbols
7474 Some systems allow individual object files that make up your program to
7475 be replaced without stopping and restarting your program. For example,
7476 in VxWorks you can simply recompile a defective object file and keep on
7477 running. If you are running on one of these systems, you can allow
7478 @value{GDBN} to reload the symbols for automatically relinked modules:
7479
7480 @table @code
7481 @kindex set symbol-reloading
7482 @item set symbol-reloading on
7483 Replace symbol definitions for the corresponding source file when an
7484 object file with a particular name is seen again.
7485
7486 @item set symbol-reloading off
7487 Do not replace symbol definitions when encountering object files of the
7488 same name more than once. This is the default state; if you are not
7489 running on a system that permits automatic relinking of modules, you
7490 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
7491 may discard symbols when linking large programs, that may contain
7492 several modules (from different directories or libraries) with the same
7493 name.
7494
7495 @kindex show symbol-reloading
7496 @item show symbol-reloading
7497 Show the current @code{on} or @code{off} setting.
7498 @end table
7499
7500 @kindex set opaque-type-resolution
7501 @item set opaque-type-resolution on
7502 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
7503 declared as a pointer to a @code{struct}, @code{class}, or
7504 @code{union}---for example, @code{struct MyType *}---that is used in one
7505 source file although the full declaration of @code{struct MyType} is in
7506 another source file. The default is on.
7507
7508 A change in the setting of this subcommand will not take effect until
7509 the next time symbols for a file are loaded.
7510
7511 @item set opaque-type-resolution off
7512 Tell @value{GDBN} not to resolve opaque types. In this case, the type
7513 is printed as follows:
7514 @smallexample
7515 @{<no data fields>@}
7516 @end smallexample
7517
7518 @kindex show opaque-type-resolution
7519 @item show opaque-type-resolution
7520 Show whether opaque types are resolved or not.
7521
7522 @kindex maint print symbols
7523 @cindex symbol dump
7524 @kindex maint print psymbols
7525 @cindex partial symbol dump
7526 @item maint print symbols @var{filename}
7527 @itemx maint print psymbols @var{filename}
7528 @itemx maint print msymbols @var{filename}
7529 Write a dump of debugging symbol data into the file @var{filename}.
7530 These commands are used to debug the @value{GDBN} symbol-reading code. Only
7531 symbols with debugging data are included. If you use @samp{maint print
7532 symbols}, @value{GDBN} includes all the symbols for which it has already
7533 collected full details: that is, @var{filename} reflects symbols for
7534 only those files whose symbols @value{GDBN} has read. You can use the
7535 command @code{info sources} to find out which files these are. If you
7536 use @samp{maint print psymbols} instead, the dump shows information about
7537 symbols that @value{GDBN} only knows partially---that is, symbols defined in
7538 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
7539 @samp{maint print msymbols} dumps just the minimal symbol information
7540 required for each object file from which @value{GDBN} has read some symbols.
7541 @xref{Files, ,Commands to specify files}, for a discussion of how
7542 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
7543 @end table
7544
7545 @node Altering
7546 @chapter Altering Execution
7547
7548 Once you think you have found an error in your program, you might want to
7549 find out for certain whether correcting the apparent error would lead to
7550 correct results in the rest of the run. You can find the answer by
7551 experiment, using the @value{GDBN} features for altering execution of the
7552 program.
7553
7554 For example, you can store new values into variables or memory
7555 locations, give your program a signal, restart it at a different
7556 address, or even return prematurely from a function.
7557
7558 @menu
7559 * Assignment:: Assignment to variables
7560 * Jumping:: Continuing at a different address
7561 * Signaling:: Giving your program a signal
7562 * Returning:: Returning from a function
7563 * Calling:: Calling your program's functions
7564 * Patching:: Patching your program
7565 @end menu
7566
7567 @node Assignment
7568 @section Assignment to variables
7569
7570 @cindex assignment
7571 @cindex setting variables
7572 To alter the value of a variable, evaluate an assignment expression.
7573 @xref{Expressions, ,Expressions}. For example,
7574
7575 @example
7576 print x=4
7577 @end example
7578
7579 @noindent
7580 stores the value 4 into the variable @code{x}, and then prints the
7581 value of the assignment expression (which is 4).
7582 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
7583 information on operators in supported languages.
7584
7585 @kindex set variable
7586 @cindex variables, setting
7587 If you are not interested in seeing the value of the assignment, use the
7588 @code{set} command instead of the @code{print} command. @code{set} is
7589 really the same as @code{print} except that the expression's value is
7590 not printed and is not put in the value history (@pxref{Value History,
7591 ,Value history}). The expression is evaluated only for its effects.
7592
7593 If the beginning of the argument string of the @code{set} command
7594 appears identical to a @code{set} subcommand, use the @code{set
7595 variable} command instead of just @code{set}. This command is identical
7596 to @code{set} except for its lack of subcommands. For example, if your
7597 program has a variable @code{width}, you get an error if you try to set
7598 a new value with just @samp{set width=13}, because @value{GDBN} has the
7599 command @code{set width}:
7600
7601 @example
7602 (@value{GDBP}) whatis width
7603 type = double
7604 (@value{GDBP}) p width
7605 $4 = 13
7606 (@value{GDBP}) set width=47
7607 Invalid syntax in expression.
7608 @end example
7609
7610 @noindent
7611 The invalid expression, of course, is @samp{=47}. In
7612 order to actually set the program's variable @code{width}, use
7613
7614 @example
7615 (@value{GDBP}) set var width=47
7616 @end example
7617
7618 Because the @code{set} command has many subcommands that can conflict
7619 with the names of program variables, it is a good idea to use the
7620 @code{set variable} command instead of just @code{set}. For example, if
7621 your program has a variable @code{g}, you run into problems if you try
7622 to set a new value with just @samp{set g=4}, because @value{GDBN} has
7623 the command @code{set gnutarget}, abbreviated @code{set g}:
7624
7625 @example
7626 @group
7627 (@value{GDBP}) whatis g
7628 type = double
7629 (@value{GDBP}) p g
7630 $1 = 1
7631 (@value{GDBP}) set g=4
7632 (@value{GDBP}) p g
7633 $2 = 1
7634 (@value{GDBP}) r
7635 The program being debugged has been started already.
7636 Start it from the beginning? (y or n) y
7637 Starting program: /home/smith/cc_progs/a.out
7638 "/home/smith/cc_progs/a.out": can't open to read symbols:
7639 Invalid bfd target.
7640 (@value{GDBP}) show g
7641 The current BFD target is "=4".
7642 @end group
7643 @end example
7644
7645 @noindent
7646 The program variable @code{g} did not change, and you silently set the
7647 @code{gnutarget} to an invalid value. In order to set the variable
7648 @code{g}, use
7649
7650 @example
7651 (@value{GDBP}) set var g=4
7652 @end example
7653
7654 @value{GDBN} allows more implicit conversions in assignments than C; you can
7655 freely store an integer value into a pointer variable or vice versa,
7656 and you can convert any structure to any other structure that is the
7657 same length or shorter.
7658 @comment FIXME: how do structs align/pad in these conversions?
7659 @comment /doc@cygnus.com 18dec1990
7660
7661 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
7662 construct to generate a value of specified type at a specified address
7663 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
7664 to memory location @code{0x83040} as an integer (which implies a certain size
7665 and representation in memory), and
7666
7667 @example
7668 set @{int@}0x83040 = 4
7669 @end example
7670
7671 @noindent
7672 stores the value 4 into that memory location.
7673
7674 @node Jumping
7675 @section Continuing at a different address
7676
7677 Ordinarily, when you continue your program, you do so at the place where
7678 it stopped, with the @code{continue} command. You can instead continue at
7679 an address of your own choosing, with the following commands:
7680
7681 @table @code
7682 @kindex jump
7683 @item jump @var{linespec}
7684 Resume execution at line @var{linespec}. Execution stops again
7685 immediately if there is a breakpoint there. @xref{List, ,Printing
7686 source lines}, for a description of the different forms of
7687 @var{linespec}. It is common practice to use the @code{tbreak} command
7688 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
7689 breakpoints}.
7690
7691 The @code{jump} command does not change the current stack frame, or
7692 the stack pointer, or the contents of any memory location or any
7693 register other than the program counter. If line @var{linespec} is in
7694 a different function from the one currently executing, the results may
7695 be bizarre if the two functions expect different patterns of arguments or
7696 of local variables. For this reason, the @code{jump} command requests
7697 confirmation if the specified line is not in the function currently
7698 executing. However, even bizarre results are predictable if you are
7699 well acquainted with the machine-language code of your program.
7700
7701 @item jump *@var{address}
7702 Resume execution at the instruction at address @var{address}.
7703 @end table
7704
7705 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
7706 On many systems, you can get much the same effect as the @code{jump}
7707 command by storing a new value into the register @code{$pc}. The
7708 difference is that this does not start your program running; it only
7709 changes the address of where it @emph{will} run when you continue. For
7710 example,
7711
7712 @example
7713 set $pc = 0x485
7714 @end example
7715
7716 @noindent
7717 makes the next @code{continue} command or stepping command execute at
7718 address @code{0x485}, rather than at the address where your program stopped.
7719 @xref{Continuing and Stepping, ,Continuing and stepping}.
7720
7721 The most common occasion to use the @code{jump} command is to back
7722 up---perhaps with more breakpoints set---over a portion of a program
7723 that has already executed, in order to examine its execution in more
7724 detail.
7725
7726 @c @group
7727 @node Signaling
7728 @section Giving your program a signal
7729
7730 @table @code
7731 @kindex signal
7732 @item signal @var{signal}
7733 Resume execution where your program stopped, but immediately give it the
7734 signal @var{signal}. @var{signal} can be the name or the number of a
7735 signal. For example, on many systems @code{signal 2} and @code{signal
7736 SIGINT} are both ways of sending an interrupt signal.
7737
7738 Alternatively, if @var{signal} is zero, continue execution without
7739 giving a signal. This is useful when your program stopped on account of
7740 a signal and would ordinary see the signal when resumed with the
7741 @code{continue} command; @samp{signal 0} causes it to resume without a
7742 signal.
7743
7744 @code{signal} does not repeat when you press @key{RET} a second time
7745 after executing the command.
7746 @end table
7747 @c @end group
7748
7749 Invoking the @code{signal} command is not the same as invoking the
7750 @code{kill} utility from the shell. Sending a signal with @code{kill}
7751 causes @value{GDBN} to decide what to do with the signal depending on
7752 the signal handling tables (@pxref{Signals}). The @code{signal} command
7753 passes the signal directly to your program.
7754
7755
7756 @node Returning
7757 @section Returning from a function
7758
7759 @table @code
7760 @cindex returning from a function
7761 @kindex return
7762 @item return
7763 @itemx return @var{expression}
7764 You can cancel execution of a function call with the @code{return}
7765 command. If you give an
7766 @var{expression} argument, its value is used as the function's return
7767 value.
7768 @end table
7769
7770 When you use @code{return}, @value{GDBN} discards the selected stack frame
7771 (and all frames within it). You can think of this as making the
7772 discarded frame return prematurely. If you wish to specify a value to
7773 be returned, give that value as the argument to @code{return}.
7774
7775 This pops the selected stack frame (@pxref{Selection, ,Selecting a
7776 frame}), and any other frames inside of it, leaving its caller as the
7777 innermost remaining frame. That frame becomes selected. The
7778 specified value is stored in the registers used for returning values
7779 of functions.
7780
7781 The @code{return} command does not resume execution; it leaves the
7782 program stopped in the state that would exist if the function had just
7783 returned. In contrast, the @code{finish} command (@pxref{Continuing
7784 and Stepping, ,Continuing and stepping}) resumes execution until the
7785 selected stack frame returns naturally.
7786
7787 @node Calling
7788 @section Calling program functions
7789
7790 @cindex calling functions
7791 @kindex call
7792 @table @code
7793 @item call @var{expr}
7794 Evaluate the expression @var{expr} without displaying @code{void}
7795 returned values.
7796 @end table
7797
7798 You can use this variant of the @code{print} command if you want to
7799 execute a function from your program, but without cluttering the output
7800 with @code{void} returned values. If the result is not void, it
7801 is printed and saved in the value history.
7802
7803 For the A29K, a user-controlled variable @code{call_scratch_address},
7804 specifies the location of a scratch area to be used when @value{GDBN}
7805 calls a function in the target. This is necessary because the usual
7806 method of putting the scratch area on the stack does not work in systems
7807 that have separate instruction and data spaces.
7808
7809 @node Patching
7810 @section Patching programs
7811
7812 @cindex patching binaries
7813 @cindex writing into executables
7814 @cindex writing into corefiles
7815
7816 By default, @value{GDBN} opens the file containing your program's
7817 executable code (or the corefile) read-only. This prevents accidental
7818 alterations to machine code; but it also prevents you from intentionally
7819 patching your program's binary.
7820
7821 If you'd like to be able to patch the binary, you can specify that
7822 explicitly with the @code{set write} command. For example, you might
7823 want to turn on internal debugging flags, or even to make emergency
7824 repairs.
7825
7826 @table @code
7827 @kindex set write
7828 @item set write on
7829 @itemx set write off
7830 If you specify @samp{set write on}, @value{GDBN} opens executable and
7831 core files for both reading and writing; if you specify @samp{set write
7832 off} (the default), @value{GDBN} opens them read-only.
7833
7834 If you have already loaded a file, you must load it again (using the
7835 @code{exec-file} or @code{core-file} command) after changing @code{set
7836 write}, for your new setting to take effect.
7837
7838 @item show write
7839 @kindex show write
7840 Display whether executable files and core files are opened for writing
7841 as well as reading.
7842 @end table
7843
7844 @node GDB Files
7845 @chapter @value{GDBN} Files
7846
7847 @value{GDBN} needs to know the file name of the program to be debugged,
7848 both in order to read its symbol table and in order to start your
7849 program. To debug a core dump of a previous run, you must also tell
7850 @value{GDBN} the name of the core dump file.
7851
7852 @menu
7853 * Files:: Commands to specify files
7854 * Symbol Errors:: Errors reading symbol files
7855 @end menu
7856
7857 @node Files
7858 @section Commands to specify files
7859
7860 @cindex symbol table
7861 @cindex core dump file
7862
7863 You may want to specify executable and core dump file names. The usual
7864 way to do this is at start-up time, using the arguments to
7865 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
7866 Out of @value{GDBN}}).
7867
7868 Occasionally it is necessary to change to a different file during a
7869 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
7870 a file you want to use. In these situations the @value{GDBN} commands
7871 to specify new files are useful.
7872
7873 @table @code
7874 @cindex executable file
7875 @kindex file
7876 @item file @var{filename}
7877 Use @var{filename} as the program to be debugged. It is read for its
7878 symbols and for the contents of pure memory. It is also the program
7879 executed when you use the @code{run} command. If you do not specify a
7880 directory and the file is not found in the @value{GDBN} working directory,
7881 @value{GDBN} uses the environment variable @code{PATH} as a list of
7882 directories to search, just as the shell does when looking for a program
7883 to run. You can change the value of this variable, for both @value{GDBN}
7884 and your program, using the @code{path} command.
7885
7886 On systems with memory-mapped files, an auxiliary file named
7887 @file{@var{filename}.syms} may hold symbol table information for
7888 @var{filename}. If so, @value{GDBN} maps in the symbol table from
7889 @file{@var{filename}.syms}, starting up more quickly. See the
7890 descriptions of the file options @samp{-mapped} and @samp{-readnow}
7891 (available on the command line, and with the commands @code{file},
7892 @code{symbol-file}, or @code{add-symbol-file}, described below),
7893 for more information.
7894
7895 @item file
7896 @code{file} with no argument makes @value{GDBN} discard any information it
7897 has on both executable file and the symbol table.
7898
7899 @kindex exec-file
7900 @item exec-file @r{[} @var{filename} @r{]}
7901 Specify that the program to be run (but not the symbol table) is found
7902 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
7903 if necessary to locate your program. Omitting @var{filename} means to
7904 discard information on the executable file.
7905
7906 @kindex symbol-file
7907 @item symbol-file @r{[} @var{filename} @r{]}
7908 Read symbol table information from file @var{filename}. @code{PATH} is
7909 searched when necessary. Use the @code{file} command to get both symbol
7910 table and program to run from the same file.
7911
7912 @code{symbol-file} with no argument clears out @value{GDBN} information on your
7913 program's symbol table.
7914
7915 The @code{symbol-file} command causes @value{GDBN} to forget the contents
7916 of its convenience variables, the value history, and all breakpoints and
7917 auto-display expressions. This is because they may contain pointers to
7918 the internal data recording symbols and data types, which are part of
7919 the old symbol table data being discarded inside @value{GDBN}.
7920
7921 @code{symbol-file} does not repeat if you press @key{RET} again after
7922 executing it once.
7923
7924 When @value{GDBN} is configured for a particular environment, it
7925 understands debugging information in whatever format is the standard
7926 generated for that environment; you may use either a @sc{gnu} compiler, or
7927 other compilers that adhere to the local conventions.
7928 Best results are usually obtained from @sc{gnu} compilers; for example,
7929 using @code{@value{GCC}} you can generate debugging information for
7930 optimized code.
7931
7932 For most kinds of object files, with the exception of old SVR3 systems
7933 using COFF, the @code{symbol-file} command does not normally read the
7934 symbol table in full right away. Instead, it scans the symbol table
7935 quickly to find which source files and which symbols are present. The
7936 details are read later, one source file at a time, as they are needed.
7937
7938 The purpose of this two-stage reading strategy is to make @value{GDBN}
7939 start up faster. For the most part, it is invisible except for
7940 occasional pauses while the symbol table details for a particular source
7941 file are being read. (The @code{set verbose} command can turn these
7942 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
7943 warnings and messages}.)
7944
7945 We have not implemented the two-stage strategy for COFF yet. When the
7946 symbol table is stored in COFF format, @code{symbol-file} reads the
7947 symbol table data in full right away. Note that ``stabs-in-COFF''
7948 still does the two-stage strategy, since the debug info is actually
7949 in stabs format.
7950
7951 @kindex readnow
7952 @cindex reading symbols immediately
7953 @cindex symbols, reading immediately
7954 @kindex mapped
7955 @cindex memory-mapped symbol file
7956 @cindex saving symbol table
7957 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7958 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
7959 You can override the @value{GDBN} two-stage strategy for reading symbol
7960 tables by using the @samp{-readnow} option with any of the commands that
7961 load symbol table information, if you want to be sure @value{GDBN} has the
7962 entire symbol table available.
7963
7964 If memory-mapped files are available on your system through the
7965 @code{mmap} system call, you can use another option, @samp{-mapped}, to
7966 cause @value{GDBN} to write the symbols for your program into a reusable
7967 file. Future @value{GDBN} debugging sessions map in symbol information
7968 from this auxiliary symbol file (if the program has not changed), rather
7969 than spending time reading the symbol table from the executable
7970 program. Using the @samp{-mapped} option has the same effect as
7971 starting @value{GDBN} with the @samp{-mapped} command-line option.
7972
7973 You can use both options together, to make sure the auxiliary symbol
7974 file has all the symbol information for your program.
7975
7976 The auxiliary symbol file for a program called @var{myprog} is called
7977 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
7978 than the corresponding executable), @value{GDBN} always attempts to use
7979 it when you debug @var{myprog}; no special options or commands are
7980 needed.
7981
7982 The @file{.syms} file is specific to the host machine where you run
7983 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
7984 symbol table. It cannot be shared across multiple host platforms.
7985
7986 @c FIXME: for now no mention of directories, since this seems to be in
7987 @c flux. 13mar1992 status is that in theory GDB would look either in
7988 @c current dir or in same dir as myprog; but issues like competing
7989 @c GDB's, or clutter in system dirs, mean that in practice right now
7990 @c only current dir is used. FFish says maybe a special GDB hierarchy
7991 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
7992 @c files.
7993
7994 @kindex core
7995 @kindex core-file
7996 @item core-file @r{[} @var{filename} @r{]}
7997 Specify the whereabouts of a core dump file to be used as the ``contents
7998 of memory''. Traditionally, core files contain only some parts of the
7999 address space of the process that generated them; @value{GDBN} can access the
8000 executable file itself for other parts.
8001
8002 @code{core-file} with no argument specifies that no core file is
8003 to be used.
8004
8005 Note that the core file is ignored when your program is actually running
8006 under @value{GDBN}. So, if you have been running your program and you
8007 wish to debug a core file instead, you must kill the subprocess in which
8008 the program is running. To do this, use the @code{kill} command
8009 (@pxref{Kill Process, ,Killing the child process}).
8010
8011 @kindex add-symbol-file
8012 @cindex dynamic linking
8013 @item add-symbol-file @var{filename} @var{address}
8014 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
8015 @itemx add-symbol-file @var{filename} @var{address} @var{data_address} @var{bss_address}
8016 @itemx add-symbol-file @var{filename} @r{-T}@var{section} @var{address}
8017 The @code{add-symbol-file} command reads additional symbol table
8018 information from the file @var{filename}. You would use this command
8019 when @var{filename} has been dynamically loaded (by some other means)
8020 into the program that is running. @var{address} should be the memory
8021 address at which the file has been loaded; @value{GDBN} cannot figure
8022 this out for itself. You can specify up to three addresses, in which
8023 case they are taken to be the addresses of the text, data, and bss
8024 segments respectively. For complicated cases, you can specify an
8025 arbitrary number of @samp{@r{-T}@var{section} @var{address}} pairs, to
8026 give an explicit section name and base address for that section. You
8027 can specify any @var{address} as an expression.
8028
8029 The symbol table of the file @var{filename} is added to the symbol table
8030 originally read with the @code{symbol-file} command. You can use the
8031 @code{add-symbol-file} command any number of times; the new symbol data
8032 thus read keeps adding to the old. To discard all old symbol data
8033 instead, use the @code{symbol-file} command without any arguments.
8034
8035 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
8036
8037 You can use the @samp{-mapped} and @samp{-readnow} options just as with
8038 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
8039 table information for @var{filename}.
8040
8041 @kindex add-shared-symbol-file
8042 @item add-shared-symbol-file
8043 The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
8044 operating system for the Motorola 88k. @value{GDBN} automatically looks for
8045 shared libraries, however if @value{GDBN} does not find yours, you can run
8046 @code{add-shared-symbol-file}. It takes no arguments.
8047
8048 @kindex section
8049 @item section
8050 The @code{section} command changes the base address of section SECTION of
8051 the exec file to ADDR. This can be used if the exec file does not contain
8052 section addresses, (such as in the a.out format), or when the addresses
8053 specified in the file itself are wrong. Each section must be changed
8054 separately. The @code{info files} command, described below, lists all
8055 the sections and their addresses.
8056
8057 @kindex info files
8058 @kindex info target
8059 @item info files
8060 @itemx info target
8061 @code{info files} and @code{info target} are synonymous; both print the
8062 current target (@pxref{Targets, ,Specifying a Debugging Target}),
8063 including the names of the executable and core dump files currently in
8064 use by @value{GDBN}, and the files from which symbols were loaded. The
8065 command @code{help target} lists all possible targets rather than
8066 current ones.
8067
8068 @end table
8069
8070 All file-specifying commands allow both absolute and relative file names
8071 as arguments. @value{GDBN} always converts the file name to an absolute file
8072 name and remembers it that way.
8073
8074 @cindex shared libraries
8075 @value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
8076 libraries.
8077
8078 @value{GDBN} automatically loads symbol definitions from shared libraries
8079 when you use the @code{run} command, or when you examine a core file.
8080 (Before you issue the @code{run} command, @value{GDBN} does not understand
8081 references to a function in a shared library, however---unless you are
8082 debugging a core file).
8083
8084 On HP-UX, if the program loads a library explicitly, @value{GDBN}
8085 automatically loads the symbols at the time of the @code{shl_load} call.
8086
8087 @c FIXME: some @value{GDBN} release may permit some refs to undef
8088 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
8089 @c FIXME...lib; check this from time to time when updating manual
8090
8091 @table @code
8092 @kindex info sharedlibrary
8093 @kindex info share
8094 @item info share
8095 @itemx info sharedlibrary
8096 Print the names of the shared libraries which are currently loaded.
8097
8098 @kindex sharedlibrary
8099 @kindex share
8100 @item sharedlibrary @var{regex}
8101 @itemx share @var{regex}
8102 Load shared object library symbols for files matching a
8103 Unix regular expression.
8104 As with files loaded automatically, it only loads shared libraries
8105 required by your program for a core file or after typing @code{run}. If
8106 @var{regex} is omitted all shared libraries required by your program are
8107 loaded.
8108 @end table
8109
8110 On HP-UX systems, @value{GDBN} detects the loading of a shared library
8111 and automatically reads in symbols from the newly loaded library, up to
8112 a threshold that is initially set but that you can modify if you wish.
8113
8114 Beyond that threshold, symbols from shared libraries must be explicitly
8115 loaded. To load these symbols, use the command @code{sharedlibrary
8116 @var{filename}}. The base address of the shared library is determined
8117 automatically by @value{GDBN} and need not be specified.
8118
8119 To display or set the threshold, use the commands:
8120
8121 @table @code
8122 @kindex set auto-solib-add
8123 @item set auto-solib-add @var{threshold}
8124 Set the autoloading size threshold, in megabytes. If @var{threshold} is
8125 nonzero, symbols from all shared object libraries will be loaded
8126 automatically when the inferior begins execution or when the dynamic
8127 linker informs @value{GDBN} that a new library has been loaded, until
8128 the symbol table of the program and libraries exceeds this threshold.
8129 Otherwise, symbols must be loaded manually, using the
8130 @code{sharedlibrary} command. The default threshold is 100 megabytes.
8131
8132 @kindex show auto-solib-add
8133 @item show auto-solib-add
8134 Display the current autoloading size threshold, in megabytes.
8135 @end table
8136
8137 @node Symbol Errors
8138 @section Errors reading symbol files
8139
8140 While reading a symbol file, @value{GDBN} occasionally encounters problems,
8141 such as symbol types it does not recognize, or known bugs in compiler
8142 output. By default, @value{GDBN} does not notify you of such problems, since
8143 they are relatively common and primarily of interest to people
8144 debugging compilers. If you are interested in seeing information
8145 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
8146 only one message about each such type of problem, no matter how many
8147 times the problem occurs; or you can ask @value{GDBN} to print more messages,
8148 to see how many times the problems occur, with the @code{set
8149 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
8150 messages}).
8151
8152 The messages currently printed, and their meanings, include:
8153
8154 @table @code
8155 @item inner block not inside outer block in @var{symbol}
8156
8157 The symbol information shows where symbol scopes begin and end
8158 (such as at the start of a function or a block of statements). This
8159 error indicates that an inner scope block is not fully contained
8160 in its outer scope blocks.
8161
8162 @value{GDBN} circumvents the problem by treating the inner block as if it had
8163 the same scope as the outer block. In the error message, @var{symbol}
8164 may be shown as ``@code{(don't know)}'' if the outer block is not a
8165 function.
8166
8167 @item block at @var{address} out of order
8168
8169 The symbol information for symbol scope blocks should occur in
8170 order of increasing addresses. This error indicates that it does not
8171 do so.
8172
8173 @value{GDBN} does not circumvent this problem, and has trouble
8174 locating symbols in the source file whose symbols it is reading. (You
8175 can often determine what source file is affected by specifying
8176 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
8177 messages}.)
8178
8179 @item bad block start address patched
8180
8181 The symbol information for a symbol scope block has a start address
8182 smaller than the address of the preceding source line. This is known
8183 to occur in the SunOS 4.1.1 (and earlier) C compiler.
8184
8185 @value{GDBN} circumvents the problem by treating the symbol scope block as
8186 starting on the previous source line.
8187
8188 @item bad string table offset in symbol @var{n}
8189
8190 @cindex foo
8191 Symbol number @var{n} contains a pointer into the string table which is
8192 larger than the size of the string table.
8193
8194 @value{GDBN} circumvents the problem by considering the symbol to have the
8195 name @code{foo}, which may cause other problems if many symbols end up
8196 with this name.
8197
8198 @item unknown symbol type @code{0x@var{nn}}
8199
8200 The symbol information contains new data types that @value{GDBN} does
8201 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
8202 uncomprehended information, in hexadecimal.
8203
8204 @value{GDBN} circumvents the error by ignoring this symbol information.
8205 This usually allows you to debug your program, though certain symbols
8206 are not accessible. If you encounter such a problem and feel like
8207 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
8208 on @code{complain}, then go up to the function @code{read_dbx_symtab}
8209 and examine @code{*bufp} to see the symbol.
8210
8211 @item stub type has NULL name
8212
8213 @value{GDBN} could not find the full definition for a struct or class.
8214
8215 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
8216 The symbol information for a C++ member function is missing some
8217 information that recent versions of the compiler should have output for
8218 it.
8219
8220 @item info mismatch between compiler and debugger
8221
8222 @value{GDBN} could not parse a type specification output by the compiler.
8223
8224 @end table
8225
8226 @node Targets
8227 @chapter Specifying a Debugging Target
8228
8229 @cindex debugging target
8230 @kindex target
8231
8232 A @dfn{target} is the execution environment occupied by your program.
8233
8234 Often, @value{GDBN} runs in the same host environment as your program;
8235 in that case, the debugging target is specified as a side effect when
8236 you use the @code{file} or @code{core} commands. When you need more
8237 flexibility---for example, running @value{GDBN} on a physically separate
8238 host, or controlling a standalone system over a serial port or a
8239 realtime system over a TCP/IP connection---you can use the @code{target}
8240 command to specify one of the target types configured for @value{GDBN}
8241 (@pxref{Target Commands, ,Commands for managing targets}).
8242
8243 @menu
8244 * Active Targets:: Active targets
8245 * Target Commands:: Commands for managing targets
8246 * Byte Order:: Choosing target byte order
8247 * Remote:: Remote debugging
8248 * KOD:: Kernel Object Display
8249
8250 @end menu
8251
8252 @node Active Targets
8253 @section Active targets
8254
8255 @cindex stacking targets
8256 @cindex active targets
8257 @cindex multiple targets
8258
8259 There are three classes of targets: processes, core files, and
8260 executable files. @value{GDBN} can work concurrently on up to three
8261 active targets, one in each class. This allows you to (for example)
8262 start a process and inspect its activity without abandoning your work on
8263 a core file.
8264
8265 For example, if you execute @samp{gdb a.out}, then the executable file
8266 @code{a.out} is the only active target. If you designate a core file as
8267 well---presumably from a prior run that crashed and coredumped---then
8268 @value{GDBN} has two active targets and uses them in tandem, looking
8269 first in the corefile target, then in the executable file, to satisfy
8270 requests for memory addresses. (Typically, these two classes of target
8271 are complementary, since core files contain only a program's
8272 read-write memory---variables and so on---plus machine status, while
8273 executable files contain only the program text and initialized data.)
8274
8275 When you type @code{run}, your executable file becomes an active process
8276 target as well. When a process target is active, all @value{GDBN}
8277 commands requesting memory addresses refer to that target; addresses in
8278 an active core file or executable file target are obscured while the
8279 process target is active.
8280
8281 Use the @code{core-file} and @code{exec-file} commands to select a new
8282 core file or executable target (@pxref{Files, ,Commands to specify
8283 files}). To specify as a target a process that is already running, use
8284 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
8285 process}).
8286
8287 @node Target Commands
8288 @section Commands for managing targets
8289
8290 @table @code
8291 @item target @var{type} @var{parameters}
8292 Connects the @value{GDBN} host environment to a target machine or
8293 process. A target is typically a protocol for talking to debugging
8294 facilities. You use the argument @var{type} to specify the type or
8295 protocol of the target machine.
8296
8297 Further @var{parameters} are interpreted by the target protocol, but
8298 typically include things like device names or host names to connect
8299 with, process numbers, and baud rates.
8300
8301 The @code{target} command does not repeat if you press @key{RET} again
8302 after executing the command.
8303
8304 @kindex help target
8305 @item help target
8306 Displays the names of all targets available. To display targets
8307 currently selected, use either @code{info target} or @code{info files}
8308 (@pxref{Files, ,Commands to specify files}).
8309
8310 @item help target @var{name}
8311 Describe a particular target, including any parameters necessary to
8312 select it.
8313
8314 @kindex set gnutarget
8315 @item set gnutarget @var{args}
8316 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
8317 knows whether it is reading an @dfn{executable},
8318 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
8319 with the @code{set gnutarget} command. Unlike most @code{target} commands,
8320 with @code{gnutarget} the @code{target} refers to a program, not a machine.
8321
8322 @quotation
8323 @emph{Warning:} To specify a file format with @code{set gnutarget},
8324 you must know the actual BFD name.
8325 @end quotation
8326
8327 @noindent
8328 @xref{Files, , Commands to specify files}.
8329
8330 @kindex show gnutarget
8331 @item show gnutarget
8332 Use the @code{show gnutarget} command to display what file format
8333 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
8334 @value{GDBN} will determine the file format for each file automatically,
8335 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
8336 @end table
8337
8338 Here are some common targets (available, or not, depending on the GDB
8339 configuration):
8340
8341 @table @code
8342 @kindex target exec
8343 @item target exec @var{program}
8344 An executable file. @samp{target exec @var{program}} is the same as
8345 @samp{exec-file @var{program}}.
8346
8347 @kindex target core
8348 @item target core @var{filename}
8349 A core dump file. @samp{target core @var{filename}} is the same as
8350 @samp{core-file @var{filename}}.
8351
8352 @kindex target remote
8353 @item target remote @var{dev}
8354 Remote serial target in GDB-specific protocol. The argument @var{dev}
8355 specifies what serial device to use for the connection (e.g.
8356 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
8357 supports the @code{load} command. This is only useful if you have
8358 some other way of getting the stub to the target system, and you can put
8359 it somewhere in memory where it won't get clobbered by the download.
8360
8361 @kindex target sim
8362 @item target sim
8363 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
8364 In general,
8365 @example
8366 target sim
8367 load
8368 run
8369 @end example
8370 @noindent
8371 works; however, you cannot assume that a specific memory map, device
8372 drivers, or even basic I/O is available, although some simulators do
8373 provide these. For info about any processor-specific simulator details,
8374 see the appropriate section in @ref{Embedded Processors, ,Embedded
8375 Processors}.
8376
8377 @end table
8378
8379 Some configurations may include these targets as well:
8380
8381 @table @code
8382
8383 @kindex target nrom
8384 @item target nrom @var{dev}
8385 NetROM ROM emulator. This target only supports downloading.
8386
8387 @end table
8388
8389 Different targets are available on different configurations of @value{GDBN};
8390 your configuration may have more or fewer targets.
8391
8392 Many remote targets require you to download the executable's code
8393 once you've successfully established a connection.
8394
8395 @table @code
8396
8397 @kindex load @var{filename}
8398 @item load @var{filename}
8399 Depending on what remote debugging facilities are configured into
8400 @value{GDBN}, the @code{load} command may be available. Where it exists, it
8401 is meant to make @var{filename} (an executable) available for debugging
8402 on the remote system---by downloading, or dynamic linking, for example.
8403 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
8404 the @code{add-symbol-file} command.
8405
8406 If your @value{GDBN} does not have a @code{load} command, attempting to
8407 execute it gets the error message ``@code{You can't do that when your
8408 target is @dots{}}''
8409
8410 The file is loaded at whatever address is specified in the executable.
8411 For some object file formats, you can specify the load address when you
8412 link the program; for other formats, like a.out, the object file format
8413 specifies a fixed address.
8414 @c FIXME! This would be a good place for an xref to the GNU linker doc.
8415
8416 @code{load} does not repeat if you press @key{RET} again after using it.
8417 @end table
8418
8419 @node Byte Order
8420 @section Choosing target byte order
8421
8422 @cindex choosing target byte order
8423 @cindex target byte order
8424 @kindex set endian big
8425 @kindex set endian little
8426 @kindex set endian auto
8427 @kindex show endian
8428
8429 Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
8430 offer the ability to run either big-endian or little-endian byte
8431 orders. Usually the executable or symbol will include a bit to
8432 designate the endian-ness, and you will not need to worry about
8433 which to use. However, you may still find it useful to adjust
8434 @value{GDBN}'s idea of processor endian-ness manually.
8435
8436 @table @code
8437 @kindex set endian big
8438 @item set endian big
8439 Instruct @value{GDBN} to assume the target is big-endian.
8440
8441 @kindex set endian little
8442 @item set endian little
8443 Instruct @value{GDBN} to assume the target is little-endian.
8444
8445 @kindex set endian auto
8446 @item set endian auto
8447 Instruct @value{GDBN} to use the byte order associated with the
8448 executable.
8449
8450 @item show endian
8451 Display @value{GDBN}'s current idea of the target byte order.
8452
8453 @end table
8454
8455 Note that these commands merely adjust interpretation of symbolic
8456 data on the host, and that they have absolutely no effect on the
8457 target system.
8458
8459 @node Remote
8460 @section Remote debugging
8461 @cindex remote debugging
8462
8463 If you are trying to debug a program running on a machine that cannot run
8464 @value{GDBN} in the usual way, it is often useful to use remote debugging.
8465 For example, you might use remote debugging on an operating system kernel,
8466 or on a small system which does not have a general purpose operating system
8467 powerful enough to run a full-featured debugger.
8468
8469 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
8470 to make this work with particular debugging targets. In addition,
8471 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
8472 but not specific to any particular target system) which you can use if you
8473 write the remote stubs---the code that runs on the remote system to
8474 communicate with @value{GDBN}.
8475
8476 Other remote targets may be available in your
8477 configuration of @value{GDBN}; use @code{help target} to list them.
8478
8479 @menu
8480 * Remote Serial:: @value{GDBN} remote serial protocol
8481 @end menu
8482
8483 @node Remote Serial
8484 @subsection The @value{GDBN} remote serial protocol
8485
8486 @cindex remote serial debugging, overview
8487 To debug a program running on another machine (the debugging
8488 @dfn{target} machine), you must first arrange for all the usual
8489 prerequisites for the program to run by itself. For example, for a C
8490 program, you need:
8491
8492 @enumerate
8493 @item
8494 A startup routine to set up the C runtime environment; these usually
8495 have a name like @file{crt0}. The startup routine may be supplied by
8496 your hardware supplier, or you may have to write your own.
8497
8498 @item
8499 A C subroutine library to support your program's
8500 subroutine calls, notably managing input and output.
8501
8502 @item
8503 A way of getting your program to the other machine---for example, a
8504 download program. These are often supplied by the hardware
8505 manufacturer, but you may have to write your own from hardware
8506 documentation.
8507 @end enumerate
8508
8509 The next step is to arrange for your program to use a serial port to
8510 communicate with the machine where @value{GDBN} is running (the @dfn{host}
8511 machine). In general terms, the scheme looks like this:
8512
8513 @table @emph
8514 @item On the host,
8515 @value{GDBN} already understands how to use this protocol; when everything
8516 else is set up, you can simply use the @samp{target remote} command
8517 (@pxref{Targets,,Specifying a Debugging Target}).
8518
8519 @item On the target,
8520 you must link with your program a few special-purpose subroutines that
8521 implement the @value{GDBN} remote serial protocol. The file containing these
8522 subroutines is called a @dfn{debugging stub}.
8523
8524 On certain remote targets, you can use an auxiliary program
8525 @code{gdbserver} instead of linking a stub into your program.
8526 @xref{Server,,Using the @code{gdbserver} program}, for details.
8527 @end table
8528
8529 The debugging stub is specific to the architecture of the remote
8530 machine; for example, use @file{sparc-stub.c} to debug programs on
8531 @sc{sparc} boards.
8532
8533 @cindex remote serial stub list
8534 These working remote stubs are distributed with @value{GDBN}:
8535
8536 @table @code
8537
8538 @item i386-stub.c
8539 @kindex i386-stub.c
8540 @cindex Intel
8541 @cindex i386
8542 For Intel 386 and compatible architectures.
8543
8544 @item m68k-stub.c
8545 @kindex m68k-stub.c
8546 @cindex Motorola 680x0
8547 @cindex m680x0
8548 For Motorola 680x0 architectures.
8549
8550 @item sh-stub.c
8551 @kindex sh-stub.c
8552 @cindex Hitachi
8553 @cindex SH
8554 For Hitachi SH architectures.
8555
8556 @item sparc-stub.c
8557 @kindex sparc-stub.c
8558 @cindex Sparc
8559 For @sc{sparc} architectures.
8560
8561 @item sparcl-stub.c
8562 @kindex sparcl-stub.c
8563 @cindex Fujitsu
8564 @cindex SparcLite
8565 For Fujitsu @sc{sparclite} architectures.
8566
8567 @end table
8568
8569 The @file{README} file in the @value{GDBN} distribution may list other
8570 recently added stubs.
8571
8572 @menu
8573 * Stub Contents:: What the stub can do for you
8574 * Bootstrapping:: What you must do for the stub
8575 * Debug Session:: Putting it all together
8576 * Protocol:: Definition of the communication protocol
8577 * Server:: Using the `gdbserver' program
8578 * NetWare:: Using the `gdbserve.nlm' program
8579 @end menu
8580
8581 @node Stub Contents
8582 @subsubsection What the stub can do for you
8583
8584 @cindex remote serial stub
8585 The debugging stub for your architecture supplies these three
8586 subroutines:
8587
8588 @table @code
8589 @item set_debug_traps
8590 @kindex set_debug_traps
8591 @cindex remote serial stub, initialization
8592 This routine arranges for @code{handle_exception} to run when your
8593 program stops. You must call this subroutine explicitly near the
8594 beginning of your program.
8595
8596 @item handle_exception
8597 @kindex handle_exception
8598 @cindex remote serial stub, main routine
8599 This is the central workhorse, but your program never calls it
8600 explicitly---the setup code arranges for @code{handle_exception} to
8601 run when a trap is triggered.
8602
8603 @code{handle_exception} takes control when your program stops during
8604 execution (for example, on a breakpoint), and mediates communications
8605 with @value{GDBN} on the host machine. This is where the communications
8606 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
8607 representative on the target machine. It begins by sending summary
8608 information on the state of your program, then continues to execute,
8609 retrieving and transmitting any information @value{GDBN} needs, until you
8610 execute a @value{GDBN} command that makes your program resume; at that point,
8611 @code{handle_exception} returns control to your own code on the target
8612 machine.
8613
8614 @item breakpoint
8615 @cindex @code{breakpoint} subroutine, remote
8616 Use this auxiliary subroutine to make your program contain a
8617 breakpoint. Depending on the particular situation, this may be the only
8618 way for @value{GDBN} to get control. For instance, if your target
8619 machine has some sort of interrupt button, you won't need to call this;
8620 pressing the interrupt button transfers control to
8621 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
8622 simply receiving characters on the serial port may also trigger a trap;
8623 again, in that situation, you don't need to call @code{breakpoint} from
8624 your own program---simply running @samp{target remote} from the host
8625 @value{GDBN} session gets control.
8626
8627 Call @code{breakpoint} if none of these is true, or if you simply want
8628 to make certain your program stops at a predetermined point for the
8629 start of your debugging session.
8630 @end table
8631
8632 @node Bootstrapping
8633 @subsubsection What you must do for the stub
8634
8635 @cindex remote stub, support routines
8636 The debugging stubs that come with @value{GDBN} are set up for a particular
8637 chip architecture, but they have no information about the rest of your
8638 debugging target machine.
8639
8640 First of all you need to tell the stub how to communicate with the
8641 serial port.
8642
8643 @table @code
8644 @item int getDebugChar()
8645 @kindex getDebugChar
8646 Write this subroutine to read a single character from the serial port.
8647 It may be identical to @code{getchar} for your target system; a
8648 different name is used to allow you to distinguish the two if you wish.
8649
8650 @item void putDebugChar(int)
8651 @kindex putDebugChar
8652 Write this subroutine to write a single character to the serial port.
8653 It may be identical to @code{putchar} for your target system; a
8654 different name is used to allow you to distinguish the two if you wish.
8655 @end table
8656
8657 @cindex control C, and remote debugging
8658 @cindex interrupting remote targets
8659 If you want @value{GDBN} to be able to stop your program while it is
8660 running, you need to use an interrupt-driven serial driver, and arrange
8661 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
8662 character). That is the character which @value{GDBN} uses to tell the
8663 remote system to stop.
8664
8665 Getting the debugging target to return the proper status to @value{GDBN}
8666 probably requires changes to the standard stub; one quick and dirty way
8667 is to just execute a breakpoint instruction (the ``dirty'' part is that
8668 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
8669
8670 Other routines you need to supply are:
8671
8672 @table @code
8673 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
8674 @kindex exceptionHandler
8675 Write this function to install @var{exception_address} in the exception
8676 handling tables. You need to do this because the stub does not have any
8677 way of knowing what the exception handling tables on your target system
8678 are like (for example, the processor's table might be in @sc{rom},
8679 containing entries which point to a table in @sc{ram}).
8680 @var{exception_number} is the exception number which should be changed;
8681 its meaning is architecture-dependent (for example, different numbers
8682 might represent divide by zero, misaligned access, etc). When this
8683 exception occurs, control should be transferred directly to
8684 @var{exception_address}, and the processor state (stack, registers,
8685 and so on) should be just as it is when a processor exception occurs. So if
8686 you want to use a jump instruction to reach @var{exception_address}, it
8687 should be a simple jump, not a jump to subroutine.
8688
8689 For the 386, @var{exception_address} should be installed as an interrupt
8690 gate so that interrupts are masked while the handler runs. The gate
8691 should be at privilege level 0 (the most privileged level). The
8692 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
8693 help from @code{exceptionHandler}.
8694
8695 @item void flush_i_cache()
8696 @kindex flush_i_cache
8697 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
8698 instruction cache, if any, on your target machine. If there is no
8699 instruction cache, this subroutine may be a no-op.
8700
8701 On target machines that have instruction caches, @value{GDBN} requires this
8702 function to make certain that the state of your program is stable.
8703 @end table
8704
8705 @noindent
8706 You must also make sure this library routine is available:
8707
8708 @table @code
8709 @item void *memset(void *, int, int)
8710 @kindex memset
8711 This is the standard library function @code{memset} that sets an area of
8712 memory to a known value. If you have one of the free versions of
8713 @code{libc.a}, @code{memset} can be found there; otherwise, you must
8714 either obtain it from your hardware manufacturer, or write your own.
8715 @end table
8716
8717 If you do not use the GNU C compiler, you may need other standard
8718 library subroutines as well; this varies from one stub to another,
8719 but in general the stubs are likely to use any of the common library
8720 subroutines which @code{@value{GCC}} generates as inline code.
8721
8722
8723 @node Debug Session
8724 @subsubsection Putting it all together
8725
8726 @cindex remote serial debugging summary
8727 In summary, when your program is ready to debug, you must follow these
8728 steps.
8729
8730 @enumerate
8731 @item
8732 Make sure you have defined the supporting low-level routines
8733 (@pxref{Bootstrapping,,What you must do for the stub}):
8734 @display
8735 @code{getDebugChar}, @code{putDebugChar},
8736 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
8737 @end display
8738
8739 @item
8740 Insert these lines near the top of your program:
8741
8742 @example
8743 set_debug_traps();
8744 breakpoint();
8745 @end example
8746
8747 @item
8748 For the 680x0 stub only, you need to provide a variable called
8749 @code{exceptionHook}. Normally you just use:
8750
8751 @example
8752 void (*exceptionHook)() = 0;
8753 @end example
8754
8755 @noindent
8756 but if before calling @code{set_debug_traps}, you set it to point to a
8757 function in your program; that function is called when
8758 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
8759 error). The function indicated by @code{exceptionHook} is called with
8760 one parameter: an @code{int} which is the exception number.
8761
8762 @item
8763 Compile and link together: your program, the @value{GDBN} debugging stub for
8764 your target architecture, and the supporting subroutines.
8765
8766 @item
8767 Make sure you have a serial connection between your target machine and
8768 the @value{GDBN} host, and identify the serial port on the host.
8769
8770 @item
8771 @c The "remote" target now provides a `load' command, so we should
8772 @c document that. FIXME.
8773 Download your program to your target machine (or get it there by
8774 whatever means the manufacturer provides), and start it.
8775
8776 @item
8777 To start remote debugging, run @value{GDBN} on the host machine, and specify
8778 as an executable file the program that is running in the remote machine.
8779 This tells @value{GDBN} how to find your program's symbols and the contents
8780 of its pure text.
8781
8782 @item
8783 @cindex serial line, @code{target remote}
8784 Establish communication using the @code{target remote} command.
8785 Its argument specifies how to communicate with the target
8786 machine---either via a devicename attached to a direct serial line, or a
8787 TCP port (usually to a terminal server which in turn has a serial line
8788 to the target). For example, to use a serial line connected to the
8789 device named @file{/dev/ttyb}:
8790
8791 @example
8792 target remote /dev/ttyb
8793 @end example
8794
8795 @cindex TCP port, @code{target remote}
8796 To use a TCP connection, use an argument of the form
8797 @code{@var{host}:port}. For example, to connect to port 2828 on a
8798 terminal server named @code{manyfarms}:
8799
8800 @example
8801 target remote manyfarms:2828
8802 @end example
8803 @end enumerate
8804
8805 Now you can use all the usual commands to examine and change data and to
8806 step and continue the remote program.
8807
8808 To resume the remote program and stop debugging it, use the @code{detach}
8809 command.
8810
8811 @cindex interrupting remote programs
8812 @cindex remote programs, interrupting
8813 Whenever @value{GDBN} is waiting for the remote program, if you type the
8814 interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
8815 program. This may or may not succeed, depending in part on the hardware
8816 and the serial drivers the remote system uses. If you type the
8817 interrupt character once again, @value{GDBN} displays this prompt:
8818
8819 @example
8820 Interrupted while waiting for the program.
8821 Give up (and stop debugging it)? (y or n)
8822 @end example
8823
8824 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
8825 (If you decide you want to try again later, you can use @samp{target
8826 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
8827 goes back to waiting.
8828
8829 @node Protocol
8830 @subsubsection Communication protocol
8831
8832 @cindex debugging stub, example
8833 @cindex remote stub, example
8834 @cindex stub example, remote debugging
8835 The stub files provided with @value{GDBN} implement the target side of the
8836 communication protocol, and the @value{GDBN} side is implemented in the
8837 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
8838 these subroutines to communicate, and ignore the details. (If you're
8839 implementing your own stub file, you can still ignore the details: start
8840 with one of the existing stub files. @file{sparc-stub.c} is the best
8841 organized, and therefore the easiest to read.)
8842
8843 However, there may be occasions when you need to know something about
8844 the protocol---for example, if there is only one serial port to your
8845 target machine, you might want your program to do something special if
8846 it recognizes a packet meant for @value{GDBN}.
8847
8848 In the examples below, @samp{<-} and @samp{->} are used to indicate
8849 transmitted and received data respectfully.
8850
8851 @cindex protocol, @value{GDBN} remote serial
8852 @cindex serial protocol, @value{GDBN} remote
8853 @cindex remote serial protocol
8854 All @value{GDBN} commands and responses (other than acknowledgments)
8855 are sent as a @var{packet}. A @var{packet} is introduced with the
8856 character @samp{$}, this is followed by an optional two-digit
8857 @var{sequence-id} and the character @samp{:}, the actual
8858 @var{packet-data}, and the terminating character @samp{#} followed by a
8859 two-digit @var{checksum}:
8860
8861 @example
8862 @code{$}@var{packet-data}@code{#}@var{checksum}
8863 @end example
8864 @noindent
8865 or, with the optional @var{sequence-id}:
8866 @example
8867 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8868 @end example
8869
8870 @cindex checksum, for @value{GDBN} remote
8871 @noindent
8872 The two-digit @var{checksum} is computed as the modulo 256 sum of all
8873 characters between the leading @samp{$} and the trailing @samp{#} (that
8874 consisting of both the optional @var{sequence-id}@code{:} and the actual
8875 @var{packet-data}) (an eight bit unsigned checksum).
8876
8877 @cindex sequence-id, for @value{GDBN} remote
8878 @noindent
8879 The two-digit @var{sequence-id}, when present, is returned with the
8880 acknowledgment. Beyond that its meaning is poorly defined.
8881 @value{GDBN} is not known to output @var{sequence-id}s.
8882
8883 When either the host or the target machine receives a packet, the first
8884 response expected is an acknowledgment: either @samp{+} (to indicate
8885 the package was received correctly) or @samp{-} (to request
8886 retransmission):
8887
8888 @example
8889 <- @code{$}@var{packet-data}@code{#}@var{checksum}
8890 -> @code{+}
8891 @end example
8892 @noindent
8893 If the received packet included a @var{sequence-id} than that is
8894 appended to a positive acknowledgment:
8895
8896 @example
8897 <- @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
8898 -> @code{+}@var{sequence-id}
8899 @end example
8900
8901 The host (@value{GDBN}) sends @var{command}s, and the target (the
8902 debugging stub incorporated in your program) sends a @var{response}. In
8903 the case of step and continue @var{command}s, the response is only sent
8904 when the operation has completed (the target has again stopped).
8905
8906 @var{packet-data} consists of a sequence of characters with the
8907 exception of @samp{#} and @samp{$} (see @samp{X} packet for an
8908 exception). @samp{:} can not appear as the third character in a packet.
8909 Fields within the packet should be separated using @samp{,} and @samp{;}
8910 (unfortunately some packets chose to use @samp{:}). Except where
8911 otherwise noted all numbers are represented in HEX with leading zeros
8912 suppressed.
8913
8914 Response @var{data} can be run-length encoded to save space. A @samp{*}
8915 means that the next character is an @sc{ascii} encoding giving a repeat count
8916 which stands for that many repetitions of the character preceding the
8917 @samp{*}. The encoding is @code{n+29}, yielding a printable character
8918 where @code{n >=3} (which is where rle starts to win). The printable
8919 characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
8920 value greater than 126 should not be used.
8921
8922 Some remote systems have used a different run-length encoding mechanism
8923 loosely refered to as the cisco encoding. Following the @samp{*}
8924 character are two hex digits that indicate the size of the packet.
8925
8926 So:
8927 @example
8928 "@code{0* }"
8929 @end example
8930 @noindent
8931 means the same as "0000".
8932
8933 The error response, returned for some packets includes a two character
8934 error number. That number is not well defined.
8935
8936 For any @var{command} not supported by the stub, an empty response
8937 (@samp{$#00}) should be returned. That way it is possible to extend the
8938 protocol. A newer @value{GDBN} can tell if a packet is supported based
8939 on that response.
8940
8941 Below is a complete list of all currently defined @var{command}s and
8942 their corresponding response @var{data}:
8943
8944 @multitable @columnfractions .30 .30 .40
8945 @item Packet
8946 @tab Request
8947 @tab Description
8948
8949 @item extended ops @emph{(optional)}
8950 @tab @code{!}
8951 @tab
8952 Use the extended remote protocol. Sticky---only needs to be set once.
8953 The extended remote protocol support the @samp{R} packet.
8954 @item
8955 @tab reply @samp{}
8956 @tab
8957 Stubs that support the extended remote protocol return @samp{} which,
8958 unfortunately, is identical to the response returned by stubs that do not
8959 support protocol extensions.
8960
8961 @item last signal
8962 @tab @code{?}
8963 @tab
8964 Indicate the reason the target halted. The reply is the same as for step
8965 and continue.
8966 @item
8967 @tab reply
8968 @tab see below
8969
8970
8971 @item reserved
8972 @tab @code{a}
8973 @tab Reserved for future use
8974
8975 @item set program arguments @strong{(reserved)} @emph{(optional)}
8976 @tab @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,...}
8977 @tab
8978 Initialized @samp{argv[]} array passed into program. @var{arglen}
8979 specifies the number of bytes in the hex encoded byte stream @var{arg}.
8980 See @file{gdbserver} for more details.
8981 @item
8982 @tab reply @code{OK}
8983 @item
8984 @tab reply @code{E}@var{NN}
8985
8986 @item set baud @strong{(deprecated)}
8987 @tab @code{b}@var{baud}
8988 @tab
8989 Change the serial line speed to @var{baud}. JTC: @emph{When does the
8990 transport layer state change? When it's received, or after the ACK is
8991 transmitted. In either case, there are problems if the command or the
8992 acknowledgment packet is dropped.} Stan: @emph{If people really wanted
8993 to add something like this, and get it working for the first time, they
8994 ought to modify ser-unix.c to send some kind of out-of-band message to a
8995 specially-setup stub and have the switch happen "in between" packets, so
8996 that from remote protocol's point of view, nothing actually
8997 happened.}
8998
8999 @item set breakpoint @strong{(deprecated)}
9000 @tab @code{B}@var{addr},@var{mode}
9001 @tab
9002 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
9003 breakpoint at @var{addr}. @emph{This has been replaced by the @samp{Z} and
9004 @samp{z} packets.}
9005
9006 @item continue
9007 @tab @code{c}@var{addr}
9008 @tab
9009 @var{addr} is address to resume. If @var{addr} is omitted, resume at
9010 current address.
9011 @item
9012 @tab reply
9013 @tab see below
9014
9015 @item continue with signal @emph{(optional)}
9016 @tab @code{C}@var{sig}@code{;}@var{addr}
9017 @tab
9018 Continue with signal @var{sig} (hex signal number). If
9019 @code{;}@var{addr} is omitted, resume at same address.
9020 @item
9021 @tab reply
9022 @tab see below
9023
9024 @item toggle debug @emph{(deprecated)}
9025 @tab @code{d}
9026 @tab
9027 toggle debug flag.
9028
9029 @item detach @emph{(optional)}
9030 @tab @code{D}
9031 @tab
9032 Detach @value{GDBN} from the remote system. Sent to the remote target before
9033 @value{GDBN} disconnects.
9034 @item
9035 @tab reply @emph{no response}
9036 @tab
9037 @value{GDBN} does not check for any response after sending this packet
9038
9039 @item reserved
9040 @tab @code{e}
9041 @tab Reserved for future use
9042
9043 @item reserved
9044 @tab @code{E}
9045 @tab Reserved for future use
9046
9047 @item reserved
9048 @tab @code{f}
9049 @tab Reserved for future use
9050
9051 @item reserved
9052 @tab @code{F}
9053 @tab Reserved for future use
9054
9055 @item read registers
9056 @tab @code{g}
9057 @tab Read general registers.
9058 @item
9059 @tab reply @var{XX...}
9060 @tab
9061 Each byte of register data is described by two hex digits. The bytes
9062 with the register are transmitted in target byte order. The size of
9063 each register and their position within the @samp{g} @var{packet} are
9064 determined by the @value{GDBN} internal macros @var{REGISTER_RAW_SIZE} and
9065 @var{REGISTER_NAME} macros. The specification of several standard
9066 @code{g} packets is specified below.
9067 @item
9068 @tab @code{E}@var{NN}
9069 @tab for an error.
9070
9071 @item write regs
9072 @tab @code{G}@var{XX...}
9073 @tab
9074 See @samp{g} for a description of the @var{XX...} data.
9075 @item
9076 @tab reply @code{OK}
9077 @tab for success
9078 @item
9079 @tab reply @code{E}@var{NN}
9080 @tab for an error
9081
9082 @item reserved
9083 @tab @code{h}
9084 @tab Reserved for future use
9085
9086 @item set thread @emph{(optional)}
9087 @tab @code{H}@var{c}@var{t...}
9088 @tab
9089 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
9090 @samp{G}, et.al.). @var{c} = @samp{c} for thread used in step and
9091 continue; @var{t...} can be -1 for all threads. @var{c} = @samp{g} for
9092 thread used in other operations. If zero, pick a thread, any thread.
9093 @item
9094 @tab reply @code{OK}
9095 @tab for success
9096 @item
9097 @tab reply @code{E}@var{NN}
9098 @tab for an error
9099
9100 @c FIXME: JTC:
9101 @c 'H': How restrictive (or permissive) is the thread model. If a
9102 @c thread is selected and stopped, are other threads allowed
9103 @c to continue to execute? As I mentioned above, I think the
9104 @c semantics of each command when a thread is selected must be
9105 @c described. For example:
9106 @c
9107 @c 'g': If the stub supports threads and a specific thread is
9108 @c selected, returns the register block from that thread;
9109 @c otherwise returns current registers.
9110 @c
9111 @c 'G' If the stub supports threads and a specific thread is
9112 @c selected, sets the registers of the register block of
9113 @c that thread; otherwise sets current registers.
9114
9115 @item cycle step @strong{(draft)} @emph{(optional)}
9116 @tab @code{i}@var{addr}@code{,}@var{nnn}
9117 @tab
9118 Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
9119 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
9120 step starting at that address.
9121
9122 @item signal then cycle step @strong{(reserved)} @emph{(optional)}
9123 @tab @code{I}
9124 @tab
9125 See @samp{i} and @samp{S} for likely syntax and semantics.
9126
9127 @item reserved
9128 @tab @code{j}
9129 @tab Reserved for future use
9130
9131 @item reserved
9132 @tab @code{J}
9133 @tab Reserved for future use
9134
9135 @item kill request @emph{(optional)}
9136 @tab @code{k}
9137 @tab
9138 FIXME: @emph{There is no description of how operate when a specific
9139 thread context has been selected (ie. does 'k' kill only that thread?)}.
9140
9141 @item reserved
9142 @tab @code{l}
9143 @tab Reserved for future use
9144
9145 @item reserved
9146 @tab @code{L}
9147 @tab Reserved for future use
9148
9149 @item read memory
9150 @tab @code{m}@var{addr}@code{,}@var{length}
9151 @tab
9152 Read @var{length} bytes of memory starting at address @var{addr}.
9153 Neither @value{GDBN} nor the stub assume that sized memory transfers are assumed
9154 using word alligned accesses. FIXME: @emph{A word aligned memory
9155 transfer mechanism is needed.}
9156 @item
9157 @tab reply @var{XX...}
9158 @tab
9159 @var{XX...} is mem contents. Can be fewer bytes than requested if able
9160 to read only part of the data. Neither @value{GDBN} nor the stub assume that
9161 sized memory transfers are assumed using word alligned accesses. FIXME:
9162 @emph{A word aligned memory transfer mechanism is needed.}
9163 @item
9164 @tab reply @code{E}@var{NN}
9165 @tab @var{NN} is errno
9166
9167 @item write mem
9168 @tab @code{M}@var{addr},@var{length}@code{:}@var{XX...}
9169 @tab
9170 Write @var{length} bytes of memory starting at address @var{addr}.
9171 @var{XX...} is the data.
9172 @item
9173 @tab reply @code{OK}
9174 @tab for success
9175 @item
9176 @tab reply @code{E}@var{NN}
9177 @tab
9178 for an error (this includes the case where only part of the data was
9179 written).
9180
9181 @item reserved
9182 @tab @code{n}
9183 @tab Reserved for future use
9184
9185 @item reserved
9186 @tab @code{N}
9187 @tab Reserved for future use
9188
9189 @item reserved
9190 @tab @code{o}
9191 @tab Reserved for future use
9192
9193 @item reserved
9194 @tab @code{O}
9195 @tab Reserved for future use
9196
9197 @item read reg @strong{(reserved)}
9198 @tab @code{p}@var{n...}
9199 @tab
9200 See write register.
9201 @item
9202 @tab return @var{r....}
9203 @tab The hex encoded value of the register in target byte order.
9204
9205 @item write reg @emph{(optional)}
9206 @tab @code{P}@var{n...}@code{=}@var{r...}
9207 @tab
9208 Write register @var{n...} with value @var{r...}, which contains two hex
9209 digits for each byte in the register (target byte order).
9210 @item
9211 @tab reply @code{OK}
9212 @tab for success
9213 @item
9214 @tab reply @code{E}@var{NN}
9215 @tab for an error
9216
9217 @item general query @emph{(optional)}
9218 @tab @code{q}@var{query}
9219 @tab
9220 Request info about @var{query}. In general @value{GDBN} @var{query}'s
9221 have a leading upper case letter. Custom vendor queries should use a
9222 company prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may
9223 optionally be followed by a @samp{,} or @samp{;} separated list. Stubs
9224 must ensure that they match the full @var{query} name.
9225 @item
9226 @tab reply @code{XX...}
9227 @tab Hex encoded data from query. The reply can not be empty.
9228 @item
9229 @tab reply @code{E}@var{NN}
9230 @tab error reply
9231 @item
9232 @tab reply @samp{}
9233 @tab Indicating an unrecognized @var{query}.
9234
9235 @item general set @emph{(optional)}
9236 @tab @code{Q}@var{var}@code{=}@var{val}
9237 @tab
9238 Set value of @var{var} to @var{val}. See @samp{q} for a discussing of
9239 naming conventions.
9240
9241 @item reset @emph{(deprecated)}
9242 @tab @code{r}
9243 @tab
9244 Reset the entire system.
9245
9246 @item remote restart @emph{(optional)}
9247 @tab @code{R}@var{XX}
9248 @tab
9249 Restart the remote server. @var{XX} while needed has no clear
9250 definition. FIXME: @emph{An example interaction explaining how this
9251 packet is used in extended-remote mode is needed}.
9252
9253 @item step @emph{(optional)}
9254 @tab @code{s}@var{addr}
9255 @tab
9256 @var{addr} is address to resume. If @var{addr} is omitted, resume at
9257 same address.
9258 @item
9259 @tab reply
9260 @tab see below
9261
9262 @item step with signal @emph{(optional)}
9263 @tab @code{S}@var{sig}@code{;}@var{addr}
9264 @tab
9265 Like @samp{C} but step not continue.
9266 @item
9267 @tab reply
9268 @tab see below
9269
9270 @item search @emph{(optional)}
9271 @tab @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM}
9272 @tab
9273 Search backwards starting at address @var{addr} for a match with pattern
9274 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4
9275 bytes. @var{addr} must be at least 3 digits.
9276
9277 @item thread alive @emph{(optional)}
9278 @tab @code{T}@var{XX}
9279 @tab Find out if the thread XX is alive.
9280 @item
9281 @tab reply @code{OK}
9282 @tab thread is still alive
9283 @item
9284 @tab reply @code{E}@var{NN}
9285 @tab thread is dead
9286
9287 @item reserved
9288 @tab @code{u}
9289 @tab Reserved for future use
9290
9291 @item reserved
9292 @tab @code{U}
9293 @tab Reserved for future use
9294
9295 @item reserved
9296 @tab @code{v}
9297 @tab Reserved for future use
9298
9299 @item reserved
9300 @tab @code{V}
9301 @tab Reserved for future use
9302
9303 @item reserved
9304 @tab @code{w}
9305 @tab Reserved for future use
9306
9307 @item reserved
9308 @tab @code{W}
9309 @tab Reserved for future use
9310
9311 @item reserved
9312 @tab @code{x}
9313 @tab Reserved for future use
9314
9315 @item write mem (binary) @emph{(optional)}
9316 @tab @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX...}
9317 @tab
9318 @var{addr} is address, @var{length} is number of bytes, @var{XX...} is
9319 binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
9320 escaped using @code{0x7d}.
9321 @item
9322 @tab reply @code{OK}
9323 @tab for success
9324 @item
9325 @tab reply @code{E}@var{NN}
9326 @tab for an error
9327
9328 @item reserved
9329 @tab @code{y}
9330 @tab Reserved for future use
9331
9332 @item reserved
9333 @tab @code{Y}
9334 @tab Reserved for future use
9335
9336 @item remove break or watchpoint @strong{(draft)} @emph{(optional)}
9337 @tab @code{z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9338 @tab
9339 See @samp{Z}.
9340
9341 @item insert break or watchpoint @strong{(draft)} @emph{(optional)}
9342 @tab @code{Z}@var{t}@code{,}@var{addr}@code{,}@var{length}
9343 @tab
9344 @var{t} is type: @samp{0} - software breakpoint, @samp{1} - hardware
9345 breakpoint, @samp{2} - write watchpoint, @samp{3} - read watchpoint,
9346 @samp{4} - access watchpoint; @var{addr} is address; @var{length} is in
9347 bytes. For a software breakpoint, @var{length} specifies the size of
9348 the instruction to be patched. For hardware breakpoints and watchpoints
9349 @var{length} specifies the memory region to be monitored. To avoid
9350 potential problems with duplicate packets, the operations should be
9351 implemented in an idempotent way.
9352 @item
9353 @tab reply @code{E}@var{NN}
9354 @tab for an error
9355 @item
9356 @tab reply @code{OK}
9357 @tab for success
9358 @item
9359 @tab @samp{}
9360 @tab If not supported.
9361
9362 @item reserved
9363 @tab <other>
9364 @tab Reserved for future use
9365
9366 @end multitable
9367
9368 The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
9369 receive any of the below as a reply. In the case of the @samp{C},
9370 @samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
9371 when the target halts. In the below the exact meaning of @samp{signal
9372 number} is poorly defined. In general one of the UNIX signal numbering
9373 conventions is used.
9374
9375 @multitable @columnfractions .4 .6
9376
9377 @item @code{S}@var{AA}
9378 @tab @var{AA} is the signal number
9379
9380 @item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
9381 @tab
9382 @var{AA} = two hex digit signal number; @var{n...} = register number
9383 (hex), @var{r...} = target byte ordered register contents, size defined
9384 by @code{REGISTER_RAW_SIZE}; @var{n...} = @samp{thread}, @var{r...} =
9385 thread process ID, this is a hex integer; @var{n...} = other string not
9386 starting with valid hex digit. @value{GDBN} should ignore this
9387 @var{n...}, @var{r...} pair and go on to the next. This way we can
9388 extend the protocol.
9389
9390 @item @code{W}@var{AA}
9391 @tab
9392 The process exited, and @var{AA} is the exit status. This is only
9393 applicable for certains sorts of targets.
9394
9395 @item @code{X}@var{AA}
9396 @tab
9397 The process terminated with signal @var{AA}.
9398
9399 @item @code{N}@var{AA}@code{;}@var{t...}@code{;}@var{d...}@code{;}@var{b...} @strong{(obsolete)}
9400 @tab
9401 @var{AA} = signal number; @var{t...} = address of symbol "_start";
9402 @var{d...} = base of data section; @var{b...} = base of bss section.
9403 @emph{Note: only used by Cisco Systems targets. The difference between
9404 this reply and the "qOffsets" query is that the 'N' packet may arrive
9405 spontaneously whereas the 'qOffsets' is a query initiated by the host
9406 debugger.}
9407
9408 @item @code{O}@var{XX...}
9409 @tab
9410 @var{XX...} is hex encoding of @sc{ascii} data. This can happen at any time
9411 while the program is running and the debugger should continue to wait
9412 for 'W', 'T', etc.
9413
9414 @end multitable
9415
9416 The following set and query packets have already been defined.
9417
9418 @multitable @columnfractions .2 .2 .6
9419
9420 @item current thread
9421 @tab @code{q}@code{C}
9422 @tab Return the current thread id.
9423 @item
9424 @tab reply @code{QC}@var{pid}
9425 @tab
9426 Where @var{pid} is a HEX encoded 16 bit process id.
9427 @item
9428 @tab reply *
9429 @tab Any other reply implies the old pid.
9430
9431 @item all thread ids
9432 @tab @code{q}@code{fThreadInfo}
9433 @item
9434 @tab @code{q}@code{sThreadInfo}
9435 @tab
9436 Obtain a list of active thread ids from the target (OS). Since there
9437 may be too many active threads to fit into one reply packet, this query
9438 works iteratively: it may require more than one query/reply sequence to
9439 obtain the entire list of threads. The first query of the sequence will
9440 be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
9441 sequence will be the @code{qs}@code{ThreadInfo} query.
9442 @item
9443 @tab
9444 @tab NOTE: replaces the @code{qL} query (see below).
9445 @item
9446 @tab reply @code{m}@var{<id>}
9447 @tab A single thread id
9448 @item
9449 @tab reply @code{m}@var{<id>,}@var{<id>...}
9450 @tab a comma-separated list of thread ids
9451 @item
9452 @tab reply @code{l}
9453 @tab (lower case 'el') denotes end of list.
9454 @item
9455 @tab
9456 @tab
9457 In response to each query, the target will reply with a list of one
9458 or more thread ids, in big-endian hex, separated by commas. GDB will
9459 respond to each reply with a request for more thread ids (using the
9460 @code{qs} form of the query), until the target responds with @code{l}
9461 (lower-case el, for @code{'last'}).
9462
9463 @item extra thread info
9464 @tab @code{qfThreadExtraInfo,}@var{<id>}
9465 @tab
9466 @item
9467 @tab
9468 @tab
9469 Where @var{<id>} is a thread-id in big-endian hex.
9470 Obtain a printable string description of a thread's attributes from
9471 the target OS. This string may contain anything that the target OS
9472 thinks is interesting for @value{GDBN} to tell the user about the thread.
9473 The string is displayed in @value{GDBN}'s @samp{info threads} display.
9474 Some examples of possible thread extra info strings are "Runnable", or
9475 "Blocked on Mutex".
9476 @item
9477 @tab reply @var{XX...}
9478 @tab
9479 Where @var{XX...} is a hex encoding of @sc{ascii} data, comprising the
9480 printable string containing the extra information about the thread's
9481 attributes.
9482
9483 @item query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
9484 @tab @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread}
9485 @tab
9486 @item
9487 @tab
9488 @tab
9489 Obtain thread information from RTOS. Where: @var{startflag} (one hex
9490 digit) is one to indicate the first query and zero to indicate a
9491 subsequent query; @var{threadcount} (two hex digits) is the maximum
9492 number of threads the response packet can contain; and @var{nextthread}
9493 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
9494 returned in the response as @var{argthread}.
9495 @item
9496 @tab
9497 @tab NOTE: this query is replaced by the @code{q}@code{fThreadInfo}
9498 query (see above).
9499 @item
9500 @tab reply @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread...}
9501 @tab
9502 @item
9503 @tab
9504 @tab
9505 Where: @var{count} (two hex digits) is the number of threads being
9506 returned; @var{done} (one hex digit) is zero to indicate more threads
9507 and one indicates no further threads; @var{argthreadid} (eight hex
9508 digits) is @var{nextthread} from the request packet; @var{thread...} is
9509 a sequence of thread IDs from the target. @var{threadid} (eight hex
9510 digits). See @code{remote.c:parse_threadlist_response()}.
9511
9512 @item compute CRC of memory block
9513 @tab @code{q}@code{CRC:}@var{addr}@code{,}@var{length}
9514 @tab
9515 @item
9516 @tab reply @code{E}@var{NN}
9517 @tab An error (such as memory fault)
9518 @item
9519 @tab reply @code{C}@var{CRC32}
9520 @tab A 32 bit cyclic redundancy check of the specified memory region.
9521
9522 @item query sect offs
9523 @tab @code{q}@code{Offsets}
9524 @tab
9525 Get section offsets that the target used when re-locating the downloaded
9526 image. @emph{Note: while a @code{Bss} offset is included in the
9527 response, @value{GDBN} ignores this and instead applies the @code{Data}
9528 offset to the @code{Bss} section.}
9529 @item
9530 @tab reply @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
9531
9532 @item thread info request
9533 @tab @code{q}@code{P}@var{mode}@var{threadid}
9534 @tab
9535 Returns information on @var{threadid}. Where: @var{mode} is a hex
9536 encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
9537 @item
9538 @tab reply *
9539 @tab
9540 See @code{remote.c:remote_unpack_thread_info_response()}.
9541
9542 @item remote command
9543 @tab @code{q}@code{Rcmd,}@var{COMMAND}
9544 @tab
9545 @var{COMMAND} (hex encoded) is passed to the local interpreter for
9546 execution. Invalid commands should be reported using the output string.
9547 Before the final result packet, the target may also respond with a
9548 number of intermediate @code{O}@var{OUTPUT} console output
9549 packets. @emph{Implementors should note that providing access to a
9550 stubs's interpreter may have security implications}.
9551 @item
9552 @tab reply @code{OK}
9553 @tab
9554 A command response with no output.
9555 @item
9556 @tab reply @var{OUTPUT}
9557 @tab
9558 A command response with the hex encoded output string @var{OUTPUT}.
9559 @item
9560 @tab reply @code{E}@var{NN}
9561 @tab
9562 Indicate a badly formed request.
9563
9564 @item
9565 @tab reply @samp{}
9566 @tab
9567 When @samp{q}@samp{Rcmd} is not recognized.
9568
9569 @end multitable
9570
9571 The following @samp{g}/@samp{G} packets have previously been defined.
9572 In the below, some thirty-two bit registers are transferred as sixty-four
9573 bits. Those registers should be zero/sign extended (which?) to fill the
9574 space allocated. Register bytes are transfered in target byte order.
9575 The two nibbles within a register byte are transfered most-significant -
9576 least-significant.
9577
9578 @multitable @columnfractions .5 .5
9579
9580 @item MIPS32
9581 @tab
9582 All registers are transfered as thirty-two bit quantities in the order:
9583 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
9584 registers; fsr; fir; fp.
9585
9586 @item MIPS64
9587 @tab
9588 All registers are transfered as sixty-four bit quantities (including
9589 thirty-two bit registers such as @code{sr}). The ordering is the same
9590 as @code{MIPS32}.
9591
9592 @end multitable
9593
9594 Example sequence of a target being re-started. Notice how the restart
9595 does not get any direct output:
9596
9597 @example
9598 <- @code{R00}
9599 -> @code{+}
9600 @emph{target restarts}
9601 <- @code{?}
9602 -> @code{+}
9603 -> @code{T001:1234123412341234}
9604 <- @code{+}
9605 @end example
9606
9607 Example sequence of a target being stepped by a single instruction:
9608
9609 @example
9610 <- @code{G1445...}
9611 -> @code{+}
9612 <- @code{s}
9613 -> @code{+}
9614 @emph{time passes}
9615 -> @code{T001:1234123412341234}
9616 <- @code{+}
9617 <- @code{g}
9618 -> @code{+}
9619 -> @code{1455...}
9620 <- @code{+}
9621 @end example
9622
9623 @node Server
9624 @subsubsection Using the @code{gdbserver} program
9625
9626 @kindex gdbserver
9627 @cindex remote connection without stubs
9628 @code{gdbserver} is a control program for Unix-like systems, which
9629 allows you to connect your program with a remote @value{GDBN} via
9630 @code{target remote}---but without linking in the usual debugging stub.
9631
9632 @code{gdbserver} is not a complete replacement for the debugging stubs,
9633 because it requires essentially the same operating-system facilities
9634 that @value{GDBN} itself does. In fact, a system that can run
9635 @code{gdbserver} to connect to a remote @value{GDBN} could also run
9636 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
9637 because it is a much smaller program than @value{GDBN} itself. It is
9638 also easier to port than all of @value{GDBN}, so you may be able to get
9639 started more quickly on a new system by using @code{gdbserver}.
9640 Finally, if you develop code for real-time systems, you may find that
9641 the tradeoffs involved in real-time operation make it more convenient to
9642 do as much development work as possible on another system, for example
9643 by cross-compiling. You can use @code{gdbserver} to make a similar
9644 choice for debugging.
9645
9646 @value{GDBN} and @code{gdbserver} communicate via either a serial line
9647 or a TCP connection, using the standard @value{GDBN} remote serial
9648 protocol.
9649
9650 @table @emph
9651 @item On the target machine,
9652 you need to have a copy of the program you want to debug.
9653 @code{gdbserver} does not need your program's symbol table, so you can
9654 strip the program if necessary to save space. @value{GDBN} on the host
9655 system does all the symbol handling.
9656
9657 To use the server, you must tell it how to communicate with @value{GDBN};
9658 the name of your program; and the arguments for your program. The
9659 syntax is:
9660
9661 @smallexample
9662 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
9663 @end smallexample
9664
9665 @var{comm} is either a device name (to use a serial line) or a TCP
9666 hostname and portnumber. For example, to debug Emacs with the argument
9667 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
9668 @file{/dev/com1}:
9669
9670 @smallexample
9671 target> gdbserver /dev/com1 emacs foo.txt
9672 @end smallexample
9673
9674 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
9675 with it.
9676
9677 To use a TCP connection instead of a serial line:
9678
9679 @smallexample
9680 target> gdbserver host:2345 emacs foo.txt
9681 @end smallexample
9682
9683 The only difference from the previous example is the first argument,
9684 specifying that you are communicating with the host @value{GDBN} via
9685 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
9686 expect a TCP connection from machine @samp{host} to local TCP port 2345.
9687 (Currently, the @samp{host} part is ignored.) You can choose any number
9688 you want for the port number as long as it does not conflict with any
9689 TCP ports already in use on the target system (for example, @code{23} is
9690 reserved for @code{telnet}).@footnote{If you choose a port number that
9691 conflicts with another service, @code{gdbserver} prints an error message
9692 and exits.} You must use the same port number with the host @value{GDBN}
9693 @code{target remote} command.
9694
9695 @item On the @value{GDBN} host machine,
9696 you need an unstripped copy of your program, since @value{GDBN} needs
9697 symbols and debugging information. Start up @value{GDBN} as usual,
9698 using the name of the local copy of your program as the first argument.
9699 (You may also need the @w{@samp{--baud}} option if the serial line is
9700 running at anything other than 9600@dmn{bps}.) After that, use @code{target
9701 remote} to establish communications with @code{gdbserver}. Its argument
9702 is either a device name (usually a serial device, like
9703 @file{/dev/ttyb}), or a TCP port descriptor in the form
9704 @code{@var{host}:@var{PORT}}. For example:
9705
9706 @smallexample
9707 (@value{GDBP}) target remote /dev/ttyb
9708 @end smallexample
9709
9710 @noindent
9711 communicates with the server via serial line @file{/dev/ttyb}, and
9712
9713 @smallexample
9714 (@value{GDBP}) target remote the-target:2345
9715 @end smallexample
9716
9717 @noindent
9718 communicates via a TCP connection to port 2345 on host @w{@file{the-target}}.
9719 For TCP connections, you must start up @code{gdbserver} prior to using
9720 the @code{target remote} command. Otherwise you may get an error whose
9721 text depends on the host system, but which usually looks something like
9722 @samp{Connection refused}.
9723 @end table
9724
9725 @node NetWare
9726 @subsubsection Using the @code{gdbserve.nlm} program
9727
9728 @kindex gdbserve.nlm
9729 @code{gdbserve.nlm} is a control program for NetWare systems, which
9730 allows you to connect your program with a remote @value{GDBN} via
9731 @code{target remote}.
9732
9733 @value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
9734 using the standard @value{GDBN} remote serial protocol.
9735
9736 @table @emph
9737 @item On the target machine,
9738 you need to have a copy of the program you want to debug.
9739 @code{gdbserve.nlm} does not need your program's symbol table, so you
9740 can strip the program if necessary to save space. @value{GDBN} on the
9741 host system does all the symbol handling.
9742
9743 To use the server, you must tell it how to communicate with
9744 @value{GDBN}; the name of your program; and the arguments for your
9745 program. The syntax is:
9746
9747 @smallexample
9748 load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
9749 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
9750 @end smallexample
9751
9752 @var{board} and @var{port} specify the serial line; @var{baud} specifies
9753 the baud rate used by the connection. @var{port} and @var{node} default
9754 to 0, @var{baud} defaults to 9600@dmn{bps}.
9755
9756 For example, to debug Emacs with the argument @samp{foo.txt}and
9757 communicate with @value{GDBN} over serial port number 2 or board 1
9758 using a 19200@dmn{bps} connection:
9759
9760 @smallexample
9761 load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
9762 @end smallexample
9763
9764 @item On the @value{GDBN} host machine,
9765 you need an unstripped copy of your program, since @value{GDBN} needs
9766 symbols and debugging information. Start up @value{GDBN} as usual,
9767 using the name of the local copy of your program as the first argument.
9768 (You may also need the @w{@samp{--baud}} option if the serial line is
9769 running at anything other than 9600@dmn{bps}. After that, use @code{target
9770 remote} to establish communications with @code{gdbserve.nlm}. Its
9771 argument is a device name (usually a serial device, like
9772 @file{/dev/ttyb}). For example:
9773
9774 @smallexample
9775 (@value{GDBP}) target remote /dev/ttyb
9776 @end smallexample
9777
9778 @noindent
9779 communications with the server via serial line @file{/dev/ttyb}.
9780 @end table
9781
9782 @node KOD
9783 @section Kernel Object Display
9784
9785 @cindex kernel object display
9786 @cindex kernel object
9787 @cindex KOD
9788
9789 Some targets support kernel object display. Using this facility,
9790 @value{GDBN} communicates specially with the underlying operating system
9791 and can display information about operating system-level objects such as
9792 mutexes and other synchronization objects. Exactly which objects can be
9793 displayed is determined on a per-OS basis.
9794
9795 Use the @code{set os} command to set the operating system. This tells
9796 @value{GDBN} which kernel object display module to initialize:
9797
9798 @example
9799 (@value{GDBP}) set os cisco
9800 @end example
9801
9802 If @code{set os} succeeds, @value{GDBN} will display some information
9803 about the operating system, and will create a new @code{info} command
9804 which can be used to query the target. The @code{info} command is named
9805 after the operating system:
9806
9807 @example
9808 (@value{GDBP}) info cisco
9809 List of Cisco Kernel Objects
9810 Object Description
9811 any Any and all objects
9812 @end example
9813
9814 Further subcommands can be used to query about particular objects known
9815 by the kernel.
9816
9817 There is currently no way to determine whether a given operating system
9818 is supported other than to try it.
9819
9820
9821 @node Configurations
9822 @chapter Configuration-Specific Information
9823
9824 While nearly all @value{GDBN} commands are available for all native and
9825 cross versions of the debugger, there are some exceptions. This chapter
9826 describes things that are only available in certain configurations.
9827
9828 There are three major categories of configurations: native
9829 configurations, where the host and target are the same, embedded
9830 operating system configurations, which are usually the same for several
9831 different processor architectures, and bare embedded processors, which
9832 are quite different from each other.
9833
9834 @menu
9835 * Native::
9836 * Embedded OS::
9837 * Embedded Processors::
9838 * Architectures::
9839 @end menu
9840
9841 @node Native
9842 @section Native
9843
9844 This section describes details specific to particular native
9845 configurations.
9846
9847 @menu
9848 * HP-UX:: HP-UX
9849 * SVR4 Process Information:: SVR4 process information
9850 @end menu
9851
9852 @node HP-UX
9853 @subsection HP-UX
9854
9855 On HP-UX systems, if you refer to a function or variable name that
9856 begins with a dollar sign, @value{GDBN} searches for a user or system
9857 name first, before it searches for a convenience variable.
9858
9859 @node SVR4 Process Information
9860 @subsection SVR4 process information
9861
9862 @kindex /proc
9863 @cindex process image
9864
9865 Many versions of SVR4 provide a facility called @samp{/proc} that can be
9866 used to examine the image of a running process using file-system
9867 subroutines. If @value{GDBN} is configured for an operating system with
9868 this facility, the command @code{info proc} is available to report on
9869 several kinds of information about the process running your program.
9870 @code{info proc} works only on SVR4 systems that include the
9871 @code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
9872 and Unixware, but not HP-UX or Linux, for example.
9873
9874 @table @code
9875 @kindex info proc
9876 @item info proc
9877 Summarize available information about the process.
9878
9879 @kindex info proc mappings
9880 @item info proc mappings
9881 Report on the address ranges accessible in the program, with information
9882 on whether your program may read, write, or execute each range.
9883
9884 @kindex info proc times
9885 @item info proc times
9886 Starting time, user CPU time, and system CPU time for your program and
9887 its children.
9888
9889 @kindex info proc id
9890 @item info proc id
9891 Report on the process IDs related to your program: its own process ID,
9892 the ID of its parent, the process group ID, and the session ID.
9893
9894 @kindex info proc status
9895 @item info proc status
9896 General information on the state of the process. If the process is
9897 stopped, this report includes the reason for stopping, and any signal
9898 received.
9899
9900 @item info proc all
9901 Show all the above information about the process.
9902 @end table
9903
9904 @node Embedded OS
9905 @section Embedded Operating Systems
9906
9907 This section describes configurations involving the debugging of
9908 embedded operating systems that are available for several different
9909 architectures.
9910
9911 @menu
9912 * VxWorks:: Using @value{GDBN} with VxWorks
9913 @end menu
9914
9915 @value{GDBN} includes the ability to debug programs running on
9916 various real-time operating systems.
9917
9918 @node VxWorks
9919 @subsection Using @value{GDBN} with VxWorks
9920
9921 @cindex VxWorks
9922
9923 @table @code
9924
9925 @kindex target vxworks
9926 @item target vxworks @var{machinename}
9927 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
9928 is the target system's machine name or IP address.
9929
9930 @end table
9931
9932 On VxWorks, @code{load} links @var{filename} dynamically on the
9933 current target system as well as adding its symbols in @value{GDBN}.
9934
9935 @value{GDBN} enables developers to spawn and debug tasks running on networked
9936 VxWorks targets from a Unix host. Already-running tasks spawned from
9937 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
9938 both the Unix host and on the VxWorks target. The program
9939 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
9940 installed with the name @code{vxgdb}, to distinguish it from a
9941 @value{GDBN} for debugging programs on the host itself.)
9942
9943 @table @code
9944 @item VxWorks-timeout @var{args}
9945 @kindex vxworks-timeout
9946 All VxWorks-based targets now support the option @code{vxworks-timeout}.
9947 This option is set by the user, and @var{args} represents the number of
9948 seconds @value{GDBN} waits for responses to rpc's. You might use this if
9949 your VxWorks target is a slow software simulator or is on the far side
9950 of a thin network line.
9951 @end table
9952
9953 The following information on connecting to VxWorks was current when
9954 this manual was produced; newer releases of VxWorks may use revised
9955 procedures.
9956
9957 @kindex INCLUDE_RDB
9958 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
9959 to include the remote debugging interface routines in the VxWorks
9960 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
9961 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
9962 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
9963 source debugging task @code{tRdbTask} when VxWorks is booted. For more
9964 information on configuring and remaking VxWorks, see the manufacturer's
9965 manual.
9966 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
9967
9968 Once you have included @file{rdb.a} in your VxWorks system image and set
9969 your Unix execution search path to find @value{GDBN}, you are ready to
9970 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
9971 @code{vxgdb}, depending on your installation).
9972
9973 @value{GDBN} comes up showing the prompt:
9974
9975 @example
9976 (vxgdb)
9977 @end example
9978
9979 @menu
9980 * VxWorks Connection:: Connecting to VxWorks
9981 * VxWorks Download:: VxWorks download
9982 * VxWorks Attach:: Running tasks
9983 @end menu
9984
9985 @node VxWorks Connection
9986 @subsubsection Connecting to VxWorks
9987
9988 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
9989 network. To connect to a target whose host name is ``@code{tt}'', type:
9990
9991 @example
9992 (vxgdb) target vxworks tt
9993 @end example
9994
9995 @need 750
9996 @value{GDBN} displays messages like these:
9997
9998 @smallexample
9999 Attaching remote machine across net...
10000 Connected to tt.
10001 @end smallexample
10002
10003 @need 1000
10004 @value{GDBN} then attempts to read the symbol tables of any object modules
10005 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
10006 these files by searching the directories listed in the command search
10007 path (@pxref{Environment, ,Your program's environment}); if it fails
10008 to find an object file, it displays a message such as:
10009
10010 @example
10011 prog.o: No such file or directory.
10012 @end example
10013
10014 When this happens, add the appropriate directory to the search path with
10015 the @value{GDBN} command @code{path}, and execute the @code{target}
10016 command again.
10017
10018 @node VxWorks Download
10019 @subsubsection VxWorks download
10020
10021 @cindex download to VxWorks
10022 If you have connected to the VxWorks target and you want to debug an
10023 object that has not yet been loaded, you can use the @value{GDBN}
10024 @code{load} command to download a file from Unix to VxWorks
10025 incrementally. The object file given as an argument to the @code{load}
10026 command is actually opened twice: first by the VxWorks target in order
10027 to download the code, then by @value{GDBN} in order to read the symbol
10028 table. This can lead to problems if the current working directories on
10029 the two systems differ. If both systems have NFS mounted the same
10030 filesystems, you can avoid these problems by using absolute paths.
10031 Otherwise, it is simplest to set the working directory on both systems
10032 to the directory in which the object file resides, and then to reference
10033 the file by its name, without any path. For instance, a program
10034 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
10035 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
10036 program, type this on VxWorks:
10037
10038 @example
10039 -> cd "@var{vxpath}/vw/demo/rdb"
10040 @end example
10041
10042 @noindent
10043 Then, in @value{GDBN}, type:
10044
10045 @example
10046 (vxgdb) cd @var{hostpath}/vw/demo/rdb
10047 (vxgdb) load prog.o
10048 @end example
10049
10050 @value{GDBN} displays a response similar to this:
10051
10052 @smallexample
10053 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
10054 @end smallexample
10055
10056 You can also use the @code{load} command to reload an object module
10057 after editing and recompiling the corresponding source file. Note that
10058 this makes @value{GDBN} delete all currently-defined breakpoints,
10059 auto-displays, and convenience variables, and to clear the value
10060 history. (This is necessary in order to preserve the integrity of
10061 debugger's data structures that reference the target system's symbol
10062 table.)
10063
10064 @node VxWorks Attach
10065 @subsubsection Running tasks
10066
10067 @cindex running VxWorks tasks
10068 You can also attach to an existing task using the @code{attach} command as
10069 follows:
10070
10071 @example
10072 (vxgdb) attach @var{task}
10073 @end example
10074
10075 @noindent
10076 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
10077 or suspended when you attach to it. Running tasks are suspended at
10078 the time of attachment.
10079
10080 @node Embedded Processors
10081 @section Embedded Processors
10082
10083 This section goes into details specific to particular embedded
10084 configurations.
10085
10086 @menu
10087 * A29K Embedded:: AMD A29K Embedded
10088 * ARM:: ARM
10089 * H8/300:: Hitachi H8/300
10090 * H8/500:: Hitachi H8/500
10091 * i960:: Intel i960
10092 * M32R/D:: Mitsubishi M32R/D
10093 * M68K:: Motorola M68K
10094 * M88K:: Motorola M88K
10095 * MIPS Embedded:: MIPS Embedded
10096 * PA:: HP PA Embedded
10097 * PowerPC: PowerPC
10098 * SH:: Hitachi SH
10099 * Sparclet:: Tsqware Sparclet
10100 * Sparclite:: Fujitsu Sparclite
10101 * ST2000:: Tandem ST2000
10102 * Z8000:: Zilog Z8000
10103 @end menu
10104
10105 @node A29K Embedded
10106 @subsection AMD A29K Embedded
10107
10108 @menu
10109 * A29K UDI::
10110 * A29K EB29K::
10111 * Comms (EB29K):: Communications setup
10112 * gdb-EB29K:: EB29K cross-debugging
10113 * Remote Log:: Remote log
10114 @end menu
10115
10116 @table @code
10117
10118 @kindex target adapt
10119 @item target adapt @var{dev}
10120 Adapt monitor for A29K.
10121
10122 @kindex target amd-eb
10123 @item target amd-eb @var{dev} @var{speed} @var{PROG}
10124 @cindex AMD EB29K
10125 Remote PC-resident AMD EB29K board, attached over serial lines.
10126 @var{dev} is the serial device, as for @code{target remote};
10127 @var{speed} allows you to specify the linespeed; and @var{PROG} is the
10128 name of the program to be debugged, as it appears to DOS on the PC.
10129 @xref{A29K EB29K, ,EBMON protocol for AMD29K}.
10130
10131 @end table
10132
10133 @node A29K UDI
10134 @subsubsection A29K UDI
10135
10136 @cindex UDI
10137 @cindex AMD29K via UDI
10138
10139 @value{GDBN} supports AMD's UDI (``Universal Debugger Interface'')
10140 protocol for debugging the a29k processor family. To use this
10141 configuration with AMD targets running the MiniMON monitor, you need the
10142 program @code{MONTIP}, available from AMD at no charge. You can also
10143 use @value{GDBN} with the UDI-conformant a29k simulator program
10144 @code{ISSTIP}, also available from AMD.
10145
10146 @table @code
10147 @item target udi @var{keyword}
10148 @kindex udi
10149 Select the UDI interface to a remote a29k board or simulator, where
10150 @var{keyword} is an entry in the AMD configuration file @file{udi_soc}.
10151 This file contains keyword entries which specify parameters used to
10152 connect to a29k targets. If the @file{udi_soc} file is not in your
10153 working directory, you must set the environment variable @samp{UDICONF}
10154 to its pathname.
10155 @end table
10156
10157 @node A29K EB29K
10158 @subsubsection EBMON protocol for AMD29K
10159
10160 @cindex EB29K board
10161 @cindex running 29K programs
10162
10163 AMD distributes a 29K development board meant to fit in a PC, together
10164 with a DOS-hosted monitor program called @code{EBMON}. As a shorthand
10165 term, this development system is called the ``EB29K''. To use
10166 @value{GDBN} from a Unix system to run programs on the EB29K board, you
10167 must first connect a serial cable between the PC (which hosts the EB29K
10168 board) and a serial port on the Unix system. In the following, we
10169 assume you've hooked the cable between the PC's @file{COM1} port and
10170 @file{/dev/ttya} on the Unix system.
10171
10172 @node Comms (EB29K)
10173 @subsubsection Communications setup
10174
10175 The next step is to set up the PC's port, by doing something like this
10176 in DOS on the PC:
10177
10178 @example
10179 C:\> MODE com1:9600,n,8,1,none
10180 @end example
10181
10182 @noindent
10183 This example---run on an MS DOS 4.0 system---sets the PC port to 9600
10184 bps, no parity, eight data bits, one stop bit, and no ``retry'' action;
10185 you must match the communications parameters when establishing the Unix
10186 end of the connection as well.
10187 @c FIXME: Who knows what this "no retry action" crud from the DOS manual may
10188 @c mean? It's optional; leave it out? ---doc@cygnus.com, 25feb91
10189 @c
10190 @c It's optional, but it's unwise to omit it: who knows what is the
10191 @c default value set when the DOS machines boots? "No retry" means that
10192 @c the DOS serial device driver won't retry the operation if it fails;
10193 @c I understand that this is needed because the GDB serial protocol
10194 @c handles any errors and retransmissions itself. ---Eli Zaretskii, 3sep99
10195
10196 To give control of the PC to the Unix side of the serial line, type
10197 the following at the DOS console:
10198
10199 @example
10200 C:\> CTTY com1
10201 @end example
10202
10203 @noindent
10204 (Later, if you wish to return control to the DOS console, you can use
10205 the command @code{CTTY con}---but you must send it over the device that
10206 had control, in our example over the @file{COM1} serial line.)
10207
10208 From the Unix host, use a communications program such as @code{tip} or
10209 @code{cu} to communicate with the PC; for example,
10210
10211 @example
10212 cu -s 9600 -l /dev/ttya
10213 @end example
10214
10215 @noindent
10216 The @code{cu} options shown specify, respectively, the linespeed and the
10217 serial port to use. If you use @code{tip} instead, your command line
10218 may look something like the following:
10219
10220 @example
10221 tip -9600 /dev/ttya
10222 @end example
10223
10224 @noindent
10225 Your system may require a different name where we show
10226 @file{/dev/ttya} as the argument to @code{tip}. The communications
10227 parameters, including which port to use, are associated with the
10228 @code{tip} argument in the ``remote'' descriptions file---normally the
10229 system table @file{/etc/remote}.
10230 @c FIXME: What if anything needs doing to match the "n,8,1,none" part of
10231 @c the DOS side's comms setup? cu can support -o (odd
10232 @c parity), -e (even parity)---apparently no settings for no parity or
10233 @c for character size. Taken from stty maybe...? John points out tip
10234 @c can set these as internal variables, eg ~s parity=none; man stty
10235 @c suggests that it *might* work to stty these options with stdin or
10236 @c stdout redirected... ---doc@cygnus.com, 25feb91
10237 @c
10238 @c There's nothing to be done for the "none" part of the DOS MODE
10239 @c command. The rest of the parameters should be matched by the
10240 @c baudrate, bits, and parity used by the Unix side. ---Eli Zaretskii, 3Sep99
10241
10242 @kindex EBMON
10243 Using the @code{tip} or @code{cu} connection, change the DOS working
10244 directory to the directory containing a copy of your 29K program, then
10245 start the PC program @code{EBMON} (an EB29K control program supplied
10246 with your board by AMD). You should see an initial display from
10247 @code{EBMON} similar to the one that follows, ending with the
10248 @code{EBMON} prompt @samp{#}---
10249
10250 @example
10251 C:\> G:
10252
10253 G:\> CD \usr\joe\work29k
10254
10255 G:\USR\JOE\WORK29K> EBMON
10256 Am29000 PC Coprocessor Board Monitor, version 3.0-18
10257 Copyright 1990 Advanced Micro Devices, Inc.
10258 Written by Gibbons and Associates, Inc.
10259
10260 Enter '?' or 'H' for help
10261
10262 PC Coprocessor Type = EB29K
10263 I/O Base = 0x208
10264 Memory Base = 0xd0000
10265
10266 Data Memory Size = 2048KB
10267 Available I-RAM Range = 0x8000 to 0x1fffff
10268 Available D-RAM Range = 0x80002000 to 0x801fffff
10269
10270 PageSize = 0x400
10271 Register Stack Size = 0x800
10272 Memory Stack Size = 0x1800
10273
10274 CPU PRL = 0x3
10275 Am29027 Available = No
10276 Byte Write Available = Yes
10277
10278 # ~.
10279 @end example
10280
10281 Then exit the @code{cu} or @code{tip} program (done in the example by
10282 typing @code{~.} at the @code{EBMON} prompt). @code{EBMON} keeps
10283 running, ready for @value{GDBN} to take over.
10284
10285 For this example, we've assumed what is probably the most convenient
10286 way to make sure the same 29K program is on both the PC and the Unix
10287 system: a PC/NFS connection that establishes ``drive @file{G:}'' on the
10288 PC as a file system on the Unix host. If you do not have PC/NFS or
10289 something similar connecting the two systems, you must arrange some
10290 other way---perhaps floppy-disk transfer---of getting the 29K program
10291 from the Unix system to the PC; @value{GDBN} does @emph{not} download it over the
10292 serial line.
10293
10294 @node gdb-EB29K
10295 @subsubsection EB29K cross-debugging
10296
10297 Finally, @code{cd} to the directory containing an image of your 29K
10298 program on the Unix system, and start @value{GDBN}---specifying as argument the
10299 name of your 29K program:
10300
10301 @example
10302 cd /usr/joe/work29k
10303 @value{GDBP} myfoo
10304 @end example
10305
10306 @need 500
10307 Now you can use the @code{target} command:
10308
10309 @example
10310 target amd-eb /dev/ttya 9600 MYFOO
10311 @c FIXME: test above 'target amd-eb' as spelled, with caps! caps are meant to
10312 @c emphasize that this is the name as seen by DOS (since I think DOS is
10313 @c single-minded about case of letters). ---doc@cygnus.com, 25feb91
10314 @end example
10315
10316 @noindent
10317 In this example, we've assumed your program is in a file called
10318 @file{myfoo}. Note that the filename given as the last argument to
10319 @code{target amd-eb} should be the name of the program as it appears to DOS.
10320 In our example this is simply @code{MYFOO}, but in general it can include
10321 a DOS path, and depending on your transfer mechanism may not resemble
10322 the name on the Unix side.
10323
10324 At this point, you can set any breakpoints you wish; when you are ready
10325 to see your program run on the 29K board, use the @value{GDBN} command
10326 @code{run}.
10327
10328 To stop debugging the remote program, use the @value{GDBN} @code{detach}
10329 command.
10330
10331 To return control of the PC to its console, use @code{tip} or @code{cu}
10332 once again, after your @value{GDBN} session has concluded, to attach to
10333 @code{EBMON}. You can then type the command @code{q} to shut down
10334 @code{EBMON}, returning control to the DOS command-line interpreter.
10335 Type @kbd{CTTY con} to return command input to the main DOS console,
10336 and type @kbd{~.} to leave @code{tip} or @code{cu}.
10337
10338 @node Remote Log
10339 @subsubsection Remote log
10340 @kindex eb.log
10341 @cindex log file for EB29K
10342
10343 The @code{target amd-eb} command creates a file @file{eb.log} in the
10344 current working directory, to help debug problems with the connection.
10345 @file{eb.log} records all the output from @code{EBMON}, including echoes
10346 of the commands sent to it. Running @samp{tail -f} on this file in
10347 another window often helps to understand trouble with @code{EBMON}, or
10348 unexpected events on the PC side of the connection.
10349
10350 @node ARM
10351 @subsection ARM
10352
10353 @table @code
10354
10355 @kindex target rdi
10356 @item target rdi @var{dev}
10357 ARM Angel monitor, via RDI library interface to ADP protocol. You may
10358 use this target to communicate with both boards running the Angel
10359 monitor, or with the EmbeddedICE JTAG debug device.
10360
10361 @kindex target rdp
10362 @item target rdp @var{dev}
10363 ARM Demon monitor.
10364
10365 @end table
10366
10367 @node H8/300
10368 @subsection Hitachi H8/300
10369
10370 @table @code
10371
10372 @kindex target hms@r{, with H8/300}
10373 @item target hms @var{dev}
10374 A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host.
10375 Use special commands @code{device} and @code{speed} to control the serial
10376 line and the communications speed used.
10377
10378 @kindex target e7000@r{, with H8/300}
10379 @item target e7000 @var{dev}
10380 E7000 emulator for Hitachi H8 and SH.
10381
10382 @kindex target sh3@r{, with H8/300}
10383 @kindex target sh3e@r{, with H8/300}
10384 @item target sh3 @var{dev}
10385 @itemx target sh3e @var{dev}
10386 Hitachi SH-3 and SH-3E target systems.
10387
10388 @end table
10389
10390 @cindex download to H8/300 or H8/500
10391 @cindex H8/300 or H8/500 download
10392 @cindex download to Hitachi SH
10393 @cindex Hitachi SH download
10394 When you select remote debugging to a Hitachi SH, H8/300, or H8/500
10395 board, the @code{load} command downloads your program to the Hitachi
10396 board and also opens it as the current executable target for
10397 @value{GDBN} on your host (like the @code{file} command).
10398
10399 @value{GDBN} needs to know these things to talk to your
10400 Hitachi SH, H8/300, or H8/500:
10401
10402 @enumerate
10403 @item
10404 that you want to use @samp{target hms}, the remote debugging interface
10405 for Hitachi microprocessors, or @samp{target e7000}, the in-circuit
10406 emulator for the Hitachi SH and the Hitachi 300H. (@samp{target hms} is
10407 the default when @value{GDBN} is configured specifically for the Hitachi SH,
10408 H8/300, or H8/500.)
10409
10410 @item
10411 what serial device connects your host to your Hitachi board (the first
10412 serial device available on your host is the default).
10413
10414 @item
10415 what speed to use over the serial device.
10416 @end enumerate
10417
10418 @menu
10419 * Hitachi Boards:: Connecting to Hitachi boards.
10420 * Hitachi ICE:: Using the E7000 In-Circuit Emulator.
10421 * Hitachi Special:: Special @value{GDBN} commands for Hitachi micros.
10422 @end menu
10423
10424 @node Hitachi Boards
10425 @subsubsection Connecting to Hitachi boards
10426
10427 @c only for Unix hosts
10428 @kindex device
10429 @cindex serial device, Hitachi micros
10430 Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
10431 need to explicitly set the serial device. The default @var{port} is the
10432 first available port on your host. This is only necessary on Unix
10433 hosts, where it is typically something like @file{/dev/ttya}.
10434
10435 @kindex speed
10436 @cindex serial line speed, Hitachi micros
10437 @code{@value{GDBN}} has another special command to set the communications
10438 speed: @samp{speed @var{bps}}. This command also is only used from Unix
10439 hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
10440 the DOS @code{mode} command (for instance,
10441 @w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
10442
10443 The @samp{device} and @samp{speed} commands are available only when you
10444 use a Unix host to debug your Hitachi microprocessor programs. If you
10445 use a DOS host,
10446 @value{GDBN} depends on an auxiliary terminate-and-stay-resident program
10447 called @code{asynctsr} to communicate with the development board
10448 through a PC serial port. You must also use the DOS @code{mode} command
10449 to set up the serial port on the DOS side.
10450
10451 The following sample session illustrates the steps needed to start a
10452 program under @value{GDBN} control on an H8/300. The example uses a
10453 sample H8/300 program called @file{t.x}. The procedure is the same for
10454 the Hitachi SH and the H8/500.
10455
10456 First hook up your development board. In this example, we use a
10457 board attached to serial port @code{COM2}; if you use a different serial
10458 port, substitute its name in the argument of the @code{mode} command.
10459 When you call @code{asynctsr}, the auxiliary comms program used by the
10460 debugger, you give it just the numeric part of the serial port's name;
10461 for example, @samp{asyncstr 2} below runs @code{asyncstr} on
10462 @code{COM2}.
10463
10464 @example
10465 C:\H8300\TEST> asynctsr 2
10466 C:\H8300\TEST> mode com2:9600,n,8,1,p
10467
10468 Resident portion of MODE loaded
10469
10470 COM2: 9600, n, 8, 1, p
10471
10472 @end example
10473
10474 @quotation
10475 @emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
10476 @code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
10477 disable it, or even boot without it, to use @code{asynctsr} to control
10478 your development board.
10479 @end quotation
10480
10481 @kindex target hms@r{, and serial protocol}
10482 Now that serial communications are set up, and the development board is
10483 connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
10484 the name of your program as the argument. @code{@value{GDBN}} prompts
10485 you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
10486 commands to begin your debugging session: @samp{target hms} to specify
10487 cross-debugging to the Hitachi board, and the @code{load} command to
10488 download your program to the board. @code{load} displays the names of
10489 the program's sections, and a @samp{*} for each 2K of data downloaded.
10490 (If you want to refresh @value{GDBN} data on symbols or on the
10491 executable file without downloading, use the @value{GDBN} commands
10492 @code{file} or @code{symbol-file}. These commands, and @code{load}
10493 itself, are described in @ref{Files,,Commands to specify files}.)
10494
10495 @smallexample
10496 (eg-C:\H8300\TEST) @value{GDBP} t.x
10497 @value{GDBN} is free software and you are welcome to distribute copies
10498 of it under certain conditions; type "show copying" to see
10499 the conditions.
10500 There is absolutely no warranty for @value{GDBN}; type "show warranty"
10501 for details.
10502 @value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
10503 (@value{GDBP}) target hms
10504 Connected to remote H8/300 HMS system.
10505 (@value{GDBP}) load t.x
10506 .text : 0x8000 .. 0xabde ***********
10507 .data : 0xabde .. 0xad30 *
10508 .stack : 0xf000 .. 0xf014 *
10509 @end smallexample
10510
10511 At this point, you're ready to run or debug your program. From here on,
10512 you can use all the usual @value{GDBN} commands. The @code{break} command
10513 sets breakpoints; the @code{run} command starts your program;
10514 @code{print} or @code{x} display data; the @code{continue} command
10515 resumes execution after stopping at a breakpoint. You can use the
10516 @code{help} command at any time to find out more about @value{GDBN} commands.
10517
10518 Remember, however, that @emph{operating system} facilities aren't
10519 available on your development board; for example, if your program hangs,
10520 you can't send an interrupt---but you can press the @sc{reset} switch!
10521
10522 Use the @sc{reset} button on the development board
10523 @itemize @bullet
10524 @item
10525 to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
10526 no way to pass an interrupt signal to the development board); and
10527
10528 @item
10529 to return to the @value{GDBN} command prompt after your program finishes
10530 normally. The communications protocol provides no other way for @value{GDBN}
10531 to detect program completion.
10532 @end itemize
10533
10534 In either case, @value{GDBN} sees the effect of a @sc{reset} on the
10535 development board as a ``normal exit'' of your program.
10536
10537 @node Hitachi ICE
10538 @subsubsection Using the E7000 in-circuit emulator
10539
10540 @kindex target e7000@r{, with Hitachi ICE}
10541 You can use the E7000 in-circuit emulator to develop code for either the
10542 Hitachi SH or the H8/300H. Use one of these forms of the @samp{target
10543 e7000} command to connect @value{GDBN} to your E7000:
10544
10545 @table @code
10546 @item target e7000 @var{port} @var{speed}
10547 Use this form if your E7000 is connected to a serial port. The
10548 @var{port} argument identifies what serial port to use (for example,
10549 @samp{com2}). The third argument is the line speed in bits per second
10550 (for example, @samp{9600}).
10551
10552 @item target e7000 @var{hostname}
10553 If your E7000 is installed as a host on a TCP/IP network, you can just
10554 specify its hostname; @value{GDBN} uses @code{telnet} to connect.
10555 @end table
10556
10557 @node Hitachi Special
10558 @subsubsection Special @value{GDBN} commands for Hitachi micros
10559
10560 Some @value{GDBN} commands are available only for the H8/300:
10561
10562 @table @code
10563
10564 @kindex set machine
10565 @kindex show machine
10566 @item set machine h8300
10567 @itemx set machine h8300h
10568 Condition @value{GDBN} for one of the two variants of the H8/300
10569 architecture with @samp{set machine}. You can use @samp{show machine}
10570 to check which variant is currently in effect.
10571
10572 @end table
10573
10574 @node H8/500
10575 @subsection H8/500
10576
10577 @table @code
10578
10579 @kindex set memory @var{mod}
10580 @cindex memory models, H8/500
10581 @item set memory @var{mod}
10582 @itemx show memory
10583 Specify which H8/500 memory model (@var{mod}) you are using with
10584 @samp{set memory}; check which memory model is in effect with @samp{show
10585 memory}. The accepted values for @var{mod} are @code{small},
10586 @code{big}, @code{medium}, and @code{compact}.
10587
10588 @end table
10589
10590 @node i960
10591 @subsection Intel i960
10592
10593 @table @code
10594
10595 @kindex target mon960
10596 @item target mon960 @var{dev}
10597 MON960 monitor for Intel i960.
10598
10599 @item target nindy @var{devicename}
10600 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10601 the name of the serial device to use for the connection, e.g.
10602 @file{/dev/ttya}.
10603
10604 @end table
10605
10606 @cindex Nindy
10607 @cindex i960
10608 @dfn{Nindy} is a ROM Monitor program for Intel 960 target systems. When
10609 @value{GDBN} is configured to control a remote Intel 960 using Nindy, you can
10610 tell @value{GDBN} how to connect to the 960 in several ways:
10611
10612 @itemize @bullet
10613 @item
10614 Through command line options specifying serial port, version of the
10615 Nindy protocol, and communications speed;
10616
10617 @item
10618 By responding to a prompt on startup;
10619
10620 @item
10621 By using the @code{target} command at any point during your @value{GDBN}
10622 session. @xref{Target Commands, ,Commands for managing targets}.
10623
10624 @kindex target nindy
10625 @item target nindy @var{devicename}
10626 An Intel 960 board controlled by a Nindy Monitor. @var{devicename} is
10627 the name of the serial device to use for the connection, e.g.
10628 @file{/dev/ttya}.
10629
10630 @end itemize
10631
10632 @cindex download to Nindy-960
10633 With the Nindy interface to an Intel 960 board, @code{load}
10634 downloads @var{filename} to the 960 as well as adding its symbols in
10635 @value{GDBN}.
10636
10637 @menu
10638 * Nindy Startup:: Startup with Nindy
10639 * Nindy Options:: Options for Nindy
10640 * Nindy Reset:: Nindy reset command
10641 @end menu
10642
10643 @node Nindy Startup
10644 @subsubsection Startup with Nindy
10645
10646 If you simply start @code{@value{GDBP}} without using any command-line
10647 options, you are prompted for what serial port to use, @emph{before} you
10648 reach the ordinary @value{GDBN} prompt:
10649
10650 @example
10651 Attach /dev/ttyNN -- specify NN, or "quit" to quit:
10652 @end example
10653
10654 @noindent
10655 Respond to the prompt with whatever suffix (after @samp{/dev/tty})
10656 identifies the serial port you want to use. You can, if you choose,
10657 simply start up with no Nindy connection by responding to the prompt
10658 with an empty line. If you do this and later wish to attach to Nindy,
10659 use @code{target} (@pxref{Target Commands, ,Commands for managing targets}).
10660
10661 @node Nindy Options
10662 @subsubsection Options for Nindy
10663
10664 These are the startup options for beginning your @value{GDBN} session with a
10665 Nindy-960 board attached:
10666
10667 @table @code
10668 @item -r @var{port}
10669 Specify the serial port name of a serial interface to be used to connect
10670 to the target system. This option is only available when @value{GDBN} is
10671 configured for the Intel 960 target architecture. You may specify
10672 @var{port} as any of: a full pathname (e.g. @samp{-r /dev/ttya}), a
10673 device name in @file{/dev} (e.g. @samp{-r ttya}), or simply the unique
10674 suffix for a specific @code{tty} (e.g. @samp{-r a}).
10675
10676 @item -O
10677 (An uppercase letter ``O'', not a zero.) Specify that @value{GDBN} should use
10678 the ``old'' Nindy monitor protocol to connect to the target system.
10679 This option is only available when @value{GDBN} is configured for the Intel 960
10680 target architecture.
10681
10682 @quotation
10683 @emph{Warning:} if you specify @samp{-O}, but are actually trying to
10684 connect to a target system that expects the newer protocol, the connection
10685 fails, appearing to be a speed mismatch. @value{GDBN} repeatedly
10686 attempts to reconnect at several different line speeds. You can abort
10687 this process with an interrupt.
10688 @end quotation
10689
10690 @item -brk
10691 Specify that @value{GDBN} should first send a @code{BREAK} signal to the target
10692 system, in an attempt to reset it, before connecting to a Nindy target.
10693
10694 @quotation
10695 @emph{Warning:} Many target systems do not have the hardware that this
10696 requires; it only works with a few boards.
10697 @end quotation
10698 @end table
10699
10700 The standard @samp{-b} option controls the line speed used on the serial
10701 port.
10702
10703 @c @group
10704 @node Nindy Reset
10705 @subsubsection Nindy reset command
10706
10707 @table @code
10708 @item reset
10709 @kindex reset
10710 For a Nindy target, this command sends a ``break'' to the remote target
10711 system; this is only useful if the target has been equipped with a
10712 circuit to perform a hard reset (or some other interesting action) when
10713 a break is detected.
10714 @end table
10715 @c @end group
10716
10717 @node M32R/D
10718 @subsection Mitsubishi M32R/D
10719
10720 @table @code
10721
10722 @kindex target m32r
10723 @item target m32r @var{dev}
10724 Mitsubishi M32R/D ROM monitor.
10725
10726 @end table
10727
10728 @node M68K
10729 @subsection M68k
10730
10731 The Motorola m68k configuration includes ColdFire support, and
10732 target command for the following ROM monitors.
10733
10734 @table @code
10735
10736 @kindex target abug
10737 @item target abug @var{dev}
10738 ABug ROM monitor for M68K.
10739
10740 @kindex target cpu32bug
10741 @item target cpu32bug @var{dev}
10742 CPU32BUG monitor, running on a CPU32 (M68K) board.
10743
10744 @kindex target dbug
10745 @item target dbug @var{dev}
10746 dBUG ROM monitor for Motorola ColdFire.
10747
10748 @kindex target est
10749 @item target est @var{dev}
10750 EST-300 ICE monitor, running on a CPU32 (M68K) board.
10751
10752 @kindex target rom68k
10753 @item target rom68k @var{dev}
10754 ROM 68K monitor, running on an M68K IDP board.
10755
10756 @end table
10757
10758 If @value{GDBN} is configured with @code{m68*-ericsson-*}, it will
10759 instead have only a single special target command:
10760
10761 @table @code
10762
10763 @kindex target es1800
10764 @item target es1800 @var{dev}
10765 ES-1800 emulator for M68K.
10766
10767 @end table
10768
10769 [context?]
10770
10771 @table @code
10772
10773 @kindex target rombug
10774 @item target rombug @var{dev}
10775 ROMBUG ROM monitor for OS/9000.
10776
10777 @end table
10778
10779 @node M88K
10780 @subsection M88K
10781
10782 @table @code
10783
10784 @kindex target bug
10785 @item target bug @var{dev}
10786 BUG monitor, running on a MVME187 (m88k) board.
10787
10788 @end table
10789
10790 @node MIPS Embedded
10791 @subsection MIPS Embedded
10792
10793 @cindex MIPS boards
10794 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
10795 MIPS board attached to a serial line. This is available when
10796 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
10797
10798 @need 1000
10799 Use these @value{GDBN} commands to specify the connection to your target board:
10800
10801 @table @code
10802 @item target mips @var{port}
10803 @kindex target mips @var{port}
10804 To run a program on the board, start up @code{@value{GDBP}} with the
10805 name of your program as the argument. To connect to the board, use the
10806 command @samp{target mips @var{port}}, where @var{port} is the name of
10807 the serial port connected to the board. If the program has not already
10808 been downloaded to the board, you may use the @code{load} command to
10809 download it. You can then use all the usual @value{GDBN} commands.
10810
10811 For example, this sequence connects to the target board through a serial
10812 port, and loads and runs a program called @var{prog} through the
10813 debugger:
10814
10815 @example
10816 host$ @value{GDBP} @var{prog}
10817 @value{GDBN} is free software and @dots{}
10818 (@value{GDBP}) target mips /dev/ttyb
10819 (@value{GDBP}) load @var{prog}
10820 (@value{GDBP}) run
10821 @end example
10822
10823 @item target mips @var{hostname}:@var{portnumber}
10824 On some @value{GDBN} host configurations, you can specify a TCP
10825 connection (for instance, to a serial line managed by a terminal
10826 concentrator) instead of a serial port, using the syntax
10827 @samp{@var{hostname}:@var{portnumber}}.
10828
10829 @item target pmon @var{port}
10830 @kindex target pmon @var{port}
10831 PMON ROM monitor.
10832
10833 @item target ddb @var{port}
10834 @kindex target ddb @var{port}
10835 NEC's DDB variant of PMON for Vr4300.
10836
10837 @item target lsi @var{port}
10838 @kindex target lsi @var{port}
10839 LSI variant of PMON.
10840
10841 @kindex target r3900
10842 @item target r3900 @var{dev}
10843 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
10844
10845 @kindex target array
10846 @item target array @var{dev}
10847 Array Tech LSI33K RAID controller board.
10848
10849 @end table
10850
10851
10852 @noindent
10853 @value{GDBN} also supports these special commands for MIPS targets:
10854
10855 @table @code
10856 @item set processor @var{args}
10857 @itemx show processor
10858 @kindex set processor @var{args}
10859 @kindex show processor
10860 Use the @code{set processor} command to set the type of MIPS
10861 processor when you want to access processor-type-specific registers.
10862 For example, @code{set processor @var{r3041}} tells @value{GDBN}
10863 to use the CPO registers appropriate for the 3041 chip.
10864 Use the @code{show processor} command to see what MIPS processor @value{GDBN}
10865 is using. Use the @code{info reg} command to see what registers
10866 @value{GDBN} is using.
10867
10868 @item set mipsfpu double
10869 @itemx set mipsfpu single
10870 @itemx set mipsfpu none
10871 @itemx show mipsfpu
10872 @kindex set mipsfpu
10873 @kindex show mipsfpu
10874 @cindex MIPS remote floating point
10875 @cindex floating point, MIPS remote
10876 If your target board does not support the MIPS floating point
10877 coprocessor, you should use the command @samp{set mipsfpu none} (if you
10878 need this, you may wish to put the command in your @value{GDBN} init
10879 file). This tells @value{GDBN} how to find the return value of
10880 functions which return floating point values. It also allows
10881 @value{GDBN} to avoid saving the floating point registers when calling
10882 functions on the board. If you are using a floating point coprocessor
10883 with only single precision floating point support, as on the @sc{r4650}
10884 processor, use the command @samp{set mipsfpu single}. The default
10885 double precision floating point coprocessor may be selected using
10886 @samp{set mipsfpu double}.
10887
10888 In previous versions the only choices were double precision or no
10889 floating point, so @samp{set mipsfpu on} will select double precision
10890 and @samp{set mipsfpu off} will select no floating point.
10891
10892 As usual, you can inquire about the @code{mipsfpu} variable with
10893 @samp{show mipsfpu}.
10894
10895 @item set remotedebug @var{n}
10896 @itemx show remotedebug
10897 @kindex set remotedebug@r{, MIPS protocol}
10898 @kindex show remotedebug@r{, MIPS protocol}
10899 @cindex @code{remotedebug}, MIPS protocol
10900 @cindex MIPS @code{remotedebug} protocol
10901 @c FIXME! For this to be useful, you must know something about the MIPS
10902 @c FIXME...protocol. Where is it described?
10903 You can see some debugging information about communications with the board
10904 by setting the @code{remotedebug} variable. If you set it to @code{1} using
10905 @samp{set remotedebug 1}, every packet is displayed. If you set it
10906 to @code{2}, every character is displayed. You can check the current value
10907 at any time with the command @samp{show remotedebug}.
10908
10909 @item set timeout @var{seconds}
10910 @itemx set retransmit-timeout @var{seconds}
10911 @itemx show timeout
10912 @itemx show retransmit-timeout
10913 @cindex @code{timeout}, MIPS protocol
10914 @cindex @code{retransmit-timeout}, MIPS protocol
10915 @kindex set timeout
10916 @kindex show timeout
10917 @kindex set retransmit-timeout
10918 @kindex show retransmit-timeout
10919 You can control the timeout used while waiting for a packet, in the MIPS
10920 remote protocol, with the @code{set timeout @var{seconds}} command. The
10921 default is 5 seconds. Similarly, you can control the timeout used while
10922 waiting for an acknowledgement of a packet with the @code{set
10923 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
10924 You can inspect both values with @code{show timeout} and @code{show
10925 retransmit-timeout}. (These commands are @emph{only} available when
10926 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
10927
10928 The timeout set by @code{set timeout} does not apply when @value{GDBN}
10929 is waiting for your program to stop. In that case, @value{GDBN} waits
10930 forever because it has no way of knowing how long the program is going
10931 to run before stopping.
10932 @end table
10933
10934 @node PowerPC
10935 @subsection PowerPC
10936
10937 @table @code
10938
10939 @kindex target dink32
10940 @item target dink32 @var{dev}
10941 DINK32 ROM monitor.
10942
10943 @kindex target ppcbug
10944 @item target ppcbug @var{dev}
10945 @kindex target ppcbug1
10946 @item target ppcbug1 @var{dev}
10947 PPCBUG ROM monitor for PowerPC.
10948
10949 @kindex target sds
10950 @item target sds @var{dev}
10951 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
10952
10953 @end table
10954
10955 @node PA
10956 @subsection HP PA Embedded
10957
10958 @table @code
10959
10960 @kindex target op50n
10961 @item target op50n @var{dev}
10962 OP50N monitor, running on an OKI HPPA board.
10963
10964 @kindex target w89k
10965 @item target w89k @var{dev}
10966 W89K monitor, running on a Winbond HPPA board.
10967
10968 @end table
10969
10970 @node SH
10971 @subsection Hitachi SH
10972
10973 @table @code
10974
10975 @kindex target hms@r{, with Hitachi SH}
10976 @item target hms @var{dev}
10977 A Hitachi SH board attached via serial line to your host. Use special
10978 commands @code{device} and @code{speed} to control the serial line and
10979 the communications speed used.
10980
10981 @kindex target e7000@r{, with Hitachi SH}
10982 @item target e7000 @var{dev}
10983 E7000 emulator for Hitachi SH.
10984
10985 @kindex target sh3@r{, with SH}
10986 @kindex target sh3e@r{, with SH}
10987 @item target sh3 @var{dev}
10988 @item target sh3e @var{dev}
10989 Hitachi SH-3 and SH-3E target systems.
10990
10991 @end table
10992
10993 @node Sparclet
10994 @subsection Tsqware Sparclet
10995
10996 @cindex Sparclet
10997
10998 @value{GDBN} enables developers to debug tasks running on
10999 Sparclet targets from a Unix host.
11000 @value{GDBN} uses code that runs on
11001 both the Unix host and on the Sparclet target. The program
11002 @code{@value{GDBP}} is installed and executed on the Unix host.
11003
11004 @table @code
11005 @item timeout @var{args}
11006 @kindex remotetimeout
11007 @value{GDBN} supports the option @code{remotetimeout}.
11008 This option is set by the user, and @var{args} represents the number of
11009 seconds @value{GDBN} waits for responses.
11010 @end table
11011
11012 @kindex Compiling
11013 When compiling for debugging, include the options @samp{-g} to get debug
11014 information and @samp{-Ttext} to relocate the program to where you wish to
11015 load it on the target. You may also want to add the options @samp{-n} or
11016 @samp{-N} in order to reduce the size of the sections. Example:
11017
11018 @example
11019 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
11020 @end example
11021
11022 You can use @code{objdump} to verify that the addresses are what you intended:
11023
11024 @example
11025 sparclet-aout-objdump --headers --syms prog
11026 @end example
11027
11028 @kindex Running
11029 Once you have set
11030 your Unix execution search path to find @value{GDBN}, you are ready to
11031 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
11032 (or @code{sparclet-aout-gdb}, depending on your installation).
11033
11034 @value{GDBN} comes up showing the prompt:
11035
11036 @example
11037 (gdbslet)
11038 @end example
11039
11040 @menu
11041 * Sparclet File:: Setting the file to debug
11042 * Sparclet Connection:: Connecting to Sparclet
11043 * Sparclet Download:: Sparclet download
11044 * Sparclet Execution:: Running and debugging
11045 @end menu
11046
11047 @node Sparclet File
11048 @subsubsection Setting file to debug
11049
11050 The @value{GDBN} command @code{file} lets you choose with program to debug.
11051
11052 @example
11053 (gdbslet) file prog
11054 @end example
11055
11056 @need 1000
11057 @value{GDBN} then attempts to read the symbol table of @file{prog}.
11058 @value{GDBN} locates
11059 the file by searching the directories listed in the command search
11060 path.
11061 If the file was compiled with debug information (option "-g"), source
11062 files will be searched as well.
11063 @value{GDBN} locates
11064 the source files by searching the directories listed in the directory search
11065 path (@pxref{Environment, ,Your program's environment}).
11066 If it fails
11067 to find a file, it displays a message such as:
11068
11069 @example
11070 prog: No such file or directory.
11071 @end example
11072
11073 When this happens, add the appropriate directories to the search paths with
11074 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
11075 @code{target} command again.
11076
11077 @node Sparclet Connection
11078 @subsubsection Connecting to Sparclet
11079
11080 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
11081 To connect to a target on serial port ``@code{ttya}'', type:
11082
11083 @example
11084 (gdbslet) target sparclet /dev/ttya
11085 Remote target sparclet connected to /dev/ttya
11086 main () at ../prog.c:3
11087 @end example
11088
11089 @need 750
11090 @value{GDBN} displays messages like these:
11091
11092 @example
11093 Connected to ttya.
11094 @end example
11095
11096 @node Sparclet Download
11097 @subsubsection Sparclet download
11098
11099 @cindex download to Sparclet
11100 Once connected to the Sparclet target,
11101 you can use the @value{GDBN}
11102 @code{load} command to download the file from the host to the target.
11103 The file name and load offset should be given as arguments to the @code{load}
11104 command.
11105 Since the file format is aout, the program must be loaded to the starting
11106 address. You can use @code{objdump} to find out what this value is. The load
11107 offset is an offset which is added to the VMA (virtual memory address)
11108 of each of the file's sections.
11109 For instance, if the program
11110 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
11111 and bss at 0x12010170, in @value{GDBN}, type:
11112
11113 @example
11114 (gdbslet) load prog 0x12010000
11115 Loading section .text, size 0xdb0 vma 0x12010000
11116 @end example
11117
11118 If the code is loaded at a different address then what the program was linked
11119 to, you may need to use the @code{section} and @code{add-symbol-file} commands
11120 to tell @value{GDBN} where to map the symbol table.
11121
11122 @node Sparclet Execution
11123 @subsubsection Running and debugging
11124
11125 @cindex running and debugging Sparclet programs
11126 You can now begin debugging the task using @value{GDBN}'s execution control
11127 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
11128 manual for the list of commands.
11129
11130 @example
11131 (gdbslet) b main
11132 Breakpoint 1 at 0x12010000: file prog.c, line 3.
11133 (gdbslet) run
11134 Starting program: prog
11135 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
11136 3 char *symarg = 0;
11137 (gdbslet) step
11138 4 char *execarg = "hello!";
11139 (gdbslet)
11140 @end example
11141
11142 @node Sparclite
11143 @subsection Fujitsu Sparclite
11144
11145 @table @code
11146
11147 @kindex target sparclite
11148 @item target sparclite @var{dev}
11149 Fujitsu sparclite boards, used only for the purpose of loading.
11150 You must use an additional command to debug the program.
11151 For example: target remote @var{dev} using @value{GDBN} standard
11152 remote protocol.
11153
11154 @end table
11155
11156 @node ST2000
11157 @subsection Tandem ST2000
11158
11159 @value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
11160 STDBUG protocol.
11161
11162 To connect your ST2000 to the host system, see the manufacturer's
11163 manual. Once the ST2000 is physically attached, you can run:
11164
11165 @example
11166 target st2000 @var{dev} @var{speed}
11167 @end example
11168
11169 @noindent
11170 to establish it as your debugging environment. @var{dev} is normally
11171 the name of a serial device, such as @file{/dev/ttya}, connected to the
11172 ST2000 via a serial line. You can instead specify @var{dev} as a TCP
11173 connection (for example, to a serial line attached via a terminal
11174 concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
11175
11176 The @code{load} and @code{attach} commands are @emph{not} defined for
11177 this target; you must load your program into the ST2000 as you normally
11178 would for standalone operation. @value{GDBN} reads debugging information
11179 (such as symbols) from a separate, debugging version of the program
11180 available on your host computer.
11181 @c FIXME!! This is terribly vague; what little content is here is
11182 @c basically hearsay.
11183
11184 @cindex ST2000 auxiliary commands
11185 These auxiliary @value{GDBN} commands are available to help you with the ST2000
11186 environment:
11187
11188 @table @code
11189 @item st2000 @var{command}
11190 @kindex st2000 @var{cmd}
11191 @cindex STDBUG commands (ST2000)
11192 @cindex commands to STDBUG (ST2000)
11193 Send a @var{command} to the STDBUG monitor. See the manufacturer's
11194 manual for available commands.
11195
11196 @item connect
11197 @cindex connect (to STDBUG)
11198 Connect the controlling terminal to the STDBUG command monitor. When
11199 you are done interacting with STDBUG, typing either of two character
11200 sequences gets you back to the @value{GDBN} command prompt:
11201 @kbd{@key{RET}~.} (Return, followed by tilde and period) or
11202 @kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
11203 @end table
11204
11205 @node Z8000
11206 @subsection Zilog Z8000
11207
11208 @cindex Z8000
11209 @cindex simulator, Z8000
11210 @cindex Zilog Z8000 simulator
11211
11212 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
11213 a Z8000 simulator.
11214
11215 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
11216 unsegmented variant of the Z8000 architecture) or the Z8001 (the
11217 segmented variant). The simulator recognizes which architecture is
11218 appropriate by inspecting the object code.
11219
11220 @table @code
11221 @item target sim @var{args}
11222 @kindex sim
11223 @kindex target sim@r{, with Z8000}
11224 Debug programs on a simulated CPU. If the simulator supports setup
11225 options, specify them via @var{args}.
11226 @end table
11227
11228 @noindent
11229 After specifying this target, you can debug programs for the simulated
11230 CPU in the same style as programs for your host computer; use the
11231 @code{file} command to load a new program image, the @code{run} command
11232 to run your program, and so on.
11233
11234 As well as making available all the usual machine registers
11235 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
11236 additional items of information as specially named registers:
11237
11238 @table @code
11239
11240 @item cycles
11241 Counts clock-ticks in the simulator.
11242
11243 @item insts
11244 Counts instructions run in the simulator.
11245
11246 @item time
11247 Execution time in 60ths of a second.
11248
11249 @end table
11250
11251 You can refer to these values in @value{GDBN} expressions with the usual
11252 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
11253 conditional breakpoint that suspends only after at least 5000
11254 simulated clock ticks.
11255
11256 @node Architectures
11257 @section Architectures
11258
11259 This section describes characteristics of architectures that affect
11260 all uses of @value{GDBN} with the architecture, both native and cross.
11261
11262 @menu
11263 * A29K::
11264 * Alpha::
11265 * MIPS::
11266 @end menu
11267
11268 @node A29K
11269 @subsection A29K
11270
11271 @table @code
11272
11273 @kindex set rstack_high_address
11274 @cindex AMD 29K register stack
11275 @cindex register stack, AMD29K
11276 @item set rstack_high_address @var{address}
11277 On AMD 29000 family processors, registers are saved in a separate
11278 @dfn{register stack}. There is no way for @value{GDBN} to determine the
11279 extent of this stack. Normally, @value{GDBN} just assumes that the
11280 stack is ``large enough''. This may result in @value{GDBN} referencing
11281 memory locations that do not exist. If necessary, you can get around
11282 this problem by specifying the ending address of the register stack with
11283 the @code{set rstack_high_address} command. The argument should be an
11284 address, which you probably want to precede with @samp{0x} to specify in
11285 hexadecimal.
11286
11287 @kindex show rstack_high_address
11288 @item show rstack_high_address
11289 Display the current limit of the register stack, on AMD 29000 family
11290 processors.
11291
11292 @end table
11293
11294 @node Alpha
11295 @subsection Alpha
11296
11297 See the following section.
11298
11299 @node MIPS
11300 @subsection MIPS
11301
11302 @cindex stack on Alpha
11303 @cindex stack on MIPS
11304 @cindex Alpha stack
11305 @cindex MIPS stack
11306 Alpha- and MIPS-based computers use an unusual stack frame, which
11307 sometimes requires @value{GDBN} to search backward in the object code to
11308 find the beginning of a function.
11309
11310 @cindex response time, MIPS debugging
11311 To improve response time (especially for embedded applications, where
11312 @value{GDBN} may be restricted to a slow serial line for this search)
11313 you may want to limit the size of this search, using one of these
11314 commands:
11315
11316 @table @code
11317 @cindex @code{heuristic-fence-post} (Alpha,MIPS)
11318 @item set heuristic-fence-post @var{limit}
11319 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
11320 search for the beginning of a function. A value of @var{0} (the
11321 default) means there is no limit. However, except for @var{0}, the
11322 larger the limit the more bytes @code{heuristic-fence-post} must search
11323 and therefore the longer it takes to run.
11324
11325 @item show heuristic-fence-post
11326 Display the current limit.
11327 @end table
11328
11329 @noindent
11330 These commands are available @emph{only} when @value{GDBN} is configured
11331 for debugging programs on Alpha or MIPS processors.
11332
11333
11334 @node Controlling GDB
11335 @chapter Controlling @value{GDBN}
11336
11337 You can alter the way @value{GDBN} interacts with you by using the
11338 @code{set} command. For commands controlling how @value{GDBN} displays
11339 data, see @ref{Print Settings, ,Print settings}. Other settings are
11340 described here.
11341
11342 @menu
11343 * Prompt:: Prompt
11344 * Editing:: Command editing
11345 * History:: Command history
11346 * Screen Size:: Screen size
11347 * Numbers:: Numbers
11348 * Messages/Warnings:: Optional warnings and messages
11349 * Debugging Output:: Optional messages about internal happenings
11350 @end menu
11351
11352 @node Prompt
11353 @section Prompt
11354
11355 @cindex prompt
11356
11357 @value{GDBN} indicates its readiness to read a command by printing a string
11358 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
11359 can change the prompt string with the @code{set prompt} command. For
11360 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
11361 the prompt in one of the @value{GDBN} sessions so that you can always tell
11362 which one you are talking to.
11363
11364 @emph{Note:} @code{set prompt} does not add a space for you after the
11365 prompt you set. This allows you to set a prompt which ends in a space
11366 or a prompt that does not.
11367
11368 @table @code
11369 @kindex set prompt
11370 @item set prompt @var{newprompt}
11371 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
11372
11373 @kindex show prompt
11374 @item show prompt
11375 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
11376 @end table
11377
11378 @node Editing
11379 @section Command editing
11380 @cindex readline
11381 @cindex command line editing
11382
11383 @value{GDBN} reads its input commands via the @dfn{readline} interface. This
11384 @sc{gnu} library provides consistent behavior for programs which provide a
11385 command line interface to the user. Advantages are @sc{gnu} Emacs-style
11386 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
11387 substitution, and a storage and recall of command history across
11388 debugging sessions.
11389
11390 You may control the behavior of command line editing in @value{GDBN} with the
11391 command @code{set}.
11392
11393 @table @code
11394 @kindex set editing
11395 @cindex editing
11396 @item set editing
11397 @itemx set editing on
11398 Enable command line editing (enabled by default).
11399
11400 @item set editing off
11401 Disable command line editing.
11402
11403 @kindex show editing
11404 @item show editing
11405 Show whether command line editing is enabled.
11406 @end table
11407
11408 @node History
11409 @section Command history
11410
11411 @value{GDBN} can keep track of the commands you type during your
11412 debugging sessions, so that you can be certain of precisely what
11413 happened. Use these commands to manage the @value{GDBN} command
11414 history facility.
11415
11416 @table @code
11417 @cindex history substitution
11418 @cindex history file
11419 @kindex set history filename
11420 @kindex GDBHISTFILE
11421 @item set history filename @var{fname}
11422 Set the name of the @value{GDBN} command history file to @var{fname}.
11423 This is the file where @value{GDBN} reads an initial command history
11424 list, and where it writes the command history from this session when it
11425 exits. You can access this list through history expansion or through
11426 the history command editing characters listed below. This file defaults
11427 to the value of the environment variable @code{GDBHISTFILE}, or to
11428 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
11429 is not set.
11430
11431 @cindex history save
11432 @kindex set history save
11433 @item set history save
11434 @itemx set history save on
11435 Record command history in a file, whose name may be specified with the
11436 @code{set history filename} command. By default, this option is disabled.
11437
11438 @item set history save off
11439 Stop recording command history in a file.
11440
11441 @cindex history size
11442 @kindex set history size
11443 @item set history size @var{size}
11444 Set the number of commands which @value{GDBN} keeps in its history list.
11445 This defaults to the value of the environment variable
11446 @code{HISTSIZE}, or to 256 if this variable is not set.
11447 @end table
11448
11449 @cindex history expansion
11450 History expansion assigns special meaning to the character @kbd{!}.
11451 @ifset have-readline-appendices
11452 @xref{Event Designators}.
11453 @end ifset
11454
11455 Since @kbd{!} is also the logical not operator in C, history expansion
11456 is off by default. If you decide to enable history expansion with the
11457 @code{set history expansion on} command, you may sometimes need to
11458 follow @kbd{!} (when it is used as logical not, in an expression) with
11459 a space or a tab to prevent it from being expanded. The readline
11460 history facilities do not attempt substitution on the strings
11461 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
11462
11463 The commands to control history expansion are:
11464
11465 @table @code
11466 @kindex set history expansion
11467 @item set history expansion on
11468 @itemx set history expansion
11469 Enable history expansion. History expansion is off by default.
11470
11471 @item set history expansion off
11472 Disable history expansion.
11473
11474 The readline code comes with more complete documentation of
11475 editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
11476 or @code{vi} may wish to read it.
11477 @ifset have-readline-appendices
11478 @xref{Command Line Editing}.
11479 @end ifset
11480
11481 @c @group
11482 @kindex show history
11483 @item show history
11484 @itemx show history filename
11485 @itemx show history save
11486 @itemx show history size
11487 @itemx show history expansion
11488 These commands display the state of the @value{GDBN} history parameters.
11489 @code{show history} by itself displays all four states.
11490 @c @end group
11491 @end table
11492
11493 @table @code
11494 @kindex show commands
11495 @item show commands
11496 Display the last ten commands in the command history.
11497
11498 @item show commands @var{n}
11499 Print ten commands centered on command number @var{n}.
11500
11501 @item show commands +
11502 Print ten commands just after the commands last printed.
11503 @end table
11504
11505 @node Screen Size
11506 @section Screen size
11507 @cindex size of screen
11508 @cindex pauses in output
11509
11510 Certain commands to @value{GDBN} may produce large amounts of
11511 information output to the screen. To help you read all of it,
11512 @value{GDBN} pauses and asks you for input at the end of each page of
11513 output. Type @key{RET} when you want to continue the output, or @kbd{q}
11514 to discard the remaining output. Also, the screen width setting
11515 determines when to wrap lines of output. Depending on what is being
11516 printed, @value{GDBN} tries to break the line at a readable place,
11517 rather than simply letting it overflow onto the following line.
11518
11519 Normally @value{GDBN} knows the size of the screen from the terminal
11520 driver software. For example, on Unix @value{GDBN} uses the termcap data base
11521 together with the value of the @code{TERM} environment variable and the
11522 @code{stty rows} and @code{stty cols} settings. If this is not correct,
11523 you can override it with the @code{set height} and @code{set
11524 width} commands:
11525
11526 @table @code
11527 @kindex set height
11528 @kindex set width
11529 @kindex show width
11530 @kindex show height
11531 @item set height @var{lpp}
11532 @itemx show height
11533 @itemx set width @var{cpl}
11534 @itemx show width
11535 These @code{set} commands specify a screen height of @var{lpp} lines and
11536 a screen width of @var{cpl} characters. The associated @code{show}
11537 commands display the current settings.
11538
11539 If you specify a height of zero lines, @value{GDBN} does not pause during
11540 output no matter how long the output is. This is useful if output is to a
11541 file or to an editor buffer.
11542
11543 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
11544 from wrapping its output.
11545 @end table
11546
11547 @node Numbers
11548 @section Numbers
11549 @cindex number representation
11550 @cindex entering numbers
11551
11552 You can always enter numbers in octal, decimal, or hexadecimal in
11553 @value{GDBN} by the usual conventions: octal numbers begin with
11554 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
11555 begin with @samp{0x}. Numbers that begin with none of these are, by
11556 default, entered in base 10; likewise, the default display for
11557 numbers---when no particular format is specified---is base 10. You can
11558 change the default base for both input and output with the @code{set
11559 radix} command.
11560
11561 @table @code
11562 @kindex set input-radix
11563 @item set input-radix @var{base}
11564 Set the default base for numeric input. Supported choices
11565 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11566 specified either unambiguously or using the current default radix; for
11567 example, any of
11568
11569 @smallexample
11570 set radix 012
11571 set radix 10.
11572 set radix 0xa
11573 @end smallexample
11574
11575 @noindent
11576 sets the base to decimal. On the other hand, @samp{set radix 10}
11577 leaves the radix unchanged no matter what it was.
11578
11579 @kindex set output-radix
11580 @item set output-radix @var{base}
11581 Set the default base for numeric display. Supported choices
11582 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
11583 specified either unambiguously or using the current default radix.
11584
11585 @kindex show input-radix
11586 @item show input-radix
11587 Display the current default base for numeric input.
11588
11589 @kindex show output-radix
11590 @item show output-radix
11591 Display the current default base for numeric display.
11592 @end table
11593
11594 @node Messages/Warnings
11595 @section Optional warnings and messages
11596
11597 By default, @value{GDBN} is silent about its inner workings. If you are
11598 running on a slow machine, you may want to use the @code{set verbose}
11599 command. This makes @value{GDBN} tell you when it does a lengthy
11600 internal operation, so you will not think it has crashed.
11601
11602 Currently, the messages controlled by @code{set verbose} are those
11603 which announce that the symbol table for a source file is being read;
11604 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
11605
11606 @table @code
11607 @kindex set verbose
11608 @item set verbose on
11609 Enables @value{GDBN} output of certain informational messages.
11610
11611 @item set verbose off
11612 Disables @value{GDBN} output of certain informational messages.
11613
11614 @kindex show verbose
11615 @item show verbose
11616 Displays whether @code{set verbose} is on or off.
11617 @end table
11618
11619 By default, if @value{GDBN} encounters bugs in the symbol table of an
11620 object file, it is silent; but if you are debugging a compiler, you may
11621 find this information useful (@pxref{Symbol Errors, ,Errors reading
11622 symbol files}).
11623
11624 @table @code
11625
11626 @kindex set complaints
11627 @item set complaints @var{limit}
11628 Permits @value{GDBN} to output @var{limit} complaints about each type of
11629 unusual symbols before becoming silent about the problem. Set
11630 @var{limit} to zero to suppress all complaints; set it to a large number
11631 to prevent complaints from being suppressed.
11632
11633 @kindex show complaints
11634 @item show complaints
11635 Displays how many symbol complaints @value{GDBN} is permitted to produce.
11636
11637 @end table
11638
11639 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
11640 lot of stupid questions to confirm certain commands. For example, if
11641 you try to run a program which is already running:
11642
11643 @example
11644 (@value{GDBP}) run
11645 The program being debugged has been started already.
11646 Start it from the beginning? (y or n)
11647 @end example
11648
11649 If you are willing to unflinchingly face the consequences of your own
11650 commands, you can disable this ``feature'':
11651
11652 @table @code
11653
11654 @kindex set confirm
11655 @cindex flinching
11656 @cindex confirmation
11657 @cindex stupid questions
11658 @item set confirm off
11659 Disables confirmation requests.
11660
11661 @item set confirm on
11662 Enables confirmation requests (the default).
11663
11664 @kindex show confirm
11665 @item show confirm
11666 Displays state of confirmation requests.
11667
11668 @end table
11669
11670 @node Debugging Output
11671 @section Optional messages about internal happenings
11672 @table @code
11673 @kindex set debug arch
11674 @item set debug arch
11675 Turns on or off display of gdbarch debugging info. The default is off
11676 @kindex show debug arch
11677 @item show debug arch
11678 Displays the current state of displaying gdbarch debugging info.
11679 @kindex set debug event
11680 @item set debug event
11681 Turns on or off display of @value{GDBN} event debugging info. The
11682 default is off.
11683 @kindex show debug event
11684 @item show debug event
11685 Displays the current state of displaying @value{GDBN} event debugging
11686 info.
11687 @kindex set debug expression
11688 @item set debug expression
11689 Turns on or off display of @value{GDBN} expression debugging info. The
11690 default is off.
11691 @kindex show debug expression
11692 @item show debug expression
11693 Displays the current state of displaying @value{GDBN} expression
11694 debugging info.
11695 @kindex set debug overload
11696 @item set debug overload
11697 Turns on or off display of @value{GDBN} C++ overload debugging
11698 info. This includes info such as ranking of functions, etc. The default
11699 is off.
11700 @kindex show debug overload
11701 @item show debug overload
11702 Displays the current state of displaying @value{GDBN} C++ overload
11703 debugging info.
11704 @kindex set debug remote
11705 @cindex packets, reporting on stdout
11706 @cindex serial connections, debugging
11707 @item set debug remote
11708 Turns on or off display of reports on all packets sent back and forth across
11709 the serial line to the remote machine. The info is printed on the
11710 @value{GDBN} standard output stream. The default is off.
11711 @kindex show debug remote
11712 @item show debug remote
11713 Displays the state of display of remote packets.
11714 @kindex set debug serial
11715 @item set debug serial
11716 Turns on or off display of @value{GDBN} serial debugging info. The
11717 default is off.
11718 @kindex show debug serial
11719 @item show debug serial
11720 Displays the current state of displaying @value{GDBN} serial debugging
11721 info.
11722 @kindex set debug target
11723 @item set debug target
11724 Turns on or off display of @value{GDBN} target debugging info. This info
11725 includes what is going on at the target level of GDB, as it happens. The
11726 default is off.
11727 @kindex show debug target
11728 @item show debug target
11729 Displays the current state of displaying @value{GDBN} target debugging
11730 info.
11731 @kindex set debug varobj
11732 @item set debug varobj
11733 Turns on or off display of @value{GDBN} variable object debugging
11734 info. The default is off.
11735 @kindex show debug varobj
11736 @item show debug varobj
11737 Displays the current state of displaying @value{GDBN} variable object
11738 debugging info.
11739 @end table
11740
11741 @node Sequences
11742 @chapter Canned Sequences of Commands
11743
11744 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
11745 command lists}), @value{GDBN} provides two ways to store sequences of
11746 commands for execution as a unit: user-defined commands and command
11747 files.
11748
11749 @menu
11750 * Define:: User-defined commands
11751 * Hooks:: User-defined command hooks
11752 * Command Files:: Command files
11753 * Output:: Commands for controlled output
11754 @end menu
11755
11756 @node Define
11757 @section User-defined commands
11758
11759 @cindex user-defined command
11760 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
11761 which you assign a new name as a command. This is done with the
11762 @code{define} command. User commands may accept up to 10 arguments
11763 separated by whitespace. Arguments are accessed within the user command
11764 via @var{$arg0@dots{}$arg9}. A trivial example:
11765
11766 @smallexample
11767 define adder
11768 print $arg0 + $arg1 + $arg2
11769 @end smallexample
11770
11771 @noindent
11772 To execute the command use:
11773
11774 @smallexample
11775 adder 1 2 3
11776 @end smallexample
11777
11778 @noindent
11779 This defines the command @code{adder}, which prints the sum of
11780 its three arguments. Note the arguments are text substitutions, so they may
11781 reference variables, use complex expressions, or even perform inferior
11782 functions calls.
11783
11784 @table @code
11785
11786 @kindex define
11787 @item define @var{commandname}
11788 Define a command named @var{commandname}. If there is already a command
11789 by that name, you are asked to confirm that you want to redefine it.
11790
11791 The definition of the command is made up of other @value{GDBN} command lines,
11792 which are given following the @code{define} command. The end of these
11793 commands is marked by a line containing @code{end}.
11794
11795 @kindex if
11796 @kindex else
11797 @item if
11798 Takes a single argument, which is an expression to evaluate.
11799 It is followed by a series of commands that are executed
11800 only if the expression is true (nonzero).
11801 There can then optionally be a line @code{else}, followed
11802 by a series of commands that are only executed if the expression
11803 was false. The end of the list is marked by a line containing @code{end}.
11804
11805 @kindex while
11806 @item while
11807 The syntax is similar to @code{if}: the command takes a single argument,
11808 which is an expression to evaluate, and must be followed by the commands to
11809 execute, one per line, terminated by an @code{end}.
11810 The commands are executed repeatedly as long as the expression
11811 evaluates to true.
11812
11813 @kindex document
11814 @item document @var{commandname}
11815 Document the user-defined command @var{commandname}, so that it can be
11816 accessed by @code{help}. The command @var{commandname} must already be
11817 defined. This command reads lines of documentation just as @code{define}
11818 reads the lines of the command definition, ending with @code{end}.
11819 After the @code{document} command is finished, @code{help} on command
11820 @var{commandname} displays the documentation you have written.
11821
11822 You may use the @code{document} command again to change the
11823 documentation of a command. Redefining the command with @code{define}
11824 does not change the documentation.
11825
11826 @kindex help user-defined
11827 @item help user-defined
11828 List all user-defined commands, with the first line of the documentation
11829 (if any) for each.
11830
11831 @kindex show user
11832 @item show user
11833 @itemx show user @var{commandname}
11834 Display the @value{GDBN} commands used to define @var{commandname} (but
11835 not its documentation). If no @var{commandname} is given, display the
11836 definitions for all user-defined commands.
11837
11838 @end table
11839
11840 When user-defined commands are executed, the
11841 commands of the definition are not printed. An error in any command
11842 stops execution of the user-defined command.
11843
11844 If used interactively, commands that would ask for confirmation proceed
11845 without asking when used inside a user-defined command. Many @value{GDBN}
11846 commands that normally print messages to say what they are doing omit the
11847 messages when used in a user-defined command.
11848
11849 @node Hooks
11850 @section User-defined command hooks
11851 @cindex command hooks
11852 @cindex hooks, for commands
11853
11854 You may define @emph{hooks}, which are a special kind of user-defined
11855 command. Whenever you run the command @samp{foo}, if the user-defined
11856 command @samp{hook-foo} exists, it is executed (with no arguments)
11857 before that command.
11858
11859 @kindex stop@r{, a pseudo-command}
11860 In addition, a pseudo-command, @samp{stop} exists. Defining
11861 (@samp{hook-stop}) makes the associated commands execute every time
11862 execution stops in your program: before breakpoint commands are run,
11863 displays are printed, or the stack frame is printed.
11864
11865 For example, to ignore @code{SIGALRM} signals while
11866 single-stepping, but treat them normally during normal execution,
11867 you could define:
11868
11869 @example
11870 define hook-stop
11871 handle SIGALRM nopass
11872 end
11873
11874 define hook-run
11875 handle SIGALRM pass
11876 end
11877
11878 define hook-continue
11879 handle SIGLARM pass
11880 end
11881 @end example
11882
11883 You can define a hook for any single-word command in @value{GDBN}, but
11884 not for command aliases; you should define a hook for the basic command
11885 name, e.g. @code{backtrace} rather than @code{bt}.
11886 @c FIXME! So how does Joe User discover whether a command is an alias
11887 @c or not?
11888 If an error occurs during the execution of your hook, execution of
11889 @value{GDBN} commands stops and @value{GDBN} issues a prompt
11890 (before the command that you actually typed had a chance to run).
11891
11892 If you try to define a hook which does not match any known command, you
11893 get a warning from the @code{define} command.
11894
11895 @node Command Files
11896 @section Command files
11897
11898 @cindex command files
11899 A command file for @value{GDBN} is a file of lines that are @value{GDBN}
11900 commands. Comments (lines starting with @kbd{#}) may also be included.
11901 An empty line in a command file does nothing; it does not mean to repeat
11902 the last command, as it would from the terminal.
11903
11904 @cindex init file
11905 @cindex @file{.gdbinit}
11906 @cindex @file{gdb.ini}
11907 When you start @value{GDBN}, it automatically executes commands from its
11908 @dfn{init files}. These are files named @file{.gdbinit} on Unix, or
11909 @file{gdb.ini} on DOS/Windows. @value{GDBN} reads the init file (if
11910 any) in your home directory@footnote{On DOS/Windows systems, the home
11911 directory is the one pointed to by the @code{HOME} environment
11912 variable.}, then processes command line options and operands, and then
11913 reads the init file (if any) in the current working directory. This is
11914 so the init file in your home directory can set options (such as
11915 @code{set complaints}) which affect the processing of the command line
11916 options and operands. The init files are not executed if you use the
11917 @samp{-nx} option; @pxref{Mode Options, ,Choosing modes}.
11918
11919 @cindex init file name
11920 On some configurations of @value{GDBN}, the init file is known by a
11921 different name (these are typically environments where a specialized
11922 form of @value{GDBN} may need to coexist with other forms, hence a
11923 different name for the specialized version's init file). These are the
11924 environments with special init file names:
11925
11926 @kindex .vxgdbinit
11927 @itemize @bullet
11928 @item
11929 VxWorks (Wind River Systems real-time OS): @samp{.vxgdbinit}
11930
11931 @kindex .os68gdbinit
11932 @item
11933 OS68K (Enea Data Systems real-time OS): @samp{.os68gdbinit}
11934
11935 @kindex .esgdbinit
11936 @item
11937 ES-1800 (Ericsson Telecom AB M68000 emulator): @samp{.esgdbinit}
11938 @end itemize
11939
11940 You can also request the execution of a command file with the
11941 @code{source} command:
11942
11943 @table @code
11944 @kindex source
11945 @item source @var{filename}
11946 Execute the command file @var{filename}.
11947 @end table
11948
11949 The lines in a command file are executed sequentially. They are not
11950 printed as they are executed. An error in any command terminates execution
11951 of the command file.
11952
11953 Commands that would ask for confirmation if used interactively proceed
11954 without asking when used in a command file. Many @value{GDBN} commands that
11955 normally print messages to say what they are doing omit the messages
11956 when called from command files.
11957
11958 @node Output
11959 @section Commands for controlled output
11960
11961 During the execution of a command file or a user-defined command, normal
11962 @value{GDBN} output is suppressed; the only output that appears is what is
11963 explicitly printed by the commands in the definition. This section
11964 describes three commands useful for generating exactly the output you
11965 want.
11966
11967 @table @code
11968 @kindex echo
11969 @item echo @var{text}
11970 @c I do not consider backslash-space a standard C escape sequence
11971 @c because it is not in ANSI.
11972 Print @var{text}. Nonprinting characters can be included in
11973 @var{text} using C escape sequences, such as @samp{\n} to print a
11974 newline. @strong{No newline is printed unless you specify one.}
11975 In addition to the standard C escape sequences, a backslash followed
11976 by a space stands for a space. This is useful for displaying a
11977 string with spaces at the beginning or the end, since leading and
11978 trailing spaces are otherwise trimmed from all arguments.
11979 To print @samp{@w{ }and foo =@w{ }}, use the command
11980 @samp{echo \@w{ }and foo = \@w{ }}.
11981
11982 A backslash at the end of @var{text} can be used, as in C, to continue
11983 the command onto subsequent lines. For example,
11984
11985 @example
11986 echo This is some text\n\
11987 which is continued\n\
11988 onto several lines.\n
11989 @end example
11990
11991 produces the same output as
11992
11993 @example
11994 echo This is some text\n
11995 echo which is continued\n
11996 echo onto several lines.\n
11997 @end example
11998
11999 @kindex output
12000 @item output @var{expression}
12001 Print the value of @var{expression} and nothing but that value: no
12002 newlines, no @samp{$@var{nn} = }. The value is not entered in the
12003 value history either. @xref{Expressions, ,Expressions}, for more information
12004 on expressions.
12005
12006 @item output/@var{fmt} @var{expression}
12007 Print the value of @var{expression} in format @var{fmt}. You can use
12008 the same formats as for @code{print}. @xref{Output Formats,,Output
12009 formats}, for more information.
12010
12011 @kindex printf
12012 @item printf @var{string}, @var{expressions}@dots{}
12013 Print the values of the @var{expressions} under the control of
12014 @var{string}. The @var{expressions} are separated by commas and may be
12015 either numbers or pointers. Their values are printed as specified by
12016 @var{string}, exactly as if your program were to execute the C
12017 subroutine
12018 @c FIXME: the above implies that at least all ANSI C formats are
12019 @c supported, but it isn't true: %E and %G don't work (or so it seems).
12020 @c Either this is a bug, or the manual should document what formats are
12021 @c supported.
12022
12023 @example
12024 printf (@var{string}, @var{expressions}@dots{});
12025 @end example
12026
12027 For example, you can print two values in hex like this:
12028
12029 @smallexample
12030 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
12031 @end smallexample
12032
12033 The only backslash-escape sequences that you can use in the format
12034 string are the simple ones that consist of backslash followed by a
12035 letter.
12036 @end table
12037
12038 @node Emacs
12039 @chapter Using @value{GDBN} under @sc{gnu} Emacs
12040
12041 @cindex Emacs
12042 @cindex @sc{gnu} Emacs
12043 A special interface allows you to use @sc{gnu} Emacs to view (and
12044 edit) the source files for the program you are debugging with
12045 @value{GDBN}.
12046
12047 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
12048 executable file you want to debug as an argument. This command starts
12049 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
12050 created Emacs buffer.
12051 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
12052
12053 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
12054 things:
12055
12056 @itemize @bullet
12057 @item
12058 All ``terminal'' input and output goes through the Emacs buffer.
12059 @end itemize
12060
12061 This applies both to @value{GDBN} commands and their output, and to the input
12062 and output done by the program you are debugging.
12063
12064 This is useful because it means that you can copy the text of previous
12065 commands and input them again; you can even use parts of the output
12066 in this way.
12067
12068 All the facilities of Emacs' Shell mode are available for interacting
12069 with your program. In particular, you can send signals the usual
12070 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
12071 stop.
12072
12073 @itemize @bullet
12074 @item
12075 @value{GDBN} displays source code through Emacs.
12076 @end itemize
12077
12078 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
12079 source file for that frame and puts an arrow (@samp{=>}) at the
12080 left margin of the current line. Emacs uses a separate buffer for
12081 source display, and splits the screen to show both your @value{GDBN} session
12082 and the source.
12083
12084 Explicit @value{GDBN} @code{list} or search commands still produce output as
12085 usual, but you probably have no reason to use them from Emacs.
12086
12087 @quotation
12088 @emph{Warning:} If the directory where your program resides is not your
12089 current directory, it can be easy to confuse Emacs about the location of
12090 the source files, in which case the auxiliary display buffer does not
12091 appear to show your source. @value{GDBN} can find programs by searching your
12092 environment's @code{PATH} variable, so the @value{GDBN} input and output
12093 session proceeds normally; but Emacs does not get enough information
12094 back from @value{GDBN} to locate the source files in this situation. To
12095 avoid this problem, either start @value{GDBN} mode from the directory where
12096 your program resides, or specify an absolute file name when prompted for the
12097 @kbd{M-x gdb} argument.
12098
12099 A similar confusion can result if you use the @value{GDBN} @code{file} command to
12100 switch to debugging a program in some other location, from an existing
12101 @value{GDBN} buffer in Emacs.
12102 @end quotation
12103
12104 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If
12105 you need to call @value{GDBN} by a different name (for example, if you keep
12106 several configurations around, with different names) you can set the
12107 Emacs variable @code{gdb-command-name}; for example,
12108
12109 @example
12110 (setq gdb-command-name "mygdb")
12111 @end example
12112
12113 @noindent
12114 (preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or
12115 in your @file{.emacs} file) makes Emacs call the program named
12116 ``@code{mygdb}'' instead.
12117
12118 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
12119 addition to the standard Shell mode commands:
12120
12121 @table @kbd
12122 @item C-h m
12123 Describe the features of Emacs' @value{GDBN} Mode.
12124
12125 @item M-s
12126 Execute to another source line, like the @value{GDBN} @code{step} command; also
12127 update the display window to show the current file and location.
12128
12129 @item M-n
12130 Execute to next source line in this function, skipping all function
12131 calls, like the @value{GDBN} @code{next} command. Then update the display window
12132 to show the current file and location.
12133
12134 @item M-i
12135 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
12136 display window accordingly.
12137
12138 @item M-x gdb-nexti
12139 Execute to next instruction, using the @value{GDBN} @code{nexti} command; update
12140 display window accordingly.
12141
12142 @item C-c C-f
12143 Execute until exit from the selected stack frame, like the @value{GDBN}
12144 @code{finish} command.
12145
12146 @item M-c
12147 Continue execution of your program, like the @value{GDBN} @code{continue}
12148 command.
12149
12150 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-p}.
12151
12152 @item M-u
12153 Go up the number of frames indicated by the numeric argument
12154 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
12155 like the @value{GDBN} @code{up} command.
12156
12157 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-u}.
12158
12159 @item M-d
12160 Go down the number of frames indicated by the numeric argument, like the
12161 @value{GDBN} @code{down} command.
12162
12163 @emph{Warning:} In Emacs v19, this command is @kbd{C-c C-d}.
12164
12165 @item C-x &
12166 Read the number where the cursor is positioned, and insert it at the end
12167 of the @value{GDBN} I/O buffer. For example, if you wish to disassemble code
12168 around an address that was displayed earlier, type @kbd{disassemble};
12169 then move the cursor to the address display, and pick up the
12170 argument for @code{disassemble} by typing @kbd{C-x &}.
12171
12172 You can customize this further by defining elements of the list
12173 @code{gdb-print-command}; once it is defined, you can format or
12174 otherwise process numbers picked up by @kbd{C-x &} before they are
12175 inserted. A numeric argument to @kbd{C-x &} indicates that you
12176 wish special formatting, and also acts as an index to pick an element of the
12177 list. If the list element is a string, the number to be inserted is
12178 formatted using the Emacs function @code{format}; otherwise the number
12179 is passed as an argument to the corresponding list element.
12180 @end table
12181
12182 In any source file, the Emacs command @kbd{C-x SPC} (@code{gdb-break})
12183 tells @value{GDBN} to set a breakpoint on the source line point is on.
12184
12185 If you accidentally delete the source-display buffer, an easy way to get
12186 it back is to type the command @code{f} in the @value{GDBN} buffer, to
12187 request a frame display; when you run under Emacs, this recreates
12188 the source buffer if necessary to show you the context of the current
12189 frame.
12190
12191 The source files displayed in Emacs are in ordinary Emacs buffers
12192 which are visiting the source files in the usual way. You can edit
12193 the files with these buffers if you wish; but keep in mind that @value{GDBN}
12194 communicates with Emacs in terms of line numbers. If you add or
12195 delete lines from the text, the line numbers that @value{GDBN} knows cease
12196 to correspond properly with the code.
12197
12198 @c The following dropped because Epoch is nonstandard. Reactivate
12199 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
12200 @ignore
12201 @kindex Emacs Epoch environment
12202 @kindex Epoch
12203 @kindex inspect
12204
12205 Version 18 of @sc{gnu} Emacs has a built-in window system
12206 called the @code{epoch}
12207 environment. Users of this environment can use a new command,
12208 @code{inspect} which performs identically to @code{print} except that
12209 each value is printed in its own window.
12210 @end ignore
12211
12212 @node Annotations
12213 @chapter @value{GDBN} Annotations
12214 @include annotate.texi
12215
12216 @node GDB Bugs
12217 @chapter Reporting Bugs in @value{GDBN}
12218 @cindex bugs in @value{GDBN}
12219 @cindex reporting bugs in @value{GDBN}
12220
12221 Your bug reports play an essential role in making @value{GDBN} reliable.
12222
12223 Reporting a bug may help you by bringing a solution to your problem, or it
12224 may not. But in any case the principal function of a bug report is to help
12225 the entire community by making the next version of @value{GDBN} work better. Bug
12226 reports are your contribution to the maintenance of @value{GDBN}.
12227
12228 In order for a bug report to serve its purpose, you must include the
12229 information that enables us to fix the bug.
12230
12231 @menu
12232 * Bug Criteria:: Have you found a bug?
12233 * Bug Reporting:: How to report bugs
12234 @end menu
12235
12236 @node Bug Criteria
12237 @section Have you found a bug?
12238 @cindex bug criteria
12239
12240 If you are not sure whether you have found a bug, here are some guidelines:
12241
12242 @itemize @bullet
12243 @cindex fatal signal
12244 @cindex debugger crash
12245 @cindex crash of debugger
12246 @item
12247 If the debugger gets a fatal signal, for any input whatever, that is a
12248 @value{GDBN} bug. Reliable debuggers never crash.
12249
12250 @cindex error on valid input
12251 @item
12252 If @value{GDBN} produces an error message for valid input, that is a
12253 bug. (Note that if you're cross debugging, the problem may also be
12254 somewhere in the connection to the target.)
12255
12256 @cindex invalid input
12257 @item
12258 If @value{GDBN} does not produce an error message for invalid input,
12259 that is a bug. However, you should note that your idea of
12260 ``invalid input'' might be our idea of ``an extension'' or ``support
12261 for traditional practice''.
12262
12263 @item
12264 If you are an experienced user of debugging tools, your suggestions
12265 for improvement of @value{GDBN} are welcome in any case.
12266 @end itemize
12267
12268 @node Bug Reporting
12269 @section How to report bugs
12270 @cindex bug reports
12271 @cindex @value{GDBN} bugs, reporting
12272
12273 A number of companies and individuals offer support for @sc{gnu} products.
12274 If you obtained @value{GDBN} from a support organization, we recommend you
12275 contact that organization first.
12276
12277 You can find contact information for many support companies and
12278 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
12279 distribution.
12280 @c should add a web page ref...
12281
12282 In any event, we also recommend that you send bug reports for
12283 @value{GDBN} to this addresses:
12284
12285 @example
12286 bug-gdb@@gnu.org
12287 @end example
12288
12289 @strong{Do not send bug reports to @samp{info-gdb}, or to
12290 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
12291 not want to receive bug reports. Those that do have arranged to receive
12292 @samp{bug-gdb}.
12293
12294 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
12295 serves as a repeater. The mailing list and the newsgroup carry exactly
12296 the same messages. Often people think of posting bug reports to the
12297 newsgroup instead of mailing them. This appears to work, but it has one
12298 problem which can be crucial: a newsgroup posting often lacks a mail
12299 path back to the sender. Thus, if we need to ask for more information,
12300 we may be unable to reach you. For this reason, it is better to send
12301 bug reports to the mailing list.
12302
12303 As a last resort, send bug reports on paper to:
12304
12305 @example
12306 @sc{gnu} Debugger Bugs
12307 Free Software Foundation Inc.
12308 59 Temple Place - Suite 330
12309 Boston, MA 02111-1307
12310 USA
12311 @end example
12312
12313 The fundamental principle of reporting bugs usefully is this:
12314 @strong{report all the facts}. If you are not sure whether to state a
12315 fact or leave it out, state it!
12316
12317 Often people omit facts because they think they know what causes the
12318 problem and assume that some details do not matter. Thus, you might
12319 assume that the name of the variable you use in an example does not matter.
12320 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
12321 stray memory reference which happens to fetch from the location where that
12322 name is stored in memory; perhaps, if the name were different, the contents
12323 of that location would fool the debugger into doing the right thing despite
12324 the bug. Play it safe and give a specific, complete example. That is the
12325 easiest thing for you to do, and the most helpful.
12326
12327 Keep in mind that the purpose of a bug report is to enable us to fix the
12328 bug. It may be that the bug has been reported previously, but neither
12329 you nor we can know that unless your bug report is complete and
12330 self-contained.
12331
12332 Sometimes people give a few sketchy facts and ask, ``Does this ring a
12333 bell?'' Those bug reports are useless, and we urge everyone to
12334 @emph{refuse to respond to them} except to chide the sender to report
12335 bugs properly.
12336
12337 To enable us to fix the bug, you should include all these things:
12338
12339 @itemize @bullet
12340 @item
12341 The version of @value{GDBN}. @value{GDBN} announces it if you start
12342 with no arguments; you can also print it at any time using @code{show
12343 version}.
12344
12345 Without this, we will not know whether there is any point in looking for
12346 the bug in the current version of @value{GDBN}.
12347
12348 @item
12349 The type of machine you are using, and the operating system name and
12350 version number.
12351
12352 @item
12353 What compiler (and its version) was used to compile @value{GDBN}---e.g.
12354 ``@value{GCC}--2.8.1''.
12355
12356 @item
12357 What compiler (and its version) was used to compile the program you are
12358 debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
12359 C Compiler''. For GCC, you can say @code{gcc --version} to get this
12360 information; for other compilers, see the documentation for those
12361 compilers.
12362
12363 @item
12364 The command arguments you gave the compiler to compile your example and
12365 observe the bug. For example, did you use @samp{-O}? To guarantee
12366 you will not omit something important, list them all. A copy of the
12367 Makefile (or the output from make) is sufficient.
12368
12369 If we were to try to guess the arguments, we would probably guess wrong
12370 and then we might not encounter the bug.
12371
12372 @item
12373 A complete input script, and all necessary source files, that will
12374 reproduce the bug.
12375
12376 @item
12377 A description of what behavior you observe that you believe is
12378 incorrect. For example, ``It gets a fatal signal.''
12379
12380 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
12381 will certainly notice it. But if the bug is incorrect output, we might
12382 not notice unless it is glaringly wrong. You might as well not give us
12383 a chance to make a mistake.
12384
12385 Even if the problem you experience is a fatal signal, you should still
12386 say so explicitly. Suppose something strange is going on, such as, your
12387 copy of @value{GDBN} is out of synch, or you have encountered a bug in
12388 the C library on your system. (This has happened!) Your copy might
12389 crash and ours would not. If you told us to expect a crash, then when
12390 ours fails to crash, we would know that the bug was not happening for
12391 us. If you had not told us to expect a crash, then we would not be able
12392 to draw any conclusion from our observations.
12393
12394 @item
12395 If you wish to suggest changes to the @value{GDBN} source, send us context
12396 diffs. If you even discuss something in the @value{GDBN} source, refer to
12397 it by context, not by line number.
12398
12399 The line numbers in our development sources will not match those in your
12400 sources. Your line numbers would convey no useful information to us.
12401
12402 @end itemize
12403
12404 Here are some things that are not necessary:
12405
12406 @itemize @bullet
12407 @item
12408 A description of the envelope of the bug.
12409
12410 Often people who encounter a bug spend a lot of time investigating
12411 which changes to the input file will make the bug go away and which
12412 changes will not affect it.
12413
12414 This is often time consuming and not very useful, because the way we
12415 will find the bug is by running a single example under the debugger
12416 with breakpoints, not by pure deduction from a series of examples.
12417 We recommend that you save your time for something else.
12418
12419 Of course, if you can find a simpler example to report @emph{instead}
12420 of the original one, that is a convenience for us. Errors in the
12421 output will be easier to spot, running under the debugger will take
12422 less time, and so on.
12423
12424 However, simplification is not vital; if you do not want to do this,
12425 report the bug anyway and send us the entire test case you used.
12426
12427 @item
12428 A patch for the bug.
12429
12430 A patch for the bug does help us if it is a good one. But do not omit
12431 the necessary information, such as the test case, on the assumption that
12432 a patch is all we need. We might see problems with your patch and decide
12433 to fix the problem another way, or we might not understand it at all.
12434
12435 Sometimes with a program as complicated as @value{GDBN} it is very hard to
12436 construct an example that will make the program follow a certain path
12437 through the code. If you do not send us the example, we will not be able
12438 to construct one, so we will not be able to verify that the bug is fixed.
12439
12440 And if we cannot understand what bug you are trying to fix, or why your
12441 patch should be an improvement, we will not install it. A test case will
12442 help us to understand.
12443
12444 @item
12445 A guess about what the bug is or what it depends on.
12446
12447 Such guesses are usually wrong. Even we cannot guess right about such
12448 things without first using the debugger to find the facts.
12449 @end itemize
12450
12451 @c The readline documentation is distributed with the readline code
12452 @c and consists of the two following files:
12453 @c rluser.texinfo
12454 @c inc-hist.texinfo
12455 @c Use -I with makeinfo to point to the appropriate directory,
12456 @c environment var TEXINPUTS with TeX.
12457
12458 @node Command Line Editing
12459 @chapter Command Line Editing
12460 @include rluser.texinfo
12461
12462
12463 @node Using History Interactively
12464 @chapter Using History Interactively
12465 @include inc-hist.texinfo
12466
12467
12468 @node Formatting Documentation
12469 @appendix Formatting Documentation
12470
12471 @cindex @value{GDBN} reference card
12472 @cindex reference card
12473 The @value{GDBN} 4 release includes an already-formatted reference card, ready
12474 for printing with PostScript or Ghostscript, in the @file{gdb}
12475 subdirectory of the main source directory@footnote{In
12476 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
12477 release.}. If you can use PostScript or Ghostscript with your printer,
12478 you can print the reference card immediately with @file{refcard.ps}.
12479
12480 The release also includes the source for the reference card. You
12481 can format it, using @TeX{}, by typing:
12482
12483 @example
12484 make refcard.dvi
12485 @end example
12486
12487 The @value{GDBN} reference card is designed to print in @dfn{landscape}
12488 mode on US ``letter'' size paper;
12489 that is, on a sheet 11 inches wide by 8.5 inches
12490 high. You will need to specify this form of printing as an option to
12491 your @sc{dvi} output program.
12492
12493 @cindex documentation
12494
12495 All the documentation for @value{GDBN} comes as part of the machine-readable
12496 distribution. The documentation is written in Texinfo format, which is
12497 a documentation system that uses a single source file to produce both
12498 on-line information and a printed manual. You can use one of the Info
12499 formatting commands to create the on-line version of the documentation
12500 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
12501
12502 @value{GDBN} includes an already formatted copy of the on-line Info
12503 version of this manual in the @file{gdb} subdirectory. The main Info
12504 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
12505 subordinate files matching @samp{gdb.info*} in the same directory. If
12506 necessary, you can print out these files, or read them with any editor;
12507 but they are easier to read using the @code{info} subsystem in @sc{gnu}
12508 Emacs or the standalone @code{info} program, available as part of the
12509 @sc{gnu} Texinfo distribution.
12510
12511 If you want to format these Info files yourself, you need one of the
12512 Info formatting programs, such as @code{texinfo-format-buffer} or
12513 @code{makeinfo}.
12514
12515 If you have @code{makeinfo} installed, and are in the top level
12516 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
12517 version @value{GDBVN}), you can make the Info file by typing:
12518
12519 @example
12520 cd gdb
12521 make gdb.info
12522 @end example
12523
12524 If you want to typeset and print copies of this manual, you need @TeX{},
12525 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
12526 Texinfo definitions file.
12527
12528 @TeX{} is a typesetting program; it does not print files directly, but
12529 produces output files called @sc{dvi} files. To print a typeset
12530 document, you need a program to print @sc{dvi} files. If your system
12531 has @TeX{} installed, chances are it has such a program. The precise
12532 command to use depends on your system; @kbd{lpr -d} is common; another
12533 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
12534 require a file name without any extension or a @samp{.dvi} extension.
12535
12536 @TeX{} also requires a macro definitions file called
12537 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
12538 written in Texinfo format. On its own, @TeX{} cannot either read or
12539 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
12540 and is located in the @file{gdb-@var{version-number}/texinfo}
12541 directory.
12542
12543 If you have @TeX{} and a @sc{dvi} printer program installed, you can
12544 typeset and print this manual. First switch to the the @file{gdb}
12545 subdirectory of the main source directory (for example, to
12546 @file{gdb-@value{GDBVN}/gdb}) and type:
12547
12548 @example
12549 make gdb.dvi
12550 @end example
12551
12552 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
12553
12554 @node Installing GDB
12555 @appendix Installing @value{GDBN}
12556 @cindex configuring @value{GDBN}
12557 @cindex installation
12558
12559 @value{GDBN} comes with a @code{configure} script that automates the process
12560 of preparing @value{GDBN} for installation; you can then use @code{make} to
12561 build the @code{gdb} program.
12562 @iftex
12563 @c irrelevant in info file; it's as current as the code it lives with.
12564 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
12565 look at the @file{README} file in the sources; we may have improved the
12566 installation procedures since publishing this manual.}
12567 @end iftex
12568
12569 The @value{GDBN} distribution includes all the source code you need for
12570 @value{GDBN} in a single directory, whose name is usually composed by
12571 appending the version number to @samp{gdb}.
12572
12573 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
12574 @file{gdb-@value{GDBVN}} directory. That directory contains:
12575
12576 @table @code
12577 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
12578 script for configuring @value{GDBN} and all its supporting libraries
12579
12580 @item gdb-@value{GDBVN}/gdb
12581 the source specific to @value{GDBN} itself
12582
12583 @item gdb-@value{GDBVN}/bfd
12584 source for the Binary File Descriptor library
12585
12586 @item gdb-@value{GDBVN}/include
12587 @sc{gnu} include files
12588
12589 @item gdb-@value{GDBVN}/libiberty
12590 source for the @samp{-liberty} free software library
12591
12592 @item gdb-@value{GDBVN}/opcodes
12593 source for the library of opcode tables and disassemblers
12594
12595 @item gdb-@value{GDBVN}/readline
12596 source for the @sc{gnu} command-line interface
12597
12598 @item gdb-@value{GDBVN}/glob
12599 source for the @sc{gnu} filename pattern-matching subroutine
12600
12601 @item gdb-@value{GDBVN}/mmalloc
12602 source for the @sc{gnu} memory-mapped malloc package
12603 @end table
12604
12605 The simplest way to configure and build @value{GDBN} is to run @code{configure}
12606 from the @file{gdb-@var{version-number}} source directory, which in
12607 this example is the @file{gdb-@value{GDBVN}} directory.
12608
12609 First switch to the @file{gdb-@var{version-number}} source directory
12610 if you are not already in it; then run @code{configure}. Pass the
12611 identifier for the platform on which @value{GDBN} will run as an
12612 argument.
12613
12614 For example:
12615
12616 @example
12617 cd gdb-@value{GDBVN}
12618 ./configure @var{host}
12619 make
12620 @end example
12621
12622 @noindent
12623 where @var{host} is an identifier such as @samp{sun4} or
12624 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
12625 (You can often leave off @var{host}; @code{configure} tries to guess the
12626 correct value by examining your system.)
12627
12628 Running @samp{configure @var{host}} and then running @code{make} builds the
12629 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
12630 libraries, then @code{gdb} itself. The configured source files, and the
12631 binaries, are left in the corresponding source directories.
12632
12633 @need 750
12634 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
12635 system does not recognize this automatically when you run a different
12636 shell, you may need to run @code{sh} on it explicitly:
12637
12638 @example
12639 sh configure @var{host}
12640 @end example
12641
12642 If you run @code{configure} from a directory that contains source
12643 directories for multiple libraries or programs, such as the
12644 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
12645 creates configuration files for every directory level underneath (unless
12646 you tell it not to, with the @samp{--norecursion} option).
12647
12648 You can run the @code{configure} script from any of the
12649 subordinate directories in the @value{GDBN} distribution if you only want to
12650 configure that subdirectory, but be sure to specify a path to it.
12651
12652 For example, with version @value{GDBVN}, type the following to configure only
12653 the @code{bfd} subdirectory:
12654
12655 @example
12656 @group
12657 cd gdb-@value{GDBVN}/bfd
12658 ../configure @var{host}
12659 @end group
12660 @end example
12661
12662 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
12663 However, you should make sure that the shell on your path (named by
12664 the @samp{SHELL} environment variable) is publicly readable. Remember
12665 that @value{GDBN} uses the shell to start your program---some systems refuse to
12666 let @value{GDBN} debug child processes whose programs are not readable.
12667
12668 @menu
12669 * Separate Objdir:: Compiling @value{GDBN} in another directory
12670 * Config Names:: Specifying names for hosts and targets
12671 * Configure Options:: Summary of options for configure
12672 @end menu
12673
12674 @node Separate Objdir
12675 @section Compiling @value{GDBN} in another directory
12676
12677 If you want to run @value{GDBN} versions for several host or target machines,
12678 you need a different @code{gdb} compiled for each combination of
12679 host and target. @code{configure} is designed to make this easy by
12680 allowing you to generate each configuration in a separate subdirectory,
12681 rather than in the source directory. If your @code{make} program
12682 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
12683 @code{make} in each of these directories builds the @code{gdb}
12684 program specified there.
12685
12686 To build @code{gdb} in a separate directory, run @code{configure}
12687 with the @samp{--srcdir} option to specify where to find the source.
12688 (You also need to specify a path to find @code{configure}
12689 itself from your working directory. If the path to @code{configure}
12690 would be the same as the argument to @samp{--srcdir}, you can leave out
12691 the @samp{--srcdir} option; it is assumed.)
12692
12693 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
12694 separate directory for a Sun 4 like this:
12695
12696 @example
12697 @group
12698 cd gdb-@value{GDBVN}
12699 mkdir ../gdb-sun4
12700 cd ../gdb-sun4
12701 ../gdb-@value{GDBVN}/configure sun4
12702 make
12703 @end group
12704 @end example
12705
12706 When @code{configure} builds a configuration using a remote source
12707 directory, it creates a tree for the binaries with the same structure
12708 (and using the same names) as the tree under the source directory. In
12709 the example, you'd find the Sun 4 library @file{libiberty.a} in the
12710 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
12711 @file{gdb-sun4/gdb}.
12712
12713 One popular reason to build several @value{GDBN} configurations in separate
12714 directories is to configure @value{GDBN} for cross-compiling (where
12715 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
12716 programs that run on another machine---the @dfn{target}).
12717 You specify a cross-debugging target by
12718 giving the @samp{--target=@var{target}} option to @code{configure}.
12719
12720 When you run @code{make} to build a program or library, you must run
12721 it in a configured directory---whatever directory you were in when you
12722 called @code{configure} (or one of its subdirectories).
12723
12724 The @code{Makefile} that @code{configure} generates in each source
12725 directory also runs recursively. If you type @code{make} in a source
12726 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
12727 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
12728 will build all the required libraries, and then build GDB.
12729
12730 When you have multiple hosts or targets configured in separate
12731 directories, you can run @code{make} on them in parallel (for example,
12732 if they are NFS-mounted on each of the hosts); they will not interfere
12733 with each other.
12734
12735 @node Config Names
12736 @section Specifying names for hosts and targets
12737
12738 The specifications used for hosts and targets in the @code{configure}
12739 script are based on a three-part naming scheme, but some short predefined
12740 aliases are also supported. The full naming scheme encodes three pieces
12741 of information in the following pattern:
12742
12743 @example
12744 @var{architecture}-@var{vendor}-@var{os}
12745 @end example
12746
12747 For example, you can use the alias @code{sun4} as a @var{host} argument,
12748 or as the value for @var{target} in a @code{--target=@var{target}}
12749 option. The equivalent full name is @samp{sparc-sun-sunos4}.
12750
12751 The @code{configure} script accompanying @value{GDBN} does not provide
12752 any query facility to list all supported host and target names or
12753 aliases. @code{configure} calls the Bourne shell script
12754 @code{config.sub} to map abbreviations to full names; you can read the
12755 script, if you wish, or you can use it to test your guesses on
12756 abbreviations---for example:
12757
12758 @smallexample
12759 % sh config.sub i386-linux
12760 i386-pc-linux-gnu
12761 % sh config.sub alpha-linux
12762 alpha-unknown-linux-gnu
12763 % sh config.sub hp9k700
12764 hppa1.1-hp-hpux
12765 % sh config.sub sun4
12766 sparc-sun-sunos4.1.1
12767 % sh config.sub sun3
12768 m68k-sun-sunos4.1.1
12769 % sh config.sub i986v
12770 Invalid configuration `i986v': machine `i986v' not recognized
12771 @end smallexample
12772
12773 @noindent
12774 @code{config.sub} is also distributed in the @value{GDBN} source
12775 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
12776
12777 @node Configure Options
12778 @section @code{configure} options
12779
12780 Here is a summary of the @code{configure} options and arguments that
12781 are most often useful for building @value{GDBN}. @code{configure} also has
12782 several other options not listed here. @inforef{What Configure
12783 Does,,configure.info}, for a full explanation of @code{configure}.
12784
12785 @example
12786 configure @r{[}--help@r{]}
12787 @r{[}--prefix=@var{dir}@r{]}
12788 @r{[}--exec-prefix=@var{dir}@r{]}
12789 @r{[}--srcdir=@var{dirname}@r{]}
12790 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
12791 @r{[}--target=@var{target}@r{]}
12792 @var{host}
12793 @end example
12794
12795 @noindent
12796 You may introduce options with a single @samp{-} rather than
12797 @samp{--} if you prefer; but you may abbreviate option names if you use
12798 @samp{--}.
12799
12800 @table @code
12801 @item --help
12802 Display a quick summary of how to invoke @code{configure}.
12803
12804 @item --prefix=@var{dir}
12805 Configure the source to install programs and files under directory
12806 @file{@var{dir}}.
12807
12808 @item --exec-prefix=@var{dir}
12809 Configure the source to install programs under directory
12810 @file{@var{dir}}.
12811
12812 @c avoid splitting the warning from the explanation:
12813 @need 2000
12814 @item --srcdir=@var{dirname}
12815 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
12816 @code{make} that implements the @code{VPATH} feature.}@*
12817 Use this option to make configurations in directories separate from the
12818 @value{GDBN} source directories. Among other things, you can use this to
12819 build (or maintain) several configurations simultaneously, in separate
12820 directories. @code{configure} writes configuration specific files in
12821 the current directory, but arranges for them to use the source in the
12822 directory @var{dirname}. @code{configure} creates directories under
12823 the working directory in parallel to the source directories below
12824 @var{dirname}.
12825
12826 @item --norecursion
12827 Configure only the directory level where @code{configure} is executed; do not
12828 propagate configuration to subdirectories.
12829
12830 @item --target=@var{target}
12831 Configure @value{GDBN} for cross-debugging programs running on the specified
12832 @var{target}. Without this option, @value{GDBN} is configured to debug
12833 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
12834
12835 There is no convenient way to generate a list of all available targets.
12836
12837 @item @var{host} @dots{}
12838 Configure @value{GDBN} to run on the specified @var{host}.
12839
12840 There is no convenient way to generate a list of all available hosts.
12841 @end table
12842
12843 There are many other options available as well, but they are generally
12844 needed for special purposes only.
12845
12846 @node Index
12847 @unnumbered Index
12848
12849 @printindex cp
12850
12851 @tex
12852 % I think something like @colophon should be in texinfo. In the
12853 % meantime:
12854 \long\def\colophon{\hbox to0pt{}\vfill
12855 \centerline{The body of this manual is set in}
12856 \centerline{\fontname\tenrm,}
12857 \centerline{with headings in {\bf\fontname\tenbf}}
12858 \centerline{and examples in {\tt\fontname\tentt}.}
12859 \centerline{{\it\fontname\tenit\/},}
12860 \centerline{{\bf\fontname\tenbf}, and}
12861 \centerline{{\sl\fontname\tensl\/}}
12862 \centerline{are used for emphasis.}\vfill}
12863 \page\colophon
12864 % Blame: doc@cygnus.com, 1991.
12865 @end tex
12866
12867 @contents
12868 @bye
This page took 0.405994 seconds and 3 git commands to generate.