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