From 72d98d76301f4372edc4b25447134b68cf177bb0 Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Tue, 2 Sep 2025 13:40:23 -0600 Subject: [PATCH 1/2] Make sure boost's stacktrace uses addr2line It apparently does not pick it up automatically --- src/core/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 2a88868b..6e969021 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -32,6 +32,7 @@ endif() # Always looking for stacktrace can cause problems when cross compiling # Hence, avoid finding boost if user didn't ask for it. option (EKAT_ENABLE_BOOST_STACKTRACE "Whether to enable Boost stacktrace" OFF) + if (EKAT_ENABLE_BOOST_STACKTRACE) message (STATUS "Looking for boost::stacktrace ...") # Stacktrace is available with Boost>=1.65 @@ -77,7 +78,7 @@ endif() if (EKAT_HAS_STACKTRACE) target_link_libraries(ekat_core PUBLIC ${Boost_LIBRARIES}) - target_compile_definitions(ekat_core PRIVATE EKAT_HAS_STACKTRACE) + target_compile_definitions(ekat_core PRIVATE EKAT_HAS_STACKTRACE BOOST_STACKTRACE_USE_ADDR2LINE) endif() if (EKAT_DEFAULT_BFB) From 14b5f480850160319e0c02d640309ba1ff4f8268 Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Tue, 2 Sep 2025 13:57:42 -0600 Subject: [PATCH 2/2] Printing backtrace to cerr rather than passing it to exception ctor Prints the bactrace without line truncation --- src/core/ekat_assert.hpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/ekat_assert.hpp b/src/core/ekat_assert.hpp index 2cb06a22..3aa025f6 100644 --- a/src/core/ekat_assert.hpp +++ b/src/core/ekat_assert.hpp @@ -33,13 +33,14 @@ void throw_exception(const std::string& msg) if constexpr (std::is_constructible::value) { throw exception_type(msg); } else if constexpr (std::is_default_constructible::value) { - std::cerr << msg; + std::cerr << msg << "\n"; throw exception_type(); } else { std::cerr << msg << "\n"; std::cerr << "Cannot create exception of type\n"; std::cerr << " " << typeid(exception_type).name() << "\n"; - std::cerr << "The program will terminate\n"; + std::cerr << "Throwing std::runtime_error instead...\n"; + throw std::runtime_error(msg); } } @@ -47,14 +48,15 @@ void throw_exception(const std::string& msg) // Internal do not call directly. #define IMPL_THROW(condition, msg, exception_type) \ - do { \ - if ( ! (condition) ) { \ - std::stringstream _ss_; \ - _ss_ << "\n FAIL:\n" << #condition << "\n"; \ - _ss_ << EKAT_BACKTRACE; \ - _ss_ << "\n" << msg; \ - ekat::throw_exception(_ss_.str()); \ - } \ + do { \ + if ( ! (condition) ) { \ + std::cerr << "\nFAILED CONDITION: '" << #condition << "'\n\n"; \ + std::cerr << "BACKTRACE:\n"; \ + std::cerr << EKAT_BACKTRACE << "\n"; \ + std::stringstream ss; \ + ss << msg; \ + ekat::throw_exception(ss.str()); \ + } \ } while(0) // Define the EKAT_REQUIRE macros for different argument counts