]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptor.cpp
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / DebugInfo / PDB / Native / DbiModuleDescriptor.cpp
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
17 using namespace llvm;
18 using namespace llvm::pdb;
19 using namespace llvm::support;
20
21 DbiModuleDescriptor::DbiModuleDescriptor() = default;
22
23 DbiModuleDescriptor::DbiModuleDescriptor(const DbiModuleDescriptor &Info) =
24     default;
25
26 DbiModuleDescriptor::~DbiModuleDescriptor() = default;
27
28 Error 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
42 bool DbiModuleDescriptor::hasECInfo() const {
43   return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
44 }
45
46 uint16_t DbiModuleDescriptor::getTypeServerIndex() const {
47   return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
48          ModInfoFlags::TypeServerIndexShift;
49 }
50
51 const SectionContrib &DbiModuleDescriptor::getSectionContrib() const {
52   return Layout->SC;
53 }
54
55 uint16_t DbiModuleDescriptor::getModuleStreamIndex() const {
56   return Layout->ModDiStream;
57 }
58
59 uint32_t DbiModuleDescriptor::getSymbolDebugInfoByteSize() const {
60   return Layout->SymBytes;
61 }
62
63 uint32_t DbiModuleDescriptor::getC11LineInfoByteSize() const {
64   return Layout->C11Bytes;
65 }
66
67 uint32_t DbiModuleDescriptor::getC13LineInfoByteSize() const {
68   return Layout->C13Bytes;
69 }
70
71 uint32_t DbiModuleDescriptor::getNumberOfFiles() const {
72   return Layout->NumFiles;
73 }
74
75 uint32_t DbiModuleDescriptor::getSourceFileNameIndex() const {
76   return Layout->SrcFileNameNI;
77 }
78
79 uint32_t DbiModuleDescriptor::getPdbFilePathNameIndex() const {
80   return Layout->PdbFilePathNI;
81 }
82
83 StringRef DbiModuleDescriptor::getModuleName() const { return ModuleName; }
84
85 StringRef DbiModuleDescriptor::getObjFileName() const { return ObjFileName; }
86
87 uint32_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 }