LLVM  6.0.0svn
DebugLinesSubsection.cpp
Go to the documentation of this file.
1 //===- DebugLinesSubsection.cpp -------------------------------------------===//
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 
11 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/Support/Error.h"
18 #include <cassert>
19 #include <cstdint>
20 
21 using namespace llvm;
22 using namespace llvm::codeview;
23 
25  LineColumnEntry &Item) {
26  const LineBlockFragmentHeader *BlockHeader;
27  BinaryStreamReader Reader(Stream);
28  if (auto EC = Reader.readObject(BlockHeader))
29  return EC;
30  bool HasColumn = Header->Flags & uint16_t(LF_HaveColumns);
31  uint32_t LineInfoSize =
32  BlockHeader->NumLines *
33  (sizeof(LineNumberEntry) + (HasColumn ? sizeof(ColumnNumberEntry) : 0));
34  if (BlockHeader->BlockSize < sizeof(LineBlockFragmentHeader))
35  return make_error<CodeViewError>(cv_error_code::corrupt_record,
36  "Invalid line block record size");
37  uint32_t Size = BlockHeader->BlockSize - sizeof(LineBlockFragmentHeader);
38  if (LineInfoSize > Size)
39  return make_error<CodeViewError>(cv_error_code::corrupt_record,
40  "Invalid line block record size");
41  // The value recorded in BlockHeader->BlockSize includes the size of
42  // LineBlockFragmentHeader.
43  Len = BlockHeader->BlockSize;
44  Item.NameIndex = BlockHeader->NameIndex;
45  if (auto EC = Reader.readArray(Item.LineNumbers, BlockHeader->NumLines))
46  return EC;
47  if (HasColumn) {
48  if (auto EC = Reader.readArray(Item.Columns, BlockHeader->NumLines))
49  return EC;
50  }
51  return Error::success();
52 }
53 
56 
58  if (auto EC = Reader.readObject(Header))
59  return EC;
60 
61  LinesAndColumns.getExtractor().Header = Header;
62  if (auto EC = Reader.readArray(LinesAndColumns, Reader.bytesRemaining()))
63  return EC;
64 
65  return Error::success();
66 }
67 
69  return !!(Header->Flags & LF_HaveColumns);
70 }
71 
74  : DebugSubsection(DebugSubsectionKind::Lines), Checksums(Checksums) {}
75 
77  uint32_t Offset = Checksums.mapChecksumOffset(FileName);
78 
79  Blocks.emplace_back(Offset);
80 }
81 
83  Block &B = Blocks.back();
84  LineNumberEntry LNE;
85  LNE.Flags = Line.getRawData();
86  LNE.Offset = Offset;
87  B.Lines.push_back(LNE);
88 }
89 
91  const LineInfo &Line,
92  uint32_t ColStart,
93  uint32_t ColEnd) {
94  Block &B = Blocks.back();
95  assert(B.Lines.size() == B.Columns.size());
96 
97  addLineInfo(Offset, Line);
99  CNE.StartColumn = ColStart;
100  CNE.EndColumn = ColEnd;
101  B.Columns.push_back(CNE);
102 }
103 
105  LineFragmentHeader Header;
106  Header.CodeSize = CodeSize;
107  Header.Flags = hasColumnInfo() ? LF_HaveColumns : 0;
108  Header.RelocOffset = RelocOffset;
109  Header.RelocSegment = RelocSegment;
110 
111  if (auto EC = Writer.writeObject(Header))
112  return EC;
113 
114  for (const auto &B : Blocks) {
115  LineBlockFragmentHeader BlockHeader;
116  assert(B.Lines.size() == B.Columns.size() || B.Columns.empty());
117 
118  BlockHeader.NumLines = B.Lines.size();
119  BlockHeader.BlockSize = sizeof(LineBlockFragmentHeader);
120  BlockHeader.BlockSize += BlockHeader.NumLines * sizeof(LineNumberEntry);
121  if (hasColumnInfo())
122  BlockHeader.BlockSize += BlockHeader.NumLines * sizeof(ColumnNumberEntry);
123  BlockHeader.NameIndex = B.ChecksumBufferOffset;
124  if (auto EC = Writer.writeObject(BlockHeader))
125  return EC;
126 
127  if (auto EC = Writer.writeArray(makeArrayRef(B.Lines)))
128  return EC;
129 
130  if (hasColumnInfo()) {
131  if (auto EC = Writer.writeArray(makeArrayRef(B.Columns)))
132  return EC;
133  }
134  }
135  return Error::success();
136 }
137 
139  uint32_t Size = sizeof(LineFragmentHeader);
140  for (const auto &B : Blocks) {
141  Size += sizeof(LineBlockFragmentHeader);
142  Size += B.Lines.size() * sizeof(LineNumberEntry);
143  if (hasColumnInfo())
144  Size += B.Columns.size() * sizeof(ColumnNumberEntry);
145  }
146  return Size;
147 }
148 
150  uint32_t Offset) {
151  RelocOffset = Offset;
152  RelocSegment = Segment;
153 }
154 
156 
157 void DebugLinesSubsection::setFlags(LineFlags Flags) { this->Flags = Flags; }
158 
160  return Flags & LF_HaveColumns;
161 }
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Error operator()(BinaryStreamRef Stream, uint32_t &Len, LineColumnEntry &Item)
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
void setRelocationAddress(uint16_t Segment, uint32_t Offset)
void addLineAndColumnInfo(uint32_t Offset, const LineInfo &Line, uint32_t ColStart, uint32_t ColEnd)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
FixedStreamArray< ColumnNumberEntry > Columns
DebugLinesSubsection(DebugChecksumsSubsection &Checksums, DebugStringTableSubsection &Strings)
Error commit(BinaryStreamWriter &Writer) const override
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
uint32_t calculateSerializedSize() const override
uint32_t getRawData() const
Definition: Line.h:50
uint32_t mapChecksumOffset(StringRef FileName) const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Provides write only access to a subclass of WritableBinaryStream.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
Represents a read-write view of a CodeView string table.
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
uint32_t bytesRemaining() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const Extractor & getExtractor() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Error initialize(BinaryStreamReader Reader)
FixedStreamArray< LineNumberEntry > LineNumbers
void addLineInfo(uint32_t Offset, const LineInfo &Line)
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...