Search in sources :

Example 1 with Method

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

the class Evaluator method invokeMethod.

public ExpressionValue invokeMethod(Value value, String name, List<Value> arguments) {
    if (!(value instanceof ObjectReference)) {
        throw new ExpressionException("Value is not object. Cannot invoke method " + name);
    }
    ObjectReference object = (ObjectReference) value;
    ReferenceType type = object.referenceType();
    List<Method> methods = type.methodsByName(name);
    Method method = findMethod(methods, arguments);
    if (method == null) {
        throw new ExpressionException("No method with name " + name + " matched to specified arguments for " + type.name());
    }
    try {
        return new ReadOnlyValue(object.invokeMethod(thread, method, arguments, 0));
    } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException | InvocationException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
}
Also used : ClassNotLoadedException(com.sun.jdi.ClassNotLoadedException) ObjectReference(com.sun.jdi.ObjectReference) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) InvocationException(com.sun.jdi.InvocationException) Method(com.sun.jdi.Method) ReferenceType(com.sun.jdi.ReferenceType) InvalidTypeException(com.sun.jdi.InvalidTypeException)

Example 2 with Method

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

use of com.sun.jdi.Method in project jdk8u_jdk by JetBrains.

the class OomDebugTest method test1.

/*
     * Test case: Object reference as method parameter.
     */
// called via reflection
@SuppressWarnings("unused")
private void test1() throws Exception {
    System.out.println("DEBUG: ------------> Running test1");
    try {
        Field field = targetClass.fieldByName("fooCls");
        ClassType clsType = (ClassType) field.type();
        Method constructor = getConstructorForClass(clsType);
        for (int i = 0; i < 15; i++) {
            @SuppressWarnings({ "rawtypes", "unchecked" }) ObjectReference objRef = clsType.newInstance(mainThread, constructor, new ArrayList(0), ObjectReference.INVOKE_NONVIRTUAL);
            if (objRef.isCollected()) {
                System.out.println("DEBUG: Object got GC'ed before we can use it. NO-OP.");
                continue;
            }
            invoke("testMethod", "(LOomDebugTestTarget$FooCls;)V", objRef);
        }
    } catch (InvocationException e) {
        handleFailure(e);
    }
}
Also used : Field(com.sun.jdi.Field) ObjectReference(com.sun.jdi.ObjectReference) InvocationException(com.sun.jdi.InvocationException) ArrayList(java.util.ArrayList) Method(com.sun.jdi.Method) ClassType(com.sun.jdi.ClassType)

Example 4 with Method

use of com.sun.jdi.Method 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 5 with Method

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

the class ValueHint method getSelectedExpression.

private static Trinity<PsiElement, TextRange, Value> getSelectedExpression(final Project project, final Editor editor, final Point point, final ValueHintType type) {
    final Ref<PsiElement> selectedExpression = Ref.create(null);
    final Ref<TextRange> currentRange = Ref.create(null);
    final Ref<Value> preCalculatedValue = Ref.create(null);
    PsiDocumentManager.getInstance(project).commitAndRunReadAction(() -> {
        // Point -> offset
        final int offset = calculateOffset(editor, point);
        PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (psiFile == null || !psiFile.isValid()) {
            return;
        }
        int selectionStart = editor.getSelectionModel().getSelectionStart();
        int selectionEnd = editor.getSelectionModel().getSelectionEnd();
        if ((type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT) && (selectionStart <= offset && offset <= selectionEnd)) {
            PsiElement ctx = (selectionStart > 0) ? psiFile.findElementAt(selectionStart - 1) : psiFile.findElementAt(selectionStart);
            try {
                String text = editor.getSelectionModel().getSelectedText();
                if (text != null && ctx != null) {
                    final JVMElementFactory factory = JVMElementFactories.getFactory(ctx.getLanguage(), project);
                    if (factory == null) {
                        return;
                    }
                    selectedExpression.set(factory.createExpressionFromText(text, ctx));
                    currentRange.set(new TextRange(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd()));
                }
            } catch (IncorrectOperationException ignored) {
            }
        }
        if (currentRange.get() == null) {
            PsiElement elementAtCursor = psiFile.findElementAt(offset);
            if (elementAtCursor == null) {
                return;
            }
            Pair<PsiElement, TextRange> pair = findExpression(elementAtCursor, type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT);
            if (pair == null) {
                if (type == ValueHintType.MOUSE_OVER_HINT) {
                    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(project).getContext().getDebuggerSession();
                    if (debuggerSession != null && debuggerSession.isPaused()) {
                        final Pair<Method, Value> lastExecuted = debuggerSession.getProcess().getLastExecutedMethod();
                        if (lastExecuted != null) {
                            final Method method = lastExecuted.getFirst();
                            if (method != null) {
                                final Pair<PsiElement, TextRange> expressionPair = findExpression(elementAtCursor, true);
                                if (expressionPair != null && expressionPair.getFirst() instanceof PsiMethodCallExpression) {
                                    final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expressionPair.getFirst();
                                    final PsiMethod psiMethod = methodCallExpression.resolveMethod();
                                    if (psiMethod != null) {
                                        final JVMName jvmSignature = JVMNameUtil.getJVMSignature(psiMethod);
                                        try {
                                            if (method.name().equals(psiMethod.getName()) && method.signature().equals(jvmSignature.getName(debuggerSession.getProcess()))) {
                                                pair = expressionPair;
                                                preCalculatedValue.set(lastExecuted.getSecond());
                                            }
                                        } catch (EvaluateException ignored) {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (pair == null) {
                return;
            }
            selectedExpression.set(pair.getFirst());
            currentRange.set(pair.getSecond());
        }
    });
    return Trinity.create(selectedExpression.get(), currentRange.get(), preCalculatedValue.get());
}
Also used : JVMName(com.intellij.debugger.engine.JVMName) Method(com.sun.jdi.Method) AbstractValueHint(com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) PrimitiveValue(com.sun.jdi.PrimitiveValue) Value(com.sun.jdi.Value) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Aggregations

Method (com.sun.jdi.Method)19 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)5 Location (com.sun.jdi.Location)5 ReferenceType (com.sun.jdi.ReferenceType)5 ClassType (com.sun.jdi.ClassType)4 SourcePosition (com.intellij.debugger.SourcePosition)3 Nullable (org.jetbrains.annotations.Nullable)3 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)2 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)2 Project (com.intellij.openapi.project.Project)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)2 ClassNotLoadedException (com.sun.jdi.ClassNotLoadedException)2 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)2 InterfaceType (com.sun.jdi.InterfaceType)2 InvocationException (com.sun.jdi.InvocationException)2 ObjectReference (com.sun.jdi.ObjectReference)2 Value (com.sun.jdi.Value)2 BreakpointRequest (com.sun.jdi.request.BreakpointRequest)2 JVMName (com.intellij.debugger.engine.JVMName)1