2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-22 10:50:44 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2009-09-22 10:50:44 +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
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company 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-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-09-09 16:42:32 +02:00
|
|
|
#include "gdbprocess.h"
|
|
|
|
|
|
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-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
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
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
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-15 14:33:39 +02:00
|
|
|
GdbRemoteServerEngine::GdbRemoteServerEngine(const DebuggerStartParameters &startParameters)
|
2014-12-05 17:42:20 +01:00
|
|
|
: GdbEngine(startParameters), m_startAttempted(false)
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2015-02-12 13:50:54 +01:00
|
|
|
if (HostOsInfo::isWindowsHost())
|
2014-04-08 09:26:41 +02:00
|
|
|
m_gdbProc->setUseCtrlCStub(startParameters.useCtrlCStub); // This is only set for QNX/BlackBerry
|
2015-02-12 13:50:54 +01:00
|
|
|
|
2015-01-29 18:37:56 +01:00
|
|
|
connect(&m_uploadProc, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
|
|
|
|
|
this, &GdbRemoteServerEngine::uploadProcError);
|
|
|
|
|
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());
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("TRYING TO START ADAPTER"));
|
2012-08-14 10:16:53 +02:00
|
|
|
if (!startParameters().serverStartScript.isEmpty()) {
|
2012-11-06 08:20:42 +01:00
|
|
|
|
|
|
|
|
// Provide script information about the environment
|
|
|
|
|
QString arglist;
|
2015-02-12 13:50:54 +01:00
|
|
|
QtcProcess::addArg(&arglist, startParameters().serverStartScript);
|
|
|
|
|
QtcProcess::addArg(&arglist, startParameters().executable);
|
|
|
|
|
QtcProcess::addArg(&arglist, startParameters().remoteChannel);
|
2012-11-06 08:20:42 +01:00
|
|
|
|
|
|
|
|
m_uploadProc.start(_("/bin/sh ") + 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
|
|
|
if (!startParameters().workingDirectory.isEmpty())
|
2013-09-09 16:42:32 +02:00
|
|
|
m_gdbProc->setWorkingDirectory(startParameters().workingDirectory);
|
2013-03-21 10:13:36 +02:00
|
|
|
if (startParameters().environment.size())
|
2013-09-09 16:42:32 +02:00
|
|
|
m_gdbProc->setEnvironment(startParameters().environment.toStringList());
|
2013-03-21 10:13:36 +02:00
|
|
|
|
2012-06-13 11:29:26 +02:00
|
|
|
if (startParameters().remoteSetupNeeded)
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyEngineRequestRemoteSetup();
|
2012-01-23 14:57:51 +01:00
|
|
|
else
|
2012-06-13 10:15:56 +02:00
|
|
|
startGdb();
|
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) {
|
2012-06-13 10:15:56 +02:00
|
|
|
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());
|
2011-09-14 17:01:57 +02:00
|
|
|
const DebuggerStartParameters &sp = startParameters();
|
2012-06-29 07:23:13 +02:00
|
|
|
QString executableFileName;
|
2011-09-14 17:01:57 +02:00
|
|
|
if (!sp.executable.isEmpty()) {
|
|
|
|
|
QFileInfo fi(sp.executable);
|
2012-06-29 07:23:13 +02:00
|
|
|
executableFileName = 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();
|
2015-02-12 13:50:54 +01:00
|
|
|
const QString args = isMasterEngine() ? startParameters().processArgs
|
|
|
|
|
: masterEngine()->startParameters().processArgs;
|
2012-06-13 10:15:56 +02:00
|
|
|
|
|
|
|
|
// if (!remoteArch.isEmpty())
|
|
|
|
|
// postCommand("set architecture " + remoteArch);
|
2015-02-12 13:50:54 +01:00
|
|
|
const QString solibSearchPath = sp.solibSearchPath.join(HostOsInfo::pathListSeparator());
|
2012-04-18 20:30:57 +03:00
|
|
|
if (!solibSearchPath.isEmpty())
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("set solib-search-path " + solibSearchPath.toLocal8Bit());
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2010-09-07 13:22:12 +02:00
|
|
|
if (!args.isEmpty())
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("-exec-arguments " + args.toLocal8Bit());
|
2009-09-24 10:54:27 +02:00
|
|
|
|
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,[...]
|
2014-07-28 14:23:52 +02:00
|
|
|
if (boolSetting(TargetAsync))
|
2015-02-06 01:26:47 +01:00
|
|
|
postCommand("set target-async on", NoFlags, CB(handleSetTargetAsync));
|
2010-09-06 14:26:19 +02:00
|
|
|
|
2013-11-01 15:39:59 +01:00
|
|
|
if (executableFileName.isEmpty()) {
|
2010-09-06 14:26:19 +02:00
|
|
|
showMessage(tr("No symbol file given."), StatusBar);
|
|
|
|
|
callTargetRemote();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
if (!executableFileName.isEmpty()) {
|
|
|
|
|
postCommand("-file-exec-and-symbols \"" + executableFileName.toLocal8Bit() + '"',
|
2015-02-06 01:26:47 +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 {
|
2013-05-03 18:26:10 +02:00
|
|
|
QByteArray reason = response.data["msg"].data();
|
2013-10-17 13:48:04 +02:00
|
|
|
QString msg = tr("Reading debug information failed:");
|
|
|
|
|
msg += QLatin1Char('\n');
|
2012-03-27 08:05:07 +02:00
|
|
|
msg += QString::fromLocal8Bit(reason);
|
|
|
|
|
if (reason.endsWith("No such file or directory.")) {
|
|
|
|
|
showMessage(_("INFERIOR STARTUP: BINARY NOT FOUND"));
|
|
|
|
|
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
|
|
|
{
|
2013-02-27 15:12:36 +01:00
|
|
|
QByteArray rawChannel = startParameters().remoteChannel.toLatin1();
|
|
|
|
|
QByteArray channel = rawChannel;
|
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-02-06 01:26:47 +01:00
|
|
|
postCommand("target qnx " + channel, NoFlags, CB(handleTargetQnx));
|
2014-09-18 20:19:59 +02:00
|
|
|
else if (startParameters().multiProcess)
|
2015-02-06 01:26:47 +01:00
|
|
|
postCommand("target extended-remote " + channel, NoFlags, CB(handleTargetExtendedRemote));
|
2012-02-29 17:14:03 +01:00
|
|
|
else
|
2015-02-06 01:26:47 +01:00
|
|
|
postCommand("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.
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("INFERIOR STARTED"));
|
|
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
2014-07-28 14:23:52 +02:00
|
|
|
QString postAttachCommands = stringSetting(GdbPostAttachCommands);
|
2012-10-23 10:51:32 +02:00
|
|
|
if (!postAttachCommands.isEmpty()) {
|
|
|
|
|
foreach (const QString &cmd, postAttachCommands.split(QLatin1Char('\n')))
|
|
|
|
|
postCommand(cmd.toLatin1());
|
|
|
|
|
}
|
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."
|
2010-01-04 14:11:07 +01:00
|
|
|
QString msg = msgConnectRemoteServerFailed(
|
2013-05-03 18:26:10 +02:00
|
|
|
QString::fromLocal8Bit(response.data["msg"].data()));
|
2013-02-27 15:12:36 +01:00
|
|
|
notifyInferiorSetupFailed(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2013-02-27 15:12:36 +01:00
|
|
|
showMessage(_("ATTACHED TO GDB SERVER STARTED"));
|
|
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
2014-07-28 14:23:52 +02:00
|
|
|
QString postAttachCommands = stringSetting(GdbPostAttachCommands);
|
2013-02-27 15:12:36 +01:00
|
|
|
if (!postAttachCommands.isEmpty()) {
|
|
|
|
|
foreach (const QString &cmd, postAttachCommands.split(QLatin1Char('\n')))
|
|
|
|
|
postCommand(cmd.toLatin1());
|
|
|
|
|
}
|
2014-09-18 20:19:59 +02:00
|
|
|
if (startParameters().attachPID > 0) { // attach to pid if valid
|
2014-06-05 15:10:43 +02:00
|
|
|
// gdb server will stop the remote application itself.
|
2014-09-18 20:19:59 +02:00
|
|
|
postCommand("attach " + QByteArray::number(startParameters().attachPID),
|
2015-02-06 01:26:47 +01:00
|
|
|
NoFlags, CB(handleTargetExtendedAttach));
|
2014-06-05 15:10:43 +02:00
|
|
|
} else {
|
|
|
|
|
postCommand("-gdb-set remote exec-file " + startParameters().remoteExecutable.toLatin1(),
|
2015-02-06 01:26:47 +01:00
|
|
|
NoFlags, CB(handleTargetExtendedAttach));
|
2014-06-05 15:10:43 +02:00
|
|
|
}
|
2013-02-27 15:12:36 +01:00
|
|
|
} else {
|
|
|
|
|
QString msg = msgConnectRemoteServerFailed(
|
2013-05-03 18:26:10 +02:00
|
|
|
QString::fromLocal8Bit(response.data["msg"].data()));
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
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 {
|
|
|
|
|
QString msg = msgConnectRemoteServerFailed(
|
2013-05-03 18:26:10 +02:00
|
|
|
QString::fromLocal8Bit(response.data["msg"].data()));
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
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.
|
|
|
|
|
showMessage(_("INFERIOR STARTED"));
|
|
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
|
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
const qint64 pid = isMasterEngine() ? startParameters().attachPID : masterEngine()->startParameters().attachPID;
|
2013-11-01 15:39:59 +01:00
|
|
|
const QString remoteExecutable = isMasterEngine() ? startParameters().remoteExecutable : masterEngine()->startParameters().remoteExecutable;
|
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)
|
2015-02-06 01:26:47 +01:00
|
|
|
postCommand("attach " + QByteArray::number(pid), NoFlags, CB(handleAttach));
|
2013-11-01 15:39:59 +01:00
|
|
|
else if (!remoteExecutable.isEmpty())
|
2015-02-06 01:26:47 +01:00
|
|
|
postCommand("set nto-executable " + remoteExecutable.toLatin1(), 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."
|
|
|
|
|
QString msg = msgConnectRemoteServerFailed(
|
2013-05-03 18:26:10 +02:00
|
|
|
QString::fromLocal8Bit(response.data["msg"].data()));
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
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: {
|
2012-02-10 07:42:44 +01:00
|
|
|
showMessage(_("INFERIOR ATTACHED"));
|
|
|
|
|
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.") {
|
2013-11-27 16:10:14 +01:00
|
|
|
notifyInferiorSetupFailed(msgPtraceError(startParameters().startMode));
|
2012-02-10 07:42:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// if msg != "ptrace: ..." fall through
|
|
|
|
|
default:
|
2013-05-03 18:26:10 +02:00
|
|
|
QString msg = QString::fromLocal8Bit(response.data["msg"].data());
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
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: {
|
2013-11-01 15:39:59 +01:00
|
|
|
showMessage(_("EXECUTABLE SET"));
|
|
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
|
|
|
|
handleInferiorPrepared();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-02-05 15:47:07 +01:00
|
|
|
case ResultError:
|
2013-11-01 15:39:59 +01:00
|
|
|
default:
|
|
|
|
|
QString msg = QString::fromLocal8Bit(response.data["msg"].data());
|
|
|
|
|
notifyInferiorSetupFailed(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2014-06-05 17:22:51 +02:00
|
|
|
const QString remoteExecutable = startParameters().remoteExecutable;
|
2012-06-29 07:23:13 +02:00
|
|
|
if (!remoteExecutable.isEmpty()) {
|
2013-11-01 15:39:59 +01:00
|
|
|
postCommand("-exec-run", GdbEngine::RunRequest, CB(handleExecRun));
|
2012-06-29 07:23:13 +02:00
|
|
|
} else {
|
|
|
|
|
notifyEngineRunAndInferiorStopOk();
|
|
|
|
|
continueInferiorInternal();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
showMessage(_("INFERIOR STARTED"));
|
|
|
|
|
showMessage(msgInferiorSetupOk(), StatusBar);
|
|
|
|
|
} else {
|
2013-05-03 18:26:10 +02:00
|
|
|
QString msg = QString::fromLocal8Bit(response.data["msg"].data());
|
2012-06-29 07:23:13 +02:00
|
|
|
showMessage(msg);
|
|
|
|
|
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());
|
2014-07-28 14:23:52 +02:00
|
|
|
if (boolSetting(TargetAsync)) {
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("-exec-interrupt", GdbEngine::Immediate,
|
2011-10-19 11:52:26 +02:00
|
|
|
CB(handleInterruptInferior));
|
2015-02-12 13:50:54 +01:00
|
|
|
} else if (m_isQnxGdb && HostOsInfo::isWindowsHost()) {
|
2013-09-09 16:42:32 +02:00
|
|
|
m_gdbProc->winInterruptByCtrlC();
|
2011-10-19 11:52:26 +02:00
|
|
|
} else {
|
2013-09-09 16:42:32 +02:00
|
|
|
bool ok = m_gdbProc->interrupt();
|
2011-10-19 11:52:26 +02:00
|
|
|
if (!ok) {
|
|
|
|
|
// FIXME: Extra state needed?
|
2012-06-13 10:15:56 +02:00
|
|
|
showMessage(_("NOTE: INFERIOR STOP NOT POSSIBLE"));
|
|
|
|
|
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
|
|
|
|
|
(const QByteArray &serverChannel, int inferiorPid)
|
|
|
|
|
{
|
2014-09-18 20:19:59 +02:00
|
|
|
// Currently only used by Android support.
|
|
|
|
|
startParameters().attachPID = inferiorPid;
|
|
|
|
|
startParameters().remoteChannel = QString::fromLatin1(serverChannel);
|
|
|
|
|
startParameters().multiProcess = true;
|
2013-02-27 15:12:36 +01: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
|