mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
CrashRecoveryContext
This commit is contained in:
parent
0f63be2418
commit
af77e6615d
@ -5,11 +5,12 @@
|
|||||||
#include "log.hh"
|
#include "log.hh"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
#include "clang/Frontend/CompilerInstance.h"
|
#include <clang/Frontend/CompilerInstance.h>
|
||||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
#include <clang/Frontend/FrontendDiagnostic.h>
|
||||||
#include <clang/Sema/CodeCompleteConsumer.h>
|
#include <clang/Sema/CodeCompleteConsumer.h>
|
||||||
#include <llvm/ADT/Twine.h>
|
#include <llvm/ADT/Twine.h>
|
||||||
#include <llvm/Config/llvm-config.h>
|
#include <llvm/Config/llvm-config.h>
|
||||||
|
#include <llvm/Support/CrashRecoveryContext.h>
|
||||||
#include <llvm/Support/Threading.h>
|
#include <llvm/Support/Threading.h>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -100,7 +100,7 @@ std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Create(
|
|||||||
/*UserFilesAreVolatile=*/true, false,
|
/*UserFilesAreVolatile=*/true, false,
|
||||||
ret->PCHCO->getRawReader().getFormat(), &ErrUnit));
|
ret->PCHCO->getRawReader().getFormat(), &ErrUnit));
|
||||||
};
|
};
|
||||||
if (!RunSafely(CRC, parse)) {
|
if (!CRC.RunSafely(parse)) {
|
||||||
LOG_S(ERROR)
|
LOG_S(ERROR)
|
||||||
<< "clang crashed for " << filepath << "\n"
|
<< "clang crashed for " << filepath << "\n"
|
||||||
<< StringJoin(args, " ") + " -fsyntax-only";
|
<< StringJoin(args, " ") + " -fsyntax-only";
|
||||||
@ -116,7 +116,7 @@ std::unique_ptr<ClangTranslationUnit> ClangTranslationUnit::Create(
|
|||||||
int ClangTranslationUnit::Reparse(llvm::CrashRecoveryContext &CRC,
|
int ClangTranslationUnit::Reparse(llvm::CrashRecoveryContext &CRC,
|
||||||
const WorkingFiles::Snapshot &snapshot) {
|
const WorkingFiles::Snapshot &snapshot) {
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
auto parse = [&]() { ret = Unit->Reparse(PCHCO, GetRemapped(snapshot)); };
|
(void)CRC.RunSafely(
|
||||||
(void)RunSafely(CRC, parse);
|
[&]() { ret = Unit->Reparse(PCHCO, GetRemapped(snapshot)); });
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,6 @@ Range FromTokenRange(const clang::SourceManager &SM, const clang::LangOptions &L
|
|||||||
clang::SourceRange R,
|
clang::SourceRange R,
|
||||||
llvm::sys::fs::UniqueID *UniqueID = nullptr);
|
llvm::sys::fs::UniqueID *UniqueID = nullptr);
|
||||||
|
|
||||||
template <typename Fn>
|
|
||||||
bool RunSafely(llvm::CrashRecoveryContext &CRC, Fn &&fn) {
|
|
||||||
const char *env = getenv("CCLS_CRASH_RECOVERY");
|
|
||||||
if (env && strcmp(env, "0") == 0) {
|
|
||||||
fn();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return CRC.RunSafely(fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ClangTranslationUnit {
|
struct ClangTranslationUnit {
|
||||||
static std::unique_ptr<ClangTranslationUnit>
|
static std::unique_ptr<ClangTranslationUnit>
|
||||||
Create(const std::string &filepath, const std::vector<std::string> &args,
|
Create(const std::string &filepath, const std::vector<std::string> &args,
|
||||||
|
@ -1153,7 +1153,7 @@ std::vector<std::unique_ptr<IndexFile>> Index(
|
|||||||
/*CaptureDiagnostics=*/true, 0, false, false,
|
/*CaptureDiagnostics=*/true, 0, false, false,
|
||||||
/*UserFilesAreVolatile=*/true);
|
/*UserFilesAreVolatile=*/true);
|
||||||
};
|
};
|
||||||
if (!RunSafely(CRC, compile)) {
|
if (!CRC.RunSafely(compile)) {
|
||||||
LOG_S(ERROR) << "clang crashed for " << file;
|
LOG_S(ERROR) << "clang crashed for " << file;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
using namespace ccls;
|
using namespace ccls;
|
||||||
|
|
||||||
#include <llvm/Support/CommandLine.h>
|
#include <llvm/Support/CommandLine.h>
|
||||||
|
#include <llvm/Support/CrashRecoveryContext.h>
|
||||||
#include <llvm/Support/Process.h>
|
#include <llvm/Support/Process.h>
|
||||||
#include <llvm/Support/Program.h>
|
#include <llvm/Support/Program.h>
|
||||||
#include <llvm/Support/Signals.h>
|
#include <llvm/Support/Signals.h>
|
||||||
@ -55,7 +56,9 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pipeline::Init();
|
pipeline::Init();
|
||||||
idx::IndexInit();
|
const char *env = getenv("CCLS_CRASH_RECOVERY");
|
||||||
|
if (!env || strcmp(env, "0") != 0)
|
||||||
|
CrashRecoveryContext::Enable();
|
||||||
|
|
||||||
bool language_server = true;
|
bool language_server = true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user