blob: 362c402c09b7df86d3f5b79337e908f16be38e9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
//===- ModInfo.cpp - PDB module information -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/Support/Endian.h"
using namespace llvm;
using namespace llvm::pdb;
using namespace llvm::support;
namespace {
struct SCBytes {
ulittle16_t Section;
char Padding1[2];
little32_t Offset;
little32_t Size;
ulittle32_t Characteristics;
ulittle16_t ModuleIndex;
char Padding2[2];
ulittle32_t DataCrc;
ulittle32_t RelocCrc;
};
// struct Flags {
// uint16_t fWritten : 1; // True if ModInfo is dirty
// uint16_t fECEnabled : 1; // Is EC symbolic info present? (What is EC?)
// uint16_t unused : 6; // Reserved
// uint16_t iTSM : 8; // Type Server Index for this module
//};
const uint16_t HasECFlagMask = 0x2;
const uint16_t TypeServerIndexMask = 0xFF00;
const uint16_t TypeServerIndexShift = 8;
}
struct ModInfo::FileLayout {
ulittle32_t Mod; // Currently opened module. This field is a
// pointer in the reference implementation, but
// that won't work on 64-bit systems, and anyway
// it doesn't make sense to read a pointer from a
// file. For now it is unused, so just ignore it.
SCBytes SC; // First section contribution of this module.
ulittle16_t Flags; // See Flags definition.
ulittle16_t ModDiStream; // Stream Number of module debug info
ulittle32_t SymBytes; // Size of local symbol debug info in above stream
ulittle32_t LineBytes; // Size of line number debug info in above stream
ulittle32_t C13Bytes; // Size of C13 line number info in above stream
ulittle16_t NumFiles; // Number of files contributing to this module
char Padding1[2]; // Padding so the next field is 4-byte aligned.
ulittle32_t FileNameOffs; // array of [0..NumFiles) DBI name buffer offsets.
// This field is a pointer in the reference
// implementation, but as with `Mod`, we ignore it
// for now since it is unused.
ulittle32_t SrcFileNameNI; // Name Index for src file name
ulittle32_t PdbFilePathNI; // Name Index for path to compiler PDB
char VarInfo[1]; // Module name followed by Obj File Name
StringRef getModuleName() const { return StringRef(VarInfo); }
StringRef getObjectFileName() const {
return StringRef(getModuleName().end() + 1);
}
};
ModInfo::ModInfo(const uint8_t *Bytes)
: Layout(reinterpret_cast<const FileLayout *>(Bytes)) {}
ModInfo::~ModInfo() {}
bool ModInfo::hasECInfo() const { return (Layout->Flags & HasECFlagMask) != 0; }
uint16_t ModInfo::getTypeServerIndex() const {
return (Layout->Flags & TypeServerIndexMask) >> TypeServerIndexShift;
}
uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; }
uint32_t ModInfo::getSymbolDebugInfoByteSize() const {
return Layout->SymBytes;
}
uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; }
uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; }
uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; }
uint32_t ModInfo::getSourceFileNameIndex() const {
return Layout->SrcFileNameNI;
}
uint32_t ModInfo::getPdbFilePathNameIndex() const {
return Layout->PdbFilePathNI;
}
llvm::StringRef ModInfo::getModuleName() const {
return Layout->getModuleName();
}
llvm::StringRef ModInfo::getObjFileName() const {
return Layout->getObjectFileName();
}
ModInfoIterator::ModInfoIterator(const uint8_t *Stream) : Bytes(Stream) {}
ModInfoIterator::ModInfoIterator(const ModInfoIterator &Other)
: Bytes(Other.Bytes) {}
ModInfo ModInfoIterator::operator*() { return ModInfo(Bytes); }
ModInfoIterator &ModInfoIterator::operator++() {
StringRef Obj = ModInfo(Bytes).getObjFileName();
Bytes = Obj.bytes_end() + 1;
Bytes = reinterpret_cast<const uint8_t *>(llvm::alignAddr(Bytes, 4));
return *this;
}
ModInfoIterator ModInfoIterator::operator++(int) {
ModInfoIterator Copy(*this);
++(*this);
return Copy;
}
bool ModInfoIterator::operator==(const ModInfoIterator &Other) {
return Bytes == Other.Bytes;
}
bool ModInfoIterator::operator!=(const ModInfoIterator &Other) {
return !(*this == Other);
}
ModInfoIterator &ModInfoIterator::operator=(const ModInfoIterator &Other) {
Bytes = Other.Bytes;
return *this;
}
|