[llvm] r274647 - [pdb] Round trip the PDB stream between YAML and binary PDB.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 6 11:05:59 PDT 2016
Author: zturner
Date: Wed Jul 6 13:05:57 2016
New Revision: 274647
URL: http://llvm.org/viewvc/llvm-project?rev=274647&view=rev
Log:
[pdb] Round trip the PDB stream between YAML and binary PDB.
This gets writing of the PDB stream working.
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ModStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/SymbolStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h
llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/ModStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/SymbolStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
llvm/trunk/test/DebugInfo/PDB/pdbdump-write.test
llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test
llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp
llvm/trunk/tools/llvm-pdbdump/PdbYaml.h
llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp
llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h
llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.h
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h Wed Jul 6 13:05:57 2016
@@ -75,6 +75,8 @@ public:
codeview::FixedStreamArray<SecMapEntry> getSectionMap() const;
void visitSectionContributions(ISectionContribVisitor &Visitor) const;
+ Error commit();
+
private:
Error initializeSectionContributionData();
Error initializeSectionHeadersData();
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h Wed Jul 6 13:05:57 2016
@@ -33,9 +33,16 @@ public:
uint32_t getAge() const;
PDB_UniqueId getGuid() const;
+ void setVersion(PdbRaw_ImplVer Ver);
+ void setSignature(uint32_t Sig);
+ void setAge(uint32_t Age);
+ void setGuid(PDB_UniqueId Guid);
+
uint32_t getNamedStreamIndex(llvm::StringRef Name) const;
iterator_range<StringMapConstIterator<uint32_t>> named_streams() const;
+ Error commit();
+
private:
std::unique_ptr<MappedBlockStream> Stream;
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ModStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ModStream.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ModStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/ModStream.h Wed Jul 6 13:05:57 2016
@@ -37,6 +37,8 @@ public:
iterator_range<codeview::ModuleSubstreamArray::Iterator>
lines(bool *HadError) const;
+ Error commit();
+
private:
const ModInfo &Mod;
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h Wed Jul 6 13:05:57 2016
@@ -18,6 +18,7 @@
namespace llvm {
namespace codeview {
class StreamReader;
+class StreamWriter;
}
namespace pdb {
@@ -26,6 +27,7 @@ public:
NameMap();
Error load(codeview::StreamReader &Stream);
+ Error commit(codeview::StreamWriter &Writer);
bool tryGetValue(StringRef Name, uint32_t &Value) const;
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h Wed Jul 6 13:05:57 2016
@@ -107,6 +107,8 @@ public:
return BlockNumber * BlockSize;
}
+ Expected<InfoStream &> emplacePDBInfoStream();
+
Expected<InfoStream &> getPDBInfoStream();
Expected<DbiStream &> getPDBDbiStream();
Expected<TpiStream &> getPDBTpiStream();
@@ -117,8 +119,9 @@ public:
Error setSuperBlock(const SuperBlock *Block);
void setStreamSizes(ArrayRef<support::ulittle32_t> Sizes);
- void setStreamMap(ArrayRef<support::ulittle32_t> Directory,
- std::vector<ArrayRef<support::ulittle32_t>> &Streams);
+ void setDirectoryBlocks(ArrayRef<support::ulittle32_t> Directory);
+ void setStreamMap(std::vector<ArrayRef<support::ulittle32_t>> &Streams);
+ Error generateSimpleStreamMap();
Error commit();
private:
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h Wed Jul 6 13:05:57 2016
@@ -51,6 +51,8 @@ public:
return SectionOffsets;
}
+ Error commit();
+
private:
PDBFile &Pdb;
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/SymbolStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/SymbolStream.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/SymbolStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/SymbolStream.h Wed Jul 6 13:05:57 2016
@@ -29,6 +29,8 @@ public:
iterator_range<codeview::CVSymbolArray::Iterator>
getSymbols(bool *HadError) const;
+ Error commit();
+
private:
codeview::CVSymbolArray SymbolRecords;
std::unique_ptr<MappedBlockStream> Stream;
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/TpiStream.h Wed Jul 6 13:05:57 2016
@@ -49,6 +49,8 @@ public:
iterator_range<codeview::CVTypeArray::Iterator> types(bool *HadError) const;
+ Error commit();
+
private:
Error verifyHashValues();
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp Wed Jul 6 13:05:57 2016
@@ -452,3 +452,5 @@ Expected<StringRef> DbiStream::getFileNa
return std::move(EC);
return Name;
}
+
+Error DbiStream::commit() { return Error::success(); }
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStream.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStream.cpp Wed Jul 6 13:05:57 2016
@@ -11,27 +11,31 @@
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/CodeView/StreamReader.h"
+#include "llvm/DebugInfo/CodeView/StreamWriter.h"
#include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
using namespace llvm;
+using namespace llvm::codeview;
using namespace llvm::pdb;
+namespace {
+struct Header {
+ support::ulittle32_t Version;
+ support::ulittle32_t Signature;
+ support::ulittle32_t Age;
+ PDB_UniqueId Guid;
+};
+}
+
InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream)
: Stream(std::move(Stream)) {}
Error InfoStream::reload() {
codeview::StreamReader Reader(*Stream);
- struct Header {
- support::ulittle32_t Version;
- support::ulittle32_t Signature;
- support::ulittle32_t Age;
- PDB_UniqueId Guid;
- };
-
const Header *H;
if (auto EC = Reader.readObject(H))
return joinErrors(
@@ -39,9 +43,16 @@ Error InfoStream::reload() {
make_error<RawError>(raw_error_code::corrupt_file,
"PDB Stream does not contain a header."));
- if (H->Version < PdbRaw_ImplVer::PdbImplVC70)
+ switch (H->Version) {
+ case PdbImplVC70:
+ case PdbImplVC80:
+ case PdbImplVC110:
+ case PdbImplVC140:
+ break;
+ default:
return make_error<RawError>(raw_error_code::corrupt_file,
"Unsupported PDB stream version.");
+ }
Version = H->Version;
Signature = H->Signature;
@@ -72,3 +83,27 @@ uint32_t InfoStream::getSignature() cons
uint32_t InfoStream::getAge() const { return Age; }
PDB_UniqueId InfoStream::getGuid() const { return Guid; }
+
+void InfoStream::setVersion(PdbRaw_ImplVer Ver) {
+ Version = static_cast<uint32_t>(Ver);
+}
+
+void InfoStream::setSignature(uint32_t Sig) { Signature = Sig; }
+
+void InfoStream::setAge(uint32_t Age) { this->Age = Age; }
+
+void InfoStream::setGuid(PDB_UniqueId Guid) { this->Guid = Guid; }
+
+Error InfoStream::commit() {
+ StreamWriter Writer(*Stream);
+
+ Header H;
+ H.Age = Age;
+ H.Signature = Signature;
+ H.Version = Version;
+ H.Guid = Guid;
+ if (auto EC = Writer.writeObject(H))
+ return EC;
+
+ return NamedStreams.commit(Writer);
+}
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/ModStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/ModStream.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/ModStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/ModStream.cpp Wed Jul 6 13:05:57 2016
@@ -78,3 +78,5 @@ iterator_range<codeview::ModuleSubstream
ModStream::lines(bool *HadError) const {
return llvm::make_range(LineInfo.begin(HadError), LineInfo.end());
}
+
+Error ModStream::commit() { return Error::success(); }
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp Wed Jul 6 13:05:57 2016
@@ -10,9 +10,11 @@
#include "llvm/DebugInfo/PDB/Raw/NameMap.h"
#include "llvm/ADT/SparseBitVector.h"
#include "llvm/DebugInfo/CodeView/StreamReader.h"
+#include "llvm/DebugInfo/CodeView/StreamWriter.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
using namespace llvm;
+using namespace llvm::codeview;
using namespace llvm::pdb;
NameMap::NameMap() {}
@@ -143,6 +145,24 @@ Error NameMap::load(codeview::StreamRead
return Error::success();
}
+Error NameMap::commit(codeview::StreamWriter &Writer) {
+ if (auto EC = Writer.writeInteger(0U)) // Number of bytes in table
+ return EC;
+
+ if (auto EC = Writer.writeInteger(0U)) // Hash Size
+ return EC;
+
+ if (auto EC = Writer.writeInteger(0U)) // Max Number of Strings
+ return EC;
+
+ if (auto EC = Writer.writeInteger(0U)) // Num Present Words
+ return EC;
+
+ if (auto EC = Writer.writeInteger(0U)) // Num Deleted Words
+ return EC;
+ return Error::success();
+}
+
iterator_range<StringMapConstIterator<uint32_t>> NameMap::entries() const {
return llvm::make_range<StringMapConstIterator<uint32_t>>(Mapping.begin(),
Mapping.end());
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Wed Jul 6 13:05:57 2016
@@ -89,7 +89,7 @@ Error PDBFile::setBlockData(uint32_t Blo
return make_error<RawError>(
raw_error_code::invalid_block_address,
"setBlockData attempted to write out of block bounds.");
- if (Data.size() >= getBlockSize() - Offset)
+ if (Data.size() > getBlockSize() - Offset)
return make_error<RawError>(
raw_error_code::invalid_block_address,
"setBlockData attempted to write out of block bounds.");
@@ -167,6 +167,17 @@ llvm::ArrayRef<support::ulittle32_t> PDB
return DirectoryBlocks;
}
+Expected<InfoStream &> PDBFile::emplacePDBInfoStream() {
+ if (Info)
+ Info.reset();
+
+ auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, *this);
+ if (!InfoS)
+ return InfoS.takeError();
+ Info = llvm::make_unique<InfoStream>(std::move(*InfoS));
+ return *Info;
+}
+
Expected<InfoStream &> PDBFile::getPDBInfoStream() {
if (!Info) {
auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, *this);
@@ -340,12 +351,59 @@ void PDBFile::setStreamSizes(ArrayRef<su
}
void PDBFile::setStreamMap(
- ArrayRef<support::ulittle32_t> Directory,
std::vector<ArrayRef<support::ulittle32_t>> &Streams) {
- DirectoryBlocks = Directory;
StreamMap = Streams;
}
+void PDBFile::setDirectoryBlocks(ArrayRef<support::ulittle32_t> Directory) {
+ DirectoryBlocks = Directory;
+}
+
+Error PDBFile::generateSimpleStreamMap() {
+ if (StreamSizes.empty())
+ return Error::success();
+
+ static std::vector<std::vector<support::ulittle32_t>> StaticMap;
+ StreamMap.clear();
+ StaticMap.clear();
+
+ // Figure out how many blocks are needed for all streams, and set the first
+ // used block to the highest block so that we can write the rest of the
+ // blocks contiguously.
+ uint32_t TotalFileBlocks = getBlockCount();
+ std::vector<support::ulittle32_t> ReservedBlocks;
+ ReservedBlocks.push_back(support::ulittle32_t(0));
+ ReservedBlocks.push_back(SB->BlockMapAddr);
+ ReservedBlocks.insert(ReservedBlocks.end(), DirectoryBlocks.begin(),
+ DirectoryBlocks.end());
+
+ uint32_t BlocksNeeded = 0;
+ for (auto Size : StreamSizes)
+ BlocksNeeded += bytesToBlocks(Size, getBlockSize());
+
+ support::ulittle32_t NextBlock(TotalFileBlocks - BlocksNeeded -
+ ReservedBlocks.size());
+
+ StaticMap.resize(StreamSizes.size());
+ for (uint32_t S = 0; S < StreamSizes.size(); ++S) {
+ uint32_t Size = StreamSizes[S];
+ uint32_t NumBlocks = bytesToBlocks(Size, getBlockSize());
+ auto &ThisStream = StaticMap[S];
+ for (uint32_t I = 0; I < NumBlocks;) {
+ NextBlock += 1;
+ if (std::find(ReservedBlocks.begin(), ReservedBlocks.end(), NextBlock) !=
+ ReservedBlocks.end())
+ continue;
+
+ ++I;
+ assert(NextBlock < getBlockCount());
+ ThisStream.push_back(NextBlock);
+ }
+ StreamMap.push_back(ThisStream);
+ }
+ return Error::success();
+}
+
Error PDBFile::commit() {
StreamWriter Writer(*Buffer);
@@ -371,5 +429,35 @@ Error PDBFile::commit() {
return EC;
}
+ if (Info) {
+ if (auto EC = Info->commit())
+ return EC;
+ }
+
+ if (Dbi) {
+ if (auto EC = Dbi->commit())
+ return EC;
+ }
+
+ if (Symbols) {
+ if (auto EC = Symbols->commit())
+ return EC;
+ }
+
+ if (Publics) {
+ if (auto EC = Publics->commit())
+ return EC;
+ }
+
+ if (Tpi) {
+ if (auto EC = Tpi->commit())
+ return EC;
+ }
+
+ if (Ipi) {
+ if (auto EC = Ipi->commit())
+ return EC;
+ }
+
return Buffer->commit();
}
\ No newline at end of file
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp Wed Jul 6 13:05:57 2016
@@ -169,3 +169,5 @@ PublicsStream::getSymbols(bool *HadError
return SS.getSymbols(HadError);
}
+
+Error PublicsStream::commit() { return Error::success(); }
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/SymbolStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/SymbolStream.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/SymbolStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/SymbolStream.cpp Wed Jul 6 13:05:57 2016
@@ -42,3 +42,5 @@ iterator_range<codeview::CVSymbolArray::
SymbolStream::getSymbols(bool *HadError) const {
return llvm::make_range(SymbolRecords.begin(HadError), SymbolRecords.end());
}
+
+Error SymbolStream::commit() { return Error::success(); }
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp Wed Jul 6 13:05:57 2016
@@ -269,3 +269,5 @@ iterator_range<CVTypeArray::Iterator>
TpiStream::types(bool *HadError) const {
return llvm::make_range(TypeRecords.begin(HadError), TypeRecords.end());
}
+
+Error TpiStream::commit() { return Error::success(); }
Modified: llvm/trunk/test/DebugInfo/PDB/pdbdump-write.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdbdump-write.test?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdbdump-write.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdbdump-write.test Wed Jul 6 13:05:57 2016
@@ -7,7 +7,7 @@
; constructed PDB to YAML, and verifies that the YAML is the same as the
; original YAML generated from the good PDB.
;
-; RUN: llvm-pdbdump pdb2yaml -stream-metadata -stream-directory %p/Inputs/empty.pdb > %t.1
+; RUN: llvm-pdbdump pdb2yaml -stream-metadata -stream-directory -pdb-stream %p/Inputs/empty.pdb > %t.1
; RUN: llvm-pdbdump yaml2pdb -pdb=%t.2 %t.1
-; RUN: llvm-pdbdump pdb2yaml -stream-metadata -stream-directory %t.2 > %t.3
+; RUN: llvm-pdbdump pdb2yaml -stream-metadata -stream-directory -pdb-stream %t.2 > %t.3
; RUN: diff %t.1 %t.3
Modified: llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test Wed Jul 6 13:05:57 2016
@@ -1,7 +1,8 @@
-; RUN: llvm-pdbdump pdb2yaml -stream-metadata %p/Inputs/empty.pdb | FileCheck -check-prefix=YAML %s
+; RUN: llvm-pdbdump pdb2yaml -stream-metadata -stream-directory -pdb-stream %p/Inputs/empty.pdb \
+; RUN: | FileCheck -check-prefix=YAML %s
; YAML: ---
-; YAML-NEXT: MSF:
+; YAML-NEXT: MSF:
; YAML-NEXT: SuperBlock:
; YAML-NEXT: BlockSize: 4096
; YAML-NEXT: Unknown0: 2
@@ -13,6 +14,63 @@
; YAML-NEXT: BlockMapOffset: 98304
; YAML-NEXT: DirectoryBlocks:
; YAML-NEXT: - 23
-; YAML-NEXT: NumStreams: 17
+; YAML-NEXT: NumStreams: 17
; YAML-NEXT: FileSize: 102400
-; YAML: ...
+; YAML-NEXT: StreamSizes:
+; YAML-NEXT: - 40
+; YAML-NEXT: - 118
+; YAML-NEXT: - 5392
+; YAML-NEXT: - 739
+; YAML-NEXT: - 784
+; YAML-NEXT: - 0
+; YAML-NEXT: - 556
+; YAML-NEXT: - 604
+; YAML-NEXT: - 104
+; YAML-NEXT: - 0
+; YAML-NEXT: - 160
+; YAML-NEXT: - 32
+; YAML-NEXT: - 308
+; YAML-NEXT: - 239
+; YAML-NEXT: - 520
+; YAML-NEXT: - 308
+; YAML-NEXT: - 68
+; YAML-NEXT: StreamMap:
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 8
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 19
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 18
+; YAML-NEXT: - 17
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 14
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 20
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 11
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 13
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 12
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 10
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 15
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 6
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 16
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 7
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 21
+; YAML-NEXT: - Stream:
+; YAML-NEXT: - 22
+; YAML-NEXT: PdbStream:
+; YAML-NEXT: Age: 1
+; YAML-NEXT: Guid: '{0B355641-86A0-A249-896F-9988FAE52FF0}'
+; YAML-NEXT: Signature: 1424295906
+; YAML-NEXT: Version: 20000404
+; YAML-NEXT: ...
Modified: llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp Wed Jul 6 13:05:57 2016
@@ -9,6 +9,7 @@
#include "PdbYaml.h"
+#include "llvm/DebugInfo/PDB/PDBExtras.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
using namespace llvm;
@@ -16,6 +17,45 @@ using namespace llvm::yaml;
using namespace llvm::pdb;
using namespace llvm::pdb::yaml;
+namespace llvm {
+namespace yaml {
+template <> struct ScalarTraits<llvm::pdb::PDB_UniqueId> {
+ static void output(const llvm::pdb::PDB_UniqueId &S, void *,
+ llvm::raw_ostream &OS) {
+ OS << S;
+ }
+
+ static StringRef input(StringRef Scalar, void *Ctx,
+ llvm::pdb::PDB_UniqueId &S) {
+ if (Scalar.size() != 38)
+ return "GUID strings are 38 characters long";
+ if (Scalar[0] != '{' || Scalar[37] != '}')
+ return "GUID is not enclosed in {}";
+ if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' ||
+ Scalar[24] != '-')
+ return "GUID sections are not properly delineated with dashes";
+
+ char *OutBuffer = S.Guid;
+ for (auto Iter = Scalar.begin(); Iter != Scalar.end();) {
+ if (*Iter == '-' || *Iter == '{' || *Iter == '}') {
+ ++Iter;
+ continue;
+ }
+ uint8_t Value = (llvm::hexDigitValue(*Iter) << 4);
+ ++Iter;
+ Value |= llvm::hexDigitValue(*Iter);
+ ++Iter;
+ *OutBuffer++ = Value;
+ }
+
+ return "";
+ }
+
+ static bool mustQuote(StringRef Scalar) { return needsQuotes(Scalar); }
+};
+}
+}
+
void MappingTraits<PDBFile::SuperBlock>::mapping(IO &IO,
PDBFile::SuperBlock &SB) {
if (!IO.outputting()) {
@@ -47,4 +87,12 @@ void MappingTraits<PdbObject>::mapping(I
IO.mapOptional("MSF", Obj.Headers);
IO.mapOptional("StreamSizes", Obj.StreamSizes);
IO.mapOptional("StreamMap", Obj.StreamMap);
+ IO.mapOptional("PdbStream", Obj.PdbStream);
}
+
+void MappingTraits<PdbInfoStream>::mapping(IO &IO, PdbInfoStream &Obj) {
+ IO.mapRequired("Age", Obj.Age);
+ IO.mapRequired("Guid", Obj.Guid);
+ IO.mapRequired("Signature", Obj.Signature);
+ IO.mapRequired("Version", Obj.Version);
+}
\ No newline at end of file
Modified: llvm/trunk/tools/llvm-pdbdump/PdbYaml.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/PdbYaml.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/PdbYaml.h (original)
+++ llvm/trunk/tools/llvm-pdbdump/PdbYaml.h Wed Jul 6 13:05:57 2016
@@ -13,7 +13,9 @@
#include "OutputStyle.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/DebugInfo/PDB/PDBTypes.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
+#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/YAMLTraits.h"
@@ -36,10 +38,18 @@ struct StreamBlockList {
std::vector<support::ulittle32_t> Blocks;
};
+struct PdbInfoStream {
+ uint32_t Version;
+ uint32_t Signature;
+ uint32_t Age;
+ PDB_UniqueId Guid;
+};
+
struct PdbObject {
MsfHeaders Headers;
Optional<std::vector<support::ulittle32_t>> StreamSizes;
Optional<std::vector<StreamBlockList>> StreamMap;
+ Optional<PdbInfoStream> PdbStream;
};
}
}
@@ -63,6 +73,10 @@ template <> struct MappingTraits<pdb::ya
template <> struct MappingTraits<pdb::yaml::PdbObject> {
static void mapping(IO &IO, pdb::yaml::PdbObject &Obj);
};
+
+template <> struct MappingTraits<pdb::yaml::PdbInfoStream> {
+ static void mapping(IO &IO, pdb::yaml::PdbInfoStream &Obj);
+};
}
}
Modified: llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp Wed Jul 6 13:05:57 2016
@@ -12,6 +12,7 @@
#include "PdbYaml.h"
#include "llvm-pdbdump.h"
+#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
@@ -21,6 +22,9 @@ using namespace llvm::pdb;
YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {}
Error YAMLOutputStyle::dump() {
+ if (opts::pdb2yaml::StreamDirectory || opts::pdb2yaml::PdbStream)
+ opts::pdb2yaml::StreamMetadata = true;
+
if (auto EC = dumpFileHeaders())
return EC;
@@ -30,6 +34,9 @@ Error YAMLOutputStyle::dump() {
if (auto EC = dumpStreamDirectory())
return EC;
+ if (auto EC = dumpPDBStream())
+ return EC;
+
flush();
return Error::success();
}
@@ -75,6 +82,24 @@ Error YAMLOutputStyle::dumpStreamDirecto
return Error::success();
}
+
+Error YAMLOutputStyle::dumpPDBStream() {
+ if (!opts::pdb2yaml::PdbStream)
+ return Error::success();
+
+ auto IS = File.getPDBInfoStream();
+ if (!IS)
+ return IS.takeError();
+
+ auto &InfoS = IS.get();
+ Obj.PdbStream.emplace();
+ Obj.PdbStream->Age = InfoS.getAge();
+ Obj.PdbStream->Guid = InfoS.getGuid();
+ Obj.PdbStream->Signature = InfoS.getSignature();
+ Obj.PdbStream->Version = InfoS.getVersion();
+
+ return Error::success();
+}
void YAMLOutputStyle::flush() {
Out << Obj;
Modified: llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h (original)
+++ llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h Wed Jul 6 13:05:57 2016
@@ -29,6 +29,7 @@ private:
Error dumpFileHeaders();
Error dumpStreamMetadata();
Error dumpStreamDirectory();
+ Error dumpPDBStream();
void flush();
Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Wed Jul 6 13:05:57 2016
@@ -40,6 +40,7 @@
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
+#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
@@ -268,6 +269,10 @@ cl::opt<bool> StreamDirectory(
"stream-directory",
cl::desc("Dump each stream's block map (implies -stream-metadata)"),
cl::sub(PdbToYamlSubcommand));
+cl::opt<bool> PdbStream(
+ "pdb-stream",
+ cl::desc("Dump the PDB Stream (Stream 1) (implies -stream-metadata)"),
+ cl::sub(PdbToYamlSubcommand));
cl::list<std::string> InputFilename(cl::Positional,
cl::desc("<input PDB file>"), cl::Required,
@@ -302,31 +307,53 @@ static void yamlToPdb(StringRef Path) {
llvm::make_unique<FileBufferByteStream>(std::move(*OutFileOrError));
PDBFile Pdb(std::move(FileByteStream));
ExitOnErr(Pdb.setSuperBlock(&YamlObj.Headers.SuperBlock));
+ if (YamlObj.StreamSizes.hasValue()) {
+ Pdb.setStreamSizes(YamlObj.StreamSizes.getValue());
+ }
+ Pdb.setDirectoryBlocks(YamlObj.Headers.DirectoryBlocks);
+
if (YamlObj.StreamMap.hasValue()) {
std::vector<ArrayRef<support::ulittle32_t>> StreamMap;
for (auto &E : YamlObj.StreamMap.getValue()) {
StreamMap.push_back(E.Blocks);
}
- Pdb.setStreamMap(YamlObj.Headers.DirectoryBlocks, StreamMap);
+ Pdb.setStreamMap(StreamMap);
+ } else {
+ ExitOnErr(Pdb.generateSimpleStreamMap());
}
- if (YamlObj.StreamSizes.hasValue()) {
- Pdb.setStreamSizes(YamlObj.StreamSizes.getValue());
+
+ if (YamlObj.PdbStream.hasValue()) {
+ auto IS = Pdb.emplacePDBInfoStream();
+ ExitOnErr(IS.takeError());
+ auto &InfoS = IS.get();
+ InfoS.setAge(YamlObj.PdbStream->Age);
+ InfoS.setGuid(YamlObj.PdbStream->Guid);
+ InfoS.setSignature(YamlObj.PdbStream->Signature);
+ InfoS.setVersion(static_cast<PdbRaw_ImplVer>(YamlObj.PdbStream->Version));
}
ExitOnErr(Pdb.commit());
}
+static void pdb2Yaml(StringRef Path) {
+ std::unique_ptr<IPDBSession> Session;
+ ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
+
+ RawSession *RS = static_cast<RawSession *>(Session.get());
+ PDBFile &File = RS->getPDBFile();
+ auto O = llvm::make_unique<YAMLOutputStyle>(File);
+ O = llvm::make_unique<YAMLOutputStyle>(File);
+
+ ExitOnErr(O->dump());
+}
+
static void dumpRaw(StringRef Path) {
std::unique_ptr<IPDBSession> Session;
ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
RawSession *RS = static_cast<RawSession *>(Session.get());
PDBFile &File = RS->getPDBFile();
- std::unique_ptr<OutputStyle> O;
- if (opts::PdbToYamlSubcommand)
- O = llvm::make_unique<YAMLOutputStyle>(File);
- else
- O = llvm::make_unique<LLVMOutputStyle>(File);
+ auto O = llvm::make_unique<LLVMOutputStyle>(File);
ExitOnErr(O->dump());
}
@@ -486,7 +513,7 @@ int main(int argc_, const char *argv_[])
llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
if (opts::PdbToYamlSubcommand) {
- dumpRaw(opts::pdb2yaml::InputFilename.front());
+ pdb2Yaml(opts::pdb2yaml::InputFilename.front());
} else if (opts::YamlToPdbSubcommand) {
yamlToPdb(opts::yaml2pdb::InputFilename.front());
} else if (opts::PrettySubcommand) {
Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.h?rev=274647&r1=274646&r2=274647&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.h (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.h Wed Jul 6 13:05:57 2016
@@ -59,6 +59,7 @@ extern llvm::cl::opt<bool> DumpFpo;
namespace pdb2yaml {
extern llvm::cl::opt<bool> StreamMetadata;
extern llvm::cl::opt<bool> StreamDirectory;
+extern llvm::cl::opt<bool> PdbStream;
extern llvm::cl::list<std::string> InputFilename;
}
}
More information about the llvm-commits
mailing list