From: Andy McFadden Date: Fri, 31 Jul 2009 20:54:59 +0000 (-0700) Subject: Added VMDebug.crash() (hidden). X-Git-Tag: android-x86-2.2~778^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e9efb8a44202c814b0ebdc16fbab1f754451cd38;p=android-x86%2Fdalvik.git Added VMDebug.crash() (hidden). This call prints the stack trace for the current thread, and then crashes the VM so you can see the native stack trace too. Useful for figuring out "how did I get here?" situations. --- diff --git a/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java b/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java index 06a67b681..bcc8b61fc 100644 --- a/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java +++ b/libcore/dalvik/src/main/java/dalvik/system/VMDebug.java @@ -282,8 +282,15 @@ public final class VMDebug { */ public static native boolean cacheRegisterMap(String classAndMethodDesc); - /* don't ask */ - static native void printThis(Object thisThing, int count, int thing); + /** + * Crashes the VM. Seriously. Dumps the stack trace for the current + * thread and then aborts the VM so you can see the native stack trace. + * Useful for figuring out how you got somewhere when lots of native + * code is involved. + * + * @hide + */ + public static native void crash(); /* * Fake method, inserted into dmtrace output when the garbage collector diff --git a/vm/native/dalvik_system_VMDebug.c b/vm/native/dalvik_system_VMDebug.c index d0fb61ded..8aa371d73 100644 --- a/vm/native/dalvik_system_VMDebug.c +++ b/vm/native/dalvik_system_VMDebug.c @@ -698,13 +698,31 @@ bail: RETURN_BOOLEAN(result); } +/* + * static void crash() + * + * Dump the current thread's interpreted stack and abort the VM. Useful + * for seeing both interpreted and native stack traces. + * + * (Might want to restrict this to debuggable processes as a security + * measure, or check SecurityManager.checkExit().) + */ +static void Dalvik_dalvik_system_VMDebug_crash(const u4* args, + JValue* pResult) +{ + UNUSED_PARAMETER(args); + UNUSED_PARAMETER(pResult); + + LOGW("Crashing VM on request\n"); + dvmDumpThread(dvmThreadSelf(), false); + dvmAbort(); +} + const DalvikNativeMethod dvm_dalvik_system_VMDebug[] = { { "getAllocCount", "(I)I", Dalvik_dalvik_system_VMDebug_getAllocCount }, { "resetAllocCount", "(I)V", Dalvik_dalvik_system_VMDebug_resetAllocCount }, - //{ "print", "(Ljava/lang/String;)V", - // Dalvik_dalvik_system_VMDebug_print }, { "startAllocCounting", "()V", Dalvik_dalvik_system_VMDebug_startAllocCounting }, { "stopAllocCounting", "()V", @@ -747,6 +765,8 @@ const DalvikNativeMethod dvm_dalvik_system_VMDebug[] = { Dalvik_dalvik_system_VMDebug_dumpHprofData }, { "cacheRegisterMap", "(Ljava/lang/String;)Z", Dalvik_dalvik_system_VMDebug_cacheRegisterMap }, + { "crash", "()V", + Dalvik_dalvik_system_VMDebug_crash }, { NULL, NULL, NULL }, };