Skip to content

Commit a54492f

Browse files
committed
Address review comments.
1 parent d653c41 commit a54492f

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,8 @@ static bool GetOsFromOSABI(unsigned char osabi_byte,
559559
/// Read the bytes for the section headers from the ELF object file data.
560560
static DataExtractor GetSectionHeadersFromELFData(
561561
const elf::ELFHeader &header, const DataExtractor &object_data) {
562-
DataExtractor sh_data;
563-
const elf_off sh_offset = header.e_shoff;
564-
const size_t sh_size = header.GetSectionHeaderByteSize();
565-
sh_data.SetData(object_data, sh_offset, sh_size);
566-
return sh_data;
562+
return DataExtractor(object_data, header.e_shoff,
563+
header.GetSectionHeaderByteSize());;
567564
}
568565

569566
/// Read the section data bytes for the section from the ELF object file data.
@@ -1511,8 +1508,17 @@ size_t ObjectFileELF::GetSectionHeaderInfo(const elf::ELFHeader &header,
15111508
// SHT_NULL sections if we have more than 1. The first entry in the section
15121509
// headers should always be a SHT_NULL section, but none of the others should
15131510
// be.
1514-
if (section_headers.size() > 1 && section_headers[1].sh_type == SHT_NULL)
1515-
section_headers.erase(section_headers.begin() + 1);
1511+
if (section_headers.size() > 1 && section_headers[1].sh_type == SHT_NULL) {
1512+
uint64_t null_count = std::count_if(section_headers.begin(),
1513+
section_headers.end(),
1514+
[](const ELFSectionHeaderInfo &sh){
1515+
return sh.sh_type == SHT_NULL;
1516+
});
1517+
if (null_count == section_headers.size()) {
1518+
// Keep only 1 SHT_NULL section if they were all SHT_NULL types.
1519+
section_headers.erase(section_headers.begin() + 1);
1520+
}
1521+
}
15161522

15171523
const unsigned strtab_idx = header.e_shstrndx;
15181524
if (strtab_idx && strtab_idx < section_headers.size()) {
@@ -3861,11 +3867,10 @@ DataExtractor ObjectFileELF::GetSectionData(const elf::ELFSectionHeader &sh) {
38613867
// We have a ELF file in process memory, read the program header data from
38623868
// the process.
38633869
if (ProcessSP process_sp = m_process_wp.lock()) {
3864-
const addr_t data_addr = m_memory_addr + sh.sh_offset;
3865-
if (DataBufferSP data_sp = ReadMemory(process_sp, data_addr, sh.sh_size)) {
3866-
data = DataExtractor(data_sp, GetByteOrder(), GetAddressByteSize());
3867-
if (data.GetByteSize() == sh.sh_size)
3868-
return data;
3870+
const addr_t addr = m_memory_addr + sh.sh_offset;
3871+
if (DataBufferSP data_sp = ReadMemory(process_sp, addr, sh.sh_size)) {
3872+
if (data_sp->GetByteSize() == sh.sh_size)
3873+
return DataExtractor(data_sp, GetByteOrder(), GetAddressByteSize());
38693874
}
38703875
}
38713876
}

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class ObjectFileELF : public lldb_private::ObjectFile {
303303
/// \return True if the section has a size and all bytes can be read,
304304
/// False otherwise.
305305
using ReadSectionDataCallback =
306-
std::function<bool(const elf::ELFSectionHeader &sh,
306+
llvm::function_ref<bool(const elf::ELFSectionHeader &sh,
307307
lldb_private::DataExtractor &data)>;
308308

309309
/// Parses the elf section headers and returns the uuid, debug link name,

0 commit comments

Comments
 (0)