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;
103 virtual void visit(Visitor &visitor) = 0;
105 virtual bool toBool(void) const = 0;
106 virtual signed long long toSInt(void) const;
107 virtual unsigned long long toUInt(void) const;
108 virtual float toFloat(void) const;
109 virtual double toDouble(void) const;
111 virtual void *toPointer(void) const;
112 virtual void *toPointer(bool bind);
113 virtual unsigned long long toUIntPtr(void) const;
114 virtual const char *toString(void) const;
116 virtual const Null *toNull(void) const { return NULL; }
117 virtual Null *toNull(void) { return NULL; }
119 virtual const Array *toArray(void) const { return NULL; }
120 virtual Array *toArray(void) { return NULL; }
122 virtual const Struct *toStruct(void) const { return NULL; }
123 virtual Struct *toStruct(void) { return NULL; }
125 const Value & operator[](size_t index) const;
129 class Null : public Value
132 bool toBool(void) const;
133 signed long long toSInt(void) const;
134 unsigned long long toUInt(void) const;
135 virtual float toFloat(void) const;
136 virtual double toDouble(void) const;
137 void *toPointer(void) const;
138 void *toPointer(bool bind);
139 unsigned long long toUIntPtr(void) const;
140 const char *toString(void) const;
141 void visit(Visitor &visitor);
143 const Null *toNull(void) const { return this; }
144 Null *toNull(void) { return this; }
148 class Bool : public Value
151 Bool(bool _value) : value(_value) {}
153 bool toBool(void) const;
154 signed long long toSInt(void) const;
155 unsigned long long toUInt(void) const;
156 virtual float toFloat(void) const;
157 virtual double toDouble(void) const;
158 void visit(Visitor &visitor);
164 class SInt : public Value
167 SInt(signed long long _value) : value(_value) {}
169 bool toBool(void) const;
170 signed long long toSInt(void) const;
171 unsigned long long toUInt(void) const;
172 virtual float toFloat(void) const;
173 virtual double toDouble(void) const;
174 void visit(Visitor &visitor);
176 signed long long value;
180 class UInt : public Value
183 UInt(unsigned long long _value) : value(_value) {}
185 bool toBool(void) const;
186 signed long long toSInt(void) const;
187 unsigned long long toUInt(void) const;
188 virtual float toFloat(void) const;
189 virtual double toDouble(void) const;
190 void visit(Visitor &visitor);
192 unsigned long long value;
196 class Float : public Value
199 Float(float _value) : value(_value) {}
201 bool toBool(void) const;
202 signed long long toSInt(void) const;
203 unsigned long long toUInt(void) const;
204 virtual float toFloat(void) const;
205 virtual double toDouble(void) const;
206 void visit(Visitor &visitor);
212 class Double : public Value
215 Double(double _value) : value(_value) {}
217 bool toBool(void) const;
218 signed long long toSInt(void) const;
219 unsigned long long toUInt(void) const;
220 virtual float toFloat(void) const;
221 virtual double toDouble(void) const;
222 void visit(Visitor &visitor);
228 class String : public Value
231 String(const char * _value) : value(_value) {}
234 bool toBool(void) const;
235 const char *toString(void) const;
236 void visit(Visitor &visitor);
242 class Enum : public SInt
245 Enum(const EnumSig *_sig, signed long long _value) : SInt(_value), sig(_sig) {}
247 void visit(Visitor &visitor);
253 // TODO: use a std::map
254 for (const EnumValue *it = sig->values; it != sig->values + sig->num_values; ++it) {
255 if (it->value == value) {
264 class Bitmask : public UInt
267 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
269 void visit(Visitor &visitor);
271 const BitmaskSig *sig;
275 class Struct : public Value
278 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
281 bool toBool(void) const;
282 void visit(Visitor &visitor);
284 const Struct *toStruct(void) const { return this; }
285 Struct *toStruct(void) { return this; }
287 const StructSig *sig;
288 std::vector<Value *> members;
292 class Array : public Value
295 Array(size_t len) : values(len) {}
298 bool toBool(void) const;
299 void visit(Visitor &visitor);
301 const Array *toArray(void) const { return this; }
302 Array *toArray(void) { return this; }
304 std::vector<Value *> values;
308 return values.size();
313 class Blob : public Value
318 buf = new char[_size];
324 bool toBool(void) const;
325 void *toPointer(void) const;
326 void *toPointer(bool bind);
327 void visit(Visitor &visitor);
335 class Pointer : public UInt
338 Pointer(unsigned long long value) : UInt(value) {}
340 bool toBool(void) const;
341 void *toPointer(void) const;
342 void *toPointer(bool bind);
343 unsigned long long toUIntPtr(void) const;
344 void visit(Visitor &visitor);
348 class Repr : public Value
351 Repr(Value *human, Value *machine) :
353 machineValue(machine)
356 /** Human-readible value */
359 /** Machine-readible value */
362 virtual bool toBool(void) const;
363 virtual signed long long toSInt(void) const;
364 virtual unsigned long long toUInt(void) const;
365 virtual float toFloat(void) const;
366 virtual double toDouble(void) const;
368 virtual void *toPointer(void) const;
369 virtual void *toPointer(bool bind);
370 virtual unsigned long long toUIntPtr(void) const;
371 virtual const char *toString(void) const;
373 void visit(Visitor &visitor);
376 struct RawStackFrame {
379 const char * function;
380 const char * filename;
393 class StackFrame : public RawStackFrame {
398 typedef std::vector<StackFrame *> Backtrace;
403 virtual void visit(Null *);
404 virtual void visit(Bool *);
405 virtual void visit(SInt *);
406 virtual void visit(UInt *);
407 virtual void visit(Float *);
408 virtual void visit(Double *);
409 virtual void visit(String *);
410 virtual void visit(Enum *);
411 virtual void visit(Bitmask *);
412 virtual void visit(Struct *);
413 virtual void visit(Array *);
414 virtual void visit(Blob *);
415 virtual void visit(Pointer *);
416 virtual void visit(Repr *);
417 virtual void visit(Backtrace *);
418 virtual void visit(StackFrame *);
420 inline void _visit(Value *value) {
428 typedef unsigned CallFlags;
433 * TODO: It might be better to to record some of these (but not all) into the
439 * Whether a call was really done by the application or not.
441 * This flag is set for fake calls -- calls not truly done by the application
442 * but emitted and recorded for completeness, to provide contextual information
443 * necessary for retracing, that would not be available through other ways.
445 * XXX: This one definetely needs to go into the trace file.
447 CALL_FLAG_FAKE = (1 << 0),
450 * Whether this call should be retraced or ignored.
452 * This flag is set for calls which can't be safely replayed (due to incomplete
453 * information) or that have no sideffects.
455 * Some incomplete calls are unreproduceable, but not all.
457 CALL_FLAG_NON_REPRODUCIBLE = (1 << 1),
460 * Whether this call has no side-effects, therefore don't need to be
463 * This flag is set for calls that merely query information which is not
464 * needed for posterior calls.
466 CALL_FLAG_NO_SIDE_EFFECTS = (1 << 2),
469 * Whether this call renders into the bound rendertargets.
471 CALL_FLAG_RENDER = (1 << 3),
474 * Whether this call causes render target to be swapped.
476 * This does not mark frame termination by itself -- that's solely the
477 * responsibility of `endOfFrame` bit.
479 * This mean that snapshots should be take prior to the call, and not
482 CALL_FLAG_SWAP_RENDERTARGET = (1 << 4),
485 * Whether this call terminates a frame.
487 * XXX: This can't always be determined by the function name, so it should also
488 * go into the trace file eventually.
490 CALL_FLAG_END_FRAME = (1 << 5),
493 * Whether this call is incomplete, i.e., it never returned.
495 CALL_FLAG_INCOMPLETE = (1 << 6),
498 * Whether this call is verbose (i.e., not usually interesting).
500 CALL_FLAG_VERBOSE = (1 << 7),
515 const FunctionSig *sig;
516 std::vector<Arg> args;
520 Backtrace* backtrace;
522 Call(const FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) :
523 thread_id(_thread_id),
525 args(_sig->num_args),
533 inline const char * name(void) const {
537 inline Value & arg(unsigned index) {
538 assert(index < args.size());
539 return *(args[index].value);
544 } /* namespace trace */
546 #endif /* _TRACE_MODEL_HPP_ */