stack frame bugs fixed
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDBGInterface.java
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 **********************************************************************/
11 package net.sourceforge.phpdt.internal.debug.core;
12
13 import java.io.IOException;
14 import java.io.BufferedReader;
15 import java.io.OutputStream;
16 import java.util.Vector;
17 import java.lang.System;
18 import org.eclipse.debug.core.DebugException;
19 import net.sourceforge.phpdt.internal.debug.core.model.PHPStackFrame;
20 import net.sourceforge.phpdt.internal.debug.core.model.PHPVariable;
21 import net.sourceforge.phpdt.internal.debug.core.model.PHPValue;
22 import net.sourceforge.phpdt.internal.debug.core.PHPDBGMod;
23
24 public class PHPDBGInterface {
25
26         // Public
27         public boolean sessionEnded= false;
28         public int sessType= -1;        
29         public int BPUnderHit= 0;
30         public String sessID= new String();
31         
32         // Private
33         private int[] LastBPRead= new int[10];
34         private Vector DBGBPList= new Vector();
35         private PHPStackFrame[] DBGStackList;
36         private PHPVariable[] DBGVariableList;
37         private Vector DBGMods= new Vector();
38         private Vector DBGVars= new Vector();
39         private BufferedReader in;
40         private OutputStream os;
41         private boolean shouldStop= false, isRef= false, hasChildren= false, isObject= false;
42         private String evalRet= new String("");
43         private String serGlobals= new String("");
44         private String typeRead= new String("");
45         private String className= new String("");
46         private int finalPos=0, refCounter=0, rawCounter=1000;
47          
48         public PHPDBGInterface(BufferedReader in, OutputStream os) {
49                 DBGBPList.clear();
50                 this.in= in;
51                 this.os= os;
52         }
53
54         public int addBreakpoint(String mod_name, int line) throws IOException {
55                 return setBreakpoint(mod_name, "", line, PHPDBGBase.BPS_ENABLED + PHPDBGBase.BPS_UNRESOLVED, 0, 0, 0, 0, 0);
56         }
57
58         public void removeBreakpoint(String mod_name, int line, int bpNo) throws IOException {
59                 setBreakpoint(mod_name, "", line, PHPDBGBase.BPS_DISABLED, 0, 0, 0, bpNo, 0);
60         }
61
62         public void requestDBGVersion() throws IOException {
63                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
64                 PHPDBGFrame DBGFrame= new PHPDBGFrame(PHPDBGBase.FRAME_VER);
65                 
66                 DBGPacket.addFrame(DBGFrame);
67                 
68                 DBGPacket.sendPacket(os);
69         }
70
71         public void addDBGModName(String modName) throws IOException {
72                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
73                 PHPDBGFrame DBGFrame= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
74                 
75                 rawCounter++;
76                 DBGFrame.addInt(rawCounter);                            // FRAME_RAWDATA ID
77                 DBGFrame.addInt(modName.length() + 1);          // length of rawdata (+ null char)
78                 DBGFrame.addString(modName);                            // file name
79                 DBGFrame.addChar('\0');                                         // null char
80
81                 DBGPacket.addFrame(DBGFrame);
82                 
83                 DBGPacket.sendPacket(os);
84         }
85
86         // Returns DBG Breakpoint ID
87         private int setBreakpoint(String mod_name, String condition, int line, int state, int istemp, int hitcount, int skiphits, int bpno, int isunderhit) throws IOException {
88                 int modNo= 0;
89
90                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
91                 PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_BPS);
92                 PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
93
94                 modNo= getModByName(mod_name);
95                 
96                 if(modNo >= 0) {
97                         DBGFrame1.addInt(modNo);        // mod number
98                 } else {
99                         DBGFrame1.addInt(0);            // mod number (0 use file name)
100                 }
101                 
102                 DBGFrame1.addInt(line);                 // line number
103                 
104                 if(modNo >= 0) {
105                         DBGFrame1.addInt(0);                    // use mod number
106                 } else {
107                         rawCounter++;
108                         DBGFrame1.addInt(rawCounter);   // ID of FRAME_RAWDATA to send file name
109                 }
110
111                 DBGFrame1.addInt(state);                // state BPS_*
112                 DBGFrame1.addInt(istemp);               // istemp
113                 DBGFrame1.addInt(hitcount);             // hit count
114                 DBGFrame1.addInt(skiphits);             // skip hits
115                 DBGFrame1.addInt(0);                    // ID of condition
116                 DBGFrame1.addInt(bpno);                 // breakpoint number
117                 DBGFrame1.addInt(isunderhit);   // is under hit
118                 
119                 if(modNo < 0) {
120                         DBGFrame2.addInt(rawCounter);                           // FRAME_RAWDATA ID
121                         DBGFrame2.addInt(mod_name.length() + 1);        // length of rawdata (+ null char)
122                         DBGFrame2.addString(mod_name);                          // file name
123                         DBGFrame2.addChar('\0');                                        // null char
124                         // First add file name data
125                         DBGPacket.addFrame(DBGFrame2);
126                 }
127
128                 // Second add command data
129                 DBGPacket.addFrame(DBGFrame1);
130
131                 DBGPacket.sendPacket(os);
132
133                 clearLastBP();
134
135                 // Wait response (1 second) and read response
136                 waitResponse(1000);
137                 flushAllPackets();
138
139                 return LastBPRead[8];
140         }
141
142         private void clearLastBP() {
143                 int i;
144
145                 for(i=0; i < LastBPRead.length; i++)
146                         LastBPRead[i]= 0;
147         }
148
149         private void copyToLastBP(int[] BPBody) {
150                 int i;
151
152                 for(i=0; i < LastBPRead.length; i++)
153                         LastBPRead[i]= BPBody[i];
154         }
155
156         public void continueExecution() throws IOException {
157                 BPUnderHit= 0;
158                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_CONTINUE);
159                 DBGPacket.sendPacket(os);
160         }
161
162         private int getBPUnderHit() {
163                 int i, BPUnder=0;
164                 int[] dbg_bpl_body= new int[10];
165
166                 // look for bp under hit
167                 for(i=0; i < DBGBPList.size(); i++) {
168                         dbg_bpl_body= (int[]) DBGBPList.get(i);
169                         if(dbg_bpl_body[9] == 1) {
170                                 BPUnder= dbg_bpl_body[8];
171                         }
172                 }
173                 return BPUnder;
174         }
175
176         public void stepInto() throws IOException {
177                 BPUnderHit= 0;
178                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPINTO);
179                 DBGPacket.sendPacket(os);
180         }
181
182         public void stepOver() throws IOException {
183                 BPUnderHit= 0;
184                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOVER);
185                 DBGPacket.sendPacket(os);
186         }
187
188         public void stepOut() throws IOException {
189                 BPUnderHit= 0;
190                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STEPOUT);
191                 DBGPacket.sendPacket(os);
192         }
193
194         public void stopExecution() throws IOException {
195                 BPUnderHit= 0;
196                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_STOP);
197                 DBGPacket.sendPacket(os);
198         }
199
200         public PHPVariable[] getVariables(PHPStackFrame stack) throws IOException, DebugException  {
201                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
202                 PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_EVAL);
203                 //PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
204         
205                 DBGFrame1.addInt(0);                                            // istr = raw data ID
206                 DBGFrame1.addInt(1);                                            // scope_id = -1 means current location, 0 never used, +1 first depth
207
208                 /*              
209                 String evalBlock= new String("$GLOBALS");
210                 DBGFrame2.addInt(1);                                            // FRAME_RAWDATA ID
211                 DBGFrame2.addInt(evalBlock.length() + 1);       // length of rawdata (+ null char)
212                 DBGFrame2.addString(evalBlock);                         // eval block
213                 DBGFrame2.addChar('\0');                                        // null char
214                 */
215                 
216                 // Add command data
217                 DBGPacket.addFrame(DBGFrame1);
218                 
219                 DBGPacket.sendPacket(os);
220
221                 waitResponse(1000);
222                 flushAllPackets();
223                 
224                 // Process serialized variables
225                 DBGVariableList= procVars(stack);
226
227                 return DBGVariableList;
228         }
229
230         public void evalBlock(String evalString) throws IOException, DebugException  {
231                 PHPDBGPacket DBGPacket= new PHPDBGPacket(PHPDBGBase.DBGA_REQUEST);
232                 PHPDBGFrame DBGFrame1= new PHPDBGFrame(PHPDBGBase.FRAME_EVAL);
233                 PHPDBGFrame DBGFrame2= new PHPDBGFrame(PHPDBGBase.FRAME_RAWDATA);
234
235                 rawCounter++;
236                 DBGFrame1.addInt(rawCounter);                           // istr = raw data ID
237                 DBGFrame1.addInt(1);                                            // scope_id = -1 means current location, 0 never used, +1 first depth
238
239                 DBGFrame2.addInt(rawCounter);                           // FRAME_RAWDATA ID
240                 DBGFrame2.addInt(evalString.length() + 1);      // length of rawdata (+ null char)
241                 DBGFrame2.addString(evalString);                        // eval block
242                 DBGFrame2.addChar('\0');                                        // null char
243
244                 // Add raw data first
245                 DBGPacket.addFrame(DBGFrame2);          
246                 // Add command data
247                 DBGPacket.addFrame(DBGFrame1);
248                 
249                 DBGPacket.sendPacket(os);
250
251                 waitResponse(1000);
252                 flushAllPackets();
253         }
254
255         public void flushAllPackets() throws IOException {
256                 while(readResponse() != 0);
257         }
258
259         public String getModByNo(int modNo) {
260                 int i;
261                 PHPDBGMod dbg_mod;
262
263                 // look for mod
264                 for(i=0; i < DBGMods.size(); i++) {
265                         dbg_mod= (PHPDBGMod) DBGMods.get(i);
266                         if(dbg_mod.getNo() == modNo) {
267                                 return dbg_mod.getName(); 
268                         }
269                 }
270                 return "";
271         }
272
273         private int getModByName(String modName) {
274                 int i;
275                 PHPDBGMod dbg_mod;
276
277                 // look for mod
278                 for(i=0; i < DBGMods.size(); i++) {
279                         dbg_mod= (PHPDBGMod) DBGMods.get(i);
280                         if(dbg_mod.getName().equalsIgnoreCase(modName)) {
281                                 return dbg_mod.getNo(); 
282                         }
283                 }
284                 return -1;
285         }
286
287         private String getRawFrameData(char[] framesInfo, int frameNo) {
288                 int nextFrame= 0;
289                 int[] dbg_frame= new int[2];
290                 
291                 while(nextFrame < framesInfo.length) {
292                         dbg_frame[0] = PHPDBGBase.Char4ToInt(framesInfo, nextFrame);            // frame name
293                         dbg_frame[1] = PHPDBGBase.Char4ToInt(framesInfo, nextFrame + 4);        // frame size
294
295                         nextFrame += 8;
296                         if(dbg_frame[1] == 0) return "";
297
298                         switch(dbg_frame[0]) {
299                                 case PHPDBGBase.FRAME_RAWDATA:
300                                         if(frameNo == PHPDBGBase.Char4ToInt(framesInfo, nextFrame)) {
301                                                 int toRead= PHPDBGBase.Char4ToInt(framesInfo, nextFrame + 4);
302                                                 return String.copyValueOf(framesInfo, nextFrame + 8, toRead);
303                                         }
304                                         break;
305                         }
306                         // go to next frame
307                         nextFrame += dbg_frame[1];
308                 }
309                 return "";
310         }
311
312         public PHPVariable[] getInstVars(PHPVariable phpVar) throws DebugException {
313                 Vector vecVars= new Vector();
314                 PHPVariable localPHPVar;
315                 int i=0;
316                 
317                 // already unserialized
318                 for(i=0; i < DBGVars.size(); i++) {
319                         localPHPVar= (PHPVariable)DBGVars.get(i);
320                         if(localPHPVar.getParent() == phpVar) {
321                                 vecVars.add(localPHPVar);
322                         }
323                 }
324                 PHPVariable[] arrVars= new PHPVariable[vecVars.size()];
325                 arrVars= (PHPVariable[]) vecVars.toArray(arrVars);
326
327                 return arrVars;
328         }
329         
330         private PHPVariable[] procVars(PHPStackFrame stack) throws DebugException {
331                 Vector vecVars= new Vector();
332                 
333                 // unserialize
334                 finalPos= 0;
335                 refCounter= 0;
336                 doUnserialize(stack, vecVars, null);
337
338                 DBGVars= vecVars;
339                 
340                 return(getInstVars(null));
341         }
342
343         private String readValue(String serialVars) throws DebugException {
344                 int startPos=0, endPos=0, lenStr=0, i=0, elements=0;
345                 String ret= new String("");
346
347                 switch(serialVars.charAt(0)) {
348                         case 'a':       // associative array, a:elements:{[index][value]...}
349                                 typeRead= "hash";
350                                 startPos= 1;
351                                 endPos= serialVars.indexOf(':', startPos + 1);
352                                 if(endPos == -1) return "";
353                                 finalPos += endPos + 2;
354                                 ret= new String(serialVars.substring(startPos + 1, endPos));
355                                 
356                                 hasChildren= true;
357                                 break;
358                         case 'O':       // object, O:name_len:"name":elements:{[attribute][value]...}
359                                 typeRead= "object";
360                                 
361                                 startPos= 1;
362                                 endPos= serialVars.indexOf(':', startPos + 1);
363                                 if(endPos == -1) return "";
364                                 
365                                 // get object class
366                                 lenStr= Integer.parseInt(serialVars.substring(startPos + 1, endPos));
367                                 startPos= endPos + 2;
368                                 endPos= lenStr + startPos;
369                                 className= new String(serialVars.substring(startPos, endPos).toString());
370
371                                 // get num of elements
372                                 startPos= endPos + 1;
373                                 endPos= serialVars.indexOf(':', startPos + 1);
374                                 if(endPos == -1) return "";
375                                 finalPos += endPos + 2;
376                                 ret= new String(serialVars.substring(startPos + 1, endPos));
377
378                                 isObject= true;
379                                 hasChildren= true;                              
380                                 break;
381                         case 's':       // string, s:length:"data";
382                                 typeRead= "string";
383                                 startPos= 1;
384                                 endPos= serialVars.indexOf(':', startPos + 1);
385                                 if(endPos == -1) return "";
386
387                                 lenStr= Integer.parseInt(serialVars.substring(startPos + 1, endPos));
388                                 startPos= endPos + 2;
389                                 endPos= lenStr + startPos;
390                                 ret= new String(serialVars.substring(startPos, endPos).toString());
391                                 finalPos += endPos + 2; 
392                                 break;
393                         case 'i':       // integer, i:123;
394                                 typeRead= "integer";
395                                 startPos= 1;
396                                 endPos= serialVars.indexOf(';', startPos + 1);
397                                 if(endPos == -1) return "";
398
399                                 ret= new String(serialVars.substring(startPos + 1, endPos).toString());
400                                 finalPos += endPos + 1;
401                                 break;
402                         case 'd':       // double (float), d:1.23;
403                                 typeRead= "double";
404                                 startPos= 1;
405                                 endPos= serialVars.indexOf(';', startPos + 1);
406                                 if(endPos == -1) return "";
407         
408                                 ret= new String(serialVars.substring(startPos + 1, endPos).toString());
409                                 finalPos += endPos + 1;
410                                 break;
411                         case 'N':       // NULL, N;
412                                 typeRead= "null";
413                                 ret= "nil";
414                                 finalPos += 2;
415                                 break;
416                         case 'b':       // bool, b:0 or 1
417                                 typeRead= "boolean";
418                                 ret= (serialVars.charAt(2) == '1')?"true":"false";
419                                 finalPos += endPos + 4;
420                                 break;
421                         case 'z':       // resource, z:typename_len:"typename":valres;
422                                 typeRead= "resource";
423                                 
424                                 startPos= 1;
425                                 endPos= serialVars.indexOf(':', startPos + 1);
426                                 if(endPos == -1) return "";
427                 
428                                 // get resource type name
429                                 lenStr= Integer.parseInt(serialVars.substring(startPos + 1, endPos));
430                                 startPos= endPos + 2;
431                                 endPos= lenStr + startPos;
432                                 className= new String(serialVars.substring(startPos, endPos).toString());
433
434                                 // get resource value
435                                 startPos= endPos + 1;
436                                 endPos= serialVars.indexOf(';', startPos + 1);
437                                 if(endPos == -1) return "";
438                                 ret= new String(serialVars.substring(startPos + 1, endPos));
439                                 finalPos += endPos + 1;
440                                 break;
441                         case 'r':
442                         case 'R':
443                                 typeRead= "reference";
444                                 startPos= 1;
445                                 endPos= serialVars.indexOf(';', startPos + 1);
446                                 if(endPos == -1) return "0";
447
448                                 ret= new String(serialVars.substring(startPos + 1, endPos));
449                                 finalPos += endPos + 1;
450                                 isRef= true;
451                                 break;
452                         case ';':
453                                 typeRead= "unknown";
454                                 finalPos+= 1;
455                                 break;
456                         case '?':
457                                 finalPos+= 1;
458                         default:
459                                 finalPos+= 1;
460                                 typeRead= "unknown";
461                                 break;
462                 }
463                 return ret;
464         }
465
466         private void doUnserialize(PHPStackFrame stack, Vector vecVars, PHPVariable parent) throws DebugException {
467                 int i, elements= 0;
468                 PHPVariable newVar= null;
469                 String value= new String("");
470                 String name= new String("");
471                 String tmp= new String("");
472                 String[] tmpSplit;
473
474                 if(finalPos > serGlobals.length() || serGlobals.equals("") || serGlobals.substring(finalPos).equals("")) return;
475
476                 isRef= false;
477                 hasChildren= false;
478                 isObject= false;
479                 name= readValue(serGlobals.substring(finalPos));
480                 
481                 if(hasChildren) {
482                         // main array
483                         if(refCounter == 0) {
484                                 value= name;
485                                 name= "";
486                         }
487                 } else {
488                         hasChildren= false;
489                         isRef= false;
490                         value= readValue(serGlobals.substring(finalPos));
491                         // replaceAll doesn't work, why???
492                         tmpSplit= value.split("\\\\");
493                         value= "";
494                         for(i= 0; i < tmpSplit.length; i++) {
495                                 value= value + tmpSplit[i];
496                                 if(!tmpSplit[i].equals("")) {
497                                         if(i < (tmpSplit.length - 1)) {
498                                                 value= value + "\\";
499                                         }
500                                 }
501                         }
502                 }
503                 
504                 if(!name.equals("")) {
505                         if(isRef) {
506                                 PHPVariable varPHP;
507                                 for(i=0; i < vecVars.size(); i++) {
508                                         varPHP= (PHPVariable) vecVars.get(i);
509                                         if(varPHP.getObjectId().equals(value)) {
510                                                 newVar= new PHPVariable(stack, name, "local", true, (PHPValue)varPHP.getValue());
511                                                 break;                                          
512                                         }
513                                 }
514                                 if(newVar == null) {
515                                         newVar= new PHPVariable(stack, name, "local", false, null);
516                                 }
517                         } else {
518                                 refCounter++;
519                                 newVar= new PHPVariable(stack, name, "local", value, typeRead, hasChildren, Integer.toString(refCounter), className);
520                         }
521                         newVar.setParent(parent);
522                         vecVars.add(newVar);
523                 }
524                 if(hasChildren) {
525                         elements= Integer.parseInt(value);
526                         for(i=0; i < elements; i++)
527                                 doUnserialize(stack, vecVars, newVar);
528
529                         // skip "}"
530                         finalPos += 1;
531                 }
532         }
533
534         public int readResponse() throws IOException {
535                 int bytesToRead=0, nextFrame=0, i=0, cmdReceived=0, stackIndex=0;
536                 char[] dbg_header_struct_read= new char[16];
537                 int[] dbg_header_struct= new int[4];
538                 int[] dbg_bpl_tmp= new int[10];
539                 int[] dbg_frame= new int[2];
540                 int[] dbg_eval_tmp= new int[3];
541                 Vector rawList= new Vector();
542                 Vector stackList= new Vector();
543                 PHPStackFrame[] newStackList;
544                 
545                 rawList.clear();
546                 stackList.clear();
547                 // Read from input
548                 while(readInput(dbg_header_struct_read, 16) != 0) {
549                         dbg_header_struct[0] = PHPDBGBase.Char4ToInt(dbg_header_struct_read, 0);
550                         dbg_header_struct[1] = PHPDBGBase.Char4ToInt(dbg_header_struct_read, 4);
551                         dbg_header_struct[2] = PHPDBGBase.Char4ToInt(dbg_header_struct_read, 8);
552                         dbg_header_struct[3] = PHPDBGBase.Char4ToInt(dbg_header_struct_read, 12);
553                         
554                         // Check DBG sync bytes
555                         if(dbg_header_struct[0] != 0x5953) return 0;
556                         
557                         cmdReceived= dbg_header_struct[1];
558                         bytesToRead= dbg_header_struct[3];
559
560                         //System.out.println("Response Received: " + cmdReceived);
561                         char[] entirePack= new char[bytesToRead];
562
563                         if(bytesToRead > 0) {
564                                 if(readInput(entirePack, bytesToRead) < bytesToRead) return 0;
565                         }
566                         
567                         // First process frames
568                         nextFrame= 0;
569                         while(nextFrame < bytesToRead) {
570                                 dbg_frame[0] = PHPDBGBase.Char4ToInt(entirePack, nextFrame);            // frame name
571                                 dbg_frame[1] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 4);        // frame size
572                                 nextFrame += 8;
573                                 if(dbg_frame[1] == 0) return 0;
574                                 switch(dbg_frame[0]) {
575                                         case PHPDBGBase.FRAME_STACK:
576                                                 int[] dbg_stack_new= new int[4];
577                                                 dbg_stack_new[0] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 0);    // line no
578                                                 dbg_stack_new[1] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 4);    // mod no
579                                                 dbg_stack_new[2] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 8);    // scope id
580                                                 dbg_stack_new[3] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 12);   // id of description string
581
582                                                 stackIndex++;
583                                                 if(dbg_stack_new[1] != 0) {                                             
584                                                         PHPStackFrame newStack= new PHPStackFrame(null, getModByNo(dbg_stack_new[1]), dbg_stack_new[0], stackIndex, getRawFrameData(entirePack, dbg_stack_new[3]), dbg_stack_new[1]);
585                                                         stackList.add(newStack);
586                                                 }
587                                                 break;
588                                         case PHPDBGBase.FRAME_SOURCE:
589                                                 break;
590                                         case PHPDBGBase.FRAME_SRC_TREE:
591                                                 break;
592                                         case PHPDBGBase.FRAME_RAWDATA:
593                                                 break;
594                                         case PHPDBGBase.FRAME_ERROR:
595                                                 break;
596                                         case PHPDBGBase.FRAME_EVAL:
597                                                 String evalString= new String("");
598                                                 dbg_eval_tmp[0] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 0); // istr
599                                                 dbg_eval_tmp[1] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 4); // iresult
600                                                 dbg_eval_tmp[2] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 8); // ierror
601
602                                                 evalRet= getRawFrameData(entirePack, dbg_eval_tmp[1]);
603                                                 evalString= getRawFrameData(entirePack, dbg_eval_tmp[0]);
604                                                 serGlobals= evalRet;
605                                                 break;
606                                         case PHPDBGBase.FRAME_BPS:
607                                                 break;
608                                         case PHPDBGBase.FRAME_BPL:
609                                                 int[] dbg_bpl_new= new int[10];
610                                                 dbg_bpl_new[0] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 0);
611                                                 dbg_bpl_new[1] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 4);
612                                                 dbg_bpl_new[2] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 8);
613                                                 dbg_bpl_new[3] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 12);
614                                                 dbg_bpl_new[4] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 16);
615                                                 dbg_bpl_new[5] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 20);
616                                                 dbg_bpl_new[6] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 24);
617                                                 dbg_bpl_new[7] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 28);
618                                                 dbg_bpl_new[8] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 32);
619                                                 dbg_bpl_new[9] = PHPDBGBase.Char4ToInt(entirePack, nextFrame + 36);
620         
621                                                 // look if breakpoint already exists in vector
622                                                 for(i=0; i < DBGBPList.size(); i++) {
623                                                         dbg_bpl_tmp= (int[]) DBGBPList.get(i);
624                                                         if(dbg_bpl_tmp[8] == dbg_bpl_new[8]) {
625                                                                 DBGBPList.remove(i);
626                                                                 break;
627                                                         }
628                                                 }
629
630                                                 // add breakpoint to vector
631                                                 DBGBPList.add(dbg_bpl_new);
632                                                 copyToLastBP(dbg_bpl_new);
633                                                 
634                                                 // mod no returned?
635                                                 if(getModByNo(dbg_bpl_new[0]).equals("")) {
636                                                         String fileName= new String(getRawFrameData(entirePack, dbg_bpl_new[2]));
637                                                         // Remove '\0' char
638                                                         if(fileName.length() > 0) fileName= fileName.substring(0, fileName.length() - 1);
639                                                         if(dbg_bpl_new[0] != 0) {
640                                                                 PHPDBGMod modNew= new PHPDBGMod(dbg_bpl_new[0], fileName);
641                                                                 DBGMods.add(modNew);
642                                                         }
643                                                 }                                                       
644                                                 break;
645                                         case PHPDBGBase.FRAME_VER:
646                                                 break;
647                                         case PHPDBGBase.FRAME_SID:
648                                                 break;
649                                         case PHPDBGBase.FRAME_SRCLINESINFO:
650                                                 break;
651                                         case PHPDBGBase.FRAME_SRCCTXINFO:
652                                                 break;
653                                         case PHPDBGBase.FRAME_LOG:
654                                                 break;
655                                         case PHPDBGBase.FRAME_PROF:
656                                                 break;
657                                         case PHPDBGBase.FRAME_PROF_C:
658                                                 break;
659                                         case PHPDBGBase.FRAME_SET_OPT:
660                                                 break;
661                                 }
662                                 // go to next frame
663                                 nextFrame += dbg_frame[1];
664                         }
665                         
666                         // Now process command
667                         switch(cmdReceived) {
668                                 case PHPDBGBase.DBGC_REPLY:
669                                         break;
670                                 case PHPDBGBase.DBGC_STARTUP:
671                                         break;
672                                 case PHPDBGBase.DBGC_END:
673                                         sessionEnded= true;
674                                         break;
675                                 case PHPDBGBase.DBGC_BREAKPOINT:
676                                         newStackList= new PHPStackFrame[stackList.size()];
677                                         newStackList= (PHPStackFrame[]) stackList.toArray(newStackList);
678                                         DBGStackList= newStackList;
679                                         BPUnderHit= getBPUnderHit();
680                                         break;
681                                 case PHPDBGBase.DBGC_STEPINTO_DONE:
682                                 case PHPDBGBase.DBGC_STEPOVER_DONE:
683                                 case PHPDBGBase.DBGC_STEPOUT_DONE:
684                                 case PHPDBGBase.DBGC_EMBEDDED_BREAK:
685                                         BPUnderHit= 1;
686                                         newStackList= new PHPStackFrame[stackList.size()];
687                                         newStackList= (PHPStackFrame[]) stackList.toArray(newStackList);
688                                         DBGStackList= newStackList;
689                                         break;
690                                 case PHPDBGBase.DBGC_ERROR:
691                                         newStackList= new PHPStackFrame[stackList.size()];
692                                         newStackList= (PHPStackFrame[]) stackList.toArray(newStackList);
693                                         DBGStackList= newStackList;
694                                         break;
695                                 case PHPDBGBase.DBGC_LOG:
696                                         break;
697                                 case PHPDBGBase.DBGC_SID:
698                                         break;
699                                 case PHPDBGBase.DBGC_PAUSE:
700                                         break;
701                         }
702                 }
703
704                 return cmdReceived;
705         }
706
707         public PHPStackFrame[] getStackList() {
708                 return DBGStackList;
709         }
710
711         private int readInput(char[] buffer, int bytes) throws IOException {
712                 int bytesRead= 0;
713
714                 for(int i=0; i < bytes; i++) {
715                         if(in.ready()) {
716                                 buffer[i]= (char) (in.read() & 0x00FF);
717                                 bytesRead++;
718                         }
719                         else
720                                 break;                          
721                 }
722                 return bytesRead;
723         }
724         
725         public void setShouldStop() {
726                 this.shouldStop= true;
727         }
728
729         public void waitResponse(long milliseconds) throws IOException {
730                 long timeout= System.currentTimeMillis() + milliseconds;
731                 while(System.currentTimeMillis() < timeout) {
732                         if(in.ready() || shouldStop) {
733                                 break;
734                         }
735                 }
736         }
737 }