LLVM API Documentation

Signals.h
Go to the documentation of this file.
00001 //===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines some helpful functions for dealing with the possibility of
00011 // unix signals occurring while your program is running.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_SUPPORT_SIGNALS_H
00016 #define LLVM_SUPPORT_SIGNALS_H
00017 
00018 #include "llvm/Support/Path.h"
00019 #include <cstdio>
00020 
00021 namespace llvm {
00022 namespace sys {
00023 
00024   /// This function runs all the registered interrupt handlers, including the
00025   /// removal of files registered by RemoveFileOnSignal.
00026   void RunInterruptHandlers();
00027 
00028   /// This function registers signal handlers to ensure that if a signal gets
00029   /// delivered that the named file is removed.
00030   /// @brief Remove a file if a fatal signal occurs.
00031   bool RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg = nullptr);
00032 
00033   /// This function removes a file from the list of files to be removed on
00034   /// signal delivery.
00035   void DontRemoveFileOnSignal(StringRef Filename);
00036 
00037   /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the
00038   /// process, print a stack trace and then exit.
00039   /// @brief Print a stack trace if a fatal signal occurs.
00040   void PrintStackTraceOnErrorSignal();
00041 
00042   /// \brief Print the stack trace using the given \c FILE object.
00043   void PrintStackTrace(FILE *);
00044 
00045   /// AddSignalHandler - Add a function to be called when an abort/kill signal
00046   /// is delivered to the process.  The handler can have a cookie passed to it
00047   /// to identify what instance of the handler it is.
00048   void AddSignalHandler(void (*FnPtr)(void *), void *Cookie);
00049 
00050   /// This function registers a function to be called when the user "interrupts"
00051   /// the program (typically by pressing ctrl-c).  When the user interrupts the
00052   /// program, the specified interrupt function is called instead of the program
00053   /// being killed, and the interrupt function automatically disabled.  Note
00054   /// that interrupt functions are not allowed to call any non-reentrant
00055   /// functions.  An null interrupt function pointer disables the current
00056   /// installed function.  Note also that the handler may be executed on a
00057   /// different thread on some platforms.
00058   /// @brief Register a function to be called when ctrl-c is pressed.
00059   void SetInterruptFunction(void (*IF)());
00060 } // End sys namespace
00061 } // End llvm namespace
00062 
00063 #endif