forked from yinyinnie/breakpad-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnative_breakpad.cpp
43 lines (37 loc) · 1.65 KB
/
native_breakpad.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
#include "include/cn_onlinecache_breakpad_NativeBreakpad_JNI.h"
#include "base/common.h"
#include "third_party/breakpad/src/client/linux/handler/exception_handler.h"
#include "third_party/breakpad/src/client/linux/handler/minidump_descriptor.h"
JavaVM* g_jvm;
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
g_jvm = vm;
JNIEnv *env;
if (JNI_OK != vm->GetEnv(reinterpret_cast<void**> (&env),JNI_VERSION_1_4)) {
LOGE("JNI_OnLoad ====> could not get JNI env");
return JNI_ERR;
}
return JNI_VERSION_1_4;
}
bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
void* context,
bool succeeded){
LOGE("DumpCallback ===> succeeded %d", succeeded);
return succeeded;
}
JNIEXPORT jint JNICALL Java_cn_onlinecache_breakpad_NativeBreakpad_nativeInit(JNIEnv* env,
jobject obj,
jstring crash_dump_path){
const char* path = (char *)env->GetStringUTFChars(crash_dump_path, NULL);
google_breakpad::MinidumpDescriptor descriptor(path);
static google_breakpad::ExceptionHandler eh(descriptor, NULL, DumpCallback, NULL, true, -1);
env->ReleaseStringUTFChars(crash_dump_path, path);
LOGD("nativeInit ===> breakpad initialized succeeded, dump file will be saved at %s", path);
return 0;
}
JNIEXPORT jint JNICALL Java_cn_onlinecache_breakpad_NativeBreakpad_nativeTestCrash
(JNIEnv* env, jobject obj) {
LOGE("native crash capture begin");
char *ptr = NULL; *ptr = 1;
LOGE("native crash capture end");
return 0;
}