Output current function in assert diagnostics (#2665)

This commit is contained in:
Wesley Shillingford 2020-03-16 15:16:00 +00:00 committed by GitHub
commit 15eebb1ca6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -108,9 +108,11 @@ void nano::move_all_files_to_dir (boost::filesystem::path const & from, boost::f
/*
* Backing code for "release_assert" & "debug_assert", which are macros
*/
void assert_internal (const char * check_expr, const char * file, unsigned int line, bool is_release_assert)
void assert_internal (const char * check_expr, const char * func, const char * file, unsigned int line, bool is_release_assert)
{
std::cerr << "Assertion (" << check_expr << ") failed " << file << ":" << line << "\n\n";
std::cerr << "Assertion (" << check_expr << ") failed\n"
<< func << "\n"
<< file << ":" << line << "\n\n";
// Output stack trace to cerr
auto backtrace_str = nano::generate_stacktrace ();

View file

@ -2,6 +2,8 @@
#include <nano/lib/locks.hpp>
#include <boost/current_function.hpp>
#include <cassert>
#include <functional>
#include <mutex>
@ -20,13 +22,13 @@ namespace system
}
}
void assert_internal (const char * check_expr, const char * file, unsigned int line, bool is_release_assert);
#define release_assert(check) check ? (void)0 : assert_internal (#check, __FILE__, __LINE__, true)
void assert_internal (const char * check_expr, const char * func, const char * file, unsigned int line, bool is_release_assert);
#define release_assert(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true)
#ifdef NDEBUG
#define debug_assert(check) (void)0
#else
#define debug_assert(check) check ? (void)0 : assert_internal (#check, __FILE__, __LINE__, false)
#define debug_assert(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false)
#endif
namespace nano