Patch to add API to read ELF ProgramHeader/Segment

The attached patch adds 3 new functions to ObjectFileELF which enables accessing ELF segment data possible.

Segment data is needed to support elf core files.

Please review and commit(if ok).


lldb-elf-segment.diff (1.86 KB)

Welcome back, Samuel, and thanks for the patch. A few minor thoughts:

Consider testing id first so that parsing isn’t required on the failure path. Also, prefer nullptr over NULL throughout:

  • if (!ParseProgramHeaders() || !id)

  • return NULL;

Consider adding a failure patch if GetProgramHeaderByIndex returns nullptr:

  • const elf::ELFProgramHeader *segment_header = GetProgramHeaderByIndex(id);

  • return DataExtractor(m_data, segment_header->p_offset, segment_header->p_filesz);

Maybe avoid the cross-post also so we have just one thread for the review. Cheers,

  • Ashok

Thanks for the revised patch, Samuel. I tested and committed in r186114, which is looking green on the buildbots,

  • Ashok