1 use std::env; 2 use std::process::Command; 3 use wasmtime::{Result, bail, error::Context as _}; 4 5 #[derive(Debug, Clone, Copy, PartialEq, Eq)] 6 pub enum DwarfDumpSection { 7 DebugInfo, 8 } 9 10 pub fn get_dwarfdump(obj: &str, section: DwarfDumpSection) -> Result<String> { 11 let dwarfdump = env::var("DWARFDUMP").unwrap_or("llvm-dwarfdump".to_string()); 12 let section_flag = match section { 13 DwarfDumpSection::DebugInfo => "-debug-info", 14 }; 15 let output = Command::new(&dwarfdump) 16 .args(&[section_flag, obj]) 17 .output() 18 .context(format!("failed to spawn `{dwarfdump}`"))?; 19 if !output.status.success() { 20 bail!( 21 "failed to execute {}: {}", 22 dwarfdump, 23 String::from_utf8_lossy(&output.stderr), 24 ); 25 } 26 Ok(String::from_utf8_lossy(&output.stdout).to_string()) 27 } 28