a4c883e0e95648d901b4e46e12ca49e0b58dc3de
[phpeclipse.git] /
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9         Vicente Fernando - www.alfersoft.com.ar - Initial implementation
10         Christian Perkonig - remote debug
11 **********************************************************************/
12 package net.sourceforge.phpdt.internal.debug.core;
13
14 import java.io.BufferedReader;
15 import java.io.IOException;
16 import java.io.OutputStream;
17 import java.util.Collections;
18 import java.util.Vector;
19
20 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy.PHPLoop;
21 import net.sourceforge.phpdt.internal.debug.core.model.PHPDBGEvalString;
22 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
23 import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
24 import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
25
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.core.runtime.Status;
28 import org.eclipse.debug.core.DebugException;
29
30 /**
31  * The interface object are created by the proxy
32  *
33  */
34 public class PHPDBGInterface {
35         public boolean                  sessionEnded = false;
36         public int                              sessType = -1;
37         public int                              BPUnderHit = 0;
38         public String                           sessID = new String();
39
40         private int[]                           LastBPRead = new int[10];
41         private Vector                  DBGBPList = new Vector();
42         private Vector                  DBGVarList = new Vector();
43         private PHPStackFrame[]         DBGStackList = new PHPStackFrame[0];
44         private Vector                  DBGMods = new Vector();                         // The module names and their numbers
45         private Vector                  stackListOld = new Vector();
46         private BufferedReader  in;
47         private OutputStream            os;                                                             // The stream which goes to DBG
48         private boolean                         shouldStop = false;
49         private String                  evalRet = new String("");
50         private int                             rawCounter = 1000;                                      // An rawData frame ID counter
51         private PHPDBGProxy             proxy = null;
52         private int                             lastCmd = -1;
53         private int                             sid = 0;
54         private boolean                         stopOnError = false;
55         private char[]                  lastCommand = new char[4];
56
57         private static final String GlobalVariablesTitle = PHPDebugCorePlugin
58                         .getResourceString("VariablesView.GlobalVariables.title");
59
60         /**
61          * @param in    The input stream (communication from DBG).
62          * @param os    The output stream (communication to DBG).
63          * @param proxy The proxy to which this interface belongs.
64          */
65         public PHPDBGInterface (BufferedReader in, OutputStream os, PHPDBGProxy proxy) {
66                 DBGBPList.clear ();
67
68                 this.in         = in;
69                 this.os         = os;
70                 this.proxy      = proxy;
71         }
72
73         /**
74          *
75          * @param mod_name  The module (source file) to which we add the breakpoint.
76          * @param line      The line where the breakpoint is set.
77          * @param hitCount  The number of hit counts before suspend.
78          * @param condition The break condition
79          * @return          Breakpoint ID ???.
80          */
81         public int addBreakpoint (String mod_name, int line, int hitCount, String condition) throws IOException {
82                 return setBreakpoint (mod_name, condition, line, PHPDBGBase.BPS_ENABLED + PHPDBGBase.BPS_UNRESOLVED, 0, hitCount, 0, 0, 0);
83         }
84
85         /**
86          *
87          * @param mod_name The module (source file) to which we add the breakpoint.
88          * @param line     The line where the breakpoint is set.
89          * @param bpNo     The breakpoint ID ???.
90          */
91         public void removeBreakpoint (String mod_name, int line, int bpNo) throws IOException {
92                 setBreakpoint (mod_name, "", line, PHPDBGBase.BPS_DISABLED, 0, 0, 0, bpNo, 0);
93         }
94
95         /**
96          * Is this method used anywhere?
97          *
98          */
99         public void requestDBGVersion () throws IOException {
100                 PHPDBGPacket DBGPacket;                                     // A DBG message packet
101                 PHPDBGFrame  DBGFrame;                                      // A frame within a DBG packet
102
103                 DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);     // A request for DBG
104                 DBGFrame  = new PHPDBGFrame (PHPDBGBase.FRAME_VER);         // We want the version of DBG
105
106                 DBGPacket.addFrame (DBGFrame);                              // Add the 'what we want' to the DBG packet
107
108                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
109                         return;                                                 //  No
110                 }
111
112                 DBGPacket.sendPacket (os);                                                                      // Send the request to DBG
113         }
114
115         /**
116          * Called by the proxy
117          *
118          */
119         public void getSourceTree () throws IOException {
120                 PHPDBGPacket DBGPacket;                                     // A DBG message packet
121                 PHPDBGFrame  DBGFrame;                                      // A frame within a DBG packet
122
123                 DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);     // A request for DBG
124                 DBGFrame  = new PHPDBGFrame (PHPDBGBase.FRAME_SRC_TREE);        // We want a source tree from DBG
125
126                 DBGPacket.addFrame (DBGFrame);                              // Add the 'what we want' to the DBG packet
127
128                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
129                         return;                                                                                                 //  No
130                 }
131
132                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
133
134                 waitResponse (1000);                                        // Wait for the DBG response (1 second)
135                 flushAllPackets ();                                                                             // Read and process the response from DBG
136         }
137
138         /**
139          * Is this method called from anywhere?
140          *
141          * @param modName The modul (filename).
142          */
143         public void addDBGModName (String modName) throws IOException {
144                 PHPDBGPacket DBGPacket;                                     // A DBG message packet
145                 PHPDBGFrame  DBGFrame;                                      // A frame within a DBG packet
146
147                 DBGPacket = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);     // A request for DBG
148                 DBGFrame  = new PHPDBGFrame (PHPDBGBase.FRAME_RAWDATA);     // We want Module name from DBG
149
150                 rawCounter++;                                               // Increment the rawData ID counter
151                 DBGFrame.addInt (rawCounter);                                                           // FRAME_RAWDATA ID
152                 DBGFrame.addInt (modName.length () + 1);                                        // The length of rawdata string (incl. null char termination)
153                 DBGFrame.addString (modName);                                                           // The file name (module name)
154                 DBGFrame.addChar ('\0');                                                                        // Add the C-String null termination
155
156                 DBGPacket.addFrame (DBGFrame);
157
158                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
159                         return;                                                                                                 //  No
160                 }
161
162                 DBGPacket.sendPacket (os);
163         }
164
165         /**
166          * This method is called for adding or removing breakpoints.
167          *
168          * @param mod_name      The module name (file name).
169          * @param condition     Info about the condition when to break (not used at the moment).
170          * @param line          The breakpoints line.
171          * @param state         Info whether this breakpoint has to be dis- or enabled.
172          * @param istep         Always 0.
173          * @param hitcount      Always 0.
174          * @param skiphits      Always 0.
175          * @param bpno          The breakpoint ID.
176          * @param isunderhit    ???
177          * @return
178          */
179         private int setBreakpoint (String mod_name, String condition, int line, int state, int istemp, int hitcount, int skiphits, int bpno, int isunderhit) throws IOException {
180                 PHPDBGPacket    DBGPacket;
181                 PHPDBGFrame     DBGFrame1;
182                 PHPDBGFrame     DBGFrame2;
183                 PHPDBGFrame             DBGFrame3;
184                 int                     modNo;
185
186                 DBGPacket       = new PHPDBGPacket (PHPDBGBase.DBGA_REQUEST);
187                 DBGFrame1       = new PHPDBGFrame (PHPDBGBase.FRAME_BPS);
188                 DBGFrame2       = new PHPDBGFrame (PHPDBGBase.FRAME_RAWDATA);
189                 DBGFrame3       = new PHPDBGFrame (PHPDBGBase.FRAME_RAWDATA);
190
191                 modNo           = getModByName (mod_name);                                              // Get the module ID by name
192
193                 if (modNo >= 0) {                                           // Did we find a module ID for the module name?
194                         DBGFrame1.addInt (modNo);                                                               // Add the module ID to frame 1
195                 } else {
196                         DBGFrame1.addInt (0);                                                                   // mod number (0 use file name)
197                 }
198
199                 DBGFrame1.addInt (line);                                                                        // line number
200
201                 if (modNo >= 0) {                                           // Did we find a module ID for the module name?
202                         DBGFrame1.addInt (0);                                                                   // use mod number
203                 } else {
204                         rawCounter++;
205                         DBGFrame1.addInt (rawCounter);                                                  // ID of FRAME_RAWDATA to send file name
206                 }
207
208                 if (modNo < 0) {                                            // Did we find a module ID for the module name?
209                         DBGFrame2.addInt (rawCounter);                                      // FRAME_RAWDATA ID
210                         DBGFrame2.addInt (mod_name.length() + 1);                   // length of rawdata (+ null char)
211                         DBGFrame2.addString (mod_name);                                     // file name
212                         DBGFrame2.addChar ('\0');                                                   // null char
213
214                         DBGPacket.addFrame (DBGFrame2);                         // First add file name data
215                 }
216
217                 DBGFrame1.addInt (state);                                       // state BPS_*
218                 DBGFrame1.addInt (istemp);                                      // istemp
219                 DBGFrame1.addInt (0);                                               // hit count; this is not supported as one might think
220                 DBGFrame1.addInt (hitcount);                                // skip hits is what we think is hit count.
221
222                 if (!condition.equals ("")) {                                                           // Do we have a condition for breakpoint
223                         rawCounter++;                                                                                   // Set to new ID
224                         DBGFrame1.addInt (rawCounter);                          // ID of condition
225
226                         DBGFrame3.addInt (rawCounter);                                      // FRAME_RAWDATA ID
227                         DBGFrame3.addInt (condition.length() + 1);                  // length of rawdata (+ null char)
228                         DBGFrame3.addString (condition);                                        // The break condition
229                         DBGFrame3.addChar ('\0');                                                   // null char
230
231                         DBGPacket.addFrame (DBGFrame3);                         // First add break condition
232                 }
233                 else {
234                         DBGFrame1.addInt (0);                                           // ID of condition is 0, because there is no condition
235                 }
236
237                 DBGFrame1.addInt (bpno);                                            // breakpoint number
238                 DBGFrame1.addInt (isunderhit);                                  // is under hit
239
240                 DBGPacket.addFrame (DBGFrame1);                                                         // Second add command data
241
242                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
243                         return 0;                                               //  No
244                 }
245
246                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
247
248                 clearLastBP ();
249
250                 waitResponse (1000);                                        // Wait for the DBG response (1 second)
251                 flushAllPackets ();                                         // Read and process the response from DBG
252
253                 return LastBPRead[8];                                                                           // Return what ???
254         }
255
256         /**
257          *
258          */
259         private void clearLastBP () {
260                 int i;
261
262                 for (i = 0; i < LastBPRead.length; i++) {
263                         LastBPRead[i] = 0;
264                 }
265         }
266
267         /**
268          *
269          */
270         private void copyToLastBP (int[] BPBody) {
271                 int i;
272
273                 for (i = 0; i < LastBPRead.length; i++) {
274                         LastBPRead[i] = BPBody[i];
275                 }
276         }
277
278         /**
279          *
280          */
281         public void continueExecution () throws IOException {
282                 PHPDBGPacket DBGPacket;
283
284                 BPUnderHit = 0;
285                 DBGPacket  = new PHPDBGPacket (PHPDBGBase.DBGA_CONTINUE);
286
287                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
288                         return;                                                 //  No
289                 }
290                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
291
292                 lastCommand = PHPDBGBase.DBGA_CONTINUE;                     // Store the info about the command we sent
293         }
294
295         /**
296          *
297          */
298         public void pauseExecution () throws IOException {
299                 PHPDBGPacket DBGPacket;
300
301                 DBGPacket = new PHPDBGPacket (PHPDBGBase.IntToChar4 (PHPDBGBase.DBGC_PAUSE));
302
303                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
304                          return;                                                //  No
305                 }
306
307                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
308         }
309
310         /**
311          *
312          */
313         private int getBPUnderHit () {
314                 int i;
315                 int BPUnder             = 0;
316                 int[] dbg_bpl_body      = new int[10];
317
318                 for (i = 0; i < DBGBPList.size (); i++) {                               // look for bp under hit
319                         dbg_bpl_body = (int[]) DBGBPList.get (i);
320
321                         if (dbg_bpl_body[9] == 1) {
322                                 BPUnder = dbg_bpl_body[8];
323                         }
324                 }
325
326                 return BPUnder;
327         }
328
329         public int getLastCmd()
330         {
331                 return lastCmd;
332         }
333
334         public int getSID()
335         {
336           return sid;
337         }
338
339         public void setLastCmd (int cmd)
340         {
341                 lastCmd = cmd;
342         }
343
344         /**
345          *
346          */
347         public void stepInto () throws IOException {
348                 PHPDBGPacket DBGPacket;
349
350                 BPUnderHit = 0;
351                 DBGPacket  = new PHPDBGPacket (PHPDBGBase.DBGA_STEPINTO);
352
353                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
354                         return;                                                 //  No
355                 }
356
357                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
358
359                 lastCommand = PHPDBGBase.DBGA_STEPINTO;                                         // Store the info about the command we sent
360         }
361
362         /**
363          *
364          */
365         public void stepOver () throws IOException {
366                 PHPDBGPacket DBGPacket;
367
368                 BPUnderHit = 0;
369                 DBGPacket  = new PHPDBGPacket (PHPDBGBase.DBGA_STEPOVER);
370
371                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
372                         return;                                                 //  No
373                 }
374
375                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
376
377                 lastCommand = PHPDBGBase.DBGA_STEPOVER;                     // Store the info about the command we sent
378         }
379
380         /**
381          *
382          */
383         public void stepOut () throws IOException {
384                 PHPDBGPacket DBGPacket;
385
386                 BPUnderHit = 0;
387                 DBGPacket  = new PHPDBGPacket (PHPDBGBase.DBGA_STEPOUT);
388
389                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
390                         return;                                                 //  No
391                 }
392
393                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
394
395                 lastCommand = PHPDBGBase.DBGA_STEPOUT;                      // Store the info about the command we sent
396         }
397
398         /**
399          *
400          */
401         public void stopExecution () throws IOException {
402                 PHPDBGPacket DBGPacket;
403
404                 BPUnderHit = 0;
405                 DBGPacket  = new PHPDBGPacket (PHPDBGBase.DBGA_STOP);
406
407                 if (proxy.getSocket ().isClosed ()) {                                           // Can we communiate with DBG?
408                         return;                                                 //  No
409                 }
410
411                 DBGPacket.sendPacket (os);                                  // Send the request to DBG
412         }
413
414         /**
415          * This method is called by the proxy.
416          * It sends a request to DBG to get the current variables
417          * with their values. It waits for the response and processes
418          * the input from DBG.
419          *
420          * @param stack The stackframe for which we want the variables.
421          * @return      The array of variables
422          */
423         public synchronized Vector getVariables(PHPStackFrame stack) throws IOException, DebugException {
424                 if (DBGStackList.length == 0) {
425                         DBGVarList.clear();
426                         return DBGVarList;
427                 }
428
429                 // get global variables (and assign them to 'main()' stackframe)
430                 int global_scope_id = (DBGStackList.length > 1) ? 2 : PHPDBGBase.GLOBAL_SCOPE_ID;
431                 // DBG 2.13.1 doesn't return Super Globals with GLOBAL_SCOPE_ID in nested stackframes,
432                 // so using 2(most out-standing stack context) instead of GLOBAL_SCOPE_ID.
433                 // Also note that 2.13.1 doesn't return $this in class context.
434                 // (You can inspect $this in Expressions View. And once it is shown, 2.13.1 comes to return $this.)
435                 Vector globalList = getVariables(DBGStackList[DBGStackList.length - 1], global_scope_id);
436                 if (!globalList.isEmpty()) {
437                         // remove unresolved '$this=?' variable
438                         removeUnresolvedThisVar(globalList);
439
440                         PHPVariable var = (PHPVariable) globalList.get(0);
441                         var.setName(GlobalVariablesTitle);
442                         var.setModifiable(false);
443                 }
444
445                 int scopeID = stack.getScopeID();
446                 if (!globalList.isEmpty()
447                                 && ((DBGStackList.length == 1)
448                                                 || (scopeID == PHPDBGBase.CURLOC_SCOPE_ID + 1))) {
449                         // 'main()' stackframe
450                         PHPVariable var = (PHPVariable) globalList.get(0);
451                         PHPValue val = (PHPValue) var.getValue();
452                         DBGVarList = val.getChildVariables();
453                         return DBGVarList;
454
455                 } else if (scopeID == PHPDBGBase.CURLOC_SCOPE_ID) {
456                         // current stackframe
457                         DBGVarList = getVariables(stack, PHPDBGBase.CURLOC_SCOPE_ID);
458
459                 } else {
460                         // back-trace stackframe
461                         //DBGVarList = getVariables(stack, scopeID);
462                         //removeUnresolvedThisVar(DBGVarList);
463                         // DBG 2.15.5 causes Application Error (on win32) in *some* cases.
464                         DBGVarList.clear();
465                 }
466
467                 if (DBGVarList.size() > 0) {                                                            // Did we get back variables?
468                         PHPVariable var = (PHPVariable) DBGVarList.get(0);              // Yes, then get the first PHPVariable
469                         PHPValue    val = (PHPValue) var.getValue();                    // Get the value
470
471                         if (var.getName().equals("")) {                                                 // Is the root node an empty node (usually it is)
472                                 DBGVarList = val.getChildVariables();                           // Then remove the empty node.
473                                                                                                                                         // With removing the empty root node, it wouldn't be necessary to
474                                                                                                                                         // set the name to an empty string. So the code below is just for
475                                                                                                                                         // info or in case the users want to have the empty root node.
476
477                                                                                                                                         // The eclipse variable view cannot handle Variables which have an empty name
478                                                                                                                                         // when it comes to variable tree restore operation. Without a name, no restore!
479                                 //var.setName (" ");                                                            // Give a name to the variable root node. Even if it is only a space :-)
480                         }                                                                                                               // TO DO the best would be to remove the empty root node, but this would
481                                                                                                                                         // require a understanding and reworking of the PHPDBGEvalstring class.
482                 }
483
484                 if (!globalList.isEmpty()) {
485                         DBGVarList.add(globalList.get(0));
486                 }
487
488                 return DBGVarList;                                                                                      // Return the variables as list
489         }
490
491         /**
492          * 
493          */
494         private Vector getVariables(PHPStackFrame stack, int scope_id) throws IOException {
495                 PHPDBGPacket DBGPacket = new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
496                 PHPDBGFrame DBGFrame1 = new PHPDBGFrame(PHPDBGBase.FRAME_EVAL);
497
498                 DBGFrame1.addInt(0);
499                 DBGFrame1.addInt(scope_id);
500
501                 DBGPacket.addFrame(DBGFrame1);
502                 evalRet = "";
503
504                 if (proxy.getSocket().isClosed()) {
505                         return new Vector();
506                 }
507                 DBGPacket.sendPacket(os);
508
509                 waitResponse(1000);
510                 flushAllPackets();
511
512                 PHPDBGEvalString evalStr = new PHPDBGEvalString(stack, evalRet);
513                 return evalStr.getVariables();
514         }
515
516         /**
517          * Remove unresolved $this variable
518          * 
519          * DBG returns $this=? in function's or intermediate stackframes.
520          * (In current method's stackframe, DBG returns $this=classname)
521          * 
522          * @param varList
523          */
524         private void removeUnresolvedThisVar(Vector varList) {
525                 if (varList.size() > 0) {
526                         PHPVariable var = (PHPVariable) varList.get(0);
527                         PHPValue val = (PHPValue) var.getValue();
528                         Vector workList = val.getChildVariables();
529                         for (int i = 0; i < workList.size(); i++) {
530                                 PHPVariable workvar = (PHPVariable) workList.get(i);
531                                 if (workvar.getName().equals("$this")) {
532                                         String workval = ((PHPValue) workvar.getValue()).getValueString();
533                                         if (workval.equals("?") || workval.equals("NULL")) {
534                                                 workList.remove(i);
535                                         }
536                                         break;
537                                 }
538                         }
539                 }
540         }
541
542         /**
543          *
544          * @param logString
545          */
546         public void log(String logString) throws IOException, DebugException  {
547                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
548                 PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_LOG);
549                 PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
550
551                 rawCounter++;
552                 DBGFrame1.addInt(rawCounter);                           // ilog
553                 DBGFrame1.addInt(1);                                            // type
554                 DBGFrame1.addInt(0);                                            // mod_no
555                 DBGFrame1.addInt(0);                                            // line_no
556                 DBGFrame1.addInt(0);                                            // imod_name
557                 DBGFrame1.addInt(0);                                            // ext_info
558
559                 DBGFrame2.addInt(rawCounter);                           // FRAME_RAWDATA ID
560                 DBGFrame2.addInt(logString.length() + 1);       // length of rawdata (+ null char)
561                 DBGFrame2.addString(logString);                         // log string
562                 DBGFrame2.addChar('\0');                                        // null char
563
564                 // Add raw data first
565                 DBGPacket.addFrame(DBGFrame2);
566                 // Add command data
567                 DBGPacket.addFrame(DBGFrame1);
568
569                 if (proxy.getSocket ().isClosed ()) {                   // Do we have a socket for DBG communication?
570                         return;                                                                                         //  No, then leave here
571                 }
572
573                 DBGPacket.sendPacket(os);
574
575                 waitResponse(1000);
576                 flushAllPackets();
577         }
578
579         public synchronized PHPVariable[] evalBlock(PHPStackFrame stack, String evalString) throws IOException, DebugException {
580                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
581                 PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_EVAL);
582                 PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
583
584                 rawCounter++;
585                 DBGFrame1.addInt(rawCounter);                           // istr = raw data ID
586                 //DBGFrame1.addInt(1);                                          // scope_id = -1 means current location, 0 never used, +1 first depth
587                 int scope_id = stack.getScopeID();
588                 /* test code : unnecessary
589                 if (DBGStackList.length == 1 || scope_id == (PHPDBGBase.CURLOC_SCOPE_ID + 1)) {
590                         scope_id = PHPDBGBase.GLOBAL_SCOPE_ID;
591                 }
592                 */
593                 DBGFrame1.addInt(scope_id);
594
595                 DBGFrame2.addInt(rawCounter);                           // FRAME_RAWDATA ID
596                 DBGFrame2.addInt(evalString.length() + 1);      // length of rawdata (+ null char)
597                 DBGFrame2.addString(evalString);                        // eval block
598                 DBGFrame2.addChar('\0');                                        // null char
599
600                 // Add raw data first
601                 DBGPacket.addFrame(DBGFrame2);
602                 // Add command data
603                 DBGPacket.addFrame(DBGFrame1);
604
605                 if (proxy.getSocket().isClosed()) {                     // Do we have a socket for DBG communication?
606                         return null;                                                    //  No, then leave here
607                 }
608                 DBGPacket.sendPacket(os);
609
610                 waitResponse(1000);
611                 flushAllPackets();
612
613                 PHPDBGEvalString evalStr=new PHPDBGEvalString(stack, evalRet);
614
615                 return evalStr.getVars();
616         }
617
618         /**
619          * Read and process everthing we got from DBG
620          */
621         public void flushAllPackets () throws IOException {
622                 while (readResponse() != 0);
623         }
624
625         /**
626          * Get the modules name by its number
627          *
628          * @param modNo The number (id) of the module
629          * @return      The name of the module
630          */
631         public String getModByNo (int modNo) {
632                 int             i;
633                 PHPDBGMod       dbg_mod;
634
635                 for (i = 0; i < DBGMods.size (); i++) {                         // For all the modules we have within the array
636                         dbg_mod = (PHPDBGMod) DBGMods.get (i);                      // Get the module
637
638                         if (dbg_mod.getNo () == modNo) {                            // Is the module from the array the module we want?
639                                 return dbg_mod.getName ();                              //  Yes, return the name of the module
640                         }
641                 }
642
643                 return "";                                                      // If nothing was found return emtpy string
644         }
645
646         /**
647          *
648          * @param  modName The name of the module for which we want the ID
649          * @return
650          * - The ID of the module
651          * - -1 if nothing was found
652          */
653         private int getModByName (String modName) {
654                 int             i;
655                 PHPDBGMod       dbg_mod;
656
657                 for (i = 0; i < DBGMods.size (); i++) {                         // For all the modules we have within the array
658                         dbg_mod = (PHPDBGMod) DBGMods.get (i);                      // Get the module
659
660                         if (dbg_mod.getName ().equalsIgnoreCase (modName)) {            // Is the module from the array the module we want?
661                                 return dbg_mod.getNo ();                                //  Yes, return the name of the module
662                         }
663                 }
664
665                 return -1;                                                      // If nothing was found return -1
666         }
667
668         /**
669          * Return the string for the given frame number
670          *
671          * @param framesInfo The buffer which is to read
672          * @param frameNo    The frame number
673          * @return
674          */
675         private String getRawFrameData (char[] framesInfo, int frameNo) {
676                 int   nextFrame = 0;                                                    // The current read position within the buffer
677                 int[] dbg_frame = new int[2];                                           // The two frame header numbers
678
679                 while (nextFrame < framesInfo.length) {                                 // As long we have something within the buffer
680                         dbg_frame[0] = PHPDBGBase.Char4ToInt (framesInfo, nextFrame);           // The frame type
681                         dbg_frame[1] = PHPDBGBase.Char4ToInt (framesInfo, nextFrame + 4);       // The frame size
682
683                         nextFrame   += 8;                                                   // The current read position
684
685                         if (dbg_frame[1] == 0) {                                            // If frame size is 0
686                                 return "";                                                      //  return an emtpy string
687                         }
688
689                         switch (dbg_frame[0]) {                                                     // Switch for the frame type
690                                 case PHPDBGBase.FRAME_RAWDATA:                                                  // The only frame type we are interrested in
691                                         if (frameNo == PHPDBGBase.Char4ToInt (framesInfo, nextFrame)) {         // Is it correct  number of the frame
692                                                 int toRead;                                                     //
693
694                                                 toRead = PHPDBGBase.Char4ToInt (framesInfo, nextFrame + 4);     // The size of the string
695
696                                                 if ((int) framesInfo[nextFrame + 8 + toRead - 1] == 0) {                                // Is there a string termination at the end?
697                                                         return String.copyValueOf (framesInfo, nextFrame + 8, toRead - 1);      // Then copy frame content to String without the \0 and return
698                                                 }
699
700                                                 return String.copyValueOf (framesInfo, nextFrame + 8, toRead);  // Copy frame content to String and return
701                                         }
702                                         break;
703                         }
704
705                         nextFrame += dbg_frame[1];                                                                      // Go for the next frame (add the length of the current one)
706                 }
707
708                 return "";                                                                                                                                              // We did not found any FRAM_RAWDATA, so return an emtpy strin
709         }
710
711         /**
712          * Reset the availability flag for all stackframes in the list.
713          *
714          * @param list          The list of old stackframes
715          */
716         private void resetAvailability (Vector list) {
717                 int             i;
718
719                 for (i = 0; i < list.size (); i++) {
720                         ((PHPStackFrame) list.get(i)).setAvailable (false);                                     //
721                 }
722         }
723
724         /**
725          * Check whether the new stackframe is in the list of old stackframes.
726          * Test for identical stackframe (identical means same description and same line number).
727          *
728          * @param stackFrameNew The stackframe to check whether he is already within the old stackframe list
729          * @param list          The list of old stackframes
730          * @return
731          *  - true if we have found the identical stackframe within the list
732          *  - false if we did not find the identical stackframe within the list
733          */
734         private boolean isStackFrameInList (PHPStackFrame stackFrameNew, Vector list) {
735                 int             i;
736                 PHPStackFrame   stackFrameOld;
737
738                 for (i = 0; i < list.size (); i++) {
739                         stackFrameOld = (PHPStackFrame) list.get (i);                                           //
740
741                         if (stackFrameNew.getDescription ().equals (stackFrameOld.getDescription ()) &&
742                                 stackFrameNew.getLineNumber () == stackFrameOld.getLineNumber ()) {     // Did we find the sent stackframe within the list of old stackframes?
743                                 stackFrameOld.setAvailable (true);                                      // We found the new stackframe in the list of old stack frames
744                 stackFrameOld.setIndex (stackFrameNew.getIndex ());
745                 stackFrameOld.setScopeID(stackFrameNew.getScopeID());
746                                 return true;                                                            // The stackframe was found in the list
747                         }
748                 }
749
750                 return false;
751         }
752
753         /**
754          * Check whether the new stackframe is in the list of old stackframes.
755          * Test for exact stackframe (exact means same description and same line number).
756          *
757          * @param stackFrameNew The stackframe to check whether he is already within the old stackframe list
758          * @param list          The list of old stackframes
759          * @return
760          *  - true if we have exactly this stackframe within the list
761          *  - false if we did not find the exact stackframe within the list
762          */
763         private void markIdenticalStackFrames (Vector oldList, Vector newList) {
764                 int             i;
765                 PHPStackFrame   stackFrameNew;
766
767                 resetAvailability (oldList);                                                    // Reset the availability flag of the old stack frames
768                 resetAvailability (newList);                                                    // Reset the availability flag of the old stack frames
769
770                 for (i = 0; i < newList.size (); i++) {                                                                                 // For all stackList entries
771                         stackFrameNew = (PHPStackFrame) newList.get (i);
772
773                         if (isStackFrameInList (stackFrameNew, oldList)) {                          // Is this stackframe in the list
774                                 stackFrameNew.setAvailable (true);                                                                              //
775                                                                                                                                                                                 //
776                                 break;
777                         }
778                 }
779         }
780
781         /**
782          *
783          * The stackList contains the currently read stackframes which were sent
784          * from DBG. The DBG interface holds a list of the active stack frames.
785          * This method replicates the 'static' stackframe list with the DBG stackframe list
786          * Replication is done in the following way:
787          * <ul>
788          * <li> It looks for new stackframes within the DBG stackframe list and
789          *      adds them to the 'static' list.
790          * <li> It looks for stackframes within the 'static' list, and removes them
791          *              from the 'static' list in case they do not appear within the DBG list.
792          * <li> It looks for stackframes which are already existent and replicates the
793          *              line number and the index number.
794          * <li> At the end, the 'static' stackframe list has to be sorted by the stackframes
795          *              index numbers.
796          * </ul>
797          *
798          * Removes the unused stackframes from the list, or adds stackframes which
799          * are not yet in the list.
800          *
801          *
802          * @param stackList
803          */
804         private void updateStackFrameList (Vector stackList) {
805                 int                     i;
806                 int             n;
807                 PHPStackFrame   stackFrameNew;
808                 PHPStackFrame   stackFrameOld;
809                 PHPStackFrame[] newStackList;
810
811                 markIdenticalStackFrames (stackListOld, stackList);                     // Check whether the newly send stack frames can be found in the list
812                                                                                                                                                                 // of old stack frames
813
814                 for (i = 0; i < stackList.size (); i++) {                                                               // For all stackList entries
815                         stackFrameNew = (PHPStackFrame) stackList.get(i);
816
817                         for (n = 0; n < stackListOld.size (); n++) {                                    // For all StackFrames in the StackFrame list
818                                 stackFrameOld = (PHPStackFrame) stackListOld.get (n);                   //
819
820                                 if (stackFrameOld.isAvailable ()) {                             // If this stack frame was already found in the new list skip it
821                                         continue;
822                                 }
823
824                                 if (stackFrameNew.getDescription ().equals (stackFrameOld.getDescription ())) {// Did we find the sent stackframe within the list of old stackframes?
825                                         stackFrameOld.setLineNumber (stackFrameNew.getLineNumber ());
826                                         stackFrameOld.setIndex (stackFrameNew.getIndex ());
827                                         stackFrameOld.setScopeID(stackFrameNew.getScopeID());
828
829                                         stackFrameOld.setAvailable (true);                                                      // And mark this stack frame as available
830                                         stackFrameNew.setAvailable (true);                                                      // And mark this stack frame as available
831
832                                         break;                                                                  //  Yes, then break;
833                                 }
834                         }
835
836                         if (!stackFrameNew.isAvailable ()) {                                // Did not find the new stackframe within the list?
837                                  stackFrameNew.setAvailable (true);                                                             // Mark the stack frame as available and
838                                  stackListOld.add (stackFrameNew);                              //  then add the new stackframe
839                         }
840                 }
841
842                 // And now for removing unused stackframes from list
843
844                 for (n = 0; n < stackListOld.size(); n++) {
845                         stackFrameOld = (PHPStackFrame) stackListOld.get(n);
846
847                         if (!stackFrameOld.isAvailable()) {
848                                 stackListOld.remove(n--);
849                         }
850                 }
851
852                 Collections.sort (stackListOld);                                                                                // Sort the 'static' stackframe list by the stackframe index numbers.
853                                                                                                                                                                 //
854                 newStackList = new PHPStackFrame[stackListOld.size ()];
855                 newStackList = (PHPStackFrame[]) stackListOld.toArray (newStackList);
856                 DBGStackList = newStackList;
857         }
858
859     /**
860      * Read the response from DBG and process the frame
861      *
862          * @return
863          * - The received command
864          * - or 0 if something was wrong
865      */
866         public int readResponse () throws IOException {
867         int     bytesToRead            = 0;                         // The number of byte to read for the current DBG block
868         int     nextFrame              = 0;                         // The current read position within entirePack
869         int     i                      = 0;
870         int     cmdReceived            = 0;
871         int     stackIndex             = 0;
872         boolean errorStack             = false;
873         char[]  dbg_header_struct_read = new char[16];              // The buffer for the first 16 bytes of a block
874         int[]   dbg_header_struct      = new int[4];                // The first four numbers (long) of a block
875         int[]   dbg_bpl_tmp            = new int[10];
876         int[]   dbg_frame              = new int[2];
877         int[]   dbg_eval_tmp           = new int[3];
878         int[]   dbg_src_tree_tmp       = new int[4];                //
879         int[]   dbg_error_tmp          = new int[2];
880         Vector  rawList                = new Vector();
881         Vector  stackList              = new Vector();              // Intermediate stacklist which is build up in FRAME_STACK frame
882
883         rawList.clear ();
884         stackList.clear ();
885
886                 // Read from input
887         while (readInput (dbg_header_struct_read, 16) != 0) {                               // Read 16 byte from input stream
888                         dbg_header_struct[0] = PHPDBGBase.Char4ToInt (dbg_header_struct_read, 0);               // Debug sync header
889             dbg_header_struct[1] = PHPDBGBase.Char4ToInt (dbg_header_struct_read, 4);           // Command
890             dbg_header_struct[2] = PHPDBGBase.Char4ToInt (dbg_header_struct_read, 8);       //
891             dbg_header_struct[3] = PHPDBGBase.Char4ToInt (dbg_header_struct_read, 12);      // Bytes within this block
892
893             if (dbg_header_struct[0] != 0x5953) {                                           // Check DBG sync bytes
894                 return 0;                                                                   // Wrong header
895             }
896
897             cmdReceived = dbg_header_struct[1];                                             // Get the command
898             setLastCmd (cmdReceived);                                                                                                           // Store the info about the current command
899             bytesToRead = dbg_header_struct[3];                                                                                         // Get the number of bytes to read for this block
900
901                         //System.out.println("Response Received: " + cmdReceived);
902                         char[] entirePack = new char[bytesToRead];                                      // Store the block data into buffer 'entirePack'
903
904             if (bytesToRead > 0) {                                                          // If there is something within the frame
905                 if (readInput (entirePack, bytesToRead) < bytesToRead) {                    // Read the frame into the buffer
906                     return 0;                                                               // We did not read enough bytes, error
907                 }
908                         }
909                         
910                         nextFrame = 0;                                                                  // Start with the first frame
911
912                         while (nextFrame < bytesToRead) {                                               // As long as we have something within this block
913                                 dbg_frame[0] = PHPDBGBase.Char4ToInt (entirePack, nextFrame);                           // The name of the frame
914                                 dbg_frame[1] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 4);               // The size of the frame
915                                 nextFrame   += 8;                                                           // The next read position
916
917                                 if (dbg_frame[1] == 0) {                                                    // Something within the frame?
918                                         return 0;                                                               //  Nothing to read, error
919                                 }
920
921                                 switch (dbg_frame[0]) {
922                                         case PHPDBGBase.FRAME_STACK:
923                                                 int[] dbg_stack_new = new int[4];                                       //
924
925                                                 dbg_stack_new[0] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 0);   // Source line number
926                                                 dbg_stack_new[1] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 4);   // Module number
927                                                 dbg_stack_new[2] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 8);   // Scope id
928                                                 dbg_stack_new[3] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 12);  // ID of description string
929
930                                                 if ((dbg_stack_new[1] != 0) && !errorStack) {
931                                                         PHPStackFrame newStack;
932
933                                                         stackIndex++;
934                                                         newStack = new PHPStackFrame (null,                                 // The thread
935                                                                                       getModByNo (dbg_stack_new[1]),        // The name of the module (file)
936                                                                                       dbg_stack_new[0],                     // The source line number
937                                                                                                                   stackIndex,
938                                                                                                                   getRawFrameData (entirePack,          // Get the string from this packet
939                                                                                                                                    dbg_stack_new[3]),   // The frame ID for which we want the string
940                                                                                                                   dbg_stack_new[1],                                     // The module number
941                                                                                                                   dbg_stack_new[2]);
942                                                         stackList.add (newStack);
943                                                 }
944
945                                                 errorStack = false;
946                                                 break;
947
948                                         case PHPDBGBase.FRAME_SOURCE:                                                   // Nothing to be done here
949                                                 break;                                                                      // TODO: what's with that frame? Something interesting
950
951                                         case PHPDBGBase.FRAME_SRC_TREE:                                                 //
952                                                 dbg_src_tree_tmp[0] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 0);        // The parent module number
953                                                 dbg_src_tree_tmp[1] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 4);        // The parent line number (not used)
954                                                 dbg_src_tree_tmp[2] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 8);        // The module number
955                                                 dbg_src_tree_tmp[3] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 12);       // The filename number
956
957                                                 if (getModByNo (dbg_src_tree_tmp[2]).equals ("")) {
958                                                         String fileName;
959
960                                                         fileName = new String (getRawFrameData (entirePack, dbg_src_tree_tmp[3]));      // Get the filename
961
962                                                         if (dbg_src_tree_tmp[2] != 0) {                                             // If there is a module number
963                                                                 PHPDBGMod modNew;
964
965                                                                 modNew = new PHPDBGMod (dbg_src_tree_tmp[2], fileName);                 // Create a module object
966
967                                                                 DBGMods.add (modNew);                                                   // And store it to array
968                                                         }
969                                                 }
970                                                 break;
971
972                                         case PHPDBGBase.FRAME_RAWDATA:                                                      // Nothing to be done here
973                                                 break;                                                                          //  FRAME_RAWDATA are processed within getRawFrameData
974
975                                         case PHPDBGBase.FRAME_ERROR:                                                                                                            // An error frame
976                                                 errorStack       = true;                                                                                                                // Yes, we have an error stack
977                                                 dbg_error_tmp[0] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 0);                   // Error type
978                                                 dbg_error_tmp[1] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 4);                   // Error message ID
979
980                                                 String error = "\n";                                                            //
981
982                                                 switch (dbg_error_tmp[0]) {                                                                                                             // Switch on error type
983                                                         case PHPDBGBase.E_ERROR:                        error += "[Error]";                     break;
984                                                         case PHPDBGBase.E_WARNING:                      error += "[Warning]";                   break;
985                                                         case PHPDBGBase.E_PARSE:                        error += "[Parse Error]";               break;
986                                                         case PHPDBGBase.E_NOTICE:                       error += "[Notice]";                    break;
987                                                         case PHPDBGBase.E_CORE_ERROR:           error += "[Core Error]";                break;
988                                                         case PHPDBGBase.E_CORE_WARNING:         error += "[Core Warning]";              break;
989                                                         case PHPDBGBase.E_COMPILE_ERROR:        error += "[Compile Error]";             break;
990                                                         case PHPDBGBase.E_COMPILE_WARNING:      error += "[Compile Warning]";   break;
991                                                         case PHPDBGBase.E_USER_ERROR:           error += "[User Error]";                break;
992                                                         case PHPDBGBase.E_USER_WARNING:         error += "[User Warning]";              break;
993                                                         case PHPDBGBase.E_USER_NOTICE:          error += "[User Notice]";               break;
994                                                         default:                                                        error += "[Unexpected Error]";  break;
995                                                 }
996
997                                                 error += ": ";
998                                                 error += new String (getRawFrameData (entirePack, dbg_error_tmp[1]));                   // Add the error string for this error message ID
999                                                 error += "\n";                                                                  // Append a CR
1000
1001                                                 PHPDebugCorePlugin.log (new DebugException (new Status (IStatus.WARNING,
1002                                                                                                         PHPDebugCorePlugin.PLUGIN_ID,
1003                                                                                                                                                                 IStatus.OK,
1004                                                                                                                                                                 error, null)));
1005
1006                                                 // To print errors on the console, I must execute a code in the
1007                                                 // php context, that write the stderr... I didn't found a better way
1008                                                 // TODO: Find a better way????
1009
1010 //                                              String codeExec= "";
1011 //                                              codeExec= "fwrite(fopen('php://stderr', 'w'),\\\"" + error + "\\\");";
1012 //                                              try {
1013 //                                                      evalBlock("eval(\"" + codeExec + "\");");
1014 //                                              } catch (DebugException e) {
1015 //                                                      PHPDebugCorePlugin.log(e);
1016 //                                              }
1017 //
1018                                                 if (!stopOnError) {                                                             // Is always false (Did not see where this is set to true!?)
1019                                                         if (lastCommand.equals (PHPDBGBase.DBGA_CONTINUE)) {                        // If last command for PHP was a 'continue',
1020                                                                 continueExecution ();                                                   //  send continue again
1021                                                         } else if (lastCommand.equals (PHPDBGBase.DBGA_STEPINTO)) {                 // If last command for PHP was a 'step into',
1022                                                                 stepInto ();                                                            //  send 'step into' again
1023                                                         } else if (lastCommand.equals (PHPDBGBase.DBGA_STEPOUT)) {                  // If last command for PHP was a 'step out',
1024                                                                 stepOut ();                                                             //  send 'step out' again
1025                                                         } else if (lastCommand.equals (PHPDBGBase.DBGA_STEPOVER)) {                 // If last command for PHP was a 'step over',
1026                                                                 stepOver ();                                                            //  send 'step over' again
1027                                                         }
1028                                                 }
1029                                                 break;
1030
1031                                         case PHPDBGBase.FRAME_EVAL:
1032                                                 //String evalString;
1033
1034                                                 //evalString      = new String ("");
1035                                                 dbg_eval_tmp[0] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 0);                    // istr
1036                                                 dbg_eval_tmp[1] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 4);                    // iresult
1037                                                 dbg_eval_tmp[2] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 8);                    // ierror
1038
1039                                                 evalRet                 = getRawFrameData (entirePack, dbg_eval_tmp[1]);                //
1040                                                 //evalString    = getRawFrameData (entirePack, dbg_eval_tmp[0]);                //
1041                                                 break;
1042
1043                                         case PHPDBGBase.FRAME_BPS:                                                          //
1044                                                 break;                                                                          //
1045
1046                                         case PHPDBGBase.FRAME_BPL:
1047                                                 int[] dbg_bpl_new;
1048
1049                                                 dbg_bpl_new        = new int[10];
1050                                                 dbg_bpl_new[0] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 0);
1051                                                 dbg_bpl_new[1] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 4);
1052                                                 dbg_bpl_new[2] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 8);
1053                                                 dbg_bpl_new[3] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 12);
1054                                                 dbg_bpl_new[4] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 16);
1055                                                 dbg_bpl_new[5] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 20);
1056                                                 dbg_bpl_new[6] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 24);
1057                                                 dbg_bpl_new[7] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 28);
1058                                                 dbg_bpl_new[8] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 32);
1059                                                 dbg_bpl_new[9] = PHPDBGBase.Char4ToInt (entirePack, nextFrame + 36);
1060
1061                                                 // look if breakpoint already exists in vector
1062                                                 for (i = 0; i < DBGBPList.size (); i++) {
1063                                                         dbg_bpl_tmp = (int[]) DBGBPList.get (i);
1064
1065                                                         if (dbg_bpl_tmp[8] == dbg_bpl_new[8]) {
1066                                                                 DBGBPList.remove (i);
1067
1068                                                                 break;
1069                                                         }
1070                                                 }
1071
1072                                                 // add breakpoint to vector
1073                                                 DBGBPList.add (dbg_bpl_new);
1074                                                 copyToLastBP (dbg_bpl_new);
1075
1076                                                 // mod no returned?
1077                                                 if (getModByNo (dbg_bpl_new[0]).equals ("")) {
1078                                                         String fileName;
1079
1080                                                         fileName = new String (getRawFrameData (entirePack, dbg_bpl_new[2]));
1081
1082                                                         if (dbg_bpl_new[0] != 0) {
1083                                                                 PHPDBGMod modNew;
1084
1085                                                                 modNew = new PHPDBGMod (dbg_bpl_new[0], fileName);
1086
1087                                                                 DBGMods.add (modNew);
1088                                                         }
1089                                                 }
1090                                                 break;
1091
1092                                         case PHPDBGBase.FRAME_VER:
1093                                                 break;
1094
1095                                         case PHPDBGBase.FRAME_SID:
1096                                                 sid = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 0);
1097                                                 break;
1098
1099                                         case PHPDBGBase.FRAME_SRCLINESINFO:
1100                                                 break;
1101
1102                                         case PHPDBGBase.FRAME_SRCCTXINFO:
1103                                                 break;
1104
1105                                         case PHPDBGBase.FRAME_LOG:
1106                                                 break;
1107
1108                                         case PHPDBGBase.FRAME_PROF:
1109                                                 break;
1110
1111                                         case PHPDBGBase.FRAME_PROF_C:
1112                                                 break;
1113
1114                                         case PHPDBGBase.FRAME_SET_OPT:
1115                                                 break;
1116                                 }
1117
1118                                 nextFrame += dbg_frame[1];                                                      // go to next frame
1119                         }
1120
1121                         // Now process command
1122                         switch(cmdReceived) {
1123                                 case PHPDBGBase.DBGC_REPLY:
1124                                         break;
1125
1126                                 case PHPDBGBase.DBGC_STARTUP:
1127                                         break;
1128
1129                                 case PHPDBGBase.DBGC_END:
1130                                         continueExecution();
1131                                         proxy.updateView();
1132                                         break;
1133
1134                                 case PHPDBGBase.DBGC_BREAKPOINT:
1135                                         BPUnderHit   = getBPUnderHit ();
1136                                         updateStackFrameList (stackList);
1137                                         break;
1138
1139                                 case PHPDBGBase.DBGC_STEPINTO_DONE:
1140                                 case PHPDBGBase.DBGC_STEPOVER_DONE:
1141                                 case PHPDBGBase.DBGC_STEPOUT_DONE:
1142                                 case PHPDBGBase.DBGC_EMBEDDED_BREAK:
1143                                 case PHPDBGBase.DBGC_PAUSE:
1144                                         BPUnderHit   = 1;
1145                                         updateStackFrameList (stackList);
1146                                         break;
1147
1148                                 case PHPDBGBase.DBGC_ERROR:
1149                                         stackList.clear ();
1150                                         updateStackFrameList (stackList);
1151                                         break;
1152
1153                                 case PHPDBGBase.DBGC_LOG:
1154                                         break;
1155
1156                                 case PHPDBGBase.DBGC_SID:
1157                                         break;
1158                         }
1159                 }
1160
1161                 return cmdReceived;                                         // Return the command we received with this block
1162         }
1163
1164     /**
1165      *
1166      */
1167
1168         public PHPStackFrame[] getStackList() {
1169                 return DBGStackList;
1170         }
1171
1172         /**
1173          * Reads from input buffer (response sent from DBG) the given number of chars
1174          * into frame buffer.
1175          *
1176          * @param buffer  The frame buffer where to store the read data from DBG.
1177          * @param bytes   The number of bytes (chars) which are to read from input stream.
1178          * @return        The number of bytes actually read.
1179          */
1180         private int readInput (char[] buffer, int bytes) throws IOException {
1181                 int bytesRead = 0;                                                                                      // Reset the bytes read counter
1182
1183                 for (int i = 0; i < bytes; i++) {                           // For the number of bytes we should read
1184                         if (in.ready ()) {                                                                              // If input stream is ready for reading
1185                                 buffer[i] = (char) (in.read () & 0x00FF);           // Read a char and store only the least significant 8-bits
1186                                 bytesRead++;                                        // Increment the bytes read counter
1187                         }
1188                         else {                                                  // Input stream is not ready
1189                                 break;                                              // Break the loop
1190                         }
1191                 }
1192
1193                 return bytesRead;                                                                                       // Return the number of bytes actually read
1194         }
1195
1196         /**
1197          * PHPProxy could stop the waiting for a response with this method.
1198          *
1199          */
1200         public void setShouldStop () {
1201                 this.shouldStop = true;
1202         }
1203
1204         /**
1205          * @param milliseconds The maximum time in milliseconds we wait for something
1206          *                     to be send from DBG.
1207          * @return             - true if something was received from DBG
1208          *                                         - false if nothing was send from DBG within the given time
1209          *
1210          */
1211         public boolean waitResponse (long milliseconds) throws IOException {
1212                 long timeout;
1213
1214                 timeout = System.currentTimeMillis () + milliseconds;           // Calculate the system time till we wait.
1215
1216                 while (System.currentTimeMillis () < timeout) {             // Is waiting time running out?
1217                         if (in.ready () || shouldStop) {                        //  No, so did we get something or should we stop now
1218                                 break;                                              //   Yes, break the waiting
1219                         }
1220                 }
1221
1222                 return in.ready ();                                         // true if we got something from DBG
1223         }
1224 }