Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Convenience-Vars.html
blob8f40b72ea448c2ccc4479f315ecaa43fcae6e522
1 <html lang="en">
2 <head>
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">
8 </head>
9 <body>
10 <div class="node">
11 <p>
12 Node:<a name="Convenience%20Vars">Convenience Vars</a>,
13 Next:<a rel="next" accesskey="n" href="Registers.html#Registers">Registers</a>,
14 Previous:<a rel="previous" accesskey="p" href="Value-History.html#Value%20History">Value History</a>,
15 Up:<a rel="up" accesskey="u" href="Data.html#Data">Data</a>
16 <hr><br>
17 </div>
19 <h3 class="section">Convenience variables</h3>
21 GDB provides <dfn>convenience variables</dfn> that you can use within
22 GDB to hold on to a value and refer to it later. These variables
23 exist entirely within GDB; they are not part of your program, and
24 setting a convenience variable has no direct effect on further execution
25 of your program. That is why you can use them freely.
27 <p>Convenience variables are prefixed with <code>$</code>. Any name preceded by
28 <code>$</code> can be used for a convenience variable, unless it is one of
29 the predefined machine-specific register names (see <a href="Registers.html#Registers">Registers</a>).
30 (Value history references, in contrast, are <em>numbers</em> preceded
31 by <code>$</code>. See <a href="Value-History.html#Value%20History">Value history</a>.)
33 <p>You can save a value in a convenience variable with an assignment
34 expression, just as you would set a variable in your program.
35 For example:
37 <pre class="example"> set $foo = *object_ptr
38 </pre>
40 <p>would save in <code>$foo</code> the value contained in the object pointed to by
41 <code>object_ptr</code>.
43 <p>Using a convenience variable for the first time creates it, but its
44 value is <code>void</code> until you assign a new value. You can alter the
45 value with another assignment at any time.
47 <p>Convenience variables have no fixed types. You can assign a convenience
48 variable any type of value, including structures and arrays, even if
49 that variable already has a value of a different type. The convenience
50 variable, when used as an expression, has the type of its current value.
52 <dl>
53 <dt><code>show convenience</code>
54 <dd>Print a list of convenience variables used so far, and their values.
55 Abbreviated <code>show conv</code>.
56 </dl>
58 <p>One of the ways to use a convenience variable is as a counter to be
59 incremented or a pointer to be advanced. For example, to print
60 a field from successive elements of an array of structures:
62 <pre class="example"> set $i = 0
63 print bar[$i++]-&gt;contents
64 </pre>
66 <p>Repeat that command by typing &lt;RET&gt;.
68 <p>Some convenience variables are created automatically by GDB and given
69 values likely to be useful.
71 <dl>
72 <dt><code>$_</code>
73 <dd>The variable <code>$_</code> is automatically set by the <code>x</code> command to
74 the last address examined (see <a href="Memory.html#Memory">Examining memory</a>). Other
75 commands which provide a default address for <code>x</code> to examine also
76 set <code>$_</code> to that address; these commands include <code>info line</code>
77 and <code>info breakpoint</code>. The type of <code>$_</code> is <code>void *</code>
78 except when set by the <code>x</code> command, in which case it is a pointer
79 to the type of <code>$__</code>.
81 <br><dt><code>$__</code>
82 <dd>The variable <code>$__</code> is automatically set by the <code>x</code> command
83 to the value found in the last address examined. Its type is chosen
84 to match the format in which the data was printed.
86 <br><dt><code>$_exitcode</code>
87 <dd>The variable <code>$_exitcode</code> is automatically set to the exit code when
88 the program being debugged terminates.
89 </dl>
91 <p>On HP-UX systems, if you refer to a function or variable name that
92 begins with a dollar sign, GDB searches for a user or system
93 name first, before it searches for a convenience variable.
95 </body></html>