Skip to content
Merged
1 change: 1 addition & 0 deletions __mocks__/vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module.exports = {
warn: jest.fn(),
error: jest.fn(),
})),
registerTreeDataProvider: jest.fn(() => ({ dispose: jest.fn() })),
showWarningMessage: jest.fn(),
createStatusBarItem: jest.fn(),
showQuickPick: jest.fn(),
Expand Down
61 changes: 61 additions & 0 deletions media/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 media/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.
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@
"activitybar": [
{
"id": "cmsis-debugger",
"title": "CMSIS Debug",
"icon": "$(rocket)"
"title": "Trace and Live View",
"icon": "media/trace-and-live-dark.svg"
}
]
},
"views": {
"cmsis-debugger": [
{
"id": "cmsis-debugger.liveWatch",
"name": "Live Watch"
"name": "Live Watch",
"icon": "media/trace-and-live-light.svg"
}
]
},
Expand All @@ -80,27 +81,27 @@
"when": "inDebugMode"
},
{
"command": "cmsis-debugger.liveWatch.add",
"command": "vscode-cmsis-debugger.liveWatch.add",
"title": "Add Expression",
"icon": "$(add)"
},
{
"command": "cmsis-debugger.liveWatch.deleteAll",
"command": "vscode-cmsis-debugger.liveWatch.deleteAll",
"title": "Delete All Expressions",
"icon": "$(close-all)"
},
{
"command": "cmsis-debugger.liveWatch.delete",
"command": "vscode-cmsis-debugger.liveWatch.delete",
"title": "Delete Expression",
"icon": "$(close)"
},
{
"command": "cmsis-debugger.liveWatch.refresh",
"command": "vscode-cmsis-debugger.liveWatch.refresh",
"title": "Refresh",
"icon": "$(refresh)"
},
{
"command": "cmsis-debugger.liveWatch.modify",
"command": "vscode-cmsis-debugger.liveWatch.modify",
"title": "Modify Expression",
"icon": "$(pencil)"
}
Expand All @@ -118,29 +119,29 @@
],
"view/title": [
{
"command": "cmsis-debugger.liveWatch.add",
"command": "vscode-cmsis-debugger.liveWatch.add",
"when": "view == cmsis-debugger.liveWatch",
"group": "navigation@1"
},
{
"command": "cmsis-debugger.liveWatch.deleteAll",
"command": "vscode-cmsis-debugger.liveWatch.deleteAll",
"when": "view == cmsis-debugger.liveWatch",
"group": "navigation@3"
},
{
"command": "cmsis-debugger.liveWatch.refresh",
"command": "vscode-cmsis-debugger.liveWatch.refresh",
"when": "view == cmsis-debugger.liveWatch",
"group": "navigation@2"
}
],
"view/item/context": [
{
"command": "cmsis-debugger.liveWatch.modify",
"command": "vscode-cmsis-debugger.liveWatch.modify",
"when": "view == cmsis-debugger.liveWatch && viewItem == expression",
"group": "inline@1"
},
{
"command": "cmsis-debugger.liveWatch.delete",
"command": "vscode-cmsis-debugger.liveWatch.delete",
"when": "view == cmsis-debugger.liveWatch && viewItem == expression",
"group": "inline@2"
}
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
5 changes: 3 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,8 @@ export class GDBTargetDebugSession {
this._cbuildRunParsePromise = undefined;
}

public async evaluateGlobalExpression(expression: string, context = 'hover'): Promise<string> {
/** Function returns string only in case of failure */
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 +64,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