| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/android/java_exception_reporter.h" | 5 #include "base/android/java_exception_reporter.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/debug/dump_without_crashing.h" | 10 #include "base/debug/dump_without_crashing.h" |
| 11 #include "jni/JavaExceptionReporter_jni.h" | 11 #include "jni/JavaExceptionReporter_jni.h" |
| 12 | 12 |
| 13 using base::android::JavaParamRef; | 13 using base::android::JavaParamRef; |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 namespace android { | 16 namespace android { |
| 17 | 17 |
| 18 void InitJavaExceptionReporter() { | 18 void InitJavaExceptionReporter() { |
| 19 JNIEnv* env = base::android::AttachCurrentThread(); | 19 JNIEnv* env = base::android::AttachCurrentThread(); |
| 20 Java_JavaExceptionReporter_installHandler(env); | 20 constexpr bool crash_after_report = false; |
| 21 Java_JavaExceptionReporter_installHandler(env, crash_after_report); |
| 22 } |
| 23 |
| 24 void InitJavaExceptionReporterForChildProcess() { |
| 25 JNIEnv* env = base::android::AttachCurrentThread(); |
| 26 constexpr bool crash_after_report = true; |
| 27 Java_JavaExceptionReporter_installHandler(env, crash_after_report); |
| 21 } | 28 } |
| 22 | 29 |
| 23 void ReportJavaException(JNIEnv* env, | 30 void ReportJavaException(JNIEnv* env, |
| 24 const JavaParamRef<jclass>& jcaller, | 31 const JavaParamRef<jclass>& jcaller, |
| 32 jboolean crash_after_report, |
| 25 const JavaParamRef<jthrowable>& e) { | 33 const JavaParamRef<jthrowable>& e) { |
| 34 std::string exception_info = base::android::GetJavaExceptionInfo(env, e); |
| 26 // Set the exception_string in BuildInfo so that breakpad can read it. | 35 // Set the exception_string in BuildInfo so that breakpad can read it. |
| 27 base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo( | 36 base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo(exception_info); |
| 28 base::android::GetJavaExceptionInfo(env, e)); | 37 if (crash_after_report) { |
| 38 LOG(ERROR) << exception_info; |
| 39 LOG(FATAL) << "Uncaught exception"; |
| 40 } |
| 29 base::debug::DumpWithoutCrashing(); | 41 base::debug::DumpWithoutCrashing(); |
| 30 base::android::BuildInfo::GetInstance()->ClearJavaExceptionInfo(); | 42 base::android::BuildInfo::GetInstance()->ClearJavaExceptionInfo(); |
| 31 } | 43 } |
| 32 | 44 |
| 33 void ReportJavaStackTrace(JNIEnv* env, | 45 void ReportJavaStackTrace(JNIEnv* env, |
| 34 const JavaParamRef<jclass>& jcaller, | 46 const JavaParamRef<jclass>& jcaller, |
| 35 const JavaParamRef<jstring>& stackTrace) { | 47 const JavaParamRef<jstring>& stackTrace) { |
| 36 base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo( | 48 base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo( |
| 37 ConvertJavaStringToUTF8(stackTrace)); | 49 ConvertJavaStringToUTF8(stackTrace)); |
| 38 base::debug::DumpWithoutCrashing(); | 50 base::debug::DumpWithoutCrashing(); |
| 39 base::android::BuildInfo::GetInstance()->ClearJavaExceptionInfo(); | 51 base::android::BuildInfo::GetInstance()->ClearJavaExceptionInfo(); |
| 40 } | 52 } |
| 41 | 53 |
| 42 bool RegisterJavaExceptionReporterJni(JNIEnv* env) { | 54 bool RegisterJavaExceptionReporterJni(JNIEnv* env) { |
| 43 return RegisterNativesImpl(env); | 55 return RegisterNativesImpl(env); |
| 44 } | 56 } |
| 45 | 57 |
| 46 } // namespace android | 58 } // namespace android |
| 47 } // namespace base | 59 } // namespace base |
| OLD | NEW |