com.sun.jdi.StringReference Java Examples

The following examples show how to use com.sun.jdi.StringReference. 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 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: EvaluatorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (!(obj instanceof JDIValue)) return false;
    Value v = ((JDIValue) obj).value;
    if (value == null) return v == null;
    if (value instanceof StringReference) {
        if (!(v instanceof StringReference)) return false;
        return ((StringReference) value).value().equals(((StringReference) v).value());
    }
    if (value instanceof ArrayReference) {
        if (!(v instanceof ArrayReference)) return false;
        ArrayReference a1 = (ArrayReference) value;
        ArrayReference a2 = (ArrayReference) v;
        if (!a1.type().equals(a2.type())) return false;
        if (a1.length() != a2.length()) return false;
        int n = a1.length();
        for (int i = 0; i < n; i++) {
            if (!new JDIValue(a1.getValue(i)).equals(new JDIValue(a2.getValue(i)))) {
                return false;
            }
        }
        return true;
    }
    return value.equals(v);
}
 
Example #12
Source File: InvocationExceptionTranslated.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getMessageFromField() throws InternalExceptionWrapper,
                                            VMDisconnectedExceptionWrapper,
                                            ObjectCollectedExceptionWrapper,
                                            ClassNotPreparedExceptionWrapper {
    List<ReferenceType> throwableClasses = VirtualMachineWrapper.classesByName(exeption.virtualMachine(), Throwable.class.getName());
    if (throwableClasses.isEmpty()) {
        return null;
    }
    Field detailMessageField = ReferenceTypeWrapper.fieldByName(throwableClasses.get(0), "detailMessage");
    if (detailMessageField != null) {
        Value messageValue = ObjectReferenceWrapper.getValue(exeption, detailMessageField);
        if (messageValue instanceof StringReference) {
            message = StringReferenceWrapper.value((StringReference) messageValue);
            if (invocationMessage != null) {
                return invocationMessage + ": " + message;
            } else {
                return message;
            }
        }
    }
    return null;
}
 
Example #13
Source File: JPDAThreadImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Variable getPendingVariable(Object action) {
    Variable var;
    synchronized (pendingActionsLock) {
        var = (action == pendingAction) ? pendingVariable : null;
    }
    if (var == null) {
        StringReference sr = threadReference.virtualMachine().mirrorOf(getPendingString(action));
        var = new AbstractObjectVariable (debugger, sr, null);
    }
    synchronized (pendingActionsLock) {
        if (action == pendingAction) {
            pendingVariable = var;
        }
    }
    return var;
}
 
Example #14
Source File: GetUninitializedStringValue.java    From dragonwell8_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 #15
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 #16
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 #17
Source File: Source.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Source getTheSource(JPDADebugger debugger, long id,
                                   String name,
                                   String path,
                                   URI uri,
                                   StringReference codeRef) {
    
    Source src = new Source(debugger, name, uri, id, codeRef);
    synchronized (KNOWN_SOURCES) {
        Map<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger);
        if (dbgSources == null) {
            dbgSources = new HashMap<>();
            KNOWN_SOURCES.put(debugger, dbgSources);
        }
        dbgSources.put(id, src);
    }
    return src;
}
 
Example #18
Source File: Source.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static Source getSource(JPDADebugger debugger, long id,
                               String name,
                               String path,
                               URI uri,
                               StringReference codeRef) {
    synchronized (KNOWN_SOURCES) {
        Map<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger);
        if (dbgSources != null) {
            Source src = dbgSources.get(id);
            if (src != null) {
                return src;
            }
        }
    }
    return getTheSource(debugger, id, name, path, uri, codeRef);
}
 
Example #19
Source File: TruffleAccess.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static SourcePosition getSourcePosition(JPDADebugger debugger, ObjectVariable sourcePositionVar) {
    Field varSrcId = sourcePositionVar.getField(VAR_SRC_ID);
    if (varSrcId == null) {
        // sourcePositionVar represents null
        return null;
    }
    long id = (Long) varSrcId.createMirrorObject();
    String sourceSection = (String) sourcePositionVar.getField(VAR_SRC_SOURCESECTION).createMirrorObject();
    Source src = Source.getExistingSource(debugger, id);
    if (src == null) {
        String name = (String) sourcePositionVar.getField(VAR_SRC_NAME).createMirrorObject();
        String path = (String) sourcePositionVar.getField(VAR_SRC_PATH).createMirrorObject();
        URI uri = (URI) sourcePositionVar.getField(VAR_SRC_URI).createMirrorObject();
        StringReference codeRef = (StringReference) ((JDIVariable) sourcePositionVar.getField(VAR_SRC_CODE)).getJDIValue();
        src = Source.getSource(debugger, id, name, path, uri, codeRef);
    }
    return new SourcePosition(debugger, id, src, sourceSection);
}
 
