2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-10-18 17:13:33 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-10-18 17:13:33 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-18 17:13:33 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-10-18 17:13:33 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-10-18 17:13:33 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-18 17:13:33 +02:00
|
|
|
|
2011-09-22 11:18:14 +02:00
|
|
|
#include "startgdbserverdialog.h"
|
|
|
|
|
|
2012-07-27 00:17:12 +02:00
|
|
|
#include "debuggermainwindow.h"
|
|
|
|
|
#include "debuggerplugin.h"
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "debuggerkitinformation.h"
|
2012-08-15 13:21:37 +02:00
|
|
|
#include "debuggerruncontrolfactory.h"
|
2012-07-27 00:17:12 +02:00
|
|
|
#include "debuggerstartparameters.h"
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitchooser.h>
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <projectexplorer/devicesupport/deviceprocesslist.h>
|
2013-03-21 17:10:19 +01:00
|
|
|
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
|
2012-07-26 23:29:00 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
2012-07-27 00:17:12 +02:00
|
|
|
#include <ssh/sshremoteprocessrunner.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 <QMessageBox>
|
2013-03-18 14:47:33 +01:00
|
|
|
#include <QFileInfo>
|
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;
|
|
|
|
|
|
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:
|
2012-08-08 12:03:07 +02:00
|
|
|
StartGdbServerDialogPrivate() {}
|
2011-09-22 11:18:14 +02:00
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
DeviceProcessesDialog *dialog;
|
2012-03-21 17:54:56 +01:00
|
|
|
bool startServerOnly;
|
2013-08-08 11:13:20 +02:00
|
|
|
DeviceProcessItem process;
|
2012-09-03 18:31:44 +02:00
|
|
|
Kit *kit;
|
2012-08-08 12:03:07 +02:00
|
|
|
IDevice::ConstPtr device;
|
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;
|
2011-09-22 11:18:14 +02:00
|
|
|
};
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
GdbServerStarter::GdbServerStarter(DeviceProcessesDialog *dlg, bool startServerOnly)
|
|
|
|
|
: QObject(dlg)
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-08-08 12:03:07 +02:00
|
|
|
d = new StartGdbServerDialogPrivate;
|
|
|
|
|
d->dialog = dlg;
|
2012-09-03 18:31:44 +02:00
|
|
|
d->kit = dlg->kitChooser()->currentKit();
|
2012-08-08 12:03:07 +02:00
|
|
|
d->process = dlg->currentProcess();
|
2012-09-03 18:31:44 +02:00
|
|
|
d->device = DeviceKitInformation::device(d->kit);
|
2012-08-08 12:03:07 +02:00
|
|
|
d->startServerOnly = startServerOnly;
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
GdbServerStarter::~GdbServerStarter()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::handleRemoteError(const QString &errorMsg)
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-08-08 12:03:07 +02:00
|
|
|
QMessageBox::critical(0, tr("Remote Error"), errorMsg);
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::portGathererError(const QString &text)
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-08-08 12:03:07 +02:00
|
|
|
logMessage(tr("Could not retrieve list of free ports:"));
|
|
|
|
|
logMessage(text);
|
|
|
|
|
logMessage(tr("Process aborted"));
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::run()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-08-08 12:03:07 +02:00
|
|
|
QTC_ASSERT(d->device, return);
|
|
|
|
|
connect(&d->gatherer, SIGNAL(error(QString)), SLOT(portGathererError(QString)));
|
|
|
|
|
connect(&d->gatherer, SIGNAL(portListReady()), SLOT(portListReady()));
|
|
|
|
|
d->gatherer.start(d->device);
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::portListReady()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-08-08 12:03:07 +02:00
|
|
|
PortList ports = d->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
|
|
|
if (port == -1) {
|
2012-08-08 12:03:07 +02:00
|
|
|
QTC_ASSERT(false, /**/);
|
|
|
|
|
emit logMessage(tr("Process aborted"));
|
2011-12-06 15:39:25 +01:00
|
|
|
return;
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
connect(&d->runner, SIGNAL(connectionError()), SLOT(handleConnectionError()));
|
|
|
|
|
connect(&d->runner, SIGNAL(processStarted()), SLOT(handleProcessStarted()));
|
|
|
|
|
connect(&d->runner, SIGNAL(readyReadStandardOutput()), SLOT(handleProcessOutputAvailable()));
|
|
|
|
|
connect(&d->runner, SIGNAL(readyReadStandardError()), SLOT(handleProcessErrorOutput()));
|
|
|
|
|
connect(&d->runner, SIGNAL(processClosed(int)), SLOT(handleProcessClosed(int)));
|
2011-09-22 11:18:14 +02:00
|
|
|
|
2013-06-12 08:55:11 +02:00
|
|
|
QByteArray cmd = "gdbserver --attach :"
|
2012-08-22 11:58:33 +02:00
|
|
|
+ QByteArray::number(port) + ' ' + QByteArray::number(d->process.pid);
|
2012-08-08 12:03:07 +02:00
|
|
|
logMessage(tr("Running command: %1").arg(QString::fromLatin1(cmd)));
|
|
|
|
|
d->runner.run(cmd, d->device->sshParameters());
|
2011-12-05 19:10:32 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::handleConnectionError()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::handleProcessStarted()
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2011-12-06 15:39:25 +01:00
|
|
|
logMessage(tr("Starting gdbserver..."));
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::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-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::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();
|
2012-08-08 12:03:07 +02:00
|
|
|
logMessage(tr("Port %1 is now accessible.").arg(port));
|
|
|
|
|
logMessage(tr("Server started on %1:%2")
|
|
|
|
|
.arg(d->device->sshParameters().host).arg(port));
|
|
|
|
|
if (!d->startServerOnly)
|
|
|
|
|
attach(port);
|
2012-03-21 17:54:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-06 15:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::attach(int port)
|
2011-12-06 15:39:25 +01:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
QString sysroot = SysRootKitInformation::sysRoot(d->kit).toString();
|
2012-08-08 12:03:07 +02:00
|
|
|
QString binary;
|
|
|
|
|
QString localExecutable;
|
|
|
|
|
QString candidate = sysroot + d->process.exe;
|
|
|
|
|
if (QFileInfo(candidate).exists())
|
|
|
|
|
localExecutable = candidate;
|
|
|
|
|
if (localExecutable.isEmpty()) {
|
|
|
|
|
binary = d->process.cmdLine.section(QLatin1Char(' '), 0, 0);
|
|
|
|
|
candidate = sysroot + QLatin1Char('/') + binary;
|
2012-07-27 00:17:12 +02:00
|
|
|
if (QFileInfo(candidate).exists())
|
|
|
|
|
localExecutable = candidate;
|
2012-08-08 12:03:07 +02:00
|
|
|
}
|
|
|
|
|
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->process.exe));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-07-27 00:17:12 +02:00
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
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->process.exe));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-07-27 00:17:12 +02:00
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
DebuggerStartParameters sp;
|
2012-09-05 14:56:08 +02:00
|
|
|
QTC_ASSERT(fillParameters(&sp, d->kit), return);
|
2012-08-15 13:21:37 +02:00
|
|
|
sp.masterEngineType = GdbEngineType;
|
|
|
|
|
sp.connParams.port = port;
|
2012-11-20 15:04:00 -06:00
|
|
|
sp.remoteChannel = sp.connParams.host + QLatin1Char(':') + QString::number(sp.connParams.port);
|
2012-08-15 13:21:37 +02:00
|
|
|
sp.displayName = tr("Remote: \"%1:%2\"").arg(sp.connParams.host).arg(port);
|
2012-08-08 12:03:07 +02:00
|
|
|
sp.executable = localExecutable;
|
|
|
|
|
sp.startMode = AttachToRemoteServer;
|
|
|
|
|
sp.closeMode = KillAtClose;
|
2012-08-15 13:21:37 +02:00
|
|
|
DebuggerRunControlFactory::createAndScheduleRun(sp);
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::handleProcessClosed(int status)
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
void GdbServerStarter::logMessage(const QString &line)
|
2011-09-22 11:18:14 +02:00
|
|
|
{
|
2012-08-08 12:03:07 +02:00
|
|
|
d->dialog->logMessage(line);
|
2011-09-22 11:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-08 12:03:07 +02:00
|
|
|
} // namespace Internal
|
2012-07-27 00:17:12 +02:00
|
|
|
} // namespace Debugger
|