Search in sources :

Example 1 with EventSet

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

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

the class DebuggerUtilsEx method getEventDescriptors.

@NotNull
public static List<Pair<Breakpoint, Event>> getEventDescriptors(@Nullable SuspendContextImpl suspendContext) {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    if (suspendContext != null) {
        EventSet events = suspendContext.getEventSet();
        if (!ContainerUtil.isEmpty(events)) {
            List<Pair<Breakpoint, Event>> eventDescriptors = ContainerUtil.newSmartList();
            RequestManagerImpl requestManager = suspendContext.getDebugProcess().getRequestsManager();
            for (Event event : events) {
                Requestor requestor = requestManager.findRequestor(event.request());
                if (requestor instanceof Breakpoint) {
                    eventDescriptors.add(Pair.create((Breakpoint) requestor, event));
                }
            }
            return eventDescriptors;
        }
    }
    return Collections.emptyList();
}
Also used : Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) EventSet(com.sun.jdi.event.EventSet) Event(com.sun.jdi.event.Event) Requestor(com.intellij.debugger.requests.Requestor) RequestManagerImpl(com.intellij.debugger.engine.requests.RequestManagerImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with EventSet

use of com.sun.jdi.event.EventSet in project gravel by gravel-st.

the class VMRemoteTarget method eventLoop.

private void eventLoop() throws InterruptedException {
    System.out.println("eventLoop started");
    EventQueue eventQueue = vm.eventQueue();
    boolean isRunning = true;
    while (isRunning) {
        EventSet eventSet = eventQueue.remove();
        boolean mayResume = true;
        for (Event event : eventSet) {
            System.out.println(event);
            if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
                isRunning = false;
            } else if (event instanceof ExceptionEvent) {
                mayResume = false;
            }
        }
        if (mayResume)
            eventSet.resume();
    }
}
Also used : ExceptionEvent(com.sun.jdi.event.ExceptionEvent) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) EventSet(com.sun.jdi.event.EventSet) Event(com.sun.jdi.event.Event) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) ExceptionEvent(com.sun.jdi.event.ExceptionEvent) EventQueue(com.sun.jdi.event.EventQueue)

Example 4 with EventSet

use of com.sun.jdi.event.EventSet in project jdk8u_jdk by JetBrains.

the class EventQueueImpl method remove.

/**
     * Filter out events not for user's eyes.
     * Then filter out empty sets.
     */
public EventSet remove(long timeout) throws InterruptedException {
    if (timeout < 0) {
        throw new IllegalArgumentException("Timeout cannot be negative");
    }
    EventSet eventSet;
    while (true) {
        EventSetImpl fullEventSet = removeUnfiltered(timeout);
        if (fullEventSet == null) {
            // timeout
            eventSet = null;
            break;
        }
        /*
             * Remove events from the event set for which
             * there is no corresponding enabled request (
             * this includes our internally requested events.)
             * This never returns null
             */
        eventSet = fullEventSet.userFilter();
        if (!eventSet.isEmpty()) {
            break;
        }
    }
    if ((eventSet != null) && (eventSet.suspendPolicy() == JDWP.SuspendPolicy.ALL)) {
        vm.notifySuspend();
    }
    return eventSet;
}
Also used : EventSet(com.sun.jdi.event.EventSet)

Example 5 with EventSet

use of com.sun.jdi.event.EventSet in project gravel by gravel-st.

the class VMTargetStarter method createJVM.

public VMRemoteTarget createJVM() throws IOException, InterruptedException, IncompatibleThreadStateException {
    Process process = startSecondJVM(VMLocalTarget.class);
    sleep(90);
    // connect
    VirtualMachine vm = new VMAcquirer().connect(debugPort);
    ClassPrepareRequest createClassPrepareRequest = vm.eventRequestManager().createClassPrepareRequest();
    createClassPrepareRequest.addClassFilter(VMLocalTarget.class.getName());
    createClassPrepareRequest.enable();
    vm.resume();
    List<ThreadReference> allThreads = vm.allThreads();
    for (ThreadReference threadReference : allThreads) {
        System.out.println(threadReference + " isSuspended: " + threadReference.isSuspended() + " suspendCount: " + threadReference.suspendCount());
    }
    // process events
    EventQueue eventQueue = vm.eventQueue();
    while (true) {
        EventSet eventSet = eventQueue.remove();
        for (Event event : eventSet) {
            if (event instanceof ClassPrepareEvent) {
                event.request().disable();
                installHaltPoint(vm);
            }
            if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
                return null;
            }
            if (event instanceof BreakpointEvent) {
                event.request().disable();
                ThreadReference thread = ((BreakpointEvent) event).thread();
                return new VMRemoteTarget(process, vm, thread, debugPort);
            }
        }
        eventSet.resume();
    }
}
Also used : VMDeathEvent(com.sun.jdi.event.VMDeathEvent) EventSet(com.sun.jdi.event.EventSet) ThreadReference(com.sun.jdi.ThreadReference) EventQueue(com.sun.jdi.event.EventQueue) ClassPrepareRequest(com.sun.jdi.request.ClassPrepareRequest) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) ClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) BreakpointEvent(com.sun.jdi.event.BreakpointEvent) ClassPrepareEvent(com.sun.jdi.event.ClassPrepareEvent) Event(com.sun.jdi.event.Event) VMDisconnectEvent(com.sun.jdi.event.VMDisconnectEvent) VMDeathEvent(com.sun.jdi.event.VMDeathEvent) VirtualMachine(com.sun.jdi.VirtualMachine)

Aggregations

EventSet (com.sun.jdi.event.EventSet)5 Event (com.sun.jdi.event.Event)3 VirtualMachine (com.sun.jdi.VirtualMachine)2 BreakpointEvent (com.sun.jdi.event.BreakpointEvent)2 EventQueue (com.sun.jdi.event.EventQueue)2 VMDeathEvent (com.sun.jdi.event.VMDeathEvent)2 VMDisconnectEvent (com.sun.jdi.event.VMDisconnectEvent)2 RequestManagerImpl (com.intellij.debugger.engine.requests.RequestManagerImpl)1 Requestor (com.intellij.debugger.requests.Requestor)1 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)1 AbsentInformationException (com.sun.jdi.AbsentInformationException)1 IncompatibleThreadStateException (com.sun.jdi.IncompatibleThreadStateException)1 Method (com.sun.jdi.Method)1 StackFrame (com.sun.jdi.StackFrame)1 ThreadReference (com.sun.jdi.ThreadReference)1 Value (com.sun.jdi.Value)1 Connector (com.sun.jdi.connect.Connector)1 IllegalConnectorArgumentsException (com.sun.jdi.connect.IllegalConnectorArgumentsException)1 ClassPrepareEvent (com.sun.jdi.event.ClassPrepareEvent)1 ExceptionEvent (com.sun.jdi.event.ExceptionEvent)1