2011-10-18 17:13:33 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-10-18 17:13:33 +02:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-10-18 17:13:33 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2011-09-22 11:18:14 +02:00
|
|
|
#include "startgdbserverdialog.h"
|
|
|
|
|
|
2012-07-27 00:17:12 +02:00
|
|
|
#include "debuggercore.h"
|
|
|
|
|
#include "debuggermainwindow.h"
|
|
|
|
|
#include "debuggerplugin.h"
|
|
|
|
|
#include "debuggerprofileinformation.h"
|
|
|
|
|
#include "debuggerrunner.h"
|
|
|
|
|
#include "debuggerstartparameters.h"
|
|
|
|
|
|
2011-12-06 15:39:25 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2011-12-05 19:10:32 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2012-07-15 21:45:29 +03:00
|
|
|
#include <projectexplorer/profilechooser.h>
|
2012-07-26 16:23:20 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceprocesslist.h>
|
2012-07-26 23:29:00 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
2012-07-27 00:17:12 +02:00
|
|
|
#include <ssh/sshconnection.h>
|
|
|
|
|
#include <ssh/sshremoteprocessrunner.h>
|
2011-12-06 15:39:25 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2012-02-28 10:34:50 +01:00
|
|
|
#include <utils/portlist.h>
|
2011-12-06 15:39:25 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2011-09-22 11:18:14 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QSettings>
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
#include <QSpacerItem>
|
|
|
|
|
#include <QTextBrowser>
|
2012-08-06 12:56:27 +02:00
|
|
|
#include <QTreeView>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QVBoxLayout>
|
2011-12-06 15:39:25 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
2012-03-06 12:31:42 +01:00
|
|
|
using namespace ProjectExplorer;
|
2012-05-18 10:49:35 +02:00
|
|
|
using namespace QSsh;
|
2011-12-06 15:39:25 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2012-07-27 00:17:12 +02:00
|
|
|
const char LastProfile[] = "Debugger/LastProfile";
|
|
|
|
|
const char LastDevice[] = "Debugger/LastDevice";
|
|
|
|
|
const char LastProcessName[] = "Debugger/LastProcessName";
|
|
|
|
|
//const char LastLocalExecutable[] = "Debugger/LastLocalExecutable";
|
2011-09-22 11:18:14 +02:00
|
|
|
|
2012-07-27 00:17:12 +02:00
|
|
|
namespace Debugger {
|
2011-09-22 11:18:14 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class StartGdbServerDialogPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2011-12-06 15:39:25 +01:00
|
|
|
StartGdbServerDialogPrivate(StartGdbServerDialog *q);
|
2011-09-22 11:18:14 +02:00
|
|
|
|
2012-07-25 16:23:26 +02:00
|
|
|
IDevice::ConstPtr currentDevice() const
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-07-25 04:11:50 +02:00
|
|
|
Profile *profile = profileChooser->currentProfile();
|
2012-07-25 16:23:26 +02:00
|
|
|
return DeviceProfileInformation::device(profile);
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-03-21 17:54:56 +01:00
|
|
|
bool startServerOnly;
|
2012-07-26 16:23:20 +02:00
|
|
|
DeviceProcessList *processList;
|
2011-09-22 11:18:14 +02:00
|
|
|
QSortFilterProxyModel proxyModel;
|
2011-12-06 15:39:25 +01:00
|
|
|
|
|
|
|
|
QLineEdit *processFilterLineEdit;
|
2012-08-06 12:56:27 +02:00
|
|
|
QTreeView *processView;
|
2011-12-06 15:39:25 +01:00
|
|
|
QPushButton *attachProcessButton;
|
|
|
|
|
QTextBrowser *textBrowser;
|
|
|
|
|
QPushButton *closeButton;
|
2012-07-15 21:45:29 +03:00
|
|
|
ProfileChooser *profileChooser;
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2012-07-26 23:29:00 +02:00
|
|
|
DeviceUsedPortsGatherer gatherer;
|
2011-12-06 15:39:25 +01:00
|
|
|
SshRemoteProcessRunner runner;
|
|
|
|
|
QString remoteCommandLine;
|
2012-05-04 12:46:33 +02:00
|
|
|
QString remoteExecutable;
|
2011-09-22 11:18:14 +02:00
|
|
|
};
|
|
|
|
|
|
2011-12-06 15:39:25 +01:00
|
|
|
StartGdbServerDialogPrivate::StartGdbServerDialogPrivate(StartGdbServerDialog *q)
|
2012-08-06 13:02:01 +02:00
|
|
|
: startServerOnly(true), processList(0)
|
2011-12-06 15:39:25 +01:00
|
|
|
{
|
2012-07-27 00:17:12 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2012-07-24 16:41:15 +02:00
|
|
|
profileChooser = new ProfileChooser(q, ProfileChooser::RemoteDebugging);
|
2011-12-06 15:39:25 +01:00
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
|
2012-08-06 12:56:27 +02:00
|
|
|
processView = new QTreeView(q);
|
|
|
|
|
processView->setSortingEnabled(true);
|
|
|
|
|
processView->header()->setDefaultSectionSize(100);
|
|
|
|
|
processView->header()->setStretchLastSection(true);
|
|
|
|
|
processView->setAlternatingRowColors(true);
|
|
|
|
|
processView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
processView->setRootIsDecorated(false);
|
2011-12-06 15:39:25 +01:00
|
|
|
|
|
|
|
|
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();
|
2012-07-15 21:46:36 +03:00
|
|
|
formLayout->addRow(StartGdbServerDialog::tr("Target:"), profileChooser);
|
2012-05-03 15:47:45 +02:00
|
|
|
formLayout->addRow(StartGdbServerDialog::tr("&Filter entries:"), processFilterLineEdit);
|
2011-12-06 15:39:25 +01:00
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout2 = new QHBoxLayout();
|
|
|
|
|
horizontalLayout2->addStretch(1);
|
|
|
|
|
horizontalLayout2->addWidget(attachProcessButton);
|
|
|
|
|
horizontalLayout2->addWidget(closeButton);
|
|
|
|
|
|
2012-08-06 12:56:27 +02:00
|
|
|
formLayout->addRow(processView);
|
2011-12-06 15:39:25 +01:00
|
|
|
formLayout->addRow(textBrowser);
|
|
|
|
|
formLayout->addRow(horizontalLayout2);
|
|
|
|
|
q->setLayout(formLayout);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-22 11:18:14 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2011-09-22 11:18:14 +02:00
|
|
|
StartGdbServerDialog::StartGdbServerDialog(QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
2011-12-06 15:39:25 +01:00
|
|
|
d(new Internal::StartGdbServerDialogPrivate(this))
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
setWindowTitle(tr("List of Remote Processes"));
|
|
|
|
|
|
|
|
|
|
QObject::connect(d->closeButton, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
connect(&d->gatherer, SIGNAL(error(QString)), SLOT(portGathererError(QString)));
|
|
|
|
|
connect(&d->gatherer, SIGNAL(portListReady()), SLOT(portListReady()));
|
2012-07-25 04:11:50 +02:00
|
|
|
|
2012-08-06 12:56:27 +02:00
|
|
|
d->processView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
2012-07-25 04:11:50 +02:00
|
|
|
d->proxyModel.setDynamicSortFilter(true);
|
|
|
|
|
d->proxyModel.setFilterKeyColumn(-1);
|
2012-08-06 12:56:27 +02:00
|
|
|
d->processView->setModel(&d->proxyModel);
|
2012-07-25 04:11:50 +02:00
|
|
|
connect(d->processFilterLineEdit, SIGNAL(textChanged(QString)),
|
|
|
|
|
&d->proxyModel, SLOT(setFilterRegExp(QString)));
|
|
|
|
|
|
2012-08-06 12:56:27 +02:00
|
|
|
connect(d->processView->selectionModel(),
|
2012-07-25 04:11:50 +02:00
|
|
|
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
|
|
|
|
SLOT(updateButtons()));
|
|
|
|
|
connect(d->profileChooser, SIGNAL(activated(int)),
|
2011-12-06 15:39:25 +01:00
|
|
|
SLOT(updateButtons()));
|
2012-07-25 04:11:50 +02:00
|
|
|
//connect(d->updateListButton, SIGNAL(clicked()),
|
|
|
|
|
// SLOT(updateProcessList()));
|
|
|
|
|
connect(d->attachProcessButton, SIGNAL(clicked()), SLOT(attachToProcess()));
|
|
|
|
|
connect(&d->proxyModel, SIGNAL(layoutChanged()),
|
|
|
|
|
SLOT(handleProcessListUpdated()));
|
|
|
|
|
connect(d->profileChooser, SIGNAL(currentIndexChanged(int)),
|
|
|
|
|
SLOT(attachToDevice()));
|
|
|
|
|
updateButtons();
|
|
|
|
|
attachToDevice();
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartGdbServerDialog::~StartGdbServerDialog()
|
|
|
|
|
{
|
|
|
|
|
delete d->processList;
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 04:11:50 +02:00
|
|
|
void StartGdbServerDialog::attachToDevice()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-07-25 16:23:26 +02:00
|
|
|
IDevice::ConstPtr device = d->currentDevice();
|
2012-05-04 18:32:12 +02:00
|
|
|
// TODO: display error on non-matching device.
|
2012-08-03 09:56:39 +02:00
|
|
|
if (!device || !device->canCreateProcessModel())
|
2012-03-06 12:31:42 +01:00
|
|
|
return;
|
2011-09-22 11:18:14 +02:00
|
|
|
delete d->processList;
|
2012-08-02 14:45:27 +02:00
|
|
|
d->processList = device->createProcessListModel();
|
2011-09-22 11:18:14 +02:00
|
|
|
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);
|
2011-12-06 15:39:25 +01:00
|
|
|
updateButtons();
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::handleProcessListUpdated()
|
|
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
updateButtons();
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::updateProcessList()
|
|
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
d->attachProcessButton->setEnabled(false);
|
2011-09-22 11:18:14 +02:00
|
|
|
d->processList->update();
|
2011-12-06 15:39:25 +01:00
|
|
|
d->proxyModel.setFilterRegExp(QString());
|
|
|
|
|
d->proxyModel.setFilterRegExp(d->processFilterLineEdit->text());
|
|
|
|
|
updateButtons();
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::attachToProcess()
|
|
|
|
|
{
|
2012-08-06 12:56:27 +02:00
|
|
|
const QModelIndexList indexes =
|
|
|
|
|
d->processView->selectionModel()->selectedIndexes();
|
2011-09-22 11:18:14 +02:00
|
|
|
if (indexes.empty())
|
|
|
|
|
return;
|
2011-12-06 15:39:25 +01:00
|
|
|
d->attachProcessButton->setEnabled(false);
|
2011-09-22 11:18:14 +02:00
|
|
|
|
2012-07-25 16:23:26 +02:00
|
|
|
IDevice::ConstPtr device = d->currentDevice();
|
2012-03-06 12:31:42 +01:00
|
|
|
if (!device)
|
|
|
|
|
return;
|
2011-09-22 11:18:14 +02:00
|
|
|
PortList ports = device->freePorts();
|
2011-12-21 20:14:42 +01:00
|
|
|
const int port = d->gatherer.getNextFreePort(&ports);
|
2011-09-22 11:18:14 +02:00
|
|
|
const int row = d->proxyModel.mapToSource(indexes.first()).row();
|
2011-12-06 15:39:25 +01:00
|
|
|
QTC_ASSERT(row >= 0, return);
|
2012-07-26 16:23:20 +02:00
|
|
|
DeviceProcess process = d->processList->at(row);
|
2012-05-04 11:44:14 +02:00
|
|
|
d->remoteCommandLine = process.cmdLine;
|
2012-05-04 12:46:33 +02:00
|
|
|
d->remoteExecutable = process.exe;
|
2011-09-22 11:18:14 +02:00
|
|
|
if (port == -1) {
|
2011-12-06 15:39:25 +01:00
|
|
|
reportFailure();
|
|
|
|
|
return;
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2012-07-27 00:17:12 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
|
|
|
|
settings->setValue(LastProfile, d->profileChooser->currentProfileId().toString());
|
|
|
|
|
settings->setValue(LastProcessName, d->processFilterLineEdit->text());
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2012-05-04 11:44:14 +02:00
|
|
|
startGdbServerOnPort(port, process.pid);
|
2011-12-06 15:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::reportFailure()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(false, /**/);
|
|
|
|
|
logMessage(tr("Process aborted"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::logMessage(const QString &line)
|
|
|
|
|
{
|
|
|
|
|
d->textBrowser->append(line);
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::handleProcessKilled()
|
|
|
|
|
{
|
|
|
|
|
updateProcessList();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-06 15:39:25 +01:00
|
|
|
void StartGdbServerDialog::updateButtons()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-08-06 12:56:27 +02:00
|
|
|
d->attachProcessButton->setEnabled(d->processView->selectionModel()->hasSelection()
|
2011-12-06 15:39:25 +01:00
|
|
|
|| d->proxyModel.rowCount() == 1);
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::portGathererError(const QString &text)
|
|
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(tr("Could not retrieve list of free ports:"));
|
|
|
|
|
logMessage(text);
|
|
|
|
|
reportFailure();
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::portListReady()
|
|
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
updateButtons();
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::startGdbServer()
|
|
|
|
|
{
|
2012-03-21 17:54:56 +01:00
|
|
|
d->startServerOnly = true;
|
|
|
|
|
if (exec() == QDialog::Rejected)
|
|
|
|
|
return;
|
2012-04-03 10:23:59 +02:00
|
|
|
d->gatherer.start(d->currentDevice());
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-05 19:10:32 +01:00
|
|
|
void StartGdbServerDialog::attachToRemoteProcess()
|
|
|
|
|
{
|
2012-03-21 17:54:56 +01:00
|
|
|
d->startServerOnly = false;
|
|
|
|
|
if (exec() == QDialog::Rejected)
|
|
|
|
|
return;
|
2012-04-03 10:23:59 +02:00
|
|
|
d->gatherer.start(d->currentDevice());
|
2011-12-05 19:10:32 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-22 11:18:14 +02:00
|
|
|
void StartGdbServerDialog::handleConnectionError()
|
|
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(tr("Connection error: %1").arg(d->runner.lastConnectionErrorString()));
|
2011-09-22 11:18:14 +02:00
|
|
|
emit processAborted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::handleProcessStarted()
|
|
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(tr("Starting gdbserver..."));
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 09:42:32 +02:00
|
|
|
void StartGdbServerDialog::handleProcessOutputAvailable()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-06-08 09:42:32 +02:00
|
|
|
logMessage(QString::fromUtf8(d->runner.readAllStandardOutput().trimmed()));
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-08 09:42:32 +02:00
|
|
|
void StartGdbServerDialog::handleProcessErrorOutput()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-06-08 09:42:32 +02:00
|
|
|
const QByteArray ba = d->runner.readAllStandardError();
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(QString::fromUtf8(ba.trimmed()));
|
2011-09-22 11:18:14 +02:00
|
|
|
// "Attached; pid = 16740"
|
|
|
|
|
// "Listening on port 10000"
|
2012-03-21 17:54:56 +01:00
|
|
|
foreach (const QByteArray &line, ba.split('\n')) {
|
|
|
|
|
if (line.startsWith("Listening on port")) {
|
|
|
|
|
const int port = line.mid(18).trimmed().toInt();
|
|
|
|
|
reportOpenPort(port);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-06 15:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::reportOpenPort(int port)
|
|
|
|
|
{
|
2012-07-27 00:17:12 +02:00
|
|
|
close();
|
2012-03-21 17:54:56 +01:00
|
|
|
logMessage(tr("Port %1 is now accessible.").arg(port));
|
2012-07-25 16:23:26 +02:00
|
|
|
IDevice::ConstPtr device = d->currentDevice();
|
2012-02-29 17:14:03 +01:00
|
|
|
QString channel = QString("%1:%2").arg(device->sshParameters().host).arg(port);
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(tr("Server started on %1").arg(channel));
|
|
|
|
|
|
2012-07-27 00:17:12 +02:00
|
|
|
const Profile *profile = d->profileChooser->currentProfile();
|
|
|
|
|
QTC_ASSERT(profile, return);
|
|
|
|
|
|
|
|
|
|
if (d->startServerOnly) {
|
|
|
|
|
//showStatusMessage(tr("gdbserver is now listening at %1").arg(channel));
|
|
|
|
|
} else {
|
|
|
|
|
QString sysroot = SysRootProfileInformation::sysRoot(profile).toString();
|
|
|
|
|
QString binary;
|
|
|
|
|
QString localExecutable;
|
|
|
|
|
QString candidate = sysroot + d->remoteExecutable;
|
|
|
|
|
if (QFileInfo(candidate).exists())
|
|
|
|
|
localExecutable = candidate;
|
|
|
|
|
if (localExecutable.isEmpty()) {
|
|
|
|
|
binary = d->remoteCommandLine.section(QLatin1Char(' '), 0, 0);
|
|
|
|
|
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(DebuggerPlugin::mainWindow(), tr("Warning"),
|
|
|
|
|
tr("Cannot find local executable for remote process \"%1\".")
|
|
|
|
|
.arg(d->remoteCommandLine));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Abi> abis = Abi::abisOfBinary(Utils::FileName::fromString(localExecutable));
|
|
|
|
|
if (abis.isEmpty()) {
|
|
|
|
|
QMessageBox::warning(DebuggerPlugin::mainWindow(), tr("Warning"),
|
|
|
|
|
tr("Cannot find ABI for remote process \"%1\".")
|
|
|
|
|
.arg(d->remoteCommandLine));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebuggerStartParameters sp;
|
|
|
|
|
sp.displayName = tr("Remote: \"%1\"").arg(channel);
|
|
|
|
|
sp.remoteChannel = channel;
|
|
|
|
|
sp.executable = localExecutable;
|
|
|
|
|
sp.startMode = AttachToRemoteServer;
|
|
|
|
|
sp.closeMode = KillAtClose;
|
|
|
|
|
sp.overrideStartScript.clear();
|
|
|
|
|
sp.useServerStartScript = false;
|
|
|
|
|
sp.serverStartScript.clear();
|
|
|
|
|
sp.sysRoot = SysRootProfileInformation::sysRoot(profile).toString();
|
|
|
|
|
sp.debuggerCommand = DebuggerProfileInformation::debuggerCommand(profile).toString();
|
|
|
|
|
sp.connParams = device->sshParameters();
|
|
|
|
|
if (ToolChain *tc = ToolChainProfileInformation::toolChain(profile))
|
|
|
|
|
sp.toolChainAbi = tc->targetAbi();
|
|
|
|
|
|
|
|
|
|
if (RunControl *rc = DebuggerPlugin::createDebugger(sp))
|
|
|
|
|
DebuggerPlugin::startDebugger(rc);
|
2012-03-21 17:54:56 +01:00
|
|
|
}
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::handleProcessClosed(int status)
|
|
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(tr("Process gdbserver finished. Status: %1").arg(status));
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StartGdbServerDialog::startGdbServerOnPort(int port, int pid)
|
|
|
|
|
{
|
2012-07-25 16:23:26 +02:00
|
|
|
IDevice::ConstPtr device = d->currentDevice();
|
2011-11-09 17:38:19 +01:00
|
|
|
connect(&d->runner, SIGNAL(connectionError()), SLOT(handleConnectionError()));
|
2011-11-09 14:19:50 +01:00
|
|
|
connect(&d->runner, SIGNAL(processStarted()), SLOT(handleProcessStarted()));
|
2012-06-08 09:42:32 +02:00
|
|
|
connect(&d->runner, SIGNAL(readyReadStandardOutput()), SLOT(handleProcessOutputAvailable()));
|
|
|
|
|
connect(&d->runner, SIGNAL(readyReadStandardError()), SLOT(handleProcessErrorOutput()));
|
2011-11-09 14:19:50 +01:00
|
|
|
connect(&d->runner, SIGNAL(processClosed(int)), SLOT(handleProcessClosed(int)));
|
2011-09-22 11:18:14 +02:00
|
|
|
|
2012-02-24 15:19:10 +01:00
|
|
|
QByteArray cmd = "/usr/bin/gdbserver --attach :"
|
2011-09-22 11:18:14 +02:00
|
|
|
+ QByteArray::number(port) + " " + QByteArray::number(pid);
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(tr("Running command: %1").arg(QString::fromLatin1(cmd)));
|
2011-11-09 14:19:50 +01:00
|
|
|
d->runner.run(cmd, device->sshParameters());
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-27 00:17:12 +02:00
|
|
|
} // namespace Debugger
|