forked from qt-creator/qt-creator
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:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user