[Lldb-commits] [PATCH] D67370: Fix ELF core file memory reading for PT_LOAD program headers with no p_filesz

Phabricator via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 9 14:44:21 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL371457: Fix ELF core file memory reading for PT_LOAD program headers with no p_filesz (authored by gclayton, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67370?vs=219423&id=219436#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67370/new/

https://reviews.llvm.org/D67370

Files:
  lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py
  lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp


Index: lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -118,16 +118,20 @@
   FileRange file_range(header.p_offset, header.p_filesz);
   VMRangeToFileOffset::Entry range_entry(addr, header.p_memsz, file_range);
 
-  VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
-  if (last_entry && last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
-      last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
-      last_entry->GetByteSize() == last_entry->data.GetByteSize()) {
-    last_entry->SetRangeEnd(range_entry.GetRangeEnd());
-    last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
-  } else {
-    m_core_aranges.Append(range_entry);
+  // Only add to m_core_aranges if the file size is non zero. Some core files
+  // have PT_LOAD segments for all address ranges, but set f_filesz to zero for
+  // the .text sections since they can be retrieved from the object files.
+  if (header.p_filesz > 0) {
+    VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
+    if (last_entry && last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
+        last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
+        last_entry->GetByteSize() == last_entry->data.GetByteSize()) {
+      last_entry->SetRangeEnd(range_entry.GetRangeEnd());
+      last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
+    } else {
+      m_core_aranges.Append(range_entry);
+    }
   }
-
   // Keep a separate map of permissions that that isn't coalesced so all ranges
   // are maintained.
   const uint32_t permissions =
Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/thread_crash/TestLinuxCoreThreads.py
@@ -51,6 +51,17 @@
         self.assertEqual(process.GetProcessID(), pid)
 
         for thread in process:
+            # Verify that if we try to read memory from a PT_LOAD that has
+            # p_filesz of zero that we don't get bytes from the next section
+            # that actually did have bytes. The addresses below were found by
+            # dumping the program headers of linux-i386.core and
+            # linux-x86_64.core and verifying that they had a p_filesz of zero.
+            mem_err = lldb.SBError()
+            if process.GetAddressByteSize() == 4:
+                bytes_read = process.ReadMemory(0x8048000, 4, mem_err)
+            else:
+                bytes_read = process.ReadMemory(0x400000, 4, mem_err)
+            self.assertEqual(bytes_read, None)
             reason = thread.GetStopReason()
             if( thread.GetThreadID() == tid ):
                 self.assertEqual(reason, lldb.eStopReasonSignal)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67370.219436.patch
Type: text/x-patch
Size: 3174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190909/7e3ad827/attachment-0001.bin>


More information about the lldb-commits mailing list