Skip to content

gdb: fix issue "Debug not enabled" when gdb feature was enabled #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/hyperlight_host/examples/guest-debugging/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,51 @@ fn get_sandbox_cfg() -> Option<SandboxConfiguration> {
fn main() -> hyperlight_host::Result<()> {
let cfg = get_sandbox_cfg();

// Create an uninitialized sandbox with a guest binary and debug enabled
let mut uninitialized_sandbox_dbg = UninitializedSandbox::new(
hyperlight_host::GuestBinary::FilePath(
hyperlight_testing::simple_guest_as_string().unwrap(),
),
cfg, // sandbox configuration
)?;

// Create an uninitialized sandbox with a guest binary
let mut uninitialized_sandbox = UninitializedSandbox::new(
hyperlight_host::GuestBinary::FilePath(
hyperlight_testing::simple_guest_as_string().unwrap(),
),
cfg, // sandbox configuration
None, // sandbox configuration
)?;

// Register a host functions
uninitialized_sandbox_dbg.register("Sleep5Secs", || {
thread::sleep(std::time::Duration::from_secs(5));
Ok(())
})?;
// Register a host functions
uninitialized_sandbox.register("Sleep5Secs", || {
thread::sleep(std::time::Duration::from_secs(5));
Ok(())
})?;
// Note: This function is unused, it's just here for demonstration purposes

// Initialize sandbox to be able to call host functions
// Initialize sandboxes to be able to call host functions
let mut multi_use_sandbox_dbg: MultiUseSandbox =
uninitialized_sandbox_dbg.evolve(Noop::default())?;
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve(Noop::default())?;

// Call guest function
let message = "Hello, World! I am executing inside of a VM :)\n".to_string();
let message =
"Hello, World! I am executing inside of a VM with debugger attached :)\n".to_string();
multi_use_sandbox_dbg
.call_guest_function_by_name::<i32>(
"PrintOutput", // function must be defined in the guest binary
message.clone(),
)
.unwrap();

let message =
"Hello, World! I am executing inside of a VM without debugger attached :)\n".to_string();
multi_use_sandbox
.call_guest_function_by_name::<i32>(
"PrintOutput", // function must be defined in the guest binary
Expand Down
4 changes: 3 additions & 1 deletion src/hyperlight_host/src/hypervisor/hyperv_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ impl HypervLinuxDriver {
// Send the interrupt handle to the GDB thread if debugging is enabled
// This is used to allow the GDB thread to stop the vCPU
#[cfg(gdb)]
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
if hv.debug.is_some() {
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
}

Ok(hv)
}
Expand Down
4 changes: 3 additions & 1 deletion src/hyperlight_host/src/hypervisor/hyperv_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ impl HypervWindowsDriver {
// Send the interrupt handle to the GDB thread if debugging is enabled
// This is used to allow the GDB thread to stop the vCPU
#[cfg(gdb)]
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
if hv.debug.is_some() {
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
}

Ok(hv)
}
Expand Down
4 changes: 3 additions & 1 deletion src/hyperlight_host/src/hypervisor/kvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ impl KVMDriver {
// Send the interrupt handle to the GDB thread if debugging is enabled
// This is used to allow the GDB thread to stop the vCPU
#[cfg(gdb)]
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
if hv.debug.is_some() {
hv.send_dbg_msg(DebugResponse::InterruptHandle(interrupt_handle))?;
}

Ok(hv)
}
Expand Down
18 changes: 9 additions & 9 deletions src/tests/rust_guests/witguest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading