home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / gdb.info-3 < prev    next >
Encoding:
GNU Info File  |  1993-05-12  |  46.3 KB  |  1,244 lines

  1. This is Info file ./gdb.info, produced by Makeinfo-1.52 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.09, April 1993, of `Debugging with GDB: the GNU
  10. Source-Level Debugger' for GDB Version 4.9.
  11.  
  12.    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993 Free Software
  13. 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 section entitled "GNU General Public License" is included
  22. exactly as in the original, and provided that the entire resulting
  23. derived work is distributed under the terms of a permission notice
  24. identical to this one.
  25.  
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31.  
  32. 
  33. File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
  34.  
  35. Selecting a frame
  36. =================
  37.  
  38.    Most commands for examining the stack and other data in your program
  39. work on whichever stack frame is selected at the moment.  Here are the
  40. commands for selecting a stack frame; all of them finish by printing a
  41. brief description of the stack frame just selected.
  42.  
  43. `frame N'
  44. `f N'
  45.      Select frame number N.  Recall that frame zero is the innermost
  46.      (currently executing) frame, frame one is the frame that called the
  47.      innermost one, and so on.  The highest-numbered frame is the one
  48.      for `main'.
  49.  
  50. `frame ADDR'
  51. `f ADDR'
  52.      Select the frame at address ADDR.  This is useful mainly if the
  53.      chaining of stack frames has been damaged by a bug, making it
  54.      impossible for GDB to assign numbers properly to all frames.  In
  55.      addition, this can be useful when your program has multiple stacks
  56.      and switches between them.
  57.  
  58.      On the SPARC architecture, `frame' needs two addresses to select
  59.      an arbitrary frame: a frame pointer and a stack pointer.
  60.  
  61. `up N'
  62.      Move N frames up the stack.  For positive numbers N, this advances
  63.      toward the outermost frame, to higher frame numbers, to frames
  64.      that have existed longer.  N defaults to one.
  65.  
  66. `down N'
  67.      Move N frames down the stack.  For positive numbers N, this
  68.      advances toward the innermost frame, to lower frame numbers, to
  69.      frames that were created more recently.  N defaults to one.  You
  70.      may abbreviate `down' as `do'.
  71.  
  72.    All of these commands end by printing two lines of output describing
  73. the frame.  The first line shows the frame number, the function name,
  74. the arguments, and the source file and line number of execution in that
  75. frame.  The second line shows the text of that source line.
  76.  
  77.    For example:
  78.      (gdb) up
  79.      #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
  80.          at env.c:10
  81.      10              read_input_file (argv[i]);
  82.  
  83.    After such a printout, the `list' command with no arguments will
  84. print ten lines centered on the point of execution in the frame.  *Note
  85. Printing source lines: List.
  86.  
  87. `up-silently N'
  88. `down-silently N'
  89.      These two commands are variants of `up' and `down', respectively;
  90.      they differ in that they do their work silently, without causing
  91.      display of the new frame.  They are intended primarily for use in
  92.      GDB command scripts, where the output might be unnecessary and
  93.      distracting.
  94.  
  95. 
  96. File: gdb.info,  Node: Frame Info,  Next: MIPS Stack,  Prev: Selection,  Up: Stack
  97.  
  98. Information about a frame
  99. =========================
  100.  
  101.    There are several other commands to print information about the
  102. selected stack frame.
  103.  
  104. `frame'
  105. `f'
  106.      When used without any argument, this command does not change which
  107.      frame is selected, but prints a brief description of the currently
  108.      selected stack frame.  It can be abbreviated `f'.  With an
  109.      argument, this command is used to select a stack frame.  *Note
  110.      Selecting a frame: Selection.
  111.  
  112. `info frame'
  113. `info f'
  114.      This command prints a verbose description of the selected stack
  115.      frame, including the address of the frame, the addresses of the
  116.      next frame down (called by this frame) and the next frame up
  117.      (caller of this frame), the language that the source code
  118.      corresponding to this frame was written in, the address of the
  119.      frame's arguments, the program counter saved in it (the address of
  120.      execution in the caller frame), and which registers were saved in
  121.      the frame.  The verbose description is useful when something has
  122.      gone wrong that has made the stack format fail to fit the usual
  123.      conventions.
  124.  
  125. `info frame ADDR'
  126. `info f ADDR'
  127.      Print a verbose description of the frame at address ADDR, without
  128.      selecting that frame.  The selected frame remains unchanged by
  129.      this command.
  130.  
  131. `info args'
  132.      Print the arguments of the selected frame, each on a separate line.
  133.  
  134. `info locals'
  135.      Print the local variables of the selected frame, each on a separate
  136.      line.  These are all variables (declared either static or
  137.      automatic) accessible at the point of execution of the selected
  138.      frame.
  139.  
  140. `info catch'
  141.      Print a list of all the exception handlers that are active in the
  142.      current stack frame at the current point of execution.  To see
  143.      other exception handlers, visit the associated frame (using the
  144.      `up', `down', or `frame' commands); then type `info catch'.  *Note
  145.      Breakpoints and exceptions: Exception Handling.
  146.  
  147. 
  148. File: gdb.info,  Node: MIPS Stack,  Prev: Frame Info,  Up: Stack
  149.  
  150. MIPS machines and the function stack
  151. ====================================
  152.  
  153.    MIPS based computers use an unusual stack frame, which sometimes
  154. requires GDB to search backward in the object code to find the
  155. beginning of a function.
  156.  
  157.    To improve response time (especially for embedded applications, where
  158. GDB may be restricted to a slow serial line for this search) you may
  159. want to limit the size of this search, using one of these commands:
  160.  
  161. `set heuristic-fence-post LIMIT'
  162.      Restrict GDBN to examining at most LIMIT bytes in its search for
  163.      the beginning of a function.  A value of `0' (the default) means
  164.      there is no limit.
  165.  
  166. `show heuristic-fence-post'
  167.      Display the current limit.
  168.  
  169. These commands are available *only* when GDB is configured for
  170. debugging programs on MIPS processors.
  171.  
  172. 
  173. File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
  174.  
  175. Examining Source Files
  176. **********************
  177.  
  178.    GDB can print parts of your program's source, since the debugging
  179. information recorded in the program tells GDB what source files were
  180. used to build it.  When your program stops, GDB spontaneously prints
  181. the line where it stopped.  Likewise, when you select a stack frame
  182. (*note Selecting a frame: Selection.), GDB prints the line where
  183. execution in that frame has stopped.  You can print other portions of
  184. source files by explicit command.
  185.  
  186.    If you use GDB through its GNU Emacs interface, you may prefer to use
  187. Emacs facilities to view source; *note Using GDB under GNU Emacs:
  188. Emacs..
  189.  
  190. * Menu:
  191.  
  192. * List::                        Printing source lines
  193.  
  194. * Search::                      Searching source files
  195.  
  196. * Source Path::                 Specifying source directories
  197. * Machine Code::                Source and machine code
  198.  
  199. 
  200. File: gdb.info,  Node: List,  Next: Search,  Up: Source
  201.  
  202. Printing source lines
  203. =====================
  204.  
  205.    To print lines from a source file, use the `list' command
  206. (abbreviated `l').  There are several ways to specify what part of the
  207. file you want to print.
  208.  
  209.    Here are the forms of the `list' command most commonly used:
  210.  
  211. `list LINENUM'
  212.      Print lines centered around line number LINENUM in the current
  213.      source file.
  214.  
  215. `list FUNCTION'
  216.      Print lines centered around the beginning of function FUNCTION.
  217.  
  218. `list'
  219.      Print more lines.  If the last lines printed were printed with a
  220.      `list' command, this prints lines following the last lines
  221.      printed; however, if the last line printed was a solitary line
  222.      printed as part of displaying a stack frame (*note Examining the
  223.      Stack: Stack.), this prints lines centered around that line.
  224.  
  225. `list -'
  226.      Print lines just before the lines last printed.
  227.  
  228.    By default, GDB prints ten source lines with any of these forms of
  229. the `list' command.  You can change this using `set listsize':
  230.  
  231. `set listsize COUNT'
  232.      Make the `list' command display COUNT source lines (unless the
  233.      `list' argument explicitly specifies some other number).
  234.  
  235. `show listsize'
  236.      Display the number of lines that `list' will currently display by
  237.      default.
  238.  
  239.    Repeating a `list' command with RET discards the argument, so it is
  240. equivalent to typing just `list'.  This is more useful than listing the
  241. same lines again.  An exception is made for an argument of `-'; that
  242. argument is preserved in repetition so that each repetition moves up in
  243. the source file.
  244.  
  245.    In general, the `list' command expects you to supply zero, one or two
  246. "linespecs".  Linespecs specify source lines; there are several ways of
  247. writing them but the effect is always to specify some source line.
  248. Here is a complete description of the possible arguments for `list':
  249.  
  250. `list LINESPEC'
  251.      Print lines centered around the line specified by LINESPEC.
  252.  
  253. `list FIRST,LAST'
  254.      Print lines from FIRST to LAST.  Both arguments are linespecs.
  255.  
  256. `list ,LAST'
  257.      Print lines ending with LAST.
  258.  
  259. `list FIRST,'
  260.      Print lines starting with FIRST.
  261.  
  262. `list +'
  263.      Print lines just after the lines last printed.
  264.  
  265. `list -'
  266.      Print lines just before the lines last printed.
  267.  
  268. `list'
  269.      As described in the preceding table.
  270.  
  271.    Here are the ways of specifying a single source line--all the kinds
  272. of linespec.
  273.  
  274. `NUMBER'
  275.      Specifies line NUMBER of the current source file.  When a `list'
  276.      command has two linespecs, this refers to the same source file as
  277.      the first linespec.
  278.  
  279. `+OFFSET'
  280.      Specifies the line OFFSET lines after the last line printed.  When
  281.      used as the second linespec in a `list' command that has two, this
  282.      specifies the line OFFSET lines down from the first linespec.
  283.  
  284. `-OFFSET'
  285.      Specifies the line OFFSET lines before the last line printed.
  286.  
  287. `FILENAME:NUMBER'
  288.      Specifies line NUMBER in the source file FILENAME.
  289.  
  290. `FUNCTION'
  291.      Specifies the line of the open-brace that begins the body of the
  292.      function FUNCTION.
  293.  
  294. `FILENAME:FUNCTION'
  295.      Specifies the line of the open-brace that begins the body of the
  296.      function FUNCTION in the file FILENAME.  You only need the file
  297.      name with a function name to avoid ambiguity when there are
  298.      identically named functions in different source files.
  299.  
  300. `*ADDRESS'
  301.      Specifies the line containing the program address ADDRESS.
  302.      ADDRESS may be any expression.
  303.  
  304. 
  305. File: gdb.info,  Node: Search,  Next: Source Path,  Prev: List,  Up: Source
  306.  
  307. Searching source files
  308. ======================
  309.  
  310.    There are two commands for searching through the current source file
  311. for a regular expression.
  312.  
  313. `forward-search REGEXP'
  314. `search REGEXP'
  315.      The command `forward-search REGEXP' checks each line, starting
  316.      with the one following the last line listed, for a match for
  317.      REGEXP.  It lists the line that is found.  You can use synonym
  318.      `search REGEXP' or abbreviate the command name as `fo'.
  319.  
  320. `reverse-search REGEXP'
  321.      The command `reverse-search REGEXP' checks each line, starting
  322.      with the one before the last line listed and going backward, for a
  323.      match for REGEXP.  It lists the line that is found.  You can
  324.      abbreviate this command as `rev'.
  325.  
  326. 
  327. File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
  328.  
  329. Specifying source directories
  330. =============================
  331.  
  332.    Executable programs sometimes do not record the directories of the
  333. source files from which they were compiled, just the names.  Even when
  334. they do, the directories could be moved between the compilation and
  335. your debugging session.  GDB has a list of directories to search for
  336. source files; this is called the "source path".  Each time GDB wants a
  337. source file, it tries all the directories in the list, in the order
  338. they are present in the list, until it finds a file with the desired
  339. name.  Note that the executable search path is *not* used for this
  340. purpose.  Neither is the current working directory, unless it happens
  341. to be in the source path.
  342.  
  343.    If GDB cannot find a source file in the source path, and the object
  344. program records a directory, GDB tries that directory too.  If the
  345. source path is empty, and there is no record of the compilation
  346. directory, GDB will, as a last resort, look in the current directory.
  347.  
  348.    Whenever you reset or rearrange the source path, GDB will clear out
  349. any information it has cached about where source files are found, where
  350. each line is in the file, etc.
  351.  
  352.    When you start GDB, its source path is empty.  To add other
  353. directories, use the `directory' command.
  354.  
  355. `directory DIRNAME ...'
  356.      Add directory DIRNAME to the front of the source path.  Several
  357.      directory names may be given to this command, separated by `:' or
  358.      whitespace.  You may specify a directory that is already in the
  359.      source path; this moves it forward, so it will be searched sooner.
  360.  
  361.      You can use the string `$cdir' to refer to the compilation
  362.      directory (if one is recorded), and `$cwd' to refer to the current
  363.      working directory.  `$cwd' is not the same as `.'--the former
  364.      tracks the current working directory as it changes during your GDB
  365.      session, while the latter is immediately expanded to the current
  366.      directory at the time you add an entry to the source path.
  367.  
  368. `directory'
  369.      Reset the source path to empty again.  This requires confirmation.
  370.  
  371. `show directories'
  372.      Print the source path: show which directories it contains.
  373.  
  374.    If your source path is cluttered with directories that are no longer
  375. of interest, GDB may sometimes cause confusion by finding the wrong
  376. versions of source.  You can correct the situation as follows:
  377.  
  378.   1. Use `directory' with no argument to reset the source path to empty.
  379.  
  380.   2. Use `directory' with suitable arguments to reinstall the
  381.      directories you want in the source path.  You can add all the
  382.      directories in one command.
  383.  
  384. 
  385. File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
  386.  
  387. Source and machine code
  388. =======================
  389.  
  390.    You can use the command `info line' to map source lines to program
  391. addresses (and vice versa), and the command `disassemble' to display a
  392. range of addresses as machine instructions.
  393.  
  394. `info line LINESPEC'
  395.      Print the starting and ending addresses of the compiled code for
  396.      source line LINESPEC.  You can specify source lines in any of the
  397.      ways understood by the `list' command (*note Printing source
  398.      lines: List.).
  399.  
  400.    For example, we can use `info line' to discover the location of the
  401. object code for the first line of function `m4_changequote':
  402.  
  403.      (gdb) info line m4_changecom
  404.      Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
  405.  
  406. We can also inquire (using `*ADDR' as the form for LINESPEC) what
  407. source line covers a particular address:
  408.      (gdb) info line *0x63ff
  409.      Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
  410.  
  411.    After `info line', the default address for the `x' command is
  412. changed to the starting address of the line, so that `x/i' is
  413. sufficient to begin examining the machine code (*note Examining memory:
  414. Memory.).  Also, this address is saved as the value of the convenience
  415. variable `$_' (*note Convenience variables: Convenience Vars.).
  416.  
  417. `disassemble'
  418.      This specialized command dumps a range of memory as machine
  419.      instructions.  The default memory range is the function
  420.      surrounding the program counter of the selected frame.  A single
  421.      argument to this command is a program counter value; the function
  422.      surrounding this value will be dumped.  Two arguments specify a
  423.      range of addresses (first inclusive, second exclusive) to dump.
  424.  
  425.    We can use `disassemble' to inspect the object code range shown in
  426. the last `info line' example (the example shows SPARC machine
  427. instructions):
  428.  
  429.      (gdb) disas 0x63e4 0x6404
  430.      Dump of assembler code from 0x63e4 to 0x6404:
  431.      0x63e4 <builtin_init+5340>:     ble 0x63f8 <builtin_init+5360>
  432.      0x63e8 <builtin_init+5344>:     sethi %hi(0x4c00), %o0
  433.      0x63ec <builtin_init+5348>:     ld [%i1+4], %o0
  434.      0x63f0 <builtin_init+5352>:     b 0x63fc <builtin_init+5364>
  435.      0x63f4 <builtin_init+5356>:     ld [%o0+4], %o0
  436.      0x63f8 <builtin_init+5360>:     or %o0, 0x1a4, %o0
  437.      0x63fc <builtin_init+5364>:     call 0x9288 <path_search>
  438.      0x6400 <builtin_init+5368>:     nop
  439.      End of assembler dump.
  440.  
  441. 
  442. File: gdb.info,  Node: Data,  Next: Languages,  Prev: Source,  Up: Top
  443.  
  444. Examining Data
  445. **************
  446.  
  447.    The usual way to examine data in your program is with the `print'
  448. command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
  449. prints the value of an expression of the language your program is
  450. written in (*note Using GDB with Different Languages: Languages.).
  451.  
  452. `print EXP'
  453. `print /F EXP'
  454.      EXP is an expression (in the source language).  By default the
  455.      value of EXP is printed in a format appropriate to its data type;
  456.      you can choose a different format by specifying `/F', where F is a
  457.      letter specifying the format; *note Output formats: Output
  458.      Formats..
  459.  
  460. `print'
  461. `print /F'
  462.      If you omit EXP, GDB displays the last value again (from the
  463.      "value history"; *note Value history: Value History.).  This
  464.      allows you to conveniently inspect the same value in an
  465.      alternative format.
  466.  
  467.    A more low-level way of examining data is with the `x' command.  It
  468. examines data in memory at a specified address and prints it in a
  469. specified format.  *Note Examining memory: Memory.
  470.  
  471.    If you are interested in information about types, or about how the
  472. fields of a struct or class are declared, use the `ptype EXP' command
  473. rather than `print'. *Note Examining the Symbol Table: Symbols.
  474.  
  475. * Menu:
  476.  
  477. * Expressions::                 Expressions
  478. * Variables::                   Program variables
  479. * Arrays::                      Artificial arrays
  480. * Output Formats::              Output formats
  481. * Memory::                      Examining memory
  482. * Auto Display::                Automatic display
  483. * Print Settings::              Print settings
  484. * Value History::               Value history
  485. * Convenience Vars::            Convenience variables
  486. * Registers::                   Registers
  487.  
  488. * Floating Point Hardware::     Floating point hardware
  489.  
  490. 
  491. File: gdb.info,  Node: Expressions,  Next: Variables,  Up: Data
  492.  
  493. Expressions
  494. ===========
  495.  
  496.    `print' and many other GDB commands accept an expression and compute
  497. its value.  Any kind of constant, variable or operator defined by the
  498. programming language you are using is valid in an expression in GDB.
  499. This includes conditional expressions, function calls, casts and string
  500. constants.  It unfortunately does not include symbols defined by
  501. preprocessor `#define' commands.
  502.  
  503.    Because C is so widespread, most of the expressions shown in
  504. examples in this manual are in C.  *Note Using GDB with Different
  505. Languages: Languages, for information on how to use expressions in other
  506. languages.
  507.  
  508.    In this section, we discuss operators that you can use in GDB
  509. expressions regardless of your programming language.
  510.  
  511.    Casts are supported in all languages, not just in C, because it is so
  512. useful to cast a number into a pointer so as to examine a structure at
  513. that address in memory.
  514.  
  515.    GDB supports these operators in addition to those of programming
  516. languages:
  517.  
  518. `@'
  519.      `@' is a binary operator for treating parts of memory as arrays.
  520.      *Note Artificial arrays: Arrays, for more information.
  521.  
  522. `::'
  523.      `::' allows you to specify a variable in terms of the file or
  524.      function where it is defined.  *Note Program variables: Variables.
  525.  
  526. `{TYPE} ADDR'
  527.      Refers to an object of type TYPE stored at address ADDR in memory.
  528.      ADDR may be any expression whose value is an integer or pointer
  529.      (but parentheses are required around binary operators, just as in
  530.      a cast).  This construct is allowed regardless of what kind of
  531.      data is normally supposed to reside at ADDR.
  532.  
  533. 
  534. File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
  535.  
  536. Program variables
  537. =================
  538.  
  539.    The most common kind of expression to use is the name of a variable
  540. in your program.
  541.  
  542.    Variables in expressions are understood in the selected stack frame
  543. (*note Selecting a frame: Selection.); they must either be global (or
  544. static) or be visible according to the scope rules of the programming
  545. language from the point of execution in that frame.  This means that in
  546. the function
  547.  
  548.      foo (a)
  549.           int a;
  550.      {
  551.        bar (a);
  552.        {
  553.          int b = test ();
  554.          bar (b);
  555.        }
  556.      }
  557.  
  558. you can examine and use the variable `a' whenever your program is
  559. executing within the function `foo', but you can only use or examine
  560. the variable `b' while your program is executing inside the block where
  561. `b' is declared.
  562.  
  563.    There is an exception: you can refer to a variable or function whose
  564. scope is a single source file even if the current execution point is not
  565. in this file.  But it is possible to have more than one such variable or
  566. function with the same name (in different source files).  If that
  567. happens, referring to that name has unpredictable effects.  If you wish,
  568. you can specify a static variable in a particular function or file,
  569. using the colon-colon notation:
  570.  
  571.      FILE::VARIABLE
  572.      FUNCTION::VARIABLE
  573.  
  574. Here FILE or FUNCTION is the name of the context for the static
  575. VARIABLE.  In the case of file names, you can use quotes to make sure
  576. GDB parses the file name as a single word--for example, to print a
  577. global value of `x' defined in `f2.c':
  578.  
  579.      (gdb) p 'f2.c'::x
  580.  
  581.    This use of `::' is very rarely in conflict with the very similar
  582. use of the same notation in C++.  GDB also supports use of the C++
  583. scope resolution operator in GDB expressions.
  584.  
  585.      *Warning:* Occasionally, a local variable may appear to have the
  586.      wrong value at certain points in a function--just after entry to a
  587.      new scope, and just before exit.
  588.    You may see this problem when you are stepping by machine
  589. instructions.  This is because on most machines, it takes more than one
  590. instruction to set up a stack frame (including local variable
  591. definitions); if you are stepping by machine instructions, variables
  592. may appear to have the wrong values until the stack frame is completely
  593. built.  On exit, it usually also takes more than one machine
  594. instruction to destroy a stack frame; after you begin stepping through
  595. that group of instructions, local variable definitions may be gone.
  596.  
  597. 
  598. File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
  599.  
  600. Artificial arrays
  601. =================
  602.  
  603.    It is often useful to print out several successive objects of the
  604. same type in memory; a section of an array, or an array of dynamically
  605. determined size for which only a pointer exists in the program.
  606.  
  607.    You can do this by referring to a contiguous span of memory as an
  608. "artificial array", using the binary operator `@'.  The left operand of
  609. `@' should be the first element of the desired array, as an individual
  610. object.  The right operand should be the desired length of the array.
  611. The result is an array value whose elements are all of the type of the
  612. left argument.  The first element is actually the left argument; the
  613. second element comes from bytes of memory immediately following those
  614. that hold the first element, and so on.  Here is an example.  If a
  615. program says
  616.  
  617.      int *array = (int *) malloc (len * sizeof (int));
  618.  
  619. you can print the contents of `array' with
  620.  
  621.      p *array@len
  622.  
  623.    The left operand of `@' must reside in memory.  Array values made
  624. with `@' in this way behave just like other arrays in terms of
  625. subscripting, and are coerced to pointers when used in expressions.
  626. Artificial arrays most often appear in expressions via the value history
  627. (*note Value history: Value History.), after printing one out.)
  628.  
  629.    Sometimes the artificial array mechanism is not quite enough; in
  630. moderately complex data structures, the elements of interest may not
  631. actually be adjacent--for example, if you are interested in the values
  632. of pointers in an array.  One useful work-around in this situation is
  633. to use a convenience variable (*note Convenience variables: Convenience
  634. Vars.) as a counter in an expression that prints the first interesting
  635. value, and then repeat that expression via RET.  For instance, suppose
  636. you have an array `dtab' of pointers to structures, and you are
  637. interested in the values of a field `fv' in each structure.  Here is an
  638. example of what you might type:
  639.  
  640.      set $i = 0
  641.      p dtab[$i++]->fv
  642.      RET
  643.      RET
  644.      ...
  645.  
  646. 
  647. File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
  648.  
  649. Output formats
  650. ==============
  651.  
  652.    By default, GDB prints a value according to its data type.  Sometimes
  653. this is not what you want.  For example, you might want to print a
  654. number in hex, or a pointer in decimal.  Or you might want to view data
  655. in memory at a certain address as a character string or as an
  656. instruction.  To do these things, specify an "output format" when you
  657. print a value.
  658.  
  659.    The simplest use of output formats is to say how to print a value
  660. already computed.  This is done by starting the arguments of the
  661. `print' command with a slash and a format letter.  The format letters
  662. supported are:
  663.  
  664. `x'
  665.      Regard the bits of the value as an integer, and print the integer
  666.      in hexadecimal.
  667.  
  668. `d'
  669.      Print as integer in signed decimal.
  670.  
  671. `u'
  672.      Print as integer in unsigned decimal.
  673.  
  674. `o'
  675.      Print as integer in octal.
  676.  
  677. `t'
  678.      Print as integer in binary.  The letter `t' stands for "two".  (1)
  679.  
  680. `a'
  681.      Print as an address, both absolute in hex and as an offset from the
  682.      nearest preceding symbol.  This format can be used to discover
  683.      where (in what function) an unknown address is located:
  684.  
  685.           (gdb) p/a 0x54320
  686.           $3 = 0x54320 <_initialize_vx+396>
  687.  
  688. `c'
  689.      Regard as an integer and print it as a character constant.
  690.  
  691. `f'
  692.      Regard the bits of the value as a floating point number and print
  693.      using typical floating point syntax.
  694.  
  695.    For example, to print the program counter in hex (*note
  696. Registers::.), type
  697.  
  698.      p/x $pc
  699.  
  700. Note that no space is required before the slash; this is because command
  701. names in GDB cannot contain a slash.
  702.  
  703.    To reprint the last value in the value history with a different
  704. format, you can use the `print' command with just a format and no
  705. expression.  For example, `p/x' reprints the last value in hex.
  706.  
  707.    ---------- Footnotes ----------
  708.  
  709.    (1)  `b' cannot be used because these format letters are also used
  710. with the `x' command, where `b' stands for "byte"; *note Examining
  711. memory: Memory..
  712.  
  713. 
  714. File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output Formats,  Up: Data
  715.  
  716. Examining memory
  717. ================
  718.  
  719.    You can use the command `x' (for "examine") to examine memory in any
  720. of several formats, independently of your program's data types.
  721.  
  722. `x/NFU ADDR'
  723. `x ADDR'
  724. `x'
  725.      Use the `x' command to examine memory.
  726.  
  727.    N, F, and U are all optional parameters that specify how much memory
  728. to display and how to format it; ADDR is an expression giving the
  729. address where you want to start displaying memory.  If you use defaults
  730. for NFU, you need not type the slash `/'.  Several commands set
  731. convenient defaults for ADDR.
  732.  
  733. N, the repeat count
  734.      The repeat count is a decimal integer; the default is 1.  It
  735.      specifies how much memory (counting by units U) to display.
  736.  
  737. F, the display format
  738.      The display format is one of the formats used by `print', or `s'
  739.      (null-terminated string) or `i' (machine instruction).  The
  740.      default is `x' (hexadecimal) initially, or the format from the
  741.      last time you used either `x' or `print'.
  742.  
  743. U, the unit size
  744.      The unit size is any of
  745.  
  746.     `b'
  747.           Bytes.
  748.  
  749.     `h'
  750.           Halfwords (two bytes).
  751.  
  752.     `w'
  753.           Words (four bytes).  This is the initial default.
  754.  
  755.     `g'
  756.           Giant words (eight bytes).
  757.  
  758.      Each time you specify a unit size with `x', that size becomes the
  759.      default unit the next time you use `x'.  (For the `s' and `i'
  760.      formats, the unit size is ignored and is normally not written.)
  761.  
  762. ADDR, starting display address
  763.      ADDR is the address where you want GDB to begin displaying memory.
  764.      The expression need not have a pointer value (though it may); it
  765.      is always interpreted as an integer address of a byte of memory.
  766.      *Note Expressions: Expressions, for more information on
  767.      expressions.  The default for ADDR is usually just after the last
  768.      address examined--but several other commands also set the default
  769.      address: `info breakpoints' (to the address of the last breakpoint
  770.      listed), `info line' (to the starting address of a line), and
  771.      `print' (if you use it to display a value from memory).
  772.  
  773.    For example, `x/3uh 0x54320' is a request to display three halfwords
  774. (`h') of memory, formatted as unsigned decimal integers (`u'), starting
  775. at address `0x54320'.  `x/4xw $sp' prints the four words (`w') of
  776. memory above the stack pointer (here, `$sp'; *note Registers::.) in
  777. hexadecimal (`x').
  778.  
  779.    Since the letters indicating unit sizes are all distinct from the
  780. letters specifying output formats, you do not have to remember whether
  781. unit size or format comes first; either order will work.  The output
  782. specifications `4xw' and `4wx' mean exactly the same thing.  (However,
  783. the count N must come first; `wx4' will not work.)
  784.  
  785.    Even though the unit size U is ignored for the formats `s' and `i',
  786. you might still want to use a count N; for example, `3i' specifies that
  787. you want to see three machine instructions, including any operands.
  788. The command `disassemble' gives an alternative way of inspecting
  789. machine instructions; *note Source and machine code: Machine Code..
  790.  
  791.    All the defaults for the arguments to `x' are designed to make it
  792. easy to continue scanning memory with minimal specifications each time
  793. you use `x'.  For example, after you have inspected three machine
  794. instructions with `x/3i ADDR', you can inspect the next seven with just
  795. `x/7'.  If you use RET to repeat the `x' command, the repeat count N is
  796. used again; the other arguments default as for successive uses of `x'.
  797.  
  798.    The addresses and contents printed by the `x' command are not saved
  799. in the value history because there is often too much of them and they
  800. would get in the way.  Instead, GDB makes these values available for
  801. subsequent use in expressions as values of the convenience variables
  802. `$_' and `$__'.  After an `x' command, the last address examined is
  803. available for use in expressions in the convenience variable `$_'.  The
  804. contents of that address, as examined, are available in the convenience
  805. variable `$__'.
  806.  
  807.    If the `x' command has a repeat count, the address and contents saved
  808. are from the last memory unit printed; this is not the same as the last
  809. address printed if several units were printed on the last line of
  810. output.
  811.  
  812. 
  813. File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
  814.  
  815. Automatic display
  816. =================
  817.  
  818.    If you find that you want to print the value of an expression
  819. frequently (to see how it changes), you might want to add it to the
  820. "automatic display list" so that GDB will print its value each time
  821. your program stops.  Each expression added to the list is given a
  822. number to identify it; to remove an expression from the list, you
  823. specify that number.  The automatic display looks like this:
  824.  
  825.      2: foo = 38
  826.      3: bar[5] = (struct hack *) 0x3804
  827.  
  828. This display shows item numbers, expressions and their current values.
  829. As with displays you request manually using `x' or `print', you can
  830. specify the output format you prefer; in fact, `display' decides
  831. whether to use `print' or `x' depending on how elaborate your format
  832. specification is--it uses `x' if you specify a unit size, or one of the
  833. two formats (`i' and `s') that are only supported by `x'; otherwise it
  834. uses `print'.
  835.  
  836. `display EXP'
  837.      Add the expression EXP to the list of expressions to display each
  838.      time your program stops.  *Note Expressions: Expressions.
  839.  
  840.      `display' will not repeat if you press RET again after using it.
  841.  
  842. `display/FMT EXP'
  843.      For FMT specifying only a display format and not a size or count,
  844.      add the expression EXP to the auto-display list but arranges to
  845.      display it each time in the specified format FMT.  *Note Output
  846.      formats: Output Formats.
  847.  
  848. `display/FMT ADDR'
  849.      For FMT `i' or `s', or including a unit-size or a number of units,
  850.      add the expression ADDR as a memory address to be examined each
  851.      time your program stops.  Examining means in effect doing `x/FMT
  852.      ADDR'.  *Note Examining memory: Memory.
  853.  
  854.    For example, `display/i $pc' can be helpful, to see the machine
  855. instruction about to be executed each time execution stops (`$pc' is a
  856. common name for the program counter; *note Registers::.).
  857.  
  858. `undisplay DNUMS...'
  859. `delete display DNUMS...'
  860.      Remove item numbers DNUMS from the list of expressions to display.
  861.  
  862.      `undisplay' will not repeat if you press RET after using it.
  863.      (Otherwise you would just get the error `No display number ...'.)
  864.  
  865. `disable display DNUMS...'
  866.      Disable the display of item numbers DNUMS.  A disabled display
  867.      item is not printed automatically, but is not forgotten.  It may be
  868.      enabled again later.
  869.  
  870. `enable display DNUMS...'
  871.      Enable display of item numbers DNUMS.  It becomes effective once
  872.      again in auto display of its expression, until you specify
  873.      otherwise.
  874.  
  875. `display'
  876.      Display the current values of the expressions on the list, just as
  877.      is done when your program stops.
  878.  
  879. `info display'
  880.      Print the list of expressions previously set up to display
  881.      automatically, each one with its item number, but without showing
  882.      the values.  This includes disabled expressions, which are marked
  883.      as such.  It also includes expressions which would not be
  884.      displayed right now because they refer to automatic variables not
  885.      currently available.
  886.  
  887.    If a display expression refers to local variables, then it does not
  888. make sense outside the lexical context for which it was set up.  Such an
  889. expression is disabled when execution enters a context where one of its
  890. variables is not defined.  For example, if you give the command
  891. `display last_char' while inside a function with an argument
  892. `last_char', then this argument will be displayed while your program
  893. continues to stop inside that function.  When it stops elsewhere--where
  894. there is no variable `last_char'--display is disabled.  The next time
  895. your program stops where `last_char' is meaningful, you can enable the
  896. display expression once again.
  897.  
  898. 
  899. File: gdb.info,  Node: Print Settings,  Next: Value History,  Prev: Auto Display,  Up: Data
  900.  
  901. Print settings
  902. ==============
  903.  
  904.    GDB provides the following ways to control how arrays, structures,
  905. and symbols are printed.
  906.  
  907. These settings are useful for debugging programs in any language:
  908.  
  909. `set print address'
  910. `set print address on'
  911.      GDB will print memory addresses showing the location of stack
  912.      traces, structure values, pointer values, breakpoints, and so
  913.      forth, even when it also displays the contents of those addresses.
  914.      The default is on.  For example, this is what a stack frame
  915.      display looks like, with `set print address on':
  916.  
  917.           (gdb) f
  918.           #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
  919.               at input.c:530
  920.           530         if (lquote != def_lquote)
  921.  
  922. `set print address off'
  923.      Do not print addresses when displaying their contents.  For
  924.      example, this is the same stack frame displayed with `set print
  925.      address off':
  926.  
  927.           (gdb) set print addr off
  928.           (gdb) f
  929.           #0  set_quotes (lq="<<", rq=">>") at input.c:530
  930.           530         if (lquote != def_lquote)
  931.  
  932.      You can use `set print address off' to eliminate all machine
  933.      dependent displays from the GDB interface.  For example, with
  934.      `print address off', you should get the same text for backtraces on
  935.      all machines--whether or not they involve pointer arguments.
  936.  
  937. `show print address'
  938.      Show whether or not addresses are to be printed.
  939.  
  940. `set print array'
  941. `set print array on'
  942.      GDB will pretty-print arrays.  This format is more convenient to
  943.      read, but uses more space.  The default is off.
  944.  
  945. `set print array off'
  946.      Return to compressed format for arrays.
  947.  
  948. `show print array'
  949.      Show whether compressed or pretty format is selected for displaying
  950.      arrays.
  951.  
  952. `set print elements NUMBER-OF-ELEMENTS'
  953.      If GDB is printing a large array, it will stop printing after it
  954.      has printed the number of elements set by the `set print elements'
  955.      command.  This limit also applies to the display of strings.
  956.  
  957. `show print elements'
  958.      Display the number of elements of a large array that GDB will print
  959.      before losing patience.
  960.  
  961. `set print pretty on'
  962.      Cause GDB to print structures in an indented format with one
  963.      member per line, like this:
  964.  
  965.           $1 = {
  966.             next = 0x0,
  967.             flags = {
  968.               sweet = 1,
  969.               sour = 1
  970.             },
  971.             meat = 0x54 "Pork"
  972.           }
  973.  
  974. `set print pretty off'
  975.      Cause GDB to print structures in a compact format, like this:
  976.  
  977.           $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
  978.           meat = 0x54 "Pork"}
  979.  
  980.      This is the default format.
  981.  
  982. `show print pretty'
  983.      Show which format GDB will use to print structures.
  984.  
  985. `set print sevenbit-strings on'
  986.      Print using only seven-bit characters; if this option is set, GDB
  987.      will display any eight-bit characters (in strings or character
  988.      values) using the notation `\'NNN.  For example, `M-a' is
  989.      displayed as `\341'.
  990.  
  991. `set print sevenbit-strings off'
  992.      Print using either seven-bit or eight-bit characters, as required.
  993.      This is the default.
  994.  
  995. `show print sevenbit-strings'
  996.      Show whether or not GDB will print only seven-bit characters.
  997.  
  998. `set print union on'
  999.      Tell GDB to print unions which are contained in structures.  This
  1000.      is the default setting.
  1001.  
  1002. `set print union off'
  1003.      Tell GDB not to print unions which are contained in structures.
  1004.  
  1005. `show print union'
  1006.      Ask GDB whether or not it will print unions which are contained in
  1007.      structures.
  1008.  
  1009.      For example, given the declarations
  1010.  
  1011.           typedef enum {Tree, Bug} Species;
  1012.           typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
  1013.           typedef enum {Caterpillar, Cocoon, Butterfly}
  1014.                         Bug_forms;
  1015.           
  1016.           struct thing {
  1017.             Species it;
  1018.             union {
  1019.               Tree_forms tree;
  1020.               Bug_forms bug;
  1021.             } form;
  1022.           };
  1023.           
  1024.           struct thing foo = {Tree, {Acorn}};
  1025.  
  1026.      with `set print union on' in effect `p foo' would print
  1027.  
  1028.           $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
  1029.  
  1030.      and with `set print union off' in effect it would print
  1031.  
  1032.           $1 = {it = Tree, form = {...}}
  1033.  
  1034. `set print max-symbolic-offset MAXOFF'
  1035.      Tell GDB to only display the symbolic form of an address if the
  1036.      offset between the closest earlier symbol and the address is less
  1037.      than MAXOFF.  The default is 0, which means to always print the
  1038.      symbolic form of an address, if any symbol precedes it.
  1039.  
  1040. `show print max-symbolic-offset'
  1041.      Ask how large the maximum offset is that GDB will print in a
  1042.      symbolic address.
  1043.  
  1044. These settings are of interest when debugging C++ programs:
  1045.  
  1046. `set print demangle'
  1047. `set print demangle on'
  1048.      Print C++ names in their source form rather than in the encoded
  1049.      ("mangled") form passed to the assembler and linker for type-safe
  1050.      linkage.  The default is `on'.
  1051.  
  1052. `show print demangle'
  1053.      Show whether C++ names will be printed in mangled or demangled
  1054.      form.
  1055.  
  1056. `set print asm-demangle'
  1057. `set print asm-demangle on'
  1058.      Print C++ names in their source form rather than their mangled
  1059.      form, even in assembler code printouts such as instruction
  1060.      disassemblies.  The default is off.
  1061.  
  1062. `show print asm-demangle'
  1063.      Show whether C++ names in assembly listings will be printed in
  1064.      mangled or demangled form.
  1065.  
  1066. `set demangle-style STYLE'
  1067.      Choose among several encoding schemes used by different compilers
  1068.      to represent C++ names.  The choices for STYLE are currently:
  1069.  
  1070.     `auto'
  1071.           Allow GDB to choose a decoding style by inspecting your
  1072.           program.
  1073.  
  1074.     `gnu'
  1075.           Decode based on the GNU C++ compiler (`g++') encoding
  1076.           algorithm.
  1077.  
  1078.     `lucid'
  1079.           Decode based on the Lucid C++ compiler (`lcc') encoding
  1080.           algorithm.
  1081.  
  1082.     `arm'
  1083.           Decode using the algorithm in the `C++ Annotated Reference
  1084.           Manual'.  *Warning:* this setting alone is not sufficient to
  1085.           allow debugging `cfront'-generated executables.  GDB would
  1086.           require further enhancement to permit that.
  1087.  
  1088. `show demangle-style'
  1089.      Display the encoding style currently in use for decoding C++
  1090.      symbols.
  1091.  
  1092. `set print object'
  1093. `set print object on'
  1094.      When displaying a pointer to an object, identify the *actual*
  1095.      (derived) type of the object rather than the *declared* type, using
  1096.      the virtual function table.
  1097.  
  1098. `set print object off'
  1099.      Display only the declared type of objects, without reference to the
  1100.      virtual function table.  This is the default setting.
  1101.  
  1102. `show print object'
  1103.      Show whether actual, or declared, object types will be displayed.
  1104.  
  1105. `set print vtbl'
  1106. `set print vtbl on'
  1107.      Pretty print C++ virtual function tables.  The default is off.
  1108.  
  1109. `set print vtbl off'
  1110.      Do not pretty print C++ virtual function tables.
  1111.  
  1112. `show print vtbl'
  1113.      Show whether C++ virtual function tables are pretty printed, or
  1114.      not.
  1115.  
  1116. 
  1117. File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Print Settings,  Up: Data
  1118.  
  1119. Value history
  1120. =============
  1121.  
  1122.    Values printed by the `print' command are saved in the GDB "value
  1123. history" so that you can refer to them in other expressions.  Values are
  1124. kept until the symbol table is re-read or discarded (for example with
  1125. the `file' or `symbol-file' commands).  When the symbol table changes,
  1126. the value history is discarded, since the values may contain pointers
  1127. back to the types defined in the symbol table.
  1128.  
  1129.    The values printed are given "history numbers" for you to refer to
  1130. them by.  These are successive integers starting with one.  `print'
  1131. shows you the history number assigned to a value by printing `$NUM = '
  1132. before the value; here NUM is the history number.
  1133.  
  1134.    To refer to any previous value, use `$' followed by the value's
  1135. history number.  The way `print' labels its output is designed to
  1136. remind you of this.  Just `$' refers to the most recent value in the
  1137. history, and `$$' refers to the value before that.  `$$N' refers to the
  1138. Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
  1139. equivalent to `$$', and `$$0' is equivalent to `$'.
  1140.  
  1141.    For example, suppose you have just printed a pointer to a structure
  1142. and want to see the contents of the structure.  It suffices to type
  1143.  
  1144.      p *$
  1145.  
  1146.    If you have a chain of structures where the component `next' points
  1147. to the next one, you can print the contents of the next one with this:
  1148.  
  1149.      p *$.next
  1150.  
  1151. You can print successive links in the chain by repeating this
  1152. command--which you can do by just typing RET.
  1153.  
  1154.    Note that the history records values, not expressions.  If the value
  1155. of `x' is 4 and you type these commands:
  1156.  
  1157.      print x
  1158.      set x=5
  1159.  
  1160. then the value recorded in the value history by the `print' command
  1161. remains 4 even though the value of `x' has changed.
  1162.  
  1163. `show values'
  1164.      Print the last ten values in the value history, with their item
  1165.      numbers.  This is like `p $$9' repeated ten times, except that
  1166.      `show values' does not change the history.
  1167.  
  1168. `show values N'
  1169.      Print ten history values centered on history item number N.
  1170.  
  1171. `show values +'
  1172.      Print ten history values just after the values last printed.  If
  1173.      no more values are available, produces no display.
  1174.  
  1175.    Pressing RET to repeat `show values N' has exactly the same effect
  1176. as `show values +'.
  1177.  
  1178. 
  1179. File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
  1180.  
  1181. Convenience variables
  1182. =====================
  1183.  
  1184.    GDB provides "convenience variables" that you can use within GDB to
  1185. hold on to a value and refer to it later.  These variables exist
  1186. entirely within GDB; they are not part of your program, and setting a
  1187. convenience variable has no direct effect on further execution of your
  1188. program.  That is why you can use them freely.
  1189.  
  1190.    Convenience variables are prefixed with `$'.  Any name preceded by
  1191. `$' can be used for a convenience variable, unless it is one of the
  1192. predefined machine-specific register names (*note Registers::.).
  1193. (Value history references, in contrast, are *numbers* preceded by `$'.
  1194. *Note Value history: Value History.)
  1195.  
  1196.    You can save a value in a convenience variable with an assignment
  1197. expression, just as you would set a variable in your program.  For
  1198. example:
  1199.  
  1200.      set $foo = *object_ptr
  1201.  
  1202. would save in `$foo' the value contained in the object pointed to by
  1203. `object_ptr'.
  1204.  
  1205.    Using a convenience variable for the first time creates it; but its
  1206. value is `void' until you assign a new value.  You can alter the value
  1207. with another assignment at any time.
  1208.  
  1209.    Convenience variables have no fixed types.  You can assign a
  1210. convenience variable any type of value, including structures and
  1211. arrays, even if that variable already has a value of a different type.
  1212. The convenience variable, when used as an expression, has the type of
  1213. its current value.
  1214.  
  1215. `show convenience'
  1216.      Print a list of convenience variables used so far, and their
  1217.      values.  Abbreviated `show con'.
  1218.  
  1219.    One of the ways to use a convenience variable is as a counter to be
  1220. incremented or a pointer to be advanced.  For example, to print a field
  1221. from successive elements of an array of structures:
  1222.  
  1223.      set $i = 0
  1224.      print bar[$i++]->contents
  1225.      ... repeat that command by typing RET.
  1226.  
  1227.    Some convenience variables are created automatically by GDB and given
  1228. values likely to be useful.
  1229.  
  1230. `$_'
  1231.      The variable `$_' is automatically set by the `x' command to the
  1232.      last address examined (*note Examining memory: Memory.).  Other
  1233.      commands which provide a default address for `x' to examine also
  1234.      set `$_' to that address; these commands include `info line' and
  1235.      `info breakpoint'.  The type of `$_' is `void *' except when set
  1236.      by the `x' command, in which case it is a pointer to the type of
  1237.      `$__'.
  1238.  
  1239. `$__'
  1240.      The variable `$__' is automatically set by the `x' command to the
  1241.      value found in the last address examined.  Its type is chosen to
  1242.      match the format in which the data was printed.
  1243.  
  1244.