Search in sources :

Example 1 with EventRequestManager

use of com.sun.jdi.request.EventRequestManager in project che by eclipse.

the class JavaDebugger method addBreakpoint.

@Override
public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException {
    final String className = findFQN(breakpoint);
    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(new BreakpointImpl(breakpoint.getLocation(), true, breakpoint.getCondition())));
    LOG.debug("Add breakpoint: {}", location);
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) AbsentInformationException(com.sun.jdi.AbsentInformationException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) BreakpointRequest(com.sun.jdi.request.BreakpointRequest) EventRequest(com.sun.jdi.request.EventRequest) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException) EventRequestManager(com.sun.jdi.request.EventRequestManager) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) ReferenceType(com.sun.jdi.ReferenceType) BreakpointActivatedEventImpl(org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl) ExpressionParser(org.eclipse.che.plugin.jdb.server.expression.ExpressionParser) InvalidRequestStateException(com.sun.jdi.request.InvalidRequestStateException) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 2 with EventRequestManager

use of com.sun.jdi.request.EventRequestManager in project che by eclipse.

the class JavaDebugger method deleteBreakpoint.

@Override
public void deleteBreakpoint(Location location) throws DebuggerException {
    final String className = location.getTarget();
    final int lineNumber = location.getLineNumber();
    EventRequestManager requestManager = getEventManager();
    List<BreakpointRequest> snapshot = new ArrayList<>(requestManager.breakpointRequests());
    for (BreakpointRequest breakpointRequest : snapshot) {
        com.sun.jdi.Location jdiLocation = breakpointRequest.location();
        if (jdiLocation.declaringType().name().equals(className) && jdiLocation.lineNumber() == lineNumber) {
            requestManager.deleteEventRequest(breakpointRequest);
            LOG.debug("Delete breakpoint: {}", location);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) BreakpointRequest(com.sun.jdi.request.BreakpointRequest) EventRequestManager(com.sun.jdi.request.EventRequestManager) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint)

Example 3 with EventRequestManager

use of com.sun.jdi.request.EventRequestManager in project otertool by wuntee.

the class Testing method main.

/**
	 * @param args
	 * @throws IllegalConnectorArgumentsException 
	 * @throws IOException 
	 * @throws InterruptedException 
	 * @throws IncompatibleThreadStateException 
	 * @throws AbsentInformationException 
	 */
@SuppressWarnings("restriction")
public static void main(String[] args) throws IOException, IllegalConnectorArgumentsException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException {
    SocketAttachingConnector c = (SocketAttachingConnector) getConnector();
    Map<String, Connector.Argument> arguments = c.defaultArguments();
    Connector.Argument hostnameArgument = arguments.get("hostname");
    hostnameArgument.setValue("127.0.0.1");
    Connector.Argument portArgument = arguments.get("port");
    portArgument.setValue("8603");
    arguments.put("hostname", hostnameArgument);
    arguments.put("port", portArgument);
    VirtualMachine vm = c.attach(arguments);
    EventRequestManager mgr = vm.eventRequestManager();
    for (com.sun.jdi.ReferenceType rt : vm.allClasses()) {
        if (rt.name().toLowerCase().contains("wuntee")) {
            System.out.println(rt.name());
            for (Method m : rt.allMethods()) {
                System.out.println(" -" + m.name());
                if (m.name().contains("cache")) {
                    addBreakpointToMethod(m, mgr);
                }
            }
        }
    }
    /*		for(Method m : vm.classesByName("android.content.Intent").get(0).methodsByName("<init>")){
			System.out.println("Breakpoint: " + m.toString());
			
			Location location = m.location(); 
			BreakpointRequest bpr = mgr.createBreakpointRequest(location);
			bpr.enable();
		}*/
    //addIntentBreakpoints(vm);
    com.sun.jdi.event.EventQueue q = vm.eventQueue();
    while (true) {
        EventSet es = q.remove();
        Iterator<com.sun.jdi.event.Event> it = es.iterator();
        while (it.hasNext()) {
            com.sun.jdi.event.Event e = it.next();
            BreakpointEvent bpe = (BreakpointEvent) e;
            try {
                System.out.println("Method: " + bpe.location().method().toString());
                for (StackFrame sf : bpe.thread().frames()) {
                    System.out.println("Stackframe Method: " + sf.location().method().toString());
                    System.out.println("Arguments: ");
                    for (Value lv : sf.getArgumentValues()) {
                        System.out.println("\t--");
                        System.out.println("\t" + lv.toString());
                    }
                }
            } catch (Exception ex) {
                System.out.println("Error: ");
                ex.printStackTrace();
            }
            System.out.println();
            vm.resume();
        }
    }
}
Also used : SocketAttachingConnector(com.sun.tools.jdi.SocketAttachingConnector) Connector(com.sun.jdi.connect.Connector) EventSet(com.sun.jdi.event.EventSet) Method(com.sun.jdi.Method) SocketAttachingConnector(com.sun.tools.jdi.SocketAttachingConnector) EventRequestManager(com.sun.jdi.request.EventRequestManager) IOException(java.io.IOException) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) AbsentInformationException(com.sun.jdi.AbsentInformationException) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) StackFrame(com.sun.jdi.StackFrame) Value(com.sun.jdi.Value) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) VirtualMachine(com.sun.jdi.VirtualMachine)

