================
@@ -0,0 +1,101 @@
+"""
+Regression test for the Memory64List size accounting in minidump save-core.
+
+When a saved range contains an unreadable page the read fails part-way. The
+range's DataSize must equal the number of bytes actually written to the shared
+Memory64 blob; if it instead records the number of bytes ReadMemoryInChunks
read
+(which includes the partially-read bytes that were dropped on the error), the
+blob's cumulative offsets desync and the descriptors claim more data than the
+file holds. See MinidumpFileBuilder::ReadWriteMemoryInChunks.
+"""
+
+import os
+import struct
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+MEMORY64_LIST_STREAM = 9 # llvm::minidump::StreamType::Memory64List
+
+
+class ProcessSaveCoreMinidumpSizeMismatchTestCase(TestBase):
+ def assert_memory64_datasize_within_file(self, core_path):
+ """Assert the minidump has a Memory64List whose ranges' cumulative
+ DataSize does not claim more bytes than the file actually holds."""
+ with open(core_path, "rb") as core_file:
+ core_bytes = core_file.read()
+ self.assertEqual(core_bytes[:4], b"MDMP")
+ num_streams, directory_rva = struct.unpack_from("<II", core_bytes, 8)
+
+ memory64_list_found = False
+ for stream_index in range(num_streams):
+ stream_type, _, stream_rva = struct.unpack_from(
+ "<III", core_bytes, directory_rva + stream_index * 12
+ )
+ if stream_type != MEMORY64_LIST_STREAM:
+ continue
+ memory64_list_found = True
+ num_ranges, base_rva = struct.unpack_from("<QQ", core_bytes,
stream_rva)
+ total_data_size = sum(
+ struct.unpack_from("<QQ", core_bytes, stream_rva + 16 + i *
16)[1]
+ for i in range(num_ranges)
+ )
+ self.assertLessEqual(
+ base_rva + total_data_size,
+ len(core_bytes),
+ "Memory64List DataSize claims more bytes than the minidump
holds",
+ )
+ self.assertTrue(memory64_list_found, "minidump has no Memory64List
stream")
+
+ @skipUnlessArch("x86_64")
----------------
Jlalond wrote:
This should work on aarch64, and I'd prefer we cover all the Linux flavors. If
it fails we can quickly follow-up with an arch exclusion.
https://github.com/llvm/llvm-project/pull/212861
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits