Skip to content

Commit

Permalink
Implement observer-based debug item value display.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Oct 8, 2024
1 parent 324949c commit ede2a3d
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 296 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"eslint.useFlatConfig": true,
"[typescript]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.removeUnusedImports": "always",
"source.fixAll.eslint": "always"
}
},
}
17 changes: 13 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@ module.exports = [
'parser': require('@typescript-eslint/parser'),
},
'plugins': {
'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
'@stylistic': require('@stylistic/eslint-plugin'),
'@typescript': require('@typescript-eslint/eslint-plugin'),
},
'rules': {
'semi': 'error',
'no-throw-literal': 'error',
'semi': 'error',
'no-extra-semi': 'error',
'eqeqeq': 'error',
'prefer-const': 'warn',
'curly': 'warn',
'eqeqeq': 'warn',
'@typescript-eslint/naming-convention': [
'@typescript/naming-convention': [
'warn',
{
'selector': 'import',
'format': [ 'camelCase', 'PascalCase' ]
}
],
'@stylistic/indent': ['warn', 4],
'@stylistic/quotes': ['warn', 'single'],
'@stylistic/brace-style': ['warn', '1tbs'],
'@stylistic/curly-newline': ['warn', {'minElements': 1, 'consistent': true}],
'@stylistic/keyword-spacing': 'warn',
'@stylistic/space-before-blocks': 'warn',
},
}
];
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,12 @@
"@types/vscode": "^1.94",
"@typescript-eslint/eslint-plugin": "^8",
"@typescript-eslint/parser": "^8",
"@vscode/vsce": "^3.x",
"esbuild": "^0.24",
"eslint": "^9.12",
"typescript": "5.5.x",
"@vscode/vsce": "^3.x"
"typescript": "5.5.x"
},
"dependencies": {
"@stylistic/eslint-plugin": "^2.9.0"
}
}
8 changes: 4 additions & 4 deletions src/cxxrtl/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ export class Connection {
}

private traceSend(packet: proto.ClientPacket) {
this.timestamps.push(new Date());
if (packet.type === 'greeting') {
console.debug(`[CXXRTL] C>S`, packet);
console.debug('[CXXRTL] C>S', packet);
} else if (packet.type === 'command') {
this.timestamps.push(new Date());
console.debug(`[CXXRTL] C>S#${this.sendIndex++}`, packet);
}
}

