|
|
|||
File indexing completed on 2026-05-10 08:44:34
0001 //===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file defines some helpful functions for dealing with the possibility of 0010 // unix signals occurring while your program is running. 0011 // 0012 //===----------------------------------------------------------------------===// 0013 0014 #ifndef LLVM_SUPPORT_SIGNALS_H 0015 #define LLVM_SUPPORT_SIGNALS_H 0016 0017 #include <cstdint> 0018 #include <string> 0019 0020 namespace llvm { 0021 class StringRef; 0022 class raw_ostream; 0023 0024 namespace sys { 0025 0026 /// This function runs all the registered interrupt handlers, including the 0027 /// removal of files registered by RemoveFileOnSignal. 0028 void RunInterruptHandlers(); 0029 0030 /// This function registers signal handlers to ensure that if a signal gets 0031 /// delivered that the named file is removed. 0032 /// Remove a file if a fatal signal occurs. 0033 bool RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg = nullptr); 0034 0035 /// This function removes a file from the list of files to be removed on 0036 /// signal delivery. 0037 void DontRemoveFileOnSignal(StringRef Filename); 0038 0039 /// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the 0040 /// process, print a stack trace and then exit. 0041 /// Print a stack trace if a fatal signal occurs. 0042 /// \param Argv0 the current binary name, used to find the symbolizer 0043 /// relative to the current binary before searching $PATH; can be 0044 /// StringRef(), in which case we will only search $PATH. 0045 /// \param DisableCrashReporting if \c true, disable the normal crash 0046 /// reporting mechanisms on the underlying operating system. 0047 void PrintStackTraceOnErrorSignal(StringRef Argv0, 0048 bool DisableCrashReporting = false); 0049 0050 /// Disable all system dialog boxes that appear when the process crashes. 0051 void DisableSystemDialogsOnCrash(); 0052 0053 /// Print the stack trace using the given \c raw_ostream object. 0054 /// \param Depth refers to the number of stackframes to print. If not 0055 /// specified, the entire frame is printed. 0056 void PrintStackTrace(raw_ostream &OS, int Depth = 0); 0057 0058 // Run all registered signal handlers. 0059 void RunSignalHandlers(); 0060 0061 using SignalHandlerCallback = void (*)(void *); 0062 0063 /// Add a function to be called when an abort/kill signal is delivered to the 0064 /// process. The handler can have a cookie passed to it to identify what 0065 /// instance of the handler it is. 0066 void AddSignalHandler(SignalHandlerCallback FnPtr, void *Cookie); 0067 0068 /// This function registers a function to be called when the user "interrupts" 0069 /// the program (typically by pressing ctrl-c). When the user interrupts the 0070 /// program, the specified interrupt function is called instead of the program 0071 /// being killed, and the interrupt function automatically disabled. 0072 /// 0073 /// Note that interrupt functions are not allowed to call any non-reentrant 0074 /// functions. An null interrupt function pointer disables the current 0075 /// installed function. Note also that the handler may be executed on a 0076 /// different thread on some platforms. 0077 void SetInterruptFunction(void (*IF)()); 0078 0079 /// Registers a function to be called when an "info" signal is delivered to 0080 /// the process. 0081 /// 0082 /// On POSIX systems, this will be SIGUSR1; on systems that have it, SIGINFO 0083 /// will also be used (typically ctrl-t). 0084 /// 0085 /// Note that signal handlers are not allowed to call any non-reentrant 0086 /// functions. An null function pointer disables the current installed 0087 /// function. Note also that the handler may be executed on a different 0088 /// thread on some platforms. 0089 void SetInfoSignalFunction(void (*Handler)()); 0090 0091 /// Registers a function to be called in a "one-shot" manner when a pipe 0092 /// signal is delivered to the process (i.e., on a failed write to a pipe). 0093 /// After the pipe signal is handled once, the handler is unregistered. 0094 /// 0095 /// The LLVM signal handling code will not install any handler for the pipe 0096 /// signal unless one is provided with this API (see \ref 0097 /// DefaultOneShotPipeSignalHandler). This handler must be provided before 0098 /// any other LLVM signal handlers are installed: the \ref InitLLVM 0099 /// constructor has a flag that can simplify this setup. 0100 /// 0101 /// Note that the handler is not allowed to call any non-reentrant 0102 /// functions. A null handler pointer disables the current installed 0103 /// function. Note also that the handler may be executed on a 0104 /// different thread on some platforms. 0105 void SetOneShotPipeSignalFunction(void (*Handler)()); 0106 0107 /// On Unix systems and Windows, this function exits with an "IO error" exit 0108 /// code. 0109 void DefaultOneShotPipeSignalHandler(); 0110 0111 #ifdef _WIN32 0112 /// Windows does not support signals and this handler must be called manually. 0113 void CallOneShotPipeSignalHandler(); 0114 #endif 0115 0116 /// This function does the following: 0117 /// - clean up any temporary files registered with RemoveFileOnSignal() 0118 /// - dump the callstack from the exception context 0119 /// - call any relevant interrupt/signal handlers 0120 /// - create a core/mini dump of the exception context whenever possible 0121 /// Context is a system-specific failure context: it is the signal type on 0122 /// Unix; the ExceptionContext on Windows. 0123 void CleanupOnSignal(uintptr_t Context); 0124 0125 void unregisterHandlers(); 0126 } // End sys namespace 0127 } // End llvm namespace 0128 0129 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|