2009-10-07 10:25:26 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-10-07 10:25:26 +02:00
|
|
|
**
|
|
|
|
|
** 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 "termgdbadapter.h"
|
|
|
|
|
|
|
|
|
|
#include "gdbengine.h"
|
|
|
|
|
#include "procinterrupt.h"
|
|
|
|
|
#include "debuggerstringutils.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QMessageBox>
|
|
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
#define CB(callback) \
|
|
|
|
|
static_cast<GdbEngine::AdapterCallback>(&TermGdbAdapter::callback), \
|
|
|
|
|
STRINGIFY(callback)
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// TermGdbAdapter
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
TermGdbAdapter::TermGdbAdapter(GdbEngine *engine, QObject *parent)
|
|
|
|
|
: AbstractGdbAdapter(engine, parent)
|
|
|
|
|
{
|
|
|
|
|
m_stubProc.setMode(Utils::ConsoleProcess::Debug);
|
|
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
|
m_stubProc.setSettings(Core::ICore::instance()->settings());
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-04-19 14:21:33 +02:00
|
|
|
connect(&m_stubProc, SIGNAL(processMessage(QString, bool)), SLOT(stubMessage(QString, bool)));
|
2009-10-07 10:25:26 +02:00
|
|
|
connect(&m_stubProc, SIGNAL(processStarted()), SLOT(handleInferiorStarted()));
|
|
|
|
|
connect(&m_stubProc, SIGNAL(wrapperStopped()), SLOT(stubExited()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TermGdbAdapter::~TermGdbAdapter()
|
|
|
|
|
{
|
|
|
|
|
m_stubProc.disconnect(); // Avoid spurious state transitions from late exiting stub
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-03 14:06:21 +01:00
|
|
|
AbstractGdbAdapter::DumperHandling TermGdbAdapter::dumperHandling() const
|
|
|
|
|
{
|
2009-11-12 16:49:12 +01:00
|
|
|
// LD_PRELOAD fails for System-Qt on Mac.
|
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
2009-11-03 14:06:21 +01:00
|
|
|
return DumperLoadedByGdb;
|
|
|
|
|
#else
|
|
|
|
|
return DumperLoadedByAdapter; // Handles loading itself via LD_PRELOAD
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-07 10:25:26 +02:00
|
|
|
void TermGdbAdapter::startAdapter()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineStarting, qDebug() << state());
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("TRYING TO START ADAPTER"));
|
2009-10-07 10:25:26 +02:00
|
|
|
|
|
|
|
|
// Currently, adapters are not re-used
|
|
|
|
|
// // We leave the console open, so recycle it now.
|
|
|
|
|
// m_stubProc.blockSignals(true);
|
|
|
|
|
// m_stubProc.stop();
|
|
|
|
|
// m_stubProc.blockSignals(false);
|
|
|
|
|
|
2010-05-12 11:48:00 +02:00
|
|
|
m_stubProc.setWorkingDirectory(startParameters().workingDirectory);
|
2009-11-03 14:06:21 +01:00
|
|
|
// Set environment + dumper preload.
|
|
|
|
|
QStringList environment = startParameters().environment;
|
|
|
|
|
m_stubProc.setEnvironment(environment);
|
2009-10-07 10:25:26 +02:00
|
|
|
// FIXME: Starting the stub implies starting the inferior. This is
|
|
|
|
|
// fairly unclean as far as the state machine and error reporting go.
|
|
|
|
|
if (!m_stubProc.start(startParameters().executable,
|
|
|
|
|
startParameters().processArgs)) {
|
|
|
|
|
// Error message for user is delivered via a signal.
|
|
|
|
|
emit adapterStartFailed(QString(), QString());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_engine->startGdb()) {
|
|
|
|
|
m_stubProc.stop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TermGdbAdapter::handleInferiorStarted()
|
|
|
|
|
{
|
2010-07-08 11:54:06 +02:00
|
|
|
QTC_ASSERT(state() == EngineStarting, qDebug() << state());
|
2009-10-07 10:25:26 +02:00
|
|
|
emit adapterStarted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TermGdbAdapter::startInferior()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
|
|
|
|
const qint64 attachedPID = m_stubProc.applicationPID();
|
2010-06-16 11:08:54 +02:00
|
|
|
m_engine->notifyInferiorPid(attachedPID);
|
2010-01-05 16:51:55 +01:00
|
|
|
m_engine->postCommand("attach " + QByteArray::number(attachedPID),
|
|
|
|
|
CB(handleStubAttached));
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TermGdbAdapter::handleStubAttached(const GdbResponse &response)
|
|
|
|
|
{
|
2009-10-30 17:40:29 +01:00
|
|
|
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
2009-10-07 10:25:26 +02:00
|
|
|
if (response.resultClass == GdbResultDone) {
|
2009-10-30 17:40:29 +01:00
|
|
|
setState(InferiorStopped);
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("INFERIOR ATTACHED"));
|
2009-10-07 10:25:26 +02:00
|
|
|
emit inferiorPrepared();
|
2009-10-30 17:16:56 +01:00
|
|
|
#ifdef Q_OS_LINUX
|
2010-01-05 16:51:55 +01:00
|
|
|
m_engine->postCommand("-stack-list-frames 0 0", CB(handleEntryPoint));
|
2009-10-30 17:16:56 +01:00
|
|
|
#endif
|
2009-10-07 10:25:26 +02:00
|
|
|
} else if (response.resultClass == GdbResultError) {
|
2010-01-04 14:11:07 +01:00
|
|
|
QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data());
|
2009-10-07 10:25:26 +02:00
|
|
|
emit inferiorStartFailed(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TermGdbAdapter::startInferiorPhase2()
|
|
|
|
|
{
|
2009-10-20 14:08:59 +02:00
|
|
|
m_engine->continueInferiorInternal();
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-30 17:16:56 +01:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
void TermGdbAdapter::handleEntryPoint(const GdbResponse &response)
|
|
|
|
|
{
|
|
|
|
|
if (response.resultClass == GdbResultDone) {
|
|
|
|
|
GdbMi stack = response.data.findChild("stack");
|
|
|
|
|
if (stack.isValid() && stack.childCount() == 1)
|
|
|
|
|
m_engine->m_entryPoint = stack.childAt(0).findChild("addr").data();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-10-07 10:25:26 +02:00
|
|
|
void TermGdbAdapter::interruptInferior()
|
|
|
|
|
{
|
2010-06-16 11:08:54 +02:00
|
|
|
const qint64 attachedPID = m_engine->inferiorPid();
|
2009-10-28 20:03:50 +01:00
|
|
|
QTC_ASSERT(attachedPID > 0, return);
|
2009-10-07 10:25:26 +02:00
|
|
|
if (!interruptProcess(attachedPID))
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("CANNOT INTERRUPT %1").arg(attachedPID));
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-19 14:21:33 +02:00
|
|
|
void TermGdbAdapter::stubMessage(const QString &msg, bool)
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2009-10-20 17:43:06 +02:00
|
|
|
showMessageBox(QMessageBox::Critical, tr("Debugger Error"), msg);
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TermGdbAdapter::stubExited()
|
|
|
|
|
{
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("STUB EXITED"));
|
2010-07-08 11:54:06 +02:00
|
|
|
if (state() != EngineStarting // From previous instance
|
2009-10-07 10:25:26 +02:00
|
|
|
&& state() != EngineShuttingDown && state() != DebuggerNotReady)
|
|
|
|
|
emit adapterCrashed(QString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|