use of flash.tools.debugger.Watch 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"));
}
}
use of flash.tools.debugger.Watch in project intellij-plugins by JetBrains.
the class DebugCLI method missingWatchpointIndexOf.
/**
* Locate the index of a WatchAction that does not
* have a corresponding Watch in the given list.
*
* WARNING: this call can be very expensive but
* it is assumed that a.list and watchpointCount()
* are both small.
*/
int missingWatchpointIndexOf(Watch[] a) {
int size = watchpointCount();
int at = -1;
for (int i = 0; i < size && at < 0; i++) {
WatchAction action = watchpointAt(i);
Watch w = action.getWatch();
// now scan the list of watches looking for a hit
int hit = -1;
for (int j = 0; j < a.length && hit < 0; j++) {
if (w == a[j])
hit = j;
}
// watchpoint in list of session watches.
if (hit < 0)
at = i;
}
return at;
}