Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.api.debug;
import com.oracle.truffle.api.TruffleException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.oracle.truffle.api.instrumentation.TruffleInstrument;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.KeyInfo;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.nodes.LanguageInfo;
import com.oracle.truffle.api.source.SourceSection;
/**
* Represents a value accessed using the debugger API. Please note that values can become invalid
* depending on the context in which they are used. For example stack values will only remain valid
* as long as the current stack element is active. Heap values on the other hand remain valid. If a
* value becomes invalid then setting or getting a value will throw an {@link IllegalStateException}
* . {@link DebugValue} instances neither support equality or preserve identity.
*
* Clients may access the debug value only on the execution thread where the suspended event of the
* stack frame was created and notification received; access from other threads will throw
* {@link IllegalStateException}.
*
* @since 0.17
*/
public abstract class DebugValue {
final LanguageInfo preferredLanguage;
abstract Object get() throws DebugException;
DebugValue(LanguageInfo preferredLanguage) {
this.preferredLanguage = preferredLanguage;
}
/**
* Sets the value using another {@link DebugValue}. Throws an {@link IllegalStateException} if
* the value is not writable, the passed value is not readable, this value or the passed value
* is invalid, or the guest language of the values do not match. Use
* {@link DebugStackFrame#eval(String)} to evaluate values to be set.
*
* @param value the value to set
* @throws DebugException when guest language code throws an exception
* @since 0.17
*/
public abstract void set(DebugValue value) throws DebugException;
/**
* Sets a primitive value. Strings and boxed Java primitive types are considered primitive.
* Throws an {@link IllegalStateException} if the value is not writable and
* {@link IllegalArgumentException} if the value is not primitive.
*
* @param primitiveValue a primitive value to set
* @throws DebugException when guest language code throws an exception
* @since 1.0
*/
public abstract void set(Object primitiveValue) throws DebugException;
/**
* Converts the debug value into a Java type. Class conversions which are always supported:
*
*
{@link String}.class converts the value to its language specific string representation.
*
*
{@link Number}.class converts the value to a Number representation, if any.
*
{@link Boolean}.class converts the value to a Boolean representation, if any.
*
* No optional conversions are currently available. If a conversion is not supported then an
* {@link UnsupportedOperationException} is thrown. If the value is not {@link #isReadable()
* readable} then an {@link IllegalStateException} is thrown.
*
* @param clazz the type to convert to
* @return the converted Java type, or null when the conversion was not possible.
* @throws DebugException when guest language code throws an exception
* @since 0.17
*/
public abstract T as(Class clazz) throws DebugException;
/**
* Returns the name of this value as it is referred to from its origin. If this value is
* originated from the stack it returns the name of the local variable. If the value was
* returned from another objects then it returns the name of the property or field it is
* contained in. If no name is available null is returned.
*
* @since 0.17
*/
public abstract String getName();
/**
* Returns true if this value can be read else false.
*
* @see #as(Class)
* @since 0.17
*/
public abstract boolean isReadable();
/**
* Returns true if this value can be read else false.
*
* @see #as(Class)
* @since 0.17
* @deprecated Use {@link #isWritable()}
*/
@Deprecated
public final boolean isWriteable() {
return isWritable();
}
/**
* Returns true if this value can be written to, else false.
*
* @see #as(Class)
* @since 0.26
*/
public abstract boolean isWritable();
/**
* Returns true if this value represents an internal variable or property,
* false otherwise.
*
* Languages might have extra object properties or extra scope variables that are a part of the
* runtime, but do not correspond to anything what is an explicit part of the guest language
* representation. They may represent additional language artifacts, providing more in-depth
* information that can be valuable during debugging. Language implementors mark these variables
* as internal. An example of such internal values are internal slots in ECMAScript.
*
*
* @since 0.26
*/
public abstract boolean isInternal();
/**
* Get the scope where this value is declared in. It returns a non-null value for local
* variables declared on a stack. It's null for object properties and other heap
* values.
*
* @return the scope, or null when this value does not belong into any scope.
*
* @since 0.26
*/
public DebugScope getScope() {
return null;
}
/**
* Provides properties representing an internal structure of this value. The returned collection
* is not thread-safe. If the value is not {@link #isReadable() readable} then an
* {@link IllegalStateException} is thrown.
*
* @return a collection of property values, or null when the value does not have
* any concept of properties.
* @throws DebugException when guest language code throws an exception
* @throws IllegalStateException if the value is not {@link #isReadable() readable}
* @since 0.19
*/
public final Collection getProperties() throws DebugException {
if (!isReadable()) {
throw new IllegalStateException("Value is not readable");
}
Object value = get();
try {
return getProperties(value, getDebugger(), resolveLanguage(), null);
} catch (Throwable ex) {
if (ex instanceof TruffleException) {
throw new DebugException(getDebugger(), (TruffleException) ex, resolveLanguage(), null, true, null);
} else {
throw ex;
}
}
}
static ValuePropertiesCollection getProperties(Object value, Debugger debugger, LanguageInfo language, DebugScope scope) {
ValuePropertiesCollection properties = null;
if (value instanceof TruffleObject) {
TruffleObject object = (TruffleObject) value;
Map