1 This is gdb.info, produced by makeinfo version 4.6 from ./gdb.texinfo.
3 INFO-DIR-SECTION Software development
5 * Gdb: (gdb). The GNU debugger.
8 This file documents the GNU debugger GDB.
10 This is the Ninth Edition, of `Debugging with GDB: the GNU
11 Source-Level Debugger' for GDB Version 6.1.1.
13 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
15 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
17 Permission is granted to copy, distribute and/or modify this document
18 under the terms of the GNU Free Documentation License, Version 1.1 or
19 any later version published by the Free Software Foundation; with the
20 Invariant Sections being "Free Software" and "Free Software Needs Free
21 Documentation", with the Front-Cover Texts being "A GNU Manual," and
22 with the Back-Cover Texts as in (a) below.
24 (a) The Free Software Foundation's Back-Cover Text is: "You have
25 freedom to copy and modify this GNU Manual, like GNU software. Copies
26 published by the Free Software Foundation raise funds for GNU
30 File: gdb.info, Node: Top, Next: Summary, Prev: (dir), Up: (dir)
35 This file describes GDB, the GNU symbolic debugger.
37 This is the Ninth Edition, for GDB Version 6.1.1.
39 Copyright (C) 1988-2004 Free Software Foundation, Inc.
43 * Summary:: Summary of GDB
44 * Sample Session:: A sample GDB session
46 * Invocation:: Getting in and out of GDB
47 * Commands:: GDB commands
48 * Running:: Running programs under GDB
49 * Stopping:: Stopping and continuing
50 * Stack:: Examining the stack
51 * Source:: Examining source files
52 * Data:: Examining data
53 * Macros:: Preprocessor Macros
54 * Tracepoints:: Debugging remote targets non-intrusively
55 * Overlays:: Debugging programs that use overlays
57 * Languages:: Using GDB with different languages
59 * Symbols:: Examining the symbol table
60 * Altering:: Altering execution
61 * GDB Files:: GDB files
62 * Targets:: Specifying a debugging target
63 * Remote Debugging:: Debugging remote programs
64 * Configurations:: Configuration-specific information
65 * Controlling GDB:: Controlling GDB
66 * Sequences:: Canned sequences of commands
67 * TUI:: GDB Text User Interface
68 * Interpreters:: Command Interpreters
69 * Emacs:: Using GDB under GNU Emacs
70 * Annotations:: GDB's annotation interface.
71 * GDB/MI:: GDB's Machine Interface.
73 * GDB Bugs:: Reporting bugs in GDB
74 * Formatting Documentation:: How to format and print GDB documentation
76 * Command Line Editing:: Command Line Editing
77 * Using History Interactively:: Using History Interactively
78 * Installing GDB:: Installing GDB
79 * Maintenance Commands:: Maintenance Commands
80 * Remote Protocol:: GDB Remote Serial Protocol
81 * Agent Expressions:: The GDB Agent Expression Mechanism
82 * Copying:: GNU General Public License says
83 how you can copy and share GDB
84 * GNU Free Documentation License:: The license for this documentation
88 File: gdb.info, Node: Summary, Next: Sample Session, Prev: Top, Up: Top
93 The purpose of a debugger such as GDB is to allow you to see what is
94 going on "inside" another program while it executes--or what another
95 program was doing at the moment it crashed.
97 GDB can do four main kinds of things (plus other things in support of
98 these) to help you catch bugs in the act:
100 * Start your program, specifying anything that might affect its
103 * Make your program stop on specified conditions.
105 * Examine what has happened, when your program has stopped.
107 * Change things in your program, so you can experiment with
108 correcting the effects of one bug and go on to learn about another.
110 You can use GDB to debug programs written in C and C++. For more
111 information, see *Note Supported languages: Support. For more
112 information, see *Note C and C++: C.
114 Support for Modula-2 is partial. For information on Modula-2, see
115 *Note Modula-2: Modula-2.
117 Debugging Pascal programs which use sets, subranges, file variables,
118 or nested functions does not currently work. GDB does not support
119 entering expressions, printing values, or similar features using Pascal
122 GDB can be used to debug programs written in Fortran, although it
123 may be necessary to refer to some variables with a trailing underscore.
125 GDB can be used to debug programs written in Objective-C, using
126 either the Apple/NeXT or the GNU Objective-C runtime.
130 * Free Software:: Freely redistributable software
131 * Contributors:: Contributors to GDB
134 File: gdb.info, Node: Free Software, Next: Contributors, Up: Summary
139 GDB is "free software", protected by the GNU General Public License
140 (GPL). The GPL gives you the freedom to copy or adapt a licensed
141 program--but every person getting a copy also gets with it the freedom
142 to modify that copy (which means that they must get access to the
143 source code), and the freedom to distribute further copies. Typical
144 software companies use copyrights to limit your freedoms; the Free
145 Software Foundation uses the GPL to preserve these freedoms.
147 Fundamentally, the General Public License is a license which says
148 that you have these freedoms and that you cannot take these freedoms
149 away from anyone else.
151 Free Software Needs Free Documentation
152 ======================================
154 The biggest deficiency in the free software community today is not in
155 the software--it is the lack of good free documentation that we can
156 include with the free software. Many of our most important programs do
157 not come with free reference manuals and free introductory texts.
158 Documentation is an essential part of any software package; when an
159 important free software package does not come with a free manual and a
160 free tutorial, that is a major gap. We have many such gaps today.
162 Consider Perl, for instance. The tutorial manuals that people
163 normally use are non-free. How did this come about? Because the
164 authors of those manuals published them with restrictive terms--no
165 copying, no modification, source files not available--which exclude
166 them from the free software world.
168 That wasn't the first time this sort of thing happened, and it was
169 far from the last. Many times we have heard a GNU user eagerly
170 describe a manual that he is writing, his intended contribution to the
171 community, only to learn that he had ruined everything by signing a
172 publication contract to make it non-free.
174 Free documentation, like free software, is a matter of freedom, not
175 price. The problem with the non-free manual is not that publishers
176 charge a price for printed copies--that in itself is fine. (The Free
177 Software Foundation sells printed copies of manuals, too.) The problem
178 is the restrictions on the use of the manual. Free manuals are
179 available in source code form, and give you permission to copy and
180 modify. Non-free manuals do not allow this.
182 The criteria of freedom for a free manual are roughly the same as for
183 free software. Redistribution (including the normal kinds of
184 commercial redistribution) must be permitted, so that the manual can
185 accompany every copy of the program, both on-line and on paper.
187 Permission for modification of the technical content is crucial too.
188 When people modify the software, adding or changing features, if they
189 are conscientious they will change the manual too--so they can provide
190 accurate and clear documentation for the modified program. A manual
191 that leaves you no choice but to write a new manual to document a
192 changed version of the program is not really available to our community.
194 Some kinds of limits on the way modification is handled are
195 acceptable. For example, requirements to preserve the original
196 author's copyright notice, the distribution terms, or the list of
197 authors, are ok. It is also no problem to require modified versions to
198 include notice that they were modified. Even entire sections that may
199 not be deleted or changed are acceptable, as long as they deal with
200 nontechnical topics (like this one). These kinds of restrictions are
201 acceptable because they don't obstruct the community's normal use of
204 However, it must be possible to modify all the _technical_ content
205 of the manual, and then distribute the result in all the usual media,
206 through all the usual channels. Otherwise, the restrictions obstruct
207 the use of the manual, it is not free, and we need another manual to
210 Please spread the word about this issue. Our community continues to
211 lose manuals to proprietary publishing. If we spread the word that
212 free software needs free reference manuals and free tutorials, perhaps
213 the next person who wants to contribute by writing documentation will
214 realize, before it is too late, that only free manuals contribute to
215 the free software community.
217 If you are writing documentation, please insist on publishing it
218 under the GNU Free Documentation License or another free documentation
219 license. Remember that this decision requires your approval--you don't
220 have to let the publisher decide. Some commercial publishers will use
221 a free license if you insist, but they will not propose the option; it
222 is up to you to raise the issue and say firmly that this is what you
223 want. If the publisher you are dealing with refuses, please try other
224 publishers. If you're not sure whether a proposed license is free,
225 write to <licensing@gnu.org>.
227 You can encourage commercial publishers to sell more free, copylefted
228 manuals and tutorials by buying them, and particularly by buying copies
229 from the publishers that paid for their writing or for major
230 improvements. Meanwhile, try to avoid buying non-free documentation at
231 all. Check the distribution terms of a manual before you buy it, and
232 insist that whoever seeks your business must respect your freedom.
233 Check the history of the book, and try to reward the publishers that
234 have paid or pay the authors to work on it.
236 The Free Software Foundation maintains a list of free documentation
237 published by other publishers, at
238 <http://www.fsf.org/doc/other-free-books.html>.
241 File: gdb.info, Node: Contributors, Prev: Free Software, Up: Summary
246 Richard Stallman was the original author of GDB, and of many other GNU
247 programs. Many others have contributed to its development. This
248 section attempts to credit major contributors. One of the virtues of
249 free software is that everyone is free to contribute to it; with
250 regret, we cannot actually acknowledge everyone here. The file
251 `ChangeLog' in the GDB distribution approximates a blow-by-blow account.
253 Changes much prior to version 2.0 are lost in the mists of time.
255 _Plea:_ Additions to this section are particularly welcome. If you
256 or your friends (or enemies, to be evenhanded) have been unfairly
257 omitted from this list, we would like to add your names!
259 So that they may not regard their many labors as thankless, we
260 particularly thank those who shepherded GDB through major releases:
261 Andrew Cagney (releases 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim Blandy
262 (release 4.18); Jason Molenda (release 4.17); Stan Shebs (release 4.14);
263 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9); Stu
264 Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4); John
265 Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases
266 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2, 3.1, and 3.0).
268 Richard Stallman, assisted at various times by Peter TerMaat, Chris
269 Hanson, and Richard Mlynarik, handled releases through 2.8.
271 Michael Tiemann is the author of most of the GNU C++ support in GDB,
272 with significant additional contributions from Per Bothner and Daniel
273 Berlin. James Clark wrote the GNU C++ demangler. Early work on C++
274 was by Peter TerMaat (who also did much general update work leading to
277 GDB uses the BFD subroutine library to examine multiple object-file
278 formats; BFD was a joint project of David V. Henkel-Wallace, Rich
279 Pixley, Steve Chamberlain, and John Gilmore.
281 David Johnson wrote the original COFF support; Pace Willison did the
282 original support for encapsulated COFF.
284 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
286 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
287 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
288 support. Jean-Daniel Fekete contributed Sun 386i support. Chris
289 Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki
290 Hasei contributed Sony/News OS 3 support. David Johnson contributed
291 Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support.
292 Jeff Law contributed HP PA and SOM support. Keith Packard contributed
293 NS32K support. Doug Rabson contributed Acorn Risc Machine support.
294 Bob Rusk contributed Harris Nighthawk CX-UX support. Chris Smith
295 contributed Convex support (and Fortran debugging). Jonathan Stone
296 contributed Pyramid support. Michael Tiemann contributed SPARC support.
297 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
298 Pace Willison contributed Intel 386 support. Jay Vosburgh contributed
299 Symmetry support. Marko Mlinar contributed OpenRISC 1000 support.
301 Andreas Schwab contributed M68K GNU/Linux support.
303 Rich Schaefer and Peter Schauer helped with support of SunOS shared
306 Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
307 several machine instruction sets.
309 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
310 develop remote debugging. Intel Corporation, Wind River Systems, AMD,
311 and ARM contributed remote debugging modules for the i960, VxWorks,
312 A29K UDI, and RDI targets, respectively.
314 Brian Fox is the author of the readline libraries providing
315 command-line editing and command history.
317 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
318 Modula-2 support, and contributed the Languages chapter of this manual.
320 Fred Fish wrote most of the support for Unix System Vr4. He also
321 enhanced the command-completion support to cover C++ overloaded symbols.
323 Hitachi America (now Renesas America), Ltd. sponsored the support for
324 H8/300, H8/500, and Super-H processors.
326 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx
329 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and
332 Toshiba sponsored the support for the TX39 Mips processor.
334 Matsushita sponsored the support for the MN10200 and MN10300
337 Fujitsu sponsored the support for SPARClite and FR30 processors.
339 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
342 Michael Snyder added support for tracepoints.
344 Stu Grossman wrote gdbserver.
346 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly
347 innumerable bug fixes and cleanups throughout GDB.
349 The following people at the Hewlett-Packard Company contributed
350 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
351 (narrow mode), HP's implementation of kernel threads, HP's aC++
352 compiler, and the Text User Interface (nee Terminal User Interface):
353 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
354 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
355 provided HP-specific information in this manual.
357 DJ Delorie ported GDB to MS-DOS, for the DJGPP project. Robert
358 Hoehne made significant contributions to the DJGPP port.
360 Cygnus Solutions has sponsored GDB maintenance and much of its
361 development since 1991. Cygnus engineers who have worked on GDB
362 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
363 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
364 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
365 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
366 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
367 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
368 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
369 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
370 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
371 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
372 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
373 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
374 Zuhn have made contributions both large and small.
376 Jim Blandy added support for preprocessor macros, while working for
380 File: gdb.info, Node: Sample Session, Next: Invocation, Prev: Summary, Up: Top
385 You can use this manual at your leisure to read all about GDB.
386 However, a handful of commands are enough to get started using the
387 debugger. This chapter illustrates those commands.
389 One of the preliminary versions of GNU `m4' (a generic macro
390 processor) exhibits the following bug: sometimes, when we change its
391 quote strings from the default, the commands used to capture one macro
392 definition within another stop working. In the following short `m4'
393 session, we define a macro `foo' which expands to `0000'; we then use
394 the `m4' built-in `defn' to define `bar' as the same thing. However,
395 when we change the open quote string to `<QUOTE>' and the close quote
396 string to `<UNQUOTE>', the same procedure fails to define a new synonym
405 define(bar,defn(`foo'))
409 changequote(<QUOTE>,<UNQUOTE>)
411 define(baz,defn(<QUOTE>foo<UNQUOTE>))
414 m4: End of input: 0: fatal error: EOF in string
416 Let us use GDB to try to see what is going on.
419 GDB is free software and you are welcome to distribute copies
420 of it under certain conditions; type "show copying" to see
422 There is absolutely no warranty for GDB; type "show warranty"
425 GDB 6.1.1, Copyright 1999 Free Software Foundation, Inc...
428 GDB reads only enough symbol data to know where to find the rest when
429 needed; as a result, the first prompt comes up very quickly. We now
430 tell GDB to use a narrower display width than usual, so that examples
435 We need to see how the `m4' built-in `changequote' works. Having
436 looked at the source, we know the relevant subroutine is
437 `m4_changequote', so we set a breakpoint there with the GDB `break'
440 (gdb) break m4_changequote
441 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
443 Using the `run' command, we start `m4' running under GDB control; as
444 long as control does not reach the `m4_changequote' subroutine, the
445 program runs as usual:
448 Starting program: /work/Editorial/gdb/gnu/m4/m4
454 To trigger the breakpoint, we call `changequote'. GDB suspends
455 execution of `m4', displaying information about the context where it
458 changequote(<QUOTE>,<UNQUOTE>)
460 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
462 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
464 Now we use the command `n' (`next') to advance execution to the next
465 line of the current function.
468 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
471 `set_quotes' looks like a promising subroutine. We can go into it by
472 using the command `s' (`step') instead of `next'. `step' goes to the
473 next line to be executed in _any_ subroutine, so it steps into
477 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
479 530 if (lquote != def_lquote)
481 The display that shows the subroutine where `m4' is now suspended (and
482 its arguments) is called a stack frame display. It shows a summary of
483 the stack. We can use the `backtrace' command (which can also be
484 spelled `bt'), to see where we are in the stack as a whole: the
485 `backtrace' command displays a stack frame for each active subroutine.
488 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
490 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
492 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
493 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
495 #4 0x79dc in expand_input () at macro.c:40
496 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
498 We step through a few more lines to see what happens. The first two
499 times, we can use `s'; the next two times we use `n' to avoid falling
500 into the `xstrdup' subroutine.
503 0x3b5c 532 if (rquote != def_rquote)
505 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
506 def_lquote : xstrdup(lq);
508 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
511 538 len_lquote = strlen(rquote);
513 The last line displayed looks a little odd; we can examine the variables
514 `lquote' and `rquote' to see if they are in fact the new left and right
515 quotes we specified. We use the command `p' (`print') to see their
519 $1 = 0x35d40 "<QUOTE>"
521 $2 = 0x35d50 "<UNQUOTE>"
523 `lquote' and `rquote' are indeed the new left and right quotes. To
524 look at some context, we can display ten lines of source surrounding
525 the current line with the `l' (`list') command.
530 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
532 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
535 538 len_lquote = strlen(rquote);
536 539 len_rquote = strlen(lquote);
541 Let us step past the two lines that set `len_lquote' and `len_rquote',
542 and then examine the values of those variables.
545 539 len_rquote = strlen(lquote);
553 That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
554 meant to be the lengths of `lquote' and `rquote' respectively. We can
555 set them to better values using the `p' command, since it can print the
556 value of any expression--and that expression can include subroutine
557 calls and assignments.
559 (gdb) p len_lquote=strlen(lquote)
561 (gdb) p len_rquote=strlen(rquote)
564 Is that enough to fix the problem of using the new quotes with the `m4'
565 built-in `defn'? We can allow `m4' to continue executing with the `c'
566 (`continue') command, and then try the example that caused trouble
572 define(baz,defn(<QUOTE>foo<UNQUOTE>))
577 Success! The new quotes now work just as well as the default ones. The
578 problem seems to have been just the two typos defining the wrong
579 lengths. We allow `m4' exit by giving it an EOF as input:
582 Program exited normally.
584 The message `Program exited normally.' is from GDB; it indicates `m4'
585 has finished executing. We can end our GDB session with the GDB `quit'
591 File: gdb.info, Node: Invocation, Next: Commands, Prev: Sample Session, Up: Top
593 Getting In and Out of GDB
594 *************************
596 This chapter discusses how to start GDB, and how to get out of it. The
598 * type `gdb' to start GDB.
600 * type `quit' or `C-d' to exit.
604 * Invoking GDB:: How to start GDB
605 * Quitting GDB:: How to quit GDB
606 * Shell Commands:: How to use shell commands inside GDB
607 * Logging output:: How to log GDB's output to a file
610 File: gdb.info, Node: Invoking GDB, Next: Quitting GDB, Up: Invocation
615 Invoke GDB by running the program `gdb'. Once started, GDB reads
616 commands from the terminal until you tell it to exit.
618 You can also run `gdb' with a variety of arguments and options, to
619 specify more of your debugging environment at the outset.
621 The command-line options described here are designed to cover a
622 variety of situations; in some environments, some of these options may
623 effectively be unavailable.
625 The most usual way to start GDB is with one argument, specifying an
630 You can also start with both an executable program and a core file
635 You can, instead, specify a process ID as a second argument, if you
636 want to debug a running process:
640 would attach GDB to process `1234' (unless you also have a file named
641 `1234'; GDB does check for a core file first).
643 Taking advantage of the second command-line argument requires a
644 fairly complete operating system; when you use GDB as a remote debugger
645 attached to a bare board, there may not be any notion of "process", and
646 there is often no way to get a core dump. GDB will warn you if it is
647 unable to attach or to read core dumps.
649 You can optionally have `gdb' pass any arguments after the
650 executable file to the inferior using `--args'. This option stops
652 gdb --args gcc -O2 -c foo.c
653 This will cause `gdb' to debug `gcc', and to set `gcc''s
654 command-line arguments (*note Arguments::) to `-O2 -c foo.c'.
656 You can run `gdb' without printing the front material, which
657 describes GDB's non-warranty, by specifying `-silent':
661 You can further control how GDB starts up by using command-line
662 options. GDB itself can remind you of the options available.
668 to display all available options and briefly describe their use (`gdb
669 -h' is a shorter equivalent).
671 All options and command line arguments you give are processed in
672 sequential order. The order makes a difference when the `-x' option is
677 * File Options:: Choosing files
678 * Mode Options:: Choosing modes
681 File: gdb.info, Node: File Options, Next: Mode Options, Up: Invoking GDB
686 When GDB starts, it reads any arguments other than options as
687 specifying an executable file and core file (or process ID). This is
688 the same as if the arguments were specified by the `-se' and `-c' (or
689 `-p' options respectively. (GDB reads the first argument that does not
690 have an associated option flag as equivalent to the `-se' option
691 followed by that argument; and the second argument that does not have
692 an associated option flag, if any, as equivalent to the `-c'/`-p'
693 option followed by that argument.) If the second argument begins with
694 a decimal digit, GDB will first attempt to attach to it as a process,
695 and if that fails, attempt to open it as a corefile. If you have a
696 corefile whose name begins with a digit, you can prevent GDB from
697 treating it as a pid by prefixing it with `./', eg. `./12345'.
699 If GDB has not been configured to included core file support, such
700 as for most embedded targets, then it will complain about a second
701 argument and ignore it.
703 Many options have both long and short forms; both are shown in the
704 following list. GDB also recognizes the long forms if you truncate
705 them, so long as enough of the option is present to be unambiguous.
706 (If you prefer, you can flag option arguments with `--' rather than
707 `-', though we illustrate the more usual convention.)
711 Read symbol table from file FILE.
715 Use file FILE as the executable file to execute when appropriate,
716 and for examining pure data in conjunction with a core dump.
719 Read symbol table from file FILE and use it as the executable file.
723 Use file FILE as a core dump to examine.
729 Connect to process ID NUMBER, as with the `attach' command. If
730 there is no such process, GDB will attempt to open a core file
735 Execute GDB commands from file FILE. *Note Command files: Command
738 `-directory DIRECTORY'
740 Add DIRECTORY to the path to search for source files.
744 _Warning: this option depends on operating system facilities that
745 are not supported on all systems._
746 If memory-mapped files are available on your system through the
747 `mmap' system call, you can use this option to have GDB write the
748 symbols from your program into a reusable file in the current
749 directory. If the program you are debugging is called
750 `/tmp/fred', the mapped symbol file is `/tmp/fred.syms'. Future
751 GDB debugging sessions notice the presence of this file, and can
752 quickly map in symbol information from it, rather than reading the
753 symbol table from the executable program.
755 The `.syms' file is specific to the host machine where GDB is run.
756 It holds an exact image of the internal GDB symbol table. It
757 cannot be shared across multiple host platforms.
761 Read each symbol file's entire symbol table immediately, rather
762 than the default, which is to read it incrementally as it is
763 needed. This makes startup slower, but makes future operations
767 You typically combine the `-mapped' and `-readnow' options in order
768 to build a `.syms' file that contains complete symbol information.
769 (*Note Commands to specify files: Files, for information on `.syms'
770 files.) A simple GDB invocation to do nothing but build a `.syms' file
773 gdb -batch -nx -mapped -readnow programname
776 File: gdb.info, Node: Mode Options, Prev: File Options, Up: Invoking GDB
781 You can run GDB in various alternative modes--for example, in batch
786 Do not execute commands found in any initialization files.
787 Normally, GDB executes the commands in these files after all the
788 command options and arguments have been processed. *Note Command
789 files: Command Files.
794 "Quiet". Do not print the introductory and copyright messages.
795 These messages are also suppressed in batch mode.
798 Run in batch mode. Exit with status `0' after processing all the
799 command files specified with `-x' (and all commands from
800 initialization files, if not inhibited with `-n'). Exit with
801 nonzero status if an error occurs in executing the GDB commands in
804 Batch mode may be useful for running GDB as a filter, for example
805 to download and run a program on another computer; in order to
806 make this more useful, the message
808 Program exited normally.
810 (which is ordinarily issued whenever a program running under GDB
811 control terminates) is not issued when running in batch mode.
815 "No windows". If GDB comes with a graphical user interface (GUI)
816 built in, then this option tells GDB to only use the command-line
817 interface. If no GUI is available, this option has no effect.
821 If GDB includes a GUI, then this option requires it to be used if
825 Run GDB using DIRECTORY as its working directory, instead of the
830 GNU Emacs sets this option when it runs GDB as a subprocess. It
831 tells GDB to output the full file name and line number in a
832 standard, recognizable fashion each time a stack frame is
833 displayed (which includes each time your program stops). This
834 recognizable format looks like two `\032' characters, followed by
835 the file name, line number and character position separated by
836 colons, and a newline. The Emacs-to-GDB interface program uses
837 the two `\032' characters as a signal to display the source code
841 The Epoch Emacs-GDB interface sets this option when it runs GDB as
842 a subprocess. It tells GDB to modify its print routines so as to
843 allow Epoch to display values of expressions in a separate window.
846 This option sets the "annotation level" inside GDB. Its effect is
847 identical to using `set annotate LEVEL' (*note Annotations::).
848 The annotation LEVEL controls how much information GDB prints
849 together with its prompt, values of expressions, source lines, and
850 other types of output. Level 0 is the normal, level 1 is for use
851 when GDB is run as a subprocess of GNU Emacs, level 3 is the
852 maximum annotation suitable for programs that control GDB, and
853 level 2 has been deprecated.
855 The annotation mechanism has largely been superseeded by GDB/MI
859 Use the asynchronous event loop for the command-line interface.
860 GDB processes all events, such as user keyboard input, via a
861 special event loop. This allows GDB to accept and process user
862 commands in parallel with the debugged process being run(1), so
863 you don't need to wait for control to return to GDB before you
864 type the next command. (_Note:_ as of version 5.1, the target
865 side of the asynchronous operation is not yet in place, so
866 `-async' does not work fully yet.)
868 When the standard input is connected to a terminal device, GDB
869 uses the asynchronous event loop by default, unless disabled by the
873 Disable the asynchronous event loop for the command-line interface.
876 Change interpretation of command line so that arguments following
877 the executable file are passed as command line arguments to the
878 inferior. This option stops option processing.
882 Set the line speed (baud rate or bits per second) of any serial
883 interface used by GDB for remote debugging.
887 Run using DEVICE for your program's standard input and output.
890 Activate the "Text User Interface" when starting. The Text User
891 Interface manages several text windows on the terminal, showing
892 source, assembly, registers and GDB command outputs (*note GDB
893 Text User Interface: TUI.). Alternatively, the Text User
894 Interface can be enabled by invoking the program `gdbtui'. Do not
895 use this option if you run GDB from Emacs (*note Using GDB under
898 `-interpreter INTERP'
899 Use the interpreter INTERP for interface with the controlling
900 program or device. This option is meant to be set by programs
901 which communicate with GDB using it as a back end. *Note Command
902 Interpreters: Interpreters.
904 `--interpreter=mi' (or `--interpreter=mi2') causes GDB to use the
905 "GDB/MI interface" (*note The GDB/MI Interface: GDB/MI.) included
906 since GDBN version 6.0. The previous GDB/MI interface, included
907 in GDB version 5.3 and selected with `--interpreter=mi1', is
908 deprecated. Earlier GDB/MI interfaces are no longer supported.
911 Open the executable and core files for both reading and writing.
912 This is equivalent to the `set write on' command inside GDB (*note
916 This option causes GDB to print statistics about time and memory
917 usage after it completes each command and returns to the prompt.
920 This option causes GDB to print its version number and no-warranty
924 ---------- Footnotes ----------
926 (1) GDB built with DJGPP tools for MS-DOS/MS-Windows supports this
927 mode of operation, but the event loop is suspended when the debuggee
931 File: gdb.info, Node: Quitting GDB, Next: Shell Commands, Prev: Invoking GDB, Up: Invocation
938 To exit GDB, use the `quit' command (abbreviated `q'), or type an
939 end-of-file character (usually `C-d'). If you do not supply
940 EXPRESSION, GDB will terminate normally; otherwise it will
941 terminate using the result of EXPRESSION as the error code.
943 An interrupt (often `C-c') does not exit from GDB, but rather
944 terminates the action of any GDB command that is in progress and
945 returns to GDB command level. It is safe to type the interrupt
946 character at any time because GDB does not allow it to take effect
947 until a time when it is safe.
949 If you have been using GDB to control an attached process or device,
950 you can release it with the `detach' command (*note Debugging an
951 already-running process: Attach.).
954 File: gdb.info, Node: Shell Commands, Next: Logging output, Prev: Quitting GDB, Up: Invocation
959 If you need to execute occasional shell commands during your debugging
960 session, there is no need to leave or suspend GDB; you can just use the
963 `shell COMMAND STRING'
964 Invoke a standard shell to execute COMMAND STRING. If it exists,
965 the environment variable `SHELL' determines which shell to run.
966 Otherwise GDB uses the default shell (`/bin/sh' on Unix systems,
967 `COMMAND.COM' on MS-DOS, etc.).
969 The utility `make' is often needed in development environments. You
970 do not have to use the `shell' command for this purpose in GDB:
973 Execute the `make' program with the specified arguments. This is
974 equivalent to `shell make MAKE-ARGS'.
977 File: gdb.info, Node: Logging output, Prev: Shell Commands, Up: Invocation
982 You may want to save the output of GDB commands to a file. There are
983 several commands to control GDB's logging.
991 `set logging file FILE'
992 Change the name of the current logfile. The default logfile is
995 `set logging overwrite [on|off]'
996 By default, GDB will append to the logfile. Set `overwrite' if
997 you want `set logging on' to overwrite the logfile instead.
999 `set logging redirect [on|off]'
1000 By default, GDB output will go to both the terminal and the
1001 logfile. Set `redirect' if you want output to go only to the log
1005 Show the current values of the logging settings.
1008 File: gdb.info, Node: Commands, Next: Running, Prev: Invocation, Up: Top
1013 You can abbreviate a GDB command to the first few letters of the command
1014 name, if that abbreviation is unambiguous; and you can repeat certain
1015 GDB commands by typing just <RET>. You can also use the <TAB> key to
1016 get GDB to fill out the rest of a word in a command (or to show you the
1017 alternatives available, if there is more than one possibility).
1021 * Command Syntax:: How to give commands to GDB
1022 * Completion:: Command completion
1023 * Help:: How to ask GDB for help
1026 File: gdb.info, Node: Command Syntax, Next: Completion, Up: Commands
1031 A GDB command is a single line of input. There is no limit on how long
1032 it can be. It starts with a command name, which is followed by
1033 arguments whose meaning depends on the command name. For example, the
1034 command `step' accepts an argument which is the number of times to
1035 step, as in `step 5'. You can also use the `step' command with no
1036 arguments. Some commands do not allow any arguments.
1038 GDB command names may always be truncated if that abbreviation is
1039 unambiguous. Other possible command abbreviations are listed in the
1040 documentation for individual commands. In some cases, even ambiguous
1041 abbreviations are allowed; for example, `s' is specially defined as
1042 equivalent to `step' even though there are other commands whose names
1043 start with `s'. You can test abbreviations by using them as arguments
1044 to the `help' command.
1046 A blank line as input to GDB (typing just <RET>) means to repeat the
1047 previous command. Certain commands (for example, `run') will not
1048 repeat this way; these are commands whose unintentional repetition
1049 might cause trouble and which you are unlikely to want to repeat.
1051 The `list' and `x' commands, when you repeat them with <RET>,
1052 construct new arguments rather than repeating exactly as typed. This
1053 permits easy scanning of source or memory.
1055 GDB can also use <RET> in another way: to partition lengthy output,
1056 in a way similar to the common utility `more' (*note Screen size:
1057 Screen Size.). Since it is easy to press one <RET> too many in this
1058 situation, GDB disables command repetition after any command that
1059 generates this sort of display.
1061 Any text from a `#' to the end of the line is a comment; it does
1062 nothing. This is useful mainly in command files (*note Command files:
1065 The `C-o' binding is useful for repeating a complex sequence of
1066 commands. This command accepts the current line, like `RET', and then
1067 fetches the next line relative to the current line from the history for
1071 File: gdb.info, Node: Completion, Next: Help, Prev: Command Syntax, Up: Commands
1076 GDB can fill in the rest of a word in a command for you, if there is
1077 only one possibility; it can also show you what the valid possibilities
1078 are for the next word in a command, at any time. This works for GDB
1079 commands, GDB subcommands, and the names of symbols in your program.
1081 Press the <TAB> key whenever you want GDB to fill out the rest of a
1082 word. If there is only one possibility, GDB fills in the word, and
1083 waits for you to finish the command (or press <RET> to enter it). For
1084 example, if you type
1086 (gdb) info bre <TAB>
1088 GDB fills in the rest of the word `breakpoints', since that is the only
1089 `info' subcommand beginning with `bre':
1091 (gdb) info breakpoints
1093 You can either press <RET> at this point, to run the `info breakpoints'
1094 command, or backspace and enter something else, if `breakpoints' does
1095 not look like the command you expected. (If you were sure you wanted
1096 `info breakpoints' in the first place, you might as well just type
1097 <RET> immediately after `info bre', to exploit command abbreviations
1098 rather than command completion).
1100 If there is more than one possibility for the next word when you
1101 press <TAB>, GDB sounds a bell. You can either supply more characters
1102 and try again, or just press <TAB> a second time; GDB displays all the
1103 possible completions for that word. For example, you might want to set
1104 a breakpoint on a subroutine whose name begins with `make_', but when
1105 you type `b make_<TAB>' GDB just sounds the bell. Typing <TAB> again
1106 displays all the function names in your program that begin with those
1107 characters, for example:
1110 GDB sounds bell; press <TAB> again, to see:
1111 make_a_section_from_file make_environ
1112 make_abs_section make_function_type
1113 make_blockvector make_pointer_type
1114 make_cleanup make_reference_type
1115 make_command make_symbol_completion_list
1118 After displaying the available possibilities, GDB copies your partial
1119 input (`b make_' in the example) so you can finish the command.
1121 If you just want to see the list of alternatives in the first place,
1122 you can press `M-?' rather than pressing <TAB> twice. `M-?' means
1123 `<META> ?'. You can type this either by holding down a key designated
1124 as the <META> shift on your keyboard (if there is one) while typing
1125 `?', or as <ESC> followed by `?'.
1127 Sometimes the string you need, while logically a "word", may contain
1128 parentheses or other characters that GDB normally excludes from its
1129 notion of a word. To permit word completion to work in this situation,
1130 you may enclose words in `'' (single quote marks) in GDB commands.
1132 The most likely situation where you might need this is in typing the
1133 name of a C++ function. This is because C++ allows function
1134 overloading (multiple definitions of the same function, distinguished
1135 by argument type). For example, when you want to set a breakpoint you
1136 may need to distinguish whether you mean the version of `name' that
1137 takes an `int' parameter, `name(int)', or the version that takes a
1138 `float' parameter, `name(float)'. To use the word-completion
1139 facilities in this situation, type a single quote `'' at the beginning
1140 of the function name. This alerts GDB that it may need to consider
1141 more information than usual when you press <TAB> or `M-?' to request
1144 (gdb) b 'bubble( M-?
1145 bubble(double,double) bubble(int,int)
1148 In some cases, GDB can tell that completing a name requires using
1149 quotes. When this happens, GDB inserts the quote for you (while
1150 completing as much as it can) if you do not type the quote in the first
1154 GDB alters your input line to the following, and rings a bell:
1157 In general, GDB can tell that a quote is needed (and inserts it) if you
1158 have not yet started typing the argument list when you ask for
1159 completion on an overloaded symbol.
1161 For more information about overloaded functions, see *Note C++
1162 expressions: C plus plus expressions. You can use the command `set
1163 overload-resolution off' to disable overload resolution; see *Note GDB
1164 features for C++: Debugging C plus plus.
1167 File: gdb.info, Node: Help, Prev: Completion, Up: Commands
1172 You can always ask GDB itself for information on its commands, using
1177 You can use `help' (abbreviated `h') with no arguments to display
1178 a short list of named classes of commands:
1181 List of classes of commands:
1183 aliases -- Aliases of other commands
1184 breakpoints -- Making program stop at certain points
1185 data -- Examining data
1186 files -- Specifying and examining files
1187 internals -- Maintenance commands
1188 obscure -- Obscure features
1189 running -- Running the program
1190 stack -- Examining the stack
1191 status -- Status inquiries
1192 support -- Support facilities
1193 tracepoints -- Tracing of program execution without
1195 stopping the program
1196 user-defined -- User-defined commands
1198 Type "help" followed by a class name for a list of
1199 commands in that class.
1200 Type "help" followed by command name for full
1202 Command name abbreviations are allowed if unambiguous.
1206 Using one of the general help classes as an argument, you can get a
1207 list of the individual commands in that class. For example, here
1208 is the help display for the class `status':
1215 info -- Generic command for showing things
1216 about the program being debugged
1217 show -- Generic command for showing things
1220 Type "help" followed by command name for full
1222 Command name abbreviations are allowed if unambiguous.
1226 With a command name as `help' argument, GDB displays a short
1227 paragraph on how to use that command.
1230 The `apropos ARGS' command searches through all of the GDB
1231 commands, and their documentation, for the regular expression
1232 specified in ARGS. It prints out all matches found. For example:
1238 set symbol-reloading -- Set dynamic symbol table reloading
1239 multiple times in one run
1240 show symbol-reloading -- Show dynamic symbol table reloading
1241 multiple times in one run
1244 The `complete ARGS' command lists all the possible completions for
1245 the beginning of a command. Use ARGS to specify the beginning of
1246 the command you want completed. For example:
1257 This is intended for use by GNU Emacs.
1259 In addition to `help', you can use the GDB commands `info' and
1260 `show' to inquire about the state of your program, or the state of GDB
1261 itself. Each command supports many topics of inquiry; this manual
1262 introduces each of them in the appropriate context. The listings under
1263 `info' and under `show' in the Index point to all the sub-commands.
1267 This command (abbreviated `i') is for describing the state of your
1268 program. For example, you can list the arguments given to your
1269 program with `info args', list the registers currently in use with
1270 `info registers', or list the breakpoints you have set with `info
1271 breakpoints'. You can get a complete list of the `info'
1272 sub-commands with `help info'.
1275 You can assign the result of an expression to an environment
1276 variable with `set'. For example, you can set the GDB prompt to a
1277 $-sign with `set prompt $'.
1280 In contrast to `info', `show' is for describing the state of GDB
1281 itself. You can change most of the things you can `show', by
1282 using the related command `set'; for example, you can control what
1283 number system is used for displays with `set radix', or simply
1284 inquire which is currently in use with `show radix'.
1286 To display all the settable parameters and their current values,
1287 you can use `show' with no arguments; you may also use `info set'.
1288 Both commands produce the same display.
1290 Here are three miscellaneous `show' subcommands, all of which are
1291 exceptional in lacking corresponding `set' commands:
1294 Show what version of GDB is running. You should include this
1295 information in GDB bug-reports. If multiple versions of GDB are
1296 in use at your site, you may need to determine which version of
1297 GDB you are running; as GDB evolves, new commands are introduced,
1298 and old ones may wither away. Also, many system vendors ship
1299 variant versions of GDB, and there are variant versions of GDB in
1300 GNU/Linux distributions as well. The version number is the same
1301 as the one announced when you start GDB.
1304 Display information about permission for copying GDB.
1307 Display the GNU "NO WARRANTY" statement, or a warranty, if your
1308 version of GDB comes with one.
1312 File: gdb.info, Node: Running, Next: Stopping, Prev: Commands, Up: Top
1314 Running Programs Under GDB
1315 **************************
1317 When you run a program under GDB, you must first generate debugging
1318 information when you compile it.
1320 You may start GDB with its arguments, if any, in an environment of
1321 your choice. If you are doing native debugging, you may redirect your
1322 program's input and output, debug an already running process, or kill a
1327 * Compilation:: Compiling for debugging
1328 * Starting:: Starting your program
1329 * Arguments:: Your program's arguments
1330 * Environment:: Your program's environment
1332 * Working Directory:: Your program's working directory
1333 * Input/Output:: Your program's input and output
1334 * Attach:: Debugging an already-running process
1335 * Kill Process:: Killing the child process
1337 * Threads:: Debugging programs with multiple threads
1338 * Processes:: Debugging programs with multiple processes
1341 File: gdb.info, Node: Compilation, Next: Starting, Up: Running
1343 Compiling for debugging
1344 =======================
1346 In order to debug a program effectively, you need to generate debugging
1347 information when you compile it. This debugging information is stored
1348 in the object file; it describes the data type of each variable or
1349 function and the correspondence between source line numbers and
1350 addresses in the executable code.
1352 To request debugging information, specify the `-g' option when you
1355 Most compilers do not include information about preprocessor macros
1356 in the debugging information if you specify the `-g' flag alone,
1357 because this information is rather large. Version 3.1 of GCC, the GNU
1358 C compiler, provides macro information if you specify the options
1359 `-gdwarf-2' and `-g3'; the former option requests debugging information
1360 in the Dwarf 2 format, and the latter requests "extra information". In
1361 the future, we hope to find more compact ways to represent macro
1362 information, so that it can be included with `-g' alone.
1364 Many C compilers are unable to handle the `-g' and `-O' options
1365 together. Using those compilers, you cannot generate optimized
1366 executables containing debugging information.
1368 GCC, the GNU C compiler, supports `-g' with or without `-O', making
1369 it possible to debug optimized code. We recommend that you _always_
1370 use `-g' whenever you compile a program. You may think your program is
1371 correct, but there is no sense in pushing your luck.
1373 When you debug a program compiled with `-g -O', remember that the
1374 optimizer is rearranging your code; the debugger shows you what is
1375 really there. Do not be too surprised when the execution path does not
1376 exactly match your source file! An extreme example: if you define a
1377 variable, but never use it, GDB never sees that variable--because the
1378 compiler optimizes it out of existence.
1380 Some things do not work as well with `-g -O' as with just `-g',
1381 particularly on machines with instruction scheduling. If in doubt,
1382 recompile with `-g' alone, and if this fixes the problem, please report
1383 it to us as a bug (including a test case!).
1385 Older versions of the GNU C compiler permitted a variant option
1386 `-gg' for debugging information. GDB no longer supports this format;
1387 if your GNU C compiler has this option, do not use it.
1390 File: gdb.info, Node: Starting, Next: Arguments, Prev: Compilation, Up: Running
1392 Starting your program
1393 =====================
1397 Use the `run' command to start your program under GDB. You must
1398 first specify the program name (except on VxWorks) with an
1399 argument to GDB (*note Getting In and Out of GDB: Invocation.), or
1400 by using the `file' or `exec-file' command (*note Commands to
1401 specify files: Files.).
1404 If you are running your program in an execution environment that
1405 supports processes, `run' creates an inferior process and makes that
1406 process run your program. (In environments without processes, `run'
1407 jumps to the start of your program.)
1409 The execution of a program is affected by certain information it
1410 receives from its superior. GDB provides ways to specify this
1411 information, which you must do _before_ starting your program. (You
1412 can change it after starting your program, but such changes only affect
1413 your program the next time you start it.) This information may be
1414 divided into four categories:
1417 Specify the arguments to give your program as the arguments of the
1418 `run' command. If a shell is available on your target, the shell
1419 is used to pass the arguments, so that you may use normal
1420 conventions (such as wildcard expansion or variable substitution)
1421 in describing the arguments. In Unix systems, you can control
1422 which shell is used with the `SHELL' environment variable. *Note
1423 Your program's arguments: Arguments.
1426 Your program normally inherits its environment from GDB, but you
1427 can use the GDB commands `set environment' and `unset environment'
1428 to change parts of the environment that affect your program.
1429 *Note Your program's environment: Environment.
1431 The _working directory._
1432 Your program inherits its working directory from GDB. You can set
1433 the GDB working directory with the `cd' command in GDB. *Note
1434 Your program's working directory: Working Directory.
1436 The _standard input and output._
1437 Your program normally uses the same device for standard input and
1438 standard output as GDB is using. You can redirect input and output
1439 in the `run' command line, or you can use the `tty' command to set
1440 a different device for your program. *Note Your program's input
1441 and output: Input/Output.
1443 _Warning:_ While input and output redirection work, you cannot use
1444 pipes to pass the output of the program you are debugging to
1445 another program; if you attempt this, GDB is likely to wind up
1446 debugging the wrong program.
1448 When you issue the `run' command, your program begins to execute
1449 immediately. *Note Stopping and continuing: Stopping, for discussion
1450 of how to arrange for your program to stop. Once your program has
1451 stopped, you may call functions in your program, using the `print' or
1452 `call' commands. *Note Examining Data: Data.
1454 If the modification time of your symbol file has changed since the
1455 last time GDB read its symbols, GDB discards its symbol table, and
1456 reads it again. When it does this, GDB tries to retain your current
1460 File: gdb.info, Node: Arguments, Next: Environment, Prev: Starting, Up: Running
1462 Your program's arguments
1463 ========================
1465 The arguments to your program can be specified by the arguments of the
1466 `run' command. They are passed to a shell, which expands wildcard
1467 characters and performs redirection of I/O, and thence to your program.
1468 Your `SHELL' environment variable (if it exists) specifies what shell
1469 GDB uses. If you do not define `SHELL', GDB uses the default shell
1470 (`/bin/sh' on Unix).
1472 On non-Unix systems, the program is usually invoked directly by GDB,
1473 which emulates I/O redirection via the appropriate system calls, and
1474 the wildcard characters are expanded by the startup code of the
1475 program, not by the shell.
1477 `run' with no arguments uses the same arguments used by the previous
1478 `run', or those set by the `set args' command.
1481 Specify the arguments to be used the next time your program is
1482 run. If `set args' has no arguments, `run' executes your program
1483 with no arguments. Once you have run your program with arguments,
1484 using `set args' before the next `run' is the only way to run it
1485 again without arguments.
1488 Show the arguments to give your program when it is started.
1491 File: gdb.info, Node: Environment, Next: Working Directory, Prev: Arguments, Up: Running
1493 Your program's environment
1494 ==========================
1496 The "environment" consists of a set of environment variables and their
1497 values. Environment variables conventionally record such things as
1498 your user name, your home directory, your terminal type, and your search
1499 path for programs to run. Usually you set up environment variables with
1500 the shell and they are inherited by all the other programs you run.
1501 When debugging, it can be useful to try running your program with a
1502 modified environment without having to start GDB over again.
1505 Add DIRECTORY to the front of the `PATH' environment variable (the
1506 search path for executables) that will be passed to your program.
1507 The value of `PATH' used by GDB does not change. You may specify
1508 several directory names, separated by whitespace or by a
1509 system-dependent separator character (`:' on Unix, `;' on MS-DOS
1510 and MS-Windows). If DIRECTORY is already in the path, it is moved
1511 to the front, so it is searched sooner.
1513 You can use the string `$cwd' to refer to whatever is the current
1514 working directory at the time GDB searches the path. If you use
1515 `.' instead, it refers to the directory where you executed the
1516 `path' command. GDB replaces `.' in the DIRECTORY argument (with
1517 the current path) before adding DIRECTORY to the search path.
1520 Display the list of search paths for executables (the `PATH'
1521 environment variable).
1523 `show environment [VARNAME]'
1524 Print the value of environment variable VARNAME to be given to
1525 your program when it starts. If you do not supply VARNAME, print
1526 the names and values of all environment variables to be given to
1527 your program. You can abbreviate `environment' as `env'.
1529 `set environment VARNAME [=VALUE]'
1530 Set environment variable VARNAME to VALUE. The value changes for
1531 your program only, not for GDB itself. VALUE may be any string;
1532 the values of environment variables are just strings, and any
1533 interpretation is supplied by your program itself. The VALUE
1534 parameter is optional; if it is eliminated, the variable is set to
1537 For example, this command:
1541 tells the debugged program, when subsequently run, that its user
1542 is named `foo'. (The spaces around `=' are used for clarity here;
1543 they are not actually required.)
1545 `unset environment VARNAME'
1546 Remove variable VARNAME from the environment to be passed to your
1547 program. This is different from `set env VARNAME ='; `unset
1548 environment' removes the variable from the environment, rather
1549 than assigning it an empty value.
1551 _Warning:_ On Unix systems, GDB runs your program using the shell
1552 indicated by your `SHELL' environment variable if it exists (or
1553 `/bin/sh' if not). If your `SHELL' variable names a shell that runs an
1554 initialization file--such as `.cshrc' for C-shell, or `.bashrc' for
1555 BASH--any variables you set in that file affect your program. You may
1556 wish to move setting of environment variables to files that are only
1557 run when you sign on, such as `.login' or `.profile'.
1560 File: gdb.info, Node: Working Directory, Next: Input/Output, Prev: Environment, Up: Running
1562 Your program's working directory
1563 ================================
1565 Each time you start your program with `run', it inherits its working
1566 directory from the current working directory of GDB. The GDB working
1567 directory is initially whatever it inherited from its parent process
1568 (typically the shell), but you can specify a new working directory in
1569 GDB with the `cd' command.
1571 The GDB working directory also serves as a default for the commands
1572 that specify files for GDB to operate on. *Note Commands to specify
1576 Set the GDB working directory to DIRECTORY.
1579 Print the GDB working directory.
1582 File: gdb.info, Node: Input/Output, Next: Attach, Prev: Working Directory, Up: Running
1584 Your program's input and output
1585 ===============================
1587 By default, the program you run under GDB does input and output to the
1588 same terminal that GDB uses. GDB switches the terminal to its own
1589 terminal modes to interact with you, but it records the terminal modes
1590 your program was using and switches back to them when you continue
1591 running your program.
1594 Displays information recorded by GDB about the terminal modes your
1597 You can redirect your program's input and/or output using shell
1598 redirection with the `run' command. For example,
1602 starts your program, diverting its output to the file `outfile'.
1604 Another way to specify where your program should do input and output
1605 is with the `tty' command. This command accepts a file name as
1606 argument, and causes this file to be the default for future `run'
1607 commands. It also resets the controlling terminal for the child
1608 process, for future `run' commands. For example,
1612 directs that processes started with subsequent `run' commands default
1613 to do input and output on the terminal `/dev/ttyb' and have that as
1614 their controlling terminal.
1616 An explicit redirection in `run' overrides the `tty' command's
1617 effect on the input/output device, but not its effect on the controlling
1620 When you use the `tty' command or redirect input in the `run'
1621 command, only the input _for your program_ is affected. The input for
1622 GDB still comes from your terminal.
1625 File: gdb.info, Node: Attach, Next: Kill Process, Prev: Input/Output, Up: Running
1627 Debugging an already-running process
1628 ====================================
1631 This command attaches to a running process--one that was started
1632 outside GDB. (`info files' shows your active targets.) The
1633 command takes as argument a process ID. The usual way to find out
1634 the process-id of a Unix process is with the `ps' utility, or with
1635 the `jobs -l' shell command.
1637 `attach' does not repeat if you press <RET> a second time after
1638 executing the command.
1640 To use `attach', your program must be running in an environment
1641 which supports processes; for example, `attach' does not work for
1642 programs on bare-board targets that lack an operating system. You must
1643 also have permission to send the process a signal.
1645 When you use `attach', the debugger finds the program running in the
1646 process first by looking in the current working directory, then (if the
1647 program is not found) by using the source file search path (*note
1648 Specifying source directories: Source Path.). You can also use the
1649 `file' command to load the program. *Note Commands to Specify Files:
1652 The first thing GDB does after arranging to debug the specified
1653 process is to stop it. You can examine and modify an attached process
1654 with all the GDB commands that are ordinarily available when you start
1655 processes with `run'. You can insert breakpoints; you can step and
1656 continue; you can modify storage. If you would rather the process
1657 continue running, you may use the `continue' command after attaching
1661 When you have finished debugging the attached process, you can use
1662 the `detach' command to release it from GDB control. Detaching
1663 the process continues its execution. After the `detach' command,
1664 that process and GDB become completely independent once more, and
1665 you are ready to `attach' another process or start one with `run'.
1666 `detach' does not repeat if you press <RET> again after executing
1669 If you exit GDB or use the `run' command while you have an attached
1670 process, you kill that process. By default, GDB asks for confirmation
1671 if you try to do either of these things; you can control whether or not
1672 you need to confirm by using the `set confirm' command (*note Optional
1673 warnings and messages: Messages/Warnings.).
1676 File: gdb.info, Node: Kill Process, Next: Threads, Prev: Attach, Up: Running
1678 Killing the child process
1679 =========================
1682 Kill the child process in which your program is running under GDB.
1684 This command is useful if you wish to debug a core dump instead of a
1685 running process. GDB ignores any core dump file while your program is
1688 On some operating systems, a program cannot be executed outside GDB
1689 while you have breakpoints set on it inside GDB. You can use the
1690 `kill' command in this situation to permit running your program outside
1693 The `kill' command is also useful if you wish to recompile and
1694 relink your program, since on many systems it is impossible to modify an
1695 executable file while it is running in a process. In this case, when
1696 you next type `run', GDB notices that the file has changed, and reads
1697 the symbol table again (while trying to preserve your current
1698 breakpoint settings).
1701 File: gdb.info, Node: Threads, Next: Processes, Prev: Kill Process, Up: Running
1703 Debugging programs with multiple threads
1704 ========================================
1706 In some operating systems, such as HP-UX and Solaris, a single program
1707 may have more than one "thread" of execution. The precise semantics of
1708 threads differ from one operating system to another, but in general the
1709 threads of a single program are akin to multiple processes--except that
1710 they share one address space (that is, they can all examine and modify
1711 the same variables). On the other hand, each thread has its own
1712 registers and execution stack, and perhaps private memory.
1714 GDB provides these facilities for debugging multi-thread programs:
1716 * automatic notification of new threads
1718 * `thread THREADNO', a command to switch among threads
1720 * `info threads', a command to inquire about existing threads
1722 * `thread apply [THREADNO] [ALL] ARGS', a command to apply a command
1723 to a list of threads
1725 * thread-specific breakpoints
1727 _Warning:_ These facilities are not yet available on every GDB
1728 configuration where the operating system supports threads. If
1729 your GDB does not support threads, these commands have no effect.
1730 For example, a system without thread support shows no output from
1731 `info threads', and always rejects the `thread' command, like this:
1735 Thread ID 1 not known. Use the "info threads" command to
1736 see the IDs of currently known threads.
1738 The GDB thread debugging facility allows you to observe all threads
1739 while your program runs--but whenever GDB takes control, one thread in
1740 particular is always the focus of debugging. This thread is called the
1741 "current thread". Debugging commands show program information from the
1742 perspective of the current thread.
1744 Whenever GDB detects a new thread in your program, it displays the
1745 target system's identification for the thread with a message in the
1746 form `[New SYSTAG]'. SYSTAG is a thread identifier whose form varies
1747 depending on the particular system. For example, on LynxOS, you might
1750 [New process 35 thread 27]
1752 when GDB notices a new thread. In contrast, on an SGI system, the
1753 SYSTAG is simply something like `process 368', with no further
1756 For debugging purposes, GDB associates its own thread number--always
1757 a single integer--with each thread in your program.
1760 Display a summary of all threads currently in your program. GDB
1761 displays for each thread (in this order):
1763 1. the thread number assigned by GDB
1765 2. the target system's thread identifier (SYSTAG)
1767 3. the current stack frame summary for that thread
1769 An asterisk `*' to the left of the GDB thread number indicates the
1775 3 process 35 thread 27 0x34e5 in sigpause ()
1776 2 process 35 thread 23 0x34e5 in sigpause ()
1777 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
1782 For debugging purposes, GDB associates its own thread number--a
1783 small integer assigned in thread-creation order--with each thread in
1786 Whenever GDB detects a new thread in your program, it displays both
1787 GDB's thread number and the target system's identification for the
1788 thread with a message in the form `[New SYSTAG]'. SYSTAG is a thread
1789 identifier whose form varies depending on the particular system. For
1790 example, on HP-UX, you see
1792 [New thread 2 (system thread 26594)]
1794 when GDB notices a new thread.
1797 Display a summary of all threads currently in your program. GDB
1798 displays for each thread (in this order):
1800 1. the thread number assigned by GDB
1802 2. the target system's thread identifier (SYSTAG)
1804 3. the current stack frame summary for that thread
1806 An asterisk `*' to the left of the GDB thread number indicates the
1812 * 3 system thread 26607 worker (wptr=0x7b09c318 "@") \
1815 2 system thread 26606 0x7b0030d8 in __ksleep () \
1817 from /usr/lib/libc.2
1818 1 system thread 27905 0x7b003498 in _brk () \
1820 from /usr/lib/libc.2
1823 Make thread number THREADNO the current thread. The command
1824 argument THREADNO is the internal GDB thread number, as shown in
1825 the first field of the `info threads' display. GDB responds by
1826 displaying the system identifier of the thread you selected, and
1827 its current stack frame summary:
1830 [Switching to process 35 thread 23]
1831 0x34e5 in sigpause ()
1833 As with the `[New ...]' message, the form of the text after
1834 `Switching to' depends on your system's conventions for identifying
1837 `thread apply [THREADNO] [ALL] ARGS'
1838 The `thread apply' command allows you to apply a command to one or
1839 more threads. Specify the numbers of the threads that you want
1840 affected with the command argument THREADNO. THREADNO is the
1841 internal GDB thread number, as shown in the first field of the
1842 `info threads' display. To apply a command to all threads, use
1843 `thread apply all' ARGS.
1845 Whenever GDB stops your program, due to a breakpoint or a signal, it
1846 automatically selects the thread where that breakpoint or signal
1847 happened. GDB alerts you to the context switch with a message of the
1848 form `[Switching to SYSTAG]' to identify the thread.
1850 *Note Stopping and starting multi-thread programs: Thread Stops, for
1851 more information about how GDB behaves when you stop and start programs
1852 with multiple threads.
1854 *Note Setting watchpoints: Set Watchpoints, for information about
1855 watchpoints in programs with multiple threads.
1858 File: gdb.info, Node: Processes, Prev: Threads, Up: Running
1860 Debugging programs with multiple processes
1861 ==========================================
1863 On most systems, GDB has no special support for debugging programs
1864 which create additional processes using the `fork' function. When a
1865 program forks, GDB will continue to debug the parent process and the
1866 child process will run unimpeded. If you have set a breakpoint in any
1867 code which the child then executes, the child will get a `SIGTRAP'
1868 signal which (unless it catches the signal) will cause it to terminate.
1870 However, if you want to debug the child process there is a workaround
1871 which isn't too painful. Put a call to `sleep' in the code which the
1872 child process executes after the fork. It may be useful to sleep only
1873 if a certain environment variable is set, or a certain file exists, so
1874 that the delay need not occur when you don't want to run GDB on the
1875 child. While the child is sleeping, use the `ps' program to get its
1876 process ID. Then tell GDB (a new invocation of GDB if you are also
1877 debugging the parent process) to attach to the child process (*note
1878 Attach::). From that point on you can debug the child process just
1879 like any other process which you attached to.
1881 On some systems, GDB provides support for debugging programs that
1882 create additional processes using the `fork' or `vfork' functions.
1883 Currently, the only platforms with this feature are HP-UX (11.x and
1884 later only?) and GNU/Linux (kernel version 2.5.60 and later).
1886 By default, when a program forks, GDB will continue to debug the
1887 parent process and the child process will run unimpeded.
1889 If you want to follow the child process instead of the parent
1890 process, use the command `set follow-fork-mode'.
1892 `set follow-fork-mode MODE'
1893 Set the debugger response to a program call of `fork' or `vfork'.
1894 A call to `fork' or `vfork' creates a new process. The MODE can
1898 The original process is debugged after a fork. The child
1899 process runs unimpeded. This is the default.
1902 The new process is debugged after a fork. The parent process
1906 `show follow-fork-mode'
1907 Display the current debugger response to a `fork' or `vfork' call.
1909 If you ask to debug a child process and a `vfork' is followed by an
1910 `exec', GDB executes the new target up to the first breakpoint in the
1911 new target. If you have a breakpoint set on `main' in your original
1912 program, the breakpoint will also be set on the child process's `main'.
1914 When a child process is spawned by `vfork', you cannot debug the
1915 child or parent until an `exec' call completes.
1917 If you issue a `run' command to GDB after an `exec' call executes,
1918 the new target restarts. To restart the parent process, use the `file'
1919 command with the parent executable name as its argument.
1921 You can use the `catch' command to make GDB stop whenever a `fork',
1922 `vfork', or `exec' call is made. *Note Setting catchpoints: Set
1926 File: gdb.info, Node: Stopping, Next: Stack, Prev: Running, Up: Top
1928 Stopping and Continuing
1929 ***********************
1931 The principal purposes of using a debugger are so that you can stop your
1932 program before it terminates; or so that, if your program runs into
1933 trouble, you can investigate and find out why.
1935 Inside GDB, your program may stop for any of several reasons, such
1936 as a signal, a breakpoint, or reaching a new line after a GDB command
1937 such as `step'. You may then examine and change variables, set new
1938 breakpoints or remove old ones, and then continue execution. Usually,
1939 the messages shown by GDB provide ample explanation of the status of
1940 your program--but you can also explicitly request this information at
1944 Display information about the status of your program: whether it is
1945 running or not, what process it is, and why it stopped.
1949 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
1950 * Continuing and Stepping:: Resuming execution
1952 * Thread Stops:: Stopping and starting multi-thread programs
1955 File: gdb.info, Node: Breakpoints, Next: Continuing and Stepping, Up: Stopping
1957 Breakpoints, watchpoints, and catchpoints
1958 =========================================
1960 A "breakpoint" makes your program stop whenever a certain point in the
1961 program is reached. For each breakpoint, you can add conditions to
1962 control in finer detail whether your program stops. You can set
1963 breakpoints with the `break' command and its variants (*note Setting
1964 breakpoints: Set Breaks.), to specify the place where your program
1965 should stop by line number, function name or exact address in the
1968 In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can
1969 set breakpoints in shared libraries before the executable is run.
1970 There is a minor limitation on HP-UX systems: you must wait until the
1971 executable is run in order to set breakpoints in shared library
1972 routines that are not called directly by the program (for example,
1973 routines that are arguments in a `pthread_create' call).
1975 A "watchpoint" is a special breakpoint that stops your program when
1976 the value of an expression changes. You must use a different command
1977 to set watchpoints (*note Setting watchpoints: Set Watchpoints.), but
1978 aside from that, you can manage a watchpoint like any other breakpoint:
1979 you enable, disable, and delete both breakpoints and watchpoints using
1982 You can arrange to have values from your program displayed
1983 automatically whenever GDB stops at a breakpoint. *Note Automatic
1984 display: Auto Display.
1986 A "catchpoint" is another special breakpoint that stops your program
1987 when a certain kind of event occurs, such as the throwing of a C++
1988 exception or the loading of a library. As with watchpoints, you use a
1989 different command to set a catchpoint (*note Setting catchpoints: Set
1990 Catchpoints.), but aside from that, you can manage a catchpoint like any
1991 other breakpoint. (To stop when your program receives a signal, use the
1992 `handle' command; see *Note Signals: Signals.)
1994 GDB assigns a number to each breakpoint, watchpoint, or catchpoint
1995 when you create it; these numbers are successive integers starting with
1996 one. In many of the commands for controlling various features of
1997 breakpoints you use the breakpoint number to say which breakpoint you
1998 want to change. Each breakpoint may be "enabled" or "disabled"; if
1999 disabled, it has no effect on your program until you enable it again.
2001 Some GDB commands accept a range of breakpoints on which to operate.
2002 A breakpoint range is either a single breakpoint number, like `5', or
2003 two such numbers, in increasing order, separated by a hyphen, like
2004 `5-7'. When a breakpoint range is given to a command, all breakpoint
2005 in that range are operated on.
2009 * Set Breaks:: Setting breakpoints
2010 * Set Watchpoints:: Setting watchpoints
2011 * Set Catchpoints:: Setting catchpoints
2012 * Delete Breaks:: Deleting breakpoints
2013 * Disabling:: Disabling breakpoints
2014 * Conditions:: Break conditions
2015 * Break Commands:: Breakpoint command lists
2016 * Breakpoint Menus:: Breakpoint menus
2017 * Error in Breakpoints:: ``Cannot insert breakpoints''
2018 * Breakpoint related warnings:: ``Breakpoint address adjusted...''
2021 File: gdb.info, Node: Set Breaks, Next: Set Watchpoints, Up: Breakpoints
2026 Breakpoints are set with the `break' command (abbreviated `b'). The
2027 debugger convenience variable `$bpnum' records the number of the
2028 breakpoint you've set most recently; see *Note Convenience variables:
2029 Convenience Vars, for a discussion of what you can do with convenience
2032 You have several ways to say where the breakpoint should go.
2035 Set a breakpoint at entry to function FUNCTION. When using source
2036 languages that permit overloading of symbols, such as C++,
2037 FUNCTION may refer to more than one possible place to break.
2038 *Note Breakpoint menus: Breakpoint Menus, for a discussion of that
2043 Set a breakpoint some number of lines forward or back from the
2044 position at which execution stopped in the currently selected
2045 "stack frame". (*Note Frames: Frames, for a description of stack
2049 Set a breakpoint at line LINENUM in the current source file. The
2050 current source file is the last file whose source text was printed.
2051 The breakpoint will stop your program just before it executes any
2052 of the code on that line.
2054 `break FILENAME:LINENUM'
2055 Set a breakpoint at line LINENUM in source file FILENAME.
2057 `break FILENAME:FUNCTION'
2058 Set a breakpoint at entry to function FUNCTION found in file
2059 FILENAME. Specifying a file name as well as a function name is
2060 superfluous except when multiple files contain similarly named
2064 Set a breakpoint at address ADDRESS. You can use this to set
2065 breakpoints in parts of your program which do not have debugging
2066 information or source files.
2069 When called without any arguments, `break' sets a breakpoint at
2070 the next instruction to be executed in the selected stack frame
2071 (*note Examining the Stack: Stack.). In any selected frame but the
2072 innermost, this makes your program stop as soon as control returns
2073 to that frame. This is similar to the effect of a `finish'
2074 command in the frame inside the selected frame--except that
2075 `finish' does not leave an active breakpoint. If you use `break'
2076 without an argument in the innermost frame, GDB stops the next
2077 time it reaches the current location; this may be useful inside
2080 GDB normally ignores breakpoints when it resumes execution, until
2081 at least one instruction has been executed. If it did not do
2082 this, you would be unable to proceed past a breakpoint without
2083 first disabling the breakpoint. This rule applies whether or not
2084 the breakpoint already existed when your program stopped.
2087 Set a breakpoint with condition COND; evaluate the expression COND
2088 each time the breakpoint is reached, and stop only if the value is
2089 nonzero--that is, if COND evaluates as true. `...' stands for one
2090 of the possible arguments described above (or no argument)
2091 specifying where to break. *Note Break conditions: Conditions,
2092 for more information on breakpoint conditions.
2095 Set a breakpoint enabled only for one stop. ARGS are the same as
2096 for the `break' command, and the breakpoint is set in the same
2097 way, but the breakpoint is automatically deleted after the first
2098 time your program stops there. *Note Disabling breakpoints:
2102 Set a hardware-assisted breakpoint. ARGS are the same as for the
2103 `break' command and the breakpoint is set in the same way, but the
2104 breakpoint requires hardware support and some target hardware may
2105 not have this support. The main purpose of this is EPROM/ROM code
2106 debugging, so you can set a breakpoint at an instruction without
2107 changing the instruction. This can be used with the new
2108 trap-generation provided by SPARClite DSU and some x86-based
2109 targets. These targets will generate traps when a program
2110 accesses some data or instruction address that is assigned to the
2111 debug registers. However the hardware breakpoint registers can
2112 take a limited number of breakpoints. For example, on the DSU,
2113 only two data breakpoints can be set at a time, and GDB will
2114 reject this command if more than two are used. Delete or disable
2115 unused hardware breakpoints before setting new ones (*note
2116 Disabling: Disabling.). *Note Break conditions: Conditions.
2117 *Note set remote hardware-breakpoint-limit::.
2120 Set a hardware-assisted breakpoint enabled only for one stop. ARGS
2121 are the same as for the `hbreak' command and the breakpoint is set
2122 in the same way. However, like the `tbreak' command, the
2123 breakpoint is automatically deleted after the first time your
2124 program stops there. Also, like the `hbreak' command, the
2125 breakpoint requires hardware support and some target hardware may
2126 not have this support. *Note Disabling breakpoints: Disabling.
2127 See also *Note Break conditions: Conditions.
2130 Set breakpoints on all functions matching the regular expression
2131 REGEX. This command sets an unconditional breakpoint on all
2132 matches, printing a list of all breakpoints it set. Once these
2133 breakpoints are set, they are treated just like the breakpoints
2134 set with the `break' command. You can delete them, disable them,
2135 or make them conditional the same way as any other breakpoint.
2137 The syntax of the regular expression is the standard one used with
2138 tools like `grep'. Note that this is different from the syntax
2139 used by shells, so for instance `foo*' matches all functions that
2140 include an `fo' followed by zero or more `o's. There is an
2141 implicit `.*' leading and trailing the regular expression you
2142 supply, so to match only functions that begin with `foo', use
2145 When debugging C++ programs, `rbreak' is useful for setting
2146 breakpoints on overloaded functions that are not members of any
2149 `info breakpoints [N]'
2151 `info watchpoints [N]'
2152 Print a table of all breakpoints, watchpoints, and catchpoints set
2153 and not deleted, with the following columns for each breakpoint:
2155 _Breakpoint Numbers_
2158 Breakpoint, watchpoint, or catchpoint.
2161 Whether the breakpoint is marked to be disabled or deleted
2164 _Enabled or Disabled_
2165 Enabled breakpoints are marked with `y'. `n' marks
2166 breakpoints that are not enabled.
2169 Where the breakpoint is in your program, as a memory address.
2170 If the breakpoint is pending (see below for details) on a
2171 future load of a shared library, the address will be listed
2175 Where the breakpoint is in the source for your program, as a
2176 file and line number. For a pending breakpoint, the original
2177 string passed to the breakpoint command will be listed as it
2178 cannot be resolved until the appropriate shared library is
2179 loaded in the future.
2181 If a breakpoint is conditional, `info break' shows the condition on
2182 the line following the affected breakpoint; breakpoint commands,
2183 if any, are listed after that. A pending breakpoint is allowed to
2184 have a condition specified for it. The condition is not parsed
2185 for validity until a shared library is loaded that allows the
2186 pending breakpoint to resolve to a valid location.
2188 `info break' with a breakpoint number N as argument lists only
2189 that breakpoint. The convenience variable `$_' and the default
2190 examining-address for the `x' command are set to the address of
2191 the last breakpoint listed (*note Examining memory: Memory.).
2193 `info break' displays a count of the number of times the breakpoint
2194 has been hit. This is especially useful in conjunction with the
2195 `ignore' command. You can ignore a large number of breakpoint
2196 hits, look at the breakpoint info to see how many times the
2197 breakpoint was hit, and then run again, ignoring one less than
2198 that number. This will get you quickly to the last hit of that
2201 GDB allows you to set any number of breakpoints at the same place in
2202 your program. There is nothing silly or meaningless about this. When
2203 the breakpoints are conditional, this is even useful (*note Break
2204 conditions: Conditions.).
2206 If a specified breakpoint location cannot be found, it may be due to
2207 the fact that the location is in a shared library that is yet to be
2208 loaded. In such a case, you may want GDB to create a special
2209 breakpoint (known as a "pending breakpoint") that attempts to resolve
2210 itself in the future when an appropriate shared library gets loaded.
2212 Pending breakpoints are useful to set at the start of your GDB
2213 session for locations that you know will be dynamically loaded later by
2214 the program being debugged. When shared libraries are loaded, a check
2215 is made to see if the load resolves any pending breakpoint locations.
2216 If a pending breakpoint location gets resolved, a regular breakpoint is
2217 created and the original pending breakpoint is removed.
2219 GDB provides some additional commands for controlling pending
2222 `set breakpoint pending auto'
2223 This is the default behavior. When GDB cannot find the breakpoint
2224 location, it queries you whether a pending breakpoint should be
2227 `set breakpoint pending on'
2228 This indicates that an unrecognized breakpoint location should
2229 automatically result in a pending breakpoint being created.
2231 `set breakpoint pending off'
2232 This indicates that pending breakpoints are not to be created. Any
2233 unrecognized breakpoint location results in an error. This
2234 setting does not affect any pending breakpoints previously created.
2236 `show breakpoint pending'
2237 Show the current behavior setting for creating pending breakpoints.
2239 Normal breakpoint operations apply to pending breakpoints as well.
2240 You may specify a condition for a pending breakpoint and/or commands to
2241 run when the breakpoint is reached. You can also enable or disable the
2242 pending breakpoint. When you specify a condition for a pending
2243 breakpoint, the parsing of the condition will be deferred until the
2244 point where the pending breakpoint location is resolved. Disabling a
2245 pending breakpoint tells GDB to not attempt to resolve the breakpoint
2246 on any subsequent shared library load. When a pending breakpoint is
2247 re-enabled, GDB checks to see if the location is already resolved.
2248 This is done because any number of shared library loads could have
2249 occurred since the time the breakpoint was disabled and one or more of
2250 these loads could resolve the location.
2252 GDB itself sometimes sets breakpoints in your program for special
2253 purposes, such as proper handling of `longjmp' (in C programs). These
2254 internal breakpoints are assigned negative numbers, starting with `-1';
2255 `info breakpoints' does not display them. You can see these
2256 breakpoints with the GDB maintenance command `maint info breakpoints'
2257 (*note maint info breakpoints::).
2260 File: gdb.info, Node: Set Watchpoints, Next: Set Catchpoints, Prev: Set Breaks, Up: Breakpoints
2265 You can use a watchpoint to stop execution whenever the value of an
2266 expression changes, without having to predict a particular place where
2269 Depending on your system, watchpoints may be implemented in software
2270 or hardware. GDB does software watchpointing by single-stepping your
2271 program and testing the variable's value each time, which is hundreds of
2272 times slower than normal execution. (But this may still be worth it, to
2273 catch errors where you have no clue what part of your program is the
2276 On some systems, such as HP-UX, GNU/Linux and some other x86-based
2277 targets, GDB includes support for hardware watchpoints, which do not
2278 slow down the running of your program.
2281 Set a watchpoint for an expression. GDB will break when EXPR is
2282 written into by the program and its value changes.
2285 Set a watchpoint that will break when watch EXPR is read by the
2289 Set a watchpoint that will break when EXPR is either read or
2290 written into by the program.
2293 This command prints a list of watchpoints, breakpoints, and
2294 catchpoints; it is the same as `info break'.
2296 GDB sets a "hardware watchpoint" if possible. Hardware watchpoints
2297 execute very quickly, and the debugger reports a change in value at the
2298 exact instruction where the change occurs. If GDB cannot set a
2299 hardware watchpoint, it sets a software watchpoint, which executes more
2300 slowly and reports the change in value at the next statement, not the
2301 instruction, after the change occurs.
2303 When you issue the `watch' command, GDB reports
2305 Hardware watchpoint NUM: EXPR
2307 if it was able to set a hardware watchpoint.
2309 Currently, the `awatch' and `rwatch' commands can only set hardware
2310 watchpoints, because accesses to data that don't change the value of
2311 the watched expression cannot be detected without examining every
2312 instruction as it is being executed, and GDB does not do that
2313 currently. If GDB finds that it is unable to set a hardware breakpoint
2314 with the `awatch' or `rwatch' command, it will print a message like
2317 Expression cannot be implemented with read/access watchpoint.
2319 Sometimes, GDB cannot set a hardware watchpoint because the data
2320 type of the watched expression is wider than what a hardware watchpoint
2321 on the target machine can handle. For example, some systems can only
2322 watch regions that are up to 4 bytes wide; on such systems you cannot
2323 set hardware watchpoints for an expression that yields a
2324 double-precision floating-point number (which is typically 8 bytes
2325 wide). As a work-around, it might be possible to break the large region
2326 into a series of smaller ones and watch them with separate watchpoints.
2328 If you set too many hardware watchpoints, GDB might be unable to
2329 insert all of them when you resume the execution of your program.
2330 Since the precise number of active watchpoints is unknown until such
2331 time as the program is about to be resumed, GDB might not be able to
2332 warn you about this when you set the watchpoints, and the warning will
2333 be printed only when the program is resumed:
2335 Hardware watchpoint NUM: Could not insert watchpoint
2337 If this happens, delete or disable some of the watchpoints.
2339 The SPARClite DSU will generate traps when a program accesses some
2340 data or instruction address that is assigned to the debug registers.
2341 For the data addresses, DSU facilitates the `watch' command. However
2342 the hardware breakpoint registers can only take two data watchpoints,
2343 and both watchpoints must be the same kind. For example, you can set
2344 two watchpoints with `watch' commands, two with `rwatch' commands, *or*
2345 two with `awatch' commands, but you cannot set one watchpoint with one
2346 command and the other with a different command. GDB will reject the
2347 command if you try to mix watchpoints. Delete or disable unused
2348 watchpoint commands before setting new ones.
2350 If you call a function interactively using `print' or `call', any
2351 watchpoints you have set will be inactive until GDB reaches another
2352 kind of breakpoint or the call completes.
2354 GDB automatically deletes watchpoints that watch local (automatic)
2355 variables, or expressions that involve such variables, when they go out
2356 of scope, that is, when the execution leaves the block in which these
2357 variables were defined. In particular, when the program being debugged
2358 terminates, _all_ local variables go out of scope, and so only
2359 watchpoints that watch global variables remain set. If you rerun the
2360 program, you will need to set all such watchpoints again. One way of
2361 doing that would be to set a code breakpoint at the entry to the `main'
2362 function and when it breaks, set all the watchpoints.
2364 _Warning:_ In multi-thread programs, watchpoints have only limited
2365 usefulness. With the current watchpoint implementation, GDB can
2366 only watch the value of an expression _in a single thread_. If
2367 you are confident that the expression can only change due to the
2368 current thread's activity (and if you are also confident that no
2369 other thread can become current), then you can use watchpoints as
2370 usual. However, GDB may not notice when a non-current thread's
2371 activity changes the expression.
2373 _HP-UX Warning:_ In multi-thread programs, software watchpoints
2374 have only limited usefulness. If GDB creates a software
2375 watchpoint, it can only watch the value of an expression _in a
2376 single thread_. If you are confident that the expression can only
2377 change due to the current thread's activity (and if you are also
2378 confident that no other thread can become current), then you can
2379 use software watchpoints as usual. However, GDB may not notice
2380 when a non-current thread's activity changes the expression.
2381 (Hardware watchpoints, in contrast, watch an expression in all
2384 *Note set remote hardware-watchpoint-limit::.
2387 File: gdb.info, Node: Set Catchpoints, Next: Delete Breaks, Prev: Set Watchpoints, Up: Breakpoints
2392 You can use "catchpoints" to cause the debugger to stop for certain
2393 kinds of program events, such as C++ exceptions or the loading of a
2394 shared library. Use the `catch' command to set a catchpoint.
2397 Stop when EVENT occurs. EVENT can be any of the following:
2399 The throwing of a C++ exception.
2402 The catching of a C++ exception.
2405 A call to `exec'. This is currently only available for HP-UX.
2408 A call to `fork'. This is currently only available for HP-UX.
2411 A call to `vfork'. This is currently only available for
2416 The dynamic loading of any shared library, or the loading of
2417 the library LIBNAME. This is currently only available for
2422 The unloading of any dynamically loaded shared library, or
2423 the unloading of the library LIBNAME. This is currently only
2424 available for HP-UX.
2427 Set a catchpoint that is enabled only for one stop. The
2428 catchpoint is automatically deleted after the first time the event
2432 Use the `info break' command to list the current catchpoints.
2434 There are currently some limitations to C++ exception handling
2435 (`catch throw' and `catch catch') in GDB:
2437 * If you call a function interactively, GDB normally returns control
2438 to you when the function has finished executing. If the call
2439 raises an exception, however, the call may bypass the mechanism
2440 that returns control to you and cause your program either to abort
2441 or to simply continue running until it hits a breakpoint, catches
2442 a signal that GDB is listening for, or exits. This is the case
2443 even if you set a catchpoint for the exception; catchpoints on
2444 exceptions are disabled within interactive calls.
2446 * You cannot raise an exception interactively.
2448 * You cannot install an exception handler interactively.
2450 Sometimes `catch' is not the best way to debug exception handling:
2451 if you need to know exactly where an exception is raised, it is better
2452 to stop _before_ the exception handler is called, since that way you
2453 can see the stack before any unwinding takes place. If you set a
2454 breakpoint in an exception handler instead, it may not be easy to find
2455 out where the exception was raised.
2457 To stop just before an exception handler is called, you need some
2458 knowledge of the implementation. In the case of GNU C++, exceptions are
2459 raised by calling a library function named `__raise_exception' which
2460 has the following ANSI C interface:
2462 /* ADDR is where the exception identifier is stored.
2463 ID is the exception identifier. */
2464 void __raise_exception (void **addr, void *id);
2466 To make the debugger catch all exceptions before any stack unwinding
2467 takes place, set a breakpoint on `__raise_exception' (*note
2468 Breakpoints; watchpoints; and exceptions: Breakpoints.).
2470 With a conditional breakpoint (*note Break conditions: Conditions.)
2471 that depends on the value of ID, you can stop your program when a
2472 specific exception is raised. You can use multiple conditional
2473 breakpoints to stop your program when any of a number of exceptions are
2477 File: gdb.info, Node: Delete Breaks, Next: Disabling, Prev: Set Catchpoints, Up: Breakpoints
2479 Deleting breakpoints
2480 --------------------
2482 It is often necessary to eliminate a breakpoint, watchpoint, or
2483 catchpoint once it has done its job and you no longer want your program
2484 to stop there. This is called "deleting" the breakpoint. A breakpoint
2485 that has been deleted no longer exists; it is forgotten.
2487 With the `clear' command you can delete breakpoints according to
2488 where they are in your program. With the `delete' command you can
2489 delete individual breakpoints, watchpoints, or catchpoints by specifying
2490 their breakpoint numbers.
2492 It is not necessary to delete a breakpoint to proceed past it. GDB
2493 automatically ignores breakpoints on the first instruction to be
2494 executed when you continue execution without changing the execution
2498 Delete any breakpoints at the next instruction to be executed in
2499 the selected stack frame (*note Selecting a frame: Selection.).
2500 When the innermost frame is selected, this is a good way to delete
2501 a breakpoint where your program just stopped.
2504 `clear FILENAME:FUNCTION'
2505 Delete any breakpoints set at entry to the function FUNCTION.
2508 `clear FILENAME:LINENUM'
2509 Delete any breakpoints set at or within the code of the specified
2512 `delete [breakpoints] [RANGE...]'
2513 Delete the breakpoints, watchpoints, or catchpoints of the
2514 breakpoint ranges specified as arguments. If no argument is
2515 specified, delete all breakpoints (GDB asks confirmation, unless
2516 you have `set confirm off'). You can abbreviate this command as
2520 File: gdb.info, Node: Disabling, Next: Conditions, Prev: Delete Breaks, Up: Breakpoints
2522 Disabling breakpoints
2523 ---------------------
2525 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2526 prefer to "disable" it. This makes the breakpoint inoperative as if it
2527 had been deleted, but remembers the information on the breakpoint so
2528 that you can "enable" it again later.
2530 You disable and enable breakpoints, watchpoints, and catchpoints with
2531 the `enable' and `disable' commands, optionally specifying one or more
2532 breakpoint numbers as arguments. Use `info break' or `info watch' to
2533 print a list of breakpoints, watchpoints, and catchpoints if you do not
2534 know which numbers to use.
2536 A breakpoint, watchpoint, or catchpoint can have any of four
2537 different states of enablement:
2539 * Enabled. The breakpoint stops your program. A breakpoint set
2540 with the `break' command starts out in this state.
2542 * Disabled. The breakpoint has no effect on your program.
2544 * Enabled once. The breakpoint stops your program, but then becomes
2547 * Enabled for deletion. The breakpoint stops your program, but
2548 immediately after it does so it is deleted permanently. A
2549 breakpoint set with the `tbreak' command starts out in this state.
2551 You can use the following commands to enable or disable breakpoints,
2552 watchpoints, and catchpoints:
2554 `disable [breakpoints] [RANGE...]'
2555 Disable the specified breakpoints--or all breakpoints, if none are
2556 listed. A disabled breakpoint has no effect but is not forgotten.
2557 All options such as ignore-counts, conditions and commands are
2558 remembered in case the breakpoint is enabled again later. You may
2559 abbreviate `disable' as `dis'.
2561 `enable [breakpoints] [RANGE...]'
2562 Enable the specified breakpoints (or all defined breakpoints).
2563 They become effective once again in stopping your program.
2565 `enable [breakpoints] once RANGE...'
2566 Enable the specified breakpoints temporarily. GDB disables any of
2567 these breakpoints immediately after stopping your program.
2569 `enable [breakpoints] delete RANGE...'
2570 Enable the specified breakpoints to work once, then die. GDB
2571 deletes any of these breakpoints as soon as your program stops
2574 Except for a breakpoint set with `tbreak' (*note Setting
2575 breakpoints: Set Breaks.), breakpoints that you set are initially
2576 enabled; subsequently, they become disabled or enabled only when you
2577 use one of the commands above. (The command `until' can set and delete
2578 a breakpoint of its own, but it does not change the state of your other
2579 breakpoints; see *Note Continuing and stepping: Continuing and
2583 File: gdb.info, Node: Conditions, Next: Break Commands, Prev: Disabling, Up: Breakpoints
2588 The simplest sort of breakpoint breaks every time your program reaches a
2589 specified place. You can also specify a "condition" for a breakpoint.
2590 A condition is just a Boolean expression in your programming language
2591 (*note Expressions: Expressions.). A breakpoint with a condition
2592 evaluates the expression each time your program reaches it, and your
2593 program stops only if the condition is _true_.
2595 This is the converse of using assertions for program validation; in
2596 that situation, you want to stop when the assertion is violated--that
2597 is, when the condition is false. In C, if you want to test an
2598 assertion expressed by the condition ASSERT, you should set the
2599 condition `! ASSERT' on the appropriate breakpoint.
2601 Conditions are also accepted for watchpoints; you may not need them,
2602 since a watchpoint is inspecting the value of an expression anyhow--but
2603 it might be simpler, say, to just set a watchpoint on a variable name,
2604 and specify a condition that tests whether the new value is an
2607 Break conditions can have side effects, and may even call functions
2608 in your program. This can be useful, for example, to activate functions
2609 that log program progress, or to use your own print functions to format
2610 special data structures. The effects are completely predictable unless
2611 there is another enabled breakpoint at the same address. (In that
2612 case, GDB might see the other breakpoint first and stop your program
2613 without checking the condition of this one.) Note that breakpoint
2614 commands are usually more convenient and flexible than break conditions
2615 for the purpose of performing side effects when a breakpoint is reached
2616 (*note Breakpoint command lists: Break Commands.).
2618 Break conditions can be specified when a breakpoint is set, by using
2619 `if' in the arguments to the `break' command. *Note Setting
2620 breakpoints: Set Breaks. They can also be changed at any time with the
2621 `condition' command.
2623 You can also use the `if' keyword with the `watch' command. The
2624 `catch' command does not recognize the `if' keyword; `condition' is the
2625 only way to impose a further condition on a catchpoint.
2627 `condition BNUM EXPRESSION'
2628 Specify EXPRESSION as the break condition for breakpoint,
2629 watchpoint, or catchpoint number BNUM. After you set a condition,
2630 breakpoint BNUM stops your program only if the value of EXPRESSION
2631 is true (nonzero, in C). When you use `condition', GDB checks
2632 EXPRESSION immediately for syntactic correctness, and to determine
2633 whether symbols in it have referents in the context of your
2634 breakpoint. If EXPRESSION uses symbols not referenced in the
2635 context of the breakpoint, GDB prints an error message:
2637 No symbol "foo" in current context.
2639 GDB does not actually evaluate EXPRESSION at the time the
2640 `condition' command (or a command that sets a breakpoint with a
2641 condition, like `break if ...') is given, however. *Note
2642 Expressions: Expressions.
2645 Remove the condition from breakpoint number BNUM. It becomes an
2646 ordinary unconditional breakpoint.
2648 A special case of a breakpoint condition is to stop only when the
2649 breakpoint has been reached a certain number of times. This is so
2650 useful that there is a special way to do it, using the "ignore count"
2651 of the breakpoint. Every breakpoint has an ignore count, which is an
2652 integer. Most of the time, the ignore count is zero, and therefore has
2653 no effect. But if your program reaches a breakpoint whose ignore count
2654 is positive, then instead of stopping, it just decrements the ignore
2655 count by one and continues. As a result, if the ignore count value is
2656 N, the breakpoint does not stop the next N times your program reaches
2660 Set the ignore count of breakpoint number BNUM to COUNT. The next
2661 COUNT times the breakpoint is reached, your program's execution
2662 does not stop; other than to decrement the ignore count, GDB takes
2665 To make the breakpoint stop the next time it is reached, specify a
2668 When you use `continue' to resume execution of your program from a
2669 breakpoint, you can specify an ignore count directly as an
2670 argument to `continue', rather than using `ignore'. *Note
2671 Continuing and stepping: Continuing and Stepping.
2673 If a breakpoint has a positive ignore count and a condition, the
2674 condition is not checked. Once the ignore count reaches zero, GDB
2675 resumes checking the condition.
2677 You could achieve the effect of the ignore count with a condition
2678 such as `$foo-- <= 0' using a debugger convenience variable that
2679 is decremented each time. *Note Convenience variables:
2682 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
2685 File: gdb.info, Node: Break Commands, Next: Breakpoint Menus, Prev: Conditions, Up: Breakpoints
2687 Breakpoint command lists
2688 ------------------------
2690 You can give any breakpoint (or watchpoint or catchpoint) a series of
2691 commands to execute when your program stops due to that breakpoint. For
2692 example, you might want to print the values of certain expressions, or
2693 enable other breakpoints.
2696 `... COMMAND-LIST ...'
2698 Specify a list of commands for breakpoint number BNUM. The
2699 commands themselves appear on the following lines. Type a line
2700 containing just `end' to terminate the commands.
2702 To remove all commands from a breakpoint, type `commands' and
2703 follow it immediately with `end'; that is, give no commands.
2705 With no BNUM argument, `commands' refers to the last breakpoint,
2706 watchpoint, or catchpoint set (not to the breakpoint most recently
2709 Pressing <RET> as a means of repeating the last GDB command is
2710 disabled within a COMMAND-LIST.
2712 You can use breakpoint commands to start your program up again.
2713 Simply use the `continue' command, or `step', or any other command that
2716 Any other commands in the command list, after a command that resumes
2717 execution, are ignored. This is because any time you resume execution
2718 (even with a simple `next' or `step'), you may encounter another
2719 breakpoint--which could have its own command list, leading to
2720 ambiguities about which list to execute.
2722 If the first command you specify in a command list is `silent', the
2723 usual message about stopping at a breakpoint is not printed. This may
2724 be desirable for breakpoints that are to print a specific message and
2725 then continue. If none of the remaining commands print anything, you
2726 see no sign that the breakpoint was reached. `silent' is meaningful
2727 only at the beginning of a breakpoint command list.
2729 The commands `echo', `output', and `printf' allow you to print
2730 precisely controlled output, and are often useful in silent
2731 breakpoints. *Note Commands for controlled output: Output.
2733 For example, here is how you could use breakpoint commands to print
2734 the value of `x' at entry to `foo' whenever `x' is positive.
2739 printf "x is %d\n",x
2743 One application for breakpoint commands is to compensate for one bug
2744 so you can test for another. Put a breakpoint just after the erroneous
2745 line of code, give it a condition to detect the case in which something
2746 erroneous has been done, and give it commands to assign correct values
2747 to any variables that need them. End with the `continue' command so
2748 that your program does not stop, and start with the `silent' command so
2749 that no output is produced. Here is an example:
2759 File: gdb.info, Node: Breakpoint Menus, Next: Error in Breakpoints, Prev: Break Commands, Up: Breakpoints
2764 Some programming languages (notably C++ and Objective-C) permit a
2765 single function name to be defined several times, for application in
2766 different contexts. This is called "overloading". When a function
2767 name is overloaded, `break FUNCTION' is not enough to tell GDB where
2768 you want a breakpoint. If you realize this is a problem, you can use
2769 something like `break FUNCTION(TYPES)' to specify which particular
2770 version of the function you want. Otherwise, GDB offers you a menu of
2771 numbered choices for different possible breakpoints, and waits for your
2772 selection with the prompt `>'. The first two options are always `[0]
2773 cancel' and `[1] all'. Typing `1' sets a breakpoint at each definition
2774 of FUNCTION, and typing `0' aborts the `break' command without setting
2775 any new breakpoints.
2777 For example, the following session excerpt shows an attempt to set a
2778 breakpoint at the overloaded symbol `String::after'. We choose three
2779 particular definitions of that function name:
2781 (gdb) b String::after
2784 [2] file:String.cc; line number:867
2785 [3] file:String.cc; line number:860
2786 [4] file:String.cc; line number:875
2787 [5] file:String.cc; line number:853
2788 [6] file:String.cc; line number:846
2789 [7] file:String.cc; line number:735
2791 Breakpoint 1 at 0xb26c: file String.cc, line 867.
2792 Breakpoint 2 at 0xb344: file String.cc, line 875.
2793 Breakpoint 3 at 0xafcc: file String.cc, line 846.
2794 Multiple breakpoints were set.
2795 Use the "delete" command to delete unwanted
2800 File: gdb.info, Node: Error in Breakpoints, Next: Breakpoint related warnings, Prev: Breakpoint Menus, Up: Breakpoints
2802 "Cannot insert breakpoints"
2803 ---------------------------
2805 Under some operating systems, breakpoints cannot be used in a program if
2806 any other process is running that program. In this situation,
2807 attempting to run or continue a program with a breakpoint causes GDB to
2808 print an error message:
2810 Cannot insert breakpoints.
2811 The same program may be running in another process.
2813 When this happens, you have three ways to proceed:
2815 1. Remove or disable the breakpoints, then continue.
2817 2. Suspend GDB, and copy the file containing your program to a new
2818 name. Resume GDB and use the `exec-file' command to specify that
2819 GDB should run your program under that name. Then start your
2822 3. Relink your program so that the text segment is nonsharable, using
2823 the linker option `-N'. The operating system limitation may not
2824 apply to nonsharable executables.
2826 A similar message can be printed if you request too many active
2827 hardware-assisted breakpoints and watchpoints:
2829 Stopped; cannot insert breakpoints.
2830 You may have requested too many hardware breakpoints and watchpoints.
2832 This message is printed when you attempt to resume the program, since
2833 only then GDB knows exactly how many hardware breakpoints and
2834 watchpoints it needs to insert.
2836 When this message is printed, you need to disable or remove some of
2837 the hardware-assisted breakpoints and watchpoints, and then continue.
2840 File: gdb.info, Node: Breakpoint related warnings, Prev: Error in Breakpoints, Up: Breakpoints
2842 "Breakpoint address adjusted..."
2843 --------------------------------
2845 Some processor architectures place constraints on the addresses at
2846 which breakpoints may be placed. For architectures thus constrained,
2847 GDB will attempt to adjust the breakpoint's address to comply with the
2848 constraints dictated by the architecture.
2850 One example of such an architecture is the Fujitsu FR-V. The FR-V is
2851 a VLIW architecture in which a number of RISC-like instructions may be
2852 bundled together for parallel execution. The FR-V architecture
2853 constrains the location of a breakpoint instruction within such a
2854 bundle to the instruction with the lowest address. GDB honors this
2855 constraint by adjusting a breakpoint's address to the first in the
2858 It is not uncommon for optimized code to have bundles which contain
2859 instructions from different source statements, thus it may happen that
2860 a breakpoint's address will be adjusted from one source statement to
2861 another. Since this adjustment may significantly alter GDB's
2862 breakpoint related behavior from what the user expects, a warning is
2863 printed when the breakpoint is first set and also when the breakpoint
2866 A warning like the one below is printed when setting a breakpoint
2867 that's been subject to address adjustment:
2869 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
2871 Such warnings are printed both for user settable and GDB's internal
2872 breakpoints. If you see one of these warnings, you should verify that
2873 a breakpoint set at the adjusted address will have the desired affect.
2874 If not, the breakpoint in question may be removed and other breakpoints
2875 may be set which will have the desired behavior. E.g., it may be
2876 sufficient to place the breakpoint at a later instruction. A
2877 conditional breakpoint may also be useful in some cases to prevent the
2878 breakpoint from triggering too often.
2880 GDB will also issue a warning when stopping at one of these adjusted
2883 warning: Breakpoint 1 address previously adjusted from 0x00010414
2886 When this warning is encountered, it may be too late to take remedial
2887 action except in cases where the breakpoint is hit earlier or more
2888 frequently than expected.
2891 File: gdb.info, Node: Continuing and Stepping, Next: Signals, Prev: Breakpoints, Up: Stopping
2893 Continuing and stepping
2894 =======================
2896 "Continuing" means resuming program execution until your program
2897 completes normally. In contrast, "stepping" means executing just one
2898 more "step" of your program, where "step" may mean either one line of
2899 source code, or one machine instruction (depending on what particular
2900 command you use). Either when continuing or when stepping, your
2901 program may stop even sooner, due to a breakpoint or a signal. (If it
2902 stops due to a signal, you may want to use `handle', or use `signal 0'
2903 to resume execution. *Note Signals: Signals.)
2905 `continue [IGNORE-COUNT]'
2908 Resume program execution, at the address where your program last
2909 stopped; any breakpoints set at that address are bypassed. The
2910 optional argument IGNORE-COUNT allows you to specify a further
2911 number of times to ignore a breakpoint at this location; its
2912 effect is like that of `ignore' (*note Break conditions:
2915 The argument IGNORE-COUNT is meaningful only when your program
2916 stopped due to a breakpoint. At other times, the argument to
2917 `continue' is ignored.
2919 The synonyms `c' and `fg' (for "foreground", as the debugged
2920 program is deemed to be the foreground program) are provided
2921 purely for convenience, and have exactly the same behavior as
2924 To resume execution at a different place, you can use `return'
2925 (*note Returning from a function: Returning.) to go back to the calling
2926 function; or `jump' (*note Continuing at a different address: Jumping.)
2927 to go to an arbitrary location in your program.
2929 A typical technique for using stepping is to set a breakpoint (*note
2930 Breakpoints; watchpoints; and catchpoints: Breakpoints.) at the
2931 beginning of the function or the section of your program where a problem
2932 is believed to lie, run your program until it stops at that breakpoint,
2933 and then step through the suspect area, examining the variables that are
2934 interesting, until you see the problem happen.
2937 Continue running your program until control reaches a different
2938 source line, then stop it and return control to GDB. This command
2941 _Warning:_ If you use the `step' command while control is
2942 within a function that was compiled without debugging
2943 information, execution proceeds until control reaches a
2944 function that does have debugging information. Likewise, it
2945 will not step into a function which is compiled without
2946 debugging information. To step through functions without
2947 debugging information, use the `stepi' command, described
2950 The `step' command only stops at the first instruction of a source
2951 line. This prevents the multiple stops that could otherwise occur
2952 in `switch' statements, `for' loops, etc. `step' continues to
2953 stop if a function that has debugging information is called within
2954 the line. In other words, `step' _steps inside_ any functions
2955 called within the line.
2957 Also, the `step' command only enters a function if there is line
2958 number information for the function. Otherwise it acts like the
2959 `next' command. This avoids problems when using `cc -gl' on MIPS
2960 machines. Previously, `step' entered subroutines if there was any
2961 debugging information about the routine.
2964 Continue running as in `step', but do so COUNT times. If a
2965 breakpoint is reached, or a signal not related to stepping occurs
2966 before COUNT steps, stepping stops right away.
2969 Continue to the next source line in the current (innermost) stack
2970 frame. This is similar to `step', but function calls that appear
2971 within the line of code are executed without stopping. Execution
2972 stops when control reaches a different line of code at the
2973 original stack level that was executing when you gave the `next'
2974 command. This command is abbreviated `n'.
2976 An argument COUNT is a repeat count, as for `step'.
2978 The `next' command only stops at the first instruction of a source
2979 line. This prevents multiple stops that could otherwise occur in
2980 `switch' statements, `for' loops, etc.
2984 The `set step-mode on' command causes the `step' command to stop
2985 at the first instruction of a function which contains no debug line
2986 information rather than stepping over it.
2988 This is useful in cases where you may be interested in inspecting
2989 the machine instructions of a function which has no symbolic info
2990 and do not want GDB to automatically skip over this function.
2993 Causes the `step' command to step over any functions which
2994 contains no debug information. This is the default.
2997 Continue running until just after function in the selected stack
2998 frame returns. Print the returned value (if any).
3000 Contrast this with the `return' command (*note Returning from a
3001 function: Returning.).
3005 Continue running until a source line past the current line, in the
3006 current stack frame, is reached. This command is used to avoid
3007 single stepping through a loop more than once. It is like the
3008 `next' command, except that when `until' encounters a jump, it
3009 automatically continues execution until the program counter is
3010 greater than the address of the jump.
3012 This means that when you reach the end of a loop after single
3013 stepping though it, `until' makes your program continue execution
3014 until it exits the loop. In contrast, a `next' command at the end
3015 of a loop simply steps back to the beginning of the loop, which
3016 forces you to step through the next iteration.
3018 `until' always stops your program if it attempts to exit the
3019 current stack frame.
3021 `until' may produce somewhat counterintuitive results if the order
3022 of machine code does not match the order of the source lines. For
3023 example, in the following excerpt from a debugging session, the `f'
3024 (`frame') command shows that execution is stopped at line `206';
3025 yet when we use `until', we get to line `195':
3028 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3031 195 for ( ; argc > 0; NEXTARG) {
3033 This happened because, for execution efficiency, the compiler had
3034 generated code for the loop closure test at the end, rather than
3035 the start, of the loop--even though the test in a C `for'-loop is
3036 written before the body of the loop. The `until' command appeared
3037 to step back to the beginning of the loop when it advanced to this
3038 expression; however, it has not really gone to an earlier
3039 statement--not in terms of the actual machine code.
3041 `until' with no argument works by means of single instruction
3042 stepping, and hence is slower than `until' with an argument.
3046 Continue running your program until either the specified location
3047 is reached, or the current stack frame returns. LOCATION is any of
3048 the forms of argument acceptable to `break' (*note Setting
3049 breakpoints: Set Breaks.). This form of the command uses
3050 breakpoints, and hence is quicker than `until' without an
3051 argument. The specified location is actually reached only if it
3052 is in the current frame. This implies that `until' can be used to
3053 skip over recursive function invocations. For instance in the
3054 code below, if the current location is line `96', issuing `until
3055 99' will execute the program up to line `99' in the same
3056 invocation of factorial, i.e. after the inner invocations have
3059 94 int factorial (int value)
3062 97 value *= factorial (value - 1);
3068 Continue running the program up to the given location. An
3069 argument is required, anything of the same form as arguments for
3070 the `break' command. Execution will also stop upon exit from the
3071 current stack frame. This command is similar to `until', but
3072 `advance' will not skip over recursive function calls, and the
3073 target location doesn't have to be in the same frame as the
3079 Execute one machine instruction, then stop and return to the
3082 It is often useful to do `display/i $pc' when stepping by machine
3083 instructions. This makes GDB automatically display the next
3084 instruction to be executed, each time your program stops. *Note
3085 Automatic display: Auto Display.
3087 An argument is a repeat count, as in `step'.
3092 Execute one machine instruction, but if it is a function call,
3093 proceed until the function returns.
3095 An argument is a repeat count, as in `next'.
3098 File: gdb.info, Node: Signals, Next: Thread Stops, Prev: Continuing and Stepping, Up: Stopping
3103 A signal is an asynchronous event that can happen in a program. The
3104 operating system defines the possible kinds of signals, and gives each
3105 kind a name and a number. For example, in Unix `SIGINT' is the signal
3106 a program gets when you type an interrupt character (often `C-c');
3107 `SIGSEGV' is the signal a program gets from referencing a place in
3108 memory far away from all the areas in use; `SIGALRM' occurs when the
3109 alarm clock timer goes off (which happens only if your program has
3110 requested an alarm).
3112 Some signals, including `SIGALRM', are a normal part of the
3113 functioning of your program. Others, such as `SIGSEGV', indicate
3114 errors; these signals are "fatal" (they kill your program immediately)
3115 if the program has not specified in advance some other way to handle
3116 the signal. `SIGINT' does not indicate an error in your program, but
3117 it is normally fatal so it can carry out the purpose of the interrupt:
3118 to kill the program.
3120 GDB has the ability to detect any occurrence of a signal in your
3121 program. You can tell GDB in advance what to do for each kind of
3124 Normally, GDB is set up to let the non-erroneous signals like
3125 `SIGALRM' be silently passed to your program (so as not to interfere
3126 with their role in the program's functioning) but to stop your program
3127 immediately whenever an error signal happens. You can change these
3128 settings with the `handle' command.
3132 Print a table of all the kinds of signals and how GDB has been
3133 told to handle each one. You can use this to see the signal
3134 numbers of all the defined types of signals.
3136 `info handle' is an alias for `info signals'.
3138 `handle SIGNAL KEYWORDS...'
3139 Change the way GDB handles signal SIGNAL. SIGNAL can be the
3140 number of a signal or its name (with or without the `SIG' at the
3141 beginning); a list of signal numbers of the form `LOW-HIGH'; or
3142 the word `all', meaning all the known signals. The KEYWORDS say
3143 what change to make.
3145 The keywords allowed by the `handle' command can be abbreviated.
3146 Their full names are:
3149 GDB should not stop your program when this signal happens. It may
3150 still print a message telling you that the signal has come in.
3153 GDB should stop your program when this signal happens. This
3154 implies the `print' keyword as well.
3157 GDB should print a message when this signal happens.
3160 GDB should not mention the occurrence of the signal at all. This
3161 implies the `nostop' keyword as well.
3165 GDB should allow your program to see this signal; your program can
3166 handle the signal, or else it may terminate if the signal is fatal
3167 and not handled. `pass' and `noignore' are synonyms.
3171 GDB should not allow your program to see this signal. `nopass'
3172 and `ignore' are synonyms.
3174 When a signal stops your program, the signal is not visible to the
3175 program until you continue. Your program sees the signal then, if
3176 `pass' is in effect for the signal in question _at that time_. In
3177 other words, after GDB reports a signal, you can use the `handle'
3178 command with `pass' or `nopass' to control whether your program sees
3179 that signal when you continue.
3181 The default is set to `nostop', `noprint', `pass' for non-erroneous
3182 signals such as `SIGALRM', `SIGWINCH' and `SIGCHLD', and to `stop',
3183 `print', `pass' for the erroneous signals.
3185 You can also use the `signal' command to prevent your program from
3186 seeing a signal, or cause it to see a signal it normally would not see,
3187 or to give it any signal at any time. For example, if your program
3188 stopped due to some sort of memory reference error, you might store
3189 correct values into the erroneous variables and continue, hoping to see
3190 more execution; but your program would probably terminate immediately as
3191 a result of the fatal signal once it saw the signal. To prevent this,
3192 you can continue with `signal 0'. *Note Giving your program a signal:
3196 File: gdb.info, Node: Thread Stops, Prev: Signals, Up: Stopping
3198 Stopping and starting multi-thread programs
3199 ===========================================
3201 When your program has multiple threads (*note Debugging programs with
3202 multiple threads: Threads.), you can choose whether to set breakpoints
3203 on all threads, or on a particular thread.
3205 `break LINESPEC thread THREADNO'
3206 `break LINESPEC thread THREADNO if ...'
3207 LINESPEC specifies source lines; there are several ways of writing
3208 them, but the effect is always to specify some source line.
3210 Use the qualifier `thread THREADNO' with a breakpoint command to
3211 specify that you only want GDB to stop the program when a
3212 particular thread reaches this breakpoint. THREADNO is one of the
3213 numeric thread identifiers assigned by GDB, shown in the first
3214 column of the `info threads' display.
3216 If you do not specify `thread THREADNO' when you set a breakpoint,
3217 the breakpoint applies to _all_ threads of your program.
3219 You can use the `thread' qualifier on conditional breakpoints as
3220 well; in this case, place `thread THREADNO' before the breakpoint
3221 condition, like this:
3223 (gdb) break frik.c:13 thread 28 if bartab > lim
3226 Whenever your program stops under GDB for any reason, _all_ threads
3227 of execution stop, not just the current thread. This allows you to
3228 examine the overall state of the program, including switching between
3229 threads, without worrying that things may change underfoot.
3231 There is an unfortunate side effect. If one thread stops for a
3232 breakpoint, or for some other reason, and another thread is blocked in a
3233 system call, then the system call may return prematurely. This is a
3234 consequence of the interaction between multiple threads and the signals
3235 that GDB uses to implement breakpoints and other events that stop
3238 To handle this problem, your program should check the return value of
3239 each system call and react appropriately. This is good programming
3242 For example, do not write code like this:
3246 The call to `sleep' will return early if a different thread stops at
3247 a breakpoint or for some other reason.
3249 Instead, write this:
3253 unslept = sleep (unslept);
3255 A system call is allowed to return early, so the system is still
3256 conforming to its specification. But GDB does cause your
3257 multi-threaded program to behave differently than it would without GDB.
3259 Also, GDB uses internal breakpoints in the thread library to monitor
3260 certain events such as thread creation and thread destruction. When
3261 such an event happens, a system call in another thread may return
3262 prematurely, even though your program does not appear to stop.
3264 Conversely, whenever you restart the program, _all_ threads start
3265 executing. _This is true even when single-stepping_ with commands like
3268 In particular, GDB cannot single-step all threads in lockstep.
3269 Since thread scheduling is up to your debugging target's operating
3270 system (not controlled by GDB), other threads may execute more than one
3271 statement while the current thread completes a single step. Moreover,
3272 in general other threads stop in the middle of a statement, rather than
3273 at a clean statement boundary, when the program stops.
3275 You might even find your program stopped in another thread after
3276 continuing or even single-stepping. This happens whenever some other
3277 thread runs into a breakpoint, a signal, or an exception before the
3278 first thread completes whatever you requested.
3280 On some OSes, you can lock the OS scheduler and thus allow only a
3281 single thread to run.
3283 `set scheduler-locking MODE'
3284 Set the scheduler locking mode. If it is `off', then there is no
3285 locking and any thread may run at any time. If `on', then only the
3286 current thread may run when the inferior is resumed. The `step'
3287 mode optimizes for single-stepping. It stops other threads from
3288 "seizing the prompt" by preempting the current thread while you are
3289 stepping. Other threads will only rarely (or never) get a chance
3290 to run when you step. They are more likely to run when you `next'
3291 over a function call, and they are completely free to run when you
3292 use commands like `continue', `until', or `finish'. However,
3293 unless another thread hits a breakpoint during its timeslice, they
3294 will never steal the GDB prompt away from the thread that you are
3297 `show scheduler-locking'
3298 Display the current scheduler locking mode.
3301 File: gdb.info, Node: Stack, Next: Source, Prev: Stopping, Up: Top
3306 When your program has stopped, the first thing you need to know is
3307 where it stopped and how it got there.
3309 Each time your program performs a function call, information about
3310 the call is generated. That information includes the location of the
3311 call in your program, the arguments of the call, and the local
3312 variables of the function being called. The information is saved in a
3313 block of data called a "stack frame". The stack frames are allocated
3314 in a region of memory called the "call stack".
3316 When your program stops, the GDB commands for examining the stack
3317 allow you to see all of this information.
3319 One of the stack frames is "selected" by GDB and many GDB commands
3320 refer implicitly to the selected frame. In particular, whenever you
3321 ask GDB for the value of a variable in your program, the value is found
3322 in the selected frame. There are special GDB commands to select
3323 whichever frame you are interested in. *Note Selecting a frame:
3326 When your program stops, GDB automatically selects the currently
3327 executing frame and describes it briefly, similar to the `frame'
3328 command (*note Information about a frame: Frame Info.).
3332 * Frames:: Stack frames
3333 * Backtrace:: Backtraces
3334 * Selection:: Selecting a frame
3335 * Frame Info:: Information on a frame
3338 File: gdb.info, Node: Frames, Next: Backtrace, Up: Stack
3343 The call stack is divided up into contiguous pieces called "stack
3344 frames", or "frames" for short; each frame is the data associated with
3345 one call to one function. The frame contains the arguments given to
3346 the function, the function's local variables, and the address at which
3347 the function is executing.
3349 When your program is started, the stack has only one frame, that of
3350 the function `main'. This is called the "initial" frame or the
3351 "outermost" frame. Each time a function is called, a new frame is
3352 made. Each time a function returns, the frame for that function
3353 invocation is eliminated. If a function is recursive, there can be
3354 many frames for the same function. The frame for the function in which
3355 execution is actually occurring is called the "innermost" frame. This
3356 is the most recently created of all the stack frames that still exist.
3358 Inside your program, stack frames are identified by their addresses.
3359 A stack frame consists of many bytes, each of which has its own
3360 address; each kind of computer has a convention for choosing one byte
3361 whose address serves as the address of the frame. Usually this address
3362 is kept in a register called the "frame pointer register" while
3363 execution is going on in that frame.
3365 GDB assigns numbers to all existing stack frames, starting with zero
3366 for the innermost frame, one for the frame that called it, and so on
3367 upward. These numbers do not really exist in your program; they are
3368 assigned by GDB to give you a way of designating stack frames in GDB
3371 Some compilers provide a way to compile functions so that they
3372 operate without stack frames. (For example, the gcc option
3373 `-fomit-frame-pointer'
3374 generates functions without a frame.) This is occasionally done
3375 with heavily used library functions to save the frame setup time. GDB
3376 has limited facilities for dealing with these function invocations. If
3377 the innermost function invocation has no stack frame, GDB nevertheless
3378 regards it as though it had a separate frame, which is numbered zero as
3379 usual, allowing correct tracing of the function call chain. However,
3380 GDB has no provision for frameless functions elsewhere in the stack.
3383 The `frame' command allows you to move from one stack frame to
3384 another, and to print the stack frame you select. ARGS may be
3385 either the address of the frame or the stack frame number.
3386 Without an argument, `frame' prints the current stack frame.
3389 The `select-frame' command allows you to move from one stack frame
3390 to another without printing the frame. This is the silent version
3394 File: gdb.info, Node: Backtrace, Next: Selection, Prev: Frames, Up: Stack
3399 A backtrace is a summary of how your program got where it is. It shows
3400 one line per frame, for many frames, starting with the currently
3401 executing frame (frame zero), followed by its caller (frame one), and
3406 Print a backtrace of the entire stack: one line per frame for all
3407 frames in the stack.
3409 You can stop the backtrace at any time by typing the system
3410 interrupt character, normally `C-c'.
3414 Similar, but print only the innermost N frames.
3418 Similar, but print only the outermost N frames.
3420 The names `where' and `info stack' (abbreviated `info s') are
3421 additional aliases for `backtrace'.
3423 Each line in the backtrace shows the frame number and the function
3424 name. The program counter value is also shown--unless you use `set
3425 print address off'. The backtrace also shows the source file name and
3426 line number, as well as the arguments to the function. The program
3427 counter value is omitted if it is at the beginning of the code for that
3430 Here is an example of a backtrace. It was made with the command `bt
3431 3', so it shows the innermost three frames.
3433 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
3435 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
3436 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
3438 (More stack frames follow...)
3440 The display for frame zero does not begin with a program counter value,
3441 indicating that your program has stopped at the beginning of the code
3442 for line `993' of `builtin.c'.
3444 Most programs have a standard user entry point--a place where system
3445 libraries and startup code transition into user code. For C this is
3446 `main'. When GDB finds the entry function in a backtrace it will
3447 terminate the backtrace, to avoid tracing into highly system-specific
3448 (and generally uninteresting) code.
3450 If you need to examine the startup code, or limit the number of
3451 levels in a backtrace, you can change this behavior:
3453 `set backtrace past-main'
3454 `set backtrace past-main on'
3455 Backtraces will continue past the user entry point.
3457 `set backtrace past-main off'
3458 Backtraces will stop when they encounter the user entry point.
3459 This is the default.
3461 `show backtrace past-main'
3462 Display the current user entry point backtrace policy.
3464 `set backtrace limit N'
3465 `set backtrace limit 0'
3466 Limit the backtrace to N levels. A value of zero means unlimited.
3468 `show backtrace limit'
3469 Display the current limit on backtrace levels.
3472 File: gdb.info, Node: Selection, Next: Frame Info, Prev: Backtrace, Up: Stack
3477 Most commands for examining the stack and other data in your program
3478 work on whichever stack frame is selected at the moment. Here are the
3479 commands for selecting a stack frame; all of them finish by printing a
3480 brief description of the stack frame just selected.
3484 Select frame number N. Recall that frame zero is the innermost
3485 (currently executing) frame, frame one is the frame that called the
3486 innermost one, and so on. The highest-numbered frame is the one
3491 Select the frame at address ADDR. This is useful mainly if the
3492 chaining of stack frames has been damaged by a bug, making it
3493 impossible for GDB to assign numbers properly to all frames. In
3494 addition, this can be useful when your program has multiple stacks
3495 and switches between them.
3497 On the SPARC architecture, `frame' needs two addresses to select
3498 an arbitrary frame: a frame pointer and a stack pointer.
3500 On the MIPS and Alpha architecture, it needs two addresses: a stack
3501 pointer and a program counter.
3503 On the 29k architecture, it needs three addresses: a register stack
3504 pointer, a program counter, and a memory stack pointer.
3507 Move N frames up the stack. For positive numbers N, this advances
3508 toward the outermost frame, to higher frame numbers, to frames
3509 that have existed longer. N defaults to one.
3512 Move N frames down the stack. For positive numbers N, this
3513 advances toward the innermost frame, to lower frame numbers, to
3514 frames that were created more recently. N defaults to one. You
3515 may abbreviate `down' as `do'.
3517 All of these commands end by printing two lines of output describing
3518 the frame. The first line shows the frame number, the function name,
3519 the arguments, and the source file and line number of execution in that
3520 frame. The second line shows the text of that source line.
3525 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
3527 10 read_input_file (argv[i]);
3529 After such a printout, the `list' command with no arguments prints
3530 ten lines centered on the point of execution in the frame. You can
3531 also edit the program at the point of execution with your favorite
3532 editing program by typing `edit'. *Note Printing source lines: List,
3537 These two commands are variants of `up' and `down', respectively;
3538 they differ in that they do their work silently, without causing
3539 display of the new frame. They are intended primarily for use in
3540 GDB command scripts, where the output might be unnecessary and
3544 File: gdb.info, Node: Frame Info, Prev: Selection, Up: Stack
3546 Information about a frame
3547 =========================
3549 There are several other commands to print information about the selected
3554 When used without any argument, this command does not change which
3555 frame is selected, but prints a brief description of the currently
3556 selected stack frame. It can be abbreviated `f'. With an
3557 argument, this command is used to select a stack frame. *Note
3558 Selecting a frame: Selection.
3562 This command prints a verbose description of the selected stack
3565 * the address of the frame
3567 * the address of the next frame down (called by this frame)
3569 * the address of the next frame up (caller of this frame)
3571 * the language in which the source code corresponding to this
3574 * the address of the frame's arguments
3576 * the address of the frame's local variables
3578 * the program counter saved in it (the address of execution in
3581 * which registers were saved in the frame
3583 The verbose description is useful when something has gone wrong
3584 that has made the stack format fail to fit the usual conventions.
3588 Print a verbose description of the frame at address ADDR, without
3589 selecting that frame. The selected frame remains unchanged by this
3590 command. This requires the same kind of address (more than one
3591 for some architectures) that you specify in the `frame' command.
3592 *Note Selecting a frame: Selection.
3595 Print the arguments of the selected frame, each on a separate line.
3598 Print the local variables of the selected frame, each on a separate
3599 line. These are all variables (declared either static or
3600 automatic) accessible at the point of execution of the selected
3604 Print a list of all the exception handlers that are active in the
3605 current stack frame at the current point of execution. To see
3606 other exception handlers, visit the associated frame (using the
3607 `up', `down', or `frame' commands); then type `info catch'. *Note
3608 Setting catchpoints: Set Catchpoints.
3612 File: gdb.info, Node: Source, Next: Data, Prev: Stack, Up: Top
3614 Examining Source Files
3615 **********************
3617 GDB can print parts of your program's source, since the debugging
3618 information recorded in the program tells GDB what source files were
3619 used to build it. When your program stops, GDB spontaneously prints
3620 the line where it stopped. Likewise, when you select a stack frame
3621 (*note Selecting a frame: Selection.), GDB prints the line where
3622 execution in that frame has stopped. You can print other portions of
3623 source files by explicit command.
3625 If you use GDB through its GNU Emacs interface, you may prefer to
3626 use Emacs facilities to view source; see *Note Using GDB under GNU
3631 * List:: Printing source lines
3632 * Edit:: Editing source files
3633 * Search:: Searching source files
3634 * Source Path:: Specifying source directories
3635 * Machine Code:: Source and machine code
3638 File: gdb.info, Node: List, Next: Edit, Up: Source
3640 Printing source lines
3641 =====================
3643 To print lines from a source file, use the `list' command (abbreviated
3644 `l'). By default, ten lines are printed. There are several ways to
3645 specify what part of the file you want to print.
3647 Here are the forms of the `list' command most commonly used:
3650 Print lines centered around line number LINENUM in the current
3654 Print lines centered around the beginning of function FUNCTION.
3657 Print more lines. If the last lines printed were printed with a
3658 `list' command, this prints lines following the last lines
3659 printed; however, if the last line printed was a solitary line
3660 printed as part of displaying a stack frame (*note Examining the
3661 Stack: Stack.), this prints lines centered around that line.
3664 Print lines just before the lines last printed.
3666 By default, GDB prints ten source lines with any of these forms of
3667 the `list' command. You can change this using `set listsize':
3669 `set listsize COUNT'
3670 Make the `list' command display COUNT source lines (unless the
3671 `list' argument explicitly specifies some other number).
3674 Display the number of lines that `list' prints.
3676 Repeating a `list' command with <RET> discards the argument, so it
3677 is equivalent to typing just `list'. This is more useful than listing
3678 the same lines again. An exception is made for an argument of `-';
3679 that argument is preserved in repetition so that each repetition moves
3680 up in the source file.
3682 In general, the `list' command expects you to supply zero, one or two
3683 "linespecs". Linespecs specify source lines; there are several ways of
3684 writing them, but the effect is always to specify some source line.
3685 Here is a complete description of the possible arguments for `list':
3688 Print lines centered around the line specified by LINESPEC.
3691 Print lines from FIRST to LAST. Both arguments are linespecs.
3694 Print lines ending with LAST.
3697 Print lines starting with FIRST.
3700 Print lines just after the lines last printed.
3703 Print lines just before the lines last printed.
3706 As described in the preceding table.
3708 Here are the ways of specifying a single source line--all the kinds
3712 Specifies line NUMBER of the current source file. When a `list'
3713 command has two linespecs, this refers to the same source file as
3717 Specifies the line OFFSET lines after the last line printed. When
3718 used as the second linespec in a `list' command that has two, this
3719 specifies the line OFFSET lines down from the first linespec.
3722 Specifies the line OFFSET lines before the last line printed.
3725 Specifies line NUMBER in the source file FILENAME.
3728 Specifies the line that begins the body of the function FUNCTION.
3729 For example: in C, this is the line with the open brace.
3732 Specifies the line of the open-brace that begins the body of the
3733 function FUNCTION in the file FILENAME. You only need the file
3734 name with a function name to avoid ambiguity when there are
3735 identically named functions in different source files.
3738 Specifies the line containing the program address ADDRESS.
3739 ADDRESS may be any expression.
3742 File: gdb.info, Node: Edit, Next: Search, Prev: List, Up: Source
3744 Editing source files
3745 ====================
3747 To edit the lines in a source file, use the `edit' command. The
3748 editing program of your choice is invoked with the current line set to
3749 the active line in the program. Alternatively, there are several ways
3750 to specify what part of the file you want to print if you want to see
3751 other parts of the program.
3753 Here are the forms of the `edit' command most commonly used:
3756 Edit the current source file at the active line number in the
3760 Edit the current source file with NUMBER as the active line number.
3763 Edit the file containing FUNCTION at the beginning of its
3766 `edit FILENAME:NUMBER'
3767 Specifies line NUMBER in the source file FILENAME.
3769 `edit FILENAME:FUNCTION'
3770 Specifies the line that begins the body of the function FUNCTION
3771 in the file FILENAME. You only need the file name with a function
3772 name to avoid ambiguity when there are identically named functions
3773 in different source files.
3776 Specifies the line containing the program address ADDRESS.
3777 ADDRESS may be any expression.
3779 Choosing your editor
3780 --------------------
3782 You can customize GDB to use any editor you want (1). By default, it
3783 is /bin/ex, but you can change this by setting the environment variable
3784 `EDITOR' before using GDB. For example, to configure GDB to use the
3785 `vi' editor, you could use these commands with the `sh' shell:
3789 or in the `csh' shell,
3790 setenv EDITOR /usr/bin/vi
3793 ---------- Footnotes ----------
3795 (1) The only restriction is that your editor (say `ex'), recognizes
3796 the following command-line syntax:
3798 The optional numeric value +NUMBER designates the active line in the
3802 File: gdb.info, Node: Search, Next: Source Path, Prev: Edit, Up: Source
3804 Searching source files
3805 ======================
3807 There are two commands for searching through the current source file
3808 for a regular expression.
3810 `forward-search REGEXP'
3812 The command `forward-search REGEXP' checks each line, starting
3813 with the one following the last line listed, for a match for
3814 REGEXP. It lists the line that is found. You can use the synonym
3815 `search REGEXP' or abbreviate the command name as `fo'.
3817 `reverse-search REGEXP'
3818 The command `reverse-search REGEXP' checks each line, starting
3819 with the one before the last line listed and going backward, for a
3820 match for REGEXP. It lists the line that is found. You can
3821 abbreviate this command as `rev'.
3824 File: gdb.info, Node: Source Path, Next: Machine Code, Prev: Search, Up: Source
3826 Specifying source directories
3827 =============================
3829 Executable programs sometimes do not record the directories of the
3830 source files from which they were compiled, just the names. Even when
3831 they do, the directories could be moved between the compilation and
3832 your debugging session. GDB has a list of directories to search for
3833 source files; this is called the "source path". Each time GDB wants a
3834 source file, it tries all the directories in the list, in the order
3835 they are present in the list, until it finds a file with the desired
3836 name. Note that the executable search path is _not_ used for this
3837 purpose. Neither is the current working directory, unless it happens
3838 to be in the source path.
3840 If GDB cannot find a source file in the source path, and the object
3841 program records a directory, GDB tries that directory too. If the
3842 source path is empty, and there is no record of the compilation
3843 directory, GDB looks in the current directory as a last resort.
3845 Whenever you reset or rearrange the source path, GDB clears out any
3846 information it has cached about where source files are found and where
3847 each line is in the file.
3849 When you start GDB, its source path includes only `cdir' and `cwd',
3850 in that order. To add other directories, use the `directory' command.
3852 `directory DIRNAME ...'
3855 Add directory DIRNAME to the front of the source path. Several
3856 directory names may be given to this command, separated by `:'
3857 (`;' on MS-DOS and MS-Windows, where `:' usually appears as part
3858 of absolute file names) or whitespace. You may specify a
3859 directory that is already in the source path; this moves it
3860 forward, so GDB searches it sooner.
3862 You can use the string `$cdir' to refer to the compilation
3863 directory (if one is recorded), and `$cwd' to refer to the current
3864 working directory. `$cwd' is not the same as `.'--the former
3865 tracks the current working directory as it changes during your GDB
3866 session, while the latter is immediately expanded to the current
3867 directory at the time you add an entry to the source path.
3870 Reset the source path to empty again. This requires confirmation.
3873 Print the source path: show which directories it contains.
3875 If your source path is cluttered with directories that are no longer
3876 of interest, GDB may sometimes cause confusion by finding the wrong
3877 versions of source. You can correct the situation as follows:
3879 1. Use `directory' with no argument to reset the source path to empty.
3881 2. Use `directory' with suitable arguments to reinstall the
3882 directories you want in the source path. You can add all the
3883 directories in one command.
3886 File: gdb.info, Node: Machine Code, Prev: Source Path, Up: Source
3888 Source and machine code
3889 =======================
3891 You can use the command `info line' to map source lines to program
3892 addresses (and vice versa), and the command `disassemble' to display a
3893 range of addresses as machine instructions. When run under GNU Emacs
3894 mode, the `info line' command causes the arrow to point to the line
3895 specified. Also, `info line' prints addresses in symbolic form as well
3898 `info line LINESPEC'
3899 Print the starting and ending addresses of the compiled code for
3900 source line LINESPEC. You can specify source lines in any of the
3901 ways understood by the `list' command (*note Printing source
3904 For example, we can use `info line' to discover the location of the
3905 object code for the first line of function `m4_changequote':
3907 (gdb) info line m4_changequote
3908 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
3910 We can also inquire (using `*ADDR' as the form for LINESPEC) what
3911 source line covers a particular address:
3912 (gdb) info line *0x63ff
3913 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
3915 After `info line', the default address for the `x' command is
3916 changed to the starting address of the line, so that `x/i' is
3917 sufficient to begin examining the machine code (*note Examining memory:
3918 Memory.). Also, this address is saved as the value of the convenience
3919 variable `$_' (*note Convenience variables: Convenience Vars.).
3922 This specialized command dumps a range of memory as machine
3923 instructions. The default memory range is the function
3924 surrounding the program counter of the selected frame. A single
3925 argument to this command is a program counter value; GDB dumps the
3926 function surrounding this value. Two arguments specify a range of
3927 addresses (first inclusive, second exclusive) to dump.
3929 The following example shows the disassembly of a range of addresses
3930 of HP PA-RISC 2.0 code:
3932 (gdb) disas 0x32c4 0x32e4
3933 Dump of assembler code from 0x32c4 to 0x32e4:
3934 0x32c4 <main+204>: addil 0,dp
3935 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
3936 0x32cc <main+212>: ldil 0x3000,r31
3937 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
3938 0x32d4 <main+220>: ldo 0(r31),rp
3939 0x32d8 <main+224>: addil -0x800,dp
3940 0x32dc <main+228>: ldo 0x588(r1),r26
3941 0x32e0 <main+232>: ldil 0x3000,r31
3942 End of assembler dump.
3944 Some architectures have more than one commonly-used set of
3945 instruction mnemonics or other syntax.
3947 `set disassembly-flavor INSTRUCTION-SET'
3948 Select the instruction set to use when disassembling the program
3949 via the `disassemble' or `x/i' commands.
3951 Currently this command is only defined for the Intel x86 family.
3952 You can set INSTRUCTION-SET to either `intel' or `att'. The
3953 default is `att', the AT&T flavor used by default by Unix
3954 assemblers for x86-based targets.
3957 File: gdb.info, Node: Data, Next: Macros, Prev: Source, Up: Top
3962 The usual way to examine data in your program is with the `print'
3963 command (abbreviated `p'), or its synonym `inspect'. It evaluates and
3964 prints the value of an expression of the language your program is
3965 written in (*note Using GDB with Different Languages: Languages.).
3969 EXPR is an expression (in the source language). By default the
3970 value of EXPR is printed in a format appropriate to its data type;
3971 you can choose a different format by specifying `/F', where F is a
3972 letter specifying the format; see *Note Output formats: Output
3977 If you omit EXPR, GDB displays the last value again (from the
3978 "value history"; *note Value history: Value History.). This
3979 allows you to conveniently inspect the same value in an
3982 A more low-level way of examining data is with the `x' command. It
3983 examines data in memory at a specified address and prints it in a
3984 specified format. *Note Examining memory: Memory.
3986 If you are interested in information about types, or about how the
3987 fields of a struct or a class are declared, use the `ptype EXP' command
3988 rather than `print'. *Note Examining the Symbol Table: Symbols.
3992 * Expressions:: Expressions
3993 * Variables:: Program variables
3994 * Arrays:: Artificial arrays
3995 * Output Formats:: Output formats
3996 * Memory:: Examining memory
3997 * Auto Display:: Automatic display
3998 * Print Settings:: Print settings
3999 * Value History:: Value history
4000 * Convenience Vars:: Convenience variables
4001 * Registers:: Registers
4002 * Floating Point Hardware:: Floating point hardware
4003 * Vector Unit:: Vector Unit
4004 * Auxiliary Vector:: Auxiliary data provided by operating system
4005 * Memory Region Attributes:: Memory region attributes
4006 * Dump/Restore Files:: Copy between memory and a file
4007 * Character Sets:: Debugging programs that use a different
4008 character set than GDB does
4011 File: gdb.info, Node: Expressions, Next: Variables, Up: Data
4016 `print' and many other GDB commands accept an expression and compute
4017 its value. Any kind of constant, variable or operator defined by the
4018 programming language you are using is valid in an expression in GDB.
4019 This includes conditional expressions, function calls, casts, and
4020 string constants. It also includes preprocessor macros, if you
4021 compiled your program to include this information; see *Note
4024 GDB supports array constants in expressions input by the user. The
4025 syntax is {ELEMENT, ELEMENT...}. For example, you can use the command
4026 `print {1, 2, 3}' to build up an array in memory that is `malloc'ed in
4029 Because C is so widespread, most of the expressions shown in
4030 examples in this manual are in C. *Note Using GDB with Different
4031 Languages: Languages, for information on how to use expressions in other
4034 In this section, we discuss operators that you can use in GDB
4035 expressions regardless of your programming language.
4037 Casts are supported in all languages, not just in C, because it is so
4038 useful to cast a number into a pointer in order to examine a structure
4039 at that address in memory.
4041 GDB supports these operators, in addition to those common to
4042 programming languages:
4045 `@' is a binary operator for treating parts of memory as arrays.
4046 *Note Artificial arrays: Arrays, for more information.
4049 `::' allows you to specify a variable in terms of the file or
4050 function where it is defined. *Note Program variables: Variables.
4053 Refers to an object of type TYPE stored at address ADDR in memory.
4054 ADDR may be any expression whose value is an integer or pointer
4055 (but parentheses are required around binary operators, just as in
4056 a cast). This construct is allowed regardless of what kind of
4057 data is normally supposed to reside at ADDR.
4060 File: gdb.info, Node: Variables, Next: Arrays, Prev: Expressions, Up: Data
4065 The most common kind of expression to use is the name of a variable in
4068 Variables in expressions are understood in the selected stack frame
4069 (*note Selecting a frame: Selection.); they must be either:
4071 * global (or file-static)
4075 * visible according to the scope rules of the programming language
4076 from the point of execution in that frame
4078 This means that in the function
4090 you can examine and use the variable `a' whenever your program is
4091 executing within the function `foo', but you can only use or examine
4092 the variable `b' while your program is executing inside the block where
4095 There is an exception: you can refer to a variable or function whose
4096 scope is a single source file even if the current execution point is not
4097 in this file. But it is possible to have more than one such variable or
4098 function with the same name (in different source files). If that
4099 happens, referring to that name has unpredictable effects. If you wish,
4100 you can specify a static variable in a particular function or file,
4101 using the colon-colon notation:
4106 Here FILE or FUNCTION is the name of the context for the static
4107 VARIABLE. In the case of file names, you can use quotes to make sure
4108 GDB parses the file name as a single word--for example, to print a
4109 global value of `x' defined in `f2.c':
4113 This use of `::' is very rarely in conflict with the very similar
4114 use of the same notation in C++. GDB also supports use of the C++
4115 scope resolution operator in GDB expressions.
4117 _Warning:_ Occasionally, a local variable may appear to have the
4118 wrong value at certain points in a function--just after entry to a
4119 new scope, and just before exit.
4120 You may see this problem when you are stepping by machine
4121 instructions. This is because, on most machines, it takes more than
4122 one instruction to set up a stack frame (including local variable
4123 definitions); if you are stepping by machine instructions, variables
4124 may appear to have the wrong values until the stack frame is completely
4125 built. On exit, it usually also takes more than one machine
4126 instruction to destroy a stack frame; after you begin stepping through
4127 that group of instructions, local variable definitions may be gone.
4129 This may also happen when the compiler does significant
4130 optimizations. To be sure of always seeing accurate values, turn off
4131 all optimization when compiling.
4133 Another possible effect of compiler optimizations is to optimize
4134 unused variables out of existence, or assign variables to registers (as
4135 opposed to memory addresses). Depending on the support for such cases
4136 offered by the debug info format used by the compiler, GDB might not be
4137 able to display values for such local variables. If that happens, GDB
4138 will print a message like this:
4140 No symbol "foo" in current context.
4142 To solve such problems, either recompile without optimizations, or
4143 use a different debug info format, if the compiler supports several such
4144 formats. For example, GCC, the GNU C/C++ compiler usually supports the
4145 `-gstabs+' option. `-gstabs+' produces debug info in a format that is
4146 superior to formats such as COFF. You may be able to use DWARF 2
4147 (`-gdwarf-2'), which is also an effective form for debug info. *Note
4148 Options for Debugging Your Program or GNU CC: (gcc.info)Debugging
4152 File: gdb.info, Node: Arrays, Next: Output Formats, Prev: Variables, Up: Data
4157 It is often useful to print out several successive objects of the same
4158 type in memory; a section of an array, or an array of dynamically
4159 determined size for which only a pointer exists in the program.
4161 You can do this by referring to a contiguous span of memory as an
4162 "artificial array", using the binary operator `@'. The left operand of
4163 `@' should be the first element of the desired array and be an
4164 individual object. The right operand should be the desired length of
4165 the array. The result is an array value whose elements are all of the
4166 type of the left argument. The first element is actually the left
4167 argument; the second element comes from bytes of memory immediately
4168 following those that hold the first element, and so on. Here is an
4169 example. If a program says
4171 int *array = (int *) malloc (len * sizeof (int));
4173 you can print the contents of `array' with
4177 The left operand of `@' must reside in memory. Array values made
4178 with `@' in this way behave just like other arrays in terms of
4179 subscripting, and are coerced to pointers when used in expressions.
4180 Artificial arrays most often appear in expressions via the value history
4181 (*note Value history: Value History.), after printing one out.
4183 Another way to create an artificial array is to use a cast. This
4184 re-interprets a value as if it were an array. The value need not be in
4186 (gdb) p/x (short[2])0x12345678
4187 $1 = {0x1234, 0x5678}
4189 As a convenience, if you leave the array length out (as in
4190 `(TYPE[])VALUE') GDB calculates the size to fill the value (as
4191 `sizeof(VALUE)/sizeof(TYPE)':
4192 (gdb) p/x (short[])0x12345678
4193 $2 = {0x1234, 0x5678}
4195 Sometimes the artificial array mechanism is not quite enough; in
4196 moderately complex data structures, the elements of interest may not
4197 actually be adjacent--for example, if you are interested in the values
4198 of pointers in an array. One useful work-around in this situation is
4199 to use a convenience variable (*note Convenience variables: Convenience
4200 Vars.) as a counter in an expression that prints the first interesting
4201 value, and then repeat that expression via <RET>. For instance,
4202 suppose you have an array `dtab' of pointers to structures, and you are
4203 interested in the values of a field `fv' in each structure. Here is an
4204 example of what you might type:
4213 File: gdb.info, Node: Output Formats, Next: Memory, Prev: Arrays, Up: Data
4218 By default, GDB prints a value according to its data type. Sometimes
4219 this is not what you want. For example, you might want to print a
4220 number in hex, or a pointer in decimal. Or you might want to view data
4221 in memory at a certain address as a character string or as an
4222 instruction. To do these things, specify an "output format" when you
4225 The simplest use of output formats is to say how to print a value
4226 already computed. This is done by starting the arguments of the
4227 `print' command with a slash and a format letter. The format letters
4231 Regard the bits of the value as an integer, and print the integer
4235 Print as integer in signed decimal.
4238 Print as integer in unsigned decimal.
4241 Print as integer in octal.
4244 Print as integer in binary. The letter `t' stands for "two". (1)
4247 Print as an address, both absolute in hexadecimal and as an offset
4248 from the nearest preceding symbol. You can use this format used
4249 to discover where (in what function) an unknown address is located:
4252 $3 = 0x54320 <_initialize_vx+396>
4254 The command `info symbol 0x54320' yields similar results. *Note
4255 info symbol: Symbols.
4258 Regard as an integer and print it as a character constant.
4261 Regard the bits of the value as a floating point number and print
4262 using typical floating point syntax.
4264 For example, to print the program counter in hex (*note
4269 Note that no space is required before the slash; this is because command
4270 names in GDB cannot contain a slash.
4272 To reprint the last value in the value history with a different
4273 format, you can use the `print' command with just a format and no
4274 expression. For example, `p/x' reprints the last value in hex.
4276 ---------- Footnotes ----------
4278 (1) `b' cannot be used because these format letters are also used
4279 with the `x' command, where `b' stands for "byte"; see *Note Examining
4283 File: gdb.info, Node: Memory, Next: Auto Display, Prev: Output Formats, Up: Data
4288 You can use the command `x' (for "examine") to examine memory in any of
4289 several formats, independently of your program's data types.
4294 Use the `x' command to examine memory.
4296 N, F, and U are all optional parameters that specify how much memory
4297 to display and how to format it; ADDR is an expression giving the
4298 address where you want to start displaying memory. If you use defaults
4299 for NFU, you need not type the slash `/'. Several commands set
4300 convenient defaults for ADDR.
4303 The repeat count is a decimal integer; the default is 1. It
4304 specifies how much memory (counting by units U) to display.
4306 F, the display format
4307 The display format is one of the formats used by `print', `s'
4308 (null-terminated string), or `i' (machine instruction). The
4309 default is `x' (hexadecimal) initially. The default changes each
4310 time you use either `x' or `print'.
4313 The unit size is any of
4319 Halfwords (two bytes).
4322 Words (four bytes). This is the initial default.
4325 Giant words (eight bytes).
4327 Each time you specify a unit size with `x', that size becomes the
4328 default unit the next time you use `x'. (For the `s' and `i'
4329 formats, the unit size is ignored and is normally not written.)
4331 ADDR, starting display address
4332 ADDR is the address where you want GDB to begin displaying memory.
4333 The expression need not have a pointer value (though it may); it
4334 is always interpreted as an integer address of a byte of memory.
4335 *Note Expressions: Expressions, for more information on
4336 expressions. The default for ADDR is usually just after the last
4337 address examined--but several other commands also set the default
4338 address: `info breakpoints' (to the address of the last breakpoint
4339 listed), `info line' (to the starting address of a line), and
4340 `print' (if you use it to display a value from memory).
4342 For example, `x/3uh 0x54320' is a request to display three halfwords
4343 (`h') of memory, formatted as unsigned decimal integers (`u'), starting
4344 at address `0x54320'. `x/4xw $sp' prints the four words (`w') of
4345 memory above the stack pointer (here, `$sp'; *note Registers:
4346 Registers.) in hexadecimal (`x').
4348 Since the letters indicating unit sizes are all distinct from the
4349 letters specifying output formats, you do not have to remember whether
4350 unit size or format comes first; either order works. The output
4351 specifications `4xw' and `4wx' mean exactly the same thing. (However,
4352 the count N must come first; `wx4' does not work.)
4354 Even though the unit size U is ignored for the formats `s' and `i',
4355 you might still want to use a count N; for example, `3i' specifies that
4356 you want to see three machine instructions, including any operands.
4357 The command `disassemble' gives an alternative way of inspecting
4358 machine instructions; see *Note Source and machine code: Machine Code.
4360 All the defaults for the arguments to `x' are designed to make it
4361 easy to continue scanning memory with minimal specifications each time
4362 you use `x'. For example, after you have inspected three machine
4363 instructions with `x/3i ADDR', you can inspect the next seven with just
4364 `x/7'. If you use <RET> to repeat the `x' command, the repeat count N
4365 is used again; the other arguments default as for successive uses of
4368 The addresses and contents printed by the `x' command are not saved
4369 in the value history because there is often too much of them and they
4370 would get in the way. Instead, GDB makes these values available for
4371 subsequent use in expressions as values of the convenience variables
4372 `$_' and `$__'. After an `x' command, the last address examined is
4373 available for use in expressions in the convenience variable `$_'. The
4374 contents of that address, as examined, are available in the convenience
4377 If the `x' command has a repeat count, the address and contents saved
4378 are from the last memory unit printed; this is not the same as the last
4379 address printed if several units were printed on the last line of
4383 File: gdb.info, Node: Auto Display, Next: Print Settings, Prev: Memory, Up: Data
4388 If you find that you want to print the value of an expression frequently
4389 (to see how it changes), you might want to add it to the "automatic
4390 display list" so that GDB prints its value each time your program stops.
4391 Each expression added to the list is given a number to identify it; to
4392 remove an expression from the list, you specify that number. The
4393 automatic display looks like this:
4396 3: bar[5] = (struct hack *) 0x3804
4398 This display shows item numbers, expressions and their current values.
4399 As with displays you request manually using `x' or `print', you can
4400 specify the output format you prefer; in fact, `display' decides
4401 whether to use `print' or `x' depending on how elaborate your format
4402 specification is--it uses `x' if you specify a unit size, or one of the
4403 two formats (`i' and `s') that are only supported by `x'; otherwise it
4407 Add the expression EXPR to the list of expressions to display each
4408 time your program stops. *Note Expressions: Expressions.
4410 `display' does not repeat if you press <RET> again after using it.
4413 For FMT specifying only a display format and not a size or count,
4414 add the expression EXPR to the auto-display list but arrange to
4415 display it each time in the specified format FMT. *Note Output
4416 formats: Output Formats.
4419 For FMT `i' or `s', or including a unit-size or a number of units,
4420 add the expression ADDR as a memory address to be examined each
4421 time your program stops. Examining means in effect doing `x/FMT
4422 ADDR'. *Note Examining memory: Memory.
4424 For example, `display/i $pc' can be helpful, to see the machine
4425 instruction about to be executed each time execution stops (`$pc' is a
4426 common name for the program counter; *note Registers: Registers.).
4428 `undisplay DNUMS...'
4429 `delete display DNUMS...'
4430 Remove item numbers DNUMS from the list of expressions to display.
4432 `undisplay' does not repeat if you press <RET> after using it.
4433 (Otherwise you would just get the error `No display number ...'.)
4435 `disable display DNUMS...'
4436 Disable the display of item numbers DNUMS. A disabled display
4437 item is not printed automatically, but is not forgotten. It may be
4438 enabled again later.
4440 `enable display DNUMS...'
4441 Enable display of item numbers DNUMS. It becomes effective once
4442 again in auto display of its expression, until you specify
4446 Display the current values of the expressions on the list, just as
4447 is done when your program stops.
4450 Print the list of expressions previously set up to display
4451 automatically, each one with its item number, but without showing
4452 the values. This includes disabled expressions, which are marked
4453 as such. It also includes expressions which would not be
4454 displayed right now because they refer to automatic variables not
4455 currently available.
4457 If a display expression refers to local variables, then it does not
4458 make sense outside the lexical context for which it was set up. Such an
4459 expression is disabled when execution enters a context where one of its
4460 variables is not defined. For example, if you give the command
4461 `display last_char' while inside a function with an argument
4462 `last_char', GDB displays this argument while your program continues to
4463 stop inside that function. When it stops elsewhere--where there is no
4464 variable `last_char'--the display is disabled automatically. The next
4465 time your program stops where `last_char' is meaningful, you can enable
4466 the display expression once again.
4469 File: gdb.info, Node: Print Settings, Next: Value History, Prev: Auto Display, Up: Data
4474 GDB provides the following ways to control how arrays, structures, and
4475 symbols are printed.
4477 These settings are useful for debugging programs in any language:
4480 `set print address on'
4481 GDB prints memory addresses showing the location of stack traces,
4482 structure values, pointer values, breakpoints, and so forth, even
4483 when it also displays the contents of those addresses. The default
4484 is `on'. For example, this is what a stack frame display looks
4485 like with `set print address on':
4488 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
4490 530 if (lquote != def_lquote)
4492 `set print address off'
4493 Do not print addresses when displaying their contents. For
4494 example, this is the same stack frame displayed with `set print
4497 (gdb) set print addr off
4499 #0 set_quotes (lq="<<", rq=">>") at input.c:530
4500 530 if (lquote != def_lquote)
4502 You can use `set print address off' to eliminate all machine
4503 dependent displays from the GDB interface. For example, with
4504 `print address off', you should get the same text for backtraces on
4505 all machines--whether or not they involve pointer arguments.
4507 `show print address'
4508 Show whether or not addresses are to be printed.
4510 When GDB prints a symbolic address, it normally prints the closest
4511 earlier symbol plus an offset. If that symbol does not uniquely
4512 identify the address (for example, it is a name whose scope is a single
4513 source file), you may need to clarify. One way to do this is with
4514 `info line', for example `info line *0x4537'. Alternately, you can set
4515 GDB to print the source file and line number when it prints a symbolic
4518 `set print symbol-filename on'
4519 Tell GDB to print the source file name and line number of a symbol
4520 in the symbolic form of an address.
4522 `set print symbol-filename off'
4523 Do not print source file name and line number of a symbol. This
4526 `show print symbol-filename'
4527 Show whether or not GDB will print the source file name and line
4528 number of a symbol in the symbolic form of an address.
4530 Another situation where it is helpful to show symbol filenames and
4531 line numbers is when disassembling code; GDB shows you the line number
4532 and source file that corresponds to each instruction.
4534 Also, you may wish to see the symbolic form only if the address being
4535 printed is reasonably close to the closest earlier symbol:
4537 `set print max-symbolic-offset MAX-OFFSET'
4538 Tell GDB to only display the symbolic form of an address if the
4539 offset between the closest earlier symbol and the address is less
4540 than MAX-OFFSET. The default is 0, which tells GDB to always
4541 print the symbolic form of an address if any symbol precedes it.
4543 `show print max-symbolic-offset'
4544 Ask how large the maximum offset is that GDB prints in a symbolic
4547 If you have a pointer and you are not sure where it points, try `set
4548 print symbol-filename on'. Then you can determine the name and source
4549 file location of the variable where it points, using `p/a POINTER'.
4550 This interprets the address in symbolic form. For example, here GDB
4551 shows that a variable `ptt' points at another variable `t', defined in
4554 (gdb) set print symbol-filename on
4556 $4 = 0xe008 <t in hi2.c>
4558 _Warning:_ For pointers that point to a local variable, `p/a' does
4559 not show the symbol name and filename of the referent, even with
4560 the appropriate `set print' options turned on.
4562 Other settings control how different kinds of objects are printed:
4565 `set print array on'
4566 Pretty print arrays. This format is more convenient to read, but
4567 uses more space. The default is off.
4569 `set print array off'
4570 Return to compressed format for arrays.
4573 Show whether compressed or pretty format is selected for displaying
4576 `set print elements NUMBER-OF-ELEMENTS'
4577 Set a limit on how many elements of an array GDB will print. If
4578 GDB is printing a large array, it stops printing after it has
4579 printed the number of elements set by the `set print elements'
4580 command. This limit also applies to the display of strings. When
4581 GDB starts, this limit is set to 200. Setting NUMBER-OF-ELEMENTS
4582 to zero means that the printing is unlimited.
4584 `show print elements'
4585 Display the number of elements of a large array that GDB will
4586 print. If the number is 0, then the printing is unlimited.
4588 `set print null-stop'
4589 Cause GDB to stop printing the characters of an array when the
4590 first NULL is encountered. This is useful when large arrays
4591 actually contain only short strings. The default is off.
4593 `set print pretty on'
4594 Cause GDB to print structures in an indented format with one member
4595 per line, like this:
4606 `set print pretty off'
4607 Cause GDB to print structures in a compact format, like this:
4609 $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
4612 This is the default format.
4615 Show which format GDB is using to print structures.
4617 `set print sevenbit-strings on'
4618 Print using only seven-bit characters; if this option is set, GDB
4619 displays any eight-bit characters (in strings or character values)
4620 using the notation `\'NNN. This setting is best if you are
4621 working in English (ASCII) and you use the high-order bit of
4622 characters as a marker or "meta" bit.
4624 `set print sevenbit-strings off'
4625 Print full eight-bit characters. This allows the use of more
4626 international character sets, and is the default.
4628 `show print sevenbit-strings'
4629 Show whether or not GDB is printing only seven-bit characters.
4631 `set print union on'
4632 Tell GDB to print unions which are contained in structures. This
4633 is the default setting.
4635 `set print union off'
4636 Tell GDB not to print unions which are contained in structures.
4639 Ask GDB whether or not it will print unions which are contained in
4642 For example, given the declarations
4644 typedef enum {Tree, Bug} Species;
4645 typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
4646 typedef enum {Caterpillar, Cocoon, Butterfly}
4657 struct thing foo = {Tree, {Acorn}};
4659 with `set print union on' in effect `p foo' would print
4661 $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
4663 and with `set print union off' in effect it would print
4665 $1 = {it = Tree, form = {...}}
4667 These settings are of interest when debugging C++ programs:
4669 `set print demangle'
4670 `set print demangle on'
4671 Print C++ names in their source form rather than in the encoded
4672 ("mangled") form passed to the assembler and linker for type-safe
4673 linkage. The default is on.
4675 `show print demangle'
4676 Show whether C++ names are printed in mangled or demangled form.
4678 `set print asm-demangle'
4679 `set print asm-demangle on'
4680 Print C++ names in their source form rather than their mangled
4681 form, even in assembler code printouts such as instruction
4682 disassemblies. The default is off.
4684 `show print asm-demangle'
4685 Show whether C++ names in assembly listings are printed in mangled
4688 `set demangle-style STYLE'
4689 Choose among several encoding schemes used by different compilers
4690 to represent C++ names. The choices for STYLE are currently:
4693 Allow GDB to choose a decoding style by inspecting your
4697 Decode based on the GNU C++ compiler (`g++') encoding
4698 algorithm. This is the default.
4701 Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
4704 Decode based on the Lucid C++ compiler (`lcc') encoding
4708 Decode using the algorithm in the `C++ Annotated Reference
4709 Manual'. *Warning:* this setting alone is not sufficient to
4710 allow debugging `cfront'-generated executables. GDB would
4711 require further enhancement to permit that.
4713 If you omit STYLE, you will see a list of possible formats.
4715 `show demangle-style'
4716 Display the encoding style currently in use for decoding C++
4720 `set print object on'
4721 When displaying a pointer to an object, identify the _actual_
4722 (derived) type of the object rather than the _declared_ type, using
4723 the virtual function table.
4725 `set print object off'
4726 Display only the declared type of objects, without reference to the
4727 virtual function table. This is the default setting.
4730 Show whether actual, or declared, object types are displayed.
4732 `set print static-members'
4733 `set print static-members on'
4734 Print static members when displaying a C++ object. The default is
4737 `set print static-members off'
4738 Do not print static members when displaying a C++ object.
4740 `show print static-members'
4741 Show whether C++ static members are printed, or not.
4745 Pretty print C++ virtual function tables. The default is off.
4746 (The `vtbl' commands do not work on programs compiled with the HP
4747 ANSI C++ compiler (`aCC').)
4749 `set print vtbl off'
4750 Do not pretty print C++ virtual function tables.
4753 Show whether C++ virtual function tables are pretty printed, or
4757 File: gdb.info, Node: Value History, Next: Convenience Vars, Prev: Print Settings, Up: Data
4762 Values printed by the `print' command are saved in the GDB "value
4763 history". This allows you to refer to them in other expressions.
4764 Values are kept until the symbol table is re-read or discarded (for
4765 example with the `file' or `symbol-file' commands). When the symbol
4766 table changes, the value history is discarded, since the values may
4767 contain pointers back to the types defined in the symbol table.
4769 The values printed are given "history numbers" by which you can
4770 refer to them. These are successive integers starting with one.
4771 `print' shows you the history number assigned to a value by printing
4772 `$NUM = ' before the value; here NUM is the history number.
4774 To refer to any previous value, use `$' followed by the value's
4775 history number. The way `print' labels its output is designed to
4776 remind you of this. Just `$' refers to the most recent value in the
4777 history, and `$$' refers to the value before that. `$$N' refers to the
4778 Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
4779 equivalent to `$$', and `$$0' is equivalent to `$'.
4781 For example, suppose you have just printed a pointer to a structure
4782 and want to see the contents of the structure. It suffices to type
4786 If you have a chain of structures where the component `next' points
4787 to the next one, you can print the contents of the next one with this:
4791 You can print successive links in the chain by repeating this
4792 command--which you can do by just typing <RET>.
4794 Note that the history records values, not expressions. If the value
4795 of `x' is 4 and you type these commands:
4800 then the value recorded in the value history by the `print' command
4801 remains 4 even though the value of `x' has changed.
4804 Print the last ten values in the value history, with their item
4805 numbers. This is like `p $$9' repeated ten times, except that
4806 `show values' does not change the history.
4809 Print ten history values centered on history item number N.
4812 Print ten history values just after the values last printed. If
4813 no more values are available, `show values +' produces no display.
4815 Pressing <RET> to repeat `show values N' has exactly the same effect
4819 File: gdb.info, Node: Convenience Vars, Next: Registers, Prev: Value History, Up: Data
4821 Convenience variables
4822 =====================
4824 GDB provides "convenience variables" that you can use within GDB to
4825 hold on to a value and refer to it later. These variables exist
4826 entirely within GDB; they are not part of your program, and setting a
4827 convenience variable has no direct effect on further execution of your
4828 program. That is why you can use them freely.
4830 Convenience variables are prefixed with `$'. Any name preceded by
4831 `$' can be used for a convenience variable, unless it is one of the
4832 predefined machine-specific register names (*note Registers:
4833 Registers.). (Value history references, in contrast, are _numbers_
4834 preceded by `$'. *Note Value history: Value History.)
4836 You can save a value in a convenience variable with an assignment
4837 expression, just as you would set a variable in your program. For
4840 set $foo = *object_ptr
4842 would save in `$foo' the value contained in the object pointed to by
4845 Using a convenience variable for the first time creates it, but its
4846 value is `void' until you assign a new value. You can alter the value
4847 with another assignment at any time.
4849 Convenience variables have no fixed types. You can assign a
4850 convenience variable any type of value, including structures and
4851 arrays, even if that variable already has a value of a different type.
4852 The convenience variable, when used as an expression, has the type of
4856 Print a list of convenience variables used so far, and their
4857 values. Abbreviated `show conv'.
4859 One of the ways to use a convenience variable is as a counter to be
4860 incremented or a pointer to be advanced. For example, to print a field
4861 from successive elements of an array of structures:
4864 print bar[$i++]->contents
4866 Repeat that command by typing <RET>.
4868 Some convenience variables are created automatically by GDB and given
4869 values likely to be useful.
4872 The variable `$_' is automatically set by the `x' command to the
4873 last address examined (*note Examining memory: Memory.). Other
4874 commands which provide a default address for `x' to examine also
4875 set `$_' to that address; these commands include `info line' and
4876 `info breakpoint'. The type of `$_' is `void *' except when set
4877 by the `x' command, in which case it is a pointer to the type of
4881 The variable `$__' is automatically set by the `x' command to the
4882 value found in the last address examined. Its type is chosen to
4883 match the format in which the data was printed.
4886 The variable `$_exitcode' is automatically set to the exit code
4887 when the program being debugged terminates.
4889 On HP-UX systems, if you refer to a function or variable name that
4890 begins with a dollar sign, GDB searches for a user or system name
4891 first, before it searches for a convenience variable.
4894 File: gdb.info, Node: Registers, Next: Floating Point Hardware, Prev: Convenience Vars, Up: Data
4899 You can refer to machine register contents, in expressions, as variables
4900 with names starting with `$'. The names of registers are different for
4901 each machine; use `info registers' to see the names used on your
4905 Print the names and values of all registers except floating-point
4906 and vector registers (in the selected stack frame).
4908 `info all-registers'
4909 Print the names and values of all registers, including
4910 floating-point and vector registers (in the selected stack frame).
4912 `info registers REGNAME ...'
4913 Print the "relativized" value of each specified register REGNAME.
4914 As discussed in detail below, register values are normally
4915 relative to the selected stack frame. REGNAME may be any register
4916 name valid on the machine you are using, with or without the
4919 GDB has four "standard" register names that are available (in
4920 expressions) on most machines--whenever they do not conflict with an
4921 architecture's canonical mnemonics for registers. The register names
4922 `$pc' and `$sp' are used for the program counter register and the stack
4923 pointer. `$fp' is used for a register that contains a pointer to the
4924 current stack frame, and `$ps' is used for a register that contains the
4925 processor status. For example, you could print the program counter in
4930 or print the instruction to be executed next with
4934 or add four to the stack pointer(1) with
4938 Whenever possible, these four standard register names are available
4939 on your machine even though the machine has different canonical
4940 mnemonics, so long as there is no conflict. The `info registers'
4941 command shows the canonical names. For example, on the SPARC, `info
4942 registers' displays the processor status register as `$psr' but you can
4943 also refer to it as `$ps'; and on x86-based machines `$ps' is an alias
4944 for the EFLAGS register.
4946 GDB always considers the contents of an ordinary register as an
4947 integer when the register is examined in this way. Some machines have
4948 special registers which can hold nothing but floating point; these
4949 registers are considered to have floating point values. There is no way
4950 to refer to the contents of an ordinary register as floating point value
4951 (although you can _print_ it as a floating point value with `print/f
4954 Some registers have distinct "raw" and "virtual" data formats. This
4955 means that the data format in which the register contents are saved by
4956 the operating system is not the same one that your program normally
4957 sees. For example, the registers of the 68881 floating point
4958 coprocessor are always saved in "extended" (raw) format, but all C
4959 programs expect to work with "double" (virtual) format. In such cases,
4960 GDB normally works with the virtual format only (the format that makes
4961 sense for your program), but the `info registers' command prints the
4962 data in both formats.
4964 Normally, register values are relative to the selected stack frame
4965 (*note Selecting a frame: Selection.). This means that you get the
4966 value that the register would contain if all stack frames farther in
4967 were exited and their saved registers restored. In order to see the
4968 true contents of hardware registers, you must select the innermost
4969 frame (with `frame 0').
4971 However, GDB must deduce where registers are saved, from the machine
4972 code generated by your compiler. If some registers are not saved, or if
4973 GDB is unable to locate the saved registers, the selected stack frame
4974 makes no difference.
4976 ---------- Footnotes ----------
4978 (1) This is a way of removing one word from the stack, on machines
4979 where stacks grow downward in memory (most machines, nowadays). This
4980 assumes that the innermost stack frame is selected; setting `$sp' is
4981 not allowed when other stack frames are selected. To pop entire frames
4982 off the stack, regardless of machine architecture, use `return'; see
4983 *Note Returning from a function: Returning.
4986 File: gdb.info, Node: Floating Point Hardware, Next: Vector Unit, Prev: Registers, Up: Data
4988 Floating point hardware
4989 =======================
4991 Depending on the configuration, GDB may be able to give you more
4992 information about the status of the floating point hardware.
4995 Display hardware-dependent information about the floating point
4996 unit. The exact contents and layout vary depending on the
4997 floating point chip. Currently, `info float' is supported on the
4998 ARM and x86 machines.
5001 File: gdb.info, Node: Vector Unit, Next: Auxiliary Vector, Prev: Floating Point Hardware, Up: Data
5006 Depending on the configuration, GDB may be able to give you more
5007 information about the status of the vector unit.
5010 Display information about the vector unit. The exact contents and
5011 layout vary depending on the hardware.
5014 File: gdb.info, Node: Auxiliary Vector, Next: Memory Region Attributes, Prev: Vector Unit, Up: Data
5016 Operating system auxiliary vector
5017 =================================
5019 Some operating systems supply an "auxiliary vector" to programs at
5020 startup. This is akin to the arguments and environment that you
5021 specify for a program, but contains a system-dependent variety of
5022 binary values that tell system libraries important details about the
5023 hardware, operating system, and process. Each value's purpose is
5024 identified by an integer tag; the meanings are well-known but
5025 system-specific. Depending on the configuration and operating system
5026 facilities, GDB may be able to show you this information.
5029 Display the auxiliary vector of the inferior, which can be either a
5030 live process or a core dump file. GDB prints each tag value
5031 numerically, and also shows names and text descriptions for
5032 recognized tags. Some values in the vector are numbers, some bit
5033 masks, and some pointers to strings or other data. GDB displays
5034 each value in the most appropriate form for a recognized tag, and
5035 in hexadecimal for an unrecognized tag.
5038 File: gdb.info, Node: Memory Region Attributes, Next: Dump/Restore Files, Prev: Auxiliary Vector, Up: Data
5040 Memory region attributes
5041 ========================
5043 "Memory region attributes" allow you to describe special handling
5044 required by regions of your target's memory. GDB uses attributes to
5045 determine whether to allow certain types of memory accesses; whether to
5046 use specific width accesses; and whether to cache target memory.
5048 Defined memory regions can be individually enabled and disabled.
5049 When a memory region is disabled, GDB uses the default attributes when
5050 accessing memory in that region. Similarly, if no memory regions have
5051 been defined, GDB uses the default attributes when accessing all memory.
5053 When a memory region is defined, it is given a number to identify it;
5054 to enable, disable, or remove a memory region, you specify that number.
5056 `mem LOWER UPPER ATTRIBUTES...'
5057 Define memory region bounded by LOWER and UPPER with attributes
5058 ATTRIBUTES.... Note that UPPER == 0 is a special case: it is
5059 treated as the the target's maximum memory address. (0xffff on 16
5060 bit targets, 0xffffffff on 32 bit targets, etc.)
5062 `delete mem NUMS...'
5063 Remove memory regions NUMS....
5065 `disable mem NUMS...'
5066 Disable memory regions NUMS.... A disabled memory region is not
5067 forgotten. It may be enabled again later.
5069 `enable mem NUMS...'
5070 Enable memory regions NUMS....
5073 Print a table of all defined memory regions, with the following
5074 columns for each region.
5076 _Memory Region Number_
5078 _Enabled or Disabled._
5079 Enabled memory regions are marked with `y'. Disabled memory
5080 regions are marked with `n'.
5083 The address defining the inclusive lower bound of the memory
5087 The address defining the exclusive upper bound of the memory
5091 The list of attributes set for this memory region.
5099 The access mode attributes set whether GDB may make read or write
5100 accesses to a memory region.
5102 While these attributes prevent GDB from performing invalid memory
5103 accesses, they do nothing to prevent the target system, I/O DMA, etc.
5104 from accessing memory.
5107 Memory is read only.
5110 Memory is write only.
5113 Memory is read/write. This is the default.
5118 The acccess size attributes tells GDB to use specific sized accesses in
5119 the memory region. Often memory mapped device registers require
5120 specific sized accesses. If no access size attribute is specified, GDB
5121 may use accesses of any size.
5124 Use 8 bit memory accesses.
5127 Use 16 bit memory accesses.
5130 Use 32 bit memory accesses.
5133 Use 64 bit memory accesses.
5138 The data cache attributes set whether GDB will cache target memory.
5139 While this generally improves performance by reducing debug protocol
5140 overhead, it can lead to incorrect results because GDB does not know
5141 about volatile variables or memory mapped device registers.
5144 Enable GDB to cache target memory.
5147 Disable GDB from caching target memory. This is the default.
5150 File: gdb.info, Node: Dump/Restore Files, Next: Character Sets, Prev: Memory Region Attributes, Up: Data
5152 Copy between memory and a file
5153 ==============================
5155 You can use the commands `dump', `append', and `restore' to copy data
5156 between target memory and a file. The `dump' and `append' commands
5157 write data to a file, and the `restore' command reads data from a file
5158 back into the inferior's memory. Files may be in binary, Motorola
5159 S-record, Intel hex, or Tektronix Hex format; however, GDB can only
5160 append to binary files.
5162 `dump [FORMAT] memory FILENAME START_ADDR END_ADDR'
5163 `dump [FORMAT] value FILENAME EXPR'
5164 Dump the contents of memory from START_ADDR to END_ADDR, or the
5165 value of EXPR, to FILENAME in the given format.
5167 The FORMAT parameter may be any one of:
5175 Motorola S-record format.
5178 Tektronix Hex format.
5180 GDB uses the same definitions of these formats as the GNU binary
5181 utilities, like `objdump' and `objcopy'. If FORMAT is omitted,
5182 GDB dumps the data in raw binary form.
5184 `append [binary] memory FILENAME START_ADDR END_ADDR'
5185 `append [binary] value FILENAME EXPR'
5186 Append the contents of memory from START_ADDR to END_ADDR, or the
5187 value of EXPR, to FILENAME, in raw binary form. (GDB can only
5188 append data to files in raw binary form.)
5190 `restore FILENAME [binary] BIAS START END'
5191 Restore the contents of file FILENAME into memory. The `restore'
5192 command can automatically recognize any known BFD file format,
5193 except for raw binary. To restore a raw binary file you must
5194 specify the optional keyword `binary' after the filename.
5196 If BIAS is non-zero, its value will be added to the addresses
5197 contained in the file. Binary files always start at address zero,
5198 so they will be restored at address BIAS. Other bfd files have a
5199 built-in location; they will be restored at offset BIAS from that
5202 If START and/or END are non-zero, then only data between file
5203 offset START and file offset END will be restored. These offsets
5204 are relative to the addresses in the file, before the BIAS
5205 argument is applied.
5209 File: gdb.info, Node: Character Sets, Prev: Dump/Restore Files, Up: Data
5214 If the program you are debugging uses a different character set to
5215 represent characters and strings than the one GDB uses itself, GDB can
5216 automatically translate between the character sets for you. The
5217 character set GDB uses we call the "host character set"; the one the
5218 inferior program uses we call the "target character set".
5220 For example, if you are running GDB on a GNU/Linux system, which
5221 uses the ISO Latin 1 character set, but you are using GDB's remote
5222 protocol (*note Remote Debugging: Remote.) to debug a program running
5223 on an IBM mainframe, which uses the EBCDIC character set, then the host
5224 character set is Latin-1, and the target character set is EBCDIC. If
5225 you give GDB the command `set target-charset EBCDIC-US', then GDB
5226 translates between EBCDIC and Latin 1 as you print character or string
5227 values, or use character and string literals in expressions.
5229 GDB has no way to automatically recognize which character set the
5230 inferior program uses; you must tell it, using the `set target-charset'
5231 command, described below.
5233 Here are the commands for controlling GDB's character set support:
5235 `set target-charset CHARSET'
5236 Set the current target character set to CHARSET. We list the
5237 character set names GDB recognizes below, but if you type `set
5238 target-charset' followed by <TAB><TAB>, GDB will list the target
5239 character sets it supports.
5241 `set host-charset CHARSET'
5242 Set the current host character set to CHARSET.
5244 By default, GDB uses a host character set appropriate to the
5245 system it is running on; you can override that default using the
5246 `set host-charset' command.
5248 GDB can only use certain character sets as its host character set.
5249 We list the character set names GDB recognizes below, and
5250 indicate which can be host character sets, but if you type `set
5251 target-charset' followed by <TAB><TAB>, GDB will list the host
5252 character sets it supports.
5254 `set charset CHARSET'
5255 Set the current host and target character sets to CHARSET. As
5256 above, if you type `set charset' followed by <TAB><TAB>, GDB will
5257 list the name of the character sets that can be used for both host
5261 Show the names of the current host and target charsets.
5264 Show the name of the current host charset.
5266 `show target-charset'
5267 Show the name of the current target charset.
5270 GDB currently includes support for the following character sets:
5273 Seven-bit U.S. ASCII. GDB can use this as its host character set.
5276 The ISO Latin 1 character set. This extends ASCII with accented
5277 characters needed for French, German, and Spanish. GDB can use
5278 this as its host character set.
5282 Variants of the EBCDIC character set, used on some of IBM's
5283 mainframe operating systems. (GNU/Linux on the S/390 uses U.S.
5284 ASCII.) GDB cannot use these as its host character set.
5287 Note that these are all single-byte character sets. More work inside
5288 GDB is needed to support multi-byte or variable-width character
5289 encodings, like the UTF-8 and UCS-2 encodings of Unicode.
5291 Here is an example of GDB's character set support in action. Assume
5292 that the following source code has been placed in the file
5298 = {72, 101, 108, 108, 111, 44, 32, 119,
5299 111, 114, 108, 100, 33, 10, 0};
5300 char ibm1047_hello[]
5301 = {200, 133, 147, 147, 150, 107, 64, 166,
5302 150, 153, 147, 132, 90, 37, 0};
5306 printf ("Hello, world!\n");
5309 In this program, `ascii_hello' and `ibm1047_hello' are arrays
5310 containing the string `Hello, world!' followed by a newline, encoded in
5311 the ASCII and IBM1047 character sets.
5313 We compile the program, and invoke the debugger on it:
5315 $ gcc -g charset-test.c -o charset-test
5316 $ gdb -nw charset-test
5317 GNU gdb 2001-12-19-cvs
5318 Copyright 2001 Free Software Foundation, Inc.
5322 We can use the `show charset' command to see what character sets GDB
5323 is currently using to interpret and display characters and strings:
5326 The current host and target character set is `ISO-8859-1'.
5329 For the sake of printing this manual, let's use ASCII as our initial
5331 (gdb) set charset ASCII
5333 The current host and target character set is `ASCII'.
5336 Let's assume that ASCII is indeed the correct character set for our
5337 host system -- in other words, let's assume that if GDB prints
5338 characters using the ASCII character set, our terminal will display
5339 them properly. Since our current target character set is also ASCII,
5340 the contents of `ascii_hello' print legibly:
5342 (gdb) print ascii_hello
5343 $1 = 0x401698 "Hello, world!\n"
5344 (gdb) print ascii_hello[0]
5348 GDB uses the target character set for character and string literals
5349 you use in expressions:
5355 The ASCII character set uses the number 43 to encode the `+'
5358 GDB relies on the user to tell it which character set the target
5359 program uses. If we print `ibm1047_hello' while our target character
5360 set is still ASCII, we get jibberish:
5362 (gdb) print ibm1047_hello
5363 $4 = 0x4016a8 "\310\205\223\223\226k@\246\226\231\223\204Z%"
5364 (gdb) print ibm1047_hello[0]
5368 If we invoke the `set target-charset' followed by <TAB><TAB>, GDB
5369 tells us the character sets it supports:
5371 (gdb) set target-charset
5372 ASCII EBCDIC-US IBM1047 ISO-8859-1
5373 (gdb) set target-charset
5375 We can select IBM1047 as our target character set, and examine the
5376 program's strings again. Now the ASCII string is wrong, but GDB
5377 translates the contents of `ibm1047_hello' from the target character
5378 set, IBM1047, to the host character set, ASCII, and they display
5381 (gdb) set target-charset IBM1047
5383 The current host character set is `ASCII'.
5384 The current target character set is `IBM1047'.
5385 (gdb) print ascii_hello
5386 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
5387 (gdb) print ascii_hello[0]
5389 (gdb) print ibm1047_hello
5390 $8 = 0x4016a8 "Hello, world!\n"
5391 (gdb) print ibm1047_hello[0]
5395 As above, GDB uses the target character set for character and string
5396 literals you use in expressions:
5402 The IBM1047 character set uses the number 78 to encode the `+'
5406 File: gdb.info, Node: Macros, Next: Tracepoints, Prev: Data, Up: Top
5408 C Preprocessor Macros
5409 *********************
5411 Some languages, such as C and C++, provide a way to define and invoke
5412 "preprocessor macros" which expand into strings of tokens. GDB can
5413 evaluate expressions containing macro invocations, show the result of
5414 macro expansion, and show a macro's definition, including where it was
5417 You may need to compile your program specially to provide GDB with
5418 information about preprocessor macros. Most compilers do not include
5419 macros in their debugging information, even when you compile with the
5420 `-g' flag. *Note Compilation::.
5422 A program may define a macro at one point, remove that definition
5423 later, and then provide a different definition after that. Thus, at
5424 different points in the program, a macro may have different
5425 definitions, or have no definition at all. If there is a current stack
5426 frame, GDB uses the macros in scope at that frame's source code line.
5427 Otherwise, GDB uses the macros in scope at the current listing location;
5430 At the moment, GDB does not support the `##' token-splicing
5431 operator, the `#' stringification operator, or variable-arity macros.
5433 Whenever GDB evaluates an expression, it always expands any macro
5434 invocations present in the expression. GDB also provides the following
5435 commands for working with macros explicitly.
5437 `macro expand EXPRESSION'
5438 `macro exp EXPRESSION'
5439 Show the results of expanding all preprocessor macro invocations in
5440 EXPRESSION. Since GDB simply expands macros, but does not parse
5441 the result, EXPRESSION need not be a valid expression; it can be
5442 any string of tokens.
5444 `macro expand-once EXPRESSION'
5445 `macro exp1 EXPRESSION'
5446 (This command is not yet implemented.) Show the results of
5447 expanding those preprocessor macro invocations that appear
5448 explicitly in EXPRESSION. Macro invocations appearing in that
5449 expansion are left unchanged. This command allows you to see the
5450 effect of a particular macro more clearly, without being confused
5451 by further expansions. Since GDB simply expands macros, but does
5452 not parse the result, EXPRESSION need not be a valid expression; it
5453 can be any string of tokens.
5456 Show the definition of the macro named MACRO, and describe the
5457 source location where that definition was established.
5459 `macro define MACRO REPLACEMENT-LIST'
5460 `macro define MACRO(ARGLIST) REPLACEMENT-LIST'
5461 (This command is not yet implemented.) Introduce a definition for
5462 a preprocessor macro named MACRO, invocations of which are replaced
5463 by the tokens given in REPLACEMENT-LIST. The first form of this
5464 command defines an "object-like" macro, which takes no arguments;
5465 the second form defines a "function-like" macro, which takes the
5466 arguments given in ARGLIST.
5468 A definition introduced by this command is in scope in every
5469 expression evaluated in GDB, until it is removed with the `macro
5470 undef' command, described below. The definition overrides all
5471 definitions for MACRO present in the program being debugged, as
5472 well as any previous user-supplied definition.
5475 (This command is not yet implemented.) Remove any user-supplied
5476 definition for the macro named MACRO. This command only affects
5477 definitions provided with the `macro define' command, described
5478 above; it cannot remove definitions present in the program being
5482 Here is a transcript showing the above commands in action. First, we
5483 show our source files:
5490 #define ADD(x) (M + x)
5495 printf ("Hello, world!\n");
5497 printf ("We're so creative.\n");
5499 printf ("Goodbye, world!\n");
5505 Now, we compile the program using the GNU C compiler, GCC. We pass
5506 the `-gdwarf-2' and `-g3' flags to ensure the compiler includes
5507 information about preprocessor macros in the debugging information.
5509 $ gcc -gdwarf-2 -g3 sample.c -o sample
5512 Now, we start GDB on our sample program:
5515 GNU gdb 2002-05-06-cvs
5516 Copyright 2002 Free Software Foundation, Inc.
5517 GDB is free software, ...
5520 We can expand macros and examine their definitions, even when the
5521 program is not running. GDB uses the current listing position to
5522 decide which macro definitions are in scope:
5527 5 #define ADD(x) (M + x)
5532 10 printf ("Hello, world!\n");
5534 12 printf ("We're so creative.\n");
5535 (gdb) info macro ADD
5536 Defined at /home/jimb/gdb/macros/play/sample.c:5
5537 #define ADD(x) (M + x)
5539 Defined at /home/jimb/gdb/macros/play/sample.h:1
5540 included at /home/jimb/gdb/macros/play/sample.c:2
5542 (gdb) macro expand ADD(1)
5543 expands to: (42 + 1)
5544 (gdb) macro expand-once ADD(1)
5545 expands to: once (M + 1)
5548 In the example above, note that `macro expand-once' expands only the
5549 macro invocation explicit in the original text -- the invocation of
5550 `ADD' -- but does not expand the invocation of the macro `M', which was
5551 introduced by `ADD'.
5553 Once the program is running, GDB uses the macro definitions in force
5554 at the source line of the current stack frame:
5557 Breakpoint 1 at 0x8048370: file sample.c, line 10.
5559 Starting program: /home/jimb/gdb/macros/play/sample
5561 Breakpoint 1, main () at sample.c:10
5562 10 printf ("Hello, world!\n");
5565 At line 10, the definition of the macro `N' at line 9 is in force:
5568 Defined at /home/jimb/gdb/macros/play/sample.c:9
5570 (gdb) macro expand N Q M
5576 As we step over directives that remove `N''s definition, and then
5577 give it a new definition, GDB finds the definition (or lack thereof) in
5578 force at each point:
5582 12 printf ("We're so creative.\n");
5584 The symbol `N' has no definition as a C/C++ preprocessor macro
5585 at /home/jimb/gdb/macros/play/sample.c:12
5588 14 printf ("Goodbye, world!\n");
5590 Defined at /home/jimb/gdb/macros/play/sample.c:13
5592 (gdb) macro expand N Q M
5593 expands to: 1729 < 42
5599 File: gdb.info, Node: Tracepoints, Next: Overlays, Prev: Macros, Up: Top
5604 In some applications, it is not feasible for the debugger to interrupt
5605 the program's execution long enough for the developer to learn anything
5606 helpful about its behavior. If the program's correctness depends on
5607 its real-time behavior, delays introduced by a debugger might cause the
5608 program to change its behavior drastically, or perhaps fail, even when
5609 the code itself is correct. It is useful to be able to observe the
5610 program's behavior without interrupting it.
5612 Using GDB's `trace' and `collect' commands, you can specify
5613 locations in the program, called "tracepoints", and arbitrary
5614 expressions to evaluate when those tracepoints are reached. Later,
5615 using the `tfind' command, you can examine the values those expressions
5616 had when the program hit the tracepoints. The expressions may also
5617 denote objects in memory--structures or arrays, for example--whose
5618 values GDB should record; while visiting a particular tracepoint, you
5619 may inspect those objects as if they were in memory at that moment.
5620 However, because GDB records these values without interacting with you,
5621 it can do so quickly and unobtrusively, hopefully not disturbing the
5624 The tracepoint facility is currently available only for remote
5625 targets. *Note Targets::. In addition, your remote target must know
5626 how to collect trace data. This functionality is implemented in the
5627 remote stub; however, none of the stubs distributed with GDB support
5628 tracepoints as of this writing.
5630 This chapter describes the tracepoint commands and features.
5635 * Analyze Collected Data::
5636 * Tracepoint Variables::
5639 File: gdb.info, Node: Set Tracepoints, Next: Analyze Collected Data, Up: Tracepoints
5641 Commands to Set Tracepoints
5642 ===========================
5644 Before running such a "trace experiment", an arbitrary number of
5645 tracepoints can be set. Like a breakpoint (*note Set Breaks::), a
5646 tracepoint has a number assigned to it by GDB. Like with breakpoints,
5647 tracepoint numbers are successive integers starting from one. Many of
5648 the commands associated with tracepoints take the tracepoint number as
5649 their argument, to identify which tracepoint to work on.
5651 For each tracepoint, you can specify, in advance, some arbitrary set
5652 of data that you want the target to collect in the trace buffer when it
5653 hits that tracepoint. The collected data can include registers, local
5654 variables, or global data. Later, you can use GDB commands to examine
5655 the values these data had at the time the tracepoint was hit.
5657 This section describes commands to set tracepoints and associated
5658 conditions and actions.
5662 * Create and Delete Tracepoints::
5663 * Enable and Disable Tracepoints::
5664 * Tracepoint Passcounts::
5665 * Tracepoint Actions::
5666 * Listing Tracepoints::
5667 * Starting and Stopping Trace Experiment::
5670 File: gdb.info, Node: Create and Delete Tracepoints, Next: Enable and Disable Tracepoints, Up: Set Tracepoints
5672 Create and Delete Tracepoints
5673 -----------------------------
5676 The `trace' command is very similar to the `break' command. Its
5677 argument can be a source line, a function name, or an address in
5678 the target program. *Note Set Breaks::. The `trace' command
5679 defines a tracepoint, which is a point in the target program where
5680 the debugger will briefly stop, collect some data, and then allow
5681 the program to continue. Setting a tracepoint or changing its
5682 commands doesn't take effect until the next `tstart' command;
5683 thus, you cannot change the tracepoint attributes once a trace
5684 experiment is running.
5686 Here are some examples of using the `trace' command:
5688 (gdb) trace foo.c:121 // a source file and line number
5690 (gdb) trace +2 // 2 lines forward
5692 (gdb) trace my_function // first source line of function
5694 (gdb) trace *my_function // EXACT start address of function
5696 (gdb) trace *0x2117c4 // an address
5698 You can abbreviate `trace' as `tr'.
5700 The convenience variable `$tpnum' records the tracepoint number of
5701 the most recently set tracepoint.
5703 `delete tracepoint [NUM]'
5704 Permanently delete one or more tracepoints. With no argument, the
5705 default is to delete all tracepoints.
5709 (gdb) delete trace 1 2 3 // remove three tracepoints
5711 (gdb) delete trace // remove all tracepoints
5713 You can abbreviate this command as `del tr'.
5716 File: gdb.info, Node: Enable and Disable Tracepoints, Next: Tracepoint Passcounts, Prev: Create and Delete Tracepoints, Up: Set Tracepoints
5718 Enable and Disable Tracepoints
5719 ------------------------------
5721 `disable tracepoint [NUM]'
5722 Disable tracepoint NUM, or all tracepoints if no argument NUM is
5723 given. A disabled tracepoint will have no effect during the next
5724 trace experiment, but it is not forgotten. You can re-enable a
5725 disabled tracepoint using the `enable tracepoint' command.
5727 `enable tracepoint [NUM]'
5728 Enable tracepoint NUM, or all tracepoints. The enabled
5729 tracepoints will become effective the next time a trace experiment
5733 File: gdb.info, Node: Tracepoint Passcounts, Next: Tracepoint Actions, Prev: Enable and Disable Tracepoints, Up: Set Tracepoints
5735 Tracepoint Passcounts
5736 ---------------------
5738 `passcount [N [NUM]]'
5739 Set the "passcount" of a tracepoint. The passcount is a way to
5740 automatically stop a trace experiment. If a tracepoint's
5741 passcount is N, then the trace experiment will be automatically
5742 stopped on the N'th time that tracepoint is hit. If the
5743 tracepoint number NUM is not specified, the `passcount' command
5744 sets the passcount of the most recently defined tracepoint. If no
5745 passcount is given, the trace experiment will run until stopped
5746 explicitly by the user.
5750 (gdb) passcount 5 2 // Stop on the 5th execution of
5753 (gdb) passcount 12 // Stop on the 12th execution of the
5754 `// most recently defined tracepoint.'
5760 (gdb) pass 1 // Stop tracing when foo has been
5761 `// executed 3 times OR when bar has'
5762 `// been executed 2 times'
5763 `// OR when baz has been executed 1 time.'
5767 File: gdb.info, Node: Tracepoint Actions, Next: Listing Tracepoints, Prev: Tracepoint Passcounts, Up: Set Tracepoints
5769 Tracepoint Action Lists
5770 -----------------------
5773 This command will prompt for a list of actions to be taken when the
5774 tracepoint is hit. If the tracepoint number NUM is not specified,
5775 this command sets the actions for the one that was most recently
5776 defined (so that you can define a tracepoint and then say
5777 `actions' without bothering about its number). You specify the
5778 actions themselves on the following lines, one action at a time,
5779 and terminate the actions list with a line containing just `end'.
5780 So far, the only defined actions are `collect' and
5783 To remove all actions from a tracepoint, type `actions NUM' and
5784 follow it immediately with `end'.
5786 (gdb) collect DATA // collect some data
5788 (gdb) while-stepping 5 // single-step 5 times, collect data
5790 (gdb) end // signals the end of actions.
5792 In the following example, the action list begins with `collect'
5793 commands indicating the things to be collected when the tracepoint
5794 is hit. Then, in order to single-step and collect additional data
5795 following the tracepoint, a `while-stepping' command is used,
5796 followed by the list of things to be collected while stepping. The
5797 `while-stepping' command is terminated by its own separate `end'
5798 command. Lastly, the action list is terminated by an `end'
5803 Enter actions for tracepoint 1, one per line:
5811 `collect EXPR1, EXPR2, ...'
5812 Collect values of the given expressions when the tracepoint is hit.
5813 This command accepts a comma-separated list of any valid
5814 expressions. In addition to global, static, or local variables,
5815 the following special arguments are supported:
5818 collect all registers
5821 collect all function arguments
5824 collect all local variables.
5826 You can give several consecutive `collect' commands, each one with
5827 a single argument, or one `collect' command with several arguments
5828 separated by commas: the effect is the same.
5830 The command `info scope' (*note info scope: Symbols.) is
5831 particularly useful for figuring out what data to collect.
5834 Perform N single-step traces after the tracepoint, collecting new
5835 data at each step. The `while-stepping' command is followed by
5836 the list of what to collect while stepping (followed by its own
5840 > collect $regs, myglobal
5844 You may abbreviate `while-stepping' as `ws' or `stepping'.
5847 File: gdb.info, Node: Listing Tracepoints, Next: Starting and Stopping Trace Experiment, Prev: Tracepoint Actions, Up: Set Tracepoints
5852 `info tracepoints [NUM]'
5853 Display information about the tracepoint NUM. If you don't specify
5854 a tracepoint number, displays information about all the tracepoints
5855 defined so far. For each tracepoint, the following information is
5860 * whether it is enabled or disabled
5864 * its passcount as given by the `passcount N' command
5866 * its step count as given by the `while-stepping N' command
5868 * where in the source files is the tracepoint set
5870 * its action list as given by the `actions' command
5873 Num Enb Address PassC StepC What
5874 1 y 0x002117c4 0 0 <gdb_asm>
5875 2 y 0x0020dc64 0 0 in g_test at g_test.c:1375
5876 3 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
5879 This command can be abbreviated `info tp'.
5882 File: gdb.info, Node: Starting and Stopping Trace Experiment, Prev: Listing Tracepoints, Up: Set Tracepoints
5884 Starting and Stopping Trace Experiment
5885 --------------------------------------
5888 This command takes no arguments. It starts the trace experiment,
5889 and begins collecting data. This has the side effect of
5890 discarding all the data collected in the trace buffer during the
5891 previous trace experiment.
5894 This command takes no arguments. It ends the trace experiment, and
5895 stops collecting data.
5897 *Note:* a trace experiment and data collection may stop
5898 automatically if any tracepoint's passcount is reached (*note
5899 Tracepoint Passcounts::), or if the trace buffer becomes full.
5902 This command displays the status of the current trace data
5905 Here is an example of the commands we described so far:
5907 (gdb) trace gdb_c_test
5909 Enter actions for tracepoint #1, one per line.
5910 > collect $regs,$locals,$args
5920 File: gdb.info, Node: Analyze Collected Data, Next: Tracepoint Variables, Prev: Set Tracepoints, Up: Tracepoints
5922 Using the collected data
5923 ========================
5925 After the tracepoint experiment ends, you use GDB commands for
5926 examining the trace data. The basic idea is that each tracepoint
5927 collects a trace "snapshot" every time it is hit and another snapshot
5928 every time it single-steps. All these snapshots are consecutively
5929 numbered from zero and go into a buffer, and you can examine them
5930 later. The way you examine them is to "focus" on a specific trace
5931 snapshot. When the remote stub is focused on a trace snapshot, it will
5932 respond to all GDB requests for memory and registers by reading from
5933 the buffer which belongs to that snapshot, rather than from _real_
5934 memory or registers of the program being debugged. This means that
5935 *all* GDB commands (`print', `info registers', `backtrace', etc.) will
5936 behave as if we were currently debugging the program state as it was
5937 when the tracepoint occurred. Any requests for data that are not in
5938 the buffer will fail.
5942 * tfind:: How to select a trace snapshot
5943 * tdump:: How to display all data for a snapshot
5944 * save-tracepoints:: How to save tracepoints for a future run
5947 File: gdb.info, Node: tfind, Next: tdump, Up: Analyze Collected Data
5952 The basic command for selecting a trace snapshot from the buffer is
5953 `tfind N', which finds trace snapshot number N, counting from zero. If
5954 no argument N is given, the next snapshot is selected.
5956 Here are the various forms of using the `tfind' command.
5959 Find the first snapshot in the buffer. This is a synonym for
5960 `tfind 0' (since 0 is the number of the first snapshot).
5963 Stop debugging trace snapshots, resume _live_ debugging.
5966 Same as `tfind none'.
5969 No argument means find the next trace snapshot.
5972 Find the previous trace snapshot before the current one. This
5973 permits retracing earlier steps.
5975 `tfind tracepoint NUM'
5976 Find the next snapshot associated with tracepoint NUM. Search
5977 proceeds forward from the last examined trace snapshot. If no
5978 argument NUM is given, it means find the next snapshot collected
5979 for the same tracepoint as the current snapshot.
5982 Find the next snapshot associated with the value ADDR of the
5983 program counter. Search proceeds forward from the last examined
5984 trace snapshot. If no argument ADDR is given, it means find the
5985 next snapshot with the same value of PC as the current snapshot.
5987 `tfind outside ADDR1, ADDR2'
5988 Find the next snapshot whose PC is outside the given range of
5991 `tfind range ADDR1, ADDR2'
5992 Find the next snapshot whose PC is between ADDR1 and ADDR2.
5994 `tfind line [FILE:]N'
5995 Find the next snapshot associated with the source line N. If the
5996 optional argument FILE is given, refer to line N in that source
5997 file. Search proceeds forward from the last examined trace
5998 snapshot. If no argument N is given, it means find the next line
5999 other than the one currently being examined; thus saying `tfind
6000 line' repeatedly can appear to have the same effect as stepping
6001 from line to line in a _live_ debugging session.
6003 The default arguments for the `tfind' commands are specifically
6004 designed to make it easy to scan through the trace buffer. For
6005 instance, `tfind' with no argument selects the next trace snapshot, and
6006 `tfind -' with no argument selects the previous trace snapshot. So, by
6007 giving one `tfind' command, and then simply hitting <RET> repeatedly
6008 you can examine all the trace snapshots in order. Or, by saying `tfind
6009 -' and then hitting <RET> repeatedly you can examine the snapshots in
6010 reverse order. The `tfind line' command with no argument selects the
6011 snapshot for the next source line executed. The `tfind pc' command with
6012 no argument selects the next snapshot with the same program counter
6013 (PC) as the current frame. The `tfind tracepoint' command with no
6014 argument selects the next trace snapshot collected by the same
6015 tracepoint as the current one.
6017 In addition to letting you scan through the trace buffer manually,
6018 these commands make it easy to construct GDB scripts that scan through
6019 the trace buffer and print out whatever collected data you are
6020 interested in. Thus, if we want to examine the PC, FP, and SP
6021 registers from each trace frame in the buffer, we can say this:
6024 (gdb) while ($trace_frame != -1)
6025 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
6026 $trace_frame, $pc, $sp, $fp
6030 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
6031 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
6032 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
6033 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
6034 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
6035 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
6036 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
6037 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
6038 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
6039 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
6040 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
6042 Or, if we want to examine the variable `X' at each source line in
6046 (gdb) while ($trace_frame != -1)
6047 > printf "Frame %d, X == %d\n", $trace_frame, X
6056 File: gdb.info, Node: tdump, Next: save-tracepoints, Prev: tfind, Up: Analyze Collected Data
6061 This command takes no arguments. It prints all the data collected at
6062 the current trace snapshot.
6066 Enter actions for tracepoint #2, one per line:
6067 > collect $regs, $locals, $args, gdb_long_test
6072 (gdb) tfind line 444
6073 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
6075 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
6078 Data collected at tracepoint 2, trace frame 1:
6079 d0 0xc4aa0085 -995491707
6083 d4 0x71aea3d 119204413
6088 a1 0x3000668 50333288
6091 a4 0x3000698 50333336
6093 fp 0x30bf3c 0x30bf3c
6094 sp 0x30bf34 0x30bf34
6096 pc 0x20b2c8 0x20b2c8
6100 p = 0x20e5b4 "gdb-test"
6107 gdb_long_test = 17 '\021'
6112 File: gdb.info, Node: save-tracepoints, Prev: tdump, Up: Analyze Collected Data
6114 `save-tracepoints FILENAME'
6115 ---------------------------
6117 This command saves all current tracepoint definitions together with
6118 their actions and passcounts, into a file `FILENAME' suitable for use
6119 in a later debugging session. To read the saved tracepoint
6120 definitions, use the `source' command (*note Command Files::).
6123 File: gdb.info, Node: Tracepoint Variables, Prev: Analyze Collected Data, Up: Tracepoints
6125 Convenience Variables for Tracepoints
6126 =====================================
6128 `(int) $trace_frame'
6129 The current trace snapshot (a.k.a. "frame") number, or -1 if no
6130 snapshot is selected.
6133 The tracepoint for the current trace snapshot.
6136 The line number for the current trace snapshot.
6138 `(char []) $trace_file'
6139 The source file for the current trace snapshot.
6141 `(char []) $trace_func'
6142 The name of the function containing `$tracepoint'.
6144 Note: `$trace_file' is not suitable for use in `printf', use
6147 Here's a simple example of using these convenience variables for
6148 stepping through all the trace snapshots and printing some of their
6153 (gdb) while $trace_frame != -1
6154 > output $trace_file
6155 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
6160 File: gdb.info, Node: Overlays, Next: Languages, Prev: Tracepoints, Up: Top
6162 Debugging Programs That Use Overlays
6163 ************************************
6165 If your program is too large to fit completely in your target system's
6166 memory, you can sometimes use "overlays" to work around this problem.
6167 GDB provides some support for debugging programs that use overlays.
6171 * How Overlays Work:: A general explanation of overlays.
6172 * Overlay Commands:: Managing overlays in GDB.
6173 * Automatic Overlay Debugging:: GDB can find out which overlays are
6174 mapped by asking the inferior.
6175 * Overlay Sample Program:: A sample program using overlays.
6178 File: gdb.info, Node: How Overlays Work, Next: Overlay Commands, Up: Overlays
6183 Suppose you have a computer whose instruction address space is only 64
6184 kilobytes long, but which has much more memory which can be accessed by
6185 other means: special instructions, segment registers, or memory
6186 management hardware, for example. Suppose further that you want to
6187 adapt a program which is larger than 64 kilobytes to run on this system.
6189 One solution is to identify modules of your program which are
6190 relatively independent, and need not call each other directly; call
6191 these modules "overlays". Separate the overlays from the main program,
6192 and place their machine code in the larger memory. Place your main
6193 program in instruction memory, but leave at least enough space there to
6194 hold the largest overlay as well.
6196 Now, to call a function located in an overlay, you must first copy
6197 that overlay's machine code from the large memory into the space set
6198 aside for it in the instruction memory, and then jump to its entry point
6201 Data Instruction Larger
6202 Address Space Address Space Address Space
6203 +-----------+ +-----------+ +-----------+
6205 +-----------+ +-----------+ +-----------+<-- overlay 1
6206 | program | | main | .----| overlay 1 | load address
6207 | variables | | program | | +-----------+
6208 | and heap | | | | | |
6209 +-----------+ | | | +-----------+<-- overlay 2
6210 | | +-----------+ | | | load address
6211 +-----------+ | | | .-| overlay 2 |
6213 mapped --->+-----------+ | | +-----------+
6215 | overlay | <-' | | |
6216 | area | <---' +-----------+<-- overlay 3
6217 | | <---. | | load address
6218 +-----------+ `--| overlay 3 |
6227 The diagram (*note A code overlay::) shows a system with separate
6228 data and instruction address spaces. To map an overlay, the program
6229 copies its code from the larger address space to the instruction
6230 address space. Since the overlays shown here all use the same mapped
6231 address, only one may be mapped at a time. For a system with a single
6232 address space for data and instructions, the diagram would be similar,
6233 except that the program variables and heap would share an address space
6234 with the main program and the overlay area.
6236 An overlay loaded into instruction memory and ready for use is
6237 called a "mapped" overlay; its "mapped address" is its address in the
6238 instruction memory. An overlay not present (or only partially present)
6239 in instruction memory is called "unmapped"; its "load address" is its
6240 address in the larger memory. The mapped address is also called the
6241 "virtual memory address", or "VMA"; the load address is also called the
6242 "load memory address", or "LMA".
6244 Unfortunately, overlays are not a completely transparent way to
6245 adapt a program to limited instruction memory. They introduce a new
6246 set of global constraints you must keep in mind as you design your
6249 * Before calling or returning to a function in an overlay, your
6250 program must make sure that overlay is actually mapped.
6251 Otherwise, the call or return will transfer control to the right
6252 address, but in the wrong overlay, and your program will probably
6255 * If the process of mapping an overlay is expensive on your system,
6256 you will need to choose your overlays carefully to minimize their
6257 effect on your program's performance.
6259 * The executable file you load onto your system must contain each
6260 overlay's instructions, appearing at the overlay's load address,
6261 not its mapped address. However, each overlay's instructions must
6262 be relocated and its symbols defined as if the overlay were at its
6263 mapped address. You can use GNU linker scripts to specify
6264 different load and relocation addresses for pieces of your
6265 program; see *Note Overlay Description: (ld.info)Overlay
6268 * The procedure for loading executable files onto your system must
6269 be able to load their contents into the larger address space as
6270 well as the instruction and data spaces.
6273 The overlay system described above is rather simple, and could be
6274 improved in many ways:
6276 * If your system has suitable bank switch registers or memory
6277 management hardware, you could use those facilities to make an
6278 overlay's load area contents simply appear at their mapped address
6279 in instruction space. This would probably be faster than copying
6280 the overlay to its mapped area in the usual way.
6282 * If your overlays are small enough, you could set aside more than
6283 one overlay area, and have more than one overlay mapped at a time.
6285 * You can use overlays to manage data, as well as instructions. In
6286 general, data overlays are even less transparent to your design
6287 than code overlays: whereas code overlays only require care when
6288 you call or return to functions, data overlays require care every
6289 time you access the data. Also, if you change the contents of a
6290 data overlay, you must copy its contents back out to its load
6291 address before you can copy a different data overlay into the same
6296 File: gdb.info, Node: Overlay Commands, Next: Automatic Overlay Debugging, Prev: How Overlays Work, Up: Overlays
6301 To use GDB's overlay support, each overlay in your program must
6302 correspond to a separate section of the executable file. The section's
6303 virtual memory address and load memory address must be the overlay's
6304 mapped and load addresses. Identifying overlays with sections allows
6305 GDB to determine the appropriate address of a function or variable,
6306 depending on whether the overlay is mapped or not.
6308 GDB's overlay commands all start with the word `overlay'; you can
6309 abbreviate this as `ov' or `ovly'. The commands are:
6312 Disable GDB's overlay support. When overlay support is disabled,
6313 GDB assumes that all functions and variables are always present at
6314 their mapped addresses. By default, GDB's overlay support is
6318 Enable "manual" overlay debugging. In this mode, GDB relies on
6319 you to tell it which overlays are mapped, and which are not, using
6320 the `overlay map-overlay' and `overlay unmap-overlay' commands
6323 `overlay map-overlay OVERLAY'
6324 `overlay map OVERLAY'
6325 Tell GDB that OVERLAY is now mapped; OVERLAY must be the name of
6326 the object file section containing the overlay. When an overlay
6327 is mapped, GDB assumes it can find the overlay's functions and
6328 variables at their mapped addresses. GDB assumes that any other
6329 overlays whose mapped ranges overlap that of OVERLAY are now
6332 `overlay unmap-overlay OVERLAY'
6333 `overlay unmap OVERLAY'
6334 Tell GDB that OVERLAY is no longer mapped; OVERLAY must be the
6335 name of the object file section containing the overlay. When an
6336 overlay is unmapped, GDB assumes it can find the overlay's
6337 functions and variables at their load addresses.
6340 Enable "automatic" overlay debugging. In this mode, GDB consults
6341 a data structure the overlay manager maintains in the inferior to
6342 see which overlays are mapped. For details, see *Note Automatic
6343 Overlay Debugging::.
6345 `overlay load-target'
6347 Re-read the overlay table from the inferior. Normally, GDB
6348 re-reads the table GDB automatically each time the inferior stops,
6349 so this command should only be necessary if you have changed the
6350 overlay mapping yourself using GDB. This command is only useful
6351 when using automatic overlay debugging.
6353 `overlay list-overlays'
6355 Display a list of the overlays currently mapped, along with their
6356 mapped addresses, load addresses, and sizes.
6359 Normally, when GDB prints a code address, it includes the name of
6360 the function the address falls in:
6363 $3 = {int ()} 0x11a0 <main>
6365 When overlay debugging is enabled, GDB recognizes code in unmapped
6366 overlays, and prints the names of unmapped functions with asterisks
6367 around them. For example, if `foo' is a function in an unmapped
6368 overlay, GDB prints it this way:
6371 No sections are mapped.
6373 $5 = {int (int)} 0x100000 <*foo*>
6375 When `foo''s overlay is mapped, GDB prints the function's name normally:
6378 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
6379 mapped at 0x1016 - 0x104a
6381 $6 = {int (int)} 0x1016 <foo>
6383 When overlay debugging is enabled, GDB can find the correct address
6384 for functions and variables in an overlay, whether or not the overlay
6385 is mapped. This allows most GDB commands, like `break' and
6386 `disassemble', to work normally, even on unmapped code. However, GDB's
6387 breakpoint support has some limitations:
6389 * You can set breakpoints in functions in unmapped overlays, as long
6390 as GDB can write to the overlay at its load address.
6392 * GDB can not set hardware or simulator-based breakpoints in
6393 unmapped overlays. However, if you set a breakpoint at the end of
6394 your overlay manager (and tell GDB which overlays are now mapped,
6395 if you are using manual overlay management), GDB will re-set its
6396 breakpoints properly.
6399 File: gdb.info, Node: Automatic Overlay Debugging, Next: Overlay Sample Program, Prev: Overlay Commands, Up: Overlays
6401 Automatic Overlay Debugging
6402 ===========================
6404 GDB can automatically track which overlays are mapped and which are
6405 not, given some simple co-operation from the overlay manager in the
6406 inferior. If you enable automatic overlay debugging with the `overlay
6407 auto' command (*note Overlay Commands::), GDB looks in the inferior's
6408 memory for certain variables describing the current state of the
6411 Here are the variables your overlay manager must define to support
6412 GDB's automatic overlay debugging:
6415 This variable must be an array of the following structures:
6419 /* The overlay's mapped address. */
6422 /* The size of the overlay, in bytes. */
6425 /* The overlay's load address. */
6428 /* Non-zero if the overlay is currently mapped;
6430 unsigned long mapped;
6434 This variable must be a four-byte signed integer, holding the total
6435 number of elements in `_ovly_table'.
6438 To decide whether a particular overlay is mapped or not, GDB looks
6439 for an entry in `_ovly_table' whose `vma' and `lma' members equal the
6440 VMA and LMA of the overlay's section in the executable file. When GDB
6441 finds a matching entry, it consults the entry's `mapped' member to
6442 determine whether the overlay is currently mapped.
6444 In addition, your overlay manager may define a function called
6445 `_ovly_debug_event'. If this function is defined, GDB will silently
6446 set a breakpoint there. If the overlay manager then calls this
6447 function whenever it has changed the overlay table, this will enable
6448 GDB to accurately keep track of which overlays are in program memory,
6449 and update any breakpoints that may be set in overlays. This will
6450 allow breakpoints to work even if the overlays are kept in ROM or other
6451 non-writable memory while they are not being executed.
6454 File: gdb.info, Node: Overlay Sample Program, Prev: Automatic Overlay Debugging, Up: Overlays
6456 Overlay Sample Program
6457 ======================
6459 When linking a program which uses overlays, you must place the overlays
6460 at their load addresses, while relocating them to run at their mapped
6461 addresses. To do this, you must write a linker script (*note Overlay
6462 Description: (ld.info)Overlay Description.). Unfortunately, since
6463 linker scripts are specific to a particular host system, target
6464 architecture, and target memory layout, this manual cannot provide
6465 portable sample code demonstrating GDB's overlay support.
6467 However, the GDB source distribution does contain an overlaid
6468 program, with linker scripts for a few systems, as part of its test
6469 suite. The program consists of the following files from
6470 `gdb/testsuite/gdb.base':
6473 The main program file.
6476 A simple overlay manager, used by `overlays.c'.
6482 Overlay modules, loaded and used by `overlays.c'.
6486 Linker scripts for linking the test program on the `d10v-elf' and
6489 You can build the test program using the `d10v-elf' GCC
6490 cross-compiler like this:
6492 $ d10v-elf-gcc -g -c overlays.c
6493 $ d10v-elf-gcc -g -c ovlymgr.c
6494 $ d10v-elf-gcc -g -c foo.c
6495 $ d10v-elf-gcc -g -c bar.c
6496 $ d10v-elf-gcc -g -c baz.c
6497 $ d10v-elf-gcc -g -c grbx.c
6498 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
6499 baz.o grbx.o -Wl,-Td10v.ld -o overlays
6501 The build process is identical for any other architecture, except
6502 that you must substitute the appropriate compiler and linker script for
6503 the target system for `d10v-elf-gcc' and `d10v.ld'.
6506 File: gdb.info, Node: Languages, Next: Symbols, Prev: Overlays, Up: Top
6508 Using GDB with Different Languages
6509 **********************************
6511 Although programming languages generally have common aspects, they are
6512 rarely expressed in the same manner. For instance, in ANSI C,
6513 dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
6514 it is accomplished by `p^'. Values can also be represented (and
6515 displayed) differently. Hex numbers in C appear as `0x1ae', while in
6516 Modula-2 they appear as `1AEH'.
6518 Language-specific information is built into GDB for some languages,
6519 allowing you to express operations like the above in your program's
6520 native language, and allowing GDB to output values in a manner
6521 consistent with the syntax of your program's native language. The
6522 language you use to build expressions is called the "working language".
6526 * Setting:: Switching between source languages
6527 * Show:: Displaying the language
6528 * Checks:: Type and range checks
6529 * Support:: Supported languages
6530 * Unsupported languages:: Unsupported languages
6533 File: gdb.info, Node: Setting, Next: Show, Up: Languages
6535 Switching between source languages
6536 ==================================
6538 There are two ways to control the working language--either have GDB set
6539 it automatically, or select it manually yourself. You can use the `set
6540 language' command for either purpose. On startup, GDB defaults to
6541 setting the language automatically. The working language is used to
6542 determine how expressions you type are interpreted, how values are
6545 In addition to the working language, every source file that GDB
6546 knows about has its own working language. For some object file
6547 formats, the compiler might indicate which language a particular source
6548 file is in. However, most of the time GDB infers the language from the
6549 name of the file. The language of a source file controls whether C++
6550 names are demangled--this way `backtrace' can show each frame
6551 appropriately for its own language. There is no way to set the
6552 language of a source file from within GDB, but you can set the language
6553 associated with a filename extension. *Note Displaying the language:
6556 This is most commonly a problem when you use a program, such as
6557 `cfront' or `f2c', that generates C but is written in another language.
6558 In that case, make the program use `#line' directives in its C output;
6559 that way GDB will know the correct language of the source code of the
6560 original program, and will display that source code, not the generated
6565 * Filenames:: Filename extensions and languages.
6566 * Manually:: Setting the working language manually
6567 * Automatically:: Having GDB infer the source language
6570 File: gdb.info, Node: Filenames, Next: Manually, Up: Setting
6572 List of filename extensions and languages
6573 -----------------------------------------
6575 If a source file name ends in one of the following extensions, then GDB
6576 infers that its language is the one indicated.
6590 Objective-C source file
6597 Modula-2 source file
6601 Assembler source file. This actually behaves almost like C, but
6602 GDB does not skip over function prologues when stepping.
6604 In addition, you may set the language associated with a filename
6605 extension. *Note Displaying the language: Show.
6608 File: gdb.info, Node: Manually, Next: Automatically, Prev: Filenames, Up: Setting
6610 Setting the working language
6611 ----------------------------
6613 If you allow GDB to set the language automatically, expressions are
6614 interpreted the same way in your debugging session and your program.
6616 If you wish, you may set the language manually. To do this, issue
6617 the command `set language LANG', where LANG is the name of a language,
6618 such as `c' or `modula-2'. For a list of the supported languages, type
6621 Setting the language manually prevents GDB from updating the working
6622 language automatically. This can lead to confusion if you try to debug
6623 a program when the working language is not the same as the source
6624 language, when an expression is acceptable to both languages--but means
6625 different things. For instance, if the current source file were
6626 written in C, and GDB was parsing Modula-2, a command such as:
6630 might not have the effect you intended. In C, this means to add `b'
6631 and `c' and place the result in `a'. The result printed would be the
6632 value of `a'. In Modula-2, this means to compare `a' to the result of
6633 `b+c', yielding a `BOOLEAN' value.
6636 File: gdb.info, Node: Automatically, Prev: Manually, Up: Setting
6638 Having GDB infer the source language
6639 ------------------------------------
6641 To have GDB set the working language automatically, use `set language
6642 local' or `set language auto'. GDB then infers the working language.
6643 That is, when your program stops in a frame (usually by encountering a
6644 breakpoint), GDB sets the working language to the language recorded for
6645 the function in that frame. If the language for a frame is unknown
6646 (that is, if the function or block corresponding to the frame was
6647 defined in a source file that does not have a recognized extension),
6648 the current working language is not changed, and GDB issues a warning.
6650 This may not seem necessary for most programs, which are written
6651 entirely in one source language. However, program modules and libraries
6652 written in one source language can be used by a main program written in
6653 a different source language. Using `set language auto' in this case
6654 frees you from having to set the working language manually.
6657 File: gdb.info, Node: Show, Next: Checks, Prev: Setting, Up: Languages
6659 Displaying the language
6660 =======================
6662 The following commands help you find out which language is the working
6663 language, and also what language source files were written in.
6666 Display the current working language. This is the language you
6667 can use with commands such as `print' to build and compute
6668 expressions that may involve variables in your program.
6671 Display the source language for this frame. This language becomes
6672 the working language if you use an identifier from this frame.
6673 *Note Information about a frame: Frame Info, to identify the other
6674 information listed here.
6677 Display the source language of this source file. *Note Examining
6678 the Symbol Table: Symbols, to identify the other information
6681 In unusual circumstances, you may have source files with extensions
6682 not in the standard list. You can then set the extension associated
6683 with a language explicitly:
6685 `set extension-language .EXT LANGUAGE'
6686 Set source files with extension .EXT to be assumed to be in the
6687 source language LANGUAGE.
6690 List all the filename extensions and the associated languages.
6693 File: gdb.info, Node: Checks, Next: Support, Prev: Show, Up: Languages
6695 Type and range checking
6696 =======================
6698 _Warning:_ In this release, the GDB commands for type and range
6699 checking are included, but they do not yet have any effect. This
6700 section documents the intended facilities.
6702 Some languages are designed to guard you against making seemingly
6703 common errors through a series of compile- and run-time checks. These
6704 include checking the type of arguments to functions and operators, and
6705 making sure mathematical overflows are caught at run time. Checks such
6706 as these help to ensure a program's correctness once it has been
6707 compiled by eliminating type mismatches, and providing active checks
6708 for range errors when your program is running.
6710 GDB can check for conditions like the above if you wish. Although
6711 GDB does not check the statements in your program, it can check
6712 expressions entered directly into GDB for evaluation via the `print'
6713 command, for example. As with the working language, GDB can also
6714 decide whether or not to check automatically based on your program's
6715 source language. *Note Supported languages: Support, for the default
6716 settings of supported languages.
6720 * Type Checking:: An overview of type checking
6721 * Range Checking:: An overview of range checking
6724 File: gdb.info, Node: Type Checking, Next: Range Checking, Up: Checks
6726 An overview of type checking
6727 ----------------------------
6729 Some languages, such as Modula-2, are strongly typed, meaning that the
6730 arguments to operators and functions have to be of the correct type,
6731 otherwise an error occurs. These checks prevent type mismatch errors
6732 from ever causing any run-time problems. For example,
6738 The second example fails because the `CARDINAL' 1 is not
6739 type-compatible with the `REAL' 2.3.
6741 For the expressions you use in GDB commands, you can tell the GDB
6742 type checker to skip checking; to treat any mismatches as errors and
6743 abandon the expression; or to only issue warnings when type mismatches
6744 occur, but evaluate the expression anyway. When you choose the last of
6745 these, GDB evaluates expressions like the second example above, but
6746 also issues a warning.
6748 Even if you turn type checking off, there may be other reasons
6749 related to type that prevent GDB from evaluating an expression. For
6750 instance, GDB does not know how to add an `int' and a `struct foo'.
6751 These particular type errors have nothing to do with the language in
6752 use, and usually arise from expressions, such as the one described
6753 above, which make little sense to evaluate anyway.
6755 Each language defines to what degree it is strict about type. For
6756 instance, both Modula-2 and C require the arguments to arithmetical
6757 operators to be numbers. In C, enumerated types and pointers can be
6758 represented as numbers, so that they are valid arguments to mathematical
6759 operators. *Note Supported languages: Support, for further details on
6762 GDB provides some additional commands for controlling the type
6765 `set check type auto'
6766 Set type checking on or off based on the current working language.
6767 *Note Supported languages: Support, for the default settings for
6771 `set check type off'
6772 Set type checking on or off, overriding the default setting for the
6773 current working language. Issue a warning if the setting does not
6774 match the language default. If any type mismatches occur in
6775 evaluating an expression while type checking is on, GDB prints a
6776 message and aborts evaluation of the expression.
6778 `set check type warn'
6779 Cause the type checker to issue warnings, but to always attempt to
6780 evaluate the expression. Evaluating the expression may still be
6781 impossible for other reasons. For example, GDB cannot add numbers
6785 Show the current setting of the type checker, and whether or not
6786 GDB is setting it automatically.
6789 File: gdb.info, Node: Range Checking, Prev: Type Checking, Up: Checks
6791 An overview of range checking
6792 -----------------------------
6794 In some languages (such as Modula-2), it is an error to exceed the
6795 bounds of a type; this is enforced with run-time checks. Such range
6796 checking is meant to ensure program correctness by making sure
6797 computations do not overflow, or indices on an array element access do
6798 not exceed the bounds of the array.
6800 For expressions you use in GDB commands, you can tell GDB to treat
6801 range errors in one of three ways: ignore them, always treat them as
6802 errors and abandon the expression, or issue warnings but evaluate the
6805 A range error can result from numerical overflow, from exceeding an
6806 array index bound, or when you type a constant that is not a member of
6807 any type. Some languages, however, do not treat overflows as an error.
6808 In many implementations of C, mathematical overflow causes the result
6809 to "wrap around" to lower values--for example, if M is the largest
6810 integer value, and S is the smallest, then
6814 This, too, is specific to individual languages, and in some cases
6815 specific to individual compilers or machines. *Note Supported
6816 languages: Support, for further details on specific languages.
6818 GDB provides some additional commands for controlling the range
6821 `set check range auto'
6822 Set range checking on or off based on the current working language.
6823 *Note Supported languages: Support, for the default settings for
6826 `set check range on'
6827 `set check range off'
6828 Set range checking on or off, overriding the default setting for
6829 the current working language. A warning is issued if the setting
6830 does not match the language default. If a range error occurs and
6831 range checking is on, then a message is printed and evaluation of
6832 the expression is aborted.
6834 `set check range warn'
6835 Output messages when the GDB range checker detects a range error,
6836 but attempt to evaluate the expression anyway. Evaluating the
6837 expression may still be impossible for other reasons, such as
6838 accessing memory that the process does not own (a typical example
6839 from many Unix systems).
6842 Show the current setting of the range checker, and whether or not
6843 it is being set automatically by GDB.
6846 File: gdb.info, Node: Support, Next: Unsupported languages, Prev: Checks, Up: Languages
6851 GDB supports C, C++, Objective-C, Fortran, Java, assembly, and Modula-2.
6852 Some GDB features may be used in expressions regardless of the language
6853 you use: the GDB `@' and `::' operators, and the `{type}addr' construct
6854 (*note Expressions: Expressions.) can be used with the constructs of
6855 any supported language.
6857 The following sections detail to what degree each source language is
6858 supported by GDB. These sections are not meant to be language
6859 tutorials or references, but serve only as a reference guide to what the
6860 GDB expression parser accepts, and what input and output formats should
6861 look like for different languages. There are many good books written
6862 on each of these languages; please look to these for a language
6863 reference or tutorial.
6868 * Objective-C:: Objective-C
6869 * Modula-2:: Modula-2
6872 File: gdb.info, Node: C, Next: Objective-C, Up: Support
6877 Since C and C++ are so closely related, many features of GDB apply to
6878 both languages. Whenever this is the case, we discuss those languages
6881 The C++ debugging facilities are jointly implemented by the C++
6882 compiler and GDB. Therefore, to debug your C++ code effectively, you
6883 must compile your C++ programs with a supported C++ compiler, such as
6884 GNU `g++', or the HP ANSI C++ compiler (`aCC').
6886 For best results when using GNU C++, use the DWARF 2 debugging
6887 format; if it doesn't work on your system, try the stabs+ debugging
6888 format. You can select those formats explicitly with the `g++'
6889 command-line options `-gdwarf-2' and `-gstabs+'. *Note Options for
6890 Debugging Your Program or GNU CC: (gcc.info)Debugging Options.
6894 * C Operators:: C and C++ operators
6895 * C Constants:: C and C++ constants
6896 * C plus plus expressions:: C++ expressions
6897 * C Defaults:: Default settings for C and C++
6898 * C Checks:: C and C++ type and range checks
6899 * Debugging C:: GDB and C
6900 * Debugging C plus plus:: GDB features for C++
6903 File: gdb.info, Node: C Operators, Next: C Constants, Up: C
6908 Operators must be defined on values of specific types. For instance,
6909 `+' is defined on numbers, but not on structures. Operators are often
6910 defined on groups of types.
6912 For the purposes of C and C++, the following definitions hold:
6914 * _Integral types_ include `int' with any of its storage-class
6915 specifiers; `char'; `enum'; and, for C++, `bool'.
6917 * _Floating-point types_ include `float', `double', and `long
6918 double' (if supported by the target platform).
6920 * _Pointer types_ include all types defined as `(TYPE *)'.
6922 * _Scalar types_ include all of the above.
6925 The following operators are supported. They are listed here in order
6926 of increasing precedence:
6929 The comma or sequencing operator. Expressions in a
6930 comma-separated list are evaluated from left to right, with the
6931 result of the entire expression being the last expression
6935 Assignment. The value of an assignment expression is the value
6936 assigned. Defined on scalar types.
6939 Used in an expression of the form `A OP= B', and translated to
6940 `A = A OP B'. `OP=' and `=' have the same precedence. OP is any
6941 one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
6945 The ternary operator. `A ? B : C' can be thought of as: if A
6946 then B else C. A should be of an integral type.
6949 Logical OR. Defined on integral types.
6952 Logical AND. Defined on integral types.
6955 Bitwise OR. Defined on integral types.
6958 Bitwise exclusive-OR. Defined on integral types.
6961 Bitwise AND. Defined on integral types.
6964 Equality and inequality. Defined on scalar types. The value of
6965 these expressions is 0 for false and non-zero for true.
6968 Less than, greater than, less than or equal, greater than or equal.
6969 Defined on scalar types. The value of these expressions is 0 for
6970 false and non-zero for true.
6973 left shift, and right shift. Defined on integral types.
6976 The GDB "artificial array" operator (*note Expressions:
6980 Addition and subtraction. Defined on integral types,
6981 floating-point types and pointer types.
6984 Multiplication, division, and modulus. Multiplication and
6985 division are defined on integral and floating-point types.
6986 Modulus is defined on integral types.
6989 Increment and decrement. When appearing before a variable, the
6990 operation is performed before the variable is used in an
6991 expression; when appearing after it, the variable's value is used
6992 before the operation takes place.
6995 Pointer dereferencing. Defined on pointer types. Same precedence
6999 Address operator. Defined on variables. Same precedence as `++'.
7001 For debugging C++, GDB implements a use of `&' beyond what is
7002 allowed in the C++ language itself: you can use `&(&REF)' (or, if
7003 you prefer, simply `&&REF') to examine the address where a C++
7004 reference variable (declared with `&REF') is stored.
7007 Negative. Defined on integral and floating-point types. Same
7011 Logical negation. Defined on integral types. Same precedence as
7015 Bitwise complement operator. Defined on integral types. Same
7019 Structure member, and pointer-to-structure member. For
7020 convenience, GDB regards the two as equivalent, choosing whether
7021 to dereference a pointer based on the stored type information.
7022 Defined on `struct' and `union' data.
7025 Dereferences of pointers to members.
7028 Array indexing. `A[I]' is defined as `*(A+I)'. Same precedence
7032 Function parameter list. Same precedence as `->'.
7035 C++ scope resolution operator. Defined on `struct', `union', and
7039 Doubled colons also represent the GDB scope operator (*note
7040 Expressions: Expressions.). Same precedence as `::', above.
7042 If an operator is redefined in the user code, GDB usually attempts
7043 to invoke the redefined version instead of using the operator's
7051 File: gdb.info, Node: C Constants, Next: C plus plus expressions, Prev: C Operators, Up: C
7056 GDB allows you to express the constants of C and C++ in the following
7059 * Integer constants are a sequence of digits. Octal constants are
7060 specified by a leading `0' (i.e. zero), and hexadecimal constants
7061 by a leading `0x' or `0X'. Constants may also end with a letter
7062 `l', specifying that the constant should be treated as a `long'
7065 * Floating point constants are a sequence of digits, followed by a
7066 decimal point, followed by a sequence of digits, and optionally
7067 followed by an exponent. An exponent is of the form:
7068 `e[[+]|-]NNN', where NNN is another sequence of digits. The `+'
7069 is optional for positive exponents. A floating-point constant may
7070 also end with a letter `f' or `F', specifying that the constant
7071 should be treated as being of the `float' (as opposed to the
7072 default `double') type; or with a letter `l' or `L', which
7073 specifies a `long double' constant.
7075 * Enumerated constants consist of enumerated identifiers, or their
7076 integral equivalents.
7078 * Character constants are a single character surrounded by single
7079 quotes (`''), or a number--the ordinal value of the corresponding
7080 character (usually its ASCII value). Within quotes, the single
7081 character may be represented by a letter or by "escape sequences",
7082 which are of the form `\NNN', where NNN is the octal representation
7083 of the character's ordinal value; or of the form `\X', where `X'
7084 is a predefined special character--for example, `\n' for newline.
7086 * String constants are a sequence of character constants surrounded
7087 by double quotes (`"'). Any valid character constant (as described
7088 above) may appear. Double quotes within the string must be
7089 preceded by a backslash, so for instance `"a\"b'c"' is a string of
7092 * Pointer constants are an integral value. You can also write
7093 pointers to constants using the C operator `&'.
7095 * Array constants are comma-separated lists surrounded by braces `{'
7096 and `}'; for example, `{1,2,3}' is a three-element array of
7097 integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and
7098 `{&"hi", &"there", &"fred"}' is a three-element array of pointers.
7102 * C plus plus expressions::
7109 File: gdb.info, Node: C plus plus expressions, Next: C Defaults, Prev: C Constants, Up: C
7114 GDB expression handling can interpret most C++ expressions.
7116 _Warning:_ GDB can only debug C++ code if you use the proper
7117 compiler and the proper debug format. Currently, GDB works best
7118 when debugging C++ code that is compiled with GCC 2.95.3 or with
7119 GCC 3.1 or newer, using the options `-gdwarf-2' or `-gstabs+'.
7120 DWARF 2 is preferred over stabs+. Most configurations of GCC emit
7121 either DWARF 2 or stabs+ as their default debug format, so you
7122 usually don't need to specify a debug format explicitly. Other
7123 compilers and/or debug formats are likely to work badly or not at
7124 all when using GDB to debug C++ code.
7126 1. Member function calls are allowed; you can use expressions like
7128 count = aml->GetOriginal(x, y)
7130 2. While a member function is active (in the selected stack frame),
7131 your expressions have the same namespace available as the member
7132 function; that is, GDB allows implicit references to the class
7133 instance pointer `this' following the same rules as C++.
7135 3. You can call overloaded functions; GDB resolves the function call
7136 to the right definition, with some restrictions. GDB does not
7137 perform overload resolution involving user-defined type
7138 conversions, calls to constructors, or instantiations of templates
7139 that do not exist in the program. It also cannot handle ellipsis
7140 argument lists or default arguments.
7142 It does perform integral conversions and promotions, floating-point
7143 promotions, arithmetic conversions, pointer conversions,
7144 conversions of class objects to base classes, and standard
7145 conversions such as those of functions or arrays to pointers; it
7146 requires an exact match on the number of function arguments.
7148 Overload resolution is always performed, unless you have specified
7149 `set overload-resolution off'. *Note GDB features for C++:
7150 Debugging C plus plus.
7152 You must specify `set overload-resolution off' in order to use an
7153 explicit function signature to call an overloaded function, as in
7154 p 'foo(char,int)'('x', 13)
7156 The GDB command-completion facility can simplify this; see *Note
7157 Command completion: Completion.
7159 4. GDB understands variables declared as C++ references; you can use
7160 them in expressions just as you do in C++ source--they are
7161 automatically dereferenced.
7163 In the parameter list shown when GDB displays a frame, the values
7164 of reference variables are not displayed (unlike other variables);
7165 this avoids clutter, since references are often used for large
7166 structures. The _address_ of a reference variable is always
7167 shown, unless you have specified `set print address off'.
7169 5. GDB supports the C++ name resolution operator `::'--your
7170 expressions can use it just as expressions in your program do.
7171 Since one scope may be defined in another, you can use `::'
7172 repeatedly if necessary, for example in an expression like
7173 `SCOPE1::SCOPE2::NAME'. GDB also allows resolving name scope by
7174 reference to source files, in both C and C++ debugging (*note
7175 Program variables: Variables.).
7177 In addition, when used with HP's C++ compiler, GDB supports calling
7178 virtual functions correctly, printing out virtual bases of objects,
7179 calling functions in a base subobject, casting objects, and invoking
7180 user-defined operators.
7183 File: gdb.info, Node: C Defaults, Next: C Checks, Prev: C plus plus expressions, Up: C
7188 If you allow GDB to set type and range checking automatically, they
7189 both default to `off' whenever the working language changes to C or
7190 C++. This happens regardless of whether you or GDB selects the working
7193 If you allow GDB to set the language automatically, it recognizes
7194 source files whose names end with `.c', `.C', or `.cc', etc, and when
7195 GDB enters code compiled from one of these files, it sets the working
7196 language to C or C++. *Note Having GDB infer the source language:
7197 Automatically, for further details.
7200 File: gdb.info, Node: C Checks, Next: Debugging C, Prev: C Defaults, Up: C
7202 C and C++ type and range checks
7203 ...............................
7205 By default, when GDB parses C or C++ expressions, type checking is not
7206 used. However, if you turn type checking on, GDB considers two
7207 variables type equivalent if:
7209 * The two variables are structured and have the same structure,
7210 union, or enumerated tag.
7212 * The two variables have the same type name, or types that have been
7213 declared equivalent through `typedef'.
7216 Range checking, if turned on, is done on mathematical operations.
7217 Array indices are not checked, since they are often used to index a
7218 pointer that is not itself an array.
7221 File: gdb.info, Node: Debugging C, Next: Debugging C plus plus, Prev: C Checks, Up: C
7226 The `set print union' and `show print union' commands apply to the
7227 `union' type. When set to `on', any `union' that is inside a `struct'
7228 or `class' is also printed. Otherwise, it appears as `{...}'.
7230 The `@' operator aids in the debugging of dynamic arrays, formed
7231 with pointers and a memory allocation function. *Note Expressions:
7236 * Debugging C plus plus::
7239 File: gdb.info, Node: Debugging C plus plus, Prev: Debugging C, Up: C
7241 GDB features for C++
7242 ....................
7244 Some GDB commands are particularly useful with C++, and some are
7245 designed specifically for use with C++. Here is a summary:
7248 When you want a breakpoint in a function whose name is overloaded,
7249 GDB breakpoint menus help you specify which function definition
7250 you want. *Note Breakpoint menus: Breakpoint Menus.
7253 Setting breakpoints using regular expressions is helpful for
7254 setting breakpoints on overloaded functions that are not members
7255 of any special classes. *Note Setting breakpoints: Set Breaks.
7259 Debug C++ exception handling using these commands. *Note Setting
7260 catchpoints: Set Catchpoints.
7263 Print inheritance relationships as well as other information for
7264 type TYPENAME. *Note Examining the Symbol Table: Symbols.
7266 `set print demangle'
7267 `show print demangle'
7268 `set print asm-demangle'
7269 `show print asm-demangle'
7270 Control whether C++ symbols display in their source form, both when
7271 displaying code as C++ source and when displaying disassemblies.
7272 *Note Print settings: Print Settings.
7276 Choose whether to print derived (actual) or declared types of
7277 objects. *Note Print settings: Print Settings.
7281 Control the format for printing virtual function tables. *Note
7282 Print settings: Print Settings. (The `vtbl' commands do not work
7283 on programs compiled with the HP ANSI C++ compiler (`aCC').)
7285 `set overload-resolution on'
7286 Enable overload resolution for C++ expression evaluation. The
7287 default is on. For overloaded functions, GDB evaluates the
7288 arguments and searches for a function whose signature matches the
7289 argument types, using the standard C++ conversion rules (see *Note
7290 C++ expressions: C plus plus expressions, for details). If it
7291 cannot find a match, it emits a message.
7293 `set overload-resolution off'
7294 Disable overload resolution for C++ expression evaluation. For
7295 overloaded functions that are not class member functions, GDB
7296 chooses the first function of the specified name that it finds in
7297 the symbol table, whether or not its arguments are of the correct
7298 type. For overloaded functions that are class member functions,
7299 GDB searches for a function whose signature _exactly_ matches the
7302 `Overloaded symbol names'
7303 You can specify a particular definition of an overloaded symbol,
7304 using the same notation that is used to declare such symbols in
7305 C++: type `SYMBOL(TYPES)' rather than just SYMBOL. You can also
7306 use the GDB command-line word completion facilities to list the
7307 available choices, or to finish the type list for you. *Note
7308 Command completion: Completion, for details on how to do this.
7311 File: gdb.info, Node: Objective-C, Next: Modula-2, Prev: C, Up: Support
7316 This section provides information about some commands and command
7317 options that are useful for debugging Objective-C code.
7321 * Method Names in Commands::
7322 * The Print Command with Objective-C::
7325 File: gdb.info, Node: Method Names in Commands, Next: The Print Command with Objective-C, Prev: Objective-C, Up: Objective-C
7327 Method Names in Commands
7328 ........................
7330 The following commands have been extended to accept Objective-C method
7331 names as line specifications:
7343 A fully qualified Objective-C method name is specified as
7347 where the minus sign is used to indicate an instance method and a
7348 plus sign (not shown) is used to indicate a class method. The class
7349 name CLASS and method name METHODNAME are enclosed in brackets, similar
7350 to the way messages are specified in Objective-C source code. For
7351 example, to set a breakpoint at the `create' instance method of class
7352 `Fruit' in the program currently being debugged, enter:
7354 break -[Fruit create]
7356 To list ten program lines around the `initialize' class method,
7359 list +[NSText initialize]
7361 In the current version of GDB, the plus or minus sign is required.
7362 In future versions of GDB, the plus or minus sign will be optional, but
7363 you can use it to narrow the search. It is also possible to specify
7368 You must specify the complete method name, including any colons. If
7369 your program's source files contain more than one `create' method,
7370 you'll be presented with a numbered list of classes that implement that
7371 method. Indicate your choice by number, or type `0' to exit if none
7374 As another example, to clear a breakpoint established at the
7375 `makeKeyAndOrderFront:' method of the `NSWindow' class, enter:
7377 clear -[NSWindow makeKeyAndOrderFront:]
7380 File: gdb.info, Node: The Print Command with Objective-C, Prev: Method Names in Commands, Up: Objective-C
7382 The Print Command With Objective-C
7383 ..................................
7385 The print command has also been extended to accept methods. For
7388 print -[OBJECT hash]
7390 will tell GDB to send the `hash' message to OBJECT and print the
7391 result. Also, an additional command has been added, `print-object' or
7392 `po' for short, which is meant to print the description of an object.
7393 However, this command may only work with certain Objective-C libraries
7394 that have a particular hook function, `_NSPrintForDebugger', defined.
7397 File: gdb.info, Node: Modula-2, Prev: Objective-C, Up: Support
7402 The extensions made to GDB to support Modula-2 only support output from
7403 the GNU Modula-2 compiler (which is currently being developed). Other
7404 Modula-2 compilers are not currently supported, and attempting to debug
7405 executables produced by them is most likely to give an error as GDB
7406 reads in the executable's symbol table.
7410 * M2 Operators:: Built-in operators
7411 * Built-In Func/Proc:: Built-in functions and procedures
7412 * M2 Constants:: Modula-2 constants
7413 * M2 Defaults:: Default settings for Modula-2
7414 * Deviations:: Deviations from standard Modula-2
7415 * M2 Checks:: Modula-2 type and range checks
7416 * M2 Scope:: The scope operators `::' and `.'
7417 * GDB/M2:: GDB and Modula-2
7420 File: gdb.info, Node: M2 Operators, Next: Built-In Func/Proc, Up: Modula-2
7425 Operators must be defined on values of specific types. For instance,
7426 `+' is defined on numbers, but not on structures. Operators are often
7427 defined on groups of types. For the purposes of Modula-2, the
7428 following definitions hold:
7430 * _Integral types_ consist of `INTEGER', `CARDINAL', and their
7433 * _Character types_ consist of `CHAR' and its subranges.
7435 * _Floating-point types_ consist of `REAL'.
7437 * _Pointer types_ consist of anything declared as `POINTER TO TYPE'.
7439 * _Scalar types_ consist of all of the above.
7441 * _Set types_ consist of `SET' and `BITSET' types.
7443 * _Boolean types_ consist of `BOOLEAN'.
7445 The following operators are supported, and appear in order of
7446 increasing precedence:
7449 Function argument or array index separator.
7452 Assignment. The value of VAR `:=' VALUE is VALUE.
7455 Less than, greater than on integral, floating-point, or enumerated
7459 Less than or equal to, greater than or equal to on integral,
7460 floating-point and enumerated types, or set inclusion on set
7461 types. Same precedence as `<'.
7464 Equality and two ways of expressing inequality, valid on scalar
7465 types. Same precedence as `<'. In GDB scripts, only `<>' is
7466 available for inequality, since `#' conflicts with the script
7470 Set membership. Defined on set types and the types of their
7471 members. Same precedence as `<'.
7474 Boolean disjunction. Defined on boolean types.
7477 Boolean conjunction. Defined on boolean types.
7480 The GDB "artificial array" operator (*note Expressions:
7484 Addition and subtraction on integral and floating-point types, or
7485 union and difference on set types.
7488 Multiplication on integral and floating-point types, or set
7489 intersection on set types.
7492 Division on floating-point types, or symmetric set difference on
7493 set types. Same precedence as `*'.
7496 Integer division and remainder. Defined on integral types. Same
7500 Negative. Defined on `INTEGER' and `REAL' data.
7503 Pointer dereferencing. Defined on pointer types.
7506 Boolean negation. Defined on boolean types. Same precedence as
7510 `RECORD' field selector. Defined on `RECORD' data. Same
7514 Array indexing. Defined on `ARRAY' data. Same precedence as `^'.
7517 Procedure argument list. Defined on `PROCEDURE' objects. Same
7521 GDB and Modula-2 scope operators.
7523 _Warning:_ Sets and their operations are not yet supported, so GDB
7524 treats the use of the operator `IN', or the use of operators `+',
7525 `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
7529 File: gdb.info, Node: Built-In Func/Proc, Next: M2 Constants, Prev: M2 Operators, Up: Modula-2
7531 Built-in functions and procedures
7532 .................................
7534 Modula-2 also makes available several built-in procedures and functions.
7535 In describing these, the following metavariables are used:
7538 represents an `ARRAY' variable.
7541 represents a `CHAR' constant or variable.
7544 represents a variable or constant of integral type.
7547 represents an identifier that belongs to a set. Generally used in
7548 the same function with the metavariable S. The type of S should
7549 be `SET OF MTYPE' (where MTYPE is the type of M).
7552 represents a variable or constant of integral or floating-point
7556 represents a variable or constant of floating-point type.
7562 represents a variable.
7565 represents a variable or constant of one of many types. See the
7566 explanation of the function for details.
7568 All Modula-2 built-in procedures also return a result, described
7572 Returns the absolute value of N.
7575 If C is a lower case letter, it returns its upper case equivalent,
7576 otherwise it returns its argument.
7579 Returns the character whose ordinal value is I.
7582 Decrements the value in the variable V by one. Returns the new
7586 Decrements the value in the variable V by I. Returns the new
7590 Removes the element M from the set S. Returns the new set.
7593 Returns the floating point equivalent of the integer I.
7596 Returns the index of the last member of A.
7599 Increments the value in the variable V by one. Returns the new
7603 Increments the value in the variable V by I. Returns the new
7607 Adds the element M to the set S if it is not already there.
7608 Returns the new set.
7611 Returns the maximum value of the type T.
7614 Returns the minimum value of the type T.
7617 Returns boolean TRUE if I is an odd number.
7620 Returns the ordinal value of its argument. For example, the
7621 ordinal value of a character is its ASCII value (on machines
7622 supporting the ASCII character set). X must be of an ordered
7623 type, which include integral, character and enumerated types.
7626 Returns the size of its argument. X can be a variable or a type.
7629 Returns the integral part of R.
7632 Returns the member of the type T whose ordinal value is I.
7634 _Warning:_ Sets and their operations are not yet supported, so
7635 GDB treats the use of procedures `INCL' and `EXCL' as an error.