Guile-Pretty-Printing-API.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Guile Pretty Printing API</title>
  16. <meta name="description" content="Debugging with GDB: Guile Pretty Printing API">
  17. <meta name="keywords" content="Debugging with GDB: Guile Pretty Printing API">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="previous" title="Types In Guile">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Guile-Pretty-Printing-API"></a>
  59. <div class="header">
  60. <p>
  61. 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="previous">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>
  62. </div>
  63. <hr>
  64. <a name="Guile-Pretty-Printing-API-1"></a>
  65. <h4 class="subsubsection">23.3.3.8 Guile Pretty Printing API</h4>
  66. <a name="index-guile-pretty-printing-api"></a>
  67. <p>An example output is provided (see <a href="Pretty-Printing.html#Pretty-Printing">Pretty Printing</a>).
  68. </p>
  69. <p>A pretty-printer is represented by an object of type &lt;gdb:pretty-printer&gt;.
  70. Pretty-printer objects are created with <code>make-pretty-printer</code>.
  71. </p>
  72. <p>The following pretty-printer-related procedures are provided by the
  73. <code>(gdb)</code> module:
  74. </p>
  75. <dl>
  76. <dt><a name="index-make_002dpretty_002dprinter"></a>Scheme Procedure: <strong>make-pretty-printer</strong> <em>name lookup-function</em></dt>
  77. <dd><p>Return a <code>&lt;gdb:pretty-printer&gt;</code> object named <var>name</var>.
  78. </p>
  79. <p><var>lookup-function</var> is a function of one parameter: the value to
  80. be printed. If the value is handled by this pretty-printer, then
  81. <var>lookup-function</var> returns an object of type
  82. &lt;gdb:pretty-printer-worker&gt; to perform the actual pretty-printing.
  83. Otherwise <var>lookup-function</var> returns <code>#f</code>.
  84. </p></dd></dl>
  85. <dl>
  86. <dt><a name="index-pretty_002dprinter_003f"></a>Scheme Procedure: <strong>pretty-printer?</strong> <em>object</em></dt>
  87. <dd><p>Return <code>#t</code> if <var>object</var> is a <code>&lt;gdb:pretty-printer&gt;</code> object.
  88. Otherwise return <code>#f</code>.
  89. </p></dd></dl>
  90. <dl>
  91. <dt><a name="index-pretty_002dprinter_002denabled_003f"></a>Scheme Procedure: <strong>pretty-printer-enabled?</strong> <em>pretty-printer</em></dt>
  92. <dd><p>Return <code>#t</code> if <var>pretty-printer</var> is enabled.
  93. Otherwise return <code>#f</code>.
  94. </p></dd></dl>
  95. <dl>
  96. <dt><a name="index-set_002dpretty_002dprinter_002denabled_0021"></a>Scheme Procedure: <strong>set-pretty-printer-enabled!</strong> <em>pretty-printer flag</em></dt>
  97. <dd><p>Set the enabled flag of <var>pretty-printer</var> to <var>flag</var>.
  98. The value returned is unspecified.
  99. </p></dd></dl>
  100. <dl>
  101. <dt><a name="index-pretty_002dprinters"></a>Scheme Procedure: <strong>pretty-printers</strong></dt>
  102. <dd><p>Return the list of global pretty-printers.
  103. </p></dd></dl>
  104. <dl>
  105. <dt><a name="index-set_002dpretty_002dprinters_0021"></a>Scheme Procedure: <strong>set-pretty-printers!</strong> <em>pretty-printers</em></dt>
  106. <dd><p>Set the list of global pretty-printers to <var>pretty-printers</var>.
  107. The value returned is unspecified.
  108. </p></dd></dl>
  109. <dl>
  110. <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>
  111. <dd><p>Return an object of type <code>&lt;gdb:pretty-printer-worker&gt;</code>.
  112. </p>
  113. <p>This function takes three parameters:
  114. </p>
  115. <dl compact="compact">
  116. <dt>&lsquo;<samp>display-hint</samp>&rsquo;</dt>
  117. <dd><p><var>display-hint</var> provides a hint to <small>GDB</small> or <small>GDB</small>
  118. front end via MI to change the formatting of the value being printed.
  119. The value must be a string or <code>#f</code> (meaning there is no hint).
  120. Several values for <var>display-hint</var>
  121. are predefined by <small>GDB</small>:
  122. </p>
  123. <dl compact="compact">
  124. <dt>&lsquo;<samp>array</samp>&rsquo;</dt>
  125. <dd><p>Indicate that the object being printed is &ldquo;array-like&rdquo;. The CLI
  126. uses this to respect parameters such as <code>set print elements</code> and
  127. <code>set print array</code>.
  128. </p>
  129. </dd>
  130. <dt>&lsquo;<samp>map</samp>&rsquo;</dt>
  131. <dd><p>Indicate that the object being printed is &ldquo;map-like&rdquo;, and that the
  132. children of this value can be assumed to alternate between keys and
  133. values.
  134. </p>
  135. </dd>
  136. <dt>&lsquo;<samp>string</samp>&rsquo;</dt>
  137. <dd><p>Indicate that the object being printed is &ldquo;string-like&rdquo;. If the
  138. printer&rsquo;s <code>to-string</code> function returns a Guile string of some
  139. kind, then <small>GDB</small> will call its internal language-specific
  140. string-printing function to format the string. For the CLI this means
  141. adding quotation marks, possibly escaping some characters, respecting
  142. <code>set print elements</code>, and the like.
  143. </p></dd>
  144. </dl>
  145. </dd>
  146. <dt>&lsquo;<samp>to-string</samp>&rsquo;</dt>
  147. <dd><p><var>to-string</var> is either a function of one parameter, the
  148. <code>&lt;gdb:pretty-printer-worker&gt;</code> object, or <code>#f</code>.
  149. </p>
  150. <p>When printing from the CLI, if the <code>to-string</code> method exists,
  151. then <small>GDB</small> will prepend its result to the values returned by
  152. <code>children</code>. Exactly how this formatting is done is dependent on
  153. the display hint, and may change as more hints are added. Also,
  154. depending on the print settings (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>), the CLI may
  155. print just the result of <code>to-string</code> in a stack trace, omitting
  156. the result of <code>children</code>.
  157. </p>
  158. <p>If this method returns a string, it is printed verbatim.
  159. </p>
  160. <p>Otherwise, if this method returns an instance of <code>&lt;gdb:value&gt;</code>,
  161. then <small>GDB</small> prints this value. This may result in a call to
  162. another pretty-printer.
  163. </p>
  164. <p>If instead the method returns a Guile value which is convertible to a
  165. <code>&lt;gdb:value&gt;</code>, then <small>GDB</small> performs the conversion and prints
  166. the resulting value. Again, this may result in a call to another
  167. pretty-printer. Guile scalars (integers, floats, and booleans) and
  168. strings are convertible to <code>&lt;gdb:value&gt;</code>; other types are not.
  169. </p>
  170. <p>Finally, if this method returns <code>#f</code> then no further operations
  171. are peformed in this method and nothing is printed.
  172. </p>
  173. <p>If the result is not one of these types, an exception is raised.
  174. </p>
  175. <p><var>to-string</var> may also be <code>#f</code> in which case it is left to
  176. <var>children</var> to print the value.
  177. </p>
  178. </dd>
  179. <dt>&lsquo;<samp>children</samp>&rsquo;</dt>
  180. <dd><p><var>children</var> is either a function of one parameter, the
  181. <code>&lt;gdb:pretty-printer-worker&gt;</code> object, or <code>#f</code>.
  182. </p>
  183. <p><small>GDB</small> will call this function on a pretty-printer to compute the
  184. children of the pretty-printer&rsquo;s value.
  185. </p>
  186. <p>This function must return a &lt;gdb:iterator&gt; object.
  187. Each item returned by the iterator must be a tuple holding
  188. two elements. The first element is the &ldquo;name&rdquo; of the child; the
  189. second element is the child&rsquo;s value. The value can be any Guile
  190. object which is convertible to a <small>GDB</small> value.
  191. </p>
  192. <p>If <var>children</var> is <code>#f</code>, <small>GDB</small> will act
  193. as though the value has no children.
  194. </p>
  195. <p>Children may be hidden from display based on the value of &lsquo;<samp>set
  196. print max-depth</samp>&rsquo; (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>).
  197. </p></dd>
  198. </dl>
  199. </dd></dl>
  200. <p><small>GDB</small> provides a function which can be used to look up the
  201. default pretty-printer for a <code>&lt;gdb:value&gt;</code>:
  202. </p>
  203. <dl>
  204. <dt><a name="index-default_002dvisualizer"></a>Scheme Procedure: <strong>default-visualizer</strong> <em>value</em></dt>
  205. <dd><p>This function takes a <code>&lt;gdb:value&gt;</code> object as an argument. If a
  206. pretty-printer for this value exists, then it is returned. If no such
  207. printer exists, then this returns <code>#f</code>.
  208. </p></dd></dl>
  209. <hr>
  210. <div class="header">
  211. <p>
  212. 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="previous">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>
  213. </div>
  214. </body>
  215. </html>