LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
LIEF::dwarf::CompilationUnit Class Reference

This class represents a DWARF compilation unit. More...

#include <CompilationUnit.hpp>

Classes

class  Iterator
 
class  Language
 Languages supported by the DWARF (v5) format. See: https://dwarfstd.org/languages.html. More...
 

Public Types

using functions_it = iterator_range<Function::Iterator>
 Iterator over the dwarf::Function.
 
using types_it = iterator_range<Type::Iterator>
 Iterator over the dwarf::Type.
 
using vars_it = iterator_range<Variable::Iterator>
 Iterator over the CompilationUnit's variables.
 

Public Member Functions

 CompilationUnit (std::unique_ptr< details::CompilationUnit > impl)
 
 ~CompilationUnit ()
 
std::string name () const
 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.
 
std::string producer () const
 Information about the program (or library) that generated this compilation unit. For instance, it can output: Debian clang version 17.0.6.
 
std::string compilation_dir () const
 Return the path to the directory in which the compilation took place for compiling this compilation unit (e.g. /workdir/build)
 
Language language () const
 Original Language of this compilation unit.
 
uint64_t low_address () const
 Return the lowest virtual address owned by this compilation unit.
 
uint64_t high_address () const
 Return the highest virtual address owned by this compilation unit.
 
uint64_t size () const
 Return the size of the compilation unit according to its range of address.
 
std::vector< range_tranges () const
 Return a list of address ranges owned by this compilation unit.
 
std::unique_ptr< Functionfind_function (const std::string &name) const
 Try to find the function whose name is given in parameter.
 
std::unique_ptr< Functionfind_function (uint64_t addr) const
 Try to find the function at the given address.
 
std::unique_ptr< Variablefind_variable (uint64_t addr) const
 Try to find the Variable at the given address.
 
std::unique_ptr< Variablefind_variable (const std::string &name) const
 Try to find the Variable with the given name.
 
functions_it functions () const
 Return an iterator over the functions implemented in this compilation unit.
 
types_it types () const
 Return an iterator over the different types defined in this compilation unit.
 
vars_it variables () const
 Return an iterator over all the variables defined in the this compilation unit:
 

Detailed Description

This class represents a DWARF compilation unit.

Member Typedef Documentation

◆ functions_it

◆ types_it

◆ vars_it

Constructor & Destructor Documentation

◆ CompilationUnit()

LIEF::dwarf::CompilationUnit::CompilationUnit ( std::unique_ptr< details::CompilationUnit > impl)

◆ ~CompilationUnit()

LIEF::dwarf::CompilationUnit::~CompilationUnit ( )

Member Function Documentation

◆ compilation_dir()

std::string LIEF::dwarf::CompilationUnit::compilation_dir ( ) const

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 attribute

◆ find_function() [1/2]

std::unique_ptr< Function > LIEF::dwarf::CompilationUnit::find_function ( const std::string & name) const

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

The provided name can be demangled

◆ find_function() [2/2]

std::unique_ptr< Function > LIEF::dwarf::CompilationUnit::find_function ( uint64_t addr) const

Try to find the function at the given address.

◆ find_variable() [1/2]

std::unique_ptr< Variable > LIEF::dwarf::CompilationUnit::find_variable ( const std::string & name) const

Try to find the Variable with the given name.

◆ find_variable() [2/2]

std::unique_ptr< Variable > LIEF::dwarf::CompilationUnit::find_variable ( uint64_t addr) const

Try to find the Variable at the given address.

◆ functions()

functions_it LIEF::dwarf::CompilationUnit::functions ( ) const

Return an iterator over the functions 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.

◆ high_address()

uint64_t LIEF::dwarf::CompilationUnit::high_address ( ) const

Return the highest virtual address owned by this compilation unit.

◆ language()

Language LIEF::dwarf::CompilationUnit::language ( ) const

Original Language of this compilation unit.

This value matches the DW_AT_language attribute.

◆ low_address()

uint64_t LIEF::dwarf::CompilationUnit::low_address ( ) const

Return the lowest virtual address owned by this compilation unit.

◆ name()

std::string LIEF::dwarf::CompilationUnit::name ( ) const

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

◆ producer()

std::string LIEF::dwarf::CompilationUnit::producer ( ) const

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

◆ ranges()

std::vector< range_t > LIEF::dwarf::CompilationUnit::ranges ( ) const

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.

◆ size()

uint64_t LIEF::dwarf::CompilationUnit::size ( ) const

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.

◆ types()

types_it LIEF::dwarf::CompilationUnit::types ( ) const

Return an iterator over the different types defined in this compilation unit.

◆ variables()

vars_it LIEF::dwarf::CompilationUnit::variables ( ) const

Return an iterator over all the variables defined in the 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;
}

The documentation for this class was generated from the following file: