DbiModuleDescriptor.cpp revision 353358
1//===- DbiModuleDescriptor.cpp - PDB module information -------------------===//
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/PDB/Native/DbiModuleDescriptor.h"
10#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
11#include "llvm/Support/BinaryStreamReader.h"
12#include "llvm/Support/Endian.h"
13#include "llvm/Support/Error.h"
14#include "llvm/Support/MathExtras.h"
15#include <cstdint>
16
17using namespace llvm;
18using namespace llvm::pdb;
19using namespace llvm::support;
20
21DbiModuleDescriptor::DbiModuleDescriptor() = default;
22
23DbiModuleDescriptor::DbiModuleDescriptor(const DbiModuleDescriptor &Info) =
24    default;
25
26DbiModuleDescriptor::~DbiModuleDescriptor() = default;
27
28Error DbiModuleDescriptor::initialize(BinaryStreamRef Stream,
29                                      DbiModuleDescriptor &Info) {
30  BinaryStreamReader Reader(Stream);
31  if (auto EC = Reader.readObject(Info.Layout))
32    return EC;
33
34  if (auto EC = Reader.readCString(Info.ModuleName))
35    return EC;
36
37  if (auto EC = Reader.readCString(Info.ObjFileName))
38    return EC;
39  return Error::success();
40}
41
42bool DbiModuleDescriptor::hasECInfo() const {
43  return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
44}
45
46uint16_t DbiModuleDescriptor::getTypeServerIndex() const {
47  return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
48         ModInfoFlags::TypeServerIndexShift;
49}
50
51const SectionContrib &DbiModuleDescriptor::getSectionContrib() const {
52  return Layout->SC;
53}
54
55uint16_t DbiModuleDescriptor::getModuleStreamIndex() const {
56  return Layout->ModDiStream;
57}
58
59uint32_t DbiModuleDescriptor::getSymbolDebugInfoByteSize() const {
60  return Layout->SymBytes;
61}
62
63uint32_t DbiModuleDescriptor::getC11LineInfoByteSize() const {
64  return Layout->C11Bytes;
65}
66
67uint32_t DbiModuleDescriptor::getC13LineInfoByteSize() const {
68  return Layout->C13Bytes;
69}
70
71uint32_t DbiModuleDescriptor::getNumberOfFiles() const {
72  return Layout->NumFiles;
73}
74
75uint32_t DbiModuleDescriptor::getSourceFileNameIndex() const {
76  return Layout->SrcFileNameNI;
77}
78
79uint32_t DbiModuleDescriptor::getPdbFilePathNameIndex() const {
80  return Layout->PdbFilePathNI;
81}
82
83StringRef DbiModuleDescriptor::getModuleName() const { return ModuleName; }
84
85StringRef DbiModuleDescriptor::getObjFileName() const { return ObjFileName; }
86
87uint32_t DbiModuleDescriptor::getRecordLength() const {
88  uint32_t M = ModuleName.str().size() + 1;
89  uint32_t O = ObjFileName.str().size() + 1;
90  uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
91  Size = alignTo(Size, 4);
92  return Size;
93}
94