diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index 5de13f9..1b8d8ed 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -6,9 +6,9 @@ #include #include #include +#include #include - namespace fc { namespace detail { class exception_impl; } @@ -292,6 +292,13 @@ namespace fc std::string except_str(); + void record_assert_trip( + const char* filename, + uint32_t lineno, + const char* expr + ); + + extern bool enable_record_assert_trip; } // namespace fc #if __APPLE__ @@ -313,7 +320,11 @@ namespace fc FC_EXPAND_MACRO( \ FC_MULTILINE_MACRO_BEGIN \ if( UNLIKELY(!(TEST)) ) \ + { \ + if( fc::enable_record_assert_trip ) \ + fc::record_assert_trip( __FILE__, __LINE__, #TEST ); \ FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \ + } \ FC_MULTILINE_MACRO_END \ ) diff --git a/src/exception.cpp b/src/exception.cpp index 922fad0..79b37ae 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -4,6 +4,8 @@ #include #include +#include + namespace fc { FC_REGISTER_EXCEPTIONS( (timeout_exception) @@ -228,4 +230,24 @@ namespace fc return *this; } + void record_assert_trip( + const char* filename, + uint32_t lineno, + const char* expr + ) + { + fc::mutable_variant_object assert_trip_info = + fc::mutable_variant_object() + ("source_file", filename) + ("source_lineno", lineno) + ("expr", expr) + ; + std::cout + << "FC_ASSERT triggered: " + << fc::json::to_string( assert_trip_info ) << "\n"; + return; + } + + bool enable_record_assert_trip = false; + } // fc