Commit eb5a60db authored by Kai Koehne's avatar Kai Koehne

Debugger: Don't expect that debug output arrives line by line

Sometimes multiple lines arrive at once through the debugger API. Handle
this gracefully for QML engine output tracking by buffering incomplete lines.

Change-Id: I295cf88d1aeb1737aa46e0a9e7ebedb7562e94e4
Reviewed-by: default avatarAurindam Jana <aurindam.jana@nokia.com>
parent 717acb6b
......@@ -100,6 +100,7 @@ private:
ApplicationLauncher m_applicationLauncher;
Utils::FileInProjectFinder fileFinder;
QTimer m_noDebugOutputTimer;
QString m_outputBuffer;
};
QmlEnginePrivate::QmlEnginePrivate(QmlEngine *q)
......@@ -280,62 +281,70 @@ bool QmlEngine::canDisplayTooltip() const
return state() == InferiorRunOk || state() == InferiorStopOk;
}
void QmlEngine::filterApplicationMessage(const QString &msg, int /*channel*/)
{
static const QString qddserver = QLatin1String("QDeclarativeDebugServer: ");
static const QString cannotRetrieveDebuggingOutput = ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput();
const int index = msg.indexOf(qddserver);
if (index != -1) {
// we're actually getting debug output
d->m_noDebugOutputTimer.stop();
QString status = msg;
status.remove(0, index + qddserver.length()); // chop of 'QDeclarativeDebugServer: '
static QString waitingForConnection = QLatin1String("Waiting for connection ");
static QString unableToListen = QLatin1String("Unable to listen ");
static QString debuggingNotEnabled = QLatin1String("Ignoring \"-qmljsdebugger=");
static QString debuggingNotEnabled2 = QLatin1String("Ignoring\"-qmljsdebugger="); // There is (was?) a bug in one of the error strings - safest to handle both
static QString connectionEstablished = QLatin1String("Connection established");
QString errorMessage;
if (status.startsWith(waitingForConnection)) {
void QmlEngine::filterApplicationMessage(const QString &output, int /*channel*/)
{
d->m_outputBuffer.append(output);
while (d->m_outputBuffer.contains(QLatin1Char('\n'))) {
const int nlIndex = d->m_outputBuffer.indexOf(QLatin1Char('\n'));
const QString msg = d->m_outputBuffer.left(nlIndex);
static const QString qddserver = QLatin1String("QDeclarativeDebugServer: ");
static const QString cannotRetrieveDebuggingOutput = ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput();
const int index = msg.indexOf(qddserver);
if (index != -1) {
// we're actually getting debug output
d->m_noDebugOutputTimer.stop();
QString status = msg;
status.remove(0, index + qddserver.length()); // chop of 'QDeclarativeDebugServer: '
static QString waitingForConnection = QLatin1String("Waiting for connection ");
static QString unableToListen = QLatin1String("Unable to listen ");
static QString debuggingNotEnabled = QLatin1String("Ignoring \"-qmljsdebugger=");
static QString debuggingNotEnabled2 = QLatin1String("Ignoring\"-qmljsdebugger="); // There is (was?) a bug in one of the error strings - safest to handle both
static QString connectionEstablished = QLatin1String("Connection established");
QString errorMessage;
if (status.startsWith(waitingForConnection)) {
beginConnection();
} else if (status.startsWith(unableToListen)) {
//: Error message shown after 'Could not connect ... debugger:"
errorMessage = tr("The port seems to be in use.");
} else if (status.startsWith(debuggingNotEnabled) || status.startsWith(debuggingNotEnabled2)) {
//: Error message shown after 'Could not connect ... debugger:"
errorMessage = tr("The application is not set up for QML/JS debugging.");
} else if (status.startsWith(connectionEstablished)) {
// nothing to do
} else {
qWarning() << "Unknown QDeclarativeDebugServer status message: " << status;
}
if (!errorMessage.isEmpty()) {
notifyEngineRunFailed();
Core::ICore * const core = Core::ICore::instance();
QMessageBox *infoBox = new QMessageBox(core->mainWindow());
infoBox->setIcon(QMessageBox::Critical);
infoBox->setWindowTitle(tr("Qt Creator"));
//: %1 is detailed error message
infoBox->setText(tr("Could not connect to the in-process QML debugger:\n%1")
.arg(errorMessage));
infoBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Help);
infoBox->setDefaultButton(QMessageBox::Ok);
infoBox->setModal(true);
connect(infoBox, SIGNAL(finished(int)),
this, SLOT(wrongSetupMessageBoxFinished(int)));
infoBox->show();
}
} else if (msg.contains(cannotRetrieveDebuggingOutput)) {
// we won't get debugging output, so just try to connect ...
beginConnection();
} else if (status.startsWith(unableToListen)) {
//: Error message shown after 'Could not connect ... debugger:"
errorMessage = tr("The port seems to be in use.");
} else if (status.startsWith(debuggingNotEnabled) || status.startsWith(debuggingNotEnabled2)) {
//: Error message shown after 'Could not connect ... debugger:"
errorMessage = tr("The application is not set up for QML/JS debugging.");
} else if (status.startsWith(connectionEstablished)) {
// nothing to do
} else {
qWarning() << "Unknown QDeclarativeDebugServer status message: " << status;
}
if (!errorMessage.isEmpty()) {
notifyEngineRunFailed();
Core::ICore * const core = Core::ICore::instance();
QMessageBox *infoBox = new QMessageBox(core->mainWindow());
infoBox->setIcon(QMessageBox::Critical);
infoBox->setWindowTitle(tr("Qt Creator"));
//: %1 is detailed error message
infoBox->setText(tr("Could not connect to the in-process QML debugger:\n%1")
.arg(errorMessage));
infoBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Help);
infoBox->setDefaultButton(QMessageBox::Ok);
infoBox->setModal(true);
connect(infoBox, SIGNAL(finished(int)),
this, SLOT(wrongSetupMessageBoxFinished(int)));
infoBox->show();
}
} else if (msg.contains(cannotRetrieveDebuggingOutput)) {
// we won't get debugging output, so just try to connect ...
beginConnection();
d->m_outputBuffer = d->m_outputBuffer.right(d->m_outputBuffer.size() - nlIndex - 1);
}
}
......
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