Skip to content

Commit 5560b9c

Browse files
authored
gdb: fix issue "Debug not enabled" when gdb feature was enabled (#678)
- This happened due to a message that was sent from the Hypervisor to the `gdb` thread even if the sandbox had no debug enabled. The transmission failed and returned this error. - The fix checks a condition before sending this signal so that to ensure the sandbox has debugging enabled Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 6ab6b2c commit 5560b9c

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

src/hyperlight_host/examples/guest-debugging/main.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,51 @@ fn get_sandbox_cfg() -> Option<SandboxConfiguration> {
4141
fn main() -> hyperlight_host::Result<()> {
4242
let cfg = get_sandbox_cfg();
4343

44+
// Create an uninitialized sandbox with a guest binary and debug enabled
45+
let mut uninitialized_sandbox_dbg = UninitializedSandbox::new(
46+
hyperlight_host::GuestBinary::FilePath(
47+
hyperlight_testing::simple_guest_as_string().unwrap(),
48+
),
49+
cfg, // sandbox configuration
50+
)?;
51+
4452
// Create an uninitialized sandbox with a guest binary
4553
let mut uninitialized_sandbox = UninitializedSandbox::new(
4654
hyperlight_host::GuestBinary::FilePath(
4755
hyperlight_testing::simple_guest_as_string().unwrap(),
4856
),
49-
cfg, // sandbox configuration
57+
None, // sandbox configuration
5058
)?;
5159

60+
// Register a host functions
61+
uninitialized_sandbox_dbg.register("Sleep5Secs", || {
62+
thread::sleep(std::time::Duration::from_secs(5));
63+
Ok(())
64+
})?;
5265
// Register a host functions
5366
uninitialized_sandbox.register("Sleep5Secs", || {
5467
thread::sleep(std::time::Duration::from_secs(5));
5568
Ok(())
5669
})?;
5770
// Note: This function is unused, it's just here for demonstration purposes
5871

59-
// Initialize sandbox to be able to call host functions
72+
// Initialize sandboxes to be able to call host functions
73+
let mut multi_use_sandbox_dbg: MultiUseSandbox =
74+
uninitialized_sandbox_dbg.evolve(Noop::default())?;
6075
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve(Noop::default())?;
6176

6277
// Call guest function
63-
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
78+
let message =
79+
"Hello, World! I am executing inside of a VM with debugger attached :)\n".to_string();
80+
multi_use_sandbox_dbg
81+
.call_guest_function_by_name::<i32>(
82+
"PrintOutput", // function must be defined in the guest binary
83+
message.clone(),
84+
)
85+
.unwrap();
86+
87+
let message =
88+
"Hello, World! I am executing inside of a VM without debugger attached :)\n".to_string();
6489
multi_use_sandbox
6590
.call_guest_function_by_name::<i32>(
6691
"PrintOutput", // function must be defined in the guest binary

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ impl HypervLinuxDriver {
441441
// Send the interrupt handle to the GDB thread if debugging is enabled
442442
// This is used to allow the GDB thread to stop the vCPU
443443
#[cfg(gdb)]
444-
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
444+
if hv.debug.is_some() {
445+
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
446+
}
445447

446448
Ok(hv)
447449
}

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ impl HypervWindowsDriver {
356356
// Send the interrupt handle to the GDB thread if debugging is enabled
357357
// This is used to allow the GDB thread to stop the vCPU
358358
#[cfg(gdb)]
359-
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
359+
if hv.debug.is_some() {
360+
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
361+
}
360362

361363
Ok(hv)
362364
}

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ impl KVMDriver {
395395
// Send the interrupt handle to the GDB thread if debugging is enabled
396396
// This is used to allow the GDB thread to stop the vCPU
397397
#[cfg(gdb)]
398-
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
398+
if hv.debug.is_some() {
399+
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
400+
}
399401

400402
Ok(hv)
401403
}

src/tests/rust_guests/witguest/Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)