Skip to content

Commit

Permalink
Accumulate gdbserver output before checking for target port
Browse files Browse the repository at this point in the history
Because the needed output from gdbserver may not arrive as a single
'data' event on stdout we need to accumulate the output before
passing it to the regex checker.

Fixes eclipse-cdt-cloud#299
  • Loading branch information
jonahgraham committed Sep 22, 2023
1 parent 815600e commit 011776e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/GDBTargetDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class GDBTargetDebugSession extends GDBDebugSession {
await new Promise<void>((resolve, reject) => {
this.gdbserver = spawn(serverExe, serverParams, { cwd: serverCwd });
let gdbserverStartupResolved = false;
let accumulatedStdout = '';
let accumulatedStderr = '';
let checkTargetPort = (_data: any) => {
// do nothing by default
Expand All @@ -243,6 +244,9 @@ export class GDBTargetDebugSession extends GDBDebugSession {
const m = regex.exec(data);
if (m !== null) {
target.port = m[1];
checkTargetPort = (_data: any) => {
// do nothing now that we have our port
};
setTimeout(
() => {
gdbserverStartupResolved = true;
Expand All @@ -257,8 +261,12 @@ export class GDBTargetDebugSession extends GDBDebugSession {
}
if (this.gdbserver.stdout) {
this.gdbserver.stdout.on('data', (data) => {
this.sendEvent(new OutputEvent(data.toString(), 'server'));
checkTargetPort(data);
const out = data.toString();
if (!gdbserverStartupResolved) {
accumulatedStdout += out;
}
this.sendEvent(new OutputEvent(out, 'server'));
checkTargetPort(accumulatedStdout);
});
} else {
throw new Error('Missing stdout in spawned gdbserver');
Expand All @@ -267,9 +275,11 @@ export class GDBTargetDebugSession extends GDBDebugSession {
if (this.gdbserver.stderr) {
this.gdbserver.stderr.on('data', (data) => {
const err = data.toString();
accumulatedStderr += err;
if (!gdbserverStartupResolved) {
accumulatedStderr += err;
}
this.sendEvent(new OutputEvent(err, 'server'));
checkTargetPort(data);
checkTargetPort(accumulatedStderr);
});
} else {
throw new Error('Missing stderr in spawned gdbserver');
Expand Down

0 comments on commit 011776e

Please sign in to comment.