1This is gdb.info, produced by makeinfo version 4.13 from ./gdb.texinfo.
2
3INFO-DIR-SECTION Software development
4START-INFO-DIR-ENTRY
5* Gdb: (gdb).                     The GNU debugger.
6END-INFO-DIR-ENTRY
7
8   Copyright (C) 1988-2013 Free Software Foundation, Inc.
9
10   Permission is granted to copy, distribute and/or modify this document
11under the terms of the GNU Free Documentation License, Version 1.3 or
12any later version published by the Free Software Foundation; with the
13Invariant Sections being "Free Software" and "Free Software Needs Free
14Documentation", with the Front-Cover Texts being "A GNU Manual," and
15with the Back-Cover Texts as in (a) below.
16
17   (a) The FSF's Back-Cover Text is: "You are free to copy and modify
18this GNU Manual.  Buying copies from GNU Press supports the FSF in
19developing GNU and promoting software freedom."
20
21   This file documents the GNU debugger GDB.
22
23   This is the Tenth Edition, of `Debugging with GDB: the GNU
24Source-Level Debugger' for GDB (GDB) Version 7.6.1.
25
26   Copyright (C) 1988-2013 Free Software Foundation, Inc.
27
28   Permission is granted to copy, distribute and/or modify this document
29under the terms of the GNU Free Documentation License, Version 1.3 or
30any later version published by the Free Software Foundation; with the
31Invariant Sections being "Free Software" and "Free Software Needs Free
32Documentation", with the Front-Cover Texts being "A GNU Manual," and
33with the Back-Cover Texts as in (a) below.
34
35   (a) The FSF's Back-Cover Text is: "You are free to copy and modify
36this GNU Manual.  Buying copies from GNU Press supports the FSF in
37developing GNU and promoting software freedom."
38
39
40File: gdb.info,  Node: Top,  Next: Summary,  Prev: (dir),  Up: (dir)
41
42Debugging with GDB
43******************
44
45This file describes GDB, the GNU symbolic debugger.
46
47   This is the Tenth Edition, for GDB (GDB) Version 7.6.1.
48
49   Copyright (C) 1988-2013 Free Software Foundation, Inc.
50
51   This edition of the GDB manual is dedicated to the memory of Fred
52Fish.  Fred was a long-standing contributor to GDB and to Free software
53in general.  We will miss him.
54
55* Menu:
56
57* Summary::                     Summary of GDB
58* Sample Session::              A sample GDB session
59
60* Invocation::                  Getting in and out of GDB
61* Commands::                    GDB commands
62* Running::                     Running programs under GDB
63* Stopping::                    Stopping and continuing
64* Reverse Execution::           Running programs backward
65* Process Record and Replay::   Recording inferior's execution and replaying it
66* Stack::                       Examining the stack
67* Source::                      Examining source files
68* Data::                        Examining data
69* Optimized Code::              Debugging optimized code
70* Macros::                      Preprocessor Macros
71* Tracepoints::                 Debugging remote targets non-intrusively
72* Overlays::                    Debugging programs that use overlays
73
74* Languages::                   Using GDB with different languages
75
76* Symbols::                     Examining the symbol table
77* Altering::                    Altering execution
78* GDB Files::                   GDB files
79* Targets::                     Specifying a debugging target
80* Remote Debugging::            Debugging remote programs
81* Configurations::              Configuration-specific information
82* Controlling GDB::             Controlling GDB
83* Extending GDB::               Extending GDB
84* Interpreters::		Command Interpreters
85* TUI::                         GDB Text User Interface
86* Emacs::                       Using GDB under GNU Emacs
87* GDB/MI::                      GDB's Machine Interface.
88* Annotations::                 GDB's annotation interface.
89* JIT Interface::               Using the JIT debugging interface.
90* In-Process Agent::            In-Process Agent
91
92* GDB Bugs::                    Reporting bugs in GDB
93
94
95* Command Line Editing::        Command Line Editing
96* Using History Interactively:: Using History Interactively
97* In Memoriam::                 In Memoriam
98* Formatting Documentation::    How to format and print GDB documentation
99* Installing GDB::              Installing GDB
100* Maintenance Commands::        Maintenance Commands
101* Remote Protocol::             GDB Remote Serial Protocol
102* Agent Expressions::           The GDB Agent Expression Mechanism
103* Target Descriptions::         How targets can describe themselves to
104                                GDB
105* Operating System Information:: Getting additional information from
106                                 the operating system
107* Trace File Format::		GDB trace file format
108* Index Section Format::        .gdb_index section format
109* Copying::			GNU General Public License says
110                                how you can copy and share GDB
111* GNU Free Documentation License::  The license for this documentation
112* Concept Index::               Index of GDB concepts
113* Command and Variable Index::  Index of GDB commands, variables,
114                                  functions, and Python data types
115
116
117File: gdb.info,  Node: Summary,  Next: Sample Session,  Prev: Top,  Up: Top
118
119Summary of GDB
120**************
121
122The purpose of a debugger such as GDB is to allow you to see what is
123going on "inside" another program while it executes--or what another
124program was doing at the moment it crashed.
125
126   GDB can do four main kinds of things (plus other things in support of
127these) to help you catch bugs in the act:
128
129   * Start your program, specifying anything that might affect its
130     behavior.
131
132   * Make your program stop on specified conditions.
133
134   * Examine what has happened, when your program has stopped.
135
136   * Change things in your program, so you can experiment with
137     correcting the effects of one bug and go on to learn about another.
138
139   You can use GDB to debug programs written in C and C++.  For more
140information, see *note Supported Languages: Supported Languages.  For
141more information, see *note C and C++: C.
142
143   Support for D is partial.  For information on D, see *note D: D.
144
145   Support for Modula-2 is partial.  For information on Modula-2, see
146*note Modula-2: Modula-2.
147
148   Support for OpenCL C is partial.  For information on OpenCL C, see
149*note OpenCL C: OpenCL C.
150
151   Debugging Pascal programs which use sets, subranges, file variables,
152or nested functions does not currently work.  GDB does not support
153entering expressions, printing values, or similar features using Pascal
154syntax.
155
156   GDB can be used to debug programs written in Fortran, although it
157may be necessary to refer to some variables with a trailing underscore.
158
159   GDB can be used to debug programs written in Objective-C, using
160either the Apple/NeXT or the GNU Objective-C runtime.
161
162* Menu:
163
164* Free Software::               Freely redistributable software
165* Free Documentation::          Free Software Needs Free Documentation
166* Contributors::                Contributors to GDB
167
168
169File: gdb.info,  Node: Free Software,  Next: Free Documentation,  Up: Summary
170
171Free Software
172=============
173
174GDB is "free software", protected by the GNU General Public License
175(GPL).  The GPL gives you the freedom to copy or adapt a licensed
176program--but every person getting a copy also gets with it the freedom
177to modify that copy (which means that they must get access to the
178source code), and the freedom to distribute further copies.  Typical
179software companies use copyrights to limit your freedoms; the Free
180Software Foundation uses the GPL to preserve these freedoms.
181
182   Fundamentally, the General Public License is a license which says
183that you have these freedoms and that you cannot take these freedoms
184away from anyone else.
185
186
187File: gdb.info,  Node: Free Documentation,  Next: Contributors,  Prev: Free Software,  Up: Summary
188
189Free Software Needs Free Documentation
190======================================
191
192The biggest deficiency in the free software community today is not in
193the software--it is the lack of good free documentation that we can
194include with the free software.  Many of our most important programs do
195not come with free reference manuals and free introductory texts.
196Documentation is an essential part of any software package; when an
197important free software package does not come with a free manual and a
198free tutorial, that is a major gap.  We have many such gaps today.
199
200   Consider Perl, for instance.  The tutorial manuals that people
201normally use are non-free.  How did this come about?  Because the
202authors of those manuals published them with restrictive terms--no
203copying, no modification, source files not available--which exclude
204them from the free software world.
205
206   That wasn't the first time this sort of thing happened, and it was
207far from the last.  Many times we have heard a GNU user eagerly
208describe a manual that he is writing, his intended contribution to the
209community, only to learn that he had ruined everything by signing a
210publication contract to make it non-free.
211
212   Free documentation, like free software, is a matter of freedom, not
213price.  The problem with the non-free manual is not that publishers
214charge a price for printed copies--that in itself is fine.  (The Free
215Software Foundation sells printed copies of manuals, too.)  The problem
216is the restrictions on the use of the manual.  Free manuals are
217available in source code form, and give you permission to copy and
218modify.  Non-free manuals do not allow this.
219
220   The criteria of freedom for a free manual are roughly the same as for
221free software.  Redistribution (including the normal kinds of
222commercial redistribution) must be permitted, so that the manual can
223accompany every copy of the program, both on-line and on paper.
224
225   Permission for modification of the technical content is crucial too.
226When people modify the software, adding or changing features, if they
227are conscientious they will change the manual too--so they can provide
228accurate and clear documentation for the modified program.  A manual
229that leaves you no choice but to write a new manual to document a
230changed version of the program is not really available to our community.
231
232   Some kinds of limits on the way modification is handled are
233acceptable.  For example, requirements to preserve the original
234author's copyright notice, the distribution terms, or the list of
235authors, are ok.  It is also no problem to require modified versions to
236include notice that they were modified.  Even entire sections that may
237not be deleted or changed are acceptable, as long as they deal with
238nontechnical topics (like this one).  These kinds of restrictions are
239acceptable because they don't obstruct the community's normal use of
240the manual.
241
242   However, it must be possible to modify all the _technical_ content
243of the manual, and then distribute the result in all the usual media,
244through all the usual channels.  Otherwise, the restrictions obstruct
245the use of the manual, it is not free, and we need another manual to
246replace it.
247
248   Please spread the word about this issue.  Our community continues to
249lose manuals to proprietary publishing.  If we spread the word that
250free software needs free reference manuals and free tutorials, perhaps
251the next person who wants to contribute by writing documentation will
252realize, before it is too late, that only free manuals contribute to
253the free software community.
254
255   If you are writing documentation, please insist on publishing it
256under the GNU Free Documentation License or another free documentation
257license.  Remember that this decision requires your approval--you don't
258have to let the publisher decide.  Some commercial publishers will use
259a free license if you insist, but they will not propose the option; it
260is up to you to raise the issue and say firmly that this is what you
261want.  If the publisher you are dealing with refuses, please try other
262publishers.  If you're not sure whether a proposed license is free,
263write to <licensing@gnu.org>.
264
265   You can encourage commercial publishers to sell more free, copylefted
266manuals and tutorials by buying them, and particularly by buying copies
267from the publishers that paid for their writing or for major
268improvements.  Meanwhile, try to avoid buying non-free documentation at
269all.  Check the distribution terms of a manual before you buy it, and
270insist that whoever seeks your business must respect your freedom.
271Check the history of the book, and try to reward the publishers that
272have paid or pay the authors to work on it.
273
274   The Free Software Foundation maintains a list of free documentation
275published by other publishers, at
276`http://www.fsf.org/doc/other-free-books.html'.
277
278
279File: gdb.info,  Node: Contributors,  Prev: Free Documentation,  Up: Summary
280
281Contributors to GDB
282===================
283
284Richard Stallman was the original author of GDB, and of many other GNU
285programs.  Many others have contributed to its development.  This
286section attempts to credit major contributors.  One of the virtues of
287free software is that everyone is free to contribute to it; with
288regret, we cannot actually acknowledge everyone here.  The file
289`ChangeLog' in the GDB distribution approximates a blow-by-blow account.
290
291   Changes much prior to version 2.0 are lost in the mists of time.
292
293     _Plea:_ Additions to this section are particularly welcome.  If you
294     or your friends (or enemies, to be evenhanded) have been unfairly
295     omitted from this list, we would like to add your names!
296
297   So that they may not regard their many labors as thankless, we
298particularly thank those who shepherded GDB through major releases:
299Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim
300Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs
301(release 4.14); Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10,
302and 4.9); Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5,
303and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim
304Kingdon (releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2,
3053.1, and 3.0).
306
307   Richard Stallman, assisted at various times by Peter TerMaat, Chris
308Hanson, and Richard Mlynarik, handled releases through 2.8.
309
310   Michael Tiemann is the author of most of the GNU C++ support in GDB,
311with significant additional contributions from Per Bothner and Daniel
312Berlin.  James Clark wrote the GNU C++ demangler.  Early work on C++
313was by Peter TerMaat (who also did much general update work leading to
314release 3.0).
315
316   GDB uses the BFD subroutine library to examine multiple object-file
317formats; BFD was a joint project of David V.  Henkel-Wallace, Rich
318Pixley, Steve Chamberlain, and John Gilmore.
319
320   David Johnson wrote the original COFF support; Pace Willison did the
321original support for encapsulated COFF.
322
323   Brent Benson of Harris Computer Systems contributed DWARF 2 support.
324
325   Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
326Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
327support.  Jean-Daniel Fekete contributed Sun 386i support.  Chris
328Hanson improved the HP9000 support.  Noboyuki Hikichi and Tomoyuki
329Hasei contributed Sony/News OS 3 support.  David Johnson contributed
330Encore Umax support.  Jyrki Kuoppala contributed Altos 3068 support.
331Jeff Law contributed HP PA and SOM support.  Keith Packard contributed
332NS32K support.  Doug Rabson contributed Acorn Risc Machine support.
333Bob Rusk contributed Harris Nighthawk CX-UX support.  Chris Smith
334contributed Convex support (and Fortran debugging).  Jonathan Stone
335contributed Pyramid support.  Michael Tiemann contributed SPARC support.
336Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
337Pace Willison contributed Intel 386 support.  Jay Vosburgh contributed
338Symmetry support.  Marko Mlinar contributed OpenRISC 1000 support.
339
340   Andreas Schwab contributed M68K GNU/Linux support.
341
342   Rich Schaefer and Peter Schauer helped with support of SunOS shared
343libraries.
344
345   Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
346several machine instruction sets.
347
348   Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
349develop remote debugging.  Intel Corporation, Wind River Systems, AMD,
350and ARM contributed remote debugging modules for the i960, VxWorks,
351A29K UDI, and RDI targets, respectively.
352
353   Brian Fox is the author of the readline libraries providing
354command-line editing and command history.
355
356   Andrew Beers of SUNY Buffalo wrote the language-switching code, the
357Modula-2 support, and contributed the Languages chapter of this manual.
358
359   Fred Fish wrote most of the support for Unix System Vr4.  He also
360enhanced the command-completion support to cover C++ overloaded symbols.
361
362   Hitachi America (now Renesas America), Ltd. sponsored the support for
363H8/300, H8/500, and Super-H processors.
364
365   NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx
366processors.
367
368   Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and
369M32R/D processors.
370
371   Toshiba sponsored the support for the TX39 Mips processor.
372
373   Matsushita sponsored the support for the MN10200 and MN10300
374processors.
375
376   Fujitsu sponsored the support for SPARClite and FR30 processors.
377
378   Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
379watchpoints.
380
381   Michael Snyder added support for tracepoints.
382
383   Stu Grossman wrote gdbserver.
384
385   Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly
386innumerable bug fixes and cleanups throughout GDB.
387
388   The following people at the Hewlett-Packard Company contributed
389support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
390(narrow mode), HP's implementation of kernel threads, HP's aC++
391compiler, and the Text User Interface (nee Terminal User Interface):
392Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
393Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni.  Kim Haase
394provided HP-specific information in this manual.
395
396   DJ Delorie ported GDB to MS-DOS, for the DJGPP project.  Robert
397Hoehne made significant contributions to the DJGPP port.
398
399   Cygnus Solutions has sponsored GDB maintenance and much of its
400development since 1991.  Cygnus engineers who have worked on GDB
401fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
402Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
403Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
404Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
405Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni.  In
406addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
407JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
408Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
409Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
410Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
411Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
412Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
413Zuhn have made contributions both large and small.
414
415   Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
416Cygnus Solutions, implemented the original GDB/MI interface.
417
418   Jim Blandy added support for preprocessor macros, while working for
419Red Hat.
420
421   Andrew Cagney designed GDB's architecture vector.  Many people
422including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick Duffek,
423Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei Sakamoto,
424Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason Thorpe, Corinna
425Vinschen, Ulrich Weigand, and Elena Zannoni, helped with the migration
426of old architectures to this new framework.
427
428   Andrew Cagney completely re-designed and re-implemented GDB's
429unwinder framework, this consisting of a fresh new design featuring
430frame IDs, independent frame sniffers, and the sentinel frame.  Mark
431Kettenis implemented the DWARF 2 unwinder, Jeff Johnston the libunwind
432unwinder, and Andrew Cagney the dummy, sentinel, tramp, and trad
433unwinders.  The architecture-specific changes, each involving a
434complete rewrite of the architecture's frame code, were carried out by
435Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
436Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
437Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
438Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
439Weigand.
440
441   Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
442Tensilica, Inc. contributed support for Xtensa processors.  Others who
443have worked on the Xtensa port of GDB in the past include Steve Tjiang,
444John Newlin, and Scott Foehner.
445
446   Michael Eager and staff of Xilinx, Inc., contributed support for the
447Xilinx MicroBlaze architecture.
448
449
450File: gdb.info,  Node: Sample Session,  Next: Invocation,  Prev: Summary,  Up: Top
451
4521 A Sample GDB Session
453**********************
454
455You can use this manual at your leisure to read all about GDB.
456However, a handful of commands are enough to get started using the
457debugger.  This chapter illustrates those commands.
458
459   One of the preliminary versions of GNU `m4' (a generic macro
460processor) exhibits the following bug: sometimes, when we change its
461quote strings from the default, the commands used to capture one macro
462definition within another stop working.  In the following short `m4'
463session, we define a macro `foo' which expands to `0000'; we then use
464the `m4' built-in `defn' to define `bar' as the same thing.  However,
465when we change the open quote string to `<QUOTE>' and the close quote
466string to `<UNQUOTE>', the same procedure fails to define a new synonym
467`baz':
468
469     $ cd gnu/m4
470     $ ./m4
471     define(foo,0000)
472
473     foo
474     0000
475     define(bar,defn(`foo'))
476
477     bar
478     0000
479     changequote(<QUOTE>,<UNQUOTE>)
480
481     define(baz,defn(<QUOTE>foo<UNQUOTE>))
482     baz
483     Ctrl-d
484     m4: End of input: 0: fatal error: EOF in string
485
486Let us use GDB to try to see what is going on.
487
488     $ gdb m4
489     GDB is free software and you are welcome to distribute copies
490      of it under certain conditions; type "show copying" to see
491      the conditions.
492     There is absolutely no warranty for GDB; type "show warranty"
493      for details.
494
495     GDB 7.6.1, Copyright 1999 Free Software Foundation, Inc...
496     (gdb)
497
498GDB reads only enough symbol data to know where to find the rest when
499needed; as a result, the first prompt comes up very quickly.  We now
500tell GDB to use a narrower display width than usual, so that examples
501fit in this manual.
502
503     (gdb) set width 70
504
505We need to see how the `m4' built-in `changequote' works.  Having
506looked at the source, we know the relevant subroutine is
507`m4_changequote', so we set a breakpoint there with the GDB `break'
508command.
509
510     (gdb) break m4_changequote
511     Breakpoint 1 at 0x62f4: file builtin.c, line 879.
512
513Using the `run' command, we start `m4' running under GDB control; as
514long as control does not reach the `m4_changequote' subroutine, the
515program runs as usual:
516
517     (gdb) run
518     Starting program: /work/Editorial/gdb/gnu/m4/m4
519     define(foo,0000)
520
521     foo
522     0000
523
524To trigger the breakpoint, we call `changequote'.  GDB suspends
525execution of `m4', displaying information about the context where it
526stops.
527
528     changequote(<QUOTE>,<UNQUOTE>)
529
530     Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
531         at builtin.c:879
532     879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
533
534Now we use the command `n' (`next') to advance execution to the next
535line of the current function.
536
537     (gdb) n
538     882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
539      : nil,
540
541`set_quotes' looks like a promising subroutine.  We can go into it by
542using the command `s' (`step') instead of `next'.  `step' goes to the
543next line to be executed in _any_ subroutine, so it steps into
544`set_quotes'.
545
546     (gdb) s
547     set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
548         at input.c:530
549     530         if (lquote != def_lquote)
550
551The display that shows the subroutine where `m4' is now suspended (and
552its arguments) is called a stack frame display.  It shows a summary of
553the stack.  We can use the `backtrace' command (which can also be
554spelled `bt'), to see where we are in the stack as a whole: the
555`backtrace' command displays a stack frame for each active subroutine.
556
557     (gdb) bt
558     #0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
559         at input.c:530
560     #1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
561         at builtin.c:882
562     #2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
563     #3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
564         at macro.c:71
565     #4  0x79dc in expand_input () at macro.c:40
566     #5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
567
568We step through a few more lines to see what happens.  The first two
569times, we can use `s'; the next two times we use `n' to avoid falling
570into the `xstrdup' subroutine.
571
572     (gdb) s
573     0x3b5c  532         if (rquote != def_rquote)
574     (gdb) s
575     0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
576     def_lquote : xstrdup(lq);
577     (gdb) n
578     536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
579      : xstrdup(rq);
580     (gdb) n
581     538         len_lquote = strlen(rquote);
582
583The last line displayed looks a little odd; we can examine the variables
584`lquote' and `rquote' to see if they are in fact the new left and right
585quotes we specified.  We use the command `p' (`print') to see their
586values.
587
588     (gdb) p lquote
589     $1 = 0x35d40 "<QUOTE>"
590     (gdb) p rquote
591     $2 = 0x35d50 "<UNQUOTE>"
592
593`lquote' and `rquote' are indeed the new left and right quotes.  To
594look at some context, we can display ten lines of source surrounding
595the current line with the `l' (`list') command.
596
597     (gdb) l
598     533             xfree(rquote);
599     534
600     535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
601      : xstrdup (lq);
602     536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
603      : xstrdup (rq);
604     537
605     538         len_lquote = strlen(rquote);
606     539         len_rquote = strlen(lquote);
607     540     }
608     541
609     542     void
610
611Let us step past the two lines that set `len_lquote' and `len_rquote',
612and then examine the values of those variables.
613
614     (gdb) n
615     539         len_rquote = strlen(lquote);
616     (gdb) n
617     540     }
618     (gdb) p len_lquote
619     $3 = 9
620     (gdb) p len_rquote
621     $4 = 7
622
623That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
624meant to be the lengths of `lquote' and `rquote' respectively.  We can
625set them to better values using the `p' command, since it can print the
626value of any expression--and that expression can include subroutine
627calls and assignments.
628
629     (gdb) p len_lquote=strlen(lquote)
630     $5 = 7
631     (gdb) p len_rquote=strlen(rquote)
632     $6 = 9
633
634Is that enough to fix the problem of using the new quotes with the `m4'
635built-in `defn'?  We can allow `m4' to continue executing with the `c'
636(`continue') command, and then try the example that caused trouble
637initially:
638
639     (gdb) c
640     Continuing.
641
642     define(baz,defn(<QUOTE>foo<UNQUOTE>))
643
644     baz
645     0000
646
647Success!  The new quotes now work just as well as the default ones.  The
648problem seems to have been just the two typos defining the wrong
649lengths.  We allow `m4' exit by giving it an EOF as input:
650
651     Ctrl-d
652     Program exited normally.
653
654The message `Program exited normally.' is from GDB; it indicates `m4'
655has finished executing.  We can end our GDB session with the GDB `quit'
656command.
657
658     (gdb) quit
659
660
661File: gdb.info,  Node: Invocation,  Next: Commands,  Prev: Sample Session,  Up: Top
662
6632 Getting In and Out of GDB
664***************************
665
666This chapter discusses how to start GDB, and how to get out of it.  The
667essentials are:
668   * type `gdb' to start GDB.
669
670   * type `quit' or `Ctrl-d' to exit.
671
672* Menu:
673
674* Invoking GDB::                How to start GDB
675* Quitting GDB::                How to quit GDB
676* Shell Commands::              How to use shell commands inside GDB
677* Logging Output::              How to log GDB's output to a file
678
679
680File: gdb.info,  Node: Invoking GDB,  Next: Quitting GDB,  Up: Invocation
681
6822.1 Invoking GDB
683================
684
685Invoke GDB by running the program `gdb'.  Once started, GDB reads
686commands from the terminal until you tell it to exit.
687
688   You can also run `gdb' with a variety of arguments and options, to
689specify more of your debugging environment at the outset.
690
691   The command-line options described here are designed to cover a
692variety of situations; in some environments, some of these options may
693effectively be unavailable.
694
695   The most usual way to start GDB is with one argument, specifying an
696executable program:
697
698     gdb PROGRAM
699
700You can also start with both an executable program and a core file
701specified:
702
703     gdb PROGRAM CORE
704
705   You can, instead, specify a process ID as a second argument, if you
706want to debug a running process:
707
708     gdb PROGRAM 1234
709
710would attach GDB to process `1234' (unless you also have a file named
711`1234'; GDB does check for a core file first).
712
713   Taking advantage of the second command-line argument requires a
714fairly complete operating system; when you use GDB as a remote debugger
715attached to a bare board, there may not be any notion of "process", and
716there is often no way to get a core dump.  GDB will warn you if it is
717unable to attach or to read core dumps.
718
719   You can optionally have `gdb' pass any arguments after the
720executable file to the inferior using `--args'.  This option stops
721option processing.
722     gdb --args gcc -O2 -c foo.c
723   This will cause `gdb' to debug `gcc', and to set `gcc''s
724command-line arguments (*note Arguments::) to `-O2 -c foo.c'.
725
726   You can run `gdb' without printing the front material, which
727describes GDB's non-warranty, by specifying `-silent':
728
729     gdb -silent
730
731You can further control how GDB starts up by using command-line
732options.  GDB itself can remind you of the options available.
733
734Type
735
736     gdb -help
737
738to display all available options and briefly describe their use (`gdb
739-h' is a shorter equivalent).
740
741   All options and command line arguments you give are processed in
742sequential order.  The order makes a difference when the `-x' option is
743used.
744
745* Menu:
746
747* File Options::                Choosing files
748* Mode Options::                Choosing modes
749* Startup::                     What GDB does during startup
750
751
752File: gdb.info,  Node: File Options,  Next: Mode Options,  Up: Invoking GDB
753
7542.1.1 Choosing Files
755--------------------
756
757When GDB starts, it reads any arguments other than options as
758specifying an executable file and core file (or process ID).  This is
759the same as if the arguments were specified by the `-se' and `-c' (or
760`-p') options respectively.  (GDB reads the first argument that does
761not have an associated option flag as equivalent to the `-se' option
762followed by that argument; and the second argument that does not have
763an associated option flag, if any, as equivalent to the `-c'/`-p'
764option followed by that argument.)  If the second argument begins with
765a decimal digit, GDB will first attempt to attach to it as a process,
766and if that fails, attempt to open it as a corefile.  If you have a
767corefile whose name begins with a digit, you can prevent GDB from
768treating it as a pid by prefixing it with `./', e.g. `./12345'.
769
770   If GDB has not been configured to included core file support, such
771as for most embedded targets, then it will complain about a second
772argument and ignore it.
773
774   Many options have both long and short forms; both are shown in the
775following list.  GDB also recognizes the long forms if you truncate
776them, so long as enough of the option is present to be unambiguous.
777(If you prefer, you can flag option arguments with `--' rather than
778`-', though we illustrate the more usual convention.)
779
780`-symbols FILE'
781`-s FILE'
782     Read symbol table from file FILE.
783
784`-exec FILE'
785`-e FILE'
786     Use file FILE as the executable file to execute when appropriate,
787     and for examining pure data in conjunction with a core dump.
788
789`-se FILE'
790     Read symbol table from file FILE and use it as the executable file.
791
792`-core FILE'
793`-c FILE'
794     Use file FILE as a core dump to examine.
795
796`-pid NUMBER'
797`-p NUMBER'
798     Connect to process ID NUMBER, as with the `attach' command.
799
800`-command FILE'
801`-x FILE'
802     Execute commands from file FILE.  The contents of this file is
803     evaluated exactly as the `source' command would.  *Note Command
804     files: Command Files.
805
806`-eval-command COMMAND'
807`-ex COMMAND'
808     Execute a single GDB command.
809
810     This option may be used multiple times to call multiple commands.
811     It may also be interleaved with `-command' as required.
812
813          gdb -ex 'target sim' -ex 'load' \
814             -x setbreakpoints -ex 'run' a.out
815
816`-init-command FILE'
817`-ix FILE'
818     Execute commands from file FILE before loading the inferior (but
819     after loading gdbinit files).  *Note Startup::.
820
821`-init-eval-command COMMAND'
822`-iex COMMAND'
823     Execute a single GDB command before loading the inferior (but
824     after loading gdbinit files).  *Note Startup::.
825
826`-directory DIRECTORY'
827`-d DIRECTORY'
828     Add DIRECTORY to the path to search for source and script files.
829
830`-r'
831`-readnow'
832     Read each symbol file's entire symbol table immediately, rather
833     than the default, which is to read it incrementally as it is
834     needed.  This makes startup slower, but makes future operations
835     faster.
836
837
838
839File: gdb.info,  Node: Mode Options,  Next: Startup,  Prev: File Options,  Up: Invoking GDB
840
8412.1.2 Choosing Modes
842--------------------
843
844You can run GDB in various alternative modes--for example, in batch
845mode or quiet mode.
846
847`-nx'
848`-n'
849     Do not execute commands found in any initialization file.  There
850     are three init files, loaded in the following order:
851
852    ``system.gdbinit''
853          This is the system-wide init file.  Its location is specified
854          with the `--with-system-gdbinit' configure option (*note
855          System-wide configuration::).  It is loaded first when GDB
856          starts, before command line options have been processed.
857
858    ``~/.gdbinit''
859          This is the init file in your home directory.  It is loaded
860          next, after `system.gdbinit', and before command options have
861          been processed.
862
863    ``./.gdbinit''
864          This is the init file in the current directory.  It is loaded
865          last, after command line options other than `-x' and `-ex'
866          have been processed.  Command line options `-x' and `-ex' are
867          processed last, after `./.gdbinit' has been loaded.
868
869     For further documentation on startup processing, *Note Startup::.
870     For documentation on how to write command files, *Note Command
871     Files: Command Files.
872
873`-nh'
874     Do not execute commands found in `~/.gdbinit', the init file in
875     your home directory.  *Note Startup::.
876
877`-quiet'
878`-silent'
879`-q'
880     "Quiet".  Do not print the introductory and copyright messages.
881     These messages are also suppressed in batch mode.
882
883`-batch'
884     Run in batch mode.  Exit with status `0' after processing all the
885     command files specified with `-x' (and all commands from
886     initialization files, if not inhibited with `-n').  Exit with
887     nonzero status if an error occurs in executing the GDB commands in
888     the command files.  Batch mode also disables pagination, sets
889     unlimited terminal width and height *note Screen Size::, and acts
890     as if `set confirm off' were in effect (*note Messages/Warnings::).
891
892     Batch mode may be useful for running GDB as a filter, for example
893     to download and run a program on another computer; in order to
894     make this more useful, the message
895
896          Program exited normally.
897
898     (which is ordinarily issued whenever a program running under GDB
899     control terminates) is not issued when running in batch mode.
900
901`-batch-silent'
902     Run in batch mode exactly like `-batch', but totally silently.  All
903     GDB output to `stdout' is prevented (`stderr' is unaffected).
904     This is much quieter than `-silent' and would be useless for an
905     interactive session.
906
907     This is particularly useful when using targets that give `Loading
908     section' messages, for example.
909
910     Note that targets that give their output via GDB, as opposed to
911     writing directly to `stdout', will also be made silent.
912
913`-return-child-result'
914     The return code from GDB will be the return code from the child
915     process (the process being debugged), with the following
916     exceptions:
917
918        * GDB exits abnormally.  E.g., due to an incorrect argument or
919          an internal error.  In this case the exit code is the same as
920          it would have been without `-return-child-result'.
921
922        * The user quits with an explicit value.  E.g., `quit 1'.
923
924        * The child process never runs, or is not allowed to terminate,
925          in which case the exit code will be -1.
926
927     This option is useful in conjunction with `-batch' or
928     `-batch-silent', when GDB is being used as a remote program loader
929     or simulator interface.
930
931`-nowindows'
932`-nw'
933     "No windows".  If GDB comes with a graphical user interface (GUI)
934     built in, then this option tells GDB to only use the command-line
935     interface.  If no GUI is available, this option has no effect.
936
937`-windows'
938`-w'
939     If GDB includes a GUI, then this option requires it to be used if
940     possible.
941
942`-cd DIRECTORY'
943     Run GDB using DIRECTORY as its working directory, instead of the
944     current directory.
945
946`-data-directory DIRECTORY'
947     Run GDB using DIRECTORY as its data directory.  The data directory
948     is where GDB searches for its auxiliary files.  *Note Data Files::.
949
950`-fullname'
951`-f'
952     GNU Emacs sets this option when it runs GDB as a subprocess.  It
953     tells GDB to output the full file name and line number in a
954     standard, recognizable fashion each time a stack frame is
955     displayed (which includes each time your program stops).  This
956     recognizable format looks like two `\032' characters, followed by
957     the file name, line number and character position separated by
958     colons, and a newline.  The Emacs-to-GDB interface program uses
959     the two `\032' characters as a signal to display the source code
960     for the frame.
961
962`-annotate LEVEL'
963     This option sets the "annotation level" inside GDB.  Its effect is
964     identical to using `set annotate LEVEL' (*note Annotations::).
965     The annotation LEVEL controls how much information GDB prints
966     together with its prompt, values of expressions, source lines, and
967     other types of output.  Level 0 is the normal, level 1 is for use
968     when GDB is run as a subprocess of GNU Emacs, level 3 is the
969     maximum annotation suitable for programs that control GDB, and
970     level 2 has been deprecated.
971
972     The annotation mechanism has largely been superseded by GDB/MI
973     (*note GDB/MI::).
974
975`--args'
976     Change interpretation of command line so that arguments following
977     the executable file are passed as command line arguments to the
978     inferior.  This option stops option processing.
979
980`-baud BPS'
981`-b BPS'
982     Set the line speed (baud rate or bits per second) of any serial
983     interface used by GDB for remote debugging.
984
985`-l TIMEOUT'
986     Set the timeout (in seconds) of any communication used by GDB for
987     remote debugging.
988
989`-tty DEVICE'
990`-t DEVICE'
991     Run using DEVICE for your program's standard input and output.
992
993`-tui'
994     Activate the "Text User Interface" when starting.  The Text User
995     Interface manages several text windows on the terminal, showing
996     source, assembly, registers and GDB command outputs (*note GDB
997     Text User Interface: TUI.).  Do not use this option if you run GDB
998     from Emacs (*note Using GDB under GNU Emacs: Emacs.).
999
1000`-interpreter INTERP'
1001     Use the interpreter INTERP for interface with the controlling
1002     program or device.  This option is meant to be set by programs
1003     which communicate with GDB using it as a back end.  *Note Command
1004     Interpreters: Interpreters.
1005
1006     `--interpreter=mi' (or `--interpreter=mi2') causes GDB to use the
1007     "GDB/MI interface" (*note The GDB/MI Interface: GDB/MI.) included
1008     since GDB version 6.0.  The previous GDB/MI interface, included in
1009     GDB version 5.3 and selected with `--interpreter=mi1', is
1010     deprecated.  Earlier GDB/MI interfaces are no longer supported.
1011
1012`-write'
1013     Open the executable and core files for both reading and writing.
1014     This is equivalent to the `set write on' command inside GDB (*note
1015     Patching::).
1016
1017`-statistics'
1018     This option causes GDB to print statistics about time and memory
1019     usage after it completes each command and returns to the prompt.
1020
1021`-version'
1022     This option causes GDB to print its version number and no-warranty
1023     blurb, and exit.
1024
1025
1026
1027File: gdb.info,  Node: Startup,  Prev: Mode Options,  Up: Invoking GDB
1028
10292.1.3 What GDB Does During Startup
1030----------------------------------
1031
1032Here's the description of what GDB does during session startup:
1033
1034  1. Sets up the command interpreter as specified by the command line
1035     (*note interpreter: Mode Options.).
1036
1037  2. Reads the system-wide "init file" (if `--with-system-gdbinit' was
1038     used when building GDB; *note System-wide configuration and
1039     settings: System-wide configuration.) and executes all the
1040     commands in that file.
1041
1042  3. Reads the init file (if any) in your home directory(1) and
1043     executes all the commands in that file.
1044
1045  4. Executes commands and command files specified by the `-iex' and
1046     `-ix' options in their specified order.  Usually you should use the
1047     `-ex' and `-x' options instead, but this way you can apply
1048     settings before GDB init files get executed and before inferior
1049     gets loaded.
1050
1051  5. Processes command line options and operands.
1052
1053  6. Reads and executes the commands from init file (if any) in the
1054     current working directory as long as `set auto-load local-gdbinit'
1055     is set to `on' (*note Init File in the Current Directory::).  This
1056     is only done if the current directory is different from your home
1057     directory.  Thus, you can have more than one init file, one
1058     generic in your home directory, and another, specific to the
1059     program you are debugging, in the directory where you invoke GDB.
1060
1061  7. If the command line specified a program to debug, or a process to
1062     attach to, or a core file, GDB loads any auto-loaded scripts
1063     provided for the program or for its loaded shared libraries.
1064     *Note Auto-loading::.
1065
1066     If you wish to disable the auto-loading during startup, you must
1067     do something like the following:
1068
1069          $ gdb -iex "set auto-load python-scripts off" myprogram
1070
1071     Option `-ex' does not work because the auto-loading is then turned
1072     off too late.
1073
1074  8. Executes commands and command files specified by the `-ex' and
1075     `-x' options in their specified order.  *Note Command Files::, for
1076     more details about GDB command files.
1077
1078  9. Reads the command history recorded in the "history file".  *Note
1079     Command History::, for more details about the command history and
1080     the files where GDB records it.
1081
1082   Init files use the same syntax as "command files" (*note Command
1083Files::) and are processed by GDB in the same way.  The init file in
1084your home directory can set options (such as `set complaints') that
1085affect subsequent processing of command line options and operands.
1086Init files are not executed if you use the `-nx' option (*note Choosing
1087Modes: Mode Options.).
1088
1089   To display the list of init files loaded by gdb at startup, you can
1090use `gdb --help'.
1091
1092   The GDB init files are normally called `.gdbinit'.  The DJGPP port
1093of GDB uses the name `gdb.ini', due to the limitations of file names
1094imposed by DOS filesystems.  The Windows port of GDB uses the standard
1095name, but if it finds a `gdb.ini' file in your home directory, it warns
1096you about that and suggests to rename the file to the standard name.
1097
1098   ---------- Footnotes ----------
1099
1100   (1) On DOS/Windows systems, the home directory is the one pointed to
1101by the `HOME' environment variable.
1102
1103
1104File: gdb.info,  Node: Quitting GDB,  Next: Shell Commands,  Prev: Invoking GDB,  Up: Invocation
1105
11062.2 Quitting GDB
1107================
1108
1109`quit [EXPRESSION]'
1110`q'
1111     To exit GDB, use the `quit' command (abbreviated `q'), or type an
1112     end-of-file character (usually `Ctrl-d').  If you do not supply
1113     EXPRESSION, GDB will terminate normally; otherwise it will
1114     terminate using the result of EXPRESSION as the error code.
1115
1116   An interrupt (often `Ctrl-c') does not exit from GDB, but rather
1117terminates the action of any GDB command that is in progress and
1118returns to GDB command level.  It is safe to type the interrupt
1119character at any time because GDB does not allow it to take effect
1120until a time when it is safe.
1121
1122   If you have been using GDB to control an attached process or device,
1123you can release it with the `detach' command (*note Debugging an
1124Already-running Process: Attach.).
1125
1126
1127File: gdb.info,  Node: Shell Commands,  Next: Logging Output,  Prev: Quitting GDB,  Up: Invocation
1128
11292.3 Shell Commands
1130==================
1131
1132If you need to execute occasional shell commands during your debugging
1133session, there is no need to leave or suspend GDB; you can just use the
1134`shell' command.
1135
1136`shell COMMAND-STRING'
1137`!COMMAND-STRING'
1138     Invoke a standard shell to execute COMMAND-STRING.  Note that no
1139     space is needed between `!' and COMMAND-STRING.  If it exists, the
1140     environment variable `SHELL' determines which shell to run.
1141     Otherwise GDB uses the default shell (`/bin/sh' on Unix systems,
1142     `COMMAND.COM' on MS-DOS, etc.).
1143
1144   The utility `make' is often needed in development environments.  You
1145do not have to use the `shell' command for this purpose in GDB:
1146
1147`make MAKE-ARGS'
1148     Execute the `make' program with the specified arguments.  This is
1149     equivalent to `shell make MAKE-ARGS'.
1150
1151
1152File: gdb.info,  Node: Logging Output,  Prev: Shell Commands,  Up: Invocation
1153
11542.4 Logging Output
1155==================
1156
1157You may want to save the output of GDB commands to a file.  There are
1158several commands to control GDB's logging.
1159
1160`set logging on'
1161     Enable logging.
1162
1163`set logging off'
1164     Disable logging.
1165
1166`set logging file FILE'
1167     Change the name of the current logfile.  The default logfile is
1168     `gdb.txt'.
1169
1170`set logging overwrite [on|off]'
1171     By default, GDB will append to the logfile.  Set `overwrite' if
1172     you want `set logging on' to overwrite the logfile instead.
1173
1174`set logging redirect [on|off]'
1175     By default, GDB output will go to both the terminal and the
1176     logfile.  Set `redirect' if you want output to go only to the log
1177     file.
1178
1179`show logging'
1180     Show the current values of the logging settings.
1181
1182
1183File: gdb.info,  Node: Commands,  Next: Running,  Prev: Invocation,  Up: Top
1184
11853 GDB Commands
1186**************
1187
1188You can abbreviate a GDB command to the first few letters of the command
1189name, if that abbreviation is unambiguous; and you can repeat certain
1190GDB commands by typing just <RET>.  You can also use the <TAB> key to
1191get GDB to fill out the rest of a word in a command (or to show you the
1192alternatives available, if there is more than one possibility).
1193
1194* Menu:
1195
1196* Command Syntax::              How to give commands to GDB
1197* Completion::                  Command completion
1198* Help::                        How to ask GDB for help
1199
1200
1201File: gdb.info,  Node: Command Syntax,  Next: Completion,  Up: Commands
1202
12033.1 Command Syntax
1204==================
1205
1206A GDB command is a single line of input.  There is no limit on how long
1207it can be.  It starts with a command name, which is followed by
1208arguments whose meaning depends on the command name.  For example, the
1209command `step' accepts an argument which is the number of times to
1210step, as in `step 5'.  You can also use the `step' command with no
1211arguments.  Some commands do not allow any arguments.
1212
1213   GDB command names may always be truncated if that abbreviation is
1214unambiguous.  Other possible command abbreviations are listed in the
1215documentation for individual commands.  In some cases, even ambiguous
1216abbreviations are allowed; for example, `s' is specially defined as
1217equivalent to `step' even though there are other commands whose names
1218start with `s'.  You can test abbreviations by using them as arguments
1219to the `help' command.
1220
1221   A blank line as input to GDB (typing just <RET>) means to repeat the
1222previous command.  Certain commands (for example, `run') will not
1223repeat this way; these are commands whose unintentional repetition
1224might cause trouble and which you are unlikely to want to repeat.
1225User-defined commands can disable this feature; see *note dont-repeat:
1226Define.
1227
1228   The `list' and `x' commands, when you repeat them with <RET>,
1229construct new arguments rather than repeating exactly as typed.  This
1230permits easy scanning of source or memory.
1231
1232   GDB can also use <RET> in another way: to partition lengthy output,
1233in a way similar to the common utility `more' (*note Screen Size:
1234Screen Size.).  Since it is easy to press one <RET> too many in this
1235situation, GDB disables command repetition after any command that
1236generates this sort of display.
1237
1238   Any text from a `#' to the end of the line is a comment; it does
1239nothing.  This is useful mainly in command files (*note Command Files:
1240Command Files.).
1241
1242   The `Ctrl-o' binding is useful for repeating a complex sequence of
1243commands.  This command accepts the current line, like <RET>, and then
1244fetches the next line relative to the current line from the history for
1245editing.
1246
1247
1248File: gdb.info,  Node: Completion,  Next: Help,  Prev: Command Syntax,  Up: Commands
1249
12503.2 Command Completion
1251======================
1252
1253GDB can fill in the rest of a word in a command for you, if there is
1254only one possibility; it can also show you what the valid possibilities
1255are for the next word in a command, at any time.  This works for GDB
1256commands, GDB subcommands, and the names of symbols in your program.
1257
1258   Press the <TAB> key whenever you want GDB to fill out the rest of a
1259word.  If there is only one possibility, GDB fills in the word, and
1260waits for you to finish the command (or press <RET> to enter it).  For
1261example, if you type
1262
1263     (gdb) info bre <TAB>
1264
1265GDB fills in the rest of the word `breakpoints', since that is the only
1266`info' subcommand beginning with `bre':
1267
1268     (gdb) info breakpoints
1269
1270You can either press <RET> at this point, to run the `info breakpoints'
1271command, or backspace and enter something else, if `breakpoints' does
1272not look like the command you expected.  (If you were sure you wanted
1273`info breakpoints' in the first place, you might as well just type
1274<RET> immediately after `info bre', to exploit command abbreviations
1275rather than command completion).
1276
1277   If there is more than one possibility for the next word when you
1278press <TAB>, GDB sounds a bell.  You can either supply more characters
1279and try again, or just press <TAB> a second time; GDB displays all the
1280possible completions for that word.  For example, you might want to set
1281a breakpoint on a subroutine whose name begins with `make_', but when
1282you type `b make_<TAB>' GDB just sounds the bell.  Typing <TAB> again
1283displays all the function names in your program that begin with those
1284characters, for example:
1285
1286     (gdb) b make_ <TAB>
1287GDB sounds bell; press <TAB> again, to see:
1288     make_a_section_from_file     make_environ
1289     make_abs_section             make_function_type
1290     make_blockvector             make_pointer_type
1291     make_cleanup                 make_reference_type
1292     make_command                 make_symbol_completion_list
1293     (gdb) b make_
1294
1295After displaying the available possibilities, GDB copies your partial
1296input (`b make_' in the example) so you can finish the command.
1297
1298   If you just want to see the list of alternatives in the first place,
1299you can press `M-?' rather than pressing <TAB> twice.  `M-?' means
1300`<META> ?'.  You can type this either by holding down a key designated
1301as the <META> shift on your keyboard (if there is one) while typing
1302`?', or as <ESC> followed by `?'.
1303
1304   Sometimes the string you need, while logically a "word", may contain
1305parentheses or other characters that GDB normally excludes from its
1306notion of a word.  To permit word completion to work in this situation,
1307you may enclose words in `'' (single quote marks) in GDB commands.
1308
1309   The most likely situation where you might need this is in typing the
1310name of a C++ function.  This is because C++ allows function
1311overloading (multiple definitions of the same function, distinguished
1312by argument type).  For example, when you want to set a breakpoint you
1313may need to distinguish whether you mean the version of `name' that
1314takes an `int' parameter, `name(int)', or the version that takes a
1315`float' parameter, `name(float)'.  To use the word-completion
1316facilities in this situation, type a single quote `'' at the beginning
1317of the function name.  This alerts GDB that it may need to consider
1318more information than usual when you press <TAB> or `M-?' to request
1319word completion:
1320
1321     (gdb) b 'bubble( M-?
1322     bubble(double,double)    bubble(int,int)
1323     (gdb) b 'bubble(
1324
1325   In some cases, GDB can tell that completing a name requires using
1326quotes.  When this happens, GDB inserts the quote for you (while
1327completing as much as it can) if you do not type the quote in the first
1328place:
1329
1330     (gdb) b bub <TAB>
1331GDB alters your input line to the following, and rings a bell:
1332     (gdb) b 'bubble(
1333
1334In general, GDB can tell that a quote is needed (and inserts it) if you
1335have not yet started typing the argument list when you ask for
1336completion on an overloaded symbol.
1337
1338   For more information about overloaded functions, see *note C++
1339Expressions: C Plus Plus Expressions.  You can use the command `set
1340overload-resolution off' to disable overload resolution; see *note GDB
1341Features for C++: Debugging C Plus Plus.
1342
1343   When completing in an expression which looks up a field in a
1344structure, GDB also tries(1) to limit completions to the field names
1345available in the type of the left-hand-side:
1346
1347     (gdb) p gdb_stdout.M-?
1348     magic                to_fputs             to_rewind
1349     to_data              to_isatty            to_write
1350     to_delete            to_put               to_write_async_safe
1351     to_flush             to_read
1352
1353This is because the `gdb_stdout' is a variable of the type `struct
1354ui_file' that is defined in GDB sources as follows:
1355
1356     struct ui_file
1357     {
1358        int *magic;
1359        ui_file_flush_ftype *to_flush;
1360        ui_file_write_ftype *to_write;
1361        ui_file_write_async_safe_ftype *to_write_async_safe;
1362        ui_file_fputs_ftype *to_fputs;
1363        ui_file_read_ftype *to_read;
1364        ui_file_delete_ftype *to_delete;
1365        ui_file_isatty_ftype *to_isatty;
1366        ui_file_rewind_ftype *to_rewind;
1367        ui_file_put_ftype *to_put;
1368        void *to_data;
1369     }
1370
1371   ---------- Footnotes ----------
1372
1373   (1) The completer can be confused by certain kinds of invalid
1374expressions.  Also, it only examines the static type of the expression,
1375not the dynamic type.
1376
1377
1378File: gdb.info,  Node: Help,  Prev: Completion,  Up: Commands
1379
13803.3 Getting Help
1381================
1382
1383You can always ask GDB itself for information on its commands, using
1384the command `help'.
1385
1386`help'
1387`h'
1388     You can use `help' (abbreviated `h') with no arguments to display
1389     a short list of named classes of commands:
1390
1391          (gdb) help
1392          List of classes of commands:
1393
1394          aliases -- Aliases of other commands
1395          breakpoints -- Making program stop at certain points
1396          data -- Examining data
1397          files -- Specifying and examining files
1398          internals -- Maintenance commands
1399          obscure -- Obscure features
1400          running -- Running the program
1401          stack -- Examining the stack
1402          status -- Status inquiries
1403          support -- Support facilities
1404          tracepoints -- Tracing of program execution without
1405                         stopping the program
1406          user-defined -- User-defined commands
1407
1408          Type "help" followed by a class name for a list of
1409          commands in that class.
1410          Type "help" followed by command name for full
1411          documentation.
1412          Command name abbreviations are allowed if unambiguous.
1413          (gdb)
1414
1415`help CLASS'
1416     Using one of the general help classes as an argument, you can get a
1417     list of the individual commands in that class.  For example, here
1418     is the help display for the class `status':
1419
1420          (gdb) help status
1421          Status inquiries.
1422
1423          List of commands:
1424
1425          info -- Generic command for showing things
1426                  about the program being debugged
1427          show -- Generic command for showing things
1428                  about the debugger
1429
1430          Type "help" followed by command name for full
1431          documentation.
1432          Command name abbreviations are allowed if unambiguous.
1433          (gdb)
1434
1435`help COMMAND'
1436     With a command name as `help' argument, GDB displays a short
1437     paragraph on how to use that command.
1438
1439`apropos ARGS'
1440     The `apropos' command searches through all of the GDB commands,
1441     and their documentation, for the regular expression specified in
1442     ARGS.  It prints out all matches found.  For example:
1443
1444          apropos alias
1445
1446     results in:
1447
1448          alias -- Define a new command that is an alias of an existing command
1449          aliases -- Aliases of other commands
1450          d -- Delete some breakpoints or auto-display expressions
1451          del -- Delete some breakpoints or auto-display expressions
1452          delete -- Delete some breakpoints or auto-display expressions
1453
1454`complete ARGS'
1455     The `complete ARGS' command lists all the possible completions for
1456     the beginning of a command.  Use ARGS to specify the beginning of
1457     the command you want completed.  For example:
1458
1459          complete i
1460
1461     results in:
1462
1463          if
1464          ignore
1465          info
1466          inspect
1467
1468     This is intended for use by GNU Emacs.
1469
1470   In addition to `help', you can use the GDB commands `info' and
1471`show' to inquire about the state of your program, or the state of GDB
1472itself.  Each command supports many topics of inquiry; this manual
1473introduces each of them in the appropriate context.  The listings under
1474`info' and under `show' in the Command, Variable, and Function Index
1475point to all the sub-commands.  *Note Command and Variable Index::.
1476
1477`info'
1478     This command (abbreviated `i') is for describing the state of your
1479     program.  For example, you can show the arguments passed to a
1480     function with `info args', list the registers currently in use
1481     with `info registers', or list the breakpoints you have set with
1482     `info breakpoints'.  You can get a complete list of the `info'
1483     sub-commands with `help info'.
1484
1485`set'
1486     You can assign the result of an expression to an environment
1487     variable with `set'.  For example, you can set the GDB prompt to a
1488     $-sign with `set prompt $'.
1489
1490`show'
1491     In contrast to `info', `show' is for describing the state of GDB
1492     itself.  You can change most of the things you can `show', by
1493     using the related command `set'; for example, you can control what
1494     number system is used for displays with `set radix', or simply
1495     inquire which is currently in use with `show radix'.
1496
1497     To display all the settable parameters and their current values,
1498     you can use `show' with no arguments; you may also use `info set'.
1499     Both commands produce the same display.
1500
1501   Here are three miscellaneous `show' subcommands, all of which are
1502exceptional in lacking corresponding `set' commands:
1503
1504`show version'
1505     Show what version of GDB is running.  You should include this
1506     information in GDB bug-reports.  If multiple versions of GDB are
1507     in use at your site, you may need to determine which version of
1508     GDB you are running; as GDB evolves, new commands are introduced,
1509     and old ones may wither away.  Also, many system vendors ship
1510     variant versions of GDB, and there are variant versions of GDB in
1511     GNU/Linux distributions as well.  The version number is the same
1512     as the one announced when you start GDB.
1513
1514`show copying'
1515`info copying'
1516     Display information about permission for copying GDB.
1517
1518`show warranty'
1519`info warranty'
1520     Display the GNU "NO WARRANTY" statement, or a warranty, if your
1521     version of GDB comes with one.
1522
1523
1524
1525File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Commands,  Up: Top
1526
15274 Running Programs Under GDB
1528****************************
1529
1530When you run a program under GDB, you must first generate debugging
1531information when you compile it.
1532
1533   You may start GDB with its arguments, if any, in an environment of
1534your choice.  If you are doing native debugging, you may redirect your
1535program's input and output, debug an already running process, or kill a
1536child process.
1537
1538* Menu:
1539
1540* Compilation::                 Compiling for debugging
1541* Starting::                    Starting your program
1542* Arguments::                   Your program's arguments
1543* Environment::                 Your program's environment
1544
1545* Working Directory::           Your program's working directory
1546* Input/Output::                Your program's input and output
1547* Attach::                      Debugging an already-running process
1548* Kill Process::                Killing the child process
1549
1550* Inferiors and Programs::      Debugging multiple inferiors and programs
1551* Threads::                     Debugging programs with multiple threads
1552* Forks::                       Debugging forks
1553* Checkpoint/Restart::          Setting a _bookmark_ to return to later
1554
1555
1556File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
1557
15584.1 Compiling for Debugging
1559===========================
1560
1561In order to debug a program effectively, you need to generate debugging
1562information when you compile it.  This debugging information is stored
1563in the object file; it describes the data type of each variable or
1564function and the correspondence between source line numbers and
1565addresses in the executable code.
1566
1567   To request debugging information, specify the `-g' option when you
1568run the compiler.
1569
1570   Programs that are to be shipped to your customers are compiled with
1571optimizations, using the `-O' compiler option.  However, some compilers
1572are unable to handle the `-g' and `-O' options together.  Using those
1573compilers, you cannot generate optimized executables containing
1574debugging information.
1575
1576   GCC, the GNU C/C++ compiler, supports `-g' with or without `-O',
1577making it possible to debug optimized code.  We recommend that you
1578_always_ use `-g' whenever you compile a program.  You may think your
1579program is correct, but there is no sense in pushing your luck.  For
1580more information, see *note Optimized Code::.
1581
1582   Older versions of the GNU C compiler permitted a variant option
1583`-gg' for debugging information.  GDB no longer supports this format;
1584if your GNU C compiler has this option, do not use it.
1585
1586   GDB knows about preprocessor macros and can show you their expansion
1587(*note Macros::).  Most compilers do not include information about
1588preprocessor macros in the debugging information if you specify the
1589`-g' flag alone.  Version 3.1 and later of GCC, the GNU C compiler,
1590provides macro information if you are using the DWARF debugging format,
1591and specify the option `-g3'.
1592
1593   *Note Options for Debugging Your Program or GCC: (gcc.info)Debugging
1594Options, for more information on GCC options affecting debug
1595information.
1596
1597   You will have the best debugging experience if you use the latest
1598version of the DWARF debugging format that your compiler supports.
1599DWARF is currently the most expressive and best supported debugging
1600format in GDB.
1601
1602
1603File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
1604
16054.2 Starting your Program
1606=========================
1607
1608`run'
1609`r'
1610     Use the `run' command to start your program under GDB.  You must
1611     first specify the program name (except on VxWorks) with an
1612     argument to GDB (*note Getting In and Out of GDB: Invocation.), or
1613     by using the `file' or `exec-file' command (*note Commands to
1614     Specify Files: Files.).
1615
1616
1617   If you are running your program in an execution environment that
1618supports processes, `run' creates an inferior process and makes that
1619process run your program.  In some environments without processes,
1620`run' jumps to the start of your program.  Other targets, like
1621`remote', are always running.  If you get an error message like this
1622one:
1623
1624     The "remote" target does not support "run".
1625     Try "help target" or "continue".
1626
1627then use `continue' to run your program.  You may need `load' first
1628(*note load::).
1629
1630   The execution of a program is affected by certain information it
1631receives from its superior.  GDB provides ways to specify this
1632information, which you must do _before_ starting your program.  (You
1633can change it after starting your program, but such changes only affect
1634your program the next time you start it.)  This information may be
1635divided into four categories:
1636
1637The _arguments._
1638     Specify the arguments to give your program as the arguments of the
1639     `run' command.  If a shell is available on your target, the shell
1640     is used to pass the arguments, so that you may use normal
1641     conventions (such as wildcard expansion or variable substitution)
1642     in describing the arguments.  In Unix systems, you can control
1643     which shell is used with the `SHELL' environment variable.  *Note
1644     Your Program's Arguments: Arguments.
1645
1646The _environment._
1647     Your program normally inherits its environment from GDB, but you
1648     can use the GDB commands `set environment' and `unset environment'
1649     to change parts of the environment that affect your program.
1650     *Note Your Program's Environment: Environment.
1651
1652The _working directory._
1653     Your program inherits its working directory from GDB.  You can set
1654     the GDB working directory with the `cd' command in GDB.  *Note
1655     Your Program's Working Directory: Working Directory.
1656
1657The _standard input and output._
1658     Your program normally uses the same device for standard input and
1659     standard output as GDB is using.  You can redirect input and output
1660     in the `run' command line, or you can use the `tty' command to set
1661     a different device for your program.  *Note Your Program's Input
1662     and Output: Input/Output.
1663
1664     _Warning:_ While input and output redirection work, you cannot use
1665     pipes to pass the output of the program you are debugging to
1666     another program; if you attempt this, GDB is likely to wind up
1667     debugging the wrong program.
1668
1669   When you issue the `run' command, your program begins to execute
1670immediately.  *Note Stopping and Continuing: Stopping, for discussion
1671of how to arrange for your program to stop.  Once your program has
1672stopped, you may call functions in your program, using the `print' or
1673`call' commands.  *Note Examining Data: Data.
1674
1675   If the modification time of your symbol file has changed since the
1676last time GDB read its symbols, GDB discards its symbol table, and
1677reads it again.  When it does this, GDB tries to retain your current
1678breakpoints.
1679
1680`start'
1681     The name of the main procedure can vary from language to language.
1682     With C or C++, the main procedure name is always `main', but other
1683     languages such as Ada do not require a specific name for their
1684     main procedure.  The debugger provides a convenient way to start
1685     the execution of the program and to stop at the beginning of the
1686     main procedure, depending on the language used.
1687
1688     The `start' command does the equivalent of setting a temporary
1689     breakpoint at the beginning of the main procedure and then invoking
1690     the `run' command.
1691
1692     Some programs contain an "elaboration" phase where some startup
1693     code is executed before the main procedure is called.  This
1694     depends on the languages used to write your program.  In C++, for
1695     instance, constructors for static and global objects are executed
1696     before `main' is called.  It is therefore possible that the
1697     debugger stops before reaching the main procedure.  However, the
1698     temporary breakpoint will remain to halt execution.
1699
1700     Specify the arguments to give to your program as arguments to the
1701     `start' command.  These arguments will be given verbatim to the
1702     underlying `run' command.  Note that the same arguments will be
1703     reused if no argument is provided during subsequent calls to
1704     `start' or `run'.
1705
1706     It is sometimes necessary to debug the program during elaboration.
1707     In these cases, using the `start' command would stop the execution
1708     of your program too late, as the program would have already
1709     completed the elaboration phase.  Under these circumstances,
1710     insert breakpoints in your elaboration code before running your
1711     program.
1712
1713`set exec-wrapper WRAPPER'
1714`show exec-wrapper'
1715`unset exec-wrapper'
1716     When `exec-wrapper' is set, the specified wrapper is used to
1717     launch programs for debugging.  GDB starts your program with a
1718     shell command of the form `exec WRAPPER PROGRAM'.  Quoting is
1719     added to PROGRAM and its arguments, but not to WRAPPER, so you
1720     should add quotes if appropriate for your shell.  The wrapper runs
1721     until it executes your program, and then GDB takes control.
1722
1723     You can use any program that eventually calls `execve' with its
1724     arguments as a wrapper.  Several standard Unix utilities do this,
1725     e.g. `env' and `nohup'.  Any Unix shell script ending with `exec
1726     "$@"' will also work.
1727
1728     For example, you can use `env' to pass an environment variable to
1729     the debugged program, without setting the variable in your shell's
1730     environment:
1731
1732          (gdb) set exec-wrapper env 'LD_PRELOAD=libtest.so'
1733          (gdb) run
1734
1735     This command is available when debugging locally on most targets,
1736     excluding DJGPP, Cygwin, MS Windows, and QNX Neutrino.
1737
1738`set disable-randomization'
1739`set disable-randomization on'
1740     This option (enabled by default in GDB) will turn off the native
1741     randomization of the virtual address space of the started program.
1742     This option is useful for multiple debugging sessions to make the
1743     execution better reproducible and memory addresses reusable across
1744     debugging sessions.
1745
1746     This feature is implemented only on certain targets, including
1747     GNU/Linux.  On GNU/Linux you can get the same behavior using
1748
1749          (gdb) set exec-wrapper setarch `uname -m` -R
1750
1751`set disable-randomization off'
1752     Leave the behavior of the started executable unchanged.  Some bugs
1753     rear their ugly heads only when the program is loaded at certain
1754     addresses.  If your bug disappears when you run the program under
1755     GDB, that might be because GDB by default disables the address
1756     randomization on platforms, such as GNU/Linux, which do that for
1757     stand-alone programs.  Use `set disable-randomization off' to try
1758     to reproduce such elusive bugs.
1759
1760     On targets where it is available, virtual address space
1761     randomization protects the programs against certain kinds of
1762     security attacks.  In these cases the attacker needs to know the
1763     exact location of a concrete executable code.  Randomizing its
1764     location makes it impossible to inject jumps misusing a code at
1765     its expected addresses.
1766
1767     Prelinking shared libraries provides a startup performance
1768     advantage but it makes addresses in these libraries predictable
1769     for privileged processes by having just unprivileged access at the
1770     target system.  Reading the shared library binary gives enough
1771     information for assembling the malicious code misusing it.  Still
1772     even a prelinked shared library can get loaded at a new random
1773     address just requiring the regular relocation process during the
1774     startup.  Shared libraries not already prelinked are always loaded
1775     at a randomly chosen address.
1776
1777     Position independent executables (PIE) contain position
1778     independent code similar to the shared libraries and therefore
1779     such executables get loaded at a randomly chosen address upon
1780     startup.  PIE executables always load even already prelinked
1781     shared libraries at a random address.  You can build such
1782     executable using `gcc -fPIE -pie'.
1783
1784     Heap (malloc storage), stack and custom mmap areas are always
1785     placed randomly (as long as the randomization is enabled).
1786
1787`show disable-randomization'
1788     Show the current setting of the explicit disable of the native
1789     randomization of the virtual address space of the started program.
1790
1791
1792
1793File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
1794
17954.3 Your Program's Arguments
1796============================
1797
1798The arguments to your program can be specified by the arguments of the
1799`run' command.  They are passed to a shell, which expands wildcard
1800characters and performs redirection of I/O, and thence to your program.
1801Your `SHELL' environment variable (if it exists) specifies what shell
1802GDB uses.  If you do not define `SHELL', GDB uses the default shell
1803(`/bin/sh' on Unix).
1804
1805   On non-Unix systems, the program is usually invoked directly by GDB,
1806which emulates I/O redirection via the appropriate system calls, and
1807the wildcard characters are expanded by the startup code of the
1808program, not by the shell.
1809
1810   `run' with no arguments uses the same arguments used by the previous
1811`run', or those set by the `set args' command.
1812
1813`set args'
1814     Specify the arguments to be used the next time your program is
1815     run.  If `set args' has no arguments, `run' executes your program
1816     with no arguments.  Once you have run your program with arguments,
1817     using `set args' before the next `run' is the only way to run it
1818     again without arguments.
1819
1820`show args'
1821     Show the arguments to give your program when it is started.
1822
1823
1824File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
1825
18264.4 Your Program's Environment
1827==============================
1828
1829The "environment" consists of a set of environment variables and their
1830values.  Environment variables conventionally record such things as
1831your user name, your home directory, your terminal type, and your search
1832path for programs to run.  Usually you set up environment variables with
1833the shell and they are inherited by all the other programs you run.
1834When debugging, it can be useful to try running your program with a
1835modified environment without having to start GDB over again.
1836
1837`path DIRECTORY'
1838     Add DIRECTORY to the front of the `PATH' environment variable (the
1839     search path for executables) that will be passed to your program.
1840     The value of `PATH' used by GDB does not change.  You may specify
1841     several directory names, separated by whitespace or by a
1842     system-dependent separator character (`:' on Unix, `;' on MS-DOS
1843     and MS-Windows).  If DIRECTORY is already in the path, it is moved
1844     to the front, so it is searched sooner.
1845
1846     You can use the string `$cwd' to refer to whatever is the current
1847     working directory at the time GDB searches the path.  If you use
1848     `.' instead, it refers to the directory where you executed the
1849     `path' command.  GDB replaces `.' in the DIRECTORY argument (with
1850     the current path) before adding DIRECTORY to the search path.
1851
1852`show paths'
1853     Display the list of search paths for executables (the `PATH'
1854     environment variable).
1855
1856`show environment [VARNAME]'
1857     Print the value of environment variable VARNAME to be given to
1858     your program when it starts.  If you do not supply VARNAME, print
1859     the names and values of all environment variables to be given to
1860     your program.  You can abbreviate `environment' as `env'.
1861
1862`set environment VARNAME [=VALUE]'
1863     Set environment variable VARNAME to VALUE.  The value changes for
1864     your program only, not for GDB itself.  VALUE may be any string;
1865     the values of environment variables are just strings, and any
1866     interpretation is supplied by your program itself.  The VALUE
1867     parameter is optional; if it is eliminated, the variable is set to
1868     a null value.
1869
1870     For example, this command:
1871
1872          set env USER = foo
1873
1874     tells the debugged program, when subsequently run, that its user
1875     is named `foo'.  (The spaces around `=' are used for clarity here;
1876     they are not actually required.)
1877
1878`unset environment VARNAME'
1879     Remove variable VARNAME from the environment to be passed to your
1880     program.  This is different from `set env VARNAME ='; `unset
1881     environment' removes the variable from the environment, rather
1882     than assigning it an empty value.
1883
1884   _Warning:_ On Unix systems, GDB runs your program using the shell
1885indicated by your `SHELL' environment variable if it exists (or
1886`/bin/sh' if not).  If your `SHELL' variable names a shell that runs an
1887initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
1888BASH--any variables you set in that file affect your program.  You may
1889wish to move setting of environment variables to files that are only
1890run when you sign on, such as `.login' or `.profile'.
1891
1892
1893File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
1894
18954.5 Your Program's Working Directory
1896====================================
1897
1898Each time you start your program with `run', it inherits its working
1899directory from the current working directory of GDB.  The GDB working
1900directory is initially whatever it inherited from its parent process
1901(typically the shell), but you can specify a new working directory in
1902GDB with the `cd' command.
1903
1904   The GDB working directory also serves as a default for the commands
1905that specify files for GDB to operate on.  *Note Commands to Specify
1906Files: Files.
1907
1908`cd [DIRECTORY]'
1909     Set the GDB working directory to DIRECTORY.  If not given,
1910     DIRECTORY uses `'~''.
1911
1912`pwd'
1913     Print the GDB working directory.
1914
1915   It is generally impossible to find the current working directory of
1916the process being debugged (since a program can change its directory
1917during its run).  If you work on a system where GDB is configured with
1918the `/proc' support, you can use the `info proc' command (*note SVR4
1919Process Information::) to find out the current working directory of the
1920debuggee.
1921
1922
1923File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
1924
19254.6 Your Program's Input and Output
1926===================================
1927
1928By default, the program you run under GDB does input and output to the
1929same terminal that GDB uses.  GDB switches the terminal to its own
1930terminal modes to interact with you, but it records the terminal modes
1931your program was using and switches back to them when you continue
1932running your program.
1933
1934`info terminal'
1935     Displays information recorded by GDB about the terminal modes your
1936     program is using.
1937
1938   You can redirect your program's input and/or output using shell
1939redirection with the `run' command.  For example,
1940
1941     run > outfile
1942
1943starts your program, diverting its output to the file `outfile'.
1944
1945   Another way to specify where your program should do input and output
1946is with the `tty' command.  This command accepts a file name as
1947argument, and causes this file to be the default for future `run'
1948commands.  It also resets the controlling terminal for the child
1949process, for future `run' commands.  For example,
1950
1951     tty /dev/ttyb
1952
1953directs that processes started with subsequent `run' commands default
1954to do input and output on the terminal `/dev/ttyb' and have that as
1955their controlling terminal.
1956
1957   An explicit redirection in `run' overrides the `tty' command's
1958effect on the input/output device, but not its effect on the controlling
1959terminal.
1960
1961   When you use the `tty' command or redirect input in the `run'
1962command, only the input _for your program_ is affected.  The input for
1963GDB still comes from your terminal.  `tty' is an alias for `set
1964inferior-tty'.
1965
1966   You can use the `show inferior-tty' command to tell GDB to display
1967the name of the terminal that will be used for future runs of your
1968program.
1969
1970`set inferior-tty /dev/ttyb'
1971     Set the tty for the program being debugged to /dev/ttyb.
1972
1973`show inferior-tty'
1974     Show the current tty for the program being debugged.
1975
1976
1977File: gdb.info,  Node: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
1978
19794.7 Debugging an Already-running Process
1980========================================
1981
1982`attach PROCESS-ID'
1983     This command attaches to a running process--one that was started
1984     outside GDB.  (`info files' shows your active targets.)  The
1985     command takes as argument a process ID.  The usual way to find out
1986     the PROCESS-ID of a Unix process is with the `ps' utility, or with
1987     the `jobs -l' shell command.
1988
1989     `attach' does not repeat if you press <RET> a second time after
1990     executing the command.
1991
1992   To use `attach', your program must be running in an environment
1993which supports processes; for example, `attach' does not work for
1994programs on bare-board targets that lack an operating system.  You must
1995also have permission to send the process a signal.
1996
1997   When you use `attach', the debugger finds the program running in the
1998process first by looking in the current working directory, then (if the
1999program is not found) by using the source file search path (*note
2000Specifying Source Directories: Source Path.).  You can also use the
2001`file' command to load the program.  *Note Commands to Specify Files:
2002Files.
2003
2004   The first thing GDB does after arranging to debug the specified
2005process is to stop it.  You can examine and modify an attached process
2006with all the GDB commands that are ordinarily available when you start
2007processes with `run'.  You can insert breakpoints; you can step and
2008continue; you can modify storage.  If you would rather the process
2009continue running, you may use the `continue' command after attaching
2010GDB to the process.
2011
2012`detach'
2013     When you have finished debugging the attached process, you can use
2014     the `detach' command to release it from GDB control.  Detaching
2015     the process continues its execution.  After the `detach' command,
2016     that process and GDB become completely independent once more, and
2017     you are ready to `attach' another process or start one with `run'.
2018     `detach' does not repeat if you press <RET> again after executing
2019     the command.
2020
2021   If you exit GDB while you have an attached process, you detach that
2022process.  If you use the `run' command, you kill that process.  By
2023default, GDB asks for confirmation if you try to do either of these
2024things; you can control whether or not you need to confirm by using the
2025`set confirm' command (*note Optional Warnings and Messages:
2026Messages/Warnings.).
2027
2028
2029File: gdb.info,  Node: Kill Process,  Next: Inferiors and Programs,  Prev: Attach,  Up: Running
2030
20314.8 Killing the Child Process
2032=============================
2033
2034`kill'
2035     Kill the child process in which your program is running under GDB.
2036
2037   This command is useful if you wish to debug a core dump instead of a
2038running process.  GDB ignores any core dump file while your program is
2039running.
2040
2041   On some operating systems, a program cannot be executed outside GDB
2042while you have breakpoints set on it inside GDB.  You can use the
2043`kill' command in this situation to permit running your program outside
2044the debugger.
2045
2046   The `kill' command is also useful if you wish to recompile and
2047relink your program, since on many systems it is impossible to modify an
2048executable file while it is running in a process.  In this case, when
2049you next type `run', GDB notices that the file has changed, and reads
2050the symbol table again (while trying to preserve your current
2051breakpoint settings).
2052
2053
2054File: gdb.info,  Node: Inferiors and Programs,  Next: Threads,  Prev: Kill Process,  Up: Running
2055
20564.9 Debugging Multiple Inferiors and Programs
2057=============================================
2058
2059GDB lets you run and debug multiple programs in a single session.  In
2060addition, GDB on some systems may let you run several programs
2061simultaneously (otherwise you have to exit from one before starting
2062another).  In the most general case, you can have multiple threads of
2063execution in each of multiple processes, launched from multiple
2064executables.
2065
2066   GDB represents the state of each program execution with an object
2067called an "inferior".  An inferior typically corresponds to a process,
2068but is more general and applies also to targets that do not have
2069processes.  Inferiors may be created before a process runs, and may be
2070retained after a process exits.  Inferiors have unique identifiers that
2071are different from process ids.  Usually each inferior will also have
2072its own distinct address space, although some embedded targets may have
2073several inferiors running in different parts of a single address space.
2074Each inferior may in turn have multiple threads running in it.
2075
2076   To find out what inferiors exist at any moment, use `info inferiors':
2077
2078`info inferiors'
2079     Print a list of all inferiors currently being managed by GDB.
2080
2081     GDB displays for each inferior (in this order):
2082
2083       1. the inferior number assigned by GDB
2084
2085       2. the target system's inferior identifier
2086
2087       3. the name of the executable the inferior is running.
2088
2089
2090     An asterisk `*' preceding the GDB inferior number indicates the
2091     current inferior.
2092
2093     For example,
2094
2095     (gdb) info inferiors
2096       Num  Description       Executable
2097       2    process 2307      hello
2098     * 1    process 3401      goodbye
2099
2100   To switch focus between inferiors, use the `inferior' command:
2101
2102`inferior INFNO'
2103     Make inferior number INFNO the current inferior.  The argument
2104     INFNO is the inferior number assigned by GDB, as shown in the
2105     first field of the `info inferiors' display.
2106
2107   You can get multiple executables into a debugging session via the
2108`add-inferior' and `clone-inferior' commands.  On some systems GDB can
2109add inferiors to the debug session automatically by following calls to
2110`fork' and `exec'.  To remove inferiors from the debugging session use
2111the `remove-inferiors' command.
2112
2113`add-inferior [ -copies N ] [ -exec EXECUTABLE ]'
2114     Adds N inferiors to be run using EXECUTABLE as the executable.  N
2115     defaults to 1.  If no executable is specified, the inferiors
2116     begins empty, with no program.  You can still assign or change the
2117     program assigned to the inferior at any time by using the `file'
2118     command with the executable name as its argument.
2119
2120`clone-inferior [ -copies N ] [ INFNO ]'
2121     Adds N inferiors ready to execute the same program as inferior
2122     INFNO.  N defaults to 1.  INFNO defaults to the number of the
2123     current inferior.  This is a convenient command when you want to
2124     run another instance of the inferior you are debugging.
2125
2126          (gdb) info inferiors
2127            Num  Description       Executable
2128          * 1    process 29964     helloworld
2129          (gdb) clone-inferior
2130          Added inferior 2.
2131          1 inferiors added.
2132          (gdb) info inferiors
2133            Num  Description       Executable
2134            2    <null>            helloworld
2135          * 1    process 29964     helloworld
2136
2137     You can now simply switch focus to inferior 2 and run it.
2138
2139`remove-inferiors INFNO...'
2140     Removes the inferior or inferiors INFNO....  It is not possible to
2141     remove an inferior that is running with this command.  For those,
2142     use the `kill' or `detach' command first.
2143
2144
2145   To quit debugging one of the running inferiors that is not the
2146current inferior, you can either detach from it by using the
2147`detach inferior' command (allowing it to run independently), or kill it
2148using the `kill inferiors' command:
2149
2150`detach inferior INFNO...'
2151     Detach from the inferior or inferiors identified by GDB inferior
2152     number(s) INFNO....  Note that the inferior's entry still stays on
2153     the list of inferiors shown by `info inferiors', but its
2154     Description will show `<null>'.
2155
2156`kill inferiors INFNO...'
2157     Kill the inferior or inferiors identified by GDB inferior
2158     number(s) INFNO....  Note that the inferior's entry still stays on
2159     the list of inferiors shown by `info inferiors', but its
2160     Description will show `<null>'.
2161
2162   After the successful completion of a command such as `detach',
2163`detach inferiors', `kill' or `kill inferiors', or after a normal
2164process exit, the inferior is still valid and listed with `info
2165inferiors', ready to be restarted.
2166
2167   To be notified when inferiors are started or exit under GDB's
2168control use `set print inferior-events':
2169
2170`set print inferior-events'
2171`set print inferior-events on'
2172`set print inferior-events off'
2173     The `set print inferior-events' command allows you to enable or
2174     disable printing of messages when GDB notices that new inferiors
2175     have started or that inferiors have exited or have been detached.
2176     By default, these messages will not be printed.
2177
2178`show print inferior-events'
2179     Show whether messages will be printed when GDB detects that
2180     inferiors have started, exited or have been detached.
2181
2182   Many commands will work the same with multiple programs as with a
2183single program: e.g., `print myglobal' will simply display the value of
2184`myglobal' in the current inferior.
2185
2186   Occasionaly, when debugging GDB itself, it may be useful to get more
2187info about the relationship of inferiors, programs, address spaces in a
2188debug session.  You can do that with the `maint info program-spaces'
2189command.
2190
2191`maint info program-spaces'
2192     Print a list of all program spaces currently being managed by GDB.
2193
2194     GDB displays for each program space (in this order):
2195
2196       1. the program space number assigned by GDB
2197
2198       2. the name of the executable loaded into the program space,
2199          with e.g., the `file' command.
2200
2201
2202     An asterisk `*' preceding the GDB program space number indicates
2203     the current program space.
2204
2205     In addition, below each program space line, GDB prints extra
2206     information that isn't suitable to display in tabular form.  For
2207     example, the list of inferiors bound to the program space.
2208
2209          (gdb) maint info program-spaces
2210            Id   Executable
2211            2    goodbye
2212                  Bound inferiors: ID 1 (process 21561)
2213          * 1    hello
2214
2215     Here we can see that no inferior is running the program `hello',
2216     while `process 21561' is running the program `goodbye'.  On some
2217     targets, it is possible that multiple inferiors are bound to the
2218     same program space.  The most common example is that of debugging
2219     both the parent and child processes of a `vfork' call.  For
2220     example,
2221
2222          (gdb) maint info program-spaces
2223            Id   Executable
2224          * 1    vfork-test
2225                  Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2226
2227     Here, both inferior 2 and inferior 1 are running in the same
2228     program space as a result of inferior 1 having executed a `vfork'
2229     call.
2230
2231
2232File: gdb.info,  Node: Threads,  Next: Forks,  Prev: Inferiors and Programs,  Up: Running
2233
22344.10 Debugging Programs with Multiple Threads
2235=============================================
2236
2237In some operating systems, such as HP-UX and Solaris, a single program
2238may have more than one "thread" of execution.  The precise semantics of
2239threads differ from one operating system to another, but in general the
2240threads of a single program are akin to multiple processes--except that
2241they share one address space (that is, they can all examine and modify
2242the same variables).  On the other hand, each thread has its own
2243registers and execution stack, and perhaps private memory.
2244
2245   GDB provides these facilities for debugging multi-thread programs:
2246
2247   * automatic notification of new threads
2248
2249   * `thread THREADNO', a command to switch among threads
2250
2251   * `info threads', a command to inquire about existing threads
2252
2253   * `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
2254     to a list of threads
2255
2256   * thread-specific breakpoints
2257
2258   * `set print thread-events', which controls printing of messages on
2259     thread start and exit.
2260
2261   * `set libthread-db-search-path PATH', which lets the user specify
2262     which `libthread_db' to use if the default choice isn't compatible
2263     with the program.
2264
2265     _Warning:_ These facilities are not yet available on every GDB
2266     configuration where the operating system supports threads.  If
2267     your GDB does not support threads, these commands have no effect.
2268     For example, a system without thread support shows no output from
2269     `info threads', and always rejects the `thread' command, like this:
2270
2271          (gdb) info threads
2272          (gdb) thread 1
2273          Thread ID 1 not known.  Use the "info threads" command to
2274          see the IDs of currently known threads.
2275
2276   The GDB thread debugging facility allows you to observe all threads
2277while your program runs--but whenever GDB takes control, one thread in
2278particular is always the focus of debugging.  This thread is called the
2279"current thread".  Debugging commands show program information from the
2280perspective of the current thread.
2281
2282   Whenever GDB detects a new thread in your program, it displays the
2283target system's identification for the thread with a message in the
2284form `[New SYSTAG]'.  SYSTAG is a thread identifier whose form varies
2285depending on the particular system.  For example, on GNU/Linux, you
2286might see
2287
2288     [New Thread 0x41e02940 (LWP 25582)]
2289
2290when GDB notices a new thread.  In contrast, on an SGI system, the
2291SYSTAG is simply something like `process 368', with no further
2292qualifier.
2293
2294   For debugging purposes, GDB associates its own thread number--always
2295a single integer--with each thread in your program.
2296
2297`info threads [ID...]'
2298     Display a summary of all threads currently in your program.
2299     Optional argument ID... is one or more thread ids separated by
2300     spaces, and means to print information only about the specified
2301     thread or threads.  GDB displays for each thread (in this order):
2302
2303       1. the thread number assigned by GDB
2304
2305       2. the target system's thread identifier (SYSTAG)
2306
2307       3. the thread's name, if one is known.  A thread can either be
2308          named by the user (see `thread name', below), or, in some
2309          cases, by the program itself.
2310
2311       4. the current stack frame summary for that thread
2312
2313     An asterisk `*' to the left of the GDB thread number indicates the
2314     current thread.
2315
2316     For example,
2317
2318     (gdb) info threads
2319       Id   Target Id         Frame
2320       3    process 35 thread 27  0x34e5 in sigpause ()
2321       2    process 35 thread 23  0x34e5 in sigpause ()
2322     * 1    process 35 thread 13  main (argc=1, argv=0x7ffffff8)
2323         at threadtest.c:68
2324
2325   On Solaris, you can display more information about user threads with
2326a Solaris-specific command:
2327
2328`maint info sol-threads'
2329     Display info on Solaris user threads.
2330
2331`thread THREADNO'
2332     Make thread number THREADNO the current thread.  The command
2333     argument THREADNO is the internal GDB thread number, as shown in
2334     the first field of the `info threads' display.  GDB responds by
2335     displaying the system identifier of the thread you selected, and
2336     its current stack frame summary:
2337
2338          (gdb) thread 2
2339          [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2340          #0  some_function (ignore=0x0) at example.c:8
2341          8	    printf ("hello\n");
2342
2343     As with the `[New ...]' message, the form of the text after
2344     `Switching to' depends on your system's conventions for identifying
2345     threads.
2346
2347     The debugger convenience variable `$_thread' contains the number
2348     of the current thread.  You may find this useful in writing
2349     breakpoint conditional expressions, command scripts, and so forth.
2350     See *Note Convenience Variables: Convenience Vars, for general
2351     information on convenience variables.
2352
2353`thread apply [THREADNO | all] COMMAND'
2354     The `thread apply' command allows you to apply the named COMMAND
2355     to one or more threads.  Specify the numbers of the threads that
2356     you want affected with the command argument THREADNO.  It can be a
2357     single thread number, one of the numbers shown in the first field
2358     of the `info threads' display; or it could be a range of thread
2359     numbers, as in `2-4'.  To apply a command to all threads, type
2360     `thread apply all COMMAND'.
2361
2362`thread name [NAME]'
2363     This command assigns a name to the current thread.  If no argument
2364     is given, any existing user-specified name is removed.  The thread
2365     name appears in the `info threads' display.
2366
2367     On some systems, such as GNU/Linux, GDB is able to determine the
2368     name of the thread as given by the OS.  On these systems, a name
2369     specified with `thread name' will override the system-give name,
2370     and removing the user-specified name will cause GDB to once again
2371     display the system-specified name.
2372
2373`thread find [REGEXP]'
2374     Search for and display thread ids whose name or SYSTAG matches the
2375     supplied regular expression.
2376
2377     As well as being the complement to the `thread name' command, this
2378     command also allows you to identify a thread by its target SYSTAG.
2379     For instance, on GNU/Linux, the target SYSTAG is the LWP id.
2380
2381          (GDB) thread find 26688
2382          Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2383          (GDB) info thread 4
2384            Id   Target Id         Frame
2385            4    Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
2386
2387`set print thread-events'
2388`set print thread-events on'
2389`set print thread-events off'
2390     The `set print thread-events' command allows you to enable or
2391     disable printing of messages when GDB notices that new threads have
2392     started or that threads have exited.  By default, these messages
2393     will be printed if detection of these events is supported by the
2394     target.  Note that these messages cannot be disabled on all
2395     targets.
2396
2397`show print thread-events'
2398     Show whether messages will be printed when GDB detects that threads
2399     have started and exited.
2400
2401   *Note Stopping and Starting Multi-thread Programs: Thread Stops, for
2402more information about how GDB behaves when you stop and start programs
2403with multiple threads.
2404
2405   *Note Setting Watchpoints: Set Watchpoints, for information about
2406watchpoints in programs with multiple threads.
2407
2408`set libthread-db-search-path [PATH]'
2409     If this variable is set, PATH is a colon-separated list of
2410     directories GDB will use to search for `libthread_db'.  If you
2411     omit PATH, `libthread-db-search-path' will be reset to its default
2412     value (`$sdir:$pdir' on GNU/Linux and Solaris systems).
2413     Internally, the default value comes from the
2414     `LIBTHREAD_DB_SEARCH_PATH' macro.
2415
2416     On GNU/Linux and Solaris systems, GDB uses a "helper"
2417     `libthread_db' library to obtain information about threads in the
2418     inferior process.  GDB will use `libthread-db-search-path' to find
2419     `libthread_db'.  GDB also consults first if inferior specific
2420     thread debugging library loading is enabled by `set auto-load
2421     libthread-db' (*note libthread_db.so.1 file::).
2422
2423     A special entry `$sdir' for `libthread-db-search-path' refers to
2424     the default system directories that are normally searched for
2425     loading shared libraries.  The `$sdir' entry is the only kind not
2426     needing to be enabled by `set auto-load libthread-db' (*note
2427     libthread_db.so.1 file::).
2428
2429     A special entry `$pdir' for `libthread-db-search-path' refers to
2430     the directory from which `libpthread' was loaded in the inferior
2431     process.
2432
2433     For any `libthread_db' library GDB finds in above directories, GDB
2434     attempts to initialize it with the current inferior process.  If
2435     this initialization fails (which could happen because of a version
2436     mismatch between `libthread_db' and `libpthread'), GDB will unload
2437     `libthread_db', and continue with the next directory.  If none of
2438     `libthread_db' libraries initialize successfully, GDB will issue a
2439     warning and thread debugging will be disabled.
2440
2441     Setting `libthread-db-search-path' is currently implemented only
2442     on some platforms.
2443
2444`show libthread-db-search-path'
2445     Display current libthread_db search path.
2446
2447`set debug libthread-db'
2448`show debug libthread-db'
2449     Turns on or off display of `libthread_db'-related events.  Use `1'
2450     to enable, `0' to disable.
2451
2452
2453File: gdb.info,  Node: Forks,  Next: Checkpoint/Restart,  Prev: Threads,  Up: Running
2454
24554.11 Debugging Forks
2456====================
2457
2458On most systems, GDB has no special support for debugging programs
2459which create additional processes using the `fork' function.  When a
2460program forks, GDB will continue to debug the parent process and the
2461child process will run unimpeded.  If you have set a breakpoint in any
2462code which the child then executes, the child will get a `SIGTRAP'
2463signal which (unless it catches the signal) will cause it to terminate.
2464
2465   However, if you want to debug the child process there is a workaround
2466which isn't too painful.  Put a call to `sleep' in the code which the
2467child process executes after the fork.  It may be useful to sleep only
2468if a certain environment variable is set, or a certain file exists, so
2469that the delay need not occur when you don't want to run GDB on the
2470child.  While the child is sleeping, use the `ps' program to get its
2471process ID.  Then tell GDB (a new invocation of GDB if you are also
2472debugging the parent process) to attach to the child process (*note
2473Attach::).  From that point on you can debug the child process just
2474like any other process which you attached to.
2475
2476   On some systems, GDB provides support for debugging programs that
2477create additional processes using the `fork' or `vfork' functions.
2478Currently, the only platforms with this feature are HP-UX (11.x and
2479later only?) and GNU/Linux (kernel version 2.5.60 and later).
2480
2481   By default, when a program forks, GDB will continue to debug the
2482parent process and the child process will run unimpeded.
2483
2484   If you want to follow the child process instead of the parent
2485process, use the command `set follow-fork-mode'.
2486
2487`set follow-fork-mode MODE'
2488     Set the debugger response to a program call of `fork' or `vfork'.
2489     A call to `fork' or `vfork' creates a new process.  The MODE
2490     argument can be:
2491
2492    `parent'
2493          The original process is debugged after a fork.  The child
2494          process runs unimpeded.  This is the default.
2495
2496    `child'
2497          The new process is debugged after a fork.  The parent process
2498          runs unimpeded.
2499
2500
2501`show follow-fork-mode'
2502     Display the current debugger response to a `fork' or `vfork' call.
2503
2504   On Linux, if you want to debug both the parent and child processes,
2505use the command `set detach-on-fork'.
2506
2507`set detach-on-fork MODE'
2508     Tells gdb whether to detach one of the processes after a fork, or
2509     retain debugger control over them both.
2510
2511    `on'
2512          The child process (or parent process, depending on the value
2513          of `follow-fork-mode') will be detached and allowed to run
2514          independently.  This is the default.
2515
2516    `off'
2517          Both processes will be held under the control of GDB.  One
2518          process (child or parent, depending on the value of
2519          `follow-fork-mode') is debugged as usual, while the other is
2520          held suspended.
2521
2522
2523`show detach-on-fork'
2524     Show whether detach-on-fork mode is on/off.
2525
2526   If you choose to set `detach-on-fork' mode off, then GDB will retain
2527control of all forked processes (including nested forks).  You can list
2528the forked processes under the control of GDB by using the
2529`info inferiors' command, and switch from one fork to another by using
2530the `inferior' command (*note Debugging Multiple Inferiors and
2531Programs: Inferiors and Programs.).
2532
2533   To quit debugging one of the forked processes, you can either detach
2534from it by using the `detach inferiors' command (allowing it to run
2535independently), or kill it using the `kill inferiors' command.  *Note
2536Debugging Multiple Inferiors and Programs: Inferiors and Programs.
2537
2538   If you ask to debug a child process and a `vfork' is followed by an
2539`exec', GDB executes the new target up to the first breakpoint in the
2540new target.  If you have a breakpoint set on `main' in your original
2541program, the breakpoint will also be set on the child process's `main'.
2542
2543   On some systems, when a child process is spawned by `vfork', you
2544cannot debug the child or parent until an `exec' call completes.
2545
2546   If you issue a `run' command to GDB after an `exec' call executes,
2547the new target restarts.  To restart the parent process, use the `file'
2548command with the parent executable name as its argument.  By default,
2549after an `exec' call executes, GDB discards the symbols of the previous
2550executable image.  You can change this behaviour with the
2551`set follow-exec-mode' command.
2552
2553`set follow-exec-mode MODE'
2554     Set debugger response to a program call of `exec'.  An `exec' call
2555     replaces the program image of a process.
2556
2557     `follow-exec-mode' can be:
2558
2559    `new'
2560          GDB creates a new inferior and rebinds the process to this
2561          new inferior.  The program the process was running before the
2562          `exec' call can be restarted afterwards by restarting the
2563          original inferior.
2564
2565          For example:
2566
2567               (gdb) info inferiors
2568               (gdb) info inferior
2569                 Id   Description   Executable
2570               * 1    <null>        prog1
2571               (gdb) run
2572               process 12020 is executing new program: prog2
2573               Program exited normally.
2574               (gdb) info inferiors
2575                 Id   Description   Executable
2576               * 2    <null>        prog2
2577                 1    <null>        prog1
2578
2579    `same'
2580          GDB keeps the process bound to the same inferior.  The new
2581          executable image replaces the previous executable loaded in
2582          the inferior.  Restarting the inferior after the `exec' call,
2583          with e.g., the `run' command, restarts the executable the
2584          process was running after the `exec' call.  This is the
2585          default mode.
2586
2587          For example:
2588
2589               (gdb) info inferiors
2590                 Id   Description   Executable
2591               * 1    <null>        prog1
2592               (gdb) run
2593               process 12020 is executing new program: prog2
2594               Program exited normally.
2595               (gdb) info inferiors
2596                 Id   Description   Executable
2597               * 1    <null>        prog2
2598
2599
2600   You can use the `catch' command to make GDB stop whenever a `fork',
2601`vfork', or `exec' call is made.  *Note Setting Catchpoints: Set
2602Catchpoints.
2603
2604
2605File: gdb.info,  Node: Checkpoint/Restart,  Prev: Forks,  Up: Running
2606
26074.12 Setting a _Bookmark_ to Return to Later
2608============================================
2609
2610On certain operating systems(1), GDB is able to save a "snapshot" of a
2611program's state, called a "checkpoint", and come back to it later.
2612
2613   Returning to a checkpoint effectively undoes everything that has
2614happened in the program since the `checkpoint' was saved.  This
2615includes changes in memory, registers, and even (within some limits)
2616system state.  Effectively, it is like going back in time to the moment
2617when the checkpoint was saved.
2618
2619   Thus, if you're stepping thru a program and you think you're getting
2620close to the point where things go wrong, you can save a checkpoint.
2621Then, if you accidentally go too far and miss the critical statement,
2622instead of having to restart your program from the beginning, you can
2623just go back to the checkpoint and start again from there.
2624
2625   This can be especially useful if it takes a lot of time or steps to
2626reach the point where you think the bug occurs.
2627
2628   To use the `checkpoint'/`restart' method of debugging:
2629
2630`checkpoint'
2631     Save a snapshot of the debugged program's current execution state.
2632     The `checkpoint' command takes no arguments, but each checkpoint
2633     is assigned a small integer id, similar to a breakpoint id.
2634
2635`info checkpoints'
2636     List the checkpoints that have been saved in the current debugging
2637     session.  For each checkpoint, the following information will be
2638     listed:
2639
2640    `Checkpoint ID'
2641
2642    `Process ID'
2643
2644    `Code Address'
2645
2646    `Source line, or label'
2647
2648`restart CHECKPOINT-ID'
2649     Restore the program state that was saved as checkpoint number
2650     CHECKPOINT-ID.  All program variables, registers, stack frames
2651     etc.  will be returned to the values that they had when the
2652     checkpoint was saved.  In essence, gdb will "wind back the clock"
2653     to the point in time when the checkpoint was saved.
2654
2655     Note that breakpoints, GDB variables, command history etc.  are
2656     not affected by restoring a checkpoint.  In general, a checkpoint
2657     only restores things that reside in the program being debugged,
2658     not in the debugger.
2659
2660`delete checkpoint CHECKPOINT-ID'
2661     Delete the previously-saved checkpoint identified by CHECKPOINT-ID.
2662
2663
2664   Returning to a previously saved checkpoint will restore the user
2665state of the program being debugged, plus a significant subset of the
2666system (OS) state, including file pointers.  It won't "un-write" data
2667from a file, but it will rewind the file pointer to the previous
2668location, so that the previously written data can be overwritten.  For
2669files opened in read mode, the pointer will also be restored so that the
2670previously read data can be read again.
2671
2672   Of course, characters that have been sent to a printer (or other
2673external device) cannot be "snatched back", and characters received
2674from eg. a serial device can be removed from internal program buffers,
2675but they cannot be "pushed back" into the serial pipeline, ready to be
2676received again.  Similarly, the actual contents of files that have been
2677changed cannot be restored (at this time).
2678
2679   However, within those constraints, you actually can "rewind" your
2680program to a previously saved point in time, and begin debugging it
2681again -- and you can change the course of events so as to debug a
2682different execution path this time.
2683
2684   Finally, there is one bit of internal program state that will be
2685different when you return to a checkpoint -- the program's process id.
2686Each checkpoint will have a unique process id (or PID), and each will
2687be different from the program's original PID.  If your program has
2688saved a local copy of its process id, this could potentially pose a
2689problem.
2690
26914.12.1 A Non-obvious Benefit of Using Checkpoints
2692-------------------------------------------------
2693
2694On some systems such as GNU/Linux, address space randomization is
2695performed on new processes for security reasons.  This makes it
2696difficult or impossible to set a breakpoint, or watchpoint, on an
2697absolute address if you have to restart the program, since the absolute
2698location of a symbol will change from one execution to the next.
2699
2700   A checkpoint, however, is an _identical_ copy of a process.
2701Therefore if you create a checkpoint at (eg.) the start of main, and
2702simply return to that checkpoint instead of restarting the process, you
2703can avoid the effects of address randomization and your symbols will
2704all stay in the same place.
2705
2706   ---------- Footnotes ----------
2707
2708   (1) Currently, only GNU/Linux.
2709
2710
2711File: gdb.info,  Node: Stopping,  Next: Reverse Execution,  Prev: Running,  Up: Top
2712
27135 Stopping and Continuing
2714*************************
2715
2716The principal purposes of using a debugger are so that you can stop your
2717program before it terminates; or so that, if your program runs into
2718trouble, you can investigate and find out why.
2719
2720   Inside GDB, your program may stop for any of several reasons, such
2721as a signal, a breakpoint, or reaching a new line after a GDB command
2722such as `step'.  You may then examine and change variables, set new
2723breakpoints or remove old ones, and then continue execution.  Usually,
2724the messages shown by GDB provide ample explanation of the status of
2725your program--but you can also explicitly request this information at
2726any time.
2727
2728`info program'
2729     Display information about the status of your program: whether it is
2730     running or not, what process it is, and why it stopped.
2731
2732* Menu:
2733
2734* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
2735* Continuing and Stepping::     Resuming execution
2736* Skipping Over Functions and Files::
2737                                Skipping over functions and files
2738* Signals::                     Signals
2739* Thread Stops::                Stopping and starting multi-thread programs
2740
2741
2742File: gdb.info,  Node: Breakpoints,  Next: Continuing and Stepping,  Up: Stopping
2743
27445.1 Breakpoints, Watchpoints, and Catchpoints
2745=============================================
2746
2747A "breakpoint" makes your program stop whenever a certain point in the
2748program is reached.  For each breakpoint, you can add conditions to
2749control in finer detail whether your program stops.  You can set
2750breakpoints with the `break' command and its variants (*note Setting
2751Breakpoints: Set Breaks.), to specify the place where your program
2752should stop by line number, function name or exact address in the
2753program.
2754
2755   On some systems, you can set breakpoints in shared libraries before
2756the executable is run.  There is a minor limitation on HP-UX systems:
2757you must wait until the executable is run in order to set breakpoints
2758in shared library routines that are not called directly by the program
2759(for example, routines that are arguments in a `pthread_create' call).
2760
2761   A "watchpoint" is a special breakpoint that stops your program when
2762the value of an expression changes.  The expression may be a value of a
2763variable, or it could involve values of one or more variables combined
2764by operators, such as `a + b'.  This is sometimes called "data
2765breakpoints".  You must use a different command to set watchpoints
2766(*note Setting Watchpoints: Set Watchpoints.), but aside from that, you
2767can manage a watchpoint like any other breakpoint: you enable, disable,
2768and delete both breakpoints and watchpoints using the same commands.
2769
2770   You can arrange to have values from your program displayed
2771automatically whenever GDB stops at a breakpoint.  *Note Automatic
2772Display: Auto Display.
2773
2774   A "catchpoint" is another special breakpoint that stops your program
2775when a certain kind of event occurs, such as the throwing of a C++
2776exception or the loading of a library.  As with watchpoints, you use a
2777different command to set a catchpoint (*note Setting Catchpoints: Set
2778Catchpoints.), but aside from that, you can manage a catchpoint like any
2779other breakpoint.  (To stop when your program receives a signal, use the
2780`handle' command; see *note Signals: Signals.)
2781
2782   GDB assigns a number to each breakpoint, watchpoint, or catchpoint
2783when you create it; these numbers are successive integers starting with
2784one.  In many of the commands for controlling various features of
2785breakpoints you use the breakpoint number to say which breakpoint you
2786want to change.  Each breakpoint may be "enabled" or "disabled"; if
2787disabled, it has no effect on your program until you enable it again.
2788
2789   Some GDB commands accept a range of breakpoints on which to operate.
2790A breakpoint range is either a single breakpoint number, like `5', or
2791two such numbers, in increasing order, separated by a hyphen, like
2792`5-7'.  When a breakpoint range is given to a command, all breakpoints
2793in that range are operated on.
2794
2795* Menu:
2796
2797* Set Breaks::                  Setting breakpoints
2798* Set Watchpoints::             Setting watchpoints
2799* Set Catchpoints::             Setting catchpoints
2800* Delete Breaks::               Deleting breakpoints
2801* Disabling::                   Disabling breakpoints
2802* Conditions::                  Break conditions
2803* Break Commands::              Breakpoint command lists
2804* Dynamic Printf::              Dynamic printf
2805* Save Breakpoints::            How to save breakpoints in a file
2806* Static Probe Points::         Listing static probe points
2807* Error in Breakpoints::        ``Cannot insert breakpoints''
2808* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
2809
2810
2811File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Up: Breakpoints
2812
28135.1.1 Setting Breakpoints
2814-------------------------
2815
2816Breakpoints are set with the `break' command (abbreviated `b').  The
2817debugger convenience variable `$bpnum' records the number of the
2818breakpoint you've set most recently; see *note Convenience Variables:
2819Convenience Vars, for a discussion of what you can do with convenience
2820variables.
2821
2822`break LOCATION'
2823     Set a breakpoint at the given LOCATION, which can specify a
2824     function name, a line number, or an address of an instruction.
2825     (*Note Specify Location::, for a list of all the possible ways to
2826     specify a LOCATION.)  The breakpoint will stop your program just
2827     before it executes any of the code in the specified LOCATION.
2828
2829     When using source languages that permit overloading of symbols,
2830     such as C++, a function name may refer to more than one possible
2831     place to break.  *Note Ambiguous Expressions: Ambiguous
2832     Expressions, for a discussion of that situation.
2833
2834     It is also possible to insert a breakpoint that will stop the
2835     program only if a specific thread (*note Thread-Specific
2836     Breakpoints::) or a specific task (*note Ada Tasks::) hits that
2837     breakpoint.
2838
2839`break'
2840     When called without any arguments, `break' sets a breakpoint at
2841     the next instruction to be executed in the selected stack frame
2842     (*note Examining the Stack: Stack.).  In any selected frame but the
2843     innermost, this makes your program stop as soon as control returns
2844     to that frame.  This is similar to the effect of a `finish'
2845     command in the frame inside the selected frame--except that
2846     `finish' does not leave an active breakpoint.  If you use `break'
2847     without an argument in the innermost frame, GDB stops the next
2848     time it reaches the current location; this may be useful inside
2849     loops.
2850
2851     GDB normally ignores breakpoints when it resumes execution, until
2852     at least one instruction has been executed.  If it did not do
2853     this, you would be unable to proceed past a breakpoint without
2854     first disabling the breakpoint.  This rule applies whether or not
2855     the breakpoint already existed when your program stopped.
2856
2857`break ... if COND'
2858     Set a breakpoint with condition COND; evaluate the expression COND
2859     each time the breakpoint is reached, and stop only if the value is
2860     nonzero--that is, if COND evaluates as true.  `...' stands for one
2861     of the possible arguments described above (or no argument)
2862     specifying where to break.  *Note Break Conditions: Conditions,
2863     for more information on breakpoint conditions.
2864
2865`tbreak ARGS'
2866     Set a breakpoint enabled only for one stop.  ARGS are the same as
2867     for the `break' command, and the breakpoint is set in the same
2868     way, but the breakpoint is automatically deleted after the first
2869     time your program stops there.  *Note Disabling Breakpoints:
2870     Disabling.
2871
2872`hbreak ARGS'
2873     Set a hardware-assisted breakpoint.  ARGS are the same as for the
2874     `break' command and the breakpoint is set in the same way, but the
2875     breakpoint requires hardware support and some target hardware may
2876     not have this support.  The main purpose of this is EPROM/ROM code
2877     debugging, so you can set a breakpoint at an instruction without
2878     changing the instruction.  This can be used with the new
2879     trap-generation provided by SPARClite DSU and most x86-based
2880     targets.  These targets will generate traps when a program
2881     accesses some data or instruction address that is assigned to the
2882     debug registers.  However the hardware breakpoint registers can
2883     take a limited number of breakpoints.  For example, on the DSU,
2884     only two data breakpoints can be set at a time, and GDB will
2885     reject this command if more than two are used.  Delete or disable
2886     unused hardware breakpoints before setting new ones (*note
2887     Disabling Breakpoints: Disabling.).  *Note Break Conditions:
2888     Conditions.  For remote targets, you can restrict the number of
2889     hardware breakpoints GDB will use, see *note set remote
2890     hardware-breakpoint-limit::.
2891
2892`thbreak ARGS'
2893     Set a hardware-assisted breakpoint enabled only for one stop.  ARGS
2894     are the same as for the `hbreak' command and the breakpoint is set
2895     in the same way.  However, like the `tbreak' command, the
2896     breakpoint is automatically deleted after the first time your
2897     program stops there.  Also, like the `hbreak' command, the
2898     breakpoint requires hardware support and some target hardware may
2899     not have this support.  *Note Disabling Breakpoints: Disabling.
2900     See also *note Break Conditions: Conditions.
2901
2902`rbreak REGEX'
2903     Set breakpoints on all functions matching the regular expression
2904     REGEX.  This command sets an unconditional breakpoint on all
2905     matches, printing a list of all breakpoints it set.  Once these
2906     breakpoints are set, they are treated just like the breakpoints
2907     set with the `break' command.  You can delete them, disable them,
2908     or make them conditional the same way as any other breakpoint.
2909
2910     The syntax of the regular expression is the standard one used with
2911     tools like `grep'.  Note that this is different from the syntax
2912     used by shells, so for instance `foo*' matches all functions that
2913     include an `fo' followed by zero or more `o's.  There is an
2914     implicit `.*' leading and trailing the regular expression you
2915     supply, so to match only functions that begin with `foo', use
2916     `^foo'.
2917
2918     When debugging C++ programs, `rbreak' is useful for setting
2919     breakpoints on overloaded functions that are not members of any
2920     special classes.
2921
2922     The `rbreak' command can be used to set breakpoints in *all* the
2923     functions in a program, like this:
2924
2925          (gdb) rbreak .
2926
2927`rbreak FILE:REGEX'
2928     If `rbreak' is called with a filename qualification, it limits the
2929     search for functions matching the given regular expression to the
2930     specified FILE.  This can be used, for example, to set breakpoints
2931     on every function in a given file:
2932
2933          (gdb) rbreak file.c:.
2934
2935     The colon separating the filename qualifier from the regex may
2936     optionally be surrounded by spaces.
2937
2938`info breakpoints [N...]'
2939`info break [N...]'
2940     Print a table of all breakpoints, watchpoints, and catchpoints set
2941     and not deleted.  Optional argument N means print information only
2942     about the specified breakpoint(s) (or watchpoint(s) or
2943     catchpoint(s)).  For each breakpoint, following columns are
2944     printed:
2945
2946    _Breakpoint Numbers_
2947
2948    _Type_
2949          Breakpoint, watchpoint, or catchpoint.
2950
2951    _Disposition_
2952          Whether the breakpoint is marked to be disabled or deleted
2953          when hit.
2954
2955    _Enabled or Disabled_
2956          Enabled breakpoints are marked with `y'.  `n' marks
2957          breakpoints that are not enabled.
2958
2959    _Address_
2960          Where the breakpoint is in your program, as a memory address.
2961          For a pending breakpoint whose address is not yet known, this
2962          field will contain `<PENDING>'.  Such breakpoint won't fire
2963          until a shared library that has the symbol or line referred
2964          by breakpoint is loaded.  See below for details.  A
2965          breakpoint with several locations will have `<MULTIPLE>' in
2966          this field--see below for details.
2967
2968    _What_
2969          Where the breakpoint is in the source for your program, as a
2970          file and line number.  For a pending breakpoint, the original
2971          string passed to the breakpoint command will be listed as it
2972          cannot be resolved until the appropriate shared library is
2973          loaded in the future.
2974
2975     If a breakpoint is conditional, there are two evaluation modes:
2976     "host" and "target".  If mode is "host", breakpoint condition
2977     evaluation is done by GDB on the host's side.  If it is "target",
2978     then the condition is evaluated by the target.  The `info break'
2979     command shows the condition on the line following the affected
2980     breakpoint, together with its condition evaluation mode in between
2981     parentheses.
2982
2983     Breakpoint commands, if any, are listed after that.  A pending
2984     breakpoint is allowed to have a condition specified for it.  The
2985     condition is not parsed for validity until a shared library is
2986     loaded that allows the pending breakpoint to resolve to a valid
2987     location.
2988
2989     `info break' with a breakpoint number N as argument lists only
2990     that breakpoint.  The convenience variable `$_' and the default
2991     examining-address for the `x' command are set to the address of
2992     the last breakpoint listed (*note Examining Memory: Memory.).
2993
2994     `info break' displays a count of the number of times the breakpoint
2995     has been hit.  This is especially useful in conjunction with the
2996     `ignore' command.  You can ignore a large number of breakpoint
2997     hits, look at the breakpoint info to see how many times the
2998     breakpoint was hit, and then run again, ignoring one less than
2999     that number.  This will get you quickly to the last hit of that
3000     breakpoint.
3001
3002     For a breakpoints with an enable count (xref) greater than 1,
3003     `info break' also displays that count.
3004
3005
3006   GDB allows you to set any number of breakpoints at the same place in
3007your program.  There is nothing silly or meaningless about this.  When
3008the breakpoints are conditional, this is even useful (*note Break
3009Conditions: Conditions.).
3010
3011   It is possible that a breakpoint corresponds to several locations in
3012your program.  Examples of this situation are:
3013
3014   * Multiple functions in the program may have the same name.
3015
3016   * For a C++ constructor, the GCC compiler generates several
3017     instances of the function body, used in different cases.
3018
3019   * For a C++ template function, a given line in the function can
3020     correspond to any number of instantiations.
3021
3022   * For an inlined function, a given source line can correspond to
3023     several places where that function is inlined.
3024
3025   In all those cases, GDB will insert a breakpoint at all the relevant
3026locations.
3027
3028   A breakpoint with multiple locations is displayed in the breakpoint
3029table using several rows--one header row, followed by one row for each
3030breakpoint location.  The header row has `<MULTIPLE>' in the address
3031column.  The rows for individual locations contain the actual addresses
3032for locations, and show the functions to which those locations belong.
3033The number column for a location is of the form
3034BREAKPOINT-NUMBER.LOCATION-NUMBER.
3035
3036   For example:
3037
3038     Num     Type           Disp Enb  Address    What
3039     1       breakpoint     keep y    <MULTIPLE>
3040             stop only if i==1
3041             breakpoint already hit 1 time
3042     1.1                         y    0x080486a2 in void foo<int>() at t.cc:8
3043     1.2                         y    0x080486ca in void foo<double>() at t.cc:8
3044
3045   Each location can be individually enabled or disabled by passing
3046BREAKPOINT-NUMBER.LOCATION-NUMBER as argument to the `enable' and
3047`disable' commands.  Note that you cannot delete the individual
3048locations from the list, you can only delete the entire list of
3049locations that belong to their parent breakpoint (with the `delete NUM'
3050command, where NUM is the number of the parent breakpoint, 1 in the
3051above example).  Disabling or enabling the parent breakpoint (*note
3052Disabling::) affects all of the locations that belong to that
3053breakpoint.
3054
3055   It's quite common to have a breakpoint inside a shared library.
3056Shared libraries can be loaded and unloaded explicitly, and possibly
3057repeatedly, as the program is executed.  To support this use case, GDB
3058updates breakpoint locations whenever any shared library is loaded or
3059unloaded.  Typically, you would set a breakpoint in a shared library at
3060the beginning of your debugging session, when the library is not
3061loaded, and when the symbols from the library are not available.  When
3062you try to set breakpoint, GDB will ask you if you want to set a so
3063called "pending breakpoint"--breakpoint whose address is not yet
3064resolved.
3065
3066   After the program is run, whenever a new shared library is loaded,
3067GDB reevaluates all the breakpoints.  When a newly loaded shared
3068library contains the symbol or line referred to by some pending
3069breakpoint, that breakpoint is resolved and becomes an ordinary
3070breakpoint.  When a library is unloaded, all breakpoints that refer to
3071its symbols or source lines become pending again.
3072
3073   This logic works for breakpoints with multiple locations, too.  For
3074example, if you have a breakpoint in a C++ template function, and a
3075newly loaded shared library has an instantiation of that template, a
3076new location is added to the list of locations for the breakpoint.
3077
3078   Except for having unresolved address, pending breakpoints do not
3079differ from regular breakpoints.  You can set conditions or commands,
3080enable and disable them and perform other breakpoint operations.
3081
3082   GDB provides some additional commands for controlling what happens
3083when the `break' command cannot resolve breakpoint address
3084specification to an address:
3085
3086`set breakpoint pending auto'
3087     This is the default behavior.  When GDB cannot find the breakpoint
3088     location, it queries you whether a pending breakpoint should be
3089     created.
3090
3091`set breakpoint pending on'
3092     This indicates that an unrecognized breakpoint location should
3093     automatically result in a pending breakpoint being created.
3094
3095`set breakpoint pending off'
3096     This indicates that pending breakpoints are not to be created.  Any
3097     unrecognized breakpoint location results in an error.  This
3098     setting does not affect any pending breakpoints previously created.
3099
3100`show breakpoint pending'
3101     Show the current behavior setting for creating pending breakpoints.
3102
3103   The settings above only affect the `break' command and its variants.
3104Once breakpoint is set, it will be automatically updated as shared
3105libraries are loaded and unloaded.
3106
3107   For some targets, GDB can automatically decide if hardware or
3108software breakpoints should be used, depending on whether the
3109breakpoint address is read-only or read-write.  This applies to
3110breakpoints set with the `break' command as well as to internal
3111breakpoints set by commands like `next' and `finish'.  For breakpoints
3112set with `hbreak', GDB will always use hardware breakpoints.
3113
3114   You can control this automatic behaviour with the following
3115commands::
3116
3117`set breakpoint auto-hw on'
3118     This is the default behavior.  When GDB sets a breakpoint, it will
3119     try to use the target memory map to decide if software or hardware
3120     breakpoint must be used.
3121
3122`set breakpoint auto-hw off'
3123     This indicates GDB should not automatically select breakpoint
3124     type.  If the target provides a memory map, GDB will warn when
3125     trying to set software breakpoint at a read-only address.
3126
3127   GDB normally implements breakpoints by replacing the program code at
3128the breakpoint address with a special instruction, which, when
3129executed, given control to the debugger.  By default, the program code
3130is so modified only when the program is resumed.  As soon as the
3131program stops, GDB restores the original instructions.  This behaviour
3132guards against leaving breakpoints inserted in the target should gdb
3133abrubptly disconnect.  However, with slow remote targets, inserting and
3134removing breakpoint can reduce the performance.  This behavior can be
3135controlled with the following commands::
3136
3137`set breakpoint always-inserted off'
3138     All breakpoints, including newly added by the user, are inserted in
3139     the target only when the target is resumed.  All breakpoints are
3140     removed from the target when it stops.
3141
3142`set breakpoint always-inserted on'
3143     Causes all breakpoints to be inserted in the target at all times.
3144     If the user adds a new breakpoint, or changes an existing
3145     breakpoint, the breakpoints in the target are updated immediately.
3146     A breakpoint is removed from the target only when breakpoint
3147     itself is removed.
3148
3149`set breakpoint always-inserted auto'
3150     This is the default mode.  If GDB is controlling the inferior in
3151     non-stop mode (*note Non-Stop Mode::), gdb behaves as if
3152     `breakpoint always-inserted' mode is on.  If GDB is controlling
3153     the inferior in all-stop mode, GDB behaves as if `breakpoint
3154     always-inserted' mode is off.
3155
3156   GDB handles conditional breakpoints by evaluating these conditions
3157when a breakpoint breaks.  If the condition is true, then the process
3158being debugged stops, otherwise the process is resumed.
3159
3160   If the target supports evaluating conditions on its end, GDB may
3161download the breakpoint, together with its conditions, to it.
3162
3163   This feature can be controlled via the following commands:
3164
3165`set breakpoint condition-evaluation host'
3166     This option commands GDB to evaluate the breakpoint conditions on
3167     the host's side.  Unconditional breakpoints are sent to the target
3168     which in turn receives the triggers and reports them back to GDB
3169     for condition evaluation.  This is the standard evaluation mode.
3170
3171`set breakpoint condition-evaluation target'
3172     This option commands GDB to download breakpoint conditions to the
3173     target at the moment of their insertion.  The target is
3174     responsible for evaluating the conditional expression and reporting
3175     breakpoint stop events back to GDB whenever the condition is true.
3176     Due to limitations of target-side evaluation, some conditions
3177     cannot be evaluated there, e.g., conditions that depend on local
3178     data that is only known to the host.  Examples include conditional
3179     expressions involving convenience variables, complex types that
3180     cannot be handled by the agent expression parser and expressions
3181     that are too long to be sent over to the target, specially when the
3182     target is a remote system.  In these cases, the conditions will be
3183     evaluated by GDB.
3184
3185`set breakpoint condition-evaluation auto'
3186     This is the default mode.  If the target supports evaluating
3187     breakpoint conditions on its end, GDB will download breakpoint
3188     conditions to the target (limitations mentioned previously apply).
3189     If the target does not support breakpoint condition evaluation,
3190     then GDB will fallback to evaluating all these conditions on the
3191     host's side.
3192
3193   GDB itself sometimes sets breakpoints in your program for special
3194purposes, such as proper handling of `longjmp' (in C programs).  These
3195internal breakpoints are assigned negative numbers, starting with `-1';
3196`info breakpoints' does not display them.  You can see these
3197breakpoints with the GDB maintenance command `maint info breakpoints'
3198(*note maint info breakpoints::).
3199
3200
3201File: gdb.info,  Node: Set Watchpoints,  Next: Set Catchpoints,  Prev: Set Breaks,  Up: Breakpoints
3202
32035.1.2 Setting Watchpoints
3204-------------------------
3205
3206You can use a watchpoint to stop execution whenever the value of an
3207expression changes, without having to predict a particular place where
3208this may happen.  (This is sometimes called a "data breakpoint".)  The
3209expression may be as simple as the value of a single variable, or as
3210complex as many variables combined by operators.  Examples include:
3211
3212   * A reference to the value of a single variable.
3213
3214   * An address cast to an appropriate data type.  For example, `*(int
3215     *)0x12345678' will watch a 4-byte region at the specified address
3216     (assuming an `int' occupies 4 bytes).
3217
3218   * An arbitrarily complex expression, such as `a*b + c/d'.  The
3219     expression can use any operators valid in the program's native
3220     language (*note Languages::).
3221
3222   You can set a watchpoint on an expression even if the expression can
3223not be evaluated yet.  For instance, you can set a watchpoint on
3224`*global_ptr' before `global_ptr' is initialized.  GDB will stop when
3225your program sets `global_ptr' and the expression produces a valid
3226value.  If the expression becomes valid in some other way than changing
3227a variable (e.g. if the memory pointed to by `*global_ptr' becomes
3228readable as the result of a `malloc' call), GDB may not stop until the
3229next time the expression changes.
3230
3231   Depending on your system, watchpoints may be implemented in software
3232or hardware.  GDB does software watchpointing by single-stepping your
3233program and testing the variable's value each time, which is hundreds of
3234times slower than normal execution.  (But this may still be worth it, to
3235catch errors where you have no clue what part of your program is the
3236culprit.)
3237
3238   On some systems, such as HP-UX, PowerPC, GNU/Linux and most other
3239x86-based targets, GDB includes support for hardware watchpoints, which
3240do not slow down the running of your program.
3241
3242`watch [-l|-location] EXPR [thread THREADNUM] [mask MASKVALUE]'
3243     Set a watchpoint for an expression.  GDB will break when the
3244     expression EXPR is written into by the program and its value
3245     changes.  The simplest (and the most popular) use of this command
3246     is to watch the value of a single variable:
3247
3248          (gdb) watch foo
3249
3250     If the command includes a `[thread THREADNUM]' argument, GDB
3251     breaks only when the thread identified by THREADNUM changes the
3252     value of EXPR.  If any other threads change the value of EXPR, GDB
3253     will not break.  Note that watchpoints restricted to a single
3254     thread in this way only work with Hardware Watchpoints.
3255
3256     Ordinarily a watchpoint respects the scope of variables in EXPR
3257     (see below).  The `-location' argument tells GDB to instead watch
3258     the memory referred to by EXPR.  In this case, GDB will evaluate
3259     EXPR, take the address of the result, and watch the memory at that
3260     address.  The type of the result is used to determine the size of
3261     the watched memory.  If the expression's result does not have an
3262     address, then GDB will print an error.
3263
3264     The `[mask MASKVALUE]' argument allows creation of masked
3265     watchpoints, if the current architecture supports this feature
3266     (e.g., PowerPC Embedded architecture, see *note PowerPC
3267     Embedded::.)  A "masked watchpoint" specifies a mask in addition
3268     to an address to watch.  The mask specifies that some bits of an
3269     address (the bits which are reset in the mask) should be ignored
3270     when matching the address accessed by the inferior against the
3271     watchpoint address.  Thus, a masked watchpoint watches many
3272     addresses simultaneously--those addresses whose unmasked bits are
3273     identical to the unmasked bits in the watchpoint address.  The
3274     `mask' argument implies `-location'.  Examples:
3275
3276          (gdb) watch foo mask 0xffff00ff
3277          (gdb) watch *0xdeadbeef mask 0xffffff00
3278
3279`rwatch [-l|-location] EXPR [thread THREADNUM] [mask MASKVALUE]'
3280     Set a watchpoint that will break when the value of EXPR is read by
3281     the program.
3282
3283`awatch [-l|-location] EXPR [thread THREADNUM] [mask MASKVALUE]'
3284     Set a watchpoint that will break when EXPR is either read from or
3285     written into by the program.
3286
3287`info watchpoints [N...]'
3288     This command prints a list of watchpoints, using the same format as
3289     `info break' (*note Set Breaks::).
3290
3291   If you watch for a change in a numerically entered address you need
3292to dereference it, as the address itself is just a constant number
3293which will never change.  GDB refuses to create a watchpoint that
3294watches a never-changing value:
3295
3296     (gdb) watch 0x600850
3297     Cannot watch constant value 0x600850.
3298     (gdb) watch *(int *) 0x600850
3299     Watchpoint 1: *(int *) 6293584
3300
3301   GDB sets a "hardware watchpoint" if possible.  Hardware watchpoints
3302execute very quickly, and the debugger reports a change in value at the
3303exact instruction where the change occurs.  If GDB cannot set a
3304hardware watchpoint, it sets a software watchpoint, which executes more
3305slowly and reports the change in value at the next _statement_, not the
3306instruction, after the change occurs.
3307
3308   You can force GDB to use only software watchpoints with the `set
3309can-use-hw-watchpoints 0' command.  With this variable set to zero, GDB
3310will never try to use hardware watchpoints, even if the underlying
3311system supports them.  (Note that hardware-assisted watchpoints that
3312were set _before_ setting `can-use-hw-watchpoints' to zero will still
3313use the hardware mechanism of watching expression values.)
3314
3315`set can-use-hw-watchpoints'
3316     Set whether or not to use hardware watchpoints.
3317
3318`show can-use-hw-watchpoints'
3319     Show the current mode of using hardware watchpoints.
3320
3321   For remote targets, you can restrict the number of hardware
3322watchpoints GDB will use, see *note set remote
3323hardware-breakpoint-limit::.
3324
3325   When you issue the `watch' command, GDB reports
3326
3327     Hardware watchpoint NUM: EXPR
3328
3329if it was able to set a hardware watchpoint.
3330
3331   Currently, the `awatch' and `rwatch' commands can only set hardware
3332watchpoints, because accesses to data that don't change the value of
3333the watched expression cannot be detected without examining every
3334instruction as it is being executed, and GDB does not do that
3335currently.  If GDB finds that it is unable to set a hardware breakpoint
3336with the `awatch' or `rwatch' command, it will print a message like
3337this:
3338
3339     Expression cannot be implemented with read/access watchpoint.
3340
3341   Sometimes, GDB cannot set a hardware watchpoint because the data
3342type of the watched expression is wider than what a hardware watchpoint
3343on the target machine can handle.  For example, some systems can only
3344watch regions that are up to 4 bytes wide; on such systems you cannot
3345set hardware watchpoints for an expression that yields a
3346double-precision floating-point number (which is typically 8 bytes
3347wide).  As a work-around, it might be possible to break the large region
3348into a series of smaller ones and watch them with separate watchpoints.
3349
3350   If you set too many hardware watchpoints, GDB might be unable to
3351insert all of them when you resume the execution of your program.
3352Since the precise number of active watchpoints is unknown until such
3353time as the program is about to be resumed, GDB might not be able to
3354warn you about this when you set the watchpoints, and the warning will
3355be printed only when the program is resumed:
3356
3357     Hardware watchpoint NUM: Could not insert watchpoint
3358
3359If this happens, delete or disable some of the watchpoints.
3360
3361   Watching complex expressions that reference many variables can also
3362exhaust the resources available for hardware-assisted watchpoints.
3363That's because GDB needs to watch every variable in the expression with
3364separately allocated resources.
3365
3366   If you call a function interactively using `print' or `call', any
3367watchpoints you have set will be inactive until GDB reaches another
3368kind of breakpoint or the call completes.
3369
3370   GDB automatically deletes watchpoints that watch local (automatic)
3371variables, or expressions that involve such variables, when they go out
3372of scope, that is, when the execution leaves the block in which these
3373variables were defined.  In particular, when the program being debugged
3374terminates, _all_ local variables go out of scope, and so only
3375watchpoints that watch global variables remain set.  If you rerun the
3376program, you will need to set all such watchpoints again.  One way of
3377doing that would be to set a code breakpoint at the entry to the `main'
3378function and when it breaks, set all the watchpoints.
3379
3380   In multi-threaded programs, watchpoints will detect changes to the
3381watched expression from every thread.
3382
3383     _Warning:_ In multi-threaded programs, software watchpoints have
3384     only limited usefulness.  If GDB creates a software watchpoint, it
3385     can only watch the value of an expression _in a single thread_.
3386     If you are confident that the expression can only change due to
3387     the current thread's activity (and if you are also confident that
3388     no other thread can become current), then you can use software
3389     watchpoints as usual.  However, GDB may not notice when a
3390     non-current thread's activity changes the expression.  (Hardware
3391     watchpoints, in contrast, watch an expression in all threads.)
3392
3393   *Note set remote hardware-watchpoint-limit::.
3394
3395
3396File: gdb.info,  Node: Set Catchpoints,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
3397
33985.1.3 Setting Catchpoints
3399-------------------------
3400
3401You can use "catchpoints" to cause the debugger to stop for certain
3402kinds of program events, such as C++ exceptions or the loading of a
3403shared library.  Use the `catch' command to set a catchpoint.
3404
3405`catch EVENT'
3406     Stop when EVENT occurs.  EVENT can be any of the following:
3407    `throw'
3408          The throwing of a C++ exception.
3409
3410    `catch'
3411          The catching of a C++ exception.
3412
3413    `exception'
3414          An Ada exception being raised.  If an exception name is
3415          specified at the end of the command (eg `catch exception
3416          Program_Error'), the debugger will stop only when this
3417          specific exception is raised.  Otherwise, the debugger stops
3418          execution when any Ada exception is raised.
3419
3420          When inserting an exception catchpoint on a user-defined
3421          exception whose name is identical to one of the exceptions
3422          defined by the language, the fully qualified name must be
3423          used as the exception name.  Otherwise, GDB will assume that
3424          it should stop on the pre-defined exception rather than the
3425          user-defined one.  For instance, assuming an exception called
3426          `Constraint_Error' is defined in package `Pck', then the
3427          command to use to catch such exceptions is `catch exception
3428          Pck.Constraint_Error'.
3429
3430    `exception unhandled'
3431          An exception that was raised but is not handled by the
3432          program.
3433
3434    `assert'
3435          A failed Ada assertion.
3436
3437    `exec'
3438          A call to `exec'.  This is currently only available for HP-UX
3439          and GNU/Linux.
3440
3441    `syscall'
3442    `syscall [NAME | NUMBER] ...'
3443          A call to or return from a system call, a.k.a. "syscall".  A
3444          syscall is a mechanism for application programs to request a
3445          service from the operating system (OS) or one of the OS
3446          system services.  GDB can catch some or all of the syscalls
3447          issued by the debuggee, and show the related information for
3448          each syscall.  If no argument is specified, calls to and
3449          returns from all system calls will be caught.
3450
3451          NAME can be any system call name that is valid for the
3452          underlying OS.  Just what syscalls are valid depends on the
3453          OS.  On GNU and Unix systems, you can find the full list of
3454          valid syscall names on `/usr/include/asm/unistd.h'.
3455
3456          Normally, GDB knows in advance which syscalls are valid for
3457          each OS, so you can use the GDB command-line completion
3458          facilities (*note command completion: Completion.) to list the
3459          available choices.
3460
3461          You may also specify the system call numerically.  A syscall's
3462          number is the value passed to the OS's syscall dispatcher to
3463          identify the requested service.  When you specify the syscall
3464          by its name, GDB uses its database of syscalls to convert the
3465          name into the corresponding numeric code, but using the
3466          number directly may be useful if GDB's database does not have
3467          the complete list of syscalls on your system (e.g., because
3468          GDB lags behind the OS upgrades).
3469
3470          The example below illustrates how this command works if you
3471          don't provide arguments to it:
3472
3473               (gdb) catch syscall
3474               Catchpoint 1 (syscall)
3475               (gdb) r
3476               Starting program: /tmp/catch-syscall
3477
3478               Catchpoint 1 (call to syscall 'close'), \
3479               	   0xffffe424 in __kernel_vsyscall ()
3480               (gdb) c
3481               Continuing.
3482
3483               Catchpoint 1 (returned from syscall 'close'), \
3484               	0xffffe424 in __kernel_vsyscall ()
3485               (gdb)
3486
3487          Here is an example of catching a system call by name:
3488
3489               (gdb) catch syscall chroot
3490               Catchpoint 1 (syscall 'chroot' [61])
3491               (gdb) r
3492               Starting program: /tmp/catch-syscall
3493
3494               Catchpoint 1 (call to syscall 'chroot'), \
3495               		   0xffffe424 in __kernel_vsyscall ()
3496               (gdb) c
3497               Continuing.
3498
3499               Catchpoint 1 (returned from syscall 'chroot'), \
3500               	0xffffe424 in __kernel_vsyscall ()
3501               (gdb)
3502
3503          An example of specifying a system call numerically.  In the
3504          case below, the syscall number has a corresponding entry in
3505          the XML file, so GDB finds its name and prints it:
3506
3507               (gdb) catch syscall 252
3508               Catchpoint 1 (syscall(s) 'exit_group')
3509               (gdb) r
3510               Starting program: /tmp/catch-syscall
3511
3512               Catchpoint 1 (call to syscall 'exit_group'), \
3513               		   0xffffe424 in __kernel_vsyscall ()
3514               (gdb) c
3515               Continuing.
3516
3517               Program exited normally.
3518               (gdb)
3519
3520          However, there can be situations when there is no
3521          corresponding name in XML file for that syscall number.  In
3522          this case, GDB prints a warning message saying that it was
3523          not able to find the syscall name, but the catchpoint will be
3524          set anyway.  See the example below:
3525
3526               (gdb) catch syscall 764
3527               warning: The number '764' does not represent a known syscall.
3528               Catchpoint 2 (syscall 764)
3529               (gdb)
3530
3531          If you configure GDB using the `--without-expat' option, it
3532          will not be able to display syscall names.  Also, if your
3533          architecture does not have an XML file describing its system
3534          calls, you will not be able to see the syscall names.  It is
3535          important to notice that these two features are used for
3536          accessing the syscall name database.  In either case, you
3537          will see a warning like this:
3538
3539               (gdb) catch syscall
3540               warning: Could not open "syscalls/i386-linux.xml"
3541               warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
3542               GDB will not be able to display syscall names.
3543               Catchpoint 1 (syscall)
3544               (gdb)
3545
3546          Of course, the file name will change depending on your
3547          architecture and system.
3548
3549          Still using the example above, you can also try to catch a
3550          syscall by its number.  In this case, you would see something
3551          like:
3552
3553               (gdb) catch syscall 252
3554               Catchpoint 1 (syscall(s) 252)
3555
3556          Again, in this case GDB would not be able to display
3557          syscall's names.
3558
3559    `fork'
3560          A call to `fork'.  This is currently only available for HP-UX
3561          and GNU/Linux.
3562
3563    `vfork'
3564          A call to `vfork'.  This is currently only available for HP-UX
3565          and GNU/Linux.
3566
3567    `load [regexp]'
3568    `unload [regexp]'
3569          The loading or unloading of a shared library.  If REGEXP is
3570          given, then the catchpoint will stop only if the regular
3571          expression matches one of the affected libraries.
3572
3573    `signal [SIGNAL... | `all']'
3574          The delivery of a signal.
3575
3576          With no arguments, this catchpoint will catch any signal that
3577          is not used internally by GDB, specifically, all signals
3578          except `SIGTRAP' and `SIGINT'.
3579
3580          With the argument `all', all signals, including those used by
3581          GDB, will be caught.  This argument cannot be used with other
3582          signal names.
3583
3584          Otherwise, the arguments are a list of signal names as given
3585          to `handle' (*note Signals::).  Only signals specified in
3586          this list will be caught.
3587
3588          One reason that `catch signal' can be more useful than
3589          `handle' is that you can attach commands and conditions to the
3590          catchpoint.
3591
3592          When a signal is caught by a catchpoint, the signal's `stop'
3593          and `print' settings, as specified by `handle', are ignored.
3594          However, whether the signal is still delivered to the
3595          inferior depends on the `pass' setting; this can be changed
3596          in the catchpoint's commands.
3597
3598
3599`tcatch EVENT'
3600     Set a catchpoint that is enabled only for one stop.  The
3601     catchpoint is automatically deleted after the first time the event
3602     is caught.
3603
3604
3605   Use the `info break' command to list the current catchpoints.
3606
3607   There are currently some limitations to C++ exception handling
3608(`catch throw' and `catch catch') in GDB:
3609
3610   * If you call a function interactively, GDB normally returns control
3611     to you when the function has finished executing.  If the call
3612     raises an exception, however, the call may bypass the mechanism
3613     that returns control to you and cause your program either to abort
3614     or to simply continue running until it hits a breakpoint, catches
3615     a signal that GDB is listening for, or exits.  This is the case
3616     even if you set a catchpoint for the exception; catchpoints on
3617     exceptions are disabled within interactive calls.
3618
3619   * You cannot raise an exception interactively.
3620
3621   * You cannot install an exception handler interactively.
3622
3623   Sometimes `catch' is not the best way to debug exception handling:
3624if you need to know exactly where an exception is raised, it is better
3625to stop _before_ the exception handler is called, since that way you
3626can see the stack before any unwinding takes place.  If you set a
3627breakpoint in an exception handler instead, it may not be easy to find
3628out where the exception was raised.
3629
3630   To stop just before an exception handler is called, you need some
3631knowledge of the implementation.  In the case of GNU C++, exceptions are
3632raised by calling a library function named `__raise_exception' which
3633has the following ANSI C interface:
3634
3635         /* ADDR is where the exception identifier is stored.
3636            ID is the exception identifier.  */
3637         void __raise_exception (void **addr, void *id);
3638
3639To make the debugger catch all exceptions before any stack unwinding
3640takes place, set a breakpoint on `__raise_exception' (*note
3641Breakpoints; Watchpoints; and Exceptions: Breakpoints.).
3642
3643   With a conditional breakpoint (*note Break Conditions: Conditions.)
3644that depends on the value of ID, you can stop your program when a
3645specific exception is raised.  You can use multiple conditional
3646breakpoints to stop your program when any of a number of exceptions are
3647raised.
3648
3649
3650File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Set Catchpoints,  Up: Breakpoints
3651
36525.1.4 Deleting Breakpoints
3653--------------------------
3654
3655It is often necessary to eliminate a breakpoint, watchpoint, or
3656catchpoint once it has done its job and you no longer want your program
3657to stop there.  This is called "deleting" the breakpoint.  A breakpoint
3658that has been deleted no longer exists; it is forgotten.
3659
3660   With the `clear' command you can delete breakpoints according to
3661where they are in your program.  With the `delete' command you can
3662delete individual breakpoints, watchpoints, or catchpoints by specifying
3663their breakpoint numbers.
3664
3665   It is not necessary to delete a breakpoint to proceed past it.  GDB
3666automatically ignores breakpoints on the first instruction to be
3667executed when you continue execution without changing the execution
3668address.
3669
3670`clear'
3671     Delete any breakpoints at the next instruction to be executed in
3672     the selected stack frame (*note Selecting a Frame: Selection.).
3673     When the innermost frame is selected, this is a good way to delete
3674     a breakpoint where your program just stopped.
3675
3676`clear LOCATION'
3677     Delete any breakpoints set at the specified LOCATION.  *Note
3678     Specify Location::, for the various forms of LOCATION; the most
3679     useful ones are listed below:
3680
3681    `clear FUNCTION'
3682    `clear FILENAME:FUNCTION'
3683          Delete any breakpoints set at entry to the named FUNCTION.
3684
3685    `clear LINENUM'
3686    `clear FILENAME:LINENUM'
3687          Delete any breakpoints set at or within the code of the
3688          specified LINENUM of the specified FILENAME.
3689
3690`delete [breakpoints] [RANGE...]'
3691     Delete the breakpoints, watchpoints, or catchpoints of the
3692     breakpoint ranges specified as arguments.  If no argument is
3693     specified, delete all breakpoints (GDB asks confirmation, unless
3694     you have `set confirm off').  You can abbreviate this command as
3695     `d'.
3696
3697
3698File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
3699
37005.1.5 Disabling Breakpoints
3701---------------------------
3702
3703Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3704prefer to "disable" it.  This makes the breakpoint inoperative as if it
3705had been deleted, but remembers the information on the breakpoint so
3706that you can "enable" it again later.
3707
3708   You disable and enable breakpoints, watchpoints, and catchpoints with
3709the `enable' and `disable' commands, optionally specifying one or more
3710breakpoint numbers as arguments.  Use `info break' to print a list of
3711all breakpoints, watchpoints, and catchpoints if you do not know which
3712numbers to use.
3713
3714   Disabling and enabling a breakpoint that has multiple locations
3715affects all of its locations.
3716
3717   A breakpoint, watchpoint, or catchpoint can have any of several
3718different states of enablement:
3719
3720   * Enabled.  The breakpoint stops your program.  A breakpoint set
3721     with the `break' command starts out in this state.
3722
3723   * Disabled.  The breakpoint has no effect on your program.
3724
3725   * Enabled once.  The breakpoint stops your program, but then becomes
3726     disabled.
3727
3728   * Enabled for a count.  The breakpoint stops your program for the
3729     next N times, then becomes disabled.
3730
3731   * Enabled for deletion.  The breakpoint stops your program, but
3732     immediately after it does so it is deleted permanently.  A
3733     breakpoint set with the `tbreak' command starts out in this state.
3734
3735   You can use the following commands to enable or disable breakpoints,
3736watchpoints, and catchpoints:
3737
3738`disable [breakpoints] [RANGE...]'
3739     Disable the specified breakpoints--or all breakpoints, if none are
3740     listed.  A disabled breakpoint has no effect but is not forgotten.
3741     All options such as ignore-counts, conditions and commands are
3742     remembered in case the breakpoint is enabled again later.  You may
3743     abbreviate `disable' as `dis'.
3744
3745`enable [breakpoints] [RANGE...]'
3746     Enable the specified breakpoints (or all defined breakpoints).
3747     They become effective once again in stopping your program.
3748
3749`enable [breakpoints] once RANGE...'
3750     Enable the specified breakpoints temporarily.  GDB disables any of
3751     these breakpoints immediately after stopping your program.
3752
3753`enable [breakpoints] count COUNT RANGE...'
3754     Enable the specified breakpoints temporarily.  GDB records COUNT
3755     with each of the specified breakpoints, and decrements a
3756     breakpoint's count when it is hit.  When any count reaches 0, GDB
3757     disables that breakpoint.  If a breakpoint has an ignore count
3758     (*note Break Conditions: Conditions.), that will be decremented to
3759     0 before COUNT is affected.
3760
3761`enable [breakpoints] delete RANGE...'
3762     Enable the specified breakpoints to work once, then die.  GDB
3763     deletes any of these breakpoints as soon as your program stops
3764     there.  Breakpoints set by the `tbreak' command start out in this
3765     state.
3766
3767   Except for a breakpoint set with `tbreak' (*note Setting
3768Breakpoints: Set Breaks.), breakpoints that you set are initially
3769enabled; subsequently, they become disabled or enabled only when you
3770use one of the commands above.  (The command `until' can set and delete
3771a breakpoint of its own, but it does not change the state of your other
3772breakpoints; see *note Continuing and Stepping: Continuing and
3773Stepping.)
3774
3775
3776File: gdb.info,  Node: Conditions,  Next: Break Commands,  Prev: Disabling,  Up: Breakpoints
3777
37785.1.6 Break Conditions
3779----------------------
3780
3781The simplest sort of breakpoint breaks every time your program reaches a
3782specified place.  You can also specify a "condition" for a breakpoint.
3783A condition is just a Boolean expression in your programming language
3784(*note Expressions: Expressions.).  A breakpoint with a condition
3785evaluates the expression each time your program reaches it, and your
3786program stops only if the condition is _true_.
3787
3788   This is the converse of using assertions for program validation; in
3789that situation, you want to stop when the assertion is violated--that
3790is, when the condition is false.  In C, if you want to test an
3791assertion expressed by the condition ASSERT, you should set the
3792condition `! ASSERT' on the appropriate breakpoint.
3793
3794   Conditions are also accepted for watchpoints; you may not need them,
3795since a watchpoint is inspecting the value of an expression anyhow--but
3796it might be simpler, say, to just set a watchpoint on a variable name,
3797and specify a condition that tests whether the new value is an
3798interesting one.
3799
3800   Break conditions can have side effects, and may even call functions
3801in your program.  This can be useful, for example, to activate functions
3802that log program progress, or to use your own print functions to format
3803special data structures.  The effects are completely predictable unless
3804there is another enabled breakpoint at the same address.  (In that
3805case, GDB might see the other breakpoint first and stop your program
3806without checking the condition of this one.)  Note that breakpoint
3807commands are usually more convenient and flexible than break conditions
3808for the purpose of performing side effects when a breakpoint is reached
3809(*note Breakpoint Command Lists: Break Commands.).
3810
3811   Breakpoint conditions can also be evaluated on the target's side if
3812the target supports it.  Instead of evaluating the conditions locally,
3813GDB encodes the expression into an agent expression (*note Agent
3814Expressions::) suitable for execution on the target, independently of
3815GDB.  Global variables become raw memory locations, locals become stack
3816accesses, and so forth.
3817
3818   In this case, GDB will only be notified of a breakpoint trigger when
3819its condition evaluates to true.  This mechanism may provide faster
3820response times depending on the performance characteristics of the
3821target since it does not need to keep GDB informed about every
3822breakpoint trigger, even those with false conditions.
3823
3824   Break conditions can be specified when a breakpoint is set, by using
3825`if' in the arguments to the `break' command.  *Note Setting
3826Breakpoints: Set Breaks.  They can also be changed at any time with the
3827`condition' command.
3828
3829   You can also use the `if' keyword with the `watch' command.  The
3830`catch' command does not recognize the `if' keyword; `condition' is the
3831only way to impose a further condition on a catchpoint.
3832
3833`condition BNUM EXPRESSION'
3834     Specify EXPRESSION as the break condition for breakpoint,
3835     watchpoint, or catchpoint number BNUM.  After you set a condition,
3836     breakpoint BNUM stops your program only if the value of EXPRESSION
3837     is true (nonzero, in C).  When you use `condition', GDB checks
3838     EXPRESSION immediately for syntactic correctness, and to determine
3839     whether symbols in it have referents in the context of your
3840     breakpoint.  If EXPRESSION uses symbols not referenced in the
3841     context of the breakpoint, GDB prints an error message:
3842
3843          No symbol "foo" in current context.
3844
3845     GDB does not actually evaluate EXPRESSION at the time the
3846     `condition' command (or a command that sets a breakpoint with a
3847     condition, like `break if ...') is given, however.  *Note
3848     Expressions: Expressions.
3849
3850`condition BNUM'
3851     Remove the condition from breakpoint number BNUM.  It becomes an
3852     ordinary unconditional breakpoint.
3853
3854   A special case of a breakpoint condition is to stop only when the
3855breakpoint has been reached a certain number of times.  This is so
3856useful that there is a special way to do it, using the "ignore count"
3857of the breakpoint.  Every breakpoint has an ignore count, which is an
3858integer.  Most of the time, the ignore count is zero, and therefore has
3859no effect.  But if your program reaches a breakpoint whose ignore count
3860is positive, then instead of stopping, it just decrements the ignore
3861count by one and continues.  As a result, if the ignore count value is
3862N, the breakpoint does not stop the next N times your program reaches
3863it.
3864
3865`ignore BNUM COUNT'
3866     Set the ignore count of breakpoint number BNUM to COUNT.  The next
3867     COUNT times the breakpoint is reached, your program's execution
3868     does not stop; other than to decrement the ignore count, GDB takes
3869     no action.
3870
3871     To make the breakpoint stop the next time it is reached, specify a
3872     count of zero.
3873
3874     When you use `continue' to resume execution of your program from a
3875     breakpoint, you can specify an ignore count directly as an
3876     argument to `continue', rather than using `ignore'.  *Note
3877     Continuing and Stepping: Continuing and Stepping.
3878
3879     If a breakpoint has a positive ignore count and a condition, the
3880     condition is not checked.  Once the ignore count reaches zero, GDB
3881     resumes checking the condition.
3882
3883     You could achieve the effect of the ignore count with a condition
3884     such as `$foo-- <= 0' using a debugger convenience variable that
3885     is decremented each time.  *Note Convenience Variables:
3886     Convenience Vars.
3887
3888   Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3889
3890
3891File: gdb.info,  Node: Break Commands,  Next: Dynamic Printf,  Prev: Conditions,  Up: Breakpoints
3892
38935.1.7 Breakpoint Command Lists
3894------------------------------
3895
3896You can give any breakpoint (or watchpoint or catchpoint) a series of
3897commands to execute when your program stops due to that breakpoint.  For
3898example, you might want to print the values of certain expressions, or
3899enable other breakpoints.
3900
3901`commands [RANGE...]'
3902`... COMMAND-LIST ...'
3903`end'
3904     Specify a list of commands for the given breakpoints.  The commands
3905     themselves appear on the following lines.  Type a line containing
3906     just `end' to terminate the commands.
3907
3908     To remove all commands from a breakpoint, type `commands' and
3909     follow it immediately with `end'; that is, give no commands.
3910
3911     With no argument, `commands' refers to the last breakpoint,
3912     watchpoint, or catchpoint set (not to the breakpoint most recently
3913     encountered).  If the most recent breakpoints were set with a
3914     single command, then the `commands' will apply to all the
3915     breakpoints set by that command.  This applies to breakpoints set
3916     by `rbreak', and also applies when a single `break' command
3917     creates multiple breakpoints (*note Ambiguous Expressions:
3918     Ambiguous Expressions.).
3919
3920   Pressing <RET> as a means of repeating the last GDB command is
3921disabled within a COMMAND-LIST.
3922
3923   You can use breakpoint commands to start your program up again.
3924Simply use the `continue' command, or `step', or any other command that
3925resumes execution.
3926
3927   Any other commands in the command list, after a command that resumes
3928execution, are ignored.  This is because any time you resume execution
3929(even with a simple `next' or `step'), you may encounter another
3930breakpoint--which could have its own command list, leading to
3931ambiguities about which list to execute.
3932
3933   If the first command you specify in a command list is `silent', the
3934usual message about stopping at a breakpoint is not printed.  This may
3935be desirable for breakpoints that are to print a specific message and
3936then continue.  If none of the remaining commands print anything, you
3937see no sign that the breakpoint was reached.  `silent' is meaningful
3938only at the beginning of a breakpoint command list.
3939
3940   The commands `echo', `output', and `printf' allow you to print
3941precisely controlled output, and are often useful in silent
3942breakpoints.  *Note Commands for Controlled Output: Output.
3943
3944   For example, here is how you could use breakpoint commands to print
3945the value of `x' at entry to `foo' whenever `x' is positive.
3946
3947     break foo if x>0
3948     commands
3949     silent
3950     printf "x is %d\n",x
3951     cont
3952     end
3953
3954   One application for breakpoint commands is to compensate for one bug
3955so you can test for another.  Put a breakpoint just after the erroneous
3956line of code, give it a condition to detect the case in which something
3957erroneous has been done, and give it commands to assign correct values
3958to any variables that need them.  End with the `continue' command so
3959that your program does not stop, and start with the `silent' command so
3960that no output is produced.  Here is an example:
3961
3962     break 403
3963     commands
3964     silent
3965     set x = y + 4
3966     cont
3967     end
3968
3969
3970File: gdb.info,  Node: Dynamic Printf,  Next: Save Breakpoints,  Prev: Break Commands,  Up: Breakpoints
3971
39725.1.8 Dynamic Printf
3973--------------------
3974
3975The dynamic printf command `dprintf' combines a breakpoint with
3976formatted printing of your program's data to give you the effect of
3977inserting `printf' calls into your program on-the-fly, without having
3978to recompile it.
3979
3980   In its most basic form, the output goes to the GDB console.  However,
3981you can set the variable `dprintf-style' for alternate handling.  For
3982instance, you can ask to format the output by calling your program's
3983`printf' function.  This has the advantage that the characters go to
3984the program's output device, so they can recorded in redirects to files
3985and so forth.
3986
3987   If you are doing remote debugging with a stub or agent, you can also
3988ask to have the printf handled by the remote agent.  In addition to
3989ensuring that the output goes to the remote program's device along with
3990any other output the program might produce, you can also ask that the
3991dprintf remain active even after disconnecting from the remote target.
3992Using the stub/agent is also more efficient, as it can do everything
3993without needing to communicate with GDB.
3994
3995`dprintf LOCATION,TEMPLATE,EXPRESSION[,EXPRESSION...]'
3996     Whenever execution reaches LOCATION, print the values of one or
3997     more EXPRESSIONS under the control of the string TEMPLATE.  To
3998     print several values, separate them with commas.
3999
4000`set dprintf-style STYLE'
4001     Set the dprintf output to be handled in one of several different
4002     styles enumerated below.  A change of style affects all existing
4003     dynamic printfs immediately.  (If you need individual control over
4004     the print commands, simply define normal breakpoints with
4005     explicitly-supplied command lists.)
4006
4007`gdb'
4008     Handle the output using the GDB `printf' command.
4009
4010`call'
4011     Handle the output by calling a function in your program (normally
4012     `printf').
4013
4014`agent'
4015     Have the remote debugging agent (such as `gdbserver') handle the
4016     output itself.  This style is only available for agents that
4017     support running commands on the target.
4018
4019`set dprintf-function FUNCTION'
4020     Set the function to call if the dprintf style is `call'.  By
4021     default its value is `printf'.  You may set it to any expression.
4022     that GDB can evaluate to a function, as per the `call' command.
4023
4024`set dprintf-channel CHANNEL'
4025     Set a "channel" for dprintf.  If set to a non-empty value, GDB
4026     will evaluate it as an expression and pass the result as a first
4027     argument to the `dprintf-function', in the manner of `fprintf' and
4028     similar functions.  Otherwise, the dprintf format string will be
4029     the first argument, in the manner of `printf'.
4030
4031     As an example, if you wanted `dprintf' output to go to a logfile
4032     that is a standard I/O stream assigned to the variable `mylog',
4033     you could do the following:
4034
4035          (gdb) set dprintf-style call
4036          (gdb) set dprintf-function fprintf
4037          (gdb) set dprintf-channel mylog
4038          (gdb) dprintf 25,"at line 25, glob=%d\n",glob
4039          Dprintf 1 at 0x123456: file main.c, line 25.
4040          (gdb) info break
4041          1       dprintf        keep y   0x00123456 in main at main.c:25
4042                  call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4043                  continue
4044          (gdb)
4045
4046     Note that the `info break' displays the dynamic printf commands as
4047     normal breakpoint commands; you can thus easily see the effect of
4048     the variable settings.
4049
4050`set disconnected-dprintf on'
4051`set disconnected-dprintf off'
4052     Choose whether `dprintf' commands should continue to run if GDB
4053     has disconnected from the target.  This only applies if the
4054     `dprintf-style' is `agent'.
4055
4056`show disconnected-dprintf off'
4057     Show the current choice for disconnected `dprintf'.
4058
4059
4060   GDB does not check the validity of function and channel, relying on
4061you to supply values that are meaningful for the contexts in which they
4062are being used.  For instance, the function and channel may be the
4063values of local variables, but if that is the case, then all enabled
4064dynamic prints must be at locations within the scope of those locals.
4065If evaluation fails, GDB will report an error.
4066
4067
4068File: gdb.info,  Node: Save Breakpoints,  Next: Static Probe Points,  Prev: Dynamic Printf,  Up: Breakpoints
4069
40705.1.9 How to save breakpoints to a file
4071---------------------------------------
4072
4073To save breakpoint definitions to a file use the `save breakpoints'
4074command.
4075
4076`save breakpoints [FILENAME]'
4077     This command saves all current breakpoint definitions together with
4078     their commands and ignore counts, into a file `FILENAME' suitable
4079     for use in a later debugging session.  This includes all types of
4080     breakpoints (breakpoints, watchpoints, catchpoints, tracepoints).
4081     To read the saved breakpoint definitions, use the `source' command
4082     (*note Command Files::).  Note that watchpoints with expressions
4083     involving local variables may fail to be recreated because it may
4084     not be possible to access the context where the watchpoint is
4085     valid anymore.  Because the saved breakpoint definitions are
4086     simply a sequence of GDB commands that recreate the breakpoints,
4087     you can edit the file in your favorite editing program, and remove
4088     the breakpoint definitions you're not interested in, or that can
4089     no longer be recreated.
4090
4091
4092File: gdb.info,  Node: Static Probe Points,  Next: Error in Breakpoints,  Prev: Save Breakpoints,  Up: Breakpoints
4093
40945.1.10 Static Probe Points
4095--------------------------
4096
4097GDB supports "SDT" probes in the code.  SDT stands for Statically
4098Defined Tracing, and the probes are designed to have a tiny runtime
4099code and data footprint, and no dynamic relocations.  They are usable
4100from assembly, C and C++ languages.  See
4101`http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation' for
4102a good reference on how the SDT probes are implemented.
4103
4104   Currently, `SystemTap' (`http://sourceware.org/systemtap/') SDT
4105probes are supported on ELF-compatible systems.  See
4106`http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps' for
4107more information on how to add `SystemTap' SDT probes in your
4108applications.
4109
4110   Some probes have an associated semaphore variable; for instance, this
4111happens automatically if you defined your probe using a DTrace-style
4112`.d' file.  If your probe has a semaphore, GDB will automatically
4113enable it when you specify a breakpoint using the `-probe-stap'
4114notation.  But, if you put a breakpoint at a probe's location by some
4115other method (e.g., `break file:line'), then GDB will not automatically
4116set the semaphore.
4117
4118   You can examine the available static static probes using `info
4119probes', with optional arguments:
4120
4121`info probes stap [PROVIDER [NAME [OBJFILE]]]'
4122     If given, PROVIDER is a regular expression used to match against
4123     provider names when selecting which probes to list.  If omitted,
4124     probes by all probes from all providers are listed.
4125
4126     If given, NAME is a regular expression to match against probe names
4127     when selecting which probes to list.  If omitted, probe names are
4128     not considered when deciding whether to display them.
4129
4130     If given, OBJFILE is a regular expression used to select which
4131     object files (executable or shared libraries) to examine.  If not
4132     given, all object files are considered.
4133
4134`info probes all'
4135     List the available static probes, from all types.
4136
4137   A probe may specify up to twelve arguments.  These are available at
4138the point at which the probe is defined--that is, when the current PC is
4139at the probe's location.  The arguments are available using the
4140convenience variables (*note Convenience Vars::)
4141`$_probe_arg0'...`$_probe_arg11'.  Each probe argument is an integer of
4142the appropriate size; types are not preserved.  The convenience
4143variable `$_probe_argc' holds the number of arguments at the current
4144probe point.
4145
4146   These variables are always available, but attempts to access them at
4147any location other than a probe point will cause GDB to give an error
4148message.
4149
4150
4151File: gdb.info,  Node: Error in Breakpoints,  Next: Breakpoint-related Warnings,  Prev: Static Probe Points,  Up: Breakpoints
4152
41535.1.11 "Cannot insert breakpoints"
4154----------------------------------
4155
4156If you request too many active hardware-assisted breakpoints and
4157watchpoints, you will see this error message:
4158
4159     Stopped; cannot insert breakpoints.
4160     You may have requested too many hardware breakpoints and watchpoints.
4161
4162This message is printed when you attempt to resume the program, since
4163only then GDB knows exactly how many hardware breakpoints and
4164watchpoints it needs to insert.
4165
4166   When this message is printed, you need to disable or remove some of
4167the hardware-assisted breakpoints and watchpoints, and then continue.
4168
4169
4170File: gdb.info,  Node: Breakpoint-related Warnings,  Prev: Error in Breakpoints,  Up: Breakpoints
4171
41725.1.12 "Breakpoint address adjusted..."
4173---------------------------------------
4174
4175Some processor architectures place constraints on the addresses at
4176which breakpoints may be placed.  For architectures thus constrained,
4177GDB will attempt to adjust the breakpoint's address to comply with the
4178constraints dictated by the architecture.
4179
4180   One example of such an architecture is the Fujitsu FR-V.  The FR-V is
4181a VLIW architecture in which a number of RISC-like instructions may be
4182bundled together for parallel execution.  The FR-V architecture
4183constrains the location of a breakpoint instruction within such a
4184bundle to the instruction with the lowest address.  GDB honors this
4185constraint by adjusting a breakpoint's address to the first in the
4186bundle.
4187
4188   It is not uncommon for optimized code to have bundles which contain
4189instructions from different source statements, thus it may happen that
4190a breakpoint's address will be adjusted from one source statement to
4191another.  Since this adjustment may significantly alter GDB's
4192breakpoint related behavior from what the user expects, a warning is
4193printed when the breakpoint is first set and also when the breakpoint
4194is hit.
4195
4196   A warning like the one below is printed when setting a breakpoint
4197that's been subject to address adjustment:
4198
4199     warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4200
4201   Such warnings are printed both for user settable and GDB's internal
4202breakpoints.  If you see one of these warnings, you should verify that
4203a breakpoint set at the adjusted address will have the desired affect.
4204If not, the breakpoint in question may be removed and other breakpoints
4205may be set which will have the desired behavior.  E.g., it may be
4206sufficient to place the breakpoint at a later instruction.  A
4207conditional breakpoint may also be useful in some cases to prevent the
4208breakpoint from triggering too often.
4209
4210   GDB will also issue a warning when stopping at one of these adjusted
4211breakpoints:
4212
4213     warning: Breakpoint 1 address previously adjusted from 0x00010414
4214     to 0x00010410.
4215
4216   When this warning is encountered, it may be too late to take remedial
4217action except in cases where the breakpoint is hit earlier or more
4218frequently than expected.
4219
4220
4221File: gdb.info,  Node: Continuing and Stepping,  Next: Skipping Over Functions and Files,  Prev: Breakpoints,  Up: Stopping
4222
42235.2 Continuing and Stepping
4224===========================
4225
4226"Continuing" means resuming program execution until your program
4227completes normally.  In contrast, "stepping" means executing just one
4228more "step" of your program, where "step" may mean either one line of
4229source code, or one machine instruction (depending on what particular
4230command you use).  Either when continuing or when stepping, your
4231program may stop even sooner, due to a breakpoint or a signal.  (If it
4232stops due to a signal, you may want to use `handle', or use `signal 0'
4233to resume execution.  *Note Signals: Signals.)
4234
4235`continue [IGNORE-COUNT]'
4236`c [IGNORE-COUNT]'
4237`fg [IGNORE-COUNT]'
4238     Resume program execution, at the address where your program last
4239     stopped; any breakpoints set at that address are bypassed.  The
4240     optional argument IGNORE-COUNT allows you to specify a further
4241     number of times to ignore a breakpoint at this location; its
4242     effect is like that of `ignore' (*note Break Conditions:
4243     Conditions.).
4244
4245     The argument IGNORE-COUNT is meaningful only when your program
4246     stopped due to a breakpoint.  At other times, the argument to
4247     `continue' is ignored.
4248
4249     The synonyms `c' and `fg' (for "foreground", as the debugged
4250     program is deemed to be the foreground program) are provided
4251     purely for convenience, and have exactly the same behavior as
4252     `continue'.
4253
4254   To resume execution at a different place, you can use `return'
4255(*note Returning from a Function: Returning.) to go back to the calling
4256function; or `jump' (*note Continuing at a Different Address: Jumping.)
4257to go to an arbitrary location in your program.
4258
4259   A typical technique for using stepping is to set a breakpoint (*note
4260Breakpoints; Watchpoints; and Catchpoints: Breakpoints.) at the
4261beginning of the function or the section of your program where a problem
4262is believed to lie, run your program until it stops at that breakpoint,
4263and then step through the suspect area, examining the variables that are
4264interesting, until you see the problem happen.
4265
4266`step'
4267     Continue running your program until control reaches a different
4268     source line, then stop it and return control to GDB.  This command
4269     is abbreviated `s'.
4270
4271          _Warning:_ If you use the `step' command while control is
4272          within a function that was compiled without debugging
4273          information, execution proceeds until control reaches a
4274          function that does have debugging information.  Likewise, it
4275          will not step into a function which is compiled without
4276          debugging information.  To step through functions without
4277          debugging information, use the `stepi' command, described
4278          below.
4279
4280     The `step' command only stops at the first instruction of a source
4281     line.  This prevents the multiple stops that could otherwise occur
4282     in `switch' statements, `for' loops, etc.  `step' continues to
4283     stop if a function that has debugging information is called within
4284     the line.  In other words, `step' _steps inside_ any functions
4285     called within the line.
4286
4287     Also, the `step' command only enters a function if there is line
4288     number information for the function.  Otherwise it acts like the
4289     `next' command.  This avoids problems when using `cc -gl' on MIPS
4290     machines.  Previously, `step' entered subroutines if there was any
4291     debugging information about the routine.
4292
4293`step COUNT'
4294     Continue running as in `step', but do so COUNT times.  If a
4295     breakpoint is reached, or a signal not related to stepping occurs
4296     before COUNT steps, stepping stops right away.
4297
4298`next [COUNT]'
4299     Continue to the next source line in the current (innermost) stack
4300     frame.  This is similar to `step', but function calls that appear
4301     within the line of code are executed without stopping.  Execution
4302     stops when control reaches a different line of code at the
4303     original stack level that was executing when you gave the `next'
4304     command.  This command is abbreviated `n'.
4305
4306     An argument COUNT is a repeat count, as for `step'.
4307
4308     The `next' command only stops at the first instruction of a source
4309     line.  This prevents multiple stops that could otherwise occur in
4310     `switch' statements, `for' loops, etc.
4311
4312`set step-mode'
4313`set step-mode on'
4314     The `set step-mode on' command causes the `step' command to stop
4315     at the first instruction of a function which contains no debug line
4316     information rather than stepping over it.
4317
4318     This is useful in cases where you may be interested in inspecting
4319     the machine instructions of a function which has no symbolic info
4320     and do not want GDB to automatically skip over this function.
4321
4322`set step-mode off'
4323     Causes the `step' command to step over any functions which
4324     contains no debug information.  This is the default.
4325
4326`show step-mode'
4327     Show whether GDB will stop in or step over functions without
4328     source line debug information.
4329
4330`finish'
4331     Continue running until just after function in the selected stack
4332     frame returns.  Print the returned value (if any).  This command
4333     can be abbreviated as `fin'.
4334
4335     Contrast this with the `return' command (*note Returning from a
4336     Function: Returning.).
4337
4338`until'
4339`u'
4340     Continue running until a source line past the current line, in the
4341     current stack frame, is reached.  This command is used to avoid
4342     single stepping through a loop more than once.  It is like the
4343     `next' command, except that when `until' encounters a jump, it
4344     automatically continues execution until the program counter is
4345     greater than the address of the jump.
4346
4347     This means that when you reach the end of a loop after single
4348     stepping though it, `until' makes your program continue execution
4349     until it exits the loop.  In contrast, a `next' command at the end
4350     of a loop simply steps back to the beginning of the loop, which
4351     forces you to step through the next iteration.
4352
4353     `until' always stops your program if it attempts to exit the
4354     current stack frame.
4355
4356     `until' may produce somewhat counterintuitive results if the order
4357     of machine code does not match the order of the source lines.  For
4358     example, in the following excerpt from a debugging session, the `f'
4359     (`frame') command shows that execution is stopped at line `206';
4360     yet when we use `until', we get to line `195':
4361
4362          (gdb) f
4363          #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
4364          206                 expand_input();
4365          (gdb) until
4366          195             for ( ; argc > 0; NEXTARG) {
4367
4368     This happened because, for execution efficiency, the compiler had
4369     generated code for the loop closure test at the end, rather than
4370     the start, of the loop--even though the test in a C `for'-loop is
4371     written before the body of the loop.  The `until' command appeared
4372     to step back to the beginning of the loop when it advanced to this
4373     expression; however, it has not really gone to an earlier
4374     statement--not in terms of the actual machine code.
4375
4376     `until' with no argument works by means of single instruction
4377     stepping, and hence is slower than `until' with an argument.
4378
4379`until LOCATION'
4380`u LOCATION'
4381     Continue running your program until either the specified location
4382     is reached, or the current stack frame returns.  LOCATION is any of
4383     the forms described in *note Specify Location::.  This form of the
4384     command uses temporary breakpoints, and hence is quicker than
4385     `until' without an argument.  The specified location is actually
4386     reached only if it is in the current frame.  This implies that
4387     `until' can be used to skip over recursive function invocations.
4388     For instance in the code below, if the current location is line
4389     `96', issuing `until 99' will execute the program up to line `99'
4390     in the same invocation of factorial, i.e., after the inner
4391     invocations have returned.
4392
4393          94	int factorial (int value)
4394          95	{
4395          96	    if (value > 1) {
4396          97            value *= factorial (value - 1);
4397          98	    }
4398          99	    return (value);
4399          100     }
4400
4401`advance LOCATION'
4402     Continue running the program up to the given LOCATION.  An
4403     argument is required, which should be of one of the forms
4404     described in *note Specify Location::.  Execution will also stop
4405     upon exit from the current stack frame.  This command is similar
4406     to `until', but `advance' will not skip over recursive function
4407     calls, and the target location doesn't have to be in the same
4408     frame as the current one.
4409
4410`stepi'
4411`stepi ARG'
4412`si'
4413     Execute one machine instruction, then stop and return to the
4414     debugger.
4415
4416     It is often useful to do `display/i $pc' when stepping by machine
4417     instructions.  This makes GDB automatically display the next
4418     instruction to be executed, each time your program stops.  *Note
4419     Automatic Display: Auto Display.
4420
4421     An argument is a repeat count, as in `step'.
4422
4423`nexti'
4424`nexti ARG'
4425`ni'
4426     Execute one machine instruction, but if it is a function call,
4427     proceed until the function returns.
4428
4429     An argument is a repeat count, as in `next'.
4430
4431
4432File: gdb.info,  Node: Skipping Over Functions and Files,  Next: Signals,  Prev: Continuing and Stepping,  Up: Stopping
4433
44345.3 Skipping Over Functions and Files
4435=====================================
4436
4437The program you are debugging may contain some functions which are
4438uninteresting to debug.  The `skip' comand lets you tell GDB to skip a
4439function or all functions in a file when stepping.
4440
4441   For example, consider the following C function:
4442
4443     101     int func()
4444     102     {
4445     103         foo(boring());
4446     104         bar(boring());
4447     105     }
4448
4449Suppose you wish to step into the functions `foo' and `bar', but you
4450are not interested in stepping through `boring'.  If you run `step' at
4451line 103, you'll enter `boring()', but if you run `next', you'll step
4452over both `foo' and `boring'!
4453
4454   One solution is to `step' into `boring' and use the `finish' command
4455to immediately exit it.  But this can become tedious if `boring' is
4456called from many places.
4457
4458   A more flexible solution is to execute `skip boring'.  This instructs
4459GDB never to step into `boring'.  Now when you execute `step' at line
4460103, you'll step over `boring' and directly into `foo'.
4461
4462   You can also instruct GDB to skip all functions in a file, with, for
4463example, `skip file boring.c'.
4464
4465`skip [LINESPEC]'
4466`skip function [LINESPEC]'
4467     After running this command, the function named by LINESPEC or the
4468     function containing the line named by LINESPEC will be skipped
4469     over when stepping.  *Note Specify Location::.
4470
4471     If you do not specify LINESPEC, the function you're currently
4472     debugging will be skipped.
4473
4474     (If you have a function called `file' that you want to skip, use
4475     `skip function file'.)
4476
4477`skip file [FILENAME]'
4478     After running this command, any function whose source lives in
4479     FILENAME will be skipped over when stepping.
4480
4481     If you do not specify FILENAME, functions whose source lives in
4482     the file you're currently debugging will be skipped.
4483
4484   Skips can be listed, deleted, disabled, and enabled, much like
4485breakpoints.  These are the commands for managing your list of skips:
4486
4487`info skip [RANGE]'
4488     Print details about the specified skip(s).  If RANGE is not
4489     specified, print a table with details about all functions and
4490     files marked for skipping.  `info skip' prints the following
4491     information about each skip:
4492
4493    _Identifier_
4494          A number identifying this skip.
4495
4496    _Type_
4497          The type of this skip, either `function' or `file'.
4498
4499    _Enabled or Disabled_
4500          Enabled skips are marked with `y'.  Disabled skips are marked
4501          with `n'.
4502
4503    _Address_
4504          For function skips, this column indicates the address in
4505          memory of the function being skipped.  If you've set a
4506          function skip on a function which has not yet been loaded,
4507          this field will contain `<PENDING>'.  Once a shared library
4508          which has the function is loaded, `info skip' will show the
4509          function's address here.
4510
4511    _What_
4512          For file skips, this field contains the filename being
4513          skipped.  For functions skips, this field contains the
4514          function name and its line number in the file where it is
4515          defined.
4516
4517`skip delete [RANGE]'
4518     Delete the specified skip(s).  If RANGE is not specified, delete
4519     all skips.
4520
4521`skip enable [RANGE]'
4522     Enable the specified skip(s).  If RANGE is not specified, enable
4523     all skips.
4524
4525`skip disable [RANGE]'
4526     Disable the specified skip(s).  If RANGE is not specified, disable
4527     all skips.
4528
4529
4530
4531File: gdb.info,  Node: Signals,  Next: Thread Stops,  Prev: Skipping Over Functions and Files,  Up: Stopping
4532
45335.4 Signals
4534===========
4535
4536A signal is an asynchronous event that can happen in a program.  The
4537operating system defines the possible kinds of signals, and gives each
4538kind a name and a number.  For example, in Unix `SIGINT' is the signal
4539a program gets when you type an interrupt character (often `Ctrl-c');
4540`SIGSEGV' is the signal a program gets from referencing a place in
4541memory far away from all the areas in use; `SIGALRM' occurs when the
4542alarm clock timer goes off (which happens only if your program has
4543requested an alarm).
4544
4545   Some signals, including `SIGALRM', are a normal part of the
4546functioning of your program.  Others, such as `SIGSEGV', indicate
4547errors; these signals are "fatal" (they kill your program immediately)
4548if the program has not specified in advance some other way to handle
4549the signal.  `SIGINT' does not indicate an error in your program, but
4550it is normally fatal so it can carry out the purpose of the interrupt:
4551to kill the program.
4552
4553   GDB has the ability to detect any occurrence of a signal in your
4554program.  You can tell GDB in advance what to do for each kind of
4555signal.
4556
4557   Normally, GDB is set up to let the non-erroneous signals like
4558`SIGALRM' be silently passed to your program (so as not to interfere
4559with their role in the program's functioning) but to stop your program
4560immediately whenever an error signal happens.  You can change these
4561settings with the `handle' command.
4562
4563`info signals'
4564`info handle'
4565     Print a table of all the kinds of signals and how GDB has been
4566     told to handle each one.  You can use this to see the signal
4567     numbers of all the defined types of signals.
4568
4569`info signals SIG'
4570     Similar, but print information only about the specified signal
4571     number.
4572
4573     `info handle' is an alias for `info signals'.
4574
4575`catch signal [SIGNAL... | `all']'
4576     Set a catchpoint for the indicated signals.  *Note Set
4577     Catchpoints::, for details about this command.
4578
4579`handle SIGNAL [KEYWORDS...]'
4580     Change the way GDB handles signal SIGNAL.  SIGNAL can be the
4581     number of a signal or its name (with or without the `SIG' at the
4582     beginning); a list of signal numbers of the form `LOW-HIGH'; or
4583     the word `all', meaning all the known signals.  Optional arguments
4584     KEYWORDS, described below, say what change to make.
4585
4586   The keywords allowed by the `handle' command can be abbreviated.
4587Their full names are:
4588
4589`nostop'
4590     GDB should not stop your program when this signal happens.  It may
4591     still print a message telling you that the signal has come in.
4592
4593`stop'
4594     GDB should stop your program when this signal happens.  This
4595     implies the `print' keyword as well.
4596
4597`print'
4598     GDB should print a message when this signal happens.
4599
4600`noprint'
4601     GDB should not mention the occurrence of the signal at all.  This
4602     implies the `nostop' keyword as well.
4603
4604`pass'
4605`noignore'
4606     GDB should allow your program to see this signal; your program can
4607     handle the signal, or else it may terminate if the signal is fatal
4608     and not handled.  `pass' and `noignore' are synonyms.
4609
4610`nopass'
4611`ignore'
4612     GDB should not allow your program to see this signal.  `nopass'
4613     and `ignore' are synonyms.
4614
4615   When a signal stops your program, the signal is not visible to the
4616program until you continue.  Your program sees the signal then, if
4617`pass' is in effect for the signal in question _at that time_.  In
4618other words, after GDB reports a signal, you can use the `handle'
4619command with `pass' or `nopass' to control whether your program sees
4620that signal when you continue.
4621
4622   The default is set to `nostop', `noprint', `pass' for non-erroneous
4623signals such as `SIGALRM', `SIGWINCH' and `SIGCHLD', and to `stop',
4624`print', `pass' for the erroneous signals.
4625
4626   You can also use the `signal' command to prevent your program from
4627seeing a signal, or cause it to see a signal it normally would not see,
4628or to give it any signal at any time.  For example, if your program
4629stopped due to some sort of memory reference error, you might store
4630correct values into the erroneous variables and continue, hoping to see
4631more execution; but your program would probably terminate immediately as
4632a result of the fatal signal once it saw the signal.  To prevent this,
4633you can continue with `signal 0'.  *Note Giving your Program a Signal:
4634Signaling.
4635
4636   On some targets, GDB can inspect extra signal information associated
4637with the intercepted signal, before it is actually delivered to the
4638program being debugged.  This information is exported by the
4639convenience variable `$_siginfo', and consists of data that is passed
4640by the kernel to the signal handler at the time of the receipt of a
4641signal.  The data type of the information itself is target dependent.
4642You can see the data type using the `ptype $_siginfo' command.  On Unix
4643systems, it typically corresponds to the standard `siginfo_t' type, as
4644defined in the `signal.h' system header.
4645
4646   Here's an example, on a GNU/Linux system, printing the stray
4647referenced address that raised a segmentation fault.
4648
4649     (gdb) continue
4650     Program received signal SIGSEGV, Segmentation fault.
4651     0x0000000000400766 in main ()
4652     69        *(int *)p = 0;
4653     (gdb) ptype $_siginfo
4654     type = struct {
4655         int si_signo;
4656         int si_errno;
4657         int si_code;
4658         union {
4659             int _pad[28];
4660             struct {...} _kill;
4661             struct {...} _timer;
4662             struct {...} _rt;
4663             struct {...} _sigchld;
4664             struct {...} _sigfault;
4665             struct {...} _sigpoll;
4666         } _sifields;
4667     }
4668     (gdb) ptype $_siginfo._sifields._sigfault
4669     type = struct {
4670         void *si_addr;
4671     }
4672     (gdb) p $_siginfo._sifields._sigfault.si_addr
4673     $1 = (void *) 0x7ffff7ff7000
4674
4675   Depending on target support, `$_siginfo' may also be writable.
4676
4677
4678File: gdb.info,  Node: Thread Stops,  Prev: Signals,  Up: Stopping
4679
46805.5 Stopping and Starting Multi-thread Programs
4681===============================================
4682
4683GDB supports debugging programs with multiple threads (*note Debugging
4684Programs with Multiple Threads: Threads.).  There are two modes of
4685controlling execution of your program within the debugger.  In the
4686default mode, referred to as "all-stop mode", when any thread in your
4687program stops (for example, at a breakpoint or while being stepped),
4688all other threads in the program are also stopped by GDB.  On some
4689targets, GDB also supports "non-stop mode", in which other threads can
4690continue to run freely while you examine the stopped thread in the
4691debugger.
4692
4693* Menu:
4694
4695* All-Stop Mode::		All threads stop when GDB takes control
4696* Non-Stop Mode::		Other threads continue to execute
4697* Background Execution::	Running your program asynchronously
4698* Thread-Specific Breakpoints::	Controlling breakpoints
4699* Interrupted System Calls::	GDB may interfere with system calls
4700* Observer Mode::               GDB does not alter program behavior
4701
4702
4703File: gdb.info,  Node: All-Stop Mode,  Next: Non-Stop Mode,  Up: Thread Stops
4704
47055.5.1 All-Stop Mode
4706-------------------
4707
4708In all-stop mode, whenever your program stops under GDB for any reason,
4709_all_ threads of execution stop, not just the current thread.  This
4710allows you to examine the overall state of the program, including
4711switching between threads, without worrying that things may change
4712underfoot.
4713
4714   Conversely, whenever you restart the program, _all_ threads start
4715executing.  _This is true even when single-stepping_ with commands like
4716`step' or `next'.
4717
4718   In particular, GDB cannot single-step all threads in lockstep.
4719Since thread scheduling is up to your debugging target's operating
4720system (not controlled by GDB), other threads may execute more than one
4721statement while the current thread completes a single step.  Moreover,
4722in general other threads stop in the middle of a statement, rather than
4723at a clean statement boundary, when the program stops.
4724
4725   You might even find your program stopped in another thread after
4726continuing or even single-stepping.  This happens whenever some other
4727thread runs into a breakpoint, a signal, or an exception before the
4728first thread completes whatever you requested.
4729
4730   Whenever GDB stops your program, due to a breakpoint or a signal, it
4731automatically selects the thread where that breakpoint or signal
4732happened.  GDB alerts you to the context switch with a message such as
4733`[Switching to Thread N]' to identify the thread.
4734
4735   On some OSes, you can modify GDB's default behavior by locking the
4736OS scheduler to allow only a single thread to run.
4737
4738`set scheduler-locking MODE'
4739     Set the scheduler locking mode.  If it is `off', then there is no
4740     locking and any thread may run at any time.  If `on', then only the
4741     current thread may run when the inferior is resumed.  The `step'
4742     mode optimizes for single-stepping; it prevents other threads from
4743     preempting the current thread while you are stepping, so that the
4744     focus of debugging does not change unexpectedly.  Other threads
4745     only rarely (or never) get a chance to run when you step.  They
4746     are more likely to run when you `next' over a function call, and
4747     they are completely free to run when you use commands like
4748     `continue', `until', or `finish'.  However, unless another thread
4749     hits a breakpoint during its timeslice, GDB does not change the
4750     current thread away from the thread that you are debugging.
4751
4752`show scheduler-locking'
4753     Display the current scheduler locking mode.
4754
4755   By default, when you issue one of the execution commands such as
4756`continue', `next' or `step', GDB allows only threads of the current
4757inferior to run.  For example, if GDB is attached to two inferiors,
4758each with two threads, the `continue' command resumes only the two
4759threads of the current inferior.  This is useful, for example, when you
4760debug a program that forks and you want to hold the parent stopped (so
4761that, for instance, it doesn't run to exit), while you debug the child.
4762In other situations, you may not be interested in inspecting the
4763current state of any of the processes GDB is attached to, and you may
4764want to resume them all until some breakpoint is hit.  In the latter
4765case, you can instruct GDB to allow all threads of all the inferiors to
4766run with the `set schedule-multiple' command.
4767
4768`set schedule-multiple'
4769     Set the mode for allowing threads of multiple processes to be
4770     resumed when an execution command is issued.  When `on', all
4771     threads of all processes are allowed to run.  When `off', only the
4772     threads of the current process are resumed.  The default is `off'.
4773     The `scheduler-locking' mode takes precedence when set to `on', or
4774     while you are stepping and set to `step'.
4775
4776`show schedule-multiple'
4777     Display the current mode for resuming the execution of threads of
4778     multiple processes.
4779
4780
4781File: gdb.info,  Node: Non-Stop Mode,  Next: Background Execution,  Prev: All-Stop Mode,  Up: Thread Stops
4782
47835.5.2 Non-Stop Mode
4784-------------------
4785
4786For some multi-threaded targets, GDB supports an optional mode of
4787operation in which you can examine stopped program threads in the
4788debugger while other threads continue to execute freely.  This
4789minimizes intrusion when debugging live systems, such as programs where
4790some threads have real-time constraints or must continue to respond to
4791external events.  This is referred to as "non-stop" mode.
4792
4793   In non-stop mode, when a thread stops to report a debugging event,
4794_only_ that thread is stopped; GDB does not stop other threads as well,
4795in contrast to the all-stop mode behavior.  Additionally, execution
4796commands such as `continue' and `step' apply by default only to the
4797current thread in non-stop mode, rather than all threads as in all-stop
4798mode.  This allows you to control threads explicitly in ways that are
4799not possible in all-stop mode -- for example, stepping one thread while
4800allowing others to run freely, stepping one thread while holding all
4801others stopped, or stepping several threads independently and
4802simultaneously.
4803
4804   To enter non-stop mode, use this sequence of commands before you run
4805or attach to your program:
4806
4807     # Enable the async interface.
4808     set target-async 1
4809
4810     # If using the CLI, pagination breaks non-stop.
4811     set pagination off
4812
4813     # Finally, turn it on!
4814     set non-stop on
4815
4816   You can use these commands to manipulate the non-stop mode setting:
4817
4818`set non-stop on'
4819     Enable selection of non-stop mode.
4820
4821`set non-stop off'
4822     Disable selection of non-stop mode.
4823
4824`show non-stop'
4825     Show the current non-stop enablement setting.
4826
4827   Note these commands only reflect whether non-stop mode is enabled,
4828not whether the currently-executing program is being run in non-stop
4829mode.  In particular, the `set non-stop' preference is only consulted
4830when GDB starts or connects to the target program, and it is generally
4831not possible to switch modes once debugging has started.  Furthermore,
4832since not all targets support non-stop mode, even when you have enabled
4833non-stop mode, GDB may still fall back to all-stop operation by default.
4834
4835   In non-stop mode, all execution commands apply only to the current
4836thread by default.  That is, `continue' only continues one thread.  To
4837continue all threads, issue `continue -a' or `c -a'.
4838
4839   You can use GDB's background execution commands (*note Background
4840Execution::) to run some threads in the background while you continue
4841to examine or step others from GDB.  The MI execution commands (*note
4842GDB/MI Program Execution::) are always executed asynchronously in
4843non-stop mode.
4844
4845   Suspending execution is done with the `interrupt' command when
4846running in the background, or `Ctrl-c' during foreground execution.  In
4847all-stop mode, this stops the whole process; but in non-stop mode the
4848interrupt applies only to the current thread.  To stop the whole
4849program, use `interrupt -a'.
4850
4851   Other execution commands do not currently support the `-a' option.
4852
4853   In non-stop mode, when a thread stops, GDB doesn't automatically make
4854that thread current, as it does in all-stop mode.  This is because the
4855thread stop notifications are asynchronous with respect to GDB's
4856command interpreter, and it would be confusing if GDB unexpectedly
4857changed to a different thread just as you entered a command to operate
4858on the previously current thread.
4859
4860
4861File: gdb.info,  Node: Background Execution,  Next: Thread-Specific Breakpoints,  Prev: Non-Stop Mode,  Up: Thread Stops
4862
48635.5.3 Background Execution
4864--------------------------
4865
4866GDB's execution commands have two variants:  the normal foreground
4867(synchronous) behavior, and a background (asynchronous) behavior.  In
4868foreground execution, GDB waits for the program to report that some
4869thread has stopped before prompting for another command.  In background
4870execution, GDB immediately gives a command prompt so that you can issue
4871other commands while your program runs.
4872
4873   You need to explicitly enable asynchronous mode before you can use
4874background execution commands.  You can use these commands to
4875manipulate the asynchronous mode setting:
4876
4877`set target-async on'
4878     Enable asynchronous mode.
4879
4880`set target-async off'
4881     Disable asynchronous mode.
4882
4883`show target-async'
4884     Show the current target-async setting.
4885
4886   If the target doesn't support async mode, GDB issues an error
4887message if you attempt to use the background execution commands.
4888
4889   To specify background execution, add a `&' to the command.  For
4890example, the background form of the `continue' command is `continue&',
4891or just `c&'.  The execution commands that accept background execution
4892are:
4893
4894`run'
4895     *Note Starting your Program: Starting.
4896
4897`attach'
4898     *Note Debugging an Already-running Process: Attach.
4899
4900`step'
4901     *Note step: Continuing and Stepping.
4902
4903`stepi'
4904     *Note stepi: Continuing and Stepping.
4905
4906`next'
4907     *Note next: Continuing and Stepping.
4908
4909`nexti'
4910     *Note nexti: Continuing and Stepping.
4911
4912`continue'
4913     *Note continue: Continuing and Stepping.
4914
4915`finish'
4916     *Note finish: Continuing and Stepping.
4917
4918`until'
4919     *Note until: Continuing and Stepping.
4920
4921
4922   Background execution is especially useful in conjunction with
4923non-stop mode for debugging programs with multiple threads; see *note
4924Non-Stop Mode::.  However, you can also use these commands in the
4925normal all-stop mode with the restriction that you cannot issue another
4926execution command until the previous one finishes.  Examples of
4927commands that are valid in all-stop mode while the program is running
4928include `help' and `info break'.
4929
4930   You can interrupt your program while it is running in the background
4931by using the `interrupt' command.
4932
4933`interrupt'
4934`interrupt -a'
4935     Suspend execution of the running program.  In all-stop mode,
4936     `interrupt' stops the whole process, but in non-stop mode, it stops
4937     only the current thread.  To stop the whole program in non-stop
4938     mode, use `interrupt -a'.
4939
4940
4941File: gdb.info,  Node: Thread-Specific Breakpoints,  Next: Interrupted System Calls,  Prev: Background Execution,  Up: Thread Stops
4942
49435.5.4 Thread-Specific Breakpoints
4944---------------------------------
4945
4946When your program has multiple threads (*note Debugging Programs with
4947Multiple Threads: Threads.), you can choose whether to set breakpoints
4948on all threads, or on a particular thread.
4949
4950`break LINESPEC thread THREADNO'
4951`break LINESPEC thread THREADNO if ...'
4952     LINESPEC specifies source lines; there are several ways of writing
4953     them (*note Specify Location::), but the effect is always to
4954     specify some source line.
4955
4956     Use the qualifier `thread THREADNO' with a breakpoint command to
4957     specify that you only want GDB to stop the program when a
4958     particular thread reaches this breakpoint.  THREADNO is one of the
4959     numeric thread identifiers assigned by GDB, shown in the first
4960     column of the `info threads' display.
4961
4962     If you do not specify `thread THREADNO' when you set a breakpoint,
4963     the breakpoint applies to _all_ threads of your program.
4964
4965     You can use the `thread' qualifier on conditional breakpoints as
4966     well; in this case, place `thread THREADNO' before or after the
4967     breakpoint condition, like this:
4968
4969          (gdb) break frik.c:13 thread 28 if bartab > lim
4970
4971
4972
4973File: gdb.info,  Node: Interrupted System Calls,  Next: Observer Mode,  Prev: Thread-Specific Breakpoints,  Up: Thread Stops
4974
49755.5.5 Interrupted System Calls
4976------------------------------
4977
4978There is an unfortunate side effect when using GDB to debug
4979multi-threaded programs.  If one thread stops for a breakpoint, or for
4980some other reason, and another thread is blocked in a system call, then
4981the system call may return prematurely.  This is a consequence of the
4982interaction between multiple threads and the signals that GDB uses to
4983implement breakpoints and other events that stop execution.
4984
4985   To handle this problem, your program should check the return value of
4986each system call and react appropriately.  This is good programming
4987style anyways.
4988
4989   For example, do not write code like this:
4990
4991       sleep (10);
4992
4993   The call to `sleep' will return early if a different thread stops at
4994a breakpoint or for some other reason.
4995
4996   Instead, write this:
4997
4998       int unslept = 10;
4999       while (unslept > 0)
5000         unslept = sleep (unslept);
5001
5002   A system call is allowed to return early, so the system is still
5003conforming to its specification.  But GDB does cause your
5004multi-threaded program to behave differently than it would without GDB.
5005
5006   Also, GDB uses internal breakpoints in the thread library to monitor
5007certain events such as thread creation and thread destruction.  When
5008such an event happens, a system call in another thread may return
5009prematurely, even though your program does not appear to stop.
5010
5011
5012File: gdb.info,  Node: Observer Mode,  Prev: Interrupted System Calls,  Up: Thread Stops
5013
50145.5.6 Observer Mode
5015-------------------
5016
5017If you want to build on non-stop mode and observe program behavior
5018without any chance of disruption by GDB, you can set variables to
5019disable all of the debugger's attempts to modify state, whether by
5020writing memory, inserting breakpoints, etc.  These operate at a low
5021level, intercepting operations from all commands.
5022
5023   When all of these are set to `off', then GDB is said to be "observer
5024mode".  As a convenience, the variable `observer' can be set to disable
5025these, plus enable non-stop mode.
5026
5027   Note that GDB will not prevent you from making nonsensical
5028combinations of these settings. For instance, if you have enabled
5029`may-insert-breakpoints' but disabled `may-write-memory', then
5030breakpoints that work by writing trap instructions into the code stream
5031will still not be able to be placed.
5032
5033`set observer on'
5034`set observer off'
5035     When set to `on', this disables all the permission variables below
5036     (except for `insert-fast-tracepoints'), plus enables non-stop
5037     debugging.  Setting this to `off' switches back to normal
5038     debugging, though remaining in non-stop mode.
5039
5040`show observer'
5041     Show whether observer mode is on or off.
5042
5043`set may-write-registers on'
5044`set may-write-registers off'
5045     This controls whether GDB will attempt to alter the values of
5046     registers, such as with assignment expressions in `print', or the
5047     `jump' command.  It defaults to `on'.
5048
5049`show may-write-registers'
5050     Show the current permission to write registers.
5051
5052`set may-write-memory on'
5053`set may-write-memory off'
5054     This controls whether GDB will attempt to alter the contents of
5055     memory, such as with assignment expressions in `print'.  It
5056     defaults to `on'.
5057
5058`show may-write-memory'
5059     Show the current permission to write memory.
5060
5061`set may-insert-breakpoints on'
5062`set may-insert-breakpoints off'
5063     This controls whether GDB will attempt to insert breakpoints.
5064     This affects all breakpoints, including internal breakpoints
5065     defined by GDB.  It defaults to `on'.
5066
5067`show may-insert-breakpoints'
5068     Show the current permission to insert breakpoints.
5069
5070`set may-insert-tracepoints on'
5071`set may-insert-tracepoints off'
5072     This controls whether GDB will attempt to insert (regular)
5073     tracepoints at the beginning of a tracing experiment.  It affects
5074     only non-fast tracepoints, fast tracepoints being under the
5075     control of `may-insert-fast-tracepoints'.  It defaults to `on'.
5076
5077`show may-insert-tracepoints'
5078     Show the current permission to insert tracepoints.
5079
5080`set may-insert-fast-tracepoints on'
5081`set may-insert-fast-tracepoints off'
5082     This controls whether GDB will attempt to insert fast tracepoints
5083     at the beginning of a tracing experiment.  It affects only fast
5084     tracepoints, regular (non-fast) tracepoints being under the
5085     control of `may-insert-tracepoints'.  It defaults to `on'.
5086
5087`show may-insert-fast-tracepoints'
5088     Show the current permission to insert fast tracepoints.
5089
5090`set may-interrupt on'
5091`set may-interrupt off'
5092     This controls whether GDB will attempt to interrupt or stop
5093     program execution.  When this variable is `off', the `interrupt'
5094     command will have no effect, nor will `Ctrl-c'. It defaults to
5095     `on'.
5096
5097`show may-interrupt'
5098     Show the current permission to interrupt or stop the program.
5099
5100
5101
5102File: gdb.info,  Node: Reverse Execution,  Next: Process Record and Replay,  Prev: Stopping,  Up: Top
5103
51046 Running programs backward
5105***************************
5106
5107When you are debugging a program, it is not unusual to realize that you
5108have gone too far, and some event of interest has already happened.  If
5109the target environment supports it, GDB can allow you to "rewind" the
5110program by running it backward.
5111
5112   A target environment that supports reverse execution should be able
5113to "undo" the changes in machine state that have taken place as the
5114program was executing normally.  Variables, registers etc. should
5115revert to their previous values.  Obviously this requires a great deal
5116of sophistication on the part of the target environment; not all target
5117environments can support reverse execution.
5118
5119   When a program is executed in reverse, the instructions that have
5120most recently been executed are "un-executed", in reverse order.  The
5121program counter runs backward, following the previous thread of
5122execution in reverse.  As each instruction is "un-executed", the values
5123of memory and/or registers that were changed by that instruction are
5124reverted to their previous states.  After executing a piece of source
5125code in reverse, all side effects of that code should be "undone", and
5126all variables should be returned to their prior values(1).
5127
5128   If you are debugging in a target environment that supports reverse
5129execution, GDB provides the following commands.
5130
5131`reverse-continue [IGNORE-COUNT]'
5132`rc [IGNORE-COUNT]'
5133     Beginning at the point where your program last stopped, start
5134     executing in reverse.  Reverse execution will stop for breakpoints
5135     and synchronous exceptions (signals), just like normal execution.
5136     Behavior of asynchronous signals depends on the target environment.
5137
5138`reverse-step [COUNT]'
5139     Run the program backward until control reaches the start of a
5140     different source line; then stop it, and return control to GDB.
5141
5142     Like the `step' command, `reverse-step' will only stop at the
5143     beginning of a source line.  It "un-executes" the previously
5144     executed source line.  If the previous source line included calls
5145     to debuggable functions, `reverse-step' will step (backward) into
5146     the called function, stopping at the beginning of the _last_
5147     statement in the called function (typically a return statement).
5148
5149     Also, as with the `step' command, if non-debuggable functions are
5150     called, `reverse-step' will run thru them backward without
5151     stopping.
5152
5153`reverse-stepi [COUNT]'
5154     Reverse-execute one machine instruction.  Note that the instruction
5155     to be reverse-executed is _not_ the one pointed to by the program
5156     counter, but the instruction executed prior to that one.  For
5157     instance, if the last instruction was a jump, `reverse-stepi' will
5158     take you back from the destination of the jump to the jump
5159     instruction itself.
5160
5161`reverse-next [COUNT]'
5162     Run backward to the beginning of the previous line executed in the
5163     current (innermost) stack frame.  If the line contains function
5164     calls, they will be "un-executed" without stopping.  Starting from
5165     the first line of a function, `reverse-next' will take you back to
5166     the caller of that function, _before_ the function was called,
5167     just as the normal `next' command would take you from the last
5168     line of a function back to its return to its caller (2).
5169
5170`reverse-nexti [COUNT]'
5171     Like `nexti', `reverse-nexti' executes a single instruction in
5172     reverse, except that called functions are "un-executed" atomically.
5173     That is, if the previously executed instruction was a return from
5174     another function, `reverse-nexti' will continue to execute in
5175     reverse until the call to that function (from the current stack
5176     frame) is reached.
5177
5178`reverse-finish'
5179     Just as the `finish' command takes you to the point where the
5180     current function returns, `reverse-finish' takes you to the point
5181     where it was called.  Instead of ending up at the end of the
5182     current function invocation, you end up at the beginning.
5183
5184`set exec-direction'
5185     Set the direction of target execution.
5186
5187`set exec-direction reverse'
5188     GDB will perform all execution commands in reverse, until the
5189     exec-direction mode is changed to "forward".  Affected commands
5190     include `step, stepi, next, nexti, continue, and finish'.  The
5191     `return' command cannot be used in reverse mode.
5192
5193`set exec-direction forward'
5194     GDB will perform all execution commands in the normal fashion.
5195     This is the default.
5196
5197   ---------- Footnotes ----------
5198
5199   (1) Note that some side effects are easier to undo than others.  For
5200instance, memory and registers are relatively easy, but device I/O is
5201hard.  Some targets may be able undo things like device I/O, and some
5202may not.
5203
5204   The contract between GDB and the reverse executing target requires
5205only that the target do something reasonable when GDB tells it to
5206execute backwards, and then report the results back to GDB.  Whatever
5207the target reports back to GDB, GDB will report back to the user.  GDB
5208assumes that the memory and registers that the target reports are in a
5209consistant state, but GDB accepts whatever it is given.
5210
5211   (2) Unless the code is too heavily optimized.
5212
5213
5214File: gdb.info,  Node: Process Record and Replay,  Next: Stack,  Prev: Reverse Execution,  Up: Top
5215
52167 Recording Inferior's Execution and Replaying It
5217*************************************************
5218
5219On some platforms, GDB provides a special "process record and replay"
5220target that can record a log of the process execution, and replay it
5221later with both forward and reverse execution commands.
5222
5223   When this target is in use, if the execution log includes the record
5224for the next instruction, GDB will debug in "replay mode".  In the
5225replay mode, the inferior does not really execute code instructions.
5226Instead, all the events that normally happen during code execution are
5227taken from the execution log.  While code is not really executed in
5228replay mode, the values of registers (including the program counter
5229register) and the memory of the inferior are still changed as they
5230normally would.  Their contents are taken from the execution log.
5231
5232   If the record for the next instruction is not in the execution log,
5233GDB will debug in "record mode".  In this mode, the inferior executes
5234normally, and GDB records the execution log for future replay.
5235
5236   The process record and replay target supports reverse execution
5237(*note Reverse Execution::), even if the platform on which the inferior
5238runs does not.  However, the reverse execution is limited in this case
5239by the range of the instructions recorded in the execution log.  In
5240other words, reverse execution on platforms that don't support it
5241directly can only be done in the replay mode.
5242
5243   When debugging in the reverse direction, GDB will work in replay
5244mode as long as the execution log includes the record for the previous
5245instruction; otherwise, it will work in record mode, if the platform
5246supports reverse execution, or stop if not.
5247
5248   For architecture environments that support process record and replay,
5249GDB provides the following commands:
5250
5251`record METHOD'
5252     This command starts the process record and replay target.  The
5253     recording method can be specified as parameter.  Without a
5254     parameter the command uses the `full' recording method.  The
5255     following recording methods are available:
5256
5257    `full'
5258          Full record/replay recording using GDB's software record and
5259          replay implementation.  This method allows replaying and
5260          reverse execution.
5261
5262    `btrace'
5263          Hardware-supported instruction recording.  This method does
5264          not allow replaying and reverse execution.
5265
5266          This recording method may not be available on all processors.
5267
5268     The process record and replay target can only debug a process that
5269     is already running.  Therefore, you need first to start the
5270     process with the `run' or `start' commands, and then start the
5271     recording with the `record METHOD' command.
5272
5273     Both `record METHOD' and `rec METHOD' are aliases of `target
5274     record-METHOD'.
5275
5276     Displaced stepping (*note displaced stepping: Maintenance
5277     Commands.)  will be automatically disabled when process record and
5278     replay target is started.  That's because the process record and
5279     replay target doesn't support displaced stepping.
5280
5281     If the inferior is in the non-stop mode (*note Non-Stop Mode::) or
5282     in the asynchronous execution mode (*note Background Execution::),
5283     not all recording methods are available.  The `full' recording
5284     method does not support these two modes.
5285
5286`record stop'
5287     Stop the process record and replay target.  When process record and
5288     replay target stops, the entire execution log will be deleted and
5289     the inferior will either be terminated, or will remain in its
5290     final state.
5291
5292     When you stop the process record and replay target in record mode
5293     (at the end of the execution log), the inferior will be stopped at
5294     the next instruction that would have been recorded.  In other
5295     words, if you record for a while and then stop recording, the
5296     inferior process will be left in the same state as if the
5297     recording never happened.
5298
5299     On the other hand, if the process record and replay target is
5300     stopped while in replay mode (that is, not at the end of the
5301     execution log, but at some earlier point), the inferior process
5302     will become "live" at that earlier state, and it will then be
5303     possible to continue the usual "live" debugging of the process
5304     from that state.
5305
5306     When the inferior process exits, or GDB detaches from it, process
5307     record and replay target will automatically stop itself.
5308
5309`record save FILENAME'
5310     Save the execution log to a file `FILENAME'.  Default filename is
5311     `gdb_record.PROCESS_ID', where PROCESS_ID is the process ID of the
5312     inferior.
5313
5314     This command may not be available for all recording methods.
5315
5316`record restore FILENAME'
5317     Restore the execution log from a file `FILENAME'.  File must have
5318     been created with `record save'.
5319
5320`set record full insn-number-max LIMIT'
5321     Set the limit of instructions to be recorded for the `full'
5322     recording method.  Default value is 200000.
5323
5324     If LIMIT is a positive number, then GDB will start deleting
5325     instructions from the log once the number of the record
5326     instructions becomes greater than LIMIT.  For every new recorded
5327     instruction, GDB will delete the earliest recorded instruction to
5328     keep the number of recorded instructions at the limit.  (Since
5329     deleting recorded instructions loses information, GDB lets you
5330     control what happens when the limit is reached, by means of the
5331     `stop-at-limit' option, described below.)
5332
5333     If LIMIT is zero, GDB will never delete recorded instructions from
5334     the execution log.  The number of recorded instructions is
5335     unlimited in this case.
5336
5337`show record full insn-number-max'
5338     Show the limit of instructions to be recorded with the `full'
5339     recording method.
5340
5341`set record full stop-at-limit'
5342     Control the behavior of the  `full' recording method when the
5343     number of recorded instructions reaches the limit.  If ON (the
5344     default), GDB will stop when the limit is reached for the first
5345     time and ask you whether you want to stop the inferior or continue
5346     running it and recording the execution log.  If you decide to
5347     continue recording, each new recorded instruction will cause the
5348     oldest one to be deleted.
5349
5350     If this option is OFF, GDB will automatically delete the oldest
5351     record to make room for each new one, without asking.
5352
5353`show record full stop-at-limit'
5354     Show the current setting of `stop-at-limit'.
5355
5356`set record full memory-query'
5357     Control the behavior when GDB is unable to record memory changes
5358     caused by an instruction for the `full' recording method.  If ON,
5359     GDB will query whether to stop the inferior in that case.
5360
5361     If this option is OFF (the default), GDB will automatically ignore
5362     the effect of such instructions on memory.  Later, when GDB
5363     replays this execution log, it will mark the log of this
5364     instruction as not accessible, and it will not affect the replay
5365     results.
5366
5367`show record full memory-query'
5368     Show the current setting of `memory-query'.
5369
5370`info record'
5371     Show various statistics about the recording depending on the
5372     recording method:
5373
5374    `full'
5375          For the `full' recording method, it shows the state of process
5376          record and its in-memory execution log buffer, including:
5377
5378             * Whether in record mode or replay mode.
5379
5380             * Lowest recorded instruction number (counting from when
5381               the current execution log started recording
5382               instructions).
5383
5384             * Highest recorded instruction number.
5385
5386             * Current instruction about to be replayed (if in replay
5387               mode).
5388
5389             * Number of instructions contained in the execution log.
5390
5391             * Maximum number of instructions that may be contained in
5392               the execution log.
5393
5394    `btrace'
5395          For the `btrace' recording method, it shows the number of
5396          instructions that have been recorded and the number of blocks
5397          of sequential control-flow that is formed by the recorded
5398          instructions.
5399
5400`record delete'
5401     When record target runs in replay mode ("in the past"), delete the
5402     subsequent execution log and begin to record a new execution log
5403     starting from the current address.  This means you will abandon
5404     the previously recorded "future" and begin recording a new
5405     "future".
5406
5407`record instruction-history'
5408     Disassembles instructions from the recorded execution log.  By
5409     default, ten instructions are disassembled.  This can be changed
5410     using the `set record instruction-history-size' command.
5411     Instructions are printed in execution order.  There are several
5412     ways to specify what part of the execution log to disassemble:
5413
5414    `record instruction-history INSN'
5415          Disassembles ten instructions starting from instruction number
5416          INSN.
5417
5418    `record instruction-history INSN, +/-N'
5419          Disassembles N instructions around instruction number INSN.
5420          If N is preceded with `+', disassembles N instructions after
5421          instruction number INSN.  If N is preceded with `-',
5422          disassembles N instructions before instruction number INSN.
5423
5424    `record instruction-history'
5425          Disassembles ten more instructions after the last disassembly.
5426
5427    `record instruction-history -'
5428          Disassembles ten more instructions before the last
5429          disassembly.
5430
5431    `record instruction-history BEGIN END'
5432          Disassembles instructions beginning with instruction number
5433          BEGIN until instruction number END.  The instruction number
5434          END is not included.
5435
5436     This command may not be available for all recording methods.
5437
5438`set record instruction-history-size'
5439     Define how many instructions to disassemble in the `record
5440     instruction-history' command.  The default value is 10.
5441
5442`show record instruction-history-size'
5443     Show how many instructions to disassemble in the `record
5444     instruction-history' command.
5445
5446`record function-call-history'
5447     Prints the execution history at function granularity. It prints one
5448     line for each sequence of instructions that belong to the same
5449     function giving the name of that function, the source lines for
5450     this instruction sequence (if the `/l' modifier is specified), and
5451     the instructions numbers that form the sequence (if the `/i'
5452     modifier is specified).
5453
5454          (gdb) list 1, 10
5455          1   void foo (void)
5456          2   {
5457          3   }
5458          4
5459          5   void bar (void)
5460          6   {
5461          7     ...
5462          8     foo ();
5463          9     ...
5464          10  }
5465          (gdb) record function-call-history /l
5466          1  foo.c:6-8   bar
5467          2  foo.c:2-3   foo
5468          3  foo.c:9-10  bar
5469
5470     By default, ten lines are printed.  This can be changed using the
5471     `set record function-call-history-size' command.  Functions are
5472     printed in execution order.  There are several ways to specify what
5473     to print:
5474
5475    `record function-call-history FUNC'
5476          Prints ten functions starting from function number FUNC.
5477
5478    `record function-call-history FUNC, +/-N'
5479          Prints N functions around function number FUNC.  If N is
5480          preceded with `+', prints N functions after function number
5481          FUNC.  If N is preceded with `-', prints N functions before
5482          function number FUNC.
5483
5484    `record function-call-history'
5485          Prints ten more functions after the last ten-line print.
5486
5487    `record function-call-history -'
5488          Prints ten more functions before the last ten-line print.
5489
5490    `record function-call-history BEGIN END'
5491          Prints functions beginning with function number BEGIN until
5492          function number END.  The function number END is not included.
5493
5494     This command may not be available for all recording methods.
5495
5496`set record function-call-history-size'
5497     Define how many lines to print in the `record
5498     function-call-history' command.  The default value is 10.
5499
5500`show record function-call-history-size'
5501     Show how many lines to print in the `record function-call-history'
5502     command.
5503
5504
5505File: gdb.info,  Node: Stack,  Next: Source,  Prev: Process Record and Replay,  Up: Top
5506
55078 Examining the Stack
5508*********************
5509
5510When your program has stopped, the first thing you need to know is
5511where it stopped and how it got there.
5512
5513   Each time your program performs a function call, information about
5514the call is generated.  That information includes the location of the
5515call in your program, the arguments of the call, and the local
5516variables of the function being called.  The information is saved in a
5517block of data called a "stack frame".  The stack frames are allocated
5518in a region of memory called the "call stack".
5519
5520   When your program stops, the GDB commands for examining the stack
5521allow you to see all of this information.
5522
5523   One of the stack frames is "selected" by GDB and many GDB commands
5524refer implicitly to the selected frame.  In particular, whenever you
5525ask GDB for the value of a variable in your program, the value is found
5526in the selected frame.  There are special GDB commands to select
5527whichever frame you are interested in.  *Note Selecting a Frame:
5528Selection.
5529
5530   When your program stops, GDB automatically selects the currently
5531executing frame and describes it briefly, similar to the `frame'
5532command (*note Information about a Frame: Frame Info.).
5533
5534* Menu:
5535
5536* Frames::                      Stack frames
5537* Backtrace::                   Backtraces
5538* Selection::                   Selecting a frame
5539* Frame Info::                  Information on a frame
5540
5541
5542File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
5543
55448.1 Stack Frames
5545================
5546
5547The call stack is divided up into contiguous pieces called "stack
5548frames", or "frames" for short; each frame is the data associated with
5549one call to one function.  The frame contains the arguments given to
5550the function, the function's local variables, and the address at which
5551the function is executing.
5552
5553   When your program is started, the stack has only one frame, that of
5554the function `main'.  This is called the "initial" frame or the
5555"outermost" frame.  Each time a function is called, a new frame is
5556made.  Each time a function returns, the frame for that function
5557invocation is eliminated.  If a function is recursive, there can be
5558many frames for the same function.  The frame for the function in which
5559execution is actually occurring is called the "innermost" frame.  This
5560is the most recently created of all the stack frames that still exist.
5561
5562   Inside your program, stack frames are identified by their addresses.
5563A stack frame consists of many bytes, each of which has its own
5564address; each kind of computer has a convention for choosing one byte
5565whose address serves as the address of the frame.  Usually this address
5566is kept in a register called the "frame pointer register" (*note $fp:
5567Registers.) while execution is going on in that frame.
5568
5569   GDB assigns numbers to all existing stack frames, starting with zero
5570for the innermost frame, one for the frame that called it, and so on
5571upward.  These numbers do not really exist in your program; they are
5572assigned by GDB to give you a way of designating stack frames in GDB
5573commands.
5574
5575   Some compilers provide a way to compile functions so that they
5576operate without stack frames.  (For example, the GCC option
5577     `-fomit-frame-pointer'
5578   generates functions without a frame.)  This is occasionally done
5579with heavily used library functions to save the frame setup time.  GDB
5580has limited facilities for dealing with these function invocations.  If
5581the innermost function invocation has no stack frame, GDB nevertheless
5582regards it as though it had a separate frame, which is numbered zero as
5583usual, allowing correct tracing of the function call chain.  However,
5584GDB has no provision for frameless functions elsewhere in the stack.
5585
5586`frame ARGS'
5587     The `frame' command allows you to move from one stack frame to
5588     another, and to print the stack frame you select.  ARGS may be
5589     either the address of the frame or the stack frame number.
5590     Without an argument, `frame' prints the current stack frame.
5591
5592`select-frame'
5593     The `select-frame' command allows you to move from one stack frame
5594     to another without printing the frame.  This is the silent version
5595     of `frame'.
5596
5597
5598File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
5599
56008.2 Backtraces
5601==============
5602
5603A backtrace is a summary of how your program got where it is.  It shows
5604one line per frame, for many frames, starting with the currently
5605executing frame (frame zero), followed by its caller (frame one), and
5606on up the stack.
5607
5608`backtrace'
5609`bt'
5610     Print a backtrace of the entire stack: one line per frame for all
5611     frames in the stack.
5612
5613     You can stop the backtrace at any time by typing the system
5614     interrupt character, normally `Ctrl-c'.
5615
5616`backtrace N'
5617`bt N'
5618     Similar, but print only the innermost N frames.
5619
5620`backtrace -N'
5621`bt -N'
5622     Similar, but print only the outermost N frames.
5623
5624`backtrace full'
5625`bt full'
5626`bt full N'
5627`bt full -N'
5628     Print the values of the local variables also.  N specifies the
5629     number of frames to print, as described above.
5630
5631   The names `where' and `info stack' (abbreviated `info s') are
5632additional aliases for `backtrace'.
5633
5634   In a multi-threaded program, GDB by default shows the backtrace only
5635for the current thread.  To display the backtrace for several or all of
5636the threads, use the command `thread apply' (*note thread apply:
5637Threads.).  For example, if you type `thread apply all backtrace', GDB
5638will display the backtrace for all the threads; this is handy when you
5639debug a core dump of a multi-threaded program.
5640
5641   Each line in the backtrace shows the frame number and the function
5642name.  The program counter value is also shown--unless you use `set
5643print address off'.  The backtrace also shows the source file name and
5644line number, as well as the arguments to the function.  The program
5645counter value is omitted if it is at the beginning of the code for that
5646line number.
5647
5648   Here is an example of a backtrace.  It was made with the command `bt
56493', so it shows the innermost three frames.
5650
5651     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5652         at builtin.c:993
5653     #1  0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
5654     #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
5655         at macro.c:71
5656     (More stack frames follow...)
5657
5658The display for frame zero does not begin with a program counter value,
5659indicating that your program has stopped at the beginning of the code
5660for line `993' of `builtin.c'.
5661
5662The value of parameter `data' in frame 1 has been replaced by `...'.
5663By default, GDB prints the value of a parameter only if it is a scalar
5664(integer, pointer, enumeration, etc).  See command `set print
5665frame-arguments' in *note Print Settings:: for more details on how to
5666configure the way function parameter values are printed.
5667
5668   If your program was compiled with optimizations, some compilers will
5669optimize away arguments passed to functions if those arguments are
5670never used after the call.  Such optimizations generate code that
5671passes arguments through registers, but doesn't store those arguments
5672in the stack frame.  GDB has no way of displaying such arguments in
5673stack frames other than the innermost one.  Here's what such a
5674backtrace might look like:
5675
5676     #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5677         at builtin.c:993
5678     #1  0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
5679     #2  0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
5680         at macro.c:71
5681     (More stack frames follow...)
5682
5683The values of arguments that were not saved in their stack frames are
5684shown as `<optimized out>'.
5685
5686   If you need to display the values of such optimized-out arguments,
5687either deduce that from other variables whose values depend on the one
5688you are interested in, or recompile without optimizations.
5689
5690   Most programs have a standard user entry point--a place where system
5691libraries and startup code transition into user code.  For C this is
5692`main'(1).  When GDB finds the entry function in a backtrace it will
5693terminate the backtrace, to avoid tracing into highly system-specific
5694(and generally uninteresting) code.
5695
5696   If you need to examine the startup code, or limit the number of
5697levels in a backtrace, you can change this behavior:
5698
5699`set backtrace past-main'
5700`set backtrace past-main on'
5701     Backtraces will continue past the user entry point.
5702
5703`set backtrace past-main off'
5704     Backtraces will stop when they encounter the user entry point.
5705     This is the default.
5706
5707`show backtrace past-main'
5708     Display the current user entry point backtrace policy.
5709
5710`set backtrace past-entry'
5711`set backtrace past-entry on'
5712     Backtraces will continue past the internal entry point of an
5713     application.  This entry point is encoded by the linker when the
5714     application is built, and is likely before the user entry point
5715     `main' (or equivalent) is called.
5716
5717`set backtrace past-entry off'
5718     Backtraces will stop when they encounter the internal entry point
5719     of an application.  This is the default.
5720
5721`show backtrace past-entry'
5722     Display the current internal entry point backtrace policy.
5723
5724`set backtrace limit N'
5725`set backtrace limit 0'
5726     Limit the backtrace to N levels.  A value of zero means unlimited.
5727
5728`show backtrace limit'
5729     Display the current limit on backtrace levels.
5730
5731   You can control how file names are displayed.
5732
5733`set filename-display'
5734`set filename-display relative'
5735     Display file names relative to the compilation directory.  This is
5736     the default.
5737
5738`set filename-display basename'
5739     Display only basename of a filename.
5740
5741`set filename-display absolute'
5742     Display an absolute filename.
5743
5744`show filename-display'
5745     Show the current way to display filenames.
5746
5747   ---------- Footnotes ----------
5748
5749   (1) Note that embedded programs (the so-called "free-standing"
5750environment) are not required to have a `main' function as the entry
5751point.  They could even have multiple entry points.
5752
5753
5754File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
5755
57568.3 Selecting a Frame
5757=====================
5758
5759Most commands for examining the stack and other data in your program
5760work on whichever stack frame is selected at the moment.  Here are the
5761commands for selecting a stack frame; all of them finish by printing a
5762brief description of the stack frame just selected.
5763
5764`frame N'
5765`f N'
5766     Select frame number N.  Recall that frame zero is the innermost
5767     (currently executing) frame, frame one is the frame that called the
5768     innermost one, and so on.  The highest-numbered frame is the one
5769     for `main'.
5770
5771`frame ADDR'
5772`f ADDR'
5773     Select the frame at address ADDR.  This is useful mainly if the
5774     chaining of stack frames has been damaged by a bug, making it
5775     impossible for GDB to assign numbers properly to all frames.  In
5776     addition, this can be useful when your program has multiple stacks
5777     and switches between them.
5778
5779     On the SPARC architecture, `frame' needs two addresses to select
5780     an arbitrary frame: a frame pointer and a stack pointer.
5781
5782     On the MIPS and Alpha architecture, it needs two addresses: a stack
5783     pointer and a program counter.
5784
5785     On the 29k architecture, it needs three addresses: a register stack
5786     pointer, a program counter, and a memory stack pointer.
5787
5788`up N'
5789     Move N frames up the stack.  For positive numbers N, this advances
5790     toward the outermost frame, to higher frame numbers, to frames
5791     that have existed longer.  N defaults to one.
5792
5793`down N'
5794     Move N frames down the stack.  For positive numbers N, this
5795     advances toward the innermost frame, to lower frame numbers, to
5796     frames that were created more recently.  N defaults to one.  You
5797     may abbreviate `down' as `do'.
5798
5799   All of these commands end by printing two lines of output describing
5800the frame.  The first line shows the frame number, the function name,
5801the arguments, and the source file and line number of execution in that
5802frame.  The second line shows the text of that source line.
5803
5804   For example:
5805
5806     (gdb) up
5807     #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
5808         at env.c:10
5809     10              read_input_file (argv[i]);
5810
5811   After such a printout, the `list' command with no arguments prints
5812ten lines centered on the point of execution in the frame.  You can
5813also edit the program at the point of execution with your favorite
5814editing program by typing `edit'.  *Note Printing Source Lines: List,
5815for details.
5816
5817`up-silently N'
5818`down-silently N'
5819     These two commands are variants of `up' and `down', respectively;
5820     they differ in that they do their work silently, without causing
5821     display of the new frame.  They are intended primarily for use in
5822     GDB command scripts, where the output might be unnecessary and
5823     distracting.
5824
5825
5826File: gdb.info,  Node: Frame Info,  Prev: Selection,  Up: Stack
5827
58288.4 Information About a Frame
5829=============================
5830
5831There are several other commands to print information about the selected
5832stack frame.
5833
5834`frame'
5835`f'
5836     When used without any argument, this command does not change which
5837     frame is selected, but prints a brief description of the currently
5838     selected stack frame.  It can be abbreviated `f'.  With an
5839     argument, this command is used to select a stack frame.  *Note
5840     Selecting a Frame: Selection.
5841
5842`info frame'
5843`info f'
5844     This command prints a verbose description of the selected stack
5845     frame, including:
5846
5847        * the address of the frame
5848
5849        * the address of the next frame down (called by this frame)
5850
5851        * the address of the next frame up (caller of this frame)
5852
5853        * the language in which the source code corresponding to this
5854          frame is written
5855
5856        * the address of the frame's arguments
5857
5858        * the address of the frame's local variables
5859
5860        * the program counter saved in it (the address of execution in
5861          the caller frame)
5862
5863        * which registers were saved in the frame
5864
5865     The verbose description is useful when something has gone wrong
5866     that has made the stack format fail to fit the usual conventions.
5867
5868`info frame ADDR'
5869`info f ADDR'
5870     Print a verbose description of the frame at address ADDR, without
5871     selecting that frame.  The selected frame remains unchanged by this
5872     command.  This requires the same kind of address (more than one
5873     for some architectures) that you specify in the `frame' command.
5874     *Note Selecting a Frame: Selection.
5875
5876`info args'
5877     Print the arguments of the selected frame, each on a separate line.
5878
5879`info locals'
5880     Print the local variables of the selected frame, each on a separate
5881     line.  These are all variables (declared either static or
5882     automatic) accessible at the point of execution of the selected
5883     frame.
5884
5885
5886
5887File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
5888
58899 Examining Source Files
5890************************
5891
5892GDB can print parts of your program's source, since the debugging
5893information recorded in the program tells GDB what source files were
5894used to build it.  When your program stops, GDB spontaneously prints
5895the line where it stopped.  Likewise, when you select a stack frame
5896(*note Selecting a Frame: Selection.), GDB prints the line where
5897execution in that frame has stopped.  You can print other portions of
5898source files by explicit command.
5899
5900   If you use GDB through its GNU Emacs interface, you may prefer to
5901use Emacs facilities to view source; see *note Using GDB under GNU
5902Emacs: Emacs.
5903
5904* Menu:
5905
5906* List::                        Printing source lines
5907* Specify Location::            How to specify code locations
5908* Edit::                        Editing source files
5909* Search::                      Searching source files
5910* Source Path::                 Specifying source directories
5911* Machine Code::                Source and machine code
5912
5913
5914File: gdb.info,  Node: List,  Next: Specify Location,  Up: Source
5915
59169.1 Printing Source Lines
5917=========================
5918
5919To print lines from a source file, use the `list' command (abbreviated
5920`l').  By default, ten lines are printed.  There are several ways to
5921specify what part of the file you want to print; see *note Specify
5922Location::, for the full list.
5923
5924   Here are the forms of the `list' command most commonly used:
5925
5926`list LINENUM'
5927     Print lines centered around line number LINENUM in the current
5928     source file.
5929
5930`list FUNCTION'
5931     Print lines centered around the beginning of function FUNCTION.
5932
5933`list'
5934     Print more lines.  If the last lines printed were printed with a
5935     `list' command, this prints lines following the last lines
5936     printed; however, if the last line printed was a solitary line
5937     printed as part of displaying a stack frame (*note Examining the
5938     Stack: Stack.), this prints lines centered around that line.
5939
5940`list -'
5941     Print lines just before the lines last printed.
5942
5943   By default, GDB prints ten source lines with any of these forms of
5944the `list' command.  You can change this using `set listsize':
5945
5946`set listsize COUNT'
5947     Make the `list' command display COUNT source lines (unless the
5948     `list' argument explicitly specifies some other number).  Setting
5949     COUNT to 0 means there's no limit.
5950
5951`show listsize'
5952     Display the number of lines that `list' prints.
5953
5954   Repeating a `list' command with <RET> discards the argument, so it
5955is equivalent to typing just `list'.  This is more useful than listing
5956the same lines again.  An exception is made for an argument of `-';
5957that argument is preserved in repetition so that each repetition moves
5958up in the source file.
5959
5960   In general, the `list' command expects you to supply zero, one or two
5961"linespecs".  Linespecs specify source lines; there are several ways of
5962writing them (*note Specify Location::), but the effect is always to
5963specify some source line.
5964
5965   Here is a complete description of the possible arguments for `list':
5966
5967`list LINESPEC'
5968     Print lines centered around the line specified by LINESPEC.
5969
5970`list FIRST,LAST'
5971     Print lines from FIRST to LAST.  Both arguments are linespecs.
5972     When a `list' command has two linespecs, and the source file of
5973     the second linespec is omitted, this refers to the same source
5974     file as the first linespec.
5975
5976`list ,LAST'
5977     Print lines ending with LAST.
5978
5979`list FIRST,'
5980     Print lines starting with FIRST.
5981
5982`list +'
5983     Print lines just after the lines last printed.
5984
5985`list -'
5986     Print lines just before the lines last printed.
5987
5988`list'
5989     As described in the preceding table.
5990
5991
5992File: gdb.info,  Node: Specify Location,  Next: Edit,  Prev: List,  Up: Source
5993
59949.2 Specifying a Location
5995=========================
5996
5997Several GDB commands accept arguments that specify a location of your
5998program's code.  Since GDB is a source-level debugger, a location
5999usually specifies some line in the source code; for that reason,
6000locations are also known as "linespecs".
6001
6002   Here are all the different ways of specifying a code location that
6003GDB understands:
6004
6005`LINENUM'
6006     Specifies the line number LINENUM of the current source file.
6007
6008`-OFFSET'
6009`+OFFSET'
6010     Specifies the line OFFSET lines before or after the "current
6011     line".  For the `list' command, the current line is the last one
6012     printed; for the breakpoint commands, this is the line at which
6013     execution stopped in the currently selected "stack frame" (*note
6014     Frames: Frames, for a description of stack frames.)  When used as
6015     the second of the two linespecs in a `list' command, this
6016     specifies the line OFFSET lines up or down from the first linespec.
6017
6018`FILENAME:LINENUM'
6019     Specifies the line LINENUM in the source file FILENAME.  If
6020     FILENAME is a relative file name, then it will match any source
6021     file name with the same trailing components.  For example, if
6022     FILENAME is `gcc/expr.c', then it will match source file name of
6023     `/build/trunk/gcc/expr.c', but not `/build/trunk/libcpp/expr.c' or
6024     `/build/trunk/gcc/x-expr.c'.
6025
6026`FUNCTION'
6027     Specifies the line that begins the body of the function FUNCTION.
6028     For example, in C, this is the line with the open brace.
6029
6030`FUNCTION:LABEL'
6031     Specifies the line where LABEL appears in FUNCTION.
6032
6033`FILENAME:FUNCTION'
6034     Specifies the line that begins the body of the function FUNCTION
6035     in the file FILENAME.  You only need the file name with a function
6036     name to avoid ambiguity when there are identically named functions
6037     in different source files.
6038
6039`LABEL'
6040     Specifies the line at which the label named LABEL appears.  GDB
6041     searches for the label in the function corresponding to the
6042     currently selected stack frame.  If there is no current selected
6043     stack frame (for instance, if the inferior is not running), then
6044     GDB will not search for a label.
6045
6046`*ADDRESS'
6047     Specifies the program address ADDRESS.  For line-oriented
6048     commands, such as `list' and `edit', this specifies a source line
6049     that contains ADDRESS.  For `break' and other breakpoint oriented
6050     commands, this can be used to set breakpoints in parts of your
6051     program which do not have debugging information or source files.
6052
6053     Here ADDRESS may be any expression valid in the current working
6054     language (*note working language: Languages.) that specifies a code
6055     address.  In addition, as a convenience, GDB extends the semantics
6056     of expressions used in locations to cover the situations that
6057     frequently happen during debugging.  Here are the various forms of
6058     ADDRESS:
6059
6060    `EXPRESSION'
6061          Any expression valid in the current working language.
6062
6063    `FUNCADDR'
6064          An address of a function or procedure derived from its name.
6065          In C, C++, Java, Objective-C, Fortran, minimal, and assembly,
6066          this is simply the function's name FUNCTION (and actually a
6067          special case of a valid expression).  In Pascal and Modula-2,
6068          this is `&FUNCTION'.  In Ada, this is `FUNCTION'Address'
6069          (although the Pascal form also works).
6070
6071          This form specifies the address of the function's first
6072          instruction, before the stack frame and arguments have been
6073          set up.
6074
6075    `'FILENAME'::FUNCADDR'
6076          Like FUNCADDR above, but also specifies the name of the source
6077          file explicitly.  This is useful if the name of the function
6078          does not specify the function unambiguously, e.g., if there
6079          are several functions with identical names in different
6080          source files.
6081
6082`-pstap|-probe-stap [OBJFILE:[PROVIDER:]]NAME'
6083     The GNU/Linux tool `SystemTap' provides a way for applications to
6084     embed static probes.  *Note Static Probe Points::, for more
6085     information on finding and using static probes.  This form of
6086     linespec specifies the location of such a static probe.
6087
6088     If OBJFILE is given, only probes coming from that shared library
6089     or executable matching OBJFILE as a regular expression are
6090     considered.  If PROVIDER is given, then only probes from that
6091     provider are considered.  If several probes match the spec, GDB
6092     will insert a breakpoint at each one of those probes.
6093
6094
6095
6096File: gdb.info,  Node: Edit,  Next: Search,  Prev: Specify Location,  Up: Source
6097
60989.3 Editing Source Files
6099========================
6100
6101To edit the lines in a source file, use the `edit' command.  The
6102editing program of your choice is invoked with the current line set to
6103the active line in the program.  Alternatively, there are several ways
6104to specify what part of the file you want to print if you want to see
6105other parts of the program:
6106
6107`edit LOCATION'
6108     Edit the source file specified by `location'.  Editing starts at
6109     that LOCATION, e.g., at the specified source line of the specified
6110     file.  *Note Specify Location::, for all the possible forms of the
6111     LOCATION argument; here are the forms of the `edit' command most
6112     commonly used:
6113
6114    `edit NUMBER'
6115          Edit the current source file with NUMBER as the active line
6116          number.
6117
6118    `edit FUNCTION'
6119          Edit the file containing FUNCTION at the beginning of its
6120          definition.
6121
6122
61239.3.1 Choosing your Editor
6124--------------------------
6125
6126You can customize GDB to use any editor you want (1).  By default, it
6127is `/bin/ex', but you can change this by setting the environment
6128variable `EDITOR' before using GDB.  For example, to configure GDB to
6129use the `vi' editor, you could use these commands with the `sh' shell:
6130     EDITOR=/usr/bin/vi
6131     export EDITOR
6132     gdb ...
6133   or in the `csh' shell,
6134     setenv EDITOR /usr/bin/vi
6135     gdb ...
6136
6137   ---------- Footnotes ----------
6138
6139   (1) The only restriction is that your editor (say `ex'), recognizes
6140the following command-line syntax:
6141     ex +NUMBER file
6142   The optional numeric value +NUMBER specifies the number of the line
6143in the file where to start editing.
6144
6145
6146File: gdb.info,  Node: Search,  Next: Source Path,  Prev: Edit,  Up: Source
6147
61489.4 Searching Source Files
6149==========================
6150
6151There are two commands for searching through the current source file
6152for a regular expression.
6153
6154`forward-search REGEXP'
6155`search REGEXP'
6156     The command `forward-search REGEXP' checks each line, starting
6157     with the one following the last line listed, for a match for
6158     REGEXP.  It lists the line that is found.  You can use the synonym
6159     `search REGEXP' or abbreviate the command name as `fo'.
6160
6161`reverse-search REGEXP'
6162     The command `reverse-search REGEXP' checks each line, starting
6163     with the one before the last line listed and going backward, for a
6164     match for REGEXP.  It lists the line that is found.  You can
6165     abbreviate this command as `rev'.
6166
6167
6168File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
6169
61709.5 Specifying Source Directories
6171=================================
6172
6173Executable programs sometimes do not record the directories of the
6174source files from which they were compiled, just the names.  Even when
6175they do, the directories could be moved between the compilation and
6176your debugging session.  GDB has a list of directories to search for
6177source files; this is called the "source path".  Each time GDB wants a
6178source file, it tries all the directories in the list, in the order
6179they are present in the list, until it finds a file with the desired
6180name.
6181
6182   For example, suppose an executable references the file
6183`/usr/src/foo-1.0/lib/foo.c', and our source path is `/mnt/cross'.  The
6184file is first looked up literally; if this fails,
6185`/mnt/cross/usr/src/foo-1.0/lib/foo.c' is tried; if this fails,
6186`/mnt/cross/foo.c' is opened; if this fails, an error message is
6187printed.  GDB does not look up the parts of the source file name, such
6188as `/mnt/cross/src/foo-1.0/lib/foo.c'.  Likewise, the subdirectories of
6189the source path are not searched: if the source path is `/mnt/cross',
6190and the binary refers to `foo.c', GDB would not find it under
6191`/mnt/cross/usr/src/foo-1.0/lib'.
6192
6193   Plain file names, relative file names with leading directories, file
6194names containing dots, etc. are all treated as described above; for
6195instance, if the source path is `/mnt/cross', and the source file is
6196recorded as `../lib/foo.c', GDB would first try `../lib/foo.c', then
6197`/mnt/cross/../lib/foo.c', and after that--`/mnt/cross/foo.c'.
6198
6199   Note that the executable search path is _not_ used to locate the
6200source files.
6201
6202   Whenever you reset or rearrange the source path, GDB clears out any
6203information it has cached about where source files are found and where
6204each line is in the file.
6205
6206   When you start GDB, its source path includes only `cdir' and `cwd',
6207in that order.  To add other directories, use the `directory' command.
6208
6209   The search path is used to find both program source files and GDB
6210script files (read using the `-command' option and `source' command).
6211
6212   In addition to the source path, GDB provides a set of commands that
6213manage a list of source path substitution rules.  A "substitution rule"
6214specifies how to rewrite source directories stored in the program's
6215debug information in case the sources were moved to a different
6216directory between compilation and debugging.  A rule is made of two
6217strings, the first specifying what needs to be rewritten in the path,
6218and the second specifying how it should be rewritten.  In *note set
6219substitute-path::, we name these two parts FROM and TO respectively.
6220GDB does a simple string replacement of FROM with TO at the start of
6221the directory part of the source file name, and uses that result
6222instead of the original file name to look up the sources.
6223
6224   Using the previous example, suppose the `foo-1.0' tree has been
6225moved from `/usr/src' to `/mnt/cross', then you can tell GDB to replace
6226`/usr/src' in all source path names with `/mnt/cross'.  The first
6227lookup will then be `/mnt/cross/foo-1.0/lib/foo.c' in place of the
6228original location of `/usr/src/foo-1.0/lib/foo.c'.  To define a source
6229path substitution rule, use the `set substitute-path' command (*note
6230set substitute-path::).
6231
6232   To avoid unexpected substitution results, a rule is applied only if
6233the FROM part of the directory name ends at a directory separator.  For
6234instance, a rule substituting  `/usr/source' into `/mnt/cross' will be
6235applied to `/usr/source/foo-1.0' but not to `/usr/sourceware/foo-2.0'.
6236And because the substitution is applied only at the beginning of the
6237directory name, this rule will not be applied to
6238`/root/usr/source/baz.c' either.
6239
6240   In many cases, you can achieve the same result using the `directory'
6241command.  However, `set substitute-path' can be more efficient in the
6242case where the sources are organized in a complex tree with multiple
6243subdirectories.  With the `directory' command, you need to add each
6244subdirectory of your project.  If you moved the entire tree while
6245preserving its internal organization, then `set substitute-path' allows
6246you to direct the debugger to all the sources with one single command.
6247
6248   `set substitute-path' is also more than just a shortcut command.
6249The source path is only used if the file at the original location no
6250longer exists.  On the other hand, `set substitute-path' modifies the
6251debugger behavior to look at the rewritten location instead.  So, if
6252for any reason a source file that is not relevant to your executable is
6253located at the original location, a substitution rule is the only
6254method available to point GDB at the new location.
6255
6256   You can configure a default source path substitution rule by
6257configuring GDB with the `--with-relocated-sources=DIR' option.  The DIR
6258should be the name of a directory under GDB's configured prefix (set
6259with `--prefix' or `--exec-prefix'), and directory names in debug
6260information under DIR will be adjusted automatically if the installed
6261GDB is moved to a new location.  This is useful if GDB, libraries or
6262executables with debug information and corresponding source code are
6263being moved together.
6264
6265`directory DIRNAME ...'
6266
6267`dir DIRNAME ...'
6268     Add directory DIRNAME to the front of the source path.  Several
6269     directory names may be given to this command, separated by `:'
6270     (`;' on MS-DOS and MS-Windows, where `:' usually appears as part
6271     of absolute file names) or whitespace.  You may specify a
6272     directory that is already in the source path; this moves it
6273     forward, so GDB searches it sooner.
6274
6275     You can use the string `$cdir' to refer to the compilation
6276     directory (if one is recorded), and `$cwd' to refer to the current
6277     working directory.  `$cwd' is not the same as `.'--the former
6278     tracks the current working directory as it changes during your GDB
6279     session, while the latter is immediately expanded to the current
6280     directory at the time you add an entry to the source path.
6281
6282`directory'
6283     Reset the source path to its default value (`$cdir:$cwd' on Unix
6284     systems).  This requires confirmation.
6285
6286`set directories PATH-LIST'
6287     Set the source path to PATH-LIST.  `$cdir:$cwd' are added if
6288     missing.
6289
6290`show directories'
6291     Print the source path: show which directories it contains.
6292
6293`set substitute-path FROM TO'
6294     Define a source path substitution rule, and add it at the end of
6295     the current list of existing substitution rules.  If a rule with
6296     the same FROM was already defined, then the old rule is also
6297     deleted.
6298
6299     For example, if the file `/foo/bar/baz.c' was moved to
6300     `/mnt/cross/baz.c', then the command
6301
6302          (gdb) set substitute-path /usr/src /mnt/cross
6303
6304     will tell GDB to replace `/usr/src' with `/mnt/cross', which will
6305     allow GDB to find the file `baz.c' even though it was moved.
6306
6307     In the case when more than one substitution rule have been defined,
6308     the rules are evaluated one by one in the order where they have
6309     been defined.  The first one matching, if any, is selected to
6310     perform the substitution.
6311
6312     For instance, if we had entered the following commands:
6313
6314          (gdb) set substitute-path /usr/src/include /mnt/include
6315          (gdb) set substitute-path /usr/src /mnt/src
6316
6317     GDB would then rewrite `/usr/src/include/defs.h' into
6318     `/mnt/include/defs.h' by using the first rule.  However, it would
6319     use the second rule to rewrite `/usr/src/lib/foo.c' into
6320     `/mnt/src/lib/foo.c'.
6321
6322`unset substitute-path [path]'
6323     If a path is specified, search the current list of substitution
6324     rules for a rule that would rewrite that path.  Delete that rule
6325     if found.  A warning is emitted by the debugger if no rule could
6326     be found.
6327
6328     If no path is specified, then all substitution rules are deleted.
6329
6330`show substitute-path [path]'
6331     If a path is specified, then print the source path substitution
6332     rule which would rewrite that path, if any.
6333
6334     If no path is specified, then print all existing source path
6335     substitution rules.
6336
6337
6338   If your source path is cluttered with directories that are no longer
6339of interest, GDB may sometimes cause confusion by finding the wrong
6340versions of source.  You can correct the situation as follows:
6341
6342  1. Use `directory' with no argument to reset the source path to its
6343     default value.
6344
6345  2. Use `directory' with suitable arguments to reinstall the
6346     directories you want in the source path.  You can add all the
6347     directories in one command.
6348
6349
6350File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
6351
63529.6 Source and Machine Code
6353===========================
6354
6355You can use the command `info line' to map source lines to program
6356addresses (and vice versa), and the command `disassemble' to display a
6357range of addresses as machine instructions.  You can use the command
6358`set disassemble-next-line' to set whether to disassemble next source
6359line when execution stops.  When run under GNU Emacs mode, the `info
6360line' command causes the arrow to point to the line specified.  Also,
6361`info line' prints addresses in symbolic form as well as hex.
6362
6363`info line LINESPEC'
6364     Print the starting and ending addresses of the compiled code for
6365     source line LINESPEC.  You can specify source lines in any of the
6366     ways documented in *note Specify Location::.
6367
6368   For example, we can use `info line' to discover the location of the
6369object code for the first line of function `m4_changequote':
6370
6371     (gdb) info line m4_changequote
6372     Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
6373
6374We can also inquire (using `*ADDR' as the form for LINESPEC) what
6375source line covers a particular address:
6376     (gdb) info line *0x63ff
6377     Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
6378
6379   After `info line', the default address for the `x' command is
6380changed to the starting address of the line, so that `x/i' is
6381sufficient to begin examining the machine code (*note Examining Memory:
6382Memory.).  Also, this address is saved as the value of the convenience
6383variable `$_' (*note Convenience Variables: Convenience Vars.).
6384
6385`disassemble'
6386`disassemble /m'
6387`disassemble /r'
6388     This specialized command dumps a range of memory as machine
6389     instructions.  It can also print mixed source+disassembly by
6390     specifying the `/m' modifier and print the raw instructions in hex
6391     as well as in symbolic form by specifying the `/r'.  The default
6392     memory range is the function surrounding the program counter of
6393     the selected frame.  A single argument to this command is a
6394     program counter value; GDB dumps the function surrounding this
6395     value.  When two arguments are given, they should be separated by
6396     a comma, possibly surrounded by whitespace.  The arguments specify
6397     a range of addresses to dump, in one of two forms:
6398
6399    `START,END'
6400          the addresses from START (inclusive) to END (exclusive)
6401
6402    `START,+LENGTH'
6403          the addresses from START (inclusive) to `START+LENGTH'
6404          (exclusive).
6405
6406     When 2 arguments are specified, the name of the function is also
6407     printed (since there could be several functions in the given
6408     range).
6409
6410     The argument(s) can be any expression yielding a numeric value,
6411     such as `0x32c4', `&main+10' or `$pc - 8'.
6412
6413     If the range of memory being disassembled contains current program
6414     counter, the instruction at that location is shown with a `=>'
6415     marker.
6416
6417   The following example shows the disassembly of a range of addresses
6418of HP PA-RISC 2.0 code:
6419
6420     (gdb) disas 0x32c4, 0x32e4
6421     Dump of assembler code from 0x32c4 to 0x32e4:
6422        0x32c4 <main+204>:      addil 0,dp
6423        0x32c8 <main+208>:      ldw 0x22c(sr0,r1),r26
6424        0x32cc <main+212>:      ldil 0x3000,r31
6425        0x32d0 <main+216>:      ble 0x3f8(sr4,r31)
6426        0x32d4 <main+220>:      ldo 0(r31),rp
6427        0x32d8 <main+224>:      addil -0x800,dp
6428        0x32dc <main+228>:      ldo 0x588(r1),r26
6429        0x32e0 <main+232>:      ldil 0x3000,r31
6430     End of assembler dump.
6431
6432   Here is an example showing mixed source+assembly for Intel x86, when
6433the program is stopped just after function prologue:
6434
6435     (gdb) disas /m main
6436     Dump of assembler code for function main:
6437     5       {
6438        0x08048330 <+0>:    push   %ebp
6439        0x08048331 <+1>:    mov    %esp,%ebp
6440        0x08048333 <+3>:    sub    $0x8,%esp
6441        0x08048336 <+6>:    and    $0xfffffff0,%esp
6442        0x08048339 <+9>:    sub    $0x10,%esp
6443
6444     6         printf ("Hello.\n");
6445     => 0x0804833c <+12>:   movl   $0x8048440,(%esp)
6446        0x08048343 <+19>:   call   0x8048284 <puts@plt>
6447
6448     7         return 0;
6449     8       }
6450        0x08048348 <+24>:   mov    $0x0,%eax
6451        0x0804834d <+29>:   leave
6452        0x0804834e <+30>:   ret
6453
6454     End of assembler dump.
6455
6456   Here is another example showing raw instructions in hex for AMD
6457x86-64,
6458
6459     (gdb) disas /r 0x400281,+10
6460     Dump of assembler code from 0x400281 to 0x40028b:
6461        0x0000000000400281:  38 36  cmp    %dh,(%rsi)
6462        0x0000000000400283:  2d 36 34 2e 73 sub    $0x732e3436,%eax
6463        0x0000000000400288:  6f     outsl  %ds:(%rsi),(%dx)
6464        0x0000000000400289:  2e 32 00       xor    %cs:(%rax),%al
6465     End of assembler dump.
6466
6467   Addresses cannot be specified as a linespec (*note Specify
6468Location::).  So, for example, if you want to disassemble function `bar'
6469in file `foo.c', you must type `disassemble 'foo.c'::bar' and not
6470`disassemble foo.c:bar'.
6471
6472   Some architectures have more than one commonly-used set of
6473instruction mnemonics or other syntax.
6474
6475   For programs that were dynamically linked and use shared libraries,
6476instructions that call functions or branch to locations in the shared
6477libraries might show a seemingly bogus location--it's actually a
6478location of the relocation table.  On some architectures, GDB might be
6479able to resolve these to actual function names.
6480
6481`set disassembly-flavor INSTRUCTION-SET'
6482     Select the instruction set to use when disassembling the program
6483     via the `disassemble' or `x/i' commands.
6484
6485     Currently this command is only defined for the Intel x86 family.
6486     You can set INSTRUCTION-SET to either `intel' or `att'.  The
6487     default is `att', the AT&T flavor used by default by Unix
6488     assemblers for x86-based targets.
6489
6490`show disassembly-flavor'
6491     Show the current setting of the disassembly flavor.
6492
6493`set disassemble-next-line'
6494`show disassemble-next-line'
6495     Control whether or not GDB will disassemble the next source line
6496     or instruction when execution stops.  If ON, GDB will display
6497     disassembly of the next source line when execution of the program
6498     being debugged stops.  This is _in addition_ to displaying the
6499     source line itself, which GDB always does if possible.  If the
6500     next source line cannot be displayed for some reason (e.g., if GDB
6501     cannot find the source file, or there's no line info in the debug
6502     info), GDB will display disassembly of the next _instruction_
6503     instead of showing the next source line.  If AUTO, GDB will
6504     display disassembly of next instruction only if the source line
6505     cannot be displayed.  This setting causes GDB to display some
6506     feedback when you step through a function with no line info or
6507     whose source file is unavailable.  The default is OFF, which means
6508     never display the disassembly of the next line or instruction.
6509
6510
6511File: gdb.info,  Node: Data,  Next: Optimized Code,  Prev: Source,  Up: Top
6512
651310 Examining Data
6514*****************
6515
6516The usual way to examine data in your program is with the `print'
6517command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
6518prints the value of an expression of the language your program is
6519written in (*note Using GDB with Different Languages: Languages.).  It
6520may also print the expression using a Python-based pretty-printer
6521(*note Pretty Printing::).
6522
6523`print EXPR'
6524`print /F EXPR'
6525     EXPR is an expression (in the source language).  By default the
6526     value of EXPR is printed in a format appropriate to its data type;
6527     you can choose a different format by specifying `/F', where F is a
6528     letter specifying the format; see *note Output Formats: Output
6529     Formats.
6530
6531`print'
6532`print /F'
6533     If you omit EXPR, GDB displays the last value again (from the
6534     "value history"; *note Value History: Value History.).  This
6535     allows you to conveniently inspect the same value in an
6536     alternative format.
6537
6538   A more low-level way of examining data is with the `x' command.  It
6539examines data in memory at a specified address and prints it in a
6540specified format.  *Note Examining Memory: Memory.
6541
6542   If you are interested in information about types, or about how the
6543fields of a struct or a class are declared, use the `ptype EXP' command
6544rather than `print'.  *Note Examining the Symbol Table: Symbols.
6545
6546   Another way of examining values of expressions and type information
6547is through the Python extension command `explore' (available only if
6548the GDB build is configured with `--with-python').  It offers an
6549interactive way to start at the highest level (or, the most abstract
6550level) of the data type of an expression (or, the data type itself) and
6551explore all the way down to leaf scalar values/fields embedded in the
6552higher level data types.
6553
6554`explore ARG'
6555     ARG is either an expression (in the source language), or a type
6556     visible in the current context of the program being debugged.
6557
6558   The working of the `explore' command can be illustrated with an
6559example.  If a data type `struct ComplexStruct' is defined in your C
6560program as
6561
6562     struct SimpleStruct
6563     {
6564       int i;
6565       double d;
6566     };
6567
6568     struct ComplexStruct
6569     {
6570       struct SimpleStruct *ss_p;
6571       int arr[10];
6572     };
6573
6574followed by variable declarations as
6575
6576     struct SimpleStruct ss = { 10, 1.11 };
6577     struct ComplexStruct cs = { &ss, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } };
6578
6579then, the value of the variable `cs' can be explored using the
6580`explore' command as follows.
6581
6582     (gdb) explore cs
6583     The value of `cs' is a struct/class of type `struct ComplexStruct' with
6584     the following fields:
6585
6586       ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
6587        arr = <Enter 1 to explore this field of type `int [10]'>
6588
6589     Enter the field number of choice:
6590
6591Since the fields of `cs' are not scalar values, you are being prompted
6592to chose the field you want to explore.  Let's say you choose the field
6593`ss_p' by entering `0'.  Then, since this field is a pointer, you will
6594be asked if it is pointing to a single value.  From the declaration of
6595`cs' above, it is indeed pointing to a single value, hence you enter
6596`y'.  If you enter `n', then you will be asked if it were pointing to
6597an array of values, in which case this field will be explored as if it
6598were an array.
6599
6600     `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
6601     Continue exploring it as a pointer to a single value [y/n]: y
6602     The value of `*(cs.ss_p)' is a struct/class of type `struct
6603     SimpleStruct' with the following fields:
6604
6605       i = 10 .. (Value of type `int')
6606       d = 1.1100000000000001 .. (Value of type `double')
6607
6608     Press enter to return to parent value:
6609
6610If the field `arr' of `cs' was chosen for exploration by entering `1'
6611earlier, then since it is as array, you will be prompted to enter the
6612index of the element in the array that you want to explore.
6613
6614     `cs.arr' is an array of `int'.
6615     Enter the index of the element you want to explore in `cs.arr': 5
6616
6617     `(cs.arr)[5]' is a scalar value of type `int'.
6618
6619     (cs.arr)[5] = 4
6620
6621     Press enter to return to parent value:
6622
6623   In general, at any stage of exploration, you can go deeper towards
6624the leaf values by responding to the prompts appropriately, or hit the
6625return key to return to the enclosing data structure (the higher level
6626data structure).
6627
6628   Similar to exploring values, you can use the `explore' command to
6629explore types.  Instead of specifying a value (which is typically a
6630variable name or an expression valid in the current context of the
6631program being debugged), you specify a type name.  If you consider the
6632same example as above, your can explore the type `struct ComplexStruct'
6633by passing the argument `struct ComplexStruct' to the `explore' command.
6634
6635     (gdb) explore struct ComplexStruct
6636
6637By responding to the prompts appropriately in the subsequent interactive
6638session, you can explore the type `struct ComplexStruct' in a manner
6639similar to how the value `cs' was explored in the above example.
6640
6641   The `explore' command also has two sub-commands, `explore value' and
6642`explore type'. The former sub-command is a way to explicitly specify
6643that value exploration of the argument is being invoked, while the
6644latter is a way to explicitly specify that type exploration of the
6645argument is being invoked.
6646
6647`explore value EXPR'
6648     This sub-command of `explore' explores the value of the expression
6649     EXPR (if EXPR is an expression valid in the current context of the
6650     program being debugged).  The behavior of this command is
6651     identical to that of the behavior of the `explore' command being
6652     passed the argument EXPR.
6653
6654`explore type ARG'
6655     This sub-command of `explore' explores the type of ARG (if ARG is
6656     a type visible in the current context of program being debugged),
6657     or the type of the value/expression ARG (if ARG is an expression
6658     valid in the current context of the program being debugged).  If
6659     ARG is a type, then the behavior of this command is identical to
6660     that of the `explore' command being passed the argument ARG.  If
6661     ARG is an expression, then the behavior of this command will be
6662     identical to that of the `explore' command being passed the type
6663     of ARG as the argument.
6664
6665* Menu:
6666
6667* Expressions::                 Expressions
6668* Ambiguous Expressions::       Ambiguous Expressions
6669* Variables::                   Program variables
6670* Arrays::                      Artificial arrays
6671* Output Formats::              Output formats
6672* Memory::                      Examining memory
6673* Auto Display::                Automatic display
6674* Print Settings::              Print settings
6675* Pretty Printing::             Python pretty printing
6676* Value History::               Value history
6677* Convenience Vars::            Convenience variables
6678* Convenience Funs::            Convenience functions
6679* Registers::                   Registers
6680* Floating Point Hardware::     Floating point hardware
6681* Vector Unit::                 Vector Unit
6682* OS Information::              Auxiliary data provided by operating system
6683* Memory Region Attributes::    Memory region attributes
6684* Dump/Restore Files::          Copy between memory and a file
6685* Core File Generation::        Cause a program dump its core
6686* Character Sets::              Debugging programs that use a different
6687                                character set than GDB does
6688* Caching Remote Data::         Data caching for remote targets
6689* Searching Memory::            Searching memory for a sequence of bytes
6690
6691
6692File: gdb.info,  Node: Expressions,  Next: Ambiguous Expressions,  Up: Data
6693
669410.1 Expressions
6695================
6696
6697`print' and many other GDB commands accept an expression and compute
6698its value.  Any kind of constant, variable or operator defined by the
6699programming language you are using is valid in an expression in GDB.
6700This includes conditional expressions, function calls, casts, and
6701string constants.  It also includes preprocessor macros, if you
6702compiled your program to include this information; see *note
6703Compilation::.
6704
6705   GDB supports array constants in expressions input by the user.  The
6706syntax is {ELEMENT, ELEMENT...}.  For example, you can use the command
6707`print {1, 2, 3}' to create an array of three integers.  If you pass an
6708array to a function or assign it to a program variable, GDB copies the
6709array to memory that is `malloc'ed in the target program.
6710
6711   Because C is so widespread, most of the expressions shown in
6712examples in this manual are in C.  *Note Using GDB with Different
6713Languages: Languages, for information on how to use expressions in other
6714languages.
6715
6716   In this section, we discuss operators that you can use in GDB
6717expressions regardless of your programming language.
6718
6719   Casts are supported in all languages, not just in C, because it is so
6720useful to cast a number into a pointer in order to examine a structure
6721at that address in memory.
6722
6723   GDB supports these operators, in addition to those common to
6724programming languages:
6725
6726`@'
6727     `@' is a binary operator for treating parts of memory as arrays.
6728     *Note Artificial Arrays: Arrays, for more information.
6729
6730`::'
6731     `::' allows you to specify a variable in terms of the file or
6732     function where it is defined.  *Note Program Variables: Variables.
6733
6734`{TYPE} ADDR'
6735     Refers to an object of type TYPE stored at address ADDR in memory.
6736     ADDR may be any expression whose value is an integer or pointer
6737     (but parentheses are required around binary operators, just as in
6738     a cast).  This construct is allowed regardless of what kind of
6739     data is normally supposed to reside at ADDR.
6740
6741
6742File: gdb.info,  Node: Ambiguous Expressions,  Next: Variables,  Prev: Expressions,  Up: Data
6743
674410.2 Ambiguous Expressions
6745==========================
6746
6747Expressions can sometimes contain some ambiguous elements.  For
6748instance, some programming languages (notably Ada, C++ and Objective-C)
6749permit a single function name to be defined several times, for
6750application in different contexts.  This is called "overloading".
6751Another example involving Ada is generics.  A "generic package" is
6752similar to C++ templates and is typically instantiated several times,
6753resulting in the same function name being defined in different contexts.
6754
6755   In some cases and depending on the language, it is possible to adjust
6756the expression to remove the ambiguity.  For instance in C++, you can
6757specify the signature of the function you want to break on, as in
6758`break FUNCTION(TYPES)'.  In Ada, using the fully qualified name of
6759your function often makes the expression unambiguous as well.
6760
6761   When an ambiguity that needs to be resolved is detected, the debugger
6762has the capability to display a menu of numbered choices for each
6763possibility, and then waits for the selection with the prompt `>'.  The
6764first option is always `[0] cancel', and typing `0 <RET>' aborts the
6765current command.  If the command in which the expression was used
6766allows more than one choice to be selected, the next option in the menu
6767is `[1] all', and typing `1 <RET>' selects all possible choices.
6768
6769   For example, the following session excerpt shows an attempt to set a
6770breakpoint at the overloaded symbol `String::after'.  We choose three
6771particular definitions of that function name:
6772
6773     (gdb) b String::after
6774     [0] cancel
6775     [1] all
6776     [2] file:String.cc; line number:867
6777     [3] file:String.cc; line number:860
6778     [4] file:String.cc; line number:875
6779     [5] file:String.cc; line number:853
6780     [6] file:String.cc; line number:846
6781     [7] file:String.cc; line number:735
6782     > 2 4 6
6783     Breakpoint 1 at 0xb26c: file String.cc, line 867.
6784     Breakpoint 2 at 0xb344: file String.cc, line 875.
6785     Breakpoint 3 at 0xafcc: file String.cc, line 846.
6786     Multiple breakpoints were set.
6787     Use the "delete" command to delete unwanted
6788      breakpoints.
6789     (gdb)
6790
6791`set multiple-symbols MODE'
6792     This option allows you to adjust the debugger behavior when an
6793     expression is ambiguous.
6794
6795     By default, MODE is set to `all'.  If the command with which the
6796     expression is used allows more than one choice, then GDB
6797     automatically selects all possible choices.  For instance,
6798     inserting a breakpoint on a function using an ambiguous name
6799     results in a breakpoint inserted on each possible match.  However,
6800     if a unique choice must be made, then GDB uses the menu to help
6801     you disambiguate the expression.  For instance, printing the
6802     address of an overloaded function will result in the use of the
6803     menu.
6804
6805     When MODE is set to `ask', the debugger always uses the menu when
6806     an ambiguity is detected.
6807
6808     Finally, when MODE is set to `cancel', the debugger reports an
6809     error due to the ambiguity and the command is aborted.
6810
6811`show multiple-symbols'
6812     Show the current value of the `multiple-symbols' setting.
6813
6814
6815File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Ambiguous Expressions,  Up: Data
6816
681710.3 Program Variables
6818======================
6819
6820The most common kind of expression to use is the name of a variable in
6821your program.
6822
6823   Variables in expressions are understood in the selected stack frame
6824(*note Selecting a Frame: Selection.); they must be either:
6825
6826   * global (or file-static)
6827
6828or
6829
6830   * visible according to the scope rules of the programming language
6831     from the point of execution in that frame
6832
6833This means that in the function
6834
6835     foo (a)
6836          int a;
6837     {
6838       bar (a);
6839       {
6840         int b = test ();
6841         bar (b);
6842       }
6843     }
6844
6845you can examine and use the variable `a' whenever your program is
6846executing within the function `foo', but you can only use or examine
6847the variable `b' while your program is executing inside the block where
6848`b' is declared.
6849
6850   There is an exception: you can refer to a variable or function whose
6851scope is a single source file even if the current execution point is not
6852in this file.  But it is possible to have more than one such variable or
6853function with the same name (in different source files).  If that
6854happens, referring to that name has unpredictable effects.  If you wish,
6855you can specify a static variable in a particular function or file by
6856using the colon-colon (`::') notation:
6857
6858     FILE::VARIABLE
6859     FUNCTION::VARIABLE
6860
6861Here FILE or FUNCTION is the name of the context for the static
6862VARIABLE.  In the case of file names, you can use quotes to make sure
6863GDB parses the file name as a single word--for example, to print a
6864global value of `x' defined in `f2.c':
6865
6866     (gdb) p 'f2.c'::x
6867
6868   The `::' notation is normally used for referring to static
6869variables, since you typically disambiguate uses of local variables in
6870functions by selecting the appropriate frame and using the simple name
6871of the variable.  However, you may also use this notation to refer to
6872local variables in frames enclosing the selected frame:
6873
6874     void
6875     foo (int a)
6876     {
6877       if (a < 10)
6878         bar (a);
6879       else
6880         process (a);    /* Stop here */
6881     }
6882
6883     int
6884     bar (int a)
6885     {
6886       foo (a + 5);
6887     }
6888
6889For example, if there is a breakpoint at the commented line, here is
6890what you might see when the program stops after executing the call
6891`bar(0)':
6892
6893     (gdb) p a
6894     $1 = 10
6895     (gdb) p bar::a
6896     $2 = 5
6897     (gdb) up 2
6898     #2  0x080483d0 in foo (a=5) at foobar.c:12
6899     (gdb) p a
6900     $3 = 5
6901     (gdb) p bar::a
6902     $4 = 0
6903
6904   These uses of `::' are very rarely in conflict with the very similar
6905use of the same notation in C++.  GDB also supports use of the C++
6906scope resolution operator in GDB expressions.
6907
6908     _Warning:_ Occasionally, a local variable may appear to have the
6909     wrong value at certain points in a function--just after entry to a
6910     new scope, and just before exit.
6911   You may see this problem when you are stepping by machine
6912instructions.  This is because, on most machines, it takes more than
6913one instruction to set up a stack frame (including local variable
6914definitions); if you are stepping by machine instructions, variables
6915may appear to have the wrong values until the stack frame is completely
6916built.  On exit, it usually also takes more than one machine
6917instruction to destroy a stack frame; after you begin stepping through
6918that group of instructions, local variable definitions may be gone.
6919
6920   This may also happen when the compiler does significant
6921optimizations.  To be sure of always seeing accurate values, turn off
6922all optimization when compiling.
6923
6924   Another possible effect of compiler optimizations is to optimize
6925unused variables out of existence, or assign variables to registers (as
6926opposed to memory addresses).  Depending on the support for such cases
6927offered by the debug info format used by the compiler, GDB might not be
6928able to display values for such local variables.  If that happens, GDB
6929will print a message like this:
6930
6931     No symbol "foo" in current context.
6932
6933   To solve such problems, either recompile without optimizations, or
6934use a different debug info format, if the compiler supports several such
6935formats.  *Note Compilation::, for more information on choosing compiler
6936options.  *Note C and C++: C, for more information about debug info
6937formats that are best suited to C++ programs.
6938
6939   If you ask to print an object whose contents are unknown to GDB,
6940e.g., because its data type is not completely specified by the debug
6941information, GDB will say `<incomplete type>'.  *Note incomplete type:
6942Symbols, for more about this.
6943
6944   If you append `@entry' string to a function parameter name you get
6945its value at the time the function got called.  If the value is not
6946available an error message is printed.  Entry values are available only
6947with some compilers.  Entry values are normally also printed at the
6948function parameter list according to *note set print entry-values::.
6949
6950     Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
6951     29	  i++;
6952     (gdb) next
6953     30	  e (i);
6954     (gdb) print i
6955     $1 = 31
6956     (gdb) print i@entry
6957     $2 = 30
6958
6959   Strings are identified as arrays of `char' values without specified
6960signedness.  Arrays of either `signed char' or `unsigned char' get
6961printed as arrays of 1 byte sized integers.  `-fsigned-char' or
6962`-funsigned-char' GCC options have no effect as GDB defines literal
6963string type `"char"' as `char' without a sign.  For program code
6964
6965     char var0[] = "A";
6966     signed char var1[] = "A";
6967
6968   You get during debugging
6969     (gdb) print var0
6970     $1 = "A"
6971     (gdb) print var1
6972     $2 = {65 'A', 0 '\0'}
6973
6974
6975File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
6976
697710.4 Artificial Arrays
6978======================
6979
6980It is often useful to print out several successive objects of the same
6981type in memory; a section of an array, or an array of dynamically
6982determined size for which only a pointer exists in the program.
6983
6984   You can do this by referring to a contiguous span of memory as an
6985"artificial array", using the binary operator `@'.  The left operand of
6986`@' should be the first element of the desired array and be an
6987individual object.  The right operand should be the desired length of
6988the array.  The result is an array value whose elements are all of the
6989type of the left argument.  The first element is actually the left
6990argument; the second element comes from bytes of memory immediately
6991following those that hold the first element, and so on.  Here is an
6992example.  If a program says
6993
6994     int *array = (int *) malloc (len * sizeof (int));
6995
6996you can print the contents of `array' with
6997
6998     p *array@len
6999
7000   The left operand of `@' must reside in memory.  Array values made
7001with `@' in this way behave just like other arrays in terms of
7002subscripting, and are coerced to pointers when used in expressions.
7003Artificial arrays most often appear in expressions via the value history
7004(*note Value History: Value History.), after printing one out.
7005
7006   Another way to create an artificial array is to use a cast.  This
7007re-interprets a value as if it were an array.  The value need not be in
7008memory:
7009     (gdb) p/x (short[2])0x12345678
7010     $1 = {0x1234, 0x5678}
7011
7012   As a convenience, if you leave the array length out (as in
7013`(TYPE[])VALUE') GDB calculates the size to fill the value (as
7014`sizeof(VALUE)/sizeof(TYPE)':
7015     (gdb) p/x (short[])0x12345678
7016     $2 = {0x1234, 0x5678}
7017
7018   Sometimes the artificial array mechanism is not quite enough; in
7019moderately complex data structures, the elements of interest may not
7020actually be adjacent--for example, if you are interested in the values
7021of pointers in an array.  One useful work-around in this situation is
7022to use a convenience variable (*note Convenience Variables: Convenience
7023Vars.) as a counter in an expression that prints the first interesting
7024value, and then repeat that expression via <RET>.  For instance,
7025suppose you have an array `dtab' of pointers to structures, and you are
7026interested in the values of a field `fv' in each structure.  Here is an
7027example of what you might type:
7028
7029     set $i = 0
7030     p dtab[$i++]->fv
7031     <RET>
7032     <RET>
7033     ...
7034
7035
7036File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
7037
703810.5 Output Formats
7039===================
7040
7041By default, GDB prints a value according to its data type.  Sometimes
7042this is not what you want.  For example, you might want to print a
7043number in hex, or a pointer in decimal.  Or you might want to view data
7044in memory at a certain address as a character string or as an
7045instruction.  To do these things, specify an "output format" when you
7046print a value.
7047
7048   The simplest use of output formats is to say how to print a value
7049already computed.  This is done by starting the arguments of the
7050`print' command with a slash and a format letter.  The format letters
7051supported are:
7052
7053`x'
7054     Regard the bits of the value as an integer, and print the integer
7055     in hexadecimal.
7056
7057`d'
7058     Print as integer in signed decimal.
7059
7060`u'
7061     Print as integer in unsigned decimal.
7062
7063`o'
7064     Print as integer in octal.
7065
7066`t'
7067     Print as integer in binary.  The letter `t' stands for "two".  (1)
7068
7069`a'
7070     Print as an address, both absolute in hexadecimal and as an offset
7071     from the nearest preceding symbol.  You can use this format used
7072     to discover where (in what function) an unknown address is located:
7073
7074          (gdb) p/a 0x54320
7075          $3 = 0x54320 <_initialize_vx+396>
7076
7077     The command `info symbol 0x54320' yields similar results.  *Note
7078     info symbol: Symbols.
7079
7080`c'
7081     Regard as an integer and print it as a character constant.  This
7082     prints both the numerical value and its character representation.
7083     The character representation is replaced with the octal escape
7084     `\nnn' for characters outside the 7-bit ASCII range.
7085
7086     Without this format, GDB displays `char', `unsigned char', and
7087     `signed char' data as character constants.  Single-byte members of
7088     vectors are displayed as integer data.
7089
7090`f'
7091     Regard the bits of the value as a floating point number and print
7092     using typical floating point syntax.
7093
7094`s'
7095     Regard as a string, if possible.  With this format, pointers to
7096     single-byte data are displayed as null-terminated strings and
7097     arrays of single-byte data are displayed as fixed-length strings.
7098     Other values are displayed in their natural types.
7099
7100     Without this format, GDB displays pointers to and arrays of
7101     `char', `unsigned char', and `signed char' as strings.
7102     Single-byte members of a vector are displayed as an integer array.
7103
7104`r'
7105     Print using the `raw' formatting.  By default, GDB will use a
7106     Python-based pretty-printer, if one is available (*note Pretty
7107     Printing::).  This typically results in a higher-level display of
7108     the value's contents.  The `r' format bypasses any Python
7109     pretty-printer which might exist.
7110
7111   For example, to print the program counter in hex (*note
7112Registers::), type
7113
7114     p/x $pc
7115
7116Note that no space is required before the slash; this is because command
7117names in GDB cannot contain a slash.
7118
7119   To reprint the last value in the value history with a different
7120format, you can use the `print' command with just a format and no
7121expression.  For example, `p/x' reprints the last value in hex.
7122
7123   ---------- Footnotes ----------
7124
7125   (1) `b' cannot be used because these format letters are also used
7126with the `x' command, where `b' stands for "byte"; see *note Examining
7127Memory: Memory.
7128
7129