Search in sources :

Example 1 with IncompatibleThreadStateException

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

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

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

the class InvokableTypeImpl method invokeMethod.

/**
     * Method invocation support.
     * Shared by ClassType and InterfaceType
     * @param threadIntf the thread in which to invoke.
     * @param methodIntf method the {@link Method} to invoke.
     * @param origArguments the list of {@link Value} arguments bound to the
     * invoked method. Values from the list are assigned to arguments
     * in the order they appear in the method signature.
     * @param options the integer bit flag options.
     * @return a {@link Value} mirror of the invoked method's return value.
     * @throws java.lang.IllegalArgumentException if the method is not
     * a member of this type, if the size of the argument list
     * does not match the number of declared arguments for the method, or
     * if the method is not static or is a static initializer.
     * @throws {@link InvalidTypeException} if any argument in the
     * argument list is not assignable to the corresponding method argument
     * type.
     * @throws ClassNotLoadedException if any argument type has not yet been loaded
     * through the appropriate class loader.
     * @throws IncompatibleThreadStateException if the specified thread has not
     * been suspended by an event.
     * @throws InvocationException if the method invocation resulted in
     * an exception in the target VM.
     * @throws InvalidTypeException If the arguments do not meet this requirement --
     *         Object arguments must be assignment compatible with the argument
     *         type.  This implies that the argument type must be
     *         loaded through the enclosing class's class loader.
     *         Primitive arguments must be either assignment compatible with the
     *         argument type or must be convertible to the argument type without loss
     *         of information. See JLS section 5.2 for more information on assignment
     *         compatibility.
     * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
     */
public final Value invokeMethod(ThreadReference threadIntf, Method methodIntf, List<? extends Value> origArguments, int options) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException {
    validateMirror(threadIntf);
    validateMirror(methodIntf);
    validateMirrorsOrNulls(origArguments);
    MethodImpl method = (MethodImpl) methodIntf;
    ThreadReferenceImpl thread = (ThreadReferenceImpl) threadIntf;
    validateMethodInvocation(method);
    List<? extends Value> arguments = method.validateAndPrepareArgumentsForInvoke(origArguments);
    ValueImpl[] args = arguments.toArray(new ValueImpl[0]);
    InvocationResult ret;
    try {
        PacketStream stream = sendInvokeCommand(thread, method, args, options);
        ret = waitForReply(stream);
    } catch (JDWPException exc) {
        if (exc.errorCode() == JDWP.Error.INVALID_THREAD) {
            throw new IncompatibleThreadStateException();
        } else {
            throw exc.toJDIException();
        }
    }
    /*
         * There is an implict VM-wide suspend at the conclusion
         * of a normal (non-single-threaded) method invoke
         */
    if ((options & ClassType.INVOKE_SINGLE_THREADED) == 0) {
        vm.notifySuspend();
    }
    if (ret.getException() != null) {
        throw new InvocationException(ret.getException());
    } else {
        return ret.getResult();
    }
}
Also used : IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) InvocationException(com.sun.jdi.InvocationException)

Example 4 with IncompatibleThreadStateException

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

the class Evaluator method getLocalVariable.

public ExpressionValue getLocalVariable(String text) {
    ExpressionValue value = null;
    try {
        StackFrame frame = thread.frame(0);
        LocalVariable var = frame.visibleVariableByName(text);
        if (var != null) {
            value = new LocalValue(thread, var);
        }
    } catch (IncompatibleThreadStateException | AbsentInformationException | InvalidStackFrameException | NativeMethodException e) {
        throw new ExpressionException(e.getMessage(), e);
    }
    LOG.debug("GET local variable {} {} ", text, value);
    return value;
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) IncompatibleThreadStateException(com.sun.jdi.IncompatibleThreadStateException) AbsentInformationException(com.sun.jdi.AbsentInformationException) StackFrame(com.sun.jdi.StackFrame) LocalVariable(com.sun.jdi.LocalVariable) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException)

Aggregations

IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)4 AbsentInformationException (com.sun.jdi.AbsentInformationException)2 InvocationException (com.sun.jdi.InvocationException)2 Method (com.sun.jdi.Method)2 StackFrame (com.sun.jdi.StackFrame)2 ClassNotLoadedException (com.sun.jdi.ClassNotLoadedException)1 InvalidStackFrameException (com.sun.jdi.InvalidStackFrameException)1 InvalidTypeException (com.sun.jdi.InvalidTypeException)1 LocalVariable (com.sun.jdi.LocalVariable)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 ObjectReference (com.sun.jdi.ObjectReference)1 ReferenceType (com.sun.jdi.ReferenceType)1 Value (com.sun.jdi.Value)1 VirtualMachine (com.sun.jdi.VirtualMachine)1 Connector (com.sun.jdi.connect.Connector)1 IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)1 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)1 EventSet (com.sun.jdi.event.EventSet)1 EventRequestManager (com.sun.jdi.request.EventRequestManager)1 SocketAttachingConnector (com.sun.tools.jdi.SocketAttachingConnector)1