OSDN Git Service

Added VMDebug.crash() (hidden).
authorAndy McFadden <fadden@android.com>
Fri, 31 Jul 2009 20:54:59 +0000 (13:54 -0700)
committerAndy McFadden <fadden@android.com>
Fri, 31 Jul 2009 20:54:59 +0000 (13:54 -0700)
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.

libcore/dalvik/src/main/java/dalvik/system/VMDebug.java
vm/native/dalvik_system_VMDebug.c

index 06a67b6..bcc8b61 100644 (file)
@@ -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
index d0fb61d..8aa371d 100644 (file)
@@ -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 },
 };