From 403c892838d36081e9a26e569dd0822f39b6d596 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 24 Jan 2018 23:58:16 -0800 Subject: [PATCH] --debug disables libclang crash recovery --- src/indexer.cc | 5 +++++ src/language_server_api.cc | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/indexer.cc b/src/indexer.cc index 558f551d..e9c1184b 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -2017,6 +2017,10 @@ optional>> ParseWithTu( CXIndexAction index_action = clang_IndexAction_create(index->cx_index); + // NOTE: libclang re-enables crash recovery whenever a new index is created. + if (g_debug) + clang_toggleCrashRecovery(0); + // |index_result| is a CXErrorCode instance. int index_result = clang_indexTranslationUnit( index_action, ¶m, &callback, sizeof(IndexerCallbacks), @@ -2133,6 +2137,7 @@ void ClangSanityCheck() { const unsigned kIndexOpts = 0; CXIndexAction index_action = clang_IndexAction_create(index); int index_param = 0; + clang_toggleCrashRecovery(0); clang_indexTranslationUnit(index_action, &index_param, &callback, sizeof(IndexerCallbacks), kIndexOpts, tu); clang_IndexAction_dispose(index_action); diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 440e0fee..67377b51 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -108,6 +108,10 @@ TEST_SUITE("FindIncludeLine") { } optional ReadCharFromStdinBlocking() { + // We do not use std::cin because it does not read bytes once stuck in + // cin.bad(). We can call cin.clear() but C++ iostream has other annoyance like + // std::{cin,cout} is tied by default, which causes undesired cout flush for + // cin operations. int c = getchar(); if (c >= 0) return c;