Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Zachary Turner
committed
Jun 7, 2016
1 parent
2737d99
commit d844799
Showing
23 changed files
with
247 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===- IPDBStreamData.h - Base interface for PDB Stream Data ----*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_DEBUGINFO_PDB_RAW_IPDBSTREAMDATA_H | ||
#define LLVM_DEBUGINFO_PDB_RAW_IPDBSTREAMDATA_H | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/Support/Endian.h" | ||
|
||
namespace llvm { | ||
namespace pdb { | ||
/// IPDBStream abstracts the notion of PDB stream data. Although we already | ||
/// have another stream abstraction (namely in the form of StreamInterface | ||
/// and MappedBlockStream), they assume that the stream data is referenced | ||
/// the same way. Namely, by looking in the directory to get the list of | ||
/// stream blocks, and by looking in the array of stream lengths to get the | ||
/// length. This breaks down for the directory itself, however, since its | ||
/// length and list of blocks are stored elsewhere. By abstracting the | ||
/// notion of stream data further, we can use a MappedBlockStream to read | ||
/// from the directory itself, or from an indexed stream which references | ||
/// the directory. | ||
class IPDBStreamData { | ||
public: | ||
virtual ~IPDBStreamData() {} | ||
|
||
virtual uint32_t getLength() = 0; | ||
virtual ArrayRef<support::ulittle32_t> getStreamBlocks() = 0; | ||
}; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===- IndexedStreamData.h - Standard PDB Stream Data -----------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_DEBUGINFO_PDB_RAW_INDEXEDSTREAMDATA_H | ||
#define LLVM_DEBUGINFO_PDB_RAW_INDEXEDSTREAMDATA_H | ||
|
||
#include "llvm/DebugInfo/PDB/Raw/IPDBStreamData.h" | ||
|
||
namespace llvm { | ||
namespace pdb { | ||
class IPDBFile; | ||
|
||
class IndexedStreamData : public IPDBStreamData { | ||
public: | ||
IndexedStreamData(uint32_t StreamIdx, const IPDBFile &File); | ||
virtual ~IndexedStreamData() {} | ||
|
||
uint32_t getLength() override; | ||
ArrayRef<support::ulittle32_t> getStreamBlocks() override; | ||
|
||
private: | ||
uint32_t StreamIdx; | ||
const IPDBFile &File; | ||
}; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===- IndexedStreamData.cpp - Standard PDB Stream Data ---------*- C++ -*-===// | ||
// | ||
// 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/IndexedStreamData.h" | ||
#include "llvm/DebugInfo/PDB/Raw/IPDBFile.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::pdb; | ||
|
||
IndexedStreamData::IndexedStreamData(uint32_t StreamIdx, const IPDBFile &File) | ||
: StreamIdx(StreamIdx), File(File) {} | ||
|
||
uint32_t IndexedStreamData::getLength() { | ||
return File.getStreamByteSize(StreamIdx); | ||
} | ||
|
||
ArrayRef<support::ulittle32_t> IndexedStreamData::getStreamBlocks() { | ||
return File.getStreamBlockList(StreamIdx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.