Example 4 with EventRequestManager

use of com.sun.jdi.request.EventRequestManager in project intellij-community by JetBrains.

the class BreakpointManager method applyThreadFilter.

public void applyThreadFilter(@NotNull final DebugProcessImpl debugProcess, @Nullable ThreadReference newFilterThread) {
    final RequestManagerImpl requestManager = debugProcess.getRequestsManager();
    final ThreadReference oldFilterThread = requestManager.getFilterThread();
    if (Comparing.equal(newFilterThread, oldFilterThread)) {
        // the filter already added
        return;
    }
    requestManager.setFilterThread(newFilterThread);
    if (newFilterThread == null || oldFilterThread != null) {
        final List<Breakpoint> breakpoints = getBreakpoints();
        for (Breakpoint breakpoint : breakpoints) {
            if (LineBreakpoint.CATEGORY.equals(breakpoint.getCategory()) || MethodBreakpoint.CATEGORY.equals(breakpoint.getCategory())) {
                requestManager.deleteRequest(breakpoint);
                breakpoint.createRequest(debugProcess);
            }
        }
    } else {
        // important! need to add filter to _existing_ requests, otherwise Requestor->Request mapping will be lost
        // and debugger trees will not be restored to original state
        EventRequestManager eventRequestManager = requestManager.getVMRequestManager();
        if (eventRequestManager != null) {
            applyFilter(eventRequestManager.breakpointRequests(), request -> request.addThreadFilter(newFilterThread));
            applyFilter(eventRequestManager.methodEntryRequests(), request -> request.addThreadFilter(newFilterThread));
            applyFilter(eventRequestManager.methodExitRequests(), request -> request.addThreadFilter(newFilterThread));
        }
    }
}
Also used : ThreadReference(com.sun.jdi.ThreadReference) EventRequestManager(com.sun.jdi.request.EventRequestManager) RequestManagerImpl(com.intellij.debugger.engine.requests.RequestManagerImpl)

Example 5 with EventRequestManager

use of com.sun.jdi.request.EventRequestManager in project intellij-community by JetBrains.

the class DebugProcessImpl method doStep.

/**
   *
   * @param suspendContext
   * @param stepThread
   * @param size the step size. One of {@link StepRequest#STEP_LINE} or {@link StepRequest#STEP_MIN}
   * @param depth
   * @param hint may be null
   */
