Skip to content

Commit 7c3a60c

Browse files
committed
move gdb thread creation in hypervisor handler
- this helps with separation and testing Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 5c35e4e commit 7c3a60c

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/hyperlight_host/src/hypervisor/hypervisor_handler.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use vmm_sys_util::signal::SIGRTMIN;
3535
#[cfg(target_os = "windows")]
3636
use windows::Win32::System::Hypervisor::{WHvCancelRunVirtualProcessor, WHV_PARTITION_HANDLE};
3737

38+
#[cfg(gdb)]
39+
use super::gdb::create_gdb_thread;
3840
#[cfg(feature = "function_call_metrics")]
3941
use crate::histogram_vec_observe;
4042
#[cfg(gdb)]
@@ -906,6 +908,26 @@ fn set_up_hypervisor_partition(
906908
}
907909
}
908910
} else {
911+
// Create gdb thread if gdb is enabled and the configuration is provided
912+
// This is only done when the hypervisor is not in-process
913+
#[cfg(gdb)]
914+
let gdb_conn = if let Some(DebugInfo { port }) = debug_info {
915+
let gdb_conn = create_gdb_thread(*port, unsafe { pthread_self() });
916+
917+
// in case the gdb thread creation fails, we still want to continue
918+
// without gdb
919+
match gdb_conn {
920+
Ok(gdb_conn) => Some(gdb_conn),
921+
Err(e) => {
922+
log::error!("Could not create gdb connection: {:#}", e);
923+
924+
None
925+
}
926+
}
927+
} else {
928+
None
929+
};
930+
909931
match *get_available_hypervisor() {
910932
#[cfg(mshv)]
911933
Some(HypervisorType::Mshv) => {
@@ -926,7 +948,7 @@ fn set_up_hypervisor_partition(
926948
entrypoint_ptr.absolute()?,
927949
rsp_ptr.absolute()?,
928950
#[cfg(gdb)]
929-
debug_info,
951+
gdb_conn,
930952
)?;
931953
Ok(Box::new(hv))
932954
}

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use tracing::{instrument, Span};
2626

2727
use super::fpu::{FP_CONTROL_WORD_DEFAULT, FP_TAG_WORD_DEFAULT, MXCSR_DEFAULT};
2828
#[cfg(gdb)]
29-
use super::gdb::{create_gdb_thread, DebugCommChannel, DebugMsg, DebugResponse, VcpuStopReason};
29+
use super::gdb::{DebugCommChannel, DebugMsg, DebugResponse, VcpuStopReason};
3030
#[cfg(gdb)]
3131
use super::handlers::DbgMemAccessHandlerWrapper;
3232
use super::handlers::{MemAccessHandlerWrapper, OutBHandlerWrapper};
@@ -38,8 +38,6 @@ use crate::hypervisor::hypervisor_handler::HypervisorHandler;
3838
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
3939
use crate::mem::ptr::{GuestPtr, RawPtr};
4040
#[cfg(gdb)]
41-
use crate::sandbox::config::DebugInfo;
42-
#[cfg(gdb)]
4341
use crate::HyperlightError;
4442
use crate::{log_then_return, new_error, Result};
4543

@@ -604,7 +602,7 @@ impl KVMDriver {
604602
pml4_addr: u64,
605603
entrypoint: u64,
606604
rsp: u64,
607-
#[cfg(gdb)] debug_info: &Option<DebugInfo>,
605+
#[cfg(gdb)] gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
608606
) -> Result<Self> {
609607
let kvm = Kvm::new()?;
610608

@@ -632,23 +630,10 @@ impl KVMDriver {
632630
Self::setup_initial_sregs(&mut vcpu_fd, pml4_addr)?;
633631

634632
#[cfg(gdb)]
635-
let (debug, gdb_conn) = {
636-
if let Some(DebugInfo { port }) = debug_info {
637-
let gdb_conn = create_gdb_thread(*port, unsafe { pthread_self() });
638-
639-
// in case the gdb thread creation fails, we still want to continue
640-
// without gdb
641-
match gdb_conn {
642-
Ok(gdb_conn) => (Some(debug::KvmDebug::new()), Some(gdb_conn)),
643-
Err(e) => {
644-
log::error!("Could not create gdb connection: {:#}", e);
645-
646-
(None, None)
647-
}
648-
}
649-
} else {
650-
(None, None)
651-
}
633+
let (debug, gdb_conn) = if let Some(gdb_conn) = gdb_conn {
634+
(Some(debug::KvmDebug::new()), Some(gdb_conn))
635+
} else {
636+
(None, None)
652637
};
653638

654639
let rsp_gp = GuestPtr::try_from(RawPtr::from(rsp))?;

0 commit comments

Comments
 (0)