[Dwarf-Discuss] How to get union member offset?

Roland McGrath roland@redhat.com
Fri Mar 27 01:49:22 GMT 2009

> I am trying to get the offset of a member in an union. However, there
> is no attribute DW_AT_data_member_location attached to it!

All members of a union start at offset 0.  I think the C standard may
require that this is always true because of its pointer casting rules.

But regardless DWARF 3 section 5.6.6 says: "The location description for
a data member of a union may be omitted, since all data members of a
union begin at the same address."

What I'd consider wise consumer behavior is always to look for
DW_AT_data_member_location as for struct, class, etc. as you already do.
If it's not found and the containing type is a union, treat it as if
you'd found the attribute with DW_FORM_udata and value 0.


More information about the Dwarf-discuss mailing list