2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-21 11:09:38 +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
|
2009-09-21 11:09:38 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-09-21 11:09:38 +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-09-21 11:09:38 +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-09-21 11:09:38 +02:00
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
#include "gdbplainengine.h"
|
2013-09-09 16:42:32 +02:00
|
|
|
#include "gdbprocess.h"
|
2013-01-24 10:38:40 +01:00
|
|
|
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <debugger/debuggeractions.h>
|
|
|
|
|
#include <debugger/debuggercore.h>
|
|
|
|
|
#include <debugger/debuggerprotocol.h>
|
|
|
|
|
#include <debugger/debuggerstartparameters.h>
|
|
|
|
|
#include <debugger/debuggerstringutils.h>
|
2009-09-21 11:09:38 +02:00
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2009-09-21 11:09:38 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
2009-09-21 11:09:38 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
#define CB(callback) \
|
2013-09-09 16:23:57 +02:00
|
|
|
static_cast<GdbEngine::GdbCommandCallback>(&GdbPlainEngine::callback), \
|
2009-09-21 11:09:38 +02:00
|
|
|
STRINGIFY(callback)
|
|
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
GdbPlainEngine::GdbPlainEngine(const DebuggerStartParameters &startParameters)
|
2012-08-15 14:33:39 +02:00
|
|
|
: GdbEngine(startParameters)
|
2013-09-09 16:23:57 +02:00
|
|
|
{
|
|
|
|
|
// Output
|
|
|
|
|
connect(&m_outputCollector, SIGNAL(byteDelivery(QByteArray)),
|
|
|
|
|
this, SLOT(readDebugeeOutput(QByteArray)));
|
|
|
|
|
}
|
2009-09-21 11:09:38 +02:00
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
|
|
|
|
|
void GdbPlainEngine::setupInferior()
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2010-01-05 16:51:55 +01:00
|
|
|
if (!startParameters().processArgs.isEmpty()) {
|
2010-10-19 11:14:03 +02:00
|
|
|
QString args = startParameters().processArgs;
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("-exec-arguments " + toLocalEncoding(args));
|
2010-01-05 16:51:55 +01:00
|
|
|
}
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("-file-exec-and-symbols \"" + execFilePath() + '"',
|
2012-05-29 12:01:29 +02:00
|
|
|
CB(handleFileExecAndSymbols));
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
void GdbPlainEngine::handleFileExecAndSymbols(const GdbResponse &response)
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2009-09-21 11:09:38 +02:00
|
|
|
if (response.resultClass == GdbResultDone) {
|
2012-06-13 10:15:56 +02:00
|
|
|
handleInferiorPrepared();
|
2009-10-12 12:00:07 +02:00
|
|
|
} else {
|
2013-05-03 18:26:10 +02:00
|
|
|
QByteArray ba = response.data["msg"].data();
|
2010-05-05 12:49:08 +02:00
|
|
|
QString msg = fromLocalEncoding(ba);
|
2010-03-22 14:21:47 +01:00
|
|
|
// Extend the message a bit in unknown cases.
|
|
|
|
|
if (!ba.endsWith("File format not recognized"))
|
|
|
|
|
msg = tr("Starting executable failed:\n") + msg;
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
void GdbPlainEngine::runEngine()
|
2011-01-19 10:48:39 +01:00
|
|
|
{
|
2013-09-12 18:46:35 +02:00
|
|
|
if (startParameters().useContinueInsteadOfRun)
|
|
|
|
|
postCommand("-exec-continue", GdbEngine::RunRequest, CB(handleExecuteContinue));
|
|
|
|
|
else
|
|
|
|
|
postCommand("-exec-run", GdbEngine::RunRequest, CB(handleExecRun));
|
2011-01-17 15:11:11 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
void GdbPlainEngine::handleExecRun(const GdbResponse &response)
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
2009-09-21 11:09:38 +02:00
|
|
|
if (response.resultClass == GdbResultRunning) {
|
2012-08-21 11:30:59 +02:00
|
|
|
//notifyEngineRunOkAndInferiorRunRequested();
|
|
|
|
|
notifyEngineRunAndInferiorRunOk(); // For gdb < 7.0
|
2010-07-09 17:07:59 +02:00
|
|
|
//showStatusMessage(tr("Running..."));
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("INFERIOR STARTED"));
|
2010-07-08 18:10:50 +02:00
|
|
|
showMessage(msgInferiorSetupOk(), StatusBar);
|
2010-03-11 11:07:16 +01:00
|
|
|
// FIXME: That's the wrong place for it.
|
2010-11-10 16:33:11 +01:00
|
|
|
if (debuggerCore()->boolSetting(EnableReverseDebugging))
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("target record");
|
2009-09-21 11:09:38 +02:00
|
|
|
} else {
|
2013-05-03 18:26:10 +02:00
|
|
|
QString msg = fromLocalEncoding(response.data["msg"].data());
|
2011-07-29 12:00:11 +02:00
|
|
|
//QTC_CHECK(status() == InferiorRunOk);
|
2009-09-21 11:09:38 +02:00
|
|
|
//interruptInferior();
|
2010-07-09 17:07:59 +02:00
|
|
|
showMessage(msg);
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyEngineRunFailed();
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-09 16:23:57 +02:00
|
|
|
GdbEngine::DumperHandling GdbPlainEngine::dumperHandling() const
|
|
|
|
|
{
|
|
|
|
|
// LD_PRELOAD fails for System-Qt on Mac.
|
|
|
|
|
return Utils::HostOsInfo::isWindowsHost() || Utils::HostOsInfo::isMacHost()
|
|
|
|
|
? DumperLoadedByGdb : DumperLoadedByGdbPreload;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbPlainEngine::setupEngine()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
|
|
|
|
showMessage(_("TRYING TO START ADAPTER"));
|
|
|
|
|
|
|
|
|
|
if (!prepareCommand())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QStringList gdbArgs;
|
|
|
|
|
|
|
|
|
|
if (!m_outputCollector.listen()) {
|
|
|
|
|
handleAdapterStartFailed(tr("Cannot set up communication with child process: %1")
|
|
|
|
|
.arg(m_outputCollector.errorString()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
gdbArgs.append(_("--tty=") + m_outputCollector.serverName());
|
|
|
|
|
|
|
|
|
|
if (!startParameters().workingDirectory.isEmpty())
|
2013-09-09 16:42:32 +02:00
|
|
|
m_gdbProc->setWorkingDirectory(startParameters().workingDirectory);
|
2013-09-09 16:23:57 +02:00
|
|
|
if (startParameters().environment.size())
|
2013-09-09 16:42:32 +02:00
|
|
|
m_gdbProc->setEnvironment(startParameters().environment.toStringList());
|
2013-09-09 16:23:57 +02:00
|
|
|
|
|
|
|
|
startGdb(gdbArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbPlainEngine::handleGdbStartFailed()
|
|
|
|
|
{
|
|
|
|
|
m_outputCollector.shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbPlainEngine::interruptInferior2()
|
|
|
|
|
{
|
|
|
|
|
interruptLocalInferior(inferiorPid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbPlainEngine::shutdownEngine()
|
|
|
|
|
{
|
|
|
|
|
showMessage(_("PLAIN ADAPTER SHUTDOWN %1").arg(state()));
|
|
|
|
|
m_outputCollector.shutdown();
|
|
|
|
|
notifyAdapterShutdownOk();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray GdbPlainEngine::execFilePath() const
|
|
|
|
|
{
|
|
|
|
|
return QFileInfo(startParameters().executable)
|
|
|
|
|
.absoluteFilePath().toLocal8Bit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray GdbPlainEngine::toLocalEncoding(const QString &s) const
|
|
|
|
|
{
|
|
|
|
|
return s.toLocal8Bit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString GdbPlainEngine::fromLocalEncoding(const QByteArray &b) const
|
|
|
|
|
{
|
|
|
|
|
return QString::fromLocal8Bit(b);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-21 11:09:38 +02:00
|
|
|
} // namespace Debugger
|
2010-05-05 12:49:08 +02:00
|
|
|
} // namespace Internal
|