aboutsummaryrefslogtreecommitdiff
path: root/lib/DebugInfo/PDB/Native/PDBFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DebugInfo/PDB/Native/PDBFile.cpp')
-rw-r--r--lib/DebugInfo/PDB/Native/PDBFile.cpp95
1 files changed, 64 insertions, 31 deletions
diff --git a/lib/DebugInfo/PDB/Native/PDBFile.cpp b/lib/DebugInfo/PDB/Native/PDBFile.cpp
index a1f8786ff12f..983031dfcb78 100644
--- a/lib/DebugInfo/PDB/Native/PDBFile.cpp
+++ b/lib/DebugInfo/PDB/Native/PDBFile.cpp
@@ -1,9 +1,8 @@
//===- PDBFile.cpp - Low level interface to a PDB file ----------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -15,6 +14,7 @@
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
+#include "llvm/DebugInfo/PDB/Native/InjectedSourceStream.h"
#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
#include "llvm/DebugInfo/PDB/Native/RawError.h"
@@ -234,7 +234,8 @@ ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() const {
return ContainerLayout.DirectoryBlocks;
}
-std::unique_ptr<MappedBlockStream> PDBFile::createIndexedStream(uint16_t SN) {
+std::unique_ptr<MappedBlockStream>
+PDBFile::createIndexedStream(uint16_t SN) const {
if (SN == kInvalidStreamIndex)
return nullptr;
return MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer, SN,
@@ -259,8 +260,8 @@ Expected<GlobalsStream &> PDBFile::getPDBGlobalsStream() {
if (!DbiS)
return DbiS.takeError();
- auto GlobalS = safelyCreateIndexedStream(
- ContainerLayout, *Buffer, DbiS->getGlobalSymbolStreamIndex());
+ auto GlobalS =
+ safelyCreateIndexedStream(DbiS->getGlobalSymbolStreamIndex());
if (!GlobalS)
return GlobalS.takeError();
auto TempGlobals = llvm::make_unique<GlobalsStream>(std::move(*GlobalS));
@@ -273,7 +274,7 @@ Expected<GlobalsStream &> PDBFile::getPDBGlobalsStream() {
Expected<InfoStream &> PDBFile::getPDBInfoStream() {
if (!Info) {
- auto InfoS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamPDB);
+ auto InfoS = safelyCreateIndexedStream(StreamPDB);
if (!InfoS)
return InfoS.takeError();
auto TempInfo = llvm::make_unique<InfoStream>(std::move(*InfoS));
@@ -286,7 +287,7 @@ Expected<InfoStream &> PDBFile::getPDBInfoStream() {
Expected<DbiStream &> PDBFile::getPDBDbiStream() {
if (!Dbi) {
- auto DbiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamDBI);
+ auto DbiS = safelyCreateIndexedStream(StreamDBI);
if (!DbiS)
return DbiS.takeError();
auto TempDbi = llvm::make_unique<DbiStream>(std::move(*DbiS));
@@ -299,7 +300,7 @@ Expected<DbiStream &> PDBFile::getPDBDbiStream() {
Expected<TpiStream &> PDBFile::getPDBTpiStream() {
if (!Tpi) {
- auto TpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamTPI);
+ auto TpiS = safelyCreateIndexedStream(StreamTPI);
if (!TpiS)
return TpiS.takeError();
auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(*TpiS));
@@ -315,7 +316,7 @@ Expected<TpiStream &> PDBFile::getPDBIpiStream() {
if (!hasPDBIpiStream())
return make_error<RawError>(raw_error_code::no_stream);
- auto IpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamIPI);
+ auto IpiS = safelyCreateIndexedStream(StreamIPI);
if (!IpiS)
return IpiS.takeError();
auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(*IpiS));
@@ -332,8 +333,8 @@ Expected<PublicsStream &> PDBFile::getPDBPublicsStream() {
if (!DbiS)
return DbiS.takeError();
- auto PublicS = safelyCreateIndexedStream(
- ContainerLayout, *Buffer, DbiS->getPublicSymbolStreamIndex());
+ auto PublicS =
+ safelyCreateIndexedStream(DbiS->getPublicSymbolStreamIndex());
if (!PublicS)
return PublicS.takeError();
auto TempPublics = llvm::make_unique<PublicsStream>(std::move(*PublicS));
@@ -351,8 +352,7 @@ Expected<SymbolStream &> PDBFile::getPDBSymbolStream() {
return DbiS.takeError();
uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
- auto SymbolS =
- safelyCreateIndexedStream(ContainerLayout, *Buffer, SymbolStreamNum);
+ auto SymbolS = safelyCreateIndexedStream(SymbolStreamNum);
if (!SymbolS)
return SymbolS.takeError();
@@ -366,17 +366,7 @@ Expected<SymbolStream &> PDBFile::getPDBSymbolStream() {
Expected<PDBStringTable &> PDBFile::getStringTable() {
if (!Strings) {
- auto IS = getPDBInfoStream();
- if (!IS)
- return IS.takeError();
-
- Expected<uint32_t> ExpectedNSI = IS->getNamedStreamIndex("/names");
- if (!ExpectedNSI)
- return ExpectedNSI.takeError();
- uint32_t NameStreamIndex = *ExpectedNSI;
-
- auto NS =
- safelyCreateIndexedStream(ContainerLayout, *Buffer, NameStreamIndex);
+ auto NS = safelyCreateNamedStream("/names");
if (!NS)
return NS.takeError();
@@ -391,6 +381,24 @@ Expected<PDBStringTable &> PDBFile::getStringTable() {
return *Strings;
}
+Expected<InjectedSourceStream &> PDBFile::getInjectedSourceStream() {
+ if (!InjectedSources) {
+ auto IJS = safelyCreateNamedStream("/src/headerblock");
+ if (!IJS)
+ return IJS.takeError();
+
+ auto Strings = getStringTable();
+ if (!Strings)
+ return Strings.takeError();
+
+ auto IJ = llvm::make_unique<InjectedSourceStream>(std::move(*IJS));
+ if (auto EC = IJ->reload(*Strings))
+ return std::move(EC);
+ InjectedSources = std::move(IJ);
+ }
+ return *InjectedSources;
+}
+
uint32_t PDBFile::getPointerSize() {
auto DbiS = getPDBDbiStream();
if (!DbiS)
@@ -459,16 +467,41 @@ bool PDBFile::hasPDBStringTable() {
return true;
}
+bool PDBFile::hasPDBInjectedSourceStream() {
+ auto IS = getPDBInfoStream();
+ if (!IS)
+ return false;
+ Expected<uint32_t> ExpectedNSI = IS->getNamedStreamIndex("/src/headerblock");
+ if (!ExpectedNSI) {
+ consumeError(ExpectedNSI.takeError());
+ return false;
+ }
+ assert(*ExpectedNSI < getNumStreams());
+ return true;
+}
+
/// Wrapper around MappedBlockStream::createIndexedStream() that checks if a
/// stream with that index actually exists. If it does not, the return value
/// will have an MSFError with code msf_error_code::no_stream. Else, the return
/// value will contain the stream returned by createIndexedStream().
Expected<std::unique_ptr<MappedBlockStream>>
-PDBFile::safelyCreateIndexedStream(const MSFLayout &Layout,
- BinaryStreamRef MsfData,
- uint32_t StreamIndex) const {
+PDBFile::safelyCreateIndexedStream(uint32_t StreamIndex) const {
if (StreamIndex >= getNumStreams())
+ // This rejects kInvalidStreamIndex with an error as well.
return make_error<RawError>(raw_error_code::no_stream);
- return MappedBlockStream::createIndexedStream(Layout, MsfData, StreamIndex,
- Allocator);
+ return createIndexedStream(StreamIndex);
+}
+
+Expected<std::unique_ptr<MappedBlockStream>>
+PDBFile::safelyCreateNamedStream(StringRef Name) {
+ auto IS = getPDBInfoStream();
+ if (!IS)
+ return IS.takeError();
+
+ Expected<uint32_t> ExpectedNSI = IS->getNamedStreamIndex(Name);
+ if (!ExpectedNSI)
+ return ExpectedNSI.takeError();
+ uint32_t NameStreamIndex = *ExpectedNSI;
+
+ return safelyCreateIndexedStream(NameStreamIndex);
}