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); } }
@Override protected boolean handleMethodEvent(LocatableEvent event, Method method, JDIThread thread, boolean suspendVote) { //System.out.println("Checking " + method.declaringType().name() + "." + method.name()); if (!method.isNative()) return true; //System.out.println("Really checking " + method.declaringType().name() + "." + method.name()); String name = method.declaringType().name(); if (!name.startsWith("java.") && !name.startsWith("sun.")) { //System.out.println("Killing " + method.declaringType().name() + "." + method.name()); try { thread.stop(exceptionObj); } catch (DebugException e) { throw new RuntimeException(e); } } return true; }
protected ObjectReference getThisObject(SuspendContextImpl context, LocatableEvent event) throws EvaluateException { ThreadReferenceProxyImpl thread = context.getThread(); if(thread != null) { StackFrameProxyImpl stackFrameProxy = thread.frame(0); if(stackFrameProxy != null) { return stackFrameProxy.thisObject(); } } return null; }
@Override protected String calculateEventClass(EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { String className = null; final ObjectReference thisObject = (ObjectReference)context.getThisObject(); if (thisObject != null) { className = thisObject.referenceType().name(); } else { final StackFrameProxyImpl frame = context.getFrameProxy(); if (frame != null) { className = frame.location().declaringType().name(); } } return className; }
public boolean matchesEvent(@NotNull final LocatableEvent event, final DebugProcessImpl process) throws EvaluateException { if (getMethodName() == null || mySignature == null) { return false; } final Method method = event.location().method(); return method != null && method.name().equals(getMethodName()) && method.signature().equals(mySignature.getName(process)); }
public boolean matchesEvent(@NotNull final LocatableEvent event, final DebugProcessImpl process) throws EvaluateException { if (myMethodName == null || mySignature == null) { return false; } final Method method = event.location().method(); return method != null && method.name().equals(myMethodName) && method.signature().equals(mySignature.getName(process)); }
IJiveEvent createVarAssignEvent(final LocatableEvent event, final StackFrame frame, final com.sun.jdi.Value newValue, final IContourMember varInstance, final String typeName) { final IThreadValue threadId = resolveThread(frame); final IValue value = resolveValue(frame.thread(), newValue, typeName); // defensively record the location when the event is provided if (event != null) { executionState().nextLine(threadId, resolveLine(event.location())); } final ILineValue line = executionState().currentLine(threadId); return eventFactory().createVarAssignEvent(threadId, line, value, varInstance); }
IJiveEvent createVarDeleteEvent(final LocatableEvent event, final StackFrame frame, final IContourMember varInstance) { final IThreadValue threadId = resolveThread(frame); // defensively record the location when the event is provided if (event != null) { executionState().nextLine(threadId, resolveLine(event.location())); } final ILineValue line = executionState().currentLine(threadId); return eventFactory().createVarDeleteEvent(threadId, line, varInstance); }
/** * Creates and dispatches a local variable {@code JiveVarDeleteEvent}. */ @Override public void dispatchVarDeleteEvent(final LocatableEvent event, final StackFrame frame, final IContourMember varInstance) { dispatchEvent(adapter().createVarDeleteEvent(event, frame, varInstance)); }
@Override public boolean handleEvent(Event event, JDIDebugTarget target, boolean suspendVote, EventSet eventSet) { try { //System.out.println("Reflection: " + event); ThreadReference thread = ((LocatableEvent)event).thread(); StackFrame stack = thread.frame(0); ObjectReference fieldValue = stack.thisObject(); ReferenceType fieldType = fieldValue.referenceType(); //String className = ((ObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).invokeMethod(thread, event.virtualMachine().classesByName("java.lang.Class").get(0).methodsByName("getName").get(0), new ArrayList<Value>(0), 0).toString(); // Calling methods in the child JVM seems to crash here. //String className = ((StringReference)((ObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).getValue(event.virtualMachine().classesByName("java.lang.Class").get(0).fieldByName("name"))).value(); // This works in JDK 7 but breaks in JDK 8 (because getting fields no longer calls SecurityManager.checkMemberAccess). String className = ((ClassObjectReference)fieldValue.getValue(fieldType.fieldByName("clazz"))).reflectedType().name(); String fieldName = ((StringReference)fieldValue.getValue(fieldType.fieldByName("name"))).value(); Field field = event.virtualMachine().classesByName(className).get(0).fieldByName(fieldName); List<Value> argValues = stack.getArgumentValues(); ObjectReference obj = (ObjectReference)argValues.get(0); if (!field.isStatic() && obj == null) return true; // The execution will crash. Value oldValue = field.isStatic() ? field.declaringType().getValue(field) : obj.getValue(field); if (argValues.size() == 2) { // We're setting the value of a field. Value newValue = argValues.get(1); if (newValue instanceof ObjectReference && EclipseUtils.isPrimitive(field.signature())) // Unbox primitive values. newValue = ((ObjectReference)newValue).getValue(((ReferenceType)newValue.type()).fieldByName("value")); recordEffect(FieldLVal.makeFieldLVal(obj, field), oldValue, newValue); } else if (oldValue instanceof ArrayReference) // We're reading the value of an array. backupArray(FieldLVal.makeFieldLVal(obj, field), oldValue); } catch (IncompatibleThreadStateException e) { throw new RuntimeException(e); } return true; }
@Override public boolean processLocatableEvent(final SuspendContextCommandImpl action, final LocatableEvent event) throws EventProcessingException { final SuspendContextImpl context = action.getSuspendContext(); if(!isValid()) { context.getDebugProcess().getRequestsManager().deleteRequest(this); return false; } final String[] title = {DebuggerBundle.message("title.error.evaluating.breakpoint.condition") }; try { final StackFrameProxyImpl frameProxy = context.getThread().frame(0); if (frameProxy == null) { // might be if the thread has been collected return false; } final EvaluationContextImpl evaluationContext = new EvaluationContextImpl( action.getSuspendContext(), frameProxy, getThisObject(context, event) ); if(!evaluateCondition(evaluationContext, event)) { return false; } title[0] = DebuggerBundle.message("title.error.evaluating.breakpoint.action"); runAction(evaluationContext, event); } catch (final EvaluateException ex) { if(ApplicationManager.getApplication().isUnitTestMode()) { System.out.println(ex.getMessage()); return false; } throw new EventProcessingException(title[0], ex.getMessage(), ex); } return true; }
private void runAction(final EvaluationContextImpl context, LocatableEvent event) { final DebugProcessImpl debugProcess = context.getDebugProcess(); if (isLogEnabled() || isLogExpressionEnabled()) { final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { if (myXBreakpoint.isLogMessage()) { buf.append(getEventMessage(event)); buf.append("\n"); } if (isLogExpressionEnabled()) { if(!debugProcess.isAttached()) { return; } final TextWithImports expressionToEvaluate = getLogMessage(); try { ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(getProject(), new EvaluatingComputable<ExpressionEvaluator>() { @Override public ExpressionEvaluator compute() throws EvaluateException { return EvaluatorBuilderImpl.build(expressionToEvaluate, ContextUtil.getContextElement(context), ContextUtil.getSourcePosition(context)); } }); final Value eval = evaluator.evaluate(context); final String result = eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval); buf.append(result); } catch (EvaluateException e) { buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression")); buf.append(" \""); buf.append(expressionToEvaluate); buf.append("\""); buf.append(" : "); buf.append(e.getMessage()); } buf.append("\n"); } if (buf.length() > 0) { debugProcess.printToConsole(buf.toString()); } } finally { StringBuilderSpinAllocator.dispose(buf); } } if (isRemoveAfterHit()) { handleTemporaryBreakpointHit(debugProcess); } }
protected String calculateEventClass(EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { return event.location().declaringType().name(); }
public boolean evaluateCondition(@NotNull EvaluationContextImpl context, @NotNull LocatableEvent event) throws EvaluateException { if (!matchesEvent(event, context.getDebugProcess())) { return false; } return super.evaluateCondition(context, event); }
@Override public boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event) throws EventProcessingException { return false; }
protected ObjectReference getThisObject(SuspendContextImpl context, LocatableEvent event) throws EvaluateException { if(event instanceof ExceptionEvent) { return ((ExceptionEvent) event).exception(); } return super.getThisObject(context, event); //To change body of overriden methods use Options | File Templates. }
public String getEventMessage(LocatableEvent event) { String exceptionName = (getQualifiedName() != null)? getQualifiedName() : CommonClassNames.JAVA_LANG_THROWABLE; String threadName = null; if (event instanceof ExceptionEvent) { ExceptionEvent exceptionEvent = (ExceptionEvent)event; try { exceptionName = exceptionEvent.exception().type().name(); threadName = exceptionEvent.thread().name(); } catch (Exception ignore) { } } final Location location = event.location(); final String locationQName = DebuggerUtilsEx.getLocationMethodQName(location); String locationFileName; try { locationFileName = location.sourceName(); } catch (AbsentInformationException e) { locationFileName = ""; } final int locationLine = Math.max(0, location.lineNumber()); if (threadName != null) { return DebuggerBundle.message( "exception.breakpoint.console.message.with.thread.info", exceptionName, threadName, locationQName, locationFileName, locationLine ); } else { return DebuggerBundle.message( "exception.breakpoint.console.message", exceptionName, locationQName, locationFileName, locationLine ); } }
public boolean evaluateCondition(EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { return matchesEvent(event) && super.evaluateCondition(context, event); }
public boolean matchesEvent(final LocatableEvent event){ final Method method = event.location().method(); return method != null && getMethodName().equals(method.name()); }
public F3LocatableEvent(F3VirtualMachine f3vm, LocatableEvent underlying) { super(f3vm, underlying); }
@Override protected LocatableEvent underlying() { return (LocatableEvent) super.underlying(); }
@Override public void visit(LocatableEvent event) { }
public VisitableLocatableEvent(LocatableEvent event) { this.event = event; }
private void runAction(final EvaluationContextImpl context, LocatableEvent event) { final DebugProcessImpl debugProcess = context.getDebugProcess(); if (LOG_ENABLED || LOG_EXPRESSION_ENABLED) { final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { if (LOG_ENABLED) { buf.append(getEventMessage(event)); buf.append("\n"); } final TextWithImports expressionToEvaluate = getLogMessage(); if (LOG_EXPRESSION_ENABLED && expressionToEvaluate != null && !"".equals(expressionToEvaluate.getText())) { if(!debugProcess.isAttached()) { return; } try { ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(getProject(), new EvaluatingComputable<ExpressionEvaluator>() { @Override public ExpressionEvaluator compute() throws EvaluateException { return EvaluatorBuilderImpl.build(expressionToEvaluate, ContextUtil.getContextElement(context), ContextUtil.getSourcePosition(context)); } }); final Value eval = evaluator.evaluate(context); final String result = eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval); buf.append(result); } catch (EvaluateException e) { buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression")); buf.append(" \""); buf.append(expressionToEvaluate); buf.append("\""); buf.append(" : "); buf.append(e.getMessage()); } buf.append("\n"); } if (buf.length() > 0) { debugProcess.printToConsole(buf.toString()); } } finally { StringBuilderSpinAllocator.dispose(buf); } } if (REMOVE_AFTER_HIT) { handleTemporaryBreakpointHit(debugProcess); } }
public boolean matchesEvent(final LocatableEvent event){ final Method method = event.location().method(); return method != null && myMethodName.equals(method.name()); }
private void showExecutionPoint(final SourcePosition position, List<Pair<Breakpoint, Event>> events) { if (myExecutionPointDescription != null) { myExecutionPointDescription.remove(); } int lineIndex = position.getLine(); Editor editor = getEditor(position); if(editor == null) { return; } myExecutionPointDescription = SelectionDescription.createExecutionPoint(editor, lineIndex); myExecutionPointDescription.select(); RangeHighlighter highlighter = myExecutionPointDescription.getHighlighter(); if(highlighter != null) { final List<Pair<Breakpoint, Event>> eventsOutOfLine = new ArrayList<Pair<Breakpoint, Event>>(); for (final Pair<Breakpoint, Event> eventDescriptor : events) { final Breakpoint breakpoint = eventDescriptor.getFirst(); // filter breakpoints that do not match the event if (breakpoint instanceof MethodBreakpoint) { try { if (!((MethodBreakpoint)breakpoint).matchesEvent((LocatableEvent)eventDescriptor.getSecond(), myContext.getDebugProcess())) { continue; } } catch (EvaluateException ignored) { } } else if (breakpoint instanceof WildcardMethodBreakpoint) { if (!((WildcardMethodBreakpoint)breakpoint).matchesEvent((LocatableEvent)eventDescriptor.getSecond())) { continue; } } if (breakpoint instanceof BreakpointWithHighlighter) { if (((BreakpointWithHighlighter)breakpoint).isVisible() && breakpoint.isValid()) { breakpoint.reload(); final SourcePosition sourcePosition = ((BreakpointWithHighlighter)breakpoint).getSourcePosition(); if (sourcePosition == null || sourcePosition.getLine() != lineIndex) { eventsOutOfLine.add(eventDescriptor); } } } else { eventsOutOfLine.add(eventDescriptor); } } if(!eventsOutOfLine.isEmpty()) { highlighter.setGutterIconRenderer(new MyGutterIconRenderer(eventsOutOfLine)); } } }
public void dispatchVarAssignEvent(LocatableEvent event, StackFrame frame, Value val, IContourMember varInstance, String typeName);
private IThreadValue resolveThread(final LocatableEvent object) { return valueFactory().createThread(object.thread().uniqueID(), object.thread().name()); }
@Override public void dispatchVarAssignEvent(final LocatableEvent event, final StackFrame frame, final Value val, final IContourMember varInstance, final String typeName) { dispatchEvent(adapter().createVarAssignEvent(event, frame, val, varInstance, typeName)); }
/** * @returns true if request was hit by the event, false otherwise */ boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event) throws EventProcessingException;
/** * returns UI representation */ public abstract String getEventMessage(LocatableEvent event);
/** * Visit a {@code LocatableEvent}. * * @param event Event to visit */ void visit(LocatableEvent event);
/** * @returns true if requesto was hit by the event, false otherwise */ boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event) throws EventProcessingException;