Analyzer: Slim down AnalyzerStartParameters

* SysRoot can always be determined from kit.
* Pass around RunMode as extra parameter
  not as part of AnalyzerStartParameters.
  That's closer to the pattern used elsewhere.
* Environment was always initialized from the runconfig's
  EnvironmentAspect. The tools can do that directly.
* Provide setter for display name for cases where
  it is not equal to RunConfiguration::displayName

Change-Id: I811a0d7cdeb55cc37a16a593b3942abb567a2150
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
This commit is contained in:
hjk
2016-01-06 11:40:52 +01:00
parent 3120692092
commit 8150209ff7
29 changed files with 177 additions and 219 deletions

View File

@@ -46,7 +46,7 @@ using namespace Valgrind::Internal;
CallgrindRunControl::CallgrindRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
: ValgrindRunControl(sp, runConfiguration)
: ValgrindRunControl(sp, runConfiguration, CALLGRIND_RUN_MODE)
, m_markAsPaused(false)
{
connect(&m_runner, &Callgrind::CallgrindRunner::finished,

View File

@@ -30,6 +30,7 @@
****************************************************************************/
#include "memcheckengine.h"
#include "memchecktool.h"
#include "valgrindprocess.h"
#include "valgrindsettings.h"
#include "xmlprotocol/error.h"
@@ -56,8 +57,8 @@ namespace Valgrind {
namespace Internal {
MemcheckRunControl::MemcheckRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
: ValgrindRunControl(sp, runConfiguration)
RunConfiguration *runConfiguration, Core::Id runMode)
: ValgrindRunControl(sp, runConfiguration, runMode)
{
connect(&m_parser, &XmlProtocol::ThreadedParser::error,
this, &MemcheckRunControl::parserError);
@@ -135,7 +136,7 @@ QStringList MemcheckRunControl::suppressionFiles() const
MemcheckWithGdbRunControl::MemcheckWithGdbRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
: MemcheckRunControl(sp, runConfiguration)
: MemcheckRunControl(sp, runConfiguration, MEMCHECK_WITH_GDB_RUN_MODE)
{
connect(&m_runner, &Memcheck::MemcheckRunner::started,
this, &MemcheckWithGdbRunControl::startDebugger);

View File

@@ -46,7 +46,8 @@ class MemcheckRunControl : public ValgrindRunControl
public:
MemcheckRunControl(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode);
bool startEngine() override;
void stopEngine() override;

View File

@@ -429,13 +429,17 @@ QWidget *MemcheckTool::createWidgets()
}
MemcheckRunControl *MemcheckTool::createRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
RunConfiguration *runConfiguration,
Core::Id runMode)
{
m_frameFinder->setFiles(runConfiguration ? runConfiguration->target()
->project()->files(Project::AllFiles) : QStringList());
MemcheckRunControl *engine = createMemcheckRunControl(sp, runConfiguration);
MemcheckRunControl *engine = 0;
if (runMode == MEMCHECK_RUN_MODE)
engine = new MemcheckRunControl(sp, runConfiguration, runMode);
else
engine = new MemcheckWithGdbRunControl(sp, runConfiguration);
connect(engine, &MemcheckRunControl::starting, this, &MemcheckTool::engineStarting);
connect(engine, &MemcheckRunControl::parserError, this, &MemcheckTool::parserError);
connect(engine, &MemcheckRunControl::internalParserError, this, &MemcheckTool::internalParserError);
@@ -567,12 +571,6 @@ int MemcheckTool::updateUiAfterFinishedHelper()
return issuesFound;
}
MemcheckRunControl *MemcheckTool::createMemcheckRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
{
return new MemcheckRunControl(sp, runConfiguration);
}
void MemcheckTool::engineFinished()
{
const int issuesFound = updateUiAfterFinishedHelper();
@@ -595,17 +593,5 @@ void MemcheckTool::setBusyCursor(bool busy)
m_errorView->setCursor(cursor);
}
MemcheckWithGdbTool::MemcheckWithGdbTool(QObject *parent) :
MemcheckTool(parent)
{
setObjectName(QLatin1String("MemcheckWithGdbTool"));
}
MemcheckRunControl *MemcheckWithGdbTool::createMemcheckRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
{
return new MemcheckWithGdbRunControl(sp, runConfiguration);
}
} // namespace Internal
} // namespace Valgrind

View File

@@ -91,7 +91,8 @@ public:
QWidget *createWidgets();
MemcheckRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode);
private slots:
void settingsDestroyed(QObject *settings);
@@ -115,11 +116,6 @@ private:
void updateFromSettings();
int updateUiAfterFinishedHelper();
protected:
virtual MemcheckRunControl *createMemcheckRunControl(
const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
private:
ValgrindBaseSettings *m_settings;
QMenu *m_filterMenu;
@@ -138,16 +134,6 @@ private:
QAction *m_goNext;
};
class MemcheckWithGdbTool : public MemcheckTool
{
public:
MemcheckWithGdbTool(QObject *parent);
MemcheckRunControl *createMemcheckRunControl(
const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) override;
};
} // namespace Internal
} // namespace Valgrind

