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