summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-10-08 14:15:32 +0000
committerPavel Labath <pavel@labath.sk>2019-10-08 14:15:32 +0000
commit6e0b1ce48e3cf95f447b932b03d8294903aa56e0 (patch)
tree67248666290e3d82f2df1da5fefb6795d3b7c6ec /llvm/lib/Object
parent534c86d172528d791738c0503948ee9bf883a9f3 (diff)
downloadbcm5719-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/lib/Object')
-rw-r--r--llvm/lib/Object/Minidump.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/llvm/lib/Object/Minidump.cpp b/llvm/lib/Object/Minidump.cpp
index 7b5b2155869..3e932fe7be2 100644
--- a/llvm/lib/Object/Minidump.cpp
+++ b/llvm/lib/Object/Minidump.cpp
@@ -53,13 +53,30 @@ Expected<std::string> MinidumpFile::getString(size_t Offset) const {
return Result;
}
+Expected<iterator_range<MinidumpFile::MemoryInfoIterator>>
+MinidumpFile::getMemoryInfoList() const {
+ Optional<ArrayRef<uint8_t>> Stream = getRawStream(StreamType::MemoryInfoList);
+ if (!Stream)
+ return createError("No such stream");
+ auto ExpectedHeader =
+ getDataSliceAs<minidump::MemoryInfoListHeader>(*Stream, 0, 1);
+ if (!ExpectedHeader)
+ return ExpectedHeader.takeError();
+ const minidump::MemoryInfoListHeader &H = ExpectedHeader.get()[0];
+ Expected<ArrayRef<uint8_t>> Data =
+ getDataSlice(*Stream, H.SizeOfHeader, H.SizeOfEntry * H.NumberOfEntries);
+ if (!Data)
+ return Data.takeError();
+ return make_range(MemoryInfoIterator(*Data, H.SizeOfEntry),
+ MemoryInfoIterator({}, H.SizeOfEntry));
+}
+
template <typename T>
-Expected<ArrayRef<T>> MinidumpFile::getListStream(StreamType Stream) const {
- auto OptionalStream = getRawStream(Stream);
- if (!OptionalStream)
+Expected<ArrayRef<T>> MinidumpFile::getListStream(StreamType Type) const {
+ Optional<ArrayRef<uint8_t>> Stream = getRawStream(Type);
+ if (!Stream)
return createError("No such stream");
- auto ExpectedSize =
- getDataSliceAs<support::ulittle32_t>(*OptionalStream, 0, 1);
+ auto ExpectedSize = getDataSliceAs<support::ulittle32_t>(*Stream, 0, 1);
if (!ExpectedSize)
return ExpectedSize.takeError();
@@ -69,10 +86,10 @@ Expected<ArrayRef<T>> MinidumpFile::getListStream(StreamType Stream) const {
// Some producers insert additional padding bytes to align the list to an
// 8-byte boundary. Check for that by comparing the list size with the overall
// stream size.
- if (ListOffset + sizeof(T) * ListSize < OptionalStream->size())
+ if (ListOffset + sizeof(T) * ListSize < Stream->size())
ListOffset = 8;
- return getDataSliceAs<T>(*OptionalStream, ListOffset, ListSize);
+ return getDataSliceAs<T>(*Stream, ListOffset, ListSize);
}
template Expected<ArrayRef<Module>>
MinidumpFile::getListStream(StreamType) const;
@@ -109,13 +126,14 @@ MinidumpFile::create(MemoryBufferRef Source) {
return ExpectedStreams.takeError();
DenseMap<StreamType, std::size_t> StreamMap;
- for (const auto &Stream : llvm::enumerate(*ExpectedStreams)) {
- StreamType Type = Stream.value().Type;
- const LocationDescriptor &Loc = Stream.value().Location;
+ for (const auto &StreamDescriptor : llvm::enumerate(*ExpectedStreams)) {
+ StreamType Type = StreamDescriptor.value().Type;
+ const LocationDescriptor &Loc = StreamDescriptor.value().Location;
- auto ExpectedStream = getDataSlice(Data, Loc.RVA, Loc.DataSize);
- if (!ExpectedStream)
- return ExpectedStream.takeError();
+ Expected<ArrayRef<uint8_t>> Stream =
+ getDataSlice(Data, Loc.RVA, Loc.DataSize);
+ if (!Stream)
+ return Stream.takeError();
if (Type == StreamType::Unused && Loc.DataSize == 0) {
// Ignore dummy streams. This is technically ill-formed, but a number of
@@ -128,7 +146,7 @@ MinidumpFile::create(MemoryBufferRef Source) {
return createError("Cannot handle one of the minidump streams");
// Update the directory map, checking for duplicate stream types.
- if (!StreamMap.try_emplace(Type, Stream.index()).second)
+ if (!StreamMap.try_emplace(Type, StreamDescriptor.index()).second)
return createError("Duplicate stream type");
}
OpenPOWER on IntegriCloud