LLVM  4.0.0
CVRecord.h
Go to the documentation of this file.
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/Optional.h"
19 #include "llvm/Support/Endian.h"
20 #include "llvm/Support/Error.h"
21 #include <cstdint>
22 
23 namespace llvm {
24 
25 namespace codeview {
26 
27 template <typename Kind> class CVRecord {
28 public:
29  CVRecord() = default;
30  CVRecord(Kind K, ArrayRef<uint8_t> Data) : Type(K), RecordData(Data) {}
31 
32  uint32_t length() const { return RecordData.size(); }
33  Kind kind() const { return Type; }
34  ArrayRef<uint8_t> data() const { return RecordData; }
35 
37  return RecordData.drop_front(sizeof(RecordPrefix));
38  }
39 
40  Optional<uint32_t> hash() const { return Hash; }
41 
42  void setHash(uint32_t Value) { Hash = Value; }
43 
47 };
48 
49 } // end namespace codeview
50 
51 namespace msf {
52 
53 template <typename Kind>
54 struct VarStreamArrayExtractor<codeview::CVRecord<Kind>> {
56  codeview::CVRecord<Kind> &Item) const {
57  using namespace codeview;
58  const RecordPrefix *Prefix = nullptr;
59  StreamReader Reader(Stream);
60  uint32_t Offset = Reader.getOffset();
61 
62  if (auto EC = Reader.readObject(Prefix))
63  return EC;
64  if (Prefix->RecordLen < 2)
65  return make_error<CodeViewError>(cv_error_code::corrupt_record);
66  Kind K = static_cast<Kind>(uint16_t(Prefix->RecordKind));
67 
68  Reader.setOffset(Offset);
69  ArrayRef<uint8_t> RawData;
70  if (auto EC =
71  Reader.readBytes(RawData, Prefix->RecordLen + sizeof(uint16_t)))
72  return EC;
73  Item = codeview::CVRecord<Kind>(K, RawData);
74  Len = Item.length();
75  return Error::success();
76  }
77 };
78 
79 } // end namespace msf
80 
81 } // end namespace llvm
82 
83 #endif // LLVM_DEBUGINFO_CODEVIEW_RECORDITERATOR_H
ArrayRef< uint8_t > data() const
Definition: CVRecord.h:34
void setOffset(uint32_t Off)
Definition: StreamReader.h:105
Optional< uint32_t > hash() const
Definition: CVRecord.h:40
void setHash(uint32_t Value)
Definition: CVRecord.h:42
Kind kind() const
Definition: CVRecord.h:33
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Error operator()(ReadableStreamRef Stream, uint32_t &Len, codeview::CVRecord< Kind > &Item) const
Definition: CVRecord.h:55
Optional< uint32_t > Hash
Definition: CVRecord.h:46
uint32_t Offset
uint32_t getOffset() const
Definition: StreamReader.h:106
static ErrorSuccess success()
Create a success value.
ArrayRef< uint8_t > content() const
Definition: CVRecord.h:36
uint32_t length() const
Definition: CVRecord.h:32
CVRecord(Kind K, ArrayRef< uint8_t > Data)
Definition: CVRecord.h:30
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:45
VarStreamArrayExtractor is intended to be specialized to provide customized extraction logic...
Definition: StreamArray.h:35
const unsigned Kind
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:180
LLVM Value Representation.
Definition: Value.h:71
Lightweight error class with error context and mandatory checking.
Error readObject(const T *&Dest)
Definition: StreamReader.h:53