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

📄 commands.java

📁 jpda例子文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                                            field.name()});                }                fieldsList.append(s);            }            MessageOutput.print("** fields list **", fieldsList.toString());        } else {            MessageOutput.println("is not a valid id or class name", idClass);        }    }    private void printThreadGroup(ThreadGroupReference tg) {        ThreadIterator threadIter = new ThreadIterator(tg);        MessageOutput.println("Thread Group:", tg.name());        int maxIdLength = 0;        int maxNameLength = 0;        while (threadIter.hasNext()) {            ThreadReference thr = (ThreadReference)threadIter.next();            maxIdLength = Math.max(maxIdLength,                                   Env.description(thr).length());            maxNameLength = Math.max(maxNameLength,                                     thr.name().length());        }        threadIter = new ThreadIterator(tg);        while (threadIter.hasNext()) {            ThreadReference thr = (ThreadReference)threadIter.next();	    if (thr.threadGroup() == null) {                continue;             }            // Note any thread group changes            if (!thr.threadGroup().equals(tg)) {                tg = thr.threadGroup();                MessageOutput.println("Thread Group:", tg.name());            }            /*             * Do a bit of filling with whitespace to get thread ID             * and thread names to line up in the listing, and also             * allow for proper localization.  This also works for             * very long thread names, at the possible cost of lines             * being wrapped by the display device.             */            StringBuffer idBuffer = new StringBuffer(Env.description(thr));            for (int i = idBuffer.length(); i < maxIdLength; i++) {                idBuffer.append(" ");            }            StringBuffer nameBuffer = new StringBuffer(thr.name());            for (int i = nameBuffer.length(); i < maxNameLength; i++) {                nameBuffer.append(" ");            }                        /*             * Select the output format to use based on thread status             * and breakpoint.             */            String statusFormat;            switch (thr.status()) {            case ThreadReference.THREAD_STATUS_UNKNOWN:                if (thr.isAtBreakpoint()) {                    statusFormat = "Thread description name unknownStatus BP";                } else {                    statusFormat = "Thread description name unknownStatus";                }                break;            case ThreadReference.THREAD_STATUS_ZOMBIE:                if (thr.isAtBreakpoint()) {                    statusFormat = "Thread description name zombieStatus BP";                } else {                    statusFormat = "Thread description name zombieStatus";                }                break;            case ThreadReference.THREAD_STATUS_RUNNING:                if (thr.isAtBreakpoint()) {                    statusFormat = "Thread description name runningStatus BP";                } else {                    statusFormat = "Thread description name runningStatus";                }                break;            case ThreadReference.THREAD_STATUS_SLEEPING:                if (thr.isAtBreakpoint()) {                    statusFormat = "Thread description name sleepingStatus BP";                } else {                    statusFormat = "Thread description name sleepingStatus";                }                break;            case ThreadReference.THREAD_STATUS_MONITOR:                if (thr.isAtBreakpoint()) {                    statusFormat = "Thread description name waitingStatus BP";                } else {                    statusFormat = "Thread description name waitingStatus";                }                break;            case ThreadReference.THREAD_STATUS_WAIT:                if (thr.isAtBreakpoint()) {                    statusFormat = "Thread description name condWaitstatus BP";                } else {                    statusFormat = "Thread description name condWaitstatus";                }                break;            default:                throw new InternalError(MessageOutput.format("Invalid thread status."));            }            MessageOutput.println(statusFormat,                                  new Object [] {idBuffer.toString(),                                                 nameBuffer.toString()});        }    }    void commandThreads(StringTokenizer t) {        if (!t.hasMoreTokens()) {            printThreadGroup(ThreadInfo.group());            return;        }        String name = t.nextToken();        ThreadGroupReference tg = ThreadGroupIterator.find(name);        if (tg == null) {            MessageOutput.println("is not a valid threadgroup name", name);        } else {            printThreadGroup(tg);        }    }    void commandThreadGroups() {        ThreadGroupIterator it = new ThreadGroupIterator();        int cnt = 0;        while (it.hasNext()) {            ThreadGroupReference tg = it.nextThreadGroup();            ++cnt;            MessageOutput.println("thread group number description name",                                  new Object [] { new Integer (cnt),                                                  Env.description(tg),                                                  tg.name()});        }    }        void commandThread(StringTokenizer t) {        if (!t.hasMoreTokens()) {            MessageOutput.println("Thread number not specified.");            return;        }        ThreadInfo threadInfo = doGetThread(t.nextToken());        if (threadInfo != null) {            ThreadInfo.setCurrentThreadInfo(threadInfo);        }    }        void commandThreadGroup(StringTokenizer t) {        if (!t.hasMoreTokens()) {            MessageOutput.println("Threadgroup name not specified.");            return;        }        String name = t.nextToken();        ThreadGroupReference tg = ThreadGroupIterator.find(name);        if (tg == null) {            MessageOutput.println("is not a valid threadgroup name", name);        } else {            ThreadInfo.setThreadGroup(tg);        }    }        void commandRun(StringTokenizer t) {        /*         * The 'run' command makes little sense in a          * that doesn't support restarts or multiple VMs. However,         * this is an attempt to emulate the behavior of the old         * JDB as much as possible. For new users and implementations         * it is much more straightforward to launch immedidately         * with the -launch option.         */        VMConnection connection = Env.connection();        if (!connection.isLaunch()) {            if (!t.hasMoreTokens()) {                commandCont();            } else {                MessageOutput.println("run <args> command is valid only with launched VMs");            }            return;        }         if (connection.isOpen()) {            MessageOutput.println("VM already running. use cont to continue after events.");            return;        }        /*         * Set the main class and any arguments. Note that this will work         * only with the standard launcher, "com.sun.jdi.CommandLineLauncher"         */        String args;        if (t.hasMoreTokens()) {            args = t.nextToken("");            boolean argsSet = connection.setConnectorArg("main", args);            if (!argsSet) {                MessageOutput.println("Unable to set main class and arguments");                return;            }         } else {            args = connection.connectorArg("main");            if (args.length() == 0) {                MessageOutput.println("Main class and arguments must be specified");                return;            }        }        MessageOutput.println("run", args);        /*         * Launch the VM.         */        connection.open();            }    void commandLoad(StringTokenizer t) {        MessageOutput.println("The load command is no longer supported.");    }    private List allThreads(ThreadGroupReference group) {        List list = new ArrayList();        list.addAll(group.threads());        Iterator iter = group.threadGroups().iterator();        while (iter.hasNext()) {            ThreadGroupReference child = (ThreadGroupReference)iter.next();            list.addAll(allThreads(child));        }        return list;    }    void commandSuspend(StringTokenizer t) {        if (!t.hasMoreTokens()) {            Env.vm().suspend();            MessageOutput.println("All threads suspended.");        } else {            while (t.hasMoreTokens()) {                ThreadInfo threadInfo = doGetThread(t.nextToken());                if (threadInfo != null) {                    threadInfo.getThread().suspend();                }                            }        }    }    void commandResume(StringTokenizer t) {         if (!t.hasMoreTokens()) {             ThreadInfo.invalidateAll();             Env.vm().resume();             MessageOutput.println("All threads resumed.");         } else {             while (t.hasMoreTokens()) {                ThreadInfo threadInfo = doGetThread(t.nextToken());                if (threadInfo != null) {                    threadInfo.invalidate();                    threadInfo.getThread().resume();                }            }        }    }    void commandCont() {        if (ThreadInfo.getCurrentThreadInfo() == null) {            MessageOutput.println("Nothing suspended.");            return;        }        ThreadInfo.invalidateAll();        Env.vm().resume();    }    void clearPreviousStep(ThreadReference thread) {        /*         * A previous step may not have completed on this thread;          * if so, it gets removed here.          */         EventRequestManager mgr = Env.vm().eventRequestManager();         List requests = mgr.stepRequests();         Iterator iter = requests.iterator();         while (iter.hasNext()) {             StepRequest request = (StepRequest)iter.next();             if (request.thread().equals(thread)) {                 mgr.deleteEventRequest(request);                 break;             }         }    }    /* step     *     */    void commandStep(StringTokenizer t) {        ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();        if (threadInfo == null) {            MessageOutput.println("Nothing suspended.");            return;        }        int depth;        if (t.hasMoreTokens() &&                  t.nextToken().toLowerCase().equals("up")) {            depth = StepRequest.STEP_OUT;        } else {            depth = StepRequest.STEP_INTO;        }        clearPreviousStep(threadInfo.getThread());        EventRequestManager reqMgr = Env.vm().eventRequestManager();        StepRequest request = reqMgr.createStepRequest(threadInfo.getThread(),                                                       StepRequest.STEP_LINE, depth);        if (depth == StepRequest.STEP_INTO) {            Env.addExcludes(request);        }        // We want just the next step event and no others        request.addCountFilter(1);        request.enable();        ThreadInfo.invalidateAll();        Env.vm().resume();    }    /* stepi     * step instruction.     */    void commandStepi() {        ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();        if (threadInfo == null) {            MessageOutput.println("Nothing suspended.");            return;        }        clearPreviousStep(threadInfo.getThread());        EventRequestManager reqMgr = Env.vm().eventRequestManager();        StepRequest request = reqMgr.createStepRequest(threadInfo.getThread(),                                                       StepRequest.STEP_MIN,                                                       StepRequest.STEP_INTO);        Env.addExcludes(request);        // We want just the next step event and no others        request.addCountFilter(1);        request.enable();        ThreadInfo.invalidateAll();        Env.vm().resume();    }    void commandNext() {        ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();        if (threadInfo == null) {

⌨️ 快捷键说明

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