commit 1adcfb1: [Feature] Use backward-cpp instead of manual libunwind stuff
Vsevolod Stakhov
vsevolod at rspamd.com
Wed Sep 13 13:07:04 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-09-13 14:04:20 +0100
URL: https://github.com/rspamd/rspamd/commit/1adcfb1e23467b797c55a01a1da5766fdb0876e0 (HEAD -> master)
[Feature] Use backward-cpp instead of manual libunwind stuff
---
CMakeLists.txt | 11 +-
config.h.in | 3 +-
contrib/DEPENDENCY_INFO.md | 76 +-
contrib/backward-cpp/BackwardConfig.cmake | 247 ++
contrib/backward-cpp/CMakeLists.txt | 139 +
contrib/backward-cpp/backward.cpp | 42 +
contrib/backward-cpp/backward.hpp | 4464 +++++++++++++++++++++++++++++
debian/control | 1 +
rpm/rspamd.spec | 2 +-
src/CMakeLists.txt | 2 +-
src/libserver/CMakeLists.txt | 1 +
src/libserver/backtrace.cxx | 61 +
src/libserver/worker_util.c | 80 +-
13 files changed, 5006 insertions(+), 123 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 68a9d1f89..fec5ca687 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,7 +56,7 @@ OPTION(ENABLE_CLANG_PLUGIN "Enable clang static analysing plugin [default: OFF]"
OPTION(ENABLE_PCRE2 "Enable pcre2 instead of pcre [default: ON]" ON)
OPTION(ENABLE_JEMALLOC "Build rspamd with jemalloc allocator [default: OFF]" OFF)
OPTION(ENABLE_UTILS "Build rspamd internal utils [default: OFF]" OFF)
-OPTION(ENABLE_LIBUNWIND "Use libunwind to print crash traces [default: OFF]" OFF)
+OPTION(ENABLE_LIBUNWIND "Obsoleted [default: OFF]" OFF)
OPTION(ENABLE_LUA_TRACE "Trace all Lua C API invocations [default: OFF]" OFF)
OPTION(ENABLE_LUA_REPL "Enables Lua repl (requires C++11 compiler) [default: ON]" ON)
OPTION(ENABLE_FASTTEXT "Link with FastText library [default: OFF]" OFF)
@@ -208,14 +208,6 @@ IF (ENABLE_JEMALLOC MATCHES "ON" AND NOT SANITIZE)
SET(WITH_JEMALLOC "1")
ENDIF ()
-IF (ENABLE_LIBUNWIND MATCHES "ON")
- ProcessPackage(LIBUNWIND LIBRARY unwind INCLUDE libunwind.h INCLUDE_SUFFIXES include/libunwind
- ROOT ${LIBUNWIND_ROOT_DIR} MODULES libunwind)
- SET(WITH_LIBUNWIND "1")
-ELSE ()
- CHECK_SYMBOL_EXISTS(backtrace "execinfo.h" HAVE_BACKTRACE)
-ENDIF ()
-
ProcessPackage(GLIB2 LIBRARY glib-2.0 INCLUDE glib.h
INCLUDE_SUFFIXES include/glib include/glib-2.0
ROOT ${GLIB_ROOT_DIR} MODULES glib-2.0>=2.28)
@@ -633,6 +625,7 @@ ADD_SUBDIRECTORY(contrib/libev)
ADD_SUBDIRECTORY(contrib/kann)
ADD_SUBDIRECTORY(contrib/fastutf8)
ADD_SUBDIRECTORY(contrib/google-ced)
+ADD_SUBDIRECTORY(contrib/backward-cpp)
IF (SYSTEM_FMT MATCHES "OFF")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/contrib/fmt/include")
ELSE ()
diff --git a/config.h.in b/config.h.in
index 164bd6523..59c70c67c 100644
--- a/config.h.in
+++ b/config.h.in
@@ -111,11 +111,10 @@
#cmakedefine WITH_PCRE2 1
#cmakedefine WITH_SNOWBALL 1
#cmakedefine WITH_SQLITE 1
-#cmakedefine WITH_LIBUNWIND 1
#cmakedefine WITH_LUA_TRACE 1
#cmakedefine WITH_LUA_REPL 1
#cmakedefine WITH_FASTTEXT 1
-#cmakedefine HAVE_BACKTRACE 1
+#cmakedefine BACKWARD_ENABLE 1
#cmakedefine DISABLE_PTHREAD_MUTEX 1
diff --git a/contrib/DEPENDENCY_INFO.md b/contrib/DEPENDENCY_INFO.md
index 4b3f8cb1c..3fdf29a3d 100644
--- a/contrib/DEPENDENCY_INFO.md
+++ b/contrib/DEPENDENCY_INFO.md
@@ -1,39 +1,41 @@
# Rspamd Dependency Info
-| Name | Version | License | Patched | Notes |
-|------------------------|---------|---------------------| --- | --- |
-| aho-corasick | ? | LGPL-3.0 | YES | lowercase support |
-| cdb | 1.1.0 | Public Domain / CC0 | NO | |
-| hiredis | 0.13.3 | BSD-3-Clause | YES | many changes |
-| libev | 4.33 | BSD-2-Clause | YES | many changes |
-| lc-btrie | ? | BSD-3-Clause | YES | mempool support |
-| libottery | ? | Public Domain / CC0 | YES | many changes |
-| librdns | ? | BSD-2-Clause | YES | |
-| libucl | ? | BSD-2-Clause | YES | |
-| replxx | 6d93360 | BSD-2-Clause | YES | libicu usage |
-| lua-argparse | 0.7.1 | MIT | NO | |
-| lua-bit | 1.0.2 | MIT | YES | build fixes |
-| lua-fun | ? | MIT | YES | rspamd text |
-| lua-lpeg | 1.0 | MIT | YES | rspamd text + alloc|
-| lua-moses | ? | MIT | NO | |
-| lua-lupa | ? | MIT | NO | |
-| lua-tableshape | 2.6.0 | MIT | NO | |
-| mumhash | ? | MIT | NO | |
-| ngx-http-parser | 2.2.0 | MIT | YES | spamc support |
-| Mozilla-PublicSuffix | ? | MIT | NO | |
-| snowball | ? | BSD-3-Clause | NO | |
-| t1ha | ? | Zlib | NO | |
-| uthash | 1.9.8 | BSD | YES | |
-| xxhash | 0.8.1 | BSD | NO | |
-| zstd | 1.5.4 | BSD | YES | build fixes only |
-| google-ced | 37529e6 | Apache 2 | YES | build fixes |
-| kann | ? | MIT | YES | blas/lapack changes|
-| fpconv | ? | Boost | YES | many changes |
-| fastutf8 | ? | MIT | YES | many changes |
-| expected | v1.0 | Public Domain / CC0 | NO | |
-| frozen | 1.0.1 | Apache 2 | NO | |
-| fmt | 10.0.0 | MIT | NO | |
-| doctest | 2.4.6 | MIT | NO | |
-| function2 | 4.1.0 | Boost | NO | |
-| ankerl/svector | 1.0.2 | MIT | NO | |
-| ankerl/unordered_dense | 2.0.1 | MIT | NO | |
+| Name | Version | License | Patched | Notes |
+|------------------------|---------|---------------------|---------|---------------------|
+| aho-corasick | ? | LGPL-3.0 | YES | lowercase support |
+| cdb | 1.1.0 | Public Domain / CC0 | NO | |
+| hiredis | 0.13.3 | BSD-3-Clause | YES | many changes |
+| libev | 4.33 | BSD-2-Clause | YES | many changes |
+| lc-btrie | ? | BSD-3-Clause | YES | mempool support |
+| libottery | ? | Public Domain / CC0 | YES | many changes |
+| librdns | ? | BSD-2-Clause | YES | |
+| libucl | ? | BSD-2-Clause | YES | |
+| replxx | 6d93360 | BSD-2-Clause | YES | libicu usage |
+| lua-argparse | 0.7.1 | MIT | NO | |
+| lua-bit | 1.0.2 | MIT | YES | build fixes |
+| lua-fun | ? | MIT | YES | rspamd text |
+| lua-lpeg | 1.0 | MIT | YES | rspamd text + alloc |
+| lua-moses | ? | MIT | NO | |
+| lua-lupa | ? | MIT | NO | |
+| lua-tableshape | 2.6.0 | MIT | NO | |
+| mumhash | ? | MIT | NO | |
+| ngx-http-parser | 2.2.0 | MIT | YES | spamc support |
+| Mozilla-PublicSuffix | ? | MIT | NO | |
+| snowball | ? | BSD-3-Clause | NO | |
+| t1ha | ? | Zlib | NO | |
+| uthash | 1.9.8 | BSD | YES | |
+| xxhash | 0.8.1 | BSD | NO | |
+| zstd | 1.5.4 | BSD | YES | build fixes only |
+| google-ced | 37529e6 | Apache 2 | YES | build fixes |
+| kann | ? | MIT | YES | blas/lapack changes |
+| fpconv | ? | Boost | YES | many changes |
+| fastutf8 | ? | MIT | YES | many changes |
+| expected | v1.0 | Public Domain / CC0 | NO | |
+| frozen | 1.0.1 | Apache 2 | NO | |
+| fmt | 10.0.0 | MIT | NO | |
+| doctest | 2.4.6 | MIT | NO | |
+| function2 | 4.1.0 | Boost | NO | |
+| ankerl/svector | 1.0.2 | MIT | NO | |
+| ankerl/unordered_dense | 2.0.1 | MIT | NO | |
+| backward-cpp | 1.6 | MIT | NO | |
+
diff --git a/contrib/backward-cpp/BackwardConfig.cmake b/contrib/backward-cpp/BackwardConfig.cmake
new file mode 100644
index 000000000..a982adcd6
--- /dev/null
+++ b/contrib/backward-cpp/BackwardConfig.cmake
@@ -0,0 +1,247 @@
+#
+# BackwardMacros.cmake
+# Copyright 2013 Google Inc. All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+###############################################################################
+# OPTIONS
+###############################################################################
+
+set(STACK_WALKING_UNWIND TRUE CACHE BOOL
+ "Use compiler's unwind API")
+set(STACK_WALKING_BACKTRACE FALSE CACHE BOOL
+ "Use backtrace from (e)glibc for stack walking")
+set(STACK_WALKING_LIBUNWIND FALSE CACHE BOOL
+ "Use libunwind for stack walking")
+
+set(STACK_DETAILS_AUTO_DETECT TRUE CACHE BOOL
+ "Auto detect backward's stack details dependencies")
+
+set(STACK_DETAILS_BACKTRACE_SYMBOL FALSE CACHE BOOL
+ "Use backtrace from (e)glibc for symbols resolution")
+set(STACK_DETAILS_DW FALSE CACHE BOOL
+ "Use libdw to read debug info")
+set(STACK_DETAILS_BFD FALSE CACHE BOOL
+ "Use libbfd to read debug info")
+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
+###############################################################################
+include(FindPackageHandleStandardArgs)
+
+if (STACK_WALKING_LIBUNWIND)
+ # libunwind works on the macOS without having to add special include
+ # paths or libraries
+ if (NOT APPLE)
+ find_path(LIBUNWIND_INCLUDE_DIR NAMES "libunwind.h")
+ find_library(LIBUNWIND_LIBRARY unwind)
+
+ if (LIBUNWIND_LIBRARY)
+ include(CheckSymbolExists)
+ check_symbol_exists(UNW_INIT_SIGNAL_FRAME libunwind.h HAVE_UNW_INIT_SIGNAL_FRAME)
+ if (NOT HAVE_UNW_INIT_SIGNAL_FRAME)
+ message(STATUS "libunwind does not support unwinding from signal handler frames")
+ endif()
+ endif()
+
+ set(LIBUNWIND_INCLUDE_DIRS ${LIBUNWIND_INCLUDE_DIR})
+ set(LIBDWARF_LIBRARIES ${LIBUNWIND_LIBRARY})
+ find_package_handle_standard_args(libunwind DEFAULT_MSG
+ LIBUNWIND_LIBRARY LIBUNWIND_INCLUDE_DIR)
+ mark_as_advanced(LIBUNWIND_INCLUDE_DIR LIBUNWIND_LIBRARY)
+ list(APPEND _BACKWARD_LIBRARIES ${LIBUNWIND_LIBRARY})
+ endif()
+
+ # Disable other unwinders if libunwind is found
+ set(STACK_WALKING_UNWIND FALSE)
+ set(STACK_WALKING_BACKTRACE FALSE)
+endif()
+
+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)
+ set(LIBDW_INCLUDE_DIRS ${LIBDW_INCLUDE_DIR} )
+ set(LIBDW_LIBRARIES ${LIBDW_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)
+
+ # find libbfd
+ find_path(LIBBFD_INCLUDE_DIR NAMES "bfd.h")
+ find_path(LIBDL_INCLUDE_DIR NAMES "dlfcn.h")
+ find_library(LIBBFD_LIBRARY bfd)
+ find_library(LIBDL_LIBRARY dl)
+ set(LIBBFD_INCLUDE_DIRS ${LIBBFD_INCLUDE_DIR} ${LIBDL_INCLUDE_DIR})
+ set(LIBBFD_LIBRARIES ${LIBBFD_LIBRARY} ${LIBDL_LIBRARY})
+ find_package_handle_standard_args(libbfd ${_name_mismatched_arg}
+ REQUIRED_VARS LIBBFD_LIBRARY LIBBFD_INCLUDE_DIR
+ LIBDL_LIBRARY LIBDL_INCLUDE_DIR)
+ mark_as_advanced(LIBBFD_INCLUDE_DIR LIBBFD_LIBRARY
+ LIBDL_INCLUDE_DIR LIBDL_LIBRARY)
+
+ # find libdwarf
+ find_path(LIBDWARF_INCLUDE_DIR NAMES "libdwarf.h" PATH_SUFFIXES libdwarf)
+ find_path(LIBELF_INCLUDE_DIR NAMES "libelf.h")
+ find_path(LIBDL_INCLUDE_DIR NAMES "dlfcn.h")
+ find_library(LIBDWARF_LIBRARY dwarf)
+ find_library(LIBELF_LIBRARY elf)
+ find_library(LIBDL_LIBRARY dl)
+ set(LIBDWARF_INCLUDE_DIRS ${LIBDWARF_INCLUDE_DIR} ${LIBELF_INCLUDE_DIR} ${LIBDL_INCLUDE_DIR})
+ set(LIBDWARF_LIBRARIES ${LIBDWARF_LIBRARY} ${LIBELF_LIBRARY} ${LIBDL_LIBRARY})
+ find_package_handle_standard_args(libdwarf ${_name_mismatched_arg}
+ REQUIRED_VARS LIBDWARF_LIBRARY LIBDWARF_INCLUDE_DIR
+ LIBELF_LIBRARY LIBELF_INCLUDE_DIR
+ LIBDL_LIBRARY LIBDL_INCLUDE_DIR)
+ mark_as_advanced(LIBDWARF_INCLUDE_DIR LIBDWARF_LIBRARY
+ LIBELF_INCLUDE_DIR LIBELF_LIBRARY
+ LIBDL_INCLUDE_DIR LIBDL_LIBRARY)
+
+ if (LIBDW_FOUND)
+ LIST(APPEND _BACKWARD_INCLUDE_DIRS ${LIBDW_INCLUDE_DIRS})
+ LIST(APPEND _BACKWARD_LIBRARIES ${LIBDW_LIBRARIES})
+ set(STACK_DETAILS_DW TRUE)
+ set(STACK_DETAILS_BFD FALSE)
+ set(STACK_DETAILS_DWARF FALSE)
+ set(STACK_DETAILS_BACKTRACE_SYMBOL FALSE)
+ elseif(LIBBFD_FOUND)
+ LIST(APPEND _BACKWARD_INCLUDE_DIRS ${LIBBFD_INCLUDE_DIRS})
+ LIST(APPEND _BACKWARD_LIBRARIES ${LIBBFD_LIBRARIES})
+
+ # 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}")
+ list(APPEND _BACKWARD_LIBRARIES iberty z)
+ endif()
+
+ set(STACK_DETAILS_DW FALSE)
+ set(STACK_DETAILS_BFD TRUE)
+ set(STACK_DETAILS_DWARF FALSE)
+ set(STACK_DETAILS_BACKTRACE_SYMBOL FALSE)
+ elseif(LIBDWARF_FOUND)
+ LIST(APPEND _BACKWARD_INCLUDE_DIRS ${LIBDWARF_INCLUDE_DIRS})
+ LIST(APPEND _BACKWARD_LIBRARIES ${LIBDWARF_LIBRARIES})
+
+ set(STACK_DETAILS_DW FALSE)
+ set(STACK_DETAILS_BFD FALSE)
+ set(STACK_DETAILS_DWARF TRUE)
+ set(STACK_DETAILS_BACKTRACE_SYMBOL FALSE)
+ else()
+ set(STACK_DETAILS_DW FALSE)
+ set(STACK_DETAILS_BFD FALSE)
+ set(STACK_DETAILS_DWARF FALSE)
+ set(STACK_DETAILS_BACKTRACE_SYMBOL TRUE)
+ endif()
+else()
+ if (STACK_DETAILS_DW)
+ LIST(APPEND _BACKWARD_LIBRARIES dw)
+ endif()
+
+ if (STACK_DETAILS_BFD)
+ LIST(APPEND _BACKWARD_LIBRARIES bfd dl)
+ endif()
+
+ if (STACK_DETAILS_DWARF)
+ LIST(APPEND _BACKWARD_LIBRARIES dwarf elf)
+ endif()
+endif()
+
+macro(map_definitions var_prefix define_prefix)
+ foreach(def ${ARGN})
+ if (${${var_prefix}${def}})
+ LIST(APPEND _BACKWARD_DEFINITIONS "${define_prefix}${def}=1")
+ else()
+ LIST(APPEND _BACKWARD_DEFINITIONS "${define_prefix}${def}=0")
+ endif()
+ endforeach()
+endmacro()
+
+if (NOT _BACKWARD_DEFINITIONS)
+ map_definitions("STACK_WALKING_" "BACKWARD_HAS_" UNWIND LIBUNWIND BACKTRACE)
+ map_definitions("STACK_DETAILS_" "BACKWARD_HAS_" BACKTRACE_SYMBOL DW BFD DWARF)
+endif()
+
+if(WIN32)
+ list(APPEND _BACKWARD_LIBRARIES dbghelp psapi)
+ if(MINGW)
+ set(MINGW_MSVCR_LIBRARY "msvcr90$<$<CONFIG:DEBUG>:d>" CACHE STRING "Mingw MSVC runtime import library")
+ list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY})
+ endif()
+endif()
+
+set(BACKWARD_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+
+set(BACKWARD_HAS_EXTERNAL_LIBRARIES FALSE)
+set(FIND_PACKAGE_REQUIRED_VARS BACKWARD_INCLUDE_DIR)
+if(DEFINED _BACKWARD_LIBRARIES)
+ set(BACKWARD_HAS_EXTERNAL_LIBRARIES TRUE)
+ list(APPEND FIND_PACKAGE_REQUIRED_VARS _BACKWARD_LIBRARIES)
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Backward
+ REQUIRED_VARS ${FIND_PACKAGE_REQUIRED_VARS}
+)
+list(APPEND _BACKWARD_INCLUDE_DIRS ${BACKWARD_INCLUDE_DIR})
+
+macro(add_backward target)
+ target_include_directories(${target} PRIVATE ${BACKWARD_INCLUDE_DIRS})
+ 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_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)
+
+# 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})
+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()
+endif()
diff --git a/contrib/backward-cpp/CMakeLists.txt b/contrib/backward-cpp/CMakeLists.txt
new file mode 100644
index 000000000..97327ccd1
--- /dev/null
+++ b/contrib/backward-cpp/CMakeLists.txt
@@ -0,0 +1,139 @@
+#
+# CMakeLists.txt
+# Copyright 2013 Google Inc. All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+cmake_minimum_required(VERSION 3.0)
+project(backward CXX)
+
+# Introduce variables:
+# * CMAKE_INSTALL_LIBDIR
+# * CMAKE_INSTALL_BINDIR
+# * CMAKE_INSTALL_INCLUDEDIR
+include(GNUInstallDirs)
+
+include(BackwardConfig.cmake)
+
+# check if compiler is nvcc or nvcc_wrapper
+set(COMPILER_IS_NVCC false)
+get_filename_component(COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME)
+if (COMPILER_NAME MATCHES "^nvcc")
+ set(COMPILER_IS_NVCC true)
+endif()
+
+if (DEFINED ENV{OMPI_CXX} OR DEFINED ENV{MPICH_CXX})
+ if ( ($ENV{OMPI_CXX} MATCHES "nvcc") OR ($ENV{MPICH_CXX} MATCHES "nvcc") )
+ set(COMPILER_IS_NVCC true)
+ endif()
+endif()
+
+# set CXX standard
+set(CMAKE_CXX_STANDARD_REQUIRED True)
+set(CMAKE_CXX_STANDARD 11)
+if (${COMPILER_IS_NVCC})
+ # GNU CXX extensions are not supported by 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})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
+ endif()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
+endif()
+
+###############################################################################
+# BACKWARD OBJECT
+###############################################################################
+
+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 $<TARGET_OBJECTS:backward_object> CACHE STRING
+ "Link with this object to setup backward automatically")
+
+
+###############################################################################
+# BACKWARD LIBRARY (Includes backward.cpp)
+###############################################################################
+option(BACKWARD_SHARED "Build dynamic backward-cpp shared lib" OFF)
+
+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})
+
+###############################################################################
+# 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::Backward)
+
+ 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_ENABLE})
+ endforeach()
+endif()
+
+install(
+ FILES "backward.hpp"
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+)
+install(
+ FILES "BackwardConfig.cmake"
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/backward
+)
diff --git a/contrib/backward-cpp/backward.cpp b/contrib/backward-cpp/backward.cpp
new file mode 100644
index 000000000..110441cba
--- /dev/null
+++ b/contrib/backward-cpp/backward.cpp
@@ -0,0 +1,42 @@
+// Pick your poison.
+//
+// On GNU/Linux, you have few choices to get the most out of your stack trace.
+//
+// By default you get:
+// - object filename
+// - function name
+//
+// In order to add:
+// - source filename
+// - line and column numbers
+// - source code snippet (assuming the file is accessible)
+
+// Install one of the following libraries then uncomment one of the macro (or
+// better, add the detection of the lib and the macro definition in your build
+// system)
+
+// - apt-get install libdw-dev ...
+// - g++/clang++ -ldw ...
+// #define BACKWARD_HAS_DW 1
+
+// - apt-get install binutils-dev ...
+// - g++/clang++ -lbfd ...
+// #define BACKWARD_HAS_BFD 1
+
+// - apt-get install libdwarf-dev ...
+// - g++/clang++ -ldwarf ...
+// #define BACKWARD_HAS_DWARF 1
+
+// Regardless of the library you choose to read the debug information,
+// for potentially more detailed stack traces you can use libunwind
+// - apt-get install libunwind-dev
+// - g++/clang++ -lunwind
+// #define BACKWARD_HAS_LIBUNWIND 1
+
+#include "backward.hpp"
+
+namespace backward {
+
+backward::SignalHandling sh;
+
+} // namespace backward
diff --git a/contrib/backward-cpp/backward.hpp b/contrib/backward-cpp/backward.hpp
new file mode 100644
index 000000000..ac7ad5173
--- /dev/null
+++ b/contrib/backward-cpp/backward.hpp
@@ -0,0 +1,4464 @@
+/*
+ * backward.hpp
+ * Copyright 2013 Google Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef H_6B9572DA_A64B_49E6_B234_051480991C89
+#define H_6B9572DA_A64B_49E6_B234_051480991C89
+
+#ifndef __cplusplus
+#error "It's not going to compile without a C++ compiler..."
+#endif
+
+#if defined(BACKWARD_CXX11)
+#elif defined(BACKWARD_CXX98)
+#else
+#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#define BACKWARD_CXX11
+#define BACKWARD_ATLEAST_CXX11
+#define BACKWARD_ATLEAST_CXX98
+#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
+#define BACKWARD_ATLEAST_CXX17
+#endif
+#else
+#define BACKWARD_CXX98
+#define BACKWARD_ATLEAST_CXX98
+#endif
+#endif
+
+// You can define one of the following (or leave it to the auto-detection):
+//
+// #define BACKWARD_SYSTEM_LINUX
+// - specialization for linux
+//
+// #define BACKWARD_SYSTEM_DARWIN
+// - specialization for Mac OS X 10.5 and later.
+//
+// #define BACKWARD_SYSTEM_WINDOWS
+// - specialization for Windows (Clang 9 and MSVC2017)
+//
+// #define BACKWARD_SYSTEM_UNKNOWN
+// - placebo implementation, does nothing.
+//
+#if defined(BACKWARD_SYSTEM_LINUX)
+#elif defined(BACKWARD_SYSTEM_DARWIN)
+#elif defined(BACKWARD_SYSTEM_UNKNOWN)
+#elif defined(BACKWARD_SYSTEM_WINDOWS)
+#else
+#if defined(__linux) || defined(__linux__)
+#define BACKWARD_SYSTEM_LINUX
+#elif defined(__APPLE__)
+#define BACKWARD_SYSTEM_DARWIN
+#elif defined(_WIN32)
+#define BACKWARD_SYSTEM_WINDOWS
+#else
+#define BACKWARD_SYSTEM_UNKNOWN
+#endif
+#endif
+
+#define NOINLINE __attribute__((noinline))
+
+#include <algorithm>
+#include <cctype>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include <limits>
+#include <new>
+#include <sstream>
+#include <streambuf>
*** OUTPUT TRUNCATED, 4611 LINES SKIPPED ***
More information about the Commits
mailing list