/** * Suspend the main thread when the program enters the main method of the specified main class. * @param debugSession * the debug session. * @param mainClass * the fully qualified name of the main class. * @return * a {@link CompletableFuture} that contains the suspended main thread id. */ public static CompletableFuture<Long> stopOnEntry(IDebugSession debugSession, String mainClass) { CompletableFuture<Long> future = new CompletableFuture<>(); EventRequestManager manager = debugSession.getVM().eventRequestManager(); MethodEntryRequest request = manager.createMethodEntryRequest(); request.addClassFilter(mainClass); request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); debugSession.getEventHub().events().filter(debugEvent -> { return debugEvent.event instanceof MethodEntryEvent && request.equals(debugEvent.event.request()); }).subscribe(debugEvent -> { Method method = ((MethodEntryEvent) debugEvent.event).method(); if (method.isPublic() && method.isStatic() && method.name().equals("main") && method.signature().equals("([Ljava/lang/String;)V")) { deleteEventRequestSafely(debugSession.getVM().eventRequestManager(), request); debugEvent.shouldResume = false; ThreadReference bpThread = ((MethodEntryEvent) debugEvent.event).thread(); future.complete(bpThread.uniqueID()); } }); request.enable(); return future; }
@Override public void perform(String[] argv, Context ctx) { EventRequestManager manager = ctx.getVm().eventRequestManager(); MethodEntryRequest mer = manager.createMethodEntryRequest(); mer.setSuspendPolicy(EventRequest.SUSPEND_NONE); mer.enable(); ctx.register(mer, new EventCallback() { @Override public void handleEvent(Event event) { MethodEntryEvent mee = (MethodEntryEvent) event; Method method = mee.method(); System.out.println("--" + method.name()); // mee.thread().resume(); } }); }
public static F3Event wrap(F3VirtualMachine f3vm, Event evt) { if (evt == null) { return null; } if (evt instanceof AccessWatchpointEvent) { return new F3AccessWatchpointEvent(f3vm, (AccessWatchpointEvent)evt); } else if (evt instanceof BreakpointEvent) { return new F3BreakpointEvent(f3vm, (BreakpointEvent)evt); } else if (evt instanceof ClassPrepareEvent) { return new F3ClassPrepareEvent(f3vm, (ClassPrepareEvent)evt); } else if (evt instanceof ClassUnloadEvent) { return new F3ClassUnloadEvent(f3vm, (ClassUnloadEvent)evt); } else if (evt instanceof ExceptionEvent) { return new F3ExceptionEvent(f3vm, (ExceptionEvent)evt); } else if (evt instanceof MethodEntryEvent) { return new F3MethodEntryEvent(f3vm, (MethodEntryEvent)evt); } else if (evt instanceof MethodExitEvent) { return new F3MethodExitEvent(f3vm, (MethodExitEvent)evt); } else if (evt instanceof ModificationWatchpointEvent) { return new F3ModificationWatchpointEvent(f3vm, (ModificationWatchpointEvent)evt); } else if (evt instanceof MonitorContendedEnterEvent) { return new F3MonitorContendedEnterEvent(f3vm, (MonitorContendedEnterEvent)evt); } else if (evt instanceof MonitorContendedEnteredEvent) { return new F3MonitorContendedEnteredEvent(f3vm, (MonitorContendedEnteredEvent)evt); } else if (evt instanceof MonitorWaitEvent) { return new F3MonitorWaitEvent(f3vm, (MonitorWaitEvent)evt); } else if (evt instanceof MonitorWaitedEvent) { return new F3MonitorWaitedEvent(f3vm, (MonitorWaitedEvent)evt); } else if (evt instanceof StepEvent) { return new F3StepEvent(f3vm, (StepEvent)evt); } else if (evt instanceof ThreadDeathEvent) { return new F3ThreadDeathEvent(f3vm, (ThreadDeathEvent)evt); } else if (evt instanceof ThreadStartEvent) { return new F3ThreadStartEvent(f3vm, (ThreadStartEvent)evt); } else if (evt instanceof VMDeathEvent) { return new F3VMDeathEvent(f3vm, (VMDeathEvent)evt); } else if (evt instanceof VMDisconnectEvent) { return new F3VMDisconnectEvent(f3vm, (VMDisconnectEvent)evt); } else if (evt instanceof VMStartEvent) { return new F3VMStartEvent(f3vm, (VMStartEvent)evt); } else if (evt instanceof WatchpointEvent) { return new F3WatchpointEvent(f3vm, (WatchpointEvent)evt); } else if (evt instanceof LocatableEvent) { return new F3LocatableEvent(f3vm, (LocatableEvent)evt); } else { return new F3Event(f3vm, evt); } }
@Override public void jdiMethodEntry(final MethodEntryEvent event) { if (!override && !owner.isStarted()) { return; } try { // if (manager().generateLockEvents()) { // inspectThreads(); // } delegate.handleMethodEntry(event, manager().generateLocalEvents()); } catch (final Throwable e) { JiveDebugPlugin.log(e); } }
/** * Filtered method calls/returns are captured lazily by determineStackFrame(event). */ void handleMethodEntry(final MethodEntryEvent event, final boolean generateLocals) throws IncompatibleThreadStateException, AbsentInformationException { if (!eventFilter().acceptsMethod(event.method(), event.thread())) { return; } // adjust the stack frames if necessary final StackFrame frame = determineStackFrame(event); // handle a pending returned event if necessary handlePendingReturned(event.location(), frame, event.thread()); // record newly observed types and objects if necessary handleNewObject(frame, event.thread()); // resolve the method resolveMethod(frame, event.method()); // record the method call dispatcher().dispatchInModelCallEvent(event, frame); // handle locals if necessary if (generateLocals) { handleLocals(null, frame, event.location()); } }
/** * This method is trigger every time one method (in not excluded classes) is called. </br> * The information that is collected is the following: </br> * </ul> * <li>Method's name</li> * <li>Method's Class (Class where the method is called)</li> * <li>Method's arguments</li> * <li>Method's Class information (State of the "this" object when the method is called)</li> * </ul> * @param event - The event that is going to be processed. */ public void methodEntryEvent(MethodEntryEvent event) { ThreadReference thread = event.thread(); Method method = event.method(); String className = ClassUtils.getClass(method.declaringType()); String methodName = method.name(); ReferenceType ref=method.declaringType(); //"class" where is declare List<Data> arguments = processArguments(method,thread); Data argument_this = null; if (!Settings.getInstance().isExcludedThis()) argument_this = processThis(event,ref,thread); MethodEntryInfo info = new MethodEntryInfo(methodName,className,arguments,argument_this); synchronized (writer) { writer.writeMethodEntryInfo(info); } }
/** * Dispatch incoming events */ private void handleEvent(Event event) { if (event instanceof ExceptionEvent) { if (!enableProfiling) exceptionManager.exceptionEvent((ExceptionEvent)event); } else if (event instanceof MethodEntryEvent) { methodEntryEvent((MethodEntryEvent)event); } else if (event instanceof MethodExitEvent) { methodExitEvent((MethodExitEvent)event); } else if (event instanceof ThreadDeathEvent) { threadeath.threadDeathEvent((ThreadDeathEvent)event); } else if (event instanceof VMDeathEvent) { vmDeathEvent((VMDeathEvent)event); } else if (event instanceof VMDisconnectEvent) { connected = disconnect.vmDisconnectEvent((VMDisconnectEvent)event); } }
@Override public void enter(MethodEntryEvent event) { MethodEntity entity = new MethodEntity(); com.sun.jdi.Method method = event.method(); entity.setClassName(method.declaringType().signature()); entity.setMethodName(method.name()); entity.setDescription(method.signature()); MethodTracer tracer = simplify.getTracerMap().get(entity); if (tracer != null) { parse(tracer, event.thread(), event.location()); } }
public void methodEntryEvent(MethodEntryEvent evt) { synchronized (listeners) { for (EventNotifier en : listeners) { en.methodEntryEvent(evt); } } }
/** * Convenient method that compares the method name (extracted from event) with the given set of names. * @param event * @param methodName1 * @param methodName2 */ private void checkEntryExit(Event event, String methodName1, String methodName2) { if (event instanceof MethodEntryEvent) { System.out.println("Starting method = " + ((MethodEntryEvent)event).method().toString()); Assert.assertTrue(((MethodEntryEvent)event).method().toString().equals(methodName1) || ((MethodEntryEvent)event).method().toString().equals(methodName2)); }else if (event instanceof MethodExitEvent) { System.out.println("Exiting method = " + ((MethodExitEvent)event).method().toString()); Assert.assertTrue(((MethodExitEvent)event).method().toString().equals(methodName1) || ((MethodExitEvent)event).method().toString().equals(methodName2)); } }
@Override public boolean handleEvent(final Event event, final JDIDebugTarget target, final boolean suspendVote, final EventSet eventSet) { if (owner.isActive()) { owner.jdiHandler().jdiMethodEntry((MethodEntryEvent) event); } return true; }
/** * Creates and dispatches an in-model {@code CallEvent} from the given {@code MethodEntryEvent} * and {@code StackFrame}. The stack frame represents the method activation resulting from the * call. */ @Override public void dispatchInModelCallEvent(final MethodEntryEvent event, final StackFrame frame) { final IMethodCallEvent initiator = adapter().createMethodCallEvent(event, frame, true, manager().generateLocalEvents()); dispatchEvent(initiator); dispatchEvent(adapter().createMethodEnterEvent(initiator, frame.thread())); }
/** * Notification of a method invocation in the target VM. This event occurs after entry into the * invoked method and before any code has executed. Method entry events are generated for both * native and non-native methods. * * @param event * * @see <a href="">http://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/index.html</a> */ @Override public void jdiMethodEntry(final MethodEntryEvent event) { final Method method = event.location().method(); if (method.isSynthetic() || method.isBridge() || method.name().contains("$")) { return; } // this.currentEvent = event; this.currentThread = event.thread(); // final long thId = registry.getThreadId(event.thread()); // final long pfrId = registry.methodEntered(thId); // final long[] eventId = registry.encode(EventHandlerLite.KIND_METHOD_ENTERED); // System.out.format(EventHandlerLite.ENCODED_METHOD_ENTERED, eventId[0], eventId[1], pfrId, eventId[2]); // System.out.println(registry.decode(eventId)); // this.currentEvent = null; this.currentThread = null; }
private void methodEntryEvent(MethodEntryEvent event) { String methodName = event.method().toString(); String className = ClassUtils.getClass(event.method().declaringType()); if (!excludesClassMethods.isExcluded(className,methodName) && !className.contains("$")){ if (enableProfiling) profiler.profileEvent(event); else methodEntryManager.methodEntryEvent(event); } }
public F3MethodEntryEvent(F3VirtualMachine f3vm, MethodEntryEvent underlying) { super(f3vm, underlying); }
@Override protected MethodEntryEvent underlying() { return (MethodEntryEvent) super.underlying(); }
public void methodEntryEvent(MethodEntryEvent e) { }
@Override public void visit(MethodEntryEvent event) { }
public VisitableMethodEntryEvent(MethodEntryEvent event) { this.event = event; }
private Data processThis(MethodEntryEvent event, ReferenceType ref, ThreadReference thread) { StackFrame stack=null; try { stack = thread.frame(0); } catch (IncompatibleThreadStateException e) { e.printStackTrace(); } Value value = stack.thisObject(); Data this_data = utils.getObj("this",value,new ArrayList<Long>()); return this_data; }
public void profileEvent(MethodEntryEvent event) { Method method = event.method(); String fullClassName = ClassUtils.getClass(method.declaringType()); List<String> packageName = ClassUtils.getPackageList(fullClassName); String className = getClassName(fullClassName); String completeMethodName = method.toString(); String methodName = completeMethodName.substring(fullClassName.length()+1,completeMethodName.length()); profilerTree.add(packageName,className,methodName); }
/** * Visit a {@code MethodEntryEvent}. * * @param event Event to visit */ void visit(MethodEntryEvent event);
/** * Creates and dispatches an in-model method call event from the given {@code StackFrame}. The * stack frame represents the method activation resulting from the call. */ public void dispatchInModelCallEvent(MethodEntryEvent event, StackFrame frame);
/** * Notification of a method invocation in the target VM. */ void jdiMethodEntry(MethodEntryEvent event);
void enter(MethodEntryEvent event);
public void profileEvent(MethodEntryEvent event);