Add ripple::FatalErrorReporter

This commit is contained in:
Vinnie Falco
2013-07-30 19:33:14 -07:00
parent 6d83d171c3
commit 3729745fc6
8 changed files with 218 additions and 35 deletions

View File

@@ -0,0 +1,55 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
FatalErrorReporter::FatalErrorReporter ()
{
FatalError::setReporter (*this);
}
FatalErrorReporter::~FatalErrorReporter ()
{
FatalError::resetReporter (*this);
}
void FatalErrorReporter::onFatalError (
char const* message,
char const* stackBacktrace,
char const* fileName,
int lineNumber)
{
String s;
s << "Message = '" << message << "'" << newLine;
s << "File = '" << fileName << "' Line " << String (lineNumber) << newLine;
s << "Stack Trace:" << newLine;
s << stackBacktrace;
Log::out() << s;
}
//------------------------------------------------------------------------------
class FatalErrorReporterTests : public UnitTest
{
public:
FatalErrorReporterTests () : UnitTest ("FatalErrorReporter", "ripple", runManual)
{
}
void runTest ()
{
beginTestCase ("report");
FatalErrorReporter reporter;
// We don't really expect the program to run after this
// but the unit test is here so you can manually test it.
FatalError ("unit test", __FILE__, __LINE__);
}
};
static FatalErrorReporterTests fatalErrorReporterTests;

View File

@@ -0,0 +1,33 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
#ifndef RIPPLE_SCOPEDFATALERRORREPORTER_H_INCLUDED
#define RIPPLE_SCOPEDFATALERRORREPORTER_H_INCLUDED
/** FatalError reporter.
This writes the details to standard error and the log. The reporter is
installed for the lifetime of the object so typically you would put this
at the top of main().
An alternative is to make it a global variable but for this to cover all
possible cases, there can be no other global variables with non trivial
constructors that can report a fatal error. Also, the Log would need
to be guaranteed to be set up for this handler to work.
*/
class FatalErrorReporter : public FatalError::Reporter
{
public:
FatalErrorReporter ();
~FatalErrorReporter ();
void onFatalError (char const* message,
char const* stackBacktrace,
char const* fileName,
int lineNumber);
};
#endif

View File

@@ -226,6 +226,8 @@ static int runUnitTests (String const& whichTests, String const& format)
int rippleMain (int argc, char** argv)
{
FatalErrorReporter reporter;
//
// These debug heap calls do nothing in release or non Visual Studio builds.
//

View File

@@ -376,6 +376,8 @@ static DH* handleTmpDh (SSL* ssl, int is_export, int iKeyLength)
#include "ledger/ripple_AcceptedLedger.cpp"
#include "consensus/ripple_DisputedTx.cpp"
#include "misc/ripple_HashRouter.cpp"
#include "main/ripple_FatalErrorReporter.h" // private
#include "main/ripple_FatalErrorReporter.cpp"
#include "main/ripple_Main.cpp"
#include "misc/ripple_Offer.cpp"