pub struct Btf { /* private fields */ }Expand description
Main representation of parsed BTF data. Provides helpers to resolve types and their associated names.
Implementations§
Source§impl Btf
impl Btf
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Parse a stand-alone BTF section from a file and construct a Rust
representation for later use. By default Backend::Cache is used.
Trying to open split BTF files using this function will fail. For split
BTF files use Btf::from_split_file.
Sourcepub fn from_file_with_backend<P: AsRef<Path>>(
path: P,
backend: Backend,
) -> Result<Self>
pub fn from_file_with_backend<P: AsRef<Path>>( path: P, backend: Backend, ) -> Result<Self>
Same as Btf::from_file but forcing a given Backend to be used.
This allows selecting the desired behavior and balance, but can fail if
a given Backend isn’t supported by the underlying system.
Sourcepub fn from_split_file<P: AsRef<Path>>(path: P, base: &Btf) -> Result<Btf>
pub fn from_split_file<P: AsRef<Path>>(path: P, base: &Btf) -> Result<Btf>
Parse a split BTF section from a file and construct a Rust
representation for later use. A base Btf containing the base section
must be provided.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Btf>
pub fn from_bytes(bytes: &[u8]) -> Result<Btf>
Perform the same actions as Btf::from_file, but fed with a byte
slice.
Sourcepub fn from_split_bytes(bytes: &[u8], base: &Btf) -> Result<Btf>
pub fn from_split_bytes(bytes: &[u8], base: &Btf) -> Result<Btf>
Performs the same actions as Btf::from_split_file, but fed with a
byte slice.
Sourcepub fn base(&self) -> &BtfSection
pub fn base(&self) -> &BtfSection
Returns a reference the base BTF section. For non-split Btf the base
BTF section holds the full BTF representation. Base BTF sections are
standalone representations (no reference to external BTF sections).
Sourcepub fn split(&self) -> Option<&BtfSection>
pub fn split(&self) -> Option<&BtfSection>
Returns a reference to the split BTF section, if any. A split BTF section is not a standalone representation (it uses references to a base BTF section).
Sourcepub fn resolve_ids_by_name(&self, name: &str) -> Result<Vec<u32>>
pub fn resolve_ids_by_name(&self, name: &str) -> Result<Vec<u32>>
Find a list of BTF ids with a given name.
Using an empty name ("") resolves anonymous ids.
Sourcepub fn resolve_type_by_id(&self, id: u32) -> Result<Type>
pub fn resolve_type_by_id(&self, id: u32) -> Result<Type>
Find a BTF type with a given id.
Sourcepub fn resolve_types_by_name(&self, name: &str) -> Result<Vec<Type>>
pub fn resolve_types_by_name(&self, name: &str) -> Result<Vec<Type>>
Find a list of BTF types with a given name.
Using an empty name ("") resolves anonymous types.
Sourcepub fn resolve_name(&self, type: &dyn BtfType) -> Result<String>
pub fn resolve_name(&self, type: &dyn BtfType) -> Result<String>
Resolve a name referenced by a Type which is defined in the current
Btf object.
Sourcepub fn type_iter(&self) -> TypeIter<'_>
pub fn type_iter(&self) -> TypeIter<'_>
Return an iterator over all types defined in the current BTF object.
Sourcepub fn resolve_chained_type<T: BtfType + ?Sized>(
&self,
type: &T,
) -> Result<Type>
pub fn resolve_chained_type<T: BtfType + ?Sized>( &self, type: &T, ) -> Result<Type>
Types can have a reference to another one, e.g. Ptr -> Int. This
helper resolve a Type referenced in an other one. It is the main helper
to traverse the Type tree.
Sourcepub fn chained_type_iter<T: BtfType + ?Sized>(
&self,
type: &T,
) -> ChainedTypeIter<'_> ⓘ
pub fn chained_type_iter<T: BtfType + ?Sized>( &self, type: &T, ) -> ChainedTypeIter<'_> ⓘ
This helper returns an iterator that allow to resolve a Type
referenced in another one all the way down to the chain.
The helper makes use of Btf::resolve_chained_type.