private traceRecv(packet: proto.ServerPacket) {
if (packet.type === 'greeting') {
console.debug(`[CXXRTL] S>C`, packet);
console.debug('[CXXRTL] S>C', packet);
} else if (packet.type === 'response') {
const elapsed = new Date().getTime() - this.timestamps.shift()!.getTime();
console.debug(`[CXXRTL] S>C#${this.recvIndex++}`, packet, `(${elapsed}ms)`);
} else if (packet.type === 'error') {
this.timestamps.shift();
console.error(`[CXXRTL] S>C#${this.recvIndex++}`, packet);
} else if (packet.type === 'event') {
console.debug(`[CXXRTL] S>C`, packet);
console.debug('[CXXRTL] S>C', packet);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cxxrtl/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ILink {
onDone: () => Promise<void>;

send(packet: proto.ClientPacket): Promise<void>;
};
}

export class MockLink implements ILink {
constructor(
Expand Down
44 changes: 26 additions & 18 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TimeInterval, TimePoint } from './model/time';
import { Scope } from './model/scope';
import { Variable } from './model/variable';
import { StatusBarItem } from './ui/status';
import { BoundReference, Reference, Sample } from './model/sample';
import { Reference, UnboundReference, Sample } from './model/sample';

export enum CXXRTLSimulationStatus {
Paused = 'paused',
Expand All @@ -28,12 +28,16 @@ export class CXXRTLDebugger {
// Session properties.

private _sessionStatus: CXXRTLSessionStatus = CXXRTLSessionStatus.Absent;
public get sessionStatus() { return this._sessionStatus;}
public get sessionStatus() {
return this._sessionStatus;
}
private _onDidChangeSessionStatus: vscode.EventEmitter<CXXRTLSessionStatus> = new vscode.EventEmitter<CXXRTLSessionStatus>();
readonly onDidChangeSessionStatus: vscode.Event<CXXRTLSessionStatus> = this._onDidChangeSessionStatus.event;

private _currentTime: TimePoint = new TimePoint(0n, 0n);
public get currentTime() { return this._currentTime;}
public get currentTime() {
return this._currentTime;
}
private _onDidChangeCurrentTime: vscode.EventEmitter<TimePoint> = new vscode.EventEmitter<TimePoint>();
readonly onDidChangeCurrentTime: vscode.Event<TimePoint> = this._onDidChangeCurrentTime.event;

Expand All @@ -42,12 +46,16 @@ export class CXXRTLDebugger {
private simulationStatusUpdateTimeout: NodeJS.Timeout | null = null;

private _simulationStatus: CXXRTLSimulationStatus = CXXRTLSimulationStatus.Finished;
public get simulationStatus() { return this._simulationStatus; }
public get simulationStatus() {
return this._simulationStatus;
}
private _onDidChangeSimulationStatus: vscode.EventEmitter<CXXRTLSimulationStatus> = new vscode.EventEmitter<CXXRTLSimulationStatus>();
readonly onDidChangeSimulationStatus: vscode.Event<CXXRTLSimulationStatus> = this._onDidChangeSimulationStatus.event;

private _latestTime: TimePoint = new TimePoint(0n, 0n);
public get latestTime() { return this._latestTime;}
public get latestTime() {
return this._latestTime;
}
private _onDidChangeLatestTime: vscode.EventEmitter<TimePoint> = new vscode.EventEmitter<TimePoint>();
readonly onDidChangeLatestTime: vscode.Event<TimePoint> = this._onDidChangeLatestTime.event;

Expand All @@ -63,7 +71,7 @@ export class CXXRTLDebugger {

public async startSession(): Promise<void> {
if (this.terminal !== null) {
vscode.window.showErrorMessage("A debug session is already in the process of being started.");
vscode.window.showErrorMessage('A debug session is already in the process of being started.');
return;
}

Expand All @@ -81,39 +89,39 @@ export class CXXRTLDebugger {
this.setSessionStatus(CXXRTLSessionStatus.Starting);

const processId = await this.terminal.processId;
console.log("[RTL Debugger] Launched process %d", processId);
console.log('[RTL Debugger] Launched process %d', processId);

setTimeout(() => {
const socket = net.createConnection({ port: configuration.port, host: '::1' }, () => {
vscode.window.showInformationMessage("Connected to the CXXRTL server.");
vscode.window.showInformationMessage('Connected to the CXXRTL server.');

(async () => {
this.connection = new Connection(new NodeStreamLink(socket));
this.setSessionStatus(CXXRTLSessionStatus.Running);
this.updateSimulationStatus();
console.log("[RTL Debugger] Initialized");
console.log('[RTL Debugger] Initialized');
})().catch(() => {
this.stopSession();
});
});
socket.on('error', (err: any) => {
if (err.code === 'ECONNREFUSED') {
vscode.window.showErrorMessage("The connection to the CXXRTL server was refused.");
vscode.window.showErrorMessage('The connection to the CXXRTL server was refused.');
} else {
vscode.window.showErrorMessage(`The connection to the CXXRTL server has failed: ${err.code}.`);
}
this.stopSession();
});
socket.on('close', (hadError) => {
if (!hadError) {
vscode.window.showInformationMessage("Disconnected from the CXXRTL server.");
vscode.window.showInformationMessage('Disconnected from the CXXRTL server.');
}
this.stopSession();
});
}, 500); // FIXME
} else {
const OpenSettings = "Open Settings";
const selection = await vscode.window.showErrorMessage("Configure the launch command to start a debug session.", OpenSettings);
const OpenSettings = 'Open Settings';
const selection = await vscode.window.showErrorMessage('Configure the launch command to start a debug session.', OpenSettings);
if (selection === OpenSettings) {
vscode.commands.executeCommand('workbench.action.openSettings', 'rtlDebugger.command');
}
Expand Down Expand Up @@ -254,7 +262,7 @@ export class CXXRTLDebugger {
for (const [cxxrtlName, cxxrtlDesc] of Object.entries(cxxrtlResponse.scopes)) {
const nestedScopes: Scope[] = [];
const nestedVariables: Thenable<Variable[]> = {
// NormallyPromises are evaluated eagerly; this Thenable does it lazily.
// Normally Promises are evaluated eagerly; this Thenable does it lazily.
then: (onfulfilled, onrejected) => {
return this.getVariablesForScope(cxxrtlName).then(onfulfilled, onrejected);
}
Expand Down Expand Up @@ -292,7 +300,7 @@ export class CXXRTLDebugger {
}
}

public bindReference(name: string, reference: Reference): BoundReference {
public bindReference(name: string, reference: UnboundReference): Reference {
const epoch = this.advanceReferenceEpoch(name);
// Note that we do not wait for the command to complete. Although it is possible for
// the command to fail, this would only happen if one of the designations is invalid,
Expand All @@ -303,13 +311,13 @@ export class CXXRTLDebugger {
reference: name,
items: reference.cxxrtlItemDesignations()
}).catch((error) => {
console.error(`[CXXRTL] invalid designation while binding reference`,
console.error('[CXXRTL] invalid designation while binding reference',
`${name}#${epoch}`, error);
});
return new BoundReference(name, epoch, reference);
return new Reference(name, epoch, reference);
}

public async queryInterval(interval: TimeInterval, reference: BoundReference): Promise<Sample[]> {
public async queryInterval(interval: TimeInterval, reference: Reference): Promise<Sample[]> {
this.verifyReferenceEpoch(reference.name, reference.epoch);
const cxxrtlResponse = await this.connection!.queryInterval({
type: 'command',
Expand Down
Loading

0 comments on commit ede2a3d

Please sign in to comment.