private void submitCheckForMonitorEntered(ObjectReference waitingMonitor) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper, IllegalThreadStateExceptionWrapper { try { ThreadReferenceWrapper.suspend(threadReference); logger.fine("submitCheckForMonitorEntered(): suspending "+threadName); ObjectReference monitor = ThreadReferenceWrapper.currentContendedMonitor(threadReference); if (monitor == null) return ; Location loc = StackFrameWrapper.location(ThreadReferenceWrapper.frame(threadReference, 0)); loc = MethodWrapper.locationOfCodeIndex(LocationWrapper.method(loc), LocationWrapper.codeIndex(loc) + 1); if (loc == null) return; BreakpointRequest br = EventRequestManagerWrapper.createBreakpointRequest( VirtualMachineWrapper.eventRequestManager(MirrorWrapper.virtualMachine(threadReference)), loc); BreakpointRequestWrapper.addThreadFilter(br, threadReference); submitMonitorEnteredRequest(br); } catch (IncompatibleThreadStateException itex) { Exceptions.printStackTrace(itex); } catch (InvalidStackFrameExceptionWrapper isex) { Exceptions.printStackTrace(isex); } finally { logger.fine("submitCheckForMonitorEntered(): resuming "+threadName); ThreadReferenceWrapper.resume(threadReference); } }
public boolean isAtBreakpoint() { /* * TO DO: This fails to take filters into account. */ try { StackFrame frame = frame(0); Location location = frame.location(); List<BreakpointRequest> requests = vm.eventRequestManager().breakpointRequests(); Iterator<BreakpointRequest> iter = requests.iterator(); while (iter.hasNext()) { BreakpointRequest request = iter.next(); if (location.equals(request.location())) { return true; } } return false; } catch (IndexOutOfBoundsException iobe) { return false; // no frames on stack => not at breakpoint } catch (IncompatibleThreadStateException itse) { // Per the javadoc, not suspended => return false return false; } }
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(); } }
@Override public List<Breakpoint> getAllBreakpoints() throws DebuggerException { List<BreakpointRequest> breakpointRequests; try { breakpointRequests = getEventManager().breakpointRequests(); } catch (DebuggerException e) { Throwable cause = e.getCause(); if (cause instanceof VMCannotBeModifiedException) { // If target VM in read-only state then list of break point always empty. return emptyList(); } throw e; } List<Breakpoint> breakPoints = new ArrayList<>(breakpointRequests.size()); for (BreakpointRequest breakpointRequest : breakpointRequests) { com.sun.jdi.Location location = breakpointRequest.location(); // Breakpoint always enabled at the moment. Managing states of breakpoint is not supported for // now. breakPoints.add( newDto(BreakpointDto.class) .withEnabled(true) .withLocation(asDto(new JdbLocation(location)))); } breakPoints.sort(BREAKPOINT_COMPARATOR); return breakPoints; }
@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()); }); } }
public boolean isAtBreakpoint() { /* * TO DO: This fails to take filters into account. */ try { StackFrame frame = frame(0); Location location = frame.location(); List requests = vm.eventRequestManager().breakpointRequests(); Iterator iter = requests.iterator(); while (iter.hasNext()) { BreakpointRequest request = (BreakpointRequest)iter.next(); if (location.equals(request.location())) { return true; } } return false; } catch (IndexOutOfBoundsException iobe) { return false; // no frames on stack => not at breakpoint } catch (IncompatibleThreadStateException itse) { // Per the javadoc, not suspended => return false return false; } }
@SuppressWarnings("unchecked") final String run(String[] args) { /* * TODO have not include deferred breakpoints yet */ List<BreakpointRequest> list = jdb.eventRequestManager.breakpointRequests(); if (list.size() == 0) { return "No breakpoints set."; } else { StringBuilder sb = new StringBuilder(); for (BreakpointRequest request : list) { sb.append(request.location() + "\n"); } return sb.toString(); } }
/** * 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; }
private void setFilters(BreakpointRequest br) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper { JPDAThread[] threadFilters = getBreakpoint().getThreadFilters(getDebugger()); if (threadFilters != null && threadFilters.length > 0) { for (JPDAThread t : threadFilters) { BreakpointRequestWrapper.addThreadFilter(br, ((JPDAThreadImpl) t).getThreadReference()); } } ObjectVariable[] varFilters = getBreakpoint().getInstanceFilters(getDebugger()); if (varFilters != null && varFilters.length > 0) { for (ObjectVariable v : varFilters) { BreakpointRequestWrapper.addInstanceFilter(br, (ObjectReference) ((JDIVariable) v).getJDIValue()); } } }
public BreakpointRequest createBreakpointRequest(Location location) { validateMirror(location); if (location.codeIndex() == -1) { throw new NativeMethodException("Cannot set breakpoints on native methods"); } return new BreakpointRequestImpl(location); }
@Override public void setHitCount(int hitCount) { this.hitCount = hitCount; Observable.fromIterable(this.requests()) .filter(request -> request instanceof BreakpointRequest) .subscribe(request -> { request.addCountFilter(hitCount); request.enable(); }); }
public void process(String accessControlClass, int lineNum) throws Exception { EventRequestManager erm = vm.eventRequestManager(); Optional<ReferenceType> classRef = getFirstClassReference(accessControlClass); if (!classRef.isPresent()) { throw new ClassNotFoundException(String.format("Class %s not found", accessControlClass)); } ReferenceType accRef = classRef.get(); Field contextField = accRef.fieldByName("context"); Location location = accRef.locationsOfLine(lineNum).get(0); BreakpointRequest br = erm.createBreakpointRequest(location); loop(br, contextField); }
private void loop(BreakpointRequest br, Field contextField) throws Exception { int lineNumber = br.location().lineNumber(); br.setSuspendPolicy(BreakpointRequest.SUSPEND_EVENT_THREAD); br.enable(); EventQueue evtQueue = vm.eventQueue(); boolean run = true; while (run) { EventSet evtSet = evtQueue.remove(); EventIterator evtIter = evtSet.eventIterator(); while (evtIter.hasNext()) { try { Event evt = evtIter.next(); EventRequest evtReq = evt.request(); if (evtReq instanceof BreakpointRequest && ((BreakpointRequest) evtReq).location().lineNumber() == lineNumber) { new BreakpointProcessor(missingPerms) .processBreakpoint(contextField, (BreakpointEvent) evt); // TODO: 12/20/17 Remove when full loop processing is restored // run = false; System.out.println(missingPerms); missingPerms.clear(); } } finally { evtSet.resume(); } } } // System.out.println(missingPerms); // printPerms(missingPerms); }
private void disableEventRequest() { List<BreakpointRequest> breakpoint = threadRef.virtualMachine().eventRequestManager().breakpointRequests(); for (int j = 0; j < breakpoint.size(); j++) { BreakpointRequest breakpointRequest = breakpoint.get(j); breakpointRequest.setEnabled(false); } }
private void enableEventRequest() { List<BreakpointRequest> breakpoint = threadRef.virtualMachine().eventRequestManager().breakpointRequests(); for (int j = 0; j < breakpoint.size(); j++) { BreakpointRequest breakpointRequest = breakpoint.get(j); breakpointRequest.setEnabled(true); } }
public static List<BreakpointRequest> wrapBreakpointRequests( F3VirtualMachine f3vm, List<BreakpointRequest> reqs) { if (reqs == null) { return null; } List<BreakpointRequest> result = new ArrayList<BreakpointRequest>(); for (BreakpointRequest req : reqs) { result.add(wrap(f3vm, req)); } return result; }
@Override @SuppressWarnings("unchecked") final String run(String[] args) throws Exception { String[] params = args[2].split(":"); List<ReferenceType> classes = jdb.debuggee.classesByName(params[0]); if (classes.isEmpty()) { if (!jdb.deferringLineBreakpoint.containsKey(params[0])) { jdb.deferringLineBreakpoint.put( params[0], new ArrayList<Integer>()); } jdb.deferringLineBreakpoint.get( params[0]).add(Integer.parseInt(params[1])); return String.format( "Deferring breakpoint %s\n" + "it will be set after the class is loaded.", args[2]); } else { List<Location> locations = classes.get(0). locationsOfLine(Integer.parseInt(params[1])); if (!locations.isEmpty()) { Location loc = locations.get(0); BreakpointRequest breakpointRequest = jdb.eventRequestManager. createBreakpointRequest(loc); breakpointRequest.setSuspendPolicy( EventRequest.SUSPEND_ALL); breakpointRequest.enable(); jdb.breakpointRegisterMap.put( loc.toString(), breakpointRequest); return String.format("Breakpoint set: " + loc); } else { return EMPTY_MSG; } } }
private void installHaltPoint(VirtualMachine vm) { List<ReferenceType> targetClasses = vm .classesByName(VMLocalTarget.class.getName()); ReferenceType classRef = targetClasses.get(0); Method meth = classRef.methodsByName("haltPoint").get(0); BreakpointRequest req = vm.eventRequestManager() .createBreakpointRequest(meth.location()); req.setSuspendPolicy(BreakpointRequest.SUSPEND_EVENT_THREAD); req.enable(); }
public List<BreakpointRequest> breakpointRequests() { return (List<BreakpointRequest>)unmodifiableRequestList(JDWP.EventKind.BREAKPOINT); }
private List<BreakpointRequest> createBreakpointRequests(ReferenceType refType, int lineNumber, int hitCount, boolean includeNestedTypes) { List<ReferenceType> refTypes = new ArrayList<>(); refTypes.add(refType); return createBreakpointRequests(refTypes, lineNumber, hitCount, includeNestedTypes); }
public F3BreakpointRequest(F3VirtualMachine f3vm, BreakpointRequest underlying) { super(f3vm, underlying); }
@Override protected BreakpointRequest underlying() { return (BreakpointRequest) super.underlying(); }
public List<BreakpointRequest> breakpointRequests() { return F3EventRequest.wrapBreakpointRequests(virtualMachine(), underlying().breakpointRequests()); }
public static F3EventRequest wrap(F3VirtualMachine f3vm, EventRequest req) { if (req == null) { return null; } if (req instanceof AccessWatchpointRequest) { return new F3AccessWatchpointRequest(f3vm, (AccessWatchpointRequest)req); } else if (req instanceof BreakpointRequest) { return new F3BreakpointRequest(f3vm, (BreakpointRequest)req); } else if (req instanceof ClassPrepareRequest) { return new F3ClassPrepareRequest(f3vm, (ClassPrepareRequest)req); } else if (req instanceof ClassUnloadRequest) { return new F3ClassUnloadRequest(f3vm, (ClassUnloadRequest)req); } else if (req instanceof ExceptionRequest) { return new F3ExceptionRequest(f3vm, (ExceptionRequest)req); } else if (req instanceof MethodEntryRequest) { return new F3MethodEntryRequest(f3vm, (MethodEntryRequest)req); } else if (req instanceof MethodExitRequest) { return new F3MethodExitRequest(f3vm, (MethodExitRequest)req); } else if (req instanceof ModificationWatchpointRequest) { return new F3ModificationWatchpointRequest(f3vm, (ModificationWatchpointRequest)req); } else if (req instanceof MonitorContendedEnterRequest) { return new F3MonitorContendedEnterRequest(f3vm, (MonitorContendedEnterRequest)req); } else if (req instanceof MonitorContendedEnteredRequest) { return new F3MonitorContendedEnteredRequest(f3vm, (MonitorContendedEnteredRequest)req); } else if (req instanceof MonitorWaitRequest) { return new F3MonitorWaitRequest(f3vm, (MonitorWaitRequest)req); } else if (req instanceof MonitorWaitedRequest) { return new F3MonitorWaitedRequest(f3vm, (MonitorWaitedRequest)req); } else if (req instanceof StepRequest) { return new F3StepRequest(f3vm, (StepRequest)req); } else if (req instanceof ThreadDeathRequest) { return new F3ThreadDeathRequest(f3vm, (ThreadDeathRequest)req); } else if (req instanceof ThreadStartRequest) { return new F3ThreadStartRequest(f3vm, (ThreadStartRequest)req); } else if (req instanceof VMDeathRequest) { return new F3VMDeathRequest(f3vm, (VMDeathRequest)req); } else if (req instanceof WatchpointRequest) { return new F3WatchpointRequest(f3vm, (WatchpointRequest)req); } else { return new F3EventRequest(f3vm, req); } }
public static F3BreakpointRequest wrap( F3VirtualMachine f3vm, BreakpointRequest req) { return (req == null)? null : new F3BreakpointRequest(f3vm, req); }