fix: fixed macOS clang build, fixed macOS StackTrace

This commit is contained in:
Qv2ray-dev 2020-06-29 00:10:35 +08:00
parent d484508c68
commit bd79b38e60
No known key found for this signature in database
GPG Key ID: E7FAEFAFCD031D4B
7 changed files with 56 additions and 50 deletions

View File

@ -107,6 +107,7 @@ set(QV2RAY_TRANSLATION_PATH "unset" CACHE STRING "Qv2ray translations path")
set(QV2RAY_DISABLE_AUTO_UPDATE OFF CACHE BOOL "Disable update checker") set(QV2RAY_DISABLE_AUTO_UPDATE OFF CACHE BOOL "Disable update checker")
set(BUILD_TESTING OFF CACHE BOOL "Build test") set(BUILD_TESTING OFF CACHE BOOL "Build test")
set(EMBED_TRANSLATIONS OFF CACHE BOOL "Embed translations") set(EMBED_TRANSLATIONS OFF CACHE BOOL "Embed translations")
set(QV2RAY_AUTO_DEPLOY ON CACHE BOOL "Automatically run deploy command after build")
if(QV2RAY_DEFAULT_VASSETS_PATH AND NOT QV2RAY_DEFAULT_VASSETS_PATH STREQUAL "unset") if(QV2RAY_DEFAULT_VASSETS_PATH AND NOT QV2RAY_DEFAULT_VASSETS_PATH STREQUAL "unset")
add_definitions(-DQV2RAY_DEFAULT_VASSETS_PATH="${QV2RAY_DEFAULT_VASSETS_PATH}") add_definitions(-DQV2RAY_DEFAULT_VASSETS_PATH="${QV2RAY_DEFAULT_VASSETS_PATH}")
@ -326,14 +327,16 @@ if(APPLE)
) )
# Destination paths below are relative to ${CMAKE_INSTALL_PREFIX} # Destination paths below are relative to ${CMAKE_INSTALL_PREFIX}
install(TARGETS qv2ray install(TARGETS qv2ray
BUNDLE DESTINATION . COMPONENT Runtime BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime RUNTIME DESTINATION bin COMPONENT Runtime
) )
if(QV2RAY_AUTO_DEPLOY)
add_custom_command(TARGET qv2ray POST_BUILD add_custom_command(TARGET qv2ray POST_BUILD
COMMAND macdeployqt ${CMAKE_BINARY_DIR}/qv2ray.app COMMAND ${Qt5_DIR}/../../../bin/macdeployqt ${CMAKE_BINARY_DIR}/qv2ray.app
) )
endif()
set(APPS "\${CMAKE_INSTALL_PREFIX}/qv2ray.app") set(APPS "\${CMAKE_INSTALL_PREFIX}/qv2ray.app")
include(cmake/deployment.cmake) include(cmake/deployment.cmake)
endif() endif()
@ -355,10 +358,11 @@ if(WIN32)
if(NOT EMBED_TRANSLATIONS) if(NOT EMBED_TRANSLATIONS)
install(FILES ${QM_FILES} DESTINATION lang) install(FILES ${QM_FILES} DESTINATION lang)
endif() endif()
if(QV2RAY_AUTO_DEPLOY)
add_custom_command(TARGET qv2ray POST_BUILD add_custom_command(TARGET qv2ray POST_BUILD
COMMAND ${Qt5_DIR}/../../../bin/windeployqt ${CMAKE_BINARY_DIR}/qv2ray.exe --compiler-runtime --verbose 2 --dir ${CMAKE_BINARY_DIR}/winqt/ COMMAND ${Qt5_DIR}/../../../bin/windeployqt ${CMAKE_BINARY_DIR}/qv2ray.exe --compiler-runtime --verbose 2 --dir ${CMAKE_BINARY_DIR}/winqt/
) )
endif()
install(DIRECTORY ${CMAKE_BINARY_DIR}/winqt/ DESTINATION .) install(DIRECTORY ${CMAKE_BINARY_DIR}/winqt/ DESTINATION .)
set(APPS "\${CMAKE_INSTALL_PREFIX}/qv2ray.exe") set(APPS "\${CMAKE_INSTALL_PREFIX}/qv2ray.exe")
include(cmake/deployment.cmake) include(cmake/deployment.cmake)

View File

