-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathTraceOptions.v3
134 lines (129 loc) · 4.51 KB
/
TraceOptions.v3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2021 Ben L. Titzer. All rights reserved.
// See LICENSE for details of Apache 2.0 license.
// Options that can be specified on the command line.
enum TraceOption(ch: byte, help: string) {
int('i', "interpreter"),
binparse('b', "binary parser"),
validation('v', "code validation"),
test('t', "test framework"),
spectest('s', "specification tests"),
operands('o', "interpreter stack contents"),
memory('m', "memory accesses"),
canon('c', "type canonicalization"),
uid('u', "internal unique IDs"),
compiler('k', "compiler(s)"),
asm('a', "generated assembly (must be used with -tk)"),
stack('y', "stacks"),
exception('x', "exceptions"),
linking('l', "linking"),
whamm('w', "whamm monitoring")
}
// Parses and updates trace options based on arguments.
component TraceOptions {
def group = OptionsRegistry.newGroup("TRACING", printHelp);
def NO_NAMES = group.newBoolOption("no-names", false, "Disables parsing and reporting from the name section.");
def COLORS = group.newBoolOption("colors", true, "Enable or disable terminal colors.")
.onSet(Palettes.reset);
def FATAL = group.newFlag("fatal", setFatal, "Aborts upon parsing, validation, or test failure.");
def X_ = OptionsRegistry.addParseFunc(parse);
def setFatal(str: string) {
if (str == null || Strings.equal(str, "true")) Trace.fatal = true;
}
// Parse command-line argument and update trace flags. Return {true} if the
// argument was matched as a trace flag.
def parse(arg: string, err: ErrorGen) -> bool {
if (Strings.startsWith(arg, "--trace-")) {
for (opt in TraceOption) {
if (Strings.endsWithFrom(arg, 8, opt.name)) {
setOption(opt);
return true;
}
}
var traceModule = "--trace-module";
if (Strings.startsWith(arg, traceModule)) {
var pat: string;
if (arg.length >= (traceModule.length + 1) && arg[traceModule.length] == '=') {
pat = Arrays.range(arg, traceModule.length + 1, arg.length);
}
BasicTracing.moduleFilter = DeclFilters.parseString(pat);
return true;
}
var traceCalls = "--trace-calls";
if (Strings.startsWith(arg, traceCalls)) {
var pat: string;
if (arg.length >= (traceCalls.length + 1) && arg[traceCalls.length] == '=') {
pat = Arrays.range(arg, traceCalls.length + 1, arg.length);
}
BasicTracing.callsFilter = DeclFilters.parseString(pat);
return true;
}
} else if (Strings.startsWith(arg, "-t")) {
for (i = 2; i < arg.length; i++) {
var ch = arg[i];
for (opt in TraceOption) {
if (ch == opt.ch) setOption(opt);
}
}
return true;
}
if (Strings.equal(arg, "--metrics")) {
Metrics.enableAll();
return true;
}
var prefix = "--metrics=";
if (Strings.startsWith(arg, prefix)) {
var pat = Arrays.range(arg, prefix.length, arg.length);
var glob = GlobMatcher.new(pat);
Metrics.enable(glob);
return true;
}
return false;
}
private def setOption(opt: TraceOption) {
match (opt) {
int => { Trace.interpreter = true; BasicTracing.enableTraceInt(); }
binparse => Trace.binparse = true;
validation => Trace.validation = true;
test => Trace.test = true;
spectest => Trace.spectest = true;
operands => Trace.operands = true;
memory => { Trace.memory = true; BasicTracing.memoryFilter = DeclFilters.parseString(null); }
canon => { Trace.canon = true; Trace.uid = true; }
uid => Trace.uid = true;
compiler => Trace.compiler = true;
asm => Trace.asm = true;
stack => Trace.stack = true;
exception => Trace.exception = true;
linking => Trace.linking = true;
whamm => Trace.whamm = true;
}
}
def printHelp(out: TraceBuilder) {
var H = out.putsln, L = out.ln;
H("A number of tracing options enable debugging output from various components of the engine.");
H("These options help debug both the engine and wasm modules, including ones that are");
H("malformed or have type errors.");
H("Note that the '-t' short form supports multiple combined options, such as '-tiov'.");
L();
for (t in TraceOption) {
out.puts(" -t");
out.putc(t.ch);
out.puts(" --trace-");
out.puts(t.name);
out.pad(' ', 32);
out.puts("trace ");
out.puts(t.help);
out.ln();
}
L();
H(" --trace-module[=<module pattern*>]");
H(" Trace calls into the given module(s).");
H(" --trace-calls[=<function pattern*>]");
H(" Trace calls into and out of the given functions(s). The pattern can use function");
H(" names from the module or function indexes.");
L();
H(" --metrics[=<pattern*>]");
H(" Reports the given metrics.");
group.print(out, false);
}
}