import java.io.BufferedReader;
import java.io.OutputStream;
import java.util.Vector;
-import java.lang.System;
+
+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;
-import net.sourceforge.phpdt.internal.debug.core.PHPDBGMod;
public class PHPDBGInterface {
private String className= new String("");
private int finalPos=0, refCounter=0, rawCounter=1000;
private PHPDBGProxy proxy= null;
+ private boolean stopOnError= false;
+ private char[] lastCommand= new char[4];
public PHPDBGInterface(BufferedReader in, OutputStream os, PHPDBGProxy proxy) {
DBGBPList.clear();
PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_CONTINUE);
if(proxy.getSocket().isClosed()) return;
DBGPacket.sendPacket(os);
+ lastCommand= PHPDBGBase.DBGA_CONTINUE;
+ }
+
+ public void pauseExecution() throws IOException {
+ PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.IntToChar4(PHPDBGBase.DBGC_PAUSE));
+ if(proxy.getSocket().isClosed()) return;
+ DBGPacket.sendPacket(os);
}
private int getBPUnderHit() {
PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPINTO);
if(proxy.getSocket().isClosed()) return;
DBGPacket.sendPacket(os);
+ lastCommand= PHPDBGBase.DBGA_STEPINTO;
}
public void stepOver() throws IOException {
PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOVER);
if(proxy.getSocket().isClosed()) return;
DBGPacket.sendPacket(os);
+ lastCommand= PHPDBGBase.DBGA_STEPOVER;
}
public void stepOut() throws IOException {
PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOUT);
if(proxy.getSocket().isClosed()) return;
DBGPacket.sendPacket(os);
+ lastCommand= PHPDBGBase.DBGA_STEPOUT;
}
public void stopExecution() throws IOException {
public PHPVariable[] getVariables(PHPStackFrame stack) throws IOException, DebugException {
PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_EVAL);
- //PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
DBGFrame1.addInt(0); // istr = raw data ID
DBGFrame1.addInt(1); // scope_id = -1 means current location, 0 never used, +1 first depth
-
- /*
- String evalBlock= new String("$GLOBALS");
- DBGFrame2.addInt(1); // FRAME_RAWDATA ID
- DBGFrame2.addInt(evalBlock.length() + 1); // length of rawdata (+ null char)
- DBGFrame2.addString(evalBlock); // eval block
- DBGFrame2.addChar('\0'); // null char
- */
// Add command data
DBGPacket.addFrame(DBGFrame1);
return DBGVariableList;
}
+ public void log(String logString) throws IOException, DebugException {
+ PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
+ PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_LOG);
+ PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
+
+ rawCounter++;
+ DBGFrame1.addInt(rawCounter); // ilog
+ DBGFrame1.addInt(1); // type
+ DBGFrame1.addInt(0); // mod_no
+ DBGFrame1.addInt(0); // line_no
+ DBGFrame1.addInt(0); // imod_name
+ DBGFrame1.addInt(0); // ext_info
+
+ DBGFrame2.addInt(rawCounter); // FRAME_RAWDATA ID
+ DBGFrame2.addInt(logString.length() + 1); // length of rawdata (+ null char)
+ DBGFrame2.addString(logString); // log string
+ DBGFrame2.addChar('\0'); // null char
+
+ // Add raw data first
+ DBGPacket.addFrame(DBGFrame2);
+ // Add command data
+ DBGPacket.addFrame(DBGFrame1);
+
+ if(proxy.getSocket().isClosed()) return;
+ DBGPacket.sendPacket(os);
+
+ waitResponse(1000);
+ flushAllPackets();
+ }
+
public void evalBlock(String evalString) throws IOException, DebugException {
PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_EVAL);
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)
DBGFrame2.addChar('\0'); // null char
// Add raw data first
- DBGPacket.addFrame(DBGFrame2);
+ DBGPacket.addFrame(DBGFrame2);
// Add command data
DBGPacket.addFrame(DBGFrame1);
public int readResponse() throws IOException {
int bytesToRead=0, nextFrame=0, i=0, cmdReceived=0, stackIndex=0;
+ boolean errorStack= false;
char[] dbg_header_struct_read= new char[16];
int[] dbg_header_struct= new int[4];
int[] dbg_bpl_tmp= new int[10];
int[] dbg_frame= new int[2];
int[] dbg_eval_tmp= new int[3];
int[] dbg_src_tree_tmp= new int[4];
+ int[] dbg_error_tmp= new int[2];
Vector rawList= new Vector();
Vector stackList= new Vector();
PHPStackFrame[] newStackList;
dbg_stack_new[2] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 8); // scope id
dbg_stack_new[3] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 12); // id of description string
- stackIndex++;
- if(dbg_stack_new[1] != 0) {
+ if(dbg_stack_new[1] != 0 && !errorStack) {
+ stackIndex++;
PHPStackFrame newStack= new PHPStackFrame(null, getModByNo(dbg_stack_new[1]), dbg_stack_new[0], stackIndex, getRawFrameData(entirePack, dbg_stack_new[3]), dbg_stack_new[1]);
stackList.add(newStack);
}
+ errorStack= false;
break;
case PHPDBGBase.FRAME_SOURCE:
break;
case PHPDBGBase.FRAME_RAWDATA:
break;
case PHPDBGBase.FRAME_ERROR:
+ errorStack= true;
+ dbg_error_tmp[0] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 0); // type /* type of error */
+ dbg_error_tmp[1] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 4); // imessage /* ID of error message */
+
+ String error= "\n";
+ switch(dbg_error_tmp[0]) {
+ case PHPDBGBase.E_ERROR:
+ error+= "[Error]";
+ break;
+ case PHPDBGBase.E_WARNING:
+ error+= "[Warning]";
+ break;
+ case PHPDBGBase.E_PARSE:
+ error+= "[Parse Error]";
+ break;
+ case PHPDBGBase.E_NOTICE:
+ error+= "[Notice]";
+ break;
+ case PHPDBGBase.E_CORE_ERROR:
+ error+= "[Core Error]";
+ break;
+ case PHPDBGBase.E_CORE_WARNING:
+ error+= "[Core Warning]";
+ break;
+ case PHPDBGBase.E_COMPILE_ERROR:
+ error+= "[Compile Error]";
+ break;
+ case PHPDBGBase.E_COMPILE_WARNING:
+ error+= "[Compile Warning]";
+ break;
+ case PHPDBGBase.E_USER_ERROR:
+ error+= "[User Error]";
+ break;
+ case PHPDBGBase.E_USER_WARNING:
+ error+= "[User Warning]";
+ break;
+ case PHPDBGBase.E_USER_NOTICE:
+ error+= "[User Notice]";
+ break;
+ default:
+ error+= "[Unexpected Error]";
+ break;
+ }
+ error+= ": ";
+ error+= new String(getRawFrameData(entirePack, dbg_error_tmp[1]));
+ // Remove '\0' char
+ if(error.length() > 0) error= error.substring(0, error.length() - 1);
+ error+= "\n";
+
+ PHPDebugCorePlugin.log(new DebugException(new Status(IStatus.WARNING, PHPDebugCorePlugin.PLUGIN_ID, IStatus.OK, error, null)));
+ // 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);
+ }
+ if(!stopOnError) {
+ if(lastCommand.equals(PHPDBGBase.DBGA_CONTINUE)) {
+ continueExecution();
+ } else if(lastCommand.equals(PHPDBGBase.DBGA_STEPINTO)) {
+ stepInto();
+ } else if(lastCommand.equals(PHPDBGBase.DBGA_STEPOUT)) {
+ stepOut();
+ } else if(lastCommand.equals(PHPDBGBase.DBGA_STEPOVER)) {
+ stepOver();
+ }
+ }
break;
case PHPDBGBase.FRAME_EVAL:
String evalString= new String("");
case PHPDBGBase.DBGC_STEPOVER_DONE:
case PHPDBGBase.DBGC_STEPOUT_DONE:
case PHPDBGBase.DBGC_EMBEDDED_BREAK:
+ case PHPDBGBase.DBGC_PAUSE:
BPUnderHit= 1;
newStackList= new PHPStackFrame[stackList.size()];
newStackList= (PHPStackFrame[]) stackList.toArray(newStackList);
DBGStackList= newStackList;
break;
case PHPDBGBase.DBGC_ERROR:
+ stackList.clear();
newStackList= new PHPStackFrame[stackList.size()];
newStackList= (PHPStackFrame[]) stackList.toArray(newStackList);
DBGStackList= newStackList;
break;
case PHPDBGBase.DBGC_SID:
break;
- case PHPDBGBase.DBGC_PAUSE:
- break;
}
}
-
return cmdReceived;
}