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

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