#[cfg_attr(not(feature = "dwarf"), allow(unused_variables))]
mod inspector;
pub mod source;
use std::borrow::Cow;
use std::ffi::OsStr;
use std::fmt::Debug;
use std::ops::ControlFlow;
use crate::Addr;
use crate::Result;
use crate::SymType;
pub use inspector::Inspector;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct SymInfo<'src> {
pub name: Cow<'src, str>,
pub addr: Addr,
pub size: Option<usize>,
pub sym_type: SymType,
pub file_offset: Option<u64>,
pub module: Option<Cow<'src, OsStr>>,
#[doc(hidden)]
pub _non_exhaustive: (),
}
impl SymInfo<'_> {
#[inline]
pub fn to_owned(&self) -> SymInfo<'static> {
SymInfo {
name: Cow::Owned(self.name.to_string()),
addr: self.addr,
size: self.size,
sym_type: self.sym_type,
file_offset: self.file_offset,
module: self
.module
.as_deref()
.map(|path| Cow::Owned(path.to_os_string())),
_non_exhaustive: (),
}
}
}
#[derive(Debug, Default)]
pub(crate) struct FindAddrOpts {
pub file_offset: bool,
pub sym_type: SymType,
}
pub(crate) type ForEachFn<'f> = dyn FnMut(&SymInfo<'_>) -> ControlFlow<()> + 'f;
pub(crate) trait Inspect
where
Self: Debug,
{
fn find_addr(&self, name: &str, opts: &FindAddrOpts) -> Result<Vec<SymInfo<'_>>>;
fn for_each(&self, opts: &FindAddrOpts, f: &mut ForEachFn<'_>) -> Result<()>;
}