3 <title>Debugging with GDB
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Debugging with GDB">
6 <meta name=
"generator" content=
"makeinfo 4.3">
7 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home">
12 Node:
<a name=
"Value%20History">Value History
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Convenience-Vars.html#Convenience%20Vars">Convenience Vars
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Print-Settings.html#Print%20Settings">Print Settings
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"Data.html#Data">Data
</a>
19 <h3 class=
"section">Value history
</h3>
21 <p>Values printed by the
<code>print
</code> command are saved in the GDB
22 <dfn>value history
</dfn>. This allows you to refer to them in other expressions.
23 Values are kept until the symbol table is re-read or discarded
24 (for example with the
<code>file
</code> or
<code>symbol-file
</code> commands).
25 When the symbol table changes, the value history is discarded,
26 since the values may contain pointers back to the types defined in the
29 <p>The values printed are given
<dfn>history numbers
</dfn> by which you can
30 refer to them. These are successive integers starting with one.
31 <code>print
</code> shows you the history number assigned to a value by
32 printing
<code>$
</code><var>num
</var><code> =
</code> before the value; here
<var>num
</var> is the
35 <p>To refer to any previous value, use
<code>$
</code> followed by the value's
36 history number. The way
<code>print
</code> labels its output is designed to
37 remind you of this. Just
<code>$
</code> refers to the most recent value in
38 the history, and
<code>$$
</code> refers to the value before that.
39 <code>$$
</code><var>n
</var><code></code> refers to the
<var>n
</var>th value from the end;
<code>$$
2</code>
40 is the value just prior to
<code>$$
</code>,
<code>$$
1</code> is equivalent to
41 <code>$$
</code>, and
<code>$$
0</code> is equivalent to
<code>$
</code>.
43 <p>For example, suppose you have just printed a pointer to a structure and
44 want to see the contents of the structure. It suffices to type
46 <pre class=
"example"> p *$
49 <p>If you have a chain of structures where the component
<code>next
</code> points
50 to the next one, you can print the contents of the next one with this:
52 <pre class=
"example"> p *$.next
55 <p>You can print successive links in the chain by repeating this
56 command--which you can do by just typing
<RET
>.
58 <p>Note that the history records values, not expressions. If the value of
59 <code>x
</code> is
4 and you type these commands:
61 <pre class=
"example"> print x
65 <p>then the value recorded in the value history by the
<code>print
</code> command
66 remains
4 even though the value of
<code>x
</code> has changed.
69 <dt><code>show values
</code>
70 <dd>Print the last ten values in the value history, with their item numbers.
71 This is like
<code>p $$
9</code> repeated ten times, except that
<code>show
72 values
</code> does not change the history.
74 <br><dt><code>show values
</code><var>n
</var><code></code>
75 <dd>Print ten history values centered on history item number
<var>n
</var>.
77 <br><dt><code>show values +
</code>
78 <dd>Print ten history values just after the values last printed. If no more
79 values are available,
<code>show values +
</code> produces no display.
82 <p>Pressing
<RET
> to repeat
<code>show values
</code><var>n
</var><code></code> has exactly the
83 same effect as
<code>show values +
</code>.