use of com.sun.jdi.ReferenceType 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.ReferenceType in project che by eclipse.
the class JdiStackFrameImpl method getFields.
@Override
public JdiField[] getFields() throws DebuggerException {
if (fields == null) {
try {
ObjectReference object = stackFrame.thisObject();
if (object == null) {
ReferenceType type = stackFrame.location().declaringType();
List<Field> fs = stackFrame.location().declaringType().allFields();
fields = new JdiField[fs.size()];
int i = 0;
for (Field f : fs) {
fields[i++] = new JdiFieldImpl(f, type);
}
} else {
List<Field> fs = object.referenceType().allFields();
fields = new JdiField[fs.size()];
int i = 0;
for (Field f : fs) {
fields[i++] = new JdiFieldImpl(f, object);
}
}
Arrays.sort(fields);
} catch (InvalidStackFrameException e) {
throw new DebuggerException(e.getMessage(), e);
}
}
return fields;
}
use of com.sun.jdi.ReferenceType 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);
}
}
use of com.sun.jdi.ReferenceType in project kotlin by JetBrains.
the class DebuggerSteppingHelper method getCurrentClassName.
// copied from DebugProcessImpl.getActiveFilters
@Nullable
private static String getCurrentClassName(ThreadReferenceProxyImpl thread) {
try {
if (thread != null && thread.frameCount() > 0) {
StackFrameProxyImpl stackFrame = thread.frame(0);
if (stackFrame != null) {
Location location = stackFrame.location();
ReferenceType referenceType = location == null ? null : location.declaringType();
if (referenceType != null) {
return referenceType.name();
}
}
}
} catch (EvaluateException ignored) {
}
return null;
}
use of com.sun.jdi.ReferenceType in project intellij-community by JetBrains.
the class SpringLoadedPositionManager method getAllClasses.
@NotNull
@Override
public List<ReferenceType> getAllClasses(@NotNull final SourcePosition classPosition) throws NoDataException {
int line;
String className;
AccessToken accessToken = ReadAction.start();
try {
className = findEnclosingName(classPosition);
if (className == null)
throw NoDataException.INSTANCE;
line = classPosition.getLine();
} finally {
accessToken.finish();
}
List<ReferenceType> referenceTypes = myDebugProcess.getVirtualMachineProxy().classesByName(className);
if (referenceTypes.isEmpty())
throw NoDataException.INSTANCE;
Set<ReferenceType> res = new HashSet<>();
for (ReferenceType referenceType : referenceTypes) {
findNested(res, referenceType, line);
}
if (res.isEmpty()) {
throw NoDataException.INSTANCE;
}
return new ArrayList<>(res);
}
Aggregations