Skip to content

Commit 3299c1f

Browse files
committed
fix crash when gdb connection closes
- wait for another gdb connection to reattach Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 80a5147 commit 3299c1f

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/hyperlight_host/src/hypervisor/gdb/event_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ impl run_blocking::BlockingEventLoop for GdbBlockingEventLoop {
7777

7878
pub fn event_loop_thread(
7979
debugger: GdbStub<HyperlightKvmSandboxTarget, Box<dyn ConnectionExt<Error = std::io::Error>>>,
80-
mut target: HyperlightKvmSandboxTarget,
80+
target: &mut HyperlightKvmSandboxTarget,
8181
) {
82-
match debugger.run_blocking::<GdbBlockingEventLoop>(&mut target) {
82+
match debugger.run_blocking::<GdbBlockingEventLoop>(target) {
8383
Ok(disconnect_reason) => match disconnect_reason {
8484
DisconnectReason::Disconnect => log::info!("Gdb client disconnected"),
8585
DisconnectReason::TargetExited(code) => {

src/hyperlight_host/src/hypervisor/gdb/mod.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,34 @@ pub fn create_gdb_thread(mut target: HyperlightKvmSandboxTarget) -> Result<(), G
104104
let _handle = thread::Builder::new()
105105
.name("GDB handler".to_string())
106106
.spawn(move || -> Result<(), GdbTargetError> {
107-
log::info!("Waiting for GDB connection ... ");
108-
let (conn, _) = listener
109-
.accept()
110-
.map_err(|_| GdbTargetError::ListenerError)?;
111-
112-
let conn: Box<dyn ConnectionExt<Error = std::io::Error>> = Box::new(conn);
113-
let debugger = GdbStub::new(conn);
114-
115-
if let DebugMessage::VcpuStoppedEv = target.recv()? {
116-
target.pause_vcpu();
117-
118-
event_loop_thread(debugger, target);
119-
120-
Ok(())
121-
} else {
122-
Err(GdbTargetError::UnexpectedMessageError)
123-
}
107+
let mut initial_conn = true;
108+
let result = loop {
109+
log::info!("Waiting for GDB connection ... ");
110+
let (conn, _) = listener
111+
.accept()
112+
.map_err(|_| GdbTargetError::ListenerError)?;
113+
114+
let conn: Box<dyn ConnectionExt<Error = std::io::Error>> = Box::new(conn);
115+
let debugger = GdbStub::new(conn);
116+
117+
if initial_conn {
118+
// Waits for vCPU to stop at entrypoint breakpoint
119+
if let DebugMessage::VcpuStoppedEv = target.recv()? {
120+
target.pause_vcpu();
121+
122+
event_loop_thread(debugger, &mut target);
123+
initial_conn = false;
124+
} else {
125+
break Err(GdbTargetError::UnexpectedMessageError)
126+
}
127+
}
128+
else {
129+
log::info!("Reattaching GDB connection ... ");
130+
event_loop_thread(debugger, &mut target);
131+
}
132+
};
133+
134+
result
124135
})
125136
.map_err(|_| GdbTargetError::SpawnThreadError)?;
126137

0 commit comments

Comments
 (0)