blob: 15adae666e32f0b3b18d12dc0e234bbe1e0c9a0e (
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
|
//===- PDBDbiStream.cpp - PDB Dbi Stream (Stream 3) Access ----------------===//
//
// 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/PDBDbiStream.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/PDBInfoStream.h"
#include "llvm/DebugInfo/PDB/Raw/PDBRawConstants.h"
using namespace llvm;
using namespace llvm::support;
namespace {
// Some of the values are stored in bitfields. Since this needs to be portable
// across compilers and architectures (big / little endian in particular) we
// can't use the actual structures below, but must instead do the shifting
// and masking ourselves. The struct definitions are provided for reference.
// struct DbiFlags {
// uint16_t IncrementalLinking : 1; // True if linked incrementally
// uint16_t IsStripped : 1; // True if private symbols were stripped.
// uint16_t HasCTypes : 1; // True if linked with /debug:ctypes.
// uint16_t Reserved : 13;
//};
const uint16_t FlagIncrementalMask = 0x0001;
const uint16_t FlagStrippedMask = 0x0002;
const uint16_t FlagHasCTypesMask = 0x0004;
// struct DbiBuildNo {
// uint16_t MinorVersion : 8;
// uint16_t MajorVersion : 7;
// uint16_t NewVersionFormat : 1;
//};
const uint16_t BuildMinorMask = 0x00FF;
const uint16_t BuildMinorShift = 0;
const uint16_t BuildMajorMask = 0x7F00;
const uint16_t BuildMajorShift = 8;
const uint16_t BuildNewFormatMask = 0x8000;
const uint16_t BuildNewFormatShift = 15;
}
struct PDBDbiStream::HeaderInfo {
ulittle32_t VersionSignature;
ulittle32_t VersionHeader;
ulittle32_t Age; // Should match PDBInfoStream.
ulittle16_t GSSyms;
ulittle16_t BuildNumber; // See DbiBuildNo structure.
ulittle16_t PSSyms;
ulittle16_t PdbDllVersion; // version of mspdbNNN.dll
ulittle16_t SymRecords; // Number of symbols
ulittle16_t PdbDllRbld; // rbld number of mspdbNNN.dll
little32_t ModiSubstreamSize; // Size of module info stream
little32_t SecContrSubstreamSize; // Size of sec. contribution stream
little32_t SectionMapSize;
little32_t FileInfoSize;
little32_t TypeServerSize; // Size of type server map
ulittle32_t MFCTypeServerIndex; // Index of MFC Type Server
little32_t OptionalDbgHdrSize; // Size of DbgHeader info
little32_t ECSubstreamSize; // Size of EC stream (what is EC?)
ulittle16_t Flags; // See DbiFlags enum.
ulittle16_t MachineType; // See PDB_MachineType enum.
ulittle32_t Reserved; // Pad to 64 bytes
};
PDBDbiStream::PDBDbiStream(PDBFile &File) : Pdb(File), Stream(3, File) {
static_assert(sizeof(HeaderInfo) == 64, "Invalid HeaderInfo size!");
}
PDBDbiStream::~PDBDbiStream() {}
std::error_code PDBDbiStream::reload() {
Stream.setOffset(0);
Header.reset(new HeaderInfo());
if (Stream.getLength() < sizeof(HeaderInfo))
return std::make_error_code(std::errc::illegal_byte_sequence);
Stream.readObject(Header.get());
if (Header->VersionSignature != -1)
return std::make_error_code(std::errc::illegal_byte_sequence);
// Prior to VC50 an old style header was used. We don't support this.
if (Header->VersionHeader < PdbDbiV50)
return std::make_error_code(std::errc::not_supported);
if (Header->Age != Pdb.getPDBInfoStream().getAge())
return std::make_error_code(std::errc::illegal_byte_sequence);
if (Stream.getLength() !=
sizeof(HeaderInfo) + Header->ModiSubstreamSize +
Header->SecContrSubstreamSize + Header->SectionMapSize +
Header->FileInfoSize + Header->TypeServerSize +
Header->OptionalDbgHdrSize + Header->ECSubstreamSize)
return std::make_error_code(std::errc::illegal_byte_sequence);
return std::error_code();
}
PdbRaw_DbiVer PDBDbiStream::getDbiVersion() const {
uint32_t Value = Header->VersionHeader;
return static_cast<PdbRaw_DbiVer>(Value);
}
uint32_t PDBDbiStream::getAge() const { return Header->Age; }
bool PDBDbiStream::isIncrementallyLinked() const {
return (Header->Flags & FlagIncrementalMask) != 0;
}
bool PDBDbiStream::hasCTypes() const {
return (Header->Flags & FlagHasCTypesMask) != 0;
}
bool PDBDbiStream::isStripped() const {
return (Header->Flags & FlagStrippedMask) != 0;
}
uint16_t PDBDbiStream::getBuildMajorVersion() const {
return (Header->BuildNumber & BuildMajorMask) >> BuildMajorShift;
}
uint16_t PDBDbiStream::getBuildMinorVersion() const {
return (Header->BuildNumber & BuildMinorMask) >> BuildMinorShift;
}
uint32_t PDBDbiStream::getPdbDllVersion() const {
return Header->PdbDllVersion;
}
uint32_t PDBDbiStream::getNumberOfSymbols() const { return Header->SymRecords; }
PDB_Machine PDBDbiStream::getMachineType() const {
uint16_t Machine = Header->MachineType;
return static_cast<PDB_Machine>(Machine);
}
|