From 950eacaaa048619a3b757f39754f0bc71427420e Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Fri, 28 Oct 2022 22:49:06 +0800 Subject: [PATCH 1/2] feature: optional using of backtrace instruments Signed-off-by: Dmitriy Khaustov aka xDimon --- CMakeLists.txt | 1 + cmake/dependencies.cmake | 6 ++++-- core/utils/CMakeLists.txt | 9 +++++++-- core/utils/kagome_db_editor.cpp | 2 ++ node/CMakeLists.txt | 4 +++- node/main.cpp | 7 ++++++- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e694c5fb4..8f464fbf86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF) option(COVERAGE "Enable generation of coverage info" OFF) option(EMBEDDINGS "Embed developers assets" ON ) option(PROFILING "Enable internal profiling instruments" OFF) +option(BACKWARD "Enable stacktrace logging instruments" ON ) # sanitizers will be enabled only for Kagome, and will be disabled for dependencies option(ASAN "Enable address sanitizer" OFF) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 2947c8e910..58957115fb 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -7,8 +7,10 @@ if (TESTING) find_package(GTest CONFIG REQUIRED) endif() -hunter_add_package(backward-cpp) -find_package(Backward) +if (BACKWARD) + hunter_add_package(backward-cpp) + find_package(Backward) +endif() # https://docs.hunter.sh/en/latest/packages/pkg/Boost.html hunter_add_package(Boost COMPONENTS random filesystem program_options date_time) diff --git a/core/utils/CMakeLists.txt b/core/utils/CMakeLists.txt index e593f1e1e7..09745eecdf 100644 --- a/core/utils/CMakeLists.txt +++ b/core/utils/CMakeLists.txt @@ -10,13 +10,14 @@ add_executable(storage_explorer target_link_libraries(storage_explorer application_injector ) -add_backward(storage_explorer) +if (BACKWARD) + add_backward(storage_explorer) +endif() add_executable(kagome-db-editor kagome_db_editor.cpp ) target_link_libraries(kagome-db-editor - Backward::Backward Boost::Boost.DI block_storage changes_tracker @@ -29,4 +30,8 @@ target_link_libraries(kagome-db-editor trie_storage trie_storage_backend ) +if (BACKWARD) + add_backward(kagome-db-editor) +endif() kagome_install(kagome-db-editor) + diff --git a/core/utils/kagome_db_editor.cpp b/core/utils/kagome_db_editor.cpp index a1a7b3b432..c865905c38 100644 --- a/core/utils/kagome_db_editor.cpp +++ b/core/utils/kagome_db_editor.cpp @@ -160,7 +160,9 @@ auto is_hash(const char *s) { }; int main(int argc, char *argv[]) { +#if defined(BACKWARD_HAS_BACKTRACE) backward::SignalHandling sh; +#endif Command cmd; if (argc == 2 or (argc == 3 && is_hash(argv[2])) diff --git a/node/CMakeLists.txt b/node/CMakeLists.txt index 501bc7acc2..30eb882921 100644 --- a/node/CMakeLists.txt +++ b/node/CMakeLists.txt @@ -7,7 +7,6 @@ add_executable(kagome main.cpp ) target_link_libraries(kagome - Backward::Backward Boost::boost Boost::program_options kagome_application @@ -16,4 +15,7 @@ target_link_libraries(kagome p2p::p2p_identify p2p::p2p_ping ) +if (BACKWARD) + add_backward(kagome) +endif() kagome_install(kagome) diff --git a/node/main.cpp b/node/main.cpp index c61019375b..38a656414c 100644 --- a/node/main.cpp +++ b/node/main.cpp @@ -5,9 +5,13 @@ #include +#if defined(BACKWARD_HAS_BACKTRACE) #include +#endif + #undef TRUE #undef FALSE + #include #include "application/impl/app_configuration_impl.hpp" @@ -20,8 +24,9 @@ using kagome::application::AppConfiguration; using kagome::application::AppConfigurationImpl; int main(int argc, const char **argv) { +#if defined(BACKWARD_HAS_BACKTRACE) backward::SignalHandling sh; - +#endif { soralog::util::setThreadName("kagome"); From 3e2c2ef4d04f071d5d231d9a39f6111ab7d205e2 Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov aka xDimon Date: Fri, 28 Oct 2022 23:14:45 +0800 Subject: [PATCH 2/2] fix: db editor Signed-off-by: Dmitriy Khaustov aka xDimon --- core/utils/kagome_db_editor.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/utils/kagome_db_editor.cpp b/core/utils/kagome_db_editor.cpp index c865905c38..da91f916b2 100644 --- a/core/utils/kagome_db_editor.cpp +++ b/core/utils/kagome_db_editor.cpp @@ -4,9 +4,13 @@ #include #include +#if defined(BACKWARD_HAS_BACKTRACE) #include +#endif + #undef TRUE #undef FALSE + #include #include