diff --git a/src/frontend/extension.ts b/src/frontend/extension.ts index 3de3d540..70cfe98e 100644 --- a/src/frontend/extension.ts +++ b/src/frontend/extension.ts @@ -502,9 +502,9 @@ export class CortexDebugExtension { if (Object.keys(this.rttPortMap).length > 0) { this.initializeRTT(args); } if (!this.currentArgs.noDebug) { - this.registerProvider.debugSessionStarted(); + this.registerProvider.debugSessionStarted(session); } - this.peripheralProvider.debugSessionStarted((svdfile && !args.noDebug) ? svdfile : null, args.svdAddrGapThreshold); + this.peripheralProvider.debugSessionStarted(session, (svdfile && !args.noDebug) ? svdfile : null, args.svdAddrGapThreshold); this.cleanupRTTTerminals(); }, (error) => { // TODO: Error handling for unable to get arguments @@ -519,9 +519,9 @@ export class CortexDebugExtension { this.debuggerStatus = 'none'; if (!this.currentArgs.noDebug) { - this.registerProvider.debugSessionTerminated(); + this.registerProvider.debugSessionTerminated(session); } - this.peripheralProvider.debugSessionTerminated(); + this.peripheralProvider.debugSessionTerminated(session); if (this.swo) { this.swo.debugSessionTerminated(); } @@ -580,7 +580,7 @@ export class CortexDebugExtension { private receivedStopEvent(e) { this.debuggerStatus = 'stopped'; - this.peripheralProvider.debugStopped(); + this.peripheralProvider.debugStopped(vscode.debug.activeDebugSession); if (this.currentArgs && !this.currentArgs.noDebug) { this.registerProvider.debugStopped(); } diff --git a/src/frontend/views/peripheral.ts b/src/frontend/views/peripheral.ts index 4e750248..07630188 100644 --- a/src/frontend/views/peripheral.ts +++ b/src/frontend/views/peripheral.ts @@ -14,6 +14,7 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider = new vscode.EventEmitter(); public readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + public session: vscode.DebugSession = null; private peripherials: PeripheralNode[] = []; private loaded: boolean = false; @@ -40,7 +41,7 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider { - return new Promise((resolve,reject) => { + return new Promise((resolve, reject) => { if (!path.isAbsolute(SVDFile)) { const fullpath = path.normalize(path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, SVDFile)); SVDFile = fullpath; @@ -100,19 +101,19 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider { + public debugSessionStarted(session: vscode.DebugSession, svdfile: string, thresh: any): Thenable { return new Promise((resolve, reject) => { this.peripherials = []; - this.loaded = false; this._onDidChangeTreeData.fire(undefined); // Set the threshold between 0 and 32, with a default of 16 and a mukltiple of 8 this.gapThreshold = ((((typeof thresh) === 'number') ? Math.max(0, Math.min(thresh, 32)) : 16) + 7) & ~0x7; - if (svdfile) { + if (svdfile && !this.session && !this.loaded) { setTimeout(() => { this.loadSVD(svdfile).then( () => { + this.session = session; vscode.workspace.findFiles('.vscode/.cortex-debug.peripherals.state.json', null, 1).then((value) => { if (value.length > 0) { const fspath = value[0].fsPath; @@ -159,20 +160,26 @@ export class PeripheralTreeProvider implements vscode.TreeDataProvider { - if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { - const fspath = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, '.vscode', '.cortex-debug.peripherals.state.json'); - this.saveState(fspath); + public debugSessionTerminated(session: vscode.DebugSession): Thenable { + if (this.session.id === session.id) { + if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { + // Path should really be in the workspace storage but this is where we will live for now + const fspath = path.join( + session.workspaceFolder.uri.fsPath, + /*vscode.workspace.workspaceFolders[0].uri.fsPath,*/ + '.vscode', '.cortex-debug.peripherals.state.json'); + this.saveState(fspath); + } + this.session = null; + this.peripherials = []; + this.loaded = false; + this._onDidChangeTreeData.fire(undefined); } - - this.peripherials = []; - this.loaded = false; - this._onDidChangeTreeData.fire(undefined); return Promise.resolve(true); } - public debugStopped() { - if (this.loaded) { + public debugStopped(session: vscode.DebugSession) { + if (this.loaded && (session.id === this.session.id)) { const promises = this.peripherials.map((p) => p.updateData()); Promise.all(promises).then((_) => { this._onDidChangeTreeData.fire(undefined); }, (_) => { this._onDidChangeTreeData.fire(undefined); }); } diff --git a/src/frontend/views/registers.ts b/src/frontend/views/registers.ts index 4921f211..822038aa 100644 --- a/src/frontend/views/registers.ts +++ b/src/frontend/views/registers.ts @@ -13,6 +13,7 @@ export class RegisterTreeProvider implements TreeDataProvider { // tslint:disable-next-line:variable-name public _onDidChangeTreeData: EventEmitter = new EventEmitter(); public readonly onDidChangeTreeData: Event = this._onDidChangeTreeData.event; + public session: vscode.DebugSession = null; private registers: RegisterNode[]; private registerMap: { [index: number]: RegisterNode }; @@ -135,10 +136,16 @@ export class RegisterTreeProvider implements TreeDataProvider { } } - public debugSessionTerminated() { - if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) { - const fspath = path.join(workspace.workspaceFolders[0].uri.fsPath, '.vscode', '.cortex-debug.registers.state.json'); - this._saveState(fspath); + public debugSessionTerminated(session: vscode.DebugSession) { + if (this.session.id === session.id) { + // We don't have multi-session capability, yet, and this file should really be in workspace storage + if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) { + const fspath = path.join(session.workspaceFolder.uri.fsPath, + /* workspace.workspaceFolders[0].uri.fsPath,*/ + '.vscode', '.cortex-debug.registers.state.json'); + this._saveState(fspath); + } + this.session = null; } this.loaded = false; @@ -147,7 +154,11 @@ export class RegisterTreeProvider implements TreeDataProvider { this._onDidChangeTreeData.fire(undefined); } - public debugSessionStarted() { + public debugSessionStarted(session: vscode.DebugSession) { + if (!this.session) { + // This is to decide where to store settings + this.session = session; + } this.loaded = false; this.registers = []; this.registerMap = {};