Struct btfparse::TypeInformation
source · pub struct TypeInformation { /* private fields */ }
Expand description
Type information acquired from the BTF data
Implementations§
source§impl TypeInformation
impl TypeInformation
sourcepub fn new(readable: &dyn Readable) -> BTFResult<Self>
pub fn new(readable: &dyn Readable) -> BTFResult<Self>
Creates a new TypeInformation
object
Examples found in repository?
examples/dump-btf.rs (line 44)
33 34 35 36 37 38 39 40 41 42 43 44 45 46
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 2 {
println!("Usage:\n\tdump-btf /path/to/btf/file\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
println!("{:?}", type_information.get());
}
More examples
examples/get-type-offset.rs (line 47)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 4 {
println!("Usage:\n\tget-type-offset /path/to/btf/file <type_name> <path>\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
let btf_type_name = &argument_list[2];
let type_path = &argument_list[3];
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
let offset = type_information
.offset_of(type_information.id_of(btf_type_name).unwrap(), type_path)
.unwrap();
println!("{} => {}: {:?}", btf_type_name, type_path, offset);
}
examples/get-type-size.rs (line 46)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 3 {
println!("Usage:\n\tget-type-size /path/to/btf/file <type_name>\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
let btf_type_name = &argument_list[2];
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
let type_id = type_information.id_of(btf_type_name).unwrap();
let type_size = type_information.size_of(type_id).unwrap();
println!(
"Type {} has ID {} and requires {} bytes in total",
btf_type_name, type_id, type_size
);
}
sourcepub fn get(&self) -> &BTreeMap<u32, TypeVariant>
pub fn get(&self) -> &BTreeMap<u32, TypeVariant>
Returns the entire type map
Examples found in repository?
examples/dump-btf.rs (line 45)
33 34 35 36 37 38 39 40 41 42 43 44 45 46
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 2 {
println!("Usage:\n\tdump-btf /path/to/btf/file\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
println!("{:?}", type_information.get());
}
sourcepub fn id_of(&self, type_name: &str) -> Option<u32>
pub fn id_of(&self, type_name: &str) -> Option<u32>
Returns the type id for the given type name
Examples found in repository?
examples/get-type-offset.rs (line 49)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 4 {
println!("Usage:\n\tget-type-offset /path/to/btf/file <type_name> <path>\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
let btf_type_name = &argument_list[2];
let type_path = &argument_list[3];
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
let offset = type_information
.offset_of(type_information.id_of(btf_type_name).unwrap(), type_path)
.unwrap();
println!("{} => {}: {:?}", btf_type_name, type_path, offset);
}
More examples
examples/get-type-size.rs (line 48)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 3 {
println!("Usage:\n\tget-type-size /path/to/btf/file <type_name>\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
let btf_type_name = &argument_list[2];
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
let type_id = type_information.id_of(btf_type_name).unwrap();
let type_size = type_information.size_of(type_id).unwrap();
println!(
"Type {} has ID {} and requires {} bytes in total",
btf_type_name, type_id, type_size
);
}
sourcepub fn from_id(&self, tid: u32) -> Option<TypeVariant>
pub fn from_id(&self, tid: u32) -> Option<TypeVariant>
Returns the type object for the given type id
sourcepub fn pointee_tid(&self, tid: u32) -> BTFResult<u32>
pub fn pointee_tid(&self, tid: u32) -> BTFResult<u32>
Returns the pointee type id
sourcepub fn size_of(&self, tid: u32) -> BTFResult<usize>
pub fn size_of(&self, tid: u32) -> BTFResult<usize>
Returns the size of the given type id
Examples found in repository?
examples/get-type-size.rs (line 49)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 3 {
println!("Usage:\n\tget-type-size /path/to/btf/file <type_name>\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
let btf_type_name = &argument_list[2];
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
let type_id = type_information.id_of(btf_type_name).unwrap();
let type_size = type_information.size_of(type_id).unwrap();
println!(
"Type {} has ID {} and requires {} bytes in total",
btf_type_name, type_id, type_size
);
}
sourcepub fn offset_of(&self, tid: u32, path: &str) -> BTFResult<(u32, Offset)>
pub fn offset_of(&self, tid: u32, path: &str) -> BTFResult<(u32, Offset)>
Returns a tuple containing the next type id and the current offset
Examples found in repository?
examples/get-type-offset.rs (line 49)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
let argument_list: Vec<String> = env::args().collect();
if argument_list.len() != 4 {
println!("Usage:\n\tget-type-offset /path/to/btf/file <type_name> <path>\n");
return;
}
let btf_file_path = Path::new(&argument_list[1]);
let btf_type_name = &argument_list[2];
let type_path = &argument_list[3];
println!("Opening BTF file: {:?}", btf_file_path);
let vmlinux_btf_file = ReadableFile::new(btf_file_path);
let type_information = TypeInformation::new(&vmlinux_btf_file).unwrap();
let offset = type_information
.offset_of(type_information.id_of(btf_type_name).unwrap(), type_path)
.unwrap();
println!("{} => {}: {:?}", btf_type_name, type_path, offset);
}
Auto Trait Implementations§
impl Freeze for TypeInformation
impl RefUnwindSafe for TypeInformation
impl Send for TypeInformation
impl Sync for TypeInformation
impl Unpin for TypeInformation
impl UnwindSafe for TypeInformation
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more