diff options
author | José Fonseca <jfonseca@vmware.com> | 2011-05-27 20:14:31 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2011-05-27 20:14:31 +0100 |
commit | 3bcb33ca2c47bdb70d91d9988664d744f4146855 (patch) | |
tree | 5207dfe3dc3ce7d5f6f844b09c97247320dced5e /cgltrace.py | |
parent | ebb1ed4a92108eee8b71a60a02117fd801164312 (diff) |
Trace the whole OpenGL framework on Mac OS X.
Diffstat (limited to 'cgltrace.py')
-rw-r--r-- | cgltrace.py | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/cgltrace.py b/cgltrace.py index f850435..86e8a29 100644 --- a/cgltrace.py +++ b/cgltrace.py @@ -44,6 +44,7 @@ if __name__ == '__main__': print print '#include <stdlib.h>' print '#include <string.h>' + print '#include <unistd.h>' print print '#ifndef _GNU_SOURCE' print '#define _GNU_SOURCE // for dladdr' @@ -69,7 +70,13 @@ if __name__ == '__main__': /* - * Handle to the true libGL.so + * Path to the true OpenGL framework + */ +static const char *libgl_filename = "/System/Library/Frameworks/OpenGL.framework/OpenGL"; + + +/* + * Handle to the true OpenGL framework. */ static void *libgl_handle = NULL; @@ -80,19 +87,27 @@ static void *libgl_handle = NULL; static void * __dlsym(const char *symbol) { void *result; - if (!libgl_handle) { - const char * libgl_filename; + if (!libgl_handle) { /* - * Unfortunately we can't just dlopen - * /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib - * because DYLD_LIBRARY_PATH takes precedence, even for absolute paths. + * Unfortunately we can't just dlopen the true dynamic library because + * DYLD_LIBRARY_PATH/DYLD_FRAMEWORK_PATH take precedence, even for + * absolute paths. So we create a temporary symlink, and dlopen that + * instead. */ - libgl_filename = "libGL.system.dylib"; - libgl_handle = dlopen(libgl_filename, RTLD_LOCAL | RTLD_NOW | RTLD_FIRST); + char temp_filename[] = "/tmp/tmp.XXXXXX"; + + if (mktemp(temp_filename) != NULL) { + if (symlink(libgl_filename, temp_filename) == 0) { + libgl_handle = dlopen(temp_filename, RTLD_LOCAL | RTLD_NOW | RTLD_FIRST); + remove(temp_filename); + } + } + if (!libgl_handle) { OS::DebugMessage("error: couldn't load %s\n", libgl_filename); + OS::Abort(); return NULL; } } |