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))
173 #define NR_TRACE_EVENTS $simple_event_num
174 extern TraceEvent trace_list[NR_TRACE_EVENTS];
178 linetoc_begin_simple()
183 TraceEvent trace_list[] = {
192 name=$(get_name "$1")
194 {.tp_name = "$name", .state=0},
196 simple_event_num=$((simple_event_num + 1))
206 # Process stdin by calling begin, line, and end functions for the backend
209 local begin process_line end
210 begin="lineto$1_begin_$backend"
211 process_line="lineto$1_$backend"
212 end="lineto$1_end_$backend"
216 while read -r str; do
217 # Skip comments and empty lines
219 test -z "$str" && continue
222 "$process_line" "$str"
235 /* This file is autogenerated by tracetool, do not edit. */
237 #include "qemu-common.h"
240 echo "#endif /* TRACE_H */"
245 echo "/* This file is autogenerated by tracetool, do not edit. */"
251 "--nop" | "--simple") backend="${1#--}" ;;
259 "--check-backend") exit 0 ;; # used by ./configure to test for backend