Skip to content

Commit aa0f7f3

Browse files
retrocpugeekclaude
andcommitted
gdb: support async interrupt (ctrl-c) to break into a running guest
The stub drove continue by calling emu_start synchronously and only read the socket again once the target stopped on its own, so the bare \x03 break byte a client sends to pause a running target was never seen. A guest that free-runs (e.g. an idle/event loop) could not be interrupted at all -- gdb/Ghidra reported 'Cannot execute this command while the target is running'. Poll the client socket for the break byte from the per-instruction run hook (dbg_hook), which does run on the emulation thread during emu_start: - GdbSerialConn.poll_interrupt(): non-blocking select+recv, True on \x03. - QlGdbUtils.dbg_hook: throttled (every INTR_POLL_INTERVAL insns) check of an installed check_interrupt callback; on a break, stop emulation and record it. - handle_c: reply SIGINT when the stop was an interrupt rather than a breakpoint or normal exit. Verified against a free-running MIPS64 BE guest: \x03 -> S02 in <1ms; the existing gdb-stub regression test still passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b3fa0a2 commit aa0f7f3

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

qiling/debugger/gdb/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def __init__(self, ql: Qiling, entry_point: int, exit_point: int):
3535
self.interrupted = False
3636
self._poll_counter = 0
3737

38+
# async-interrupt support: `check_interrupt` is a callable installed by the
39+
# gdb stub that returns True when the client sent a break (ctrl-c / \x03)
40+
# while the target was running. `interrupted` records that the last resume
41+
# stopped for that reason (rather than a breakpoint or normal exit).
42+
self.check_interrupt = None
43+
self.interrupted = False
44+
self._poll_counter = 0
45+
3846
def __entry_point_hook(ql: Qiling):
3947
ql.hook_del(ep_hret)
4048
ql.hook_code(self.dbg_hook)

0 commit comments

Comments
 (0)