]> git.cworth.org Git - apitrace/commitdiff
backtrace: Allow to build without libbacktrace.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 20 Sep 2013 09:50:45 +0000 (10:50 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 20 Sep 2013 14:50:08 +0000 (15:50 +0100)
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.

CMakeLists.txt
common/os_backtrace.cpp
common/os_backtrace.hpp

index 4566db59ad487b920dc62d92b1cd9313b0c17681..81e5cdcd8f8ada8c8145aa0a18ab48539ba86f54 100644 (file)
@@ -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.
index 1a555900b2c89f02c386b107757df4f340ce3ed5..c95692bd11a54b6e4bb7d2e7ea44c8b1accef767 100644 (file)
  */
 
 
-
 #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 */
index ae1c831ac4a4059573be924e1ffefb9b49deedb0..27dcc90fca3c811e257262cbdaeac8c525ef4728 100644 (file)
@@ -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 */