X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fretrace_swizzle.cpp;h=b487de184a994cdd9c9bfbec01364704d13a80ef;hb=b35ae0df401ff22e3b2dc9b6bfacf1e23baebde0;hp=52d1d74dfd251eeb20cc9ce8c462a4f81a970313;hpb=a27e272aac56c7869fe9dc0444ae124abafe35ac;p=apitrace diff --git a/retrace/retrace_swizzle.cpp b/retrace/retrace_swizzle.cpp index 52d1d74..b487de1 100644 --- a/retrace/retrace_swizzle.cpp +++ b/retrace/retrace_swizzle.cpp @@ -75,6 +75,12 @@ lowerBound(unsigned long long address) { } } +#ifndef NDEBUG + if (it != regionMap.end()) { + assert(contains(it, address) || it->first > address); + } +#endif + return it; } @@ -83,6 +89,12 @@ static RegionMap::iterator upperBound(unsigned long long address) { RegionMap::iterator it = regionMap.upper_bound(address); +#ifndef NDEBUG + if (it != regionMap.end()) { + assert(it->first >= address); + } +#endif + return it; } @@ -108,7 +120,7 @@ addRegion(unsigned long long address, void *buffer, unsigned long long size) #ifndef NDEBUG RegionMap::iterator start = lowerBound(address); - RegionMap::iterator stop = upperBound(address + size); + RegionMap::iterator stop = upperBound(address + size - 1); if (0) { // Forget all regions that intersect this new one. regionMap.erase(start, stop); @@ -243,8 +255,18 @@ toPointer(trace::Value &value, bool bind) { static std::map _obj_map; void -addObj(trace::Value &value, void *obj) { +addObj(trace::Call &call, trace::Value &value, void *obj) { unsigned long long address = value.toUIntPtr(); + + if (!address) { + assert(!obj); + return; + } + + if (!obj) { + warning(call) << "got null for object 0x" << std::hex << address << std::dec << "\n"; + } + _obj_map[address] = obj; if (retrace::verbosity >= 2) { @@ -259,9 +281,18 @@ delObj(trace::Value &value) { } void * -toObjPointer(trace::Value &value) { +toObjPointer(trace::Call &call, trace::Value &value) { unsigned long long address = value.toUIntPtr(); - void *obj = address ? _obj_map[address] : NULL; + + void *obj; + if (address) { + obj = _obj_map[address]; + if (!obj) { + warning(call) << "unknown object 0x" << std::hex << address << std::dec << "\n"; + } + } else { + obj = NULL; + } if (retrace::verbosity >= 2) { std::cout << std::hex << "obj 0x" << address << " <- 0x" << size_t(obj) << std::dec << "\n";