gimli-rs / gimli

A library for reading and writing the DWARF debugging format

Home Page:https://docs.rs/gimli/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a helper for getting the size of a DIE

khuey opened this issue · comments

I find myself often typing

die.attr(gimli::DW_AT_byte_size)
    .map(|attr| attr.and_then(|attr| attr.udata_value()).map(|v| v * 8)) // we want the size in bits.
    .or_else(|_| {
        die.attr(gimli::DW_AT_bit_size)
            .map(|attr| attr.and_then(|attr| attr.udata_value()))
    })?

How would you feel about adding that to DebuggingInformationEntry (either directly or on some sort of Ext trait)?

It would be nice if gimli did something to make it easier to parse these. However, I'm not sure that helper is the correct thing to do.

In DWARF 5 (I haven't checked earlier versions), only base types and data members should have DW_AT_bit_size. Data members in particular are complicated because you need to determine the bit offset too.

Similar I'm sure there's semantic information for other tags and attributes that is specified in the standard but which each user of gimli currently needs to handle themselves.

So what we might need instead is a higher level API that parses all of the attributes for a given tag, as suggested in #82.