Skip to content

Simpler attribute value parsing #845

@philipc

Description

@philipc

Attribute::value is okay for things like the dwarfdump example or the convert code, where we can treat all attributes the same without needing to interpret the values. However for many consumers it may better to have Attribute methods that parse the value for a specific attribute kind, and return an enum that only has variants that are legal for that attribute. This makes it easier for the consumer to correctly handle all possibilities. Constructing this enum should handle things like looking up values in .debug_addr or .debug_str.

The methods returning these enums probably should be a replacement for Attribute::value, rather than something you call for the resulting AttributeValue. While Attribute::value may work, my intuition is that it results in extra work for the compiler to remove all the unreachable cases, and maybe some unneeded clones. So we should consider replacing existing methods like Dwarf::attr_string which need an AttributeValue. We should also remove methods like Attribute::string_value which don't handle all possibilities and should never be used anyway.

Ideally this would also be used to implement something like #82 for DIEs; the fields in those DIE structs would be these enums.

Semi related to this, we should investigate if there is a more efficient representation for AttributeValue. Currently this has a lot of variants, while other DWARF parsers seem to use a union with many fewer fields (for example, LLVM's DWARFFormValue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions