Line data Source code
1 : //===- ModInfo.cpp - PDB module information -------------------------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #include "llvm/DebugInfo/PDB/Native/ModInfo.h"
11 : #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
12 : #include "llvm/Support/BinaryStreamReader.h"
13 : #include "llvm/Support/Endian.h"
14 : #include "llvm/Support/Error.h"
15 : #include "llvm/Support/MathExtras.h"
16 : #include <cstdint>
17 :
18 : using namespace llvm;
19 : using namespace llvm::pdb;
20 : using namespace llvm::support;
21 :
22 : ModInfo::ModInfo() = default;
23 :
24 : ModInfo::ModInfo(const ModInfo &Info) = default;
25 :
26 : ModInfo::~ModInfo() = default;
27 :
28 121 : Error ModInfo::initialize(BinaryStreamRef Stream, ModInfo &Info) {
29 242 : BinaryStreamReader Reader(Stream);
30 363 : if (auto EC = Reader.readObject(Info.Layout))
31 0 : return EC;
32 :
33 363 : if (auto EC = Reader.readCString(Info.ModuleName))
34 0 : return EC;
35 :
36 363 : if (auto EC = Reader.readCString(Info.ObjFileName))
37 0 : return EC;
38 363 : return Error::success();
39 : }
40 :
41 53 : bool ModInfo::hasECInfo() const {
42 106 : return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
43 : }
44 :
45 53 : uint16_t ModInfo::getTypeServerIndex() const {
46 106 : return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
47 53 : ModInfoFlags::TypeServerIndexShift;
48 : }
49 :
50 256 : uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; }
51 :
52 64 : uint32_t ModInfo::getSymbolDebugInfoByteSize() const {
53 128 : return Layout->SymBytes;
54 : }
55 :
56 128 : uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; }
57 :
58 128 : uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; }
59 :
60 106 : uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; }
61 :
62 53 : uint32_t ModInfo::getSourceFileNameIndex() const {
63 106 : return Layout->SrcFileNameNI;
64 : }
65 :
66 53 : uint32_t ModInfo::getPdbFilePathNameIndex() const {
67 106 : return Layout->PdbFilePathNI;
68 : }
69 :
70 134 : StringRef ModInfo::getModuleName() const { return ModuleName; }
71 :
72 60 : StringRef ModInfo::getObjFileName() const { return ObjFileName; }
73 :
74 121 : uint32_t ModInfo::getRecordLength() const {
75 363 : uint32_t M = ModuleName.str().size() + 1;
76 363 : uint32_t O = ObjFileName.str().size() + 1;
77 121 : uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
78 242 : Size = alignTo(Size, 4);
79 121 : return Size;
80 : }
|