X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=trace_model.cpp;h=306b9e7a64da745384f06ee050eeddc97e9a1b4b;hb=93e4d1569ac411912ddb2c15b9b130af0171f049;hp=617abc7a79b778be5e9a475432760b738a246d38;hpb=ec494edf0f473db4088c23ec7a97f20eab393c2d;p=apitrace diff --git a/trace_model.cpp b/trace_model.cpp index 617abc7..306b9e7 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -42,6 +42,11 @@ Call::~Call() { } +String::~String() { + delete [] value; +} + + Struct::~Struct() { for (std::vector::iterator it = members.begin(); it != members.end(); ++it) { delete *it; @@ -56,9 +61,16 @@ Array::~Array() { } Blob::~Blob() { - // TODO: Don't leak blobs. Blobs are often bound and accessed during many - // calls, so we can't delete them here. - //delete [] buf; + // Blobs are often bound and referred during many calls, so we can't delete + // them here in that case. + // + // Once bound there is no way to know when they were unbound, which + // effectively means we have to leak them. A better solution would be to + // keep a list of bound pointers, and defer the destruction to when the + // trace in question has been fully processed. + if (!bound) { + delete [] buf; + } } @@ -122,6 +134,11 @@ void * Null ::toPointer(void) const { return NULL; } void * Blob ::toPointer(void) const { return buf; } void * Pointer::toPointer(void) const { return (void *)value; } +void * Value ::toPointer(bool bind) { assert(0); return NULL; } +void * Null ::toPointer(bool bind) { return NULL; } +void * Blob ::toPointer(bool bind) { if (bind) bound = true; return buf; } +void * Pointer::toPointer(bool bind) { return (void *)value; } + // pointer cast unsigned long long Value ::toUIntPtr(void) const { assert(0); return 0; } @@ -177,8 +194,8 @@ protected: Formatter::Attribute *literal; public: - Dumper(std::ostream &_os) : os(_os) { - formatter = Formatter::defaultFormatter(); + Dumper(std::ostream &_os, bool color) : os(_os) { + formatter = Formatter::defaultFormatter(color); normal = formatter->normal(); bold = formatter->bold(); italic = formatter->italic(); @@ -257,7 +274,7 @@ public: unsigned long long value = bitmask->value; const BitmaskSig *sig = bitmask->sig; bool first = true; - for (const BitmaskVal *it = sig->values; value != 0 && it != sig->values + sig->count; ++it) { + for (const BitmaskFlag *it = sig->flags; value != 0 && it != sig->flags + sig->num_flags; ++it) { if ((it->value && (value & it->value) == it->value) || (!it->value && value == 0)) { if (!first) { @@ -334,12 +351,9 @@ public: }; -std::ostream & operator <<(std::ostream &os, Value *value) { - Dumper d(os); - if (value) { - value->visit(d); - } - return os; +void Value::dump(std::ostream &os, bool color) { + Dumper d(os, color); + visit(d); } @@ -355,11 +369,10 @@ const Value & Value::operator[](size_t index) const { return null; } -std::ostream & operator <<(std::ostream &os, Call &call) { - Dumper d(os); - os << call.no << " "; - d.visit(&call); - return os; +void Call::dump(std::ostream &os, bool color) { + Dumper d(os, color); + os << no << " "; + d.visit(this); }