From 001d5b8c65b2d46cc9aeac13425cf376a4034787 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 16 Jul 2026 15:47:19 +0200 Subject: [PATCH] feat(samples): Make Native Crash button fault inside app native code The Native Crash button called raise(SIGSEGV), which faults inside libc and, for a JNI-originated crash, does not exercise symbolication of the app's own native code. Point it at a null-deref inside a named function (trigger_null_deref) instead, so the crashing frame resolves to a real symbol + source line and native symbolication can be verified from the sample. Ref JAVA-645 Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01EmE8hdaj9H9K61opK2PZ6U --- .../src/main/cpp/native-sample.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp b/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp index abac2bf58f..6b9e6e89d8 100644 --- a/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp +++ b/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp @@ -1,15 +1,23 @@ #include #include #include -#include #define TAG "sentry-sample" extern "C" { +// Faults inside this named function so the crashing frame resolves to a real +// symbol + source line. A bare raise(SIGSEGV) would instead fault in libc and, +// for a JNI-originated crash, not exercise app-native symbolication. +[[gnu::noinline]] +static void trigger_null_deref() { + volatile int *ptr = nullptr; + *ptr = 42; +} + 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); + trigger_null_deref(); } JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_message(JNIEnv *env, jclass cls) {