Skip to content

Commit 0074bab

Browse files
committed
Allow RTT advanced decoder to displose(). Recycle output panels
1 parent 48913dc commit 0074bab

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# ChangeLog
2+
3+
# V1.13.0-pre6
4+
* Make the advanced decoder work properly for RTT. It now allows a dispose.
5+
* Both SWO/RTT OUTPUT panels are now recycled instead of creating a new one every time. You can for a new one by supplying a new outputLabel and/or typeName.
6+
27
# V1.13.0-pre5
38
* Refactored all the SWO initialization gdb commands to one common method used by all gdb servers. This eliminated tons of duplicate code.
49
* All gdb servers that have SWO will now use the SWO_Init (you can override it) GDB macro. See https://github.com/Marus/cortex-debug/wiki/SWO-Output and https://github.com/Marus/cortex-debug/blob/master/support/gdb-swo.init

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.13.0-pre5",
2+
"version": "1.13.0-pre6",
33
"preview": false,
44
"activationEvents": [
55
"onDebugResolve:cortex-debug",

src/frontend/swo/advanced-decoder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { SWODecoderConfig } from './common';
22

33
export interface SWOAdvancedDecoderConfig extends SWODecoderConfig {
4-
decoder: string;
4+
decoder: string; // Path to decoder JS file
55
config: any;
6-
ports: number[];
6+
ports: number[]; // List of ITM/RTT ports
77
}
88

99
export interface AdvancedDecoder {

src/frontend/swo/core.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class RTTDecoder extends EventEmitter {
444444

445445
constructor(
446446
public readonly source: SocketSWOSource,
447-
public readonly port: number, // Thisis the rtt channel
447+
public readonly port: number, // This is the rtt channel
448448
public readonly bytesNeeded: number) {
449449
super();
450450
this.buffer = Buffer.alloc(bytesNeeded);
@@ -460,6 +460,7 @@ class RTTDecoder extends EventEmitter {
460460
this.source.on('data', this.onData.bind(this));
461461
this.source.on('disconnected', () => {
462462
this.connected = false;
463+
this.emit('disconnected');
463464
});
464465
}
465466

@@ -526,6 +527,7 @@ export class RTTCore extends SWORTTCoreBase {
526527
if (src) {
527528
const dec = new RTTDecoder(src, src.channel, 4);
528529
dec.on('software-event', this.onPacket.bind(this));
530+
dec.on('disconnected', this.dispose.bind(this));
529531
this.decoders.push(dec);
530532
} else {
531533
console.error('Null source?');

src/frontend/swo/decoders/advanced.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class SWORTTAdvancedProcessor extends EventEmitter implements SWORTTDecod
1717
private ports: number[];
1818
private decoder: AdvancedDecoder;
1919
private timer = new HrTimer();
20+
private static outputPanels = new Map<string, vscode.OutputChannel>();
2021

2122
constructor(config: SWOAdvancedDecoderConfig) {
2223
super();
@@ -39,7 +40,15 @@ export class SWORTTAdvancedProcessor extends EventEmitter implements SWORTTDecod
3940
}
4041
try {
4142
this.decoder.init(config, this.displayOutput.bind(this), this.graphData.bind(this));
42-
this.output = vscode.window.createOutputChannel(`SWO/RTT: ${this.decoder.outputLabel() || ''} [type: ${this.decoder.typeName()}]`);
43+
const name = `SWO/RTT: ${this.decoder.outputLabel() || ''} [type: ${this.decoder.typeName()}]`;
44+
let panel = SWORTTAdvancedProcessor.outputPanels.get(name);
45+
if (!panel) {
46+
panel = vscode.window.createOutputChannel(name);
47+
SWORTTAdvancedProcessor.outputPanels.set(name, panel);
48+
} else {
49+
panel.clear();
50+
}
51+
this.output = panel;
4352
} catch (e) {
4453
throw new Error(`Error initializing decoder class. Potential issues with outputLabel(), typeName() or init(): ${e.toString()}`);
4554
}
@@ -96,7 +105,8 @@ export class SWORTTAdvancedProcessor extends EventEmitter implements SWORTTDecod
96105

97106
public dispose() {
98107
try {
99-
this.output.dispose();
108+
// We are recycling these now. So, do not dispose()
109+
// this.output.dispose();
100110
} finally {
101111
this.output = undefined;
102112
this.close();
@@ -110,7 +120,7 @@ export class SWORTTAdvancedProcessor extends EventEmitter implements SWORTTDecod
110120
} catch (e) {
111121
CortexDebugChannel.debugMessage('Error: in dispose() for decoder ' + e.toString());
112122
}
113-
this.decoder = undefined;
114123
}
124+
this.decoder = undefined;
115125
}
116126
}

0 commit comments

Comments
 (0)