2010-05-05 12:49:08 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "remotegdbprocess.h"
|
|
|
|
|
|
|
|
|
|
#include "remoteplaingdbadapter.h"
|
|
|
|
|
|
2010-10-08 18:32:13 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2010-05-31 11:12:58 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
|
2010-05-05 12:49:08 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
RemoteGdbProcess::RemoteGdbProcess(const Core::SshConnectionParameters &connParams,
|
2010-05-05 12:49:08 +02:00
|
|
|
RemotePlainGdbAdapter *adapter, QObject *parent)
|
2010-07-12 09:33:22 +02:00
|
|
|
: AbstractGdbProcess(parent), m_connParams(connParams), m_adapter(adapter)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray RemoteGdbProcess::readAllStandardOutput()
|
|
|
|
|
{
|
|
|
|
|
QByteArray output = m_gdbOutput;
|
|
|
|
|
m_gdbOutput.clear();
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray RemoteGdbProcess::readAllStandardError()
|
|
|
|
|
{
|
|
|
|
|
QByteArray errorOutput = m_errorOutput;
|
|
|
|
|
m_errorOutput.clear();
|
|
|
|
|
return errorOutput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::start(const QString &cmd, const QStringList &args)
|
2010-10-08 18:32:13 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(cmd);
|
|
|
|
|
Q_UNUSED(args);
|
|
|
|
|
QTC_ASSERT(m_gdbStarted, return);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::realStart(const QString &cmd, const QStringList &args)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
|
|
|
|
m_command = cmd;
|
|
|
|
|
m_cmdArgs = args;
|
2010-07-12 09:33:22 +02:00
|
|
|
m_gdbStarted = false;
|
|
|
|
|
m_error.clear();
|
|
|
|
|
m_conn = SshConnection::create();
|
|
|
|
|
connect(m_conn.data(), SIGNAL(connected()), this, SLOT(handleConnected()));
|
2010-10-08 18:32:13 +02:00
|
|
|
connect(m_conn.data(), SIGNAL(error(Core::SshError)), this,
|
2010-07-12 09:33:22 +02:00
|
|
|
SLOT(handleConnectionError()));
|
|
|
|
|
m_conn->connectToHost(m_connParams);
|
|
|
|
|
}
|
2010-05-05 12:49:08 +02:00
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::handleConnected()
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
m_fifoCreator = m_conn->createRemoteProcess( "rm -f "
|
|
|
|
|
+ AppOutputFile + " && mkfifo " + AppOutputFile);
|
|
|
|
|
connect(m_fifoCreator.data(), SIGNAL(closed(int)), this,
|
|
|
|
|
SLOT(handleFifoCreationFinished(int)));
|
|
|
|
|
m_fifoCreator->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::handleConnectionError()
|
|
|
|
|
{
|
|
|
|
|
emitErrorExit(tr("Connection could not be established."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::handleFifoCreationFinished(int exitStatus)
|
|
|
|
|
{
|
|
|
|
|
if (exitStatus != SshRemoteProcess::ExitedNormally) {
|
|
|
|
|
emitErrorExit(tr("Could not create FIFO."));
|
|
|
|
|
} else {
|
2010-10-29 11:41:39 +02:00
|
|
|
m_appOutputReader = m_conn->createRemoteProcess("cat " + AppOutputFile
|
|
|
|
|
+ " && rm -f " + AppOutputFile);
|
2010-07-12 09:33:22 +02:00
|
|
|
connect(m_appOutputReader.data(), SIGNAL(started()), this,
|
|
|
|
|
SLOT(handleAppOutputReaderStarted()));
|
|
|
|
|
connect(m_appOutputReader.data(), SIGNAL(closed(int)), this,
|
|
|
|
|
SLOT(handleAppOutputReaderFinished(int)));
|
|
|
|
|
m_appOutputReader->start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::handleAppOutputReaderStarted()
|
|
|
|
|
{
|
|
|
|
|
connect(m_appOutputReader.data(), SIGNAL(outputAvailable(QByteArray)),
|
|
|
|
|
this, SLOT(handleAppOutput(QByteArray)));
|
|
|
|
|
QByteArray cmdLine = "DISPLAY=:0.0 " + m_command.toUtf8() + ' '
|
2010-05-10 14:26:41 +02:00
|
|
|
+ m_cmdArgs.join(QLatin1String(" ")).toUtf8()
|
2010-07-12 09:33:22 +02:00
|
|
|
+ " -tty=" + AppOutputFile;
|
2010-05-10 14:26:41 +02:00
|
|
|
if (!m_wd.isEmpty())
|
2010-07-12 09:33:22 +02:00
|
|
|
cmdLine.prepend("cd " + m_wd.toUtf8() + " && ");
|
|
|
|
|
m_gdbProc = m_conn->createRemoteProcess(cmdLine);
|
|
|
|
|
connect(m_gdbProc.data(), SIGNAL(started()), this,
|
|
|
|
|
SLOT(handleGdbStarted()));
|
|
|
|
|
connect(m_gdbProc.data(), SIGNAL(closed(int)), this,
|
|
|
|
|
SLOT(handleGdbFinished(int)));
|
|
|
|
|
connect(m_gdbProc.data(), SIGNAL(outputAvailable(QByteArray)), this,
|
|
|
|
|
SLOT(handleGdbOutput(QByteArray)));
|
|
|
|
|
connect(m_gdbProc.data(), SIGNAL(errorOutputAvailable(QByteArray)), this,
|
|
|
|
|
SLOT(handleErrOutput(QByteArray)));
|
|
|
|
|
m_gdbProc->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::handleAppOutputReaderFinished(int exitStatus)
|
|
|
|
|
{
|
|
|
|
|
if (exitStatus != SshRemoteProcess::ExitedNormally)
|
|
|
|
|
emitErrorExit(tr("Application output reader unexpectedly finished."));
|
|
|
|
|
}
|
2010-05-10 14:26:41 +02:00
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::handleGdbStarted()
|
|
|
|
|
{
|
|
|
|
|
m_gdbStarted = true;
|
2010-10-08 18:32:13 +02:00
|
|
|
emit started();
|
2010-07-12 09:33:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::handleGdbFinished(int exitStatus)
|
|
|
|
|
{
|
|
|
|
|
switch (exitStatus) {
|
|
|
|
|
case SshRemoteProcess::FailedToStart:
|
2010-10-08 18:32:13 +02:00
|
|
|
m_error = tr("Remote gdb failed to start.");
|
|
|
|
|
emit startFailed();
|
2010-07-12 09:33:22 +02:00
|
|
|
break;
|
|
|
|
|
case SshRemoteProcess::KilledBySignal:
|
|
|
|
|
emitErrorExit(tr("Remote gdb crashed."));
|
|
|
|
|
break;
|
|
|
|
|
case SshRemoteProcess::ExitedNormally:
|
|
|
|
|
emit finished(m_gdbProc->exitCode(), QProcess::NormalExit);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
disconnect(m_conn.data(), 0, this, 0);
|
|
|
|
|
m_gdbProc = SshRemoteProcess::Ptr();
|
|
|
|
|
m_appOutputReader = SshRemoteProcess::Ptr();
|
|
|
|
|
m_conn->disconnectFromHost();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RemoteGdbProcess::waitForStarted()
|
|
|
|
|
{
|
|
|
|
|
return m_error.isEmpty();
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 RemoteGdbProcess::write(const QByteArray &data)
|
|
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
if (!m_gdbStarted || !m_inputToSend.isEmpty() || !m_lastSeqNr.isEmpty())
|
2010-05-05 12:49:08 +02:00
|
|
|
m_inputToSend.enqueue(data);
|
2010-07-12 09:33:22 +02:00
|
|
|
else
|
|
|
|
|
sendInput(data);
|
|
|
|
|
return data.size();
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::kill()
|
|
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
SshRemoteProcess::Ptr killProc
|
|
|
|
|
= m_conn->createRemoteProcess("pkill -SIGKILL -x gdb");
|
|
|
|
|
killProc->start();
|
|
|
|
|
}
|
2010-05-05 12:49:08 +02:00
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::interruptInferior()
|
|
|
|
|
{
|
|
|
|
|
SshRemoteProcess::Ptr intProc
|
|
|
|
|
= m_conn->createRemoteProcess("pkill -x -SIGINT gdb");
|
|
|
|
|
intProc->start();
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QProcess::ProcessState RemoteGdbProcess::state() const
|
|
|
|
|
{
|
2010-05-10 14:26:41 +02:00
|
|
|
return m_gdbStarted ? QProcess::Running : QProcess::Starting;
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString RemoteGdbProcess::errorString() const
|
|
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
return m_error;
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::handleGdbOutput(const QByteArray &output)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
// TODO: Carriage return removal still necessary?
|
|
|
|
|
m_currentGdbOutput += removeCarriageReturn(output);
|
2010-05-05 12:49:08 +02:00
|
|
|
#if 0
|
2010-05-10 14:26:41 +02:00
|
|
|
qDebug("%s: complete unread output is '%s'", Q_FUNC_INFO, m_currentGdbOutput.data());
|
2010-05-05 12:49:08 +02:00
|
|
|
#endif
|
|
|
|
|
if (!m_currentGdbOutput.endsWith('\n'))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_currentGdbOutput.contains(m_lastSeqNr + '^'))
|
|
|
|
|
m_lastSeqNr.clear();
|
|
|
|
|
|
|
|
|
|
if (m_lastSeqNr.isEmpty() && !m_inputToSend.isEmpty()) {
|
|
|
|
|
#if 0
|
|
|
|
|
qDebug("Sending queued command: %s", m_inputToSend.head().data());
|
|
|
|
|
#endif
|
|
|
|
|
sendInput(m_inputToSend.dequeue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_currentGdbOutput.isEmpty()) {
|
|
|
|
|
const int startPos
|
|
|
|
|
= m_gdbOutput.isEmpty() ? findAnchor(m_currentGdbOutput) : 0;
|
|
|
|
|
if (startPos != -1) {
|
|
|
|
|
m_gdbOutput += m_currentGdbOutput.mid(startPos);
|
|
|
|
|
m_currentGdbOutput.clear();
|
|
|
|
|
emit readyReadStandardOutput();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QProcessEnvironment RemoteGdbProcess::processEnvironment() const
|
|
|
|
|
{
|
|
|
|
|
return QProcessEnvironment(); // TODO: Provide actual environment.
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 08:51:46 +02:00
|
|
|
void RemoteGdbProcess::setProcessEnvironment(const QProcessEnvironment & /* env */)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
// TODO: Do something. (if remote process exists: set, otherwise queue)
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
2010-05-19 08:51:46 +02:00
|
|
|
void RemoteGdbProcess::setEnvironment(const QStringList & /* env */)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
|
|
|
|
// TODO: Do something.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoteGdbProcess::setWorkingDirectory(const QString &dir)
|
|
|
|
|
{
|
|
|
|
|
m_wd = dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RemoteGdbProcess::findAnchor(const QByteArray &data) const
|
|
|
|
|
{
|
|
|
|
|
for (int pos = 0; pos < data.count(); ++pos) {
|
|
|
|
|
const char c = data.at(pos);
|
|
|
|
|
if (isdigit(c) || c == '*' || c == '+' || c == '=' || c == '~'
|
|
|
|
|
|| c == '@' || c == '&' || c == '^')
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::sendInput(const QByteArray &data)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
|
|
|
|
int pos;
|
|
|
|
|
for (pos = 0; pos < data.size(); ++pos)
|
|
|
|
|
if (!isdigit(data.at(pos)))
|
|
|
|
|
break;
|
|
|
|
|
m_lastSeqNr = data.left(pos);
|
2010-07-12 09:33:22 +02:00
|
|
|
m_gdbProc->sendInput(data);
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::handleAppOutput(const QByteArray &output)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
m_adapter->handleApplicationOutput(output);
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::handleErrOutput(const QByteArray &output)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
m_errorOutput += output;
|
2010-05-10 14:26:41 +02:00
|
|
|
emit readyReadStandardError();
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray RemoteGdbProcess::removeCarriageReturn(const QByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
QByteArray output;
|
|
|
|
|
for (int i = 0; i < data.size(); ++i) {
|
|
|
|
|
const char c = data.at(i);
|
|
|
|
|
if (c != '\r')
|
|
|
|
|
output += c;
|
|
|
|
|
}
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
void RemoteGdbProcess::emitErrorExit(const QString &error)
|
2010-05-05 12:49:08 +02:00
|
|
|
{
|
2010-07-12 09:33:22 +02:00
|
|
|
if (m_error.isEmpty()) {
|
|
|
|
|
m_error = error;
|
|
|
|
|
emit finished(-1, QProcess::CrashExit);
|
2010-05-05 12:49:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QByteArray RemoteGdbProcess::CtrlC = QByteArray(1, 0x3);
|
|
|
|
|
const QByteArray RemoteGdbProcess::AppOutputFile("app_output");
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|