mirror of https://github.com/oxen-io/oxen-core.git
Merge pull request #1456 from jagerman/cmake-cleanups
CMake/build cleanups
This commit is contained in:
commit
17413713b4
|
@ -138,6 +138,7 @@ local android_build_steps(android_abi, android_platform=21, jobs=6, cmake_extra=
|
|||
'-DCMAKE_TOOLCHAIN_FILE=/usr/lib/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake ' +
|
||||
'-DANDROID_PLATFORM=' + android_platform + ' -DANDROID_ABI=' + android_abi + ' ' +
|
||||
'-DMONERO_SLOW_HASH=ON ' +
|
||||
'-DLOCAL_MIRROR=https://builds.lokinet.dev/deps ' +
|
||||
'-DBUILD_STATIC_DEPS=ON -DSTATIC=ON -G Ninja ' + cmake_extra,
|
||||
'ninja -j' + jobs + ' -v wallet_merged',
|
||||
'cd ..',
|
||||
|
|
|
@ -75,6 +75,16 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||
set(CMAKE_C_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
|
||||
cmake_policy(SET CMP0083 NEW)
|
||||
include(CheckPIESupported)
|
||||
check_pie_supported(OUTPUT_VARIABLE pie_error LANGUAGES CXX C)
|
||||
if(NOT CMAKE_CXX_LINK_PIE_SUPPORTED)
|
||||
message(WARNING "PIE linking is not supported: ${pie_error}")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "PIE disabled: cmake 3.14+ is required for proper PIE linking support")
|
||||
endif()
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
@ -616,7 +626,7 @@ else()
|
|||
add_c_flag_if_supported(-fcf-protection=full C_SECURITY_FLAGS)
|
||||
add_cxx_flag_if_supported(-fcf-protection=full CXX_SECURITY_FLAGS)
|
||||
endif()
|
||||
if (NOT WIN32 AND NOT OPENBSD)
|
||||
if (NOT WIN32 AND NOT OPENBSD AND NOT APPLE)
|
||||
add_c_flag_if_supported(-fstack-clash-protection C_SECURITY_FLAGS)
|
||||
add_cxx_flag_if_supported(-fstack-clash-protection CXX_SECURITY_FLAGS)
|
||||
endif()
|
||||
|
@ -628,10 +638,6 @@ else()
|
|||
endif()
|
||||
|
||||
# linker
|
||||
if (NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)))
|
||||
# Windows binaries die on startup with PIE when compiled with GCC <9.x
|
||||
add_linker_flag_if_supported(-pie LD_SECURITY_FLAGS)
|
||||
endif()
|
||||
add_linker_flag_if_supported(-Wl,-z,relro LD_SECURITY_FLAGS)
|
||||
add_linker_flag_if_supported(-Wl,-z,now LD_SECURITY_FLAGS)
|
||||
add_linker_flag_if_supported(-Wl,-z,noexecstack noexecstack_SUPPORTED)
|
||||
|
@ -697,10 +703,6 @@ else()
|
|||
message(STATUS "Selecting VFP for ARMv6")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfp")
|
||||
if(DEPENDS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm")
|
||||
endif()
|
||||
endif(ARM6)
|
||||
|
||||
if(ARM7)
|
||||
|
@ -745,14 +747,6 @@ else()
|
|||
|
||||
endif(ARM)
|
||||
|
||||
if(ANDROID OR IOS)
|
||||
#From Android 5: "only position independent executables (PIE) are supported"
|
||||
message(STATUS "Enabling PIE executable")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -pie")
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -DGTEST_HAS_TR1_TUPLE=0")
|
||||
endif()
|
||||
|
@ -830,11 +824,7 @@ add_library(icu INTERFACE)
|
|||
if(MINGW)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj")
|
||||
target_link_libraries(extra INTERFACE mswsock ws2_32 iphlpapi crypt32 bcrypt)
|
||||
if(DEPENDS)
|
||||
link_dep_libs(icu INTERFACE "" icuio icui18n icuuc icudata icutu iconv)
|
||||
else()
|
||||
link_dep_libs(icu INTERFACE "" icuio icuin icuuc icudt icutu iconv)
|
||||
endif()
|
||||
link_dep_libs(icu INTERFACE "" icuio icuin icuuc icudt icutu iconv)
|
||||
elseif(FREEBSD)
|
||||
target_link_libraries(extra INTERFACE execinfo)
|
||||
elseif(DRAGONFLY)
|
||||
|
@ -843,14 +833,10 @@ elseif(DRAGONFLY)
|
|||
elseif(CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
|
||||
target_link_libraries(extra INTERFACE socket nsl resolv)
|
||||
elseif(APPLE)
|
||||
if(DEPENDS)
|
||||
target_link_libraries(extra INTERFACE "-framework Foundation" "-framework IOKit" "-framework AppKit" "-framework IOKit")
|
||||
else()
|
||||
find_library(COREFOUNDATION CoreFoundation)
|
||||
find_library(IOKIT IOKit)
|
||||
target_link_libraries(extra INTERFACE ${IOKIT} ${COREFOUNDATION})
|
||||
endif()
|
||||
elseif(NOT (MSVC OR DEPENDS OR APPLE OR OPENBSD OR ANDROID))
|
||||
find_library(COREFOUNDATION CoreFoundation)
|
||||
find_library(IOKIT IOKit)
|
||||
target_link_libraries(extra INTERFACE ${IOKIT} ${COREFOUNDATION})
|
||||
elseif(NOT (MSVC OR APPLE OR OPENBSD OR ANDROID))
|
||||
find_library(RT rt)
|
||||
target_link_libraries(extra INTERFACE rt)
|
||||
endif()
|
||||
|
@ -865,7 +851,7 @@ else()
|
|||
option(USE_READLINE "Build with GNU readline support." ON)
|
||||
if(USE_READLINE AND BUILD_STATIC_DEPS)
|
||||
# readline target already set up
|
||||
elseif(USE_READLINE AND NOT DEPENDS)
|
||||
elseif(USE_READLINE)
|
||||
find_package(Readline)
|
||||
if(READLINE_FOUND AND GNU_READLINE_FOUND)
|
||||
add_library(readline INTERFACE)
|
||||
|
@ -876,14 +862,6 @@ else()
|
|||
else()
|
||||
message(STATUS "Could not find GNU readline library so building without readline support")
|
||||
endif()
|
||||
elseif(USE_READLINE AND DEPENDS AND NOT MINGW)
|
||||
find_path(Readline_INCLUDE_PATH readline/readline.h)
|
||||
find_library(Readline_LIBRARY readline)
|
||||
find_library(Terminfo_LIBRARY tinfo)
|
||||
add_library(readline INTERFACE)
|
||||
target_link_libraries(readline INTERFACE ${Readline_LIBRARY} ${Terminfo_LIBRARY})
|
||||
target_include_directories(readline INTERFACE ${Readline_INCLUDE_PATH})
|
||||
target_compile_definitions(readline INTERFACE HAVE_READLINE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -902,13 +880,9 @@ if(BUILD_STATIC_DEPS)
|
|||
# sqlite3 target already set up
|
||||
else()
|
||||
add_library(sqlite3 INTERFACE)
|
||||
if (NOT SQLITE3_LIBRARIES)
|
||||
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
|
||||
endif()
|
||||
find_library(sqlite3_link_libs NAMES ${SQLITE3_LIBRARIES} PATHS ${SQLITE3_LIBRARY_DIRS})
|
||||
message(STATUS "sqlite3: ${SQLITE3_LIBRARIES} ${sqlite3_link_libs}")
|
||||
target_link_libraries(sqlite3 INTERFACE ${sqlite3_link_libs})
|
||||
target_include_directories(sqlite3 INTERFACE ${SQLITE3_INCLUDE_DIRS})
|
||||
pkg_check_modules(SQLITE3 REQUIRED sqlite3 IMPORTED_TARGET)
|
||||
message(STATUS "Found sqlite3 ${SQLITE3_VERSION}")
|
||||
target_link_libraries(sqlite3 INTERFACE PkgConfig::SQLITE3)
|
||||
endif()
|
||||
|
||||
add_subdirectory(contrib)
|
||||
|
|
|
@ -43,10 +43,9 @@ option(WITH_MINIUPNPC "Enable miniupnpc support for IGD NAT hole punching" ${DEF
|
|||
if(NOT STATIC AND NOT BUILD_STATIC_DEPS)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
if(WITH_MINIUPNPC)
|
||||
pkg_check_modules(MINIUPNPC miniupnpc>=2.1)
|
||||
pkg_check_modules(MINIUPNPC miniupnpc>=2.1 IMPORTED_TARGET)
|
||||
endif()
|
||||
pkg_check_modules(UNBOUND libunbound)
|
||||
pkg_check_modules(LOKIMQ liboxenmq>=1.2.3)
|
||||
pkg_check_modules(OXENMQ liboxenmq>=1.2.3 IMPORTED_TARGET)
|
||||
endif()
|
||||
|
||||
if(NOT WITH_MINIUPNPC)
|
||||
|
@ -54,8 +53,7 @@ if(NOT WITH_MINIUPNPC)
|
|||
target_compile_definitions(miniupnpc INTERFACE WITHOUT_MINIUPNPC)
|
||||
elseif(MINIUPNPC_FOUND)
|
||||
message(STATUS "Found miniupnpc")
|
||||
link_dep_libs(miniupnpc INTERFACE "${MINIUPNPC_LIBRARY_DIRS}" ${MINIUPNPC_LIBRARIES})
|
||||
target_include_directories(miniupnpc INTERFACE ${MINIUPNPC_INCLUDE_DIRS})
|
||||
target_link_libraries(miniupnpc INTERFACE PkgConfig::MINIUPNPC)
|
||||
else()
|
||||
message(STATUS "Using in-tree miniupnpc")
|
||||
add_subdirectory(miniupnp/miniupnpc)
|
||||
|
@ -72,31 +70,14 @@ else()
|
|||
endif()
|
||||
|
||||
|
||||
if(NOT LOKIMQ_FOUND)
|
||||
if(NOT OXENMQ_FOUND)
|
||||
message(STATUS "Using in-tree oxenmq")
|
||||
if (DEPENDS)
|
||||
# The depends system builds a static libzmq so set up a target loki-mq can use to avoid building
|
||||
add_library(libzmq STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${ZMQ_LIBRARIES})
|
||||
target_link_libraries(libzmq INTERFACE sodium)
|
||||
target_include_directories(libzmq INTERFACE ${ZMQ_INCLUDE_DIRS})
|
||||
message(STATUS "${ZMQ_INCLUDE_DIRS} ${ZMQ_LIBRARIES}")
|
||||
endif()
|
||||
add_subdirectory(loki-mq)
|
||||
else()
|
||||
add_library(oxenmq INTERFACE)
|
||||
link_dep_libs(oxenmq INTERFACE "${LOKIMQ_LIBRARY_DIRS}" ${LOKIMQ_LIBRARIES})
|
||||
target_include_directories(oxenmq INTERFACE ${LOKIMQ_INCLUDE_DIRS})
|
||||
target_link_libraries(oxenmq INTERFACE PkgConfig::OXENMQ)
|
||||
add_library(oxenmq::oxenmq ALIAS oxenmq)
|
||||
message(STATUS "Found liboxenmq ${LOKIMQ_VERSION}")
|
||||
|
||||
# TODO: Temporary fix for also linking libzmq; this can go when the direct zmq code (for zmq
|
||||
# server) gets replaced with oxenmq.
|
||||
pkg_check_modules(LIBZMQ libzmq)
|
||||
if (LIBZMQ_FOUND)
|
||||
link_dep_libs(oxenmq INTERFACE "${LIBZMQ_LIBRARY_DIRS}" ${LIBZMQ_LIBRARIES})
|
||||
target_include_directories(oxenmq INTERFACE ${LIBZMQ_INCLUDE_DIRS})
|
||||
endif()
|
||||
message(STATUS "Found liboxenmq ${OXENMQ_VERSION}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(db_drivers)
|
||||
|
|
|
@ -34,21 +34,10 @@ if (NOT (MINGW OR APPLE OR FREEBSD OR OPENBSD OR DRAGONFLY))
|
|||
add_compile_options("${WARNINGS_AS_ERRORS_FLAG}") # applies only to targets that follow
|
||||
endif()
|
||||
|
||||
function (enable_stack_trace target)
|
||||
if(STACK_TRACE)
|
||||
target_compile_definitions("${target}" PRIVATE STACK_TRACE)
|
||||
if (STATIC)
|
||||
set_property(TARGET "${target}"
|
||||
APPEND PROPERTY LINK_FLAGS "-Wl,--wrap=__cxa_throw")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set_property(GLOBAL PROPERTY oxen_executable_targets "")
|
||||
function (oxen_add_executable target binary)
|
||||
add_executable("${target}" ${ARGN})
|
||||
target_link_libraries("${target}" PRIVATE extra)
|
||||
enable_stack_trace("${target}")
|
||||
set_target_properties("${target}" PROPERTIES
|
||||
OUTPUT_NAME "${binary}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
|
|
@ -57,13 +57,6 @@ set_source_files_properties(${PROJECT_BINARY_DIR}/translations/translation_files
|
|||
add_dependencies(common generate_translation_data)
|
||||
|
||||
|
||||
if (STACK_TRACE)
|
||||
target_sources(common PRIVATE stack_trace.cpp)
|
||||
if(WIN32 OR STATIC)
|
||||
target_compile_definitions(common PRIVATE STATICLIB)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (BACKCOMPAT)
|
||||
target_sources(common PRIVATE compat/glibc_compat.cpp)
|
||||
endif()
|
||||
|
@ -78,23 +71,3 @@ target_link_libraries(common
|
|||
OpenSSL::SSL
|
||||
OpenSSL::Crypto
|
||||
extra)
|
||||
|
||||
option(STACK_TRACE "Install a hook that dumps stack on exception" OFF)
|
||||
|
||||
if(STACK_TRACE)
|
||||
# Can't install hook in static build on OSX, because OSX linker does not support --wrap
|
||||
# On ARM, having libunwind package (with .so's only) installed breaks static link.
|
||||
# When possible, avoid stack tracing using libunwind in favor of using easylogging++.
|
||||
if (APPLE)
|
||||
elseif (DEPENDS AND NOT LINUX)
|
||||
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT MINGW)
|
||||
target_link_libraries(common PRIVATE easylogging) # for diag output only
|
||||
elseif (ARM AND STATIC)
|
||||
else()
|
||||
find_package(Libunwind)
|
||||
if(LIBUNWIND_FOUND)
|
||||
target_link_libraries(common PRIVATE ${LIBUNWIND_LIBRARIES})
|
||||
target_include_directories(common PRIVATE ${LIBUNWIND_INCLUDE_DIR})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -1,177 +0,0 @@
|
|||
// Copyright (c) 2016-2019, The Monero Project
|
||||
// Copyright (c) 2018, The Loki Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#if !defined __GNUC__ || defined __MINGW32__ || defined __MINGW64__ || defined __ANDROID__
|
||||
#define USE_UNWIND
|
||||
#else
|
||||
#define ELPP_FEATURE_CRASH_LOG 1
|
||||
#endif
|
||||
#include "easylogging++/easylogging++.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#ifdef USE_UNWIND
|
||||
#define UNW_LOCAL_ONLY
|
||||
#include <libunwind.h>
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
#ifndef STATICLIB
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "common/stack_trace.h"
|
||||
#include "epee/misc_log_ex.h"
|
||||
|
||||
#undef OXEN_DEFAULT_LOG_CATEGORY
|
||||
#define OXEN_DEFAULT_LOG_CATEGORY "stacktrace"
|
||||
|
||||
#define ST_LOG(x) \
|
||||
do { \
|
||||
auto elpp = ELPP; \
|
||||
if (elpp) { \
|
||||
CINFO(el::base::Writer,el::base::DispatchAction::FileOnlyLog,OXEN_DEFAULT_LOG_CATEGORY) << x; \
|
||||
} \
|
||||
else { \
|
||||
std::cout << x << std::endl; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
// from https://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c
|
||||
|
||||
// The decl of __cxa_throw in /usr/include/.../cxxabi.h uses
|
||||
// 'std::type_info *', but GCC's built-in protype uses 'void *'.
|
||||
#ifdef __clang__
|
||||
#define CXA_THROW_INFO_T std::type_info
|
||||
#else // !__clang__
|
||||
#define CXA_THROW_INFO_T void
|
||||
#endif // !__clang__
|
||||
|
||||
#ifdef STATICLIB
|
||||
#define CXA_THROW __wrap___cxa_throw
|
||||
extern "C"
|
||||
__attribute__((noreturn))
|
||||
void __real___cxa_throw(void *ex, CXA_THROW_INFO_T *info, void (*dest)(void*));
|
||||
#else // !STATICLIB
|
||||
#define CXA_THROW __cxa_throw
|
||||
extern "C"
|
||||
typedef
|
||||
#ifdef __clang__ // only clang, not GCC, lets apply the attr in typedef
|
||||
__attribute__((noreturn))
|
||||
#endif // __clang__
|
||||
void (cxa_throw_t)(void *ex, CXA_THROW_INFO_T *info, void (*dest)(void*));
|
||||
#endif // !STATICLIB
|
||||
|
||||
extern "C"
|
||||
__attribute__((noreturn))
|
||||
void CXA_THROW(void *ex, CXA_THROW_INFO_T *info, void (*dest)(void*))
|
||||
{
|
||||
|
||||
int status;
|
||||
char *dsym = abi::__cxa_demangle(((const std::type_info*)info)->name(), NULL, NULL, &status);
|
||||
tools::log_stack_trace((std::string("Exception: ")+((!status && dsym) ? dsym : (const char*)info)).c_str());
|
||||
free(dsym);
|
||||
|
||||
#ifndef STATICLIB
|
||||
#ifndef __clang__ // for GCC the attr can't be applied in typedef like for clang
|
||||
__attribute__((noreturn))
|
||||
#endif // !__clang__
|
||||
cxa_throw_t *__real___cxa_throw = (cxa_throw_t*)dlsym(RTLD_NEXT, "__cxa_throw");
|
||||
#endif // !STATICLIB
|
||||
__real___cxa_throw(ex, info, dest);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string stack_trace_log;
|
||||
}
|
||||
|
||||
namespace tools
|
||||
{
|
||||
|
||||
void set_stack_trace_log(const std::string &log)
|
||||
{
|
||||
stack_trace_log = log;
|
||||
}
|
||||
|
||||
void log_stack_trace(const char *msg)
|
||||
{
|
||||
#ifdef USE_UNWIND
|
||||
unw_context_t ctx;
|
||||
unw_cursor_t cur;
|
||||
unw_word_t ip, off;
|
||||
unsigned level;
|
||||
char sym[512], *dsym;
|
||||
int status;
|
||||
const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();
|
||||
#endif
|
||||
|
||||
if (msg)
|
||||
ST_LOG(msg);
|
||||
ST_LOG("Unwound call stack:");
|
||||
|
||||
#ifdef USE_UNWIND
|
||||
if (unw_getcontext(&ctx) < 0) {
|
||||
ST_LOG("Failed to create unwind context");
|
||||
return;
|
||||
}
|
||||
if (unw_init_local(&cur, &ctx) < 0) {
|
||||
ST_LOG("Failed to find the first unwind frame");
|
||||
return;
|
||||
}
|
||||
for (level = 1; level < 999; ++level) { // 999 for safety
|
||||
int ret = unw_step(&cur);
|
||||
if (ret < 0) {
|
||||
ST_LOG("Failed to find the next frame");
|
||||
return;
|
||||
}
|
||||
if (ret == 0)
|
||||
break;
|
||||
if (unw_get_reg(&cur, UNW_REG_IP, &ip) < 0) {
|
||||
ST_LOG(" " << std::setw(4) << level);
|
||||
continue;
|
||||
}
|
||||
if (unw_get_proc_name(&cur, sym, sizeof(sym), &off) < 0) {
|
||||
ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip);
|
||||
continue;
|
||||
}
|
||||
dsym = abi::__cxa_demangle(sym, NULL, NULL, &status);
|
||||
ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off);
|
||||
free(dsym);
|
||||
}
|
||||
#else
|
||||
std::stringstream ss;
|
||||
ss << el::base::debug::StackTrace();
|
||||
std::vector<std::string> lines;
|
||||
std::string s = ss.str();
|
||||
boost::split(lines, s, boost::is_any_of("\n"));
|
||||
for (const auto &line: lines)
|
||||
ST_LOG(line);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace tools
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (c) 2016-2019, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef MONERO_EXCEPTION_H
|
||||
#define MONERO_EXCEPTION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace tools
|
||||
{
|
||||
|
||||
void set_stack_trace_log(const std::string &log);
|
||||
void log_stack_trace(const char *msg);
|
||||
|
||||
} // namespace tools
|
||||
|
||||
#endif
|
|
@ -41,7 +41,6 @@
|
|||
#include "epee/wipeable_string.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "util.h"
|
||||
#include "stack_trace.h"
|
||||
#include "epee/misc_os_dependent.h"
|
||||
#include "epee/readline_buffer.h"
|
||||
#include "string_util.h"
|
||||
|
@ -74,41 +73,6 @@ namespace tools
|
|||
return with_threads;
|
||||
}
|
||||
|
||||
#ifdef STACK_TRACE
|
||||
#ifdef _WIN32
|
||||
// https://stackoverflow.com/questions/1992816/how-to-handle-seg-faults-under-windows
|
||||
static LONG WINAPI windows_crash_handler(PEXCEPTION_POINTERS pExceptionInfo)
|
||||
{
|
||||
tools::log_stack_trace("crashing");
|
||||
exit(1);
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
static void setup_crash_dump()
|
||||
{
|
||||
SetUnhandledExceptionFilter(windows_crash_handler);
|
||||
}
|
||||
#else
|
||||
static void posix_crash_handler(int signal)
|
||||
{
|
||||
tools::log_stack_trace(("crashing with fatal signal " + std::to_string(signal)).c_str());
|
||||
#ifdef NDEBUG
|
||||
_exit(1);
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
static void setup_crash_dump()
|
||||
{
|
||||
signal(SIGSEGV, posix_crash_handler);
|
||||
signal(SIGBUS, posix_crash_handler);
|
||||
signal(SIGILL, posix_crash_handler);
|
||||
signal(SIGFPE, posix_crash_handler);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
static void setup_crash_dump() {}
|
||||
#endif
|
||||
|
||||
bool disable_core_dumps()
|
||||
{
|
||||
#ifdef __GLIBC__
|
||||
|
@ -143,8 +107,6 @@ namespace tools
|
|||
{
|
||||
mlog_configure("", true);
|
||||
|
||||
setup_crash_dump();
|
||||
|
||||
#ifdef __GLIBC__
|
||||
const char *ver = ::gnu_get_libc_version();
|
||||
if (!strcmp(ver, "2.25"))
|
||||
|
|
|
@ -47,10 +47,6 @@
|
|||
#include "command_server.h"
|
||||
#include "daemon.h"
|
||||
|
||||
#ifdef STACK_TRACE
|
||||
#include "common/stack_trace.h"
|
||||
#endif // STACK_TRACE
|
||||
|
||||
#undef OXEN_DEFAULT_LOG_CATEGORY
|
||||
#define OXEN_DEFAULT_LOG_CATEGORY "daemon"
|
||||
|
||||
|
@ -311,10 +307,6 @@ int main(int argc, char const * argv[])
|
|||
}
|
||||
logs_initialized = true;
|
||||
|
||||
#ifdef STACK_TRACE
|
||||
tools::set_stack_trace_log(log_file_path.filename().string());
|
||||
#endif // STACK_TRACE
|
||||
|
||||
if (!command_line::is_arg_defaulted(vm, daemon_args::arg_max_concurrency))
|
||||
tools::set_max_concurrency(command_line::get_arg(vm, daemon_args::arg_max_concurrency));
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@ target_link_libraries(core_tests
|
|||
Boost::program_options
|
||||
miniupnpc
|
||||
extra)
|
||||
enable_stack_trace(core_tests)
|
||||
set_property(TARGET core_tests
|
||||
PROPERTY
|
||||
FOLDER "tests")
|
||||
|
|
|
@ -52,7 +52,6 @@ target_link_libraries(trezor_tests
|
|||
${ZMQ_LIB}
|
||||
extra)
|
||||
|
||||
enable_stack_trace(trezor_tests)
|
||||
set_property(TARGET trezor_tests
|
||||
PROPERTY
|
||||
FOLDER "tests")
|
||||
|
|
Loading…
Reference in New Issue