From 31be6bad0bcd8b0c6b05971bbf84be83b802bd7a Mon Sep 17 00:00:00 2001 From: mos Date: Fri, 28 Jun 2024 16:36:35 +0200 Subject: [PATCH] update backward-cpp updated backward-cpp to last version fix compile under openSUSE Tumbleweed --- .../src/memory_tools/CMakeLists.txt | 2 +- .../bombela/backward-cpp/BackwardConfig.cmake | 89 ++++++++----- .../bombela/backward-cpp/CMakeLists.txt | 71 +++++++--- .../vendor/bombela/backward-cpp/README.md | 80 +++++++---- .../vendor/bombela/backward-cpp/backward.hpp | 126 +++++++++++------- .../bombela/backward-cpp/test/suicide.cpp | 4 +- .../backward-cpp/test_package/CMakeLists.txt | 2 +- 7 files changed, 250 insertions(+), 124 deletions(-) diff --git a/osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt b/osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt index af256e4..56ed2c7 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt +++ b/osrf_testing_tools_cpp/src/memory_tools/CMakeLists.txt @@ -26,7 +26,7 @@ target_include_directories(memory_tools $ $ ) -target_link_libraries(memory_tools PRIVATE Backward::Backward) + if(CMAKE_DL_LIBS) target_link_libraries(memory_tools PUBLIC ${CMAKE_DL_LIBS}) diff --git a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/BackwardConfig.cmake b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/BackwardConfig.cmake index 61d6fc9..7f6b3cb 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/BackwardConfig.cmake +++ b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/BackwardConfig.cmake @@ -43,12 +43,6 @@ set(STACK_DETAILS_BFD FALSE CACHE BOOL set(STACK_DETAILS_DWARF FALSE CACHE BOOL "Use libdwarf/libelf to read debug info") -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND NOT DEFINED BACKWARD_TESTS) - # If this is a top level CMake project, we most lixely want the tests - set(BACKWARD_TESTS ON CACHE BOOL "Enable tests") -else() - set(BACKWARD_TESTS OFF CACHE BOOL "Enable tests") -endif() ############################################################################### # CONFIGS ############################################################################### @@ -79,18 +73,31 @@ if (STACK_WALKING_LIBUNWIND) # Disable other unwinders if libunwind is found set(STACK_WALKING_UNWIND FALSE) - set(STACK_WALKING_BACKTRACE FALSE) + set(STACK_WALKING_BACKTRACE FALSE) endif() -if (${STACK_DETAILS_AUTO_DETECT} AND NOT WIN32) +if (${STACK_DETAILS_AUTO_DETECT}) if(NOT CMAKE_VERSION VERSION_LESS 3.17) set(_name_mismatched_arg NAME_MISMATCHED) endif() # find libdw find_path(LIBDW_INCLUDE_DIR NAMES "elfutils/libdw.h" "elfutils/libdwfl.h") find_library(LIBDW_LIBRARY dw) + # in case it's statically linked, look for all the possible dependencies + find_library(LIBELF_LIBRARY elf) + find_library(LIBPTHREAD_LIBRARY pthread) + find_library(LIBZ_LIBRARY z) + find_library(LIBBZ2_LIBRARY bz2) + find_library(LIBLZMA_LIBRARY lzma) + find_library(LIBZSTD_LIBRARY zstd) set(LIBDW_INCLUDE_DIRS ${LIBDW_INCLUDE_DIR} ) - set(LIBDW_LIBRARIES ${LIBDW_LIBRARY} ) + set(LIBDW_LIBRARIES ${LIBDW_LIBRARY} + $<$:${LIBELF_LIBRARY}> + $<$:${LIBPTHREAD_LIBRARY}> + $<$:${LIBZ_LIBRARY}> + $<$:${LIBBZ2_LIBRARY}> + $<$:${LIBLZMA_LIBRARY}> + $<$:${LIBZSTD_LIBRARY}>) find_package_handle_standard_args(libdw ${_name_mismatched_arg} REQUIRED_VARS LIBDW_LIBRARY LIBDW_INCLUDE_DIR) mark_as_advanced(LIBDW_INCLUDE_DIR LIBDW_LIBRARY) @@ -139,6 +146,11 @@ if (${STACK_DETAILS_AUTO_DETECT} AND NOT WIN32) # If we attempt to link against static bfd, make sure to link its dependencies, too get_filename_component(bfd_lib_ext "${LIBBFD_LIBRARY}" EXT) if (bfd_lib_ext STREQUAL "${CMAKE_STATIC_LIBRARY_SUFFIX}") + find_library(LIBSFRAME_LIBRARY NAMES sframe) + if (LIBSFRAME_LIBRARY) + list(APPEND _BACKWARD_LIBRARIES ${LIBSFRAME_LIBRARY}) + endif() + list(APPEND _BACKWARD_LIBRARIES iberty z) endif() @@ -190,14 +202,24 @@ if (NOT _BACKWARD_DEFINITIONS) endif() if(WIN32) - list(APPEND _BACKWARD_LIBRARIES dbghelp psapi) + list(APPEND _BACKWARD_LIBRARIES dbghelp psapi) if(MINGW) - set(MINGW_MSVCR_LIBRARY "msvcr90$<$:d>" CACHE STRING "Mingw MSVC runtime import library") - list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY}) - endif() + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-gcodeview SUPPORT_WINDOWS_DEBUG_INFO) + if(SUPPORT_WINDOWS_DEBUG_INFO) + set(CMAKE_EXE_LINKER_FLAGS "-Wl,--pdb= ") + add_compile_options(-gcodeview) + else() + set(MINGW_MSVCR_LIBRARY "msvcr90$<$:d>" CACHE STRING "Mingw MSVC runtime import library") + list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY}) + endif() + endif() endif() -set(BACKWARD_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}") +set(BACKWARD_INCLUDE_DIR + $ + $ +) set(BACKWARD_HAS_EXTERNAL_LIBRARIES FALSE) set(FIND_PACKAGE_REQUIRED_VARS BACKWARD_INCLUDE_DIR) @@ -208,17 +230,25 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Backward - REQUIRED_VARS ${FIND_PACKAGE_REQUIRED_VARS} + REQUIRED_VARS ${FIND_PACKAGE_REQUIRED_VARS} ) list(APPEND _BACKWARD_INCLUDE_DIRS ${BACKWARD_INCLUDE_DIR}) +# add_backward, optional bool argument; if passed and true, backward will be included as a system header macro(add_backward target) - target_include_directories(${target} PRIVATE ${BACKWARD_INCLUDE_DIRS}) + message(DEPRECATION "The add_backward() macro is deprecated, use target_link_libraries() to link to " + "one of the exported targets: Backward::Interface, Backward::Object, or Backward::Backward." + ) + if ("${ARGN}") + target_include_directories(${target} SYSTEM PRIVATE ${BACKWARD_INCLUDE_DIRS}) + else() + target_include_directories(${target} PRIVATE ${BACKWARD_INCLUDE_DIRS}) + endif() set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS ${BACKWARD_DEFINITIONS}) set_property(TARGET ${target} APPEND PROPERTY LINK_LIBRARIES ${BACKWARD_LIBRARIES}) endmacro() -set(BACKWARD_INCLUDE_DIRS ${_BACKWARD_INCLUDE_DIRS} CACHE INTERNAL "_BACKWARD_INCLUDE_DIRS") +set(BACKWARD_INCLUDE_DIRS ${_BACKWARD_INCLUDE_DIRS} CACHE INTERNAL "BACKWARD_INCLUDE_DIRS") set(BACKWARD_DEFINITIONS ${_BACKWARD_DEFINITIONS} CACHE INTERNAL "BACKWARD_DEFINITIONS") set(BACKWARD_LIBRARIES ${_BACKWARD_LIBRARIES} CACHE INTERNAL "BACKWARD_LIBRARIES") mark_as_advanced(BACKWARD_INCLUDE_DIRS BACKWARD_DEFINITIONS BACKWARD_LIBRARIES) @@ -226,22 +256,15 @@ mark_as_advanced(BACKWARD_INCLUDE_DIRS BACKWARD_DEFINITIONS BACKWARD_LIBRARIES) # Expand each definition in BACKWARD_DEFINITIONS to its own cmake var and export # to outer scope foreach(var ${BACKWARD_DEFINITIONS}) - string(REPLACE "=" ";" var_as_list ${var}) - list(GET var_as_list 0 var_name) - list(GET var_as_list 1 var_value) - set(${var_name} ${var_value}) - mark_as_advanced(${var_name}) + string(REPLACE "=" ";" var_as_list ${var}) + list(GET var_as_list 0 var_name) + list(GET var_as_list 1 var_value) + set(${var_name} ${var_value}) + mark_as_advanced(${var_name}) endforeach() -if (NOT TARGET Backward::Backward) - add_library(Backward::Backward INTERFACE IMPORTED) - set_target_properties(Backward::Backward PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${BACKWARD_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${BACKWARD_DEFINITIONS}" - ) - if(BACKWARD_HAS_EXTERNAL_LIBRARIES) - set_target_properties(Backward::Backward PROPERTIES - INTERFACE_LINK_LIBRARIES "${BACKWARD_LIBRARIES}" - ) - endif() +# if this file is used from the install tree by find_package(), include the +# file CMake-generated file where the targets are defined +if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/BackwardTargets.cmake) + include(${CMAKE_CURRENT_LIST_DIR}/BackwardTargets.cmake) endif() diff --git a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/CMakeLists.txt b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/CMakeLists.txt index 97327cc..e625f8a 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/CMakeLists.txt +++ b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/CMakeLists.txt @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.14) project(backward CXX) # Introduce variables: @@ -31,6 +31,22 @@ include(GNUInstallDirs) include(BackwardConfig.cmake) +############################################################################### +# OPTIONS +############################################################################### + +option(BACKWARD_SHARED "Build backward as a shared library" OFF) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND NOT DEFINED BACKWARD_TESTS) + # If this is a top level CMake project, we most lixely want the tests + set(BACKWARD_TESTS ON CACHE BOOL "Enable tests") +else() + set(BACKWARD_TESTS OFF CACHE BOOL "Enable tests") +endif() + +############################################################################### +# COMPILER FLAGS +############################################################################### + # check if compiler is nvcc or nvcc_wrapper set(COMPILER_IS_NVCC false) get_filename_component(COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME) @@ -52,10 +68,6 @@ if (${COMPILER_IS_NVCC}) set(CMAKE_CXX_EXTENSIONS OFF) endif() -############################################################################### -# COMPILER FLAGS -############################################################################### - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") if (NOT ${COMPILER_IS_NVCC}) @@ -65,27 +77,43 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX) endif() ############################################################################### -# BACKWARD OBJECT +# BACKWARD INTERFACE ############################################################################### -add_library(backward_object OBJECT backward.cpp) -target_compile_definitions(backward_object PRIVATE ${BACKWARD_DEFINITIONS}) -target_include_directories(backward_object PRIVATE ${BACKWARD_INCLUDE_DIRS}) -set(BACKWARD_ENABLE $ CACHE STRING - "Link with this object to setup backward automatically") +add_library(backward_interface INTERFACE) +set_target_properties(backward_interface PROPERTIES EXPORT_NAME Interface) +target_compile_definitions(backward_interface INTERFACE ${BACKWARD_DEFINITIONS}) +target_include_directories(backward_interface INTERFACE ${BACKWARD_INCLUDE_DIRS}) +if(BACKWARD_HAS_EXTERNAL_LIBRARIES) + target_link_libraries(backward_interface INTERFACE ${BACKWARD_LIBRARIES}) +endif() +add_library(Backward::Interface ALIAS backward_interface) +############################################################################### +# BACKWARD OBJECT (Includes backward.cpp) +# (Note that this target is not exported, since CMake currently does not allow +# exporting an OBJECT library.) +############################################################################### + +add_library(backward_object OBJECT backward.cpp) +set_target_properties(backward_object PROPERTIES EXPORT_NAME Object) +target_link_libraries(backward_object PUBLIC Backward::Interface) +add_library(Backward::Object ALIAS backward_object) ############################################################################### # BACKWARD LIBRARY (Includes backward.cpp) +# (Note that the linker will not include unused objects from a static library, +# unless the -Wl,--whole-archive option (or similar) is used.) ############################################################################### -option(BACKWARD_SHARED "Build dynamic backward-cpp shared lib" OFF) +set(libtype STATIC) if(BACKWARD_SHARED) set(libtype SHARED) endif() add_library(backward ${libtype} backward.cpp) -target_compile_definitions(backward PUBLIC ${BACKWARD_DEFINITIONS}) -target_include_directories(backward PUBLIC ${BACKWARD_INCLUDE_DIRS}) +set_target_properties(backward PROPERTIES EXPORT_NAME Backward) +target_link_libraries(backward PUBLIC Backward::Interface) +add_library(Backward::Backward ALIAS backward) ############################################################################### # TESTS @@ -102,7 +130,7 @@ if(BACKWARD_TESTS) add_executable(${test_name} ${src} ${ARGN} $) - target_link_libraries(${test_name} PRIVATE Backward::Backward) + target_link_libraries(${test_name} PRIVATE Backward::Interface) add_test(NAME ${name} COMMAND ${test_name}) endmacro() @@ -125,7 +153,7 @@ if(BACKWARD_TESTS) ) foreach(test ${TESTS}) - backward_add_test(test/${test}.cpp ${BACKWARD_ENABLE}) + backward_add_test(test/${test}.cpp backward.cpp) endforeach() endif() @@ -135,5 +163,14 @@ install( ) install( FILES "BackwardConfig.cmake" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/backward + 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) + # 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 + install(EXPORT BackwardTargets + NAMESPACE Backward:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") +endif() diff --git a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/README.md b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/README.md index 031716f..92c98e9 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/README.md +++ b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/README.md @@ -1,4 +1,4 @@ -Backward-cpp [![badge](https://img.shields.io/badge/conan.io-backward%2F1.3.0-green.svg?logo=data:image/png;base64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAA1VBMVEUAAABhlctjlstkl8tlmMtlmMxlmcxmmcxnmsxpnMxpnM1qnc1sn85voM91oM11oc1xotB2oc56pNF6pNJ2ptJ8ptJ8ptN9ptN8p9N5qNJ9p9N9p9R8qtOBqdSAqtOAqtR%2BrNSCrNJ/rdWDrNWCsNWCsNaJs9eLs9iRvNuVvdyVv9yXwd2Zwt6axN6dxt%2Bfx%2BChyeGiyuGjyuCjyuGly%2BGlzOKmzOGozuKoz%2BKqz%2BOq0OOv1OWw1OWw1eWx1eWy1uay1%2Baz1%2Baz1%2Bez2Oe02Oe12ee22ujUGwH3AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgBQkREyOxFIh/AAAAiklEQVQI12NgAAMbOwY4sLZ2NtQ1coVKWNvoc/Eq8XDr2wB5Ig62ekza9vaOqpK2TpoMzOxaFtwqZua2Bm4makIM7OzMAjoaCqYuxooSUqJALjs7o4yVpbowvzSUy87KqSwmxQfnsrPISyFzWeWAXCkpMaBVIC4bmCsOdgiUKwh3JojLgAQ4ZCE0AMm2D29tZwe6AAAAAElFTkSuQmCC)](http://www.conan.io/source/backward/1.3.0/Manu343726/testing) +Backward-cpp [![Conan Center](https://img.shields.io/conan/v/backward-cpp)](https://conan.io/center/recipes/backward-cpp) ============ Backward is a beautiful stack trace pretty printer for C++. @@ -45,27 +45,59 @@ Note for [folly](https://github.com/facebook/folly) library users: must define ` ### Integration with CMake -If you are using CMake and want to use its configuration abilities to save -you the trouble, you can easily integrate Backward, depending on how you obtained +If you are using CMake and want to use its configuration abilities to save you +the trouble, you can easily integrate Backward, depending on how you obtained the library. +Notice that all approaches are equivalent in the way Backward is added to a +CMake target, the difference is in how CMake is pointed to the Backward +sources. Backward defines three targets: + +- `Backward::Interface` is an interface target that brings compiler definition + flags, include directory, and external libraries. This is all you need to use + the `backward.hpp` header library. +- `Backward::Object` brings `Backward::Interface` and `backward.cpp` as an + `OBJECT` CMake library. This target cannot be exported, so it is not + available when Backward is used via `find_package`. +- `Backward::Backward` brings `Backward::Interface` and `backward.cpp` as + either `STATIC` or `SHARED` library (depending on the `BACKWARD_SHARED` + option). This target is exported and always available, however note that the + linker will not include unused objects from a static library, unless the + `-Wl,--whole-archive` option (or similar) is used. + +#### With `FetchContent()`: + +If you are using a recent version of CMake, you can integrate `backward` via `FetchContent` like below: + +```cmake +include(FetchContent) + +# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils) +FetchContent_Declare(backward + GIT_REPOSITORY https://github.com/bombela/backward-cpp + GIT_TAG master # or a version tag, such as v1.6 + SYSTEM # optional, the Backward include directory will be treated as system directory +) +FetchContent_MakeAvailable(backward) + +# Add Backward to your target (either Backward::Interface, Backward::Object, or Backward::Backward) +target_link_libraries(mytarget PUBLIC Backward::Interface) +``` + #### As a subdirectory: In this case you have a subdirectory containing the whole repository of Backward -(eg.: using git-submodules), in this case you can do: +(e.g. using [git-submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules)), +in this case you can do: -``` +```cmake add_subdirectory(/path/to/backward-cpp) -# This will add backward.cpp to your target -add_executable(mytarget mysource.cpp ${BACKWARD_ENABLE}) - -# This will add libraries, definitions and include directories needed by backward -# by setting each property on the target. -add_backward(mytarget) +# Add Backward to your target (either Backward::Interface, Backward::Object, or Backward::Backward) +target_link_libraries(mytarget PUBLIC Backward::Interface) ``` -#### Modifying CMAKE_MODULE_PATH +#### Modifying `CMAKE_MODULE_PATH`: In this case you can have Backward installed as a subdirectory: @@ -73,14 +105,10 @@ In this case you can have Backward installed as a subdirectory: list(APPEND CMAKE_MODULE_PATH /path/to/backward-cpp) find_package(Backward) -# This will add libraries, definitions and include directories needed by backward -# through an IMPORTED target. -target_link_libraries(mytarget PUBLIC Backward::Backward) +# Add Backward to your target (either Backward::Interface or Backward::Backward) +target_link_libraries(mytarget PUBLIC Backward::Interface) ``` -Notice that this is equivalent to using the the approach that uses `add_subdirectory()`, -however it uses cmake's [imported target](https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets) mechanism. - #### Installation through a regular package manager In this case you have obtained Backward through a package manager. @@ -91,10 +119,10 @@ Packages currently available: ``` find_package(Backward) -# This will add libraries, definitions and include directories needed by backward -# through an IMPORTED target. -target_link_libraries(mytarget PUBLIC Backward::Backward) +# Add Backward to your target (either Backward::Interface or Backward::Backward) +target_link_libraries(mytarget PUBLIC Backward::Interface) ``` + ### Libraries to unwind the stack On Linux and macOS, backtrace can back-trace or "walk" the stack using the @@ -379,6 +407,12 @@ this object doesn't do anything. It exposes only one method: bool loaded() const // true if loaded with success ``` +**Warning:** The registered signal handlers are not +[signal safe](https://www.man7.org/linux/man-pages/man7/signal-safety.7.html), +mostly because backward-cpp and the DWARF decoding libraries are using `malloc`. +In case a signal is raised while malloc is holding a lock, a deadlock will +occur. + ### Trace object To keep the memory footprint of a loaded `StackTrace` on the low-side, there a @@ -404,8 +438,8 @@ struct ResolvedTrace: public Trace { struct SourceLoc { std::string function; std::string filename; - size_t line; - size_t col; + unsigned line; + unsigned col; }; // In which binary object this trace is located. diff --git a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/backward.hpp b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/backward.hpp index ac7ad51..670aa45 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/backward.hpp +++ b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/backward.hpp @@ -101,7 +101,7 @@ // #define BACKWARD_HAS_UNWIND 1 // - unwind comes from libgcc, but I saw an equivalent inside clang itself. // - with unwind, the stacktrace is as accurate as it can possibly be, since -// this is used by the C++ runtine in gcc/clang for stack unwinding on +// this is used by the C++ runtime in gcc/clang for stack unwinding on // exception. // - normally libgcc is already linked to your program by default. // @@ -211,10 +211,23 @@ #else #include #endif +#if defined(__ppc__) || defined(__powerpc) || defined(__powerpc__) || \ + defined(__POWERPC__) +// Linux kernel header required for the struct pt_regs definition +// to access the NIP (Next Instruction Pointer) register value +#include +#endif #include #include #include #include +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#include +#undef _GNU_SOURCE +#else +#include +#endif #if BACKWARD_HAS_BFD == 1 // NOTE: defining PACKAGE{,_VERSION} is required before including @@ -227,13 +240,6 @@ #define PACKAGE_VERSION #endif #include -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#include -#undef _GNU_SOURCE -#else -#include -#endif #endif #if BACKWARD_HAS_DW == 1 @@ -248,13 +254,6 @@ #include #include #include -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#include -#undef _GNU_SOURCE -#else -#include -#endif #endif #if (BACKWARD_HAS_BACKTRACE == 1) || (BACKWARD_HAS_BACKTRACE_SYMBOL == 1) @@ -271,7 +270,7 @@ // #define BACKWARD_HAS_UNWIND 1 // - unwind comes from libgcc, but I saw an equivalent inside clang itself. // - with unwind, the stacktrace is as accurate as it can possibly be, since -// this is used by the C++ runtine in gcc/clang for stack unwinding on +// this is used by the C++ runtime in gcc/clang for stack unwinding on // exception. // - normally libgcc is already linked to your program by default. // @@ -338,7 +337,12 @@ #include #include + +#ifdef _WIN64 typedef SSIZE_T ssize_t; +#else +typedef int ssize_t; +#endif #ifndef NOMINMAX #define NOMINMAX @@ -517,7 +521,7 @@ template struct default_delete { void operator()(T &ptr) const { delete ptr; } }; -template > +template > class handle { struct dummy; T _val; @@ -723,6 +727,7 @@ template class StackTraceImpl { } size_t thread_id() const { return 0; } void skip_n_firsts(size_t) {} + void *const *begin() const { return nullptr; } }; class StackTraceImplBase { @@ -806,7 +811,12 @@ template class Unwinder { _index = -1; _depth = depth; _Unwind_Backtrace(&this->backtrace_trampoline, this); - return static_cast(_index); + if (_index == -1) { + // _Unwind_Backtrace has failed to obtain any backtraces + return 0; + } else { + return static_cast(_index); + } } private: @@ -827,7 +837,7 @@ template class Unwinder { uintptr_t ip = _Unwind_GetIPInfo(ctx, &ip_before_instruction); if (!ip_before_instruction) { - // calculating 0-1 for unsigned, looks like a possible bug to sanitiziers, + // calculating 0-1 for unsigned, looks like a possible bug to sanitizers, // so let's do it explicitly: if (ip == 0) { ip = std::numeric_limits::max(); // set it to 0xffff... (as @@ -1224,7 +1234,7 @@ class TraceResolverImplBase { } template void load_stacktrace(ST &st) { - load_addresses(st.begin(), (int)st.size()); + load_addresses(st.begin(), static_cast(st.size())); } virtual ResolvedTrace resolve(ResolvedTrace t) { return t; } @@ -1449,7 +1459,7 @@ class TraceResolverLinuxImpl // line of the function that was called. But if the code is optimized, // we might get something absolutely not related since the compiler // can reschedule the return address with inline functions and - // tail-call optimisation (among other things that I don't even know + // tail-call optimization (among other things that I don't even know // or cannot even dream about with my tiny limited brain). find_sym_result details_adjusted_call_site = find_symbol_details( fobj, (void *)(uintptr_t(trace.addr) - 1), symbol_info.dli_fbase); @@ -1480,7 +1490,7 @@ class TraceResolverLinuxImpl // this time we get the name of the function where the code is // located, instead of the function were the address is // located. In short, if the code was inlined, we get the - // function correspoding to the code. Else we already got in + // function corresponding to the code. Else we already got in // trace.function. trace.source.function = demangle(details_selected->funcname); @@ -1549,7 +1559,7 @@ class TraceResolverLinuxImpl bool _bfd_loaded; typedef details::handle> + details::deleter > bfd_handle_t; typedef details::handle bfd_symtab_t; @@ -1695,7 +1705,7 @@ class TraceResolverLinuxImpl // are we in the boundaries of the section? if (addr < sec_addr || addr >= sec_addr + size) { - addr -= base_addr; // oups, a relocated object, lets try again... + addr -= base_addr; // oops, a relocated object, lets try again... if (addr < sec_addr || addr >= sec_addr + size) { return; } @@ -1774,7 +1784,7 @@ class TraceResolverLinuxImpl ResolvedTrace resolve(ResolvedTrace trace) override { using namespace details; - Dwarf_Addr trace_addr = (Dwarf_Addr)trace.addr; + Dwarf_Addr trace_addr = reinterpret_cast(trace.addr); if (!_dwfl_handle_initialized) { // initialize dwfl... @@ -1906,8 +1916,8 @@ class TraceResolverLinuxImpl int line = 0, col = 0; dwarf_lineno(srcloc, &line); dwarf_linecol(srcloc, &col); - trace.source.line = line; - trace.source.col = col; + trace.source.line = static_cast(line); + trace.source.col = static_cast(col); } deep_first_search_by_pc(cudie, trace_addr - mod_bias, @@ -1921,9 +1931,9 @@ class TraceResolverLinuxImpl } private: - typedef details::handle> + typedef details::handle > dwfl_handle_t; - details::handle> + details::handle > _dwfl_cb; dwfl_handle_t _dwfl_handle; bool _dwfl_handle_initialized; @@ -1954,8 +1964,8 @@ class TraceResolverLinuxImpl Dwarf_Word line = 0, col = 0; dwarf_formudata(dwarf_attr(die, DW_AT_call_line, &attr_mem), &line); dwarf_formudata(dwarf_attr(die, DW_AT_call_column, &attr_mem), &col); - sloc.line = (unsigned)line; - sloc.col = (unsigned)col; + sloc.line = static_cast(line); + sloc.col = static_cast(col); trace.inliners.push_back(sloc); break; @@ -2245,14 +2255,14 @@ class TraceResolverLinuxImpl private: bool _dwarf_loaded; - typedef details::handle> + typedef details::handle > dwarf_file_t; - typedef details::handle> + typedef details::handle > dwarf_elf_t; typedef details::handle> + details::deleter > dwarf_handle_t; typedef std::map die_linemap_t; @@ -3610,10 +3620,12 @@ template <> class TraceResolverImpl symOptions |= SYMOPT_LOAD_LINES | SYMOPT_UNDNAME; SymSetOptions(symOptions); EnumProcessModules(process, &module_handles[0], - module_handles.size() * sizeof(HMODULE), &cbNeeded); + static_cast(module_handles.size() * sizeof(HMODULE)), + &cbNeeded); module_handles.resize(cbNeeded / sizeof(HMODULE)); EnumProcessModules(process, &module_handles[0], - module_handles.size() * sizeof(HMODULE), &cbNeeded); + static_cast(module_handles.size() * sizeof(HMODULE)), + &cbNeeded); std::transform(module_handles.begin(), module_handles.end(), std::back_inserter(modules), get_mod_info(process)); void *base = modules[0].base_address; @@ -3686,7 +3698,7 @@ class TraceResolver : public TraceResolverImpl {}; class SourceFile { public: - typedef std::vector> lines_t; + typedef std::vector > lines_t; SourceFile() {} SourceFile(const std::string &path) { @@ -3797,11 +3809,18 @@ class SourceFile { } #endif + // Allow adding to paths gotten from BACKWARD_CXX_SOURCE_PREFIXES after loading the + // library; this can be useful when the library is loaded when the locations are unknown + // Warning: Because this edits the static paths variable, it is *not* intrinsiclly thread safe + static void add_paths_to_env_variable_impl(const std::string & to_add) { + get_mutable_paths_from_env_variable().push_back(to_add); + } + private: - details::handle> + details::handle > _file; - std::vector get_paths_from_env_variable_impl() { + static std::vector get_paths_from_env_variable_impl() { std::vector paths; const char *prefixes_str = std::getenv("BACKWARD_CXX_SOURCE_PREFIXES"); if (prefixes_str && prefixes_str[0]) { @@ -3810,9 +3829,13 @@ class SourceFile { return paths; } - const std::vector &get_paths_from_env_variable() { - static std::vector paths = get_paths_from_env_variable_impl(); - return paths; + static std::vector &get_mutable_paths_from_env_variable() { + static volatile std::vector paths = get_paths_from_env_variable_impl(); + return const_cast&>(paths); + } + + static const std::vector &get_paths_from_env_variable() { + return get_mutable_paths_from_env_variable(); } #ifdef BACKWARD_ATLEAST_CXX11 @@ -3980,10 +4003,12 @@ class Printer { bool object; int inliner_context_size; int trace_context_size; + bool reverse; Printer() : snippet(true), color_mode(ColorMode::automatic), address(false), - object(false), inliner_context_size(5), trace_context_size(7) {} + object(false), inliner_context_size(5), trace_context_size(7), + reverse(true) {} template FILE *print(ST &st, FILE *fp = stderr) { cfile_streambuf obuf(fp); @@ -4030,8 +4055,14 @@ class Printer { void print_stacktrace(ST &st, std::ostream &os, Colorize &colorize) { print_header(os, st.thread_id()); _resolver.load_stacktrace(st); - for (size_t trace_idx = st.size(); trace_idx > 0; --trace_idx) { - print_trace(os, _resolver.resolve(st[trace_idx - 1]), colorize); + if ( reverse ) { + for (size_t trace_idx = st.size(); trace_idx > 0; --trace_idx) { + print_trace(os, _resolver.resolve(st[trace_idx - 1]), colorize); + } + } else { + for (size_t trace_idx = 0; trace_idx < st.size(); ++trace_idx) { + print_trace(os, _resolver.resolve(st[trace_idx]), colorize); + } } } @@ -4245,7 +4276,8 @@ class SignalHandling { printer.address = true; printer.print(st, stderr); -#if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L +#if (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || \ + (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) psiginfo(info, nullptr); #else (void)info; @@ -4360,7 +4392,7 @@ class SignalHandling { static const constexpr int signal_skip_recs = #ifdef __clang__ // With clang, RtlCaptureContext also captures the stack frame of the - // current function Below that, there ar 3 internal Windows functions + // current function Below that, there are 3 internal Windows functions 4 #else // With MSVC cl, RtlCaptureContext misses the stack frame of the current diff --git a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test/suicide.cpp b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test/suicide.cpp index aa8022c..784fcd8 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test/suicide.cpp +++ b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test/suicide.cpp @@ -57,8 +57,8 @@ void abort_abort_I_repeat_abort_abort() { TEST_ABORT(calling_abort) { abort_abort_I_repeat_abort_abort(); } -// aarch64 and mips does not trap Division by zero -#if !defined(__aarch64__) || !defined(__mips__) +// aarch64, mips, PowerPC and RISC-V do not trap Division by zero +#if !defined(__aarch64__) && !defined(__mips__) && !defined (__powerpc__) && !defined (__riscv) volatile int zero = 0; int divide_by_zero() { diff --git a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test_package/CMakeLists.txt b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test_package/CMakeLists.txt index 90cf190..13a8d68 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test_package/CMakeLists.txt +++ b/osrf_testing_tools_cpp/src/memory_tools/vendor/bombela/backward-cpp/test_package/CMakeLists.txt @@ -1,5 +1,5 @@ project(backward-package-test) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.12) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS)