* [Qemu-devel] [PATCH v1 1/4] trace-gen: gracefully handle TCG types in "trace-events"
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
2010-11-03 20:02 ` [Qemu-devel] [PATCH v1 2/4] trace-gen: auto-generate TCG helper routines for tracing Lluís
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Lluís @ 2010-11-03 20:02 UTC (permalink / raw)
To: qemu-devel
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")
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v1 2/4] trace-gen: auto-generate TCG helper routines for tracing
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 ` [Qemu-devel] [PATCH v1 1/4] trace-gen: gracefully handle TCG types in "trace-events" Lluís
@ 2010-11-03 20:02 ` 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
3 siblings, 0 replies; 5+ messages in thread
From: Lluís @ 2010-11-03 20:02 UTC (permalink / raw)
To: qemu-devel
Auto-generates file "trace-helper.h" to provide TCG helpers and "trace-helper.c"
to proxy these helpers onto trace event routines.
Only trace events with the 'gen' property are affected.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
.gitignore | 2 +
Makefile | 15 ++++++++
Makefile.target | 5 +--
trace-events | 5 +++
tracetool | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 120 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index e4a351d..758f457 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,8 @@ config-host.*
config-target.*
trace.h
trace.c
+trace-helper.h
+trace-helper.c
*-timestamp
*-softmmu
*-darwin-user
diff --git a/Makefile b/Makefile
index 1886317..5975926 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# Makefile for QEMU.
-GENERATED_HEADERS = config-host.h trace.h
+GENERATED_HEADERS = config-host.h trace.h trace-helper.h trace-helper.c
ifneq ($(wildcard config-host.mak),)
# Put the all: rule here so that config-host.mak can contain dependencies.
@@ -118,6 +118,18 @@ trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
trace.o: trace.c $(GENERATED_HEADERS)
+trace-helper.h: trace-helper.h-timestamp
+trace-helper.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
+ $(call quiet-command,sh $(SRC_PATH)/tracetool $(TRACETOOL_EXTRA) --helper --$(TRACE_BACKEND) -h < $< > $@," GEN trace-helper.h")
+ @cmp -s $@ trace-helper.h || cp $@ trace-helper.h
+
+trace-helper.c: trace-helper.c-timestamp
+trace-helper.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
+ $(call quiet-command,sh $(SRC_PATH)/tracetool $(TRACETOOL_EXTRA) --helper --$(TRACE_BACKEND) -c < $< > $@," GEN trace-helper.c")
+ @cmp -s $@ trace-helper.c || cp $@ trace-helper.c
+
+trace-helper.o: trace-helper.c $(GENERATED_HEADERS)
+
simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
version.o: $(SRC_PATH)/version.rc config-host.mak
@@ -154,6 +166,7 @@ clean:
rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d
rm -f qemu-img-cmds.h
rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
+ rm -f trace-helper.c trace-helper.h trace-helper.h-timestamp trace-helper.c-timestamp
$(MAKE) -C tests clean
for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
diff --git a/Makefile.target b/Makefile.target
index 90867e7..c7e26e2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -378,9 +378,8 @@ endif
$(QEMU_PROG)-prepare: $(GENERATED_HEADERS) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB) $(QEMU_PROG)
-$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
- $(call LINK,$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
-
+$(QEMU_PROG): trace-helper.o $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
+ $(call LINK,trace-helper.o $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)) $(LIBBACKDOOR_LIB) $(LIBINSTRUMENT_LIB)
gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh
$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/feature_to_c.sh $@ $(TARGET_XML_FILES)," GEN $(TARGET_DIR)$@")
diff --git a/trace-events b/trace-events
index 3b91a1c..4a89d97 100644
--- a/trace-events
+++ b/trace-events
@@ -38,6 +38,11 @@
# is identified by the '--with-instrument' configure option).
# The original backend-specific function is still available under the name
# 'trace_##name##_backend'.
+#
+# - gen
+# Provide trace events suitable for using during TCG code generation.
+# Generates TCG function helpers reachable through 'helper_trace_gen_##name'
+# which proxy their calls onto 'trace_##name'.
# qemu-malloc.c
disable qemu_malloc(size_t size, void *ptr) "size %zu ptr %p"
diff --git a/tracetool b/tracetool
index 3172259..588f442 100755
--- a/tracetool
+++ b/tracetool
@@ -234,6 +234,38 @@ native_type()
################################################################################
### Backend code
+### nil -- H
+begin_h_nil()
+{
+ return
+}
+
+line_h_nil()
+{
+ return
+}
+
+end_h_nil()
+{
+ return
+}
+
+### nil -- C
+begin_c_nil()
+{
+ return
+}
+
+line_c_nil()
+{
+ return
+}
+
+end_c_nil()
+{
+ return
+}
+
### nop -- H
begin_h_nop()
{
@@ -507,6 +539,69 @@ line_c_regular()
return
}
+### Helper -- H
+traceto_h_helper()
+{
+ echo "/* This file is autogenerated by tracetool, do not edit. */"
+ convert h $1 nil
+}
+
+helper_h_type()
+{
+ case "$1" in
+ "void *"|"TCGv_ptr") echo "ptr";;
+ "uint32_t"|"TCGv_i64") echo "i32";;
+ "uint64_t"|"TCGv_i32") echo "i64";;
+ *) echo "i64";;
+ esac
+}
+
+line_h_helper()
+{
+ local gen
+ gen=$(get_property "$1" "gen")
+ [ "$gen" = "1" ] || return
+
+ local name argc argtypes
+ name=$(get_event_name "$1")
+ argc=$(get_argc "$1")
+ argtypes=$(get_argtypes "$1" helper_h_type)
+ echo "DEF_HELPER_$argc(trace_proxy_$name, void, $argtypes)"
+}
+
+### Helper -- C
+traceto_c_helper()
+{
+ cat <<EOF
+/* This file is autogenerated by tracetool, do not edit. */
+#include "trace.h"
+#include "helper.h"
+EOF
+ convert c $1 nil
+}
+
+line_c_helper()
+{
+ local gen
+ gen=$(get_property "$1" "gen")
+ [ "$gen" = "1" ] || return
+
+ local name api args argtypes_native argnames values
+ name=$(get_event_name "$1")
+ api=$(get_api_name "$1")
+ args=$(get_args "$1" native_type)
+ argtypes_native=$(get_argtypes "$1" native_type)
+ argnames=$(get_argnames "$1")
+ values=$(zip_lists "$argtypes_native" "$argnames" "(%s)%s")
+
+ cat <<EOF
+void helper_trace_proxy_$name($args)
+{
+ $api($values);
+}
+EOF
+}
+
################################################################################
### Generic code
@@ -551,6 +646,7 @@ Flags:
Frontends:
--regular Regular frontend
+ --helper Helper proxies
Backends:
--nop Tracing disabled
@@ -567,7 +663,7 @@ EOF
while [ $# -gt 0 ]; do
case $1 in
"--instrument") enable_instrument="1" ;;
- "--regular") frontend="${1#--}" ;;
+ "--regular"|"--helper") frontend="${1#--}" ;;
"--nop"|"--simple"|"--ust") backend="${1#--}" ;;
"-h"|"-c") output="${1#-}" ;;
"--check-backend") check=1 ;; # used by ./configure to test for backend
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v1 3/4] trace-gen: [all] include "trace-helper.h" on all "helper.h" files
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 ` [Qemu-devel] [PATCH v1 1/4] trace-gen: gracefully handle TCG types in "trace-events" Lluís
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 ` 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
3 siblings, 0 replies; 5+ messages in thread
From: Lluís @ 2010-11-03 20:02 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
target-alpha/helper.h | 2 ++
target-arm/helper.h | 2 ++
target-cris/helper.h | 2 ++
target-i386/helper.h | 2 ++
target-m68k/helper.h | 2 ++
target-microblaze/helper.h | 2 ++
target-mips/helper.h | 2 ++
target-ppc/helper.h | 2 ++
target-sh4/helper.h | 2 ++
target-sparc/helper.h | 2 ++
10 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/target-alpha/helper.h b/target-alpha/helper.h
index ccf6a2a..030def3 100644
--- a/target-alpha/helper.h
+++ b/target-alpha/helper.h
@@ -123,4 +123,6 @@ DEF_HELPER_2(stl_c_raw, i64, i64, i64)
DEF_HELPER_2(stq_c_raw, i64, i64, i64)
#endif
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-arm/helper.h b/target-arm/helper.h
index 0d1bc47..d3ba5d9 100644
--- a/target-arm/helper.h
+++ b/target-arm/helper.h
@@ -447,4 +447,6 @@ DEF_HELPER_3(iwmmxt_muladdswl, i64, i64, i32, i32)
DEF_HELPER_2(set_teecr, void, env, i32)
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-cris/helper.h b/target-cris/helper.h
index 093063a..620a199 100644
--- a/target-cris/helper.h
+++ b/target-cris/helper.h
@@ -23,4 +23,6 @@ DEF_HELPER_FLAGS_2(evaluate_flags_move_2, TCG_CALL_PURE, i32, i32, i32)
DEF_HELPER_0(evaluate_flags, void)
DEF_HELPER_0(top_evaluate_flags, void)
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-i386/helper.h b/target-i386/helper.h
index 979d94e..94d7bd1 100644
--- a/target-i386/helper.h
+++ b/target-i386/helper.h
@@ -217,6 +217,8 @@ DEF_HELPER_2(rclq, tl, tl, tl)
DEF_HELPER_2(rcrq, tl, tl, tl)
#endif
+#include "trace-helper.h"
+
#if defined(CONFIG_BACKDOOR)
#include "backdoor/helper.h"
#endif
diff --git a/target-m68k/helper.h b/target-m68k/helper.h
index cb8a0c7..29e206b 100644
--- a/target-m68k/helper.h
+++ b/target-m68k/helper.h
@@ -51,4 +51,6 @@ DEF_HELPER_3(set_mac_extu, void, env, i32, i32)
DEF_HELPER_2(flush_flags, void, env, i32)
DEF_HELPER_1(raise_exception, void, i32)
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-microblaze/helper.h b/target-microblaze/helper.h
index 11ad1b6..3606614 100644
--- a/target-microblaze/helper.h
+++ b/target-microblaze/helper.h
@@ -34,4 +34,6 @@ DEF_HELPER_2(mmu_write, void, i32, i32)
DEF_HELPER_4(memalign, void, i32, i32, i32, i32)
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-mips/helper.h b/target-mips/helper.h
index cb13fb2..4855b67 100644
--- a/target-mips/helper.h
+++ b/target-mips/helper.h
@@ -287,4 +287,6 @@ DEF_HELPER_0(rdhwr_ccres, tl)
DEF_HELPER_1(pmon, void, int)
DEF_HELPER_0(wait, void)
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-ppc/helper.h b/target-ppc/helper.h
index 2bf9283..c76e733 100644
--- a/target-ppc/helper.h
+++ b/target-ppc/helper.h
@@ -401,4 +401,6 @@ DEF_HELPER_2(store_601_batl, void, i32, tl)
DEF_HELPER_2(store_601_batu, void, i32, tl)
#endif
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-sh4/helper.h b/target-sh4/helper.h
index 4b2fcdd..daec7cd 100644
--- a/target-sh4/helper.h
+++ b/target-sh4/helper.h
@@ -50,4 +50,6 @@ DEF_HELPER_1(fsqrt_DT, i64, i64)
DEF_HELPER_1(ftrc_FT, i32, i32)
DEF_HELPER_1(ftrc_DT, i32, i64)
+#include "trace-helper.h"
+
#include "def-helper.h"
diff --git a/target-sparc/helper.h b/target-sparc/helper.h
index 6f103e7..f2014b8 100644
--- a/target-sparc/helper.h
+++ b/target-sparc/helper.h
@@ -160,4 +160,6 @@ VIS_CMPHELPER(cmpne);
DEF_HELPER_0(compute_psr, void);
DEF_HELPER_0(compute_C_icc, i32);
+#include "trace-helper.h"
+
#include "def-helper.h"
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v1 4/4] trace-gen: auto-generate wrappers to call TCG trace helpers
2010-11-03 20:02 [Qemu-devel] [RFC][PATCH v1 0/4] trace-gen: support for trace points in code-generation routines Lluís
` (2 preceding siblings ...)
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 ` Lluís
3 siblings, 0 replies; 5+ messages in thread
From: Lluís @ 2010-11-03 20:03 UTC (permalink / raw)
To: qemu-devel
Auto-generates file "trace-gen.h" with instrumentable wrappers to generate calls
to TCG trace helpers.
Such wrappers are named 'trace_gen_##name', also reachable as
'trace_gen_##name##_backend' when instrumented.
Events with the "gen" property are also able to use TCG types on the trace event
declaration, which are gracefully handled when generating trace functions.
Only trace events with the 'gen' property are affected.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
Makefile | 8 +++-
trace-events | 3 +
tracetool | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 5975926..2831dc3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# Makefile for QEMU.
-GENERATED_HEADERS = config-host.h trace.h trace-helper.h trace-helper.c
+GENERATED_HEADERS = config-host.h trace.h trace-helper.h trace-helper.c trace-gen.h
ifneq ($(wildcard config-host.mak),)
# Put the all: rule here so that config-host.mak can contain dependencies.
@@ -130,6 +130,11 @@ trace-helper.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
trace-helper.o: trace-helper.c $(GENERATED_HEADERS)
+trace-gen.h: trace-gen.h-timestamp
+trace-gen.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
+ $(call quiet-command,sh $(SRC_PATH)/tracetool $(TRACETOOL_EXTRA) --gen --$(TRACE_BACKEND) -h < $< > $@," GEN trace-gen.h")
+ @cmp -s $@ trace-gen.h || cp $@ trace-gen.h
+
simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
version.o: $(SRC_PATH)/version.rc config-host.mak
@@ -167,6 +172,7 @@ clean:
rm -f qemu-img-cmds.h
rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
rm -f trace-helper.c trace-helper.h trace-helper.h-timestamp trace-helper.c-timestamp
+ rm -f trace-gen.h-timestamp trace-gen.c-timestamp
$(MAKE) -C tests clean
for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
diff --git a/trace-events b/trace-events
index 4a89d97..a54fa03 100644
--- a/trace-events
+++ b/trace-events
@@ -43,6 +43,9 @@
# Provide trace events suitable for using during TCG code generation.
# Generates TCG function helpers reachable through 'helper_trace_gen_##name'
# which proxy their calls onto 'trace_##name'.
+# As an extra aid, functions named 'trace_gen_##name' are generated into
+# "trace-gen.h", which can be reched through 'trace_gen_##name##_backend' when
+# the event is instrumented.
# qemu-malloc.c
disable qemu_malloc(size_t size, void *ptr) "size %zu ptr %p"
diff --git a/tracetool b/tracetool
index 588f442..e99da0c 100755
--- a/tracetool
+++ b/tracetool
@@ -602,6 +602,134 @@ void helper_trace_proxy_$name($args)
EOF
}
+### Gen - H
+traceto_h_gen()
+{
+ cat <<EOF
+#ifndef TRACE_GEN_H
+#define TRACE_GEN_H
+
+/* This file is autogenerated by tracetool, do not edit. */
+EOF
+
+ convert h $1 nil
+
+ if [ "$had_instrument" = "1" ]; then
+ echo '#include "trace-instrument.h"'
+ fi
+ echo "#endif /* TRACE_GEN_H */"
+}
+
+line_h_gen_parse_pre()
+{
+ case "$3" in
+ "uint32_t") echo "TCGv_i32 __arg_$1 = tcg_const_i32($2);" ;;
+ "uint64_t") echo "TCGv_i64 __arg_$1 = tcg_const_i64($2);" ;;
+ "void *") echo "TCGv_ptr __arg_$1 = tcg_const_ptr((int64_t)$2);" ;;
+ esac
+}
+
+line_h_gen_parse_args()
+{
+ case "$3" in
+ "uint64_t") echo "__arg_$1" ;;
+ "uint32_t") echo "__arg_$1" ;;
+ "void *") echo "__arg_$1" ;;
+ *) echo "$2" ;;
+ esac
+}
+
+line_h_gen_parse_post()
+{
+ case "$3" in
+ "uint32_t") echo "tcg_temp_free_i32(__arg_$1);" ;;
+ "uint64_t") echo "tcg_temp_free_i64(__arg_$1);" ;;
+ "void *") echo "tcg_temp_free_i64(__arg_$1);" ;;
+ esac
+}
+
+line_h_gen()
+{
+ local gen
+ gen=$(get_property "$1" "gen")
+ [ "$gen" = "1" ] || return
+
+ local name args
+ name=$(get_event_name "$1")
+ args=$(get_args "$1")
+
+ local gen_pre gen_post gen_args i
+ gen_pre=""
+ gen_post=""
+ gen_args=""
+
+ local argname
+ i=1
+ for argname in $(get_argnames "$1"); do
+ argname=${argname%,}
+ eval __argname_$i=$argname
+ i=$(($i + 1))
+ done
+
+ local argtypes argtype accum _pre _arg _post
+ argtypes=$(get_argtypes "$1")
+ i=1
+ accum=""
+ for argtype in $argtypes; do
+ accum="$accum ${argtype%,}"
+ if [ "$argtype" = "${argtype%,}" ]; then
+ continue
+ fi
+ argtype="${accum# }"
+ accum=""
+
+ eval argname=\$__argname_$i
+
+ _pre=$(line_h_gen_parse_pre $i $argname "$argtype")
+ gen_pre="$gen_pre
+$_pre"
+ _arg=$(line_h_gen_parse_arg $i $argname "$argtype")
+ gen_args="$gen_args$_arg"
+ _post=$(line_h_gen_parse_post $i $argname "$argtype")
+ gen_post="$gen_post
+$_post"
+
+ i=$(($i + 1))
+ done
+ argtype="${accum# }"
+ eval argname=\$__argname_$i
+
+ _pre=$(line_h_gen_parse_pre $i $argname "$argtype")
+ gen_pre="$gen_pre
+$_pre"
+ _arg=$(line_h_gen_parse_args $i $argname "$argtype")
+ gen_args="$gen_args, $_arg"
+ _post=$(line_h_gen_parse_post $i $argname "$argtype")
+ gen_post="$gen_post
+$_post"
+
+ gen_args="${gen_args#, }"
+
+ cat <<EOF
+static inline void trace_gen_${name}_backend($args)
+{
+$gen_pre
+ gen_helper_trace_proxy_$name($gen_args);
+$gen_post
+}
+EOF
+
+ # XXX: should still provide instrumentation if event is disabled?
+ local instrument
+ instrument=$(get_property "$1" "instrument")
+ if [ "$instrument" = "1" ]; then
+ had_instrument="1"
+ return
+ fi
+
+ echo "#define trace_gen_$name trace_gen_${name}_backend"
+}
+
################################################################################
### Generic code
@@ -663,7 +791,7 @@ EOF
while [ $# -gt 0 ]; do
case $1 in
"--instrument") enable_instrument="1" ;;
- "--regular"|"--helper") frontend="${1#--}" ;;
+ "--regular"|"--helper"|"--gen") frontend="${1#--}" ;;
"--nop"|"--simple"|"--ust") backend="${1#--}" ;;
"-h"|"-c") output="${1#-}" ;;
"--check-backend") check=1 ;; # used by ./configure to test for backend
^ permalink raw reply related [flat|nested] 5+ messages in thread