executionmanager.java
来自「jpda例子文件」· Java 代码 · 共 827 行 · 第 1/2 页
JAVA
827 行
newSession = new ChildSession(this, (LaunchingConnector)connector, arguments, appInput, appOutput, appError, diagnostics); } else if (connector instanceof AttachingConnector) { newSession = internalAttach((AttachingConnector)connector, arguments); } else if (connector instanceof ListeningConnector) { newSession = internalListen((ListeningConnector)connector, arguments); } else { diagnostics.putString("\n Unknown connector: " + connector); } if (newSession != null) { startSession(newSession); } return newSession != null; } /* * Detach from VM. If VM was started by debugger, terminate it. */ public void detach() throws NoSessionException { ensureActiveSession(); endSession(); } private void startSession(Session s) throws VMLaunchFailureException { if (!s.attach()) { throw new VMLaunchFailureException(); } session = s; EventRequestManager em = vm().eventRequestManager(); ClassPrepareRequest classPrepareRequest = em.createClassPrepareRequest(); //### We must allow the deferred breakpoints to be resolved before //### we continue executing the class. We could optimize if there //### were no deferred breakpoints outstanding for a particular class. //### Can we do this with JDI? classPrepareRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL); classPrepareRequest.enable(); ClassUnloadRequest classUnloadRequest = em.createClassUnloadRequest(); classUnloadRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE); classUnloadRequest.enable(); ThreadStartRequest threadStartRequest = em.createThreadStartRequest(); threadStartRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE); threadStartRequest.enable(); ThreadDeathRequest threadDeathRequest = em.createThreadDeathRequest(); threadDeathRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE); threadDeathRequest.enable(); ExceptionRequest exceptionRequest = em.createExceptionRequest(null, false, true); exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL); exceptionRequest.enable(); validateThreadInfo(); session.interrupted = true; notifySessionStart(); } void endSession() { if (session != null) { session.detach(); session = null; invalidateThreadInfo(); notifySessionDeath(); } } /* * Suspend all VM activity. */ public void interrupt() throws NoSessionException { ensureActiveSession(); vm().suspend(); //### Is it guaranteed that the interrupt has happened? validateThreadInfo(); session.interrupted = true; notifyInterrupted(); } /* * Resume interrupted VM. */ public void go() throws NoSessionException, VMNotInterruptedException { ensureActiveSession(); invalidateThreadInfo(); session.interrupted = false; notifyContinued(); vm().resume(); } /* * Stepping. */ void clearPreviousStep(ThreadReference thread) { /* * A previous step may not have completed on this thread; * if so, it gets removed here. */ EventRequestManager mgr = 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; } } } private void generalStep(ThreadReference thread, int size, int depth) throws NoSessionException { ensureActiveSession(); invalidateThreadInfo(); session.interrupted = false; notifyContinued(); clearPreviousStep(thread); EventRequestManager reqMgr = vm().eventRequestManager(); StepRequest request = reqMgr.createStepRequest(thread, size, depth); // We want just the next step event and no others request.addCountFilter(1); request.enable(); vm().resume(); } public void stepIntoInstruction(ThreadReference thread) throws NoSessionException { generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO); } public void stepOverInstruction(ThreadReference thread) throws NoSessionException { generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_OVER); } public void stepIntoLine(ThreadReference thread) throws NoSessionException, AbsentInformationException { generalStep(thread, StepRequest.STEP_LINE, StepRequest.STEP_INTO); } public void stepOverLine(ThreadReference thread) throws NoSessionException, AbsentInformationException { generalStep(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER); } public void stepOut(ThreadReference thread) throws NoSessionException { generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_OUT); } /* * Thread control. */ public void suspendThread(ThreadReference thread) throws NoSessionException { ensureActiveSession(); thread.suspend(); } public void resumeThread(ThreadReference thread) throws NoSessionException { ensureActiveSession(); thread.resume(); } public void stopThread(ThreadReference thread) throws NoSessionException { ensureActiveSession(); //### Need an exception now. Which one to use? //thread.stop(); } /* * ThreadInfo objects -- Allow query of thread status and stack. */ private List threadInfoList = new LinkedList(); //### Should be weak! (in the value, not the key) private HashMap threadInfoMap = new HashMap(); public ThreadInfo threadInfo(ThreadReference thread) { if (session == null || thread == null) { return null; } ThreadInfo info = (ThreadInfo)threadInfoMap.get(thread); if (info == null) { //### Should not hardcode initial frame count and prefetch here! //info = new ThreadInfo(thread, 10, 10); info = new ThreadInfo(thread); if (session.interrupted) { info.validate(); } threadInfoList.add(info); threadInfoMap.put(thread, info); } return info; } void validateThreadInfo() { session.interrupted = true; Iterator iter = threadInfoList.iterator(); while (iter.hasNext()) { ((ThreadInfo)iter.next()).validate(); } } private void invalidateThreadInfo() { if (session != null) { session.interrupted = false; Iterator iter = threadInfoList.iterator(); while (iter.hasNext()) { ((ThreadInfo)iter.next()).invalidate(); } } } void removeThreadInfo(ThreadReference thread) { ThreadInfo info = (ThreadInfo)threadInfoMap.get(thread); if (info != null) { info.invalidate(); threadInfoMap.remove(thread); threadInfoList.remove(info); } } /* * Listen for Session control events. */ private void notifyInterrupted() { Vector l = (Vector)sessionListeners.clone(); EventObject evt = new EventObject(this); for (int i = 0; i < l.size(); i++) { ((SessionListener)l.elementAt(i)).sessionInterrupt(evt); } } private void notifyContinued() { Vector l = (Vector)sessionListeners.clone(); EventObject evt = new EventObject(this); for (int i = 0; i < l.size(); i++) { ((SessionListener)l.elementAt(i)).sessionContinue(evt); } } private void notifySessionStart() { Vector l = (Vector)sessionListeners.clone(); EventObject evt = new EventObject(this); for (int i = 0; i < l.size(); i++) { ((SessionListener)l.elementAt(i)).sessionStart(evt); } } private void notifySessionDeath() {/*** noop for now Vector l = (Vector)sessionListeners.clone(); EventObject evt = new EventObject(this); for (int i = 0; i < l.size(); i++) { ((SessionListener)l.elementAt(i)).sessionDeath(evt); }****/ } /* * Listen for input and output requests from the application * being debugged. These are generated only when the debuggee * is spawned as a child of the debugger. */ private Object inputLock = new Object(); private LinkedList inputBuffer = new LinkedList(); private void resetInputBuffer() { synchronized (inputLock) { inputBuffer = new LinkedList(); } } public void sendLineToApplication(String line) { synchronized (inputLock) { inputBuffer.addFirst(line); inputLock.notifyAll(); } } private InputListener appInput = new InputListener() { public String getLine() { // Don't allow reader to be interrupted -- catch and retry. String line = null; while (line == null) { synchronized (inputLock) { try { while (inputBuffer.size() < 1) { inputLock.wait(); } line = (String)inputBuffer.removeLast(); } catch (InterruptedException e) {} } } // We must not be holding inputLock here, as the listener // that we call to echo a line might call us re-entrantly // to provide another line of input. // Run in Swing event dispatcher thread. final String input = line; SwingUtilities.invokeLater(new Runnable() { public void run() { echoInputLine(input); } }); return line; } }; private static String newline = System.getProperty("line.separator"); private void echoInputLine(String line) { Vector l = (Vector)appEchoListeners.clone(); for (int i = 0; i < l.size(); i++) { OutputListener ol = (OutputListener)l.elementAt(i); ol.putString(line); ol.putString(newline); } } private OutputListener appOutput = new OutputListener() { public void putString(String string) { Vector l = (Vector)appOutputListeners.clone(); for (int i = 0; i < l.size(); i++) { ((OutputListener)l.elementAt(i)).putString(string); } } }; private OutputListener appError = new OutputListener() { public void putString(String string) { Vector l = (Vector)appErrorListeners.clone(); for (int i = 0; i < l.size(); i++) { ((OutputListener)l.elementAt(i)).putString(string); } } }; private OutputListener diagnostics = new OutputListener() { public void putString(String string) { Vector l = (Vector)diagnosticsListeners.clone(); for (int i = 0; i < l.size(); i++) { ((OutputListener)l.elementAt(i)).putString(string); } } }; ///////////// Spec Request Creation/Deletion/Query /////////// private EventRequestSpecList specList = new EventRequestSpecList(this); public BreakpointSpec createSourceLineBreakpoint(String sourceName, int line) { return specList.createSourceLineBreakpoint(sourceName, line); } public BreakpointSpec createClassLineBreakpoint(String classPattern, int line) { return specList.createClassLineBreakpoint(classPattern, line); } public BreakpointSpec createMethodBreakpoint(String classPattern, String methodId, List methodArgs) { return specList.createMethodBreakpoint(classPattern, methodId, methodArgs); } public ExceptionSpec createExceptionIntercept(String classPattern, boolean notifyCaught, boolean notifyUncaught) { return specList.createExceptionIntercept(classPattern, notifyCaught, notifyUncaught); } public AccessWatchpointSpec createAccessWatchpoint(String classPattern, String fieldId) { return specList.createAccessWatchpoint(classPattern, fieldId); } public ModificationWatchpointSpec createModificationWatchpoint(String classPattern, String fieldId) { return specList.createModificationWatchpoint(classPattern, fieldId); } public void delete(EventRequestSpec spec) { specList.delete(spec); } void resolve(ReferenceType refType) { specList.resolve(refType); } public void install(EventRequestSpec spec) { specList.install(spec, vm()); } public List eventRequestSpecs() { return specList.eventRequestSpecs(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?