LLVM  10.0.0svn
Signals.h
Go to the documentation of this file.
1 //===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines some helpful functions for dealing with the possibility of
10 // unix signals occurring while your program is running.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_SIGNALS_H
15 #define LLVM_SUPPORT_SIGNALS_H
16 
17 #include <string>
18 
19 namespace llvm {
20 class StringRef;
21 class raw_ostream;
22 
23 namespace sys {
24 
25  /// This function runs all the registered interrupt handlers, including the
26  /// removal of files registered by RemoveFileOnSignal.
27  void RunInterruptHandlers();
28 
29  /// This function registers signal handlers to ensure that if a signal gets
30  /// delivered that the named file is removed.
31  /// Remove a file if a fatal signal occurs.
32  bool RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg = nullptr);
33 
34  /// This function removes a file from the list of files to be removed on
35  /// signal delivery.
36  void DontRemoveFileOnSignal(StringRef Filename);
37 
38  /// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
39  /// process, print a stack trace and then exit.
40  /// Print a stack trace if a fatal signal occurs.
41  /// \param Argv0 the current binary name, used to find the symbolizer
42  /// relative to the current binary before searching $PATH; can be
43  /// StringRef(), in which case we will only search $PATH.
44  /// \param DisableCrashReporting if \c true, disable the normal crash
45  /// reporting mechanisms on the underlying operating system.
46  void PrintStackTraceOnErrorSignal(StringRef Argv0,
47  bool DisableCrashReporting = false);
48 
49  /// Disable all system dialog boxes that appear when the process crashes.
51 
52  /// Print the stack trace using the given \c raw_ostream object.
53  void PrintStackTrace(raw_ostream &OS);
54 
55  // Run all registered signal handlers.
56  void RunSignalHandlers();
57 
58  using SignalHandlerCallback = void (*)(void *);
59 
60  /// Add a function to be called when an abort/kill signal is delivered to the
61  /// process. The handler can have a cookie passed to it to identify what
62  /// instance of the handler it is.
63  void AddSignalHandler(SignalHandlerCallback FnPtr, void *Cookie);
64 
65  /// This function registers a function to be called when the user "interrupts"
66  /// the program (typically by pressing ctrl-c). When the user interrupts the
67  /// program, the specified interrupt function is called instead of the program
68  /// being killed, and the interrupt function automatically disabled.
69  ///
70  /// Note 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.
74  void SetInterruptFunction(void (*IF)());
75 
76  /// Registers a function to be called when an "info" signal is delivered to
77  /// the process.
78  ///
79  /// On POSIX systems, this will be SIGUSR1; on systems that have it, SIGINFO
80  /// will also be used (typically ctrl-t).
81  ///
82  /// Note that signal handlers are not allowed to call any non-reentrant
83  /// functions. An null function pointer disables the current installed
84  /// function. Note also that the handler may be executed on a different
85  /// thread on some platforms.
86  void SetInfoSignalFunction(void (*Handler)());
87 
88  /// Registers a function to be called when a "pipe" signal is delivered to
89  /// the process.
90  ///
91  /// The "pipe" signal typically indicates a failed write to a pipe (SIGPIPE).
92  /// The default installed handler calls `exit(EX_IOERR)`, causing the process
93  /// to immediately exit with an IO error exit code.
94  ///
95  /// This function is only applicable on POSIX systems.
96  void SetPipeSignalFunction(void (*Handler)());
97 
98 } // End sys namespace
99 } // End llvm namespace
100 
101 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void(*)(void *) SignalHandlerCallback
Definition: Signals.h:58
void DisableSystemDialogsOnCrash()
Disable all system dialog boxes that appear when the process crashes.
void SetPipeSignalFunction(void(*Handler)())
Registers a function to be called when a "pipe" signal is delivered to the process.
void SetInfoSignalFunction(void(*Handler)())
Registers a function to be called when an "info" signal is delivered to the process.
void RunSignalHandlers()
Definition: Signals.cpp:60
void PrintStackTraceOnErrorSignal(StringRef Argv0, bool DisableCrashReporting=false)
When an error signal (such as SIGABRT or SIGSEGV) is delivered to the process, print a stack trace an...
void PrintStackTrace(raw_ostream &OS)
Print the stack trace using the given raw_ostream object.
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
void DontRemoveFileOnSignal(StringRef Filename)
This function removes a file from the list of files to be removed on signal delivery.
bool RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg=nullptr)
This function registers signal handlers to ensure that if a signal gets delivered that the named file...
void AddSignalHandler(SignalHandlerCallback FnPtr, void *Cookie)
Add a function to be called when an abort/kill signal is delivered to the process.
void SetInterruptFunction(void(*IF)())
This function registers a function to be called when the user "interrupts" the program (typically by ...