Commit ee242781 authored by hjk's avatar hjk Committed by hjk

debugger/remote linux: add dialog to start gdbserver on the device

Change-Id: I57ddfa17a7c51a9347b0d81205c1679c6398d126
Reviewed-on: http://codereview.qt-project.org/5383Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 92c23296
......@@ -3016,6 +3016,11 @@ void DebuggerPluginPrivate::extensionsInitialized()
mstart->addAction(cmd, CC::G_DEFAULT_ONE);
}
QAction *sep = new QAction(this);
sep->setSeparator(true);
cmd = am->registerAction(sep, "Debugger.Sep.Start", globalcontext);
mstart->addAction(cmd);
cmd = am->registerAction(m_detachAction,
"Debugger.Detach", globalcontext);
cmd->setAttribute(Command::CA_Hide);
......@@ -3051,7 +3056,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
cmd->setDefaultText(tr("Reset Debugger"));
debugMenu->addAction(cmd, CC::G_DEFAULT_ONE);
QAction *sep = new QAction(this);
sep = new QAction(this);
sep->setSeparator(true);
cmd = am->registerAction(sep, "Debugger.Sep.Step", globalcontext);
debugMenu->addAction(cmd);
......
......@@ -54,7 +54,8 @@ HEADERS += \
remotelinuxutils.h \
deploymentsettingsassistant.h \
remotelinuxdeployconfigurationwidget.h \
profilesupdatedialog.h
profilesupdatedialog.h \
startgdbserverdialog.h
SOURCES += \
remotelinuxplugin.cpp \
......@@ -103,7 +104,8 @@ SOURCES += \
remotelinuxutils.cpp \
deploymentsettingsassistant.cpp \
remotelinuxdeployconfigurationwidget.cpp \
profilesupdatedialog.cpp
profilesupdatedialog.cpp \
startgdbserverdialog.cpp
FORMS += \
linuxdevicefactoryselectiondialog.ui \
......@@ -113,7 +115,8 @@ FORMS += \
linuxdeviceconfigurationssettingswidget.ui \
sshkeycreationdialog.ui \
remotelinuxdeployconfigurationwidget.ui \
profilesupdatedialog.ui
profilesupdatedialog.ui \
startgdbserverdialog.ui
DEFINES += QT_NO_CAST_TO_ASCII
DEFINES += REMOTELINUX_LIBRARY
......@@ -41,8 +41,17 @@
#include "remotelinuxrunconfigurationfactory.h"
#include "remotelinuxruncontrolfactory.h"
#include "remotelinuxsettingspages.h"
#include "startgdbserverdialog.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <QtCore/QtPlugin>
#include <QtGui/QAction>
namespace RemoteLinux {
namespace Internal {
......@@ -51,10 +60,6 @@ RemoteLinuxPlugin::RemoteLinuxPlugin()
{
}
RemoteLinuxPlugin::~RemoteLinuxPlugin()
{
}
bool RemoteLinuxPlugin::initialize(const QStringList &arguments,
QString *errorMessage)
{
......@@ -77,6 +82,28 @@ bool RemoteLinuxPlugin::initialize(const QStringList &arguments,
void RemoteLinuxPlugin::extensionsInitialized()
{
using namespace Core;
ICore *core = ICore::instance();
ActionManager *am = core->actionManager();
ActionContainer *mstart = am->actionContainer(ProjectExplorer::Constants::M_DEBUG_STARTDEBUGGING);
const Context globalcontext(Core::Constants::C_GLOBAL);
QAction *startGdbServerAction = new QAction(tr("Start Remote Debug Server"), 0);
Command *cmd = am->registerAction(startGdbServerAction, "StartGdbServer", globalcontext);
cmd->setDefaultText(tr("Start Gdbserver"));
mstart->addAction(cmd, Constants::G_DEFAULT_TWO);
connect(startGdbServerAction, SIGNAL(triggered()), SLOT(startGdbServer()));
}
void RemoteLinuxPlugin::startGdbServer()
{
StartGdbServerDialog dlg;
int result = dlg.exec();
if (result == QDialog::Rejected)
return;
dlg.startGdbServer();
}
} // namespace Internal
......
......@@ -41,12 +41,15 @@ namespace Internal {
class RemoteLinuxPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
RemoteLinuxPlugin();
~RemoteLinuxPlugin();
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();
private slots:
void startGdbServer();
};
} // namespace Internal
......
......@@ -105,6 +105,11 @@ void AbstractRemoteLinuxProcessList::killProcess(int row)
startProcess(killProcessCommandLine(d->remoteProcesses.at(row)));
}
int AbstractRemoteLinuxProcessList::pidAt(int row) const
{
return d->remoteProcesses.at(row).pid;
}
int AbstractRemoteLinuxProcessList::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : d->remoteProcesses.count();
......
......@@ -53,6 +53,7 @@ public:
void update();
void killProcess(int row);
int pidAt(int row) const;
signals:
void error(const QString &errorMsg);
......
#include "startgdbserverdialog.h"
#include "ui_startgdbserverdialog.h"
#include "remotelinuxprocesslist.h"
#include "linuxdeviceconfiguration.h"
#include "linuxdeviceconfigurations.h"
#include "remotelinuxusedportsgatherer.h"
#include "portlist.h"
#include <utils/ssh/sshconnection.h>
#include <utils/ssh/sshremoteprocessrunner.h>
#include <utils/qtcassert.h>
#include <QtGui/QMessageBox>
#include <QtGui/QSortFilterProxyModel>
#include <QtGui/QComboBox>
namespace RemoteLinux {
namespace Internal {
class StartGdbServerDialogPrivate
{
public:
StartGdbServerDialogPrivate()
: processList(0)
{}
LinuxDeviceConfiguration::ConstPtr currentDevice() const
{
LinuxDeviceConfigurations *devices = LinuxDeviceConfigurations::instance();
return devices->deviceAt(ui.deviceComboBox->currentIndex());
}
AbstractRemoteLinuxProcessList *processList;
QSortFilterProxyModel proxyModel;
Ui::StartGdbServerDialog ui;
RemoteLinuxUsedPortsGatherer gatherer;
Utils::SshRemoteProcessRunner::Ptr runner;
};
} // namespace Internal
StartGdbServerDialog::StartGdbServerDialog(QWidget *parent) :
QDialog(parent),
d(new Internal::StartGdbServerDialogPrivate)
{
LinuxDeviceConfigurations *devices = LinuxDeviceConfigurations::instance();
d->ui.setupUi(this);
d->ui.deviceComboBox->setModel(devices);
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);
} else {
d->ui.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->proxyModel, SLOT(setFilterRegExp(QString)));
connect(d->ui.tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(handleSelectionChanged()));
connect(d->ui.updateListButton, SIGNAL(clicked()),
SLOT(updateProcessList()));
connect(d->ui.attachProcessButton, SIGNAL(clicked()), SLOT(attachToProcess()));
connect(&d->proxyModel, SIGNAL(layoutChanged()),
SLOT(handleProcessListUpdated()));
connect(d->ui.deviceComboBox, SIGNAL(currentIndexChanged(int)),
SLOT(attachToDevice(int)));
handleSelectionChanged();
attachToDevice(0);
}
}
StartGdbServerDialog::~StartGdbServerDialog()
{
delete d->processList;
delete d;
}
void StartGdbServerDialog::attachToDevice(int index)
{
LinuxDeviceConfigurations *devices = LinuxDeviceConfigurations::instance();
delete d->processList;
d->processList = new GenericRemoteLinuxProcessList(devices->deviceAt(index));
d->proxyModel.setSourceModel(d->processList);
connect(d->processList, SIGNAL(error(QString)),
SLOT(handleRemoteError(QString)));
connect(d->processList, SIGNAL(modelReset()),
SLOT(handleProcessListUpdated()));
connect(d->processList, SIGNAL(processKilled()),
SLOT(handleProcessKilled()), Qt::QueuedConnection);
updateProcessList();
}
void StartGdbServerDialog::handleRemoteError(const QString &errorMsg)
{
QMessageBox::critical(this, tr("Remote Error"), errorMsg);
d->ui.updateListButton->setEnabled(true);
handleSelectionChanged();
}
void StartGdbServerDialog::handleProcessListUpdated()
{
d->ui.updateListButton->setEnabled(true);
d->ui.tableView->resizeRowsToContents();
handleSelectionChanged();
}
void StartGdbServerDialog::updateProcessList()
{
d->ui.updateListButton->setEnabled(false);
d->ui.attachProcessButton->setEnabled(false);
d->processList->update();
}
void StartGdbServerDialog::attachToProcess()
{
const QModelIndexList &indexes =
d->ui.tableView->selectionModel()->selectedIndexes();
if (indexes.empty())
return;
d->ui.updateListButton->setEnabled(false);
d->ui.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);
const int pid = d->processList->pidAt(row);
if (port == -1) {
emit processAborted();
} else {
emit pidSelected(pid);
emit portSelected(pid);
startGdbServerOnPort(port, pid);
}
}
void StartGdbServerDialog::handleProcessKilled()
{
updateProcessList();
}
void StartGdbServerDialog::handleSelectionChanged()
{
d->ui.attachProcessButton->setEnabled(d->ui.tableView->selectionModel()->hasSelection());
}
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();
}
void StartGdbServerDialog::portListReady()
{
d->ui.updateListButton->setEnabled(true);
d->ui.attachProcessButton->setEnabled(true);
}
void StartGdbServerDialog::startGdbServer()
{
LinuxDeviceConfiguration::ConstPtr device = d->currentDevice();
d->gatherer.start(Utils::SshConnection::create(device->sshParameters()), device);
}
void StartGdbServerDialog::handleConnectionError()
{
d->ui.textBrowser->append(tr("Connection error: %1")
.arg(d->runner->connection()->errorString()));
emit processAborted();
}
void StartGdbServerDialog::handleProcessStarted()
{
d->ui.textBrowser->append(tr("Starting gdbserver..."));
}
void StartGdbServerDialog::handleProcessOutputAvailable(const QByteArray &ba)
{
d->ui.textBrowser->append(QString::fromUtf8(ba.trimmed()));
}
void StartGdbServerDialog::handleProcessErrorOutput(const QByteArray &ba)
{
d->ui.textBrowser->append(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).toInt();
d->ui.textBrowser->append(tr("Port %1 is now accessible.").arg(port));
emit portOpened(port);
}
}
void StartGdbServerDialog::handleProcessClosed(int status)
{
d->ui.textBrowser->append(tr("Process gdbserver finished. Status: %1").arg(status));
}
void StartGdbServerDialog::startGdbServerOnPort(int port, int pid)
{
LinuxDeviceConfiguration::ConstPtr device = d->currentDevice();
d->runner = Utils::SshRemoteProcessRunner::create(device->sshParameters());
connect(d->runner.data(), SIGNAL(connectionError(Utils::SshError)),
SLOT(handleConnectionError()));
connect(d->runner.data(), SIGNAL(processStarted()),
SLOT(handleProcessStarted()));
connect(d->runner.data(), SIGNAL(processOutputAvailable(QByteArray)),
SLOT(handleProcessOutputAvailable(QByteArray)));
connect(d->runner.data(), SIGNAL(processErrorOutputAvailable(QByteArray)),
SLOT(handleProcessErrorOutput(QByteArray)));
connect(d->runner.data(), SIGNAL(processClosed(int)),
SLOT(handleProcessClosed(int)));
QByteArray cmd = "/usr/bin/gdbserver --attach localhost:"
+ QByteArray::number(port) + " " + QByteArray::number(pid);
d->runner->run(cmd);
}
} // namespace RemoteLinux
#ifndef STARTGDBSERVERDIALOG_H
#define STARTGDBSERVERDIALOG_H
#include "remotelinux_export.h"
#include <QtGui/QDialog>
namespace RemoteLinux {
namespace Internal {
class StartGdbServerDialogPrivate;
} // namespace Internal
class REMOTELINUX_EXPORT StartGdbServerDialog : public QDialog
{
Q_OBJECT
public:
explicit StartGdbServerDialog(QWidget *parent = 0);
~StartGdbServerDialog();
void startGdbServer();
signals:
void pidSelected(int pid);
void portSelected(int port);
void portOpened(int port);
void processAborted();
private slots:
void attachToDevice(int index);
void handleRemoteError(const QString &errorMessage);
void handleProcessListUpdated();
void updateProcessList();
void attachToProcess();
void handleProcessKilled();
void handleSelectionChanged();
void portGathererError(const QString &errorMessage);
void portListReady();
void handleProcessClosed(int);
void handleProcessErrorOutput(const QByteArray &data);
void handleProcessOutputAvailable(const QByteArray &data);
void handleProcessStarted();
void handleConnectionError();
private:
void startGdbServerOnPort(int port, int pid);
Internal::StartGdbServerDialogPrivate *d;
};
} // namespace RemoteLinux
#endif // STARTGDBSERVERDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>StartGdbServerDialog</class>
<widget class="QDialog" name="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" alignment="Qt::AlignVCenter">
<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>
<zorder>buttonBox</zorder>
<zorder>filterLabel</zorder>
<zorder>processFilterLineEdit</zorder>
<zorder>deviceComboBox</zorder>
<zorder>label</zorder>
<zorder>updateListButton</zorder>
<zorder>attachProcessButton</zorder>
<zorder>textBrowser</zorder>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>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>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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment