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.

Values-From-Inferior.html 26KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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>Values From Inferior (Debugging with GDB)</title>
  17. <meta name="description" content="Values From Inferior (Debugging with GDB)">
  18. <meta name="keywords" content="Values From Inferior (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="Python-API.html#Python-API" rel="up" title="Python API">
  26. <link href="Types-In-Python.html#Types-In-Python" rel="next" title="Types In Python">
  27. <link href="Exception-Handling.html#Exception-Handling" rel="prev" title="Exception Handling">
  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="Values-From-Inferior"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Types-In-Python.html#Types-In-Python" accesskey="n" rel="next">Types In Python</a>, Previous: <a href="Exception-Handling.html#Exception-Handling" accesskey="p" rel="prev">Exception Handling</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</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="Values-From-Inferior-1"></a>
  64. <h4 class="subsubsection">23.2.2.3 Values From Inferior</h4>
  65. <a name="index-values-from-inferior_002c-with-Python"></a>
  66. <a name="index-python_002c-working-with-values-from-inferior"></a>
  67. <a name="index-gdb_002eValue"></a>
  68. <p><small>GDB</small> provides values it obtains from the inferior program in
  69. an object of type <code>gdb.Value</code>. <small>GDB</small> uses this object
  70. for its internal bookkeeping of the inferior&rsquo;s values, and for
  71. fetching values when necessary.
  72. </p>
  73. <p>Inferior values that are simple scalars can be used directly in
  74. Python expressions that are valid for the value&rsquo;s data type. Here&rsquo;s
  75. an example for an integer or floating-point value <code>some_val</code>:
  76. </p>
  77. <div class="smallexample">
  78. <pre class="smallexample">bar = some_val + 2
  79. </pre></div>
  80. <p>As result of this, <code>bar</code> will also be a <code>gdb.Value</code> object
  81. whose values are of the same type as those of <code>some_val</code>. Valid
  82. Python operations can also be performed on <code>gdb.Value</code> objects
  83. representing a <code>struct</code> or <code>class</code> object. For such cases,
  84. the overloaded operator (if present), is used to perform the operation.
  85. For example, if <code>val1</code> and <code>val2</code> are <code>gdb.Value</code> objects
  86. representing instances of a <code>class</code> which overloads the <code>+</code>
  87. operator, then one can use the <code>+</code> operator in their Python script
  88. as follows:
  89. </p>
  90. <div class="smallexample">
  91. <pre class="smallexample">val3 = val1 + val2
  92. </pre></div>
  93. <p>The result of the operation <code>val3</code> is also a <code>gdb.Value</code>
  94. object corresponding to the value returned by the overloaded <code>+</code>
  95. operator. In general, overloaded operators are invoked for the
  96. following operations: <code>+</code> (binary addition), <code>-</code> (binary
  97. subtraction), <code>*</code> (multiplication), <code>/</code>, <code>%</code>, <code>&lt;&lt;</code>,
  98. <code>&gt;&gt;</code>, <code>|</code>, <code>&amp;</code>, <code>^</code>.
  99. </p>
  100. <p>Inferior values that are structures or instances of some class can
  101. be accessed using the Python <em>dictionary syntax</em>. For example, if
  102. <code>some_val</code> is a <code>gdb.Value</code> instance holding a structure, you
  103. can access its <code>foo</code> element with:
  104. </p>
  105. <div class="smallexample">
  106. <pre class="smallexample">bar = some_val['foo']
  107. </pre></div>
  108. <a name="index-getting-structure-elements-using-gdb_002eField-objects-as-subscripts"></a>
  109. <p>Again, <code>bar</code> will also be a <code>gdb.Value</code> object. Structure
  110. elements can also be accessed by using <code>gdb.Field</code> objects as
  111. subscripts (see <a href="Types-In-Python.html#Types-In-Python">Types In Python</a>, for more information on
  112. <code>gdb.Field</code> objects). For example, if <code>foo_field</code> is a
  113. <code>gdb.Field</code> object corresponding to element <code>foo</code> of the above
  114. structure, then <code>bar</code> can also be accessed as follows:
  115. </p>
  116. <div class="smallexample">
  117. <pre class="smallexample">bar = some_val[foo_field]
  118. </pre></div>
  119. <p>A <code>gdb.Value</code> that represents a function can be executed via
  120. inferior function call. Any arguments provided to the call must match
  121. the function&rsquo;s prototype, and must be provided in the order specified
  122. by that prototype.
  123. </p>
  124. <p>For example, <code>some_val</code> is a <code>gdb.Value</code> instance
  125. representing a function that takes two integers as arguments. To
  126. execute this function, call it like so:
  127. </p>
  128. <div class="smallexample">
  129. <pre class="smallexample">result = some_val (10,20)
  130. </pre></div>
  131. <p>Any values returned from a function call will be stored as a
  132. <code>gdb.Value</code>.
  133. </p>
  134. <p>The following attributes are provided:
  135. </p>
  136. <dl>
  137. <dt><a name="index-Value_002eaddress"></a>Variable: <strong>Value.address</strong></dt>
  138. <dd><p>If this object is addressable, this read-only attribute holds a
  139. <code>gdb.Value</code> object representing the address. Otherwise,
  140. this attribute holds <code>None</code>.
  141. </p></dd></dl>
  142. <a name="index-optimized-out-value-in-Python"></a>
  143. <dl>
  144. <dt><a name="index-Value_002eis_005foptimized_005fout"></a>Variable: <strong>Value.is_optimized_out</strong></dt>
  145. <dd><p>This read-only boolean attribute is true if the compiler optimized out
  146. this value, thus it is not available for fetching from the inferior.
  147. </p></dd></dl>
  148. <dl>
  149. <dt><a name="index-Value_002etype"></a>Variable: <strong>Value.type</strong></dt>
  150. <dd><p>The type of this <code>gdb.Value</code>. The value of this attribute is a
  151. <code>gdb.Type</code> object (see <a href="Types-In-Python.html#Types-In-Python">Types In Python</a>).
  152. </p></dd></dl>
  153. <dl>
  154. <dt><a name="index-Value_002edynamic_005ftype"></a>Variable: <strong>Value.dynamic_type</strong></dt>
  155. <dd><p>The dynamic type of this <code>gdb.Value</code>. This uses the object&rsquo;s
  156. virtual table and the C<tt>++</tt> run-time type information
  157. (<acronym>RTTI</acronym>) to determine the dynamic type of the value. If this
  158. value is of class type, it will return the class in which the value is
  159. embedded, if any. If this value is of pointer or reference to a class
  160. type, it will compute the dynamic type of the referenced object, and
  161. return a pointer or reference to that type, respectively. In all
  162. other cases, it will return the value&rsquo;s static type.
  163. </p>
  164. <p>Note that this feature will only work when debugging a C<tt>++</tt> program
  165. that includes <acronym>RTTI</acronym> for the object in question. Otherwise,
  166. it will just return the static type of the value as in <kbd>ptype foo</kbd>
  167. (see <a href="Symbols.html#Symbols">ptype</a>).
  168. </p></dd></dl>
  169. <dl>
  170. <dt><a name="index-Value_002eis_005flazy"></a>Variable: <strong>Value.is_lazy</strong></dt>
  171. <dd><p>The value of this read-only boolean attribute is <code>True</code> if this
  172. <code>gdb.Value</code> has not yet been fetched from the inferior.
  173. <small>GDB</small> does not fetch values until necessary, for efficiency.
  174. For example:
  175. </p>
  176. <div class="smallexample">
  177. <pre class="smallexample">myval = gdb.parse_and_eval ('somevar')
  178. </pre></div>
  179. <p>The value of <code>somevar</code> is not fetched at this time. It will be
  180. fetched when the value is needed, or when the <code>fetch_lazy</code>
  181. method is invoked.
  182. </p></dd></dl>
  183. <p>The following methods are provided:
  184. </p>
  185. <dl>
  186. <dt><a name="index-Value_002e_005f_005finit_005f_005f"></a>Function: <strong>Value.__init__</strong> <em>(<var>val</var>)</em></dt>
  187. <dd><p>Many Python values can be converted directly to a <code>gdb.Value</code> via
  188. this object initializer. Specifically:
  189. </p>
  190. <dl compact="compact">
  191. <dt>Python boolean</dt>
  192. <dd><p>A Python boolean is converted to the boolean type from the current
  193. language.
  194. </p>
  195. </dd>
  196. <dt>Python integer</dt>
  197. <dd><p>A Python integer is converted to the C <code>long</code> type for the
  198. current architecture.
  199. </p>
  200. </dd>
  201. <dt>Python long</dt>
  202. <dd><p>A Python long is converted to the C <code>long long</code> type for the
  203. current architecture.
  204. </p>
  205. </dd>
  206. <dt>Python float</dt>
  207. <dd><p>A Python float is converted to the C <code>double</code> type for the
  208. current architecture.
  209. </p>
  210. </dd>
  211. <dt>Python string</dt>
  212. <dd><p>A Python string is converted to a target string in the current target
  213. language using the current target encoding.
  214. If a character cannot be represented in the current target encoding,
  215. then an exception is thrown.
  216. </p>
  217. </dd>
  218. <dt><code>gdb.Value</code></dt>
  219. <dd><p>If <code>val</code> is a <code>gdb.Value</code>, then a copy of the value is made.
  220. </p>
  221. </dd>
  222. <dt><code>gdb.LazyString</code></dt>
  223. <dd><p>If <code>val</code> is a <code>gdb.LazyString</code> (see <a href="Lazy-Strings-In-Python.html#Lazy-Strings-In-Python">Lazy Strings In Python</a>), then the lazy string&rsquo;s <code>value</code> method is called, and
  224. its result is used.
  225. </p></dd>
  226. </dl>
  227. </dd></dl>
  228. <dl>
  229. <dt><a name="index-Value_002e_005f_005finit_005f_005f-1"></a>Function: <strong>Value.__init__</strong> <em>(<var>val</var>, <var>type</var>)</em></dt>
  230. <dd><p>This second form of the <code>gdb.Value</code> constructor returns a
  231. <code>gdb.Value</code> of type <var>type</var> where the value contents are taken
  232. from the Python buffer object specified by <var>val</var>. The number of
  233. bytes in the Python buffer object must be greater than or equal to the
  234. size of <var>type</var>.
  235. </p></dd></dl>
  236. <dl>
  237. <dt><a name="index-Value_002ecast"></a>Function: <strong>Value.cast</strong> <em>(type)</em></dt>
  238. <dd><p>Return a new instance of <code>gdb.Value</code> that is the result of
  239. casting this instance to the type described by <var>type</var>, which must
  240. be a <code>gdb.Type</code> object. If the cast cannot be performed for some
  241. reason, this method throws an exception.
  242. </p></dd></dl>
  243. <dl>
  244. <dt><a name="index-Value_002edereference"></a>Function: <strong>Value.dereference</strong> <em>()</em></dt>
  245. <dd><p>For pointer data types, this method returns a new <code>gdb.Value</code> object
  246. whose contents is the object pointed to by the pointer. For example, if
  247. <code>foo</code> is a C pointer to an <code>int</code>, declared in your C program as
  248. </p>
  249. <div class="smallexample">
  250. <pre class="smallexample">int *foo;
  251. </pre></div>
  252. <p>then you can use the corresponding <code>gdb.Value</code> to access what
  253. <code>foo</code> points to like this:
  254. </p>
  255. <div class="smallexample">
  256. <pre class="smallexample">bar = foo.dereference ()
  257. </pre></div>
  258. <p>The result <code>bar</code> will be a <code>gdb.Value</code> object holding the
  259. value pointed to by <code>foo</code>.
  260. </p>
  261. <p>A similar function <code>Value.referenced_value</code> exists which also
  262. returns <code>gdb.Value</code> objects corresponding to the values pointed to
  263. by pointer values (and additionally, values referenced by reference
  264. values). However, the behavior of <code>Value.dereference</code>
  265. differs from <code>Value.referenced_value</code> by the fact that the
  266. behavior of <code>Value.dereference</code> is identical to applying the C
  267. unary operator <code>*</code> on a given value. For example, consider a
  268. reference to a pointer <code>ptrref</code>, declared in your C<tt>++</tt> program
  269. as
  270. </p>
  271. <div class="smallexample">
  272. <pre class="smallexample">typedef int *intptr;
  273. ...
  274. int val = 10;
  275. intptr ptr = &amp;val;
  276. intptr &amp;ptrref = ptr;
  277. </pre></div>
  278. <p>Though <code>ptrref</code> is a reference value, one can apply the method
  279. <code>Value.dereference</code> to the <code>gdb.Value</code> object corresponding
  280. to it and obtain a <code>gdb.Value</code> which is identical to that
  281. corresponding to <code>val</code>. However, if you apply the method
  282. <code>Value.referenced_value</code>, the result would be a <code>gdb.Value</code>
  283. object identical to that corresponding to <code>ptr</code>.
  284. </p>
  285. <div class="smallexample">
  286. <pre class="smallexample">py_ptrref = gdb.parse_and_eval (&quot;ptrref&quot;)
  287. py_val = py_ptrref.dereference ()
  288. py_ptr = py_ptrref.referenced_value ()
  289. </pre></div>
  290. <p>The <code>gdb.Value</code> object <code>py_val</code> is identical to that
  291. corresponding to <code>val</code>, and <code>py_ptr</code> is identical to that
  292. corresponding to <code>ptr</code>. In general, <code>Value.dereference</code> can
  293. be applied whenever the C unary operator <code>*</code> can be applied
  294. to the corresponding C value. For those cases where applying both
  295. <code>Value.dereference</code> and <code>Value.referenced_value</code> is allowed,
  296. the results obtained need not be identical (as we have seen in the above
  297. example). The results are however identical when applied on
  298. <code>gdb.Value</code> objects corresponding to pointers (<code>gdb.Value</code>
  299. objects with type code <code>TYPE_CODE_PTR</code>) in a C/C<tt>++</tt> program.
  300. </p></dd></dl>
  301. <dl>
  302. <dt><a name="index-Value_002ereferenced_005fvalue"></a>Function: <strong>Value.referenced_value</strong> <em>()</em></dt>
  303. <dd><p>For pointer or reference data types, this method returns a new
  304. <code>gdb.Value</code> object corresponding to the value referenced by the
  305. pointer/reference value. For pointer data types,
  306. <code>Value.dereference</code> and <code>Value.referenced_value</code> produce
  307. identical results. The difference between these methods is that
  308. <code>Value.dereference</code> cannot get the values referenced by reference
  309. values. For example, consider a reference to an <code>int</code>, declared
  310. in your C<tt>++</tt> program as
  311. </p>
  312. <div class="smallexample">
  313. <pre class="smallexample">int val = 10;
  314. int &amp;ref = val;
  315. </pre></div>
  316. <p>then applying <code>Value.dereference</code> to the <code>gdb.Value</code> object
  317. corresponding to <code>ref</code> will result in an error, while applying
  318. <code>Value.referenced_value</code> will result in a <code>gdb.Value</code> object
  319. identical to that corresponding to <code>val</code>.
  320. </p>
  321. <div class="smallexample">
  322. <pre class="smallexample">py_ref = gdb.parse_and_eval (&quot;ref&quot;)
  323. er_ref = py_ref.dereference () # Results in error
  324. py_val = py_ref.referenced_value () # Returns the referenced value
  325. </pre></div>
  326. <p>The <code>gdb.Value</code> object <code>py_val</code> is identical to that
  327. corresponding to <code>val</code>.
  328. </p></dd></dl>
  329. <dl>
  330. <dt><a name="index-Value_002ereference_005fvalue"></a>Function: <strong>Value.reference_value</strong> <em>()</em></dt>
  331. <dd><p>Return a <code>gdb.Value</code> object which is a reference to the value
  332. encapsulated by this instance.
  333. </p></dd></dl>
  334. <dl>
  335. <dt><a name="index-Value_002econst_005fvalue"></a>Function: <strong>Value.const_value</strong> <em>()</em></dt>
  336. <dd><p>Return a <code>gdb.Value</code> object which is a <code>const</code> version of the
  337. value encapsulated by this instance.
  338. </p></dd></dl>
  339. <dl>
  340. <dt><a name="index-Value_002edynamic_005fcast"></a>Function: <strong>Value.dynamic_cast</strong> <em>(type)</em></dt>
  341. <dd><p>Like <code>Value.cast</code>, but works as if the C<tt>++</tt> <code>dynamic_cast</code>
  342. operator were used. Consult a C<tt>++</tt> reference for details.
  343. </p></dd></dl>
  344. <dl>
  345. <dt><a name="index-Value_002ereinterpret_005fcast"></a>Function: <strong>Value.reinterpret_cast</strong> <em>(type)</em></dt>
  346. <dd><p>Like <code>Value.cast</code>, but works as if the C<tt>++</tt> <code>reinterpret_cast</code>
  347. operator were used. Consult a C<tt>++</tt> reference for details.
  348. </p></dd></dl>
  349. <dl>
  350. <dt><a name="index-Value_002eformat_005fstring"></a>Function: <strong>Value.format_string</strong> <em>(...)</em></dt>
  351. <dd><p>Convert a <code>gdb.Value</code> to a string, similarly to what the <code>print</code>
  352. command does. Invoked with no arguments, this is equivalent to calling
  353. the <code>str</code> function on the <code>gdb.Value</code>. The representation of
  354. the same value may change across different versions of <small>GDB</small>, so
  355. you shouldn&rsquo;t, for instance, parse the strings returned by this method.
  356. </p>
  357. <p>All the arguments are keyword only. If an argument is not specified, the
  358. current global default setting is used.
  359. </p>
  360. <dl compact="compact">
  361. <dt><code>raw</code></dt>
  362. <dd><p><code>True</code> if pretty-printers (see <a href="Pretty-Printing.html#Pretty-Printing">Pretty Printing</a>) should not be
  363. used to format the value. <code>False</code> if enabled pretty-printers
  364. matching the type represented by the <code>gdb.Value</code> should be used to
  365. format it.
  366. </p>
  367. </dd>
  368. <dt><code>pretty_arrays</code></dt>
  369. <dd><p><code>True</code> if arrays should be pretty printed to be more convenient to
  370. read, <code>False</code> if they shouldn&rsquo;t (see <code>set print array</code> in
  371. <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  372. </p>
  373. </dd>
  374. <dt><code>pretty_structs</code></dt>
  375. <dd><p><code>True</code> if structs should be pretty printed to be more convenient to
  376. read, <code>False</code> if they shouldn&rsquo;t (see <code>set print pretty</code> in
  377. <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  378. </p>
  379. </dd>
  380. <dt><code>array_indexes</code></dt>
  381. <dd><p><code>True</code> if array indexes should be included in the string
  382. representation of arrays, <code>False</code> if they shouldn&rsquo;t (see <code>set
  383. print array-indexes</code> in <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  384. </p>
  385. </dd>
  386. <dt><code>symbols</code></dt>
  387. <dd><p><code>True</code> if the string representation of a pointer should include the
  388. corresponding symbol name (if one exists), <code>False</code> if it shouldn&rsquo;t
  389. (see <code>set print symbol</code> in <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  390. </p>
  391. </dd>
  392. <dt><code>unions</code></dt>
  393. <dd><p><code>True</code> if unions which are contained in other structures or unions
  394. should be expanded, <code>False</code> if they shouldn&rsquo;t (see <code>set print
  395. union</code> in <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  396. </p>
  397. </dd>
  398. <dt><code>deref_refs</code></dt>
  399. <dd><p><code>True</code> if C<tt>++</tt> references should be resolved to the value they
  400. refer to, <code>False</code> (the default) if they shouldn&rsquo;t. Note that, unlike
  401. for the <code>print</code> command, references are not automatically expanded
  402. when using the <code>format_string</code> method or the <code>str</code>
  403. function. There is no global <code>print</code> setting to change the default
  404. behaviour.
  405. </p>
  406. </dd>
  407. <dt><code>actual_objects</code></dt>
  408. <dd><p><code>True</code> if the representation of a pointer to an object should
  409. identify the <em>actual</em> (derived) type of the object rather than the
  410. <em>declared</em> type, using the virtual function table. <code>False</code> if
  411. the <em>declared</em> type should be used. (See <code>set print object</code> in
  412. <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  413. </p>
  414. </dd>
  415. <dt><code>static_fields</code></dt>
  416. <dd><p><code>True</code> if static members should be included in the string
  417. representation of a C<tt>++</tt> object, <code>False</code> if they shouldn&rsquo;t (see
  418. <code>set print static-members</code> in <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  419. </p>
  420. </dd>
  421. <dt><code>max_elements</code></dt>
  422. <dd><p>Number of array elements to print, or <code>0</code> to print an unlimited
  423. number of elements (see <code>set print elements</code> in <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  424. </p>
  425. </dd>
  426. <dt><code>max_depth</code></dt>
  427. <dd><p>The maximum depth to print for nested structs and unions, or <code>-1</code>
  428. to print an unlimited number of elements (see <code>set print
  429. max-depth</code> in <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  430. </p>
  431. </dd>
  432. <dt><code>repeat_threshold</code></dt>
  433. <dd><p>Set the threshold for suppressing display of repeated array elements, or
  434. <code>0</code> to represent all elements, even if repeated. (See <code>set
  435. print repeats</code> in <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  436. </p>
  437. </dd>
  438. <dt><code>format</code></dt>
  439. <dd><p>A string containing a single character representing the format to use for
  440. the returned string. For instance, <code>'x'</code> is equivalent to using the
  441. <small>GDB</small> command <code>print</code> with the <code>/x</code> option and formats
  442. the value as a hexadecimal number.
  443. </p></dd>
  444. </dl>
  445. </dd></dl>
  446. <dl>
  447. <dt><a name="index-Value_002estring"></a>Function: <strong>Value.string</strong> <em>(<span class="roman">[</span>encoding<span class="roman">[</span>, errors<span class="roman">[</span>, length<span class="roman">]]]</span>)</em></dt>
  448. <dd><p>If this <code>gdb.Value</code> represents a string, then this method
  449. converts the contents to a Python string. Otherwise, this method will
  450. throw an exception.
  451. </p>
  452. <p>Values are interpreted as strings according to the rules of the
  453. current language. If the optional length argument is given, the
  454. string will be converted to that length, and will include any embedded
  455. zeroes that the string may contain. Otherwise, for languages
  456. where the string is zero-terminated, the entire string will be
  457. converted.
  458. </p>
  459. <p>For example, in C-like languages, a value is a string if it is a pointer
  460. to or an array of characters or ints of type <code>wchar_t</code>, <code>char16_t</code>,
  461. or <code>char32_t</code>.
  462. </p>
  463. <p>If the optional <var>encoding</var> argument is given, it must be a string
  464. naming the encoding of the string in the <code>gdb.Value</code>, such as
  465. <code>&quot;ascii&quot;</code>, <code>&quot;iso-8859-6&quot;</code> or <code>&quot;utf-8&quot;</code>. It accepts
  466. the same encodings as the corresponding argument to Python&rsquo;s
  467. <code>string.decode</code> method, and the Python codec machinery will be used
  468. to convert the string. If <var>encoding</var> is not given, or if
  469. <var>encoding</var> is the empty string, then either the <code>target-charset</code>
  470. (see <a href="Character-Sets.html#Character-Sets">Character Sets</a>) will be used, or a language-specific encoding
  471. will be used, if the current language is able to supply one.
  472. </p>
  473. <p>The optional <var>errors</var> argument is the same as the corresponding
  474. argument to Python&rsquo;s <code>string.decode</code> method.
  475. </p>
  476. <p>If the optional <var>length</var> argument is given, the string will be
  477. fetched and converted to the given length.
  478. </p></dd></dl>
  479. <dl>
  480. <dt><a name="index-Value_002elazy_005fstring"></a>Function: <strong>Value.lazy_string</strong> <em>(<span class="roman">[</span>encoding <span class="roman">[</span>, length<span class="roman">]]</span>)</em></dt>
  481. <dd><p>If this <code>gdb.Value</code> represents a string, then this method
  482. converts the contents to a <code>gdb.LazyString</code> (see <a href="Lazy-Strings-In-Python.html#Lazy-Strings-In-Python">Lazy Strings In Python</a>). Otherwise, this method will throw an exception.
  483. </p>
  484. <p>If the optional <var>encoding</var> argument is given, it must be a string
  485. naming the encoding of the <code>gdb.LazyString</code>. Some examples are:
  486. &lsquo;<samp>ascii</samp>&rsquo;, &lsquo;<samp>iso-8859-6</samp>&rsquo; or &lsquo;<samp>utf-8</samp>&rsquo;. If the
  487. <var>encoding</var> argument is an encoding that <small>GDB</small> does
  488. recognize, <small>GDB</small> will raise an error.
  489. </p>
  490. <p>When a lazy string is printed, the <small>GDB</small> encoding machinery is
  491. used to convert the string during printing. If the optional
  492. <var>encoding</var> argument is not provided, or is an empty string,
  493. <small>GDB</small> will automatically select the encoding most suitable for
  494. the string type. For further information on encoding in <small>GDB</small>
  495. please see <a href="Character-Sets.html#Character-Sets">Character Sets</a>.
  496. </p>
  497. <p>If the optional <var>length</var> argument is given, the string will be
  498. fetched and encoded to the length of characters specified. If
  499. the <var>length</var> argument is not provided, the string will be fetched
  500. and encoded until a null of appropriate width is found.
  501. </p></dd></dl>
  502. <dl>
  503. <dt><a name="index-Value_002efetch_005flazy"></a>Function: <strong>Value.fetch_lazy</strong> <em>()</em></dt>
  504. <dd><p>If the <code>gdb.Value</code> object is currently a lazy value
  505. (<code>gdb.Value.is_lazy</code> is <code>True</code>), then the value is
  506. fetched from the inferior. Any errors that occur in the process
  507. will produce a Python exception.
  508. </p>
  509. <p>If the <code>gdb.Value</code> object is not a lazy value, this method
  510. has no effect.
  511. </p>
  512. <p>This method does not return a value.
  513. </p></dd></dl>
  514. <hr>
  515. <div class="header">
  516. <p>
  517. Next: <a href="Types-In-Python.html#Types-In-Python" accesskey="n" rel="next">Types In Python</a>, Previous: <a href="Exception-Handling.html#Exception-Handling" accesskey="p" rel="prev">Exception Handling</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</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>
  518. </div>
  519. </body>
  520. </html>