fix win pack lost dlls bug (#53)

* feature add sentry for soft catch dmp

* feature add cli upload pdb to sentry server

* feature add flag for control sentry to use

* fix  flag not effect on src/makefile

* feature unzip for dmp file to upload sentry server

* feature remove test code

* feature add api for function report log to server

* feature update the soft version

* feature merge mac sentry to win platform.

* fix mac build error bug

* feature add sentry config for mac cmake

* fix packed the soft and not copy dlls question

* fix windows not copy library bug

* feature remove test code
This commit is contained in:
Alves
2025-12-09 10:24:15 +08:00
committed by GitHub
parent ccae13b98b
commit f32aa81f6a
7 changed files with 192 additions and 52 deletions

View File

@@ -117,7 +117,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/osx/Info.plist.in
if (WIN32)
add_library(Snapmaker_Orca SHARED Snapmaker_Orca.cpp Snapmaker_Orca.hpp dev-utils/BaseException.cpp dev-utils/BaseException.h dev-utils/StackWalker.cpp dev-utils/StackWalker.h sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp)
else ()
add_executable(Snapmaker_Orca Snapmaker_Orca.cpp Snapmaker_Orca.hpp)
add_executable(Snapmaker_Orca Snapmaker_Orca.cpp Snapmaker_Orca.hpp sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp)
endif ()
if (MINGW)
@@ -222,20 +222,33 @@ if (WIN32)
)
endforeach ()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
Snapmaker_Orca_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
Snapmaker_Orca_copy_dlls(COPY_DLLS "RelWithDebInfo" "" output_dlls_Release)
else()
Snapmaker_Orca_copy_dlls(COPY_DLLS "Release" "" output_dlls_Release)
endif()
# For multi-config generators (Visual Studio), copy DLLs for all configurations
foreach (CONF ${CMAKE_CONFIGURATION_TYPES})
if ("${CONF}" STREQUAL "Debug")
Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "d" output_dlls_Debug)
elseif ("${CONF}" STREQUAL "Release")
Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "" output_dlls_Release)
elseif ("${CONF}" STREQUAL "RelWithDebInfo")
Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "" output_dlls_RelWithDebInfo)
else()
# MinSizeRel or other configs
Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "" _unused_dlls)
endif()
endforeach ()
else ()
# Single-config generators (Ninja, Makefiles)
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources" WIN_RESOURCES_SYMLINK)
add_custom_command(TARGET Snapmaker_Orca POST_BUILD
COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" "(" mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ")"
COMMENT "Symlinking the resources directory into the build tree"
VERBATIM
)
# Copy DLLs for single-config generators
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
Snapmaker_Orca_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug)
else()
Snapmaker_Orca_copy_dlls(COPY_DLLS "${CMAKE_BUILD_TYPE}" "" output_dlls_Release)
endif()
endif ()
@@ -246,6 +259,20 @@ else ()
COMMAND ln -sf Snapmaker_Orca snapmaker-orca
WORKING_DIRECTORY "$<TARGET_FILE_DIR:Snapmaker_Orca>"
VERBATIM)
# Copy Sentry crashpad_handler to executable directory for non-bundle builds (e.g., Xcode debugging)
if (SLIC3R_SENTRY)
add_custom_command(TARGET Snapmaker_Orca POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/crashpad_handler" "$<TARGET_FILE_DIR:Snapmaker_Orca>/crashpad_handler"
COMMAND sh -c "codesign --force --sign - '$<TARGET_FILE_DIR:Snapmaker_Orca>/crashpad_handler' 2>/dev/null || true"
COMMENT "Copying crashpad_handler for Sentry crash reporting"
VERBATIM)
# Copy libsentry.dylib to executable directory for non-bundle builds
add_custom_command(TARGET Snapmaker_Orca POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/lib/libsentry.dylib" "$<TARGET_FILE_DIR:Snapmaker_Orca>/libsentry.dylib"
COMMAND sh -c "codesign --force --sign - '$<TARGET_FILE_DIR:Snapmaker_Orca>/libsentry.dylib' 2>/dev/null || true"
COMMENT "Copying libsentry.dylib for Sentry crash reporting"
VERBATIM)
endif()
else ()
add_custom_command(TARGET Snapmaker_Orca POST_BUILD
WORKING_DIRECTORY "$<TARGET_FILE_DIR:Snapmaker_Orca>"
@@ -278,6 +305,26 @@ else ()
COMMAND ${CMAKE_COMMAND} -E create_symlink "${SLIC3R_RESOURCES_DIR}" "$<TARGET_FILE_DIR:Snapmaker_Orca>/../Resources"
COMMENT "Symlinking the resources directory into the build tree"
VERBATIM)
# Copy Sentry crashpad_handler to MacOS directory (same directory as executable)
if (SLIC3R_SENTRY)
add_custom_command(TARGET Snapmaker_Orca POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/crashpad_handler" "$<TARGET_FILE_DIR:Snapmaker_Orca>/crashpad_handler"
COMMAND sh -c "codesign --force --sign - '$<TARGET_FILE_DIR:Snapmaker_Orca>/crashpad_handler' 2>/dev/null || true"
COMMENT "Copying and signing crashpad_handler for Sentry crash reporting"
VERBATIM)
# Copy libsentry.dylib to Frameworks directory
add_custom_command(TARGET Snapmaker_Orca POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:Snapmaker_Orca>/../Frameworks"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/lib/libsentry.dylib" "$<TARGET_FILE_DIR:Snapmaker_Orca>/../Frameworks/libsentry.dylib"
COMMAND sh -c "codesign --force --sign - '$<TARGET_FILE_DIR:Snapmaker_Orca>/../Frameworks/libsentry.dylib' 2>/dev/null || true"
COMMENT "Copying and signing libsentry.dylib for Sentry crash reporting"
VERBATIM)
# Update the rpath for libsentry.dylib
add_custom_command(TARGET Snapmaker_Orca POST_BUILD
COMMAND install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "$<TARGET_FILE:Snapmaker_Orca>" || true
COMMENT "Updating rpath for libsentry.dylib"
VERBATIM)
endif()
endif()
endif ()

