This is an archive of the discontinued LLVM Phabricator instance.

Use MappedBlockStream for parsing the directory
ClosedPublic

Authored by zturner on Jun 6 2016, 5:18 PM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner updated this revision to Diff 59809.Jun 6 2016, 5:18 PM
zturner retitled this revision from to Use MappedBlockStream for parsing the directory.
zturner updated this object.
zturner added reviewers: rnk, ruiu, majnemer.
zturner added a subscriber: llvm-commits.
ruiu accepted this revision.Jun 6 2016, 5:56 PM
ruiu edited edge metadata.

LGTM

Introducing a new abstraction make the code slightly more hard to understand, but since this reduces the amount of code by removing multiple pieces of code that do the same thing, I think it is overall win.

include/llvm/DebugInfo/PDB/Raw/IPDBStreamData.h
1–2 ↗(On Diff #59809)

Format.

include/llvm/DebugInfo/PDB/Raw/IndexedStreamData.h
19–28 ↗(On Diff #59809)

Remove duplicate comment.

This revision is now accepted and ready to land.Jun 6 2016, 5:56 PM
This revision was automatically updated to reflect the committed changes.