Debugger: Consolidate "Attach to running process"

Change-Id: I78e89a662140f37f5f9719dbbbff070f1e2fbe84
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-10-19 08:29:20 +02:00
parent 6a470f0a70
commit 3d11a27ad0
10 changed files with 139 additions and 372 deletions

View File

@@ -61,7 +61,6 @@
#include "snapshothandler.h"
#include "threadshandler.h"
#include "commonoptionspage.h"
#include "gdb/startgdbserverdialog.h"
#include "analyzer/analyzerconstants.h"
#include "analyzer/analyzermanager.h"
@@ -735,7 +734,6 @@ public:
void updateDebugWithoutDeployMenu();
void startRemoteCdbSession();
void startRemoteServerAndAttachToProcess();
void attachToRunningApplication();
void attachToUnstartedApplicationDialog();
void attachToQmlPort();
@@ -981,7 +979,6 @@ public:
QAction *m_startAction = 0;
QAction *m_debugWithoutDeployAction = 0;
QAction *m_startAndDebugApplicationAction = 0;
QAction *m_startRemoteServerAction = 0;
QAction *m_attachToRunningApplication = 0;
QAction *m_attachToUnstartedApplication = 0;
QAction *m_attachToQmlPortAction = 0;
@@ -1507,10 +1504,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
act->setText(tr("Attach to Running Debug Server..."));
connect(act, &QAction::triggered, this, &StartApplicationDialog::attachToRemoteServer);
act = m_startRemoteServerAction = new QAction(this);
act->setText(tr("Start Debug Server Attached to Process..."));
connect(act, &QAction::triggered, this, &DebuggerPluginPrivate::startRemoteServerAndAttachToProcess);
act = m_attachToRunningApplication = new QAction(this);
act->setText(tr("Attach to Running Application..."));
connect(act, &QAction::triggered, this, &DebuggerPluginPrivate::attachToRunningApplication);
@@ -1584,11 +1577,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, Constants::G_SPECIAL);
cmd = ActionManager::registerAction(m_startRemoteServerAction,
"Debugger.StartRemoteServer");
cmd->setDescription(tr("Start Gdbserver"));
mstart->addAction(cmd, Constants::G_SPECIAL);
if (m_startRemoteCdbAction) {
cmd = ActionManager::registerAction(m_startRemoteCdbAction,
"Debugger.AttachRemoteCdb");
@@ -1992,30 +1980,48 @@ void DebuggerPluginPrivate::startRemoteCdbSession()
debugger->startRunControl();
}
void DebuggerPluginPrivate::startRemoteServerAndAttachToProcess()
class RemoteAttachRunner : public DebuggerRunTool
{
auto kitChooser = new DebuggerKitChooser(DebuggerKitChooser::AnyDebugging);
auto dlg = new DeviceProcessesDialog(kitChooser, ICore::dialogParent());
dlg->addAcceptButton(DeviceProcessesDialog::tr("&Attach to Process"));
dlg->showAllDevices();
if (dlg->exec() == QDialog::Rejected) {
delete dlg;
return;
public:
RemoteAttachRunner(RunControl *runControl, Kit *kit, int pid)
: DebuggerRunTool(runControl, kit)
{
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
setDisplayName("AttachToRunningProcess");
portsGatherer = new GdbServerPortsGatherer(runControl);
portsGatherer->setUseGdbServer(true);
portsGatherer->setUseQmlServer(false);
portsGatherer->setDevice(device);
auto gdbServer = new GdbServerRunner(runControl, portsGatherer);
gdbServer->setUseMulti(false);
gdbServer->addStartDependency(portsGatherer);
gdbServer->setDevice(device);
gdbServer->setAttachPid(ProcessHandle(pid));
addStartDependency(gdbServer);
setStartMode(AttachToRemoteProcess);
setCloseMode(DetachAtClose);
// setInferiorExecutable(localExecutable);
setUseContinueInsteadOfRun(true);
setContinueAfterAttach(false);
}
dlg->setAttribute(Qt::WA_DeleteOnClose);
Kit *kit = kitChooser->currentKit();
QTC_ASSERT(kit, return);
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
QTC_ASSERT(device, return);
void start() final
{
setRemoteChannel(portsGatherer->gdbServerChannel());
DebuggerRunTool::start();
}
GdbServerStarter *starter = new GdbServerStarter(dlg, true);
starter->run();
}
GdbServerPortsGatherer *portsGatherer;
};
void DebuggerPluginPrivate::attachToRunningApplication()
{
auto kitChooser = new DebuggerKitChooser(DebuggerKitChooser::LocalDebugging);
auto kitChooser = new DebuggerKitChooser(DebuggerKitChooser::AnyDebugging);
auto dlg = new DeviceProcessesDialog(kitChooser, ICore::dialogParent());
dlg->addAcceptButton(DeviceProcessesDialog::tr("&Attach to Process"));
@@ -2031,11 +2037,14 @@ void DebuggerPluginPrivate::attachToRunningApplication()
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
QTC_ASSERT(device, return);
DeviceProcessItem process = dlg->currentProcess();
if (device->type() == PE::DESKTOP_DEVICE_TYPE) {
attachToRunningProcess(kit, dlg->currentProcess(), false);
attachToRunningProcess(kit, process, false);
} else {
GdbServerStarter *starter = new GdbServerStarter(dlg, true);
starter->run();
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new RemoteAttachRunner(runControl, kit, process.pid);
debugger->startRunControl();
}
}