Add GDB backend (for QEMU) - #399
Conversation
Adds a GDBBackend (OCDBackend registry member "gdb") that connects to a QEMU instance's gdbstub over TCP, so gnwmanager can target emulated devices the same way it targets physical ones via openocd/pyocd. Selected via the existing --backend/-b flag, with --gdb-host/--gdb-port to configure the target (defaults to localhost:1234).
Address ruff SIM105/N806/B904 and unused-import findings, and black formatting.
Addresses review feedback on the GDB/QEMU backend. - Route all socket I/O through _read()/_write() helpers that translate socket.timeout and OSError into GDBError. Previously raw socket timeouts escaped past the TransferErrors retry machinery and main.py's DebugProbeConnectionError handling everywhere except halt(). - Validate reply length in read_memory(). A stub may legally return fewer bytes than requested; that previously yielded silently truncated data to callers. - Decode run-length-encoded reply packets. QEMU does not emit these (gdb_put_packet_binary() copies payloads verbatim; its RLE handling is receive-side only), but the remote protocol permits any stub to. - reset() no longer suppresses GDBError, so a reset that did nothing can no longer report success, and it now unconditionally leaves the target running to match OpenOCDBackend/PyOCDBackend. - start_gdbserver() raises NotImplementedError naming QEMU's port rather than silently returning, which left `gnwmanager gdbserver` exiting instantly and `gnwmanager gdb` pointing gdb at a dead port. - Decode hex replies via _decode_hex() so malformed input raises GDBError instead of a bare ValueError. - close() resets _is_running. - Trim read_memory()'s justification comment to the general cpu_memory_rw_debug() argument, dropping references to a private tree. Adds tests/test_gdb_backend.py (20 tests) covering RLE expansion, short reads, malformed hex, timeout translation and reset/close state. Verified against qemu-gnw: info, tree, ls, push/pull, dump (256KB bank1 and 4MB ext, both byte-exact), flash, format, blank-bank boot, and flash-patch zelda, whose output is byte-identical to the reference zelda-bank1-patched.bin.
Correction: the RLE finding doesn't hold against QEMUThe report's only ≥80-confidence finding was that QEMU RLE-compresses reply packets, so I also checked it empirically rather than just by reading source — dumped 1 MB of erased I've implemented the RLE decoder anyway, since the remote protocol does permit any stub to use it and it's a few lines — just flagging that it's spec compliance rather than a bug fix, in case that Changes
New Verified against gwemu
Caveat: a pre-existing intermittent timeoutWhile testing I hit a timeout roughly 1 command in 8, at no consistent step. I A/B'd it by stashing my changes and running the same 8-command sequence 3× on each build: 4 failures / 24 steps before, 2 Root cause of the cascade, at least: once a |
Adds a GDBBackend (OCDBackend registry member "gdb") that connects to a QEMU instance's gdbstub over TCP, so gnwmanager can target emulated devices the same way it targets physical ones via openocd/pyocd. Selected via the existing --backend/-b flag, with --gdb-host/--gdb-port to configure the target (defaults to localhost:1234).