use of flash.tools.debugger.Value in project vscode-nextgenas by BowlerHatLLC.
the class SWFDebugSession method variables.
public void variables(Response response, VariablesRequest.VariablesArguments arguments) {
List<Variable> variables = new ArrayList<>();
try {
Value swfValue = null;
long variablesReference = arguments.variablesReference;
int frameId = -1;
if (variablesReference < 1000) {
frameId = (int) variablesReference / 10;
variablesReference -= frameId * 10;
}
flash.tools.debugger.Variable[] members = null;
if (variablesReference == LOCAL_VARIABLES_REFERENCE) {
Frame[] swfFrames = swfSession.getFrames();
if (frameId >= 0 && frameId < swfFrames.length) {
Frame swfFrame = swfFrames[frameId];
flash.tools.debugger.Variable[] args = swfFrame.getArguments(swfSession);
flash.tools.debugger.Variable[] locals = swfFrame.getLocals(swfSession);
flash.tools.debugger.Variable swfThis = swfFrame.getThis(swfSession);
int memberCount = locals.length + args.length;
int offset = 0;
if (swfThis != null) {
offset = 1;
}
members = new flash.tools.debugger.Variable[memberCount + offset];
if (swfThis != null) {
members[0] = swfThis;
}
System.arraycopy(args, 0, members, offset, args.length);
System.arraycopy(locals, 0, members, args.length + offset, locals.length);
} else {
members = new flash.tools.debugger.Variable[0];
}
} else {
swfValue = swfSession.getValue(arguments.variablesReference);
members = swfValue.getMembers(swfSession);
}
for (flash.tools.debugger.Variable member : members) {
Value memberValue = member.getValue();
Variable variable = new Variable();
variable.name = member.getName();
variable.type = memberValue.getTypeName();
long id = memberValue.getId();
if (id != Value.UNKNOWN_ID) {
variable.value = memberValue.getTypeName();
variable.variablesReference = memberValue.getId();
} else {
if (memberValue.getType() == VariableType.STRING) {
variable.value = "\"" + memberValue.getValueAsString() + "\"";
} else {
variable.value = memberValue.getValueAsString();
}
}
variables.add(variable);
}
} catch (PlayerDebugException e) {
//ignore
}
sendResponse(response, new VariablesResponseBody(variables));
}
use of flash.tools.debugger.Value in project intellij-plugins by JetBrains.
the class ExpressionCache method appendVariableValue.
/**
* Given any arbitrary constant value, such as a Double, a String, etc.,
* format its value appropriately. For example, strings will be quoted.
*
* @param sb
* a StringBuilder to which the formatted value will be appended.
* @param o
* the value to format.
*/
public static void appendVariableValue(StringBuilder sb, final Object o) {
Value v;
if (o instanceof Value) {
v = (Value) o;
} else {
v = new Value() {
public int getAttributes() {
return 0;
}
public String[] getClassHierarchy(boolean allLevels) {
return new String[0];
}
public String getClassName() {
//$NON-NLS-1$
return "";
}
public long getId() {
return UNKNOWN_ID;
}
public int getMemberCount(Session s) throws NotSuspendedException, NoResponseException, NotConnectedException {
return 0;
}
public Variable getMemberNamed(Session s, String name) throws NotSuspendedException, NoResponseException, NotConnectedException {
return null;
}
public Variable[] getMembers(Session s) throws NotSuspendedException, NoResponseException, NotConnectedException {
return new Variable[0];
}
public int getType() {
if (o instanceof Number)
return VariableType.NUMBER;
else if (o instanceof Boolean)
return VariableType.BOOLEAN;
else if (o instanceof String)
return VariableType.STRING;
else if (o == Value.UNDEFINED)
return VariableType.UNDEFINED;
else if (o == null)
return VariableType.NULL;
assert false;
return VariableType.UNKNOWN;
}
public String getTypeName() {
//$NON-NLS-1$
return "";
}
public Object getValueAsObject() {
return o;
}
public String getValueAsString() {
return DValue.getValueAsString(o);
}
public boolean isAttributeSet(int variableAttribute) {
return false;
}
public Variable[] getPrivateInheritedMembers() {
return new Variable[0];
}
public Variable[] getPrivateInheritedMemberNamed(String name) {
return new Variable[0];
}
};
}
appendVariableValue(sb, v);
}
use of flash.tools.debugger.Value in project intellij-plugins by JetBrains.
the class DebugCLI method processDisplay.
// iterate through our display list entries
void processDisplay(StringBuffer sb) {
int count = displayCount();
for (int i = 0; i < count; i++) {
DisplayAction a = displayAt(i);
if (a.isEnabled()) {
try {
sb.append(a.getId());
//$NON-NLS-1$
sb.append(": ");
sb.append(a.getContent());
//$NON-NLS-1$
sb.append(" = ");
// command[0] contains our expression, so first we parse it, evalulate it then print it
Object result = m_exprCache.evaluate(a.getExpression());
if (result instanceof Variable)
ExpressionCache.appendVariableValue(sb, ((Variable) result).getValue());
else if (result instanceof Value)
ExpressionCache.appendVariableValue(sb, (Value) result);
else if (result instanceof InternalProperty)
sb.append(((InternalProperty) result).valueOf());
else
sb.append(result);
sb.append(m_newline);
} catch (NoSuchVariableException nsv) {
Map args = new HashMap();
//$NON-NLS-1$
args.put("variable", nsv.getMessage());
//$NON-NLS-1$
sb.append(getLocalizationManager().getLocalizedTextString("variableUnknown", args));
sb.append(m_newline);
} catch (NumberFormatException nfe) {
Map args = new HashMap();
//$NON-NLS-1$
args.put("value", nfe.getMessage());
//$NON-NLS-1$
sb.append(getLocalizationManager().getLocalizedTextString("couldNotConvertToNumber", args));
sb.append(m_newline);
} catch (PlayerFaultException pfe) {
sb.append(pfe.getMessage() + m_newline);
} catch (NullPointerException npe) {
//$NON-NLS-1$
sb.append(getLocalizationManager().getLocalizedTextString("couldNotEvaluate"));
}
}
}
}
use of flash.tools.debugger.Value in project intellij-plugins by JetBrains.
the class DebugCLI method doCatch.
private void doCatch() throws NotConnectedException, NotSuspendedException, NoResponseException {
/* wait a bit if we are not halted */
waitTilHalted();
String typeToCatch = null;
/* currentXXX may NOT be invalid! */
if (!hasMoreTokens()) {
err("Catch requires an exception name.");
return;
}
typeToCatch = nextToken();
if (typeToCatch == null || typeToCatch.length() == 0) {
err("Illegal argument");
return;
}
Value type = null;
if (//$NON-NLS-1$
typeToCatch.equals("*")) {
typeToCatch = null;
} else {
type = getSession().getGlobal(typeToCatch);
if (type == null) {
err("Type not found.");
return;
}
String typeName = type.getTypeName();
int at = typeName.indexOf('@');
if (at != -1)
typeName = typeName.substring(0, at);
if (!typeName.endsWith("$")) {
err("Not a type: " + type);
return;
}
}
CatchAction c;
try {
c = addCatch(typeToCatch);
} catch (NotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
Map<String, Object> args = new HashMap<String, Object>();
//$NON-NLS-1$
args.put("id", c.getId());
c.getId();
}
use of flash.tools.debugger.Value in project intellij-plugins by JetBrains.
the class DebugCLI method doWatch.
/**
* Request to add a new watchpoint
* This may result in one of two things happening
* (1) a new watchpoint could be added or
* (2) an existing watchpoint may be modified.
*
* The watch, awatch, and rwatch commands will set a watchpoint on the
* given expression. The different commands control the read/write aspect
* of the watchpoint.
*
* awatch will trigger a break if the expression is read or written.
* rwatch will trigger a break if the expression is read.
* watch will trigger a break if the expression is written.
*/
void doWatch(boolean read, boolean write) throws PlayerDebugException {
try {
if (read) {
err("Only break-on-write watchpoints are supported.");
return;
}
StringBuilder sb = new StringBuilder();
/* pull the rest of the line */
String s = restOfLine();
int flags = 3;
if (read && write)
flags = WatchKind.READWRITE;
else if (read)
flags = WatchKind.READ;
else if (write)
flags = WatchKind.WRITE;
// snapshot of our existing list
Watch[] list = m_session.getWatchList();
// We need to separate the front part the 'a.b' in 'a.b.c'
// of the expression to resolve it into a variable
// We usually get back a VariableFacade which contains
// the context id (i.e the variable id) and the member name.
ValueExp expr = parseExpression(s);
VariableFacade result = (VariableFacade) (evalExpression(expr).value);
// extract the 2 pieces and get the raw variable.
// TODO fix this??? -mike
int varId = result.getContext();
String memberName = result.getName();
Value v = m_session.getValue(varId);
// attempt to set.
Watch w = m_session.setWatch(v, memberName, flags);
if (w == null) {
// failed
Map<String, Object> args = new HashMap<String, Object>();
//$NON-NLS-1$
args.put("expression", s);
//$NON-NLS-1$
err(getLocalizationManager().getLocalizedTextString("watchpointCouldNotBeSet", args));
} else {
// if modified then lists are same length
// otherwise 1 will be added
Watch[] newList = m_session.getWatchList();
if (newList.length == list.length) {
// modified, lets locate the one that changed
// and reset it
int at = missingWatchpointIndexOf(newList);
WatchAction a = null;
try {
a = watchpointAt(at);
} catch (ArrayIndexOutOfBoundsException aio) {
// this is pretty bad it means the player thinks we have a watchpoint
// but we don't have a record of it. So let's create a new one
// and hope that we are now in sync with the player.
a = new WatchAction(w);
}
// modify our view of the watchpoint
int id = a.getId();
a.resetWatch(w);
Map<String, Object> args = new HashMap<String, Object>();
//$NON-NLS-1$
args.put("watchpointNumber", Integer.toString(id));
//$NON-NLS-1$
args.put("expression", s);
//$NON-NLS-1$
args.put("watchpointMode", getWatchpointModeString(a.getKind()));
//$NON-NLS-1$
sb.append(getLocalizationManager().getLocalizedTextString("changedWatchpointMode", args));
} else {
// newly added
WatchAction a = new WatchAction(w);
watchpointAdd(a);
int which = a.getId();
Map<String, Object> args = new HashMap<String, Object>();
//$NON-NLS-1$
args.put("watchpointNumber", Integer.toString(which));
//$NON-NLS-1$
args.put("expression", s);
//$NON-NLS-1$
sb.append(getLocalizationManager().getLocalizedTextString("createdWatchpoint", args));
}
out(sb.toString());
}
} catch (ArrayIndexOutOfBoundsException aio) {
// We should really do some cleanup after this exception
// since it most likely means we can't find the watchpoint
// that was just modified, therefore our watchlists are
// out of sync with those of the API.
//$NON-NLS-1$
err(getLocalizationManager().getLocalizedTextString("badWatchpointNumber"));
} catch (NullPointerException npe) {
//$NON-NLS-1$
err(getLocalizationManager().getLocalizedTextString("couldNotEvaluate"));
} catch (ClassCastException cce) {
//$NON-NLS-1$
err(getLocalizationManager().getLocalizedTextString("couldNotResolveExpression"));
}
}
Aggregations