blob: 538fe2255997442e6a6e5fca49bc935662d08b61 [file] [log] [blame]
Zachary Turner1822af542016-04-27 23:41:42 +00001//===- 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/Raw/ModInfo.h"
Zachary Turner8dbe3622016-05-27 01:54:44 +000011
12#include "llvm/DebugInfo/CodeView/StreamReader.h"
Zachary Turner1822af542016-04-27 23:41:42 +000013#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
14#include "llvm/Support/Endian.h"
15
16using namespace llvm;
Zachary Turner2f09b502016-04-29 17:28:47 +000017using namespace llvm::pdb;
Zachary Turner1822af542016-04-27 23:41:42 +000018using namespace llvm::support;
19
Zachary Turner1822af542016-04-27 23:41:42 +000020
Zachary Turner1de49c92016-05-27 18:47:20 +000021ModInfo::ModInfo() : Layout(nullptr) {}
22
Zachary Turner8dbe3622016-05-27 01:54:44 +000023ModInfo::ModInfo(const ModInfo &Info)
24 : ModuleName(Info.ModuleName), ObjFileName(Info.ObjFileName),
25 Layout(Info.Layout) {}
Zachary Turner1822af542016-04-27 23:41:42 +000026
27ModInfo::~ModInfo() {}
28
Zachary Turner0d43c1c2016-05-28 05:21:57 +000029Error ModInfo::initialize(codeview::StreamRef Stream, ModInfo &Info) {
30 codeview::StreamReader Reader(Stream);
31 if (auto EC = Reader.readObject(Info.Layout))
32 return EC;
33
34 if (auto EC = Reader.readZeroString(Info.ModuleName))
35 return EC;
36
37 if (auto EC = Reader.readZeroString(Info.ObjFileName))
38 return EC;
39 return Error::success();
40}
41
Zachary Turner1822af542016-04-27 23:41:42 +000042bool ModInfo::hasECInfo() const { return (Layout->Flags & HasECFlagMask) != 0; }
43
44uint16_t ModInfo::getTypeServerIndex() const {
45 return (Layout->Flags & TypeServerIndexMask) >> TypeServerIndexShift;
46}
47
48uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; }
49
50uint32_t ModInfo::getSymbolDebugInfoByteSize() const {
51 return Layout->SymBytes;
52}
53
54uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; }
55
56uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; }
57
58uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; }
59
60uint32_t ModInfo::getSourceFileNameIndex() const {
61 return Layout->SrcFileNameNI;
62}
63
64uint32_t ModInfo::getPdbFilePathNameIndex() const {
65 return Layout->PdbFilePathNI;
66}
67
Zachary Turner8dbe3622016-05-27 01:54:44 +000068StringRef ModInfo::getModuleName() const { return ModuleName; }
Zachary Turner1822af542016-04-27 23:41:42 +000069
Zachary Turner8dbe3622016-05-27 01:54:44 +000070StringRef ModInfo::getObjFileName() const { return ObjFileName; }
Zachary Turner1822af542016-04-27 23:41:42 +000071
Zachary Turner8dbe3622016-05-27 01:54:44 +000072uint32_t ModInfo::getRecordLength() const {
73 uint32_t M = ModuleName.str().size() + 1;
74 uint32_t O = ObjFileName.str().size() + 1;
75 uint32_t Size = sizeof(FileLayout) + M + O;
76 Size = llvm::alignTo(Size, 4);
77 return Size;
Zachary Turner1822af542016-04-27 23:41:42 +000078}