From 3276ac9f6830d2f6343a10fa29bd324908483fc1 Mon Sep 17 00:00:00 2001 From: robekras Date: Mon, 2 Jan 2012 19:55:11 +0000 Subject: [PATCH] 1) Although dbg will be dropped from being supported or bundled with PHPeclipse, some fixes. --- .../phpdt/internal/debug/core/PHPDBGInterface.java | 371 ++++++++++++++++---- .../phpdt/internal/debug/core/PHPDBGPacket.java | 2 + .../phpdt/internal/debug/core/PHPDBGProxy.java | 78 +++-- .../internal/debug/core/PHPDebugCorePlugin.java | 20 +- .../debug/core/model/PHPDBGEvalString.java | 84 ++++-- .../internal/debug/core/model/PHPDebugTarget.java | 14 +- .../internal/debug/core/model/PHPStackFrame.java | 128 ++++--- .../phpdt/internal/debug/core/model/PHPThread.java | 9 +- .../phpdt/internal/debug/core/model/PHPValue.java | 34 +- .../internal/debug/core/model/PHPVariable.java | 132 ++++---- 10 files changed, 592 insertions(+), 280 deletions(-) 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 4da1970..d2262ae 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 @@ -32,42 +32,47 @@ import org.eclipse.debug.core.DebugException; * */ public class PHPDBGInterface { - public boolean sessionEnded = false; - public int sessType = -1; - public int BPUnderHit = 0; - public String sessID = new String(); - - private int[] LastBPRead = new int[10]; - private Vector DBGBPList = new Vector(); - private Vector DBGVarList = new Vector(); + public boolean sessionEnded = false; + public int sessType = -1; + public int BPUnderHit = 0; + public String sessID = new String(); + + private int[] LastBPRead = new int[10]; + private Vector DBGBPList = new Vector(); + private Vector DBGVarList = new Vector(); private PHPStackFrame[] DBGStackList = new PHPStackFrame[0]; - private Vector DBGMods = new Vector(); // The module names and their numbers - private Vector stackListOld = new Vector(); - private BufferedReader in; - private OutputStream os; // The stream which goes to DBG - private boolean shouldStop = false; - private String evalRet = new String(""); - private int rawCounter = 1000; // An rawData frame ID counter - private PHPDBGProxy proxy = null; - //private int lastCmd = -1; - private int sid = 0; - private boolean stopOnError = false; - private char[] lastCommand = new char[4]; + private Vector DBGMods = new Vector(); // The module names and their numbers + private Vector stackListOld = new Vector(); + private BufferedReader dbgInput; + private OutputStream dbgOutput; // The stream which goes to DBG + private boolean shouldStop = false; + private String evalRet = new String(""); + private int rawCounter = 1000; // An rawData frame ID counter + private PHPDBGProxy proxy = null; +// private int lastCmd = -1; + private int sid = 0; + private boolean stopOnError = false; // If we the debugger should be relaunched after script termination + private boolean bRelaunch = true; + private char[] lastCommand = new char[4]; + private boolean bBusy = false; + private boolean bDebug = true; // Prints text to console for debugging purposes private static final String GlobalVariablesTitle = PHPDebugCorePlugin .getResourceString("VariablesView.GlobalVariables.title"); /** - * @param in The input stream (communication from DBG). - * @param os The output stream (communication to DBG). - * @param proxy The proxy to which this interface belongs. + * @param in The input stream (communication from DBG). + * @param os The output stream (communication to DBG). + * @param proxy The proxy to which this interface belongs. + * @param bRelaunch The debugger should be relaunched after PHP script termination */ - public PHPDBGInterface (BufferedReader in, OutputStream os, PHPDBGProxy proxy) { + public PHPDBGInterface (BufferedReader in, OutputStream os, PHPDBGProxy proxy, boolean bRelaunch) { DBGBPList.clear (); - this.in = in; - this.os = os; - this.proxy = proxy; + this.dbgInput = in; + this.dbgOutput = os; + this.proxy = proxy; + this.bRelaunch = bRelaunch; } /** @@ -120,16 +125,26 @@ public class PHPDBGInterface { PHPDBGPacket DBGPacket; // A DBG message packet PHPDBGFrame DBGFrame; // A frame within a DBG packet + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: getSourceTree"); + } + DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST); // A request for DBG DBGFrame = new PHPDBGFrame (PHPDBGBase.FRAME_SRC_TREE); // We want a source tree from DBG DBGPacket.addFrame (DBGFrame); // Add the 'what we want' to the DBG packet if (proxy.getSocket ().isClosed ()) { // Can we communiate with DBG? + bBusy = false; return; // No } - DBGPacket.sendPacket (os); // Send the request to DBG + DBGPacket.sendPacket (dbgOutput); // Send the request to DBG waitResponse (1000); // Wait for the DBG response (1 second) flushAllPackets (); // Read and process the response from DBG @@ -183,6 +198,15 @@ public class PHPDBGInterface { PHPDBGFrame DBGFrame3; int modNo; + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: setBreakpoint"); + } + DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST); DBGFrame1 = new PHPDBGFrame (PHPDBGBase.FRAME_BPS); DBGFrame2 = new PHPDBGFrame (PHPDBGBase.FRAME_RAWDATA); @@ -240,10 +264,11 @@ public class PHPDBGInterface { DBGPacket.addFrame (DBGFrame1); // Second add command data if (proxy.getSocket ().isClosed ()) { // Can we communiate with DBG? + bBusy = false; return 0; // No } - DBGPacket.sendPacket (os); // Send the request to DBG + DBGPacket.sendPacket (dbgOutput); // Send the request to DBG clearLastBP (); @@ -281,13 +306,17 @@ public class PHPDBGInterface { public void continueExecution () throws IOException { PHPDBGPacket DBGPacket; + if (bDebug) { + System.out.println ("PHPDBGInterface: continueExecution"); + } + BPUnderHit = 0; DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_CONTINUE); if (proxy.getSocket ().isClosed ()) { // Can we communiate with DBG? return; // No } - DBGPacket.sendPacket (os); // Send the request to DBG + DBGPacket.sendPacket (dbgOutput); // Send the request to DBG lastCommand = PHPDBGBase.DBGA_CONTINUE; // Store the info about the command we sent } @@ -298,13 +327,17 @@ public class PHPDBGInterface { public void pauseExecution () throws IOException { PHPDBGPacket DBGPacket; + if (bDebug) { + System.out.println ("PHPDBGInterface: pauseExecution"); + } + DBGPacket = new PHPDBGPacket (PHPDBGBase.IntToChar4 (PHPDBGBase.DBGC_PAUSE)); if (proxy.getSocket ().isClosed ()) { // Can we communiate with DBG? return; // No } - DBGPacket.sendPacket (os); // Send the request to DBG + DBGPacket.sendPacket (dbgOutput); // Send the request to DBG } /** @@ -344,55 +377,106 @@ public class PHPDBGInterface { /** * */ - public void stepInto () throws IOException { + public boolean stepInto () throws IOException { PHPDBGPacket DBGPacket; + if (bBusy) { + if (bDebug) { + System.out.println ("PHPDBGInterface: stepOver vetoed"); + } + } + + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: stepInto"); + } + BPUnderHit = 0; DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_STEPINTO); if (proxy.getSocket ().isClosed ()) { // Can we communiate with DBG? - return; // No + return false; // No } - DBGPacket.sendPacket (os); // Send the request to DBG + DBGPacket.sendPacket (dbgOutput); // Send the request to DBG lastCommand = PHPDBGBase.DBGA_STEPINTO; // Store the info about the command we sent + + return true; } /** * */ - public void stepOver () throws IOException { + public boolean stepOver () throws IOException { PHPDBGPacket DBGPacket; + if (bBusy) { + if (bDebug) { + System.out.println ("PHPDBGInterface: stepOver vetoed"); + } + } + + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: stepOver"); + } + BPUnderHit = 0; DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_STEPOVER); if (proxy.getSocket ().isClosed ()) { // Can we communiate with DBG? - return; // No + return false; // No } - DBGPacket.sendPacket (os); // Send the request to DBG + DBGPacket.sendPacket (dbgOutput); // Send the request to DBG lastCommand = PHPDBGBase.DBGA_STEPOVER; // Store the info about the command we sent + + return true; } /** * */ - public void stepOut () throws IOException { + public boolean stepOut () throws IOException { PHPDBGPacket DBGPacket; + if (bBusy) { + if (bDebug) { + System.out.println ("PHPDBGInterface: stepOver vetoed"); + } + } + + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: stepOut"); + } + BPUnderHit = 0; DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_STEPOUT); if (proxy.getSocket ().isClosed ()) { // Can we communiate with DBG? - return; // No + return false; // No } - DBGPacket.sendPacket (os); // Send the request to DBG + DBGPacket.sendPacket (dbgOutput); // Send the request to DBG lastCommand = PHPDBGBase.DBGA_STEPOUT; // Store the info about the command we sent + + return true; } /** @@ -423,6 +507,7 @@ public class PHPDBGInterface { public synchronized Vector getVariables(PHPStackFrame stack) throws IOException, DebugException { if (DBGStackList.length == 0) { DBGVarList.clear(); + return DBGVarList; } @@ -433,6 +518,7 @@ public class PHPDBGInterface { // Also note that 2.13.1 doesn't return $this in class context. // (You can inspect $this in Expressions View. And once it is shown, 2.13.1 comes to return $this.) Vector globalList = getVariables(DBGStackList[DBGStackList.length - 1], global_scope_id); + if (!globalList.isEmpty()) { // remove unresolved '$this=?' variable removeUnresolvedThisVar(globalList); @@ -443,20 +529,22 @@ public class PHPDBGInterface { } int scopeID = stack.getScopeID(); - if (!globalList.isEmpty() - && ((DBGStackList.length == 1) - || (scopeID == PHPDBGBase.CURLOC_SCOPE_ID + 1))) { + + if (!globalList.isEmpty () && + ((DBGStackList.length == 1) || (scopeID == PHPDBGBase.CURLOC_SCOPE_ID + 1))) { // 'main()' stackframe PHPVariable var = (PHPVariable) globalList.get(0); - PHPValue val = (PHPValue) var.getValue(); - DBGVarList = val.getChildVariables(); - return DBGVarList; + PHPValue val = (PHPValue) var.getValue(); + + DBGVarList = val.getChildVariables(); - } else if (scopeID == PHPDBGBase.CURLOC_SCOPE_ID) { + return DBGVarList; + } + else if (scopeID == PHPDBGBase.CURLOC_SCOPE_ID) { // current stackframe DBGVarList = getVariables(stack, PHPDBGBase.CURLOC_SCOPE_ID); - - } else { + } + else { // back-trace stackframe //DBGVarList = getVariables(stack, scopeID); //removeUnresolvedThisVar(DBGVarList); @@ -489,12 +577,27 @@ public class PHPDBGInterface { } /** - * + * */ private Vector getVariables(PHPStackFrame stack, int scope_id) throws IOException { PHPDBGPacket DBGPacket = new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST); PHPDBGFrame DBGFrame1 = new PHPDBGFrame(PHPDBGBase.FRAME_EVAL); + if (bBusy) { + if (bDebug) { + System.out.println ("PHPDBGInterface: getVariables vetoed"); + } + } + + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: getVariables"); + } + DBGFrame1.addInt(0); DBGFrame1.addInt(scope_id); @@ -502,36 +605,44 @@ public class PHPDBGInterface { evalRet = ""; if (proxy.getSocket().isClosed()) { + bBusy = false; return new Vector(); } - DBGPacket.sendPacket(os); + + DBGPacket.sendPacket(dbgOutput); waitResponse(1000); flushAllPackets(); + bBusy = false; // Already done in flushAllPackets () + PHPDBGEvalString evalStr = new PHPDBGEvalString(stack, evalRet); return evalStr.getVariables(); } /** * Remove unresolved $this variable - * + * * DBG returns $this=? in function's or intermediate stackframes. * (In current method's stackframe, DBG returns $this=classname) - * + * * @param varList */ private void removeUnresolvedThisVar(Vector varList) { if (varList.size() > 0) { - PHPVariable var = (PHPVariable) varList.get(0); - PHPValue val = (PHPValue) var.getValue(); - Vector workList = val.getChildVariables(); + PHPVariable var = (PHPVariable) varList.get(0); + PHPValue val = (PHPValue) var.getValue(); + Vector workList = val.getChildVariables (); + for (int i = 0; i < workList.size(); i++) { PHPVariable workvar = (PHPVariable) workList.get(i); - if (workvar.getName().equals("$this")) { - String workval = ((PHPValue) workvar.getValue()).getValueString(); - if (workval.equals("?") || workval.equals("NULL")) { - workList.remove(i); + + if (workvar.getName().equals ("$this")) { + String workval = ((PHPValue) workvar.getValue ()).getValueString (); + + if (workval.equals ("?") || + workval.equals ("NULL")) { + workList.remove (i); } break; } @@ -548,6 +659,15 @@ public class PHPDBGInterface { PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_LOG); PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA); + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: log"); + } + rawCounter++; DBGFrame1.addInt(rawCounter); // ilog DBGFrame1.addInt(1); // type @@ -567,10 +687,11 @@ public class PHPDBGInterface { DBGPacket.addFrame(DBGFrame1); if (proxy.getSocket ().isClosed ()) { // Do we have a socket for DBG communication? + bBusy = false; return; // No, then leave here } - DBGPacket.sendPacket(os); + DBGPacket.sendPacket(dbgOutput); waitResponse(1000); flushAllPackets(); @@ -581,6 +702,15 @@ public class PHPDBGInterface { PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_EVAL); PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA); + while (bBusy) { + } + + bBusy = true; + + if (bDebug) { + System.out.println ("PHPDBGInterface: evalBlock"); + } + rawCounter++; DBGFrame1.addInt(rawCounter); // istr = raw data ID //DBGFrame1.addInt(1); // scope_id = -1 means current location, 0 never used, +1 first depth @@ -603,9 +733,11 @@ public class PHPDBGInterface { DBGPacket.addFrame(DBGFrame1); if (proxy.getSocket().isClosed()) { // Do we have a socket for DBG communication? + bBusy = false; return null; // No, then leave here } - DBGPacket.sendPacket(os); + + DBGPacket.sendPacket(dbgOutput); waitResponse(1000); flushAllPackets(); @@ -743,6 +875,7 @@ public class PHPDBGInterface { stackFrameOld.setAvailable (true); // We found the new stackframe in the list of old stack frames stackFrameOld.setIndex (stackFrameNew.getIndex ()); stackFrameOld.setScopeID(stackFrameNew.getScopeID()); + return true; // The stackframe was found in the list } } @@ -773,7 +906,7 @@ public class PHPDBGInterface { if (isStackFrameInList (stackFrameNew, oldList)) { // Is this stackframe in the list stackFrameNew.setAvailable (true); // // - break; +// break; } } } @@ -808,6 +941,10 @@ public class PHPDBGInterface { PHPStackFrame stackFrameOld; PHPStackFrame[] newStackList; + if (bDebug) { + System.out.println ("PHPDBGInterface: updateStackFrameList Start"); + } + markIdenticalStackFrames (stackListOld, stackList); // Check whether the newly send stack frames can be found in the list // of old stack frames @@ -854,6 +991,10 @@ public class PHPDBGInterface { newStackList = new PHPStackFrame[stackListOld.size ()]; newStackList = (PHPStackFrame[]) stackListOld.toArray (newStackList); DBGStackList = newStackList; + + if (bDebug) { + System.out.println ("PHPDBGInterface: updateStackFrameList End"); + } } /** @@ -880,6 +1021,10 @@ public class PHPDBGInterface { Vector rawList = new Vector(); Vector stackList = new Vector(); // Intermediate stacklist which is build up in FRAME_STACK frame + if (bDebug) { + System.out.println ("PHPDBGInterface: readResponse start"); + } + rawList.clear (); stackList.clear (); @@ -891,6 +1036,11 @@ public class PHPDBGInterface { dbg_header_struct[3] = PHPDBGBase.Char4ToInt (dbg_header_struct_read, 12); // Bytes within this block if (dbg_header_struct[0] != 0x5953) { // Check DBG sync bytes + if (bDebug) { + System.out.println ("PHPDBGInterface: readResponse. Wrong sync"); + } + + bBusy = false; return 0; // Wrong header } @@ -903,10 +1053,15 @@ public class PHPDBGInterface { if (bytesToRead > 0) { // If there is something within the frame if (readInput (entirePack, bytesToRead) < bytesToRead) { // Read the frame into the buffer + if (bDebug) { + System.out.println ("PHPDBGInterface: readResponse. Did not read enough"); + } + + bBusy = false; return 0; // We did not read enough bytes, error } } - + nextFrame = 0; // Start with the first frame while (nextFrame < bytesToRead) { // As long as we have something within this block @@ -915,6 +1070,11 @@ public class PHPDBGInterface { nextFrame += 8; // The next read position if (dbg_frame[1] == 0) { // Something within the frame? + if (bDebug) { + System.out.println ("PHPDBGInterface: readResponse. Nothing within the frame"); + } + + bBusy = false; return 0; // Nothing to read, error } @@ -1127,8 +1287,15 @@ public class PHPDBGInterface { break; case PHPDBGBase.DBGC_END: - sessionEnded = true; - this.proxy.setTerminated(); + if (bRelaunch) { + continueExecution (); // Inform dbg that we want to continue execution + proxy.updateView (); // Sent a change event and create thread event to eclipse core + updateStackFrameList (stackList); // ??? Just a try + } + else { + sessionEnded = true; + proxy.setTerminated (); + } break; case PHPDBGBase.DBGC_BREAKPOINT: @@ -1158,6 +1325,12 @@ public class PHPDBGInterface { } } + if (bDebug) { + System.out.println ("PHPDBGInterface: readResponse finish, received: " + cmdReceived); + } + + bBusy = false; + return cmdReceived; // Return the command we received with this block } @@ -1179,14 +1352,51 @@ public class PHPDBGInterface { */ private int readInput (char[] buffer, int bytes) throws IOException { int bytesRead = 0; // Reset the bytes read counter + int nRetry = 0; // Retry counter + + if (bDebug) { + System.out.println ("PHPDBGInterface: readInput " + bytes); + } - for (int i = 0; i < bytes; i++) { // For the number of bytes we should read - if (in.ready ()) { // If input stream is ready for reading - buffer[i] = (char) (in.read () & 0x00FF); // Read a char and store only the least significant 8-bits + for (int i = 0; i < bytes;) { // For the number of bytes we should read + if (dbgInput.ready ()) { // If input stream is ready for reading + nRetry = 0; // Reset the retry counter + buffer[i] = (char) (dbgInput.read () & 0x00FF); // Read a char and store only the least significant 8-bits bytesRead++; // Increment the bytes read counter + i++; } else { // Input stream is not ready - break; // Break the loop + nRetry++; // Increment the retry counter + + if (nRetry > 10) { // If nothing received within 100 retries + if (i > 0) { + if (bDebug) { + System.out.println ("PHPDBGInterface: Too many retries without receiving something"); + } + } + break; // we break the loop + } + + synchronized (dbgInput) { + if (i > 0) { + if (bDebug) { + System.out.println ("PHPDBGInterface: retry: " + nRetry + " Wait for something to receive, received: " + i + " need " + bytes); + } + } + try { + dbgInput.wait (10); // wait 5 ms maximum for something to receive + } catch (InterruptedException e) { + } + } + } + } + + if (bytesRead > 0) { + if (bytes != bytesRead) { + if (bDebug) { + System.out.println ("PHPDBGInterface: readInput: Possible error: not enough bytes in buffer should read: " + bytes + + " actually read: " + bytesRead); + } } } @@ -1207,18 +1417,33 @@ public class PHPDBGInterface { * @return - true if something was received from DBG * - false if nothing was send from DBG within the given time * + * This method has been a busy wait loop. It was changed to use + * a non busy wait to avoid a heavy load after automatic relaunch + * after script termination + * */ public boolean waitResponse (long milliseconds) throws IOException { long timeout; + if (bDebug) { + System.out.println ("PHPDBGInterface: waitResponse " + milliseconds); + } + timeout = System.currentTimeMillis () + milliseconds; // Calculate the system time till we wait. while (System.currentTimeMillis () < timeout) { // Is waiting time running out? - if (in.ready () || shouldStop) { // No, so did we get something or should we stop now - break; // Yes, break the waiting + synchronized (dbgInput) { + try { + dbgInput.wait (5); // wait 5 ms maximum for something to receive + } catch (InterruptedException e) { + } + } + + if (dbgInput.ready () || shouldStop) { // If something is received of if we should stop now + break; // break the waiting loop } } - return in.ready (); // true if we got something from DBG + return dbgInput.ready (); // true if we got something from DBG } } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGPacket.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGPacket.java index 313f57d..337a556 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGPacket.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDBGPacket.java @@ -45,6 +45,8 @@ public class PHPDBGPacket { int i; PHPDBGFrame frame; +// System.out.println ("PHPDBGPacket: sendPacket"); + PHPDBGBase.copyCharsTo (packetHeader, PHPDBGBase.IntToChar4 (packetSize), 4, 12); try { 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 192cff0..1001de9 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 @@ -48,6 +48,7 @@ public class PHPDBGProxy { private int port; private boolean remote; private boolean pathtranslation; + private boolean bRelaunch; // Relaunch the debugger after script termination private Map pathmap; private IPath remoteSourcePath; @@ -56,28 +57,39 @@ public class PHPDBGProxy { public PHPDBGProxy () { thisProxy = this; } - + /** * updateView * Clean up the view, but leave the Debug session running. * added by ed_mann */ -// public void updateView(){ -// getDebugTarget().updateThreads(PHPMainThread); -// } - + public void updateView () { +/* + try { + server.close (); + server = null; + start (); + } + catch (IOException e) { + } +*/ + getDebugTarget ().updateThreads (PHPMainThread); + } + /** * @param remote * @param remoteSourcePath * @param pathTranslate * @param paths + * @param */ - public PHPDBGProxy (boolean remote, String remoteSourcePath, boolean pathTranslate, Map paths) { + public PHPDBGProxy (boolean remote, String remoteSourcePath, boolean pathTranslate, Map paths, boolean bRelaunchOnScriptTermination) { thisProxy = this; this.remote = remote; this.remoteSourcePath = new Path (remoteSourcePath); this.pathmap = paths; this.pathtranslation = pathTranslate; + this.bRelaunch = bRelaunchOnScriptTermination; } /** @@ -108,7 +120,7 @@ public class PHPDBGProxy { phpLoop.notifyWait (); } - + public void setTerminated () { try { PHPMainThread.terminate (); @@ -137,15 +149,15 @@ public class PHPDBGProxy { /** * Find a free unused port between 10001 and 10101 if the current debug session * is for remote debugging, and a unused port 7869 if it is used as non remote debugging. - * + * * For remote debugging the used port is submitted with the URL. * E.g. http://localhost/index.php?DBGSESSID=1@localhost:10001 * For non remote debugging (if PHPeclipse used e.g. php cli directly) no port * can be submitted by parameter, and only the default port (7869) can be used. - * - * @note: The free dbg version doesn't allow to set the appropriate port within php.ini! - * - * + * + * @note: The free dbg version doesn't allow to set the appropriate port within php.ini! + * + * */ protected void createServerSocket () { if (this.remote) { @@ -154,7 +166,7 @@ public class PHPDBGProxy { else { port = SocketUtil.findUnusedLocalPort ("localhost", 7869, 7869); // Get the first free port in the range from 7869 to 7869 } - + if (port == -1) { // Did we get a free port? PHPDebugCorePlugin.log (5, "Cannot find free port!!!!"); // No, output a error message @@ -195,7 +207,7 @@ public class PHPDBGProxy { public PHPDBGInterface getDBGInterface () { return DBGInt; } - + /** * Give back a buffered input stream for the socket which is * linked with this proxy @@ -284,7 +296,7 @@ public class PHPDBGProxy { localPath = new Path (local); // Get the remote/server side path of the mapping if (localPath.isPrefixOf (filename)) { // Starts the remote/server side file path with the remote/server side mapping path - // dann prefix abh�ngen und den remote path davorh�gen + // dann prefix abhängen und den remote path davorhägen newpath = filename.removeFirstSegments (localPath.matchingFirstSegments (filename)); newpath = remotePath.append (newpath); path = newpath.toString (); @@ -334,17 +346,17 @@ public class PHPDBGProxy { // bpNo= DBGInt.addBreakpoint(phpLBP.getMarker().getResource().getLocation().toOSString(), phpLBP.getLineNumber()); if (phpLBP.isConditionEnabled ()) { bpNo = DBGInt.addBreakpoint (MapPath(phpLBP), - phpLBP.getLineNumber(), + phpLBP.getLineNumber(), phpLBP.getHitCount(), phpLBP.getCondition ()); } else { bpNo = DBGInt.addBreakpoint (MapPath(phpLBP), - phpLBP.getLineNumber(), + phpLBP.getLineNumber(), phpLBP.getHitCount(), ""); } - + phpLBP.setDBGBpNo(bpNo); } } catch (IOException e) { @@ -439,14 +451,14 @@ public class PHPDBGProxy { /** * Is called by the DebuggerRunner - * + * * @param debugTarget */ public void setDebugTarget (PHPDebugTarget debugTarget) { this.debugTarget = debugTarget; debugTarget.setPHPDBGProxy(this); } - + /** * This method is called by a stackframe. * It reads the variables from PHP via DBG @@ -487,8 +499,9 @@ public class PHPDBGProxy { public void readStepOverEnd (PHPStackFrame stackFrame) { try { - DBGInt.stepOver(); - phpLoop.notifyWait(); + if (DBGInt.stepOver ()) { + phpLoop.notifyWait(); + } } catch (Exception e) { PHPDebugCorePlugin.log(e); } @@ -496,8 +509,9 @@ public class PHPDBGProxy { public void readStepReturnEnd (PHPStackFrame stackFrame) { try { - DBGInt.stepOut(); - phpLoop.notifyWait(); + if (DBGInt.stepOut ()) { + phpLoop.notifyWait(); + } } catch (Exception e) { PHPDebugCorePlugin.log(e); } @@ -505,14 +519,15 @@ public class PHPDBGProxy { public void readStepIntoEnd (PHPStackFrame stackFrame) { try { - DBGInt.stepInto(); - phpLoop.notifyWait(); + if (DBGInt.stepInto ()) { + phpLoop.notifyWait(); + } } catch (Exception e) { PHPDebugCorePlugin.log(e); } } - /* + /** * public PHPStackFrame[] readFrames(PHPThread thread) { //try { //this.println("th " + thread.getId() + " ; f "); //return new * FramesReader(getMultiReaderStrategy()).readFrames(thread); return null; //} catch (IOException e) { // * PHPDebugCorePlugin.log(e); // return null; //} @@ -546,7 +561,7 @@ public class PHPDBGProxy { shouldStop = false; this.setName ("PHPDebuggerLoop"); } - + /** * */ @@ -620,9 +635,10 @@ public class PHPDBGProxy { server.setSoTimeout(1); // ??? } - newDBGInt = new PHPDBGInterface (getReader (newSocket), // Create a new interface - newSocket.getOutputStream (), - thisProxy); + newDBGInt = new PHPDBGInterface (getReader (newSocket), // The input buffer (frames from dbg) + newSocket.getOutputStream (), // The output buffer (frames to dbg) + thisProxy, + bRelaunch); // Whether the debugger should be relaunched after script termination newDBGInt.waitResponse (1000); // Wait for the initial DBG response newDBGInt.flushAllPackets (); // Read and process the DBG response diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDebugCorePlugin.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDebugCorePlugin.java index f2c34da..e6dcd86 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDebugCorePlugin.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/PHPDebugCorePlugin.java @@ -95,16 +95,16 @@ public class PHPDebugCorePlugin extends AbstractUIPlugin { /** * The constructor. */ -// public PHPDebugCorePlugin() { -// super(); -// plugin = this; -// try { -// resourceBundle = ResourceBundle -// .getBundle("net.sourceforge.phpdt.internal.debug.core.debugresources"); //$NON-NLS-1$ -// } catch (MissingResourceException x) { -// resourceBundle = null; -// } -// } + public PHPDebugCorePlugin() { + super(); + plugin = this; + try { + resourceBundle = ResourceBundle + .getBundle("net.sourceforge.phpdt.internal.debug.core.debugresources"); //$NON-NLS-1$ + } catch (MissingResourceException x) { + resourceBundle = null; + } + } public java.util.ResourceBundle getResourceBundle() { return resourceBundle; diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java index 1439ed9..2f4953c 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java @@ -395,30 +395,49 @@ public class PHPDBGEvalString { * @param var_list * @param startIdx */ - private boolean ParseEvalRef(String name, PHPVariable parent, Vector list, - Vector var_list, boolean isSoftRef, int startIdx) - throws DebugException { - int v; + private boolean ParseEvalRef (String name, PHPVariable parent, Vector list, + Vector var_list, boolean isSoftRef, int startIdx + ) throws DebugException { + int v; // The ref ID (index into vector list) PHPVariable item; PHPVariable var_item; - v = ExtractInt(':', ';', startIdx); - item = new PHPVariable(fStackFrame, name, parent, "", - isSoftRef ? PHPValue.PEVT_SOFTREF : PHPValue.PEVT_REF, null); - v--; // ref ID is 1-based, EvalList is 0-based + v = ExtractInt (':', ';', startIdx); + item = new PHPVariable (fStackFrame, name, parent, "", + isSoftRef ? PHPValue.PEVT_SOFTREF : PHPValue.PEVT_REF, null); + v--; // ref ID is 1-based, EvalList is 0-based - if ((var_list == null) || (v < 0) || (v >= var_list.size())) { + if ((var_list == null) || + (v < 0) || (v >= var_list.size ())) { // Check ref ID (index) bounds //item.ref = item; // self-resolving return true; - } else { - var_item = (PHPVariable) var_list.get(v); + } + else { +// This is the original code without the problems of stackframe overflow + var_item = (PHPVariable) var_list.get (v); // Get the variable from the list of all variables + + try { + item.setValue (var_item.getValue ()); + item.setReferenceType (var_item.getReferenceType ()); +// ((PHPValue) item.getValue ()).setParent (item); // Set the new variable as parent for all child variables + } catch (DebugException e) { + // TODO Auto-generated catch block + e.printStackTrace (); + } + + list.add (item); + +/************* + * this code produces a stackframe overflow if the reference contains loop references + var_item = (PHPVariable) var_list.get (v); // Get the referenced variable from the list of variables + + PHPValue new_val = (PHPValue) var_item.getValue (); - PHPValue new_val = (PHPValue) var_item.getValue(); if (isSoftRef) { // expand reduced structure to full tree // each value must have its appropriate parent try { - new_val = copyItems(new_val); + new_val = copyItems (new_val, 0); // Copy the child variables to the new referenced variable } catch (CloneNotSupportedException e) { // never occurs } @@ -428,14 +447,15 @@ public class PHPDBGEvalString { //item.setValue(var_item.getValue()); //item.setReferenceType(var_item.getReferenceType()); //((PHPValue) item.getValue()).setParent(item); - item.setValue(new_val); - item.setReferenceType(var_item.getReferenceType()); - new_val.setParent(item); + item.setValue (new_val); + item.setReferenceType (var_item.getReferenceType ()); + new_val.setParent (item); } catch (DebugException e) { // never occurs } - list.add(item); + list.add (item); + */ } return true; @@ -552,21 +572,37 @@ public class PHPDBGEvalString { /* * Copy referenced items tree + * + * @note We have to take care of recursion. We have to stop on recursion else + * we get a stack overflow! + * + * @param val The variable for which we build the tree of all childs */ - private PHPValue copyItems(PHPValue val) throws CloneNotSupportedException { - PHPValue newVal = (PHPValue) val.clone(); - Vector vars = newVal.getChildVariables(); - Vector newVars = new Vector(); + private PHPValue copyItems (PHPValue val, int nDepth) throws CloneNotSupportedException { + PHPValue newVal = (PHPValue) val.clone(); + Vector vars = newVal.getChildVariables(); + Vector newVars = new Vector(); + + nDepth++; + + if (nDepth >= 10) { // A very quick and very dirty way to avoid stack overflow + return newVal; + } + for (int i = 0; i < vars.size(); i++) { PHPVariable newVar = (PHPVariable) ((PHPVariable) vars.get(i)).clone(); + try { - newVar.setValue(copyItems((PHPValue) newVar.getValue())); + newVar.setValue (copyItems ((PHPValue) newVar.getValue(), nDepth)); } catch (DebugException e) { // never occurs } - newVars.add(newVar); + + newVars.add (newVar); } - val.setVariables(newVars); + + val.setVariables (newVars); + return newVal; } 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 00f460a..3f64b31 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 @@ -40,18 +40,14 @@ import org.eclipse.ui.model.IWorkbenchAdapter; public class PHPDebugTarget extends PHPDebugElement implements IPHPDebugTarget, ILaunchListener, IDebugEventSetListener { - private IProcess process; - - private ILaunch launch; - - private PHPThread[] threads = new PHPThread[0]; - - private PHPDBGProxy phpDBGProxy; + private IProcess process; + private ILaunch launch; + private PHPThread[] threads = new PHPThread[0]; + private PHPDBGProxy phpDBGProxy; private class State { private boolean isTerminated = false; - - private boolean isSuspended = false; + private boolean isSuspended = false; boolean isTerminated() { return isTerminated; diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java index 245dc76..7bede78 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPStackFrame.java @@ -11,6 +11,7 @@ Contributors: **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core.model; +import java.util.Arrays; import java.util.Collections; import java.util.Vector; @@ -33,17 +34,19 @@ import org.eclipse.debug.core.model.IVariable; public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Comparable { private PHPThread thread; // The thread to which this stackframe belongs - private String file; // The file name??? + private String file; // The file name??? private int lineNumber; private int index; private int modno; + private PHPVariable[] variables; // private int scope_id; // scope id - private Vector varList; // Variables list - private String description; // The source file name with the full path on target/remote system + private Vector varList; // Variables list + private String description; // The source file name with the full path on target/remote system private boolean fUpToDate; // Indicates whether the variable list within this stackframe is // up-to-date private boolean fAvailable; // Needed when updating the stackframe list, shows whether the stackframe // is within the list which was received from dbg + private boolean fDebug = true; /** * @@ -55,19 +58,19 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * @param modno * @param scope_id */ - public PHPStackFrame(PHPThread thread, String file, int line, int index, - String desc, int modno, int scope_id) { - super(null); - - this.lineNumber = line; - this.index = index; - this.file = file; - this.thread = thread; + public PHPStackFrame (PHPThread thread, String file, int line, int index, + String desc, int modno, int scope_id) { + super (null); + + this.lineNumber = line; + this.index = index; + this.file = file; + this.thread = thread; this.description = desc; - this.modno = modno; - this.scope_id = scope_id; - this.varList = new Vector(); - this.fUpToDate = false; + this.modno = modno; + this.scope_id = scope_id; + this.varList = new Vector(); + this.fUpToDate = false; } // /** @@ -88,7 +91,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa // } /** - * + * * @return scope id */ public int getScopeID() { @@ -96,7 +99,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa } /** - * + * */ public void setScopeID(int scope_id) { this.scope_id = scope_id; @@ -187,7 +190,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * * TODO Check where this recursion can come from. * Whether this back reference is legal or a bug. - * + * * Typically $GLOBALS contains $GLOBALS * * @param var @@ -197,17 +200,17 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa *
  • true if the PHPValue is * */ - private boolean hasRecursion(PHPVariable var) { + private boolean hasRecursion (PHPVariable var) { PHPVariable parentVar; PHPValue val; - val = (PHPValue) var.getValue(); // Get the PHPValue from the current PHPVariable + val = (PHPValue) var.getValue (); // Get the PHPValue from the current PHPVariable while (var != null) { // As long as we have PHPVariable - parentVar = var.getParent(); // Get the parent PHPVariable + parentVar = var.getParent (); // Get the parent PHPVariable if (parentVar != null) { // Is there a parent? - if (parentVar.getValue().equals(val)) { // Get the PHPValue for the parent PHPVariable and check + if (parentVar.getValue ().equals (val)) { // Get the PHPValue for the parent PHPVariable and check // whether it is the same return true; // Return, if we have recursion } @@ -238,7 +241,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa * @param varListOld The 'static' list of variables which are to be updated. * @param varListNew The new list of (current) variables from DBG. */ - private void updateVariableList(Vector varListOld, Vector varListNew) { + private void updateVariableList (Vector varListOld, Vector varListNew) { PHPVariable varOld; // The variable from the 'static' list PHPVariable varNew; // The variable from the DBG list PHPValue valOld; // The value of the current variable from 'static' list @@ -257,21 +260,24 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa varOld = (PHPVariable) varListOld.get(o); // Get the static variable if (varNew.getName().equals(varOld.getName())) { // Did we found the variable within the 'static' list? - valOld = (PHPValue) varOld.getValue(); // Get the value from 'static' - valNew = (PHPValue) varNew.getValue(); // Get the value from DBG + valOld = (PHPValue) varOld.getValue (); // Get the value from 'static' + valNew = (PHPValue) varNew.getValue (); // Get the value from DBG try { if (valOld.hasVariables() || // If the 'static' value has child variables - valNew.hasVariables()) { // or if the DBG value has child variables - if (!hasRecursion(varOld) && !hasRecursion(varNew)) { // Both branches should not have a recursion - updateVariableList(valOld.getChildVariables(), // Update the variable list for the child variables - valNew.getChildVariables()); + valNew.hasVariables()) { // or if the DBG value has child variables + if (!hasRecursion(varOld) && + !hasRecursion(varNew)) { // Both branches should not have a recursion + updateVariableList ( + valOld.getChildVariables (), // Update the variable list for the child variables + valNew.getChildVariables ()); } } - if (!valOld.getValueString().equals( - valNew.getValueString())) { // Has the value changed? - valOld.setValueString(valNew.getValueString()); // Yes, set the 'static' value (variable) to the new value - varOld.setValueChanged(true); // and set the 'has changed' flag, so that the variable view + + if (!valOld.getValueString ().equals ( + valNew.getValueString ())) { // Has the value changed? + valOld.setValueString (valNew.getValueString ()); // Yes, set the 'static' value (variable) to the new value + varOld.setValueChanged (true); // and set the 'has changed' flag, so that the variable view // could show the user the changed status with a different // color } @@ -318,13 +324,20 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa */ public IVariable[] getVariables() throws DebugException { if (!fUpToDate) { - resetHasChangedInfo(varList); - updateVariableList(varList, this.getPHPDBGProxy().readVariables(this)); + resetHasChangedInfo (varList); + updateVariableList (varList, this.getPHPDBGProxy ().readVariables (this)); fUpToDate = true; - Collections.sort(varList, new PHPVariableComparator()); + + variables = (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]); + Arrays.sort (variables, new PHPVariableComparator ()); +/* + Collections.sort (varList, new PHPVariableComparator ()); + */ } - return (PHPVariable[]) varList.toArray(new PHPVariable[varList.size()]); +// return (PHPVariable[]) varList.toArray (new PHPVariable[varList.size ()]); + + return variables; // Give the array back to user interface } /** @@ -336,19 +349,21 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa int i; for (i = 0; i < varList.size(); i++) { // For all variables - variable = (PHPVariable) varList.get(i); // Get the variable - value = (PHPValue) variable.getValue(); // Get the value of the variable + variable = (PHPVariable) varList.get (i); // Get the variable + value = (PHPValue) variable.getValue (); // Get the value of the variable try { - if (value.hasVariables()) { // Does the variable/value have children - if (!hasRecursion(variable)) { // Don't follow recursive variable/values - PHPVariable var = findVariable(value.getChildVariables(), varname); + if (value.hasVariables ()) { // Does the variable/value have children + if (!hasRecursion (variable)) { // Don't follow recursive variable/values + PHPVariable var = findVariable (value.getChildVariables(), varname); + if (var != null) { return var; } } } - if (variable.getName().equals(varname)) { + + if (variable.getName().equals (varname)) { return variable; } } catch (DebugException e) { // That's, because of the hasVariables method @@ -406,14 +421,18 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa StringBuffer name = new StringBuffer(); if (!this.getDescription().equals("")) { - name.append(this.getDescription()); + name.append (this.getDescription()); } else { - name.append(this.getFileName()); + name.append (this.getFileName()); } - name.append(" [line "); - name.append(this.getLineNumber()); - name.append("]"); + name.append (" [line "); + name.append (this.getLineNumber()); + name.append ("]"); + + if (fDebug) { + System.out.println ("PHPStackFrame getName: " + name.toString ()); + } return name.toString(); } @@ -474,14 +493,14 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa thread.prepareForResume(DebugEvent.STEP_INTO); // Don't know why, but this is necessary this.getPHPDBGProxy().readStepIntoEnd(PHPStackFrame.this); - + // Commented out sending the RESUME event because it was already sent by prepareForResume. // The second RESUME event leads only to a little flickering within the variables view. // It is also not clear why this event was necessary in eclipse < 3.2 // Also sending a SUSPEND event here leads to a total rebuild of the variables view. // (eclipse 3.2 has a build in timeout of 500 ms which leads to a auto suspend, with // no flickering... but why???) - // + // //ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_INTO); //DebugPlugin.getDefault().fireDebugEventSet (new DebugEvent[] { ev }); } @@ -496,7 +515,7 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa this.getPHPDBGProxy().readStepOverEnd(PHPStackFrame.this); // See comment within the previous stepInto method. - // + // //ev = new DebugEvent (this.getThread (), DebugEvent.RESUME, DebugEvent.STEP_OVER); //DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev }); } @@ -612,16 +631,19 @@ public class PHPStackFrame extends PHPDebugElement implements IStackFrame, Compa *
  • 1 if the index of this stackframe is greater. * */ - public int compareTo(Object obj) { + public int compareTo (Object obj) { if (!(obj instanceof PHPStackFrame)) { - throw new IllegalArgumentException("A PHPStackFrame can only be compared with another PHPStackFrame"); + throw new IllegalArgumentException ("A PHPStackFrame can only be compared with another PHPStackFrame"); } + int frameIndex = ((PHPStackFrame) obj).getIndex(); + if (index < frameIndex) { return -1; } else if (index > frameIndex) { return 1; } + return 0; } } 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 9c94fee..a8ebb2e 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 @@ -27,9 +27,10 @@ import org.eclipse.ui.model.IWorkbenchAdapter; public class PHPThread extends PHPDebugElement implements IThread { private PHPStackFrame[] frames; // The stackframes which belongs to this thread - private PHPDebugTarget target; // + private PHPDebugTarget target; // This is doppel moppel, fTarget exists in PHPDebugElement private String name; // private int id; // The port number through which we communicate to DBG + private boolean fDebug = true; private class State { private boolean isSuspended = false; @@ -95,6 +96,10 @@ public class PHPThread extends PHPDebugElement implements IThread { */ public IStackFrame[] getStackFrames () throws DebugException { if (isSuspended()) { + if (fDebug) { + System.out.println ("PHPThread getStackFrames"); + } + return ((PHPDebugTarget)getDebugTarget()).getStackFrames(); } else { return new IStackFrame[0]; @@ -167,7 +172,7 @@ public class PHPThread extends PHPDebugElement implements IThread { DebugEvent ev; state.setSuspended (false); // We will leave the suspended state - this.frames = null; // Reset the stackframes + frames = null; // Reset the stackframes ev = new DebugEvent (this, DebugEvent.RESUME, de); // Create an event resume by stepping DebugPlugin.getDefault ().fireDebugEventSet (new DebugEvent[] { ev }); // Fire the event diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java index e20be3d..18b11b2 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPValue.java @@ -42,20 +42,20 @@ public class PHPValue implements IValue { "soft reference" }; // 9 public final static int PEVT_UNKNOWN = 0; - public final static int PEVT_LONG = 1; + public final static int PEVT_LONG = 1; public final static int PEVT_DOUBLE = 2; public final static int PEVT_STRING = 3; - public final static int PEVT_ARRAY = 4; + public final static int PEVT_ARRAY = 4; public final static int PEVT_OBJECT = 5; public final static int PEVT_BOOLEAN = 6; - public final static int PEVT_RESOURCE = 7; + public final static int PEVT_RESOURCE = 7; public final static int PEVT_REF = 8; public final static int PEVT_SOFTREF = 9; private int fValueType; // The type of this value (see the PEVT_... values) //private boolean hasChildren; // This value (variable) has children (more variables) - private String fValueString; // The value of this variable as text - private Vector fVariables; // The children of this variable (other variables) if any + private String fValueString; // The value of this variable as text + private Vector fVariables; // The children of this variable (other variables) if any private PHPStackFrame fStackFrame; // The stackframe this value (variable) belongs to private boolean fHasChanged; // The value has changed between two suspends // This variable was moved from PHPVariable due to the fact, @@ -78,12 +78,12 @@ public class PHPValue implements IValue { * @param fValueType The type of this value (see the PEVT_... values). * @param subitems This value has subitems. */ - public PHPValue(PHPStackFrame frame, String value, int fValueType, Vector subitems) { - this.fValueType = fValueType; + public PHPValue (PHPStackFrame frame, String value, int fValueType, Vector subitems) { + this.fValueType = fValueType; this.fValueString = value; - this.fStackFrame = frame; - this.fHasChanged = false; - this.fSorted = false; + this.fStackFrame = frame; + this.fHasChanged = false; + this.fSorted = false; if (subitems != null) { // If there are children for this value (variable) this.fVariables = new Vector(subitems); // Then add the children to this value (variable) @@ -248,12 +248,14 @@ public class PHPValue implements IValue { */ protected Object clone() throws CloneNotSupportedException { PHPValue val = new PHPValue(); - val.fValueType = fValueType; - val.fValueString = fValueString; - val.fVariables = fVariables; - val.fStackFrame = fStackFrame; - val.fHasChanged = fHasChanged; - val.fSorted = fSorted; + + val.fValueType = fValueType; + val.fValueString = fValueString; + val.fVariables = fVariables; + val.fStackFrame = fStackFrame; + val.fHasChanged = fHasChanged; + val.fSorted = fSorted; + return val; } diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java index 94d3c99..8bd7406 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPVariable.java @@ -32,11 +32,11 @@ import org.eclipse.debug.core.model.IVariable; public class PHPVariable implements IVariable { private PHPValue fValue; // The value of this variable - private String fName; // The name of the variable + private String fName; // The name of the variable private PHPStackFrame fStackFrame; // The stackframe this variable belongs to private PHPVariable fParent; // The parent variable (a back link) - private String fLongName; // The qualified name - private boolean fModifiable = true; + private String fLongName; // The qualified name + private boolean fModifiable = true; /** * @@ -54,13 +54,13 @@ public class PHPVariable implements IVariable { * @param valueType The type of the value (e.g. int, double, string etc.) @see PHPValue * @param subitems */ - public PHPVariable(PHPStackFrame frame, String name, PHPVariable parent, - String value, int valueType, Vector subitems) { + public PHPVariable (PHPStackFrame frame, String name, PHPVariable parent, + String value, int valueType, Vector subitems) { this.fStackFrame = frame; - this.fValue = new PHPValue(frame, value, valueType, subitems); - this.fParent = parent; + this.fValue = new PHPValue(frame, value, valueType, subitems); + this.fParent = parent; - setName(name); + setName (name); } /** @@ -69,7 +69,7 @@ public class PHPVariable implements IVariable { */ public void setName(String name) { if ((fParent == null) || // If we have no parent for this variable - (fParent.getName() == "")) { // or we have a parent which is just a simple node ??? + (fParent.getName() == "")) { // or we have a parent which is just a simple node ??? fLongName = name; // Set the long name fName = name; // and set the name @@ -77,20 +77,20 @@ public class PHPVariable implements IVariable { } switch (fParent.getReferenceType()) { // Get the type of the parent variable - case PHPValue.PEVT_ARRAY: // It's an array - fName = "['" + name + "']"; // So set the variable name as [name] - fLongName = fParent.getLongName() + fName; // Set the longname to parentVariableLongname[name] - break; + case PHPValue.PEVT_ARRAY: // It's an array + fName = "['" + name + "']"; // So set the variable name as [name] + fLongName = fParent.getLongName() + fName; // Set the longname to parentVariableLongname[name] + break; - case PHPValue.PEVT_OBJECT: // It's an object - fName = name; // Set the name to name - fLongName = fParent.getLongName() + "->" + fName; // Set the longname to parentVariableLongname.name - break; + case PHPValue.PEVT_OBJECT: // It's an object + fName = name; // Set the name to name + fLongName = fParent.getLongName() + "->" + fName;// Set the longname to parentVariableLongname.name + break; - default: - fName = name; // Set the name to name - fLongName = name; // Set the Longname to name - break; + default: + fName = name; // Set the name to name + fLongName = name; // Set the Longname to name + break; } } @@ -121,16 +121,18 @@ public class PHPVariable implements IVariable { public void setParent(PHPVariable parent) { this.fParent = parent; - switch (fParent.getReferenceType()) { - case PHPValue.PEVT_ARRAY: - fLongName = fParent.getLongName() + fName; - break; - case PHPValue.PEVT_OBJECT: - fLongName = fParent.getLongName() + "->" + fName; - break; - default: - fLongName = fName; - break; + switch (fParent.getReferenceType ()) { + case PHPValue.PEVT_ARRAY: + fLongName = fParent.getLongName() + fName; + break; + + case PHPValue.PEVT_OBJECT: + fLongName = fParent.getLongName() + "->" + fName; + break; + + default: + fLongName = fName; + break; } } @@ -204,46 +206,50 @@ public class PHPVariable implements IVariable { /** * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String) */ - public void setValue(String expression) throws DebugException { + public void setValue (String expression) throws DebugException { String evalString; - if (fValue.getReferenceType() == PHPValue.PEVT_STRING) + + if (fValue.getReferenceType () == PHPValue.PEVT_STRING) { evalString = fLongName + "=\"" + expression + "\""; - else + } + else { evalString = fLongName + "=" + expression; - PHPVariable[] vars = fStackFrame.getPHPDBGProxy().eval(fStackFrame, - evalString); + } + PHPVariable[] vars = fStackFrame.getPHPDBGProxy ().eval (fStackFrame, evalString); +///* if (vars == null || vars.length == 0) { - vars = fStackFrame.getPHPDBGProxy().eval(fStackFrame, fLongName); + vars = fStackFrame.getPHPDBGProxy ().eval (fStackFrame, fLongName); + if (vars == null || vars.length == 0) { - int code = 0; - String msg = "Could not set " + expression + " to " + fLongName; - Status status = new Status(Status.ERROR, - PHPDebugCorePlugin.PLUGIN_ID, code, msg, null); - PHPDebugCorePlugin.log(status); - throw new DebugException(status); + int code = 0; + String msg = "Could not set " + expression + " to " + fLongName; + Status status = new Status (Status.ERROR, PHPDebugCorePlugin.PLUGIN_ID, code, msg, null); + PHPDebugCorePlugin.log (status); + + throw new DebugException (status); } } - +//*/ fValue = vars[0].fValue; +///* + if (fValue.hasVariables ()) { // set parent if new value has children + Vector variables = fValue.getChildVariables (); + + for (int i = 0; i < variables.size (); i++) { + PHPVariable var = (PHPVariable) variables.get (i); + + var.setParent (this); - // set parent if new value has children - if (fValue.hasVariables()) { - Vector variables = fValue.getChildVariables(); - for (int i = 0; i < variables.size(); i++) { - PHPVariable var = (PHPVariable) variables.get(i); - var.setParent(this); - // adjust name if value type is array - // (still bare name. make "['name']") - if (fValue.getReferenceType() == PHPValue.PEVT_ARRAY) { - var.setName(var.getName()); + if (fValue.getReferenceType() == PHPValue.PEVT_ARRAY) { // adjust name if value type is array + var.setName (var.getName ()); // (still bare name. make "['name']") } } } - DebugPlugin.getDefault().fireDebugEventSet( - new DebugEvent[] { new DebugEvent(this, DebugEvent.CHANGE, - DebugEvent.CONTENT) }); + DebugPlugin.getDefault().fireDebugEventSet (new DebugEvent[] { + new DebugEvent (this, DebugEvent.CHANGE, DebugEvent.CONTENT) }); +//*/ } /** @@ -262,7 +268,7 @@ public class PHPVariable implements IVariable { /** * Set whether this variable can be modified (default is true) - * + * * for Global Variables root element only */ public void setModifiable(boolean modifiable) { @@ -340,12 +346,14 @@ public class PHPVariable implements IVariable { */ protected Object clone() throws CloneNotSupportedException { PHPVariable var = new PHPVariable(); - var.fValue = fValue; - var.fName = fName; + + var.fValue = fValue; + var.fName = fName; var.fStackFrame = fStackFrame; - var.fParent = fParent; - var.fLongName = fLongName; + var.fParent = fParent; + var.fLongName = fLongName; var.fModifiable = fModifiable; + return var; } -- 1.7.1