]> git.cworth.org Git - apitrace/blobdiff - cgltrace.py
cli: Add a new "apitrace diff" command.
[apitrace] / cgltrace.py
index 33765f9b8d3b1ebfae3e81656c994e6434cc3cac..b6a6fd0847215e9775f195b1a40c7cb2f740c774 100644 (file)
@@ -27,9 +27,9 @@
 """Cgl tracing generator."""
 
 
-from stdapi import API
-from glapi import glapi
-from cglapi import cglapi
+from specs.stdapi import API
+from specs.glapi import glapi
+from specs.cglapi import cglapi
 from gltrace import GlTracer
 
 
@@ -44,13 +44,14 @@ 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'
     print '#endif'
     print '#include <dlfcn.h>'
     print
-    print '#include "trace_write.hpp"'
+    print '#include "trace_writer.hpp"'
     print
     print '// To validate our prototypes'
     print '#define GL_GLEXT_PROTOTYPES'
@@ -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;
 
@@ -77,22 +84,30 @@ static void *libgl_handle = NULL;
 /*
  * Lookup a libGL symbol
  */
-static void * __dlsym(const char *symbol)
+void * __libgl_sym(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::log("apitrace: error: couldn't load %s\n", libgl_filename);
+            os::abort();
             return NULL;
         }
     }
@@ -100,8 +115,8 @@ static void * __dlsym(const char *symbol)
     result = dlsym(libgl_handle, symbol);
 
     if (result == dlsym(RTLD_SELF, symbol)) {
-        OS::DebugMessage("error: symbol lookup recursion\n");
-        OS::Abort();
+        os::log("apitrace: error: symbol lookup recursion\n");
+        os::abort();
         return NULL;
     }