trace: allow PRI*64 at beginning and ending of format string

The tracetool parser only picks up PRI*64 and other format string macros
when enclosed between double quoted strings.  Lift this restriction by
extracting everything after the closing ')' as the format string:

  cpu_set_apic_base(uint64_t val) "%016"PRIx64
                                  ^^        ^^

One trick here: it turns out that backslashes in the format string like
"\n" were being interpreted by echo(1).  Fix this by using the POSIX
printf(1) command instead.  Although it normally does not make sense to
include backslashes in trace event format strings, an injected newline
causes tracetool to emit a broken header file and I want to eliminate
cases where broken output is emitted, even if the input was bad.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Stefan Hajnoczi 2011-09-13 13:34:35 +01:00 committed by Blue Swirl
parent 2f4a725b94
commit 913540a376
2 changed files with 14 additions and 11 deletions

View file

@ -40,6 +40,15 @@ EOF
exit 1
}
# Print a line without interpreting backslash escapes
#
# The built-in echo command may interpret backslash escapes without an option
# to disable this behavior.
puts()
{
printf "%s\n" "$1"
}
# Get the name of a trace event
get_name()
{
@ -111,13 +120,10 @@ get_argc()
echo $argc
}
# Get the format string for a trace event
# Get the format string including double quotes for a trace event
get_fmt()
{
local fmt
fmt=${1#*\"}
fmt=${fmt%\"*}
echo "$fmt"
puts "${1#*)}"
}
linetoh_begin_nop()
@ -266,7 +272,7 @@ linetoh_stderr()
static inline void trace_$name($args)
{
if (trace_list[$stderr_event_num].state != 0) {
fprintf(stderr, "$name $fmt\n" $argnames);
fprintf(stderr, "$name " $fmt "\n" $argnames);
}
}
EOF
@ -366,7 +372,7 @@ DEFINE_TRACE(ust_$name);
static void ust_${name}_probe($args)
{
trace_mark(ust, $name, "$fmt"$argnames);
trace_mark(ust, $name, $fmt$argnames);
}
EOF