Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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 | |
| 20 | namespace llvm { |
| 21 | class StringRef; |
| 22 | class raw_ostream; |
| 23 | |
| 24 | namespace 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. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame^] | 32 | /// Remove a file if a fatal signal occurs. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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 SIGABRT or SIGSEGV) is delivered to the |
| 40 | /// process, print a stack trace and then exit. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame^] | 41 | /// Print a stack trace if a fatal signal occurs. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 42 | /// \param Argv0 the current binary name, used to find the symbolizer |
| 43 | /// relative to the current binary before searching $PATH; can be |
| 44 | /// StringRef(), in which case we will only search $PATH. |
| 45 | /// \param DisableCrashReporting if \c true, disable the normal crash |
| 46 | /// reporting mechanisms on the underlying operating system. |
| 47 | void PrintStackTraceOnErrorSignal(StringRef Argv0, |
| 48 | bool DisableCrashReporting = false); |
| 49 | |
| 50 | /// Disable all system dialog boxes that appear when the process crashes. |
| 51 | void DisableSystemDialogsOnCrash(); |
| 52 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame^] | 53 | /// Print the stack trace using the given \c raw_ostream object. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 54 | void PrintStackTrace(raw_ostream &OS); |
| 55 | |
| 56 | // Run all registered signal handlers. |
| 57 | void RunSignalHandlers(); |
| 58 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame^] | 59 | using SignalHandlerCallback = void (*)(void *); |
| 60 | |
| 61 | /// Add a function to be called when an abort/kill signal is delivered to the |
| 62 | /// process. The handler can have a cookie passed to it to identify what |
| 63 | /// instance of the handler it is. |
| 64 | void AddSignalHandler(SignalHandlerCallback FnPtr, void *Cookie); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 65 | |
| 66 | /// This function registers a function to be called when the user "interrupts" |
| 67 | /// the program (typically by pressing ctrl-c). When the user interrupts the |
| 68 | /// program, the specified interrupt function is called instead of the program |
| 69 | /// being killed, and the interrupt function automatically disabled. Note |
| 70 | /// that interrupt functions are not allowed to call any non-reentrant |
| 71 | /// functions. An null interrupt function pointer disables the current |
| 72 | /// installed function. Note also that the handler may be executed on a |
| 73 | /// different thread on some platforms. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame^] | 74 | /// Register a function to be called when ctrl-c is pressed. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 75 | void SetInterruptFunction(void (*IF)()); |
| 76 | } // End sys namespace |
| 77 | } // End llvm namespace |
| 78 | |
| 79 | #endif |