Signals.h revision 309124
150477Speter//===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===// 2139749Simp// 335388Smjacob// The LLVM Compiler Infrastructure 435388Smjacob// 5154704Smjacob// This file is distributed under the University of Illinois Open Source 635388Smjacob// License. See LICENSE.TXT for details. 752347Smjacob// 835388Smjacob//===----------------------------------------------------------------------===// 935388Smjacob// 1035388Smjacob// This file defines some helpful functions for dealing with the possibility of 1135388Smjacob// unix signals occurring while your program is running. 1235388Smjacob// 1335388Smjacob//===----------------------------------------------------------------------===// 1466189Smjacob 1535388Smjacob#ifndef LLVM_SUPPORT_SIGNALS_H 1635388Smjacob#define LLVM_SUPPORT_SIGNALS_H 1735388Smjacob 1835388Smjacob#include <string> 1935388Smjacob 2035388Smjacobnamespace llvm { 2135388Smjacobclass StringRef; 2235388Smjacobclass raw_ostream; 2335388Smjacob 2435388Smjacobnamespace sys { 2535388Smjacob 2635388Smjacob /// This function runs all the registered interrupt handlers, including the 2735388Smjacob /// removal of files registered by RemoveFileOnSignal. 2835388Smjacob void RunInterruptHandlers(); 2935388Smjacob 3035388Smjacob /// This function registers signal handlers to ensure that if a signal gets 3135388Smjacob /// delivered that the named file is removed. 3235388Smjacob /// @brief Remove a file if a fatal signal occurs. 3344819Smjacob bool RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg = nullptr); 34163899Smjacob 3535388Smjacob /// This function removes a file from the list of files to be removed on 3635388Smjacob /// signal delivery. 3735388Smjacob void DontRemoveFileOnSignal(StringRef Filename); 38163899Smjacob 3935388Smjacob /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the 4035388Smjacob /// process, print a stack trace and then exit. 4135388Smjacob /// \brief Print a stack trace if a fatal signal occurs. 42163899Smjacob /// \param Argv0 the current binary name, used to find the symbolizer 4342131Smjacob /// relative to the current binary before searching $PATH; can be 4435388Smjacob /// StringRef(), in which case we will only search $PATH. 45155704Smjacob /// \param DisableCrashReporting if \c true, disable the normal crash 46163899Smjacob /// reporting mechanisms on the underlying operating system. 47155704Smjacob void PrintStackTraceOnErrorSignal(StringRef Argv0, 4853487Smjacob bool DisableCrashReporting = false); 4935388Smjacob 50163899Smjacob /// Disable all system dialog boxes that appear when the process crashes. 51163899Smjacob void DisableSystemDialogsOnCrash(); 5239235Sgibbs 5335388Smjacob /// \brief Print the stack trace using the given \c raw_ostream object. 5443420Smjacob void PrintStackTrace(raw_ostream &OS); 5535388Smjacob 56155704Smjacob // Run all registered signal handlers. 5735388Smjacob void RunSignalHandlers(); 5882689Smjacob 59163899Smjacob /// AddSignalHandler - Add a function to be called when an abort/kill signal 60163899Smjacob /// is delivered to the process. The handler can have a cookie passed to it 61163899Smjacob /// to identify what instance of the handler it is. 62155704Smjacob void AddSignalHandler(void (*FnPtr)(void *), void *Cookie); 63155704Smjacob 64163899Smjacob /// This function registers a function to be called when the user "interrupts" 65163899Smjacob /// the program (typically by pressing ctrl-c). When the user interrupts the 66155704Smjacob /// program, the specified interrupt function is called instead of the program 67155704Smjacob /// being killed, and the interrupt function automatically disabled. Note 68155704Smjacob /// that interrupt functions are not allowed to call any non-reentrant 69163899Smjacob /// functions. An null interrupt function pointer disables the current 70155704Smjacob /// installed function. Note also that the handler may be executed on a 71155704Smjacob /// different thread on some platforms. 7235388Smjacob /// @brief Register a function to be called when ctrl-c is pressed. 7335388Smjacob void SetInterruptFunction(void (*IF)()); 7464087Smjacob} // End sys namespace 7564087Smjacob} // End llvm namespace 7664087Smjacob 7782689Smjacob#endif 78164272Smjacob