add backward as backtrace pretty printer

this patch adds the MIT-licensed header-only library backward-cpp
as possible alternative for our internal backtrace-to-file
writer.
master
Andre Puschmann 4 years ago
parent 711438f756
commit 3784439088

@ -269,6 +269,17 @@ if (ENABLE_TTCN3)
message(STATUS "Building with TTCN3 binaries") message(STATUS "Building with TTCN3 binaries")
endif (ENABLE_TTCN3) endif (ENABLE_TTCN3)
# Backward-cpp
find_package(Backward)
if(Backward_FOUND)
if(BACKWARD_HAS_EXTERNAL_LIBRARIES)
add_definitions(-DHAVE_BACKWARD)
message(STATUS "Building with backward-cpp support")
else (BACKWARD_HAS_EXTERNAL_LIBRARIES)
message(STATUS "Backward-cpp found, but external libraries are missing.")
endif()
endif()
######################################################################## ########################################################################
# Install Dirs # Install Dirs
######################################################################## ########################################################################

@ -46,6 +46,10 @@ Files: lib/include/srslte/srslog/bundled/fmt/chrono.h
Copyright: 2012-2020, Victor Zverovich Copyright: 2012-2020, Victor Zverovich
License: MIT License: MIT
Files: lib/include/srslte/common/backward.hpp
cmake/modules/FindBackward.cmake
Copyright: 2013, Google Inc.
License: MIT
License: AGPL-3+ License: AGPL-3+
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

@ -132,6 +132,7 @@ Note that depending on your flavor and version of Linux, the actual package name
* Optional requirements: * Optional requirements:
* srsgui: https://github.com/srslte/srsgui - for real-time plotting. * srsgui: https://github.com/srslte/srsgui - for real-time plotting.
* libpcsclite-dev: https://pcsclite.apdu.fr/ - for accessing smart card readers * libpcsclite-dev: https://pcsclite.apdu.fr/ - for accessing smart card readers
* libdw-dev libdw - for truly informative backtraces using backward-cpp
* RF front-end driver: * RF front-end driver:
* UHD: https://github.com/EttusResearch/uhd * UHD: https://github.com/EttusResearch/uhd

@ -0,0 +1,243 @@
#
# 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
###############################################################################
if(POLICY CMP0011)
cmake_policy(SET CMP0011 NEW)
cmake_policy(SET CMP0012 NEW)
endif()
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})
# 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 DEFAULT_MSG
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 DEFAULT_MSG
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 DEFAULT_MSG
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()
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})
#message(STATUS "${var_name}=${var_value}")
endforeach()
# Disabled for older CMake version (CentOS)
#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()

5
debian/copyright vendored

@ -53,6 +53,11 @@ Files: lib/include/srslte/srslog/bundled/fmt/chrono.h
Copyright: 2012-2020, Victor Zverovich Copyright: 2012-2020, Victor Zverovich
License: MIT License: MIT
Files: lib/include/srslte/common/backward.hpp
cmake/modules/FindBackward.cmake
Copyright: 2013, Google Inc.
License: MIT
License: AGPL-3+ License: AGPL-3+
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

File diff suppressed because it is too large Load Diff

@ -12,7 +12,7 @@ set(SOURCES arch_select.cc
backtrace.c backtrace.c
band_helper.cc band_helper.cc
buffer_pool.cc buffer_pool.cc
crash_handler.c crash_handler.cc
gen_mch_tables.c gen_mch_tables.c
liblte_security.cc liblte_security.cc
log_filter.cc log_filter.cc
@ -47,8 +47,9 @@ add_dependencies(srslte_common gen_build_info)
add_executable(arch_select arch_select.cc) add_executable(arch_select arch_select.cc)
target_include_directories(srslte_common PUBLIC ${SEC_INCLUDE_DIRS}) target_include_directories(srslte_common PUBLIC ${SEC_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${BACKWARD_INCLUDE_DIRS})
target_link_libraries(srslte_common srslte_phy srslog ${SEC_LIBRARIES}) target_link_libraries(srslte_common srslte_phy srslog ${SEC_LIBRARIES} ${BACKWARD_LIBRARIES})
target_compile_definitions(srslte_common PRIVATE ${BACKWARD_DEFINITIONS})
INSTALL(TARGETS srslte_common DESTINATION ${LIBRARY_DIR}) INSTALL(TARGETS srslte_common DESTINATION ${LIBRARY_DIR})

@ -15,8 +15,17 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "srslte/common/backtrace.h"
#include "srslte/common/crash_handler.h" #include "srslte/common/crash_handler.h"
#if HAVE_BACKWARD
#include "srslte/common/backward.hpp"
using namespace backward;
void srslte_debug_handle_crash(int argc, char** argv)
{
backward::SignalHandling sh;
}
#else // HAVE_BACKWARD
#include "srslte/common/backtrace.h"
#include "srslte/version.h" #include "srslte/version.h"
const static char crash_file_name[] = "./srsLTE.backtrace.crash"; const static char crash_file_name[] = "./srsLTE.backtrace.crash";
@ -65,3 +74,5 @@ void srslte_debug_handle_crash(int argc, char** argv)
signal(SIGFPE, crash_handler); signal(SIGFPE, crash_handler);
signal(SIGPIPE, crash_handler); signal(SIGPIPE, crash_handler);
} }
#endif // HAVE_BACKWARD
Loading…
Cancel
Save