}
if (!libgl_handle) {
- os::DebugMessage("apitrace: error: couldn't load %s\n", libgl_filename);
- os::Abort();
+ os::log("apitrace: error: couldn't load %s\n", libgl_filename);
+ os::abort();
return NULL;
}
}
result = dlsym(libgl_handle, symbol);
if (result == dlsym(RTLD_SELF, symbol)) {
- os::DebugMessage("apitrace: error: symbol lookup recursion\n");
- os::Abort();
+ os::log("apitrace: error: symbol lookup recursion\n");
+ os::abort();
return NULL;
}
namespace os {
-void AcquireMutex(void);
+void acquireMutex(void);
-void ReleaseMutex(void);
+void releaseMutex(void);
-bool GetProcessName(char *str, size_t size);
-bool GetCurrentDir(char *str, size_t size);
+bool getProcessName(char *str, size_t size);
+bool getCurrentDir(char *str, size_t size);
-void DebugMessage(const char *format, ...)
+void log(const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
/**
* Get the current time in microseconds from an unknown base.
*/
-long long GetTime(void);
+long long getTime(void);
-void Abort(void);
+void abort(void);
-void SetExceptionCallback(void (*callback)(void));
-void ResetExceptionCallback(void);
+void setExceptionCallback(void (*callback)(void));
+void resetExceptionCallback(void);
} /* namespace os */
void
-AcquireMutex(void)
+acquireMutex(void)
{
pthread_mutex_lock(&mutex);
}
void
-ReleaseMutex(void)
+releaseMutex(void)
{
pthread_mutex_unlock(&mutex);
}
bool
-GetProcessName(char *str, size_t size)
+getProcessName(char *str, size_t size)
{
char szProcessPath[PATH_MAX + 1];
char *lpProcessName;
}
bool
-GetCurrentDir(char *str, size_t size)
+getCurrentDir(char *str, size_t size)
{
char *ret;
ret = getcwd(str, size);
}
void
-DebugMessage(const char *format, ...)
+log(const char *format, ...)
{
va_list ap;
va_start(ap, format);
va_end(ap);
}
-long long GetTime(void)
+long long
+getTime(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
}
void
-Abort(void)
+abort(void)
{
exit(0);
}
* - http://sourceware.org/git/?p=glibc.git;a=blob;f=debug/segfault.c
* - http://ggi.cvs.sourceforge.net/viewvc/ggi/ggi-core/libgg/gg/cleanup.c?view=markup
*/
-static void signal_handler(int sig, siginfo_t *info, void *context)
+static void
+signalHandler(int sig, siginfo_t *info, void *context)
{
static int recursion_count = 0;
- fprintf(stderr, "signal_handler: sig = %i\n", sig);
+ fprintf(stderr, "apitrace: warning: caught signal %i\n", sig);
if (recursion_count) {
- fprintf(stderr, "recursion with sig %i\n", sig);
+ fprintf(stderr, "apitrace: warning: recursion handling signal %i\n", sig);
} else {
if (gCallback) {
++recursion_count;
struct sigaction *old_action;
if (sig >= NUM_SIGNALS) {
/* This should never happen */
- fprintf(stderr, "Unexpected signal %i\n", sig);
+ fprintf(stderr, "error: unexpected signal %i\n", sig);
raise(SIGKILL);
}
old_action = &old_actions[sig];
old_action->sa_sigaction(sig, info, context);
} else {
if (old_action->sa_handler == SIG_DFL) {
- fprintf(stderr, "taking default action for signal %i\n", sig);
+ fprintf(stderr, "apitrace: info: taking default action for signal %i\n", sig);
#if 1
struct sigaction dfl_action;
}
void
-SetExceptionCallback(void (*callback)(void))
+setExceptionCallback(void (*callback)(void))
{
assert(!gCallback);
if (!gCallback) {
gCallback = callback;
struct sigaction new_action;
- new_action.sa_sigaction = signal_handler;
+ new_action.sa_sigaction = signalHandler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = SA_SIGINFO | SA_RESTART;
}
void
-ResetExceptionCallback(void)
+resetExceptionCallback(void)
{
gCallback = NULL;
}
* Trick from http://locklessinc.com/articles/pthreads_on_windows/
*/
static CRITICAL_SECTION
-CriticalSection = {
+criticalSection = {
(PCRITICAL_SECTION_DEBUG)-1, -1, 0, 0, 0, 0
};
void
-AcquireMutex(void)
+acquireMutex(void)
{
- EnterCriticalSection(&CriticalSection);
+ EnterCriticalSection(&criticalSection);
}
void
-ReleaseMutex(void)
+releaseMutex(void)
{
- LeaveCriticalSection(&CriticalSection);
+ LeaveCriticalSection(&criticalSection);
}
bool
-GetProcessName(char *str, size_t size)
+getProcessName(char *str, size_t size)
{
char szProcessPath[PATH_MAX];
char *lpProcessName;
}
bool
-GetCurrentDir(char *str, size_t size)
+getCurrentDir(char *str, size_t size)
{
DWORD ret;
ret = GetCurrentDirectoryA(size, str);
}
void
-DebugMessage(const char *format, ...)
+log(const char *format, ...)
{
char buf[4096];
#endif
}
-long long GetTime(void)
+long long
+getTime(void)
{
static LARGE_INTEGER frequency;
LARGE_INTEGER counter;
}
void
-Abort(void)
+abort(void)
{
#ifndef NDEBUG
DebugBreak();
static LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter = NULL;
static void (*gCallback)(void) = NULL;
-static LONG WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
+static LONG WINAPI
+unhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
{
if (gCallback) {
gCallback();
}
void
-SetExceptionCallback(void (*callback)(void))
+setExceptionCallback(void (*callback)(void))
{
assert(!gCallback);
* handler in certain circumnstances. See
* http://www.codeproject.com/KB/winsdk/crash_hook.aspx
*/
- prevExceptionFilter = SetUnhandledExceptionFilter(UnhandledExceptionFilter);
+ prevExceptionFilter = SetUnhandledExceptionFilter(unhandledExceptionFilter);
}
}
void
-ResetExceptionCallback(void)
+resetExceptionCallback(void)
{
gCallback = NULL;
}
_writeUInt(sig->num_flags);
for (unsigned i = 0; i < sig->num_flags; ++i) {
if (i != 0 && sig->flags[i].value == 0) {
- os::DebugMessage("apitrace: warning: sig %s is zero but is not first flag\n", sig->flags[i].name);
+ os::log("apitrace: warning: sig %s is zero but is not first flag\n", sig->flags[i].name);
}
_writeString(sig->flags[i].name);
_writeUInt(sig->flags[i].value);
{
// Install the signal handlers as early as possible, to prevent
// interfering with the application's signal handling.
- os::SetExceptionCallback(exceptionCallback);
+ os::setExceptionCallback(exceptionCallback);
}
LocalWriter::~LocalWriter()
{
- os::ResetExceptionCallback();
+ os::resetExceptionCallback();
}
void
else {
char szProcessName[PATH_MAX];
char szCurrentDir[PATH_MAX];
- os::GetProcessName(szProcessName, PATH_MAX);
- os::GetCurrentDir(szCurrentDir, PATH_MAX);
+ os::getProcessName(szProcessName, PATH_MAX);
+ os::getCurrentDir(szCurrentDir, PATH_MAX);
for (;;) {
FILE *file;
}
}
- os::DebugMessage("apitrace: tracing to %s\n", szFileName);
+ os::log("apitrace: tracing to %s\n", szFileName);
Writer::open(szFileName);
}
unsigned LocalWriter::beginEnter(const FunctionSig *sig) {
- os::AcquireMutex();
+ os::acquireMutex();
++acquired;
if (!m_file->isOpened()) {
void LocalWriter::endEnter(void) {
Writer::endEnter();
--acquired;
- os::ReleaseMutex();
+ os::releaseMutex();
}
void LocalWriter::beginLeave(unsigned call) {
- os::AcquireMutex();
+ os::acquireMutex();
++acquired;
Writer::beginLeave(call);
}
void LocalWriter::endLeave(void) {
Writer::endLeave();
--acquired;
- os::ReleaseMutex();
+ os::releaseMutex();
}
void LocalWriter::flush(void) {
*/
if (!acquired) {
- os::AcquireMutex();
+ os::acquireMutex();
if (m_file->isOpened()) {
- os::DebugMessage("apitrace: flushing trace due to an exception\n");
+ os::log("apitrace: flushing trace due to an exception\n");
m_file->flush();
}
- os::ReleaseMutex();
+ os::releaseMutex();
}
}
def fail_function(self, function):
if function.type is stdapi.Void or function.fail is not None:
- print r' os::DebugMessage("warning: ignoring call to unavailable function %s\n", __name);'
+ print r' os::log("warning: ignoring call to unavailable function %s\n", __name);'
if function.type is stdapi.Void:
assert function.fail is None
print ' return;'
assert function.fail is not None
print ' return %s;' % function.fail
else:
- print r' os::DebugMessage("error: unavailable function %s\n", __name);'
- print r' os::Abort();'
+ print r' os::log("error: unavailable function %s\n", __name);'
+ print r' os::abort();'
retracer.addCallbacks(wgl_callbacks);
retracer.addCallbacks(cgl_callbacks);
- startTime = os::GetTime();
+ startTime = os::getTime();
trace::Call *call;
while ((call = parser.parse_call())) {
// Reached the end of trace
glFlush();
- long long endTime = os::GetTime();
+ long long endTime = os::getTime();
float timeInterval = (endTime - startTime) * 1.0E-6;
if (retrace::verbosity >= -1) {
case GL_DOUBLE:
return 8;
default:
- os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
+ os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
return 0;
}
}
numElems = 1;
break;
default:
- os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
+ os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
elemType = GL_NONE;
numElems = 0;
return;
}
}
} else {
- os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
+ os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
}
if (__element_array_buffer) {
static inline GLuint
__glDrawArraysIndirect_maxindex(const GLvoid *indirect) {
- os::DebugMessage("apitrace: warning: %s: unsupported\n", __FUNCTION__);
+ os::log("apitrace: warning: %s: unsupported\n", __FUNCTION__);
return 0;
}
static inline GLuint
__glDrawElementsIndirect_maxindex(GLenum type, const GLvoid *indirect) {
- os::DebugMessage("apitrace: warning: %s: unsupported\n", __FUNCTION__);
+ os::log("apitrace: warning: %s: unsupported\n", __FUNCTION__);
return 0;
}
channels = 4;
break;
default:
- os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, target);
+ os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, target);
return 0;
}
channels = 4;
break;
default:
- os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, target);
+ os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, target);
return 0;
}
case GL_CMYKA_EXT:
return 5;
default:
- os::DebugMessage("apitrace: warning: %s: unexpected format GLenum 0x%04X\n", __FUNCTION__, format);
+ os::log("apitrace: warning: %s: unexpected format GLenum 0x%04X\n", __FUNCTION__, format);
return 0;
}
}
bits_per_pixel = 64;
break;
default:
- os::DebugMessage("apitrace: warning: %s: unexpected type GLenum 0x%04X\n", __FUNCTION__, type);
+ os::log("apitrace: warning: %s: unexpected type GLenum 0x%04X\n", __FUNCTION__, type);
bits_per_pixel = 0;
break;
}
case GL_STENCIL:
return 1;
default:
- os::DebugMessage("apitrace: warning: %s: unexpected buffer GLenum 0x%04X\n", __FUNCTION__, buffer);
+ os::log("apitrace: warning: %s: unexpected buffer GLenum 0x%04X\n", __FUNCTION__, buffer);
return 0;
}
}
}
}
} else {
- os::DebugMessage("apitrace: unexpected XImage: "
+ os::log("apitrace: unexpected XImage: "
"bits_per_pixel = %i, "
"depth = %i, "
"red_mask = 0x%08lx, "
char filename[PATH_MAX];
snprintf(filename, sizeof filename, "%s%010u.png", snapshot_prefix, call_no);
if (src->writePNG(filename)) {
- os::DebugMessage("apitrace: wrote %s\n", filename);
+ os::log("apitrace: wrote %s\n", filename);
}
delete src;
print ' case GL_%s:' % target
print ' return & __%s_mapping;' % target.lower()
print ' default:'
- print ' os::DebugMessage("apitrace: warning: unknown buffer target 0x%04X\\n", target);'
+ print ' os::log("apitrace: warning: unknown buffer target 0x%04X\\n", target);'
print ' return NULL;'
print ' }'
print '}'
print ' return num_compressed_texture_formats;'
print ' }'
print ' default:'
- print r' os::DebugMessage("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);'
+ print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);'
print ' return 1;'
print ' }'
print '}'
print ' %s = (%s)procPtr;' % (pvalue, ptype)
print ' return (__GLXextFuncPtr)&%s;' % (f.name,)
print ' }'
- print ' os::DebugMessage("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);'
+ print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);'
print ' return procPtr;'
print '}'
print
if (!dlopen_ptr) {
dlopen_ptr = (PFNDLOPEN)dlsym(RTLD_NEXT, "dlopen");
if (!dlopen_ptr) {
- os::DebugMessage("apitrace: error: dlsym(RTLD_NEXT, \"dlopen\") failed\n");
+ os::log("apitrace: error: dlsym(RTLD_NEXT, \"dlopen\") failed\n");
return NULL;
}
}
if (filename && handle && !libgl_filename) {
if (0) {
- os::DebugMessage("apitrace: warning: dlopen(\"%s\", 0x%x)\n", filename, flag);
+ os::log("apitrace: warning: dlopen(\"%s\", 0x%x)\n", filename, flag);
}
// FIXME: handle absolute paths and other versions
static int dummy = 0xdeedbeef;
Dl_info info;
if (dladdr(&dummy, &info)) {
- os::DebugMessage("apitrace: redirecting dlopen(\"%s\", 0x%x)\n", filename, flag);
+ os::log("apitrace: redirecting dlopen(\"%s\", 0x%x)\n", filename, flag);
handle = __dlopen(info.dli_fname, flag);
} else {
- os::DebugMessage("apitrace: warning: dladdr() failed\n");
+ os::log("apitrace: warning: dladdr() failed\n");
}
}
}
libgl_handle = __dlopen(libgl_filename, RTLD_GLOBAL | RTLD_LAZY);
if (!libgl_handle) {
- os::DebugMessage("apitrace: error: couldn't find libGL.so\n");
+ os::log("apitrace: error: couldn't find libGL.so\n");
return NULL;
}
}
print ' %s = (%s)&%s;' % (instance, function.type, f.name);
def handle_default():
- print ' os::DebugMessage("apitrace: warning: unknown function \\"%s\\"\\n", lpszProc);'
+ print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", lpszProc);'
string_switch('lpszProc', func_dict.keys(), handle_case, handle_default)
print ' }'