Example #20
Source File: Source.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Source(JPDADebugger jpda, String name, URI uri, long hash, StringReference codeRef) {
    this.name = name;
    this.codeRef = codeRef;
    URL url = null;
    if (uri == null || !"file".equalsIgnoreCase(uri.getScheme())) {
        try {
            url = SourceFilesCache.get(jpda).getSourceFile(name, hash, uri, getContent());
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    if (url == null) {
        try {
            url = uri.toURL();
        } catch (MalformedURLException muex) {
            Exceptions.printStackTrace(muex);
        }
    }
    this.url = url;
    this.uri = uri;
    this.hash = hash;
}
 
Example #21
Source File: TruffleBreakpointsHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    final JSLineBreakpoint jsbp = (JSLineBreakpoint) evt.getSource();
    String propertyName = evt.getPropertyName();
    final TruffleBPMethods method;
    final List<? extends Value> args;
    final VirtualMachine vm = ((JPDADebuggerImpl) debugger).getVirtualMachine();
    if (vm == null) {
        return ;
    }
    switch (propertyName) {
        case JSLineBreakpoint.PROP_ENABLED:
            method = TruffleBPMethods.setEnabled;
            args = Collections.singletonList(vm.mirrorOf(jsbp.isEnabled()));
            break;
        case JSLineBreakpoint.PROP_CONDITION:
            method = TruffleBPMethods.setCondition;
            String condition = jsbp.getCondition();
            StringReference conditionRef = (condition != null) ? vm.mirrorOf(condition) : null;
            args = Collections.singletonList(conditionRef);
            break;
        case Breakpoint.PROP_HIT_COUNT_FILTER:
            method = TruffleBPMethods.setIgnoreCount;
            args = Collections.singletonList(vm.mirrorOf(getIgnoreCount(jsbp)));
            break;
        default:
            return ;
    }
    ((JPDADebuggerImpl) debugger).getRequestProcessor().post(new Runnable() {
        @Override
        public void run() {
            setBreakpointProperty(jsbp, method, args);
        }
    });
}
 
Example #22
Source File: VMTargetRemoteTest.java    From gravel with Apache License 2.0 5 votes vote down vote up
@Test
	public void testDNU() throws Throwable {
		ObjectReference promise = remote.evaluateForked("3 fromage");
		ThreadReference thread = ((ThreadReference) remote.invokeMethod(
				promise, "thread"));
		remote.invokeMethod(thread, "start");
		ObjectReference state = (ObjectReference) remote.invokeMethod(thread, "getState");
		StringReference str = (StringReference) remote.invokeMethod(state, "toString");
		System.out.println(str.value());
		
		printStack(thread);
//		assertFalse(thread.isSuspended());
		printThreadState();
		System.out.println("VMTargetStarter.sleep(1000)");
		VMTargetStarter.sleep(1000);
		printStack(thread);
		printThreadState();

		boolean isFinished = ((BooleanValue) remote.invokeMethod(promise,
				"isFinished")).booleanValue();

		assertFalse(isFinished);
		printThreadState();

		printStack(thread);
		assertTrue(thread.isAtBreakpoint());
	}
 
Example #23
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void retrieveScreenshots(JPDAThreadImpl t, final ThreadReference tr, VirtualMachine vm, DebuggerEngine engine, JPDADebuggerImpl d, final List<RemoteScreenshot> screenshots) throws RetrievalException {
    try {
        final ClassType windowClass = getClass(vm, tr, "javafx.stage.Window");
        
        Method getWindows = windowClass.concreteMethodByName("impl_getWindows", "()Ljava/util/Iterator;");
        Method windowName = windowClass.concreteMethodByName("impl_getMXWindowType", "()Ljava/lang/String;");

        ObjectReference iterator = (ObjectReference)windowClass.invokeMethod(tr, getWindows, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
        ClassType iteratorClass = (ClassType)iterator.referenceType();
        Method hasNext = iteratorClass.concreteMethodByName("hasNext", "()Z");
        Method next = iteratorClass.concreteMethodByName("next", "()Ljava/lang/Object;");
        
        boolean nextFlag = false;
        do {
            BooleanValue bv = (BooleanValue)iterator.invokeMethod(tr, hasNext, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
            nextFlag = bv.booleanValue();
            if (nextFlag) {
                ObjectReference window = (ObjectReference)iterator.invokeMethod(tr, next, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                StringReference name = (StringReference)window.invokeMethod(tr, windowName, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
                SGComponentInfo windowInfo = new SGComponentInfo(t, window);
                
                screenshots.add(createRemoteFXScreenshot(engine, vm, tr, name.value(), window, windowInfo));
            }
        } while (nextFlag);
    } catch (Exception e) {
        throw new RetrievalException(e.getMessage(), e);
    }
}
 
Example #24
Source File: RemoteFXScreenshot.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ReferenceType getType(VirtualMachine vm, ThreadReference tr, String name) {
    List<ReferenceType> classList = VirtualMachineWrapper.classesByName0(vm, name);
    if (!classList.isEmpty()) {
        return classList.iterator().next();
    }
    List<ReferenceType> classClassList = VirtualMachineWrapper.classesByName0(vm, "java.lang.Class"); // NOI18N
    if (classClassList.isEmpty()) {
        throw new IllegalStateException("Cannot load class Class"); // NOI18N
    }

    ClassType cls = (ClassType) classClassList.iterator().next();
    try {
        Method m = ClassTypeWrapper.concreteMethodByName(cls, "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); // NOI18N
        StringReference mirrorOfName = VirtualMachineWrapper.mirrorOf(vm, name);
        ClassTypeWrapper.invokeMethod(cls, tr, m, Collections.singletonList(mirrorOfName), ObjectReference.INVOKE_SINGLE_THREADED);
        List<ReferenceType> classList2 = VirtualMachineWrapper.classesByName0(vm, name);
        if (!classList2.isEmpty()) {
            return classList2.iterator().next();
        }
    } catch (ClassNotLoadedException | ClassNotPreparedExceptionWrapper |
             IncompatibleThreadStateException | InvalidTypeException |
             InvocationException | InternalExceptionWrapper |
             ObjectCollectedExceptionWrapper | UnsupportedOperationExceptionWrapper |
             VMDisconnectedExceptionWrapper ex) {
        logger.log(Level.FINE, "Cannot load class " + name, ex); // NOI18N
    }
    
    return null;
}
 
Example #25
Source File: StringObjectFormatterTest.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testToString() throws Exception {
    Value string = this.getLocalValue("str");
    Map<String, Object> options = formatter.getDefaultOptions();
    options.put(MAX_STRING_LENGTH_OPTION, 4);
    assertEquals("Should be able to format string type.", "\"s...\"",
        formatter.toString(string, options));

    options.put(MAX_STRING_LENGTH_OPTION, 5);
    assertEquals("Should be able to format string type.", "\"st...\"",
        formatter.toString(string, options));
    assertTrue("Should not trim long string by default",
        formatter.toString(string, new HashMap<>()).contains(((StringReference) string).value()));
}
 
Example #26
Source File: TruffleStackInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private TruffleStackFrame[] loadStackFrames(boolean includeInternal) {
    JPDAClassType debugAccessor = TruffleDebugManager.getDebugAccessorJPDAClass(debugger);
    try {
        Variable internalVar = debugger.createMirrorVar(includeInternal, true);
        Variable framesVar = debugAccessor.invokeMethod(METHOD_GET_FRAMES_INFO,
                                                        METHOD_GET_FRAMES_INFO_SIG,
                                                        new Variable[] { stackTrace,
                                                                         internalVar });
        Field[] framesInfos = ((ObjectVariable) framesVar).getFields(0, Integer.MAX_VALUE);
        String framesDesc = (String) framesInfos[0].createMirrorObject();
        Field[] codes = ((ObjectVariable) framesInfos[1]).getFields(0, Integer.MAX_VALUE);
        Field[] thiss = ((ObjectVariable) framesInfos[2]).getFields(0, Integer.MAX_VALUE);
        areInternalFrames = false;
        if (!includeInternal) {
            areInternalFrames = (Boolean) framesInfos[3].createMirrorObject();
        }
        int i1 = 0;
        int i2;
        int depth = 1;
        List<TruffleStackFrame> truffleFrames = new ArrayList<>();
        while ((i2 = framesDesc.indexOf("\n\n", i1)) > 0) {
            StringReference codeRef = (StringReference) ((JDIVariable) codes[depth-1]).getJDIValue();
            ObjectVariable frameInstance = (ObjectVariable) stackTrace.getFields(0, Integer.MAX_VALUE)[depth - 1];
            TruffleStackFrame tsf = new TruffleStackFrame(
                    debugger, thread, depth, frameInstance, framesDesc.substring(i1, i2),
                    codeRef, null, (ObjectVariable) thiss[depth-1], includeInternal);
            truffleFrames.add(tsf);
            if (includeInternal && tsf.isInternal()) {
                areInternalFrames = true;
            }
            i1 = i2 + 2;
            depth++;
        }
        return truffleFrames.toArray(new TruffleStackFrame[truffleFrames.size()]);
    } catch (InvalidExpressionException | NoSuchMethodException | InvalidObjectException ex) {
        Exceptions.printStackTrace(ex);
        return new TruffleStackFrame[] {};
    }
}
 
Example #27
Source File: MirrorValuesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testTargetMirrors() throws Exception {
    try {
        Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src") + 
                "org/netbeans/api/debugger/jpda/testapps/MirrorValuesApp.java");
        LineBreakpoint lb = bp.getLineBreakpoints().get(0);
        dm.addBreakpoint (lb);
        
        support = JPDASupport.attach (CLASS_NAME);

        support.waitState (JPDADebugger.STATE_STOPPED);  // breakpoint hit
        
        JPDADebugger debugger = support.getDebugger();
        
        Variable mirrorVar = debugger.createMirrorVar("Test");
        Value v = ((JDIVariable) mirrorVar).getJDIValue();
        assertTrue("Value "+v+" should be a String", v instanceof StringReference);
        assertEquals("Test", ((StringReference) v).value());
        
        Point p = new Point(-1, 1);
        mirrorVar = debugger.createMirrorVar(p);
        Object mp = mirrorVar.createMirrorObject();
        assertTrue("Correct point was created: "+mp, p.equals(mp));
        
        mirrorVar = debugger.createMirrorVar(1);
        v = ((JDIVariable) mirrorVar).getJDIValue();
        assertTrue("Value "+v+" should be an Integer object.",
                   (v.type() instanceof ClassType) && Integer.class.getName().equals(((ClassType) v.type()).name()));
        
        mirrorVar = debugger.createMirrorVar(1, true);
        v = ((JDIVariable) mirrorVar).getJDIValue();
        assertTrue("Value "+v+" should be an int.", v instanceof IntegerValue);
        assertEquals(((IntegerValue) v).value(), 1);
    } finally {
        support.doFinish ();
    }
}
 
Example #28
Source File: MethodInvocationTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testTargetMirrors() throws Exception {
    try {
        Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src") + 
                "org/netbeans/api/debugger/jpda/testapps/MirrorValuesApp.java");
        LineBreakpoint lb = bp.getLineBreakpoints().get(0);
        dm.addBreakpoint (lb);
        
        support = JPDASupport.attach ("org.netbeans.api.debugger.jpda.testapps.MirrorValuesApp");

        support.waitState (JPDADebugger.STATE_STOPPED);  // breakpoint hit
        
        JPDADebugger debugger = support.getDebugger();
        
        List<JPDAClassType> systemClasses = debugger.getClassesByName("java.lang.System");
        assertEquals(systemClasses.size(), 1);
        JPDAClassType systemClass = systemClasses.get(0);
        Properties properties = System.getProperties();
        Variable propertiesVar = systemClass.invokeMethod("getProperties", "()Ljava/util/Properties;", new Variable[]{});
        Value pv = ((JDIVariable) propertiesVar).getJDIValue();
        assertTrue("Properties "+pv, (pv instanceof ObjectReference) &&
                                     Properties.class.getName().equals(((ClassType) pv.type()).name()));
        String userHomeProperty = properties.getProperty("user.home");
        Variable propVar = ((ObjectVariable) propertiesVar).invokeMethod("getProperty",
                "(Ljava/lang/String;)Ljava/lang/String;",
                new Variable[] { debugger.createMirrorVar("user.home") });
        Value p = ((JDIVariable) propVar).getJDIValue();
        assertTrue(p instanceof StringReference);
        assertEquals(userHomeProperty, ((StringReference) p).value());
    } finally {
        support.doFinish ();
    }
}
 
Example #29
Source File: AbstractVariable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static String getValue (Value v) {
    if (v == null) {
        return "null";
    }
    if (v instanceof VoidValue) {
        return "void";
    }
    if (v instanceof CharValue) {
        return "\'" + v.toString () + "\'";
    }
    if (v instanceof PrimitiveValue) {
        return v.toString ();
    }
    try {
        if (v instanceof StringReference) {
            String str = ShortenedStrings.getStringWithLengthControl((StringReference) v);
            return "\"" + str + "\"";
        }
        if (v instanceof ClassObjectReference) {
            return "class " + ReferenceTypeWrapper.name(ClassObjectReferenceWrapper.reflectedType((ClassObjectReference) v));
        }
        if (v instanceof ArrayReference) {
            return "#" + ObjectReferenceWrapper.uniqueID((ArrayReference) v) +
                "(length=" + ArrayReferenceWrapper.length((ArrayReference) v) + ")";
        }
        return "#" + ObjectReferenceWrapper.uniqueID((ObjectReference) v);
    } catch (InternalExceptionWrapper iex) {
        return "";
    } catch (ObjectCollectedExceptionWrapper oex) {
        return "";
    } catch (VMDisconnectedExceptionWrapper dex) {
        return "";
    }
}
 
Example #30
Source File: TruffleAccess.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Supplier<SourcePosition> parseSourceLazy(JPDADebugger debugger, Variable sourceDefVar, JDIVariable codeRefVar) {
    return () -> parseSource(debugger,
                             (String) sourceDefVar.createMirrorObject(),
                             (StringReference) codeRefVar.getJDIValue());
}