Skip to content

Commit e4458ab

Browse files
committed
wip
1 parent 441af06 commit e4458ab

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

src/common.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,14 @@ export class RTTServerHelper {
456456
});
457457
}
458458

459-
public emitConfigures(cfg: RTTConfiguration, obj: EventEmitter): boolean {
459+
public emitConfigures(cfg: RTTConfiguration, executable: string, obj: EventEmitter): boolean {
460460
let ret = false;
461461
if (cfg.enabled) {
462462
for (const dec of cfg.decoders) {
463463
if (dec.tcpPort || dec.tcpPorts) {
464464
obj.emit('event', new RTTConfigureEvent({
465465
type: 'socket',
466+
executable: executable,
466467
decoder: dec
467468
}));
468469
ret = true;

src/frontend/extension.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { MemoryContentProvider } from './memory_content_provider';
1212
import Reporting from '../reporting';
1313

1414
import { CortexDebugConfigurationProvider } from './configprovider';
15-
import { JLinkSocketRTTSource, SocketRTTSource, SocketSWOSource, PeMicroSocketSource } from './swo/sources/socket';
15+
import { JLinkSocketRTTSource, SocketRTTSource, SocketSWOSource, PeMicroSocketSource, DefmtSocketRTTSource } from './swo/sources/socket';
1616
import { FifoSWOSource } from './swo/sources/fifo';
1717
import { FileSWOSource } from './swo/sources/file';
1818
import { SerialSWOSource } from './swo/sources/serial';
@@ -770,7 +770,7 @@ export class CortexDebugExtension {
770770
private receivedRTTConfigureEvent(e: vscode.DebugSessionCustomEvent) {
771771
if (e.body.type === 'socket') {
772772
const decoder: RTTCommonDecoderOpts = e.body.decoder;
773-
if ((decoder.type === 'console') || (decoder.type === 'binary')) {
773+
if ((decoder.type === 'console') || (decoder.type === 'binary') || (decoder.type === 'defmt')) {
774774
Reporting.sendEvent('RTT', 'Source', 'Socket: Console');
775775
this.rttCreateTerninal(e, decoder as RTTConsoleDecoderOpts);
776776
} else {
@@ -801,6 +801,8 @@ export class CortexDebugExtension {
801801
}
802802
if (mySession.config.servertype === 'jlink') {
803803
src = new JLinkSocketRTTSource(tcpPort, channel);
804+
} else if (e.body.decoder.type === 'defmt') {
805+
src = new DefmtSocketRTTSource(tcpPort, channel, e.body.executable);
804806
} else {
805807
src = new SocketRTTSource(tcpPort, channel);
806808
}

src/frontend/swo/sources/socket.ts

+28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { parseHostPort } from '../../../common';
55
import * as vscode from 'vscode';
66
import { TextDecoder } from 'util';
77
import { setFlagsFromString } from 'v8';
8+
import * as ChildProcess from 'child_process';
89

910
const TimerInterval = 250;
1011
export class SocketSWOSource extends EventEmitter implements SWORTTSource {
@@ -135,6 +136,33 @@ export class SocketRTTSource extends SocketSWOSource {
135136
}
136137
}
137138

139+
export class DefmtSocketRTTSource extends SocketRTTSource {
140+
private process: ChildProcess.ChildProcess;
141+
private executable: string;
142+
private cwd: string;
143+
144+
protected processData(buffer: Buffer): void {
145+
this.process.stdin.write(buffer);
146+
}
147+
148+
public start(timeout = (1000 * 60 * 5)): Promise<void> {
149+
this.process = ChildProcess.spawn(
150+
'defmt-print',['-e', this.executable], { cwd: this.cwd }
151+
);
152+
153+
this.process.stdout.on('data', (buffer) => this.emit('data', buffer));
154+
155+
return super.start(timeout);
156+
}
157+
158+
constructor(tcpPort: string, public readonly channel: number, executable: string) {
159+
super(tcpPort, channel);
160+
161+
this.executable = executable;
162+
this.cwd = process.cwd(); // TODO: Use workspace directory as cwd
163+
}
164+
}
165+
138166
export class JLinkSocketRTTSource extends SocketRTTSource {
139167
constructor(tcpPort: string, public readonly channel: number) {
140168
super(tcpPort, channel);

src/jlink.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,6 @@ export class JLinkServerController extends EventEmitter implements GDBServerCont
222222
}
223223
public debuggerLaunchStarted(): void {}
224224
public debuggerLaunchCompleted(): void {
225-
this.rttHelper.emitConfigures(this.args.rttConfig, this);
225+
this.rttHelper.emitConfigures(this.args.rttConfig, this.args.executable, this);
226226
}
227227
}

src/openocd.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export class OpenOCDServerController extends EventEmitter implements GDBServerCo
307307
this.session = obj;
308308
}
309309
public debuggerLaunchCompleted(): void {
310-
const hasRtt = this.rttHelper.emitConfigures(this.args.rttConfig, this);
310+
const hasRtt = this.rttHelper.emitConfigures(this.args.rttConfig, this.args.executable, this);
311311
if (this.args.ctiOpenOCDConfig?.enabled) {
312312
this.ctiStopResume(CTIAction.init);
313313
}

0 commit comments

Comments
 (0)