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);
355 struct RawStackFrame {
358 const char * function;
359 const char * filename;
372 class StackFrame : public RawStackFrame {
377 typedef std::vector<StackFrame *> Backtrace;
382 virtual void visit(Null *);
383 virtual void visit(Bool *);
384 virtual void visit(SInt *);
385 virtual void visit(UInt *);
386 virtual void visit(Float *);
387 virtual void visit(Double *);
388 virtual void visit(String *);
389 virtual void visit(Enum *);
390 virtual void visit(Bitmask *);
391 virtual void visit(Struct *);
392 virtual void visit(Array *);
393 virtual void visit(Blob *);
394 virtual void visit(Pointer *);
395 virtual void visit(Repr *);
396 virtual void visit(Backtrace *);
397 virtual void visit(StackFrame *);
399 inline void _visit(Value *value) {
407 typedef unsigned CallFlags;
412 * TODO: It might be better to to record some of these (but not all) into the
418 * Whether a call was really done by the application or not.
420 * This flag is set for fake calls -- calls not truly done by the application
421 * but emitted and recorded for completeness, to provide contextual information
422 * necessary for retracing, that would not be available through other ways.
424 * XXX: This one definetely needs to go into the trace file.
426 CALL_FLAG_FAKE = (1 << 0),
429 * Whether this call should be retraced or ignored.
431 * This flag is set for calls which can't be safely replayed (due to incomplete
432 * information) or that have no sideffects.
434 * Some incomplete calls are unreproduceable, but not all.
436 CALL_FLAG_NON_REPRODUCIBLE = (1 << 1),
439 * Whether this call has no side-effects, therefore don't need to be
442 * This flag is set for calls that merely query information which is not
443 * needed for posterior calls.
445 CALL_FLAG_NO_SIDE_EFFECTS = (1 << 2),
448 * Whether this call renders into the bound rendertargets.
450 CALL_FLAG_RENDER = (1 << 3),
453 * Whether this call causes render target to be swapped.
455 * This does not mark frame termination by itself -- that's solely the
456 * responsibility of `endOfFrame` bit.
458 * This mean that snapshots should be take prior to the call, and not
461 CALL_FLAG_SWAP_RENDERTARGET = (1 << 4),
464 * Whether this call terminates a frame.
466 * XXX: This can't always be determined by the function name, so it should also
467 * go into the trace file eventually.
469 CALL_FLAG_END_FRAME = (1 << 5),
472 * Whether this call is incomplete, i.e., it never returned.
474 CALL_FLAG_INCOMPLETE = (1 << 6),
477 * Whether this call is verbose (i.e., not usually interesting).
479 CALL_FLAG_VERBOSE = (1 << 7),
494 const FunctionSig *sig;
495 std::vector<Arg> args;
499 Backtrace* backtrace;
501 Call(const FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) :
502 thread_id(_thread_id),
504 args(_sig->num_args),
512 inline const char * name(void) const {
516 inline Value & arg(unsigned index) {
517 assert(index < args.size());
518 return *(args[index].value);
523 } /* namespace trace */
525 #endif /* _TRACE_MODEL_HPP_ */