dwarf_aggregate_size doesn't work with arrays in partial CUs

KJ Tsanaktsidis ktsanaktsidis@zendesk.com
Sat Sep 25 07:21:39 GMT 2021


Hi folks,

I'm writing a program that uses ptrace to poke at internal OpenSSL
data structures for another process. I'm using libdw to parse the
DWARF data for the copy of OpenSSL actually linked in to the target
process, so I can extract struct offsets, member sizes and the like
and poke at the right places.

I've run into an issue where dwarf_aggregate_size can't calculate the
size of an array, when the array is included in a partial CU
(DW_TAG_partial_unit). If the array unit includes a DW_AT_upper_bound
attribute, but not a DW_AT_lower_bound attribute, then
dwarf_aggregate_size will infer the lower bound based on the
DW_AT_language attribute of the enclisng CU (i.e. whether the language
uses zero or one based indexing).

However, the debug symbols I'm looking at for OpenSSL from the Ubuntu
repositories have the DW_AT_language on the full compilation unit
entries, but not in the partial ones included in them. This means that
caling dwarf_aggregate_size on the array type DIE does not work.

The DWARF spec doesn't really seem to have anything to say on the
matter (all it says is "A full or partial compilation unit entry may
have the following attributes", but doesn't say what it logically
means if an attribute is present on the complete CU but not a partial
one).

I guess it doesn't really make sense for a single compilation unit to
contain multiple languages? So I wonder if dwarf_srclang (called by
dwarf_aggregate_size) should crawl through the list of CU's to see if
the DIE's CU is included in a CU that _does_ specify DW_AT_language
(recursively, I suppose). Then, we can infer that the partial CU's
language is the same as the enclosing one.

If people reckon this is a good idea (or, have a better one!), I'm
happy to try and put together a patch.

KJ



More information about the Elfutils-devel mailing list