use std::sync::Arc;
use symbolic::common::Arch;
use symbolic::debuginfo::Archive;
use crate::common;
use crate::mapping::PathMappings;
use crate::object_info::ObjectInfo;
use crate::platform::Platform;
impl ObjectInfo {
pub fn from_macho(
buf: &[u8],
file_name: &str,
arch: Arch,
mapping: Option<Arc<PathMappings>>,
collect_inlines: bool,
) -> common::Result<Self> {
let archive = Archive::parse(buf)?;
let object = if archive.object_count() == 1 {
archive.object_by_index(0).unwrap()
} else {
archive
.objects()
.filter_map(|o| o.ok())
.find(|o| o.arch() == arch)
};
if let Some(object) = object {
ObjectInfo::from_object(
&object,
file_name,
None,
None,
Platform::Mac,
mapping,
collect_inlines,
)
} else {
anyhow::bail!(
"Cannot find a valid object for architecture {} in file {}",
arch.name(),
file_name
);
}
}
}
pub fn print_macho_architectures(buf: &[u8], file_name: String) -> common::Result<()> {
let archive = Archive::parse(buf)?;
let archs = archive
.objects()
.map(|o| o.unwrap().arch().name())
.collect::<Vec<_>>();
println!(
"{} contains the following architecture{}:",
file_name,
if archs.len() == 1 { "" } else { "s" }
);
println!("{}", archs.join(", "));
Ok(())
}