Debug Info

PDB and DWARF share similar traits which are abstracted by the following classes:

C++

DebugInfo

class DebugInfo

This class provides a generic interface for accessing debug information from different formats such as DWARF and PDB.

Users can use this interface to access high-level debug features like resolving function addresses.

Subclassed by LIEF::dwarf::DebugInfo, LIEF::pdb::DebugInfo

Public Types

enum class FORMAT

Values:

enumerator UNKNOWN = 0
enumerator DWARF
enumerator PDB

Public Functions

DebugInfo(std::unique_ptr<details::DebugInfo> impl)
virtual ~DebugInfo()
inline virtual FORMAT format() const
template<class T>
inline const T *as() const

This function can be used to down cast a DebugInfo instance:

std::unique_ptr<LIEF::Instruction> dbg = bin->debug_info();
if (const auto* dwarf = inst->as<LIEF::dwarf::DebugInfo>()) {
  dwarf->find_function("main");
}
virtual optional<uint64_t> find_function_address(const std::string &name) const = 0

Attempt to resolve the address of the function specified by name.

Friends

friend class Binary

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

DeclOpt

class DeclOpt

Configuration options for generated code from debug info.

This structure configures how the debug information (DWARF/PDB) translated into an AST is generated. You can use it to configure the indentation, and the information to generate when translating DWARF/PDB into C++-like definitions

Public Types

using type_aliases_t = std::unordered_map<std::string, std::string>

Mapping between a type name and a user-friendly aliases. (e.g. std::basic_string<char,std::char_traits<char>,std::allocator<char>> -> std::string).

Public Functions

DeclOpt()
DeclOpt(const DeclOpt &other)
DeclOpt &operator=(const DeclOpt &other)
DeclOpt(DeclOpt &&other) noexcept
DeclOpt &operator=(DeclOpt &&other) noexcept
~DeclOpt()
uint32_t indentation() const

The number of spaces for indentation.

DeclOpt &indentation(uint32_t value)
bool is_cpp() const

Prefer C++ syntax over C syntax.

If true, the output will use C++ features (e.g. bool keyword)

DeclOpt &is_cpp(bool value)
bool show_extended_annotations() const

Enable extended comments and annotations.

If true, the generated code will include comments containing low-level details such as memory addresses, offsets, type sizes, and original source locations.

DeclOpt &show_extended_annotations(bool value)
bool include_types() const

Include full type definitions.

If true, the output will contain the full definition of types (structs, enums, unions).

DeclOpt &include_types(bool value)
bool include_locals() const

Emit a function body listing its local / stack variables.

DeclOpt &include_locals(bool value)
bool desugar() const

Resolve type aliases (sugar).

If true, typedef and type aliases are replaced by their underlying canonical types (e.g., uint32_t might become unsigned int).

DeclOpt &desugar(bool value)
bool show_field_offsets() const

Show the relative offset of each field/attribute in structures.

If true, every member of a structure is prefixed with its byte offset,

struct Foo {
  /* 0x00 *&zwj;/ int A;
  /* 0x04 *&zwj;/ int B;
};
DeclOpt &show_field_offsets(bool value)
const type_aliases_t &type_aliases() const

Mapping of type names to user-friendly aliases.

DeclOpt &type_aliases(type_aliases_t aliases)
DeclOpt &add_type_alias(std::string name, std::string alias)

Register a single type alias.


Python

DebugInfo

class lief.DebugInfo

Bases: object

This class provides a generic interface for accessing debug information from different formats such as DWARF and PDB.

Users can use this interface to access high-level debug features like resolving function addresses.

See: DebugInfo, lief.dwarf.DebugInfo

class FORMAT(*values)

Bases: Enum

DWARF = 1
PDB = 2
UNKNOWN = 0
from_value(arg: int) lief.DebugInfo.FORMAT = <nanobind.nb_func object>
find_function_address(self, name: str) int | None

Attempt to resolve the address of the function specified by name.

property format lief.DebugInfo.FORMAT

The actual debug format (PDB/DWARF)

debug_location_t

class lief.debug_location_t

Bases: object

property file str
property line int

DeclOpt

class lief.DeclOpt(self)

Bases: object

Configuration options for generated code from debug info.

This structure configures how the debug information (DWARF/PDB) translated into an AST is generated. You can use it to configure the indentation, and the information to generate when translating DWARF/PDB into C++-like definitions

add_type_alias(self, name: str, alias: str) lief._lief.DeclOpt

Register a single type alias (see type_aliases).

property desugar bool

Resolve type aliases (sugar).

If true, typedef and type aliases are replaced by their underlying canonical types (e.g., uint32_t might become unsigned int).

property include_locals bool

Emit a function body listing its local / stack variables.

property include_types bool

Include full type definitions.

If true, the output will contain the full definition of types (structs, enums, unions).

property indentation int

The number of spaces for indentation.

property is_cpp bool

Prefer C++ syntax over C syntax.

If true, the output will use C++ features (e.g., bool keyword)

property show_extended_annotations bool

Enable extended comments and annotations.

If true, the generated code will include comments containing low-level details such as memory addresses, offsets, type sizes, and original source locations.

property show_field_offsets bool

Show the relative offset of each field/attribute in structures.

If true, every member of a structure is prefixed with its byte offset (e.g. /* 0x04 */).

property type_aliases dict[str, str]

Mapping of type names to user-friendly aliases used while rendering types (e.g. std::basic_string<char, ...> -> std::string).


Rust