[PATCH] D21157: [pdb] Improve StreamInterface to support writing

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 17:21:51 PDT 2016


zturner added a comment.

In http://reviews.llvm.org/D21157#452974, @ruiu wrote:

> IIUC, this is a patch to allow users to read and write arbitrary streams at arbitrary position just like files on a file system (I haven't read through yet, so correct me if I'm wrong.) I wonder if it is actually going to be needed. In most cases, we are going to create a new stream in PDB (by copying a stream and appending some data at end of it or in the middle of it) and then atomically update the MSF so that the old stream number now refers to the new stream, no? If that's the case, we open most streams as read-only and write to streams without seeking back.


While it might not be an immediate priority for LLD, I think it will be needed in the future for LLD, and I also think it will be very helpful for some of the improvements tools I have in mind.  For example, we might want to find out how our tools would handle a specific type of CodeView record, or how Microsoft's tool would handle a specific type of CodeView record.  But it's hard to figure out how to get Microsoft to generate that record type, or get it with just the right flag that we want to test.  With the YAML stuff, we will be able to write YAML however we want, and generate a PDB that contains that YAML.  We may even want to have the option to take a small fragment of YAML that describes 1 single record, and inject it into an existing PDB file.

For those kind of operations, we will need the ability to "append" to a PDB.  This means handling complications like what happens if you want to write to a PDB, but there aren't enough blocks.  You have to allocate a new block at the end of the file, then go update the directory, and then write to the PDB while making use of the newly allocated block.

Finally, I think it will be very helpful for testing.  Because when we write a test to make sure we can write PDBs, the easiest way to start doing that is to output some YAML, generate a PDB from it, then dump it, and make sure the dump of the new PDB and the old PDB looks the same.  In order to do that we will need to be able to maintain the structure (stream order, etc).

While it does allow writing into the middle of a stream at an arbitrary position, that wasn't the primary motivating factor.  The primary motivating factor is just to be able to treat discontiguous sequences of blocks as contiguous when writing, so that the person doing the writing doesn't have to worry about seeking around to different blocks.  As long as you give it the stream map, it just works.


http://reviews.llvm.org/D21157





More information about the llvm-commits mailing list