2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-21 11:09:38 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-09-21 11:09:38 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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-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>
|
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 {
|
|
|
|
|
|
2015-02-06 01:26:47 +01:00
|
|
|
#define CB(callback) [this](const DebuggerResponse &r) { callback(r); }
|
2009-09-21 11:09:38 +02:00
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
GdbPlainEngine::GdbPlainEngine(const DebuggerRunParameters &startParameters)
|
2012-08-15 14:33:39 +02:00
|
|
|
: GdbEngine(startParameters)
|
2013-09-09 16:23:57 +02:00
|
|
|
{
|
|
|
|
|
// Output
|
2015-02-12 13:50:54 +01:00
|
|
|
connect(&m_outputCollector, &OutputCollector::byteDelivery,
|
2016-06-07 17:04:53 +02:00
|
|
|
this, &GdbEngine::readDebuggeeOutput);
|
2013-09-09 16:23:57 +02:00
|
|
|
}
|
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());
|
2015-07-15 10:38:15 +03:00
|
|
|
setEnvironmentVariables();
|
2016-01-28 10:31:24 +01:00
|
|
|
if (!runParameters().inferior.commandLineArguments.isEmpty()) {
|
|
|
|
|
QString args = runParameters().inferior.commandLineArguments;
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"-exec-arguments " + args, NoFlags});
|
2010-01-05 16:51:55 +01:00
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
|
|
|
|
|
QString executable = QFileInfo(runParameters().inferior.executable).absoluteFilePath();
|
|
|
|
|
runCommand({"-file-exec-and-symbols \"" + executable + '"', NoFlags,
|
2015-11-03 12:01:57 +01:00
|
|
|
CB(handleFileExecAndSymbols)});
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbPlainEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2015-02-05 15:47:07 +01:00
|
|
|
if (response.resultClass == ResultDone) {
|
2012-06-13 10:15:56 +02:00
|
|
|
handleInferiorPrepared();
|
2009-10-12 12:00:07 +02:00
|
|
|
} else {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString msg = response.data["msg"].data();
|
2010-03-22 14:21:47 +01:00
|
|
|
// Extend the message a bit in unknown cases.
|
2016-06-07 17:04:53 +02:00
|
|
|
if (!msg.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
|
|
|
{
|
2015-05-27 13:59:56 +02:00
|
|
|
if (runParameters().useContinueInsteadOfRun)
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"-exec-continue", RunRequest, CB(handleExecuteContinue)});
|
2013-09-12 18:46:35 +02:00
|
|
|
else
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"-exec-run", RunRequest, CB(handleExecRun)});
|
2011-01-17 15:11:11 +01:00
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbPlainEngine::handleExecRun(const DebuggerResponse &response)
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
2015-02-05 15:47:07 +01:00
|
|
|
if (response.resultClass == ResultRunning) {
|
2012-08-21 11:30:59 +02:00
|
|
|
notifyEngineRunAndInferiorRunOk(); // For gdb < 7.0
|
2010-07-09 17:07:59 +02:00
|
|
|
//showStatusMessage(tr("Running..."));
|
2016-06-07 17:04:53 +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.
|
2014-07-28 14:23:52 +02:00
|
|
|
if (boolSetting(EnableReverseDebugging))
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"target record", NoFlags});
|
2009-09-21 11:09:38 +02:00
|
|
|
} else {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString msg = 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
|
|
|
void GdbPlainEngine::setupEngine()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("TRYING TO START ADAPTER");
|
2013-09-09 16:23:57 +02:00
|
|
|
|
|
|
|
|
if (!prepareCommand())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QStringList gdbArgs;
|
|
|
|
|
|
|
|
|
|
if (!m_outputCollector.listen()) {
|
|
|
|
|
handleAdapterStartFailed(tr("Cannot set up communication with child process: %1")
|
|
|
|
|
.arg(m_outputCollector.errorString()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
gdbArgs.append("--tty=" + m_outputCollector.serverName());
|
2013-09-09 16:23:57 +02:00
|
|
|
|
|
|
|
|
startGdb(gdbArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbPlainEngine::handleGdbStartFailed()
|
|
|
|
|
{
|
|
|
|
|
m_outputCollector.shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbPlainEngine::interruptInferior2()
|
|
|
|
|
{
|
|
|
|
|
interruptLocalInferior(inferiorPid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbPlainEngine::shutdownEngine()
|
|
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage(QString("PLAIN ADAPTER SHUTDOWN %1").arg(state()));
|
2013-09-09 16:23:57 +02:00
|
|
|
m_outputCollector.shutdown();
|
|
|
|
|
notifyAdapterShutdownOk();
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-21 11:09:38 +02:00
|
|
|
} // namespace Debugger
|
2010-05-05 12:49:08 +02:00
|
|
|
} // namespace Internal
|