mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Added stack trace logging for exceptions.
This commit is contained in:
@@ -34,6 +34,8 @@ target_link_libraries(hpsupport
|
||||
libboost_log.a
|
||||
libboost_log_setup.a
|
||||
libboost_filesystem.a
|
||||
libboost_stacktrace_backtrace.a
|
||||
backtrace
|
||||
pthread
|
||||
crypto
|
||||
ssl
|
||||
@@ -124,10 +126,10 @@ target_link_libraries(hpstatemon
|
||||
add_dependencies(hpcore
|
||||
hpstatemon
|
||||
)
|
||||
add_custom_command(TARGET hpcore POST_BUILD
|
||||
COMMAND strip ./build/hpcore
|
||||
COMMAND strip ./build/hpstatemon
|
||||
)
|
||||
# add_custom_command(TARGET hpcore POST_BUILD
|
||||
# COMMAND strip ./build/hpcore
|
||||
# COMMAND strip ./build/hpstatemon
|
||||
# )
|
||||
|
||||
target_precompile_headers(hpsupport PUBLIC src/pchheader.hpp)
|
||||
target_precompile_headers(hpcore REUSE_FROM hpsupport)
|
||||
|
||||
29
src/main.cpp
29
src/main.cpp
@@ -75,15 +75,32 @@ void signal_handler(int signum)
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
namespace boost
|
||||
{
|
||||
/**
|
||||
* Global exception handler for boost exceptions.
|
||||
*/
|
||||
void boost::throw_exception(std::exception const &e)
|
||||
void throw_exception(std::exception const &e)
|
||||
{
|
||||
std::cerr << "Boost error:" << e.what() << "\n";
|
||||
LOG_ERR << "Boost error: " << e.what() << "\n"
|
||||
<< boost::stacktrace::stacktrace();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void assertion_failed_msg(char const *expr, char const *msg, char const *function, char const * /*file*/, long /*line*/)
|
||||
{
|
||||
LOG_ERR << "Expression '" << expr << "' is false in function '" << function << "': " << (msg ? msg : "<...>") << ".\n"
|
||||
<< "Backtrace:\n"
|
||||
<< boost::stacktrace::stacktrace() << '\n';
|
||||
std::abort();
|
||||
}
|
||||
|
||||
inline void assertion_failed(char const *expr, char const *function, char const *file, long line)
|
||||
{
|
||||
::boost::assertion_failed_msg(expr, 0 /*nullptr*/, function, file, line);
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
/**
|
||||
* Global exception handler for std exceptions.
|
||||
*/
|
||||
@@ -102,14 +119,18 @@ void std_terminate() noexcept
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "std error: Terminated due to unknown exception" << "\n";
|
||||
LOG_ERR << "std error: Terminated due to unknown exception"
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "std error: Terminated due to unknown reason" << "\n";
|
||||
LOG_ERR << "std error: Terminated due to unknown reason"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
LOG_ERR << boost::stacktrace::stacktrace();
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
// This will direct all boost exceptions to our error handler.
|
||||
#define BOOST_NO_EXCEPTIONS
|
||||
// Enable boost strack trace.
|
||||
#define BOOST_STACKTRACE_USE_BACKTRACE
|
||||
// Enable custom handlers for boost assertion failures.
|
||||
#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER
|
||||
|
||||
#include <bitset>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@@ -25,6 +29,7 @@
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/utility/setup/console.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
#include <boost/stacktrace.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdarg>
|
||||
|
||||
@@ -1354,4 +1354,30 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
return fusefs::start(argv[0], argv[1], argv[2]);
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost
|
||||
{
|
||||
/**
|
||||
* Global exception handler for boost exceptions.
|
||||
*/
|
||||
void throw_exception(std::exception const &e)
|
||||
{
|
||||
std::cerr << "Boost error: " << e.what() << "\n"
|
||||
<< boost::stacktrace::stacktrace();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
inline void assertion_failed_msg(char const *expr, char const *msg, char const *function, char const * /*file*/, long /*line*/)
|
||||
{
|
||||
std::cerr << "Expression '" << expr << "' is false in function '" << function << "': " << (msg ? msg : "<...>") << ".\n"
|
||||
<< "Backtrace:\n"
|
||||
<< boost::stacktrace::stacktrace() << '\n';
|
||||
std::abort();
|
||||
}
|
||||
|
||||
inline void assertion_failed(char const *expr, char const *function, char const *file, long line)
|
||||
{
|
||||
::boost::assertion_failed_msg(expr, 0 /*nullptr*/, function, file, line);
|
||||
}
|
||||
} // namespace boost
|
||||
Reference in New Issue
Block a user