@ -1 +1 @@
5681 5682

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <QString> #include <QString>
#ifdef Q_OS_LINUX #ifdef Q_OS_UNIX
#include "backward.hpp" #include "backward.hpp"
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -17,18 +17,16 @@ namespace Qv2ray
public: public:
static QString GetStackTrace() static QString GetStackTrace()
{ {
#ifdef Q_OS_LINUX #ifdef Q_OS_UNIX
return GetStackTraceImpl_Linux(); return GetStackTraceImpl_Unix();
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
return GetStackTraceImpl_Windows(); return GetStackTraceImpl_Windows();
#else
return "";
#endif #endif
} }
private: private:
#ifdef Q_OS_LINUX #ifdef Q_OS_UNIX
static QString GetStackTraceImpl_Linux() static QString GetStackTraceImpl_Unix()
{ {
using namespace backward; using namespace backward;
StackTrace st; StackTrace st;
@ -69,21 +67,23 @@ namespace Qv2ray
DWORD displacement; DWORD displacement;
IMAGEHLP_LINE64 *line = (IMAGEHLP_LINE64 *) malloc(sizeof(IMAGEHLP_LINE64)); IMAGEHLP_LINE64 *line = (IMAGEHLP_LINE64 *) malloc(sizeof(IMAGEHLP_LINE64));
line->SizeOfStruct = sizeof(IMAGEHLP_LINE64); line->SizeOfStruct = sizeof(IMAGEHLP_LINE64);
//
QString msg;
//
for (int i = 0; i < numberOfFrames; i++) for (int i = 0; i < numberOfFrames; i++)
{ {
DWORD64 address = (DWORD64)(stack[i]); const auto address = (DWORD64) stack[i];
SymFromAddr(process, address, NULL, symbol); SymFromAddr(process, address, NULL, symbol);
if (SymGetLineFromAddr64(process, address, &displacement, line)) if (SymGetLineFromAddr64(process, address, &displacement, line))
{ {
printf("\tat %s in %s: line: %lu: address: 0x%0X\n", symbol->Name, line->FileName, line->LineNumber, symbol->Address); msg += QString("[%1]: %2 (%3:%4)\r\n").arg(symbol->Address).arg(symbol->Name).arg(line->FileName).arg(line->LineNumber);
} }
else else
{ {
printf("\tSymGetLineFromAddr64 returned error code %lu.\n", GetLastError()); msg += QString("[*]: %1 SymGetLineFromAddr64[%2]\r\n").arg(symbol->Address).arg(symbol->Name).arg(GetLastError());
printf("\tat %s, address 0x%0X.\n", symbol->Name, symbol->Address);
} }
} }
return 0; return msg;
} }
#endif #endif
}; };

View File

