2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-22 10:50:44 +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-22 10:50:44 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-09-22 10:50:44 +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-22 10:50:44 +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-22 10:50:44 +02:00
|
|
|
|
2010-05-05 12:49:08 +02:00
|
|
|
#include "remotegdbserveradapter.h"
|
2010-11-10 16:33:11 +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>
|
2015-06-08 12:10:11 +02:00
|
|
|
#include <debugger/procinterrupt.h>
|
2009-09-22 10:50:44 +02:00
|
|
|
|
2014-11-25 13:08:18 +01:00
|
|
|
#include <coreplugin/messagebox.h>
|
|
|
|
|
|
2012-08-31 16:39:20 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2009-09-22 10:50:44 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2012-11-06 08:20:42 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2009-09-22 10:50:44 +02:00
|
|
|
|
2016-06-13 16:04:19 +02:00
|
|
|
#include <QAbstractButton>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
2016-06-13 16:04:19 +02:00
|
|
|
#include <QMessageBox>
|
2009-09-22 10:50:44 +02:00
|
|
|
|
2015-02-12 13:50:54 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2009-09-22 10:50:44 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-02-05 22:46:09 +01:00
|
|
|
#define CB(callback) [this](const DebuggerResponse &r) { callback(r); }
|
2009-09-22 10:50:44 +02:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// RemoteGdbAdapter
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-06-26 13:06:08 +02:00
|
|
|
GdbRemoteServerEngine::GdbRemoteServerEngine(const DebuggerRunParameters &runParameters)
|
|
|
|
|
: GdbEngine(runParameters), m_startAttempted(false)
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2015-02-12 13:50:54 +01:00
|
|
|
if (HostOsInfo::isWindowsHost())
|
2015-06-26 13:06:08 +02:00
|
|
|
m_gdbProc.setUseCtrlCStub(runParameters.useCtrlCStub); // This is only set for QNX/BlackBerry
|
2015-02-12 13:50:54 +01:00
|
|
|
|
2016-08-03 19:43:54 +03:00
|
|
|
connect(&m_uploadProc, &QProcess::errorOccurred, this, &GdbRemoteServerEngine::uploadProcError);
|
2015-01-29 18:37:56 +01:00
|
|
|
connect(&m_uploadProc, &QProcess::readyReadStandardOutput,
|
|
|
|
|
this, &GdbRemoteServerEngine::readUploadStandardOutput);
|
|
|
|
|
connect(&m_uploadProc, &QProcess::readyReadStandardError,
|
|
|
|
|
this, &GdbRemoteServerEngine::readUploadStandardError);
|
|
|
|
|
connect(&m_uploadProc, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
|
|
|
|
|
this, &GdbRemoteServerEngine::uploadProcFinished);
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::setupEngine()
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("TRYING TO START ADAPTER");
|
2015-07-17 13:56:37 +02:00
|
|
|
QString serverStartScript = runParameters().serverStartScript;
|
|
|
|
|
if (!serverStartScript.isEmpty()) {
|
2012-11-06 08:20:42 +01:00
|
|
|
|
|
|
|
|
// Provide script information about the environment
|
|
|
|
|
QString arglist;
|
2015-07-17 13:56:37 +02:00
|
|
|
QtcProcess::addArg(&arglist, serverStartScript);
|
2016-01-28 10:31:24 +01:00
|
|
|
QtcProcess::addArg(&arglist, runParameters().inferior.executable);
|
2015-05-27 13:59:56 +02:00
|
|
|
QtcProcess::addArg(&arglist, runParameters().remoteChannel);
|
2012-11-06 08:20:42 +01:00
|
|
|
|
2015-07-17 13:56:37 +02:00
|
|
|
m_uploadProc.start(arglist);
|
2012-08-14 10:16:53 +02:00
|
|
|
m_uploadProc.waitForStarted();
|
2009-09-22 12:10:12 +02:00
|
|
|
}
|
2013-03-21 10:13:36 +02:00
|
|
|
|
2015-07-17 13:56:37 +02:00
|
|
|
if (runParameters().remoteSetupNeeded) {
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyEngineRequestRemoteSetup();
|
2015-07-17 13:56:37 +02:00
|
|
|
} else {
|
|
|
|
|
m_startAttempted = true;
|
2012-06-13 10:15:56 +02:00
|
|
|
startGdb();
|
2015-07-17 13:56:37 +02:00
|
|
|
}
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::uploadProcError(QProcess::ProcessError error)
|
2009-09-22 11:31:34 +02:00
|
|
|
{
|
|
|
|
|
QString msg;
|
|
|
|
|
switch (error) {
|
|
|
|
|
case QProcess::FailedToStart:
|
2009-10-20 17:43:23 +02:00
|
|
|
msg = tr("The upload process failed to start. Shell missing?");
|
2009-09-22 11:31:34 +02:00
|
|
|
break;
|
|
|
|
|
case QProcess::Crashed:
|
|
|
|
|
msg = tr("The upload process crashed some time after starting "
|
|
|
|
|
"successfully.");
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::Timedout:
|
|
|
|
|
msg = tr("The last waitFor...() function timed out. "
|
|
|
|
|
"The state of QProcess is unchanged, and you can try calling "
|
|
|
|
|
"waitFor...() again.");
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::WriteError:
|
|
|
|
|
msg = tr("An error occurred when attempting to write "
|
|
|
|
|
"to the upload process. For example, the process may not be running, "
|
|
|
|
|
"or it may have closed its input channel.");
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::ReadError:
|
|
|
|
|
msg = tr("An error occurred when attempting to read from "
|
|
|
|
|
"the upload process. For example, the process may not be running.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
msg = tr("An unknown error in the upload process occurred. "
|
|
|
|
|
"This is the default return value of error().");
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(msg, StatusBar);
|
2014-11-25 13:08:18 +01:00
|
|
|
Core::AsynchronousMessageBox::critical(tr("Error"), msg);
|
2009-09-22 11:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::readUploadStandardOutput()
|
2009-09-22 11:31:34 +02:00
|
|
|
{
|
2010-06-14 18:19:02 +02:00
|
|
|
const QByteArray ba = m_uploadProc.readAllStandardOutput();
|
|
|
|
|
const QString msg = QString::fromLocal8Bit(ba, ba.length());
|
|
|
|
|
showMessage(msg, LogOutput);
|
|
|
|
|
showMessage(msg, AppOutput);
|
2009-09-22 11:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::readUploadStandardError()
|
2009-09-22 11:31:34 +02:00
|
|
|
{
|
2010-06-14 18:19:02 +02:00
|
|
|
const QByteArray ba = m_uploadProc.readAllStandardError();
|
|
|
|
|
const QString msg = QString::fromLocal8Bit(ba, ba.length());
|
|
|
|
|
showMessage(msg, LogOutput);
|
|
|
|
|
showMessage(msg, AppError);
|
2009-09-22 11:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::uploadProcFinished()
|
2010-07-15 16:43:56 +02:00
|
|
|
{
|
2014-09-18 20:19:59 +02:00
|
|
|
if (m_uploadProc.exitStatus() == QProcess::NormalExit && m_uploadProc.exitCode() == 0) {
|
2015-07-17 13:56:37 +02:00
|
|
|
if (!m_startAttempted)
|
|
|
|
|
startGdb();
|
2014-09-18 19:21:27 +02:00
|
|
|
} else {
|
|
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = false;
|
|
|
|
|
result.reason = m_uploadProc.errorString();
|
|
|
|
|
notifyEngineRemoteSetupFinished(result);
|
|
|
|
|
}
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::setupInferior()
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2016-04-07 12:34:19 +03:00
|
|
|
setLinuxOsAbi();
|
2015-05-27 13:59:56 +02:00
|
|
|
const DebuggerRunParameters &rp = runParameters();
|
2016-04-21 12:44:11 +02:00
|
|
|
QString symbolFile;
|
|
|
|
|
if (!rp.symbolFile.isEmpty()) {
|
|
|
|
|
QFileInfo fi(rp.symbolFile);
|
|
|
|
|
symbolFile = fi.absoluteFilePath();
|
2010-09-06 14:26:19 +02:00
|
|
|
}
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
//const QByteArray sysroot = sp.sysroot.toLocal8Bit();
|
|
|
|
|
//const QByteArray remoteArch = sp.remoteArchitecture.toLatin1();
|
2016-01-28 10:31:24 +01:00
|
|
|
const QString args = isMasterEngine() ? runParameters().inferior.commandLineArguments
|
|
|
|
|
: masterEngine()->runParameters().inferior.commandLineArguments;
|
2012-06-13 10:15:56 +02:00
|
|
|
|
|
|
|
|
// if (!remoteArch.isEmpty())
|
|
|
|
|
// postCommand("set architecture " + remoteArch);
|
2015-05-27 13:59:56 +02:00
|
|
|
const QString solibSearchPath = rp.solibSearchPath.join(HostOsInfo::pathListSeparator());
|
2012-04-18 20:30:57 +03:00
|
|
|
if (!solibSearchPath.isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"set solib-search-path " + solibSearchPath, NoFlags});
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2010-09-07 13:22:12 +02:00
|
|
|
if (!args.isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"-exec-arguments " + args, NoFlags});
|
2009-09-24 10:54:27 +02:00
|
|
|
|
2015-07-15 10:38:15 +03:00
|
|
|
setEnvironmentVariables();
|
|
|
|
|
|
2010-09-08 11:54:33 +02:00
|
|
|
// This has to be issued before 'target remote'. On pre-7.0 the
|
|
|
|
|
// command is not present and will result in ' No symbol table is
|
2010-11-01 14:14:17 +01:00
|
|
|
// loaded. Use the "file" command.' as gdb tries to set the
|
2010-09-08 11:54:33 +02:00
|
|
|
// value of a variable with name 'target-async'.
|
|
|
|
|
//
|
|
|
|
|
// Testing with -list-target-features which was introduced at
|
|
|
|
|
// the same time would not work either, as this need an existing
|
|
|
|
|
// target.
|
|
|
|
|
//
|
|
|
|
|
// Using it even without a target and having it fail might still
|
|
|
|
|
// be better as:
|
|
|
|
|
// Some external comment: '[but] "set target-async on" with a native
|
|
|
|
|
// windows gdb will work, but then fail when you actually do
|
|
|
|
|
// "run"/"attach", I think..
|
2011-09-26 18:43:26 +02:00
|
|
|
|
|
|
|
|
|
2011-09-29 18:53:16 +02:00
|
|
|
// gdb/mi/mi-main.c:1958: internal-error:
|
2011-09-26 18:43:26 +02:00
|
|
|
// mi_execute_async_cli_command: Assertion `is_running (inferior_ptid)'
|
|
|
|
|
// failed.\nA problem internal to GDB has been detected,[...]
|
2016-04-19 14:01:44 +02:00
|
|
|
if (usesTargetAsync())
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"set target-async on", NoFlags, CB(handleSetTargetAsync)});
|
2010-09-06 14:26:19 +02:00
|
|
|
|
2016-04-21 12:44:11 +02:00
|
|
|
if (symbolFile.isEmpty()) {
|
2010-09-06 14:26:19 +02:00
|
|
|
showMessage(tr("No symbol file given."), StatusBar);
|
|
|
|
|
callTargetRemote();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-21 12:44:11 +02:00
|
|
|
if (!symbolFile.isEmpty()) {
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"-file-exec-and-symbols \"" + symbolFile + '"',
|
2015-11-03 12:01:57 +01:00
|
|
|
NoFlags, CB(handleFileExecAndSymbols)});
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
2009-10-01 17:13:27 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleSetTargetAsync(const DebuggerResponse &response)
|
2009-10-01 17:13:27 +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 == ResultError)
|
2009-10-16 15:05:30 +02:00
|
|
|
qDebug() << "Adapter too old: does not support asynchronous mode.";
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
|
2009-09-22 10:50:44 +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) {
|
2010-09-06 14:26:19 +02:00
|
|
|
callTargetRemote();
|
2009-10-12 12:00:07 +02:00
|
|
|
} else {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString reason = response.data["msg"].data();
|
|
|
|
|
QString msg = tr("Reading debug information failed:") + '\n' + reason;
|
2012-03-27 08:05:07 +02:00
|
|
|
if (reason.endsWith("No such file or directory.")) {
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("INFERIOR STARTUP: BINARY NOT FOUND");
|
2012-03-27 08:05:07 +02:00
|
|
|
showMessage(msg, StatusBar);
|
|
|
|
|
callTargetRemote(); // Proceed nevertheless.
|
|
|
|
|
} else {
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
2012-03-27 08:05:07 +02:00
|
|
|
}
|
2009-09-24 10:54:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::callTargetRemote()
|
2010-09-06 14:26:19 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
QString channel = runParameters().remoteChannel;
|
2012-02-29 17:14:03 +01:00
|
|
|
|
|
|
|
|
// Don't touch channels with explicitly set protocols.
|
|
|
|
|
if (!channel.startsWith("tcp:") && !channel.startsWith("udp:")
|
2014-06-05 11:24:30 +02:00
|
|
|
&& !channel.startsWith("file:") && channel.contains(':')
|
|
|
|
|
&& !channel.startsWith('|'))
|
2012-02-29 17:14:03 +01:00
|
|
|
{
|
|
|
|
|
// "Fix" the IPv6 case with host names without '['...']'
|
|
|
|
|
if (!channel.startsWith('[') && channel.count(':') >= 2) {
|
|
|
|
|
channel.insert(0, '[');
|
|
|
|
|
channel.insert(channel.lastIndexOf(':'), ']');
|
|
|
|
|
}
|
|
|
|
|
channel = "tcp:" + channel;
|
2012-02-10 07:42:44 +01:00
|
|
|
}
|
2012-02-29 17:14:03 +01:00
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
if (m_isQnxGdb)
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"target qnx " + channel, NoFlags, CB(handleTargetQnx)});
|
2016-11-16 13:02:22 +01:00
|
|
|
else if (runParameters().useExtendedRemote)
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"target extended-remote " + channel, NoFlags, CB(handleTargetExtendedRemote)});
|
2012-02-29 17:14:03 +01:00
|
|
|
else
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"target remote " + channel, NoFlags, CB(handleTargetRemote)});
|
2010-09-06 14:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleTargetRemote(const DebuggerResponse &response)
|
2009-09-24 10:54:27 +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) {
|
2009-10-01 17:13:27 +02:00
|
|
|
// gdb server will stop the remote application itself.
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("INFERIOR STARTED");
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
2016-06-13 16:39:37 +02:00
|
|
|
QString commands = expand(stringSetting(GdbPostAttachCommands));
|
|
|
|
|
if (!commands.isEmpty())
|
|
|
|
|
runCommand({commands, NoFlags});
|
2012-06-13 10:15:56 +02:00
|
|
|
handleInferiorPrepared();
|
2009-10-12 12:00:07 +02:00
|
|
|
} else {
|
2009-09-24 10:54:27 +02:00
|
|
|
// 16^error,msg="hd:5555: Connection timed out."
|
2016-06-07 17:04:53 +02:00
|
|
|
notifyInferiorSetupFailed(msgConnectRemoteServerFailed(response.data["msg"].data()));
|
2013-02-27 15:12:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleTargetExtendedRemote(const DebuggerResponse &response)
|
2013-02-27 15:12:36 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2015-02-05 15:47:07 +01:00
|
|
|
if (response.resultClass == ResultDone) {
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("ATTACHED TO GDB SERVER STARTED");
|
2013-02-27 15:12:36 +01:00
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
2016-06-13 16:39:37 +02:00
|
|
|
QString commands = expand(stringSetting(GdbPostAttachCommands));
|
|
|
|
|
if (!commands.isEmpty())
|
|
|
|
|
runCommand({commands, NoFlags});
|
2015-05-27 13:59:56 +02:00
|
|
|
if (runParameters().attachPID > 0) { // attach to pid if valid
|
2014-06-05 15:10:43 +02:00
|
|
|
// gdb server will stop the remote application itself.
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"attach " + QString::number(runParameters().attachPID),
|
2015-11-03 12:01:57 +01:00
|
|
|
NoFlags, CB(handleTargetExtendedAttach)});
|
2016-06-13 16:04:19 +02:00
|
|
|
} else if (!runParameters().inferior.executable.isEmpty()) {
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"-gdb-set remote exec-file " + runParameters().inferior.executable,
|
2015-11-03 12:01:57 +01:00
|
|
|
NoFlags, CB(handleTargetExtendedAttach)});
|
2016-06-13 16:04:19 +02:00
|
|
|
} else {
|
|
|
|
|
const QString title = tr("No Remote Executable or Process ID Specified");
|
|
|
|
|
const QString msg = tr(
|
|
|
|
|
"No remote executable could be determined from your build system files.<p>"
|
|
|
|
|
"In case you use qmake, consider adding<p>"
|
|
|
|
|
" target.path = /tmp/your_executable # path on device<br>"
|
|
|
|
|
" INSTALLS += target</p>"
|
|
|
|
|
"to your .pro file.");
|
|
|
|
|
QMessageBox *mb = showMessageBox(QMessageBox::Critical, title, msg,
|
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
|
mb->button(QMessageBox::Cancel)->setText(tr("Continue Debugging"));
|
|
|
|
|
mb->button(QMessageBox::Ok)->setText(tr("Stop Debugging"));
|
|
|
|
|
if (mb->exec() == QMessageBox::Ok) {
|
|
|
|
|
showMessage("KILLING DEBUGGER AS REQUESTED BY USER");
|
|
|
|
|
notifyInferiorSetupFailed(title);
|
|
|
|
|
} else {
|
|
|
|
|
showMessage("CONTINUE DEBUGGER AS REQUESTED BY USER");
|
|
|
|
|
handleInferiorPrepared(); // This will likely fail.
|
|
|
|
|
}
|
2014-06-05 15:10:43 +02:00
|
|
|
}
|
2013-02-27 15:12:36 +01:00
|
|
|
} else {
|
2016-06-07 17:04:53 +02:00
|
|
|
notifyInferiorSetupFailed(msgConnectRemoteServerFailed(response.data["msg"].data()));
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleTargetExtendedAttach(const DebuggerResponse &response)
|
2013-02-27 15:12:36 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2015-02-05 15:47:07 +01:00
|
|
|
if (response.resultClass == ResultDone) {
|
2013-02-27 15:12:36 +01:00
|
|
|
// gdb server will stop the remote application itself.
|
|
|
|
|
handleInferiorPrepared();
|
|
|
|
|
} else {
|
2016-06-07 17:04:53 +02:00
|
|
|
notifyInferiorSetupFailed(msgConnectRemoteServerFailed(response.data["msg"].data()));
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleTargetQnx(const DebuggerResponse &response)
|
2012-02-10 07:42:44 +01:00
|
|
|
{
|
2012-06-13 10:15:56 +02:00
|
|
|
QTC_ASSERT(m_isQnxGdb, qDebug() << m_isQnxGdb);
|
2012-02-10 07:42:44 +01:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2015-02-05 15:47:07 +01:00
|
|
|
if (response.resultClass == ResultDone) {
|
2012-02-10 07:42:44 +01:00
|
|
|
// gdb server will stop the remote application itself.
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("INFERIOR STARTED");
|
2012-02-10 07:42:44 +01:00
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
|
|
|
|
|
2016-04-21 12:44:11 +02:00
|
|
|
const DebuggerRunParameters &rp = isMasterEngine() ? runParameters() : masterEngine()->runParameters();
|
|
|
|
|
const qint64 pid = rp.attachPID;
|
|
|
|
|
const QString remoteExecutable = rp.inferior.executable;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (pid > -1)
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"attach " + QString::number(pid), NoFlags, CB(handleAttach)});
|
2013-11-01 15:39:59 +01:00
|
|
|
else if (!remoteExecutable.isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
runCommand({"set nto-executable " + remoteExecutable, NoFlags, CB(handleSetNtoExecutable)});
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2012-06-13 10:15:56 +02:00
|
|
|
handleInferiorPrepared();
|
2012-02-10 07:42:44 +01:00
|
|
|
} else {
|
|
|
|
|
// 16^error,msg="hd:5555: Connection timed out."
|
2016-06-07 17:04:53 +02:00
|
|
|
notifyInferiorSetupFailed(response.data["msg"].data());
|
2012-02-10 07:42:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleAttach(const DebuggerResponse &response)
|
2012-02-10 07:42:44 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
|
|
|
|
switch (response.resultClass) {
|
2015-02-05 15:47:07 +01:00
|
|
|
case ResultDone:
|
|
|
|
|
case ResultRunning: {
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("INFERIOR ATTACHED");
|
2012-02-10 07:42:44 +01:00
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
2012-06-13 10:15:56 +02:00
|
|
|
handleInferiorPrepared();
|
2012-02-10 07:42:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2015-02-05 15:47:07 +01:00
|
|
|
case ResultError:
|
2013-05-03 18:26:10 +02:00
|
|
|
if (response.data["msg"].data() == "ptrace: Operation not permitted.") {
|
2015-05-27 13:59:56 +02:00
|
|
|
notifyInferiorSetupFailed(msgPtraceError(runParameters().startMode));
|
2012-02-10 07:42:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// if msg != "ptrace: ..." fall through
|
|
|
|
|
default:
|
2016-06-07 17:04:53 +02:00
|
|
|
notifyInferiorSetupFailed(response.data["msg"].data());
|
2012-02-10 07:42:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleSetNtoExecutable(const DebuggerResponse &response)
|
2013-11-01 15:39:59 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
|
|
|
|
switch (response.resultClass) {
|
2015-02-05 15:47:07 +01:00
|
|
|
case ResultDone:
|
|
|
|
|
case ResultRunning: {
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("EXECUTABLE SET");
|
2013-11-01 15:39:59 +01:00
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
|
|
|
|
handleInferiorPrepared();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-02-05 15:47:07 +01:00
|
|
|
case ResultError:
|
2013-11-01 15:39:59 +01:00
|
|
|
default:
|
2016-06-07 17:04:53 +02:00
|
|
|
notifyInferiorSetupFailed(response.data["msg"].data());
|
2013-11-01 15:39:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::runEngine()
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2010-07-20 12:14:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2016-04-21 14:59:00 +02:00
|
|
|
if (runParameters().useContinueInsteadOfRun) {
|
2012-06-29 07:23:13 +02:00
|
|
|
notifyEngineRunAndInferiorStopOk();
|
|
|
|
|
continueInferiorInternal();
|
2016-04-21 14:59:00 +02:00
|
|
|
} else {
|
|
|
|
|
runCommand({"-exec-run", RunRequest, CB(handleExecRun)});
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleExecRun(const DebuggerResponse &response)
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
2015-02-05 15:47:07 +01:00
|
|
|
if (response.resultClass == ResultRunning) {
|
2012-06-29 07:23:13 +02:00
|
|
|
notifyEngineRunAndInferiorRunOk();
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("INFERIOR STARTED");
|
2012-06-29 07:23:13 +02:00
|
|
|
showMessage(msgInferiorSetupOk(), StatusBar);
|
|
|
|
|
} else {
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage(response.data["msg"].data());
|
2012-06-29 07:23:13 +02:00
|
|
|
notifyEngineRunFailed();
|
|
|
|
|
}
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::interruptInferior2()
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2010-11-26 14:23:52 +01:00
|
|
|
QTC_ASSERT(state() == InferiorStopRequested, qDebug() << state());
|
2016-04-19 14:01:44 +02:00
|
|
|
if (usesTargetAsync()) {
|
2015-11-03 12:01:57 +01:00
|
|
|
runCommand({"-exec-interrupt", NoFlags, CB(handleInterruptInferior)});
|
2015-02-12 13:50:54 +01:00
|
|
|
} else if (m_isQnxGdb && HostOsInfo::isWindowsHost()) {
|
2015-06-08 12:10:11 +02:00
|
|
|
m_gdbProc.interrupt();
|
2011-10-19 11:52:26 +02:00
|
|
|
} else {
|
2015-09-11 13:13:04 +02:00
|
|
|
qint64 pid = m_gdbProc.processId();
|
2015-06-08 12:10:11 +02:00
|
|
|
bool ok = interruptProcess(pid, GdbEngineType, &m_errorString);
|
2011-10-19 11:52:26 +02:00
|
|
|
if (!ok) {
|
|
|
|
|
// FIXME: Extra state needed?
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("NOTE: INFERIOR STOP NOT POSSIBLE");
|
2012-06-13 10:15:56 +02:00
|
|
|
showStatusMessage(tr("Interrupting not possible"));
|
|
|
|
|
notifyInferiorRunOk();
|
2011-10-19 11:52:26 +02:00
|
|
|
}
|
2011-10-12 16:34:02 +02:00
|
|
|
}
|
2010-11-26 14:23:52 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 15:47:07 +01:00
|
|
|
void GdbRemoteServerEngine::handleInterruptInferior(const DebuggerResponse &response)
|
2010-11-26 14:23:52 +01:00
|
|
|
{
|
2015-02-05 15:47:07 +01:00
|
|
|
if (response.resultClass == ResultDone) {
|
2010-11-26 14:23:52 +01:00
|
|
|
// The gdb server will trigger extra output that we will pick up
|
|
|
|
|
// to do a proper state transition.
|
|
|
|
|
} else {
|
|
|
|
|
// FIXME: On some gdb versions like git 170ffa5d7dd this produces
|
|
|
|
|
// >810^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorStopOk();
|
2010-11-26 14:23:52 +01:00
|
|
|
}
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::shutdownEngine()
|
2010-07-09 17:07:59 +02:00
|
|
|
{
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyAdapterShutdownOk();
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2013-02-27 15:12:36 +01:00
|
|
|
void GdbRemoteServerEngine::notifyEngineRemoteServerRunning
|
2016-06-13 15:27:17 +02:00
|
|
|
(const QString &serverChannel, int inferiorPid)
|
2013-02-27 15:12:36 +01:00
|
|
|
{
|
2014-09-18 20:19:59 +02:00
|
|
|
// Currently only used by Android support.
|
2015-05-27 13:59:56 +02:00
|
|
|
runParameters().attachPID = inferiorPid;
|
2016-06-13 15:27:17 +02:00
|
|
|
runParameters().remoteChannel = serverChannel;
|
2016-11-16 13:02:22 +01:00
|
|
|
runParameters().useExtendedRemote = true;
|
2016-06-07 17:04:53 +02:00
|
|
|
showMessage("NOTE: REMOTE SERVER RUNNING IN MULTIMODE");
|
2014-09-18 20:01:19 +02:00
|
|
|
m_startAttempted = true;
|
2013-02-27 15:12:36 +01:00
|
|
|
startGdb();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 19:21:27 +02:00
|
|
|
void GdbRemoteServerEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &result)
|
2010-07-15 16:43:56 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
2014-12-05 17:42:20 +01:00
|
|
|
GdbEngine::notifyEngineRemoteSetupFinished(result);
|
2014-09-18 19:21:27 +02:00
|
|
|
|
2014-09-18 20:19:59 +02:00
|
|
|
if (result.success) {
|
|
|
|
|
if (!m_startAttempted)
|
|
|
|
|
startGdb();
|
|
|
|
|
} else {
|
2014-09-18 19:21:27 +02:00
|
|
|
handleAdapterStartFailed(result.reason);
|
|
|
|
|
}
|
2012-06-05 11:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
2009-09-22 10:50:44 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|