Debuggers need to handle negative values a bit better

This commit is contained in:
Jeff 2017-03-08 16:48:25 -08:00 committed by Jeff Parsons
commit 70cd954974
7 changed files with 204 additions and 161 deletions

View file

@ -90,6 +90,7 @@ class DebuggerPDP10 extends Debugger {
*/
this.fInit = false;
this.fParens = true;
this.nBusWidth = 18; // default value, updated by initBus()
/*
* Most commands that require an address call parseAddr(), and if a dbgAddr parameter is supplied
@ -315,6 +316,7 @@ class DebuggerPDP10 extends Debugger {
this.cmp = cmp;
this.cpu = cpu;
this.panel = cmp.panel;
this.nBusWidth = bus.getWidth();
/*
* Re-initialize Debugger message support if necessary
@ -527,6 +529,7 @@ class DebuggerPDP10 extends Debugger {
addr = this.parseExpression(sAddr, fPrint);
}
if (addr != null) {
addr = this.validateWord(addr, this.nBusWidth);
this.setAddr(dbgAddr, addr, fPhysical, nBase);
}
return dbgAddr;
@ -549,6 +552,31 @@ class DebuggerPDP10 extends Debugger {
}
}
/**
* validateWord(w, bits)
*
* @this {DebuggerPDP10}
* @param {number} w
* @param {number} [bits]
* @return {number}
*/
validateWord(w, bits = 36)
{
/*
* Although it's expected that most callers will supply unsigned 36-bit values, we're nice about
* converting any signed values to their unsigned (two's complement) counterpart, provided they are
* within the acceptable range. Any values outside that range will be dealt with afterward.
*/
if (w < 0 && w >= -PDP10.MIN_NEG36) {
w += PDP10.WORD_LIMIT;
}
var value = Math.trunc(Math.abs(w)) % Math.pow(2, bits);
if (DEBUG && w !== value) {
this.println("validateWord(" + Str.toOct(w) + "): out of range, truncated to " + Str.toOct(value));
}
return value;
}
/**
* incAddr(dbgAddr, inc)
*
@ -2780,14 +2808,12 @@ class DebuggerPDP10 extends Debugger {
var dbgAddr = this.parseAddr(sAddr, this.dbgAddrData);
if (!dbgAddr) return;
for (var i = 2; i < asArgs.length; i++) {
var vNew = this.parseExpression(asArgs[i]);
if (vNew === undefined) {
this.println("unknown value: " + asArgs[i]);
break;
}
this.println("changing " + this.toStrAddr(dbgAddr) + " from " + this.toStrWord(fnGet.call(this, dbgAddr)) + " to " + this.toStrWord(vNew));
var w = this.parseExpression(asArgs[i]);
if (w === undefined) break;
w = this.validateWord(w);
this.println("changing " + this.toStrAddr(dbgAddr) + " from " + this.toStrWord(fnGet.call(this, dbgAddr)) + " to " + this.toStrWord(w));
//noinspection JSUnresolvedFunction
fnSet.call(this, dbgAddr, vNew, 1);
fnSet.call(this, dbgAddr, w, 1);
}
}
@ -3679,7 +3705,7 @@ class DebuggerPDP10 extends Debugger {
}
}
} catch(e) {
this.println("debugger error: " + (e.stack || e.message));
this.println("Debugger " + (e.stack || e.message));
result = false;
}
return result;