================ @@ -132,6 +140,95 @@ class MinidumpFile : public Binary { size_t Stride; }; + /// Class the provides an iterator over the memory64 memory ranges. Only the + /// the first descriptor is validated as readable beforehand. + class Memory64Iterator { + public: + static Memory64Iterator + begin(ArrayRef<uint8_t> Storage, + ArrayRef<minidump::MemoryDescriptor_64> Descriptors, + uint64_t BaseRVA) { + return Memory64Iterator(Storage, Descriptors, BaseRVA); + } + + static Memory64Iterator end() { return Memory64Iterator(); } + + std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> Current; + + bool operator==(const Memory64Iterator &R) const { + return IsEnd == R.IsEnd; + } + + bool operator!=(const Memory64Iterator &R) const { return !(*this == R); } + + const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> & + operator*() { + return Current; + } + + const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> * + operator&() { + return &Current; + } + + Error inc() { + if (Storage.size() == 0 || Descriptors.size() == 0) + return make_error<GenericBinaryError>("No Memory64List Stream", + object_error::parse_failed); + + if (Index >= Descriptors.size()) + return createError("Can't read past of Memory64List Stream"); + + const minidump::MemoryDescriptor_64 &Descriptor = Descriptors[Index]; + if (RVA + Descriptor.DataSize > Storage.size()) + return make_error<GenericBinaryError>( + "Memory64 Descriptor exceeds end of file.", + object_error::unexpected_eof); + + ArrayRef<uint8_t> Content = Storage.slice(RVA, Descriptor.DataSize); + Current = std::make_pair(Descriptor, Content); + Index++; + RVA += Descriptor.DataSize; + if (Index >= Descriptors.size()) + IsEnd = true; + return Error::success(); + } + + private: + // This constructor will only happen after a validation check to see + // if the first descriptor is readable. + Memory64Iterator(ArrayRef<uint8_t> Storage, + ArrayRef<minidump::MemoryDescriptor_64> Descriptors, + uint64_t BaseRVA) + : RVA(BaseRVA), Storage(Storage), Descriptors(Descriptors), + IsEnd(false) { + assert(Descriptors.size() > 0); + assert(Storage.size() >= BaseRVA + Descriptors.front().DataSize); ---------------- labath wrote:
Okay, that's fine. https://github.com/llvm/llvm-project/pull/101272 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits