Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected EOF when constructing unit from compilation unit header #405

Closed
AjayMT opened this issue Mar 12, 2019 · 4 comments
Closed

Unexpected EOF when constructing unit from compilation unit header #405

AjayMT opened this issue Mar 12, 2019 · 4 comments

Comments

@AjayMT
Copy link

AjayMT commented Mar 12, 2019

Hello all,

I would first like to thank you for your incredible work -- gimli is by far the most approachable and convenient DWARF parsing library I have found. 😄

I've been trying to parse some Mach-O files on macOS with object and gimli, and I've encountered an issue that I haven't found much documentation on. It is likely an error on my part, but I'm not sure exactly what's causing it. This is the relevant code:

let s_debug_info = parsed_file.section_by_name(".debug_info").unwrap().data();
let s_debug_abbrev = parsed_file.section_by_name(".debug_abbrev").unwrap().data();

let debug_info = gimli::DebugInfo::new(&s_debug_info, gimli::LittleEndian);
let debug_abbrev = gimli::DebugAbbrev::new(&s_debug_abbrev, gimli::LittleEndian);
let dwarf = gimli::Dwarf {
    debug_info,
    debug_abbrev,
    ..Default::default()
};

let units = dwarf.units().collect::<Vec<_>>().unwrap();
for header in units {
    let unit = match dwarf.unit(header) {
        Ok(r) => r,
        Err(err) => {
            println!("error constructing unit for header {:?}: {}", header, err);
            continue;
        }
    };

    println!("unit name {:?}", unit.name.unwrap());
}

dwarf.unit(header) seems to fail every time with an UnexpectedEof error. Perhaps this is due to how I'm loading the data with object?

I am trying to read and parse DWARF files within dSYM bundles, i.e example.dSYM/Contents/Resources/DWARF/example. Please let me know if this is not the right place to ask this question. Any advice is appreciated.

@philipc
Copy link
Collaborator

philipc commented Mar 12, 2019

This is probably because dwarf.unit() tries to parse the line number program too, and you haven't provided the .debug_line section. If there's a reason you don't want to load .debug_line, then I can try to rethink the error handling in dwarf.unit() to see if we can handle this case better.

@philipc
Copy link
Collaborator

philipc commented Mar 12, 2019

I see our example does the same thing, so I'll have to fix that too.

@AjayMT
Copy link
Author

AjayMT commented Mar 12, 2019

Thanks for the quick response. Unfortunately, loading debug_line does not seem to fix the error. The dwarfdump example works perfectly, so it's definitely an issue with my code. I will try loading every DWARF section.

EDIT: loading .debug_str seems to have fixed the issue, I'm not sure why.

@philipc
Copy link
Collaborator

philipc commented Mar 12, 2019

Ah, .debug_str is a similar problem, we often need to use it to parse the DW_AT_name and DW_AT_compdir attributes, and you'll want it anyway if you're doing anything significant using DWARF. I've opened #406 to make it easier to load all the sections. I'm also going to see if we can make the UnexpectedEof error tell you which section the error occurred for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants