com.sun.jdi.StackFrame Java Examples

The following examples show how to use com.sun.jdi.StackFrame. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetUninitializedStringValue.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #2
Source File: GetUninitializedStringValue.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #3
Source File: GetUninitializedStringValue.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #4
Source File: GetUninitializedStringValue.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #5
Source File: JPDADebuggerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void popFrames (ThreadReference thread, StackFrame frame) {
    PropertyChangeEvent evt = null;
    accessLock.readLock().lock();
    try {
        JPDAThreadImpl threadImpl = getThread(thread);
        setState (STATE_RUNNING);
        try {
            threadImpl.popFrames(frame);
            evt = updateCurrentCallStackFrameNoFire(threadImpl);
        } catch (IncompatibleThreadStateException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            setState (STATE_STOPPED);
        }
    } finally {
        accessLock.readLock().unlock();
    }
    if (evt != null) {
        firePropertyChange(evt);
    }
}
 
Example #6
Source File: GetUninitializedStringValue.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #7
Source File: EvaluationContext.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new context in which to evaluate expressions.
 *
 * @param frame the frame in which context evaluation occurs
 * @param imports list of imports
 * @param staticImports list of static imports
 */
public EvaluationContext(JPDAThreadImpl thread, StackFrame frame, int frameDepth,
                         ObjectReference contextVariable,
                         List<String> imports, List<String> staticImports,
                         boolean canInvokeMethods, Runnable methodInvokePreproc,
                         JPDADebuggerImpl debugger, VMCache vmCache) {
    if (thread == null) throw new IllegalArgumentException("Thread argument must not be null");
    if (frame == null) throw new IllegalArgumentException("Frame argument must not be null");
    if (imports == null) throw new IllegalArgumentException("Imports argument must not be null");
    if (staticImports == null) throw new IllegalArgumentException("Static imports argument must not be null");
    this.thread = thread;
    this.frame = frame;
    this.frameDepth = frameDepth;
    this.contextVariable = contextVariable;
    this.sourceImports = imports;
    this.staticImports = staticImports;
    this.canInvokeMethods = canInvokeMethods;
    this.methodInvokePreproc = methodInvokePreproc;
    this.debugger = debugger;
    this.vmCache = vmCache;

    stack.push(new HashMap<String, ScriptVariable>());
}
 
Example #8
Source File: JPDAStepTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getCurrentClassName() {
    JPDADebuggerImpl debugger = (JPDADebuggerImpl) support.getDebugger();
    
    String className = null;
    
    try {
        JPDAThreadImpl jpdaThread = (JPDAThreadImpl) debugger.getCurrentThread();
        if (jpdaThread == null) {
            System.err.println("NULL Current Thread!");
            Thread.dumpStack();
        } else {
            StackFrame sf = jpdaThread.getThreadReference().frame(0);
            if (sf == null) {
                System.err.println("No stack frame!");
                Thread.dumpStack();
            } else {
                className = sf.location().declaringType().name();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return className;
}
 
Example #9
Source File: GetUninitializedStringValue.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #10
Source File: GetObjectLockCount.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static int getLockRecursions(VirtualMachine vm) {
    List <ThreadReference> threads = vm.allThreads();
    for (ThreadReference thread : threads) {
        if (thread.name().equals("main")) {

            System.out.println("Found main thread.");
            try{
                StackFrame frame = thread.frame(3);
                return frame.thisObject().entryCount();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.out.println("Main thread not found!");
    }
    return -1;
}
 
Example #11
Source File: GetUninitializedStringValue.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #12
Source File: GetUninitializedStringValue.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #13
Source File: RestartFrameHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private boolean canRestartFrame(IDebugAdapterContext context, StackFrameReference frameReference) {
    if (!context.getDebugSession().getVM().canPopFrames()) {
        return false;
    }
    ThreadReference reference = frameReference.getThread();
    StackFrame[] frames = context.getStackFrameManager().reloadStackFrames(reference);

    // The frame cannot be the bottom one of the call stack:
    if (frames.length <= frameReference.getDepth() + 1) {
        return false;
    }

    // Cannot restart frame involved with native call stacks:
    for (int i = 0; i <= frameReference.getDepth() + 1; i++) {
        if (StackFrameUtility.isNative(frames[i])) {
            return false;
        }
    }
    return true;
}
 
Example #14
Source File: StackTraceRequestHandler.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context)
        throws URISyntaxException, AbsentInformationException {
    Location location = stackFrame.location();
    Method method = location.method();
    Types.Source clientSource = this.convertDebuggerSourceToClient(location, context);
    String methodName = formatMethodName(method, true, true);
    int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1());
    // Line number returns -1 if the information is not available; specifically, always returns -1 for native methods.
    if (lineNumber < 0) {
        if (method.isNative()) {
            // For native method, display a tip text "native method" in the Call Stack View.
            methodName += "[native method]";
        } else {
            // For other unavailable method, such as lambda expression's built-in methods run/accept/apply,
            // display "Unknown Source" in the Call Stack View.
            clientSource = null;
        }
    }
    return new Types.StackFrame(frameId, methodName, clientSource, lineNumber, context.isClientColumnsStartAt1() ? 1 : 0);
}
 
Example #15
Source File: GetUninitializedStringValue.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #16
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given a stack frame, find the target java project that the associated source file belongs to.
 *
 * @param stackFrame
 *                  the stack frame.
 * @param containers
 *                  the source container list.
 * @return the java project.
 */
public static IJavaProject findProject(StackFrame stackFrame, ISourceContainer[] containers) {
    Location location = stackFrame.location();
    try {
        Object sourceElement = findSourceElement(location.sourcePath(), containers);
        if (sourceElement instanceof IResource) {
            return JavaCore.create(((IResource) sourceElement).getProject());
        } else if (sourceElement instanceof IClassFile) {
            IJavaProject javaProject = ((IClassFile) sourceElement).getJavaProject();
            if (javaProject != null) {
                return javaProject;
            }
        }
    } catch (AbsentInformationException e) {
        // When the compiled .class file doesn't contain debug source information, return null.
    }
    return null;
}
 
Example #17
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a list of frames which should be popped in the given threads.
 */
private List<StackFrame> getAffectedFrames(List<ThreadReference> threads, List<String> replacedClassNames)
        throws DebugException {
    List<StackFrame> popFrames = new ArrayList<>();
    for (ThreadReference thread : threads) {
        if (thread.isSuspended()) {
            StackFrame affectedFrame = getAffectedFrame(thread, replacedClassNames);
            if (affectedFrame == null) {
                // No frame to drop to in this thread
                continue;
            }
            if (supportsDropToFrame(thread, affectedFrame)) {
                popFrames.add(affectedFrame);
            }
        }
    }
    return popFrames;
}
 
Example #18
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private boolean containsChangedType(StackFrame frame, List<String> replacedClassNames) throws DebugException {
    String declaringTypeName = JdtUtils.getDeclaringTypeName(frame);
    // Check if the frame's declaring type was changed
    if (replacedClassNames.contains(declaringTypeName)) {
        return true;
    }
    // Check if one of the frame's declaring type's inner classes have
    // changed
    for (String className : replacedClassNames) {
        int index = className.indexOf('$');
        if (index > -1 && declaringTypeName.equals(className.substring(0, index))) {
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
private boolean containsObsoleteMethods() throws DebugException {
    List<ThreadReference> threads = currentDebugSession.getAllThreads();
    for (ThreadReference thread : threads) {
        if (!thread.isSuspended()) {
            continue;
        }
        List<StackFrame> frames = getStackFrames(thread, true);
        if (frames == null || frames.isEmpty()) {
            continue;
        }
        for (StackFrame frame : frames) {
            if (StackFrameUtility.isObsolete(frame)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #20
Source File: GetUninitializedStringValue.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #21
Source File: GetUninitializedStringValue.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/********** test core **********/

    protected void runTests()
        throws Exception
    {
        /*
         * Run to String.<init>
         */
        startUp("GetUninitializedStringValueTarg");
        BreakpointEvent bpe = resumeTo("java.lang.String", "<init>", "(Ljava/lang/String;)V");

        /*
         * We've arrived. Look at 'this' - it will be uninitialized (the value field will not be set yet).
         */
        StackFrame frame = bpe.thread().frame(0);
        StringReference sr = (StringReference)frame.thisObject();
        if (!sr.value().equals("")) {
            throw new Exception("Unexpected value for the uninitialized String");
        }

        /*
         * resume the target listening for events
         */
        listenUntilVMDisconnect();
    }
 
Example #22
Source File: ThreadInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #23
Source File: ThreadInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #24
Source File: ThreadInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #25
Source File: ThreadInfo.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #26
Source File: Evaluator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates the context, do not call directly */
public Context(Lookup context) {
    this.callStackFrame = context.lookup(CallStackFrame.class);
    this.contextVariable = context.lookup(ObjectVariable.class);
    this.stackFrame = context.lookup(StackFrame.class);
    this.stackDepth = context.lookup(Integer.class);
    this.contextObject = context.lookup(ObjectReference.class);
    this.methodToBeInvokedNotifier = context.lookup(Runnable.class);
}
 
Example #27
Source File: DebugExecutionEnvironment.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean sendStopUserCode() throws IllegalStateException {
    if (closed) {
        return false;
    }
    vm.suspend();
    try {
        ObjectReference myRef = getAgentObjectReference();

        OUTER:
        for (ThreadReference thread : vm.allThreads()) {
            // could also tag the thread (e.g. using name), to find it easier
            AGENT: for (StackFrame frame : thread.frames()) {
                if (REMOTE_AGENT_CLASS.equals(frame.location().declaringType().name())) {
                    String n = frame.location().method().name();
                    if (AGENT_INVOKE_METHOD.equals(n) || AGENT_VARVALUE_METHOD.equals(n)) {
                        ObjectReference thiz = frame.thisObject();
                        if (myRef != null && myRef != thiz) {
                            break AGENT;
                        }
                        if (((BooleanValue) thiz.getValue(thiz.referenceType().fieldByName("inClientCode"))).value()) {
                            thiz.setValue(thiz.referenceType().fieldByName("expectingStop"), vm.mirrorOf(true));
                            ObjectReference stopInstance = (ObjectReference) thiz.getValue(thiz.referenceType().fieldByName("stopException"));
                            vm.resume();
                            thread.stop(stopInstance);
                            thiz.setValue(thiz.referenceType().fieldByName("expectingStop"), vm.mirrorOf(false));
                        }
                        return true;
                    }
                }
            }
        }
    } catch (ClassNotLoadedException | IncompatibleThreadStateException | InvalidTypeException ex) {
        throw new IllegalStateException(ex);
    } finally {
        vm.resume();
    }
    return false;
}
 
Example #28
Source File: TreeEvaluator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int indexOf(List<StackFrame> frames, StackFrame frame) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, InvalidStackFrameExceptionWrapper {
    int n = frames.size();
    Location loc = StackFrameWrapper.location(frame);
    for (int i = 0; i < n; i++) {
        if (loc.equals(StackFrameWrapper.location(frames.get(i)))) return i;
    }
    return -1;
}
 
Example #29
Source File: ThreadInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}
 
Example #30
Source File: ThreadInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current stackframe.
 *
 * @return the current stackframe.
 */
StackFrame getCurrentFrame() throws IncompatibleThreadStateException {
    if (thread.frameCount() == 0) {
        return null;
    }
    return thread.frame(currentFrameIndex);
}