diff --git a/src/agent/coverage/src/record.rs b/src/agent/coverage/src/record.rs index 30b01886ad..2f28fa1b11 100644 --- a/src/agent/coverage/src/record.rs +++ b/src/agent/coverage/src/record.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use std::process::{Command, Output, Stdio}; +use std::process::{Command, ExitStatus, Stdio}; use std::sync::Arc; use std::time::Duration; @@ -85,7 +85,7 @@ impl CoverageRecorder { let (mut dbg, child) = Debugger::init(self.cmd, &mut recorder)?; dbg.run(&mut recorder)?; - let output = child.wait_with_output()?; + let output = child.wait_with_output()?.into(); let coverage = recorder.coverage; Ok(Recorded { coverage, output }) @@ -98,3 +98,24 @@ pub struct Recorded { pub coverage: BinaryCoverage, pub output: Output, } + +#[derive(Clone, Debug, Default)] +pub struct Output { + pub status: Option, + pub stderr: String, + pub stdout: String, +} + +impl From for Output { + fn from(output: std::process::Output) -> Self { + let status = Some(output.status); + let stdout = String::from_utf8_lossy(&output.stdout).into_owned(); + let stderr = String::from_utf8_lossy(&output.stderr).into_owned(); + + Self { + status, + stdout, + stderr, + } + } +} diff --git a/src/agent/coverage/src/record/linux/debugger.rs b/src/agent/coverage/src/record/linux/debugger.rs index d3bd2e2238..8f0f462631 100644 --- a/src/agent/coverage/src/record/linux/debugger.rs +++ b/src/agent/coverage/src/record/linux/debugger.rs @@ -2,7 +2,8 @@ // Licensed under the MIT License. use std::collections::BTreeMap; -use std::process::{Command, Output}; +use std::io::Read; +use std::process::Command; use anyhow::{bail, format_err, Result}; use debuggable_module::path::FilePath; @@ -10,6 +11,8 @@ use debuggable_module::Address; use pete::{Ptracer, Restart, Signal, Stop, Tracee}; use procfs::process::{MMapPath, MemoryMap, Process}; +use crate::record::Output; + pub trait DebugEventHandler { fn on_breakpoint(&mut self, dbg: &mut DebuggerContext, tracee: &mut Tracee) -> Result<()>; @@ -46,7 +49,30 @@ impl<'eh> Debugger<'eh> { return Err(err); } - let output = child.wait_with_output()?; + // Currently unavailable on Linux. + let status = None; + + let stdout = if let Some(mut pipe) = child.stdout { + let mut stdout = Vec::new(); + pipe.read_to_end(&mut stdout)?; + String::from_utf8_lossy(&stdout).into_owned() + } else { + "".into() + }; + + let stderr = if let Some(mut pipe) = child.stderr { + let mut stderr = Vec::new(); + pipe.read_to_end(&mut stderr)?; + String::from_utf8_lossy(&stderr).into_owned() + } else { + "".into() + }; + + let output = Output { + status, + stderr, + stdout, + }; Ok(output) }