Struct lief::dwarf::CompilationUnit

pub struct CompilationUnit<'a> { /* private fields */ }
Expand description

A DWARF compilation unit

Implementations§

§

impl CompilationUnit<'_>

pub fn name(&self) -> String

Name of the file associated with this compilation unit (e.g. test.cpp) Return an empty string if the name is not found or can’t be resolved

This value matches the DW_AT_name attribute

pub fn producer(&self) -> String

Information about the program (or library) that generated this compilation unit. For instance, it can output: Debian clang version 17.0.6.

It returns an empty string if the producer is not present or can’t be resolved

This value matches the DW_AT_producer attribute

pub fn compilation_dir(&self) -> String

Return the path to the directory in which the compilation took place for compiling this compilation unit (e.g. /workdir/build)

It returns an empty string if the entry is not present or can’t be resolved

This value matches the DW_AT_comp_dir attributeducer` attribute

pub fn language(&self) -> Language

Original Language of this compilation unit.

This value matches the DW_AT_language attribute

pub fn low_address(&self) -> u64

Return the lowest virtual address owned by this compilation unit.

pub fn high_address(&self) -> u64

Return the highest virtual address owned by this compilation unit.

pub fn size(&self) -> u64

Return the size of the compilation unit according to its range of address.

If the compilation is fragmented (i.e. there are some address ranges between the lowest address and the highest that are not owned by the CU), then it returns the sum of all the address ranges owned by this CU.

If the compilation unit is not fragmented, then is basically returns high_address - low_address.

pub fn ranges(&self) -> Vec<Range>

Return a list of address ranges owned by this compilation unit.

If the compilation unit owns a contiguous range, it should return a single range.

pub fn functions(&self) -> Functions<'_>

Return an iterator over the functions Function implemented in this compilation unit.

Note that this iterator only iterates over the functions that have a concrete implementation in the compilation unit.

For instance with this code:

inline const char* get_secret_env() {
  return getenv("MY_SECRET_ENV");
}

int main() {
  printf("%s", get_secret_env());
  return 0;
}

The iterator will only return one function for main since get_secret_env is inlined and thus, its implementation is located in main.

pub fn variables(&self) -> CompilationUnitVariables<'_>

Return an iterator over the variables defined in the global scope of this compilation unit:

static int A = 1; // Returned by the iterator
static const char* B = "Hello"; // Returned by the iterator

int get() {
  static int C = 2; // Returned by the iterator
  return C;
}

pub fn types(&self) -> Types<'_>

pub fn function_by_name(&self, name: &str) -> Option<Function<'_>>

Try to find the function whose name is given in parameter.

The provided name can be demangled.

pub fn function_by_addr(&self, address: u64) -> Option<Function<'_>>

Try to find the function at the given address

pub fn variable_by_name(&self, name: &str) -> Option<Variable<'_>>

Try to find the variable whose name is given in parameter.

pub fn variable_by_addr(&self, address: u64) -> Option<Variable<'_>>

Try to find the variable at the given address

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for CompilationUnit<'a>

§

impl<'a> !Send for CompilationUnit<'a>

§

impl<'a> !Sync for CompilationUnit<'a>

§

impl<'a> Unpin for CompilationUnit<'a>

§

impl<'a> UnwindSafe for CompilationUnit<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.