Commit 5e72be24 authored by hjk's avatar hjk

debugger: fix wrong assert when no engine could be constructed

parent bfd3186b
......@@ -106,138 +106,12 @@ bool checkCdbConfiguration(int, QString *, QString *)
#endif
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControlFactory
//
////////////////////////////////////////////////////////////////////////
static QString msgEngineNotAvailable(const char *engine)
{
return DebuggerPlugin::tr("The application requires the debugger engine '%1', "
"which is disabled.").arg(QLatin1String(engine));
}
// A factory to create DebuggerRunControls
DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent,
unsigned enabledEngines)
: IRunControlFactory(parent), m_enabledEngines(enabledEngines)
{}
bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
{
// return mode == ProjectExplorer::Constants::DEBUGMODE;
return mode == Constants::DEBUGMODE
&& qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
}
QString DebuggerRunControlFactory::displayName() const
{
return tr("Debug");
}
// Find Qt installation by running qmake
static inline QString findQtInstallPath(const QString &qmakePath)
{
QProcess proc;
QStringList args;
args.append(QLatin1String("-query"));
args.append(QLatin1String("QT_INSTALL_HEADERS"));
proc.start(qmakePath, args);
if (!proc.waitForStarted()) {
qWarning("%s: Cannot start '%s': %s", Q_FUNC_INFO, qPrintable(qmakePath),
qPrintable(proc.errorString()));
return QString();
}
proc.closeWriteChannel();
if (!proc.waitForFinished()) {
Utils::SynchronousProcess::stopProcess(proc);
qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(qmakePath));
return QString();
}
if (proc.exitStatus() != QProcess::NormalExit) {
qWarning("%s: '%s' crashed.", Q_FUNC_INFO, qPrintable(qmakePath));
return QString();
}
const QByteArray ba = proc.readAllStandardOutput().trimmed();
QDir dir(QString::fromLocal8Bit(ba));
if (dir.exists() && dir.cdUp())
return dir.absolutePath();
return QString();
}
static DebuggerStartParameters localStartParameters(RunConfiguration *runConfiguration)
{
DebuggerStartParameters sp;
QTC_ASSERT(runConfiguration, return sp);
LocalApplicationRunConfiguration *rc =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
QTC_ASSERT(rc, return sp);
sp.startMode = StartInternal;
sp.environment = rc->environment();
sp.workingDirectory = rc->workingDirectory();
sp.executable = rc->executable();
sp.processArgs = rc->commandLineArguments();
sp.toolChainType = rc->toolChainType();
sp.useTerminal = rc->runMode() == LocalApplicationRunConfiguration::Console;
sp.dumperLibrary = rc->dumperLibrary();
sp.dumperLibraryLocations = rc->dumperLibraryLocations();
if (debuggerCore()->isActiveDebugLanguage(QmlLanguage)) {
sp.qmlServerAddress = QLatin1String("127.0.0.1");
sp.qmlServerPort = runConfiguration->qmlDebugServerPort();
sp.projectDir = runConfiguration->target()->project()->projectDirectory();
if (runConfiguration->target()->activeBuildConfiguration())
sp.projectBuildDir = runConfiguration->target()
->activeBuildConfiguration()->buildDirectory();
sp.processArgs.append(QLatin1String("-qmljsdebugger=port:")
+ QString::number(sp.qmlServerPort));
}
// FIXME: If it's not yet build this will be empty and not filled
// when rebuild as the runConfiguration is not stored and therefore
// cannot be used to retrieve the dumper location.
//qDebug() << "DUMPER: " << sp.dumperLibrary << sp.dumperLibraryLocations;
sp.displayName = rc->displayName();
// Find qtInstallPath.
QString qmakePath = DebuggingHelperLibrary::findSystemQt(rc->environment());
if (!qmakePath.isEmpty())
sp.qtInstallPath = findQtInstallPath(qmakePath);
return sp;
}
RunControl *DebuggerRunControlFactory::create
(RunConfiguration *runConfiguration, const QString &mode)
{
QTC_ASSERT(mode == Constants::DEBUGMODE, return 0);
DebuggerStartParameters sp = localStartParameters(runConfiguration);
return create(sp, runConfiguration);
}
DebuggerRunControl *DebuggerRunControlFactory::create
(const DebuggerStartParameters &sp, RunConfiguration *runConfiguration)
{
DebuggerRunControl *runControl =
new DebuggerRunControl(runConfiguration, m_enabledEngines, sp);
if (runControl->engine())
return runControl;
qDebug() << "FAILED TO CREATE ENGINE";
delete runControl;
return 0;
}
QWidget *DebuggerRunControlFactory::createConfigurationWidget
(RunConfiguration *runConfiguration)
{
// NBS TODO: Add GDB-specific configuration widget
Q_UNUSED(runConfiguration)
return 0;
}
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControlPrivate
......@@ -525,6 +399,7 @@ QString DebuggerRunControl::displayName() const
void DebuggerRunControl::setCustomEnvironment(Utils::Environment env)
{
QTC_ASSERT(d->m_engine, return);
d->m_engine->startParameters().environment = env;
}
......@@ -595,14 +470,14 @@ void DebuggerRunControl::start()
return;
}
debuggerCore()->runControlStarted(engine());
debuggerCore()->runControlStarted(d->m_engine);
// We might get a synchronous startFailed() notification on Windows,
// when launching the process fails. Emit a proper finished() sequence.
emit started();
d->m_running = true;
engine()->startDebugger(this);
d->m_engine->startDebugger(this);
if (d->m_running) {
emit addToOutputWindowInline(this, tr("Debugging starts"), false);
......@@ -615,15 +490,15 @@ void DebuggerRunControl::startFailed()
emit addToOutputWindowInline(this, tr("Debugging has failed"), false);
d->m_running = false;
emit finished();
engine()->handleStartFailed();
d->m_engine->handleStartFailed();
}
void DebuggerRunControl::handleFinished()
{
emit addToOutputWindowInline(this, tr("Debugging has finished"), false);
if (engine())
engine()->handleFinished();
debuggerCore()->runControlFinished(engine());
if (d->m_engine)
d->m_engine->handleFinished();
debuggerCore()->runControlFinished(d->m_engine);
}
void DebuggerRunControl::showMessage(const QString &msg, int channel)
......@@ -686,4 +561,130 @@ RunConfiguration *DebuggerRunControl::runConfiguration() const
return d->m_myRunConfiguration.data();
}
////////////////////////////////////////////////////////////////////////
//
// DebuggerRunControlFactory
//
////////////////////////////////////////////////////////////////////////
// A factory to create DebuggerRunControls
DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent,
unsigned enabledEngines)
: IRunControlFactory(parent), m_enabledEngines(enabledEngines)
{}
bool DebuggerRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
{
// return mode == ProjectExplorer::Constants::DEBUGMODE;
return mode == Constants::DEBUGMODE
&& qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
}
QString DebuggerRunControlFactory::displayName() const
{
return tr("Debug");
}
// Find Qt installation by running qmake
static inline QString findQtInstallPath(const QString &qmakePath)
{
QProcess proc;
QStringList args;
args.append(QLatin1String("-query"));
args.append(QLatin1String("QT_INSTALL_HEADERS"));
proc.start(qmakePath, args);
if (!proc.waitForStarted()) {
qWarning("%s: Cannot start '%s': %s", Q_FUNC_INFO, qPrintable(qmakePath),
qPrintable(proc.errorString()));
return QString();
}
proc.closeWriteChannel();
if (!proc.waitForFinished()) {
Utils::SynchronousProcess::stopProcess(proc);
qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(qmakePath));
return QString();
}
if (proc.exitStatus() != QProcess::NormalExit) {
qWarning("%s: '%s' crashed.", Q_FUNC_INFO, qPrintable(qmakePath));
return QString();
}
const QByteArray ba = proc.readAllStandardOutput().trimmed();
QDir dir(QString::fromLocal8Bit(ba));
if (dir.exists() && dir.cdUp())
return dir.absolutePath();
return QString();
}
static DebuggerStartParameters localStartParameters(RunConfiguration *runConfiguration)
{
DebuggerStartParameters sp;
QTC_ASSERT(runConfiguration, return sp);
LocalApplicationRunConfiguration *rc =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
QTC_ASSERT(rc, return sp);
sp.startMode = StartInternal;
sp.environment = rc->environment();
sp.workingDirectory = rc->workingDirectory();
sp.executable = rc->executable();
sp.processArgs = rc->commandLineArguments();
sp.toolChainType = rc->toolChainType();
sp.useTerminal = rc->runMode() == LocalApplicationRunConfiguration::Console;
sp.dumperLibrary = rc->dumperLibrary();
sp.dumperLibraryLocations = rc->dumperLibraryLocations();
if (debuggerCore()->isActiveDebugLanguage(QmlLanguage)) {
sp.qmlServerAddress = QLatin1String("127.0.0.1");
sp.qmlServerPort = runConfiguration->qmlDebugServerPort();
sp.projectDir = runConfiguration->target()->project()->projectDirectory();
if (runConfiguration->target()->activeBuildConfiguration())
sp.projectBuildDir = runConfiguration->target()
->activeBuildConfiguration()->buildDirectory();
sp.processArgs.append(QLatin1String("-qmljsdebugger=port:")
+ QString::number(sp.qmlServerPort));
}
// FIXME: If it's not yet build this will be empty and not filled
// when rebuild as the runConfiguration is not stored and therefore
// cannot be used to retrieve the dumper location.
//qDebug() << "DUMPER: " << sp.dumperLibrary << sp.dumperLibraryLocations;
sp.displayName = rc->displayName();
// Find qtInstallPath.
QString qmakePath = DebuggingHelperLibrary::findSystemQt(rc->environment());
if (!qmakePath.isEmpty())
sp.qtInstallPath = findQtInstallPath(qmakePath);
return sp;
}
RunControl *DebuggerRunControlFactory::create
(RunConfiguration *runConfiguration, const QString &mode)
{
QTC_ASSERT(mode == Constants::DEBUGMODE, return 0);
DebuggerStartParameters sp = localStartParameters(runConfiguration);
return create(sp, runConfiguration);
}
QWidget *DebuggerRunControlFactory::createConfigurationWidget
(RunConfiguration *runConfiguration)
{
// NBS TODO: Add GDB-specific configuration widget
Q_UNUSED(runConfiguration)
return 0;
}
DebuggerRunControl *DebuggerRunControlFactory::create
(const DebuggerStartParameters &sp, RunConfiguration *runConfiguration)
{
DebuggerRunControl *runControl =
new DebuggerRunControl(runConfiguration, m_enabledEngines, sp);
if (runControl->d->m_engine)
return runControl;
delete runControl;
return 0;
}
} // namespace Debugger
......@@ -102,7 +102,7 @@ public:
void startFailed();
void debuggingFinished();
RunConfiguration *runConfiguration() const;
DebuggerEngine *engine();
DebuggerEngine *engine(); // FIXME: Remove. Only used by Maemo support.
void showMessage(const QString &msg, int channel);
......@@ -120,6 +120,7 @@ protected:
const DebuggerStartParameters &startParameters() const;
private:
friend class Internal::DebuggerRunControlFactory;
QScopedPointer<Internal::DebuggerRunControlPrivate> d;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment