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 Error DbiModuleDescriptor::initialize(BinaryStreamRef Stream,
27                                       DbiModuleDescriptor &Info) {
28   BinaryStreamReader Reader(Stream);
29   if (auto EC = Reader.readObject(Info.Layout))
30     return EC;
31 
32   if (auto EC = Reader.readCString(Info.ModuleName))
33     return EC;
34 
35   if (auto EC = Reader.readCString(Info.ObjFileName))
36     return EC;
37   return Error::success();
38 }
39 
40 bool DbiModuleDescriptor::hasECInfo() const {
41   return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
42 }
43 
44 uint16_t DbiModuleDescriptor::getTypeServerIndex() const {
45   return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
46          ModInfoFlags::TypeServerIndexShift;
47 }
48 
49 const SectionContrib &DbiModuleDescriptor::getSectionContrib() const {
50   return Layout->SC;
51 }
52 
53 uint16_t DbiModuleDescriptor::getModuleStreamIndex() const {
54   return Layout->ModDiStream;
55 }
56 
57 uint32_t DbiModuleDescriptor::getSymbolDebugInfoByteSize() const {
58   return Layout->SymBytes;
59 }
60 
61 uint32_t DbiModuleDescriptor::getC11LineInfoByteSize() const {
62   return Layout->C11Bytes;
63 }
64 
65 uint32_t DbiModuleDescriptor::getC13LineInfoByteSize() const {
66   return Layout->C13Bytes;
67 }
68 
69 uint32_t DbiModuleDescriptor::getNumberOfFiles() const {
70   return Layout->NumFiles;
71 }
72 
73 uint32_t DbiModuleDescriptor::getSourceFileNameIndex() const {
74   return Layout->SrcFileNameNI;
75 }
76 
77 uint32_t DbiModuleDescriptor::getPdbFilePathNameIndex() const {
78   return Layout->PdbFilePathNI;
79 }
80 
81 StringRef DbiModuleDescriptor::getModuleName() const { return ModuleName; }
82 
83 StringRef DbiModuleDescriptor::getObjFileName() const { return ObjFileName; }
84 
85 uint32_t DbiModuleDescriptor::getRecordLength() const {
86   uint32_t M = ModuleName.str().size() + 1;
87   uint32_t O = ObjFileName.str().size() + 1;
88   uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
89   Size = alignTo(Size, 4);
90   return Size;
91 }
92