Load the DWARF from the given path
Bases: DebugInfo
This class represents a DWARF debug information. It can embed different compilation units which can be accessed through compilation_units
.
This class can be instantiated from lief.Binary.debug_info
Iterator on the CompilationUnit embedded in this dwarf
Overloaded function.
find_function(self, name: str) -> Optional[lief._lief.dwarf.Function]
Try to find the function with the given name (mangled or not)
info: lief.dwarf.DebugInfo = ... if func := info.find_function("_ZNSt6localeD1Ev"): print("Found") if func := info.find_function("std::locale::~locale()"): print("Found")
find_function(self, addr: int) -> Optional[lief._lief.dwarf.Function]
Try to find the function at the given virtual address.
Try to find the type with the given name.
Overloaded function.
find_variable(self, addr: int) -> Optional[lief._lief.dwarf.Variable]
Try to find the (static) variable at the given virtual address.
find_variable(self, name: str) -> Optional[lief._lief.dwarf.Variable]
Try to find the variable with the given name. This name can be mangled or not.
Bases: object
This class represents a DWARF compilation unit
Bases: object
Languages supported by the DWARF (v5) format. See: https://dwarfstd.org/languages.html
Some languages (like C++11, C++17, ..) have a version (11, 17, …) which is stored in a dedicated attribute: version
Bases: object
The underlying integer value
The language itself
Version of the language (e.g. 17 for C++17)
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.
Overloaded function.
find_function(self, name: str) -> Optional[lief._lief.dwarf.Function]
Try to find the function whose name is given in parameter.
The provided name can be demangled.
find_function(self, addr: int) -> Optional[lief._lief.dwarf.Function]
Try to find the function at the given address
Overloaded function.
find_variable(self, addr: int) -> Optional[lief._lief.dwarf.Variable]
Try to find the variable at the given address
find_variable(self, name: str) -> Optional[lief._lief.dwarf.Variable]
Try to find the variable with the given name (mangled or not)
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
.
Return the highest virtual address owned by this compilation unit
Original language of this compilation unit.
This value matches the DW_AT_language
attribute.
Return the lowest virtual address owned by this compilation unit.
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.
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.
Return a list of address ranges owned by this compilation unit.
If the compilation unit owns a contiguous range, it returns a single range.
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 it basically returns high_address - low_address
.
Return an iterator over the different types defined in this compilation unit.
Return an iterator over the variables defined in the any 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;
}
Bases: object
This class represents a DWARF function which can be associated with either: DW_TAG_subprogram
or DW_TAG_inlined_subroutine
.
Bases: object
This class represents a DWARF function’s parameter.
The name of the parameter
Type of the parameter
Return the address of the function (DW_AT_entry_pc
or DW_AT_low_pc
) or None
if it’s not available.
Original source code location.
Whether this function is created by the compiler and not present in the original source code.
The name of the function which is used for linking (DW_AT_linkage_name).
This name differs from name
as it is usually mangled. The function return an empty string if the linkage name is not available.
The name of the function (DW_AT_name
)
Return the list of parameters used by this function.
Ranges of virtual addresses owned by this function.
Scope in which this function is defined
Return the size taken by this function in the binary.
Return the Type
associated with the return type of this function
Return an iterator over the variables (DW_TAG_variable
) defined within the scope of this function. This includes regular stack-based variables as well as static ones.
Bases: object
This class materializes a scope in which Function
, Variable
, Type
, … can be defined.
Bases: object
Represent the whole chain of all (parent) scopes using the provided separator. E.g. ns1::ns2::Class1::Struct2::Type
.
Name of the scope. For instance namespace’s name or function’s name.
Parent scope (if any).
The current scope type.
Bases: object
This class represents a DWARF variable which can be owned by a Function
or a CompilationUnit
.
Address of the variable.
If the variable is static, it returns the virtual address where it is defined. If the variable is stack-based, it returns the relative offset from the frame-base register.
If the address can’t be resolved, it returns None
.
The original source location where the variable is defined.
Whether it’s a constexpr
variable.
The name of the variable which is used for linking (DW_AT_linkage_name
).
This name differs from name
as it is usually mangled. The function return an empty string if the linkage name is not available.
Name of the variable (usually demangled)
Scope in which this variable is defined
Return the size of the variable (or a lief_errors if it can’t be resolved).
This size is defined by the type of the variable.
Return the type of this variable.
Bases: object
This class represents a DWARF Type which includes:
DW_TAG_array_type
DW_TAG_const_type
DW_TAG_pointer_type
DW_TAG_structure_type
DW_TAG_base_type
DW_TAG_class_type
DW_TAG_enumeration_type
DW_TAG_string_type
DW_TAG_union_type
DW_TAG_volatile_type
DW_TAG_unspecified_type
Bases: object
Whether this type is a DW_TAG_unspecified_type
Discriminator for the type’s subclasses
Return the debug location where this type is defined.
Return the type’s name or None
if it can’t be resolved.
Scope in which this type is defined
Return the size of the type or None
if it can’t be computed.
This size should match the equivalent of sizeof(Type)
.
Bases: Type
This class represents a DW_TAG_array_type
The underlying type of this array.
Bases: Type
This class wraps the DW_TAG_base_type
type which can be used – for instance – to represent integers or primitive types.
Bases: object
Describe how the the base type is encoded and should be interpreted.
Bases: Type
This class abstracts a DWARF aggregate (DW_TAG_structure_type
, DW_TAG_class_type
, DW_TAG_union_type
).
Bases: object
This class represents a class/struct/union attribute.
Offset of the current member in bits in the current struct/union/class
This function differs from offset
for aggregates using bit-field declaration:
struct S {
int flag : 4;
int opt : 1
};
Usually, offset * 8 == bit_offset
If the offset can’t be resolved it returns None
Name of the member
Offset of the current member in the struct/union/class
If the offset can’t be resolved it returns None
Type of the current member
Try to find the attribute at the given offset
Return a list of all the members defined in this class-like type.
Bases: Type
This class represents a DW_TAG_const_type
modifier
The underlying type being const-ed by this type.
Bases: Type
This class represents a DW_TAG_pointer_type
DWARF type.
The type pointed by this pointer