**********************************************************************/
package net.sourceforge.phpdt.internal.debug.core;
-import java.io.IOException;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;
+import net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString;
+import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
+import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
+
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
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;
-
public class PHPDBGInterface {
// Public
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;
flushAllPackets();
// Process serialized variables
- DBGVariableList= procVars(stack);
+ PHPDBGEvalString evalStr=new PHPDBGEvalString(stack,serGlobals);
+
+ DBGVariableList= evalStr.getVars();
return DBGVariableList;
}
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)
// 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 {
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;
// To print errors on the console, I must execute a code in the
// php context, that write the stderr... I didn't found a better way
// TODO: Find a better way????
- String codeExec= "";
- codeExec= "fwrite(fopen('php://stderr', 'w'),\\\"" + error + "\\\");";
- try {
- evalBlock("eval(\"" + codeExec + "\");");
- } catch (DebugException e) {
- PHPDebugCorePlugin.log(e);
- }
+// String codeExec= "";
+// codeExec= "fwrite(fopen('php://stderr', 'w'),\\\"" + error + "\\\");";
+// try {
+// evalBlock("eval(\"" + codeExec + "\");");
+// } catch (DebugException e) {
+// PHPDebugCorePlugin.log(e);
+// }
if(!stopOnError) {
if(lastCommand.equals(PHPDBGBase.DBGA_CONTINUE)) {
continueExecution();