Add a new 'AddSignalHandler' function to Signals.h that allows
arbitrary functions to be run when a crash happens. Delete
RemoveDirectoryOnSignal as it is dead and has never had clients.
Change PrintStackTraceOnErrorSignal to be implemented in terms of
AddSignalHandler.
I updated the Win32 versions of these APIs, but can't test them.
If there are any problems, I'd be happy to fix them as well.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66072 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/System/Win32/Signals.inc b/lib/System/Win32/Signals.inc
index 02dab86..da9fd50 100644
--- a/lib/System/Win32/Signals.inc
+++ b/lib/System/Win32/Signals.inc
@@ -39,7 +39,7 @@
static void (*InterruptFunction)() = 0;
static std::vector<llvm::sys::Path> *FilesToRemove = NULL;
-static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;
+static std::vector<std::pair<void(*)(void*), void*> > *CallBacksToRun = 0;
static bool RegisteredUnhandledExceptionFilter = false;
static bool CleanupExecuted = false;
static PTOP_LEVEL_EXCEPTION_FILTER OldFilter = NULL;
@@ -98,37 +98,6 @@
return false;
}
-// RemoveDirectoryOnSignal - The public API
-bool sys::RemoveDirectoryOnSignal(const sys::Path& path, std::string* ErrMsg) {
- // Not a directory?
- WIN32_FILE_ATTRIBUTE_DATA fi;
- if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) {
- MakeErrMsg(ErrMsg, path.toString() + ": can't get status of file");
- return true;
- }
-
- if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
- if (ErrMsg)
- *ErrMsg = path.toString() + ": not a directory";
- return true;
- }
-
- RegisterHandler();
-
- if (CleanupExecuted) {
- if (ErrMsg)
- *ErrMsg = "Process terminating -- cannot register for removal";
- return true;
- }
-
- if (DirectoriesToRemove == NULL)
- DirectoriesToRemove = new std::vector<sys::Path>;
- DirectoriesToRemove->push_back(path);
-
- LeaveCriticalSection(&CriticalSection);
- return false;
-}
-
/// PrintStackTraceOnErrorSignal - When an error signal (such as SIBABRT or
/// SIGSEGV) is delivered to the process, print a stack trace and then exit.
void sys::PrintStackTraceOnErrorSignal() {
@@ -162,14 +131,9 @@
FilesToRemove->pop_back();
}
- if (DirectoriesToRemove != NULL)
- while (!DirectoriesToRemove->empty()) {
- try {
- DirectoriesToRemove->back().eraseFromDisk(true);
- } catch (...) {
- }
- DirectoriesToRemove->pop_back();
- }
+ if (CallBacksToRun)
+ for (unsigned i = 0, e = CallBacksToRun->size(); i != e; ++i)
+ (*CallBacksToRun)[i].first((*CallBacksToRun)[i].second);
LeaveCriticalSection(&CriticalSection);
}
@@ -259,7 +223,7 @@
#endif
} catch (...) {
- assert(!"Crashed in LLVMUnhandledExceptionFilter");
+ assert(0 && "Crashed in LLVMUnhandledExceptionFilter");
}
// Allow dialog box to pop up allowing choice to start debugger.
@@ -292,3 +256,13 @@
return FALSE;
}
+/// AddSignalHandler - Add a function to be called when a signal is delivered
+/// to the process. The handler can have a cookie passed to it to identify
+/// what instance of the handler it is.
+void sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) {
+ if (CallBacksToRun == 0)
+ CallBacksToRun = new std::vector<std::pair<void(*)(void*), void*> >();
+ CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie));
+ std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
+}
+