/********** test core **********/ protected void runTests() throws Exception { /* * Run to String.<init> */ startUp("GetUninitializedStringValueTarg"); BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V"); /* * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet). */ StackFrame frame = bpe.thread().frame(0); StringReference sr = (StringReference)frame.thisObject(); if (!sr.value().equals("")) { throw new Exception("Unexpected value for the uninitialized String"); } /* * resume the target listening for events */ listenUntilVMDisconnect(); }
/********** test core **********/ protected void runTests() throws Exception { startToMain("LambdaBreakpointTestTarg"); // Put a breakpoint on each location in the order they should happen for (int line : LambdaBreakpointTestTarg.breakpointLines) { System.out.println("Running to line: " + line); BreakpointEvent be = resumeTo("LambdaBreakpointTestTarg", line); int stoppedAt = be.location().lineNumber(); System.out.println("Stopped at line: " + stoppedAt); if (stoppedAt != line) { throw new Exception("Stopped on the wrong line: " + stoppedAt + " != " + line); } } /* * resume the target listening for events */ listenUntilVMDisconnect(); }
/********** test core **********/ protected void runTests() throws Exception { startToMain("LambdaBreakpointTestTarg"); // Put a breakpoint on each location in the order they should happen for (int line : BKPT_LINES) { System.out.println("Running to line: " + line); BreakpointEvent be = resumeTo("LambdaBreakpointTestTarg", line); int stoppedAt = be.location().lineNumber(); System.out.println("Stopped at line: " + stoppedAt); if (stoppedAt != line) { throw new Exception("Stopped on the wrong line: " + stoppedAt + " != " + line); } } /* * resume the target listening for events */ listenUntilVMDisconnect(); }
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); } }
/********** test core **********/ protected void runTests() throws Exception { /* * Get to the top of main() * to determine targetClass and mainThread */ BreakpointEvent bpe = startToMain(targetClassName); targetClass = bpe.location().declaringType(); mainThread = bpe.thread(); int initialSize = mainThread.frames().size(); resumeTo(targetClassName, "foo3", "()V"); if (!mainThread.frame(0).location().method().name() .equals("foo3")) { failure("frame failed"); } // not F3 frames for (StackFrame fr : mainThread.frames()) { Assert.assertEquals(false, ((F3StackFrame)fr).isF3Frame()); } if (mainThread.frames().size() != (initialSize + 3)) { failure("frames size failed"); } if (mainThread.frames().size() != mainThread.frameCount()) { failure("frames size not equal to frameCount"); } exceptionTest(-1, 1); exceptionTest(mainThread.frameCount(), 1); exceptionTest(0, -1); exceptionTest(0, -2); exceptionTest(0, mainThread.frameCount()+1); nameTest(0, 0); nameTest(0, 1); nameTest(0, 4); nameTest(2, 2); nameTest(1, 1); /* * resume until end */ listenUntilVMDisconnect(); /* * deal with results of test * if anything has called failure("foo") testFailed will be true */ if (!testFailed) { println("FramesTest: passed"); } else { throw new Exception("FramesTest: failed"); } }
@Test(timeout=5000) public void testHello1() { try { compile("LocalVar.f3"); stop("in LocalVar.f3$run$"); f3run(); BreakpointEvent bkpt = resumeToBreakpoint(); // We hide F3 synthetic variables. F3StackFrame frame = (F3StackFrame) bkpt.thread().frame(0); LocalVariable var = frame.visibleVariableByName("_$UNUSED$_$ARGS$_"); Assert.assertNull(var); // underlying (java) frame object exposes this variable. StackFrame jframe = F3Wrapper.unwrap(frame); var = jframe.visibleVariableByName("_$UNUSED$_$ARGS$_"); Assert.assertNotNull(var); resumeToVMDeath(); quit(); } catch (Exception exp) { exp.printStackTrace(); Assert.fail(exp.getMessage()); } }
public void processBreakpointEvent(ObjectReference instance, BreakpointEvent event, Breakpoint breakpoint, JDIDebugTarget target) { if (!breakpoint.isTrackingActive()) { return; } long currTime = System.currentTimeMillis(); LineBreakpointHistory history = (LineBreakpointHistory)getHistory(instance, breakpoint, target); boolean notifyInstanceAdded = history.getAllValues().size() == 0; boolean eventModificationEvent = event instanceof ModificationWatchpointEvent; history.addValue(currTime, event.thread()); for (IBreakpointListener listener : listeners) { if (notifyInstanceAdded) { listener.notifyInstanceAdded(breakpoint, instance, target); } listener.notifyBreakpointHit(breakpoint, instance, target); } }
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 BreakpointEvent resumeTo(String clsName, String methodName, String methodSignature) { ReferenceType rt = findReferenceType(clsName); if (rt == null) { rt = resumeToPrepareOf(clsName).referenceType(); } Method method = findMethod(rt, methodName, methodSignature); if (method == null) { throw new IllegalArgumentException("Bad method name/signature"); } return resumeTo(method.location()); }
public BreakpointEvent resumeTo(String clsName, int lineNumber) throws AbsentInformationException { ReferenceType rt = findReferenceType(clsName); if (rt == null) { rt = resumeToPrepareOf(clsName).referenceType(); } return resumeTo(findLocation(rt, lineNumber)); }
public BreakpointEvent resumeToBreakpoint() { return (BreakpointEvent) resumeToEvent(new EventFilter() { public boolean match(Event evt) { return (evt instanceof BreakpointEvent); } }); }
public void breakpointEvent(BreakpointEvent evt) { synchronized (listeners) { for (EventNotifier en : listeners) { en.breakpointEvent(evt); } } }
protected void runTests() throws Exception { startToMain(); BreakpointEvent bpe = resumeTo("f3.lang.Builtins", "println", "(Ljava/lang/Object;)V"); mainThread = bpe.thread(); targetClass = bpe.location().declaringType(); // We are stopped under the on replace for sv2 List<StackFrame> frames = bpe.thread().frames(0,10); for (StackFrame frame: frames) { printUser(frame, 1); } bpe = resumeTo("f3.lang.Builtins", "println", "(Ljava/lang/Object;)V"); // stopped in the on replace for override1 printUser(bpe.thread().frame(2), 2); testFailed = !didTestPass(); /* * resume until end */ listenUntilVMDisconnect(); /* * deal with results of test * if anything has called failure("foo") testFailed will be true */ if (!testFailed) { writeActual(testClassName + ": passed"); } else { throw new Exception(testClassName + ": failed"); } }
protected void runTests() throws Exception { startToMain(); // go to "run" method of F3 class BreakpointEvent bpe = resumeTo(targetClassName, f3RunMethodName(), f3RunMethodSignature()); mainThread = bpe.thread(); if (!mainThread.frame(0).location().method().name().equals(f3RunMethodName())) { failure("frame failed"); } Assert.assertEquals(true, mainThread.frame(0) instanceof F3StackFrame); Assert.assertEquals(true, ((F3StackFrame)mainThread.frame(0)).isF3Frame()); /* * resume until end */ listenUntilVMDisconnect(); /* * deal with results of test */ if (!testFailed) { println("HelloTest: passed"); } else { throw new Exception("HelloTest: failed"); } }
protected void runTests() throws Exception { startToMain(); BreakpointEvent bpe = resumeTo("f3.lang.Builtins", "println", "(Ljava/lang/Object;)V"); mainThread = bpe.thread(); targetClass = bpe.location().declaringType(); // We are stopped under the on replace for sv2 List<StackFrame> frames = bpe.thread().frames(0,10); for (StackFrame frame: frames) { printTop(frame, 1); } bpe = resumeTo("f3.lang.Builtins", "println", "(Ljava/lang/Object;)V"); // stopped in the on replace for override1 printTop(bpe.thread().frame(2), 2); testFailed = !didTestPass(); /* * resume until end */ listenUntilVMDisconnect(); /* * deal with results of test * if anything has called failure("foo") testFailed will be true */ if (!testFailed) { writeActual(testClassName + ": passed"); } else { throw new Exception(testClassName + ": failed"); } }
@Override public boolean handleEvent(Event event, JDIDebugTarget target, boolean suspendVote, EventSet eventSet) { if (event instanceof BreakpointEvent) { try { ObjectReference instance = ((BreakpointEvent) event).thread().frame(0).thisObject(); wpMgr.processBreakpointEvent(instance, (BreakpointEvent)event, this, target); } catch (IncompatibleThreadStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return true; }
/** * Gets the observable object for breakpoint events. * @return the observable object for breakpoint events */ @Override public Observable<DebugEvent> breakpointEvents() { return this.events().filter(debugEvent -> debugEvent.event instanceof BreakpointEvent); }
void processBreakpoint(Field contextField, BreakpointEvent evt) throws Exception { ThreadReference threadRef = evt.thread(); checkConditions(threadRef, contextField); }
public F3BreakpointEvent(F3VirtualMachine f3vm, BreakpointEvent underlying) { super(f3vm, underlying); }
@Override protected BreakpointEvent underlying() { return (BreakpointEvent) super.underlying(); }
public BreakpointEvent resumeTo(Location loc) { final BreakpointRequest request = eventRequestManager().createBreakpointRequest(loc); request.addCountFilter(1); request.enable(); return (BreakpointEvent)resumeToEvent(request); }
public void breakpointEvent(BreakpointEvent e) { }
protected BreakpointEvent startToMain() { return startToMain(f3MainClassName()); }
protected void runTests() throws Exception { startToMain(); // break into function printSeq(arg: Integer[]) BreakpointEvent bpe = resumeTo(targetClassName, "printSeq", "(Lorg/f3/runtime/sequence/Sequence;)V"); mainThread = bpe.thread(); // get the top frame StackFrame frame = mainThread.frame(0); // get first argument which is Integer[] Value value = frame.getArgumentValues().get(0); Assert.assertEquals(true, value instanceof F3SequenceReference); F3SequenceReference seq = (F3SequenceReference) value; Assert.assertEquals(2, seq.size()); Assert.assertEquals(2, seq.length()); Assert.assertEquals(F3SequenceReference.Types.INT, seq.getElementType()); Value zerothElementAsVal = seq.getValue(0); Assert.assertEquals(true, zerothElementAsVal instanceof IntegerValue); Assert.assertEquals(1729, ((IntegerValue)zerothElementAsVal).intValue()); Value firstElementAsVal = seq.getValue(1); Assert.assertEquals(true, firstElementAsVal instanceof IntegerValue); Assert.assertEquals(9999, ((IntegerValue)firstElementAsVal).intValue()); // sequence element set seq.setValue(0, vm().mirrorOf(1111)); seq.setValue(1, vm().mirrorOf(2222)); Assert.assertEquals(1111, ((IntegerValue)seq.getValue(0)).intValue()); Assert.assertEquals(2222, ((IntegerValue)seq.getValue(1)).intValue()); // sequence setValues List<Value> newValues = new ArrayList<Value>(2); newValues.add(vm().mirrorOf(1234)); newValues.add(vm().mirrorOf(5678)); seq.setValues(newValues); Assert.assertEquals(1234, ((IntegerValue)seq.getValue(0)).intValue()); Assert.assertEquals(5678, ((IntegerValue)seq.getValue(1)).intValue()); // sequence getValues List<Value> values = seq.getValues(0, 2); Assert.assertEquals(1234, ((IntegerValue)values.get(0)).intValue()); Assert.assertEquals(5678, ((IntegerValue)values.get(1)).intValue()); /* * resume until end */ listenUntilVMDisconnect(); }
@Override public void visit(BreakpointEvent event) { }
public VisitableBreakpointEvent(BreakpointEvent event) { this.event = event; }
public VMRemoteTarget createJVM() throws IOException, InterruptedException, IncompatibleThreadStateException { Process process = startSecondJVM(VMLocalTarget.class); sleep(90); // connect VirtualMachine vm = new VMAcquirer().connect(debugPort); ClassPrepareRequest createClassPrepareRequest = vm .eventRequestManager().createClassPrepareRequest(); createClassPrepareRequest.addClassFilter(VMLocalTarget.class.getName()); createClassPrepareRequest.enable(); vm.resume(); List<ThreadReference> allThreads = vm.allThreads(); for (ThreadReference threadReference : allThreads) { System.out.println(threadReference+" isSuspended: "+threadReference.isSuspended()+" suspendCount: "+threadReference.suspendCount()); } // process events EventQueue eventQueue = vm.eventQueue(); while (true) { EventSet eventSet = eventQueue.remove(); for (Event event : eventSet) { if (event instanceof ClassPrepareEvent) { event.request().disable(); installHaltPoint(vm); } if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) { return null; } if (event instanceof BreakpointEvent) { event.request().disable(); ThreadReference thread = ((BreakpointEvent) event).thread(); return new VMRemoteTarget(process, vm, thread, debugPort); } } eventSet.resume(); } }