Search in sources :

Example 76 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project XobotOS by xamarin.

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[] features = Debug.getVmFeatureList();
    if (false)
        Log.v("ddm-heap", "Got feature list request");
    int size = 4 + 4 * features.length;
    for (int i = features.length - 1; i >= 0; i--) size += features[i].length() * 2;
    ByteBuffer out = ByteBuffer.allocate(size);
    out.order(ChunkHandler.CHUNK_ORDER);
    out.putInt(features.length);
    for (int i = features.length - 1; i >= 0; i--) {
        out.putInt(features[i].length());
        putString(out, features[i]);
    }
    return new Chunk(CHUNK_FEAT, out);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 77 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project XobotOS by xamarin.

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 78 with Chunk

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

the class DdmHandleThread method handleTHST.

/*
     * Handle a "THread STatus" request.  This is constructed by the VM.
     */
private Chunk handleTHST(Chunk request) {
    ByteBuffer in = wrapChunk(request);
    // currently nothing to read from "in"
    //Log.d("ddm-thread", "Thread status request");
    byte[] status = DdmVmInternal.getThreadStats();
    if (status != null)
        return new Chunk(CHUNK_THST, status, 0, status.length);
    else
        return createFailChunk(1, "Can't build THST chunk");
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 79 with Chunk

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

the class DdmHandleHeap method handleHPDU.

/*
     * Handle a "HeaP DUmp" request.
     *
     * This currently just returns a result code.  We could pull up
     * the entire contents of the file and return them, but hprof dump
     * files can be a few megabytes.
     */
private Chunk handleHPDU(Chunk request) {
    ByteBuffer in = wrapChunk(request);
    byte result;
    /* get the filename for the output file */
    int len = in.getInt();
    String fileName = getString(in, len);
    if (false)
        Log.d("ddm-heap", "Heap dump: file='" + fileName + "'");
    try {
        Debug.dumpHprofData(fileName);
        result = 0;
    } catch (UnsupportedOperationException uoe) {
        Log.w("ddm-heap", "hprof dumps not supported in this VM");
        result = -1;
    } catch (IOException ioe) {
        result = -1;
    } catch (RuntimeException re) {
        result = -1;
    }
    /* create a non-empty reply so the handler fires on completion */
    byte[] reply = { result };
    return new Chunk(CHUNK_HPDU, reply, 0, reply.length);
}
Also used : IOException(java.io.IOException) Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 80 with Chunk

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

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