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