From: José Fonseca Date: Fri, 13 Apr 2012 16:36:19 +0000 (+0100) Subject: Merge branch 'd3dretrace' X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=1da480dd320a9d3d631a94025ca40609099f6d34 Merge branch 'd3dretrace' --- 1da480dd320a9d3d631a94025ca40609099f6d34 diff --cc retrace.hpp index 8ce15ad,7357a70..c1e556a --- a/retrace.hpp +++ b/retrace.hpp @@@ -119,17 -120,24 +123,35 @@@ public return static_cast(alloc(sizeof(T) * n)); } + /** + * Allocate an array with the same dimensions as the specified value. + */ + template< class T > + inline T * + alloc(const trace::Value *value) { + const trace::Array *array = dynamic_cast(value); + if (array) { + return alloc(array->size()); + } + const trace::Null *null = dynamic_cast(value); + if (null) { + return NULL; + } + assert(0); + return NULL; + } + + /** + * Prevent this pointer from being automatically freed. + */ + template< class T > + inline void + bind(T *ptr) { + if (ptr) { + reinterpret_cast(ptr)[-1] |= 1; + } + } + inline ~ScopedAllocator() { while (next) { diff --cc retrace.py index e4d462a,ee85f29..a450f82 --- a/retrace.py +++ b/retrace.py @@@ -207,9 -320,45 +320,41 @@@ class Retracer print '}' print + def retraceInterfaceMethod(self, interface, method): + print 'static void retrace_%s__%s(trace::Call &call) {' % (interface.name, method.name) + self.retraceInterfaceMethodBody(interface, method) + print '}' + print + def retraceFunctionBody(self, function): - if not function.sideeffects: - print ' (void)call;' - return + assert function.sideeffects + self.deserializeArgs(function) + + self.invokeFunction(function) + + self.swizzleValues(function) + + def retraceInterfaceMethodBody(self, interface, method): - if not method.sideeffects: - print ' (void)call;' - return ++ assert method.sideeffects + + self.deserializeThisPointer(interface) + + self.deserializeArgs(method) + + self.invokeInterfaceMethod(interface, method) + + self.swizzleValues(method) + + def deserializeThisPointer(self, interface): + print r' %s *_this;' % (interface.name,) + print r' _this = static_cast<%s *>(_obj_map[call.arg(0).toUIntPtr()]);' % (interface.name,) + print r' if (!_this) {' + print r' retrace::warning(call) << "NULL this pointer\n";' + print r' return;' + print r' }' + + def deserializeArgs(self, function): print ' retrace::ScopedAllocator _allocator;' print ' (void)_allocator;' success = True @@@ -317,5 -465,24 +461,32 @@@ handle_names.add(handle.name) print - self.retraceFunctions(api.functions) + print 'static std::map _obj_map;' + print + + functions = filter(self.filterFunction, api.functions) + for function in functions: - self.retraceFunction(function) ++ if function.sideeffects: ++ self.retraceFunction(function) + interfaces = api.getAllInterfaces() + for interface in interfaces: + for method in interface.iterMethods(): - self.retraceInterfaceMethod(interface, method) ++ if method.sideeffects: ++ self.retraceInterfaceMethod(interface, method) + + print 'const retrace::Entry %s[] = {' % self.table_name + for function in functions: - print ' {"%s", &retrace_%s},' % (function.name, function.name) ++ if function.sideeffects: ++ print ' {"%s", &retrace_%s},' % (function.name, function.name) ++ else: ++ print ' {"%s", &retrace::ignore},' % (function.name,) + for interface in interfaces: - for method in interface.iterMethods(): - print ' {"%s::%s", &retrace_%s__%s},' % (interface.name, method.name, interface.name, method.name) ++ for method in interface.iterMethods(): ++ if method.sideeffects: ++ print ' {"%s::%s", &retrace_%s__%s},' % (interface.name, method.name, interface.name, method.name) ++ else: ++ print ' {"%s::%s", &retrace::ignore},' % (interface.name, method.name) + print ' {NULL, NULL}' + print '};' + print