blob: 9d0a0ae6e36f80645df4999712f75ad39a1fe767 [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 Turnerb383d622016-07-22 15:46:46 +000042bool ModInfo::hasECInfo() const {
43 return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
44}
Zachary Turner1822af542016-04-27 23:41:42 +000045
46uint16_t ModInfo::getTypeServerIndex() const {
Zachary Turnerb383d622016-07-22 15:46:46 +000047 return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
48 ModInfoFlags::TypeServerIndexShift;
Zachary Turner1822af542016-04-27 23:41:42 +000049}
50
51uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; }
52
53uint32_t ModInfo::getSymbolDebugInfoByteSize() const {
54 return Layout->SymBytes;
55}
56
57uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; }
58
59uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; }
60
61uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; }
62
63uint32_t ModInfo::getSourceFileNameIndex() const {
64 return Layout->SrcFileNameNI;
65}
66
67uint32_t ModInfo::getPdbFilePathNameIndex() const {
68 return Layout->PdbFilePathNI;
69}
70
Zachary Turner8dbe3622016-05-27 01:54:44 +000071StringRef ModInfo::getModuleName() const { return ModuleName; }
Zachary Turner1822af542016-04-27 23:41:42 +000072
Zachary Turner8dbe3622016-05-27 01:54:44 +000073StringRef ModInfo::getObjFileName() const { return ObjFileName; }
Zachary Turner1822af542016-04-27 23:41:42 +000074
Zachary Turner8dbe3622016-05-27 01:54:44 +000075uint32_t ModInfo::getRecordLength() const {
76 uint32_t M = ModuleName.str().size() + 1;
77 uint32_t O = ObjFileName.str().size() + 1;
Zachary Turnerb383d622016-07-22 15:46:46 +000078 uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
Zachary Turner8dbe3622016-05-27 01:54:44 +000079 Size = llvm::alignTo(Size, 4);
80 return Size;
Zachary Turner1822af542016-04-27 23:41:42 +000081}