X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_model.hpp;h=36f0a03eff83cb15d5919fb86b661eb0cd271513;hb=ad6f60ff31d1cc912e947989afea39d698181ac4;hp=4f150bc925caec0162dd21b6e07a28c664049ed4;hpb=946da143b5fa8b5babddd5668743e4048bf08e7d;p=apitrace diff --git a/common/trace_model.hpp b/common/trace_model.hpp index 4f150bc..36f0a03 100644 --- a/common/trace_model.hpp +++ b/common/trace_model.hpp @@ -41,6 +41,10 @@ namespace trace { +// Should match Call::no +typedef unsigned CallNo; + + typedef unsigned Id; @@ -87,6 +91,9 @@ struct BitmaskSig { class Visitor; +class Null; +class Struct; +class Array; class Value @@ -106,6 +113,15 @@ public: virtual unsigned long long toUIntPtr(void) const; virtual const char *toString(void) const; + virtual const Null *toNull(void) const { return NULL; } + virtual Null *toNull(void) { return NULL; } + + virtual const Array *toArray(void) const { return NULL; } + virtual Array *toArray(void) { return NULL; } + + virtual const Struct *toStruct(void) const { return NULL; } + virtual Struct *toStruct(void) { return NULL; } + const Value & operator[](size_t index) const; }; @@ -123,6 +139,9 @@ public: unsigned long long toUIntPtr(void) const; const char *toString(void) const; void visit(Visitor &visitor); + + const Null *toNull(void) const { return this; } + Null *toNull(void) { return this; } }; @@ -228,6 +247,17 @@ public: void visit(Visitor &visitor); const EnumSig *sig; + + const EnumValue * + lookup() { + // TODO: use a std::map + for (const EnumValue *it = sig->values; it != sig->values + sig->num_values; ++it) { + if (it->value == value) { + return it; + } + } + return NULL; + } }; @@ -251,6 +281,9 @@ public: bool toBool(void) const; void visit(Visitor &visitor); + const Struct *toStruct(void) const { return this; } + Struct *toStruct(void) { return this; } + const StructSig *sig; std::vector members; }; @@ -265,7 +298,15 @@ public: bool toBool(void) const; void visit(Visitor &visitor); + const Array *toArray(void) const { return this; } + Array *toArray(void) { return this; } + std::vector values; + + inline size_t + size(void) const { + return values.size(); + } }; @@ -304,6 +345,58 @@ public: }; +class Repr : public Value +{ +public: + Repr(Value *human, Value *machine) : + humanValue(human), + machineValue(machine) + {} + + /** Human-readible value */ + Value *humanValue; + + /** Machine-readible value */ + Value *machineValue; + + virtual bool toBool(void) const; + virtual signed long long toSInt(void) const; + virtual unsigned long long toUInt(void) const; + virtual float toFloat(void) const; + virtual double toDouble(void) const; + + virtual void *toPointer(void) const; + virtual void *toPointer(bool bind); + virtual unsigned long long toUIntPtr(void) const; + virtual const char *toString(void) const; + + void visit(Visitor &visitor); +}; + +struct RawStackFrame { + Id id; + const char * module; + const char * function; + const char * filename; + int linenumber; + long long offset; + RawStackFrame() : + module(0), + function(0), + filename(0), + linenumber(-1), + offset(-1) + { + } +}; + +class StackFrame : public RawStackFrame { +public: + ~StackFrame(); +}; + +typedef std::vector Backtrace; + class Visitor { public: @@ -320,7 +413,9 @@ public: virtual void visit(Array *); virtual void visit(Blob *); virtual void visit(Pointer *); - + virtual void visit(Repr *); + virtual void visit(Backtrace *); + virtual void visit(StackFrame *); protected: inline void _visit(Value *value) { if (value) { @@ -406,22 +501,31 @@ enum { }; +struct Arg +{ + Value *value; +}; + class Call { public: + unsigned thread_id; unsigned no; const FunctionSig *sig; - std::vector args; + std::vector args; Value *ret; CallFlags flags; + Backtrace* backtrace; - Call(FunctionSig *_sig, const CallFlags &_flags) : + Call(const FunctionSig *_sig, const CallFlags &_flags, unsigned _thread_id) : + thread_id(_thread_id), sig(_sig), args(_sig->num_args), ret(0), - flags(_flags) { + flags(_flags), + backtrace(0) { } ~Call(); @@ -432,7 +536,7 @@ public: inline Value & arg(unsigned index) { assert(index < args.size()); - return *(args[index]); + return *(args[index].value); } };