From: José Fonseca Date: Fri, 20 Sep 2013 09:50:45 +0000 (+0100) Subject: backtrace: Allow to build without libbacktrace. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=d6c02fd58feb2b48be13a2405d0eb738ed62925a backtrace: Allow to build without libbacktrace. For apitrace integrated into Regal they want to opt-out of backtrace support, for now. One reason is that it's fairly platform-specific. Another concern is potential build issue across various Linux flavors. Based on Nigel Stewart patch on issue #168. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4566db5..81e5cdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -269,6 +269,7 @@ if (CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF") add_subdirectory (thirdparty/libbacktrace) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libbacktrace) set (LIBBACKTRACE_LIBRARIES dl backtrace) + add_definitions (-DHAVE_BACKTRACE=1) endif () # Always use bundled QJSon. diff --git a/common/os_backtrace.cpp b/common/os_backtrace.cpp index 1a55590..c95692b 100644 --- a/common/os_backtrace.cpp +++ b/common/os_backtrace.cpp @@ -30,14 +30,25 @@ */ - #include "os_backtrace.hpp" -#if defined(ANDROID) || defined(__ELF__) - #include +#include #include "os.hpp" +#if defined(ANDROID) +# include +#elif HAVE_BACKTRACE +# include +# include +# include +# include +# include +# include +# include +#endif + + using trace::Id; namespace os { @@ -111,16 +122,8 @@ bool backtrace_is_needed(const char* fname) { return backtraceFunctionNamePrefixes.contain(fname); } -} /* namespace os */ - #if defined(ANDROID) -#include -#include "os.hpp" -#include - -namespace os { - /* The following two declarations are copied from Android sources */ enum DebugTargetKind { @@ -274,21 +277,9 @@ void dump_backtrace() { /* TODO */ } -} /* namespace os */ -/* end ANDROID */ -#elif defined(__ELF__) +#elif HAVE_BACKTRACE -#include -#include -#include -#include -#include -#include - -#include - -namespace os { static char* format(uintptr_t num, int base, char *buf, int maxlen) { @@ -480,8 +471,16 @@ void dump_backtrace() { } -} /* namespace os */ +#else /* !HAVE_BACKTRACE */ -#endif /* __ELF__ */ +std::vector get_backtrace() { + return std::vector(); +} -#endif /* ANDROID or LINUX */ +void dump_backtrace() { +} + +#endif + + +} /* namespace os */ diff --git a/common/os_backtrace.hpp b/common/os_backtrace.hpp index ae1c831..27dcc90 100644 --- a/common/os_backtrace.hpp +++ b/common/os_backtrace.hpp @@ -36,32 +36,11 @@ namespace os { using trace::RawStackFrame; -#if defined(ANDROID) || defined(__ELF__) - std::vector get_backtrace(); bool backtrace_is_needed(const char* fname); -#else - -static inline std::vector get_backtrace() { - return std::vector(); -} - -static inline bool backtrace_is_needed(const char*) { - return false; -} - -#endif - -#if defined(__ELF__) - void dump_backtrace(); -#else - -static inline void dump_backtrace() {} - -#endif } /* namespace os */