debugger/remotelinux: new dialog to attach to remote process

Change-Id: I221534561f4bbd299d494ecc902092e2e709770c
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
hjk
2011-12-06 15:39:25 +01:00
committed by hjk
parent 676739a87a
commit 9739b8df62
10 changed files with 313 additions and 299 deletions
+103 -39
View File
@@ -364,6 +364,7 @@ using namespace Core;
using namespace Debugger::Constants;
using namespace ProjectExplorer;
using namespace TextEditor;
using namespace ExtensionSystem;
namespace CC = Core::Constants;
namespace PE = ProjectExplorer::Constants;
@@ -730,10 +731,11 @@ public slots:
void debugProjectBreakMain();
void startExternalApplication();
void startRemoteCdbSession();
void startRemoteApplication();
void startRemoteProcess();
void startRemoteServer();
bool queryRemoteParameters(DebuggerStartParameters &sp, bool useScript);
void attachToRemoteServer();
//void attachToRemoteProcess();
void attachToRemoteProcess();
void attachToQmlPort();
void startRemoteEngine();
void attachExternalApplication();
@@ -1024,6 +1026,8 @@ public slots:
// FIXME: Remove.
void maybeEnrichParameters(DebuggerStartParameters *sp);
void gdbServerStarted(const QString &channel, const QString &sysroot, const QString &localExecutable);
public:
DebuggerMainWindow *m_mainWindow;
DebuggerRunControlFactory *m_debuggerRunControlFactory;
@@ -1037,9 +1041,10 @@ public:
QAction *m_debugWithoutDeployAction;
QAction *m_startExternalProcessAction;
QAction *m_startRemoteProcessAction;
QAction *m_startRemoteServerAction;
QAction *m_attachToRemoteProcessAction;
QAction *m_attachToQmlPortAction;
QAction *m_attachToRemoteServerAction;
//QAction *m_attachToRemoteProcessAction;
QAction *m_startRemoteCdbAction;
QAction *m_startRemoteLldbAction;
QAction *m_attachExternalAction;
@@ -1510,7 +1515,7 @@ void DebuggerPluginPrivate::attachExternalApplication()
startDebugger(rc);
}
void DebuggerPluginPrivate::attachExternalApplication(ProjectExplorer::RunControl *rc)
void DebuggerPluginPrivate::attachExternalApplication(RunControl *rc)
{
DebuggerStartParameters sp;
sp.attachPID = rc->applicationProcessHandle().pid();
@@ -1571,11 +1576,8 @@ void DebuggerPluginPrivate::startRemoteCdbSession()
const QString connectionKey = _("CdbRemoteConnection");
DebuggerStartParameters sp;
Abi hostAbi = Abi::hostAbi();
sp.toolChainAbi = ProjectExplorer::Abi(hostAbi.architecture(),
ProjectExplorer::Abi::WindowsOS,
ProjectExplorer::Abi::WindowsMsvc2010Flavor,
ProjectExplorer::Abi::PEFormat,
hostAbi.wordWidth());
sp.toolChainAbi = Abi(hostAbi.architecture(), Abi::WindowsOS,
Abi::WindowsMsvc2010Flavor, Abi::PEFormat, hostAbi.wordWidth());
sp.startMode = AttachToRemoteServer;
StartRemoteCdbDialog dlg(mainWindow());
QString previousConnection = configValue(connectionKey).toString();
@@ -1644,7 +1646,7 @@ bool DebuggerPluginPrivate::queryRemoteParameters(DebuggerStartParameters &sp, b
sp.displayName = tr("Remote: \"%1\"").arg(sp.remoteChannel);
sp.debuggerCommand = dlg.debugger(); // Override toolchain-detection.
if (!sp.debuggerCommand.isEmpty())
sp.toolChainAbi = ProjectExplorer::Abi();
sp.toolChainAbi = Abi();
sp.overrideStartScript = dlg.overrideStartScript();
sp.useServerStartScript = dlg.useServerStartScript();
sp.serverStartScript = dlg.serverStartScript();
@@ -1653,7 +1655,7 @@ bool DebuggerPluginPrivate::queryRemoteParameters(DebuggerStartParameters &sp, b
return true;
}
void DebuggerPluginPrivate::startRemoteApplication()
void DebuggerPluginPrivate::startRemoteProcess()
{
DebuggerStartParameters sp;
sp.startMode = StartRemoteProcess;
@@ -1675,21 +1677,71 @@ void DebuggerPluginPrivate::attachToRemoteServer()
startDebugger(rc);
}
/*
void DebuggerPluginPrivate::attachToRemoteProcess()
{
startRemoteServer();
}
void DebuggerPluginPrivate::startRemoteServer()
{
PluginManager *pm = PluginManager::instance();
QTC_ASSERT(pm, return);
QObject *rl = pm->getObjectByName(_("RemoteLinuxPlugin"));
QTC_ASSERT(rl, return);
QMetaObject::invokeMethod(rl, "startGdbServer", Qt::QueuedConnection);
// Will call back gdbServerStarted() below.
}
void DebuggerPluginPrivate::gdbServerStarted(const QString &channel,
const QString &sysroot, const QString &remoteCommandLine)
{
QString binary = remoteCommandLine.section(QLatin1Char(' '), 0, 0);
QString localExecutable;
QString candidate = sysroot + QLatin1Char('/') + binary;
if (QFileInfo(candidate).exists())
localExecutable = candidate;
if (localExecutable.isEmpty()) {
candidate = sysroot + QLatin1String("/usr/bin/") + binary;
if (QFileInfo(candidate).exists())
localExecutable = candidate;
}
if (localExecutable.isEmpty()) {
candidate = sysroot + QLatin1String("/bin/") + binary;
if (QFileInfo(candidate).exists())
localExecutable = candidate;
}
if (localExecutable.isEmpty()) {
QMessageBox::warning(mainWindow(), tr("Warning"),
tr("Cannot find local executable for remote process \"%1\".")
.arg(remoteCommandLine));
return;
}
QList<Abi> abis = Abi::abisOfBinary(localExecutable);
if (abis.isEmpty()) {
QMessageBox::warning(mainWindow(), tr("Warning"),
tr("Cannot find abi for remote process \"%1\".")
.arg(remoteCommandLine));
return;
}
DebuggerStartParameters sp;
if (!queryRemoteParameters(sp, false))
return;
sp.startMode = AttachToRemoteProcess;
sp.toolChainAbi = abis.at(0);
//sp.remoteArchitecture = abis.at(0).toString();
sp.displayName = tr("Remote: \"%1\"").arg(channel);
sp.remoteChannel = channel;
sp.sysroot = sysroot;
sp.executable = localExecutable;
sp.startMode = AttachToRemoteServer;
sp.useServerStartScript = false;
sp.serverStartScript.clear();
sp.overrideStartScript.clear();
sp.useServerStartScript = false;
sp.serverStartScript.clear();
//sp.debugInfoLocation = dlg.debugInfoLocation();
if (RunControl *rc = createDebugger(sp))
startDebugger(rc);
}
*/
void DebuggerPluginPrivate::attachToQmlPort()
{
@@ -1730,11 +1782,11 @@ void DebuggerPluginPrivate::attachToQmlPort()
//
// get files from all the projects in the session
//
ProjectExplorer::SessionManager *sessionManager = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
SessionManager *sessionManager = ProjectExplorerPlugin::instance()->session();
QList<Project *> projects = sessionManager->projects();
if (Project *startupProject = ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject()) {
if (Project *startupProject = ProjectExplorerPlugin::instance()->startupProject()) {
// startup project first
projects.removeOne(ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject());
projects.removeOne(ProjectExplorerPlugin::instance()->startupProject());
projects.insert(0, startupProject);
}
QStringList sourceFiles;
@@ -2260,7 +2312,7 @@ void DebuggerPluginPrivate::updateState(DebuggerEngine *engine)
m_attachToCoreAction->setEnabled(true);
m_startRemoteProcessAction->setEnabled(true);
m_attachToRemoteServerAction->setEnabled(true);
//m_attachToRemoteProcessAction->setEnabled(true);
m_attachToRemoteProcessAction->setEnabled(true);
const bool isCore = engine->startParameters().startMode == AttachCore;
const bool stopped = state == InferiorStopOk;
@@ -2728,7 +2780,7 @@ QString DebuggerPluginPrivate::debuggerForAbi(const Abi &abi, DebuggerEngineType
searchAbis.push_back(abi);
// Pick the right tool chain in case cdb/gdb were started with other tool chains.
// Also, lldb should be preferred over gdb.
if (abi.os() == ProjectExplorer::Abi::WindowsOS) {
if (abi.os() == Abi::WindowsOS) {
switch (et) {
case CdbEngineType:
searchAbis.clear();
@@ -2800,7 +2852,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
connect(core, SIGNAL(coreAboutToClose()), this, SLOT(coreShutdown()));
Core::ActionManager *am = core->actionManager();
ActionManager *am = core->actionManager();
QTC_ASSERT(am, return);
m_plugin->addObject(this);
@@ -2972,7 +3024,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
m_mainWindow->createDockWidget(CppLanguage, m_threadsWindow);
m_mainWindow->createDockWidget(QmlLanguage, m_scriptConsoleWindow);
QSplitter *localsAndWatchers = new Core::MiniSplitter(Qt::Vertical);
QSplitter *localsAndWatchers = new MiniSplitter(Qt::Vertical);
localsAndWatchers->setObjectName(DOCKWIDGET_WATCHERS);
localsAndWatchers->setWindowTitle(m_localsWindow->windowTitle());
localsAndWatchers->addWidget(m_localsWindow);
@@ -3034,15 +3086,19 @@ void DebuggerPluginPrivate::extensionsInitialized()
act = m_startRemoteProcessAction = new QAction(this);
act->setText(tr("Start and Debug Remote Application..."));
connect(act, SIGNAL(triggered()), SLOT(startRemoteApplication()));
connect(act, SIGNAL(triggered()), SLOT(startRemoteProcess()));
act = m_attachToRemoteServerAction = new QAction(this);
act->setText(tr("Attach to Remote Debug Server..."));
connect(act, SIGNAL(triggered()), SLOT(attachToRemoteServer()));
//act = m_attachToRemoteProcessAction = new QAction(this);
//act->setText(tr("Attach to Running Remote Process..."));
//connect(act, SIGNAL(triggered()), SLOT(attachToRemoteProcess()));
act = m_startRemoteServerAction = new QAction(this);
act->setText(tr("Start Remote Debug Server..."));
connect(act, SIGNAL(triggered()), SLOT(startRemoteServer()));
act = m_attachToRemoteProcessAction = new QAction(this);
act->setText(tr("Attach to Running Remote Process..."));
connect(act, SIGNAL(triggered()), SLOT(attachToRemoteProcess()));
act = m_attachToQmlPortAction = new QAction(this);
act->setText(tr("Attach to QML Port..."));
@@ -3108,16 +3164,20 @@ void DebuggerPluginPrivate::extensionsInitialized()
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, Constants::G_MANUAL_REMOTE);
//cmd = am->registerAction(m_attachToRemoteProcessAction,
// "Debugger.AttachToRemoteProcess", globalcontext);
//cmd->setAttribute(Command::CA_Hide);
//mstart->addAction(cmd, Constants::G_AUTOMATIC_REMOTE);
cmd = am->registerAction(m_startRemoteProcessAction,
"Debugger.StartRemoteProcess", globalcontext);
cmd->setAttribute(Command::CA_Hide);
mstart->addAction(cmd, Constants::G_AUTOMATIC_REMOTE);
cmd = am->registerAction(m_startRemoteServerAction,
"Debugger.StartRemoteServer", globalcontext);
cmd->setDefaultText(tr("Start Gdbserver"));
mstart->addAction(cmd, Debugger::Constants::G_MANUAL_REMOTE);
cmd = am->registerAction(m_attachToRemoteProcessAction,
"Debugger.AttachToRemoteProcess", globalcontext);
cmd->setDefaultText(tr("Attach to Remote Process"));
mstart->addAction(cmd, Debugger::Constants::G_AUTOMATIC_REMOTE);
#ifdef WITH_LLDB
cmd = am->registerAction(m_startRemoteLldbAction,
@@ -3292,7 +3352,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
// Debugger.AddToWatch is enough.
}
QList<Core::IOptionsPage *> engineOptionPages;
QList<IOptionsPage *> engineOptionPages;
if (m_cmdLineEnabledEngines & GdbEngineType)
addGdbOptionPages(&engineOptionPages);
addCdbOptionPages(&engineOptionPages);
@@ -3305,7 +3365,8 @@ void DebuggerPluginPrivate::extensionsInitialized()
// addScriptOptionPages(&engineOptionPages);
//if (m_cmdLineEnabledEngines & TcfEngineType)
// addTcfOptionPages(&engineOptionPages);
foreach (Core::IOptionsPage *op, engineOptionPages)
foreach (IOptionsPage *op, engineOptionPages)
m_plugin->addAutoReleasedObject(op);
m_plugin->addAutoReleasedObject(new DebuggingHelperOptionPage);
@@ -3313,7 +3374,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
SLOT(onModeChanged(Core::IMode*)));
connect(ICore::instance(), SIGNAL(coreAboutToOpen()),
SLOT(onCoreAboutToOpen()));
connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
connect(ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
this, SLOT(updateDebugWithoutDeployMenu()));
// Debug mode setup
@@ -3399,6 +3460,9 @@ void DebuggerPluginPrivate::extensionsInitialized()
SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
SLOT(onCurrentProjectChanged(ProjectExplorer::Project*)));
m_commonOptionsPage = new CommonOptionsPage(m_globalDebuggerOptions);
m_plugin->addAutoReleasedObject(m_commonOptionsPage);
QTC_CHECK(m_coreSettings);
m_globalDebuggerOptions->fromSettings(m_coreSettings);
m_watchersWindow->setVisible(false);
@@ -3494,12 +3558,12 @@ DebuggerPlugin::~DebuggerPlugin()
bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
ICore *core = ICore::instance();
QTC_ASSERT(core, return true);
QTC_ASSERT(core, return false);
// Menu groups
const Context globalcontext(CC::C_GLOBAL);
Core::ActionManager *am = core->actionManager();
ActionManager *am = core->actionManager();
ActionContainer *mstart = am->actionContainer(PE::M_DEBUG_STARTDEBUGGING);
mstart->appendGroup(Constants::G_START_LOCAL);
@@ -3526,7 +3590,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
return theDebuggerCore->initialize(arguments, errorMessage);
}
ExtensionSystem::IPlugin::ShutdownFlag DebuggerPlugin::aboutToShutdown()
IPlugin::ShutdownFlag DebuggerPlugin::aboutToShutdown()
{
theDebuggerCore->aboutToShutdown();
return SynchronousShutdown;
+3 -1
View File
@@ -512,7 +512,9 @@ static QList<DebuggerEngineType> engineTypes(const DebuggerStartParameters &sp)
return result;
}
if (sp.startMode != AttachToRemoteServer && !sp.executable.isEmpty())
if (sp.startMode != AttachToRemoteServer
&& sp.startMode != AttachToRemoteProcess
&& !sp.executable.isEmpty())
result = enginesForExecutable(sp.executable);
if (!result.isEmpty())
return result;
@@ -213,6 +213,7 @@ SshConnectionParameters LinuxDeviceConfiguration::sshParameters() const
}
LinuxDeviceConfiguration::DeviceType LinuxDeviceConfiguration::deviceType() const
{
return d->deviceType;
}
+1 -2
View File
@@ -127,8 +127,7 @@ FORMS += \
linuxdeviceconfigurationssettingswidget.ui \
sshkeycreationdialog.ui \
remotelinuxdeployconfigurationwidget.ui \
profilesupdatedialog.ui \
startgdbserverdialog.ui
profilesupdatedialog.ui
RESOURCES += remotelinux.qrc
@@ -62,6 +62,7 @@ namespace Internal {
RemoteLinuxPlugin::RemoteLinuxPlugin()
{
setObjectName(QLatin1String("RemoteLinuxPlugin"));
}
bool RemoteLinuxPlugin::initialize(const QStringList &arguments,
@@ -72,6 +73,7 @@ bool RemoteLinuxPlugin::initialize(const QStringList &arguments,
LinuxDeviceConfigurations::instance(this);
addObject(this);
addAutoReleasedObject(new LinuxDeviceConfigurationsSettingsPage);
addAutoReleasedObject(new GenericLinuxDeviceConfigurationFactory);
addAutoReleasedObject(new RemoteLinuxRunConfigurationFactory);
@@ -89,6 +91,7 @@ bool RemoteLinuxPlugin::initialize(const QStringList &arguments,
void RemoteLinuxPlugin::extensionsInitialized()
{
/*
using namespace Core;
ICore *core = ICore::instance();
ActionManager *am = core->actionManager();
@@ -111,6 +114,7 @@ void RemoteLinuxPlugin::extensionsInitialized()
cmd->setDefaultText(tr("Attach to Remote Process"));
mstart->addAction(cmd, Debugger::Constants::G_AUTOMATIC_REMOTE);
connect(act, SIGNAL(triggered()), SLOT(startGdbServer()));
*/
}
void RemoteLinuxPlugin::startGdbServer()
@@ -110,6 +110,11 @@ int AbstractRemoteLinuxProcessList::pidAt(int row) const
return d->remoteProcesses.at(row).pid;
}
QString AbstractRemoteLinuxProcessList::commandLineAt(int row) const
{
return d->remoteProcesses.at(row).cmdLine;
}
int AbstractRemoteLinuxProcessList::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : d->remoteProcesses.count();
@@ -54,6 +54,7 @@ public:
void update();
void killProcess(int row);
int pidAt(int row) const;
QString commandLineAt(int row) const;
signals:
void error(const QString &errorMsg);
+190 -68
View File
@@ -31,7 +31,6 @@
**************************************************************************/
#include "startgdbserverdialog.h"
#include "ui_startgdbserverdialog.h"
#include "remotelinuxprocesslist.h"
#include "linuxdeviceconfiguration.h"
@@ -39,15 +38,44 @@
#include "remotelinuxusedportsgatherer.h"
#include "portlist.h"
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <utils/ssh/sshconnection.h>
#include <utils/ssh/sshremoteprocessrunner.h>
#include <utils/qtcassert.h>
#include <QtGui/QMessageBox>
#include <QtGui/QSortFilterProxyModel>
#include <QtCore/QVariant>
#include <QtCore/QSettings>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QComboBox>
#include <QtGui/QDialog>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QFormLayout>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <QtGui/QSortFilterProxyModel>
#include <QtGui/QSpacerItem>
#include <QtGui/QTableView>
#include <QtGui/QTextBrowser>
#include <QtGui/QVBoxLayout>
using namespace Core;
using namespace Utils;
const char LastSysroot[] = "RemoteLinux/LastSysroot";
const char LastDevice[] = "RemoteLinux/LastDevice";
const char LastProcessName[] = "RemoteLinux/LastProcessName";
//const char LastLocalExecutable[] = "RemoteLinux/LastLocalExecutable";
namespace RemoteLinux {
namespace Internal {
@@ -55,54 +83,126 @@ namespace Internal {
class StartGdbServerDialogPrivate
{
public:
StartGdbServerDialogPrivate() : processList(0) {}
StartGdbServerDialogPrivate(StartGdbServerDialog *q);
LinuxDeviceConfiguration::ConstPtr currentDevice() const
{
LinuxDeviceConfigurations *devices = LinuxDeviceConfigurations::instance();
return devices->deviceAt(ui.deviceComboBox->currentIndex());
return devices->deviceAt(deviceComboBox->currentIndex());
}
StartGdbServerDialog *q;
AbstractRemoteLinuxProcessList *processList;
QSortFilterProxyModel proxyModel;
Ui::StartGdbServerDialog ui;
QComboBox *deviceComboBox;
QLineEdit *processFilterLineEdit;
QTableView *tableView;
QPushButton *attachProcessButton;
QTextBrowser *textBrowser;
QPushButton *closeButton;
PathChooser *sysrootPathChooser;
RemoteLinuxUsedPortsGatherer gatherer;
Utils::SshRemoteProcessRunner runner;
SshRemoteProcessRunner runner;
QSettings *settings;
QString remoteCommandLine;
};
StartGdbServerDialogPrivate::StartGdbServerDialogPrivate(StartGdbServerDialog *q)
: q(q), processList(0)
{
settings = ICore::instance()->settings();
deviceComboBox = new QComboBox(q);
sysrootPathChooser = new PathChooser(q);
sysrootPathChooser->setExpectedKind(PathChooser::Directory);
sysrootPathChooser->setPromptDialogTitle(StartGdbServerDialog::tr("Select Sysroot"));
sysrootPathChooser->setPath(settings->value(LastSysroot).toString());
//executablePathChooser = new PathChooser(q);
//executablePathChooser->setExpectedKind(PathChooser::File);
//executablePathChooser->setPromptDialogTitle(StartGdbServerDialog::tr("Select Executable"));
//executablePathChooser->setPath(settings->value(LastLocalExecutable).toString());
processFilterLineEdit = new QLineEdit(q);
processFilterLineEdit->setText(settings->value(LastProcessName).toString());
processFilterLineEdit->selectAll();
tableView = new QTableView(q);
tableView->setShowGrid(false);
tableView->setSortingEnabled(true);
tableView->horizontalHeader()->setDefaultSectionSize(100);
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->verticalHeader()->setVisible(false);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
attachProcessButton = new QPushButton(q);
attachProcessButton->setText(StartGdbServerDialog::tr("&Attach to Selected Process"));
closeButton = new QPushButton(q);
closeButton->setText(StartGdbServerDialog::tr("Close"));
textBrowser = new QTextBrowser(q);
textBrowser->setEnabled(false);
QFormLayout *formLayout = new QFormLayout();
formLayout->addRow(StartGdbServerDialog::tr("Device:"), deviceComboBox);
formLayout->addRow(StartGdbServerDialog::tr("Sysroot:"), sysrootPathChooser);
formLayout->addRow(StartGdbServerDialog::tr("&Filter by process name:"),
processFilterLineEdit);
QHBoxLayout *horizontalLayout2 = new QHBoxLayout();
horizontalLayout2->addStretch(1);
horizontalLayout2->addWidget(attachProcessButton);
horizontalLayout2->addWidget(closeButton);
formLayout->addRow(tableView);
formLayout->addRow(textBrowser);
formLayout->addRow(horizontalLayout2);
q->setLayout(formLayout);
}
} // namespace Internal
StartGdbServerDialog::StartGdbServerDialog(QWidget *parent) :
QDialog(parent),
d(new Internal::StartGdbServerDialogPrivate)
d(new Internal::StartGdbServerDialogPrivate(this))
{
setWindowTitle(tr("List of Remote Processes"));
LinuxDeviceConfigurations *devices = LinuxDeviceConfigurations::instance();
d->ui.setupUi(this);
d->ui.deviceComboBox->setModel(devices);
QObject::connect(d->closeButton, SIGNAL(clicked()), this, SLOT(reject()));
d->deviceComboBox->setModel(devices);
d->deviceComboBox->setCurrentIndex(d->settings->value(LastDevice).toInt());
connect(&d->gatherer, SIGNAL(error(QString)), SLOT(portGathererError(QString)));
connect(&d->gatherer, SIGNAL(portListReady()), SLOT(portListReady()));
if (devices->rowCount() == 0) {
d->ui.tableView->setEnabled(false);
d->tableView->setEnabled(false);
} else {
d->ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
d->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
d->proxyModel.setDynamicSortFilter(true);
d->proxyModel.setFilterKeyColumn(1);
d->ui.tableView->setModel(&d->proxyModel);
connect(d->ui.processFilterLineEdit, SIGNAL(textChanged(QString)),
d->tableView->setModel(&d->proxyModel);
connect(d->processFilterLineEdit, SIGNAL(textChanged(QString)),
&d->proxyModel, SLOT(setFilterRegExp(QString)));
connect(d->ui.tableView->selectionModel(),
connect(d->tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(handleSelectionChanged()));
connect(d->ui.updateListButton, SIGNAL(clicked()),
SLOT(updateProcessList()));
connect(d->ui.attachProcessButton, SIGNAL(clicked()), SLOT(attachToProcess()));
SLOT(updateButtons()));
//connect(d->updateListButton, SIGNAL(clicked()),
// SLOT(updateProcessList()));
connect(d->attachProcessButton, SIGNAL(clicked()), SLOT(attachToProcess()));
connect(&d->proxyModel, SIGNAL(layoutChanged()),
SLOT(handleProcessListUpdated()));
connect(d->ui.deviceComboBox, SIGNAL(currentIndexChanged(int)),
connect(d->deviceComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(attachToDevice(int)));
handleSelectionChanged();
attachToDevice(0);
updateButtons();
attachToDevice(d->deviceComboBox->currentIndex());
}
}
@@ -112,7 +212,6 @@ StartGdbServerDialog::~StartGdbServerDialog()
delete d;
}
void StartGdbServerDialog::attachToDevice(int index)
{
LinuxDeviceConfigurations *devices = LinuxDeviceConfigurations::instance();
@@ -131,46 +230,60 @@ void StartGdbServerDialog::attachToDevice(int index)
void StartGdbServerDialog::handleRemoteError(const QString &errorMsg)
{
QMessageBox::critical(this, tr("Remote Error"), errorMsg);
d->ui.updateListButton->setEnabled(true);
handleSelectionChanged();
updateButtons();
}
void StartGdbServerDialog::handleProcessListUpdated()
{
d->ui.updateListButton->setEnabled(true);
d->ui.tableView->resizeRowsToContents();
handleSelectionChanged();
d->tableView->resizeRowsToContents();
updateButtons();
}
void StartGdbServerDialog::updateProcessList()
{
d->ui.updateListButton->setEnabled(false);
d->ui.attachProcessButton->setEnabled(false);
d->attachProcessButton->setEnabled(false);
d->processList->update();
d->proxyModel.setFilterRegExp(QString());
d->proxyModel.setFilterRegExp(d->processFilterLineEdit->text());
updateButtons();
}
void StartGdbServerDialog::attachToProcess()
{
const QModelIndexList &indexes =
d->ui.tableView->selectionModel()->selectedIndexes();
d->tableView->selectionModel()->selectedIndexes();
if (indexes.empty())
return;
d->ui.updateListButton->setEnabled(false);
d->ui.attachProcessButton->setEnabled(false);
d->attachProcessButton->setEnabled(false);
LinuxDeviceConfiguration::ConstPtr device = d->currentDevice();
PortList ports = device->freePorts();
const int port = d->gatherer.getNextFreePort(&ports);
const int row = d->proxyModel.mapToSource(indexes.first()).row();
QTC_ASSERT(row >= 0, processAborted(); return);
QTC_ASSERT(row >= 0, return);
const int pid = d->processList->pidAt(row);
d->remoteCommandLine = d->processList->commandLineAt(row);
if (port == -1) {
emit processAborted();
} else {
emit pidSelected(pid);
emit portSelected(pid);
startGdbServerOnPort(port, pid);
reportFailure();
return;
}
d->settings->setValue(LastSysroot, d->sysrootPathChooser->path());
d->settings->setValue(LastDevice, d->deviceComboBox->currentIndex());
d->settings->setValue(LastProcessName, d->processFilterLineEdit->text());
startGdbServerOnPort(port, pid);
}
void StartGdbServerDialog::reportFailure()
{
QTC_ASSERT(false, /**/);
logMessage(tr("Process aborted"));
}
void StartGdbServerDialog::logMessage(const QString &line)
{
d->textBrowser->append(line);
}
void StartGdbServerDialog::handleProcessKilled()
@@ -178,76 +291,84 @@ void StartGdbServerDialog::handleProcessKilled()
updateProcessList();
}
void StartGdbServerDialog::handleSelectionChanged()
void StartGdbServerDialog::updateButtons()
{
d->ui.attachProcessButton->setEnabled(d->ui.tableView->selectionModel()->hasSelection());
d->attachProcessButton->setEnabled(d->tableView->selectionModel()->hasSelection()
|| d->proxyModel.rowCount() == 1);
}
void StartGdbServerDialog::portGathererError(const QString &text)
{
d->ui.textBrowser->append(tr("Could not retrieve list of free ports:"));
d->ui.textBrowser->append(text);
emit processAborted();
logMessage(tr("Could not retrieve list of free ports:"));
logMessage(text);
reportFailure();
}
void StartGdbServerDialog::portListReady()
{
d->ui.updateListButton->setEnabled(true);
d->ui.attachProcessButton->setEnabled(true);
updateButtons();
}
void StartGdbServerDialog::startGdbServer()
{
LinuxDeviceConfiguration::ConstPtr device = d->currentDevice();
d->gatherer.start(Utils::SshConnection::create(device->sshParameters()), device);
d->gatherer.start(SshConnection::create(device->sshParameters()), device);
}
void StartGdbServerDialog::attachToRemoteProcess()
{
LinuxDeviceConfiguration::ConstPtr device = d->currentDevice();
d->gatherer.start(Utils::SshConnection::create(device->sshParameters()), device);
startGdbServer();
}
void StartGdbServerDialog::handleConnectionError()
{
d->ui.textBrowser->append(tr("Connection error: %1")
.arg(d->runner.lastConnectionErrorString()));
logMessage(tr("Connection error: %1").arg(d->runner.lastConnectionErrorString()));
emit processAborted();
}
void StartGdbServerDialog::handleProcessStarted()
{
d->ui.textBrowser->append(tr("Starting gdbserver..."));
logMessage(tr("Starting gdbserver..."));
}
void StartGdbServerDialog::handleProcessOutputAvailable(const QByteArray &ba)
{
d->ui.textBrowser->append(QString::fromUtf8(ba.trimmed()));
logMessage(QString::fromUtf8(ba.trimmed()));
}
void StartGdbServerDialog::handleProcessErrorOutput(const QByteArray &ba)
{
d->ui.textBrowser->append(QString::fromUtf8(ba.trimmed()));
logMessage(QString::fromUtf8(ba.trimmed()));
// "Attached; pid = 16740"
// "Listening on port 10000"
int pos = ba.indexOf("Listening on port");
if (pos != -1) {
int port = ba.mid(pos + 18).trimmed().toInt();
d->ui.textBrowser->append(tr("Port %1 is now accessible.").arg(port));
emit portOpened(port);
ExtensionSystem::PluginManager *pm =
ExtensionSystem::PluginManager::instance();
QObject *ob = pm->getObjectByName("DebuggerCore");
qDebug() << "FOUND DEBUGGER CORE: " << ob;
if (ob)
QMetaObject::invokeMethod(ob, "gdbServerStarted", Qt::QueuedConnection,
Q_ARG(int, port));
}
if (pos == -1)
return;
const int port = ba.mid(pos + 18).trimmed().toInt();
logMessage(tr("Port %1 is now accessible.").arg(port));
reportOpenPort(port);
}
void StartGdbServerDialog::reportOpenPort(int port)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
QObject *ob = pm->getObjectByName("DebuggerCore");
if (!ob)
return;
LinuxDeviceConfiguration::ConstPtr device = d->currentDevice();
QString channel = QString("%1:%2").arg(device->sshParameters().host).arg(port);
logMessage(tr("Server started on %1").arg(channel));
QMetaObject::invokeMethod(ob, "gdbServerStarted", Qt::QueuedConnection,
Q_ARG(QString, channel),
Q_ARG(QString, d->sysrootPathChooser->path()),
Q_ARG(QString, d->remoteCommandLine));
}
void StartGdbServerDialog::handleProcessClosed(int status)
{
d->ui.textBrowser->append(tr("Process gdbserver finished. Status: %1").arg(status));
logMessage(tr("Process gdbserver finished. Status: %1").arg(status));
}
void StartGdbServerDialog::startGdbServerOnPort(int port, int pid)
@@ -263,6 +384,7 @@ void StartGdbServerDialog::startGdbServerOnPort(int port, int pid)
QByteArray cmd = "/usr/bin/gdbserver --attach localhost:"
+ QByteArray::number(port) + " " + QByteArray::number(pid);
logMessage(tr("Running command: %1").arg(QString::fromLatin1(cmd)));
d->runner.run(cmd, device->sshParameters());
}
@@ -39,9 +39,7 @@
namespace RemoteLinux {
namespace Internal {
class StartGdbServerDialogPrivate;
} // namespace Internal
namespace Internal { class StartGdbServerDialogPrivate; }
class REMOTELINUX_EXPORT StartGdbServerDialog : public QDialog
{
@@ -55,9 +53,6 @@ public:
void attachToRemoteProcess();
signals:
void pidSelected(int pid);
void portSelected(int port);
void portOpened(int port);
void processAborted();
private slots:
@@ -67,7 +62,7 @@ private slots:
void updateProcessList();
void attachToProcess();
void handleProcessKilled();
void handleSelectionChanged();
void updateButtons();
void portGathererError(const QString &errorMessage);
void portListReady();
@@ -79,6 +74,9 @@ private slots:
private:
void startGdbServerOnPort(int port, int pid);
void reportOpenPort(int port);
void reportFailure();
void logMessage(const QString &line);
Internal::StartGdbServerDialogPrivate *d;
};
@@ -1,182 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RemoteLinux::Internal::StartGdbServerDialog</class>
<widget class="QDialog" name="RemoteLinux::Internal::StartGdbServerDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>564</height>
</rect>
</property>
<property name="windowTitle">
<string>List of Remote Processes</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1,0,0,0">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Device:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="deviceComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="filterLabel">
<property name="text">
<string>&amp;Filter by process name:</string>
</property>
<property name="buddy">
<cstring>processFilterLineEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="processFilterLineEdit"/>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTableView" name="tableView">
<property name="showGrid">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>100</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="attachProcessButton">
<property name="text">
<string>&amp;Attach to Selected Process</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateListButton">
<property name="text">
<string>&amp;Update List</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>242</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RemoteLinux::Internal::StartGdbServerDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RemoteLinux::Internal::StartGdbServerDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>