Signals.h revision 249423
1218885Sdim//===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim// 10218885Sdim// This file defines some helpful functions for dealing with the possibility of 11221345Sdim// unix signals occurring while your program is running. 12218885Sdim// 13218885Sdim//===----------------------------------------------------------------------===// 14218885Sdim 15249423Sdim#ifndef LLVM_SUPPORT_SIGNALS_H 16249423Sdim#define LLVM_SUPPORT_SIGNALS_H 17218885Sdim 18218885Sdim#include "llvm/Support/Path.h" 19249423Sdim#include <cstdio> 20218885Sdim 21218885Sdimnamespace llvm { 22218885Sdimnamespace sys { 23218885Sdim 24218885Sdim /// This function runs all the registered interrupt handlers, including the 25218885Sdim /// removal of files registered by RemoveFileOnSignal. 26218885Sdim void RunInterruptHandlers(); 27218885Sdim 28218885Sdim /// This function registers signal handlers to ensure that if a signal gets 29218885Sdim /// delivered that the named file is removed. 30218885Sdim /// @brief Remove a file if a fatal signal occurs. 31218885Sdim bool RemoveFileOnSignal(const Path &Filename, std::string* ErrMsg = 0); 32218885Sdim 33218885Sdim /// This function removes a file from the list of files to be removed on 34218885Sdim /// signal delivery. 35218885Sdim void DontRemoveFileOnSignal(const Path &Filename); 36218885Sdim 37218885Sdim /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the 38218885Sdim /// process, print a stack trace and then exit. 39218885Sdim /// @brief Print a stack trace if a fatal signal occurs. 40218885Sdim void PrintStackTraceOnErrorSignal(); 41218885Sdim 42249423Sdim /// \brief Print the stack trace using the given \c FILE object. 43249423Sdim void PrintStackTrace(FILE *); 44249423Sdim 45218885Sdim /// AddSignalHandler - Add a function to be called when an abort/kill signal 46218885Sdim /// is delivered to the process. The handler can have a cookie passed to it 47218885Sdim /// to identify what instance of the handler it is. 48218885Sdim void AddSignalHandler(void (*FnPtr)(void *), void *Cookie); 49218885Sdim 50218885Sdim /// This function registers a function to be called when the user "interrupts" 51218885Sdim /// the program (typically by pressing ctrl-c). When the user interrupts the 52218885Sdim /// program, the specified interrupt function is called instead of the program 53218885Sdim /// being killed, and the interrupt function automatically disabled. Note 54218885Sdim /// that interrupt functions are not allowed to call any non-reentrant 55218885Sdim /// functions. An null interrupt function pointer disables the current 56218885Sdim /// installed function. Note also that the handler may be executed on a 57218885Sdim /// different thread on some platforms. 58218885Sdim /// @brief Register a function to be called when ctrl-c is pressed. 59218885Sdim void SetInterruptFunction(void (*IF)()); 60218885Sdim} // End sys namespace 61218885Sdim} // End llvm namespace 62218885Sdim 63218885Sdim#endif 64