gimli icon indicating copy to clipboard operation
gimli copied to clipboard

Consider adding a higher level API on top of DIE parsing/traversal

Open fitzgen opened this issue 9 years ago • 4 comments

Something like this:

struct Subprogram {
    ...
}

impl Subprogram {
    pub fn new(die: DebuggingInformationEntry) -> Subprogram {
        assert!(die.tag() == DW_TAG_subprogram);
        Subprogram { ... }
    }

    pub fn name(&self) -> Option<&ffi::CStr> { ... }

    pub fn linkage_name(&self) -> Option<&ffi::CStr> { ... }

    pub fn calling_convention(&self) -> Option<DwCc> { ... }

    pub fn is_pure(&self) -> Option<bool> { ... }

    pub fn is_recursive(&self) -> Option<bool> { ... }

    // Etc...
}

Would ideally be able to become owned, if the user wants to copy the data.

fitzgen avatar Aug 29 '16 18:08 fitzgen

When I writing a program that parse global variable addresses( https://github.com/grissiom/elfvars/ ), I found I have to pass the gimli::Abbreviations and gimli::DebugStr all the way down if I want to do "lazy parsing"(travel only portion of the DIE and than parse only the DIEs that relevant).

IMHO, the abbreviations and debug_str associated with a CU does not change in the middle. So a higher level API may group those info into a struct and make the methods easier to use.

grissiom avatar Feb 19 '17 03:02 grissiom

It's not just those two that you need. DIEs can contain references to most other sections too, and so you currently need to pass those sections down too if you want to use those values (the dwarfdump example passes down abbrev/line/loc/ranges/str). Definitely open to ideas for making this easier to use though.

philipc avatar Feb 19 '17 05:02 philipc

If we had an Image for the whole object file, it might help solve the issues here as well as potentially making #182 more ergonomic. The down side would be that gimli has to get a deeper understanding of object files, rather than having it be completely another crate's concern.

fitzgen avatar Feb 19 '17 23:02 fitzgen

Maybe we could handover the "parsing" of the ELF to other crates such as object or xmas-elf. But only store the section data references in the Image.

For #182 , I think we could let Reader to do the ELF parsing for us and we just need to &[uint8] read(".debug_info", offset). If the backend of Reader is memmap, than we could get Zero-copy for free. If the backend is internet, it could do some COW.

grissiom avatar Feb 21 '17 14:02 grissiom