diff options
author | Pavel Labath <pavel@labath.sk> | 2019-10-08 14:15:32 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-10-08 14:15:32 +0000 |
commit | 6e0b1ce48e3cf95f447b932b03d8294903aa56e0 (patch) | |
tree | 67248666290e3d82f2df1da5fefb6795d3b7c6ec /llvm/unittests/Object/MinidumpTest.cpp | |
parent | 534c86d172528d791738c0503948ee9bf883a9f3 (diff) | |
download | bcm5719-llvm-6e0b1ce48e3cf95f447b932b03d8294903aa56e0.tar.gz bcm5719-llvm-6e0b1ce48e3cf95f447b932b03d8294903aa56e0.zip |
Object/minidump: Add support for the MemoryInfoList stream
Summary:
This patch adds the definitions of the constants and structures
necessary to interpret the MemoryInfoList minidump stream, as well as
the object::MinidumpFile interface to access the stream.
While the code is fairly simple, there is one important deviation from
the other minidump streams, which is worth calling out explicitly.
Unlike other "List" streams, the size of the records inside
MemoryInfoList stream is not known statically. Instead it is described
in the stream header. This makes it impossible to return
ArrayRef<MemoryInfo> from the accessor method, as it is done with other
streams. Instead, I create an iterator class, which can be parameterized
by the runtime size of the structure, and return
iterator_range<iterator> instead.
Reviewers: amccarth, jhenderson, clayborg
Subscribers: JosephTremoulet, zturner, markmentovai, lldb-commits, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68210
llvm-svn: 374051
Diffstat (limited to 'llvm/unittests/Object/MinidumpTest.cpp')
-rw-r--r-- | llvm/unittests/Object/MinidumpTest.cpp | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/llvm/unittests/Object/MinidumpTest.cpp b/llvm/unittests/Object/MinidumpTest.cpp index ba9af5a8247..5abb5b77fa2 100644 --- a/llvm/unittests/Object/MinidumpTest.cpp +++ b/llvm/unittests/Object/MinidumpTest.cpp @@ -511,3 +511,202 @@ TEST(MinidumpFile, getMemoryList) { EXPECT_EQ(0x00090807u, MD.Memory.RVA); } } + +TEST(MinidumpFile, getMemoryInfoList) { + std::vector<uint8_t> OneEntry{ + // Header + 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version + 1, 0, 0, 0, // NumberOfStreams, + 32, 0, 0, 0, // StreamDirectoryRVA + 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp + 0, 0, 0, 0, 0, 0, 0, 0, // Flags + // Stream Directory + 16, 0, 0, 0, 64, 0, 0, 0, // Type, DataSize, + 44, 0, 0, 0, // RVA + // MemoryInfoListHeader + 16, 0, 0, 0, 48, 0, 0, 0, // SizeOfHeader, SizeOfEntry + 1, 0, 0, 0, 0, 0, 0, 0, // NumberOfEntries + // MemoryInfo + 0, 1, 2, 3, 4, 5, 6, 7, // BaseAddress + 8, 9, 0, 1, 2, 3, 4, 5, // AllocationBase + 16, 0, 0, 0, 6, 7, 8, 9, // AllocationProtect, Reserved0 + 0, 1, 2, 3, 4, 5, 6, 7, // RegionSize + 0, 16, 0, 0, 32, 0, 0, 0, // State, Protect + 0, 0, 2, 0, 8, 9, 0, 1, // Type, Reserved1 + }; + + // Same as before, but the list header is larger. + std::vector<uint8_t> BiggerHeader{ + // Header + 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version + 1, 0, 0, 0, // NumberOfStreams, + 32, 0, 0, 0, // StreamDirectoryRVA + 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp + 0, 0, 0, 0, 0, 0, 0, 0, // Flags + // Stream Directory + 16, 0, 0, 0, 68, 0, 0, 0, // Type, DataSize, + 44, 0, 0, 0, // RVA + // MemoryInfoListHeader + 20, 0, 0, 0, 48, 0, 0, 0, // SizeOfHeader, SizeOfEntry + 1, 0, 0, 0, 0, 0, 0, 0, // NumberOfEntries + 0, 0, 0, 0, // ??? + // MemoryInfo + 0, 1, 2, 3, 4, 5, 6, 7, // BaseAddress + 8, 9, 0, 1, 2, 3, 4, 5, // AllocationBase + 16, 0, 0, 0, 6, 7, 8, 9, // AllocationProtect, Reserved0 + 0, 1, 2, 3, 4, 5, 6, 7, // RegionSize + 0, 16, 0, 0, 32, 0, 0, 0, // State, Protect + 0, 0, 2, 0, 8, 9, 0, 1, // Type, Reserved1 + }; + + // Same as before, but the entry is larger. + std::vector<uint8_t> BiggerEntry{ + // Header + 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version + 1, 0, 0, 0, // NumberOfStreams, + 32, 0, 0, 0, // StreamDirectoryRVA + 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp + 0, 0, 0, 0, 0, 0, 0, 0, // Flags + // Stream Directory + 16, 0, 0, 0, 68, 0, 0, 0, // Type, DataSize, + 44, 0, 0, 0, // RVA + // MemoryInfoListHeader + 16, 0, 0, 0, 52, 0, 0, 0, // SizeOfHeader, SizeOfEntry + 1, 0, 0, 0, 0, 0, 0, 0, // NumberOfEntries + // MemoryInfo + 0, 1, 2, 3, 4, 5, 6, 7, // BaseAddress + 8, 9, 0, 1, 2, 3, 4, 5, // AllocationBase + 16, 0, 0, 0, 6, 7, 8, 9, // AllocationProtect, Reserved0 + 0, 1, 2, 3, 4, 5, 6, 7, // RegionSize + 0, 16, 0, 0, 32, 0, 0, 0, // State, Protect + 0, 0, 2, 0, 8, 9, 0, 1, // Type, Reserved1 + 0, 0, 0, 0, // ??? + }; + + for (ArrayRef<uint8_t> Data : {OneEntry, BiggerHeader, BiggerEntry}) { + auto ExpectedFile = create(Data); + ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded()); + const MinidumpFile &File = **ExpectedFile; + auto ExpectedInfo = File.getMemoryInfoList(); + ASSERT_THAT_EXPECTED(ExpectedInfo, Succeeded()); + ASSERT_EQ(1u, std::distance(ExpectedInfo->begin(), ExpectedInfo->end())); + const MemoryInfo &Info = *ExpectedInfo.get().begin(); + EXPECT_EQ(0x0706050403020100u, Info.BaseAddress); + EXPECT_EQ(0x0504030201000908u, Info.AllocationBase); + EXPECT_EQ(MemoryProtection::Execute, Info.AllocationProtect); + EXPECT_EQ(0x09080706u, Info.Reserved0); + EXPECT_EQ(0x0706050403020100u, Info.RegionSize); + EXPECT_EQ(MemoryState::Commit, Info.State); + EXPECT_EQ(MemoryProtection::ExecuteRead, Info.Protect); + EXPECT_EQ(MemoryType::Private, Info.Type); + EXPECT_EQ(0x01000908u, Info.Reserved1); + } + + // Header does not fit into the stream. + std::vector<uint8_t> HeaderTooBig{ + // Header + 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version + 1, 0, 0, 0, // NumberOfStreams, + 32, 0, 0, 0, // StreamDirectoryRVA + 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp + 0, 0, 0, 0, 0, 0, 0, 0, // Flags + // Stream Directory + 16, 0, 0, 0, 15, 0, 0, 0, // Type, DataSize, + 44, 0, 0, 0, // RVA + // MemoryInfoListHeader + 16, 0, 0, 0, 48, 0, 0, 0, // SizeOfHeader, SizeOfEntry + 1, 0, 0, 0, 0, 0, 0, // ??? + }; + Expected<std::unique_ptr<MinidumpFile>> File = create(HeaderTooBig); + ASSERT_THAT_EXPECTED(File, Succeeded()); + EXPECT_THAT_EXPECTED(File.get()->getMemoryInfoList(), Failed<BinaryError>()); + + // Header fits into the stream, but it is too small to contain the required + // entries. + std::vector<uint8_t> HeaderTooSmall{ + // Header + 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version + 1, 0, 0, 0, // NumberOfStreams, + 32, 0, 0, 0, // StreamDirectoryRVA + 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp + 0, 0, 0, 0, 0, 0, 0, 0, // Flags + // Stream Directory + 16, 0, 0, 0, 15, 0, 0, 0, // Type, DataSize, + 44, 0, 0, 0, // RVA + // MemoryInfoListHeader + 15, 0, 0, 0, 48, 0, 0, 0, // SizeOfHeader, SizeOfEntry + 1, 0, 0, 0, 0, 0, 0, // ??? + }; + File = create(HeaderTooSmall); + ASSERT_THAT_EXPECTED(File, Succeeded()); + EXPECT_THAT_EXPECTED(File.get()->getMemoryInfoList(), Failed<BinaryError>()); + + std::vector<uint8_t> EntryTooBig{ + // Header + 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version + 1, 0, 0, 0, // NumberOfStreams, + 32, 0, 0, 0, // StreamDirectoryRVA + 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp + 0, 0, 0, 0, 0, 0, 0, 0, // Flags + // Stream Directory + 16, 0, 0, 0, 64, 0, 0, 0, // Type, DataSize, + 44, 0, 0, 0, // RVA + // MemoryInfoListHeader + 16, 0, 0, 0, 49, 0, 0, 0, // SizeOfHeader, SizeOfEntry + 1, 0, 0, 0, 0, 0, 0, 0, // NumberOfEntries + // MemoryInfo + 0, 1, 2, 3, 4, 5, 6, 7, // BaseAddress + 8, 9, 0, 1, 2, 3, 4, 5, // AllocationBase + 16, 0, 0, 0, 6, 7, 8, 9, // AllocationProtect, Reserved0 + 0, 1, 2, 3, 4, 5, 6, 7, // RegionSize + 0, 16, 0, 0, 32, 0, 0, 0, // State, Protect + 0, 0, 2, 0, 8, 9, 0, 1, // Type, Reserved1 + }; + File = create(EntryTooBig); + ASSERT_THAT_EXPECTED(File, Succeeded()); + EXPECT_THAT_EXPECTED(File.get()->getMemoryInfoList(), Failed<BinaryError>()); + + std::vector<uint8_t> ThreeEntries{ + // Header + 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version + 1, 0, 0, 0, // NumberOfStreams, + 32, 0, 0, 0, // StreamDirectoryRVA + 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp + 0, 0, 0, 0, 0, 0, 0, 0, // Flags + // Stream Directory + 16, 0, 0, 0, 160, 0, 0, 0, // Type, DataSize, + 44, 0, 0, 0, // RVA + // MemoryInfoListHeader + 16, 0, 0, 0, 48, 0, 0, 0, // SizeOfHeader, SizeOfEntry + 3, 0, 0, 0, 0, 0, 0, 0, // NumberOfEntries + // MemoryInfo + 0, 1, 2, 3, 0, 0, 0, 0, // BaseAddress + 0, 0, 0, 0, 0, 0, 0, 0, // AllocationBase + 0, 0, 0, 0, 0, 0, 0, 0, // AllocationProtect, Reserved0 + 0, 0, 0, 0, 0, 0, 0, 0, // RegionSize + 0, 0, 0, 0, 0, 0, 0, 0, // State, Protect + 0, 0, 0, 0, 0, 0, 0, 0, // Type, Reserved1 + 0, 0, 4, 5, 6, 7, 0, 0, // BaseAddress + 0, 0, 0, 0, 0, 0, 0, 0, // AllocationBase + 0, 0, 0, 0, 0, 0, 0, 0, // AllocationProtect, Reserved0 + 0, 0, 0, 0, 0, 0, 0, 0, // RegionSize + 0, 0, 0, 0, 0, 0, 0, 0, // State, Protect + 0, 0, 0, 0, 0, 0, 0, 0, // Type, Reserved1 + 0, 0, 0, 8, 9, 0, 1, 0, // BaseAddress + 0, 0, 0, 0, 0, 0, 0, 0, // AllocationBase + 0, 0, 0, 0, 0, 0, 0, 0, // AllocationProtect, Reserved0 + 0, 0, 0, 0, 0, 0, 0, 0, // RegionSize + 0, 0, 0, 0, 0, 0, 0, 0, // State, Protect + 0, 0, 0, 0, 0, 0, 0, 0, // Type, Reserved1 + }; + File = create(ThreeEntries); + ASSERT_THAT_EXPECTED(File, Succeeded()); + auto ExpectedInfo = File.get()->getMemoryInfoList(); + ASSERT_THAT_EXPECTED(ExpectedInfo, Succeeded()); + EXPECT_THAT(to_vector<3>(map_range(*ExpectedInfo, + [](const MemoryInfo &Info) -> uint64_t { + return Info.BaseAddress; + })), + testing::ElementsAre(0x0000000003020100u, 0x0000070605040000u, + 0x0001000908000000u)); +} |