153ca1f3190680f3e86aebe0f72f7918d63f71e0dCharles Davis//===- llvm/Support/Signals.h - Signal Handling support ----------*- C++ -*-===// 263b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman// 3b2109ce97881269a610fa4afbcbca350e975174dJohn Criswell// The LLVM Compiler Infrastructure 4b2109ce97881269a610fa4afbcbca350e975174dJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 763b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman// 8b2109ce97881269a610fa4afbcbca350e975174dJohn Criswell//===----------------------------------------------------------------------===// 9922a392565130d658f34abb65f5b710e600a1a83Chris Lattner// 10922a392565130d658f34abb65f5b710e600a1a83Chris Lattner// This file defines some helpful functions for dealing with the possibility of 117a2bdde0a0eebcd2125055e0eacaca040f0b766cChris Lattner// unix signals occurring while your program is running. 12922a392565130d658f34abb65f5b710e600a1a83Chris Lattner// 13922a392565130d658f34abb65f5b710e600a1a83Chris Lattner//===----------------------------------------------------------------------===// 14922a392565130d658f34abb65f5b710e600a1a83Chris Lattner 15674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_SUPPORT_SIGNALS_H 16674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_SUPPORT_SIGNALS_H 17922a392565130d658f34abb65f5b710e600a1a83Chris Lattner 181f6efa3996dd1929fbc129203ce5009b620e6969Michael J. Spencer#include "llvm/Support/Path.h" 191930fbf3ebfd988e71a96bf8839afb772f675233NAKAMURA Takumi#include <cstdio> 20922a392565130d658f34abb65f5b710e600a1a83Chris Lattner 21d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 22fd5c345a0e5b18206adc65a9a9f5ab3b5e4d7bd3Reid Spencernamespace sys { 23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 24fb89e08413878571c1c1fc6ff15cdbf5cd8692dcDaniel Dunbar /// This function runs all the registered interrupt handlers, including the 25fb89e08413878571c1c1fc6ff15cdbf5cd8692dcDaniel Dunbar /// removal of files registered by RemoveFileOnSignal. 26fb89e08413878571c1c1fc6ff15cdbf5cd8692dcDaniel Dunbar void RunInterruptHandlers(); 27fb89e08413878571c1c1fc6ff15cdbf5cd8692dcDaniel Dunbar 2863b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman /// This function registers signal handlers to ensure that if a signal gets 29ac4b796c40c507d6f0c3c010ebdee6eabd683e4aReid Spencer /// delivered that the named file is removed. 30ac4b796c40c507d6f0c3c010ebdee6eabd683e4aReid Spencer /// @brief Remove a file if a fatal signal occurs. 31b7e2188f7fb9a1c1cb6dbd32b206e44b11b4a157Rafael Espindola bool RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg = 0); 326c3df8e93ece684f54a07d553085824f4e66984aRafael Espindola 3341154114f64c1531764236e9268d2a5ac52e3e91Dan Gohman /// This function removes a file from the list of files to be removed on 3441154114f64c1531764236e9268d2a5ac52e3e91Dan Gohman /// signal delivery. 35b7e2188f7fb9a1c1cb6dbd32b206e44b11b4a157Rafael Espindola void DontRemoveFileOnSignal(StringRef Filename); 3641154114f64c1531764236e9268d2a5ac52e3e91Dan Gohman 3763b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the 38ac4b796c40c507d6f0c3c010ebdee6eabd683e4aReid Spencer /// process, print a stack trace and then exit. 39ac4b796c40c507d6f0c3c010ebdee6eabd683e4aReid Spencer /// @brief Print a stack trace if a fatal signal occurs. 409717ee9e6c4bc8d71561d46b6914dc0ae300bbc3Chris Lattner void PrintStackTraceOnErrorSignal(); 41ac4b796c40c507d6f0c3c010ebdee6eabd683e4aReid Spencer 42f48acd5ecd2616623f441f2922d8b4c637e3cd6cArgyrios Kyrtzidis /// \brief Print the stack trace using the given \c FILE object. 43f48acd5ecd2616623f441f2922d8b4c637e3cd6cArgyrios Kyrtzidis void PrintStackTrace(FILE *); 44f48acd5ecd2616623f441f2922d8b4c637e3cd6cArgyrios Kyrtzidis 4535033a5876aa27ea5729bc29b41bb4460a303cadChris Lattner /// AddSignalHandler - Add a function to be called when an abort/kill signal 4635033a5876aa27ea5729bc29b41bb4460a303cadChris Lattner /// is delivered to the process. The handler can have a cookie passed to it 4735033a5876aa27ea5729bc29b41bb4460a303cadChris Lattner /// to identify what instance of the handler it is. 4835033a5876aa27ea5729bc29b41bb4460a303cadChris Lattner void AddSignalHandler(void (*FnPtr)(void *), void *Cookie); 4935033a5876aa27ea5729bc29b41bb4460a303cadChris Lattner 50e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner /// This function registers a function to be called when the user "interrupts" 51e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner /// the program (typically by pressing ctrl-c). When the user interrupts the 52e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner /// program, the specified interrupt function is called instead of the program 53e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner /// being killed, and the interrupt function automatically disabled. Note 54e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner /// that interrupt functions are not allowed to call any non-reentrant 55e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner /// functions. An null interrupt function pointer disables the current 56ee841a1a8735805f84d609ae105bec92525033c6Jeff Cohen /// installed function. Note also that the handler may be executed on a 57ee841a1a8735805f84d609ae105bec92525033c6Jeff Cohen /// different thread on some platforms. 58e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner /// @brief Register a function to be called when ctrl-c is pressed. 59e62321ac417fc894c15fa1420408a286b9a535d0Chris Lattner void SetInterruptFunction(void (*IF)()); 60fd5c345a0e5b18206adc65a9a9f5ab3b5e4d7bd3Reid Spencer} // End sys namespace 61d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 622a77df33f00b4a3dff3b748bf5f48a8b68152ba7Chris Lattner 63d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke#endif 64