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