mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-28 01:16:50 +00:00
crosvm: simplify gdb setup
If we defer the gdb tube creation until `run_control`, we don't need to pass the tube around as much. TESTED=connect with gdb and step through some instructions Change-Id: I2821ad6353afaa09167acc08e3324d57c70f59dc Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5926547 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Frederick Mayle <fmayle@google.com>
This commit is contained in:
parent
9e675e62b9
commit
bb63b39cff
5 changed files with 17 additions and 35 deletions
|
@ -871,8 +871,6 @@ impl arch::LinuxArch for AArch64 {
|
|||
rt_cpus: components.rt_cpus,
|
||||
delay_rt: components.delay_rt,
|
||||
bat_control,
|
||||
#[cfg(feature = "gdb")]
|
||||
gdb: components.gdb,
|
||||
pm: None,
|
||||
resume_notify_devices: Vec::new(),
|
||||
root_config: pci_root,
|
||||
|
|
|
@ -360,8 +360,6 @@ pub struct VmComponents {
|
|||
pub force_s2idle: bool,
|
||||
pub fw_cfg_enable: bool,
|
||||
pub fw_cfg_parameters: Vec<FwCfgParameters>,
|
||||
#[cfg(feature = "gdb")]
|
||||
pub gdb: Option<(u32, Tube)>, // port and control tube.
|
||||
pub host_cpu_topology: bool,
|
||||
pub hugepages: bool,
|
||||
pub hv_cfg: hypervisor::Config,
|
||||
|
@ -401,8 +399,6 @@ pub struct RunnableLinuxVm<V: VmArch, Vcpu: VcpuArch> {
|
|||
pub bat_control: Option<BatControl>,
|
||||
pub delay_rt: bool,
|
||||
pub devices_thread: Option<std::thread::JoinHandle<()>>,
|
||||
#[cfg(feature = "gdb")]
|
||||
pub gdb: Option<(u32, Tube)>,
|
||||
pub hotplug_bus: BTreeMap<u8, Arc<Mutex<dyn HotPlugBus>>>,
|
||||
pub io_bus: Arc<Bus>,
|
||||
pub irq_chip: Box<dyn IrqChipArch>,
|
||||
|
|
|
@ -424,8 +424,6 @@ impl arch::LinuxArch for Riscv64 {
|
|||
delay_rt: components.delay_rt,
|
||||
suspend_tube: (Arc::new(Mutex::new(suspend_tube_send)), suspend_tube_recv),
|
||||
bat_control: None,
|
||||
#[cfg(feature = "gdb")]
|
||||
gdb: components.gdb,
|
||||
pm: None,
|
||||
devices_thread: None,
|
||||
vm_request_tubes: Vec::new(),
|
||||
|
|
|
@ -1407,8 +1407,6 @@ fn setup_vm_components(cfg: &Config) -> Result<VmComponents> {
|
|||
.collect::<Result<Vec<SDT>>>()?,
|
||||
rt_cpus: cfg.rt_cpus.clone(),
|
||||
delay_rt: cfg.delay_rt,
|
||||
#[cfg(feature = "gdb")]
|
||||
gdb: None,
|
||||
no_i8042: cfg.no_i8042,
|
||||
no_rtc: cfg.no_rtc,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
|
@ -1842,14 +1840,6 @@ where
|
|||
let mut all_control_tubes = Vec::new();
|
||||
let mut add_control_tube = |t| all_control_tubes.push(t);
|
||||
|
||||
#[cfg(feature = "gdb")]
|
||||
if let Some(port) = cfg.gdb {
|
||||
// GDB needs a control socket to interrupt vcpus.
|
||||
let (gdb_host_tube, gdb_control_tube) = Tube::pair().context("failed to create tube")?;
|
||||
add_control_tube(TaggedControlTube::Vm(gdb_host_tube).into());
|
||||
components.gdb = Some((port, gdb_control_tube));
|
||||
}
|
||||
|
||||
if let Some(ioapic_host_tube) = ioapic_host_tube {
|
||||
add_control_tube(AnyControlTube::IrqTube(ioapic_host_tube));
|
||||
}
|
||||
|
@ -3350,6 +3340,21 @@ fn run_control<V: VmArch + 'static, Vcpu: VcpuArch + 'static>(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gdb")]
|
||||
let (to_gdb_channel, gdb) = if let Some(port) = cfg.gdb {
|
||||
// GDB needs a control socket to interrupt vcpus.
|
||||
let (gdb_host_tube, gdb_control_tube) = Tube::pair().context("failed to create tube")?;
|
||||
control_tubes.push(TaggedControlTube::Vm(gdb_host_tube));
|
||||
// Create a channel for GDB thread.
|
||||
let (to_gdb_channel, from_vcpu_channel) = mpsc::channel();
|
||||
(
|
||||
Some(to_gdb_channel),
|
||||
Some((port, gdb_control_tube, from_vcpu_channel)),
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
#[derive(EventToken)]
|
||||
enum Token {
|
||||
VmEvent,
|
||||
|
@ -3409,15 +3414,6 @@ fn run_control<V: VmArch + 'static, Vcpu: VcpuArch + 'static>(
|
|||
drop_capabilities().context("failed to drop process capabilities")?;
|
||||
}
|
||||
|
||||
#[cfg(feature = "gdb")]
|
||||
// Create a channel for GDB thread.
|
||||
let (to_gdb_channel, from_vcpu_channel) = if linux.gdb.is_some() {
|
||||
let (s, r) = mpsc::channel();
|
||||
(Some(s), Some(r))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let (device_ctrl_tube, device_ctrl_resp) = Tube::pair().context("failed to create tube")?;
|
||||
// Create devices thread, and restore if a restore file exists.
|
||||
linux.devices_thread = match create_devices_worker_thread(
|
||||
|
@ -3627,16 +3623,12 @@ fn run_control<V: VmArch + 'static, Vcpu: VcpuArch + 'static>(
|
|||
|
||||
#[cfg(feature = "gdb")]
|
||||
// Spawn GDB thread.
|
||||
if let Some((gdb_port_num, gdb_control_tube)) = linux.gdb.take() {
|
||||
if let Some((gdb_port_num, gdb_control_tube, from_vcpu_channel)) = gdb {
|
||||
let to_vcpu_channels = vcpu_handles
|
||||
.iter()
|
||||
.map(|(_handle, channel)| channel.clone())
|
||||
.collect();
|
||||
let target = GdbStub::new(
|
||||
gdb_control_tube,
|
||||
to_vcpu_channels,
|
||||
from_vcpu_channel.unwrap(), // Must succeed to unwrap()
|
||||
);
|
||||
let target = GdbStub::new(gdb_control_tube, to_vcpu_channels, from_vcpu_channel);
|
||||
std::thread::Builder::new()
|
||||
.name("gdb".to_owned())
|
||||
.spawn(move || gdb_thread(target, gdb_port_num))
|
||||
|
|
|
@ -1231,8 +1231,6 @@ impl arch::LinuxArch for X8664arch {
|
|||
rt_cpus: components.rt_cpus,
|
||||
delay_rt: components.delay_rt,
|
||||
bat_control,
|
||||
#[cfg(feature = "gdb")]
|
||||
gdb: components.gdb,
|
||||
pm: Some(acpi_dev_resource.pm),
|
||||
root_config: pci,
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
|
|
Loading…
Reference in a new issue