forked from qt-creator/qt-creator
ClangCodeModel: Catch exceptions in semantic highlighter
I've repeatedly encountered std::bad_alloc recently, and would like to get more info about where it is triggered. The crash comes from Qt, apparently after the original thread has alresdy finished, so the original location is not found in the stack trace. Change-Id: I7bbdcce6534ea0c846a69af33ad8634c3415572d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <new>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -1349,8 +1350,13 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc,
|
|||||||
doc = QPointer(doc), rev = doc->document()->revision(),
|
doc = QPointer(doc), rev = doc->document()->revision(),
|
||||||
clangdVersion = q->versionNumber(),
|
clangdVersion = q->versionNumber(),
|
||||||
this] {
|
this] {
|
||||||
return Utils::runAsync(doSemanticHighlighting, filePath, tokens, text, ast, doc, rev,
|
try {
|
||||||
clangdVersion, highlightingTimer);
|
return Utils::runAsync(doSemanticHighlighting, filePath, tokens, text, ast, doc,
|
||||||
|
rev, clangdVersion, highlightingTimer);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
qWarning() << "caught" << e.what() << "in main highlighting thread";
|
||||||
|
return QFuture<HighlightingResult>();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isTesting) {
|
if (isTesting) {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
using namespace LanguageClient;
|
using namespace LanguageClient;
|
||||||
using namespace LanguageServerProtocol;
|
using namespace LanguageServerProtocol;
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
@@ -345,7 +347,15 @@ void doSemanticHighlighting(
|
|||||||
return HighlightingResult(token.line, token.column, token.length, styles);
|
return HighlightingResult(token.line, token.column, token.length, styles);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto results = QtConcurrent::blockingMapped<HighlightingResults>(tokens, toResult);
|
const auto safeToResult = [&toResult](const ExpandedSemanticToken &token) {
|
||||||
|
try {
|
||||||
|
return toResult(token);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
qWarning() << "caught" << e.what() << "in toResult()";
|
||||||
|
return HighlightingResult();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
auto results = QtConcurrent::blockingMapped<HighlightingResults>(tokens, safeToResult);
|
||||||
const QList<BlockRange> ifdefedOutBlocks = cleanupDisabledCode(results, &doc, docContents);
|
const QList<BlockRange> ifdefedOutBlocks = cleanupDisabledCode(results, &doc, docContents);
|
||||||
ExtraHighlightingResultsCollector(future, results, filePath, ast, &doc, docContents,
|
ExtraHighlightingResultsCollector(future, results, filePath, ast, &doc, docContents,
|
||||||
clangdVersion).collect();
|
clangdVersion).collect();
|
||||||
|
|||||||
Reference in New Issue
Block a user