Skip to content
Merged
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ else()
add_definitions("-DGZ_PROFILER_ENABLE=0")
endif()

#--------------------------------------
# Find Backward-cpp for stack trace support
# See https://github.com/gazebosim/gz-cmake/issues/477 before copy this code

set(BACKWARD_TESTS OFF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vendor/backward-cpp)

# Using other CMake interfaces from backwards won't work here since
# CMake would not resolve them into gz-cmake (uses EXTRA_TEST_LIB_DEPS)
# using backward_object set the object file path.
if (UNIX AND NOT APPLE)
set (EXTRA_TEST_LIB_DEPS stdc++fs backward_object)
else()
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ install(
add_library(gz STATIC gz.cc)
target_link_libraries(gz
${PROJECT_LIBRARY_TARGET_NAME}
Backward::Object
gz-common::gz-common
gz-utils::cli
gz-sim
Expand All @@ -25,7 +26,8 @@ if(ENABLE_GUI)
target_link_libraries(gz gz-sim-gui)

add_executable(gz-sim-gui-client gui_main.cc)
target_link_libraries(gz-sim-gui-client PRIVATE gz)
target_link_libraries(gz-sim-gui-client
PRIVATE gz Backward::Object)

install(
TARGETS gz-sim-gui-client
Expand All @@ -36,7 +38,8 @@ endif()
# Create sim main executable
set(sim_executable gz-sim-main)
add_executable(${sim_executable} sim_main.cc)
target_link_libraries(${sim_executable} PRIVATE gz)
target_link_libraries(${sim_executable}
PRIVATE Backward::Object gz)

install(
TARGETS ${sim_executable}
Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ include_directories (
${PROJECT_BINARY_DIR}/include
)

add_subdirectory(backward_vendor/backward-cpp)
add_subdirectory(gtest_vendor)
add_subdirectory(benchmark)
add_subdirectory(integration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,58 @@ set_target_properties(backward PROPERTIES EXPORT_NAME Backward)
target_link_libraries(backward PUBLIC Backward::Interface)
add_library(Backward::Backward ALIAS backward)

###############################################################################
# TESTS
###############################################################################

if(BACKWARD_TESTS)
enable_testing()

add_library(test_main OBJECT test/_test_main.cpp)

macro(backward_add_test src)
get_filename_component(name ${src} NAME_WE)
set(test_name "test_${name}")

add_executable(${test_name} ${src} ${ARGN} $<TARGET_OBJECTS:test_main>)

target_link_libraries(${test_name} PRIVATE Backward::Interface)

add_test(NAME ${name} COMMAND ${test_name})
endmacro()

# Tests without backward.cpp
set(TESTS
test
stacktrace
rectrace
select_signals
)

foreach(test ${TESTS})
backward_add_test(test/${test}.cpp)
endforeach()

# Tests with backward.cpp
set(TESTS
suicide
)

foreach(test ${TESTS})
backward_add_test(test/${test}.cpp backward.cpp)
endforeach()
endif()

install(
FILES "backward.hpp"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES "BackwardConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
# check if Backward is being used as a top-level project or included as a subproject
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
install(
FILES "backward.hpp"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES "BackwardConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reverted #2838, and @j-rivero predicted this fragility in #2838 (comment)

for now the debbuild is unstable due to these installed files since BackwardConfig.cmake is not included in any package install rules

# export the targets (note that exporting backward_object does not make sense)
install(TARGETS backward_interface backward EXPORT BackwardTargets)
# install a CMake file for the exported targets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,19 +1178,31 @@ class StackTraceImpl<system_tag::current_tag> : public StackTraceImplHolder {
s.AddrStack.Mode = AddrModeFlat;
s.AddrFrame.Mode = AddrModeFlat;
s.AddrPC.Mode = AddrModeFlat;
#ifdef _M_X64
#if defined(_M_X64)
s.AddrPC.Offset = ctx_->Rip;
s.AddrStack.Offset = ctx_->Rsp;
s.AddrFrame.Offset = ctx_->Rbp;
#elif defined(_M_ARM64)
s.AddrPC.Offset = ctx_->Pc;
s.AddrStack.Offset = ctx_->Sp;
s.AddrFrame.Offset = ctx_->Fp;
#elif defined(_M_ARM)
s.AddrPC.Offset = ctx_->Pc;
s.AddrStack.Offset = ctx_->Sp;
s.AddrFrame.Offset = ctx_->R11;
#else
s.AddrPC.Offset = ctx_->Eip;
s.AddrStack.Offset = ctx_->Esp;
s.AddrFrame.Offset = ctx_->Ebp;
#endif

if (!machine_type_) {
#ifdef _M_X64
#if defined(_M_X64)
machine_type_ = IMAGE_FILE_MACHINE_AMD64;
#elif defined(_M_ARM64)
machine_type_ = IMAGE_FILE_MACHINE_ARM64;
#elif defined(_M_ARM)
machine_type_ = IMAGE_FILE_MACHINE_ARMNT;
#else
machine_type_ = IMAGE_FILE_MACHINE_I386;
#endif
Expand Down Expand Up @@ -4269,6 +4281,8 @@ class SignalHandling {
#elif defined(__mips__)
error_addr = reinterpret_cast<void *>(
reinterpret_cast<struct sigcontext *>(&uctx->uc_mcontext)->sc_pc);
#elif defined(__APPLE__) && defined(__POWERPC__)
error_addr = reinterpret_cast<void *>(uctx->uc_mcontext->__ss.__srr0);
#elif defined(__ppc__) || defined(__powerpc) || defined(__powerpc__) || \
defined(__POWERPC__)
error_addr = reinterpret_cast<void *>(uctx->uc_mcontext.regs->nip);
Expand All @@ -4280,6 +4294,8 @@ class SignalHandling {
error_addr = reinterpret_cast<void *>(uctx->uc_mcontext->__ss.__rip);
#elif defined(__APPLE__)
error_addr = reinterpret_cast<void *>(uctx->uc_mcontext->__ss.__eip);
#elif defined(__loongarch__)
error_addr = reinterpret_cast<void *>(uctx->uc_mcontext.__pc);
#else
#warning ":/ sorry, ain't know no nothing none not of your architecture!"
#endif
Expand Down