Bug 1235475 - Crash at the exception source when an exception is in native code; r=snorp

When we have a Java exception in native code, the Java stack in the
exception will not be very useful because the top frame is the native
entry point. In this case, the native stack is more useful. However,
currently we don't get a good native stack in this situation because we
go through Java when handling the exception, and the native stack we get
will have a lot of unknown frames inside libdvm or libart. This patch
makes us stay in native code when handling an uncaught exception from
native code, so that we get a good native stack.
This commit is contained in:
Jim Chen
2015-12-30 18:36:41 -05:00
parent c0487ab6ef
commit 1f403e6400
12 changed files with 69 additions and 36 deletions

View File

@@ -8,6 +8,10 @@
#include "AndroidBridge.h"
#include "GeneratedJNIWrappers.h"
#ifdef MOZ_CRASHREPORTER
#include "nsExceptionHandler.h"
#endif
namespace mozilla {
namespace jni {
@@ -129,23 +133,34 @@ bool ThrowException(JNIEnv *aEnv, const char *aClass,
return !aEnv->ThrowNew(cls.Get(), aMessage);
}
void HandleUncaughtException(JNIEnv *aEnv)
bool HandleUncaughtException(JNIEnv* aEnv)
{
MOZ_ASSERT(aEnv, "Invalid thread JNI env");
if (!aEnv->ExceptionCheck()) {
return;
return false;
}
#ifdef DEBUG
aEnv->ExceptionDescribe();
#endif
Throwable::LocalRef e =
Throwable::LocalRef::Adopt(aEnv->ExceptionOccurred());
MOZ_ASSERT(e);
aEnv->ExceptionClear();
widget::GeckoAppShell::HandleUncaughtException(nullptr, e);
String::LocalRef stack = widget::GeckoAppShell::HandleUncaughtException(e);
// Should be dead by now...
MOZ_CRASH("Failed to handle uncaught exception");
#ifdef MOZ_CRASHREPORTER
if (stack) {
// GeckoAppShell wants us to annotate and trigger the crash reporter.
CrashReporter::AnnotateCrashReport(
NS_LITERAL_CSTRING("AuxiliaryJavaStack"), nsCString(stack));
}
#endif // MOZ_CRASHREPORTER
return true;
}
namespace {