aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2019-02-03 14:26:18 -0500
committerAustin Adams <git@austinjadams.com>2019-02-03 14:26:18 -0500
commitc53c83df5fbfec93d8d45bbda8e391fbc590121a (patch)
treeb3dd67cec635bf10ab647185564aeec8c5054b09
parent653097769b59eec970ddd0cb6ff85a39beaadcf3 (diff)
downloadnovice-c53c83df5fbfec93d8d45bbda8e391fbc590121a.tar.gz
novice-c53c83df5fbfec93d8d45bbda8e391fbc590121a.tar.xz
Accept labels as breakpoints
-rw-r--r--novice/simulator/cli-debugger.test.ts28
-rw-r--r--novice/simulator/cli-debugger.ts5
2 files changed, 30 insertions, 3 deletions
diff --git a/novice/simulator/cli-debugger.test.ts b/novice/simulator/cli-debugger.test.ts
index c1c0c31..86eb0b6 100644
--- a/novice/simulator/cli-debugger.test.ts
+++ b/novice/simulator/cli-debugger.test.ts
@@ -155,12 +155,12 @@ describe('cli debugger', () => {
expect(mockInterface.close.mock.calls).toEqual([[]]);
});
- it('errors on label breakpoint', () => {
+ it('does not show state again after an error (bogus breakpoint)', () => {
runCmd('b asdf');
runCmd('q');
return dbg.run().then(() => {
- expect(stdoutActual).toMatch('not yet implemented');
+ expect(stdoutActual).toMatch('unknown label `asdf\'');
// Don't print state again after an error
expect(stdoutActual).not.toMatch(/==>[^]+==>/);
});
@@ -203,6 +203,30 @@ describe('cli debugger', () => {
});
});
+ it('breakpoints with labels, continue work', () => {
+ dbg.store(0x3000, 0x5020); // and r0, r0, 0
+ dbg.store(0x3001, 0x1023); // add r0, r0, 3
+ dbg.store(0x3002, 0x5220); // and r1, r0, 0
+ dbg.store(0x3003, 0x1264); // add r1, r1, 4
+ dbg.store(0x3004, 0xf025); // halt
+
+ Object.assign(dbg.getSymbTable(), {
+ tim_brown: 0x3002
+ });
+
+ runCmd('b tim_brown');
+ runCmd('c');
+ runCmd('c');
+ runCmd('q');
+
+ return dbg.run().then(() => {
+ expect(stdoutActual).toMatch('breakpoint set at 0x3002');
+ expect(stdoutActual).toMatch(/==> 0x3000[^]+==> 0x3002[^]+==> 0x3004/);
+ expect(stdoutActual).toMatch(/r0: 0x0000[^]+r0: 0x0003[^]+r0: 0x0003/);
+ expect(stdoutActual).toMatch(/r1: 0x0000[^]+r1: 0x0000[^]+r1: 0x0004/);
+ });
+ });
+
it('puts works', () => {
dbg.store(0x3000, 0xe002); // lea r0, message
dbg.store(0x3001, 0xf022); // puts
diff --git a/novice/simulator/cli-debugger.ts b/novice/simulator/cli-debugger.ts
index cf46e7b..03d861d 100644
--- a/novice/simulator/cli-debugger.ts
+++ b/novice/simulator/cli-debugger.ts
@@ -178,7 +178,10 @@ class CliDebugger extends Debugger {
/\d+/.test(operand) ? 10 : -1;
let addr: number;
if (base === -1) {
- throw new Error('labels not yet implemented sorry');
+ if (!(operand in this.symbTable)) {
+ throw new Error(`unknown label \`${operand}'`);
+ }
+ addr = this.symbTable[operand];
} else {
addr = parseInt(operand, base);
}