KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > DbgPacket


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface;
21
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.io.UnsupportedEncodingException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import org.netbeans.modules.scripting.php.dbginterface.models.DebugError;
32 import org.netbeans.modules.scripting.php.dbginterface.models.DebugFrame;
33 import org.netbeans.modules.scripting.php.dbginterface.models.Variable;
34 import org.openide.ErrorManager;
35 import org.openide.text.Line;
36
37 /**
38  *
39  * @author marcow
40  */

41 public class DbgPacket {
42     private static final int PACKET_HEADER_SIZE = 16;
43     private static final int FRAME_HEADER_SIZE = 8;
44     
45     private int cmd;
46     private int flags;
47     private int size;
48     private int currentRawId;
49     private List JavaDoc<Frame> frames = new ArrayList JavaDoc<Frame>();
50     
51     /** Creates a new instance of DbgPacket */
52     public DbgPacket(int cmd) {
53         this.cmd = cmd;
54     }
55     
56     public void addFrame(Frame frame) {
57         frames.add(frame);
58         size += frame.getSize();
59     }
60     
61     public void setFlags(int flags) {
62         this.flags = flags;
63     }
64     
65     public void send(OutputStream JavaDoc out) throws IOException JavaDoc {
66         System.err.println("mw DbgPacket.send(" + cmd + ")");
67         byte[] header = new byte[PACKET_HEADER_SIZE];
68         
69         copyToByteArray(header, 0, DbgConstants.DBG_SYNC);
70         copyToByteArray(header, 4, cmd);
71         copyToByteArray(header, 8, flags);
72         copyToByteArray(header, 12, size);
73         
74         out.write(header);
75         out.flush();
76
77         for (Frame f : frames) {
78             f.send(out);
79         }
80     }
81     
82     public boolean isWaitAck() {
83         return (flags & DbgConstants.DBGF_WAITACK) != 0;
84     }
85     
86     public static DbgPacket receive(InputStream JavaDoc in) throws IOException JavaDoc {
87         byte[] header = new byte[PACKET_HEADER_SIZE];
88         
89         if (in.read(header) < PACKET_HEADER_SIZE) {
90             return null;
91         }
92             
93         if (intFromByteArray(header, 0) != DbgConstants.DBG_SYNC) {
94             return null;
95         }
96             
97         DbgPacket ret = new DbgPacket(intFromByteArray(header, 4));
98             
99         ret.flags = intFromByteArray(header, 8);
100         ret.size = intFromByteArray(header, 12);
101         ret.frames = Frame.receiveFrames(in, ret.size);
102
103         return ret;
104     }
105     
106     public String JavaDoc toString() {
107         String JavaDoc ret = "DbgPacket([" + cmd + ", " + flags + ", " + size + "]";
108         
109         if (frames != null) {
110             for (Frame f : frames) {
111                 ret += "\n\t" + f.toString();
112             }
113         }
114         
115         return ret + ")";
116     }
117     
118     public Frame getFirstFrame() {
119         if (frames == null || frames.size() == 0) {
120             return null;
121         }
122         
123         return frames.get(0);
124     }
125
126     public void handle(DbgServerHandler handler) {
127         System.err.println("mw packet returned= " + this);
128         
129         if (cmd == DbgConstants.DBGC_STARTUP && flags == (DbgConstants.DBGF_STARTED | DbgConstants.DBGF_WAITACK)) {
130             handler.setBreakpoints();
131             handler.resume();
132             
133             return;
134         }
135
136         if (cmd == DbgConstants.DBGF_FINISHED) {
137             handler.finish();
138             
139             return;
140         }
141         
142         if (frames != null) {
143             for (Frame f : frames) {
144                 f.handle(handler);
145             }
146         }
147         
148         if (cmd == DbgConstants.DBGC_BREAKPOINT || cmd == DbgConstants.DBGC_STEPINTO_DONE ||
149                 cmd == DbgConstants.DBGC_STEPOUT_DONE || cmd == DbgConstants.DBGC_STEPOVER_DONE) {
150             updateCallStack(handler);
151             handler.setSuspended(true);
152         }
153         
154         if (cmd == DbgConstants.DBGC_ERROR) {
155             handleError(handler);
156         }
157     }
158     
159     public List JavaDoc<Variable> getEvalValue() {
160         if (frames == null) {
161             return null;
162         }
163         
164         for (Frame f : frames) {
165             if (f instanceof FrameEval) {
166                 return ((FrameEval)f).getEvalValue();
167             }
168         }
169         
170         return null;
171     }
172     
173     protected int getNewRawId() {
174         return ++currentRawId;
175     }
176     
177     private static void copyToByteArray(byte[] target, int offset, int value) {
178         target[offset + 0] = (byte)((value >> 24) & 0xff);
179         target[offset + 1] = (byte)((value >> 16) & 0xff);
180         target[offset + 2] = (byte)((value >> 8) & 0xff);
181         target[offset + 3] = (byte)((value >> 0) & 0xff);
182     }
183     
184     private static int intFromByteArray(byte[] target, int offset) {
185         int ret = 0;
186         
187         ret |= ((int)target[offset + 0] & 0xff) << 24;
188         ret |= ((int)target[offset + 1] & 0xff) << 16;
189         ret |= ((int)target[offset + 2] & 0xff) << 8;
190         ret |= ((int)target[offset + 3] & 0xff) << 0;
191         
192         return ret;
193     }
194     
195     private void updateCallStack(DbgServerHandler handler) {
196         List JavaDoc<DebugFrame> dFrames = new ArrayList JavaDoc<DebugFrame>();
197         boolean firstFrame = true;
198         
199         for (Frame frame : frames) {
200             if (frame instanceof FrameStack) {
201                 FrameStack sFrame = (FrameStack)frame;
202                 String JavaDoc desc = sFrame.getDesc();
203                 String JavaDoc method = "";
204                 int idx;
205                 
206                 if ((idx = desc.lastIndexOf("::")) >= 0) {
207                     method = desc.substring(idx + 2);
208                 }
209                 else {
210                     method = desc;
211                 }
212                 
213                 System.err.println("mw DbgPacket.updateCallStack() method= " + method);
214                 
215                 Line line = findLine(sFrame, handler);
216                 
217                 dFrames.add(new DebugFrame(handler, line, method, sFrame.getScope()));
218         
219                 if (firstFrame) {
220                     handler.setCurrentLine(line);
221                     handler.handleCurrentLine();
222                     firstFrame = false;
223                 }
224             }
225         }
226         
227         handler.setCallStack(dFrames);
228     }
229     
230     private void handleError(DbgServerHandler handler) {
231         Line line = null;
232         boolean canContinue = true;
233         boolean canResume = true;
234         
235         for (Frame f : frames) {
236             if (f instanceof FrameStack) {
237                 line = findLine((FrameStack)f, handler);
238                 
239                 break;
240             }
241         }
242         
243         for (Frame f : frames) {
244             if (f instanceof FrameError) {
245                 FrameError eFrame = (FrameError)f;
246                 int type = eFrame.getType();
247                 String JavaDoc desc = eFrame.getDesc();
248                 
249                 handler.addError(new DebugError(line, type, desc));
250
251                 if (type == DbgConstants.ERR_CORE_ERROR || type == DbgConstants.ERR_ERROR ||
252                         type == DbgConstants.ERR_PARSE) {
253                     canContinue = false;
254                     canResume = false;
255                 }
256                 else if (type == DbgConstants.ERR_CORE_WARNING) {
257                     canResume = false;
258                 }
259             }
260         }
261         
262         if (canResume) {
263             handler.resume();
264             
265             return;
266         }
267         
268         if (canContinue) {
269             handler.setSuspended(true);
270         }
271     }
272     
273     private Line findLine(FrameStack sFrame, DbgServerHandler handler) {
274         int modNo = sFrame.getModNo();
275         
276         String JavaDoc sourceFileName = handler.getSourceFileInfo(modNo);
277         
278         if (sourceFileName == null) {
279             String JavaDoc s = sFrame.getDesc();
280             int idx;
281                 
282             if ((idx = s.lastIndexOf("::")) >= 0) {
283                 sourceFileName = s.substring(0, idx);
284             }
285             else {
286                 handler.updateSourceTree();
287                 sourceFileName = handler.getSourceFileInfo(modNo);
288             }
289         }
290         
291         System.err.println("mw DbgPacket.updateCallStack() sourceFileName= " + sourceFileName);
292             
293         return Utils.getLine(handler.getSourceMap().mapToSourceFileDataObject(sourceFileName),
294                     sFrame.getLineNo());
295     }
296     
297     public static class Frame {
298         static private Map JavaDoc<Integer JavaDoc, Frame> map;
299         
300         protected byte[] buffer;
301         protected int type; // It's called framename but it's more an type
302

303         private Frame() {
304         }
305         
306         public int getSize() {
307             int ret = FRAME_HEADER_SIZE;
308             
309             if (buffer != null) {
310                 ret += buffer.length;
311             }
312             
313             return ret;
314         }
315         
316         public void send(OutputStream JavaDoc out) throws IOException JavaDoc {
317             byte[] header = new byte[FRAME_HEADER_SIZE];
318         
319             copyToByteArray(header, 0, type);
320             copyToByteArray(header, 4, (buffer != null ? buffer.length : 0));
321
322             try {
323                 out.write(header);
324                 
325                 if (buffer != null) {
326                     out.write(buffer);
327                 }
328                 
329                 out.flush();
330             }
331             catch (Exception JavaDoc e) {
332                 ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
333             }
334         }
335
336         public static List JavaDoc<Frame> receiveFrames(InputStream JavaDoc in, int size) throws IOException JavaDoc {
337             if (size == 0) {
338                 return null;
339             }
340             
341             if (map == null) {
342                 initMap();
343             }
344             
345             byte[] recBuffer = new byte[size];
346             int offset = 0;
347             
348             if (in.read(recBuffer) < size) {
349                 // We did not get all the promised bytes!
350
return null;
351             }
352             
353             List JavaDoc<Frame> ret = new ArrayList JavaDoc<Frame>();
354             List JavaDoc<FrameRawdata> raw = new ArrayList JavaDoc<FrameRawdata>();
355             
356             while (offset < size) {
357                 // Frame header
358
int recType = intFromByteArray(recBuffer, offset);
359                 int recFrameSize = intFromByteArray(recBuffer, offset + 4);
360                 offset += 8;
361                 
362                 Frame f = map.get(recType).receive(recBuffer, offset, recFrameSize);
363                 
364                 if (recType == DbgConstants.FRAME_RAWDATA) {
365                     raw.add((FrameRawdata)f);
366                 }
367                 else {
368                     ret.add(f);
369                 }
370                 
371                 offset += recFrameSize;
372             }
373             
374             for (Frame f : ret) {
375                 f.resolveRawRefs(raw);
376             }
377             
378             assert raw.isEmpty();
379             
380             return ret;
381         }
382                 
383         // This had to be overridden by the different Frame types.
384
protected Frame receive(byte[] buffer, int offset, int size) {
385             return null;
386         }
387         
388         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
389         }
390         
391         protected String JavaDoc bufferToString() {
392             if (buffer == null) {
393                 return "";
394             }
395             
396             String JavaDoc ret = "[";
397             for (int i = 0; i < buffer.length; i++) {
398                 ret += "" + buffer[i] + ", ";
399             }
400             
401             ret += "]";
402             
403             return ret;
404         }
405         
406         protected void handle(DbgServerHandler handler) {
407         }
408         
409         private static void initMap() {
410             map = new HashMap JavaDoc<Integer JavaDoc, Frame>();
411             
412             map.put(DbgConstants.FRAME_STACK, new FrameStack());
413             map.put(DbgConstants.FRAME_SOURCE, new FrameSource());
414             map.put(DbgConstants.FRAME_SRC_TREE, new FrameSrcTree());
415             map.put(DbgConstants.FRAME_RAWDATA, new FrameRawdata());
416             map.put(DbgConstants.FRAME_ERROR, new FrameError());
417             map.put(DbgConstants.FRAME_EVAL, new FrameEval());
418             map.put(DbgConstants.FRAME_BPS, new FrameBps());
419             map.put(DbgConstants.FRAME_BPL, new FrameBpl());
420             map.put(DbgConstants.FRAME_VER, new FrameVer());
421             map.put(DbgConstants.FRAME_SID, new FrameSid());
422             map.put(DbgConstants.FRAME_SRCLINESINFO, new FrameSrcLinesInfo());
423             map.put(DbgConstants.FRAME_SRCCTXINFO, new FrameSrcCtxInfo());
424             map.put(DbgConstants.FRAME_LOG, new FrameLog());
425             map.put(DbgConstants.FRAME_PROF, new FrameProf());
426             map.put(DbgConstants.FRAME_PROF_C, new FrameProfC());
427             map.put(DbgConstants.FRAME_SET_OPT, new FrameSetOpt());
428         }
429     }
430     
431     public static class FrameVer extends Frame {
432         private int major;
433         private int minor;
434         private int iDesc;
435         private FrameRawdata desc;
436         
437         public FrameVer() {
438             type = DbgConstants.FRAME_VER;
439         }
440                 
441         public String JavaDoc toString() {
442             return "DbgPacket.FrameVer(" + major + "." + minor + ", iDesc= " + iDesc + ", desc= " + desc + ")";
443         }
444         
445         protected Frame receive(byte[] buffer, int offset, int size) {
446             // assert size == 12;
447
System.err.println("mw DbgPacket.FrameVer.receive() size= " + size);
448             
449             FrameVer ret = new FrameVer();
450             
451             ret.major = intFromByteArray(buffer, offset);
452             ret.minor = intFromByteArray(buffer, offset + 4);
453             ret.iDesc = intFromByteArray(buffer, offset + 8);
454
455             return ret;
456         }
457
458         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
459             Iterator JavaDoc<FrameRawdata> it = list.iterator();
460             
461             while (it.hasNext()) {
462                 FrameRawdata f = it.next();
463                 
464                 if (f.rawid == iDesc) {
465                     desc = f;
466                     it.remove();
467                     
468                     break;
469                 }
470             }
471         }
472     }
473
474     public static class FrameSid extends Frame {
475         private int iSid;
476         private FrameRawdata sid;
477         private int sesstype;
478                 
479         protected FrameSid() {
480             type = DbgConstants.FRAME_SID;
481         }
482         
483         public String JavaDoc toString() {
484             return "DbgPacket.FrameSid(iSid= " + iSid + ", sesstype= " + sesstype + ", sid= " + sid + ")";
485         }
486         
487         protected Frame receive(byte[] buffer, int offset, int size) {
488             assert size == 8;
489             
490             FrameSid ret = new FrameSid();
491             
492             ret.iSid = intFromByteArray(buffer, offset);
493             ret.sesstype = intFromByteArray(buffer, offset + 4);
494
495             return ret;
496         }
497         
498         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
499             Iterator JavaDoc<FrameRawdata> it = list.iterator();
500             
501             while (it.hasNext()) {
502                 FrameRawdata f = it.next();
503                 
504                 if (f.rawid == iSid) {
505                     sid = f;
506                     it.remove();
507                     
508                     break;
509                 }
510             }
511         }
512         
513         protected void handle(DbgServerHandler handler) {
514             handler.setSessionId(sid.getString());
515         }
516     }
517
518     public static class FrameStack extends Frame {
519         private int lineNo;
520         private int modNo;
521         private int scope;
522         private int iDesc;
523         private FrameRawdata desc;
524         
525         public FrameStack() {
526             type = DbgConstants.FRAME_STACK;
527         }
528         
529         public String JavaDoc toString() {
530             return "DbgPacket.FrameStack(lineNo= " + lineNo + ", modNo= " + modNo + ", scope= " + scope +
531                     ", iDesc= " + iDesc + ", desc= " + desc + ")";
532         }
533         
534         protected String JavaDoc getDesc() {
535             return desc.getString();
536         }
537         
538         protected int getLineNo() {
539             return lineNo;
540         }
541         
542         protected int getScope() {
543             return scope;
544         }
545         
546         protected int getModNo() {
547             return modNo;
548         }
549         
550         protected Frame receive(byte[] buffer, int offset, int size) {
551             assert size == 16;
552          
553             FrameStack ret = new FrameStack();
554             
555             ret.lineNo = intFromByteArray(buffer, offset);
556             ret.modNo = intFromByteArray(buffer, offset + 4);
557             ret.scope = intFromByteArray(buffer, offset + 8);
558             ret.iDesc = intFromByteArray(buffer, offset + 12);
559             
560             return ret;
561         }
562         
563         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
564             Iterator JavaDoc<FrameRawdata> it = list.iterator();
565             
566             while (it.hasNext()) {
567                 FrameRawdata f = it.next();
568                 
569                 if (f.rawid == iDesc) {
570                     desc = f;
571                     it.remove();
572                     
573                     break;
574                 }
575             }
576         }
577     }
578     
579     public static class FrameSource extends Frame {
580         private int modNo;
581         private int filePos;
582         private int error;
583         private int fullSize;
584         private int iModName;
585         private FrameRawdata modName;
586         private int iText;
587         private FrameRawdata text;
588         
589         protected FrameSource() {
590             type = DbgConstants.FRAME_SOURCE;
591         }
592         
593         public FrameSource(int _modNo, int _filePos) {
594             this();
595             buffer = new byte[8];
596             copyToByteArray(buffer, 0, _modNo);
597             copyToByteArray(buffer, 4, _filePos);
598         }
599         
600         public String JavaDoc toString() {
601             return "DbgPacket.FrameSource(modNo= " + modNo + ", filePos= " + filePos +
602                     ", error= " + error + ", fullSize= " + fullSize + ", modName= " + modName +
603                     ", text= " + text + ")" +
604                     "\n\t\t" + bufferToString();
605
606         }
607         protected Frame receive(byte[] buffer, int offset, int size) {
608             assert size == 24;
609             
610             FrameSource ret = new FrameSource();
611             
612             ret.modNo = intFromByteArray(buffer, offset);
613             ret.filePos = intFromByteArray(buffer, offset + 4);
614             ret.error = intFromByteArray(buffer, offset + 8);
615             ret.fullSize = intFromByteArray(buffer, offset + 12);
616             ret.iModName = intFromByteArray(buffer, offset + 16);
617             ret.iText = intFromByteArray(buffer, offset + 20);
618             
619             return ret;
620         }
621
622         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
623             Iterator JavaDoc<FrameRawdata> it = list.iterator();
624             
625             while (it.hasNext()) {
626                 FrameRawdata f = it.next();
627                 
628                 if (f.rawid == iModName) {
629                     modName = f;
630                     it.remove();
631                 }
632                 if (f.rawid == iText) {
633                     text = f;
634                     it.remove();
635                 }
636             }
637         }
638
639     }
640     
641     public static class FrameSrcTree extends Frame {
642         private int parentModNo;
643         private int parentLineNo;
644         private int modNo;
645         private int iModName;
646         private FrameRawdata modName;
647         
648         public FrameSrcTree() {
649             type = DbgConstants.FRAME_SRC_TREE;
650         }
651         
652         public String JavaDoc toString() {
653             return "DbgPacket.FrameSrcTree(parentModNo= " + parentModNo + ", parentLineNo= " + parentLineNo +
654                     ", modNo= " + modNo + ", modName= " + modName + ")";
655         }
656         
657         protected Frame receive(byte[] buffer, int offset, int size) {
658             assert size == 16;
659             
660             FrameSrcTree ret = new FrameSrcTree();
661             
662             ret.parentModNo = intFromByteArray(buffer, offset);
663             ret.parentLineNo = intFromByteArray(buffer, offset + 4);
664             ret.modNo = intFromByteArray(buffer, offset + 8);
665             ret.iModName = intFromByteArray(buffer, offset + 12);
666             
667             return ret;
668         }
669     
670         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
671             Iterator JavaDoc<FrameRawdata> it = list.iterator();
672             
673             while (it.hasNext()) {
674                 FrameRawdata f = it.next();
675                 
676                 if (f.rawid == iModName) {
677                     modName = f;
678                     it.remove();
679                     
680                     break;
681                 }
682             }
683         }
684         
685         protected void handle(DbgServerHandler handler) {
686             handler.addSourceFileInfo(modNo, modName.getString());
687         }
688     }
689    
690      public static class FrameRawdata extends Frame {
691         private int rawid;
692         private int dataSize;
693         private byte[] data;
694         
695         protected FrameRawdata() {
696             type = DbgConstants.FRAME_RAWDATA;
697         }
698         
699         public FrameRawdata(DbgPacket packet, String JavaDoc str) {
700             this();
701             data = new byte[0];
702             
703             try {
704                 data = str.getBytes("ISO8859_1");
705             }
706             catch (UnsupportedEncodingException JavaDoc uee) {
707                 // Should not happen
708
}
709             
710             rawid = packet.getNewRawId();
711             buffer = new byte[8 + data.length + 1]; // '\0'
712
copyToByteArray(buffer, 0, rawid);
713             copyToByteArray(buffer, 4, data.length);
714             int i;
715             
716             for (i = 0; i < data.length; i++) {
717                 buffer[i + 8] = data[i];
718             }
719             
720             buffer[i + 8] = 0;
721         }
722         
723         public int getRawId() {
724             return rawid;
725         }
726         
727         public String JavaDoc toString() {
728             return "DbgPacket.FrameRawdata(rawid= " + rawid + ", dataSize= " + dataSize + ", data= " + getString() + ")";
729         }
730         
731         protected Frame receive(byte[] buffer, int offset, int size) {
732             assert size >= 8;
733             
734             FrameRawdata ret = new FrameRawdata();
735             
736             ret.rawid = intFromByteArray(buffer, offset);
737             ret.dataSize = intFromByteArray(buffer, offset + 4);
738             
739             ret.data = new byte[ret.dataSize - 1]; // '\0'
740

741             for (int i = 0; i < ret.dataSize - 1; i++) {
742                 ret.data[i] = buffer[offset + 8 + i];
743             }
744             
745             return ret;
746         }
747         
748         protected String JavaDoc getString() {
749             try {
750                 return new String JavaDoc(data, "ISO8859_1");
751             }
752             catch (UnsupportedEncodingException JavaDoc uee) {
753                 // Should not happen
754
}
755             
756             return "";
757         }
758     }
759      
760     public static class FrameError extends Frame {
761         private int errorType;
762         private int iMessage;
763         private FrameRawdata message;
764         
765         protected FrameError() {
766             type = DbgConstants.FRAME_ERROR;
767         }
768         
769         protected Frame receive(byte[] buffer, int offset, int size) {
770             assert size == 8;
771             
772             FrameError ret = new FrameError();
773             
774             ret.errorType = intFromByteArray(buffer, offset);
775             ret.iMessage = intFromByteArray(buffer, offset + 4);
776             
777             return ret;
778         }
779
780         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
781             Iterator JavaDoc<FrameRawdata> it = list.iterator();
782             
783             while (it.hasNext()) {
784                 FrameRawdata f = it.next();
785                 
786                 if (f.rawid == iMessage) {
787                     message = f;
788                     it.remove();
789                     
790                     break;
791                 }
792             }
793         }
794         
795         protected int getType() {
796             return errorType;
797         }
798         
799         protected String JavaDoc getDesc() {
800             return message.getString();
801         }
802     }
803
804     public static class FrameEval extends Frame {
805         private int iStr;
806         private FrameRawdata str;
807         private int iResult;
808         private FrameRawdata result;
809         private int iError;
810         private FrameRawdata error;
811         private List JavaDoc<Variable> vars;
812         
813         protected FrameEval() {
814             type = DbgConstants.FRAME_EVAL;
815         }
816         
817         public FrameEval(int _iStr, int _scope) {
818             this();
819             buffer = new byte[8];
820             copyToByteArray(buffer, 0, _iStr);
821             copyToByteArray(buffer, 4, _scope);
822         }
823         
824         protected List JavaDoc <Variable> getEvalValue() {
825             if (vars != null) {
826                 return vars;
827             }
828             
829             if (result != null && result.data != null) {
830                 vars = new DbgEvalValues(result.getString(), "").getVars();
831             }
832  
833             return vars;
834         }
835         
836         public String JavaDoc toString() {
837             return "DbgPacket.FrameEval(str= " + str + ", result= " + result +
838                     ", error= " + error + ")" +
839                     "\n\t\t" + getEvalValue() +
840                     "\n\t\t" + bufferToString();
841
842         }
843         
844         protected Frame receive(byte[] buffer, int offset, int size) {
845             // assert size == 12;
846
System.err.println("mw DbgPacket.FrameEval.receive() size= " + size);
847             FrameEval ret = new FrameEval();
848             
849             ret.iStr = intFromByteArray(buffer, offset);
850             ret.iResult = intFromByteArray(buffer, offset + 4);
851             ret.iError = intFromByteArray(buffer, offset + 8);
852             
853             return ret;
854         }
855
856         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
857             Iterator JavaDoc<FrameRawdata> it = list.iterator();
858             
859             while (it.hasNext()) {
860                 FrameRawdata f = it.next();
861                 
862                 if (f.rawid == iStr) {
863                     str = f;
864                     it.remove();
865                 }
866                 if (f.rawid == iResult) {
867                     result = f;
868                     it.remove();
869                 }
870                 if (f.rawid == iError) {
871                     error = f;
872                     it.remove();
873                 }
874             }
875         }
876
877     }
878
879     public static class FrameBpl extends Frame {
880         private int modNo;
881         private int lineNo;
882         private int iModName;
883         private FrameRawdata modName;
884         private int state;
885         private int isTemp;
886         private int hitCount;
887         private int skipHits;
888         private int iCondition;
889         private FrameRawdata condition;
890         private int bpNo;
891         private int isUnderHit;
892         
893         protected FrameBpl() {
894             type = DbgConstants.FRAME_BPL;
895         }
896         
897         public FrameBpl(int _bpNo) {
898             this();
899             buffer = new byte[4];
900             copyToByteArray(buffer, 0, _bpNo);
901         }
902
903         public String JavaDoc toString() {
904             return "DbgPacket.FrameBpl(state= " + state + " isTemp= " + isTemp +
905                     " hitCount= " + hitCount + " skipHits= " + skipHits + " condition= " + condition +
906                     " bpNo= " + bpNo + " isUnderHit= " + isUnderHit + ")";
907         }
908         
909         public int getBpNo() {
910             return bpNo;
911         }
912         
913         protected Frame receive(byte[] buffer, int offset, int size) {
914             assert size == 40;
915             
916             FrameBpl ret = new FrameBpl();
917             
918             ret.modNo = intFromByteArray(buffer, offset);
919             ret.lineNo = intFromByteArray(buffer, offset + 4);
920             ret.iModName = intFromByteArray(buffer, offset + 8);
921             ret.state = intFromByteArray(buffer, offset + 12);
922             ret.isTemp = intFromByteArray(buffer, offset + 16);
923             ret.hitCount = intFromByteArray(buffer, offset + 20);
924             ret.skipHits = intFromByteArray(buffer, offset + 24);
925             ret.iCondition = intFromByteArray(buffer, offset + 28);
926             ret.bpNo = intFromByteArray(buffer, offset + 32);
927             ret.isUnderHit = intFromByteArray(buffer, offset + 36);
928             
929             return ret;
930         }
931
932         protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
933             Iterator JavaDoc<FrameRawdata> it = list.iterator();
934             
935             while (it.hasNext()) {
936                 FrameRawdata f = it.next();
937                 
938                 if (f.rawid == iModName) {
939                     modName = f;
940                     it.remove();
941                 }
942                 if (f.rawid == iCondition) {
943                     condition = f;
944                     it.remove();
945                 }
946             }
947         }
948     }
949
950     public static class FrameBps extends Frame {
951         protected FrameBps() {
952             type = DbgConstants.FRAME_BPS;
953         }
954         
955         public FrameBps(int bpNo, int lineNo, int modNo, int iModName, int iCondition, int skipHits, int isTemp, int state) {
956             // FrameBpl response layout!!
957
this();
958             buffer = new byte[40];
959             copyToByteArray(buffer, 0, modNo);
960             copyToByteArray(buffer, 4, lineNo);
961             copyToByteArray(buffer, 8, iModName);
962             copyToByteArray(buffer, 12, state);
963             copyToByteArray(buffer, 16, isTemp);
964             // hitCount
965
copyToByteArray(buffer, 24, skipHits);
966             copyToByteArray(buffer, 28, iCondition);
967             copyToByteArray(buffer, 32, bpNo);
968             // isUnderHit
969
}
970         
971         protected Frame receive(byte[] buffer, int offset, int size) {
972             assert size == 0;
973             
974             return new FrameBps();
975         }
976     }
977     
978     public static class FrameSrcLinesInfo extends Frame {
979         private int modNo;
980         private int startLineNo;
981         private int linesCount;
982         private int ctxId;
983         
984         protected FrameSrcLinesInfo() {
985             type = DbgConstants.FRAME_SRCLINESINFO;
986         }
987         
988         public FrameSrcLinesInfo(int _modNo) {
989             this();
990             buffer = new byte[4];
991             copyToByteArray(buffer, 0, _modNo);
992         }
993         
994         public String JavaDoc toString() {
995             return "DbgPacket.FrameSrcLinesInfo(modNo= " + modNo + ", startLineNo= " + startLineNo +
996                     ", linesCount= " + linesCount + ", ctxId= " + ctxId + ")";
997         }
998
999         protected Frame receive(byte[] buffer, int offset, int size) {
1000            assert size == 16;
1001            
1002            FrameSrcLinesInfo ret = new FrameSrcLinesInfo();
1003            
1004            ret.modNo = intFromByteArray(buffer, offset);
1005            ret.startLineNo = intFromByteArray(buffer, offset + 4);
1006            ret.linesCount = intFromByteArray(buffer, offset + 8);
1007            ret.ctxId = intFromByteArray(buffer, offset + 12);
1008            
1009            return ret;
1010        }
1011    }
1012    
1013    public static class FrameSrcCtxInfo extends Frame {
1014        private int modNo;
1015        private int ctxId;
1016        private int iFunctionName;
1017        private FrameRawdata funtionName;
1018        
1019        protected FrameSrcCtxInfo() {
1020            type = DbgConstants.FRAME_SRCCTXINFO;
1021        }
1022        
1023        public FrameSrcCtxInfo(int _modNo) {
1024            this();
1025            buffer = new byte[4];
1026            copyToByteArray(buffer, 0, _modNo);
1027        }
1028        
1029        public String JavaDoc toString() {
1030            return "DbgPacket.FrameSrcCtxInfo(modNo= " + modNo + ", ctxId= " + ctxId +
1031                    ", funtionName= " + funtionName + ")";
1032        }
1033
1034        protected Frame receive(byte[] buffer, int offset, int size) {
1035            assert size == 12;
1036            System.err.println("mw DbgPacket.FrameSrcCtxInfo.receive() size= " + size);
1037            
1038            FrameSrcCtxInfo ret = new FrameSrcCtxInfo();
1039            
1040            ret.modNo = intFromByteArray(buffer, offset);
1041            ret.ctxId = intFromByteArray(buffer, offset + 4);
1042            ret.iFunctionName = intFromByteArray(buffer, offset + 8);
1043            
1044            return ret;
1045        }
1046
1047        protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
1048            Iterator JavaDoc<FrameRawdata> it = list.iterator();
1049            
1050            while (it.hasNext()) {
1051                FrameRawdata f = it.next();
1052                
1053                if (f.rawid == iFunctionName) {
1054                    funtionName = f;
1055                    it.remove();
1056                    
1057                    break;
1058                }
1059            }
1060        }
1061
1062    }
1063    
1064    public static class FrameLog extends Frame {
1065        private int iLog;
1066        private FrameRawdata log;
1067        private int logType;
1068        private int modNo;
1069        private int lineNo;
1070        private int iModName;
1071        private FrameRawdata modName;
1072        private int extInfo;
1073        
1074        protected FrameLog() {
1075            type = DbgConstants.FRAME_LOG;
1076        }
1077        
1078        protected Frame receive(byte[] buffer, int offset, int size) {
1079            assert size == 24;
1080            
1081            FrameLog ret = new FrameLog();
1082            
1083            ret.iLog = intFromByteArray(buffer, offset);
1084            ret.logType = intFromByteArray(buffer, offset + 4);
1085            ret.modNo = intFromByteArray(buffer, offset + 8);
1086            ret.lineNo = intFromByteArray(buffer, offset + 12);
1087            ret.iModName = intFromByteArray(buffer, offset + 16);
1088            ret.extInfo = intFromByteArray(buffer, offset + 20);
1089            
1090            return ret;
1091        }
1092
1093        protected void resolveRawRefs(List JavaDoc<FrameRawdata> list) {
1094            Iterator JavaDoc<FrameRawdata> it = list.iterator();
1095            
1096            while (it.hasNext()) {
1097                FrameRawdata f = it.next();
1098                
1099                if (f.rawid == iLog) {
1100                    log = f;
1101                    it.remove();
1102                }
1103                if (f.rawid == iModName) {
1104                    modName = f;
1105                    it.remove();
1106                }
1107            }
1108        }
1109
1110    }
1111
1112    public static class FrameProf extends Frame {
1113        private int modNo;
1114        private int lineNo;
1115        private int hitCount;
1116        private int tm_min_lo;
1117        private int tm_min_hi;
1118        private int tm_max_lo;
1119        private int tm_max_hi;
1120        private int tm_sum_lo;
1121        private int tm_sum_hi;
1122        
1123        protected FrameProf() {
1124            type = DbgConstants.FRAME_PROF;
1125        }
1126        
1127        public FrameProf(int _modNo) {
1128            this();
1129            buffer = new byte[4];
1130            copyToByteArray(buffer, 0, _modNo);
1131        }
1132        
1133        protected Frame receive(byte[] buffer, int offset, int size) {
1134            assert size == 36;
1135            
1136            FrameProf ret = new FrameProf();
1137            
1138            ret.modNo = intFromByteArray(buffer, offset);
1139            ret.lineNo = intFromByteArray(buffer, offset + 4);
1140            ret.hitCount = intFromByteArray(buffer, offset + 8);
1141            ret.tm_min_lo = intFromByteArray(buffer, offset + 12);
1142            ret.tm_min_hi = intFromByteArray(buffer, offset + 16);
1143            ret.tm_max_lo = intFromByteArray(buffer, offset + 20);
1144            ret.tm_max_hi = intFromByteArray(buffer, offset + 20);
1145            ret.tm_sum_lo = intFromByteArray(buffer, offset + 20);
1146            ret.tm_sum_hi = intFromByteArray(buffer, offset + 20);
1147            
1148            return ret;
1149        }
1150    }
1151
1152    public static class FrameProfC extends Frame {
1153        private int tm_freq_lo;
1154        private int tm_freq_hi;
1155        private int tm_diff_min;
1156        private int tm_diff_max;
1157        private int tm_diff_m;
1158        
1159        protected FrameProfC() {
1160            type = DbgConstants.FRAME_PROF_C;
1161        }
1162        
1163        public FrameProfC(int testLoops) {
1164            this();
1165            buffer = new byte[4];
1166            copyToByteArray(buffer, 0, testLoops);
1167        }
1168        
1169        protected Frame receive(byte[] buffer, int offset, int size) {
1170            assert size == 20;
1171            
1172            FrameProfC ret = new FrameProfC();
1173            
1174            ret.tm_freq_lo = intFromByteArray(buffer, offset);
1175            ret.tm_freq_hi = intFromByteArray(buffer, offset + 4);
1176            ret.tm_diff_min = intFromByteArray(buffer, offset + 8);
1177            ret.tm_diff_max = intFromByteArray(buffer, offset + 12);
1178            ret.tm_diff_m = intFromByteArray(buffer, offset + 16);
1179            
1180            return ret;
1181        }
1182    }
1183
1184    public static class FrameSetOpt extends Frame {
1185        protected FrameSetOpt() {
1186            type = DbgConstants.FRAME_SET_OPT;
1187        }
1188        
1189        public FrameSetOpt(int opt) {
1190            this();
1191            buffer = new byte[4];
1192            copyToByteArray(buffer, 0, opt);
1193        }
1194        
1195        protected Frame receive(byte[] buffer, int offset, int size) {
1196            assert size == 0;
1197        
1198            return new FrameSetOpt();
1199        }
1200    }
1201
1202}
1203
Popular Tags