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 ); }
/** * Record JDI event. */ public static void recordEvent(Event event) { try { UsageDataSession currentSession = threadLocal.get(); if (currentSession != null) { Map<String, String> eventEntry = new HashMap<>(); eventEntry.put("timestamp", String.valueOf(System.currentTimeMillis())); eventEntry.put("event", event.toString()); synchronized (currentSession.eventList) { currentSession.eventList.add(JsonUtils.toJson(eventEntry)); } } } catch (Exception e) { logger.log(Level.SEVERE, String.format("Exception on recording event: %s.", e.toString()), e); } }
@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(); } }); }
private void singleStep(final Context ctx, int depth) { if (ctx.getState().isSuspend()) { ctx.registerStep(ctx.getState().thread, depth, 1, new EventCallback() { @Override public void handleEvent(Event event) { StepEvent se = (StepEvent) event; SuspendState state = ctx.getState(); state.isSuspend = true; state.thread = se.thread(); state.location = se.location(); util.Logger("single step complete"); } }); ctx.getState().resume(); } else { System.err.println("suspend thread before step"); } }
@NotNull public static List<Pair<Breakpoint, Event>> getEventDescriptors(SuspendContextImpl suspendContext) { DebuggerManagerThreadImpl.assertIsManagerThread(); if(suspendContext == null) { return Collections.emptyList(); } final EventSet events = suspendContext.getEventSet(); if(events == null) { return Collections.emptyList(); } final List<Pair<Breakpoint, Event>> eventDescriptors = new SmartList<Pair<Breakpoint, Event>>(); final RequestManagerImpl requestManager = suspendContext.getDebugProcess().getRequestsManager(); for (final Event event : events) { final Requestor requestor = requestManager.findRequestor(event.request()); if (requestor instanceof Breakpoint) { eventDescriptors.add(Pair.create((Breakpoint)requestor, event)); } } return eventDescriptors; }
public Iterator<Event> iterator() { final Iterator<Event> wrapped = underlying().iterator(); if (wrapped != null) { return new Iterator<Event>() { public boolean hasNext() { return wrapped.hasNext(); } public Event next() { return F3Event.wrap(virtualMachine(), wrapped.next()); } public void remove() { wrapped.remove(); } }; } else { return null; } }
public static F3Event wrap(F3VirtualMachine f3vm, Event evt) { if (evt == null) { return null; } if (evt instanceof AccessWatchpointEvent) { return new F3AccessWatchpointEvent(f3vm, (AccessWatchpointEvent)evt); } else if (evt instanceof BreakpointEvent) { return new F3BreakpointEvent(f3vm, (BreakpointEvent)evt); } else if (evt instanceof ClassPrepareEvent) { return new F3ClassPrepareEvent(f3vm, (ClassPrepareEvent)evt); } else if (evt instanceof ClassUnloadEvent) { return new F3ClassUnloadEvent(f3vm, (ClassUnloadEvent)evt); } else if (evt instanceof ExceptionEvent) { return new F3ExceptionEvent(f3vm, (ExceptionEvent)evt); } else if (evt instanceof MethodEntryEvent) { return new F3MethodEntryEvent(f3vm, (MethodEntryEvent)evt); } else if (evt instanceof MethodExitEvent) { return new F3MethodExitEvent(f3vm, (MethodExitEvent)evt); } else if (evt instanceof ModificationWatchpointEvent) { return new F3ModificationWatchpointEvent(f3vm, (ModificationWatchpointEvent)evt); } else if (evt instanceof MonitorContendedEnterEvent) { return new F3MonitorContendedEnterEvent(f3vm, (MonitorContendedEnterEvent)evt); } else if (evt instanceof MonitorContendedEnteredEvent) { return new F3MonitorContendedEnteredEvent(f3vm, (MonitorContendedEnteredEvent)evt); } else if (evt instanceof MonitorWaitEvent) { return new F3MonitorWaitEvent(f3vm, (MonitorWaitEvent)evt); } else if (evt instanceof MonitorWaitedEvent) { return new F3MonitorWaitedEvent(f3vm, (MonitorWaitedEvent)evt); } else if (evt instanceof StepEvent) { return new F3StepEvent(f3vm, (StepEvent)evt); } else if (evt instanceof ThreadDeathEvent) { return new F3ThreadDeathEvent(f3vm, (ThreadDeathEvent)evt); } else if (evt instanceof ThreadStartEvent) { return new F3ThreadStartEvent(f3vm, (ThreadStartEvent)evt); } else if (evt instanceof VMDeathEvent) { return new F3VMDeathEvent(f3vm, (VMDeathEvent)evt); } else if (evt instanceof VMDisconnectEvent) { return new F3VMDisconnectEvent(f3vm, (VMDisconnectEvent)evt); } else if (evt instanceof VMStartEvent) { return new F3VMStartEvent(f3vm, (VMStartEvent)evt); } else if (evt instanceof WatchpointEvent) { return new F3WatchpointEvent(f3vm, (WatchpointEvent)evt); } else if (evt instanceof LocatableEvent) { return new F3LocatableEvent(f3vm, (LocatableEvent)evt); } else { return new F3Event(f3vm, evt); } }
public ExceptionEvent resumeToException() { return (ExceptionEvent) resumeToEvent(new EventFilter() { public boolean match(Event evt) { return (evt instanceof ExceptionEvent); } }); }
public void receivedEvent(Event evt) { synchronized (listeners) { ListIterator<EventNotifier> itr = listeners.listIterator(); if (itr.hasNext()) { EventNotifier en = itr.next(); if (en.shouldRemoveListener()) { itr.remove(); } else { en.receivedEvent(evt); if (en.shouldRemoveListener()) { itr.remove(); } } } } }
private void start() throws Exception { eventQueue = debuggee.eventQueue(); while (true) { if (isExit == true) { break; } eventSet = eventQueue.remove(); EventIterator eventIterator = eventSet.eventIterator(); while (eventIterator.hasNext()) { Event event = (Event) eventIterator.next(); execute(event); } if (!isExit) { eventSet.resume(); } } }
public String getTooltipText() { DebugProcessImpl debugProcess = myContext.getDebugProcess(); if (debugProcess == null) { return null; } final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { //noinspection HardCodedStringLiteral buf.append("<html><body>"); for (Iterator<Pair<Breakpoint, Event>> iterator = myEventsOutOfLine.iterator(); iterator.hasNext();) { Pair<Breakpoint, Event> eventDescriptor = iterator.next(); buf.append(((DebugProcessEvents)debugProcess).getEventText(eventDescriptor)); if(iterator.hasNext()) { //noinspection HardCodedStringLiteral buf.append("<br>"); } } //noinspection HardCodedStringLiteral buf.append("</body></html>"); return buf.toString(); } finally { StringBuilderSpinAllocator.dispose(buf); } }
@NotNull public static List<Pair<Breakpoint, Event>> getEventDescriptors(SuspendContextImpl suspendContext) { DebuggerManagerThreadImpl.assertIsManagerThread(); if(suspendContext == null) { return Collections.emptyList(); } final EventSet events = suspendContext.getEventSet(); if(events == null) { return Collections.emptyList(); } final List<Pair<Breakpoint, Event>> eventDescriptors = new SmartList<Pair<Breakpoint, Event>>(); final RequestManagerImpl requestManager = suspendContext.getDebugProcess().getRequestsManager(); for (final Event event : events) { final Requestor requestor = requestManager.findRequestor(event.request()); if (requestor instanceof Breakpoint) { eventDescriptors.add(new Pair<Breakpoint, Event>((Breakpoint)requestor, event)); } } return eventDescriptors; }
@Override public boolean handleEvent(final Event event, final JDIDebugTarget target, final boolean suspendVote, final EventSet eventSet) { try { final int numFrames = getUnderlyingFrameCount(); if (numFrames <= getRemainingFrames()) { stepEnd(eventSet); return false; } // reset running state and keep going setRunning(true); deleteStepRequest(); createSecondaryStepRequest(); return true; } catch (final DebugException e) { logError(e); stepEnd(eventSet); return false; } }
private void eventLoop() throws InterruptedException { System.out.println("eventLoop started"); EventQueue eventQueue = vm.eventQueue(); boolean isRunning = true; while (isRunning) { EventSet eventSet = eventQueue.remove(); boolean mayResume = true; for (Event event : eventSet) { System.out.println(event); if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) { isRunning = false; } else if (event instanceof ExceptionEvent) { mayResume = false; } } if (mayResume) eventSet.resume(); } }
/** * Dispatch incoming events */ private void handleEvent(Event event) { if (event instanceof ExceptionEvent) { if (!enableProfiling) exceptionManager.exceptionEvent((ExceptionEvent)event); } else if (event instanceof MethodEntryEvent) { methodEntryEvent((MethodEntryEvent)event); } else if (event instanceof MethodExitEvent) { methodExitEvent((MethodExitEvent)event); } else if (event instanceof ThreadDeathEvent) { threadeath.threadDeathEvent((ThreadDeathEvent)event); } else if (event instanceof VMDeathEvent) { vmDeathEvent((VMDeathEvent)event); } else if (event instanceof VMDisconnectEvent) { connected = disconnect.vmDisconnectEvent((VMDisconnectEvent)event); } }
/*** * A VMDisconnectedException has happened while dealing with * another event. We need to flush the event queue, dealing only * with exit events (VMDeath, VMDisconnect) so that we terminate * correctly. */ synchronized void handleDisconnectedException() { EventQueue queue = vm.eventQueue(); while (connected) { try { EventSet eventSet = queue.remove(); EventIterator iter = eventSet.eventIterator(); while (iter.hasNext()) { Event event = iter.nextEvent(); if (event instanceof VMDeathEvent) { vmDeathManager.vmDeathEvent((VMDeathEvent)event,enableProfiling); } else if (event instanceof VMDisconnectEvent) { connected=disconnect.vmDisconnectEvent((VMDisconnectEvent)event); } } eventSet.resume(); // Resume the VM } catch (InterruptedException exc) { exc.printStackTrace(); } } }
boolean processCondition( Event event, String condition, ThreadReference threadReference, Value returnValue) { return processCondition(event, condition, threadReference, returnValue, null); }
public String toString() { String string = "event set, policy:" + suspendPolicy + ", count:" + this.size() + " = {"; boolean first = true; for (Event event : this) { if (!first) { string += ", "; } string += event.toString(); first = false; } string += "}"; return string; }
/** * Constructor for events. */ protected EventImpl(JDWP.Event.Composite.Events.EventsCommon evt, int requestID) { super(EventSetImpl.this.vm); this.eventCmd = evt.eventKind(); this.requestID = requestID; EventRequestManagerImpl ermi = EventSetImpl.this. vm.eventRequestManagerImpl(); this.request = ermi.request(eventCmd, requestID); }
WatchpointEventImpl(JDWP.Event.Composite.Events.EventsCommon evt, int requestID, ThreadReference thread, Location location, byte refTypeTag, long typeID, long fieldID, ObjectReference object) { super(evt, requestID, thread, location); this.refType = this.vm.referenceType(typeID, refTypeTag); this.fieldID = fieldID; this.object = object; }
private ThreadReference eventThread() { for (Event event : this) { if (event instanceof ThreadedEventImpl) { return ((ThreadedEventImpl)event).thread(); } } return null; }
public Event next() { try { Event nxt = get(cursor); ++cursor; return nxt; } catch(IndexOutOfBoundsException e) { throw new NoSuchElementException(); } }
@Override public void handleEvent(Event event) { StepEvent se = (StepEvent)event; // long index = se.location().codeIndex(); // System.out.println("index: " + index); if (listener != null) { listener.step(se); } if (se.thread().isSuspended()) se.thread().resume(); else { util.Logger("[Method Step]thread is not suspend"); } }
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); }
public Object[] toArray() { Object[] res = underlying().toArray(); if (res != null) { for (int i = 0; i < res.length; i++) { if (res[i] instanceof Event) { res[i] = F3Event.unwrap((Event)res[i]); } } } return res; }
public static Collection unwrapEvents(Collection events) { if (events == null) { return null; } ArrayList<Object> result = new ArrayList<Object>(); for (Object obj : events) { result.add((obj instanceof Event)? unwrap((Event)obj) : obj); } return result; }
public Event resumeToEvent(final EventRequest request) { return resumeToEvent(new EventFilter() { public boolean match(Event evt) { return request.equals(evt.request()); } }); }
public BreakpointEvent resumeToBreakpoint() { return (BreakpointEvent) resumeToEvent(new EventFilter() { public boolean match(Event evt) { return (evt instanceof BreakpointEvent); } }); }
public StepEvent resumeToStep() { return (StepEvent) resumeToEvent(new EventFilter() { public boolean match(Event evt) { return (evt instanceof StepEvent); } }); }
public WatchpointEvent resumeToWatchpoint() { return (WatchpointEvent) resumeToEvent(new EventFilter() { public boolean match(Event evt) { return (evt instanceof WatchpointEvent); } }); }
/** * Resumes the target VM and waits till VMDeath or VMDisconnect event occurs. */ public VMDeathEvent resumeToVMDeath() { return (VMDeathEvent) resumeToEvent(new EventFilter() { public boolean match(Event evt) { return (evt instanceof VMDeathEvent); } }); }
public Event resumeToAnyEvent() { return resumeToEvent(new EventFilter() { public boolean match(Event evt) { return true; } }); }
/** * Convenient method that compares the method name (extracted from event) with the given set of names. * @param event * @param methodName1 * @param methodName2 */ private void checkEntryExit(Event event, String methodName1, String methodName2) { if (event instanceof MethodEntryEvent) { System.out.println("Starting method = " + ((MethodEntryEvent)event).method().toString()); Assert.assertTrue(((MethodEntryEvent)event).method().toString().equals(methodName1) || ((MethodEntryEvent)event).method().toString().equals(methodName2)); }else if (event instanceof MethodExitEvent) { System.out.println("Exiting method = " + ((MethodExitEvent)event).method().toString()); Assert.assertTrue(((MethodExitEvent)event).method().toString().equals(methodName1) || ((MethodExitEvent)event).method().toString().equals(methodName2)); } }
/** * Trace entry and exit of method calls. */ //TODO: Please uncomment the below annotation when the TC is fixed. @Test(timeout=5000) public void testTrace() { try { //resetOutputs();//Uncomment this if you want to see the output on console compile("Method.f3"); stop("in Method:7"); stop("in Method:4"); stop("in Method:8"); f3run(); resumeToBreakpoint(); trace("go methods");//Trace all the method's entry and exit where(); list(); Event event = resumeToAnyEvent();//This is definitely start of methodOne() checkEntryExit(event, "Method.methodOne()", "f3.lang.Builtins.println(java.lang.Object)"); where(); list(); event = resumeToAnyEvent();//This is exit of either methodOne() or println() because the breakpoint is at end of methodOne() checkEntryExit(event, "Method.methodOne()", "f3.lang.Builtins.println(java.lang.Object)"); where(); list(); cont(); quit(); } catch (Exception exp) { exp.printStackTrace(); Assert.fail(exp.getMessage()); } }
/** * We call this method just before throwing an Exception and make sure it ExceptionEvent. */ private void checkExceptionEvent() { Event event = resumeToAnyEvent(); System.out.println("Exception request is " + event); Assert.assertTrue(event instanceof ExceptionEvent || event instanceof ThreadStartEvent); list(); }
/** * Transforms a JDI event to a visitable event. * * @param event JDI event * @return The corresponding visitable event */ public static Visitable transform(Event event) { // This assumes that an event implements only one interface Class<?> eventClass = event.getClass().getInterfaces()[0]; Class<? extends Visitable> visitableEventClass = eventMap .get(eventClass); try { Constructor<? extends Visitable> constructor = visitableEventClass .getConstructor(eventClass); return constructor.newInstance(event); } catch (Exception e) { throw new RuntimeException(e); } }
/** * A {@link VMDisconnectedException} has happened while dealing with another * event. We need to flush the event queue, dealing only with exit events ( * {@link VMDeatEvent} and {@link VMDisconnectEvent}) so that we terminate * correctly. */ private void handleDisconnectedException() { EventQueue queue = vm.eventQueue(); while (connected) { try { EventSet eventSet = queue.remove(); EventIterator eventIterator = eventSet.eventIterator(); while (eventIterator.hasNext()) { Event event = eventIterator.nextEvent(); if (event instanceof VMDeathEvent) { handleEvent(event); } else if (event instanceof VMDisconnectEvent) { handleEvent(event); connected = false; } } eventSet.resume(); } catch (InterruptedException ie) { vm.dispose(); break; } catch (VMDisconnectedException vmde) { break; } } }
/** * Handle the event by invoking the event visitor. * * @param event Event to handle */ private void handleEvent(Event event) { if (eventVisitor != null) { Visitable visitableEvent = EventTransformer.transform(event); visitableEvent.accept(eventVisitor); } }
public ActionGroup getPopupMenuActions() { DefaultActionGroup group = new DefaultActionGroup(); for (Pair<Breakpoint, Event> eventDescriptor : myEventsOutOfLine) { Breakpoint breakpoint = eventDescriptor.getFirst(); AnAction viewBreakpointsAction = new ViewBreakpointsAction(breakpoint.getDisplayName(), breakpoint); group.add(viewBreakpointsAction); } return group; }