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;
60 const char **member_names;
66 signed long long value;
73 const EnumValue *values;
79 unsigned long long value;
86 const BitmaskFlag *flags;
97 virtual void visit(Visitor &visitor) = 0;
99 virtual bool toBool(void) const = 0;
100 virtual signed long long toSInt(void) const;
101 virtual unsigned long long toUInt(void) const;
102 virtual float toFloat(void) const;
103 virtual double toDouble(void) const;
105 virtual void *toPointer(void) const;
106 virtual void *toPointer(bool bind);
107 virtual unsigned long long toUIntPtr(void) const;
108 virtual const char *toString(void) const;
110 const Value & operator[](size_t index) const;
114 class Null : public Value
117 bool toBool(void) const;
118 signed long long toSInt(void) const;
119 unsigned long long toUInt(void) const;
120 virtual float toFloat(void) const;
121 virtual double toDouble(void) const;
122 void *toPointer(void) const;
123 void *toPointer(bool bind);
124 unsigned long long toUIntPtr(void) const;
125 const char *toString(void) const;
126 void visit(Visitor &visitor);
130 class Bool : public Value
133 Bool(bool _value) : value(_value) {}
135 bool toBool(void) const;
136 signed long long toSInt(void) const;
137 unsigned long long toUInt(void) const;
138 virtual float toFloat(void) const;
139 virtual double toDouble(void) const;
140 void visit(Visitor &visitor);
146 class SInt : public Value
149 SInt(signed long long _value) : value(_value) {}
151 bool toBool(void) const;
152 signed long long toSInt(void) const;
153 unsigned long long toUInt(void) const;
154 virtual float toFloat(void) const;
155 virtual double toDouble(void) const;
156 void visit(Visitor &visitor);
158 signed long long value;
162 class UInt : public Value
165 UInt(unsigned long long _value) : value(_value) {}
167 bool toBool(void) const;
168 signed long long toSInt(void) const;
169 unsigned long long toUInt(void) const;
170 virtual float toFloat(void) const;
171 virtual double toDouble(void) const;
172 void visit(Visitor &visitor);
174 unsigned long long value;
178 class Float : public Value
181 Float(float _value) : value(_value) {}
183 bool toBool(void) const;
184 signed long long toSInt(void) const;
185 unsigned long long toUInt(void) const;
186 virtual float toFloat(void) const;
187 virtual double toDouble(void) const;
188 void visit(Visitor &visitor);
194 class Double : public Value
197 Double(double _value) : value(_value) {}
199 bool toBool(void) const;
200 signed long long toSInt(void) const;
201 unsigned long long toUInt(void) const;
202 virtual float toFloat(void) const;
203 virtual double toDouble(void) const;
204 void visit(Visitor &visitor);
210 class String : public Value
213 String(const char * _value) : value(_value) {}
216 bool toBool(void) const;
217 const char *toString(void) const;
218 void visit(Visitor &visitor);
224 class Enum : public SInt
227 Enum(const EnumSig *_sig, signed long long _value) : SInt(_value), sig(_sig) {}
229 void visit(Visitor &visitor);
235 // TODO: use a std::map
236 for (const EnumValue *it = sig->values; it != sig->values + sig->num_values; ++it) {
237 if (it->value == value) {
246 class Bitmask : public UInt
249 Bitmask(const BitmaskSig *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
251 void visit(Visitor &visitor);
253 const BitmaskSig *sig;
257 class Struct : public Value
260 Struct(StructSig *_sig) : sig(_sig), members(_sig->num_members) { }
263 bool toBool(void) const;
264 void visit(Visitor &visitor);
266 const StructSig *sig;
267 std::vector<Value *> members;
271 class Array : public Value
274 Array(size_t len) : values(len) {}
277 bool toBool(void) const;
278 void visit(Visitor &visitor);
280 std::vector<Value *> values;
284 return values.size();
289 class Blob : public Value
294 buf = new char[_size];
300 bool toBool(void) const;
301 void *toPointer(void) const;
302 void *toPointer(bool bind);
303 void visit(Visitor &visitor);
311 class Pointer : public UInt
314 Pointer(unsigned long long value) : UInt(value) {}
316 bool toBool(void) const;
317 void *toPointer(void) const;
318 void *toPointer(bool bind);
319 unsigned long long toUIntPtr(void) const;
320 void visit(Visitor &visitor);
324 class Repr : public Value
327 Repr(Value *human, Value *machine) :
329 machineValue(machine)
332 /** Human-readible value */
335 /** Machine-readible value */
338 virtual bool toBool(void) const;
339 virtual signed long long toSInt(void) const;
340 virtual unsigned long long toUInt(void) const;
341 virtual float toFloat(void) const;
342 virtual double toDouble(void) const;
344 virtual void *toPointer(void) const;
345 virtual void *toPointer(bool bind);
346 virtual unsigned long long toUIntPtr(void) const;
347 virtual const char *toString(void) const;
349 void visit(Visitor &visitor);
371 std::vector<StackFrame*> frames;
373 void addFrame(StackFrame* frame);
379 virtual void visit(Null *);
380 virtual void visit(Bool *);
381 virtual void visit(SInt *);
382 virtual void visit(UInt *);
383 virtual void visit(Float *);
384 virtual void visit(Double *);
385 virtual void visit(String *);
386 virtual void visit(Enum *);
387 virtual void visit(Bitmask *);
388 virtual void visit(Struct *);
389 virtual void visit(Array *);
390 virtual void visit(Blob *);
391 virtual void visit(Pointer *);
392 virtual void visit(Repr *);
393 virtual void visit(Backtrace *);
394 virtual void visit(StackFrame *);
396 inline void _visit(Value *value) {
404 typedef unsigned CallFlags;
409 * TODO: It might be better to to record some of these (but not all) into the
415 * Whether a call was really done by the application or not.
417 * This flag is set for fake calls -- calls not truly done by the application
418 * but emitted and recorded for completeness, to provide contextual information
419 * necessary for retracing, that would not be available through other ways.
421 * XXX: This one definetely needs to go into the trace file.
423 CALL_FLAG_FAKE = (1 << 0),
426 * Whether this call should be retraced or ignored.
428 * This flag is set for calls which can't be safely replayed (due to incomplete
429 * information) or that have no sideffects.
431 * Some incomplete calls are unreproduceable, but not all.
433 CALL_FLAG_NON_REPRODUCIBLE = (1 << 1),
436 * Whether this call has no side-effects, therefore don't need to be
439 * This flag is set for calls that merely query information which is not
440 * needed for posterior calls.
442 CALL_FLAG_NO_SIDE_EFFECTS = (1 << 2),
445 * Whether this call renders into the bound rendertargets.
447 CALL_FLAG_RENDER = (1 << 3),
450 * Whether this call causes render target to be swapped.
452 * This does not mark frame termination by itself -- that's solely the
453 * responsibility of `endOfFrame` bit.
455 * This mean that snapshots should be take prior to the call, and not
458 CALL_FLAG_SWAP_RENDERTARGET = (1 << 4),
461 * Whether this call terminates a frame.
463 * XXX: This can't always be determined by the function name, so it should also
464 * go into the trace file eventually.
466 CALL_FLAG_END_FRAME = (1 << 5),
469 * Whether this call is incomplete, i.e., it never returned.
471 CALL_FLAG_INCOMPLETE = (1 << 6),
474 * Whether this call is verbose (i.e., not usually interesting).
476 CALL_FLAG_VERBOSE = (1 << 7),
492 std::vector<Arg> args;
496 Backtrace* backtrace;
498 Call(FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) :
499 thread_id(_thread_id),
501 args(_sig->num_args),
509 inline const char * name(void) const {
513 inline Value & arg(unsigned index) {
514 assert(index < args.size());
515 return *(args[index].value);
520 } /* namespace trace */
522 #endif /* _TRACE_MODEL_HPP_ */