Previous: Command Files, Up: Sequences
During the execution of a command file or a user-defined command, normal gdb output is suppressed; the only output that appears is what is explicitly printed by the commands in the definition. This section describes three commands useful for generating exactly the output you want.
echo textA backslash at the end of text can be used, as in C, to continue the command onto subsequent lines. For example,
echo This is some text\n\
which is continued\n\
onto several lines.\n
produces the same output as
echo This is some text\n
echo which is continued\n
echo onto several lines.\n
output expressionoutput/fmt expressionprint. See Output Formats, for more information.
printf template, expressions...printf (template, expressions...);
As in C printf, ordinary characters in template
are printed verbatim, while conversion specification introduced
by the ‘%’ character cause subsequent expressions to be
evaluated, their values converted and formatted according to type and
style information encoded in the conversion specifications, and then
printed.
For example, you can print two values in hex like this:
printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
printf supports all the standard C conversion
specifications, including the flags and modifiers between the ‘%’
character and the conversion letter, with the following exceptions:
LC_NUMERIC') is not supported.
Note that the ‘ll’ type modifier is supported only if the
underlying C implementation used to build gdb supports
the long long int type, and the ‘L’ type modifier is
supported only if long double type is available.
As in C, printf supports simple backslash-escape
sequences, such as \n, ‘\t’, ‘\\’, ‘\"’,
‘\a’, and ‘\f’, that consist of backslash followed by a
single character. Octal and hexadecimal escape sequences are not
supported.
Additionally, printf supports conversion specifications for DFP
(Decimal Floating Point) types using the following length modifiers
together with a floating point specifier.
letters:
Decimal32 types.
Decimal64 types.
Decimal128 types.
If the underlying C implementation used to build gdb has
support for the three length modifiers for DFP types, other modifiers
such as width and precision will also be available for gdb to use.
In case there is no such C support, no additional modifiers will be
available and the value will be printed in the standard way.
Here's an example of printing DFP types using the above conversion letters:
printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl