From: Lluís <xscript@gmx.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v1 1/4] trace-gen: gracefully handle TCG types in "trace-events"
Date: Wed, 03 Nov 2010 21:02:40 +0100 [thread overview]
Message-ID: <20101103200240.6599.52807.stgit@ginnungagap.bsc.es> (raw)
In-Reply-To: <20101103200233.6599.50130.stgit@ginnungagap.bsc.es>
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 <vilanova@ac.upc.edu>
---
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 <<EOF
@@ -173,7 +297,7 @@ line_h_simple()
# XXX: why 'simple' backend does not expand into 'nop' when disabled?
local func args argc trace_args
func=$(get_func_name "$1")
- args=$(get_args "$1")
+ args=$(get_args "$1" native_type)
argc=$(get_argc "$1")
trace_args="$simple_event_num"
@@ -267,7 +391,7 @@ line_h_ust()
local name func args argnames
name=$(get_event_name "$1")
func=$(get_func_name "$1")
- args=$(get_args "$1")
+ args=$(get_args "$1" native_type)
argnames=$(get_argnames "$1")
cat <<EOF
@@ -302,7 +426,7 @@ line_c_ust()
local name args argnames fmt
name=$(get_event_name "$1")
- args=$(get_args "$1")
+ args=$(get_args "$1" native_type)
argnames=$(get_argnames "$1")
fmt=$(get_fmt "$1")
next prev parent reply other threads:[~2010-11-03 20:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-03 20:02 [Qemu-devel] [RFC][PATCH v1 0/4] trace-gen: support for trace points in code-generation routines Lluís
2010-11-03 20:02 ` Lluís [this message]
2010-11-03 20:02 ` [Qemu-devel] [PATCH v1 2/4] trace-gen: auto-generate TCG helper routines for tracing Lluís
2010-11-03 20:02 ` [Qemu-devel] [PATCH v1 3/4] trace-gen: [all] include "trace-helper.h" on all "helper.h" files Lluís
2010-11-03 20:03 ` [Qemu-devel] [PATCH v1 4/4] trace-gen: auto-generate wrappers to call TCG trace helpers Lluís
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101103200240.6599.52807.stgit@ginnungagap.bsc.es \
--to=xscript@gmx.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).