Struct btfparse::TypeInformation

source ·
pub struct TypeInformation { /* private fields */ }
Expand description

Type information acquired from the BTF data

Implementations§

source§

impl TypeInformation

source

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
Hide additional 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
    );
}
source

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());
}
source

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
Hide additional 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
    );
}
source

pub fn from_id(&self, tid: u32) -> Option<TypeVariant>

Returns the type object for the given type id

source

pub fn name_of(&self, tid: u32) -> Option<String>

Returns the name of the given type id

source

pub fn pointee_tid(&self, tid: u32) -> BTFResult<u32>

Returns the pointee type id

source

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
    );
}
source

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§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.