]> git.cworth.org Git - apitrace/blobdiff - common/trace_tools_trace.cpp
Fix SnappyFile::rawGetc() on big endian hosts.
[apitrace] / common / trace_tools_trace.cpp
index 4ba38e0704f1df235afc1a64f96f279ddc769c9e..768fd108d3541eaf1352b09c910b2c4c335bd1ea 100644 (file)
@@ -30,7 +30,9 @@
 
 #include <iostream>
 
-#include "os_path.hpp"
+#include "os_string.hpp"
+#include "os_process.hpp"
+#include "trace_resource.hpp"
 #include "trace_tools.hpp"
 
 
@@ -39,58 +41,48 @@ namespace trace {
 
 
 #if defined(__APPLE__)
-#define CLI_TRACE_VARIABLE "DYLD_LIBRARY_PATH"
-#define CLI_TRACE_WRAPPER  "OpenGL"
+#define TRACE_VARIABLE "DYLD_LIBRARY_PATH"
+#define GL_TRACE_WRAPPER  "OpenGL"
 #elif defined(_WIN32)
-#define CLI_TRACE_VARIABLE ""
-#define CLI_TRACE_WRAPPER  "opengl32.dll"
+#define TRACE_VARIABLE ""
+#define GL_TRACE_WRAPPER  "opengl32.dll"
 #else
-#define CLI_TRACE_VARIABLE "LD_PRELOAD"
-#define CLI_TRACE_WRAPPER  "glxtrace.so"
+#define TRACE_VARIABLE "LD_PRELOAD"
+#define GL_TRACE_WRAPPER  "glxtrace.so"
+#define EGL_TRACE_WRAPPER  "egltrace.so"
 #endif
 
 
-os::Path
-findFile(const char *relPath,
-         const char *absPath,
-         bool verbose)
-{
-    os::Path complete;
-
-    /* First look in the same directory from which this process is
-     * running, (to support developers running a compiled program that
-     * has not been installed. */
-    os::Path process_dir = os::getProcessName();
-
-    process_dir.trimFilename();
-
-    complete = process_dir;
-    complete.join(relPath);
-
-    if (complete.exists())
-        return complete;
-
-    /* Second, look in the directory for installed wrappers. */
-    complete = absPath;
-    if (complete.exists())
-        return complete;
-
-    if (verbose) {
-        std::cerr << "error: cannot find " << relPath << " or " << absPath << "\n";
-    }
-
-    return "";
-}
-
-
 int
-traceProgram(char * const *argv,
+traceProgram(API api,
+             char * const *argv,
              const char *output,
              bool verbose)
 {
-    os::Path wrapper;
+    const char *relPath;
+    const char *absPath;
+
+    switch (api) {
+    case API_GL:
+        relPath = "wrappers/" GL_TRACE_WRAPPER;
+        absPath = APITRACE_WRAPPER_INSTALL_DIR "/" GL_TRACE_WRAPPER;
+        break;
+    case API_EGL:
+#ifndef EGL_TRACE_WRAPPER
+        std::cerr << "error: unsupported API\n";
+        return 1;
+#else
+        relPath = "wrappers/" EGL_TRACE_WRAPPER;
+        absPath = APITRACE_WRAPPER_INSTALL_DIR "/" EGL_TRACE_WRAPPER;
+        break;
+#endif
+    default:
+        std::cerr << "error: invalid API\n";
+        return 1;
+    }
 
-    wrapper = findFile("wrappers/" CLI_TRACE_WRAPPER, APITRACE_WRAPPER_INSTALL_DIR CLI_TRACE_WRAPPER, verbose);
+    os::String wrapper;
+    wrapper = findFile(relPath, absPath, verbose);
 
     if (!wrapper.length()) {
         return 1;
@@ -104,6 +96,8 @@ traceProgram(char * const *argv,
         APITRACE_WRAPPER_INSTALL_DIR "\n"
         "to the directory with the application to trace, then run the application.\n";
 
+    return 1;
+
 #else
 
 #if defined(__APPLE__)
@@ -113,11 +107,11 @@ traceProgram(char * const *argv,
 #endif
 
     if (verbose) {
-        std::cerr << CLI_TRACE_VARIABLE << "=" << wrapper.str() << "\n";
+        std::cerr << TRACE_VARIABLE << "=" << wrapper.str() << "\n";
     }
 
     /* FIXME: Don't modify the current environment */
-    setenv(CLI_TRACE_VARIABLE, wrapper.str(), 1);
+    setenv(TRACE_VARIABLE, wrapper.str(), 1);
 
     if (output) {
         setenv("TRACE_FILE", output, 1);
@@ -132,17 +126,16 @@ traceProgram(char * const *argv,
         std::cerr << "\n";
     }
 
-    execvp(argv[0], argv);
+    int status = os::execute(argv);
 
-    unsetenv(CLI_TRACE_VARIABLE);
+    unsetenv(TRACE_VARIABLE);
     if (output) {
         unsetenv("TRACE_FILE");
     }
-
-    std::cerr << "error: Failed to execute " << argv[0] << "\n";
+    
+    return status;
 #endif
 
-    return 1;
 }