2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-10-07 10:25:26 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-10-07 10:25:26 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-10-07 10:25:26 +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.
|
2009-10-07 10:25:26 +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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-10-07 10:25:26 +02:00
|
|
|
|
|
|
|
|
#include "termgdbadapter.h"
|
2011-01-10 10:14:23 +01:00
|
|
|
|
|
|
|
|
#include "debuggerstartparameters.h"
|
2010-11-02 16:14:00 +01:00
|
|
|
#include "gdbmi.h"
|
2009-10-07 10:25:26 +02:00
|
|
|
#include "gdbengine.h"
|
|
|
|
|
#include "procinterrupt.h"
|
|
|
|
|
#include "debuggerstringutils.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
#include "debuggercore.h"
|
2011-11-03 12:01:50 +01:00
|
|
|
#include "shared/hostutils.h"
|
2009-10-07 10:25:26 +02:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2009-10-07 10:25:26 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMessageBox>
|
2009-10-07 10:25:26 +02:00
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
#define CB(callback) \
|
2012-06-13 10:15:56 +02:00
|
|
|
static_cast<GdbEngine::GdbCommandCallback>(&GdbTermEngine::callback), \
|
2009-10-07 10:25:26 +02:00
|
|
|
STRINGIFY(callback)
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// TermGdbAdapter
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-15 14:33:39 +02:00
|
|
|
GdbTermEngine::GdbTermEngine(const DebuggerStartParameters &startParameters)
|
|
|
|
|
: GdbEngine(startParameters)
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2011-12-28 15:24:05 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
// Windows up to xp needs a workaround for attaching to freshly started processes. see proc_stub_win
|
|
|
|
|
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) {
|
|
|
|
|
m_stubProc.setMode(Utils::ConsoleProcess::Suspend);
|
|
|
|
|
} else {
|
|
|
|
|
m_stubProc.setMode(Utils::ConsoleProcess::Debug);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2009-10-07 10:25:26 +02:00
|
|
|
m_stubProc.setMode(Utils::ConsoleProcess::Debug);
|
2012-01-24 15:36:40 +01:00
|
|
|
m_stubProc.setSettings(Core::ICore::settings());
|
2009-10-07 10:25:26 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
GdbTermEngine::~GdbTermEngine()
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
|
|
|
|
m_stubProc.disconnect(); // Avoid spurious state transitions from late exiting stub
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
GdbEngine::DumperHandling GdbTermEngine::dumperHandling() const
|
2009-11-03 14:06:21 +01:00
|
|
|
{
|
2009-11-12 16:49:12 +01:00
|
|
|
// LD_PRELOAD fails for System-Qt on Mac.
|
2012-08-23 15:53:58 +02:00
|
|
|
return Utils::HostOsInfo::isWindowsHost() || Utils::HostOsInfo::isMacHost()
|
|
|
|
|
? DumperLoadedByGdb
|
|
|
|
|
: DumperLoadedByAdapter; // Handles loading itself via LD_PRELOAD
|
2009-11-03 14:06:21 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::setupEngine()
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, 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);
|
|
|
|
|
|
2011-02-17 15:21:35 +01:00
|
|
|
if (!prepareCommand())
|
2010-10-19 11:14:03 +02:00
|
|
|
return;
|
|
|
|
|
|
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.
|
2010-10-19 11:14:03 +02:00
|
|
|
m_stubProc.setEnvironment(startParameters().environment);
|
2012-06-13 10:15:56 +02:00
|
|
|
|
|
|
|
|
connect(&m_stubProc, SIGNAL(processError(QString)), SLOT(stubError(QString)));
|
|
|
|
|
connect(&m_stubProc, SIGNAL(processStarted()), SLOT(stubStarted()));
|
|
|
|
|
connect(&m_stubProc, SIGNAL(wrapperStopped()), SLOT(stubExited()));
|
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.
|
2012-06-13 10:15:56 +02:00
|
|
|
|
2009-10-07 10:25:26 +02:00
|
|
|
if (!m_stubProc.start(startParameters().executable,
|
|
|
|
|
startParameters().processArgs)) {
|
|
|
|
|
// Error message for user is delivered via a signal.
|
2012-06-13 10:15:56 +02:00
|
|
|
handleAdapterStartFailed(QString());
|
2009-10-07 10:25:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2012-06-05 11:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::stubStarted()
|
2012-06-05 11:05:58 +02:00
|
|
|
{
|
2012-06-13 10:15:56 +02:00
|
|
|
startGdb();
|
2012-06-05 11:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::handleGdbStartFailed()
|
2012-06-05 11:05:58 +02:00
|
|
|
{
|
|
|
|
|
m_stubProc.stop();
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::setupInferior()
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2009-10-07 10:25:26 +02:00
|
|
|
const qint64 attachedPID = m_stubProc.applicationPID();
|
2010-09-02 16:46:39 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
const qint64 attachedMainThreadID = m_stubProc.applicationMainThreadID();
|
|
|
|
|
showMessage(QString::fromLatin1("Attaching to %1 (%2)").arg(attachedPID).arg(attachedMainThreadID), LogMisc);
|
|
|
|
|
#else
|
|
|
|
|
showMessage(QString::fromLatin1("Attaching to %1").arg(attachedPID), LogMisc);
|
|
|
|
|
#endif
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorPid(attachedPID);
|
|
|
|
|
postCommand("attach " + QByteArray::number(attachedPID),
|
2010-01-05 16:51:55 +01:00
|
|
|
CB(handleStubAttached));
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::handleStubAttached(const GdbResponse &response)
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2012-11-02 15:33:06 +01:00
|
|
|
|
2010-09-02 16:46:39 +02:00
|
|
|
switch (response.resultClass) {
|
|
|
|
|
case GdbResultDone:
|
|
|
|
|
case GdbResultRunning:
|
2012-11-02 15:33:06 +01:00
|
|
|
if (startParameters().toolChainAbi.os() != ProjectExplorer::Abi::WindowsOS) {
|
|
|
|
|
showMessage(_("INFERIOR ATTACHED"));
|
2010-09-02 16:46:39 +02:00
|
|
|
} else {
|
2012-11-02 15:33:06 +01:00
|
|
|
QString errorMessage;
|
|
|
|
|
// Resume thread that was suspended by console stub process (see stub code).
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
const qint64 mainThreadId = m_stubProc.applicationMainThreadID();
|
2010-09-02 16:46:39 +02:00
|
|
|
#else
|
2012-11-02 15:33:06 +01:00
|
|
|
const qint64 mainThreadId = -1;
|
|
|
|
|
#endif
|
|
|
|
|
if (winResumeThread(mainThreadId, &errorMessage)) {
|
|
|
|
|
showMessage(QString::fromLatin1("Inferior attached, thread %1 resumed").
|
|
|
|
|
arg(mainThreadId), LogMisc);
|
|
|
|
|
} else {
|
|
|
|
|
showMessage(QString::fromLatin1("Inferior attached, unable to resume thread %1: %2").
|
|
|
|
|
arg(mainThreadId).arg(errorMessage),
|
|
|
|
|
LogWarning);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-13 10:15:56 +02:00
|
|
|
handleInferiorPrepared();
|
2010-09-02 16:46:39 +02:00
|
|
|
break;
|
|
|
|
|
case GdbResultError:
|
2012-01-02 10:42:01 +01:00
|
|
|
if (response.data.findChild("msg").data() == "ptrace: Operation not permitted.") {
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(DumperHelper::msgPtraceError(startParameters().startMode));
|
2012-01-02 10:42:01 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(QString::fromLocal8Bit(response.data.findChild("msg").data()));
|
2010-09-02 16:46:39 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(QString::fromLatin1("Invalid response %1").arg(response.resultClass));
|
2010-09-02 16:46:39 +02:00
|
|
|
break;
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::runEngine()
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyEngineRunAndInferiorStopOk();
|
|
|
|
|
continueInferiorInternal();
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::interruptInferior2()
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2012-06-13 10:15:56 +02:00
|
|
|
interruptLocalInferior(inferiorPid());
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::stubError(const QString &msg)
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2010-11-10 16:33:11 +01:00
|
|
|
showMessageBox(QMessageBox::Critical, tr("Debugger Error"), msg);
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::stubExited()
|
2009-10-07 10:25:26 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
if (state() == EngineShutdownRequested || state() == DebuggerFinished) {
|
|
|
|
|
showMessage(_("STUB EXITED EXPECTEDLY"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("STUB EXITED"));
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyEngineIll();
|
2010-07-09 17:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbTermEngine::shutdownEngine()
|
2010-07-09 17:07:59 +02:00
|
|
|
{
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyAdapterShutdownOk();
|
2009-10-07 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|