-
-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathnative-sample.cpp
More file actions
50 lines (41 loc) · 1.29 KB
/
native-sample.cpp
File metadata and controls
50 lines (41 loc) · 1.29 KB
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
#include <jni.h>
#include <android/log.h>
#include <sentry.h>
#include <signal.h>
#define TAG "sentry-sample"
extern "C" {
JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_crash(JNIEnv *env, jclass cls) {
__android_log_print(ANDROID_LOG_WARN, TAG, "About to crash.");
raise(SIGSEGV);
}
JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_message(JNIEnv *env, jclass cls) {
__android_log_print(ANDROID_LOG_WARN, TAG, "Sending message.");
sentry_value_t event = sentry_value_new_message_event(
/* level */ SENTRY_LEVEL_INFO,
/* logger */ "custom",
/* message */ "It works!"
);
sentry_capture_event(event);
}
[[gnu::noinline]]
static void idle_pointlessly() {
static const volatile int x = 42;
(void)x;
}
[[gnu::noinline]]
static void loop_eternally() {
while (true) {
idle_pointlessly();
}
}
[[gnu::noinline]]
static void keep_object_locked(JNIEnv* env, jobject obj) {
env->MonitorEnter(obj);
loop_eternally();
env->MonitorExit(obj);
}
JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_freezeMysteriously(JNIEnv *env, jclass cls, jobject obj) {
__android_log_print(ANDROID_LOG_WARN, TAG, "About to lock object eternally.");
keep_object_locked(env, obj);
}
}