Skip to content
Merged
3 changes: 3 additions & 0 deletions __mocks__/vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const MockTreeItemCollapsibleState = {
Expanded: 2
};

const registerTreeDataProviderMock = jest.fn(() => ({ dispose: jest.fn() }));

class MockTreeItem {
label;
description;
Expand Down Expand Up @@ -71,6 +73,7 @@ module.exports = {
warn: jest.fn(),
error: jest.fn(),
})),
registerTreeDataProvider: registerTreeDataProviderMock,
showWarningMessage: jest.fn(),
createStatusBarItem: jest.fn(),
showQuickPick: jest.fn(),
Expand Down
61 changes: 61 additions & 0 deletions images/trace-and-live-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions images/trace-and-live-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@
{
"id": "cmsis-debugger",
"title": "CMSIS Debug",
"icon": "$(rocket)"
"icon": "images/trace-and-live-dark.svg"
}
]
},
"views": {
"cmsis-debugger": [
{
"id": "cmsis-debugger.liveWatch",
"name": "Live Watch"
"name": "Live Watch",
"icon": "images/live-watch-dark.svg"
}
]
},
Expand Down
8 changes: 4 additions & 4 deletions src/debug-session/gdbtarget-debug-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ describe('GDBTargetDebugSession', () => {

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

it('evaluates a global expression with active stack frame and returns a value', async () => {
// Only mock relevant properties, return value is body of EvaluateResponse
(debugSession.customRequest as jest.Mock).mockReturnValueOnce({ result: '1234567' });
(debugSession.customRequest as jest.Mock).mockReturnValueOnce({ result: '1234567', variableReference: 0 });
(vscode.debug.activeStackItem as unknown) = { session: debugSession, threadId: 1, frameId: 2 };
const result = await gdbTargetSession.evaluateGlobalExpression('myGlobalVariable');
expect(result).toEqual('1234567');
expect(result).toEqual({ result: '1234567', variableReference: 0 });
expect(debugSession.customRequest as jest.Mock).toHaveBeenCalledWith('evaluate', { expression: 'myGlobalVariable', frameId: 2, context: 'hover' });
// restore default
(vscode.debug.activeStackItem as unknown) = undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/debug-session/gdbtarget-debug-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class GDBTargetDebugSession {
this._cbuildRunParsePromise = undefined;
}

public async evaluateGlobalExpression(expression: string, context = 'hover'): Promise<string> {
public async evaluateGlobalExpression(expression: string, context = 'hover'): Promise<DebugProtocol.EvaluateResponse['body'] | string> {
try {
const frameId = (vscode.debug.activeStackItem as vscode.DebugStackFrame)?.frameId ?? 0;
const args: DebugProtocol.EvaluateArguments = {
Expand All @@ -63,7 +63,7 @@ export class GDBTargetDebugSession {
context: context
};
const response = await this.session.customRequest('evaluate', args) as DebugProtocol.EvaluateResponse['body'];
return response.result;
return response;
} catch (error: unknown) {
const errorMessage = (error as Error)?.message;
logger.debug(`Session '${this.session.name}': Failed to evaluate global expression '${expression}' - '${errorMessage}'`);
Expand Down
5 changes: 4 additions & 1 deletion src/features/cpu-states/cpu-states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ export class CpuStates {

protected async getFrequency(): Promise<number|undefined> {
const result = await this.activeSession?.evaluateGlobalExpression('SystemCoreClock');
const frequencyString = result?.match(/\d+/) ? result : undefined;
if (typeof result == 'string') {
return undefined;
}
const frequencyString = result?.result.match(/\d+/) ? result.result : undefined;
if (!frequencyString) {
return undefined;
}
Expand Down
Loading