================ @@ -132,6 +140,92 @@ 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) { + return Memory64Iterator(Storage, Descriptors); + } + + static Memory64Iterator end() { return Memory64Iterator(); } + + 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) { + IsEnd = true; + return Error::success(); + } + + // Drop front gives us an array ref, so we need to call .front() as well. + const minidump::MemoryDescriptor_64 &Descriptor = Descriptors.front(); + if (Descriptor.DataSize > Storage.size()) { + IsEnd = true; + return make_error<GenericBinaryError>( + "Memory64 Descriptor exceeds end of file.", + object_error::unexpected_eof); + } + + ArrayRef<uint8_t> Content = Storage.take_front(Descriptor.DataSize); + Current = std::make_pair(Descriptor, Content); + + Storage = Storage.drop_front(Descriptor.DataSize); + Descriptors = Descriptors.drop_front(); + + if (Descriptors.empty()) + IsEnd = true; ---------------- labath wrote:
This doesn't look correct. Since you're holding the "current" object in a separate member, the emptyness of this does not indicate that you've reached the end (well, you sort of did, but the end iterator should point **past** the end of the array). I would expect that this should be caught the next time someone calls this function (attempts to increment the iterator). 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