private void setEventRequests(VirtualMachine vm) { EventRequestManager erm = vm.eventRequestManager(); // Normally, we want all uncaught exceptions. We request them // via the same mechanism as Commands.commandCatchException() // so the user can ignore them later if they are not // interested. // FIXME: this works but generates spurious messages on stdout // during startup: // Set uncaught java.lang.Throwable // Set deferred uncaught java.lang.Throwable Commands evaluator = new Commands(); evaluator.commandCatchException (new StringTokenizer("uncaught java.lang.Throwable")); ThreadStartRequest tsr = erm.createThreadStartRequest(); tsr.enable(); ThreadDeathRequest tdr = erm.createThreadDeathRequest(); tdr.enable(); }
private static void addBreakpoint(VirtualMachine vm, ReferenceType refType) { Location breakpointLocation = null; List<Location> locs; try { locs = refType.allLineLocations(); for (Location loc: locs) { if (loc.method().name().equals(METHOD_NAME)) { breakpointLocation = loc; break; } } } catch (AbsentInformationException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (breakpointLocation != null) { EventRequestManager evtReqMgr = vm.eventRequestManager(); BreakpointRequest bReq = evtReqMgr.createBreakpointRequest(breakpointLocation); bReq.setSuspendPolicy(BreakpointRequest.SUSPEND_ALL); bReq.enable(); } }
/** * 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(); } }); }
void deleteStepRequests(@Nullable final ThreadReference stepThread) { EventRequestManager requestManager = getVirtualMachineProxy().eventRequestManager(); List<StepRequest> stepRequests = requestManager.stepRequests(); if (!stepRequests.isEmpty()) { final List<StepRequest> toDelete = new ArrayList<StepRequest>(stepRequests.size()); for (final StepRequest request : stepRequests) { ThreadReference threadReference = request.thread(); // [jeka] on attempt to delete a request assigned to a thread with unknown status, a JDWP error occurs try { if (threadReference.status() != ThreadReference.THREAD_STATUS_UNKNOWN && (stepThread == null || stepThread.equals(threadReference))) { toDelete.add(request); } } catch (IllegalThreadStateException e) { LOG.info(e); // undocumented by JDI: may be thrown when querying thread status } catch (ObjectCollectedException ignored) { } } requestManager.deleteEventRequests(toDelete); } }
@Override public void deleteBreakpoint(Location location) throws DebuggerException { final String className = debuggerUtil.findFqnByPosition(location); final int lineNumber = location.getLineNumber(); EventRequestManager requestManager = getEventManager(); List<BreakpointRequest> snapshot = new ArrayList<>(requestManager.breakpointRequests()); for (BreakpointRequest breakpointRequest : snapshot) { com.sun.jdi.Location jdiLocation = breakpointRequest.location(); if (jdiLocation.declaringType().name().equals(className) && jdiLocation.lineNumber() == lineNumber) { requestManager.deleteEventRequest(breakpointRequest); LOG.debug("Delete breakpoint: {}", location); } } List<Breakpoint> defferedByClass = deferredBreakpoints.get(className); if (defferedByClass != null) { defferedByClass.removeIf( breakpoint -> { Location l = breakpoint.getLocation(); return l.getLineNumber() == location.getLineNumber() && l.getTarget().equals(location.getTarget()); }); } }
private void setEventRequests(VirtualMachine vm) { EventRequestManager erm = vm.eventRequestManager(); // Normally, we want all uncaught exceptions. We request them // via the same mechanism as Commands.commandCatchException() // so the user can ignore them later if they are not // interested. // FIXME: this works but generates spurious messages on stdout // during startup: // Set uncaught java.lang.Throwable // Set deferred uncaught java.lang.Throwable Commands evaluator = new Commands(env); evaluator.commandCatchException (new StringTokenizer("uncaught java.lang.Throwable")); ThreadStartRequest tsr = erm.createThreadStartRequest(); tsr.enable(); ThreadDeathRequest tdr = erm.createThreadDeathRequest(); tdr.enable(); }
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 removeRequest() { final EventRequestManager manager = owner.getEventRequestManager(); if (manager != null && request != null) { try { owner.removeJDIEventListener(this, request); manager.deleteEventRequest(request); request = null; } 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); } } }
protected void removeRequest() { final EventRequestManager manager = getEventRequestManager(); if (manager != null && stepRequest != null) { try { removeJDIEventListener(this, stepRequest); manager.deleteEventRequest(stepRequest); stepRequest = null; } 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); } } }
/** * Connects to the JVM. * * @param port the port number used for the connection to the JVM. */ public HotSwapperJpda(String port) throws IOException, IllegalConnectorArgumentsException { jvm = null; request = null; newClassFiles = null; trigger = new Trigger(); AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach"); Map arguments = connector.defaultArguments(); ((Connector.Argument) arguments.get("hostname")).setValue(HOST_NAME); ((Connector.Argument) arguments.get("port")).setValue(port); jvm = connector.attach(arguments); EventRequestManager manager = jvm.eventRequestManager(); request = methodEntryRequests(manager, TRIGGER_NAME); }
protected EventRequestManager getEventRequestManager () throws VMDisconnectedExceptionWrapper, InternalExceptionWrapper { VirtualMachine vm = getVirtualMachine(); if (vm == null) { // Already disconnected throw new VMDisconnectedExceptionWrapper(new VMDisconnectedException()); } return VirtualMachineWrapper.eventRequestManager (vm); }
private boolean setUpBoundaryStepRequest(EventRequestManager erm, ThreadReference trRef, boolean isNextOperationFromDifferentExpression) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper { boundaryStepRequest = EventRequestManagerWrapper.createStepRequest( erm, trRef, StepRequest.STEP_LINE, StepRequest.STEP_OVER ); if (isNextOperationFromDifferentExpression) { EventRequestWrapper.addCountFilter(boundaryStepRequest, 2); } else { EventRequestWrapper.addCountFilter(boundaryStepRequest, 1); } ((JPDADebuggerImpl) debugger).getOperator().register(boundaryStepRequest, this); EventRequestWrapper.setSuspendPolicy(boundaryStepRequest, debugger.getSuspend()); try { EventRequestWrapper.enable (boundaryStepRequest); requestsToCancel.add(boundaryStepRequest); } catch (IllegalThreadStateException itsex) { // the thread named in the request has died. ((JPDADebuggerImpl) debugger).getOperator().unregister(boundaryStepRequest); boundaryStepRequest = null; return false; } catch (InvalidRequestStateExceptionWrapper ex) { Exceptions.printStackTrace(ex); ((JPDADebuggerImpl) debugger).getOperator().unregister(boundaryStepRequest); boundaryStepRequest = null; return false; } return true; }
/** * The 'refType' is known to match, return the EventRequest. */ @Override EventRequest resolveEventRequest(ReferenceType refType) throws NoSuchFieldException { Field field = refType.fieldByName(fieldId); EventRequestManager em = refType.virtualMachine().eventRequestManager(); EventRequest wp = em.createModificationWatchpointRequest(field); wp.setSuspendPolicy(suspendPolicy); wp.enable(); return wp; }
private static void addClassWatch(VirtualMachine vm) { EventRequestManager erm = vm.eventRequestManager(); ClassPrepareRequest classPrepareRequest = erm .createClassPrepareRequest(); classPrepareRequest.addClassFilter(CLASS_NAME); classPrepareRequest.setEnabled(true); }
private static void addFieldWatch(VirtualMachine vm, ReferenceType refType) { EventRequestManager erm = vm.eventRequestManager(); Field field = refType.fieldByName(FIELD_NAME); ModificationWatchpointRequest modificationWatchpointRequest = erm .createModificationWatchpointRequest(field); modificationWatchpointRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); modificationWatchpointRequest.setEnabled(true); }