[Lldb-commits] [clang-tools-extra] [libcxx] [llvm] [lldb] [compiler-rt] [openmp] [flang] [clang] [OpenMP] Add memory diff dump for kernel record-replay (PR #70667)

Giorgis Georgakoudis via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 31 13:53:12 PDT 2023


================
@@ -141,13 +141,56 @@ struct RecordReplayTy {
     if (Err)
       report_fatal_error("Error retrieving data for target pointer");
 
-    StringRef DeviceMemory(DeviceMemoryMB.get()->getBufferStart(), MemorySize);
     std::error_code EC;
     raw_fd_ostream OS(Filename, EC);
     if (EC)
       report_fatal_error("Error dumping memory to file " + Filename + " :" +
                          EC.message());
-    OS << DeviceMemory;
+
+    if (saveDiff) {
+      // Get the pre-record memory filename
+      SmallString<128> InputFilename = {Filename.split('.').first, ".memory"};
+      // read the pre-record memorydump
+      auto InputFileBuffer = MemoryBuffer::getFileOrSTDIN(InputFilename);
+      if (std::error_code EC = InputFileBuffer.getError())
+        report_fatal_error("Error reading pre-record device memory");
+
+      StringRef InputBufferContents = (*InputFileBuffer)->getBuffer();
+      if (InputBufferContents.size() != MemorySize)
+        report_fatal_error("Error: Pre-record device memory size mismatch");
+
+      // get current memory contents
+      StringRef DeviceMemoryContents(DeviceMemoryMB.get()->getBuffer().data(),
+                                     DeviceMemoryMB.get()->getBuffer().size());
+
+      // compare pre-record memorydump to current contents
+      size_t i = 0;
+      while (i < MemorySize) {
+        // if mismatch found, create a new diff line
+        // current format - location, size, differences ...
+        if (InputBufferContents[i] != DeviceMemoryContents[i]) {
+          OS << i << " "; // marks the start offset
+          SmallVector<uint8_t, 128> modified;
+          modified.push_back(DeviceMemoryContents[i]);
+          size_t j = 1;
----------------
ggeorgakoudis wrote:

rename j -> J

https://github.com/llvm/llvm-project/pull/70667


More information about the lldb-commits mailing list