blob: 9ccb7edd696ca1106d46de529b874f492ff4b203 [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
20namespace {
Zachary Turner8dbe3622016-05-27 01:54:44 +000021
Zachary Turner1822af542016-04-27 23:41:42 +000022struct SCBytes {
23 ulittle16_t Section;
24 char Padding1[2];
25 little32_t Offset;
26 little32_t Size;
27 ulittle32_t Characteristics;
28 ulittle16_t ModuleIndex;
29 char Padding2[2];
30 ulittle32_t DataCrc;
31 ulittle32_t RelocCrc;
32};
33
34// struct Flags {
35// uint16_t fWritten : 1; // True if ModInfo is dirty
36// uint16_t fECEnabled : 1; // Is EC symbolic info present? (What is EC?)
37// uint16_t unused : 6; // Reserved
38// uint16_t iTSM : 8; // Type Server Index for this module
39//};
40const uint16_t HasECFlagMask = 0x2;
41
42const uint16_t TypeServerIndexMask = 0xFF00;
43const uint16_t TypeServerIndexShift = 8;
44}
45
46struct ModInfo::FileLayout {
47 ulittle32_t Mod; // Currently opened module. This field is a
48 // pointer in the reference implementation, but
49 // that won't work on 64-bit systems, and anyway
50 // it doesn't make sense to read a pointer from a
51 // file. For now it is unused, so just ignore it.
52 SCBytes SC; // First section contribution of this module.
53 ulittle16_t Flags; // See Flags definition.
54 ulittle16_t ModDiStream; // Stream Number of module debug info
55 ulittle32_t SymBytes; // Size of local symbol debug info in above stream
56 ulittle32_t LineBytes; // Size of line number debug info in above stream
57 ulittle32_t C13Bytes; // Size of C13 line number info in above stream
58 ulittle16_t NumFiles; // Number of files contributing to this module
59 char Padding1[2]; // Padding so the next field is 4-byte aligned.
60 ulittle32_t FileNameOffs; // array of [0..NumFiles) DBI name buffer offsets.
61 // This field is a pointer in the reference
62 // implementation, but as with `Mod`, we ignore it
63 // for now since it is unused.
64 ulittle32_t SrcFileNameNI; // Name Index for src file name
65 ulittle32_t PdbFilePathNI; // Name Index for path to compiler PDB
Zachary Turner8dbe3622016-05-27 01:54:44 +000066 // Null terminated Module name
67 // Null terminated Obj File Name
Zachary Turner1822af542016-04-27 23:41:42 +000068};
69
Zachary Turner8dbe3622016-05-27 01:54:44 +000070ModInfo::ModInfo(codeview::StreamRef Stream) : Layout(nullptr) {
71 codeview::StreamReader Reader(Stream);
72 if (auto EC = Reader.readObject(Layout)) {
73 consumeError(std::move(EC));
74 return;
75 }
76 if (auto EC = Reader.readZeroString(ModuleName)) {
77 consumeError(std::move(EC));
78 return;
79 }
80 if (auto EC = Reader.readZeroString(ObjFileName)) {
81 consumeError(std::move(EC));
82 return;
83 }
84}
85
86ModInfo::ModInfo(const ModInfo &Info)
87 : ModuleName(Info.ModuleName), ObjFileName(Info.ObjFileName),
88 Layout(Info.Layout) {}
Zachary Turner1822af542016-04-27 23:41:42 +000089
90ModInfo::~ModInfo() {}
91
92bool ModInfo::hasECInfo() const { return (Layout->Flags & HasECFlagMask) != 0; }
93
94uint16_t ModInfo::getTypeServerIndex() const {
95 return (Layout->Flags & TypeServerIndexMask) >> TypeServerIndexShift;
96}
97
98uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; }
99
100uint32_t ModInfo::getSymbolDebugInfoByteSize() const {
101 return Layout->SymBytes;
102}
103
104uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; }
105
106uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; }
107
108uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; }
109
110uint32_t ModInfo::getSourceFileNameIndex() const {
111 return Layout->SrcFileNameNI;
112}
113
114uint32_t ModInfo::getPdbFilePathNameIndex() const {
115 return Layout->PdbFilePathNI;
116}
117
Zachary Turner8dbe3622016-05-27 01:54:44 +0000118StringRef ModInfo::getModuleName() const { return ModuleName; }
Zachary Turner1822af542016-04-27 23:41:42 +0000119
Zachary Turner8dbe3622016-05-27 01:54:44 +0000120StringRef ModInfo::getObjFileName() const { return ObjFileName; }
Zachary Turner1822af542016-04-27 23:41:42 +0000121
Zachary Turner8dbe3622016-05-27 01:54:44 +0000122uint32_t ModInfo::getRecordLength() const {
123 uint32_t M = ModuleName.str().size() + 1;
124 uint32_t O = ObjFileName.str().size() + 1;
125 uint32_t Size = sizeof(FileLayout) + M + O;
126 Size = llvm::alignTo(Size, 4);
127 return Size;
Zachary Turner1822af542016-04-27 23:41:42 +0000128}