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: Output</title>
18
19<meta name="description" content="Debugging with GDB: Output">
20<meta name="keywords" content="Debugging with GDB: Output">
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="Sequences.html#Sequences" rel="up" title="Sequences">
29<link href="Auto_002dloading-sequences.html#Auto_002dloading-sequences" rel="next" title="Auto-loading sequences">
30<link href="Command-Files.html#Command-Files" rel="previous" title="Command Files">
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="Output"></a>
65<div class="header">
66<p>
67Next: <a href="Auto_002dloading-sequences.html#Auto_002dloading-sequences" accesskey="n" rel="next">Auto-loading sequences</a>, Previous: <a href="Command-Files.html#Command-Files" accesskey="p" rel="previous">Command Files</a>, Up: <a href="Sequences.html#Sequences" accesskey="u" rel="up">Sequences</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="Commands-for-Controlled-Output"></a>
71<h4 class="subsection">23.1.4 Commands for Controlled Output</h4>
72
73<p>During the execution of a command file or a user-defined command, normal
74<small>GDB</small> output is suppressed; the only output that appears is what is
75explicitly printed by the commands in the definition.  This section
76describes three commands useful for generating exactly the output you
77want.
78</p>
79<dl compact="compact">
80<dd><a name="index-echo"></a>
81</dd>
82<dt><code>echo <var>text</var></code></dt>
83<dd><p>Print <var>text</var>.  Nonprinting characters can be included in
84<var>text</var> using C escape sequences, such as &lsquo;<samp>\n</samp>&rsquo; to print a
85newline.  <strong>No newline is printed unless you specify one.</strong>
86In addition to the standard C escape sequences, a backslash followed
87by a space stands for a space.  This is useful for displaying a
88string with spaces at the beginning or the end, since leading and
89trailing spaces are otherwise trimmed from all arguments.
90To print &lsquo;<samp>&nbsp;<!-- /@w -->and foo =&nbsp;<!-- /@w --></samp>&rsquo;, use the command
91&lsquo;<samp>echo \&nbsp;<!-- /@w -->and foo = \&nbsp;<!-- /@w --></samp>&rsquo;.
92</p>
93<p>A backslash at the end of <var>text</var> can be used, as in C, to continue
94the command onto subsequent lines.  For example,
95</p>
96<div class="smallexample">
97<pre class="smallexample">echo This is some text\n\
98which is continued\n\
99onto several lines.\n
100</pre></div>
101
102<p>produces the same output as
103</p>
104<div class="smallexample">
105<pre class="smallexample">echo This is some text\n
106echo which is continued\n
107echo onto several lines.\n
108</pre></div>
109
110<a name="index-output"></a>
111</dd>
112<dt><code>output <var>expression</var></code></dt>
113<dd><p>Print the value of <var>expression</var> and nothing but that value: no
114newlines, no &lsquo;<samp>$<var>nn</var> = </samp>&rsquo;.  The value is not entered in the
115value history either.  See <a href="Expressions.html#Expressions">Expressions</a>, for more information
116on expressions.
117</p>
118</dd>
119<dt><code>output/<var>fmt</var> <var>expression</var></code></dt>
120<dd><p>Print the value of <var>expression</var> in format <var>fmt</var>.  You can use
121the same formats as for <code>print</code>.  See <a href="Output-Formats.html#Output-Formats">Output
122Formats</a>, for more information.
123</p>
124<a name="index-printf"></a>
125</dd>
126<dt><code>printf <var>template</var>, <var>expressions</var>&hellip;</code></dt>
127<dd><p>Print the values of one or more <var>expressions</var> under the control of
128the string <var>template</var>.  To print several values, make
129<var>expressions</var> be a comma-separated list of individual expressions,
130which may be either numbers or pointers.  Their values are printed as
131specified by <var>template</var>, exactly as a C program would do by
132executing the code below:
133</p>
134<div class="smallexample">
135<pre class="smallexample">printf (<var>template</var>, <var>expressions</var>&hellip;);
136</pre></div>
137
138<p>As in <code>C</code> <code>printf</code>, ordinary characters in <var>template</var>
139are printed verbatim, while <em>conversion specification</em> introduced
140by the &lsquo;<samp>%</samp>&rsquo; character cause subsequent <var>expressions</var> to be
141evaluated, their values converted and formatted according to type and
142style information encoded in the conversion specifications, and then
143printed.
144</p>
145<p>For example, you can print two values in hex like this:
146</p>
147<div class="smallexample">
148<pre class="smallexample">printf &quot;foo, bar-foo = 0x%x, 0x%x\n&quot;, foo, bar-foo
149</pre></div>
150
151<p><code>printf</code> supports all the standard <code>C</code> conversion
152specifications, including the flags and modifiers between the &lsquo;<samp>%</samp>&rsquo;
153character and the conversion letter, with the following exceptions:
154</p>
155<ul>
156<li> The argument-ordering modifiers, such as &lsquo;<samp>2$</samp>&rsquo;, are not supported.
157
158</li><li> The modifier &lsquo;<samp>*</samp>&rsquo; is not supported for specifying precision or
159width.
160
161</li><li> The &lsquo;<samp>'</samp>&rsquo; flag (for separation of digits into groups according to
162<code>LC_NUMERIC'</code>) is not supported.
163
164</li><li> The type modifiers &lsquo;<samp>hh</samp>&rsquo;, &lsquo;<samp>j</samp>&rsquo;, &lsquo;<samp>t</samp>&rsquo;, and &lsquo;<samp>z</samp>&rsquo; are not
165supported.
166
167</li><li> The conversion letter &lsquo;<samp>n</samp>&rsquo; (as in &lsquo;<samp>%n</samp>&rsquo;) is not supported.
168
169</li><li> The conversion letters &lsquo;<samp>a</samp>&rsquo; and &lsquo;<samp>A</samp>&rsquo; are not supported.
170</li></ul>
171
172<p>Note that the &lsquo;<samp>ll</samp>&rsquo; type modifier is supported only if the
173underlying <code>C</code> implementation used to build <small>GDB</small> supports
174the <code>long long int</code> type, and the &lsquo;<samp>L</samp>&rsquo; type modifier is
175supported only if <code>long double</code> type is available.
176</p>
177<p>As in <code>C</code>, <code>printf</code> supports simple backslash-escape
178sequences, such as <code>\n</code>, &lsquo;<samp>\t</samp>&rsquo;, &lsquo;<samp>\\</samp>&rsquo;, &lsquo;<samp>\&quot;</samp>&rsquo;,
179&lsquo;<samp>\a</samp>&rsquo;, and &lsquo;<samp>\f</samp>&rsquo;, that consist of backslash followed by a
180single character.  Octal and hexadecimal escape sequences are not
181supported.
182</p>
183<p>Additionally, <code>printf</code> supports conversion specifications for DFP
184(<em>Decimal Floating Point</em>) types using the following length modifiers
185together with a floating point specifier.
186letters:
187</p>
188<ul>
189<li> &lsquo;<samp>H</samp>&rsquo; for printing <code>Decimal32</code> types.
190
191</li><li> &lsquo;<samp>D</samp>&rsquo; for printing <code>Decimal64</code> types.
192
193</li><li> &lsquo;<samp>DD</samp>&rsquo; for printing <code>Decimal128</code> types.
194</li></ul>
195
196<p>If the underlying <code>C</code> implementation used to build <small>GDB</small> has
197support for the three length modifiers for DFP types, other modifiers
198such as width and precision will also be available for <small>GDB</small> to use.
199</p>
200<p>In case there is no such <code>C</code> support, no additional modifiers will be
201available and the value will be printed in the standard way.
202</p>
203<p>Here&rsquo;s an example of printing DFP types using the above conversion letters:
204</p><div class="smallexample">
205<pre class="smallexample">printf &quot;D32: %Hf - D64: %Df - D128: %DDf\n&quot;,1.2345df,1.2E10dd,1.2E1dl
206</pre></div>
207
208<a name="eval"></a><a name="index-eval"></a>
209</dd>
210<dt><code>eval <var>template</var>, <var>expressions</var>&hellip;</code></dt>
211<dd><p>Convert the values of one or more <var>expressions</var> under the control of
212the string <var>template</var> to a command line, and call it.
213</p>
214</dd>
215</dl>
216
217<hr>
218<div class="header">
219<p>
220Next: <a href="Auto_002dloading-sequences.html#Auto_002dloading-sequences" accesskey="n" rel="next">Auto-loading sequences</a>, Previous: <a href="Command-Files.html#Command-Files" accesskey="p" rel="previous">Command Files</a>, Up: <a href="Sequences.html#Sequences" accesskey="u" rel="up">Sequences</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>
221</div>
222
223
224
225</body>
226</html>
227