Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

190 Zeilen
9.3KB

  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>Pretty Printing API (Debugging with GDB)</title>
  17. <meta name="description" content="Pretty Printing API (Debugging with GDB)">
  18. <meta name="keywords" content="Pretty Printing API (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="Selecting-Pretty_002dPrinters.html#Selecting-Pretty_002dPrinters" rel="next" title="Selecting Pretty-Printers">
  27. <link href="Types-In-Python.html#Types-In-Python" rel="prev" title="Types In Python">
  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="Pretty-Printing-API"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Selecting-Pretty_002dPrinters.html#Selecting-Pretty_002dPrinters" accesskey="n" rel="next">Selecting Pretty-Printers</a>, Previous: <a href="Types-In-Python.html#Types-In-Python" accesskey="p" rel="prev">Types In Python</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="Pretty-Printing-API-1"></a>
  64. <h4 class="subsubsection">23.2.2.5 Pretty Printing API</h4>
  65. <a name="index-python-pretty-printing-api"></a>
  66. <p>A pretty-printer is just an object that holds a value and implements a
  67. specific interface, defined here. An example output is provided
  68. (see <a href="Pretty-Printing.html#Pretty-Printing">Pretty Printing</a>).
  69. </p>
  70. <dl>
  71. <dt><a name="index-pretty_005fprinter_002echildren"></a>Function: <strong>pretty_printer.children</strong> <em>(self)</em></dt>
  72. <dd><p><small>GDB</small> will call this method on a pretty-printer to compute the
  73. children of the pretty-printer&rsquo;s value.
  74. </p>
  75. <p>This method must return an object conforming to the Python iterator
  76. protocol. Each item returned by the iterator must be a tuple holding
  77. two elements. The first element is the &ldquo;name&rdquo; of the child; the
  78. second element is the child&rsquo;s value. The value can be any Python
  79. object which is convertible to a <small>GDB</small> value.
  80. </p>
  81. <p>This method is optional. If it does not exist, <small>GDB</small> will act
  82. as though the value has no children.
  83. </p>
  84. <p>For efficiency, the <code>children</code> method should lazily compute its
  85. results. This will let <small>GDB</small> read as few elements as
  86. necessary, for example when various print settings (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>) or <code>-var-list-children</code> (see <a href="GDB_002fMI-Variable-Objects.html#GDB_002fMI-Variable-Objects">GDB/MI Variable Objects</a>) limit the number of elements to be displayed.
  87. </p>
  88. <p>Children may be hidden from display based on the value of &lsquo;<samp>set
  89. print max-depth</samp>&rsquo; (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  90. </p></dd></dl>
  91. <dl>
  92. <dt><a name="index-pretty_005fprinter_002edisplay_005fhint"></a>Function: <strong>pretty_printer.display_hint</strong> <em>(self)</em></dt>
  93. <dd><p>The CLI may call this method and use its result to change the
  94. formatting of a value. The result will also be supplied to an MI
  95. consumer as a &lsquo;<samp>displayhint</samp>&rsquo; attribute of the variable being
  96. printed.
  97. </p>
  98. <p>This method is optional. If it does exist, this method must return a
  99. string or the special value <code>None</code>.
  100. </p>
  101. <p>Some display hints are predefined by <small>GDB</small>:
  102. </p>
  103. <dl compact="compact">
  104. <dt>&lsquo;<samp>array</samp>&rsquo;</dt>
  105. <dd><p>Indicate that the object being printed is &ldquo;array-like&rdquo;. The CLI
  106. uses this to respect parameters such as <code>set print elements</code> and
  107. <code>set print array</code>.
  108. </p>
  109. </dd>
  110. <dt>&lsquo;<samp>map</samp>&rsquo;</dt>
  111. <dd><p>Indicate that the object being printed is &ldquo;map-like&rdquo;, and that the
  112. children of this value can be assumed to alternate between keys and
  113. values.
  114. </p>
  115. </dd>
  116. <dt>&lsquo;<samp>string</samp>&rsquo;</dt>
  117. <dd><p>Indicate that the object being printed is &ldquo;string-like&rdquo;. If the
  118. printer&rsquo;s <code>to_string</code> method returns a Python string of some
  119. kind, then <small>GDB</small> will call its internal language-specific
  120. string-printing function to format the string. For the CLI this means
  121. adding quotation marks, possibly escaping some characters, respecting
  122. <code>set print elements</code>, and the like.
  123. </p></dd>
  124. </dl>
  125. <p>The special value <code>None</code> causes <small>GDB</small> to apply the default
  126. display rules.
  127. </p></dd></dl>
  128. <dl>
  129. <dt><a name="index-pretty_005fprinter_002eto_005fstring"></a>Function: <strong>pretty_printer.to_string</strong> <em>(self)</em></dt>
  130. <dd><p><small>GDB</small> will call this method to display the string
  131. representation of the value passed to the object&rsquo;s constructor.
  132. </p>
  133. <p>When printing from the CLI, if the <code>to_string</code> method exists,
  134. then <small>GDB</small> will prepend its result to the values returned by
  135. <code>children</code>. Exactly how this formatting is done is dependent on
  136. the display hint, and may change as more hints are added. Also,
  137. depending on the print settings (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>), the CLI may
  138. print just the result of <code>to_string</code> in a stack trace, omitting
  139. the result of <code>children</code>.
  140. </p>
  141. <p>If this method returns a string, it is printed verbatim.
  142. </p>
  143. <p>Otherwise, if this method returns an instance of <code>gdb.Value</code>,
  144. then <small>GDB</small> prints this value. This may result in a call to
  145. another pretty-printer.
  146. </p>
  147. <p>If instead the method returns a Python value which is convertible to a
  148. <code>gdb.Value</code>, then <small>GDB</small> performs the conversion and prints
  149. the resulting value. Again, this may result in a call to another
  150. pretty-printer. Python scalars (integers, floats, and booleans) and
  151. strings are convertible to <code>gdb.Value</code>; other types are not.
  152. </p>
  153. <p>Finally, if this method returns <code>None</code> then no further operations
  154. are peformed in this method and nothing is printed.
  155. </p>
  156. <p>If the result is not one of these types, an exception is raised.
  157. </p></dd></dl>
  158. <p><small>GDB</small> provides a function which can be used to look up the
  159. default pretty-printer for a <code>gdb.Value</code>:
  160. </p>
  161. <a name="index-gdb_002edefault_005fvisualizer"></a>
  162. <dl>
  163. <dt><a name="index-gdb_002edefault_005fvisualizer-1"></a>Function: <strong>gdb.default_visualizer</strong> <em>(value)</em></dt>
  164. <dd><p>This function takes a <code>gdb.Value</code> object as an argument. If a
  165. pretty-printer for this value exists, then it is returned. If no such
  166. printer exists, then this returns <code>None</code>.
  167. </p></dd></dl>
  168. <hr>
  169. <div class="header">
  170. <p>
  171. Next: <a href="Selecting-Pretty_002dPrinters.html#Selecting-Pretty_002dPrinters" accesskey="n" rel="next">Selecting Pretty-Printers</a>, Previous: <a href="Types-In-Python.html#Types-In-Python" accesskey="p" rel="prev">Types In Python</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>
  172. </div>
  173. </body>
  174. </html>