Make exception logging a little prettier.
Convert the class descriptor to dotted form when logging an exception
from the VM (e.g. when CheckJNI gets upset). Instead of
Ljava/lang/Throwable;: yikes
at android.test.JNITest.part1a(Native Method)
we now show:
java.lang.Throwable: yikes
at android.test.JNITest.part1a(Native Method)
Change-Id: I8b65920b85f03a1871e6a417b43b269b448340d5
diff --git a/vm/Exception.c b/vm/Exception.c
index 3a73420..0aeeae5 100644
--- a/vm/Exception.c
+++ b/vm/Exception.c
@@ -1252,21 +1252,30 @@
StringObject* messageStr;
int stackSize;
const int* intVals;
+ char* className;
+ className = dvmDescriptorToDot(exception->clazz->descriptor);
messageStr = (StringObject*) dvmGetFieldObject(exception,
gDvm.offJavaLangThrowable_message);
if (messageStr != NULL) {
char* cp = dvmCreateCstrFromString(messageStr);
- LOGI("%s: %s\n", exception->clazz->descriptor, cp);
+ LOGI("%s: %s\n", className, cp);
free(cp);
} else {
- LOGI("%s:\n", exception->clazz->descriptor);
+ LOGI("%s:\n", className);
}
+ free(className);
+ /*
+ * This relies on the stackState field, which contains the "raw"
+ * form of the stack. The Throwable class may clear this field
+ * after it generates the "cooked" form, in which case we'll have
+ * nothing to show.
+ */
stackData = (const ArrayObject*) dvmGetFieldObject(exception,
gDvm.offJavaLangThrowable_stackState);
if (stackData == NULL) {
- LOGI(" (no stack trace data found)\n");
+ LOGI(" (raw stack trace not found)\n");
return;
}