Skip to content

Commit

Permalink
Ensure the terminating newline is received from gdbserver before pars…
Browse files Browse the repository at this point in the history
…ing port

We were parsing the port number from gdbserver before it had
been fully output. Use a regex now to wait for terminating
newline so we know gdbserver has output full port.
  • Loading branch information
jonahgraham committed Dec 10, 2024
1 parent 8c1d362 commit 9272451
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/integration-tests/attachRemote.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { expect } from 'chai';
describe('attach remote', function () {
let dc: CdtDebugClient;
let gdbserver: cp.ChildProcess;
let port: number;
let port: string;
const emptyProgram = path.join(testProgramsDir, 'empty');
const emptySrc = path.join(testProgramsDir, 'empty.c');

Expand All @@ -39,19 +39,18 @@ describe('attach remote', function () {
cwd: testProgramsDir,
}
);
port = await new Promise<number>((resolve, reject) => {
port = await new Promise<string>((resolve, reject) => {
const regex = new RegExp(/Listening on port ([0-9]+)\r?\n/);
let accumulatedStderr = '';
if (gdbserver.stderr) {
gdbserver.stderr.on('data', (data) => {
const line = String(data);
accumulatedStderr += line;
const LISTENING_ON_PORT = 'Listening on port ';
const index = accumulatedStderr.indexOf(LISTENING_ON_PORT);
if (index >= 0) {
const portStr = accumulatedStderr
.substr(index + LISTENING_ON_PORT.length, 6)
.trim();
resolve(parseInt(portStr, 10));
if (!port) {
const line = String(data);
accumulatedStderr += line;
const m = regex.exec(accumulatedStderr);
if (m !== null) {
resolve(m[1]);
}
}
});
} else {
Expand Down

0 comments on commit 9272451

Please sign in to comment.