diff --git a/daemon/c_bpwrapper.cpp b/daemon/c_bpwrapper.cpp new file mode 100644 index 00000000..57e4a7ab --- /dev/null +++ b/daemon/c_bpwrapper.cpp @@ -0,0 +1,101 @@ +#ifdef ENABLE_BREAKPAD + +#if defined(WIN32) +#include +#endif +#include +#include + +#include "c_bpwrapper.h" + +wchar_t *utf8ToWString(const std::string &src) +{ + wchar_t dst[4096]; + int len; + + len = MultiByteToWideChar + (CP_UTF8, /* multibyte code page */ + 0, /* flags */ + src.c_str(), /* src */ + -1, /* src len, -1 for all includes \0 */ + dst, /* dst */ + sizeof(dst) / sizeof(wchar_t)); /* dst buf len */ + + if (len <= 0) { + return NULL; + } + + return _wcsdup(dst); +} + +std::string wStringToUtf8(const wchar_t *src) +{ + char dst[4096]; + int len; + + len = WideCharToMultiByte + (CP_UTF8, /* multibyte code page */ + 0, /* flags */ + src, /* src */ + -1, /* src len, -1 for all includes \0 */ + dst, /* dst */ + sizeof(dst), /* dst buf len */ + NULL, /* default char */ + NULL); /* BOOL flag indicates default char is used */ + + if (len <= 0) { + return ""; + } + + return dst; +} + +std::string wStringToLocale(const wchar_t *src) +{ + char dst[4096]; + int len; + + len = WideCharToMultiByte + (CP_ACP, /* multibyte code page */ + 0, /* flags */ + src, /* src */ + -1, /* src len, -1 for all includes \0 */ + dst, /* dst */ + sizeof(dst), /* dst buf len */ + NULL, /* default char */ + NULL); /* BOOL flag indicates default char is used */ + + if (len <= 0) { + return ""; + } + + return dst; +} + +bool DumpCallback(const wchar_t *dump_path, + const wchar_t *minidump_id, + void *context, + EXCEPTION_POINTERS *exinfo, + MDRawAssertionInfo *assertion, + bool succeeded) +{ + printf("program dump %s\n", succeeded ? "succeeded" : "failed"); + printf("program crashed, you can find the minidump in %s\n", wStringToLocale(dump_path).c_str()); + printf("minidump id: %s\n", wStringToLocale(minidump_id).c_str()); + return succeeded; +} + + +extern "C" { + CBPWrapperExceptionHandler newCBPWrapperExceptionHandler(const char *dump_dir) + { + printf("initializing crash reporter\n"); + std::wstring path = utf8ToWString(dump_dir); + return reinterpret_cast(new google_breakpad::ExceptionHandler( + path, NULL, + (google_breakpad::ExceptionHandler::MinidumpCallback)DumpCallback, NULL, + google_breakpad::ExceptionHandler::HANDLER_ALL)); + } +} + +#endif \ No newline at end of file diff --git a/daemon/c_bpwrapper.h b/daemon/c_bpwrapper.h new file mode 100644 index 00000000..124c899e --- /dev/null +++ b/daemon/c_bpwrapper.h @@ -0,0 +1,12 @@ +#pragma once + +typedef void *CBPWrapperExceptionHandler; +#ifdef __cplusplus +extern "C" +{ +#endif + CBPWrapperExceptionHandler newCBPWrapperExceptionHandler(const char *dump_dir); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/daemon/seaf-daemon.c b/daemon/seaf-daemon.c index e94ba413..c65705a4 100644 --- a/daemon/seaf-daemon.c +++ b/daemon/seaf-daemon.c @@ -26,6 +26,10 @@ #include #endif // HAVE_BREAKPAD_SUPPORT +#ifdef ENABLE_BREAKPAD +#include "c_bpwrapper.h" +#endif // ENABLE_BREAKPAD + #include #include @@ -363,7 +367,7 @@ get_argv_utf8 (int *argc) int main (int argc, char **argv) { -#ifdef HAVE_BREAKPAD_SUPPORT +#if defined(HAVE_BREAKPAD_SUPPORT) || defined(ENABLE_BREAKPAD) #ifdef WIN32 #define DUMPS_DIR "~/ccnet/logs/dumps/" #else diff --git a/seafile.vcxproj b/seafile.vcxproj index c40ddd86..04f19adb 100644 --- a/seafile.vcxproj +++ b/seafile.vcxproj @@ -158,10 +158,10 @@ false - WIN32;PACKAGE_VERSION="8.0.0";WIN32_LEAN_AND_MEAN;UNICODE;SEAFILE_CLIENT;%(PreprocessorDefinitions) + WIN32;PACKAGE_VERSION="8.0.0";WIN32_LEAN_AND_MEAN;UNICODE;SEAFILE_CLIENT;ENABLE_BREAKPAD;%(PreprocessorDefinitions) false stdcpp17 - $(ProjectDir)..\libsearpc\lib;$(ProjectDir);$(ProjectDir)common;$(ProjectDir)lib;$(ProjectDir)include;$(ProjectDir)daemon;%(AdditionalIncludeDirectories) + $(ProjectDir)..\libsearpc\lib;$(ProjectDir);$(ProjectDir)common;$(ProjectDir)lib;$(ProjectDir)include;$(ProjectDir)daemon;$(ProjectDir)..\breakpad\src;%(AdditionalIncludeDirectories) /utf-8 %(AdditionalOptions) MultiThreadedDLL @@ -172,8 +172,8 @@ true - $(ProjectDir)..\libsearpc\$(IntDir);%(AdditionalLibraryDirectories) - ws2_32.lib;Psapi.lib;Rpcrt4.lib;Crypt32.lib;libsearpc.lib;%(AdditionalDependencies) + $(ProjectDir)..\libsearpc\$(IntDir);$(ProjectDir)..\breakpad\src\client\windows\Release\lib\;%(AdditionalLibraryDirectories) + ws2_32.lib;Psapi.lib;Rpcrt4.lib;Crypt32.lib;libsearpc.lib;common.lib;crash_generation_client.lib;exception_handler.lib;%(AdditionalDependencies) false @@ -200,6 +200,7 @@ + @@ -245,6 +246,7 @@ + @@ -273,4 +275,4 @@ - + \ No newline at end of file