From patchwork Wed Nov 3 20:02:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?Q?Llu=C3=ADs?= X-Patchwork-Id: 70062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 59ABFB6EE8 for ; Thu, 4 Nov 2010 07:07:23 +1100 (EST) Received: from localhost ([127.0.0.1]:50710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDjc7-0003Ce-TB for incoming@patchwork.ozlabs.org; Wed, 03 Nov 2010 16:07:20 -0400 Received: from [140.186.70.92] (port=58860 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDjXZ-0001Nw-Cg for qemu-devel@nongnu.org; Wed, 03 Nov 2010 16:02:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDjXX-0006Hd-Io for qemu-devel@nongnu.org; Wed, 03 Nov 2010 16:02:37 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:40160 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PDjXX-0006HK-4e for qemu-devel@nongnu.org; Wed, 03 Nov 2010 16:02:35 -0400 Received: (qmail invoked by alias); 03 Nov 2010 20:02:32 -0000 Received: from unknown (EHLO localhost) [84.88.53.92] by mail.gmx.net (mp054) with SMTP; 03 Nov 2010 21:02:32 +0100 X-Authenticated: #12333383 X-Provags-ID: V01U2FsdGVkX1+r7Cdtl2urrKgoVPAzJY1y8+DefkSiTQc2b7fhf6 MRUhTLhxGi2ZnM To: qemu-devel@nongnu.org From: =?utf-8?b?TGx1w61z?= Date: Wed, 03 Nov 2010 21:02:40 +0100 Message-ID: <20101103200240.6599.52807.stgit@ginnungagap.bsc.es> In-Reply-To: <20101103200233.6599.50130.stgit@ginnungagap.bsc.es> References: <20101103200233.6599.50130.stgit@ginnungagap.bsc.es> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH v1 1/4] trace-gen: gracefully handle TCG types in "trace-events" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Some trace events with the "gen" property will need to use TCG arguments. As such, modify 'tracetool' to gracefully handle these types and let the backend code transliterate these types into their native counterpart. Signed-off-by: LluĂ­s Vilanova --- tracetool | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 132 insertions(+), 8 deletions(-) diff --git a/tracetool b/tracetool index facb385..3172259 100755 --- a/tracetool +++ b/tracetool @@ -38,13 +38,71 @@ get_api_name() echo "$event" } +# Convenience function to pair elements of two lists (of comma-separated values) of equal size +# $1: list +# $2: list +# $3: format (defaults to ", $1 $2") +zip_lists() +{ + local format + format=$3 + [ -n "$format" ] || format=", %s %s" + + local i elem accum + i=1 + accum="" + for elem in $1; do + if [ "$elem" = "${elem%,}" ]; then + accum="$accum $elem" + else + accum="$accum ${elem%,}" + eval __elem_$i=\"$accum\" + i=$(($i + 1)) + accum="" + fi + done + eval __elem_$i=\"$accum\" + + local tmp res + accum="" + res="" + i=1 + for elem in $2; do + if [ "$elem" = "${elem%,}" ]; then + accum="$accum $elem" + else + accum="$accum ${elem%,}" + eval tmp=\$__elem_$i + tmp=$(printf "$format" "$tmp" "$accum") + res="$res$tmp" + i=$(($i + 1)) + accum="" + fi + done + eval tmp=\$__elem_$i + tmp=$(printf "$format" "$tmp" "$elem") + res="$res$tmp" + + echo $res +} + # Get the argument list of a trace event, including types and names +# If given, the second argument is a function name to map on each element of the +# comma-separated list get_args() { - local args - args=${1#*\(} - args=${args%\)*} - echo "$args" + if [ -z "$2" ]; then + local args + args=${1#*\(} + args=${args%\)*} + echo "$args" + else + local argtypes argnames res + argtypes=$(get_argtypes "$1" $2) + argnames=$(get_argnames "$1") + res=$(zip_lists "$argtypes" "$argnames") + echo "${res#, }" + fi } # Get the argument name list of a trace event @@ -72,6 +130,60 @@ get_argnames() fi } +# Get the argument type list of a trace event +# If given, the second argument is a function name to map on each element of the +# comma-separated list +get_argtypes() +{ + if [ -z "$2" ]; then + local res elem accum + res="" + accum="" + for elem in $(get_args "$1"); do + if [ "${elem}" = "${elem%,}" ]; then + accum="$accum $elem" + else + [ "$elem" = "${elem#\*}" ] || accum="$accum *" + res="$res, $accum" + accum="" + fi + done + accum=${accum% *} + [ "$elem" = "${elem#\*}" ] || accum="$accum *" + res="$res, $accum" + echo "${res#, }" + else + local res elem accum + res="" + accum="" + for elem in $(get_argtypes "$1"); do + if [ "${elem}" = "${elem%,}" ]; then + accum="$accum $elem" + else + accum="$accum ${elem%,}" + + # trim spaces + accum=${accum## } + accum=${accum%% } + # transliterate + [ -z "$2" ] || accum=$($2 "$accum") + + res="$res, $accum" + accum="" + fi + done + + # trim spaces + accum=${accum## } + accum=${accum%% } + # transliterate + [ -z "$2" ] || accum=$($2 "$accum") + + res="$res, $accum" + echo "${res#, }" + fi +} + # Get the number of arguments to a trace event get_argc() { @@ -107,6 +219,18 @@ get_fmt() echo "$fmt" } +# Transliterate an argument in trace-events (raw) into its native counterpart +# (e.g., TCGv_i32 -> uint32_t) +native_type() +{ + case "$1" in + "TCGv_i32") echo "uint32_t" ;; + "TCGv_i64") echo "uint64_t" ;; + "TCGv_ptr") echo "void *" ;; + *) echo "$1" ;; + esac +} + ################################################################################ ### Backend code @@ -120,7 +244,7 @@ line_h_nop() { local func args func=$(get_func_name "$1") - args=$(get_args "$1") + args=$(get_args "$1" native_type) # Define an empty function for the trace event cat <