1 //===- RecordIterator.h -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_DEBUGINFO_CODEVIEW_RECORDITERATOR_H 11 #define LLVM_DEBUGINFO_CODEVIEW_RECORDITERATOR_H 12 13 #include "llvm/ADT/ArrayRef.h" 14 #include "llvm/ADT/iterator_range.h" 15 #include "llvm/DebugInfo/CodeView/RecordSerialization.h" 16 #include "llvm/DebugInfo/CodeView/StreamInterface.h" 17 #include "llvm/DebugInfo/CodeView/StreamReader.h" 18 #include "llvm/Support/Endian.h" 19 20 namespace llvm { 21 namespace codeview { 22 23 template <typename Kind> struct CVRecord { 24 uint32_t Length; 25 Kind Type; 26 ArrayRef<uint8_t> Data; 27 ArrayRef<uint8_t> RawData; 28 }; 29 30 template <typename Kind> struct VarStreamArrayExtractor<CVRecord<Kind>> { 31 Error operator()(StreamRef Stream, uint32_t &Len, 32 CVRecord<Kind> &Item) const { 33 const RecordPrefix *Prefix = nullptr; 34 StreamReader Reader(Stream); 35 uint32_t Offset = Reader.getOffset(); 36 37 if (auto EC = Reader.readObject(Prefix)) 38 return EC; 39 Item.Length = Prefix->RecordLen; 40 if (Item.Length < 2) 41 return make_error<CodeViewError>(cv_error_code::corrupt_record); 42 Item.Type = static_cast<Kind>(uint16_t(Prefix->RecordKind)); 43 44 Reader.setOffset(Offset); 45 if (auto EC = 46 Reader.readBytes(Item.RawData, Item.Length + sizeof(uint16_t))) 47 return EC; 48 Item.Data = Item.RawData.slice(sizeof(RecordPrefix)); 49 Len = Prefix->RecordLen + 2; 50 return Error::success(); 51 } 52 }; 53 } 54 } 55 56 #endif 57