master
py 78 lines 2.67 KB
Raw
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 """
4 trace/generated-tracers.dtrace (DTrace only).
5 """
6
7 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
8 __copyright__ = "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
9 __license__ = "GPL version 2 or (at your option) any later version"
10
11 __maintainer__ = "Stefan Hajnoczi"
12 __email__ = "stefanha@redhat.com"
13
14
15 from tracetool import out
16 from sys import platform
17
18
19 # Reserved keywords from
20 # https://wikis.oracle.com/display/DTrace/Types,+Operators+and+Expressions
21 RESERVED_WORDS = (
22 'auto', 'goto', 'sizeof', 'break', 'if', 'static', 'case', 'import',
23 'string', 'char', 'inline', 'stringof', 'const', 'int', 'struct',
24 'continue', 'long', 'switch', 'counter', 'offsetof', 'this',
25 'default', 'probe', 'translator', 'do', 'provider', 'typedef',
26 'double', 'register', 'union', 'else', 'restrict', 'unsigned',
27 'enum', 'return', 'void', 'extern', 'self', 'volatile', 'float',
28 'short', 'while', 'for', 'signed', 'xlate',
29 )
30
31
32 def generate(events, backend, group):
33 events = [e for e in events
34 if "disable" not in e.properties]
35
36 # SystemTap's dtrace(1) warns about empty "provider qemu {}" but is happy
37 # with an empty file. Avoid the warning.
38 # But dtrace on macOS can't deal with empty files.
39 if not events and platform != "darwin":
40 return
41
42 out('/* This file is autogenerated by tracetool, do not edit. */',
43 '/* SPDX-License-Identifier: GPL-2.0-or-later */',
44 '',
45 'provider qemu {')
46
47 for e in events:
48 args = []
49 for type_, name in e.args:
50 if platform == "darwin":
51 # macOS dtrace accepts only C99 _Bool
52 if type_ == 'bool':
53 type_ = '_Bool'
54 if type_ == 'bool *':
55 type_ = '_Bool *'
56 # It converts int8_t * in probe points to char * in header
57 # files and introduces [-Wpointer-sign] warning.
58 # Avoid it by changing probe type to signed char * beforehand.
59 if type_ == 'int8_t *':
60 type_ = 'signed char *'
61
62 # SystemTap dtrace(1) emits a warning when long long is used
63 type_ = type_.replace('unsigned long long', 'uint64_t')
64 type_ = type_.replace('signed long long', 'int64_t')
65 type_ = type_.replace('long long', 'int64_t')
66
67 if name in RESERVED_WORDS:
68 name += '_'
69 args.append(type_ + ' ' + name)
70
71 # Define prototype for probe arguments
72 out('',
73 'probe %(name)s(%(args)s);',
74 name=e.name,
75 args=','.join(args))
76
77 out('',
78 '};')