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) 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 =