use of com.sun.jdi.request.EventRequestManager in project che by eclipse.
the class JavaDebugger method addBreakpoint.
@Override
public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException {
final String className = findFQN(breakpoint);
final int lineNumber = breakpoint.getLocation().getLineNumber();
List<ReferenceType> classes = vm.classesByName(className);
// it may mean that class doesn't loaded by a target JVM yet
if (classes.isEmpty()) {
deferBreakpoint(breakpoint);
throw new DebuggerException("Class not loaded");
}
ReferenceType clazz = classes.get(0);
List<com.sun.jdi.Location> locations;
try {
locations = clazz.locationsOfLine(lineNumber);
} catch (AbsentInformationException | ClassNotPreparedException e) {
throw new DebuggerException(e.getMessage(), e);
}
if (locations.isEmpty()) {
throw new DebuggerException("Line " + lineNumber + " not found in class " + className);
}
com.sun.jdi.Location location = locations.get(0);
if (location.method() == null) {
// Line is out of method.
throw new DebuggerException("Invalid line " + lineNumber + " in class " + className);
}
// Ignore new breakpoint if already have breakpoint at the same location.
EventRequestManager requestManager = getEventManager();
for (BreakpointRequest breakpointRequest : requestManager.breakpointRequests()) {
if (location.equals(breakpointRequest.location())) {
LOG.debug("Breakpoint at {} already set", location);
return;
}
}
try {
EventRequest breakPointRequest = requestManager.createBreakpointRequest(location);
breakPointRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
String expression = breakpoint.getCondition();
if (!(expression == null || expression.isEmpty())) {
ExpressionParser parser = ExpressionParser.newInstance(expression);
breakPointRequest.putProperty("org.eclipse.che.ide.java.debug.condition.expression.parser", parser);
}
breakPointRequest.setEnabled(true);
} catch (NativeMethodException | IllegalThreadStateException | InvalidRequestStateException e) {
throw new DebuggerException(e.getMessage(), e);
}
debuggerCallback.onEvent(new BreakpointActivatedEventImpl(new BreakpointImpl(breakpoint.getLocation(), true, breakpoint.getCondition())));
LOG.debug("Add breakpoint: {}", location);
}
use of com.sun.jdi.request.EventRequestManager in project che by eclipse.
the class JavaDebugger method deleteBreakpoint.
@Override
public void deleteBreakpoint(Location location) throws DebuggerException {
final String className = location.getTarget();
final int lineNumber = location.getLineNumber();
EventRequestManager requestManager = getEventManager();
List<BreakpointRequest> snapshot = new ArrayList<>(requestManager.breakpointRequests());
for (BreakpointRequest breakpointRequest : snapshot) {
com.sun.jdi.Location jdiLocation = breakpointRequest.location();
if (jdiLocation.declaringType().name().equals(className) && jdiLocation.lineNumber() == lineNumber) {
requestManager.deleteEventRequest(breakpointRequest);
LOG.debug("Delete breakpoint: {}", location);
}
}
}
use of com.sun.jdi.request.EventRequestManager 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();
}
}
}
use of com.sun.jdi.request.EventRequestManager in project intellij-community by JetBrains.
the class BreakpointManager method applyThreadFilter.
public void applyThreadFilter(@NotNull final DebugProcessImpl debugProcess, @Nullable ThreadReference newFilterThread) {
final RequestManagerImpl requestManager = debugProcess.getRequestsManager();
final ThreadReference oldFilterThread = requestManager.getFilterThread();
if (Comparing.equal(newFilterThread, oldFilterThread)) {
// the filter already added
return;
}
requestManager.setFilterThread(newFilterThread);
if (newFilterThread == null || oldFilterThread != null) {
final List<Breakpoint> breakpoints = getBreakpoints();
for (Breakpoint breakpoint : breakpoints) {
if (LineBreakpoint.CATEGORY.equals(breakpoint.getCategory()) || MethodBreakpoint.CATEGORY.equals(breakpoint.getCategory())) {
requestManager.deleteRequest(breakpoint);
breakpoint.createRequest(debugProcess);
}
}
} else {
// important! need to add filter to _existing_ requests, otherwise Requestor->Request mapping will be lost
// and debugger trees will not be restored to original state
EventRequestManager eventRequestManager = requestManager.getVMRequestManager();
if (eventRequestManager != null) {
applyFilter(eventRequestManager.breakpointRequests(), request -> request.addThreadFilter(newFilterThread));
applyFilter(eventRequestManager.methodEntryRequests(), request -> request.addThreadFilter(newFilterThread));
applyFilter(eventRequestManager.methodExitRequests(), request -> request.addThreadFilter(newFilterThread));
}
}
}
use of com.sun.jdi.request.EventRequestManager in project intellij-community by JetBrains.
the class DebugProcessImpl method doStep.
/**
*
* @param suspendContext
* @param stepThread
* @param size the step size. One of {@link StepRequest#STEP_LINE} or {@link StepRequest#STEP_MIN}
* @param depth
* @param hint may be null
*/
protected void doStep(final SuspendContextImpl suspendContext, final ThreadReferenceProxyImpl stepThread, int size, int depth, RequestHint hint) {
if (stepThread == null) {
return;
}
try {
final ThreadReference stepThreadReference = stepThread.getThreadReference();
if (LOG.isDebugEnabled()) {
LOG.debug("DO_STEP: creating step request for " + stepThreadReference);
}
deleteStepRequests(stepThreadReference);
EventRequestManager requestManager = getVirtualMachineProxy().eventRequestManager();
StepRequest stepRequest = requestManager.createStepRequest(stepThreadReference, size, depth);
if (!(hint != null && hint.isIgnoreFilters())) /*&& depth == StepRequest.STEP_INTO*/
{
checkPositionNotFiltered(stepThread, filters -> filters.forEach(f -> stepRequest.addClassExclusionFilter(f.getPattern())));
}
// suspend policy to match the suspend policy of the context:
// if all threads were suspended, then during stepping all the threads must be suspended
// if only event thread were suspended, then only this particular thread must be suspended during stepping
stepRequest.setSuspendPolicy(suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD ? EventRequest.SUSPEND_EVENT_THREAD : EventRequest.SUSPEND_ALL);
if (hint != null) {
//noinspection HardCodedStringLiteral
stepRequest.putProperty("hint", hint);
}
stepRequest.enable();
} catch (ObjectCollectedException ignored) {
}
}
Aggregations