diff options
author | José Fonseca <jfonseca@vmware.com> | 2013-09-20 10:50:45 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2013-09-20 15:50:08 +0100 |
commit | d6c02fd58feb2b48be13a2405d0eb738ed62925a (patch) | |
tree | c5575e4260de33eb5220c9479ac842bdf191af41 | |
parent | bd9811ff579a0482bfd7d40b1149bcef40ad3d71 (diff) |
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.
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | common/os_backtrace.cpp | 53 | ||||
-rw-r--r-- | common/os_backtrace.hpp | 21 |
3 files changed, 27 insertions, 48 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4566db59..81e5cdcd 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 1a555900..c95692bd 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 <set> +#include <vector> #include "os.hpp" +#if defined(ANDROID) +# include <dlfcn.h> +#elif HAVE_BACKTRACE +# include <stdint.h> +# include <dlfcn.h> +# include <unistd.h> +# include <map> +# include <vector> +# include <cxxabi.h> +# include <backtrace.h> +#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 <dlfcn.h> -#include "os.hpp" -#include <vector> - -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 <stdint.h> -#include <dlfcn.h> -#include <unistd.h> -#include <map> -#include <vector> -#include <cxxabi.h> - -#include <backtrace.h> - -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<RawStackFrame> get_backtrace() { + return std::vector<RawStackFrame>(); +} -#endif /* ANDROID or LINUX */ +void dump_backtrace() { +} + +#endif + + +} /* namespace os */ diff --git a/common/os_backtrace.hpp b/common/os_backtrace.hpp index ae1c831a..27dcc90f 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<RawStackFrame> get_backtrace(); bool backtrace_is_needed(const char* fname); -#else - -static inline std::vector<RawStackFrame> get_backtrace() { - return std::vector<RawStackFrame>(); -} - -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 */ |