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;
113 class Null : public Value
116 bool toBool(void) const;
117 signed long long toSInt(void) const;
118 unsigned long long toUInt(void) const;
119 virtual float toFloat(void) const;
120 virtual double toDouble(void) const;
121 void *toPointer(void) const;
122 void *toPointer(bool bind);
123 unsigned long long toUIntPtr(void) const;
124 const char *toString(void) const;
125 void visit(Visitor &visitor);
129 class Bool : public Value
132 Bool(bool _value) : value(_value) {}
134 bool toBool(void) const;
135 signed long long toSInt(void) const;
136 unsigned long long toUInt(void) const;
137 virtual float toFloat(void) const;
138 virtual double toDouble(void) const;
139 void visit(Visitor &visitor);
145 class SInt : public Value
148 SInt(signed long long _value) : value(_value) {}
150 bool toBool(void) const;
151 signed long long toSInt(void) const;
152 unsigned long long toUInt(void) const;
153 virtual float toFloat(void) const;
154 virtual double toDouble(void) const;
155 void visit(Visitor &visitor);
157 signed long long value;
161 class UInt : public Value
164 UInt(unsigned long long _value) : value(_value) {}
166 bool toBool(void) const;
167 signed long long toSInt(void) const;
168 unsigned long long toUInt(void) const;
169 virtual float toFloat(void) const;
170 virtual double toDouble(void) const;
171 void visit(Visitor &visitor);
173 unsigned long long value;
177 class Float : public Value
180 Float(float _value) : value(_value) {}
182 bool toBool(void) const;
183 signed long long toSInt(void) const;
184 unsigned long long toUInt(void) const;
185 virtual float toFloat(void) const;
186 virtual double toDouble(void) const;
187 void visit(Visitor &visitor);
193 class Double : public Value
196 Double(double _value) : value(_value) {}
198 bool toBool(void) const;
199 signed long long toSInt(void) const;
200 unsigned long long toUInt(void) const;
201 virtual float toFloat(void) const;
202 virtual double toDouble(void) const;
203 void visit(Visitor &visitor);
209 class String : public Value
212 String(const char * _value) : value(_value) {}
215 bool toBool(void) const;
216 const char *toString(void) const;
217 void visit(Visitor &visitor);
223 class Enum : public SInt
226 Enum(const EnumSig *_sig, signed long long _value) : SInt(_value), sig(_sig) {}
228 void visit(Visitor &visitor);
234 // TODO: use a std::map
235 for (const EnumValue *it = sig->values; it != sig->values + sig->num_values; ++it) {
236 if (it->value == value) {
245 class Bitmask : public UInt
248 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
250 void visit(Visitor &visitor);
252 const BitmaskSig *sig;
256 class Struct : public Value
259 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
262 bool toBool(void) const;
263 void visit(Visitor &visitor);
265 const StructSig *sig;
266 std::vector<Value *> members;
270 class Array : public Value
273 Array(size_t len) : values(len) {}
276 bool toBool(void) const;
277 void visit(Visitor &visitor);
279 std::vector<Value *> values;
283 return values.size();
288 class Blob : public Value
293 buf = new char[_size];
299 bool toBool(void) const;
300 void *toPointer(void) const;
301 void *toPointer(bool bind);
302 void visit(Visitor &visitor);
310 class Pointer : public UInt
313 Pointer(unsigned long long value) : UInt(value) {}
315 bool toBool(void) const;
316 void *toPointer(void) const;
317 void *toPointer(bool bind);
318 unsigned long long toUIntPtr(void) const;
319 void visit(Visitor &visitor);
323 class Repr : public Value
326 Repr(Value *human, Value *machine) :
328 machineValue(machine)
331 /** Human-readible value */
334 /** Machine-readible value */
337 virtual bool toBool(void) const;
338 virtual signed long long toSInt(void) const;
339 virtual unsigned long long toUInt(void) const;
340 virtual float toFloat(void) const;
341 virtual double toDouble(void) const;
343 virtual void *toPointer(void) const;
344 virtual void *toPointer(bool bind);
345 virtual unsigned long long toUIntPtr(void) const;
346 virtual const char *toString(void) const;
348 void visit(Visitor &visitor);
355 virtual void visit(Null *);
356 virtual void visit(Bool *);
357 virtual void visit(SInt *);
358 virtual void visit(UInt *);
359 virtual void visit(Float *);
360 virtual void visit(Double *);
361 virtual void visit(String *);
362 virtual void visit(Enum *);
363 virtual void visit(Bitmask *);
364 virtual void visit(Struct *);
365 virtual void visit(Array *);
366 virtual void visit(Blob *);
367 virtual void visit(Pointer *);
368 virtual void visit(Repr *);
371 inline void _visit(Value *value) {
379 typedef unsigned CallFlags;
384 * TODO: It might be better to to record some of these (but not all) into the
390 * Whether a call was really done by the application or not.
392 * This flag is set for fake calls -- calls not truly done by the application
393 * but emitted and recorded for completeness, to provide contextual information
394 * necessary for retracing, that would not be available through other ways.
396 * XXX: This one definetely needs to go into the trace file.
398 CALL_FLAG_FAKE = (1 << 0),
401 * Whether this call should be retraced or ignored.
403 * This flag is set for calls which can't be safely replayed (due to incomplete
404 * information) or that have no sideffects.
406 * Some incomplete calls are unreproduceable, but not all.
408 CALL_FLAG_NON_REPRODUCIBLE = (1 << 1),
411 * Whether this call has no side-effects, therefore don't need to be
414 * This flag is set for calls that merely query information which is not
415 * needed for posterior calls.
417 CALL_FLAG_NO_SIDE_EFFECTS = (1 << 2),
420 * Whether this call renders into the bound rendertargets.
422 CALL_FLAG_RENDER = (1 << 3),
425 * Whether this call causes render target to be swapped.
427 * This does not mark frame termination by itself -- that's solely the
428 * responsibility of `endOfFrame` bit.
430 * This mean that snapshots should be take prior to the call, and not
433 CALL_FLAG_SWAP_RENDERTARGET = (1 << 4),
436 * Whether this call terminates a frame.
438 * XXX: This can't always be determined by the function name, so it should also
439 * go into the trace file eventually.
441 CALL_FLAG_END_FRAME = (1 << 5),
444 * Whether this call is incomplete, i.e., it never returned.
446 CALL_FLAG_INCOMPLETE = (1 << 6),
449 * Whether this call is verbose (i.e., not usually interesting).
451 CALL_FLAG_VERBOSE = (1 << 7),
466 const FunctionSig *sig;
467 std::vector<Arg> args;
472 Call(FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) :
473 thread_id(_thread_id),
475 args(_sig->num_args),
482 inline const char * name(void) const {
486 inline Value & arg(unsigned index) {
487 assert(index < args.size());
488 return *(args[index].value);
493 } /* namespace trace */
495 #endif /* _TRACE_MODEL_HPP_ */