[Dwarf-Discuss] Finding parent of a DIE?
roland at redhat.com
Fri Jul 24 13:26:37 PDT 2009
> Is there any straight-forward method to find the parent DIE of a selected
> DIE in the DWARF data? For example, if I have a DIE with offset 0x1640,
> which is a DW_TAG_subprogram DIE, is there any way to determine the
> parent of that DIE?
Nope. You have to walk the tree from the root until you meet yourself, or
cache state to optimize that. Note that when you are looking for your
parent, you can skip some useless parts of the walk just by looking at a
DIE's DW_AT_sibling and quickly seeing that it doesn't "own" your offset.
But also note that if there are "indirect" children via DW_TAG_imported_unit
(a generic compression technique for DWARF trees), then your logical parent
might be in another CU and then you have to know which CU to start with (or
walk them all), walk its tree and look for the parent of a
DW_TAG_imported_unit that points to the CU that's your parent.
In short, the way you probably want to approach consuming DWARF trees is by
keeping state about your tree walks, caches of paths taken to reach DIEs
you can look up to follow the random-access pointers in attributes of class
More information about the Dwarf-Discuss