diff --git a/tesseract_common/CMakeLists.txt b/tesseract_common/CMakeLists.txt index 5dc4eb1dca9..3d164067635 100644 --- a/tesseract_common/CMakeLists.txt +++ b/tesseract_common/CMakeLists.txt @@ -67,6 +67,8 @@ target_link_libraries( Boost::filesystem Boost::serialization console_bridge::console_bridge + boost_stacktrace_backtrace + backtrace # important for boost::stacktrace to generate function names and line numbers yaml-cpp) target_compile_options(${PROJECT_NAME} PUBLIC ${TESSERACT_COMPILE_OPTIONS_PUBLIC}) target_compile_definitions(${PROJECT_NAME} PUBLIC ${TESSERACT_COMPILE_DEFINITIONS}) diff --git a/tesseract_common/include/tesseract_common/type_erasure.h b/tesseract_common/include/tesseract_common/type_erasure.h index 3ff546eba26..a34e717962f 100644 --- a/tesseract_common/include/tesseract_common/type_erasure.h +++ b/tesseract_common/include/tesseract_common/type_erasure.h @@ -26,8 +26,11 @@ #ifndef TESSERACT_COMMON_TYPE_ERASURE_H #define TESSERACT_COMMON_TYPE_ERASURE_H +#define BOOST_STACKTRACE_USE_BACKTRACE + #include #include +#include #include #include #include @@ -218,7 +221,8 @@ struct TypeErasureBase { if (getType() != typeid(T)) throw std::runtime_error("TypeErasureBase, tried to cast '" + std::string(getType().name()) + "' to '" + - std::string(typeid(T).name()) + "'!"); + std::string(typeid(T).name()) + "'\nBacktrace:\n" + + boost::stacktrace::to_string(boost::stacktrace::stacktrace()) + "\n"); auto* p = static_cast*>(value_->recover()); return *p; @@ -229,7 +233,8 @@ struct TypeErasureBase { if (getType() != typeid(T)) throw std::runtime_error("TypeErasureBase, tried to cast '" + std::string(getType().name()) + "' to '" + - std::string(typeid(T).name()) + "'!"); + std::string(typeid(T).name()) + "'\nBacktrace:\n" + + boost::stacktrace::to_string(boost::stacktrace::stacktrace()) + "\n"); const auto* p = static_cast*>(value_->recover()); return *p;