2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-22 10:50:44 +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-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
|
|
|
|
|
** 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-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
|
|
|
|
|
** 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-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
|
|
|
|
2011-09-30 13:35:31 +02:00
|
|
|
#include "debuggeractions.h"
|
2011-01-10 10:14:23 +01:00
|
|
|
#include "debuggerstartparameters.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
#include "debuggercore.h"
|
2009-09-25 15:02:16 +02:00
|
|
|
#include "debuggerstringutils.h"
|
2009-09-22 10:50:44 +02:00
|
|
|
#include "gdbengine.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
#include "gdbmi.h"
|
2009-09-22 10:50:44 +02:00
|
|
|
|
2012-08-31 16:39:20 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2009-09-22 10:50:44 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-09-25 15:02:16 +02:00
|
|
|
#include <utils/fancymainwindow.h>
|
2012-11-06 08:20:42 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <projectexplorer/abi.h>
|
2009-09-22 10:50:44 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMessageBox>
|
2009-09-22 10:50:44 +02:00
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
#define CB(callback) \
|
2012-06-13 10:15:56 +02:00
|
|
|
static_cast<GdbEngine::GdbCommandCallback>(&GdbRemoteServerEngine::callback), \
|
2009-09-22 10:50:44 +02:00
|
|
|
STRINGIFY(callback)
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// RemoteGdbAdapter
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-15 14:33:39 +02:00
|
|
|
GdbRemoteServerEngine::GdbRemoteServerEngine(const DebuggerStartParameters &startParameters)
|
|
|
|
|
: GdbEngine(startParameters)
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2009-09-22 11:31:34 +02:00
|
|
|
connect(&m_uploadProc, SIGNAL(error(QProcess::ProcessError)),
|
2010-11-26 12:58:04 +01:00
|
|
|
SLOT(uploadProcError(QProcess::ProcessError)));
|
2009-09-22 11:31:34 +02:00
|
|
|
connect(&m_uploadProc, SIGNAL(readyReadStandardOutput()),
|
2010-11-26 12:58:04 +01:00
|
|
|
SLOT(readUploadStandardOutput()));
|
2009-09-22 11:31:34 +02:00
|
|
|
connect(&m_uploadProc, SIGNAL(readyReadStandardError()),
|
2010-11-26 12:58:04 +01:00
|
|
|
SLOT(readUploadStandardError()));
|
|
|
|
|
connect(&m_uploadProc, SIGNAL(finished(int)),
|
2010-07-15 16:43:56 +02:00
|
|
|
SLOT(uploadProcFinished()));
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
GdbEngine::DumperHandling GdbRemoteServerEngine::dumperHandling() const
|
2009-11-03 14:06:21 +01:00
|
|
|
{
|
2011-03-24 15:05:45 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
const Abi abi = startParameters().toolChainAbi;
|
2012-08-22 13:27:25 +02:00
|
|
|
if (abi.os() == Abi::WindowsOS
|
2011-03-24 15:05:45 +01:00
|
|
|
|| abi.binaryFormat() == Abi::ElfFormat)
|
2009-11-03 14:06:21 +01:00
|
|
|
return DumperLoadedByGdb;
|
|
|
|
|
return DumperLoadedByGdbPreload;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
Utils::QtcProcess::addArg(&arglist, startParameters().serverStartScript);
|
|
|
|
|
Utils::QtcProcess::addArg(&arglist, startParameters().executable);
|
|
|
|
|
Utils::QtcProcess::addArg(&arglist, startParameters().remoteChannel);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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);
|
2010-11-10 16:33:11 +01:00
|
|
|
showMessageBox(QMessageBox::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
|
|
|
{
|
|
|
|
|
if (m_uploadProc.exitStatus() == QProcess::NormalExit
|
|
|
|
|
&& m_uploadProc.exitCode() == 0)
|
2012-06-13 10:15:56 +02:00
|
|
|
startGdb();
|
2010-07-15 16:43:56 +02:00
|
|
|
else
|
2012-06-13 11:29:26 +02:00
|
|
|
notifyEngineRemoteSetupFailed(m_uploadProc.errorString());
|
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
|
|
|
QString symbolFileName;
|
|
|
|
|
if (!sp.symbolFileName.isEmpty()) {
|
|
|
|
|
QFileInfo fi(sp.symbolFileName);
|
|
|
|
|
symbolFileName = fi.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
//const QByteArray sysroot = sp.sysroot.toLocal8Bit();
|
|
|
|
|
//const QByteArray remoteArch = sp.remoteArchitecture.toLatin1();
|
2011-09-14 17:01:57 +02:00
|
|
|
const QString args = sp.processArgs;
|
2012-06-13 10:15:56 +02:00
|
|
|
|
|
|
|
|
// if (!remoteArch.isEmpty())
|
|
|
|
|
// postCommand("set architecture " + remoteArch);
|
2012-08-31 16:39:20 +02:00
|
|
|
const QString solibSearchPath
|
|
|
|
|
= sp.solibSearchPath.join(QString(Utils::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,[...]
|
2011-09-30 13:35:31 +02:00
|
|
|
if (debuggerCore()->boolSetting(TargetAsync))
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("set target-async on", CB(handleSetTargetAsync));
|
2010-09-06 14:26:19 +02:00
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
if (executableFileName.isEmpty() && symbolFileName.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 (!symbolFileName.isEmpty()) {
|
|
|
|
|
postCommand("-file-symbol-file \""
|
|
|
|
|
+ symbolFileName.toLocal8Bit() + '"',
|
|
|
|
|
CB(handleFileExecAndSymbols));
|
|
|
|
|
}
|
|
|
|
|
if (!executableFileName.isEmpty()) {
|
|
|
|
|
postCommand("-file-exec-and-symbols \"" + executableFileName.toLocal8Bit() + '"',
|
|
|
|
|
CB(handleFileExecAndSymbols));
|
|
|
|
|
}
|
2009-10-01 17:13:27 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::handleSetTargetAsync(const GdbResponse &response)
|
2009-10-01 17:13:27 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2009-10-16 15:05:30 +02:00
|
|
|
if (response.resultClass == GdbResultError)
|
|
|
|
|
qDebug() << "Adapter too old: does not support asynchronous mode.";
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::handleFileExecAndSymbols(const GdbResponse &response)
|
2009-09-22 10:50:44 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2009-09-22 10:50:44 +02:00
|
|
|
if (response.resultClass == GdbResultDone) {
|
2010-09-06 14:26:19 +02:00
|
|
|
callTargetRemote();
|
2009-10-12 12:00:07 +02:00
|
|
|
} else {
|
2012-03-27 08:05:07 +02:00
|
|
|
QByteArray reason = response.data.findChild("msg").data();
|
2010-09-06 14:26:19 +02:00
|
|
|
QString msg = tr("Reading debug information failed:\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
|
|
|
{
|
|
|
|
|
//m_breakHandler->clearBreakMarkers();
|
|
|
|
|
|
|
|
|
|
// "target remote" does three things:
|
|
|
|
|
// (1) connects to the gdb server
|
|
|
|
|
// (2) starts the remote application
|
|
|
|
|
// (3) stops the remote application (early, e.g. in the dynamic linker)
|
2012-02-29 17:14:03 +01:00
|
|
|
QByteArray channel = startParameters().remoteChannel.toLatin1();
|
|
|
|
|
|
|
|
|
|
// Don't touch channels with explicitly set protocols.
|
|
|
|
|
if (!channel.startsWith("tcp:") && !channel.startsWith("udp:")
|
|
|
|
|
&& !channel.startsWith("file:") && channel.contains(':'))
|
|
|
|
|
{
|
|
|
|
|
// "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)
|
|
|
|
|
postCommand("target qnx " + channel, CB(handleTargetQnx));
|
2012-02-29 17:14:03 +01:00
|
|
|
else
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("target remote " + channel, CB(handleTargetRemote));
|
2010-09-06 14:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::handleTargetRemote(const GdbResponse &record)
|
2009-09-24 10:54:27 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2009-09-24 10:54:27 +02:00
|
|
|
if (record.resultClass == GdbResultDone) {
|
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);
|
2012-10-23 10:51:32 +02:00
|
|
|
QString postAttachCommands = debuggerCore()->stringSetting(GdbPostAttachCommands);
|
|
|
|
|
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(
|
|
|
|
|
QString::fromLocal8Bit(record.data.findChild("msg").data()));
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
2009-09-22 10:50:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::handleTargetQnx(const GdbResponse &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());
|
|
|
|
|
if (response.resultClass == GdbResultDone) {
|
|
|
|
|
// 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;
|
2012-02-10 07:42:44 +01:00
|
|
|
if (pid > -1) {
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("attach " + QByteArray::number(pid), CB(handleAttach));
|
2012-02-10 07:42:44 +01: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(
|
|
|
|
|
QString::fromLocal8Bit(response.data.findChild("msg").data()));
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
2012-02-10 07:42:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::handleAttach(const GdbResponse &response)
|
2012-02-10 07:42:44 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
|
|
|
|
switch (response.resultClass) {
|
|
|
|
|
case GdbResultDone:
|
|
|
|
|
case GdbResultRunning: {
|
|
|
|
|
showMessage(_("INFERIOR ATTACHED"));
|
|
|
|
|
showMessage(msgAttachedToStoppedInferior(), StatusBar);
|
2012-06-13 10:15:56 +02:00
|
|
|
handleInferiorPrepared();
|
2012-02-10 07:42:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GdbResultError:
|
|
|
|
|
if (response.data.findChild("msg").data() == "ptrace: Operation not permitted.") {
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(DumperHelper::msgPtraceError(startParameters().startMode));
|
2012-02-10 07:42:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// if msg != "ptrace: ..." fall through
|
|
|
|
|
default:
|
|
|
|
|
QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data());
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
2012-02-10 07:42:44 +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
|
|
|
|
|
|
|
|
const QString remoteExecutable = startParameters().remoteExecutable;
|
|
|
|
|
if (!remoteExecutable.isEmpty()) {
|
2012-09-05 13:13:58 +02:00
|
|
|
// Cannot use -exec-run for QNX gdb 7.4 as it does not support path parameter for the MI call
|
|
|
|
|
const bool useRun = m_isQnxGdb && m_gdbVersion > 70300;
|
|
|
|
|
const QByteArray command = useRun ? "run" : "-exec-run";
|
2012-08-24 07:58:28 +02:00
|
|
|
postCommand(command + " " + remoteExecutable.toLocal8Bit(), GdbEngine::RunRequest, CB(handleExecRun));
|
2012-06-29 07:23:13 +02:00
|
|
|
} else {
|
|
|
|
|
notifyEngineRunAndInferiorStopOk();
|
|
|
|
|
continueInferiorInternal();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GdbRemoteServerEngine::handleExecRun(const GdbResponse &response)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
|
|
|
|
if (response.resultClass == GdbResultRunning) {
|
|
|
|
|
notifyEngineRunAndInferiorRunOk();
|
|
|
|
|
showMessage(_("INFERIOR STARTED"));
|
|
|
|
|
showMessage(msgInferiorSetupOk(), StatusBar);
|
|
|
|
|
} else {
|
|
|
|
|
QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data());
|
|
|
|
|
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());
|
2011-10-19 11:52:26 +02:00
|
|
|
if (debuggerCore()->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));
|
|
|
|
|
} else {
|
|
|
|
|
bool ok = m_gdbProc.interrupt();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbRemoteServerEngine::handleInterruptInferior(const GdbResponse &response)
|
2010-11-26 14:23:52 +01:00
|
|
|
{
|
|
|
|
|
if (response.resultClass == GdbResultDone) {
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
2012-06-13 11:29:26 +02:00
|
|
|
void GdbRemoteServerEngine::notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort)
|
2010-07-15 16:43:56 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
2012-06-13 11:29:26 +02:00
|
|
|
DebuggerEngine::notifyEngineRemoteSetupDone(gdbServerPort, qmlPort);
|
2010-07-15 16:43:56 +02:00
|
|
|
|
2010-11-02 10:24:50 +01:00
|
|
|
if (qmlPort != -1)
|
|
|
|
|
startParameters().qmlServerPort = qmlPort;
|
|
|
|
|
if (gdbServerPort != -1) {
|
|
|
|
|
QString &rc = startParameters().remoteChannel;
|
|
|
|
|
const int sepIndex = rc.lastIndexOf(QLatin1Char(':'));
|
|
|
|
|
if (sepIndex != -1) {
|
|
|
|
|
rc.replace(sepIndex + 1, rc.count() - sepIndex - 1,
|
|
|
|
|
QString::number(gdbServerPort));
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-13 10:15:56 +02:00
|
|
|
startGdb();
|
2012-06-05 11:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 11:29:26 +02:00
|
|
|
void GdbRemoteServerEngine::notifyEngineRemoteSetupFailed(const QString &reason)
|
2010-07-15 16:43:56 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
2012-06-13 11:29:26 +02:00
|
|
|
DebuggerEngine::notifyEngineRemoteSetupFailed(reason);
|
2012-06-13 10:15:56 +02:00
|
|
|
handleAdapterStartFailed(reason);
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2009-09-22 10:50:44 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|