mirror of
https://github.com/haiwen/seafile.git
synced 2025-01-07 03:17:13 +08:00
Support breakpad for windows (#2401)
This commit is contained in:
parent
1e34e85f28
commit
f0097a706b
101
daemon/c_bpwrapper.cpp
Normal file
101
daemon/c_bpwrapper.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#ifdef ENABLE_BREAKPAD
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <client/windows/handler/exception_handler.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#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<void *>(new google_breakpad::ExceptionHandler(
|
||||
path, NULL,
|
||||
(google_breakpad::ExceptionHandler::MinidumpCallback)DumpCallback, NULL,
|
||||
google_breakpad::ExceptionHandler::HANDLER_ALL));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
12
daemon/c_bpwrapper.h
Normal file
12
daemon/c_bpwrapper.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
typedef void *CBPWrapperExceptionHandler;
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
CBPWrapperExceptionHandler newCBPWrapperExceptionHandler(const char *dump_dir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -26,6 +26,10 @@
|
||||
#include <c_bpwrapper.h>
|
||||
#endif // HAVE_BREAKPAD_SUPPORT
|
||||
|
||||
#ifdef ENABLE_BREAKPAD
|
||||
#include "c_bpwrapper.h"
|
||||
#endif // ENABLE_BREAKPAD
|
||||
|
||||
#include <searpc.h>
|
||||
#include <searpc-named-pipe-transport.h>
|
||||
|
||||
@ -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
|
||||
|
@ -158,10 +158,10 @@
|
||||
<IntrinsicFunctions>false</IntrinsicFunctions>
|
||||
<SDLCheck>
|
||||
</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;PACKAGE_VERSION="8.0.0";WIN32_LEAN_AND_MEAN;UNICODE;SEAFILE_CLIENT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;PACKAGE_VERSION="8.0.0";WIN32_LEAN_AND_MEAN;UNICODE;SEAFILE_CLIENT;ENABLE_BREAKPAD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>false</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\libsearpc\lib;$(ProjectDir);$(ProjectDir)common;$(ProjectDir)lib;$(ProjectDir)include;$(ProjectDir)daemon;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\libsearpc\lib;$(ProjectDir);$(ProjectDir)common;$(ProjectDir)lib;$(ProjectDir)include;$(ProjectDir)daemon;$(ProjectDir)..\breakpad\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
@ -172,8 +172,8 @@
|
||||
<OptimizeReferences>
|
||||
</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(ProjectDir)..\libsearpc\$(IntDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>ws2_32.lib;Psapi.lib;Rpcrt4.lib;Crypt32.lib;libsearpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(ProjectDir)..\libsearpc\$(IntDir);$(ProjectDir)..\breakpad\src\client\windows\Release\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>ws2_32.lib;Psapi.lib;Rpcrt4.lib;Crypt32.lib;libsearpc.lib;common.lib;crash_generation_client.lib;exception_handler.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<PerUserRedirection>false</PerUserRedirection>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
@ -200,6 +200,7 @@
|
||||
<ClCompile Include="daemon\cevent.c" />
|
||||
<ClCompile Include="daemon\change-set.c" />
|
||||
<ClCompile Include="daemon\clone-mgr.c" />
|
||||
<ClCompile Include="daemon\c_bpwrapper.cpp" />
|
||||
<ClCompile Include="daemon\filelock-mgr.c" />
|
||||
<ClCompile Include="daemon\http-tx-mgr.c" />
|
||||
<ClCompile Include="daemon\job-mgr.c" />
|
||||
@ -245,6 +246,7 @@
|
||||
<ClInclude Include="daemon\cevent.h" />
|
||||
<ClInclude Include="daemon\change-set.h" />
|
||||
<ClInclude Include="daemon\clone-mgr.h" />
|
||||
<ClInclude Include="daemon\c_bpwrapper.h" />
|
||||
<ClInclude Include="daemon\filelock-mgr.h" />
|
||||
<ClInclude Include="daemon\http-tx-mgr.h" />
|
||||
<ClInclude Include="daemon\job-mgr.h" />
|
||||
@ -273,4 +275,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user