Added support for evaluating references (ie, expressions in braces, addresses in brackets)

This commit is contained in:
Jeff Parsons 2015-08-20 09:47:07 -07:00
commit fb62277ea0

View file

@ -2540,6 +2540,12 @@ if (DEBUGGER) {
* @return {string} * @return {string}
*/ */
Debugger.prototype.replaceRegs = function(s) { Debugger.prototype.replaceRegs = function(s) {
/*
* Replace any references first; this means that register references inside the reference
* do NOT need to be prefixed with '%'.
*/
s = this.parseReference(s);
/* /*
* Replace every %XX (or %XXX), where XX (or XXX) is a register, with the register's value. * Replace every %XX (or %XXX), where XX (or XXX) is a register, with the register's value.
*/ */
@ -4460,7 +4466,12 @@ if (DEBUGGER) {
*/ */
Debugger.prototype.parseExpression = function(sExp, fPrint) Debugger.prototype.parseExpression = function(sExp, fPrint)
{ {
var i = 0, value; var value;
if (sExp) {
sExp = this.parseReference(sExp);
var i = 0;
var fError = false; var fError = false;
var sExpOrig = sExp; var sExpOrig = sExp;
var aVals = [], aOps = []; var aVals = [], aOps = [];
@ -4508,9 +4519,36 @@ if (DEBUGGER) {
} else { } else {
if (fPrint) this.println("error parsing '" + sExpOrig + "' at character " + (sExpOrig.length - sExp.length)); if (fPrint) this.println("error parsing '" + sExpOrig + "' at character " + (sExpOrig.length - sExp.length));
} }
}
return value; return value;
}; };
/**
* parseReference(sValue)
*
* Returns the given string with any "{expression}" sequences replaced with the value of the expression,
* and any "[address]" references replaced with the contents of the address. Expressions are parsed BEFORE
* addresses.
*
* @this {Debugger}
* @param {string} sValue
* @return {string}
*/
Debugger.prototype.parseReference = function(sValue)
{
var a;
while (a = sValue.match(/\{(.*)\}/)) {
var value = this.parseExpression(a[1]);
sValue = sValue.replace('{' + a[1] + '}', value != null? str.toHex(value) : "undefined");
}
while (a = sValue.match(/\[(.*)\]/)) {
var sAddr = this.parseReference(a[1]); // take care of any inner references, too
var dbgAddr = this.parseAddr(sAddr);
sValue = sValue.replace('[' + a[1] + ']', dbgAddr? str.toHex(this.getWord(dbgAddr), dbgAddr.fData32? 8 : 4) : "undefined");
}
return sValue;
};
/** /**
* parseValue(sValue, sName, fQuiet) * parseValue(sValue, sName, fQuiet)
* *