Path: blob/main/tests/all/native_debug/dump.rs
2450 views
use anyhow::{Context, Result, bail};1use std::env;2use std::process::Command;34#[derive(Debug, Clone, Copy, PartialEq, Eq)]5pub enum DwarfDumpSection {6DebugInfo,7}89pub fn get_dwarfdump(obj: &str, section: DwarfDumpSection) -> Result<String> {10let dwarfdump = env::var("DWARFDUMP").unwrap_or("llvm-dwarfdump".to_string());11let section_flag = match section {12DwarfDumpSection::DebugInfo => "-debug-info",13};14let output = Command::new(&dwarfdump)15.args(&[section_flag, obj])16.output()17.context(format!("failed to spawn `{dwarfdump}`"))?;18if !output.status.success() {19bail!(20"failed to execute {}: {}",21dwarfdump,22String::from_utf8_lossy(&output.stderr),23);24}25Ok(String::from_utf8_lossy(&output.stdout).to_string())26}272829