Search in sources :

Example 1 with AbsentInformationException

use of com.sun.jdi.AbsentInformationException 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 AbsentInformationException

use of com.sun.jdi.AbsentInformationException 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 3 with AbsentInformationException

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

the class WildcardMethodBreakpoint method getEventMessage.

public String getEventMessage(LocatableEvent event) {
    final Location location = event.location();
    final String locationQName = DebuggerUtilsEx.getLocationMethodQName(location);
    String locationFileName;
    try {
        locationFileName = location.sourceName();
    } catch (AbsentInformationException e) {
        locationFileName = "";
    }
    final int locationLine = location.lineNumber();
    if (event instanceof MethodEntryEvent) {
        MethodEntryEvent entryEvent = (MethodEntryEvent) event;
        final Method method = entryEvent.method();
        return DebuggerBundle.message("status.method.entry.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
    }
    if (event instanceof MethodExitEvent) {
        MethodExitEvent exitEvent = (MethodExitEvent) event;
        final Method method = exitEvent.method();
        return DebuggerBundle.message("status.method.exit.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
    }
    return "";
}
Also used : AbsentInformationException(com.sun.jdi.AbsentInformationException) Method(com.sun.jdi.Method) MethodExitEvent(com.sun.jdi.event.MethodExitEvent) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Location(com.sun.jdi.Location) MethodEntryEvent(com.sun.jdi.event.MethodEntryEvent)

Example 4 with AbsentInformationException

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

the class DefaultSourcePositionProvider method getSourcePositionForField.

@Nullable
private static SourcePosition getSourcePositionForField(@NotNull FieldDescriptor descriptor, @NotNull Project project, @NotNull DebuggerContextImpl context, boolean nearest) {
    final ReferenceType type = descriptor.getField().declaringType();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final String fieldName = descriptor.getField().name();
    if (fieldName.startsWith(FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
        // this field actually mirrors a local variable in the outer class
        String varName = fieldName.substring(fieldName.lastIndexOf('$') + 1);
        PsiElement element = PositionUtil.getContextElement(context);
        if (element == null) {
            return null;
        }
        PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
        if (aClass == null) {
            return null;
        }
        PsiElement navigationElement = aClass.getNavigationElement();
        if (!(navigationElement instanceof PsiClass)) {
            return null;
        }
        aClass = (PsiClass) navigationElement;
        PsiVariable psiVariable = facade.getResolveHelper().resolveReferencedVariable(varName, aClass);
        if (psiVariable == null) {
            return null;
        }
        if (nearest) {
            return DebuggerContextUtil.findNearest(context, psiVariable, aClass.getContainingFile());
        }
        return SourcePosition.createFromElement(psiVariable);
    } else {
        final DebuggerSession session = context.getDebuggerSession();
        final GlobalSearchScope scope = session != null ? session.getSearchScope() : GlobalSearchScope.allScope(project);
        PsiClass aClass = facade.findClass(type.name().replace('$', '.'), scope);
        if (aClass == null) {
            // trying to search, assuming declaring class is an anonymous class
            final DebugProcessImpl debugProcess = context.getDebugProcess();
            if (debugProcess != null) {
                try {
                    final List<Location> locations = type.allLineLocations();
                    if (!locations.isEmpty()) {
                        // important: use the last location to be sure the position will be within the anonymous class
                        final Location lastLocation = locations.get(locations.size() - 1);
                        final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation);
                        aClass = JVMNameUtil.getClassAt(position);
                    }
                } catch (AbsentInformationException | ClassNotPreparedException ignored) {
                }
            }
        }
        if (aClass != null) {
            PsiField field = aClass.findFieldByName(fieldName, false);
            if (field == null)
                return null;
            if (nearest) {
                return DebuggerContextUtil.findNearest(context, field.getNavigationElement(), aClass.getContainingFile());
            }
            return SourcePosition.createFromElement(field);
        }
        return null;
    }
}
Also used : AbsentInformationException(com.sun.jdi.AbsentInformationException) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException) ReferenceType(com.sun.jdi.ReferenceType) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SourcePosition(com.intellij.debugger.SourcePosition) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with AbsentInformationException

use of com.sun.jdi.AbsentInformationException in project che by eclipse.

the class JdiStackFrameImpl method getLocalVariables.

@Override
public JdiLocalVariable[] getLocalVariables() throws DebuggerException {
    if (localVariables == null) {
        try {
            List<LocalVariable> targetVariables = stackFrame.visibleVariables();
            localVariables = new JdiLocalVariable[targetVariables.size()];
            int i = 0;
            for (LocalVariable var : targetVariables) {
                localVariables[i++] = new JdiLocalVariableImpl(stackFrame, var);
            }
        } catch (AbsentInformationException e) {
            throw new DebuggerAbsentInformationException(e.getMessage(), e);
        } catch (InvalidStackFrameException | NativeMethodException e) {
            throw new DebuggerException(e.getMessage(), e);
        }
    }
    return localVariables;
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) AbsentInformationException(com.sun.jdi.AbsentInformationException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) LocalVariable(com.sun.jdi.LocalVariable) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException) DebuggerAbsentInformationException(org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)

Aggregations

AbsentInformationException (com.sun.jdi.AbsentInformationException)12 ReferenceType (com.sun.jdi.ReferenceType)4 LocalVariable (com.sun.jdi.LocalVariable)3 Location (com.sun.jdi.Location)3 NativeMethodException (com.sun.jdi.NativeMethodException)3 StackFrame (com.sun.jdi.StackFrame)3 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)2 ClassNotPreparedException (com.sun.jdi.ClassNotPreparedException)2 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)2 InvalidStackFrameException (com.sun.jdi.InvalidStackFrameException)2 Method (com.sun.jdi.Method)2 Value (com.sun.jdi.Value)2 EventRequestManager (com.sun.jdi.request.EventRequestManager)2 DebuggerException (org.eclipse.che.api.debugger.server.exceptions.DebuggerException)2 DebuggerAbsentInformationException (org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException)2 Nullable (org.jetbrains.annotations.Nullable)2 Operation (org.netbeans.spi.debugger.jpda.EditorContext.Operation)2 SourcePosition (com.intellij.debugger.SourcePosition)1 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1