target-i386: Use mulu2 and muls2
[qemu/pbrook.git] / scripts / tracetool.py
blobc003cf69eded3df2beadf7e9b44eb51627bee185
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 """
5 Command-line wrapper for the tracetool machinery.
6 """
8 __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>"
9 __copyright__ = "Copyright 2012, Lluís Vilanova <vilanova@ac.upc.edu>"
10 __license__ = "GPL version 2 or (at your option) any later version"
12 __maintainer__ = "Stefan Hajnoczi"
13 __email__ = "stefanha@linux.vnet.ibm.com"
16 import sys
17 import getopt
19 from tracetool import error_write, out
20 import tracetool.backend
21 import tracetool.format
24 _SCRIPT = ""
26 def error_opt(msg = None):
27 if msg is not None:
28 error_write("Error: " + msg + "\n")
30 backend_descr = "\n".join([ " %-15s %s" % (n, d)
31 for n,d in tracetool.backend.get_list() ])
32 format_descr = "\n".join([ " %-15s %s" % (n, d)
33 for n,d in tracetool.format.get_list() ])
34 error_write("""\
35 Usage: %(script)s --format=<format> --backend=<backend> [<options>]
37 Backends:
38 %(backends)s
40 Formats:
41 %(formats)s
43 Options:
44 --help This help message.
45 --list-backends Print list of available backends.
46 --check-backend Check if the given backend is valid.
47 --binary <path> Full path to QEMU binary.
48 --target-type <type> QEMU emulator target type ('system' or 'user').
49 --target-arch <arch> QEMU emulator target arch.
50 --probe-prefix <prefix> Prefix for dtrace probe names
51 (default: qemu-<target-type>-<target-arch>).\
52 """ % {
53 "script" : _SCRIPT,
54 "backends" : backend_descr,
55 "formats" : format_descr,
58 if msg is None:
59 sys.exit(0)
60 else:
61 sys.exit(1)
64 def main(args):
65 global _SCRIPT
66 _SCRIPT = args[0]
68 long_opts = [ "backend=", "format=", "help", "list-backends", "check-backend" ]
69 long_opts += [ "binary=", "target-type=", "target-arch=", "probe-prefix=" ]
71 try:
72 opts, args = getopt.getopt(args[1:], "", long_opts)
73 except getopt.GetoptError, err:
74 error_opt(str(err))
76 check_backend = False
77 arg_backend = ""
78 arg_format = ""
79 binary = None
80 target_type = None
81 target_arch = None
82 probe_prefix = None
83 for opt, arg in opts:
84 if opt == "--help":
85 error_opt()
87 elif opt == "--backend":
88 arg_backend = arg
89 elif opt == "--format":
90 arg_format = arg
92 elif opt == "--list-backends":
93 backends = tracetool.backend.get_list()
94 out(", ".join([ b for b,_ in backends ]))
95 sys.exit(0)
96 elif opt == "--check-backend":
97 check_backend = True
99 elif opt == "--binary":
100 binary = arg
101 elif opt == '--target-type':
102 target_type = arg
103 elif opt == '--target-arch':
104 target_arch = arg
105 elif opt == '--probe-prefix':
106 probe_prefix = arg
108 else:
109 error_opt("unhandled option: %s" % opt)
111 if arg_backend is None:
112 error_opt("backend not set")
114 if check_backend:
115 if tracetool.backend.exists(arg_backend):
116 sys.exit(0)
117 else:
118 sys.exit(1)
120 if arg_format == "stap":
121 if binary is None:
122 error_opt("--binary is required for SystemTAP tapset generator")
123 if probe_prefix is None and target_type is None:
124 error_opt("--target-type is required for SystemTAP tapset generator")
125 if probe_prefix is None and target_arch is None:
126 error_opt("--target-arch is required for SystemTAP tapset generator")
128 if probe_prefix is None:
129 probe_prefix = ".".join([ "qemu", target_type, target_arch ])
131 try:
132 tracetool.generate(sys.stdin, arg_format, arg_backend,
133 binary = binary, probe_prefix = probe_prefix)
134 except tracetool.TracetoolError, e:
135 error_opt(str(e))
137 if __name__ == "__main__":
138 main(sys.argv)