• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2013.11/share/doc/arm-arm-none-eabi/html/gdb/
1<html lang="en">
2<head>
3<title>Convenience Vars - 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.13">
7<link title="Top" rel="start" href="index.html#Top">
8<link rel="up" href="Data.html#Data" title="Data">
9<link rel="prev" href="Value-History.html#Value-History" title="Value History">
10<link rel="next" href="Convenience-Funs.html#Convenience-Funs" title="Convenience Funs">
11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12<!--
13Copyright (C) 1988-2013 Free Software Foundation, Inc.
14
15Permission is granted to copy, distribute and/or modify this document
16under the terms of the GNU Free Documentation License, Version 1.3 or
17any later version published by the Free Software Foundation; with the
18Invariant Sections being ``Free Software'' and ``Free Software Needs
19Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
20and with the Back-Cover Texts as in (a) below.
21
22(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
23this GNU Manual.  Buying copies from GNU Press supports the FSF in
24developing GNU and promoting software freedom.''
25-->
26<meta http-equiv="Content-Style-Type" content="text/css">
27<style type="text/css"><!--
28  pre.display { font-family:inherit }
29  pre.format  { font-family:inherit }
30  pre.smalldisplay { font-family:inherit; font-size:smaller }
31  pre.smallformat  { font-family:inherit; font-size:smaller }
32  pre.smallexample { font-size:smaller }
33  pre.smalllisp    { font-size:smaller }
34  span.sc    { font-variant:small-caps }
35  span.roman { font-family:serif; font-weight:normal; } 
36  span.sansserif { font-family:sans-serif; font-weight:normal; } 
37--></style>
38<link rel="stylesheet" type="text/css" href="../cs.css">
39</head>
40<body>
41<div class="node">
42<a name="Convenience-Vars"></a>
43<p>
44Next:&nbsp;<a rel="next" accesskey="n" href="Convenience-Funs.html#Convenience-Funs">Convenience Funs</a>,
45Previous:&nbsp;<a rel="previous" accesskey="p" href="Value-History.html#Value-History">Value History</a>,
46Up:&nbsp;<a rel="up" accesskey="u" href="Data.html#Data">Data</a>
47<hr>
48</div>
49
50<h3 class="section">10.11 Convenience Variables</h3>
51
52<p><a name="index-convenience-variables-640"></a><a name="index-user_002ddefined-variables-641"></a><span class="sc">gdb</span> provides <dfn>convenience variables</dfn> that you can use within
53<span class="sc">gdb</span> to hold on to a value and refer to it later.  These variables
54exist entirely within <span class="sc">gdb</span>; they are not part of your program, and
55setting a convenience variable has no direct effect on further execution
56of your program.  That is why you can use them freely.
57
58   <p>Convenience variables are prefixed with &lsquo;<samp><span class="samp">$</span></samp>&rsquo;.  Any name preceded by
59&lsquo;<samp><span class="samp">$</span></samp>&rsquo; can be used for a convenience variable, unless it is one of
60the predefined machine-specific register names (see <a href="Registers.html#Registers">Registers</a>). 
61(Value history references, in contrast, are <em>numbers</em> preceded
62by &lsquo;<samp><span class="samp">$</span></samp>&rsquo;.  See <a href="Value-History.html#Value-History">Value History</a>.)
63
64   <p>You can save a value in a convenience variable with an assignment
65expression, just as you would set a variable in your program. 
66For example:
67
68<pre class="smallexample">     set $foo = *object_ptr
69</pre>
70   <p class="noindent">would save in <code>$foo</code> the value contained in the object pointed to by
71<code>object_ptr</code>.
72
73   <p>Using a convenience variable for the first time creates it, but its
74value is <code>void</code> until you assign a new value.  You can alter the
75value with another assignment at any time.
76
77   <p>Convenience variables have no fixed types.  You can assign a convenience
78variable any type of value, including structures and arrays, even if
79that variable already has a value of a different type.  The convenience
80variable, when used as an expression, has the type of its current value.
81
82     
83<a name="index-show-convenience-642"></a>
84<a name="index-show-all-user-variables-and-functions-643"></a>
85<dl><dt><code>show convenience</code><dd>Print a list of convenience variables used so far, and their values,
86as well as a list of the convenience functions. 
87Abbreviated <code>show conv</code>.
88
89     <p><a name="index-init_002dif_002dundefined-644"></a><a name="index-convenience-variables_002c-initializing-645"></a><br><dt><code>init-if-undefined $</code><var>variable</var><code> = </code><var>expression</var><dd>Set a convenience variable if it has not already been set.  This is useful
90for user-defined commands that keep some state.  It is similar, in concept,
91to using local static variables with initializers in C (except that
92convenience variables are global).  It can also be used to allow users to
93override default values used in a command script.
94
95     <p>If the variable is already defined then the expression is not evaluated so
96any side-effects do not occur. 
97</dl>
98
99   <p>One of the ways to use a convenience variable is as a counter to be
100incremented or a pointer to be advanced.  For example, to print
101a field from successive elements of an array of structures:
102
103<pre class="smallexample">     set $i = 0
104     print bar[$i++]-&gt;contents
105</pre>
106   <p class="noindent">Repeat that command by typing &lt;RET&gt;.
107
108   <p>Some convenience variables are created automatically by <span class="sc">gdb</span> and given
109values likely to be useful.
110
111     
112<a name="index-g_t_0024_005f_0040r_007b_002c-convenience-variable_007d-646"></a>
113<dl><dt><code>$_</code><dd>The variable <code>$_</code> is automatically set by the <code>x</code> command to
114the last address examined (see <a href="Memory.html#Memory">Examining Memory</a>).  Other
115commands which provide a default address for <code>x</code> to examine also
116set <code>$_</code> to that address; these commands include <code>info line</code>
117and <code>info breakpoint</code>.  The type of <code>$_</code> is <code>void *</code>
118except when set by the <code>x</code> command, in which case it is a pointer
119to the type of <code>$__</code>.
120
121     <p><a name="index-g_t_0024_005f_005f_0040r_007b_002c-convenience-variable_007d-647"></a><br><dt><code>$__</code><dd>The variable <code>$__</code> is automatically set by the <code>x</code> command
122to the value found in the last address examined.  Its type is chosen
123to match the format in which the data was printed.
124
125     <br><dt><code>$_exitcode</code><dd><a name="index-g_t_0024_005fexitcode_0040r_007b_002c-convenience-variable_007d-648"></a>The variable <code>$_exitcode</code> is automatically set to the exit code when
126the program being debugged terminates.
127
128     <br><dt><code>$_exception</code><dd>The variable <code>$_exception</code> is set to the exception object being
129thrown at an exception-related catchpoint.  See <a href="Set-Catchpoints.html#Set-Catchpoints">Set Catchpoints</a>.
130
131     <br><dt><code>$_probe_argc</code><dt><code>$_probe_arg0...$_probe_arg11</code><dd>Arguments to a static probe.  See <a href="Static-Probe-Points.html#Static-Probe-Points">Static Probe Points</a>.
132
133     <br><dt><code>$_sdata</code><dd><a name="index-g_t_0024_005fsdata_0040r_007b_002c-inspect_002c-convenience-variable_007d-649"></a>The variable <code>$_sdata</code> contains extra collected static tracepoint
134data.  See <a href="Tracepoint-Actions.html#Tracepoint-Actions">Tracepoint Action Lists</a>.  Note that
135<code>$_sdata</code> could be empty, if not inspecting a trace buffer, or
136if extra static tracepoint data has not been collected.
137
138     <br><dt><code>$_siginfo</code><dd><a name="index-g_t_0024_005fsiginfo_0040r_007b_002c-convenience-variable_007d-650"></a>The variable <code>$_siginfo</code> contains extra signal information
139(see <a href="extra-signal-information.html#extra-signal-information">extra signal information</a>).  Note that <code>$_siginfo</code>
140could be empty, if the application has not yet received any signals. 
141For example, it will be empty before you execute the <code>run</code> command.
142
143     <br><dt><code>$_tlb</code><dd><a name="index-g_t_0024_005ftlb_0040r_007b_002c-convenience-variable_007d-651"></a>The variable <code>$_tlb</code> is automatically set when debugging
144applications running on MS-Windows in native mode or connected to
145gdbserver that supports the <code>qGetTIBAddr</code> request. 
146See <a href="General-Query-Packets.html#General-Query-Packets">General Query Packets</a>. 
147This variable contains the address of the thread information block.
148
149   </dl>
150
151   <p>On HP-UX systems, if you refer to a function or variable name that
152begins with a dollar sign, <span class="sc">gdb</span> searches for a user or system
153name first, before it searches for a convenience variable.
154
155   </body></html>
156
157