From patchwork Tue Sep 13 12:34:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 114487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7BD53B6F94 for ; Tue, 13 Sep 2011 23:08:58 +1000 (EST) Received: from localhost ([::1]:50408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3SD7-0005Xt-7C for incoming@patchwork.ozlabs.org; Tue, 13 Sep 2011 08:35:33 -0400 Received: from eggs.gnu.org ([140.186.70.92]:35480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3SCX-0004E1-RZ for qemu-devel@nongnu.org; Tue, 13 Sep 2011 08:35:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3SCQ-0008Rd-JX for qemu-devel@nongnu.org; Tue, 13 Sep 2011 08:34:57 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:49965) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3SCQ-0008Pz-8w for qemu-devel@nongnu.org; Tue, 13 Sep 2011 08:34:50 -0400 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p8DCYh37026294 for ; Tue, 13 Sep 2011 12:34:43 GMT Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p8DCYh3L2154504 for ; Tue, 13 Sep 2011 13:34:43 +0100 Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p8DCYgDL032235 for ; Tue, 13 Sep 2011 06:34:42 -0600 Received: from stefanha-thinkpad.manchester-maybrook.uk.ibm.com (dyn-9-174-219-31.manchester-maybrook.uk.ibm.com [9.174.219.31]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p8DCYf64032195; Tue, 13 Sep 2011 06:34:42 -0600 From: Stefan Hajnoczi To: Date: Tue, 13 Sep 2011 13:34:35 +0100 Message-Id: <1315917277-20670-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1315917277-20670-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1315917277-20670-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.163 Cc: Blue Swirl , William Cohen , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 2/4] trace: allow PRI*64 at beginning and ending of format string X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- docs/tracing.txt | 5 +---- scripts/tracetool | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/tracing.txt b/docs/tracing.txt index e130a61..2c33a62 100644 --- a/docs/tracing.txt +++ b/docs/tracing.txt @@ -75,10 +75,7 @@ Trace events should use types as follows: Format strings should reflect the types defined in the trace event. Take special care to use PRId64 and PRIu64 for int64_t and uint64_t types, -respectively. This ensures portability between 32- and 64-bit platforms. Note -that format strings must begin and end with double quotes. When using -portability macros, ensure they are preceded and followed by double quotes: -"value %"PRIx64"". +respectively. This ensures portability between 32- and 64-bit platforms. === Hints for adding new trace events === diff --git a/scripts/tracetool b/scripts/tracetool index 743d246..4c9951d 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -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