xref: /openbmc/qemu/scripts/tracetool/format/d.py (revision 6016b7b4)
1# -*- coding: utf-8 -*-
2
3"""
4trace/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
15from tracetool import out
16from sys import platform
17
18
19# Reserved keywords from
20# https://wikis.oracle.com/display/DTrace/Types,+Operators+and+Expressions
21RESERVED_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
32def 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        '',
44        'provider qemu {')
45
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 *'
60
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')
65
66            if name in RESERVED_WORDS:
67                name += '_'
68            args.append(type_ + ' ' + name)
69
70        # Define prototype for probe arguments
71        out('',
72            'probe %(name)s(%(args)s);',
73            name=e.name,
74            args=','.join(args))
75
76    out('',
77        '};')
78