long thread = createLongFromBytes(inData, 0, 8);
logr.log(JDILogger.LEVEL_VERBOSE, "ThreadReference.Name(" + thread + ")"); //$NON-NLS-1$ //$NON-NLS-2$
Iterator asIt = image.getAddressSpaces( ).iterator();
while ( asIt.hasNext( ) )
{
ImageAddressSpace as = (ImageAddressSpace) asIt.next( );
Iterator prIt = as.getProcesses( ).iterator();
while ( prIt.hasNext( ) )
{
ImageProcess process = (ImageProcess) prIt.next( );
Iterator runTimesIt = process.getRuntimes( ).iterator();
while ( runTimesIt.hasNext( ) )
{
JavaRuntime javaRT = (JavaRuntime) runTimesIt.next( );
Iterator thds = javaRT.getThreads().iterator();
int count = 0;
while(thds.hasNext()){
Object tmpobj = thds.next();
if (tmpobj instanceof CorruptData){
//ignore this thread
}else{
count++;
JavaThread thd = (JavaThread)tmpobj;
if (thread == thd.getObject().getID().getAddress()){
Vector<Byte> vctr = new Vector<Byte>();
addStringToVector(vctr, thd.getName());
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
rpckt.setData(vectorToByte(vctr));
return rpckt;
}
}
}
}
}
}
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_THREAD);
return rpckt;
}else if (cpckt.getCommand() == 2){
logr.log(JDILogger.LEVEL_VERBOSE, "Suspend()"); //$NON-NLS-1$
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
return rpckt;
}else if (cpckt.getCommand() == 3){
logr.log(JDILogger.LEVEL_VERBOSE, "Resume()"); //$NON-NLS-1$
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
return rpckt;
}else if (cpckt.getCommand() == 4){
byte []inData = cpckt.getByteData();
long thread = createLongFromBytes(inData, 0, 8);
logr.log(JDILogger.LEVEL_VERBOSE, "Status("+thread+")"); //$NON-NLS-1$ //$NON-NLS-2$
Iterator asIt = image.getAddressSpaces( ).iterator();
while ( asIt.hasNext( ) )
{
ImageAddressSpace as = (ImageAddressSpace) asIt.next( );
Iterator prIt = as.getProcesses( ).iterator();
while ( prIt.hasNext( ) )
{
ImageProcess process = (ImageProcess) prIt.next( );
Iterator runTimesIt = process.getRuntimes( ).iterator();
while ( runTimesIt.hasNext( ) )
{
JavaRuntime javaRT = (JavaRuntime) runTimesIt.next( );
Iterator thds = javaRT.getThreads().iterator();
Vector<Byte> vctr = new Vector<Byte>();
while(thds.hasNext()){
Object tmpobj = thds.next();
if (tmpobj instanceof CorruptData){
//ignore this thread
}else{
JavaThread thd = (JavaThread) tmpobj;
if (thd.getObject().getID().getAddress() == thread){
int threadStatus = 1;
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread Status: "+thd.getState()); //$NON-NLS-1$
logr.log(JDILogger.LEVEL_VERYVERBOSE, " Thread Name: " + thd.getName()); //$NON-NLS-1$
if ((thd.getState() & JavaThread.STATE_TERMINATED) > 0){
threadStatus = 0;
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is terminated"); //$NON-NLS-1$
}else if ((thd.getState() & JavaThread.STATE_SLEEPING) > 0){
threadStatus = 2;
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is sleeping"); //$NON-NLS-1$
}else if ((thd.getState() & JavaThread.STATE_IN_OBJECT_WAIT) > 0 || (thd.getState() & JavaThread.STATE_WAITING) > 0 || (thd.getState() & JavaThread.STATE_WAITING_INDEFINITELY) > 0 || (thd.getState() & JavaThread.STATE_WAITING_WITH_TIMEOUT) > 0){
threadStatus = 4;
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is waiting"); //$NON-NLS-1$
}else if ((thd.getState() & JavaThread.STATE_BLOCKED_ON_MONITOR_ENTER) > 0){
threadStatus = 3;
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is monitor"); //$NON-NLS-1$
}else{
threadStatus = 1;
logr.log(JDILogger.LEVEL_VERBOSE, "Thread is other (running)"); //$NON-NLS-1$
if ((thd.getState() & JavaThread.STATE_ALIVE) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is alive"); //$NON-NLS-1$
}
if ((thd.getState() & JavaThread.STATE_IN_NATIVE) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is in native"); //$NON-NLS-1$
}
if ((thd.getState() & JavaThread.STATE_PARKED) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is parked"); //$NON-NLS-1$
}
if ((thd.getState() & JavaThread.STATE_INTERRUPTED) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is interrupted"); //$NON-NLS-1$
}
if ((thd.getState() & JavaThread.STATE_VENDOR_1) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is vendor 1"); //$NON-NLS-1$
}
if ((thd.getState() & JavaThread.STATE_VENDOR_3) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is vendor 2"); //$NON-NLS-1$
}
if ((thd.getState() & JavaThread.STATE_VENDOR_2) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is vendor 3"); //$NON-NLS-1$
}
if ((thd.getState() & JavaThread.STATE_RUNNABLE) > 0){
logr.log(JDILogger.LEVEL_VERYVERBOSE, "Thread is runnable"); //$NON-NLS-1$
}
}
//The thread always starts in Eclipse as running
//Even if it isn't (See bug #161781)
int suspendStatus = 1;
threadStatus = 2;
addIntToVector(vctr, threadStatus);
addIntToVector(vctr, suspendStatus);
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
rpckt.setData(vectorToByte(vctr));
return rpckt;
}
}
}
}
}
}
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
return rpckt;
}else if (cpckt.getCommand() == 5){
//ThreadGroup
//This call returns the group of the input thread.
//TODO - Since this doesn't seem available in Kato, let's fake it with 0
// Lets fake it with 1 ...
byte [] inData = cpckt.getByteData();
long thread = createLongFromBytes(inData, 0, 8);
logr.log(JDILogger.LEVEL_VERBOSE, "ThreadGroup("+thread+")"); //$NON-NLS-1$ //$NON-NLS-2$
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
Vector<Byte> vctr = new Vector<Byte>();
addLongToVector(vctr, 1);
rpckt.setData(vectorToByte(vctr));
return rpckt;
}else if (cpckt.getCommand() == 6){
//List all the frames from the thread
byte []inData = cpckt.getByteData();
long thread = createLongFromBytes(inData, 0, 8);
int startFrame = createIntFromBytes(inData, 8, 4);
int length = createIntFromBytes(inData, 12, 4);
logr.log(JDILogger.LEVEL_VERBOSE, "Frames(" + thread + "," + startFrame + "," + length + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Iterator asIt = image.getAddressSpaces( ).iterator();
while ( asIt.hasNext( ) )
{
ImageAddressSpace as = (ImageAddressSpace) asIt.next( );
Iterator prIt = as.getProcesses( ).iterator();
while ( prIt.hasNext( ) )
{
ImageProcess process = (ImageProcess) prIt.next( );
Iterator runTimesIt = process.getRuntimes( ).iterator();
while ( runTimesIt.hasNext( ) )
{
JavaRuntime javaRT = (JavaRuntime) runTimesIt.next( );
Iterator thds = javaRT.getThreads().iterator();
while(thds.hasNext()){
Object tmpobj = thds.next();
if (tmpobj instanceof CorruptData){
//ignore this thread
}else{
JavaThread thd = (JavaThread) tmpobj;
if (thd.getObject().getID().getAddress() == thread){
int currentFrame = 0;
int count = 0;
Iterator frames = thd.getStackFrames().iterator();
Vector<Byte> vctr = new Vector<Byte>();
int count2 = 0;
while(frames.hasNext()){
count2++;
if (length > 0){
if (currentFrame >= startFrame && currentFrame <= startFrame + length){
JavaStackFrame jStackFrame = (JavaStackFrame)frames.next();
addLongToVector(vctr, jStackFrame.getBasePointer().getAddress());
JavaLocation jLoc = jStackFrame.getLocation();
JavaMethod jMethod = jLoc.getMethod();
JavaClass jClass = jMethod.getDeclaringClass();
if (jClass.isArray()){
vctr.add((byte)3);
}else if(isInterface(jClass.getID().getAddress())){
vctr.add((byte)2);
}else{
vctr.add((byte)1);
}
addLongToVector(vctr, jClass.getID().getAddress());
addLongToVector(vctr, getMethodId(jClass.getID().getAddress(), jMethod));
//This is the current memory address.
addLongToVector(vctr, jLoc.getAddress().getAddress());
try{
logr.log(JDILogger.LEVEL_VERYVERBOSE, " " + jLoc.getFilename() + "@" + jLoc.getMethod().getDeclaringClass().getName() + "{"+jLoc.getMethod().getDeclaringClass().getID().getAddress()+"}." + jLoc.getMethod().getName() + "{"+getMethodId(jClass.getID().getAddress(), jLoc.getMethod())+"}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
try{
logr.log(JDILogger.LEVEL_VERYVERBOSE, " :" + jLoc.getLineNumber()); //$NON-NLS-1$
}catch(Exception exxy){
}
}catch (Exception exxy){}
count++;
}
}else{
if (currentFrame >= startFrame){
JavaStackFrame jStackFrame = (JavaStackFrame)frames.next();
addLongToVector(vctr, jStackFrame.getBasePointer().getAddress());
JavaLocation jLoc = jStackFrame.getLocation();
JavaMethod jMethod = jLoc.getMethod();
JavaClass jClass = jMethod.getDeclaringClass();
if (jClass.isArray()){
vctr.add((byte)3);
}else if(isInterface(jClass.getID().getAddress())){
vctr.add((byte)2);
}else{
vctr.add((byte)1);
}
addLongToVector(vctr, jClass.getID().getAddress());
addLongToVector(vctr, getMethodId(jClass.getID().getAddress(), jMethod));
//Location is 8 bytes (2 ints)
//We pad with 4 bytes of zeros
try{
addLongToVector(vctr, jLoc.getAddress().getAddress());
}
catch(Exception exxy){
addLongToVector(vctr, -1);
}
try{
logr.log(JDILogger.LEVEL_VERYVERBOSE, " " + jLoc.getFilename() + "@" + jLoc.getMethod().getDeclaringClass().getName() + "{"+jLoc.getMethod().getDeclaringClass().getID().getAddress()+"}." + jLoc.getMethod().getName() + "{"+getMethodId(jClass.getID().getAddress(),jLoc.getMethod())+"}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
try{
logr.log(JDILogger.LEVEL_VERYVERBOSE, " :" + jLoc.getLineNumber()); //$NON-NLS-1$
}catch(Exception exxy){
}
}catch (Exception exxy){}
count++;
}
}
}
logr.log(JDILogger.LEVEL_VERYVERBOSE, count + " frames found (of " +count2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
addIntToVectorFront(vctr, count);
rpckt.setData(vectorToByte(vctr));
return rpckt;
}
}
}
}
}
}
ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
return rpckt;
}else if (cpckt.getCommand() == 7){
//List all the frames from the thread
byte []inData = cpckt.getByteData();
long thread = createLongFromBytes(inData, 0, 8);
logr.log(JDILogger.LEVEL_VERBOSE, "FrameCount(" + thread + ")"); //$NON-NLS-1$ //$NON-NLS-2$
Iterator asIt = image.getAddressSpaces( ).iterator();
while ( asIt.hasNext( ) )
{
ImageAddressSpace as = (ImageAddressSpace) asIt.next( );
Iterator prIt = as.getProcesses( ).iterator();
while ( prIt.hasNext( ) )
{
ImageProcess process = (ImageProcess) prIt.next( );
Iterator runTimesIt = process.getRuntimes( ).iterator();