use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by ParanoidAndroid.
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;
}
}
}
use of org.apache.harmony.dalvik.ddmc.Chunk in project platform_frameworks_base by android.
the class DdmHandleViewDebug method profileView.
/** Profiles provided view. */
private Chunk profileView(View rootView, final View targetView) {
ByteArrayOutputStream b = new ByteArrayOutputStream(32 * 1024);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(b), 32 * 1024);
try {
ViewDebug.profileViewAndChildren(targetView, bw);
} catch (IOException e) {
return createFailChunk(1, "Unexpected error while profiling view: " + e.getMessage());
} finally {
try {
bw.close();
} catch (IOException e) {
// ignore
}
}
byte[] data = b.toByteArray();
return new Chunk(CHUNK_VUOP, data, 0, data.length);
}
use of org.apache.harmony.dalvik.ddmc.Chunk in project XobotOS by xamarin.
the class DdmHandleThread method createStackChunk.
/*
* Serialize a StackTraceElement[] into an STKL chunk.
*
* We include the threadId in the response so the other side doesn't have
* to match up requests and responses as carefully.
*/
private Chunk createStackChunk(StackTraceElement[] trace, int threadId) {
int bufferSize = 0;
// version, flags, whatever
bufferSize += 4;
// thread ID
bufferSize += 4;
// frame count
bufferSize += 4;
for (StackTraceElement elem : trace) {
bufferSize += 4 + elem.getClassName().length() * 2;
bufferSize += 4 + elem.getMethodName().length() * 2;
bufferSize += 4;
if (elem.getFileName() != null)
bufferSize += elem.getFileName().length() * 2;
// line number
bufferSize += 4;
}
ByteBuffer out = ByteBuffer.allocate(bufferSize);
out.putInt(0);
out.putInt(threadId);
out.putInt(trace.length);
for (StackTraceElement elem : trace) {
out.putInt(elem.getClassName().length());
putString(out, elem.getClassName());
out.putInt(elem.getMethodName().length());
putString(out, elem.getMethodName());
if (elem.getFileName() != null) {
out.putInt(elem.getFileName().length());
putString(out, elem.getFileName());
} else {
out.putInt(0);
}
out.putInt(elem.getLineNumber());
}
return new Chunk(CHUNK_STKL, out);
}
use of org.apache.harmony.dalvik.ddmc.Chunk in project XobotOS by xamarin.
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");
}
use of org.apache.harmony.dalvik.ddmc.Chunk in project XobotOS by xamarin.
the class DdmHandleAppName method sendAPNM.
/*
* Send an APNM (APplication NaMe) chunk.
*/
private static void sendAPNM(String appName) {
if (false)
Log.v("ddm", "Sending app name");
ByteBuffer out = ByteBuffer.allocate(4 + appName.length() * 2);
out.order(ChunkHandler.CHUNK_ORDER);
out.putInt(appName.length());
putString(out, appName);
Chunk chunk = new Chunk(CHUNK_APNM, out);
DdmServer.sendChunk(chunk);
}
Aggregations