Skip to content

Commit bd3fcbd

Browse files
authored
Add complex data type support to live watch (#592)
* Added support to complex data types in Live Watch * Added custom icon to view container * Updated tests of gdbtarget-debug-session to accommodate changes * Updated command names
1 parent 90481f7 commit bd3fcbd

File tree

9 files changed

+301
-84
lines changed

9 files changed

+301
-84
lines changed

__mocks__/vscode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = {
7171
warn: jest.fn(),
7272
error: jest.fn(),
7373
})),
74+
registerTreeDataProvider: jest.fn(() => ({ dispose: jest.fn() })),
7475
showWarningMessage: jest.fn(),
7576
createStatusBarItem: jest.fn(),
7677
showQuickPick: jest.fn(),

media/trace-and-live-dark.svg

Lines changed: 61 additions & 0 deletions
Loading

media/trace-and-live-light.svg

Lines changed: 58 additions & 0 deletions
Loading

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@
5151
"activitybar": [
5252
{
5353
"id": "cmsis-debugger",
54-
"title": "CMSIS Debug",
55-
"icon": "$(rocket)"
54+
"title": "Trace and Live View",
55+
"icon": "media/trace-and-live-dark.svg"
5656
}
5757
]
5858
},
5959
"views": {
6060
"cmsis-debugger": [
6161
{
6262
"id": "cmsis-debugger.liveWatch",
63-
"name": "Live Watch"
63+
"name": "Live Watch",
64+
"icon": "media/trace-and-live-light.svg"
6465
}
6566
]
6667
},
@@ -80,27 +81,27 @@
8081
"when": "inDebugMode"
8182
},
8283
{
83-
"command": "cmsis-debugger.liveWatch.add",
84+
"command": "vscode-cmsis-debugger.liveWatch.add",
8485
"title": "Add Expression",
8586
"icon": "$(add)"
8687
},
8788
{
88-
"command": "cmsis-debugger.liveWatch.deleteAll",
89+
"command": "vscode-cmsis-debugger.liveWatch.deleteAll",
8990
"title": "Delete All Expressions",
9091
"icon": "$(close-all)"
9192
},
9293
{
93-
"command": "cmsis-debugger.liveWatch.delete",
94+
"command": "vscode-cmsis-debugger.liveWatch.delete",
9495
"title": "Delete Expression",
9596
"icon": "$(close)"
9697
},
9798
{
98-
"command": "cmsis-debugger.liveWatch.refresh",
99+
"command": "vscode-cmsis-debugger.liveWatch.refresh",
99100
"title": "Refresh",
100101
"icon": "$(refresh)"
101102
},
102103
{
103-
"command": "cmsis-debugger.liveWatch.modify",
104+
"command": "vscode-cmsis-debugger.liveWatch.modify",
104105
"title": "Modify Expression",
105106
"icon": "$(pencil)"
106107
}
@@ -118,29 +119,29 @@
118119
],
119120
"view/title": [
120121
{
121-
"command": "cmsis-debugger.liveWatch.add",
122+
"command": "vscode-cmsis-debugger.liveWatch.add",
122123
"when": "view == cmsis-debugger.liveWatch",
123124
"group": "navigation@1"
124125
},
125126
{
126-
"command": "cmsis-debugger.liveWatch.deleteAll",
127+
"command": "vscode-cmsis-debugger.liveWatch.deleteAll",
127128
"when": "view == cmsis-debugger.liveWatch",
128129
"group": "navigation@3"
129130
},
130131
{
131-
"command": "cmsis-debugger.liveWatch.refresh",
132+
"command": "vscode-cmsis-debugger.liveWatch.refresh",
132133
"when": "view == cmsis-debugger.liveWatch",
133134
"group": "navigation@2"
134135
}
135136
],
136137
"view/item/context": [
137138
{
138-
"command": "cmsis-debugger.liveWatch.modify",
139+
"command": "vscode-cmsis-debugger.liveWatch.modify",
139140
"when": "view == cmsis-debugger.liveWatch && viewItem == expression",
140141
"group": "inline@1"
141142
},
142143
{
143-
"command": "cmsis-debugger.liveWatch.delete",
144+
"command": "vscode-cmsis-debugger.liveWatch.delete",
144145
"when": "view == cmsis-debugger.liveWatch && viewItem == expression",
145146
"group": "inline@2"
146147
}

src/debug-session/gdbtarget-debug-session.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ describe('GDBTargetDebugSession', () => {
5959

6060
it('evaluates a global expression without active stack frame and returns a value', async () => {
6161
// Only mock relevant properties, return value is body of EvaluateResponse
62-
(debugSession.customRequest as jest.Mock).mockReturnValueOnce({ result: '1234567' });
62+
(debugSession.customRequest as jest.Mock).mockReturnValueOnce({ result: '1234567', variableReference: 0 });
6363
const result = await gdbTargetSession.evaluateGlobalExpression('myGlobalVariable');
64-
expect(result).toEqual('1234567');
64+
expect(result).toEqual({ result: '1234567', variableReference: 0 });
6565
expect(debugSession.customRequest as jest.Mock).toHaveBeenCalledWith('evaluate', { expression: 'myGlobalVariable', frameId: 0, context: 'hover' });
6666
});
6767

6868
it('evaluates a global expression with active stack frame and returns a value', async () => {
6969
// Only mock relevant properties, return value is body of EvaluateResponse
70-
(debugSession.customRequest as jest.Mock).mockReturnValueOnce({ result: '1234567' });
70+
(debugSession.customRequest as jest.Mock).mockReturnValueOnce({ result: '1234567', variableReference: 0 });
7171
(vscode.debug.activeStackItem as unknown) = { session: debugSession, threadId: 1, frameId: 2 };
7272
const result = await gdbTargetSession.evaluateGlobalExpression('myGlobalVariable');
73-
expect(result).toEqual('1234567');
73+
expect(result).toEqual({ result: '1234567', variableReference: 0 });
7474
expect(debugSession.customRequest as jest.Mock).toHaveBeenCalledWith('evaluate', { expression: 'myGlobalVariable', frameId: 2, context: 'hover' });
7575
// restore default
7676
(vscode.debug.activeStackItem as unknown) = undefined;

src/debug-session/gdbtarget-debug-session.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export class GDBTargetDebugSession {
5454
this._cbuildRunParsePromise = undefined;
5555
}
5656

57-
public async evaluateGlobalExpression(expression: string, context = 'hover'): Promise<string> {
57+
/** Function returns string only in case of failure */
58+
public async evaluateGlobalExpression(expression: string, context = 'hover'): Promise<DebugProtocol.EvaluateResponse['body'] | string> {
5859
try {
5960
const frameId = (vscode.debug.activeStackItem as vscode.DebugStackFrame)?.frameId ?? 0;
6061
const args: DebugProtocol.EvaluateArguments = {
@@ -63,7 +64,7 @@ export class GDBTargetDebugSession {
6364
context: context
6465
};
6566
const response = await this.session.customRequest('evaluate', args) as DebugProtocol.EvaluateResponse['body'];
66-
return response.result;
67+
return response;
6768
} catch (error: unknown) {
6869
const errorMessage = (error as Error)?.message;
6970
logger.debug(`Session '${this.session.name}': Failed to evaluate global expression '${expression}' - '${errorMessage}'`);

src/features/cpu-states/cpu-states.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ export class CpuStates {
215215

216216
protected async getFrequency(): Promise<number|undefined> {
217217
const result = await this.activeSession?.evaluateGlobalExpression('SystemCoreClock');
218-
const frequencyString = result?.match(/\d+/) ? result : undefined;
218+
if (typeof result == 'string') {
219+
return undefined;
220+
}
221+
const frequencyString = result?.result.match(/\d+/) ? result.result : undefined;
219222
if (!frequencyString) {
220223
return undefined;
221224
}

0 commit comments

Comments
 (0)