summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabien Sanglard <sanglardf@google.com> 2022-12-21 18:44:13 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2022-12-21 18:44:13 +0000
commite5527c234ed2cf68cdff61a719a97c31fa367f16 (patch)
treeacf5acf05745d5eb7f748e93569c9100b41c90b1
parent71678b8c2689ab26f52eb2166d5f892f7c49a735 (diff)
parentc947f2cf0ddcd38b6775fa48dade8158ded6210f (diff)
Merge "Remove 1.3s "Waiting for Debugger" delay"
-rw-r--r--core/java/android/os/Debug.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 399f11b0f2a7..c731a808263a 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -982,6 +982,43 @@ public final class Debug
/**
+ * Wait until a debugger attaches. As soon as a debugger attaches,
+ * suspend all Java threads and send VM_START (a.k.a VM_INIT)
+ * packet.
+ *
+ * @hide
+ */
+ public static void suspendAllAndSendVmStart() {
+ if (!VMDebug.isDebuggingEnabled()) {
+ return;
+ }
+
+ // if DDMS is listening, inform them of our plight
+ System.out.println("Sending WAIT chunk");
+ byte[] data = new byte[] { 0 }; // 0 == "waiting for debugger"
+ Chunk waitChunk = new Chunk(ChunkHandler.type("WAIT"), data, 0, 1);
+ DdmServer.sendChunk(waitChunk);
+
+ // We must wait until a debugger is connected (debug socket is
+ // open and at least one non-DDM JDWP packedt has been received.
+ // This guarantees that oj-libjdwp has been attached and that
+ // ART's default implementation of suspendAllAndSendVmStart has
+ // been replaced with an implementation that will suspendAll and
+ // send VM_START.
+ System.out.println("Waiting for debugger first packet");
+ while (!isDebuggerConnected()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ie) {
+ }
+ }
+
+ System.out.println("Debug.suspendAllAndSentVmStart");
+ VMDebug.suspendAllAndSendVmStart();
+ System.out.println("Debug.suspendAllAndSendVmStart, resumed");
+ }
+
+ /**
* Wait until a debugger attaches. As soon as the debugger attaches,
* this returns, so you will need to place a breakpoint after the
* waitForDebugger() call if you want to start tracing immediately.