From: fvicente Date: Tue, 25 Nov 2003 03:24:07 +0000 (+0000) Subject: Show errors in console X-Git-Url: http://git.phpeclipse.com Show errors in console --- diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGBase.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGBase.java index a4ff01f..f72c52a 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGBase.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGBase.java @@ -65,6 +65,18 @@ public class PHPDBGBase { public static final int BPS_ENABLED = 2; public static final int BPS_UNRESOLVED = 0x100; + public static final int E_ERROR = (1<<0L); + public static final int E_WARNING = (1<<1L); + public static final int E_PARSE = (1<<2L); + public static final int E_NOTICE = (1<<3L); + public static final int E_CORE_ERROR = (1<<4L); + public static final int E_CORE_WARNING = (1<<5L); + public static final int E_COMPILE_ERROR = (1<<6L); + public static final int E_COMPILE_WARNING = (1<<7L); + public static final int E_USER_ERROR = (1<<8L); + public static final int E_USER_WARNING = (1<<9L); + public static final int E_USER_NOTICE = (1<<10L); + public PHPDBGBase() { } 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 72edfed..80682b8 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 @@ -14,12 +14,14 @@ import java.io.IOException; 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 { @@ -45,6 +47,8 @@ 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(); @@ -177,6 +181,13 @@ public class PHPDBGInterface { 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() { @@ -198,6 +209,7 @@ public class PHPDBGInterface { PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPINTO); if(proxy.getSocket().isClosed()) return; DBGPacket.sendPacket(os); + lastCommand= PHPDBGBase.DBGA_STEPINTO; } public void stepOver() throws IOException { @@ -205,6 +217,7 @@ public class PHPDBGInterface { PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOVER); if(proxy.getSocket().isClosed()) return; DBGPacket.sendPacket(os); + lastCommand= PHPDBGBase.DBGA_STEPOVER; } public void stepOut() throws IOException { @@ -212,6 +225,7 @@ public class PHPDBGInterface { PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOUT); if(proxy.getSocket().isClosed()) return; DBGPacket.sendPacket(os); + lastCommand= PHPDBGBase.DBGA_STEPOUT; } public void stopExecution() throws IOException { @@ -224,18 +238,9 @@ public class PHPDBGInterface { 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); @@ -252,6 +257,36 @@ public class PHPDBGInterface { 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); @@ -259,7 +294,7 @@ public class PHPDBGInterface { 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) @@ -267,7 +302,7 @@ public class PHPDBGInterface { DBGFrame2.addChar('\0'); // null char // Add raw data first - DBGPacket.addFrame(DBGFrame2); + DBGPacket.addFrame(DBGFrame2); // Add command data DBGPacket.addFrame(DBGFrame1); @@ -559,12 +594,14 @@ public class PHPDBGInterface { 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; @@ -606,11 +643,12 @@ public class PHPDBGInterface { 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; @@ -634,6 +672,77 @@ public class PHPDBGInterface { 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(""); @@ -724,12 +833,14 @@ public class PHPDBGInterface { 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; @@ -738,11 +849,8 @@ public class PHPDBGInterface { break; case PHPDBGBase.DBGC_SID: break; - case PHPDBGBase.DBGC_PAUSE: - break; } } - return cmdReceived; } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java index aecbdf0..feb5325 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGProxy.java @@ -52,6 +52,11 @@ public class PHPDBGProxy { public void stop() { phpLoop.setShouldStop(); if(DBGInt != null) DBGInt.setShouldStop(); + try { + getDebugTarget().getProcess().terminate(); + } catch (DebugException e) { + e.printStackTrace(); + } phpLoop.notifyWait(); } @@ -89,7 +94,7 @@ public class PHPDBGProxy { } public BufferedReader getReader() throws IOException { - if (reader == null) { + if (reader == null) { reader = new BufferedReader(new InputStreamReader(this.getSocket().getInputStream(), "ISO8859_1")); } return reader; @@ -147,7 +152,7 @@ public class PHPDBGProxy { phpLoop.start(); } - public void resume(PHPThread thread) { + public void resume() { try { DBGInt.continueExecution(); phpLoop.notifyWait(); @@ -157,6 +162,14 @@ public class PHPDBGProxy { } } + public void pause() { + try { + DBGInt.pauseExecution(); + } catch (IOException e) { + PHPDebugCorePlugin.log(e); + stop(); + } + } protected IPHPDebugTarget getDebugTarget() { return debugTarget; } @@ -337,5 +350,5 @@ public class PHPDBGProxy { //System.out.println("Socket loop finished."); } } - } + } } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/IPHPDebugTarget.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/IPHPDebugTarget.java index 65f5960..e51c63f 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/IPHPDebugTarget.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/IPHPDebugTarget.java @@ -20,5 +20,4 @@ public interface IPHPDebugTarget extends IDebugTarget { public void terminate(); public void setPHPDBGProxy(PHPDBGProxy phpDBGProxy); public void addThread(PHPThread phpThread); - } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDebugTarget.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDebugTarget.java index 4f8f8f6..52f2cd5 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDebugTarget.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDebugTarget.java @@ -35,11 +35,13 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE private IProcess process; private boolean isTerminated; + private boolean isSuspended; private ILaunch launch; private PHPThread[] threads; private PHPDBGProxy phpDBGProxy; public PHPDebugTarget(ILaunch launch, IProcess process) { + this.isSuspended = false; this.launch = launch; this.process = process; this.threads = new PHPThread[0]; @@ -125,21 +127,27 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE } public boolean canResume() { - return false; + if(isTerminated) return false; + return isSuspended; } public boolean canSuspend() { - return false; + if(isTerminated) return false; + return !isSuspended; } public boolean isSuspended() { - return false; + return isSuspended; } public void resume() throws DebugException { + this.getPHPDBGProxy().resume(); + isSuspended= false; } public void suspend() throws DebugException { + this.getPHPDBGProxy().pause(); + isSuspended= true; } public void breakpointAdded(IBreakpoint breakpoint) { @@ -238,6 +246,8 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE getPHPDBGProxy().stop(); } } + } else if (event.getKind() == DebugEvent.SUSPEND) { + getPHPDBGProxy().pause(); } } } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPThread.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPThread.java index 2aad677..2512b10 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPThread.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPThread.java @@ -109,7 +109,7 @@ public class PHPThread implements IThread { public void resume() throws DebugException { this.prepareForResume() ; - ((PHPDebugTarget) this.getDebugTarget()).getPHPDBGProxy().resume(this); + ((PHPDebugTarget) this.getDebugTarget()).getPHPDBGProxy().resume(); } /* diff --git a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java index 967d643..b32752f 100644 --- a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java +++ b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java @@ -30,6 +30,7 @@ public class InterpreterRunner { IProcess process = DebugPlugin.newProcess(launch, nativePHPProcess, renderLabel(configuration)); process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine); + return process ; } @@ -85,5 +86,5 @@ public class InterpreterRunner { protected String getDebugCommandLineArgument() { return "" ; - } + } } diff --git a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java index a1b5e43..58ccc37 100644 --- a/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java +++ b/net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java @@ -11,6 +11,8 @@ Contributors: **********************************************************************/ package net.sourceforge.phpdt.internal.launching; +import java.io.OutputStream; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus;