1 /*********************************************************************
3 * Copyright 2011 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 *********************************************************************/
33 #include "os_string.hpp"
34 #include "os_process.hpp"
35 #include "trace_resource.hpp"
36 #include "trace_tools.hpp"
43 #if defined(__APPLE__)
44 #define TRACE_VARIABLE "DYLD_LIBRARY_PATH"
45 #define GL_TRACE_WRAPPER "OpenGL"
47 #define TRACE_VARIABLE ""
48 #define GL_TRACE_WRAPPER "opengl32.dll"
50 #define TRACE_VARIABLE "LD_PRELOAD"
51 #define GL_TRACE_WRAPPER "glxtrace.so"
52 #define EGL_TRACE_WRAPPER "egltrace.so"
67 relPath = "wrappers/" GL_TRACE_WRAPPER;
68 absPath = APITRACE_WRAPPER_INSTALL_DIR "/" GL_TRACE_WRAPPER;
71 #ifndef EGL_TRACE_WRAPPER
72 std::cerr << "error: unsupported API\n";
75 relPath = "wrappers/" EGL_TRACE_WRAPPER;
76 absPath = APITRACE_WRAPPER_INSTALL_DIR "/" EGL_TRACE_WRAPPER;
80 std::cerr << "error: invalid API\n";
85 wrapper = findFile(relPath, absPath, verbose);
87 if (!wrapper.length()) {
92 /* On Windows copt the wrapper to the program directory.
94 os::String wrapperName (wrapper);
95 wrapperName.trimDirectory();
97 os::String tmpWrapper(argv[0]);
98 tmpWrapper.trimFilename();
99 tmpWrapper.join(wrapperName);
101 if (tmpWrapper.exists()) {
102 std::cerr << "error: not overwriting " << tmpWrapper << "\n";
106 if (!os::copyFile(wrapper, tmpWrapper, false)) {
107 std::cerr << "error: failed to copy " << wrapper << " into " << tmpWrapper << "\n";
112 #if defined(__APPLE__)
113 /* On Mac OS X, using DYLD_LIBRARY_PATH, we actually set the
114 * directory, not the file. */
115 wrapper.trimFilename();
118 #if defined(TRACE_VARIABLE)
121 std::cerr << TRACE_VARIABLE << "=" << wrapper.str() << "\n";
124 /* FIXME: Don't modify the current environment */
125 os::setEnvironment(TRACE_VARIABLE, wrapper.str());
127 #endif /* TRACE_VARIABLE */
130 os::setEnvironment("TRACE_FILE", output);
134 const char *sep = "";
135 for (char * const * arg = argv; *arg; ++arg) {
136 std::cerr << *arg << sep;
142 int status = os::execute(argv);
144 #if defined(TRACE_VARIABLE)
145 os::unsetEnvironment(TRACE_VARIABLE);
148 os::removeFile(tmpWrapper);
152 os::unsetEnvironment("TRACE_FILE");
160 } /* namespace trace */