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.

234 lines
11KB

  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>Guile Pretty Printing API (Debugging with GDB)</title>
  17. <meta name="description" content="Guile Pretty Printing API (Debugging with GDB)">
  18. <meta name="keywords" content="Guile 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="Guile-API.html#Guile-API" rel="up" title="Guile API">
  26. <link href="Selecting-Guile-Pretty_002dPrinters.html#Selecting-Guile-Pretty_002dPrinters" rel="next" title="Selecting Guile Pretty-Printers">
  27. <link href="Types-In-Guile.html#Types-In-Guile" rel="prev" title="Types In Guile">
  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="Guile-Pretty-Printing-API"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Selecting-Guile-Pretty_002dPrinters.html#Selecting-Guile-Pretty_002dPrinters" accesskey="n" rel="next">Selecting Guile Pretty-Printers</a>, Previous: <a href="Types-In-Guile.html#Types-In-Guile" accesskey="p" rel="prev">Types In Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile 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="Guile-Pretty-Printing-API-1"></a>
  64. <h4 class="subsubsection">23.3.3.8 Guile Pretty Printing API</h4>
  65. <a name="index-guile-pretty-printing-api"></a>
  66. <p>An example output is provided (see <a href="Pretty-Printing.html#Pretty-Printing">Pretty Printing</a>).
  67. </p>
  68. <p>A pretty-printer is represented by an object of type &lt;gdb:pretty-printer&gt;.
  69. Pretty-printer objects are created with <code>make-pretty-printer</code>.
  70. </p>
  71. <p>The following pretty-printer-related procedures are provided by the
  72. <code>(gdb)</code> module:
  73. </p>
  74. <dl>
  75. <dt><a name="index-make_002dpretty_002dprinter"></a>Scheme Procedure: <strong>make-pretty-printer</strong> <em>name lookup-function</em></dt>
  76. <dd><p>Return a <code>&lt;gdb:pretty-printer&gt;</code> object named <var>name</var>.
  77. </p>
  78. <p><var>lookup-function</var> is a function of one parameter: the value to
  79. be printed. If the value is handled by this pretty-printer, then
  80. <var>lookup-function</var> returns an object of type
  81. &lt;gdb:pretty-printer-worker&gt; to perform the actual pretty-printing.
  82. Otherwise <var>lookup-function</var> returns <code>#f</code>.
  83. </p></dd></dl>
  84. <dl>
  85. <dt><a name="index-pretty_002dprinter_003f"></a>Scheme Procedure: <strong>pretty-printer?</strong> <em>object</em></dt>
  86. <dd><p>Return <code>#t</code> if <var>object</var> is a <code>&lt;gdb:pretty-printer&gt;</code> object.
  87. Otherwise return <code>#f</code>.
  88. </p></dd></dl>
  89. <dl>
  90. <dt><a name="index-pretty_002dprinter_002denabled_003f"></a>Scheme Procedure: <strong>pretty-printer-enabled?</strong> <em>pretty-printer</em></dt>
  91. <dd><p>Return <code>#t</code> if <var>pretty-printer</var> is enabled.
  92. Otherwise return <code>#f</code>.
  93. </p></dd></dl>
  94. <dl>
  95. <dt><a name="index-set_002dpretty_002dprinter_002denabled_0021"></a>Scheme Procedure: <strong>set-pretty-printer-enabled!</strong> <em>pretty-printer flag</em></dt>
  96. <dd><p>Set the enabled flag of <var>pretty-printer</var> to <var>flag</var>.
  97. The value returned is unspecified.
  98. </p></dd></dl>
  99. <dl>
  100. <dt><a name="index-pretty_002dprinters"></a>Scheme Procedure: <strong>pretty-printers</strong></dt>
  101. <dd><p>Return the list of global pretty-printers.
  102. </p></dd></dl>
  103. <dl>
  104. <dt><a name="index-set_002dpretty_002dprinters_0021"></a>Scheme Procedure: <strong>set-pretty-printers!</strong> <em>pretty-printers</em></dt>
  105. <dd><p>Set the list of global pretty-printers to <var>pretty-printers</var>.
  106. The value returned is unspecified.
  107. </p></dd></dl>
  108. <dl>
  109. <dt><a name="index-make_002dpretty_002dprinter_002dworker"></a>Scheme Procedure: <strong>make-pretty-printer-worker</strong> <em>display-hint to-string children</em></dt>
  110. <dd><p>Return an object of type <code>&lt;gdb:pretty-printer-worker&gt;</code>.
  111. </p>
  112. <p>This function takes three parameters:
  113. </p>
  114. <dl compact="compact">
  115. <dt>&lsquo;<samp>display-hint</samp>&rsquo;</dt>
  116. <dd><p><var>display-hint</var> provides a hint to <small>GDB</small> or <small>GDB</small>
  117. front end via MI to change the formatting of the value being printed.
  118. The value must be a string or <code>#f</code> (meaning there is no hint).
  119. Several values for <var>display-hint</var>
  120. are predefined by <small>GDB</small>:
  121. </p>
  122. <dl compact="compact">
  123. <dt>&lsquo;<samp>array</samp>&rsquo;</dt>
  124. <dd><p>Indicate that the object being printed is &ldquo;array-like&rdquo;. The CLI
  125. uses this to respect parameters such as <code>set print elements</code> and
  126. <code>set print array</code>.
  127. </p>
  128. </dd>
  129. <dt>&lsquo;<samp>map</samp>&rsquo;</dt>
  130. <dd><p>Indicate that the object being printed is &ldquo;map-like&rdquo;, and that the
  131. children of this value can be assumed to alternate between keys and
  132. values.
  133. </p>
  134. </dd>
  135. <dt>&lsquo;<samp>string</samp>&rsquo;</dt>
  136. <dd><p>Indicate that the object being printed is &ldquo;string-like&rdquo;. If the
  137. printer&rsquo;s <code>to-string</code> function returns a Guile string of some
  138. kind, then <small>GDB</small> will call its internal language-specific
  139. string-printing function to format the string. For the CLI this means
  140. adding quotation marks, possibly escaping some characters, respecting
  141. <code>set print elements</code>, and the like.
  142. </p></dd>
  143. </dl>
  144. </dd>
  145. <dt>&lsquo;<samp>to-string</samp>&rsquo;</dt>
  146. <dd><p><var>to-string</var> is either a function of one parameter, the
  147. <code>&lt;gdb:pretty-printer-worker&gt;</code> object, or <code>#f</code>.
  148. </p>
  149. <p>When printing from the CLI, if the <code>to-string</code> method exists,
  150. then <small>GDB</small> will prepend its result to the values returned by
  151. <code>children</code>. Exactly how this formatting is done is dependent on
  152. the display hint, and may change as more hints are added. Also,
  153. depending on the print settings (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>), the CLI may
  154. print just the result of <code>to-string</code> in a stack trace, omitting
  155. the result of <code>children</code>.
  156. </p>
  157. <p>If this method returns a string, it is printed verbatim.
  158. </p>
  159. <p>Otherwise, if this method returns an instance of <code>&lt;gdb:value&gt;</code>,
  160. then <small>GDB</small> prints this value. This may result in a call to
  161. another pretty-printer.
  162. </p>
  163. <p>If instead the method returns a Guile value which is convertible to a
  164. <code>&lt;gdb:value&gt;</code>, then <small>GDB</small> performs the conversion and prints
  165. the resulting value. Again, this may result in a call to another
  166. pretty-printer. Guile scalars (integers, floats, and booleans) and
  167. strings are convertible to <code>&lt;gdb:value&gt;</code>; other types are not.
  168. </p>
  169. <p>Finally, if this method returns <code>#f</code> then no further operations
  170. are peformed in this method and nothing is printed.
  171. </p>
  172. <p>If the result is not one of these types, an exception is raised.
  173. </p>
  174. <p><var>to-string</var> may also be <code>#f</code> in which case it is left to
  175. <var>children</var> to print the value.
  176. </p>
  177. </dd>
  178. <dt>&lsquo;<samp>children</samp>&rsquo;</dt>
  179. <dd><p><var>children</var> is either a function of one parameter, the
  180. <code>&lt;gdb:pretty-printer-worker&gt;</code> object, or <code>#f</code>.
  181. </p>
  182. <p><small>GDB</small> will call this function on a pretty-printer to compute the
  183. children of the pretty-printer&rsquo;s value.
  184. </p>
  185. <p>This function must return a &lt;gdb:iterator&gt; object.
  186. Each item returned by the iterator must be a tuple holding
  187. two elements. The first element is the &ldquo;name&rdquo; of the child; the
  188. second element is the child&rsquo;s value. The value can be any Guile
  189. object which is convertible to a <small>GDB</small> value.
  190. </p>
  191. <p>If <var>children</var> is <code>#f</code>, <small>GDB</small> will act
  192. as though the value has no children.
  193. </p>
  194. <p>Children may be hidden from display based on the value of &lsquo;<samp>set
  195. print max-depth</samp>&rsquo; (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  196. </p></dd>
  197. </dl>
  198. </dd></dl>
  199. <p><small>GDB</small> provides a function which can be used to look up the
  200. default pretty-printer for a <code>&lt;gdb:value&gt;</code>:
  201. </p>
  202. <dl>
  203. <dt><a name="index-default_002dvisualizer"></a>Scheme Procedure: <strong>default-visualizer</strong> <em>value</em></dt>
  204. <dd><p>This function takes a <code>&lt;gdb:value&gt;</code> object as an argument. If a
  205. pretty-printer for this value exists, then it is returned. If no such
  206. printer exists, then this returns <code>#f</code>.
  207. </p></dd></dl>
  208. <hr>
  209. <div class="header">
  210. <p>
  211. Next: <a href="Selecting-Guile-Pretty_002dPrinters.html#Selecting-Guile-Pretty_002dPrinters" accesskey="n" rel="next">Selecting Guile Pretty-Printers</a>, Previous: <a href="Types-In-Guile.html#Types-In-Guile" accesskey="p" rel="prev">Types In Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile 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>
  212. </div>
  213. </body>
  214. </html>