home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / gdb.info-1 < prev    next >
Encoding:
GNU Info File  |  1995-03-04  |  49.0 KB  |  1,285 lines

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