@ -27,6 +27,18 @@ using namespace Qv2ray::base::objects;
using namespace Qv2ray::base::objects::protocol; using namespace Qv2ray::base::objects::protocol;
using namespace Qv2ray::base::objects::transfer; using namespace Qv2ray::base::objects::transfer;
class _qv2ray_global_config_impl_details
{
public:
static Qv2rayConfigObject _GlobalConfig;
static bool _isExiting;
static QString _Qv2rayConfigPath;
};
#define GlobalConfig (_qv2ray_global_config_impl_details::_GlobalConfig)
#define isExiting (_qv2ray_global_config_impl_details::_isExiting)
#define Qv2rayConfigPath (_qv2ray_global_config_impl_details::_Qv2rayConfigPath)
#define QV2RAY_BUILD_INFO QString(_QV2RAY_BUILD_INFO_STR_) #define QV2RAY_BUILD_INFO QString(_QV2RAY_BUILD_INFO_STR_)
#define QV2RAY_BUILD_EXTRA_INFO QString(_QV2RAY_BUILD_EXTRA_INFO_STR_) #define QV2RAY_BUILD_EXTRA_INFO QString(_QV2RAY_BUILD_EXTRA_INFO_STR_)
@ -38,7 +50,7 @@ using namespace Qv2ray::base::objects::transfer;
#endif #endif
// Get Configured Config Dir Path // Get Configured Config Dir Path
#define QV2RAY_CONFIG_DIR (Qv2ray::Qv2rayConfigPath) #define QV2RAY_CONFIG_DIR (Qv2rayConfigPath)
#define QV2RAY_CONFIG_FILE (QV2RAY_CONFIG_DIR + "Qv2ray.conf") #define QV2RAY_CONFIG_FILE (QV2RAY_CONFIG_DIR + "Qv2ray.conf")
// //
#define QV2RAY_ROUTING_DIR (QV2RAY_CONFIG_DIR + "rounting/") #define QV2RAY_ROUTING_DIR (QV2RAY_CONFIG_DIR + "rounting/")
@ -109,25 +121,9 @@ using namespace Qv2ray::base::objects::transfer;
#define API_TAG_INBOUND "_QV2RAY_API_INBOUND_" #define API_TAG_INBOUND "_QV2RAY_API_INBOUND_"
#define QV2RAY_USE_FPROXY_KEY "_QV2RAY_USE_GLOBAL_FORWARD_PROXY_" #define QV2RAY_USE_FPROXY_KEY "_QV2RAY_USE_GLOBAL_FORWARD_PROXY_"
//#define GlobalConfig (Qv2ray::GetGlobalConfig())
namespace Qv2ray namespace Qv2ray
{ {
//namespace
//{
inline Qv2rayConfigObject GlobalConfig;
//}
// Qv2ray runtime config
inline bool isExiting = false;
inline QString Qv2rayConfigPath = "";
//inline Qv2rayConfigObject &GetGlobalConfig()
// {
// if (!realGlobalConfig)
// {
// realGlobalConfig = std::make_unique<Qv2rayConfigObject>();
// }
// return *realGlobalConfig;
// };
inline QStringList Qv2rayAssetsPaths(const QString &dirName) inline QStringList Qv2rayAssetsPaths(const QString &dirName)
{ {
// Configuration Path // Configuration Path

View File

@ -7,6 +7,11 @@
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
#include <android/log.h> #include <android/log.h>
#endif #endif
Qv2rayConfigObject _qv2ray_global_config_impl_details::_GlobalConfig;
bool _qv2ray_global_config_impl_details::_isExiting;
QString _qv2ray_global_config_impl_details::_Qv2rayConfigPath;
namespace Qv2ray::base namespace Qv2ray::base
{ {
// Forwarded from QvTinyLog // Forwarded from QvTinyLog

View File

@ -338,22 +338,22 @@ namespace Qv2ray::components::proxy
} }
#else #else
for (auto service : macOSgetNetworkServices()) for (const auto &service : macOSgetNetworkServices())
{ {
LOG(MODULE_PROXY, "Setting proxy for interface: " + service) LOG(MODULE_PROXY, "Setting proxy for interface: " + service)
if (hasHTTP) if (hasHTTP)
{ {
QProcess::execute("/usr/sbin/networksetup -setwebproxystate " + service + " on"); QProcess::execute("/usr/sbin/networksetup", { "-setwebproxystate", service, "on" });
QProcess::execute("/usr/sbin/networksetup -setsecurewebproxystate " + service + " on"); QProcess::execute("/usr/sbin/networksetup", { "-setsecurewebproxystate", service, "on" });
QProcess::execute("/usr/sbin/networksetup -setwebproxy " + service + " " + address + " " + QSTRN(httpPort)); QProcess::execute("/usr/sbin/networksetup", { "-setwebproxy", service, address, QSTRN(httpPort) });
QProcess::execute("/usr/sbin/networksetup -setsecurewebproxy " + service + " " + address + " " + QSTRN(httpPort)); QProcess::execute("/usr/sbin/networksetup", { "-setsecurewebproxy", service, address, QSTRN(httpPort) });
} }
if (hasSOCKS) if (hasSOCKS)
{ {
QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxystate " + service + " on"); QProcess::execute("/usr/sbin/networksetup", { "-setsocksfirewallproxystate", service, "on" });
QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxy " + service + " " + address + " " + QSTRN(socksPort)); QProcess::execute("/usr/sbin/networksetup", { "-setsocksfirewallproxy", service, address, QSTRN(socksPort) });
} }
} }
@ -436,10 +436,10 @@ namespace Qv2ray::components::proxy
for (const auto &service : macOSgetNetworkServices()) for (const auto &service : macOSgetNetworkServices())
{ {
LOG(MODULE_PROXY, "Clearing proxy for interface: " + service) LOG(MODULE_PROXY, "Clearing proxy for interface: " + service)
QProcess::execute("/usr/sbin/networksetup", { "-setautoproxystate " + service + " off" }); QProcess::execute("/usr/sbin/networksetup", { "-setautoproxystate", service, "off" });
QProcess::execute("/usr/sbin/networksetup", { "-setwebproxystate " + service + " off" }); QProcess::execute("/usr/sbin/networksetup", { "-setwebproxystate", service, "off" });
QProcess::execute("/usr/sbin/networksetup", { "-setsecurewebproxystate " + service + " off" }); QProcess::execute("/usr/sbin/networksetup", { "-setsecurewebproxystate", service, "off" });
QProcess::execute("/usr/sbin/networksetup", { "-setsocksfirewallproxystate " + service + " off" }); QProcess::execute("/usr/sbin/networksetup", { "-setsocksfirewallproxystate", service, "off" });
} }
#endif #endif

View File

@ -16,7 +16,8 @@ void signalHandler(int signum)
if (signum == SIGSEGV) if (signum == SIGSEGV)
{ {
const auto msg = StackTraceHelper::GetStackTrace(); const auto msg = StackTraceHelper::GetStackTrace();
auto filePath = QV2RAY_CONFIG_DIR + "QvBugReport_" + QSTRN(system_clock::to_time_t(system_clock::now())) + ".stacktrace"; QDir().mkpath(QV2RAY_CONFIG_DIR + "/bugreport/");
auto filePath = QV2RAY_CONFIG_DIR + "/bugreport/QvBugReport_" + QSTRN(system_clock::to_time_t(system_clock::now())) + ".stacktrace";
StringToFile(msg, filePath); StringToFile(msg, filePath);
LOG(MODULE_INIT, "Backtrace saved in: " + filePath) LOG(MODULE_INIT, "Backtrace saved in: " + filePath)
LOG(MODULE_INIT, msg) LOG(MODULE_INIT, msg)