executionmanager.java
来自「jpda例子文件」· Java 代码 · 共 827 行 · 第 1/2 页
JAVA
827 行
/* * @(#)ExecutionManager.java 1.26 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Copyright (c) 1997-1999 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.bdi;import com.sun.jdi.*;import com.sun.jdi.event.*;import com.sun.jdi.request.*;import com.sun.jdi.connect.*;import com.sun.tools.example.debug.expr.ExpressionParser;import com.sun.tools.example.debug.expr.ParseException;import java.io.*;import java.util.*;import com.sun.tools.example.debug.event.*;import javax.swing.SwingUtilities;/** * Move this towards being only state and functionality * that spans across Sessions (and thus VMs). */public class ExecutionManager { private Session session; /** * Get/set JDI trace mode. */ int traceMode = VirtualMachine.TRACE_NONE; ////////////////// Listener registration ////////////////// // Session Listeners Vector sessionListeners = new Vector(); public void addSessionListener(SessionListener listener) { sessionListeners.add(listener); } public void removeSessionListener(SessionListener listener) { sessionListeners.remove(listener); } // Spec Listeners Vector specListeners = new Vector(); public void addSpecListener(SpecListener cl) { specListeners.add(cl); } public void removeSpecListener(SpecListener cl) { specListeners.remove(cl); } // JDI Listeners Vector jdiListeners = new Vector(); /** * Adds a JDIListener */ public void addJDIListener(JDIListener jl) { jdiListeners.add(jl); } /** * Adds a JDIListener - at the specified position */ public void addJDIListener(int index, JDIListener jl) { jdiListeners.add(index, jl); } /** * Removes a JDIListener */ public void removeJDIListener(JDIListener jl) { jdiListeners.remove(jl); } // App Echo Listeners private Vector appEchoListeners = new Vector(); public void addApplicationEchoListener(OutputListener l) { appEchoListeners.addElement(l); } public void removeApplicationEchoListener(OutputListener l) { appEchoListeners.removeElement(l); } // App Output Listeners private Vector appOutputListeners = new Vector(); public void addApplicationOutputListener(OutputListener l) { appOutputListeners.addElement(l); } public void removeApplicationOutputListener(OutputListener l) { appOutputListeners.removeElement(l); } // App Error Listeners private Vector appErrorListeners = new Vector(); public void addApplicationErrorListener(OutputListener l) { appErrorListeners.addElement(l); } public void removeApplicationErrorListener(OutputListener l) { appErrorListeners.removeElement(l); } // Diagnostic Listeners private Vector diagnosticsListeners = new Vector(); public void addDiagnosticsListener(OutputListener l) { diagnosticsListeners.addElement(l); } public void removeDiagnosticsListener(OutputListener l) { diagnosticsListeners.removeElement(l); } /////////// End Listener Registration ////////////// //### We probably don't want this public public VirtualMachine vm() { return session == null ? null : session.vm; } void ensureActiveSession() throws NoSessionException { if (session == null) throw new NoSessionException(); } public EventRequestManager eventRequestManager() { return vm() == null ? null : vm().eventRequestManager(); } /** * Get JDI trace mode. */ public int getTraceMode(int mode) { return traceMode; } /** * Set JDI trace mode. */ public void setTraceMode(int mode) { traceMode = mode; if (session != null) { session.setTraceMode(mode); } } /** * Determine if VM is interrupted, i.e, present and not running. */ public boolean isInterrupted() /* should: throws NoSessionException */ {// ensureActiveSession(); return session.interrupted; } /** * Return a list of ReferenceType objects for all * currently loaded classes and interfaces. * Array types are not returned. */ public List allClasses() throws NoSessionException { ensureActiveSession(); return vm().allClasses(); } /** * Return a ReferenceType object for the currently * loaded class or interface whose fully-qualified * class name is specified, else return null if there * is none. * * In general, we must return a list of types, because * multiple class loaders could have loaded a class * with the same fully-qualified name. */ public List findClassesByName(String name) throws NoSessionException { ensureActiveSession(); return vm().classesByName(name); } /** * Return a list of ReferenceType objects for all * currently loaded classes and interfaces whose name * matches the given pattern. The pattern syntax is * open to some future revision, but currently consists * of a fully-qualified class name in which the first * component may optionally be a "*" character, designating * an arbitrary prefix. */ public List findClassesMatchingPattern(String pattern) throws NoSessionException { ensureActiveSession(); List result = new ArrayList(); //### Is default size OK? if (pattern.startsWith("*.")) { // Wildcard matches any leading package name. pattern = pattern.substring(1); List classes = vm().allClasses(); Iterator iter = classes.iterator(); while (iter.hasNext()) { ReferenceType type = ((ReferenceType)iter.next()); if (type.name().endsWith(pattern)) { result.add(type); } } return result; } else { // It's a class name. return vm().classesByName(pattern); } } /* * Return a list of ThreadReference objects corresponding * to the threads that are currently active in the VM. * A thread is removed from the list just before the * thread terminates. */ public List allThreads() throws NoSessionException { ensureActiveSession(); return vm().allThreads(); } /* * Return a list of ThreadGroupReference objects corresponding * to the top-level threadgroups that are currently active in the VM. * Note that a thread group may be empty, or contain no threads as * descendents. */ public List topLevelThreadGroups() throws NoSessionException { ensureActiveSession(); return vm().topLevelThreadGroups(); } /* * Return the system threadgroup. */ public ThreadGroupReference systemThreadGroup() throws NoSessionException { ensureActiveSession(); return (ThreadGroupReference)vm().topLevelThreadGroups().get(0); } /* * Evaluate an expression. */ public Value evaluate(final StackFrame f, String expr) throws ParseException, InvocationException, InvalidTypeException, ClassNotLoadedException, NoSessionException, IncompatibleThreadStateException { ExpressionParser.GetFrame frameGetter = null; ensureActiveSession(); if (f != null) { frameGetter = new ExpressionParser.GetFrame() { public StackFrame get() /* throws IncompatibleThreadStateException */ { return f; } }; } return ExpressionParser.evaluate(expr, vm(), frameGetter); } /* * Start a new VM. */ public void run(boolean suspended, String vmArgs, String className, String args) throws VMLaunchFailureException { endSession(); //### Set a breakpoint on 'main' method. //### Would be cleaner if we could just bring up VM already suspended. if (suspended) { //### Set breakpoint at 'main(java.lang.String[])'. List argList = new ArrayList(1); argList.add("java.lang.String[]"); createMethodBreakpoint(className, "main", argList); } String cmdLine = className + " " + args; startSession(new ChildSession(this, vmArgs, cmdLine, appInput, appOutput, appError, diagnostics)); } /* * Attach to an existing VM. */ public void attach(String portName) throws VMLaunchFailureException { endSession(); //### Changes made here for connectors have broken the //### the 'Session' abstraction. The 'Session.attach()' //### method is intended to encapsulate all of the various //### ways in which session start-up can fail. (maddox 12/18/98) /* * Now that attaches and launches both go through Connectors, * it may be worth creating a new subclass of Session for * attach sessions. */ VirtualMachineManager mgr = Bootstrap.virtualMachineManager(); List connectors = mgr.attachingConnectors(); AttachingConnector connector = (AttachingConnector)connectors.get(0); Map arguments = connector.defaultArguments(); ((Connector.Argument)arguments.get("port")).setValue(portName); Session newSession = internalAttach(connector, arguments); if (newSession != null) { startSession(newSession); } } private Session internalAttach(AttachingConnector connector, Map arguments) { try { VirtualMachine vm = connector.attach(arguments); return new Session(vm, this, diagnostics); } catch (IOException ioe) { diagnostics.putString("\n Unable to attach to target VM: " + ioe.getMessage()); } catch (IllegalConnectorArgumentsException icae) { diagnostics.putString("\n Invalid connector arguments: " + icae.getMessage()); } return null; } private Session internalListen(ListeningConnector connector, Map arguments) { try { VirtualMachine vm = connector.accept(arguments); return new Session(vm, this, diagnostics); } catch (IOException ioe) { diagnostics.putString( "\n Unable to accept connection to target VM: " + ioe.getMessage()); } catch (IllegalConnectorArgumentsException icae) { diagnostics.putString("\n Invalid connector arguments: " + icae.getMessage()); } return null; } /* * Connect via user specified arguments * @return true on success */ public boolean explictStart(Connector connector, Map arguments) throws VMLaunchFailureException { Session newSession = null; endSession(); if (connector instanceof LaunchingConnector) { // we were launched, use ChildSession
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?