Skip to content
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
36 changes: 12 additions & 24 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,6 @@ pub fn build_microvm_for_boot(
let entry_point = load_kernel(&boot_config.kernel_file, vm.guest_memory())?;
let initrd = InitrdConfig::from_config(boot_config, vm.guest_memory())?;

#[cfg(feature = "gdb")]
let (gdb_tx, gdb_rx) = mpsc::channel();
#[cfg(feature = "gdb")]
vcpus
.iter_mut()
.for_each(|vcpu| vcpu.attach_debug_info(gdb_tx.clone()));
#[cfg(feature = "gdb")]
let vcpu_fds = vcpus
.iter()
.map(|vcpu| vcpu.copy_kvm_vcpu_fd(&vm))
.collect::<Result<Vec<_>, _>>()?;

if vm_resources.pci_enabled {
device_manager.enable_pci(&vm)?;
} else {
Expand Down Expand Up @@ -291,21 +279,21 @@ pub fn build_microvm_for_boot(
vcpus_exit_evt,
device_manager,
};

let vmm = Arc::new(Mutex::new(vmm));

#[cfg(feature = "gdb")]
if let Some(gdb_socket_path) = &vm_resources.machine_config.gdb_socket_path {
gdb::gdb_thread(
vmm.clone(),
vcpu_fds,
gdb_rx,
entry_point.entry_addr,
gdb_socket_path,
)
.map_err(StartMicrovmError::GdbServer)?;
} else {
debug!("No GDB socket provided not starting gdb server.");
{
let (gdb_tx, gdb_rx) = mpsc::channel();
vcpus
.iter_mut()
.for_each(|vcpu| vcpu.attach_debug_info(gdb_tx.clone()));

if let Some(gdb_socket_path) = &vm_resources.machine_config.gdb_socket_path {
gdb::gdb_thread(vmm.clone(), gdb_rx, entry_point.entry_addr, gdb_socket_path)
.map_err(StartMicrovmError::GdbServer)?;
} else {
debug!("No GDB socket provided not starting gdb server.");
}
}

// Move vcpus to their own threads and start their state machine in the 'Paused' state.
Expand Down
4 changes: 1 addition & 3 deletions src/vmm/src/gdb/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use gdbstub::conn::{Connection, ConnectionExt};
use gdbstub::stub::run_blocking::{self, WaitForStopReasonError};
use gdbstub::stub::{DisconnectReason, GdbStub, MultiThreadStopReason};
use gdbstub::target::Target;
use kvm_ioctls::VcpuFd;
use vm_memory::GuestAddress;

use super::target::{FirecrackerTarget, GdbTargetError, vcpuid_to_tid};
Expand All @@ -22,11 +21,10 @@ use crate::logger::{error, trace};
pub fn event_loop(
connection: UnixStream,
vmm: Arc<Mutex<Vmm>>,
vcpu_fds: Vec<VcpuFd>,
gdb_event_receiver: Receiver<usize>,
entry_addr: GuestAddress,
) {
let target = FirecrackerTarget::new(vmm, vcpu_fds, gdb_event_receiver, entry_addr);
let target = FirecrackerTarget::new(vmm, gdb_event_receiver, entry_addr);
let connection: Box<dyn ConnectionExt<Error = std::io::Error>> = { Box::new(connection) };
let debugger = GdbStub::new(connection);

Expand Down
14 changes: 7 additions & 7 deletions src/vmm/src/gdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::sync::{Arc, Mutex};

use arch::vcpu_set_debug;
use event_loop::event_loop;
use kvm_ioctls::VcpuFd;
use target::GdbTargetError;
use vm_memory::GuestAddress;

Expand All @@ -35,7 +34,6 @@ use crate::logger::trace;
/// communcation to the GDB server
pub fn gdb_thread(
vmm: Arc<Mutex<Vmm>>,
vcpu_fds: Vec<VcpuFd>,
gdb_event_receiver: Receiver<usize>,
entry_addr: GuestAddress,
socket_addr: &str,
Expand All @@ -44,10 +42,12 @@ pub fn gdb_thread(
// to be stopped as it connects. This also allows us to set breakpoints before kernel starts.
// This entry adddress is automatically used as it is not tracked inside the target state, so
// when resumed will be removed
vcpu_set_debug(&vcpu_fds[0], &[entry_addr], false)?;

for vcpu_fd in &vcpu_fds[1..] {
vcpu_set_debug(vcpu_fd, &[], false)?;
{
let vmm = vmm.lock().unwrap();
vcpu_set_debug(&vmm.vcpus_handles[0].vcpu_fd, &[entry_addr], false)?;
for handle in &vmm.vcpus_handles[1..] {
vcpu_set_debug(&handle.vcpu_fd, &[], false)?;
}
}

let path = Path::new(socket_addr);
Expand All @@ -59,7 +59,7 @@ pub fn gdb_thread(

std::thread::Builder::new()
.name("gdb".into())
.spawn(move || event_loop(connection, vmm, vcpu_fds, gdb_event_receiver, entry_addr))
.spawn(move || event_loop(connection, vmm, gdb_event_receiver, entry_addr))
.map_err(|_| GdbTargetError::GdbThreadError)?;

Ok(())
Expand Down
Loading