You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

963 lines
40KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>GDB/MI Variable Objects (Debugging with GDB)</title>
  17. <meta name="description" content="GDB/MI Variable Objects (Debugging with GDB)">
  18. <meta name="keywords" content="GDB/MI Variable Objects (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="GDB_002fMI.html#GDB_002fMI" rel="up" title="GDB/MI">
  26. <link href="GDB_002fMI-Data-Manipulation.html#GDB_002fMI-Data-Manipulation" rel="next" title="GDB/MI Data Manipulation">
  27. <link href="GDB_002fMI-Stack-Manipulation.html#GDB_002fMI-Stack-Manipulation" rel="prev" title="GDB/MI Stack Manipulation">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="GDB_002fMI-Variable-Objects"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="GDB_002fMI-Data-Manipulation.html#GDB_002fMI-Data-Manipulation" accesskey="n" rel="next">GDB/MI Data Manipulation</a>, Previous: <a href="GDB_002fMI-Stack-Manipulation.html#GDB_002fMI-Stack-Manipulation" accesskey="p" rel="prev">GDB/MI Stack Manipulation</a>, Up: <a href="GDB_002fMI.html#GDB_002fMI" accesskey="u" rel="up">GDB/MI</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="GDB_002fMI-Variable-Objects-1"></a>
  64. <h3 class="section">27.15 <small>GDB/MI</small> Variable Objects</h3>
  65. <a name="Introduction-to-Variable-Objects"></a>
  66. <h4 class="subheading">Introduction to Variable Objects</h4>
  67. <a name="index-variable-objects-in-GDB_002fMI"></a>
  68. <p>Variable objects are &quot;object-oriented&quot; MI interface for examining and
  69. changing values of expressions. Unlike some other MI interfaces that
  70. work with expressions, variable objects are specifically designed for
  71. simple and efficient presentation in the frontend. A variable object
  72. is identified by string name. When a variable object is created, the
  73. frontend specifies the expression for that variable object. The
  74. expression can be a simple variable, or it can be an arbitrary complex
  75. expression, and can even involve CPU registers. After creating a
  76. variable object, the frontend can invoke other variable object
  77. operations&mdash;for example to obtain or change the value of a variable
  78. object, or to change display format.
  79. </p>
  80. <p>Variable objects have hierarchical tree structure. Any variable object
  81. that corresponds to a composite type, such as structure in C, has
  82. a number of child variable objects, for example corresponding to each
  83. element of a structure. A child variable object can itself have
  84. children, recursively. Recursion ends when we reach
  85. leaf variable objects, which always have built-in types. Child variable
  86. objects are created only by explicit request, so if a frontend
  87. is not interested in the children of a particular variable object, no
  88. child will be created.
  89. </p>
  90. <p>For a leaf variable object it is possible to obtain its value as a
  91. string, or set the value from a string. String value can be also
  92. obtained for a non-leaf variable object, but it&rsquo;s generally a string
  93. that only indicates the type of the object, and does not list its
  94. contents. Assignment to a non-leaf variable object is not allowed.
  95. </p>
  96. <p>A frontend does not need to read the values of all variable objects each time
  97. the program stops. Instead, MI provides an update command that lists all
  98. variable objects whose values has changed since the last update
  99. operation. This considerably reduces the amount of data that must
  100. be transferred to the frontend. As noted above, children variable
  101. objects are created on demand, and only leaf variable objects have a
  102. real value. As result, gdb will read target memory only for leaf
  103. variables that frontend has created.
  104. </p>
  105. <p>The automatic update is not always desirable. For example, a frontend
  106. might want to keep a value of some expression for future reference,
  107. and never update it. For another example, fetching memory is
  108. relatively slow for embedded targets, so a frontend might want
  109. to disable automatic update for the variables that are either not
  110. visible on the screen, or &ldquo;closed&rdquo;. This is possible using so
  111. called &ldquo;frozen variable objects&rdquo;. Such variable objects are never
  112. implicitly updated.
  113. </p>
  114. <p>Variable objects can be either <em>fixed</em> or <em>floating</em>. For the
  115. fixed variable object, the expression is parsed when the variable
  116. object is created, including associating identifiers to specific
  117. variables. The meaning of expression never changes. For a floating
  118. variable object the values of variables whose names appear in the
  119. expressions are re-evaluated every time in the context of the current
  120. frame. Consider this example:
  121. </p>
  122. <div class="smallexample">
  123. <pre class="smallexample">void do_work(...)
  124. {
  125. struct work_state state;
  126. if (...)
  127. do_work(...);
  128. }
  129. </pre></div>
  130. <p>If a fixed variable object for the <code>state</code> variable is created in
  131. this function, and we enter the recursive call, the variable
  132. object will report the value of <code>state</code> in the top-level
  133. <code>do_work</code> invocation. On the other hand, a floating variable
  134. object will report the value of <code>state</code> in the current frame.
  135. </p>
  136. <p>If an expression specified when creating a fixed variable object
  137. refers to a local variable, the variable object becomes bound to the
  138. thread and frame in which the variable object is created. When such
  139. variable object is updated, <small>GDB</small> makes sure that the
  140. thread/frame combination the variable object is bound to still exists,
  141. and re-evaluates the variable object in context of that thread/frame.
  142. </p>
  143. <p>The following is the complete set of <small>GDB/MI</small> operations defined to
  144. access this functionality:
  145. </p>
  146. <table>
  147. <tr><td width="40%"><strong>Operation</strong></td><td width="60%"><strong>Description</strong></td></tr>
  148. <tr><td width="40%"><code>-enable-pretty-printing</code></td><td width="60%">enable Python-based pretty-printing</td></tr>
  149. <tr><td width="40%"><code>-var-create</code></td><td width="60%">create a variable object</td></tr>
  150. <tr><td width="40%"><code>-var-delete</code></td><td width="60%">delete the variable object and/or its children</td></tr>
  151. <tr><td width="40%"><code>-var-set-format</code></td><td width="60%">set the display format of this variable</td></tr>
  152. <tr><td width="40%"><code>-var-show-format</code></td><td width="60%">show the display format of this variable</td></tr>
  153. <tr><td width="40%"><code>-var-info-num-children</code></td><td width="60%">tells how many children this object has</td></tr>
  154. <tr><td width="40%"><code>-var-list-children</code></td><td width="60%">return a list of the object&rsquo;s children</td></tr>
  155. <tr><td width="40%"><code>-var-info-type</code></td><td width="60%">show the type of this variable object</td></tr>
  156. <tr><td width="40%"><code>-var-info-expression</code></td><td width="60%">print parent-relative expression that this variable object represents</td></tr>
  157. <tr><td width="40%"><code>-var-info-path-expression</code></td><td width="60%">print full expression that this variable object represents</td></tr>
  158. <tr><td width="40%"><code>-var-show-attributes</code></td><td width="60%">is this variable editable? does it exist here?</td></tr>
  159. <tr><td width="40%"><code>-var-evaluate-expression</code></td><td width="60%">get the value of this variable</td></tr>
  160. <tr><td width="40%"><code>-var-assign</code></td><td width="60%">set the value of this variable</td></tr>
  161. <tr><td width="40%"><code>-var-update</code></td><td width="60%">update the variable and its children</td></tr>
  162. <tr><td width="40%"><code>-var-set-frozen</code></td><td width="60%">set frozenness attribute</td></tr>
  163. <tr><td width="40%"><code>-var-set-update-range</code></td><td width="60%">set range of children to display on update</td></tr>
  164. </table>
  165. <p>In the next subsection we describe each operation in detail and suggest
  166. how it can be used.
  167. </p>
  168. <a name="Description-And-Use-of-Operations-on-Variable-Objects"></a>
  169. <h4 class="subheading">Description And Use of Operations on Variable Objects</h4>
  170. <a name="The-_002denable_002dpretty_002dprinting-Command"></a>
  171. <h4 class="subheading">The <code>-enable-pretty-printing</code> Command</h4>
  172. <a name="index-_002denable_002dpretty_002dprinting"></a>
  173. <div class="smallexample">
  174. <pre class="smallexample">-enable-pretty-printing
  175. </pre></div>
  176. <p><small>GDB</small> allows Python-based visualizers to affect the output of the
  177. MI variable object commands. However, because there was no way to
  178. implement this in a fully backward-compatible way, a front end must
  179. request that this functionality be enabled.
  180. </p>
  181. <p>Once enabled, this feature cannot be disabled.
  182. </p>
  183. <p>Note that if Python support has not been compiled into <small>GDB</small>,
  184. this command will still succeed (and do nothing).
  185. </p>
  186. <p>This feature is currently (as of <small>GDB</small> 7.0) experimental, and
  187. may work differently in future versions of <small>GDB</small>.
  188. </p>
  189. <a name="The-_002dvar_002dcreate-Command"></a>
  190. <h4 class="subheading">The <code>-var-create</code> Command</h4>
  191. <a name="index-_002dvar_002dcreate"></a>
  192. <a name="Synopsis-48"></a>
  193. <h4 class="subsubheading">Synopsis</h4>
  194. <div class="smallexample">
  195. <pre class="smallexample"> -var-create {<var>name</var> | &quot;-&quot;}
  196. {<var>frame-addr</var> | &quot;*&quot; | &quot;@&quot;} <var>expression</var>
  197. </pre></div>
  198. <p>This operation creates a variable object, which allows the monitoring of
  199. a variable, the result of an expression, a memory cell or a CPU
  200. register.
  201. </p>
  202. <p>The <var>name</var> parameter is the string by which the object can be
  203. referenced. It must be unique. If &lsquo;<samp>-</samp>&rsquo; is specified, the varobj
  204. system will generate a string &ldquo;varNNNNNN&rdquo; automatically. It will be
  205. unique provided that one does not specify <var>name</var> of that format.
  206. The command fails if a duplicate name is found.
  207. </p>
  208. <p>The frame under which the expression should be evaluated can be
  209. specified by <var>frame-addr</var>. A &lsquo;<samp>*</samp>&rsquo; indicates that the current
  210. frame should be used. A &lsquo;<samp>@</samp>&rsquo; indicates that a floating variable
  211. object must be created.
  212. </p>
  213. <p><var>expression</var> is any expression valid on the current language set (must not
  214. begin with a &lsquo;<samp>*</samp>&rsquo;), or one of the following:
  215. </p>
  216. <ul>
  217. <li> &lsquo;<samp>*<var>addr</var></samp>&rsquo;, where <var>addr</var> is the address of a memory cell
  218. </li><li> &lsquo;<samp>*<var>addr</var>-<var>addr</var></samp>&rsquo; &mdash; a memory address range (TBD)
  219. </li><li> &lsquo;<samp>$<var>regname</var></samp>&rsquo; &mdash; a CPU register name
  220. </li></ul>
  221. <a name="index-dynamic-varobj"></a>
  222. <p>A varobj&rsquo;s contents may be provided by a Python-based pretty-printer. In this
  223. case the varobj is known as a <em>dynamic varobj</em>. Dynamic varobjs
  224. have slightly different semantics in some cases. If the
  225. <code>-enable-pretty-printing</code> command is not sent, then <small>GDB</small>
  226. will never create a dynamic varobj. This ensures backward
  227. compatibility for existing clients.
  228. </p>
  229. <a name="Result-5"></a>
  230. <h4 class="subsubheading">Result</h4>
  231. <p>This operation returns attributes of the newly-created varobj. These
  232. are:
  233. </p>
  234. <dl compact="compact">
  235. <dt>&lsquo;<samp>name</samp>&rsquo;</dt>
  236. <dd><p>The name of the varobj.
  237. </p>
  238. </dd>
  239. <dt>&lsquo;<samp>numchild</samp>&rsquo;</dt>
  240. <dd><p>The number of children of the varobj. This number is not necessarily
  241. reliable for a dynamic varobj. Instead, you must examine the
  242. &lsquo;<samp>has_more</samp>&rsquo; attribute.
  243. </p>
  244. </dd>
  245. <dt>&lsquo;<samp>value</samp>&rsquo;</dt>
  246. <dd><p>The varobj&rsquo;s scalar value. For a varobj whose type is some sort of
  247. aggregate (e.g., a <code>struct</code>), or for a dynamic varobj, this value
  248. will not be interesting.
  249. </p>
  250. </dd>
  251. <dt>&lsquo;<samp>type</samp>&rsquo;</dt>
  252. <dd><p>The varobj&rsquo;s type. This is a string representation of the type, as
  253. would be printed by the <small>GDB</small> CLI. If &lsquo;<samp>print object</samp>&rsquo;
  254. (see <a href="Print-Settings.html#Print-Settings">set print object</a>) is set to <code>on</code>, the
  255. <em>actual</em> (derived) type of the object is shown rather than the
  256. <em>declared</em> one.
  257. </p>
  258. </dd>
  259. <dt>&lsquo;<samp>thread-id</samp>&rsquo;</dt>
  260. <dd><p>If a variable object is bound to a specific thread, then this is the
  261. thread&rsquo;s global identifier.
  262. </p>
  263. </dd>
  264. <dt>&lsquo;<samp>has_more</samp>&rsquo;</dt>
  265. <dd><p>For a dynamic varobj, this indicates whether there appear to be any
  266. children available. For a non-dynamic varobj, this will be 0.
  267. </p>
  268. </dd>
  269. <dt>&lsquo;<samp>dynamic</samp>&rsquo;</dt>
  270. <dd><p>This attribute will be present and have the value &lsquo;<samp>1</samp>&rsquo; if the
  271. varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
  272. then this attribute will not be present.
  273. </p>
  274. </dd>
  275. <dt>&lsquo;<samp>displayhint</samp>&rsquo;</dt>
  276. <dd><p>A dynamic varobj can supply a display hint to the front end. The
  277. value comes directly from the Python pretty-printer object&rsquo;s
  278. <code>display_hint</code> method. See <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>.
  279. </p></dd>
  280. </dl>
  281. <p>Typical output will look like this:
  282. </p>
  283. <div class="smallexample">
  284. <pre class="smallexample"> name=&quot;<var>name</var>&quot;,numchild=&quot;<var>N</var>&quot;,type=&quot;<var>type</var>&quot;,thread-id=&quot;<var>M</var>&quot;,
  285. has_more=&quot;<var>has_more</var>&quot;
  286. </pre></div>
  287. <a name="The-_002dvar_002ddelete-Command"></a>
  288. <h4 class="subheading">The <code>-var-delete</code> Command</h4>
  289. <a name="index-_002dvar_002ddelete"></a>
  290. <a name="Synopsis-49"></a>
  291. <h4 class="subsubheading">Synopsis</h4>
  292. <div class="smallexample">
  293. <pre class="smallexample"> -var-delete [ -c ] <var>name</var>
  294. </pre></div>
  295. <p>Deletes a previously created variable object and all of its children.
  296. With the &lsquo;<samp>-c</samp>&rsquo; option, just deletes the children.
  297. </p>
  298. <p>Returns an error if the object <var>name</var> is not found.
  299. </p>
  300. <a name="The-_002dvar_002dset_002dformat-Command"></a>
  301. <h4 class="subheading">The <code>-var-set-format</code> Command</h4>
  302. <a name="index-_002dvar_002dset_002dformat"></a>
  303. <a name="Synopsis-50"></a>
  304. <h4 class="subsubheading">Synopsis</h4>
  305. <div class="smallexample">
  306. <pre class="smallexample"> -var-set-format <var>name</var> <var>format-spec</var>
  307. </pre></div>
  308. <p>Sets the output format for the value of the object <var>name</var> to be
  309. <var>format-spec</var>.
  310. </p>
  311. <a name="g_t_002dvar_002dset_002dformat"></a><p>The syntax for the <var>format-spec</var> is as follows:
  312. </p>
  313. <div class="smallexample">
  314. <pre class="smallexample"> <var>format-spec</var> &rarr;
  315. {binary | decimal | hexadecimal | octal | natural | zero-hexadecimal}
  316. </pre></div>
  317. <p>The natural format is the default format choosen automatically
  318. based on the variable type (like decimal for an <code>int</code>, hex
  319. for pointers, etc.).
  320. </p>
  321. <p>The zero-hexadecimal format has a representation similar to hexadecimal
  322. but with padding zeroes to the left of the value. For example, a 32-bit
  323. hexadecimal value of 0x1234 would be represented as 0x00001234 in the
  324. zero-hexadecimal format.
  325. </p>
  326. <p>For a variable with children, the format is set only on the
  327. variable itself, and the children are not affected.
  328. </p>
  329. <a name="The-_002dvar_002dshow_002dformat-Command"></a>
  330. <h4 class="subheading">The <code>-var-show-format</code> Command</h4>
  331. <a name="index-_002dvar_002dshow_002dformat"></a>
  332. <a name="Synopsis-51"></a>
  333. <h4 class="subsubheading">Synopsis</h4>
  334. <div class="smallexample">
  335. <pre class="smallexample"> -var-show-format <var>name</var>
  336. </pre></div>
  337. <p>Returns the format used to display the value of the object <var>name</var>.
  338. </p>
  339. <div class="smallexample">
  340. <pre class="smallexample"> <var>format</var> &rarr;
  341. <var>format-spec</var>
  342. </pre></div>
  343. <a name="The-_002dvar_002dinfo_002dnum_002dchildren-Command"></a>
  344. <h4 class="subheading">The <code>-var-info-num-children</code> Command</h4>
  345. <a name="index-_002dvar_002dinfo_002dnum_002dchildren"></a>
  346. <a name="Synopsis-52"></a>
  347. <h4 class="subsubheading">Synopsis</h4>
  348. <div class="smallexample">
  349. <pre class="smallexample"> -var-info-num-children <var>name</var>
  350. </pre></div>
  351. <p>Returns the number of children of a variable object <var>name</var>:
  352. </p>
  353. <div class="smallexample">
  354. <pre class="smallexample"> numchild=<var>n</var>
  355. </pre></div>
  356. <p>Note that this number is not completely reliable for a dynamic varobj.
  357. It will return the current number of children, but more children may
  358. be available.
  359. </p>
  360. <a name="The-_002dvar_002dlist_002dchildren-Command"></a>
  361. <h4 class="subheading">The <code>-var-list-children</code> Command</h4>
  362. <a name="index-_002dvar_002dlist_002dchildren"></a>
  363. <a name="Synopsis-53"></a>
  364. <h4 class="subsubheading">Synopsis</h4>
  365. <div class="smallexample">
  366. <pre class="smallexample"> -var-list-children [<var>print-values</var>] <var>name</var> [<var>from</var> <var>to</var>]
  367. </pre></div>
  368. <a name="g_t_002dvar_002dlist_002dchildren"></a>
  369. <p>Return a list of the children of the specified variable object and
  370. create variable objects for them, if they do not already exist. With
  371. a single argument or if <var>print-values</var> has a value of 0 or
  372. <code>--no-values</code>, print only the names of the variables; if
  373. <var>print-values</var> is 1 or <code>--all-values</code>, also print their
  374. values; and if it is 2 or <code>--simple-values</code> print the name and
  375. value for simple data types and just the name for arrays, structures
  376. and unions.
  377. </p>
  378. <p><var>from</var> and <var>to</var>, if specified, indicate the range of children
  379. to report. If <var>from</var> or <var>to</var> is less than zero, the range is
  380. reset and all children will be reported. Otherwise, children starting
  381. at <var>from</var> (zero-based) and up to and excluding <var>to</var> will be
  382. reported.
  383. </p>
  384. <p>If a child range is requested, it will only affect the current call to
  385. <code>-var-list-children</code>, but not future calls to <code>-var-update</code>.
  386. For this, you must instead use <code>-var-set-update-range</code>. The
  387. intent of this approach is to enable a front end to implement any
  388. update approach it likes; for example, scrolling a view may cause the
  389. front end to request more children with <code>-var-list-children</code>, and
  390. then the front end could call <code>-var-set-update-range</code> with a
  391. different range to ensure that future updates are restricted to just
  392. the visible items.
  393. </p>
  394. <p>For each child the following results are returned:
  395. </p>
  396. <dl compact="compact">
  397. <dt><var>name</var></dt>
  398. <dd><p>Name of the variable object created for this child.
  399. </p>
  400. </dd>
  401. <dt><var>exp</var></dt>
  402. <dd><p>The expression to be shown to the user by the front end to designate this child.
  403. For example this may be the name of a structure member.
  404. </p>
  405. <p>For a dynamic varobj, this value cannot be used to form an
  406. expression. There is no way to do this at all with a dynamic varobj.
  407. </p>
  408. <p>For C/C<tt>++</tt> structures there are several pseudo children returned to
  409. designate access qualifiers. For these pseudo children <var>exp</var> is
  410. &lsquo;<samp>public</samp>&rsquo;, &lsquo;<samp>private</samp>&rsquo;, or &lsquo;<samp>protected</samp>&rsquo;. In this case the
  411. type and value are not present.
  412. </p>
  413. <p>A dynamic varobj will not report the access qualifying
  414. pseudo-children, regardless of the language. This information is not
  415. available at all with a dynamic varobj.
  416. </p>
  417. </dd>
  418. <dt><var>numchild</var></dt>
  419. <dd><p>Number of children this child has. For a dynamic varobj, this will be
  420. 0.
  421. </p>
  422. </dd>
  423. <dt><var>type</var></dt>
  424. <dd><p>The type of the child. If &lsquo;<samp>print object</samp>&rsquo;
  425. (see <a href="Print-Settings.html#Print-Settings">set print object</a>) is set to <code>on</code>, the
  426. <em>actual</em> (derived) type of the object is shown rather than the
  427. <em>declared</em> one.
  428. </p>
  429. </dd>
  430. <dt><var>value</var></dt>
  431. <dd><p>If values were requested, this is the value.
  432. </p>
  433. </dd>
  434. <dt><var>thread-id</var></dt>
  435. <dd><p>If this variable object is associated with a thread, this is the
  436. thread&rsquo;s global thread id. Otherwise this result is not present.
  437. </p>
  438. </dd>
  439. <dt><var>frozen</var></dt>
  440. <dd><p>If the variable object is frozen, this variable will be present with a value of 1.
  441. </p>
  442. </dd>
  443. <dt><var>displayhint</var></dt>
  444. <dd><p>A dynamic varobj can supply a display hint to the front end. The
  445. value comes directly from the Python pretty-printer object&rsquo;s
  446. <code>display_hint</code> method. See <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>.
  447. </p>
  448. </dd>
  449. <dt><var>dynamic</var></dt>
  450. <dd><p>This attribute will be present and have the value &lsquo;<samp>1</samp>&rsquo; if the
  451. varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
  452. then this attribute will not be present.
  453. </p>
  454. </dd>
  455. </dl>
  456. <p>The result may have its own attributes:
  457. </p>
  458. <dl compact="compact">
  459. <dt>&lsquo;<samp>displayhint</samp>&rsquo;</dt>
  460. <dd><p>A dynamic varobj can supply a display hint to the front end. The
  461. value comes directly from the Python pretty-printer object&rsquo;s
  462. <code>display_hint</code> method. See <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>.
  463. </p>
  464. </dd>
  465. <dt>&lsquo;<samp>has_more</samp>&rsquo;</dt>
  466. <dd><p>This is an integer attribute which is nonzero if there are children
  467. remaining after the end of the selected range.
  468. </p></dd>
  469. </dl>
  470. <a name="Example-46"></a>
  471. <h4 class="subsubheading">Example</h4>
  472. <div class="smallexample">
  473. <pre class="smallexample">(gdb)
  474. -var-list-children n
  475. ^done,numchild=<var>n</var>,children=[child={name=<var>name</var>,exp=<var>exp</var>,
  476. numchild=<var>n</var>,type=<var>type</var>},<span class="roman">(repeats N times)</span>]
  477. (gdb)
  478. -var-list-children --all-values n
  479. ^done,numchild=<var>n</var>,children=[child={name=<var>name</var>,exp=<var>exp</var>,
  480. numchild=<var>n</var>,value=<var>value</var>,type=<var>type</var>},<span class="roman">(repeats N times)</span>]
  481. </pre></div>
  482. <a name="The-_002dvar_002dinfo_002dtype-Command"></a>
  483. <h4 class="subheading">The <code>-var-info-type</code> Command</h4>
  484. <a name="index-_002dvar_002dinfo_002dtype"></a>
  485. <a name="Synopsis-54"></a>
  486. <h4 class="subsubheading">Synopsis</h4>
  487. <div class="smallexample">
  488. <pre class="smallexample"> -var-info-type <var>name</var>
  489. </pre></div>
  490. <p>Returns the type of the specified variable <var>name</var>. The type is
  491. returned as a string in the same format as it is output by the
  492. <small>GDB</small> CLI:
  493. </p>
  494. <div class="smallexample">
  495. <pre class="smallexample"> type=<var>typename</var>
  496. </pre></div>
  497. <a name="The-_002dvar_002dinfo_002dexpression-Command"></a>
  498. <h4 class="subheading">The <code>-var-info-expression</code> Command</h4>
  499. <a name="index-_002dvar_002dinfo_002dexpression"></a>
  500. <a name="Synopsis-55"></a>
  501. <h4 class="subsubheading">Synopsis</h4>
  502. <div class="smallexample">
  503. <pre class="smallexample"> -var-info-expression <var>name</var>
  504. </pre></div>
  505. <p>Returns a string that is suitable for presenting this
  506. variable object in user interface. The string is generally
  507. not valid expression in the current language, and cannot be evaluated.
  508. </p>
  509. <p>For example, if <code>a</code> is an array, and variable object
  510. <code>A</code> was created for <code>a</code>, then we&rsquo;ll get this output:
  511. </p>
  512. <div class="smallexample">
  513. <pre class="smallexample">(gdb) -var-info-expression A.1
  514. ^done,lang=&quot;C&quot;,exp=&quot;1&quot;
  515. </pre></div>
  516. <p>Here, the value of <code>lang</code> is the language name, which can be
  517. found in <a href="Supported-Languages.html#Supported-Languages">Supported Languages</a>.
  518. </p>
  519. <p>Note that the output of the <code>-var-list-children</code> command also
  520. includes those expressions, so the <code>-var-info-expression</code> command
  521. is of limited use.
  522. </p>
  523. <a name="The-_002dvar_002dinfo_002dpath_002dexpression-Command"></a>
  524. <h4 class="subheading">The <code>-var-info-path-expression</code> Command</h4>
  525. <a name="index-_002dvar_002dinfo_002dpath_002dexpression"></a>
  526. <a name="Synopsis-56"></a>
  527. <h4 class="subsubheading">Synopsis</h4>
  528. <div class="smallexample">
  529. <pre class="smallexample"> -var-info-path-expression <var>name</var>
  530. </pre></div>
  531. <p>Returns an expression that can be evaluated in the current
  532. context and will yield the same value that a variable object has.
  533. Compare this with the <code>-var-info-expression</code> command, which
  534. result can be used only for UI presentation. Typical use of
  535. the <code>-var-info-path-expression</code> command is creating a
  536. watchpoint from a variable object.
  537. </p>
  538. <p>This command is currently not valid for children of a dynamic varobj,
  539. and will give an error when invoked on one.
  540. </p>
  541. <p>For example, suppose <code>C</code> is a C<tt>++</tt> class, derived from class
  542. <code>Base</code>, and that the <code>Base</code> class has a member called
  543. <code>m_size</code>. Assume a variable <code>c</code> is has the type of
  544. <code>C</code> and a variable object <code>C</code> was created for variable
  545. <code>c</code>. Then, we&rsquo;ll get this output:
  546. </p><div class="smallexample">
  547. <pre class="smallexample">(gdb) -var-info-path-expression C.Base.public.m_size
  548. ^done,path_expr=((Base)c).m_size)
  549. </pre></div>
  550. <a name="The-_002dvar_002dshow_002dattributes-Command"></a>
  551. <h4 class="subheading">The <code>-var-show-attributes</code> Command</h4>
  552. <a name="index-_002dvar_002dshow_002dattributes"></a>
  553. <a name="Synopsis-57"></a>
  554. <h4 class="subsubheading">Synopsis</h4>
  555. <div class="smallexample">
  556. <pre class="smallexample"> -var-show-attributes <var>name</var>
  557. </pre></div>
  558. <p>List attributes of the specified variable object <var>name</var>:
  559. </p>
  560. <div class="smallexample">
  561. <pre class="smallexample"> status=<var>attr</var> [ ( ,<var>attr</var> )* ]
  562. </pre></div>
  563. <p>where <var>attr</var> is <code>{ { editable | noneditable } | TBD }</code>.
  564. </p>
  565. <a name="The-_002dvar_002devaluate_002dexpression-Command"></a>
  566. <h4 class="subheading">The <code>-var-evaluate-expression</code> Command</h4>
  567. <a name="index-_002dvar_002devaluate_002dexpression"></a>
  568. <a name="Synopsis-58"></a>
  569. <h4 class="subsubheading">Synopsis</h4>
  570. <div class="smallexample">
  571. <pre class="smallexample"> -var-evaluate-expression [-f <var>format-spec</var>] <var>name</var>
  572. </pre></div>
  573. <p>Evaluates the expression that is represented by the specified variable
  574. object and returns its value as a string. The format of the string
  575. can be specified with the &lsquo;<samp>-f</samp>&rsquo; option. The possible values of
  576. this option are the same as for <code>-var-set-format</code>
  577. (see <a href="#g_t_002dvar_002dset_002dformat">-var-set-format</a>). If the &lsquo;<samp>-f</samp>&rsquo; option is not specified,
  578. the current display format will be used. The current display format
  579. can be changed using the <code>-var-set-format</code> command.
  580. </p>
  581. <div class="smallexample">
  582. <pre class="smallexample"> value=<var>value</var>
  583. </pre></div>
  584. <p>Note that one must invoke <code>-var-list-children</code> for a variable
  585. before the value of a child variable can be evaluated.
  586. </p>
  587. <a name="The-_002dvar_002dassign-Command"></a>
  588. <h4 class="subheading">The <code>-var-assign</code> Command</h4>
  589. <a name="index-_002dvar_002dassign"></a>
  590. <a name="Synopsis-59"></a>
  591. <h4 class="subsubheading">Synopsis</h4>
  592. <div class="smallexample">
  593. <pre class="smallexample"> -var-assign <var>name</var> <var>expression</var>
  594. </pre></div>
  595. <p>Assigns the value of <var>expression</var> to the variable object specified
  596. by <var>name</var>. The object must be &lsquo;<samp>editable</samp>&rsquo;. If the variable&rsquo;s
  597. value is altered by the assign, the variable will show up in any
  598. subsequent <code>-var-update</code> list.
  599. </p>
  600. <a name="Example-47"></a>
  601. <h4 class="subsubheading">Example</h4>
  602. <div class="smallexample">
  603. <pre class="smallexample">(gdb)
  604. -var-assign var1 3
  605. ^done,value=&quot;3&quot;
  606. (gdb)
  607. -var-update *
  608. ^done,changelist=[{name=&quot;var1&quot;,in_scope=&quot;true&quot;,type_changed=&quot;false&quot;}]
  609. (gdb)
  610. </pre></div>
  611. <a name="The-_002dvar_002dupdate-Command"></a>
  612. <h4 class="subheading">The <code>-var-update</code> Command</h4>
  613. <a name="index-_002dvar_002dupdate"></a>
  614. <a name="Synopsis-60"></a>
  615. <h4 class="subsubheading">Synopsis</h4>
  616. <div class="smallexample">
  617. <pre class="smallexample"> -var-update [<var>print-values</var>] {<var>name</var> | &quot;*&quot;}
  618. </pre></div>
  619. <p>Reevaluate the expressions corresponding to the variable object
  620. <var>name</var> and all its direct and indirect children, and return the
  621. list of variable objects whose values have changed; <var>name</var> must
  622. be a root variable object. Here, &ldquo;changed&rdquo; means that the result of
  623. <code>-var-evaluate-expression</code> before and after the
  624. <code>-var-update</code> is different. If &lsquo;<samp>*</samp>&rsquo; is used as the variable
  625. object names, all existing variable objects are updated, except
  626. for frozen ones (see <a href="#g_t_002dvar_002dset_002dfrozen">-var-set-frozen</a>). The option
  627. <var>print-values</var> determines whether both names and values, or just
  628. names are printed. The possible values of this option are the same
  629. as for <code>-var-list-children</code> (see <a href="#g_t_002dvar_002dlist_002dchildren">-var-list-children</a>). It is
  630. recommended to use the &lsquo;<samp>--all-values</samp>&rsquo; option, to reduce the
  631. number of MI commands needed on each program stop.
  632. </p>
  633. <p>With the &lsquo;<samp>*</samp>&rsquo; parameter, if a variable object is bound to a
  634. currently running thread, it will not be updated, without any
  635. diagnostic.
  636. </p>
  637. <p>If <code>-var-set-update-range</code> was previously used on a varobj, then
  638. only the selected range of children will be reported.
  639. </p>
  640. <p><code>-var-update</code> reports all the changed varobjs in a tuple named
  641. &lsquo;<samp>changelist</samp>&rsquo;.
  642. </p>
  643. <p>Each item in the change list is itself a tuple holding:
  644. </p>
  645. <dl compact="compact">
  646. <dt>&lsquo;<samp>name</samp>&rsquo;</dt>
  647. <dd><p>The name of the varobj.
  648. </p>
  649. </dd>
  650. <dt>&lsquo;<samp>value</samp>&rsquo;</dt>
  651. <dd><p>If values were requested for this update, then this field will be
  652. present and will hold the value of the varobj.
  653. </p>
  654. </dd>
  655. <dt>&lsquo;<samp>in_scope</samp>&rsquo;</dt>
  656. <dd><a name="g_t_002dvar_002dupdate"></a><p>This field is a string which may take one of three values:
  657. </p>
  658. <dl compact="compact">
  659. <dt><code>&quot;true&quot;</code></dt>
  660. <dd><p>The variable object&rsquo;s current value is valid.
  661. </p>
  662. </dd>
  663. <dt><code>&quot;false&quot;</code></dt>
  664. <dd><p>The variable object does not currently hold a valid value but it may
  665. hold one in the future if its associated expression comes back into
  666. scope.
  667. </p>
  668. </dd>
  669. <dt><code>&quot;invalid&quot;</code></dt>
  670. <dd><p>The variable object no longer holds a valid value.
  671. This can occur when the executable file being debugged has changed,
  672. either through recompilation or by using the <small>GDB</small> <code>file</code>
  673. command. The front end should normally choose to delete these variable
  674. objects.
  675. </p></dd>
  676. </dl>
  677. <p>In the future new values may be added to this list so the front should
  678. be prepared for this possibility. See <a href="GDB_002fMI-Development-and-Front-Ends.html#GDB_002fMI-Development-and-Front-Ends"><small>GDB/MI</small> Development and Front Ends</a>.
  679. </p>
  680. </dd>
  681. <dt>&lsquo;<samp>type_changed</samp>&rsquo;</dt>
  682. <dd><p>This is only present if the varobj is still valid. If the type
  683. changed, then this will be the string &lsquo;<samp>true</samp>&rsquo;; otherwise it will
  684. be &lsquo;<samp>false</samp>&rsquo;.
  685. </p>
  686. <p>When a varobj&rsquo;s type changes, its children are also likely to have
  687. become incorrect. Therefore, the varobj&rsquo;s children are automatically
  688. deleted when this attribute is &lsquo;<samp>true</samp>&rsquo;. Also, the varobj&rsquo;s update
  689. range, when set using the <code>-var-set-update-range</code> command, is
  690. unset.
  691. </p>
  692. </dd>
  693. <dt>&lsquo;<samp>new_type</samp>&rsquo;</dt>
  694. <dd><p>If the varobj&rsquo;s type changed, then this field will be present and will
  695. hold the new type.
  696. </p>
  697. </dd>
  698. <dt>&lsquo;<samp>new_num_children</samp>&rsquo;</dt>
  699. <dd><p>For a dynamic varobj, if the number of children changed, or if the
  700. type changed, this will be the new number of children.
  701. </p>
  702. <p>The &lsquo;<samp>numchild</samp>&rsquo; field in other varobj responses is generally not
  703. valid for a dynamic varobj &ndash; it will show the number of children that
  704. <small>GDB</small> knows about, but because dynamic varobjs lazily
  705. instantiate their children, this will not reflect the number of
  706. children which may be available.
  707. </p>
  708. <p>The &lsquo;<samp>new_num_children</samp>&rsquo; attribute only reports changes to the
  709. number of children known by <small>GDB</small>. This is the only way to
  710. detect whether an update has removed children (which necessarily can
  711. only happen at the end of the update range).
  712. </p>
  713. </dd>
  714. <dt>&lsquo;<samp>displayhint</samp>&rsquo;</dt>
  715. <dd><p>The display hint, if any.
  716. </p>
  717. </dd>
  718. <dt>&lsquo;<samp>has_more</samp>&rsquo;</dt>
  719. <dd><p>This is an integer value, which will be 1 if there are more children
  720. available outside the varobj&rsquo;s update range.
  721. </p>
  722. </dd>
  723. <dt>&lsquo;<samp>dynamic</samp>&rsquo;</dt>
  724. <dd><p>This attribute will be present and have the value &lsquo;<samp>1</samp>&rsquo; if the
  725. varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
  726. then this attribute will not be present.
  727. </p>
  728. </dd>
  729. <dt>&lsquo;<samp>new_children</samp>&rsquo;</dt>
  730. <dd><p>If new children were added to a dynamic varobj within the selected
  731. update range (as set by <code>-var-set-update-range</code>), then they will
  732. be listed in this attribute.
  733. </p></dd>
  734. </dl>
  735. <a name="Example-48"></a>
  736. <h4 class="subsubheading">Example</h4>
  737. <div class="smallexample">
  738. <pre class="smallexample">(gdb)
  739. -var-assign var1 3
  740. ^done,value=&quot;3&quot;
  741. (gdb)
  742. -var-update --all-values var1
  743. ^done,changelist=[{name=&quot;var1&quot;,value=&quot;3&quot;,in_scope=&quot;true&quot;,
  744. type_changed=&quot;false&quot;}]
  745. (gdb)
  746. </pre></div>
  747. <a name="The-_002dvar_002dset_002dfrozen-Command"></a>
  748. <h4 class="subheading">The <code>-var-set-frozen</code> Command</h4>
  749. <a name="index-_002dvar_002dset_002dfrozen"></a>
  750. <a name="g_t_002dvar_002dset_002dfrozen"></a>
  751. <a name="Synopsis-61"></a>
  752. <h4 class="subsubheading">Synopsis</h4>
  753. <div class="smallexample">
  754. <pre class="smallexample"> -var-set-frozen <var>name</var> <var>flag</var>
  755. </pre></div>
  756. <p>Set the frozenness flag on the variable object <var>name</var>. The
  757. <var>flag</var> parameter should be either &lsquo;<samp>1</samp>&rsquo; to make the variable
  758. frozen or &lsquo;<samp>0</samp>&rsquo; to make it unfrozen. If a variable object is
  759. frozen, then neither itself, nor any of its children, are
  760. implicitly updated by <code>-var-update</code> of
  761. a parent variable or by <code>-var-update *</code>. Only
  762. <code>-var-update</code> of the variable itself will update its value and
  763. values of its children. After a variable object is unfrozen, it is
  764. implicitly updated by all subsequent <code>-var-update</code> operations.
  765. Unfreezing a variable does not update it, only subsequent
  766. <code>-var-update</code> does.
  767. </p>
  768. <a name="Example-49"></a>
  769. <h4 class="subsubheading">Example</h4>
  770. <div class="smallexample">
  771. <pre class="smallexample">(gdb)
  772. -var-set-frozen V 1
  773. ^done
  774. (gdb)
  775. </pre></div>
  776. <a name="The-_002dvar_002dset_002dupdate_002drange-command"></a>
  777. <h4 class="subheading">The <code>-var-set-update-range</code> command</h4>
  778. <a name="index-_002dvar_002dset_002dupdate_002drange"></a>
  779. <a name="g_t_002dvar_002dset_002dupdate_002drange"></a>
  780. <a name="Synopsis-62"></a>
  781. <h4 class="subsubheading">Synopsis</h4>
  782. <div class="smallexample">
  783. <pre class="smallexample"> -var-set-update-range <var>name</var> <var>from</var> <var>to</var>
  784. </pre></div>
  785. <p>Set the range of children to be returned by future invocations of
  786. <code>-var-update</code>.
  787. </p>
  788. <p><var>from</var> and <var>to</var> indicate the range of children to report. If
  789. <var>from</var> or <var>to</var> is less than zero, the range is reset and all
  790. children will be reported. Otherwise, children starting at <var>from</var>
  791. (zero-based) and up to and excluding <var>to</var> will be reported.
  792. </p>
  793. <a name="Example-50"></a>
  794. <h4 class="subsubheading">Example</h4>
  795. <div class="smallexample">
  796. <pre class="smallexample">(gdb)
  797. -var-set-update-range V 1 2
  798. ^done
  799. </pre></div>
  800. <a name="The-_002dvar_002dset_002dvisualizer-command"></a>
  801. <h4 class="subheading">The <code>-var-set-visualizer</code> command</h4>
  802. <a name="index-_002dvar_002dset_002dvisualizer"></a>
  803. <a name="g_t_002dvar_002dset_002dvisualizer"></a>
  804. <a name="Synopsis-63"></a>
  805. <h4 class="subsubheading">Synopsis</h4>
  806. <div class="smallexample">
  807. <pre class="smallexample"> -var-set-visualizer <var>name</var> <var>visualizer</var>
  808. </pre></div>
  809. <p>Set a visualizer for the variable object <var>name</var>.
  810. </p>
  811. <p><var>visualizer</var> is the visualizer to use. The special value
  812. &lsquo;<samp>None</samp>&rsquo; means to disable any visualizer in use.
  813. </p>
  814. <p>If not &lsquo;<samp>None</samp>&rsquo;, <var>visualizer</var> must be a Python expression.
  815. This expression must evaluate to a callable object which accepts a
  816. single argument. <small>GDB</small> will call this object with the value of
  817. the varobj <var>name</var> as an argument (this is done so that the same
  818. Python pretty-printing code can be used for both the CLI and MI).
  819. When called, this object must return an object which conforms to the
  820. pretty-printing interface (see <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>).
  821. </p>
  822. <p>The pre-defined function <code>gdb.default_visualizer</code> may be used to
  823. select a visualizer by following the built-in process
  824. (see <a href="Selecting-Pretty_002dPrinters.html#Selecting-Pretty_002dPrinters">Selecting Pretty-Printers</a>). This is done automatically when
  825. a varobj is created, and so ordinarily is not needed.
  826. </p>
  827. <p>This feature is only available if Python support is enabled. The MI
  828. command <code>-list-features</code> (see <a href="GDB_002fMI-Support-Commands.html#GDB_002fMI-Support-Commands">GDB/MI Support Commands</a>)
  829. can be used to check this.
  830. </p>
  831. <a name="Example-51"></a>
  832. <h4 class="subsubheading">Example</h4>
  833. <p>Resetting the visualizer:
  834. </p>
  835. <div class="smallexample">
  836. <pre class="smallexample">(gdb)
  837. -var-set-visualizer V None
  838. ^done
  839. </pre></div>
  840. <p>Reselecting the default (type-based) visualizer:
  841. </p>
  842. <div class="smallexample">
  843. <pre class="smallexample">(gdb)
  844. -var-set-visualizer V gdb.default_visualizer
  845. ^done
  846. </pre></div>
  847. <p>Suppose <code>SomeClass</code> is a visualizer class. A lambda expression
  848. can be used to instantiate this class for a varobj:
  849. </p>
  850. <div class="smallexample">
  851. <pre class="smallexample">(gdb)
  852. -var-set-visualizer V &quot;lambda val: SomeClass()&quot;
  853. ^done
  854. </pre></div>
  855. <hr>
  856. <div class="header">
  857. <p>
  858. Next: <a href="GDB_002fMI-Data-Manipulation.html#GDB_002fMI-Data-Manipulation" accesskey="n" rel="next">GDB/MI Data Manipulation</a>, Previous: <a href="GDB_002fMI-Stack-Manipulation.html#GDB_002fMI-Stack-Manipulation" accesskey="p" rel="prev">GDB/MI Stack Manipulation</a>, Up: <a href="GDB_002fMI.html#GDB_002fMI" accesskey="u" rel="up">GDB/MI</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  859. </div>
  860. </body>
  861. </html>