Serve gdb on the vCPU thread

未關閉
#1,974 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
25/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust
領域
backend

研究方向

Read the referenced event loop in src/hyperlight_host/src/hypervisor/gdb/event_loop.rs, session setup in src/hyperlight_host/src/hypervisor/gdb/mod.rs, and crash handling in src/hyperlight_host/src/hypervisor/hyperlight_vm/mod.rs. Then inspect the gdb tests and the draft’s stated design: drive GdbStubStateMachine from the vCPU thread and keep the session on HyperlightVm. Done means the listed failure cases are fixed, the Ctrl-C end-to-end case passes, and the open questions about detach and Sandbox::recreate are resolved.

由索引模型根據 Issue 內容生成。

描述

C-question

gdbstub runs on a separate thread and talks to the vCPU thread through two channels. That needs 12 request and 16 reply message kinds, a startup handshake that sends the interrupt handle, and a loop that watches both the channel and the socket.

Problems this causes on main:

  • The stop-reason loop spins at 100% CPU while the guest runs. Each pass toggles O_NONBLOCK and peeks the socket (event_loop.rs#L85).
  • Ctrl-C while the vCPU is not running, for example during a host call, ends the gdb session. on_interrupt returns a fatal error (event_loop.rs#L108).
  • A sandbox from a running snapshot can be dropped before a client connects. Its gdb thread then stays blocked in accept() and holds the port forever (mod.rs#L305). Later sandboxes on that port only log an error and run without gdb.
  • An unexpected disconnect leaves debugging enabled and int3 bytes in memory. The next debug exit fails the guest call. The docs say the guest continues (how-to-debug-a-hyperlight-guest.md#L29).
  • If reporting a crash to gdb fails, the ? returns that debug error instead of the guest's error (hyperlight_vm/mod.rs#L798).
  • The gdb thread's spawn result and errors are discarded (mod.rs#L301).

Proposal:

  • The vCPU thread drives gdbstub's GdbStubStateMachine at each debug stop. gdbstub's Target is implemented on HyperlightVm, so requests call the VM directly. The message enums go away.
  • HyperlightVm owns a GdbSession with the listener and the connection. Dropping the sandbox frees the port.
  • The client is accepted at the first debug stop. A client may connect before the vCPU stops.
  • A small watcher thread blocks in peek on a clone of the socket while the guest runs. On data it calls kill_from_debugger. This is the only extra thread.
  • While stopped, the target holds clones of the HostSharedMemory handles. This avoids lifetimes and unsafe.

Draft result (not yet pushed): about 650 fewer lines. It passes all gdb tests on KVM, plus a new end-to-end Ctrl-C test. It fixes every problem above, #1973, and the rbx read in #1971.

Open questions:

  • Attaching again after a detach (see #1210).
  • Moving the session to the new VM in Sandbox::recreate.
主要語言
Rust
星號
4.8k
分支
222
平均合併
1 天 16 小時
30 天內合併 PR
60

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

hyperlight-dev/hyperlight 的其他 Issue

查看 hyperlight-dev/hyperlight 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。