public static IDebugSession getDebugSession(String projectName, String mainClass) throws Exception { setupProject(projectName); return debugSessionMap.computeIfAbsent(projectName, (name) -> { String projectRoot = new File(rootPath, name).getAbsolutePath(); try { final IDebugSession debugSession = DebugUtility.launch(Bootstrap.virtualMachineManager(), mainClass, "", "", null, new File(projectRoot, "bin").getAbsolutePath(), null, null); debugSession.getEventHub().events().subscribe(debugEvent -> { if (debugEvent.event instanceof VMDisconnectEvent) { try { debugSession.getEventHub().close(); } catch (Exception e) { // do nothing. } } }); return debugSession; } catch (Exception ex) { 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); } }
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(); } } }
/** * Gets the observable object for vm events. * @return the observable object for vm events */ @Override public Observable<DebugEvent> vmEvents() { return this.events().filter(debugEvent -> debugEvent.event instanceof VMStartEvent || debugEvent.event instanceof VMDisconnectEvent || debugEvent.event instanceof VMDeathEvent); }
public void vmDisconnectEvent(VMDisconnectEvent evt) { synchronized (listeners) { for (EventNotifier en : listeners) { en.vmDisconnectEvent(evt); } } }
/** * 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; } } }
@Override public synchronized void jdiVMDisconnect(final VMDisconnectEvent event) { if (!override && !owner.isStarted()) { return; } systemExit(); }
@Override public void jdiVMDisconnect(final VMDisconnectEvent event) { // this.currentEvent = null; this.currentThread = null; // this.currentEvent = null; this.currentThread = null; }
@Override public void handleVMDisconnect(final VMDisconnectEvent event) { if (isActive()) { // this waits for all pending thread deaths to be processed jdiHandler().jdiVMDisconnect(event); } super.handleVMDisconnect(event); }
public static void main(String[] args) throws IOException, InterruptedException { //VirtualMachine vm = launchTarget(sb.toString()); VirtualMachine vm = launchTarget(CLASS_NAME); System.out.println("Vm launched"); // process events EventQueue eventQueue = vm.eventQueue(); // resume the vm Process process = vm.process(); // Copy target's output and error to our output and error. Thread outThread = new StreamRedirectThread("out reader", process.getInputStream()); Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream()); errThread.start(); outThread.start(); boolean connected = true; int watched = 0; while (connected) { EventSet eventSet = eventQueue.remove(); for (Event event : eventSet) { System.out.println("FieldMonitor-main receives: "+event); if (event instanceof VMStartEvent) { addClassWatch(vm); } else if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) { // exit connected = false; } else if (event instanceof ClassPrepareEvent) { // watch field on loaded class System.out.println("ClassPrepareEvent"); ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event; ReferenceType refType = classPrepEvent .referenceType(); addFieldWatch(vm, refType); } else if (event instanceof ModificationWatchpointEvent) { watched++; System.out.println("sleep for 500 ms"); Thread.sleep(500); ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event; System.out.println("old=" + modEvent.valueCurrent()); System.out.println("new=" + modEvent.valueToBe()); } } System.out.println("resume..."); eventSet.resume(); } // Shutdown begins when event thread terminates try { errThread.join(); // Make sure output is forwarded outThread.join(); } catch (InterruptedException exc) { // we don't interrupt } if (watched != 11) { // init + 10 modifications in TestPostFieldModification class throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched); } }
public F3VMDisconnectEvent(F3VirtualMachine f3vm, VMDisconnectEvent underlying) { super(f3vm, underlying); }
@Override protected VMDisconnectEvent underlying() { return (VMDisconnectEvent) super.underlying(); }
public void vmDisconnectEvent(VMDisconnectEvent e) { }
public VisitableVMDisconnectEvent(VMDisconnectEvent event) { this.event = event; }
@Override public void visit(VMDisconnectEvent 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(); } }
public boolean vmDisconnectEvent(VMDisconnectEvent event) { return false; }
/** * Visit a {@code VMDisconnectEvent}. * * @param event Event to visit */ void visit(VMDisconnectEvent event);
/** * Notification of disconnection from target VM. */ void jdiVMDisconnect(VMDisconnectEvent event);