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 <vilan...@ac.upc.edu> --- .gitignore | 2 + Makefile | 15 +++++++ Makefile.target | 5 +- simpletrace.py | 2 - trace-events | 5 ++ tracetool | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 6 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 97cb3b4..4effdcc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Makefile for QEMU. -GENERATED_HEADERS = config-host.h trace.h qemu-options.def +GENERATED_HEADERS = config-host.h trace.h trace-helper.h trace-helper.c qemu-options.def ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies. @@ -120,6 +120,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 @@ -157,6 +169,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 7a92e02..0c8b0ac 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/simpletrace.py b/simpletrace.py index 6d8100e..1cfc3de 100755 --- a/simpletrace.py +++ b/simpletrace.py @@ -19,7 +19,7 @@ header_version = 0 trace_fmt = '=QQQQQQQQ' trace_len = struct.calcsize(trace_fmt) -event_re = re.compile(r'(disable\s+|instrument\s+)*([a-zA-Z0-9_]+)\(([^)]*)\).*') +event_re = re.compile(r'(disable\s+|instrument\s+|gen\s+)*([a-zA-Z0-9_]+)\(([^)]*)\).*') def err(msg): sys.stderr.write(msg + '\n') diff --git a/trace-events b/trace-events index fefac91..52e4128 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 6f48215..28d434a 100755 --- a/tracetool +++ b/tracetool @@ -237,6 +237,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() { @@ -514,6 +546,83 @@ 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") + if [ "$argc" != "0" ]; then + argtypes=$(get_argtypes "$1" helper_h_type) + argtypes=", $argtypes" + fi + 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 +} + +helper_c_type() +{ + case "$1" in + "void *"|"TCGv_ptr") echo "void *";; + "uint32_t"|"TCGv_i64") echo "uint32_t";; + "uint64_t"|"TCGv_i32") echo "uint64_t";; + *) echo "uint64_t";; + esac +} + +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" helper_c_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 @@ -558,6 +667,7 @@ Flags: Frontends: --regular Regular frontend + --helper Helper proxies Backends: --nop Tracing disabled @@ -574,7 +684,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