X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fretrace_swizzle.cpp;h=2045f6bb7c83eafe5e71cca35141ce19080e7a1a;hb=42b89fc9a180e56dbe55a9816904c84aacb555ea;hp=52dfad29b69c33158324eb4288cadd58ba5e792f;hpb=ab8142ff4ab07a92565676ead5b0ad4607492cbc;p=apitrace diff --git a/retrace/retrace_swizzle.cpp b/retrace/retrace_swizzle.cpp index 52dfad2..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); @@ -239,4 +251,57 @@ toPointer(trace::Value &value, bool bind) { } + +static std::map _obj_map; + +void +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) { + std::cout << std::hex << "obj 0x" << address << " -> 0x" << size_t(obj) << std::dec << "\n"; + } +} + +void +delObj(trace::Value &value) { + unsigned long long address = value.toUIntPtr(); + _obj_map.erase(address); +} + +void * +toObjPointer(trace::Call &call, trace::Value &value) { + unsigned long long address = value.toUIntPtr(); + + 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"; + } + + return obj; +} + + } /* retrace */