This is an archive of the discontinued LLVM Phabricator instance.

[Object, MachO] Introduce MachOObjectFile::load_commands() range iterator.
ClosedPublic

Authored by samsonov on May 29 2015, 6:12 PM.

Details

Summary

Now users don't have to manually deal with getFirstLoadCommandInfo() /
getNextLoadCommandInfo(), calculate the number of load segments, etc.
Additionally, the iterator has a support for error handling, that
would allow to detect the case when the next load command cannot be
parsed.

Diff Detail

Event Timeline

samsonov updated this revision to Diff 26840.May 29 2015, 6:12 PM
samsonov retitled this revision from to [Object, MachO] Introduce MachOObjectFile::load_commands() range iterator..
samsonov updated this object.
samsonov edited the test plan for this revision. (Show Details)
samsonov added reviewers: rafael, lhames, loladiro.
samsonov added a subscriber: Unknown Object (MLST).

Wait a second, this is stupid. We're walking through all load commands in the constructor and fail to create an object if another command can't be parsed. We should just cache all the load commands in a vector, and get rid of all this ErrorOr<> stuff. I'll update the patch shortly, sorry for noise.

rafael edited edge metadata.Jun 1 2015, 7:25 AM

If we can instead avoid walking all the load commands that would be
even better :-)

samsonov updated this revision to Diff 26914.Jun 1 2015, 11:14 AM
samsonov edited edge metadata.
  • Parse all MachO load commands in constructor, and store them in a vector.

Alright, now this changes significantly simplifies the users' code - they can use a simple foreach to iterate over all load commands. I will add error recovery for the case when we can't parse load command info in a subsequent change. This one has NFC. Please take a look.

rafael accepted this revision.Jun 1 2015, 12:03 PM
rafael edited edge metadata.

LGTM, thanks

This revision is now accepted and ready to land.Jun 1 2015, 12:03 PM
This revision was automatically updated to reflect the committed changes.