diff options
author | Pavel Labath <pavel@labath.sk> | 2019-04-05 08:06:26 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-04-05 08:06:26 +0000 |
commit | 51d9fa0a22b1abff619613800fa14df80341d0d0 (patch) | |
tree | f590ef32d2d4e92252c17d7785934eb47587a3b6 /llvm/lib/Object/Minidump.cpp | |
parent | 98edcd9b9c28adf36b085c1a33e10328552ae1d4 (diff) | |
download | bcm5719-llvm-51d9fa0a22b1abff619613800fa14df80341d0d0.tar.gz bcm5719-llvm-51d9fa0a22b1abff619613800fa14df80341d0d0.zip |
Minidump: Add support for reading/writing strings
Summary:
Strings in minidump files are stored as a 32-bit length field, giving
the length of the string in *bytes*, which is followed by the
appropriate number of UTF16 code units. The string is also supposed to
be null-terminated, and the null-terminator is not a part of the length
field. This patch:
- adds support for reading these strings out of the minidump file (this
implementation does not depend on proper null-termination)
- adds support for writing them to a minidump file
- using the previous two pieces implements proper (de)serialization of
the CSDVersion field of the SystemInfo stream. Previously, this was
only read/written as hex, and no attempt was made to access the
referenced string -- now this string is read and written correctly.
The changes are tested via yaml2obj|obj2yaml round-trip as well as a
unit test which checks the corner cases of the string deserialization
logic.
Reviewers: jhenderson, zturner, clayborg
Subscribers: llvm-commits, aprantl, markmentovai, amccarth, lldb-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59775
llvm-svn: 357749
Diffstat (limited to 'llvm/lib/Object/Minidump.cpp')
-rw-r--r-- | llvm/lib/Object/Minidump.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Object/Minidump.cpp b/llvm/lib/Object/Minidump.cpp index d0d49b4e8d3..3e3255a2f17 100644 --- a/llvm/lib/Object/Minidump.cpp +++ b/llvm/lib/Object/Minidump.cpp @@ -8,6 +8,7 @@ #include "llvm/Object/Minidump.h" #include "llvm/Object/Error.h" +#include "llvm/Support/ConvertUTF.h" using namespace llvm; using namespace llvm::object; @@ -21,6 +22,33 @@ MinidumpFile::getRawStream(minidump::StreamType Type) const { return None; } +Expected<std::string> MinidumpFile::getString(size_t Offset) const { + // Minidump strings consist of a 32-bit length field, which gives the size of + // the string in *bytes*. This is followed by the actual string encoded in + // UTF16. + auto ExpectedSize = + getDataSliceAs<support::ulittle32_t>(getData(), Offset, 1); + if (!ExpectedSize) + return ExpectedSize.takeError(); + size_t Size = (*ExpectedSize)[0]; + if (Size % 2 != 0) + return createError("String size not even"); + Size /= 2; + if (Size == 0) + return ""; + + Offset += sizeof(support::ulittle32_t); + auto ExpectedData = getDataSliceAs<UTF16>(getData(), Offset, Size); + if (!ExpectedData) + return ExpectedData.takeError(); + + std::string Result; + if (!convertUTF16ToUTF8String(*ExpectedData, Result)) + return createError("String decoding failed"); + + return Result; +} + Expected<ArrayRef<uint8_t>> MinidumpFile::getDataSlice(ArrayRef<uint8_t> Data, size_t Offset, size_t Size) { // Check for overflow. |