Debugger: Replace a few more uses of setRunParameters

Change-Id: I8f35bcd3812402cda7d3c69eb01ed3d3fb9e396a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-09-12 12:38:31 +02:00
parent 4c360601b4
commit 67b4a7a872
6 changed files with 91 additions and 75 deletions

View File

@@ -367,9 +367,8 @@ void StartApplicationDialog::updateState()
d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(okEnabled); d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(okEnabled);
} }
bool StartApplicationDialog::run(QWidget *parent, DebuggerRunParameters *rp, Kit **kit) void StartApplicationDialog::run(bool attachRemote)
{ {
const bool attachRemote = rp->startMode == AttachToRemoteServer;
const QString settingsGroup = QLatin1String("DebugMode"); const QString settingsGroup = QLatin1String("DebugMode");
const QString arrayName = QLatin1String("StartApplication"); const QString arrayName = QLatin1String("StartApplication");
@@ -389,7 +388,7 @@ bool StartApplicationDialog::run(QWidget *parent, DebuggerRunParameters *rp, Kit
settings->endArray(); settings->endArray();
settings->endGroup(); settings->endGroup();
StartApplicationDialog dialog(parent); StartApplicationDialog dialog(ICore::dialogParent());
dialog.setHistory(history); dialog.setHistory(history);
dialog.setParameters(history.back()); dialog.setParameters(history.back());
if (!attachRemote) { if (!attachRemote) {
@@ -401,11 +400,14 @@ bool StartApplicationDialog::run(QWidget *parent, DebuggerRunParameters *rp, Kit
dialog.d->channelOverrideEdit->setVisible(false); dialog.d->channelOverrideEdit->setVisible(false);
} }
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return false; return;
Kit *k = dialog.d->kitChooser->currentKit(); Kit *k = dialog.d->kitChooser->currentKit();
IDevice::ConstPtr dev = DeviceKitInformation::device(k); IDevice::ConstPtr dev = DeviceKitInformation::device(k);
DebuggerRunTool *debugger = DebuggerRunTool::createFromKit(k);
QTC_ASSERT(debugger, return);
const StartApplicationParameters newParameters = dialog.parameters(); const StartApplicationParameters newParameters = dialog.parameters();
if (newParameters != history.back()) { if (newParameters != history.back()) {
history.append(newParameters); history.append(newParameters);
@@ -421,27 +423,39 @@ bool StartApplicationDialog::run(QWidget *parent, DebuggerRunParameters *rp, Kit
settings->endGroup(); settings->endGroup();
} }
rp->inferior.executable = newParameters.runnable.executable; StandardRunnable inferior = newParameters.runnable;
debugger->setUseTerminal(newParameters.runnable.runMode == ApplicationLauncher::Console);
const QString inputAddress = dialog.d->channelOverrideEdit->text(); const QString inputAddress = dialog.d->channelOverrideEdit->text();
if (!inputAddress.isEmpty()) if (!inputAddress.isEmpty())
rp->remoteChannel = inputAddress; debugger->setRemoteChannel(inputAddress);
else else
rp->remoteChannel = QString("%1:%2").arg(dev->sshParameters().host).arg(newParameters.serverPort); debugger->setRemoteChannel(dev->sshParameters().host, newParameters.serverPort);
rp->displayName = newParameters.displayName(); debugger->setRunControlName(newParameters.displayName());
rp->inferior.workingDirectory = newParameters.runnable.workingDirectory; debugger->setBreakOnMain(newParameters.breakAtMain);
rp->useTerminal = newParameters.runnable.runMode == ApplicationLauncher::Console; debugger->setServerStartScript(newParameters.serverStartScript);
if (!newParameters.runnable.commandLineArguments.isEmpty()) debugger->setDebugInfoLocation(newParameters.debugInfoLocation);
rp->inferior.commandLineArguments = newParameters.runnable.commandLineArguments; debugger->setInferior(inferior);
rp->breakOnMain = newParameters.breakAtMain;
rp->serverStartScript = newParameters.serverStartScript;
rp->debugInfoLocation = newParameters.debugInfoLocation;
bool isLocal = !dev || (dev->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); bool isLocal = !dev || (dev->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
if (!attachRemote) if (!attachRemote)
rp->startMode = isLocal ? StartExternal : StartRemoteProcess; debugger->setStartMode(isLocal ? StartExternal : StartRemoteProcess);
if (kit)
*kit = k; if (attachRemote) {
return true; debugger->setStartMode(AttachToRemoteServer);
debugger->setCloseMode(KillAtClose);
debugger->setUseContinueInsteadOfRun(true);
}
debugger->startRunControl();
}
void StartApplicationDialog::attachToRemoteServer()
{
run(true);
}
void StartApplicationDialog::startAndDebugApplication()
{
run(false);
} }
StartApplicationParameters StartApplicationDialog::parameters() const StartApplicationParameters StartApplicationDialog::parameters() const

View File

@@ -72,7 +72,8 @@ public:
explicit StartApplicationDialog(QWidget *parent); explicit StartApplicationDialog(QWidget *parent);
~StartApplicationDialog(); ~StartApplicationDialog();
static bool run(QWidget *parent, DebuggerRunParameters *rp, ProjectExplorer::Kit **kit); static void attachToRemoteServer();
static void startAndDebugApplication();
private: private:
void historyIndexChanged(int); void historyIndexChanged(int);
@@ -81,6 +82,7 @@ private:
void setParameters(const StartApplicationParameters &p); void setParameters(const StartApplicationParameters &p);
void setHistory(const QList<StartApplicationParameters> &l); void setHistory(const QList<StartApplicationParameters> &l);
void onChannelOverrideChanged(const QString &channel); void onChannelOverrideChanged(const QString &channel);
static void run(bool);
StartApplicationDialogPrivate *d; StartApplicationDialogPrivate *d;
}; };

View File

@@ -46,10 +46,7 @@ QT_END_NAMESPACE
namespace Core { class IOptionsPage; } namespace Core { class IOptionsPage; }
namespace Utils { namespace Utils { class MacroExpander; }
class MacroExpander;
class ProcessHandle;
} // Utils
namespace Debugger { namespace Debugger {

View File

@@ -733,10 +733,8 @@ public:
void onModeChanged(Id mode); void onModeChanged(Id mode);
void updateDebugWithoutDeployMenu(); void updateDebugWithoutDeployMenu();
void startAndDebugApplication();
void startRemoteCdbSession(); void startRemoteCdbSession();
void startRemoteServerAndAttachToProcess(); void startRemoteServerAndAttachToProcess();
void attachToRemoteServer();
void attachToRunningApplication(); void attachToRunningApplication();
void attachToUnstartedApplicationDialog(); void attachToUnstartedApplicationDialog();
void attachToQmlPort(); void attachToQmlPort();
@@ -1499,7 +1497,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
act = m_startAndDebugApplicationAction = new QAction(this); act = m_startAndDebugApplicationAction = new QAction(this);
act->setText(tr("Start and Debug External Application...")); act->setText(tr("Start and Debug External Application..."));
connect(act, &QAction::triggered, this, &DebuggerPluginPrivate::startAndDebugApplication); connect(act, &QAction::triggered, this, &StartApplicationDialog::startAndDebugApplication);
act = m_attachToCoreAction = new QAction(this); act = m_attachToCoreAction = new QAction(this);
act->setText(tr("Load Core File...")); act->setText(tr("Load Core File..."));
@@ -1507,7 +1505,7 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
act = m_attachToRemoteServerAction = new QAction(this); act = m_attachToRemoteServerAction = new QAction(this);
act->setText(tr("Attach to Running Debug Server...")); act->setText(tr("Attach to Running Debug Server..."));
connect(act, &QAction::triggered, this, &DebuggerPluginPrivate::attachToRemoteServer); connect(act, &QAction::triggered, this, &StartApplicationDialog::attachToRemoteServer);
act = m_startRemoteServerAction = new QAction(this); act = m_startRemoteServerAction = new QAction(this);
act->setText(tr("Start Debug Server Attached to Process...")); act->setText(tr("Start Debug Server Attached to Process..."));
@@ -1936,18 +1934,6 @@ void DebuggerPluginPrivate::onCurrentProjectChanged(Project *project)
setProxyAction(m_visibleStartAction, Id(Constants::DEBUG)); setProxyAction(m_visibleStartAction, Id(Constants::DEBUG));
} }
void DebuggerPluginPrivate::startAndDebugApplication()
{
DebuggerRunParameters rp;
Kit *kit;
if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) {
auto debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
}
}
void DebuggerPluginPrivate::attachCore() void DebuggerPluginPrivate::attachCore()
{ {
AttachCoreDialog dlg(ICore::dialogParent()); AttachCoreDialog dlg(ICore::dialogParent());
@@ -1971,19 +1957,16 @@ void DebuggerPluginPrivate::attachCore()
setConfigValue("LastExternalStartScript", dlg.overrideStartScript()); setConfigValue("LastExternalStartScript", dlg.overrideStartScript());
setConfigValue("LastForceLocalCoreFile", dlg.forcesLocalCoreFile()); setConfigValue("LastForceLocalCoreFile", dlg.forcesLocalCoreFile());
QString display = dlg.useLocalCoreFile() ? dlg.localCoreFile() : dlg.remoteCoreFile();
DebuggerRunParameters rp;
rp.masterEngineType = DebuggerKitInformation::engineType(dlg.kit());
rp.inferior.executable = dlg.localExecutableFile();
rp.coreFile = dlg.localCoreFile();
rp.displayName = tr("Core file \"%1\"").arg(display);
rp.startMode = AttachCore;
rp.closeMode = DetachAtClose;
rp.overrideStartScript = dlg.overrideStartScript();
auto debugger = DebuggerRunTool::createFromKit(dlg.kit()); auto debugger = DebuggerRunTool::createFromKit(dlg.kit());
QTC_ASSERT(debugger, return); QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp); debugger->setMasterEngineType(DebuggerKitInformation::engineType(dlg.kit()));
debugger->setInferiorExecutable(dlg.localExecutableFile());
debugger->setCoreFileName(dlg.localCoreFile());
debugger->setRunControlName(tr("Core file \"%1\"")
.arg(dlg.useLocalCoreFile() ? dlg.localCoreFile() : dlg.remoteCoreFile()));
debugger->setStartMode(AttachCore);
debugger->setCloseMode(DetachAtClose);
debugger->setOverrideStartScript(dlg.overrideStartScript());
debugger->startRunControl(); debugger->startRunControl();
} }
@@ -2010,21 +1993,6 @@ void DebuggerPluginPrivate::startRemoteCdbSession()
debugger->startRunControl(); debugger->startRunControl();
} }
void DebuggerPluginPrivate::attachToRemoteServer()
{
DebuggerRunParameters rp;
Kit *kit;
rp.startMode = AttachToRemoteServer;
rp.useContinueInsteadOfRun = true;
if (StartApplicationDialog::run(ICore::dialogParent(), &rp, &kit)) {
rp.closeMode = KillAtClose;
auto debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
debugger->setRunParameters(rp);
debugger->startRunControl();
}
}
void DebuggerPluginPrivate::startRemoteServerAndAttachToProcess() void DebuggerPluginPrivate::startRemoteServerAndAttachToProcess()
{ {
auto kitChooser = new DebuggerKitChooser(DebuggerKitChooser::AnyDebugging); auto kitChooser = new DebuggerKitChooser(DebuggerKitChooser::AnyDebugging);
@@ -2135,22 +2103,20 @@ RunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
void DebuggerPlugin::attachExternalApplication(RunControl *rc) void DebuggerPlugin::attachExternalApplication(RunControl *rc)
{ {
DebuggerRunParameters rp;
rp.attachPID = rc->applicationProcessHandle();
rp.displayName = tr("Process %1").arg(rp.attachPID.pid());
rp.startMode = AttachExternal;
rp.closeMode = DetachAtClose;
rp.toolChainAbi = rc->abi();
rp.languages = CppLanguage;
DebuggerRunTool *debugger; DebuggerRunTool *debugger;
if (RunConfiguration *runConfig = rc->runConfiguration()) { if (RunConfiguration *runConfig = rc->runConfiguration()) {
debugger = DebuggerRunTool::createFromRunConfiguration(runConfig); debugger = DebuggerRunTool::createFromRunConfiguration(runConfig);
} else { } else {
Kit *kit = guessKitFromAbis({rc->abi()}); Kit *kit = guessKitFromAbis({rc->abi()});
debugger = DebuggerRunTool::createFromKit(kit); debugger = DebuggerRunTool::createFromKit(kit);
QTC_ASSERT(debugger, return);
} }
debugger->setRunParameters(rp); QTC_ASSERT(debugger, return);
ProcessHandle pid = rc->applicationProcessHandle();
debugger->setAttachPid(pid);
debugger->setRunControlName(tr("Process %1").arg(pid.pid()));
debugger->setStartMode(AttachExternal);
debugger->setCloseMode(DetachAtClose);
debugger->setToolChainAbi(rc->abi());
debugger->startRunControl(); debugger->startRunControl();
} }

View File

@@ -256,6 +256,16 @@ void DebuggerRunTool::setUseCtrlCStub(bool on)
m_runParameters.useCtrlCStub = on; m_runParameters.useCtrlCStub = on;
} }
void DebuggerRunTool::setBreakOnMain(bool on)
{
m_runParameters.breakOnMain = on;
}
void DebuggerRunTool::setUseTerminal(bool on)
{
m_runParameters.useTerminal = on;
}
void DebuggerRunTool::setCommandsAfterConnect(const QString &commands) void DebuggerRunTool::setCommandsAfterConnect(const QString &commands)
{ {
m_runParameters.commandsAfterConnect = commands; m_runParameters.commandsAfterConnect = commands;
@@ -266,6 +276,16 @@ void DebuggerRunTool::setCommandsForReset(const QString &commands)
m_runParameters.commandsForReset = commands; m_runParameters.commandsForReset = commands;
} }
void DebuggerRunTool::setServerStartScript(const QString &serverStartScript)
{
m_runParameters.serverStartScript = serverStartScript;
}
void DebuggerRunTool::setDebugInfoLocation(const QString &debugInfoLocation)
{
m_runParameters.debugInfoLocation = debugInfoLocation;
}
void DebuggerRunTool::setQmlServer(const QUrl &qmlServer) void DebuggerRunTool::setQmlServer(const QUrl &qmlServer)
{ {
m_runParameters.qmlServer = qmlServer; m_runParameters.qmlServer = qmlServer;
@@ -291,6 +311,16 @@ void DebuggerRunTool::setTestCase(int testCase)
m_runParameters.testCase = testCase; m_runParameters.testCase = testCase;
} }
void DebuggerRunTool::setOverrideStartScript(const QString &script)
{
m_runParameters.overrideStartScript = script;
}
void DebuggerRunTool::setToolChainAbi(const Abi &abi)
{
m_runParameters.toolChainAbi = abi;
}
void DebuggerRunTool::setInferior(const Runnable &runnable) void DebuggerRunTool::setInferior(const Runnable &runnable)
{ {
QTC_ASSERT(runnable.is<StandardRunnable>(), reportFailure(); return); QTC_ASSERT(runnable.is<StandardRunnable>(), reportFailure(); return);

View File

@@ -109,10 +109,15 @@ public:
void setContinueAfterAttach(bool on); void setContinueAfterAttach(bool on);
void setSkipExecutableValidation(bool on); void setSkipExecutableValidation(bool on);
void setUseCtrlCStub(bool on); void setUseCtrlCStub(bool on);
void setBreakOnMain(bool on);
void setUseTerminal(bool on);
void setCommandsAfterConnect(const QString &commands); void setCommandsAfterConnect(const QString &commands);
void setCommandsForReset(const QString &commands); void setCommandsForReset(const QString &commands);
void setServerStartScript(const QString &serverStartScript);
void setDebugInfoLocation(const QString &debugInfoLocation);
void setQmlServer(const QUrl &qmlServer); void setQmlServer(const QUrl &qmlServer);
void setCoreFileName(const QString &core, bool isSnapshot = false); void setCoreFileName(const QString &core, bool isSnapshot = false);
@@ -122,6 +127,8 @@ public:
void setNeedFixup(bool on); void setNeedFixup(bool on);
void setTestCase(int testCase); void setTestCase(int testCase);
void setOverrideStartScript(const QString &script);
void setToolChainAbi(const ProjectExplorer::Abi &abi);
signals: signals:
void aboutToNotifyInferiorSetupOk(); void aboutToNotifyInferiorSetupOk();