Files
reverse-engineering-anything/scripts
morluto 43934682ab refactor(gdb): parse MI result records with one typed record parser (#10799)
* refactor(gdb): parse MI result records with one typed record parser

GdbSessionManager recognized ^done with a prefix regex at seven sites, kept a hand-written span scanner and a second character scanner for -list-thread-groups, and decoded C-string fields with a dynamic RegExp. src/gdb/GdbMiRecord.ts now parses a result record into its token, class and typed results (C-string bytes, tuples, value lists and result lists), and returns a typed malformed-mi-record failure with a reason and offset. The done checks, the thread-group PID inventory and the C-string field reader use it; the stream dispatcher reads only the record header through the same module. An architecture guard keeps MI result-record regexes in the owner.

* perf(gdb): encode each unescaped C-string run once

The MI C-string decoder allocated a Buffer per unescaped character, pushed every byte into a number array, and copied the rest of the line for each hex or octal escape. It now validates unescaped runs in place, encodes each run once, reads escapes with sticky patterns, and joins the chunks once. On a 12.1 MiB groups reply: 887/832 ms elapsed and 818/775 ms CPU before, 76/76 ms elapsed and 131/128 ms CPU after; peak RSS 152-170 MiB both.

* test(gdb): refuse a malformed ^done for a startup setting through a real session

A fake GDB answers -gdb-set auto-load off with ^done,msg="unterminated. The session must not start: the typed MI record parser refuses the record, where main's ^done prefix match accepted it (the case fails against main's GdbSessionManager).

* feat(gdb): record the GDB version from -gdb-version in session Evidence (#10865)

* feat(gdb): record the GDB version from -gdb-version in session Evidence

Startup now asks -gdb-version before the auto-load setting and reads its first console stream record through a new MI stream-record parser (parseGdbMiStreamRecord). Each session's Evidence names that version; an unrecognised banner, malformed record or refused query leaves it null (unknown), as before.

Fake GDB fixtures answer -gdb-version from one owner in gdbTestHelpers: a stdin preamble for scripted fakes and answerFakeGdbStartup for in-process fakes, so scenarios model only their own commands.

* fix(gdb): leave a lossily decoded version unknown and frame fake startup replies by line

* test(gdb): reject unmodeled commands in the lossy version banner fixture

* test(gdb): refuse commands the scripted fake GDBs do not model (#10947)

* test(gdb): refuse commands the scripted fake GDBs do not model

* test(gdb): match the migrated fakes' special commands exactly
2026-11-15 17:01:45 +08:00
..