C++

Note

You can also find the Doxygen documentation here: here

inline std::unique_ptr<DebugInfo> LIEF::dwarf::load(const std::string &pdb_path)

Load DWARF file from the given path.

DebugInfo

class DebugInfo : public LIEF::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() or load()

Public Types

using compilation_units_it = iterator_range<CompilationUnit::Iterator>

Iterator over the CompilationUnit.

Public Functions

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

Try to find the function with the given name (mangled or not)

const DebugInfo& info = ...;
if (auto func = info.find_function("_ZNSt6localeD1Ev")) {
  // Found
}
if (auto func = info.find_function("std::locale::~locale()")) {
  // Found
}
std::unique_ptr<Function> find_function(uint64_t addr) const

Try to find the function at the given virtual address.

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

Try to find the variable with the given name. This name can be mangled or not.

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

Try to find the variable at the given virtual address.

std::unique_ptr<Type> find_type(const std::string &name) const

Try to find the type with the given name.

compilation_units_it compilation_units() const

Iterator on the CompilationUnit embedded in this dwarf.

inline virtual FORMAT format() const override
virtual ~DebugInfo() override = default

Public Static Functions

static std::unique_ptr<DebugInfo> from_file(const std::string &path)
static inline bool classof(const LIEF::DebugInfo *info)

CompilationUnit

class CompilationUnit

This class represents a DWARF compilation unit.

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 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.

This value matches the DW_AT_name attribute

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.

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

This value matches the DW_AT_producer attribute

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)

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

Language language() const

Original Language of this compilation unit.

This value matches the DW_AT_language attribute.

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.

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.

std::vector<range_t> 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.

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

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

The provided name can be demangled

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

Try to find the function at the given address.

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

Try to find the Variable at the given address.

std::unique_ptr<Variable> find_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.

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.

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:

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;
}
class Iterator

Public Types

using iterator_category = std::bidirectional_iterator_tag
using value_type = std::unique_ptr<CompilationUnit>
using difference_type = std::ptrdiff_t
using pointer = CompilationUnit*
using reference = std::unique_ptr<CompilationUnit>&
using implementation = details::CompilationUnitIt

Public Functions

