From 57f5556aad13b48d9f2910f0c0f08306756eee9d Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Tue, 29 Oct 2024 16:52:32 +0100 Subject: [PATCH] Inline terminate handler --- source/core/lib/CMakeLists.txt | 2 -- .../lib/inc/tactile/core/debug/terminate.hpp | 19 -------------- source/core/lib/src/debug/terminate.cpp | 25 ------------------- source/runtime/lib/src/runtime_impl.cpp | 20 ++++++++++++--- 4 files changed, 17 insertions(+), 49 deletions(-) delete mode 100644 source/core/lib/inc/tactile/core/debug/terminate.hpp delete mode 100644 source/core/lib/src/debug/terminate.cpp diff --git a/source/core/lib/CMakeLists.txt b/source/core/lib/CMakeLists.txt index 3301a777c..1a915a023 100644 --- a/source/core/lib/CMakeLists.txt +++ b/source/core/lib/CMakeLists.txt @@ -27,7 +27,6 @@ target_sources(tactile-core "src/debug/assert.cpp" "src/debug/performance.cpp" "src/debug/stacktrace.cpp" - "src/debug/terminate.cpp" "src/document/document_manager.cpp" "src/document/layer_view_impl.cpp" "src/document/map_document.cpp" @@ -133,7 +132,6 @@ target_sources(tactile-core "inc/tactile/core/debug/assert.hpp" "inc/tactile/core/debug/performance.hpp" "inc/tactile/core/debug/stacktrace.hpp" - "inc/tactile/core/debug/terminate.hpp" "inc/tactile/core/document/document_info.hpp" "inc/tactile/core/document/document_manager.hpp" "inc/tactile/core/document/layer_view_impl.hpp" diff --git a/source/core/lib/inc/tactile/core/debug/terminate.hpp b/source/core/lib/inc/tactile/core/debug/terminate.hpp deleted file mode 100644 index a1c70924a..000000000 --- a/source/core/lib/inc/tactile/core/debug/terminate.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) - -#pragma once - -#include "tactile/base/prelude.hpp" - -namespace tactile::core { - -/** - * Provides a custom terminate handler. - * - * \details - * This function will log an error message including the current stack trace, - * and subsequently abort the program. - */ -[[noreturn]] -void on_terminate() noexcept; - -} // namespace tactile::core diff --git a/source/core/lib/src/debug/terminate.cpp b/source/core/lib/src/debug/terminate.cpp deleted file mode 100644 index 44b2a1d71..000000000 --- a/source/core/lib/src/debug/terminate.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) - -#include "tactile/core/debug/terminate.hpp" - -#include // abort - -#include "tactile/core/debug/stacktrace.hpp" -#include "tactile/core/logging.hpp" - -namespace tactile::core { - -void on_terminate() noexcept -{ - try { - const auto trace = get_stacktrace(); - TACTILE_CORE_ERROR("Into exile I must go. Failed I have.\n{}", trace); - } - catch (...) { // NOLINT(*-empty-catch) - // Not much we can do. - } - - std::abort(); -} - -} // namespace tactile::core diff --git a/source/runtime/lib/src/runtime_impl.cpp b/source/runtime/lib/src/runtime_impl.cpp index caf46f40e..5c55eeb66 100644 --- a/source/runtime/lib/src/runtime_impl.cpp +++ b/source/runtime/lib/src/runtime_impl.cpp @@ -3,7 +3,7 @@ #include "tactile/runtime/runtime_impl.hpp" #include // steady_clock -#include // malloc, free, EXIT_SUCCESS, EXIT_FAILURE +#include // malloc, free, abort, EXIT_SUCCESS, EXIT_FAILURE #include // exception, set_terminate #include // optional #include // unordered_map @@ -12,7 +12,7 @@ #include #include "tactile/base/render/renderer.hpp" -#include "tactile/core/debug/terminate.hpp" +#include "tactile/core/debug/stacktrace.hpp" #include "tactile/core/logging.hpp" #include "tactile/core/numeric/random.hpp" #include "tactile/core/platform/win32.hpp" @@ -28,6 +28,20 @@ namespace tactile::runtime { namespace { +[[noreturn]] +void _on_terminate() noexcept +{ + try { + const auto trace = core::get_stacktrace(); + TACTILE_RUNTIME_ERROR("Into exile I must go. Failed I have.\n{}", trace); + } + catch (...) { // NOLINT(*-empty-catch) + // Not much we can do. + } + + std::abort(); +} + [[nodiscard]] auto _imgui_malloc(const std::size_t bytes, void*) -> void* { @@ -112,7 +126,7 @@ struct RuntimeImpl::Data final RuntimeImpl::RuntimeImpl(const CommandLineOptions& options) { - std::set_terminate(&core::on_terminate); + std::set_terminate(&_on_terminate); m_data = std::make_unique(options); core::init_random_number_generator();