diff --git a/source/lib/core/debug.hpp b/source/lib/core/debug.hpp index b933cf33f8..fe265767ad 100644 --- a/source/lib/core/debug.hpp +++ b/source/lib/core/debug.hpp @@ -377,14 +377,21 @@ as_hex(void*, size_t); if(ROCPROFSYS_UNLIKELY((COND))) \ { \ char _msg_buffer[ROCPROFSYS_DEBUG_BUFFER_LEN]; \ + bool _print_backtrace = ::rocprofsys::get_debug() || \ + ::rocprofsys::get_verbose() >= 2 || \ + ::rocprofsys::get_is_continuous_integration(); \ snprintf(_msg_buffer, ROCPROFSYS_DEBUG_BUFFER_LEN, \ "[rocprof-sys][%i][%li][%s]%s", ROCPROFSYS_DEBUG_PROCESS_IDENTIFIER, \ ROCPROFSYS_DEBUG_THREAD_IDENTIFIER, ROCPROFSYS_FUNCTION, \ ::rocprofsys::debug::is_bracket(__VA_ARGS__) ? "" : " "); \ auto len = strlen(_msg_buffer); \ snprintf(_msg_buffer + len, ROCPROFSYS_DEBUG_BUFFER_LEN - len, __VA_ARGS__); \ - throw ::rocprofsys::exception( \ - ::tim::log::string(::tim::log::color::fatal(), _msg_buffer)); \ + if(!_print_backtrace) \ + throw ::rocprofsys::exception( \ + ::tim::log::string(::tim::log::color::fatal(), _msg_buffer), false); \ + else \ + throw ::rocprofsys::exception( \ + ::tim::log::string(::tim::log::color::fatal(), _msg_buffer)); \ } #define ROCPROFSYS_CONDITIONAL_BASIC_THROW_E(COND, TYPE, ...) \ diff --git a/source/lib/core/exception.cpp b/source/lib/core/exception.cpp index 3d66d947c8..05f2e27964 100644 --- a/source/lib/core/exception.cpp +++ b/source/lib/core/exception.cpp @@ -73,6 +73,12 @@ exception::exception(const char* _msg) , m_what{ get_backtrace(_msg) } {} +template +exception::exception(const std::string& _msg, bool with_backtrace) +: Tp{ _msg } +, m_what{ with_backtrace ? get_backtrace(_msg) : strdup(_msg.c_str()) } +{} + template exception::~exception() { diff --git a/source/lib/core/exception.hpp b/source/lib/core/exception.hpp index d95436e57b..4326d7fa85 100644 --- a/source/lib/core/exception.hpp +++ b/source/lib/core/exception.hpp @@ -36,6 +36,7 @@ class exception : public Tp public: explicit exception(const std::string& _msg); explicit exception(const char* _msg); + explicit exception(const std::string& _msg, bool with_backtrace); ~exception() override;