-
Notifications
You must be signed in to change notification settings - Fork 667
/
Copy pathTrace.h
224 lines (212 loc) · 5.54 KB
/
Trace.h
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include <mutex>
#include <string>
#include "Macros.h"
#include "Util.h"
class DexMethodRef;
class DexType;
#define TMS \
TM(ACCESS) \
TM(ANNO) \
TM(API_UTILS) \
TM(ARGS) \
TM(BBPROFILE) \
TM(BIND) \
TM(BLD_PATTERN) \
TM(BPH) \
TM(BRCR) \
TM(BRIDGE) \
TM(BUILDERS) \
TM(CFG) \
TM(CFP) \
TM(CHECKRECURSION) \
TM(CIC) \
TM(CLA) \
TM(CLMG) \
TM(CLP_LITHO) \
TM(CONSTP) \
TM(CPG) \
TM(CS) \
TM(CSE) \
TM(CU) \
TM(CUSTOMSORT) \
TM(DBGSTRIP) \
TM(DC) \
TM(DCE) \
TM(DEDUP_BLOCKS) \
TM(DEDUP_RES) \
TM(DELINIT) \
TM(DELMET) \
TM(DS) \
TM(EMPTY) \
TM(ENUM) \
TM(EVALTC) \
TM(FINALINLINE) \
TM(GETTER) \
TM(GQL) \
TM(HASHER) \
TM(ICONSTP) \
TM(IDEX) \
TM(IFCS_ANALYSIS) \
TM(INL) \
TM(INLINE) \
TM(INLRES) \
TM(INSTRUMENT) \
TM(INTF) \
TM(INTRO_SWITCH) \
TM(IODI) \
TM(ISO) \
TM(LCR_PASS) \
TM(LIB) \
TM(LOC) \
TM(LOCKS) \
TM(LOOP) \
TM(MAGIC_FIELDS) \
TM(MAIN) \
TM(MARIANA_TRENCH) \
TM(MEINT) \
TM(METH_DEDUP) \
TM(METH_MERGER) \
TM(METH_PROF) \
TM(MMINL) \
TM(MODULARITY) \
TM(MONITOR) \
TM(MORTIROLO) \
TM(MTRANS) \
TM(NULLCHECK) \
TM(OBFUSCATE) \
TM(OPTRES) \
TM(OPT_STORES) \
TM(OPUT) \
TM(ORIGINALNAME) \
TM(OSDCE) \
TM(OUTLINE) \
TM(PEEPHOLE) \
TM(PGR) \
TM(PM) \
TM(POST_LOWERING) \
TM(PTA) \
TM(PURITY) \
TM(QUICK) \
TM(RABBIT) \
TM(RAL) \
TM(REACH) \
TM(REFL) \
TM(REFU) \
TM(REG) \
TM(RENAME) \
TM(RES) \
TM(RESO) \
TM(RG) \
TM(RME) \
TM(RMGOTO) \
TM(RM_INTF) \
TM(RMU) \
TM(RMUF) \
TM(RMUNINST) \
TM(RP) \
TM(SDIS) \
TM(SHORTEN) \
TM(SPLIT_RES) \
TM(STATIC_RELO) \
TM(STATS) \
TM(STRBUILD) \
TM(STR_CAT) \
TM(SUPER) \
TM(SW) \
TM(SWIN) \
TM(SWITCH_EQUIV) \
TM(SYNT) \
TM(TIME) \
TM(TP) \
TM(TRACKRESOURCES) \
TM(TRMU) \
TM(TYPE) \
TM(TYPE_TRANSFORM) \
TM(UCM) \
TM(UNREF_INTF) \
TM(USES_NAMES) \
TM(VERIFY) \
TM(VIRT) \
TM(VM) \
TM(VMERGE) \
/* End of list */
enum TraceModule : int {
#define TM(x) x,
TMS
#undef TM
N_TRACE_MODULES,
};
// To avoid "-Wunused" warnings, keep the TRACE macros in common so that the
// compiler sees a "use." However, ensure that it is optimized away through
// a constexpr condition in NDEBUG mode.
#ifdef NDEBUG
constexpr bool traceEnabled(TraceModule, int) { return false; }
#else
bool traceEnabled(TraceModule module, int level);
#endif // NDEBUG
void trace(
TraceModule module, int level, bool suppress_newline, const char* fmt, ...);
#define TRACE(module, level, fmt, ...) \
do { \
if (traceEnabled(module, level)) { \
trace(module, level, /* suppress_newline */ false, fmt, ##__VA_ARGS__); \
} \
} while (0)
#define TRACE_NO_LINE(module, level, fmt, ...) \
do { \
if (traceEnabled(module, level)) { \
trace(module, level, /* suppress_newline */ true, fmt, ##__VA_ARGS__); \
} \
} while (0)
class TraceContext {
public:
explicit TraceContext(const DexMethodRef* current_method) {
#if !IS_WINDOWS
last_context = s_context;
s_context = this;
method = current_method;
string_value = &string_value_cache;
#endif
}
explicit TraceContext(const DexType* current_type) {
#if !IS_WINDOWS
last_context = s_context;
s_context = this;
type = current_type;
string_value = &string_value_cache;
#endif
}
explicit TraceContext(const std::string* string_value) {
#if !IS_WINDOWS
last_context = s_context;
s_context = this;
this->string_value = string_value;
#endif
}
~TraceContext() {
#if !IS_WINDOWS
s_context = last_context;
#endif
}
#if !IS_WINDOWS
const std::string& get_string_value() const;
#endif
private:
#if !IS_WINDOWS
thread_local static const TraceContext* s_context;
const TraceContext* last_context{nullptr};
const DexMethodRef* method{nullptr};
const DexType* type{nullptr};
const std::string* string_value{nullptr};
mutable std::string string_value_cache;
#endif
friend struct TraceContextAccess;
};