blob: 9f2cb850c4680ebd81d0e207a1951d43dbccfeb1 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
19namespace llvm {
20class StringRef;
21class raw_ostream;
22
23namespace 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.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010031 /// Remove a file if a fatal signal occurs.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010032 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.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010040 /// Print a stack trace if a fatal signal occurs.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010041 /// \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.
50 void DisableSystemDialogsOnCrash();
51
Andrew Scullcdfcccc2018-10-05 20:58:37 +010052 /// Print the stack trace using the given \c raw_ostream object.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010053 void PrintStackTrace(raw_ostream &OS);
54
55 // Run all registered signal handlers.
56 void RunSignalHandlers();
57
Andrew Scullcdfcccc2018-10-05 20:58:37 +010058 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);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010064
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. Note
69 /// that interrupt functions are not allowed to call any non-reentrant
70 /// functions. An null interrupt function pointer disables the current
71 /// installed function. Note also that the handler may be executed on a
72 /// different thread on some platforms.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010073 /// Register a function to be called when ctrl-c is pressed.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010074 void SetInterruptFunction(void (*IF)());
75} // End sys namespace
76} // End llvm namespace
77
78#endif