Search in sources :

Example 1 with StackFrame

use of com.sun.jdi.StackFrame 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 2 with StackFrame

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

the class LambdaStepTest method runTests.

/********** test core **********/
protected void runTests() throws Exception {
    // ## Normal instance method
    BreakpointEvent bpe = startTo("LambdaStepTestTarg", "instanceTest", "()V");
    ThreadReference thread = bpe.thread();
    // step over allocation
    StepEvent se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // step into test();
    se = stepIntoLine(thread);
    System.out.println(se.thread().frame(0));
    // step over variable initialization
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // get value of variable "from"
    StackFrame frame = se.thread().frame(0);
    LocalVariable lv = frame.visibleVariableByName("from");
    System.out.println(lv);
    StringReference sr = (StringReference) frame.getValue(lv);
    if (!sr.value().equals("test")) {
        throw new Exception("Unexpected variable value in instanceTest: " + sr.value());
    }
    // ## Lambda method
    bpe = resumeTo("LambdaStepTestTarg", "lambdaTest", "()V");
    thread = bpe.thread();
    // step over allocation
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // step into run() of the lambda
    se = stepIntoLine(thread);
    System.out.println(se.thread().frame(0));
    // step over variable initialization
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // get value of variable "from"
    frame = se.thread().frame(0);
    lv = frame.visibleVariableByName("from");
    System.out.println(lv);
    sr = (StringReference) frame.getValue(lv);
    if (!sr.value().equals("lambda")) {
        throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
    }
    // ## Default method
    bpe = resumeTo("LambdaStepTestTarg", "defaultTest", "()V");
    thread = bpe.thread();
    // step over allocation
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // step into defaultMethod()
    se = stepIntoLine(thread);
    System.out.println(se.thread().frame(0));
    // step over variable initialization
    se = stepOverLine(thread);
    System.out.println(se.thread().frame(0));
    // get value of variable "from"
    frame = se.thread().frame(0);
    lv = frame.visibleVariableByName("from");
    System.out.println(lv);
    sr = (StringReference) frame.getValue(lv);
    if (!sr.value().equals("default")) {
        throw new Exception("Unexpected variable value in lambdaTest: " + sr.value());
    }
    /*
         * resume the target listening for events
         */
    listenUntilVMDisconnect();
}
Also used : BreakpointEvent(com.sun.jdi.event.BreakpointEvent) StepEvent(com.sun.jdi.event.StepEvent) StackFrame(com.sun.jdi.StackFrame) LocalVariable(com.sun.jdi.LocalVariable) ThreadReference(com.sun.jdi.ThreadReference) StringReference(com.sun.jdi.StringReference)

Example 3 with StackFrame

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

the class GetUninitializedStringValue method runTests.

/********** test core **********/
protected void runTests() throws Exception {
    /*
         * Run to String.<init>
         */
    startUp("GetUninitializedStringValueTarg");
    BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");
    /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
    StackFrame frame = bpe.thread().frame(0);
    StringReference sr = (StringReference) frame.thisObject();
    if (!sr.value().equals("")) {
        throw new Exception("Unexpected value for the uninitialized String");
    }
    /*
         * resume the target listening for events
         */
    listenUntilVMDisconnect();
}
Also used : BreakpointEvent(com.sun.jdi.event.BreakpointEvent) StackFrame(com.sun.jdi.StackFrame) StringReference(com.sun.jdi.StringReference)

Example 4 with StackFrame

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

Example 5 with StackFrame

use of com.sun.jdi.StackFrame in project otertool by wuntee.

the class Testing method printBreakpointData.

public static void printBreakpointData(BreakpointEvent e) throws IncompatibleThreadStateException, AbsentInformationException {
    System.out.println(e.location());
    System.out.println("Line number: " + e.location().lineNumber());
    System.out.println("Code index: " + e.location().codeIndex());
    try {
        System.out.println("SourceName: " + e.location().sourceName());
    } catch (AbsentInformationException e1) {
        System.out.println("SourceName: UNAVAILABLE");
    }
    System.out.println("Declaration type: " + e.location().declaringType());
    System.out.println("Method: " + e.location().method());
    System.out.println("Stack frames:");
    for (StackFrame sf : e.thread().frames()) {
        System.out.println("\t" + sf.toString());
        System.out.println("\t   Visible Variables:");
        for (LocalVariable lv : sf.visibleVariables()) {
            System.out.println("\t\t--");
            System.out.println("\t\tName: " + lv.name());
            System.out.println("\t\tType: " + lv.typeName());
            Value lvValue = sf.getValue(lv);
            if (lvValue != null) {
                System.out.println("\t\tValue: " + lvValue);
                System.out.println("\t\tValue Type:" + lvValue.type());
                System.out.println("\t\ttoString: " + lv);
            }
        }
        System.out.println("\t   Argument Values:");
        for (Value lv : sf.getArgumentValues()) {
            System.out.println("\t\t--");
            System.out.println("\t\t" + lv.toString());
        }
    }
}
Also used : AbsentInformationException(com.sun.jdi.AbsentInformationException) StackFrame(com.sun.jdi.StackFrame) LocalVariable(com.sun.jdi.LocalVariable) Value(com.sun.jdi.Value)

Aggregations

StackFrame (com.sun.jdi.StackFrame)6 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)4 AbsentInformationException (com.sun.jdi.AbsentInformationException)3 LocalVariable (com.sun.jdi.LocalVariable)3 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)2 StringReference (com.sun.jdi.StringReference)2 Value (com.sun.jdi.Value)2 InvalidStackFrameException (com.sun.jdi.InvalidStackFrameException)1 Method (com.sun.jdi.Method)1 NativeMethodException (com.sun.jdi.NativeMethodException)1 ThreadReference (com.sun.jdi.ThreadReference)1 VirtualMachine (com.sun.jdi.VirtualMachine)1 Connector (com.sun.jdi.connect.Connector)1 IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)1 EventSet (com.sun.jdi.event.EventSet)1 ExceptionEvent (com.sun.jdi.event.ExceptionEvent)1 StepEvent (com.sun.jdi.event.StepEvent)1 EventRequestManager (com.sun.jdi.request.EventRequestManager)1 SocketAttachingConnector (com.sun.tools.jdi.SocketAttachingConnector)1 IOException (java.io.IOException)1