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