[Lldb-commits] [lldb] r374532 - minidump: Use llvm memory info list parser
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 11 04:23:40 PDT 2019
Author: labath
Date: Fri Oct 11 04:23:40 2019
New Revision: 374532
URL: http://llvm.org/viewvc/llvm-project?rev=374532&view=rev
Log:
minidump: Use llvm memory info list parser
Modified:
lldb/trunk/source/Plugins/Process/minidump/MinidumpParser.cpp
lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.cpp
lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.h
lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp
Modified: lldb/trunk/source/Plugins/Process/minidump/MinidumpParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/minidump/MinidumpParser.cpp?rev=374532&r1=374531&r2=374532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/minidump/MinidumpParser.cpp (original)
+++ lldb/trunk/source/Plugins/Process/minidump/MinidumpParser.cpp Fri Oct 11 04:23:40 2019
@@ -427,23 +427,35 @@ CreateRegionsCacheFromLinuxMaps(Minidump
static bool
CreateRegionsCacheFromMemoryInfoList(MinidumpParser &parser,
std::vector<MemoryRegionInfo> ®ions) {
- auto data = parser.GetStream(StreamType::MemoryInfoList);
- if (data.empty())
- return false;
- auto mem_info_list = MinidumpMemoryInfo::ParseMemoryInfoList(data);
- if (mem_info_list.empty())
+ Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES);
+ auto ExpectedInfo = parser.GetMinidumpFile().getMemoryInfoList();
+ if (!ExpectedInfo) {
+ LLDB_LOG_ERROR(log, ExpectedInfo.takeError(),
+ "Failed to read memory info list: {0}");
return false;
+ }
constexpr auto yes = MemoryRegionInfo::eYes;
constexpr auto no = MemoryRegionInfo::eNo;
- regions.reserve(mem_info_list.size());
- for (const auto &entry : mem_info_list) {
+ for (const MemoryInfo &entry : *ExpectedInfo) {
MemoryRegionInfo region;
- region.GetRange().SetRangeBase(entry->base_address);
- region.GetRange().SetByteSize(entry->region_size);
- region.SetReadable(entry->isReadable() ? yes : no);
- region.SetWritable(entry->isWritable() ? yes : no);
- region.SetExecutable(entry->isExecutable() ? yes : no);
- region.SetMapped(entry->isMapped() ? yes : no);
+ region.GetRange().SetRangeBase(entry.BaseAddress);
+ region.GetRange().SetByteSize(entry.RegionSize);
+
+ MemoryProtection prot = entry.Protect;
+ region.SetReadable(bool(prot & MemoryProtection::NoAccess) ? no : yes);
+ region.SetWritable(
+ bool(prot & (MemoryProtection::ReadWrite | MemoryProtection::WriteCopy |
+ MemoryProtection::ExecuteReadWrite |
+ MemoryProtection::ExeciteWriteCopy))
+ ? yes
+ : no);
+ region.SetExecutable(
+ bool(prot & (MemoryProtection::Execute | MemoryProtection::ExecuteRead |
+ MemoryProtection::ExecuteReadWrite |
+ MemoryProtection::ExeciteWriteCopy))
+ ? yes
+ : no);
+ region.SetMapped(entry.State != MemoryState::Free ? yes : no);
regions.push_back(region);
}
return !regions.empty();
Modified: lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.cpp?rev=374532&r1=374531&r2=374532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.cpp (original)
+++ lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.cpp Fri Oct 11 04:23:40 2019
@@ -87,29 +87,3 @@ MinidumpMemoryDescriptor64::ParseMemory6
*mem_ranges_count),
*base_rva);
}
-
-std::vector<const MinidumpMemoryInfo *>
-MinidumpMemoryInfo::ParseMemoryInfoList(llvm::ArrayRef<uint8_t> &data) {
- const MinidumpMemoryInfoListHeader *header;
- Status error = consumeObject(data, header);
- if (error.Fail() ||
- header->size_of_header < sizeof(MinidumpMemoryInfoListHeader) ||
- header->size_of_entry < sizeof(MinidumpMemoryInfo))
- return {};
-
- data = data.drop_front(header->size_of_header -
- sizeof(MinidumpMemoryInfoListHeader));
-
- if (header->size_of_entry * header->num_of_entries > data.size())
- return {};
-
- std::vector<const MinidumpMemoryInfo *> result;
- result.reserve(header->num_of_entries);
-
- for (uint64_t i = 0; i < header->num_of_entries; ++i) {
- result.push_back(reinterpret_cast<const MinidumpMemoryInfo *>(
- data.data() + i * header->size_of_entry));
- }
-
- return result;
-}
Modified: lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.h?rev=374532&r1=374531&r2=374532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.h (original)
+++ lldb/trunk/source/Plugins/Process/minidump/MinidumpTypes.h Fri Oct 11 04:23:40 2019
@@ -85,90 +85,6 @@ struct MinidumpMemoryDescriptor64 {
static_assert(sizeof(MinidumpMemoryDescriptor64) == 16,
"sizeof MinidumpMemoryDescriptor64 is not correct!");
-// Reference:
-// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680385(v=vs.85).aspx
-struct MinidumpMemoryInfoListHeader {
- llvm::support::ulittle32_t size_of_header;
- llvm::support::ulittle32_t size_of_entry;
- llvm::support::ulittle64_t num_of_entries;
-};
-static_assert(sizeof(MinidumpMemoryInfoListHeader) == 16,
- "sizeof MinidumpMemoryInfoListHeader is not correct!");
-
-enum class MinidumpMemoryInfoState : uint32_t {
- MemCommit = 0x1000,
- MemFree = 0x10000,
- MemReserve = 0x2000,
- LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ MemFree)
-};
-
-enum class MinidumpMemoryInfoType : uint32_t {
- MemImage = 0x1000000,
- MemMapped = 0x40000,
- MemPrivate = 0x20000,
- LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ MemImage)
-};
-
-// Reference:
-// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx
-enum class MinidumpMemoryProtectionContants : uint32_t {
- PageExecute = 0x10,
- PageExecuteRead = 0x20,
- PageExecuteReadWrite = 0x40,
- PageExecuteWriteCopy = 0x80,
- PageNoAccess = 0x01,
- PageReadOnly = 0x02,
- PageReadWrite = 0x04,
- PageWriteCopy = 0x08,
- PageTargetsInvalid = 0x40000000,
- PageTargetsNoUpdate = 0x40000000,
-
- PageWritable = PageExecuteReadWrite | PageExecuteWriteCopy | PageReadWrite |
- PageWriteCopy,
- PageExecutable = PageExecute | PageExecuteRead | PageExecuteReadWrite |
- PageExecuteWriteCopy,
- LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ PageTargetsInvalid)
-};
-
-// Reference:
-// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680386(v=vs.85).aspx
-struct MinidumpMemoryInfo {
- llvm::support::ulittle64_t base_address;
- llvm::support::ulittle64_t allocation_base;
- llvm::support::ulittle32_t allocation_protect;
- llvm::support::ulittle32_t alignment1;
- llvm::support::ulittle64_t region_size;
- llvm::support::ulittle32_t state;
- llvm::support::ulittle32_t protect;
- llvm::support::ulittle32_t type;
- llvm::support::ulittle32_t alignment2;
-
- static std::vector<const MinidumpMemoryInfo *>
- ParseMemoryInfoList(llvm::ArrayRef<uint8_t> &data);
-
- bool isReadable() const {
- const auto mask = MinidumpMemoryProtectionContants::PageNoAccess;
- return (static_cast<uint32_t>(mask) & protect) == 0;
- }
-
- bool isWritable() const {
- const auto mask = MinidumpMemoryProtectionContants::PageWritable;
- return (static_cast<uint32_t>(mask) & protect) != 0;
- }
-
- bool isExecutable() const {
- const auto mask = MinidumpMemoryProtectionContants::PageExecutable;
- return (static_cast<uint32_t>(mask) & protect) != 0;
- }
-
- bool isMapped() const {
- return state != static_cast<uint32_t>(MinidumpMemoryInfoState::MemFree);
- }
-};
-
-static_assert(sizeof(MinidumpMemoryInfo) == 48,
- "sizeof MinidumpMemoryInfo is not correct!");
-
// TODO misc2, misc3 ?
// Reference:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680389(v=vs.85).aspx
Modified: lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp?rev=374532&r1=374531&r2=374532&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp (original)
+++ lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp Fri Oct 11 04:23:40 2019
@@ -338,6 +338,7 @@ void check_region(MinidumpParser &parser
MemoryRegionInfo::OptionalBool exec,
MemoryRegionInfo::OptionalBool mapped,
ConstString name = ConstString()) {
+ SCOPED_TRACE(addr);
auto range_info = parser.GetMemoryRegionInfo(addr);
EXPECT_EQ(start, range_info.GetRange().GetRangeBase());
EXPECT_EQ(end, range_info.GetRange().GetRangeEnd());
More information about the lldb-commits
mailing list