3 # Code generator for trace events
5 # Copyright IBM, Corp. 2010
7 # This work is licensed under the terms of the GNU GPL, version 2. See
8 # the COPYING file in the top-level directory.
10 # Disable pathname expansion, makes processing text with '*' characters simpler
16 usage: $0 [--nop | --simple] [-h | -c]
17 Generate tracing code for a file on stdin.
20 --nop Tracing disabled
21 --simple Simple built-in backend
30 # Get the name of a trace event
36 # Get the argument list of a trace event, including types and names
45 # Get the argument name list of a trace event
48 local nfields field name
50 for field in $(get_args "$1"); do
51 nfields=$((nfields + 1))
56 # Only argument names have commas at the end
58 test "$field" = "$name" && continue
64 if [ "$nfields" -gt 1 ]
70 # Get the number of arguments to a trace event
75 for name in $(get_argnames "$1"); do
81 # Get the format string for a trace event
101 # Define an empty function for the trace event
103 static inline void trace_$name($args)
121 # No need for function definitions in nop backend
130 linetoh_begin_simple()
133 #include "simpletrace.h"
139 cast_args_to_uint64_t()
142 for arg in $(get_argnames "$1"); do
143 printf "%s" "(uint64_t)(uintptr_t)$arg"
149 local name args argc trace_args
150 name=$(get_name "$1")
151 args=$(get_args "$1")
152 argc=$(get_argc "$1")
154 trace_args="$simple_event_num"
157 trace_args="$trace_args, $(cast_args_to_uint64_t "$1")"
161 static inline void trace_$name($args)
163 trace$argc($trace_args);
167 simple_event_num=$((simple_event_num + 1))
175 linetoc_begin_simple()
190 # Process stdin by calling begin, line, and end functions for the backend
193 local begin process_line end
194 begin="lineto$1_begin_$backend"
195 process_line="lineto$1_$backend"
196 end="lineto$1_end_$backend"
200 while read -r str; do
201 # Skip comments and empty lines
203 test -z "$str" && continue
206 "$process_line" "$str"
219 /* This file is autogenerated by tracetool, do not edit. */
221 #include "qemu-common.h"
224 echo "#endif /* TRACE_H */"
229 echo "/* This file is autogenerated by tracetool, do not edit. */"
235 "--nop" | "--simple") backend="${1#--}" ;;
243 "--check-backend") exit 0 ;; # used by ./configure to test for backend