View File

@@ -33,6 +33,10 @@
using namespace nlohmann;
#endif
#include "sentry_wrapper/SentryWrapper.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/nowide/args.hpp>
@@ -6291,6 +6295,12 @@ extern "C" {
#else /* _MSC_VER */
int main(int argc, char **argv)
{
return CLI().run(argc, argv);
initSentry();
auto res = CLI().run(argc, argv);
exitSentry();
return res;
}
#endif /* _MSC_VER */

View File

@@ -10,14 +10,19 @@
#ifdef SLIC3R_SENTRY
#include "sentry.h"
#endif
#ifdef _WIN32
#include <Windows.h>
#include <shlobj.h>
#endif
#ifdef __APPLE__
#include <unistd.h>
#include <mach-o/dyld.h>
#endif
#include <cstdlib>
#include <atomic>
namespace Slic3r {
@@ -36,41 +41,60 @@ static sentry_value_t on_crash_callback(const sentry_ucontext_t* uctx, sentry_va
void initSentryEx()
{
sentry_options_t* options = sentry_options_new();
std::string dsn = "";
{
#ifdef WIN32
#ifdef __APPLE__
std::string dsn = std::string("https://ac473187efb8877f36bd31694ffd5dec@o4508125599563776.ingest.us.sentry.io/4510425212059648");
#elif _WIN32
std::string dsn = std::string("https://c74b617c2aedc291444d3a238d23e780@o4508125599563776.ingest.us.sentry.io/4510425163956224");
#endif
sentry_options_set_dsn(options, dsn.c_str());
std::string handlerDir = "";
std::string dataBaseDir = "";
#ifdef __APPLE__
char exe_path[PATH_MAX] = {0};
uint32_t buf_size = PATH_MAX;
if (_NSGetExecutablePath(exe_path, &buf_size) != 0) {
throw std::runtime_error("Buffer too small for executable path");
}
// Get the directory containing the executable, not the executable path itself
boost::filesystem::path exe_dir = boost::filesystem::path(exe_path).parent_path();
handlerDir = (exe_dir / "crashpad_handler").string();
const char* home_env = getenv("HOME");
dataBaseDir = home_env;
dataBaseDir = dataBaseDir + "/Library/Application Support/Snapmaker_Orca/SentryData";
#elif _WIN32
wchar_t exeDir[MAX_PATH];
::GetModuleFileNameW(nullptr, exeDir, MAX_PATH);
std::wstring wsExeDir(exeDir);
int nPos = wsExeDir.find_last_of('\\');
std::wstring wsDmpDir = wsExeDir.substr(0, nPos + 1);
std::wstring handlerDir = wsDmpDir + L"crashpad_handler.exe";
std::wstring desDir = wsDmpDir + L"crashpad_handler.exe";
wsDmpDir += L"dump";
auto wstringTostring = [](std::wstring wTmpStr) -> std::string {
std::string resStr = std::string();
int len = WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, nullptr, 0, nullptr, nullptr);
if (len <= 0)
return std::string();
std::string desStr(len, 0);
WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, &desStr[0], len, nullptr, nullptr);
resStr = desStr;
return resStr;
};
std::string desDir = wstringTostring(handlerDir);
if (!desDir.empty())
sentry_options_set_handler_path(options, desDir.c_str());
desDir = wstringTostring(wsDmpDir);
desDir = wstringTostring(wsDmpDir);
handlerDir = wstringTostring(desDir);
wchar_t appDataPath[MAX_PATH] = {0};
auto hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
char* path = new char[MAX_PATH];
@@ -78,13 +102,16 @@ void initSentryEx()
wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH);
std::string filePath = path;
std::string appName = "\\" + std::string("Snapmaker_Orca\\");
filePath = filePath + appName;
if (!filePath.empty())
sentry_options_set_database_path(options, filePath.c_str());
dataBaseDir = filePath + appName;
#endif
if (!handlerDir.empty())
sentry_options_set_handler_path(options, handlerDir.c_str());
if (!dataBaseDir.empty())
sentry_options_set_database_path(options, dataBaseDir.c_str());
std::string softVersion = "snapmaker_orca_2.2.0_beta2";
// Snapmaker_VERSION
sentry_options_set_release(options, softVersion.c_str());
#if defined(_DEBUG) || !defined(NDEBUG)
@@ -92,17 +119,16 @@ void initSentryEx()
#else
sentry_options_set_debug(options, 0);
#endif
// release version environment(Testing/production/development/Staging)
sentry_options_set_environment(options, "develop");
sentry_options_set_auto_session_tracking(options, false);
sentry_options_set_symbolize_stacktraces(options, true);
sentry_options_set_auto_session_tracking(options, 0);
sentry_options_set_symbolize_stacktraces(options, 1);
sentry_options_set_on_crash(options, on_crash_callback, NULL);
// Enable before_send hook for filtering sensitive data
sentry_options_set_before_send(options, NULL, NULL);
// Ensure all events and crashes are captured (sample rate 100%)
sentry_options_set_sample_rate(options, 1.0); // Capture 100% of events
sentry_options_set_traces_sample_rate(options, 1.0); // Capture 100% of traces
sentry_options_set_sample_rate(options, 1.0);
sentry_options_set_traces_sample_rate(options, 1.0);
sentry_init(options);
sentry_start_session();

View File

@@ -19,7 +19,7 @@ namespace Slic3r {
};
void sentryReportLog(SENTRY_LOG_LEVEL logLevel,
const std::string& logContent,
const std::string& logContent,
const std::string& funcModule = "",
const std::string& logTagKey = "",
const std::string& logTagValue = "",