Skip to content

Commit

Permalink
Enhanced stack-traces via backwards library
Browse files Browse the repository at this point in the history
Backwards library provides basic stack-traces of a crash and enhanced
stack-traces by using libdw and/or libbfd.
This patch will detect if either library exists on the system and set
the appropriate compiler directives accordingly.
The libraries will be packages as part of the Lambda zip file.
  • Loading branch information
marcomagdy committed May 8, 2019
1 parent 02c35e4 commit 3c6fb20
Show file tree
Hide file tree
Showing 3 changed files with 3,769 additions and 18 deletions.
34 changes: 16 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
project(aws-lambda-runtime
VERSION 0.1.0
VERSION 0.2.0
LANGUAGES CXX)

option(ENABLE_TESTS "Enables building the test project, requires AWS C++ SDK." OFF)

include(CheckCXXSourceCompiles)
include(CheckCXXCompilerFlag)

check_cxx_source_compiles("
#include <execinfo.h>
int main() {
void *buffer[5];
int nptrs = backtrace(buffer, 5);
char **strings = backtrace_symbols(buffer, nptrs);
return !!strings;
}" HAVE_BACKTRACE)


check_cxx_compiler_flag("-Wl,-flto" LTO_CAPABLE)

add_library(${PROJECT_NAME}
"src/logging.cpp"
"src/runtime.cpp"
"src/backward.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/version.cpp"
)

Expand All @@ -39,10 +27,6 @@ find_package(CURL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CURL_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CURL_INCLUDE_DIRS})

if(HAVE_BACKTRACE)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DHAVE_BACKTRACE)
endif()

target_compile_options(${PROJECT_NAME} PRIVATE
"-fno-exceptions"
"-fno-rtti"
Expand All @@ -53,6 +37,20 @@ target_compile_options(${PROJECT_NAME} PRIVATE
"-Wconversion"
"-Wno-sign-conversion")

find_library(DW_LIB NAMES dw)
if (NOT DW_LIB STREQUAL DW_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libdw: ${DW_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_DW=1")
target_link_libraries(${PROJECT_NAME} PUBLIC "${DW_LIB}")
else()
find_library(BFD_LIB NAMES bfd)
if (NOT BFD_LIB STREQUAL BFD_LIB-NOTFOUND)
message("-- Enhanced stack-traces are enabled via libbfd: ${BFD_LIB}")
target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_BFD=1")
target_link_libraries(${PROJECT_NAME} PRIVATE "${BFD_LIB}")
endif()
endif()

if (LOG_VERBOSITY)
target_compile_definitions(${PROJECT_NAME} PRIVATE "AWS_LAMBDA_LOG=${LOG_VERBOSITY}")
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
Expand Down
Loading

0 comments on commit 3c6fb20

Please sign in to comment.