Struct lief::dwarf::compilation_unit::CompilationUnit
pub struct CompilationUnit<'a> { /* private fields */ }
Expand description
A DWARF compilation unit
Implementations§
§impl CompilationUnit<'_>
impl CompilationUnit<'_>
pub fn name(&self) -> String
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
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
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
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
pub fn low_address(&self) -> u64
Return the lowest virtual address owned by this compilation unit.
pub fn high_address(&self) -> u64
pub fn high_address(&self) -> u64
Return the highest virtual address owned by this compilation unit.
pub fn size(&self) -> u64
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>
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<'_> ⓘ
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 imported_functions(&self) -> Functions<'_> ⓘ
pub fn imported_functions(&self) -> Functions<'_> ⓘ
Return an iterator over the functions imported in this compilation unit but not implemented.
For instance with this code:
#include <cstdio>
int main() {
printf("Hello\n");
return 0;
}
printf
is imported from the standard libc so the function is returned by
the iterator. On the other hand, main()
is implemented in this
compilation unit so it is not returned by CompilationUnit::imported_functions
but
CompilationUnit::functions
.
pub fn variables(&self) -> CompilationUnitVariables<'_> ⓘ
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<'_>>
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<'_>>
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<'_>>
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<'_>>
pub fn variable_by_addr(&self, address: u64) -> Option<Variable<'_>>
Try to find the variable at the given address