diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-01-06 03:42:32 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-01-06 03:42:32 +0000 |
commit | 8a8da7d17d4eb281b61d08d603c7bb180d280d5a (patch) | |
tree | dde754539a0f19329bbbcc8991e7e4be336298f8 | |
parent | faef8a402c3cc50eea556abc7340ef8bb895440b (diff) |
Add enhanced crash reporter breadcrumbs for clang_createTranslationUnitFromSourceFile().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92820 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | tools/CIndex/CIndex.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 20e68b2c5e..e6b3d60e19 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -25,6 +25,20 @@ using namespace clang; using namespace idx; +//===----------------------------------------------------------------------===// +// Crash Reporting. +//===----------------------------------------------------------------------===// + +#ifdef __APPLE__ +#include "clang/Analysis/Support/SaveAndRestore.h" +// Integrate with crash reporter. +extern "C" const char *__crashreporter_info__; +#endif + +//===----------------------------------------------------------------------===// +// Visitors. +//===----------------------------------------------------------------------===// + namespace { static enum CXCursorKind TranslateDeclRefExpr(DeclRefExpr *DRE) { NamedDecl *D = DRE->getDecl(); @@ -392,6 +406,46 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, command_line_args + num_command_line_args); unsigned NumErrors = CXXIdx->getDiags().getNumErrors(); + +#ifdef __APPLE__ + // Integrate with crash reporter. + static unsigned counter = 0; + static const char* reportStrings[16] = { 0 }; + + llvm::SmallString<1028> CrashString; + { + llvm::raw_svector_ostream Out(CrashString); + Out << "ClangCIndex [createTranslationUnitFromSourceFile]: clang"; + for (llvm::SmallVectorImpl<const char*>::iterator I=Args.begin(), + E=Args.end(); I!=E; ++I) + Out << ' ' << *I; + } + + unsigned myCounter = counter; + counter = myCounter == 15 ? 0 : myCounter + 1; + + while (reportStrings[myCounter]) { + myCounter = counter; + counter = myCounter == 15 ? 0 : myCounter + 1; + } + + SaveAndRestore<const char*> OldCrashString(reportStrings[myCounter], + CrashString.c_str()); + + // We need to create an aggregate string because multiple threads + // may be in this method at one time. The crash reporter string + // will attempt to overapproximate the set of in-flight invocations + // of this function. Race conditions can still cause this goal + // to not be achieved. + llvm::SmallString<1028> AggregateString; + { + llvm::raw_svector_ostream Out(AggregateString); + for (unsigned i = 0; i < 16; ++i) + if (reportStrings[i]) Out << reportStrings[i] << '\n'; + } + __crashreporter_info__ = AggregateString.c_str(); +#endif + llvm::OwningPtr<ASTUnit> Unit( ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(), CXXIdx->getDiags(), |