[Lldb-commits] [lldb] e1bbe50 - Revert "[lldb] Make SBSection::GetSectionData call Section::GetSectionData."

Muhammad Omair Javaid via lldb-commits lldb-commits at lists.llvm.org
Sun Jan 29 23:35:42 PST 2023


Author: Muhammad Omair Javaid
Date: 2023-01-30T12:34:37+05:00
New Revision: e1bbe50f5a48e9b5407de9e5f4ab8197dedc85c5

URL: https://github.com/llvm/llvm-project/commit/e1bbe50f5a48e9b5407de9e5f4ab8197dedc85c5
DIFF: https://github.com/llvm/llvm-project/commit/e1bbe50f5a48e9b5407de9e5f4ab8197dedc85c5.diff

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

This reverts commit 805600c7d573cf88cf035d01a2ea9389fc24d435.

LLDB windows buildbots were broken by the TestSectionAPI.py test. I dont
have full context of the commit to fix it. Reverting it temporarily.

https://lab.llvm.org/buildbot/#/builders/83/builds/28617
https://lab.llvm.org/buildbot/#/builders/219/builds/180

Differential Revision: https://reviews.llvm.org/D142672

Added: 
    

Modified: 
    lldb/source/API/SBSection.cpp
    lldb/test/API/python_api/section/TestSectionAPI.py

Removed: 
    lldb/test/API/python_api/section/compressed-sections.yaml


################################################################################
diff  --git a/lldb/source/API/SBSection.cpp b/lldb/source/API/SBSection.cpp
index b7b94f3ece1a6..3a9cf20e484a5 100644
--- a/lldb/source/API/SBSection.cpp
+++ b/lldb/source/API/SBSection.cpp
@@ -182,10 +182,35 @@ SBData SBSection::GetSectionData(uint64_t offset, uint64_t size) {
   SBData sb_data;
   SectionSP section_sp(GetSP());
   if (section_sp) {
-    DataExtractor section_data;
-    section_sp->GetSectionData(section_data);
-    sb_data.SetOpaque(
-        std::make_shared<DataExtractor>(section_data, offset, size));
+    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);
+          }
+        }
+      }
+    }
   }
   return sb_data;
 }

diff  --git a/lldb/test/API/python_api/section/TestSectionAPI.py b/lldb/test/API/python_api/section/TestSectionAPI.py
index b01ddece0de36..ab9ae56238c8b 100644
--- a/lldb/test/API/python_api/section/TestSectionAPI.py
+++ b/lldb/test/API/python_api/section/TestSectionAPI.py
@@ -48,18 +48,3 @@ def test_get_alignment(self):
         section = target.modules[0].sections[0]
         self.assertEqual(section.GetAlignment(), 0x1000)
         self.assertEqual(section.alignment, 0x1000)
-
-    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])
-

diff  --git a/lldb/test/API/python_api/section/compressed-sections.yaml b/lldb/test/API/python_api/section/compressed-sections.yaml
deleted file mode 100644
index a41307ef7d1fc..0000000000000
--- a/lldb/test/API/python_api/section/compressed-sections.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
---- !ELF
-FileHeader:
-  Class:           ELFCLASS32
-  Data:            ELFDATA2LSB
-  Type:            ET_REL
-  Machine:         EM_386
-Sections:
-  - Name:            .compressed
-    Type:            SHT_PROGBITS
-    Flags:           [ SHF_COMPRESSED ]
-    Content:         010000000800000001000000789c5330700848286898000009c802c1


        


More information about the lldb-commits mailing list