summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-04-24 05:08:12 +0200
committerSven Gothel <[email protected]>2022-04-24 05:08:12 +0200
commitdb3f34ae795c0f0789018925371bf45271cb3e7b (patch)
treef45dc14ac2ed661ed2442810e70e84e459fd5ada
parentb78e1670ae329dad4a89065873e5345752f998f0 (diff)
Allow disabling libunwind for backtrace (stability, default disabled for arm32/armhf else enabled), use cmake variable USE_LIBUNWIND
-rw-r--r--JaulibSetup.cmake20
-rw-r--r--README.md5
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/debug.cpp17
4 files changed, 39 insertions, 5 deletions
diff --git a/JaulibSetup.cmake b/JaulibSetup.cmake
index 477ce46..19b6541 100644
--- a/JaulibSetup.cmake
+++ b/JaulibSetup.cmake
@@ -125,6 +125,26 @@ message (STATUS "OS_NAME ${OS_NAME}")
message (STATUS "OS_ARCH ${OS_ARCH} (${CMAKE_SYSTEM_PROCESSOR})")
message (STATUS "OS_AND_ARCH ${OS_AND_ARCH}")
+message(STATUS "${PROJECT_NAME} USE_LIBUNWIND = ${USE_LIBUNWIND} (pre-set)")
+if(NOT DEFINED USE_LIBUNWIND)
+ if(${OS_ARCH} STREQUAL "armhf")
+ set(USE_LIBUNWIND OFF)
+ message(STATUS "${PROJECT_NAME} USE_LIBUNWIND ${USE_LIBUNWIND} (default armhf)")
+ else()
+ set(USE_LIBUNWIND ON)
+ message(STATUS "${PROJECT_NAME} USE_LIBUNWIND ${USE_LIBUNWIND} (default !armhf)")
+ endif()
+else()
+ message(STATUS "${PROJECT_NAME} USE_LIBUNWIND ${USE_LIBUNWIND} (user)")
+endif()
+if(USE_LIBUNWIND)
+ set(LIBUNWIND_LIBNAME "unwind")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_LIBUNWIND=1")
+else()
+ set(LIBUNWIND_LIBNAME "")
+endif()
+message(STATUS "${PROJECT_NAME} USE_LIBUNWIND ${USE_LIBUNWIND} -> libname ${LIBUNWIND_LIBNAME}")
+
# Make a version file containing the current version from git.
include (GetGitRevisionDescription)
diff --git a/README.md b/README.md
index 18b2fec..08eedcc 100644
--- a/README.md
+++ b/README.md
@@ -77,6 +77,11 @@ Disable stripping native lib even in non debug build:
~~~~~~~~~~~~~
-DUSE_STRIP=OFF
~~~~~~~~~~~~~
+Disable using `libunwind` (default: enabled for all but `arm32`, `armhf`)
+~~~~~~~~~~~~~
+-DUSE_LIBUNWIND=OFF
+~~~~~~~~~~~~~
+
Override default javac debug arguments `source,lines`:
~~~~~~~~~~~~~
-DJAVAC_DEBUG_ARGS="source,lines,vars"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dcb2c60..6253666 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,7 +21,7 @@ set (jaulib_LIB_SRCS
add_library (jaulib SHARED ${jaulib_LIB_SRCS})
target_link_libraries (
jaulib
- unwind
+ ${LIBUNWIND_LIBNAME}
${CMAKE_THREAD_LIBS_INIT}
)
diff --git a/src/debug.cpp b/src/debug.cpp
index acc77a7..08ae750 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -27,9 +27,11 @@
#include <cstdarg>
-#define UNW_LOCAL_ONLY
-#include <libunwind.h>
-#include <cxxabi.h>
+#ifdef USE_LIBUNWIND
+ #define UNW_LOCAL_ONLY
+ #include <libunwind.h>
+ #include <cxxabi.h>
+#endif /* USE_LIBUNWIND */
using namespace jau;
@@ -44,11 +46,12 @@ using namespace jau;
#endif
std::string jau::get_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames, const jau::snsize_t skip_frames) noexcept {
+ std::string out;
+#ifdef USE_LIBUNWIND
// symbol:
// 1: _ZN9direct_bt10DBTAdapter14startDiscoveryEbNS_19HCILEOwnAddressTypeEtt + 0x58d @ ip 0x7faa959d6daf, sp 0x7ffe38f301e0
// de-mangled:
// 1: direct_bt::DBTAdapter::startDiscovery(bool, direct_bt::HCILEOwnAddressType, unsigned short, unsigned short) + 0x58d @ ip 0x7f687b459071, sp 0x7fff2bf795d0
- std::string out;
jau::snsize_t frame=0;
int res;
char cstr[256];
@@ -108,6 +111,12 @@ std::string jau::get_backtrace(const bool skip_anon_frames, const jau::snsize_t
out.append(line);
}
}
+#else /* USE_LIBUNWIND */
+ (void)skip_anon_frames;
+ (void)max_frames;
+ (void)skip_frames;
+ out.append("0: backtrace disabled\n");
+#endif /* USE_LIBUNWIND */
return out;
}