Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-virtiofs-20210413...
[qemu/ar7.git] / scripts / tracetool / format / d.py
blobebfb7142002660527bfdc0476bc8cfb6713994ae
1 # -*- coding: utf-8 -*-
3 """
4 trace/generated-tracers.dtrace (DTrace only).
5 """
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"
11 __maintainer__ = "Stefan Hajnoczi"
12 __email__ = "stefanha@redhat.com"
15 from tracetool import out
16 from sys import platform
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',
32 def generate(events, backend, group):
33 events = [e for e in events
34 if "disable" not in e.properties]
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
42 out('/* This file is autogenerated by tracetool, do not edit. */'
43 '',
44 'provider qemu {')
46 for e in events:
47 args = []
48 for type_, name in e.args:
49 if platform == "darwin":
50 # macOS dtrace accepts only C99 _Bool
51 if type_ == 'bool':
52 type_ = '_Bool'
53 if type_ == 'bool *':
54 type_ = '_Bool *'
55 # It converts int8_t * in probe points to char * in header
56 # files and introduces [-Wpointer-sign] warning.
57 # Avoid it by changing probe type to signed char * beforehand.
58 if type_ == 'int8_t *':
59 type_ = 'signed char *'
61 # SystemTap dtrace(1) emits a warning when long long is used
62 type_ = type_.replace('unsigned long long', 'uint64_t')
63 type_ = type_.replace('signed long long', 'int64_t')
64 type_ = type_.replace('long long', 'int64_t')
66 if name in RESERVED_WORDS:
67 name += '_'
68 args.append(type_ + ' ' + name)
70 # Define prototype for probe arguments
71 out('',
72 'probe %(name)s(%(args)s);',
73 name=e.name,
74 args=','.join(args))
76 out('',
77 '};')