⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debuggerlistener.java

📁 已经移植好的java虚拟机
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                ps2.send();                                handled = true;                                break;                        }                        int num = ps.readInt();         // get number of values                        byte tag = ps.readByte();       // get tag type                        int objectID = ps.readInt();    // and get object ID                        Log.LOGN(3, "Stackframe: thisobject tag: " + tag +                            " objectID " + objectID);                        ps2.writeByte(tag);                        ps2.writeInt(objectID);                        ps2.send();                        handled = true;                        break;                }                break;            case CLASSOBJECTREFERENCE_CMDSET:                switch (p.cmd) {                case REFLECTEDTYPE_CMD:                    int oID = in.readInt(); // get object ID                    PacketStream ps2 = new PacketStream(this, in.id,                        Packet.Reply, Packet.ReplyNoError);                    if ((cf = (ClassFile)ClassManager.classMap.get(                        new Integer(oID))) == null) {                            // this can't possibly happen :-)                        ps2.writeByte(TYPE_TAG_CLASS);                    } else {                        ps2.writeByte(cf.getJDWPTypeTag());                    }                    ps2.writeInt(oID);                    ps2.send();                    handled = true;                    break;                }                break;            }            }                           if (!handled) {                Log.LOG(3, "DebuggerListener: ");                disp(p);                if (p.cmdSet == 15 && p.cmd == 1) {                    Log.LOG(3, "EventKind == " + p.data[ 0 ] + "\n");                }                KVMListener.send(p);            }        }        } catch (IOException e) {            PacketStream error = new PacketStream(this, in.id, Packet.Reply, NOTFOUND_ERROR);            error.send();        } catch (ArrayIndexOutOfBoundsException e) {            System.out.println(p.cmdSet + "/" + p.cmd + " caused: " + e);            PacketStream error = new PacketStream(this, in.id, Packet.Reply, NOTFOUND_ERROR);            error.send();        }            }    public String toString() {        return (new String("DebuggerListener: "));    }    /**     * Retrieves the name of the class associated     * with the specified id in a KVM defined manner     */    protected String getClassName(byte[] classid) {        return new String("");       }    /**     * Retrieves the name of the method associated     * with the specified id in a KVM defined manner     */    protected String getMethodName(byte[] methodid) {        return new String("");    }    protected boolean processFields(ClassFile cf, PacketStream ps, int id) {        ClassFile scf;        Log.LOGN(3, "processFields for " + cf.getClassFileName());        try {            FieldInfo fi;            List fiList = cf.getAllFieldInfo();            Iterator fiIter = fiList.iterator();            long fieldID = ((long)cf.getClassID()) << 32;            Log.LOGN(5, "field class id is " +                Integer.toHexString(cf.getClassID()) +                " fieldid is " + Long.toHexString(fieldID));            ps.writeInt(fiList.size());            while (fiIter.hasNext()) {                fi = (FieldInfo)fiIter.next();                if (fi == null) {                    throw new Exception("fieldinfo null");                }                Log.LOGN(5, "Field: id = " + Long.toHexString(fieldID));                ps.writeLong(fieldID++);                Log.LOGN(5, "Field: name = " + fi.getName());                ps.writeString(fi.getName());                Log.LOGN(5, "Field: sig = " + fi.getType());                ps.writeString(fi.getType());                Log.LOGN(5, "Field: flags = " + fi.getAccessFlags());                ps.writeInt(fi.getAccessFlags());            }        } catch (Exception e) {            System.out.println("Fields cmd: exception " + e);            ps = new PacketStream(this, id, Packet.Reply,                INVALID_OBJECT);            ps.send();            return false;        }        return true;    }    public void handleLineTable(PacketStream in) throws IOException {        int mid, cid;        String classname, methodname, methodsig;        PacketStream ps;        ClassFile   cf = null;        MethodInfo  mi;        int code[][] = null;        long startingOffset, endingOffset;        int lineCount;        // we need to know the class and method to which the id's refer         cid = in.readInt(); // class id - we won't need it        mid = in.readInt() - method_index_base;        Log.LOGN(4, "linetable: class id= " + Integer.toHexString(cid) + ", method id= " + Integer.toHexString(mid + method_index_base));        if ((cf = (ClassFile)ClassManager.classMap.            get(new Integer(cid))) == null) {            Log.LOGN(3, "Linetable cmd: not found");            ps = new PacketStream(this, in.id, Packet.Reply, NOTFOUND_ERROR);            ps.send();            return;        }        Log.LOGN(4, "linetable: class: " + cf.getClassFileName());        ps = new PacketStream(this, in.id, Packet.Reply, Packet.ReplyNoError);        mi = cf.getMethodInfoByIndex(mid);        if (mi == null) {            Log.LOGN(1, "Couldn't find methodinfo for index " + mid + method_index_base);            ps = new PacketStream(this, in.id, Packet.Reply, INVALID_METHODID);            ps.send();            return;        }        CodeAttribute ca = mi.getCodeAttribute();        if (ca == null) {            /* I don't think this can happen; no code, return -1 as start and end */            startingOffset = endingOffset = -1;        } else {            startingOffset = 0;            endingOffset = ca.getCodeLength() - 1;        }        code = mi.getBreakableLineNumbers();        if (code == null) {            Log.LOGN(1, "No linenumber table found for class "+ cf.getClassName());            lineCount = 0;        } else {            lineCount = code.length;        }        ps.writeLong(startingOffset);  // starting offset        ps.writeLong(endingOffset);        Log.LOGN(5, "Starting code offset = " + startingOffset + ", Ending code offset = " + endingOffset);        Log.LOGN(5, "Code Length = " + lineCount);        ps.writeInt(lineCount);        for (int i=0; i < lineCount; i++) {            ps.writeLong(code[ i ][ 1 ]);             ps.writeInt(code[ i ][ 0 ]);             Log.LOGN(5, "  index=" + code[ i ][ 1 ] + " l#=" + code[ i ][ 0 ]);        }         ps.send();    }    public void handleVariableTable(PacketStream in) throws IOException {        int mid, cid;        PacketStream ps;        List table = null;        MethodInfo mi = null;        ClassFile cf;        cid = in.readInt(); // class id - we won't need it        Log.LOGN(3, "variable: class id = " + Integer.toHexString(cid));        mid = in.readInt() - method_index_base;        Log.LOGN(3, "variable: method id = " + Integer.toHexString(mid + method_index_base));        if ((cf = (ClassFile)ClassManager.classMap.get(new            Integer(cid))) == null) {            Log.LOGN(3, "Variabletable cmd: not found");            ps = new PacketStream(this, in.id, Packet.Reply, NOTFOUND_ERROR);            ps.send();            return;        }        try {            table = cf.getVariableTableForMethodIndex(mid);            mi = cf.getMethodInfoByIndex(mid);            if (mi == null) {                throw new Exception("couldn't find method info for class " +                    cf.getClassFileName());            }        } catch (Exception e) {            System.out.println("class " + cf.getClassName() + " caused " + e);            ps = new PacketStream(this, in.id, Packet.Reply, INVALID_OBJECT);            ps.send();            return;        }        ps = new PacketStream(this, in.id, Packet.Reply, Packet.ReplyNoError);        ps.writeInt(mi.getArgCount());        if (table != null) {            ps.writeInt(table.size());            Iterator iter = table.iterator();            while (iter.hasNext()) {                LocalVariable var = (LocalVariable)iter.next();                ps.writeLong(var.getCodeIndex());                ps.writeString(var.getName());                ps.writeString(getJNISignature(var.getType()));                ps.writeInt(var.getLength());                ps.writeInt(var.getSlot());            }        } else {            ps.writeInt(0);        }        ps.send();    }   private void handleByteCode(PacketStream in) {        int cid, mid;        PacketStream ps;        MethodInfo mi = null;        ClassFile cf;        Log.LOGN(1, "Method: Bytecodes");        String sig=null;        cid = in.readInt(); // class id        Log.LOGN(3, "class id=" + Integer.toHexString(cid));        mid = in.readInt() - method_index_base; // method id        Log.LOGN(3, "method id=" + Integer.toHexString(mid + method_index_base));        //        // now we will build a packet to send         // to the debugger        //        if ((cf = (ClassFile)ClassManager.classMap.get(new            Integer(cid))) == null) {                Log.LOGN(3, "Bytecode cmd: not found");                ps = new PacketStream(this, in.id,                    Packet.Reply, INVALID_OBJECT);                ps.send();                return;        }        try {            mi = cf.getMethodInfoByIndex(mid);            if (mi == null) {                throw new Exception("couldn't find method info for class " +                    cf.getClassFileName());            }        } catch (Exception e) {            System.out.println(" class" + cf.getClassFileName() + " caused " +            e);            ps = new PacketStream(this, in.id, Packet.Reply, INVALID_METHODID);            ps.send();            return;        }        // grab the byte codes        //        byte[] code = mi.getCodeAttribute().getByteCodes();        //        // build the reply packet and send it off        //        ps = new PacketStream(this,                in.id, Packet.Reply, Packet.ReplyNoError);        ps.writeInt((int)code.length);        ps.writeByteArray(code);        ps.send();     }    private String getJNISignature(String type) {        int index = type.length();        int preindex = index;        String ret = new String();        String str;        Log.LOGN(6, "getJNISignature()  type == " + type);        while ((index = type.lastIndexOf("[]", index)) != -1) {            ret += "[";            preindex = index;            index--;        }        str = type.substring(0, preindex);        if      ("int".equalsIgnoreCase(str))     ret += "I";        else if ("boolean".equalsIgnoreCase(str)) ret += "Z";        else if ("short".equalsIgnoreCase(str))   ret += "S";        else if ("byte".equalsIgnoreCase(str))    ret += "B";        else if ("char".equalsIgnoreCase(str))    ret += "C";        else if ("long".equalsIgnoreCase(str))    ret += "J";        else if ("float".equalsIgnoreCase(str))   ret += "F";        else if ("double".equalsIgnoreCase(str))  ret += "D";        else ret += "L" + str.replace('.', '/') + ";";        return ret;    }} // DebuggerListener

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -