1
+ #include " breakpad.hpp"
2
+
3
+ #ifdef _WIN32
4
+ #include < client/windows/handler/exception_handler.h>
5
+ #elif __APPLE__
6
+ #include < client/mac/handler/exception_handler.h>
7
+ #elif __linux__
8
+ #include < client/linux/handler/exception_handler.h>
9
+ #endif
10
+
11
+ #include < codecvt>
12
+ #include < iostream>
13
+ #include < locale>
14
+
15
+ #ifdef _WIN32
16
+ bool callback (const wchar_t *dump_path,
17
+ const wchar_t *id,
18
+ void *context,
19
+ EXCEPTION_POINTERS *exinfo,
20
+ MDRawAssertionInfo *assertion,
21
+ bool succeeded)
22
+ {
23
+ auto succeeded_str = succeeded ? " succeeded" : " fialed" ;
24
+ auto convert_str = [](const wchar_t *wstr) {
25
+ std::wstring_convert<std::codecvt_utf8<wchar_t >> converter;
26
+ return converter.to_bytes (wstr);
27
+ };
28
+ auto dump_path_str = convert_str (dump_path) + convert_str (id);
29
+ std::cout << " Create dump file " << succeeded_str << " Dump path: " << dump_path_str
30
+ << std::endl;
31
+ return succeeded;
32
+ }
33
+ #elif __APPLE__
34
+ bool callback (const char *dump_path, const char *id, void *context, bool succeeded)
35
+ {
36
+ auto succeeded_str = succeeded ? " succeeded" : " fialed" ;
37
+ std::cout << " Create dump file " << succeeded_str << " Dump path: " << dump_path << std::endl;
38
+ return succeeded;
39
+ }
40
+ #elif __linux__
41
+ bool callback (const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded)
42
+ {
43
+ auto succeeded_str = succeeded ? " succeeded" : " fialed" ;
44
+ std::cout << " Create dump file " << succeeded_str << " Dump path: " << descriptor.path ()
45
+ << std::endl;
46
+ return succeeded;
47
+ }
48
+ #endif
49
+
50
+ Breakpad::Breakpad (const std::string &dump_path)
51
+ {
52
+ #ifdef _WIN32
53
+ auto dump_path_w = std::wstring (dump_path.begin (), dump_path.end ());
54
+ handler_ptr = std::make_unique<google_breakpad::ExceptionHandler>(
55
+ dump_path_w, nullptr , callback, nullptr , google_breakpad::ExceptionHandler::HANDLER_ALL);
56
+ #elif __APPLE__
57
+ handler_ptr = std::make_unique<google_breakpad::ExceptionHandler>(dump_path,
58
+ nullptr ,
59
+ callback,
60
+ nullptr ,
61
+ true ,
62
+ nullptr );
63
+ #elif __linux__
64
+ handler_ptr = std::make_unique<google_breakpad::ExceptionHandler>(
65
+ google_breakpad::MinidumpDescriptor (dump_path), nullptr , callback, nullptr , true , -1 );
66
+ #endif
67
+ }
68
+
69
+ Breakpad::~Breakpad () {}
0 commit comments