use of com.sun.jdi.AbsentInformationException 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.AbsentInformationException 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.AbsentInformationException in project intellij-community by JetBrains.
the class WildcardMethodBreakpoint method getEventMessage.
public String getEventMessage(LocatableEvent event) {
final Location location = event.location();
final String locationQName = DebuggerUtilsEx.getLocationMethodQName(location);
String locationFileName;
try {
locationFileName = location.sourceName();
} catch (AbsentInformationException e) {
locationFileName = "";
}
final int locationLine = location.lineNumber();
if (event instanceof MethodEntryEvent) {
MethodEntryEvent entryEvent = (MethodEntryEvent) event;
final Method method = entryEvent.method();
return DebuggerBundle.message("status.method.entry.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
}
if (event instanceof MethodExitEvent) {
MethodExitEvent exitEvent = (MethodExitEvent) event;
final Method method = exitEvent.method();
return DebuggerBundle.message("status.method.exit.breakpoint.reached", method.declaringType().name() + "." + method.name() + "()", locationQName, locationFileName, locationLine);
}
return "";
}
use of com.sun.jdi.AbsentInformationException in project intellij-community by JetBrains.
the class DefaultSourcePositionProvider method getSourcePositionForField.
@Nullable
private static SourcePosition getSourcePositionForField(@NotNull FieldDescriptor descriptor, @NotNull Project project, @NotNull DebuggerContextImpl context, boolean nearest) {
final ReferenceType type = descriptor.getField().declaringType();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final String fieldName = descriptor.getField().name();
if (fieldName.startsWith(FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
// this field actually mirrors a local variable in the outer class
String varName = fieldName.substring(fieldName.lastIndexOf('$') + 1);
PsiElement element = PositionUtil.getContextElement(context);
if (element == null) {
return null;
}
PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class, false);
if (aClass == null) {
return null;
}
PsiElement navigationElement = aClass.getNavigationElement();
if (!(navigationElement instanceof PsiClass)) {
return null;
}
aClass = (PsiClass) navigationElement;
PsiVariable psiVariable = facade.getResolveHelper().resolveReferencedVariable(varName, aClass);
if (psiVariable == null) {
return null;
}
if (nearest) {
return DebuggerContextUtil.findNearest(context, psiVariable, aClass.getContainingFile());
}
return SourcePosition.createFromElement(psiVariable);
} else {
final DebuggerSession session = context.getDebuggerSession();
final GlobalSearchScope scope = session != null ? session.getSearchScope() : GlobalSearchScope.allScope(project);
PsiClass aClass = facade.findClass(type.name().replace('$', '.'), scope);
if (aClass == null) {
// trying to search, assuming declaring class is an anonymous class
final DebugProcessImpl debugProcess = context.getDebugProcess();
if (debugProcess != null) {
try {
final List<Location> locations = type.allLineLocations();
if (!locations.isEmpty()) {
// important: use the last location to be sure the position will be within the anonymous class
final Location lastLocation = locations.get(locations.size() - 1);
final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation);
aClass = JVMNameUtil.getClassAt(position);
}
} catch (AbsentInformationException | ClassNotPreparedException ignored) {
}
}
}
if (aClass != null) {
PsiField field = aClass.findFieldByName(fieldName, false);
if (field == null)
return null;
if (nearest) {
return DebuggerContextUtil.findNearest(context, field.getNavigationElement(), aClass.getContainingFile());
}
return SourcePosition.createFromElement(field);
}
return null;
}
}
use of com.sun.jdi.AbsentInformationException in project che by eclipse.
the class JdiStackFrameImpl method getLocalVariables.
@Override
public JdiLocalVariable[] getLocalVariables() throws DebuggerException {
if (localVariables == null) {
try {
List<LocalVariable> targetVariables = stackFrame.visibleVariables();
localVariables = new JdiLocalVariable[targetVariables.size()];
int i = 0;
for (LocalVariable var : targetVariables) {
localVariables[i++] = new JdiLocalVariableImpl(stackFrame, var);
}
} catch (AbsentInformationException e) {
throw new DebuggerAbsentInformationException(e.getMessage(), e);
} catch (InvalidStackFrameException | NativeMethodException e) {
throw new DebuggerException(e.getMessage(), e);
}
}
return localVariables;
}
Aggregations