protected void doStep(final SuspendContextImpl suspendContext, final ThreadReferenceProxyImpl stepThread, int size, int depth, RequestHint hint) {
    if (stepThread == null) {
        return;
    }
    try {
        final ThreadReference stepThreadReference = stepThread.getThreadReference();
        if (LOG.isDebugEnabled()) {
            LOG.debug("DO_STEP: creating step request for " + stepThreadReference);
        }
        deleteStepRequests(stepThreadReference);
        EventRequestManager requestManager = getVirtualMachineProxy().eventRequestManager();
        StepRequest stepRequest = requestManager.createStepRequest(stepThreadReference, size, depth);
        if (!(hint != null && hint.isIgnoreFilters())) /*&& depth == StepRequest.STEP_INTO*/
        {
            checkPositionNotFiltered(stepThread, filters -> filters.forEach(f -> stepRequest.addClassExclusionFilter(f.getPattern())));
        }
        // suspend policy to match the suspend policy of the context:
        // if all threads were suspended, then during stepping all the threads must be suspended
        // if only event thread were suspended, then only this particular thread must be suspended during stepping
        stepRequest.setSuspendPolicy(suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD ? EventRequest.SUSPEND_EVENT_THREAD : EventRequest.SUSPEND_ALL);
        if (hint != null) {
            //noinspection HardCodedStringLiteral
            stepRequest.putProperty("hint", hint);
        }
        stepRequest.enable();
    } catch (ObjectCollectedException ignored) {
    }
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) PrimitiveRenderer(com.intellij.debugger.ui.tree.render.PrimitiveRenderer) MessageType(com.intellij.openapi.ui.MessageType) StackCapturingLineBreakpoint(com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint) HashMap(com.intellij.util.containers.HashMap) com.intellij.execution.process(com.intellij.execution.process) EventRequest(com.sun.jdi.request.EventRequest) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl) PsiManager(com.intellij.psi.PsiManager) Semaphore(com.intellij.util.concurrency.Semaphore) Disposer(com.intellij.openapi.util.Disposer) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) ClassRenderer(com.intellij.debugger.ui.tree.render.ClassRenderer) ExecutionResult(com.intellij.execution.ExecutionResult) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) XDebugSession(com.intellij.xdebugger.XDebugSession) MethodReturnValueWatcher(com.intellij.debugger.engine.requests.MethodReturnValueWatcher) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) Extensions(com.intellij.openapi.extensions.Extensions) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) com.intellij.debugger.engine.evaluation(com.intellij.debugger.engine.evaluation) NodeRenderer(com.intellij.debugger.ui.tree.render.NodeRenderer) BreakpointManager(com.intellij.debugger.ui.breakpoints.BreakpointManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) StepIntoBreakpoint(com.intellij.debugger.ui.breakpoints.StepIntoBreakpoint) com.intellij.debugger.impl(com.intellij.debugger.impl) ActionsBundle(com.intellij.idea.ActionsBundle) com.sun.jdi.connect(com.sun.jdi.connect) MagicConstant(org.intellij.lang.annotations.MagicConstant) Nullable(org.jetbrains.annotations.Nullable) ClassFilter(com.intellij.ui.classFilter.ClassFilter) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) XSourcePosition(com.intellij.xdebugger.XSourcePosition) ArrayRenderer(com.intellij.debugger.ui.tree.render.ArrayRenderer) StreamEx(one.util.streamex.StreamEx) com.intellij.debugger(com.intellij.debugger) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ExecutionUtil(com.intellij.execution.runners.ExecutionUtil) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) DebuggerClassFilterProvider(com.intellij.ui.classFilter.DebuggerClassFilterProvider) EventRequestManager(com.sun.jdi.request.EventRequestManager) NodeRendererSettings(com.intellij.debugger.settings.NodeRendererSettings) java.util(java.util) DebuggerAction(com.intellij.debugger.actions.DebuggerAction) ThreadReferenceProxyImpl(com.intellij.debugger.jdi.ThreadReferenceProxyImpl) ExecutionException(com.intellij.execution.ExecutionException) XDebuggerActions(com.intellij.xdebugger.impl.actions.XDebuggerActions) NonNls(org.jetbrains.annotations.NonNls) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) StepRequest(com.sun.jdi.request.StepRequest) ContainerUtil(com.intellij.util.containers.ContainerUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) DebuggerCommandImpl(com.intellij.debugger.engine.events.DebuggerCommandImpl) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl) StatusBarUtil(com.intellij.openapi.wm.impl.status.StatusBarUtil) ThreadReferenceProxy(com.intellij.debugger.engine.jdi.ThreadReferenceProxy) RequestManagerImpl(com.intellij.debugger.engine.requests.RequestManagerImpl) RunToCursorBreakpoint(com.intellij.debugger.ui.breakpoints.RunToCursorBreakpoint) ToolWindowId(com.intellij.openapi.wm.ToolWindowId) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) Patches(com.intellij.Patches) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Disposable(com.intellij.openapi.Disposable) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) CommonClassNames(com.intellij.psi.CommonClassNames) DebuggerSettings(com.intellij.debugger.settings.DebuggerSettings) DebuggerActions(com.intellij.debugger.actions.DebuggerActions) Pair(com.intellij.openapi.util.Pair) com.sun.jdi(com.sun.jdi) CantRunException(com.intellij.execution.CantRunException) StepRequest(com.sun.jdi.request.StepRequest) EventRequestManager(com.sun.jdi.request.EventRequestManager)

Aggregations

EventRequestManager (com.sun.jdi.request.EventRequestManager)11 BreakpointRequest (com.sun.jdi.request.BreakpointRequest)4 EventRequest (com.sun.jdi.request.EventRequest)3 MethodReturnValueWatcher (com.intellij.debugger.engine.requests.MethodReturnValueWatcher)2 RequestManagerImpl (com.intellij.debugger.engine.requests.RequestManagerImpl)2 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)2 StepRequest (com.sun.jdi.request.StepRequest)2 IOException (java.io.IOException)2 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)2 Patches (com.intellij.Patches)1 com.intellij.debugger (com.intellij.debugger)1 DebuggerAction (com.intellij.debugger.actions.DebuggerAction)1 DebuggerActions (com.intellij.debugger.actions.DebuggerActions)1 com.intellij.debugger.engine.evaluation (com.intellij.debugger.engine.evaluation)1 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)1 ThreadReferenceProxy (com.intellij.debugger.engine.jdi.ThreadReferenceProxy)1 com.intellij.debugger.impl (com.intellij.debugger.impl)1