Signals.h revision 296417
1//===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines some helpful functions for dealing with the possibility of 11// unix signals occurring while your program is running. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_SUPPORT_SIGNALS_H 16#define LLVM_SUPPORT_SIGNALS_H 17 18#include <string> 19 20namespace llvm { 21class StringRef; 22class raw_ostream; 23 24namespace sys { 25 26 /// This function runs all the registered interrupt handlers, including the 27 /// removal of files registered by RemoveFileOnSignal. 28 void RunInterruptHandlers(); 29 30 /// This function registers signal handlers to ensure that if a signal gets 31 /// delivered that the named file is removed. 32 /// @brief Remove a file if a fatal signal occurs. 33 bool RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg = nullptr); 34 35 /// This function removes a file from the list of files to be removed on 36 /// signal delivery. 37 void DontRemoveFileOnSignal(StringRef Filename); 38 39 /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the 40 /// process, print a stack trace and then exit. 41 /// @brief Print a stack trace if a fatal signal occurs. 42 void PrintStackTraceOnErrorSignal(bool DisableCrashReporting = false); 43 44 /// Disable all system dialog boxes that appear when the process crashes. 45 void DisableSystemDialogsOnCrash(); 46 47 /// \brief Print the stack trace using the given \c raw_ostream object. 48 void PrintStackTrace(raw_ostream &OS); 49 50 // Run all registered signal handlers. 51 void RunSignalHandlers(); 52 53 /// AddSignalHandler - Add a function to be called when an abort/kill signal 54 /// is delivered to the process. The handler can have a cookie passed to it 55 /// to identify what instance of the handler it is. 56 void AddSignalHandler(void (*FnPtr)(void *), void *Cookie); 57 58 /// This function registers a function to be called when the user "interrupts" 59 /// the program (typically by pressing ctrl-c). When the user interrupts the 60 /// program, the specified interrupt function is called instead of the program 61 /// being killed, and the interrupt function automatically disabled. Note 62 /// that interrupt functions are not allowed to call any non-reentrant 63 /// functions. An null interrupt function pointer disables the current 64 /// installed function. Note also that the handler may be executed on a 65 /// different thread on some platforms. 66 /// @brief Register a function to be called when ctrl-c is pressed. 67 void SetInterruptFunction(void (*IF)()); 68} // End sys namespace 69} // End llvm namespace 70 71#endif 72