blob: 501188e96f6c848d1f6dfd44635a53f5a5f51215 [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
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000010#include "llvm/DebugInfo/PDB/Native/ModInfo.h"
Zachary Turnerd2684b72017-02-25 00:33:34 +000011#include "llvm/DebugInfo/MSF/BinaryStreamReader.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000012#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
Zachary Turner1822af542016-04-27 23:41:42 +000013#include "llvm/Support/Endian.h"
Eugene Zelenko570e39a2016-11-23 23:16:32 +000014#include "llvm/Support/Error.h"
15#include "llvm/Support/MathExtras.h"
16#include <cstdint>
Zachary Turner1822af542016-04-27 23:41:42 +000017
18using namespace llvm;
Zachary Turnerbac69d32016-07-22 19:56:05 +000019using namespace llvm::msf;
Zachary Turner2f09b502016-04-29 17:28:47 +000020using namespace llvm::pdb;
Zachary Turner1822af542016-04-27 23:41:42 +000021using namespace llvm::support;
22
Eugene Zelenko570e39a2016-11-23 23:16:32 +000023ModInfo::ModInfo() = default;
Zachary Turner1822af542016-04-27 23:41:42 +000024
Eugene Zelenko570e39a2016-11-23 23:16:32 +000025ModInfo::ModInfo(const ModInfo &Info) = default;
Zachary Turner1de49c92016-05-27 18:47:20 +000026
Eugene Zelenko570e39a2016-11-23 23:16:32 +000027ModInfo::~ModInfo() = default;
Zachary Turner1822af542016-04-27 23:41:42 +000028
Zachary Turnerd66889c2016-07-28 19:12:28 +000029Error ModInfo::initialize(ReadableStreamRef Stream, ModInfo &Info) {
Zachary Turnerbac69d32016-07-22 19:56:05 +000030 StreamReader Reader(Stream);
Zachary Turner0d43c1c2016-05-28 05:21:57 +000031 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;
Eugene Zelenko570e39a2016-11-23 23:16:32 +000079 Size = alignTo(Size, 4);
Zachary Turner8dbe3622016-05-27 01:54:44 +000080 return Size;
Zachary Turner1822af542016-04-27 23:41:42 +000081}