Add asynchronous machine over and out to shared MCP

This commit is contained in:
Александр Петров
2026-09-17 23:32:46 +03:00
parent 259c782190
commit a8d0692eb2
15 changed files with 241 additions and 19 deletions
+36 -1
View File
@@ -109,8 +109,43 @@ async def probe() -> None:
after_dap = await call('session_status')
if after_dap['phase'] != 'ready' or after_dap['session_id'] != status['session_id']:
raise RuntimeError('DAP disconnect завершил MCP-owned MAME')
lines = disassembly['text'].splitlines()
addresses = [int(line.split(':', 1)[0], 16) for line in lines]
calls = [index for index, line in enumerate(lines)
if ' call ' in ' ' + line.lower() + ' ']
if len(calls) < 2 or calls[0] != 0 or calls[1] <= 1:
raise RuntimeError('Нет двух call в main: ' + disassembly['text'])
async def wait_machine_stop() -> dict:
deadline = time.monotonic() + 10
while time.monotonic() < deadline:
if not (await call('session_status'))['running']:
return await call('where')
await asyncio.sleep(.05)
paused = await call('pause_execution')
raise TimeoutError('Машинный шаг не завершился; Pause PC=' +
hex(paused['pc']))
await call('step_over_instruction', {'count': 1})
after_over = await wait_machine_stop()
if after_over['pc'] != addresses[1]:
raise RuntimeError('over call не остановился после вызова: ' +
repr(after_over))
await call('step_over_instruction', {'count': calls[1] - 1})
at_call = await wait_machine_stop()
if at_call['pc'] != addresses[calls[1]]:
raise RuntimeError('over count не дошёл до второго call: ' +
repr(at_call))
entered = await call('step_instruction', {'count': 1})
if entered['pc'] == at_call['pc']:
raise RuntimeError('Машинный step не вошёл в возвращаемый вызов')
await call('step_out_instruction')
returned = await wait_machine_stop()
if returned['pc'] != addresses[calls[1] + 1]:
raise RuntimeError('Машинный out не вернулся после call: ' +
repr(returned))
stepped = await call('step_instruction', {'count': 3})
if stepped['pc'] == location['pc'] or \
if stepped['pc'] == returned['pc'] or \
(await call('session_status'))['running']:
raise RuntimeError('Три машинных шага не остановились: ' + repr(stepped))
source = str(ROOT / 'tests/hello/hello.c')