Revert "Revert "[lldb] Make SBSection::GetSectionData call Section::GetSectionData.""

This reverts commit e1bbe50f5a.

Differential Revision: https://reviews.llvm.org/D142672
This commit is contained in:
Muhammad Omair Javaid 2023-01-30 16:43:52 +05:00
parent 5a9cb37722
commit bde5d31e96
3 changed files with 36 additions and 29 deletions

View File

@ -182,35 +182,10 @@ SBData SBSection::GetSectionData(uint64_t offset, uint64_t size) {
SBData sb_data;
SectionSP section_sp(GetSP());
if (section_sp) {
const uint64_t sect_file_size = section_sp->GetFileSize();
if (sect_file_size > 0) {
ModuleSP module_sp(section_sp->GetModule());
if (module_sp) {
ObjectFile *objfile = module_sp->GetObjectFile();
if (objfile) {
const uint64_t sect_file_offset =
objfile->GetFileOffset() + section_sp->GetFileOffset();
const uint64_t file_offset = sect_file_offset + offset;
uint64_t file_size = size;
if (file_size == UINT64_MAX) {
file_size = section_sp->GetByteSize();
if (file_size > offset)
file_size -= offset;
else
file_size = 0;
}
auto data_buffer_sp = FileSystem::Instance().CreateDataBuffer(
objfile->GetFileSpec().GetPath(), file_size, file_offset);
if (data_buffer_sp && data_buffer_sp->GetByteSize() > 0) {
DataExtractorSP data_extractor_sp(
new DataExtractor(data_buffer_sp, objfile->GetByteOrder(),
objfile->GetAddressByteSize()));
sb_data.SetOpaque(data_extractor_sp);
}
}
}
}
DataExtractor section_data;
section_sp->GetSectionData(section_data);
sb_data.SetOpaque(
std::make_shared<DataExtractor>(section_data, offset, size));
}
return sb_data;
}

View File

@ -11,6 +11,8 @@ from lldbsuite.test import lldbutil
class SectionAPITestCase(TestBase):
@no_debug_info_test
@skipIfXmlSupportMissing
def test_get_target_byte_size(self):
d = {'EXE': 'b.out'}
self.build(dictionary=d)
@ -38,6 +40,8 @@ class SectionAPITestCase(TestBase):
self.assertIsNotNone(data_section)
self.assertEqual(data_section.target_byte_size, 1)
@no_debug_info_test
@skipIfXmlSupportMissing
def test_get_alignment(self):
exe = self.getBuildArtifact("aligned.out")
self.yaml2obj("aligned.yaml", exe)
@ -48,3 +52,20 @@ class SectionAPITestCase(TestBase):
section = target.modules[0].sections[0]
self.assertEqual(section.GetAlignment(), 0x1000)
self.assertEqual(section.alignment, 0x1000)
@no_debug_info_test
@skipIfXmlSupportMissing
def test_compressed_section_data(self):
exe = self.getBuildArtifact("compressed-sections.out")
self.yaml2obj("compressed-sections.yaml", exe)
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# exe contains a single section with SHF_COMPRESSED. Check that
# GetSectionData returns the uncompressed data and not the raw contents
# of the section.
section = target.modules[0].sections[0]
section_data = section.GetSectionData().uint8s
self.assertEqual(section_data,
[0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90])

View File

@ -0,0 +1,11 @@
--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_386
Sections:
- Name: .compressed
Type: SHT_PROGBITS
Flags: [ SHF_COMPRESSED ]
Content: 010000000800000001000000789c5330700848286898000009c802c1