Search in sources :

Example 81 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by DirtyUnicorns.

the class DdmHandleHello method sendWAIT.

/**
     * Send up a WAIT chunk.  The only currently defined value for "reason"
     * is zero, which means "waiting for a debugger".
     */
public static void sendWAIT(int reason) {
    byte[] data = new byte[] { (byte) reason };
    Chunk waitChunk = new Chunk(CHUNK_WAIT, data, 0, 1);
    DdmServer.sendChunk(waitChunk);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk)

Example 82 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by DirtyUnicorns.

the class Debug method waitForDebugger.

/**
     * 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.
     */
public static void waitForDebugger() {
    if (!VMDebug.isDebuggingEnabled()) {
        //System.out.println("debugging not enabled, not waiting");
        return;
    }
    if (isDebuggerConnected())
        return;
    // if DDMS is listening, inform them of our plight
    System.out.println("Sending WAIT chunk");
    // 0 == "waiting for debugger"
    byte[] data = new byte[] { 0 };
    Chunk waitChunk = new Chunk(ChunkHandler.type("WAIT"), data, 0, 1);
    DdmServer.sendChunk(waitChunk);
    mWaiting = true;
    while (!isDebuggerConnected()) {
        try {
            Thread.sleep(SPIN_DELAY);
        } catch (InterruptedException ie) {
        }
    }
    mWaiting = false;
    System.out.println("Debugger has connected");
    /*
         * There is no "ready to go" signal from the debugger, and we're
         * not allowed to suspend ourselves -- the debugger expects us to
         * be running happily, and gets confused if we aren't.  We need to
         * allow the debugger a chance to set breakpoints before we start
         * running again.
         *
         * Sit and spin until the debugger has been idle for a short while.
         */
    while (true) {
        long delta = VMDebug.lastDebuggerActivity();
        if (delta < 0) {
            System.out.println("debugger detached?");
            break;
        }
        if (delta < MIN_DEBUGGER_IDLE) {
            System.out.println("waiting for debugger to settle...");
            try {
                Thread.sleep(SPIN_DELAY);
            } catch (InterruptedException ie) {
            }
        } else {
            System.out.println("debugger has settled (" + delta + ")");
            break;
        }
    }
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk)

Example 83 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by AOSPA.

the class DdmHandleAppName method sendAPNM.

/*
     * Send an APNM (APplication NaMe) chunk.
     */
private static void sendAPNM(String appName, int userId) {
    if (false)
        Log.v("ddm", "Sending app name");
    ByteBuffer out = ByteBuffer.allocate(4 + /* appName's length */
    appName.length() * 2 + /* appName */
    4);
    out.order(ChunkHandler.CHUNK_ORDER);
    out.putInt(appName.length());
    putString(out, appName);
    out.putInt(userId);
    Chunk chunk = new Chunk(CHUNK_APNM, out);
    DdmServer.sendChunk(chunk);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 84 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by AOSPA.

the class DdmHandleViewDebug method dumpHierarchy.

/**
     * Returns the view hierarchy and/or view properties starting at the provided view.
     * Based on the input options, the return data may include:
     *  - just the view hierarchy
     *  - view hierarchy & the properties for each of the views
     *  - just the view properties for a specific view.
     *  TODO: Currently this only returns views starting at the root, need to fix so that
     *  it can return properties of any view.
     */
private Chunk dumpHierarchy(View rootView, ByteBuffer in) {
    boolean skipChildren = in.getInt() > 0;
    boolean includeProperties = in.getInt() > 0;
    boolean v2 = in.hasRemaining() && in.getInt() > 0;
    long start = System.currentTimeMillis();
    ByteArrayOutputStream b = new ByteArrayOutputStream(2 * 1024 * 1024);
    try {
        if (v2) {
            ViewDebug.dumpv2(rootView, b);
        } else {
            ViewDebug.dump(rootView, skipChildren, includeProperties, b);
        }
    } catch (IOException | InterruptedException e) {
        return createFailChunk(1, "Unexpected error while obtaining view hierarchy: " + e.getMessage());
    }
    long end = System.currentTimeMillis();
    Log.d(TAG, "Time to obtain view hierarchy (ms): " + (end - start));
    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VURT, data, 0, data.length);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Chunk(org.apache.harmony.dalvik.ddmc.Chunk)

Example 85 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by AOSPA.

the class DdmHandleHello method handleFEAT.

/*
     * Handle request for list of supported features.
     */
private Chunk handleFEAT(Chunk request) {
    // TODO: query the VM to ensure that support for these features
    // is actually compiled in
    final String[] vmFeatures = Debug.getVmFeatureList();
    if (false)
        Log.v("ddm-heap", "Got feature list request");
    int size = 4 + 4 * (vmFeatures.length + FRAMEWORK_FEATURES.length);
    for (int i = vmFeatures.length - 1; i >= 0; i--) size += vmFeatures[i].length() * 2;
    for (int i = FRAMEWORK_FEATURES.length - 1; i >= 0; i--) size += FRAMEWORK_FEATURES[i].length() * 2;
    ByteBuffer out = ByteBuffer.allocate(size);
    out.order(ChunkHandler.CHUNK_ORDER);
    out.putInt(vmFeatures.length + FRAMEWORK_FEATURES.length);
    for (int i = vmFeatures.length - 1; i >= 0; i--) {
        out.putInt(vmFeatures[i].length());
        putString(out, vmFeatures[i]);
    }
    for (int i = FRAMEWORK_FEATURES.length - 1; i >= 0; i--) {
        out.putInt(FRAMEWORK_FEATURES[i].length());
        putString(out, FRAMEWORK_FEATURES[i]);
    }
    return new Chunk(CHUNK_FEAT, out);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Chunk (org.apache.harmony.dalvik.ddmc.Chunk)98 ByteBuffer (java.nio.ByteBuffer)48 IOException (java.io.IOException)36 ByteArrayOutputStream (java.io.ByteArrayOutputStream)29 BufferedWriter (java.io.BufferedWriter)6 DataOutputStream (java.io.DataOutputStream)6 OutputStreamWriter (java.io.OutputStreamWriter)6 VMRuntime (dalvik.system.VMRuntime)5