View File

@@ -55,12 +55,13 @@ namespace Valgrind {
namespace Internal {
ValgrindRunControl::ValgrindRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
: AnalyzerRunControl(sp, runConfiguration),
RunConfiguration *runConfiguration, Core::Id runMode)
: AnalyzerRunControl(sp, runConfiguration, runMode),
m_settings(0),
m_isStopping(false)
{
m_isCustomStart = false;
m_localRunMode = ApplicationLauncher::Gui;
if (runConfiguration)
if (IRunConfigurationAspect *aspect = runConfiguration->extraAspect(ANALYZER_VALGRIND_SETTINGS))
@@ -94,15 +95,15 @@ bool ValgrindRunControl::startEngine()
#endif
ValgrindRunner *run = runner();
run->setWorkingDirectory(sp.workingDirectory);
run->setWorkingDirectory(workingDirectory());
run->setValgrindExecutable(m_settings->valgrindExecutable());
run->setValgrindArguments(genericToolArguments() + toolArguments());
run->setDebuggeeExecutable(sp.debuggee);
run->setDebuggeeArguments(sp.debuggeeArgs);
run->setEnvironment(sp.environment);
run->setEnvironment(m_environment);
run->setConnectionParameters(sp.connParams);
run->setUseStartupProject(!m_isCustomStart);
run->setLocalRunMode(sp.localRunMode);
run->setLocalRunMode(m_localRunMode);
connect(run, &ValgrindRunner::processOutputReceived,
this, &ValgrindRunControl::receiveProcessOutput);
@@ -129,6 +130,16 @@ QString ValgrindRunControl::executable() const
return startParameters().debuggee;
}
void ValgrindRunControl::setEnvironment(const Utils::Environment &environment)
{
m_environment = environment;
}
void ValgrindRunControl::setLocalRunMode(ApplicationLauncher::Mode localRunMode)
{
m_localRunMode = localRunMode;
}
QStringList ValgrindRunControl::genericToolArguments() const
{
QTC_ASSERT(m_settings, return QStringList());

View File

@@ -49,14 +49,18 @@ class ValgrindRunControl : public Analyzer::AnalyzerRunControl
public:
ValgrindRunControl(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode);
~ValgrindRunControl();
bool startEngine();
void stopEngine();
QString executable() const;
void setCustomStart() { m_isCustomStart = true; }
void setEnvironment(const Utils::Environment &environment);
void setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode localRunMode);
protected:
virtual QString progressTitle() const = 0;
@@ -66,6 +70,8 @@ protected:
ValgrindBaseSettings *m_settings;
QFutureInterface<void> m_progress;
bool m_isCustomStart;
Utils::Environment m_environment;
ProjectExplorer::ApplicationLauncher::Mode m_localRunMode;
private slots:
void handleProgressCanceled();

View File

@@ -110,20 +110,6 @@ ValgrindPlugin::~ValgrindPlugin()
theGlobalSettings = 0;
}
static bool fillParameters(AnalyzerStartParameters *sp)
{
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return false;
sp->connParams = dlg.sshParams();
sp->debuggee = dlg.executable();
sp->debuggeeArgs = dlg.arguments();
sp->displayName = dlg.executable();
sp->workingDirectory = dlg.workingDirectory();
return false;
}
bool ValgrindPlugin::initialize(const QStringList &, QString *)
{
theGlobalSettings = new ValgrindGlobalSettings();
@@ -137,6 +123,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
void ValgrindPlugin::extensionsInitialized()
{
using namespace std::placeholders;
AnalyzerAction *action = 0;
QString callgrindToolTip = tr("Valgrind Function Profile uses the "
@@ -147,15 +134,10 @@ void ValgrindPlugin::extensionsInitialized()
auto mcTool = new MemcheckTool(this);
auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); };
auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) -> AnalyzerRunControl * {
return mcTool->createRunControl(sp, runConfiguration);
};
auto cgTool = new CallgrindTool(this);
auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); };
auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) {
RunConfiguration *runConfiguration, Core::Id) {
return cgTool->createRunControl(sp, runConfiguration);
};
@@ -164,8 +146,9 @@ void ValgrindPlugin::extensionsInitialized()
action->setActionId("Memcheck.Local");
action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator);
action->setToolMode(SymbolsMode);
action->setRunControlCreator(std::bind(&MemcheckTool::createRunControl,
mcTool, _1, _2, MEMCHECK_RUN_MODE));
action->setToolMode(DebugMode);
action->setRunMode(MEMCHECK_RUN_MODE);
action->setText(tr("Valgrind Memory Analyzer"));
action->setToolTip(memcheckToolTip);
@@ -173,15 +156,14 @@ void ValgrindPlugin::extensionsInitialized()
action->setEnabled(false);
AnalyzerManager::addAction(action);
using namespace std::placeholders;
auto mcgTool = new MemcheckWithGdbTool(this);
auto mcgTool = new MemcheckTool(this);
action = new AnalyzerAction(this);
action->setActionId("MemcheckWithGdb.Local");
action->setToolId("MemcheckWithGdb");
action->setWidgetCreator([mcgTool] { return mcgTool->createWidgets(); });
action->setRunControlCreator(std::bind(&MemcheckWithGdbTool::createRunControl,
mcgTool, _1, _2));
action->setToolMode(SymbolsMode);
action->setRunControlCreator(std::bind(&MemcheckTool::createRunControl,
mcgTool, _1, _2, MEMCHECK_WITH_GDB_RUN_MODE));
action->setToolMode(DebugMode);
action->setRunMode(MEMCHECK_WITH_GDB_RUN_MODE);
action->setText(tr("Valgrind Memory Analyzer with GDB"));
action->setToolTip(tr("Valgrind Analyze Memory with GDB uses the "
@@ -210,11 +192,17 @@ void ValgrindPlugin::extensionsInitialized()
action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator);
action->setCustomToolStarter([mcTool] {
AnalyzerStartParameters sp;
if (!fillParameters(&sp))
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return;
ValgrindRunControl *rc = mcTool->createRunControl(sp, 0);
AnalyzerStartParameters sp;
sp.connParams = dlg.sshParams();
sp.debuggee = dlg.executable();
sp.debuggeeArgs = dlg.arguments();
ValgrindRunControl *rc = mcTool->createRunControl(sp, 0, MEMCHECK_RUN_MODE);
QTC_ASSERT(rc, return);
rc->setDisplayName(dlg.executable());
rc->setWorkingDirectory(dlg.workingDirectory());
rc->setCustomStart();
ProjectExplorerPlugin::startRunControl(rc, MEMCHECK_RUN_MODE);
});
@@ -228,11 +216,17 @@ void ValgrindPlugin::extensionsInitialized()
action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator);
action->setCustomToolStarter([cgTool] {
AnalyzerStartParameters sp;
if (!fillParameters(&sp))
StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted)
return;
AnalyzerStartParameters sp;
sp.connParams = dlg.sshParams();
sp.debuggee = dlg.executable();
sp.debuggeeArgs = dlg.arguments();
ValgrindRunControl *rc = cgTool->createRunControl(sp, 0);
QTC_ASSERT(rc, return);
rc->setDisplayName(dlg.executable());
rc->setWorkingDirectory(dlg.workingDirectory());
rc->setCustomStart();
ProjectExplorerPlugin::startRunControl(rc, CALLGRIND_RUN_MODE);
});

