home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gdb.i02 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  50KB  |  901 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: Attach,  Next: Kill Process,  Prev: Input/Output,  Up: Running
  25. Debugging an Already-Running Process
  26. ====================================
  27. `attach PROCESS-ID'
  28.      This command attaches to a running process--one that was started
  29.      outside GDB. (`info files' will show your active targets.)  The
  30.      command takes as argument a process ID.  The usual way to find out
  31.      the process-id of a Unix process is with the `ps' utility, or with
  32.      the `jobs -l' shell command.
  33.      `attach' will not repeat if you press RET a second time after
  34.      executing the command.
  35.    To use `attach', you must be debugging in an environment which
  36. supports processes.  You must also have permission to send the process a
  37. signal, and it must have the same effective user ID as the GDB process.
  38.    When using `attach', you should first use the `file' command to
  39. specify the program running in the process and load its symbol table.
  40. *Note Commands to Specify Files: Files.
  41.    The first thing GDB does after arranging to debug the specified
  42. process is to stop it.  You can examine and modify an attached process
  43. with all the GDB commands that are ordinarily available when you start
  44. processes with `run'.  You can insert breakpoints; you can step and
  45. continue; you can modify storage.  If you would rather the process
  46. continue running, you may use the `continue' command after attaching
  47. GDB to the process.
  48. `detach'
  49.      When you have finished debugging the attached process, you can use
  50.      the `detach' command to release it from GDB's control.  Detaching
  51.      the process continues its execution.  After the `detach' command,
  52.      that process and GDB become completely independent once more, and
  53.      you are ready to `attach' another process or start one with `run'.
  54.      `detach' will not repeat if you press RET again after executing
  55.      the command.
  56.    If you exit GDB or use the `run' command while you have an attached
  57. process, you kill that process.  By default, you will be asked for
  58. confirmation if you try to do either of these things; you can control
  59. whether or not you need to confirm by using the `set confirm' command
  60. (*note Optional Warnings and Messages: Messages/Warnings.).
  61. File: gdb.info,  Node: Kill Process,  Next: Process Information,  Prev: Attach,  Up: Running
  62. Killing the Child Process
  63. =========================
  64. `kill'
  65.      Kill the child process in which your program is running under GDB.
  66.    This command is useful if you wish to debug a core dump instead of a
  67. running process.  GDB ignores any core dump file while your program is
  68. running.
  69.    On some operating systems, a program cannot be executed outside GDB
  70. while you have breakpoints set on it inside GDB.  You can use the
  71. `kill' command in this situation to permit running your program outside
  72. the debugger.
  73.    The `kill' command is also useful if you wish to recompile and
  74. relink your program, since on many systems it is impossible to modify an
  75. executable file while it is running in a process.  In this case, when
  76. you next type `run', GDB will notice that the file has changed, and
  77. will re-read the symbol table (while trying to preserve your current
  78. breakpoint settings).
  79. File: gdb.info,  Node: Process Information,  Prev: Kill Process,  Up: Running
  80. Additional Process Information
  81. ==============================
  82.    Some operating systems provide a facility called `/proc' that can be
  83. used to examine the image of a running process using file-system
  84. subroutines.  If GDB is configured for an operating system with this
  85. facility, the command `info proc' is available to report on several
  86. kinds of information about the process running your program.
  87. `info proc'
  88.      Summarize available information about the process.
  89. `info proc mappings'
  90.      Report on the address ranges accessible in the program, with
  91.      information on whether your program may read, write, or execute
  92.      each range.
  93. `info proc times'
  94.      Starting time, user CPU time, and system CPU time for your program
  95.      and its children.
  96. `info proc id'
  97.      Report on the process ID's related to your program: its own
  98.      process id, the id of its parent, the process group id, and the
  99.      session id.
  100. `info proc status'
  101.      General information on the state of the process.  If the process is
  102.      stopped, this report includes the reason for stopping, and any
  103.      signal received.
  104. `info proc all'
  105.      Show all the above information about the process.
  106. File: gdb.info,  Node: Stopping,  Next: Stack,  Prev: Running,  Up: Top
  107. Stopping and Continuing
  108. ***********************
  109.    The principal purpose of using a debugger is so that you can stop
  110. your program before it terminates; or so that, if your program runs into
  111. trouble, you can investigate and find out why.
  112.    Inside GDB, your program may stop for any of several reasons, such
  113. as a signal, a breakpoint, or reaching a new line after a GDB command
  114. such as `step'.  You may then examine and change variables, set new
  115. breakpoints or remove old ones, and then continue execution.  Usually,
  116. the messages shown by GDB provide ample explanation of the status of
  117. your program--but you can also explicitly request this information at
  118. any time.
  119. `info program'
  120.      Display information about the status of your program: whether it is
  121.      running or not, what process it is, and why it stopped.
  122. * Menu:
  123. * Breakpoints::                 Breakpoints, Watchpoints, and Exceptions
  124. * Continuing and Stepping::     Resuming Execution
  125. * Signals::                     Signals
  126. File: gdb.info,  Node: Breakpoints,  Next: Continuing and Stepping,  Up: Stopping
  127. Breakpoints, Watchpoints, and Exceptions
  128. ========================================
  129.    A "breakpoint" makes your program stop whenever a certain point in
  130. the program is reached.  For each breakpoint, you can add various
  131. conditions to control in finer detail whether your program will stop.
  132. You can set breakpoints with the `break' command and its variants
  133. (*note Setting Breakpoints: Set Breaks.), to specify the place where
  134. your program should stop by line number, function name or exact address
  135. in the program. In languages with exception handling (such as GNU C++),
  136. you can also set breakpoints where an exception is raised (*note
  137. Breakpoints and Exceptions: Exception Handling.).
  138.    A "watchpoint" is a special breakpoint that stops your program when
  139. the value of an expression changes.  You must use a different command
  140. to set watchpoints (*note Setting Watchpoints: Set Watchpoints.), but
  141. aside from that, you can manage a watchpoint like any other breakpoint:
  142. you enable, disable, and delete both breakpoints and watchpoints using
  143. the same commands.
  144.    GDB assigns a number to each breakpoint or watchpoint when you
  145. create it; these numbers are successive integers starting with one.  In
  146. many of the commands for controlling various features of breakpoints you
  147. use the breakpoint number to say which breakpoint you want to change.
  148. Each breakpoint may be "enabled" or "disabled"; if disabled, it has no
  149. effect on your program until you enable it again.
  150. * Menu:
  151. * Set Breaks::                  Setting Breakpoints
  152. * Set Watchpoints::             Setting Watchpoints
  153. * Exception Handling::          Breakpoints and Exceptions
  154. * Delete Breaks::               Deleting Breakpoints
  155. * Disabling::                   Disabling Breakpoints
  156. * Conditions::                  Break Conditions
  157. * Break Commands::              Breakpoint Command Lists
  158. * Breakpoint Menus::            Breakpoint Menus
  159. * Error in Breakpoints::
  160. File: gdb.info,  Node: Set Breaks,  Next: Set Watchpoints,  Up: Breakpoints
  161. Setting Breakpoints
  162. -------------------
  163.    Breakpoints are set with the `break' command (abbreviated `b').  The
  164. debugger convenience variable `$bpnum' records the number of the
  165. beakpoint you've set most recently; see *Note Convenience Variables:
  166. Convenience Vars, for a discussion of what you can do with convenience
  167. variables.
  168.    You have several ways to say where the breakpoint should go.
  169. `break FUNCTION'
  170.      Set a breakpoint at entry to function FUNCTION. When using source
  171.      languages that permit overloading of symbols, such as C++,
  172.      FUNCTION may refer to more than one possible place to break. *Note
  173.      Breakpoint Menus::, for a discussion of that situation.
  174. `break +OFFSET'
  175. `break -OFFSET'
  176.      Set a breakpoint some number of lines forward or back from the
  177.      position at which execution stopped in the currently selected
  178.      frame.
  179. `break LINENUM'
  180.      Set a breakpoint at line LINENUM in the current source file. That
  181.      file is the last file whose source text was printed.  This
  182.      breakpoint will stop your program just before it executes any of
  183.      the code on that line.
  184. `break FILENAME:LINENUM'
  185.      Set a breakpoint at line LINENUM in source file FILENAME.
  186. `break FILENAME:FUNCTION'
  187.      Set a breakpoint at entry to function FUNCTION found in file
  188.      FILENAME.  Specifying a file name as well as a function name is
  189.      superfluous except when multiple files contain similarly named
  190.      functions.
  191. `break *ADDRESS'
  192.      Set a breakpoint at address ADDRESS.  You can use this to set
  193.      breakpoints in parts of your program which do not have debugging
  194.      information or source files.
  195. `break'
  196.      When called without any arguments, `break' sets a breakpoint at
  197.      the next instruction to be executed in the selected stack frame
  198.      (*note Examining the Stack: Stack.).  In any selected frame but the
  199.      innermost, this will cause your program to stop as soon as control
  200.      returns to that frame.  This is similar to the effect of a
  201.      `finish' command in the frame inside the selected frame--except
  202.      that `finish' does not leave an active breakpoint.  If you use
  203.      `break' without an argument in the innermost frame, GDB will stop
  204.      the next time it reaches the current location; this may be useful
  205.      inside loops.
  206.      GDB normally ignores breakpoints when it resumes execution, until
  207.      at least one instruction has been executed.  If it did not do
  208.      this, you would be unable to proceed past a breakpoint without
  209.      first disabling the breakpoint.  This rule applies whether or not
  210.      the breakpoint already existed when your program stopped.
  211. `break ... if COND'
  212.      Set a breakpoint with condition COND; evaluate the expression COND
  213.      each time the breakpoint is reached, and stop only if the value is
  214.      nonzero--that is, if COND evaluates as true. `...' stands for one
  215.      of the possible arguments described above (or no argument)
  216.      specifying where to break.  *Note Break Conditions: Conditions,
  217.      for more information on breakpoint conditions.
  218. `tbreak ARGS'
  219.      Set a breakpoint enabled only for one stop.  ARGS are the same as
  220.      for the `break' command, and the breakpoint is set in the same
  221.      way, but the breakpoint is automatically disabled after the first
  222.      time your program stops there.  *Note Disabling Breakpoints:
  223.      Disabling.
  224. `rbreak REGEX'
  225.      Set breakpoints on all functions matching the regular expression
  226.      REGEX.  This command sets an unconditional breakpoint on all
  227.      matches, printing a list of all breakpoints it set. Once these
  228.      breakpoints are set, they are treated just like the breakpoints
  229.      set with the `break' command.  They can be deleted, disabled, made
  230.      conditional, etc., in the standard ways.
  231.      When debugging C++ programs, `rbreak' is useful for setting
  232.      breakpoints on overloaded functions that are not members of any
  233.      special classes.
  234. `info breakpoints [N]'
  235. `info break [N]'
  236. `info watchpoints [N]'
  237.      Print a table of all breakpoints and watchpoints set and not
  238.      deleted, with the following columns for each breakpoint:
  239.     *Breakpoint Numbers*
  240.     *Type*
  241.           Breakpoint or watchpoint.
  242.     *Disposition*
  243.           Whether the breakpoint is marked to be disabled or deleted
  244.           when hit.
  245.     *Enabled or Disabled*
  246.           Enabled breakpoints are marked with `y'.  `n' marks
  247.           breakpoints that are not enabled.
  248.     *Address*
  249.           Where the breakpoint is in your program, as a memory address
  250.     *What*
  251.           Where the breakpoint is in the source for your program, as a
  252.           file and line number.
  253.      Breakpoint commands, if any, are listed after the line for the
  254.      corresponding breakpoint.
  255.      `info break' with a breakpoint number N as argument lists only
  256.      that breakpoint.  The convenience variable `$_' and the default
  257.      examining-address for the `x' command are set to the address of
  258.      the last breakpoint listed (*note Examining Memory: Memory.).
  259.    GDB allows you to set any number of breakpoints at the same place in
  260. your program.  There is nothing silly or meaningless about this.  When
  261. the breakpoints are conditional, this is even useful (*note Break
  262. Conditions: Conditions.).
  263.    GDB itself sometimes sets breakpoints in your program for special
  264. purposes, such as proper handling of `longjmp' (in C programs). These
  265. internal breakpoints are assigned negative numbers, starting with `-1';
  266. `info breakpoints' does not display them.
  267.    You can see these breakpoints with the GDB maintenance command
  268. `maint info breakpoints'.
  269. `maint info breakpoints'
  270.      Using the same format as `info breakpoints', display both the
  271.      breakpoints you've set explicitly, and those GDB is using for
  272.      internal purposes.  Internal breakpoints are shown with negative
  273.      breakpoint numbers.  The type column identifies what kind of
  274.      breakpoint is shown:
  275.     `breakpoint'
  276.           Normal, explicitly set breakpoint.
  277.     `watchpoint'
  278.           Normal, explicitly set watchpoint.
  279.     `longjmp'
  280.           Internal breakpoint, used to handle correctly stepping through
  281.           `longjmp' calls.
  282.     `longjmp resume'
  283.           Internal breakpoint at the target of a `longjmp'.
  284.     `until'
  285.           Temporary internal breakpoint used by the GDB `until' command.
  286.     `finish'
  287.           Temporary internal breakpoint used by the GDB `finish'
  288.           command.
  289. File: gdb.info,  Node: Set Watchpoints,  Next: Exception Handling,  Prev: Set Breaks,  Up: Breakpoints
  290. Setting Watchpoints
  291. -------------------
  292.    You can use a watchpoint to stop execution whenever the value of an
  293. expression changes, without having to predict a particular place where
  294. this may happen.
  295.    Watchpoints currently execute two orders of magnitude more slowly
  296. than other breakpoints, but this can well be worth it to catch errors
  297. where you have no clue what part of your program is the culprit.  Some
  298. processors provide special hardware to support watchpoint evaluation;
  299. future releases of GDB will use such hardware if it is available.
  300. `watch EXPR'
  301.      Set a watchpoint for an expression.
  302. `info watchpoints'
  303.      This command prints a list of watchpoints and breakpoints; it is
  304.      the same as `info break'.
  305. File: gdb.info,  Node: Exception Handling,  Next: Delete Breaks,  Prev: Set Watchpoints,  Up: Breakpoints
  306. Breakpoints and Exceptions
  307. --------------------------
  308.    Some languages, such as GNU C++, implement exception handling.  You
  309. can use GDB to examine what caused your program to raise an exception,
  310. and to list the exceptions your program is prepared to handle at a
  311. given point in time.
  312. `catch EXCEPTIONS'
  313.      You can set breakpoints at active exception handlers by using the
  314.      `catch' command.  EXCEPTIONS is a list of names of exceptions to
  315.      catch.
  316.    You can use `info catch' to list active exception handlers. *Note
  317. Information About a Frame: Frame Info.
  318.    There are currently some limitations to exception handling in GDB.
  319. These will be corrected in a future release.
  320.    * If you call a function interactively, GDB normally returns control
  321.      to you when the function has finished executing.  If the call
  322.      raises an exception, however, the call may bypass the mechanism
  323.      that returns control to you and cause your program to simply
  324.      continue running until it hits a breakpoint, catches a signal that
  325.      GDB is listening for, or exits.
  326.    * You cannot raise an exception interactively.
  327.    * You cannot interactively install an exception handler.
  328.    Sometimes `catch' is not the best way to debug exception handling:
  329. if you need to know exactly where an exception is raised, it is better
  330. to stop *before* the exception handler is called, since that way you
  331. can see the stack before any unwinding takes place.  If you set a
  332. breakpoint in an exception handler instead, it may not be easy to find
  333. out where the exception was raised.
  334.    To stop just before an exception handler is called, you need some
  335. knowledge of the implementation.  In the case of GNU C++, exceptions are
  336. raised by calling a library function named `__raise_exception' which
  337. has the following ANSI C interface:
  338.          /* ADDR is where the exception identifier is stored.
  339.             ID is the exception identifier.  */
  340.          void __raise_exception (void **ADDR, void *ID);
  341. To make the debugger catch all exceptions before any stack unwinding
  342. takes place, set a breakpoint on `__raise_exception' (*note Breakpoints
  343. Watchpoints and Exceptions: Breakpoints.).
  344.    With a conditional breakpoint (*note Break Conditions: Conditions.)
  345. that depends on the value of ID, you can stop your program when a
  346. specific exception is raised.  You can use multiple conditional
  347. breakpoints to stop your program when any of a number of exceptions are
  348. raised.
  349. File: gdb.info,  Node: Delete Breaks,  Next: Disabling,  Prev: Exception Handling,  Up: Breakpoints
  350. Deleting Breakpoints
  351. --------------------
  352.    It is often necessary to eliminate a breakpoint or watchpoint once it
  353. has done its job and you no longer want your program to stop there. 
  354. This is called "deleting" the breakpoint.  A breakpoint that has been
  355. deleted no longer exists; it is forgotten.
  356.    With the `clear' command you can delete breakpoints according to
  357. where they are in your program.  With the `delete' command you can
  358. delete individual breakpoints or watchpoints by specifying their
  359. breakpoint numbers.
  360.    It is not necessary to delete a breakpoint to proceed past it.  GDB
  361. automatically ignores breakpoints on the first instruction to be
  362. executed when you continue execution without changing the execution
  363. address.
  364. `clear'
  365.      Delete any breakpoints at the next instruction to be executed in
  366.      the selected stack frame (*note Selecting a Frame: Selection.). 
  367.      When the innermost frame is selected, this is a good way to delete
  368.      a breakpoint where your program just stopped.
  369. `clear FUNCTION'
  370. `clear FILENAME:FUNCTION'
  371.      Delete any breakpoints set at entry to the function FUNCTION.
  372. `clear LINENUM'
  373. `clear FILENAME:LINENUM'
  374.      Delete any breakpoints set at or within the code of the specified
  375.      line.
  376. `delete [breakpoints] [BNUMS...]'
  377.      Delete the breakpoints or watchpoints of the numbers specified as
  378.      arguments.  If no argument is specified, delete all breakpoints
  379.      (GDB asks confirmation, unless you have `set confirm off').  You
  380.      can abbreviate this command as `d'.
  381. File: gdb.info,  Node: Disabling,  Next: Conditions,  Prev: Delete Breaks,  Up: Breakpoints
  382. Disabling Breakpoints
  383. ---------------------
  384.    Rather than deleting a breakpoint or watchpoint, you might prefer to
  385. "disable" it.  This makes the breakpoint inoperative as if it had been
  386. deleted, but remembers the information on the breakpoint so that you
  387. can "enable" it again later.
  388.    You disable and enable breakpoints and watchpoints with the `enable'
  389. and `disable' commands, optionally specifying one or more breakpoint
  390. numbers as arguments.  Use `info break' or `info watch' to print a list
  391. of breakpoints or watchpoints if you do not know which numbers to use.
  392.    A breakpoint or watchpoint can have any of four different states of
  393. enablement:
  394.    * Enabled.  The breakpoint will stop your program.  A breakpoint set
  395.      with the `break' command starts out in this state.
  396.    * Disabled.  The breakpoint has no effect on your program.
  397.    * Enabled once.  The breakpoint will stop your program, but when it
  398.      does so it will become disabled.  A breakpoint set with the
  399.      `tbreak' command starts out in this state.
  400.    * Enabled for deletion.  The breakpoint will stop your program, but
  401.      immediately after it does so it will be deleted permanently.
  402.    You can use the following commands to enable or disable breakpoints
  403. and watchpoints:
  404. `disable [breakpoints] [BNUMS...]'
  405.      Disable the specified breakpoints--or all breakpoints, if none are
  406.      listed.  A disabled breakpoint has no effect but is not forgotten.
  407.       All options such as ignore-counts, conditions and commands are
  408.      remembered in case the breakpoint is enabled again later.  You may
  409.      abbreviate `disable' as `dis'.
  410. `enable [breakpoints] [BNUMS...]'
  411.      Enable the specified breakpoints (or all defined breakpoints). 
  412.      They become effective once again in stopping your program.
  413. `enable [breakpoints] once BNUMS...'
  414.      Enable the specified breakpoints temporarily.  Each will be
  415.      disabled again the next time it stops your program.
  416. `enable [breakpoints] delete BNUMS...'
  417.      Enable the specified breakpoints to work once and then die.  Each
  418.      of the breakpoints will be deleted the next time it stops your
  419.      program.
  420.    Save for a breakpoint set with `tbreak' (*note Setting Breakpoints:
  421. Set Breaks.), breakpoints that you set are initially enabled;
  422. subsequently, they become disabled or enabled only when you use one of
  423. the commands above.  (The command `until' can set and delete a
  424. breakpoint of its own, but it will not change the state of your other
  425. breakpoints; see *Note Continuing and Stepping: Continuing and
  426. Stepping.)
  427. File: gdb.info,  Node: Conditions,  Next: Break Commands,  Prev: Disabling,  Up: Breakpoints
  428. Break Conditions
  429. ----------------
  430.    The simplest sort of breakpoint breaks every time your program
  431. reaches a specified place.  You can also specify a "condition" for a
  432. breakpoint.  A condition is just a Boolean expression in your
  433. programming language (*note Expressions: Expressions.).  A breakpoint
  434. with a condition evaluates the expression each time your program
  435. reaches it, and your program stops only if the condition is *true*.
  436.    This is the converse of using assertions for program validation; in
  437. that situation, you want to stop when the assertion is violated--that
  438. is, when the condition is false.  In C, if you want to test an
  439. assertion expressed by the condition ASSERT, you should set the
  440. condition `! ASSERT' on the appropriate breakpoint.
  441.    Conditions are also accepted for watchpoints; you may not need them,
  442. since a watchpoint is inspecting the value of an expression anyhow--but
  443. it might be simpler, say, to just set a watchpoint on a variable name,
  444. and specify a condition that tests whether the new value is an
  445. interesting one.
  446.    Break conditions can have side effects, and may even call functions
  447. in your program.  This can be useful, for example, to activate functions
  448. that log program progress, or to use your own print functions to format
  449. special data structures. The effects are completely predictable unless
  450. there is another enabled breakpoint at the same address.  (In that
  451. case, GDB might see the other breakpoint first and stop your program
  452. without checking the condition of this one.)  Note that breakpoint
  453. commands are usually more convenient and flexible for the purpose of
  454. performing side effects when a breakpoint is reached (*note Breakpoint
  455. Command Lists: Break Commands.).
  456.    Break conditions can be specified when a breakpoint is set, by using
  457. `if' in the arguments to the `break' command.  *Note Setting
  458. Breakpoints: Set Breaks.  They can also be changed at any time with the
  459. `condition' command.  The `watch' command does not recognize the `if'
  460. keyword; `condition' is the only way to impose a further condition on a
  461. watchpoint.
  462. `condition BNUM EXPRESSION'
  463.      Specify EXPRESSION as the break condition for breakpoint or
  464.      watchpoint number BNUM.  From now on, this breakpoint will stop
  465.      your program only if the value of EXPRESSION is true (nonzero, in
  466.      C).  When you use `condition', GDB checks EXPRESSION immediately
  467.      for syntactic correctness, and to determine whether symbols in it
  468.      have referents in the context of your breakpoint. GDB does not
  469.      actually evaluate EXPRESSION at the time the `condition' command
  470.      is given, however.  *Note Expressions: Expressions.
  471. `condition BNUM'
  472.      Remove the condition from breakpoint number BNUM.  It becomes an
  473.      ordinary unconditional breakpoint.
  474.    A special case of a breakpoint condition is to stop only when the
  475. breakpoint has been reached a certain number of times.  This is so
  476. useful that there is a special way to do it, using the "ignore count"
  477. of the breakpoint.  Every breakpoint has an ignore count, which is an
  478. integer.  Most of the time, the ignore count is zero, and therefore has
  479. no effect.  But if your program reaches a breakpoint whose ignore count
  480. is positive, then instead of stopping, it just decrements the ignore
  481. count by one and continues.  As a result, if the ignore count value is
  482. N, the breakpoint will not stop the next N times it is reached.
  483. `ignore BNUM COUNT'
  484.      Set the ignore count of breakpoint number BNUM to COUNT. The next
  485.      COUNT times the breakpoint is reached, your program's execution
  486.      will not stop; other than to decrement the ignore count, GDB takes
  487.      no action.
  488.      To make the breakpoint stop the next time it is reached, specify a
  489.      count of zero.
  490. `continue COUNT'
  491. `c COUNT'
  492. `fg COUNT'
  493.      Continue execution of your program, setting the ignore count of the
  494.      breakpoint where your program stopped to COUNT minus one. Thus,
  495.      your program will not stop at this breakpoint until the COUNT'th
  496.      time it is reached.
  497.      An argument to this command is meaningful only when your program
  498.      stopped due to a breakpoint.  At other times, the argument to
  499.      `continue' is ignored.
  500.      The synonym `fg' is provided purely for convenience, and has
  501.      exactly the same behavior as other forms of the command.
  502.    If a breakpoint has a positive ignore count and a condition, the
  503. condition is not checked.  Once the ignore count reaches zero, the
  504. condition will be checked.
  505.    You could achieve the effect of the ignore count with a condition
  506. such as `$foo-- <= 0' using a debugger convenience variable that is
  507. decremented each time.  *Note Convenience Variables: Convenience Vars.
  508. File: gdb.info,  Node: Break Commands,  Next: Breakpoint Menus,  Prev: Conditions,  Up: Breakpoints
  509. Breakpoint Command Lists
  510. ------------------------
  511.    You can give any breakpoint (or watchpoint) a series of commands to
  512. execute when your program stops due to that breakpoint.  For example,
  513. you might want to print the values of certain expressions, or enable
  514. other breakpoints.
  515. `commands [BNUM]'
  516. `... COMMAND-LIST ...'
  517. `end'
  518.      Specify a list of commands for breakpoint number BNUM.  The
  519.      commands themselves appear on the following lines.  Type a line
  520.      containing just `end' to terminate the commands.
  521.      To remove all commands from a breakpoint, type `commands' and
  522.      follow it immediately with `end'; that is, give no commands.
  523.      With no BNUM argument, `commands' refers to the last breakpoint or
  524.      watchpoint set (not to the breakpoint most recently encountered).
  525.    Pressing RET as a means of repeating the last GDB command is
  526. disabled within a COMMAND-LIST.
  527.    You can use breakpoint commands to start your program up again. 
  528. Simply use the `continue' command, or `step', or any other command that
  529. resumes execution.  Subsequent commands in the command list are ignored.
  530.    If the first command specified is `silent', the usual message about
  531. stopping at a breakpoint is not printed.  This may be desirable for
  532. breakpoints that are to print a specific message and then continue. If
  533. the remaining commands too print nothing, you will see no sign that the
  534. breakpoint was reached at all.  `silent' is meaningful only at the
  535. beginning of a breakpoint command list.
  536.    The commands `echo' and `output' that allow you to print precisely
  537. controlled output are often useful in silent breakpoints. *Note
  538. Commands for Controlled Output: Output.
  539.    For example, here is how you could use breakpoint commands to print
  540. the value of `x' at entry to `foo' whenever `x' is positive.
  541.      break foo if x>0
  542.      commands
  543.      silent
  544.      echo x is\040
  545.      output x
  546.      echo \n
  547.      cont
  548.      end
  549.    One application for breakpoint commands is to compensate for one bug
  550. so you can test for another.  Put a breakpoint just after the erroneous
  551. line of code, give it a condition to detect the case in which something
  552. erroneous has been done, and give it commands to assign correct values
  553. to any variables that need them.  End with the `continue' command so
  554. that your program does not stop, and start with the `silent' command so
  555. that no output is produced.  Here is an example:
  556.      break 403
  557.      commands
  558.      silent
  559.      set x = y + 4
  560.      cont
  561.      end
  562.    One deficiency in the operation of automatically continuing
  563. breakpoints under Unix appears when your program uses raw mode for the
  564. terminal. GDB switches back to its own terminal modes (not raw) before
  565. executing commands, and then must switch back to raw mode when your
  566. program is continued.  This causes any pending terminal input to be
  567. lost.
  568.    Under Unix, you can get around this problem by writing actions into
  569. the breakpoint condition rather than in commands.  For example
  570.      condition 5  (x = y + 4), 0
  571. specifies a condition expression (*note Expressions: Expressions.) that
  572. will change `x' as needed, then always have the value zero so your
  573. program will not stop.  No input is lost here, because GDB evaluates
  574. break conditions without changing the terminal modes.  When you want to
  575. have nontrivial conditions for performing the side effects, the
  576. operators `&&', `||' and `?...:' may be useful.
  577. File: gdb.info,  Node: Breakpoint Menus,  Next: Error in Breakpoints,  Prev: Break Commands,  Up: Breakpoints
  578. Breakpoint Menus
  579. ----------------
  580.    Some programming languages (notably C++) permit a single function
  581. name to be defined several times, for application in different contexts.
  582. This is called "overloading".  When a function name is overloaded,
  583. `break FUNCTION' is not enough to tell GDB where you want a breakpoint.
  584.  If you realize this will be a problem, you can use something like
  585. `break FUNCTION(TYPES)' to specify which particular version of the
  586. function you want.  Otherwise, GDB offers you a menu of numbered
  587. choices for different possible breakpoints, and waits for your
  588. selection with the prompt `>'.  The first two options are always `[0]
  589. cancel' and `[1] all'.  Typing `1' sets a breakpoint at each definition
  590. of FUNCTION, and typing `0' aborts the `break' command without setting
  591. any new breakpoints.
  592.    For example, the following session excerpt shows an attempt to set a
  593. breakpoint at the overloaded symbol `String::after'. We choose three
  594. particular definitions of that function name:
  595.      (gdb) b String::after
  596.      [0] cancel
  597.      [1] all
  598.      [2] file:String.cc; line number:867
  599.      [3] file:String.cc; line number:860
  600.      [4] file:String.cc; line number:875
  601.      [5] file:String.cc; line number:853
  602.      [6] file:String.cc; line number:846
  603.      [7] file:String.cc; line number:735
  604.      > 2 4 6
  605.      Breakpoint 1 at 0xb26c: file String.cc, line 867.
  606.      Breakpoint 2 at 0xb344: file String.cc, line 875.
  607.      Breakpoint 3 at 0xafcc: file String.cc, line 846.
  608.      Multiple breakpoints were set.
  609.      Use the "delete" command to delete unwanted breakpoints.
  610.      (gdb)
  611. File: gdb.info,  Node: Error in Breakpoints,  Prev: Breakpoint Menus,  Up: Breakpoints
  612. "Cannot Insert Breakpoints"
  613. ---------------------------
  614.    Under some operating systems, breakpoints cannot be used in a
  615. program if any other process is running that program.  In this
  616. situation, attempting to run or continue a program with a breakpoint
  617. causes GDB to stop the other process.
  618.    When this happens, you have three ways to proceed:
  619.   1. Remove or disable the breakpoints, then continue.
  620.   2. Suspend GDB, and copy the file containing your program to a new
  621.      name. Resume GDB and use the `exec-file' command to specify that
  622.      GDB should run your program under that name.  Then start your
  623.      program again.
  624.   3. Relink your program so that the text segment is nonsharable, using
  625.      the linker option `-N'.  The operating system limitation may not
  626.      apply to nonsharable executables.
  627. File: gdb.info,  Node: Continuing and Stepping,  Next: Signals,  Prev: Breakpoints,  Up: Stopping
  628. Continuing and Stepping
  629. =======================
  630.    "Continuing" means resuming program execution until your program
  631. completes normally.  In contrast, "stepping" means executing just one
  632. more "step" of your program, where "step" may mean either one line of
  633. source code, or one machine instruction (depending on what particular
  634. command you use).  Either when continuing or when stepping, your
  635. program may stop even sooner, due to a breakpoint or to a signal.  (If
  636. due to a signal, you may want to use `handle', or use `signal 0' to
  637. resume execution. *Note Signals: Signals.)
  638. `continue [IGNORE-COUNT]'
  639.      Resume program execution, at the address where your program last
  640.      stopped; any breakpoints set at that address are bypassed.  The
  641.      optional argument IGNORE-COUNT allows you to specify a further
  642.      number of times to ignore a breakpoint at this location; its
  643.      effect is like that of `ignore' (*note Break Conditions:
  644.      Conditions.).
  645.      To resume execution at a different place, you can use `return'
  646.      (*note Returning from a Function: Returning.) to go back to the
  647.      calling function; or `jump' (*note Continuing at a Different
  648.      Address: Jumping.) to go to an arbitrary location in your program.
  649.    A typical technique for using stepping is to set a breakpoint (*note
  650. Breakpoints Watchpoints and Exceptions: Breakpoints.) at the beginning
  651. of the function or the section of your program where a problem is
  652. believed to lie, run your program until it stops at that breakpoint,
  653. and then step through the suspect area, examining the variables that
  654. are interesting, until you see the problem happen.
  655. `step'
  656.      Continue running your program until control reaches a different
  657.      source line, then stop it and return control to GDB.  This command
  658.      is abbreviated `s'.
  659.           *Warning:* If you use the `step' command while control is
  660.           within a function that was compiled without debugging
  661.           information, execution will proceed until control reaches
  662.           another function.
  663. `step COUNT'
  664.      Continue running as in `step', but do so COUNT times.  If a
  665.      breakpoint is reached or a signal not related to stepping occurs
  666.      before COUNT steps, stepping stops right away.
  667. `next [COUNT]'
  668.      Continue to the next source line in the current (innermost) stack
  669.      frame. Similar to `step', but any function calls appearing within
  670.      the line of code are executed without stopping.  Execution stops
  671.      when control reaches a different line of code at the stack level
  672.      which was executing when the `next' command was given.  This
  673.      command is abbreviated `n'.
  674.      An argument COUNT is a repeat count, as for `step'.
  675.      `next' within a function that lacks debugging information acts like
  676.      `step', but any function calls appearing within the code of the
  677.      function are executed without stopping.
  678. `finish'
  679.      Continue running until just after function in the selected stack
  680.      frame returns.  Print the returned value (if any).
  681.      Contrast this with the `return' command (*note Returning from a
  682.      Function: Returning.).
  683. `until'
  684.      Continue running until a source line past the current line, in the
  685.      current stack frame, is reached.  This command is used to avoid
  686.      single stepping through a loop more than once.  It is like the
  687.      `next' command, except that when `until' encounters a jump, it
  688.      automatically continues execution until the program counter is
  689.      greater than the address of the jump.
  690.      This means that when you reach the end of a loop after single
  691.      stepping though it, `until' will cause your program to continue
  692.      execution until the loop is exited.  In contrast, a `next' command
  693.      at the end of a loop will simply step back to the beginning of the
  694.      loop, which would force you to step through the next iteration.
  695.      `until' always stops your program if it attempts to exit the
  696.      current stack frame.
  697.      `until' may produce somewhat counterintuitive results if the order
  698.      of machine code does not match the order of the source lines.  For
  699.      example, in the following excerpt from a debugging session, the `f'
  700.      (`frame') command shows that execution is stopped at line `206';
  701.      yet when we use `until', we get to line `195':
  702.           (gdb) f
  703.           #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
  704.           206                 expand_input();
  705.           (gdb) until
  706.           195             for ( ; argc > 0; NEXTARG) {
  707.      This happened because, for execution efficiency, the compiler had
  708.      generated code for the loop closure test at the end, rather than
  709.      the start, of the loop--even though the test in a C `for'-loop is
  710.      written before the body of the loop.  The `until' command appeared
  711.      to step back to the beginning of the loop when it advanced to this
  712.      expression; however, it has not really gone to an earlier
  713.      statement--not in terms of the actual machine code.
  714.      `until' with no argument works by means of single instruction
  715.      stepping, and hence is slower than `until' with an argument.
  716. `until LOCATION'
  717. `u LOCATION'
  718.      Continue running your program until either the specified location
  719.      is reached, or the current stack frame returns.  LOCATION is any of
  720.      the forms of argument acceptable to `break' (*note Setting
  721.      Breakpoints: Set Breaks.).  This form of the command uses
  722.      breakpoints, and hence is quicker than `until' without an argument.
  723. `stepi'
  724.      Execute one machine instruction, then stop and return to the
  725.      debugger.
  726.      It is often useful to do `display/i $pc' when stepping by machine
  727.      instructions.  This will cause the next instruction to be executed
  728.      to be displayed automatically at each stop.  *Note Automatic
  729.      Display: Auto Display.
  730.      An argument is a repeat count, as in `step'.
  731. `nexti'
  732.      Execute one machine instruction, but if it is a function call,
  733.      proceed until the function returns.
  734.      An argument is a repeat count, as in `next'.
  735. File: gdb.info,  Node: Signals,  Prev: Continuing and Stepping,  Up: Stopping
  736. Signals
  737. =======
  738.    A signal is an asynchronous event that can happen in a program.  The
  739. operating system defines the possible kinds of signals, and gives each
  740. kind a name and a number.  For example, in Unix `SIGINT' is the signal
  741. a program gets when you type an interrupt (often `C-c'); `SIGSEGV' is
  742. the signal a program gets from referencing a place in memory far away
  743. from all the areas in use; `SIGALRM' occurs when the alarm clock timer
  744. goes off (which happens only if your program has requested an alarm).
  745.    Some signals, including `SIGALRM', are a normal part of the
  746. functioning of your program.  Others, such as `SIGSEGV', indicate
  747. errors; these signals are "fatal" (kill your program immediately) if the
  748. program has not specified in advance some other way to handle the
  749. signal. `SIGINT' does not indicate an error in your program, but it is
  750. normally fatal so it can carry out the purpose of the interrupt: to
  751. kill the program.
  752.    GDB has the ability to detect any occurrence of a signal in your
  753. program.  You can tell GDB in advance what to do for each kind of
  754. signal.
  755.    Normally, GDB is set up to ignore non-erroneous signals like
  756. `SIGALRM' (so as not to interfere with their role in the functioning of
  757. your program) but to stop your program immediately whenever an error
  758. signal happens. You can change these settings with the `handle' command.
  759. `info signals'
  760.      Print a table of all the kinds of signals and how GDB has been
  761.      told to handle each one.  You can use this to see the signal
  762.      numbers of all the defined types of signals.
  763. `handle SIGNAL KEYWORDS...'
  764.      Change the way GDB handles signal SIGNAL.  SIGNAL can be the
  765.      number of a signal or its name (with or without the `SIG' at the
  766.      beginning).  The KEYWORDS say what change to make.
  767.    The keywords allowed by the `handle' command can be abbreviated.
  768. Their full names are:
  769. `nostop'
  770.      GDB should not stop your program when this signal happens.  It may
  771.      still print a message telling you that the signal has come in.
  772. `stop'
  773.      GDB should stop your program when this signal happens.  This
  774.      implies the `print' keyword as well.
  775. `print'
  776.      GDB should print a message when this signal happens.
  777. `noprint'
  778.      GDB should not mention the occurrence of the signal at all.  This
  779.      implies the `nostop' keyword as well.
  780. `pass'
  781.      GDB should allow your program to see this signal; your program
  782.      will be able to handle the signal, or may be terminated if the
  783.      signal is fatal and not handled.
  784. `nopass'
  785.      GDB should not allow your program to see this signal.
  786.    When a signal has been set to stop your program, your program cannot
  787. see the signal until you continue.  It will see the signal then, if
  788. `pass' is in effect for the signal in question *at that time*.  In
  789. other words, after GDB reports a signal, you can use the `handle'
  790. command with `pass' or `nopass' to control whether that signal will be
  791. seen by your program when you later continue it.
  792.    You can also use the `signal' command to prevent your program from
  793. seeing a signal, or cause it to see a signal it normally would not see,
  794. or to give it any signal at any time.  For example, if your program
  795. stopped due to some sort of memory reference error, you might store
  796. correct values into the erroneous variables and continue, hoping to see
  797. more execution; but your program would probably terminate immediately as
  798. a result of the fatal signal once it saw the signal.  To prevent this,
  799. you can continue with `signal 0'.  *Note Giving your Program a Signal:
  800. Signaling.
  801. File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
  802. Examining the Stack
  803. *******************
  804.    When your program has stopped, the first thing you need to know is
  805. where it stopped and how it got there.
  806.    Each time your program performs a function call, the information
  807. about where in your program the call was made from is saved in a block
  808. of data called a "stack frame".  The frame also contains the arguments
  809. of the call and the local variables of the function that was called. 
  810. All the stack frames are allocated in a region of memory called the
  811. "call stack".
  812.    When your program stops, the GDB commands for examining the stack
  813. allow you to see all of this information.
  814.    One of the stack frames is "selected" by GDB and many GDB commands
  815. refer implicitly to the selected frame.  In particular, whenever you ask
  816. GDB for the value of a variable in your program, the value is found in
  817. the selected frame.  There are special GDB commands to select whichever
  818. frame you are interested in.
  819.    When your program stops, GDB automatically selects the currently
  820. executing frame and describes it briefly as the `frame' command does
  821. (*note Information About a Frame: Frame Info.).
  822. * Menu:
  823. * Frames::                      Stack Frames
  824. * Backtrace::                   Backtraces
  825. * Selection::                   Selecting a Frame
  826. * Frame Info::                  Information on a Frame
  827. File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
  828. Stack Frames
  829. ============
  830.    The call stack is divided up into contiguous pieces called "stack
  831. frames", or "frames" for short; each frame is the data associated with
  832. one call to one function.  The frame contains the arguments given to
  833. the function, the function's local variables, and the address at which
  834. the function is executing.
  835.    When your program is started, the stack has only one frame, that of
  836. the function `main'.  This is called the "initial" frame or the
  837. "outermost" frame.  Each time a function is called, a new frame is
  838. made.  Each time a function returns, the frame for that function
  839. invocation is eliminated.  If a function is recursive, there can be
  840. many frames for the same function.  The frame for the function in which
  841. execution is actually occurring is called the "innermost" frame.  This
  842. is the most recently created of all the stack frames that still exist.
  843.    Inside your program, stack frames are identified by their addresses.
  844.  A stack frame consists of many bytes, each of which has its own
  845. address; each kind of computer has a convention for choosing one of
  846. those bytes whose address serves as the address of the frame.  Usually
  847. this address is kept in a register called the "frame pointer register"
  848. while execution is going on in that frame.
  849.    GDB assigns numbers to all existing stack frames, starting with zero
  850. for the innermost frame, one for the frame that called it, and so on
  851. upward.  These numbers do not really exist in your program; they are
  852. assigned by GDB to give you a way of designating stack frames in GDB
  853. commands.
  854.    Some compilers allow functions to be compiled so that they operate
  855. without stack frames.  (For example, the `gcc' option
  856. `-fomit-frame-pointer' will generate functions without a frame.) This
  857. is occasionally done with heavily used library functions to save the
  858. frame setup time.  GDB has limited facilities for dealing with these
  859. function invocations.  If the innermost function invocation has no
  860. stack frame, GDB will nevertheless regard it as though it had a
  861. separate frame, which is numbered zero as usual, allowing correct
  862. tracing of the function call chain.  However, GDB has no provision for
  863. frameless functions elsewhere in the stack.
  864. File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
  865. Backtraces
  866. ==========
  867.    A backtrace is a summary of how your program got where it is.  It
  868. shows one line per frame, for many frames, starting with the currently
  869. executing frame (frame zero), followed by its caller (frame one), and
  870. on up the stack.
  871. `backtrace'
  872.      Print a backtrace of the entire stack: one line per frame for all
  873.      frames in the stack.
  874.      You can stop the backtrace at any time by typing the system
  875.      interrupt character, normally `C-c'.
  876. `backtrace N'
  877. `bt N'
  878.      Similar, but print only the innermost N frames.
  879. `backtrace -N'
  880. `bt -N'
  881.      Similar, but print only the outermost N frames.
  882.    The names `where' and `info stack' (abbreviated `info s') are
  883. additional aliases for `backtrace'.
  884.    Each line in the backtrace shows the frame number and the function
  885. name. The program counter value is also shown--unless you use `set
  886. print address off'.  The backtrace also shows the source file name and
  887. line number, as well as the arguments to the function.  The program
  888. counter value is omitted if it is at the beginning of the code for that
  889. line number.
  890.    Here is an example of a backtrace.  It was made with the command `bt
  891. 3', so it shows the innermost three frames.
  892.      #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
  893.          at builtin.c:993
  894.      #1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
  895.      #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
  896.          at macro.c:71
  897.      (More stack frames follow...)
  898. The display for frame zero does not begin with a program counter value,
  899. indicating that your program has stopped at the beginning of the code
  900. for line `993' of `builtin.c'.
  901.