summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-04-05 08:06:26 +0000
committerPavel Labath <pavel@labath.sk>2019-04-05 08:06:26 +0000
commit51d9fa0a22b1abff619613800fa14df80341d0d0 (patch)
treef590ef32d2d4e92252c17d7785934eb47587a3b6 /llvm/unittests
parent98edcd9b9c28adf36b085c1a33e10328552ae1d4 (diff)
downloadbcm5719-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/unittests')
-rw-r--r--llvm/unittests/Object/MinidumpTest.cpp35
-rw-r--r--llvm/unittests/ObjectYAML/MinidumpYAMLTest.cpp2
2 files changed, 35 insertions, 2 deletions
diff --git a/llvm/unittests/Object/MinidumpTest.cpp b/llvm/unittests/Object/MinidumpTest.cpp
index 97fde12c0f8..06034e1e5ad 100644
--- a/llvm/unittests/Object/MinidumpTest.cpp
+++ b/llvm/unittests/Object/MinidumpTest.cpp
@@ -249,3 +249,38 @@ TEST(MinidumpFile, getSystemInfo) {
EXPECT_EQ(0x08070605u, Info.CPU.X86.FeatureInfo);
EXPECT_EQ(0x02010009u, Info.CPU.X86.AMDExtendedFeatures);
}
+
+TEST(MinidumpFile, getString) {
+ std::vector<uint8_t> ManyStrings{
+ // Header
+ 'M', 'D', 'M', 'P', 0x93, 0xa7, 0, 0, // Signature, Version
+ 2, 0, 0, 0, // NumberOfStreams,
+ 0x20, 0, 0, 0, // StreamDirectoryRVA
+ 0, 1, 2, 3, 4, 5, 6, 7, // Checksum, TimeDateStamp
+ 8, 9, 0, 1, 2, 3, 4, 5, // Flags
+ // Stream Directory
+ 0, 0, 0, 0, 0, 0, 0, 0, // Type, DataSize,
+ 0x20, 0, 0, 0, // RVA
+ 1, 0, 0, 0, 0, 0, // String1 - odd length
+ 0, 0, 1, 0, 0, 0, // String2 - too long
+ 2, 0, 0, 0, 0, 0xd8, // String3 - invalid utf16
+ 0, 0, 0, 0, 0, 0, // String4 - ""
+ 2, 0, 0, 0, 'a', 0, // String5 - "a"
+ 0, // Mis-align next string
+ 2, 0, 0, 0, 'a', 0, // String6 - "a"
+
+ };
+ auto ExpectedFile = create(ManyStrings);
+ ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
+ const MinidumpFile &File = **ExpectedFile;
+ EXPECT_THAT_EXPECTED(File.getString(44), Failed<BinaryError>());
+ EXPECT_THAT_EXPECTED(File.getString(50), Failed<BinaryError>());
+ EXPECT_THAT_EXPECTED(File.getString(56), Failed<BinaryError>());
+ EXPECT_THAT_EXPECTED(File.getString(62), HasValue(""));
+ EXPECT_THAT_EXPECTED(File.getString(68), HasValue("a"));
+ EXPECT_THAT_EXPECTED(File.getString(75), HasValue("a"));
+
+ // Check the case when the size field does not fit into the remaining data.
+ EXPECT_THAT_EXPECTED(File.getString(ManyStrings.size() - 2),
+ Failed<BinaryError>());
+}
diff --git a/llvm/unittests/ObjectYAML/MinidumpYAMLTest.cpp b/llvm/unittests/ObjectYAML/MinidumpYAMLTest.cpp
index d172ccf9301..66d44e06759 100644
--- a/llvm/unittests/ObjectYAML/MinidumpYAMLTest.cpp
+++ b/llvm/unittests/ObjectYAML/MinidumpYAMLTest.cpp
@@ -33,7 +33,6 @@ Streams:
- Type: SystemInfo
Processor Arch: ARM64
Platform ID: Linux
- CSD Version RVA: 0x01020304
CPU:
CPUID: 0x05060708
- Type: LinuxMaps
@@ -54,7 +53,6 @@ Streams:
const SystemInfo &SysInfo = *ExpectedSysInfo;
EXPECT_EQ(ProcessorArchitecture::ARM64, SysInfo.ProcessorArch);
EXPECT_EQ(OSPlatform::Linux, SysInfo.PlatformId);
- EXPECT_EQ(0x01020304u, SysInfo.CSDVersionRVA);
EXPECT_EQ(0x05060708u, SysInfo.CPU.Arm.CPUID);
EXPECT_EQ(StreamType::LinuxMaps, File.streams()[1].Type);
OpenPOWER on IntegriCloud