View File

@@ -29,6 +29,8 @@
****************************************************************************/
#include "valgrindruncontrolfactory.h"
#include "valgrindengine.h"
#include "valgrindsettings.h"
#include "valgrindplugin.h"
#include "callgrindtool.h"
@@ -55,6 +57,7 @@
using namespace Analyzer;
using namespace ProjectExplorer;
using namespace Utils;
namespace Valgrind {
namespace Internal {
@@ -74,15 +77,15 @@ RunControl *ValgrindRunControlFactory::create(RunConfiguration *runConfiguration
{
Q_UNUSED(errorMessage);
ApplicationLauncher::Mode localRunMode = ApplicationLauncher::Gui;
Utils::Environment environment;
AnalyzerStartParameters sp;
sp.displayName = runConfiguration->displayName();
sp.runMode = mode;
if (LocalApplicationRunConfiguration *rc1 =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) {
QString workingDirectory;
if (auto rc1 = qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) {
EnvironmentAspect *aspect = runConfiguration->extraAspect<EnvironmentAspect>();
if (aspect)
sp.environment = aspect->environment();
sp.workingDirectory = rc1->workingDirectory();
environment = aspect->environment();
workingDirectory = rc1->workingDirectory();
sp.debuggee = rc1->executable();
sp.debuggeeArgs = rc1->commandLineArguments();
const IDevice::ConstPtr device =
@@ -96,19 +99,23 @@ RunControl *ValgrindRunControlFactory::create(RunConfiguration *runConfiguration
}
sp.connParams.host = server.serverAddress().toString();
sp.connParams.port = server.serverPort();
sp.localRunMode = static_cast<ApplicationLauncher::Mode>(rc1->runMode());
localRunMode = rc1->runMode();
} else if (RemoteLinux::AbstractRemoteLinuxRunConfiguration *rc2 =
qobject_cast<RemoteLinux::AbstractRemoteLinuxRunConfiguration *>(runConfiguration)) {
sp.debuggee = rc2->remoteExecutableFilePath();
sp.connParams = DeviceKitInformation::device(rc2->target()->kit())->sshParameters();
sp.debuggeeArgs = rc2->arguments().join(QLatin1Char(' '));
sp.workingDirectory = rc2->workingDirectory();
sp.environment = rc2->environment();
} else {
QTC_ASSERT(false, return 0);
}
return AnalyzerManager::createRunControl(sp, runConfiguration);
auto analyzerRunControl = AnalyzerManager::createRunControl(sp, runConfiguration, mode);
if (auto valgrindRunControl = qobject_cast<ValgrindRunControl *>(analyzerRunControl)) {
valgrindRunControl->setLocalRunMode(localRunMode);
valgrindRunControl->setEnvironment(environment);
valgrindRunControl->setWorkingDirectory(workingDirectory);
}
return analyzerRunControl;
}

View File

@@ -183,11 +183,6 @@ void ValgrindRunner::setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode
d->localRunMode = localRunMode;
}
ProjectExplorer::ApplicationLauncher::Mode ValgrindRunner::localRunMode() const
{
return d->localRunMode;
}
const QSsh::SshConnectionParameters &ValgrindRunner::connectionParameters() const
{
return d->connParams;

View File

@@ -76,7 +76,6 @@ public:
bool useStartupProject() const;
void setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode localRunMode);
ProjectExplorer::ApplicationLauncher::Mode localRunMode() const;
void setConnectionParameters(const QSsh::SshConnectionParameters &connParams);
const QSsh::SshConnectionParameters &connectionParameters() const;