Commit 8baa54e7 authored by hjk's avatar hjk

debugger: code cosmetics

parent 75ee5bce
......@@ -219,7 +219,7 @@ enum DebuggerEngineType
TcfEngineType = 0x10,
QmlEngineType = 0x20,
QmlCppEngineType = 0x40,
LLDBEngineType = 0x80,
LldbEngineType = 0x80,
AllEngineTypes = GdbEngineType
| ScriptEngineType
| CdbEngineType
......@@ -227,7 +227,7 @@ enum DebuggerEngineType
| TcfEngineType
| QmlEngineType
| QmlCppEngineType
| LLDBEngineType
| LldbEngineType
};
enum DebuggerLanguage
......
......@@ -75,7 +75,7 @@ DebuggerEngine *createPdbEngine(const DebuggerStartParameters &);
DebuggerEngine *createTcfEngine(const DebuggerStartParameters &);
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &);
DebuggerEngine *createQmlCppEngine(const DebuggerStartParameters &);
DebuggerEngine *createLLDBEngine(const DebuggerStartParameters &);
DebuggerEngine *createLldbEngine(const DebuggerStartParameters &);
extern QString msgNoBinaryForToolChain(int tc);
......@@ -95,6 +95,8 @@ bool checkCdbConfiguration(int, QString *, QString *) { return false; }
#endif
} // namespace Internal
namespace Cdb {
DebuggerEngine *createCdbEngine(const DebuggerStartParameters &, QString *errorMessage);
bool isCdbEngineEnabled(); // Check the configuration page
......@@ -243,16 +245,28 @@ QWidget *DebuggerRunControlFactory::createConfigurationWidget
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControl
// DebuggerRunControlPrivate
//
////////////////////////////////////////////////////////////////////////
struct DebuggerRunnerPrivate {
explicit DebuggerRunnerPrivate(RunConfiguration *runConfiguration,
unsigned enabledEngines);
class DebuggerRunControlPrivate
{
public:
DebuggerRunControlPrivate(DebuggerRunControl *parent,
RunConfiguration *runConfiguration, unsigned enabledEngines);
unsigned enabledEngines() const;
DebuggerEngineType engineForExecutable(unsigned enabledEngineTypes,
const QString &executable);
DebuggerEngineType engineForMode(unsigned enabledEngineTypes,
DebuggerStartMode mode);
void initGdbEngine(GdbEngine *engine);
GdbEngine *gdbEngine() const;
AbstractGdbAdapter *gdbAdapter() const;
public:
DebuggerRunControl *q;
DebuggerEngine *m_engine;
const QWeakPointer<RunConfiguration> m_myRunConfiguration;
bool m_running;
......@@ -261,83 +275,30 @@ struct DebuggerRunnerPrivate {
QString m_settingsIdHint;
};
unsigned DebuggerRunnerPrivate::enabledEngines() const
unsigned DebuggerRunControlPrivate::enabledEngines() const
{
unsigned rc = m_cmdLineEnabledEngines;
#ifdef CDB_ENABLED
if (!Internal::isCdbEngineEnabled() && !Cdb::isCdbEngineEnabled())
if (!isCdbEngineEnabled() && !Cdb::isCdbEngineEnabled())
rc &= ~CdbEngineType;
#endif
return rc;
}
DebuggerRunnerPrivate::DebuggerRunnerPrivate(RunConfiguration *runConfiguration,
unsigned enabledEngines) :
m_engine(0)
DebuggerRunControlPrivate::DebuggerRunControlPrivate(DebuggerRunControl *parent,
RunConfiguration *runConfiguration, unsigned enabledEngines)
: q(parent)
, m_engine(0)
, m_myRunConfiguration(runConfiguration)
, m_running(false)
, m_cmdLineEnabledEngines(enabledEngines)
{
}
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
unsigned enabledEngines, const DebuggerStartParameters &sp)
: RunControl(runConfiguration, Constants::DEBUGMODE),
d(new DebuggerRunnerPrivate(runConfiguration, enabledEngines))
{
connect(this, SIGNAL(finished()), this, SLOT(handleFinished()));
DebuggerStartParameters startParams = sp;
createEngine(startParams);
}
DebuggerRunControl::~DebuggerRunControl()
{
disconnect();
if (DebuggerEngine *engine = d->m_engine) {
d->m_engine = 0;
engine->disconnect();
delete engine;
}
}
const DebuggerStartParameters &DebuggerRunControl::startParameters() const
{
QTC_ASSERT(d->m_engine, return *(new DebuggerStartParameters()));
return d->m_engine->startParameters();
}
static DebuggerEngineType engineForToolChain(int toolChainType)
{
switch (toolChainType) {
case ProjectExplorer::ToolChain_LINUX_ICC:
case ProjectExplorer::ToolChain_MinGW:
case ProjectExplorer::ToolChain_GCC:
case ProjectExplorer::ToolChain_WINSCW: // S60
case ProjectExplorer::ToolChain_GCCE:
case ProjectExplorer::ToolChain_RVCT_ARMV5:
case ProjectExplorer::ToolChain_RVCT_ARMV6:
case ProjectExplorer::ToolChain_RVCT_ARMV5_GNUPOC:
case ProjectExplorer::ToolChain_GCCE_GNUPOC:
case ProjectExplorer::ToolChain_GCC_MAEMO:
return GdbEngineType;
case ProjectExplorer::ToolChain_MSVC:
case ProjectExplorer::ToolChain_WINCE:
return CdbEngineType;
case ProjectExplorer::ToolChain_OTHER:
case ProjectExplorer::ToolChain_UNKNOWN:
case ProjectExplorer::ToolChain_INVALID:
default:
break;
}
return NoEngineType;
}
// Figure out the debugger type of an executable. Analyze executable
// unless the toolchain provides a hint.
DebuggerEngineType DebuggerRunControl::engineForExecutable(unsigned enabledEngineTypes, const QString &executable)
DebuggerEngineType DebuggerRunControlPrivate::engineForExecutable
(unsigned enabledEngineTypes, const QString &executable)
{
/*if (executable.endsWith(_("qmlviewer"))) {
if (enabledEngineTypes & QmlEngineType)
......@@ -348,13 +309,13 @@ DebuggerEngineType DebuggerRunControl::engineForExecutable(unsigned enabledEngin
if (executable.endsWith(_(".js"))) {
if (enabledEngineTypes & ScriptEngineType)
return ScriptEngineType;
d->m_errorMessage = msgEngineNotAvailable("Script Engine");
m_errorMessage = msgEngineNotAvailable("Script Engine");
}
if (executable.endsWith(_(".py"))) {
if (enabledEngineTypes & PdbEngineType)
return PdbEngineType;
d->m_errorMessage = msgEngineNotAvailable("Pdb Engine");
m_errorMessage = msgEngineNotAvailable("Pdb Engine");
}
#ifdef Q_OS_WIN
......@@ -364,9 +325,9 @@ DebuggerEngineType DebuggerRunControl::engineForExecutable(unsigned enabledEngin
// If a file has PDB files, it has been compiled by VS.
QStringList pdbFiles;
if (!getPDBFiles(executable, &pdbFiles, &d->m_errorMessage)) {
if (!getPDBFiles(executable, &pdbFiles, &m_errorMessage)) {
qWarning("Cannot determine type of executable %s: %s",
qPrintable(executable), qPrintable(d->m_errorMessage));
qPrintable(executable), qPrintable(m_errorMessage));
return NoEngineType;
}
if (pdbFiles.empty())
......@@ -374,23 +335,24 @@ DebuggerEngineType DebuggerRunControl::engineForExecutable(unsigned enabledEngin
// We need the CDB debugger in order to be able to debug VS
// executables
if (checkDebugConfiguration(ProjectExplorer::ToolChain_MSVC, &d->m_errorMessage, 0, &d->m_settingsIdHint)) {
if (checkDebugConfiguration(ProjectExplorer::ToolChain_MSVC, &m_errorMessage, 0, &m_settingsIdHint)) {
if (enabledEngineTypes & CdbEngineType)
return CdbEngineType;
d->m_errorMessage = msgEngineNotAvailable("Cdb Engine");
m_errorMessage = msgEngineNotAvailable("Cdb Engine");
return NoEngineType;
}
#else
if (enabledEngineTypes & GdbEngineType)
return GdbEngineType;
d->m_errorMessage = msgEngineNotAvailable("Gdb Engine");
m_errorMessage = msgEngineNotAvailable("Gdb Engine");
#endif
return NoEngineType;
}
// Debugger type for mode.
DebuggerEngineType DebuggerRunControl::engineForMode(unsigned enabledEngineTypes, DebuggerStartMode startMode)
DebuggerEngineType DebuggerRunControlPrivate::engineForMode
(unsigned enabledEngineTypes, DebuggerStartMode startMode)
{
if (startMode == AttachTcf)
return TcfEngineType;
......@@ -400,18 +362,109 @@ DebuggerEngineType DebuggerRunControl::engineForMode(unsigned enabledEngineTypes
if (startMode != AttachToRemote && (enabledEngineTypes & CdbEngineType))
return CdbEngineType;
if (startMode == AttachCrashedExternal) {
d->m_errorMessage = tr("There is no debugging engine available for post-mortem debugging.");
m_errorMessage = tr("There is no debugging engine available for post-mortem debugging.");
return NoEngineType;
}
return GdbEngineType;
#else
Q_UNUSED(startMode)
Q_UNUSED(enabledEngineTypes)
// d->m_errorMessage = msgEngineNotAvailable("Gdb Engine");
// >m_errorMessage = msgEngineNotAvailable("Gdb Engine");
return GdbEngineType;
#endif
}
void DebuggerRunControlPrivate::initGdbEngine(GdbEngine *engine)
{
QTC_ASSERT(engine, return)
// Forward adapter signals.
AbstractGdbAdapter *adapter = engine->gdbAdapter();
RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter);
RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter);
if (rpga)
q->connect(rpga, SIGNAL(requestSetup()), SIGNAL(engineRequestSetup()));
else if (rgsa)
q->connect(rgsa, SIGNAL(requestSetup()), SIGNAL(engineRequestSetup()));
}
GdbEngine *DebuggerRunControlPrivate::gdbEngine() const
{
QTC_ASSERT(m_engine, return 0);
if (GdbEngine *gdbEngine = qobject_cast<GdbEngine *>(m_engine))
return gdbEngine;
if (QmlCppEngine *qmlEngine = qobject_cast<QmlCppEngine *>(m_engine))
if (GdbEngine *embeddedGdbEngine = qobject_cast<GdbEngine *>(qmlEngine->cppEngine()))
return embeddedGdbEngine;
return 0;
}
AbstractGdbAdapter *DebuggerRunControlPrivate::gdbAdapter() const
{
GdbEngine *engine = gdbEngine();
QTC_ASSERT(engine, return 0)
return engine->gdbAdapter();
}
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControl
//
////////////////////////////////////////////////////////////////////////
DebuggerRunControl::DebuggerRunControl(RunConfiguration *runConfiguration,
unsigned enabledEngines, const DebuggerStartParameters &sp)
: RunControl(runConfiguration, Constants::DEBUGMODE),
d(new DebuggerRunControlPrivate(this, runConfiguration, enabledEngines))
{
connect(this, SIGNAL(finished()), SLOT(handleFinished()));
createEngine(sp);
}
DebuggerRunControl::~DebuggerRunControl()
{
disconnect();
if (DebuggerEngine *engine = d->m_engine) {
d->m_engine = 0;
engine->disconnect();
delete engine;
}
}
const DebuggerStartParameters &DebuggerRunControl::startParameters() const
{
QTC_ASSERT(d->m_engine, return *(new DebuggerStartParameters()));
return d->m_engine->startParameters();
}
static DebuggerEngineType engineForToolChain(int toolChainType)
{
switch (toolChainType) {
case ProjectExplorer::ToolChain_LINUX_ICC:
case ProjectExplorer::ToolChain_MinGW:
case ProjectExplorer::ToolChain_GCC:
case ProjectExplorer::ToolChain_WINSCW: // S60
case ProjectExplorer::ToolChain_GCCE:
case ProjectExplorer::ToolChain_RVCT_ARMV5:
case ProjectExplorer::ToolChain_RVCT_ARMV6:
case ProjectExplorer::ToolChain_RVCT_ARMV5_GNUPOC:
case ProjectExplorer::ToolChain_GCCE_GNUPOC:
case ProjectExplorer::ToolChain_GCC_MAEMO:
return GdbEngineType;
case ProjectExplorer::ToolChain_MSVC:
case ProjectExplorer::ToolChain_WINCE:
return CdbEngineType;
case ProjectExplorer::ToolChain_OTHER:
case ProjectExplorer::ToolChain_UNKNOWN:
case ProjectExplorer::ToolChain_INVALID:
default:
break;
}
return NoEngineType;
}
void DebuggerRunControl::createEngine(const DebuggerStartParameters &startParams)
{
DebuggerStartParameters sp = startParams;
......@@ -437,15 +490,15 @@ void DebuggerRunControl::createEngine(const DebuggerStartParameters &startParams
engineType = GdbEngineType;
if (sp.processArgs.contains( _("@lldb@")))
engineType = LLDBEngineType;
engineType = LldbEngineType;
if (engineType == NoEngineType
&& sp.startMode != AttachToRemote
&& !sp.executable.isEmpty())
engineType = engineForExecutable(enabledEngineTypes, sp.executable);
engineType = d->engineForExecutable(enabledEngineTypes, sp.executable);
if (engineType == NoEngineType)
engineType = engineForMode(enabledEngineTypes, sp.startMode);
engineType = d->engineForMode(enabledEngineTypes, sp.startMode);
if ((engineType != QmlEngineType && engineType != NoEngineType)
&& (activeLangs & QmlLanguage)) {
......@@ -462,10 +515,10 @@ void DebuggerRunControl::createEngine(const DebuggerStartParameters &startParams
switch (engineType) {
case GdbEngineType:
d->m_engine = createGdbEngine(sp);
initGdbEngine(qobject_cast<Internal::GdbEngine *>(d->m_engine));
d->initGdbEngine(qobject_cast<GdbEngine *>(d->m_engine));
break;
case ScriptEngineType:
d->m_engine = Internal::createScriptEngine(sp);
d->m_engine = createScriptEngine(sp);
break;
case CdbEngineType:
// Try new engine, fall back to old.
......@@ -476,24 +529,24 @@ void DebuggerRunControl::createEngine(const DebuggerStartParameters &startParams
}
break;
case PdbEngineType:
d->m_engine = Internal::createPdbEngine(sp);
d->m_engine = createPdbEngine(sp);
break;
case TcfEngineType:
d->m_engine = Internal::createTcfEngine(sp);
d->m_engine = createTcfEngine(sp);
break;
case QmlEngineType:
d->m_engine = Internal::createQmlEngine(sp);
d->m_engine = createQmlEngine(sp);
connect(qobject_cast<QmlEngine *>(d->m_engine),
SIGNAL(remoteStartupRequested()), this,
SIGNAL(remoteStartupRequested()),
SIGNAL(engineRequestSetup()));
break;
case QmlCppEngineType:
d->m_engine = Internal::createQmlCppEngine(sp);
if (Internal::GdbEngine *embeddedGdbEngine = gdbEngine())
initGdbEngine(embeddedGdbEngine);
d->m_engine = createQmlCppEngine(sp);
if (GdbEngine *embeddedGdbEngine = d->gdbEngine())
d->initGdbEngine(embeddedGdbEngine);
break;
case LLDBEngineType:
d->m_engine = Internal::createLLDBEngine(sp);
case LldbEngineType:
d->m_engine = createLldbEngine(sp);
case NoEngineType:
case AllEngineTypes:
break;
......@@ -511,21 +564,6 @@ void DebuggerRunControl::createEngine(const DebuggerStartParameters &startParams
}
}
void DebuggerRunControl::initGdbEngine(Internal::GdbEngine *engine)
{
QTC_ASSERT(engine, return)
// Forward adapter signals.
Internal::AbstractGdbAdapter *adapter = engine->gdbAdapter();
if (RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter)) {
connect(rpga, SIGNAL(requestSetup()), this,
SIGNAL(engineRequestSetup()));
} else if (RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter)) {
connect(rgsa, SIGNAL(requestSetup()),
this, SIGNAL(engineRequestSetup()));
}
}
QString DebuggerRunControl::displayName() const
{
QTC_ASSERT(d->m_engine, return QString());
......@@ -703,56 +741,54 @@ DebuggerEngine *DebuggerRunControl::engine()
return d->m_engine;
}
Internal::GdbEngine *DebuggerRunControl::gdbEngine() const
{
QTC_ASSERT(d->m_engine, return 0);
if (GdbEngine *gdbEngine = qobject_cast<GdbEngine *>(d->m_engine))
return gdbEngine;
if (QmlCppEngine * const qmlEngine = qobject_cast<QmlCppEngine *>(d->m_engine))
if (Internal::GdbEngine *embeddedGdbEngine = qobject_cast<GdbEngine *>(qmlEngine->cppEngine()))
return embeddedGdbEngine;
return 0;
}
Internal::AbstractGdbAdapter *DebuggerRunControl::gdbAdapter() const
{
GdbEngine *engine = gdbEngine();
QTC_ASSERT(engine, return 0)
return engine->gdbAdapter();
}
void DebuggerRunControl::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
{
// FIXME: Use virtual functions?
if (QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(d->m_engine)) {
qmlEngine->handleRemoteSetupDone(qmlPort);
} else if (Internal::AbstractGdbAdapter *adapter = gdbAdapter()) {
if (RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter)) {
rpga->handleSetupDone(qmlPort);
} else if (RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter)) {
rgsa->handleSetupDone(gdbServerPort, qmlPort);
} else {
QTC_ASSERT(false, /* */ );
}
} else {
QTC_ASSERT(false, /* */ );
return;
}
AbstractGdbAdapter *adapter = d->gdbAdapter();
QTC_ASSERT(adapter, return);
RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter);
if (rpga) {
rpga->handleSetupDone(qmlPort);
return;
}
RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter);
if (rgsa) {
rgsa->handleSetupDone(gdbServerPort, qmlPort);
return;
}
QTC_ASSERT(false, /**/);
}
void DebuggerRunControl::handleRemoteSetupFailed(const QString &message)
{
// FIXME: Use virtual functions?
if (QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(d->m_engine)) {
qmlEngine->handleRemoteSetupFailed(message);
} else if (Internal::AbstractGdbAdapter *adapter = gdbAdapter()) {
if (RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter)) {
rpga->handleSetupFailed(message);
} else if (RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter)) {
rgsa->handleSetupFailed(message);
} else {
QTC_ASSERT(false, /* */ );
}
} else {
QTC_ASSERT(false, /* */ );
return;
}
AbstractGdbAdapter *adapter = d->gdbAdapter();
QTC_ASSERT(adapter, return);
RemotePlainGdbAdapter *rpga = qobject_cast<RemotePlainGdbAdapter *>(adapter);
if (rpga) {
rpga->handleSetupFailed(message);
return;
}
RemoteGdbServerAdapter *rgsa = qobject_cast<RemoteGdbServerAdapter *>(adapter);
if (rgsa) {
rgsa->handleSetupFailed(message);
return;
}
QTC_ASSERT(false, /**/);
}
void DebuggerRunControl::emitAddToOutputWindow(const QString &line, bool onStdErr)
......
......@@ -44,9 +44,8 @@ class Environment;
namespace Debugger {
class DebuggerEngine;
class DebuggerRunControl;
class QmlEngine;
class DebuggerRunControlPrivate;
class DebuggerStartParameters;
struct DebuggerRunnerPrivate;
namespace Internal {
class GdbEngine;
......@@ -101,9 +100,7 @@ public:
QString displayName() const;
void createEngine(const DebuggerStartParameters &startParameters);
void setCustomEnvironment(Utils::Environment env);
void startFailed();
void debuggingFinished();
RunConfiguration *runConfiguration() const;
......@@ -136,13 +133,7 @@ protected:
const DebuggerStartParameters &startParameters() const;
private:
DebuggerEngineType engineForExecutable(unsigned enabledEngineTypes, const QString &executable);
DebuggerEngineType engineForMode(unsigned enabledEngineTypes, DebuggerStartMode mode);
void initGdbEngine(Internal::GdbEngine *engine);
Internal::GdbEngine *gdbEngine() const;
Internal::AbstractGdbAdapter *gdbAdapter() const;
QScopedPointer<DebuggerRunnerPrivate> d;
QScopedPointer<DebuggerRunControlPrivate> d;
};
} // namespace Debugger
......
......@@ -68,7 +68,7 @@
namespace Debugger {
namespace Internal {
void LLDBEventListener::listen(lldb::SBListener *listener)
void LldbEventListener::listen(lldb::SBListener *listener)
{
while (true) {
lldb::SBEvent event;
......@@ -77,11 +77,11 @@ void LLDBEventListener::listen(lldb::SBListener *listener)
}
}
LLDBEngineGuest::LLDBEngineGuest()
LldbEngineGuest::LldbEngineGuest()
: IPCEngineGuest()
, m_runLock (QMutex::Recursive)
, m_running (false)
, m_worker (new LLDBEventListener)
, m_worker (new LldbEventListener)
, m_lldb (new lldb::SBDebugger)
, m_target (new lldb::SBTarget)
, m_process (new lldb::SBProcess)
......@@ -101,7 +101,7 @@ LLDBEngineGuest::LLDBEngineGuest()
setObjectName(QLatin1String("LLDBEngineGuest"));
}
LLDBEngineGuest::~LLDBEngineGuest()
LldbEngineGuest::~LldbEngineGuest()
{
delete m_lldb;
delete m_target;
......@@ -109,7 +109,7 @@ LLDBEngineGuest::~LLDBEngineGuest()
delete m_listener;
}
void LLDBEngineGuest::setupEngine()
void LldbEngineGuest::setupEngine()
{
DEBUG_FUNC_ENTER;
......@@ -124,7 +124,7 @@ void LLDBEngineGuest::setupEngine()
}
void LLDBEngineGuest::setupInferior(const QString &executable,
void LldbEngineGuest::setupInferior(const QString &executable,
const QStringList &args, const QStringList &env)
{
DEBUG_FUNC_ENTER;
......@@ -146,17 +146,17 @@ void LLDBEngineGuest::setupInferior(const QString &executable,
notifyInferiorSetupOk();
}
void LLDBEngineGuest::runEngine()
void LldbEngineGuest::runEngine()
{
DEBUG_FUNC_ENTER;
const char **argp = new const char * [m_arguments.count() + 1];
const char **argp = new const char *[m_arguments.count() + 1];
argp[m_arguments.count()] = 0;
for (int i = 0; i < m_arguments.count(); i++) {
argp[i] = m_arguments[i].data();