Iterator(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator(std::unique_ptr<details::CompilationUnitIt> impl)
~Iterator()
Iterator &operator++()
Iterator &operator--()
inline Iterator operator--(int)
inline Iterator operator++(int)
std::unique_ptr<CompilationUnit> operator*() const
inline PointerProxy operator->() const

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
class PointerProxy

Public Functions

inline pointer operator->() const
class Language

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

Public Types

enum LANG

Values:

enumerator UNKNOWN = 0
enumerator C
enumerator CPP
enumerator RUST
enumerator DART

Public Functions

Language() = default
inline Language(LANG lang, uint32_t version)
inline Language(LANG lang)
Language(const Language&) = default
Language &operator=(const Language&) = default
Language(Language&&) = default
Language &operator=(Language&&) = default
~Language() = default

Public Members

LANG lang = UNKNOWN

The language itself.

uint32_t version = 0

Version of the language (e.g. 17 for C++17)


Function

class Function

This class represents a DWARF function which can be associated with either: DW_TAG_subprogram or DW_TAG_inlined_subroutine.

Public Types

using vars_it = iterator_range<Variable::Iterator>

Public Functions

Function(std::unique_ptr<details::Function> impl)
std::string name() const

The name of the function (DW_AT_name)

std::string linkage_name() const

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.

result<uint64_t> address() const

Return the address of the function (DW_AT_entry_pc or DW_AT_low_pc).

vars_it variables() const

Return an iterator of variables (DW_TAG_variable) defined within the scope of this function. This includes regular stack-based variables as well as static ones.

bool is_artificial() const

Whether this function is created by the compiler and not present in the original source code.

uint64_t size() const

Return the size taken by this function in the binary.

std::vector<range_t> ranges() const

Ranges of virtual addresses owned by this function.

debug_location_t debug_location() const

Original source code location.

std::unique_ptr<Type> type() const

Return the dwarf::Type associated with the return type of this function.

std::vector<Parameter> parameters() const

Return the function’s parameters.

std::unique_ptr<Scope> scope() const

Return the scope in which this function is defined.

~Function()
class Iterator

Public Types

using iterator_category = std::bidirectional_iterator_tag
using value_type = std::unique_ptr<Function>
using difference_type = std::ptrdiff_t
using pointer = Function*
using reference = std::unique_ptr<Function>&
using implementation = details::FunctionIt

Public Functions

Iterator(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator(std::unique_ptr<details::FunctionIt> impl)
~Iterator()
Iterator &operator++()
Iterator &operator--()
inline Iterator operator--(int)
inline Iterator operator++(int)
std::unique_ptr<Function> operator*() const
inline PointerProxy operator->() const

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
class PointerProxy

Public Functions

inline pointer operator->() const
class Parameter

This class wraps a DWARF function’s parameter.

Public Functions

Parameter(std::unique_ptr<details::Parameter> impl)
Parameter(Parameter &&other) noexcept
Parameter &operator=(Parameter &&other) noexcept
std::string name() const

Name of the parameter.

std::unique_ptr<Type> type() const

Type of the parameter.

~Parameter()

Scope

class Scope

This class materializes a scope in which Function, Variable, Type, … can be defined.

Public Types

enum class TYPE : uint32_t

Values:

enumerator UNKNOWN = 0
enumerator UNION
enumerator CLASS
enumerator STRUCT
enumerator NAMESPACE
enumerator FUNCTION
enumerator COMPILATION_UNIT

Public Functions

Scope(std::unique_ptr<details::Scope> impl)
std::string name() const

Name of the scope. For instance namespace’s name or function’s name.

std::unique_ptr<Scope> parent() const

Parent scope (if any)

TYPE type() const

The current scope type.

std::string chained(const std::string &sep = "::") const

Represent the whole chain of all (parent) scopes using the provided separator. E.g. ns1::ns2::Class1::Struct2::Type

~Scope()

Variable

class Variable

This class represents a DWARF variable which can be owned by a dwarf::Function or a dwarf::CompilationUnit.

Public Functions

Variable(std::unique_ptr<details::Variable> impl)
std::string name() const

Name of the variable (usually demangled)

std::string linkage_name() const

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.

result<int64_t> address() const

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 based register.

If the address can’t be resolved, it returns a lief_errors.

result<uint64_t> size() const

Return the size of the variable (or a lief_errors if it can’t be resolved).

This size is defined by its type.

bool is_constexpr() const

Whether it’s a constexpr variable.

debug_location_t debug_location() const

The original source location where the variable is defined.

std::unique_ptr<Type> type() const

Return the type of this variable.

std::unique_ptr<Scope> scope() const

Return the scope in which this variable is defined.

~Variable()
class Iterator

Public Types

using iterator_category = std::bidirectional_iterator_tag
using value_type = std::unique_ptr<Variable>
using difference_type = std::ptrdiff_t
using pointer = Variable*
using reference = std::unique_ptr<Variable>&
using implementation = details::VariableIt

Public Functions

Iterator(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator(std::unique_ptr<details::VariableIt> impl)
~Iterator()
Iterator &operator++()
Iterator &operator--()
inline Iterator operator--(int)
inline Iterator operator++(int)
std::unique_ptr<Variable> operator*() const
inline PointerProxy operator->() const

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
class PointerProxy

Public Functions

inline pointer operator->() const

Type

class Type

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

Subclassed by LIEF::dwarf::types::Array, LIEF::dwarf::types::Base, LIEF::dwarf::types::ClassLike, LIEF::dwarf::types::Const, LIEF::dwarf::types::Pointer

Public Types

enum class KIND

Values:

enumerator UNKNOWN = 0
enumerator UNSPECIFIED
enumerator BASE
enumerator CONST_KIND
enumerator CLASS
enumerator ARRAY
enumerator POINTER
enumerator STRUCT
enumerator UNION

Public Functions

virtual ~Type()
KIND kind() const
inline bool is_unspecified() const

Whether this type is a DW_TAG_unspecified_type

result<std::string> name() const

Return the type’s name (if any)

result<uint64_t> size() const

Return the size of the type or an error if it can’t be computed.

This size should match the equivalent of sizeof(Type).

debug_location_t location() const

Return the debug location where this type is defined.

std::unique_ptr<Scope> scope() const

Return the scope in which this type is defined.

template<class T>
inline const T *as() const

Public Static Functions

static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl)
class Iterator

Public Types

using iterator_category = std::bidirectional_iterator_tag
using value_type = std::unique_ptr<Type>
using difference_type = std::ptrdiff_t
using pointer = Type*
using reference = std::unique_ptr<Type>&
using implementation = details::TypeIt

Public Functions

Iterator(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator(std::unique_ptr<details::TypeIt> impl)
~Iterator()
Iterator &operator++()
Iterator &operator--()
inline Iterator operator--(int)
inline Iterator operator++(int)
std::unique_ptr<Type> operator*() const
inline PointerProxy operator->() const

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)
class PointerProxy

Public Functions

inline pointer operator->() const

Array

class Array : public LIEF::dwarf::Type

This class represents a DW_TAG_array_type

Public Functions

const Type *underlying_type() const

The underlying type of this array.

inline const Type *operator->() const
inline const Type &operator*() const
~Array() override

Public Static Functions

static inline bool classof(const Type *type)

Base

class Base : public LIEF::dwarf::Type

This class wraps the DW_TAG_base_type type which can be used &#8212; for instance &#8212; to represent integers or primitive types.

Public Types

enum class ENCODING

Values:

enumerator NONE = 0
enumerator SIGNED

Mirror DW_ATE_signed

enumerator SIGNED_CHAR

Mirror DW_ATE_signed_char

enumerator UNSIGNED

Mirror DW_ATE_unsigned

enumerator UNSIGNED_CHAR

Mirror DW_ATE_unsigned_char

enumerator FLOAT

Mirror DW_ATE_float

enumerator BOOLEAN

Mirror DW_ATE_boolean

enumerator ADDRESS

Mirror DW_ATE_address

Public Functions

ENCODING encoding() const

Describe how the base type is encoded and should be interpreted.

~Base() override

Public Static Functions

static inline bool classof(const Type *type)

ClassLike

class ClassLike : public LIEF::dwarf::Type

This class abstracts a DWARF aggregate: DW_TAG_structure_type, DW_TAG_class_type, DW_TAG_union_type.

Subclassed by LIEF::dwarf::types::Class, LIEF::dwarf::types::Structure, LIEF::dwarf::types::Union

Public Functions

std::vector<Member> members() const

Return the list of all the attributes defined in this class-like type.

std::unique_ptr<Member> find_member(uint64_t offset) const

Try to find the attribute at the given offset.

~ClassLike() override

Public Static Functions

static inline bool classof(const Type *type)
class Member

This represents a class/struct/union attribute.

Public Functions

Member(std::unique_ptr<details::Member> impl)
Member(Member &&other) noexcept
Member &operator=(Member &&other) noexcept
std::string name() const

Name of the member.

result<uint64_t> offset() const

Offset of the current member in the struct/union/class.

If the offset can’t be resolved it returns a lief_errors

result<uint64_t> bit_offset() const

Offset of the current member in bits the 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 a lief_errors

std::unique_ptr<Type> type() const

Type of the current member.

bool is_external() const
bool is_declaration() const
~Member()

Structure

class Structure : public LIEF::dwarf::types::ClassLike

This class represents a DWARF struct type (DW_TAG_structure_type)

Public Functions

~Structure() override

Public Static Functions

static inline bool classof(const Type *type)

Class

class Class : public LIEF::dwarf::types::ClassLike

This class represents a DWARF class type (DW_TAG_class_type)

Public Functions

~Class() override

Public Static Functions

static inline bool classof(const Type *type)

Union

class Union : public LIEF::dwarf::types::ClassLike

This class represents a DWARF class type (DW_TAG_union_type)

Public Functions

~Union() override

Public Static Functions

static inline bool classof(const Type *type)

Const

class Const : public LIEF::dwarf::Type

This class represents a DW_TAG_const_type

Public Functions

const Type *underlying_type() const

The underlying type being const-ed.

inline const Type *operator->() const
inline const Type &operator*() const
~Const() override

Public Static Functions

static inline bool classof(const Type *type)

Pointer

class Pointer : public LIEF::dwarf::Type

This class represents a DW_TAG_pointer_type DWARF type.

Public Functions

const Type *underlying_type() const

The type pointed by this pointer.

inline const Type *operator->() const
inline const Type &operator*() const
~Pointer() override

Public Static Functions

static inline bool classof(const Type *type)

debug_location_t

struct debug_location_t

This structure holds a debug location (source filename & line)

Public Members

std::string file
uint64_t line = 0