[cfe-commits] r118274 - in /cfe/trunk/tools/libclang: CIndex.cpp CIndexCodeCompletion.cpp CIndexer.h

Daniel Dunbar daniel at zuster.org
Fri Nov 5 00:19:31 PDT 2010


Author: ddunbar
Date: Fri Nov  5 02:19:31 2010
New Revision: 118274

URL: http://llvm.org/viewvc/llvm-project?rev=118274&view=rev
Log:
libclang: Add some support for running certain entry points in a "safety"
thread, primarily to get a larger stack.
 - Yes, I feel dirty.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
    cfe/trunk/tools/libclang/CIndexer.h

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=118274&r1=118273&r2=118274&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Nov  5 02:19:31 2010
@@ -2139,7 +2139,7 @@
                                     num_unsaved_files, options, 0 };
   llvm::CrashRecoveryContext CRC;
 
-  if (!CRC.RunSafely(clang_parseTranslationUnit_Impl, &PTUI)) {
+  if (!RunSafely(CRC, clang_parseTranslationUnit_Impl, &PTUI)) {
     fprintf(stderr, "libclang: crash detected during parsing: {\n");
     fprintf(stderr, "  'source_filename' : '%s'\n", source_filename);
     fprintf(stderr, "  'command_line_args' : [");
@@ -2238,7 +2238,7 @@
                                       options, 0 };
   llvm::CrashRecoveryContext CRC;
 
-  if (!CRC.RunSafely(clang_reparseTranslationUnit_Impl, &RTUI)) {
+  if (!RunSafely(CRC, clang_reparseTranslationUnit_Impl, &RTUI)) {
     fprintf(stderr, "libclang: crash detected during reparsing\n");
     static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
     return 1;
@@ -4431,6 +4431,27 @@
 // Misc. utility functions.
 //===----------------------------------------------------------------------===//
 
+static unsigned SafetyStackThreadSize = 0;
+
+namespace clang {
+
+bool RunSafely(llvm::CrashRecoveryContext &CRC,
+               void (*Fn)(void*), void *UserData) {
+  if (unsigned Size = GetSafetyThreadStackSize())
+    return CRC.RunSafelyOnThread(Fn, UserData, Size);
+  return CRC.RunSafely(Fn, UserData);
+}
+
+unsigned GetSafetyThreadStackSize() {
+  return SafetyStackThreadSize;
+}
+
+void SetSafetyThreadStackSize(unsigned Value) {
+  SafetyStackThreadSize = Value;
+}
+
+}
+
 extern "C" {
 
 CXString clang_getClangVersion() {

Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=118274&r1=118273&r2=118274&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Fri Nov  5 02:19:31 2010
@@ -480,7 +480,7 @@
                               options, 0 };
   llvm::CrashRecoveryContext CRC;
 
-  if (!CRC.RunSafely(clang_codeCompleteAt_Impl, &CCAI)) {
+  if (!RunSafely(CRC, clang_codeCompleteAt_Impl, &CCAI)) {
     fprintf(stderr, "libclang: crash detected in code completion\n");
     static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
     return 0;

Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=118274&r1=118273&r2=118274&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Fri Nov  5 02:19:31 2010
@@ -1,4 +1,4 @@
-//===- CIndexer.h - Clang-C Source Indexing Library -----------------------===//
+//===- CIndexer.h - Clang-C Source Indexing Library -------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -20,6 +20,10 @@
 #include "llvm/System/Path.h"
 #include <vector>
 
+namespace llvm {
+  class CrashRecoveryContext;
+}
+
 namespace clang {
 namespace cxstring {
   CXString createCXString(const char *String, bool DupString = false);
@@ -66,6 +70,20 @@
                   struct CXUnsavedFile *unsaved_files,
                   std::vector<std::string> &RemapArgs,
                   std::vector<llvm::sys::Path> &TemporaryFiles);
+
+  /// \brief Return the current size to request for "safety".
+  unsigned GetSafetyThreadStackSize();
+
+  /// \brief Set the current size to request for "safety" (or 0, if safety
+  /// threads should not be used).
+  void SetSafetyThreadStackSize(unsigned Value);
+
+  /// \brief Execution the given code "safely", using crash recovery or safety
+  /// threads when possible.
+  ///
+  /// \return False if a crash was detected.
+  bool RunSafely(llvm::CrashRecoveryContext &CRC,
+                 void (*Fn)(void*), void *UserData);
 }
 
 #endif





More information about the cfe-commits mailing list