Next: Auto-loading sequences, Previous: Command Files, Up: Sequences [Contents][Index]
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 text
Print text. Nonprinting characters can be included in text using C escape sequences, such as ‘\n’ to print a newline. No newline is printed unless you specify one. In addition to the standard C escape sequences, a backslash followed by a space stands for a space. This is useful for displaying a string with spaces at the beginning or the end, since leading and trailing spaces are otherwise trimmed from all arguments. To print ‘ and foo = ’, use the command ‘echo \ and foo = \ ’.
A 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 expression
Print the value of expression and nothing but that value: no newlines, no ‘$nn = ’. The value is not entered in the value history either. See Expressions, for more information on expressions.
output/fmt expression
Print the value of expression in format fmt. You can use
the same formats as for print
. See Output
Formats, for more information.
printf template, expressions…
Print the values of one or more expressions under the control of the string template. To print several values, make expressions be a comma-separated list of individual expressions, which may be either numbers or pointers. Their values are printed as specified by template, exactly as a C program would do by executing the code below:
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
eval template, expressions…
Convert the values of one or more expressions under the control of the string template to a command line, and call it.
Next: Auto-loading sequences, Previous: Command Files, Up: Sequences [Contents][Index]