X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java index 80682b8..e0e19cc 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGInterface.java @@ -7,6 +7,7 @@ http://www.eclipse.org/legal/cpl-v10.html Contributors: Vicente Fernando - www.alfersoft.com.ar - Initial implementation + Christian Perkonig - remote debug **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core; @@ -21,7 +22,7 @@ import org.eclipse.debug.core.DebugException; import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame; import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable; -import net.sourceforge.phpdt.internal.debug.core.model.PHPValue; +import net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString; public class PHPDBGInterface { @@ -37,16 +38,16 @@ public class PHPDBGInterface { private PHPStackFrame[] DBGStackList; private PHPVariable[] DBGVariableList; private Vector DBGMods= new Vector(); - private Vector DBGVars= new Vector(); private BufferedReader in; private OutputStream os; - private boolean shouldStop= false, isRef= false, hasChildren= false, isObject= false; + private boolean shouldStop= false; private String evalRet= new String(""); private String serGlobals= new String(""); - private String typeRead= new String(""); - private String className= new String(""); - private int finalPos=0, refCounter=0, rawCounter=1000; + private int rawCounter=1000; private PHPDBGProxy proxy= null; + + private int lastCmd=-1; + private int sid=0; private boolean stopOnError= false; private char[] lastCommand= new char[4]; @@ -203,6 +204,21 @@ public class PHPDBGInterface { } return BPUnder; } + + public int getLastCmd() + { + return lastCmd; + } + + public int getSID() + { + return sid; + } + + public void setLastCmd(int cmd) + { + lastCmd=cmd; + } public void stepInto() throws IOException { BPUnderHit= 0; @@ -252,7 +268,9 @@ public class PHPDBGInterface { flushAllPackets(); // Process serialized variables - DBGVariableList= procVars(stack); + PHPDBGEvalString evalStr=new PHPDBGEvalString(stack,serGlobals); + + DBGVariableList= evalStr.getVars(); return DBGVariableList; } @@ -287,14 +305,14 @@ public class PHPDBGInterface { flushAllPackets(); } - public void evalBlock(String evalString) throws IOException, DebugException { + public PHPVariable[] evalBlock(PHPStackFrame stack, String evalString) throws IOException, DebugException { PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST); PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_EVAL); PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA); rawCounter++; DBGFrame1.addInt(rawCounter); // istr = raw data ID - DBGFrame1.addInt(-1); // scope_id = -1 means current location, 0 never used, +1 first depth + DBGFrame1.addInt(1); // scope_id = -1 means current location, 0 never used, +1 first depth DBGFrame2.addInt(rawCounter); // FRAME_RAWDATA ID DBGFrame2.addInt(evalString.length() + 1); // length of rawdata (+ null char) @@ -306,11 +324,16 @@ public class PHPDBGInterface { // Add command data DBGPacket.addFrame(DBGFrame1); - if(proxy.getSocket().isClosed()) return; + if(proxy.getSocket().isClosed()) return null; DBGPacket.sendPacket(os); waitResponse(1000); flushAllPackets(); + + PHPDBGEvalString evalStr=new PHPDBGEvalString(stack,evalRet); + + return evalStr.getVars(); + } public void flushAllPackets() throws IOException { @@ -370,227 +393,6 @@ public class PHPDBGInterface { return ""; } - public PHPVariable[] getInstVars(PHPVariable phpVar) throws DebugException { - Vector vecVars= new Vector(); - PHPVariable localPHPVar; - int i=0; - - // already unserialized - for(i=0; i < DBGVars.size(); i++) { - localPHPVar= (PHPVariable)DBGVars.get(i); - if(localPHPVar.getParent() == phpVar) { - vecVars.add(localPHPVar); - } - } - PHPVariable[] arrVars= new PHPVariable[vecVars.size()]; - arrVars= (PHPVariable[]) vecVars.toArray(arrVars); - - return arrVars; - } - - private PHPVariable[] procVars(PHPStackFrame stack) throws DebugException { - Vector vecVars= new Vector(); - - // unserialize - finalPos= 0; - refCounter= 0; - doUnserialize(stack, vecVars, null); - - DBGVars= vecVars; - - return(getInstVars(null)); - } - - private String readValue(String serialVars) throws DebugException { - int startPos=0, endPos=0, lenStr=0, i=0, elements=0; - String ret= new String(""); - - switch(serialVars.charAt(0)) { - case 'a': // associative array, a:elements:{[index][value]...} - typeRead= "hash"; - startPos= 1; - endPos= serialVars.indexOf(':', startPos + 1); - if(endPos == -1) return ""; - finalPos += endPos + 2; - ret= new String(serialVars.substring(startPos + 1, endPos)); - - hasChildren= true; - break; - case 'O': // object, O:name_len:"name":elements:{[attribute][value]...} - typeRead= "object"; - - startPos= 1; - endPos= serialVars.indexOf(':', startPos + 1); - if(endPos == -1) return ""; - - // get object class - lenStr= Integer.parseInt(serialVars.substring(startPos + 1, endPos)); - startPos= endPos + 2; - endPos= lenStr + startPos; - className= new String(serialVars.substring(startPos, endPos).toString()); - - // get num of elements - startPos= endPos + 1; - endPos= serialVars.indexOf(':', startPos + 1); - if(endPos == -1) return ""; - finalPos += endPos + 2; - ret= new String(serialVars.substring(startPos + 1, endPos)); - - isObject= true; - hasChildren= true; - break; - case 's': // string, s:length:"data"; - typeRead= "string"; - startPos= 1; - endPos= serialVars.indexOf(':', startPos + 1); - if(endPos == -1) return ""; - - lenStr= Integer.parseInt(serialVars.substring(startPos + 1, endPos)); - startPos= endPos + 2; - endPos= lenStr + startPos; - ret= new String(serialVars.substring(startPos, endPos).toString()); - finalPos += endPos + 2; - break; - case 'i': // integer, i:123; - typeRead= "integer"; - startPos= 1; - endPos= serialVars.indexOf(';', startPos + 1); - if(endPos == -1) return ""; - - ret= new String(serialVars.substring(startPos + 1, endPos).toString()); - finalPos += endPos + 1; - break; - case 'd': // double (float), d:1.23; - typeRead= "double"; - startPos= 1; - endPos= serialVars.indexOf(';', startPos + 1); - if(endPos == -1) return ""; - - ret= new String(serialVars.substring(startPos + 1, endPos).toString()); - finalPos += endPos + 1; - break; - case 'N': // NULL, N; - typeRead= "null"; - ret= "nil"; - finalPos += 2; - break; - case 'b': // bool, b:0 or 1 - typeRead= "boolean"; - ret= (serialVars.charAt(2) == '1')?"true":"false"; - finalPos += endPos + 4; - break; - case 'z': // resource, z:typename_len:"typename":valres; - typeRead= "resource"; - - startPos= 1; - endPos= serialVars.indexOf(':', startPos + 1); - if(endPos == -1) return ""; - - // get resource type name - lenStr= Integer.parseInt(serialVars.substring(startPos + 1, endPos)); - startPos= endPos + 2; - endPos= lenStr + startPos; - className= new String(serialVars.substring(startPos, endPos).toString()); - - // get resource value - startPos= endPos + 1; - endPos= serialVars.indexOf(';', startPos + 1); - if(endPos == -1) return ""; - ret= new String(serialVars.substring(startPos + 1, endPos)); - finalPos += endPos + 1; - break; - case 'r': - case 'R': - typeRead= "reference"; - startPos= 1; - endPos= serialVars.indexOf(';', startPos + 1); - if(endPos == -1) return "0"; - - ret= new String(serialVars.substring(startPos + 1, endPos)); - finalPos += endPos + 1; - isRef= true; - break; - case ';': - typeRead= "unknown"; - finalPos+= 1; - break; - case '?': - finalPos+= 1; - default: - finalPos+= 1; - typeRead= "unknown"; - break; - } - return ret; - } - - private void doUnserialize(PHPStackFrame stack, Vector vecVars, PHPVariable parent) throws DebugException { - int i, elements= 0; - PHPVariable newVar= null; - String value= new String(""); - String name= new String(""); - String tmp= new String(""); - String[] tmpSplit; - - if(finalPos > serGlobals.length() || serGlobals.equals("") || serGlobals.substring(finalPos).equals("")) return; - - isRef= false; - hasChildren= false; - isObject= false; - name= readValue(serGlobals.substring(finalPos)); - - if(hasChildren) { - // main array - if(refCounter == 0) { - value= name; - name= ""; - } - } else { - hasChildren= false; - isRef= false; - value= readValue(serGlobals.substring(finalPos)); - // replaceAll doesn't work, why??? - tmpSplit= value.split("\\\\"); - value= ""; - for(i= 0; i < tmpSplit.length; i++) { - value= value + tmpSplit[i]; - if(!tmpSplit[i].equals("")) { - if(i < (tmpSplit.length - 1)) { - value= value + "\\"; - } - } - } - } - - if(!name.equals("")) { - if(isRef) { - PHPVariable varPHP; - for(i=0; i < vecVars.size(); i++) { - varPHP= (PHPVariable) vecVars.get(i); - if(varPHP.getObjectId().equals(value)) { - newVar= new PHPVariable(stack, name, "local", true, (PHPValue)varPHP.getValue()); - break; - } - } - if(newVar == null) { - newVar= new PHPVariable(stack, name, "local", false, null); - } - } else { - refCounter++; - newVar= new PHPVariable(stack, name, "local", value, typeRead, hasChildren, Integer.toString(refCounter), className); - } - newVar.setParent(parent); - vecVars.add(newVar); - } - if(hasChildren) { - elements= Integer.parseInt(value); - for(i=0; i < elements; i++) - doUnserialize(stack, vecVars, newVar); - - // skip "}" - finalPos += 1; - } - } public int readResponse() throws IOException { int bytesToRead=0, nextFrame=0, i=0, cmdReceived=0, stackIndex=0; @@ -619,6 +421,7 @@ public class PHPDBGInterface { if(dbg_header_struct[0] != 0x5953) return 0; cmdReceived= dbg_header_struct[1]; + setLastCmd(cmdReceived); bytesToRead= dbg_header_struct[3]; //System.out.println("Response Received: " + cmdReceived); @@ -727,11 +530,11 @@ public class PHPDBGInterface { // TODO: Find a better way???? String codeExec= ""; codeExec= "fwrite(fopen('php://stderr', 'w'),\\\"" + error + "\\\");"; - try { - evalBlock("eval(\"" + codeExec + "\");"); - } catch (DebugException e) { - PHPDebugCorePlugin.log(e); - } +// try { +// evalBlock("eval(\"" + codeExec + "\");"); +// } catch (DebugException e) { +// PHPDebugCorePlugin.log(e); +// } if(!stopOnError) { if(lastCommand.equals(PHPDBGBase.DBGA_CONTINUE)) { continueExecution(); @@ -796,6 +599,7 @@ public class PHPDBGInterface { case PHPDBGBase.FRAME_VER: break; case PHPDBGBase.FRAME_SID: + sid = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 0); break; case PHPDBGBase.FRAME_SRCLINESINFO: break; @@ -876,12 +680,13 @@ public class PHPDBGInterface { this.shouldStop= true; } - public void waitResponse(long milliseconds) throws IOException { + public boolean waitResponse(long milliseconds) throws IOException { long timeout= System.currentTimeMillis() + milliseconds; while(System.currentTimeMillis() < timeout) { if(in.ready() || shouldStop) { break; } } + return in.ready(); } -} \ No newline at end of file +}