Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Fix app state not being properly reset when stepping back
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos committed Jan 4, 2024
1 parent ea323d2 commit 34aa408
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/common/traceReplayEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ export class ProgramStackFrame extends TraceReplayStackFrame {
if (typeof this.initialAppState !== 'undefined') {
this.engine.currentAppState.set(
this.currentAppID()!,
this.initialAppState,
this.initialAppState.clone(),
);
}
}
Expand Down
101 changes: 101 additions & 0 deletions tests/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,35 @@ describe('Debug Adapter Tests', () => {
},
],
});

// Move to the end of the program
await advanceTo(client, { program: PROGRAM, line: 46 });

// Step back to the beginning of the program
for (;;) {
const stackTraceResponse = await client.stackTraceRequest({
threadId: 1,
});
const currentFrame = stackTraceResponse.body.stackFrames[0];
if (currentFrame.source?.path === PROGRAM && currentFrame.line === 3) {
break;
}
await client.stepBackRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');
}

// Ensure that the global state at the beginning does not show changes that will happen later
await assertVariables(client, {
pc: 6,
stack: [1050],
apps: [
{
appID: 1050,
globalState: new ByteArrayMap(),
},
],
});
});
});

Expand Down Expand Up @@ -1535,6 +1564,41 @@ describe('Debug Adapter Tests', () => {
},
],
});

// Move to the end of the program
await advanceTo(client, { program: PROGRAM, line: 46 });

// Step back to the beginning of the program
for (;;) {
const stackTraceResponse = await client.stackTraceRequest({
threadId: 1,
});
const currentFrame = stackTraceResponse.body.stackFrames[0];
if (currentFrame.source?.path === PROGRAM && currentFrame.line === 3) {
break;
}
await client.stepBackRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');
}

// Ensure that the local state at the beginning does not show changes that will happen later
await assertVariables(client, {
pc: 6,
stack: [1054],
apps: [
{
appID: 1054,
localState: [
{
account:
'YGOSQB6R5IVQDJHJUHTIZAJNWNIT7VLMWHXFWY2H5HMWPK7QOPXHELNPJ4',
state: new ByteArrayMap(),
},
],
},
],
});
});
});

Expand Down Expand Up @@ -1632,6 +1696,43 @@ describe('Debug Adapter Tests', () => {
},
],
});

// Clear breakpoints -- must do because the 'next' request is on line 46 as well
await client.setBreakpointsRequest({
source: { path: PROGRAM },
breakpoints: [],
});

// Move to the end of the program
await client.nextRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');

// Step back to the beginning of the program
for (;;) {
const stackTraceResponse = await client.stackTraceRequest({
threadId: 1,
});
const currentFrame = stackTraceResponse.body.stackFrames[0];
if (currentFrame.source?.path === PROGRAM && currentFrame.line === 3) {
break;
}
await client.stepBackRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');
}

// Ensure that the local state at the beginning does not show changes that will happen later
await assertVariables(client, {
pc: 6,
stack: [1058],
apps: [
{
appID: 1058,
boxState: new ByteArrayMap(),
},
],
});
});
});

Expand Down

0 comments on commit 34aa408

Please sign in to comment.