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