Debugger: Move some commonly used flags to base DebuggerTool

Basically all derived tools will need access to the debugger aspect
data. Fetch it once.

Change-Id: I054e4255a036db258201a8a501af244206c06990
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-05-03 12:35:00 +02:00
parent 20cacb4a8a
commit ba5d12e80f
4 changed files with 55 additions and 41 deletions

View File

@@ -477,23 +477,47 @@ static bool isDebuggableScript(RunConfiguration *runConfig)
return mainScript.endsWith(".py"); // Only Python for now.
}
static DebuggerRunConfigurationAspect *debuggerAspect(const RunControl *runControl)
{
return runControl->runConfiguration()->extraAspect<DebuggerRunConfigurationAspect>();
}
/// DebuggerRunTool
DebuggerRunTool::DebuggerRunTool(RunControl *runControl)
: ToolRunner(runControl),
m_isCppDebugging(debuggerAspect(runControl)->useCppDebugger()),
m_isQmlDebugging(debuggerAspect(runControl)->useQmlDebugger())
{
}
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerStartParameters &sp, QString *errorMessage)
: DebuggerRunTool(runControl, DebuggerRunParameters(sp), errorMessage)
{}
: DebuggerRunTool(runControl)
{
setStartParameters(sp, errorMessage);
}
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParameters &rp, QString *errorMessage)
: ToolRunner(runControl)
: DebuggerRunTool(runControl)
{
setRunParameters(rp, errorMessage);
}
void DebuggerRunTool::setStartParameters(const DebuggerStartParameters &sp, QString *errorMessage)
{
setRunParameters(sp, errorMessage);
}
void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp, QString *errorMessage)
{
DebuggerRunParameters m_rp = rp;
runControl->setDisplayName(m_rp.displayName);
runControl()->setDisplayName(m_rp.displayName);
// QML and/or mixed are not prepared for it.
runControl->setSupportsReRunning(!(m_rp.languages & QmlLanguage));
runControl()->setSupportsReRunning(!(m_rp.languages & QmlLanguage));
runControl->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR);
runControl->setPromptToStop([](bool *optionalPrompt) {
runControl()->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL_TOOLBAR);
runControl()->setPromptToStop([](bool *optionalPrompt) {
return RunControl::showPromptToStopDialog(
DebuggerRunTool::tr("Close Debugging Session"),
DebuggerRunTool::tr("A debugging session is still in progress. "
@@ -503,7 +527,7 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParame
QString(), QString(), optionalPrompt);
});
if (Internal::fixupParameters(m_rp, runControl, m_errors)) {
if (Internal::fixupParameters(m_rp, runControl(), m_errors)) {
m_engine = createEngine(m_rp.masterEngineType, m_rp, &m_errors);
if (!m_engine) {
QString msg = m_errors.join('\n');
@@ -515,7 +539,7 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParame
m_engine->setRunTool(this);
connect(runControl, &RunControl::finished,
connect(runControl(), &RunControl::finished,
this, &DebuggerRunTool::handleFinished);
}

View File

@@ -41,14 +41,21 @@ class DEBUGGER_EXPORT DebuggerRunTool : public ProjectExplorer::ToolRunner
Q_OBJECT
public:
DebuggerRunTool(ProjectExplorer::RunControl *runControl); // Use.
DebuggerRunTool(ProjectExplorer::RunControl *runControl,
const DebuggerStartParameters &sp,
QString *errorMessage = nullptr); // Use.
QString *errorMessage = nullptr); // Use rarely.
DebuggerRunTool(ProjectExplorer::RunControl *runControl,
const Internal::DebuggerRunParameters &rp,
QString *errorMessage = nullptr); // FIXME: Don't use.
~DebuggerRunTool();
void setStartParameters(const DebuggerStartParameters &sp,
QString *errorMessage = nullptr); // Use rarely.
void setRunParameters(const Internal::DebuggerRunParameters &rp,
QString *errorMessage = nullptr); // FIXME: Don't use.
Internal::DebuggerEngine *engine() const { return m_engine; }
void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1);
@@ -71,6 +78,9 @@ public:
DebuggerStartParameters &startParameters(); // Used in Boot2Qt.
bool isCppDebugging() const { return m_isCppDebugging; }
bool isQmlDebugging() const { return m_isQmlDebugging; }
signals:
void stateChanged(Debugger::DebuggerState state);
void aboutToNotifyInferiorSetupOk();
@@ -79,6 +89,8 @@ signals:
private:
Internal::DebuggerEngine *m_engine = nullptr; // Master engine
QStringList m_errors;
const bool m_isCppDebugging;
const bool m_isQmlDebugging;
};
} // namespace Debugger

View File

@@ -27,10 +27,8 @@
#include "remotelinuxrunconfiguration.h"
#include <debugger/debuggerrunconfigurationaspect.h>
#include <debugger/debuggerruncontrol.h>
#include <debugger/debuggerstartparameters.h>
#include <debugger/debuggerkitinformation.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
@@ -56,14 +54,6 @@ namespace Internal {
class LinuxDeviceDebugSupportPrivate
{
public:
LinuxDeviceDebugSupportPrivate(const RunConfiguration *runConfig)
: qmlDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useQmlDebugger()),
cppDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useCppDebugger())
{
}
bool qmlDebugging;
bool cppDebugging;
QByteArray gdbserverOutput;
Port gdbServerPort;
Port qmlPort;
@@ -77,7 +67,7 @@ LinuxDeviceDebugSupport::LinuxDeviceDebugSupport(RunControl *runControl,
const Debugger::DebuggerStartParameters &sp,
QString *errorMessage)
: DebuggerRunTool(runControl, sp, errorMessage),
d(new LinuxDeviceDebugSupportPrivate(runControl->runConfiguration()))
d(new LinuxDeviceDebugSupportPrivate)
{
connect(this, &DebuggerRunTool::requestRemoteSetup,
this, &LinuxDeviceDebugSupport::handleRemoteSetupRequested);
@@ -97,16 +87,6 @@ LinuxDeviceDebugSupport::~LinuxDeviceDebugSupport()
delete d;
}
bool LinuxDeviceDebugSupport::isCppDebugging() const
{
return d->cppDebugging;
}
bool LinuxDeviceDebugSupport::isQmlDebugging() const
{
return d->qmlDebugging;
}
AbstractRemoteLinuxRunSupport *LinuxDeviceDebugSupport::targetRunner() const
{
return qobject_cast<AbstractRemoteLinuxRunSupport *>(runControl()->targetRunner());
@@ -130,14 +110,14 @@ void LinuxDeviceDebugSupport::startExecution()
{
QTC_ASSERT(state() == AbstractRemoteLinuxRunSupport::GatheringResources, return);
if (d->cppDebugging) {
if (isCppDebugging()) {
d->gdbServerPort = targetRunner()->findPort();
if (!d->gdbServerPort.isValid()) {
handleAdapterSetupFailed(tr("Not enough free ports on device for C++ debugging."));
return;
}
}
if (d->qmlDebugging) {
if (isQmlDebugging()) {
d->qmlPort = targetRunner()->findPort();
if (!d->qmlPort.isValid()) {
handleAdapterSetupFailed(tr("Not enough free ports on device for QML debugging."));
@@ -159,7 +139,7 @@ void LinuxDeviceDebugSupport::startExecution()
this, &LinuxDeviceDebugSupport::handleProgressReport);
connect(launcher, &ApplicationLauncher::reportError,
this, &LinuxDeviceDebugSupport::handleAppRunnerError);
if (d->qmlDebugging && !d->cppDebugging)
if (isQmlDebugging() && !isCppDebugging())
connect(launcher, &ApplicationLauncher::remoteProcessStarted,
this, &LinuxDeviceDebugSupport::handleRemoteProcessStarted);
@@ -172,10 +152,10 @@ Runnable LinuxDeviceDebugSupport::realRunnable() const
QStringList args = QtcProcess::splitArgs(r.commandLineArguments, OsTypeLinux);
QString command;
if (d->qmlDebugging)
if (isQmlDebugging())
args.prepend(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, d->qmlPort));
if (d->qmlDebugging && !d->cppDebugging) {
if (isQmlDebugging() && !isCppDebugging()) {
command = r.executable;
} else {
command = device()->debugServerPath();
@@ -207,7 +187,7 @@ void LinuxDeviceDebugSupport::handleAppRunnerFinished(bool success)
if (state() == AbstractRemoteLinuxRunSupport::Running) {
// The QML engine does not realize on its own that the application has finished.
if (d->qmlDebugging && !d->cppDebugging)
if (isQmlDebugging() && !isCppDebugging())
quitDebugger();
else if (!success)
notifyInferiorIll();
@@ -240,7 +220,7 @@ void LinuxDeviceDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
QTC_ASSERT(state() != AbstractRemoteLinuxRunSupport::GatheringResources, return);
showMessage(QString::fromUtf8(output), AppError);
if (state() == AbstractRemoteLinuxRunSupport::StartingRunner && d->cppDebugging) {
if (state() == AbstractRemoteLinuxRunSupport::StartingRunner && isCppDebugging()) {
d->gdbserverOutput += output;
if (d->gdbserverOutput.contains("Listening on port")) {
handleAdapterSetupDone();
@@ -275,7 +255,7 @@ void LinuxDeviceDebugSupport::handleAdapterSetupDone()
void LinuxDeviceDebugSupport::handleRemoteProcessStarted()
{
QTC_ASSERT(d->qmlDebugging && !d->cppDebugging, return);
QTC_ASSERT(isQmlDebugging() && !isCppDebugging(), return);
QTC_ASSERT(state() == AbstractRemoteLinuxRunSupport::StartingRunner, return);
handleAdapterSetupDone();

View File

@@ -45,8 +45,6 @@ public:
protected:
virtual ProjectExplorer::Runnable realRunnable() const;
bool isCppDebugging() const;
bool isQmlDebugging() const;
private:
void startExecution();