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: Enum
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
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 imported_function
but
functions
.
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
.
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.
Disassemble the current function by returning an iterator over the
lief.assembly.Instruction
.
Whether this function is created by the compiler and not present in the original source code.
Whether the function is defined outside the current compilation unit
(DW_AT_external
).
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 (including template parameters)
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.
List of exceptions (types) that can be thrown by the function. For instance, given this Swift code:
func summarize(_ ratings: [Int]) throws(StatisticsError) {
// ...
}
thrown_types
returns one element associated with the
Type
: StatisticsError
.
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 represents a DWARF parameter which can be either:
- A regular function parameter (see: parameters.Formal
)
- A template type parameter (see: parameters.TemplateType
)
- A template value parameter (see: parameters.TemplateValue
)
Name of the parameter
Type of this parameter
Bases: Parameter
This class represents a regular function parameter.
For instance, given this prototype:
int main(int argc, const char** argv);
The function main
has two Formal
parameters:
argc
(lief.dwarf.Parameter.name
) typed as int
(Base
from lief.dwarf.Parameter.type
)
argv
(lief.dwarf.Parameter.name
) typed as const char**
(Const
)
Bases: Parameter
This class represents a template value parameter.
For instance, given this prototype:
template<int X = 5>
void generic();
The function generic
has one TemplateValue
parameter: X
Bases: Parameter
This class represents a template type parameter.
For instance, given this prototype:
template<class Y>
void generic();
The function generic
has one TemplateType
parameter: Y
Bases: object
This class materializes a scope in which Function
,
Variable
, Type
, … can be defined.
Bases: Enum
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
DW_TAG_typedef
DW_TAG_reference_type
DW_TAG_subroutine_type
DW_TAG_ptr_to_member_type
DW_TAG_set_type
DW_TAG_packed_type
DW_TAG_file_type
DW_TAG_thrown_type
DW_TAG_restrict_type
DW_TAG_interface_type
DW_TAG_shared_type
DW_TAG_rvalue_reference_type
DW_TAG_template_alias
DW_TAG_coarray_type
DW_TAG_dynamic_type
DW_TAG_atomic_type
DW_TAG_immutable_type
Bases: Enum
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.
The name is resolved using either DW_AT_name
or DW_AT_picture_string
.
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
Return information about the size of this array.
This size info is usually embedded in a DW_TAG_subrange_type
DIE which
is represented by the Array.size_info_t
class.
Bases: object
Class that wraps information about the dimension of this array
Name of the index (usually not relevant like __ARRAY_SIZE_TYPE__
)
Size of the array. For instance in uint8_t[3]
, it returns 3.
Type of the index for this array.
For instance in uint8_t[3]
the index type could be set to a size_t
.
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: Enum
Describe how 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
Iterator over the functions defined by the class-like.
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
Bases: Type
This class represents a DW_TAG_typedef
type
The type aliased by this typedef
Bases: Type
This class represents the DW_TAG_atomic_type
type
The underlying type being atomized by this type.
Bases: Type
This class represents the DW_TAG_immutable_type
type
The underlying type.
Bases: Type
This class represents the DW_TAG_ptr_to_member_type
type
The type that embeds this member.
The type of the member referenced by this pointer.
Bases: Type
This class represents the DW_TAG_rvalue_reference_type
type
The underlying type referenced by this rvalue-type.
Bases: Type
This class represents the DW_TAG_reference_type
type
The underlying type referenced by this ref-type.
Bases: Type
This class represents the DW_TAG_restrict_type
type
The underlying type referenced by this restrict-type.
Bases: Type
This class represents the DW_TAG_set_type
type
The underlying type referenced by this set-type.
Bases: Type
This class represents the DW_TAG_subroutine_type
type
Parameters of this subroutine
Bases: Type
This class represents the DW_TAG_template_alias
type
Parameters associated with the underlying template
The underlying type aliased by this type.
Bases: Type
This class represents a DW_TAG_thrown_type
The underlying type being thrown
Bases: Type
This class represents a DW_TAG_volatile_type
The underlying type.
Bases: object
This class exposes the main API to create DWARF information
Create a new compilation unit
Write the DWARF file to the specified output
Bases: object
This class represents an editable DWARF compilation unit
Create an array type with the given name, type and size.
Create a primitive type with the given name and size.
Create an enum type (DW_TAG_enumeration_type
)
Create a new function owned by this compilation unit
Create a function type with the given name.
Create a DW_TAG_unspecified_type
type with the given name
Create a pointer on the provided type.
Create a struct-like type (struct, class, union) with the given name
Create a typdef with the name provided in the first parameter which aliases the type provided in the second parameter
Create a new global variable owned by this compilation unit
Create a void
type
Set the DW_AT_producer
producer attribute.
This attribute aims to inform about the program that generated this
compilation unit (e.g. LIEF Extended
)
Bases: object
This class represents an editable DWARF function (DW_TAG_subprogram
)
Bases: object
This class mirrors the DW_TAG_label
DWARF tag
Bases: object
This class mirrors the DW_TAG_lexical_block DWARF tag
Bases: object
This class represents a parameter of the current function (DW_TAG_formal_parameter
)
Add a label at the given address
Add a lexical block with the given range
Add a parameter to the current function
Create a stack-based variable owned by the current function
Bases: object
Set the address of this function by defining DW_AT_entry_pc
Set the function as external by defining DW_AT_external
to true.
This means that the function is imported by the current compilation
unit.
Set the upper and lower bound addresses for this function. This assumes
that the function is contiguous between low
and high
.
Underneath, the function defines DW_AT_low_pc
and DW_AT_high_pc
Set the ranges of addresses owned by the implementation of this function
by setting the DW_AT_ranges
attribute.
This setter should be used for non-contiguous function.
Set the return type of this function
Bases: object
This class represents an editable DWARF variable which can be
scoped by a function or a compilation unit (DW_TAG_variable
)
Set the global address of this variable. Setting this address is only
revelant in the case of a static global variable. For stack variable, you
should use set_stack_offset()
.
This function set the DW_AT_location
attribute
Mark this variable as imported
Set the stack offset of this variable.
This function set the DW_AT_location
attribute
Set the type of the current variable
Bases: object
This class is the base class for any types created when editing DWARF debug info.
A type is owned by a lief.dwarf.editor.CompilationUnit
and should be
created from this class.
Create a pointer type pointing to this type
Bases: Type
This class represents an editable enum type (DW_TAG_enumeration_type
)
Bases: object
This class represents an enum value
Add an enum value by specifying its name and its integer value.
Define the number of bytes required to hold an instance of the
enumeration (DW_AT_byte_size
).
Bases: Type
This class represents a function type (DW_TAG_subroutine_type
)
Bases: object
This class represents a function’s parameter
Add a parameter
Set the return type of this function
Bases: Type
This class represents a struct-like type which can be:
DW_TAG_class_type
DW_TAG_structure_type
DW_TAG_union_type
Bases: object
This class represents a member of the struct-like
mber to the current struct-like
Define the overall size which is equivalent to the sizeof
of the
current type.
This function defines the DW_AT_byte_size
attribute