From aaff480c68cac3c363420292ff58889c366aca5c Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 8 Apr 2019 09:57:29 +0000 Subject: Object/Minidump: Add support for reading the ModuleList stream Summary: The ModuleList stream consists of an integer giving the number of entries in the list, followed by the list itself. Each entry in the list describes a module (dynamically loaded objects which were loaded in the process when it crashed (or when the minidump was generated). The code for reading the list is relatively straight-forward, with a single gotcha. Some minidump writers are emitting padding after the "count" field in order to align the subsequent list on 8 byte boundary (this depends on how their ModuleList type was defined and the native alignment of various types on their platform). Fortunately, the minidump format contains enough redundancy (in the form of the stream length field in the stream directory), which allows us to detect this situation and correct it. This patch just adds the ability to parse the stream. Code for conversion to/from yaml will come in a follow-up patch. Reviewers: zturner, amccarth, jhenderson, clayborg Subscribers: jdoerfert, markmentovai, lldb-commits, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60121 llvm-svn: 357897 --- llvm/lib/Object/Minidump.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'llvm/lib/Object/Minidump.cpp') diff --git a/llvm/lib/Object/Minidump.cpp b/llvm/lib/Object/Minidump.cpp index 1a22491ce3c..4b1abe52994 100644 --- a/llvm/lib/Object/Minidump.cpp +++ b/llvm/lib/Object/Minidump.cpp @@ -53,6 +53,27 @@ Expected MinidumpFile::getString(size_t Offset) const { return Result; } +Expected> MinidumpFile::getModuleList() const { + auto OptionalStream = getRawStream(StreamType::ModuleList); + if (!OptionalStream) + return createError("No such stream"); + auto ExpectedSize = + getDataSliceAs(*OptionalStream, 0, 1); + if (!ExpectedSize) + return ExpectedSize.takeError(); + + size_t ListSize = ExpectedSize.get()[0]; + + size_t ListOffset = 4; + // Some producers insert additional padding bytes to align the module list to + // 8-byte boundary. Check for that by comparing the module list size with the + // overall stream size. + if (ListOffset + sizeof(Module) * ListSize < OptionalStream->size()) + ListOffset = 8; + + return getDataSliceAs(*OptionalStream, ListOffset, ListSize); +} + Expected> MinidumpFile::getDataSlice(ArrayRef Data, size_t Offset, size_t Size) { // Check for overflow. -- cgit v1.2.3