blob: 89a03ec3a4d377b3bbdec2cb7b68c4023c51efba [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
Zachary Turnerbac69d32016-07-22 19:56:05 +000012#include "llvm/DebugInfo/Msf/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 Turnerbac69d32016-07-22 19:56:05 +000017using namespace llvm::msf;
Zachary Turner2f09b502016-04-29 17:28:47 +000018using namespace llvm::pdb;
Zachary Turner1822af542016-04-27 23:41:42 +000019using namespace llvm::support;
20
Zachary Turner1822af542016-04-27 23:41:42 +000021
Zachary Turner1de49c92016-05-27 18:47:20 +000022ModInfo::ModInfo() : Layout(nullptr) {}
23
Zachary Turner8dbe3622016-05-27 01:54:44 +000024ModInfo::ModInfo(const ModInfo &Info)
25 : ModuleName(Info.ModuleName), ObjFileName(Info.ObjFileName),
26 Layout(Info.Layout) {}
Zachary Turner1822af542016-04-27 23:41:42 +000027
28ModInfo::~ModInfo() {}
29
Zachary Turnerbac69d32016-07-22 19:56:05 +000030Error ModInfo::initialize(StreamRef Stream, ModInfo &Info) {
31 StreamReader Reader(Stream);
Zachary Turner0d43c1c2016-05-28 05:21:57 +000032 if (auto EC = Reader.readObject(Info.Layout))
33 return EC;
34
35 if (auto EC = Reader.readZeroString(Info.ModuleName))
36 return EC;
37
38 if (auto EC = Reader.readZeroString(Info.ObjFileName))
39 return EC;
40 return Error::success();
41}
42
Zachary Turnerb383d622016-07-22 15:46:46 +000043bool ModInfo::hasECInfo() const {
44 return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0;
45}
Zachary Turner1822af542016-04-27 23:41:42 +000046
47uint16_t ModInfo::getTypeServerIndex() const {
Zachary Turnerb383d622016-07-22 15:46:46 +000048 return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >>
49 ModInfoFlags::TypeServerIndexShift;
Zachary Turner1822af542016-04-27 23:41:42 +000050}
51
52uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; }
53
54uint32_t ModInfo::getSymbolDebugInfoByteSize() const {
55 return Layout->SymBytes;
56}
57
58uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; }
59
60uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; }
61
62uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; }
63
64uint32_t ModInfo::getSourceFileNameIndex() const {
65 return Layout->SrcFileNameNI;
66}
67
68uint32_t ModInfo::getPdbFilePathNameIndex() const {
69 return Layout->PdbFilePathNI;
70}
71
Zachary Turner8dbe3622016-05-27 01:54:44 +000072StringRef ModInfo::getModuleName() const { return ModuleName; }
Zachary Turner1822af542016-04-27 23:41:42 +000073
Zachary Turner8dbe3622016-05-27 01:54:44 +000074StringRef ModInfo::getObjFileName() const { return ObjFileName; }
Zachary Turner1822af542016-04-27 23:41:42 +000075
Zachary Turner8dbe3622016-05-27 01:54:44 +000076uint32_t ModInfo::getRecordLength() const {
77 uint32_t M = ModuleName.str().size() + 1;
78 uint32_t O = ObjFileName.str().size() + 1;
Zachary Turnerb383d622016-07-22 15:46:46 +000079 uint32_t Size = sizeof(ModuleInfoHeader) + M + O;
Zachary Turner8dbe3622016-05-27 01:54:44 +000080 Size = llvm::alignTo(Size, 4);
81 return Size;
Zachary Turner1822af542016-04-27 23:41:42 +000082}