Skip to content

Commit b2298c7

Browse files
authored
Show CPU Time and History (#460)
* status bar item with switchable (pname or none) * move debug session specifics to own folder * add @vscode/debugprotocol 1.68.0 * track active session, evaluate expressions * read states/cycles from target * time calc * redirect output to Debug Console * show pname in history output, show time or states depending on frequency * reset command * demo feedback: some formatting enhancements * check if CPU states supported for session * print location info * tests * track stack trace requests for threadId Signed-off-by: Jens Reinecke <[email protected]>
1 parent dc2602f commit b2298c7

26 files changed

+2440
-83
lines changed

__mocks__/vscode.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const EnvironmentVariableMutatorType = {
2525
Prepend: 3
2626
};
2727

28+
const StatusBarAlignment = {
29+
Left: 1,
30+
Right: 2
31+
};
32+
2833
module.exports = {
2934
EventEmitter: jest.fn(() => {
3035
const callbacks = [];
@@ -48,6 +53,8 @@ module.exports = {
4853
error: jest.fn(),
4954
})),
5055
showWarningMessage: jest.fn(),
56+
createStatusBarItem: jest.fn(),
57+
showQuickPick: jest.fn(),
5158
},
5259
workspace: {
5360
getConfiguration: jest.fn(() => ({
@@ -72,10 +79,19 @@ module.exports = {
7279
},
7380
commands: {
7481
executeCommand: jest.fn(),
82+
registerCommand: jest.fn(),
7583
},
7684
debug: {
7785
registerDebugConfigurationProvider: jest.fn(),
7886
registerDebugAdapterTrackerFactory: jest.fn(),
87+
onDidChangeActiveDebugSession: jest.fn(),
88+
onDidChangeActiveStackItem: jest.fn(),
89+
activeStackItem: undefined,
90+
activeDebugConsole: {
91+
append: jest.fn(),
92+
appendLine: jest.fn()
93+
}
7994
},
8095
EnvironmentVariableMutatorType,
96+
StatusBarAlignment,
8197
};

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,34 @@
4646
"onStartupFinished"
4747
],
4848
"contributes": {
49+
"commands": [
50+
{
51+
"title": "CPU Time",
52+
"shortTitle": "CPU Time",
53+
"command": "vscode-cmsis-debugger.showCpuTimeHistory",
54+
"category": "Run and Debug",
55+
"when": "inDebugMode"
56+
},
57+
{
58+
"title": "Reset CPU Time",
59+
"shortTitle": "CPU Time",
60+
"command": "vscode-cmsis-debugger.resetCpuTimeHistory",
61+
"category": "Run and Debug",
62+
"when": "inDebugMode"
63+
}
64+
],
65+
"menus": {
66+
"commandPalette": [
67+
{
68+
"command": "vscode-cmsis-debugger.showCpuTimeHistory",
69+
"when": "inDebugMode"
70+
},
71+
{
72+
"command": "vscode-cmsis-debugger.resetCpuTimeHistory",
73+
"when": "inDebugMode"
74+
}
75+
]
76+
},
4977
"debuggers": [
5078
{
5179
"type": "*",
@@ -120,6 +148,7 @@
120148
"@types/yarnpkg__lockfile": "^1.1.9",
121149
"@typescript-eslint/eslint-plugin": "^8.39.0",
122150
"@typescript-eslint/parser": "^8.39.0",
151+
"@vscode/debugprotocol": "^1.68.0",
123152
"@vscode/vsce": "^3.6.0",
124153
"@yarnpkg/lockfile": "^1.1.0",
125154
"eslint": "^9.32.0",

src/__test__/vscode.factory.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,17 @@ export function extensionContextFactory(): jest.Mocked<vscode.ExtensionContext>
6868
} as unknown as vscode.LanguageModelAccessInformation,
6969
};
7070
};
71+
72+
export function debugSessionFactory(
73+
configuration: vscode.DebugConfiguration
74+
): jest.Mocked<vscode.DebugSession> {
75+
return {
76+
id: '{session-id}',
77+
name: configuration.name,
78+
type: configuration.type,
79+
workspaceFolder: undefined,
80+
configuration,
81+
customRequest: jest.fn(),
82+
getDebugProtocolBreakpoint: jest.fn()
83+
};
84+
};

src/debug-configuration/gdbtarget-debug-tracker.test.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/debug-configuration/gdbtarget-debug-tracker.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`GDBTargetDebugSession returns a cbuild object after parsing one 1`] = `
4+
CbuildRunReader {
5+
"cbuildRun": {
6+
"compiler": "AC6",
7+
"debug-sequences": [
8+
{
9+
"blocks": [
10+
{
11+
"execute": "Write32(0x20000000, 0xA5A5A5A5);
12+
",
13+
},
14+
{
15+
"blocks": [
16+
{
17+
"execute": "Read32(0x20000004);
18+
",
19+
},
20+
],
21+
"if": "condition == true",
22+
},
23+
{
24+
"execute": "Write32(0x20000008, 0x5);
25+
",
26+
},
27+
],
28+
"name": "MySequence",
29+
"pname": "Core0",
30+
},
31+
{
32+
"blocks": [
33+
{
34+
"execute": "DAP_Delay(500000); // Delay for 500ms
35+
",
36+
},
37+
],
38+
"name": "DebugDeviceUnlock",
39+
"pname": "Core0",
40+
},
41+
],
42+
"debug-topology": {
43+
"debugports": [
44+
{
45+
"accessports": [
46+
{
47+
"address": 0,
48+
"apid": 0,
49+
},
50+
{
51+
"address": 1048576,
52+
"apid": 1,
53+
},
54+
],
55+
"dpid": 0,
56+
},
57+
],
58+
"processors": [
59+
{
60+
"apid": 0,
61+
"pname": "Core0",
62+
},
63+
{
64+
"apid": 1,
65+
"pname": "Core1",
66+
},
67+
],
68+
},
69+
"debugger": {
70+
"clock": 10000000,
71+
"gdbserver": [
72+
{
73+
"pname": "Core0",
74+
"port": 3336,
75+
},
76+
{
77+
"pname": "Core1",
78+
"port": 3339,
79+
},
80+
],
81+
"name": "<default>",
82+
"port": "swd",
83+
"start-pname": "Core0",
84+
"terminal": 4444,
85+
},
86+
"device": "MyVendor::MyDevice",
87+
"device-pack": "MyVendor::[email protected]",
88+
"generated-by": "csolution version 2.8.0",
89+
"output": [
90+
{
91+
"file": "out/MyApp.bin",
92+
"info": "generate by MyApp",
93+
"load": "image",
94+
"type": "bin",
95+
},
96+
{
97+
"file": "out/out/MyApp.axf",
98+
"info": "generate by MyApp",
99+
"load": "symbols",
100+
"type": "elf",
101+
},
102+
],
103+
"programming": [
104+
{
105+
"algorithm": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Flash/algorithms/MyAlgorithm_Core0.FLM",
106+
"pname": "Core0",
107+
"ram-size": 131072,
108+
"ram-start": 536870912,
109+
"size": 524288,
110+
"start": 0,
111+
},
112+
{
113+
"algorithm": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Flash/algorithms/MyAlgorithm_Extern.FLM",
114+
"pname": "Core0",
115+
"ram-size": 131072,
116+
"ram-start": 536870912,
117+
"size": 33554432,
118+
"start": 3221225472,
119+
},
120+
],
121+
"solution": "my-test.csolution.yml",
122+
"system-descriptions": [
123+
{
124+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd",
125+
"pname": "Core0",
126+
"type": "svd",
127+
},
128+
{
129+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd",
130+
"pname": "Core1",
131+
"type": "svd",
132+
},
133+
],
134+
"system-resources": {
135+
"memory": [
136+
{
137+
"access": "rx",
138+
"from-pack": "MyVendor::[email protected]",
139+
"name": "Flash",
140+
"pname": "Core0",
141+
"size": 524288,
142+
"start": 0,
143+
},
144+
{
145+
"access": "rwx",
146+
"from-pack": "MyVendor::[email protected]",
147+
"name": "SRAM0",
148+
"pname": "Core0",
149+
"size": 4194304,
150+
"start": 33554432,
151+
},
152+
{
153+
"access": "rwx",
154+
"from-pack": "MyVendor::[email protected]",
155+
"name": "SRAM1",
156+
"pname": "Core0",
157+
"size": 2621440,
158+
"start": 134217728,
159+
},
160+
],
161+
},
162+
"target-type": "My-Test-Target-Type",
163+
},
164+
"reader": VscodeFileReader {},
165+
}
166+
`;

src/debug-session/constants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2025 Arm Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export const GDB_TARGET_DEBUGGER_TYPE = 'gdbtarget';

0 commit comments

Comments
 (0)