Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / doc / gdb.info-1
blobb96721d1a53ca4f75780054aad68523a8c473cad
1 This is gdb.info, produced by makeinfo version 4.8 from
2 ../.././gdb/doc/gdb.texinfo.
4 INFO-DIR-SECTION Software development
5 START-INFO-DIR-ENTRY
6 * Gdb: (gdb).                     The GNU debugger.
7 END-INFO-DIR-ENTRY
9    This file documents the GNU debugger GDB.
11    This is the Ninth Edition, of `Debugging with GDB: the GNU
12 Source-Level Debugger' for GDB Version 6.5.
14    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
15 1998,
16 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
17 Free Software Foundation, Inc.
19    Permission is granted to copy, distribute and/or modify this document
20 under the terms of the GNU Free Documentation License, Version 1.1 or
21 any later version published by the Free Software Foundation; with the
22 Invariant Sections being "Free Software" and "Free Software Needs Free
23 Documentation", with the Front-Cover Texts being "A GNU Manual," and
24 with the Back-Cover Texts as in (a) below.
26    (a) The Free Software Foundation's Back-Cover Text is: "You have
27 freedom to copy and modify this GNU Manual, like GNU software.  Copies
28 published by the Free Software Foundation raise funds for GNU
29 development."
31 \x1f
32 File: gdb.info,  Node: Top,  Next: Summary,  Prev: (dir),  Up: (dir)
34 Debugging with GDB
35 ******************
37 This file describes GDB, the GNU symbolic debugger.
39    This is the Ninth Edition, for GDB Version 6.5.
41    Copyright (C) 1988-2006 Free Software Foundation, Inc.
43 * Menu:
45 * Summary::                     Summary of GDB
46 * Sample Session::              A sample GDB session
48 * Invocation::                  Getting in and out of GDB
49 * Commands::                    GDB commands
50 * Running::                     Running programs under GDB
51 * Stopping::                    Stopping and continuing
52 * Stack::                       Examining the stack
53 * Source::                      Examining source files
54 * Data::                        Examining data
55 * Macros::                      Preprocessor Macros
56 * Tracepoints::                 Debugging remote targets non-intrusively
57 * Overlays::                    Debugging programs that use overlays
59 * Languages::                   Using GDB with different languages
61 * Symbols::                     Examining the symbol table
62 * Altering::                    Altering execution
63 * GDB Files::                   GDB files
64 * Targets::                     Specifying a debugging target
65 * Remote Debugging::            Debugging remote programs
66 * Configurations::              Configuration-specific information
67 * Controlling GDB::             Controlling GDB
68 * Sequences::                   Canned sequences of commands
69 * TUI::                         GDB Text User Interface
70 * Interpreters::                Command Interpreters
71 * Emacs::                       Using GDB under GNU Emacs
72 * Annotations::                 GDB's annotation interface.
73 * GDB/MI::                      GDB's Machine Interface.
75 * GDB Bugs::                    Reporting bugs in GDB
76 * Formatting Documentation::    How to format and print GDB documentation
78 * Command Line Editing::        Command Line Editing
79 * Using History Interactively:: Using History Interactively
80 * Installing GDB::              Installing GDB
81 * Maintenance Commands::        Maintenance Commands
82 * Remote Protocol::             GDB Remote Serial Protocol
83 * Agent Expressions::           The GDB Agent Expression Mechanism
84 * Copying::                     GNU General Public License says
85                                 how you can copy and share GDB
86 * GNU Free Documentation License::  The license for this documentation
87 * Index::                       Index
89 \x1f
90 File: gdb.info,  Node: Summary,  Next: Sample Session,  Prev: Top,  Up: Top
92 Summary of GDB
93 **************
95 The purpose of a debugger such as GDB is to allow you to see what is
96 going on "inside" another program while it executes--or what another
97 program was doing at the moment it crashed.
99    GDB can do four main kinds of things (plus other things in support of
100 these) to help you catch bugs in the act:
102    * Start your program, specifying anything that might affect its
103      behavior.
105    * Make your program stop on specified conditions.
107    * Examine what has happened, when your program has stopped.
109    * Change things in your program, so you can experiment with
110      correcting the effects of one bug and go on to learn about another.
112    You can use GDB to debug programs written in C and C++.  For more
113 information, see *Note Supported languages: Supported languages.  For
114 more information, see *Note C and C++: C.
116    Support for Modula-2 is partial.  For information on Modula-2, see
117 *Note Modula-2: Modula-2.
119    Debugging Pascal programs which use sets, subranges, file variables,
120 or nested functions does not currently work.  GDB does not support
121 entering expressions, printing values, or similar features using Pascal
122 syntax.
124    GDB can be used to debug programs written in Fortran, although it
125 may be necessary to refer to some variables with a trailing underscore.
127    GDB can be used to debug programs written in Objective-C, using
128 either the Apple/NeXT or the GNU Objective-C runtime.
130 * Menu:
132 * Free Software::               Freely redistributable software
133 * Contributors::                Contributors to GDB
135 \x1f
136 File: gdb.info,  Node: Free Software,  Next: Contributors,  Up: Summary
138 Free software
139 =============
141 GDB is "free software", protected by the GNU General Public License
142 (GPL).  The GPL gives you the freedom to copy or adapt a licensed
143 program--but every person getting a copy also gets with it the freedom
144 to modify that copy (which means that they must get access to the
145 source code), and the freedom to distribute further copies.  Typical
146 software companies use copyrights to limit your freedoms; the Free
147 Software Foundation uses the GPL to preserve these freedoms.
149    Fundamentally, the General Public License is a license which says
150 that you have these freedoms and that you cannot take these freedoms
151 away from anyone else.
153 Free Software Needs Free Documentation
154 ======================================
156 The biggest deficiency in the free software community today is not in
157 the software--it is the lack of good free documentation that we can
158 include with the free software.  Many of our most important programs do
159 not come with free reference manuals and free introductory texts.
160 Documentation is an essential part of any software package; when an
161 important free software package does not come with a free manual and a
162 free tutorial, that is a major gap.  We have many such gaps today.
164    Consider Perl, for instance.  The tutorial manuals that people
165 normally use are non-free.  How did this come about?  Because the
166 authors of those manuals published them with restrictive terms--no
167 copying, no modification, source files not available--which exclude
168 them from the free software world.
170    That wasn't the first time this sort of thing happened, and it was
171 far from the last.  Many times we have heard a GNU user eagerly
172 describe a manual that he is writing, his intended contribution to the
173 community, only to learn that he had ruined everything by signing a
174 publication contract to make it non-free.
176    Free documentation, like free software, is a matter of freedom, not
177 price.  The problem with the non-free manual is not that publishers
178 charge a price for printed copies--that in itself is fine.  (The Free
179 Software Foundation sells printed copies of manuals, too.)  The problem
180 is the restrictions on the use of the manual.  Free manuals are
181 available in source code form, and give you permission to copy and
182 modify.  Non-free manuals do not allow this.
184    The criteria of freedom for a free manual are roughly the same as for
185 free software.  Redistribution (including the normal kinds of
186 commercial redistribution) must be permitted, so that the manual can
187 accompany every copy of the program, both on-line and on paper.
189    Permission for modification of the technical content is crucial too.
190 When people modify the software, adding or changing features, if they
191 are conscientious they will change the manual too--so they can provide
192 accurate and clear documentation for the modified program.  A manual
193 that leaves you no choice but to write a new manual to document a
194 changed version of the program is not really available to our community.
196    Some kinds of limits on the way modification is handled are
197 acceptable.  For example, requirements to preserve the original
198 author's copyright notice, the distribution terms, or the list of
199 authors, are ok.  It is also no problem to require modified versions to
200 include notice that they were modified.  Even entire sections that may
201 not be deleted or changed are acceptable, as long as they deal with
202 nontechnical topics (like this one).  These kinds of restrictions are
203 acceptable because they don't obstruct the community's normal use of
204 the manual.
206    However, it must be possible to modify all the _technical_ content
207 of the manual, and then distribute the result in all the usual media,
208 through all the usual channels.  Otherwise, the restrictions obstruct
209 the use of the manual, it is not free, and we need another manual to
210 replace it.
212    Please spread the word about this issue.  Our community continues to
213 lose manuals to proprietary publishing.  If we spread the word that
214 free software needs free reference manuals and free tutorials, perhaps
215 the next person who wants to contribute by writing documentation will
216 realize, before it is too late, that only free manuals contribute to
217 the free software community.
219    If you are writing documentation, please insist on publishing it
220 under the GNU Free Documentation License or another free documentation
221 license.  Remember that this decision requires your approval--you don't
222 have to let the publisher decide.  Some commercial publishers will use
223 a free license if you insist, but they will not propose the option; it
224 is up to you to raise the issue and say firmly that this is what you
225 want.  If the publisher you are dealing with refuses, please try other
226 publishers.  If you're not sure whether a proposed license is free,
227 write to <licensing@gnu.org>.
229    You can encourage commercial publishers to sell more free, copylefted
230 manuals and tutorials by buying them, and particularly by buying copies
231 from the publishers that paid for their writing or for major
232 improvements.  Meanwhile, try to avoid buying non-free documentation at
233 all.  Check the distribution terms of a manual before you buy it, and
234 insist that whoever seeks your business must respect your freedom.
235 Check the history of the book, and try to reward the publishers that
236 have paid or pay the authors to work on it.
238    The Free Software Foundation maintains a list of free documentation
239 published by other publishers, at
240 `http://www.fsf.org/doc/other-free-books.html'.
242 \x1f
243 File: gdb.info,  Node: Contributors,  Prev: Free Software,  Up: Summary
245 Contributors to GDB
246 ===================
248 Richard Stallman was the original author of GDB, and of many other GNU
249 programs.  Many others have contributed to its development.  This
250 section attempts to credit major contributors.  One of the virtues of
251 free software is that everyone is free to contribute to it; with
252 regret, we cannot actually acknowledge everyone here.  The file
253 `ChangeLog' in the GDB distribution approximates a blow-by-blow account.
255    Changes much prior to version 2.0 are lost in the mists of time.
257      _Plea:_ Additions to this section are particularly welcome.  If you
258      or your friends (or enemies, to be evenhanded) have been unfairly
259      omitted from this list, we would like to add your names!
261    So that they may not regard their many labors as thankless, we
262 particularly thank those who shepherded GDB through major releases:
263 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim
264 Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs
265 (release 4.14); Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10,
266 and 4.9); Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5,
267 and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim
268 Kingdon (releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2,
269 3.1, and 3.0).
271    Richard Stallman, assisted at various times by Peter TerMaat, Chris
272 Hanson, and Richard Mlynarik, handled releases through 2.8.
274    Michael Tiemann is the author of most of the GNU C++ support in GDB,
275 with significant additional contributions from Per Bothner and Daniel
276 Berlin.  James Clark wrote the GNU C++ demangler.  Early work on C++
277 was by Peter TerMaat (who also did much general update work leading to
278 release 3.0).
280    GDB uses the BFD subroutine library to examine multiple object-file
281 formats; BFD was a joint project of David V.  Henkel-Wallace, Rich
282 Pixley, Steve Chamberlain, and John Gilmore.
284    David Johnson wrote the original COFF support; Pace Willison did the
285 original support for encapsulated COFF.
287    Brent Benson of Harris Computer Systems contributed DWARF 2 support.
289    Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
290 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
291 support.  Jean-Daniel Fekete contributed Sun 386i support.  Chris
292 Hanson improved the HP9000 support.  Noboyuki Hikichi and Tomoyuki
293 Hasei contributed Sony/News OS 3 support.  David Johnson contributed
294 Encore Umax support.  Jyrki Kuoppala contributed Altos 3068 support.
295 Jeff Law contributed HP PA and SOM support.  Keith Packard contributed
296 NS32K support.  Doug Rabson contributed Acorn Risc Machine support.
297 Bob Rusk contributed Harris Nighthawk CX-UX support.  Chris Smith
298 contributed Convex support (and Fortran debugging).  Jonathan Stone
299 contributed Pyramid support.  Michael Tiemann contributed SPARC support.
300 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
301 Pace Willison contributed Intel 386 support.  Jay Vosburgh contributed
302 Symmetry support.  Marko Mlinar contributed OpenRISC 1000 support.
304    Andreas Schwab contributed M68K GNU/Linux support.
306    Rich Schaefer and Peter Schauer helped with support of SunOS shared
307 libraries.
309    Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
310 several machine instruction sets.
312    Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
313 develop remote debugging.  Intel Corporation, Wind River Systems, AMD,
314 and ARM contributed remote debugging modules for the i960, VxWorks,
315 A29K UDI, and RDI targets, respectively.
317    Brian Fox is the author of the readline libraries providing
318 command-line editing and command history.
320    Andrew Beers of SUNY Buffalo wrote the language-switching code, the
321 Modula-2 support, and contributed the Languages chapter of this manual.
323    Fred Fish wrote most of the support for Unix System Vr4.  He also
324 enhanced the command-completion support to cover C++ overloaded symbols.
326    Hitachi America (now Renesas America), Ltd. sponsored the support for
327 H8/300, H8/500, and Super-H processors.
329    NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx
330 processors.
332    Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and
333 M32R/D processors.
335    Toshiba sponsored the support for the TX39 Mips processor.
337    Matsushita sponsored the support for the MN10200 and MN10300
338 processors.
340    Fujitsu sponsored the support for SPARClite and FR30 processors.
342    Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
343 watchpoints.
345    Michael Snyder added support for tracepoints.
347    Stu Grossman wrote gdbserver.
349    Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly
350 innumerable bug fixes and cleanups throughout GDB.
352    The following people at the Hewlett-Packard Company contributed
353 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
354 (narrow mode), HP's implementation of kernel threads, HP's aC++
355 compiler, and the Text User Interface (nee Terminal User Interface):
356 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
357 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni.  Kim Haase
358 provided HP-specific information in this manual.
360    DJ Delorie ported GDB to MS-DOS, for the DJGPP project.  Robert
361 Hoehne made significant contributions to the DJGPP port.
363    Cygnus Solutions has sponsored GDB maintenance and much of its
364 development since 1991.  Cygnus engineers who have worked on GDB
365 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
366 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
367 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
368 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
369 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni.  In
370 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
371 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
372 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
373 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
374 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
375 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
376 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
377 Zuhn have made contributions both large and small.
379    Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
380 Cygnus Solutions, implemented the original GDB/MI interface.
382    Jim Blandy added support for preprocessor macros, while working for
383 Red Hat.
385    Andrew Cagney designed GDB's architecture vector.  Many people
386 including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick Duffek,
387 Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei Sakamoto,
388 Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason Thorpe, Corinna
389 Vinschen, Ulrich Weigand, and Elena Zannoni, helped with the migration
390 of old architectures to this new framework.
392    Andrew Cagney completely re-designed and re-implemented GDB's
393 unwinder framework, this consisting of a fresh new design featuring
394 frame IDs, independent frame sniffers, and the sentinel frame.  Mark
395 Kettenis implemented the DWARF 2 unwinder, Jeff Johnston the libunwind
396 unwinder, and Andrew Cagney the dummy, sentinel, tramp, and trad
397 unwinders.  The architecture specific changes, each involving a
398 complete rewrite of the architecture's frame code, were carried out by
399 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
400 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
401 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
402 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
403 Weigand.
405 \x1f
406 File: gdb.info,  Node: Sample Session,  Next: Invocation,  Prev: Summary,  Up: Top
408 1 A Sample GDB Session
409 **********************
411 You can use this manual at your leisure to read all about GDB.
412 However, a handful of commands are enough to get started using the
413 debugger.  This chapter illustrates those commands.
415    One of the preliminary versions of GNU `m4' (a generic macro
416 processor) exhibits the following bug: sometimes, when we change its
417 quote strings from the default, the commands used to capture one macro
418 definition within another stop working.  In the following short `m4'
419 session, we define a macro `foo' which expands to `0000'; we then use
420 the `m4' built-in `defn' to define `bar' as the same thing.  However,
421 when we change the open quote string to `<QUOTE>' and the close quote
422 string to `<UNQUOTE>', the same procedure fails to define a new synonym
423 `baz':
425      $ cd gnu/m4
426      $ ./m4
427      define(foo,0000)
429      foo
430      0000
431      define(bar,defn(`foo'))
433      bar
434      0000
435      changequote(<QUOTE>,<UNQUOTE>)
437      define(baz,defn(<QUOTE>foo<UNQUOTE>))
438      baz
439      C-d
440      m4: End of input: 0: fatal error: EOF in string
442 Let us use GDB to try to see what is going on.
444      $ gdb m4
445      GDB is free software and you are welcome to distribute copies
446       of it under certain conditions; type "show copying" to see
447       the conditions.
448      There is absolutely no warranty for GDB; type "show warranty"
449       for details.
451      GDB 6.5, Copyright 1999 Free Software Foundation, Inc...
452      (gdb)
454 GDB reads only enough symbol data to know where to find the rest when
455 needed; as a result, the first prompt comes up very quickly.  We now
456 tell GDB to use a narrower display width than usual, so that examples
457 fit in this manual.
459      (gdb) set width 70
461 We need to see how the `m4' built-in `changequote' works.  Having
462 looked at the source, we know the relevant subroutine is
463 `m4_changequote', so we set a breakpoint there with the GDB `break'
464 command.
466      (gdb) break m4_changequote
467      Breakpoint 1 at 0x62f4: file builtin.c, line 879.
469 Using the `run' command, we start `m4' running under GDB control; as
470 long as control does not reach the `m4_changequote' subroutine, the
471 program runs as usual:
473      (gdb) run
474      Starting program: /work/Editorial/gdb/gnu/m4/m4
475      define(foo,0000)
477      foo
478      0000
480 To trigger the breakpoint, we call `changequote'.  GDB suspends
481 execution of `m4', displaying information about the context where it
482 stops.
484      changequote(<QUOTE>,<UNQUOTE>)
486      Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
487          at builtin.c:879
488      879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
490 Now we use the command `n' (`next') to advance execution to the next
491 line of the current function.
493      (gdb) n
494      882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
495       : nil,
497 `set_quotes' looks like a promising subroutine.  We can go into it by
498 using the command `s' (`step') instead of `next'.  `step' goes to the
499 next line to be executed in _any_ subroutine, so it steps into
500 `set_quotes'.
502      (gdb) s
503      set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
504          at input.c:530
505      530         if (lquote != def_lquote)
507 The display that shows the subroutine where `m4' is now suspended (and
508 its arguments) is called a stack frame display.  It shows a summary of
509 the stack.  We can use the `backtrace' command (which can also be
510 spelled `bt'), to see where we are in the stack as a whole: the
511 `backtrace' command displays a stack frame for each active subroutine.
513      (gdb) bt
514      #0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
515          at input.c:530
516      #1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
517          at builtin.c:882
518      #2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
519      #3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
520          at macro.c:71
521      #4  0x79dc in expand_input () at macro.c:40
522      #5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
524 We step through a few more lines to see what happens.  The first two
525 times, we can use `s'; the next two times we use `n' to avoid falling
526 into the `xstrdup' subroutine.
528      (gdb) s
529      0x3b5c  532         if (rquote != def_rquote)
530      (gdb) s
531      0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
532      def_lquote : xstrdup(lq);
533      (gdb) n
534      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
535       : xstrdup(rq);
536      (gdb) n
537      538         len_lquote = strlen(rquote);
539 The last line displayed looks a little odd; we can examine the variables
540 `lquote' and `rquote' to see if they are in fact the new left and right
541 quotes we specified.  We use the command `p' (`print') to see their
542 values.
544      (gdb) p lquote
545      $1 = 0x35d40 "<QUOTE>"
546      (gdb) p rquote
547      $2 = 0x35d50 "<UNQUOTE>"
549 `lquote' and `rquote' are indeed the new left and right quotes.  To
550 look at some context, we can display ten lines of source surrounding
551 the current line with the `l' (`list') command.
553      (gdb) l
554      533             xfree(rquote);
555      534
556      535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
557       : xstrdup (lq);
558      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
559       : xstrdup (rq);
560      537
561      538         len_lquote = strlen(rquote);
562      539         len_rquote = strlen(lquote);
563      540     }
564      541
565      542     void
567 Let us step past the two lines that set `len_lquote' and `len_rquote',
568 and then examine the values of those variables.
570      (gdb) n
571      539         len_rquote = strlen(lquote);
572      (gdb) n
573      540     }
574      (gdb) p len_lquote
575      $3 = 9
576      (gdb) p len_rquote
577      $4 = 7
579 That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
580 meant to be the lengths of `lquote' and `rquote' respectively.  We can
581 set them to better values using the `p' command, since it can print the
582 value of any expression--and that expression can include subroutine
583 calls and assignments.
585      (gdb) p len_lquote=strlen(lquote)
586      $5 = 7
587      (gdb) p len_rquote=strlen(rquote)
588      $6 = 9
590 Is that enough to fix the problem of using the new quotes with the `m4'
591 built-in `defn'?  We can allow `m4' to continue executing with the `c'
592 (`continue') command, and then try the example that caused trouble
593 initially:
595      (gdb) c
596      Continuing.
598      define(baz,defn(<QUOTE>foo<UNQUOTE>))
600      baz
601      0000
603 Success!  The new quotes now work just as well as the default ones.  The
604 problem seems to have been just the two typos defining the wrong
605 lengths.  We allow `m4' exit by giving it an EOF as input:
607      C-d
608      Program exited normally.
610 The message `Program exited normally.' is from GDB; it indicates `m4'
611 has finished executing.  We can end our GDB session with the GDB `quit'
612 command.
614      (gdb) quit
616 \x1f
617 File: gdb.info,  Node: Invocation,  Next: Commands,  Prev: Sample Session,  Up: Top
619 2 Getting In and Out of GDB
620 ***************************
622 This chapter discusses how to start GDB, and how to get out of it.  The
623 essentials are:
624    * type `gdb' to start GDB.
626    * type `quit' or `C-d' to exit.
628 * Menu:
630 * Invoking GDB::                How to start GDB
631 * Quitting GDB::                How to quit GDB
632 * Shell Commands::              How to use shell commands inside GDB
633 * Logging output::              How to log GDB's output to a file
635 \x1f
636 File: gdb.info,  Node: Invoking GDB,  Next: Quitting GDB,  Up: Invocation
638 2.1 Invoking GDB
639 ================
641 Invoke GDB by running the program `gdb'.  Once started, GDB reads
642 commands from the terminal until you tell it to exit.
644    You can also run `gdb' with a variety of arguments and options, to
645 specify more of your debugging environment at the outset.
647    The command-line options described here are designed to cover a
648 variety of situations; in some environments, some of these options may
649 effectively be unavailable.
651    The most usual way to start GDB is with one argument, specifying an
652 executable program:
654      gdb PROGRAM
656 You can also start with both an executable program and a core file
657 specified:
659      gdb PROGRAM CORE
661    You can, instead, specify a process ID as a second argument, if you
662 want to debug a running process:
664      gdb PROGRAM 1234
666 would attach GDB to process `1234' (unless you also have a file named
667 `1234'; GDB does check for a core file first).
669    Taking advantage of the second command-line argument requires a
670 fairly complete operating system; when you use GDB as a remote debugger
671 attached to a bare board, there may not be any notion of "process", and
672 there is often no way to get a core dump.  GDB will warn you if it is
673 unable to attach or to read core dumps.
675    You can optionally have `gdb' pass any arguments after the
676 executable file to the inferior using `--args'.  This option stops
677 option processing.
678      gdb --args gcc -O2 -c foo.c
679    This will cause `gdb' to debug `gcc', and to set `gcc''s
680 command-line arguments (*note Arguments::) to `-O2 -c foo.c'.
682    You can run `gdb' without printing the front material, which
683 describes GDB's non-warranty, by specifying `-silent':
685      gdb -silent
687 You can further control how GDB starts up by using command-line
688 options.  GDB itself can remind you of the options available.
690 Type
692      gdb -help
694 to display all available options and briefly describe their use (`gdb
695 -h' is a shorter equivalent).
697    All options and command line arguments you give are processed in
698 sequential order.  The order makes a difference when the `-x' option is
699 used.
701 * Menu:
703 * File Options::                Choosing files
704 * Mode Options::                Choosing modes
705 * Startup::                     What GDB does during startup
707 \x1f
708 File: gdb.info,  Node: File Options,  Next: Mode Options,  Up: Invoking GDB
710 2.1.1 Choosing files
711 --------------------
713 When GDB starts, it reads any arguments other than options as
714 specifying an executable file and core file (or process ID).  This is
715 the same as if the arguments were specified by the `-se' and `-c' (or
716 `-p' options respectively.  (GDB reads the first argument that does not
717 have an associated option flag as equivalent to the `-se' option
718 followed by that argument; and the second argument that does not have
719 an associated option flag, if any, as equivalent to the `-c'/`-p'
720 option followed by that argument.)  If the second argument begins with
721 a decimal digit, GDB will first attempt to attach to it as a process,
722 and if that fails, attempt to open it as a corefile.  If you have a
723 corefile whose name begins with a digit, you can prevent GDB from
724 treating it as a pid by prefixing it with `./', e.g. `./12345'.
726    If GDB has not been configured to included core file support, such
727 as for most embedded targets, then it will complain about a second
728 argument and ignore it.
730    Many options have both long and short forms; both are shown in the
731 following list.  GDB also recognizes the long forms if you truncate
732 them, so long as enough of the option is present to be unambiguous.
733 (If you prefer, you can flag option arguments with `--' rather than
734 `-', though we illustrate the more usual convention.)
736 `-symbols FILE'
737 `-s FILE'
738      Read symbol table from file FILE.
740 `-exec FILE'
741 `-e FILE'
742      Use file FILE as the executable file to execute when appropriate,
743      and for examining pure data in conjunction with a core dump.
745 `-se FILE'
746      Read symbol table from file FILE and use it as the executable file.
748 `-core FILE'
749 `-c FILE'
750      Use file FILE as a core dump to examine.
752 `-c NUMBER'
754 `-pid NUMBER'
755 `-p NUMBER'
756      Connect to process ID NUMBER, as with the `attach' command.  If
757      there is no such process, GDB will attempt to open a core file
758      named NUMBER.
760 `-command FILE'
761 `-x FILE'
762      Execute GDB commands from file FILE.  *Note Command files: Command
763      Files.
765 `-eval-command COMMAND'
766 `-ex COMMAND'
767      Execute a single GDB command.
769      This option may be used multiple times to call multiple commands.
770      It may also be interleaved with `-command' as required.
772           gdb -ex 'target sim' -ex 'load' \
773              -x setbreakpoints -ex 'run' a.out
775 `-directory DIRECTORY'
776 `-d DIRECTORY'
777      Add DIRECTORY to the path to search for source and script files.
779 `-r'
780 `-readnow'
781      Read each symbol file's entire symbol table immediately, rather
782      than the default, which is to read it incrementally as it is
783      needed.  This makes startup slower, but makes future operations
784      faster.
787 \x1f
788 File: gdb.info,  Node: Mode Options,  Next: Startup,  Prev: File Options,  Up: Invoking GDB
790 2.1.2 Choosing modes
791 --------------------
793 You can run GDB in various alternative modes--for example, in batch
794 mode or quiet mode.
796 `-nx'
797 `-n'
798      Do not execute commands found in any initialization files.
799      Normally, GDB executes the commands in these files after all the
800      command options and arguments have been processed.  *Note Command
801      files: Command Files.
803 `-quiet'
804 `-silent'
805 `-q'
806      "Quiet".  Do not print the introductory and copyright messages.
807      These messages are also suppressed in batch mode.
809 `-batch'
810      Run in batch mode.  Exit with status `0' after processing all the
811      command files specified with `-x' (and all commands from
812      initialization files, if not inhibited with `-n').  Exit with
813      nonzero status if an error occurs in executing the GDB commands in
814      the command files.
816      Batch mode may be useful for running GDB as a filter, for example
817      to download and run a program on another computer; in order to
818      make this more useful, the message
820           Program exited normally.
822      (which is ordinarily issued whenever a program running under GDB
823      control terminates) is not issued when running in batch mode.
825 `-batch-silent'
826      Run in batch mode exactly like `-batch', but totally silently.  All
827      GDB output to `stdout' is prevented (`stderr' is unaffected).
828      This is much quieter than `-silent' and would be useless for an
829      interactive session.
831      This is particularly useful when using targets that give `Loading
832      section' messages, for example.
834      Note that targets that give their output via GDB, as opposed to
835      writing directly to `stdout', will also be made silent.
837 `-return-child-result'
838      The return code from GDB will be the return code from the child
839      process (the process being debugged), with the following
840      exceptions:
842         * GDB exits abnormally.  E.g., due to an incorrect argument or
843           an internal error.  In this case the exit code is the same as
844           it would have been without `-return-child-result'.
846         * The user quits with an explicit value.  E.g., `quit 1'.
848         * The child process never runs, or is not allowed to terminate,
849           in which case the exit code will be -1.
851      This option is useful in conjunction with `-batch' or
852      `-batch-silent', when GDB is being used as a remote program loader
853      or simulator interface.
855 `-nowindows'
856 `-nw'
857      "No windows".  If GDB comes with a graphical user interface (GUI)
858      built in, then this option tells GDB to only use the command-line
859      interface.  If no GUI is available, this option has no effect.
861 `-windows'
862 `-w'
863      If GDB includes a GUI, then this option requires it to be used if
864      possible.
866 `-cd DIRECTORY'
867      Run GDB using DIRECTORY as its working directory, instead of the
868      current directory.
870 `-fullname'
871 `-f'
872      GNU Emacs sets this option when it runs GDB as a subprocess.  It
873      tells GDB to output the full file name and line number in a
874      standard, recognizable fashion each time a stack frame is
875      displayed (which includes each time your program stops).  This
876      recognizable format looks like two `\032' characters, followed by
877      the file name, line number and character position separated by
878      colons, and a newline.  The Emacs-to-GDB interface program uses
879      the two `\032' characters as a signal to display the source code
880      for the frame.
882 `-epoch'
883      The Epoch Emacs-GDB interface sets this option when it runs GDB as
884      a subprocess.  It tells GDB to modify its print routines so as to
885      allow Epoch to display values of expressions in a separate window.
887 `-annotate LEVEL'
888      This option sets the "annotation level" inside GDB.  Its effect is
889      identical to using `set annotate LEVEL' (*note Annotations::).
890      The annotation LEVEL controls how much information GDB prints
891      together with its prompt, values of expressions, source lines, and
892      other types of output.  Level 0 is the normal, level 1 is for use
893      when GDB is run as a subprocess of GNU Emacs, level 3 is the
894      maximum annotation suitable for programs that control GDB, and
895      level 2 has been deprecated.
897      The annotation mechanism has largely been superseded by GDB/MI
898      (*note GDB/MI::).
900 `--args'
901      Change interpretation of command line so that arguments following
902      the executable file are passed as command line arguments to the
903      inferior.  This option stops option processing.
905 `-baud BPS'
906 `-b BPS'
907      Set the line speed (baud rate or bits per second) of any serial
908      interface used by GDB for remote debugging.
910 `-l TIMEOUT'
911      Set the timeout (in seconds) of any communication used by GDB for
912      remote debugging.
914 `-tty DEVICE'
915 `-t DEVICE'
916      Run using DEVICE for your program's standard input and output.
918 `-tui'
919      Activate the "Text User Interface" when starting.  The Text User
920      Interface manages several text windows on the terminal, showing
921      source, assembly, registers and GDB command outputs (*note GDB
922      Text User Interface: TUI.).  Alternatively, the Text User
923      Interface can be enabled by invoking the program `gdbtui'.  Do not
924      use this option if you run GDB from Emacs (*note Using GDB under
925      GNU Emacs: Emacs.).
927 `-interpreter INTERP'
928      Use the interpreter INTERP for interface with the controlling
929      program or device.  This option is meant to be set by programs
930      which communicate with GDB using it as a back end.  *Note Command
931      Interpreters: Interpreters.
933      `--interpreter=mi' (or `--interpreter=mi2') causes GDB to use the
934      "GDB/MI interface" (*note The GDB/MI Interface: GDB/MI.) included
935      since GDB version 6.0.  The previous GDB/MI interface, included in
936      GDB version 5.3 and selected with `--interpreter=mi1', is
937      deprecated.  Earlier GDB/MI interfaces are no longer supported.
939 `-write'
940      Open the executable and core files for both reading and writing.
941      This is equivalent to the `set write on' command inside GDB (*note
942      Patching::).
944 `-statistics'
945      This option causes GDB to print statistics about time and memory
946      usage after it completes each command and returns to the prompt.
948 `-version'
949      This option causes GDB to print its version number and no-warranty
950      blurb, and exit.
953 \x1f
954 File: gdb.info,  Node: Startup,  Prev: Mode Options,  Up: Invoking GDB
956 2.1.3 What GDB does during startup
957 ----------------------------------
959 Here's the description of what GDB does during session startup:
961   1. Sets up the command interpreter as specified by the command line
962      (*note interpreter: Mode Options.).
964   2. Reads the "init file" (if any) in your home directory(1) and
965      executes all the commands in that file.
967   3. Processes command line options and operands.
969   4. Reads and executes the commands from init file (if any) in the
970      current working directory.  This is only done if the current
971      directory is different from your home directory.  Thus, you can
972      have more than one init file, one generic in your home directory,
973      and another, specific to the program you are debugging, in the
974      directory where you invoke GDB.
976   5. Reads command files specified by the `-x' option.  *Note Command
977      Files::, for more details about GDB command files.
979   6. Reads the command history recorded in the "history file".  *Note
980      Command History::, for more details about the command history and
981      the files where GDB records it.
983    Init files use the same syntax as "command files" (*note Command
984 Files::) and are processed by GDB in the same way.  The init file in
985 your home directory can set options (such as `set complaints') that
986 affect subsequent processing of command line options and operands.
987 Init files are not executed if you use the `-nx' option (*note Choosing
988 modes: Mode Options.).
990    The GDB init files are normally called `.gdbinit'.  On some
991 configurations of GDB, the init file is known by a different name
992 (these are typically environments where a specialized form of GDB may
993 need to coexist with other forms, hence a different name for the
994 specialized version's init file).  These are the environments with
995 special init file names:
997    * The DJGPP port of GDB uses the name `gdb.ini', due to the
998      limitations of file names imposed by DOS filesystems.  The Windows
999      ports of GDB use the standard name, but if they find a `gdb.ini'
1000      file, they warn you about that and suggest to rename the file to
1001      the standard name.
1003    * VxWorks (Wind River Systems real-time OS): `.vxgdbinit'
1005    * OS68K (Enea Data Systems real-time OS): `.os68gdbinit'
1007    * ES-1800 (Ericsson Telecom AB M68000 emulator): `.esgdbinit'
1009    * CISCO 68k: `.cisco-gdbinit'
1011    ---------- Footnotes ----------
1013    (1) On DOS/Windows systems, the home directory is the one pointed to
1014 by the `HOME' environment variable.
1016 \x1f
1017 File: gdb.info,  Node: Quitting GDB,  Next: Shell Commands,  Prev: Invoking GDB,  Up: Invocation
1019 2.2 Quitting GDB
1020 ================
1022 `quit [EXPRESSION]'
1024      To exit GDB, use the `quit' command (abbreviated `q'), or type an
1025      end-of-file character (usually `C-d').  If you do not supply
1026      EXPRESSION, GDB will terminate normally; otherwise it will
1027      terminate using the result of EXPRESSION as the error code.
1029    An interrupt (often `C-c') does not exit from GDB, but rather
1030 terminates the action of any GDB command that is in progress and
1031 returns to GDB command level.  It is safe to type the interrupt
1032 character at any time because GDB does not allow it to take effect
1033 until a time when it is safe.
1035    If you have been using GDB to control an attached process or device,
1036 you can release it with the `detach' command (*note Debugging an
1037 already-running process: Attach.).
1039 \x1f
1040 File: gdb.info,  Node: Shell Commands,  Next: Logging output,  Prev: Quitting GDB,  Up: Invocation
1042 2.3 Shell commands
1043 ==================
1045 If you need to execute occasional shell commands during your debugging
1046 session, there is no need to leave or suspend GDB; you can just use the
1047 `shell' command.
1049 `shell COMMAND STRING'
1050      Invoke a standard shell to execute COMMAND STRING.  If it exists,
1051      the environment variable `SHELL' determines which shell to run.
1052      Otherwise GDB uses the default shell (`/bin/sh' on Unix systems,
1053      `COMMAND.COM' on MS-DOS, etc.).
1055    The utility `make' is often needed in development environments.  You
1056 do not have to use the `shell' command for this purpose in GDB:
1058 `make MAKE-ARGS'
1059      Execute the `make' program with the specified arguments.  This is
1060      equivalent to `shell make MAKE-ARGS'.
1062 \x1f
1063 File: gdb.info,  Node: Logging output,  Prev: Shell Commands,  Up: Invocation
1065 2.4 Logging output
1066 ==================
1068 You may want to save the output of GDB commands to a file.  There are
1069 several commands to control GDB's logging.
1071 `set logging on'
1072      Enable logging.
1074 `set logging off'
1075      Disable logging.  
1077 `set logging file FILE'
1078      Change the name of the current logfile.  The default logfile is
1079      `gdb.txt'.
1081 `set logging overwrite [on|off]'
1082      By default, GDB will append to the logfile.  Set `overwrite' if
1083      you want `set logging on' to overwrite the logfile instead.
1085 `set logging redirect [on|off]'
1086      By default, GDB output will go to both the terminal and the
1087      logfile.  Set `redirect' if you want output to go only to the log
1088      file.  
1090 `show logging'
1091      Show the current values of the logging settings.
1093 \x1f
1094 File: gdb.info,  Node: Commands,  Next: Running,  Prev: Invocation,  Up: Top
1096 3 GDB Commands
1097 **************
1099 You can abbreviate a GDB command to the first few letters of the command
1100 name, if that abbreviation is unambiguous; and you can repeat certain
1101 GDB commands by typing just <RET>.  You can also use the <TAB> key to
1102 get GDB to fill out the rest of a word in a command (or to show you the
1103 alternatives available, if there is more than one possibility).
1105 * Menu:
1107 * Command Syntax::              How to give commands to GDB
1108 * Completion::                  Command completion
1109 * Help::                        How to ask GDB for help
1111 \x1f
1112 File: gdb.info,  Node: Command Syntax,  Next: Completion,  Up: Commands
1114 3.1 Command syntax
1115 ==================
1117 A GDB command is a single line of input.  There is no limit on how long
1118 it can be.  It starts with a command name, which is followed by
1119 arguments whose meaning depends on the command name.  For example, the
1120 command `step' accepts an argument which is the number of times to
1121 step, as in `step 5'.  You can also use the `step' command with no
1122 arguments.  Some commands do not allow any arguments.
1124    GDB command names may always be truncated if that abbreviation is
1125 unambiguous.  Other possible command abbreviations are listed in the
1126 documentation for individual commands.  In some cases, even ambiguous
1127 abbreviations are allowed; for example, `s' is specially defined as
1128 equivalent to `step' even though there are other commands whose names
1129 start with `s'.  You can test abbreviations by using them as arguments
1130 to the `help' command.
1132    A blank line as input to GDB (typing just <RET>) means to repeat the
1133 previous command.  Certain commands (for example, `run') will not
1134 repeat this way; these are commands whose unintentional repetition
1135 might cause trouble and which you are unlikely to want to repeat.
1136 User-defined commands can disable this feature; see *Note dont-repeat:
1137 Define.
1139    The `list' and `x' commands, when you repeat them with <RET>,
1140 construct new arguments rather than repeating exactly as typed.  This
1141 permits easy scanning of source or memory.
1143    GDB can also use <RET> in another way: to partition lengthy output,
1144 in a way similar to the common utility `more' (*note Screen size:
1145 Screen Size.).  Since it is easy to press one <RET> too many in this
1146 situation, GDB disables command repetition after any command that
1147 generates this sort of display.
1149    Any text from a `#' to the end of the line is a comment; it does
1150 nothing.  This is useful mainly in command files (*note Command files:
1151 Command Files.).
1153    The `C-o' binding is useful for repeating a complex sequence of
1154 commands.  This command accepts the current line, like `RET', and then
1155 fetches the next line relative to the current line from the history for
1156 editing.
1158 \x1f
1159 File: gdb.info,  Node: Completion,  Next: Help,  Prev: Command Syntax,  Up: Commands
1161 3.2 Command completion
1162 ======================
1164 GDB can fill in the rest of a word in a command for you, if there is
1165 only one possibility; it can also show you what the valid possibilities
1166 are for the next word in a command, at any time.  This works for GDB
1167 commands, GDB subcommands, and the names of symbols in your program.
1169    Press the <TAB> key whenever you want GDB to fill out the rest of a
1170 word.  If there is only one possibility, GDB fills in the word, and
1171 waits for you to finish the command (or press <RET> to enter it).  For
1172 example, if you type
1174      (gdb) info bre <TAB>
1176 GDB fills in the rest of the word `breakpoints', since that is the only
1177 `info' subcommand beginning with `bre':
1179      (gdb) info breakpoints
1181 You can either press <RET> at this point, to run the `info breakpoints'
1182 command, or backspace and enter something else, if `breakpoints' does
1183 not look like the command you expected.  (If you were sure you wanted
1184 `info breakpoints' in the first place, you might as well just type
1185 <RET> immediately after `info bre', to exploit command abbreviations
1186 rather than command completion).
1188    If there is more than one possibility for the next word when you
1189 press <TAB>, GDB sounds a bell.  You can either supply more characters
1190 and try again, or just press <TAB> a second time; GDB displays all the
1191 possible completions for that word.  For example, you might want to set
1192 a breakpoint on a subroutine whose name begins with `make_', but when
1193 you type `b make_<TAB>' GDB just sounds the bell.  Typing <TAB> again
1194 displays all the function names in your program that begin with those
1195 characters, for example:
1197      (gdb) b make_ <TAB>
1198 GDB sounds bell; press <TAB> again, to see:
1199      make_a_section_from_file     make_environ
1200      make_abs_section             make_function_type
1201      make_blockvector             make_pointer_type
1202      make_cleanup                 make_reference_type
1203      make_command                 make_symbol_completion_list
1204      (gdb) b make_
1206 After displaying the available possibilities, GDB copies your partial
1207 input (`b make_' in the example) so you can finish the command.
1209    If you just want to see the list of alternatives in the first place,
1210 you can press `M-?' rather than pressing <TAB> twice.  `M-?' means
1211 `<META> ?'.  You can type this either by holding down a key designated
1212 as the <META> shift on your keyboard (if there is one) while typing
1213 `?', or as <ESC> followed by `?'.
1215    Sometimes the string you need, while logically a "word", may contain
1216 parentheses or other characters that GDB normally excludes from its
1217 notion of a word.  To permit word completion to work in this situation,
1218 you may enclose words in `'' (single quote marks) in GDB commands.
1220    The most likely situation where you might need this is in typing the
1221 name of a C++ function.  This is because C++ allows function
1222 overloading (multiple definitions of the same function, distinguished
1223 by argument type).  For example, when you want to set a breakpoint you
1224 may need to distinguish whether you mean the version of `name' that
1225 takes an `int' parameter, `name(int)', or the version that takes a
1226 `float' parameter, `name(float)'.  To use the word-completion
1227 facilities in this situation, type a single quote `'' at the beginning
1228 of the function name.  This alerts GDB that it may need to consider
1229 more information than usual when you press <TAB> or `M-?' to request
1230 word completion:
1232      (gdb) b 'bubble( M-?
1233      bubble(double,double)    bubble(int,int)
1234      (gdb) b 'bubble(
1236    In some cases, GDB can tell that completing a name requires using
1237 quotes.  When this happens, GDB inserts the quote for you (while
1238 completing as much as it can) if you do not type the quote in the first
1239 place:
1241      (gdb) b bub <TAB>
1242 GDB alters your input line to the following, and rings a bell:
1243      (gdb) b 'bubble(
1245 In general, GDB can tell that a quote is needed (and inserts it) if you
1246 have not yet started typing the argument list when you ask for
1247 completion on an overloaded symbol.
1249    For more information about overloaded functions, see *Note C++
1250 expressions: C plus plus expressions.  You can use the command `set
1251 overload-resolution off' to disable overload resolution; see *Note GDB
1252 features for C++: Debugging C plus plus.
1254 \x1f
1255 File: gdb.info,  Node: Help,  Prev: Completion,  Up: Commands
1257 3.3 Getting help
1258 ================
1260 You can always ask GDB itself for information on its commands, using
1261 the command `help'.
1263 `help'
1265      You can use `help' (abbreviated `h') with no arguments to display
1266      a short list of named classes of commands:
1268           (gdb) help
1269           List of classes of commands:
1271           aliases -- Aliases of other commands
1272           breakpoints -- Making program stop at certain points
1273           data -- Examining data
1274           files -- Specifying and examining files
1275           internals -- Maintenance commands
1276           obscure -- Obscure features
1277           running -- Running the program
1278           stack -- Examining the stack
1279           status -- Status inquiries
1280           support -- Support facilities
1281           tracepoints -- Tracing of program execution without
1283           stopping the program
1284           user-defined -- User-defined commands
1286           Type "help" followed by a class name for a list of
1287           commands in that class.
1288           Type "help" followed by command name for full
1289           documentation.
1290           Command name abbreviations are allowed if unambiguous.
1291           (gdb)
1293 `help CLASS'
1294      Using one of the general help classes as an argument, you can get a
1295      list of the individual commands in that class.  For example, here
1296      is the help display for the class `status':
1298           (gdb) help status
1299           Status inquiries.
1301           List of commands:
1303           info -- Generic command for showing things
1304            about the program being debugged
1305           show -- Generic command for showing things
1306            about the debugger
1308           Type "help" followed by command name for full
1309           documentation.
1310           Command name abbreviations are allowed if unambiguous.
1311           (gdb)
1313 `help COMMAND'
1314      With a command name as `help' argument, GDB displays a short
1315      paragraph on how to use that command.
1317 `apropos ARGS'
1318      The `apropos' command searches through all of the GDB commands,
1319      and their documentation, for the regular expression specified in
1320      ARGS. It prints out all matches found. For example:
1322           apropos reload
1324      results in:
1326           set symbol-reloading -- Set dynamic symbol table reloading
1327                                            multiple times in one run
1328           show symbol-reloading -- Show dynamic symbol table reloading
1329                                            multiple times in one run
1331 `complete ARGS'
1332      The `complete ARGS' command lists all the possible completions for
1333      the beginning of a command.  Use ARGS to specify the beginning of
1334      the command you want completed.  For example:
1336           complete i
1338      results in:
1340           if
1341           ignore
1342           info
1343           inspect
1345      This is intended for use by GNU Emacs.
1347    In addition to `help', you can use the GDB commands `info' and
1348 `show' to inquire about the state of your program, or the state of GDB
1349 itself.  Each command supports many topics of inquiry; this manual
1350 introduces each of them in the appropriate context.  The listings under
1351 `info' and under `show' in the Index point to all the sub-commands.
1352 *Note Index::.
1354 `info'
1355      This command (abbreviated `i') is for describing the state of your
1356      program.  For example, you can list the arguments given to your
1357      program with `info args', list the registers currently in use with
1358      `info registers', or list the breakpoints you have set with `info
1359      breakpoints'.  You can get a complete list of the `info'
1360      sub-commands with `help info'.
1362 `set'
1363      You can assign the result of an expression to an environment
1364      variable with `set'.  For example, you can set the GDB prompt to a
1365      $-sign with `set prompt $'.
1367 `show'
1368      In contrast to `info', `show' is for describing the state of GDB
1369      itself.  You can change most of the things you can `show', by
1370      using the related command `set'; for example, you can control what
1371      number system is used for displays with `set radix', or simply
1372      inquire which is currently in use with `show radix'.
1374      To display all the settable parameters and their current values,
1375      you can use `show' with no arguments; you may also use `info set'.
1376      Both commands produce the same display.
1378    Here are three miscellaneous `show' subcommands, all of which are
1379 exceptional in lacking corresponding `set' commands:
1381 `show version'
1382      Show what version of GDB is running.  You should include this
1383      information in GDB bug-reports.  If multiple versions of GDB are
1384      in use at your site, you may need to determine which version of
1385      GDB you are running; as GDB evolves, new commands are introduced,
1386      and old ones may wither away.  Also, many system vendors ship
1387      variant versions of GDB, and there are variant versions of GDB in
1388      GNU/Linux distributions as well.  The version number is the same
1389      as the one announced when you start GDB.
1391 `show copying'
1392 `info copying'
1393      Display information about permission for copying GDB.
1395 `show warranty'
1396 `info warranty'
1397      Display the GNU "NO WARRANTY" statement, or a warranty, if your
1398      version of GDB comes with one.
1401 \x1f
1402 File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Commands,  Up: Top
1404 4 Running Programs Under GDB
1405 ****************************
1407 When you run a program under GDB, you must first generate debugging
1408 information when you compile it.
1410    You may start GDB with its arguments, if any, in an environment of
1411 your choice.  If you are doing native debugging, you may redirect your
1412 program's input and output, debug an already running process, or kill a
1413 child process.
1415 * Menu:
1417 * Compilation::                 Compiling for debugging
1418 * Starting::                    Starting your program
1419 * Arguments::                   Your program's arguments
1420 * Environment::                 Your program's environment
1422 * Working Directory::           Your program's working directory
1423 * Input/Output::                Your program's input and output
1424 * Attach::                      Debugging an already-running process
1425 * Kill Process::                Killing the child process
1427 * Threads::                     Debugging programs with multiple threads
1428 * Processes::                   Debugging programs with multiple processes
1429 * Checkpoint/Restart::          Setting a _bookmark_ to return to later
1431 \x1f
1432 File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
1434 4.1 Compiling for debugging
1435 ===========================
1437 In order to debug a program effectively, you need to generate debugging
1438 information when you compile it.  This debugging information is stored
1439 in the object file; it describes the data type of each variable or
1440 function and the correspondence between source line numbers and
1441 addresses in the executable code.
1443    To request debugging information, specify the `-g' option when you
1444 run the compiler.
1446    Programs that are to be shipped to your customers are compiled with
1447 optimizations, using the `-O' compiler option.  However, many compilers
1448 are unable to handle the `-g' and `-O' options together.  Using those
1449 compilers, you cannot generate optimized executables containing
1450 debugging information.
1452    GCC, the GNU C/C++ compiler, supports `-g' with or without `-O',
1453 making it possible to debug optimized code.  We recommend that you
1454 _always_ use `-g' whenever you compile a program.  You may think your
1455 program is correct, but there is no sense in pushing your luck.
1457    When you debug a program compiled with `-g -O', remember that the
1458 optimizer is rearranging your code; the debugger shows you what is
1459 really there.  Do not be too surprised when the execution path does not
1460 exactly match your source file!  An extreme example: if you define a
1461 variable, but never use it, GDB never sees that variable--because the
1462 compiler optimizes it out of existence.
1464    Some things do not work as well with `-g -O' as with just `-g',
1465 particularly on machines with instruction scheduling.  If in doubt,
1466 recompile with `-g' alone, and if this fixes the problem, please report
1467 it to us as a bug (including a test case!).  *Note Variables::, for
1468 more information about debugging optimized code.
1470    Older versions of the GNU C compiler permitted a variant option
1471 `-gg' for debugging information.  GDB no longer supports this format;
1472 if your GNU C compiler has this option, do not use it.
1474    GDB knows about preprocessor macros and can show you their expansion
1475 (*note Macros::).  Most compilers do not include information about
1476 preprocessor macros in the debugging information if you specify the
1477 `-g' flag alone, because this information is rather large.  Version 3.1
1478 and later of GCC, the GNU C compiler, provides macro information if you
1479 specify the options `-gdwarf-2' and `-g3'; the former option requests
1480 debugging information in the Dwarf 2 format, and the latter requests
1481 "extra information".  In the future, we hope to find more compact ways
1482 to represent macro information, so that it can be included with `-g'
1483 alone.
1485 \x1f
1486 File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
1488 4.2 Starting your program
1489 =========================
1491 `run'
1493      Use the `run' command to start your program under GDB.  You must
1494      first specify the program name (except on VxWorks) with an
1495      argument to GDB (*note Getting In and Out of GDB: Invocation.), or
1496      by using the `file' or `exec-file' command (*note Commands to
1497      specify files: Files.).
1500    If you are running your program in an execution environment that
1501 supports processes, `run' creates an inferior process and makes that
1502 process run your program.  (In environments without processes, `run'
1503 jumps to the start of your program.)
1505    The execution of a program is affected by certain information it
1506 receives from its superior.  GDB provides ways to specify this
1507 information, which you must do _before_ starting your program.  (You
1508 can change it after starting your program, but such changes only affect
1509 your program the next time you start it.)  This information may be
1510 divided into four categories:
1512 The _arguments._
1513      Specify the arguments to give your program as the arguments of the
1514      `run' command.  If a shell is available on your target, the shell
1515      is used to pass the arguments, so that you may use normal
1516      conventions (such as wildcard expansion or variable substitution)
1517      in describing the arguments.  In Unix systems, you can control
1518      which shell is used with the `SHELL' environment variable.  *Note
1519      Your program's arguments: Arguments.
1521 The _environment._
1522      Your program normally inherits its environment from GDB, but you
1523      can use the GDB commands `set environment' and `unset environment'
1524      to change parts of the environment that affect your program.
1525      *Note Your program's environment: Environment.
1527 The _working directory._
1528      Your program inherits its working directory from GDB.  You can set
1529      the GDB working directory with the `cd' command in GDB.  *Note
1530      Your program's working directory: Working Directory.
1532 The _standard input and output._
1533      Your program normally uses the same device for standard input and
1534      standard output as GDB is using.  You can redirect input and output
1535      in the `run' command line, or you can use the `tty' command to set
1536      a different device for your program.  *Note Your program's input
1537      and output: Input/Output.
1539      _Warning:_ While input and output redirection work, you cannot use
1540      pipes to pass the output of the program you are debugging to
1541      another program; if you attempt this, GDB is likely to wind up
1542      debugging the wrong program.
1544    When you issue the `run' command, your program begins to execute
1545 immediately.  *Note Stopping and continuing: Stopping, for discussion
1546 of how to arrange for your program to stop.  Once your program has
1547 stopped, you may call functions in your program, using the `print' or
1548 `call' commands.  *Note Examining Data: Data.
1550    If the modification time of your symbol file has changed since the
1551 last time GDB read its symbols, GDB discards its symbol table, and
1552 reads it again.  When it does this, GDB tries to retain your current
1553 breakpoints.
1555 `start'
1556      The name of the main procedure can vary from language to language.
1557      With C or C++, the main procedure name is always `main', but other
1558      languages such as Ada do not require a specific name for their
1559      main procedure.  The debugger provides a convenient way to start
1560      the execution of the program and to stop at the beginning of the
1561      main procedure, depending on the language used.
1563      The `start' command does the equivalent of setting a temporary
1564      breakpoint at the beginning of the main procedure and then invoking
1565      the `run' command.
1567      Some programs contain an "elaboration" phase where some startup
1568      code is executed before the main procedure is called.  This
1569      depends on the languages used to write your program.  In C++, for
1570      instance, constructors for static and global objects are executed
1571      before `main' is called.  It is therefore possible that the
1572      debugger stops before reaching the main procedure.  However, the
1573      temporary breakpoint will remain to halt execution.
1575      Specify the arguments to give to your program as arguments to the
1576      `start' command.  These arguments will be given verbatim to the
1577      underlying `run' command.  Note that the same arguments will be
1578      reused if no argument is provided during subsequent calls to
1579      `start' or `run'.
1581      It is sometimes necessary to debug the program during elaboration.
1582      In these cases, using the `start' command would stop the
1583      execution of your program too late, as the program would have
1584      already completed the elaboration phase.  Under these
1585      circumstances, insert breakpoints in your elaboration code before
1586      running your program.
1588 \x1f
1589 File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
1591 4.3 Your program's arguments
1592 ============================
1594 The arguments to your program can be specified by the arguments of the
1595 `run' command.  They are passed to a shell, which expands wildcard
1596 characters and performs redirection of I/O, and thence to your program.
1597 Your `SHELL' environment variable (if it exists) specifies what shell
1598 GDB uses.  If you do not define `SHELL', GDB uses the default shell
1599 (`/bin/sh' on Unix).
1601    On non-Unix systems, the program is usually invoked directly by GDB,
1602 which emulates I/O redirection via the appropriate system calls, and
1603 the wildcard characters are expanded by the startup code of the
1604 program, not by the shell.
1606    `run' with no arguments uses the same arguments used by the previous
1607 `run', or those set by the `set args' command.
1609 `set args'
1610      Specify the arguments to be used the next time your program is
1611      run.  If `set args' has no arguments, `run' executes your program
1612      with no arguments.  Once you have run your program with arguments,
1613      using `set args' before the next `run' is the only way to run it
1614      again without arguments.
1616 `show args'
1617      Show the arguments to give your program when it is started.
1619 \x1f
1620 File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
1622 4.4 Your program's environment
1623 ==============================
1625 The "environment" consists of a set of environment variables and their
1626 values.  Environment variables conventionally record such things as
1627 your user name, your home directory, your terminal type, and your search
1628 path for programs to run.  Usually you set up environment variables with
1629 the shell and they are inherited by all the other programs you run.
1630 When debugging, it can be useful to try running your program with a
1631 modified environment without having to start GDB over again.
1633 `path DIRECTORY'
1634      Add DIRECTORY to the front of the `PATH' environment variable (the
1635      search path for executables) that will be passed to your program.
1636      The value of `PATH' used by GDB does not change.  You may specify
1637      several directory names, separated by whitespace or by a
1638      system-dependent separator character (`:' on Unix, `;' on MS-DOS
1639      and MS-Windows).  If DIRECTORY is already in the path, it is moved
1640      to the front, so it is searched sooner.
1642      You can use the string `$cwd' to refer to whatever is the current
1643      working directory at the time GDB searches the path.  If you use
1644      `.' instead, it refers to the directory where you executed the
1645      `path' command.  GDB replaces `.' in the DIRECTORY argument (with
1646      the current path) before adding DIRECTORY to the search path.
1648 `show paths'
1649      Display the list of search paths for executables (the `PATH'
1650      environment variable).
1652 `show environment [VARNAME]'
1653      Print the value of environment variable VARNAME to be given to
1654      your program when it starts.  If you do not supply VARNAME, print
1655      the names and values of all environment variables to be given to
1656      your program.  You can abbreviate `environment' as `env'.
1658 `set environment VARNAME [=VALUE]'
1659      Set environment variable VARNAME to VALUE.  The value changes for
1660      your program only, not for GDB itself.  VALUE may be any string;
1661      the values of environment variables are just strings, and any
1662      interpretation is supplied by your program itself.  The VALUE
1663      parameter is optional; if it is eliminated, the variable is set to
1664      a null value.
1666      For example, this command:
1668           set env USER = foo
1670      tells the debugged program, when subsequently run, that its user
1671      is named `foo'.  (The spaces around `=' are used for clarity here;
1672      they are not actually required.)
1674 `unset environment VARNAME'
1675      Remove variable VARNAME from the environment to be passed to your
1676      program.  This is different from `set env VARNAME ='; `unset
1677      environment' removes the variable from the environment, rather
1678      than assigning it an empty value.
1680    _Warning:_ On Unix systems, GDB runs your program using the shell
1681 indicated by your `SHELL' environment variable if it exists (or
1682 `/bin/sh' if not).  If your `SHELL' variable names a shell that runs an
1683 initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
1684 BASH--any variables you set in that file affect your program.  You may
1685 wish to move setting of environment variables to files that are only
1686 run when you sign on, such as `.login' or `.profile'.
1688 \x1f
1689 File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
1691 4.5 Your program's working directory
1692 ====================================
1694 Each time you start your program with `run', it inherits its working
1695 directory from the current working directory of GDB.  The GDB working
1696 directory is initially whatever it inherited from its parent process
1697 (typically the shell), but you can specify a new working directory in
1698 GDB with the `cd' command.
1700    The GDB working directory also serves as a default for the commands
1701 that specify files for GDB to operate on.  *Note Commands to specify
1702 files: Files.
1704 `cd DIRECTORY'
1705      Set the GDB working directory to DIRECTORY.
1707 `pwd'
1708      Print the GDB working directory.
1710    It is generally impossible to find the current working directory of
1711 the process being debugged (since a program can change its directory
1712 during its run).  If you work on a system where GDB is configured with
1713 the `/proc' support, you can use the `info proc' command (*note SVR4
1714 Process Information::) to find out the current working directory of the
1715 debuggee.
1717 \x1f
1718 File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
1720 4.6 Your program's input and output
1721 ===================================
1723 By default, the program you run under GDB does input and output to the
1724 same terminal that GDB uses.  GDB switches the terminal to its own
1725 terminal modes to interact with you, but it records the terminal modes
1726 your program was using and switches back to them when you continue
1727 running your program.
1729 `info terminal'
1730      Displays information recorded by GDB about the terminal modes your
1731      program is using.
1733    You can redirect your program's input and/or output using shell
1734 redirection with the `run' command.  For example,
1736      run > outfile
1738 starts your program, diverting its output to the file `outfile'.
1740    Another way to specify where your program should do input and output
1741 is with the `tty' command.  This command accepts a file name as
1742 argument, and causes this file to be the default for future `run'
1743 commands.  It also resets the controlling terminal for the child
1744 process, for future `run' commands.  For example,
1746      tty /dev/ttyb
1748 directs that processes started with subsequent `run' commands default
1749 to do input and output on the terminal `/dev/ttyb' and have that as
1750 their controlling terminal.
1752    An explicit redirection in `run' overrides the `tty' command's
1753 effect on the input/output device, but not its effect on the controlling
1754 terminal.
1756    When you use the `tty' command or redirect input in the `run'
1757 command, only the input _for your program_ is affected.  The input for
1758 GDB still comes from your terminal.  `tty' is an alias for `set
1759 inferior-tty'.
1761    You can use the `show inferior-tty' command to tell GDB to display
1762 the name of the terminal that will be used for future runs of your
1763 program.
1765 `set inferior-tty /dev/ttyb'
1766      Set the tty for the program being debugged to /dev/ttyb.
1768 `show inferior-tty'
1769      Show the current tty for the program being debugged.
1771 \x1f
1772 File: gdb.info,  Node: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
1774 4.7 Debugging an already-running process
1775 ========================================
1777 `attach PROCESS-ID'
1778      This command attaches to a running process--one that was started
1779      outside GDB.  (`info files' shows your active targets.)  The
1780      command takes as argument a process ID.  The usual way to find out
1781      the PROCESS-ID of a Unix process is with the `ps' utility, or with
1782      the `jobs -l' shell command.
1784      `attach' does not repeat if you press <RET> a second time after
1785      executing the command.
1787    To use `attach', your program must be running in an environment
1788 which supports processes; for example, `attach' does not work for
1789 programs on bare-board targets that lack an operating system.  You must
1790 also have permission to send the process a signal.
1792    When you use `attach', the debugger finds the program running in the
1793 process first by looking in the current working directory, then (if the
1794 program is not found) by using the source file search path (*note
1795 Specifying source directories: Source Path.).  You can also use the
1796 `file' command to load the program.  *Note Commands to Specify Files:
1797 Files.
1799    The first thing GDB does after arranging to debug the specified
1800 process is to stop it.  You can examine and modify an attached process
1801 with all the GDB commands that are ordinarily available when you start
1802 processes with `run'.  You can insert breakpoints; you can step and
1803 continue; you can modify storage.  If you would rather the process
1804 continue running, you may use the `continue' command after attaching
1805 GDB to the process.
1807 `detach'
1808      When you have finished debugging the attached process, you can use
1809      the `detach' command to release it from GDB control.  Detaching
1810      the process continues its execution.  After the `detach' command,
1811      that process and GDB become completely independent once more, and
1812      you are ready to `attach' another process or start one with `run'.
1813      `detach' does not repeat if you press <RET> again after executing
1814      the command.
1816    If you exit GDB or use the `run' command while you have an attached
1817 process, you kill that process.  By default, GDB asks for confirmation
1818 if you try to do either of these things; you can control whether or not
1819 you need to confirm by using the `set confirm' command (*note Optional
1820 warnings and messages: Messages/Warnings.).
1822 \x1f
1823 File: gdb.info,  Node: Kill Process,  Next: Threads,  Prev: Attach,  Up: Running
1825 4.8 Killing the child process
1826 =============================
1828 `kill'
1829      Kill the child process in which your program is running under GDB.
1831    This command is useful if you wish to debug a core dump instead of a
1832 running process.  GDB ignores any core dump file while your program is
1833 running.
1835    On some operating systems, a program cannot be executed outside GDB
1836 while you have breakpoints set on it inside GDB.  You can use the
1837 `kill' command in this situation to permit running your program outside
1838 the debugger.
1840    The `kill' command is also useful if you wish to recompile and
1841 relink your program, since on many systems it is impossible to modify an
1842 executable file while it is running in a process.  In this case, when
1843 you next type `run', GDB notices that the file has changed, and reads
1844 the symbol table again (while trying to preserve your current
1845 breakpoint settings).
1847 \x1f
1848 File: gdb.info,  Node: Threads,  Next: Processes,  Prev: Kill Process,  Up: Running
1850 4.9 Debugging programs with multiple threads
1851 ============================================
1853 In some operating systems, such as HP-UX and Solaris, a single program
1854 may have more than one "thread" of execution.  The precise semantics of
1855 threads differ from one operating system to another, but in general the
1856 threads of a single program are akin to multiple processes--except that
1857 they share one address space (that is, they can all examine and modify
1858 the same variables).  On the other hand, each thread has its own
1859 registers and execution stack, and perhaps private memory.
1861    GDB provides these facilities for debugging multi-thread programs:
1863    * automatic notification of new threads
1865    * `thread THREADNO', a command to switch among threads
1867    * `info threads', a command to inquire about existing threads
1869    * `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
1870      to a list of threads
1872    * thread-specific breakpoints
1874      _Warning:_ These facilities are not yet available on every GDB
1875      configuration where the operating system supports threads.  If
1876      your GDB does not support threads, these commands have no effect.
1877      For example, a system without thread support shows no output from
1878      `info threads', and always rejects the `thread' command, like this:
1880           (gdb) info threads
1881           (gdb) thread 1
1882           Thread ID 1 not known.  Use the "info threads" command to
1883           see the IDs of currently known threads.
1885    The GDB thread debugging facility allows you to observe all threads
1886 while your program runs--but whenever GDB takes control, one thread in
1887 particular is always the focus of debugging.  This thread is called the
1888 "current thread".  Debugging commands show program information from the
1889 perspective of the current thread.
1891    Whenever GDB detects a new thread in your program, it displays the
1892 target system's identification for the thread with a message in the
1893 form `[New SYSTAG]'.  SYSTAG is a thread identifier whose form varies
1894 depending on the particular system.  For example, on LynxOS, you might
1897      [New process 35 thread 27]
1899 when GDB notices a new thread.  In contrast, on an SGI system, the
1900 SYSTAG is simply something like `process 368', with no further
1901 qualifier.
1903    For debugging purposes, GDB associates its own thread number--always
1904 a single integer--with each thread in your program.
1906 `info threads'
1907      Display a summary of all threads currently in your program.  GDB
1908      displays for each thread (in this order):
1910        1. the thread number assigned by GDB
1912        2. the target system's thread identifier (SYSTAG)
1914        3. the current stack frame summary for that thread
1916      An asterisk `*' to the left of the GDB thread number indicates the
1917      current thread.
1919      For example,
1921      (gdb) info threads
1922        3 process 35 thread 27  0x34e5 in sigpause ()
1923        2 process 35 thread 23  0x34e5 in sigpause ()
1924      * 1 process 35 thread 13  main (argc=1, argv=0x7ffffff8)
1925          at threadtest.c:68
1927    On HP-UX systems:
1929    For debugging purposes, GDB associates its own thread number--a
1930 small integer assigned in thread-creation order--with each thread in
1931 your program.
1933    Whenever GDB detects a new thread in your program, it displays both
1934 GDB's thread number and the target system's identification for the
1935 thread with a message in the form `[New SYSTAG]'.  SYSTAG is a thread
1936 identifier whose form varies depending on the particular system.  For
1937 example, on HP-UX, you see
1939      [New thread 2 (system thread 26594)]
1941 when GDB notices a new thread.
1943 `info threads'
1944      Display a summary of all threads currently in your program.  GDB
1945      displays for each thread (in this order):
1947        1. the thread number assigned by GDB
1949        2. the target system's thread identifier (SYSTAG)
1951        3. the current stack frame summary for that thread
1953      An asterisk `*' to the left of the GDB thread number indicates the
1954      current thread.
1956      For example,
1958      (gdb) info threads
1959          * 3 system thread 26607  worker (wptr=0x7b09c318 "@") \
1961      at quicksort.c:137
1962            2 system thread 26606  0x7b0030d8 in __ksleep () \
1964      from /usr/lib/libc.2
1965            1 system thread 27905  0x7b003498 in _brk () \
1967      from /usr/lib/libc.2
1969    On Solaris, you can display more information about user threads with
1970 a Solaris-specific command:
1972 `maint info sol-threads'
1973      Display info on Solaris user threads.
1975 `thread THREADNO'
1976      Make thread number THREADNO the current thread.  The command
1977      argument THREADNO is the internal GDB thread number, as shown in
1978      the first field of the `info threads' display.  GDB responds by
1979      displaying the system identifier of the thread you selected, and
1980      its current stack frame summary:
1982           (gdb) thread 2
1983           [Switching to process 35 thread 23]
1984           0x34e5 in sigpause ()
1986      As with the `[New ...]' message, the form of the text after
1987      `Switching to' depends on your system's conventions for identifying
1988      threads.
1990 `thread apply [THREADNO] [ALL] COMMAND'
1991      The `thread apply' command allows you to apply the named COMMAND
1992      to one or more threads.  Specify the numbers of the threads that
1993      you want affected with the command argument THREADNO.  It can be a
1994      single thread number, one of the numbers shown in the first field
1995      of the `info threads' display; or it could be a range of thread
1996      numbers, as in `2-4'.  To apply a command to all threads, type
1997      `thread apply all COMMAND'.
1999    Whenever GDB stops your program, due to a breakpoint or a signal, it
2000 automatically selects the thread where that breakpoint or signal
2001 happened.  GDB alerts you to the context switch with a message of the
2002 form `[Switching to SYSTAG]' to identify the thread.
2004    *Note Stopping and starting multi-thread programs: Thread Stops, for
2005 more information about how GDB behaves when you stop and start programs
2006 with multiple threads.
2008    *Note Setting watchpoints: Set Watchpoints, for information about
2009 watchpoints in programs with multiple threads.
2011 \x1f
2012 File: gdb.info,  Node: Processes,  Next: Checkpoint/Restart,  Prev: Threads,  Up: Running
2014 4.10 Debugging programs with multiple processes
2015 ===============================================
2017 On most systems, GDB has no special support for debugging programs
2018 which create additional processes using the `fork' function.  When a
2019 program forks, GDB will continue to debug the parent process and the
2020 child process will run unimpeded.  If you have set a breakpoint in any
2021 code which the child then executes, the child will get a `SIGTRAP'
2022 signal which (unless it catches the signal) will cause it to terminate.
2024    However, if you want to debug the child process there is a workaround
2025 which isn't too painful.  Put a call to `sleep' in the code which the
2026 child process executes after the fork.  It may be useful to sleep only
2027 if a certain environment variable is set, or a certain file exists, so
2028 that the delay need not occur when you don't want to run GDB on the
2029 child.  While the child is sleeping, use the `ps' program to get its
2030 process ID.  Then tell GDB (a new invocation of GDB if you are also
2031 debugging the parent process) to attach to the child process (*note
2032 Attach::).  From that point on you can debug the child process just
2033 like any other process which you attached to.
2035    On some systems, GDB provides support for debugging programs that
2036 create additional processes using the `fork' or `vfork' functions.
2037 Currently, the only platforms with this feature are HP-UX (11.x and
2038 later only?) and GNU/Linux (kernel version 2.5.60 and later).
2040    By default, when a program forks, GDB will continue to debug the
2041 parent process and the child process will run unimpeded.
2043    If you want to follow the child process instead of the parent
2044 process, use the command `set follow-fork-mode'.
2046 `set follow-fork-mode MODE'
2047      Set the debugger response to a program call of `fork' or `vfork'.
2048      A call to `fork' or `vfork' creates a new process.  The MODE
2049      argument can be:
2051     `parent'
2052           The original process is debugged after a fork.  The child
2053           process runs unimpeded.  This is the default.
2055     `child'
2056           The new process is debugged after a fork.  The parent process
2057           runs unimpeded.
2060 `show follow-fork-mode'
2061      Display the current debugger response to a `fork' or `vfork' call.
2063    On Linux, if you want to debug both the parent and child processes,
2064 use the command `set detach-on-fork'.
2066 `set detach-on-fork MODE'
2067      Tells gdb whether to detach one of the processes after a fork, or
2068      retain debugger control over them both.
2070     `on'
2071           The child process (or parent process, depending on the value
2072           of `follow-fork-mode') will be detached and allowed to run
2073           independently.  This is the default.
2075     `off'
2076           Both processes will be held under the control of GDB.  One
2077           process (child or parent, depending on the value of
2078           `follow-fork-mode') is debugged as usual, while the other is
2079           held suspended.
2082 `show detach-on-follow'
2083      Show whether detach-on-follow mode is on/off.
2085    If you choose to set DETACH-ON-FOLLOW mode off, then GDB will retain
2086 control of all forked processes (including nested forks).  You can list
2087 the forked processes under the control of GDB by using the `info forks'
2088 command, and switch from one fork to another by using the `fork'
2089 command.
2091 `info forks'
2092      Print a list of all forked processes under the control of GDB.
2093      The listing will include a fork id, a process id, and the current
2094      position (program counter) of the process.
2096 `fork FORK-ID'
2097      Make fork number FORK-ID the current process.  The argument
2098      FORK-ID is the internal fork number assigned by GDB, as shown in
2099      the first field of the `info forks' display.
2102    To quit debugging one of the forked processes, you can either detach
2103 from it by using the `detach-fork' command (allowing it to run
2104 independently), or delete (and kill) it using the `delete fork' command.
2106 `detach-fork FORK-ID'
2107      Detach from the process identified by GDB fork number FORK-ID, and
2108      remove it from the fork list.  The process will be allowed to run
2109      independently.
2111 `delete fork FORK-ID'
2112      Kill the process identified by GDB fork number FORK-ID, and remove
2113      it from the fork list.
2116    If you ask to debug a child process and a `vfork' is followed by an
2117 `exec', GDB executes the new target up to the first breakpoint in the
2118 new target.  If you have a breakpoint set on `main' in your original
2119 program, the breakpoint will also be set on the child process's `main'.
2121    When a child process is spawned by `vfork', you cannot debug the
2122 child or parent until an `exec' call completes.
2124    If you issue a `run' command to GDB after an `exec' call executes,
2125 the new target restarts.  To restart the parent process, use the `file'
2126 command with the parent executable name as its argument.
2128    You can use the `catch' command to make GDB stop whenever a `fork',
2129 `vfork', or `exec' call is made.  *Note Setting catchpoints: Set
2130 Catchpoints.
2132 \x1f
2133 File: gdb.info,  Node: Checkpoint/Restart,  Prev: Processes,  Up: Running
2135 4.11 Setting a _bookmark_ to return to later
2136 ============================================
2138 On certain operating systems(1), GDB is able to save a "snapshot" of a
2139 program's state, called a "checkpoint", and come back to it later.
2141    Returning to a checkpoint effectively undoes everything that has
2142 happened in the program since the `checkpoint' was saved.  This
2143 includes changes in memory, registers, and even (within some limits)
2144 system state.  Effectively, it is like going back in time to the moment
2145 when the checkpoint was saved.
2147    Thus, if you're stepping thru a program and you think you're getting
2148 close to the point where things go wrong, you can save a checkpoint.
2149 Then, if you accidentally go too far and miss the critical statement,
2150 instead of having to restart your program from the beginning, you can
2151 just go back to the checkpoint and start again from there.
2153    This can be especially useful if it takes a lot of time or steps to
2154 reach the point where you think the bug occurs.
2156    To use the `checkpoint'/`restart' method of debugging:
2158 `checkpoint'
2159      Save a snapshot of the debugged program's current execution state.
2160      The `checkpoint' command takes no arguments, but each checkpoint
2161      is assigned a small integer id, similar to a breakpoint id.
2163 `info checkpoints'
2164      List the checkpoints that have been saved in the current debugging
2165      session.  For each checkpoint, the following information will be
2166      listed:
2168     `Checkpoint ID'
2170     `Process ID'
2172     `Code Address'
2174     `Source line, or label'
2176 `restart CHECKPOINT-ID'
2177      Restore the program state that was saved as checkpoint number
2178      CHECKPOINT-ID.  All program variables, registers, stack frames
2179      etc.  will be returned to the values that they had when the
2180      checkpoint was saved.  In essence, gdb will "wind back the clock"
2181      to the point in time when the checkpoint was saved.
2183      Note that breakpoints, GDB variables, command history etc.  are
2184      not affected by restoring a checkpoint.  In general, a checkpoint
2185      only restores things that reside in the program being debugged,
2186      not in the debugger.
2188 `delete checkpoint CHECKPOINT-ID'
2189      Delete the previously-saved checkpoint identified by CHECKPOINT-ID.
2192    Returning to a previously saved checkpoint will restore the user
2193 state of the program being debugged, plus a significant subset of the
2194 system (OS) state, including file pointers.  It won't "un-write" data
2195 from a file, but it will rewind the file pointer to the previous
2196 location, so that the previously written data can be overwritten.  For
2197 files opened in read mode, the pointer will also be restored so that the
2198 previously read data can be read again.
2200    Of course, characters that have been sent to a printer (or other
2201 external device) cannot be "snatched back", and characters received
2202 from eg. a serial device can be removed from internal program buffers,
2203 but they cannot be "pushed back" into the serial pipeline, ready to be
2204 received again.  Similarly, the actual contents of files that have been
2205 changed cannot be restored (at this time).
2207    However, within those constraints, you actually can "rewind" your
2208 program to a previously saved point in time, and begin debugging it
2209 again -- and you can change the course of events so as to debug a
2210 different execution path this time.
2212    Finally, there is one bit of internal program state that will be
2213 different when you return to a checkpoint -- the program's process id.
2214 Each checkpoint will have a unique process id (or PID), and each will
2215 be different from the program's original PID.  If your program has
2216 saved a local copy of its process id, this could potentially pose a
2217 problem.
2219 4.11.1 A non-obvious benefit of using checkpoints
2220 -------------------------------------------------
2222 On some systems such as GNU/Linux, address space randomization is
2223 performed on new processes for security reasons.  This makes it
2224 difficult or impossible to set a breakpoint, or watchpoint, on an
2225 absolute address if you have to restart the program, since the absolute
2226 location of a symbol will change from one execution to the next.
2228    A checkpoint, however, is an _identical_ copy of a process.
2229 Therefore if you create a checkpoint at (eg.) the start of main, and
2230 simply return to that checkpoint instead of restarting the process, you
2231 can avoid the effects of address randomization and your symbols will
2232 all stay in the same place.
2234    ---------- Footnotes ----------
2236    (1) Currently, only GNU/Linux.
2238 \x1f
2239 File: gdb.info,  Node: Stopping,  Next: Stack,  Prev: Running,  Up: Top
2241 5 Stopping and Continuing
2242 *************************
2244 The principal purposes of using a debugger are so that you can stop your
2245 program before it terminates; or so that, if your program runs into
2246 trouble, you can investigate and find out why.
2248    Inside GDB, your program may stop for any of several reasons, such
2249 as a signal, a breakpoint, or reaching a new line after a GDB command
2250 such as `step'.  You may then examine and change variables, set new
2251 breakpoints or remove old ones, and then continue execution.  Usually,
2252 the messages shown by GDB provide ample explanation of the status of
2253 your program--but you can also explicitly request this information at
2254 any time.
2256 `info program'
2257      Display information about the status of your program: whether it is
2258      running or not, what process it is, and why it stopped.
2260 * Menu:
2262 * Breakpoints::                 Breakpoints, watchpoints, and catchpoints
2263 * Continuing and Stepping::     Resuming execution
2264 * Signals::                     Signals
2265 * Thread Stops::                Stopping and starting multi-thread programs
2267 \x1f
2268 File: gdb.info,  Node: Breakpoints,  Next: Continuing and Stepping,  Up: Stopping
2270 5.1 Breakpoints, watchpoints, and catchpoints
2271 =============================================
2273 A "breakpoint" makes your program stop whenever a certain point in the
2274 program is reached.  For each breakpoint, you can add conditions to
2275 control in finer detail whether your program stops.  You can set
2276 breakpoints with the `break' command and its variants (*note Setting
2277 breakpoints: Set Breaks.), to specify the place where your program
2278 should stop by line number, function name or exact address in the
2279 program.
2281    On some systems, you can set breakpoints in shared libraries before
2282 the executable is run.  There is a minor limitation on HP-UX systems:
2283 you must wait until the executable is run in order to set breakpoints
2284 in shared library routines that are not called directly by the program
2285 (for example, routines that are arguments in a `pthread_create' call).
2287    A "watchpoint" is a special breakpoint that stops your program when
2288 the value of an expression changes.  You must use a different command
2289 to set watchpoints (*note Setting watchpoints: Set Watchpoints.), but
2290 aside from that, you can manage a watchpoint like any other breakpoint:
2291 you enable, disable, and delete both breakpoints and watchpoints using
2292 the same commands.
2294    You can arrange to have values from your program displayed
2295 automatically whenever GDB stops at a breakpoint.  *Note Automatic
2296 display: Auto Display.
2298    A "catchpoint" is another special breakpoint that stops your program
2299 when a certain kind of event occurs, such as the throwing of a C++
2300 exception or the loading of a library.  As with watchpoints, you use a
2301 different command to set a catchpoint (*note Setting catchpoints: Set
2302 Catchpoints.), but aside from that, you can manage a catchpoint like any
2303 other breakpoint.  (To stop when your program receives a signal, use the
2304 `handle' command; see *Note Signals: Signals.)
2306    GDB assigns a number to each breakpoint, watchpoint, or catchpoint
2307 when you create it; these numbers are successive integers starting with
2308 one.  In many of the commands for controlling various features of
2309 breakpoints you use the breakpoint number to say which breakpoint you
2310 want to change.  Each breakpoint may be "enabled" or "disabled"; if
2311 disabled, it has no effect on your program until you enable it again.
2313    Some GDB commands accept a range of breakpoints on which to operate.
2314 A breakpoint range is either a single breakpoint number, like `5', or
2315 two such numbers, in increasing order, separated by a hyphen, like
2316 `5-7'.  When a breakpoint range is given to a command, all breakpoint
2317 in that range are operated on.
2319 * Menu:
2321 * Set Breaks::                  Setting breakpoints
2322 * Set Watchpoints::             Setting watchpoints
2323 * Set Catchpoints::             Setting catchpoints
2324 * Delete Breaks::               Deleting breakpoints
2325 * Disabling::                   Disabling breakpoints
2326 * Conditions::                  Break conditions
2327 * Break Commands::              Breakpoint command lists
2328 * Breakpoint Menus::            Breakpoint menus
2329 * Error in Breakpoints::        ``Cannot insert breakpoints''
2330 * Breakpoint related warnings:: ``Breakpoint address adjusted...''
2332 \x1f
2333 File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Up: Breakpoints
2335 5.1.1 Setting breakpoints
2336 -------------------------
2338 Breakpoints are set with the `break' command (abbreviated `b').  The
2339 debugger convenience variable `$bpnum' records the number of the
2340 breakpoint you've set most recently; see *Note Convenience variables:
2341 Convenience Vars, for a discussion of what you can do with convenience
2342 variables.
2344    You have several ways to say where the breakpoint should go.
2346 `break FUNCTION'
2347      Set a breakpoint at entry to function FUNCTION.  When using source
2348      languages that permit overloading of symbols, such as C++,
2349      FUNCTION may refer to more than one possible place to break.
2350      *Note Breakpoint menus: Breakpoint Menus, for a discussion of that
2351      situation.
2353 `break +OFFSET'
2354 `break -OFFSET'
2355      Set a breakpoint some number of lines forward or back from the
2356      position at which execution stopped in the currently selected
2357      "stack frame".  (*Note Frames: Frames, for a description of stack
2358      frames.)
2360 `break LINENUM'
2361      Set a breakpoint at line LINENUM in the current source file.  The
2362      current source file is the last file whose source text was printed.
2363      The breakpoint will stop your program just before it executes any
2364      of the code on that line.
2366 `break FILENAME:LINENUM'
2367      Set a breakpoint at line LINENUM in source file FILENAME.
2369 `break FILENAME:FUNCTION'
2370      Set a breakpoint at entry to function FUNCTION found in file
2371      FILENAME.  Specifying a file name as well as a function name is
2372      superfluous except when multiple files contain similarly named
2373      functions.
2375 `break *ADDRESS'
2376      Set a breakpoint at address ADDRESS.  You can use this to set
2377      breakpoints in parts of your program which do not have debugging
2378      information or source files.
2380 `break'
2381      When called without any arguments, `break' sets a breakpoint at
2382      the next instruction to be executed in the selected stack frame
2383      (*note Examining the Stack: Stack.).  In any selected frame but the
2384      innermost, this makes your program stop as soon as control returns
2385      to that frame.  This is similar to the effect of a `finish'
2386      command in the frame inside the selected frame--except that
2387      `finish' does not leave an active breakpoint.  If you use `break'
2388      without an argument in the innermost frame, GDB stops the next
2389      time it reaches the current location; this may be useful inside
2390      loops.
2392      GDB normally ignores breakpoints when it resumes execution, until
2393      at least one instruction has been executed.  If it did not do
2394      this, you would be unable to proceed past a breakpoint without
2395      first disabling the breakpoint.  This rule applies whether or not
2396      the breakpoint already existed when your program stopped.
2398 `break ... if COND'
2399      Set a breakpoint with condition COND; evaluate the expression COND
2400      each time the breakpoint is reached, and stop only if the value is
2401      nonzero--that is, if COND evaluates as true.  `...' stands for one
2402      of the possible arguments described above (or no argument)
2403      specifying where to break.  *Note Break conditions: Conditions,
2404      for more information on breakpoint conditions.
2406 `tbreak ARGS'
2407      Set a breakpoint enabled only for one stop.  ARGS are the same as
2408      for the `break' command, and the breakpoint is set in the same
2409      way, but the breakpoint is automatically deleted after the first
2410      time your program stops there.  *Note Disabling breakpoints:
2411      Disabling.
2413 `hbreak ARGS'
2414      Set a hardware-assisted breakpoint.  ARGS are the same as for the
2415      `break' command and the breakpoint is set in the same way, but the
2416      breakpoint requires hardware support and some target hardware may
2417      not have this support.  The main purpose of this is EPROM/ROM code
2418      debugging, so you can set a breakpoint at an instruction without
2419      changing the instruction.  This can be used with the new
2420      trap-generation provided by SPARClite DSU and most x86-based
2421      targets.  These targets will generate traps when a program
2422      accesses some data or instruction address that is assigned to the
2423      debug registers.  However the hardware breakpoint registers can
2424      take a limited number of breakpoints.  For example, on the DSU,
2425      only two data breakpoints can be set at a time, and GDB will
2426      reject this command if more than two are used.  Delete or disable
2427      unused hardware breakpoints before setting new ones (*note
2428      Disabling: Disabling.).  *Note Break conditions: Conditions.  For
2429      remote targets, you can restrict the number of hardware
2430      breakpoints GDB will use, see *Note set remote
2431      hardware-breakpoint-limit::.
2433 `thbreak ARGS'
2434      Set a hardware-assisted breakpoint enabled only for one stop.  ARGS
2435      are the same as for the `hbreak' command and the breakpoint is set
2436      in the same way.  However, like the `tbreak' command, the
2437      breakpoint is automatically deleted after the first time your
2438      program stops there.  Also, like the `hbreak' command, the
2439      breakpoint requires hardware support and some target hardware may
2440      not have this support.  *Note Disabling breakpoints: Disabling.
2441      See also *Note Break conditions: Conditions.
2443 `rbreak REGEX'
2444      Set breakpoints on all functions matching the regular expression
2445      REGEX.  This command sets an unconditional breakpoint on all
2446      matches, printing a list of all breakpoints it set.  Once these
2447      breakpoints are set, they are treated just like the breakpoints
2448      set with the `break' command.  You can delete them, disable them,
2449      or make them conditional the same way as any other breakpoint.
2451      The syntax of the regular expression is the standard one used with
2452      tools like `grep'.  Note that this is different from the syntax
2453      used by shells, so for instance `foo*' matches all functions that
2454      include an `fo' followed by zero or more `o's.  There is an
2455      implicit `.*' leading and trailing the regular expression you
2456      supply, so to match only functions that begin with `foo', use
2457      `^foo'.
2459      When debugging C++ programs, `rbreak' is useful for setting
2460      breakpoints on overloaded functions that are not members of any
2461      special classes.
2463      The `rbreak' command can be used to set breakpoints in *all* the
2464      functions in a program, like this:
2466           (gdb) rbreak .
2468 `info breakpoints [N]'
2469 `info break [N]'
2470 `info watchpoints [N]'
2471      Print a table of all breakpoints, watchpoints, and catchpoints set
2472      and not deleted, with the following columns for each breakpoint:
2474     _Breakpoint Numbers_
2476     _Type_
2477           Breakpoint, watchpoint, or catchpoint.
2479     _Disposition_
2480           Whether the breakpoint is marked to be disabled or deleted
2481           when hit.
2483     _Enabled or Disabled_
2484           Enabled breakpoints are marked with `y'.  `n' marks
2485           breakpoints that are not enabled.
2487     _Address_
2488           Where the breakpoint is in your program, as a memory address.
2489           If the breakpoint is pending (see below for details) on a
2490           future load of a shared library, the address will be listed
2491           as `<PENDING>'.
2493     _What_
2494           Where the breakpoint is in the source for your program, as a
2495           file and line number.  For a pending breakpoint, the original
2496           string passed to the breakpoint command will be listed as it
2497           cannot be resolved until the appropriate shared library is
2498           loaded in the future.
2500      If a breakpoint is conditional, `info break' shows the condition on
2501      the line following the affected breakpoint; breakpoint commands,
2502      if any, are listed after that.  A pending breakpoint is allowed to
2503      have a condition specified for it.  The condition is not parsed
2504      for validity until a shared library is loaded that allows the
2505      pending breakpoint to resolve to a valid location.
2507      `info break' with a breakpoint number N as argument lists only
2508      that breakpoint.  The convenience variable `$_' and the default
2509      examining-address for the `x' command are set to the address of
2510      the last breakpoint listed (*note Examining memory: Memory.).
2512      `info break' displays a count of the number of times the breakpoint
2513      has been hit.  This is especially useful in conjunction with the
2514      `ignore' command.  You can ignore a large number of breakpoint
2515      hits, look at the breakpoint info to see how many times the
2516      breakpoint was hit, and then run again, ignoring one less than
2517      that number.  This will get you quickly to the last hit of that
2518      breakpoint.
2520    GDB allows you to set any number of breakpoints at the same place in
2521 your program.  There is nothing silly or meaningless about this.  When
2522 the breakpoints are conditional, this is even useful (*note Break
2523 conditions: Conditions.).
2525    If a specified breakpoint location cannot be found, it may be due to
2526 the fact that the location is in a shared library that is yet to be
2527 loaded.  In such a case, you may want GDB to create a special
2528 breakpoint (known as a "pending breakpoint") that attempts to resolve
2529 itself in the future when an appropriate shared library gets loaded.
2531    Pending breakpoints are useful to set at the start of your GDB
2532 session for locations that you know will be dynamically loaded later by
2533 the program being debugged.  When shared libraries are loaded, a check
2534 is made to see if the load resolves any pending breakpoint locations.
2535 If a pending breakpoint location gets resolved, a regular breakpoint is
2536 created and the original pending breakpoint is removed.
2538    GDB provides some additional commands for controlling pending
2539 breakpoint support:
2541 `set breakpoint pending auto'
2542      This is the default behavior.  When GDB cannot find the breakpoint
2543      location, it queries you whether a pending breakpoint should be
2544      created.
2546 `set breakpoint pending on'
2547      This indicates that an unrecognized breakpoint location should
2548      automatically result in a pending breakpoint being created.
2550 `set breakpoint pending off'
2551      This indicates that pending breakpoints are not to be created.  Any
2552      unrecognized breakpoint location results in an error.  This
2553      setting does not affect any pending breakpoints previously created.
2555 `show breakpoint pending'
2556      Show the current behavior setting for creating pending breakpoints.
2558    Normal breakpoint operations apply to pending breakpoints as well.
2559 You may specify a condition for a pending breakpoint and/or commands to
2560 run when the breakpoint is reached.  You can also enable or disable the
2561 pending breakpoint.  When you specify a condition for a pending
2562 breakpoint, the parsing of the condition will be deferred until the
2563 point where the pending breakpoint location is resolved.  Disabling a
2564 pending breakpoint tells GDB to not attempt to resolve the breakpoint
2565 on any subsequent shared library load.  When a pending breakpoint is
2566 re-enabled, GDB checks to see if the location is already resolved.
2567 This is done because any number of shared library loads could have
2568 occurred since the time the breakpoint was disabled and one or more of
2569 these loads could resolve the location.
2571    GDB itself sometimes sets breakpoints in your program for special
2572 purposes, such as proper handling of `longjmp' (in C programs).  These
2573 internal breakpoints are assigned negative numbers, starting with `-1';
2574 `info breakpoints' does not display them.  You can see these
2575 breakpoints with the GDB maintenance command `maint info breakpoints'
2576 (*note maint info breakpoints::).
2578 \x1f
2579 File: gdb.info,  Node: Set Watchpoints,  Next: Set Catchpoints,  Prev: Set Breaks,  Up: Breakpoints
2581 5.1.2 Setting watchpoints
2582 -------------------------
2584 You can use a watchpoint to stop execution whenever the value of an
2585 expression changes, without having to predict a particular place where
2586 this may happen.
2588    Depending on your system, watchpoints may be implemented in software
2589 or hardware.  GDB does software watchpointing by single-stepping your
2590 program and testing the variable's value each time, which is hundreds of
2591 times slower than normal execution.  (But this may still be worth it, to
2592 catch errors where you have no clue what part of your program is the
2593 culprit.)
2595    On some systems, such as HP-UX, GNU/Linux and most other x86-based
2596 targets, GDB includes support for hardware watchpoints, which do not
2597 slow down the running of your program.
2599 `watch EXPR'
2600      Set a watchpoint for an expression.  GDB will break when EXPR is
2601      written into by the program and its value changes.
2603 `rwatch EXPR'
2604      Set a watchpoint that will break when the value of EXPR is read by
2605      the program.
2607 `awatch EXPR'
2608      Set a watchpoint that will break when EXPR is either read from or
2609      written into by the program.
2611 `info watchpoints'
2612      This command prints a list of watchpoints, breakpoints, and
2613      catchpoints; it is the same as `info break' (*note Set Breaks::).
2615    GDB sets a "hardware watchpoint" if possible.  Hardware watchpoints
2616 execute very quickly, and the debugger reports a change in value at the
2617 exact instruction where the change occurs.  If GDB cannot set a
2618 hardware watchpoint, it sets a software watchpoint, which executes more
2619 slowly and reports the change in value at the next _statement_, not the
2620 instruction, after the change occurs.
2622    You can force GDB to use only software watchpoints with the `set
2623 can-use-hw-watchpoints 0' command.  With this variable set to zero, GDB
2624 will never try to use hardware watchpoints, even if the underlying
2625 system supports them.  (Note that hardware-assisted watchpoints that
2626 were set _before_ setting `can-use-hw-watchpoints' to zero will still
2627 use the hardware mechanism of watching expressiion values.)
2629 `set can-use-hw-watchpoints'
2630      Set whether or not to use hardware watchpoints.
2632 `show can-use-hw-watchpoints'
2633      Show the current mode of using hardware watchpoints.
2635    For remote targets, you can restrict the number of hardware
2636 watchpoints GDB will use, see *Note set remote
2637 hardware-breakpoint-limit::.
2639    When you issue the `watch' command, GDB reports
2641      Hardware watchpoint NUM: EXPR
2643 if it was able to set a hardware watchpoint.
2645    Currently, the `awatch' and `rwatch' commands can only set hardware
2646 watchpoints, because accesses to data that don't change the value of
2647 the watched expression cannot be detected without examining every
2648 instruction as it is being executed, and GDB does not do that
2649 currently.  If GDB finds that it is unable to set a hardware breakpoint
2650 with the `awatch' or `rwatch' command, it will print a message like
2651 this:
2653      Expression cannot be implemented with read/access watchpoint.
2655    Sometimes, GDB cannot set a hardware watchpoint because the data
2656 type of the watched expression is wider than what a hardware watchpoint
2657 on the target machine can handle.  For example, some systems can only
2658 watch regions that are up to 4 bytes wide; on such systems you cannot
2659 set hardware watchpoints for an expression that yields a
2660 double-precision floating-point number (which is typically 8 bytes
2661 wide).  As a work-around, it might be possible to break the large region
2662 into a series of smaller ones and watch them with separate watchpoints.
2664    If you set too many hardware watchpoints, GDB might be unable to
2665 insert all of them when you resume the execution of your program.
2666 Since the precise number of active watchpoints is unknown until such
2667 time as the program is about to be resumed, GDB might not be able to
2668 warn you about this when you set the watchpoints, and the warning will
2669 be printed only when the program is resumed:
2671      Hardware watchpoint NUM: Could not insert watchpoint
2673 If this happens, delete or disable some of the watchpoints.
2675    The SPARClite DSU will generate traps when a program accesses some
2676 data or instruction address that is assigned to the debug registers.
2677 For the data addresses, DSU facilitates the `watch' command.  However
2678 the hardware breakpoint registers can only take two data watchpoints,
2679 and both watchpoints must be the same kind.  For example, you can set
2680 two watchpoints with `watch' commands, two with `rwatch' commands, *or*
2681 two with `awatch' commands, but you cannot set one watchpoint with one
2682 command and the other with a different command.  GDB will reject the
2683 command if you try to mix watchpoints.  Delete or disable unused
2684 watchpoint commands before setting new ones.
2686    If you call a function interactively using `print' or `call', any
2687 watchpoints you have set will be inactive until GDB reaches another
2688 kind of breakpoint or the call completes.
2690    GDB automatically deletes watchpoints that watch local (automatic)
2691 variables, or expressions that involve such variables, when they go out
2692 of scope, that is, when the execution leaves the block in which these
2693 variables were defined.  In particular, when the program being debugged
2694 terminates, _all_ local variables go out of scope, and so only
2695 watchpoints that watch global variables remain set.  If you rerun the
2696 program, you will need to set all such watchpoints again.  One way of
2697 doing that would be to set a code breakpoint at the entry to the `main'
2698 function and when it breaks, set all the watchpoints.
2700      _Warning:_ In multi-thread programs, watchpoints have only limited
2701      usefulness.  With the current watchpoint implementation, GDB can
2702      only watch the value of an expression _in a single thread_.  If
2703      you are confident that the expression can only change due to the
2704      current thread's activity (and if you are also confident that no
2705      other thread can become current), then you can use watchpoints as
2706      usual.  However, GDB may not notice when a non-current thread's
2707      activity changes the expression.
2709      _HP-UX Warning:_ In multi-thread programs, software watchpoints
2710      have only limited usefulness.  If GDB creates a software
2711      watchpoint, it can only watch the value of an expression _in a
2712      single thread_.  If you are confident that the expression can only
2713      change due to the current thread's activity (and if you are also
2714      confident that no other thread can become current), then you can
2715      use software watchpoints as usual.  However, GDB may not notice
2716      when a non-current thread's activity changes the expression.
2717      (Hardware watchpoints, in contrast, watch an expression in all
2718      threads.)
2720    *Note set remote hardware-watchpoint-limit::.
2722 \x1f
2723 File: gdb.info,  Node: Set Catchpoints,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
2725 5.1.3 Setting catchpoints
2726 -------------------------
2728 You can use "catchpoints" to cause the debugger to stop for certain
2729 kinds of program events, such as C++ exceptions or the loading of a
2730 shared library.  Use the `catch' command to set a catchpoint.
2732 `catch EVENT'
2733      Stop when EVENT occurs.  EVENT can be any of the following:
2734     `throw'
2735           The throwing of a C++ exception.
2737     `catch'
2738           The catching of a C++ exception.
2740     `exec'
2741           A call to `exec'.  This is currently only available for HP-UX.
2743     `fork'
2744           A call to `fork'.  This is currently only available for HP-UX.
2746     `vfork'
2747           A call to `vfork'.  This is currently only available for
2748           HP-UX.
2750     `load'
2751     `load LIBNAME'
2752           The dynamic loading of any shared library, or the loading of
2753           the library LIBNAME.  This is currently only available for
2754           HP-UX.
2756     `unload'
2757     `unload LIBNAME'
2758           The unloading of any dynamically loaded shared library, or
2759           the unloading of the library LIBNAME.  This is currently only
2760           available for HP-UX.
2762 `tcatch EVENT'
2763      Set a catchpoint that is enabled only for one stop.  The
2764      catchpoint is automatically deleted after the first time the event
2765      is caught.
2768    Use the `info break' command to list the current catchpoints.
2770    There are currently some limitations to C++ exception handling
2771 (`catch throw' and `catch catch') in GDB:
2773    * If you call a function interactively, GDB normally returns control
2774      to you when the function has finished executing.  If the call
2775      raises an exception, however, the call may bypass the mechanism
2776      that returns control to you and cause your program either to abort
2777      or to simply continue running until it hits a breakpoint, catches
2778      a signal that GDB is listening for, or exits.  This is the case
2779      even if you set a catchpoint for the exception; catchpoints on
2780      exceptions are disabled within interactive calls.
2782    * You cannot raise an exception interactively.
2784    * You cannot install an exception handler interactively.
2786    Sometimes `catch' is not the best way to debug exception handling:
2787 if you need to know exactly where an exception is raised, it is better
2788 to stop _before_ the exception handler is called, since that way you
2789 can see the stack before any unwinding takes place.  If you set a
2790 breakpoint in an exception handler instead, it may not be easy to find
2791 out where the exception was raised.
2793    To stop just before an exception handler is called, you need some
2794 knowledge of the implementation.  In the case of GNU C++, exceptions are
2795 raised by calling a library function named `__raise_exception' which
2796 has the following ANSI C interface:
2798          /* ADDR is where the exception identifier is stored.
2799             ID is the exception identifier.  */
2800          void __raise_exception (void **addr, void *id);
2802 To make the debugger catch all exceptions before any stack unwinding
2803 takes place, set a breakpoint on `__raise_exception' (*note
2804 Breakpoints; watchpoints; and exceptions: Breakpoints.).
2806    With a conditional breakpoint (*note Break conditions: Conditions.)
2807 that depends on the value of ID, you can stop your program when a
2808 specific exception is raised.  You can use multiple conditional
2809 breakpoints to stop your program when any of a number of exceptions are
2810 raised.
2812 \x1f
2813 File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Catchpoints,  Up: Breakpoints
2815 5.1.4 Deleting breakpoints
2816 --------------------------
2818 It is often necessary to eliminate a breakpoint, watchpoint, or
2819 catchpoint once it has done its job and you no longer want your program
2820 to stop there.  This is called "deleting" the breakpoint.  A breakpoint
2821 that has been deleted no longer exists; it is forgotten.
2823    With the `clear' command you can delete breakpoints according to
2824 where they are in your program.  With the `delete' command you can
2825 delete individual breakpoints, watchpoints, or catchpoints by specifying
2826 their breakpoint numbers.
2828    It is not necessary to delete a breakpoint to proceed past it.  GDB
2829 automatically ignores breakpoints on the first instruction to be
2830 executed when you continue execution without changing the execution
2831 address.
2833 `clear'
2834      Delete any breakpoints at the next instruction to be executed in
2835      the selected stack frame (*note Selecting a frame: Selection.).
2836      When the innermost frame is selected, this is a good way to delete
2837      a breakpoint where your program just stopped.
2839 `clear FUNCTION'
2840 `clear FILENAME:FUNCTION'
2841      Delete any breakpoints set at entry to the named FUNCTION.
2843 `clear LINENUM'
2844 `clear FILENAME:LINENUM'
2845      Delete any breakpoints set at or within the code of the specified
2846      LINENUM of the specified FILENAME.
2848 `delete [breakpoints] [RANGE...]'
2849      Delete the breakpoints, watchpoints, or catchpoints of the
2850      breakpoint ranges specified as arguments.  If no argument is
2851      specified, delete all breakpoints (GDB asks confirmation, unless
2852      you have `set confirm off').  You can abbreviate this command as
2853      `d'.
2855 \x1f
2856 File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
2858 5.1.5 Disabling breakpoints
2859 ---------------------------
2861 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2862 prefer to "disable" it.  This makes the breakpoint inoperative as if it
2863 had been deleted, but remembers the information on the breakpoint so
2864 that you can "enable" it again later.
2866    You disable and enable breakpoints, watchpoints, and catchpoints with
2867 the `enable' and `disable' commands, optionally specifying one or more
2868 breakpoint numbers as arguments.  Use `info break' or `info watch' to
2869 print a list of breakpoints, watchpoints, and catchpoints if you do not
2870 know which numbers to use.
2872    A breakpoint, watchpoint, or catchpoint can have any of four
2873 different states of enablement:
2875    * Enabled.  The breakpoint stops your program.  A breakpoint set
2876      with the `break' command starts out in this state.
2878    * Disabled.  The breakpoint has no effect on your program.
2880    * Enabled once.  The breakpoint stops your program, but then becomes
2881      disabled.
2883    * Enabled for deletion.  The breakpoint stops your program, but
2884      immediately after it does so it is deleted permanently.  A
2885      breakpoint set with the `tbreak' command starts out in this state.
2887    You can use the following commands to enable or disable breakpoints,
2888 watchpoints, and catchpoints:
2890 `disable [breakpoints] [RANGE...]'
2891      Disable the specified breakpoints--or all breakpoints, if none are
2892      listed.  A disabled breakpoint has no effect but is not forgotten.
2893      All options such as ignore-counts, conditions and commands are
2894      remembered in case the breakpoint is enabled again later.  You may
2895      abbreviate `disable' as `dis'.
2897 `enable [breakpoints] [RANGE...]'
2898      Enable the specified breakpoints (or all defined breakpoints).
2899      They become effective once again in stopping your program.
2901 `enable [breakpoints] once RANGE...'
2902      Enable the specified breakpoints temporarily.  GDB disables any of
2903      these breakpoints immediately after stopping your program.
2905 `enable [breakpoints] delete RANGE...'
2906      Enable the specified breakpoints to work once, then die.  GDB
2907      deletes any of these breakpoints as soon as your program stops
2908      there.  Breakpoints set by the `tbreak' command start out in this
2909      state.
2911    Except for a breakpoint set with `tbreak' (*note Setting
2912 breakpoints: Set Breaks.), breakpoints that you set are initially
2913 enabled; subsequently, they become disabled or enabled only when you
2914 use one of the commands above.  (The command `until' can set and delete
2915 a breakpoint of its own, but it does not change the state of your other
2916 breakpoints; see *Note Continuing and stepping: Continuing and
2917 Stepping.)
2919 \x1f
2920 File: gdb.info,  Node: Conditions,  Next: Break Commands,  Prev: Disabling,  Up: Breakpoints
2922 5.1.6 Break conditions
2923 ----------------------
2925 The simplest sort of breakpoint breaks every time your program reaches a
2926 specified place.  You can also specify a "condition" for a breakpoint.
2927 A condition is just a Boolean expression in your programming language
2928 (*note Expressions: Expressions.).  A breakpoint with a condition
2929 evaluates the expression each time your program reaches it, and your
2930 program stops only if the condition is _true_.
2932    This is the converse of using assertions for program validation; in
2933 that situation, you want to stop when the assertion is violated--that
2934 is, when the condition is false.  In C, if you want to test an
2935 assertion expressed by the condition ASSERT, you should set the
2936 condition `! ASSERT' on the appropriate breakpoint.
2938    Conditions are also accepted for watchpoints; you may not need them,
2939 since a watchpoint is inspecting the value of an expression anyhow--but
2940 it might be simpler, say, to just set a watchpoint on a variable name,
2941 and specify a condition that tests whether the new value is an
2942 interesting one.
2944    Break conditions can have side effects, and may even call functions
2945 in your program.  This can be useful, for example, to activate functions
2946 that log program progress, or to use your own print functions to format
2947 special data structures. The effects are completely predictable unless
2948 there is another enabled breakpoint at the same address.  (In that
2949 case, GDB might see the other breakpoint first and stop your program
2950 without checking the condition of this one.)  Note that breakpoint
2951 commands are usually more convenient and flexible than break conditions
2952 for the purpose of performing side effects when a breakpoint is reached
2953 (*note Breakpoint command lists: Break Commands.).
2955    Break conditions can be specified when a breakpoint is set, by using
2956 `if' in the arguments to the `break' command.  *Note Setting
2957 breakpoints: Set Breaks.  They can also be changed at any time with the
2958 `condition' command.
2960    You can also use the `if' keyword with the `watch' command.  The
2961 `catch' command does not recognize the `if' keyword; `condition' is the
2962 only way to impose a further condition on a catchpoint.
2964 `condition BNUM EXPRESSION'
2965      Specify EXPRESSION as the break condition for breakpoint,
2966      watchpoint, or catchpoint number BNUM.  After you set a condition,
2967      breakpoint BNUM stops your program only if the value of EXPRESSION
2968      is true (nonzero, in C).  When you use `condition', GDB checks
2969      EXPRESSION immediately for syntactic correctness, and to determine
2970      whether symbols in it have referents in the context of your
2971      breakpoint.  If EXPRESSION uses symbols not referenced in the
2972      context of the breakpoint, GDB prints an error message:
2974           No symbol "foo" in current context.
2976      GDB does not actually evaluate EXPRESSION at the time the
2977      `condition' command (or a command that sets a breakpoint with a
2978      condition, like `break if ...') is given, however.  *Note
2979      Expressions: Expressions.
2981 `condition BNUM'
2982      Remove the condition from breakpoint number BNUM.  It becomes an
2983      ordinary unconditional breakpoint.
2985    A special case of a breakpoint condition is to stop only when the
2986 breakpoint has been reached a certain number of times.  This is so
2987 useful that there is a special way to do it, using the "ignore count"
2988 of the breakpoint.  Every breakpoint has an ignore count, which is an
2989 integer.  Most of the time, the ignore count is zero, and therefore has
2990 no effect.  But if your program reaches a breakpoint whose ignore count
2991 is positive, then instead of stopping, it just decrements the ignore
2992 count by one and continues.  As a result, if the ignore count value is
2993 N, the breakpoint does not stop the next N times your program reaches
2996 `ignore BNUM COUNT'
2997      Set the ignore count of breakpoint number BNUM to COUNT.  The next
2998      COUNT times the breakpoint is reached, your program's execution
2999      does not stop; other than to decrement the ignore count, GDB takes
3000      no action.
3002      To make the breakpoint stop the next time it is reached, specify a
3003      count of zero.
3005      When you use `continue' to resume execution of your program from a
3006      breakpoint, you can specify an ignore count directly as an
3007      argument to `continue', rather than using `ignore'.  *Note
3008      Continuing and stepping: Continuing and Stepping.
3010      If a breakpoint has a positive ignore count and a condition, the
3011      condition is not checked.  Once the ignore count reaches zero, GDB
3012      resumes checking the condition.
3014      You could achieve the effect of the ignore count with a condition
3015      such as `$foo-- <= 0' using a debugger convenience variable that
3016      is decremented each time.  *Note Convenience variables:
3017      Convenience Vars.
3019    Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3021 \x1f
3022 File: gdb.info,  Node: Break Commands,  Next: Breakpoint Menus,  Prev: Conditions,  Up: Breakpoints
3024 5.1.7 Breakpoint command lists
3025 ------------------------------
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.
3032 `commands [BNUM]'
3033 `... COMMAND-LIST ...'
3034 `end'
3035      Specify a list of commands for breakpoint number BNUM.  The
3036      commands themselves appear on the following lines.  Type a line
3037      containing just `end' to terminate the commands.
3039      To remove all commands from a breakpoint, type `commands' and
3040      follow it immediately with `end'; that is, give no commands.
3042      With no BNUM argument, `commands' refers to the last breakpoint,
3043      watchpoint, or catchpoint set (not to the breakpoint most recently
3044      encountered).
3046    Pressing <RET> as a means of repeating the last GDB command is
3047 disabled within a COMMAND-LIST.
3049    You can use breakpoint commands to start your program up again.
3050 Simply use the `continue' command, or `step', or any other command that
3051 resumes execution.
3053    Any other commands in the command list, after a command that resumes
3054 execution, are ignored.  This is because any time you resume execution
3055 (even with a simple `next' or `step'), you may encounter another
3056 breakpoint--which could have its own command list, leading to
3057 ambiguities about which list to execute.
3059    If the first command you specify in a command list is `silent', the
3060 usual message about stopping at a breakpoint is not printed.  This may
3061 be desirable for breakpoints that are to print a specific message and
3062 then continue.  If none of the remaining commands print anything, you
3063 see no sign that the breakpoint was reached.  `silent' is meaningful
3064 only at the beginning of a breakpoint command list.
3066    The commands `echo', `output', and `printf' allow you to print
3067 precisely controlled output, and are often useful in silent
3068 breakpoints.  *Note Commands for controlled output: Output.
3070    For example, here is how you could use breakpoint commands to print
3071 the value of `x' at entry to `foo' whenever `x' is positive.
3073      break foo if x>0
3074      commands
3075      silent
3076      printf "x is %d\n",x
3077      cont
3078      end
3080    One application for breakpoint commands is to compensate for one bug
3081 so you can test for another.  Put a breakpoint just after the erroneous
3082 line of code, give it a condition to detect the case in which something
3083 erroneous has been done, and give it commands to assign correct values
3084 to any variables that need them.  End with the `continue' command so
3085 that your program does not stop, and start with the `silent' command so
3086 that no output is produced.  Here is an example:
3088      break 403
3089      commands
3090      silent
3091      set x = y + 4
3092      cont
3093      end
3095 \x1f
3096 File: gdb.info,  Node: Breakpoint Menus,  Next: Error in Breakpoints,  Prev: Break Commands,  Up: Breakpoints
3098 5.1.8 Breakpoint menus
3099 ----------------------
3101 Some programming languages (notably C++ and Objective-C) permit a
3102 single function name to be defined several times, for application in
3103 different contexts.  This is called "overloading".  When a function
3104 name is overloaded, `break FUNCTION' is not enough to tell GDB where
3105 you want a breakpoint.  If you realize this is a problem, you can use
3106 something like `break FUNCTION(TYPES)' to specify which particular
3107 version of the function you want.  Otherwise, GDB offers you a menu of
3108 numbered choices for different possible breakpoints, and waits for your
3109 selection with the prompt `>'.  The first two options are always `[0]
3110 cancel' and `[1] all'.  Typing `1' sets a breakpoint at each definition
3111 of FUNCTION, and typing `0' aborts the `break' command without setting
3112 any new breakpoints.
3114    For example, the following session excerpt shows an attempt to set a
3115 breakpoint at the overloaded symbol `String::after'.  We choose three
3116 particular definitions of that function name:
3118      (gdb) b String::after
3119      [0] cancel
3120      [1] all
3121      [2] file:String.cc; line number:867
3122      [3] file:String.cc; line number:860
3123      [4] file:String.cc; line number:875
3124      [5] file:String.cc; line number:853
3125      [6] file:String.cc; line number:846
3126      [7] file:String.cc; line number:735
3127      > 2 4 6
3128      Breakpoint 1 at 0xb26c: file String.cc, line 867.
3129      Breakpoint 2 at 0xb344: file String.cc, line 875.
3130      Breakpoint 3 at 0xafcc: file String.cc, line 846.
3131      Multiple breakpoints were set.
3132      Use the "delete" command to delete unwanted
3133       breakpoints.
3134      (gdb)
3136 \x1f
3137 File: gdb.info,  Node: Error in Breakpoints,  Next: Breakpoint related warnings,  Prev: Breakpoint Menus,  Up: Breakpoints
3139 5.1.9 "Cannot insert breakpoints"
3140 ---------------------------------
3142 Under some operating systems, breakpoints cannot be used in a program if
3143 any other process is running that program.  In this situation,
3144 attempting to run or continue a program with a breakpoint causes GDB to
3145 print an error message:
3147      Cannot insert breakpoints.
3148      The same program may be running in another process.
3150    When this happens, you have three ways to proceed:
3152   1. Remove or disable the breakpoints, then continue.
3154   2. Suspend GDB, and copy the file containing your program to a new
3155      name.  Resume GDB and use the `exec-file' command to specify that
3156      GDB should run your program under that name.  Then start your
3157      program again.
3159   3. Relink your program so that the text segment is nonsharable, using
3160      the linker option `-N'.  The operating system limitation may not
3161      apply to nonsharable executables.
3163    A similar message can be printed if you request too many active
3164 hardware-assisted breakpoints and watchpoints:
3166      Stopped; cannot insert breakpoints.
3167      You may have requested too many hardware breakpoints and watchpoints.
3169 This message is printed when you attempt to resume the program, since
3170 only then GDB knows exactly how many hardware breakpoints and
3171 watchpoints it needs to insert.
3173    When this message is printed, you need to disable or remove some of
3174 the hardware-assisted breakpoints and watchpoints, and then continue.
3176 \x1f
3177 File: gdb.info,  Node: Breakpoint related warnings,  Prev: Error in Breakpoints,  Up: Breakpoints
3179 5.1.10 "Breakpoint address adjusted..."
3180 ---------------------------------------
3182 Some processor architectures place constraints on the addresses at
3183 which breakpoints may be placed.  For architectures thus constrained,
3184 GDB will attempt to adjust the breakpoint's address to comply with the
3185 constraints dictated by the architecture.
3187    One example of such an architecture is the Fujitsu FR-V.  The FR-V is
3188 a VLIW architecture in which a number of RISC-like instructions may be
3189 bundled together for parallel execution.  The FR-V architecture
3190 constrains the location of a breakpoint instruction within such a
3191 bundle to the instruction with the lowest address.  GDB honors this
3192 constraint by adjusting a breakpoint's address to the first in the
3193 bundle.
3195    It is not uncommon for optimized code to have bundles which contain
3196 instructions from different source statements, thus it may happen that
3197 a breakpoint's address will be adjusted from one source statement to
3198 another.  Since this adjustment may significantly alter GDB's
3199 breakpoint related behavior from what the user expects, a warning is
3200 printed when the breakpoint is first set and also when the breakpoint
3201 is hit.
3203    A warning like the one below is printed when setting a breakpoint
3204 that's been subject to address adjustment:
3206      warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3208    Such warnings are printed both for user settable and GDB's internal
3209 breakpoints.  If you see one of these warnings, you should verify that
3210 a breakpoint set at the adjusted address will have the desired affect.
3211 If not, the breakpoint in question may be removed and other breakpoints
3212 may be set which will have the desired behavior.  E.g., it may be
3213 sufficient to place the breakpoint at a later instruction.  A
3214 conditional breakpoint may also be useful in some cases to prevent the
3215 breakpoint from triggering too often.
3217    GDB will also issue a warning when stopping at one of these adjusted
3218 breakpoints:
3220      warning: Breakpoint 1 address previously adjusted from 0x00010414
3221      to 0x00010410.
3223    When this warning is encountered, it may be too late to take remedial
3224 action except in cases where the breakpoint is hit earlier or more
3225 frequently than expected.
3227 \x1f
3228 File: gdb.info,  Node: Continuing and Stepping,  Next: Signals,  Prev: Breakpoints,  Up: Stopping
3230 5.2 Continuing and stepping
3231 ===========================
3233 "Continuing" means resuming program execution until your program
3234 completes normally.  In contrast, "stepping" means executing just one
3235 more "step" of your program, where "step" may mean either one line of
3236 source code, or one machine instruction (depending on what particular
3237 command you use).  Either when continuing or when stepping, your
3238 program may stop even sooner, due to a breakpoint or a signal.  (If it
3239 stops due to a signal, you may want to use `handle', or use `signal 0'
3240 to resume execution.  *Note Signals: Signals.)
3242 `continue [IGNORE-COUNT]'
3243 `c [IGNORE-COUNT]'
3244 `fg [IGNORE-COUNT]'
3245      Resume program execution, at the address where your program last
3246      stopped; any breakpoints set at that address are bypassed.  The
3247      optional argument IGNORE-COUNT allows you to specify a further
3248      number of times to ignore a breakpoint at this location; its
3249      effect is like that of `ignore' (*note Break conditions:
3250      Conditions.).
3252      The argument IGNORE-COUNT is meaningful only when your program
3253      stopped due to a breakpoint.  At other times, the argument to
3254      `continue' is ignored.
3256      The synonyms `c' and `fg' (for "foreground", as the debugged
3257      program is deemed to be the foreground program) are provided
3258      purely for convenience, and have exactly the same behavior as
3259      `continue'.
3261    To resume execution at a different place, you can use `return'
3262 (*note Returning from a function: Returning.) to go back to the calling
3263 function; or `jump' (*note Continuing at a different address: Jumping.)
3264 to go to an arbitrary location in your program.
3266    A typical technique for using stepping is to set a breakpoint (*note
3267 Breakpoints; watchpoints; and catchpoints: Breakpoints.) at the
3268 beginning of the function or the section of your program where a problem
3269 is believed to lie, run your program until it stops at that breakpoint,
3270 and then step through the suspect area, examining the variables that are
3271 interesting, until you see the problem happen.
3273 `step'
3274      Continue running your program until control reaches a different
3275      source line, then stop it and return control to GDB.  This command
3276      is abbreviated `s'.
3278           _Warning:_ If you use the `step' command while control is
3279           within a function that was compiled without debugging
3280           information, execution proceeds until control reaches a
3281           function that does have debugging information.  Likewise, it
3282           will not step into a function which is compiled without
3283           debugging information.  To step through functions without
3284           debugging information, use the `stepi' command, described
3285           below.
3287      The `step' command only stops at the first instruction of a source
3288      line.  This prevents the multiple stops that could otherwise occur
3289      in `switch' statements, `for' loops, etc.  `step' continues to
3290      stop if a function that has debugging information is called within
3291      the line.  In other words, `step' _steps inside_ any functions
3292      called within the line.
3294      Also, the `step' command only enters a function if there is line
3295      number information for the function.  Otherwise it acts like the
3296      `next' command.  This avoids problems when using `cc -gl' on MIPS
3297      machines.  Previously, `step' entered subroutines if there was any
3298      debugging information about the routine.
3300 `step COUNT'
3301      Continue running as in `step', but do so COUNT times.  If a
3302      breakpoint is reached, or a signal not related to stepping occurs
3303      before COUNT steps, stepping stops right away.
3305 `next [COUNT]'
3306      Continue to the next source line in the current (innermost) stack
3307      frame.  This is similar to `step', but function calls that appear
3308      within the line of code are executed without stopping.  Execution
3309      stops when control reaches a different line of code at the
3310      original stack level that was executing when you gave the `next'
3311      command.  This command is abbreviated `n'.
3313      An argument COUNT is a repeat count, as for `step'.
3315      The `next' command only stops at the first instruction of a source
3316      line.  This prevents multiple stops that could otherwise occur in
3317      `switch' statements, `for' loops, etc.
3319 `set step-mode'
3320 `set step-mode on'
3321      The `set step-mode on' command causes the `step' command to stop
3322      at the first instruction of a function which contains no debug line
3323      information rather than stepping over it.
3325      This is useful in cases where you may be interested in inspecting
3326      the machine instructions of a function which has no symbolic info
3327      and do not want GDB to automatically skip over this function.
3329 `set step-mode off'
3330      Causes the `step' command to step over any functions which
3331      contains no debug information.  This is the default.
3333 `show step-mode'
3334      Show whether GDB will stop in or step over functions without
3335      source line debug information.
3337 `finish'
3338      Continue running until just after function in the selected stack
3339      frame returns.  Print the returned value (if any).
3341      Contrast this with the `return' command (*note Returning from a
3342      function: Returning.).
3344 `until'
3346      Continue running until a source line past the current line, in the
3347      current stack frame, is reached.  This command is used to avoid
3348      single stepping through a loop more than once.  It is like the
3349      `next' command, except that when `until' encounters a jump, it
3350      automatically continues execution until the program counter is
3351      greater than the address of the jump.
3353      This means that when you reach the end of a loop after single
3354      stepping though it, `until' makes your program continue execution
3355      until it exits the loop.  In contrast, a `next' command at the end
3356      of a loop simply steps back to the beginning of the loop, which
3357      forces you to step through the next iteration.
3359      `until' always stops your program if it attempts to exit the
3360      current stack frame.
3362      `until' may produce somewhat counterintuitive results if the order
3363      of machine code does not match the order of the source lines.  For
3364      example, in the following excerpt from a debugging session, the `f'
3365      (`frame') command shows that execution is stopped at line `206';
3366      yet when we use `until', we get to line `195':
3368           (gdb) f
3369           #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
3370           206                 expand_input();
3371           (gdb) until
3372           195             for ( ; argc > 0; NEXTARG) {
3374      This happened because, for execution efficiency, the compiler had
3375      generated code for the loop closure test at the end, rather than
3376      the start, of the loop--even though the test in a C `for'-loop is
3377      written before the body of the loop.  The `until' command appeared
3378      to step back to the beginning of the loop when it advanced to this
3379      expression; however, it has not really gone to an earlier
3380      statement--not in terms of the actual machine code.
3382      `until' with no argument works by means of single instruction
3383      stepping, and hence is slower than `until' with an argument.
3385 `until LOCATION'
3386 `u LOCATION'
3387      Continue running your program until either the specified location
3388      is reached, or the current stack frame returns.  LOCATION is any of
3389      the forms of argument acceptable to `break' (*note Setting
3390      breakpoints: Set Breaks.).  This form of the command uses
3391      breakpoints, and hence is quicker than `until' without an
3392      argument.  The specified location is actually reached only if it
3393      is in the current frame.  This implies that `until' can be used to
3394      skip over recursive function invocations.  For instance in the
3395      code below, if the current location is line `96', issuing `until
3396      99' will execute the program up to line `99' in the same
3397      invocation of factorial, i.e. after the inner invocations have
3398      returned.
3400           94    int factorial (int value)
3401           95    {
3402           96        if (value > 1) {
3403           97            value *= factorial (value - 1);
3404           98        }
3405           99        return (value);
3406           100     }
3408 `advance LOCATION'
3409      Continue running the program up to the given LOCATION.  An
3410      argument is required, which should be of the same form as
3411      arguments for the `break' command.  Execution will also stop upon
3412      exit from the current stack frame.  This command is similar to
3413      `until', but `advance' will not skip over recursive function
3414      calls, and the target location doesn't have to be in the same
3415      frame as the current one.
3417 `stepi'
3418 `stepi ARG'
3419 `si'
3420      Execute one machine instruction, then stop and return to the
3421      debugger.
3423      It is often useful to do `display/i $pc' when stepping by machine
3424      instructions.  This makes GDB automatically display the next
3425      instruction to be executed, each time your program stops.  *Note
3426      Automatic display: Auto Display.
3428      An argument is a repeat count, as in `step'.
3430 `nexti'
3431 `nexti ARG'
3432 `ni'
3433      Execute one machine instruction, but if it is a function call,
3434      proceed until the function returns.
3436      An argument is a repeat count, as in `next'.
3438 \x1f
3439 File: gdb.info,  Node: Signals,  Next: Thread Stops,  Prev: Continuing and Stepping,  Up: Stopping
3441 5.3 Signals
3442 ===========
3444 A signal is an asynchronous event that can happen in a program.  The
3445 operating system defines the possible kinds of signals, and gives each
3446 kind a name and a number.  For example, in Unix `SIGINT' is the signal
3447 a program gets when you type an interrupt character (often `C-c');
3448 `SIGSEGV' is the signal a program gets from referencing a place in
3449 memory far away from all the areas in use; `SIGALRM' occurs when the
3450 alarm clock timer goes off (which happens only if your program has
3451 requested an alarm).
3453    Some signals, including `SIGALRM', are a normal part of the
3454 functioning of your program.  Others, such as `SIGSEGV', indicate
3455 errors; these signals are "fatal" (they kill your program immediately)
3456 if the program has not specified in advance some other way to handle
3457 the signal.  `SIGINT' does not indicate an error in your program, but
3458 it is normally fatal so it can carry out the purpose of the interrupt:
3459 to kill the program.
3461    GDB has the ability to detect any occurrence of a signal in your
3462 program.  You can tell GDB in advance what to do for each kind of
3463 signal.
3465    Normally, GDB is set up to let the non-erroneous signals like
3466 `SIGALRM' be silently passed to your program (so as not to interfere
3467 with their role in the program's functioning) but to stop your program
3468 immediately whenever an error signal happens.  You can change these
3469 settings with the `handle' command.
3471 `info signals'
3472 `info handle'
3473      Print a table of all the kinds of signals and how GDB has been
3474      told to handle each one.  You can use this to see the signal
3475      numbers of all the defined types of signals.
3477      `info handle' is an alias for `info signals'.
3479 `handle SIGNAL KEYWORDS...'
3480      Change the way GDB handles signal SIGNAL.  SIGNAL can be the
3481      number of a signal or its name (with or without the `SIG' at the
3482      beginning); a list of signal numbers of the form `LOW-HIGH'; or
3483      the word `all', meaning all the known signals.  The KEYWORDS say
3484      what change to make.
3486    The keywords allowed by the `handle' command can be abbreviated.
3487 Their full names are:
3489 `nostop'
3490      GDB should not stop your program when this signal happens.  It may
3491      still print a message telling you that the signal has come in.
3493 `stop'
3494      GDB should stop your program when this signal happens.  This
3495      implies the `print' keyword as well.
3497 `print'
3498      GDB should print a message when this signal happens.
3500 `noprint'
3501      GDB should not mention the occurrence of the signal at all.  This
3502      implies the `nostop' keyword as well.
3504 `pass'
3505 `noignore'
3506      GDB should allow your program to see this signal; your program can
3507      handle the signal, or else it may terminate if the signal is fatal
3508      and not handled.  `pass' and `noignore' are synonyms.
3510 `nopass'
3511 `ignore'
3512      GDB should not allow your program to see this signal.  `nopass'
3513      and `ignore' are synonyms.
3515    When a signal stops your program, the signal is not visible to the
3516 program until you continue.  Your program sees the signal then, if
3517 `pass' is in effect for the signal in question _at that time_.  In
3518 other words, after GDB reports a signal, you can use the `handle'
3519 command with `pass' or `nopass' to control whether your program sees
3520 that signal when you continue.
3522    The default is set to `nostop', `noprint', `pass' for non-erroneous
3523 signals such as `SIGALRM', `SIGWINCH' and `SIGCHLD', and to `stop',
3524 `print', `pass' for the erroneous signals.
3526    You can also use the `signal' command to prevent your program from
3527 seeing a signal, or cause it to see a signal it normally would not see,
3528 or to give it any signal at any time.  For example, if your program
3529 stopped due to some sort of memory reference error, you might store
3530 correct values into the erroneous variables and continue, hoping to see
3531 more execution; but your program would probably terminate immediately as
3532 a result of the fatal signal once it saw the signal.  To prevent this,
3533 you can continue with `signal 0'.  *Note Giving your program a signal:
3534 Signaling.
3536 \x1f
3537 File: gdb.info,  Node: Thread Stops,  Prev: Signals,  Up: Stopping
3539 5.4 Stopping and starting multi-thread programs
3540 ===============================================
3542 When your program has multiple threads (*note Debugging programs with
3543 multiple threads: Threads.), you can choose whether to set breakpoints
3544 on all threads, or on a particular thread.
3546 `break LINESPEC thread THREADNO'
3547 `break LINESPEC thread THREADNO if ...'
3548      LINESPEC specifies source lines; there are several ways of writing
3549      them, but the effect is always to specify some source line.
3551      Use the qualifier `thread THREADNO' with a breakpoint command to
3552      specify that you only want GDB to stop the program when a
3553      particular thread reaches this breakpoint.  THREADNO is one of the
3554      numeric thread identifiers assigned by GDB, shown in the first
3555      column of the `info threads' display.
3557      If you do not specify `thread THREADNO' when you set a breakpoint,
3558      the breakpoint applies to _all_ threads of your program.
3560      You can use the `thread' qualifier on conditional breakpoints as
3561      well; in this case, place `thread THREADNO' before the breakpoint
3562      condition, like this:
3564           (gdb) break frik.c:13 thread 28 if bartab > lim
3567    Whenever your program stops under GDB for any reason, _all_ threads
3568 of execution stop, not just the current thread.  This allows you to
3569 examine the overall state of the program, including switching between
3570 threads, without worrying that things may change underfoot.
3572    There is an unfortunate side effect.  If one thread stops for a
3573 breakpoint, or for some other reason, and another thread is blocked in a
3574 system call, then the system call may return prematurely.  This is a
3575 consequence of the interaction between multiple threads and the signals
3576 that GDB uses to implement breakpoints and other events that stop
3577 execution.
3579    To handle this problem, your program should check the return value of
3580 each system call and react appropriately.  This is good programming
3581 style anyways.
3583    For example, do not write code like this:
3585        sleep (10);
3587    The call to `sleep' will return early if a different thread stops at
3588 a breakpoint or for some other reason.
3590    Instead, write this:
3592        int unslept = 10;
3593        while (unslept > 0)
3594          unslept = sleep (unslept);
3596    A system call is allowed to return early, so the system is still
3597 conforming to its specification.  But GDB does cause your
3598 multi-threaded program to behave differently than it would without GDB.
3600    Also, GDB uses internal breakpoints in the thread library to monitor
3601 certain events such as thread creation and thread destruction.  When
3602 such an event happens, a system call in another thread may return
3603 prematurely, even though your program does not appear to stop.
3605    Conversely, whenever you restart the program, _all_ threads start
3606 executing.  _This is true even when single-stepping_ with commands like
3607 `step' or `next'.
3609    In particular, GDB cannot single-step all threads in lockstep.
3610 Since thread scheduling is up to your debugging target's operating
3611 system (not controlled by GDB), other threads may execute more than one
3612 statement while the current thread completes a single step.  Moreover,
3613 in general other threads stop in the middle of a statement, rather than
3614 at a clean statement boundary, when the program stops.
3616    You might even find your program stopped in another thread after
3617 continuing or even single-stepping.  This happens whenever some other
3618 thread runs into a breakpoint, a signal, or an exception before the
3619 first thread completes whatever you requested.
3621    On some OSes, you can lock the OS scheduler and thus allow only a
3622 single thread to run.
3624 `set scheduler-locking MODE'
3625      Set the scheduler locking mode.  If it is `off', then there is no
3626      locking and any thread may run at any time.  If `on', then only the
3627      current thread may run when the inferior is resumed.  The `step'
3628      mode optimizes for single-stepping.  It stops other threads from
3629      "seizing the prompt" by preempting the current thread while you are
3630      stepping.  Other threads will only rarely (or never) get a chance
3631      to run when you step.  They are more likely to run when you `next'
3632      over a function call, and they are completely free to run when you
3633      use commands like `continue', `until', or `finish'.  However,
3634      unless another thread hits a breakpoint during its timeslice, they
3635      will never steal the GDB prompt away from the thread that you are
3636      debugging.
3638 `show scheduler-locking'
3639      Display the current scheduler locking mode.
3641 \x1f
3642 File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
3644 6 Examining the Stack
3645 *********************
3647 When your program has stopped, the first thing you need to know is
3648 where it stopped and how it got there.
3650    Each time your program performs a function call, information about
3651 the call is generated.  That information includes the location of the
3652 call in your program, the arguments of the call, and the local
3653 variables of the function being called.  The information is saved in a
3654 block of data called a "stack frame".  The stack frames are allocated
3655 in a region of memory called the "call stack".
3657    When your program stops, the GDB commands for examining the stack
3658 allow you to see all of this information.
3660    One of the stack frames is "selected" by GDB and many GDB commands
3661 refer implicitly to the selected frame.  In particular, whenever you
3662 ask GDB for the value of a variable in your program, the value is found
3663 in the selected frame.  There are special GDB commands to select
3664 whichever frame you are interested in. *Note Selecting a frame:
3665 Selection.
3667    When your program stops, GDB automatically selects the currently
3668 executing frame and describes it briefly, similar to the `frame'
3669 command (*note Information about a frame: Frame Info.).
3671 * Menu:
3673 * Frames::                      Stack frames
3674 * Backtrace::                   Backtraces
3675 * Selection::                   Selecting a frame
3676 * Frame Info::                  Information on a frame
3678 \x1f
3679 File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
3681 6.1 Stack frames
3682 ================
3684 The call stack is divided up into contiguous pieces called "stack
3685 frames", or "frames" for short; each frame is the data associated with
3686 one call to one function.  The frame contains the arguments given to
3687 the function, the function's local variables, and the address at which
3688 the function is executing.
3690    When your program is started, the stack has only one frame, that of
3691 the function `main'.  This is called the "initial" frame or the
3692 "outermost" frame.  Each time a function is called, a new frame is
3693 made.  Each time a function returns, the frame for that function
3694 invocation is eliminated.  If a function is recursive, there can be
3695 many frames for the same function.  The frame for the function in which
3696 execution is actually occurring is called the "innermost" frame.  This
3697 is the most recently created of all the stack frames that still exist.
3699    Inside your program, stack frames are identified by their addresses.
3700 A stack frame consists of many bytes, each of which has its own
3701 address; each kind of computer has a convention for choosing one byte
3702 whose address serves as the address of the frame.  Usually this address
3703 is kept in a register called the "frame pointer register" (*note $fp:
3704 Registers.) while execution is going on in that frame.
3706    GDB assigns numbers to all existing stack frames, starting with zero
3707 for the innermost frame, one for the frame that called it, and so on
3708 upward.  These numbers do not really exist in your program; they are
3709 assigned by GDB to give you a way of designating stack frames in GDB
3710 commands.
3712    Some compilers provide a way to compile functions so that they
3713 operate without stack frames.  (For example, the gcc option
3714      `-fomit-frame-pointer'
3715    generates functions without a frame.)  This is occasionally done
3716 with heavily used library functions to save the frame setup time.  GDB
3717 has limited facilities for dealing with these function invocations.  If
3718 the innermost function invocation has no stack frame, GDB nevertheless
3719 regards it as though it had a separate frame, which is numbered zero as
3720 usual, allowing correct tracing of the function call chain.  However,
3721 GDB has no provision for frameless functions elsewhere in the stack.
3723 `frame ARGS'
3724      The `frame' command allows you to move from one stack frame to
3725      another, and to print the stack frame you select.  ARGS may be
3726      either the address of the frame or the stack frame number.
3727      Without an argument, `frame' prints the current stack frame.
3729 `select-frame'
3730      The `select-frame' command allows you to move from one stack frame
3731      to another without printing the frame.  This is the silent version
3732      of `frame'.
3734 \x1f
3735 File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
3737 6.2 Backtraces
3738 ==============
3740 A backtrace is a summary of how your program got where it is.  It shows
3741 one line per frame, for many frames, starting with the currently
3742 executing frame (frame zero), followed by its caller (frame one), and
3743 on up the stack.
3745 `backtrace'
3746 `bt'
3747      Print a backtrace of the entire stack: one line per frame for all
3748      frames in the stack.
3750      You can stop the backtrace at any time by typing the system
3751      interrupt character, normally `C-c'.
3753 `backtrace N'
3754 `bt N'
3755      Similar, but print only the innermost N frames.
3757 `backtrace -N'
3758 `bt -N'
3759      Similar, but print only the outermost N frames.
3761 `backtrace full'
3762      Print the values of the local variables also.
3764 `bt full'
3766    The names `where' and `info stack' (abbreviated `info s') are
3767 additional aliases for `backtrace'.
3769    In a multi-threaded program, GDB by default shows the backtrace only
3770 for the current thread.  To display the backtrace for several or all of
3771 the threads, use the command `thread apply' (*note thread apply:
3772 Threads.).  For example, if you type `thread apply all backtrace', GDB
3773 will display the backtrace for all the threads; this is handy when you
3774 debug a core dump of a multi-threaded program.
3776    Each line in the backtrace shows the frame number and the function
3777 name.  The program counter value is also shown--unless you use `set
3778 print address off'.  The backtrace also shows the source file name and
3779 line number, as well as the arguments to the function.  The program
3780 counter value is omitted if it is at the beginning of the code for that
3781 line number.
3783    Here is an example of a backtrace.  It was made with the command `bt
3784 3', so it shows the innermost three frames.
3786      #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3787          at builtin.c:993
3788      #1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3789      #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3790          at macro.c:71
3791      (More stack frames follow...)
3793 The display for frame zero does not begin with a program counter value,
3794 indicating that your program has stopped at the beginning of the code
3795 for line `993' of `builtin.c'.
3797    If your program was compiled with optimizations, some compilers will
3798 optimize away arguments passed to functions if those arguments are
3799 never used after the call.  Such optimizations generate code that
3800 passes arguments through registers, but doesn't store those arguments
3801 in the stack frame.  GDB has no way of displaying such arguments in
3802 stack frames other than the innermost one.  Here's what such a
3803 backtrace might look like:
3805      #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3806          at builtin.c:993
3807      #1  0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
3808      #2  0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
3809          at macro.c:71
3810      (More stack frames follow...)
3812 The values of arguments that were not saved in their stack frames are
3813 shown as `<value optimized out>'.
3815    If you need to display the values of such optimized-out arguments,
3816 either deduce that from other variables whose values depend on the one
3817 you are interested in, or recompile without optimizations.
3819    Most programs have a standard user entry point--a place where system
3820 libraries and startup code transition into user code.  For C this is
3821 `main'(1).  When GDB finds the entry function in a backtrace it will
3822 terminate the backtrace, to avoid tracing into highly system-specific
3823 (and generally uninteresting) code.
3825    If you need to examine the startup code, or limit the number of
3826 levels in a backtrace, you can change this behavior:
3828 `set backtrace past-main'
3829 `set backtrace past-main on'
3830      Backtraces will continue past the user entry point.
3832 `set backtrace past-main off'
3833      Backtraces will stop when they encounter the user entry point.
3834      This is the default.
3836 `show backtrace past-main'
3837      Display the current user entry point backtrace policy.
3839 `set backtrace past-entry'
3840 `set backtrace past-entry on'
3841      Backtraces will continue past the internal entry point of an
3842      application.  This entry point is encoded by the linker when the
3843      application is built, and is likely before the user entry point
3844      `main' (or equivalent) is called.
3846 `set backtrace past-entry off'
3847      Backtraces will stop when they encouter the internal entry point
3848      of an application.  This is the default.
3850 `show backtrace past-entry'
3851      Display the current internal entry point backtrace policy.
3853 `set backtrace limit N'
3854 `set backtrace limit 0'
3855      Limit the backtrace to N levels.  A value of zero means unlimited.
3857 `show backtrace limit'
3858      Display the current limit on backtrace levels.
3860    ---------- Footnotes ----------
3862    (1) Note that embedded programs (the so-called "free-standing"
3863 environment) are not required to have a `main' function as the entry
3864 point.  They could even have multiple entry points.
3866 \x1f
3867 File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
3869 6.3 Selecting a frame
3870 =====================
3872 Most commands for examining the stack and other data in your program
3873 work on whichever stack frame is selected at the moment.  Here are the
3874 commands for selecting a stack frame; all of them finish by printing a
3875 brief description of the stack frame just selected.
3877 `frame N'
3878 `f N'
3879      Select frame number N.  Recall that frame zero is the innermost
3880      (currently executing) frame, frame one is the frame that called the
3881      innermost one, and so on.  The highest-numbered frame is the one
3882      for `main'.
3884 `frame ADDR'
3885 `f ADDR'
3886      Select the frame at address ADDR.  This is useful mainly if the
3887      chaining of stack frames has been damaged by a bug, making it
3888      impossible for GDB to assign numbers properly to all frames.  In
3889      addition, this can be useful when your program has multiple stacks
3890      and switches between them.
3892      On the SPARC architecture, `frame' needs two addresses to select
3893      an arbitrary frame: a frame pointer and a stack pointer.
3895      On the MIPS and Alpha architecture, it needs two addresses: a stack
3896      pointer and a program counter.
3898      On the 29k architecture, it needs three addresses: a register stack
3899      pointer, a program counter, and a memory stack pointer.
3901 `up N'
3902      Move N frames up the stack.  For positive numbers N, this advances
3903      toward the outermost frame, to higher frame numbers, to frames
3904      that have existed longer.  N defaults to one.
3906 `down N'
3907      Move N frames down the stack.  For positive numbers N, this
3908      advances toward the innermost frame, to lower frame numbers, to
3909      frames that were created more recently.  N defaults to one.  You
3910      may abbreviate `down' as `do'.
3912    All of these commands end by printing two lines of output describing
3913 the frame.  The first line shows the frame number, the function name,
3914 the arguments, and the source file and line number of execution in that
3915 frame.  The second line shows the text of that source line.
3917    For example:
3919      (gdb) up
3920      #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3921          at env.c:10
3922      10              read_input_file (argv[i]);
3924    After such a printout, the `list' command with no arguments prints
3925 ten lines centered on the point of execution in the frame.  You can
3926 also edit the program at the point of execution with your favorite
3927 editing program by typing `edit'.  *Note Printing source lines: List,
3928 for details.
3930 `up-silently N'
3931 `down-silently N'
3932      These two commands are variants of `up' and `down', respectively;
3933      they differ in that they do their work silently, without causing
3934      display of the new frame.  They are intended primarily for use in
3935      GDB command scripts, where the output might be unnecessary and
3936      distracting.
3938 \x1f
3939 File: gdb.info,  Node: Frame Info,  Prev: Selection,  Up: Stack
3941 6.4 Information about a frame
3942 =============================
3944 There are several other commands to print information about the selected
3945 stack frame.
3947 `frame'
3949      When used without any argument, this command does not change which
3950      frame is selected, but prints a brief description of the currently
3951      selected stack frame.  It can be abbreviated `f'.  With an
3952      argument, this command is used to select a stack frame.  *Note
3953      Selecting a frame: Selection.
3955 `info frame'
3956 `info f'
3957      This command prints a verbose description of the selected stack
3958      frame, including:
3960         * the address of the frame
3962         * the address of the next frame down (called by this frame)
3964         * the address of the next frame up (caller of this frame)
3966         * the language in which the source code corresponding to this
3967           frame is written
3969         * the address of the frame's arguments
3971         * the address of the frame's local variables
3973         * the program counter saved in it (the address of execution in
3974           the caller frame)
3976         * which registers were saved in the frame
3978      The verbose description is useful when something has gone wrong
3979      that has made the stack format fail to fit the usual conventions.
3981 `info frame ADDR'
3982 `info f ADDR'
3983      Print a verbose description of the frame at address ADDR, without
3984      selecting that frame.  The selected frame remains unchanged by this
3985      command.  This requires the same kind of address (more than one
3986      for some architectures) that you specify in the `frame' command.
3987      *Note Selecting a frame: Selection.
3989 `info args'
3990      Print the arguments of the selected frame, each on a separate line.
3992 `info locals'
3993      Print the local variables of the selected frame, each on a separate
3994      line.  These are all variables (declared either static or
3995      automatic) accessible at the point of execution of the selected
3996      frame.
3998 `info catch'
3999      Print a list of all the exception handlers that are active in the
4000      current stack frame at the current point of execution.  To see
4001      other exception handlers, visit the associated frame (using the
4002      `up', `down', or `frame' commands); then type `info catch'.  *Note
4003      Setting catchpoints: Set Catchpoints.
4006 \x1f
4007 File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
4009 7 Examining Source Files
4010 ************************
4012 GDB can print parts of your program's source, since the debugging
4013 information recorded in the program tells GDB what source files were
4014 used to build it.  When your program stops, GDB spontaneously prints
4015 the line where it stopped.  Likewise, when you select a stack frame
4016 (*note Selecting a frame: Selection.), GDB prints the line where
4017 execution in that frame has stopped.  You can print other portions of
4018 source files by explicit command.
4020    If you use GDB through its GNU Emacs interface, you may prefer to
4021 use Emacs facilities to view source; see *Note Using GDB under GNU
4022 Emacs: Emacs.
4024 * Menu:
4026 * List::                        Printing source lines
4027 * Edit::                        Editing source files
4028 * Search::                      Searching source files
4029 * Source Path::                 Specifying source directories
4030 * Machine Code::                Source and machine code
4032 \x1f
4033 File: gdb.info,  Node: List,  Next: Edit,  Up: Source
4035 7.1 Printing source lines
4036 =========================
4038 To print lines from a source file, use the `list' command (abbreviated
4039 `l').  By default, ten lines are printed.  There are several ways to
4040 specify what part of the file you want to print.
4042    Here are the forms of the `list' command most commonly used:
4044 `list LINENUM'
4045      Print lines centered around line number LINENUM in the current
4046      source file.
4048 `list FUNCTION'
4049      Print lines centered around the beginning of function FUNCTION.
4051 `list'
4052      Print more lines.  If the last lines printed were printed with a
4053      `list' command, this prints lines following the last lines
4054      printed; however, if the last line printed was a solitary line
4055      printed as part of displaying a stack frame (*note Examining the
4056      Stack: Stack.), this prints lines centered around that line.
4058 `list -'
4059      Print lines just before the lines last printed.
4061    By default, GDB prints ten source lines with any of these forms of
4062 the `list' command.  You can change this using `set listsize':
4064 `set listsize COUNT'
4065      Make the `list' command display COUNT source lines (unless the
4066      `list' argument explicitly specifies some other number).
4068 `show listsize'
4069      Display the number of lines that `list' prints.
4071    Repeating a `list' command with <RET> discards the argument, so it
4072 is equivalent to typing just `list'.  This is more useful than listing
4073 the same lines again.  An exception is made for an argument of `-';
4074 that argument is preserved in repetition so that each repetition moves
4075 up in the source file.
4077    In general, the `list' command expects you to supply zero, one or two
4078 "linespecs".  Linespecs specify source lines; there are several ways of
4079 writing them, but the effect is always to specify some source line.
4080 Here is a complete description of the possible arguments for `list':
4082 `list LINESPEC'
4083      Print lines centered around the line specified by LINESPEC.
4085 `list FIRST,LAST'
4086      Print lines from FIRST to LAST.  Both arguments are linespecs.
4088 `list ,LAST'
4089      Print lines ending with LAST.
4091 `list FIRST,'
4092      Print lines starting with FIRST.
4094 `list +'
4095      Print lines just after the lines last printed.
4097 `list -'
4098      Print lines just before the lines last printed.
4100 `list'
4101      As described in the preceding table.
4103    Here are the ways of specifying a single source line--all the kinds
4104 of linespec.
4106 `NUMBER'
4107      Specifies line NUMBER of the current source file.  When a `list'
4108      command has two linespecs, this refers to the same source file as
4109      the first linespec.
4111 `+OFFSET'
4112      Specifies the line OFFSET lines after the last line printed.  When
4113      used as the second linespec in a `list' command that has two, this
4114      specifies the line OFFSET lines down from the first linespec.
4116 `-OFFSET'
4117      Specifies the line OFFSET lines before the last line printed.
4119 `FILENAME:NUMBER'
4120      Specifies line NUMBER in the source file FILENAME.
4122 `FUNCTION'
4123      Specifies the line that begins the body of the function FUNCTION.
4124      For example: in C, this is the line with the open brace.
4126 `FILENAME:FUNCTION'
4127      Specifies the line of the open-brace that begins the body of the
4128      function FUNCTION in the file FILENAME.  You only need the file
4129      name with a function name to avoid ambiguity when there are
4130      identically named functions in different source files.
4132 `*ADDRESS'
4133      Specifies the line containing the program address ADDRESS.
4134      ADDRESS may be any expression.
4136 \x1f
4137 File: gdb.info,  Node: Edit,  Next: Search,  Prev: List,  Up: Source
4139 7.2 Editing source files
4140 ========================
4142 To edit the lines in a source file, use the `edit' command.  The
4143 editing program of your choice is invoked with the current line set to
4144 the active line in the program.  Alternatively, there are several ways
4145 to specify what part of the file you want to print if you want to see
4146 other parts of the program.
4148    Here are the forms of the `edit' command most commonly used:
4150 `edit'
4151      Edit the current source file at the active line number in the
4152      program.
4154 `edit NUMBER'
4155      Edit the current source file with NUMBER as the active line number.
4157 `edit FUNCTION'
4158      Edit the file containing FUNCTION at the beginning of its
4159      definition.
4161 `edit FILENAME:NUMBER'
4162      Specifies line NUMBER in the source file FILENAME.
4164 `edit FILENAME:FUNCTION'
4165      Specifies the line that begins the body of the function FUNCTION
4166      in the file FILENAME.  You only need the file name with a function
4167      name to avoid ambiguity when there are identically named functions
4168      in different source files.
4170 `edit *ADDRESS'
4171      Specifies the line containing the program address ADDRESS.
4172      ADDRESS may be any expression.
4174 7.2.1 Choosing your editor
4175 --------------------------
4177 You can customize GDB to use any editor you want (1).  By default, it
4178 is `/bin/ex', but you can change this by setting the environment
4179 variable `EDITOR' before using GDB.  For example, to configure GDB to
4180 use the `vi' editor, you could use these commands with the `sh' shell:
4181      EDITOR=/usr/bin/vi
4182      export EDITOR
4183      gdb ...
4184    or in the `csh' shell,
4185      setenv EDITOR /usr/bin/vi
4186      gdb ...
4188    ---------- Footnotes ----------
4190    (1) The only restriction is that your editor (say `ex'), recognizes
4191 the following command-line syntax:
4192      ex +NUMBER file
4193    The optional numeric value +NUMBER specifies the number of the line
4194 in the file where to start editing.
4196 \x1f
4197 File: gdb.info,  Node: Search,  Next: Source Path,  Prev: Edit,  Up: Source
4199 7.3 Searching source files
4200 ==========================
4202 There are two commands for searching through the current source file
4203 for a regular expression.
4205 `forward-search REGEXP'
4206 `search REGEXP'
4207      The command `forward-search REGEXP' checks each line, starting
4208      with the one following the last line listed, for a match for
4209      REGEXP.  It lists the line that is found.  You can use the synonym
4210      `search REGEXP' or abbreviate the command name as `fo'.
4212 `reverse-search REGEXP'
4213      The command `reverse-search REGEXP' checks each line, starting
4214      with the one before the last line listed and going backward, for a
4215      match for REGEXP.  It lists the line that is found.  You can
4216      abbreviate this command as `rev'.
4218 \x1f
4219 File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
4221 7.4 Specifying source directories
4222 =================================
4224 Executable programs sometimes do not record the directories of the
4225 source files from which they were compiled, just the names.  Even when
4226 they do, the directories could be moved between the compilation and
4227 your debugging session.  GDB has a list of directories to search for
4228 source files; this is called the "source path".  Each time GDB wants a
4229 source file, it tries all the directories in the list, in the order
4230 they are present in the list, until it finds a file with the desired
4231 name.
4233    For example, suppose an executable references the file
4234 `/usr/src/foo-1.0/lib/foo.c', and our source path is `/mnt/cross'.  The
4235 file is first looked up literally; if this fails,
4236 `/mnt/cross/usr/src/foo-1.0/lib/foo.c' is tried; if this fails,
4237 `/mnt/cross/foo.c' is opened; if this fails, an error message is
4238 printed.  GDB does not look up the parts of the source file name, such
4239 as `/mnt/cross/src/foo-1.0/lib/foo.c'.  Likewise, the subdirectories of
4240 the source path are not searched: if the source path is `/mnt/cross',
4241 and the binary refers to `foo.c', GDB would not find it under
4242 `/mnt/cross/usr/src/foo-1.0/lib'.
4244    Plain file names, relative file names with leading directories, file
4245 names containing dots, etc. are all treated as described above; for
4246 instance, if the source path is `/mnt/cross', and the source file is
4247 recorded as `../lib/foo.c', GDB would first try `../lib/foo.c', then
4248 `/mnt/cross/../lib/foo.c', and after that--`/mnt/cross/foo.c'.
4250    Note that the executable search path is _not_ used to locate the
4251 source files.
4253    Whenever you reset or rearrange the source path, GDB clears out any
4254 information it has cached about where source files are found and where
4255 each line is in the file.
4257    When you start GDB, its source path includes only `cdir' and `cwd',
4258 in that order.  To add other directories, use the `directory' command.
4260    The search path is used to find both program source files and GDB
4261 script files (read using the `-command' option and `source' command).
4263 `directory DIRNAME ...'
4265 `dir DIRNAME ...'
4266      Add directory DIRNAME to the front of the source path.  Several
4267      directory names may be given to this command, separated by `:'
4268      (`;' on MS-DOS and MS-Windows, where `:' usually appears as part
4269      of absolute file names) or whitespace.  You may specify a
4270      directory that is already in the source path; this moves it
4271      forward, so GDB searches it sooner.
4273      You can use the string `$cdir' to refer to the compilation
4274      directory (if one is recorded), and `$cwd' to refer to the current
4275      working directory.  `$cwd' is not the same as `.'--the former
4276      tracks the current working directory as it changes during your GDB
4277      session, while the latter is immediately expanded to the current
4278      directory at the time you add an entry to the source path.
4280 `directory'
4281      Reset the source path to its default value (`$cdir:$cwd' on Unix
4282      systems).  This requires confirmation.
4284 `show directories'
4285      Print the source path: show which directories it contains.
4287    If your source path is cluttered with directories that are no longer
4288 of interest, GDB may sometimes cause confusion by finding the wrong
4289 versions of source.  You can correct the situation as follows:
4291   1. Use `directory' with no argument to reset the source path to its
4292      default value.
4294   2. Use `directory' with suitable arguments to reinstall the
4295      directories you want in the source path.  You can add all the
4296      directories in one command.
4298 \x1f
4299 File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
4301 7.5 Source and machine code
4302 ===========================
4304 You can use the command `info line' to map source lines to program
4305 addresses (and vice versa), and the command `disassemble' to display a
4306 range of addresses as machine instructions.  When run under GNU Emacs
4307 mode, the `info line' command causes the arrow to point to the line
4308 specified.  Also, `info line' prints addresses in symbolic form as well
4309 as hex.
4311 `info line LINESPEC'
4312      Print the starting and ending addresses of the compiled code for
4313      source line LINESPEC.  You can specify source lines in any of the
4314      ways understood by the `list' command (*note Printing source
4315      lines: List.).
4317    For example, we can use `info line' to discover the location of the
4318 object code for the first line of function `m4_changequote':
4320      (gdb) info line m4_changequote
4321      Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4323 We can also inquire (using `*ADDR' as the form for LINESPEC) what
4324 source line covers a particular address:
4325      (gdb) info line *0x63ff
4326      Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4328    After `info line', the default address for the `x' command is
4329 changed to the starting address of the line, so that `x/i' is
4330 sufficient to begin examining the machine code (*note Examining memory:
4331 Memory.).  Also, this address is saved as the value of the convenience
4332 variable `$_' (*note Convenience variables: Convenience Vars.).
4334 `disassemble'
4335      This specialized command dumps a range of memory as machine
4336      instructions.  The default memory range is the function
4337      surrounding the program counter of the selected frame.  A single
4338      argument to this command is a program counter value; GDB dumps the
4339      function surrounding this value.  Two arguments specify a range of
4340      addresses (first inclusive, second exclusive) to dump.
4342    The following example shows the disassembly of a range of addresses
4343 of HP PA-RISC 2.0 code:
4345      (gdb) disas 0x32c4 0x32e4
4346      Dump of assembler code from 0x32c4 to 0x32e4:
4347      0x32c4 <main+204>:      addil 0,dp
4348      0x32c8 <main+208>:      ldw 0x22c(sr0,r1),r26
4349      0x32cc <main+212>:      ldil 0x3000,r31
4350      0x32d0 <main+216>:      ble 0x3f8(sr4,r31)
4351      0x32d4 <main+220>:      ldo 0(r31),rp
4352      0x32d8 <main+224>:      addil -0x800,dp
4353      0x32dc <main+228>:      ldo 0x588(r1),r26
4354      0x32e0 <main+232>:      ldil 0x3000,r31
4355      End of assembler dump.
4357    Some architectures have more than one commonly-used set of
4358 instruction mnemonics or other syntax.
4360    For programs that were dynamically linked and use shared libraries,
4361 instructions that call functions or branch to locations in the shared
4362 libraries might show a seemingly bogus location--it's actually a
4363 location of the relocation table.  On some architectures, GDB might be
4364 able to resolve these to actual function names.
4366 `set disassembly-flavor INSTRUCTION-SET'
4367      Select the instruction set to use when disassembling the program
4368      via the `disassemble' or `x/i' commands.
4370      Currently this command is only defined for the Intel x86 family.
4371      You can set INSTRUCTION-SET to either `intel' or `att'.  The
4372      default is `att', the AT&T flavor used by default by Unix
4373      assemblers for x86-based targets.
4375 `show disassembly-flavor'
4376      Show the current setting of the disassembly flavor.
4378 \x1f
4379 File: gdb.info,  Node: Data,  Next: Macros,  Prev: Source,  Up: Top
4381 8 Examining Data
4382 ****************
4384 The usual way to examine data in your program is with the `print'
4385 command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
4386 prints the value of an expression of the language your program is
4387 written in (*note Using GDB with Different Languages: Languages.).
4389 `print EXPR'
4390 `print /F EXPR'
4391      EXPR is an expression (in the source language).  By default the
4392      value of EXPR is printed in a format appropriate to its data type;
4393      you can choose a different format by specifying `/F', where F is a
4394      letter specifying the format; see *Note Output formats: Output
4395      Formats.
4397 `print'
4398 `print /F'
4399      If you omit EXPR, GDB displays the last value again (from the
4400      "value history"; *note Value history: Value History.).  This
4401      allows you to conveniently inspect the same value in an
4402      alternative format.
4404    A more low-level way of examining data is with the `x' command.  It
4405 examines data in memory at a specified address and prints it in a
4406 specified format.  *Note Examining memory: Memory.
4408    If you are interested in information about types, or about how the
4409 fields of a struct or a class are declared, use the `ptype EXP' command
4410 rather than `print'.  *Note Examining the Symbol Table: Symbols.
4412 * Menu:
4414 * Expressions::                 Expressions
4415 * Variables::                   Program variables
4416 * Arrays::                      Artificial arrays
4417 * Output Formats::              Output formats
4418 * Memory::                      Examining memory
4419 * Auto Display::                Automatic display
4420 * Print Settings::              Print settings
4421 * Value History::               Value history
4422 * Convenience Vars::            Convenience variables
4423 * Registers::                   Registers
4424 * Floating Point Hardware::     Floating point hardware
4425 * Vector Unit::                 Vector Unit
4426 * OS Information::              Auxiliary data provided by operating system
4427 * Memory Region Attributes::    Memory region attributes
4428 * Dump/Restore Files::          Copy between memory and a file
4429 * Core File Generation::        Cause a program dump its core
4430 * Character Sets::              Debugging programs that use a different
4431                                 character set than GDB does
4432 * Caching Remote Data::         Data caching for remote targets
4434 \x1f
4435 File: gdb.info,  Node: Expressions,  Next: Variables,  Up: Data
4437 8.1 Expressions
4438 ===============
4440 `print' and many other GDB commands accept an expression and compute
4441 its value.  Any kind of constant, variable or operator defined by the
4442 programming language you are using is valid in an expression in GDB.
4443 This includes conditional expressions, function calls, casts, and
4444 string constants.  It also includes preprocessor macros, if you
4445 compiled your program to include this information; see *Note
4446 Compilation::.
4448    GDB supports array constants in expressions input by the user.  The
4449 syntax is {ELEMENT, ELEMENT...}.  For example, you can use the command
4450 `print {1, 2, 3}' to build up an array in memory that is `malloc'ed in
4451 the target program.
4453    Because C is so widespread, most of the expressions shown in
4454 examples in this manual are in C.  *Note Using GDB with Different
4455 Languages: Languages, for information on how to use expressions in other
4456 languages.
4458    In this section, we discuss operators that you can use in GDB
4459 expressions regardless of your programming language.
4461    Casts are supported in all languages, not just in C, because it is so
4462 useful to cast a number into a pointer in order to examine a structure
4463 at that address in memory.
4465    GDB supports these operators, in addition to those common to
4466 programming languages:
4469      `@' is a binary operator for treating parts of memory as arrays.
4470      *Note Artificial arrays: Arrays, for more information.
4472 `::'
4473      `::' allows you to specify a variable in terms of the file or
4474      function where it is defined.  *Note Program variables: Variables.
4476 `{TYPE} ADDR'
4477      Refers to an object of type TYPE stored at address ADDR in memory.
4478      ADDR may be any expression whose value is an integer or pointer
4479      (but parentheses are required around binary operators, just as in
4480      a cast).  This construct is allowed regardless of what kind of
4481      data is normally supposed to reside at ADDR.
4483 \x1f
4484 File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
4486 8.2 Program variables
4487 =====================
4489 The most common kind of expression to use is the name of a variable in
4490 your program.
4492    Variables in expressions are understood in the selected stack frame
4493 (*note Selecting a frame: Selection.); they must be either:
4495    * global (or file-static)
4499    * visible according to the scope rules of the programming language
4500      from the point of execution in that frame
4502 This means that in the function
4504      foo (a)
4505           int a;
4506      {
4507        bar (a);
4508        {
4509          int b = test ();
4510          bar (b);
4511        }
4512      }
4514 you can examine and use the variable `a' whenever your program is
4515 executing within the function `foo', but you can only use or examine
4516 the variable `b' while your program is executing inside the block where
4517 `b' is declared.
4519    There is an exception: you can refer to a variable or function whose
4520 scope is a single source file even if the current execution point is not
4521 in this file.  But it is possible to have more than one such variable or
4522 function with the same name (in different source files).  If that
4523 happens, referring to that name has unpredictable effects.  If you wish,
4524 you can specify a static variable in a particular function or file,
4525 using the colon-colon (`::') notation:
4527      FILE::VARIABLE
4528      FUNCTION::VARIABLE
4530 Here FILE or FUNCTION is the name of the context for the static
4531 VARIABLE.  In the case of file names, you can use quotes to make sure
4532 GDB parses the file name as a single word--for example, to print a
4533 global value of `x' defined in `f2.c':
4535      (gdb) p 'f2.c'::x
4537    This use of `::' is very rarely in conflict with the very similar
4538 use of the same notation in C++.  GDB also supports use of the C++
4539 scope resolution operator in GDB expressions.
4541      _Warning:_ Occasionally, a local variable may appear to have the
4542      wrong value at certain points in a function--just after entry to a
4543      new scope, and just before exit.
4544    You may see this problem when you are stepping by machine
4545 instructions.  This is because, on most machines, it takes more than
4546 one instruction to set up a stack frame (including local variable
4547 definitions); if you are stepping by machine instructions, variables
4548 may appear to have the wrong values until the stack frame is completely
4549 built.  On exit, it usually also takes more than one machine
4550 instruction to destroy a stack frame; after you begin stepping through
4551 that group of instructions, local variable definitions may be gone.
4553    This may also happen when the compiler does significant
4554 optimizations.  To be sure of always seeing accurate values, turn off
4555 all optimization when compiling.
4557    Another possible effect of compiler optimizations is to optimize
4558 unused variables out of existence, or assign variables to registers (as
4559 opposed to memory addresses).  Depending on the support for such cases
4560 offered by the debug info format used by the compiler, GDB might not be
4561 able to display values for such local variables.  If that happens, GDB
4562 will print a message like this:
4564      No symbol "foo" in current context.
4566    To solve such problems, either recompile without optimizations, or
4567 use a different debug info format, if the compiler supports several such
4568 formats.  For example, GCC, the GNU C/C++ compiler, usually supports
4569 the `-gstabs+' option.  `-gstabs+' produces debug info in a format that
4570 is superior to formats such as COFF.  You may be able to use DWARF 2
4571 (`-gdwarf-2'), which is also an effective form for debug info.  *Note
4572 Options for Debugging Your Program or GNU CC: (gcc.info)Debugging
4573 Options.  *Note Debugging C++: C, for more info about debug info formats
4574 that are best suited to C++ programs.
4576    If you ask to print an object whose contents are unknown to GDB,
4577 e.g., because its data type is not completely specified by the debug
4578 information, GDB will say `<incomplete type>'.  *Note incomplete type:
4579 Symbols, for more about this.
4581 \x1f
4582 File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
4584 8.3 Artificial arrays
4585 =====================
4587 It is often useful to print out several successive objects of the same
4588 type in memory; a section of an array, or an array of dynamically
4589 determined size for which only a pointer exists in the program.
4591    You can do this by referring to a contiguous span of memory as an
4592 "artificial array", using the binary operator `@'.  The left operand of
4593 `@' should be the first element of the desired array and be an
4594 individual object.  The right operand should be the desired length of
4595 the array.  The result is an array value whose elements are all of the
4596 type of the left argument.  The first element is actually the left
4597 argument; the second element comes from bytes of memory immediately
4598 following those that hold the first element, and so on.  Here is an
4599 example.  If a program says
4601      int *array = (int *) malloc (len * sizeof (int));
4603 you can print the contents of `array' with
4605      p *array@len
4607    The left operand of `@' must reside in memory.  Array values made
4608 with `@' in this way behave just like other arrays in terms of
4609 subscripting, and are coerced to pointers when used in expressions.
4610 Artificial arrays most often appear in expressions via the value history
4611 (*note Value history: Value History.), after printing one out.
4613    Another way to create an artificial array is to use a cast.  This
4614 re-interprets a value as if it were an array.  The value need not be in
4615 memory:
4616      (gdb) p/x (short[2])0x12345678
4617      $1 = {0x1234, 0x5678}
4619    As a convenience, if you leave the array length out (as in
4620 `(TYPE[])VALUE') GDB calculates the size to fill the value (as
4621 `sizeof(VALUE)/sizeof(TYPE)':
4622      (gdb) p/x (short[])0x12345678
4623      $2 = {0x1234, 0x5678}
4625    Sometimes the artificial array mechanism is not quite enough; in
4626 moderately complex data structures, the elements of interest may not
4627 actually be adjacent--for example, if you are interested in the values
4628 of pointers in an array.  One useful work-around in this situation is
4629 to use a convenience variable (*note Convenience variables: Convenience
4630 Vars.) as a counter in an expression that prints the first interesting
4631 value, and then repeat that expression via <RET>.  For instance,
4632 suppose you have an array `dtab' of pointers to structures, and you are
4633 interested in the values of a field `fv' in each structure.  Here is an
4634 example of what you might type:
4636      set $i = 0
4637      p dtab[$i++]->fv
4638      <RET>
4639      <RET>
4640      ...
4642 \x1f
4643 File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
4645 8.4 Output formats
4646 ==================
4648 By default, GDB prints a value according to its data type.  Sometimes
4649 this is not what you want.  For example, you might want to print a
4650 number in hex, or a pointer in decimal.  Or you might want to view data
4651 in memory at a certain address as a character string or as an
4652 instruction.  To do these things, specify an "output format" when you
4653 print a value.
4655    The simplest use of output formats is to say how to print a value
4656 already computed.  This is done by starting the arguments of the
4657 `print' command with a slash and a format letter.  The format letters
4658 supported are:
4661      Regard the bits of the value as an integer, and print the integer
4662      in hexadecimal.
4665      Print as integer in signed decimal.
4668      Print as integer in unsigned decimal.
4671      Print as integer in octal.
4674      Print as integer in binary.  The letter `t' stands for "two".  (1)
4677      Print as an address, both absolute in hexadecimal and as an offset
4678      from the nearest preceding symbol.  You can use this format used
4679      to discover where (in what function) an unknown address is located:
4681           (gdb) p/a 0x54320
4682           $3 = 0x54320 <_initialize_vx+396>
4684      The command `info symbol 0x54320' yields similar results.  *Note
4685      info symbol: Symbols.
4688      Regard as an integer and print it as a character constant.  This
4689      prints both the numerical value and its character representation.
4690      The character representation is replaced with the octal escape
4691      `\nnn' for characters outside the 7-bit ASCII range.
4694      Regard the bits of the value as a floating point number and print
4695      using typical floating point syntax.
4697    For example, to print the program counter in hex (*note
4698 Registers::), type
4700      p/x $pc
4702 Note that no space is required before the slash; this is because command
4703 names in GDB cannot contain a slash.
4705    To reprint the last value in the value history with a different
4706 format, you can use the `print' command with just a format and no
4707 expression.  For example, `p/x' reprints the last value in hex.
4709    ---------- Footnotes ----------
4711    (1) `b' cannot be used because these format letters are also used
4712 with the `x' command, where `b' stands for "byte"; see *Note Examining
4713 memory: Memory.
4715 \x1f
4716 File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output Formats,  Up: Data
4718 8.5 Examining memory
4719 ====================
4721 You can use the command `x' (for "examine") to examine memory in any of
4722 several formats, independently of your program's data types.
4724 `x/NFU ADDR'
4725 `x ADDR'
4727      Use the `x' command to examine memory.
4729    N, F, and U are all optional parameters that specify how much memory
4730 to display and how to format it; ADDR is an expression giving the
4731 address where you want to start displaying memory.  If you use defaults
4732 for NFU, you need not type the slash `/'.  Several commands set
4733 convenient defaults for ADDR.
4735 N, the repeat count
4736      The repeat count is a decimal integer; the default is 1.  It
4737      specifies how much memory (counting by units U) to display.
4739 F, the display format
4740      The display format is one of the formats used by `print' (`x',
4741      `d', `u', `o', `t', `a', `c', `f'), and in addition `s' (for
4742      null-terminated strings) and `i' (for machine instructions).  The
4743      default is `x' (hexadecimal) initially.  The default changes each
4744      time you use either `x' or `print'.
4746 U, the unit size
4747      The unit size is any of
4749     `b'
4750           Bytes.
4752     `h'
4753           Halfwords (two bytes).
4755     `w'
4756           Words (four bytes).  This is the initial default.
4758     `g'
4759           Giant words (eight bytes).
4761      Each time you specify a unit size with `x', that size becomes the
4762      default unit the next time you use `x'.  (For the `s' and `i'
4763      formats, the unit size is ignored and is normally not written.)
4765 ADDR, starting display address
4766      ADDR is the address where you want GDB to begin displaying memory.
4767      The expression need not have a pointer value (though it may); it
4768      is always interpreted as an integer address of a byte of memory.
4769      *Note Expressions: Expressions, for more information on
4770      expressions.  The default for ADDR is usually just after the last
4771      address examined--but several other commands also set the default
4772      address: `info breakpoints' (to the address of the last breakpoint
4773      listed), `info line' (to the starting address of a line), and
4774      `print' (if you use it to display a value from memory).
4776    For example, `x/3uh 0x54320' is a request to display three halfwords
4777 (`h') of memory, formatted as unsigned decimal integers (`u'), starting
4778 at address `0x54320'.  `x/4xw $sp' prints the four words (`w') of
4779 memory above the stack pointer (here, `$sp'; *note Registers:
4780 Registers.) in hexadecimal (`x').
4782    Since the letters indicating unit sizes are all distinct from the
4783 letters specifying output formats, you do not have to remember whether
4784 unit size or format comes first; either order works.  The output
4785 specifications `4xw' and `4wx' mean exactly the same thing.  (However,
4786 the count N must come first; `wx4' does not work.)
4788    Even though the unit size U is ignored for the formats `s' and `i',
4789 you might still want to use a count N; for example, `3i' specifies that
4790 you want to see three machine instructions, including any operands.
4791 The command `disassemble' gives an alternative way of inspecting
4792 machine instructions; see *Note Source and machine code: Machine Code.
4794    All the defaults for the arguments to `x' are designed to make it
4795 easy to continue scanning memory with minimal specifications each time
4796 you use `x'.  For example, after you have inspected three machine
4797 instructions with `x/3i ADDR', you can inspect the next seven with just
4798 `x/7'.  If you use <RET> to repeat the `x' command, the repeat count N
4799 is used again; the other arguments default as for successive uses of
4800 `x'.
4802    The addresses and contents printed by the `x' command are not saved
4803 in the value history because there is often too much of them and they
4804 would get in the way.  Instead, GDB makes these values available for
4805 subsequent use in expressions as values of the convenience variables
4806 `$_' and `$__'.  After an `x' command, the last address examined is
4807 available for use in expressions in the convenience variable `$_'.  The
4808 contents of that address, as examined, are available in the convenience
4809 variable `$__'.
4811    If the `x' command has a repeat count, the address and contents saved
4812 are from the last memory unit printed; this is not the same as the last
4813 address printed if several units were printed on the last line of
4814 output.
4816    When you are debugging a program running on a remote target machine
4817 (*note Remote::), you may wish to verify the program's image in the
4818 remote machine's memory against the executable file you downloaded to
4819 the target.  The `compare-sections' command is provided for such
4820 situations.
4822 `compare-sections [SECTION-NAME]'
4823      Compare the data of a loadable section SECTION-NAME in the
4824      executable file of the program being debugged with the same
4825      section in the remote machine's memory, and report any mismatches.
4826      With no arguments, compares all loadable sections.  This command's
4827      availability depends on the target's support for the `"qCRC"'
4828      remote request.
4830 \x1f
4831 File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
4833 8.6 Automatic display
4834 =====================
4836 If you find that you want to print the value of an expression frequently
4837 (to see how it changes), you might want to add it to the "automatic
4838 display list" so that GDB prints its value each time your program stops.
4839 Each expression added to the list is given a number to identify it; to
4840 remove an expression from the list, you specify that number.  The
4841 automatic display looks like this:
4843      2: foo = 38
4844      3: bar[5] = (struct hack *) 0x3804
4846 This display shows item numbers, expressions and their current values.
4847 As with displays you request manually using `x' or `print', you can
4848 specify the output format you prefer; in fact, `display' decides
4849 whether to use `print' or `x' depending on how elaborate your format
4850 specification is--it uses `x' if you specify a unit size, or one of the
4851 two formats (`i' and `s') that are only supported by `x'; otherwise it
4852 uses `print'.
4854 `display EXPR'
4855      Add the expression EXPR to the list of expressions to display each
4856      time your program stops.  *Note Expressions: Expressions.
4858      `display' does not repeat if you press <RET> again after using it.
4860 `display/FMT EXPR'
4861      For FMT specifying only a display format and not a size or count,
4862      add the expression EXPR to the auto-display list but arrange to
4863      display it each time in the specified format FMT.  *Note Output
4864      formats: Output Formats.
4866 `display/FMT ADDR'
4867      For FMT `i' or `s', or including a unit-size or a number of units,
4868      add the expression ADDR as a memory address to be examined each
4869      time your program stops.  Examining means in effect doing `x/FMT
4870      ADDR'.  *Note Examining memory: Memory.
4872    For example, `display/i $pc' can be helpful, to see the machine
4873 instruction about to be executed each time execution stops (`$pc' is a
4874 common name for the program counter; *note Registers: Registers.).
4876 `undisplay DNUMS...'
4877 `delete display DNUMS...'
4878      Remove item numbers DNUMS from the list of expressions to display.
4880      `undisplay' does not repeat if you press <RET> after using it.
4881      (Otherwise you would just get the error `No display number ...'.)
4883 `disable display DNUMS...'
4884      Disable the display of item numbers DNUMS.  A disabled display
4885      item is not printed automatically, but is not forgotten.  It may be
4886      enabled again later.
4888 `enable display DNUMS...'
4889      Enable display of item numbers DNUMS.  It becomes effective once
4890      again in auto display of its expression, until you specify
4891      otherwise.
4893 `display'
4894      Display the current values of the expressions on the list, just as
4895      is done when your program stops.
4897 `info display'
4898      Print the list of expressions previously set up to display
4899      automatically, each one with its item number, but without showing
4900      the values.  This includes disabled expressions, which are marked
4901      as such.  It also includes expressions which would not be
4902      displayed right now because they refer to automatic variables not
4903      currently available.
4905    If a display expression refers to local variables, then it does not
4906 make sense outside the lexical context for which it was set up.  Such an
4907 expression is disabled when execution enters a context where one of its
4908 variables is not defined.  For example, if you give the command
4909 `display last_char' while inside a function with an argument
4910 `last_char', GDB displays this argument while your program continues to
4911 stop inside that function.  When it stops elsewhere--where there is no
4912 variable `last_char'--the display is disabled automatically.  The next
4913 time your program stops where `last_char' is meaningful, you can enable
4914 the display expression once again.
4916 \x1f
4917 File: gdb.info,  Node: Print Settings,  Next: Value History,  Prev: Auto Display,  Up: Data
4919 8.7 Print settings
4920 ==================
4922 GDB provides the following ways to control how arrays, structures, and
4923 symbols are printed.
4925 These settings are useful for debugging programs in any language:
4927 `set print address'
4928 `set print address on'
4929      GDB prints memory addresses showing the location of stack traces,
4930      structure values, pointer values, breakpoints, and so forth, even
4931      when it also displays the contents of those addresses.  The default
4932      is `on'.  For example, this is what a stack frame display looks
4933      like with `set print address on':
4935           (gdb) f
4936           #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4937               at input.c:530
4938           530         if (lquote != def_lquote)
4940 `set print address off'
4941      Do not print addresses when displaying their contents.  For
4942      example, this is the same stack frame displayed with `set print
4943      address off':
4945           (gdb) set print addr off
4946           (gdb) f
4947           #0  set_quotes (lq="<<", rq=">>") at input.c:530
4948           530         if (lquote != def_lquote)
4950      You can use `set print address off' to eliminate all machine
4951      dependent displays from the GDB interface.  For example, with
4952      `print address off', you should get the same text for backtraces on
4953      all machines--whether or not they involve pointer arguments.
4955 `show print address'
4956      Show whether or not addresses are to be printed.
4958    When GDB prints a symbolic address, it normally prints the closest
4959 earlier symbol plus an offset.  If that symbol does not uniquely
4960 identify the address (for example, it is a name whose scope is a single
4961 source file), you may need to clarify.  One way to do this is with
4962 `info line', for example `info line *0x4537'.  Alternately, you can set
4963 GDB to print the source file and line number when it prints a symbolic
4964 address:
4966 `set print symbol-filename on'
4967      Tell GDB to print the source file name and line number of a symbol
4968      in the symbolic form of an address.
4970 `set print symbol-filename off'
4971      Do not print source file name and line number of a symbol.  This
4972      is the default.
4974 `show print symbol-filename'
4975      Show whether or not GDB will print the source file name and line
4976      number of a symbol in the symbolic form of an address.
4978    Another situation where it is helpful to show symbol filenames and
4979 line numbers is when disassembling code; GDB shows you the line number
4980 and source file that corresponds to each instruction.
4982    Also, you may wish to see the symbolic form only if the address being
4983 printed is reasonably close to the closest earlier symbol:
4985 `set print max-symbolic-offset MAX-OFFSET'
4986      Tell GDB to only display the symbolic form of an address if the
4987      offset between the closest earlier symbol and the address is less
4988      than MAX-OFFSET.  The default is 0, which tells GDB to always
4989      print the symbolic form of an address if any symbol precedes it.
4991 `show print max-symbolic-offset'
4992      Ask how large the maximum offset is that GDB prints in a symbolic
4993      address.
4995    If you have a pointer and you are not sure where it points, try `set
4996 print symbol-filename on'.  Then you can determine the name and source
4997 file location of the variable where it points, using `p/a POINTER'.
4998 This interprets the address in symbolic form.  For example, here GDB
4999 shows that a variable `ptt' points at another variable `t', defined in
5000 `hi2.c':
5002      (gdb) set print symbol-filename on
5003      (gdb) p/a ptt
5004      $4 = 0xe008 <t in hi2.c>
5006      _Warning:_ For pointers that point to a local variable, `p/a' does
5007      not show the symbol name and filename of the referent, even with
5008      the appropriate `set print' options turned on.
5010    Other settings control how different kinds of objects are printed:
5012 `set print array'
5013 `set print array on'
5014      Pretty print arrays.  This format is more convenient to read, but
5015      uses more space.  The default is off.
5017 `set print array off'
5018      Return to compressed format for arrays.
5020 `show print array'
5021      Show whether compressed or pretty format is selected for displaying
5022      arrays.
5024 `set print array-indexes'
5025 `set print array-indexes on'
5026      Print the index of each element when displaying arrays.  May be
5027      more convenient to locate a given element in the array or quickly
5028      find the index of a given element in that printed array.  The
5029      default is off.
5031 `set print array-indexes off'
5032      Stop printing element indexes when displaying arrays.
5034 `show print array-indexes'
5035      Show whether the index of each element is printed when displaying
5036      arrays.
5038 `set print elements NUMBER-OF-ELEMENTS'
5039      Set a limit on how many elements of an array GDB will print.  If
5040      GDB is printing a large array, it stops printing after it has
5041      printed the number of elements set by the `set print elements'
5042      command.  This limit also applies to the display of strings.  When
5043      GDB starts, this limit is set to 200.  Setting  NUMBER-OF-ELEMENTS
5044      to zero means that the printing is unlimited.
5046 `show print elements'
5047      Display the number of elements of a large array that GDB will
5048      print.  If the number is 0, then the printing is unlimited.
5050 `set print repeats'
5051      Set the threshold for suppressing display of repeated array
5052      elelments.  When the number of consecutive identical elements of an
5053      array exceeds the threshold, GDB prints the string `"<repeats N
5054      times>"', where N is the number of identical repetitions, instead
5055      of displaying the identical elements themselves.  Setting the
5056      threshold to zero will cause all elements to be individually
5057      printed.  The default threshold is 10.
5059 `show print repeats'
5060      Display the current threshold for printing repeated identical
5061      elements.
5063 `set print null-stop'
5064      Cause GDB to stop printing the characters of an array when the
5065      first NULL is encountered.  This is useful when large arrays
5066      actually contain only short strings.  The default is off.
5068 `show print null-stop'
5069      Show whether GDB stops printing an array on the first NULL
5070      character.
5072 `set print pretty on'
5073      Cause GDB to print structures in an indented format with one member
5074      per line, like this:
5076           $1 = {
5077             next = 0x0,
5078             flags = {
5079               sweet = 1,
5080               sour = 1
5081             },
5082             meat = 0x54 "Pork"
5083           }
5085 `set print pretty off'
5086      Cause GDB to print structures in a compact format, like this:
5088           $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
5089           meat = 0x54 "Pork"}
5091      This is the default format.
5093 `show print pretty'
5094      Show which format GDB is using to print structures.
5096 `set print sevenbit-strings on'
5097      Print using only seven-bit characters; if this option is set, GDB
5098      displays any eight-bit characters (in strings or character values)
5099      using the notation `\'NNN.  This setting is best if you are
5100      working in English (ASCII) and you use the high-order bit of
5101      characters as a marker or "meta" bit.
5103 `set print sevenbit-strings off'
5104      Print full eight-bit characters.  This allows the use of more
5105      international character sets, and is the default.
5107 `show print sevenbit-strings'
5108      Show whether or not GDB is printing only seven-bit characters.
5110 `set print union on'
5111      Tell GDB to print unions which are contained in structures and
5112      other unions.  This is the default setting.
5114 `set print union off'
5115      Tell GDB not to print unions which are contained in structures and
5116      other unions.  GDB will print `"{...}"' instead.
5118 `show print union'
5119      Ask GDB whether or not it will print unions which are contained in
5120      structures and other unions.
5122      For example, given the declarations
5124           typedef enum {Tree, Bug} Species;
5125           typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
5126           typedef enum {Caterpillar, Cocoon, Butterfly}
5127                         Bug_forms;
5129           struct thing {
5130             Species it;
5131             union {
5132               Tree_forms tree;
5133               Bug_forms bug;
5134             } form;
5135           };
5137           struct thing foo = {Tree, {Acorn}};
5139      with `set print union on' in effect `p foo' would print
5141           $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
5143      and with `set print union off' in effect it would print
5145           $1 = {it = Tree, form = {...}}
5147      `set print union' affects programs written in C-like languages and
5148      in Pascal.
5150 These settings are of interest when debugging C++ programs:
5152 `set print demangle'
5153 `set print demangle on'
5154      Print C++ names in their source form rather than in the encoded
5155      ("mangled") form passed to the assembler and linker for type-safe
5156      linkage.  The default is on.
5158 `show print demangle'
5159      Show whether C++ names are printed in mangled or demangled form.
5161 `set print asm-demangle'
5162 `set print asm-demangle on'
5163      Print C++ names in their source form rather than their mangled
5164      form, even in assembler code printouts such as instruction
5165      disassemblies.  The default is off.
5167 `show print asm-demangle'
5168      Show whether C++ names in assembly listings are printed in mangled
5169      or demangled form.
5171 `set demangle-style STYLE'
5172      Choose among several encoding schemes used by different compilers
5173      to represent C++ names.  The choices for STYLE are currently:
5175     `auto'
5176           Allow GDB to choose a decoding style by inspecting your
5177           program.
5179     `gnu'
5180           Decode based on the GNU C++ compiler (`g++') encoding
5181           algorithm.  This is the default.
5183     `hp'
5184           Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
5186     `lucid'
5187           Decode based on the Lucid C++ compiler (`lcc') encoding
5188           algorithm.
5190     `arm'
5191           Decode using the algorithm in the `C++ Annotated Reference
5192           Manual'.  *Warning:* this setting alone is not sufficient to
5193           allow debugging `cfront'-generated executables.  GDB would
5194           require further enhancement to permit that.
5196      If you omit STYLE, you will see a list of possible formats.
5198 `show demangle-style'
5199      Display the encoding style currently in use for decoding C++
5200      symbols.
5202 `set print object'
5203 `set print object on'
5204      When displaying a pointer to an object, identify the _actual_
5205      (derived) type of the object rather than the _declared_ type, using
5206      the virtual function table.
5208 `set print object off'
5209      Display only the declared type of objects, without reference to the
5210      virtual function table.  This is the default setting.
5212 `show print object'
5213      Show whether actual, or declared, object types are displayed.
5215 `set print static-members'
5216 `set print static-members on'
5217      Print static members when displaying a C++ object.  The default is
5218      on.
5220 `set print static-members off'
5221      Do not print static members when displaying a C++ object.
5223 `show print static-members'
5224      Show whether C++ static members are printed or not.
5226 `set print pascal_static-members'
5227 `set print pascal_static-members on'
5228      Print static members when displaying a Pascal object.  The default
5229      is on.
5231 `set print pascal_static-members off'
5232      Do not print static members when displaying a Pascal object.
5234 `show print pascal_static-members'
5235      Show whether Pascal static members are printed or not.
5237 `set print vtbl'
5238 `set print vtbl on'
5239      Pretty print C++ virtual function tables.  The default is off.
5240      (The `vtbl' commands do not work on programs compiled with the HP
5241      ANSI C++ compiler (`aCC').)
5243 `set print vtbl off'
5244      Do not pretty print C++ virtual function tables.
5246 `show print vtbl'
5247      Show whether C++ virtual function tables are pretty printed, or
5248      not.
5250 \x1f
5251 File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Print Settings,  Up: Data
5253 8.8 Value history
5254 =================
5256 Values printed by the `print' command are saved in the GDB "value
5257 history".  This allows you to refer to them in other expressions.
5258 Values are kept until the symbol table is re-read or discarded (for
5259 example with the `file' or `symbol-file' commands).  When the symbol
5260 table changes, the value history is discarded, since the values may
5261 contain pointers back to the types defined in the symbol table.
5263    The values printed are given "history numbers" by which you can
5264 refer to them.  These are successive integers starting with one.
5265 `print' shows you the history number assigned to a value by printing
5266 `$NUM = ' before the value; here NUM is the history number.
5268    To refer to any previous value, use `$' followed by the value's
5269 history number.  The way `print' labels its output is designed to
5270 remind you of this.  Just `$' refers to the most recent value in the
5271 history, and `$$' refers to the value before that.  `$$N' refers to the
5272 Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
5273 equivalent to `$$', and `$$0' is equivalent to `$'.
5275    For example, suppose you have just printed a pointer to a structure
5276 and want to see the contents of the structure.  It suffices to type
5278      p *$
5280    If you have a chain of structures where the component `next' points
5281 to the next one, you can print the contents of the next one with this:
5283      p *$.next
5285 You can print successive links in the chain by repeating this
5286 command--which you can do by just typing <RET>.
5288    Note that the history records values, not expressions.  If the value
5289 of `x' is 4 and you type these commands:
5291      print x
5292      set x=5
5294 then the value recorded in the value history by the `print' command
5295 remains 4 even though the value of `x' has changed.
5297 `show values'
5298      Print the last ten values in the value history, with their item
5299      numbers.  This is like `p $$9' repeated ten times, except that
5300      `show values' does not change the history.
5302 `show values N'
5303      Print ten history values centered on history item number N.
5305 `show values +'
5306      Print ten history values just after the values last printed.  If
5307      no more values are available, `show values +' produces no display.
5309    Pressing <RET> to repeat `show values N' has exactly the same effect
5310 as `show values +'.
5312 \x1f
5313 File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
5315 8.9 Convenience variables
5316 =========================
5318 GDB provides "convenience variables" that you can use within GDB to
5319 hold on to a value and refer to it later.  These variables exist
5320 entirely within GDB; they are not part of your program, and setting a
5321 convenience variable has no direct effect on further execution of your
5322 program.  That is why you can use them freely.
5324    Convenience variables are prefixed with `$'.  Any name preceded by
5325 `$' can be used for a convenience variable, unless it is one of the
5326 predefined machine-specific register names (*note Registers:
5327 Registers.).  (Value history references, in contrast, are _numbers_
5328 preceded by `$'.  *Note Value history: Value History.)
5330    You can save a value in a convenience variable with an assignment
5331 expression, just as you would set a variable in your program.  For
5332 example:
5334      set $foo = *object_ptr
5336 would save in `$foo' the value contained in the object pointed to by
5337 `object_ptr'.
5339    Using a convenience variable for the first time creates it, but its
5340 value is `void' until you assign a new value.  You can alter the value
5341 with another assignment at any time.
5343    Convenience variables have no fixed types.  You can assign a
5344 convenience variable any type of value, including structures and
5345 arrays, even if that variable already has a value of a different type.
5346 The convenience variable, when used as an expression, has the type of
5347 its current value.
5349 `show convenience'
5350      Print a list of convenience variables used so far, and their
5351      values.  Abbreviated `show conv'.
5353 `init-if-undefined $VARIABLE = EXPRESSION'
5354      Set a convenience variable if it has not already been set.  This
5355      is useful for user-defined commands that keep some state.  It is
5356      similar, in concept, to using local static variables with
5357      initializers in C (except that convenience variables are global).
5358      It can also be used to allow users to override default values used
5359      in a command script.
5361      If the variable is already defined then the expression is not
5362      evaluated so any side-effects do not occur.
5364    One of the ways to use a convenience variable is as a counter to be
5365 incremented or a pointer to be advanced.  For example, to print a field
5366 from successive elements of an array of structures:
5368      set $i = 0
5369      print bar[$i++]->contents
5371 Repeat that command by typing <RET>.
5373    Some convenience variables are created automatically by GDB and given
5374 values likely to be useful.
5376 `$_'
5377      The variable `$_' is automatically set by the `x' command to the
5378      last address examined (*note Examining memory: Memory.).  Other
5379      commands which provide a default address for `x' to examine also
5380      set `$_' to that address; these commands include `info line' and
5381      `info breakpoint'.  The type of `$_' is `void *' except when set
5382      by the `x' command, in which case it is a pointer to the type of
5383      `$__'.
5385 `$__'
5386      The variable `$__' is automatically set by the `x' command to the
5387      value found in the last address examined.  Its type is chosen to
5388      match the format in which the data was printed.
5390 `$_exitcode'
5391      The variable `$_exitcode' is automatically set to the exit code
5392      when the program being debugged terminates.
5394    On HP-UX systems, if you refer to a function or variable name that
5395 begins with a dollar sign, GDB searches for a user or system name
5396 first, before it searches for a convenience variable.
5398 \x1f
5399 File: gdb.info,  Node: Registers,  Next: Floating Point Hardware,  Prev: Convenience Vars,  Up: Data
5401 8.10 Registers
5402 ==============
5404 You can refer to machine register contents, in expressions, as variables
5405 with names starting with `$'.  The names of registers are different for
5406 each machine; use `info registers' to see the names used on your
5407 machine.
5409 `info registers'
5410      Print the names and values of all registers except floating-point
5411      and vector registers (in the selected stack frame).
5413 `info all-registers'
5414      Print the names and values of all registers, including
5415      floating-point and vector registers (in the selected stack frame).
5417 `info registers REGNAME ...'
5418      Print the "relativized" value of each specified register REGNAME.
5419      As discussed in detail below, register values are normally
5420      relative to the selected stack frame.  REGNAME may be any register
5421      name valid on the machine you are using, with or without the
5422      initial `$'.
5424    GDB has four "standard" register names that are available (in
5425 expressions) on most machines--whenever they do not conflict with an
5426 architecture's canonical mnemonics for registers.  The register names
5427 `$pc' and `$sp' are used for the program counter register and the stack
5428 pointer.  `$fp' is used for a register that contains a pointer to the
5429 current stack frame, and `$ps' is used for a register that contains the
5430 processor status.  For example, you could print the program counter in
5431 hex with
5433      p/x $pc
5435 or print the instruction to be executed next with
5437      x/i $pc
5439 or add four to the stack pointer(1) with
5441      set $sp += 4
5443    Whenever possible, these four standard register names are available
5444 on your machine even though the machine has different canonical
5445 mnemonics, so long as there is no conflict.  The `info registers'
5446 command shows the canonical names.  For example, on the SPARC, `info
5447 registers' displays the processor status register as `$psr' but you can
5448 also refer to it as `$ps'; and on x86-based machines `$ps' is an alias
5449 for the EFLAGS register.
5451    GDB always considers the contents of an ordinary register as an
5452 integer when the register is examined in this way.  Some machines have
5453 special registers which can hold nothing but floating point; these
5454 registers are considered to have floating point values.  There is no way
5455 to refer to the contents of an ordinary register as floating point value
5456 (although you can _print_ it as a floating point value with `print/f
5457 $REGNAME').
5459    Some registers have distinct "raw" and "virtual" data formats.  This
5460 means that the data format in which the register contents are saved by
5461 the operating system is not the same one that your program normally
5462 sees.  For example, the registers of the 68881 floating point
5463 coprocessor are always saved in "extended" (raw) format, but all C
5464 programs expect to work with "double" (virtual) format.  In such cases,
5465 GDB normally works with the virtual format only (the format that makes
5466 sense for your program), but the `info registers' command prints the
5467 data in both formats.
5469    Some machines have special registers whose contents can be
5470 interpreted in several different ways.  For example, modern x86-based
5471 machines have SSE and MMX registers that can hold several values packed
5472 together in several different formats.  GDB refers to such registers in
5473 `struct' notation:
5475      (gdb) print $xmm1
5476      $1 = {
5477        v4_float = {0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044},
5478        v2_double = {9.92129282474342e-303, 2.7585945287983262e-313},
5479        v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
5480        v8_int16 = {0, 0, 14072, 315, 11, 0, 13, 0},
5481        v4_int32 = {0, 20657912, 11, 13},
5482        v2_int64 = {88725056443645952, 55834574859},
5483        uint128 = 0x0000000d0000000b013b36f800000000
5484      }
5486 To set values of such registers, you need to tell GDB which view of the
5487 register you wish to change, as if you were assigning value to a
5488 `struct' member:
5490       (gdb) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
5492    Normally, register values are relative to the selected stack frame
5493 (*note Selecting a frame: Selection.).  This means that you get the
5494 value that the register would contain if all stack frames farther in
5495 were exited and their saved registers restored.  In order to see the
5496 true contents of hardware registers, you must select the innermost
5497 frame (with `frame 0').
5499    However, GDB must deduce where registers are saved, from the machine
5500 code generated by your compiler.  If some registers are not saved, or if
5501 GDB is unable to locate the saved registers, the selected stack frame
5502 makes no difference.
5504    ---------- Footnotes ----------
5506    (1) This is a way of removing one word from the stack, on machines
5507 where stacks grow downward in memory (most machines, nowadays).  This
5508 assumes that the innermost stack frame is selected; setting `$sp' is
5509 not allowed when other stack frames are selected.  To pop entire frames
5510 off the stack, regardless of machine architecture, use `return'; see
5511 *Note Returning from a function: Returning.
5513 \x1f
5514 File: gdb.info,  Node: Floating Point Hardware,  Next: Vector Unit,  Prev: Registers,  Up: Data
5516 8.11 Floating point hardware
5517 ============================
5519 Depending on the configuration, GDB may be able to give you more
5520 information about the status of the floating point hardware.
5522 `info float'
5523      Display hardware-dependent information about the floating point
5524      unit.  The exact contents and layout vary depending on the
5525      floating point chip.  Currently, `info float' is supported on the
5526      ARM and x86 machines.
5528 \x1f
5529 File: gdb.info,  Node: Vector Unit,  Next: OS Information,  Prev: Floating Point Hardware,  Up: Data
5531 8.12 Vector Unit
5532 ================
5534 Depending on the configuration, GDB may be able to give you more
5535 information about the status of the vector unit.
5537 `info vector'
5538      Display information about the vector unit.  The exact contents and
5539      layout vary depending on the hardware.
5541 \x1f
5542 File: gdb.info,  Node: OS Information,  Next: Memory Region Attributes,  Prev: Vector Unit,  Up: Data
5544 8.13 Operating system auxiliary information
5545 ===========================================
5547 GDB provides interfaces to useful OS facilities that can help you debug
5548 your program.
5550    When GDB runs on a "Posix system" (such as GNU or Unix machines), it
5551 interfaces with the inferior via the `ptrace' system call.  The
5552 operating system creates a special sata structure, called `struct
5553 user', for this interface.  You can use the command `info udot' to
5554 display the contents of this data structure.
5556 `info udot'
5557      Display the contents of the `struct user' maintained by the OS
5558      kernel for the program being debugged.  GDB displays the contents
5559      of `struct user' as a list of hex numbers, similar to the
5560      `examine' command.
5562    Some operating systems supply an "auxiliary vector" to programs at
5563 startup.  This is akin to the arguments and environment that you
5564 specify for a program, but contains a system-dependent variety of
5565 binary values that tell system libraries important details about the
5566 hardware, operating system, and process.  Each value's purpose is
5567 identified by an integer tag; the meanings are well-known but
5568 system-specific.  Depending on the configuration and operating system
5569 facilities, GDB may be able to show you this information.  For remote
5570 targets, this functionality may further depend on the remote stub's
5571 support of the `qPart:auxv:read' packet, see *Note auxiliary vector:
5572 Remote configuration.
5574 `info auxv'
5575      Display the auxiliary vector of the inferior, which can be either a
5576      live process or a core dump file.  GDB prints each tag value
5577      numerically, and also shows names and text descriptions for
5578      recognized tags.  Some values in the vector are numbers, some bit
5579      masks, and some pointers to strings or other data.  GDB displays
5580      each value in the most appropriate form for a recognized tag, and
5581      in hexadecimal for an unrecognized tag.
5583 \x1f
5584 File: gdb.info,  Node: Memory Region Attributes,  Next: Dump/Restore Files,  Prev: OS Information,  Up: Data
5586 8.14 Memory region attributes
5587 =============================
5589 "Memory region attributes" allow you to describe special handling
5590 required by regions of your target's memory.  GDB uses attributes to
5591 determine whether to allow certain types of memory accesses; whether to
5592 use specific width accesses; and whether to cache target memory.
5594    Defined memory regions can be individually enabled and disabled.
5595 When a memory region is disabled, GDB uses the default attributes when
5596 accessing memory in that region.  Similarly, if no memory regions have
5597 been defined, GDB uses the default attributes when accessing all memory.
5599    When a memory region is defined, it is given a number to identify it;
5600 to enable, disable, or remove a memory region, you specify that number.
5602 `mem LOWER UPPER ATTRIBUTES...'
5603      Define a memory region bounded by LOWER and UPPER with attributes
5604      ATTRIBUTES..., and add it to the list of regions monitored by GDB.
5605      Note that UPPER == 0 is a special case: it is treated as the the
5606      target's maximum memory address.  (0xffff on 16 bit targets,
5607      0xffffffff on 32 bit targets, etc.)
5609 `delete mem NUMS...'
5610      Remove memory regions NUMS... from the list of regions monitored
5611      by GDB.
5613 `disable mem NUMS...'
5614      Disable monitoring of memory regions NUMS....  A disabled memory
5615      region is not forgotten.  It may be enabled again later.
5617 `enable mem NUMS...'
5618      Enable monitoring of memory regions NUMS....
5620 `info mem'
5621      Print a table of all defined memory regions, with the following
5622      columns for each region:
5624     _Memory Region Number_
5626     _Enabled or Disabled._
5627           Enabled memory regions are marked with `y'.  Disabled memory
5628           regions are marked with `n'.
5630     _Lo Address_
5631           The address defining the inclusive lower bound of the memory
5632           region.
5634     _Hi Address_
5635           The address defining the exclusive upper bound of the memory
5636           region.
5638     _Attributes_
5639           The list of attributes set for this memory region.
5641 8.14.1 Attributes
5642 -----------------
5644 8.14.1.1 Memory Access Mode
5645 ...........................
5647 The access mode attributes set whether GDB may make read or write
5648 accesses to a memory region.
5650    While these attributes prevent GDB from performing invalid memory
5651 accesses, they do nothing to prevent the target system, I/O DMA, etc.
5652 from accessing memory.
5654 `ro'
5655      Memory is read only.
5657 `wo'
5658      Memory is write only.
5660 `rw'
5661      Memory is read/write.  This is the default.
5663 8.14.1.2 Memory Access Size
5664 ...........................
5666 The acccess size attributes tells GDB to use specific sized accesses in
5667 the memory region.  Often memory mapped device registers require
5668 specific sized accesses.  If no access size attribute is specified, GDB
5669 may use accesses of any size.
5672      Use 8 bit memory accesses.
5674 `16'
5675      Use 16 bit memory accesses.
5677 `32'
5678      Use 32 bit memory accesses.
5680 `64'
5681      Use 64 bit memory accesses.
5683 8.14.1.3 Data Cache
5684 ...................
5686 The data cache attributes set whether GDB will cache target memory.
5687 While this generally improves performance by reducing debug protocol
5688 overhead, it can lead to incorrect results because GDB does not know
5689 about volatile variables or memory mapped device registers.
5691 `cache'
5692      Enable GDB to cache target memory.
5694 `nocache'
5695      Disable GDB from caching target memory.  This is the default.
5697 \x1f
5698 File: gdb.info,  Node: Dump/Restore Files,  Next: Core File Generation,  Prev: Memory Region Attributes,  Up: Data
5700 8.15 Copy between memory and a file
5701 ===================================
5703 You can use the commands `dump', `append', and `restore' to copy data
5704 between target memory and a file.  The `dump' and `append' commands
5705 write data to a file, and the `restore' command reads data from a file
5706 back into the inferior's memory.  Files may be in binary, Motorola
5707 S-record, Intel hex, or Tektronix Hex format; however, GDB can only
5708 append to binary files.
5710 `dump [FORMAT] memory FILENAME START_ADDR END_ADDR'
5711 `dump [FORMAT] value FILENAME EXPR'
5712      Dump the contents of memory from START_ADDR to END_ADDR, or the
5713      value of EXPR, to FILENAME in the given format.
5715      The FORMAT parameter may be any one of:
5716     `binary'
5717           Raw binary form.
5719     `ihex'
5720           Intel hex format.
5722     `srec'
5723           Motorola S-record format.
5725     `tekhex'
5726           Tektronix Hex format.
5728      GDB uses the same definitions of these formats as the GNU binary
5729      utilities, like `objdump' and `objcopy'.  If FORMAT is omitted,
5730      GDB dumps the data in raw binary form.
5732 `append [binary] memory FILENAME START_ADDR END_ADDR'
5733 `append [binary] value FILENAME EXPR'
5734      Append the contents of memory from START_ADDR to END_ADDR, or the
5735      value of EXPR, to the file FILENAME, in raw binary form.  (GDB can
5736      only append data to files in raw binary form.)
5738 `restore FILENAME [binary] BIAS START END'
5739      Restore the contents of file FILENAME into memory.  The `restore'
5740      command can automatically recognize any known BFD file format,
5741      except for raw binary.  To restore a raw binary file you must
5742      specify the optional keyword `binary' after the filename.
5744      If BIAS is non-zero, its value will be added to the addresses
5745      contained in the file.  Binary files always start at address zero,
5746      so they will be restored at address BIAS.  Other bfd files have a
5747      built-in location; they will be restored at offset BIAS from that
5748      location.
5750      If START and/or END are non-zero, then only data between file
5751      offset START and file offset END will be restored.  These offsets
5752      are relative to the addresses in the file, before the BIAS
5753      argument is applied.
5756 \x1f
5757 File: gdb.info,  Node: Core File Generation,  Next: Character Sets,  Prev: Dump/Restore Files,  Up: Data
5759 8.16 How to Produce a Core File from Your Program
5760 =================================================
5762 A "core file" or "core dump" is a file that records the memory image of
5763 a running process and its process status (register values etc.).  Its
5764 primary use is post-mortem debugging of a program that crashed while it
5765 ran outside a debugger.  A program that crashes automatically produces
5766 a core file, unless this feature is disabled by the user.  *Note
5767 Files::, for information on invoking GDB in the post-mortem debugging
5768 mode.
5770    Occasionally, you may wish to produce a core file of the program you
5771 are debugging in order to preserve a snapshot of its state.  GDB has a
5772 special command for that.
5774 `generate-core-file [FILE]'
5775 `gcore [FILE]'
5776      Produce a core dump of the inferior process.  The optional argument
5777      FILE specifies the file name where to put the core dump.  If not
5778      specified, the file name defaults to `core.PID', where PID is the
5779      inferior process ID.
5781      Note that this command is implemented only for some systems (as of
5782      this writing, GNU/Linux, FreeBSD, Solaris, Unixware, and S390).
5784 \x1f
5785 File: gdb.info,  Node: Character Sets,  Next: Caching Remote Data,  Prev: Core File Generation,  Up: Data
5787 8.17 Character Sets
5788 ===================
5790 If the program you are debugging uses a different character set to
5791 represent characters and strings than the one GDB uses itself, GDB can
5792 automatically translate between the character sets for you.  The
5793 character set GDB uses we call the "host character set"; the one the
5794 inferior program uses we call the "target character set".
5796    For example, if you are running GDB on a GNU/Linux system, which
5797 uses the ISO Latin 1 character set, but you are using GDB's remote
5798 protocol (*note Remote Debugging: Remote.) to debug a program running
5799 on an IBM mainframe, which uses the EBCDIC character set, then the host
5800 character set is Latin-1, and the target character set is EBCDIC.  If
5801 you give GDB the command `set target-charset EBCDIC-US', then GDB
5802 translates between EBCDIC and Latin 1 as you print character or string
5803 values, or use character and string literals in expressions.
5805    GDB has no way to automatically recognize which character set the
5806 inferior program uses; you must tell it, using the `set target-charset'
5807 command, described below.
5809    Here are the commands for controlling GDB's character set support:
5811 `set target-charset CHARSET'
5812      Set the current target character set to CHARSET.  We list the
5813      character set names GDB recognizes below, but if you type `set
5814      target-charset' followed by <TAB><TAB>, GDB will list the target
5815      character sets it supports.
5817 `set host-charset CHARSET'
5818      Set the current host character set to CHARSET.
5820      By default, GDB uses a host character set appropriate to the
5821      system it is running on; you can override that default using the
5822      `set host-charset' command.
5824      GDB can only use certain character sets as its host character set.
5825      We list the character set names GDB recognizes below, and
5826      indicate which can be host character sets, but if you type `set
5827      target-charset' followed by <TAB><TAB>, GDB will list the host
5828      character sets it supports.
5830 `set charset CHARSET'
5831      Set the current host and target character sets to CHARSET.  As
5832      above, if you type `set charset' followed by <TAB><TAB>, GDB will
5833      list the name of the character sets that can be used for both host
5834      and target.
5836 `show charset'
5837      Show the names of the current host and target charsets.
5839 `show host-charset'
5840      Show the name of the current host charset.
5842 `show target-charset'
5843      Show the name of the current target charset.
5846    GDB currently includes support for the following character sets:
5848 `ASCII'
5849      Seven-bit U.S. ASCII.  GDB can use this as its host character set.
5851 `ISO-8859-1'
5852      The ISO Latin 1 character set.  This extends ASCII with accented
5853      characters needed for French, German, and Spanish.  GDB can use
5854      this as its host character set.
5856 `EBCDIC-US'
5857 `IBM1047'
5858      Variants of the EBCDIC character set, used on some of IBM's
5859      mainframe operating systems.  (GNU/Linux on the S/390 uses U.S.
5860      ASCII.)  GDB cannot use these as its host character set.
5863    Note that these are all single-byte character sets.  More work inside
5864 GDB is needed to support multi-byte or variable-width character
5865 encodings, like the UTF-8 and UCS-2 encodings of Unicode.
5867    Here is an example of GDB's character set support in action.  Assume
5868 that the following source code has been placed in the file
5869 `charset-test.c':
5871      #include <stdio.h>
5873      char ascii_hello[]
5874        = {72, 101, 108, 108, 111, 44, 32, 119,
5875           111, 114, 108, 100, 33, 10, 0};
5876      char ibm1047_hello[]
5877        = {200, 133, 147, 147, 150, 107, 64, 166,
5878           150, 153, 147, 132, 90, 37, 0};
5880      main ()
5881      {
5882        printf ("Hello, world!\n");
5883      }
5885    In this program, `ascii_hello' and `ibm1047_hello' are arrays
5886 containing the string `Hello, world!' followed by a newline, encoded in
5887 the ASCII and IBM1047 character sets.
5889    We compile the program, and invoke the debugger on it:
5891      $ gcc -g charset-test.c -o charset-test
5892      $ gdb -nw charset-test
5893      GNU gdb 2001-12-19-cvs
5894      Copyright 2001 Free Software Foundation, Inc.
5895      ...
5896      (gdb)
5898    We can use the `show charset' command to see what character sets GDB
5899 is currently using to interpret and display characters and strings:
5901      (gdb) show charset
5902      The current host and target character set is `ISO-8859-1'.
5903      (gdb)
5905    For the sake of printing this manual, let's use ASCII as our initial
5906 character set:
5907      (gdb) set charset ASCII
5908      (gdb) show charset
5909      The current host and target character set is `ASCII'.
5910      (gdb)
5912    Let's assume that ASCII is indeed the correct character set for our
5913 host system -- in other words, let's assume that if GDB prints
5914 characters using the ASCII character set, our terminal will display
5915 them properly.  Since our current target character set is also ASCII,
5916 the contents of `ascii_hello' print legibly:
5918      (gdb) print ascii_hello
5919      $1 = 0x401698 "Hello, world!\n"
5920      (gdb) print ascii_hello[0]
5921      $2 = 72 'H'
5922      (gdb)
5924    GDB uses the target character set for character and string literals
5925 you use in expressions:
5927      (gdb) print '+'
5928      $3 = 43 '+'
5929      (gdb)
5931    The ASCII character set uses the number 43 to encode the `+'
5932 character.
5934    GDB relies on the user to tell it which character set the target
5935 program uses.  If we print `ibm1047_hello' while our target character
5936 set is still ASCII, we get jibberish:
5938      (gdb) print ibm1047_hello
5939      $4 = 0x4016a8 "\310\205\223\223\226k@\246\226\231\223\204Z%"
5940      (gdb) print ibm1047_hello[0]
5941      $5 = 200 '\310'
5942      (gdb)
5944    If we invoke the `set target-charset' followed by <TAB><TAB>, GDB
5945 tells us the character sets it supports:
5947      (gdb) set target-charset
5948      ASCII       EBCDIC-US   IBM1047     ISO-8859-1
5949      (gdb) set target-charset
5951    We can select IBM1047 as our target character set, and examine the
5952 program's strings again.  Now the ASCII string is wrong, but GDB
5953 translates the contents of `ibm1047_hello' from the target character
5954 set, IBM1047, to the host character set, ASCII, and they display
5955 correctly:
5957      (gdb) set target-charset IBM1047
5958      (gdb) show charset
5959      The current host character set is `ASCII'.
5960      The current target character set is `IBM1047'.
5961      (gdb) print ascii_hello
5962      $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
5963      (gdb) print ascii_hello[0]
5964      $7 = 72 '\110'
5965      (gdb) print ibm1047_hello
5966      $8 = 0x4016a8 "Hello, world!\n"
5967      (gdb) print ibm1047_hello[0]
5968      $9 = 200 'H'
5969      (gdb)
5971    As above, GDB uses the target character set for character and string
5972 literals you use in expressions:
5974      (gdb) print '+'
5975      $10 = 78 '+'
5976      (gdb)
5978    The IBM1047 character set uses the number 78 to encode the `+'
5979 character.
5981 \x1f
5982 File: gdb.info,  Node: Caching Remote Data,  Prev: Character Sets,  Up: Data
5984 8.18 Caching Data of Remote Targets
5985 ===================================
5987 GDB can cache data exchanged between the debugger and a remote target
5988 (*note Remote::).  Such caching generally improves performance, because
5989 it reduces the overhead of the remote protocol by bundling memory reads
5990 and writes into large chunks.  Unfortunately, GDB does not currently
5991 know anything about volatile registers, and thus data caching will
5992 produce incorrect results when volatile registers are in use.
5994 `set remotecache on'
5995 `set remotecache off'
5996      Set caching state for remote targets.  When `ON', use data
5997      caching.  By default, this option is `OFF'.
5999 `show remotecache'
6000      Show the current state of data caching for remote targets.
6002 `info dcache'
6003      Print the information about the data cache performance.  The
6004      information displayed includes: the dcache width and depth; and for
6005      each cache line, how many times it was referenced, and its data and
6006      state (dirty, bad, ok, etc.).  This command is useful for debugging
6007      the data cache operation.
6009 \x1f
6010 File: gdb.info,  Node: Macros,  Next: Tracepoints,  Prev: Data,  Up: Top
6012 9 C Preprocessor Macros
6013 ***********************
6015 Some languages, such as C and C++, provide a way to define and invoke
6016 "preprocessor macros" which expand into strings of tokens.  GDB can
6017 evaluate expressions containing macro invocations, show the result of
6018 macro expansion, and show a macro's definition, including where it was
6019 defined.
6021    You may need to compile your program specially to provide GDB with
6022 information about preprocessor macros.  Most compilers do not include
6023 macros in their debugging information, even when you compile with the
6024 `-g' flag.  *Note Compilation::.
6026    A program may define a macro at one point, remove that definition
6027 later, and then provide a different definition after that.  Thus, at
6028 different points in the program, a macro may have different
6029 definitions, or have no definition at all.  If there is a current stack
6030 frame, GDB uses the macros in scope at that frame's source code line.
6031 Otherwise, GDB uses the macros in scope at the current listing location;
6032 see *Note List::.
6034    At the moment, GDB does not support the `##' token-splicing
6035 operator, the `#' stringification operator, or variable-arity macros.
6037    Whenever GDB evaluates an expression, it always expands any macro
6038 invocations present in the expression.  GDB also provides the following
6039 commands for working with macros explicitly.
6041 `macro expand EXPRESSION'
6042 `macro exp EXPRESSION'
6043      Show the results of expanding all preprocessor macro invocations in
6044      EXPRESSION.  Since GDB simply expands macros, but does not parse
6045      the result, EXPRESSION need not be a valid expression; it can be
6046      any string of tokens.
6048 `macro expand-once EXPRESSION'
6049 `macro exp1 EXPRESSION'
6050      (This command is not yet implemented.)  Show the results of
6051      expanding those preprocessor macro invocations that appear
6052      explicitly in EXPRESSION.  Macro invocations appearing in that
6053      expansion are left unchanged.  This command allows you to see the
6054      effect of a particular macro more clearly, without being confused
6055      by further expansions.  Since GDB simply expands macros, but does
6056      not parse the result, EXPRESSION need not be a valid expression; it
6057      can be any string of tokens.
6059 `info macro MACRO'
6060      Show the definition of the macro named MACRO, and describe the
6061      source location where that definition was established.
6063 `macro define MACRO REPLACEMENT-LIST'
6064 `macro define MACRO(ARGLIST) REPLACEMENT-LIST'
6065      (This command is not yet implemented.)  Introduce a definition for
6066      a preprocessor macro named MACRO, invocations of which are replaced
6067      by the tokens given in REPLACEMENT-LIST.  The first form of this
6068      command defines an "object-like" macro, which takes no arguments;
6069      the second form defines a "function-like" macro, which takes the
6070      arguments given in ARGLIST.
6072      A definition introduced by this command is in scope in every
6073      expression evaluated in GDB, until it is removed with the `macro
6074      undef' command, described below.  The definition overrides all
6075      definitions for MACRO present in the program being debugged, as
6076      well as any previous user-supplied definition.
6078 `macro undef MACRO'
6079      (This command is not yet implemented.)  Remove any user-supplied
6080      definition for the macro named MACRO.  This command only affects
6081      definitions provided with the `macro define' command, described
6082      above; it cannot remove definitions present in the program being
6083      debugged.
6085 `macro list'
6086      (This command is not yet implemented.)  List all the macros
6087      defined using the `macro define' command.
6089    Here is a transcript showing the above commands in action.  First, we
6090 show our source files:
6092      $ cat sample.c
6093      #include <stdio.h>
6094      #include "sample.h"
6096      #define M 42
6097      #define ADD(x) (M + x)
6099      main ()
6100      {
6101      #define N 28
6102        printf ("Hello, world!\n");
6103      #undef N
6104        printf ("We're so creative.\n");
6105      #define N 1729
6106        printf ("Goodbye, world!\n");
6107      }
6108      $ cat sample.h
6109      #define Q <
6110      $
6112    Now, we compile the program using the GNU C compiler, GCC.  We pass
6113 the `-gdwarf-2' and `-g3' flags to ensure the compiler includes
6114 information about preprocessor macros in the debugging information.
6116      $ gcc -gdwarf-2 -g3 sample.c -o sample
6117      $
6119    Now, we start GDB on our sample program:
6121      $ gdb -nw sample
6122      GNU gdb 2002-05-06-cvs
6123      Copyright 2002 Free Software Foundation, Inc.
6124      GDB is free software, ...
6125      (gdb)
6127    We can expand macros and examine their definitions, even when the
6128 program is not running.  GDB uses the current listing position to
6129 decide which macro definitions are in scope:
6131      (gdb) list main
6132      3
6133      4       #define M 42
6134      5       #define ADD(x) (M + x)
6135      6
6136      7       main ()
6137      8       {
6138      9       #define N 28
6139      10        printf ("Hello, world!\n");
6140      11      #undef N
6141      12        printf ("We're so creative.\n");
6142      (gdb) info macro ADD
6143      Defined at /home/jimb/gdb/macros/play/sample.c:5
6144      #define ADD(x) (M + x)
6145      (gdb) info macro Q
6146      Defined at /home/jimb/gdb/macros/play/sample.h:1
6147        included at /home/jimb/gdb/macros/play/sample.c:2
6148      #define Q <
6149      (gdb) macro expand ADD(1)
6150      expands to: (42 + 1)
6151      (gdb) macro expand-once ADD(1)
6152      expands to: once (M + 1)
6153      (gdb)
6155    In the example above, note that `macro expand-once' expands only the
6156 macro invocation explicit in the original text -- the invocation of
6157 `ADD' -- but does not expand the invocation of the macro `M', which was
6158 introduced by `ADD'.
6160    Once the program is running, GDB uses the macro definitions in force
6161 at the source line of the current stack frame:
6163      (gdb) break main
6164      Breakpoint 1 at 0x8048370: file sample.c, line 10.
6165      (gdb) run
6166      Starting program: /home/jimb/gdb/macros/play/sample
6168      Breakpoint 1, main () at sample.c:10
6169      10        printf ("Hello, world!\n");
6170      (gdb)
6172    At line 10, the definition of the macro `N' at line 9 is in force:
6174      (gdb) info macro N
6175      Defined at /home/jimb/gdb/macros/play/sample.c:9
6176      #define N 28
6177      (gdb) macro expand N Q M
6178      expands to: 28 < 42
6179      (gdb) print N Q M
6180      $1 = 1
6181      (gdb)
6183    As we step over directives that remove `N''s definition, and then
6184 give it a new definition, GDB finds the definition (or lack thereof) in
6185 force at each point:
6187      (gdb) next
6188      Hello, world!
6189      12        printf ("We're so creative.\n");
6190      (gdb) info macro N
6191      The symbol `N' has no definition as a C/C++ preprocessor macro
6192      at /home/jimb/gdb/macros/play/sample.c:12
6193      (gdb) next
6194      We're so creative.
6195      14        printf ("Goodbye, world!\n");
6196      (gdb) info macro N
6197      Defined at /home/jimb/gdb/macros/play/sample.c:13
6198      #define N 1729
6199      (gdb) macro expand N Q M
6200      expands to: 1729 < 42
6201      (gdb) print N Q M
6202      $2 = 0
6203      (gdb)
6205 \x1f
6206 File: gdb.info,  Node: Tracepoints,  Next: Overlays,  Prev: Macros,  Up: Top
6208 10 Tracepoints
6209 **************
6211 In some applications, it is not feasible for the debugger to interrupt
6212 the program's execution long enough for the developer to learn anything
6213 helpful about its behavior.  If the program's correctness depends on
6214 its real-time behavior, delays introduced by a debugger might cause the
6215 program to change its behavior drastically, or perhaps fail, even when
6216 the code itself is correct.  It is useful to be able to observe the
6217 program's behavior without interrupting it.
6219    Using GDB's `trace' and `collect' commands, you can specify
6220 locations in the program, called "tracepoints", and arbitrary
6221 expressions to evaluate when those tracepoints are reached.  Later,
6222 using the `tfind' command, you can examine the values those expressions
6223 had when the program hit the tracepoints.  The expressions may also
6224 denote objects in memory--structures or arrays, for example--whose
6225 values GDB should record; while visiting a particular tracepoint, you
6226 may inspect those objects as if they were in memory at that moment.
6227 However, because GDB records these values without interacting with you,
6228 it can do so quickly and unobtrusively, hopefully not disturbing the
6229 program's behavior.
6231    The tracepoint facility is currently available only for remote
6232 targets.  *Note Targets::.  In addition, your remote target must know
6233 how to collect trace data.  This functionality is implemented in the
6234 remote stub; however, none of the stubs distributed with GDB support
6235 tracepoints as of this writing.  The format of the remote packets used
6236 to implement tracepoints are described in *Note Tracepoint Packets::.
6238    This chapter describes the tracepoint commands and features.
6240 * Menu:
6242 * Set Tracepoints::
6243 * Analyze Collected Data::
6244 * Tracepoint Variables::
6246 \x1f
6247 File: gdb.info,  Node: Set Tracepoints,  Next: Analyze Collected Data,  Up: Tracepoints
6249 10.1 Commands to Set Tracepoints
6250 ================================
6252 Before running such a "trace experiment", an arbitrary number of
6253 tracepoints can be set.  Like a breakpoint (*note Set Breaks::), a
6254 tracepoint has a number assigned to it by GDB.  Like with breakpoints,
6255 tracepoint numbers are successive integers starting from one.  Many of
6256 the commands associated with tracepoints take the tracepoint number as
6257 their argument, to identify which tracepoint to work on.
6259    For each tracepoint, you can specify, in advance, some arbitrary set
6260 of data that you want the target to collect in the trace buffer when it
6261 hits that tracepoint.  The collected data can include registers, local
6262 variables, or global data.  Later, you can use GDB commands to examine
6263 the values these data had at the time the tracepoint was hit.
6265    This section describes commands to set tracepoints and associated
6266 conditions and actions.
6268 * Menu:
6270 * Create and Delete Tracepoints::
6271 * Enable and Disable Tracepoints::
6272 * Tracepoint Passcounts::
6273 * Tracepoint Actions::
6274 * Listing Tracepoints::
6275 * Starting and Stopping Trace Experiment::
6277 \x1f
6278 File: gdb.info,  Node: Create and Delete Tracepoints,  Next: Enable and Disable Tracepoints,  Up: Set Tracepoints
6280 10.1.1 Create and Delete Tracepoints
6281 ------------------------------------
6283 `trace'
6284      The `trace' command is very similar to the `break' command.  Its
6285      argument can be a source line, a function name, or an address in
6286      the target program.  *Note Set Breaks::.  The `trace' command
6287      defines a tracepoint, which is a point in the target program where
6288      the debugger will briefly stop, collect some data, and then allow
6289      the program to continue.  Setting a tracepoint or changing its
6290      commands doesn't take effect until the next `tstart' command;
6291      thus, you cannot change the tracepoint attributes once a trace
6292      experiment is running.
6294      Here are some examples of using the `trace' command:
6296           (gdb) trace foo.c:121    // a source file and line number
6298           (gdb) trace +2           // 2 lines forward
6300           (gdb) trace my_function  // first source line of function
6302           (gdb) trace *my_function // EXACT start address of function
6304           (gdb) trace *0x2117c4    // an address
6306      You can abbreviate `trace' as `tr'.
6308      The convenience variable `$tpnum' records the tracepoint number of
6309      the most recently set tracepoint.
6311 `delete tracepoint [NUM]'
6312      Permanently delete one or more tracepoints.  With no argument, the
6313      default is to delete all tracepoints.
6315      Examples:
6317           (gdb) delete trace 1 2 3 // remove three tracepoints
6319           (gdb) delete trace       // remove all tracepoints
6321      You can abbreviate this command as `del tr'.
6323 \x1f
6324 File: gdb.info,  Node: Enable and Disable Tracepoints,  Next: Tracepoint Passcounts,  Prev: Create and Delete Tracepoints,  Up: Set Tracepoints
6326 10.1.2 Enable and Disable Tracepoints
6327 -------------------------------------
6329 `disable tracepoint [NUM]'
6330      Disable tracepoint NUM, or all tracepoints if no argument NUM is
6331      given.  A disabled tracepoint will have no effect during the next
6332      trace experiment, but it is not forgotten.  You can re-enable a
6333      disabled tracepoint using the `enable tracepoint' command.
6335 `enable tracepoint [NUM]'
6336      Enable tracepoint NUM, or all tracepoints.  The enabled
6337      tracepoints will become effective the next time a trace experiment
6338      is run.
6340 \x1f
6341 File: gdb.info,  Node: Tracepoint Passcounts,  Next: Tracepoint Actions,  Prev: Enable and Disable Tracepoints,  Up: Set Tracepoints
6343 10.1.3 Tracepoint Passcounts
6344 ----------------------------
6346 `passcount [N [NUM]]'
6347      Set the "passcount" of a tracepoint.  The passcount is a way to
6348      automatically stop a trace experiment.  If a tracepoint's
6349      passcount is N, then the trace experiment will be automatically
6350      stopped on the N'th time that tracepoint is hit.  If the
6351      tracepoint number NUM is not specified, the `passcount' command
6352      sets the passcount of the most recently defined tracepoint.  If no
6353      passcount is given, the trace experiment will run until stopped
6354      explicitly by the user.
6356      Examples:
6358           (gdb) passcount 5 2 // Stop on the 5th execution of
6359                                         `// tracepoint 2'
6361           (gdb) passcount 12  // Stop on the 12th execution of the
6362                                         `// most recently defined tracepoint.'
6363           (gdb) trace foo
6364           (gdb) pass 3
6365           (gdb) trace bar
6366           (gdb) pass 2
6367           (gdb) trace baz
6368           (gdb) pass 1        // Stop tracing when foo has been
6369                                          `// executed 3 times OR when bar has'
6370                                          `// been executed 2 times'
6371                                          `// OR when baz has been executed 1 time.'
6374 \x1f
6375 File: gdb.info,  Node: Tracepoint Actions,  Next: Listing Tracepoints,  Prev: Tracepoint Passcounts,  Up: Set Tracepoints
6377 10.1.4 Tracepoint Action Lists
6378 ------------------------------
6380 `actions [NUM]'
6381      This command will prompt for a list of actions to be taken when the
6382      tracepoint is hit.  If the tracepoint number NUM is not specified,
6383      this command sets the actions for the one that was most recently
6384      defined (so that you can define a tracepoint and then say
6385      `actions' without bothering about its number).  You specify the
6386      actions themselves on the following lines, one action at a time,
6387      and terminate the actions list with a line containing just `end'.
6388      So far, the only defined actions are `collect' and
6389      `while-stepping'.
6391      To remove all actions from a tracepoint, type `actions NUM' and
6392      follow it immediately with `end'.
6394           (gdb) collect DATA // collect some data
6396           (gdb) while-stepping 5 // single-step 5 times, collect data
6398           (gdb) end              // signals the end of actions.
6400      In the following example, the action list begins with `collect'
6401      commands indicating the things to be collected when the tracepoint
6402      is hit.  Then, in order to single-step and collect additional data
6403      following the tracepoint, a `while-stepping' command is used,
6404      followed by the list of things to be collected while stepping.  The
6405      `while-stepping' command is terminated by its own separate `end'
6406      command.  Lastly, the action list is terminated by an `end'
6407      command.
6409           (gdb) trace foo
6410           (gdb) actions
6411           Enter actions for tracepoint 1, one per line:
6412           > collect bar,baz
6413           > collect $regs
6414           > while-stepping 12
6415             > collect $fp, $sp
6416             > end
6417           end
6419 `collect EXPR1, EXPR2, ...'
6420      Collect values of the given expressions when the tracepoint is hit.
6421      This command accepts a comma-separated list of any valid
6422      expressions.  In addition to global, static, or local variables,
6423      the following special arguments are supported:
6425     `$regs'
6426           collect all registers
6428     `$args'
6429           collect all function arguments
6431     `$locals'
6432           collect all local variables.
6434      You can give several consecutive `collect' commands, each one with
6435      a single argument, or one `collect' command with several arguments
6436      separated by commas: the effect is the same.
6438      The command `info scope' (*note info scope: Symbols.) is
6439      particularly useful for figuring out what data to collect.
6441 `while-stepping N'
6442      Perform N single-step traces after the tracepoint, collecting new
6443      data at each step.  The `while-stepping' command is followed by
6444      the list of what to collect while stepping (followed by its own
6445      `end' command):
6447           > while-stepping 12
6448             > collect $regs, myglobal
6449             > end
6450           >
6452      You may abbreviate `while-stepping' as `ws' or `stepping'.
6454 \x1f
6455 File: gdb.info,  Node: Listing Tracepoints,  Next: Starting and Stopping Trace Experiment,  Prev: Tracepoint Actions,  Up: Set Tracepoints
6457 10.1.5 Listing Tracepoints
6458 --------------------------
6460 `info tracepoints [NUM]'
6461      Display information about the tracepoint NUM.  If you don't specify
6462      a tracepoint number, displays information about all the tracepoints
6463      defined so far.  For each tracepoint, the following information is
6464      shown:
6466         * its number
6468         * whether it is enabled or disabled
6470         * its address
6472         * its passcount as given by the `passcount N' command
6474         * its step count as given by the `while-stepping N' command
6476         * where in the source files is the tracepoint set
6478         * its action list as given by the `actions' command
6480           (gdb) info trace
6481           Num Enb Address    PassC StepC What
6482           1   y   0x002117c4 0     0     <gdb_asm>
6483           2   y   0x0020dc64 0     0     in g_test at g_test.c:1375
6484           3   y   0x0020b1f4 0     0     in get_data at ../foo.c:41
6485           (gdb)
6487      This command can be abbreviated `info tp'.
6489 \x1f
6490 File: gdb.info,  Node: Starting and Stopping Trace Experiment,  Prev: Listing Tracepoints,  Up: Set Tracepoints
6492 10.1.6 Starting and Stopping Trace Experiment
6493 ---------------------------------------------
6495 `tstart'
6496      This command takes no arguments.  It starts the trace experiment,
6497      and begins collecting data.  This has the side effect of
6498      discarding all the data collected in the trace buffer during the
6499      previous trace experiment.
6501 `tstop'
6502      This command takes no arguments.  It ends the trace experiment, and
6503      stops collecting data.
6505      *Note*: a trace experiment and data collection may stop
6506      automatically if any tracepoint's passcount is reached (*note
6507      Tracepoint Passcounts::), or if the trace buffer becomes full.
6509 `tstatus'
6510      This command displays the status of the current trace data
6511      collection.
6513    Here is an example of the commands we described so far:
6515      (gdb) trace gdb_c_test
6516      (gdb) actions
6517      Enter actions for tracepoint #1, one per line.
6518      > collect $regs,$locals,$args
6519      > while-stepping 11
6520        > collect $regs
6521        > end
6522      > end
6523      (gdb) tstart
6524         [time passes ...]
6525      (gdb) tstop
6527 \x1f
6528 File: gdb.info,  Node: Analyze Collected Data,  Next: Tracepoint Variables,  Prev: Set Tracepoints,  Up: Tracepoints
6530 10.2 Using the collected data
6531 =============================
6533 After the tracepoint experiment ends, you use GDB commands for
6534 examining the trace data.  The basic idea is that each tracepoint
6535 collects a trace "snapshot" every time it is hit and another snapshot
6536 every time it single-steps.  All these snapshots are consecutively
6537 numbered from zero and go into a buffer, and you can examine them
6538 later.  The way you examine them is to "focus" on a specific trace
6539 snapshot.  When the remote stub is focused on a trace snapshot, it will
6540 respond to all GDB requests for memory and registers by reading from
6541 the buffer which belongs to that snapshot, rather than from _real_
6542 memory or registers of the program being debugged.  This means that
6543 *all* GDB commands (`print', `info registers', `backtrace', etc.) will
6544 behave as if we were currently debugging the program state as it was
6545 when the tracepoint occurred.  Any requests for data that are not in
6546 the buffer will fail.
6548 * Menu:
6550 * tfind::                       How to select a trace snapshot
6551 * tdump::                       How to display all data for a snapshot
6552 * save-tracepoints::            How to save tracepoints for a future run
6554 \x1f
6555 File: gdb.info,  Node: tfind,  Next: tdump,  Up: Analyze Collected Data
6557 10.2.1 `tfind N'
6558 ----------------
6560 The basic command for selecting a trace snapshot from the buffer is
6561 `tfind N', which finds trace snapshot number N, counting from zero.  If
6562 no argument N is given, the next snapshot is selected.
6564    Here are the various forms of using the `tfind' command.
6566 `tfind start'
6567      Find the first snapshot in the buffer.  This is a synonym for
6568      `tfind 0' (since 0 is the number of the first snapshot).
6570 `tfind none'
6571      Stop debugging trace snapshots, resume _live_ debugging.
6573 `tfind end'
6574      Same as `tfind none'.
6576 `tfind'
6577      No argument means find the next trace snapshot.
6579 `tfind -'
6580      Find the previous trace snapshot before the current one.  This
6581      permits retracing earlier steps.
6583 `tfind tracepoint NUM'
6584      Find the next snapshot associated with tracepoint NUM.  Search
6585      proceeds forward from the last examined trace snapshot.  If no
6586      argument NUM is given, it means find the next snapshot collected
6587      for the same tracepoint as the current snapshot.
6589 `tfind pc ADDR'
6590      Find the next snapshot associated with the value ADDR of the
6591      program counter.  Search proceeds forward from the last examined
6592      trace snapshot.  If no argument ADDR is given, it means find the
6593      next snapshot with the same value of PC as the current snapshot.
6595 `tfind outside ADDR1, ADDR2'
6596      Find the next snapshot whose PC is outside the given range of
6597      addresses.
6599 `tfind range ADDR1, ADDR2'
6600      Find the next snapshot whose PC is between ADDR1 and ADDR2.
6602 `tfind line [FILE:]N'
6603      Find the next snapshot associated with the source line N.  If the
6604      optional argument FILE is given, refer to line N in that source
6605      file.  Search proceeds forward from the last examined trace
6606      snapshot.  If no argument N is given, it means find the next line
6607      other than the one currently being examined; thus saying `tfind
6608      line' repeatedly can appear to have the same effect as stepping
6609      from line to line in a _live_ debugging session.
6611    The default arguments for the `tfind' commands are specifically
6612 designed to make it easy to scan through the trace buffer.  For
6613 instance, `tfind' with no argument selects the next trace snapshot, and
6614 `tfind -' with no argument selects the previous trace snapshot.  So, by
6615 giving one `tfind' command, and then simply hitting <RET> repeatedly
6616 you can examine all the trace snapshots in order.  Or, by saying `tfind
6617 -' and then hitting <RET> repeatedly you can examine the snapshots in
6618 reverse order.  The `tfind line' command with no argument selects the
6619 snapshot for the next source line executed.  The `tfind pc' command with
6620 no argument selects the next snapshot with the same program counter
6621 (PC) as the current frame.  The `tfind tracepoint' command with no
6622 argument selects the next trace snapshot collected by the same
6623 tracepoint as the current one.
6625    In addition to letting you scan through the trace buffer manually,
6626 these commands make it easy to construct GDB scripts that scan through
6627 the trace buffer and print out whatever collected data you are
6628 interested in.  Thus, if we want to examine the PC, FP, and SP
6629 registers from each trace frame in the buffer, we can say this:
6631      (gdb) tfind start
6632      (gdb) while ($trace_frame != -1)
6633      > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6634                $trace_frame, $pc, $sp, $fp
6635      > tfind
6636      > end
6638      Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6639      Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6640      Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6641      Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6642      Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6643      Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6644      Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6645      Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6646      Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6647      Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6648      Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6650    Or, if we want to examine the variable `X' at each source line in
6651 the buffer:
6653      (gdb) tfind start
6654      (gdb) while ($trace_frame != -1)
6655      > printf "Frame %d, X == %d\n", $trace_frame, X
6656      > tfind line
6657      > end
6659      Frame 0, X = 1
6660      Frame 7, X = 2
6661      Frame 13, X = 255
6663 \x1f
6664 File: gdb.info,  Node: tdump,  Next: save-tracepoints,  Prev: tfind,  Up: Analyze Collected Data
6666 10.2.2 `tdump'
6667 --------------
6669 This command takes no arguments.  It prints all the data collected at
6670 the current trace snapshot.
6672      (gdb) trace 444
6673      (gdb) actions
6674      Enter actions for tracepoint #2, one per line:
6675      > collect $regs, $locals, $args, gdb_long_test
6676      > end
6678      (gdb) tstart
6680      (gdb) tfind line 444
6681      #0  gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
6682      at gdb_test.c:444
6683      444        printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
6685      (gdb) tdump
6686      Data collected at tracepoint 2, trace frame 1:
6687      d0             0xc4aa0085       -995491707
6688      d1             0x18     24
6689      d2             0x80     128
6690      d3             0x33     51
6691      d4             0x71aea3d        119204413
6692      d5             0x22     34
6693      d6             0xe0     224
6694      d7             0x380035 3670069
6695      a0             0x19e24a 1696330
6696      a1             0x3000668        50333288
6697      a2             0x100    256
6698      a3             0x322000 3284992
6699      a4             0x3000698        50333336
6700      a5             0x1ad3cc 1758156
6701      fp             0x30bf3c 0x30bf3c
6702      sp             0x30bf34 0x30bf34
6703      ps             0x0      0
6704      pc             0x20b2c8 0x20b2c8
6705      fpcontrol      0x0      0
6706      fpstatus       0x0      0
6707      fpiaddr        0x0      0
6708      p = 0x20e5b4 "gdb-test"
6709      p1 = (void *) 0x11
6710      p2 = (void *) 0x22
6711      p3 = (void *) 0x33
6712      p4 = (void *) 0x44
6713      p5 = (void *) 0x55
6714      p6 = (void *) 0x66
6715      gdb_long_test = 17 '\021'
6717      (gdb)
6719 \x1f
6720 File: gdb.info,  Node: save-tracepoints,  Prev: tdump,  Up: Analyze Collected Data
6722 10.2.3 `save-tracepoints FILENAME'
6723 ----------------------------------
6725 This command saves all current tracepoint definitions together with
6726 their actions and passcounts, into a file `FILENAME' suitable for use
6727 in a later debugging session.  To read the saved tracepoint
6728 definitions, use the `source' command (*note Command Files::).
6730 \x1f
6731 File: gdb.info,  Node: Tracepoint Variables,  Prev: Analyze Collected Data,  Up: Tracepoints
6733 10.3 Convenience Variables for Tracepoints
6734 ==========================================
6736 `(int) $trace_frame'
6737      The current trace snapshot (a.k.a. "frame") number, or -1 if no
6738      snapshot is selected.
6740 `(int) $tracepoint'
6741      The tracepoint for the current trace snapshot.
6743 `(int) $trace_line'
6744      The line number for the current trace snapshot.
6746 `(char []) $trace_file'
6747      The source file for the current trace snapshot.
6749 `(char []) $trace_func'
6750      The name of the function containing `$tracepoint'.
6752    Note: `$trace_file' is not suitable for use in `printf', use
6753 `output' instead.
6755    Here's a simple example of using these convenience variables for
6756 stepping through all the trace snapshots and printing some of their
6757 data.
6759      (gdb) tfind start
6761      (gdb) while $trace_frame != -1
6762      > output $trace_file
6763      > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
6764      > tfind
6765      > end
6767 \x1f
6768 File: gdb.info,  Node: Overlays,  Next: Languages,  Prev: Tracepoints,  Up: Top
6770 11 Debugging Programs That Use Overlays
6771 ***************************************
6773 If your program is too large to fit completely in your target system's
6774 memory, you can sometimes use "overlays" to work around this problem.
6775 GDB provides some support for debugging programs that use overlays.
6777 * Menu:
6779 * How Overlays Work::              A general explanation of overlays.
6780 * Overlay Commands::               Managing overlays in GDB.
6781 * Automatic Overlay Debugging::    GDB can find out which overlays are
6782                                    mapped by asking the inferior.
6783 * Overlay Sample Program::         A sample program using overlays.
6785 \x1f
6786 File: gdb.info,  Node: How Overlays Work,  Next: Overlay Commands,  Up: Overlays
6788 11.1 How Overlays Work
6789 ======================
6791 Suppose you have a computer whose instruction address space is only 64
6792 kilobytes long, but which has much more memory which can be accessed by
6793 other means: special instructions, segment registers, or memory
6794 management hardware, for example.  Suppose further that you want to
6795 adapt a program which is larger than 64 kilobytes to run on this system.
6797    One solution is to identify modules of your program which are
6798 relatively independent, and need not call each other directly; call
6799 these modules "overlays".  Separate the overlays from the main program,
6800 and place their machine code in the larger memory.  Place your main
6801 program in instruction memory, but leave at least enough space there to
6802 hold the largest overlay as well.
6804    Now, to call a function located in an overlay, you must first copy
6805 that overlay's machine code from the large memory into the space set
6806 aside for it in the instruction memory, and then jump to its entry point
6807 there.
6809          Data             Instruction            Larger
6810      Address Space       Address Space        Address Space
6811      +-----------+       +-----------+        +-----------+
6812      |           |       |           |        |           |
6813      +-----------+       +-----------+        +-----------+<-- overlay 1
6814      | program   |       |   main    |   .----| overlay 1 | load address
6815      | variables |       |  program  |   |    +-----------+
6816      | and heap  |       |           |   |    |           |
6817      +-----------+       |           |   |    +-----------+<-- overlay 2
6818      |           |       +-----------+   |    |           | load address
6819      +-----------+       |           |   |  .-| overlay 2 |
6820                          |           |   |  | |           |
6821               mapped --->+-----------+   |  | +-----------+
6822               address    |           |   |  | |           |
6823                          |  overlay  | <-'  | |           |
6824                          |   area    |  <---' +-----------+<-- overlay 3
6825                          |           | <---.  |           | load address
6826                          +-----------+     `--| overlay 3 |
6827                          |           |        |           |
6828                          +-----------+        |           |
6829                                               +-----------+
6830                                               |           |
6831                                               +-----------+
6833                          A code overlay
6835    The diagram (*note A code overlay::) shows a system with separate
6836 data and instruction address spaces.  To map an overlay, the program
6837 copies its code from the larger address space to the instruction
6838 address space.  Since the overlays shown here all use the same mapped
6839 address, only one may be mapped at a time.  For a system with a single
6840 address space for data and instructions, the diagram would be similar,
6841 except that the program variables and heap would share an address space
6842 with the main program and the overlay area.
6844    An overlay loaded into instruction memory and ready for use is
6845 called a "mapped" overlay; its "mapped address" is its address in the
6846 instruction memory.  An overlay not present (or only partially present)
6847 in instruction memory is called "unmapped"; its "load address" is its
6848 address in the larger memory.  The mapped address is also called the
6849 "virtual memory address", or "VMA"; the load address is also called the
6850 "load memory address", or "LMA".
6852    Unfortunately, overlays are not a completely transparent way to
6853 adapt a program to limited instruction memory.  They introduce a new
6854 set of global constraints you must keep in mind as you design your
6855 program:
6857    * Before calling or returning to a function in an overlay, your
6858      program must make sure that overlay is actually mapped.
6859      Otherwise, the call or return will transfer control to the right
6860      address, but in the wrong overlay, and your program will probably
6861      crash.
6863    * If the process of mapping an overlay is expensive on your system,
6864      you will need to choose your overlays carefully to minimize their
6865      effect on your program's performance.
6867    * The executable file you load onto your system must contain each
6868      overlay's instructions, appearing at the overlay's load address,
6869      not its mapped address.  However, each overlay's instructions must
6870      be relocated and its symbols defined as if the overlay were at its
6871      mapped address.  You can use GNU linker scripts to specify
6872      different load and relocation addresses for pieces of your
6873      program; see *Note Overlay Description: (ld.info)Overlay
6874      Description.
6876    * The procedure for loading executable files onto your system must
6877      be able to load their contents into the larger address space as
6878      well as the instruction and data spaces.
6881    The overlay system described above is rather simple, and could be
6882 improved in many ways:
6884    * If your system has suitable bank switch registers or memory
6885      management hardware, you could use those facilities to make an
6886      overlay's load area contents simply appear at their mapped address
6887      in instruction space.  This would probably be faster than copying
6888      the overlay to its mapped area in the usual way.
6890    * If your overlays are small enough, you could set aside more than
6891      one overlay area, and have more than one overlay mapped at a time.
6893    * You can use overlays to manage data, as well as instructions.  In
6894      general, data overlays are even less transparent to your design
6895      than code overlays: whereas code overlays only require care when
6896      you call or return to functions, data overlays require care every
6897      time you access the data.  Also, if you change the contents of a
6898      data overlay, you must copy its contents back out to its load
6899      address before you can copy a different data overlay into the same
6900      mapped area.
6903 \x1f
6904 File: gdb.info,  Node: Overlay Commands,  Next: Automatic Overlay Debugging,  Prev: How Overlays Work,  Up: Overlays
6906 11.2 Overlay Commands
6907 =====================
6909 To use GDB's overlay support, each overlay in your program must
6910 correspond to a separate section of the executable file.  The section's
6911 virtual memory address and load memory address must be the overlay's
6912 mapped and load addresses.  Identifying overlays with sections allows
6913 GDB to determine the appropriate address of a function or variable,
6914 depending on whether the overlay is mapped or not.
6916    GDB's overlay commands all start with the word `overlay'; you can
6917 abbreviate this as `ov' or `ovly'.  The commands are:
6919 `overlay off'
6920      Disable GDB's overlay support.  When overlay support is disabled,
6921      GDB assumes that all functions and variables are always present at
6922      their mapped addresses.  By default, GDB's overlay support is
6923      disabled.
6925 `overlay manual'
6926      Enable "manual" overlay debugging.  In this mode, GDB relies on
6927      you to tell it which overlays are mapped, and which are not, using
6928      the `overlay map-overlay' and `overlay unmap-overlay' commands
6929      described below.
6931 `overlay map-overlay OVERLAY'
6932 `overlay map OVERLAY'
6933      Tell GDB that OVERLAY is now mapped; OVERLAY must be the name of
6934      the object file section containing the overlay.  When an overlay
6935      is mapped, GDB assumes it can find the overlay's functions and
6936      variables at their mapped addresses.  GDB assumes that any other
6937      overlays whose mapped ranges overlap that of OVERLAY are now
6938      unmapped.
6940 `overlay unmap-overlay OVERLAY'
6941 `overlay unmap OVERLAY'
6942      Tell GDB that OVERLAY is no longer mapped; OVERLAY must be the
6943      name of the object file section containing the overlay.  When an
6944      overlay is unmapped, GDB assumes it can find the overlay's
6945      functions and variables at their load addresses.
6947 `overlay auto'
6948      Enable "automatic" overlay debugging.  In this mode, GDB consults
6949      a data structure the overlay manager maintains in the inferior to
6950      see which overlays are mapped.  For details, see *Note Automatic
6951      Overlay Debugging::.
6953 `overlay load-target'
6954 `overlay load'
6955      Re-read the overlay table from the inferior.  Normally, GDB
6956      re-reads the table GDB automatically each time the inferior stops,
6957      so this command should only be necessary if you have changed the
6958      overlay mapping yourself using GDB.  This command is only useful
6959      when using automatic overlay debugging.
6961 `overlay list-overlays'
6962 `overlay list'
6963      Display a list of the overlays currently mapped, along with their
6964      mapped addresses, load addresses, and sizes.
6967    Normally, when GDB prints a code address, it includes the name of
6968 the function the address falls in:
6970      (gdb) print main
6971      $3 = {int ()} 0x11a0 <main>
6972    When overlay debugging is enabled, GDB recognizes code in unmapped
6973 overlays, and prints the names of unmapped functions with asterisks
6974 around them.  For example, if `foo' is a function in an unmapped
6975 overlay, GDB prints it this way:
6977      (gdb) overlay list
6978      No sections are mapped.
6979      (gdb) print foo
6980      $5 = {int (int)} 0x100000 <*foo*>
6981    When `foo''s overlay is mapped, GDB prints the function's name
6982 normally:
6984      (gdb) overlay list
6985      Section .ov.foo.text, loaded at 0x100000 - 0x100034,
6986              mapped at 0x1016 - 0x104a
6987      (gdb) print foo
6988      $6 = {int (int)} 0x1016 <foo>
6990    When overlay debugging is enabled, GDB can find the correct address
6991 for functions and variables in an overlay, whether or not the overlay
6992 is mapped.  This allows most GDB commands, like `break' and
6993 `disassemble', to work normally, even on unmapped code.  However, GDB's
6994 breakpoint support has some limitations:
6996    * You can set breakpoints in functions in unmapped overlays, as long
6997      as GDB can write to the overlay at its load address.
6999    * GDB can not set hardware or simulator-based breakpoints in
7000      unmapped overlays.  However, if you set a breakpoint at the end of
7001      your overlay manager (and tell GDB which overlays are now mapped,
7002      if you are using manual overlay management), GDB will re-set its
7003      breakpoints properly.
7005 \x1f
7006 File: gdb.info,  Node: Automatic Overlay Debugging,  Next: Overlay Sample Program,  Prev: Overlay Commands,  Up: Overlays
7008 11.3 Automatic Overlay Debugging
7009 ================================
7011 GDB can automatically track which overlays are mapped and which are
7012 not, given some simple co-operation from the overlay manager in the
7013 inferior.  If you enable automatic overlay debugging with the `overlay
7014 auto' command (*note Overlay Commands::), GDB looks in the inferior's
7015 memory for certain variables describing the current state of the
7016 overlays.
7018    Here are the variables your overlay manager must define to support
7019 GDB's automatic overlay debugging:
7021 `_ovly_table':
7022      This variable must be an array of the following structures:
7024           struct
7025           {
7026             /* The overlay's mapped address.  */
7027             unsigned long vma;
7029             /* The size of the overlay, in bytes.  */
7030             unsigned long size;
7032             /* The overlay's load address.  */
7033             unsigned long lma;
7035             /* Non-zero if the overlay is currently mapped;
7036                zero otherwise.  */
7037             unsigned long mapped;
7038           }
7040 `_novlys':
7041      This variable must be a four-byte signed integer, holding the total
7042      number of elements in `_ovly_table'.
7045    To decide whether a particular overlay is mapped or not, GDB looks
7046 for an entry in `_ovly_table' whose `vma' and `lma' members equal the
7047 VMA and LMA of the overlay's section in the executable file.  When GDB
7048 finds a matching entry, it consults the entry's `mapped' member to
7049 determine whether the overlay is currently mapped.
7051    In addition, your overlay manager may define a function called
7052 `_ovly_debug_event'.  If this function is defined, GDB will silently
7053 set a breakpoint there.  If the overlay manager then calls this
7054 function whenever it has changed the overlay table, this will enable
7055 GDB to accurately keep track of which overlays are in program memory,
7056 and update any breakpoints that may be set in overlays.  This will
7057 allow breakpoints to work even if the overlays are kept in ROM or other
7058 non-writable memory while they are not being executed.
7060 \x1f
7061 File: gdb.info,  Node: Overlay Sample Program,  Prev: Automatic Overlay Debugging,  Up: Overlays
7063 11.4 Overlay Sample Program
7064 ===========================
7066 When linking a program which uses overlays, you must place the overlays
7067 at their load addresses, while relocating them to run at their mapped
7068 addresses.  To do this, you must write a linker script (*note Overlay
7069 Description: (ld.info)Overlay Description.).  Unfortunately, since
7070 linker scripts are specific to a particular host system, target
7071 architecture, and target memory layout, this manual cannot provide
7072 portable sample code demonstrating GDB's overlay support.
7074    However, the GDB source distribution does contain an overlaid
7075 program, with linker scripts for a few systems, as part of its test
7076 suite.  The program consists of the following files from
7077 `gdb/testsuite/gdb.base':
7079 `overlays.c'
7080      The main program file.
7082 `ovlymgr.c'
7083      A simple overlay manager, used by `overlays.c'.
7085 `foo.c'
7086 `bar.c'
7087 `baz.c'
7088 `grbx.c'
7089      Overlay modules, loaded and used by `overlays.c'.
7091 `d10v.ld'
7092 `m32r.ld'
7093      Linker scripts for linking the test program on the `d10v-elf' and
7094      `m32r-elf' targets.
7096    You can build the test program using the `d10v-elf' GCC
7097 cross-compiler like this:
7099      $ d10v-elf-gcc -g -c overlays.c
7100      $ d10v-elf-gcc -g -c ovlymgr.c
7101      $ d10v-elf-gcc -g -c foo.c
7102      $ d10v-elf-gcc -g -c bar.c
7103      $ d10v-elf-gcc -g -c baz.c
7104      $ d10v-elf-gcc -g -c grbx.c
7105      $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7106                        baz.o grbx.o -Wl,-Td10v.ld -o overlays
7108    The build process is identical for any other architecture, except
7109 that you must substitute the appropriate compiler and linker script for
7110 the target system for `d10v-elf-gcc' and `d10v.ld'.
7112 \x1f
7113 File: gdb.info,  Node: Languages,  Next: Symbols,  Prev: Overlays,  Up: Top
7115 12 Using GDB with Different Languages
7116 *************************************
7118 Although programming languages generally have common aspects, they are
7119 rarely expressed in the same manner.  For instance, in ANSI C,
7120 dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
7121 it is accomplished by `p^'.  Values can also be represented (and
7122 displayed) differently.  Hex numbers in C appear as `0x1ae', while in
7123 Modula-2 they appear as `1AEH'.
7125    Language-specific information is built into GDB for some languages,
7126 allowing you to express operations like the above in your program's
7127 native language, and allowing GDB to output values in a manner
7128 consistent with the syntax of your program's native language.  The
7129 language you use to build expressions is called the "working language".
7131 * Menu:
7133 * Setting::                     Switching between source languages
7134 * Show::                        Displaying the language
7135 * Checks::                      Type and range checks
7136 * Supported languages::         Supported languages
7137 * Unsupported languages::       Unsupported languages
7139 \x1f
7140 File: gdb.info,  Node: Setting,  Next: Show,  Up: Languages
7142 12.1 Switching between source languages
7143 =======================================
7145 There are two ways to control the working language--either have GDB set
7146 it automatically, or select it manually yourself.  You can use the `set
7147 language' command for either purpose.  On startup, GDB defaults to
7148 setting the language automatically.  The working language is used to
7149 determine how expressions you type are interpreted, how values are
7150 printed, etc.
7152    In addition to the working language, every source file that GDB
7153 knows about has its own working language.  For some object file
7154 formats, the compiler might indicate which language a particular source
7155 file is in.  However, most of the time GDB infers the language from the
7156 name of the file.  The language of a source file controls whether C++
7157 names are demangled--this way `backtrace' can show each frame
7158 appropriately for its own language.  There is no way to set the
7159 language of a source file from within GDB, but you can set the language
7160 associated with a filename extension.  *Note Displaying the language:
7161 Show.
7163    This is most commonly a problem when you use a program, such as
7164 `cfront' or `f2c', that generates C but is written in another language.
7165 In that case, make the program use `#line' directives in its C output;
7166 that way GDB will know the correct language of the source code of the
7167 original program, and will display that source code, not the generated
7168 C code.
7170 * Menu:
7172 * Filenames::                   Filename extensions and languages.
7173 * Manually::                    Setting the working language manually
7174 * Automatically::               Having GDB infer the source language
7176 \x1f
7177 File: gdb.info,  Node: Filenames,  Next: Manually,  Up: Setting
7179 12.1.1 List of filename extensions and languages
7180 ------------------------------------------------
7182 If a source file name ends in one of the following extensions, then GDB
7183 infers that its language is the one indicated.
7185 `.ada'
7186 `.ads'
7187 `.adb'
7188 `.a'
7189      Ada source file.
7191 `.c'
7192      C source file
7194 `.C'
7195 `.cc'
7196 `.cp'
7197 `.cpp'
7198 `.cxx'
7199 `.c++'
7200      C++ source file
7202 `.m'
7203      Objective-C source file
7205 `.f'
7206 `.F'
7207      Fortran source file
7209 `.mod'
7210      Modula-2 source file
7212 `.s'
7213 `.S'
7214      Assembler source file.  This actually behaves almost like C, but
7215      GDB does not skip over function prologues when stepping.
7217    In addition, you may set the language associated with a filename
7218 extension.  *Note Displaying the language: Show.
7220 \x1f
7221 File: gdb.info,  Node: Manually,  Next: Automatically,  Prev: Filenames,  Up: Setting
7223 12.1.2 Setting the working language
7224 -----------------------------------
7226 If you allow GDB to set the language automatically, expressions are
7227 interpreted the same way in your debugging session and your program.
7229    If you wish, you may set the language manually.  To do this, issue
7230 the command `set language LANG', where LANG is the name of a language,
7231 such as `c' or `modula-2'.  For a list of the supported languages, type
7232 `set language'.
7234    Setting the language manually prevents GDB from updating the working
7235 language automatically.  This can lead to confusion if you try to debug
7236 a program when the working language is not the same as the source
7237 language, when an expression is acceptable to both languages--but means
7238 different things.  For instance, if the current source file were
7239 written in C, and GDB was parsing Modula-2, a command such as:
7241      print a = b + c
7243 might not have the effect you intended.  In C, this means to add `b'
7244 and `c' and place the result in `a'.  The result printed would be the
7245 value of `a'.  In Modula-2, this means to compare `a' to the result of
7246 `b+c', yielding a `BOOLEAN' value.
7248 \x1f
7249 File: gdb.info,  Node: Automatically,  Prev: Manually,  Up: Setting
7251 12.1.3 Having GDB infer the source language
7252 -------------------------------------------
7254 To have GDB set the working language automatically, use `set language
7255 local' or `set language auto'.  GDB then infers the working language.
7256 That is, when your program stops in a frame (usually by encountering a
7257 breakpoint), GDB sets the working language to the language recorded for
7258 the function in that frame.  If the language for a frame is unknown
7259 (that is, if the function or block corresponding to the frame was
7260 defined in a source file that does not have a recognized extension),
7261 the current working language is not changed, and GDB issues a warning.
7263    This may not seem necessary for most programs, which are written
7264 entirely in one source language.  However, program modules and libraries
7265 written in one source language can be used by a main program written in
7266 a different source language.  Using `set language auto' in this case
7267 frees you from having to set the working language manually.
7269 \x1f
7270 File: gdb.info,  Node: Show,  Next: Checks,  Prev: Setting,  Up: Languages
7272 12.2 Displaying the language
7273 ============================
7275 The following commands help you find out which language is the working
7276 language, and also what language source files were written in.
7278 `show language'
7279      Display the current working language.  This is the language you
7280      can use with commands such as `print' to build and compute
7281      expressions that may involve variables in your program.
7283 `info frame'
7284      Display the source language for this frame.  This language becomes
7285      the working language if you use an identifier from this frame.
7286      *Note Information about a frame: Frame Info, to identify the other
7287      information listed here.
7289 `info source'
7290      Display the source language of this source file.  *Note Examining
7291      the Symbol Table: Symbols, to identify the other information
7292      listed here.
7294    In unusual circumstances, you may have source files with extensions
7295 not in the standard list.  You can then set the extension associated
7296 with a language explicitly:
7298 `set extension-language EXT LANGUAGE'
7299      Tell GDB that source files with extension EXT are to be assumed as
7300      written in the source language LANGUAGE.
7302 `info extensions'
7303      List all the filename extensions and the associated languages.
7305 \x1f
7306 File: gdb.info,  Node: Checks,  Next: Supported languages,  Prev: Show,  Up: Languages
7308 12.3 Type and range checking
7309 ============================
7311      _Warning:_ In this release, the GDB commands for type and range
7312      checking are included, but they do not yet have any effect.  This
7313      section documents the intended facilities.
7315    Some languages are designed to guard you against making seemingly
7316 common errors through a series of compile- and run-time checks.  These
7317 include checking the type of arguments to functions and operators, and
7318 making sure mathematical overflows are caught at run time.  Checks such
7319 as these help to ensure a program's correctness once it has been
7320 compiled by eliminating type mismatches, and providing active checks
7321 for range errors when your program is running.
7323    GDB can check for conditions like the above if you wish.  Although
7324 GDB does not check the statements in your program, it can check
7325 expressions entered directly into GDB for evaluation via the `print'
7326 command, for example.  As with the working language, GDB can also
7327 decide whether or not to check automatically based on your program's
7328 source language.  *Note Supported languages: Supported languages, for
7329 the default settings of supported languages.
7331 * Menu:
7333 * Type Checking::               An overview of type checking
7334 * Range Checking::              An overview of range checking
7336 \x1f
7337 File: gdb.info,  Node: Type Checking,  Next: Range Checking,  Up: Checks
7339 12.3.1 An overview of type checking
7340 -----------------------------------
7342 Some languages, such as Modula-2, are strongly typed, meaning that the
7343 arguments to operators and functions have to be of the correct type,
7344 otherwise an error occurs.  These checks prevent type mismatch errors
7345 from ever causing any run-time problems.  For example,
7347      1 + 2 => 3
7349      error--> 1 + 2.3
7351    The second example fails because the `CARDINAL' 1 is not
7352 type-compatible with the `REAL' 2.3.
7354    For the expressions you use in GDB commands, you can tell the GDB
7355 type checker to skip checking; to treat any mismatches as errors and
7356 abandon the expression; or to only issue warnings when type mismatches
7357 occur, but evaluate the expression anyway.  When you choose the last of
7358 these, GDB evaluates expressions like the second example above, but
7359 also issues a warning.
7361    Even if you turn type checking off, there may be other reasons
7362 related to type that prevent GDB from evaluating an expression.  For
7363 instance, GDB does not know how to add an `int' and a `struct foo'.
7364 These particular type errors have nothing to do with the language in
7365 use, and usually arise from expressions, such as the one described
7366 above, which make little sense to evaluate anyway.
7368    Each language defines to what degree it is strict about type.  For
7369 instance, both Modula-2 and C require the arguments to arithmetical
7370 operators to be numbers.  In C, enumerated types and pointers can be
7371 represented as numbers, so that they are valid arguments to mathematical
7372 operators.  *Note Supported languages: Supported languages, for further
7373 details on specific languages.
7375    GDB provides some additional commands for controlling the type
7376 checker:
7378 `set check type auto'
7379      Set type checking on or off based on the current working language.
7380      *Note Supported languages: Supported languages, for the default
7381      settings for each language.
7383 `set check type on'
7384 `set check type off'
7385      Set type checking on or off, overriding the default setting for the
7386      current working language.  Issue a warning if the setting does not
7387      match the language default.  If any type mismatches occur in
7388      evaluating an expression while type checking is on, GDB prints a
7389      message and aborts evaluation of the expression.
7391 `set check type warn'
7392      Cause the type checker to issue warnings, but to always attempt to
7393      evaluate the expression.  Evaluating the expression may still be
7394      impossible for other reasons.  For example, GDB cannot add numbers
7395      and structures.
7397 `show type'
7398      Show the current setting of the type checker, and whether or not
7399      GDB is setting it automatically.
7401 \x1f
7402 File: gdb.info,  Node: Range Checking,  Prev: Type Checking,  Up: Checks
7404 12.3.2 An overview of range checking
7405 ------------------------------------
7407 In some languages (such as Modula-2), it is an error to exceed the
7408 bounds of a type; this is enforced with run-time checks.  Such range
7409 checking is meant to ensure program correctness by making sure
7410 computations do not overflow, or indices on an array element access do
7411 not exceed the bounds of the array.
7413    For expressions you use in GDB commands, you can tell GDB to treat
7414 range errors in one of three ways: ignore them, always treat them as
7415 errors and abandon the expression, or issue warnings but evaluate the
7416 expression anyway.
7418    A range error can result from numerical overflow, from exceeding an
7419 array index bound, or when you type a constant that is not a member of
7420 any type.  Some languages, however, do not treat overflows as an error.
7421 In many implementations of C, mathematical overflow causes the result
7422 to "wrap around" to lower values--for example, if M is the largest
7423 integer value, and S is the smallest, then
7425      M + 1 => S
7427    This, too, is specific to individual languages, and in some cases
7428 specific to individual compilers or machines.  *Note Supported
7429 languages: Supported languages, for further details on specific
7430 languages.
7432    GDB provides some additional commands for controlling the range
7433 checker:
7435 `set check range auto'
7436      Set range checking on or off based on the current working language.
7437      *Note Supported languages: Supported languages, for the default
7438      settings for each language.
7440 `set check range on'
7441 `set check range off'
7442      Set range checking on or off, overriding the default setting for
7443      the current working language.  A warning is issued if the setting
7444      does not match the language default.  If a range error occurs and
7445      range checking is on, then a message is printed and evaluation of
7446      the expression is aborted.
7448 `set check range warn'
7449      Output messages when the GDB range checker detects a range error,
7450      but attempt to evaluate the expression anyway.  Evaluating the
7451      expression may still be impossible for other reasons, such as
7452      accessing memory that the process does not own (a typical example
7453      from many Unix systems).
7455 `show range'
7456      Show the current setting of the range checker, and whether or not
7457      it is being set automatically by GDB.