X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_tools_trace.cpp;h=77fc5520ba90a3797bb5a1e3b6d75d50b9d91b21;hb=975f124938c523fc15933bcd4cdd7a25ce48ebc4;hp=36fe735466e104c98fcb4a5afe5902c0ed2a793d;hpb=ab6ded73916c5ea5ffee7a44b5c00eab78626b1c;p=apitrace diff --git a/common/trace_tools_trace.cpp b/common/trace_tools_trace.cpp index 36fe735..77fc552 100644 --- a/common/trace_tools_trace.cpp +++ b/common/trace_tools_trace.cpp @@ -33,6 +33,7 @@ #include "os_string.hpp" #include "os_process.hpp" #include "trace_tools.hpp" +#include "trace_resource.hpp" @@ -51,47 +52,33 @@ namespace trace { #endif -static os::String -findWrapper(const char *wrapperFilename) +static inline bool +copyWrapper(const os::String & wrapperPath, + const char *programPath, + bool verbose) { - os::String wrapperPath; - - os::String processDir = os::getProcessName(); - processDir.trimFilename(); - - // Try relative build directory - // XXX: Just make build and install directory layout match - wrapperPath = processDir; - wrapperPath.join("wrappers"); - wrapperPath.join(wrapperFilename); - if (wrapperPath.exists()) { - return wrapperPath; + os::String wrapperFilename(wrapperPath); + wrapperFilename.trimDirectory(); + + os::String tmpWrapper(programPath); + tmpWrapper.trimFilename(); + tmpWrapper.join(wrapperFilename); + + if (verbose) { + std::cerr << wrapperPath << " -> " << tmpWrapper << "\n"; } - // Try relative install directory - wrapperPath = processDir; -#if defined(_WIN32) - wrapperPath.join("..\\lib\\wrappers"); -#elif defined(__APPLE__) - wrapperPath.join("../lib/wrappers"); -#else - wrapperPath.join("../lib/apitrace/wrappers"); -#endif - wrapperPath.join(wrapperFilename); - if (wrapperPath.exists()) { - return wrapperPath; + if (tmpWrapper.exists()) { + std::cerr << "error: not overwriting " << tmpWrapper << "\n"; + return false; } -#ifndef _WIN32 - // Try absolute install directory - wrapperPath = APITRACE_WRAPPER_INSTALL_DIR; - wrapperPath.join(wrapperFilename); - if (wrapperPath.exists()) { - return wrapperPath; + if (!os::copyFile(wrapperPath, tmpWrapper, false)) { + std::cerr << "error: failed to copy " << wrapperPath << " into " << tmpWrapper << "\n"; + return false; } -#endif - return ""; + return true; } @@ -102,11 +89,14 @@ traceProgram(API api, bool verbose) { const char *wrapperFilename; + std::vector args; + int status = 1; /* * TODO: simplify code */ + bool useInject = false; switch (api) { case API_GL: wrapperFilename = GL_TRACE_WRAPPER; @@ -127,7 +117,10 @@ traceProgram(API api, wrapperFilename = "d3d9.dll"; break; case API_D3D10: - wrapperFilename = "d3d10.dll"; + case API_D3D10_1: + case API_D3D11: + wrapperFilename = "dxgitrace.dll"; + useInject = true; break; #endif default: @@ -136,33 +129,25 @@ traceProgram(API api, } os::String wrapperPath = findWrapper(wrapperFilename); - if (!wrapperPath.length()) { std::cerr << "error: failed to find " << wrapperFilename << "\n"; - return 1; + goto exit; } #if defined(_WIN32) - /* On Windows copy the wrapper to the program directory. - */ - os::String tmpWrapper(argv[0]); - tmpWrapper.trimFilename(); - tmpWrapper.join(wrapperFilename); - - if (verbose) { - std::cerr << wrapperPath << " -> " << tmpWrapper << "\n"; - } - - if (tmpWrapper.exists()) { - std::cerr << "error: not overwriting " << tmpWrapper << "\n"; - return 1; - } - - if (!os::copyFile(wrapperPath, tmpWrapper, false)) { - std::cerr << "error: failed to copy " << wrapperPath << " into " << tmpWrapper << "\n"; - return 1; + if (useInject) { + args.push_back("inject"); + args.push_back(wrapperPath); + } else { + /* On Windows copy the wrapper to the program directory. + */ + if (!copyWrapper(wrapperPath, argv[0], verbose)) { + goto exit; + } } -#endif /* _WIN32 */ +#else /* !_WIN32 */ + (void)useInject; +#endif /* !_WIN32 */ #if defined(__APPLE__) /* On Mac OS X, using DYLD_LIBRARY_PATH, we actually set the @@ -182,22 +167,33 @@ traceProgram(API api, os::setEnvironment("TRACE_FILE", output); } + for (char * const * arg = argv; *arg; ++arg) { + args.push_back(*arg); + } + args.push_back(NULL); + if (verbose) { const char *sep = ""; - for (char * const * arg = argv; *arg; ++arg) { - std::cerr << *arg << sep; + for (unsigned i = 0; i < args.size(); ++i) { + std::cerr << sep << args[i]; sep = " "; } std::cerr << "\n"; } - int status = os::execute(argv); + status = os::execute((char * const *)&args[0]); +exit: #if defined(TRACE_VARIABLE) os::unsetEnvironment(TRACE_VARIABLE); #endif #if defined(_WIN32) - os::removeFile(tmpWrapper); + if (!useInject) { + os::String tmpWrapper(argv[0]); + tmpWrapper.trimFilename(); + tmpWrapper.join(wrapperFilename); + os::removeFile(tmpWrapper); + } #endif if (output) {