Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ export class MI2 extends EventEmitter implements IBackend {
}

private onOutputPartial(line) {
// A chunk may end after the digits of an MI result token, before '^done'.
// Keep those digits until we have the rest of the record or a newline.
if (/^\d+$/.test(line)) {
return false;
}
if (couldBeOutput(line)) {
this.logNoNewLine('stdout', line);
return true;
Expand Down
34 changes: 34 additions & 0 deletions test/suite/mi2_stream.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as assert from 'assert';
import { MI2 } from '../../src/backend/mi2/mi2';
import { MINode } from '../../src/backend/mi_parse';

suite('GDB/MI output stream', () => {
test('keeps a result token split from its record marker', () => {
const gdb = new MI2('gdb', []);
const messages: Array<[string, string]> = [];
let response: MINode = undefined;
gdb.on('msg', (type: string, message: string) => messages.push([type, message]));
(gdb as any).handlers[787] = (result: MINode) => {
response = result;
};

(gdb as any).stdout(Buffer.from('787'));
assert.strictEqual((gdb as any).buffer, '787');
assert.deepStrictEqual(messages, []);

(gdb as any).stdout(Buffer.from('^done,changelist=[]\n'));
assert.strictEqual(response.token, 787);
assert.strictEqual(response.resultRecords.resultClass, 'done');
assert.strictEqual((gdb as any).handlers[787], undefined);
assert.strictEqual((gdb as any).buffer, '');
});

test('still forwards a complete numeric output line', () => {
const gdb = new MI2('gdb', []);
const messages: Array<[string, string]> = [];
gdb.on('msg', (type: string, message: string) => messages.push([type, message]));

(gdb as any).stdout(Buffer.from('787\n'));
assert.deepStrictEqual(messages, [['stdout', '787\n']]);
});
});