![]() |
![]() |
#include <Iguana/Framework/interface/IgOnCrashService.h>
Public Types | |
typedef void(* | FatalExceptionHook )(const char *type, const char *what) |
typedef bool(* | FatalSignalHook )(int sig, siginfo_t *info, void *x) |
Static Public Member Functions | |
static void | fatalException (const char *type, const char *what) |
static FatalExceptionHook | fatalExceptionHook (FatalExceptionHook hook) |
Set fatal exception handler. | |
static const char * | fatalMessage (void) |
Message template for crashes; has one s arg: reason. | |
static FatalSignalHook | fatalSignalHook (FatalSignalHook hook) |
Set fatal signal handler. | |
static const char * | fatalTitle (void) |
Title template for crashes; has two s args: topic, title. | |
static bool | init (const char *appname) |
static void | printFatalException (const char *type, const char *what) |
static void | printFatalMessage (const char *topic, const char *title, const char *reason) |
Private Member Functions | |
IgOnCrashService () | |
Static Private Member Functions | |
static void | defaultFatalException (const char *type, const char *what) |
static bool | defaultFatalSignal (int sig, siginfo_t *info, void *x) |
static void | explainException (const char *type, const char *what, std::string &topic, std::string &title, std::string &reason) |
static bool | fatalSignal (int sig, siginfo_t *info, void *x) |
Static Private Attributes | |
static FatalExceptionHook | s_exceptionHook = defaultFatalException |
static FatalSignalHook | s_signalHook = defaultFatalSignal |
Definition at line 17 of file IgOnCrashService.h.
typedef void(* IgOnCrashService::FatalExceptionHook)(const char *type, const char *what) |
typedef bool(* IgOnCrashService::FatalSignalHook)(int sig, siginfo_t *info, void *x) |
IgOnCrashService::IgOnCrashService | ( | ) | [private] |
void IgOnCrashService::defaultFatalException | ( | const char * | type, | |
const char * | what | |||
) | [static, private] |
Definition at line 237 of file IgOnCrashService.cc.
References printFatalException().
Referenced by init().
00238 { 00239 printFatalException (type, what); 00240 }
Definition at line 157 of file IgOnCrashService.cc.
References lat::Signal::fatalDump(), name, lat::Signal::name(), printFatalMessage(), and signum.
Referenced by init().
00158 { 00159 char buf [128]; 00160 int signum = sig < 0 ? -sig : sig; 00161 bool have_core = sig < 0; 00162 const char *name = lat::Signal::name (signum); 00163 00164 if (name) 00165 sprintf (buf, "`%.100s' signal", name); 00166 else 00167 sprintf (buf, "Signal %d", signum); 00168 00169 if (have_core) 00170 strcat (buf, " (core dumped)"); 00171 00172 printFatalMessage ("Internal error", buf, buf); 00173 return lat::Signal::fatalDump (sig, info, x); 00174 }
void IgOnCrashService::explainException | ( | const char * | type, | |
const char * | what, | |||
std::string & | topic, | |||
std::string & | title, | |||
std::string & | reason | |||
) | [static, private] |
Definition at line 180 of file IgOnCrashService.cc.
Referenced by printFatalException().
00185 { 00186 if (! what || ! *what) 00187 what = "C++ exception"; 00188 00189 topic = "Internal error"; 00190 title = what; 00191 reason = what; 00192 00193 // GCC prepends the name length to type names, strip them off 00194 while (type && isdigit (*type)) 00195 type++; 00196 00197 if (type && *type) 00198 topic = type; 00199 00200 // Convert underscores to spaces 00201 std::string::size_type pos = topic.find ('_'); 00202 while (pos != std::string::npos) 00203 { 00204 topic.replace (pos, 1, 1, ' '); 00205 pos = topic.find ('_'); 00206 } 00207 00208 // Uppercase first character 00209 topic[0] = toupper (topic[0]); 00210 if (type && *type) 00211 reason.insert (0, topic + ": "); 00212 }
void IgOnCrashService::fatalException | ( | const char * | type, | |
const char * | what | |||
) | [static] |
Definition at line 226 of file IgOnCrashService.cc.
References ASSERT, and s_exceptionHook.
Referenced by IgApplication::loadDriver().
00227 { 00228 // FIXME: should be dialog in a graphical app! 00229 // FIXME: should interrupt here any subprocesses/threads 00230 // FIXME: should this be a service others can hook into? 00231 00232 ASSERT (s_exceptionHook); 00233 s_exceptionHook (type, what); 00234 }
IgOnCrashService::FatalExceptionHook IgOnCrashService::fatalExceptionHook | ( | FatalExceptionHook | hook | ) | [static] |
Set fatal exception handler.
Sets current fatal exception handler to hook and returns the old one. If hook is null, doesn't change the current value, just returns the old one. The caller should restore the old handler when the new one becomes invalid. It can also call the old handlers in a chain if desirable.
Definition at line 91 of file IgOnCrashService.cc.
References old, and s_exceptionHook.
00092 { 00093 FatalExceptionHook old = s_exceptionHook; 00094 if (hook) 00095 s_exceptionHook = hook; 00096 return old; 00097 }
const char * IgOnCrashService::fatalMessage | ( | void | ) | [static] |
Message template for crashes; has one s arg: reason.
Definition at line 111 of file IgOnCrashService.cc.
References IGUANA_APP, IGUANA_COMPILER, IGUANA_CXX, IGUANA_HOST, IGUANA_UNAME, IGUANA_VERSION, and IGUANA_WHO.
Referenced by printFatalMessage().
00112 { 00113 // FIXME: put in apps etc. from service constructor args? 00114 return "Oh dear! You have found a bug in CMSSW.\n\n" 00115 00116 "If you can reproduce this bug, please send a bug report\n" 00117 "to <iguana-developers@cern.ch>, giving a subject like\n\n" 00118 00119 " %s in " IGUANA_APP " " IGUANA_VERSION " (" IGUANA_HOST ")\n\n" 00120 00121 "To enable us to fix the bug, please include the following information:\n" 00122 "* What you were doing to get this message. Please report all the facts.\n" 00123 "* The following build configuration information:\n" 00124 " " IGUANA_UNAME "\n" 00125 " " IGUANA_CXX " (" IGUANA_COMPILER ")\n" 00126 " built by " IGUANA_WHO " on " __DATE__ " " __TIME__ "\n" 00127 "* The stack trace and loaded libraries list following this message.\n" 00128 "Please read also the section \"Reporting Bugs\" in the " IGUANA_APP " manual.\n\n" 00129 00130 "We thank you for your support and our apologies for the inconvenience.\n\n"; 00131 }
Definition at line 146 of file IgOnCrashService.cc.
References ASSERT, and s_signalHook.
Referenced by init().
00147 { 00148 // FIXME: should interrupt here any subprocesses/threads 00149 // FIXME: should this be a service others can hook into? 00150 // FIXME: deal with recursive crashes 00151 // FIXME: be smarter about SIGINT 00152 ASSERT (s_signalHook); 00153 return s_signalHook (sig, info, x); 00154 }
IgOnCrashService::FatalSignalHook IgOnCrashService::fatalSignalHook | ( | FatalSignalHook | hook | ) | [static] |
Set fatal signal handler.
Sets current fatal signal handler to hook and returns the old one. If hook is null, doesn't change the current value, just returns the old one. The caller should restore the old handler when the new one becomes invalid. It can also call the old handlers in a chain if desirable.
Definition at line 75 of file IgOnCrashService.cc.
References old, and s_signalHook.
00076 { 00077 FatalSignalHook old = s_signalHook; 00078 if (hook) 00079 s_signalHook = hook; 00080 return old; 00081 }
const char * IgOnCrashService::fatalTitle | ( | void | ) | [static] |
Title template for crashes; has two s args: topic, title.
Definition at line 104 of file IgOnCrashService.cc.
Referenced by printFatalMessage().
bool IgOnCrashService::init | ( | const char * | appname | ) | [static] |
Definition at line 36 of file IgOnCrashService.cc.
References ASSERT, defaultFatalException(), defaultFatalSignal(), fatalSignal(), lat::Signal::handleFatal(), s_exceptionHook, and s_signalHook.
Referenced by IgApplication::initDebugging().
00037 { 00038 // FIXME: For GUI app drivers, install fatal X error handler too 00039 // (or redirect whatever Qt has already), and hook it into 00040 // fatal_error_hook structure. 00041 00042 // FIXME: Maybe install a graphical notification dialog in the app 00043 // driver? If yes, create the dialog beforehand, and when showing 00044 // it, make sure the dialog is mapped and X is synchronised before 00045 // returning from the equivalent of the fatal_error_hook(). This 00046 // will allow us to exit if we get another signal (or an X error?) 00047 // during that time. 00048 00049 // FIXME: If we have subprocesses that we are communicating with 00050 // (or a thread, or another interruptable subunit), the SIGINT 00051 // handler should send an interrupt to it (a C-c character for 00052 // example). 00053 00054 // FIXME: App driver should disable core dump on fatal signals 00055 // while in the main event loop (that is, allow them from init 00056 // till exit sequence begins) -- except if the user has requested 00057 // otherwise. 00058 00059 // FIXME: Install a quit cleanup handler? 00060 00061 ASSERT (s_signalHook == defaultFatalSignal); 00062 ASSERT (s_exceptionHook == defaultFatalException); 00063 lat::Signal::handleFatal (appname, -1, fatalSignal); 00064 return true; 00065 }
void IgOnCrashService::printFatalException | ( | const char * | type, | |
const char * | what | |||
) | [static] |
Definition at line 215 of file IgOnCrashService.cc.
References explainException(), printFatalMessage(), and indexGen::title.
Referenced by defaultFatalException().
00216 { 00217 std::string title; 00218 std::string reason; 00219 std::string topic; 00220 00221 explainException (type, what, title, reason, topic); 00222 printFatalMessage (title.c_str (), reason.c_str (), topic.c_str ()); 00223 }
void IgOnCrashService::printFatalMessage | ( | const char * | topic, | |
const char * | title, | |||
const char * | reason | |||
) | [static] |
Definition at line 137 of file IgOnCrashService.cc.
References TestMuL1L2Filter_cff::cerr, fatalMessage(), and fatalTitle().
Referenced by defaultFatalSignal(), and printFatalException().
00139 { 00140 std::cerr.flush (); 00141 fprintf (stderr, fatalTitle (), topic, title); 00142 fprintf (stderr, fatalMessage (), reason); 00143 }
IgOnCrashService::FatalExceptionHook IgOnCrashService::s_exceptionHook = defaultFatalException [static, private] |
Definition at line 57 of file IgOnCrashService.h.
Referenced by fatalException(), fatalExceptionHook(), and init().
IgOnCrashService::FatalSignalHook IgOnCrashService::s_signalHook = defaultFatalSignal [static, private] |
Definition at line 56 of file IgOnCrashService.h.
Referenced by fatalSignal(), fatalSignalHook(), and init().