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

📄 commands.java

📁 jpda例子文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    lineno = n.intValue();                } catch (java.text.ParseException jtpe) {                    // It isn't -- see if it's a method name.                        List meths = refType.methodsByName(id);                        if (meths == null || meths.size() == 0) {                            MessageOutput.println("is not a valid line number or method name for",                                                  new Object [] {id, refType.name()});                            return;                        } else if (meths.size() > 1) {                            MessageOutput.println("is an ambiguous method name in",                                                  new Object [] {id, refType.name()});                            return;                        }                        loc = ((Method)meths.get(0)).location();                        lineno = loc.lineNumber();                }            }            int startLine = Math.max(lineno - 4, 1);            int endLine = startLine + 9;            if (lineno < 0) {                MessageOutput.println("Line number information not available for");            } else if (Env.sourceLine(loc, lineno) == null) {                MessageOutput.println("is an invalid line number for",                                      new Object [] {new Integer (lineno),                                                     refType.name()});            } else {                for (int i = startLine; i <= endLine; i++) {                    String sourceLine = Env.sourceLine(loc, i);                    if (sourceLine == null) {                        break;                    }                    if (i == lineno) {                        MessageOutput.println("source line number current line and line",                                              new Object [] {new Integer (i),                                                             sourceLine});                    } else {                        MessageOutput.println("source line number and line",                                              new Object [] {new Integer (i),                                                             sourceLine});                    }                }            }        } catch (AbsentInformationException e) {            MessageOutput.println("No source information available for:", loc.toString());        } catch(FileNotFoundException exc) {            MessageOutput.println("Source file not found:", sourceFileName);        } catch(IOException exc) {            MessageOutput.println("I/O exception occurred:", exc.toString());        }     }    void commandLines(StringTokenizer t) { // Undocumented command: useful for testing        if (!t.hasMoreTokens()) {            MessageOutput.println("Specify class and method");        } else {            String idClass = t.nextToken();            String idMethod = t.hasMoreTokens() ? t.nextToken() : null;            try {                ReferenceType refType = Env.getReferenceTypeFromToken(idClass);                if (refType != null) {                    List lines = null;                    if (idMethod == null) {                        lines = refType.allLineLocations();                    } else {                        List methods = refType.allMethods();                        Iterator iter = methods.iterator();                        while (iter.hasNext()) {                            Method method = (Method)iter.next();                            if (method.name().equals(idMethod)) {                                lines = method.allLineLocations();                            }                        }                        if (lines == null) {                            MessageOutput.println("is not a valid method name", idMethod);                        }                    }                    Iterator iter = lines.iterator();                    while (iter.hasNext()) {                        Location line = (Location)iter.next();                        MessageOutput.printDirectln(line.toString());// Special case: use printDirectln()                    }                } else {                    MessageOutput.println("is not a valid id or class name", idClass);                }            } catch (AbsentInformationException e) {                MessageOutput.println("Line number information not available for", idClass);            }        }    }    void commandClasspath(StringTokenizer t) {        if (Env.vm() instanceof PathSearchingVirtualMachine) {            PathSearchingVirtualMachine vm = (PathSearchingVirtualMachine)Env.vm();            MessageOutput.println("base directory:", vm.baseDirectory());            MessageOutput.println("classpath:", vm.classPath().toString());            MessageOutput.println("bootclasspath:", vm.bootClassPath().toString());        } else {            MessageOutput.println("The VM does not use paths");        }    }    /* Get or set the source file path list. */    void commandUse(StringTokenizer t) {        if (!t.hasMoreTokens()) {            MessageOutput.printDirectln(Env.getSourcePath());// Special case: use printDirectln()        } else {            /*             * Take the remainder of the command line, minus             * leading or trailing whitespace.  Embedded             * whitespace is fine.             */            Env.setSourcePath(t.nextToken("").trim());        }    }    /* Print a stack variable */    private void printVar(LocalVariable var, Value value) {        MessageOutput.println("expr is value",                              new Object [] {var.name(),                                              value == null ? "null" : value.toString()});    }    /* Print all local variables in current stack frame. */    void commandLocals() {        StackFrame frame;        ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();        if (threadInfo == null) {            MessageOutput.println("No default thread specified:");            return;        }        try {            frame = threadInfo.getCurrentFrame();            if (frame == null) {                throw new AbsentInformationException();            }            List vars = frame.visibleVariables();                if (vars.size() == 0) {                MessageOutput.println("No local variables");                return;            }            Map values = frame.getValues(vars);            MessageOutput.println("Method arguments:");            for (Iterator it = vars.iterator(); it.hasNext(); ) {                LocalVariable var = (LocalVariable)it.next();                if (var.isArgument()) {                    Value val = (Value)values.get(var);                    printVar(var, val);                }            }            MessageOutput.println("Local variables:");            for (Iterator it = vars.iterator(); it.hasNext(); ) {                LocalVariable var = (LocalVariable)it.next();                if (!var.isArgument()) {                    Value val = (Value)values.get(var);                    printVar(var, val);                }            }        } catch (AbsentInformationException aie) {            MessageOutput.println("Local variable information not available.");        } catch (IncompatibleThreadStateException exc) {            MessageOutput.println("Current thread isnt suspended.");        }    }    private void dump(ObjectReference obj, ReferenceType refType,                      ReferenceType refTypeBase) {        for (Iterator it = refType.fields().iterator(); it.hasNext(); ) {            StringBuffer o = new StringBuffer();            Field field = (Field)it.next();            o.append("    ");            if (!refType.equals(refTypeBase)) {                o.append(refType.name());                o.append(".");            }            o.append(field.name());            o.append(MessageOutput.format("colon space"));            o.append(obj.getValue(field));            MessageOutput.printDirectln(o.toString()); // Special case: use printDirectln()        }        if (refType instanceof ClassType) {            ClassType sup = ((ClassType)refType).superclass();            if (sup != null) {                dump(obj, sup, refTypeBase);            }        } else if (refType instanceof InterfaceType) {            List sups = ((InterfaceType)refType).superinterfaces();            for (Iterator it = sups.iterator(); it.hasNext(); ) {                dump(obj, (ReferenceType)it.next(), refTypeBase);            }        } else {            /* else refType is an instanceof ArrayType */            if (obj instanceof ArrayReference) {                for (Iterator it = ((ArrayReference)obj).getValues().iterator();                     it.hasNext(); ) {                    MessageOutput.printDirect(it.next().toString());// Special case: use printDirect()                    if (it.hasNext()) {                        MessageOutput.printDirect(", ");// Special case: use printDirect()                    }                }                MessageOutput.println();            }        }    }    /* Print a specified reference.      */    void doPrint(StringTokenizer t, boolean dumpObject) {        if (!t.hasMoreTokens()) {            MessageOutput.println("No objects specified.");            return;        }        while (t.hasMoreTokens()) {            String expr = t.nextToken("");            Value val = evaluate(expr);            if (val == null) {                MessageOutput.println("expr is null", expr.toString());            } else if (dumpObject && (val instanceof ObjectReference) &&                       !(val instanceof StringReference)) {                ObjectReference obj = (ObjectReference)val;                ReferenceType refType = obj.referenceType();                MessageOutput.println("expr is value",                                      new Object [] {expr.toString(),                                                     MessageOutput.format("grouping begin character")});                dump(obj, refType, refType);                MessageOutput.println("grouping end character");            } else {                  String strVal = getStringValue();                  if (strVal != null) {                     MessageOutput.println("expr is value", new Object [] {expr.toString(),                                                                      strVal});                   }             }        }    }    void commandPrint(final StringTokenizer t, final boolean dumpObject) {        new AsyncExecution() {                void action() {                    doPrint(t, dumpObject);                }            };     }    void commandSet(final StringTokenizer t) {        String all = t.nextToken("");        /*         * Bare bones error checking.          */        if (all.indexOf('=') == -1) {            MessageOutput.println("Invalid assignment syntax");            MessageOutput.printPrompt();            return;        }        /*         * The set command is really just syntactic sugar. Pass it on to the          * print command.         */        commandPrint(new StringTokenizer(all), false);    }    void doLock(StringTokenizer t) {        if (!t.hasMoreTokens()) {            MessageOutput.println("No object specified.");            return;        }        String expr = t.nextToken("");        Value val = evaluate(expr);        try {            if ((val != null) && (val instanceof ObjectReference)) {                ObjectReference object = (ObjectReference)val;                String strVal = getStringValue();                if (strVal != null) {                    MessageOutput.println("Monitor information for expr",                                      new Object [] {expr.trim(),                                                     strVal});                }                 ThreadReference owner = object.owningThread();                if (owner == null) {                    MessageOutput.println("Not owned");                } else {                    MessageOutput.println("Owned by:",                                          new Object [] {owner.name(),                                                         new Integer (object.entryCount())});                }                List waiters = object.waitingThreads();                if (waiters.size() == 0) {                    MessageOutput.println("No waiters");                } else {                    Iterator iter = waiters.iterator();                    while (iter.hasNext()) {                        ThreadReference waiter = (ThreadReference)iter.next();                        MessageOutput.println("Waiting thread:", owner.name());                    }                }            } else {                MessageOutput.println("Expression must evaluate to an object");            }        } catch (IncompatibleThreadStateException e) {            MessageOutput.println("Threads must be suspended");        }    }    void commandLock(final StringTokenizer t) {        new AsyncExecution() {                void action() {                    doLock(t);                }            };     }    private void printThreadLockInfo(ThreadInfo threadInfo) {        ThreadReference thread = threadInfo.getThread();        try {            MessageOutput.println("Monitor information for thread", thread.name());            List owned = thread.ownedMonitors();            if (owned.size() == 0) {                MessageOutput.println("No monitors owned");            } else {                Iterator iter = owned.iterator();                while (iter.hasNext()) {                    ObjectReference monitor = (ObjectReference)iter.next();                    MessageOutput.println("Owned monitor:", monitor.toString());                }            }            ObjectReference waiting = thread.currentContendedMonitor();            if (waiting == null) {                MessageOutput.println("Not waiting for a monitor");      

⌨️ 快捷键说明

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