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-3 < prev    next >
Encoding:
GNU Info File  |  1995-03-04  |  42.1 KB  |  1,084 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: Thread Stops,  Prev: Signals,  Up: Stopping
  30.  
  31. Stopping and starting multi-thread programs
  32. ===========================================
  33.  
  34.    When your program has multiple threads (*note Debugging programs
  35. with multiple threads: Threads.), you can choose whether to set
  36. breakpoints on all threads, or on a particular thread.
  37.  
  38. `break LINESPEC thread THREADNO'
  39. `break LINESPEC thread THREADNO if ...'
  40.      Use the qualifier `thread THREADNO' with a breakpoint command to
  41.      specify that you only want GDB to stop the program when a
  42.      particular thread reaches this breakpoint.  THREADNO is one of the
  43.      numeric thread identifiers assigned by GDB, shown in the first
  44.      column of the `info threads' display.
  45.  
  46.      If you do not specify `thread THREADNO' when you set a breakpoint,
  47.      the breakpoint applies to *all* threads of your program.
  48.  
  49.      You can use the `thread' qualifier on conditional breakpoints as
  50.      well; in this case, place `thread THREADNO' before the breakpoint
  51.      condition, like this:
  52.  
  53.           (gdb) break frik.c:13 thread 28 if bartab > lim
  54.  
  55.    Whenever your program stops under GDB for any reason, *all* threads
  56. of execution stop, not just the current thread.  This allows you to
  57. examine the overall state of the program, including switching between
  58. threads, without worrying that things may change underfoot.
  59.  
  60.    Conversely, whenever you restart the program, *all* threads start
  61. executing.  *This is true even when single-stepping* with commands like
  62. `step' or `next'.
  63.  
  64.    In particular, GDB cannot single-step all threads in lockstep.
  65. Since thread scheduling is up to your debugging target's operating
  66. system (not controlled by GDB), other threads may execute more than one
  67. statement while the current thread completes a single step.  Moreover,
  68. in general other threads stop in the middle of a statement, rather than
  69. at a clean statement boundary, when the program stops.
  70.  
  71.    You might even find your program stopped in another thread after
  72. continuing or even single-stepping.  This happens whenever some other
  73. thread runs into a breakpoint, a signal, or an exception before the
  74. first thread completes whatever you requested.
  75.  
  76. 
  77. File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
  78.  
  79. Examining the Stack
  80. *******************
  81.  
  82.    When your program has stopped, the first thing you need to know is
  83. where it stopped and how it got there.
  84.  
  85.    Each time your program performs a function call, the information
  86. about where in your program the call was made from is saved in a block
  87. of data called a "stack frame".  The frame also contains the arguments
  88. of the call and the local variables of the function that was called.
  89. All the stack frames are allocated in a region of memory called the
  90. "call stack".
  91.  
  92.    When your program stops, the GDB commands for examining the stack
  93. allow you to see all of this information.
  94.  
  95.    One of the stack frames is "selected" by GDB and many GDB commands
  96. refer implicitly to the selected frame.  In particular, whenever you
  97. ask GDB for the value of a variable in your program, the value is found
  98. in the selected frame.  There are special GDB commands to select
  99. whichever frame you are interested in.
  100.  
  101.    When your program stops, GDB automatically selects the currently
  102. executing frame and describes it briefly as the `frame' command does
  103. (*note Information about a frame: Frame Info.).
  104.  
  105. * Menu:
  106.  
  107. * Frames::                      Stack frames
  108. * Backtrace::                   Backtraces
  109. * Selection::                   Selecting a frame
  110. * Frame Info::                  Information on a frame
  111.  
  112. * MIPS Stack::                  MIPS machines and the function stack
  113.  
  114. 
  115. File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
  116.  
  117. Stack frames
  118. ============
  119.  
  120.    The call stack is divided up into contiguous pieces called "stack
  121. frames", or "frames" for short; each frame is the data associated with
  122. one call to one function.  The frame contains the arguments given to
  123. the function, the function's local variables, and the address at which
  124. the function is executing.
  125.  
  126.    When your program is started, the stack has only one frame, that of
  127. the function `main'.  This is called the "initial" frame or the
  128. "outermost" frame.  Each time a function is called, a new frame is
  129. made.  Each time a function returns, the frame for that function
  130. invocation is eliminated.  If a function is recursive, there can be
  131. many frames for the same function.  The frame for the function in which
  132. execution is actually occurring is called the "innermost" frame.  This
  133. is the most recently created of all the stack frames that still exist.
  134.  
  135.    Inside your program, stack frames are identified by their addresses.
  136. A stack frame consists of many bytes, each of which has its own
  137. address; each kind of computer has a convention for choosing one of
  138. those bytes whose address serves as the address of the frame.  Usually
  139. this address is kept in a register called the "frame pointer register"
  140. while execution is going on in that frame.
  141.  
  142.    GDB assigns numbers to all existing stack frames, starting with zero
  143. for the innermost frame, one for the frame that called it, and so on
  144. upward.  These numbers do not really exist in your program; they are
  145. assigned by GDB to give you a way of designating stack frames in GDB
  146. commands.
  147.  
  148.    Some compilers provide a way to compile functions so that they
  149. operate without stack frames.  (For example, the `gcc' option
  150. `-fomit-frame-pointer' generates functions without a frame.) This is
  151. occasionally done with heavily used library functions to save the frame
  152. setup time.  GDB has limited facilities for dealing with these function
  153. invocations.  If the innermost function invocation has no stack frame,
  154. GDB nevertheless regards it as though it had a separate frame, which is
  155. numbered zero as usual, allowing correct tracing of the function call
  156. chain.  However, GDB has no provision for frameless functions elsewhere
  157. in the stack.
  158.  
  159. 
  160. File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
  161.  
  162. Backtraces
  163. ==========
  164.  
  165.    A backtrace is a summary of how your program got where it is.  It
  166. shows one line per frame, for many frames, starting with the currently
  167. executing frame (frame zero), followed by its caller (frame one), and
  168. on up the stack.
  169.  
  170. `backtrace'
  171. `bt'
  172.      Print a backtrace of the entire stack: one line per frame for all
  173.      frames in the stack.
  174.  
  175.      You can stop the backtrace at any time by typing the system
  176.      interrupt character, normally `C-c'.
  177.  
  178. `backtrace N'
  179. `bt N'
  180.      Similar, but print only the innermost N frames.
  181.  
  182. `backtrace -N'
  183. `bt -N'
  184.      Similar, but print only the outermost N frames.
  185.  
  186.    The names `where' and `info stack' (abbreviated `info s') are
  187. additional aliases for `backtrace'.
  188.  
  189.    Each line in the backtrace shows the frame number and the function
  190. name.  The program counter value is also shown--unless you use `set
  191. print address off'.  The backtrace also shows the source file name and
  192. line number, as well as the arguments to the function.  The program
  193. counter value is omitted if it is at the beginning of the code for that
  194. line number.
  195.  
  196.    Here is an example of a backtrace.  It was made with the command `bt
  197. 3', so it shows the innermost three frames.
  198.  
  199.      #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
  200.          at builtin.c:993
  201.      #1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
  202.      #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
  203.          at macro.c:71
  204.      (More stack frames follow...)
  205.  
  206. The display for frame zero does not begin with a program counter value,
  207. indicating that your program has stopped at the beginning of the code
  208. for line `993' of `builtin.c'.
  209.  
  210. 
  211. File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
  212.  
  213. Selecting a frame
  214. =================
  215.  
  216.    Most commands for examining the stack and other data in your program
  217. work on whichever stack frame is selected at the moment.  Here are the
  218. commands for selecting a stack frame; all of them finish by printing a
  219. brief description of the stack frame just selected.
  220.  
  221. `frame N'
  222. `f N'
  223.      Select frame number N.  Recall that frame zero is the innermost
  224.      (currently executing) frame, frame one is the frame that called the
  225.      innermost one, and so on.  The highest-numbered frame is the one
  226.      for `main'.
  227.  
  228. `frame ADDR'
  229. `f ADDR'
  230.      Select the frame at address ADDR.  This is useful mainly if the
  231.      chaining of stack frames has been damaged by a bug, making it
  232.      impossible for GDB to assign numbers properly to all frames.  In
  233.      addition, this can be useful when your program has multiple stacks
  234.      and switches between them.
  235.  
  236.      On the SPARC architecture, `frame' needs two addresses to select
  237.      an arbitrary frame: a frame pointer and a stack pointer.
  238.  
  239.      On the MIPS and Alpha architecture, it needs two addresses: a stack
  240.      pointer and a program counter.
  241.  
  242.      On the 29k architecture, it needs three addresses: a register stack
  243.      pointer, a program counter, and a memory stack pointer.
  244.  
  245. `up N'
  246.      Move N frames up the stack.  For positive numbers N, this advances
  247.      toward the outermost frame, to higher frame numbers, to frames
  248.      that have existed longer.  N defaults to one.
  249.  
  250. `down N'
  251.      Move N frames down the stack.  For positive numbers N, this
  252.      advances toward the innermost frame, to lower frame numbers, to
  253.      frames that were created more recently.  N defaults to one.  You
  254.      may abbreviate `down' as `do'.
  255.  
  256.    All of these commands end by printing two lines of output describing
  257. the frame.  The first line shows the frame number, the function name,
  258. the arguments, and the source file and line number of execution in that
  259. frame.  The second line shows the text of that source line.
  260.  
  261.    For example:
  262.  
  263.      (gdb) up
  264.      #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
  265.          at env.c:10
  266.      10              read_input_file (argv[i]);
  267.  
  268.    After such a printout, the `list' command with no arguments prints
  269. ten lines centered on the point of execution in the frame.  *Note
  270. Printing source lines: List.
  271.  
  272. `up-silently N'
  273. `down-silently N'
  274.      These two commands are variants of `up' and `down', respectively;
  275.      they differ in that they do their work silently, without causing
  276.      display of the new frame.  They are intended primarily for use in
  277.      GDB command scripts, where the output might be unnecessary and
  278.      distracting.
  279.  
  280. 
  281. File: gdb.info,  Node: Frame Info,  Next: MIPS Stack,  Prev: Selection,  Up: Stack
  282.  
  283. Information about a frame
  284. =========================
  285.  
  286.    There are several other commands to print information about the
  287. selected stack frame.
  288.  
  289. `frame'
  290. `f'
  291.      When used without any argument, this command does not change which
  292.      frame is selected, but prints a brief description of the currently
  293.      selected stack frame.  It can be abbreviated `f'.  With an
  294.      argument, this command is used to select a stack frame.  *Note
  295.      Selecting a frame: Selection.
  296.  
  297. `info frame'
  298. `info f'
  299.      This command prints a verbose description of the selected stack
  300.      frame, including the address of the frame, the addresses of the
  301.      next frame down (called by this frame) and the next frame up
  302.      (caller of this frame), the language that the source code
  303.      corresponding to this frame was written in, the address of the
  304.      frame's arguments, the program counter saved in it (the address of
  305.      execution in the caller frame), and which registers were saved in
  306.      the frame.  The verbose description is useful when something has
  307.      gone wrong that has made the stack format fail to fit the usual
  308.      conventions.
  309.  
  310. `info frame ADDR'
  311. `info f ADDR'
  312.      Print a verbose description of the frame at address ADDR, without
  313.      selecting that frame.  The selected frame remains unchanged by this
  314.      command.  This requires the same kind of address (more than one
  315.      for some architectures) that you specify in the `frame' command.
  316.      *Note Selecting a frame: Selection.
  317.  
  318. `info args'
  319.      Print the arguments of the selected frame, each on a separate line.
  320.  
  321. `info locals'
  322.      Print the local variables of the selected frame, each on a separate
  323.      line.  These are all variables (declared either static or
  324.      automatic) accessible at the point of execution of the selected
  325.      frame.
  326.  
  327. `info catch'
  328.      Print a list of all the exception handlers that are active in the
  329.      current stack frame at the current point of execution.  To see
  330.      other exception handlers, visit the associated frame (using the
  331.      `up', `down', or `frame' commands); then type `info catch'.  *Note
  332.      Breakpoints and exceptions: Exception Handling.
  333.  
  334. 
  335. File: gdb.info,  Node: MIPS Stack,  Prev: Frame Info,  Up: Stack
  336.  
  337. MIPS machines and the function stack
  338. ====================================
  339.  
  340.    MIPS based computers use an unusual stack frame, which sometimes
  341. requires GDB to search backward in the object code to find the
  342. beginning of a function.
  343.  
  344.    To improve response time (especially for embedded applications, where
  345. GDB may be restricted to a slow serial line for this search) you may
  346. want to limit the size of this search, using one of these commands:
  347.  
  348. `set heuristic-fence-post LIMIT'
  349.      Restrict GDB to examining at most LIMIT bytes in its search for
  350.      the beginning of a function.  A value of `0' (the default) means
  351.      there is no limit.
  352.  
  353. `show heuristic-fence-post'
  354.      Display the current limit.
  355.  
  356. These commands are available *only* when GDB is configured for
  357. debugging programs on MIPS processors.
  358.  
  359. 
  360. File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
  361.  
  362. Examining Source Files
  363. **********************
  364.  
  365.    GDB can print parts of your program's source, since the debugging
  366. information recorded in the program tells GDB what source files were
  367. used to build it.  When your program stops, GDB spontaneously prints
  368. the line where it stopped.  Likewise, when you select a stack frame
  369. (*note Selecting a frame: Selection.), GDB prints the line where
  370. execution in that frame has stopped.  You can print other portions of
  371. source files by explicit command.
  372.  
  373.    If you use GDB through its GNU Emacs interface, you may prefer to use
  374. Emacs facilities to view source; *note Using GDB under GNU Emacs:
  375. Emacs..
  376.  
  377. * Menu:
  378.  
  379. * List::                        Printing source lines
  380.  
  381. * Search::                      Searching source files
  382.  
  383. * Source Path::                 Specifying source directories
  384. * Machine Code::                Source and machine code
  385.  
  386. 
  387. File: gdb.info,  Node: List,  Next: Search,  Up: Source
  388.  
  389. Printing source lines
  390. =====================
  391.  
  392.    To print lines from a source file, use the `list' command
  393. (abbreviated `l').  There are several ways to specify what part of the
  394. file you want to print.
  395.  
  396.    Here are the forms of the `list' command most commonly used:
  397.  
  398. `list LINENUM'
  399.      Print lines centered around line number LINENUM in the current
  400.      source file.
  401.  
  402. `list FUNCTION'
  403.      Print lines centered around the beginning of function FUNCTION.
  404.  
  405. `list'
  406.      Print more lines.  If the last lines printed were printed with a
  407.      `list' command, this prints lines following the last lines
  408.      printed; however, if the last line printed was a solitary line
  409.      printed as part of displaying a stack frame (*note Examining the
  410.      Stack: Stack.), this prints lines centered around that line.
  411.  
  412. `list -'
  413.      Print lines just before the lines last printed.
  414.  
  415.    By default, GDB prints ten source lines with any of these forms of
  416. the `list' command.  You can change this using `set listsize':
  417.  
  418. `set listsize COUNT'
  419.      Make the `list' command display COUNT source lines (unless the
  420.      `list' argument explicitly specifies some other number).
  421.  
  422. `show listsize'
  423.      Display the number of lines that `list' prints.
  424.  
  425.    Repeating a `list' command with RET discards the argument, so it is
  426. equivalent to typing just `list'.  This is more useful than listing the
  427. same lines again.  An exception is made for an argument of `-'; that
  428. argument is preserved in repetition so that each repetition moves up in
  429. the source file.
  430.  
  431.    In general, the `list' command expects you to supply zero, one or two
  432. "linespecs".  Linespecs specify source lines; there are several ways of
  433. writing them but the effect is always to specify some source line.
  434. Here is a complete description of the possible arguments for `list':
  435.  
  436. `list LINESPEC'
  437.      Print lines centered around the line specified by LINESPEC.
  438.  
  439. `list FIRST,LAST'
  440.      Print lines from FIRST to LAST.  Both arguments are linespecs.
  441.  
  442. `list ,LAST'
  443.      Print lines ending with LAST.
  444.  
  445. `list FIRST,'
  446.      Print lines starting with FIRST.
  447.  
  448. `list +'
  449.      Print lines just after the lines last printed.
  450.  
  451. `list -'
  452.      Print lines just before the lines last printed.
  453.  
  454. `list'
  455.      As described in the preceding table.
  456.  
  457.    Here are the ways of specifying a single source line--all the kinds
  458. of linespec.
  459.  
  460. `NUMBER'
  461.      Specifies line NUMBER of the current source file.  When a `list'
  462.      command has two linespecs, this refers to the same source file as
  463.      the first linespec.
  464.  
  465. `+OFFSET'
  466.      Specifies the line OFFSET lines after the last line printed.  When
  467.      used as the second linespec in a `list' command that has two, this
  468.      specifies the line OFFSET lines down from the first linespec.
  469.  
  470. `-OFFSET'
  471.      Specifies the line OFFSET lines before the last line printed.
  472.  
  473. `FILENAME:NUMBER'
  474.      Specifies line NUMBER in the source file FILENAME.
  475.  
  476. `FUNCTION'
  477.      Specifies the line of the open-brace that begins the body of the
  478.      function FUNCTION.
  479.  
  480. `FILENAME:FUNCTION'
  481.      Specifies the line of the open-brace that begins the body of the
  482.      function FUNCTION in the file FILENAME.  You only need the file
  483.      name with a function name to avoid ambiguity when there are
  484.      identically named functions in different source files.
  485.  
  486. `*ADDRESS'
  487.      Specifies the line containing the program address ADDRESS.
  488.      ADDRESS may be any expression.
  489.  
  490. 
  491. File: gdb.info,  Node: Search,  Next: Source Path,  Prev: List,  Up: Source
  492.  
  493. Searching source files
  494. ======================
  495.  
  496.    There are two commands for searching through the current source file
  497. for a regular expression.
  498.  
  499. `forward-search REGEXP'
  500. `search REGEXP'
  501.      The command `forward-search REGEXP' checks each line, starting
  502.      with the one following the last line listed, for a match for
  503.      REGEXP.  It lists the line that is found.  You can use synonym
  504.      `search REGEXP' or abbreviate the command name as `fo'.
  505.  
  506. `reverse-search REGEXP'
  507.      The command `reverse-search REGEXP' checks each line, starting
  508.      with the one before the last line listed and going backward, for a
  509.      match for REGEXP.  It lists the line that is found.  You can
  510.      abbreviate this command as `rev'.
  511.  
  512. 
  513. File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
  514.  
  515. Specifying source directories
  516. =============================
  517.  
  518.    Executable programs sometimes do not record the directories of the
  519. source files from which they were compiled, just the names.  Even when
  520. they do, the directories could be moved between the compilation and
  521. your debugging session.  GDB has a list of directories to search for
  522. source files; this is called the "source path".  Each time GDB wants a
  523. source file, it tries all the directories in the list, in the order
  524. they are present in the list, until it finds a file with the desired
  525. name.  Note that the executable search path is *not* used for this
  526. purpose.  Neither is the current working directory, unless it happens
  527. to be in the source path.
  528.  
  529.    If GDB cannot find a source file in the source path, and the object
  530. program records a directory, GDB tries that directory too.  If the
  531. source path is empty, and there is no record of the compilation
  532. directory, GDB looks in the current directory as a last resort.
  533.  
  534.    Whenever you reset or rearrange the source path, GDB clears out any
  535. information it has cached about where source files are found and where
  536. each line is in the file.
  537.  
  538.    When you start GDB, its source path is empty.  To add other
  539. directories, use the `directory' command.
  540.  
  541. `directory DIRNAME ...'
  542.      Add directory DIRNAME to the front of the source path.  Several
  543.      directory names may be given to this command, separated by `:' or
  544.      whitespace.  You may specify a directory that is already in the
  545.      source path; this moves it forward, so GDB searches it sooner.
  546.  
  547.      You can use the string `$cdir' to refer to the compilation
  548.      directory (if one is recorded), and `$cwd' to refer to the current
  549.      working directory.  `$cwd' is not the same as `.'--the former
  550.      tracks the current working directory as it changes during your GDB
  551.      session, while the latter is immediately expanded to the current
  552.      directory at the time you add an entry to the source path.
  553.  
  554. `directory'
  555.      Reset the source path to empty again.  This requires confirmation.
  556.  
  557. `show directories'
  558.      Print the source path: show which directories it contains.
  559.  
  560.    If your source path is cluttered with directories that are no longer
  561. of interest, GDB may sometimes cause confusion by finding the wrong
  562. versions of source.  You can correct the situation as follows:
  563.  
  564.   1. Use `directory' with no argument to reset the source path to empty.
  565.  
  566.   2. Use `directory' with suitable arguments to reinstall the
  567.      directories you want in the source path.  You can add all the
  568.      directories in one command.
  569.  
  570. 
  571. File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
  572.  
  573. Source and machine code
  574. =======================
  575.  
  576.    You can use the command `info line' to map source lines to program
  577. addresses (and vice versa), and the command `disassemble' to display a
  578. range of addresses as machine instructions.
  579.  
  580. `info line LINESPEC'
  581.      Print the starting and ending addresses of the compiled code for
  582.      source line LINESPEC.  You can specify source lines in any of the
  583.      ways understood by the `list' command (*note Printing source
  584.      lines: List.).
  585.  
  586.    For example, we can use `info line' to discover the location of the
  587. object code for the first line of function `m4_changequote':
  588.  
  589.      (gdb) info line m4_changecom
  590.      Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
  591.  
  592. We can also inquire (using `*ADDR' as the form for LINESPEC) what
  593. source line covers a particular address:
  594.      (gdb) info line *0x63ff
  595.      Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
  596.  
  597.    After `info line', the default address for the `x' command is
  598. changed to the starting address of the line, so that `x/i' is
  599. sufficient to begin examining the machine code (*note Examining memory:
  600. Memory.).  Also, this address is saved as the value of the convenience
  601. variable `$_' (*note Convenience variables: Convenience Vars.).
  602.  
  603. `disassemble'
  604.      This specialized command dumps a range of memory as machine
  605.      instructions.  The default memory range is the function
  606.      surrounding the program counter of the selected frame.  A single
  607.      argument to this command is a program counter value; GDB dumps the
  608.      function surrounding this value.  Two arguments specify a range of
  609.      addresses (first inclusive, second exclusive) to dump.
  610.  
  611.    We can use `disassemble' to inspect the object code range shown in
  612. the last `info line' example (the example shows SPARC machine
  613. instructions):
  614.  
  615.      (gdb) disas 0x63e4 0x6404
  616.      Dump of assembler code from 0x63e4 to 0x6404:
  617.      0x63e4 <builtin_init+5340>:     ble 0x63f8 <builtin_init+5360>
  618.      0x63e8 <builtin_init+5344>:     sethi %hi(0x4c00), %o0
  619.      0x63ec <builtin_init+5348>:     ld [%i1+4], %o0
  620.      0x63f0 <builtin_init+5352>:     b 0x63fc <builtin_init+5364>
  621.      0x63f4 <builtin_init+5356>:     ld [%o0+4], %o0
  622.      0x63f8 <builtin_init+5360>:     or %o0, 0x1a4, %o0
  623.      0x63fc <builtin_init+5364>:     call 0x9288 <path_search>
  624.      0x6400 <builtin_init+5368>:     nop
  625.      End of assembler dump.
  626.  
  627. 
  628. File: gdb.info,  Node: Data,  Next: Languages,  Prev: Source,  Up: Top
  629.  
  630. Examining Data
  631. **************
  632.  
  633.    The usual way to examine data in your program is with the `print'
  634. command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
  635. prints the value of an expression of the language your program is
  636. written in (*note Using GDB with Different Languages: Languages.).
  637.  
  638. `print EXP'
  639. `print /F EXP'
  640.      EXP is an expression (in the source language).  By default the
  641.      value of EXP is printed in a format appropriate to its data type;
  642.      you can choose a different format by specifying `/F', where F is a
  643.      letter specifying the format; *note Output formats: Output
  644.      Formats..
  645.  
  646. `print'
  647. `print /F'
  648.      If you omit EXP, GDB displays the last value again (from the
  649.      "value history"; *note Value history: Value History.).  This
  650.      allows you to conveniently inspect the same value in an
  651.      alternative format.
  652.  
  653.    A more low-level way of examining data is with the `x' command.  It
  654. examines data in memory at a specified address and prints it in a
  655. specified format.  *Note Examining memory: Memory.
  656.  
  657.    If you are interested in information about types, or about how the
  658. fields of a struct or class are declared, use the `ptype EXP' command
  659. rather than `print'. *Note Examining the Symbol Table: Symbols.
  660.  
  661. * Menu:
  662.  
  663. * Expressions::                 Expressions
  664. * Variables::                   Program variables
  665. * Arrays::                      Artificial arrays
  666. * Output Formats::              Output formats
  667. * Memory::                      Examining memory
  668. * Auto Display::                Automatic display
  669. * Print Settings::              Print settings
  670. * Value History::               Value history
  671. * Convenience Vars::            Convenience variables
  672. * Registers::                   Registers
  673.  
  674. * Floating Point Hardware::     Floating point hardware
  675.  
  676. 
  677. File: gdb.info,  Node: Expressions,  Next: Variables,  Up: Data
  678.  
  679. Expressions
  680. ===========
  681.  
  682.    `print' and many other GDB commands accept an expression and compute
  683. its value.  Any kind of constant, variable or operator defined by the
  684. programming language you are using is valid in an expression in GDB.
  685. This includes conditional expressions, function calls, casts and string
  686. constants.  It unfortunately does not include symbols defined by
  687. preprocessor `#define' commands.
  688.  
  689.    Because C is so widespread, most of the expressions shown in
  690. examples in this manual are in C.  *Note Using GDB with Different
  691. Languages: Languages, for information on how to use expressions in other
  692. languages.
  693.  
  694.    In this section, we discuss operators that you can use in GDB
  695. expressions regardless of your programming language.
  696.  
  697.    Casts are supported in all languages, not just in C, because it is so
  698. useful to cast a number into a pointer so as to examine a structure at
  699. that address in memory.
  700.  
  701.    GDB supports these operators in addition to those of programming
  702. languages:
  703.  
  704. `@'
  705.      `@' is a binary operator for treating parts of memory as arrays.
  706.      *Note Artificial arrays: Arrays, for more information.
  707.  
  708. `::'
  709.      `::' allows you to specify a variable in terms of the file or
  710.      function where it is defined.  *Note Program variables: Variables.
  711.  
  712. `{TYPE} ADDR'
  713.      Refers to an object of type TYPE stored at address ADDR in memory.
  714.      ADDR may be any expression whose value is an integer or pointer
  715.      (but parentheses are required around binary operators, just as in
  716.      a cast).  This construct is allowed regardless of what kind of
  717.      data is normally supposed to reside at ADDR.
  718.  
  719. 
  720. File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
  721.  
  722. Program variables
  723. =================
  724.  
  725.    The most common kind of expression to use is the name of a variable
  726. in your program.
  727.  
  728.    Variables in expressions are understood in the selected stack frame
  729. (*note Selecting a frame: Selection.); they must either be global (or
  730. static) or be visible according to the scope rules of the programming
  731. language from the point of execution in that frame.  This means that in
  732. the function
  733.  
  734.      foo (a)
  735.           int a;
  736.      {
  737.        bar (a);
  738.        {
  739.          int b = test ();
  740.          bar (b);
  741.        }
  742.      }
  743.  
  744. you can examine and use the variable `a' whenever your program is
  745. executing within the function `foo', but you can only use or examine
  746. the variable `b' while your program is executing inside the block where
  747. `b' is declared.
  748.  
  749.    There is an exception: you can refer to a variable or function whose
  750. scope is a single source file even if the current execution point is not
  751. in this file.  But it is possible to have more than one such variable or
  752. function with the same name (in different source files).  If that
  753. happens, referring to that name has unpredictable effects.  If you wish,
  754. you can specify a static variable in a particular function or file,
  755. using the colon-colon notation:
  756.  
  757.      FILE::VARIABLE
  758.      FUNCTION::VARIABLE
  759.  
  760. Here FILE or FUNCTION is the name of the context for the static
  761. VARIABLE.  In the case of file names, you can use quotes to make sure
  762. GDB parses the file name as a single word--for example, to print a
  763. global value of `x' defined in `f2.c':
  764.  
  765.      (gdb) p 'f2.c'::x
  766.  
  767.    This use of `::' is very rarely in conflict with the very similar
  768. use of the same notation in C++.  GDB also supports use of the C++
  769. scope resolution operator in GDB expressions.
  770.  
  771.      *Warning:* Occasionally, a local variable may appear to have the
  772.      wrong value at certain points in a function--just after entry to a
  773.      new scope, and just before exit.
  774.    You may see this problem when you are stepping by machine
  775. instructions.  This is because on most machines, it takes more than one
  776. instruction to set up a stack frame (including local variable
  777. definitions); if you are stepping by machine instructions, variables
  778. may appear to have the wrong values until the stack frame is completely
  779. built.  On exit, it usually also takes more than one machine
  780. instruction to destroy a stack frame; after you begin stepping through
  781. that group of instructions, local variable definitions may be gone.
  782.  
  783. 
  784. File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
  785.  
  786. Artificial arrays
  787. =================
  788.  
  789.    It is often useful to print out several successive objects of the
  790. same type in memory; a section of an array, or an array of dynamically
  791. determined size for which only a pointer exists in the program.
  792.  
  793.    You can do this by referring to a contiguous span of memory as an
  794. "artificial array", using the binary operator `@'.  The left operand of
  795. `@' should be the first element of the desired array, as an individual
  796. object.  The right operand should be the desired length of the array.
  797. The result is an array value whose elements are all of the type of the
  798. left argument.  The first element is actually the left argument; the
  799. second element comes from bytes of memory immediately following those
  800. that hold the first element, and so on.  Here is an example.  If a
  801. program says
  802.  
  803.      int *array = (int *) malloc (len * sizeof (int));
  804.  
  805. you can print the contents of `array' with
  806.  
  807.      p *array@len
  808.  
  809.    The left operand of `@' must reside in memory.  Array values made
  810. with `@' in this way behave just like other arrays in terms of
  811. subscripting, and are coerced to pointers when used in expressions.
  812. Artificial arrays most often appear in expressions via the value history
  813. (*note Value history: Value History.), after printing one out.
  814.  
  815.    Sometimes the artificial array mechanism is not quite enough; in
  816. moderately complex data structures, the elements of interest may not
  817. actually be adjacent--for example, if you are interested in the values
  818. of pointers in an array.  One useful work-around in this situation is
  819. to use a convenience variable (*note Convenience variables: Convenience
  820. Vars.) as a counter in an expression that prints the first interesting
  821. value, and then repeat that expression via RET.  For instance, suppose
  822. you have an array `dtab' of pointers to structures, and you are
  823. interested in the values of a field `fv' in each structure.  Here is an
  824. example of what you might type:
  825.  
  826.      set $i = 0
  827.      p dtab[$i++]->fv
  828.      RET
  829.      RET
  830.      ...
  831.  
  832. 
  833. File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
  834.  
  835. Output formats
  836. ==============
  837.  
  838.    By default, GDB prints a value according to its data type.  Sometimes
  839. this is not what you want.  For example, you might want to print a
  840. number in hex, or a pointer in decimal.  Or you might want to view data
  841. in memory at a certain address as a character string or as an
  842. instruction.  To do these things, specify an "output format" when you
  843. print a value.
  844.  
  845.    The simplest use of output formats is to say how to print a value
  846. already computed.  This is done by starting the arguments of the
  847. `print' command with a slash and a format letter.  The format letters
  848. supported are:
  849.  
  850. `x'
  851.      Regard the bits of the value as an integer, and print the integer
  852.      in hexadecimal.
  853.  
  854. `d'
  855.      Print as integer in signed decimal.
  856.  
  857. `u'
  858.      Print as integer in unsigned decimal.
  859.  
  860. `o'
  861.      Print as integer in octal.
  862.  
  863. `t'
  864.      Print as integer in binary.  The letter `t' stands for "two".  (1)
  865.  
  866. `a'
  867.      Print as an address, both absolute in hexadecimal and as an offset
  868.      from the nearest preceding symbol.  You can use this format used
  869.      to discover where (in what function) an unknown address is located:
  870.  
  871.           (gdb) p/a 0x54320
  872.           $3 = 0x54320 <_initialize_vx+396>
  873.  
  874. `c'
  875.      Regard as an integer and print it as a character constant.
  876.  
  877. `f'
  878.      Regard the bits of the value as a floating point number and print
  879.      using typical floating point syntax.
  880.  
  881.    For example, to print the program counter in hex (*note
  882. Registers::.), type
  883.  
  884.      p/x $pc
  885.  
  886. Note that no space is required before the slash; this is because command
  887. names in GDB cannot contain a slash.
  888.  
  889.    To reprint the last value in the value history with a different
  890. format, you can use the `print' command with just a format and no
  891. expression.  For example, `p/x' reprints the last value in hex.
  892.  
  893.    ---------- Footnotes ----------
  894.  
  895.    (1)  `b' cannot be used because these format letters are also used
  896. with the `x' command, where `b' stands for "byte"; *note Examining
  897. memory: Memory..
  898.  
  899. 
  900. File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output Formats,  Up: Data
  901.  
  902. Examining memory
  903. ================
  904.  
  905.    You can use the command `x' (for "examine") to examine memory in any
  906. of several formats, independently of your program's data types.
  907.  
  908. `x/NFU ADDR'
  909. `x ADDR'
  910. `x'
  911.      Use the `x' command to examine memory.
  912.  
  913.    N, F, and U are all optional parameters that specify how much memory
  914. to display and how to format it; ADDR is an expression giving the
  915. address where you want to start displaying memory.  If you use defaults
  916. for NFU, you need not type the slash `/'.  Several commands set
  917. convenient defaults for ADDR.
  918.  
  919. N, the repeat count
  920.      The repeat count is a decimal integer; the default is 1.  It
  921.      specifies how much memory (counting by units U) to display.
  922.  
  923. F, the display format
  924.      The display format is one of the formats used by `print', or `s'
  925.      (null-terminated string) or `i' (machine instruction).  The
  926.      default is `x' (hexadecimal) initially, or the format from the
  927.      last time you used either `x' or `print'.
  928.  
  929. U, the unit size
  930.      The unit size is any of
  931.  
  932.     `b'
  933.           Bytes.
  934.  
  935.     `h'
  936.           Halfwords (two bytes).
  937.  
  938.     `w'
  939.           Words (four bytes).  This is the initial default.
  940.  
  941.     `g'
  942.           Giant words (eight bytes).
  943.  
  944.      Each time you specify a unit size with `x', that size becomes the
  945.      default unit the next time you use `x'.  (For the `s' and `i'
  946.      formats, the unit size is ignored and is normally not written.)
  947.  
  948. ADDR, starting display address
  949.      ADDR is the address where you want GDB to begin displaying memory.
  950.      The expression need not have a pointer value (though it may); it
  951.      is always interpreted as an integer address of a byte of memory.
  952.      *Note Expressions: Expressions, for more information on
  953.      expressions.  The default for ADDR is usually just after the last
  954.      address examined--but several other commands also set the default
  955.      address: `info breakpoints' (to the address of the last breakpoint
  956.      listed), `info line' (to the starting address of a line), and
  957.      `print' (if you use it to display a value from memory).
  958.  
  959.    For example, `x/3uh 0x54320' is a request to display three halfwords
  960. (`h') of memory, formatted as unsigned decimal integers (`u'), starting
  961. at address `0x54320'.  `x/4xw $sp' prints the four words (`w') of
  962. memory above the stack pointer (here, `$sp'; *note Registers::.) in
  963. hexadecimal (`x').
  964.  
  965.    Since the letters indicating unit sizes are all distinct from the
  966. letters specifying output formats, you do not have to remember whether
  967. unit size or format comes first; either order works.  The output
  968. specifications `4xw' and `4wx' mean exactly the same thing.  (However,
  969. the count N must come first; `wx4' does not work.)
  970.  
  971.    Even though the unit size U is ignored for the formats `s' and `i',
  972. you might still want to use a count N; for example, `3i' specifies that
  973. you want to see three machine instructions, including any operands.
  974. The command `disassemble' gives an alternative way of inspecting
  975. machine instructions; *note Source and machine code: Machine Code..
  976.  
  977.    All the defaults for the arguments to `x' are designed to make it
  978. easy to continue scanning memory with minimal specifications each time
  979. you use `x'.  For example, after you have inspected three machine
  980. instructions with `x/3i ADDR', you can inspect the next seven with just
  981. `x/7'.  If you use RET to repeat the `x' command, the repeat count N is
  982. used again; the other arguments default as for successive uses of `x'.
  983.  
  984.    The addresses and contents printed by the `x' command are not saved
  985. in the value history because there is often too much of them and they
  986. would get in the way.  Instead, GDB makes these values available for
  987. subsequent use in expressions as values of the convenience variables
  988. `$_' and `$__'.  After an `x' command, the last address examined is
  989. available for use in expressions in the convenience variable `$_'.  The
  990. contents of that address, as examined, are available in the convenience
  991. variable `$__'.
  992.  
  993.    If the `x' command has a repeat count, the address and contents saved
  994. are from the last memory unit printed; this is not the same as the last
  995. address printed if several units were printed on the last line of
  996. output.
  997.  
  998. 
  999. File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
  1000.  
  1001. Automatic display
  1002. =================
  1003.  
  1004.    If you find that you want to print the value of an expression
  1005. frequently (to see how it changes), you might want to add it to the
  1006. "automatic display list" so that GDB prints its value each time your
  1007. program stops.  Each expression added to the list is given a number to
  1008. identify it; to remove an expression from the list, you specify that
  1009. number.  The automatic display looks like this:
  1010.  
  1011.      2: foo = 38
  1012.      3: bar[5] = (struct hack *) 0x3804
  1013.  
  1014. This display shows item numbers, expressions and their current values.
  1015. As with displays you request manually using `x' or `print', you can
  1016. specify the output format you prefer; in fact, `display' decides
  1017. whether to use `print' or `x' depending on how elaborate your format
  1018. specification is--it uses `x' if you specify a unit size, or one of the
  1019. two formats (`i' and `s') that are only supported by `x'; otherwise it
  1020. uses `print'.
  1021.  
  1022. `display EXP'
  1023.      Add the expression EXP to the list of expressions to display each
  1024.      time your program stops.  *Note Expressions: Expressions.
  1025.  
  1026.      `display' does not repeat if you press RET again after using it.
  1027.  
  1028. `display/FMT EXP'
  1029.      For FMT specifying only a display format and not a size or count,
  1030.      add the expression EXP to the auto-display list but arrange to
  1031.      display it each time in the specified format FMT.  *Note Output
  1032.      formats: Output Formats.
  1033.  
  1034. `display/FMT ADDR'
  1035.      For FMT `i' or `s', or including a unit-size or a number of units,
  1036.      add the expression ADDR as a memory address to be examined each
  1037.      time your program stops.  Examining means in effect doing `x/FMT
  1038.      ADDR'.  *Note Examining memory: Memory.
  1039.  
  1040.    For example, `display/i $pc' can be helpful, to see the machine
  1041. instruction about to be executed each time execution stops (`$pc' is a
  1042. common name for the program counter; *note Registers::.).
  1043.  
  1044. `undisplay DNUMS...'
  1045. `delete display DNUMS...'
  1046.      Remove item numbers DNUMS from the list of expressions to display.
  1047.  
  1048.      `undisplay' does not repeat if you press RET after using it.
  1049.      (Otherwise you would just get the error `No display number ...'.)
  1050.  
  1051. `disable display DNUMS...'
  1052.      Disable the display of item numbers DNUMS.  A disabled display
  1053.      item is not printed automatically, but is not forgotten.  It may be
  1054.      enabled again later.
  1055.  
  1056. `enable display DNUMS...'
  1057.      Enable display of item numbers DNUMS.  It becomes effective once
  1058.      again in auto display of its expression, until you specify
  1059.      otherwise.
  1060.  
  1061. `display'
  1062.      Display the current values of the expressions on the list, just as
  1063.      is done when your program stops.
  1064.  
  1065. `info display'
  1066.      Print the list of expressions previously set up to display
  1067.      automatically, each one with its item number, but without showing
  1068.      the values.  This includes disabled expressions, which are marked
  1069.      as such.  It also includes expressions which would not be
  1070.      displayed right now because they refer to automatic variables not
  1071.      currently available.
  1072.  
  1073.    If a display expression refers to local variables, then it does not
  1074. make sense outside the lexical context for which it was set up.  Such an
  1075. expression is disabled when execution enters a context where one of its
  1076. variables is not defined.  For example, if you give the command
  1077. `display last_char' while inside a function with an argument
  1078. `last_char', GDB displays this argument while your program continues to
  1079. stop inside that function.  When it stops elsewhere--where there is no
  1080. variable `last_char'--the display is disabled automatically.  The next
  1081. time your program stops where `last_char' is meaningful, you can enable
  1082. the display expression once again.
  1083.  
  1084.