Skip to content

Commit de28e8a

Browse files
committed
Implement watch list management.
1 parent f23addd commit de28e8a

File tree

6 files changed

+220
-19
lines changed

6 files changed

+220
-19
lines changed

example/.vscode/settings.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"rtlDebugger.command": ["${workspaceFolder}/design_sim"]
3-
}
2+
"rtlDebugger.command": [
3+
"${workspaceFolder}/design_sim"
4+
],
5+
"rtlDebugger.watchList": []
6+
}

package.json

+39-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"$comment": "UPSTREAM: Unfortunately there is no way to control the formatting of the extension name within the setting title. See microsoft/vscode#103592",
2424
"properties": {
2525
"rtlDebugger.command": {
26-
"type": [
27-
"array"
28-
],
26+
"type": "array",
2927
"items": {
3028
"type": "string"
3129
},
@@ -60,6 +58,20 @@
6058
],
6159
"default": "Verilog",
6260
"markdownDescription": "Specifies the display format for variables."
61+
},
62+
"rtlDebugger.watchList": {
63+
"type": "array",
64+
"items": {
65+
"type": "object",
66+
"properties": {
67+
"id": {"type": "string"},
68+
"row": {"type": "integer"},
69+
"bit": {"type": "integer"}
70+
},
71+
"required": ["id"],
72+
"additionalProperties": false
73+
},
74+
"description": "Specifies the list of variables being watched separately."
6375
}
6476
}
6577
},
@@ -104,6 +116,18 @@
104116
"category": "RTL Debugger",
105117
"title": "Step Backward",
106118
"icon": "$(debug-step-back)"
119+
},
120+
{
121+
"command": "rtlDebugger.watchVariable",
122+
"category": "RTL Debugger",
123+
"title": "Watch Variable",
124+
"icon": "$(eye-watch)"
125+
},
126+
{
127+
"command": "rtlDebugger.unWatchVariable",
128+
"category": "RTL Debugger",
129+
"title": "Stop Watching",
130+
"icon": "$(remove)"
107131
}
108132
],
109133
"viewsContainers": {
@@ -197,6 +221,18 @@
197221
"when": "view == rtlDebugger.sidebar && rtlDebugger.sessionStatus == running",
198222
"group": "navigation@5"
199223
}
224+
],
225+
"view/item/context": [
226+
{
227+
"command": "rtlDebugger.watchVariable",
228+
"when": "view == rtlDebugger.sidebar && viewItem == canWatch",
229+
"group": "inline"
230+
},
231+
{
232+
"command": "rtlDebugger.unWatchVariable",
233+
"when": "view == rtlDebugger.sidebar && viewItem == inWatchList",
234+
"group": "inline"
235+
}
200236
]
201237
}
202238
},

src/debug/session.ts

+11
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ export class Session {
116116
);
117117
}
118118

119+
async getVariable(variableIdentifier: string): Promise<Variable | null> {
120+
const identifierParts = variableIdentifier.split(' ');
121+
const scopeIdentifier = identifierParts.slice(0, identifierParts.length - 1).join(' ');
122+
const items = await this.listItemsInScope(scopeIdentifier);
123+
if (variableIdentifier in items) {
124+
return Variable.fromCXXRTL(variableIdentifier, items[variableIdentifier]);
125+
} else {
126+
return null;
127+
}
128+
}
129+
119130
// ======================================== Querying the database
120131

121132
private referenceEpochs: Map<string, number> = new Map();

src/debug/watch.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as vscode from 'vscode';
2+
3+
export interface IWatchItem {
4+
id: string;
5+
row?: number;
6+
bit?: number;
7+
}
8+
9+
export interface IWatchList {
10+
get(): IWatchItem[];
11+
set(items: IWatchItem[]): void;
12+
append(item: IWatchItem): void;
13+
remove(index: number): void;
14+
15+
onDidChange(callback: (items: IWatchItem[]) => any): vscode.Disposable;
16+
}
17+
18+
export const watchList: IWatchList = {
19+
get(): IWatchItem[] {
20+
return vscode.workspace.getConfiguration('rtlDebugger').get('watchList') || [];
21+
},
22+
23+
set(items: IWatchItem[]): void {
24+
vscode.workspace.getConfiguration('rtlDebugger').update('watchList', items);
25+
},
26+
27+
append(item: IWatchItem): void {
28+
this.set(this.get().concat(item));
29+
},
30+
31+
remove(index: number): void {
32+
const items = this.get();
33+
items.splice(index, 1);
34+
this.set(items);
35+
},
36+
37+
onDidChange(callback: (items: IWatchItem[]) => any): vscode.Disposable {
38+
return vscode.workspace.onDidChangeConfiguration((event) => {
39+
if (event.affectsConfiguration('rtlDebugger.watchList')) {
40+
callback(watchList.get());
41+
}
42+
});
43+
},
44+
};

src/extension.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import * as vscode from 'vscode';
2+
import { watchList } from './debug/watch';
23
import { CXXRTLDebugger } from './debugger';
34
import * as sidebar from './ui/sidebar';
45
import { inputTime } from './ui/input';
56

67
export function activate(context: vscode.ExtensionContext) {
78
const rtlDebugger = new CXXRTLDebugger();
8-
const sidebarTreeDataProvider = new sidebar.TreeDataProvider(rtlDebugger);
99

10-
context.subscriptions.push(vscode.window.createTreeView('rtlDebugger.sidebar', {
10+
const sidebarTreeDataProvider = new sidebar.TreeDataProvider(rtlDebugger);
11+
const sidebarTreeView = vscode.window.createTreeView('rtlDebugger.sidebar', {
1112
treeDataProvider: sidebarTreeDataProvider
12-
}));
13+
});
14+
context.subscriptions.push(sidebarTreeView);
1315

1416
vscode.commands.executeCommand('setContext', 'rtlDebugger.sessionStatus', rtlDebugger.sessionStatus);
1517
context.subscriptions.push(rtlDebugger.onDidChangeSessionStatus((state) =>
@@ -48,6 +50,11 @@ export function activate(context: vscode.ExtensionContext) {
4850
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.stepForward', () =>
4951
rtlDebugger.session!.stepForward()));
5052

53+
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.watchVariable', (treeItem) =>
54+
watchList.append(treeItem.getWatchItem())));
55+
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.unWatchVariable', (treeItem) =>
56+
watchList.remove(treeItem.metadata.index)));
57+
5158
// For an unknown reason, the `vscode.open` command (which does the exact same thing) ignores the options.
5259
context.subscriptions.push(vscode.commands.registerCommand('rtlDebugger.openDocument',
5360
(uri: vscode.Uri, options: vscode.TextDocumentShowOptions) => {

0 commit comments

Comments
 (0)