2009-09-21 11:09:38 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "plaingdbadapter.h"
|
|
|
|
|
|
|
|
|
|
#include "gdbengine.h"
|
|
|
|
|
#include "procinterrupt.h"
|
2009-09-25 15:02:16 +02:00
|
|
|
#include "debuggerstringutils.h"
|
2009-09-21 11:09:38 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
#define CB(callback) \
|
|
|
|
|
static_cast<GdbEngine::AdapterCallback>(&PlainGdbAdapter::callback), \
|
|
|
|
|
STRINGIFY(callback)
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// PlainGdbAdapter
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
PlainGdbAdapter::PlainGdbAdapter(GdbEngine *engine, QObject *parent)
|
|
|
|
|
: AbstractGdbAdapter(engine, parent)
|
|
|
|
|
{
|
2009-10-05 15:36:45 +02:00
|
|
|
// Output
|
|
|
|
|
connect(&m_outputCollector, SIGNAL(byteDelivery(QByteArray)),
|
|
|
|
|
engine, SLOT(readDebugeeOutput(QByteArray)));
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
2009-11-03 14:06:21 +01:00
|
|
|
AbstractGdbAdapter::DumperHandling PlainGdbAdapter::dumperHandling() const
|
|
|
|
|
{
|
2009-11-12 16:49:12 +01:00
|
|
|
// LD_PRELOAD fails for System-Qt on Mac.
|
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
2009-11-03 14:06:21 +01:00
|
|
|
return DumperLoadedByGdb;
|
|
|
|
|
#else
|
|
|
|
|
return DumperLoadedByGdbPreload;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-23 10:14:53 +02:00
|
|
|
void PlainGdbAdapter::startAdapter()
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2009-09-25 08:35:31 +02:00
|
|
|
QTC_ASSERT(state() == EngineStarting, qDebug() << state());
|
2009-09-21 17:35:19 +02:00
|
|
|
setState(AdapterStarting);
|
2009-09-21 11:09:38 +02:00
|
|
|
debugMessage(_("TRYING TO START ADAPTER"));
|
|
|
|
|
|
|
|
|
|
QStringList gdbArgs;
|
|
|
|
|
|
2009-10-06 17:07:23 +02:00
|
|
|
if (!m_outputCollector.listen()) {
|
|
|
|
|
emit adapterStartFailed(tr("Cannot set up communication with child process: %1")
|
2009-10-08 12:31:17 +02:00
|
|
|
.arg(m_outputCollector.errorString()), QString());
|
2009-10-06 17:07:23 +02:00
|
|
|
return;
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
2009-10-20 11:02:16 +02:00
|
|
|
gdbArgs.append(_("--tty=") + m_outputCollector.serverName());
|
2009-10-06 17:07:23 +02:00
|
|
|
|
|
|
|
|
if (!startParameters().workingDir.isEmpty())
|
2009-10-20 11:02:16 +02:00
|
|
|
m_engine->m_gdbProc.setWorkingDirectory(startParameters().workingDir);
|
2009-10-06 17:07:23 +02:00
|
|
|
if (!startParameters().environment.isEmpty())
|
2009-10-20 11:02:16 +02:00
|
|
|
m_engine->m_gdbProc.setEnvironment(startParameters().environment);
|
2009-09-21 11:09:38 +02:00
|
|
|
|
2009-10-20 11:02:16 +02:00
|
|
|
if (!m_engine->startGdb(gdbArgs)) {
|
|
|
|
|
m_outputCollector.shutdown();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-09-21 11:09:38 +02:00
|
|
|
|
2009-09-21 17:35:19 +02:00
|
|
|
emit adapterStarted();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-13 09:53:47 +02:00
|
|
|
void PlainGdbAdapter::startInferior()
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2009-10-13 09:53:47 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
2009-09-23 10:14:53 +02:00
|
|
|
if (!startParameters().processArgs.isEmpty())
|
2009-09-21 17:35:19 +02:00
|
|
|
m_engine->postCommand(_("-exec-arguments ")
|
2009-09-23 10:14:53 +02:00
|
|
|
+ startParameters().processArgs.join(_(" ")));
|
2009-09-30 12:27:03 +02:00
|
|
|
QFileInfo fi(startParameters().executable);
|
2009-09-21 11:09:38 +02:00
|
|
|
m_engine->postCommand(_("-file-exec-and-symbols \"%1\"").arg(fi.absoluteFilePath()),
|
|
|
|
|
CB(handleFileExecAndSymbols));
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-24 11:16:00 +02:00
|
|
|
void PlainGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2009-10-13 09:53:47 +02:00
|
|
|
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
2009-09-21 11:09:38 +02:00
|
|
|
if (response.resultClass == GdbResultDone) {
|
2009-11-09 22:11:56 +01:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
// Old gdbs do not announce the PID for programs without pthreads.
|
|
|
|
|
// Note that successfully preloading the debugging helpers will
|
|
|
|
|
// automatically load pthreads, so this will be unnecessary.
|
|
|
|
|
if (m_engine->m_gdbVersion < 70000)
|
|
|
|
|
m_engine->postCommand(_("info target"), CB(handleInfoTarget));
|
|
|
|
|
#endif
|
2009-10-19 19:04:01 +02:00
|
|
|
emit inferiorPrepared();
|
2009-10-12 12:00:07 +02:00
|
|
|
} else {
|
2009-09-21 11:09:38 +02:00
|
|
|
QString msg = tr("Starting executable failed:\n") +
|
|
|
|
|
__(response.data.findChild("msg").data());
|
2009-10-13 09:53:47 +02:00
|
|
|
emit inferiorStartFailed(msg);
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-09 22:11:56 +01:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
void PlainGdbAdapter::handleInfoTarget(const GdbResponse &response)
|
|
|
|
|
{
|
|
|
|
|
if (response.resultClass == GdbResultDone) {
|
|
|
|
|
// [some leading stdout here]
|
|
|
|
|
// >&" Entry point: 0x80831f0 0x08048134 - 0x08048147 is .interp\n"
|
|
|
|
|
// [some trailing stdout here]
|
|
|
|
|
QString msg = _(response.data.findChild("consolestreamoutput").data());
|
|
|
|
|
QRegExp needle(_("\\bEntry point: 0x([0-9a-f]+)\\b"));
|
|
|
|
|
if (needle.indexIn(msg) != -1) {
|
|
|
|
|
m_engine->m_entryPoint =
|
|
|
|
|
"0x" + needle.cap(1).toLatin1().rightJustified(sizeof(void *) * 2, '0');
|
|
|
|
|
m_engine->postCommand(_("tbreak *0x") + needle.cap(1));
|
|
|
|
|
// Do nothing here - inferiorPrepared handles the sequencing.
|
|
|
|
|
} else {
|
|
|
|
|
emit inferiorStartFailed(_("Parsing start address failed"));
|
|
|
|
|
}
|
|
|
|
|
} else if (response.resultClass == GdbResultError) {
|
|
|
|
|
emit inferiorStartFailed(_("Fetching start address failed"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-10-19 19:04:01 +02:00
|
|
|
void PlainGdbAdapter::startInferiorPhase2()
|
|
|
|
|
{
|
|
|
|
|
setState(InferiorRunningRequested);
|
|
|
|
|
m_engine->postCommand(_("-exec-run"), GdbEngine::RunRequest, CB(handleExecRun));
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-24 11:16:00 +02:00
|
|
|
void PlainGdbAdapter::handleExecRun(const GdbResponse &response)
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
|
|
|
|
if (response.resultClass == GdbResultRunning) {
|
2009-09-28 15:06:17 +02:00
|
|
|
QTC_ASSERT(state() == InferiorRunning, qDebug() << state());
|
2009-09-29 10:15:52 +02:00
|
|
|
debugMessage(_("INFERIOR STARTED"));
|
2009-10-12 12:33:12 +02:00
|
|
|
showStatusMessage(msgInferiorStarted());
|
2009-09-21 11:09:38 +02:00
|
|
|
} else {
|
2009-09-28 15:06:17 +02:00
|
|
|
QTC_ASSERT(state() == InferiorRunningRequested, qDebug() << state());
|
2009-09-21 11:09:38 +02:00
|
|
|
const QByteArray &msg = response.data.findChild("msg").data();
|
2009-09-25 08:35:31 +02:00
|
|
|
//QTC_ASSERT(status() == InferiorRunning, /**/);
|
2009-09-21 11:09:38 +02:00
|
|
|
//interruptInferior();
|
|
|
|
|
emit inferiorStartFailed(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlainGdbAdapter::interruptInferior()
|
|
|
|
|
{
|
|
|
|
|
const qint64 attachedPID = m_engine->inferiorPid();
|
|
|
|
|
if (attachedPID <= 0) {
|
|
|
|
|
debugMessage(_("TRYING TO INTERRUPT INFERIOR BEFORE PID WAS OBTAINED"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!interruptProcess(attachedPID))
|
|
|
|
|
debugMessage(_("CANNOT INTERRUPT %1").arg(attachedPID));
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-22 11:31:34 +02:00
|
|
|
void PlainGdbAdapter::shutdown()
|
2009-09-21 11:09:38 +02:00
|
|
|
{
|
2009-09-25 11:06:51 +02:00
|
|
|
debugMessage(_("PLAIN ADAPTER SHUTDOWN %1").arg(state()));
|
2009-10-05 15:36:45 +02:00
|
|
|
m_outputCollector.shutdown();
|
2009-09-21 11:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|