home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gdb.i01 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  51KB  |  971 lines

  1. This is Info file gdb.info, produced by Makeinfo-1.47 from the input
  2. file gdb-all.tex.
  3. START-INFO-DIR-ENTRY
  4. * Gdb: (gdb).                   The GNU debugger.
  5. END-INFO-DIR-ENTRY
  6.    This file documents the GNU debugger GDB.
  7.    This is Edition 4.06, October 1992, of `Debugging with GDB: the GNU
  8. Source-Level Debugger' for GDB Version 4.7.
  9.    Copyright (C) 1988, 1989, 1990, 1991, 1992 Free Software Foundation,
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided also
  15. that the section entitled "GNU General Public License" is included
  16. exactly as in the original, and provided that the entire resulting
  17. derived work is distributed under the terms of a permission notice
  18. identical to this one.
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that the section entitled "GNU General Public License"
  22. may be included in a translation approved by the Free Software
  23. Foundation instead of in the original English.
  24. File: gdb.info,  Node: Top,  Next: Summary,  Prev: (DIR),  Up: (DIR)
  25. Debugging with GDB
  26. ******************
  27.    This file describes GDB, the GNU symbolic debugger.
  28.    This is Edition 4.06, October 1992, for GDB Version 4.7.
  29. * Menu:
  30. * Summary::                     Summary of GDB
  31. * New Features::                New features since GDB version 3.5
  32. * Sample Session::              A sample GDB session
  33. * Invocation::                  Getting in and out of GDB
  34. * Commands::                    GDB commands
  35. * Running::                     Running programs under GDB
  36. * Stopping::                    Stopping and continuing
  37. * Stack::                       Examining the stack
  38. * Source::                      Examining source files
  39. * Data::                        Examining data
  40. * Languages::                   Using GDB with different languages
  41. * Symbols::                     Examining the symbol table
  42. * Altering::                    Altering execution
  43. * GDB Files::                   GDB's files
  44. * Targets::                     Specifying a debugging target
  45. * Controlling GDB::             Controlling GDB
  46. * Sequences::                   Canned sequences of commands
  47. * Emacs::                       Using GDB under GNU Emacs
  48. * GDB Bugs::                    Reporting bugs in GDB
  49. * Renamed Commands::
  50. * Formatting Documentation::    How to format and print GDB documentation
  51. * Installing GDB::              Installing GDB
  52. * Copying::                     GNU GENERAL PUBLIC LICENSE
  53. * Index::                       Index
  54. File: gdb.info,  Node: Summary,  Next: New Features,  Prev: Top,  Up: Top
  55. Summary of GDB
  56. **************
  57.    The purpose of a debugger such as GDB is to allow you to see what is
  58. going on "inside" another program while it executes--or what another
  59. program was doing at the moment it crashed.
  60.    GDB can do four main kinds of things (plus other things in support of
  61. these) to help you catch bugs in the act:
  62.    * Start your program, specifying anything that might affect its
  63.      behavior.
  64.    * Make your program stop on specified conditions.
  65.    * Examine what has happened, when your program has stopped.
  66.    * Change things in your program, so you can experiment with
  67.      correcting the effects of one bug and go on to learn about another.
  68.    You can use GDB to debug programs written in C, C++, and Modula-2.
  69. Fortran support will be added when a GNU Fortran compiler is ready.
  70. * Menu:
  71. * Free Software::               Free Software
  72. * Contributors::                Contributors to GDB
  73. File: gdb.info,  Node: Free Software,  Next: Contributors,  Up: Summary
  74. Free Software
  75. =============
  76.    GDB is "free software", protected by the GNU General Public License
  77. (GPL).  The GPL gives you the freedom to copy or adapt a licensed
  78. program--but every person getting a copy also gets with it the freedom
  79. to modify that copy (which means that they must get access to the
  80. source code), and the freedom to distribute further copies. Typical
  81. software companies use copyrights to limit your freedoms; the Free
  82. Software Foundation uses the GPL to preserve these freedoms.
  83.    Fundamentally, the General Public License is a license which says
  84. that you have these freedoms and that you cannot take these freedoms
  85. away from anyone else.
  86.    For full details, *note GNU GENERAL PUBLIC LICENSE: Copying..
  87. File: gdb.info,  Node: Contributors,  Prev: Free Software,  Up: Summary
  88. Contributors to GDB
  89. ===================
  90.    Richard Stallman was the original author of GDB, and of many other
  91. GNU programs.  Many others have contributed to its development.  This
  92. section attempts to credit major contributors.  One of the virtues of
  93. free software is that everyone is free to contribute to it; with
  94. regret, we cannot actually acknowledge everyone here.  The file
  95. `ChangeLog' in the GDB distribution approximates a blow-by-blow account.
  96.    Changes much prior to version 2.0 are lost in the mists of time.
  97.      *Plea:* Additions to this section are particularly welcome.  If you
  98.      or your friends (or enemies; let's be evenhanded) have been
  99.      unfairly omitted from this list, we would like to add your names!
  100.    So that they may not regard their long labor as thankless, we
  101. particularly thank those who shepherded GDB through major releases: Stu
  102. Grossman and John Gilmore (releases 4.6, 4.5, 4.4), John Gilmore
  103. (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4,
  104. 3.3); and Randy Smith (releases 3.2, 3.1, 3.0).  As major maintainer of
  105. GDB for some period, each contributed significantly to the structure,
  106. stability, and capabilities of the entire debugger.
  107.    Richard Stallman, assisted at various times by Pete TerMaat, Chris
  108. Hanson, and Richard Mlynarik, handled releases through 2.8.
  109.    Michael Tiemann is the author of most of the GNU C++ support in GDB,
  110. with significant additional contributions from Per Bothner.  James
  111. Clark wrote the GNU C++ demangler.  Early work on C++ was by Peter
  112. TerMaat (who also did much general update work leading to release 3.0).
  113.    GDB 4 uses the BFD subroutine library to examine multiple
  114. object-file formats; BFD was a joint project of David V.
  115. Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
  116.    David Johnson wrote the original COFF support; Pace Willison did the
  117. original support for encapsulated COFF.
  118.    Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
  119. Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
  120. support.  Jean-Daniel Fekete contributed Sun 386i support.  Chris
  121. Hanson improved the HP9000 support.  Noboyuki Hikichi and Tomoyuki
  122. Hasei contributed Sony/News OS 3 support.  David Johnson contributed
  123. Encore Umax support.  Jyrki Kuoppala contributed Altos 3068 support.
  124. Keith Packard contributed NS32K support.  Doug Rabson contributed Acorn
  125. Risc Machine support.  Chris Smith contributed Convex support (and
  126. Fortran debugging).  Jonathan Stone contributed Pyramid support.
  127. Michael Tiemann contributed SPARC support.  Tim Tucker contributed
  128. support for the Gould NP1 and Gould Powernode.  Pace Willison
  129. contributed Intel 386 support.  Jay Vosburgh contributed Symmetry
  130. support.
  131.    Rich Schaefer and Peter Schauer helped with support of SunOS shared
  132. libraries.
  133.    Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
  134. several machine instruction sets.
  135.    Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
  136. develop remote debugging.  Intel Corporation and Wind River Systems
  137. contributed remote debugging modules for their products.
  138.    Brian Fox is the author of the readline libraries providing
  139. command-line editing and command history.
  140.    Andrew Beers of SUNY Buffalo wrote the language-switching code and
  141. the Modula-2 support, and contributed the Languages chapter of this
  142. manual.
  143.    Fred Fish wrote most of the support for Unix System Vr4, and enhanced
  144. the command-completion support to cover C++ overloaded symbols.
  145. File: gdb.info,  Node: New Features,  Next: Sample Session,  Prev: Summary,  Up: Top
  146. New Features since GDB version 3.5
  147. **********************************
  148. *Targets*
  149.      Using the new command `target', you can select at runtime whether
  150.      you are debugging local files, local processes, standalone systems
  151.      over a serial port, realtime systems over a TCP/IP connection,
  152.      etc.  The command `load' can download programs into a remote
  153.      system.  Serial stubs are available for Motorola 680x0, Intel
  154.      80386, and Sparc remote systems; GDB also supports debugging
  155.      realtime processes running under VxWorks, using SunRPC Remote
  156.      Procedure Calls over TCP/IP to talk to a debugger stub on the
  157.      target system.  Internally, GDB now uses a function vector to
  158.      mediate access to different targets; if you need to add your own
  159.      support for a remote protocol, this makes it much easier.
  160. *Watchpoints*
  161.      GDB now sports watchpoints as well as breakpoints.  You can use a
  162.      watchpoint to stop execution whenever the value of an expression
  163.      changes, without having to predict a particular place in your
  164.      program where this may happen.
  165. *Wide Output*
  166.      Commands that issue wide output now insert newlines at places
  167.      designed to make the output more readable.
  168. *Object Code Formats*
  169.      GDB uses a new library called the Binary File Descriptor (BFD)
  170.      Library to permit it to switch dynamically, without
  171.      reconfiguration or recompilation, between different object-file
  172.      formats.  Formats currently supported are COFF, a.out, and the
  173.      Intel 960 b.out; files may be read as .o's, archive libraries, or
  174.      core dumps.  BFD is available as a subroutine library so that
  175.      other programs may take advantage of it, and the other GNU binary
  176.      utilities are being converted to use it.
  177. *Configuration and Ports*
  178.      Compile-time configuration (to select a particular architecture and
  179.      operating system) is much easier.  The script `configure' now
  180.      allows you to configure GDB as either a native debugger or a
  181.      cross-debugger. *Note Installing GDB::, for details on how to
  182.      configure.
  183. *Interaction*
  184.      The user interface to GDB's control variables has been simplified
  185.      and consolidated in two commands, `set' and `show'.  Output lines
  186.      are now broken at readable places, rather than overflowing onto
  187.      the next line.  You can suppress output of machine-level addresses,
  188.      displaying only source language information.
  189. *C++*
  190.      GDB now supports C++ multiple inheritance (if used with a GCC
  191.      version 2 compiler), and also has limited support for C++ exception
  192.      handling, with the commands `catch' and `info catch': GDB can
  193.      break when an exception is raised, before the stack is peeled back
  194.      to the exception handler's context.
  195. *Modula-2*
  196.      GDB now has preliminary support for the GNU Modula-2 compiler,
  197.      currently under development at the State University of New York at
  198.      Buffalo.  Coordinated development of both GDB and the GNU Modula-2
  199.      compiler will continue into 1992.  Other Modula-2 compilers are
  200.      currently not supported, and attempting to debug programs compiled
  201.      with them will likely result in an error as the symbol table of the
  202.      executable is read in.
  203. *Command Rationalization*
  204.      Many GDB commands have been renamed to make them easier to remember
  205.      and use.  In particular, the subcommands of `info' and
  206.      `show'/`set' are grouped to make the former refer to the state of
  207.      your program, and the latter refer to the state of GDB itself.
  208.      *Note Renamed Commands::, for details on what commands were
  209.      renamed.
  210. *Shared Libraries*
  211.      GDB 4 can debug programs and core files that use SunOS, SVR4, or
  212.      IBM RS/6000 shared libraries.
  213. *Reference Card*
  214.      GDB 4 has a reference card.  *Note Formatting the Documentation:
  215.      Formatting Documentation, for instructions to print it.
  216. *Work in Progress*
  217.      Kernel debugging for BSD and Mach systems; Tahoe and HPPA
  218.      architecture support.
  219. File: gdb.info,  Node: Sample Session,  Next: Invocation,  Prev: New Features,  Up: Top
  220. A Sample GDB Session
  221. ********************
  222.    You can use this manual at your leisure to read all about GDB.
  223. However, a handful of commands are enough to get started using the
  224. debugger.  This chapter illustrates these commands.
  225.    One of the preliminary versions of GNU `m4' (a generic macro
  226. processor) exhibits the following bug: sometimes, when we change its
  227. quote strings from the default, the commands used to capture one macro's
  228. definition in another stop working.  In the following short `m4'
  229. session, we define a macro `foo' which expands to `0000'; we then use
  230. the `m4' built-in `defn' to define `bar' as the same thing.  However,
  231. when we change the open quote string to `<QUOTE>' and the close quote
  232. string to `<UNQUOTE>', the same procedure fails to define a new synonym
  233. `baz':
  234.      $ cd gnu/m4
  235.      $ ./m4
  236.      define(foo,0000)
  237.      
  238.      foo
  239.      0000
  240.      define(bar,defn(`foo'))
  241.      
  242.      bar
  243.      0000
  244.      changequote(<QUOTE>,<UNQUOTE>)
  245.      
  246.      define(baz,defn(<QUOTE>foo<UNQUOTE>))
  247.      baz
  248.      C-d
  249.      m4: End of input: 0: fatal error: EOF in string
  250. Let's use GDB to try to see what's going on.
  251.      $ gdb m4
  252.      GDB is free software and you are welcome to distribute copies
  253.       of it under certain conditions; type "show copying" to see
  254.       the conditions.
  255.      There is absolutely no warranty for GDB; type "show warranty"
  256.      for details.
  257.      GDB 4.7, Copyright 1992 Free Software Foundation, Inc...
  258.      (gdb)
  259. GDB reads only enough symbol data to know where to find the rest when
  260. needed; as a result, the first prompt comes up very quickly.  We now
  261. tell GDB to use a narrower display width than usual, so that examples
  262. will fit in this manual.
  263.      (gdb) set width 70
  264. Let's see how the `m4' built-in `changequote' works. Having looked at
  265. the source, we know the relevant subroutine is `m4_changequote', so we
  266. set a breakpoint there with GDB's `break' command.
  267.      (gdb) break m4_changequote
  268.      Breakpoint 1 at 0x62f4: file builtin.c, line 879.
  269. Using the `run' command, we start `m4' running under GDB control; as
  270. long as control does not reach the `m4_changequote' subroutine, the
  271. program runs as usual:
  272.      (gdb) run
  273.      Starting program: /work/Editorial/gdb/gnu/m4/m4
  274.      define(foo,0000)
  275.      
  276.      foo
  277.      0000
  278. To trigger the breakpoint, we call `changequote'.  GDB suspends
  279. execution of `m4', displaying information about the context where it
  280. stops.
  281.      changequote(<QUOTE>,<UNQUOTE>)
  282.      
  283.      Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
  284.          at builtin.c:879
  285.      879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
  286. Now we use the command `n' (`next') to advance execution to the next
  287. line of the current function.
  288.      (gdb) n
  289.      882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
  290.       : nil,
  291. `set_quotes' looks like a promising subroutine.  We can go into it by
  292. using the command `s' (`step') instead of `next'. `step' goes to the
  293. next line to be executed in *any* subroutine, so it steps into
  294. `set_quotes'.
  295.      (gdb) s
  296.      set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
  297.          at input.c:530
  298.      530         if (lquote != def_lquote)
  299. The display that shows the subroutine where `m4' is now suspended (and
  300. its arguments) is called a stack frame display.  It shows a summary of
  301. the stack.  We can use the `backtrace' command (which can also be
  302. spelled `bt'), to see where we are in the stack as a whole: the
  303. `backtrace' command displays a stack frame for each active subroutine.
  304.      (gdb) bt
  305.      #0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
  306.          at input.c:530
  307.      #1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
  308.          at builtin.c:882
  309.      #2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
  310.      #3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
  311.          at macro.c:71
  312.      #4  0x79dc in expand_input () at macro.c:40
  313.      #5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
  314. Let's step through a few more lines to see what happens.  The first two
  315. times, we can use `s'; the next two times we use `n' to avoid falling
  316. into the `xstrdup' subroutine.
  317.      (gdb) s
  318.      0x3b5c  532         if (rquote != def_rquote)
  319.      (gdb) s
  320.      0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
  321.      def_lquote : xstrdup(lq);
  322.      (gdb) n
  323.      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
  324.       : xstrdup(rq);
  325.      (gdb) n
  326.      538         len_lquote = strlen(rquote);
  327. The last line displayed looks a little odd; let's examine the variables
  328. `lquote' and `rquote' to see if they are in fact the new left and right
  329. quotes we specified.  We can use the command `p' (`print') to see their
  330. values.
  331.      (gdb) p lquote
  332.      $1 = 0x35d40 "<QUOTE>"
  333.      (gdb) p rquote
  334.      $2 = 0x35d50 "<UNQUOTE>"
  335. `lquote' and `rquote' are indeed the new left and right quotes. Let's
  336. look at some context; we can display ten lines of source surrounding
  337. the current line, with the `l' (`list') command.
  338.      (gdb) l
  339.      533             xfree(rquote);
  340.      534
  341.      535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
  342.       : xstrdup (lq);
  343.      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
  344.       : xstrdup (rq);
  345.      537
  346.      538         len_lquote = strlen(rquote);
  347.      539         len_rquote = strlen(lquote);
  348.      540     }
  349.      541
  350.      542     void
  351. Let's step past the two lines that set `len_lquote' and `len_rquote',
  352. and then examine the values of those variables.
  353.      (gdb) n
  354.      539         len_rquote = strlen(lquote);
  355.      (gdb) n
  356.      540     }
  357.      (gdb) p len_lquote
  358.      $3 = 9
  359.      (gdb) p len_rquote
  360.      $4 = 7
  361. That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
  362. meant to be the lengths of `lquote' and `rquote' respectively.  Let's
  363. try setting them to better values. We can use the `p' command for this,
  364. since it'll print the value of any expression--and that expression can
  365. include subroutine calls and assignments.
  366.      (gdb) p len_lquote=strlen(lquote)
  367.      $5 = 7
  368.      (gdb) p len_rquote=strlen(rquote)
  369.      $6 = 9
  370. Let's see if that fixes the problem of using the new quotes with the
  371. `m4' built-in `defn'.  We can allow `m4' to continue executing with the
  372. `c' (`continue') command, and then try the example that caused trouble
  373. initially:
  374.      (gdb) c
  375.      Continuing.
  376.      
  377.      define(baz,defn(<QUOTE>foo<UNQUOTE>))
  378.      
  379.      baz
  380.      0000
  381. Success!  The new quotes now work just as well as the default ones.  The
  382. problem seems to have been just the two typos defining the wrong
  383. lengths.  We'll let `m4' exit by giving it an EOF as input.
  384.      C-d
  385.      Program exited normally.
  386. The message `Program exited normally.' is from GDB; it indicates `m4'
  387. has finished executing.  We can end our GDB session with the GDB `quit'
  388. command.
  389.      (gdb) quit
  390. File: gdb.info,  Node: Invocation,  Next: Commands,  Prev: Sample Session,  Up: Top
  391. Getting In and Out of GDB
  392. *************************
  393.    This chapter discusses how to start GDB, and how to get out of it.
  394. (The essentials: type `gdb' to start GDB, and type `quit' or `C-d' to
  395. exit.)
  396. * Menu:
  397. * Invoking GDB::                Starting GDB
  398. * Leaving GDB::                 Leaving GDB
  399. * Shell Commands::              Shell Commands
  400. File: gdb.info,  Node: Invoking GDB,  Next: Leaving GDB,  Up: Invocation
  401. Starting GDB
  402. ============
  403.    For details on starting up gdb as a remote debugger attached to a
  404. Hitachi H8/300 board, see *Note GDB and the Hitachi H8/300: Hitachi
  405. H8/300 Remote.
  406.    Start GDB by running the program `gdb'.  Once it's running, GDB
  407. reads commands from the terminal until you tell it to exit.
  408.    You can also run `gdb' with a variety of arguments and options, to
  409. specify more of your debugging environment at the outset.
  410.    The command-line options described here are designed to cover a
  411. variety of situations; in some environments, some of these options may
  412. effectively be unavailable.
  413.    The most usual way to start GDB is with one argument, specifying an
  414. executable program:
  415.      gdb PROGRAM
  416. You can also start with both an executable program and a core file
  417. specified:
  418.      gdb PROGRAM CORE
  419.    You can, instead, specify a process ID as a second argument, if you
  420. want to debug a running process:
  421.      gdb PROGRAM 1234
  422. would attach GDB to process `1234' (unless you also have a file named
  423. `1234'; GDB does check for a core file first).
  424.    Taking advantage of the second command-line argument requires a
  425. fairly complete operating system; when you use GDB as a remote debugger
  426. attached to a bare board, there may not be any notion of "process", and
  427. there is often no way to get a core dump.
  428. You can further control how GDB starts up by using command-line
  429. options.  GDB itself can remind you of the options available.
  430.      gdb -help
  431. to display all available options and briefly describe their use (`gdb
  432. -h' is a shorter equivalent).
  433.    All options and command line arguments you give are processed in
  434. sequential order.  The order makes a difference when the `-x' option is
  435. used.
  436. * Menu:
  437. * File Options::                Choosing Files
  438. * Mode Options::                Choosing Modes
  439. File: gdb.info,  Node: File Options,  Next: Mode Options,  Up: Invoking GDB
  440. Choosing Files
  441. --------------
  442.    When GDB starts, it reads any arguments other than options as
  443. specifying an executable file and core file (or process ID).  This is
  444. the same as if the arguments were specified by the `-se' and `-c'
  445. options respectively.  (GDB reads the first argument that does not have
  446. an associated option flag as equivalent to the `-se' option followed by
  447. that argument; and the second argument that does not have an associated
  448. option flag, if any, as equivalent to the `-c' option followed by that
  449. argument.)
  450.    Many options have both long and short forms; both are shown in the
  451. following list.  GDB also recognizes the long forms if you truncate
  452. them, so long as enough of the option is present to be unambiguous. (If
  453. you prefer, you can flag option arguments with `--' rather than `-',
  454. though we illustrate the more usual convention.)
  455. `-symbols=FILE'
  456. `-s FILE'
  457.      Read symbol table from file FILE.
  458. `-exec=FILE'
  459. `-e FILE'
  460.      Use file FILE as the executable file to execute when appropriate,
  461.      and for examining pure data in conjunction with a core dump.
  462. `-se=FILE'
  463.      Read symbol table from file FILE and use it as the executable file.
  464. `-core=FILE'
  465. `-c FILE'
  466.      Use file FILE as a core dump to examine.
  467. `-command=FILE'
  468. `-x FILE'
  469.      Execute GDB commands from file FILE.  *Note Command Files::.
  470. `-directory=DIRECTORY'
  471. `-d DIRECTORY'
  472.      Add DIRECTORY to the path to search for source files.
  473. `-mapped'
  474.      *Warning: this option depends on operating system facilities that
  475.      are not supported on all systems.*
  476.      If memory-mapped files are available on your system through the
  477.      `mmap' system call, you can use this option to have GDB write the
  478.      symbols from your program into a reusable file in the current
  479.      directory.  If the program you are debugging is called
  480.      `/tmp/fred', the mapped symbol file will be `./fred.syms'. Future
  481.      GDB debugging sessions will notice the presence of this file, and
  482.      will quickly map in symbol information from it, rather than reading
  483.      the symbol table from the executable program.
  484.      The `.syms' file is specific to the host machine on which GDB is
  485.      run. It holds an exact image of GDB's internal symbol table.  It
  486.      cannot be shared across multiple host platforms.
  487. `-readnow'
  488.      Read each symbol file's entire symbol table immediately, rather
  489.      than the default, which is to read it incrementally as it is
  490.      needed. This makes startup slower, but makes future operations
  491.      faster.
  492.    The `-mapped' and `-readnow' options are typically combined in order
  493. to build a `.syms' file that contains complete symbol information. A
  494. simple GDB invocation to do nothing but build a `.syms' file for future
  495. use is:
  496.          gdb -batch -nx -mapped -readnow programname
  497. File: gdb.info,  Node: Mode Options,  Prev: File Options,  Up: Invoking GDB
  498. Choosing Modes
  499. --------------
  500.    You can run GDB in various alternative modes--for example, in batch
  501. mode or quiet mode.
  502. `-nx'
  503.      Do not execute commands from any `.gdbinit' initialization files.
  504.      Normally, the commands in these files are executed after all the
  505.      command options and arguments have been processed. *Note Command
  506.      Files::.
  507. `-quiet'
  508.      "Quiet".  Do not print the introductory and copyright messages. 
  509.      These messages are also suppressed in batch mode.
  510. `-batch'
  511.      Run in batch mode.  Exit with status `0' after processing all the
  512.      command files specified with `-x' (and `.gdbinit', if not
  513.      inhibited). Exit with nonzero status if an error occurs in
  514.      executing the GDB commands in the command files.
  515.      Batch mode may be useful for running GDB as a filter, for example
  516.      to download and run a program on another computer; in order to
  517.      make this more useful, the message
  518.           Program exited normally.
  519.      (which is ordinarily issued whenever a program running under GDB
  520.      control terminates) is not issued when running in batch mode.
  521. `-cd=DIRECTORY'
  522.      Run GDB using DIRECTORY as its working directory, instead of the
  523.      current directory.
  524. `-fullname'
  525.      Emacs sets this option when it runs GDB as a subprocess.  It tells
  526.      GDB to output the full file name and line number in a standard,
  527.      recognizable fashion each time a stack frame is displayed (which
  528.      includes each time your program stops).  This recognizable format
  529.      looks like two `\032' characters, followed by the file name, line
  530.      number and character position separated by colons, and a newline. 
  531.      The Emacs-to-GDB interface program uses the two `\032' characters
  532.      as a signal to display the source code for the frame.
  533. `-b BPS'
  534.      Set the line speed (baud rate or bits per second) of any serial
  535.      interface used by GDB for remote debugging.
  536. `-tty=DEVICE'
  537.      Run using DEVICE for your program's standard input and output.
  538. File: gdb.info,  Node: Leaving GDB,  Next: Shell Commands,  Prev: Invoking GDB,  Up: Invocation
  539. Leaving GDB
  540. ===========
  541. `quit'
  542.      To exit GDB, use the `quit' command (abbreviated `q'), or type an
  543.      end-of-file character (usually `C-d').
  544.    An interrupt (often `C-c') will not exit from GDB, but rather will
  545. terminate the action of any GDB command that is in progress and return
  546. to GDB command level.  It is safe to type the interrupt character at
  547. any time because GDB does not allow it to take effect until a time when
  548. it is safe.
  549.    If you have been using GDB to control an attached process or device,
  550. you can release it with the `detach' command; *note Debugging an
  551. Already-Running Process: Attach...
  552. File: gdb.info,  Node: Shell Commands,  Prev: Leaving GDB,  Up: Invocation
  553. Shell Commands
  554. ==============
  555.    If you need to execute occasional shell commands during your
  556. debugging session, there is no need to leave or suspend GDB; you can
  557. just use the `shell' command.
  558. `shell COMMAND STRING'
  559.      Directs GDB to invoke an inferior shell to execute COMMAND STRING.
  560.       If it exists, the environment variable `SHELL' is used for the
  561.      name of the shell to run.  Otherwise GDB uses `/bin/sh'.
  562.    The utility `make' is often needed in development environments. You
  563. do not have to use the `shell' command for this purpose in GDB:
  564. `make MAKE-ARGS'
  565.      Causes GDB to execute an inferior `make' program with the specified
  566.      arguments.  This is equivalent to `shell make MAKE-ARGS'.
  567. File: gdb.info,  Node: Commands,  Next: Running,  Prev: Invocation,  Up: Top
  568. GDB Commands
  569. ************
  570.    You can abbreviate a GDB command to the first few letters of the
  571. command name, if that abbreviation is unambiguous; and you can repeat
  572. certain GDB commands by typing just RET.  You can also use the TAB key
  573. to get GDB to fill out the rest of a word in a command (or to show you
  574. the alternatives available, if there's more than one possibility).
  575. * Menu:
  576. * Command Syntax::              Command Syntax
  577. * Completion::                  Command Completion
  578. * Help::                        Getting Help
  579. File: gdb.info,  Node: Command Syntax,  Next: Completion,  Up: Commands
  580. Command Syntax
  581. ==============
  582.    A GDB command is a single line of input.  There is no limit on how
  583. long it can be.  It starts with a command name, which is followed by
  584. arguments whose meaning depends on the command name.  For example, the
  585. command `step' accepts an argument which is the number of times to step,
  586. as in `step 5'.  You can also use the `step' command with no arguments.
  587.  Some command names do not allow any arguments.
  588.    GDB command names may always be truncated if that abbreviation is
  589. unambiguous.  Other possible command abbreviations are listed in the
  590. documentation for individual commands.  In some cases, even ambiguous
  591. abbreviations are allowed; for example, `s' is specially defined as
  592. equivalent to `step' even though there are other commands whose names
  593. start with `s'.  You can test abbreviations by using them as arguments
  594. to the `help' command.
  595.    A blank line as input to GDB (typing just RET) means to repeat the
  596. previous command. Certain commands (for example, `run') will not repeat
  597. this way; these are commands for which unintentional repetition might
  598. cause trouble and which you are unlikely to want to repeat.
  599.    The `list' and `x' commands, when you repeat them with RET,
  600. construct new arguments rather than repeating exactly as typed.  This
  601. permits easy scanning of source or memory.
  602.    GDB can also use RET in another way: to partition lengthy output, in
  603. a way similar to the common utility `more' (*note Screen Size::.). 
  604. Since it is easy to press one RET too many in this situation, GDB
  605. disables command repetition after any command that generates this sort
  606. of display.
  607.    A line of input starting with `#' is a comment; it does nothing.
  608. This is useful mainly in command files (*note Command Files::.).
  609. File: gdb.info,  Node: Completion,  Next: Help,  Prev: Command Syntax,  Up: Commands
  610. Command Completion
  611. ==================
  612.    GDB can fill in the rest of a word in a command for you, if there's
  613. only one possibility; it can also show you what the valid possibilities
  614. are for the next word in a command, at any time.  This works for GDB
  615. commands, GDB subcommands, and the names of symbols in your program.
  616.    Press the TAB key whenever you want GDB to fill out the rest of a
  617. word.  If there's only one possibility, GDB will fill in the word, and
  618. wait for you to finish the command (or press RET to enter it).  For
  619. example, if you type
  620.      (gdb) info bre TAB
  621. GDB fills in the rest of the word `breakpoints', since that's the only
  622. `info' subcommand beginning with `bre':
  623.      (gdb) info breakpoints
  624. You can either press RET at this point, to run the `info breakpoints'
  625. command, or backspace and enter something else, if `breakpoints'
  626. doesn't look like the command you expected.  (If you were sure you
  627. wanted `info breakpoints' in the first place, you might as well just
  628. type RET immediately after `info bre', to exploit command abbreviations
  629. rather than command completion).
  630.    If there is more than one possibility for the next word when you
  631. press TAB, GDB will sound a bell.  You can either supply more
  632. characters and try again, or just press TAB a second time, and GDB will
  633. display all the possible completions for that word.  For example, you
  634. might want to set a breakpoint on a subroutine whose name begins with
  635. `make_', but when you type `b make_TAB' GDB just sounds the bell. 
  636. Typing TAB again will display all the function names in your program
  637. that begin with those characters, for example:
  638.      (gdb) b make_ TAB
  639. GDB sounds bell; press TAB again, to see:
  640.      make_a_section_from_file     make_environ
  641.      make_abs_section             make_function_type
  642.      make_blockvector             make_pointer_type
  643.      make_cleanup                 make_reference_type
  644.      make_command                 make_symbol_completion_list
  645.      (GDBP__) b make_
  646. After displaying the available possibilities, GDB copies your partial
  647. input (`b make_' in the example) so you can finish the command.
  648.    If you just want to see the list of alternatives in the first place,
  649. you can press `M-?' rather than pressing TAB twice. `M-?' means `META
  650. ?'.  You can type this either by holding down a key designated as the
  651. META shift on your keyboard (if there is one) while typing `?', or as
  652. ESC followed by `?'.
  653.    Sometimes the string you need, while logically a "word", may contain
  654. parentheses or other characters that GDB normally excludes from its
  655. notion of a word.  To permit word completion to work in this situation,
  656. you may enclose words in `'' (single quote marks) in GDB commands.
  657.    The most likely situation where you might need this is in typing the
  658. name of a C++ function.  This is because C++ allows function overloading
  659. (multiple definitions of the same function, distinguished by argument
  660. type).  For example, when you want to set a breakpoint you may need to
  661. distinguish whether you mean the version of `name' that takes an `int'
  662. parameter, `name(int)', or the version that takes a `float' parameter,
  663. `name(float)'.  To use the word-completion facilities in this
  664. situation, type a single quote `'' at the beginning of the function
  665. name.  This alerts GDB that it may need to consider more information
  666. than usual when you press TAB or `M-?' to request word completion:
  667.      (gdb) b 'bubble( M-?
  668.      bubble(double,double)    bubble(int,int)
  669.      (gdb) b 'bubble(
  670.    In some cases, GDB can tell that completing a name will require
  671. quotes.  When this happens, GDB will insert the quote for you (while
  672. completing as much as it can) if you do not type the quote in the first
  673. place:
  674.      (gdb) b bub TAB
  675. GDB alters your input line to the following, and rings a bell:
  676.      (gdb) b 'bubble(
  677. In general, GDB can tell that a quote is needed (and inserts it) if you
  678. have not yet started typing the argument list when you ask for
  679. completion on an overloaded symbol.
  680. File: gdb.info,  Node: Help,  Prev: Completion,  Up: Commands
  681. Getting Help
  682. ============
  683.    You can always ask GDB itself for information on its commands, using
  684. the command `help'.
  685. `help'
  686.      You can use `help' (abbreviated `h') with no arguments to display
  687.      a short list of named classes of commands:
  688.           (gdb) help
  689.           List of classes of commands:
  690.           
  691.           running -- Running the program
  692.           stack -- Examining the stack
  693.           data -- Examining data
  694.           breakpoints -- Making program stop at certain points
  695.           files -- Specifying and examining files
  696.           status -- Status inquiries
  697.           support -- Support facilities
  698.           user-defined -- User-defined commands
  699.           aliases -- Aliases of other commands
  700.           obscure -- Obscure features
  701.           
  702.           Type "help" followed by a class name for a list of
  703.           commands in that class.
  704.           Type "help" followed by command name for full
  705.           documentation.
  706.           Command name abbreviations are allowed if unambiguous.
  707.           (gdb)
  708. `help CLASS'
  709.      Using one of the general help classes as an argument, you can get a
  710.      list of the individual commands in that class.  For example, here
  711.      is the help display for the class `status':
  712.           (gdb) help status
  713.           Status inquiries.
  714.           
  715.           List of commands:
  716.           
  717.           show -- Generic command for showing things set with "set"
  718.           info -- Generic command for printing status
  719.           
  720.           Type "help" followed by command name for full
  721.           documentation.
  722.           Command name abbreviations are allowed if unambiguous.
  723.           (gdb)
  724. `help COMMAND'
  725.      With a command name as `help' argument, GDB will display a short
  726.      paragraph on how to use that command.
  727.    In addition to `help', you can use the GDB commands `info' and
  728. `show' to inquire about the state of your program, or the state of GDB
  729. itself.  Each command supports many topics of inquiry; this manual
  730. introduces each of them in the appropriate context.  The listings under
  731. `info' and under `show' in the Index point to all the sub-commands. 
  732. *Note Index::.
  733. `info'
  734.      This command (abbreviated `i') is for describing the state of your
  735.      program; for example, it can list the arguments given to your
  736.      program (`info args'), the registers currently in use (`info
  737.      registers'), or the breakpoints you have set (`info breakpoints').
  738.      You can get a complete list of the `info' sub-commands with
  739.      `help info'.
  740. `show'
  741.      In contrast, `show' is for describing the state of GDB itself. You
  742.      can change most of the things you can `show', by using the related
  743.      command `set'; for example, you can control what number system is
  744.      used for displays with `set radix', or simply inquire which is
  745.      currently in use with `show radix'.
  746.      To display all the settable parameters and their current values,
  747.      you can use `show' with no arguments; you may also use `info set'.
  748.       Both commands produce the same display.
  749.    Here are three miscellaneous `show' subcommands, all of which are
  750. exceptional in lacking corresponding `set' commands:
  751. `show version'
  752.      Show what version of GDB is running.  You should include this
  753.      information in GDB bug-reports.  If multiple versions of GDB are in
  754.      use at your site, you may occasionally want to make sure what
  755.      version of GDB you are running; as GDB evolves, new commands are
  756.      introduced, and old ones may wither away.  The version number is
  757.      also announced when you start GDB with no arguments.
  758. `show copying'
  759.      Display information about permission for copying GDB.
  760. `show warranty'
  761.      Display the GNU "NO WARRANTY" statement.
  762. File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Commands,  Up: Top
  763. Running Programs Under GDB
  764. **************************
  765.    To debug a program, you must run it under GDB.
  766. * Menu:
  767. * Compilation::                 Compiling for Debugging
  768. * Starting::                    Starting your Program
  769. * Arguments::                   Your Program's Arguments
  770. * Environment::                 Your Program's Environment
  771. * Working Directory::           Your Program's Working Directory
  772. * Input/Output::                Your Program's Input and Output
  773. * Attach::                      Debugging an Already-Running Process
  774. * Kill Process::                Killing the Child Process
  775. * Process Information::         Additional Process Information
  776. File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
  777. Compiling for Debugging
  778. =======================
  779.    In order to debug a program effectively, you need to generate
  780. debugging information when you compile it.  This debugging information
  781. is stored in the object file; it describes the data type of each
  782. variable or function and the correspondence between source line numbers
  783. and addresses in the executable code.
  784.    To request debugging information, specify the `-g' option when you
  785. run the compiler.
  786.    Many C compilers are unable to handle the `-g' and `-O' options
  787. together.  Using those compilers, you cannot generate optimized
  788. executables containing debugging information.
  789.    gcc, the GNU C compiler, supports `-g' with or without `-O', making
  790. it possible to debug optimized code.  We recommend that you *always*
  791. use `-g' whenever you compile a program. You may think your program is
  792. correct, but there is no sense in pushing your luck.
  793.    When you debug a program compiled with `-g -O', remember that the
  794. optimizer is rearranging your code; the debugger will show you what's
  795. really there.  Don't be too surprised when the execution path doesn't
  796. exactly match your source file!  An extreme example: if you define a
  797. variable, but never use it, GDB will never see that variable--because
  798. the compiler optimizes it out of existence.
  799.    Some things do not work as well with `-g -O' as with just `-g',
  800. particularly on machines with instruction scheduling.  If in doubt,
  801. recompile with `-g' alone, and if this fixes the problem, please report
  802. it as a bug (including a test case!).
  803.    Older versions of the GNU C compiler permitted a variant option
  804. `-gg' for debugging information.  GDB no longer supports this format;
  805. if your GNU C compiler has this option, do not use it.
  806. File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
  807. Starting your Program
  808. =====================
  809. `run'
  810.      Use the `run' command to start your program under GDB.  You must
  811.      first specify the program name (except on VxWorks) with an
  812.      argument to GDB (*note Getting In and Out of GDB: Invocation.), or
  813.      by using the `file' or `exec-file' command (*note Commands to
  814.      Specify Files: Files.).
  815.    If you are running your program in an execution environment that
  816. supports processes, `run' creates an inferior process and makes that
  817. process run your program.  (In environments without processes, `run'
  818. jumps to the start of your program.)
  819.    The execution of a program is affected by certain information it
  820. receives from its superior.  GDB provides ways to specify this
  821. information, which you must do *before* starting your program.  (You
  822. can change it after starting your program, but such changes will only
  823. affect your program the next time you start it.)  This information may
  824. be divided into four categories:
  825. The *arguments.*
  826.      Specify the arguments to give your program as the arguments of the
  827.      `run' command.  If a shell is available on your target, the shell
  828.      is used to pass the arguments, so that you may use normal
  829.      conventions (such as wildcard expansion or variable substitution)
  830.      in describing the arguments.  In Unix systems, you can control
  831.      which shell is used with the `SHELL' environment variable. *Note
  832.      Your Program's Arguments: Arguments.
  833. The *environment.*
  834.      Your program normally inherits its environment from GDB, but you
  835.      can use the GDB commands `set environment' and `unset environment'
  836.      to change parts of the environment that will be given to your
  837.      program.  *Note Your Program's Environment: Environment.
  838. The *working directory.*
  839.      Your program inherits its working directory from GDB.  You can set
  840.      GDB's working directory with the `cd' command in GDB. *Note Your
  841.      Program's Working Directory: Working Directory.
  842. The *standard input and output.*
  843.      Your program normally uses the same device for standard input and
  844.      standard output as GDB is using.  You can redirect input and output
  845.      in the `run' command line, or you can use the `tty' command to set
  846.      a different device for your program. *Note Your Program's Input
  847.      and Output: Input/Output.
  848.      *Warning:* While input and output redirection work, you cannot use
  849.      pipes to pass the output of the program you are debugging to
  850.      another program; if you attempt this, GDB is likely to wind up
  851.      debugging the wrong program.
  852.    When you issue the `run' command, your program begins to execute
  853. immediately.  *Note Stopping and Continuing: Stopping, for discussion
  854. of how to arrange for your program to stop.  Once your program has
  855. stopped, you may calls functions in your program, using the `print' or
  856. `call' commands.  *Note Examining Data: Data.
  857.    If the modification time of your symbol file has changed since the
  858. last time GDB read its symbols, GDB will discard its symbol table and
  859. re-read it.  When it does this, GDB tries to retain your current
  860. breakpoints.
  861. File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
  862. Your Program's Arguments
  863. ========================
  864.    The arguments to your program can be specified by the arguments of
  865. the `run' command.  They are passed to a shell, which expands wildcard
  866. characters and performs redirection of I/O, and thence to your program.
  867. GDB uses the shell indicated by your environment variable `SHELL' if it
  868. exists; otherwise, GDB uses `/bin/sh'.
  869.    `run' with no arguments uses the same arguments used by the previous
  870. `run', or those set by the `set args' command.
  871. `set args'
  872.      Specify the arguments to be used the next time your program is
  873.      run.  If `set args' has no arguments, `run' will execute your
  874.      program with no arguments.  Once you have run your program with
  875.      arguments, using `set args' before the next `run' is the only way
  876.      to run it again without arguments.
  877. `show args'
  878.      Show the arguments to give your program when it is started.
  879. File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
  880. Your Program's Environment
  881. ==========================
  882.    The "environment" consists of a set of environment variables and
  883. their values.  Environment variables conventionally record such things
  884. as your user name, your home directory, your terminal type, and your
  885. search path for programs to run.  Usually you set up environment
  886. variables with the shell and they are inherited by all the other
  887. programs you run.  When debugging, it can be useful to try running your
  888. program with a modified environment without having to start GDB over
  889. again.
  890. `path DIRECTORY'
  891.      Add DIRECTORY to the front of the `PATH' environment variable (the
  892.      search path for executables), for both GDB and your program. You
  893.      may specify several directory names, separated by `:' or
  894.      whitespace.  If DIRECTORY is already in the path, it is moved to
  895.      the front, so it will be searched sooner.
  896.      You can use the string `$cwd' to refer to whatever is the current
  897.      working directory at the time GDB searches the path.  If you use
  898.      `.' instead, it refers to the directory where you executed the
  899.      `path' command.  GDB fills in the current path where needed in the
  900.      DIRECTORY argument, before adding it to the search path.
  901. `show paths'
  902.      Display the list of search paths for executables (the `PATH'
  903.      environment variable).
  904. `show environment [VARNAME]'
  905.      Print the value of environment variable VARNAME to be given to
  906.      your program when it starts.  If you do not supply VARNAME, print
  907.      the names and values of all environment variables to be given to
  908.      your program.  You can abbreviate `environment' as `env'.
  909. `set environment VARNAME [=] VALUE'
  910.      Sets environment variable VARNAME to VALUE.  The value changes for
  911.      your program only, not for GDB itself.  VALUE may be any string;
  912.      the values of environment variables are just strings, and any
  913.      interpretation is supplied by your program itself.  The VALUE
  914.      parameter is optional; if it is eliminated, the variable is set to
  915.      a null value.
  916.      For example, this command:
  917.           set env USER = foo
  918.      tells a Unix program, when subsequently run, that its user is named
  919.      `foo'.  (The spaces around `=' are used for clarity here; they are
  920.      not actually required.)
  921. `unset environment VARNAME'
  922.      Remove variable VARNAME from the environment to be passed to your
  923.      program.  This is different from `set env VARNAME ='; `unset
  924.      environment' removes the variable from the environment, rather
  925.      than assigning it an empty value.
  926. File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
  927. Your Program's Working Directory
  928. ================================
  929.    Each time you start your program with `run', it inherits its working
  930. directory from the current working directory of GDB.  GDB's working
  931. directory is initially whatever it inherited from its parent process
  932. (typically the shell), but you can specify a new working directory in
  933. GDB with the `cd' command.
  934.    The GDB working directory also serves as a default for the commands
  935. that specify files for GDB to operate on.  *Note Commands to Specify
  936. Files: Files.
  937. `cd DIRECTORY'
  938.      Set GDB's working directory to DIRECTORY.
  939. `pwd'
  940.      Print GDB's working directory.
  941. File: gdb.info,  Node: Input/Output,  Next: Attach,  Prev: Working Directory,  Up: Running
  942. Your Program's Input and Output
  943. ===============================
  944.    By default, the program you run under GDB does input and output to
  945. the same terminal that GDB uses.  GDB switches the terminal to its own
  946. terminal modes to interact with you, but it records the terminal modes
  947. your program was using and switches back to them when you continue
  948. running your program.
  949. `info terminal'
  950.      Displays GDB's recorded information about the terminal modes your
  951.      program is using.
  952.    You can redirect your program's input and/or output using shell
  953. redirection with the `run' command.  For example,
  954.      run > outfile
  955. starts your program, diverting its output to the file `outfile'.
  956.    Another way to specify where your program should do input and output
  957. is with the `tty' command.  This command accepts a file name as
  958. argument, and causes this file to be the default for future `run'
  959. commands.  It also resets the controlling terminal for the child
  960. process, for future `run' commands.  For example,
  961.      tty /dev/ttyb
  962. directs that processes started with subsequent `run' commands default
  963. to do input and output on the terminal `/dev/ttyb' and have that as
  964. their controlling terminal.
  965.    An explicit redirection in `run' overrides the `tty' command's
  966. effect on the input/output device, but not its effect on the controlling
  967. terminal.
  968.    When you use the `tty' command or redirect input in the `run'
  969. command, only the input *for your program* is affected.  The input for
  970. GDB still comes from your terminal.
  971.