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

📄 commands.java

📁 jpda例子文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)Commands.java	1.78 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Copyright (c) 1997-2001 by Sun Microsystems, Inc. All Rights Reserved. *  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. *  * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. *  * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */package com.sun.tools.example.debug.tty;import com.sun.jdi.*;import com.sun.jdi.request.*;import com.sun.tools.example.debug.expr.ExpressionParser;import com.sun.tools.example.debug.expr.ParseException;import java.text.*;import java.util.*;import java.io.*;class Commands {    abstract class AsyncExecution {	abstract void action();	AsyncExecution() {            execute();	}	void execute() {            /*             * Save current thread and stack frame. (BugId 4296031)             */            final ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();            final int stackFrame = threadInfo == null? 0 : threadInfo.getCurrentFrameIndex();            Thread thread = new Thread("asynchronous jdb command") {                    public void run() {                        try {                            action();                        } catch (UnsupportedOperationException uoe) {                            //(BugId 4453329)                            MessageOutput.println("Operation is not supported on the target VM");                        } catch (Exception e) {                            MessageOutput.println("Internal exception during operation:",                                                  e.getMessage());                        } finally {                            /*                             * This was an asynchronous command.  Events may have been                             * processed while it was running.  Restore the thread and                             * stack frame the user was looking at.  (BugId 4296031)                             */                            if (threadInfo != null) {                                ThreadInfo.setCurrentThreadInfo(threadInfo);                                try {                                    threadInfo.setCurrentFrameIndex(stackFrame);                                } catch (IncompatibleThreadStateException e) {                                    MessageOutput.println("Current thread isnt suspended.");                                } catch (ArrayIndexOutOfBoundsException e) {                                    MessageOutput.println("Requested stack frame is no longer active:",                                                          new Object []{new Integer(stackFrame)});                                }                            }                            MessageOutput.printPrompt();                        }                    }                };            thread.start();	}    }    Commands() {    }    private Value evaluate(String expr) {        Value result = null;        ExpressionParser.GetFrame frameGetter = null;        try {            final ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();            if ((threadInfo != null) && (threadInfo.getCurrentFrame() != null)) {                frameGetter = new ExpressionParser.GetFrame() {                        public StackFrame get() throws IncompatibleThreadStateException {                            return threadInfo.getCurrentFrame();                        }                    };            }            result = ExpressionParser.evaluate(expr, Env.vm(), frameGetter);        } catch (InvocationException ie) {            MessageOutput.println("Exception in expression:",                                  ie.exception().referenceType().name());        } catch (Exception ex) {            String exMessage = ex.getMessage();            if (exMessage == null) {                MessageOutput.printException(exMessage, ex);            } else {                String s;                try {                    s = MessageOutput.format(exMessage);                } catch (MissingResourceException mex) {                    s = ex.toString();                }                MessageOutput.printDirectln(s);// Special case: use printDirectln()            }        }        return result;    }    private String getStringValue() {         Value val = null;         String valStr = null;         try {              val = ExpressionParser.getMassagedValue();              valStr = val.toString();         } catch (ParseException e) {               String msg = e.getMessage();              if (msg == null) {                  MessageOutput.printException(msg, e);              } else {                  String s;                  try {                      s = MessageOutput.format(msg);                  } catch (MissingResourceException mex) {                      s = e.toString();                  }                  MessageOutput.printDirectln(s);                  }         }         return valStr;    }    private ThreadInfo doGetThread(String idToken) {        ThreadInfo threadInfo = ThreadInfo.getThreadInfo(idToken);        if (threadInfo == null) {            MessageOutput.println("is not a valid thread id", idToken);        }        return threadInfo;    }    String typedName(Method method) {        StringBuffer buf = new StringBuffer();        buf.append(method.name());        buf.append("(");        Iterator it = method.argumentTypeNames().iterator();        while (it.hasNext()) {            buf.append((String)it.next());            if (it.hasNext()) {                buf.append(",");            }        }        buf.append(")");        return buf.toString();    }                                   void commandClasses() {        List list = Env.vm().allClasses();        StringBuffer classList = new StringBuffer();        for (int i = 0 ; i < list.size() ; i++) {            ReferenceType refType = (ReferenceType)list.get(i);            classList.append(refType.name());            classList.append("\n");        }        MessageOutput.print("** classes list **", classList.toString());    }    void commandClass(StringTokenizer t) {        List list = Env.vm().allClasses();        if (!t.hasMoreTokens()) {            MessageOutput.println("No class specified.");            return;        }        String idClass = t.nextToken();        boolean showAll = false;        if (t.hasMoreTokens()) {            if (t.nextToken().toLowerCase().equals("all")) {                showAll = true;            } else {                MessageOutput.println("Invalid option on class command");                return;            }        }        ReferenceType type = Env.getReferenceTypeFromToken(idClass);        if (type == null) {            MessageOutput.println("is not a valid id or class name", idClass);            return;        }        if (type instanceof ClassType) {            ClassType clazz = (ClassType)type;            MessageOutput.println("Class:", clazz.name());            ClassType superclass = clazz.superclass();            while (superclass != null) {                MessageOutput.println("extends:", superclass.name());                superclass = showAll ? superclass.superclass() : null;            }            List interfaces = showAll ? clazz.allInterfaces()                                       : clazz.interfaces();            Iterator iter = interfaces.iterator();            while (iter.hasNext()) {                InterfaceType interfaze = (InterfaceType)iter.next();                MessageOutput.println("implements:", interfaze.name());            }            List subs = clazz.subclasses();            iter = subs.iterator();            while (iter.hasNext()) {                ClassType sub = (ClassType)iter.next();                MessageOutput.println("subclass:", sub.name());            }            List nested = clazz.nestedTypes();            iter = nested.iterator();            while (iter.hasNext()) {                ReferenceType nest = (ReferenceType)iter.next();                MessageOutput.println("nested:", nest.name());            }        } else if (type instanceof InterfaceType) {            InterfaceType interfaze = (InterfaceType)type;            MessageOutput.println("Interface:", interfaze.name());            List supers = interfaze.superinterfaces();            Iterator iter = supers.iterator();            while (iter.hasNext()) {                InterfaceType superinterface = (InterfaceType)iter.next();                MessageOutput.println("extends:", superinterface.name());            }            List subs = interfaze.subinterfaces();            iter = subs.iterator();            while (iter.hasNext()) {                InterfaceType sub = (InterfaceType)iter.next();                MessageOutput.println("subinterface:", sub.name());            }            List implementors = interfaze.implementors();            iter = implementors.iterator();            while (iter.hasNext()) {                ClassType implementor = (ClassType)iter.next();                MessageOutput.println("implementor:", implementor.name());            }            List nested = interfaze.nestedTypes();            iter = nested.iterator();            while (iter.hasNext()) {                ReferenceType nest = (ReferenceType)iter.next();                MessageOutput.println("nested:", nest.name());            }        } else {  // array type            ArrayType array = (ArrayType)type;            MessageOutput.println("Array:", array.name());        }    }    void commandMethods(StringTokenizer t) {        if (!t.hasMoreTokens()) {            MessageOutput.println("No class specified.");            return;        }        String idClass = t.nextToken();        ReferenceType cls = Env.getReferenceTypeFromToken(idClass);        if (cls != null) {            List methods = cls.allMethods();            StringBuffer methodsList = new StringBuffer();            for (int i = 0; i < methods.size(); i++) {                Method method = (Method)methods.get(i);                methodsList.append(method.declaringType().name());                methodsList.append(" ");                methodsList.append(method.name());                methodsList.append("(");                Iterator it = method.argumentTypeNames().iterator();                if (it.hasNext()) {                    while (true) {                        methodsList.append((String)it.next());                        if (!it.hasNext()) {                            break;                        }                        methodsList.append(", ");                    }                }                methodsList.append(")\n");            }            MessageOutput.print("** methods list **", methodsList.toString());        } else {            MessageOutput.println("is not a valid id or class name", idClass);        }    }    void commandFields(StringTokenizer t) {        if (!t.hasMoreTokens()) {            MessageOutput.println("No class specified.");            return;        }        String idClass = t.nextToken();        ReferenceType cls = Env.getReferenceTypeFromToken(idClass);        if (cls != null) {            List fields = cls.allFields();            List visible = cls.visibleFields();            StringBuffer fieldsList = new StringBuffer();            for (int i = 0; i < fields.size(); i++) {                Field field = (Field)fields.get(i);                String s;                if (!visible.contains(field)) {                    s = MessageOutput.format("list field typename and name hidden",                                             new Object [] {field.typeName(),                                                            field.name()});                } else if (!field.declaringType().equals(cls)) {                    s = MessageOutput.format("list field typename and name inherited",                                             new Object [] {field.typeName(),                                                            field.name(),                                                            field.declaringType().name()});                } else {                    s = MessageOutput.format("list field typename and name",                                             new Object [] {field.typeName(),

⌨️ 快捷键说明

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