private void handleDebugEvent()

in com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/ConfigurationDoneRequestHandler.java [72:130]


    private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession, IDebugAdapterContext context) {
        Event event = debugEvent.event;
        boolean isImportantEvent = true;
        if (event instanceof VMStartEvent) {
            if (context.isVmStopOnEntry()) {
                DebugUtility.stopOnEntry(debugSession, context.getMainClass()).thenAccept(threadId -> {
                    context.getProtocolServer().sendEvent(new Events.StoppedEvent("entry", threadId));
                });
            }
        } else if (event instanceof VMDeathEvent) {
            vmHandler.disconnectVirtualMachine(event.virtualMachine());
            context.setVmTerminated();
            context.getProtocolServer().sendEvent(new Events.ExitedEvent(0));
        } else if (event instanceof VMDisconnectEvent) {
            vmHandler.disconnectVirtualMachine(event.virtualMachine());
            if (context.isAttached()) {
                context.setVmTerminated();
                context.getProtocolServer().sendEvent(new Events.TerminatedEvent());
                // Terminate eventHub thread.
                try {
                    debugSession.getEventHub().close();
                } catch (Exception e) {
                    // do nothing.
                }
            } else {
                // Skip it when the debugger is in launch mode, because LaunchRequestHandler will handle the event there.
            }
        } else if (event instanceof ThreadStartEvent) {
            ThreadReference startThread = ((ThreadStartEvent) event).thread();
            Events.ThreadEvent threadEvent = new Events.ThreadEvent("started", startThread.uniqueID());
            context.getProtocolServer().sendEvent(threadEvent);
        } else if (event instanceof ThreadDeathEvent) {
            ThreadReference deathThread = ((ThreadDeathEvent) event).thread();
            Events.ThreadEvent threadDeathEvent = new Events.ThreadEvent("exited", deathThread.uniqueID());
            context.getProtocolServer().sendEvent(threadDeathEvent);
        } else if (event instanceof BreakpointEvent) {
            // ignore since SetBreakpointsRequestHandler has already handled
        } else if (event instanceof ExceptionEvent) {
            ThreadReference thread = ((ExceptionEvent) event).thread();
            ThreadReference bpThread = ((ExceptionEvent) event).thread();
            IEvaluationProvider engine = context.getProvider(IEvaluationProvider.class);
            if (engine.isInEvaluation(bpThread)) {
                return;
            }

            JdiExceptionReference jdiException = new JdiExceptionReference(((ExceptionEvent) event).exception(),
                    ((ExceptionEvent) event).catchLocation() == null);
            context.getExceptionManager().setException(thread.uniqueID(), jdiException);
            context.getProtocolServer().sendEvent(new Events.StoppedEvent("exception", thread.uniqueID()));
            debugEvent.shouldResume = false;
        } else {
            isImportantEvent = false;
        }

        // record events of important types only, to get rid of noises.
        if (isImportantEvent) {
            UsageDataSession.recordEvent(event);
        }
    }