# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
# DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py stdapi.py
# )
- # add_library (d3d8 SHARED d3d8.def d3d8.cpp log.cpp os_win32.cpp)
+ # add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
# set_target_properties (d3d8 PROPERTIES PREFIX "")
#endif (DirectX_D3D8_FOUND)
# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
# DEPENDS d3d9.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
# )
- # add_library (d3d9 SHARED d3d9.def d3d9.cpp log.cpp os_win32.cpp)
+ # add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
# set_target_properties (d3d9 PROPERTIES PREFIX "")
#endif (DirectX_D3DX9_FOUND)
# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
# DEPENDS d3d10misc.py winapi.py stdapi.py
# )
- # add_library (d3d10 SHARED d3d10.def d3d10.cpp log.cpp os_win32.cpp)
+ # add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
# set_target_properties (d3d10 PROPERTIES PREFIX "")
#endif (DirectX_D3D10_FOUND)
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
DEPENDS wgltrace.py trace.py wglapi.py glapi.py glenum.py winapi.py stdapi.py
)
- add_library (opengl SHARED opengl32.def opengl32.cpp log.cpp os_win32.cpp)
+ add_library (opengl SHARED opengl32.def opengl32.cpp trace_write.cpp os_win32.cpp)
set_target_properties (opengl PROPERTIES
PREFIX ""
OUTPUT_NAME opengl32)
DEPENDS glxtrace.py trace.py glxapi.py glapi.py glenum.py stdapi.py
)
- add_library (glxtrace SHARED glxtrace.cpp log.cpp os_posix.cpp)
+ add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp)
set_target_properties (glxtrace PROPERTIES PREFIX "")
target_link_libraries (glxtrace dl)
endif ()
print
print '#include <d3d10_1.h>'
print
- print '#include "log.hpp"'
+ print '#include "trace_write.hpp"'
print
wrap()
print
print '#include <d3d10.h>'
print
- print '#include "log.hpp"'
+ print '#include "trace_write.hpp"'
print
wrap()
print '#include <tchar.h>'
print '#include <d3d8.h>'
print
- print '#include "log.hpp"'
+ print '#include "trace_write.hpp"'
print
wrap()
print
print '#include <d3d9.h>'
print
- print '#include "log.hpp"'
+ print '#include "trace_write.hpp"'
print
wrap()
LPD3DXBUFFER pDisassembly = NULL;
if (pfnD3DXDisassembleShader( (DWORD *)tokens, FALSE, NULL, &pDisassembly) == D3D_OK)
- Log::LiteralString((char *)pDisassembly->GetBufferPointer());
+ Trace::LiteralString((char *)pDisassembly->GetBufferPointer());
if(pDisassembly)
pDisassembly->Release();
print '#include <tchar.h>'
print '#include <ddraw.h>'
print
- print '#include "log.hpp"'
+ print '#include "trace_write.hpp"'
print
wrap()
print ' if (!pglXGetProcAddress) {'
print ' pglXGetProcAddress = (PglXGetProcAddress)dlsym(RTLD_NEXT, "glXGetProcAddress");'
print ' if (!pglXGetProcAddress)'
- print ' Log::Abort();'
+ print ' Trace::Abort();'
print ' }'
return 'pglXGetProcAddress((const GLubyte *)"%s")' % (function.name,)
print '#include <GL/glx.h>'
print '#include "glxext.h"'
print
- print '#include "log.hpp"'
+ print '#include "trace_write.hpp"'
print '#include "glsize.hpp"'
print
print 'extern "C" {'
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2007-2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include <assert.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <map>
-
-#include <zlib.h>
-
-#include "os.hpp"
-#include "log.hpp"
-#include "trace_format.hpp"
-
-
-namespace Log {
-
-
-static gzFile g_gzFile = NULL;
-static void _Close(void) {
- if(g_gzFile != NULL) {
- gzclose(g_gzFile);
- g_gzFile = NULL;
- }
-}
-
-static void _Open(const char *szExtension) {
- _Close();
-
- static unsigned dwCounter = 0;
-
- char szFileName[PATH_MAX];
- const char *lpFileName;
-
- lpFileName = getenv("TRACE_PATH");
- if (lpFileName) {
- strncpy(szFileName, lpFileName, PATH_MAX);
- }
- else {
- char szProcessName[PATH_MAX];
- char szCurrentDir[PATH_MAX];
- OS::GetProcessName(szProcessName, PATH_MAX);
- OS::GetCurrentDir(szCurrentDir, PATH_MAX);
-
- for(;;) {
- FILE *file;
-
- if (dwCounter)
- snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir, PATH_SEP, szProcessName, dwCounter, szExtension);
- else
- snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir, PATH_SEP, szProcessName, szExtension);
-
- file = fopen(szFileName, "rb");
- if(file == NULL)
- break;
-
- fclose(file);
-
- ++dwCounter;
- }
- }
-
- OS::DebugMessage("apitrace: tracing to %s\n", szFileName);
-
- g_gzFile = gzopen(szFileName, "wb");
-}
-
-static inline void Write(const void *sBuffer, size_t dwBytesToWrite) {
- if (g_gzFile == NULL)
- return;
-
- gzwrite(g_gzFile, sBuffer, dwBytesToWrite);
-}
-
-static inline void
-WriteByte(char c) {
- Write(&c, 1);
-}
-
-void inline
-WriteUInt(unsigned long long value) {
- char buf[2 * sizeof value];
- unsigned len;
-
- len = 0;
- do {
- assert(len < sizeof buf);
- buf[len] = 0x80 | (value & 0x7f);
- value >>= 7;
- ++len;
- } while (value);
-
- assert(len);
- buf[len - 1] &= 0x7f;
-
- Write(buf, len);
-}
-
-static inline void
-WriteFloat(float value) {
- assert(sizeof value == 4);
- Write((const char *)&value, sizeof value);
-}
-
-static inline void
-WriteDouble(double value) {
- assert(sizeof value == 8);
- Write((const char *)&value, sizeof value);
-}
-
-static inline void
-WriteString(const char *str) {
- size_t len = strlen(str);
- WriteUInt(len);
- Write(str, len);
-}
-
-typedef std::map<const char *, size_t> namemap;
-static namemap names;
-
-static inline void
-WriteName(const char *name) {
- namemap::iterator it = names.find(name);
- if (it == names.end()) {
- size_t name_id = names.size();
- WriteUInt(name_id);
- WriteString(name);
- names[name] = name_id;
- } else {
- WriteUInt(it->second);
- }
-}
-
-void Open(void) {
- if (!g_gzFile) {
- _Open("trace");
- WriteUInt(TRACE_VERSION);
- }
-}
-
-void Close(void) {
- _Close();
-}
-
-static unsigned call_no = 0;
-
-unsigned BeginEnter(const char *function) {
- OS::AcquireMutex();
- Open();
- WriteByte(Trace::EVENT_ENTER);
- WriteName(function);
- return call_no++;
-}
-
-void EndEnter(void) {
- WriteByte(Trace::CALL_END);
- gzflush(g_gzFile, Z_SYNC_FLUSH);
- OS::ReleaseMutex();
-}
-
-void BeginLeave(unsigned call) {
- OS::AcquireMutex();
- WriteByte(Trace::EVENT_LEAVE);
- WriteUInt(call);
-}
-
-void EndLeave(void) {
- WriteByte(Trace::CALL_END);
- gzflush(g_gzFile, Z_SYNC_FLUSH);
- OS::ReleaseMutex();
-}
-
-void BeginArg(unsigned index, const char *name) {
- WriteByte(Trace::CALL_ARG);
- WriteUInt(index);
- WriteName(name);
-}
-
-void BeginReturn(void) {
- WriteByte(Trace::CALL_RET);
-}
-
-void BeginArray(size_t length) {
- WriteByte(Trace::TYPE_ARRAY);
- WriteUInt(length);
-}
-
-void BeginStruct(size_t length) {
- WriteByte(Trace::TYPE_STRUCT);
- WriteUInt(length);
-}
-
-void BeginMember(const char *name) {
- WriteName(name);
-}
-
-void BeginBitmask(void) {
- WriteByte(Trace::TYPE_BITMASK);
-}
-
-void EndBitmask(void) {
- WriteByte(Trace::TYPE_NULL);
-}
-
-void LiteralBool(bool value) {
- WriteByte(value ? Trace::TYPE_TRUE : Trace::TYPE_FALSE);
-}
-
-void LiteralSInt(signed long long value) {
- if (value < 0) {
- WriteByte(Trace::TYPE_SINT);
- WriteUInt(-value);
- } else {
- WriteByte(Trace::TYPE_UINT);
- WriteUInt(value);
- }
-}
-
-void LiteralUInt(unsigned long long value) {
- WriteByte(Trace::TYPE_UINT);
- WriteUInt(value);
-}
-
-void LiteralFloat(float value) {
- WriteByte(Trace::TYPE_FLOAT);
- WriteFloat(value);
-}
-
-void LiteralFloat(double value) {
- WriteByte(Trace::TYPE_DOUBLE);
- WriteDouble(value);
-}
-
-void LiteralString(const char *str) {
- if (!str) {
- LiteralNull();
- return;
- }
- WriteByte(Trace::TYPE_STRING);
- WriteString(str);
-}
-
-void LiteralString(const char *str, size_t len) {
- if (!str) {
- LiteralNull();
- return;
- }
- WriteByte(Trace::TYPE_STRING);
- WriteUInt(len);
- Write(str, len);
-}
-
-void LiteralWString(const wchar_t *str) {
- if (!str) {
- LiteralNull();
- return;
- }
- WriteByte(Trace::TYPE_STRING);
- WriteString("<wide-string>");
-}
-
-void LiteralBlob(const void *data, size_t size) {
- if (!data) {
- LiteralNull();
- return;
- }
- WriteByte(Trace::TYPE_BLOB);
- WriteUInt(size);
- if (size) {
- Write(data, size);
- }
-}
-
-void LiteralNamedConstant(const char *name, long long value) {
- WriteByte(Trace::TYPE_CONST);
- WriteName(name);
- LiteralSInt(value);
-}
-
-void LiteralNull(void) {
- WriteByte(Trace::TYPE_NULL);
-}
-
-void LiteralOpaque(const void *addr) {
- if (!addr) {
- LiteralNull();
- return;
- }
- WriteByte(Trace::TYPE_OPAQUE);
- WriteUInt((size_t)addr);
-}
-
-void Abort(void) {
- Close();
- OS::Abort();
-}
-
-} /* namespace Log */
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2007-2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- **************************************************************************/
-
-#ifndef _LOG_HPP_
-#define _LOG_HPP_
-
-namespace Log {
-
- void Open(void);
- void Close(void);
-
- unsigned BeginEnter(const char *function);
- void EndEnter(void);
-
- void BeginLeave(unsigned call);
- void EndLeave(void);
-
- void BeginArg(unsigned index, const char *name);
- inline void EndArg(void) {}
-
- void BeginReturn(void);
- inline void EndReturn(void) {}
-
- void BeginArray(size_t length);
- inline void EndArray(void) {}
-
- inline void BeginElement(void) {}
- inline void EndElement(void) {}
-
- void BeginStruct(size_t length);
- inline void EndStruct(void) {}
-
- void BeginMember(const char *name);
- inline void EndMember(void) {}
-
- void BeginBitmask(void);
- void EndBitmask(void);
-
- void LiteralBool(bool value);
- void LiteralSInt(signed long long value);
- void LiteralUInt(unsigned long long value);
- void LiteralFloat(float value);
- void LiteralFloat(double value);
- void LiteralString(const char *str);
- void LiteralString(const char *str, size_t size);
- void LiteralWString(const wchar_t *str);
- void LiteralBlob(const void *data, size_t size);
- void LiteralNamedConstant(const char *name, long long value);
- void LiteralNull(void);
- void LiteralOpaque(const void *ptr);
-
- void Abort(void);
-}
-
-#endif /* _LOG_HPP_ */
#include <pthread.h>
#include "os.hpp"
-#include "log.hpp"
+#include "trace_write.hpp"
namespace OS {
static void _uninit(void) __attribute__((destructor));
static void _uninit(void) {
- Log::Close();
+ Trace::Close();
}
#include <stdio.h>
#include "os.hpp"
-#include "log.hpp"
+#include "trace_write.hpp"
namespace OS {
case DLL_THREAD_DETACH:
return TRUE;
case DLL_PROCESS_DETACH:
- Log::Close();
+ Trace::Close();
return TRUE;
}
(void)hinstDLL;
for type, name in struct.members:
self.visit(type)
print 'static void __traceStruct%s(const %s &value) {' % (struct.id, struct.expr)
- print ' Log::BeginStruct(%u);' % len(struct.members)
+ print ' Trace::BeginStruct(%u);' % len(struct.members)
for type, name in struct.members:
- print ' Log::BeginMember("%s");' % (name,)
+ print ' Trace::BeginMember("%s");' % (name,)
dump_instance(type, 'value.%s' % (name,))
- print ' Log::EndMember();'
- print ' Log::EndStruct();'
+ print ' Trace::EndMember();'
+ print ' Trace::EndStruct();'
print '}'
print
print ' switch(value) {'
for value in enum.values:
print ' case %s:' % value
- print ' Log::LiteralNamedConstant("%s", %s);' % (value, value)
+ print ' Trace::LiteralNamedConstant("%s", %s);' % (value, value)
print ' break;'
print ' default:'
- print ' Log::LiteralSInt(value);'
+ print ' Trace::LiteralSInt(value);'
print ' break;'
print ' }'
print '}'
def visit_bitmask(self, bitmask):
print 'static void __traceBitmask%s(%s value) {' % (bitmask.id, bitmask.type)
- print ' Log::BeginBitmask();'
+ print ' Trace::BeginBitmask();'
for value in bitmask.values:
print ' if((value & %s) == %s) {' % (value, value)
- print ' Log::LiteralNamedConstant("%s", %s);' % (value, value)
+ print ' Trace::LiteralNamedConstant("%s", %s);' % (value, value)
print ' value &= ~%s;' % value
print ' }'
print ' if(value) {'
dump_instance(bitmask.type, "value");
print ' }'
- print ' Log::EndBitmask();'
+ print ' Trace::EndBitmask();'
print '}'
print
'''Dump an instance.'''
def visit_literal(self, literal, instance):
- print ' Log::Literal%s(%s);' % (literal.format, instance)
+ print ' Trace::Literal%s(%s);' % (literal.format, instance)
def visit_string(self, string, instance):
if string.length is not None:
- print ' Log::LiteralString((const char *)%s, %s);' % (instance, string.length)
+ print ' Trace::LiteralString((const char *)%s, %s);' % (instance, string.length)
else:
- print ' Log::LiteralString((const char *)%s);' % instance
+ print ' Trace::LiteralString((const char *)%s);' % instance
def visit_const(self, const, instance):
self.visit(const.type, instance)
def visit_array(self, array, instance):
print ' if(%s) {' % instance
index = '__i' + array.type.id
- print ' Log::BeginArray(%s);' % (array.length,)
+ print ' Trace::BeginArray(%s);' % (array.length,)
print ' for (int %s = 0; %s < %s; ++%s) {' % (index, index, array.length, index)
- print ' Log::BeginElement();'
+ print ' Trace::BeginElement();'
self.visit(array.type, '(%s)[%s]' % (instance, index))
- print ' Log::EndElement();'
+ print ' Trace::EndElement();'
print ' }'
- print ' Log::EndArray();'
+ print ' Trace::EndArray();'
print ' }'
print ' else'
- print ' Log::LiteralNull();'
+ print ' Trace::LiteralNull();'
def visit_blob(self, blob, instance):
- print ' Log::LiteralBlob(%s, %s);' % (instance, blob.size)
+ print ' Trace::LiteralBlob(%s, %s);' % (instance, blob.size)
def visit_enum(self, enum, instance):
print ' __traceEnum%s(%s);' % (enum.id, instance)
def visit_pointer(self, pointer, instance):
print ' if(%s) {' % instance
- print ' Log::BeginArray(1);'
- print ' Log::BeginElement();'
+ print ' Trace::BeginArray(1);'
+ print ' Trace::BeginElement();'
dump_instance(pointer.type, "*" + instance)
- print ' Log::EndElement();'
- print ' Log::EndArray();'
+ print ' Trace::EndElement();'
+ print ' Trace::EndArray();'
print ' }'
print ' else'
- print ' Log::LiteralNull();'
+ print ' Trace::LiteralNull();'
def visit_handle(self, handle, instance):
self.visit(handle.type, instance)
self.visit(alias.type, instance)
def visit_opaque(self, opaque, instance):
- print ' Log::LiteralOpaque((const void *)%s);' % instance
+ print ' Trace::LiteralOpaque((const void *)%s);' % instance
def visit_interface(self, interface, instance):
- print ' Log::LiteralOpaque((const void *)%s);' % instance
+ print ' Trace::LiteralOpaque((const void *)%s);' % instance
dump_instance = DumpImplementer().visit
assert function.fail != ''
print ' return %s;' % function.fail
else:
- print ' Log::Abort();'
+ print ' Trace::Abort();'
def get_function_address(self, function):
raise NotImplementedError
print ' %s __result;' % function.type
result = '__result = '
self._get_true_pointer(function)
- print ' unsigned __call = Log::BeginEnter("%s");' % (function.name)
+ print ' unsigned __call = Trace::BeginEnter("%s");' % (function.name)
for arg in function.args:
if not arg.output:
self.unwrap_arg(function, arg)
self.dump_arg(function, arg)
- print ' Log::EndEnter();'
+ print ' Trace::EndEnter();'
print ' %s%s(%s);' % (result, pvalue, ', '.join([str(arg.name) for arg in function.args]))
- print ' Log::BeginLeave(__call);'
+ print ' Trace::BeginLeave(__call);'
for arg in function.args:
if arg.output:
self.dump_arg(function, arg)
self.wrap_arg(function, arg)
if function.type is not stdapi.Void:
self.dump_ret(function, "__result")
- print ' Log::EndLeave();'
+ print ' Trace::EndLeave();'
if function.type is not stdapi.Void:
self.wrap_ret(function, "__result")
print ' return __result;'
print
def dump_arg(self, function, arg):
- print ' Log::BeginArg(%u, "%s");' % (arg.index, arg.name,)
+ print ' Trace::BeginArg(%u, "%s");' % (arg.index, arg.name,)
dump_instance(arg.type, arg.name)
- print ' Log::EndArg();'
+ print ' Trace::EndArg();'
def wrap_arg(self, function, arg):
wrap_instance(arg.type, arg.name)
unwrap_instance(arg.type, arg.name)
def dump_ret(self, function, instance):
- print ' Log::BeginReturn();'
+ print ' Trace::BeginReturn();'
dump_instance(function.type, instance)
- print ' Log::EndReturn();'
+ print ' Trace::EndReturn();'
def wrap_ret(self, function, instance):
wrap_instance(function.type, instance)
else:
print ' %s __result;' % method.type
result = '__result = '
- print ' Log::BeginCall("%s");' % (interface.name + '::' + method.name)
- print ' Log::BeginArg(0, "this");'
- print ' Log::LiteralOpaque((const void *)m_pInstance);'
- print ' Log::EndArg();'
+ print ' Trace::BeginCall("%s");' % (interface.name + '::' + method.name)
+ print ' Trace::BeginArg(0, "this");'
+ print ' Trace::LiteralOpaque((const void *)m_pInstance);'
+ print ' Trace::EndArg();'
for arg in method.args:
if not arg.output:
self.unwrap_arg(method, arg)
self.dump_arg(method, arg)
self.wrap_arg(method, arg)
if method.type is not Void:
- print ' Log::BeginReturn("%s");' % method.type
+ print ' Trace::BeginReturn("%s");' % method.type
dump_instance(method.type, "__result")
- print ' Log::EndReturn();'
+ print ' Trace::EndReturn();'
wrap_instance(method.type, '__result')
- print ' Log::EndCall();'
+ print ' Trace::EndCall();'
if method.name == 'QueryInterface':
print ' if (*ppvObj == m_pInstance)'
print ' *ppvObj = this;'
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2007-2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <map>
+
+#include <zlib.h>
+
+#include "os.hpp"
+#include "trace_write.hpp"
+#include "trace_format.hpp"
+
+
+namespace Trace {
+
+
+static gzFile g_gzFile = NULL;
+static void _Close(void) {
+ if(g_gzFile != NULL) {
+ gzclose(g_gzFile);
+ g_gzFile = NULL;
+ }
+}
+
+static void _Open(const char *szExtension) {
+ _Close();
+
+ static unsigned dwCounter = 0;
+
+ char szFileName[PATH_MAX];
+ const char *lpFileName;
+
+ lpFileName = getenv("TRACE_PATH");
+ if (lpFileName) {
+ strncpy(szFileName, lpFileName, PATH_MAX);
+ }
+ else {
+ char szProcessName[PATH_MAX];
+ char szCurrentDir[PATH_MAX];
+ OS::GetProcessName(szProcessName, PATH_MAX);
+ OS::GetCurrentDir(szCurrentDir, PATH_MAX);
+
+ for(;;) {
+ FILE *file;
+
+ if (dwCounter)
+ snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir, PATH_SEP, szProcessName, dwCounter, szExtension);
+ else
+ snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir, PATH_SEP, szProcessName, szExtension);
+
+ file = fopen(szFileName, "rb");
+ if(file == NULL)
+ break;
+
+ fclose(file);
+
+ ++dwCounter;
+ }
+ }
+
+ OS::DebugMessage("apitrace: tracing to %s\n", szFileName);
+
+ g_gzFile = gzopen(szFileName, "wb");
+}
+
+static inline void Write(const void *sBuffer, size_t dwBytesToWrite) {
+ if (g_gzFile == NULL)
+ return;
+
+ gzwrite(g_gzFile, sBuffer, dwBytesToWrite);
+}
+
+static inline void
+WriteByte(char c) {
+ Write(&c, 1);
+}
+
+void inline
+WriteUInt(unsigned long long value) {
+ char buf[2 * sizeof value];
+ unsigned len;
+
+ len = 0;
+ do {
+ assert(len < sizeof buf);
+ buf[len] = 0x80 | (value & 0x7f);
+ value >>= 7;
+ ++len;
+ } while (value);
+
+ assert(len);
+ buf[len - 1] &= 0x7f;
+
+ Write(buf, len);
+}
+
+static inline void
+WriteFloat(float value) {
+ assert(sizeof value == 4);
+ Write((const char *)&value, sizeof value);
+}
+
+static inline void
+WriteDouble(double value) {
+ assert(sizeof value == 8);
+ Write((const char *)&value, sizeof value);
+}
+
+static inline void
+WriteString(const char *str) {
+ size_t len = strlen(str);
+ WriteUInt(len);
+ Write(str, len);
+}
+
+typedef std::map<const char *, size_t> namemap;
+static namemap names;
+
+static inline void
+WriteName(const char *name) {
+ namemap::iterator it = names.find(name);
+ if (it == names.end()) {
+ size_t name_id = names.size();
+ WriteUInt(name_id);
+ WriteString(name);
+ names[name] = name_id;
+ } else {
+ WriteUInt(it->second);
+ }
+}
+
+void Open(void) {
+ if (!g_gzFile) {
+ _Open("trace");
+ WriteUInt(TRACE_VERSION);
+ }
+}
+
+void Close(void) {
+ _Close();
+}
+
+static unsigned call_no = 0;
+
+unsigned BeginEnter(const char *function) {
+ OS::AcquireMutex();
+ Open();
+ WriteByte(Trace::EVENT_ENTER);
+ WriteName(function);
+ return call_no++;
+}
+
+void EndEnter(void) {
+ WriteByte(Trace::CALL_END);
+ gzflush(g_gzFile, Z_SYNC_FLUSH);
+ OS::ReleaseMutex();
+}
+
+void BeginLeave(unsigned call) {
+ OS::AcquireMutex();
+ WriteByte(Trace::EVENT_LEAVE);
+ WriteUInt(call);
+}
+
+void EndLeave(void) {
+ WriteByte(Trace::CALL_END);
+ gzflush(g_gzFile, Z_SYNC_FLUSH);
+ OS::ReleaseMutex();
+}
+
+void BeginArg(unsigned index, const char *name) {
+ WriteByte(Trace::CALL_ARG);
+ WriteUInt(index);
+ WriteName(name);
+}
+
+void BeginReturn(void) {
+ WriteByte(Trace::CALL_RET);
+}
+
+void BeginArray(size_t length) {
+ WriteByte(Trace::TYPE_ARRAY);
+ WriteUInt(length);
+}
+
+void BeginStruct(size_t length) {
+ WriteByte(Trace::TYPE_STRUCT);
+ WriteUInt(length);
+}
+
+void BeginMember(const char *name) {
+ WriteName(name);
+}
+
+void BeginBitmask(void) {
+ WriteByte(Trace::TYPE_BITMASK);
+}
+
+void EndBitmask(void) {
+ WriteByte(Trace::TYPE_NULL);
+}
+
+void LiteralBool(bool value) {
+ WriteByte(value ? Trace::TYPE_TRUE : Trace::TYPE_FALSE);
+}
+
+void LiteralSInt(signed long long value) {
+ if (value < 0) {
+ WriteByte(Trace::TYPE_SINT);
+ WriteUInt(-value);
+ } else {
+ WriteByte(Trace::TYPE_UINT);
+ WriteUInt(value);
+ }
+}
+
+void LiteralUInt(unsigned long long value) {
+ WriteByte(Trace::TYPE_UINT);
+ WriteUInt(value);
+}
+
+void LiteralFloat(float value) {
+ WriteByte(Trace::TYPE_FLOAT);
+ WriteFloat(value);
+}
+
+void LiteralFloat(double value) {
+ WriteByte(Trace::TYPE_DOUBLE);
+ WriteDouble(value);
+}
+
+void LiteralString(const char *str) {
+ if (!str) {
+ LiteralNull();
+ return;
+ }
+ WriteByte(Trace::TYPE_STRING);
+ WriteString(str);
+}
+
+void LiteralString(const char *str, size_t len) {
+ if (!str) {
+ LiteralNull();
+ return;
+ }
+ WriteByte(Trace::TYPE_STRING);
+ WriteUInt(len);
+ Write(str, len);
+}
+
+void LiteralWString(const wchar_t *str) {
+ if (!str) {
+ LiteralNull();
+ return;
+ }
+ WriteByte(Trace::TYPE_STRING);
+ WriteString("<wide-string>");
+}
+
+void LiteralBlob(const void *data, size_t size) {
+ if (!data) {
+ LiteralNull();
+ return;
+ }
+ WriteByte(Trace::TYPE_BLOB);
+ WriteUInt(size);
+ if (size) {
+ Write(data, size);
+ }
+}
+
+void LiteralNamedConstant(const char *name, long long value) {
+ WriteByte(Trace::TYPE_CONST);
+ WriteName(name);
+ LiteralSInt(value);
+}
+
+void LiteralNull(void) {
+ WriteByte(Trace::TYPE_NULL);
+}
+
+void LiteralOpaque(const void *addr) {
+ if (!addr) {
+ LiteralNull();
+ return;
+ }
+ WriteByte(Trace::TYPE_OPAQUE);
+ WriteUInt((size_t)addr);
+}
+
+void Abort(void) {
+ Close();
+ OS::Abort();
+}
+
+} /* namespace Trace */
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2007-2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef _TRACE_HPP_
+#define _TRACE_HPP_
+
+namespace Trace {
+
+ void Open(void);
+ void Close(void);
+
+ unsigned BeginEnter(const char *function);
+ void EndEnter(void);
+
+ void BeginLeave(unsigned call);
+ void EndLeave(void);
+
+ void BeginArg(unsigned index, const char *name);
+ inline void EndArg(void) {}
+
+ void BeginReturn(void);
+ inline void EndReturn(void) {}
+
+ void BeginArray(size_t length);
+ inline void EndArray(void) {}
+
+ inline void BeginElement(void) {}
+ inline void EndElement(void) {}
+
+ void BeginStruct(size_t length);
+ inline void EndStruct(void) {}
+
+ void BeginMember(const char *name);
+ inline void EndMember(void) {}
+
+ void BeginBitmask(void);
+ void EndBitmask(void);
+
+ void LiteralBool(bool value);
+ void LiteralSInt(signed long long value);
+ void LiteralUInt(unsigned long long value);
+ void LiteralFloat(float value);
+ void LiteralFloat(double value);
+ void LiteralString(const char *str);
+ void LiteralString(const char *str, size_t size);
+ void LiteralWString(const wchar_t *str);
+ void LiteralBlob(const void *data, size_t size);
+ void LiteralNamedConstant(const char *name, long long value);
+ void LiteralNull(void);
+ void LiteralOpaque(const void *ptr);
+
+ void Abort(void);
+}
+
+#endif /* _TRACE_HPP_ */
print ' if (!pwglGetProcAddress) {'
print ' pwglGetProcAddress = (PwglGetProcAddress)__GetProcAddress("wglGetProcAddress");'
print ' if (!pwglGetProcAddress)'
- print ' Log::Abort();'
+ print ' Trace::Abort();'
print ' }'
return 'pwglGetProcAddress("%s")' % (function.name,)
print
print '#include "glimports.hpp"'
print
- print '#include "log.hpp"'
+ print '#include "trace_write.hpp"'
print '#include "os.hpp"'
print '#include "glsize.hpp"'
print
print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))'
print r' return FALSE;'
print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
- print r' Log::Open("%s");' % self.name
+ print r' Trace::Open("%s");' % self.name
print r' case DLL_THREAD_ATTACH:'
print r' return TRUE;'
print r' case DLL_THREAD_DETACH:'
print r' return TRUE;'
print r' case DLL_PROCESS_DETACH:'
- print r' Log::Close();'
+ print r' Trace::Close();'
print r' if(g_hDll) {'
print r' FreeLibrary(g_hDll);'
print r' g_hDll = NULL;'