From: José Fonseca Date: Fri, 30 Mar 2012 19:41:25 +0000 (+0100) Subject: Merge branch 'master' into d3dretrace X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=12a22803faa06a0db229b6dfb6130a0e8156ba31;hp=-c;p=apitrace Merge branch 'master' into d3dretrace Conflicts: retrace.py --- 12a22803faa06a0db229b6dfb6130a0e8156ba31 diff --combined CMakeLists.txt index 35d9a78,ed09055..03208fb --- a/CMakeLists.txt +++ b/CMakeLists.txt @@@ -60,10 -60,6 +60,6 @@@ else ( include_directories (${X11_INCLUDE_DIR}) add_definitions (-DHAVE_X11) endif () - - if (ENABLE_EGL) - add_definitions (-DHAVE_EGL) - endif () endif () @@@ -510,12 -506,6 +506,6 @@@ if (ENABLE_EGL AND NOT WIN32 AND NOT AP add_dependencies (egltrace glproc) - set_property ( - TARGET egltrace - APPEND - PROPERTY COMPILE_DEFINITIONS "TRACE_EGL" - ) - set_target_properties (egltrace PROPERTIES # avoid the default "lib" prefix PREFIX "" @@@ -548,11 -538,11 +538,11 @@@ add_custom_command add_custom_command ( OUTPUT glstate_params.cpp - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp - DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate_params.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp + DEPENDS glstate_params.py specs/glparams.py specs/gltypes.py specs/stdapi.py ) - set (retrace_sources + add_library (retrace_common glretrace_gl.cpp glretrace_cgl.cpp glretrace_glx.cpp @@@ -560,15 -550,22 +550,22 @@@ glretrace_egl.cpp glretrace_main.cpp glstate.cpp + glstate_images.cpp glstate_params.cpp + glstate_shaders.cpp retrace.cpp retrace_stdc.cpp glws.cpp ) + set_property ( + TARGET retrace_common + APPEND + PROPERTY COMPILE_DEFINITIONS "RETRACE" + ) + if (WIN32 OR APPLE OR X11_FOUND) add_executable (glretrace - ${retrace_sources} ${glws_os} glproc_gl.cpp ) @@@ -582,6 -579,7 +579,7 @@@ ) target_link_libraries (glretrace + retrace_common common ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} @@@ -619,7 -617,6 +617,6 @@@ endif ( if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE) add_executable (eglretrace - ${retrace_sources} glws_egl_xlib.cpp glproc_egl.cpp ) @@@ -630,10 -627,10 +627,10 @@@ TARGET eglretrace APPEND PROPERTY COMPILE_DEFINITIONS "RETRACE" - PROPERTY COMPILE_DEFINITIONS "TRACE_EGL" ) target_link_libraries (eglretrace + retrace_common common ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} @@@ -650,21 -647,6 +647,21 @@@ install (TARGETS eglretrace RUNTIME DESTINATION bin) endif () +if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR) + add_custom_command ( + OUTPUT d3dretrace_d3d9.cpp + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp + DEPENDS d3dretrace.py retrace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py + ) + + include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR}) + add_executable (d3dretrace + retrace.cpp + d3dretrace_main.cpp + d3dretrace_d3d9.cpp + ) +endif () + ############################################################################## # CLI diff --combined retrace.hpp index a4559c7,dc11bb3..1b5fdd2 --- a/retrace.hpp +++ b/retrace.hpp @@@ -1,6 -1,6 +1,6 @@@ /************************************************************************** * - * Copyright 2011 Jose Fonseca + * Copyright 2011-2012 Jose Fonseca * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@@ -33,15 -33,11 +33,15 @@@ #include #include "trace_model.hpp" +#include "trace_parser.hpp" namespace retrace { +extern trace::Parser parser; + + /** * Handle map. * @@@ -84,6 -80,53 +84,53 @@@ public }; + /** + * Similar to alloca(), but implemented with malloc. + */ + class ScopedAllocator + { + private: + void *next; + + public: + ScopedAllocator() : + next(NULL) { + } + + inline void * + alloc(size_t size) { + if (!size) { + return NULL; + } + + void * * buf = static_cast(malloc(sizeof(void *) + size)); + if (!buf) { + return NULL; + } + + *buf = next; + next = buf; + + return &buf[1]; + } + + template< class T > + inline T * + alloc(size_t n = 1) { + return static_cast(alloc(sizeof(T) * n)); + } + + inline + ~ScopedAllocator() { + while (next) { + void *temp = *static_cast(next); + free(next); + next = temp; + } + } + }; + + void addRegion(unsigned long long address, void *buffer, unsigned long long size); diff --combined retrace.py index 15cdaf5,1203a09..d6e8387 --- a/retrace.py +++ b/retrace.py @@@ -72,7 -72,7 +72,7 @@@ class ValueDeserializer(stdapi.Visitor) print ' const trace::Array *__a%s = dynamic_cast(&%s);' % (array.tag, rvalue) print ' if (__a%s) {' % (array.tag) length = '__a%s->values.size()' % array.tag - print ' %s = new %s[%s];' % (lvalue, array.type, length) + print ' %s = _allocator.alloc<%s>(%s);' % (lvalue, array.type, length) index = '__j' + array.tag print ' for (size_t {i} = 0; {i} < {length}; ++{i}) {{'.format(i = index, length = length) try: @@@ -86,7 -86,7 +86,7 @@@ def visitPointer(self, pointer, lvalue, rvalue): print ' const trace::Array *__a%s = dynamic_cast(&%s);' % (pointer.tag, rvalue) print ' if (__a%s) {' % (pointer.tag) - print ' %s = new %s;' % (lvalue, pointer.type) + print ' %s = _allocator.alloc<%s>();' % (lvalue, pointer.type) try: self.visit(pointer.type, '%s[0]' % (lvalue,), '*__a%s->values[0]' % (pointer.tag,)) finally: @@@ -207,41 -207,13 +207,43 @@@ 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 + self.deserializeArgs(function) + + self.invokeFunction(function) + + self.swizzleValues(function) + + def retraceInterfaceMethodBody(self, interface, method): + if not method.sideeffects: + print ' (void)call;' + return + + self.deserializeThisPointer(interface) + + self.deserializeArgs(method) + + self.invokeInterfaceMethod(interface, method) + + self.swizzleValues(method) + + def deserializeThisPointer(self, interface): + print ' %s *_this;' % (interface.name,) + # FIXME + + def deserializeArgs(self, function): + print ' retrace::ScopedAllocator _allocator;' + print ' (void)_allocator;' success = True for arg in function.args: arg_type = ConstRemover().visit(arg.type) @@@ -252,17 -224,13 +254,17 @@@ try: self.extractArg(function, arg, arg_type, lvalue, rvalue) except NotImplementedError: - success = False + success = False print ' %s = 0; // FIXME' % arg.name + if not success: print ' if (1) {' self.failFunction(function) + if function.name[-1].islower(): + sys.stderr.write('warning: unsupported %s call\n' % function.name) print ' }' - self.invokeFunction(function) + + def swizzleValues(self, function): for arg in function.args: if arg.output: arg_type = ConstRemover().visit(arg.type) @@@ -279,6 -247,9 +281,6 @@@ self.regiterSwizzledValue(function.type, lvalue, rvalue) except NotImplementedError: print ' // XXX: result' - if not success: - if function.name[-1].islower(): - sys.stderr.write('warning: unsupported %s call\n' % function.name) def failFunction(self, function): print ' if (retrace::verbosity >= 0) {' @@@ -305,20 -276,25 +307,20 @@@ else: print ' %s(%s);' % (function.name, arg_names) + def invokeInterfaceMethod(self, interface, method): + arg_names = ", ".join(method.argNames()) + if method.type is not stdapi.Void: + print ' %s __result;' % (method.type) + print ' __result = _this->%s(%s);' % (method.name, arg_names) + print ' (void)__result;' + else: + print ' _this->%s(%s);' % (method.name, arg_names) + def filterFunction(self, function): return True table_name = 'retrace::callbacks' - def retraceFunctions(self, functions): - functions = filter(self.filterFunction, functions) - - for function in functions: - self.retraceFunction(function) - - print 'const retrace::Entry %s[] = {' % self.table_name - for function in functions: - print ' {"%s", &retrace_%s},' % (function.name, function.name) - print ' {NULL, NULL}' - print '};' - print - - def retraceApi(self, api): print '#include "trace_parser.hpp"' @@@ -338,21 -314,5 +340,21 @@@ handle_names.add(handle.name) print - self.retraceFunctions(api.functions) + functions = filter(self.filterFunction, api.functions) + for function in functions: + self.retraceFunction(function) + interfaces = api.getAllInterfaces() + for interface in interfaces: + for method in interface.iterMethods(): + self.retraceInterfaceMethod(interface, method) + + print 'const retrace::Entry %s[] = {' % self.table_name + for function in functions: + print ' {"%s", &retrace_%s},' % (function.name, 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) + print ' {NULL, NULL}' + print '};' + print