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
90 # Get the state of a trace event
93 local str disable state
95 disable
=${str##disable }
96 if [ "$disable" = "$str" ] ; then
112 name
=$
(get_name
"$1")
113 args
=$
(get_args
"$1")
115 # Define an empty function for the trace event
117 static inline void trace_$name($args)
135 # No need for function definitions in nop backend
144 linetoh_begin_simple
()
147 #include "simpletrace.h"
153 cast_args_to_uint64_t
()
156 for arg
in $
(get_argnames
"$1"); do
157 printf "%s" "(uint64_t)(uintptr_t)$arg"
163 local name args argc trace_args state
164 name
=$
(get_name
"$1")
165 args
=$
(get_args
"$1")
166 argc
=$
(get_argc
"$1")
167 state
=$
(get_state
"$1")
168 if [ "$state" = "0" ]; then
169 name
=${name##disable }
172 trace_args
="$simple_event_num"
175 trace_args
="$trace_args, $(cast_args_to_uint64_t "$1")"
179 static inline void trace_$name($args)
181 trace$argc($trace_args);
185 simple_event_num
=$
((simple_event_num
+ 1))
191 #define NR_TRACE_EVENTS $simple_event_num
192 extern TraceEvent trace_list[NR_TRACE_EVENTS];
196 linetoc_begin_simple
()
201 TraceEvent trace_list[] = {
210 name
=$
(get_name
"$1")
211 state
=$
(get_state
"$1")
212 if [ "$state" = "0" ] ; then
213 name
=${name##disable }
216 {.tp_name = "$name", .state=$state},
218 simple_event_num
=$
((simple_event_num
+ 1))
228 # Process stdin by calling begin, line, and end functions for the backend
231 local begin process_line end str disable
232 begin
="lineto$1_begin_$backend"
233 process_line
="lineto$1_$backend"
234 end
="lineto$1_end_$backend"
238 while read -r str
; do
239 # Skip comments and empty lines
241 test -z "$str" && continue
243 # Process the line. The nop backend handles disabled lines.
244 disable
=${str%%disable *}
246 if test -z "$disable"; then
247 # Pass the disabled state as an arg to lineto$1_simple().
248 # For all other cases, call lineto$1_nop()
249 if [ $backend = "simple" ]; then
250 "$process_line" "$str"
252 "lineto$1_nop" "${str##disable }"
255 "$process_line" "$str"
269 /* This file is autogenerated by tracetool, do not edit. */
271 #include "qemu-common.h"
274 echo "#endif /* TRACE_H */"
279 echo "/* This file is autogenerated by tracetool, do not edit. */"
285 "--nop" |
"--simple") backend
="${1#--}" ;;
293 "--check-backend") exit 0 ;; # used by ./configure to test for backend