From 46d85a3462f4be67c346ce68d2abe5e682037099 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 1 Jul 2015 16:24:09 -0400 Subject: [PATCH 1/2] exception.hpp: Add assert_trip debug logging for exceptions --- include/fc/exception/exception.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index 5de13f9..7b86866 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -6,9 +6,10 @@ #include #include #include +#include +#include #include - namespace fc { namespace detail { class exception_impl; } @@ -291,7 +292,6 @@ namespace fc FC_DECLARE_EXCEPTION( underflow_exception, underflow_code, "Integer Underflow" ); std::string except_str(); - } // namespace fc #if __APPLE__ @@ -313,7 +313,10 @@ namespace fc FC_EXPAND_MACRO( \ FC_MULTILINE_MACRO_BEGIN \ if( UNLIKELY(!(TEST)) ) \ + { \ + std::cout << "assert_trip: " << __FILE__ << ':' << __LINE__ << ": " << #TEST << "\n"; \ FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \ + } \ FC_MULTILINE_MACRO_END \ ) From 787e4abf3ff6f1ced9fabc9d30963d8b73137ae7 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 6 Jul 2015 14:50:59 -0400 Subject: [PATCH 2/2] exception.hpp: Allow enable/disable assert trip notifications with only one dirty file --- include/fc/exception/exception.hpp | 12 ++++++++++-- src/exception.cpp | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index 7b86866..1b8d8ed 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace fc @@ -292,6 +291,14 @@ namespace fc FC_DECLARE_EXCEPTION( underflow_exception, underflow_code, "Integer Underflow" ); 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__ @@ -314,7 +321,8 @@ namespace fc FC_MULTILINE_MACRO_BEGIN \ if( UNLIKELY(!(TEST)) ) \ { \ - std::cout << "assert_trip: " << __FILE__ << ':' << __LINE__ << ": " << #TEST << "\n"; \ + 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