Search in sources :

Example 11 with Location

use of com.sun.jdi.Location in project kotlin by JetBrains.

the class AbstractPositionManagerTest method assertBreakpointIsHandledCorrectly.

private static void assertBreakpointIsHandledCorrectly(Breakpoint breakpoint, PositionManager positionManager) throws NoDataException {
    SourcePosition position = SourcePosition.createFromLine(breakpoint.file, breakpoint.lineNumber);
    List<ReferenceType> classes = positionManager.getAllClasses(position);
    assertNotNull(classes);
    assertEquals(1, classes.size());
    ReferenceType type = classes.get(0);
    assertTrue("Type name " + type.name() + " doesn't match " + breakpoint.classNameRegexp + " for line " + (breakpoint.lineNumber + 1), type.name().matches(breakpoint.classNameRegexp));
    // JDI names are of form "package.Class$InnerClass"
    ReferenceType typeWithFqName = new MockReferenceType(type.name().replace('/', '.'));
    Location location = new MockLocation(typeWithFqName, breakpoint.file.getName(), breakpoint.lineNumber + 1);
    SourcePosition actualPosition = positionManager.getSourcePosition(location);
    assertNotNull(actualPosition);
    assertEquals(position.getFile(), actualPosition.getFile());
    assertEquals(position.getLine(), actualPosition.getLine());
}
Also used : SourcePosition(com.intellij.debugger.SourcePosition) ReferenceType(com.sun.jdi.ReferenceType) Location(com.sun.jdi.Location)

Example 12 with Location

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

the class Testing method addIntentBreakpoints.

@SuppressWarnings("restriction")
public static void addIntentBreakpoints(VirtualMachine vm) {
    EventRequestManager mgr = vm.eventRequestManager();
    com.sun.jdi.ReferenceType intentClass = vm.classesByName("android.content.Intent").get(0);
    for (Method m : intentClass.methodsByName("<init>")) {
        System.out.println("Breakpoint: " + m.toString());
        Location location = m.location();
        BreakpointRequest bpr = mgr.createBreakpointRequest(location);
        bpr.enable();
    }
    for (Method m : intentClass.methodsByName("putExtra")) {
        System.out.println("Breakpoint: " + m.toString());
        Location location = m.location();
        BreakpointRequest bpr = mgr.createBreakpointRequest(location);
        bpr.enable();
    }
}
Also used : BreakpointRequest(com.sun.jdi.request.BreakpointRequest) Method(com.sun.jdi.Method) EventRequestManager(com.sun.jdi.request.EventRequestManager) Location(com.sun.jdi.Location)

Example 13 with Location

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

the class ContextUtil method getSourcePosition.

@Nullable
public static SourcePosition getSourcePosition(@Nullable final StackFrameContext context) {
    if (context == null) {
        return null;
    }
    DebugProcessImpl debugProcess = (DebugProcessImpl) context.getDebugProcess();
    if (debugProcess == null) {
        return null;
    }
    final StackFrameProxy frameProxy = context.getFrameProxy();
    if (frameProxy == null) {
        return null;
    }
    Location location = null;
    try {
        location = frameProxy.location();
    } catch (Throwable e) {
        LOG.debug(e);
    }
    if (location == null) {
        return null;
    }
    return debugProcess.getPositionManager().getSourcePosition(location);
}
Also used : StackFrameProxy(com.intellij.debugger.engine.jdi.StackFrameProxy) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Location

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

the class NodeManagerImpl method getContextKeyForFrame.

@Nullable
public static String getContextKeyForFrame(final StackFrameProxyImpl frame) {
    if (frame == null) {
        return null;
    }
    try {
        final Location location = frame.location();
        final Method method = DebuggerUtilsEx.getMethod(location);
        if (method == null) {
            return null;
        }
        final ReferenceType referenceType = location.declaringType();
        final StringBuilder builder = StringBuilderSpinAllocator.alloc();
        try {
            return builder.append(referenceType.signature()).append("#").append(method.name()).append(method.signature()).toString();
        } finally {
            StringBuilderSpinAllocator.dispose(builder);
        }
    } catch (EvaluateException ignored) {
    } catch (InternalException ie) {
        if (ie.errorCode() != 23) {
            // INVALID_METHODID
            throw ie;
        }
    }
    return null;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Method(com.sun.jdi.Method) ReferenceType(com.sun.jdi.ReferenceType) Location(com.sun.jdi.Location) InternalException(com.sun.jdi.InternalException) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with Location

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

the class ExceptionBreakpoint method getEventMessage.

public String getEventMessage(LocatableEvent event) {
    String exceptionName = (getQualifiedName() != null) ? getQualifiedName() : CommonClassNames.JAVA_LANG_THROWABLE;
    String threadName = null;
    if (event instanceof ExceptionEvent) {
        ExceptionEvent exceptionEvent = (ExceptionEvent) event;
        try {
            exceptionName = exceptionEvent.exception().type().name();
            threadName = exceptionEvent.thread().name();
        } catch (Exception ignore) {
        }
    }
    final Location location = event.location();
    final String locationQName = DebuggerUtilsEx.getLocationMethodQName(location);
    String locationFileName;
    try {
        locationFileName = location.sourceName();
    } catch (AbsentInformationException e) {
        locationFileName = "";
    }
    final int locationLine = Math.max(0, location.lineNumber());
    if (threadName != null) {
        return DebuggerBundle.message("exception.breakpoint.console.message.with.thread.info", exceptionName, threadName, locationQName, locationFileName, locationLine);
    } else {
        return DebuggerBundle.message("exception.breakpoint.console.message", exceptionName, locationQName, locationFileName, locationLine);
    }
}
Also used : ExceptionEvent(com.sun.jdi.event.ExceptionEvent) AbsentInformationException(com.sun.jdi.AbsentInformationException) InvalidDataException(com.intellij.openapi.util.InvalidDataException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) AbsentInformationException(com.sun.jdi.AbsentInformationException) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Location(com.sun.jdi.Location)

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