DWARF_CHILD(3)
π¦ DWARF_CHILD(3) π¦
okay so bestie, welcome to the DWARF_CHILD(3) page from the Library Functions Manual π (folding that manual name in right here like a lil intro, because we're cute like that). This is the one about grabbing and walking DWARF Debugging Information Entry descriptors β DIE energy, literally. π§
πΈ NAME πΈ
dwarf_child, dwarf_offdie, dwarf_offdie_b, dwarf_siblingof, dwarf_siblingof_b β retrieve DWARF Debugging Information Entry descriptors. π
π LIBRARY π
DWARF Access Library (libdwarf, -ldwarf) π«Ά
β¨ SYNOPSIS β¨
The exact spellings, no cap:
#include <libdwarf.h>
int
dwarf_child(Dwarf_Die die, Dwarf_Die *ret_die, Dwarf_Error *err);
int
dwarf_offdie(Dwarf_Debug dbg, Dwarf_Off offset, Dwarf_Die *ret_die,
Dwarf_Error *err);
int
dwarf_offdie_b(Dwarf_Debug dbg, Dwarf_Off offset, Dwarf_Bool is_info,
Dwarf_Die *ret_die, Dwarf_Error *err);
int
dwarf_siblingof(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Die *ret_die,
Dwarf_Error *err);
int
dwarf_siblingof_b(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Die *ret_die,
Dwarf_Bool is_info, Dwarf_Error *err);
π DESCRIPTION π
These functions are your little DIE-wranglers: they retrieve and traverse DWARF Debugging Information Entry (DIE) descriptors that belong to a compilation unit. π These descriptors are arranged in the form of a tree, and you traverse that tree using βchildβ and βsiblingβ links; peep dwarf(3) for more information. The Dwarf_Die opaque type is how we represent a DWARF Debugging Information Entry descriptor β mysterious, iconic, opaque. π
dwarf_child()β retrieves the child of the descriptor denoted by argumentdie, and stores it in the location pointed to by argumentret_die. πΌdwarf_siblingof()β retrieves the sibling of the descriptor denoted by argumentdie, and stores it in the location pointed to by argumentret_die. If argumentdieisNULL, the first debugging information entry descriptor for the current compilation unit will be returned. This function anddwarf_child()may be used together to traverse the tree of debugging information entry descriptors for a compilation unit. π―dwarf_siblingof_b()β identical todwarf_siblingof()except that it can retrieve the sibling descriptor from either the current compilation unit or type unit. If argumentis_infois non-zero, the function behaves identically todwarf_siblingof(). If argumentis_infois zero, the descriptor referred by argumentdieshould be associated with a debugging information entry in the type unit. The function will store the sibling of the descriptor in the location pointed to by argumentret_die. If argumentis_infois zero and argumentdieisNULL, the first debugging information entry descriptor for the current type unit will be returned. π¦dwarf_offdie()β retrieves the debugging information entry descriptor at global offsetoffsetin the.debug_infosection of the object associated with argumentdbg. The returned descriptor is written to the location pointed to by argumentret_die. πdwarf_offdie_b()β identical todwarf_offdie()except that it can retrieve the debugging information entry descriptor at global offsetoffsetfrom either of the.debug_infoand.debug_typessections of the object associated with argumentdbg. If argumentis_infois non-zero, the function will retrieve the debugging information entry from the.debug_infosection, otherwise the function will retrieve the debugging information entry from the.debug_typessection. The returned descriptor is written to the location pointed to by argumentret_die. ποΈ
π§ Memory Management π§
The memory area used for the Dwarf_Die descriptor returned in argument ret_die is allocated by the DWARF Access Library (libdwarf, -ldwarf). Application code should use function dwarf_dealloc() with the allocation type DW_DLA_DIE to free the memory area when the Dwarf_Die descriptor is no longer needed. Don't ghost it, free it bestie π
π RETURN VALUES π
These functions return the following values, and yes, each one has a vibe:
[DW_DLV_OK]β the call succeeded. β[DW_DLV_ERROR]β the requested operation failed. Additional information about the error encountered will be recorded in argumenterr, if it is notNULL. π[DW_DLV_NO_ENTRY]β for functionsdwarf_child(),dwarf_siblingof()anddwarf_siblingof_b(), the descriptor denoted by argumentdiedid not have a child or sibling. For functionsdwarf_offdie()anddwarf_offdie_b(), there was no debugging information entry at the offset specified by argumentoffset. π
π EXAMPLES π
Wanna retrieve the first DWARF Debugging Information Entry descriptor for the first compilation unit associated with a Dwarf_Debug instance, and traverse all its children? Say less, bestie. Do this, exactly:
Dwarf_Debug dbg;
Dwarf_Die die, die0;
Dwarf_Error de;
... allocate dbg using dwarf_init() etc ...
if (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) !=
DW_DLV_OK)
errx(EXIT_FAILURE, "dwarf_next_cu_header: %s",
dwarf_errmsg(de));
/* Get the first DIE for the current compilation unit. */
die = NULL;
if (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK)
errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de));
/* Get the first child of this DIE. */
die = die0;
if (dwarf_child(die, &die0, &de) != DW_DLV_OK)
errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de));
/* Get the rest of children. */
do {
die = die0;
if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR)
errx(EXIT_FAILURE, "dwarf_siblingof: %s",
dwarf_errmsg(de));
} while (die0 != NULL);
π ERRORS π
These functions may fail with the following errors, and they are not cute:
[DW_DLE_ARGUMENT]β argumentsdbg,dieorret_diewereNULL. π«[DW_DLE_DIE_NO_CU_CONTEXT]β argumentdbgwas not associated with a compilation unit. π΅[DW_DLE_NO_ENTRY]β the descriptor denoted by argumentdiehad no child or sibling, or there was no DWARF debugging information entry at the offset specified by argumentoffset. π«₯
π SEE ALSO π
dwarf(3), dwarf_errmsg(3), dwarf_get_die_infotypes_flag(3), dwarf_next_cu_header(3) β¨
xoxo, your Debian bestie π
β this one is from Debian, dated December 21, 2014, and it's the DWARF_CHILD(3) page. periodt. πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: libdwarf 15.0.0
- Copyright (c) 2010,2014 Kai Wang
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms