From d8447990b04ed0955b23f811266aada6d48db014 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 7 Jun 2016 05:28:55 +0000 Subject: [pdb] Use MappedBlockStream to parse the PDB directory. In order to efficiently write PDBs, we need to be able to make a StreamWriter class similar to a StreamReader, which can transparently deal with writing to discontiguous streams, and we need to use this for all writing, similar to how we use StreamReader for all reading. Most discontiguous streams are the typical numbered streams that appear in a PDB file and are described by the directory, but the exception to this, that until now has been parsed by hand, is the directory itself. MappedBlockStream works by querying the directory to find out which blocks a stream occupies and various other things, so naturally the same logic could not possibly work to describe the blocks that the directory itself resided on. To solve this, I've introduced an abstraction IPDBStreamData, which allows the client to query for the list of blocks occupied by the stream, as well as the stream length. I provide two implementations of this: one which queries the directory (for indexed streams), and one which queries the super block (for the directory stream). This has the side benefit of vastly simplifying the code to parse the directory. Whereas before a mini state machine was rolled by hand, now we simply use FixedStreamArray to read out the stream sizes, then build a vector of FixedStreamArrays for the stream map, all in just a few lines of code. Reviewed By: ruiu Differential Revision: http://reviews.llvm.org/D21046 llvm-svn: 271982 --- llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'llvm/tools/llvm-pdbdump') diff --git a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp index 034879bf0f4..f819a2cfc92 100644 --- a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -17,6 +17,7 @@ #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" #include "llvm/DebugInfo/PDB/Raw/EnumTables.h" #include "llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h" +#include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h" #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" #include "llvm/DebugInfo/PDB/Raw/ModStream.h" @@ -194,7 +195,8 @@ Error LLVMOutputStyle::dumpStreamData() { DumpStreamNum >= StreamCount) return Error::success(); - MappedBlockStream S(DumpStreamNum, File); + MappedBlockStream S(llvm::make_unique(DumpStreamNum, File), + File); codeview::StreamReader R(S); while (R.bytesRemaining() > 0) { ArrayRef Data; @@ -244,7 +246,8 @@ Error LLVMOutputStyle::dumpNamedStream() { DictScope D(P, Name); P.printNumber("Index", NameStreamIndex); - MappedBlockStream NameStream(NameStreamIndex, File); + MappedBlockStream NameStream( + llvm::make_unique(NameStreamIndex, File), File); codeview::StreamReader Reader(NameStream); NameHashTable NameTable; -- cgit v1.2.3