On 03/17/2017 10:18 AM, SASHA NICOLAS DA ROCHA PINHEIRO wrote: > I did not find the reference about the argument named > next_cu_header_offset (below I pasted the respective functions > signatures). Anyway, name orthography apart, what is being used in > Dyninst with libdwarf is exactly the value of what we called > next_cu_off, which corresponds to the third parameter of > dwarf_nextcu(), named in libdw as next_off.
We must have different versions of libdwarf.h, but either way the point is that this value is not a die offset, just the offset of the next cu. In your libdwarf code, it looks like you only use "cu_die_off" in the call to dwarf_next_cu_header_c and for updating the "dies_seen" set. The latter is suspect, but probably fine in practice. You don't need the true die offset because dwarf_siblingof_b uses a NULL die input to specify that you want the first die of the current cu. It might help to call dwarf_dieoffset to see what it actually is. But libdw doesn't have a notion of a "current" cu, so you do need the correct offset for dwarf_offdie. I'm 99% sure cu_off + cu_header_size is the right value. > Do you have any other thoughts why the sequence of function calls is > not working, instead it is giving invalid dwarf? If the offset I suggest doesn't work, then I'm not sure what's going on. Maybe you could share the full code on a branch somewhere, with a test program to reproduce the problem?