| |||
| Home > RealView Debugger Commands > Alphabetical command reference > PRINTF | |||
The PRINTF command prints formatted text on the screen.
PRINTF " format_string"
[,argument]...
where:
format_stringIs a format specification conforming to C/C++ rules with extensions. It might be a text message, or it can describe how one or more arguments are to be presented. See Format string syntax for details.
Only the first 256 characters of the string are displayed, even after formatting is applied.
argumentIs a list of values that you want displayed in the way described by the specified format.
The PRINTF command uses a special format
string to write text and numbers to the screen. If you are using
the GUI, then they are displayed in the Output pane. It works in a
similar way to the ANSI C standard library function printf(),
with a number of extensions to better support the debugger environment.
The message in is
a string. If there are no format_string% characters in the
string, the message is written out and any arguments are ignored.
The % symbol is used to indicate the start of
an argument conversion specification.
The syntax of the specification is:
%[flag][fieldwidth][precision][lenmod]convspec
where:
flagAn optional conversion modification flag -.
If specified, the result is left-justified within the field width.
If not specified, the result is right-justified.
fieldwidthAn optional minimum field width specified in decimal.
precisionAn optional precision specified in decimal, with
a preceding . (period character) to identify
it.
lenmodAn optional argument length specifier:
a 16-bit value
a 32-bit value
a 64-bit value
convspecThe possible conversion specifier characters are:
A literal % character.
The mnemonic for the processor instruction in memory pointed to by the argument. The expansion includes a newline character. The information that is printed includes:
the memory address in hexadecimal
the memory contents in hexadecimal
the instruction mnemonic and arguments
an ASCII representation of the memory contents, if printable.
A line from the current source file, where the argument is the line number.
A line from the current source file, where the argument is a target memory address.
An integer argument printed in decimal. d and i are equivalent, and indicate a signed integer. u is used for unsigned integers.
An integer argument
printed in unsigned hexadecimal. x indicates that the
letters a to f are used for
the extra digits, and X indicates that the letters A to F are
used.
A single character argument.
A string argument. The string itself can be stored on the host or on the target.
A pointer argument. The value of the pointer is printed in hexadecimal.
A floating point argument, printed in scientific notation,
fixed point notation, or the shorter of the two. The capital letter forms
use a capital E in scientific notation rather
than an e.
The following rules apply to the use of the PRINTF command:
if there are too many arguments, some of them are not printed
if there are too few arguments (that is, there are
more conversion specifiers in the format string than there are arguments
after the format string), the string <invalid value> is
output instead
if the argument type does not correspond to its conversion field specification, arguments are converted incorrectly.
The following examples show how to use PRINTF:
printf "Found %d errors\n",
ecountPrint out a message, substituting
the value of ecount. So, if ecount had
the value 5, the message is:
Found 5 errors
printf "Completion %\n",
runsPrint out a message that includes
a single percent symbol. The argument runs is
ignored, so the message is:
Completion %
printf "%h\n", #82Print out a source file line 82. For example:
REG char Ch_Index;
printf "Var is %hd.\n",
short_varPrint out the variable short
short_var. For example:
Var is 22.
printf "Instruction1
%m\nInstruction2 %m", 0x100, 0x104Print
out the disassembly of the contents of location 0x100,
two newlines and the contents of location 0x104.
For example, it might print:
Instruction1 000000100 20011410 ANDCS r1,r1,r0,LSL r4 Instruction2 000000104 20011412 ANDCS r1,r1,r2,LSL r4
printf "Average execution
time %f secs\n", totaltime / (double)20Print out a message, substituting the value of the expression.
So, if totaltime had the value 523.3,
the message is:
Average execution time 26.165 secs
Using variable substitution in commands within a macro in the RealView Debugger User Guide.