libdwarf
using dwarf_validate_die_sibling

Example of a DIE tree validation.

Here we show how one uses dwarf_validate_die_sibling(). Dwarfdump uses this function as a part of its validation of DIE trees.

It is not something you need to use. But one must use it in a specific pattern for it to work properly.

dwarf_validate_die_sibling() depends on data set by dwarf_child() preceeding dwarf_siblingof_b() . dwarf_child() records a little bit of information invisibly in the Dwarf_Debug data.

*/
int example_sibvalid(Dwarf_Debug dbg,
Dwarf_Die in_die,
Dwarf_Error*error)
{
int cres = DW_DLV_OK;
int sibres = DW_DLV_OK;
Dwarf_Die die = 0;
Dwarf_Die sibdie = 0;
Dwarf_Die child = 0;
die = in_die;
for ( ; die ; die = sibdie) {
int vres = 0;
Dwarf_Unsigned offset = 0;
/* Maybe print something you extract from the DIE */
cres = dwarf_child(die,&child,error);
if (cres == DW_DLV_ERROR) {
if (die != in_die) {
}
printf("dwarf_child ERROR\n");
return DW_DLV_ERROR;
}
if (cres == DW_DLV_OK) {
int lres = 0;
child = 0;
lres = example_sibvalid(dbg,child,error);
if (lres == DW_DLV_ERROR) {
if (die != in_die) {
}
printf("example_sibvalid ERROR\n");
return lres;
}
}
sibdie = 0;
sibres = dwarf_siblingof_b(dbg,die,is_info,
&sibdie,error);
if (sibres == DW_DLV_ERROR) {
if (die != in_die) {
}
if (child) {
}
printf("dwarf_siblingof_b ERROR\n");
return DW_DLV_ERROR;
}
if (sibres == DW_DLV_NO_ENTRY) {
if (die != in_die) {
}
if (child) {
}
return DW_DLV_OK;
}
vres = dwarf_validate_die_sibling(sibdie,&offset);
if (vres == DW_DLV_ERROR) {
if (die != in_die) {
}
if (child) {
}
printf("Invalid sibling DIE\n");
return DW_DLV_ERROR;
}
/* loop again */
if (die != in_die) {
}
die = 0;
}
return DW_DLV_OK;
}
struct Dwarf_Debug_s * Dwarf_Debug
Definition: libdwarf.h:603
struct Dwarf_Die_s * Dwarf_Die
Definition: libdwarf.h:608
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:597
unsigned long long Dwarf_Unsigned
Definition: libdwarf.h:196
int Dwarf_Bool
Definition: libdwarf.h:202
Dwarf_Bool dwarf_get_die_infotypes_flag(Dwarf_Die dw_die)
Return the is_info flag.
void dwarf_dealloc_die(Dwarf_Die dw_die)
Deallocate (free) a DIE.
int dwarf_child(Dwarf_Die dw_die, Dwarf_Die *dw_return_childdie, Dwarf_Error *dw_error)
Return the child DIE, if any. The child may be the first of a list of sibling DIEs.
int dwarf_siblingof_b(Dwarf_Debug dw_dbg, Dwarf_Die dw_die, Dwarf_Bool dw_is_info, Dwarf_Die *dw_return_siblingdie, Dwarf_Error *dw_error)
Return the first DIE or the next sibling DIE.
int dwarf_validate_die_sibling(Dwarf_Die dw_sibling, Dwarf_Off *dw_offset)
Validate a sibling DIE.