X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fretrace_swizzle.cpp;h=2045f6bb7c83eafe5e71cca35141ce19080e7a1a;hb=12e1f987f7af2fb66dc6d28ab50f913d6e54a141;hp=52d1d74dfd251eeb20cc9ce8c462a4f81a970313;hpb=e7cb2b98575d5ff3801bd3527a648e0dbfdebdad;p=apitrace diff --git a/retrace/retrace_swizzle.cpp b/retrace/retrace_swizzle.cpp index 52d1d74..2045f6b 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,20 @@ 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) { + if (obj) { + warning(call) << "unexpected non-null object\n"; + } + 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 +283,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";