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
16using namespace llvm;
17using namespace llvm::pdb;
18using namespace llvm::support;
19
20Error DbiModuleDescriptor::initialize(BinaryStreamRef Stream,
21 DbiModuleDescriptor &Info) {
22 BinaryStreamReader Reader(Stream);
23 if (auto EC = Reader.readObject(Dest&: Info.Layout))
24 return EC;
25
26 if (auto EC = Reader.readCString(Dest&: Info.ModuleName))
27 return EC;
28
29 if (auto EC = Reader.readCString(Dest&: Info.ObjFileName))
30 return EC;
31 return Error::success();
32}
33
34bool DbiModuleDescriptor::hasECInfo() const {
35 return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
36}
37
38uint16_t DbiModuleDescriptor::getTypeServerIndex() const {
39 return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
40 ModInfoFlags::TypeServerIndexShift;
41}
42
43const SectionContrib &DbiModuleDescriptor::getSectionContrib() const {
44 return Layout->SC;
45}
46
47uint16_t DbiModuleDescriptor::getModuleStreamIndex() const {
48 return Layout->ModDiStream;
49}
50
51uint32_t DbiModuleDescriptor::getSymbolDebugInfoByteSize() const {
52 return Layout->SymBytes;
53}
54
55uint32_t DbiModuleDescriptor::getC11LineInfoByteSize() const {
56 return Layout->C11Bytes;
57}
58
59uint32_t DbiModuleDescriptor::getC13LineInfoByteSize() const {
60 return Layout->C13Bytes;
61}
62
63uint32_t DbiModuleDescriptor::getNumberOfFiles() const {
64 return Layout->NumFiles;
65}
66
67uint32_t DbiModuleDescriptor::getSourceFileNameIndex() const {
68 return Layout->SrcFileNameNI;
69}
70
71uint32_t DbiModuleDescriptor::getPdbFilePathNameIndex() const {
72 return Layout->PdbFilePathNI;
73}
74
75StringRef DbiModuleDescriptor::getModuleName() const { return ModuleName; }
76
77StringRef DbiModuleDescriptor::getObjFileName() const { return ObjFileName; }
78
79uint32_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(Value: Size, Align: 4);
84 return Size;
85}
86