Search in sources :

Example 1 with Location

use of com.sun.jdi.Location in project otertool by wuntee.

the class Testing method addBreakpointToMethod.

public static void addBreakpointToMethod(Method m, EventRequestManager mgr) {
    System.out.println("Breakpoint: " + m.toString());
    try {
        Location location = m.location();
        BreakpointRequest bpr = mgr.createBreakpointRequest(location);
        bpr.enable();
    } catch (com.sun.jdi.NativeMethodException e) {
        System.out.println("Error: Cant add breakpoint to native method (" + m.toString() + ")");
    }
}
Also used : BreakpointRequest(com.sun.jdi.request.BreakpointRequest) Location(com.sun.jdi.Location)

Example 2 with Location

use of com.sun.jdi.Location 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;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ReferenceType(com.sun.jdi.ReferenceType) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with Location

use of com.sun.jdi.Location 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 "";
}
Also used : AbsentInformationException(com.sun.jdi.AbsentInformationException) Method(com.sun.jdi.Method) MethodExitEvent(com.sun.jdi.event.MethodExitEvent) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Location(com.sun.jdi.Location) MethodEntryEvent(com.sun.jdi.event.MethodEntryEvent)

Example 4 with Location

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

the class AlternativeSourceNotificationProvider method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (!DebuggerSettings.getInstance().SHOW_ALTERNATIVE_SOURCE) {
        return null;
    }
    XDebugSession session = XDebuggerManager.getInstance(myProject).getCurrentSession();
    if (session == null) {
        FILE_PROCESSED_KEY.set(file, null);
        return null;
    }
    XSourcePosition position = session.getCurrentPosition();
    if (position == null || !file.equals(position.getFile())) {
        FILE_PROCESSED_KEY.set(file, null);
        return null;
    }
    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
    if (psiFile == null)
        return null;
    if (!(psiFile instanceof PsiJavaFile))
        return null;
    PsiClass[] classes = ((PsiJavaFile) psiFile).getClasses();
    if (classes.length == 0)
        return null;
    PsiClass baseClass = classes[0];
    String name = baseClass.getQualifiedName();
    if (name == null)
        return null;
    if (DumbService.getInstance(myProject).isDumb())
        return null;
    ArrayList<PsiClass> alts = ContainerUtil.newArrayList(JavaPsiFacade.getInstance(myProject).findClasses(name, GlobalSearchScope.allScope(myProject)));
    ContainerUtil.removeDuplicates(alts);
    FILE_PROCESSED_KEY.set(file, true);
    if (alts.size() > 1) {
        for (PsiClass cls : alts) {
            if (cls.equals(baseClass) || cls.getNavigationElement().equals(baseClass)) {
                alts.remove(cls);
                break;
            }
        }
        alts.add(0, baseClass);
        ComboBoxClassElement[] elems = ContainerUtil.map2Array(alts, ComboBoxClassElement.class, psiClass -> new ComboBoxClassElement((PsiClass) psiClass.getNavigationElement()));
        String locationDeclName = null;
        XStackFrame frame = session.getCurrentStackFrame();
        if (frame instanceof JavaStackFrame) {
            Location location = ((JavaStackFrame) frame).getDescriptor().getLocation();
            if (location != null) {
                locationDeclName = location.declaringType().name();
            }
        }
        return new AlternativeSourceNotificationPanel(elems, baseClass, myProject, file, locationDeclName);
    }
    return null;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XStackFrame(com.intellij.xdebugger.frame.XStackFrame) JavaStackFrame(com.intellij.debugger.engine.JavaStackFrame) XSourcePosition(com.intellij.xdebugger.XSourcePosition) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with Location

use of com.sun.jdi.Location 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;
    }
}
Also used : AbsentInformationException(com.sun.jdi.AbsentInformationException) ClassNotPreparedException(com.sun.jdi.ClassNotPreparedException) ReferenceType(com.sun.jdi.ReferenceType) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SourcePosition(com.intellij.debugger.SourcePosition) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Location (com.sun.jdi.Location)15 Nullable (org.jetbrains.annotations.Nullable)7 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)5 Method (com.sun.jdi.Method)5 ReferenceType (com.sun.jdi.ReferenceType)5 SourcePosition (com.intellij.debugger.SourcePosition)4 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)3 AbsentInformationException (com.sun.jdi.AbsentInformationException)3 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 Computable (com.intellij.openapi.util.Computable)2 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)2 DebuggerUtils (com.intellij.debugger.engine.DebuggerUtils)1 JavaStackFrame (com.intellij.debugger.engine.JavaStackFrame)1 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)1 EvaluatorBuilderImpl (com.intellij.debugger.engine.evaluation.expression.EvaluatorBuilderImpl)1 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 StackFrameProxy (com.intellij.debugger.engine.jdi.StackFrameProxy)1 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)1 DebuggerUtilsEx (com.intellij.debugger.impl.DebuggerUtilsEx)1