-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbackend.cpp
113 lines (100 loc) · 3.42 KB
/
backend.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "backend.h"
#include "client-side-unwinding.h"
#include <android/log.h>
#include <atomic>
#include <mutex>
#ifdef CRASHPAD_BACKEND
#include "crashpad-backend.h"
#elif BREAKPAD_BACKEND
#include "breakpad-backend.h"
#endif
extern std::atomic_bool initialized;
extern "C" {
bool Initialize(jstring url,
jstring database_path,
jstring handler_path,
jobjectArray attributeKeys,
jobjectArray attributeValues,
jobjectArray attachmentPaths,
jboolean enableClientSideUnwinding,
jint unwindingMode) {
static std::once_flag initialize_flag;
std::call_once(initialize_flag, [&] {
#ifdef CRASHPAD_BACKEND
initialized = InitializeCrashpad(url,
database_path, handler_path,
attributeKeys, attributeValues,
attachmentPaths, enableClientSideUnwinding,
unwindingMode);
#elif BREAKPAD_BACKEND
initialized = InitializeBreakpad(url,
database_path, handler_path,
attributeKeys, attributeValues,
attachmentPaths, enableClientSideUnwinding,
unwindingMode);
#else
initialized = false;
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android",
"No native crash reporting backend defined");
#endif
});
#ifdef CRASHPAD_BACKEND
if (initialized) {
ReEnableCrashpad();
}
#endif
return initialized;
}
void DumpWithoutCrash(jstring message, jboolean set_main_thread_as_faulting_thread) {
#ifdef CRASHPAD_BACKEND
DumpWithoutCrashCrashpad(message, set_main_thread_as_faulting_thread);
#elif BREAKPAD_BACKEND
DumpWithoutCrashBreakpad(message, set_main_thread_as_faulting_thread);
#else
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android",
"DumpWithoutCrash not supported on this backend");
#endif
}
void AddAttribute(jstring key, jstring value) {
#ifdef CRASHPAD_BACKEND
AddAttributeCrashpad(key, value);
#elif BREAKPAD_BACKEND
AddAttributeBreakpad(key, value);
#else
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android",
"AddAttribute not supported on this backend");
#endif
}
void Disable() {
#ifdef CRASHPAD_BACKEND
DisableCrashpad();
#else
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android",
"Disable not supported on this backend");
#endif
}
bool EnableCrashLoopDetection() {
#ifdef CRASHPAD_BACKEND
return EnableCrashLoopDetectionCrashpad();
#elif BREAKPAD_BACKEND
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android", "EnableCrashLoopDetection not supported on this backend");
return false;
#endif
}
bool IsSafeModeRequired() {
#ifdef CRASHPAD_BACKEND
return IsSafeModeRequiredCrashpad();
#elif BREAKPAD_BACKEND
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android", "IsSafeModeRequired not supported on this backend");
return false;
#endif
}
int ConsecutiveCrashesCount() {
#ifdef CRASHPAD_BACKEND
return ConsecutiveCrashesCountCrashpad();
#elif BREAKPAD_BACKEND
__android_log_print(ANDROID_LOG_ERROR, "Backtrace-Android", "ConsecutiveCrashesCount not supported on this backend");
return 0;
#endif
}
}