-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ca0480
commit 65822d4
Showing
5 changed files
with
81 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <nano/lib/assert.hpp> | ||
#include <nano/lib/stacktrace.hpp> | ||
|
||
#include <iostream> | ||
|
||
/* | ||
* Backing code for "release_assert" & "debug_assert", which are macros | ||
*/ | ||
void assert_internal (char const * check_expr, char const * func, char const * file, unsigned int line, bool is_release_assert, std::string_view error_msg) | ||
{ | ||
std::cerr << "Assertion (" << check_expr << ") failed\n" | ||
<< func << "\n" | ||
<< file << ":" << line << "\n"; | ||
if (!error_msg.empty ()) | ||
{ | ||
std::cerr << "Error: " << error_msg << "\n"; | ||
} | ||
std::cerr << "\n"; | ||
|
||
// Output stack trace to cerr | ||
auto backtrace_str = nano::generate_stacktrace (); | ||
std::cerr << backtrace_str << std::endl; | ||
|
||
// "abort" at the end of this function will go into any signal handlers (the daemon ones will generate a stack trace and load memory address files on non-Windows systems). | ||
// As there is no async-signal-safe way to generate stacktraces on Windows it must be done before aborting | ||
#ifdef _WIN32 | ||
{ | ||
// Try construct the stacktrace dump in the same folder as the running executable, otherwise use the current directory. | ||
boost::system::error_code err; | ||
auto running_executable_filepath = boost::dll::program_location (err); | ||
std::string filename = is_release_assert ? "nano_node_backtrace_release_assert.txt" : "nano_node_backtrace_assert.txt"; | ||
std::string filepath = filename; | ||
if (!err) | ||
{ | ||
filepath = (running_executable_filepath.parent_path () / filename).string (); | ||
} | ||
|
||
std::ofstream file (filepath); | ||
nano::set_secure_perm_file (filepath); | ||
file << backtrace_str; | ||
} | ||
#endif | ||
|
||
abort (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <boost/current_function.hpp> | ||
#include <boost/preprocessor/facilities/empty.hpp> | ||
#include <boost/preprocessor/facilities/overload.hpp> | ||
|
||
#include <string_view> | ||
|
||
[[noreturn]] void assert_internal (char const * check_expr, char const * func, char const * file, unsigned int line, bool is_release_assert, std::string_view error = ""); | ||
|
||
#define release_assert_1(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true) | ||
#define release_assert_2(check, error_msg) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, true, error_msg) | ||
#if !BOOST_PP_VARIADICS_MSVC | ||
#define release_assert(...) \ | ||
BOOST_PP_OVERLOAD (release_assert_, __VA_ARGS__) \ | ||
(__VA_ARGS__) | ||
#else | ||
#define release_assert(...) BOOST_PP_CAT (BOOST_PP_OVERLOAD (release_assert_, __VA_ARGS__) (__VA_ARGS__), BOOST_PP_EMPTY ()) | ||
#endif | ||
|
||
#ifdef NDEBUG | ||
#define debug_assert(...) (void)0 | ||
#else | ||
#define debug_assert_1(check) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false) | ||
#define debug_assert_2(check, error_msg) check ? (void)0 : assert_internal (#check, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, false, error_msg) | ||
#if !BOOST_PP_VARIADICS_MSVC | ||
#define debug_assert(...) \ | ||
BOOST_PP_OVERLOAD (debug_assert_, __VA_ARGS__) \ | ||
(__VA_ARGS__) | ||
#else | ||
#define debug_assert(...) BOOST_PP_CAT (BOOST_PP_OVERLOAD (debug_assert_, __VA_ARGS__) (__VA_ARGS__), BOOST_PP_EMPTY ()) | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters