Skip to content

Commit 06004ac

Browse files
authored
Merge pull request #340 from brownts/bugfix/mi_parser_stopped
Fix MI parser to allow async-record w/o a result.
2 parents 90d24ce + 40dc461 commit 06004ac

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/backend/mi_parse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const resultRecordRegex = /^(\d*)\^(done|running|connected|error|exit)/;
129129
const newlineRegex = /^\r\n?/;
130130
const endRegex = /^\(gdb\)\r\n?/;
131131
const variableRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*)/;
132-
const asyncClassRegex = /^(.*?),/;
132+
const asyncClassRegex = /^[^,\r\n]+/;
133133

134134
export function parseMI(output: string): MINode {
135135
/*
@@ -270,11 +270,11 @@ export function parseMI(output: string): MINode {
270270

271271
if (match[2]) {
272272
const classMatch = asyncClassRegex.exec(output);
273-
output = output.substr(classMatch[1].length);
273+
output = output.substring(classMatch[0].length);
274274
const asyncRecord = {
275275
isStream: false,
276276
type: asyncRecordType[match[2]],
277-
asyncClass: classMatch[1],
277+
asyncClass: classMatch[0],
278278
output: []
279279
};
280280
let result;

src/test/suite/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as glob from 'glob';
55
export function run(): Promise<void> {
66
// Create the mocha test
77
const mocha = new Mocha({
8-
ui: 'tdd'
8+
ui: 'tdd',
9+
useColors: true
910
});
10-
mocha.useColors(true);
1111

1212
const testsRoot = path.resolve(__dirname, '..');
1313

src/test/suite/mi_parse.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import * as assert from 'assert';
22
import { parseMI, MINode } from '../../backend/mi_parse';
33

44
suite("MI Parse", () => {
5+
test("Very simple out of band record", () => {
6+
const parsed = parseMI(`*stopped`);
7+
assert.ok(parsed);
8+
assert.strictEqual(parsed.token, undefined);
9+
assert.strictEqual(parsed.outOfBandRecord.length, 1);
10+
assert.strictEqual(parsed.outOfBandRecord[0].isStream, false);
11+
assert.strictEqual(parsed.outOfBandRecord[0].asyncClass, "stopped");
12+
assert.strictEqual(parsed.outOfBandRecord[0].output.length, 0);
13+
assert.strictEqual(parsed.resultRecords, undefined);
14+
});
515
test("Simple out of band record", () => {
616
const parsed = parseMI(`4=thread-exited,id="3",group-id="i1"`);
717
assert.ok(parsed);

0 commit comments

Comments
 (0)