1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
27 * Object hierarchy for describing the traces in memory.
30 #ifndef _TRACE_MODEL_HPP_
31 #define _TRACE_MODEL_HPP_
51 const char **arg_names;
59 const char **member_names;
65 signed long long value;
72 const EnumValue *values;
78 unsigned long long value;
85 const BitmaskFlag *flags;
96 virtual void visit(Visitor &visitor) = 0;
98 virtual bool toBool(void) const = 0;
99 virtual signed long long toSInt(void) const;
100 virtual unsigned long long toUInt(void) const;
101 virtual float toFloat(void) const;
102 virtual double toDouble(void) const;
104 virtual void *toPointer(void) const;
105 virtual void *toPointer(bool bind);
106 virtual unsigned long long toUIntPtr(void) const;
107 virtual const char *toString(void) const;
109 const Value & operator[](size_t index) const;
111 void dump(std::ostream &os, bool color=true);
115 class Null : public Value
118 bool toBool(void) const;
119 signed long long toSInt(void) const;
120 unsigned long long toUInt(void) const;
121 virtual float toFloat(void) const;
122 virtual double toDouble(void) const;
123 void *toPointer(void) const;
124 void *toPointer(bool bind);
125 unsigned long long toUIntPtr(void) const;
126 const char *toString(void) const;
127 void visit(Visitor &visitor);
131 class Bool : public Value
134 Bool(bool _value) : value(_value) {}
136 bool toBool(void) const;
137 signed long long toSInt(void) const;
138 unsigned long long toUInt(void) const;
139 virtual float toFloat(void) const;
140 virtual double toDouble(void) const;
141 void visit(Visitor &visitor);
147 class SInt : public Value
150 SInt(signed long long _value) : value(_value) {}
152 bool toBool(void) const;
153 signed long long toSInt(void) const;
154 unsigned long long toUInt(void) const;
155 virtual float toFloat(void) const;
156 virtual double toDouble(void) const;
157 void visit(Visitor &visitor);
159 signed long long value;
163 class UInt : public Value
166 UInt(unsigned long long _value) : value(_value) {}
168 bool toBool(void) const;
169 signed long long toSInt(void) const;
170 unsigned long long toUInt(void) const;
171 virtual float toFloat(void) const;
172 virtual double toDouble(void) const;
173 void visit(Visitor &visitor);
175 unsigned long long value;
179 class Float : public Value
182 Float(float _value) : value(_value) {}
184 bool toBool(void) const;
185 signed long long toSInt(void) const;
186 unsigned long long toUInt(void) const;
187 virtual float toFloat(void) const;
188 virtual double toDouble(void) const;
189 void visit(Visitor &visitor);
195 class Double : public Value
198 Double(double _value) : value(_value) {}
200 bool toBool(void) const;
201 signed long long toSInt(void) const;
202 unsigned long long toUInt(void) const;
203 virtual float toFloat(void) const;
204 virtual double toDouble(void) const;
205 void visit(Visitor &visitor);
211 class String : public Value
214 String(const char * _value) : value(_value) {}
217 bool toBool(void) const;
218 const char *toString(void) const;
219 void visit(Visitor &visitor);
225 class Enum : public SInt
228 Enum(const EnumSig *_sig, signed long long _value) : SInt(_value), sig(_sig) {}
230 void visit(Visitor &visitor);
236 class Bitmask : public UInt
239 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
241 void visit(Visitor &visitor);
243 const BitmaskSig *sig;
247 class Struct : public Value
250 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
253 bool toBool(void) const;
254 void visit(Visitor &visitor);
256 const StructSig *sig;
257 std::vector<Value *> members;
261 class Array : public Value
264 Array(size_t len) : values(len) {}
267 bool toBool(void) const;
268 void visit(Visitor &visitor);
270 std::vector<Value *> values;
274 class Blob : public Value
279 buf = new char[_size];
285 bool toBool(void) const;
286 void *toPointer(void) const;
287 void *toPointer(bool bind);
288 void visit(Visitor &visitor);
296 class Pointer : public UInt
299 Pointer(unsigned long long value) : UInt(value) {}
301 bool toBool(void) const;
302 void *toPointer(void) const;
303 void *toPointer(bool bind);
304 unsigned long long toUIntPtr(void) const;
305 void visit(Visitor &visitor);
312 virtual void visit(Null *);
313 virtual void visit(Bool *);
314 virtual void visit(SInt *);
315 virtual void visit(UInt *);
316 virtual void visit(Float *);
317 virtual void visit(Double *);
318 virtual void visit(String *);
319 virtual void visit(Enum *);
320 virtual void visit(Bitmask *);
321 virtual void visit(Struct *);
322 virtual void visit(Array *);
323 virtual void visit(Blob *);
324 virtual void visit(Pointer *);
327 inline void _visit(Value *value) {
335 inline std::ostream & operator <<(std::ostream &os, Value *value) {
343 typedef unsigned CallFlags;
348 * TODO: It might be better to to record some of these (but not all) into the
354 * Whether a call was really done by the application or not.
356 * This flag is set for fake calls -- calls not truly done by the application
357 * but emitted and recorded for completeness, to provide contextual information
358 * necessary for retracing, that would not be available through other ways.
360 * XXX: This one definetely needs to go into the trace file.
362 CALL_FLAG_FAKE = (1 << 0),
365 * Whether this call should be retraced or ignored.
367 * This flag is set for calls which can't be safely replayed (due to incomplete
368 * information) or that have no sideffects.
370 * Some incomplete calls are unreproduceable, but not all.
372 CALL_FLAG_NON_REPRODUCIBLE = (1 << 1),
375 * Whether this call has no side-effects, therefore don't need to be
378 * This flag is set for calls that merely query information which is not
379 * needed for posterior calls.
381 CALL_FLAG_NO_SIDE_EFFECTS = (1 << 2),
384 * Whether this call renders into the bound rendertargets.
386 CALL_FLAG_RENDER = (1 << 3),
389 * Whether this call causes render target to be swapped.
391 * This does not mark frame termination by itself -- that's solely the
392 * responsibility of `endOfFrame` bit.
394 * This mean that snapshots should be take prior to the call, and not
397 CALL_FLAG_SWAP_RENDERTARGET = (1 << 4),
400 * Whether this call terminates a frame.
402 * XXX: This can't always be determined by the function name, so it should also
403 * go into the trace file eventually.
405 CALL_FLAG_END_FRAME = (1 << 5),
408 * Whether this call is incomplete, i.e., it never returned.
410 CALL_FLAG_INCOMPLETE = (1 << 6),
413 * Whether this call is verbose (i.e., not usually interesting).
415 CALL_FLAG_VERBOSE = (1 << 7),
424 const FunctionSig *sig;
425 std::vector<Value *> args;
430 Call(FunctionSig *_sig, const CallFlags &_flags) :
432 args(_sig->num_args),
439 inline const char * name(void) const {
443 inline Value & arg(unsigned index) {
444 assert(index < args.size());
445 return *(args[index]);
448 void dump(std::ostream &os, bool color=true);
452 inline std::ostream & operator <<(std::ostream &os, Call &call) {
458 } /* namespace trace */
460 #endif /* _TRACE_MODEL_HPP_ */