[Lldb-commits] [openmp] [clang-tools-extra] [llvm] [compiler-rt] [lldb] [libcxx] [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:14 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;
+ // loop until next match is found
+ while (InputBufferContents[i + j] != DeviceMemoryContents[i + j]) {
+ modified.push_back(DeviceMemoryContents[i + j]);
+ j++;
+ }
+ OS << j << " "; // marks the length of the mismatching sequence
+ for (const auto &value : modified)
+ OS << value << " ";
+ OS << "\n";
+ i += j + 1;
+ } else
+ i++;
+ }
+ } else {
+ StringRef DeviceMemory(DeviceMemoryMB.get()->getBufferStart(),
+ MemorySize);
+ OS << DeviceMemory;
+ }
----------------
ggeorgakoudis wrote:
Simplify control flow for readability:
```
for(size_t I = 0; I < MemorySize; ++I) {
If (InputBufferContest[I] == DeviceMemoryContest[I]
continue;
...
// do stuff, simplify too
...
I += J;
}
```
https://github.com/llvm/llvm-project/pull/70667
More information about the lldb-commits
mailing list