diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f61ed929e..5144ed8f79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,11 @@ set (NANO_ROCKSDB OFF CACHE BOOL "") set (NANO_WARN_TO_ERR OFF CACHE BOOL "") set (NANO_TIMED_LOCKS 0 CACHE INTEGER "") +option (NANO_STACKTRACE_BACKTRACE "Use BOOST_STACKTRACE_USE_BACKTRACE in stacktraces, for POSIX" OFF) +if (NANO_STACKTRACE_BACKTRACE) + add_definitions(-DNANO_STACKTRACE_BACKTRACE=1) +endif () + if (${NANO_TIMED_LOCKS} GREATER 0) add_definitions (-DNANO_TIMED_LOCKS=${NANO_TIMED_LOCKS}) endif () diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 13f421a082..41d8bde0c1 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -71,6 +71,10 @@ target_link_libraries (nano_lib ${timed_locks_boost_libs} Boost::boost) +if (NANO_STACKTRACE_BACKTRACE) + target_link_libraries(nano_lib backtrace) +endif () + target_compile_definitions(nano_lib PUBLIC -DACTIVE_NETWORK=${ACTIVE_NETWORK} diff --git a/nano/lib/utility.cpp b/nano/lib/utility.cpp index d2a27a01db..cdb9fc760e 100644 --- a/nano/lib/utility.cpp +++ b/nano/lib/utility.cpp @@ -6,6 +6,9 @@ // Some builds (mac) fail due to "Boost.Stacktrace requires `_Unwind_Backtrace` function". #ifndef _WIN32 +#ifdef NANO_STACKTRACE_BACKTRACE +#define BOOST_STACKTRACE_USE_BACKTRACE +#endif #ifndef _GNU_SOURCE #define BEFORE_GNU_SOURCE 0 #define _GNU_SOURCE diff --git a/nano/nano_node/CMakeLists.txt b/nano/nano_node/CMakeLists.txt index 63412fac80..d38895f01d 100644 --- a/nano/nano_node/CMakeLists.txt +++ b/nano/nano_node/CMakeLists.txt @@ -12,6 +12,10 @@ target_link_libraries (nano_node ${PLATFORM_LIBS} ) +if (NANO_STACKTRACE_BACKTRACE) + target_link_libraries(nano_node backtrace) +endif () + target_compile_definitions(nano_node PRIVATE -DTAG_VERSION_STRING=${TAG_VERSION_STRING} diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 12d95c5de6..01e7c5570a 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -17,6 +17,9 @@ // Some builds (mac) fail due to "Boost.Stacktrace requires `_Unwind_Backtrace` function". #ifndef _WIN32 +#ifdef NANO_STACKTRACE_BACKTRACE +#define BOOST_STACKTRACE_USE_BACKTRACE +#endif #ifndef _GNU_SOURCE #define BEFORE_GNU_SOURCE 0 #define _GNU_SOURCE @@ -130,6 +133,7 @@ int main (int argc, char * const * argv) ("debug_validate_blocks", "Check all blocks for correct hash, signature, work value") ("debug_peers", "Display peer IPv6:port connections") ("debug_cemented_block_count", "Displays the number of cemented (confirmed) blocks") + ("debug_stacktrace", "Display an example stacktrace") ("platform", boost::program_options::value (), "Defines the for OpenCL commands") ("device", boost::program_options::value (), "Defines for OpenCL command") ("threads", boost::program_options::value (), "Defines count for OpenCL command") @@ -1078,6 +1082,10 @@ int main (int argc, char * const * argv) nano::inactive_node node (data_path, 24000, node_flags); std::cout << "Total cemented block count: " << node.node->ledger.cemented_count << std::endl; } + else if (vm.count ("debug_stacktrace")) + { + std::cout << boost::stacktrace::stacktrace (); + } else if (vm.count ("debug_sys_logging")) { #ifdef BOOST_WINDOWS diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index c65610859e..567c722974 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -137,6 +137,10 @@ target_link_libraries (node ${psapi_lib} ) +if (NANO_STACKTRACE_BACKTRACE) + target_link_libraries(node backtrace) +endif () + target_compile_definitions(node PRIVATE -DTAG_VERSION_STRING=${TAG_VERSION_STRING} diff --git a/nano/node/lmdb/lmdb_txn.cpp b/nano/node/lmdb/lmdb_txn.cpp index d71562556f..1b0a705ad7 100644 --- a/nano/node/lmdb/lmdb_txn.cpp +++ b/nano/node/lmdb/lmdb_txn.cpp @@ -9,6 +9,9 @@ // Some builds (mac) fail due to "Boost.Stacktrace requires `_Unwind_Backtrace` function". #ifndef _WIN32 +#ifdef NANO_STACKTRACE_BACKTRACE +#define BOOST_STACKTRACE_USE_BACKTRACE +#endif #ifndef _GNU_SOURCE #define BEFORE_GNU_SOURCE 0 #define _GNU_SOURCE