Skip to content

Commit 8a00a96

Browse files
authored
Handle multi session in component viewer (#766)
* propagating active session information to target access functions * filtering out scvd files that have the same pname as that of the session * if no pname is specified for system descriptor, then accept it * handle incoming undefined sessions * adding tests
1 parent faf5c80 commit 8a00a96

17 files changed

Lines changed: 186 additions & 22 deletions

src/cbuild-run/__snapshots__/cbuild-run-reader.test.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ exports[`CbuildRunReader Parser successfully parses a *.cbuild-run.yml file 1`]
129129
"pname": "Core1",
130130
"type": "svd",
131131
},
132+
{
133+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd",
134+
"type": "svd",
135+
},
136+
{
137+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/MySoftware_component.scvd",
138+
"type": "scvd",
139+
},
140+
{
141+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/Core1.scvd",
142+
"pname": "Core1",
143+
"type": "scvd",
144+
},
132145
],
133146
"system-resources": {
134147
"memory": [

src/cbuild-run/cbuild-run-reader.test.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,24 @@ describe('CbuildRunReader', () => {
5959
pname: undefined,
6060
expectedSvdPaths: [
6161
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd',
62-
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd'
62+
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd',
63+
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd',
6364
]
6465
},
6566
{
6667
info: 'Core0',
6768
pname: 'Core0',
6869
expectedSvdPaths: [
6970
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd',
71+
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd',
7072
]
7173
},
7274
{
7375
info: 'Core1',
7476
pname: 'Core1',
7577
expectedSvdPaths: [
76-
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd'
78+
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd',
79+
'/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd',
7780
]
7881
},
7982
])('returns SVD file path ($info)', async ({ pname, expectedSvdPaths }) => {
@@ -90,5 +93,43 @@ describe('CbuildRunReader', () => {
9093
const svdFilePaths = cbuildRunReader.getSvdFilePaths('/my/pack/root');
9194
expect(svdFilePaths.length).toEqual(0);
9295
});
96+
97+
it('returns empty SCVD file path list when nothing is parsed', async () => {
98+
const scvdFilePaths = cbuildRunReader.getScvdFilePaths('/my/pack/root');
99+
expect(scvdFilePaths.length).toEqual(0);
100+
});
101+
102+
it('returns processor names from debug topology', async () => {
103+
await cbuildRunReader.parse(TEST_CBUILD_RUN_FILE);
104+
const pnames = cbuildRunReader.getPnames();
105+
expect(pnames).toEqual(['Core0', 'Core1']);
106+
});
107+
108+
it('includes descriptors without pname when filtering by pname (SVD)', async () => {
109+
await cbuildRunReader.parse(TEST_CBUILD_RUN_FILE);
110+
const cbuildRun = (cbuildRunReader as unknown as { cbuildRun?: { ['system-descriptions']?: Array<{ file: string; type: string; pname?: string }> } }).cbuildRun;
111+
const systemDescriptions = cbuildRun?.['system-descriptions'];
112+
expect(systemDescriptions).toBeDefined();
113+
const svdPaths = cbuildRunReader.getSvdFilePaths('', 'Core1');
114+
115+
expect(svdPaths).toEqual([
116+
'${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd',
117+
'${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd'
118+
119+
]);
120+
});
121+
122+
it('includes descriptors without pname when filtering by pname (SCVD)', async () => {
123+
await cbuildRunReader.parse(TEST_CBUILD_RUN_FILE);
124+
const cbuildRun = (cbuildRunReader as unknown as { cbuildRun?: { ['system-descriptions']?: Array<{ file: string; type: string; pname?: string }> } }).cbuildRun;
125+
const systemDescriptions = cbuildRun?.['system-descriptions'] ?? [];
126+
expect(systemDescriptions).toBeDefined();
127+
const scvdPaths = cbuildRunReader.getScvdFilePaths('', 'Core1');
128+
129+
expect(scvdPaths).toEqual([
130+
'${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/MySoftware_component.scvd',
131+
'${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/Core1.scvd',
132+
]);
133+
});
93134
});
94135
});

src/cbuild-run/cbuild-run-reader.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ export class CbuildRunReader {
6565
}
6666
// Replace potential ${CMSIS_PACK_ROOT} placeholder
6767
const effectiveCmsisPackRoot = cmsisPackRoot ?? getCmsisPackRootPath();
68-
// Map to copies, leave originals untouched
69-
const filteredDescriptors = pname ? fileDescriptors.filter(descriptor => descriptor.pname === pname): fileDescriptors;
68+
// Map to copies, leave originals untouched, if file descriptors do not have a pname, always include it
69+
const filteredDescriptors = pname ? fileDescriptors.filter(descriptor => {
70+
if (!descriptor.pname) {
71+
return true;
72+
}
73+
return descriptor.pname === pname;
74+
}): fileDescriptors;
7075
const filePaths = filteredDescriptors.map(descriptor => `${effectiveCmsisPackRoot
7176
? descriptor.file.replaceAll(CMSIS_PACK_ROOT_ENVVAR, effectiveCmsisPackRoot)
7277
: descriptor.file}`);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ CbuildRunReader {
130130
"pname": "Core1",
131131
"type": "svd",
132132
},
133+
{
134+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd",
135+
"type": "svd",
136+
},
137+
{
138+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/MySoftware_component.scvd",
139+
"type": "scvd",
140+
},
141+
{
142+
"file": "\${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/Core1.scvd",
143+
"pname": "Core1",
144+
"type": "scvd",
145+
},
133146
],
134147
"system-resources": {
135148
"memory": [

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ describe('GDBTargetDebugSession', () => {
128128
expect(result).toEqual(0x78563412);
129129
});
130130

131+
it('returns the active pname for a multi-core session name', async () => {
132+
const multiCoreSession = debugSessionFactory({
133+
name: 'Core1 session-name',
134+
type: 'gdbtarget',
135+
request: 'launch',
136+
});
137+
const multiCoreTargetSession = new GDBTargetDebugSession(multiCoreSession);
138+
await multiCoreTargetSession.parseCbuildRun(TEST_CBUILD_RUN_FILE);
139+
const pname = await multiCoreTargetSession.getPname();
140+
expect(pname).toBe('Core1');
141+
});
142+
131143
it('filters output events correctly', () => {
132144
const makeEvent = (output: string, category: string): DebugProtocol.OutputEvent => ({
133145
seq: 1,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { PeriodicRefreshTimer } from './periodic-refresh-timer';
2222
import { OutputEventFilter } from './output-event-filter';
2323
import { URI } from 'vscode-uri';
2424
import { GDBTargetConfiguration } from '../debug-configuration';
25+
import { extractPname } from '../utils';
2526
import path from 'path';
2627

2728
/**
@@ -95,6 +96,17 @@ export class GDBTargetDebugSession {
9596
this._cbuildRunParsePromise = undefined;
9697
}
9798

99+
public async getPname(): Promise<string|undefined> {
100+
const sessionName = this.session?.name;
101+
if (!sessionName) {
102+
return undefined;
103+
}
104+
const cbuildRunReader = await this.getCbuildRun();
105+
const pnames = cbuildRunReader?.getPnames();
106+
const pname = pnames && pnames.length > 1 ? extractPname(sessionName) : undefined;
107+
return pname;
108+
}
109+
98110
/**
99111
* Check if first stop attempt for session is done by 'terminate' request.
100112
* Notes:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class CpuStates {
258258
if (!this.activeCpuStates || this.activeHasStates() === undefined ) {
259259
return undefined;
260260
}
261-
const pname = await this.getActivePname();
261+
const pname = await this.activeSession?.getPname();
262262
await this.updateFrequency();
263263
const cpuName = pname ? ` ${pname} ` : '';
264264
if (!this.activeHasStates()) {

src/views/component-viewer/component-viewer-instance.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class ComponentViewerInstance {
4444
private _timeUsageLast: number = 0;
4545
private _statementEngine: StatementEngine | undefined;
4646
private _guiTree: ScvdGuiTree | undefined;
47+
private _scvdEvalContext: ScvdEvalContext | undefined;
4748

4849
public constructor(
4950
) {
@@ -61,6 +62,14 @@ export class ComponentViewerInstance {
6162
return result.join('\n');
6263
}
6364

65+
public get scvdEvalContext(): ScvdEvalContext | undefined {
66+
return this._scvdEvalContext;
67+
}
68+
69+
public set scvdEvalContext(scvdEvalContext: ScvdEvalContext | undefined) {
70+
this._scvdEvalContext = scvdEvalContext;
71+
}
72+
6473
public getGuiTree(): ScvdGuiTree[] | undefined {
6574
return this._guiTree?.children;
6675
}
@@ -88,6 +97,10 @@ export class ComponentViewerInstance {
8897
return `${text}, Time: ${timeUsage} ms, Mem: ${memUsage}, Mem Increase: ${memIncrease} MB, (Total: ${memCurrent} MB)`;
8998
}
9099

100+
public updateActiveSession(debugSession: GDBTargetDebugSession): void {
101+
this._scvdEvalContext?.updateActiveSession(debugSession);
102+
}
103+
91104
public async readModel(filename: URI, debugSession: GDBTargetDebugSession, debugTracker: GDBTargetDebugTracker): Promise<void> {
92105
const stats: string[] = [];
93106

@@ -114,11 +127,11 @@ export class ComponentViewerInstance {
114127
this.model.readXml(xml);
115128
stats.push(this.getStats(' model.readXml'));
116129

117-
const scvdEvalContext = new ScvdEvalContext(this.model);
118-
scvdEvalContext.init(debugSession, debugTracker);
130+
this._scvdEvalContext = new ScvdEvalContext(this.model);
131+
this._scvdEvalContext.init(debugSession, debugTracker);
119132
stats.push(this.getStats(' evalContext.init'));
120133

121-
const executionContext = scvdEvalContext.getExecutionContext();
134+
const executionContext = this._scvdEvalContext.getExecutionContext();
122135
this.model.setExecutionContextAll(executionContext);
123136
stats.push(this.getStats(' model.setExecutionContextAll'));
124137

src/views/component-viewer/component-viewer-main.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ export class ComponentViewer {
4848
return;
4949
}
5050
const cbuildRunReader = await session.getCbuildRun();
51+
const pname = await session.getPname();
5152
if (!cbuildRunReader) {
5253
return;
5354
}
5455
// Get SCVD file paths from cbuild-run reader
55-
const scvdFilesPaths: string [] = cbuildRunReader.getScvdFilePaths();
56+
const scvdFilesPaths: string [] = cbuildRunReader.getScvdFilePaths(undefined, pname);
5657
if (scvdFilesPaths.length === 0) {
5758
return undefined;
5859
}
@@ -147,6 +148,15 @@ export class ComponentViewer {
147148
private async handleOnDidChangeActiveDebugSession(session: GDBTargetDebugSession | undefined): Promise<void> {
148149
// Update debug session
149150
this._activeSession = session;
151+
if (!session) {
152+
this._instances = [];
153+
this._componentViewerTreeDataProvider?.deleteModels();
154+
return;
155+
}
156+
// Update Active Session in all instances
157+
for (const instance of this._instances) {
158+
instance.updateActiveSession(session);
159+
}
150160
// Update component viewer instance(s)
151161
await this.updateInstances();
152162
}

src/views/component-viewer/component-viewer-target-access.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ import { logger } from '../../logger';
2323
export class ComponentViewerTargetAccess {
2424
_activeSession: GDBTargetDebugSession | undefined;
2525
constructor () {
26-
if (vscode.debug.activeDebugSession) {
27-
this._activeSession = new GDBTargetDebugSession(vscode.debug.activeDebugSession);
28-
}
2926
}
3027

3128
// Function to reset active session

0 commit comments

Comments
 (0)