aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/DebugInfo/CodeView/CVRecord.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/DebugInfo/CodeView/CVRecord.h')
-rw-r--r--include/llvm/DebugInfo/CodeView/CVRecord.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/llvm/DebugInfo/CodeView/CVRecord.h b/include/llvm/DebugInfo/CodeView/CVRecord.h
index 9f3a753ad1ae..9dbeb438f4ae 100644
--- a/include/llvm/DebugInfo/CodeView/CVRecord.h
+++ b/include/llvm/DebugInfo/CodeView/CVRecord.h
@@ -61,6 +61,30 @@ template <typename Kind> struct RemappedRecord {
SmallVector<std::pair<uint32_t, TypeIndex>, 8> Mappings;
};
+template <typename Record, typename Func>
+Error forEachCodeViewRecord(ArrayRef<uint8_t> StreamBuffer, Func F) {
+ while (!StreamBuffer.empty()) {
+ if (StreamBuffer.size() < sizeof(RecordPrefix))
+ return make_error<CodeViewError>(cv_error_code::corrupt_record);
+
+ const RecordPrefix *Prefix =
+ reinterpret_cast<const RecordPrefix *>(StreamBuffer.data());
+
+ size_t RealLen = Prefix->RecordLen + 2;
+ if (StreamBuffer.size() < RealLen)
+ return make_error<CodeViewError>(cv_error_code::corrupt_record);
+
+ ArrayRef<uint8_t> Data = StreamBuffer.take_front(RealLen);
+ StreamBuffer = StreamBuffer.drop_front(RealLen);
+
+ Record R(static_cast<decltype(Record::Type)>((uint16_t)Prefix->RecordKind),
+ Data);
+ if (auto EC = F(R))
+ return EC;
+ }
+ return Error::success();
+}
+
/// Read a complete record from a stream at a random offset.
template <typename Kind>
inline Expected<CVRecord<Kind>> readCVRecordFromStream(BinaryStreamRef Stream,