private void initSourceBreakpoints() { synchronized (sourceBreakpointsInitLock) { if (scriptBP == null) { scriptBP = ClassLoadUnloadBreakpoint.create(JSUtils.NASHORN_SCRIPT+"*", false, ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED); scriptBP.setHidden(true); scriptBP.setSuspend(EventRequest.SUSPEND_NONE); sourceBindBP = MethodBreakpoint.create(NASHORN_CONTEXT_CLASS, NASHORN_CONTEXT_SOURCE_BIND_METHOD); sourceBindBP.setHidden(true); sourceBindBP.setSuspend(EventRequest.SUSPEND_EVENT_THREAD); functionClassBP = MethodBreakpoint.create(NASHORN_FUNCTION_NODE_CLASS, NASHORN_FUNCTION_NODE_SET_CLASS); functionClassBP.setHidden(true); functionClassBP.setSuspend(EventRequest.SUSPEND_EVENT_THREAD); debuggerBP = MethodBreakpoint.create(NASHORN_SCRIPT_RUNTIME_CLASS, NASHORN_SCRIPT_RUNTIME_DEBUGGER_METHOD); debuggerBP.setHidden(true); debuggerBP.setSuspend(EventRequest.SUSPEND_EVENT_THREAD); } } }
private Operator createOperator ( VirtualMachine virtualMachine, final Object startLock ) { return new Operator ( virtualMachine, debuggerImpl, new Executor () { @Override public boolean exec(Event event) { synchronized(startLock) { startLock.notify(); } return false; } @Override public void removed(EventRequest eventRequest) {} }, new Runnable () { @Override public void run () { debuggerImpl.finish(); } }, debuggerImpl.accessLock ); }
private void stepDone(EventRequest er) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper { JPDAThreadImpl t; if (er instanceof StepRequest) { StepRequest sr = (StepRequest) er; t = ((JPDADebuggerImpl) debugger).getThread(StepRequestWrapper.thread(sr)); } else { ThreadReference tr = (ThreadReference) EventRequestWrapper.getProperty(er, "thread"); // NOI18N if (tr != null) { t = ((JPDADebuggerImpl) debugger).getThread(tr); } else { t = null; } } if (t != null) { t.setInStep(false, null); } }
/** * Resolve all deferred eventRequests waiting for 'refType'. * @return true if it completes successfully, false on error. */ boolean resolve(ClassPrepareEvent event) { boolean failure = false; synchronized(eventRequestSpecs) { for (EventRequestSpec spec : eventRequestSpecs) { if (!spec.isResolved()) { try { EventRequest eventRequest = spec.resolve(event); if (eventRequest != null) { MessageOutput.println("Set deferred", spec.toString()); } } catch (Exception e) { MessageOutput.println("Unable to set deferred", new Object [] {spec.toString(), spec.errorMessageFor(e)}); failure = true; } } } } return !failure; }
ExceptionRequestImpl(ReferenceType refType, boolean notifyCaught, boolean notifyUncaught) { exception = refType; caught = notifyCaught; uncaught = notifyUncaught; { ReferenceTypeImpl exc; if (exception == null) { exc = new ClassTypeImpl(vm, 0); } else { exc = (ReferenceTypeImpl)exception; } filters.add(JDWP.EventRequest.Set.Modifier.ExceptionOnly. create(exc, caught, uncaught)); } requestList().add(this); }
public void resume() { switch (suspendPolicy()) { case EventRequest.SUSPEND_ALL: vm.resume(); break; case EventRequest.SUSPEND_EVENT_THREAD: ThreadReference thread = eventThread(); if (thread == null) { throw new InternalException("Inconsistent suspend policy"); } thread.resume(); break; case EventRequest.SUSPEND_NONE: // Do nothing break; default: throw new InternalException("Invalid suspend policy"); } }
/** * Suspend the main thread when the program enters the main method of the specified main class. * @param debugSession * the debug session. * @param mainClass * the fully qualified name of the main class. * @return * a {@link CompletableFuture} that contains the suspended main thread id. */ public static CompletableFuture<Long> stopOnEntry(IDebugSession debugSession, String mainClass) { CompletableFuture<Long> future = new CompletableFuture<>(); EventRequestManager manager = debugSession.getVM().eventRequestManager(); MethodEntryRequest request = manager.createMethodEntryRequest(); request.addClassFilter(mainClass); request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); debugSession.getEventHub().events().filter(debugEvent -> { return debugEvent.event instanceof MethodEntryEvent && request.equals(debugEvent.event.request()); }).subscribe(debugEvent -> { Method method = ((MethodEntryEvent) debugEvent.event).method(); if (method.isPublic() && method.isStatic() && method.name().equals("main") && method.signature().equals("([Ljava/lang/String;)V")) { deleteEventRequestSafely(debugSession.getVM().eventRequestManager(), request); debugEvent.shouldResume = false; ThreadReference bpThread = ((MethodEntryEvent) debugEvent.event).thread(); future.complete(bpThread.uniqueID()); } }); request.enable(); return future; }
@Override public void perform(String[] argv, Context ctx) { EventRequestManager manager = ctx.getVm().eventRequestManager(); MethodEntryRequest mer = manager.createMethodEntryRequest(); mer.setSuspendPolicy(EventRequest.SUSPEND_NONE); mer.enable(); ctx.register(mer, new EventCallback() { @Override public void handleEvent(Event event) { MethodEntryEvent mee = (MethodEntryEvent) event; Method method = mee.method(); System.out.println("--" + method.name()); // mee.thread().resume(); } }); }
@Override public int onReached(SuspendContextImpl context) { StackFrameProxyImpl proxy = context.getFrameProxy(); if (proxy != null) { try { ObjectReference reference = proxy.thisObject(); if (reference != null) { DebugProcessImpl debugProcess = context.getDebugProcessNoAssert(); BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(debugProcess.getProject()).getBreakpointManager(); StepIntoBreakpoint breakpoint = breakpointManager.addStepIntoBreakpoint(myMethodFilter); if (breakpoint != null) { breakpointManager.applyThreadFilter(debugProcess, null); // clear the filter on resume breakpoint.addInstanceFilter(reference.uniqueID()); breakpoint.setInstanceFiltersEnabled(true); breakpoint.setSuspendPolicy(context.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD ? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL); breakpoint.createRequest(debugProcess); debugProcess.setRunToCursorBreakpoint(breakpoint); return RequestHint.RESUME; } } } catch (EvaluateException ignored) { } } return RequestHint.STOP; }
@Override protected void resumeAction() { SuspendContextImpl context = getSuspendContext(); if (context != null && context.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD) { myThreadBlockedMonitor.startWatching(myContextThread); } if (context != null && Registry.is("debugger.step.resumes.one.thread") && context.getSuspendPolicy() == EventRequest.SUSPEND_ALL && myContextThread != null) { getSuspendManager().resumeThread(context, myContextThread); } else { super.resumeAction(); } }
/** * Resolve all deferred eventRequests waiting for 'refType'. * @return true if it completes successfully, false on error. */ boolean resolve(ClassPrepareEvent event) { boolean failure = false; synchronized(eventRequestSpecs) { for (EventRequestSpec spec : eventRequestSpecs) { if (!spec.isResolved()) { try { EventRequest eventRequest = spec.resolve(event); if (eventRequest != null) { env.messageOutput().println("Set deferred", spec.toString()); } } catch (Exception e) { env.messageOutput().println("Unable to set deferred", new Object [] {spec.toString(), spec.errorMessageFor(e)}); failure = true; } } } } return !failure; }
public void contextAction() { showStatusText(DebuggerBundle.message("status.run.to.cursor")); cancelRunToCursorBreakpoint(); if (myRunToCursorBreakpoint == null) { return; } if (myIgnoreBreakpoints) { final BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager(); breakpointManager.disableBreakpoints(DebugProcessImpl.this); } applyThreadFilter(getContextThread()); final SuspendContextImpl context = getSuspendContext(); myRunToCursorBreakpoint.SUSPEND_POLICY = context.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD? DebuggerSettings.SUSPEND_THREAD : DebuggerSettings.SUSPEND_ALL; myRunToCursorBreakpoint.LOG_ENABLED = false; myRunToCursorBreakpoint.createRequest(context.getDebugProcess()); DebugProcessImpl.this.myRunToCursorBreakpoint = myRunToCursorBreakpoint; super.contextAction(); }
protected void createRequest() { final EventRequestManager manager = owner.getEventRequestManager(); if (manager != null) { try { final ClassPrepareRequest request = manager.createClassPrepareRequest(); owner.jdiManager().modelFilter().filter(request); request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); request.enable(); owner.addJDIEventListener(this, request); } catch (final RuntimeException e) { JiveDebugPlugin.log(e); } } }
protected void removeFieldRequests(final JDIDebugTarget target) { final EventRequestManager manager = target.getEventRequestManager(); if (manager != null && !fieldRequests.isEmpty()) { try { manager.deleteEventRequests(fieldRequests); for (final EventRequest request : fieldRequests) { target.removeJDIEventListener( request instanceof AccessWatchpointRequest ? fieldReadHandler : fieldWriteHandler, request); } } catch (final RuntimeException e) { JiveDebugPlugin.log(e); } } }
protected void createRequest() { final EventRequestManager manager = owner.getEventRequestManager(); if (manager != null) { try { if (request != null) { removeRequest(); } request = manager.createMethodEntryRequest(); owner.jdiManager().modelFilter().filter(request); request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); request.enable(); owner.addJDIEventListener(this, request); } catch (final RuntimeException e) { JiveDebugPlugin.log(e); } } }
protected void createRequest() { final EventRequestManager manager = owner.getEventRequestManager(); if (manager != null) { try { if (request != null) { removeRequest(); } request = manager.createMethodExitRequest(); owner.jdiManager().modelFilter().filter(request); request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); request.enable(); owner.addJDIEventListener(this, request); } catch (final RuntimeException e) { JiveDebugPlugin.log(e); } } }
protected void createRequest() { final EventRequestManager manager = getEventRequestManager(); if (manager != null) { try { if (stepRequest != null) { removeRequest(); } stepRequest = manager.createStepRequest(getUnderlyingThread(), StepRequest.STEP_LINE, StepRequest.STEP_INTO); final JiveDebugTarget target = (JiveDebugTarget) getDebugTarget(); final IModelFilter requestFilter = target.jdiManager().modelFilter(); requestFilter.filter(stepRequest); stepRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); stepRequest.enable(); addJDIEventListener(this, stepRequest); } catch (final RuntimeException e) { logError(e); } } }
@Override protected void createRequest() { final EventRequestManager manager = getEventRequestManager(); if (manager != null) { try { final EventRequest request = manager.createThreadDeathRequest(); request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); request.enable(); addJDIEventListener(this, request); } catch (final RuntimeException e) { logError(e); } } }
/** * Checks whether the list of reference types are new types (the breakpoint * was not submitted anywhere yet), or are some of the types for which the * breakpoint was submitted already. * @param referenceTypes The types to check */ private boolean areNewOrSubmittedTypes(List<ReferenceType> referenceTypes) { List<EventRequest> eventRequests = getEventRequests(); List<BreakpointRequest> brs = new LinkedList<BreakpointRequest>(); for (EventRequest er : eventRequests) { if (er instanceof BreakpointRequest) { brs.add((BreakpointRequest) er); } } if (brs.isEmpty()) { return true; } for (ReferenceType rt : referenceTypes) { // Check whether breakpoint requests' types contains rt: boolean contains = false; for (BreakpointRequest br : brs) { ReferenceType brt = br.location().declaringType(); if (rt.equals(brt)) { contains = true; break; } } if (!contains) { return false; } } return true; }
@Override protected EventRequest createEventRequest(EventRequest oldRequest) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper { Location location = BreakpointRequestWrapper.location((BreakpointRequest) oldRequest); BreakpointRequest br = EventRequestManagerWrapper.createBreakpointRequest(getEventRequestManager(), location); setFilters(br); return br; }
@Override protected EventRequest createEventRequest(EventRequest oldRequest) throws VMDisconnectedExceptionWrapper, InternalExceptionWrapper { if (oldRequest instanceof ThreadStartRequest) { return EventRequestManagerWrapper.createThreadStartRequest(getEventRequestManager()); } if (oldRequest instanceof ThreadDeathRequest) { return EventRequestManagerWrapper.createThreadDeathRequest(getEventRequestManager()); } return null; }
@Override protected ExceptionRequest createEventRequest(EventRequest oldRequest) throws VMDisconnectedExceptionWrapper, InternalExceptionWrapper { ExceptionRequest excRequest = (ExceptionRequest) oldRequest; ExceptionRequest er = EventRequestManagerWrapper.createExceptionRequest ( getEventRequestManager(), ExceptionRequestWrapper.exception(excRequest), ExceptionRequestWrapper.notifyCaught(excRequest), ExceptionRequestWrapper.notifyUncaught(excRequest) ); addFilters(er, breakpoint.getClassFilters(), breakpoint.getClassExclusionFilters()); return er; }
protected final List<EventRequest> getEventRequests() { List<EventRequest> ers; synchronized (this) { ers = new LinkedList<EventRequest>(requests); ers = Collections.unmodifiableList(ers); } return ers; }
/** * Removes binding between the specified event request and a registered object. * * @param req request * @see #register */ public synchronized void unregister (EventRequest req) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper { Executor e = (Executor) EventRequestWrapper.getProperty(req, "executor"); EventRequestWrapper.putProperty (req, "executor", null); // NOI18N if (e != null) { e.removed(req); } if (req instanceof StepRequest) { ThreadReference tr = StepRequestWrapper.thread((StepRequest) req); debugger.getThread(tr).setInStep(false, null); } }
@Override public void run() { EventQueue queue = Env.vm().eventQueue(); while (connected) { try { EventSet eventSet = queue.remove(); boolean resumeStoppedApp = false; EventIterator it = eventSet.eventIterator(); while (it.hasNext()) { resumeStoppedApp |= !handleEvent(it.nextEvent()); } if (resumeStoppedApp) { eventSet.resume(); } else if (eventSet.suspendPolicy() == EventRequest.SUSPEND_ALL) { setCurrentThread(eventSet); notifier.vmInterrupted(); } } catch (InterruptedException exc) { // Do nothing. Any changes will be seen at top of loop. } catch (VMDisconnectedException discExc) { handleDisconnectedException(); break; } } synchronized (this) { completed = true; notifyAll(); } }
/** * @return If this EventRequestSpec matches the 'refType' * return the cooresponding EventRequest. Otherwise * return null. */ synchronized EventRequest resolve(ClassPrepareEvent event) throws Exception { if ((resolved == null) && (prepareRequest != null) && prepareRequest.equals(event.request())) { resolved = resolveEventRequest(event.referenceType()); prepareRequest.disable(); Env.vm().eventRequestManager().deleteEventRequest(prepareRequest); prepareRequest = null; if (refSpec instanceof PatternReferenceTypeSpec) { PatternReferenceTypeSpec prs = (PatternReferenceTypeSpec)refSpec; if (! prs.isUnique()){ /* * Class pattern event requests are never * considered "resolved", since future class loads * might also match. * Create and enable a new ClassPrepareRequest to * keep trying to resolve. */ resolved = null; prepareRequest = refSpec.createPrepareRequest(); prepareRequest.enable(); } } } return resolved; }
private EventRequest resolveAgainstPreparedClasses() throws Exception { for (ReferenceType refType : Env.vm().allClasses()) { if (refType.isPrepared() && refSpec.matches(refType)) { resolved = resolveEventRequest(refType); } } return resolved; }
void resolveAll() { for (EventRequestSpec spec : eventRequestSpecs) { try { EventRequest eventRequest = spec.resolveEagerly(); if (eventRequest != null) { MessageOutput.println("Set deferred", spec.toString()); } } catch (Exception e) { } } }