Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/CodeView/SymbolSerializer.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- SymbolSerializer.cpp -----------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
10
#include "llvm/ADT/ArrayRef.h"
11
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
12
#include "llvm/Support/Endian.h"
13
#include "llvm/Support/Error.h"
14
#include <cassert>
15
#include <cstdint>
16
#include <cstring>
17
18
using namespace llvm;
19
using namespace llvm::codeview;
20
21
SymbolSerializer::SymbolSerializer(BumpPtrAllocator &Allocator,
22
                                   CodeViewContainer Container)
23
    : Storage(Allocator), Stream(RecordBuffer, support::little), Writer(Stream),
24
1.69k
      Mapping(Writer, Container) {}
25
26
1.69k
Error SymbolSerializer::visitSymbolBegin(CVSymbol &Record) {
27
1.69k
  assert(!CurrentSymbol.hasValue() && "Already in a symbol mapping!");
28
1.69k
29
1.69k
  Writer.setOffset(0);
30
1.69k
31
1.69k
  if (auto EC = writeRecordPrefix(Record.kind()))
32
0
    return EC;
33
1.69k
34
1.69k
  CurrentSymbol = Record.kind();
35
1.69k
  if (auto EC = Mapping.visitSymbolBegin(Record))
36
0
    return EC;
37
1.69k
38
1.69k
  return Error::success();
39
1.69k
}
40
41
1.69k
Error SymbolSerializer::visitSymbolEnd(CVSymbol &Record) {
42
1.69k
  assert(CurrentSymbol.hasValue() && "Not in a symbol mapping!");
43
1.69k
44
1.69k
  if (auto EC = Mapping.visitSymbolEnd(Record))
45
0
    return EC;
46
1.69k
47
1.69k
  uint32_t RecordEnd = Writer.getOffset();
48
1.69k
  uint16_t Length = RecordEnd - 2;
49
1.69k
  Writer.setOffset(0);
50
1.69k
  if (auto EC = Writer.writeInteger(Length))
51
0
    return EC;
52
1.69k
53
1.69k
  uint8_t *StableStorage = Storage.Allocate<uint8_t>(RecordEnd);
54
1.69k
  ::memcpy(StableStorage, &RecordBuffer[0], RecordEnd);
55
1.69k
  Record.RecordData = ArrayRef<uint8_t>(StableStorage, RecordEnd);
56
1.69k
  CurrentSymbol.reset();
57
1.69k
58
1.69k
  return Error::success();
59
1.69k
}