bool StyleInjector::launch(const QStringList &programAndArgs, const QString &probeDll, const QString &probeFunc) { QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("GAMMARAY_STYLEINJECTOR_PROBEDLL", probeDll); env.insert("GAMMARAY_STYLEINJECTOR_PROBEFUNC", probeFunc); QString qtPluginPath = env.value("QT_PLUGIN_PATH"); if (!qtPluginPath.isEmpty()) { qtPluginPath.append(":"); } qtPluginPath.append(GAMMARAY_LIB_INSTALL_DIR "/qt4/plugins"); env.insert("QT_PLUGIN_PATH", qtPluginPath); InteractiveProcess proc; proc.setProcessEnvironment(env); proc.setProcessChannelMode(QProcess::ForwardedChannels); QStringList args = programAndArgs; if (env.value("GAMMARAY_GDB").toInt()) { QStringList newArgs; newArgs << "gdb" << "--eval-command" << "run" << "--args"; newArgs += args; args = newArgs; } else if (env.value("GAMMARAY_MEMCHECK").toInt()) { QStringList newArgs; newArgs << "valgrind" << "--tool=memcheck" << "--track-origins=yes" << "--num-callers=25"; newArgs += args; args = newArgs; } else if (env.value("GAMMARAY_HELGRIND").toInt()) { QStringList newArgs; newArgs << "valgrind" << "--tool=helgrind"; newArgs += args; args = newArgs; } const QString program = args.takeFirst(); args << QLatin1String("-style") << QLatin1String("gammaray-injector"); proc.start(program, args); proc.waitForFinished(-1); mExitCode = proc.exitCode(); mProcessError = proc.error(); mExitStatus = proc.exitStatus(); mErrorString = proc.errorString(); return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit; }
bool ProcessInjector::launchProcess(const QStringList& programAndArgs, const QProcessEnvironment& env) { InteractiveProcess proc; proc.setProcessEnvironment(env); proc.setProcessChannelMode(QProcess::ForwardedChannels); QStringList args = programAndArgs; if (env.value("GAMMARAY_GDB").toInt()) { QStringList newArgs; newArgs << "gdb"; #ifndef Q_OS_MAC newArgs << "--eval-command" << "run"; #endif newArgs << "--args"; newArgs += args; args = newArgs; } else if (env.value("GAMMARAY_MEMCHECK").toInt()) { QStringList newArgs; newArgs << "valgrind" << "--tool=memcheck" << "--track-origins=yes" << "--num-callers=25" << "--leak-check=full"; newArgs += args; args = newArgs; } else if (env.value("GAMMARAY_HELGRIND").toInt()) { QStringList newArgs; newArgs << "valgrind" << "--tool=helgrind"; newArgs += args; args = newArgs; } const QString program = args.takeFirst(); proc.start(program, args); proc.waitForFinished(-1); mExitCode = proc.exitCode(); mProcessError = proc.error(); mExitStatus = proc.exitStatus(); mErrorString = proc.errorString(); if (mProcessError == QProcess::FailedToStart) { mErrorString.prepend(QString("Could not start '%1': ").arg(program)); } return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit && mProcessError == QProcess::UnknownError; }
bool ProcessInjector::launchProcess(const QStringList& programAndArgs, const QProcessEnvironment& env) { InteractiveProcess proc; proc.setProcessEnvironment(env); proc.setProcessChannelMode(QProcess::ForwardedChannels); QStringList args = programAndArgs; if (!env.value("GAMMARAY_TARGET_WRAPPER").isEmpty()) { const QString fullWrapperCmd = env.value("GAMMARAY_TARGET_WRAPPER"); // ### TODO properly handle quoted arguments! QStringList newArgs = fullWrapperCmd.split(' '); newArgs += args; args = newArgs; qDebug() << "Launching with target wrapper:" << args; } else if (env.value("GAMMARAY_GDB").toInt()) { QStringList newArgs; newArgs << "gdb"; #ifndef Q_OS_MAC newArgs << "--eval-command" << "run"; #endif newArgs << "--args"; newArgs += args; args = newArgs; } const QString program = args.takeFirst(); proc.start(program, args); proc.waitForFinished(-1); mExitCode = proc.exitCode(); mProcessError = proc.error(); mExitStatus = proc.exitStatus(); mErrorString = proc.errorString(); if (mProcessError == QProcess::FailedToStart) { mErrorString.prepend(QString("Could not start '%1': ").arg(program)); } return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit && mProcessError == QProcess::UnknownError; }
bool PreloadInjector::launch(const QStringList &programAndArgs, const QString &probeDll, const QString &probeFunc) { Q_UNUSED(probeFunc); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); #ifdef Q_OS_MAC env.insert("DYLD_FORCE_FLAT_NAMESPACE", QLatin1String("1")); env.insert("DYLD_INSERT_LIBRARIES", probeDll); env.insert("GAMMARAY_UNSET_DYLD", "1"); #else env.insert("LD_PRELOAD", probeDll); env.insert("GAMMARAY_UNSET_PRELOAD", "1"); PreloadCheck check; bool success = check.test("qt_startup_hook"); if (!success) { mExitCode = 1; mErrorString = check.errorString(); return false; } #endif InteractiveProcess proc; proc.setProcessEnvironment(env); proc.setProcessChannelMode(QProcess::ForwardedChannels); QStringList args = programAndArgs; if (env.value("GAMMARAY_GDB").toInt()) { QStringList newArgs; newArgs << "gdb"; #ifndef Q_OS_MAC newArgs << "--eval-command" << "run"; #endif newArgs << "--args"; newArgs += args; args = newArgs; } else if (env.value("GAMMARAY_MEMCHECK").toInt()) { QStringList newArgs; newArgs << "valgrind" << "--tool=memcheck" << "--track-origins=yes" << "--num-callers=25" << "--leak-check=full"; newArgs += args; args = newArgs; } else if (env.value("GAMMARAY_HELGRIND").toInt()) { QStringList newArgs; newArgs << "valgrind" << "--tool=helgrind"; newArgs += args; args = newArgs; } const QString program = args.takeFirst(); proc.start(program, args); proc.waitForFinished(-1); mExitCode = proc.exitCode(); mProcessError = proc.error(); mExitStatus = proc.exitStatus(); mErrorString = proc.errorString(); return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit && mProcessError == QProcess::UnknownError; }