diff --git a/src/command_line.cc b/src/command_line.cc index e1674dee..631c0c50 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -49,6 +49,7 @@ // items per second completed and scales up/down number of running threads. std::string g_init_options; +bool g_debug; namespace { @@ -417,6 +418,7 @@ int main(int argc, char** argv) { // std::this_thread::sleep_for(std::chrono::seconds(10)); PlatformInit(); + g_debug = HasOption(options, "--debug"); IndexInit(); bool print_help = true; @@ -435,6 +437,7 @@ int main(int argc, char** argv) { } if (HasOption(options, "--test-unit")) { + g_debug = true; print_help = false; doctest::Context context; context.applyCommandLine(argc, argv); @@ -444,6 +447,7 @@ int main(int argc, char** argv) { } if (HasOption(options, "--test-index")) { + g_debug = true; print_help = false; if (!RunIndexTests(options["--test-index"], !HasOption(options, "--ci"))) return -1; @@ -485,17 +489,22 @@ int main(int argc, char** argv) { std::cout << R"help(cquery is a low-latency C/C++/Objective-C language server. -Command line options: +Mode: --language-server Run as a language server. This implements the language server spec over STDIN and STDOUT. - --init - Override user provided initialization options. --test-unit Run unit tests. --test-index Run index tests. opt_filter_path can be used to specify which test to run (ie, "foo" will run all tests which contain "foo" in the path). If not provided all tests are run. + +Other command line options: + --debug Disable libclang crash recovery so that in case of libclang or + indexer callback issue, the process will crash and we can + get a stack trace. + --init + Override user provided initialization options. --log-stdin-stdout-to-stderr Print stdin and stdout messages to stderr. This is a aid for developing new language clients, as it makes it easier to figure diff --git a/src/indexer.cc b/src/indexer.cc index 2f44e66e..558f551d 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -17,6 +17,9 @@ // TODO: See if we can use clang_indexLoc_getFileLocation to get a type ref on // |Foobar| in DISALLOW_COPY(Foobar) +// Defined in command_line.cc +extern bool g_debug; + namespace { constexpr bool kIndexStdDeclarations = true; @@ -2014,11 +2017,6 @@ optional>> ParseWithTu( CXIndexAction index_action = clang_IndexAction_create(index->cx_index); - // NOTE: libclang re-enables crash recovery whenever a new index is created. - // To have clang crash toggle crash recovery right before calling - // clang_indexTranslationUnit. - // clang_toggleCrashRecovery(0); - // |index_result| is a CXErrorCode instance. int index_result = clang_indexTranslationUnit( index_action, ¶m, &callback, sizeof(IndexerCallbacks), @@ -2090,7 +2088,8 @@ void ConcatTypeAndName(std::string& type, const std::string& name) { void IndexInit() { clang_enableStackTraces(); - clang_toggleCrashRecovery(1); + if (!g_debug) + clang_toggleCrashRecovery(1); } void ClangSanityCheck() { @@ -2134,7 +2133,6 @@ 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);