Skip to content

Commit

Permalink
Add backtrace to type erasure casting to quickly identify where the i…
Browse files Browse the repository at this point in the history
…ssue location
  • Loading branch information
Levi-Armstrong committed Jun 7, 2024
1 parent 6f9582d commit a79ffea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: vcpkg build
uses: johnwason/vcpkg-action@v6
with:
pkgs: fcl bullet3[multithreading,double-precision,rtti] octomap console-bridge eigen3 yaml-cpp benchmark tinyxml2 assimp orocos-kdl pcl lapack-reference boost-dll boost-filesystem boost-filesystem boost-serialization boost-program-options boost-graph urdfdom ccd[double-precision] gtest
pkgs: fcl bullet3[multithreading,double-precision,rtti] octomap console-bridge eigen3 yaml-cpp benchmark tinyxml2 assimp orocos-kdl pcl lapack-reference boost-dll boost-filesystem boost-filesystem boost-serialization boost-program-options boost-graph boost-stacktrace urdfdom ccd[double-precision] gtest
triplet: x64-windows-release
extra-args: --clean-after-build
token: ${{ github.token }}
Expand Down
20 changes: 19 additions & 1 deletion tesseract_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,24 @@ endif()
include(cmake/tesseract_macros.cmake)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")

find_package(Boost REQUIRED COMPONENTS system filesystem serialization)
if(WIN32)
find_package(
Boost REQUIRED
COMPONENTS system
filesystem
serialization
stacktrace_windbg)
set(TESSERACT_BACKTRACE_LIB Boost::stacktrace_windbg)
else()
find_package(
Boost REQUIRED
COMPONENTS system
filesystem
serialization
stacktrace_backtrace)
set(TESSERACT_BACKTRACE_LIB Boost::stacktrace_backtrace)
endif()

find_package(Eigen3 REQUIRED)
find_package(TinyXML2 REQUIRED)
find_package(yaml-cpp REQUIRED)
Expand Down Expand Up @@ -66,6 +83,7 @@ target_link_libraries(
Boost::system
Boost::filesystem
Boost::serialization
${TESSERACT_BACKTRACE_LIB}
console_bridge::console_bridge
yaml-cpp)
target_compile_options(${PROJECT_NAME} PUBLIC ${TESSERACT_COMPILE_OPTIONS_PUBLIC})
Expand Down
13 changes: 11 additions & 2 deletions tesseract_common/include/tesseract_common/type_erasure.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@
#ifndef TESSERACT_COMMON_TYPE_ERASURE_H
#define TESSERACT_COMMON_TYPE_ERASURE_H

#ifndef _WIN32
#define BOOST_STACKTRACE_USE_BACKTRACE
#else
#define BOOST_STACKTRACE_USE_WINDBG
#endif

#include <memory>
#include <typeindex>
#include <boost/stacktrace.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/assume_abstract.hpp>
Expand Down Expand Up @@ -218,7 +225,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<uncvref_t<T>*>(value_->recover());
return *p;
Expand All @@ -229,7 +237,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<const uncvref_t<T>*>(value_->recover());
return *p;
Expand Down

0 comments on commit a79ffea

Please sign in to comment.