logging: Add proper backtrace support detection

The Q_OS_UNIX macro is inappropriate because many UNIX-like platforms may
lack backtrace support in the libc. E.g.: Darwin / Mac OS X, Musl libc,
OpenBSD, OpenIndiana.
This commit is contained in:
Ismael Luceno 2021-08-22 21:49:25 +02:00 committed by John Maguire
parent c8c110efaf
commit 628ff65828
3 changed files with 9 additions and 4 deletions

View File

@ -39,3 +39,6 @@ target_link_libraries(libclementine-common
${TAGLIB_LIBRARIES} ${TAGLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
) )
find_package(Backtrace)
configure_file(core/conf_backtrace.h.in conf_backtrace.h)

View File

@ -0,0 +1,4 @@
#cmakedefine Backtrace_FOUND
#ifdef Backtrace_FOUND
#include <@Backtrace_HEADER@>
#endif

View File

@ -21,9 +21,7 @@
#include <cxxabi.h> #include <cxxabi.h>
#include <QtGlobal> #include <QtGlobal>
#ifdef Q_OS_UNIX #include "conf_backtrace.h"
#include <execinfo.h>
#endif
#include <glib.h> #include <glib.h>
@ -325,7 +323,7 @@ QString DemangleSymbol(const QString& symbol) {
} }
void DumpStackTrace() { void DumpStackTrace() {
#ifdef Q_OS_UNIX #ifdef Backtrace_FOUND
void* callstack[128]; void* callstack[128];
int callstack_size = int callstack_size =
backtrace(reinterpret_cast<void**>(&callstack), sizeof(callstack)); backtrace(reinterpret_cast<void**>(&callstack), sizeof(callstack));