private boolean processBreakPointEvent(com.sun.jdi.event.BreakpointEvent event) throws DebuggerException { setCurrentThread(event.thread()); boolean hitBreakpoint; ExpressionParser parser = (ExpressionParser) event .request() .getProperty("org.eclipse.che.ide.java.debug.condition.expression.parser"); if (parser != null) { com.sun.jdi.Value result = evaluate(parser); hitBreakpoint = result instanceof com.sun.jdi.BooleanValue && ((com.sun.jdi.BooleanValue) result).value(); } else { // If there is no expression. hitBreakpoint = true; } if (hitBreakpoint) { com.sun.jdi.Location jdiLocation = event.location(); Location location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber()); debuggerCallback.onEvent(new SuspendEventImpl(location)); } // Left target JVM in suspended state if result of evaluation of expression is boolean value and // true // or if condition expression is not set. return !hitBreakpoint; }
private boolean processStepEvent(com.sun.jdi.event.StepEvent event) throws DebuggerException { setCurrentThread(event.thread()); com.sun.jdi.Location jdiLocation = event.location(); Location location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber()); debuggerCallback.onEvent(new SuspendEventImpl(location)); return false; }
@Override public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException { final String className = breakpoint.getLocation().getTarget(); final int lineNumber = breakpoint.getLocation().getLineNumber(); List<ReferenceType> classes = vm.classesByName(className); // it may mean that class doesn't loaded by a target JVM yet if (classes.isEmpty()) { deferBreakpoint(breakpoint); throw new DebuggerException("Class not loaded"); } ReferenceType clazz = classes.get(0); List<com.sun.jdi.Location> locations; try { locations = clazz.locationsOfLine(lineNumber); } catch (AbsentInformationException | ClassNotPreparedException e) { throw new DebuggerException(e.getMessage(), e); } if (locations.isEmpty()) { throw new DebuggerException("Line " + lineNumber + " not found in class " + className); } com.sun.jdi.Location location = locations.get(0); if (location.method() == null) { // Line is out of method. throw new DebuggerException("Invalid line " + lineNumber + " in class " + className); } // Ignore new breakpoint if already have breakpoint at the same location. EventRequestManager requestManager = getEventManager(); for (BreakpointRequest breakpointRequest : requestManager.breakpointRequests()) { if (location.equals(breakpointRequest.location())) { LOG.debug("Breakpoint at {} already set", location); return; } } try { EventRequest breakPointRequest = requestManager.createBreakpointRequest(location); breakPointRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL); String expression = breakpoint.getCondition(); if (!(expression == null || expression.isEmpty())) { ExpressionParser parser = ExpressionParser.newInstance(expression); breakPointRequest.putProperty( "org.eclipse.che.ide.java.debug.condition.expression.parser", parser); } breakPointRequest.setEnabled(true); } catch (NativeMethodException | IllegalThreadStateException | InvalidRequestStateException e) { throw new DebuggerException(e.getMessage(), e); } debuggerCallback.onEvent(new BreakpointActivatedEventImpl(breakpoint)); LOG.debug("Add breakpoint: {}", location); }
private boolean processDisconnectEvent() { debuggerCallback.onEvent(new DisconnectEventImpl()); eventsCollector.stop(); return true; }