]> git.cworth.org Git - apitrace/blobdiff - retrace/retrace_swizzle.cpp
Update downloads link.
[apitrace] / retrace / retrace_swizzle.cpp
index 52d1d74dfd251eeb20cc9ce8c462a4f81a970313..2045f6bb7c83eafe5e71cca35141ce19080e7a1a 100644 (file)
@@ -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<unsigned long long, void *> _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";