diff --git a/Poplar.toml b/Poplar.toml index a2d4f88340..c3232cec0e 100644 --- a/Poplar.toml +++ b/Poplar.toml @@ -20,6 +20,8 @@ user_tasks = [ "virtio_gpu user/virtio_gpu", "fb_console user/fb_console", ] +# Useful values: `virtio_*`, `usb_ehci_*`, `usb_packet_*`, `usb_*` +qemu_trace = "" [mq_pro] release = true diff --git a/tools/xtask/src/config.rs b/tools/xtask/src/config.rs index 029999525b..17a9412cf6 100644 --- a/tools/xtask/src/config.rs +++ b/tools/xtask/src/config.rs @@ -12,6 +12,7 @@ pub struct Config { pub release: bool, pub kernel_features: Vec, pub user_tasks: Vec, + pub qemu_trace: Option, } #[derive(Clone, Debug)] @@ -36,6 +37,7 @@ pub struct PlatformInfo { pub release: Option, pub kernel_features: Option>, pub user_tasks: Option>, + pub qemu_trace: Option, } impl Config { @@ -78,8 +80,9 @@ impl Config { UserTask { name, source_dir } }) .collect(); + let qemu_trace = platform_info.and_then(|info| info.qemu_trace.clone()); - Config { platform, release, kernel_features, user_tasks } + Config { platform, release, kernel_features, user_tasks, qemu_trace } } } diff --git a/tools/xtask/src/main.rs b/tools/xtask/src/main.rs index d7c0e54505..b3db6ad3a5 100644 --- a/tools/xtask/src/main.rs +++ b/tools/xtask/src/main.rs @@ -56,6 +56,7 @@ fn main() -> Result<()> { .debug_int_firehose(flags.debug_int_firehose) .debug_mmu_firehose(flags.debug_mmu_firehose) .debug_cpu_firehose(flags.debug_cpu_firehose) + .trace(config.qemu_trace) .run(), Platform::Rv64Virt => { let ramdisk = dist_result.build_ramdisk(); @@ -67,6 +68,7 @@ fn main() -> Result<()> { .ramdisk(Some(ramdisk)) .open_display(flags.display) .debug_int_firehose(flags.debug_int_firehose) + .trace(config.qemu_trace) .run() } _ => { diff --git a/tools/xtask/src/riscv/qemu.rs b/tools/xtask/src/riscv/qemu.rs index 1e071a9d38..e58d1f0533 100644 --- a/tools/xtask/src/riscv/qemu.rs +++ b/tools/xtask/src/riscv/qemu.rs @@ -10,6 +10,7 @@ pub struct RunQemuRiscV { pub open_display: bool, pub debug_int_firehose: bool, + pub trace: Option, } impl RunQemuRiscV { @@ -21,6 +22,7 @@ impl RunQemuRiscV { disk_image, open_display: false, debug_int_firehose: false, + trace: None, } } @@ -41,6 +43,10 @@ impl RunQemuRiscV { Self { debug_int_firehose: enabled, ..self } } + pub fn trace(self, trace: Option) -> Self { + Self { trace, ..self } + } + pub fn run(self) -> Result<()> { let mut qemu = Command::new("qemu-system-riscv64"); @@ -99,6 +105,10 @@ impl RunQemuRiscV { qemu.args(&["-monitor", "tcp:127.0.0.1:55555,server,nowait"]); } + if let Some(trace) = self.trace { + qemu.args(&["--trace", &trace]); + } + println!("QEMU command: {:?}", qemu); qemu.status() .wrap_err("Failed to invoke qemu-system-riscv")? diff --git a/tools/xtask/src/x64/qemu.rs b/tools/xtask/src/x64/qemu.rs index 1af807003a..0158ed8683 100644 --- a/tools/xtask/src/x64/qemu.rs +++ b/tools/xtask/src/x64/qemu.rs @@ -18,6 +18,7 @@ pub struct RunQemuX64 { pub debug_mmu_firehose: bool, /// Passes `-d cpu` to QEMU. Note that this disables KVM even if `kvm` is set. pub debug_cpu_firehose: bool, + pub trace: Option, /* * Firmware @@ -44,6 +45,7 @@ impl RunQemuX64 { debug_int_firehose: false, debug_mmu_firehose: false, debug_cpu_firehose: false, + trace: None, ovmf_dir: PathBuf::from("bundled/ovmf/"), ovmf_debugcon_to_file: false, @@ -68,6 +70,10 @@ impl RunQemuX64 { Self { debug_cpu_firehose: enabled, ..self } } + pub fn trace(self, trace: Option) -> Self { + Self { trace, ..self } + } + fn use_kvm(&self) -> bool { self.kvm && !(self.debug_int_firehose || self.debug_mmu_firehose || self.debug_cpu_firehose) } @@ -103,6 +109,10 @@ impl RunQemuX64 { // qemu.args(&["-smp", &self.cpus.to_string()]); qemu.args(&["-m", &self.ram.to_string()]); + if let Some(trace) = self.trace { + qemu.args(&["--trace", &trace]); + } + // Emit serial on both stdio and to a file qemu.args(&["-chardev", "stdio,id=char0,logfile=qemu_serial_x64.log"]); qemu.args(&["-serial", "chardev:char0"]);