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_
44 // Should match Call::no
45 typedef unsigned CallNo;
55 const char **arg_names;
63 const char **member_names;
69 signed long long value;
76 const EnumValue *values;
82 unsigned long long value;
89 const BitmaskFlag *flags;
100 virtual void visit(Visitor &visitor) = 0;
102 virtual bool toBool(void) const = 0;
103 virtual signed long long toSInt(void) const;
104 virtual unsigned long long toUInt(void) const;
105 virtual float toFloat(void) const;
106 virtual double toDouble(void) const;
108 virtual void *toPointer(void) const;
109 virtual void *toPointer(bool bind);
110 virtual unsigned long long toUIntPtr(void) const;
111 virtual const char *toString(void) const;
113 const Value & operator[](size_t index) const;
117 class Null : public Value
120 bool toBool(void) const;
121 signed long long toSInt(void) const;
122 unsigned long long toUInt(void) const;
123 virtual float toFloat(void) const;
124 virtual double toDouble(void) const;
125 void *toPointer(void) const;
126 void *toPointer(bool bind);
127 unsigned long long toUIntPtr(void) const;
128 const char *toString(void) const;
129 void visit(Visitor &visitor);
133 class Bool : public Value
136 Bool(bool _value) : value(_value) {}
138 bool toBool(void) const;
139 signed long long toSInt(void) const;
140 unsigned long long toUInt(void) const;
141 virtual float toFloat(void) const;
142 virtual double toDouble(void) const;
143 void visit(Visitor &visitor);
149 class SInt : public Value
152 SInt(signed long long _value) : value(_value) {}
154 bool toBool(void) const;
155 signed long long toSInt(void) const;
156 unsigned long long toUInt(void) const;
157 virtual float toFloat(void) const;
158 virtual double toDouble(void) const;
159 void visit(Visitor &visitor);
161 signed long long value;
165 class UInt : public Value
168 UInt(unsigned long long _value) : value(_value) {}
170 bool toBool(void) const;
171 signed long long toSInt(void) const;
172 unsigned long long toUInt(void) const;
173 virtual float toFloat(void) const;
174 virtual double toDouble(void) const;
175 void visit(Visitor &visitor);
177 unsigned long long value;
181 class Float : public Value
184 Float(float _value) : value(_value) {}
186 bool toBool(void) const;
187 signed long long toSInt(void) const;
188 unsigned long long toUInt(void) const;
189 virtual float toFloat(void) const;
190 virtual double toDouble(void) const;
191 void visit(Visitor &visitor);
197 class Double : public Value
200 Double(double _value) : value(_value) {}
202 bool toBool(void) const;
203 signed long long toSInt(void) const;
204 unsigned long long toUInt(void) const;
205 virtual float toFloat(void) const;
206 virtual double toDouble(void) const;
207 void visit(Visitor &visitor);
213 class String : public Value
216 String(const char * _value) : value(_value) {}
219 bool toBool(void) const;
220 const char *toString(void) const;
221 void visit(Visitor &visitor);
227 class Enum : public SInt
230 Enum(const EnumSig *_sig, signed long long _value) : SInt(_value), sig(_sig) {}
232 void visit(Visitor &visitor);
238 // TODO: use a std::map
239 for (const EnumValue *it = sig->values; it != sig->values + sig->num_values; ++it) {
240 if (it->value == value) {
249 class Bitmask : public UInt
252 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
254 void visit(Visitor &visitor);
256 const BitmaskSig *sig;
260 class Struct : public Value
263 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
266 bool toBool(void) const;
267 void visit(Visitor &visitor);
269 const StructSig *sig;
270 std::vector<Value *> members;
274 class Array : public Value
277 Array(size_t len) : values(len) {}
280 bool toBool(void) const;
281 void visit(Visitor &visitor);
283 std::vector<Value *> values;
287 return values.size();
292 class Blob : public Value
297 buf = new char[_size];
303 bool toBool(void) const;
304 void *toPointer(void) const;
305 void *toPointer(bool bind);
306 void visit(Visitor &visitor);
314 class Pointer : public UInt
317 Pointer(unsigned long long value) : UInt(value) {}
319 bool toBool(void) const;
320 void *toPointer(void) const;
321 void *toPointer(bool bind);
322 unsigned long long toUIntPtr(void) const;
323 void visit(Visitor &visitor);
327 class Repr : public Value
330 Repr(Value *human, Value *machine) :
332 machineValue(machine)
335 /** Human-readible value */
338 /** Machine-readible value */
341 virtual bool toBool(void) const;
342 virtual signed long long toSInt(void) const;
343 virtual unsigned long long toUInt(void) const;
344 virtual float toFloat(void) const;
345 virtual double toDouble(void) const;
347 virtual void *toPointer(void) const;
348 virtual void *toPointer(bool bind);
349 virtual unsigned long long toUIntPtr(void) const;
350 virtual const char *toString(void) const;
352 void visit(Visitor &visitor);
359 virtual void visit(Null *);
360 virtual void visit(Bool *);
361 virtual void visit(SInt *);
362 virtual void visit(UInt *);
363 virtual void visit(Float *);
364 virtual void visit(Double *);
365 virtual void visit(String *);
366 virtual void visit(Enum *);
367 virtual void visit(Bitmask *);
368 virtual void visit(Struct *);
369 virtual void visit(Array *);
370 virtual void visit(Blob *);
371 virtual void visit(Pointer *);
372 virtual void visit(Repr *);
375 inline void _visit(Value *value) {
383 typedef unsigned CallFlags;
388 * TODO: It might be better to to record some of these (but not all) into the
394 * Whether a call was really done by the application or not.
396 * This flag is set for fake calls -- calls not truly done by the application
397 * but emitted and recorded for completeness, to provide contextual information
398 * necessary for retracing, that would not be available through other ways.
400 * XXX: This one definetely needs to go into the trace file.
402 CALL_FLAG_FAKE = (1 << 0),
405 * Whether this call should be retraced or ignored.
407 * This flag is set for calls which can't be safely replayed (due to incomplete
408 * information) or that have no sideffects.
410 * Some incomplete calls are unreproduceable, but not all.
412 CALL_FLAG_NON_REPRODUCIBLE = (1 << 1),
415 * Whether this call has no side-effects, therefore don't need to be
418 * This flag is set for calls that merely query information which is not
419 * needed for posterior calls.
421 CALL_FLAG_NO_SIDE_EFFECTS = (1 << 2),
424 * Whether this call renders into the bound rendertargets.
426 CALL_FLAG_RENDER = (1 << 3),
429 * Whether this call causes render target to be swapped.
431 * This does not mark frame termination by itself -- that's solely the
432 * responsibility of `endOfFrame` bit.
434 * This mean that snapshots should be take prior to the call, and not
437 CALL_FLAG_SWAP_RENDERTARGET = (1 << 4),
440 * Whether this call terminates a frame.
442 * XXX: This can't always be determined by the function name, so it should also
443 * go into the trace file eventually.
445 CALL_FLAG_END_FRAME = (1 << 5),
448 * Whether this call is incomplete, i.e., it never returned.
450 CALL_FLAG_INCOMPLETE = (1 << 6),
453 * Whether this call is verbose (i.e., not usually interesting).
455 CALL_FLAG_VERBOSE = (1 << 7),
470 const FunctionSig *sig;
471 std::vector<Arg> args;
476 Call(const FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) :
477 thread_id(_thread_id),
479 args(_sig->num_args),
486 inline const char * name(void) const {
490 inline Value & arg(unsigned index) {
491 assert(index < args.size());
492 return *(args[index].value);
497 } /* namespace trace */
499 #endif /* _TRACE_MODEL_HPP_ */