use gimli::UnitSectionOffset;
use super::unit::UnitRef;
use crate::{
die::utils::{get_lang_attr, pretty_print_die_entry},
file::{DebugFile, RawDie},
DwarfDb,
};
#[salsa::interned(debug)]
#[derive(Ord, PartialOrd)]
pub struct CompilationUnitId<'db> {
pub file: DebugFile,
pub offset: UnitSectionOffset<usize>,
}
impl<'db> CompilationUnitId<'db> {
pub fn unit_ref(&self, db: &'db dyn DwarfDb) -> Option<UnitRef<'db>> {
super::unit::get_unit_ref(db, self.file(db), self.offset(db))
}
}
pub fn is_rust_cu(root: &RawDie<'_>, unit_ref: &UnitRef<'_>) -> bool {
match get_lang_attr(root, unit_ref) {
Ok(Some(lang)) if lang == gimli::DW_LANG_Rust => {
true
}
Ok(_) => {
tracing::debug!(
"skipping non-Rust compilation unit: {}",
pretty_print_die_entry(root, unit_ref)
);
false
}
Err(e) => {
tracing::error!(
"could not get language of compilation unit: {e}: \n{}",
pretty_print_die_entry(root, unit_ref),
);
false
}
}
}