Fennel: AutoBacktrace Class Reference (original) (raw)

AutoBacktrace provides a handler that intercepts fatal errors, prints a backtrace, and passes on the fatal error to other handlers. More...

#include <[Backtrace.h](Backtrace%5F8h-source.html)>

List of all members.

Static Public Member Functions
static void install (bool includeSegFault=true)
Installs backtrace on error; default output is to stderr.
static void setOutputStream (std::ostream &outStream)
Sets an ostream to which the backtrace is written.
static void setOutputStream ()
Unsets a target stream for backtrace.
static void setTraceTarget (SharedTraceTarget pTraceTarget=SharedTraceTarget())
Sets a TraceTarget to which the backtrace is written, independent of setOutputStream.
Private Member Functions
AutoBacktrace ()
Static Private Member Functions
static void signal_handler (int signum)
static void installSignal (int signum)
Static Private Attributes
static std::ostream * pstream
static SharedTraceTarget ptrace
static struct sigaction nextAction [BACKTRACE_SIG_MAX]

Detailed Description

AutoBacktrace provides a handler that intercepts fatal errors, prints a backtrace, and passes on the fatal error to other handlers.

The backtrace handler has global scope. Fatal errors include abort(), assert(), fennel permAssert(), and runaway C++ exceptions.

Definition at line 121 of file Backtrace.h.


Constructor & Destructor Documentation

| AutoBacktrace::AutoBacktrace | ( | | ) | [inline, private] | | ---------------------------- | - | | - | ------------------- |


Member Function Documentation

void AutoBacktrace::signal_handler ( int signum ) [static, private]

Definition at line 198 of file Backtrace.cpp.

References TRACE_SEVERE.

Referenced by installSignal().

00199 { 00200 #ifndef MSVC 00201 Backtrace bt; 00202 if (ptrace) { 00203 std::ostringstream oss; 00204 oss << 00205 "*** CAUGHT SIGNAL " << signum << "; BACKTRACE:" << std::endl; 00206 oss << bt; 00207 std::string msg = oss.str(); 00208 if (pstream) { 00209 pstream << msg; 00210 } 00211 ptrace->notifyTrace("backtrace", TRACE_SEVERE, msg); 00212 } else if (pstream) { 00213 pstream << 00214 "* CAUGHT SIGNAL " << signum << "; BACKTRACE:" << std::endl; 00215 *pstream << bt; 00216 } 00217 00218
00219 sigaction(signum, &(nextAction[signum]), NULL); 00220 raise(signum); 00221 #endif 00222 }

void AutoBacktrace::installSignal ( int signum ) [static, private]

Definition at line 256 of file Backtrace.cpp.

References nextAction, and signal_handler().

Referenced by install().

00257 { 00258 #ifndef MSVC 00259 permAssert(signum < BACKTRACE_SIG_MAX); 00260 struct sigaction act; 00261 struct sigaction old_act; 00262 act.sa_handler = signal_handler; 00263 sigemptyset (&act.sa_mask); 00264 act.sa_flags = 0; 00265 int rc = sigaction(signum, &act, &old_act); 00266 if (rc) { 00267 return;
00268 } 00269 if (old_act.sa_handler != signal_handler) { 00270
00271 nextAction[signum] = old_act; 00272 } 00273 #endif 00274 }

void AutoBacktrace::install ( bool includeSegFault = true ) [static]

Installs backtrace on error; default output is to stderr.

NOTE jvs 25-Dec-2005: for more flexibility, we could allow the caller to specify a sigset_t.

Parameters:

includeSegFault if true, SIGSEGV is included in the set of signals causing a backtrace; if false, it is omitted (required in environments such as a Java VM where spurious segfaults may be signalled but handled as part of normal operation)

Definition at line 239 of file Backtrace.cpp.

References installSignal().

Referenced by TestBase::beforeTestCase(), and JniUtil::init().

static void AutoBacktrace::setOutputStream ( std::ostream & outStream ) [static]

Sets an ostream to which the backtrace is written.

Parameters:

outStream receives backtrace if signal is handled

| void AutoBacktrace::setOutputStream | ( | | ) | [static] | | ----------------------------------- | - | | - | ---------- |


Member Data Documentation


The documentation for this class was generated from the following files:


Generated on Mon Jun 22 04:00:24 2009 for Fennel by doxygen 1.5.1