From 7712d0ada0d09dca15cbb39705a34284858b05aa Mon Sep 17 00:00:00 2001 From: Nick Korotysh Date: Mon, 9 Apr 2018 23:30:20 +0300 Subject: [PATCH] Allow to disable Stacktrace support Enable backtrace stuff only if GNU C library used, because current backtrace implementation based on , which is not a part of standard C library, it is a GNU extension. This will be usefull when building with custom POSIX-compilant C library (like musl) and no available. Note: configure script will detect presence of and enable/disable feature depending on it. Feature is enabled by default. --- CMakeLists.txt | 8 ++++---- configure | 44 +++++++++++++++++++++++++++++++++++++++++- configure.ac | 23 ++++++++++++++++++++++ src/CMakeLists.txt | 6 +++--- src/app/CMakeLists.txt | 20 +++++++++---------- src/app/app.pri | 16 +++++++++------ src/app/main.cpp | 30 ++++++++++++++-------------- src/src.pro | 12 ++++++++---- winconf.pri | 2 +- 9 files changed, 117 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 924478431..c77a0f723 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,13 +43,13 @@ option(GUI "Allows to disable GUI for headless running. Disables QtDBus and the option(WEBUI "Allows to disable the WebUI." ON) -if (WIN32) - option(STACKTRACE_WIN "") -else (WIN32) +option(STACKTRACE "Enable stacktrace feature" ON) + +if (UNIX) cmake_dependent_option(SYSTEMD "Install the systemd service file (headless only)" OFF "NOT GUI" OFF) cmake_dependent_option(DBUS "Enable use of QtDBus (GUI only)" ON "GUI" OFF) -endif(WIN32) +endif(UNIX) add_subdirectory(src) diff --git a/configure b/configure index 94c9dc922..4f51cde8e 100755 --- a/configure +++ b/configure @@ -717,6 +717,7 @@ enable_dependency_tracking enable_silent_rules with_qtsingleapplication enable_debug +enable_stacktrace enable_gui enable_systemd enable_webui @@ -1382,6 +1383,7 @@ Optional Features: --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") --enable-debug Enable debug build + --enable-stacktrace Enable stacktrace feature (default=auto) --disable-gui Disable the GUI for headless running. Disables QtDBus and the GeoIP Database. --enable-systemd Install the systemd service file (headless only). @@ -4189,6 +4191,14 @@ else fi +# Check whether --enable-stacktrace was given. +if test "${enable_stacktrace+set}" = set; then : + enableval=$enable_stacktrace; +else + enable_stacktrace=auto +fi + + # Check whether --enable-gui was given. if test "${enable_gui+set}" = set; then : enableval=$enable_gui; @@ -4389,6 +4399,39 @@ $as_echo "$enable_debug" >&6; } as_fn_error $? "Unknown option \"$enable_debug\". Use either \"yes\" or \"no\"." "$LINENO" 5 ;; esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable the stacktrace feature" >&5 +$as_echo_n "checking whether to enable the stacktrace feature... " >&6; } + +case "x$enable_stacktrace" in #( + "xno") : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace" ;; #( + "xyes") : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace" ;; #( + "xauto") : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; #( + *) : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_stacktrace" >&5 +$as_echo "$enable_stacktrace" >&6; } + as_fn_error $? "Unknown option \"$enable_stacktrace\". Use either \"yes\" or \"no\"." "$LINENO" 5 ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable the GUI" >&5 $as_echo_n "checking whether to enable the GUI... " >&6; } case "x$enable_gui" in #( @@ -4636,7 +4679,6 @@ esac - # Check whether --with-boost was given. if test "${with_boost+set}" = set; then : withval=$with_boost; diff --git a/configure.ac b/configure.ac index 3a1e142e7..ae5640639 100644 --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,12 @@ AC_ARG_ENABLE(debug, [], [enable_debug=no]) +AC_ARG_ENABLE(stacktrace, + [AS_HELP_STRING([--enable-stacktrace], + [Enable stacktrace feature (default=auto)])], + [], + [enable_stacktrace=auto]) + AC_ARG_ENABLE(gui, [AS_HELP_STRING([--disable-gui], [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])], @@ -80,6 +86,23 @@ AS_CASE(["x$enable_debug"], [AC_MSG_RESULT([$enable_debug]) AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])]) +AC_MSG_CHECKING([whether to enable the stacktrace feature]) +AS_CASE(["x$enable_stacktrace"], + ["xno"], + [AC_MSG_RESULT([no]) + QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"], + ["xyes"], + [AC_MSG_RESULT([yes]) + QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"], + ["xauto"], + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include ]])], + [AC_MSG_RESULT([yes]) + QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"], + [AC_MSG_RESULT([no]) + QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])], + [AC_MSG_RESULT([$enable_stacktrace]) + AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])]) + AC_MSG_CHECKING([whether to enable the GUI]) AS_CASE(["x$enable_gui"], ["xyes"], diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8928a9161..5f87fed9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,9 +51,9 @@ if (NOT WEBUI) add_definitions(-DDISABLE_WEBUI) endif (NOT WEBUI) -if (STACKTRACE_WIN) - add_definitions(-DSTACKTRACE_WIN) -endif(STACKTRACE_WIN) +if (STACKTRACE) + add_definitions(-DSTACKTRACE) +endif(STACKTRACE) # nogui { # TARGET = qbittorrent-nox # } else { diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index bb5ea43e3..9dbe6f4ca 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -53,16 +53,16 @@ if (WIN32) list(APPEND QBT_APP_SOURCES ../qbittorrent.exe.manifest) endif (WIN32) -if (UNIX) - list(APPEND QBT_APP_HEADERS stacktrace.h) -endif (UNIX) - -if (STACKTRACE_WIN) - list(APPEND QBT_APP_HEADERS stacktrace_win.h) - if (GUI) - list(APPEND QBT_APP_HEADERS stacktrace_win_dlg.h) - endif (GUI) -endif (STACKTRACE_WIN) +if (STACKTRACE) + if (UNIX) + list(APPEND QBT_APP_HEADERS stacktrace.h) + else (UNIX) + list(APPEND QBT_APP_HEADERS stacktrace_win.h) + if (GUI) + list(APPEND QBT_APP_HEADERS stacktrace_win_dlg.h) + endif (GUI) + endif (UNIX) +endif (STACKTRACE) # usesystemqtsingleapplication { # nogui { diff --git a/src/app/app.pri b/src/app/app.pri index 8c8c7d870..fc792c715 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -25,12 +25,16 @@ SOURCES += \ $$PWD/filelogger.cpp \ $$PWD/main.cpp -unix: HEADERS += $$PWD/stacktrace.h -strace_win { - HEADERS += $$PWD/stacktrace_win.h - !nogui { - HEADERS += $$PWD/stacktrace_win_dlg.h - FORMS += $$PWD/stacktrace_win_dlg.ui +stacktrace { + unix { + HEADERS += $$PWD/stacktrace.h + } + else { + HEADERS += $$PWD/stacktrace_win.h + !nogui { + HEADERS += $$PWD/stacktrace_win_dlg.h + FORMS += $$PWD/stacktrace_win_dlg.ui + } } } diff --git a/src/app/main.cpp b/src/app/main.cpp index 9525bb27c..fb37fa43f 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -57,17 +57,15 @@ Q_IMPORT_PLUGIN(QICOPlugin) #endif #endif // DISABLE_GUI -#ifdef Q_OS_UNIX #include -#include +#ifdef STACKTRACE +#ifdef Q_OS_UNIX #include "stacktrace.h" -#endif // Q_OS_UNIX - -#ifdef STACKTRACE_WIN -#include +#else #include "stacktrace_win.h" #include "stacktrace_win_dlg.h" -#endif //STACKTRACE_WIN +#endif // Q_OS_UNIX +#endif //STACKTRACE #include "application.h" #include "base/profile.h" @@ -77,9 +75,10 @@ Q_IMPORT_PLUGIN(QICOPlugin) #include "upgrade.h" // Signal handlers -#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) void sigNormalHandler(int signum); +#ifdef STACKTRACE void sigAbnormalHandler(int signum); +#endif // sys_signame[] is only defined in BSD const char *sysSigName[] = { #if defined(Q_OS_WIN) @@ -94,7 +93,6 @@ const char *sysSigName[] = { "SIGPWR", "SIGUNUSED" #endif }; -#endif #if !defined Q_OS_WIN && !defined Q_OS_HAIKU void reportToUser(const char* str); @@ -255,9 +253,9 @@ int main(int argc, char *argv[]) showSplashScreen(); #endif -#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) signal(SIGINT, sigNormalHandler); signal(SIGTERM, sigNormalHandler); +#ifdef STACKTRACE signal(SIGABRT, sigAbnormalHandler); signal(SIGSEGV, sigAbnormalHandler); #endif @@ -281,7 +279,6 @@ void reportToUser(const char* str) } #endif -#if defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) void sigNormalHandler(int signum) { #if !defined Q_OS_WIN && !defined Q_OS_HAIKU @@ -295,6 +292,7 @@ void sigNormalHandler(int signum) qApp->exit(); // unsafe, but exit anyway } +#ifdef STACKTRACE void sigAbnormalHandler(int signum) { const char *sigName = sysSigName[signum]; @@ -307,16 +305,18 @@ void sigAbnormalHandler(int signum) reportToUser(sigName); reportToUser("\n"); print_stacktrace(); // unsafe -#endif // !defined Q_OS_WIN && !defined Q_OS_HAIKU -#ifdef STACKTRACE_WIN +#endif + +#if defined Q_OS_WIN StraceDlg dlg; // unsafe dlg.setStacktraceString(QLatin1String(sigName), straceWin::getBacktrace()); dlg.exec(); -#endif // STACKTRACE_WIN +#endif + signal(signum, SIG_DFL); raise(signum); } -#endif // defined(Q_OS_UNIX) || defined(STACKTRACE_WIN) +#endif // STACKTRACE #if !defined(DISABLE_GUI) void showSplashScreen() diff --git a/src/src.pro b/src/src.pro index 3b76fbafa..3e1c4619e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -33,13 +33,17 @@ nogui { LIBS += -lobjc } } + nowebui { DEFINES += DISABLE_WEBUI } -strace_win { - DEFINES += STACKTRACE_WIN - DEFINES += STACKTRACE_WIN_PROJECT_PATH=$$PWD - DEFINES += STACKTRACE_WIN_MAKEFILE_PATH=$$OUT_PWD + +stacktrace { + DEFINES += STACKTRACE + win32 { + DEFINES += STACKTRACE_WIN_PROJECT_PATH=$$PWD + DEFINES += STACKTRACE_WIN_MAKEFILE_PATH=$$OUT_PWD + } } CONFIG(debug, debug|release): message(Project is built in DEBUG mode.) diff --git a/winconf.pri b/winconf.pri index 19f240ba9..ac5153814 100644 --- a/winconf.pri +++ b/winconf.pri @@ -55,7 +55,7 @@ else { } # Stack trace support can be enabled in 'conf.pri' -strace_win { +stacktrace { win32-g++* { contains(QMAKE_HOST.arch, x86) { # i686 arch requires frame pointer preservation